pCloudCC/ formatting
This commit is contained in:
parent
6a5c1960bf
commit
8c3d737815
6
Makefile
6
Makefile
|
|
@ -8,5 +8,11 @@ all:
|
|||
clean:
|
||||
make -C pCloudCC/lib/pclsync clean
|
||||
make -C pCloudCC/lib/mbedtls clean
|
||||
rm -rf pCloudCC/lib/mbedtls/CMakeFiles
|
||||
rm pCloudCC/lib/mbedtls/CMakeCache.txt
|
||||
rm pCloudCC/lib/mbedtls/Makefile
|
||||
make -C pCloudCC clean
|
||||
rm -rf pCloudCC/CMakeFiles
|
||||
rm pCloudCC/CMakeCache.txt
|
||||
rm pCloudCC/Makefile
|
||||
|
||||
|
|
|
|||
|
|
@ -1,120 +1,147 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "control_tools.h"
|
||||
#include "pclsync_lib.h"
|
||||
#include "overlay_client.h"
|
||||
|
||||
namespace control_tools{
|
||||
namespace cc = console_client;
|
||||
|
||||
static const int STOP = 0;
|
||||
namespace control_tools {
|
||||
|
||||
enum command_ids_ {
|
||||
STARTCRYPTO = 20,
|
||||
STOPCRYPTO,
|
||||
FINALIZE,
|
||||
LISTSYNC,
|
||||
ADDSYNC,
|
||||
STOPSYNC
|
||||
};
|
||||
static const int STOP = 0;
|
||||
|
||||
enum command_ids_ {
|
||||
STARTCRYPTO = 20,
|
||||
STOPCRYPTO,
|
||||
FINALIZE,
|
||||
LISTSYNC,
|
||||
ADDSYNC,
|
||||
STOPSYNC
|
||||
};
|
||||
|
||||
|
||||
int start_crypto(const char * pass) {
|
||||
int ret;
|
||||
char* errm;
|
||||
if (SendCall(STARTCRYPTO, pass, &ret, &errm))
|
||||
std::cout << "Start Crypto failed. return is " << ret<< " and message is "<<errm << std::endl;
|
||||
else
|
||||
std::cout << "Crypto started. "<< std::endl;
|
||||
int
|
||||
start_crypto(const char * pass) {
|
||||
int ret;
|
||||
char* errm;
|
||||
|
||||
if (SendCall(STARTCRYPTO, pass, &ret, &errm)) {
|
||||
std::cout << "Start Crypto failed. return is "
|
||||
<< ret << " and message is "<< errm
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Crypto started. "<< std::endl;
|
||||
}
|
||||
|
||||
free(errm);
|
||||
return ret;
|
||||
}
|
||||
int stop_crypto(){
|
||||
int ret;
|
||||
char* errm;
|
||||
if (SendCall(STOPCRYPTO, "", &ret, &errm))
|
||||
std::cout << "Stop Crypto failed. return is " << ret<< " and message is "<<errm << std::endl;
|
||||
else
|
||||
std::cout << "Crypto Stopped. "<< std::endl;
|
||||
|
||||
free(errm);
|
||||
return ret;
|
||||
}
|
||||
int finalize(){
|
||||
int ret;
|
||||
char* errm;
|
||||
if (SendCall(FINALIZE, "", &ret, &errm))
|
||||
std::cout << "Finalize failed. return is " << ret<< " and message is "<<errm << std::endl;
|
||||
else
|
||||
std::cout << "Exiting ..."<< std::endl;
|
||||
|
||||
free(errm);
|
||||
return ret;
|
||||
}
|
||||
void process_commands()
|
||||
{
|
||||
std::cout<< "Supported commands are:" << std::endl << "startcrypto <crypto pass>, stopcrypto, finalize, q, quit" << std::endl;
|
||||
std::cout<< "> " ;
|
||||
for (std::string line; std::getline(std::cin, line);) {
|
||||
if (!line.compare("finalize")) {
|
||||
finalize();
|
||||
break;}
|
||||
else if (!line.compare("stopcrypto"))
|
||||
stop_crypto();
|
||||
else if (!line.compare(0,11,"startcrypto",0,11) && (line.length() > 12))
|
||||
start_crypto(line.c_str() + 12);
|
||||
else if (!line.compare("q") || !line.compare("quit"))
|
||||
break;
|
||||
|
||||
std::cout<< "> " ;
|
||||
free(errm);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
stop_crypto(){
|
||||
int ret;
|
||||
char* errm;
|
||||
|
||||
int daemonize(bool do_commands) {
|
||||
pid_t pid, sid;
|
||||
if (SendCall(STOPCRYPTO, "", &ret, &errm)) {
|
||||
std::cout << "Stop Crypto failed. return is " << ret
|
||||
<< " and message is "<<errm << std::endl;
|
||||
} else {
|
||||
std::cout << "Crypto Stopped. " << std::endl;
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
exit(EXIT_FAILURE);
|
||||
if (pid > 0) {
|
||||
std::cout << "Daemon process created. Process id is: " << pid << std::endl;
|
||||
if (do_commands) {
|
||||
process_commands();
|
||||
}
|
||||
else
|
||||
std::cout << "sudo kill -9 "<<pid<< std::endl<<" To stop it."<< std::endl;
|
||||
exit(EXIT_SUCCESS);
|
||||
free(errm);
|
||||
return ret;
|
||||
}
|
||||
umask(0);
|
||||
/* Open any logs here */
|
||||
sid = setsid();
|
||||
if (sid < 0)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
int
|
||||
finalize() {
|
||||
int ret;
|
||||
char* errm;
|
||||
|
||||
if ((chdir("/")) < 0)
|
||||
exit(EXIT_FAILURE);
|
||||
close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
if (SendCall(FINALIZE, "", &ret, &errm)) {
|
||||
std::cout << "Finalize failed. return is "
|
||||
<< ret << " and message is "<< errm
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Exiting ..."<< std::endl;
|
||||
}
|
||||
|
||||
if (console_client::clibrary::pclsync_lib::get_lib().init())
|
||||
exit(EXIT_FAILURE);
|
||||
while (1) {
|
||||
sleep(10);
|
||||
free(errm);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
process_commands() {
|
||||
std::cout << "Supported commands are:" << std::endl
|
||||
<< "startcrypto <crypto pass>, "
|
||||
<< "stopcrypto, "
|
||||
<< "finalize, "
|
||||
<< "q, quit" << std::endl;
|
||||
std::cout << "> " ;
|
||||
|
||||
for (std::string line; std::getline(std::cin, line);) {
|
||||
if (!line.compare("finalize")) {
|
||||
finalize();
|
||||
break;
|
||||
} else if (!line.compare("stopcrypto")) {
|
||||
stop_crypto();
|
||||
} else if (!line.compare(0,11,"startcrypto",0,11)
|
||||
&& (line.length() > 12)) {
|
||||
start_crypto(line.c_str() + 12);
|
||||
} else if (!line.compare("q") || !line.compare("quit")) {
|
||||
break;
|
||||
}
|
||||
std::cout<< "> " ;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
daemonize(bool do_commands) {
|
||||
pid_t pid, sid;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (pid > 0) {
|
||||
std::cout << "Daemon process created. Process id is: " << pid << std::endl;
|
||||
if (do_commands) {
|
||||
process_commands();
|
||||
} else {
|
||||
std::cout << "kill -9 "<< pid << std::endl
|
||||
<< " to stop it." << std::endl;
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* Open any logs here */
|
||||
umask(0);
|
||||
sid = setsid();
|
||||
if (sid < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((chdir("/")) < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
|
||||
if (cc::clibrary::pclsync_lib::get_lib().init()) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,66 @@
|
|||
namespace cc = console_client;
|
||||
namespace clib = cc::clibrary;
|
||||
|
||||
clib::pclsync_lib &clib::pclsync_lib::get_lib() {
|
||||
const std::string&
|
||||
clib::pclsync_lib::get_username() {
|
||||
return username_;
|
||||
}
|
||||
|
||||
const std::string &
|
||||
clib::pclsync_lib::get_password() {
|
||||
return password_;
|
||||
}
|
||||
|
||||
const std::string &
|
||||
clib::pclsync_lib::get_crypto_pass() {
|
||||
return crypto_pass_;
|
||||
};
|
||||
|
||||
const std::string &
|
||||
clib::pclsync_lib::get_mount() {
|
||||
return mount_;
|
||||
}
|
||||
|
||||
void
|
||||
clib::pclsync_lib::set_username(const std::string &arg) {
|
||||
username_ = arg;
|
||||
}
|
||||
void
|
||||
clib::pclsync_lib::set_password(const std::string &arg) {
|
||||
password_ = arg;
|
||||
}
|
||||
void
|
||||
clib::pclsync_lib::set_crypto_pass(const std::string &arg) {
|
||||
crypto_pass_ = arg;
|
||||
};
|
||||
void
|
||||
clib::pclsync_lib::set_mount(const std::string &arg) {
|
||||
mount_ = arg;
|
||||
}
|
||||
void
|
||||
clib::pclsync_lib::set_savepass(bool s) {
|
||||
save_pass_ = s;
|
||||
}
|
||||
void
|
||||
clib::pclsync_lib::setupsetup_crypto(bool p) {
|
||||
setup_crypto_ = p;
|
||||
}
|
||||
void
|
||||
clib::pclsync_lib::set_newuser(bool p) {
|
||||
newuser_ = p;
|
||||
}
|
||||
void
|
||||
clib::pclsync_lib::set_daemon(bool p) {
|
||||
daemon_ = p;
|
||||
}
|
||||
void
|
||||
clib::pclsync_lib::set_status_callback(status_callback_t p) {
|
||||
status_callback_ = p;
|
||||
}
|
||||
|
||||
|
||||
clib::pclsync_lib &
|
||||
clib::pclsync_lib::get_lib() {
|
||||
static clib::pclsync_lib g_lib;
|
||||
return g_lib;
|
||||
}
|
||||
|
|
@ -67,17 +126,21 @@ exec(const char *cmd) {
|
|||
return result;
|
||||
}
|
||||
|
||||
char *clib::pclsync_lib::get_token() { return psync_get_token(); }
|
||||
char *
|
||||
clib::pclsync_lib::get_token() { return psync_get_token(); }
|
||||
|
||||
void clib::pclsync_lib::get_pass_from_console() {
|
||||
void
|
||||
clib::pclsync_lib::get_pass_from_console() {
|
||||
do_get_pass_from_console(password_);
|
||||
}
|
||||
|
||||
void clib::pclsync_lib::get_cryptopass_from_console() {
|
||||
void
|
||||
clib::pclsync_lib::get_cryptopass_from_console() {
|
||||
do_get_pass_from_console(crypto_pass_);
|
||||
}
|
||||
|
||||
void clib::pclsync_lib::do_get_pass_from_console(std::string &password) {
|
||||
void
|
||||
clib::pclsync_lib::do_get_pass_from_console(std::string &password) {
|
||||
if (daemon_) {
|
||||
std::cout << "Not able to read password when started as daemon."
|
||||
<< std::endl;
|
||||
|
|
@ -263,7 +326,7 @@ static void status_change(pstatus_t *status) {
|
|||
(int)status->status, status2string(status->status));
|
||||
}
|
||||
|
||||
int clib::pclsync_lib::statrt_crypto(const char *pass, void *rep) {
|
||||
int clib::pclsync_lib::start_crypto(const char *pass, void *rep) {
|
||||
std::cout << "calling startcrypto pass: " << pass << std::endl;
|
||||
get_lib().crypto_pass_ = pass;
|
||||
return lib_setup_cripto();
|
||||
|
|
@ -326,7 +389,7 @@ int clib::pclsync_lib::init() // std::string& username, std::string& password,
|
|||
psync_free(username_old);
|
||||
}
|
||||
|
||||
psync_add_overlay_callback(20, &clib::pclsync_lib::statrt_crypto);
|
||||
psync_add_overlay_callback(20, &clib::pclsync_lib::start_crypto);
|
||||
psync_add_overlay_callback(21, &clib::pclsync_lib::stop_crypto);
|
||||
psync_add_overlay_callback(22, &clib::pclsync_lib::finalize);
|
||||
psync_add_overlay_callback(23, &clib::pclsync_lib::list_sync_folders);
|
||||
|
|
|
|||
|
|
@ -36,70 +36,70 @@
|
|||
struct pstatus_struct_;
|
||||
|
||||
namespace console_client {
|
||||
namespace clibrary {
|
||||
namespace clibrary {
|
||||
|
||||
class pclsync_lib {
|
||||
public:
|
||||
~pclsync_lib();
|
||||
pclsync_lib();
|
||||
class pclsync_lib {
|
||||
public:
|
||||
~pclsync_lib();
|
||||
pclsync_lib();
|
||||
|
||||
// Getters
|
||||
const std::string &get_username() { return username_; }
|
||||
const std::string &get_password() { return password_; }
|
||||
const std::string &get_crypto_pass() { return crypto_pass_; };
|
||||
const std::string &get_mount() { return mount_; }
|
||||
bool crypto_on_;
|
||||
bool save_pass_;
|
||||
bool setup_crypto_;
|
||||
pstatus_struct_ *status_;
|
||||
bool newuser_;
|
||||
status_callback_t status_callback_;
|
||||
bool was_init_;
|
||||
|
||||
// Setters
|
||||
void set_username(const std::string &arg) { username_ = arg; }
|
||||
void set_password(const std::string &arg) { password_ = arg; }
|
||||
void set_crypto_pass(const std::string &arg) { crypto_pass_ = arg; };
|
||||
void set_mount(const std::string &arg) { mount_ = arg; }
|
||||
void set_savepass(bool s) { save_pass_ = s; }
|
||||
void setupsetup_crypto(bool p) { setup_crypto_ = p; }
|
||||
void set_newuser(bool p) { newuser_ = p; }
|
||||
void set_daemon(bool p) { daemon_ = p; }
|
||||
void set_status_callback(status_callback_t p) { status_callback_ = p; }
|
||||
// Getters
|
||||
const std::string &get_username();
|
||||
const std::string &get_password();
|
||||
const std::string &get_crypto_pass();
|
||||
const std::string &get_mount();
|
||||
|
||||
// Console
|
||||
void get_pass_from_console();
|
||||
void get_cryptopass_from_console();
|
||||
// Setters
|
||||
void set_username(const std::string &arg);
|
||||
void set_password(const std::string &arg);
|
||||
void set_crypto_pass(const std::string &arg);
|
||||
void set_mount(const std::string &arg);
|
||||
void set_savepass(bool s);
|
||||
void setupsetup_crypto(bool p);
|
||||
void set_newuser(bool p);
|
||||
void set_daemon(bool p);
|
||||
void set_status_callback(status_callback_t p);
|
||||
|
||||
// API calls
|
||||
int init(); // std::string& username, std::string& password, std::string*
|
||||
// crypto_pass, int setup_crypto = 1, int usesrypto_userpass = 0);
|
||||
static int statrt_crypto(const char *pass, void *rep);
|
||||
static int stop_crypto(const char *path, void *rep);
|
||||
static int finalize(const char *path, void *rep);
|
||||
static int list_sync_folders(const char *path, void *rep);
|
||||
// Singelton
|
||||
static pclsync_lib &get_lib();
|
||||
char *get_token();
|
||||
int logout();
|
||||
int unlink();
|
||||
int login(const char *user, const char *pass, int save);
|
||||
// Singleton
|
||||
static pclsync_lib &get_lib();
|
||||
|
||||
// Console
|
||||
void get_pass_from_console();
|
||||
void get_cryptopass_from_console();
|
||||
|
||||
bool crypto_on_;
|
||||
bool save_pass_;
|
||||
bool setup_crypto_;
|
||||
pstatus_struct_ *status_;
|
||||
bool newuser_;
|
||||
status_callback_t status_callback_;
|
||||
bool was_init_;
|
||||
// API calls
|
||||
int init();
|
||||
// std::string& username, std::string& password, std::string*
|
||||
// crypto_pass, int setup_crypto = 1, int usesrypto_userpass = 0);
|
||||
static int start_crypto(const char *pass, void *rep);
|
||||
static int stop_crypto(const char *path, void *rep);
|
||||
static int finalize(const char *path, void *rep);
|
||||
static int list_sync_folders(const char *path, void *rep);
|
||||
|
||||
private:
|
||||
std::string username_;
|
||||
std::string password_;
|
||||
std::string crypto_pass_;
|
||||
std::string mount_;
|
||||
char *get_token();
|
||||
int logout();
|
||||
int unlink();
|
||||
int login(const char *user, const char *pass, int save);
|
||||
|
||||
bool to_set_mount_;
|
||||
bool daemon_;
|
||||
private:
|
||||
std::string username_;
|
||||
std::string password_;
|
||||
std::string crypto_pass_;
|
||||
std::string mount_;
|
||||
|
||||
private:
|
||||
void do_get_pass_from_console(std::string &password);
|
||||
};
|
||||
|
||||
} // namespace clibrary
|
||||
} // namespace console_client
|
||||
bool to_set_mount_;
|
||||
bool daemon_;
|
||||
|
||||
void do_get_pass_from_console(std::string &password);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // PCLSYNC_LIB_H
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ extern "C" {
|
|||
else return 0;
|
||||
}
|
||||
|
||||
int statrt_crypto (const char* pass) {
|
||||
return cc::pclsync_lib::statrt_crypto (pass, NULL);
|
||||
int start_crypto (const char* pass) {
|
||||
return cc::pclsync_lib::start_crypto (pass, NULL);
|
||||
}
|
||||
int stop_crypto () {
|
||||
return cc::pclsync_lib::stop_crypto (NULL, NULL);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ void psync_fs_pause_until_login();
|
|||
typedef void (*status_callback_t)(int status, const char *stat_string);
|
||||
|
||||
int init();
|
||||
int statrt_crypto(const char *pass);
|
||||
int start_crypto(const char *pass);
|
||||
int stop_crypto();
|
||||
int finalize();
|
||||
char *get_token();
|
||||
|
|
|
|||
Loading…
Reference in New Issue