ptask namespace and cleanup
This commit is contained in:
parent
4dbea61178
commit
94d960655e
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2015 Anton Titov.
|
||||
|
||||
Copyright (c) 2015 pCloud Ltd. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met: Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer. Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided with
|
||||
the distribution. Neither the name of pCloud Ltd nor the names of
|
||||
its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL pCloud Ltd BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _PSYNC_ASYNCNET_H
|
||||
#define _PSYNC_ASYNCNET_H
|
||||
|
||||
#include "psynclib.h"
|
||||
|
||||
#define PSYNC_ASYNC_ERR_FLAG_PERM \
|
||||
0x01 // the error is permanent(ish) and there is no reason to retry
|
||||
#define PSYNC_ASYNC_ERR_FLAG_RETRY_AS_IS \
|
||||
0x02 // same request may succeed in the future if retried as is
|
||||
#define PSYNC_ASYNC_ERR_FLAG_SUCCESS \
|
||||
0x04 // like no action performed because of no need - file already exists and
|
||||
// so on
|
||||
|
||||
#define PSYNC_ASYNC_ERROR_NET 1
|
||||
#define PSYNC_ASYNC_ERROR_FILE 2
|
||||
#define PSYNC_ASYNC_ERROR_DISK_FULL 3
|
||||
#define PSYNC_ASYNC_ERROR_IO 4
|
||||
#define PSYNC_ASYNC_ERROR_CHECKSUM 5
|
||||
|
||||
#define PSYNC_SERVER_ERROR_TOO_BIG 102
|
||||
#define PSYNC_SERVER_ERROR_NOT_MOD 104
|
||||
|
||||
typedef struct {
|
||||
uint64_t size;
|
||||
uint64_t hash;
|
||||
unsigned char sha1hex[40];
|
||||
} psync_async_file_result_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t error;
|
||||
uint32_t errorflags;
|
||||
union {
|
||||
psync_async_file_result_t file;
|
||||
};
|
||||
} psync_async_result_t;
|
||||
|
||||
typedef void (*psync_async_callback_t)(void *, psync_async_result_t *);
|
||||
|
||||
/* Important! The interface typically expect all passed pointers to be alive
|
||||
* until the completion callback is called.
|
||||
*/
|
||||
|
||||
void psync_async_stop();
|
||||
int psync_async_download_file(psync_fileid_t fileid, const char *localpath,
|
||||
psync_async_callback_t cb, void *cbext);
|
||||
int psync_async_download_file_if_changed(psync_fileid_t fileid,
|
||||
const char *localpath, uint64_t size,
|
||||
const void *sha1hex,
|
||||
psync_async_callback_t cb,
|
||||
void *cbext);
|
||||
|
||||
#endif
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
#include "psynclib.h"
|
||||
#include "psyncer.h"
|
||||
#include "psys.h"
|
||||
#include "ptasks.h"
|
||||
#include "ptask.h"
|
||||
#include "ptimer.h"
|
||||
#include "ptools.h"
|
||||
#include "publiclinks.h"
|
||||
|
|
@ -949,7 +949,7 @@ static void process_createfolder(const binresult *entry) {
|
|||
psync_sql_bind_uint(stmt, 4, row[2]);
|
||||
psync_sql_run(stmt);
|
||||
if (psync_sql_affected_rows() == 1) {
|
||||
psync_task_create_local_folder(syncid, folderid, localfolderid);
|
||||
ptask_ldir_mk(syncid, folderid, localfolderid);
|
||||
needdownload = 1;
|
||||
} else {
|
||||
stmt2 = psync_sql_prep_statement("UPDATE syncedfolder SET folderid=? "
|
||||
|
|
@ -1156,7 +1156,7 @@ static void process_modifyfolder(const binresult *entry) {
|
|||
}
|
||||
localfolderid = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psync_task_rename_local_folder(
|
||||
ptask_ldir_rename(
|
||||
psync_get_result_cell(fres2, i, 0), folderid, localfolderid,
|
||||
psync_get_result_cell(fres2, i, 1), name->str);
|
||||
needdownload = 1;
|
||||
|
|
@ -1188,7 +1188,7 @@ static void process_modifyfolder(const binresult *entry) {
|
|||
localfolderid = row[0];
|
||||
psync_sql_free_result(res);
|
||||
del_synced_folder_rec(folderid, syncid);
|
||||
psync_task_delete_local_folder_recursive(syncid, folderid, localfolderid);
|
||||
ptask_ldir_rm_r(syncid, folderid, localfolderid);
|
||||
needdownload = 1;
|
||||
}
|
||||
for (/*i is already=cnt*/; i < fres2->rows; i++) {
|
||||
|
|
@ -1199,7 +1199,7 @@ static void process_modifyfolder(const binresult *entry) {
|
|||
(unsigned long)folderid, (unsigned long)parentfolderid);
|
||||
localfolderid = psync_create_local_folder_in_db(
|
||||
syncid, folderid, psync_get_result_cell(fres2, i, 1), name->str);
|
||||
psync_task_create_local_folder(syncid, folderid, localfolderid);
|
||||
ptask_ldir_mk(syncid, folderid, localfolderid);
|
||||
psync_add_folder_for_downloadsync(
|
||||
syncid, psync_get_result_cell(fres2, i, 2), folderid, localfolderid);
|
||||
needdownload = 1;
|
||||
|
|
@ -1253,7 +1253,7 @@ static void process_deletefolder(const binresult *entry) {
|
|||
psync_sql_run_free(stmt);
|
||||
if (psync_sql_affected_rows() == 1) {
|
||||
path = psync_get_path_by_folderid(folderid, NULL);
|
||||
psync_task_delete_local_folder(row[0], folderid, row[1], path);
|
||||
ptask_ldir_rm(row[0], folderid, row[1], path);
|
||||
psync_free(path);
|
||||
needdownload = 1;
|
||||
}
|
||||
|
|
@ -1416,7 +1416,7 @@ static void process_createfile(const binresult *entry) {
|
|||
if (!hasit) {
|
||||
debug(D_NOTICE, "downloading file %s with hash %ld to local folder %lu",
|
||||
name->str, (long)hash, (unsigned long)row[1]);
|
||||
psync_task_download_file_silent(row[0], fileid, row[1], name->str);
|
||||
ptask_download_q(row[0], fileid, row[1], name->str);
|
||||
needdownload = 1;
|
||||
} else
|
||||
debug(D_NOTICE,
|
||||
|
|
@ -1520,7 +1520,7 @@ static void process_modifyfile(const binresult *entry) {
|
|||
char *path;
|
||||
psync_delete_download_tasks_for_file(fileid, 0, 1);
|
||||
path = psync_get_path_by_fileid(fileid, NULL);
|
||||
psync_task_delete_local_file(fileid, path);
|
||||
ptask_lfile_rm(fileid, path);
|
||||
psync_free(path);
|
||||
needdownload = 1;
|
||||
return;
|
||||
|
|
@ -1549,7 +1549,7 @@ static void process_modifyfile(const binresult *entry) {
|
|||
// fres2->rows, oldparentfolderid, parentfolderid);
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (needrename) {
|
||||
psync_task_rename_local_file(psync_get_result_cell(fres1, i, 0),
|
||||
ptask_lfile_rename(psync_get_result_cell(fres1, i, 0),
|
||||
psync_get_result_cell(fres2, i, 0), fileid,
|
||||
psync_get_result_cell(fres1, i, 1),
|
||||
psync_get_result_cell(fres2, i, 1),
|
||||
|
|
@ -1571,7 +1571,7 @@ static void process_modifyfile(const binresult *entry) {
|
|||
"ignoring update for file %s, has correct hash in the database",
|
||||
name->str);
|
||||
else {
|
||||
psync_task_download_file_silent(
|
||||
ptask_download_q(
|
||||
psync_get_result_cell(fres2, i, 0), fileid,
|
||||
psync_get_result_cell(fres2, i, 1), name->str);
|
||||
needdownload = 1;
|
||||
|
|
@ -1579,14 +1579,14 @@ static void process_modifyfile(const binresult *entry) {
|
|||
}
|
||||
}
|
||||
for (/*i is already=cnt*/; i < fres2->rows; i++) {
|
||||
psync_task_download_file_silent(
|
||||
ptask_download_q(
|
||||
psync_get_result_cell(fres2, i, 0), fileid,
|
||||
psync_get_result_cell(fres2, i, 1), name->str);
|
||||
needdownload = 1;
|
||||
}
|
||||
for (/*i is already=cnt*/; i < fres1->rows; i++) {
|
||||
char *path = psync_get_path_by_fileid(fileid, NULL);
|
||||
psync_task_delete_local_file_syncid(psync_get_result_cell(fres1, i, 0),
|
||||
ptask_lfile_rm_id(psync_get_result_cell(fres1, i, 0),
|
||||
fileid, path);
|
||||
psync_delete_download_tasks_for_file(
|
||||
fileid, psync_get_result_cell(fres1, i, 0), 1);
|
||||
|
|
@ -1622,7 +1622,7 @@ static void process_deletefile(const binresult *entry) {
|
|||
psync_delete_download_tasks_for_file(fileid, 0, 1);
|
||||
path = psync_get_path_by_fileid(fileid, NULL);
|
||||
if (likely(path)) {
|
||||
psync_task_delete_local_file(fileid, path);
|
||||
ptask_lfile_rm(fileid, path);
|
||||
psync_free(path);
|
||||
needdownload = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,9 +39,7 @@
|
|||
#include <mbedtls/sha1.h>
|
||||
#include <mbedtls/ssl.h>
|
||||
|
||||
|
||||
#include "papi.h"
|
||||
#include "pasyncnet.h"
|
||||
#include "pcallbacks.h"
|
||||
#include "pdownload.h"
|
||||
#include "pfolder.h"
|
||||
|
|
@ -56,7 +54,7 @@
|
|||
#include "psys.h"
|
||||
#include "pstatus.h"
|
||||
#include "psyncer.h"
|
||||
#include "ptasks.h"
|
||||
#include "ptask.h"
|
||||
#include "ptimer.h"
|
||||
#include "pupload.h"
|
||||
#include "putil.h"
|
||||
|
|
@ -973,7 +971,7 @@ static int task_rename_file(psync_syncid_t oldsyncid, psync_syncid_t newsyncid,
|
|||
}
|
||||
psync_sql_free_result(res);
|
||||
if (unlikely_log(!lfileid)) {
|
||||
psync_task_download_file(newsyncid, fileid, newlocalfolderid, newname);
|
||||
ptask_download(newsyncid, fileid, newlocalfolderid, newname);
|
||||
return 0;
|
||||
}
|
||||
newfolder =
|
||||
|
|
@ -993,7 +991,7 @@ static int task_rename_file(psync_syncid_t oldsyncid, psync_syncid_t newsyncid,
|
|||
if (errno == ENOENT) {
|
||||
debug(D_WARNING, "renamed from %s to %s failed, downloading", oldpath,
|
||||
newpath);
|
||||
psync_task_download_file(newsyncid, fileid, newlocalfolderid, newname);
|
||||
ptask_download(newsyncid, fileid, newlocalfolderid, newname);
|
||||
} else
|
||||
ret = -1;
|
||||
} else {
|
||||
|
|
@ -1315,11 +1313,11 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid,
|
|||
set_task_inprogress(taskid, 1);
|
||||
if (size <= PSYNC_MAX_SIZE_FOR_ASYNC_DOWNLOAD) {
|
||||
if (dt->localexists)
|
||||
ret = psync_async_download_file_if_changed(
|
||||
ret = ptask_download_needed_async(
|
||||
fileid, dt->tmpname, dt->localsize, dt->checksum,
|
||||
finish_async_download_existing, dt);
|
||||
else
|
||||
ret = psync_async_download_file(fileid, dt->tmpname,
|
||||
ret = ptask_download_async(fileid, dt->tmpname,
|
||||
finish_async_download, dt);
|
||||
if (ret) {
|
||||
debug(D_WARNING, "async download start failed for %s", dt->localname);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
#include "pssl.h"
|
||||
#include "pstatus.h"
|
||||
#include "psys.h"
|
||||
#include "ptasks.h"
|
||||
#include "ptask.h"
|
||||
#include "ptimer.h"
|
||||
#include "pupload.h"
|
||||
#include "ppath.h"
|
||||
|
|
@ -657,7 +657,7 @@ static void scan_rename_file(sync_folderlist *rnfr, sync_folderlist *rnto) {
|
|||
psync_sql_bind_string(res, 3, rnto->name);
|
||||
psync_sql_bind_uint(res, 4, rnfr->localid);
|
||||
psync_sql_run_free(res);
|
||||
psync_task_rename_remote_file(rnfr->syncid, rnto->syncid, rnfr->localid,
|
||||
ptask_rfile_rename(rnfr->syncid, rnto->syncid, rnfr->localid,
|
||||
rnto->localparentfolderid, rnto->name);
|
||||
if (filetoupload) {
|
||||
psync_path_status_sync_folder_task_added_locked(rnto->syncid,
|
||||
|
|
@ -690,7 +690,7 @@ static void scan_upload_file(sync_folderlist *fl) {
|
|||
if (unlikely_log(!psync_sql_affected_rows()))
|
||||
return;
|
||||
localfileid = psync_sql_insertid();
|
||||
psync_task_upload_file_silent(fl->syncid, localfileid, fl->name);
|
||||
ptask_upload_q(fl->syncid, localfileid, fl->name);
|
||||
psync_path_status_sync_folder_task_added(fl->syncid, fl->localparentfolderid);
|
||||
}
|
||||
|
||||
|
|
@ -707,7 +707,7 @@ static void scan_upload_modified_file(sync_folderlist *fl) {
|
|||
psync_sql_bind_uint(res, 4, fl->mtimenat);
|
||||
psync_sql_bind_uint(res, 5, fl->localid);
|
||||
psync_sql_run_free(res);
|
||||
psync_task_upload_file_silent(fl->syncid, fl->localid, fl->name);
|
||||
ptask_upload_q(fl->syncid, fl->localid, fl->name);
|
||||
psync_path_status_sync_folder_task_added(fl->syncid, fl->localparentfolderid);
|
||||
}
|
||||
|
||||
|
|
@ -737,7 +737,7 @@ static void scan_delete_file(sync_folderlist *fl) {
|
|||
psync_sql_bind_uint(res, 1, fl->localid);
|
||||
psync_sql_run_free(res);
|
||||
if (fileid)
|
||||
psync_task_delete_remote_file(fl->syncid, fileid);
|
||||
ptask_rfile_rm(fl->syncid, fileid);
|
||||
psync_path_status_sync_folder_task_completed(syncid, localparentfolderid);
|
||||
}
|
||||
|
||||
|
|
@ -796,7 +796,7 @@ static void scan_create_folder(sync_folderlist *fl) {
|
|||
psync_sql_run_free(res);
|
||||
if (unlikely_log(!psync_sql_affected_rows()))
|
||||
return;
|
||||
psync_task_create_remote_folder(fl->syncid, localfolderid, fl->name);
|
||||
ptask_rdir_mk(fl->syncid, localfolderid, fl->name);
|
||||
return;
|
||||
hasfolder:
|
||||
return;
|
||||
|
|
@ -879,7 +879,7 @@ static void scan_rename_folder(sync_folderlist *rnfr, sync_folderlist *rnto) {
|
|||
(unsigned)rnfr->syncid, (unsigned)rnto->syncid);
|
||||
update_syncid_rec(rnfr->localid, rnto->syncid);
|
||||
}
|
||||
psync_task_rename_remote_folder(rnfr->syncid, rnto->syncid, rnfr->localid,
|
||||
ptask_rdir_rename(rnfr->syncid, rnto->syncid, rnfr->localid,
|
||||
rnto->localparentfolderid, rnto->name);
|
||||
}
|
||||
|
||||
|
|
@ -952,7 +952,7 @@ retry:
|
|||
}
|
||||
delete_local_folder_rec(fl->localid);
|
||||
if (folderid)
|
||||
psync_task_delete_remote_folder(fl->syncid, folderid);
|
||||
ptask_rdir_rm(fl->syncid, folderid);
|
||||
}
|
||||
|
||||
#define check_for_query_cnt() \
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
#include "plist.h"
|
||||
#include "ppathstatus.h"
|
||||
#include "pstatus.h"
|
||||
#include "ptasks.h"
|
||||
#include "ptask.h"
|
||||
#include "ptree.h"
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
#include "plibs.h"
|
||||
#include "prunratelimit.h"
|
||||
#include "psettings.h"
|
||||
#include "ptasks.h"
|
||||
#include "ptask.h"
|
||||
#include "putil.h"
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
#include "prun.h"
|
||||
#include "pstatus.h"
|
||||
#include "psyncer.h"
|
||||
#include "ptasks.h"
|
||||
#include "ptask.h"
|
||||
#include "ptree.h"
|
||||
#include "putil.h"
|
||||
#include <string.h>
|
||||
|
|
@ -275,7 +275,7 @@ void psync_add_folder_for_downloadsync(psync_syncid_t syncid,
|
|||
cfolderid = psync_get_number(row[0]);
|
||||
clfolderid =
|
||||
psync_create_local_folder_in_db(syncid, cfolderid, lfoiderid, name);
|
||||
psync_task_create_local_folder(syncid, cfolderid, clfolderid);
|
||||
ptask_ldir_mk(syncid, cfolderid, clfolderid);
|
||||
psync_add_folder_for_downloadsync(syncid, synctype, cfolderid,
|
||||
clfolderid /*, path*/);
|
||||
}
|
||||
|
|
@ -287,7 +287,7 @@ void psync_add_folder_for_downloadsync(psync_syncid_t syncid,
|
|||
name = psync_get_string(row[1]);
|
||||
if (psync_is_name_to_ignore(name))
|
||||
continue;
|
||||
psync_task_download_file_silent(syncid, psync_get_number(row[0]), lfoiderid,
|
||||
ptask_download_q(syncid, psync_get_number(row[0]), lfoiderid,
|
||||
name);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
|
|
|
|||
|
|
@ -31,28 +31,27 @@
|
|||
|
||||
#include <ctype.h>
|
||||
#include <execinfo.h>
|
||||
#include <pthread.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
#include <mbedtls/debug.h>
|
||||
#include <mbedtls/entropy.h>
|
||||
#include <mbedtls/pkcs5.h>
|
||||
#include <mbedtls/ssl.h>
|
||||
#include <pthread.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "papi.h"
|
||||
#include "pasyncnet.h"
|
||||
#include "pbusinessaccount.h"
|
||||
#include "pcache.h"
|
||||
#include "pcallbacks.h"
|
||||
#include "pcloudcrypto.h"
|
||||
#include "pfile.h"
|
||||
#include "pcontacts.h"
|
||||
#include "pdevice.h"
|
||||
#include "pdevice_monitor.h"
|
||||
#include "pdiff.h"
|
||||
#include "ppath.h"
|
||||
#include "pdownload.h"
|
||||
#include "psys.h"
|
||||
#include "pfile.h"
|
||||
#include "pfileops.h"
|
||||
#include "pfolder.h"
|
||||
#include "pfsfolder.h"
|
||||
|
|
@ -63,12 +62,11 @@
|
|||
#include "pmemlock.h"
|
||||
#include "pnetlibs.h"
|
||||
#include "pnotifications.h"
|
||||
#include "putil.h"
|
||||
|
||||
#include "poverlay.h"
|
||||
#include "pp2p.h"
|
||||
#include "ppagecache.h"
|
||||
#include "ppassword.h"
|
||||
#include "ppath.h"
|
||||
#include "ppathstatus.h"
|
||||
#include "prun.h"
|
||||
#include "pscanner.h"
|
||||
|
|
@ -78,13 +76,14 @@
|
|||
#include "pstatus.h"
|
||||
#include "psyncer.h"
|
||||
#include "psynclib.h"
|
||||
#include "psys.h"
|
||||
#include "ptask.h"
|
||||
#include "ptimer.h"
|
||||
#include "ptools.h"
|
||||
#include "publiclinks.h"
|
||||
#include "pupload.h"
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "putil.h"
|
||||
|
||||
|
||||
#define BUGHUNT 0
|
||||
|
||||
|
|
@ -356,7 +355,7 @@ void psync_destroy() {
|
|||
psync_fs_stop();
|
||||
psync_terminate_status_waiters();
|
||||
psync_send_status_update();
|
||||
psync_async_stop();
|
||||
ptask_stop_async();
|
||||
psync_timer_wake();
|
||||
psync_timer_notify_exception();
|
||||
psync_sql_sync();
|
||||
|
|
@ -447,7 +446,7 @@ void psync_logout2(uint32_t auth_status, int doinvauth) {
|
|||
psync_fs_pause_until_login();
|
||||
psync_stop_all_download();
|
||||
psync_stop_all_upload();
|
||||
psync_async_stop();
|
||||
ptask_stop_async();
|
||||
psync_cache_clean_all();
|
||||
psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT);
|
||||
psync_restart_localscan();
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -32,18 +32,29 @@
|
|||
#ifndef _PSYNC_TASKS_H
|
||||
#define _PSYNC_TASKS_H
|
||||
|
||||
#include "pcompiler.h"
|
||||
#include "psynclib.h"
|
||||
|
||||
#define PSYNC_ASYNC_ERR_FLAG_PERM \
|
||||
0x01 // the error is permanent(ish) and there is no reason to retry
|
||||
#define PSYNC_ASYNC_ERR_FLAG_RETRY_AS_IS \
|
||||
0x02 // same request may succeed in the future if retried as is
|
||||
#define PSYNC_ASYNC_ERR_FLAG_SUCCESS \
|
||||
0x04 // like no action performed because of no need - file already exists and
|
||||
// so on
|
||||
|
||||
#define PSYNC_ASYNC_ERROR_NET 1
|
||||
#define PSYNC_ASYNC_ERROR_FILE 2
|
||||
#define PSYNC_ASYNC_ERROR_DISK_FULL 3
|
||||
#define PSYNC_ASYNC_ERROR_IO 4
|
||||
#define PSYNC_ASYNC_ERROR_CHECKSUM 5
|
||||
#define PSYNC_SERVER_ERROR_TOO_BIG 102
|
||||
#define PSYNC_SERVER_ERROR_NOT_MOD 104
|
||||
#define PSYNC_TASK_DOWNLOAD 0
|
||||
#define PSYNC_TASK_UPLOAD 1
|
||||
#define PSYNC_TASK_DWLUPL_MASK 1
|
||||
|
||||
#define PSYNC_TASK_FOLDER 0
|
||||
#define PSYNC_TASK_FILE 2
|
||||
|
||||
#define PSYNC_TASK_TYPE_OFF 2
|
||||
|
||||
#define PSYNC_TASK_TYPE_CREATE 0
|
||||
#define PSYNC_TASK_TYPE_DELETE 1
|
||||
#define PSYNC_TASK_TYPE_DELREC 2
|
||||
|
|
@ -94,65 +105,53 @@
|
|||
((PSYNC_TASK_TYPE_DELREC << PSYNC_TASK_TYPE_OFF) + PSYNC_TASK_FOLDER + \
|
||||
PSYNC_TASK_UPLOAD)
|
||||
|
||||
void psync_task_create_local_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid,
|
||||
psync_folderid_t localfolderid);
|
||||
void psync_task_delete_local_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid,
|
||||
psync_folderid_t localfolderid,
|
||||
const char *remotepath);
|
||||
void psync_task_delete_local_folder_recursive(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid,
|
||||
psync_folderid_t localfolderid);
|
||||
void psync_task_rename_local_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid,
|
||||
psync_folderid_t localfolderid,
|
||||
psync_folderid_t newlocalparentfolderid,
|
||||
const char *newname);
|
||||
void psync_task_download_file(psync_syncid_t syncid, psync_fileid_t fileid,
|
||||
psync_folderid_t localfolderid, const char *name);
|
||||
void psync_task_download_file_silent(psync_syncid_t syncid,
|
||||
psync_fileid_t fileid,
|
||||
psync_folderid_t localfolderid,
|
||||
const char *name);
|
||||
void psync_task_rename_local_file(psync_syncid_t oldsyncid,
|
||||
psync_syncid_t newsyncid,
|
||||
psync_fileid_t fileid,
|
||||
psync_folderid_t oldlocalfolderid,
|
||||
psync_folderid_t newlocalfolderid,
|
||||
const char *newname);
|
||||
void psync_task_delete_local_file(psync_fileid_t fileid,
|
||||
const char *remotepath);
|
||||
void psync_task_delete_local_file_syncid(psync_syncid_t syncid,
|
||||
psync_fileid_t fileid,
|
||||
const char *remotepath);
|
||||
typedef struct {
|
||||
uint64_t size;
|
||||
uint64_t hash;
|
||||
unsigned char sha1hex[40];
|
||||
} psync_async_file_result_t;
|
||||
|
||||
void psync_task_create_remote_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t localfolderid,
|
||||
const char *name);
|
||||
void psync_task_upload_file(psync_syncid_t syncid, psync_fileid_t localfileid,
|
||||
const char *name);
|
||||
void psync_task_upload_file_silent(psync_syncid_t syncid,
|
||||
psync_fileid_t localfileid,
|
||||
const char *name);
|
||||
typedef struct {
|
||||
uint32_t error;
|
||||
uint32_t errorflags;
|
||||
union {
|
||||
psync_async_file_result_t file;
|
||||
};
|
||||
} psync_async_result_t;
|
||||
|
||||
/* newname should be passed here instead of reading it from localfile in time of
|
||||
* renaming as there might be many pending renames and filename conflict is
|
||||
* possible
|
||||
typedef void (*psync_async_callback_t)(void *, psync_async_result_t *);
|
||||
|
||||
|
||||
/* Important! The interface typically expect all passed pointers to be alive
|
||||
* until the completion callback is called.
|
||||
*/
|
||||
void psync_task_rename_remote_file(psync_syncid_t oldsyncid,
|
||||
psync_syncid_t newsyncid,
|
||||
psync_fileid_t localfileid,
|
||||
psync_folderid_t newlocalparentfolderid,
|
||||
const char *newname);
|
||||
void psync_task_rename_remote_folder(psync_syncid_t oldsyncid,
|
||||
psync_syncid_t newsyncid,
|
||||
psync_fileid_t localfileid,
|
||||
psync_folderid_t newlocalparentfolderid,
|
||||
const char *newname);
|
||||
void psync_task_delete_remote_file(psync_syncid_t syncid,
|
||||
psync_fileid_t fileid);
|
||||
void psync_task_delete_remote_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid);
|
||||
void ptask_stop_async();
|
||||
int ptask_download_async(psync_fileid_t fileid, const char *localpath, psync_async_callback_t cb, void *cbext);
|
||||
int ptask_download_needed_async(psync_fileid_t fileid, const char *localpath, uint64_t size, const void *sha1hex, psync_async_callback_t cb, void *cbext);
|
||||
|
||||
// local ops
|
||||
void ptask_ldir_mk(psync_syncid_t syncid, psync_folderid_t folderid, psync_folderid_t localfolderid);
|
||||
void ptask_ldir_rename(psync_syncid_t syncid, psync_folderid_t folderid, psync_folderid_t localfolderid, psync_folderid_t newlocalparentfolderid, const char *newname);
|
||||
void ptask_ldir_rm(psync_syncid_t syncid, psync_folderid_t folderid, psync_folderid_t localfolderid, const char *remotepath);
|
||||
void ptask_ldir_rm_r(psync_syncid_t syncid, psync_folderid_t folderid, psync_folderid_t localfolderid);
|
||||
void ptask_lfile_rename(psync_syncid_t oldsyncid, psync_syncid_t newsyncid, psync_fileid_t fileid, psync_folderid_t oldlocalfolderid, psync_folderid_t newlocalfolderid, const char *newname);
|
||||
void ptask_lfile_rm(psync_fileid_t fileid, const char *remotepath);
|
||||
void ptask_lfile_rm_id(psync_syncid_t syncid, psync_fileid_t fileid, const char *remotepath);
|
||||
|
||||
// remote ops
|
||||
//
|
||||
// for rename operations, "newname" should be passed here instead of reading
|
||||
// it from localfile, to avoid conflict due to many pending renames
|
||||
void ptask_rdir_mk(psync_syncid_t syncid, psync_folderid_t localfolderid, const char *name);
|
||||
void ptask_rdir_rename(psync_syncid_t oldsyncid, psync_syncid_t newsyncid, psync_fileid_t localfileid, psync_folderid_t newlocalparentfolderid, const char *newname);
|
||||
void ptask_rdir_rm(psync_syncid_t syncid, psync_folderid_t folderid);
|
||||
void ptask_rfile_rename(psync_syncid_t oldsyncid, psync_syncid_t newsyncid, psync_fileid_t localfileid, psync_folderid_t newlocalparentfolderid, const char *newname);
|
||||
void ptask_rfile_rm(psync_syncid_t syncid, psync_fileid_t fileid);
|
||||
|
||||
// file transfer
|
||||
void ptask_download(psync_syncid_t syncid, psync_fileid_t fileid, psync_folderid_t localfolderid, const char *name);
|
||||
void ptask_download_q(psync_syncid_t syncid, psync_fileid_t fileid, psync_folderid_t localfolderid, const char *name);
|
||||
void ptask_upload(psync_syncid_t syncid, psync_fileid_t localfileid, const char *name);
|
||||
void ptask_upload_q(psync_syncid_t syncid, psync_fileid_t localfileid, const char *name);
|
||||
|
||||
#endif
|
||||
271
pclsync/ptasks.c
271
pclsync/ptasks.c
|
|
@ -1,271 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2013-2014 Anton Titov.
|
||||
|
||||
Copyright (c) 2013-2014 pCloud Ltd. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met: Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer. Redistributions in binary form must reproduce the
|
||||
above copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution. Neither the name of pCloud Ltd nor the
|
||||
names of its contributors may be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL pCloud
|
||||
Ltd BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGE.
|
||||
*/
|
||||
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
#include <mbedtls/debug.h>
|
||||
#include <mbedtls/entropy.h>
|
||||
#include <mbedtls/pkcs5.h>
|
||||
#include <mbedtls/ssl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "pcallbacks.h"
|
||||
#include "pdownload.h"
|
||||
#include "plibs.h"
|
||||
#include "ppathstatus.h"
|
||||
#include "pstatus.h"
|
||||
#include "ptasks.h"
|
||||
#include "pupload.h"
|
||||
|
||||
static void create_task1(unsigned long type, psync_syncid_t syncid,
|
||||
uint64_t entryid, uint64_t localentryid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid) VALUES (?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, type);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, entryid);
|
||||
psync_sql_bind_uint(res, 4, localentryid);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
static void create_task2(unsigned long type, psync_syncid_t syncid,
|
||||
uint64_t entryid, uint64_t localentryid,
|
||||
uint64_t newitemid, const char *name) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
"INSERT INTO task (type, syncid, itemid, localitemid, newitemid, name) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, type);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, entryid);
|
||||
psync_sql_bind_uint(res, 4, localentryid);
|
||||
psync_sql_bind_uint(res, 5, newitemid);
|
||||
psync_sql_bind_string(res, 6, name);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
static void create_task3(unsigned long type, psync_syncid_t syncid,
|
||||
uint64_t entryid, uint64_t localentryid,
|
||||
const char *name) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid, name) VALUES (?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, type);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, entryid);
|
||||
psync_sql_bind_uint(res, 4, localentryid);
|
||||
psync_sql_bind_string(res, 5, name);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
static void create_task4(unsigned long type, uint64_t entryid,
|
||||
const char *name) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
"INSERT INTO task (type, itemid, localitemid, name) VALUES (?, ?, 0, ?)");
|
||||
psync_sql_bind_uint(res, 1, type);
|
||||
psync_sql_bind_uint(res, 2, entryid);
|
||||
psync_sql_bind_string(res, 3, name);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
static void create_task5(unsigned long type, psync_syncid_t syncid,
|
||||
uint64_t entryid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid) VALUES (?, ?, ?, 0)");
|
||||
psync_sql_bind_uint(res, 1, type);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, entryid);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
static void create_task6(unsigned long type, psync_syncid_t syncid,
|
||||
uint64_t entryid, const char *name) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid, name) VALUES (?, ?, ?, 0, ?)");
|
||||
psync_sql_bind_uint(res, 1, type);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, entryid);
|
||||
psync_sql_bind_string(res, 4, name);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
void psync_task_create_local_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid,
|
||||
psync_folderid_t localfolderid) {
|
||||
create_task1(PSYNC_CREATE_LOCAL_FOLDER, syncid, folderid, localfolderid);
|
||||
}
|
||||
|
||||
void psync_task_delete_local_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid,
|
||||
psync_folderid_t localfolderid,
|
||||
const char *remotepath) {
|
||||
create_task3(PSYNC_DELETE_LOCAL_FOLDER, syncid, folderid, localfolderid,
|
||||
remotepath);
|
||||
}
|
||||
|
||||
void psync_task_delete_local_folder_recursive(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid,
|
||||
psync_folderid_t localfolderid) {
|
||||
create_task1(PSYNC_DELREC_LOCAL_FOLDER, syncid, folderid, localfolderid);
|
||||
}
|
||||
|
||||
void psync_task_rename_local_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid,
|
||||
psync_folderid_t localfolderid,
|
||||
psync_folderid_t newlocalparentfolderid,
|
||||
const char *newname) {
|
||||
create_task2(PSYNC_RENAME_LOCAL_FOLDER, syncid, folderid, localfolderid,
|
||||
newlocalparentfolderid, newname);
|
||||
}
|
||||
|
||||
void psync_task_download_file_silent(psync_syncid_t syncid,
|
||||
psync_fileid_t fileid,
|
||||
psync_folderid_t localfolderid,
|
||||
const char *name) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid, name) VALUES (?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, fileid);
|
||||
psync_sql_bind_uint(res, 4, localfolderid);
|
||||
psync_sql_bind_string(res, 5, name);
|
||||
psync_path_status_sync_folder_task_added_locked(syncid, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
void psync_task_download_file(psync_syncid_t syncid, psync_fileid_t fileid,
|
||||
psync_folderid_t localfolderid,
|
||||
const char *name) {
|
||||
psync_task_download_file_silent(syncid, fileid, localfolderid, name);
|
||||
psync_wake_download();
|
||||
psync_status_recalc_to_download();
|
||||
psync_send_status_update();
|
||||
}
|
||||
|
||||
void psync_task_rename_local_file(psync_syncid_t oldsyncid,
|
||||
psync_syncid_t newsyncid,
|
||||
psync_fileid_t fileid,
|
||||
psync_folderid_t oldlocalfolderid,
|
||||
psync_folderid_t newlocalfolderid,
|
||||
const char *newname) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
"INSERT INTO task (type, syncid, newsyncid, itemid, localitemid, "
|
||||
"newitemid, name) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_RENAME_LOCAL_FILE);
|
||||
psync_sql_bind_uint(res, 2, oldsyncid);
|
||||
psync_sql_bind_uint(res, 3, newsyncid);
|
||||
psync_sql_bind_uint(res, 4, fileid);
|
||||
psync_sql_bind_uint(res, 5, oldlocalfolderid);
|
||||
psync_sql_bind_uint(res, 6, newlocalfolderid);
|
||||
psync_sql_bind_string(res, 7, newname);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
void psync_task_delete_local_file(psync_fileid_t fileid,
|
||||
const char *remotepath) {
|
||||
create_task4(PSYNC_DELETE_LOCAL_FILE, fileid, remotepath);
|
||||
}
|
||||
|
||||
void psync_task_delete_local_file_syncid(psync_syncid_t syncid,
|
||||
psync_fileid_t fileid,
|
||||
const char *remotepath) {
|
||||
create_task6(PSYNC_DELETE_LOCAL_FILE, syncid, fileid, remotepath);
|
||||
}
|
||||
|
||||
void psync_task_create_remote_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t localfolderid,
|
||||
const char *name) {
|
||||
create_task3(PSYNC_CREATE_REMOTE_FOLDER, syncid, 0, localfolderid, name);
|
||||
}
|
||||
|
||||
void psync_task_upload_file_silent(psync_syncid_t syncid,
|
||||
psync_fileid_t localfileid,
|
||||
const char *name) {
|
||||
create_task3(PSYNC_UPLOAD_FILE, syncid, 0, localfileid, name);
|
||||
}
|
||||
|
||||
void psync_task_upload_file(psync_syncid_t syncid, psync_fileid_t localfileid,
|
||||
const char *name) {
|
||||
create_task3(PSYNC_UPLOAD_FILE, syncid, 0, localfileid, name);
|
||||
psync_wake_upload();
|
||||
psync_status_recalc_to_upload_async();
|
||||
}
|
||||
|
||||
void psync_task_rename_remote_file(psync_syncid_t oldsyncid,
|
||||
psync_syncid_t newsyncid,
|
||||
psync_fileid_t localfileid,
|
||||
psync_folderid_t newlocalparentfolderid,
|
||||
const char *newname) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
"INSERT INTO task (type, syncid, newsyncid, localitemid, newitemid, "
|
||||
"name, itemid) VALUES (?, ?, ?, ?, ?, ?, 0)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_RENAME_REMOTE_FILE);
|
||||
psync_sql_bind_uint(res, 2, oldsyncid);
|
||||
psync_sql_bind_uint(res, 3, newsyncid);
|
||||
psync_sql_bind_uint(res, 4, localfileid);
|
||||
psync_sql_bind_uint(res, 5, newlocalparentfolderid);
|
||||
psync_sql_bind_string(res, 6, newname);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
void psync_task_rename_remote_folder(psync_syncid_t oldsyncid,
|
||||
psync_syncid_t newsyncid,
|
||||
psync_fileid_t localfileid,
|
||||
psync_folderid_t newlocalparentfolderid,
|
||||
const char *newname) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
"INSERT INTO task (type, syncid, newsyncid, localitemid, newitemid, "
|
||||
"name, itemid) VALUES (?, ?, ?, ?, ?, ?, 0)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_RENAME_REMOTE_FOLDER);
|
||||
psync_sql_bind_uint(res, 2, oldsyncid);
|
||||
psync_sql_bind_uint(res, 3, newsyncid);
|
||||
psync_sql_bind_uint(res, 4, localfileid);
|
||||
psync_sql_bind_uint(res, 5, newlocalparentfolderid);
|
||||
psync_sql_bind_string(res, 6, newname);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
|
||||
void psync_task_delete_remote_file(psync_syncid_t syncid,
|
||||
psync_fileid_t fileid) {
|
||||
create_task5(PSYNC_DELETE_REMOTE_FILE, syncid, fileid);
|
||||
}
|
||||
|
||||
void psync_task_delete_remote_folder(psync_syncid_t syncid,
|
||||
psync_folderid_t folderid) {
|
||||
create_task5(PSYNC_DELREC_REMOTE_FOLDER, syncid, folderid);
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@
|
|||
#include "psettings.h"
|
||||
#include "psys.h"
|
||||
#include "pstatus.h"
|
||||
#include "ptasks.h"
|
||||
#include "ptask.h"
|
||||
#include "ptimer.h"
|
||||
#include "ptools.h"
|
||||
#include "pupload.h"
|
||||
|
|
|
|||
Loading…
Reference in New Issue