diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-18 01:31:55 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-24 21:53:50 +0100 |
commit | 15cb4261665bab4ef02a5b1b9db48b9477c9b87a (patch) | |
tree | d0c40a45afa19fff26ce1eb5bb703e18a9acdd4a /other/bootstrap_daemon/src | |
parent | 0d347c2b2e69aa09b079f6daaa00007fef4fe52f (diff) |
Make toxcore code C++ compatible.
It is still C code, so still compatible with C compilers as well. This
change lets us see more clearly where implicit conversions occur by
making them explicit.
Diffstat (limited to 'other/bootstrap_daemon/src')
-rw-r--r-- | other/bootstrap_daemon/src/config.c | 24 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/log.c | 11 |
2 files changed, 19 insertions, 16 deletions
diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index 27d1364a..3e102af9 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c | |||
@@ -62,7 +62,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por | |||
62 | } | 62 | } |
63 | 63 | ||
64 | // similar procedure to the one of reading config file below | 64 | // similar procedure to the one of reading config file below |
65 | *tcp_relay_ports = malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t)); | 65 | *tcp_relay_ports = (uint16_t *)malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t)); |
66 | 66 | ||
67 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { | 67 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { |
68 | 68 | ||
@@ -80,7 +80,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por | |||
80 | 80 | ||
81 | // the loop above skips invalid ports, so we adjust the allocated memory size | 81 | // the loop above skips invalid ports, so we adjust the allocated memory size |
82 | if ((*tcp_relay_port_count) > 0) { | 82 | if ((*tcp_relay_port_count) > 0) { |
83 | *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); | 83 | *tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); |
84 | } else { | 84 | } else { |
85 | free(*tcp_relay_ports); | 85 | free(*tcp_relay_ports); |
86 | *tcp_relay_ports = NULL; | 86 | *tcp_relay_ports = NULL; |
@@ -102,7 +102,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por | |||
102 | return; | 102 | return; |
103 | } | 103 | } |
104 | 104 | ||
105 | *tcp_relay_ports = malloc(config_port_count * sizeof(uint16_t)); | 105 | *tcp_relay_ports = (uint16_t *)malloc(config_port_count * sizeof(uint16_t)); |
106 | 106 | ||
107 | int i; | 107 | int i; |
108 | 108 | ||
@@ -134,7 +134,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por | |||
134 | 134 | ||
135 | // the loop above skips invalid ports, so we adjust the allocated memory size | 135 | // the loop above skips invalid ports, so we adjust the allocated memory size |
136 | if ((*tcp_relay_port_count) > 0) { | 136 | if ((*tcp_relay_port_count) > 0) { |
137 | *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); | 137 | *tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); |
138 | } else { | 138 | } else { |
139 | free(*tcp_relay_ports); | 139 | free(*tcp_relay_ports); |
140 | *tcp_relay_ports = NULL; | 140 | *tcp_relay_ports = NULL; |
@@ -182,7 +182,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
182 | tmp_pid_file = DEFAULT_PID_FILE_PATH; | 182 | tmp_pid_file = DEFAULT_PID_FILE_PATH; |
183 | } | 183 | } |
184 | 184 | ||
185 | *pid_file_path = malloc(strlen(tmp_pid_file) + 1); | 185 | *pid_file_path = (char *)malloc(strlen(tmp_pid_file) + 1); |
186 | strcpy(*pid_file_path, tmp_pid_file); | 186 | strcpy(*pid_file_path, tmp_pid_file); |
187 | 187 | ||
188 | // Get keys file location | 188 | // Get keys file location |
@@ -194,7 +194,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
194 | tmp_keys_file = DEFAULT_KEYS_FILE_PATH; | 194 | tmp_keys_file = DEFAULT_KEYS_FILE_PATH; |
195 | } | 195 | } |
196 | 196 | ||
197 | *keys_file_path = malloc(strlen(tmp_keys_file) + 1); | 197 | *keys_file_path = (char *)malloc(strlen(tmp_keys_file) + 1); |
198 | strcpy(*keys_file_path, tmp_keys_file); | 198 | strcpy(*keys_file_path, tmp_keys_file); |
199 | 199 | ||
200 | // Get IPv6 option | 200 | // Get IPv6 option |
@@ -254,7 +254,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
254 | 254 | ||
255 | size_t tmp_motd_length = strlen(tmp_motd) + 1; | 255 | size_t tmp_motd_length = strlen(tmp_motd) + 1; |
256 | size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length; | 256 | size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length; |
257 | *motd = malloc(motd_length); | 257 | *motd = (char *)malloc(motd_length); |
258 | strncpy(*motd, tmp_motd, motd_length); | 258 | strncpy(*motd, tmp_motd, motd_length); |
259 | (*motd)[motd_length - 1] = '\0'; | 259 | (*motd)[motd_length - 1] = '\0'; |
260 | } | 260 | } |
@@ -310,7 +310,7 @@ static uint8_t *hex_string_to_bin(const char *hex_string) | |||
310 | } | 310 | } |
311 | 311 | ||
312 | size_t len = strlen(hex_string) / 2; | 312 | size_t len = strlen(hex_string) / 2; |
313 | uint8_t *ret = malloc(len); | 313 | uint8_t *ret = (uint8_t *)malloc(len); |
314 | 314 | ||
315 | const char *pos = hex_string; | 315 | const char *pos = hex_string; |
316 | size_t i; | 316 | size_t i; |
@@ -364,6 +364,8 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
364 | int i = 0; | 364 | int i = 0; |
365 | 365 | ||
366 | while (config_setting_length(node_list)) { | 366 | while (config_setting_length(node_list)) { |
367 | int address_resolved; | ||
368 | uint8_t *bs_public_key_bin; | ||
367 | 369 | ||
368 | node = config_setting_get_elem(node_list, 0); | 370 | node = config_setting_get_elem(node_list, 0); |
369 | 371 | ||
@@ -403,9 +405,9 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
403 | goto next; | 405 | goto next; |
404 | } | 406 | } |
405 | 407 | ||
406 | uint8_t *bs_public_key_bin = hex_string_to_bin(bs_public_key); | 408 | bs_public_key_bin = hex_string_to_bin(bs_public_key); |
407 | const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), | 409 | address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), |
408 | bs_public_key_bin); | 410 | bs_public_key_bin); |
409 | free(bs_public_key_bin); | 411 | free(bs_public_key_bin); |
410 | 412 | ||
411 | if (!address_resolved) { | 413 | if (!address_resolved) { |
diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c index 2eae3286..7632d739 100644 --- a/other/bootstrap_daemon/src/log.c +++ b/other/bootstrap_daemon/src/log.c | |||
@@ -31,11 +31,12 @@ | |||
31 | #include <stdarg.h> | 31 | #include <stdarg.h> |
32 | #include <stdio.h> | 32 | #include <stdio.h> |
33 | 33 | ||
34 | static LOG_BACKEND current_backend = -1; | 34 | #define INVALID_BACKEND (LOG_BACKEND)-1u |
35 | static LOG_BACKEND current_backend = INVALID_BACKEND; | ||
35 | 36 | ||
36 | bool open_log(LOG_BACKEND backend) | 37 | bool open_log(LOG_BACKEND backend) |
37 | { | 38 | { |
38 | if (current_backend != -1) { | 39 | if (current_backend != INVALID_BACKEND) { |
39 | return false; | 40 | return false; |
40 | } | 41 | } |
41 | 42 | ||
@@ -50,7 +51,7 @@ bool open_log(LOG_BACKEND backend) | |||
50 | 51 | ||
51 | bool close_log(void) | 52 | bool close_log(void) |
52 | { | 53 | { |
53 | if (current_backend == -1) { | 54 | if (current_backend == INVALID_BACKEND) { |
54 | return false; | 55 | return false; |
55 | } | 56 | } |
56 | 57 | ||
@@ -58,7 +59,7 @@ bool close_log(void) | |||
58 | closelog(); | 59 | closelog(); |
59 | } | 60 | } |
60 | 61 | ||
61 | current_backend = -1; | 62 | current_backend = INVALID_BACKEND; |
62 | 63 | ||
63 | return true; | 64 | return true; |
64 | } | 65 | } |
@@ -121,5 +122,5 @@ bool write_log(LOG_LEVEL level, const char *format, ...) | |||
121 | 122 | ||
122 | va_end(args); | 123 | va_end(args); |
123 | 124 | ||
124 | return current_backend != -1; | 125 | return current_backend != INVALID_BACKEND; |
125 | } | 126 | } |