From bb3a9a32fda97426bf7f05b04724d894eb4399c7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 30 May 2015 22:53:24 +0000 Subject: patch for the embedded images processing git-svn-id: http://svn.miranda-ng.org/main/trunk@13920 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/src/jabber_misc.cpp | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'protocols/JabberG/src/jabber_misc.cpp') diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp index 844dc54ba7..21c686a724 100644 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -499,3 +499,51 @@ void CJabberProto::MsgPopup(MCONTACT hContact, const TCHAR *szMsg, const TCHAR * MessageBox(NULL, szMsg, szTitle, mtype); } } + +CMString CJabberProto::ExtractImage(HXML node) +{ + HXML nHtml, nBody, nImg; + LPCTSTR src; + CMString link; + + if ((nHtml = xmlGetChild(node, "html")) != NULL && + (nBody = xmlGetChild(nHtml, "body")) != NULL && + (nImg = xmlGetChild(nBody, "img")) != NULL && + (src = xmlGetAttrValue(nImg, _T("src"))) != NULL) { + + CMString strSrc(src); + if (strSrc.Left(11).Compare(L"data:image/") == 0) { + int end = strSrc.Find(L';'); + if (end != -1) { + CMString ext(strSrc.c_str() + 11, end - 11); + int comma = strSrc.Find(L',', end); + if (comma != -1) { + CMString image(strSrc.c_str() + comma + 1, strSrc.GetLength() - comma - 1); + image.Replace(L"%2B", L"+"); + image.Replace(L"%2F", L"/"); + image.Replace(L"%3D", L"="); + + TCHAR tszTempPath[MAX_PATH], tszTempFile[MAX_PATH]; + GetTempPath(_countof(tszTempPath), tszTempPath); + GetTempFileName(tszTempPath, _T("jab"), InterlockedIncrement(&g_nTempFileId), tszTempFile); + + HANDLE h = CreateFile(tszTempFile, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, NULL); + + if (h != INVALID_HANDLE_VALUE) { + DWORD n; + unsigned int bufferLen; + ptrA buffer((char*)mir_base64_decode(_T2A(image), &bufferLen)); + WriteFile(h, buffer, bufferLen, &n, NULL); + CloseHandle(h); + + link = _T(" file:///"); + link += tszTempFile; + } + } + } + } + } + return link; +} -- cgit v1.2.3