summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-11-28 13:44:22 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-11-28 13:44:22 +0300
commitfc7d7e43522b9c9dcbd27bc193baf566f89deb5b (patch)
tree6df52d29502ac253f8a33c81a3f9ca43ba9d6274
parentfe20601717b055126333f54512964edbe1d43c46 (diff)
fixes #3973 (Jabber: файлы, пришедшие по HTTP File Upload, имеют размер 0)
-rw-r--r--protocols/JabberG/src/jabber_file.cpp49
-rw-r--r--protocols/JabberG/src/jabber_proto.h5
-rw-r--r--protocols/JabberG/src/jabber_thread.cpp31
3 files changed, 53 insertions, 32 deletions
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<CJabberProto>, 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");