diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-09 10:45:10 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-09 10:45:10 +0000 |
commit | 24a161c41edfebcc4850bd58480649ff2ddf8d7f (patch) | |
tree | 6793c7a8dc85b8c9bb8cc7c5ce8cc4683d6c1709 /protocols/VKontakte | |
parent | 199bf2fee8e9f3844744288a8dde5d2dbc5ff55f (diff) |
VKontakte: fix for 'To many MarkAsRead', redesign PARAM structure
git-svn-id: http://svn.miranda-ng.org/main/trunk@10410 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 4 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 19 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_queue.cpp | 45 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 2 |
4 files changed, 49 insertions, 21 deletions
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 6d8df49e5c..fad6a277e7 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -205,11 +205,9 @@ int CVkProto::SendMsg(MCONTACT hContact, int flags, const char *msg) ULONG msgId = ::InterlockedIncrement(&m_msgId);
AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage)
<< INT_PARAM("user_id", userID)
+ << CHAR_PARAM("message", szMsg, reqPOST)
<< VER_API;
pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
- CMStringA szBody(FORMAT, "message=%s", ptrA(mir_urlEncode(szMsg)));
- pReq->pData = mir_strdup(szBody);
- pReq->dataLength = szBody.GetLength();
pReq->pUserInfo = new CVkSendMsgParam(hContact, msgId);
Push(pReq);
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 734ffc813c..c789a24138 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -32,22 +32,25 @@ struct AsyncHttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject void Redirect(NETLIBHTTPREQUEST*);
CMStringA m_szUrl;
- bool bNeedsRestart, bIsMainConn, m_bHasParams;
+ bool bNeedsRestart, bIsMainConn, m_bHasGParams, m_bHasPParams;
VK_REQUEST_HANDLER m_pFunc;
void *pUserInfo;
};
+enum ReqType {reqGET, reqPOST};
+
struct PARAM
{
LPCSTR szName;
- __forceinline PARAM(LPCSTR _name) : szName(_name) {}
+ ReqType rtType;
+ __forceinline PARAM(LPCSTR _name, ReqType _type = reqGET) : szName(_name), rtType(_type) {}
};
struct INT_PARAM : public PARAM
{
int iValue;
- __forceinline INT_PARAM(LPCSTR _name, int _value) :
- PARAM(_name), iValue(_value)
+ __forceinline INT_PARAM(LPCSTR _name, int _value, ReqType _type = reqGET) :
+ PARAM(_name, _type), iValue(_value)
{
}
};
@@ -56,8 +59,8 @@ AsyncHttpRequest* operator<<(AsyncHttpRequest*, const INT_PARAM&); struct CHAR_PARAM : public PARAM
{
LPCSTR szValue;
- __forceinline CHAR_PARAM(LPCSTR _name, LPCSTR _value) :
- PARAM(_name), szValue(_value)
+ __forceinline CHAR_PARAM(LPCSTR _name, LPCSTR _value, ReqType _type = reqGET) :
+ PARAM(_name, _type), szValue(_value)
{
}
};
@@ -66,8 +69,8 @@ AsyncHttpRequest* operator<<(AsyncHttpRequest*, const CHAR_PARAM&); struct TCHAR_PARAM : public PARAM
{
LPCTSTR tszValue;
- __forceinline TCHAR_PARAM(LPCSTR _name, LPCTSTR _value) :
- PARAM(_name), tszValue(_value)
+ __forceinline TCHAR_PARAM(LPCSTR _name, LPCTSTR _value, ReqType _type = reqGET) :
+ PARAM(_name, _type), tszValue(_value)
{
}
};
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index b19d47f4cc..5b9fc4b282 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -113,25 +113,52 @@ void CVkProto::WorkerThread(void*) AsyncHttpRequest* operator<<(AsyncHttpRequest *pReq, const INT_PARAM ¶m)
{
- CMStringA &s = pReq->m_szUrl;
- s.AppendFormat("%c%s=%i", pReq->m_bHasParams ? '&' : '?', param.szName, param.iValue);
- pReq->m_bHasParams = true;
+ if (param.rtType == reqGET){
+ CMStringA &s = pReq->m_szUrl;
+ s.AppendFormat("%c%s=%i", pReq->m_bHasGParams ? '&' : '?', param.szName, param.iValue);
+ pReq->m_bHasGParams = true;
+ }
+ else {
+ CMStringA s = pReq->pData;
+ s.AppendFormat("%s%s=%i", pReq->m_bHasPParams ? "&" : "?", param.szName, param.iValue);
+ pReq->pData = mir_strdup(s);
+ pReq->dataLength = s.GetLength();
+ pReq->m_bHasPParams = true;
+ }
return pReq;
}
AsyncHttpRequest* operator<<(AsyncHttpRequest *pReq, const CHAR_PARAM ¶m)
{
- CMStringA &s = pReq->m_szUrl;
- s.AppendFormat("%c%s=%s", pReq->m_bHasParams ? '&' : '?', param.szName, ptrA(mir_urlEncode(param.szValue)));
- pReq->m_bHasParams = true;
+ if (param.rtType == reqGET){
+ CMStringA &s = pReq->m_szUrl;
+ s.AppendFormat("%c%s=%s", pReq->m_bHasGParams ? '&' : '?', param.szName, ptrA(mir_urlEncode(param.szValue)));
+ pReq->m_bHasGParams = true;
+ }
+ else {
+ CMStringA s = pReq->pData;
+ s.AppendFormat("%s%s=%s", pReq->m_bHasPParams ? "&" : "", param.szName, ptrA(mir_urlEncode(param.szValue)));
+ pReq->pData = mir_strdup(s);
+ pReq->dataLength = s.GetLength();
+ pReq->m_bHasPParams = true;
+ }
return pReq;
}
AsyncHttpRequest* operator<<(AsyncHttpRequest *pReq, const TCHAR_PARAM ¶m)
{
ptrA szValue(mir_utf8encodeT(param.tszValue));
- CMStringA &s = pReq->m_szUrl;
- s.AppendFormat("%c%s=%s", pReq->m_bHasParams ? '&' : '?', param.szName, ptrA(mir_urlEncode(szValue)));
- pReq->m_bHasParams = true;
+ if (param.rtType == reqGET){
+ CMStringA &s = pReq->m_szUrl;
+ s.AppendFormat("%c%s=%s", pReq->m_bHasGParams ? '&' : '?', param.szName, ptrA(mir_urlEncode(szValue)));
+ pReq->m_bHasGParams = true;
+ }
+ else{
+ CMStringA s = pReq->pData;
+ s.AppendFormat("%s%s=%s", pReq->m_bHasGParams ? "&" : "?", param.szName, ptrA(mir_urlEncode(szValue)));
+ pReq->pData = mir_strdup(s);
+ pReq->dataLength = s.GetLength();
+ pReq->m_bHasPParams = true;
+ }
return pReq;
}
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index a8717339c6..0d7761fa1d 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -529,7 +529,7 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) else
GetHistoryDlg(hContact, mid);
- if (!m_bMarkReadOnReply)
+ if (!m_bMarkReadOnReply&&numUnread)
MarkMessagesRead(hContact);
}
else if (numUnread) {
|