Skip to content

Commit

Permalink
[#19] Integrate uncrustify
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Mar 18, 2022
1 parent 0eda9a5 commit 4e61015
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 93 deletions.
19 changes: 9 additions & 10 deletions src/admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
static char CHARS[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', '{', ']', '}', '\\', '|', ';', ':',
'\'', '\"', ',', '<', '.', '>', '/', '?'};
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', '{', ']', '}', '\\', '|', ';', ':',
'\'', '\"', ',', '<', '.', '>', '/', '?'};

static int master_key(char* password, bool generate_pwd, int pwd_length);
static int add_user(char* users_path, char* username, char* password, bool generate_pwd, int pwd_length);
Expand Down Expand Up @@ -121,11 +121,11 @@ main(int argc, char** argv)
{
static struct option long_options[] =
{
{"user", required_argument, 0, 'U'},
{"password", required_argument, 0, 'P'},
{"file", required_argument, 0, 'f'},
{"generate", no_argument, 0, 'g'},
{"length", required_argument, 0, 'l'},
{"user", required_argument, 0, 'U'},
{"password", required_argument, 0, 'P'},
{"file", required_argument, 0, 'f'},
{"generate", no_argument, 0, 'g'},
{"length", required_argument, 0, 'l'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, '?'}
};
Expand Down Expand Up @@ -342,7 +342,6 @@ master_key(char* password, bool generate_pwd, int pwd_length)
}
}


file = fopen(&buf[0], "w+");
if (file == NULL)
{
Expand All @@ -354,13 +353,13 @@ master_key(char* password, bool generate_pwd, int pwd_length)
{
if (!generate_pwd)
{
while( password == NULL )
while (password == NULL)
{
printf("Master key (will not echo): ");
password = pgagroal_get_password();
printf("\n");

if (password != NULL && strlen(password) < MIN_PASSWORD_LENGTH )
if (password != NULL && strlen(password) < MIN_PASSWORD_LENGTH)
{
printf("Invalid key length, must be at least %d chars.\n", MIN_PASSWORD_LENGTH );
free(password);
Expand Down
12 changes: 6 additions & 6 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ main(int argc, char** argv)
{
static struct option long_options[] =
{
{"config", required_argument, 0, 'c'},
{"host", required_argument, 0, 'h'},
{"port", required_argument, 0, 'p'},
{"user", required_argument, 0, 'U'},
{"password", required_argument, 0, 'P'},
{"logfile", required_argument, 0, 'L'},
{"config", required_argument, 0, 'c'},
{"host", required_argument, 0, 'h'},
{"port", required_argument, 0, 'p'},
{"user", required_argument, 0, 'U'},
{"password", required_argument, 0, 'P'},
{"logfile", required_argument, 0, 'L'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, '?'}
Expand Down
5 changes: 2 additions & 3 deletions src/include/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ extern "C" {

#define pgagroal_log_trace(...) pgagroal_log_line(PGAGROAL_LOGGING_LEVEL_DEBUG5, __FILE__, __LINE__, __VA_ARGS__)
#define pgagroal_log_debug(...) pgagroal_log_line(PGAGROAL_LOGGING_LEVEL_DEBUG1, __FILE__, __LINE__, __VA_ARGS__)
#define pgagroal_log_info(...) pgagroal_log_line(PGAGROAL_LOGGING_LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__)
#define pgagroal_log_warn(...) pgagroal_log_line(PGAGROAL_LOGGING_LEVEL_WARN, __FILE__, __LINE__, __VA_ARGS__)
#define pgagroal_log_info(...) pgagroal_log_line(PGAGROAL_LOGGING_LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__)
#define pgagroal_log_warn(...) pgagroal_log_line(PGAGROAL_LOGGING_LEVEL_WARN, __FILE__, __LINE__, __VA_ARGS__)
#define pgagroal_log_error(...) pgagroal_log_line(PGAGROAL_LOGGING_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
#define pgagroal_log_fatal(...) pgagroal_log_line(PGAGROAL_LOGGING_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)

Expand Down Expand Up @@ -91,4 +91,3 @@ pgagroal_log_mem(void* data, size_t size);
#endif

#endif

1 change: 0 additions & 1 deletion src/include/pgagroal.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ struct prometheus_connection
atomic_ullong query_count; /**< The number of queries per connection */
} __attribute__ ((aligned (64)));


/** @struct
* Defines the Prometheus metrics
*/
Expand Down
1 change: 0 additions & 1 deletion src/include/prometheus.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,3 @@ pgagroal_prometheus_failed_servers(void);
#endif

#endif

1 change: 0 additions & 1 deletion src/include/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ pgagroal_remote_management(int fd, char* address);
#endif

#endif

1 change: 0 additions & 1 deletion src/include/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,3 @@ pgagroal_worker(int fd, char* address, char** argv);
#endif

#endif

2 changes: 1 addition & 1 deletion src/libpgagroal/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,7 @@ as_logging_level(char* str)
{
if (strlen(str) > strlen("debug"))
{
debug_value = (char*) malloc( (strlen(str) - strlen("debug")) * sizeof(char));
debug_value = (char*) malloc((strlen(str) - strlen("debug")) * sizeof(char));
memcpy(debug_value, str + sizeof("debug") - 1, strlen(str) - strlen("debug") + 1);
debug_level = atoi(debug_value);
}
Expand Down
41 changes: 21 additions & 20 deletions src/libpgagroal/management.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

#define MANAGEMENT_HEADER_SIZE 5


static int read_complete(SSL* ssl, int socket, void* buf, size_t size);
static int write_complete(SSL* ssl, int socket, void* buf, size_t size);
static int write_socket(int socket, void* buf, size_t size);
Expand Down Expand Up @@ -118,7 +117,7 @@ pgagroal_management_read_payload(int socket, signed char id, int* payload_i, cha
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_control = cmptr;
msg.msg_control = cmptr;
msg.msg_controllen = CMSG_SPACE(sizeof(int));
msg.msg_flags = 0;

Expand Down Expand Up @@ -245,19 +244,19 @@ pgagroal_management_transfer_connection(int32_t slot)
memset(&buf2[0], 0, sizeof(buf2));

iov[0].iov_base = &buf2[0];
iov[0].iov_len = sizeof(buf2);
iov[0].iov_len = sizeof(buf2);

cmptr = malloc(CMSG_SPACE(sizeof(int)));
memset(cmptr, 0, CMSG_SPACE(sizeof(int)));
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
cmptr->cmsg_len = CMSG_LEN(sizeof(int));

msg.msg_name = NULL;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_control = cmptr;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_control = cmptr;
msg.msg_controllen = CMSG_SPACE(sizeof(int));
msg.msg_flags = 0;
*(int*)CMSG_DATA(cmptr) = config->connections[slot].fd;
Expand Down Expand Up @@ -1106,17 +1105,17 @@ pgagroal_management_client_fd(int32_t slot, pid_t pid)

/* Write file descriptor */
iov[0].iov_base = buf;
iov[0].iov_len = 2;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_name = NULL;
iov[0].iov_len = 2;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_name = NULL;
msg.msg_namelen = 0;

cmptr = malloc(CMSG_LEN(sizeof(int)));
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
msg.msg_control = cmptr;
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
msg.msg_control = cmptr;
msg.msg_controllen = CMSG_LEN(sizeof(int));
*(int*)CMSG_DATA(cmptr) = config->connections[slot].fd;
buf[1] = 0; /* zero status means OK */
Expand Down Expand Up @@ -1368,7 +1367,8 @@ write_socket(int socket, void* buf, size_t size)
break;
}
}
} while (keep_write);
}
while (keep_write);

return 1;
}
Expand Down Expand Up @@ -1450,7 +1450,8 @@ write_ssl(SSL* ssl, void* buf, size_t size)
return 1;
}
}
} while (keep_write);
}
while (keep_write);

return 1;
}
Expand Down
12 changes: 8 additions & 4 deletions src/libpgagroal/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,8 @@ read_message(int socket, bool block, int timeout, struct message** msg)
errno = 0;
}
}
} while (keep_read);
}
while (keep_read);

if (unlikely(timeout > 0))
{
Expand Down Expand Up @@ -1224,7 +1225,8 @@ write_message(int socket, struct message* msg)
break;
}
}
} while (keep_write);
}
while (keep_write);

return MESSAGE_STATUS_ERROR;
}
Expand Down Expand Up @@ -1304,7 +1306,8 @@ ssl_read_message(SSL* ssl, int timeout, struct message** msg)
}
ERR_clear_error();
}
} while (keep_read);
}
while (keep_read);

return MESSAGE_STATUS_ERROR;
}
Expand Down Expand Up @@ -1396,7 +1399,8 @@ ssl_write_message(SSL* ssl, struct message* msg)
return MESSAGE_STATUS_ERROR;
}
}
} while (keep_write);
}
while (keep_write);

return MESSAGE_STATUS_ERROR;
}
3 changes: 2 additions & 1 deletion src/libpgagroal/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ pgagroal_remote_management(int client_fd, char* address)
}

status = pgagroal_write_message(client_ssl, client_fd, msg);
} while (status == MESSAGE_STATUS_OK);
}
while (status == MESSAGE_STATUS_OK);
break;
case MANAGEMENT_FLUSH:
case MANAGEMENT_RESET_SERVER:
Expand Down
9 changes: 5 additions & 4 deletions src/libpgagroal/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,8 @@ pgagroal_remote_management_scram_sha256(char* username, char* password, int serv
}
ERR_clear_error();
}
} while (status != 1);
}
while (status != 1);
}
}
}
Expand Down Expand Up @@ -4517,7 +4518,7 @@ static int
create_ssl_server(SSL_CTX* ctx, int socket, SSL** ssl)
{
SSL* s = NULL;
STACK_OF(X509_NAME) *root_cert_list = NULL;
STACK_OF(X509_NAME) * root_cert_list = NULL;
struct configuration* config;

config = (struct configuration*)shmem;
Expand Down Expand Up @@ -5360,7 +5361,6 @@ auth_query_get_password(int socket, SSL* server_ssl, char* username, char* datab
return 1;
}


static int
auth_query_client_md5(SSL* c_ssl, int client_fd, char* username, char* hash, int slot)
{
Expand Down Expand Up @@ -5821,7 +5821,8 @@ create_client_tls_connection(int fd, SSL** ssl)
}
ERR_clear_error();
}
} while (status != 1);
}
while (status != 1);

*ssl = s;

Expand Down
2 changes: 1 addition & 1 deletion src/libpgagroal/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ pgagroal_server_force_failover(int server)
{
prev_state = atomic_exchange(&config->servers[server].state, SERVER_FAILOVER);

if (prev_state == SERVER_NOTINIT || prev_state == SERVER_NOTINIT_PRIMARY || prev_state == SERVER_PRIMARY || prev_state == SERVER_REPLICA)
if (prev_state == SERVER_NOTINIT || prev_state == SERVER_NOTINIT_PRIMARY || prev_state == SERVER_PRIMARY || prev_state == SERVER_REPLICA)
{
return failover(server);
}
Expand Down
17 changes: 8 additions & 9 deletions src/libpgagroal/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pgagroal_read_int16(void* data)
*((unsigned char*)(data + 1))};

int16_t res = (int16_t)((bytes[0] << 8)) |
((bytes[1] ));
((bytes[1]));

return res;
}
Expand All @@ -301,8 +301,8 @@ pgagroal_read_int32(void* data)

int32_t res = (int32_t)((bytes[0] << 24)) |
((bytes[1] << 16)) |
((bytes[2] << 8)) |
((bytes[3] ));
((bytes[2] << 8)) |
((bytes[3]));

return res;
}
Expand All @@ -325,8 +325,8 @@ pgagroal_read_long(void* data)
(((long)bytes[3]) << 32) |
(((long)bytes[4]) << 24) |
(((long)bytes[5]) << 16) |
(((long)bytes[6]) << 8) |
(((long)bytes[7]) );
(((long)bytes[6]) << 8) |
(((long)bytes[7]));

return res;
}
Expand All @@ -337,7 +337,6 @@ pgagroal_read_string(void* data)
return (char*)data;
}


void
pgagroal_write_byte(void* data, signed char b)
{
Expand Down Expand Up @@ -398,8 +397,8 @@ unsigned int
pgagroal_swap(unsigned int i)
{
return ((i << 24) & 0xff000000) |
((i << 8) & 0x00ff0000) |
((i >> 8) & 0x0000ff00) |
((i << 8) & 0x00ff0000) |
((i >> 8) & 0x0000ff00) |
((i >> 24) & 0x000000ff);
}

Expand Down Expand Up @@ -690,7 +689,7 @@ pgagroal_base64_decode(char* encoded, size_t encoded_length, char** raw, int* ra
BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL);

index = 0;
while (0 < BIO_read(b64_bio, decoded + index, 1) )
while (0 < BIO_read(b64_bio, decoded + index, 1))
{
index++;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ main(int argc, char** argv)
{
static struct option long_options[] =
{
{"config", required_argument, 0, 'c'},
{"config", required_argument, 0, 'c'},
{"hba", required_argument, 0, 'a'},
{"limit", required_argument, 0, 'l'},
{"users", required_argument, 0, 'u'},
Expand Down Expand Up @@ -1934,7 +1934,7 @@ create_pidfile(void)
if (strlen(config->pidfile) == 0)
{
// no pidfile set, use a default one
snprintf(config->pidfile, sizeof( config->pidfile ), "%s/pgagraol.%d.pid",
snprintf(config->pidfile, sizeof(config->pidfile), "%s/pgagraol.%d.pid",
config->unix_socket_dir,
config->port);
pgagroal_log_debug("PID file automatically set to: [%s]", config->pidfile);
Expand Down
Loading

0 comments on commit 4e61015

Please sign in to comment.