From 2e2455779068f117e25bbb600d22f9f84aeb90a0 Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Mon, 21 Mar 2016 07:22:23 +0000 Subject: =?UTF-8?q?VKontakte:=20captcha=20sent=20to=20browser=20as=20data:?= =?UTF-8?q?image/png;base64=20(pat=D1=81h=20by=20MikalaiR,=20edited)=20add?= =?UTF-8?q?=20'UseCaptchaAssistant'=20hidden=20option=20(BYTE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.miranda-ng.org/main/trunk@16520 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/main.cpp | 2 ++ protocols/VKontakte/src/misc.cpp | 53 +++++++++++----------------- protocols/VKontakte/src/stdafx.h | 1 + protocols/VKontakte/src/vk_captcha.cpp | 63 ++++++++++++++++++++-------------- protocols/VKontakte/src/vk_proto.h | 1 - 5 files changed, 61 insertions(+), 59 deletions(-) (limited to 'protocols') diff --git a/protocols/VKontakte/src/main.cpp b/protocols/VKontakte/src/main.cpp index 4279c2c3cf..058c65b8e4 100644 --- a/protocols/VKontakte/src/main.cpp +++ b/protocols/VKontakte/src/main.cpp @@ -21,6 +21,7 @@ along with this program. If not, see . HINSTANCE hInst; int hLangpack; CLIST_INTERFACE *pcli; +FI_INTERFACE *fii; PLUGININFOEX pluginInfo = { @@ -71,6 +72,7 @@ extern "C" int __declspec(dllexport) Load() { mir_getLP(&pluginInfo); mir_getCLI(); + CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fii); InitIcons(); // Register protocol module diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index fb13fa8ee4..d22fa90ad8 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -1277,46 +1277,33 @@ CMString CVkProto::RemoveBBC(CMString& tszSrc) return tszRes; } -CMString CVkProto::SaveImage(HBITMAP hBitmap) +void CVkProto::ShowCaptchaInBrowser(HBITMAP hBitmap) { TCHAR tszTempDir[MAX_PATH]; - if (!GetEnvironmentVariable(_T("TEMP"), tszTempDir, MAX_PATH)) - return CMString(); - - CMString tszImgFileName(FORMAT, _T("%s\\miranda_captcha.png"), tszTempDir); + return; - IMGSRVC_INFO isi = { sizeof(isi) }; - isi.tszName = mir_tstrdup(tszImgFileName); - isi.hbm = hBitmap; - isi.dwMask = IMGI_HBITMAP; - isi.fif = FREE_IMAGE_FORMAT::FIF_PNG; - - if (CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_TCHAR)) - return tszImgFileName; + CMString tszHTMLPath(FORMAT, _T("%s\\miranda_captcha.html"), tszTempDir); - return CMString(); -} - -void CVkProto::ShowCaptchaInBrowser(HBITMAP hBitmap) -{ - CMString tszFHTML = SaveImage(hBitmap); - - if (tszFHTML.IsEmpty()) + FILE *pFile = _tfopen(tszHTMLPath, _T("w")); + if (pFile == NULL) return; - - tszFHTML.Replace(_T(".png"), _T(".html")); - if (!(GetFileAttributes(tszFHTML) < 0xFFFFFFF)) { - FILE *pFile = _tfopen(tszFHTML, _T("w")); - if (pFile == NULL) - return; + FIBITMAP *dib = fii->FI_CreateDIBFromHBITMAP(hBitmap); + FIMEMORY *hMem = fii->FI_OpenMemory(nullptr, 0); + fii->FI_SaveToMemory(FIF_PNG, dib, hMem, 0); - CMStringA szHTML(""); - fwrite(szHTML, 1, szHTML.GetLength(), pFile); - fclose(pFile); - } + BYTE *buf = NULL; + DWORD bufLen; + fii->FI_AcquireMemory(hMem, &buf, &bufLen); + ptrA base64(mir_base64_encode(buf, bufLen)); + fii->FI_CloseMemory(hMem); + + + CMStringA szHTML(FORMAT, "", base64); + fwrite(szHTML, 1, szHTML.GetLength(), pFile); + fclose(pFile); - tszFHTML = _T("file://") + tszFHTML; - Utils_OpenUrlT(tszFHTML); + tszHTMLPath = _T("file://") + tszHTMLPath; + Utils_OpenUrlT(tszHTMLPath); } \ No newline at end of file diff --git a/protocols/VKontakte/src/stdafx.h b/protocols/VKontakte/src/stdafx.h index d9079c1069..651856837f 100644 --- a/protocols/VKontakte/src/stdafx.h +++ b/protocols/VKontakte/src/stdafx.h @@ -64,6 +64,7 @@ along with this program. If not, see . #include #include "win2k.h" +extern FI_INTERFACE *fii; #include "resource.h" #include "vk.h" diff --git a/protocols/VKontakte/src/vk_captcha.cpp b/protocols/VKontakte/src/vk_captcha.cpp index 9e7913443d..fdc450911d 100644 --- a/protocols/VKontakte/src/vk_captcha.cpp +++ b/protocols/VKontakte/src/vk_captcha.cpp @@ -42,6 +42,9 @@ static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam SetDlgItemText(hwndDlg, IDC_INSTRUCTION, TranslateT("Enter the text you see")); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)params); + if (!params->proto) + EnableWindow(GetDlgItem(hwndDlg,IDOPENBROWSER), false); + return TRUE; } case WM_CTLCOLORSTATIC: @@ -54,7 +57,7 @@ static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam return NULL; case WM_PAINT: - if (params) { + if (params && params->proto) { PAINTSTRUCT ps; HDC hdc, hdcMem; RECT rc; @@ -84,7 +87,8 @@ static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam return TRUE; case IDOPENBROWSER: - params->proto->ShowCaptchaInBrowser(params->bmp); + if (params->proto) + params->proto->ShowCaptchaInBrowser(params->bmp); break; case IDOK: @@ -111,33 +115,42 @@ bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) debugLogA("CVkProto::RunCaptchaForm: reading picture from %s", szUrl); result.Empty(); - NETLIBHTTPREQUEST req = { sizeof(req) }; - req.requestType = REQUEST_GET; - req.szUrl = (LPSTR)szUrl; - req.flags = VK_NODUMPHEADERS; + CAPTCHA_FORM_PARAMS param = { 0 }; + if (getBool("UseCaptchaAssistant", false)) { + CMStringA szCaptchaAssistant(FORMAT, "http://ca.tiflohelp.ru/?link=%s", ptrA(ExpUrlEncode(szUrl))); + Utils_OpenUrl(szCaptchaAssistant); + param.proto = NULL; + } + else { + NETLIBHTTPREQUEST req = { sizeof(req) }; + req.requestType = REQUEST_GET; + req.szUrl = (LPSTR)szUrl; + req.flags = VK_NODUMPHEADERS; + + NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req); + if (reply == NULL) + return false; + + if (reply->resultCode != 200) { + debugLogA("CVkProto::RunCaptchaForm: failed with code %d", reply->resultCode); + return false; + } - NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req); - if (reply == NULL) - return false; - if (reply->resultCode != 200) { - debugLogA("CVkProto::RunCaptchaForm: failed with code %d", reply->resultCode); - return false; - } + IMGSRVC_MEMIO memio = { 0 }; + memio.iLen = reply->dataLength; + memio.pBuf = reply->pData; + memio.fif = FIF_UNKNOWN; /* detect */ + param.bmp = (HBITMAP)CallService(MS_IMG_LOADFROMMEM, (WPARAM)&memio); - CAPTCHA_FORM_PARAMS param = { 0 }; + BITMAP bmp = { 0 }; + GetObject(param.bmp, sizeof(bmp), &bmp); + param.w = bmp.bmWidth; + param.h = bmp.bmHeight; + param.proto = this; + + } - IMGSRVC_MEMIO memio = { 0 }; - memio.iLen = reply->dataLength; - memio.pBuf = reply->pData; - memio.fif = FIF_UNKNOWN; /* detect */ - param.bmp = (HBITMAP)CallService(MS_IMG_LOADFROMMEM, (WPARAM)&memio); - - BITMAP bmp = { 0 }; - GetObject(param.bmp, sizeof(bmp), &bmp); - param.w = bmp.bmWidth; - param.h = bmp.bmHeight; - param.proto = this; int res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CAPTCHAFORM), NULL, CaptchaFormDlgProc, (LPARAM)¶m); if (res == 0) return false; diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 1a105eed24..04a7605f9c 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -229,7 +229,6 @@ struct CVkProto : public PROTO void SetInvisible(MCONTACT hContact); CMString RemoveBBC(CMString& tszSrc); - CMString SaveImage(HBITMAP hBitmap); void ShowCaptchaInBrowser(HBITMAP hBitmap); //==================================================================================== -- cgit v1.2.3