summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-10-12 18:33:31 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-10-12 18:33:31 +0000
commita61c282b82ac68a5d694de4de0645de52bf5585a (patch)
treed3678c0373d406fbcb8442ac1f9f50624729d272 /protocols
parent53566f8632f56ecbaf2f3f80059a801cb1648358 (diff)
VK: captcha form
git-svn-id: http://svn.miranda-ng.org/main/trunk@6460 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/VKontakte/res/resource.rc25
-rw-r--r--protocols/VKontakte/src/main.cpp2
-rw-r--r--protocols/VKontakte/src/misc.cpp136
-rw-r--r--protocols/VKontakte/src/resource.h15
-rw-r--r--protocols/VKontakte/src/stdafx.h1
-rw-r--r--protocols/VKontakte/src/vk.h2
-rw-r--r--protocols/VKontakte/src/vk_proto.h2
7 files changed, 180 insertions, 3 deletions
diff --git a/protocols/VKontakte/res/resource.rc b/protocols/VKontakte/res/resource.rc
index fe46d8ad2f..8e9ae7568f 100644
--- a/protocols/VKontakte/res/resource.rc
+++ b/protocols/VKontakte/res/resource.rc
@@ -35,6 +35,31 @@ BEGIN
CONTROL "Open VK site",IDC_URL,"Hyperlink",WS_TABSTOP,7,49,174,12
END
+IDD_CAPTCHAFORM DIALOGEX 0, 0, 258, 224
+STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_CONTROLPARENT
+CAPTION "Bots Challenge Test"
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
+BEGIN
+ EDITTEXT IDC_VALUE,4,203,137,14,ES_AUTOHSCROLL
+ CONTROL "",IDC_WHITERECT,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,0,0,258,25
+ LTEXT "Instruction:",IDC_TITLE,7,7,243,8,NOT WS_GROUP
+ EDITTEXT IDC_INSTRUCTION,17,16,233,8,ES_MULTILINE | ES_READONLY | NOT WS_BORDER
+ CONTROL "",IDC_FRAME1,"Static",SS_ETCHEDHORZ,0,26,258,1
+ CONTROL "",IDC_FRAME2,"Static",SS_ETCHEDHORZ,0,197,258,1
+ DEFPUSHBUTTON "Submit",IDOK,146,203,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,200,203,50,14
+END
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+
+IDI_KEYS ICON "key.ico"
/////////////////////////////////////////////////////////////////////////////
//
diff --git a/protocols/VKontakte/src/main.cpp b/protocols/VKontakte/src/main.cpp
index 32e3246751..5264952384 100644
--- a/protocols/VKontakte/src/main.cpp
+++ b/protocols/VKontakte/src/main.cpp
@@ -78,6 +78,8 @@ extern "C" int __declspec(dllexport) Load()
{
mir_getLP(&pluginInfo);
+ InitIcons();
+
// Register protocol module
PROTOCOLDESCRIPTOR pd = { sizeof(pd) };
pd.szName = "VKontakte";
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index edb7739e6e..b4f27823cb 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -84,6 +84,137 @@ bool CVkProto::CheckJsonResult(JSONNODE *pNode)
}
/////////////////////////////////////////////////////////////////////////////////////////
+
+static IconItem iconList[] =
+{
+ { LPGEN("Captcha form icon"), "key", IDI_KEYS }
+};
+
+void InitIcons()
+{
+ Icon_Register(hInst, LPGEN("Protocols")"/"LPGEN("VKontakte"), iconList, SIZEOF(iconList), "VKontakte");
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Captcha form
+
+struct CAPTCHA_FORM_PARAMS
+{
+ HBITMAP bmp;
+ int w,h;
+ char Result[100];
+};
+
+static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ CAPTCHA_FORM_PARAMS *params = (CAPTCHA_FORM_PARAMS*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ switch (msg) {
+ case WM_INITDIALOG: {
+ TranslateDialogDefault(hwndDlg);
+ SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIconByHandle(iconList[0].hIcolib, TRUE));
+ SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIconByHandle(iconList[0].hIcolib));
+ params = (CAPTCHA_FORM_PARAMS*)lParam;
+
+ SetDlgItemText(hwndDlg, IDC_INSTRUCTION, TranslateT("Enter the text you see"));
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG)params);
+
+ return TRUE;
+ }
+ case WM_CTLCOLORSTATIC:
+ switch(GetWindowLongPtr((HWND)lParam, GWL_ID)) {
+ case IDC_WHITERECT:
+ case IDC_INSTRUCTION:
+ case IDC_TITLE:
+ return (BOOL)GetStockObject(WHITE_BRUSH);
+ }
+ return NULL;
+
+ case WM_PAINT:
+ if (params) {
+ PAINTSTRUCT ps;
+ HDC hdc, hdcMem;
+ RECT rc;
+
+ GetClientRect(hwndDlg, &rc);
+ hdc = BeginPaint(hwndDlg, &ps);
+ hdcMem = CreateCompatibleDC(hdc);
+ HGDIOBJ hOld = SelectObject(hdcMem, params->bmp);
+
+ int y = (rc.bottom + rc.top - params->h) / 2;
+ int x = (rc.right + rc.left - params->w) / 2;
+ BitBlt(hdc, x, y, params->w, params->h, hdcMem, 0,0, SRCCOPY);
+ SelectObject(hdcMem, hOld);
+ DeleteDC(hdcMem);
+
+ EndPaint(hwndDlg, &ps);
+ }
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDCANCEL:
+ EndDialog(hwndDlg, 0);
+ return TRUE;
+
+ case IDOK:
+ GetDlgItemTextA(hwndDlg, IDC_VALUE, params->Result, SIZEOF(params->Result));
+ EndDialog(hwndDlg, 1);
+ return TRUE;
+ }
+ break;
+
+ case WM_CLOSE:
+ EndDialog(hwndDlg, 0);
+ break;
+
+ case WM_DESTROY:
+ Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
+ Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
+ break;
+ }
+ return FALSE;
+}
+
+CMStringA CVkProto::RunCaptchaForm(LPCSTR szUrl)
+{
+ debugLogA("CVkProto::RunCaptchaForm: reading picture from %s", szUrl);
+
+ NETLIBHTTPREQUEST req = { sizeof(req) };
+ req.requestType = REQUEST_GET;
+ req.szUrl = (LPSTR)szUrl;
+ req.flags = NLHRF_HTTP11;
+ req.timeout = 60;
+
+ NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req);
+ if (reply == NULL)
+ return "";
+
+ if (reply->resultCode != 200) {
+ debugLogA("CVkProto::RunCaptchaForm: failed with code %d", reply->resultCode);
+ return "";
+ }
+
+ CAPTCHA_FORM_PARAMS param = { 0 };
+
+ 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, 0);
+
+ BITMAP bmp = {0};
+ GetObject(param.bmp, sizeof(bmp), &bmp);
+ param.w = bmp.bmWidth;
+ param.h = bmp.bmHeight;
+ int res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CAPTCHAFORM), NULL, CaptchaFormDlgProc, (LPARAM)&param);
+ if (res == 0)
+ return "";
+
+ debugLogA("CVkProto::RunCaptchaForm: user entered text %s", param.Result);
+ return param.Result;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// Quick & dirty form parser
static CMStringA getAttr(char *szSrc, LPCSTR szAttrName)
@@ -138,6 +269,11 @@ CMStringA CVkProto::AutoFillForm(char *pBody, CMStringA &szAction)
value = ptrA( mir_utf8encodeT( ptrT( getTStringA("Login"))));
else if (name == "pass")
value = ptrA( mir_utf8encodeT( ptrT( GetUserStoredPassword())));
+ else if (name == "captcha_key") {
+ char *pCaptchaBeg = strstr(pFormBeg, "<img id=\"captcha\"");
+ if (pCaptchaBeg != NULL)
+ value = RunCaptchaForm( getAttr(pCaptchaBeg, "src"));
+ }
if ( !result.IsEmpty())
result.AppendChar('&');
diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h
index 3060905969..0c1fe3cc33 100644
--- a/protocols/VKontakte/src/resource.h
+++ b/protocols/VKontakte/src/resource.h
@@ -3,18 +3,27 @@
// Used by D:\Myranda\protocols\VKontakte\res\resource.rc
//
#define IDD_ACCMGRUI 101
+#define IDD_CAPTCHAFORM 102
+#define IDI_KEYS 103
#define IDC_LOGIN 1001
#define IDC_PASSWORD 1002
#define IDC_URL 1003
+#define IDC_VALUE 1004
+#define IDC_WHITERECT 1005
+#define IDC_TITLE 1006
+#define IDC_INSTRUCTION 1007
+#define IDC_FRAME1 1008
+#define IDC_FRAME2 1009
+#define IDC_SUBMIT 1010
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
-#define _APS_NEXT_RESOURCE_VALUE 101
+#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1004
+#define _APS_NEXT_CONTROL_VALUE 1011
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/protocols/VKontakte/src/stdafx.h b/protocols/VKontakte/src/stdafx.h
index 5788e340a5..876fd93ab1 100644
--- a/protocols/VKontakte/src/stdafx.h
+++ b/protocols/VKontakte/src/stdafx.h
@@ -44,6 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <m_hotkeys.h>
#include <m_icolib.h>
#include <m_idle.h>
+#include <m_imgsrvc.h>
#include <m_json.h>
#include <m_langpack.h>
#include <m_message.h>
diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h
index 8b979cd8cf..e9f0779ca8 100644
--- a/protocols/VKontakte/src/vk.h
+++ b/protocols/VKontakte/src/vk.h
@@ -28,3 +28,5 @@ struct HttpParam
extern HINSTANCE hInst;
LPCSTR findHeader(NETLIBHTTPREQUEST *hdr, LPCSTR szField);
+
+void InitIcons(void);
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index c8275ae6f1..a0a7cbb708 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -139,7 +139,9 @@ private:
int SetupConnection(void);
void __cdecl WorkerThread(void*);
+ CMStringA RunCaptchaForm(LPCSTR szUrl);
CMStringA AutoFillForm(char*, CMStringA&);
+
void ConnectionFailed(int iReason);
bool CheckJsonResult(JSONNODE*);
void OnLoggedIn();