diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-05 16:10:48 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-06 11:54:37 +0100 |
commit | ad2656051697899e960694bb68ac104fcc5e92f1 (patch) | |
tree | 7e69fcd03db88b3839ee523f5d1b51ef9a38c372 /other/bootstrap_daemon/src | |
parent | 4e6c86d1cb228308678f89ff6e4e09b3f46347aa (diff) |
Improve static and const correctness.
- Any non-externally-visible declarations should be `static`.
- Casting away the `const` qualifier from pointers-to-const is
dangerous. All but one instance of this are now correct. The one
instance where we can't keep `const` is one where toxav code actually
writes to a chunk of memory marked as `const`. This code also assumes
4 byte alignment of data packets. I don't know whether that is a valid
assumption, but it's likely unportable, and *not* obviously correct.
- Replaced empty parameter lists with `(void)` to avoid passing
parameters to it. Empty parameter lists are old style declarations for
unknown number and type of arguments.
- Commented out (as `#if DHT_HARDENING` block) the hardening code that
was never executed.
- Minor style fix: don't use `default` in enum-switches unless the number
of enumerators in the default case is very large. In this case, it was
2, so we want to list them both explicitly to be warned about missing
one if we add one in the future.
- Removed the only two function declarations from nTox.h and put them
into nTox.c. They are not used outside and nTox is not a library.
Diffstat (limited to 'other/bootstrap_daemon/src')
-rw-r--r-- | other/bootstrap_daemon/src/command_line_arguments.c | 2 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/config.c | 8 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/log.c | 10 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/log.h | 2 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/tox-bootstrapd.c | 6 |
5 files changed, 14 insertions, 14 deletions
diff --git a/other/bootstrap_daemon/src/command_line_arguments.c b/other/bootstrap_daemon/src/command_line_arguments.c index ecfef1ad..262dd4c8 100644 --- a/other/bootstrap_daemon/src/command_line_arguments.c +++ b/other/bootstrap_daemon/src/command_line_arguments.c | |||
@@ -35,7 +35,7 @@ | |||
35 | /** | 35 | /** |
36 | * Prints --help message | 36 | * Prints --help message |
37 | */ | 37 | */ |
38 | void print_help() | 38 | static void print_help(void) |
39 | { | 39 | { |
40 | // 2 space ident | 40 | // 2 space ident |
41 | // make sure all lines fit into 80 columns | 41 | // make sure all lines fit into 80 columns |
diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index dc0a251c..a0c6045d 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c | |||
@@ -41,7 +41,7 @@ | |||
41 | * | 41 | * |
42 | * Important: iff `tcp_relay_port_count` > 0, then you are responsible for freeing `tcp_relay_ports`. | 42 | * Important: iff `tcp_relay_port_count` > 0, then you are responsible for freeing `tcp_relay_ports`. |
43 | */ | 43 | */ |
44 | void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) | 44 | static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) |
45 | { | 45 | { |
46 | const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports"; | 46 | const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports"; |
47 | 47 | ||
@@ -303,7 +303,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
303 | * @return binary on success, | 303 | * @return binary on success, |
304 | * NULL on failure. | 304 | * NULL on failure. |
305 | */ | 305 | */ |
306 | uint8_t *hex_string_to_bin(char *hex_string) | 306 | static uint8_t *hex_string_to_bin(const char *hex_string) |
307 | { | 307 | { |
308 | if (strlen(hex_string) % 2 != 0) { | 308 | if (strlen(hex_string) % 2 != 0) { |
309 | return NULL; | 309 | return NULL; |
@@ -312,7 +312,7 @@ uint8_t *hex_string_to_bin(char *hex_string) | |||
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 = malloc(len); |
314 | 314 | ||
315 | char *pos = hex_string; | 315 | const char *pos = hex_string; |
316 | size_t i; | 316 | size_t i; |
317 | 317 | ||
318 | for (i = 0; i < len; ++i, pos += 2) { | 318 | for (i = 0; i < len; ++i, pos += 2) { |
@@ -403,7 +403,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
403 | goto next; | 403 | goto next; |
404 | } | 404 | } |
405 | 405 | ||
406 | uint8_t *bs_public_key_bin = hex_string_to_bin((char *)bs_public_key); | 406 | uint8_t *bs_public_key_bin = hex_string_to_bin((const char *)bs_public_key); |
407 | const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), | 407 | const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), |
408 | bs_public_key_bin); | 408 | bs_public_key_bin); |
409 | free(bs_public_key_bin); | 409 | free(bs_public_key_bin); |
diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c index ee3a1421..e0fb3b33 100644 --- a/other/bootstrap_daemon/src/log.c +++ b/other/bootstrap_daemon/src/log.c | |||
@@ -48,7 +48,7 @@ bool open_log(LOG_BACKEND backend) | |||
48 | return true; | 48 | return true; |
49 | } | 49 | } |
50 | 50 | ||
51 | bool close_log() | 51 | bool close_log(void) |
52 | { | 52 | { |
53 | if (current_backend == -1) { | 53 | if (current_backend == -1) { |
54 | return false; | 54 | return false; |
@@ -63,7 +63,7 @@ bool close_log() | |||
63 | return true; | 63 | return true; |
64 | } | 64 | } |
65 | 65 | ||
66 | int level_syslog(LOG_LEVEL level) | 66 | static int level_syslog(LOG_LEVEL level) |
67 | { | 67 | { |
68 | switch (level) { | 68 | switch (level) { |
69 | case LOG_LEVEL_INFO: | 69 | case LOG_LEVEL_INFO: |
@@ -79,12 +79,12 @@ int level_syslog(LOG_LEVEL level) | |||
79 | return LOG_INFO; | 79 | return LOG_INFO; |
80 | } | 80 | } |
81 | 81 | ||
82 | void log_syslog(LOG_LEVEL level, const char *format, va_list args) | 82 | static void log_syslog(LOG_LEVEL level, const char *format, va_list args) |
83 | { | 83 | { |
84 | vsyslog(level_syslog(level), format, args); | 84 | vsyslog(level_syslog(level), format, args); |
85 | } | 85 | } |
86 | 86 | ||
87 | FILE *level_stdout(LOG_LEVEL level) | 87 | static FILE *level_stdout(LOG_LEVEL level) |
88 | { | 88 | { |
89 | switch (level) { | 89 | switch (level) { |
90 | case LOG_LEVEL_INFO: | 90 | case LOG_LEVEL_INFO: |
@@ -98,7 +98,7 @@ FILE *level_stdout(LOG_LEVEL level) | |||
98 | return stdout; | 98 | return stdout; |
99 | } | 99 | } |
100 | 100 | ||
101 | void log_stdout(LOG_LEVEL level, const char *format, va_list args) | 101 | static void log_stdout(LOG_LEVEL level, const char *format, va_list args) |
102 | { | 102 | { |
103 | vfprintf(level_stdout(level), format, args); | 103 | vfprintf(level_stdout(level), format, args); |
104 | fflush(level_stdout(level)); | 104 | fflush(level_stdout(level)); |
diff --git a/other/bootstrap_daemon/src/log.h b/other/bootstrap_daemon/src/log.h index 61cb2ee3..cb374968 100644 --- a/other/bootstrap_daemon/src/log.h +++ b/other/bootstrap_daemon/src/log.h | |||
@@ -49,7 +49,7 @@ bool open_log(LOG_BACKEND backend); | |||
49 | * Releases all used resources by the logger. | 49 | * Releases all used resources by the logger. |
50 | * @return true on success, flase if log is already closed. | 50 | * @return true on success, flase if log is already closed. |
51 | */ | 51 | */ |
52 | bool close_log(); | 52 | bool close_log(void); |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Writes a message to the log. | 55 | * Writes a message to the log. |
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 06ea45aa..fe360b4e 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c | |||
@@ -53,7 +53,7 @@ | |||
53 | // returns 1 on success | 53 | // returns 1 on success |
54 | // 0 on failure - no keys were read or stored | 54 | // 0 on failure - no keys were read or stored |
55 | 55 | ||
56 | int manage_keys(DHT *dht, char *keys_file_path) | 56 | static int manage_keys(DHT *dht, char *keys_file_path) |
57 | { | 57 | { |
58 | enum { KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES }; | 58 | enum { KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES }; |
59 | uint8_t keys[KEYS_SIZE]; | 59 | uint8_t keys[KEYS_SIZE]; |
@@ -98,7 +98,7 @@ int manage_keys(DHT *dht, char *keys_file_path) | |||
98 | 98 | ||
99 | // Prints public key | 99 | // Prints public key |
100 | 100 | ||
101 | void print_public_key(const uint8_t *public_key) | 101 | static void print_public_key(const uint8_t *public_key) |
102 | { | 102 | { |
103 | char buffer[2 * crypto_box_PUBLICKEYBYTES + 1]; | 103 | char buffer[2 * crypto_box_PUBLICKEYBYTES + 1]; |
104 | int index = 0; | 104 | int index = 0; |
@@ -115,7 +115,7 @@ void print_public_key(const uint8_t *public_key) | |||
115 | // Demonizes the process, appending PID to the PID file and closing file descriptors based on log backend | 115 | // Demonizes the process, appending PID to the PID file and closing file descriptors based on log backend |
116 | // Terminates the application if the daemonization fails. | 116 | // Terminates the application if the daemonization fails. |
117 | 117 | ||
118 | void daemonize(LOG_BACKEND log_backend, char *pid_file_path) | 118 | static void daemonize(LOG_BACKEND log_backend, char *pid_file_path) |
119 | { | 119 | { |
120 | // Check if the PID file exists | 120 | // Check if the PID file exists |
121 | FILE *pid_file; | 121 | FILE *pid_file; |