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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
// ---------------------------------------------------------------------------80
// ICQ plugin for Miranda Instant Messenger
// ________________________________________
//
// Copyright © 2000-2001 Richard Hughes, Roland Rabien, Tristan Van de Vreede
// Copyright © 2001-2002 Jon Keating, Richard Hughes
// Copyright © 2002-2004 Martin Öberg, Sam Kothari, Robert Rainwater
// Copyright © 2004-2010 Joe Kucera, George Hazan
// Copyright © 2012-2019 Miranda NG team
//
// 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.
//
// 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 General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// -----------------------------------------------------------------------------
// DESCRIPTION:
//
// Protocol Interface declarations
// -----------------------------------------------------------------------------
#ifndef _ICQ_PROTO_H_
#define _ICQ_PROTO_H_
#include "m_system.h"
#include "m_protoint.h"
#define ICQ_APP_ID "ic1nmMjqg7Yu-0hL"
#define ICQ_API_SERVER "https://api.icq.net"
#define ICQ_ROBUST_SERVER "https://rapi.icq.net"
enum ChatMenuItems
{
IDM_INVITE = 10, IDM_LEAVE
};
struct IcqGroup
{
IcqGroup(int icqId, const CMStringW &wszName) :
m_iIcqId(icqId),
m_wszName(wszName)
{
m_iMirId = ::Clist_GroupExists(wszName);
}
MGROUP m_iMirId;
int m_iIcqId;
CMStringW m_wszName;
};
struct IcqCacheItem
{
IcqCacheItem(DWORD _uin, MCONTACT _contact) :
m_uin(_uin),
m_hContact(_contact)
{}
DWORD m_uin;
MCONTACT m_hContact;
bool m_bInList = false;
};
struct IcqOwnMessage
{
IcqOwnMessage(MCONTACT _hContact, int _msgid, const char *guid)
: m_hContact(_hContact), m_msgid(_msgid)
{
strncpy_s(m_guid, guid, _TRUNCATE);
}
MCONTACT m_hContact;
int m_msgid;
char m_guid[50];
};
struct IcqConn
{
HNETLIBCONN s;
int lastTs, timeout;
};
class CIcqProto : public PROTO<CIcqProto>
{
friend struct CIcqRegistrationDlg;
friend class CGroupchatInviteDlg;
bool m_bOnline = false, m_bTerminated = false;
void CheckAvatarChange(MCONTACT hContact, const JSONNode&);
void CheckLastId(MCONTACT hContact, const JSONNode&);
void CheckNickChange(MCONTACT hContact, const JSONNode&);
MCONTACT CheckOwnMessage(const CMStringA &reqId, const CMStringA &msgId, bool bRemove);
void CheckPassword(void);
void ConnectionFailed(int iReason);
CMStringA GetUserId(MCONTACT);
MCONTACT ParseBuddyInfo(const JSONNode &buddy, MCONTACT hContact = -1);
void ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNode &msg);
void RetrieveUserHistory(MCONTACT, __int64 startMsgId, __int64 endMsgId);
void RetrieveUserInfo(MCONTACT);
void SetServerStatus(int iNewStatus);
void ShutdownSession(void);
void StartSession(void);
void OnLoggedIn(void);
void OnLoggedOut(void);
mir_cs csMarkReadQueue;
LIST<IcqCacheItem> arMarkReadQueue;
static void CALLBACK MarkReadTimerProc(HWND hwnd, UINT, UINT_PTR id, DWORD);
__int64 getId(MCONTACT hContact, const char *szSetting);
void setId(MCONTACT hContact, const char *szSetting, __int64 iValue);
void OnAddBuddy(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnAddClient(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnCheckPassword(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnCheckPhone(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnFetchEvents(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnGetChatInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnGetUserHistory(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnGetUserInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnLoginViaPhone(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnNormalizePhone(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnSearchResults(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnSendMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnStartSession(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnValidateSms(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void ProcessBuddyList(const JSONNode&);
void ProcessDiff(const JSONNode&);
void ProcessEvent(const JSONNode&);
void ProcessGroupChat(const JSONNode&);
void ProcessHistData(const JSONNode&);
void ProcessImState(const JSONNode&);
void ProcessMyInfo(const JSONNode&);
void ProcessPresence(const JSONNode&);
void ProcessTyping(const JSONNode&);
IcqConn m_ConnPool[CONN_LAST];
CMStringA m_szSessionKey;
CMStringA m_szAToken;
CMStringA m_szRToken;
CMStringA m_fetchBaseURL;
CMStringA m_aimsid;
LONG m_msgId = 1;
int m_iRClientId;
OBJLIST<IcqOwnMessage> m_arOwnIds;
////////////////////////////////////////////////////////////////////////////////////////
// group chats
int __cdecl GroupchatEventHook(WPARAM, LPARAM);
int __cdecl GroupchatMenuHook(WPARAM, LPARAM);
void Chat_ProcessLogMenu(SESSION_INFO *si, int);
void Chat_SendPrivateMessage(GCHOOK *gch);
void InviteUserToChat(SESSION_INFO *si);
void LeaveDestroyChat(SESSION_INFO *si);
void LoadChatInfo(SESSION_INFO *si);
////////////////////////////////////////////////////////////////////////////////////////
// http queue
mir_cs m_csHttpQueue;
HANDLE m_evRequestsQueue;
LIST<AsyncHttpRequest> m_arHttpQueue;
void CalcHash(AsyncHttpRequest*);
void ExecuteRequest(AsyncHttpRequest*);
void Push(MHttpRequest*);
bool RefreshRobustToken();
////////////////////////////////////////////////////////////////////////////////////////
// cache
mir_cs m_csCache;
OBJLIST<IcqCacheItem> m_arCache;
OBJLIST<IcqGroup> m_arGroups;
void InitContactCache(void);
IcqCacheItem* FindContactByUIN(DWORD);
MCONTACT CreateContact(DWORD dwUin, bool bTemporary);
void GetAvatarFileName(MCONTACT hContact, wchar_t *pszDest, size_t cbLen);
////////////////////////////////////////////////////////////////////////////////////////
// threads
HANDLE m_hWorkerThread;
void __cdecl ServerThread(void*);
HANDLE m_hPollThread;
void __cdecl PollThread(void*);
////////////////////////////////////////////////////////////////////////////////////////
// services
INT_PTR __cdecl GetAvatar(WPARAM, LPARAM);
INT_PTR __cdecl GetAvatarCaps(WPARAM, LPARAM);
INT_PTR __cdecl GetAvatarInfo(WPARAM, LPARAM);
INT_PTR __cdecl SetAvatar(WPARAM, LPARAM);
INT_PTR __cdecl CreateAccMgrUI(WPARAM, LPARAM);
////////////////////////////////////////////////////////////////////////////////////////
// events
int __cdecl OnDbEventRead(WPARAM, LPARAM);
int __cdecl OnOptionsInit(WPARAM, LPARAM);
////////////////////////////////////////////////////////////////////////////////////////
// PROTO_INTERFACE
MCONTACT AddToList( int flags, PROTOSEARCHRESULT *psr) override;
int AuthRequest(MCONTACT hContact, const wchar_t *szMessage) override;
HANDLE FileAllow(MCONTACT hContact, HANDLE hTransfer, const wchar_t *szPath) override;
int FileCancel(MCONTACT hContact, HANDLE hTransfer) override;
int FileDeny(MCONTACT hContact, HANDLE hTransfer, const wchar_t *szReason) override;
int FileResume( HANDLE hTransfer, int *action, const wchar_t **szFilename) override;
INT_PTR GetCaps(int type, MCONTACT hContact = NULL) override;
int GetInfo(MCONTACT hContact, int infoType) override;
HANDLE SearchBasic(const wchar_t *id) override;
HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override;
int SendMsg(MCONTACT hContact, int flags, const char *msg) override;
int SendUrl(MCONTACT hContact, int flags, const char *url) override;
int SetApparentMode(MCONTACT hContact, int mode) override;
int SetStatus(int iNewStatus) override;
HANDLE GetAwayMsg(MCONTACT hContact) override;
int RecvAwayMsg(MCONTACT hContact, int mode, PROTORECVEVENT *evt) override;
int SetAwayMsg(int m_iStatus, const wchar_t *msg) override;
int UserIsTyping(MCONTACT hContact, int type) override;
void OnContactDeleted(MCONTACT) override;
void OnModulesLoaded() override;
void OnShutdown() override;
public:
CIcqProto(const char*, const wchar_t*);
~CIcqProto();
CMOption<DWORD> m_dwUin; // our own id
CMOption<wchar_t*> m_szPassword; // password, if present
CMOption<BYTE> m_bUseFriendly; // use friendly names instead of old icq nicks
CMOption<BYTE> m_bHideGroupchats; // don't pop up group chat windows on startup
};
struct CMPlugin : public ACCPROTOPLUGIN<CIcqProto>
{
CMPlugin();
int Load() override;
int Unload() override;
};
#endif
|