summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp405
1 files changed, 208 insertions, 197 deletions
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index 6e66c0c0c2..a29d2d11d9 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -20,6 +20,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
UINT_PTR CVkProto::m_timer;
char szBlankUrl[] = "http://api.vk.com/blank.html";
+static char* szImageTypes[] = { "photo_2560", "photo_1280", "photo_807", "photo_604", "photo_256", "photo_130", "photo_128", "photo_75", "photo_64" };
+static char VK_TOKEN_BEG[] = "access_token=";
+static char fieldsName[] = "id, first_name, last_name, photo_100, bdate, sex, timezone, contacts, online, status, about, domain";
+
+/////////////////////////////////////////////////////////////////////////////////////////
void CVkProto::ShutdownSession()
{
@@ -41,6 +46,8 @@ void CVkProto::ConnectionFailed(int iReason)
ShutdownSession();
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
{
for (int i = 0; i < vk_Instances.getCount(); i++){
@@ -62,6 +69,8 @@ static void CALLBACK VKUnsetTimer(void *pObject)
CVkProto::m_timer = 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CVkProto::OnLoggedIn()
{
debugLogA("CVkProto::OnLoggedIn");
@@ -86,7 +95,7 @@ void CVkProto::OnLoggedOut()
bool bOnline = false;
for (int i=0; i < vk_Instances.getCount(); i++)
- bOnline = bOnline&&vk_Instances[i]->IsOnline();
+ bOnline = bOnline && vk_Instances[i]->IsOnline();
if(!bOnline)
CallFunctionAsync(VKUnsetTimer, this);
SetAllContactStatuses(ID_STATUS_OFFLINE);
@@ -126,8 +135,6 @@ void CVkProto::SetServerStatus(int iNewStatus)
/////////////////////////////////////////////////////////////////////////////////////////
-static char VK_TOKEN_BEG[] = "access_token=";
-
void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
debugLogA("CVkProto::OnOAuthAuthorize %d", reply->resultCode);
@@ -242,10 +249,6 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
RetrievePollingInfo();
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static char fieldsName[] = "id, first_name, last_name, photo_100, bdate, sex, timezone, contacts, online, status, about, domain";
-
MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self)
{
debugLogA("CVkProto::SetContactInfo");
@@ -348,7 +351,7 @@ MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self)
tszValue = json_as_string(json_get(pAudio, "url"));
db_set_ts(hContact, m_szModuleName, "AudioUrl", tszValue.GetBuffer());
}
- else if ((tszValue.GetBuffer()[0] == TCHAR(9835)) && (tszValue.GetLength() > 2))
+ else if (tszValue.GetBuffer()[0] == TCHAR(9835) && tszValue.GetLength() > 2)
db_set_ts(hContact, m_szModuleName, "ListeningTo", &(tszValue.GetBuffer())[2]);
else
db_unset(hContact, m_szModuleName, "ListeningTo");
@@ -387,6 +390,7 @@ void CVkProto::RetrieveUsersInfo(bool flag)
debugLogA("CVkProto::RetrieveUsersInfo");
if (!IsOnline())
return;
+
CMString userIDs, code;
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)){
LONG userID = getDword(hContact, "ID", -1);
@@ -414,7 +418,7 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
{
debugLogA("CVkProto::OnReceiveUserInfo %d", reply->resultCode);
- if ((reply->resultCode != 200) || !IsOnline())
+ if (reply->resultCode != 200 || !IsOnline())
return;
JSONROOT pRoot;
@@ -434,7 +438,7 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
int iCount = json_as_int(json_get(pRequests, "count"));
JSONNODE *pItems = json_get(pRequests, "items"), *pInfo;
- if (!iCount||(pItems == NULL))
+ if (!iCount || pItems == NULL)
return;
debugLogA("CVkProto::OnReceiveUserInfo AuthRequests");
@@ -452,8 +456,6 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
}
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
void CVkProto::RetrieveFriends()
{
debugLogA("CVkProto::RetrieveFriends");
@@ -468,7 +470,7 @@ void CVkProto::RetrieveFriends()
void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
debugLogA("CVkProto::OnReceiveFriends %d", reply->resultCode);
- if ((reply->resultCode != 200) || !IsOnline())
+ if (reply->resultCode != 200 || !IsOnline())
return;
JSONROOT pRoot;
@@ -484,7 +486,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq
setByte(hContact, "Auth", 1);
db_unset(hContact, m_szModuleName, "ReqAuth");
SetMirVer(hContact, -1);
- if (bCleanContacts&&!isChatRoom(hContact))
+ if (bCleanContacts && !isChatRoom(hContact))
arContacts.insert((HANDLE)hContact);
}
@@ -495,7 +497,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq
for (int i = 0; i<iCount; i++) {
MCONTACT hContact = SetContactInfo(json_at(pItems, i), true);
- if ((hContact == NULL) || hContact == -1)
+ if (hContact == NULL || hContact == -1)
continue;
arContacts.remove((HANDLE)hContact);
@@ -508,6 +510,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq
}
/////////////////////////////////////////////////////////////////////////////////////////
+
int CVkProto::OnDbEventRead(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::OnDbEventRead");
@@ -565,8 +568,6 @@ void CVkProto::RetrieveUnreadMessages()
<< VER_API);
}
-static char* szImageTypes[] = { "photo_2560", "photo_1280", "photo_807", "photo_604", "photo_256", "photo_130", "photo_128", "photo_75", "photo_64" };
-
void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
debugLogA("CVkProto::OnReceiveMessages %d", reply->resultCode);
@@ -603,7 +604,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
char szMid[40];
_itoa(mid, szMid, 10);
- if ((m_iMarkMessageReadOn == markOnReceive) || (chat_id != 0)){
+ if (m_iMarkMessageReadOn == markOnReceive || chat_id != 0){
if (!mids.IsEmpty())
mids.AppendChar(',');
mids.Append(szMid);
@@ -621,7 +622,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
PROTORECVEVENT recv = { 0 };
recv.flags = PREF_TCHAR;
- if (isRead&&!m_bMesAsUnread)
+ if (isRead && !m_bMesAsUnread)
recv.flags |= PREF_CREATEREAD;
if (isOut)
recv.flags |= PREF_SENT;
@@ -685,14 +686,14 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
int uid = json_as_int(json_get(pDlg, "user_id"));
MCONTACT hContact = FindUser(uid, true);
- if ((getDword(hContact, "lastmsgid", -1) == -1) && numUnread){
+ if (getDword(hContact, "lastmsgid", -1) == -1 && numUnread){
setDword(hContact, "new_lastmsgid", mid);
GetHistoryDlgMessages(hContact, 0, numUnread, -1);
}
else
GetHistoryDlg(hContact, mid);
- if (m_iMarkMessageReadOn==markOnReceive&&numUnread)
+ if (m_iMarkMessageReadOn == markOnReceive&&numUnread)
MarkMessagesRead(hContact);
}
else if (numUnread) {
@@ -706,7 +707,7 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
MarkMessagesRead(hContact);
}
}
- if (m_bAutoSyncHistory&&m_bPopUpSyncHistory)
+ if (m_bAutoSyncHistory && m_bPopUpSyncHistory)
MsgPopup(NULL, TranslateT("Sync history complete"), TranslateT("Sync history"));
RetrieveUsersInfo();
}
@@ -717,7 +718,7 @@ void CVkProto::GetHistoryDlg(MCONTACT hContact, int iLastMsg)
{
debugLogA("CVkProto::GetHistoryDlg %d", iLastMsg);
int lastmsgid = getDword(hContact, "lastmsgid", -1);
- if ((lastmsgid == -1)||(!IsOnline())) {
+ if (lastmsgid == -1 || !IsOnline()) {
setDword(hContact, "lastmsgid", iLastMsg);
return;
}
@@ -822,6 +823,8 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque
delete param;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CVkProto::RetrievePollingInfo()
{
debugLogA("CVkProto::RetrievePollingInfo");
@@ -849,7 +852,161 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *
m_hPollingThread = ForkThreadEx(&CVkProto::PollingThread, NULL, NULL);
}
+void CVkProto::PollUpdates(JSONNODE *pUpdates)
+{
+ debugLogA("CVkProto::PollUpdates");
+ CMStringA mids;
+ int msgid, uid, flags, platform;
+ MCONTACT hContact;
+
+ JSONNODE *pChild;
+ for (int i = 0; (pChild = json_at(pUpdates, i)) != NULL; i++) {
+ switch (json_as_int(json_at(pChild, 0))) {
+ case VKPOLL_MSG_DELFLAGS:
+ flags = json_as_int(json_at(pChild, 2));
+ uid = json_as_int(json_at(pChild, 3));
+ hContact = FindUser(uid);
+ if (hContact != NULL) {
+ if (flags&VKFLAG_MSGUNREAD){
+ setDword(hContact, "LastMsgReadTime", time(NULL));
+ SetSrmmReadStatus(hContact);
+ }
+ if (m_bUserForceOnlineOnActivity)
+ setWord(hContact, "Status", ID_STATUS_ONLINE);
+ }
+ break;
+
+ case VKPOLL_MSG_ADDED: // new message
+ msgid = json_as_int(json_at(pChild, 1));
+
+ // skip outgoing messages sent from a client
+ flags = json_as_int(json_at(pChild, 2));
+ if (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT))
+ if (CheckMid(msgid))
+ break;
+
+ if (!mids.IsEmpty())
+ mids.AppendChar(',');
+ mids.AppendFormat("%d", msgid);
+ break;
+
+ case VKPOLL_READ_ALL_OUT:
+ uid = json_as_int(json_at(pChild, 1));
+ hContact = FindUser(uid);
+ if (hContact != NULL){
+ setDword(hContact, "LastMsgReadTime", time(NULL));
+ SetSrmmReadStatus(hContact);
+ if (m_bUserForceOnlineOnActivity)
+ setWord(hContact, "Status", ID_STATUS_ONLINE);
+ }
+ break;
+
+ case VKPOLL_USR_ONLINE:
+ uid = -json_as_int(json_at(pChild, 1));
+ if ((hContact = FindUser(uid)) != NULL)
+ setWord(hContact, "Status", ID_STATUS_ONLINE);
+ platform = json_as_int(json_at(pChild, 2));
+ SetMirVer(hContact, platform);
+ break;
+
+ case VKPOLL_USR_OFFLINE:
+ uid = -json_as_int(json_at(pChild, 1));
+ if ((hContact = FindUser(uid)) != NULL)
+ setWord(hContact, "Status", ID_STATUS_OFFLINE);
+ break;
+
+ case VKPOLL_USR_UTN:
+ uid = json_as_int(json_at(pChild, 1));
+ hContact = FindUser(uid);
+ if (hContact != NULL){
+ ForkThread(&CVkProto::ContactTypingThread, (void *)hContact);
+ if (m_bUserForceOnlineOnActivity)
+ setWord(hContact, "Status", ID_STATUS_ONLINE);
+ }
+ break;
+
+ case VKPOLL_CHAT_CHANGED:
+ int chat_id = json_as_int(json_at(pChild, 1));
+ CVkChatInfo *cc = m_chats.find((CVkChatInfo*)&chat_id);
+ if (cc)
+ RetrieveChatInfo(cc);
+ break;
+ }
+ }
+
+ RetrieveMessagesByIds(mids);
+}
+
+int CVkProto::PollServer()
+{
+ debugLogA("CVkProto::PollServer");
+ if (!IsOnline())
+ return 0;
+
+ NETLIBHTTPREQUEST req = { sizeof(req) };
+ req.requestType = REQUEST_GET;
+ req.szUrl = NEWSTR_ALLOCA(CMStringA().Format("http://%s?act=a_check&key=%s&ts=%s&wait=25&access_token=%s&mode=%d", m_pollingServer, m_pollingKey, m_pollingTs, m_szAccessToken, 106));
+ // see mode parametr description on https://vk.com/dev/using_longpoll (Russian version)
+ req.flags = VK_NODUMPHEADERS | NLHRF_PERSISTENT;
+ req.timeout = 30000;
+ req.nlc = m_pollingConn;
+
+ NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req);
+ if (reply == NULL) {
+ debugLogA("CVkProto::PollServer is dead");
+ m_pollingConn = NULL;
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
+ ShutdownSession();
+ return 0;
+ }
+
+ int retVal = 0;
+ if (reply->resultCode == 200) {
+ JSONROOT pRoot(reply->pData);
+ JSONNODE *pFailed = json_get(pRoot, "failed");
+ if (pFailed != NULL && json_as_int(pFailed) == 2) {
+ RetrievePollingInfo();
+ retVal = -1;
+ debugLogA("Polling key expired, restarting polling thread");
+ }
+ else if (CheckJsonResult(NULL, reply, pRoot)) {
+ m_pollingTs = mir_t2a(ptrT(json_as_string(json_get(pRoot, "ts"))));
+ JSONNODE *pUpdates = json_get(pRoot, "updates");
+ if (pUpdates != NULL)
+ PollUpdates(pUpdates);
+ retVal = 1;
+ }
+ }
+ else if ((reply->resultCode >= 400 && reply->resultCode <= 417)
+ || (reply->resultCode >= 500 && reply->resultCode <= 509)) {
+ debugLogA("CVkProto::PollServer is dead. Error code - %d", reply->resultCode);
+ m_pollingConn = NULL;
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
+ ShutdownSession();
+ return 0;
+ }
+
+ m_pollingConn = reply->nlc;
+
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
+ return retVal;
+}
+
+void CVkProto::PollingThread(void*)
+{
+ debugLogA("CVkProto::PollingThread: entering");
+
+ while (!m_bTerminated)
+ if (PollServer() == -1)
+ break;
+
+ m_hPollingThread = NULL;
+ m_pollingConn = NULL;
+ debugLogA("CVkProto::PollingThread: leaving");
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
+
void CVkProto::OnReceiveStatus(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
debugLogA("CVkProto::OnReceiveStatus %d", reply->resultCode);
@@ -880,7 +1037,7 @@ void CVkProto::RetrieveStatusMsg(const CMString &StatusMsg)
void CVkProto::RetrieveStatusMusic(const CMString &StatusMsg)
{
debugLogA("CVkProto::RetrieveStatusMusic");
- if (!IsOnline() || (m_iStatus == ID_STATUS_INVISIBLE) || (m_iMusicSendMetod == sendNone))
+ if (!IsOnline() || m_iStatus == ID_STATUS_INVISIBLE || m_iMusicSendMetod == sendNone)
return;
CMString code;
@@ -943,8 +1100,8 @@ INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM wParam, LPARAM lParam)
wszListeningTo = ptrT((LPWSTR)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)L"%artist% - %title%", (LPARAM)pliInfo));
else
wszListeningTo.Format(L"%s - %s",
- pliInfo->ptszArtist ? pliInfo->ptszArtist : _T(""),
- pliInfo->ptszTitle ? pliInfo->ptszTitle : _T(""));
+ pliInfo->ptszArtist ? pliInfo->ptszArtist : L"",
+ pliInfo->ptszTitle ? pliInfo->ptszTitle : L"");
setTString("ListeningTo", wszListeningTo);
}
RetrieveStatusMusic(wszListeningTo);
@@ -952,6 +1109,7 @@ INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM wParam, LPARAM lParam)
}
/////////////////////////////////////////////////////////////////////////////////////////
+
INT_PTR __cdecl CVkProto::SvcAddAsFriend(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::SvcAddAsFriend");
@@ -971,7 +1129,7 @@ INT_PTR __cdecl CVkProto::SvcDeleteFriend(WPARAM hContact, LPARAM flag)
CMString formatstr = TranslateT("Are you sure to delete %s from your friend list?"),
tszNick = db_get_tsa(hContact, m_szModuleName, "Nick"),
ptszMsg;
- if (flag==0){
+ if (flag == 0){
ptszMsg.AppendFormat(formatstr, tszNick.IsEmpty() ? TranslateT("(Unknown contact)") : tszNick);
if (IDNO == MessageBox(NULL, ptszMsg.GetBuffer(), TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO))
return 1;
@@ -1020,7 +1178,7 @@ INT_PTR __cdecl CVkProto::SvcBanUser(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::SvcBanUser");
LONG userID = getDword(hContact, "ID", -1);
- if (!IsOnline() || (userID == -1))
+ if (!IsOnline() || userID == -1)
return 1;
CMStringA code;
@@ -1083,7 +1241,7 @@ INT_PTR __cdecl CVkProto::SvcReportAbuse(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::SvcReportAbuse");
LONG userID = getDword(hContact, "ID", -1);
- if (!IsOnline() || (userID == -1))
+ if (!IsOnline() || userID == -1)
return 1;
CMString formatstr = TranslateT("Are you sure to report abuse on %s?"),
@@ -1159,159 +1317,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;
-
- JSONNODE *pChild;
- for (int i = 0; (pChild = json_at(pUpdates, i)) != NULL; i++) {
- switch (json_as_int(json_at(pChild, 0))) {
- case VKPOLL_MSG_DELFLAGS:
- flags = json_as_int(json_at(pChild, 2));
- uid = json_as_int(json_at(pChild, 3));
- hContact = FindUser(uid);
- if (hContact != NULL) {
- if (flags&VKFLAG_MSGUNREAD){
- setDword(hContact, "LastMsgReadTime", time(NULL));
- SetSrmmReadStatus(hContact);
- }
- if (m_bUserForceOnlineOnActivity)
- setWord(hContact, "Status", ID_STATUS_ONLINE);
- }
- break;
-
- case VKPOLL_MSG_ADDED: // new message
- msgid = json_as_int(json_at(pChild, 1));
-
- // skip outgoing messages sent from a client
- flags = json_as_int(json_at(pChild, 2));
- if ((flags & VKFLAG_MSGOUTBOX) && !(flags & VKFLAG_MSGCHAT))
- if (CheckMid(msgid))
- break;
-
- if (!mids.IsEmpty())
- mids.AppendChar(',');
- mids.AppendFormat("%d", msgid);
- break;
-
- case VKPOLL_READ_ALL_OUT:
- uid = json_as_int(json_at(pChild, 1));
- hContact = FindUser(uid);
- if (hContact != NULL){
- setDword(hContact, "LastMsgReadTime", time(NULL));
- SetSrmmReadStatus(hContact);
- if (m_bUserForceOnlineOnActivity)
- setWord(hContact, "Status", ID_STATUS_ONLINE);
- }
- break;
-
- case VKPOLL_USR_ONLINE:
- uid = -json_as_int(json_at(pChild, 1));
- if ((hContact = FindUser(uid)) != NULL)
- setWord(hContact, "Status", ID_STATUS_ONLINE);
- platform = json_as_int(json_at(pChild, 2));
- SetMirVer(hContact, platform);
- break;
-
- case VKPOLL_USR_OFFLINE:
- uid = -json_as_int(json_at(pChild, 1));
- if ((hContact = FindUser(uid)) != NULL)
- setWord(hContact, "Status", ID_STATUS_OFFLINE);
- break;
-
- case VKPOLL_USR_UTN:
- uid = json_as_int(json_at(pChild, 1));
- hContact = FindUser(uid);
- if (hContact != NULL){
- ForkThread(&CVkProto::ContactTypingThread, (void *)hContact);
- if (m_bUserForceOnlineOnActivity)
- setWord(hContact, "Status", ID_STATUS_ONLINE);
- }
- break;
-
- case VKPOLL_CHAT_CHANGED:
- int chat_id = json_as_int(json_at(pChild, 1));
- CVkChatInfo *cc = m_chats.find((CVkChatInfo*)&chat_id);
- if (cc)
- RetrieveChatInfo(cc);
- break;
- }
- }
-
- RetrieveMessagesByIds(mids);
-}
-
-int CVkProto::PollServer()
-{
- debugLogA("CVkProto::PollServer");
- if (!IsOnline())
- return 0;
-
- NETLIBHTTPREQUEST req = { sizeof(req) };
- req.requestType = REQUEST_GET;
- req.szUrl = NEWSTR_ALLOCA(CMStringA().Format("http://%s?act=a_check&key=%s&ts=%s&wait=25&access_token=%s&mode=%d", m_pollingServer, m_pollingKey, m_pollingTs, m_szAccessToken, 106));
- // see mode parametr description on https://vk.com/dev/using_longpoll (Russian version)
- req.flags = VK_NODUMPHEADERS | NLHRF_PERSISTENT;
- req.timeout = 30000;
- req.nlc = m_pollingConn;
-
- NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req);
- if (reply == NULL) {
- debugLogA("CVkProto::PollServer is dead");
- m_pollingConn = NULL;
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
- ShutdownSession();
- return 0;
- }
-
- int retVal = 0;
- if (reply->resultCode == 200) {
- JSONROOT pRoot(reply->pData);
- JSONNODE *pFailed = json_get(pRoot, "failed");
- if (pFailed != NULL && json_as_int(pFailed) == 2) {
- RetrievePollingInfo();
- retVal = -1;
- debugLogA("Polling key expired, restarting polling thread");
- }
- else if (CheckJsonResult(NULL, reply, pRoot)) {
- m_pollingTs = mir_t2a(ptrT(json_as_string(json_get(pRoot, "ts"))));
- JSONNODE *pUpdates = json_get(pRoot, "updates");
- if (pUpdates != NULL)
- PollUpdates(pUpdates);
- retVal = 1;
- }
- }
- else if (((reply->resultCode >= 400) && (reply->resultCode <= 417))
- || ((reply->resultCode >= 500) && (reply->resultCode <= 509))) {
- debugLogA("CVkProto::PollServer is dead. Error code - %d", reply->resultCode);
- m_pollingConn = NULL;
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
- ShutdownSession();
- return 0;
- }
-
- m_pollingConn = reply->nlc;
-
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
- return retVal;
-}
-
-void CVkProto::PollingThread(void*)
-{
- debugLogA("CVkProto::PollingThread: entering");
-
- while (!m_bTerminated)
- if (PollServer() == -1)
- break;
-
- m_hPollingThread = NULL;
- m_pollingConn = NULL;
- debugLogA("CVkProto::PollingThread: leaving");
-}
-
CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments)
{
debugLogA("CVkProto::GetAttachmentDescr");
@@ -1323,9 +1328,10 @@ CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments)
for (int k = 0; (pAttach = json_at(pAttachments, k)) != NULL; k++) {
res.AppendChar('\t');
ptrT ptszType(json_as_string(json_get(pAttach, "type")));
- if (!lstrcmp(ptszType, _T("photo"))) {
+ if (!lstrcmp(ptszType, L"photo")) {
JSONNODE *pPhoto = json_get(pAttach, "photo");
- if (pPhoto == NULL) continue;
+ if (pPhoto == NULL)
+ continue;
ptrT ptszLink;
for (int i = 0; i < SIZEOF(szImageTypes); i++) {
@@ -1342,47 +1348,52 @@ CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments)
if (m_bAddImgBbc)
res.AppendFormat(L"\n\t[img]%s[/img]", ptszLink);
}
- else if (!lstrcmp(ptszType, _T("audio"))) {
+ else if (!lstrcmp(ptszType, L"audio")) {
JSONNODE *pAudio = json_get(pAttach, "audio");
- if (pAudio == NULL) continue;
+ if (pAudio == NULL)
+ continue;
ptrT ptszArtist(json_as_string(json_get(pAudio, "artist")));
ptrT ptszTitle(json_as_string(json_get(pAudio, "title")));
ptrT ptszUrl(json_as_string(json_get(pAudio, "url")));
- res.AppendFormat(_T("%s: (%s - %s) - %s"),
+ res.AppendFormat(L"%s: (%s - %s) - %s",
TranslateT("Audio"), ptszArtist, ptszTitle, ptszUrl);
}
- else if (!lstrcmp(ptszType, _T("video"))) {
+ else if (!lstrcmp(ptszType, L"video")) {
JSONNODE *pVideo = json_get(pAttach, "video");
- if (pVideo == NULL) continue;
+ if (pVideo == NULL)
+ continue;
ptrT ptszTitle(json_as_string(json_get(pVideo, "title")));
int vid = json_as_int(json_get(pVideo, "id"));
int ownerID = json_as_int(json_get(pVideo, "owner_id"));
- res.AppendFormat(_T("%s: %s - http://vk.com/video%d_%d"),
+ res.AppendFormat(L"%s: %s - http://vk.com/video%d_%d",
TranslateT("Video"), ptszTitle, ownerID, vid);
}
- else if (!lstrcmp(ptszType, _T("doc"))) {
+ else if (!lstrcmp(ptszType, L"doc")) {
JSONNODE *pDoc = json_get(pAttach, "doc");
- if (pDoc == NULL) continue;
+ if (pDoc == NULL)
+ continue;
ptrT ptszTitle(json_as_string(json_get(pDoc, "title")));
ptrT ptszUrl(json_as_string(json_get(pDoc, "url")));
- res.AppendFormat(_T("%s: (%s) - %s"),
+ res.AppendFormat(L"%s: (%s) - %s",
TranslateT("Document"), ptszTitle, ptszUrl);
}
- else if (!lstrcmp(ptszType, _T("wall"))) {
+ else if (!lstrcmp(ptszType, L"wall")) {
JSONNODE *pWall = json_get(pAttach, "wall");
- if (pWall == NULL) continue;
+ if (pWall == NULL)
+ continue;
ptrT ptszText(json_as_string(json_get(pWall, "text")));
int id = json_as_int(json_get(pWall, "id"));
int fromID = json_as_int(json_get(pWall, "from_id"));
- res.AppendFormat(_T("%s: %s - http://vk.com/wall%d_%d"), TranslateT("Wall post"), ptszText ? ptszText : L" ", fromID, id);
+ res.AppendFormat(L"%s: %s - http://vk.com/wall%d_%d", TranslateT("Wall post"), ptszText ? ptszText : L" ", fromID, id);
}
else if (!lstrcmp(ptszType, _T("sticker"))) {
JSONNODE *pSticker = json_get(pAttach, "sticker");
- if (pSticker == NULL) continue;
+ if (pSticker == NULL)
+ continue;
res.Empty(); // sticker is not really an attachment, so we don't want all that heading info
if (m_bStikersAsSmyles){