prpc namespace (got rid of confusing "overlay")
This commit is contained in:
parent
a362cd6733
commit
4eef4289f3
|
|
@ -38,11 +38,11 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "control_tools.h"
|
#include "control_tools.h"
|
||||||
#include "pclsync/overlay_client.h"
|
|
||||||
|
|
||||||
#include "pclsync_lib.h"
|
#include "pclsync_lib.h"
|
||||||
#include "pclsync/psynclib.h"
|
|
||||||
#include "pclsync/pshm.h"
|
#include "pclsync/pshm.h"
|
||||||
|
#include "pclsync/pfoldersync.h"
|
||||||
|
#include "pclsync/rpcclient.h"
|
||||||
|
|
||||||
#include "CLI11.hpp"
|
#include "CLI11.hpp"
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ int list_sync_folders() {
|
||||||
errmsz = 0;
|
errmsz = 0;
|
||||||
rval = 0;
|
rval = 0;
|
||||||
|
|
||||||
result = SendCall(LISTSYNC, "", &ret, &errm, &errmsz);
|
result = rpc_call(LISTSYNC, "", &ret, &errm, &errmsz);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
std::cout << "List Sync Folders failed. return is " << ret
|
std::cout << "List Sync Folders failed. return is " << ret
|
||||||
|
|
@ -124,7 +124,7 @@ int start_crypto(const char *pass) {
|
||||||
char *errm;
|
char *errm;
|
||||||
size_t errm_size;
|
size_t errm_size;
|
||||||
|
|
||||||
int result = SendCall(STARTCRYPTO, pass, &ret, &errm, &errm_size);
|
int result = rpc_call(STARTCRYPTO, pass, &ret, &errm, &errm_size);
|
||||||
|
|
||||||
if (result != 0 || ret != 0) {
|
if (result != 0 || ret != 0) {
|
||||||
std::cout << "Start Crypto failed. return is " << ret << " and message is "
|
std::cout << "Start Crypto failed. return is " << ret << " and message is "
|
||||||
|
|
@ -142,7 +142,7 @@ int stop_crypto() {
|
||||||
char *errm;
|
char *errm;
|
||||||
size_t errm_size;
|
size_t errm_size;
|
||||||
|
|
||||||
int result = SendCall(STOPCRYPTO, "", &ret, &errm, &errm_size);
|
int result = rpc_call(STOPCRYPTO, "", &ret, &errm, &errm_size);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
std::cout << "Stop Crypto failed. return is " << ret << " and message is "
|
std::cout << "Stop Crypto failed. return is " << ret << " and message is "
|
||||||
<< (errm ? errm : "no message") << std::endl;
|
<< (errm ? errm : "no message") << std::endl;
|
||||||
|
|
@ -166,7 +166,7 @@ int remove_sync_folder(const char *folderid) {
|
||||||
errmsz = 0;
|
errmsz = 0;
|
||||||
rval = 0;
|
rval = 0;
|
||||||
|
|
||||||
result = SendCall(STOPSYNC, folderid, &ret, &errm, &errmsz);
|
result = rpc_call(STOPSYNC, folderid, &ret, &errm, &errmsz);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
std::cout << "Remove Sync Folder failed with unknown error. return is "
|
std::cout << "Remove Sync Folder failed with unknown error. return is "
|
||||||
<< ret << " and message is " << (errm ? errm : "no message")
|
<< ret << " and message is " << (errm ? errm : "no message")
|
||||||
|
|
@ -197,7 +197,7 @@ int add_sync_folder(std::string localpath, std::string remotepath) {
|
||||||
rval = 0;
|
rval = 0;
|
||||||
|
|
||||||
std::string combinedPaths = localpath + '|' + remotepath;
|
std::string combinedPaths = localpath + '|' + remotepath;
|
||||||
result = SendCall(ADDSYNC, combinedPaths.c_str(), &ret, &errm, &errmsz);
|
result = rpc_call(ADDSYNC, combinedPaths.c_str(), &ret, &errm, &errmsz);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
if (result == -1) {
|
if (result == -1) {
|
||||||
|
|
@ -225,7 +225,7 @@ int finalize() {
|
||||||
char *errm;
|
char *errm;
|
||||||
size_t errm_size;
|
size_t errm_size;
|
||||||
|
|
||||||
SendCall(FINALIZE, "", &ret, &errm, &errm_size);
|
rpc_call(FINALIZE, "", &ret, &errm, &errm_size);
|
||||||
std::cout << "Exiting ..." << std::endl;
|
std::cout << "Exiting ..." << std::endl;
|
||||||
|
|
||||||
if (errm){
|
if (errm){
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
// defines the messaging protocol for pclsync
|
|
||||||
|
|
||||||
#ifndef __POVERLAY_PROTOCOL_H
|
|
||||||
#define __POVERLAY_PROTOCOL_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifndef POVERLAY_SOCK_PATH
|
|
||||||
#define POVERLAY_SOCK_PATH "/tmp/pcloud_unix_soc.sock"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct _message {
|
|
||||||
uint32_t type;
|
|
||||||
uint64_t length;
|
|
||||||
char value[];
|
|
||||||
} message;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -42,11 +42,9 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "pfile.h"
|
#include "prpc.h"
|
||||||
#include "poverlay_protocol.h"
|
|
||||||
|
|
||||||
#include "poverlay.h"
|
|
||||||
#include "ppathstatus.h"
|
#include "ppathstatus.h"
|
||||||
|
|
||||||
#include "plibs.h"
|
#include "plibs.h"
|
||||||
|
|
@ -105,8 +103,8 @@ void psync_overlay_handle_request(void *lpvParam) {
|
||||||
int readbytes; // total bytes read from request
|
int readbytes; // total bytes read from request
|
||||||
char rqbuf[POVERLAY_BUFSIZE]; // request buffer, contains the request message
|
char rqbuf[POVERLAY_BUFSIZE]; // request buffer, contains the request message
|
||||||
char *rqbufp; // request buffer ptr, for convenient iteration
|
char *rqbufp; // request buffer ptr, for convenient iteration
|
||||||
message *request; // request message
|
rpc_message_t *request; // request message
|
||||||
message *response; // response message and payload
|
rpc_message_t *response; // response message and payload
|
||||||
|
|
||||||
request = NULL;
|
request = NULL;
|
||||||
response = NULL;
|
response = NULL;
|
||||||
|
|
@ -120,7 +118,7 @@ void psync_overlay_handle_request(void *lpvParam) {
|
||||||
readbytes += rc;
|
readbytes += rc;
|
||||||
rqbufp = rqbufp + rc;
|
rqbufp = rqbufp + rc;
|
||||||
if (readbytes > 12) {
|
if (readbytes > 12) {
|
||||||
request = (message *)rqbuf;
|
request = (rpc_message_t *)rqbuf;
|
||||||
if (request->length == (uint64_t)readbytes)
|
if (request->length == (uint64_t)readbytes)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -133,8 +131,8 @@ void psync_overlay_handle_request(void *lpvParam) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
request = (message *)rqbuf;
|
request = (rpc_message_t *)rqbuf;
|
||||||
response = (message *)malloc(POVERLAY_BUFSIZE);
|
response = (rpc_message_t *)malloc(POVERLAY_BUFSIZE);
|
||||||
if (request) {
|
if (request) {
|
||||||
psync_overlay_get_response(request, response);
|
psync_overlay_get_response(request, response);
|
||||||
|
|
||||||
|
|
@ -192,8 +190,8 @@ void psync_overlay_init_callbacks() {
|
||||||
memset(callbacks, 0, sizeof(poverlay_callback) * callbacks_size);
|
memset(callbacks, 0, sizeof(poverlay_callback) * callbacks_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void psync_overlay_get_status_response(message *request,
|
static void psync_overlay_get_status_response(rpc_message_t *request,
|
||||||
message *response,
|
rpc_message_t *response,
|
||||||
size_t available_space) {
|
size_t available_space) {
|
||||||
psync_path_status_t stat;
|
psync_path_status_t stat;
|
||||||
|
|
||||||
|
|
@ -220,8 +218,8 @@ static void psync_overlay_get_status_response(message *request,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void psync_overlay_get_overlay_response(message *request,
|
static void psync_overlay_get_overlay_response(rpc_message_t *request,
|
||||||
message *response,
|
rpc_message_t *response,
|
||||||
size_t available_space) {
|
size_t available_space) {
|
||||||
int cbidx; // callback index (based on message type)
|
int cbidx; // callback index (based on message type)
|
||||||
int cbret; // callback return value
|
int cbret; // callback return value
|
||||||
|
|
@ -256,8 +254,8 @@ static void psync_overlay_get_overlay_response(message *request,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void psync_overlay_get_response(message *request,
|
void psync_overlay_get_response(rpc_message_t *request,
|
||||||
message *response) {
|
rpc_message_t *response) {
|
||||||
|
|
||||||
const char *dbgmsg; // debug messages
|
const char *dbgmsg; // debug messages
|
||||||
size_t value_avail; // space available to store value (flexible array)
|
size_t value_avail; // space available to store value (flexible array)
|
||||||
|
|
@ -265,7 +263,7 @@ void psync_overlay_get_response(message *request,
|
||||||
dbgmsg = NULL;
|
dbgmsg = NULL;
|
||||||
memset(response, 0, POVERLAY_BUFSIZE);
|
memset(response, 0, POVERLAY_BUFSIZE);
|
||||||
response->length = 0;
|
response->length = 0;
|
||||||
value_avail = POVERLAY_BUFSIZE - sizeof(message);
|
value_avail = POVERLAY_BUFSIZE - sizeof(rpc_message_t);
|
||||||
|
|
||||||
// never print the crypto password to the logs in plain text
|
// never print the crypto password to the logs in plain text
|
||||||
dbgmsg = (request->type == 20) ? "REDACTED" : request->value;
|
dbgmsg = (request->type == 20) ? "REDACTED" : request->value;
|
||||||
|
|
@ -291,7 +289,7 @@ void psync_overlay_get_response(message *request,
|
||||||
|
|
||||||
// truncate messages that exceed the buffer boundaries
|
// truncate messages that exceed the buffer boundaries
|
||||||
size_t value_length = strnlen(response->value, value_avail);
|
size_t value_length = strnlen(response->value, value_avail);
|
||||||
response->length = sizeof(message) + value_length + 1;
|
response->length = sizeof(rpc_message_t) + value_length + 1;
|
||||||
if (response->length > POVERLAY_BUFSIZE) {
|
if (response->length > POVERLAY_BUFSIZE) {
|
||||||
response->length = POVERLAY_BUFSIZE;
|
response->length = POVERLAY_BUFSIZE;
|
||||||
response->value[value_avail - 1] = '\0';
|
response->value[value_avail - 1] = '\0';
|
||||||
|
|
@ -41,15 +41,24 @@
|
||||||
#define LPVOID void *
|
#define LPVOID void *
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef POVERLAY_SOCK_PATH
|
||||||
|
#define POVERLAY_SOCK_PATH "/tmp/pcloud_unix_soc.sock"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "psynclib.h"
|
#include "psynclib.h"
|
||||||
#include "poverlay_protocol.h"
|
|
||||||
|
|
||||||
extern int overlays_running;
|
extern int overlays_running;
|
||||||
extern int callbacks_running;
|
extern int callbacks_running;
|
||||||
|
|
||||||
|
typedef struct _rpc_message_t {
|
||||||
|
uint32_t type;
|
||||||
|
uint64_t length;
|
||||||
|
char value[];
|
||||||
|
} rpc_message_t;
|
||||||
|
|
||||||
void psync_overlay_main_loop(VOID);
|
void psync_overlay_main_loop(VOID);
|
||||||
void psync_overlay_handle_request(LPVOID);
|
void psync_overlay_handle_request(LPVOID);
|
||||||
void psync_overlay_get_response(message*, message*);
|
void psync_overlay_get_response(rpc_message_t*, rpc_message_t*);
|
||||||
void psync_overlay_stop_overlays();
|
void psync_overlay_stop_overlays();
|
||||||
void psync_overlay_start_overlays();
|
void psync_overlay_start_overlays();
|
||||||
void psync_overlay_stop_overlay_callbacks();
|
void psync_overlay_stop_overlay_callbacks();
|
||||||
|
|
@ -63,7 +63,7 @@
|
||||||
#include "pmemlock.h"
|
#include "pmemlock.h"
|
||||||
#include "pnetlibs.h"
|
#include "pnetlibs.h"
|
||||||
#include "pnotify.h"
|
#include "pnotify.h"
|
||||||
#include "poverlay.h"
|
#include "prpc.h"
|
||||||
#include "pp2p.h"
|
#include "pp2p.h"
|
||||||
#include "ppagecache.h"
|
#include "ppagecache.h"
|
||||||
#include "ppassword.h"
|
#include "ppassword.h"
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,9 @@
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "overlay_client.h"
|
#include "rpcclient.h"
|
||||||
#include "poverlay_protocol.h"
|
|
||||||
#include "plibs.h"
|
#include "plibs.h"
|
||||||
|
#include "prpc.h"
|
||||||
|
|
||||||
#define POVERLAY_BUFSIZE 512
|
#define POVERLAY_BUFSIZE 512
|
||||||
|
|
||||||
|
|
@ -73,34 +73,11 @@
|
||||||
#define POVERLAY_READ_INCOMPLETE -105
|
#define POVERLAY_READ_INCOMPLETE -105
|
||||||
#define POVERLAY_READ_INVALID_RESPONSE -106
|
#define POVERLAY_READ_INVALID_RESPONSE -106
|
||||||
|
|
||||||
int QueryState(pCloud_FileState *state, char *path) {
|
|
||||||
int rep = 0;
|
|
||||||
char *errm;
|
|
||||||
size_t errm_size;
|
|
||||||
|
|
||||||
if (!SendCall(4, path /*IN*/, &rep, &errm, &errm_size)) {
|
|
||||||
debug(D_NOTICE, "QueryState responese rep[%d] path[%s]", rep, path);
|
|
||||||
if (errm)
|
|
||||||
debug(D_NOTICE, "The error is %s", errm);
|
|
||||||
if (rep == 10)
|
|
||||||
*state = FileStateInSync;
|
|
||||||
else if (rep == 12)
|
|
||||||
*state = FileStateInProgress;
|
|
||||||
else if (rep == 11)
|
|
||||||
*state = FileStateNoSync;
|
|
||||||
else
|
|
||||||
*state = FileStateInvalid;
|
|
||||||
} else
|
|
||||||
debug(D_ERROR, "QueryState ERROR rep[%d] path[%s]", rep, path);
|
|
||||||
free(errm);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// socket_connect creates and connects to a unix socket at the
|
// socket_connect creates and connects to a unix socket at the
|
||||||
// specified sockpath. it may write an error message and error message
|
// specified sockpath. it may write an error message and error message
|
||||||
// size to out and out_size, and a "ret" value to ret (i think this is
|
// size to out and out_size, and a "ret" value to ret (i think this is
|
||||||
// redundant maybe...)
|
// redundant maybe...)
|
||||||
int socket_connect(const char *sockpath, char **out, size_t *out_size,
|
static int socket_connect(const char *sockpath, char **out, size_t *out_size,
|
||||||
int *ret) {
|
int *ret) {
|
||||||
int fd;
|
int fd;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
|
|
@ -127,7 +104,7 @@ int socket_connect(const char *sockpath, char **out, size_t *out_size,
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_request(int fd, int msgtype, const char *value, char **out,
|
static int write_request(int fd, int msgtype, const char *value, char **out,
|
||||||
size_t *out_size, int *ret) {
|
size_t *out_size, int *ret) {
|
||||||
uint64_t bytes_written;
|
uint64_t bytes_written;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
@ -135,15 +112,15 @@ int write_request(int fd, int msgtype, const char *value, char **out,
|
||||||
int size;
|
int size;
|
||||||
char *buf;
|
char *buf;
|
||||||
const char *err;
|
const char *err;
|
||||||
message *request;
|
rpc_message_t *request;
|
||||||
char *curbuf;
|
char *curbuf;
|
||||||
|
|
||||||
*ret = 0; // Initialize ret to 0
|
*ret = 0; // Initialize ret to 0
|
||||||
|
|
||||||
len = strlen(value);
|
len = strlen(value);
|
||||||
size = sizeof(message) + len + 1;
|
size = sizeof(rpc_message_t) + len + 1;
|
||||||
buf = (char *)malloc(size);
|
buf = (char *)malloc(size);
|
||||||
request = (message *)buf;
|
request = (rpc_message_t *)buf;
|
||||||
memset(request, 0, size);
|
memset(request, 0, size);
|
||||||
request->type = msgtype;
|
request->type = msgtype;
|
||||||
strncpy(request->value, value, len + 1);
|
strncpy(request->value, value, len + 1);
|
||||||
|
|
@ -176,11 +153,11 @@ int write_request(int fd, int msgtype, const char *value, char **out,
|
||||||
return *ret;
|
return *ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_response(int fd, char **out, size_t *out_size, int *ret) {
|
static int read_response(int fd, char **out, size_t *out_size, int *ret) {
|
||||||
message *msg;
|
rpc_message_t *msg;
|
||||||
ssize_t bytes_read;
|
ssize_t bytes_read;
|
||||||
|
|
||||||
msg = (message *)malloc(POVERLAY_BUFSIZE);
|
msg = (rpc_message_t *)malloc(POVERLAY_BUFSIZE);
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
const char *error_msg = "Memory allocation failed";
|
const char *error_msg = "Memory allocation failed";
|
||||||
*out = strdup(error_msg);
|
*out = strdup(error_msg);
|
||||||
|
|
@ -208,8 +185,31 @@ int read_response(int fd, char **out, size_t *out_size, int *ret) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rpc_get_state(pCloud_FileState *state, char *path) {
|
||||||
|
int rep = 0;
|
||||||
|
char *errm;
|
||||||
|
size_t errm_size;
|
||||||
|
|
||||||
|
if (!rpc_call(4, path /*IN*/, &rep, &errm, &errm_size)) {
|
||||||
|
debug(D_NOTICE, "rpc_get_state responese rep[%d] path[%s]", rep, path);
|
||||||
|
if (errm)
|
||||||
|
debug(D_NOTICE, "The error is %s", errm);
|
||||||
|
if (rep == 10)
|
||||||
|
*state = FileStateInSync;
|
||||||
|
else if (rep == 12)
|
||||||
|
*state = FileStateInProgress;
|
||||||
|
else if (rep == 11)
|
||||||
|
*state = FileStateNoSync;
|
||||||
|
else
|
||||||
|
*state = FileStateInvalid;
|
||||||
|
} else
|
||||||
|
debug(D_ERROR, "rpc_get_state ERROR rep[%d] path[%s]", rep, path);
|
||||||
|
free(errm);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// path contains the input argument(s).
|
// path contains the input argument(s).
|
||||||
int SendCall(int id, const char *path, int *ret, char **errm, size_t *errmsz) {
|
int rpc_call(int id, const char *path, int *ret, char **errm, size_t *errmsz) {
|
||||||
int result;
|
int result;
|
||||||
int sockfd;
|
int sockfd;
|
||||||
|
|
||||||
|
|
@ -48,8 +48,8 @@ typedef enum _pCloud_FileState {
|
||||||
FileStateInvalid
|
FileStateInvalid
|
||||||
} pCloud_FileState;
|
} pCloud_FileState;
|
||||||
|
|
||||||
int QueryState(pCloud_FileState *, char *);
|
int rpc_get_state(pCloud_FileState *, char *);
|
||||||
int SendCall(int id, const char *, int *, char **, size_t *);
|
int rpc_call(int id, const char *, int *, char **, size_t *);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
@ -37,9 +37,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "poverlay_protocol.h"
|
#include "prpc.h"
|
||||||
|
|
||||||
#include "poverlay.h"
|
|
||||||
#include "psynclib.h"
|
#include "psynclib.h"
|
||||||
#include "pshm.h"
|
#include "pshm.h"
|
||||||
#include "pdevice.h"
|
#include "pdevice.h"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue