From fc7d7e43522b9c9dcbd27bc193baf566f89deb5b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 28 Nov 2023 13:44:22 +0300 Subject: =?UTF-8?q?fixes=20#3973=20(Jabber:=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D1=8B,=20=D0=BF=D1=80=D0=B8=D1=88=D0=B5=D0=B4=D1=88=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=20HTTP=20File=20Upload,=20=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D1=8E=D1=82=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=200)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/JabberG/src/jabber_file.cpp | 49 +++++++++++++++++++++++++++++++-- protocols/JabberG/src/jabber_proto.h | 5 ++-- protocols/JabberG/src/jabber_thread.cpp | 31 +++------------------ 3 files changed, 53 insertions(+), 32 deletions(-) (limited to 'protocols') diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp index e4fd827a81..b84560dde1 100644 --- a/protocols/JabberG/src/jabber_file.cpp +++ b/protocols/JabberG/src/jabber_file.cpp @@ -113,9 +113,13 @@ INT_PTR __cdecl CJabberProto::OnOfflineFile(WPARAM param, LPARAM) void CJabberProto::OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *pHandle) { - if (auto *ft = (filetransfer *)pHandle) - if (ft->type == FT_HTTP && ft->httpPath) - blob.setUrl(ft->httpPath); + if (auto *ft = (filetransfer *)pHandle) { + if (ft->type == FT_HTTP) { + if (ft->httpPath) + blob.setUrl(ft->httpPath); + blob.setSize(ft->dwExpectedRecvFileSize); + } + } } ///////////////////////////////////////////////////////////////////////////////////////// @@ -143,6 +147,45 @@ void __cdecl CJabberProto::FileReceiveHttpThread(filetransfer *ft) delete ft; } +void CJabberProto::FileProcessHttpDownload(MCONTACT hContact, const char *jid, const char *pszUrl, const char *pszDescr) +{ + // create incoming file transfer instead of writing message + CMStringA szName; + const char *b = strrchr(pszUrl, '/') + 1; + while (*b != 0 && *b != '#' && *b != '?') + szName.AppendChar(*b++); + auto *pszName = szName.c_str(); + + NETLIBHTTPREQUEST req = {}; + req.cbSize = sizeof(req); + req.requestType = REQUEST_HEAD; + req.szUrl = (char*)pszUrl; + + filetransfer *ft = new filetransfer(this, 0); + ft->jid = mir_strdup(jid); + ft->std.hContact = hContact; + ft->type = FT_HTTP; + ft->httpPath = mir_strdup(pszUrl); + ft->std.totalFiles = 1; + ft->std.szCurrentFile.w = mir_utf8decodeW(szName); + + NLHR_PTR pResp(Netlib_HttpTransaction(m_hNetlibUser, &req)); + if (pResp && pResp->resultCode == 200) { + auto *p = (*pResp)["Content-Length"]; + if (p) + ft->dwExpectedRecvFileSize = ft->std.currentFileSize = atoi(p); + } + + PROTORECVFILE pre = {}; + pre.dwFlags = PRFF_UTF | PRFF_SILENT; + pre.fileCount = 1; + pre.timestamp = time(0); + pre.files.a = &pszName; + pre.lParam = (LPARAM)ft; + pre.descr.a = pszDescr; + ProtoChainRecvFile(ft->std.hContact, &pre); +} + ///////////////////////////////////////////////////////////////////////////////////////// void __cdecl CJabberProto::FileReceiveThread(filetransfer *ft) diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index a907cdc65e..c85a2bb988 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -492,11 +492,12 @@ struct CJabberProto : public PROTO, public IJabberInterface //---- jabber_file.cpp --------------------------------------------------------------- + void FileProcessHttpDownload(MCONTACT, const char *jid, const char *pszUrl, const char *pszDescr); int FileReceiveParse(filetransfer *ft, char* buffer, int datalen); int FileSendParse(HNETLIBCONN s, filetransfer *ft, char* buffer, int datalen); - + void GroupchatJoinRoomByJid(HWND hwndParent, char *jid); - + void RenameParticipantNick(JABBER_LIST_ITEM *item, const char *oldNick, const TiXmlElement *itemNode); //---- jabber_ft.c ------------------------------------------------------------------- diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index ae99fb29d2..2efe644ed3 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1324,33 +1324,10 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) } } else if (!mir_strcmp(pszXmlns, JABBER_FEAT_OOB2)) { - if (auto *url = XmlGetChildText(xNode, "url")) { - // create incoming file transfer instead of writing message - CMStringA szName; - const char *b = strrchr(url, '/') + 1; - while (*b != 0 && *b != '#' && *b != '?') - szName.AppendChar(*b++); - auto *pszName = szName.c_str(); - - filetransfer *ft = new filetransfer(this, 0); - ft->jid = mir_strdup(from); - ft->std.hContact = hContact; - ft->type = FT_HTTP; - ft->httpPath = mir_strdup(url); - ft->std.totalFiles = 1; - ft->std.szCurrentFile.w = mir_utf8decodeW(szName); - - PROTORECVFILE pre = {}; - pre.dwFlags = PRFF_UTF | PRFF_SILENT; - pre.fileCount = 1; - pre.timestamp = time(0); - pre.files.a = &pszName; - pre.lParam = (LPARAM)ft; - pre.descr.a = XmlGetChildText(xNode, "desc"); - ProtoChainRecvFile(ft->std.hContact, &pre); - return; - } - else debugLogA("No URL in OOB file transfer, ignoring"); + if (auto *url = XmlGetChildText(xNode, "url")) + FileProcessHttpDownload(hContact, from, url, XmlGetChildText(xNode, "desc")); + else + debugLogA("No URL in OOB file transfer, ignoring"); } else if (!mir_strcmp(pszXmlns, JABBER_FEAT_MUC_USER)) { auto *inviteNode = XmlFirstChild(xNode, "invite"); -- cgit v1.2.3