summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Biro <nurupo.contributions@gmail.com>2014-01-25 20:00:34 -0500
committerMaxim Biro <nurupo.contributions@gmail.com>2014-01-25 20:00:34 -0500
commitb9ef9b91aff17533254073538467684d62ed465f (patch)
tree08eb97d8e21f7c2f309a4f5109e45b5ff83f4fe8
parent0d53abebcdea36adc509ee46e2bfdacea41ac5e4 (diff)
Added more error checking
-rw-r--r--other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
index 24bb8266..1a68393f 100644
--- a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
+++ b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
@@ -233,20 +233,29 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
233 } 233 }
234 234
235 // Proceed only if all parts are present 235 // Proceed only if all parts are present
236 if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE || 236 if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) {
237 config_setting_lookup_int (server, NAME_PORT, &bs_port) == CONFIG_FALSE || 237 syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY);
238 config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE ) { 238 goto next;
239 }
240
241 if (config_setting_lookup_int(server, NAME_PORT, &bs_port) == CONFIG_FALSE) {
242 syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PORT);
243 goto next;
244 }
245
246 if (config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE) {
247 syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_ADDRESS);
239 goto next; 248 goto next;
240 } 249 }
241 250
242 if (strlen(bs_public_key) != 64) { 251 if (strlen(bs_public_key) != 64) {
243 syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %s.\n", i, NAME_PUBLIC_KEY, bs_public_key); 252 syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key);
244 goto next; 253 goto next;
245 } 254 }
246 255
247 // not (1 <= port <= 65535) 256 // not (1 <= port <= 65535)
248 if (bs_port < 1 || bs_port > 65535) { 257 if (bs_port < 1 || bs_port > 65535) {
249 syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %d.\n", i, NAME_PORT, bs_port); 258 syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %d. Skipping the server.\n", i, NAME_PORT, bs_port);
250 goto next; 259 goto next;
251 } 260 }
252 261
@@ -254,11 +263,11 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
254 hex_string_to_bin((char *)bs_public_key)); 263 hex_string_to_bin((char *)bs_public_key));
255 264
256 if (!address_resolved) { 265 if (!address_resolved) {
257 syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %s.\n", i, NAME_ADDRESS, bs_address); 266 syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_ADDRESS, bs_address);
258 goto next; 267 goto next;
259 } 268 }
260 269
261 syslog(LOG_DEBUG, "Successfully connected to %s:%d %s\n", bs_address, bs_port, bs_public_key); 270 syslog(LOG_DEBUG, "Successfully added bootstrap server #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key);
262 271
263next: 272next:
264 // config_setting_lookup_string() allocates string inside and doesn't allow us to free it 273 // config_setting_lookup_string() allocates string inside and doesn't allow us to free it
@@ -330,7 +339,7 @@ int main(int argc, char *argv[])
330 openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); 339 openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON);
331 340
332 if (argc < 2) { 341 if (argc < 2) {
333 syslog(LOG_ERR, "Please specify a configuration file. Exiting.\n"); 342 syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n");
334 return 1; 343 return 1;
335 } 344 }
336 345