Skip to content

Commit 78ebda4

Browse files
author
Ivan Stoev
committed
Merge of master branch.
2 parents 3e3181e + a6ac7ab commit 78ebda4

File tree

13 files changed

+396
-66
lines changed

13 files changed

+396
-66
lines changed

pCloudCC/lib/pclsync/pbusinessaccount.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
#include "papi.h"
2929
#include "plibs.h"
3030
#include "pnetlibs.h"
31+
#include "pfolder.h"
3132

3233
#include <stdio.h>
34+
3335
typedef struct _email_vis_params {
3436
char** email;
3537
size_t *length;
@@ -611,3 +613,112 @@ int api_error_result(binresult* res) {
611613
}
612614
return 0;
613615
}
616+
617+
void psync_update_cryptostatus(){
618+
binresult *res;
619+
const binresult *cres;
620+
psync_sql_res *q;
621+
uint64_t u, crexp, crsub = 0, is_business = 0;
622+
int crst = 0,crstat;
623+
624+
binparam params[] = { P_STR("auth", psync_my_auth) };
625+
res = psync_api_run_command("userinfo", params);
626+
if (!res) {
627+
debug(D_WARNING, "Send command returned invalid result.\n");
628+
return;
629+
}
630+
631+
if (api_error_result(res))
632+
return;
633+
634+
q=psync_sql_prep_statement("REPLACE INTO setting (id, value) VALUES (?, ?)");
635+
636+
is_business=psync_find_result(res, "business", PARAM_BOOL)->num;
637+
638+
u=psync_find_result(res, "cryptosetup", PARAM_BOOL)->num;
639+
psync_sql_bind_string(q, 1, "cryptosetup");
640+
psync_sql_bind_uint(q, 2, u);
641+
psync_sql_run(q);
642+
if (u)
643+
crst = 1;
644+
psync_sql_bind_string(q, 1, "cryptosubscription");
645+
crsub = psync_find_result(res, "cryptosubscription", PARAM_BOOL)->num;
646+
psync_sql_bind_uint(q, 2, crsub);
647+
psync_sql_run(q);
648+
649+
cres=psync_check_result(res, "cryptoexpires", PARAM_NUM);
650+
crexp = cres?cres->num:0;
651+
psync_sql_bind_string(q, 1, "cryptoexpires");
652+
psync_sql_bind_uint(q, 2, crexp);
653+
psync_sql_run(q);
654+
655+
if (is_business || crsub){
656+
if (crst)
657+
crstat = 5;
658+
else crstat = 4;
659+
} else {
660+
if (!crst)
661+
crstat = 1;
662+
else
663+
{
664+
if (psync_time() > crexp)
665+
crstat = 3;
666+
else
667+
crstat = 2;
668+
}
669+
}
670+
psync_sql_bind_string(q, 1, "cryptostatus");
671+
psync_sql_bind_uint(q, 2, crstat);
672+
psync_sql_run(q);
673+
psync_sql_free_result(q);
674+
675+
676+
}
677+
678+
static int check_write_permissions (psync_folderid_t folderid) {
679+
psync_sql_res* res;
680+
psync_uint_row row;
681+
int ret = 0;
682+
683+
res=psync_sql_query("SELECT permissions, flags, name FROM folder WHERE id=?");
684+
psync_sql_bind_uint(res, 1, folderid);
685+
row=psync_sql_fetch_rowint(res);
686+
if (unlikely(!row))
687+
debug(D_ERROR, "could not find folder of folderid %lu", (unsigned long)folderid);
688+
else if (/*(((row[1]) & 3) != O_RDONLY) &&*/ ((row[0]&PSYNC_PERM_MODIFY)&&(row[0]&PSYNC_PERM_CREATE)))
689+
ret = 1;
690+
691+
psync_sql_free_result(res);
692+
return ret;
693+
}
694+
695+
psync_folderid_t psync_check_and_create_folder (const char * path) {
696+
psync_folderid_t folderid=psync_get_folderid_by_path_or_create(path);
697+
if (folderid==PSYNC_INVALID_FOLDERID || (!check_write_permissions(folderid))){
698+
char *buff=NULL;
699+
uint32_t bufflen;
700+
int ind = 1;
701+
char *err=NULL;
702+
703+
while (ind < 100) {
704+
folderid=PSYNC_INVALID_FOLDERID;
705+
bufflen = strlen(path) + 1 /*zero char*/ + 3 /*parenthesis*/ + 3 /*up to 3 digit index*/;
706+
buff = (char *) psync_malloc(bufflen);
707+
snprintf(buff, bufflen - 1, "%s (%d)", path, ind);
708+
if (psync_create_remote_folder_by_path(buff, &err)!=0)
709+
debug(D_NOTICE, "Unable to create folder %s error is %s.", buff, err);
710+
folderid=psync_get_folderid_by_path_or_create(buff);
711+
if ((folderid!=PSYNC_INVALID_FOLDERID)&&check_write_permissions(folderid)) {
712+
psync_free(buff);
713+
break;
714+
}
715+
++ind;
716+
717+
if (err)
718+
psync_free(err);
719+
psync_free(buff);
720+
}
721+
}
722+
723+
return folderid;
724+
}

pCloudCC/lib/pclsync/pcompat.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ static wchar_t *utf8_to_wchar_path(const char *str){
156156
/* MAX_PATH seems not to be apporopriate here as it is defined as 260, and CreateDirectory() description says:
157157
* There is a default string size limit for paths of 248 characters. This limit is related to how the CreateDirectory function parses paths.
158158
*/
159-
if (len>=248){
159+
// if (len>=248){
160160
ret=psync_new_cnt(wchar_t, len+4);
161161
memcpy(ret, L"\\\\?\\", 4*sizeof(wchar_t));
162162
MultiByteToWideChar(CP_UTF8, 0, str, -1, ret+4, len);
163-
}
164-
else{
165-
ret=psync_new_cnt(wchar_t, len);
166-
MultiByteToWideChar(CP_UTF8, 0, str, -1, ret, len);
167-
}
163+
// }
164+
// else{
165+
// ret=psync_new_cnt(wchar_t, len);
166+
// MultiByteToWideChar(CP_UTF8, 0, str, -1, ret, len);
167+
// }
168168
return ret;
169169
}
170170

@@ -617,22 +617,22 @@ static void psync_get_random_seed_from_db(psync_lhash_ctx *hctx){
617617
psync_lhash_update(hctx, &tm, sizeof(&tm));
618618
res=psync_sql_query_rdlock("SELECT * FROM setting ORDER BY RANDOM()");
619619
psync_get_random_seed_from_query(hctx, res);
620-
res=psync_sql_query_rdlock("SELECT * FROM filerevision ORDER BY RANDOM() LIMIT 50");
620+
res=psync_sql_query_rdlock("SELECT * FROM resolver ORDER BY RANDOM() LIMIT 50");
621+
psync_get_random_seed_from_query(hctx, res);
622+
/* res=psync_sql_query_rdlock("SELECT * FROM filerevision ORDER BY RANDOM() LIMIT 50");
621623
psync_get_random_seed_from_query(hctx, res);
622624
res=psync_sql_query_rdlock("SELECT * FROM file ORDER BY RANDOM() LIMIT 50");
623625
psync_get_random_seed_from_query(hctx, res);
624626
res=psync_sql_query_rdlock("SELECT * FROM localfile ORDER BY RANDOM() LIMIT 50");
625627
psync_get_random_seed_from_query(hctx, res);
626-
res=psync_sql_query_rdlock("SELECT * FROM resolver ORDER BY RANDOM() LIMIT 50");
627-
psync_get_random_seed_from_query(hctx, res);
628628
res=psync_sql_query_rdlock("SELECT * FROM folder ORDER BY RANDOM() LIMIT 25");
629629
psync_get_random_seed_from_query(hctx, res);
630630
res=psync_sql_query_rdlock("SELECT * FROM localfolder ORDER BY RANDOM() LIMIT 25");
631631
psync_get_random_seed_from_query(hctx, res);
632632
res=psync_sql_query_rdlock("SELECT * FROM hashchecksum ORDER BY RANDOM() LIMIT 25");
633633
psync_get_random_seed_from_query(hctx, res);
634634
res=psync_sql_query_rdlock("SELECT * FROM pagecache WHERE type=1 AND rowid>(ABS(RANDOM())%(SELECT MAX(rowid)+1 FROM pagecache)) ORDER BY rowid LIMIT 50");
635-
psync_get_random_seed_from_query(hctx, res);
635+
psync_get_random_seed_from_query(hctx, res); */
636636
psync_sql_statement("REPLACE INTO setting (id, value) VALUES ('random', RANDOM())");
637637
psync_nanotime(&tm);
638638
psync_lhash_update(hctx, &tm, sizeof(&tm));
@@ -665,12 +665,12 @@ static void psync_store_seed_in_db(const unsigned char *seed){
665665
unsigned char hashbin[PSYNC_LHASH_DIGEST_LEN];
666666
char hashhex[PSYNC_LHASH_DIGEST_HEXLEN], nm[16];
667667
memcpy(hashbin, seed, PSYNC_LHASH_DIGEST_LEN);
668-
psync_rehash_cnt(hashbin, 5000);
668+
psync_rehash_cnt(hashbin, 2000);
669669
psync_binhex(hashhex, hashbin, PSYNC_LHASH_DIGEST_LEN);
670670
res=psync_sql_prep_statement("REPLACE INTO setting (id, value) VALUES ('randomhash', ?)");
671671
psync_sql_bind_lstring(res, 1, hashhex, PSYNC_LHASH_DIGEST_HEXLEN);
672672
psync_sql_run_free(res);
673-
psync_rehash_cnt(hashbin, 5000);
673+
psync_rehash_cnt(hashbin, 2000);
674674
psync_binhex(hashhex, hashbin, PSYNC_LHASH_DIGEST_LEN);
675675
memcpy(nm, "randomhash", 10);
676676
nm[10]=hashhex[0];
@@ -691,7 +691,7 @@ void psync_get_random_seed(unsigned char *seed, const void *addent, size_t aelen
691691
psync_uint_t i, j;
692692
int64_t i64;
693693
pthread_t threadid;
694-
unsigned char lsc[100][PSYNC_LHASH_DIGEST_LEN];
694+
unsigned char lsc[64][PSYNC_LHASH_DIGEST_LEN];
695695
#if defined(P_OS_POSIX)
696696
debug(D_NOTICE, "in");
697697
struct utsname un;
@@ -802,7 +802,6 @@ void psync_get_random_seed(unsigned char *seed, const void *addent, size_t aelen
802802
if (home){
803803
i64=psync_get_free_space_by_path(home);
804804
psync_lhash_update(&hctx, &i64, sizeof(i64));
805-
psync_lhash_update(&hctx, &home, sizeof(home));
806805
psync_lhash_update(&hctx, home, strlen(home));
807806
if (likely_log(!psync_stat(home, &st)))
808807
psync_lhash_update(&hctx, &st, sizeof(st));
@@ -821,7 +820,7 @@ void psync_get_random_seed(unsigned char *seed, const void *addent, size_t aelen
821820
for (j=0; j<PSYNC_LHASH_DIGEST_LEN; j++)
822821
lsc[i][j]^=(unsigned char)i;
823822
}
824-
for (j=fast?98:0; j<100; j++){
823+
for (j=fast?3:0; j<5; j++){
825824
for (i=0; i<100; i++){
826825
psync_lhash_update(&hctx, &i, sizeof(i));
827826
psync_lhash_update(&hctx, &j, sizeof(j));

pCloudCC/lib/pclsync/pcompat.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ typedef unsigned long psync_uint_t;
145145
#define psync_stat_isfolder(s) S_ISDIR((s)->st_mode)
146146
#define psync_stat_size(s) ((s)->st_size)
147147
#ifdef _DARWIN_FEATURE_64_BIT_INODE
148-
#define psync_stat_ctime(s) ((s)->st_birthtime)
148+
#define psync_stat_birthtime(s) ((s)->st_birthtime)
149149
#else
150-
#define psync_stat_ctime(s) ((s)->st_ctime)
150+
#define psync_stat_birthtime(s) ((s)->st_mtime)
151151
#endif
152+
#define psync_stat_ctime(s) ((s)->st_ctime)
152153
#define psync_stat_mtime(s) ((s)->st_mtime)
153154

154155
#if defined(st_mtime)
@@ -266,6 +267,7 @@ int psync_stat(const char *path, psync_stat_t *st);
266267
#define psync_stat_size(s) psync_32to64((s)->nFileSizeHigh, (s)->nFileSizeLow)
267268
#define psync_stat_ctime(s) psync_filetime_to_timet(&(s)->ftCreationTime)
268269
#define psync_stat_mtime(s) psync_filetime_to_timet(&(s)->ftLastWriteTime)
270+
#define psync_stat_birthtime(s) psync_filetime_to_timet(&(s)->ftCreationTime)
269271
#define psync_stat_mtime_native(s) psync_32to64((s)->ftLastWriteTime.dwHighDateTime, (s)->ftLastWriteTime.dwLowDateTime)
270272
#define psync_mtime_native_to_mtime(n) psync_filetime64_to_timet(n)
271273
#define psync_stat_inode(s) psync_32to64((s)->nFileIndexHigh, (s)->nFileIndexLow)

0 commit comments

Comments
 (0)