summaryrefslogtreecommitdiff
path: root/protocols/SkypeWeb
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-09-25 20:21:47 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-09-25 20:21:47 +0300
commit484b5c4e8cd2d8591273a06cfde1d73dcdda00d2 (patch)
treeae53a3d07145436a05ffd21e4d861172e15d081e /protocols/SkypeWeb
parent6dc2b417c94f35b0175e41fd99e96533cb2107ee (diff)
temporary fix for #2071 - we don't try to send a file if we cannot obtain an object id
Diffstat (limited to 'protocols/SkypeWeb')
-rw-r--r--protocols/SkypeWeb/src/requests/asm/files.h5
-rw-r--r--protocols/SkypeWeb/src/skype_files.cpp67
2 files changed, 41 insertions, 31 deletions
diff --git a/protocols/SkypeWeb/src/requests/asm/files.h b/protocols/SkypeWeb/src/requests/asm/files.h
index 721aac16b3..6400e2a8db 100644
--- a/protocols/SkypeWeb/src/requests/asm/files.h
+++ b/protocols/SkypeWeb/src/requests/asm/files.h
@@ -19,8 +19,7 @@ public:
node << JSONNode("type", "sharing/file") << JSONNode("filename", szFileName) << jPermissions;
Body << VALUE(node.write().c_str());
-
- }// {"id":"0-neu-d1-d0649c1fb4e4c60f2d2d1f2165a99f60"}
+ }
};
class ASMObjectUploadRequest : public HttpRequest
@@ -42,4 +41,4 @@ public:
{
mir_free(pData);
}
-}; \ No newline at end of file
+};
diff --git a/protocols/SkypeWeb/src/skype_files.cpp b/protocols/SkypeWeb/src/skype_files.cpp
index 12cf2200ba..4c35337e6f 100644
--- a/protocols/SkypeWeb/src/skype_files.cpp
+++ b/protocols/SkypeWeb/src/skype_files.cpp
@@ -32,36 +32,47 @@ void CSkypeProto::SendFileThread(void *p)
void CSkypeProto::OnASMObjectCreated(const NETLIBHTTPREQUEST *response, void *arg)
{
CFileUploadParam *fup = (CFileUploadParam*)arg;
- if (response && response->pData) {
- JSONNode node = JSONNode::parse((char*)response->pData);
- std::string strObjectId = node["id"].as_string();
- fup->uid = mir_strdup(strObjectId.c_str());
- FILE *pFile = _wfopen(fup->tszFileName, L"rb");
- if (pFile == nullptr) return;
-
- fseek(pFile, 0, SEEK_END);
- long lFileLen = ftell(pFile);
-
- if (lFileLen < 1) {
- fclose(pFile);
- return;
- }
-
- fseek(pFile, 0, SEEK_SET);
-
- mir_ptr<BYTE> pData((BYTE*)mir_alloc(lFileLen));
- long lBytes = (long)fread(pData, sizeof(BYTE), lFileLen, pFile);
-
- if (lBytes != lFileLen) {
- fclose(pFile);
- FILETRANSFER_FAILED(fup);
- return;
- }
- fup->size = lBytes;
- ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)fup);
- SendRequest(new ASMObjectUploadRequest(this, strObjectId.c_str(), pData, lBytes), &CSkypeProto::OnASMObjectUploaded, fup);
+ if (response == nullptr || response->pData == nullptr) {
+LBL_Error:
+ FILETRANSFER_FAILED(fup);
+ return;
+ }
+
+ if (response->resultCode != 200) {
+ debugLogA("Object creation failed with error code %d", response->resultCode);
+ goto LBL_Error;
+ }
+
+ JSONNode node = JSONNode::parse((char*)response->pData);
+ std::string strObjectId = node["id"].as_string();
+ if (strObjectId.empty()) {
+ debugLogA("Invalid server response (empty object id)");
+ goto LBL_Error;
+ }
+
+ fup->uid = mir_strdup(strObjectId.c_str());
+ FILE *pFile = _wfopen(fup->tszFileName, L"rb");
+ if (pFile == nullptr) return;
+
+ fseek(pFile, 0, SEEK_END);
+ long lFileLen = ftell(pFile);
+ if (lFileLen < 1) {
+ fclose(pFile);
+ goto LBL_Error;
+ }
+
+ fseek(pFile, 0, SEEK_SET);
+
+ mir_ptr<BYTE> pData((BYTE*)mir_alloc(lFileLen));
+ long lBytes = (long)fread(pData, sizeof(BYTE), lFileLen, pFile);
+ if (lBytes != lFileLen) {
fclose(pFile);
+ goto LBL_Error;
}
+ fup->size = lBytes;
+ ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)fup);
+ SendRequest(new ASMObjectUploadRequest(this, strObjectId.c_str(), pData, lBytes), &CSkypeProto::OnASMObjectUploaded, fup);
+ fclose(pFile);
}
void CSkypeProto::OnASMObjectUploaded(const NETLIBHTTPREQUEST *response, void *arg)