From fc4ca4545540ba1f35e4e7ad01646edf11199b4e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 7 Jan 2014 12:31:01 +0000 Subject: ability to set the alternative VK domain git-svn-id: http://svn.miranda-ng.org/main/trunk@7531 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/resource.h | 5 +++-- protocols/VKontakte/src/vk.h | 3 --- protocols/VKontakte/src/vk_options.cpp | 15 +++++++++++++-- protocols/VKontakte/src/vk_proto.cpp | 4 ++++ protocols/VKontakte/src/vk_proto.h | 5 ++++- protocols/VKontakte/src/vk_queue.cpp | 5 +++-- protocols/VKontakte/src/vk_thread.cpp | 3 ++- 7 files changed, 29 insertions(+), 11 deletions(-) (limited to 'protocols/VKontakte/src') diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h index fba3cf24a7..2de4898616 100644 --- a/protocols/VKontakte/src/resource.h +++ b/protocols/VKontakte/src/resource.h @@ -18,15 +18,16 @@ #define IDC_SUBMIT 1010 #define IDC_DELIVERY 1011 #define IDC_GROUPNAME 1012 +#define IDC_VKDOMAIN 1014 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 104 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1014 +#define _APS_NEXT_CONTROL_VALUE 1015 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h index 9550262153..ee882de9d9 100644 --- a/protocols/VKontakte/src/vk.h +++ b/protocols/VKontakte/src/vk.h @@ -17,9 +17,6 @@ along with this program. If not, see . #define VK_APP_ID "3917910" -#define VK_API_URL "api.vk.com" -#define VK_REDIRECT_URL "http://" VK_API_URL "/blank.html" - #define VKPOLL_MSG_REMOVED 0 #define VKPOLL_MSG_NEWFLAGS 1 #define VKPOLL_MSG_ADDFLAGS 2 diff --git a/protocols/VKontakte/src/vk_options.cpp b/protocols/VKontakte/src/vk_options.cpp index 6228cb3fae..b644e1e34d 100644 --- a/protocols/VKontakte/src/vk_options.cpp +++ b/protocols/VKontakte/src/vk_options.cpp @@ -22,7 +22,7 @@ along with this program. If not, see . INT_PTR CALLBACK VKAccountProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - CVkProto* ppro = (CVkProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + CVkProto *ppro = (CVkProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (uMsg) { case WM_INITDIALOG: @@ -117,6 +117,7 @@ INT_PTR CALLBACK CVkProto::OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L SetDlgItemText(hwndDlg, IDC_PASSWORD, tszPassw); SetDlgItemText(hwndDlg, IDC_GROUPNAME, ppro->getGroup()); + SetDlgItemTextA(hwndDlg, IDC_VKDOMAIN, ppro->getDomain()); } CheckDlgButton(hwndDlg, IDC_DELIVERY, ppro->m_bServerDelivery); return TRUE; @@ -130,6 +131,7 @@ INT_PTR CALLBACK CVkProto::OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L case IDC_LOGIN: case IDC_PASSWORD: case IDC_GROUPNAME: + case IDC_VKDOMAIN: if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; @@ -143,7 +145,10 @@ INT_PTR CALLBACK CVkProto::OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L case WM_NOTIFY: if (((LPNMHDR)lParam)->code == PSN_APPLY) { - TCHAR str[128]; + union { + TCHAR str[128]; + char stra[256]; + }; GetDlgItemText(hwndDlg, IDC_LOGIN, str, SIZEOF(str)); ppro->setTString("Login", str); @@ -153,6 +158,12 @@ INT_PTR CALLBACK CVkProto::OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L ppro->setTString("ProtoGroup", str); } + GetDlgItemTextA(hwndDlg, IDC_VKDOMAIN, stra, SIZEOF(stra)); + if (strcmp(ppro->getDomain(), stra)) { + ppro->setDomain(stra); + ppro->setString("BaseDomain", stra); + } + GetDlgItemText(hwndDlg, IDC_PASSWORD, str, SIZEOF(str)); ptrA szRawPasswd(mir_utf8encodeT(str)); if (szRawPasswd != NULL) diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 1d45da95fe..3a4f28bb1d 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -42,6 +42,10 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : nlu.ptszDescriptiveName = descr; m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); + m_baseDomain = getStringA("BaseDomain"); + if (m_baseDomain == NULL) + m_baseDomain = mir_strdup("vk.com"); + m_defaultGroup = getTStringA("ProtoGroup"); if (m_defaultGroup == NULL) m_defaultGroup = mir_tstrdup(_T("VKontakte")); diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 7b488f15ae..dbb5d68100 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -135,6 +135,9 @@ struct CVkProto : public PROTO __forceinline LPCTSTR getGroup() const { return m_defaultGroup; } __forceinline void setGroup(LPCTSTR grp) { m_defaultGroup = mir_tstrdup(grp); } + __forceinline LPCSTR getDomain() const { return m_baseDomain; } + __forceinline void setDomain(LPCSTR domain) { m_baseDomain = mir_strdup(domain); } + private: LIST m_arRequestsQueue; CRITICAL_SECTION m_csRequestsQueue; @@ -189,7 +192,7 @@ private: bool m_bOnline; LONG m_myUserId; - ptrA m_szAccessToken; + ptrA m_baseDomain, m_szAccessToken; ptrT m_defaultGroup; UINT_PTR m_timer; diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index b3ee1e9195..0b4c48140a 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -64,7 +64,7 @@ AsyncHttpRequest* CVkProto::PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, CMStringA url; if (*szUrl == '/') { // relative url leads to a site - url = ((bSecure) ? "https://" : "http://") + CMStringA(VK_API_URL); + url = ((bSecure) ? "https://api." : "http://api.") + CMStringA(m_baseDomain); url += szUrl; pReq->bIsMainConn = true; } @@ -105,11 +105,12 @@ void CVkProto::WorkerThread(void*) // try to receive a response from server RetrieveMyInfo(); else { + CMStringA redirectUrl; redirectUrl.Format("http://api.%s/blank.html", m_baseDomain); // Initialize new OAuth session HttpParam params[] = { { "client_id", VK_APP_ID }, { "scope", "friends,photos,audio,video,wall,messages,offline" }, - { "redirect_uri", VK_REDIRECT_URL }, + { "redirect_uri", redirectUrl }, { "display", "wap" }, { "response_type", "token" } }; diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 088201e450..8c624d95d8 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -98,7 +98,8 @@ void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq if (reply->resultCode == 302) { // manual redirect LPCSTR pszLocation = findHeader(reply, "Location"); if (pszLocation) { - if ( !_strnicmp(pszLocation, VK_REDIRECT_URL, sizeof(VK_REDIRECT_URL)-1)) { + CMStringA redirectUrl; redirectUrl.Format("http://api.%s/blank.html", m_baseDomain); + if (!_strnicmp(pszLocation, redirectUrl, redirectUrl.GetLength())) { m_szAccessToken = NULL; LPCSTR p = strstr(pszLocation, VK_TOKEN_BEG); if (p) { -- cgit v1.2.3