summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/dropbox_commands.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-05-30 19:52:45 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-05-30 19:52:45 +0000
commit4175d475a610d2ed581116a960a77df4efe6890d (patch)
tree5a047e53ad47893793f40170c5b447f4724bf94a /plugins/Dropbox/src/dropbox_commands.cpp
parent6c764151d2fbb2b6ecfdd68bcd48b86e36a773df (diff)
Dropbox:
- fixed contact creation after auth - more correct way to release response object - version bumb git-svn-id: http://svn.miranda-ng.org/main/trunk@13910 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src/dropbox_commands.cpp')
-rw-r--r--plugins/Dropbox/src/dropbox_commands.cpp162
1 files changed, 83 insertions, 79 deletions
diff --git a/plugins/Dropbox/src/dropbox_commands.cpp b/plugins/Dropbox/src/dropbox_commands.cpp
index 48d6cfa9b4..a5e09c6fb7 100644
--- a/plugins/Dropbox/src/dropbox_commands.cpp
+++ b/plugins/Dropbox/src/dropbox_commands.cpp
@@ -4,10 +4,13 @@ void CDropbox::CommandHelp(void *arg)
{
CommandParam *param = (CommandParam*)arg;
- CMStringA help(Translate("Dropbox supports the following commands:")); help += "\n";
- help += "\"/content [dir]\" \t- "; help += Translate("shows all files in folder \"dir\" (\"dir\" can be omitted for root folder)"); help += "\n";
- help += "\"/share <path>\" \t- "; help += Translate("returns download link for file or folder with specified path (\"path\" is relative from root folder)"); help += "\n";
- help += "\"/delete <path>\" \t- "; help += Translate("deletes file or folder with specified path (\"path\" is relative from root folder)");
+ CMStringA help = (char*)T2Utf(TranslateT("Dropbox supports the following commands:"));
+ help += "\n";
+ help += "\"/content [dir]\" \t- "; help += T2Utf(TranslateT("shows all files in folder \"dir\" (\"dir\" can be omitted for root folder)"));
+ help += "\n";
+ help += "\"/share <path>\" \t- "; help += T2Utf(TranslateT("returns download link for file or folder with specified path (\"path\" is relative from root folder)"));
+ help += "\n";
+ help += "\"/delete <path>\" \t- "; help += T2Utf(TranslateT("deletes file or folder with specified path (\"path\" is relative from root folder)"));
ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help.GetBuffer());
@@ -24,43 +27,46 @@ void CDropbox::CommandContent(void *arg)
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));
+ NetlibPtr response(request.Send(param->instance->hNetlibConnection));
- if (response && response->resultCode == HTTP_STATUS_OK)
+ if (response == NULL || response->resultCode != HTTP_STATUS_OK)
{
- CMStringA message;
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
+ return;
+ }
- JSONROOT root(response->pData);
- if (root)
+ JSONNode root = JSONNode::parse(response->pData);
+ if (root.empty())
+ {
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
+ return;
+ }
+
+ CMStringA message;
+ bool isDir = root.at("is_dir").as_bool();
+ if (!isDir)
+ message.AppendFormat("\"%s\" %s", encodedPath, T2Utf(TranslateT("is file")));
+ else
+ {
+ JSONNode content = root.at("contents").as_array();
+ int size = content.size();
+ for (int i = 0; i < content.size(); i++)
{
- 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 item = content[i];
+ if (item.empty())
{
- 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);
- }
+ if (i == 0)
+ message.AppendFormat("\"%s\" %s", encodedPath, T2Utf(TranslateT("is empty")));
+ break;
}
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
-
- return;
+ CMStringA subName(item.at("path").as_string().c_str());
+ message.AppendFormat("%s\n", (subName[0] == '/') ? subName.Mid(1) : subName);
}
}
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
}
void CDropbox::CommandShare(void *arg)
@@ -68,40 +74,37 @@ void CDropbox::CommandShare(void *arg)
CommandParam *param = (CommandParam*)arg;
char *path = (char*)param->data;
- if (path)
+ if (path == NULL)
{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- ptrA encodedPath(mir_utf8encode(path));
- bool useShortUrl = db_get_b(NULL, MODULE, "UseSortLinks", 1) > 0;
- ShareRequest request(token, encodedPath, useShortUrl);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(param->instance->hNetlibConnection));
+ CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/share");
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
- if (response && response->resultCode == HTTP_STATUS_OK)
- {
- CMStringA link;
+ return;
+ }
- JSONROOT root(response->pData);
- if (root)
- {
- JSONNODE *node = json_get(root, "url");
- link = mir_u2a(json_as_string(node));
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)link.GetBuffer());
+ ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
+ ptrA encodedPath(mir_utf8encode(path));
+ bool useShortUrl = db_get_b(NULL, MODULE, "UseSortLinks", 1) > 0;
+ ShareRequest request(token, encodedPath, useShortUrl);
+ NetlibPtr response(request.Send(param->instance->hNetlibConnection));
- return;
- }
- }
- }
- else
+ if (response == NULL || response->resultCode != HTTP_STATUS_OK)
{
- CMStringA error(FORMAT, Translate("\"%s\" command has invalid parameter.\nUse \"/help\" for more info."), "/share");
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
+ return;
+ }
+ JSONNode root = JSONNode::parse(response->pData);
+ if (root.empty())
+ {
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
return;
}
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
+ CMStringA link = root.at("url").as_string().c_str();
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)link.GetBuffer());
}
void CDropbox::CommandDelete(void *arg)
@@ -109,33 +112,34 @@ void CDropbox::CommandDelete(void *arg)
CommandParam *param = (CommandParam*)arg;
char *path = (char*)param->data;
- if (path)
+ if (path == NULL)
{
- ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- ptrA encodedPath(mir_utf8encode(path));
- DeleteRequest request(token, encodedPath);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(param->instance->hNetlibConnection));
+ CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/delete");
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
- if (response && response->resultCode == HTTP_STATUS_OK)
- {
- JSONROOT root(response->pData);
- if (root)
- {
- JSONNODE *node = json_get(root, "is_deleted");
- bool isDeleted = json_as_bool(node) > 0;
- CMStringA message(FORMAT, "%s %s", path, !isDeleted ? Translate("is not deleted") : Translate("is deleted"));
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
- return;
- }
- }
+ return;
}
- else
+ ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
+ ptrA encodedPath(mir_utf8encode(path));
+ DeleteRequest request(token, encodedPath);
+ NetlibPtr response(request.Send(param->instance->hNetlibConnection));
+
+ if (response == NULL || response->resultCode != HTTP_STATUS_OK)
{
- CMStringA error(FORMAT, Translate("\"%s\" command has invalid parameter.\nUse \"/help\" for more info."), "/delete");
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
+ return;
+ }
+
+ JSONNode root = JSONNode::parse(response->pData);
+ if (root.empty())
+ {
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
+ return;
}
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
+ bool isDeleted = root.at("is_deleted").as_bool();
+ CMStringA message(FORMAT, "%s %s", path, !isDeleted ? T2Utf(TranslateT("is not deleted")) : T2Utf(TranslateT("is deleted")));
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
} \ No newline at end of file