read the service-conf from the global config-file
authorPhilipp Tölke <toelke@in.tum.de>
Wed, 15 Jun 2011 07:15:43 +0000 (07:15 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Wed, 15 Jun 2011 07:15:43 +0000 (07:15 +0000)
src/vpn/gnunet-daemon-exit.c
src/vpn/gnunet-service-dns.c

index 76d653b06120198ba8bdbc682cc3e0352c15273c..975e97c87f332b76dbeae8d81c1ebe11e16b0082 100644 (file)
  */
 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 &lt;more of those&gt;)*
  */
 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);
index 87c24b67ffeb4a538cc528cfaadb7cd626dfa3e5..6349e0547f7089bea38cd6c65a0d1977fbe956b4 100644 (file)
@@ -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);
 }
 
 /**