From 94dcc72f13094157f344f284aec4edf0c0f5faa1 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 11 Aug 2013 10:41:37 +0000 Subject: ProtoGetAvatarFormat, ProtoGetAvatarFileFormat, ProtoGetBufferFormat, ProtoGetAvatarExtension - standard helpers for protocol avatars' processing instead of the zoo that existed previously git-svn-id: http://svn.miranda-ng.org/main/trunk@5645 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/src/jabber.h | 1 - protocols/JabberG/src/jabber_iqid.cpp | 2 +- protocols/JabberG/src/jabber_misc.cpp | 24 ++++++------------------ protocols/JabberG/src/jabber_svc.cpp | 2 +- protocols/JabberG/src/jabber_util.cpp | 16 ++-------------- protocols/JabberG/src/jabber_vcard.cpp | 4 ++-- 6 files changed, 12 insertions(+), 37 deletions(-) (limited to 'protocols/JabberG') diff --git a/protocols/JabberG/src/jabber.h b/protocols/JabberG/src/jabber.h index 4c3108726d..f36d0822b5 100644 --- a/protocols/JabberG/src/jabber.h +++ b/protocols/JabberG/src/jabber.h @@ -753,7 +753,6 @@ void __stdcall JabberStringAppend(char* *str, int *sizeAlloced, const c TCHAR* __stdcall JabberStripJid(const TCHAR *jid, TCHAR* dest, size_t destLen); int __stdcall JabberGetPacketID(HXML n); -int __stdcall JabberGetPictureType(const char* buf); LPCTSTR __stdcall JabberGetPictureType(HXML node, const char *picBuf); TCHAR* time2str(time_t _time, TCHAR *buf, size_t bufLen); diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index d36c82292d..60517cc113 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -1457,7 +1457,7 @@ LBL_ErrFormat: Log("Invalid mime type specified for picture: %S", mimeType); return; } } - else if ((pictureType = JabberGetPictureType(body)) == PA_FORMAT_UNKNOWN) + else if ((pictureType = ProtoGetBufferFormat(body, 0)) == PA_FORMAT_UNKNOWN) goto LBL_ErrFormat; TCHAR tszFileName[ MAX_PATH ]; diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp index eb0f091f22..9f636480a2 100644 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -267,13 +267,7 @@ void CJabberProto::GetAvatarFileName(HANDLE hContact, TCHAR* pszDest, size_t cbL pszDest[ tPathLen++ ] = '\\'; - char* szFileType = NULL; - switch(getByte(hContact, "AvatarType", PA_FORMAT_PNG)) { - case PA_FORMAT_JPEG: szFileType = "jpg"; break; - case PA_FORMAT_PNG: szFileType = "png"; break; - case PA_FORMAT_GIF: szFileType = "gif"; break; - case PA_FORMAT_BMP: szFileType = "bmp"; break; - } + const TCHAR* szFileType = ProtoGetAvatarExtension( getByte(hContact, "AvatarType", PA_FORMAT_PNG)); if (hContact != NULL) { char str[ 256 ]; @@ -284,22 +278,16 @@ void CJabberProto::GetAvatarFileName(HANDLE hContact, TCHAR* pszDest, size_t cbL db_free(&dbv); } else _i64toa((LONG_PTR)hContact, str, 10); - mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%S.%S"), ptrA(JabberSha1(str)), szFileType); + mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%S%s"), ptrA(JabberSha1(str)), szFileType); } else if (m_ThreadInfo != NULL) { - mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%s@%S avatar.%S"), + mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%s@%S avatar%s"), m_ThreadInfo->username, m_ThreadInfo->server, szFileType); } else { - DBVARIANT dbv1, dbv2; - BOOL res1 = getString("LoginName", &dbv1); - BOOL res2 = getString("LoginServer", &dbv2); - mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%S@%S avatar.%S"), - res1 ? "noname" : dbv1.pszVal, - res2 ? m_szModuleName : dbv2.pszVal, - szFileType); - if ( !res1) db_free(&dbv1); - if ( !res2) db_free(&dbv2); + ptrA res1( getStringA("LoginName")), res2( getStringA("LoginServer")); + mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%S@%S avatar%s"), + res1 ? res1 : "noname", res2 ? res2 : m_szModuleName, szFileType); } } diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp index c4fb05571e..60978c69f3 100644 --- a/protocols/JabberG/src/jabber_svc.cpp +++ b/protocols/JabberG/src/jabber_svc.cpp @@ -327,7 +327,7 @@ INT_PTR __cdecl CJabberProto::JabberSetAvatar(WPARAM, LPARAM lParam) for (int i=0; inlc; if (res->resultCode == 200 && res->dataLength) { - int pictureType = JabberGetPictureType(res->pData); + int pictureType = ProtoGetBufferFormat(res->pData); if (pictureType != PA_FORMAT_UNKNOWN) { PROTO_AVATAR_INFORMATIONT AI; AI.cbSize = sizeof(AI); diff --git a/protocols/JabberG/src/jabber_vcard.cpp b/protocols/JabberG/src/jabber_vcard.cpp index 566c276bf2..08b1e70b13 100644 --- a/protocols/JabberG/src/jabber_vcard.cpp +++ b/protocols/JabberG/src/jabber_vcard.cpp @@ -1158,7 +1158,7 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, TCHAR* szPhotoFileName) if ((str=mir_base64_encode((PBYTE)buffer, nRead)) != NULL) { n = v << XCHILD(_T("PHOTO")); TCHAR *szFileType; - switch(JabberGetPictureType(buffer)) { + switch( ProtoGetBufferFormat(buffer)) { case PA_FORMAT_PNG: szFileType = _T("image/png"); break; case PA_FORMAT_GIF: szFileType = _T("image/gif"); break; case PA_FORMAT_BMP: szFileType = _T("image/bmp"); break; @@ -1181,7 +1181,7 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, TCHAR* szPhotoFileName) for (int j=0; j