diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-02-19 19:07:45 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-02-19 19:07:45 +0000 |
commit | fc46c19a61d26fb610d173bb8fc5420eea966caa (patch) | |
tree | 0d388af6d8a53eb4ef56dcdb96fe44d56bccb63d /plugins/Dropbox/src/dropbox_transfers.cpp | |
parent | 3ced66e7eac9a8a0867073553db2b2bd74729b09 (diff) |
Dropbox:
- global object replaced by singleton
- added ability to upload folders
git-svn-id: http://svn.miranda-ng.org/main/trunk@8183 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src/dropbox_transfers.cpp')
-rw-r--r-- | plugins/Dropbox/src/dropbox_transfers.cpp | 122 |
1 files changed, 78 insertions, 44 deletions
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index 550e6b7e64..6a0d885894 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -76,14 +76,23 @@ void CDropbox::SendFileChunkedNext(const char *data, int length, const char *upl void CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId, MCONTACT hContact)
{
- char url[MAX_PATH];
+ /*char url[MAX_PATH];
mir_snprintf(
url,
SIZEOF(url),
"%s/commit_chunked_upload/%s/%s",
DROPBOX_APICONTENT_URL,
DROPBOX_API_ROOT,
+ fileName);*/
+
+ CMStringA url;
+ url.AppendFormat(
+ "%s/commit_chunked_upload/%s/%s",
+ DROPBOX_APICONTENT_URL,
+ DROPBOX_API_ROOT,
fileName);
+ url.Replace('\\', '/');
+
HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_POST, url);
request->AddParameter("upload_id", uploadId);
@@ -93,55 +102,76 @@ void CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId, M delete request;
- if (response && response->resultCode == HttpStatus::OK)
+ if (response)
{
- mir_snprintf(
- url,
- SIZEOF(url),
- "%s/shares/%s/%s",
- DROPBOX_API_URL,
- DROPBOX_API_ROOT,
- fileName);
+ if (response->resultCode == HttpStatus::OK)
+ {
+ url.Replace(DROPBOX_APICONTENT_URL, DROPBOX_API_URL);
+ url.Replace("commit_chunked_upload", "shares");
- request = new HttpRequest(hNetlibUser, REQUEST_POST, url);
- request->AddParameter("access_token", db_get_sa(NULL, MODULE, "TokenSecret"));
+ request = new HttpRequest(hNetlibUser, REQUEST_POST, url);
+ request->AddParameter("access_token", db_get_sa(NULL, MODULE, "TokenSecret"));
- mir_free(response);
+ mir_free(response);
- response = request->Send();
+ response = request->Send();
- if (response)
- {
- if (response->resultCode == HttpStatus::OK)
+ if (response)
{
- JSONNODE *root = json_parse(response->pData);
- if (root != NULL)
+ if (response->resultCode == HttpStatus::OK)
{
- JSONNODE *node = json_get(root, "url");
- char message[1024];
- mir_snprintf(
- message,
- SIZEOF(message),
- Translate("Link to download file \"%s\": %s"),
- fileName,
- mir_utf8encodeW(json_as_string(node)));
-
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.szModule = MODULE;
- dbei.timestamp = time(NULL);
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = strlen(message);
- dbei.pBlob = (PBYTE)mir_strdup(message);
- dbei.flags = DBEF_UTF;
- ::db_event_add(hContact, &dbei);
-
- delete node;
- delete root;
+ JSONNODE *root = json_parse(response->pData);
+ if (root != NULL)
+ {
+ JSONNODE *node = json_get(root, "url");
+ char message[1024];
+ mir_snprintf(
+ message,
+ SIZEOF(message),
+ Translate("Link to download file \"%s\": %s"),
+ fileName,
+ mir_utf8encodeW(json_as_string(node)));
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = MODULE;
+ dbei.timestamp = time(NULL);
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.cbBlob = strlen(message);
+ dbei.pBlob = (PBYTE)mir_strdup(message);
+ dbei.flags = DBEF_UTF;
+ ::db_event_add(hContact, &dbei);
+
+ delete node;
+ delete root;
+ }
}
- }
- mir_free(response);
+ mir_free(response);
+ }
}
+ else
+ mir_free(response);
+ }
+}
+
+void CDropbox::CreateFolder(const char *folderName)
+{
+ HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/fileops/create_folder");
+ request->AddParameter("root", DROPBOX_API_ROOT);
+ request->AddParameter("path", folderName);
+ request->AddParameter("access_token", db_get_sa(NULL, MODULE, "TokenSecret"));
+
+ NETLIBHTTPREQUEST *response = request->Send();
+
+ delete request;
+
+ if (response)
+ {
+ /*if (response->resultCode == HttpStatus::OK)
+ {
+ }*/
+
+ mir_free(response);
}
}
@@ -151,6 +181,9 @@ void _cdecl CDropbox::SendFileAsync(void *arg) ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ftp->hProcess, 0);
+ for (int i = 0; ftp->pszFolders[i]; i++)
+ Singleton<CDropbox>::GetInstance()->CreateFolder(ftp->pszFolders[i]);
+
for (int i = 0; ftp->pfts.pszFiles[i]; i++)
{
FILE *file = fopen(ftp->pfts.pszFiles[i], "rb");
@@ -159,7 +192,8 @@ void _cdecl CDropbox::SendFileAsync(void *arg) int offset = 0;
char *uploadId = new char[32];
- const char *fileName = strrchr(ftp->pfts.pszFiles[i], '\\') + 1;
+ //const char *fileName = strrchr(ftp->pfts.pszFiles[i], '\\') + 1;
+ const char *fileName = &ftp->pfts.pszFiles[i][ftp->relativePathStart];
fseek(file, 0, SEEK_END);
DWORD fileSize = ftell(file);
@@ -184,9 +218,9 @@ void _cdecl CDropbox::SendFileAsync(void *arg) size_t count = fread(data, sizeof(char), chunkSize, file);
if (!offset)
- g_dropbox->SendFileChunkedFirst(data, count, uploadId, offset);
+ Singleton<CDropbox>::GetInstance()->SendFileChunkedFirst(data, count, uploadId, offset);
else
- g_dropbox->SendFileChunkedNext(data, count, uploadId, offset);
+ Singleton<CDropbox>::GetInstance()->SendFileChunkedNext(data, count, uploadId, offset);
ftp->pfts.currentFileProgress += count;
ftp->pfts.totalProgress += count;
@@ -196,7 +230,7 @@ void _cdecl CDropbox::SendFileAsync(void *arg) fclose(file);
- g_dropbox->SendFileChunkedLast(fileName, uploadId, ftp->pfts.hContact);
+ Singleton<CDropbox>::GetInstance()->SendFileChunkedLast(fileName, uploadId, ftp->pfts.hContact);
ftp->pfts.currentFileProgress = ftp->pfts.currentFileSize;
if (i < ftp->pfts.totalFiles - 1)
|