From 9fe76eefc0d2cf962f7845d8fbcd1fc92c8bc3b4 Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Fri, 17 Oct 2014 06:38:34 +0000 Subject: VKontakte: some cleanup add more debuglog git-svn-id: http://svn.miranda-ng.org/main/trunk@10811 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/misc.cpp | 16 +++++++++++++++- protocols/VKontakte/src/vk_captcha.cpp | 1 + protocols/VKontakte/src/vk_proto.cpp | 16 +++++++++++++--- protocols/VKontakte/src/vk_queue.cpp | 6 +++++- protocols/VKontakte/src/vk_thread.cpp | 24 ++++++++++++++++-------- 5 files changed, 50 insertions(+), 13 deletions(-) (limited to 'protocols/VKontakte/src') diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 866ea48068..b21d296420 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -19,12 +19,14 @@ along with this program. If not, see . TCHAR* CVkProto::GetUserStoredPassword() { + debugLogA("CVkProto::GetUserStoredPassword"); ptrA szRawPass( getStringA("Password")); return (szRawPass != NULL) ? mir_utf8decodeT(szRawPass) : NULL; } void CVkProto::SetAllContactStatuses(int iStatus) { + debugLogA("CVkProto::SetAllContactStatuses (%d)", iStatus); for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (isChatRoom(hContact)) SetChatStatus(hContact, iStatus); @@ -96,6 +98,7 @@ LPCSTR findHeader(NETLIBHTTPREQUEST *pReq, LPCSTR szField) JSONNODE* CVkProto::CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONROOT &pRoot) { + debugLogA("CVkProto::CheckJsonResponse"); pRoot.Parse(reply->pData); if (pRoot == NULL) return NULL; @@ -108,6 +111,7 @@ JSONNODE* CVkProto::CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONNODE *pNode) { + debugLogA("CVkProto::CheckJsonResult"); if (pNode == NULL) return false; @@ -145,12 +149,14 @@ bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, if (pReq->m_iRetry > 0){ pReq->bNeedsRestart = true; Sleep(500); //Pause for fix err + debugLogA("CVkProto::CheckJsonResult Retry = %d", pReq->m_iRetry); pReq->m_iRetry--; } else{ CMString msg, msgformat = TranslateT("Error %d. Data will not be sent or received."); msg.AppendFormat(msgformat, iErrorCode); MsgPopup(NULL, msg.GetBuffer(), TranslateT("Error"), true); + debugLogA("CVkProto::CheckJsonResult SendError"); } break; case VKERR_HIMSELF_AS_FRIEND: @@ -231,6 +237,7 @@ LBL_NotFound: bool CVkProto::AutoFillForm(char *pBody, CMStringA &szAction, CMStringA& szResult) { + debugLogA("CVkProto::AutoFillForm"); szResult.Empty(); char *pFormBeg = strstr(pBody, "
headersCount; i++) { if ( _stricmp(nhr->headers[i].szName, "Set-cookie")) continue; @@ -380,6 +389,7 @@ void CVkProto::GrabCookies(NETLIBHTTPREQUEST *nhr) void CVkProto::ApplyCookies(AsyncHttpRequest *pReq) { + debugLogA("CVkProto::ApplyCookies"); CMStringA szCookie; for (int i=0; i < m_cookies.getCount(); i++) { @@ -399,6 +409,7 @@ void CVkProto::ApplyCookies(AsyncHttpRequest *pReq) void CVkProto::DBAddAuthRequest(const MCONTACT hContact) { + debugLogA("CVkProto::DBAddAuthRequest"); //char* szJid = mir_utf8encodeT(jid); CMString tszNick = db_get_sa(hContact, m_szModuleName, "Nick"); char* szNick = mir_utf8encodeT(tszNick.GetBuffer()); @@ -439,6 +450,7 @@ void CVkProto::DBAddAuthRequest(const MCONTACT hContact) MCONTACT CVkProto::MContactFromDbEvent(HANDLE hDbEvent) { + debugLogA("CVkProto::MContactFromDbEvent"); if (!hDbEvent || !IsOnline()) return (MCONTACT)-1; @@ -531,6 +543,7 @@ bool tlstrstr(TCHAR* _s1, TCHAR* _s2) void CVkProto::ContactTypingThread(void *p) { + debugLogA("CVkProto::ContactTypingThread"); MCONTACT hContact = (MCONTACT)p; CallService(MS_PROTO_CONTACTISTYPING, hContact, 5); Sleep(5500); @@ -541,6 +554,7 @@ void CVkProto::ContactTypingThread(void *p) int CVkProto::OnProcessSrmmEvent(WPARAM, LPARAM lParam) { + debugLogA("CVkProto::OnProcessSrmmEvent"); MessageWindowEventData *event = (MessageWindowEventData *)lParam; if (event->uType == MSG_WINDOW_EVT_OPENING) @@ -565,7 +579,7 @@ void CVkProto::SetSrmmReadStatus(MCONTACT hContact) CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)&st); } -char* CVkProto::GetStickerId (const char* Msg, int &stickerid) +char* CVkProto::GetStickerId(const char* Msg, int &stickerid) { int iRes = 0; char HeadMsg[32] = { 0 }; diff --git a/protocols/VKontakte/src/vk_captcha.cpp b/protocols/VKontakte/src/vk_captcha.cpp index 89b77168e7..715e36761f 100644 --- a/protocols/VKontakte/src/vk_captcha.cpp +++ b/protocols/VKontakte/src/vk_captcha.cpp @@ -143,6 +143,7 @@ bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) bool CVkProto::ApplyCaptcha(AsyncHttpRequest *pReq, JSONNODE *pErrorNode) { + debugLogA("CVkProto::ApplyCaptcha"); char *szUrl = NEWSTR_ALLOCA( _T2A( json_as_string( json_get(pErrorNode, "captcha_img")))); char *szSid = NEWSTR_ALLOCA( _T2A( json_as_string( json_get(pErrorNode, "captcha_sid")))); if (szUrl == NULL || szSid == NULL) diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index cabf6d9c84..be7ecce320 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -324,6 +324,7 @@ DWORD_PTR CVkProto::GetCaps(int type, MCONTACT hContact) int CVkProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) { + debugLogA("CVkProto::RecvMsg"); Proto_RecvMessage(hContact, pre); return 0; } @@ -332,6 +333,7 @@ int CVkProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) void CVkProto::SendMsgAck(void *param) { + debugLogA("CVkProto::SendMsgAck"); TFakeAckParams *ack = (TFakeAckParams*)param; Sleep(100); ProtoBroadcastAck(ack->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)ack->msgid, 0); @@ -340,6 +342,7 @@ void CVkProto::SendMsgAck(void *param) int CVkProto::SendMsg(MCONTACT hContact, int flags, const char *msg) { + debugLogA("CVkProto::SendMsg"); LONG userID = getDword(hContact, "ID", -1); if (userID == -1) return 0; @@ -416,6 +419,7 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) int CVkProto::SetStatus(int iNewStatus) { + debugLogA("CVkProto::SetStatus iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus); if (m_iDesiredStatus == iNewStatus || iNewStatus == ID_STATUS_IDLE) return 0; @@ -423,7 +427,7 @@ int CVkProto::SetStatus(int iNewStatus) m_iDesiredStatus = iNewStatus; if (iNewStatus == ID_STATUS_OFFLINE) { - if ( IsOnline()) { + if (IsOnline()) { SetServerStatus(ID_STATUS_OFFLINE); debugLogA("CVkProto::SetStatus ShutdownSession"); ShutdownSession(); @@ -437,7 +441,7 @@ int CVkProto::SetStatus(int iNewStatus) ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); m_hWorkerThread = ForkThreadEx(&CVkProto::WorkerThread, 0, NULL); } - else if ( IsOnline()) + else if (IsOnline()) SetServerStatus(iNewStatus); else ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); @@ -467,6 +471,8 @@ int CVkProto::OnEvent(PROTOEVENTTYPE event, WPARAM wParam, LPARAM lParam) MCONTACT CVkProto::AddToList(int flags, PROTOSEARCHRESULT* psr) { + debugLogA("CVkProto::AddToList"); + int uid = _ttoi(psr->id); if (!uid) return NULL; @@ -500,8 +506,8 @@ int CVkProto::AuthRequest(MCONTACT hContact,const PROTOCHAR* message) void CVkProto::OnReceiveAuthRequest(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) { - CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo; debugLogA("CVkProto::OnReceiveAuthRequest %d", reply->resultCode); + CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo; if (reply->resultCode == 200){ JSONROOT pRoot; JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot); @@ -537,6 +543,7 @@ void CVkProto::OnReceiveAuthRequest(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * int CVkProto::Authorize(HANDLE hDbEvent) { + debugLogA("CVkProto::Authorize"); MCONTACT hContact = MContactFromDbEvent(hDbEvent); if (hContact == -1) return 1; @@ -546,6 +553,7 @@ int CVkProto::Authorize(HANDLE hDbEvent) int CVkProto::AuthDeny(HANDLE hDbEvent, const PROTOCHAR *reason) { + debugLogA("CVkProto::AuthDeny"); MCONTACT hContact = MContactFromDbEvent(hDbEvent); if (hContact == -1) return 1; @@ -555,6 +563,7 @@ int CVkProto::AuthDeny(HANDLE hDbEvent, const PROTOCHAR *reason) int CVkProto::UserIsTyping(MCONTACT hContact, int type) { + debugLogA("CVkProto::UserIsTyping"); if (PROTOTYPE_SELFTYPING_ON == type) { LONG userID = getDword(hContact, "ID", -1); if ((userID == -1)||(!IsOnline())) @@ -584,6 +593,7 @@ int CVkProto::AuthRecv(MCONTACT hContact,PROTORECVEVENT *) int CVkProto::GetInfo(MCONTACT hContact, int infoType) { + debugLogA("CVkProto::GetInfo"); LONG userID = getDword(hContact, "ID", -1); if (userID == -1) return 1; diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index 08caa1684a..71ce7e8687 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -19,11 +19,13 @@ along with this program. If not, see . void CVkProto::InitQueue() { + debugLogA("CVkProto::InitQueue"); m_evRequestsQueue = CreateEvent(NULL, FALSE, FALSE, NULL); } void CVkProto::UninitQueue() { + debugLogA("CVkProto::UninitQueue"); m_arRequestsQueue.destroy(); CloseHandle(m_evRequestsQueue); } @@ -48,7 +50,7 @@ LBL_Restart: } } - debugLogA("CVkProto::ExecuteRequest %s", pReq->szUrl); + debugLogA("CVkProto::ExecuteRequest \n====\n%s\n====\n", pReq->szUrl); NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)pReq); if (reply != NULL) { if (pReq->m_pFunc != NULL) @@ -73,6 +75,7 @@ LBL_Restart: AsyncHttpRequest* CVkProto::Push(AsyncHttpRequest *pReq, int iTimeout) { + debugLogA("CVkProto::Push"); pReq->timeout = iTimeout; { mir_cslock lck(m_csRequestsQueue); @@ -124,6 +127,7 @@ void CVkProto::WorkerThread(void*) ExecuteRequest(pReq); if (need_sleep) // There can be maximum 3 requests to API methods per second from a client Sleep(330); // (c) https://vk.com/dev/api_requests + debugLogA("CVkProto::WorkerThread: while"); } } diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 1babac70be..5d526189e5 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -23,6 +23,7 @@ char szBlankUrl[] = "http://api.vk.com/blank.html"; void CVkProto::ShutdownSession() { + debugLogA("CVkProto::ShutdownSession"); if (m_hWorkerThread) { m_bTerminated = true; SetEvent(m_evRequestsQueue); @@ -63,6 +64,7 @@ static void CALLBACK VKUnsetTimer(void *pObject) void CVkProto::OnLoggedIn() { + debugLogA("CVkProto::OnLoggedIn"); m_bOnline = true; SetServerStatus(m_iDesiredStatus); @@ -73,6 +75,7 @@ void CVkProto::OnLoggedIn() void CVkProto::OnLoggedOut() { + debugLogA("CVkProto::OnLoggedOut"); m_bOnline = false; if (m_pollingConn) @@ -208,6 +211,7 @@ LBL_NoForm: void CVkProto::RetrieveMyInfo() { + debugLogA("CVkProto::RetrieveMyInfo"); Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnReceiveMyInfo) << VER_API); } @@ -241,7 +245,7 @@ static char fieldsName[] = "id, first_name, last_name, photo_100, bdate, sex, ti MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self) { - debugLogA("CVkProto::SetContactInfo flag=%d self = %d", flag, self); + debugLogA("CVkProto::SetContactInfo"); if (pItem == NULL) return -1; @@ -354,7 +358,7 @@ MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self) void CVkProto::RetrieveUserInfo(LONG userID) { - debugLogA("CVkProto::RetrieveUserInfo %d", userID); + debugLogA("CVkProto::RetrieveUserInfo (%d)", userID); CMString userIDs, code; userIDs.AppendFormat(L"%i", userID); CMString codeformat("var userIDs=\"%s\";" @@ -491,6 +495,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq ///////////////////////////////////////////////////////////////////////////////////////// int CVkProto::OnDbEventRead(WPARAM hContact, LPARAM) { + debugLogA("CVkProto::OnDbEventRead"); if (m_iMarkMessageReadOn == markOnRead) MarkMessagesRead(hContact); return 0; @@ -498,6 +503,7 @@ int CVkProto::OnDbEventRead(WPARAM hContact, LPARAM) void CVkProto::MarkMessagesRead(const CMStringA &mids) { + debugLogA("CVkProto::MarkMessagesRead (mids)"); if (mids.IsEmpty()) return; @@ -508,6 +514,7 @@ void CVkProto::MarkMessagesRead(const CMStringA &mids) void CVkProto::MarkMessagesRead(const MCONTACT hContact) { + debugLogA("CVkProto::MarkMessagesRead (hContact)"); LONG userID = getDword(hContact, "ID", -1); if (userID == -1) return; @@ -519,6 +526,7 @@ void CVkProto::MarkMessagesRead(const MCONTACT hContact) void CVkProto::RetrieveMessagesByIds(const CMStringA &mids) { + debugLogA("CVkProto::RetrieveMessagesByIds"); if (mids.IsEmpty()) return; @@ -632,9 +640,7 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) return; if (m_bAutoSyncHistory&&m_bPopUpSyncHistory) MsgPopup(NULL, TranslateT("Start sync history"), TranslateT("Sync history")); - debugLogA("CVkProto::OnReceiveDlgs numDlgs = %d", numDlgs); for (int i = 0; i < numDlgs; i++) { - debugLogA("CVkProto::OnReceiveDlgs i = %d", i); JSONNODE *pDlg = json_at(pDlgs, i); if (pDlg == NULL) break; @@ -699,6 +705,7 @@ void CVkProto::GetHistoryDlg(MCONTACT hContact, int iLastMsg) void CVkProto::GetHistoryDlgMessages(MCONTACT hContact, int iOffset, int iMaxCount, int lastcount) { + debugLogA("CVkProto::GetHistoryDlgMessages"); LONG userID = getDword(hContact, "ID", -1); if (-1 == userID) return; @@ -795,7 +802,6 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque void CVkProto::RetrievePollingInfo() { debugLogA("CVkProto::RetrievePollingInfo"); - Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getLongPollServer.json", true, &CVkProto::OnReceivePollingInfo) << VER_API); } @@ -823,7 +829,6 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * void CVkProto::RetrieveStatusMsg(const CMString &StatusMsg) { debugLogA("CVkProto::RetrieveStatusMsg"); - Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/status.set.json", true, &CVkProto::OnReceiveSmth) << TCHAR_PARAM("text", StatusMsg) << VER_API); @@ -860,6 +865,7 @@ void CVkProto::RetrieveStatusMusic(const CMString &StatusMsg) INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM wParam, LPARAM lParam) { + debugLogA("CVkProto::SvcSetListeningTo"); LISTENINGTOINFO *pliInfo = (LISTENINGTOINFO*)lParam; CMStringW wszListeningTo; if (pliInfo == NULL || pliInfo->cbSize != sizeof(LISTENINGTOINFO)) @@ -880,6 +886,7 @@ INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM wParam, LPARAM lParam) ///////////////////////////////////////////////////////////////////////////////////////// INT_PTR __cdecl CVkProto::SvcAddAsFriend(WPARAM hContact, LPARAM) { + debugLogA("CVkProto::SvcAddAsFriend"); CallContactService(hContact, PSS_AUTHREQUESTW, 0, (LPARAM)TranslateT("Please authorize me to add you to my friend list.")); return 0; } @@ -908,8 +915,8 @@ INT_PTR __cdecl CVkProto::SvcDeleteFriend(WPARAM hContact, LPARAM flag) void CVkProto::OnReceiveDeleteFriend(NETLIBHTTPREQUEST* reply, AsyncHttpRequest* pReq) { - CVkSendMsgParam *param = (CVkSendMsgParam*) pReq->pUserInfo; debugLogA("CVkProto::OnReceiveDeleteFriend %d", reply->resultCode); + CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo; if (reply->resultCode == 200){ JSONROOT pRoot; JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot); @@ -1027,6 +1034,7 @@ INT_PTR __cdecl CVkProto::SvcReportAbuse(WPARAM hContact, LPARAM) INT_PTR __cdecl CVkProto::SvcVisitProfile(WPARAM hContact, LPARAM) { + debugLogA("CVkProto::SvcVisitProfile"); LONG userID = getDword(hContact, "ID", -1); ptrT tszDomain(db_get_tsa(hContact, m_szModuleName, "domain")); CMString tszUrl("https://vk.com/"); @@ -1043,6 +1051,7 @@ INT_PTR __cdecl CVkProto::SvcVisitProfile(WPARAM hContact, LPARAM) INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM hContact, LPARAM) { + debugLogA("CVkProto::SvcGetAllServerHistory"); LPCTSTR str = TranslateT("Are you sure to reload all messages from vk.com?\nLocal contact history will be deleted and reloaded from the server.\nIt may take a long time.\nDo you want to continue?"); if (IDNO == MessageBox(NULL, str, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO)) return 0; @@ -1067,7 +1076,6 @@ INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM hContact, LPARAM) void CVkProto::PollUpdates(JSONNODE *pUpdates) { debugLogA("CVkProto::PollUpdates"); - CMStringA mids; int msgid, uid, flags, platform; MCONTACT hContact; -- cgit v1.2.3