-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.h
151 lines (139 loc) · 4.41 KB
/
client.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
/****************************************************************************
**
** 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_CONNECTION_H
#define IREEN_CONNECTION_H
#include "ireen_global.h"
#include "abstractconnection.h"
#include "status.h"
namespace Ireen {
class SNACHandler;
class SNAC;
class ProtocolNegotiation;
class BuddyPictureHandler;
class Roster;
class Feedbag;
class Md5Login;
class ClientPrivate;
class MD5LoginDataPrivate;
class OAuthLoginDataPrivate;
class IREEN_EXPORT MD5LoginData
{
public:
MD5LoginData(const QString &password = QString());
~MD5LoginData();
MD5LoginData(const MD5LoginData &other);
MD5LoginData &operator=(const MD5LoginData &other);
QString password() const;
void setPassword(const QString &password);
QString loginServer() const;
quint16 loginServerPort() const;
void setLoginServer(const QString &server, quint16 port);
#if IREEN_SSL_SUPPORT
void setSslMode(bool enableSsl = true);
bool isSslEnabled() const;
#endif
private:
QSharedDataPointer<MD5LoginDataPrivate> d;
};
#if IREEN_SSL_SUPPORT
class IREEN_EXPORT OAuthLoginData
{
public:
OAuthLoginData();
~OAuthLoginData();
OAuthLoginData(const OAuthLoginData &other);
OAuthLoginData &operator=(const OAuthLoginData &other);
QString developerId() const;
void setDeveloperId(const QString &developerId);
QString clientName() const;
void setClientName(const QString &clientName);
QString distributionId() const;
void setDistributionId(const QString &distributionId);
QString password() const;
void setPassword(const QString &password);
void setSslMode(bool enableSsl = true);
bool isSslEnabled() const;
int versionMajor() const;
int versionMinor() const;
int versionSecMinor() const;
int versionPatch() const;
void setVersion(int major, int minor, int secMinor, int patch);
QVariant lastToken() const;
void setLastToken(const QVariant &tokenData);
private:
QSharedDataPointer<OAuthLoginDataPrivate> d;
};
#endif
class IREEN_EXPORT Client: public AbstractConnection
{
Q_OBJECT
Q_DECLARE_PRIVATE(Client)
public:
Client(const QString &uin, QObject *parent);
void login(const QString &password);
void login(const MD5LoginData &data);
#if IREEN_SSL_SUPPORT
void login(const OAuthLoginData &data);
#endif
void disconnectFromHost(bool force = false);
QString uin() const;
void sendStatus(Status status);
QAbstractSocket::SocketState socketState() const;
Status status() const;
bool isConnected();
void setCapability(const Capability &capability, const QString &type);
bool removeCapability(const Capability &capability);
bool removeCapability(const QString &type);
bool containsCapability(const Capability &capability) const;
bool containsCapability(const QString &type) const;
QList<Capability> capabilities() const;
Feedbag *feedbag() const;
QTextCodec *asciiCodec() const;
void setAsciiCodec(QTextCodec *codec);
QTextCodec *detectCodec() const;
signals:
void loginFinished();
void loginTokenUpdated(const QVariant &token);
protected:
void handleSNAC(AbstractConnection *conn, const SNAC &snac);
private slots:
void onDisconnect();
void onError(ConnectionError error);
void authError(Ireen::AbstractConnection::ConnectionError error);
void onCookieTimeout();
void finishLogin();
private:
void setIdle(bool allow);
void processNewConnection();
void processCloseConnection();
private:
friend class Cookie;
friend class Md5Login;
friend class OscarAuth;
friend class Feedbag;
};
} // namespace Ireen
#endif // IREEN_CONNECTION_H