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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
/*
Copyright (c) 2013-15 Miranda NG project (http://miranda-ng.org)
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 version 2
of the License.
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, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#pragma once
#define PS_CREATECHAT "/CreateNewChat"
#define PS_LOADVKNEWS "/LoadVKNews"
#define PS_GETSERVERHISTORY "/SyncHistory"
#define PS_GETSERVERHISTORYLAST1DAY "/GetServerHystoryLast1Day"
#define PS_GETSERVERHISTORYLAST3DAY "/GetServerHystoryLast3Day"
#define PS_GETSERVERHISTORYLAST7DAY "/GetServerHystoryLast7Day"
#define PS_GETSERVERHISTORYLAST30DAY "/GetServerHystoryLast30Day"
#define PS_GETSERVERHISTORYLAST90DAY "/GetServerHystoryLast90Day"
#define PS_GETALLSERVERHISTORY "/GetAllServerHystory"
#define PS_VISITPROFILE "/VisitProfile"
#define PS_ADDASFRIEND "/AddAsFriend"
#define PS_DELETEFRIEND "/DeleteFriend"
#define PS_BANUSER "/BanUser"
#define PS_REPORTABUSE "/ReportAbuse"
#define PS_DESTROYKICKCHAT "/DestroyKickChat"
#define PS_OPENBROADCAST "/OpenBroadcast"
#define PS_SETSTATUSMSG "/SetStatusMsg"
#define PS_WALLPOST "/WallPost"
#define MAXHISTORYMIDSPERONE 175
#define MAX_RETRIES 10
struct CVkProto : public PROTO<CVkProto>
{
CVkProto(const char*, const TCHAR*);
~CVkProto();
//====================================================================================
// PROTO_INTERFACE
//====================================================================================
virtual MCONTACT __cdecl AddToList(int flags, PROTOSEARCHRESULT* psr);
virtual int __cdecl Authorize(MEVENT hDbEvent);
virtual int __cdecl AuthDeny(MEVENT hDbEvent, const TCHAR *szReason);
virtual int __cdecl AuthRequest(MCONTACT hContact, const TCHAR *szMessage);
virtual DWORD_PTR __cdecl GetCaps(int type, MCONTACT hContact = NULL);
virtual int __cdecl GetInfo(MCONTACT hContact, int infoType);
virtual HANDLE __cdecl SearchBasic(const TCHAR *id);
virtual HANDLE __cdecl SearchByEmail(const TCHAR *email);
virtual HANDLE __cdecl SearchByName(const TCHAR *nick, const TCHAR *firstName, const TCHAR *lastName);
virtual int __cdecl RecvMsg(MCONTACT hContact, PROTORECVEVENT*);
virtual int __cdecl SendMsg(MCONTACT hContact, int flags, const char *msg);
virtual HANDLE __cdecl SendFile(MCONTACT hContact, const TCHAR *szDescription, TCHAR **ppszFiles);
virtual int __cdecl SetStatus(int iNewStatus);
virtual int __cdecl UserIsTyping(MCONTACT hContact, int type);
virtual int __cdecl OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam);
//==== Events ========================================================================
int __cdecl OnModulesLoaded(WPARAM, LPARAM);
int __cdecl OnOptionsInit(WPARAM, LPARAM);
int __cdecl OnPreShutdown(WPARAM, LPARAM);
void OnOAuthAuthorize(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
//==== Services ======================================================================
INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM);
INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM);
INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM);
INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM);
INT_PTR __cdecl SvcSetListeningTo(WPARAM, LPARAM);
//==== Menus ==========================================================================
INT_PTR __cdecl SvcVisitProfile(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcAddAsFriend(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcDeleteFriend(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcBanUser(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcReportAbuse(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcDestroyKickChat(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcOpenBroadcast(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcWallPost(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcSetStatusMsg(WPARAM, LPARAM);
//==== History Menus ==================================================================
INT_PTR __cdecl SvcGetServerHistoryLast1Day(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcGetServerHistoryLast3Day(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcGetServerHistoryLast7Day(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcGetServerHistoryLast30Day(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcGetServerHistoryLast90Day(WPARAM hContact, LPARAM);
INT_PTR __cdecl SvcGetAllServerHistory(WPARAM hContact, LPARAM);
void InitMenus();
void UnInitMenus();
int __cdecl OnPreBuildContactMenu(WPARAM hContact, LPARAM);
//==== PopUps ========================================================================
void InitPopups(void);
void MsgPopup(MCONTACT hContact, const TCHAR *szMsg, const TCHAR *szTitle, bool err = false);
//==== Hooks =========================================================================
int __cdecl OnProcessSrmmEvent(WPARAM, LPARAM);
int __cdecl OnDbEventRead(WPARAM, LPARAM);
int __cdecl OnDbSettingChanged(WPARAM, LPARAM);
//==== Search ========================================================================
void __cdecl SearchBasicThread(void* id);
void __cdecl SearchByMailThread(void* email);
void __cdecl SearchThread(void* p);
void FreeProtoShearchStruct(PROTOSEARCHBYNAME *pParam);
void OnSearch(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnSearchByMail(NETLIBHTTPREQUEST *, AsyncHttpRequest *);
//==== Files Upload ==================================================================
void __cdecl SendFileThread(void *p);
void SendFileFiled(CVkFileUploadParam *fup, int ErrorCode);
void OnReciveUploadServer(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReciveUpload(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReciveUploadFile(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
//==== Feed ==========================================================================
void AddFeedSpecialUser();
void AddFeedEvent(CMString& tszBody, time_t tTime);
CVkUserInfo* GetVkUserInfo(LONG iUserId, OBJLIST<CVkUserInfo> &vkUsers);
void CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, const JSONNode &jnResponse);
CVKNewsItem* GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers, bool isRepost = false);
CVKNewsItem* GetVkGroupInvates(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers);
CVKNewsItem* GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers);
CMString GetVkFeedback(const JSONNode &jnFeedback, VKObjType vkFeedbackType, OBJLIST<CVkUserInfo> &vkUsers, CVkUserInfo *vkUser);
CVKNewsItem* GetVkParent(const JSONNode &jnParent, VKObjType vkParentType, LPCTSTR ptszReplyText = NULL, LPCTSTR ptszReplyLink = NULL);
void RetrieveUnreadNews(time_t tLastNewsTime);
void OnReceiveUnreadNews(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void RetrieveUnreadNotifications(time_t tLastNotificationsTime);
bool FilterNotification(CVKNewsItem* vkNotificationItem, bool& isCommented);
void NotificationMarkAsViewed();
void OnReceiveUnreadNotifications(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void RetrieveUnreadEvents();
void NewsClearHistory();
INT_PTR __cdecl SvcLoadVKNews(WPARAM, LPARAM);
//==== Misc ==========================================================================
TCHAR* GetUserStoredPassword(void);
void SetAllContactStatuses(int status);
MCONTACT FindUser(LONG userid, bool bCreate = false);
MCONTACT FindChat(LONG dwUserid);
bool CheckMid(LIST<void> &lList, int guid);
JSONNode& CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONNode &root);
bool CheckJsonResult(AsyncHttpRequest *pReq, const JSONNode &Node);
void OnReceiveSmth(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
bool AutoFillForm(char*, CMStringA&, CMStringA&);
CMString RunConfirmationCode();
void GrabCookies(NETLIBHTTPREQUEST *nhr);
void ApplyCookies(AsyncHttpRequest*);
void __cdecl DBAddAuthRequestThread(void *p);
void DBAddAuthRequest(const MCONTACT hContact);
MCONTACT MContactFromDbEvent(MEVENT hDbEvent);
void SetMirVer(MCONTACT hContact, int platform);
void __cdecl ContactTypingThread(void *p);
void SetSrmmReadStatus(MCONTACT hContact);
char* GetStickerId(const char* Msg, int& stickerid);
CMString SpanVKNotificationType(CMString& tszType, VKObjType& vkFeedback, VKObjType& vkParent);
CMString GetVkPhotoItem(const JSONNode &jnPhoto, BBCSupport iBBC);
CMString SetBBCString(LPCTSTR tszString, BBCSupport iBBC, VKBBCType bbcType, LPCTSTR tszAddString = NULL);
CMString& ClearFormatNick(CMString& tszText);
CMString GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport iBBC = bbcNo);
CMString GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, BBCSupport iBBC = bbcNo);
void SetInvisible(MCONTACT hContact);
//====================================================================================
void RetrieveStatusMsg(const CMString &StatusMsg);
void RetrieveStatusMusic(const CMString &StatusMsg);
void OnReceiveStatus(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveStatusMsg(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
MCONTACT SetContactInfo(const JSONNode &jnItem, bool flag = false, bool self = false);
void RetrieveMyInfo(void);
void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void RetrieveUserInfo(LONG userId);
void RetrieveUsersInfo(bool flag = false);
void OnReceiveUserInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void RetrieveFriends();
void OnReceiveFriends(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void MarkMessagesRead(const CMStringA &mids);
void MarkMessagesRead(const MCONTACT hContact);
void RetrieveMessagesByIds(const CMStringA &mids);
void RetrieveUnreadMessages();
void OnReceiveMessages(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveDlgs(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnSendMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void WallPost(MCONTACT hContact, TCHAR *ptszMsg, TCHAR *ptszUrl, bool bFriendsOnly);
void GetServerHistoryLastNDay(MCONTACT hContact, int NDay);
void GetServerHistory(MCONTACT hContact, int iOffset, int iCount, int iTime, int iLastMsgId, bool once = false);
void OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq);
void GetHistoryDlg(MCONTACT hContact, int iLastMsg);
void RetrievePollingInfo();
void OnReceivePollingInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void __cdecl PollingThread(void*);
int PollServer();
void PollUpdates(const JSONNode&);
void OnReceivePolling(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveAuthRequest(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveDeleteFriend(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void SetServerStatus(int);
void CreateNewChat(LPCSTR uids, LPCTSTR ptrszTitle);
void OnCreateNewChat(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
__forceinline bool IsOnline() const { return m_bOnline; }
__forceinline LPCTSTR getGroup() const { return m_defaultGroup; }
__forceinline void setGroup(LPCTSTR grp) { m_defaultGroup = mir_tstrdup(grp); }
static mir_cs m_csTimer;
static UINT_PTR m_timer;
private:
friend struct AsyncHttpRequest;
LIST<AsyncHttpRequest> m_arRequestsQueue;
mir_cs m_csRequestsQueue;
HANDLE m_evRequestsQueue;
HANDLE m_hWorkerThread;
bool m_bTerminated, m_bServerDelivery;
CMStringA m_prevUrl;
enum CLMenuIndexes {
CMI_VISITPROFILE,
CMI_WALLPOST,
CMI_ADDASFRIEND,
CMI_DELETEFRIEND,
CMI_BANUSER,
CMI_REPORTABUSE,
CMI_DESTROYKICKCHAT,
CMI_OPENBROADCAST,
CMI_LOADVKNEWS,
CMI_GETSERVERHISTORY,
CMI_COUNT
};
enum CLMenuHistoruIndexes {
CHMI_GETSERVERHISTORY,
CHMI_GETSERVERHISTORYLAST1DAY,
CHMI_GETSERVERHISTORYLAST3DAY,
CHMI_GETSERVERHISTORYLAST7DAY,
CHMI_GETSERVERHISTORYLAST30DAY,
CHMI_GETSERVERHISTORYLAST90DAY,
CHMI_GETALLSERVERHISTORY,
CHMI_COUNT
};
enum ProtoMenuIndexes {
PMI_CREATECHAT,
PMI_SETSTATUSMSG,
PMI_WALLPOST,
PMI_LOADVKNEWS,
PMI_VISITPROFILE,
PMI_COUNT
};
HGENMENU g_hContactMenuItems[CMI_COUNT];
HGENMENU g_hContactHistoryMenuItems[CHMI_COUNT];
HGENMENU g_hProtoMenuItems[PMI_COUNT];
struct Cookie
{
Cookie(const CMStringA& name, const CMStringA& value, const CMStringA& domain) :
m_name(name),
m_value(value),
m_domain(domain)
{}
CMStringA m_name, m_value, m_domain;
};
OBJLIST<Cookie> m_cookies;
void InitQueue();
void UninitQueue();
void ExecuteRequest(AsyncHttpRequest*);
void __cdecl WorkerThread(void*);
AsyncHttpRequest* Push(AsyncHttpRequest*, int iTimeout = 10000);
bool RunCaptchaForm(LPCSTR szUrl, CMStringA&);
bool ApplyCaptcha(AsyncHttpRequest *pReq, const JSONNode&);
void ConnectionFailed(int iReason);
void OnLoggedIn();
void OnLoggedOut();
void ShutdownSession();
void SetAvatarUrl(MCONTACT hContact, CMString &tszUrl);
void GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen);
void ReloadAvatarInfo(MCONTACT hContact);
void __cdecl SendMsgAck(void *param);
//============== Options =============================================================
bool m_prevError,
m_bOnline,
m_bNeedSendOnline,
m_bHideChats,
m_bMesAsUnread,
m_bUseLocalTime,
m_bReportAbuse,
m_bClearServerHistory,
m_bRemoveFromFrendlist,
m_bRemoveFromClist,
m_bPopUpSyncHistory,
m_bStikersAsSmyles,
m_bUserForceOnlineOnActivity,
m_bNewsEnabled,
m_bNotificationsEnabled,
m_bNotificationsMarkAsViewed,
m_bSpecialContactAlwaysEnabled,
m_bNewsAutoClearHistory,
m_bNewsFilterPosts,
m_bNewsFilterPhotos,
m_bNewsFilterTags,
m_bNewsFilterWallPhotos,
m_bNewsSourceFriends,
m_bNewsSourceGroups,
m_bNewsSourcePages,
m_bNewsSourceFollowing,
m_bNewsSourceIncludeBanned,
m_bNewsSourceNoReposts,
m_bNotificationFilterComments,
m_bNotificationFilterLikes,
m_bNotificationFilterReposts,
m_bNotificationFilterMentions,
m_bNotificationFilterInvites,
m_bUseBBCOnAttacmentsAsNews,
m_bUseNonStandardUrlEncode,
m_bSetBroadcast,
m_bShortenLinksForAudio,
m_bSplitFormatFwdMsg;
int m_iNewsInterval,
m_iNotificationsInterval,
m_iNewsAutoClearHistoryInterval,
m_iMaxLoadNewsPhoto,
m_iInvisibleInterval;
enum MarkMsgReadOn { markOnRead, markOnReceive, markOnReply, markOnTyping };
MarkMsgReadOn m_iMarkMessageReadOn;
enum SyncHistoryMetod { syncOff, syncAuto, sync1Days, sync3Days };
SyncHistoryMetod m_iSyncHistoryMetod;
enum MusicSendMetod { sendNone, sendStatusOnly, sendBroadcastOnly, sendBroadcastAndStatus };
MusicSendMetod m_iMusicSendMetod;
enum IMGBBCSypport { imgNo, imgFullSize, imgPreview130, imgPreview604 };
IMGBBCSypport m_iIMGBBCSupport;
BBCSupport m_iBBCForNews,
m_iBBCForAttachments;
LONG m_myUserId;
ptrT m_defaultGroup;
ptrA
m_pollingServer,
m_pollingKey,
m_pollingTs,
m_szAccessToken;
HANDLE
m_pollingConn,
m_hPollingThread,
m_hPopupClassError,
m_hPopupClassNotification;
ULONG m_msgId;
LIST<void> m_sendIds;
LIST<void> m_incIds;
static INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static INT_PTR CALLBACK OptionsAdvProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static INT_PTR CALLBACK OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static INT_PTR CALLBACK OptionsViewProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
OBJLIST<CVkChatInfo> m_chats;
CVkChatInfo* AppendChat(int id, const JSONNode &jnNode);
void SetChatTitle(CVkChatInfo *cc, LPCTSTR tszTopic);
void AppendChatMessage(int id, const JSONNode &jnMsg, const JSONNode &jnFUsers, bool bIsHistory);
void AppendChatMessage(CVkChatInfo *cc, int uid, int msgTime, LPCTSTR ptszBody, bool bIsHistory, bool bIsAction = false);
void RetrieveChatInfo(CVkChatInfo*);
void OnReceiveChatInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnSendChatMsg(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnChatLeave(NETLIBHTTPREQUEST*, AsyncHttpRequest *);
void OnChatDestroy(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
int __cdecl OnChatEvent(WPARAM, LPARAM);
int __cdecl OnGcMenuHook(WPARAM, LPARAM);
void KickFromChat(int chat_id, int user_id, const JSONNode &jnMsg, const JSONNode &jnFUsers);
void LeaveChat(int chat_id, bool close_window = true, bool delete_chat = false);
INT_PTR __cdecl OnLeaveChat(WPARAM, LPARAM);
INT_PTR __cdecl OnJoinChat(WPARAM, LPARAM);
void LogMenuHook(CVkChatInfo*, GCHOOK*);
void NickMenuHook(CVkChatInfo*, GCHOOK*);
LPTSTR ChangeChatTopic(CVkChatInfo*);
void SetChatStatus(MCONTACT hContact, int iStatus);
CVkChatInfo* GetChatById(LPCTSTR ptszId);
INT_PTR __cdecl SvcCreateChat(WPARAM, LPARAM);
};
|