diff --git a/pclsync/pbusinessaccount.c b/pclsync/pbusinessaccount.c index 1b6e379..de9e538 100644 --- a/pclsync/pbusinessaccount.c +++ b/pclsync/pbusinessaccount.c @@ -27,7 +27,7 @@ #include "pbusinessaccount.h" #include "papi.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "plibs.h" #include "pnetlibs.h" #include "psys.h" @@ -745,7 +745,7 @@ static psync_folderid_t create_index_folder(const char *path) { snprintf(buff, bufflen - 1, "%s (%d)", path, ind); if (psync_create_remote_folder_by_path(buff, &err) != 0) debug(D_NOTICE, "Unable to create folder %s error is %s.", buff, err); - folderid = psync_get_folderid_by_path(buff); + folderid = pfolder_id(buff); if ((folderid != PSYNC_INVALID_FOLDERID) && check_write_permissions(folderid)) { psync_free(buff); @@ -759,7 +759,7 @@ static psync_folderid_t create_index_folder(const char *path) { return folderid; } psync_folderid_t psync_check_and_create_folder(const char *path) { - psync_folderid_t folderid = psync_get_folderid_by_path(path); + psync_folderid_t folderid = pfolder_id(path); char *err; if (folderid == PSYNC_INVALID_FOLDERID) { diff --git a/pclsync/pcryptofolder.c b/pclsync/pcryptofolder.c index a833352..efaaeda 100644 --- a/pclsync/pcryptofolder.c +++ b/pclsync/pcryptofolder.c @@ -43,7 +43,7 @@ #include "pcryptofolder.h" #include "pcrypto.h" #include "pfileops.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "pfs.h" #include "plibs.h" #include "pmemlock.h" diff --git a/pclsync/pdiff.c b/pclsync/pdiff.c index c760ead..c265bf6 100644 --- a/pclsync/pdiff.c +++ b/pclsync/pdiff.c @@ -49,7 +49,7 @@ #include "pdiff.h" #include "pdownload.h" #include "pfileops.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "pfs.h" #include "pfsxattr.h" #include "plibs.h" @@ -60,7 +60,7 @@ #include "psettings.h" #include "pstatus.h" #include "psynclib.h" -#include "psyncer.h" +#include "pfoldersync.h" #include "psys.h" #include "ptask.h" #include "ptimer.h" @@ -923,9 +923,9 @@ static void process_createfolder(const binresult *entry) { psync_sql_bind_uint(st2, 1, mtime); psync_sql_bind_uint(st2, 2, parentfolderid); psync_sql_run(st2); - if (psync_is_folder_in_downloadlist(parentfolderid) && + if (psyncer_dl_has_folder(parentfolderid) && !psync_is_name_to_ignore(name->str)) { - psync_add_folder_to_downloadlist(folderid); + psyncer_dl_queue_add(folderid); res = psync_sql_query( "SELECT syncid, localfolderid, synctype FROM syncedfolder WHERE " "folderid=? AND " PSYNC_SQL_DOWNLOAD); @@ -940,7 +940,7 @@ static void process_createfolder(const binresult *entry) { (unsigned long)row[1], name->str, (unsigned long)folderid, (unsigned long)parentfolderid); localfolderid = - psync_create_local_folder_in_db(syncid, folderid, row[1], name->str); + psyncer_db_folder_create(syncid, folderid, row[1], name->str); psync_sql_bind_uint(stmt, 1, syncid); psync_sql_bind_uint(stmt, 2, folderid); psync_sql_bind_uint(stmt, 3, localfolderid); @@ -1107,23 +1107,23 @@ static void process_modifyfolder(const binresult *entry) { * parentfolderid is not in and folderid is in, it means that folder that is a * "root" of a syncid is modified, we do not care about that. */ - oldsync = psync_is_folder_in_downloadlist(oldparentfolderid); + oldsync = psyncer_dl_has_folder(oldparentfolderid); if (oldparentfolderid == parentfolderid) newsync = oldsync; else { - newsync = psync_is_folder_in_downloadlist(parentfolderid); + newsync = psyncer_dl_has_folder(parentfolderid); psync_diff_refresh_fs_add_folder(oldparentfolderid); } if ((oldsync || newsync) && (oldparentfolderid != parentfolderid || strcmp(name->str, oldname))) { if (!oldsync) - psync_add_folder_to_downloadlist(folderid); + psyncer_dl_queue_add(folderid); else if (!newsync) { res = psync_sql_query( "SELECT id FROM syncfolder WHERE folderid=? AND " PSYNC_SQL_DOWNLOAD); psync_sql_bind_uint(res, 1, folderid); if (!psync_sql_fetch_rowint(res)) - psync_del_folder_from_downloadlist(folderid); + psyncer_dl_queue_del(folderid); psync_sql_free_result(res); } res = psync_sql_query( @@ -1195,10 +1195,10 @@ static void process_modifyfolder(const binresult *entry) { "creating local folder %lu/%s for folderid %lu, parentfolderid %lu", (unsigned long)psync_get_result_cell(fres2, i, 1), name->str, (unsigned long)folderid, (unsigned long)parentfolderid); - localfolderid = psync_create_local_folder_in_db( + localfolderid = psyncer_db_folder_create( syncid, folderid, psync_get_result_cell(fres2, i, 1), name->str); ptask_ldir_mk(syncid, folderid, localfolderid); - psync_add_folder_for_downloadsync( + psyncer_dl_folder_add( syncid, psync_get_result_cell(fres2, i, 2), folderid, localfolderid); needdownload = 1; } @@ -1238,8 +1238,8 @@ static void process_deletefolder(const binresult *entry) { meta = papi_find_result2(entry, "metadata", PARAM_HASH); folderid = papi_find_result2(meta, "folderid", PARAM_NUM)->num; psync_path_status_folder_deleted(folderid); - if (psync_is_folder_in_downloadlist(folderid)) { - psync_del_folder_from_downloadlist(folderid); + if (psyncer_dl_has_folder(folderid)) { + psyncer_dl_queue_del(folderid); res = psync_sql_query( "SELECT syncid, localfolderid FROM syncedfolder WHERE folderid=?"); psync_sql_bind_uint(res, 1, folderid); @@ -1250,7 +1250,7 @@ static void process_deletefolder(const binresult *entry) { psync_sql_bind_uint(stmt, 2, folderid); psync_sql_run_free(stmt); if (psync_sql_affected_rows() == 1) { - path = psync_get_path_by_folderid(folderid, NULL); + path = pfolder_path(folderid, NULL); ptask_ldir_rm(row[0], folderid, row[1], path); psync_free(path); needdownload = 1; @@ -1395,7 +1395,7 @@ static void process_createfile(const binresult *entry) { } insert_revision(fileid, hash, papi_find_result2(meta, "modified", PARAM_NUM)->num, size); - if (psync_is_folder_in_downloadlist(parentfolderid) && + if (psyncer_dl_has_folder(parentfolderid) && !psync_is_name_to_ignore(name->str)) { res = psync_sql_query("SELECT syncid, localfolderid FROM syncedfolder " "WHERE folderid=? AND " PSYNC_SQL_DOWNLOAD); @@ -1506,18 +1506,18 @@ static void process_modifyfile(const binresult *entry) { insert_revision(fileid, hash, papi_find_result2(meta, "modified", PARAM_NUM)->num, size); oldparentfolderid = psync_get_number(row[0]); - oldsync = psync_is_folder_in_downloadlist(oldparentfolderid); + oldsync = psyncer_dl_has_folder(oldparentfolderid); if (oldparentfolderid == parentfolderid) newsync = oldsync; else { - newsync = psync_is_folder_in_downloadlist(parentfolderid); + newsync = psyncer_dl_has_folder(parentfolderid); psync_diff_refresh_fs_add_folder(oldparentfolderid); } if (oldsync || newsync) { if (psync_is_name_to_ignore(name->str)) { char *path; pdownload_tasks_delete(fileid, 0, 1); - path = psync_get_path_by_fileid(fileid, NULL); + path = pfolder_file_path(fileid, NULL); ptask_lfile_rm(fileid, path); psync_free(path); needdownload = 1; @@ -1583,7 +1583,7 @@ static void process_modifyfile(const binresult *entry) { needdownload = 1; } for (/*i is already=cnt*/; i < fres1->rows; i++) { - char *path = psync_get_path_by_fileid(fileid, NULL); + char *path = pfolder_file_path(fileid, NULL); ptask_lfile_rm_id(psync_get_result_cell(fres1, i, 0), fileid, path); pdownload_tasks_delete( @@ -1615,10 +1615,10 @@ static void process_deletefile(const binresult *entry) { } meta = papi_find_result2(entry, "metadata", PARAM_HASH); fileid = papi_find_result2(meta, "fileid", PARAM_NUM)->num; - if (psync_is_folder_in_downloadlist( + if (psyncer_dl_has_folder( papi_find_result2(meta, "parentfolderid", PARAM_NUM)->num)) { pdownload_tasks_delete(fileid, 0, 1); - path = psync_get_path_by_fileid(fileid, NULL); + path = pfolder_file_path(fileid, NULL); if (likely(path)) { ptask_lfile_rm(fileid, path); psync_free(path); @@ -2641,7 +2641,7 @@ static void handle_exception(psock_t **sock, subscribed_ids *ids, *sock = get_connected_socket(); debug(D_NOTICE, "got new socket"); pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE); - psync_syncer_check_delayed_syncs(); + psyncer_check_delayed(); ids->diffid = psync_sql_cellint("SELECT value FROM setting WHERE id='diffid'", 0); send_diff_command(*sock, *ids); @@ -2659,7 +2659,7 @@ static void handle_exception(psock_t **sock, subscribed_ids *ids, *sock = get_connected_socket(); debug(D_NOTICE, "got new socket"); pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE); - psync_syncer_check_delayed_syncs(); + psyncer_check_delayed(); ids->diffid = psync_sql_cellint("SELECT value FROM setting WHERE id='diffid'", 0); send_diff_command(*sock, *ids); @@ -2674,7 +2674,7 @@ static void handle_exception(psock_t **sock, subscribed_ids *ids, pcache_clean_oneof(prefixes, ARRAY_SIZE(prefixes)); *sock = get_connected_socket(); pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE); - psync_syncer_check_delayed_syncs(); + psyncer_check_delayed(); send_diff_command(*sock, *ids); } else { debug(D_NOTICE, "diff socket seems to be alive"); @@ -2940,7 +2940,7 @@ restart: pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE); initialdownload = 0; psync_run_analyze_if_needed(); - psync_syncer_check_delayed_syncs(); + psyncer_check_delayed(); exceptionsock = setup_exeptions(); if (unlikely(exceptionsock == INVALID_SOCKET)) { debug(D_ERROR, "could not create pipe"); diff --git a/pclsync/pdownload.c b/pclsync/pdownload.c index 0f81df5..42ed3ad 100644 --- a/pclsync/pdownload.c +++ b/pclsync/pdownload.c @@ -34,7 +34,7 @@ #include "pqevent.h" #include "pdownload.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "plibs.h" #include "plocalscan.h" #include "pnetlibs.h" @@ -43,7 +43,7 @@ #include "prun.h" #include "psys.h" #include "pstatus.h" -#include "psyncer.h" +#include "pfoldersync.h" #include "ptask.h" #include "ptimer.h" #include "pupload.h" @@ -229,14 +229,14 @@ static int call_func_for_folder(psync_folderid_t localfolderid, const char *debug) { char *localpath; int res; - localpath = psync_local_path_for_local_folder(localfolderid, syncid, NULL); + localpath = pfolder_lpath_lfldr(localfolderid, syncid, NULL); if (likely(localpath)) { res = func(localpath); if (!res) { pqevent_queue_sync_event_id(event, syncid, localpath, folderid); if (updatemtime) update_local_folder_mtime(localpath, localfolderid); - psync_decrease_local_folder_taskcnt(localfolderid); + psyncer_folder_dec_tasks(localfolderid); debug(D_NOTICE, "%s %s", debug, localpath); } psync_free(localpath); @@ -256,14 +256,14 @@ static int call_func_for_folder_name(psync_folderid_t localfolderid, const char *debug) { char *localpath; int res; - localpath = psync_local_path_for_local_folder(localfolderid, syncid, NULL); + localpath = pfolder_lpath_lfldr(localfolderid, syncid, NULL); if (likely(localpath)) { res = func(localpath); if (!res) { pqevent_queue_sync_event_path(event, syncid, localpath, folderid, name); if (updatemtime) update_local_folder_mtime(localpath, localfolderid); - psync_decrease_local_folder_taskcnt(localfolderid); + psyncer_folder_dec_tasks(localfolderid); debug(D_NOTICE, "%s %s", debug, localpath); } psync_free(localpath); @@ -342,7 +342,7 @@ static int task_renamefolder(psync_syncid_t newsyncid, return 0; } psync_sql_free_result(res); - oldpath = psync_local_path_for_local_folder(localfolderid, oldsyncid, NULL); + oldpath = pfolder_lpath_lfldr(localfolderid, oldsyncid, NULL); if (unlikely(!oldpath)) { debug(D_ERROR, "could not get local path for folder id %lu", (unsigned long)localfolderid); @@ -369,7 +369,7 @@ static int task_renamefolder(psync_syncid_t newsyncid, psync_sql_bind_string(res, 3, newname); psync_sql_bind_uint(res, 4, localfolderid); psync_sql_run_free(res); - newpath = psync_local_path_for_local_folder(localfolderid, newsyncid, NULL); + newpath = pfolder_lpath_lfldr(localfolderid, newsyncid, NULL); if (unlikely(!newpath)) { psync_sql_rollback_transaction(); psync_free(oldpath); @@ -381,7 +381,7 @@ static int task_renamefolder(psync_syncid_t newsyncid, if (ret) psync_sql_rollback_transaction(); else { - psync_decrease_local_folder_taskcnt(localfolderid); + psyncer_folder_dec_tasks(localfolderid); psync_sql_commit_transaction(); pqevent_queue_sync_event_id(PEVENT_LOCAL_FOLDER_RENAMED, newsyncid, newpath, folderid); @@ -466,7 +466,7 @@ static int stat_and_create_local(psync_syncid_t syncid, psync_fileid_t fileid, sql = psync_sql_query_nolock("SELECT parentfolderid FROM file WHERE id=?"); psync_sql_bind_uint(sql, 1, fileid); row = psync_sql_fetch_rowint(sql); - if (!row || !psync_is_folder_in_downloadlist(row[0])) { + if (!row || !psyncer_dl_has_folder(row[0])) { psync_sql_free_result(sql); if (localfileid) { sql = psync_sql_prep_statement("DELETE FROM localfile WHERE id=?"); @@ -650,7 +650,7 @@ static int task_download_file(download_task_t *dt) { psync_sql_bind_lstring(sql, 2, (char *)serverhashhex, PSYNC_HASH_DIGEST_HEXLEN); while ((row = psync_sql_fetch_rowint(sql))) { - tmpold = psync_local_path_for_local_file(row[0], NULL); + tmpold = pfolder_lpath_lfile(row[0], NULL); if (unlikely_log(!tmpold)) continue; psync_sql_free_result(sql); @@ -900,7 +900,7 @@ static int task_delete_file(psync_syncid_t syncid, psync_fileid_t fileid, psync_sql_bind_uint(res, 1, fileid); psync_restart_localscan(); while ((row = psync_sql_fetch_rowint(res))) { - name = psync_local_path_for_local_file(row[0], NULL); + name = pfolder_lpath_lfile(row[0], NULL); if (likely_log(name)) { if (unlikely(pfile_delete(name))) { debug(D_WARNING, "error deleting local file %s error %d", name, @@ -964,10 +964,10 @@ static int task_rename_file(psync_syncid_t oldsyncid, psync_syncid_t newsyncid, return 0; } newfolder = - psync_local_path_for_local_folder(newlocalfolderid, newsyncid, NULL); + pfolder_lpath_lfldr(newlocalfolderid, newsyncid, NULL); if (unlikely_log(!newfolder)) return 0; - oldpath = psync_local_path_for_local_file(lfileid, NULL); + oldpath = pfolder_lpath_lfile(lfileid, NULL); if (unlikely_log(!oldpath)) { psync_free(newfolder); return 0; @@ -1191,7 +1191,7 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid, } else hastargetchecksum = 0; psync_sql_free_result(res); - localpath = psync_local_path_for_local_folder(localfolderid, syncid, NULL); + localpath = pfolder_lpath_lfldr(localfolderid, syncid, NULL); if (unlikely_log(!localpath)) return 0; localname = @@ -1378,7 +1378,7 @@ static int task_del_folder_rec(psync_folderid_t localfolderid, psync_sql_res *res; task_wait_no_downloads(); psync_stop_localscan(); - localpath = psync_local_path_for_local_folder(localfolderid, syncid, NULL); + localpath = pfolder_lpath_lfldr(localfolderid, syncid, NULL); if (unlikely_log(!localpath)) { psync_resume_localscan(); return 0; diff --git a/pclsync/pfileops.c b/pclsync/pfileops.c index 409ada7..2183cb1 100644 --- a/pclsync/pfileops.c +++ b/pclsync/pfileops.c @@ -31,7 +31,7 @@ #include "pfileops.h" #include "pdiff.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "plibs.h" void pfileops_create_fldr(const binresult *meta) { diff --git a/pclsync/pfolder.c b/pclsync/pfolder.c index 5fd1a7d..214bbfb 100644 --- a/pclsync/pfolder.c +++ b/pclsync/pfolder.c @@ -29,18 +29,13 @@ DAMAGE. */ -#include -#include -#include -#include -#include #include #include #include "papi.h" #include "pcryptofolder.h" #include "pdiff.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "pfsfolder.h" #include "plibs.h" #include "plist.h" @@ -50,23 +45,10 @@ #include #include + #define INITIAL_NAME_BUFF 2000 #define INITIAL_ENTRY_CNT 128 -typedef struct { - pentry_t *entries; - char *namebuff; - size_t nameoff; - size_t namealloc; - uint32_t entriescnt; - uint32_t entriesalloc; -} folder_list; - -typedef struct { - folder_list *folderlist; - psync_listtype_t listtype; -} flist_ltype; - typedef struct _string_list { psync_list list; char *str; @@ -81,7 +63,7 @@ static inline int psync_crypto_to_error(const void *ptr) { return -((int)(uintptr_t)ptr); } -psync_folderid_t psync_get_folderid_by_path(const char *path) { +psync_folderid_t pfolder_id(const char *path) { psync_folderid_t cfolderid; const char *sl; psync_sql_res *res; @@ -146,11 +128,11 @@ static psync_folderid_t wait_folder_id_in_db(psync_folderid_t folderid) { return PSYNC_INVALID_FOLDERID; } -psync_folderid_t psync_wait_folder_in_local_db(psync_folderid_t folderid) { +psync_folderid_t pfolder_db_wait(psync_folderid_t folderid) { return wait_folder_id_in_db(folderid); } -psync_folderid_t psync_get_folderid_by_path_or_create(const char *path) { +psync_folderid_t pfolder_id_create(const char *path) { psync_folderid_t cfolderid; const char *sl; psync_sql_res *res; @@ -374,7 +356,7 @@ char *psync_join_string_list(const char *sep, psync_list *lst, size_t *retlen) { return ret; } -char *psync_get_path_by_folderid(psync_folderid_t folderid, size_t *retlen) { +char *pfolder_path(psync_folderid_t folderid, size_t *retlen) { psync_list folderlist; char *ret; int res; @@ -397,7 +379,7 @@ char *psync_get_path_by_folderid(psync_folderid_t folderid, size_t *retlen) { return ret; } -char *psync_get_path_by_folderid_sep(psync_folderid_t folderid, const char *sep, +char *pfolder_path_sep(psync_folderid_t folderid, const char *sep, size_t *retlen) { psync_list folderlist; char *ret; @@ -419,7 +401,7 @@ char *psync_get_path_by_folderid_sep(psync_folderid_t folderid, const char *sep, return ret; } -char *psync_get_path_by_fileid(psync_fileid_t fileid, size_t *retlen) { +char *pfolder_file_path(psync_fileid_t fileid, size_t *retlen) { psync_list folderlist; char *ret; psync_sql_res *res; @@ -497,7 +479,7 @@ static int psync_add_local_path_to_list_by_localfolderid( return -1; } -char *psync_local_path_for_local_folder(psync_folderid_t localfolderid, +char *pfolder_lpath_lfldr(psync_folderid_t localfolderid, psync_syncid_t syncid, size_t *retlen) { psync_list folderlist; char *ret; @@ -516,7 +498,7 @@ char *psync_local_path_for_local_folder(psync_folderid_t localfolderid, return ret; } -char *psync_local_path_for_local_file(psync_fileid_t localfileid, +char *pfolder_lpath_lfile(psync_fileid_t localfileid, size_t *retlen) { psync_list folderlist; char *ret; @@ -616,7 +598,7 @@ static pfolder_list_t *folder_list_finalize(folder_list *list) { return ret; } -pfolder_list_t *psync_list_remote_folder(psync_folderid_t folderid, +pfolder_list_t *pfolder_remote_folders(psync_folderid_t folderid, psync_listtype_t listtype) { folder_list *list; psync_sql_res *res; @@ -724,7 +706,7 @@ static void add_to_folderlist(void *ptr, ppath_stat *stat) { } } -pfolder_list_t *psync_list_local_folder(const char *path, +pfolder_list_t *pfolder_local_folders(const char *path, psync_listtype_t listtype) { flist_ltype ft; ft.folderlist = folder_list_init(); @@ -736,7 +718,7 @@ pfolder_list_t *psync_list_local_folder(const char *path, return folder_list_finalize(ft.folderlist); } -pentry_t *psync_folder_stat_path(const char *remotepath) { +pentry_t *pfolder_stat(const char *remotepath) { psync_folderid_t folderid; psync_sql_res *res; psync_uint_row row; @@ -764,7 +746,7 @@ pentry_t *psync_folder_stat_path(const char *remotepath) { cremotepath = psync_new_cnt(char, len + 1); memcpy(cremotepath, remotepath, len + 1); cremotepath[len] = 0; - folderid = psync_get_folderid_by_path(cremotepath); + folderid = pfolder_id(cremotepath); psync_free(cremotepath); if (folderid == PSYNC_INVALID_FOLDERID) return NULL; @@ -819,7 +801,7 @@ typedef struct { psync_synctype_t synctype; } psync_tmp_folder_t; -psync_folder_list_t *psync_list_get_list(char *syncTypes) { +psync_folder_list_t *pfolder_sync_folders(char *syncTypes) { psync_sql_res *res; psync_variant_row row; psync_tmp_folder_t *folders; @@ -864,7 +846,7 @@ psync_folder_list_t *psync_list_get_list(char *syncTypes) { folders[lastfolder].localpath = str; folders[lastfolder].locallen = l; folderid = psync_get_number(row[1]); - str = psync_get_path_by_folderid(folderid, &l); + str = pfolder_path(folderid, &l); if (unlikely(!str)) { str = psync_strdup("/Invalid/Path"); l = strlen(str); diff --git a/pclsync/pfolder.h b/pclsync/pfolder.h deleted file mode 100644 index 1a2e9f8..0000000 --- a/pclsync/pfolder.h +++ /dev/null @@ -1,78 +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. -*/ - -#ifndef _PSYNC_FOLDER_H -#define _PSYNC_FOLDER_H - -#include "pcompiler.h" -#include "psynclib.h" - -#define PSYNC_INVALID_FOLDERID ((psync_folderid_t) - 1) -#define PSYNC_INVALID_PATH NULL - -#define PSYNC_FOLDER_FLAG_ENCRYPTED 1 -#define PSYNC_FOLDER_FLAG_INVISIBLE 2 -#define PSYNC_FOLDER_FLAG_PUBLIC_ROOT 4 -#define PSYNC_FOLDER_FLAG_BACKUP_DEVICE_LIST 8 -#define PSYNC_FOLDER_FLAG_BACKUP_DEVICE 16 -#define PSYNC_FOLDER_FLAG_BACKUP_ROOT 32 -#define PSYNC_FOLDER_FLAG_BACKUP 64 - -psync_folderid_t psync_get_folderid_by_path(const char *path) - PSYNC_NONNULL(1) PSYNC_PURE; -psync_folderid_t psync_get_folderid_by_path_or_create(const char *path) - PSYNC_NONNULL(1); -char *psync_get_path_by_folderid(psync_folderid_t folderid, size_t *retlen); -char *psync_get_path_by_folderid_sep(psync_folderid_t folderid, const char *sep, - size_t *retlen); -char *psync_get_path_by_fileid(psync_fileid_t fileid, size_t *retlen); -char *psync_local_path_for_local_folder(psync_folderid_t localfolderid, - psync_syncid_t syncid, size_t *retlen); -char *psync_local_path_for_local_file(psync_fileid_t localfileid, - size_t *retlen); -// char *psync_local_path_for_remote_folder(psync_folderid_t folderid, -// psync_syncid_t syncid, size_t *retlen); char -// *psync_local_path_for_remote_file(psync_fileid_t fileid, psync_syncid_t -// syncid, size_t *retlen); char -// *psync_local_path_for_remote_file_or_folder_by_name(psync_folderid_t -// parentfolderid, const char *filename, psync_syncid_t syncid, size_t *retlen); -pfolder_list_t *psync_list_remote_folder(psync_folderid_t folderid, - psync_listtype_t listtype); -pfolder_list_t *psync_list_local_folder(const char *path, - psync_listtype_t listtype) - PSYNC_NONNULL(1); -pentry_t *psync_folder_stat_path(const char *remotepath); - -psync_folder_list_t *psync_list_get_list(char *syncTypes); - -psync_folderid_t psync_wait_folder_in_local_db(psync_folderid_t folderid); - -#endif diff --git a/pclsync/pfoldersync.h b/pclsync/pfoldersync.h new file mode 100644 index 0000000..ecd9c2d --- /dev/null +++ b/pclsync/pfoldersync.h @@ -0,0 +1,161 @@ +/* + 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. +*/ + +// pfoldersync.h provides a unified interface for folder synchronization. + +#ifndef _PSYNC_FOLDERSYNC_H +#define _PSYNC_FOLDERSYNC_H + +#include "pcompiler.h" +#include "plist.h" + +#include +#include + +// folders API +#define PSYNC_INVALID_FOLDERID ((psync_folderid_t) - 1) +#define PSYNC_INVALID_PATH NULL + +#define PSYNC_FOLDER_FLAG_ENCRYPTED 1 +#define PSYNC_FOLDER_FLAG_INVISIBLE 2 +#define PSYNC_FOLDER_FLAG_PUBLIC_ROOT 4 +#define PSYNC_FOLDER_FLAG_BACKUP_DEVICE_LIST 8 +#define PSYNC_FOLDER_FLAG_BACKUP_DEVICE 16 +#define PSYNC_FOLDER_FLAG_BACKUP_ROOT 32 +#define PSYNC_FOLDER_FLAG_BACKUP 64 + +// limitation: path length of 255, plus null terminator. +#define PSYNC_MAX_PATH_LENGTH 256 + +typedef uint64_t psync_folderid_t; +typedef uint64_t psync_fileid_t; +typedef uint64_t psync_fileorfolderid_t; +typedef uint32_t psync_synctype_t; +typedef uint32_t psync_syncid_t; + +typedef struct { + psync_fileid_t fileid; + uint64_t size; +} pfile_t; + +typedef struct { + psync_folderid_t folderid; + uint8_t cansyncup; + uint8_t cansyncdown; + uint8_t canshare; + uint8_t isencrypted; +} pfolder_t; + +typedef struct { + const char *name; + union { + pfolder_t folder; + pfile_t file; + }; + uint16_t namelen; + uint8_t isfolder; +} pentry_t; + +typedef struct { + size_t entrycnt; + pentry_t entries[]; +} pfolder_list_t; + +typedef struct { + const char *localpath; + const char *name; + const char *description; +} psuggested_folder_t; + +typedef struct { + size_t entrycnt; + psuggested_folder_t entries[]; +} psuggested_folders_t; + +typedef struct { + pentry_t *entries; + char *namebuff; + size_t nameoff; + size_t namealloc; + uint32_t entriescnt; + uint32_t entriesalloc; +} folder_list; + +typedef struct { + folder_list *folderlist; + psync_listtype_t listtype; +} flist_ltype; + +typedef struct { + char localname[PSYNC_MAX_PATH_LENGTH]; + char localpath[PSYNC_MAX_PATH_LENGTH]; + char remotename[PSYNC_MAX_PATH_LENGTH]; + char remotepath[PSYNC_MAX_PATH_LENGTH]; + psync_folderid_t folderid; + psync_syncid_t syncid; + psync_synctype_t synctype; +} psync_folder_t; + +typedef struct { + size_t foldercnt; + psync_folder_t folders[]; +} psync_folder_list_t; + +// folder API (impl. pfolder.c) +psync_folderid_t pfolder_id(const char *path) PSYNC_NONNULL(1) PSYNC_PURE; +psync_folderid_t pfolder_id_create(const char *path) PSYNC_NONNULL(1); +char *pfolder_path(psync_folderid_t folderid, size_t *retlen); +char *pfolder_path_sep(psync_folderid_t folderid, const char *sep, size_t *retlen); +char *pfolder_file_path(psync_fileid_t fileid, size_t *retlen); +char *pfolder_lpath_lfldr(psync_folderid_t localfolderid, psync_syncid_t syncid, size_t *retlen); +char *pfolder_lpath_lfile(psync_fileid_t localfileid, size_t *retlen); +pfolder_list_t *pfolder_remote_folders(psync_folderid_t folderid, psync_listtype_t listtype); +pfolder_list_t *pfolder_local_folders(const char *path, psync_listtype_t listtype) PSYNC_NONNULL(1); +pentry_t *pfolder_stat(const char *remotepath); +psync_folder_list_t *pfolder_sync_folders(char *syncTypes); +psync_folderid_t pfolder_db_wait(psync_folderid_t folderid); + +// "syncer" API (impl. psync.c) +void psyncer_check_delayed(); +void psyncer_create(psync_syncid_t syncid); +psync_folderid_t psyncer_db_folder_create(psync_syncid_t syncid, psync_folderid_t folderid, psync_folderid_t localparentfolderid, const char *name); +void psyncer_dl_folder_add(psync_syncid_t syncid, psync_synctype_t synctype, psync_folderid_t folderid, psync_folderid_t lfoiderid); +int psyncer_dl_has_folder(psync_folderid_t folderid); +void psyncer_dl_queue_add(psync_folderid_t folderid); +void psyncer_dl_queue_clear(); +void psyncer_dl_queue_del(psync_folderid_t folderid); +void psyncer_folder_dec_tasks(psync_folderid_t lfolderid); +void psyncer_folder_inc_tasks(psync_folderid_t lfolderid); +void psyncer_init(); +int psyncer_str_has_prefix(const char *str1, const char *str2); +int psyncer_str_starts_with(const char *str1, const char *str2); + +#endif diff --git a/pclsync/pfs.c b/pclsync/pfs.c index 8b37f43..80efa82 100644 --- a/pclsync/pfs.c +++ b/pclsync/pfs.c @@ -39,7 +39,7 @@ #include "pcompiler.h" #include "pcryptofolder.h" #include "pfile.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "pfs.h" #include "pfscrypto.h" @@ -3364,7 +3364,7 @@ void psync_fs_refresh_folder(psync_folderid_t folderid) { int fd; path = - psync_get_path_by_folderid_sep(folderid, "/", NULL); + pfolder_path_sep(folderid, "/", NULL); if (path == PSYNC_INVALID_PATH) return; psync_ssl_rand_weak(rndbuff, sizeof(rndbuff)); @@ -3433,7 +3433,7 @@ char *psync_fs_get_path_by_folderid(psync_folderid_t folderid) { if (!mp || folderid == 0) return mp; path = - psync_get_path_by_folderid_sep(folderid, "/", NULL); + pfolder_path_sep(folderid, "/", NULL); if (path == PSYNC_INVALID_PATH) { psync_free(mp); return NULL; diff --git a/pclsync/pfsfolder.c b/pclsync/pfsfolder.c index 6f2c7a0..9270f48 100644 --- a/pclsync/pfsfolder.c +++ b/pclsync/pfsfolder.c @@ -37,7 +37,7 @@ #include #include "pcryptofolder.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "pfs.h" #include "pfsfolder.h" #include "pfstasks.h" diff --git a/pclsync/pfstasks.c b/pclsync/pfstasks.c index 160b64f..26d769a 100644 --- a/pclsync/pfstasks.c +++ b/pclsync/pfstasks.c @@ -44,7 +44,7 @@ #include "pcache.h" #include "pcryptofolder.h" #include "putil.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "pfs.h" #include "pfstasks.h" #include "pfsupload.h" diff --git a/pclsync/plist.h b/pclsync/plist.h index 5f85a47..3094ad6 100644 --- a/pclsync/plist.h +++ b/pclsync/plist.h @@ -34,6 +34,9 @@ #include "pcompiler.h" #include +#include + +typedef uint32_t psync_listtype_t; typedef struct _psync_list { struct _psync_list *next; diff --git a/pclsync/plocalscan.c b/pclsync/plocalscan.c index ddb9f9b..a5c61a5 100644 --- a/pclsync/plocalscan.c +++ b/pclsync/plocalscan.c @@ -39,7 +39,7 @@ #include "pdevice.h" #include "pfile.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "plibs.h" #include "prun.h" #include "plist.h" @@ -808,7 +808,7 @@ static void scan_created_folder(sync_folderlist *fl) { debug(D_WARNING, "local folder %s does not have localid", fl->name); return; } - localpath = psync_local_path_for_local_folder(fl->localid, fl->syncid, NULL); + localpath = pfolder_lpath_lfldr(fl->localid, fl->syncid, NULL); if (likely_log(localpath)) { debug(D_NOTICE, "scanning just created folder %s localid %lu name %s", localpath, (unsigned long)fl->localid, fl->name); diff --git a/pclsync/pp2p.c b/pclsync/pp2p.c index c0658b3..ad6b0c1 100644 --- a/pclsync/pp2p.c +++ b/pclsync/pp2p.c @@ -42,7 +42,7 @@ #include "pfile.h" #include "pcrypto.h" #include "pdownload.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "plibs.h" #include "pnetlibs.h" #include "pp2p.h" @@ -371,7 +371,7 @@ static void psync_p2p_tcphandler(void *ptr) { psync_free(binpubrsa); if (unlikely_log(pubrsa == PSYNC_INVALID_RSA)) goto err0; - localpath = psync_local_path_for_local_file(localfileid, NULL); + localpath = pfolder_lpath_lfile(localfileid, NULL); if (unlikely_log(!localpath)) goto err0; fd = pfile_open(localpath, O_RDONLY, 0); diff --git a/pclsync/ppathstatus.c b/pclsync/ppathstatus.c index 1b9dc81..8c7a899 100644 --- a/pclsync/ppathstatus.c +++ b/pclsync/ppathstatus.c @@ -37,7 +37,7 @@ #include #include "pcryptofolder.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "pfs.h" #include "plibs.h" #include "plist.h" diff --git a/pclsync/pqevent.c b/pclsync/pqevent.c index fda0c1f..f2481dc 100644 --- a/pclsync/pqevent.c +++ b/pclsync/pqevent.c @@ -28,7 +28,7 @@ */ #include "pqevent.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "plibs.h" #include "plist.h" #include "prun.h" @@ -354,9 +354,9 @@ void pqevent_queue_sync_event_id(psync_eventtype_t eventid, psync_syncid_t synci if (eventthreadrunning) { char *remotepath; if (eventid & PEVENT_TYPE_FOLDER) - remotepath = psync_get_path_by_folderid(remoteid, NULL); + remotepath = pfolder_path(remoteid, NULL); else - remotepath = psync_get_path_by_fileid(remoteid, NULL); + remotepath = pfolder_file_path(remoteid, NULL); if (unlikely_log(!remotepath)) return; pqevent_queue_sync_event_path(eventid, syncid, localpath, remoteid, remotepath); diff --git a/pclsync/psyncer.c b/pclsync/psyncer.c index 13a8f4c..fb4cd7d 100644 --- a/pclsync/psyncer.c +++ b/pclsync/psyncer.c @@ -39,14 +39,14 @@ #include "pdownload.h" #include "pfile.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "plibs.h" #include "plocalnotify.h" #include "plocalscan.h" #include "ppathstatus.h" #include "prun.h" #include "pstatus.h" -#include "psyncer.h" +#include "pfoldersync.h" #include "ptask.h" #include "ptree.h" #include "putil.h" @@ -103,13 +103,13 @@ static void psync_add_folder_to_downloadlist_locked(psync_folderid_t folderid) { } } -void psync_add_folder_to_downloadlist(psync_folderid_t folderid) { +void psyncer_dl_queue_add(psync_folderid_t folderid) { pthread_mutex_lock(&sync_down_mutex); psync_add_folder_to_downloadlist_locked(folderid); pthread_mutex_unlock(&sync_down_mutex); } -void psync_del_folder_from_downloadlist(psync_folderid_t folderid) { +void psyncer_dl_queue_del(psync_folderid_t folderid) { synced_down_folder *f; pthread_mutex_lock(&sync_down_mutex); f = psync_tree_element(synced_down_folders, synced_down_folder, tree); @@ -127,7 +127,7 @@ void psync_del_folder_from_downloadlist(psync_folderid_t folderid) { pthread_mutex_unlock(&sync_down_mutex); } -void psync_clear_downloadlist() { +void psyncer_dl_queue_clear() { pthread_mutex_lock(&sync_down_mutex); psync_tree_for_each_element_call_safe(synced_down_folders, synced_down_folder, tree, psync_free); @@ -135,7 +135,7 @@ void psync_clear_downloadlist() { pthread_mutex_unlock(&sync_down_mutex); } -int psync_is_folder_in_downloadlist(psync_folderid_t folderid) { +int psyncer_dl_has_folder(psync_folderid_t folderid) { synced_down_folder *f; pthread_mutex_lock(&sync_down_mutex); f = psync_tree_element(synced_down_folders, synced_down_folder, tree); @@ -151,7 +151,7 @@ int psync_is_folder_in_downloadlist(psync_folderid_t folderid) { return f != NULL; } -void psync_increase_local_folder_taskcnt(psync_folderid_t lfolderid) { +void psyncer_folder_inc_tasks(psync_folderid_t lfolderid) { psync_sql_res *res; res = psync_sql_prep_statement( "UPDATE localfolder SET taskcnt=taskcnt+1 WHERE id=?"); @@ -160,7 +160,7 @@ void psync_increase_local_folder_taskcnt(psync_folderid_t lfolderid) { assertw(psync_sql_affected_rows() == 1); } -void psync_decrease_local_folder_taskcnt(psync_folderid_t lfolderid) { +void psyncer_folder_dec_tasks(psync_folderid_t lfolderid) { psync_sql_res *res; res = psync_sql_prep_statement( "UPDATE localfolder SET taskcnt=taskcnt+1 WHERE id=?"); @@ -169,7 +169,7 @@ void psync_decrease_local_folder_taskcnt(psync_folderid_t lfolderid) { assertw(psync_sql_affected_rows() == 1); } -psync_folderid_t psync_create_local_folder_in_db( +psync_folderid_t psyncer_db_folder_create( psync_syncid_t syncid, psync_folderid_t folderid, psync_folderid_t localparentfolderid, const char *name) { psync_sql_res *res; @@ -241,12 +241,12 @@ psync_folderid_t psync_create_local_folder_in_db( psync_sql_bind_uint(res, 2, folderid); psync_sql_run_free(res); } - psync_increase_local_folder_taskcnt(lfolderid); + psyncer_folder_inc_tasks(lfolderid); psync_free(vname); return lfolderid; } -void psync_add_folder_for_downloadsync(psync_syncid_t syncid, +void psyncer_dl_folder_add(psync_syncid_t syncid, psync_synctype_t synctype, psync_folderid_t folderid, psync_folderid_t lfoiderid) { @@ -262,7 +262,7 @@ void psync_add_folder_for_downloadsync(psync_syncid_t syncid, psync_sql_bind_uint(res, 3, lfoiderid); psync_sql_bind_uint(res, 4, synctype); psync_sql_run_free(res); - psync_add_folder_to_downloadlist(folderid); + psyncer_dl_queue_add(folderid); res = psync_sql_query( "SELECT id, permissions, name FROM folder WHERE parentfolderid=?"); psync_sql_bind_uint(res, 1, folderid); @@ -273,9 +273,9 @@ void psync_add_folder_for_downloadsync(psync_syncid_t syncid, continue; cfolderid = psync_get_number(row[0]); clfolderid = - psync_create_local_folder_in_db(syncid, cfolderid, lfoiderid, name); + psyncer_db_folder_create(syncid, cfolderid, lfoiderid, name); ptask_ldir_mk(syncid, cfolderid, clfolderid); - psync_add_folder_for_downloadsync(syncid, synctype, cfolderid, + psyncer_dl_folder_add(syncid, synctype, cfolderid, clfolderid /*, path*/); } } @@ -314,7 +314,7 @@ static void psync_sync_newsyncedfolder(psync_syncid_t syncid) { psync_strndup(psync_get_string(row[2]), strlen(psync_get_string(row[2]))); psync_sql_free_result(res); if (synctype & PSYNC_DOWNLOAD_ONLY) { - psync_add_folder_for_downloadsync(syncid, synctype, folderid, 0); + psyncer_dl_folder_add(syncid, synctype, folderid, 0); } else { res = psync_sql_prep_statement( "REPLACE INTO syncedfolder (syncid, folderid, localfolderid, synctype) " @@ -350,7 +350,7 @@ static void psync_do_sync_thread(void *ptr) { psync_free(ptr); } -void psync_syncer_new(psync_syncid_t syncid) { +void psyncer_create(psync_syncid_t syncid) { psync_syncid_t *psid = psync_new(psync_syncid_t); *psid = syncid; prun_thread1("syncer", psync_do_sync_thread, psid); @@ -374,7 +374,7 @@ static void delete_delayed_sync(uint64_t id) { psync_sql_run_free(res); } -int psync_str_is_prefix(const char *str1, const char *str2) { +int psyncer_str_has_prefix(const char *str1, const char *str2) { size_t len1, len2; len1 = strlen(str1); len2 = strlen(str2); @@ -394,7 +394,7 @@ int psync_str_is_prefix(const char *str1, const char *str2) { return !memcmp(str1, str2, len1); } -int psync_left_str_is_prefix(const char *str1, const char *str2) { +int psyncer_str_starts_with(const char *str1, const char *str2) { size_t len1, len2; len1 = strlen(str1); len2 = strlen(str2); @@ -414,7 +414,7 @@ int psync_left_str_is_prefix(const char *str1, const char *str2) { return !memcmp(str1, str2, len1); } -void psync_syncer_check_delayed_syncs() { +void psyncer_check_delayed() { struct stat st; psync_sql_res *res, *res2, *stmt; psync_variant_row row; @@ -449,7 +449,7 @@ re: mbedtls_md = 0; res2 = psync_sql_query("SELECT localpath FROM syncfolder"); while ((srow = psync_sql_fetch_rowstr(res2))) - if (psync_str_is_prefix(srow[0], localpath)) { + if (psyncer_str_has_prefix(srow[0], localpath)) { debug( D_WARNING, "skipping localfolder %s, remote %s, because of same parent to %s", @@ -471,7 +471,7 @@ re: remotepath = psync_strdup(remotepath); psync_sql_free_result(res); - folderid = psync_get_folderid_by_path_or_create(remotepath); + folderid = pfolder_id_create(remotepath); if (unlikely(folderid == PSYNC_INVALID_FOLDERID)) { debug(D_WARNING, "could not get folderid/create folder %s", remotepath); psync_free(localpath); @@ -512,7 +512,7 @@ re: psync_free(remotepath); if (!psync_sql_commit_transaction() && syncid != -1) { psync_path_status_reload_syncs(); - psync_syncer_new(syncid); + psyncer_create(syncid); goto re; } return; @@ -520,7 +520,7 @@ re: psync_sql_free_result(res); } -void psync_syncer_init() { +void psyncer_init() { psync_sql_res *res; psync_uint_row row; res = psync_sql_query( diff --git a/pclsync/psyncer.h b/pclsync/psyncer.h deleted file mode 100644 index a7933b7..0000000 --- a/pclsync/psyncer.h +++ /dev/null @@ -1,60 +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. -*/ - -#ifndef _PSYNC_SYNCER_H -#define _PSYNC_SYNCER_H - -#include "psynclib.h" - -void psync_syncer_init(); -void psync_syncer_new(psync_syncid_t syncid); - -void psync_increase_local_folder_taskcnt(psync_folderid_t lfolderid); -void psync_decrease_local_folder_taskcnt(psync_folderid_t lfolderid); -psync_folderid_t psync_create_local_folder_in_db( - psync_syncid_t syncid, psync_folderid_t folderid, - psync_folderid_t localparentfolderid, const char *name); -void psync_add_folder_for_downloadsync(psync_syncid_t syncid, - psync_synctype_t synctype, - psync_folderid_t folderid, - psync_folderid_t lfoiderid); - -void psync_add_folder_to_downloadlist(psync_folderid_t folderid); -void psync_del_folder_from_downloadlist(psync_folderid_t folderid); -void psync_clear_downloadlist(); -int psync_is_folder_in_downloadlist(psync_folderid_t folderid); - -int psync_str_is_prefix(const char *str1, const char *str2); -void psync_syncer_check_delayed_syncs(); - -int psync_left_str_is_prefix(const char *str1, const char *str2); - -#endif diff --git a/pclsync/psynclib.c b/pclsync/psynclib.c index 65ac56d..cca955b 100644 --- a/pclsync/psynclib.c +++ b/pclsync/psynclib.c @@ -54,7 +54,7 @@ #include "pdownload.h" #include "pfile.h" #include "pfileops.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "pfsfolder.h" #include "plibs.h" #include "plist.h" @@ -75,7 +75,7 @@ #include "pshm.h" #include "pssl.h" #include "pstatus.h" -#include "psyncer.h" +#include "pfoldersync.h" #include "psynclib.h" #include "psys.h" #include "ptask.h" @@ -329,7 +329,7 @@ void psync_start_sync(pstatus_change_callback_t status_callback, pstatus_set_cb(status_callback); if (event_callback) pqevent_process(event_callback); - psync_syncer_init(); + psyncer_init(); pdiff_init(); psync_upload_init(); pdownload_init(); @@ -594,7 +594,7 @@ void psync_unlink() { psync_fs_pause_until_login(); psync_fs_clean_tasks(); psync_path_status_init(); - psync_clear_downloadlist(); + psyncer_dl_queue_clear(); psync_sql_unlock(); psync_sql_checkpoint_unlock(); psync_settings_reset(); @@ -739,7 +739,7 @@ void psync_tfa_set_code(const char *code, int trusted, int is_recovery) { psync_syncid_t psync_add_sync_by_path(const char *localpath, const char *remotepath, psync_synctype_t synctype) { - psync_folderid_t folderid = psync_get_folderid_by_path(remotepath); + psync_folderid_t folderid = pfolder_id(remotepath); if (likely_log(folderid != PSYNC_INVALID_FOLDERID)) return psync_add_sync_by_folderid(localpath, folderid, synctype); else @@ -787,7 +787,7 @@ psync_syncid_t psync_add_sync_by_folderid(const char *localpath, if (unlikely_log(!res)) return_isyncid(PERROR_DATABASE_ERROR); while ((srow = psync_sql_fetch_rowstr(res))) - if (psync_str_is_prefix(srow[0], localpath)) { + if (psyncer_str_has_prefix(srow[0], localpath)) { psync_sql_free_result(res); return_isyncid(PERROR_PARENT_OR_SUBFOLDER_ALREADY_SYNCING); } else if (!strcmp(srow[0], localpath)) { @@ -834,7 +834,7 @@ psync_syncid_t psync_add_sync_by_folderid(const char *localpath, return_isyncid(PERROR_FOLDER_ALREADY_SYNCING); psync_sql_sync(); psync_path_status_reload_syncs(); - psync_syncer_new(ret); + psyncer_create(ret); return ret; } @@ -864,7 +864,7 @@ int psync_add_sync_by_path_delayed(const char *localpath, psync_sql_run_free(res); psync_sql_sync(); if (pstatus_get(PSTATUS_TYPE_ONLINE) == PSTATUS_ONLINE_ONLINE) - prun_thread("check delayed syncs", psync_syncer_check_delayed_syncs); + prun_thread("check delayed syncs", psyncer_check_delayed); return 0; } @@ -942,7 +942,7 @@ int psync_change_synctype(psync_syncid_t syncid, psync_synctype_t synctype) { res = psync_sql_query("SELECT folderid FROM syncedfolder WHERE syncid=?"); psync_sql_bind_uint(res, 1, syncid); while ((urow = psync_sql_fetch_rowint(res))) - psync_del_folder_from_downloadlist(urow[0]); + psyncer_dl_queue_del(urow[0]); psync_sql_free_result(res); res = psync_sql_prep_statement("DELETE FROM syncedfolder WHERE syncid=?"); psync_sql_bind_uint(res, 1, syncid); @@ -961,7 +961,7 @@ int psync_change_synctype(psync_syncid_t syncid, psync_synctype_t synctype) { psync_stop_sync_upload(syncid); psync_sql_sync(); psync_path_status_reload_syncs(); - psync_syncer_new(syncid); + psyncer_create(syncid); return 0; } @@ -1020,7 +1020,7 @@ int psync_delete_sync(psync_syncid_t syncid) { } psync_folder_list_t *psync_get_sync_list() { - return psync_list_get_list(PSYNC_STR_ALLSYNCS); + return pfolder_sync_folders(PSYNC_STR_ALLSYNCS); } psuggested_folders_t *psync_get_sync_suggestions() { @@ -1039,14 +1039,14 @@ psuggested_folders_t *psync_get_sync_suggestions() { pfolder_list_t *psync_list_local_folder_by_path(const char *localpath, psync_listtype_t listtype) { - return psync_list_local_folder(localpath, listtype); + return pfolder_local_folders(localpath, listtype); } pfolder_list_t *psync_list_remote_folder_by_path(const char *remotepath, psync_listtype_t listtype) { - psync_folderid_t folderid = psync_get_folderid_by_path(remotepath); + psync_folderid_t folderid = pfolder_id(remotepath); if (folderid != PSYNC_INVALID_FOLDERID) - return psync_list_remote_folder(folderid, listtype); + return pfolder_remote_folders(folderid, listtype); else return NULL; } @@ -1054,11 +1054,11 @@ pfolder_list_t *psync_list_remote_folder_by_path(const char *remotepath, pfolder_list_t * psync_list_remote_folder_by_folderid(psync_folderid_t folderid, psync_listtype_t listtype) { - return psync_list_remote_folder(folderid, listtype); + return pfolder_remote_folders(folderid, listtype); } pentry_t *psync_stat_path(const char *remotepath) { - return psync_folder_stat_path(remotepath); + return pfolder_stat(remotepath); } int psync_is_lname_to_ignore(const char *name, size_t namelen) { @@ -2766,7 +2766,7 @@ int psync_is_folder_syncable(char *localPath, char **errMsg) { } while ((srow = psync_sql_fetch_rowstr(sql))) { - if (psync_str_is_prefix(srow[0], localPath)) { + if (psyncer_str_has_prefix(srow[0], localPath)) { psync_sql_free_result(sql); *errMsg = psync_strdup("There is already an active sync or backup for a " @@ -2810,7 +2810,7 @@ int psync_is_folder_syncable(char *localPath, char **errMsg) { debug(D_NOTICE, "Check ignored folder: [%s]=[%s]", folders.folders[i], localPath); - if (psync_left_str_is_prefix(folders.folders[i], localPath)) { + if (psyncer_str_starts_with(folders.folders[i], localPath)) { *errMsg = psync_strdup( "This folder is a child of a folder in your ignore folders list."); return PERROR_PARENT_IS_IGNORED; @@ -2823,7 +2823,7 @@ int psync_is_folder_syncable(char *localPath, char **errMsg) { psync_folder_list_t *psync_get_syncs_bytype(const char *syncType) { debug(D_NOTICE, "Get syncs type: [%s]", syncType); - return psync_list_get_list((char *)syncType); + return pfolder_sync_folders((char *)syncType); } psync_folderid_t create_bup_mach_folder(char **msgErr) { diff --git a/pclsync/psynclib.h b/pclsync/psynclib.h index fc8c2d7..d46f768 100644 --- a/pclsync/psynclib.h +++ b/pclsync/psynclib.h @@ -44,57 +44,13 @@ #include "paccountevents.h" #include "ptools.h" #include "pstatus.h" +#include "pfoldersync.h" -typedef uint64_t psync_folderid_t; -typedef uint64_t psync_fileid_t; -typedef uint64_t psync_fileorfolderid_t; typedef uint64_t psync_userid_t; typedef uint64_t psync_shareid_t; typedef uint64_t psync_sharerequestid_t; typedef uint64_t psync_teamid_t; -typedef uint32_t psync_syncid_t; typedef uint32_t psync_eventtype_t; -typedef uint32_t psync_synctype_t; -typedef uint32_t psync_listtype_t; - -typedef struct { - psync_fileid_t fileid; - uint64_t size; -} pfile_t; - -typedef struct { - psync_folderid_t folderid; - uint8_t cansyncup; - uint8_t cansyncdown; - uint8_t canshare; - uint8_t isencrypted; -} pfolder_t; - -typedef struct { - const char *name; - union { - pfolder_t folder; - pfile_t file; - }; - uint16_t namelen; - uint8_t isfolder; -} pentry_t; - -typedef struct { - size_t entrycnt; - pentry_t entries[]; -} pfolder_list_t; - -typedef struct { - const char *localpath; - const char *name; - const char *description; -} psuggested_folder_t; - -typedef struct { - size_t entrycnt; - psuggested_folder_t entries[]; -} psuggested_folders_t; typedef struct { const char *label; @@ -329,9 +285,6 @@ typedef struct { #define PSYNC_CRYPTO_STATUS_ACTIVE 4 #define PSYNC_CRYPTO_STATUS_SETUP 5 -// limitation: path length of 255, plus null terminator. -#define PSYNC_MAX_PATH_LENGTH 256 - #define PSYNC_CRYPTO_INVALID_FOLDERID ((psync_folderid_t) - 1) #define PSYNC_CRYPTO_FLAG_TEMP_PASS 1 @@ -352,20 +305,6 @@ typedef struct { // Backup errors end // Lib error codes end -typedef struct { - char localname[PSYNC_MAX_PATH_LENGTH]; - char localpath[PSYNC_MAX_PATH_LENGTH]; - char remotename[PSYNC_MAX_PATH_LENGTH]; - char remotepath[PSYNC_MAX_PATH_LENGTH]; - psync_folderid_t folderid; - psync_syncid_t syncid; - psync_synctype_t synctype; -} psync_folder_t; - -typedef struct { - size_t foldercnt; - psync_folder_t folders[]; -} psync_folder_list_t; typedef struct { psync_fileid_t fileid; @@ -1312,7 +1251,7 @@ int psync_upload_file_as(const char *remote_path, const char *remote_filename, * full path (including mountpoint) of a given folderid on the filesystem or * NULL if it is not mounted or folder could not be * found. You are supposed to free the returned pointer. - * psync_get_path_by_fileid() - returns path (without mountpoint) of a given + * pfolder_file_path() - returns path (without mountpoint) of a given * fileid on the filesystem or NULL if it is not mounted or parent folder could * not be found. You are supposed to free the returned pointer. * @@ -1342,7 +1281,6 @@ void psync_fs_stop(); char *psync_fs_getmountpoint(); void psync_fs_register_start_callback(psync_generic_callback_t callback); char *psync_fs_get_path_by_folderid(psync_folderid_t folderid); -char *psync_get_path_by_fileid(psync_fileid_t fileid, size_t *retlen); void psync_fs_clean_read_cache(); int psync_fs_move_cache(const char *path); diff --git a/pclsync/pupload.c b/pclsync/pupload.c index 4f51639..bddf545 100644 --- a/pclsync/pupload.c +++ b/pclsync/pupload.c @@ -43,7 +43,7 @@ #include "pcompiler.h" #include "pdiff.h" #include "pfileops.h" -#include "pfolder.h" +#include "pfoldersync.h" #include "plibs.h" #include "plist.h" #include "pnetlibs.h" @@ -500,7 +500,7 @@ static void set_local_file_conflicted(psync_fileid_t localfileid, psync_sql_bind_string(res, 1, newname); psync_sql_bind_uint(res, 2, taskid); psync_sql_run_free(res); - newpath = psync_local_path_for_local_file(localfileid, NULL); + newpath = pfolder_lpath_lfile(localfileid, NULL); if (unlikely_log(pfile_rename_overwrite(localpath, newpath))) psync_sql_rollback_transaction(); else @@ -1341,7 +1341,7 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid, pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses)); if (upload->stop) return -1; - localpath = psync_local_path_for_local_file(localfileid, NULL); + localpath = pfolder_lpath_lfile(localfileid, NULL); if (unlikely(!localpath)) { debug(D_WARNING, "could not find local file %s (id %lu)", name, (unsigned long)localfileid);