Skip to content

Commit

Permalink
lib: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed Nov 11, 2023
1 parent 96d0a89 commit fa991e0
Show file tree
Hide file tree
Showing 128 changed files with 6,651 additions and 5,494 deletions.
1,112 changes: 580 additions & 532 deletions src/lib/binrpc/binrpc_api.c

Large diffs are not rendered by default.

70 changes: 29 additions & 41 deletions src/lib/binrpc/binrpc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@

#include "../../modules/ctl/binrpc.h"

struct binrpc_handle {
struct binrpc_handle
{
int socket;
int proto;
int sock_type;
unsigned char* buf;
unsigned char *buf;
int buf_size;
};

struct binrpc_response_handle {
struct binrpc_response_handle
{
unsigned char *reply_buf;
struct binrpc_parse_ctx in_pkt;
};
Expand All @@ -58,11 +60,9 @@ struct binrpc_response_handle {
*
* @return 0 on success, -1 on failure.
*
* */
int binrpc_open_connection(
struct binrpc_handle* handle,
char* name, int port, int proto,
char* reply_socket, char* sock_dir);
* */
int binrpc_open_connection(struct binrpc_handle *handle, char *name, int port,
int proto, char *reply_socket, char *sock_dir);

/**
* Function: binrpc_open_connection_url
Expand All @@ -78,10 +78,10 @@ int binrpc_open_connection(
*
* @return 0 on success, -1 on failure.
*
* */
* */

int binrpc_open_connection_url(struct binrpc_handle *handle, char *url);

int binrpc_open_connection_url(struct binrpc_handle* handle, char* url);

/**
* Function: binrpc_close_connection
*
Expand All @@ -94,7 +94,7 @@ int binrpc_open_connection_url(struct binrpc_handle* handle, char* url);
* @return 0 on success, -1 on failure.
* none
* */
void binrpc_close_connection(struct binrpc_handle* handle);
void binrpc_close_connection(struct binrpc_handle *handle);

/**
* Function: binrpc_send_command
Expand All @@ -113,10 +113,8 @@ void binrpc_close_connection(struct binrpc_handle* handle);
* @return 0 on success, -1 on failure.
*
* */
int binrpc_send_command(
struct binrpc_handle* handle,
char* method, char** args, int arg_count,
struct binrpc_response_handle* resp_handle);
int binrpc_send_command(struct binrpc_handle *handle, char *method, char **args,
int arg_count, struct binrpc_response_handle *resp_handle);

/**
* Function: binrpc_send_command_ex
Expand All @@ -132,9 +130,8 @@ int binrpc_send_command(
* @return 0 on success, -1 on failure.
*
* */
int binrpc_send_command_ex(
struct binrpc_handle* handle, struct binrpc_pkt* pkt,
struct binrpc_response_handle *resp_handle);
int binrpc_send_command_ex(struct binrpc_handle *handle, struct binrpc_pkt *pkt,
struct binrpc_response_handle *resp_handle);

/**
* Function: binrpc_release_response
Expand All @@ -147,9 +144,7 @@ int binrpc_send_command_ex(
* @return 0 on success, -1 on failure.
*
* */
void binrpc_release_response(
struct binrpc_response_handle *resp_handle
);
void binrpc_release_response(struct binrpc_response_handle *resp_handle);

/**
* Function: binrpc_get_response_type
Expand All @@ -159,7 +154,7 @@ void binrpc_release_response(
*
* @return 1 on valid failure response, 0 on valid successfull, -1 on failure.
*
* */
* */
int binrpc_get_response_type(struct binrpc_response_handle *resp_handle);

/*
Expand All @@ -175,12 +170,9 @@ int binrpc_get_response_type(struct binrpc_response_handle *resp_handle);
* @return -1 failure.
*
* */
int binrpc_parse_response(
struct binrpc_val** vals,
int* val_count,
struct binrpc_response_handle *resp_handle
);

int binrpc_parse_response(struct binrpc_val **vals, int *val_count,
struct binrpc_response_handle *resp_handle);

/*
* Function: binrpc_parse_error_response
*
Expand All @@ -195,10 +187,7 @@ int binrpc_parse_response(
*
* */
int binrpc_parse_error_response(
struct binrpc_response_handle *resp_handle,
int *err_no,
char **err
);
struct binrpc_response_handle *resp_handle, int *err_no, char **err);

/**
* Function: binrpc_print_response
Expand All @@ -213,8 +202,9 @@ int binrpc_parse_error_response(
*
* @return 0 on success, -1 on failure
*
* */
int binrpc_print_response(struct binrpc_response_handle *resp_handle, char* fmt);
* */
int binrpc_print_response(
struct binrpc_response_handle *resp_handle, char *fmt);

/**
* Function: binrpc_response_to_text
Expand All @@ -238,10 +228,8 @@ int binrpc_print_response(struct binrpc_response_handle *resp_handle, char* fmt)
* @return 0 on success, -1 on failure
*
* */
int binrpc_response_to_text(
struct binrpc_response_handle *resp_handle,
unsigned char** txt_rsp, int* txt_rsp_len,
char delimiter);
int binrpc_response_to_text(struct binrpc_response_handle *resp_handle,
unsigned char **txt_rsp, int *txt_rsp_len, char delimiter);

/**
* Function: binrpc_set_mallocs
Expand All @@ -255,7 +243,7 @@ int binrpc_response_to_text(
* @param _free [in]: pointer to function that ensures memory deallocation
*
* */
void binrpc_set_mallocs(void* _malloc, void* _realloc, void* _free);
void binrpc_set_mallocs(void *_malloc, void *_realloc, void *_free);

/**
* Function: binrpc_get_last_errs
Expand Down Expand Up @@ -283,6 +271,6 @@ void binrpc_clear_last_err();
* and finally frees the values array
*
* */
void binrpc_free_rpc_array(struct binrpc_val* a, int size);
void binrpc_free_rpc_array(struct binrpc_val *a, int size);

#endif /*BINRPC_API_H_*/
82 changes: 48 additions & 34 deletions src/lib/cds/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,77 +27,91 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

void base64decode(char* src_buf, int src_len, char* tgt_buf, int* tgt_len) {
void base64decode(char *src_buf, int src_len, char *tgt_buf, int *tgt_len)
{
int pos, i, n;
unsigned char c[4];
for (pos=0, i=0, *tgt_len=0; pos < src_len; pos++) {
if (src_buf[pos] >= 'A' && src_buf[pos] <= 'Z')
c[i] = src_buf[pos] - 65; /* <65..90> --> <0..25> */
else if (src_buf[pos] >= 'a' && src_buf[pos] <= 'z')
c[i] = src_buf[pos] - 71; /* <97..122> --> <26..51> */
else if (src_buf[pos] >= '0' && src_buf[pos] <= '9')
c[i] = src_buf[pos] + 4; /* <48..56> --> <52..61> */
else if (src_buf[pos] == '+')
for(pos = 0, i = 0, *tgt_len = 0; pos < src_len; pos++) {
if(src_buf[pos] >= 'A' && src_buf[pos] <= 'Z')
c[i] = src_buf[pos] - 65; /* <65..90> --> <0..25> */
else if(src_buf[pos] >= 'a' && src_buf[pos] <= 'z')
c[i] = src_buf[pos] - 71; /* <97..122> --> <26..51> */
else if(src_buf[pos] >= '0' && src_buf[pos] <= '9')
c[i] = src_buf[pos] + 4; /* <48..56> --> <52..61> */
else if(src_buf[pos] == '+')
c[i] = 62;
else if (src_buf[pos] == '/')
else if(src_buf[pos] == '/')
c[i] = 63;
else /* '=' */
else /* '=' */
c[i] = 64;
i++;
if (pos == src_len-1) {
while (i < 4) {
if(pos == src_len - 1) {
while(i < 4) {
c[i] = 64;
i++;
}
}
if (i==4) {
if (c[0] == 64)
if(i == 4) {
if(c[0] == 64)
n = 0;
else if (c[2] == 64)
else if(c[2] == 64)
n = 1;
else if (c[3] == 64)
else if(c[3] == 64)
n = 2;
else
n = 3;
switch (n) {
switch(n) {
case 3:
tgt_buf[*tgt_len+2] = (char) (((c[2] & 0x03) << 6) | c[3]);
tgt_buf[*tgt_len + 2] = (char)(((c[2] & 0x03) << 6) | c[3]);
/* no break */
case 2:
tgt_buf[*tgt_len+1] = (char) (((c[1] & 0x0F) << 4) | (c[2] >> 2));
tgt_buf[*tgt_len + 1] =
(char)(((c[1] & 0x0F) << 4) | (c[2] >> 2));
/* no break */
case 1:
tgt_buf[*tgt_len+0] = (char) ((c[0] << 2) | (c[1] >> 4));
tgt_buf[*tgt_len + 0] = (char)((c[0] << 2) | (c[1] >> 4));
break;
}
i=0;
*tgt_len+= n;
i = 0;
*tgt_len += n;
}
}
}

void base64encode(char* src_buf, int src_len, char* tgt_buf, int* tgt_len, int quoted) {
static char code64[64+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
void base64encode(
char *src_buf, int src_len, char *tgt_buf, int *tgt_len, int quoted)
{
static char code64[64 + 1] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int pos;
for (pos=0, *tgt_len=0; pos < src_len; pos+=3,*tgt_len+=4) {
tgt_buf[*tgt_len+0] = code64[(unsigned char)src_buf[pos+0] >> 2];
tgt_buf[*tgt_len+1] = code64[(((unsigned char)src_buf[pos+0] & 0x03) << 4) | ((pos+1 < src_len)?((unsigned char)src_buf[pos+1] >> 4):0)];
if (pos+1 < src_len)
tgt_buf[*tgt_len+2] = code64[(((unsigned char)src_buf[pos+1] & 0x0F) << 2) | ((pos+2 < src_len)?((unsigned char)src_buf[pos+2] >> 6):0)];
for(pos = 0, *tgt_len = 0; pos < src_len; pos += 3, *tgt_len += 4) {
tgt_buf[*tgt_len + 0] = code64[(unsigned char)src_buf[pos + 0] >> 2];
tgt_buf[*tgt_len + 1] =
code64[(((unsigned char)src_buf[pos + 0] & 0x03) << 4)
| ((pos + 1 < src_len)
? ((unsigned char)src_buf[pos + 1] >> 4)
: 0)];
if(pos + 1 < src_len)
tgt_buf[*tgt_len + 2] =
code64[(((unsigned char)src_buf[pos + 1] & 0x0F) << 2)
| ((pos + 2 < src_len) ? (
(unsigned char)src_buf[pos + 2] >> 6)
: 0)];
else {
if(!quoted)
(*tgt_len)--;
else
/* this data is going to be quoted */
tgt_buf[*tgt_len+2] = '=';
tgt_buf[*tgt_len + 2] = '=';
}
if (pos+2 < src_len)
tgt_buf[*tgt_len+3] = code64[(unsigned char)src_buf[pos+2] & 0x3F];
if(pos + 2 < src_len)
tgt_buf[*tgt_len + 3] =
code64[(unsigned char)src_buf[pos + 2] & 0x3F];
else {
if(!quoted)
(*tgt_len)--;
else
tgt_buf[*tgt_len+3] = '=';
tgt_buf[*tgt_len + 3] = '=';
}
}
}
5 changes: 3 additions & 2 deletions src/lib/cds/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
#ifndef base64_h
#define base64_h

void base64decode(char* src_buf, int src_len, char* tgt_buf, int* tgt_len);
void base64encode(char* src_buf, int src_len, char* tgt_buf, int* tgt_len, int quoted);
void base64decode(char *src_buf, int src_len, char *tgt_buf, int *tgt_len);
void base64encode(
char *src_buf, int src_len, char *tgt_buf, int *tgt_len, int quoted);

#endif
5 changes: 3 additions & 2 deletions src/lib/cds/cds.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
* @{ */

#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif

#if 0
Expand All @@ -66,7 +67,7 @@ void cds_cleanup();

#endif

/** @} */
/** @} */

#ifdef __cplusplus
}
Expand Down
12 changes: 5 additions & 7 deletions src/lib/cds/dbid.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ void generate_dbid_ptr(dbid_t dst, void *data_ptr)
{
/* TODO: add cluster distinctive member */
/* FIXME: replace sprintf by something more effective */
snprintf(dst, MAX_DBID_LEN, "%px%xx%x",
data_ptr, (int)time(NULL), rand());
snprintf(dst, MAX_DBID_LEN, "%px%xx%x", data_ptr, (int)time(NULL), rand());
}

#ifdef SER
Expand All @@ -21,16 +20,15 @@ void generate_dbid(dbid_t dst)
{
static int cntr = 0;
static pid_t my_pid = -1;
if (my_pid < 0) {

if(my_pid < 0) {
my_pid = getpid();
}

/* TODO: add cluster distinctive member */
/* FIXME: replace sprintf by something more effective */
snprintf(dst, MAX_DBID_LEN, "%xy%xy%xy%x",
my_pid, cntr++, (int)time(NULL), rand());
snprintf(dst, MAX_DBID_LEN, "%xy%xy%xy%x", my_pid, cntr++, (int)time(NULL),
rand());
}

#endif

0 comments on commit fa991e0

Please sign in to comment.