diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-05-13 15:21:50 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-05-13 15:21:50 +0000 |
commit | ac60e6cd374568da60bf732a8018f94d48ee9dd7 (patch) | |
tree | e85ce8fe96226a39f3d1432f29c769cd5926047c /plugins/Dropbox | |
parent | 71846c4e387e27164ffde6b2e8a188b3bc21b2eb (diff) |
Dropbox:
- fixed commands sending
- removed status changing
git-svn-id: http://svn.miranda-ng.org/main/trunk@13571 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox')
-rw-r--r-- | plugins/Dropbox/src/api/operations.h | 6 | ||||
-rw-r--r-- | plugins/Dropbox/src/api/upload.h | 1 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox.cpp | 3 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox.h | 3 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_commands.cpp | 70 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_services.cpp | 33 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_transfers.cpp | 2 | ||||
-rw-r--r-- | plugins/Dropbox/src/http_request.h | 6 |
8 files changed, 50 insertions, 74 deletions
diff --git a/plugins/Dropbox/src/api/operations.h b/plugins/Dropbox/src/api/operations.h index 1ff7d50230..56578515b3 100644 --- a/plugins/Dropbox/src/api/operations.h +++ b/plugins/Dropbox/src/api/operations.h @@ -26,8 +26,7 @@ public: CMStringA data(CMStringDataFormat::FORMAT, "root=auto&path=%s", path);
data.Replace('\\', '/');
- pData = data.GetBuffer();
- dataLength = data.GetLength();
+ SetData(data.GetBuffer(), data.GetLength());
}
};
@@ -42,8 +41,7 @@ public: CMStringA data(CMStringDataFormat::FORMAT, "root=auto&path=%s", path);
data.Replace('\\', '/');
- pData = data.GetBuffer();
- dataLength = data.GetLength();
+ SetData(data.GetBuffer(), data.GetLength());
}
};
diff --git a/plugins/Dropbox/src/api/upload.h b/plugins/Dropbox/src/api/upload.h index 323bf907a5..5c2e41c792 100644 --- a/plugins/Dropbox/src/api/upload.h +++ b/plugins/Dropbox/src/api/upload.h @@ -39,7 +39,6 @@ public: {
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/x-www-form-urlencoded");
-
AddUrlParameter("upload_id=%s", uploadId);
}
};
diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp index 5649bec56e..18f611cdff 100644 --- a/plugins/Dropbox/src/dropbox.cpp +++ b/plugins/Dropbox/src/dropbox.cpp @@ -18,8 +18,7 @@ CDropbox::CDropbox() : transfers(1, HandleKeySortT) CreateProtoServiceFunction(MODULE, PS_GETCAPS, ProtoGetCaps);
CreateProtoServiceFunction(MODULE, PS_GETNAME, ProtoGetName);
CreateProtoServiceFunction(MODULE, PS_LOADICON, ProtoLoadIcon);
- CreateProtoServiceFunction(MODULE, PS_GETSTATUS, ProtoGetStatus);
- CreateProtoServiceFunctionObj(PS_SETSTATUS, ProtoSetStatus, this);
+ CreateProtoServiceFunctionObj(PS_GETSTATUS, ProtoGetStatus, this);
CreateProtoServiceFunctionObj(PSS_FILEW, ProtoSendFile, this);
CreateProtoServiceFunctionObj(PSS_FILECANCEL, ProtoCancelFile, this);
CreateProtoServiceFunctionObj(PSS_MESSAGE, ProtoSendMessage, this);
diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index 8c46fcc55b..f05df5e6d1 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -70,8 +70,7 @@ private: static INT_PTR ProtoGetCaps(WPARAM wParam, LPARAM lParam);
static INT_PTR ProtoGetName(WPARAM wParam, LPARAM lParam);
static INT_PTR ProtoLoadIcon(WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoGetStatus(WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoSetStatus(void *obj, WPARAM wParam, LPARAM lParam);
+ static INT_PTR ProtoGetStatus(void *obj, WPARAM wParam, LPARAM lParam);
static INT_PTR ProtoSendFile(void *obj, WPARAM wParam, LPARAM lParam);
static INT_PTR ProtoCancelFile(void *obj, WPARAM wParam, LPARAM lParam);
static INT_PTR ProtoSendMessage(void *obj, WPARAM wParam, LPARAM lParam);
diff --git a/plugins/Dropbox/src/dropbox_commands.cpp b/plugins/Dropbox/src/dropbox_commands.cpp index 3ce87a7c3b..739768d099 100644 --- a/plugins/Dropbox/src/dropbox_commands.cpp +++ b/plugins/Dropbox/src/dropbox_commands.cpp @@ -18,55 +18,47 @@ void CDropbox::CommandContent(void *arg) CommandParam *param = (CommandParam*)arg;
char *path = (char*)param->data;
- if (path)
+ if (path == NULL)
+ path = "";
+
+ ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
+ ptrA encodedPath(mir_utf8encode(path));
+ GetMetadataRequest request(token, encodedPath);
+ mir_ptr<NETLIBHTTPREQUEST> response(request.Send(param->instance->hNetlibConnection));
+
+ if (response && response->resultCode == HTTP_STATUS_OK)
{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- ptrA encodedPath(mir_utf8encode(path));
- GetMetadataRequest request(token, encodedPath);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(param->instance->hNetlibConnection));
+ CMStringA message;
- if (response && response->resultCode == HTTP_STATUS_OK)
+ JSONROOT root(response->pData);
+ if (root)
{
- CMStringA message;
-
- JSONROOT root(response->pData);
- if (root)
+ JSONNODE *node = json_get(root, "is_dir");
+ bool isDir = json_as_bool(node) > 0;
+ if (!isDir)
+ message.AppendFormat("\"%s\" %s", path, Translate("is file"));
+ else
{
- JSONNODE *node = json_get(root, "is_dir");
- bool isDir = json_as_bool(node) > 0;
- if (!isDir)
- message.AppendFormat("\"%s\" %s", path, Translate("is file"));
- else
- {
- JSONNODE *content = json_as_array(json_get(root, "contents"));
- for (int i = 0;; i++) {
- JSONNODE *item = json_at(content, i);
- if (item == NULL) {
- if (i == 0)
- message.AppendFormat("\"%s\" %s", path, Translate("is empty"));
- break;
- }
-
- ptrA subName(mir_u2a(json_as_string(json_get(item, "path"))));
- message.AppendFormat("%s\n", (subName[0] == '/') ? &subName[1] : subName);
+ JSONNODE *content = json_as_array(json_get(root, "contents"));
+ for (int i = 0;; i++) {
+ JSONNODE *item = json_at(content, i);
+ if (item == NULL) {
+ if (i == 0)
+ message.AppendFormat("\"%s\" %s", path, Translate("is empty"));
+ break;
}
+
+ ptrA subName(mir_u2a(json_as_string(json_get(item, "path"))));
+ message.AppendFormat("%s\n", (subName[0] == '/') ? &subName[1] : subName);
}
+ }
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
- return;
- }
+ return;
}
}
- else
- {
- CMStringA error(FORMAT, Translate("\"%s\" command has invalid parameter.\nUse \"/help\" for more info."), "/content");
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
-
- return;
- }
ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
}
diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index 059d92036b..d558fa7917 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -41,30 +41,10 @@ INT_PTR CDropbox::ProtoLoadIcon(WPARAM wParam, LPARAM) return (LOWORD(wParam) == PLI_PROTOCOL) ? (INT_PTR)CopyIcon(LoadIconEx(IDI_DROPBOX)) : 0;
}
-INT_PTR CDropbox::ProtoGetStatus(WPARAM, LPARAM)
-{
- return g_nStatus;
-}
-
-INT_PTR CDropbox::ProtoSetStatus(void *obj, WPARAM wp, LPARAM)
+INT_PTR CDropbox::ProtoGetStatus(void *obj, WPARAM, LPARAM)
{
CDropbox *instance = (CDropbox*)obj;
- int nStatus = wp;
- if ((ID_STATUS_ONLINE == nStatus) || (ID_STATUS_OFFLINE == nStatus))
- {
- int nOldStatus = g_nStatus;
- if (nStatus != g_nStatus)
- {
- g_nStatus = nStatus;
-
- MCONTACT hContact = instance->GetDefaultContact();
- db_set_w(hContact, MODULE, "Status", nStatus);
-
- ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)nOldStatus, g_nStatus);
- }
- }
-
- return 0;
+ return instance->HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE;
}
INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam)
@@ -172,7 +152,14 @@ INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam) CCSDATA *pccsd = (CCSDATA*)lParam;
- char *message = NEWSTR_ALLOCA((char*)pccsd->lParam);
+ char *message = NULL;
+ char *szMessage = (char*)pccsd->lParam;
+ if (pccsd->wParam & PREF_UNICODE)
+ message = mir_utf8encodeW((wchar_t*)&szMessage[mir_strlen(szMessage) + 1]);
+ else if (pccsd->wParam & PREF_UTF)
+ message = mir_strdup(szMessage);
+ else
+ message = mir_utf8encode(szMessage);
DBEVENTINFO dbei = { sizeof(dbei) };
dbei.szModule = MODULE;
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index f7d10463e3..459914521c 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -151,7 +151,7 @@ UINT CDropbox::SendFilesAsync(void *owner, void *arg) if (ftp->isTerminated)
throw TransferException("Transfer was terminated");
- char *data = new char[chunkSize + 1];
+ char *data = (char*)mir_alloc(chunkSize);
int count = (int)fread(data, sizeof(char), chunkSize, hFile);
if (offset == 0)
diff --git a/plugins/Dropbox/src/http_request.h b/plugins/Dropbox/src/http_request.h index 79f6c09a65..0cb769f609 100644 --- a/plugins/Dropbox/src/http_request.h +++ b/plugins/Dropbox/src/http_request.h @@ -115,7 +115,7 @@ protected: va_end(urlArgs);
}
- /*void SetData(const char *data, size_t size)
+ void SetData(const char *data, size_t size)
{
if (pData != NULL)
mir_free(pData);
@@ -124,7 +124,7 @@ protected: pData = (char*)mir_alloc(size + 1);
memcpy(pData, data, size);
pData[size] = 0;
- }*/
+ }
public:
HttpRequest(int type, LPCSTR url)
@@ -152,6 +152,8 @@ public: mir_free(headers[i].szValue);
}
mir_free(headers);
+ if (pData)
+ mir_free(pData);
}
NETLIBHTTPREQUEST* Send(HANDLE hNetlibConnection)
|