diff options
author | George Hazan <ghazan@miranda.im> | 2020-01-13 16:48:55 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-01-13 16:48:55 +0300 |
commit | 87a2660299edd64cbb6f6c92c33683e91a6d187c (patch) | |
tree | a1b0777ec5b8afc0c49fbb66cf6a122b5ac82c6d /protocols/ICQ-WIM/src | |
parent | 21f52dbfa251d171b4cc9dc315e8736da2e2be08 (diff) |
Netlib_GetHeader() - handful utility to avoid writing cycles
Diffstat (limited to 'protocols/ICQ-WIM/src')
-rw-r--r-- | protocols/ICQ-WIM/src/http.cpp | 11 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/server.cpp | 17 |
2 files changed, 12 insertions, 16 deletions
diff --git a/protocols/ICQ-WIM/src/http.cpp b/protocols/ICQ-WIM/src/http.cpp index 4826a411c6..b41a45404b 100644 --- a/protocols/ICQ-WIM/src/http.cpp +++ b/protocols/ICQ-WIM/src/http.cpp @@ -179,13 +179,10 @@ bool CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq) auto &conn = m_ConnPool[pReq->m_conn]; conn.s = reply->nlc; conn.timeout = 0; - for (int i = 0; i < reply->headersCount; i++) { - if (!mir_strcmp(reply->headers[i].szName, "Keep-Alive")) { - int timeout; - if (1 == sscanf(reply->headers[i].szValue, "timeout=%d", &timeout)) - conn.timeout = timeout; - break; - } + if (auto *pszHdr = Netlib_GetHeader(reply, "Keep-Alive")) { + int timeout; + if (1 == sscanf(pszHdr, "timeout=%d", &timeout)) + conn.timeout = timeout; } } diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp index 4bf8ab7385..0e95605bdd 100644 --- a/protocols/ICQ-WIM/src/server.cpp +++ b/protocols/ICQ-WIM/src/server.cpp @@ -38,17 +38,13 @@ void CIcqProto::CheckAvatarChange(MCONTACT hContact, const JSONNode &ev) } setWString(hContact, "IconId", wszIconId); - } - else delSetting(hContact, "IconId"); - CMStringA szUrl(ev["bigBuddyIcon"].as_mstring()); - if (szUrl.IsEmpty()) - szUrl = ev["buddyIcon"].as_mstring(); - if (!szUrl.IsEmpty()) { - auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, szUrl, &CIcqProto::OnReceiveAvatar); + auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/expressions/get", &CIcqProto::OnReceiveAvatar); + pReq << CHAR_PARAM("f", "native") << WCHAR_PARAM("t", GetUserId(hContact)) << CHAR_PARAM("type", "bigBuddyIcon"); pReq->hContact = hContact; Push(pReq); } + else delSetting(hContact, "IconId"); } void CIcqProto::CheckLastId(MCONTACT hContact, const JSONNode &ev) @@ -889,8 +885,11 @@ LBL_Error: return; } - const wchar_t *pwszExtension; - ai.format = ProtoGetBufferFormat(pReply->pData, &pwszExtension); + const char *szContentType = Netlib_GetHeader(pReply, "Content-Type"); + if (szContentType == nullptr) + szContentType = "image/jpeg"; + + ai.format = ProtoGetAvatarFormatByMimeType(szContentType); setByte(pReq->hContact, "AvatarType", ai.format); GetAvatarFileName(pReq->hContact, ai.filename, _countof(ai.filename)); |