diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-11-28 07:53:55 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-11-28 07:53:55 +0000 |
commit | c602f1813c094cf5b355867ee253a9ad4ef3c147 (patch) | |
tree | fd644e63e9078c4d47225d08178d0fde9184f091 /protocols | |
parent | 0c89be2bea895bfe6c6077f4ac09d72fdffd160f (diff) |
VKontakte:
fix unset and timer for multiprotocol configuration
remove 'goto' contructions
code cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@11127 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/VKontakte/src/vk_queue.cpp | 70 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 26 |
2 files changed, 45 insertions, 51 deletions
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index aeaf052028..5fbbff50df 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -35,46 +35,42 @@ void CVkProto::UninitQueue() void CVkProto::ExecuteRequest(AsyncHttpRequest *pReq)
{
CMStringA str;
-
-LBL_Restart:
- pReq->bNeedsRestart = false;
- pReq->szUrl = pReq->m_szUrl.GetBuffer();
- if (!pReq->m_szParam.IsEmpty()) {
- if (pReq->requestType == REQUEST_GET) {
- str.Format("%s?%s", pReq->m_szUrl, pReq->m_szParam);
- pReq->szUrl = str.GetBuffer();
+ do {
+ pReq->bNeedsRestart = false;
+ pReq->szUrl = pReq->m_szUrl.GetBuffer();
+ if (!pReq->m_szParam.IsEmpty()) {
+ if (pReq->requestType == REQUEST_GET) {
+ str.Format("%s?%s", pReq->m_szUrl, pReq->m_szParam);
+ pReq->szUrl = str.GetBuffer();
+ }
+ else {
+ pReq->pData = mir_strdup(pReq->m_szParam.GetBuffer());
+ pReq->dataLength = pReq->m_szParam.GetLength();
+ }
}
- else {
- pReq->pData = mir_strdup(pReq->m_szParam.GetBuffer());
- pReq->dataLength = pReq->m_szParam.GetLength();
+ 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)
+ (this->*(pReq->m_pFunc))(reply, pReq); // may be set pReq->bNeedsRestart
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
}
- }
-
- 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)
- (this->*(pReq->m_pFunc))(reply, pReq);
-
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
- if (pReq->bNeedsRestart)
- goto LBL_Restart;
- }
- else if (pReq->bIsMainConn) {
- if (m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)
- ConnectionFailed(LOGINERR_NONETWORK);
- else if (pReq->m_iRetry){
- pReq->bNeedsRestart = true;
- Sleep(1000); //Pause for fix err
- pReq->m_iRetry--;
- debugLogA("CVkProto::ExecuteRequest restarting retry = %d", MAX_RETRIES - pReq->m_iRetry);
- goto LBL_Restart;
- }
- else{
- debugLogA("CVkProto::ExecuteRequest ShutdownSession");
- ShutdownSession();
+ else if (pReq->bIsMainConn) {
+ if (m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)
+ ConnectionFailed(LOGINERR_NONETWORK);
+ else if (pReq->m_iRetry){
+ pReq->bNeedsRestart = true;
+ Sleep(1000); //Pause for fix err
+ pReq->m_iRetry--;
+ debugLogA("CVkProto::ExecuteRequest restarting retry = %d", MAX_RETRIES - pReq->m_iRetry);
+ }
+ else{
+ debugLogA("CVkProto::ExecuteRequest ShutdownSession");
+ ShutdownSession();
+ }
}
- }
+ debugLogA("CVkProto::ExecuteRequest pReq->bNeedsRestart = %d", (int)pReq->bNeedsRestart);
+ } while (pReq->bNeedsRestart);
delete pReq;
}
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index a925887b68..326833dc79 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -50,10 +50,11 @@ void CVkProto::ConnectionFailed(int iReason) static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
{
- for (int i = 0; i < vk_Instances.getCount(); i++){
- vk_Instances[i]->SetServerStatus(vk_Instances[i]->m_iDesiredStatus);
- vk_Instances[i]->RetrieveUsersInfo(true);
- }
+ for (int i = 0; i < vk_Instances.getCount(); i++)
+ if (vk_Instances[i]->IsOnline()){
+ vk_Instances[i]->SetServerStatus(vk_Instances[i]->m_iDesiredStatus);
+ vk_Instances[i]->RetrieveUsersInfo(true);
+ }
}
static void CALLBACK VKSetTimer(void *pObject)
@@ -95,7 +96,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);
@@ -182,8 +183,7 @@ void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq return;
}
- if (reply->resultCode != 200) { // something went wrong
-LBL_NoForm:
+ if (reply->resultCode != 200 || !strstr(reply->pData, "form method=\"post\"")){ // something went wrong
ConnectionFailed(LOGINERR_NOSERVER);
return;
}
@@ -192,16 +192,14 @@ LBL_NoForm: ConnectionFailed(LOGINERR_WRONGPASSWORD);
return;
}
-
- // Application requests access to user's account
- if (!strstr(reply->pData, "form method=\"post\""))
- goto LBL_NoForm;
-
+
CMStringA szAction, szBody;
bool bSuccess = AutoFillForm(reply->pData, szAction, szBody);
if (!bSuccess || szAction.IsEmpty() || szBody.IsEmpty()) {
- if (m_prevError)
- goto LBL_NoForm;
+ if (m_prevError){
+ ConnectionFailed(LOGINERR_NOSERVER);
+ return;
+ }
m_prevError = true;
}
|