diff options
-rw-r--r-- | libs/libjson/src/stdafx.cxx | 32 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/server.cpp | 29 |
2 files changed, 48 insertions, 13 deletions
diff --git a/libs/libjson/src/stdafx.cxx b/libs/libjson/src/stdafx.cxx index 178e138057..e96fbffa1b 100644 --- a/libs/libjson/src/stdafx.cxx +++ b/libs/libjson/src/stdafx.cxx @@ -22,18 +22,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const INT_PARAM ¶m)
{
+ auto n = json.find(param.szName);
+ if (n != json.end())
+ json.erase(n);
+
json.push_back(JSONNode(param.szName, param.iValue));
return json;
}
LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const INT64_PARAM ¶m)
{
+ auto n = json.find(param.szName);
+ if (n != json.end())
+ json.erase(n);
+
json.push_back(JSONNode(param.szName, param.iValue));
return json;
}
LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const SINT64_PARAM ¶m)
{
+ auto n = json.find(param.szName);
+ if (n != json.end())
+ json.erase(n);
+
char str[40];
_i64toa(param.iValue, str, 10);
return json << CHAR_PARAM(param.szName, str);
@@ -41,12 +53,20 @@ LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const SINT64_PARAM ¶m) LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const BOOL_PARAM ¶m)
{
+ auto n = json.find(param.szName);
+ if (n != json.end())
+ json.erase(n);
+
json.push_back(JSONNode(param.szName, param.bValue));
return json;
}
LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const CHAR_PARAM ¶m)
{
+ auto n = json.find(param.szName);
+ if (n != json.end())
+ json.erase(n);
+
if (param.szValue == nullptr) {
JSONNode tmp(JSON_NULL); tmp.set_name(param.szName);
json.push_back(tmp);
@@ -62,12 +82,20 @@ LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const CHAR_PARAM ¶m) LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const WCHAR_PARAM ¶m)
{
+ auto n = json.find(param.szName);
+ if (n != json.end())
+ json.erase(n);
+
json.push_back(JSONNode(param.szName, ptrA(mir_utf8encodeW(param.wszValue)).get()));
return json;
}
LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const NULL_PARAM ¶m)
{
+ auto n = json.find(param.szName);
+ if (n != json.end())
+ json.erase(n);
+
JSONNode newOne(JSON_NULL);
newOne.set_name(param.szName);
json.push_back(newOne);
@@ -76,6 +104,10 @@ LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const NULL_PARAM ¶m) LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const JSON_PARAM ¶m)
{
+ auto n = json.find(param.szName);
+ if (n != json.end())
+ json.erase(n);
+
JSONNode newOne(param.node);
newOne.set_name(param.szName);
json.push_back(newOne);
diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp index 1d06a643b0..3b310d9b49 100644 --- a/protocols/ICQ-WIM/src/server.cpp +++ b/protocols/ICQ-WIM/src/server.cpp @@ -630,15 +630,19 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo db_event_edit(hOldEvent, &dbei, true);
}
else {
+ int iSaveSize = pFileInfo->dwFileSize;
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());
-
+ wchar_t wszReceiveFolder[MAX_PATH];
+ File::GetReceivedFolder(hContact, wszReceiveFolder, _countof(wszReceiveFolder), true);
+ CMStringW wszFileName(FORMAT, L"%s%s", wszReceiveFolder, blob.getName());
+
+ // download & save file only if it's missing
+ struct _stat st = {};
+ int rc = _wstat(wszFileName, &st);
+ if (rc != 0 || st.st_size != iSaveSize) {
MHttpRequest nlhr(REQUEST_GET);
nlhr.flags = NLHRF_REDIRECT;
nlhr.m_szUrl = szUrl;
@@ -649,15 +653,14 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo 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);
- }
+ if (!reply || reply->resultCode != 200)
+ return;
}
+
+ blob.setLocalName(wszFileName);
+ blob.complete(iSaveSize);
+ blob.write(dbei);
+ db_event_edit(hEvent, &dbei, true);
}
}
|