diff --git a/src/cli.c b/src/cli.c index 5cc1a141..91db9c0d 100644 --- a/src/cli.c +++ b/src/cli.c @@ -928,7 +928,7 @@ display_helper(char* command) else if (//!strcmp(command, COMMAND_CONFIG_GET) || //!strcmp(command, COMMAND_CONFIG_LS) || //!strcmp(command, COMMAND_CONFIG_SET) || - !strcmp(command, COMMAND_RELOAD)) + !strcmp(command, COMMAND_RELOAD)) { help_conf(); } diff --git a/src/include/utils.h b/src/include/utils.h index 431d812b..704119a5 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -516,10 +516,10 @@ bool pgagroal_compare_string(const char* str1, const char* str2); /** -* Escape a string -* @param str The original string -* @return The escaped string -*/ + * Escape a string + * @param str The original string + * @return The escaped string + */ char* pgagroal_escape_string(char* str); diff --git a/src/libpgagroal/aes.c b/src/libpgagroal/aes.c index f48d3387..80e895f0 100644 --- a/src/libpgagroal/aes.c +++ b/src/libpgagroal/aes.c @@ -38,7 +38,6 @@ static const EVP_CIPHER* (*get_cipher(int mode))(void); static int encrypt_decrypt_buffer(unsigned char* origin_buffer, size_t origin_size, unsigned char** res_buffer, size_t* res_size, int enc, int mode); - int pgagroal_encrypt(char* plaintext, char* password, char** ciphertext, int* ciphertext_length, int mode) { diff --git a/src/libpgagroal/configuration.c b/src/libpgagroal/configuration.c index 82adc84d..5792e7b3 100644 --- a/src/libpgagroal/configuration.c +++ b/src/libpgagroal/configuration.c @@ -1590,7 +1590,7 @@ pgagroal_read_admins_configuration(void* shm, char* filename) goto error; } - if (pgagroal_decrypt(decoded, decoded_length, master_key, &password, ENCRYPTION_AES_256_CBC)) + if (pgagroal_decrypt(decoded, decoded_length, master_key, &password, ENCRYPTION_AES_256_CBC)) { status = PGAGROAL_CONFIGURATION_STATUS_CANNOT_DECRYPT; goto error; @@ -2586,7 +2586,7 @@ transfer_configuration(struct main_configuration* config, struct main_configurat config->common.metrics_cache_max_age = reload->common.metrics_cache_max_age; if (restart_int("metrics_cache_max_size", config->common.metrics_cache_max_size, reload->common.metrics_cache_max_size)) { - changed= true; + changed = true; } config->management = reload->management; diff --git a/src/libpgagroal/connection.c b/src/libpgagroal/connection.c index 6a17818b..69955a41 100644 --- a/src/libpgagroal/connection.c +++ b/src/libpgagroal/connection.c @@ -53,7 +53,6 @@ static int write_complete(SSL* ssl, int socket, void* buf, size_t size); static int write_socket(int socket, void* buf, size_t size); static int write_ssl(SSL* ssl, void* buf, size_t size); - int pgagroal_connection_get(int* client_fd) { @@ -72,7 +71,7 @@ pgagroal_connection_get(int* client_fd) } *client_fd = fd; - + return 0; error: @@ -102,7 +101,7 @@ pgagroal_connection_get_pid(pid_t pid, int* client_fd) } *client_fd = fd; - + free(f); return 0; @@ -114,7 +113,6 @@ pgagroal_connection_get_pid(pid_t pid, int* client_fd) return 1; } - int pgagroal_connection_id_write(int client_fd, int id) { @@ -141,7 +139,7 @@ int pgagroal_connection_id_read(int client_fd, int* id) { char buf4[4]; - + *id = -1; memset(&buf4[0], 0, sizeof(buf4)); @@ -231,7 +229,7 @@ pgagroal_connection_transfer_read(int client_fd, int* slot, int* fd) struct cmsghdr* cmptr = NULL; struct iovec iov[1]; struct msghdr msg; - + *slot = -1; *fd = -1; @@ -279,7 +277,7 @@ pgagroal_connection_transfer_read(int client_fd, int* slot, int* fd) *fd = *(int*)CMSG_DATA(cmptr); free(cmptr); - + return 0; error: @@ -318,7 +316,7 @@ int pgagroal_connection_slot_read(int client_fd, int32_t* slot) { char buf4[4]; - + *slot = -1; memset(&buf4[0], 0, sizeof(buf4)); @@ -364,7 +362,7 @@ int pgagroal_connection_socket_read(int client_fd, int* socket) { char buf4[4]; - + *socket = -1; memset(&buf4[0], 0, sizeof(buf4)); @@ -410,7 +408,7 @@ int pgagroal_connection_pid_read(int client_fd, pid_t* pid) { char buf4[4]; - + *pid = -1; memset(&buf4[0], 0, sizeof(buf4)); @@ -637,7 +635,6 @@ write_ssl(SSL* ssl, void* buf, size_t size) return 1; } - /* int */ /* pgagroal_management_client_done(pid_t pid) */ /* { */ @@ -681,10 +678,6 @@ write_ssl(SSL* ssl, void* buf, size_t size) /* return 1; */ /* } */ - - - - /* int */ /* pgagroal_management_client_fd(int32_t slot, pid_t pid) */ /* { */ @@ -757,7 +750,6 @@ write_ssl(SSL* ssl, void* buf, size_t size) /* return 1; */ /* } */ - /* int */ /* pgagroal_management_remove_fd(int32_t slot, int socket, pid_t pid) */ /* { */ @@ -810,7 +802,6 @@ write_ssl(SSL* ssl, void* buf, size_t size) /* return 1; */ /* } */ - /* /\* */ /* * Utility function to convert PGAGROAL_VERSION into a number. */ /* * The major version is represented by a single digit. */ @@ -899,7 +890,6 @@ write_ssl(SSL* ssl, void* buf, size_t size) /* return 0; */ /* } */ - /* /\* */ /* * Utility function to convert command into a string. */ /* *\/ */ diff --git a/src/libpgagroal/management.c b/src/libpgagroal/management.c index eff931ac..2bdf6bf3 100644 --- a/src/libpgagroal/management.c +++ b/src/libpgagroal/management.c @@ -369,7 +369,6 @@ pgagroal_management_request_details(SSL* ssl, int socket, uint8_t compression, u return 1; } - int pgagroal_management_request_ping(SSL* ssl, int socket, uint8_t compression, uint8_t encryption, int32_t output_format) { diff --git a/src/libpgagroal/memory.c b/src/libpgagroal/memory.c index d69ed16d..63ca7725 100644 --- a/src/libpgagroal/memory.c +++ b/src/libpgagroal/memory.c @@ -64,7 +64,7 @@ pgagroal_memory_init(void) goto error; } } - + if (data == NULL) { data = calloc(1, DEFAULT_BUFFER_SIZE); diff --git a/src/libpgagroal/pool.c b/src/libpgagroal/pool.c index be571c0d..670d4a26 100644 --- a/src/libpgagroal/pool.c +++ b/src/libpgagroal/pool.c @@ -549,7 +549,7 @@ pgagroal_kill_connection(int slot, SSL* ssl) { result = 1; } - + pgagroal_disconnect(transfer_fd); if (ssl != NULL) @@ -1020,7 +1020,7 @@ pgagroal_request_flush(SSL* ssl, int client_fd, uint8_t compression, uint8_t enc char* database = NULL; start_time = time(NULL); - + req = (struct json*)pgagroal_json_get(payload, MANAGEMENT_CATEGORY_REQUEST); mode = (int)pgagroal_json_get(req, MANAGEMENT_ARGUMENT_MODE); database = (char*)pgagroal_json_get(req, MANAGEMENT_ARGUMENT_DATABASE); diff --git a/src/libpgagroal/status.c b/src/libpgagroal/status.c index 81284aec..f2233179 100644 --- a/src/libpgagroal/status.c +++ b/src/libpgagroal/status.c @@ -105,7 +105,7 @@ pgagroal_status_details(SSL* ssl, int client_fd, uint8_t compression, uint8_t en pgagroal_memory_init(); pgagroal_start_logging(); - + start_time = time(NULL); if (pgagroal_management_create_response(payload, -1, &response)) @@ -223,7 +223,7 @@ status_details(bool details, struct json* response) struct json* js = NULL; pgagroal_json_create(&js); - + pgagroal_json_put(js, MANAGEMENT_ARGUMENT_DATABASE, (uintptr_t)config->limits[i].database, ValueString); pgagroal_json_put(js, MANAGEMENT_ARGUMENT_USERNAME, (uintptr_t)config->limits[i].username, ValueString); @@ -232,12 +232,12 @@ status_details(bool details, struct json* response) pgagroal_json_put(js, MANAGEMENT_ARGUMENT_MAX_CONNECTIONS, (uintptr_t)config->limits[i].max_size, ValueUInt32); pgagroal_json_put(js, MANAGEMENT_ARGUMENT_INITIAL_CONNECTIONS, (uintptr_t)config->limits[i].initial_size, ValueUInt32); pgagroal_json_put(js, MANAGEMENT_ARGUMENT_MIN_CONNECTIONS, (uintptr_t)config->limits[i].min_size, ValueUInt32); - + pgagroal_json_append(limits, (uintptr_t)js, ValueJSON); } pgagroal_json_put(response, MANAGEMENT_ARGUMENT_LIMITS, (uintptr_t)limits, ValueJSON); - + pgagroal_json_create(&databases); for (int i = 0; i < NUMBER_OF_DISABLED; i++) @@ -264,19 +264,19 @@ status_details(bool details, struct json* response) pgagroal_json_create(&js); pgagroal_json_put(js, MANAGEMENT_ARGUMENT_DATABASE, (uintptr_t)"*", ValueString); - pgagroal_json_put(js, MANAGEMENT_ARGUMENT_ENABLED, (uintptr_t)!config->all_disabled, ValueBool); + pgagroal_json_put(js, MANAGEMENT_ARGUMENT_ENABLED, (uintptr_t) !config->all_disabled, ValueBool); pgagroal_json_append(databases, (uintptr_t)js, ValueJSON); } - + pgagroal_json_put(response, MANAGEMENT_ARGUMENT_DATABASES, (uintptr_t)databases, ValueJSON); - + for (int i = 0; i < config->max_connections; i++) { struct json* js = NULL; pgagroal_json_create(&js); - + pgagroal_json_put(js, MANAGEMENT_ARGUMENT_START_TIME, (uintptr_t)config->connections[i].start_time, ValueInt64); pgagroal_json_put(js, MANAGEMENT_ARGUMENT_TIMESTAMP, (uintptr_t)config->connections[i].timestamp, ValueInt64); @@ -286,7 +286,7 @@ status_details(bool details, struct json* response) pgagroal_json_put(js, MANAGEMENT_ARGUMENT_DATABASE, (uintptr_t)config->connections[i].database, ValueString); pgagroal_json_put(js, MANAGEMENT_ARGUMENT_USERNAME, (uintptr_t)config->connections[i].username, ValueString); pgagroal_json_put(js, MANAGEMENT_ARGUMENT_APPNAME, (uintptr_t)config->connections[i].appname, ValueString); - + pgagroal_json_append(connections, (uintptr_t)js, ValueJSON); } diff --git a/src/libpgagroal/utils.c b/src/libpgagroal/utils.c index 26fb2712..86e870bc 100644 --- a/src/libpgagroal/utils.c +++ b/src/libpgagroal/utils.c @@ -1272,30 +1272,30 @@ pgagroal_escape_string(char* str) { switch (str[i]) { - case '\\': - case '\"': - translated_ec_string[idx] = '\\'; - idx++; - translated_ec_string[idx] = str[i]; - break; - case '\n': - translated_ec_string[idx] = '\\'; - idx++; - translated_ec_string[idx] = 'n'; - break; - case '\t': - translated_ec_string[idx] = '\\'; - idx++; - translated_ec_string[idx] = 't'; - break; - case '\r': - translated_ec_string[idx] = '\\'; - idx++; - translated_ec_string[idx] = 'r'; - break; - default: - translated_ec_string[idx] = str[i]; - break; + case '\\': + case '\"': + translated_ec_string[idx] = '\\'; + idx++; + translated_ec_string[idx] = str[i]; + break; + case '\n': + translated_ec_string[idx] = '\\'; + idx++; + translated_ec_string[idx] = 'n'; + break; + case '\t': + translated_ec_string[idx] = '\\'; + idx++; + translated_ec_string[idx] = 't'; + break; + case '\r': + translated_ec_string[idx] = '\\'; + idx++; + translated_ec_string[idx] = 'r'; + break; + default: + translated_ec_string[idx] = str[i]; + break; } } translated_ec_string[idx] = '\0'; // terminator diff --git a/src/libpgagroal/zstandard_compression.c b/src/libpgagroal/zstandard_compression.c index 016405c5..1b718291 100644 --- a/src/libpgagroal/zstandard_compression.c +++ b/src/libpgagroal/zstandard_compression.c @@ -112,4 +112,3 @@ pgagroal_zstdd_string(unsigned char* compressed_buffer, size_t compressed_size, return 0; } - diff --git a/src/main.c b/src/main.c index 053aafd8..20fac745 100644 --- a/src/main.c +++ b/src/main.c @@ -1472,7 +1472,7 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) struct json* res = NULL; struct json* databases = NULL; char* database = NULL; - + pgagroal_log_debug("pgagroal: Management enabledb: "); pgagroal_pool_status(); @@ -1483,7 +1483,7 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) pgagroal_management_create_response(payload, -1, &res); pgagroal_json_create(&databases); - + if (!strcmp("*", database)) { struct json* js = NULL; @@ -1533,7 +1533,7 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) struct json* res = NULL; struct json* databases = NULL; char* database = NULL; - + pgagroal_log_debug("pgagroal: Management disabledb: "); pgagroal_pool_status(); @@ -1598,7 +1598,7 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) start_time = time(NULL); config->gracefully = true; - + end_time = time(NULL); pgagroal_management_response_ok(NULL, client_fd, start_time, end_time, compression, encryption, payload); @@ -1659,7 +1659,6 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) pgagroal_log_debug("pgagroal: Management details"); pgagroal_pool_status(); - pid = fork(); if (pid == -1) { @@ -1700,7 +1699,7 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) start_time = time(NULL); pgagroal_prometheus_clear(); - + end_time = time(NULL); pgagroal_management_response_ok(NULL, client_fd, start_time, end_time, compression, encryption, payload); @@ -1711,7 +1710,7 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) pgagroal_log_debug("pgagroal: Management clear server"); char* server = NULL; struct json* req = NULL; - + start_time = time(NULL); req = (struct json*)pgagroal_json_get(payload, MANAGEMENT_CATEGORY_REQUEST); @@ -1719,7 +1718,7 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) pgagroal_server_clear(server); pgagroal_prometheus_failed_servers(); - + end_time = time(NULL); pgagroal_management_response_ok(NULL, client_fd, start_time, end_time, compression, encryption, payload); @@ -1731,7 +1730,7 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) signed char server_state; char* server = NULL; struct json* req = NULL; - + start_time = time(NULL); req = (struct json*)pgagroal_json_get(payload, MANAGEMENT_CATEGORY_REQUEST); @@ -1776,7 +1775,7 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) pgagroal_log_debug("pgagroal: Management reload"); start_time = time(NULL); - + restart = reload_configuration(); pgagroal_management_create_response(payload, -1, &res); @@ -1810,9 +1809,9 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) char* username = NULL; struct json* req = NULL; struct json* res = NULL; - + start_time = time(NULL); - + req = (struct json*)pgagroal_json_get(payload, MANAGEMENT_CATEGORY_REQUEST); username = (char*)pgagroal_json_get(req, MANAGEMENT_ARGUMENT_USERNAME); @@ -1823,9 +1822,9 @@ accept_mgt_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) index = i; } } - + pgagroal_management_create_response(payload, -1, &res); - + pgagroal_json_put(res, MANAGEMENT_ARGUMENT_USERNAME, (uintptr_t)username, ValueString); if (index != -1) @@ -1972,7 +1971,7 @@ accept_transfer_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) } pgagroal_disconnect(c_fd); - + c = c->next; } } @@ -2025,7 +2024,7 @@ accept_transfer_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) } pgagroal_disconnect(c_fd); - + c = c->next; } @@ -2055,7 +2054,7 @@ accept_transfer_cb(struct ev_loop* loop, struct ev_io* watcher, int revents) pgagroal_prometheus_self_sockets_sub(); return; - + error: pgagroal_disconnect(client_fd);