diff options
Diffstat (limited to 'protocols')
40 files changed, 163 insertions, 501 deletions
diff --git a/protocols/AimOscar/src/avatars.cpp b/protocols/AimOscar/src/avatars.cpp index 7f54961398..dea8de177e 100644 --- a/protocols/AimOscar/src/avatars.cpp +++ b/protocols/AimOscar/src/avatars.cpp @@ -102,7 +102,7 @@ void CAimProto::avatar_retrieval_handler(const char* sn, const char* hash, const if (data_len > 0)
{
const TCHAR *type;
- AI.format = detect_image_type(data, type);
+ AI.format = ProtoGetBufferFormat(data, &type);
get_avatar_filename(AI.hContact, AI.filename, SIZEOF(AI.filename), type);
int fileId = _topen(AI.filename, _O_CREAT | _O_TRUNC | _O_WRONLY | O_BINARY, _S_IREAD | _S_IWRITE);
@@ -123,45 +123,6 @@ void CAimProto::avatar_retrieval_handler(const char* sn, const char* hash, const ProtoBroadcastAck(AI.hContact, ACKTYPE_AVATAR, res ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, &AI, 0);
}
-int detect_image_type(const char* stream, const TCHAR* &type_ret)
-{
- if (stream[0]=='G'&&stream[1]=='I'&&stream[2]=='F')
- {
- type_ret = _T(".gif");
- return PA_FORMAT_GIF;
- }
- else if (stream[1]=='P'&&stream[2]=='N'&&stream[3]=='G')
- {
- type_ret = _T(".png");
- return PA_FORMAT_PNG;
- }
- else if (stream[0]=='B'&&stream[1]=='M')
- {
- type_ret = _T(".bmp");
- return PA_FORMAT_BMP;
- }
- else//assume jpg
- {
- type_ret = _T(".jpg");
- return PA_FORMAT_JPEG;
- }
-}
-
-int detect_image_type(const TCHAR* file)
-{
- const TCHAR *ext = _tcsrchr(file, '.');
- if (ext == NULL)
- return PA_FORMAT_UNKNOWN;
- if (_tcsicmp(ext, _T(".gif")) == 0)
- return PA_FORMAT_GIF;
- else if (_tcsicmp(ext, _T(".bmp")) == 0)
- return PA_FORMAT_BMP;
- else if (_tcsicmp(ext, _T(".png")) == 0)
- return PA_FORMAT_PNG;
- else
- return PA_FORMAT_JPEG;
-}
-
void CAimProto::init_custom_folders(void)
{
if (init_cst_fld_ran) return;
diff --git a/protocols/AimOscar/src/avatars.h b/protocols/AimOscar/src/avatars.h index 69c7ec49bf..1188a1ec82 100644 --- a/protocols/AimOscar/src/avatars.h +++ b/protocols/AimOscar/src/avatars.h @@ -46,8 +46,6 @@ struct avatar_up_req { mir_free(data1); mir_free(data2); }
};
-int detect_image_type(const char* stream, const TCHAR* &type_ret);
-int detect_image_type(const TCHAR* file);
bool get_avatar_hash(const TCHAR* file, char* hash, char** data, unsigned short &size);
void rescale_image(char *data, unsigned short size, char *&data1, unsigned short &size1);
diff --git a/protocols/AimOscar/src/services.cpp b/protocols/AimOscar/src/services.cpp index bfc0ca83ed..721751016c 100644 --- a/protocols/AimOscar/src/services.cpp +++ b/protocols/AimOscar/src/services.cpp @@ -384,7 +384,7 @@ INT_PTR CAimProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) return GAIR_SUCCESS;
case GAIR_WAITFOR:
- AI->format = detect_image_type(AI->filename);
+ AI->format = ProtoGetAvatarFormat(AI->filename);
break;
default:
diff --git a/protocols/FacebookRM/src/avatars.cpp b/protocols/FacebookRM/src/avatars.cpp index 58b7f4f504..5540bd1848 100644 --- a/protocols/FacebookRM/src/avatars.cpp +++ b/protocols/FacebookRM/src/avatars.cpp @@ -41,10 +41,8 @@ bool FacebookProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string * db_free(&dbv);
ai.hContact = ai.hContact;
- ai.format = ext_to_format(ext);
- _tcsncpy(ai.filename, filename.c_str(), SIZEOF(ai.filename));
- ai.filename[SIZEOF(ai.filename)-1] = 0;
-
+ _tcsncpy_s(ai.filename, SIZEOF(ai.filename), filename.c_str(), _TRUNCATE);
+ ai.format = ProtoGetAvatarFormat(ai.filename);
return true;
}
}
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp index d02b3901eb..ad9bf8f246 100644 --- a/protocols/FacebookRM/src/utils.cpp +++ b/protocols/FacebookRM/src/utils.cpp @@ -489,28 +489,3 @@ int utils::debug::log(std::string file_name, std::string text) return EXIT_SUCCESS;
}
-
-struct
-{
- char *ext;
- int fmt;
-}
-static formats[] = {
- { ".png", PA_FORMAT_PNG },
- { ".jpg", PA_FORMAT_JPEG },
- { ".jpeg", PA_FORMAT_JPEG },
- { ".ico", PA_FORMAT_ICON },
- { ".bmp", PA_FORMAT_BMP },
- { ".gif", PA_FORMAT_GIF },
-};
-
-int ext_to_format(const std::string &ext)
-{
- for(size_t i=0; i<SIZEOF(formats); i++)
- {
- if(ext == formats[i].ext)
- return formats[i].fmt;
- }
-
- return PA_FORMAT_UNKNOWN;
-}
diff --git a/protocols/FacebookRM/src/utils.h b/protocols/FacebookRM/src/utils.h index 6839a4367e..8da874c96b 100644 --- a/protocols/FacebookRM/src/utils.h +++ b/protocols/FacebookRM/src/utils.h @@ -109,7 +109,5 @@ private: int timeout_;
};
-int ext_to_format(const std::string &ext);
-
void MB(const char* m);
void MBI(int a);
diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp index 66a249b92c..9130366d8d 100644 --- a/protocols/Gadu-Gadu/src/avatar.cpp +++ b/protocols/Gadu-Gadu/src/avatar.cpp @@ -30,7 +30,6 @@ void GGPROTO::getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen) {
int tPathLen;
TCHAR *path = (TCHAR*)alloca(cbLen * sizeof(TCHAR));
- TCHAR *avatartype = NULL;
if (hAvatarsFolder == NULL || FoldersGetCustomPathT(hAvatarsFolder, path, cbLen, _T("")))
tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST( _T("%miranda_avatarcache%")), m_szModuleName);
@@ -51,22 +50,18 @@ void GGPROTO::getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen) }
}
- switch (getByte(hContact, GG_KEY_AVATARTYPE, GG_KEYDEF_AVATARTYPE)) {
- case PA_FORMAT_JPEG: avatartype = _T("jpg"); break;
- case PA_FORMAT_GIF: avatartype = _T("gif"); break;
- case PA_FORMAT_PNG: avatartype = _T("png"); break;
- }
+ const TCHAR *avatartype = ProtoGetAvatarExtension( getByte(hContact, GG_KEY_AVATARTYPE, GG_KEYDEF_AVATARTYPE));
if (hContact != NULL) {
DBVARIANT dbv;
if (!getString(hContact, GG_KEY_AVATARHASH, &dbv)) {
TCHAR* avatarHashT = mir_a2t(dbv.pszVal);
- mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s.%s"), avatarHashT, avatartype);
+ mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s%s"), avatarHashT, avatartype);
mir_free(avatarHashT);
db_free(&dbv);
}
}
- else mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%S avatar.%s"), m_szModuleName, avatartype);
+ else mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%S avatar%s"), m_szModuleName, avatartype);
}
bool GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts)
@@ -247,7 +242,7 @@ void __cdecl GGPROTO::avatarrequestthread(void*) for (int i=0; i < resp->headersCount; i++)
{
NETLIBHTTPHEADER& tHeader = resp->headers[i];
- if (!_stricmp(tHeader.szName, "Content-Type")){
+ if (!_stricmp(tHeader.szName, "Content-Type")) {
if (!_stricmp(tHeader.szValue, "image/jpeg"))
avatarType = PA_FORMAT_JPEG;
else if (!_stricmp(tHeader.szValue, "image/gif"))
diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp index adb9e792d6..6fef25e6d9 100644 --- a/protocols/Gadu-Gadu/src/services.cpp +++ b/protocols/Gadu-Gadu/src/services.cpp @@ -168,37 +168,6 @@ INT_PTR GGPROTO::getavatarcaps(WPARAM wParam, LPARAM lParam) return 0;
}
-int GetImageFormat(TCHAR *filename)
-{
- size_t len = lstrlen(filename);
-
- if (len < 5)
- return PA_FORMAT_UNKNOWN;
-
- if (_tcsicmp(_T(".png"), &filename[len-4]) == 0)
- return PA_FORMAT_PNG;
-
- if (_tcsicmp(_T(".jpg"), &filename[len-4]) == 0 || _tcsicmp(_T(".jpeg"), &filename[len-4]) == 0)
- return PA_FORMAT_JPEG;
-
- if (_tcsicmp(_T(".ico"), &filename[len-4]) == 0)
- return PA_FORMAT_ICON;
-
- if (_tcsicmp(_T(".bmp"), &filename[len-4]) == 0 || _tcsicmp(_T(".rle"), &filename[len-4]) == 0)
- return PA_FORMAT_BMP;
-
- if (_tcsicmp(_T(".gif"), &filename[len-4]) == 0)
- return PA_FORMAT_GIF;
-
- if (_tcsicmp(_T(".swf"), &filename[len-4]) == 0)
- return PA_FORMAT_SWF;
-
- if (_tcsicmp(_T(".xml"), &filename[len-4]) == 0)
- return PA_FORMAT_XML;
-
- return PA_FORMAT_UNKNOWN;
-}
-
//////////////////////////////////////////////////////////
// gets avatar information
// registered as ProtoService PS_GETAVATARINFOT
@@ -226,7 +195,7 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam) if ((_tcslen(dbv.ptszVal)>0) && db_get_b(pai->hContact, "ContactPhoto", "Locked", 0)){
netlog("getavatarinfo(): Incoming request for avatar information. Contact has assigned Locked ContactPhoto. return GAIR_SUCCESS");
_tcscpy_s(pai->filename, SIZEOF(pai->filename) ,dbv.ptszVal);
- pai->format = GetImageFormat(pai->filename);
+ pai->format = ProtoGetAvatarFormat(pai->filename);
db_free(&dbv);
return GAIR_SUCCESS;
}
@@ -357,20 +326,10 @@ INT_PTR GGPROTO::setmyavatar(WPARAM wParam, LPARAM lParam) m_tszUserName, MB_OK | MB_ICONINFORMATION);
return -1;
}
-
-
- TCHAR *szAvType = _tcsrchr(szFilename, '.');
- int iAvType = -1;
- szAvType++;
- if (!_tcsicmp(szAvType, _T("jpg")))
- iAvType = PA_FORMAT_JPEG;
- else if (!_tcsicmp(szAvType, _T("gif")))
- iAvType = PA_FORMAT_GIF;
- else if (!_tcsicmp(szAvType, _T("png")))
- iAvType = PA_FORMAT_PNG;
-
- if ( iAvType == -1) {
- netlog("setmyavatar(): Failed to set user avatar. File %S has incompatible extansion.", szAvType);
+
+ int iAvType = ProtoGetAvatarFormat(szFilename);
+ if ( iAvType == PA_FORMAT_UNKNOWN) {
+ netlog("setmyavatar(): Failed to set user avatar. File %s has incompatible extension.", szFilename);
return -1;
}
diff --git a/protocols/IcqOscarJ/src/icq_avatar.cpp b/protocols/IcqOscarJ/src/icq_avatar.cpp index 4058cf4649..b3f02e8f13 100644 --- a/protocols/IcqOscarJ/src/icq_avatar.cpp +++ b/protocols/IcqOscarJ/src/icq_avatar.cpp @@ -177,55 +177,8 @@ void CIcqProto::GetAvatarFileName(int dwUin, const char *szUid, TCHAR *pszDest, void AddAvatarExt(int dwFormat, TCHAR *pszDest)
{
- if (dwFormat == PA_FORMAT_JPEG)
- _tcscat(pszDest, _T(".jpg"));
- else if (dwFormat == PA_FORMAT_GIF)
- _tcscat(pszDest, _T(".gif"));
- else if (dwFormat == PA_FORMAT_PNG)
- _tcscat(pszDest, _T(".png"));
- else if (dwFormat == PA_FORMAT_BMP)
- _tcscat(pszDest, _T(".bmp"));
- else if (dwFormat == PA_FORMAT_XML)
- _tcscat(pszDest, _T(".xml"));
- else if (dwFormat == PA_FORMAT_SWF)
- _tcscat(pszDest, _T(".swf"));
- else
- _tcscat(pszDest, _T(".dat"));
-}
-
-
-int DetectAvatarFormatBuffer(const char *pBuffer)
-{
- if (!strncmp(pBuffer, "%PNG", 4))
- return PA_FORMAT_PNG;
-
- if (!strncmp(pBuffer, "GIF8", 4))
- return PA_FORMAT_GIF;
-
- if (!_strnicmp(pBuffer, "<?xml", 5))
- return PA_FORMAT_XML;
-
- if ((((DWORD*)pBuffer)[0] == 0xE0FFD8FFul) || (((DWORD*)pBuffer)[0] == 0xE1FFD8FFul))
- return PA_FORMAT_JPEG;
-
- if (!strncmp(pBuffer, "BM", 2))
- return PA_FORMAT_BMP;
-
- return PA_FORMAT_UNKNOWN;
-}
-
-
-int DetectAvatarFormat(const TCHAR *tszFile)
-{
- int src = _topen(tszFile, _O_BINARY | _O_RDONLY, 0);
- if (src == -1)
- return PA_FORMAT_UNKNOWN;
-
- char pBuf[32];
- _read(src, pBuf, 32);
- _close(src);
-
- return DetectAvatarFormatBuffer(pBuf);
+ const TCHAR *ext = ProtoGetAvatarExtension(dwFormat);
+ _tcscat(pszDest, (*ext == 0) ? _T(".dat") : ext);
}
@@ -424,7 +377,7 @@ void CIcqProto::handleAvatarOwnerHash(WORD wItemID, BYTE bFlags, BYTE *pData, BY { // we have different avatar, sync that
if (m_bSsiEnabled && getByte("ForceOurAvatar", 1))
{ // we want our avatar, update hash
- DWORD dwPaFormat = DetectAvatarFormat(file);
+ DWORD dwPaFormat = ::ProtoGetAvatarFileFormat(file);
BYTE *pHash = (BYTE*)_alloca(0x14);
NetLog_Server("Our avatar is different, setting our new hash.");
@@ -463,7 +416,7 @@ void CIcqProto::handleAvatarOwnerHash(WORD wItemID, BYTE bFlags, BYTE *pData, BY SetMyAvatar(0, 0);
break;
}
- DWORD dwPaFormat = DetectAvatarFormat(file);
+ DWORD dwPaFormat = ::ProtoGetAvatarFileFormat(file);
BYTE *hash = calcMD5HashOfFile(file);
if (!hash)
@@ -1653,11 +1606,10 @@ void avatars_server_connection::handleAvatarFam(BYTE *pBuffer, WORD wBufferLengt {
NetLog_Server("Received user avatar, storing (%d bytes).", datalen);
- int dwPaFormat = DetectAvatarFormatBuffer((char*)pBuffer);
- TCHAR *tszImageFile = (TCHAR*)_alloca(sizeof(TCHAR)*(strlennull(pCookieData->szFile) + 6));
-
- _tcscpy(tszImageFile, pCookieData->szFile);
- AddAvatarExt(dwPaFormat, tszImageFile);
+ const TCHAR *ptszExt;
+ int dwPaFormat = ProtoGetBufferFormat(pBuffer, &ptszExt);
+ TCHAR tszImageFile[MAX_PATH];
+ mir_sntprintf(tszImageFile, SIZEOF(tszImageFile), _T("%s%s"), pCookieData->szFile, ptszExt);
ppro->setByte(pCookieData->hContact, "AvatarType", (BYTE)dwPaFormat);
ai.format = dwPaFormat; // set the format
diff --git a/protocols/IcqOscarJ/src/icq_avatar.h b/protocols/IcqOscarJ/src/icq_avatar.h index 954dd28226..b6193c7717 100644 --- a/protocols/IcqOscarJ/src/icq_avatar.h +++ b/protocols/IcqOscarJ/src/icq_avatar.h @@ -118,8 +118,6 @@ __inline static void SAFE_DELETE(avatars_request **p) { SAFE_DELETE((MZeroedObje #define ART_UPLOAD 2
#define ART_BLOCK 4
-
-int DetectAvatarFormat(const TCHAR *szFile);
void AddAvatarExt(int dwFormat, TCHAR *pszDest);
BYTE* calcMD5HashOfFile(const TCHAR *szFile);
diff --git a/protocols/IcqOscarJ/src/icqosc_svcs.cpp b/protocols/IcqOscarJ/src/icqosc_svcs.cpp index 8bd8195462..ff04d94b85 100644 --- a/protocols/IcqOscarJ/src/icqosc_svcs.cpp +++ b/protocols/IcqOscarJ/src/icqosc_svcs.cpp @@ -333,49 +333,37 @@ INT_PTR CIcqProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) if (wParam == AF_MAXSIZE)
{
POINT *size = (POINT*)lParam;
-
- if (size)
- {
+ if (size) {
size->x = 64;
size->y = 64;
-
- return 0;
}
+ return 0;
}
- else if (wParam == AF_PROPORTION)
- {
+
+ if (wParam == AF_PROPORTION)
return PIP_NONE;
- }
- else if (wParam == AF_FORMATSUPPORTED)
- {
- if (lParam == PA_FORMAT_JPEG || lParam == PA_FORMAT_GIF || lParam == PA_FORMAT_XML || lParam == PA_FORMAT_BMP)
- return 1;
- else
- return 0;
- }
- else if (wParam == AF_ENABLED)
- {
- if (m_bSsiEnabled && m_bAvatarsEnabled)
- return 1;
- else
- return 0;
- }
- else if (wParam == AF_DONTNEEDDELAYS)
- {
+
+ if (wParam == AF_FORMATSUPPORTED)
+ return (lParam == PA_FORMAT_JPEG || lParam == PA_FORMAT_GIF || lParam == PA_FORMAT_XML || lParam == PA_FORMAT_BMP);
+
+ if (wParam == AF_ENABLED)
+ return (m_bSsiEnabled && m_bAvatarsEnabled);
+
+ if (wParam == AF_DONTNEEDDELAYS)
return 0;
- }
- else if (wParam == AF_MAXFILESIZE)
- { // server accepts images of 7168 bytees, not bigger
+
+ // server accepts images of 7168 bytees, not bigger
+ if (wParam == AF_MAXFILESIZE)
return 7168;
- }
- else if (wParam == AF_DELAYAFTERFAIL)
- { // do not request avatar again if server gave an error
+
+ // do not request avatar again if server gave an error
+ if (wParam == AF_DELAYAFTERFAIL)
return 1 * 60 * 60 * 1000; // one hour
- }
- else if (wParam == AF_FETCHALWAYS)
- { // avatars can be fetched all the time (server only operation)
+
+ // avatars can be fetched all the time (server only operation)
+ if (wParam == AF_FETCHALWAYS)
return 1;
- }
+
return 0;
}
@@ -561,7 +549,7 @@ INT_PTR CIcqProto::SetMyAvatar(WPARAM wParam, LPARAM lParam) if (tszFile)
{ // set file for avatar
- int dwPaFormat = DetectAvatarFormat(tszFile);
+ int dwPaFormat = ::ProtoGetAvatarFileFormat(tszFile);
if (dwPaFormat != PA_FORMAT_XML)
{
// if it should be image, check if it is valid
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; i<MIR_SHA1_HASH_SIZE; i++)
sprintf(buf+(i<<1), "%02x", digest[i]);
- m_options.AvatarType = JabberGetPictureType(pResult);
+ m_options.AvatarType = ProtoGetBufferFormat(pResult);
GetAvatarFileName(NULL, tFileName, MAX_PATH);
FILE* out = _tfopen(tFileName, _T("wb"));
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 34f429c83b..2a319cd7ea 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -969,18 +969,6 @@ TCHAR* __stdcall JabberStripJid(const TCHAR *jid, TCHAR *dest, size_t destLen) /////////////////////////////////////////////////////////////////////////////////////////
// JabberGetPictureType - tries to autodetect the picture type from the buffer
-int __stdcall JabberGetPictureType(const char* buf)
-{
- if (buf != NULL) {
- if (memcmp(buf, "GIF8", 4) == 0) return PA_FORMAT_GIF;
- if (memcmp(buf, "\x89PNG", 4) == 0) return PA_FORMAT_PNG;
- if (memcmp(buf, "BM", 2) == 0) return PA_FORMAT_BMP;
- if (memcmp(buf, "\xFF\xD8", 2) == 0) return PA_FORMAT_JPEG;
- }
-
- return PA_FORMAT_UNKNOWN;
-}
-
LPCTSTR __stdcall JabberGetPictureType(HXML node, const char *picBuf)
{
if (LPCTSTR ptszType = xmlGetText( xmlGetChild(node , "TYPE")))
@@ -990,7 +978,7 @@ LPCTSTR __stdcall JabberGetPictureType(HXML node, const char *picBuf) !_tcscmp(ptszType, _T("image/bmp")))
return ptszType;
- switch(JabberGetPictureType(picBuf)) {
+ switch( ProtoGetBufferFormat(picBuf)) {
case PA_FORMAT_GIF: return _T("image/gif");
case PA_FORMAT_BMP: return _T("image/bmp");
case PA_FORMAT_PNG: return _T("image/png");
@@ -1641,7 +1629,7 @@ void __cdecl CJabberProto::LoadHttpAvatars(void* param) if (res) {
hHttpCon = res->nlc;
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<MIR_SHA1_HASH_SIZE; j++)
sprintf(buf+(j<<1), "%02x", digest[j]);
- m_options.AvatarType = JabberGetPictureType(buffer);
+ m_options.AvatarType = ProtoGetBufferFormat(buffer);
if (bPhotoChanged) {
DeleteFile(szAvatarName);
diff --git a/protocols/MSN/src/msn_avatar.cpp b/protocols/MSN/src/msn_avatar.cpp index 4543038281..eae7364de7 100644 --- a/protocols/MSN/src/msn_avatar.cpp +++ b/protocols/MSN/src/msn_avatar.cpp @@ -75,7 +75,7 @@ LBL_Error: }
const TCHAR *szExt;
- int fmt = MSN_GetImageFormat(nlhrReply->pData, &szExt);
+ int fmt = ProtoGetBufferFormat(nlhrReply->pData, &szExt);
if (fmt == PA_FORMAT_UNKNOWN)
goto LBL_Error;
diff --git a/protocols/MSN/src/msn_contact.cpp b/protocols/MSN/src/msn_contact.cpp index 630635e546..5739d96294 100644 --- a/protocols/MSN/src/msn_contact.cpp +++ b/protocols/MSN/src/msn_contact.cpp @@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "msn_global.h"
#include "msn_proto.h"
-HANDLE CMsnProto::MSN_HContactFromEmail(const char* wlid, const char* msnNick, bool addIfNeeded, bool temporary)
+HANDLE CMsnProto::MSN_HContactFromEmail(const char* wlid, const char* msnNick, bool addIfNeeded, bool temporary)
{
HANDLE hContact = NULL;
diff --git a/protocols/MSN/src/msn_global.h b/protocols/MSN/src/msn_global.h index 99b4448964..ea44ab8228 100644 --- a/protocols/MSN/src/msn_global.h +++ b/protocols/MSN/src/msn_global.h @@ -173,8 +173,6 @@ void UrlEncode(const char* src, char* dest, size_t cbDest); void __cdecl MSN_ConnectionProc(HANDLE hNewConnection, DWORD dwRemoteIP, void*);
char* MSN_GetAvatarHash(char* szContext, char** pszUrl = NULL);
-int MSN_GetImageFormat(void* buf, const TCHAR** ext);
-int MSN_GetImageFormat(const TCHAR* file);
bool MSN_MsgWndExist(HANDLE hContact);
#define MSN_SendNickname(a) MSN_SendNicknameUtf(UTF8(a))
diff --git a/protocols/MSN/src/msn_lists.cpp b/protocols/MSN/src/msn_lists.cpp index f218a1171c..02eb12c80d 100644 --- a/protocols/MSN/src/msn_lists.cpp +++ b/protocols/MSN/src/msn_lists.cpp @@ -35,7 +35,7 @@ void CMsnProto::Lists_Uninit(void) DeleteCriticalSection(&csLists);
}
-void CMsnProto::Lists_Wipe(void)
+void CMsnProto::Lists_Wipe(void)
{
EnterCriticalSection(&csLists);
contList.destroy();
@@ -220,7 +220,7 @@ int CMsnProto::Lists_Add(int list, int netId, const char* email, HANDLE hContact return result;
}
-void CMsnProto::Lists_Remove(int list, const char* email)
+void CMsnProto::Lists_Remove(int list, const char* email)
{
EnterCriticalSection(&csLists);
int i = contList.getIndex((MsnContact*)&email);
@@ -236,7 +236,7 @@ void CMsnProto::Lists_Remove(int list, const char* email) }
-void CMsnProto::Lists_Populate(void)
+void CMsnProto::Lists_Populate(void)
{
HANDLE hContact = db_find_first(m_szModuleName);
while (hContact) {
diff --git a/protocols/MSN/src/msn_menu.cpp b/protocols/MSN/src/msn_menu.cpp index f8f56c334a..b6760000cb 100644 --- a/protocols/MSN/src/msn_menu.cpp +++ b/protocols/MSN/src/msn_menu.cpp @@ -350,7 +350,7 @@ void CMsnProto::MsnRemoveMainMenus(void) CallService(MS_CLIST_REMOVEMAINMENUITEM, (WPARAM)mainMenuRoot, 0);
}
-void CMsnProto::MSN_EnableMenuItems(bool bEnable)
+void CMsnProto::MSN_EnableMenuItems(bool bEnable)
{
CLISTMENUITEM mi = { sizeof(mi) };
mi.flags = CMIM_FLAGS;
diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index 4f9c3a47e6..b765ff5e59 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /////////////////////////////////////////////////////////////////////////////////////////
// MirandaStatusToMSN - status helper functions
-const char* CMsnProto::MirandaStatusToMSN(int status)
+const char* CMsnProto::MirandaStatusToMSN(int status)
{
switch(status)
{
@@ -44,7 +44,7 @@ const char* CMsnProto::MirandaStatusToMSN(int status) default: return "NLN";
} }
-WORD CMsnProto::MSNStatusToMiranda(const char *status)
+WORD CMsnProto::MSNStatusToMiranda(const char *status)
{
switch((*(PDWORD)status&0x00FFFFFF) | 0x20000000)
{
@@ -60,7 +60,7 @@ WORD CMsnProto::MSNStatusToMiranda(const char *status) }
}
-char** CMsnProto::GetStatusMsgLoc(int status)
+char** CMsnProto::GetStatusMsgLoc(int status)
{
static const int modes[MSN_NUM_MODES] =
{
@@ -84,7 +84,7 @@ char** CMsnProto::GetStatusMsgLoc(int status) /////////////////////////////////////////////////////////////////////////////////////////
// MSN_AddAuthRequest - adds the authorization event to the database
-void CMsnProto::MSN_AddAuthRequest(const char *email, const char *nick, const char *reason)
+void CMsnProto::MSN_AddAuthRequest(const char *email, const char *nick, const char *reason)
{
//blob is: UIN=0(DWORD), hContact(DWORD), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), email(ASCIIZ), ""(ASCIIZ)
@@ -197,7 +197,7 @@ char* MSN_GetAvatarHash(char* szContext, char** pszUrl) /////////////////////////////////////////////////////////////////////////////////////////
// MSN_GetAvatarFileName - gets a file name for an contact's avatar
-void CMsnProto::MSN_GetAvatarFileName(HANDLE hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext)
+void CMsnProto::MSN_GetAvatarFileName(HANDLE hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext)
{
size_t tPathLen;
@@ -268,45 +268,7 @@ void CMsnProto::MSN_GetAvatarFileName(HANDLE hContact, TCHAR* pszDest, size_t c else mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext);
}
-int MSN_GetImageFormat(void* buf, const TCHAR** ext)
-{
- if (*(unsigned short*)buf == 0xd8ff) {
- *ext = _T("jpg");
- return PA_FORMAT_JPEG;
- }
- if (*(unsigned short*)buf == 0x4d42) {
- *ext = _T("bmp");
- return PA_FORMAT_BMP;
- }
- if (*(unsigned*)buf == 0x474e5089) {
- *ext = _T("png");
- return PA_FORMAT_PNG;
- }
- if (*(unsigned*)buf == 0x38464947) {
- *ext = _T("gif");
- return PA_FORMAT_GIF;
- }
-
- *ext = _T("unk");
- return PA_FORMAT_UNKNOWN;
-}
-
-int MSN_GetImageFormat(const TCHAR* file)
-{
- const TCHAR *ext = _tcsrchr(file, '.');
- if (ext == NULL)
- return PA_FORMAT_UNKNOWN;
- if (_tcsicmp(ext, _T(".gif")) == 0)
- return PA_FORMAT_GIF;
- else if (_tcsicmp(ext, _T(".bmp")) == 0)
- return PA_FORMAT_BMP;
- else if (_tcsicmp(ext, _T(".png")) == 0)
- return PA_FORMAT_PNG;
- else
- return PA_FORMAT_JPEG;
-}
-
-int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen)
+int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen)
{
mir_sha1_ctx sha1ctx;
BYTE sha1c[MIR_SHA1_HASH_SIZE], sha1d[MIR_SHA1_HASH_SIZE];
@@ -363,8 +325,9 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen free(szBuffer);
const TCHAR *szExt;
- int fmt = MSN_GetImageFormat(pData, &szExt);
- if (fmt == PA_FORMAT_UNKNOWN) return fmt;
+ int fmt = ProtoGetBufferFormat(pData, &szExt);
+ if (fmt == PA_FORMAT_UNKNOWN)
+ return fmt;
TCHAR szFileName[MAX_PATH];
MSN_GetAvatarFileName(NULL, szFileName, SIZEOF(szFileName), NULL);
@@ -395,7 +358,7 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen /////////////////////////////////////////////////////////////////////////////////////////
// MSN_GetCustomSmileyFileName - gets a file name for an contact's custom smiley
-void CMsnProto::MSN_GetCustomSmileyFileName(HANDLE hContact, TCHAR* pszDest, size_t cbLen, const char* SmileyName, int type)
+void CMsnProto::MSN_GetCustomSmileyFileName(HANDLE hContact, TCHAR* pszDest, size_t cbLen, const char* SmileyName, int type)
{
size_t tPathLen;
@@ -629,7 +592,7 @@ static VOID CALLBACK TypingTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWO }
-void CMsnProto::MSN_StartStopTyping(ThreadData* info, bool start)
+void CMsnProto::MSN_StartStopTyping(ThreadData* info, bool start)
{
if (start && info->mTimerId == 0) {
info->mTimerId = SetTimer(NULL, 0, 5000, TypingTimerProc);
@@ -654,7 +617,7 @@ static char * HtmlEncodeUTF8T(const TCHAR *src) return HtmlEncode(UTF8(src));
}
-void CMsnProto::MSN_SendStatusMessage(const char* msg)
+void CMsnProto::MSN_SendStatusMessage(const char* msg)
{
if (!msnLoggedIn)
return;
@@ -770,7 +733,7 @@ int ThreadData::sendPacket(const char* cmd, const char* fmt,...) /////////////////////////////////////////////////////////////////////////////////////////
// MSN_SetServerStatus - changes plugins status at the server
-void CMsnProto::MSN_SetServerStatus(int newStatus)
+void CMsnProto::MSN_SetServerStatus(int newStatus)
{
MSN_DebugLog("Setting MSN server status %d, logged in = %d", newStatus, msnLoggedIn);
diff --git a/protocols/MSN/src/msn_msgqueue.cpp b/protocols/MSN/src/msn_msgqueue.cpp index a82cad6a49..040ceedc72 100644 --- a/protocols/MSN/src/msn_msgqueue.cpp +++ b/protocols/MSN/src/msn_msgqueue.cpp @@ -38,7 +38,7 @@ void CMsnProto::MsgQueue_Uninit(void) DeleteCriticalSection(&csMsgQueue);
}
-int CMsnProto::MsgQueue_Add(const char* wlid, int msgType, const char* msg, int msgSize, filetransfer* ft, int flags, STRLIST *cnt)
+int CMsnProto::MsgQueue_Add(const char* wlid, int msgType, const char* msg, int msgSize, filetransfer* ft, int flags, STRLIST *cnt)
{
EnterCriticalSection(&csMsgQueue);
@@ -112,7 +112,7 @@ const char* CMsnProto::MsgQueue_GetNextRecipient(void) }
//deletes from list. Must mir_free() return value
-bool CMsnProto::MsgQueue_GetNext(const char* wlid, MsgQueueEntry& retVal)
+bool CMsnProto::MsgQueue_GetNext(const char* wlid, MsgQueueEntry& retVal)
{
int i;
@@ -131,7 +131,7 @@ bool CMsnProto::MsgQueue_GetNext(const char* wlid, MsgQueueEntry& retVal) return res;
}
-int CMsnProto::MsgQueue_NumMsg(const char* wlid)
+int CMsnProto::MsgQueue_NumMsg(const char* wlid)
{
int res = 0;
EnterCriticalSection(&csMsgQueue);
@@ -143,7 +143,7 @@ int CMsnProto::MsgQueue_NumMsg(const char* wlid) return res;
}
-void CMsnProto::MsgQueue_Clear(const char* wlid, bool msg)
+void CMsnProto::MsgQueue_Clear(const char* wlid, bool msg)
{
int i;
diff --git a/protocols/MSN/src/msn_p2p.cpp b/protocols/MSN/src/msn_p2p.cpp index 9c3c60489b..a67a378f16 100644 --- a/protocols/MSN/src/msn_p2p.cpp +++ b/protocols/MSN/src/msn_p2p.cpp @@ -219,8 +219,7 @@ void CMsnProto::p2p_savePicture2disk(filetransfer* ft) if (p2p_IsDlFileOk(ft))
{
int fileId = _topen(ft->std.tszCurrentFile, O_RDONLY | _O_BINARY, _S_IREAD);
- if (fileId == -1)
- {
+ if (fileId == -1) {
p2p_pictureTransferFailed(ft);
return;
}
@@ -232,9 +231,8 @@ void CMsnProto::p2p_savePicture2disk(filetransfer* ft) int bytes = _read(fileId, buf, sizeof(buf));
_close(fileId);
if (bytes > 4)
- format = MSN_GetImageFormat(buf, &ext);
- else
- {
+ format = ProtoGetBufferFormat(buf, &ext);
+ else {
p2p_pictureTransferFailed(ft);
return;
}
@@ -293,7 +291,7 @@ void CMsnProto::p2p_savePicture2disk(filetransfer* ft) static const char sttVoidSession[] = "ACHTUNG!!! an attempt made to send a message via the empty session";
-void CMsnProto::p2p_sendMsg(const char *wlid, unsigned appId, P2PB_Header& hdrdata, char* msgbody, size_t msgsz)
+void CMsnProto::p2p_sendMsg(const char *wlid, unsigned appId, P2PB_Header& hdrdata, char* msgbody, size_t msgsz)
{
ThreadData* info = MSN_GetP2PThreadByContact(wlid);
if (info == NULL)
@@ -304,7 +302,7 @@ void CMsnProto::p2p_sendMsg(const char *wlid, unsigned appId, P2PB_Header& hdrd p2p_sendMsg(info, wlid, appId, hdrdata, msgbody, msgsz);
}
-void CMsnProto::p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId, P2PB_Header& hdrdata, char* msgbody, size_t msgsz)
+void CMsnProto::p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId, P2PB_Header& hdrdata, char* msgbody, size_t msgsz)
{
unsigned msgType;
@@ -416,7 +414,7 @@ void CMsnProto::p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId, }
-void CMsnProto::p2p_sendAck(const char *wlid, P2PB_Header* hdr)
+void CMsnProto::p2p_sendAck(const char *wlid, P2PB_Header* hdr)
{
if (hdr == NULL) return;
@@ -448,7 +446,7 @@ void CMsnProto::p2p_sendAck(const char *wlid, P2PB_Header* hdr) /////////////////////////////////////////////////////////////////////////////////////////
// p2p_sendEndSession - sends MSN P2P file transfer end packet
-void CMsnProto::p2p_sendAbortSession(filetransfer* ft)
+void CMsnProto::p2p_sendAbortSession(filetransfer* ft)
{
if (ft == NULL)
{
@@ -480,7 +478,7 @@ void CMsnProto::p2p_sendAbortSession(filetransfer* ft) ft->ts = time(NULL);
}
-void CMsnProto::p2p_sendRedirect(filetransfer* ft)
+void CMsnProto::p2p_sendRedirect(filetransfer* ft)
{
if (ft == NULL)
{
@@ -507,7 +505,7 @@ void CMsnProto::p2p_sendRedirect(filetransfer* ft) /////////////////////////////////////////////////////////////////////////////////////////
// p2p_sendSlp - send MSN P2P SLP packet
-void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders,
+void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders,
MimeHeaders &pContent, const char *wlid)
{
if (ft == NULL)
@@ -602,7 +600,7 @@ void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders, /////////////////////////////////////////////////////////////////////////////////////////
// p2p_sendBye - closes P2P session
-void CMsnProto::p2p_sendBye(filetransfer* ft)
+void CMsnProto::p2p_sendBye(filetransfer* ft)
{
if (ft == NULL)
{
@@ -623,13 +621,13 @@ void CMsnProto::p2p_sendBye(filetransfer* ft) p2p_sendSlp(-1, ft, tHeaders, chdrs);
}
-void CMsnProto::p2p_sendCancel(filetransfer* ft)
+void CMsnProto::p2p_sendCancel(filetransfer* ft)
{
p2p_sendBye(ft);
p2p_sendAbortSession(ft);
}
-void CMsnProto::p2p_sendNoCall(filetransfer* ft)
+void CMsnProto::p2p_sendNoCall(filetransfer* ft)
{
if (ft == NULL)
{
@@ -653,7 +651,7 @@ void CMsnProto::p2p_sendNoCall(filetransfer* ft) /////////////////////////////////////////////////////////////////////////////////////////
// p2p_sendStatus - send MSN P2P status and its description
-void CMsnProto::p2p_sendStatus(filetransfer* ft, long lStatus)
+void CMsnProto::p2p_sendStatus(filetransfer* ft, long lStatus)
{
if (ft == NULL)
{
@@ -681,7 +679,7 @@ void CMsnProto::p2p_sendStatus(filetransfer* ft, long lStatus) p2p_sendSlp(lStatus, ft, tHeaders, chdrs);
}
-void CMsnProto::p2p_sendAvatarInit(filetransfer* ft)
+void CMsnProto::p2p_sendAvatarInit(filetransfer* ft)
{
unsigned body = 0;
@@ -888,7 +886,7 @@ LBL_Error: return true;
}
-LONG CMsnProto::p2p_sendPortion(filetransfer* ft, ThreadData* T, bool isV2)
+LONG CMsnProto::p2p_sendPortion(filetransfer* ft, ThreadData* T, bool isV2)
{
LONG trid;
char databuf[1500], *p = databuf;
@@ -1068,7 +1066,7 @@ void __cdecl CMsnProto::p2p_sendFeedThread(void* arg) }
-void CMsnProto::p2p_sendFeedStart(filetransfer* ft)
+void CMsnProto::p2p_sendFeedStart(filetransfer* ft)
{
if (ft->std.flags & PFTS_SENDING)
{
@@ -1860,7 +1858,7 @@ void CMsnProto::p2p_processSIP(ThreadData* info, char* msgbody, P2PB_Header* hdr /////////////////////////////////////////////////////////////////////////////////////////
// p2p_processMsg - processes all MSN P2P incoming messages
-void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* wlid)
+void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* wlid)
{
P2PV2_Header hdrdata;
@@ -1966,7 +1964,7 @@ void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* }
}
-void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wlid)
+void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wlid)
{
P2P_Header hdrdata;
msgbody = hdrdata.parseMsg(msgbody);
@@ -2153,7 +2151,7 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wl /////////////////////////////////////////////////////////////////////////////////////////
// p2p_invite - invite another side to transfer an avatar
-void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid)
+void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid)
{
const char* szAppID;
switch(iAppID)
@@ -2394,7 +2392,7 @@ void CMsnProto::p2p_sendSessionAck(filetransfer* ft) p2p_sendSlp(-3, ft, tResult, chdrs);
}
*/
-void CMsnProto::p2p_sessionComplete(filetransfer* ft)
+void CMsnProto::p2p_sessionComplete(filetransfer* ft)
{
if (ft->p2p_appID != MSN_APPID_FILE)
p2p_unregisterSession(ft);
diff --git a/protocols/MSN/src/msn_p2ps.cpp b/protocols/MSN/src/msn_p2ps.cpp index 4bfb86d1ee..b642180695 100644 --- a/protocols/MSN/src/msn_p2ps.cpp +++ b/protocols/MSN/src/msn_p2ps.cpp @@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /////////////////////////////////////////////////////////////////////////////////////////
// add file session to a list
-void CMsnProto::p2p_registerSession(filetransfer* ft)
+void CMsnProto::p2p_registerSession(filetransfer* ft)
{
EnterCriticalSection(&sessionLock);
sessionList.insert(ft);
@@ -36,7 +36,7 @@ void CMsnProto::p2p_registerSession(filetransfer* ft) /////////////////////////////////////////////////////////////////////////////////////////
// remove file session from a list
-void CMsnProto::p2p_unregisterSession(filetransfer* ft)
+void CMsnProto::p2p_unregisterSession(filetransfer* ft)
{
EnterCriticalSection(&sessionLock);
// int idx = sessionList.getIndex(ft);
@@ -48,7 +48,7 @@ void CMsnProto::p2p_unregisterSession(filetransfer* ft) /////////////////////////////////////////////////////////////////////////////////////////
// get session by some parameter
-filetransfer* CMsnProto::p2p_getSessionByID(unsigned id)
+filetransfer* CMsnProto::p2p_getSessionByID(unsigned id)
{
if (id == 0)
return NULL;
@@ -73,7 +73,7 @@ filetransfer* CMsnProto::p2p_getSessionByID(unsigned id) return ft;
}
-filetransfer* CMsnProto::p2p_getSessionByUniqueID(unsigned id)
+filetransfer* CMsnProto::p2p_getSessionByUniqueID(unsigned id)
{
if (id == 0)
return NULL;
@@ -99,7 +99,7 @@ filetransfer* CMsnProto::p2p_getSessionByUniqueID(unsigned id) }
-bool CMsnProto::p2p_sessionRegistered(filetransfer* ft)
+bool CMsnProto::p2p_sessionRegistered(filetransfer* ft)
{
if (ft != NULL && ft->p2p_appID == 0)
return true;
@@ -110,7 +110,7 @@ bool CMsnProto::p2p_sessionRegistered(filetransfer* ft) return idx > -1;
}
-filetransfer* CMsnProto::p2p_getThreadSession(HANDLE hContact, TInfoType mType)
+filetransfer* CMsnProto::p2p_getThreadSession(HANDLE hContact, TInfoType mType)
{
EnterCriticalSection(&sessionLock);
@@ -129,7 +129,7 @@ filetransfer* CMsnProto::p2p_getThreadSession(HANDLE hContact, TInfoType mType) return result;
}
-void CMsnProto::p2p_clearThreadSessions(HANDLE hContact, TInfoType mType)
+void CMsnProto::p2p_clearThreadSessions(HANDLE hContact, TInfoType mType)
{
EnterCriticalSection(&sessionLock);
@@ -147,7 +147,7 @@ void CMsnProto::p2p_clearThreadSessions(HANDLE hContact, TInfoType mType) LeaveCriticalSection(&sessionLock);
}
-filetransfer* CMsnProto::p2p_getAvatarSession(HANDLE hContact)
+filetransfer* CMsnProto::p2p_getAvatarSession(HANDLE hContact)
{
EnterCriticalSection(&sessionLock);
@@ -165,7 +165,7 @@ filetransfer* CMsnProto::p2p_getAvatarSession(HANDLE hContact) return result;
}
-bool CMsnProto::p2p_isAvatarOnly(HANDLE hContact)
+bool CMsnProto::p2p_isAvatarOnly(HANDLE hContact)
{
EnterCriticalSection(&sessionLock);
@@ -180,7 +180,7 @@ bool CMsnProto::p2p_isAvatarOnly(HANDLE hContact) return result;
}
-void CMsnProto::p2p_clearDormantSessions(void)
+void CMsnProto::p2p_clearDormantSessions(void)
{
EnterCriticalSection(&sessionLock);
@@ -204,7 +204,7 @@ void CMsnProto::p2p_clearDormantSessions(void) LeaveCriticalSection(&sessionLock);
}
-void CMsnProto::p2p_redirectSessions(const char *wlid)
+void CMsnProto::p2p_redirectSessions(const char *wlid)
{
EnterCriticalSection(&sessionLock);
@@ -232,7 +232,7 @@ void CMsnProto::p2p_redirectSessions(const char *wlid) LeaveCriticalSection(&sessionLock);
}
-void CMsnProto::p2p_startSessions(const char* wlid)
+void CMsnProto::p2p_startSessions(const char* wlid)
{
EnterCriticalSection(&sessionLock);
@@ -254,7 +254,7 @@ void CMsnProto::p2p_startSessions(const char* wlid) LeaveCriticalSection(&sessionLock);
}
-void CMsnProto::p2p_cancelAllSessions(void)
+void CMsnProto::p2p_cancelAllSessions(void)
{
EnterCriticalSection(&sessionLock);
@@ -267,7 +267,7 @@ void CMsnProto::p2p_cancelAllSessions(void) LeaveCriticalSection(&sessionLock);
}
-filetransfer* CMsnProto::p2p_getSessionByCallID(const char* CallID, const char* wlid)
+filetransfer* CMsnProto::p2p_getSessionByCallID(const char* CallID, const char* wlid)
{
if (CallID == NULL)
return NULL;
@@ -301,21 +301,21 @@ filetransfer* CMsnProto::p2p_getSessionByCallID(const char* CallID, const char* }
-void CMsnProto::p2p_registerDC(directconnection* dc)
+void CMsnProto::p2p_registerDC(directconnection* dc)
{
EnterCriticalSection(&sessionLock);
dcList.insert(dc);
LeaveCriticalSection(&sessionLock);
}
-void CMsnProto::p2p_unregisterDC(directconnection* dc)
+void CMsnProto::p2p_unregisterDC(directconnection* dc)
{
EnterCriticalSection(&sessionLock);
dcList.remove(dc);
LeaveCriticalSection(&sessionLock);
}
-directconnection* CMsnProto::p2p_getDCByCallID(const char* CallID, const char* wlid)
+directconnection* CMsnProto::p2p_getDCByCallID(const char* CallID, const char* wlid)
{
if (CallID == NULL)
return NULL;
diff --git a/protocols/MSN/src/msn_srv.cpp b/protocols/MSN/src/msn_srv.cpp index 5e92edd0f9..984f49d2c6 100644 --- a/protocols/MSN/src/msn_srv.cpp +++ b/protocols/MSN/src/msn_srv.cpp @@ -227,7 +227,7 @@ void CMsnProto::MSN_RenameServerGroup(LPCSTR szId, const char* newName) /////////////////////////////////////////////////////////////////////////////////////////
// MSN_UploadServerGroups - adds a group to the server list and contacts into the group
-void CMsnProto::MSN_UploadServerGroups(char* group)
+void CMsnProto::MSN_UploadServerGroups(char* group)
{
if (!MyOptions.ManageServer) return;
@@ -314,7 +314,7 @@ void CMsnProto::MSN_SyncContactToServerGroup(HANDLE hContact, const char* szCont /////////////////////////////////////////////////////////////////////////////////////////
// Msn_SendNickname - update our own nickname on the server
-void CMsnProto::MSN_SendNicknameUtf(const char* nickname)
+void CMsnProto::MSN_SendNicknameUtf(const char* nickname)
{
if (nickname[0])
setStringUtf(NULL, "Nick", nickname);
@@ -326,7 +326,7 @@ void CMsnProto::MSN_SendNicknameUtf(const char* nickname) ForkThread(&CMsnProto::msn_storeProfileThread, (void*)1);
}
-void CMsnProto::MSN_SetNicknameUtf(const char* nickname)
+void CMsnProto::MSN_SetNicknameUtf(const char* nickname)
{
const size_t urlNickSz = strlen(nickname) * 3 + 1;
char* urlNick = (char*)alloca(urlNickSz);
diff --git a/protocols/MSN/src/msn_std.cpp b/protocols/MSN/src/msn_std.cpp index 2b7d56a6df..06f6d9c9eb 100644 --- a/protocols/MSN/src/msn_std.cpp +++ b/protocols/MSN/src/msn_std.cpp @@ -34,7 +34,7 @@ int CMsnProto::getStringUtf(const char* name, DBVARIANT* result) { return db_get_utf(NULL, m_szModuleName, name, result);
}
-int CMsnProto::getStaticString(HANDLE hContact, const char* valueName, char* dest, unsigned dest_len)
+int CMsnProto::getStaticString(HANDLE hContact, const char* valueName, char* dest, unsigned dest_len)
{
DBVARIANT dbv;
dbv.pszVal = dest;
diff --git a/protocols/MSN/src/msn_svcs.cpp b/protocols/MSN/src/msn_svcs.cpp index ee59fdccde..5f1db4ff16 100644 --- a/protocols/MSN/src/msn_svcs.cpp +++ b/protocols/MSN/src/msn_svcs.cpp @@ -77,7 +77,7 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam,LPARAM lParam) if (AI->hContact == NULL || _stricmp(cont->email, MyOptions.szEmail) == 0) {
MSN_GetAvatarFileName(NULL, filename, SIZEOF(filename), NULL);
- AI->format = MSN_GetImageFormat(filename);
+ AI->format = ProtoGetAvatarFormat(filename);
if (AI->format != PA_FORMAT_UNKNOWN)
_tcscpy(AI->filename, filename);
return AI->format == PA_FORMAT_UNKNOWN ? GAIR_NOAVATAR : GAIR_SUCCESS;
@@ -92,7 +92,7 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam,LPARAM lParam) else return GAIR_NOAVATAR;
MSN_GetAvatarFileName(AI->hContact, filename, SIZEOF(filename), NULL);
- AI->format = MSN_GetImageFormat(filename);
+ AI->format = ProtoGetAvatarFormat(filename);
if (AI->format != PA_FORMAT_UNKNOWN) {
bool needupdate = true;
diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp index 8640a40140..e25bbb7085 100644 --- a/protocols/MSN/src/msn_threads.cpp +++ b/protocols/MSN/src/msn_threads.cpp @@ -300,12 +300,12 @@ LBL_Exit: MSN_DebugLog("Thread [%08X] ending now", GetCurrentThreadId());
}
-void CMsnProto::MSN_InitThreads(void)
+void CMsnProto::MSN_InitThreads(void)
{
InitializeCriticalSection(&sttLock);
}
-void CMsnProto::MSN_CloseConnections(void)
+void CMsnProto::MSN_CloseConnections(void)
{
EnterCriticalSection(&sttLock);
@@ -349,7 +349,7 @@ void CMsnProto::Threads_Uninit(void) DeleteCriticalSection(&sttLock);
}
-ThreadData* CMsnProto::MSN_GetThreadByContact(const char* wlid, TInfoType type)
+ThreadData* CMsnProto::MSN_GetThreadByContact(const char* wlid, TInfoType type)
{
ThreadData* result = NULL;
EnterCriticalSection(&sttLock);
@@ -393,7 +393,7 @@ ThreadData* CMsnProto::MSN_GetThreadByContact(const char* wlid, TInfoType type) return result;
}
-ThreadData* CMsnProto::MSN_GetThreadByChatId(const TCHAR* chatId)
+ThreadData* CMsnProto::MSN_GetThreadByChatId(const TCHAR* chatId)
{
ThreadData* result = NULL;
EnterCriticalSection(&sttLock);
@@ -413,7 +413,7 @@ ThreadData* CMsnProto::MSN_GetThreadByChatId(const TCHAR* chatId) return result;
}
-ThreadData* CMsnProto::MSN_GetThreadByTimer(UINT timerId)
+ThreadData* CMsnProto::MSN_GetThreadByTimer(UINT timerId)
{
ThreadData* result = NULL;
EnterCriticalSection(&sttLock);
@@ -432,7 +432,7 @@ ThreadData* CMsnProto::MSN_GetThreadByTimer(UINT timerId) return result;
}
-ThreadData* CMsnProto::MSN_GetP2PThreadByContact(const char *wlid)
+ThreadData* CMsnProto::MSN_GetP2PThreadByContact(const char *wlid)
{
ThreadData *result = NULL;
@@ -479,7 +479,7 @@ ThreadData* CMsnProto::MSN_GetP2PThreadByContact(const char *wlid) }
-void CMsnProto::MSN_StartP2PTransferByContact(const char* wlid)
+void CMsnProto::MSN_StartP2PTransferByContact(const char* wlid)
{
EnterCriticalSection(&sttLock);
@@ -499,7 +499,7 @@ void CMsnProto::MSN_StartP2PTransferByContact(const char* wlid) }
-ThreadData* CMsnProto::MSN_GetOtherContactThread(ThreadData* thread)
+ThreadData* CMsnProto::MSN_GetOtherContactThread(ThreadData* thread)
{
ThreadData* result = NULL;
EnterCriticalSection(&sttLock);
@@ -521,7 +521,7 @@ ThreadData* CMsnProto::MSN_GetOtherContactThread(ThreadData* thread) return result;
}
-ThreadData* CMsnProto::MSN_GetUnconnectedThread(const char* wlid, TInfoType type)
+ThreadData* CMsnProto::MSN_GetUnconnectedThread(const char* wlid, TInfoType type)
{
ThreadData* result = NULL;
EnterCriticalSection(&sttLock);
@@ -567,7 +567,7 @@ ThreadData* CMsnProto::MSN_StartSB(const char* wlid, bool& isOffline) -int CMsnProto::MSN_GetActiveThreads(ThreadData** parResult)
+int CMsnProto::MSN_GetActiveThreads(ThreadData** parResult)
{
int tCount = 0;
EnterCriticalSection(&sttLock);
@@ -583,7 +583,7 @@ int CMsnProto::MSN_GetActiveThreads(ThreadData** parResult) return tCount;
}
-ThreadData* CMsnProto::MSN_GetThreadByConnection(HANDLE s)
+ThreadData* CMsnProto::MSN_GetThreadByConnection(HANDLE s)
{
ThreadData* tResult = NULL;
EnterCriticalSection(&sttLock);
@@ -602,7 +602,7 @@ ThreadData* CMsnProto::MSN_GetThreadByConnection(HANDLE s) return tResult;
}
-ThreadData* CMsnProto::MSN_GetThreadByPort(WORD wPort)
+ThreadData* CMsnProto::MSN_GetThreadByPort(WORD wPort)
{
ThreadData* result = NULL;
EnterCriticalSection(&sttLock);
diff --git a/protocols/Skype/src/skype_avatars.cpp b/protocols/Skype/src/skype_avatars.cpp index 4f29a2e8cf..fbf8af6138 100644 --- a/protocols/Skype/src/skype_avatars.cpp +++ b/protocols/Skype/src/skype_avatars.cpp @@ -21,39 +21,6 @@ bool CSkypeProto::IsAvatarChanged(const SEBinary &avatar, HANDLE hContact) return result;
}
-int CSkypeProto::DetectAvatarFormatBuffer(const char *pBuffer)
-{
- if (!strncmp(pBuffer, "%PNG", 4))
- return PA_FORMAT_PNG;
-
- if (!strncmp(pBuffer, "GIF8", 4))
- return PA_FORMAT_GIF;
-
- if (!_strnicmp(pBuffer, "<?xml", 5))
- return PA_FORMAT_XML;
-
- if ((((DWORD *)pBuffer)[0] == 0xE0FFD8FFul) || (((DWORD *)pBuffer)[0] == 0xE1FFD8FFul))
- return PA_FORMAT_JPEG;
-
- if (!strncmp(pBuffer, "BM", 2))
- return PA_FORMAT_BMP;
-
- return PA_FORMAT_UNKNOWN;
-}
-
-int CSkypeProto::DetectAvatarFormat(const wchar_t *path)
-{
- int src = _wopen(path, _O_BINARY | _O_RDONLY, 0);
- if (src == -1)
- return PA_FORMAT_UNKNOWN;
-
- char pBuf[32];
- _read(src, pBuf, 32);
- _close(src);
-
- return CSkypeProto::DetectAvatarFormatBuffer(pBuf);
-}
-
wchar_t * CSkypeProto::GetContactAvatarFilePath(HANDLE hContact)
{
wchar_t *path = (wchar_t*)::mir_alloc(MAX_PATH * sizeof(wchar_t));
diff --git a/protocols/Skype/src/skype_profile.cpp b/protocols/Skype/src/skype_profile.cpp index 699f667491..faf8e27e08 100644 --- a/protocols/Skype/src/skype_profile.cpp +++ b/protocols/Skype/src/skype_profile.cpp @@ -25,8 +25,7 @@ void CSkypeProto::UpdateProfileAvatar(SEObject *obj, HANDLE hContact) if (hContact)
{
- PROTO_AVATAR_INFORMATIONW pai = {0};
- pai.cbSize = sizeof(pai);
+ PROTO_AVATAR_INFORMATIONW pai = { sizeof(pai) };
pai.format = PA_FORMAT_JPEG;
pai.hContact = hContact;
::wcscpy(pai.filename, path);
diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index 432ca34dc7..20ae6437e0 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -283,9 +283,6 @@ protected: // avatars
bool IsAvatarChanged(const SEBinary &avatar, HANDLE hContact = NULL);
- static int DetectAvatarFormatBuffer(const char *pBuffer);
- static int DetectAvatarFormat(const wchar_t *path);
-
wchar_t* GetContactAvatarFilePath(HANDLE hContact);
INT_PTR __cdecl GetAvatarInfo(WPARAM, LPARAM);
diff --git a/protocols/Tlen/src/jabber.h b/protocols/Tlen/src/jabber.h index c62d1110e5..deab57ac51 100644 --- a/protocols/Tlen/src/jabber.h +++ b/protocols/Tlen/src/jabber.h @@ -464,7 +464,6 @@ char *JabberTextEncode(const char *str); char *JabberTextDecode(const char *str);
char *JabberBase64Encode(const char *buffer, int bufferLen);
char *JabberBase64Decode(const char *buffer, int *resultLen);
-int JabberGetPictureType(const char* buf);
void TlenLogMessage(TlenProtocol *proto, HANDLE hContact, DWORD flags, const char *message);
BOOL IsAuthorized(TlenProtocol *proto, const char *jid);
//char *JabberGetVersionText();
diff --git a/protocols/Tlen/src/jabber_util.cpp b/protocols/Tlen/src/jabber_util.cpp index 00ce04e579..0fe8d0b10d 100644 --- a/protocols/Tlen/src/jabber_util.cpp +++ b/protocols/Tlen/src/jabber_util.cpp @@ -615,17 +615,6 @@ void JabberStringAppend(char **str, int *sizeAlloced, const char *fmt, ...) va_end(vararg);
}
-int JabberGetPictureType( const char* buf )
-{
- if ( buf != NULL ) {
- if ( memcmp( buf, "GIF89", 5 ) == 0 ) return PA_FORMAT_GIF;
- if ( memcmp( buf, "\x89PNG", 4 ) == 0 ) return PA_FORMAT_PNG;
- if ( memcmp( buf, "BM", 2 ) == 0 ) return PA_FORMAT_BMP;
- if ( memcmp( buf, "\xFF\xD8", 2 ) == 0 ) return PA_FORMAT_JPEG;
- }
- return PA_FORMAT_UNKNOWN;
-}
-
BOOL IsAuthorized(TlenProtocol *proto, const char *jid)
{
JABBER_LIST_ITEM *item = JabberListGetItemPtr(proto, LIST_ROSTER, jid);
diff --git a/protocols/Tlen/src/jabber_ws.cpp b/protocols/Tlen/src/jabber_ws.cpp index c2cb853b02..b1cb066d7a 100644 --- a/protocols/Tlen/src/jabber_ws.cpp +++ b/protocols/Tlen/src/jabber_ws.cpp @@ -32,13 +32,13 @@ BOOL JabberWsInit(TlenProtocol *proto) nlu.cbSize = sizeof(nlu);
nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_TCHAR; // | NUF_HTTPGATEWAY;
- mir_sntprintf( name, SIZEOF(name), TranslateT("%s connection"), proto->m_tszUserName);
+ mir_sntprintf(name, SIZEOF(name), TranslateT("%s connection"), proto->m_tszUserName);
nlu.ptszDescriptiveName = name;
nlu.szSettingsModule = proto->m_szModuleName;
proto->hNetlibUser = (HANDLE) CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM) &nlu);
nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_NOOPTIONS | NUF_TCHAR;
- mir_sntprintf( name, SIZEOF(name), TranslateT("%s SOCKS connection"), proto->m_tszUserName);
+ mir_sntprintf(name, SIZEOF(name), TranslateT("%s SOCKS connection"), proto->m_tszUserName);
nlu.ptszDescriptiveName = name;
proto->hFileNetlibUser = (HANDLE) CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM) &nlu);
nlus.cbSize = sizeof(nlus);
diff --git a/protocols/Tlen/src/tlen_avatar.cpp b/protocols/Tlen/src/tlen_avatar.cpp index 1df8c8836d..28f3953061 100644 --- a/protocols/Tlen/src/tlen_avatar.cpp +++ b/protocols/Tlen/src/tlen_avatar.cpp @@ -33,45 +33,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void TlenGetAvatarFileName(TlenProtocol *proto, JABBER_LIST_ITEM *item, TCHAR* ptszDest, int cbLen)
{
- DWORD dwAttributes;
- int tPathLen;
int format = PA_FORMAT_PNG;
- TCHAR* tszFileType;
TCHAR* tmpPath = Utils_ReplaceVarsT( TEXT("%miranda_avatarcache%") );
- tPathLen = mir_sntprintf( ptszDest, cbLen, TEXT("%s\\Tlen"), tmpPath );
+ int tPathLen = mir_sntprintf(ptszDest, cbLen, TEXT("%s\\Tlen"), tmpPath );
mir_free(tmpPath);
- dwAttributes = GetFileAttributes( ptszDest );
+ DWORD dwAttributes = GetFileAttributes( ptszDest );
if (dwAttributes == 0xffffffff || ( dwAttributes & FILE_ATTRIBUTE_DIRECTORY ) == 0)
CreateDirectoryTreeT(ptszDest);
ptszDest[ tPathLen++ ] = '\\';
- if (item != NULL) {
+ if (item != NULL)
format = item->avatarFormat;
- } else if (proto->threadData != NULL) {
+ else if (proto->threadData != NULL)
format = proto->threadData->avatarFormat;
- } else {
+ else
format = db_get_dw(NULL, proto->m_szModuleName, "AvatarFormat", PA_FORMAT_UNKNOWN);
- }
- tszFileType = TEXT("png");
- switch(format) {
- case PA_FORMAT_JPEG: tszFileType = TEXT("jpg"); break;
- case PA_FORMAT_ICON: tszFileType = TEXT("ico"); break;
- case PA_FORMAT_PNG: tszFileType = TEXT("png"); break;
- case PA_FORMAT_GIF: tszFileType = TEXT("gif"); break;
- case PA_FORMAT_BMP: tszFileType = TEXT("bmp"); break;
- }
- if ( item != NULL ) {
- char* hash;
- hash = JabberSha1(item->jid);
- TCHAR* hashT = mir_a2t(hash);
- mir_free( hash );
- mir_sntprintf( ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%s.%s"), hashT, tszFileType );
- mir_free( hashT );
- } else {
- TCHAR* m_tszModuleName = mir_a2t(proto->m_szModuleName);
- mir_sntprintf( ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%s_avatar.%s"), m_tszModuleName, tszFileType );
- mir_free( m_tszModuleName );
- }
+
+ const TCHAR *tszFileType = ProtoGetAvatarExtension(format);
+ if ( item != NULL )
+ mir_sntprintf(ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%S%s"), ptrA( JabberSha1(item->jid)), tszFileType);
+ else
+ mir_sntprintf(ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%S_avatar%s"), proto->m_szModuleName, tszFileType);
}
static void RemoveAvatar(TlenProtocol *proto, HANDLE hContact) {
@@ -88,15 +70,13 @@ static void RemoveAvatar(TlenProtocol *proto, HANDLE hContact) { }
static void SetAvatar(TlenProtocol *proto, HANDLE hContact, JABBER_LIST_ITEM *item, char *data, int len, DWORD format) {
- FILE* out;
TCHAR filename[MAX_PATH];
char md5[33];
mir_md5_state_t ctx;
DWORD digest[4];
- if (format == PA_FORMAT_UNKNOWN && len > 4) {
- format = JabberGetPictureType(data);
- }
+ if (format == PA_FORMAT_UNKNOWN && len > 4)
+ format = ProtoGetBufferFormat(data);
mir_md5_init( &ctx );
mir_md5_append( &ctx, ( BYTE* )data, len);
@@ -114,10 +94,10 @@ static void SetAvatar(TlenProtocol *proto, HANDLE hContact, JABBER_LIST_ITEM *it }
TlenGetAvatarFileName(proto, item, filename, sizeof filename );
DeleteFile(filename);
- out = _tfopen( filename, TEXT("wb") );
- if ( out != NULL ) {
- fwrite( data, len, 1, out );
- fclose( out );
+ FILE *out = _tfopen( filename, TEXT("wb") );
+ if (out != NULL) {
+ fwrite(data, len, 1, out);
+ fclose(out);
db_set_ts(hContact, "ContactPhoto", "File", filename );
db_set_s(hContact, proto->m_szModuleName, "AvatarHash", md5);
db_set_dw(hContact, proto->m_szModuleName, "AvatarFormat", format);
@@ -274,20 +254,20 @@ static void TlenGetAvatarThread(void *ptr) { if (resp->dataLength > 0) {
int i;
for (i=0; i<resp->headersCount; i++ ) {
- if (strcmpi(resp->headers[i].szName, "Content-Type") == 0) {
- if (strcmpi(resp->headers[i].szValue, "image/png") == 0) {
+ if (!strcmpi(resp->headers[i].szName, "Content-Type")) {
+ if (!strcmpi(resp->headers[i].szValue, "image/png"))
format = PA_FORMAT_PNG;
- } else if (strcmpi(resp->headers[i].szValue, "image/x-png") == 0) {
+ else if (!strcmpi(resp->headers[i].szValue, "image/x-png"))
format = PA_FORMAT_PNG;
- } else if (strcmpi(resp->headers[i].szValue, "image/jpeg") == 0) {
+ else if (!strcmpi(resp->headers[i].szValue, "image/jpeg"))
format = PA_FORMAT_JPEG;
- } else if (strcmpi(resp->headers[i].szValue, "image/jpg") == 0) {
+ else if (!strcmpi(resp->headers[i].szValue, "image/jpg"))
format = PA_FORMAT_JPEG;
- } else if (strcmpi(resp->headers[i].szValue, "image/gif") == 0) {
+ else if (!strcmpi(resp->headers[i].szValue, "image/gif"))
format = PA_FORMAT_GIF;
- } else if (strcmpi(resp->headers[i].szValue, "image/bmp") == 0) {
+ else if (!strcmpi(resp->headers[i].szValue, "image/bmp"))
format = PA_FORMAT_BMP;
- }
+
break;
}
}
diff --git a/protocols/Twitter/src/connection.cpp b/protocols/Twitter/src/connection.cpp index d9a7dc704b..bf51ca0687 100644 --- a/protocols/Twitter/src/connection.cpp +++ b/protocols/Twitter/src/connection.cpp @@ -426,7 +426,7 @@ void TwitterProto::UpdateAvatarWorker(void *p) PROTO_AVATAR_INFORMATIONT ai = {sizeof(ai)};
ai.hContact = data->hContact;
- ai.format = ext_to_format(ext);
+ ai.format = ProtoGetAvatarFormat(filename.c_str());
if (ai.format == PA_FORMAT_UNKNOWN) {
LOG( _T("***** Update avatar: Terminated for this contact, extension format unknown for %s"), data->url.c_str());
diff --git a/protocols/Twitter/src/utility.cpp b/protocols/Twitter/src/utility.cpp index 219b8e1ec4..2a245455be 100644 --- a/protocols/Twitter/src/utility.cpp +++ b/protocols/Twitter/src/utility.cpp @@ -195,27 +195,3 @@ bool save_url(HANDLE hNetlib,const std::string &url,const std::tstring &filename else
return false;
}
-
-static const struct
-{
- char *ext;
- int fmt;
-} formats[] = {
- { ".png", PA_FORMAT_PNG },
- { ".jpg", PA_FORMAT_JPEG },
- { ".jpeg", PA_FORMAT_JPEG },
- { ".ico", PA_FORMAT_ICON },
- { ".bmp", PA_FORMAT_BMP },
- { ".gif", PA_FORMAT_GIF },
-};
-
-int ext_to_format(const std::string &ext)
-{
- for(size_t i=0; i<SIZEOF(formats); i++)
- {
- if(ext == formats[i].ext)
- return formats[i].fmt;
- }
-
- return PA_FORMAT_UNKNOWN;
-}
\ No newline at end of file diff --git a/protocols/Twitter/src/utility.h b/protocols/Twitter/src/utility.h index 17aa1cb649..c8f862e247 100644 --- a/protocols/Twitter/src/utility.h +++ b/protocols/Twitter/src/utility.h @@ -125,5 +125,4 @@ private: HANDLE handle_;
};
-int ext_to_format(const std::string &ext);
bool save_url(HANDLE hNetlib,const std::string &url,const std::tstring &filename);
\ No newline at end of file |