diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2016-03-21 07:22:23 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2016-03-21 07:22:23 +0000 |
commit | 2e2455779068f117e25bbb600d22f9f84aeb90a0 (patch) | |
tree | 456152f5ad4bf8b8d515db98164591ef430eb480 | |
parent | 3290e01656f52149b1c0c871a84357ec53510e26 (diff) |
VKontakte:
captcha sent to browser as data:image/png;base64 (patсh by MikalaiR, edited)
add 'UseCaptchaAssistant' hidden option (BYTE)
git-svn-id: http://svn.miranda-ng.org/main/trunk@16520 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/VKontakte/src/main.cpp | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 53 | ||||
-rw-r--r-- | protocols/VKontakte/src/stdafx.h | 1 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_captcha.cpp | 63 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 1 |
5 files changed, 61 insertions, 59 deletions
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 <http://www.gnu.org/licenses/>. 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("<html><body><img src=\"miranda_captcha.png\" /></body></html>");
- 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, "<html><body><img src=\"data:image/png;base64,%s\" /></body></html>", 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 <http://www.gnu.org/licenses/>. #include <m_metacontacts.h>
#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<CVkProto> void SetInvisible(MCONTACT hContact);
CMString RemoveBBC(CMString& tszSrc);
- CMString SaveImage(HBITMAP hBitmap);
void ShowCaptchaInBrowser(HBITMAP hBitmap);
//====================================================================================
|