Skip to content

Commit dced645

Browse files
author
Raycho Mukelov
committed
Updated the sync lib to 1.5.0 etc.
1 parent f1cffb7 commit dced645

35 files changed

+1465
-1125
lines changed

pCloudCC/CMakeLists.txt

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
cmake_minimum_required(VERSION 2.6)
1+
cmake_minimum_required(VERSION 2.8)
22
project(pcloudcc)
33

44
#INCLUDE(CPack)
55

6+
set(CMAKE_BUILD_TYPE Release)
7+
68
set(Boost_USE_STATIC_LIBS ON)
79
set(Boost_USE_MULTITHREADED ON)
810
unset(Boost_INCLUDE_DIR CACHE)
@@ -13,10 +15,12 @@ include_directories(${Boost_INCLUDE_DIR})
1315
link_directories(${Boost_LIBRARY_DIR})
1416
#set (CMAKE_CXX_FLAGS "-static -Wl,-Bstatic")
1517
#set (CMAKE_CXX_FLAGS "-Wl,-Bstatic")
18+
#set (CMAKE_CXX_FLAGS "-DP_CONSOLE_CLIENT")
1619
set (CMAKE_C_FLAGS "-fPIC")
1720
set (PCLSYNC_PATH ${CMAKE_SOURCE_DIR}/lib/pclsync)
1821
set (MBEDTLS_PATH ${CMAKE_SOURCE_DIR}/lib/mbedtls)
1922
set (SQLITE3_PATH ${CMAKE_SOURCE_DIR}/lib/sqlite)
23+
set (PRJF_PATH ${CMAKE_SOURCE_DIR}/lib/prjf)
2024

2125
#add_subdirectory(${MBEDTLS_PATH})
2226

@@ -46,30 +50,33 @@ add_custom_target(
4650
WORKING_DIRECTORY ${MBEDTLS_PATH}
4751
)
4852

49-
set (OVERLAY_CLENT_PATH ${CMAKE_SOURCE_DIR}/lib/poverlay_linux)
53+
set(OVERLAY_CLENT_PATH ${CMAKE_SOURCE_DIR}/lib/poverlay_linux)
5054
include_directories(${OVERLAY_CLENT_PATH})
5155

5256
add_library(sqlite3 STATIC ${SQLITE3_PATH}/sqlite3.c)
5357
target_link_libraries(sqlite3 z dl)
5458

55-
add_library(pcloudcc_lib SHARED pclsync_lib_c.cpp pclsync_lib.cpp control_tools.cpp ${OVERLAY_CLENT_PATH}/overlay_client.c ${OVERLAY_CLENT_PATH}/debug.c )
56-
57-
target_link_libraries(pcloudcc_lib ${PCLSYNC_PATH}/libpsynclib.a ${MBEDTLS_PATH}/library/libmbedtls.a fuse pthread sqlite3
58-
)
59+
add_library(pcloudcc_lib SHARED pclsync_lib_c.cpp pclsync_lib.cpp control_tools.cpp ${OVERLAY_CLENT_PATH}/overlay_client.c ${OVERLAY_CLENT_PATH}/debug.c ${PRJF_PATH}/pRJF.c)
60+
target_link_libraries(pcloudcc_lib ${PCLSYNC_PATH}/psynclib.a ${MBEDTLS_PATH}/library/libmbedtls.a fuse pthread sqlite3 udev)
5961

60-
add_executable(pcloudcc main.cpp)
62+
file(GLOB_RECURSE INC_ALL "*.h" "*.hpp")
63+
add_executable(pcloudcc main.cpp ${INC_ALL})
6164

6265
target_link_libraries(pcloudcc pcloudcc_lib)
63-
6466
target_link_libraries(pcloudcc ${Boost_LIBRARIES})
65-
6667
link_directories(${PCLSYNC_PATH} ${MBEDTLS_PATH}/library ${SQLITE3_PATH} ${OVERLAY_CLENT_PATH})
6768

6869
#add_dependencies(pclsync sqlite3_lib)
69-
7070
#add_dependencies(pcloudcc sqlite3_lib mbedtls pclsync )
71-
72-
install(TARGETS pcloudcc RUNTIME DESTINATION bin)
73-
install(TARGETS pcloudcc_lib LIBRARY DESTINATION lib)
74-
75-
71+
#add_dependencies(pcloudcc pcloudcc_lib)
72+
install(TARGETS pcloudcc DESTINATION /usr/bin)
73+
#EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
74+
#message( STATUS "Architecture: ${ARCHITECTURE}" )
75+
#if(${ARCHITECTURE} STREQUAL "x86_64")
76+
# set(LIB_DIR "/usr/lib64")
77+
#else()
78+
# set(LIB_DIR "/usr/lib")
79+
#endif()
80+
81+
install(TARGETS pcloudcc_lib LIBRARY DESTINATION /usr/lib)
82+
message(STATUS "System CPU: " ${CMAKE_SYSTEM_PROCESSOR})

pCloudCC/control_tools.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,49 @@ enum command_ids_ {
2828
ADDSYNC,
2929
STOPSYNC
3030
};
31-
3231

33-
int start_crypto(const char * pass) {
32+
int start_crypto(const char * pass){
3433
int ret;
35-
char* errm;
36-
if (SendCall(STARTCRYPTO, pass, &ret, &errm))
37-
std::cout << "Start Crypto failed. return is " << ret<< " and message is "<<errm << std::endl;
34+
char* errm=NULL;
35+
if(SendCall(STARTCRYPTO, pass, &ret, &errm))
36+
std::cout << "Start Crypto failed. return is " << ret << " and message is "<<errm << std::endl;
3837
else
3938
std::cout << "Crypto started. "<< std::endl;
40-
free(errm);
39+
if(errm)
40+
free(errm);
4141
}
42+
4243
int stop_crypto(){
4344
int ret;
44-
char* errm;
45+
char* errm=NULL;
4546
if (SendCall(STOPCRYPTO, "", &ret, &errm))
46-
std::cout << "Stop Crypto failed. return is " << ret<< " and message is "<<errm << std::endl;
47+
std::cout << "Stop Crypto failed. return is " << ret << " and message is "<< errm << std::endl;
4748
else
4849
std::cout << "Crypto Stopped. "<< std::endl;
49-
free(errm);
50+
if (errm)
51+
free(errm);
5052
}
53+
5154
int finalize(){
5255
int ret;
53-
char* errm;
56+
char* errm=NULL;
5457
if (SendCall(FINALIZE, "", &ret, &errm))
55-
std::cout << "Finalize failed. return is " << ret<< " and message is "<<errm << std::endl;
58+
std::cout << "Finalize failed. return is " << ret<< " and message is "<< errm << std::endl;
5659
else
5760
std::cout << "Exiting ..."<< std::endl;
58-
59-
free(errm);
61+
if (errm)
62+
free(errm);
6063
}
64+
6165
void process_commands()
6266
{
6367
std::cout<< "Supported commands are:" << std::endl << "startcrypto <crypto pass>, stopcrypto, finalize, q, quit" << std::endl;
6468
std::cout<< "> " ;
6569
for (std::string line; std::getline(std::cin, line);) {
66-
if (!line.compare("finalize")) {
70+
if (!line.compare("finalize")){
6771
finalize();
68-
break;}
72+
break;
73+
}
6974
else if (!line.compare("stopcrypto"))
7075
stop_crypto();
7176
else if (!line.compare(0,11,"startcrypto",0,11) && (line.length() > 12))
@@ -81,11 +86,11 @@ int daemonize(bool do_commands) {
8186
pid_t pid, sid;
8287

8388
pid = fork();
84-
if (pid < 0)
89+
if (pid<0)
8590
exit(EXIT_FAILURE);
86-
if (pid > 0) {
91+
if (pid>0){
8792
std::cout << "Daemon process created. Process id is: " << pid << std::endl;
88-
if (do_commands) {
93+
if (do_commands){
8994
process_commands();
9095
}
9196
else
@@ -94,10 +99,9 @@ int daemonize(bool do_commands) {
9499
}
95100
umask(0);
96101
/* Open any logs here */
97-
sid = setsid();
102+
sid=setsid();
98103
if (sid < 0)
99104
exit(EXIT_FAILURE);
100-
101105
if ((chdir("/")) < 0)
102106
exit(EXIT_FAILURE);
103107
close(STDIN_FILENO);
@@ -106,10 +110,9 @@ int daemonize(bool do_commands) {
106110

107111
if (console_client::clibrary::pclsync_lib::get_lib().init())
108112
exit(EXIT_FAILURE);
109-
while (1) {
113+
while (1){
110114
sleep(10);
111115
}
112-
113116
}
114117

115118
}

pCloudCC/debian/changelog

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
pcloudcc (2.0.1-1) trusty; urgency=low
1+
pcloudcc (2.1.0-1) bionic; urgency=low
22

3-
* Initial release
3+
* Updated the sync library to v 1.5.0
4+
5+
-- Raycho Mukelov <[email protected]> Thu, 1 Aug 2019 16:53:02 +0300
46

5-
-- Ivan Stoev <[email protected]> Tue, 05 Apr 2016 16:58:02 +0300

pCloudCC/lib/pclsync/Makefile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
#CC=cc
1+
CC=gcc
22
AR=ar rcu
33
RANLIB=ranlib
44
#USESSL=openssl
55
USESSL=mbed
66

7+
#CFLAGS=-Wall -Wpointer-arith -O2 -g -mtune=core2
8+
CFLAGS=-Wall -Wpointer-arith -O2 -g -fno-stack-protector -fomit-frame-pointer -mtune=core2 -I../sqlite -DP_ELECTRON -fPIC
9+
710
#CFLAGS=-Wall -Wpointer-arith -O2 -g -fsanitize=address -mtune=core2
8-
CFLAGS=-Wall -Wpointer-arith -O2 -g -fno-stack-protector -fomit-frame-pointer -fPIC
11+
#CFLAGS=-Wall -Wpointer-arith -O2 -g -fsanitize=address -mtune=core2 -I../sqlite
12+
#CFLAGS=-Wall -Wpointer-arith -Os -g -mtune=core2 -I../sqlite -pg
13+
#CFLAGS=-Wall -Wpointer-arith -O2 -g -fno-stack-protector -fomit-frame-pointer -mtune=core2 -I../sqlite/ -fPIC
14+
#CFLAGS=-Wall -Wpointer-arith -O2 -g -mtune=core2 -I../sqlite -pg -m32 -D_FILE_OFFSET_BITS=64
915
#CFLAGS=-O2 -g -pg
1016
#CFLAGS=-Wall -Wpointer-arith -O2 -g -mtune=core2 -I../../psync32/zlib -I../../psync32/sqlite -m32 -D_FILE_OFFSET_BITS=64
1117

12-
#CMAKE whants lib extension
13-
LIB_A=libpsynclib.a
18+
LIB_A=psynclib.a
19+
#LIB_A=libpsynclib.a
1420

1521

1622
ifeq ($(OS),Windows_NT)
@@ -23,7 +29,7 @@ else
2329
UNAME_S := $(shell uname -s)
2430
UNAME_V := $(shell uname -v)
2531
ifeq ($(UNAME_S),Linux)
26-
CFLAGS += -DP_OS_LINUX -I../sqlite
32+
CFLAGS += -DP_OS_LINUX -D_FILE_OFFSET_BITS=64
2733
ifneq (,$(findstring Debian,$(UNAME_V)))
2834
CFLAGS += -DP_OS_DEBIAN
2935
endif
@@ -72,6 +78,9 @@ fs: $(OBJ) $(OBJFS)
7278
$(AR) $(LIB_A) $(OBJ) $(OBJFS)
7379
$(RANLIB) $(LIB_A)
7480

81+
debugfs: fs
82+
CFLAGS += -DDEBUG_LEVEL=${DEBUG}
83+
7584
cli: fs
7685
$(CC) $(CFLAGS) -o cli cli.c $(LIB_A) $(LDFLAGS)
7786

pCloudCC/lib/pclsync/gitcommit.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef _GITCOMMIT_H
22
#define _GITCOMMIT_H
33

4-
#define GIT_PREV_COMMIT_ID "6339ebce20a8b853dd78b80e075ab25e1f413f73"
5-
#define GIT_PREV_COMMIT_DATE "2018-03-15 15:36:43 +0200"
6-
#define GIT_COMMIT_DATE "2018-03-26 18:43:25 +0300"
4+
#define GIT_PREV_COMMIT_ID "17d868f376d826d6beeecb6c7d326f0fb119ff18"
5+
#define GIT_PREV_COMMIT_DATE "2019-03-06 18:00:24 +0200"
6+
#define GIT_COMMIT_DATE "2019-03-11 11:29:47 +0200"
77

88
#endif

pCloudCC/lib/pclsync/papi.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,20 @@ const binresult *psync_do_check_result(const binresult *res, const char *name, u
609609
}
610610
return NULL;
611611
}
612+
613+
const binresult *psync_do_get_result(const binresult *res, const char *name, const char *file, const char *function, int unsigned line){
614+
uint32_t i;
615+
if (unlikely(!res || res->type!=PARAM_HASH)){
616+
if (D_CRITICAL<=DEBUG_LEVEL){
617+
const char *nm="NULL";
618+
if (res)
619+
nm=type_names[res->type];
620+
psync_debug(file, function, line, D_CRITICAL, "expecting hash as first parameter, got %s", nm);
621+
}
622+
return NULL;
623+
}
624+
for (i=0; i<res->length; i++)
625+
if (!strcmp(res->hash[i].key, name))
626+
return res->hash[i].value;
627+
return NULL;
628+
}

pCloudCC/lib/pclsync/papi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ typedef struct {
102102

103103
#define psync_find_result(res, name, type) psync_do_find_result(res, name, type, __FILE__, __FUNCTION__, __LINE__)
104104
#define psync_check_result(res, name, type) psync_do_check_result(res, name, type, __FILE__, __FUNCTION__, __LINE__)
105+
#define psync_get_result(res, name) psync_do_get_result(res, name, __FILE__, __FUNCTION__, __LINE__)
105106

106107
psync_socket *psync_api_connect(const char *hostname, int usessl);
107108
void psync_api_conn_fail_inc();
@@ -116,5 +117,6 @@ unsigned char *do_prepare_command(const char *command, size_t cmdlen, const binp
116117
binresult *do_send_command(psync_socket *sock, const char *command, size_t cmdlen, const binparam *params, size_t paramcnt, int64_t datalen, int readres) PSYNC_NONNULL(1, 2);
117118
const binresult *psync_do_find_result(const binresult *res, const char *name, uint32_t type, const char *file, const char *function, int unsigned line) PSYNC_NONNULL(2) PSYNC_PURE;
118119
const binresult *psync_do_check_result(const binresult *res, const char *name, uint32_t type, const char *file, const char *function, int unsigned line) PSYNC_NONNULL(2) PSYNC_PURE;
120+
const binresult *psync_do_get_result(const binresult *res, const char *name, const char *file, const char *function, int unsigned line) PSYNC_NONNULL(2) PSYNC_PURE;
119121

120122
#endif

pCloudCC/lib/pclsync/pcompat.c

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ static char proxy_port[8];
122122

123123
static int psync_page_size;
124124

125-
static const char *psync_software_name="pCloudSync library "PSYNC_LIB_VERSION;
125+
static const char *psync_software_name=PSYNC_LIB_VERSION;
126+
static const char *psync_os_name=NULL;
126127

127128
PSYNC_THREAD const char *psync_thread_name="no name";
128129
static pthread_mutex_t socket_mutex=PTHREAD_MUTEX_INITIALIZER;
@@ -2508,6 +2509,10 @@ int psync_list_dir(const char *path, psync_list_dir_callback callback, void *ptr
25082509
if (de->d_name[0]!='.' || (de->d_name[1]!=0 && (de->d_name[1]!='.' || de->d_name[2]!=0))){
25092510
psync_strlcpy(cpath+pl, de->d_name, namelen+1);
25102511
if (likely_log(!lstat(cpath, &pst.stat)) && (S_ISREG(pst.stat.st_mode) || S_ISDIR(pst.stat.st_mode))){
2512+
#if defined(P_OS_MACOSX)
2513+
if (pst.stat.st_flags&(UF_HIDDEN|UF_IMMUTABLE|SF_IMMUTABLE))
2514+
continue;
2515+
#endif
25112516
pst.name=de->d_name;
25122517
callback(ptr, &pst);
25132518
}
@@ -2569,7 +2574,9 @@ int psync_list_dir(const char *path, psync_list_dir_callback callback, void *ptr
25692574
}
25702575

25712576
int psync_list_dir_fast(const char *path, psync_list_dir_callback_fast callback, void *ptr){
2572-
#if defined(P_OS_POSIX)
2577+
#if defined(P_OS_MACOSX)
2578+
return psync_list_dir(path, callback, ptr);
2579+
#elif defined(P_OS_POSIX)
25732580
psync_pstat_fast pst;
25742581
struct stat st;
25752582
DIR *dh;
@@ -3368,12 +3375,12 @@ int64_t psync_file_size(psync_file_t fd){
33683375
else
33693376
return st.st_size;
33703377
#elif defined(P_OS_WINDOWS)
3371-
ULARGE_INTEGER li;
3372-
li.LowPart=GetFileSize(fd, &li.HighPart);
3373-
if (unlikely_log(li.LowPart==INVALID_FILE_SIZE && GetLastError()!=NO_ERROR))
3374-
return -1;
3375-
else
3376-
return li.QuadPart;
3378+
ULARGE_INTEGER li;
3379+
li.LowPart=GetFileSize(fd, &li.HighPart);
3380+
if (unlikely_log(li.LowPart==INVALID_FILE_SIZE && GetLastError()!=NO_ERROR))
3381+
return -1;
3382+
else
3383+
return li.QuadPart;
33773384
#else
33783385
#error "Function not implemented for your operating system"
33793386
#endif
@@ -3383,6 +3390,29 @@ void psync_set_software_name(const char *snm){
33833390
psync_software_name=snm;
33843391
}
33853392

3393+
void psync_set_os_name(const char *osnm){
3394+
psync_os_name=osnm;
3395+
}
3396+
3397+
char *psync_deviceos(){
3398+
return psync_os_name?psync_strdup(psync_os_name):psync_deviceid();
3399+
}
3400+
3401+
char *psync_device_string(){
3402+
#if defined(P_OS_LINUX)
3403+
char *osname=psync_deviceos();
3404+
char *ret = psync_strcat(osname, ", ", psync_software_name, NULL);
3405+
free(osname);
3406+
return ret;
3407+
3408+
#endif
3409+
return psync_strcat(psync_deviceid(), ", ", psync_software_name, NULL);
3410+
}
3411+
3412+
const char *psync_appname(){
3413+
return psync_software_name;
3414+
}
3415+
33863416
char *psync_deviceid(){
33873417
char *device;
33883418
#if defined(P_OS_WINDOWS)
@@ -3426,7 +3456,7 @@ char *psync_deviceid(){
34263456
psync_slprintf(versbuff, sizeof(versbuff), "%u.%u", (unsigned int)vmajor, (unsigned int)vminor);
34273457
ver=versbuff;
34283458
}
3429-
device=psync_strcat(hardware, ", Windows ", ver, ", ", psync_software_name, NULL);
3459+
device=psync_strcat(hardware, ", Windows ", ver, NULL);
34303460
#elif defined(P_OS_MACOSX)
34313461
struct utsname un;
34323462
const char *ver;
@@ -3452,7 +3482,7 @@ char *psync_deviceid(){
34523482
if (sysctlbyname("hw.model", modelname, &len, NULL, 0))
34533483
psync_strlcpy(modelname, "Mac", sizeof(modelname));
34543484
versbuff[sizeof(versbuff)-1]=0;
3455-
device=psync_strcat(modelname, ", ", ver, ", ", psync_software_name, NULL);
3485+
device=psync_strcat(modelname, ", ", ver, NULL);
34563486
#elif defined(P_OS_LINUX)
34573487
DIR *dh;
34583488
struct dirent entry, *de;
@@ -3478,9 +3508,9 @@ char *psync_deviceid(){
34783508
}
34793509
closedir(dh);
34803510
}
3481-
device=psync_strcat(hardware, ", Linux, ", psync_software_name, NULL);
3511+
device=psync_strcat(hardware, ", Linux", NULL);
34823512
#else
3483-
device=psync_strcat("Desktop, ", psync_software_name, NULL);
3513+
device=psync_strcat("Desktop", NULL);
34843514
#endif
34853515
debug(D_NOTICE, "detected device: %s", device);
34863516
return device;

0 commit comments

Comments
 (0)