From 9ffedbd49389d9aaebb0e118b0c0299b0d4d6a97 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Mon, 12 Aug 2013 15:24:48 +0000 Subject: loading captcha from memmory git-svn-id: http://svn.miranda-ng.org/main/trunk@5658 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/src/jabber.h | 1 + protocols/JabberG/src/jabber_captcha.cpp | 42 +++++++++----------------------- 2 files changed, 12 insertions(+), 31 deletions(-) (limited to 'protocols/JabberG') diff --git a/protocols/JabberG/src/jabber.h b/protocols/JabberG/src/jabber.h index f36d0822b5..294072106e 100644 --- a/protocols/JabberG/src/jabber.h +++ b/protocols/JabberG/src/jabber.h @@ -94,6 +94,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include #include diff --git a/protocols/JabberG/src/jabber_captcha.cpp b/protocols/JabberG/src/jabber_captcha.cpp index ce4018ca66..3034e777ad 100644 --- a/protocols/JabberG/src/jabber_captcha.cpp +++ b/protocols/JabberG/src/jabber_captcha.cpp @@ -141,11 +141,17 @@ bool CJabberProto::ProcessCaptcha(HXML node, HXML parentNode, ThreadData* info) if (o == NULL || xmlGetText(o) == NULL) return false; - TCHAR *CaptchaPath = 0; - GetCaptchaImage(parentNode, CaptchaPath); - param.bmp = (HBITMAP) CallService(MS_UTILS_LOADBITMAPT, 0, (LPARAM)CaptchaPath); - DeleteFile(CaptchaPath); - mir_free(CaptchaPath); + unsigned bufferLen; + ptrA buffer((char*)mir_base64_decode( _T2A(xmlGetText(o)), &bufferLen)); + if (buffer == NULL) + return false; + + IMGSRVC_MEMIO memio; + memio.iLen = bufferLen; + memio.pBuf = (void *)buffer; + memio.fif = FIF_UNKNOWN; /* detect */ + memio.flags = 0; + param.bmp = (HBITMAP)CallService(MS_IMG_LOADFROMMEM, (WPARAM)&memio, 0); BITMAP bmp = {0}; GetObject(param.bmp, sizeof(bmp), &bmp); @@ -159,32 +165,6 @@ bool CJabberProto::ProcessCaptcha(HXML node, HXML parentNode, ThreadData* info) return true; } -bool CJabberProto::GetCaptchaImage(HXML node, TCHAR*& CaptchaPath) -{ - HXML o = xmlGetChild(node , "data"); - unsigned bufferLen; - ptrA buffer((char*)mir_base64_decode( _T2A(xmlGetText(o)), &bufferLen)); - if (buffer == NULL) - return false; - - const TCHAR *szPicType = JabberGetPictureType(node, buffer); - if (szPicType == NULL) - return false; - - TCHAR *ext = _tcsstr((TCHAR*)szPicType, _T("/"))+1; - TCHAR filename[MAX_PATH]; - mir_sntprintf(filename, SIZEOF(filename), _T("%%TEMP%%\\captcha.%s"), ext); - CaptchaPath = Utils_ReplaceVarsT(filename); - HANDLE hFile = CreateFile(CaptchaPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) - return false; - - DWORD nWritten; - bool res = WriteFile(hFile, buffer, bufferLen, &nWritten, NULL) != 0; - CloseHandle(hFile); - return res; -} - void CJabberProto::sendCaptchaResult(TCHAR* buf, ThreadData* info, LPCTSTR from, LPCTSTR challenge, LPCTSTR fromjid, LPCTSTR sid) { XmlNodeIq iq(_T("set"), SerialNext()); -- cgit v1.2.3