summaryrefslogtreecommitdiff
path: root/plugins
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
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')
-rw-r--r--plugins/Dropbox/src/dropbox.cpp118
-rw-r--r--plugins/Dropbox/src/dropbox.h2
-rw-r--r--plugins/Dropbox/src/dropbox_commands.cpp162
-rw-r--r--plugins/Dropbox/src/dropbox_events.cpp4
-rw-r--r--plugins/Dropbox/src/dropbox_services.cpp7
-rw-r--r--plugins/Dropbox/src/dropbox_transfers.cpp59
-rw-r--r--plugins/Dropbox/src/http_request.h24
-rw-r--r--plugins/Dropbox/src/version.h2
8 files changed, 205 insertions, 173 deletions
diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp
index 3575867b21..6f8c84c2f0 100644
--- a/plugins/Dropbox/src/dropbox.cpp
+++ b/plugins/Dropbox/src/dropbox.cpp
@@ -48,10 +48,9 @@ MCONTACT CDropbox::GetDefaultContact()
db_set_s(hDefaultContact, MODULE, "Nick", MODULE);
db_set_ws(hDefaultContact, "CList", "MyHandle", L"Dropbox");
}
+ db_set_w(hDefaultContact, MODULE, "Status", HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE);
}
- db_set_w(hDefaultContact, MODULE, "Status", HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE);
-
return hDefaultContact;
}
@@ -66,73 +65,62 @@ void CDropbox::RequestAccountInfo()
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
GetAccountInfoRequest request(token);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
+ NetlibPtr response(request.Send(hNetlibConnection));
HandleHttpResponseError(response);
- JSONROOT root(response->pData);
- if (root)
+ JSONNode root = JSONNode::parse(response->pData);
+ if (root.empty())
+ return;
+
+ JSONNode referral_link = root.at("referral_link");
+ if (!referral_link.empty())
+ db_set_s(hContact, MODULE, "Homepage", referral_link.as_string().c_str());
+
+ JSONNode display_name = root.at("display_name");
+ if (!display_name.empty())
{
- JSONNODE *node = json_get(root, "referral_link");
- if (node)
+ ptrT display_name(mir_utf8decodeT(display_name.as_string().c_str()));
+ TCHAR *sep = _tcsrchr(display_name, _T(' '));
+ if (sep)
{
- ptrW referral_link = ptrW(json_as_string(node));
- db_set_ws(hContact, MODULE, "Homepage", referral_link);
+ db_set_ts(hContact, MODULE, "LastName", sep + 1);
+ display_name[mir_tstrlen(display_name) - mir_tstrlen(sep)] = '\0';
+ db_set_ts(hContact, MODULE, "FirstName", display_name);
}
-
- node = json_get(root, "display_name");
- if (node)
+ else
{
- ptrW display_name = ptrW(json_as_string(node));
- TCHAR *sep = _tcsrchr(display_name, L' ');
- if (sep)
- {
- db_set_ws(hContact, MODULE, "LastName", sep + 1);
- display_name[mir_tstrlen(display_name) - mir_tstrlen(sep)] = '\0';
- db_set_ws(hContact, MODULE, "FirstName", display_name);
- }
- else
- {
- db_set_ws(hContact, MODULE, "FirstName", display_name);
- db_unset(hContact, MODULE, "LastName");
- }
+ db_set_ts(hContact, MODULE, "FirstName", display_name);
+ db_unset(hContact, MODULE, "LastName");
}
+ }
- node = json_get(root, "country");
- if (node)
- {
- ptrW isocodeW(json_as_string(node));
- ptrA isocode(mir_u2a(isocodeW));
-
- if (!mir_strlen(isocode))
- db_unset(hContact, MODULE, "Country");
- else
- {
- char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode, 0);
- db_set_s(hContact, MODULE, "Country", country);
- }
- }
+ JSONNode country = root.at("country");
+ if (!country.empty())
+ {
+ std::string isocode = country.as_string();
- node = json_get(root, "quota_info");
- JSONNODE *nroot = json_as_node(node);
- if (nroot)
+ if (isocode.empty())
+ db_unset(hContact, MODULE, "Country");
+ else
{
- node = json_get(nroot, "shared");
- if (node)
- db_set_dw(hContact, MODULE, "SharedQuota", json_as_int(node));
- node = json_get(nroot, "normal");
- if (node)
- db_set_dw(hContact, MODULE, "NormalQuota", json_as_int(node));
- node = json_get(nroot, "quota");
- if (node)
- db_set_dw(hContact, MODULE, "TotalQuota", json_as_int(node));
+ char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0);
+ db_set_s(hContact, MODULE, "Country", country);
}
}
+
+ JSONNode quota_info = root.at("quota_info");
+ if (!quota_info.empty())
+ {
+ db_set_dw(hContact, MODULE, "SharedQuota", quota_info.at("shared").as_int());
+ db_set_dw(hContact, MODULE, "NormalQuota", quota_info.at("normal").as_int());
+ db_set_dw(hContact, MODULE, "TotalQuota", quota_info.at("quota").as_int());
+ }
}
void CDropbox::DestroyAccessToken()
{
DisableAccessTokenRequest request;
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
+ NetlibPtr response(request.Send(hNetlibConnection));
db_unset(NULL, MODULE, "TokenSecret");
MCONTACT hContact = CDropbox::GetDefaultContact();
@@ -158,7 +146,7 @@ UINT CDropbox::RequestAccessTokenAsync(void *owner, void *param)
GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, SIZEOF(requestToken));
GetAccessTokenRequest request(requestToken);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(instance->hNetlibConnection));
+ NetlibPtr response(request.Send(instance->hNetlibConnection));
if (response == NULL)
{
@@ -170,13 +158,22 @@ UINT CDropbox::RequestAccessTokenAsync(void *owner, void *param)
return 0;
}
- JSONROOT root(response->pData);
- if (root == NULL)
+ JSONNode root = JSONNode::parse(response->pData);
+ if (root.empty())
{
- JSONNODE *node = json_get(root, "error_description");
- ptrW error_description(json_as_string(node));
+ Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode));
+ if (hwndDlg)
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond"));
+ /*else
+ ShowNotification((TCHAR*)error_description, MB_ICONERROR);*/
+ return 0;
+ }
- Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode)));
+ JSONNode node = root.at("error_description");
+ if (node != JSONNULL)
+ {
+ ptrT error_description(mir_a2t_cp(node.as_string().c_str(), CP_UTF8));
+ Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode));
if (hwndDlg)
SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description);
/*else
@@ -184,9 +181,8 @@ UINT CDropbox::RequestAccessTokenAsync(void *owner, void *param)
return 0;
}
- JSONNODE *node = json_get(root, "access_token");
- ptrA access_token = ptrA(mir_u2a(json_as_string(node)));
- db_set_s(NULL, MODULE, "TokenSecret", access_token);
+ node = root.at("access_token");
+ db_set_s(NULL, MODULE, "TokenSecret", node.as_string().c_str());
ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, (WPARAM)ID_STATUS_ONLINE);
MCONTACT hContact = instance->GetDefaultContact();
diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h
index 74b156c864..8cad46c4ea 100644
--- a/plugins/Dropbox/src/dropbox.h
+++ b/plugins/Dropbox/src/dropbox.h
@@ -7,6 +7,8 @@ enum
CMI_MAX // this item shall be the last one
};
+#define JSONNULL JSONNode(JSON_NULL)
+
class CDropbox : public MZeroedObject
{
friend CDropboxOptionsMain;
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
diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp
index 9ab3242645..8da1f74270 100644
--- a/plugins/Dropbox/src/dropbox_events.cpp
+++ b/plugins/Dropbox/src/dropbox_events.cpp
@@ -58,9 +58,11 @@ int CDropbox::OnPreShutdown(WPARAM, LPARAM)
int CDropbox::OnContactDeleted(WPARAM hContact, LPARAM)
{
if (mir_strcmpi(GetContactProto(hContact), MODULE) == 0)
+ {
if (HasAccessToken())
DestroyAccessToken();
-
+ hDefaultContact = NULL;
+ }
return 0;
}
diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp
index 77baf2f5cc..f72ba6de39 100644
--- a/plugins/Dropbox/src/dropbox_services.cpp
+++ b/plugins/Dropbox/src/dropbox_services.cpp
@@ -151,14 +151,14 @@ INT_PTR CDropbox::ProtoSendMessage(WPARAM, LPARAM lParam)
char *szMessage = (char*)pccsd->lParam;
- DBEVENTINFO dbei = { sizeof(dbei) };
+ /*DBEVENTINFO dbei = { sizeof(dbei) };
dbei.szModule = MODULE;
dbei.timestamp = time(NULL);
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.cbBlob = (int)mir_strlen(szMessage);
dbei.pBlob = (PBYTE)szMessage;
dbei.flags = DBEF_SENT | DBEF_READ | DBEF_UTF;
- db_event_add(pccsd->hContact, &dbei);
+ db_event_add(pccsd->hContact, &dbei);*/
if (*szMessage == '/')
{
@@ -211,11 +211,12 @@ INT_PTR CDropbox::ProtoReceiveMessage(WPARAM, LPARAM lParam)
char *message = (char*)pccsd->lParam;
DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.flags = DBEF_UTF;
dbei.szModule = MODULE;
dbei.timestamp = time(NULL);
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.cbBlob = (int)mir_strlen(message);
- dbei.pBlob = (PBYTE)message;
+ dbei.pBlob = (PBYTE)mir_strdup(message);
db_event_add(pccsd->hContact, &dbei);
return 0;
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp
index 36990b3f74..e7e5433ff1 100644
--- a/plugins/Dropbox/src/dropbox_transfers.cpp
+++ b/plugins/Dropbox/src/dropbox_transfers.cpp
@@ -5,7 +5,7 @@ void CDropbox::SendFile(const char *path, const char *data, size_t size)
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
ptrA encodedPath(mir_utf8encode(path));
UploadFileRequest request(token, encodedPath, data, size);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
+ NetlibPtr response(request.Send(hNetlibConnection));
HandleHttpResponseError(response);
}
@@ -13,31 +13,34 @@ void CDropbox::SendFileChunkedFirst(const char *data, size_t size, char *uploadI
{
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
UploadFileChunkRequest request(token, data, size);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
+ NetlibPtr response(request.Send(hNetlibConnection));
+
HandleHttpResponseError(response);
- JSONROOT root(response->pData);
- if (root)
- {
- JSONNODE *node = json_get(root, "upload_id");
- mir_strcpy(uploadId, mir_u2a(json_as_string(node)));
- node = json_get(root, "offset");
- offset = json_as_int(node);
- }
+ JSONNode root = JSONNode::parse(response->pData);
+ if (root.empty())
+ return;
+
+ JSONNode node = root.at("upload_id");
+ mir_strcpy(uploadId, node.as_string().c_str());
+
+ node = root.at("offset");
+ offset = node.as_int();
}
void CDropbox::SendFileChunkedNext(const char *data, size_t size, const char *uploadId, size_t &offset)
{
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
UploadFileChunkRequest request(token, uploadId, offset, data, size);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
+ NetlibPtr response(request.Send(hNetlibConnection));
+
HandleHttpResponseError(response);
- JSONROOT root(response->pData);
- if (root)
- {
- JSONNODE *node = json_get(root, "offset");
- offset = json_as_int(node);
- }
+
+ JSONNode root = JSONNode::parse(response->pData);
+ if (root.empty())
+ return;
+
+ offset = root.at("offset").as_int();
}
void CDropbox::SendFileChunkedLast(const char *path, const char *uploadId)
@@ -45,7 +48,7 @@ void CDropbox::SendFileChunkedLast(const char *path, const char *uploadId)
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
ptrA encodedPath(mir_utf8encode(path));
UploadFileChunkRequest request(token, uploadId, (char*)encodedPath);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
+ NetlibPtr response(request.Send(hNetlibConnection));
HandleHttpResponseError(response);
}
@@ -54,7 +57,7 @@ void CDropbox::CreateFolder(const char *path)
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
ptrA encodedPath(mir_utf8encode(path));
CreateFolderRequest request(token, encodedPath);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send(hNetlibConnection));
+ NetlibPtr response(request.Send(hNetlibConnection));
// forder exists on server
if (response->resultCode == HTTP_STATUS_FORBIDDEN)
@@ -69,14 +72,16 @@ void CDropbox::CreateDownloadUrl(const char *path, char *url)
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(hNetlibConnection));
+ NetlibPtr response(request.Send(hNetlibConnection));
+
HandleHttpResponseError(response);
- JSONROOT root(response->pData);
- if (root)
- {
- JSONNODE *node = json_get(root, "url");
- mir_strcpy(url, _T2A(json_as_string(node)));
- }
+
+ JSONNode root = JSONNode::parse(response->pData);
+ if (root.empty())
+ return;
+
+ JSONNode node = root.at("url");
+ mir_strcpy(url, node.as_string().c_str());
}
UINT CDropbox::SendFilesAsync(void *owner, void *arg)
@@ -230,7 +235,7 @@ UINT CDropbox::SendFilesAndReportAsync(void *owner, void *arg)
if (CallContactService(ftp->hContact, PSS_MESSAGE, 0, (LPARAM)message) != ACKRESULT_FAILED)
{
DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.flags = DBEF_UTF | DBEF_SENT/* | DBEF_READ*/;
+ dbei.flags = DBEF_UTF | DBEF_SENT;
dbei.szModule = MODULE;
dbei.timestamp = time(NULL);
dbei.eventType = EVENTTYPE_MESSAGE;
diff --git a/plugins/Dropbox/src/http_request.h b/plugins/Dropbox/src/http_request.h
index 9980945b66..dc0c006b47 100644
--- a/plugins/Dropbox/src/http_request.h
+++ b/plugins/Dropbox/src/http_request.h
@@ -31,7 +31,7 @@ public:
}
};
-class HttpRequest : protected NETLIBHTTPREQUEST//, public MZeroedObject
+class HttpRequest : protected NETLIBHTTPREQUEST
{
private:
CMStringA m_szUrl;
@@ -163,4 +163,26 @@ public:
}
};
+class NetlibPtr
+{
+protected:
+ NETLIBHTTPREQUEST *_p;
+
+public:
+ __inline explicit NetlibPtr(NETLIBHTTPREQUEST *p) : _p(p) {}
+ __inline NETLIBHTTPREQUEST* operator=(NETLIBHTTPREQUEST *p)
+ {
+ if (p)
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)(NETLIBHTTPREQUEST*)p);
+ _p = p;
+ return _p;
+ }
+ __inline operator NETLIBHTTPREQUEST*() const { return _p; }
+ __inline NETLIBHTTPREQUEST* operator->() const { return _p; }
+ __inline ~NetlibPtr()
+ {
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)(NETLIBHTTPREQUEST*)this);
+ }
+};
+
#endif //_HTTP_REQUEST_H_ \ No newline at end of file
diff --git a/plugins/Dropbox/src/version.h b/plugins/Dropbox/src/version.h
index 65d96b82ca..69b84b0724 100644
--- a/plugins/Dropbox/src/version.h
+++ b/plugins/Dropbox/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 12
#define __RELEASE_NUM 0
-#define __BUILD_NUM 5
+#define __BUILD_NUM 6
#include <stdver.h>