From e22532dbddb956abd18e7cae5adb3d3cbb209578 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 11 Feb 2019 14:55:27 +0300 Subject: ICQ-WIM: - support for file description in file transfers; - fix for passing file chunks for large files; - added reaction to http error code 206 (partial success); - version bump --- protocols/ICQ-WIM/src/proto.cpp | 6 ++++-- protocols/ICQ-WIM/src/proto.h | 2 +- protocols/ICQ-WIM/src/server.cpp | 34 ++++++++++++++++++++++++++++++++-- protocols/ICQ-WIM/src/version.h | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) (limited to 'protocols/ICQ-WIM') diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp index 8ad2ba6d12..44e9a6a650 100644 --- a/protocols/ICQ-WIM/src/proto.cpp +++ b/protocols/ICQ-WIM/src/proto.cpp @@ -378,7 +378,7 @@ HANDLE CIcqProto::SearchBasic(const wchar_t *pszSearch) //////////////////////////////////////////////////////////////////////////////////////// // SendFile - sends a file -HANDLE CIcqProto::SendFile(MCONTACT hContact, const wchar_t*, wchar_t **ppszFiles) +HANDLE CIcqProto::SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) { // we can't send more than one file at a time if (ppszFiles[1] != 0) @@ -398,9 +398,11 @@ HANDLE CIcqProto::SendFile(MCONTACT hContact, const wchar_t*, wchar_t **ppszFile pTransfer->pfts.totalFiles = 1; pTransfer->pfts.currentFileSize = pTransfer->pfts.totalBytes = statbuf.st_size; pTransfer->m_fileId = iFileId; + if (mir_wstrlen(szDescription)) + pTransfer->m_wszDescr = szDescription; auto *pReq = new AsyncHttpRequest(CONN_NONE, REQUEST_GET, "https://files.icq.com/files/init", &CIcqProto::OnFileInit); - pReq << CHAR_PARAM("a", m_szAToken) << CHAR_PARAM("client", "icq") << CHAR_PARAM("f", "json") << CHAR_PARAM("fileName", mir_urlEncode(T2Utf(pTransfer->m_wszShortName))) + pReq << CHAR_PARAM("a", m_szAToken) << CHAR_PARAM("client", "icq") << CHAR_PARAM("f", "json") << CHAR_PARAM("filename", mir_urlEncode(T2Utf(pTransfer->m_wszShortName))) << CHAR_PARAM("k", ICQ_APP_ID) << INT_PARAM("size", statbuf.st_size) << INT_PARAM("ts", time(0)); CalcHash(pReq); pReq->pUserInfo = pTransfer; diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h index 325c745a32..253bc15927 100644 --- a/protocols/ICQ-WIM/src/proto.h +++ b/protocols/ICQ-WIM/src/proto.h @@ -113,7 +113,7 @@ struct IcqFileTransfer : public MZeroedObject int m_fileId = -1; CMStringA m_szHost; - CMStringW m_wszFileName; + CMStringW m_wszFileName, m_wszDescr; const wchar_t *m_wszShortName; PROTOFILETRANSFERSTATUS pfts; diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp index 920e826f78..692eb1f511 100644 --- a/protocols/ICQ-WIM/src/server.cpp +++ b/protocols/ICQ-WIM/src/server.cpp @@ -631,7 +631,12 @@ void CIcqProto::OnFileContinue(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pOld { IcqFileTransfer *pTransfer = (IcqFileTransfer*)pOld->pUserInfo; - if (pReply->resultCode != 200) { + switch (pReply->resultCode) { + case 200: // final ok + case 206: // partial ok + break; + + default: ProtoBroadcastAck(pTransfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, pTransfer); delete pTransfer; return; @@ -645,7 +650,29 @@ void CIcqProto::OnFileContinue(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pOld const JSONNode &data = root.data(); CMStringW wszUrl(data["static_url"].as_mstring()); - SendMsg(pTransfer->pfts.hContact, 0, _T2A(wszUrl)); + + JSONNode bundle, contents; contents.set_name("captionedContent"); + contents << WCHAR_PARAM("caption", pTransfer->m_wszDescr) << WCHAR_PARAM("url", wszUrl); + bundle << CHAR_PARAM("mediaType", "text") << CHAR_PARAM("text", "") << contents; + CMStringW wszParts(FORMAT, L"[%s]", ptrW(json_write(&bundle))); + + if (!pTransfer->m_wszDescr.IsEmpty()) + wszUrl += L" " + pTransfer->m_wszDescr; + + int id = InterlockedIncrement(&m_msgId); + auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_POST, ICQ_API_SERVER "/im/sendIM", &CIcqProto::OnSendMessage); + + auto *pOwn = new IcqOwnMessage(pTransfer->pfts.hContact, id, pReq->m_reqId); + pReq->pUserInfo = pOwn; + { + mir_cslock lck(m_csOwnIds); + m_arOwnIds.insert(pOwn); + } + + pReq << CHAR_PARAM("a", m_szAToken) << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("f", "json") << CHAR_PARAM("k", ICQ_APP_ID) + << CHAR_PARAM("mentions", "") << WCHAR_PARAM("message", wszUrl) << CHAR_PARAM("offlineIM", "true") << WCHAR_PARAM("parts", wszParts) + << CHAR_PARAM("r", pReq->m_reqId) << WCHAR_PARAM("t", GetUserId(pTransfer->pfts.hContact)) << INT_PARAM("ts", time(0)); + Push(pReq); } else ProtoBroadcastAck(pTransfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, pTransfer); delete pTransfer; @@ -656,6 +683,9 @@ void CIcqProto::OnFileContinue(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pOld auto *pReq = new AsyncHttpRequest(CONN_NONE, REQUEST_POST, pTransfer->m_szHost, &CIcqProto::OnFileContinue); pReq << CHAR_PARAM("a", m_szAToken) << CHAR_PARAM("client", "icq") << CHAR_PARAM("k", ICQ_APP_ID) << INT_PARAM("ts", time(0)); CalcHash(pReq); + pReq->m_szUrl.AppendChar('?'); + pReq->m_szUrl += pReq->m_szParam; pReq->m_szParam.Empty(); + pReq->pUserInfo = pTransfer; pTransfer->FillHeaders(pReq); Push(pReq); diff --git a/protocols/ICQ-WIM/src/version.h b/protocols/ICQ-WIM/src/version.h index 5b655a7047..f023323c28 100644 --- a/protocols/ICQ-WIM/src/version.h +++ b/protocols/ICQ-WIM/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 95 #define __RELEASE_NUM 11 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include -- cgit v1.2.3