From ec0297e13b1a994384254abc87d3ed9f42edcf99 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Sat, 10 Oct 2015 17:02:14 +0000 Subject: SkypeWeb: correct mimetype in avatar request git-svn-id: http://svn.miranda-ng.org/main/trunk@15530 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/http_request.h | 2 - protocols/SkypeWeb/src/requests/avatars.h | 8 ++-- protocols/SkypeWeb/src/skype_avatars.cpp | 63 +++++++++++++++---------------- 3 files changed, 34 insertions(+), 39 deletions(-) diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h index 90d552358c..4fc62c02b7 100644 --- a/protocols/SkypeWeb/src/http_request.h +++ b/protocols/SkypeWeb/src/http_request.h @@ -240,7 +240,6 @@ public: cbSize = sizeof(NETLIBHTTPREQUEST); flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_DUMPASTEXT; requestType = type; - pData = NULL; } HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...) @@ -250,7 +249,6 @@ public: flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_DUMPASTEXT; requestType = type; va_end(formatArgs); - pData = NULL; } ~HttpRequest() diff --git a/protocols/SkypeWeb/src/requests/avatars.h b/protocols/SkypeWeb/src/requests/avatars.h index 23be77bee1..438fef9eac 100644 --- a/protocols/SkypeWeb/src/requests/avatars.h +++ b/protocols/SkypeWeb/src/requests/avatars.h @@ -30,12 +30,12 @@ public: class SetAvatarRequest : public HttpRequest { public: - SetAvatarRequest(const char *data, size_t dataSize, LoginInfo &li) : - HttpRequest(REQUEST_PUT, FORMAT, "api.skype.com/users/%s/profile/avatar", li.szSkypename) + SetAvatarRequest(const PBYTE data, size_t dataSize, const char *szMime, LoginInfo &li) : + HttpRequest(REQUEST_PUT, FORMAT, "api.skype.com/users/%s/profile/avatar", CMStringA(li.szSkypename).MakeLower()) { Headers << CHAR_VALUE("X-Skypetoken", li.api.szToken) - << CHAR_VALUE("Content-Type", "image/jpeg"); + << CHAR_VALUE("Content-Type", szMime); pData = (char*)mir_alloc(dataSize); memcpy(pData, data, dataSize); @@ -44,8 +44,8 @@ public: ~SetAvatarRequest() { - HttpRequest::~HttpRequest(); mir_free(pData); + HttpRequest::~HttpRequest(); } }; diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp index b306a3d4a0..7622ad09e4 100644 --- a/protocols/SkypeWeb/src/skype_avatars.cpp +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -22,8 +22,8 @@ INT_PTR CSkypeProto::SvcGetAvatarCaps(WPARAM wParam, LPARAM lParam) switch (wParam) { case AF_MAXSIZE: - ((POINT*)lParam)->x = 150; - ((POINT*)lParam)->y = 150; + ((POINT*)lParam)->x = 98; + ((POINT*)lParam)->y = 98; return 0; case AF_MAXFILESIZE: @@ -171,39 +171,36 @@ INT_PTR CSkypeProto::SvcSetMyAvatar(WPARAM, LPARAM lParam) GetAvatarFileName(NULL, avatarPath, _countof(avatarPath)); if (path != NULL) { - if (!CopyFile(path, avatarPath, FALSE)) + if (CopyFile(path, avatarPath, FALSE)) { - debugLogA("CSkypeProto::SetMyAvatar: failed to copy new avatar to avatar cache"); - return -1; + FILE *hFile = _tfopen(path, L"rb"); + if (hFile) + { + fseek(hFile, 0, SEEK_END); + size_t length = ftell(hFile); + if (length != -1) + { + rewind(hFile); + + mir_ptr data((PBYTE)mir_alloc(length)); + + if (data != NULL && fread(data, sizeof(BYTE), length, hFile) == length) + { + FI_INTERFACE *fii = NULL; + const char *szMime = "image/jpeg"; + if (CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fii) == S_OK && fii) + { + szMime = fii->FI_GetFIFMimeType(fii->FI_GetFIFFromFilenameU(path)); + } + + PushRequest(new SetAvatarRequest(data, length, szMime, li), &CSkypeProto::OnSentAvatar); + return 0; + } + } + fclose(hFile); + } } - - FILE *hFile = _tfopen(path, L"rb"); - if (!hFile) - { - debugLogA("CSkypeProto::SetMyAvatar: failed to open avatar file"); - return -1; - } - - fseek(hFile, 0, SEEK_END); - size_t length = ftell(hFile); - if (length == -1) - { - debugLogA("CSkypeProto::SvcSetMyAvatar: failed to get avatar file size"); - fclose(hFile); - return -1; - } - rewind(hFile); - - ptrA data((char*)mir_alloc(length)); - - if (data == NULL || fread(data, sizeof(char), length, hFile) != length) - { - debugLogA("CSkypeProto::SvcSetMyAvatar: failed to read avatar file"); - fclose(hFile); - return -1; - } - fclose(hFile); - PushRequest(new SetAvatarRequest(data, length, li), &CSkypeProto::OnSentAvatar); + return -1; } else { -- cgit v1.2.3