Skip to content

Commit

Permalink
cleanup: Remove implicit bool conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 2, 2024
1 parent 4e2dba4 commit b7404f2
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 140 deletions.
14 changes: 7 additions & 7 deletions other/DHT_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static void print_log(void *context, Logger_Level level, const char *file, int l

int main(int argc, char *argv[])
{
if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) {
if (argc == 2 && tox_strncasecmp(argv[1], "-h", 3) == 0) {
printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
return 0;
Expand Down Expand Up @@ -167,7 +167,7 @@ int main(int argc, char *argv[])
bootstrap_set_callbacks(dht_get_net(dht), (uint32_t)DAEMON_VERSION_NUMBER, (const uint8_t *) motd_str, strlen(motd_str) + 1);
#endif

if (!(onion && forwarding && onion_a)) {
if (onion == nullptr || forwarding == nullptr || onion_a == nullptr) {
printf("Something failed to initialize.\n");
// cppcheck-suppress resourceLeak
return 1;
Expand Down Expand Up @@ -229,8 +229,8 @@ int main(int argc, char *argv[])
const uint16_t port = net_htons((uint16_t)port_conv);

uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
ipv6enabled, port, bootstrap_key);
const bool res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
ipv6enabled, port, bootstrap_key);
free(bootstrap_key);

if (!res) {
Expand All @@ -239,17 +239,17 @@ int main(int argc, char *argv[])
}
}

int is_waiting_for_dht_connection = 1;
bool is_waiting_for_dht_connection = true;

uint64_t last_lan_discovery = 0;
const Broadcast_Info *broadcast = lan_discovery_init(ns);

while (1) {
while (true) {
mono_time_update(mono_time);

if (is_waiting_for_dht_connection && dht_isconnected(dht)) {
printf("Connected to other bootstrap node successfully.\n");
is_waiting_for_dht_connection = 0;
is_waiting_for_dht_connection = false;
}

do_dht(dht);
Expand Down
44 changes: 22 additions & 22 deletions other/bootstrap_daemon/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
}
}

int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd)
bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd)
{
config_t cfg;

Expand All @@ -156,7 +156,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return 0;
return false;
}

// Get port
Expand Down Expand Up @@ -223,7 +223,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
*enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY;
}

if (*enable_tcp_relay) {
if (*enable_tcp_relay != 0) {
parse_tcp_relay_ports_config(&cfg, tcp_relay_ports, tcp_relay_port_count);
} else {
*tcp_relay_port_count = 0;
Expand All @@ -237,7 +237,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
*enable_motd = DEFAULT_ENABLE_MOTD;
}

if (*enable_motd) {
if (*enable_motd != 0) {
// Get MOTD
const char *tmp_motd;

Expand All @@ -259,14 +259,14 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path);
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path);
log_write(LOG_LEVEL_INFO, "'%s': %d\n", NAME_PORT, *port);
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 != 0 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback != 0 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery != 0 ? "true" : "false");

log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay != 0 ? "true" : "false");

// Show info about tcp ports only if tcp relay is enabled
if (*enable_tcp_relay) {
if (*enable_tcp_relay != 0) {
if (*tcp_relay_port_count == 0) {
log_write(LOG_LEVEL_ERROR, "No TCP ports could be read.\n");
} else {
Expand All @@ -278,13 +278,13 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
}
}

log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd != 0 ? "true" : "false");

if (*enable_motd) {
if (*enable_motd != 0) {
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_MOTD, *motd);
}

return 1;
return true;
}

/**
Expand Down Expand Up @@ -316,7 +316,7 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string)
return ret;
}

int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6)
{
const char *const NAME_BOOTSTRAP_NODES = "bootstrap_nodes";

Expand All @@ -331,7 +331,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return 0;
return false;
}

config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES);
Expand All @@ -340,13 +340,13 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n",
NAME_BOOTSTRAP_NODES);
config_destroy(&cfg);
return 1;
return true;
}

if (config_setting_length(node_list) == 0) {
log_write(LOG_LEVEL_WARNING, "No bootstrap nodes found. Skipping bootstrapping.\n");
config_destroy(&cfg);
return 1;
return true;
}

int bs_port;
Expand All @@ -357,15 +357,15 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)

int i = 0;

while (config_setting_length(node_list)) {
int address_resolved;
while (config_setting_length(node_list) != 0) {
bool address_resolved;
uint8_t *bs_public_key_bin;

node = config_setting_get_elem(node_list, 0);

if (node == nullptr) {
config_destroy(&cfg);
return 0;
return false;
}

// Check that all settings are present
Expand Down Expand Up @@ -421,5 +421,5 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)

config_destroy(&cfg);

return 1;
return true;
}
16 changes: 8 additions & 8 deletions other/bootstrap_daemon/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
* also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports`
* and also `motd` iff `enable_motd` is set.
*
* @return 1 on success,
* 0 on failure, doesn't modify any data pointed by arguments.
* @return true on success,
* false on failure, doesn't modify any data pointed by arguments.
*/
int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd);
bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd);

/**
* Bootstraps off nodes listed in the config file.
*
* @return 1 on success, some or no bootstrap nodes were added
* 0 on failure, an error occurred while parsing the config file.
* @return true on success, some or no bootstrap nodes were added
* false on failure, an error occurred while parsing the config file.
*/
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6);
bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6);

#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_CONFIG_H
Loading

0 comments on commit b7404f2

Please sign in to comment.