summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/ICQ-WIM/src/poll.cpp4
-rw-r--r--protocols/ICQ-WIM/src/proto.h10
-rw-r--r--protocols/ICQ-WIM/src/server.cpp49
-rw-r--r--protocols/ICQ-WIM/src/stdafx.h1
4 files changed, 54 insertions, 10 deletions
diff --git a/protocols/ICQ-WIM/src/poll.cpp b/protocols/ICQ-WIM/src/poll.cpp
index 1a7c72b2f0..c46a489017 100644
--- a/protocols/ICQ-WIM/src/poll.cpp
+++ b/protocols/ICQ-WIM/src/poll.cpp
@@ -241,10 +241,10 @@ LBL_SkipPatch:
debugLogA("Proceeding with empty cache for %d", hContact);
for (auto &it : ev["intro"]["messages"])
- ParseMessage(hContact, lastMsgId, it, false, false);
+ ParseMessage(hContact, lastMsgId, it, 0);
for (auto &it : ev["tail"]["messages"])
- ParseMessage(hContact, lastMsgId, it, false, true);
+ ParseMessage(hContact, lastMsgId, it, PM::CreateRead);
setId(hContact, DB_KEY_LASTMSGID, lastMsgId);
if (pUser) {
diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h
index f198ed76e7..61ce296697 100644
--- a/protocols/ICQ-WIM/src/proto.h
+++ b/protocols/ICQ-WIM/src/proto.h
@@ -243,14 +243,20 @@ class CIcqProto : public PROTO<CIcqProto>
void Json2int(MCONTACT, const JSONNode&, const char *szJson, const char *szSetting, bool bIsPartial);
void Json2string(MCONTACT, const JSONNode&, const char *szJson, const char *szSetting, bool bIsPartial);
MCONTACT ParseBuddyInfo(const JSONNode &buddy, MCONTACT hContact = INVALID_CONTACT_ID, bool bIsPartial = false);
- void ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNode &msg, bool bCreateRead, bool bLocalTime);
void ParseMessagePart(MCONTACT hContact, const JSONNode &msg, IcqFileInfo *&pFileInfo);
IcqFileInfo* RetrieveFileInfo(MCONTACT hContact, const CMStringW &wszUrl);
void RetrievePatches(MCONTACT hContact);
int StatusFromPresence(const JSONNode &presence, MCONTACT hContact);
void ProcessPatchVersion(MCONTACT hContact, __int64 currPatch);
void ProcessStatus(IcqUser *pUser, int iStatus);
-
+
+ enum PM {
+ CreateRead = 1,
+ LocalTime = 2,
+ FetchFiles = 4
+ };
+ void ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNode &msg, int flags);
+
void OnLoggedIn(void);
void OnLoggedOut(void);
diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp
index 0d44af1811..62f009cc83 100644
--- a/protocols/ICQ-WIM/src/server.cpp
+++ b/protocols/ICQ-WIM/src/server.cpp
@@ -457,7 +457,7 @@ MCONTACT CIcqProto::ParseBuddyInfo(const JSONNode &buddy, MCONTACT hContact, boo
return hContact;
}
-void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNode &it, bool bCreateRead, bool bLocalTime)
+void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNode &it, int flags)
{
CMStringA szMsgId(it["msgId"].as_mstring()), szSender, szReply;
__int64 msgId = _atoi64(szMsgId);
@@ -465,6 +465,7 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo
lastMsgId = msgId;
MEVENT hOldEvent = db_event_getById(m_szModuleName, szMsgId);
+ bool bLocalTime = (flags & PM::LocalTime) != 0;
int iMsgTime = (bLocalTime) ? time(0) : it["time"].as_int();
if (auto &node = it["chat"]["sender"])
@@ -592,6 +593,7 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo
}
// process our own messages
+ bool bCreateRead = (flags & PM::CreateRead) != 0;
CMStringA reqId(it["reqId"].as_mstring());
if (CheckOwnMessage(reqId, szMsgId, true)) {
debugLogA("Skipping our own message %s", szMsgId.c_str());
@@ -627,7 +629,38 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo
blob.write(dbei);
db_event_edit(hOldEvent, &dbei, true);
}
- else ProtoChainRecvFile(hContact, blob, dbei);
+ else {
+ CMStringA szUrl(pFileInfo->szUrl);
+ MEVENT hEvent = ProtoChainRecvFile(hContact, blob, dbei);
+
+ if (flags & PM::FetchFiles) {
+ if (!blob.isCompleted()) {
+ wchar_t wszReceiveFolder[MAX_PATH];
+ File::GetReceivedFolder(hContact, wszReceiveFolder, _countof(wszReceiveFolder), true);
+ CMStringW wszFileName(FORMAT, L"%s%s", wszReceiveFolder, blob.getName());
+
+ MHttpRequest nlhr(REQUEST_GET);
+ nlhr.flags = NLHRF_REDIRECT;
+ nlhr.m_szUrl = szUrl;
+ nlhr.AddHeader("Sec-Fetch-User", "?1");
+ nlhr.AddHeader("Sec-Fetch-Site", "cross-site");
+ nlhr.AddHeader("Sec-Fetch-Mode", "navigate");
+ nlhr.AddHeader("Accept-Encoding", "gzip");
+
+ debugLogW(L"Saving to [%s]", wszFileName.c_str());
+ NLHR_PTR reply(Netlib_DownloadFile(m_hNetlibUser, &nlhr, wszFileName.c_str(), 0, 0));
+ if (reply && reply->resultCode == 200) {
+ struct _stat st;
+ _wstat(wszFileName, &st);
+
+ DBVARIANT dbv = { DBVT_DWORD };
+ dbv.dVal = st.st_size;
+ db_event_setJson(hEvent, "ft", &dbv);
+ }
+ }
+ }
+ }
+
return;
}
@@ -844,7 +877,7 @@ void CIcqProto::OnGetPatches(MHttpResponse *pReply, AsyncHttpRequest *pReq)
if (_wtoi64(msg["msgId"].as_mstring()) == it.first) {
bFound = true;
__int64 lastMsgId;
- ParseMessage(pReq->hContact, lastMsgId, msg, true, false);
+ ParseMessage(pReq->hContact, lastMsgId, msg, PM::LocalTime);
}
if (!bFound)
@@ -902,17 +935,21 @@ void CIcqProto::OnGetUserHistory(MHttpResponse *pReply, AsyncHttpRequest *pReq)
__int64 lastMsgId = getId(pReq->hContact, DB_KEY_LASTMSGID);
- int count = 0;
+ wchar_t wszReceiveFolder[MAX_PATH];
+ File::GetReceivedFolder(pReq->hContact, wszReceiveFolder, _countof(wszReceiveFolder), true);
+ CreateDirectoryTreeW(wszReceiveFolder);
+
+ int count = 0, flags = PM::FetchFiles + (pReq->pUserInfo ? PM::LocalTime : 0);
auto &results = root.results();
for (auto &it : results["messages"]) {
- ParseMessage(pReq->hContact, lastMsgId, it, pReq->pUserInfo != nullptr, false);
+ ParseMessage(pReq->hContact, lastMsgId, it, flags);
count++;
}
setId(pReq->hContact, DB_KEY_LASTMSGID, lastMsgId);
if (count >= 999)
- RetrieveUserHistory(pReq->hContact, lastMsgId, pReq->pUserInfo != nullptr);
+ RetrieveUserHistory(pReq->hContact, lastMsgId, flags);
}
void CIcqProto::RetrieveUserHistory(MCONTACT hContact, __int64 startMsgId, bool bCreateRead)
diff --git a/protocols/ICQ-WIM/src/stdafx.h b/protocols/ICQ-WIM/src/stdafx.h
index e8a50d16ab..e8c1452cb7 100644
--- a/protocols/ICQ-WIM/src/stdafx.h
+++ b/protocols/ICQ-WIM/src/stdafx.h
@@ -51,6 +51,7 @@
#include <m_clistint.h>
#include <m_contacts.h>
#include <m_database.h>
+#include <m_file.h>
#include <m_gui.h>
#include <m_idle.h>
#include <m_icolib.h>