diff options
author | George Hazan <george.hazan@gmail.com> | 2015-05-30 22:53:24 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-05-30 22:53:24 +0000 |
commit | bb3a9a32fda97426bf7f05b04724d894eb4399c7 (patch) | |
tree | 4591c0d10d429b380d542d733f3bae3df34a2966 /protocols/JabberG/src/jabber_misc.cpp | |
parent | 27116b65cabb181630170eea15a987dc9395fd85 (diff) |
patch for the embedded images processing
git-svn-id: http://svn.miranda-ng.org/main/trunk@13920 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/JabberG/src/jabber_misc.cpp')
-rw-r--r-- | protocols/JabberG/src/jabber_misc.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
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;
+}
|