gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r15544 - in gnunet-setup: . po src


From: gnunet
Subject: [GNUnet-SVN] r15544 - in gnunet-setup: . po src
Date: Fri, 10 Jun 2011 18:16:14 +0200

Author: grothoff
Date: 2011-06-10 18:16:14 +0200 (Fri, 10 Jun 2011)
New Revision: 15544

Modified:
   gnunet-setup/ChangeLog
   gnunet-setup/po/
   gnunet-setup/src/gnunet-setup-options.c
Log:
finish DNS configurator

Modified: gnunet-setup/ChangeLog
===================================================================
--- gnunet-setup/ChangeLog      2011-06-10 15:51:48 UTC (rev 15543)
+++ gnunet-setup/ChangeLog      2011-06-10 16:16:14 UTC (rev 15544)
@@ -1,5 +1,5 @@
 Fri Jun 10 11:07:58 CEST 2011
-       Releasing GNUnet 0.9.0pre3.  Instead of listing all that has
+       Releasing gnunet-setup 0.9.0pre3.  Instead of listing all that has
        changed, here is the short list of what is known NOT to work:
 
        * Autoconfiguration of NAT options


Property changes on: gnunet-setup/po
___________________________________________________________________
Modified: svn:ignore
   - remove-potcdate.sed
gnunet-setup.pot
de.gmo

   + Makefile.in
Makefile
remove-potcdate.sed
gnunet-setup.pot
de.gmo


Modified: gnunet-setup/src/gnunet-setup-options.c
===================================================================
--- gnunet-setup/src/gnunet-setup-options.c     2011-06-10 15:51:48 UTC (rev 
15543)
+++ gnunet-setup/src/gnunet-setup-options.c     2011-06-10 16:16:14 UTC (rev 
15544)
@@ -740,6 +740,70 @@
 
 
 /**
+ * Records we use to build DNS information lists.
+ */
+struct DnsInfo 
+{
+  struct DnsInfo *next;
+  char *section;
+  char *altnames;
+  char *tcpred;
+  char *udpred;
+  unsigned long long ttl;  
+};
+
+
+/**
+ * Function called for each section in the configuration.
+ * Gather existing ttl, section names and altnames.
+ * 
+ * @param cls 'struct DnsInfo**' to create
+ * @param section name of a section in the configuration
+ */
+static void
+collect_dns_sections (void *cls,
+                     const char *section)
+{
+  struct DnsInfo **base = cls;
+  struct DnsInfo *pos;
+
+  if ( (8 > strlen (section)) ||
+       (0 != strcmp (".gnunet.", section + ((strlen (section) - 8)))) )
+    return;
+  pos = GNUNET_malloc (sizeof (struct DnsInfo));
+  pos->section = GNUNET_strdup (section);
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (cfg, section, "TTL", &pos->ttl))
+    pos->ttl = 3600000;
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg, section, 
"ALTERNATIVE_NAMES", &pos->altnames))
+    pos->altnames = NULL;
+  pos->tcpred = GNUNET_strdup ("");
+  pos->udpred = GNUNET_strdup ("");
+  pos->next = *base;
+  *base = pos;
+}
+
+
+/**
+ * Function called for each section in the configuration.
+ * Removes those ending in '.gnunet.'.
+ * 
+ * @param cls unused
+ * @param section name of a section in the configuration
+ */
+static void
+remove_dns_sections (void *cls,
+                    const char *section)
+{
+  if ( (8 > strlen (section)) ||
+       (0 != strcmp (".gnunet.", section + ((strlen (section) - 8)))) )
+    return;
+  GNUNET_CONFIGURATION_remove_section (cfg, section);
+}
+
+
+/**
  * Given the list store and the data in it, update the 
  * configuration file accordingly.
  *
@@ -754,10 +818,14 @@
   guint targetport;
   gchar *targethost;
   gchar *tcpudp;
+  char *tmp;
+  struct DnsInfo *head;
+  struct DnsInfo *pos;
 
-  /* FIXME: remove all existing DNS-related entries from cfg  */
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-             "Updating configuration file not implemented\n");
+  head = NULL;
+  GNUNET_CONFIGURATION_iterate_sections (cfg,
+                                        &collect_dns_sections,
+                                        &head);
   if (TRUE ==
       gtk_tree_model_get_iter_first (tm, &iter))
     do
@@ -769,13 +837,85 @@
                            3, &targethost,
                            4, &tcpudp,
                            -1);
-
-       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "[%s]: %u:%s:%u, %s\n", hostname, 
srcport, targethost, targetport, tcpudp);
-
+       if (0 != strlen (hostname))
+         {
+           pos = head;
+           GNUNET_asprintf (&tmp,
+                            "%s.gnunet.",
+                            hostname);
+           while ( (NULL != pos) &&
+                   (0 != strcasecmp (tmp, pos->section)) )
+             pos = pos->next;
+           if (pos == NULL)
+             {
+               pos = GNUNET_malloc (sizeof (struct DnsInfo));
+               pos->section = tmp;
+               pos->ttl = 3600000;
+               pos->altnames = NULL;
+               pos->tcpred = GNUNET_strdup ("");
+               pos->udpred = GNUNET_strdup ("");
+               pos->next = head;
+               head = pos;
+             }
+           else
+             {
+               GNUNET_free (tmp);
+             }
+           
+           GNUNET_asprintf (&tmp,
+                            "%u:%s:%u %s",
+                            srcport,
+                            targethost,
+                            targetport,
+                            (0 == strcasecmp ("tcp", tcpudp)) ? pos->tcpred : 
pos->udpred);
+           if (0 == strcasecmp ("tcp", tcpudp))
+             {
+               GNUNET_free (pos->tcpred);
+               pos->tcpred = tmp;
+             }
+           else
+             {
+               GNUNET_free (pos->udpred);
+               pos->udpred = tmp;
+             }
+         }
+       g_free (tcpudp);
        g_free (hostname);
        g_free (targethost);
       }
     while (TRUE == gtk_tree_model_iter_next (tm, &iter));
+  GNUNET_CONFIGURATION_iterate_sections (cfg,
+                                        &remove_dns_sections,
+                                        NULL);
+  while (NULL != head)
+    {
+      pos = head;
+      head = pos->next;
+      if (pos->altnames != NULL)
+       GNUNET_CONFIGURATION_set_value_string (cfg,
+                                              pos->section,
+                                              "ALTERNATIVE_NAMES",
+                                              pos->altnames);
+      if (strlen (pos->udpred) > 0)
+       GNUNET_CONFIGURATION_set_value_string (cfg,
+                                              pos->section,
+                                              "UDP_REDIRECTS",
+                                              pos->udpred);
+      if (strlen (pos->tcpred) > 0)
+       GNUNET_CONFIGURATION_set_value_string (cfg,
+                                              pos->section,
+                                              "TCP_REDIRECTS",
+                                              pos->tcpred);
+      GNUNET_CONFIGURATION_set_value_number (cfg,
+                                            pos->section,
+                                            "TTL",
+                                            pos->ttl);
+      GNUNET_free_non_null (pos->altnames);
+      GNUNET_free (pos->tcpred);
+      GNUNET_free (pos->udpred);
+      GNUNET_free (pos->section);
+      GNUNET_free (pos);
+    }
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]