diff options
Diffstat (limited to 'protocols/IcqOscarJ')
-rw-r--r-- | protocols/IcqOscarJ/src/icq_avatar.cpp | 64 | ||||
-rw-r--r-- | protocols/IcqOscarJ/src/icq_avatar.h | 2 | ||||
-rw-r--r-- | protocols/IcqOscarJ/src/icqosc_svcs.cpp | 58 |
3 files changed, 31 insertions, 93 deletions
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
|