diff options
author | George Hazan <ghazan@miranda.im> | 2017-02-03 16:08:38 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-02-03 16:08:38 +0300 |
commit | 1ef4b90ce07ccc4e372f0b8179c69438bff24ae2 (patch) | |
tree | eb9cda4038333ff654e4da664325569d493c9648 /protocols | |
parent | ceb375ad7f99c4169ffb3041037583996122fa57 (diff) |
mime type standardization
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/JabberG/src/jabber_iq_handlers.cpp | 11 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_iqid.cpp | 19 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_util.cpp | 14 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_vcard.cpp | 10 | ||||
-rw-r--r-- | protocols/MRA/src/MraAvatars.cpp | 23 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_avatar.cpp | 17 |
6 files changed, 18 insertions, 76 deletions
diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index 924b335afc..e532340acc 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -151,14 +151,9 @@ BOOL CJabberProto::OnIqRequestAvatar(HXML, CJabberIqInfo *pInfo) if (pictureType == PA_FORMAT_UNKNOWN)
return TRUE;
- wchar_t *szMimeType;
- switch (pictureType) {
- case PA_FORMAT_JPEG: szMimeType = L"image/jpeg"; break;
- case PA_FORMAT_GIF: szMimeType = L"image/gif"; break;
- case PA_FORMAT_PNG: szMimeType = L"image/png"; break;
- case PA_FORMAT_BMP: szMimeType = L"image/bmp"; break;
- default: return TRUE;
- }
+ const wchar_t *szMimeType = ProtoGetAvatarMimeType(pictureType);
+ if (szMimeType == NULL)
+ return TRUE;
wchar_t szFileName[MAX_PATH];
GetAvatarFileName(NULL, szFileName, _countof(szFileName));
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index a91cd1d3d4..df2fd4cf42 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -1405,19 +1405,14 @@ void CJabberProto::OnIqResultGotAvatar(MCONTACT hContact, HXML n, const wchar_t return;
int pictureType;
- if (mimeType != NULL) {
- if (!mir_wstrcmp(mimeType, L"image/jpeg")) pictureType = PA_FORMAT_JPEG;
- else if (!mir_wstrcmp(mimeType, L"image/png")) pictureType = PA_FORMAT_PNG;
- else if (!mir_wstrcmp(mimeType, L"image/gif")) pictureType = PA_FORMAT_GIF;
- else if (!mir_wstrcmp(mimeType, L"image/bmp")) pictureType = PA_FORMAT_BMP;
- else {
-LBL_ErrFormat:
- debugLogW(L"Invalid mime type specified for picture: %s", mimeType);
- return;
- }
+ if (mimeType != NULL)
+ pictureType = ProtoGetAvatarFormatByMimeType(mimeType);
+ else
+ pictureType = ProtoGetBufferFormat(body, 0);
+ if (pictureType == PA_FORMAT_UNKNOWN) {
+ debugLogW(L"Invalid mime type specified for picture: %s", mimeType);
+ return;
}
- else if ((pictureType = ProtoGetBufferFormat(body, 0)) == PA_FORMAT_UNKNOWN)
- goto LBL_ErrFormat;
PROTO_AVATAR_INFORMATION ai;
ai.format = pictureType;
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index c1fb18a4e2..19de86f090 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -587,20 +587,10 @@ wchar_t* __stdcall JabberStripJid(const wchar_t *jid, wchar_t *dest, size_t dest LPCTSTR __stdcall JabberGetPictureType(HXML node, const char *picBuf)
{
if (LPCTSTR ptszType = XmlGetText(XmlGetChild(node, "TYPE")))
- if (!mir_wstrcmp(ptszType, L"image/jpeg") ||
- !mir_wstrcmp(ptszType, L"image/png") ||
- !mir_wstrcmp(ptszType, L"image/gif") ||
- !mir_wstrcmp(ptszType, L"image/bmp"))
+ if (ProtoGetAvatarFormatByMimeType(ptszType) != PA_FORMAT_UNKNOWN)
return ptszType;
- switch (ProtoGetBufferFormat(picBuf)) {
- case PA_FORMAT_GIF: return L"image/gif";
- case PA_FORMAT_BMP: return L"image/bmp";
- case PA_FORMAT_PNG: return L"image/png";
- case PA_FORMAT_JPEG: return L"image/jpeg";
- }
-
- return NULL;
+ return ProtoGetAvatarMimeType(ProtoGetBufferFormat(picBuf));
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/JabberG/src/jabber_vcard.cpp b/protocols/JabberG/src/jabber_vcard.cpp index 2150161afd..16e57c3817 100644 --- a/protocols/JabberG/src/jabber_vcard.cpp +++ b/protocols/JabberG/src/jabber_vcard.cpp @@ -1132,15 +1132,9 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, wchar_t* szPhotoFileName) DWORD nRead;
if (ReadFile(hFile, buffer, st.st_size, &nRead, NULL)) {
ptrA str(mir_base64_encode((PBYTE)(LPSTR)buffer, nRead));
- if (str != NULL) {
+ const wchar_t *szFileType = ProtoGetAvatarMimeType(ProtoGetBufferFormat(buffer));
+ if (str != NULL && szFileType != NULL) {
n = v << XCHILD(L"PHOTO");
- wchar_t *szFileType;
- switch (ProtoGetBufferFormat(buffer)) {
- case PA_FORMAT_PNG: szFileType = L"image/png"; break;
- case PA_FORMAT_GIF: szFileType = L"image/gif"; break;
- case PA_FORMAT_BMP: szFileType = L"image/bmp"; break;
- default: szFileType = L"image/jpeg"; break;
- }
n << XCHILD(L"TYPE", szFileType);
n << XCHILD(L"BINVAL", _A2T(str));
diff --git a/protocols/MRA/src/MraAvatars.cpp b/protocols/MRA/src/MraAvatars.cpp index 7c80a1230a..a61094c670 100644 --- a/protocols/MRA/src/MraAvatars.cpp +++ b/protocols/MRA/src/MraAvatars.cpp @@ -3,19 +3,6 @@ #define PA_FORMAT_MAX 7
-const LPSTR lpcszContentType[9] =
-{
- "", // PA_FORMAT_UNKNOWN
- "image/png", // PA_FORMAT_PNG
- "image/jpeg", // PA_FORMAT_JPEG
- "image/icon", // PA_FORMAT_ICON
- "image/x-xbitmap", // PA_FORMAT_BMP
- "image/gif", // PA_FORMAT_GIF
- "", // PA_FORMAT_SWF
- "", // PA_FORMAT_XML
- NULL
-};
-
struct MRA_AVATARS_QUEUE : public FIFO_MT
{
HNETLIBUSER hNetlibUser;
@@ -405,14 +392,8 @@ DWORD MraAvatarsHttpTransaction(HNETLIBCONN hConnection, DWORD dwRequestType, LP *pbKeepAlive = !_strnicmp(pnlhr->headers[i].szValue, "keep-alive", 10);
}
else if (!_strnicmp(pnlhr->headers[i].szName, "Content-Type", 12)) {
- if (pdwFormat) {
- for (DWORD j = 0; j < PA_FORMAT_MAX; j++) {
- if (!_stricmp(pnlhr->headers[i].szValue, lpcszContentType[j])) {
- *pdwFormat = j;
- break;
- }
- }
- }
+ if (pdwFormat)
+ *pdwFormat = ProtoGetAvatarFormatByMimeType(_A2T(pnlhr->headers[i].szValue));
}
else if (!_strnicmp(pnlhr->headers[i].szName, "Content-Length", 14)) {
if (pdwAvatarSize)
diff --git a/protocols/Tlen/src/tlen_avatar.cpp b/protocols/Tlen/src/tlen_avatar.cpp index bd9c031b3a..3689a8bb75 100644 --- a/protocols/Tlen/src/tlen_avatar.cpp +++ b/protocols/Tlen/src/tlen_avatar.cpp @@ -274,22 +274,9 @@ static void TlenGetAvatarThread(void *ptr) if (resp != NULL) { if (resp->resultCode/100 == 2) { if (resp->dataLength > 0) { - int i; - for (i=0; i<resp->headersCount; i++ ) { + for (int i=0; i<resp->headersCount; i++ ) { 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")) - format = PA_FORMAT_PNG; - else if (!strcmpi(resp->headers[i].szValue, "image/jpeg")) - format = PA_FORMAT_JPEG; - else if (!strcmpi(resp->headers[i].szValue, "image/jpg")) - format = PA_FORMAT_JPEG; - else if (!strcmpi(resp->headers[i].szValue, "image/gif")) - format = PA_FORMAT_GIF; - else if (!strcmpi(resp->headers[i].szValue, "image/bmp")) - format = PA_FORMAT_BMP; - + format = ProtoGetAvatarFormatByMimeType(_A2T(resp->headers[i].szValue)); break; } } |