1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*
p2p.h - msn p2p protocol
Copyright (c) 2003-2005 by Olivier Goffart <ogoffart@ kde.org>
Copyright (c) 2005 by Gregg Edghill <gregg.edghill@gmail.com>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#ifndef P2P_H
#define P2P_H
// Qt includes
#include <qobject.h>
#include "messageformatter.h"
#include "kopete_export.h"
#include "config.h"
namespace Kopete { class Transfer; }
namespace Kopete { struct FileTransferInfo; }
namespace P2P { class Dispatcher; }
namespace KNetwork { class KBufferedSocket; }
class QFile;
class KTempFile;
/**
@author Kopete Developers
*/
namespace System{
class Guid
{
public:
~Guid(){}
static Guid newGuid();
QString toString();
private:
Guid(){}
};
}
namespace P2P{
enum TransferType { UserDisplayIcon = 1, File = 2, WebcamType=4};
enum TransferDirection { Incoming = 1, Outgoing = 8};
enum MessageType { BYE, OK, DECLINE, ERROR, INVITE };
enum CommunicationState
{
Invitation = 1,
Negotiation = 2,
DataTransfer = 8,
Finished = 16
};
struct TransportHeader
{
Q_UINT32 sessionId;
Q_UINT32 identifier;
Q_INT64 dataOffset;
Q_INT64 totalDataSize;
Q_UINT32 dataSize;
Q_UINT32 flag;
Q_UINT32 ackSessionIdentifier;
Q_UINT32 ackUniqueIdentifier;
Q_INT64 ackDataSize;
};
struct Message
{
public:
QString mimeVersion;
QString contentType;
QString destination;
QString source;
TransportHeader header;
QByteArray body;
Q_INT32 applicationIdentifier;
bool attachApplicationIdentifier;
};
class KOPETE_EXPORT Uid
{
public: static QString createUid();
};
class KOPETE_EXPORT TransferContext : public QObject
{ Q_OBJECT
public:
virtual ~TransferContext();
void acknowledge(const Message& message);
virtual void acknowledged() = 0;
void error();
virtual void processMessage(const P2P::Message& message) = 0;
void sendDataPreparation();
void sendMessage(MessageType type, const QString& content=QString::null, Q_INT32 flag=0, Q_INT32 appId=0);
void setType(TransferType type);
public:
Q_UINT32 m_sessionId;
Q_UINT32 m_identifier;
QFile *m_file;
Q_UINT32 m_transactionId;
Q_UINT32 m_ackSessionIdentifier;
Q_UINT32 m_ackUniqueIdentifier;
Kopete::Transfer *m_transfer;
QString m_branch;
QString m_callId;
QString m_object;
public slots:
void abort();
void readyWrite();
protected:
TransferContext(const QString& contact, P2P::Dispatcher *dispatcher,Q_UINT32 sessionId);
void sendData(const QByteArray& bytes);
void sendMessage(P2P::Message& outbound, const QByteArray& body);
virtual void readyToSend();
Q_UINT32 m_baseIdentifier;
TransferDirection m_direction;
P2P::Dispatcher *m_dispatcher;
bool m_isComplete;
Q_INT64 m_offset;
Q_INT64 m_totalDataSize;
P2P::MessageFormatter m_messageFormatter;
QString m_recipient;
QString m_sender;
KNetwork::KBufferedSocket *m_socket;
CommunicationState m_state;
TransferType m_type;
};
}
#endif
|