gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: GNS: Make string formats more comaptible


From: gnunet
Subject: [gnunet] branch master updated: GNS: Make string formats more comaptible with DNS zonefiles
Date: Wed, 19 Oct 2022 15:56:33 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 3683f556d GNS: Make string formats more comaptible with DNS zonefiles
3683f556d is described below

commit 3683f556df1324b1ce575dd5932d174d75512f7a
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Wed Oct 19 22:56:22 2022 +0900

    GNS: Make string formats more comaptible with DNS zonefiles
---
 src/gns/test_gns_mx_lookup.sh             |   4 +-
 src/gnsrecord/plugin_gnsrecord_dns.c      |   8 +-
 src/namestore/gnunet-namestore-zonefile.c | 163 ++++++++++++++++++++++++++++--
 src/util/dnsparser.c                      |   4 +-
 4 files changed, 165 insertions(+), 14 deletions(-)

diff --git a/src/gns/test_gns_mx_lookup.sh b/src/gns/test_gns_mx_lookup.sh
index 4afc93bb8..ffbe5a1b6 100755
--- a/src/gns/test_gns_mx_lookup.sh
+++ b/src/gns/test_gns_mx_lookup.sh
@@ -18,11 +18,11 @@ rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths 
-o GNUNET_TEST_HOME`
 which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
 
 MY_EGO="myego"
-TEST_MX="5,mail.+"
+TEST_MX="5 mail.+"
 gnunet-arm -s -c test_gns_lookup.conf
 gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
 PKEY=`gnunet-identity -d | grep "$MY_EGO - " | awk '{print $3'}`
-WANT_MX="5,mail.$PKEY"
+WANT_MX="5 mail.$PKEY"
 gnunet-namestore -p -z $MY_EGO -a -n www -t MX -V "$TEST_MX" -e never -c 
test_gns_lookup.conf
 
 RES_MX=`$DO_TIMEOUT gnunet-gns --raw -u www.$MY_EGO -t MX -c 
test_gns_lookup.conf`
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c 
b/src/gnsrecord/plugin_gnsrecord_dns.c
index 649133cd1..e8c24501c 100644
--- a/src/gnsrecord/plugin_gnsrecord_dns.c
+++ b/src/gnsrecord/plugin_gnsrecord_dns.c
@@ -100,7 +100,7 @@ dns_value_to_string (void *cls,
         return NULL;
       }
       GNUNET_asprintf (&result,
-                       "rname=%s mname=%s %u,%u,%u,%u,%u",
+                       "%s %s ( %u %u %u %u %u )",
                        soa->rname,
                        soa->mname,
                        soa->serial,
@@ -169,7 +169,7 @@ dns_value_to_string (void *cls,
         return NULL;
       }
       GNUNET_asprintf (&result,
-                       "%u,%s",
+                       "%u %s",
                        (unsigned int) mx->preference,
                        mx->mxhost);
       GNUNET_DNSPARSER_free_mx (mx);
@@ -503,7 +503,7 @@ dns_string_to_value (void *cls,
       size_t off;
 
       if (7 != sscanf (s,
-                       "rname=%253s mname=%253s %u,%u,%u,%u,%u",
+                       "%253s %253s ( %u %u %u %u %u )",
                        soa_rname,
                        soa_mname,
                        &soa_serial,
@@ -567,7 +567,7 @@ dns_string_to_value (void *cls,
       unsigned int mx_pref;
       size_t off;
 
-      if (2 != sscanf (s, "%u,%253s", &mx_pref, mxhost))
+      if (2 != sscanf (s, "%u %253s", &mx_pref, mxhost))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                     _ ("Unable to parse MX record `%s'\n"),
diff --git a/src/namestore/gnunet-namestore-zonefile.c 
b/src/namestore/gnunet-namestore-zonefile.c
index a55e3a0aa..d8ac7c234 100644
--- a/src/namestore/gnunet-namestore-zonefile.c
+++ b/src/namestore/gnunet-namestore-zonefile.c
@@ -32,6 +32,32 @@
  */
 static int ret = 0;
 
+/**
+ * Name of the ego
+ */
+static char *ego_name = NULL;
+
+/**
+ * Handle to identity lookup.
+ */
+static struct GNUNET_IDENTITY_EgoLookup *el;
+
+/**
+ * Private key for the our zone.
+ */
+static struct GNUNET_IDENTITY_PrivateKey zone_pkey;
+
+/**
+ * Queue entry for the 'add' operation.
+ */
+static struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
+
+/**
+ * Handle to the namestore.
+ */
+static struct GNUNET_NAMESTORE_Handle *ns;
+
+
 /**
  * Task run on shutdown.  Cleans up everything.
  *
@@ -41,8 +67,36 @@ static void
 do_shutdown (void *cls)
 {
   (void) cls;
+  if (NULL != ego_name)
+    GNUNET_free (ego_name);
+  if (NULL != el)
+  {
+    GNUNET_IDENTITY_ego_lookup_cancel (el);
+    el = NULL;
+  }
+  if (NULL != ns_qe)
+    GNUNET_NAMESTORE_cancel (ns_qe);
+  if (NULL != ns)
+    GNUNET_NAMESTORE_disconnect (ns);
+
+}
+
+static void
+tx_end (void *cls, int32_t success, const char *emsg)
+{
+  ns_qe = NULL;
+  if (GNUNET_SYSERR == success)
+  {
+    fprintf (stderr,
+             _ ("Ego `%s' not known to identity service\n"),
+             ego_name);
+    GNUNET_SCHEDULER_shutdown ();
+    ret = -1;
+  }
+  GNUNET_SCHEDULER_shutdown ();
 }
 
+
 /**
  * Main function that will be run.
  *
@@ -64,22 +118,25 @@ do_shutdown (void *cls)
  * @param cfg configuration
  */
 static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+parse (void *cls)
 {
+  struct GNUNET_GNSRECORD_Data rd[50]; // Let's hope we do not need more
+  struct GNUNET_GNSRECORD_Data *cur_rd = rd;
   char buf[5000];   /* buffer to hold entire line (adjust MAXC as needed) */
   char *next;
   char *token;
   char origin[255];
   char lastname[255];
+  void *data;
+  size_t data_size;
   struct GNUNET_TIME_Relative ttl;
   int origin_line = 0;
   int ttl_line = 0;
+  int type;
+  unsigned int rd_count = 0;
   uint32_t ttl_tmp;
 
-  /* use filename provided as 1st argument (stdin by default) */
+/* use filename provided as 1st argument (stdin by default) */
   int i = 0;
   while (fgets (buf, 5000, stdin))                     /* read each line of 
input */
   {
@@ -167,6 +224,9 @@ run (void *cls,
       printf ("Origin is: %s\n", origin);
       continue;
     }
+    // This is a record, let's go
+    cur_rd->flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
+    cur_rd->expiration_time = ttl.rel_value_us;
     next = strchr (token, ' ');
     if (NULL == next)
     {
@@ -188,16 +248,99 @@ run (void *cls,
     next[0] = '\0';
     next++;
     printf ("type is: %s\n", token);
+    type = GNUNET_GNSRECORD_typename_to_number (token);
+    cur_rd->record_type = type;
     while (*next == ' ')
       next++;
     token = next;
     next = strchr (token, ';');
     if (NULL != next)
       next[0] = '\0';
+    while (token[strlen (token) - 1] == ' ')
+      token[strlen (token) - 1] = '\0';
     printf ("data is: %s\n\n", token);
+    if (GNUNET_OK !=
+        GNUNET_GNSRECORD_string_to_value (type, token,
+                                          &data,
+                                          &data_size))
+    {
+      fprintf (stderr,
+               _ ("Data `%s' invalid\n"),
+               token);
+      ret = 1;
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
   }
+  ns_qe = GNUNET_NAMESTORE_transaction_commit (ns,
+                                               &tx_end,
+                                               NULL);
+}
+
+static void
+tx_start (void *cls, int32_t success, const char *emsg)
+{
+  ns_qe = NULL;
+  if (GNUNET_SYSERR == success)
+  {
+    fprintf (stderr,
+             _ ("Ego `%s' not known to identity service\n"),
+             ego_name);
+    GNUNET_SCHEDULER_shutdown ();
+    ret = -1;
+    return;
+  }
+  GNUNET_SCHEDULER_add_now (&parse, NULL);
+}
+
+static void
+identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
+{
+  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+
+  el = NULL;
+
+  if (NULL == ego)
+  {
+    if (NULL != ego_name)
+    {
+      fprintf (stderr,
+               _ ("Ego `%s' not known to identity service\n"),
+               ego_name);
+    }
+    GNUNET_SCHEDULER_shutdown ();
+    ret = -1;
+    return;
+  }
+  zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
+  ns_qe = GNUNET_NAMESTORE_transaction_begin (ns,
+                                              &tx_start,
+                                              NULL);
+}
+
+
+static void
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  ns = GNUNET_NAMESTORE_connect (cfg);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg);
+  if (NULL == ns)
+  {
+    fprintf (stderr,
+             _ ("Failed to connect to namestore\n"));
+    return;
+  }
+  if (NULL == ego_name)
+  {
+    fprintf (stderr, _ ("You must provide a zone ego to use\n"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg);
 
-  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -212,6 +355,12 @@ int
 main (int argc, char *const *argv)
 {
   struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_option_string ('z',
+                                 "zone",
+                                 "EGO",
+                                 gettext_noop (
+                                   "name of the ego controlling the zone"),
+                                 &ego_name),
     GNUNET_GETOPT_OPTION_END
   };
   int lret;
@@ -223,7 +372,7 @@ main (int argc, char *const *argv)
   if (GNUNET_OK !=
       (lret = GNUNET_PROGRAM_run (argc,
                                   argv,
-                                  "gnunet-namestore-dbtool",
+                                  "gnunet-namestore-zonefile",
                                   _ (
                                     "GNUnet namestore database manipulation 
tool"),
                                   options,
diff --git a/src/util/dnsparser.c b/src/util/dnsparser.c
index 401723106..d8b4a9bed 100644
--- a/src/util/dnsparser.c
+++ b/src/util/dnsparser.c
@@ -924,7 +924,9 @@ GNUNET_DNSPARSER_builder_add_name (char *dst,
       len = strlen (idna_name);
     else
       len = dot - idna_name;
-    if ((len >= 64) || (0 == len))
+    if (len == 0)
+      break;
+    if (len >= 64)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Invalid DNS name `%s': label with %u characters 
encountered\n",

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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