summaryrefslogtreecommitdiff
path: root/protocols/Icq10/src/utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-12-29 22:19:43 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-12-29 22:19:43 +0300
commitad3174415c91079ff97c73de835aa81573724343 (patch)
tree5f49f630229b1381fa4e1ca7d025171304e2465e /protocols/Icq10/src/utils.cpp
parent8b5aedc9a9697f4138017fd0ecb40b5a6fcbc279 (diff)
fixes #1686 (ICQ10: implement own avatar changing)
Diffstat (limited to 'protocols/Icq10/src/utils.cpp')
-rw-r--r--protocols/Icq10/src/utils.cpp47
1 files changed, 45 insertions, 2 deletions
diff --git a/protocols/Icq10/src/utils.cpp b/protocols/Icq10/src/utils.cpp
index d3364dd58c..49c9ad0d03 100644
--- a/protocols/Icq10/src/utils.cpp
+++ b/protocols/Icq10/src/utils.cpp
@@ -137,9 +137,52 @@ INT_PTR __cdecl CIcqProto::GetAvatarInfo(WPARAM, LPARAM lParam)
return GAIR_NOAVATAR;
}
-INT_PTR __cdecl CIcqProto::SetAvatar(WPARAM, LPARAM)
+INT_PTR __cdecl CIcqProto::SetAvatar(WPARAM, LPARAM lParam)
{
- return 1; // TODO
+ wchar_t* pwszFileName = (wchar_t*)lParam;
+
+ wchar_t wszOldName[MAX_PATH];
+ GetAvatarFileName(0, wszOldName, _countof(wszOldName));
+ _wremove(wszOldName);
+
+ auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_POST, ICQ_API_SERVER "/expressions/upload");
+ pReq->m_szUrl.AppendFormat("?f=json&aimsid=%s&r=%s&type=largeBuddyIcon", ptrA(mir_urlEncode(m_aimsid.c_str())), pReq->m_reqId);
+
+ if (pwszFileName == nullptr)
+ delSetting("AvatarHash");
+ else {
+ int fileId = _wopen(pwszFileName, _O_RDONLY | _O_BINARY, _S_IREAD);
+ if (fileId < 0) {
+ delete pReq;
+ return 1;
+ }
+
+ unsigned dwSize = (unsigned)_filelengthi64(fileId);
+ char* pData = (char*)mir_alloc(dwSize);
+ if (pData == nullptr) {
+ _close(fileId);
+ delete pReq;
+ return 2;
+ }
+
+ _read(fileId, pData, dwSize);
+ _close(fileId);
+
+ pReq->pData = pData;
+ pReq->dataLength = dwSize;
+
+ int iAvatarType = ProtoGetBufferFormat(pData);
+ if (iAvatarType == PA_FORMAT_UNKNOWN) {
+ delete pReq;
+ delete pData;
+ return 3;
+ }
+
+ pReq->AddHeader("Content-Type", _T2A(ProtoGetAvatarMimeType(iAvatarType)));
+ }
+ Push(pReq);
+
+ return 0; // TODO
}
/////////////////////////////////////////////////////////////////////////////////////////