Skip to content

Commit d6764a1

Browse files
author
Ivan Stoev
committed
latest
1 parent 312a01f commit d6764a1

File tree

4 files changed

+71
-24
lines changed

4 files changed

+71
-24
lines changed

pCloudCC/pclsync_lib.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,25 @@ void event_handler(psync_eventtype_t event, psync_eventdata_t eventdata){
124124
std::cout <<"event" << event << std::endl;
125125
}
126126

127-
static void lib_setup_cripto(){
128-
if (psync_crypto_issetup())
129-
std::cout << "crypto is setup, login result=" << psync_crypto_start(clib::pclsync_lib::get_lib().get_crypto_pass().c_str()) << std::endl;
130-
else{
127+
static int lib_setup_cripto(){
128+
int ret = 0;
129+
ret = psync_crypto_issetup();
130+
if (ret) {
131+
ret = psync_crypto_start(clib::pclsync_lib::get_lib().get_crypto_pass().c_str());
132+
std::cout << "crypto is setup, login result=" << ret << std::endl;
133+
} else {
131134
std::cout << "crypto is not setup" << std::endl;
132-
if (psync_crypto_setup(clib::pclsync_lib::get_lib().get_crypto_pass().c_str(), "no hint"))
135+
ret = psync_crypto_setup(clib::pclsync_lib::get_lib().get_crypto_pass().c_str(), "no hint");
136+
if (ret)
133137
std::cout << "crypto setup failed" << std::endl;
134138
else{
135-
std::cout << "crypto setup successful, start=" << psync_crypto_start(clib::pclsync_lib::get_lib().get_crypto_pass().c_str()) << std::endl;
136-
std::cout << "creating folder=" << psync_crypto_mkdir(0, "Crypto", NULL, NULL) << std::endl;
139+
ret = psync_crypto_start(clib::pclsync_lib::get_lib().get_crypto_pass().c_str());
140+
std::cout << "crypto setup successful, start=" << ret << std::endl;
141+
ret = psync_crypto_mkdir(0, "Crypto", NULL, NULL) ;
142+
std::cout << "creating folder=" << ret << std::endl;
137143
}
138144
}
145+
return ret;
139146
clib::pclsync_lib::get_lib().crypto_on_ = true;
140147
}
141148

@@ -204,7 +211,7 @@ static void status_change(pstatus_t* status) {
204211
int clib::pclsync_lib::statrt_crypto (const char* pass, void * rep) {
205212
std::cout << "calling startcrypto pass: "<<pass << std::endl;
206213
get_lib().crypto_pass_ = pass;
207-
lib_setup_cripto();
214+
return lib_setup_cripto();
208215
}
209216
int clib::pclsync_lib::stop_crypto (const char* path, void * rep) {
210217
psync_crypto_stop();
@@ -227,18 +234,22 @@ int clib::pclsync_lib::init()//std::string& username, std::string& password, std
227234
psync_set_software_string(software_string.append(client_name).c_str());
228235
if (setup_crypto_ && crypto_pass_.empty() )
229236
return 3;
230-
was_init_ = true;
237+
231238

232239
if (psync_init()){
233240
std::cout <<"init failed\n";
234241
return 1;
235242
}
236243

244+
was_init_ = true;
237245
if (!get_mount().empty())
238246
psync_set_string_setting("fsroot",get_mount().c_str());
239247

240248
// _tunnel = psync_ssl_tunnel_start("127.0.0.1", 9443, "62.210.116.50", 443);
249+
241250

251+
int isfsautostart = psync_get_bool_setting("autostartfs");
252+
242253
psync_start_sync(status_change, event_handler);
243254
char * username_old = psync_get_username();
244255

@@ -260,6 +271,27 @@ int clib::pclsync_lib::init()//std::string& username, std::string& password, std
260271
return 0;
261272
}
262273

274+
int clib::pclsync_lib::login(const char* user, const char* pass, int save) {
275+
set_username(user);
276+
set_password(pass);
277+
set_savepass(bool(save));
278+
psync_set_user_pass(user,pass, save);
279+
return 0;
280+
}
281+
282+
int clib::pclsync_lib::logout () {
283+
set_password("");
284+
psync_logout();
285+
return 0;
286+
}
287+
288+
int clib::pclsync_lib::unlink () {
289+
set_username("");
290+
set_password("");
291+
psync_unlink();
292+
return 0;
293+
}
294+
263295
clib::pclsync_lib::pclsync_lib() : status_(new pstatus_struct_() ), was_init_(false), setup_crypto_(false)
264296
{}
265297

pCloudCC/pclsync_lib.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,24 @@ namespace console_client {
7070
//Singelton
7171
static pclsync_lib& get_lib();
7272
char * get_token();
73+
int logout();
74+
int unlink();
75+
int login(const char* user, const char* pass, int save);
7376

7477
bool crypto_on_;
7578
bool save_pass_;
7679
bool setup_crypto_;
7780
pstatus_struct_* status_;
7881
bool newuser_;
7982
status_callback_t status_callback_;
83+
bool was_init_;
8084

8185
private:
8286
std::string username_;
8387
std::string password_;
8488
std::string crypto_pass_;
8589
std::string mount_;
86-
bool was_init_;
90+
8791
bool to_set_mount_;
8892
bool daemon_;
8993

pCloudCC/pclsync_lib_c.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ extern "C" {
88
#endif
99
namespace cc = console_client::clibrary;
1010

11-
int init(const char* user, const char* pass, int save) {
12-
cc::pclsync_lib::get_lib().set_username(user);
13-
cc::pclsync_lib::get_lib().set_password(pass);
14-
cc::pclsync_lib::get_lib().set_savepass((bool)save);
15-
return cc::pclsync_lib::get_lib().init();
11+
int init() {
12+
if (!cc::pclsync_lib::get_lib().was_init_)
13+
return cc::pclsync_lib::get_lib().init();
14+
else return 0;
1615
}
1716

1817
int statrt_crypto (const char* pass) {
@@ -24,14 +23,28 @@ int init(const char* user, const char* pass, int save) {
2423
int finalize () {
2524
cc::pclsync_lib::finalize(NULL, NULL);
2625
}
27-
void set_status_callback(status_callback_t c)
28-
{
26+
void set_status_callback(status_callback_t c) {
2927
cc::pclsync_lib::get_lib().set_status_callback(c);
3028
}
3129

3230
char * get_token(){
3331
return cc::pclsync_lib::get_lib().get_token();
3432
}
33+
34+
35+
int login(const char* user, const char* pass, int save) {
36+
return cc::pclsync_lib::get_lib().login(user, pass, save);
37+
}
38+
39+
int logout() {
40+
return cc::pclsync_lib::get_lib().logout();
41+
}
42+
43+
int unlinklib() {
44+
return cc::pclsync_lib::get_lib().unlink();
45+
}
46+
47+
3548
#ifdef __cplusplus
3649
}
3750
#endif

pCloudCC/pclsync_lib_c.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@ extern "C" {
55

66
#include "psynclib.h"
77

8-
psync_syncid_t psync_add_sync_by_path(const char *localpath, const char *remotepath, psync_synctype_t synctype);
9-
psync_syncid_t psync_add_sync_by_folderid(const char *localpath, psync_folderid_t folderid, psync_synctype_t synctype);
10-
int psync_add_sync_by_path_delayed(const char *localpath, const char *remotepath, psync_synctype_t synctype);
11-
int psync_change_synctype(psync_syncid_t syncid, psync_synctype_t synctype);
12-
int psync_delete_sync(psync_syncid_t syncid);
13-
psync_folder_list_t *psync_get_sync_list();
8+
void psync_fs_pause_until_login();
149

1510
typedef void (*status_callback_t)(int status, const char * stat_string);
1611

17-
int init(const char* user, const char* pass, int save);
12+
int init();
1813
int statrt_crypto (const char* pass);
1914
int stop_crypto ();
2015
int finalize ();
2116
char * get_token();
2217
void set_status_callback(status_callback_t);
18+
int logout();
19+
int unlinklib();
20+
int login(const char* user, const char* pass, int save);
2321

2422
#ifdef __cplusplus
2523
};

0 commit comments

Comments
 (0)