-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabstractconnection.h
199 lines (184 loc) · 5.56 KB
/
abstractconnection.h
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/****************************************************************************
**
** Ireen — cross-platform OSCAR protocol library
**
** Copyright © 2012 Ruslan Nigmatullin <[email protected]>
** Alexey Prokhin <[email protected]>
**
*****************************************************************************
**
** $IREEN_BEGIN_LICENSE$
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as
** published by the Free Software Foundation, either version 3
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program. If not, see http://www.gnu.org/licenses/.
** $IREEN_END_LICENSE$
**
****************************************************************************/
#ifndef IREEN_ABSTRACTCONNECTION_H
#define IREEN_ABSTRACTCONNECTION_H
#if IREEN_SSL_SUPPORT
#include <QSslSocket>
#else
#include <QTcpSocket>
#endif
#include <QMap>
#include <QHostAddress>
#include "core/snachandler.h"
#include "core/flap.h"
namespace Ireen {
class ConnectionRate;
class AbstractConnectionPrivate;
struct IREEN_EXPORT ProtocolError
{
public:
ProtocolError(const SNAC &snac);
qint16 code() { return m_code; }
qint16 subcode() { return m_subcode; }
QString errorString();
TLVMap tlvs() const { return m_tlvs; }
protected:
qint16 m_code;
qint16 m_subcode;
TLVMap m_tlvs;
};
struct IREEN_EXPORT ClientInfo
{
QByteArray id_string;
quint16 id_number;
quint16 major_version;
quint16 minor_version;
quint16 lesser_version;
quint16 build_number;
quint32 distribution_number;
QByteArray language;
QByteArray country;
};
struct IREEN_EXPORT DirectConnectionInfo
{
QHostAddress internal_ip;
QHostAddress external_ip;
quint32 port;
quint8 dc_type;
quint16 protocol_version;
quint32 auth_cookie;
quint32 web_front_port;
quint32 client_features;
quint32 info_utime; // last info update time (unix time_t)
quint32 extinfo_utime; // last ext info update time (i.e. icqphone status)
quint32 extstatus_utime; // last ext status update time (i.e. phonebook)
};
#if IREEN_SSL_SUPPORT
typedef QSslSocket Socket;
#else
typedef QTcpSocket Socket;
#endif
class IREEN_EXPORT AbstractConnection : public QObject, public SNACHandler
{
Q_OBJECT
Q_INTERFACES(Ireen::SNACHandler)
Q_DECLARE_PRIVATE(AbstractConnection)
public:
enum ConnectionError
{
NoError = 0x00,
InvalidNickOrPassword = 0x01,
ServiceUnaivalable = 0x02,
IncorrectNickOrPassword = 0x04,
MismatchNickOrPassword = 0x05,
InternalClientError = 0x06,
InvalidAccount = 0x07,
DeletedAccount = 0x08,
ExpiredAccount = 0x09,
NoAccessToDatabase = 0x0a,
NoAccessToResolver = 0x0b,
InvalidDatabaseFields = 0x0c,
BadDatabaseStatus = 0x0D,
BadResolverStatus = 0x0E,
InternalError = 0x0F,
ServiceOffline = 0x10,
SuspendedAccount = 0x11,
DBSendError = 0x12,
DBLinkError = 0x13,
ReservationMapError = 0x14,
ReservationLinkError = 0x15,
ConnectionLimitExceeded = 0x16,
ConnectionLimitExceededReservation = 0x17,
RateLimitExceededReservation = 0x18,
UserHeavilyWarned = 0x19,
ReservationTimeout = 0x1a,
ClientUpgradeRequired = 0x1b,
ClientUpgradeRecommended = 0x1c,
RateLimitExceeded = 0x1d,
IcqNetworkError = 0x1e,
InvalidSecirID = 0x20,
AgeLimit = 0x22,
AnotherClientLogined = 0x80,
SocketError = 0x81,
HostNotFound = 0x82
};
enum State
{
Unconnected,
Connecting,
Connected
};
public:
explicit AbstractConnection(QObject *parent = 0);
virtual ~AbstractConnection();
void registerHandler(SNACHandler *handler);
void send(SNAC &snac, bool priority = true);
void sendSnac(quint16 family, quint16 subtype, bool priority = true);
bool testRate(quint16 family, quint16 subtype, bool priority = true);
virtual void disconnectFromHost(bool force = false);
const QHostAddress &externalIP() const;
const QList<quint16> &servicesList();
Socket *socket(); // FIXME: Make it private
const Socket *socket() const;
QNetworkProxy proxy() const;
ConnectionError error();
QString errorString();
const ClientInfo &clientInfo();
State state() const;
void registerInitializationSnacs(const QList<SNACInfo> &snacs, bool append = true);
void registerInitializationSnac(quint16 family, quint16 subtype);
public slots:
void setProxy(const QNetworkProxy &proxy);
signals:
void error(Ireen::AbstractConnection::ConnectionError error);
void disconnected();
void proxyUpdated(const QNetworkProxy &proxy);
protected:
AbstractConnection(AbstractConnectionPrivate *d, QObject *parent);
const FLAP &flap();
void send(FLAP &flap);
quint32 sendSnac(SNAC &snac);
void setSeqNum(quint16 seqnum);
virtual void processNewConnection();
virtual void processCloseConnection();
virtual void onDisconnect();
virtual void onError(ConnectionError error);
void setError(ConnectionError error, const QString &errorStr = QString());
virtual void handleSNAC(AbstractConnection *conn, const SNAC &snac);
void setState(AbstractConnection::State state);
static quint16 generateFlapSequence();
private slots:
void processSnac();
void readData();
void stateChanged(QAbstractSocket::SocketState);
void error(QAbstractSocket::SocketError);
void sendAlivePacket();
protected:
friend class ConnectionRate;
QScopedPointer<AbstractConnectionPrivate> d_ptr;
};
} // namespace Ireen
#endif // IREEN_ABSTRACTCONNECTION_H