From e36478e5c3bc275e29604c501dd0abdf90d20d55 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 27 May 2018 14:11:16 +0300 Subject: merge with master till fixes #1374 (IRC crash on exit after 20-30 account on/off) --- plugins/SimpleStatusMsg/src/main.cpp | 20 +++++++-------- protocols/FacebookRM/src/client.h | 5 ++++ protocols/FacebookRM/src/communication.cpp | 41 +++++++++++++++++++++++++++++- protocols/FacebookRM/src/connection.cpp | 21 +++++++++++++++ protocols/FacebookRM/src/http_request.h | 2 +- protocols/FacebookRM/src/version.h | 2 +- src/mir_app/src/proto_opts.cpp | 4 ++- 7 files changed, 80 insertions(+), 15 deletions(-) diff --git a/plugins/SimpleStatusMsg/src/main.cpp b/plugins/SimpleStatusMsg/src/main.cpp index b2216a2846..47345eb3ae 100644 --- a/plugins/SimpleStatusMsg/src/main.cpp +++ b/plugins/SimpleStatusMsg/src/main.cpp @@ -240,7 +240,7 @@ wchar_t* InsertBuiltinVarsIntoMsg(wchar_t *in, const char *szProto, int) mir_snwprintf(substituteStr, L"%d", GetRandom(ran_from, ran_to)); for (k = i + 1; msg[k]; k++) if (msg[k] == '%') { k++; break; } - if (mir_wstrlen(substituteStr) > k - i) + if ((int)mir_wstrlen(substituteStr) > k - i) msg = (wchar_t *)mir_realloc(msg, (mir_wstrlen(msg) + 1 + mir_wstrlen(substituteStr) - (k - i)) * sizeof(wchar_t)); memmove(msg + i + mir_wstrlen(substituteStr), msg + i + (k - i), (mir_wstrlen(msg) - i - (k - i - 1)) * sizeof(wchar_t)); @@ -761,18 +761,17 @@ void SetStatusMessage(const char *szProto, int iInitialStatus, int iStatus, wcha INT_PTR ShowStatusMessageDialogInternal(WPARAM, LPARAM lParam) { - struct MsgBoxInitData *box_data; - BOOL idvstatusmsg = FALSE; + bool idvstatusmsg = false; if (Miranda_IsTerminated()) return 0; if (hTTBButton) { - CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTTBButton, (LPARAM)0); - CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM((WORD)TTBO_TIPNAME, (WORD)hTTBButton), (LPARAM)Translate("Change status message")); + CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTTBButton, 0); + CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, (LPARAM)hTTBButton), (LPARAM)Translate("Change status message")); } - box_data = (struct MsgBoxInitData *)mir_alloc(sizeof(struct MsgBoxInitData)); + MsgBoxInitData *box_data = (struct MsgBoxInitData *)mir_alloc(sizeof(struct MsgBoxInitData)); if (accounts->statusMsgCount == 1) { for (int i = 0; i < accounts->count; ++i) { @@ -812,7 +811,7 @@ INT_PTR ShowStatusMessageDialogInternal(WPARAM, LPARAM lParam) box_data->m_iStatusModes = CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0)&~CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_5, 0); box_data->m_iStatusMsgModes = CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_3, 0); - idvstatusmsg = TRUE; + idvstatusmsg = true; break; } } @@ -1409,17 +1408,16 @@ static int OnIdleChanged(WPARAM, LPARAM lParam) return 0; } -static int CSStatusChange(WPARAM wParam, LPARAM) +static int CSStatusChange(WPARAM wParam, LPARAM iCount) { PROTOCOLSETTINGEX **ps = *(PROTOCOLSETTINGEX***)wParam; - int status_mode, CSProtoCount; + int status_mode; char szSetting[80]; wchar_t *msg = nullptr; if (ps == nullptr) return -1; - CSProtoCount = CallService(MS_CS_GETPROTOCOUNT, 0, 0); - for (int i = 0; i < CSProtoCount; ++i) { + for (int i = 0; i < iCount; ++i) { if (ps[i]->m_szName == nullptr || !*ps[i]->m_szName) continue; if (ps[i]->m_status == ID_STATUS_IDLE) status_mode = ps[i]->m_lastStatus; diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index 7089be47ea..bd3104114c 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -38,6 +38,11 @@ public: { } + HNETLIBCONN hChannelCon; + HNETLIBCONN hMessagesCon; + HNETLIBCONN hFcbCon; + mir_cs fcb_conn_lock_; + // Random generator value for this client unsigned int random_ = 0; diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index dbec3c4e32..2dd2c7aac7 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -54,11 +54,50 @@ http::response facebook_client::sendRequest(HttpRequest *request) if (request->requestType == REQUEST_POST) request->Headers << CHAR_PARAM("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); + mir_cslockfull s(fcb_conn_lock_); s.unlock(); + + // Set persistent connection (or not) + switch (request->Persistent) { + case HttpRequest::PersistentType::NONE: + request->nlc = nullptr; + request->flags &= ~NLHRF_PERSISTENT; + break; + case HttpRequest::PersistentType::CHANNEL: + request->nlc = hChannelCon; + request->flags |= NLHRF_PERSISTENT; + break; + case HttpRequest::PersistentType::MESSAGES: + request->nlc = hMessagesCon; + request->flags |= NLHRF_PERSISTENT; + break; + case HttpRequest::PersistentType::DEFAULT: + s.lock(); + request->nlc = hFcbCon; + request->flags |= NLHRF_PERSISTENT; + break; + } + parent->debugLogA("@@@ Sending request to '%s'", request->szUrl); // Send the request NETLIBHTTPREQUEST *pnlhr = request->Send(handle_); + // Remember the persistent connection handle (or not) + switch (request->Persistent) { + case HttpRequest::PersistentType::NONE: + break; + case HttpRequest::PersistentType::CHANNEL: + hChannelCon = pnlhr ? pnlhr->nlc : nullptr; + break; + case HttpRequest::PersistentType::MESSAGES: + hMessagesCon = pnlhr ? pnlhr->nlc : nullptr; + break; + case HttpRequest::PersistentType::DEFAULT: + s.unlock(); + hFcbCon = pnlhr ? pnlhr->nlc : nullptr; + break; + } + // Check and copy response data if (pnlhr != nullptr) { parent->debugLogA("@@@ Got response with code %d", pnlhr->resultCode); @@ -1099,7 +1138,7 @@ bool facebook_client::save_url(const std::string &url, const std::wstring &filen NETLIBHTTPREQUEST req = { sizeof(req) }; req.requestType = REQUEST_GET; req.szUrl = const_cast(url.c_str()); - req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_NODUMP; + req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_PERSISTENT | NLHRF_NODUMP; req.nlc = nlc; bool ret = false; diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index 79a0f5e03b..e2ebc70f56 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -36,6 +36,18 @@ void FacebookProto::ChangeStatus(void*) SetEvent(update_loop_event); + // Shutdown and close channel handle + Netlib_Shutdown(facy.hChannelCon); + if (facy.hChannelCon) + Netlib_CloseHandle(facy.hChannelCon); + facy.hChannelCon = nullptr; + + // Shutdown and close messages handle + Netlib_Shutdown(facy.hMessagesCon); + if (facy.hMessagesCon) + Netlib_CloseHandle(facy.hMessagesCon); + facy.hMessagesCon = nullptr; + // Turn off chat on Facebook if (getByte(FACEBOOK_KEY_DISCONNECT_CHAT, DEFAULT_DISCONNECT_CHAT)) facy.chat_state(false); @@ -62,6 +74,11 @@ void FacebookProto::ChangeStatus(void*) facy.pages.clear(); facy.typers.clear(); + // Close connection handle + if (facy.hFcbCon) + Netlib_CloseHandle(facy.hFcbCon); + facy.hFcbCon = nullptr; + m_iStatus = facy.self_.status_id = ID_STATUS_OFFLINE; ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); @@ -118,6 +135,10 @@ void FacebookProto::ChangeStatus(void*) else { ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE)old_status, m_iStatus); + if (facy.hFcbCon) + Netlib_CloseHandle(facy.hFcbCon); + facy.hFcbCon = nullptr; + facy.clear_cookies(); // Set to offline diff --git a/protocols/FacebookRM/src/http_request.h b/protocols/FacebookRM/src/http_request.h index f21e5be78c..f4ed8d76ae 100644 --- a/protocols/FacebookRM/src/http_request.h +++ b/protocols/FacebookRM/src/http_request.h @@ -137,7 +137,7 @@ public: flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_DUMPASTEXT; requestType = type; pData = nullptr; - timeout = 20 * 1000; + timeout = 600 * 1000; NotifyErrors = true; Persistent = DEFAULT; diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h index 82e341a973..5c4c0f4f93 100644 --- a/protocols/FacebookRM/src/version.h +++ b/protocols/FacebookRM/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 4 #define __RELEASE_NUM 1 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include diff --git a/src/mir_app/src/proto_opts.cpp b/src/mir_app/src/proto_opts.cpp index 208ccb107f..884577650e 100644 --- a/src/mir_app/src/proto_opts.cpp +++ b/src/mir_app/src/proto_opts.cpp @@ -751,8 +751,10 @@ LRESULT CAccountListCtrl::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lParam) case WM_LBUTTONUP: { POINT pt = { LOWORD(lParam), HIWORD(lParam) }; - if ((m_iItem >= 0) && PtInRect(&m_rcCheck, pt)) + if ((m_iItem >= 0) && PtInRect(&m_rcCheck, pt)) { + PARENT()->m_iPrevSel = m_iItem; PARENT()->OnAccountCheck(m_iItem); + } m_iItem = -1; } break; -- cgit v1.2.3