From: Philipp Tölke Date: Wed, 15 Jun 2011 07:15:43 +0000 (+0000) Subject: read the service-conf from the global config-file X-Git-Tag: initial-import-from-subversion-38251~18178 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=89ee30fc0e5b3091905e2cf4bf02bb5419b95152;p=oweals%2Fgnunet.git read the service-conf from the global config-file --- diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index 76d653b06..975e97c87 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c @@ -41,11 +41,6 @@ */ static const struct GNUNET_CONFIGURATION_Handle *cfg; -/** - * The handle to the service-configuration - */ -static struct GNUNET_CONFIGURATION_Handle *servicecfg; - /** * The handle to the helper */ @@ -459,9 +454,13 @@ message_token (void *cls __attribute__((unused)), * "OFFERED-PORT:HOSTNAME:HOST-PORT" (SPACE <more of those>)* */ static void -read_service_conf (void *cls __attribute__((unused)), const char *section, const char *option, - const char *value) +read_service_conf (void *cls __attribute__((unused)), const char *section) { + if ((strlen(section) < 8) || (0 != strcmp (".gnunet.", section + (strlen(section) - 8)))) + return; + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %d %s %s\n", strlen(section), section, section + (strlen(section) - 8)); + char *cpy; char *redirect; char *hostname; @@ -473,17 +472,15 @@ read_service_conf (void *cls __attribute__((unused)), const char *section, const #define TCP 2 #define UDP 1 - unsigned int proto; - if (0 == strcmp ("UDP_REDIRECTS", option)) - proto = UDP; - else if (0 == strcmp ("TCP_REDIRECTS", option)) - proto = TCP; - else - proto = 0; + int proto = UDP; - if (0 != proto) + do { - cpy = GNUNET_strdup (value); + if (proto == UDP && (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, section, "UDP_REDIRECTS", &cpy))) + goto next; + else if (proto == TCP && (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, section, "TCP_REDIRECTS", &cpy))) + goto next; + for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok (NULL, " ")) { @@ -565,7 +562,10 @@ read_service_conf (void *cls __attribute__((unused)), const char *section, const } GNUNET_free (cpy); +next: + proto = (proto == UDP) ? TCP : UDP; } + while (proto != UDP); } /** @@ -1255,16 +1255,7 @@ run (void *cls, GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_TCP_CONNECTIONS", &max_tcp_connections); - char *services; - GNUNET_CONFIGURATION_get_value_filename (cfg, "dns", "SERVICES", &services); - servicecfg = GNUNET_CONFIGURATION_create (); - if (GNUNET_OK == GNUNET_CONFIGURATION_parse (servicecfg, services)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Parsing services %s\n", services); - GNUNET_CONFIGURATION_iterate (servicecfg, read_service_conf, NULL); - } - if (NULL != services) - GNUNET_free (services); + GNUNET_CONFIGURATION_iterate_sections (cfg, read_service_conf, NULL); GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 87c24b67f..6349e0547 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -63,11 +63,6 @@ static struct GNUNET_DHT_Handle *dht; */ static const struct GNUNET_CONFIGURATION_Handle *cfg; -/** - * The handle to the service-configuration - */ -static struct GNUNET_CONFIGURATION_Handle *servicecfg; - /** * A list of DNS-Responses that have to be sent to the requesting client */ @@ -1043,12 +1038,17 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type, void publish_iterate (void *cls __attribute__((unused)), const char *section) { + if ((strlen(section) < 8) || (0 != strcmp (".gnunet.", section + (strlen(section) - 8)))) + return; + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %s\n", section); + char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name, *keyfile; - GNUNET_CONFIGURATION_get_value_string (servicecfg, section, + GNUNET_CONFIGURATION_get_value_string (cfg, section, "UDP_REDIRECTS", &udp_redirects); - GNUNET_CONFIGURATION_get_value_string (servicecfg, section, "TCP_REDIRECTS", + GNUNET_CONFIGURATION_get_value_string (cfg, section, "TCP_REDIRECTS", &tcp_redirects); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", @@ -1080,7 +1080,7 @@ publish_iterate (void *cls __attribute__((unused)), const char *section) publish_name (section, ports, service_type, my_private_key); - GNUNET_CONFIGURATION_get_value_string (servicecfg, section, + GNUNET_CONFIGURATION_get_value_string (cfg, section, "ALTERNATIVE_NAMES", &alternative_names); for (alternative_name = strtok (alternative_names, " "); @@ -1102,32 +1102,19 @@ publish_iterate (void *cls __attribute__((unused)), const char *section) } /** - * Publish a DNS-record in the DHT. This is up to now just for testing. + * Publish a DNS-record in the DHT. */ static void publish_names (void *cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext *tc) { - char *services; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; - if (NULL != servicecfg) - GNUNET_CONFIGURATION_destroy(servicecfg); - - GNUNET_CONFIGURATION_get_value_filename(cfg, "dns", "SERVICES", &services); - - servicecfg = GNUNET_CONFIGURATION_create(); - if (GNUNET_OK == GNUNET_CONFIGURATION_parse(servicecfg, services)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Parsing services %s\n", services); - GNUNET_CONFIGURATION_iterate_sections(servicecfg, publish_iterate, NULL); - } - if (NULL != services) - GNUNET_free(services); + GNUNET_CONFIGURATION_iterate_sections(cfg, publish_iterate, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_HOURS, - publish_names, - NULL); + publish_names, + NULL); } /**