gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r7713 - in GNUnet: . src/util/config


From: gnunet
Subject: [GNUnet-SVN] r7713 - in GNUnet: . src/util/config
Date: Thu, 18 Sep 2008 23:46:08 -0600 (MDT)

Author: grothoff
Date: 2008-09-18 23:46:08 -0600 (Thu, 18 Sep 2008)
New Revision: 7713

Modified:
   GNUnet/src/util/config/config.c
   GNUnet/src/util/config/configtest.c
   GNUnet/src/util/config/testconfig.conf
   GNUnet/todo
Log:
fixing new config API, adding test

Modified: GNUnet/src/util/config/config.c
===================================================================
--- GNUnet/src/util/config/config.c     2008-09-17 17:11:48 UTC (rev 7712)
+++ GNUnet/src/util/config/config.c     2008-09-19 05:46:08 UTC (rev 7713)
@@ -541,7 +541,6 @@
   if (ret == GNUNET_SYSERR)
     GNUNET_GE_LOG (ectx,
                    GNUNET_GE_USER | GNUNET_GE_BULK | GNUNET_GE_WARNING,
-                   _
                    ("Setting option `%s' in section `%s' to value `%s' was 
refused.\n"),
                    option, section, value);
   GNUNET_mutex_unlock (data->lock);
@@ -1023,6 +1022,36 @@
   return ret;            
 }
 
+static char *
+escape_name (const char * value)
+{
+  char * escaped;
+  const char * rpos;
+  char * wpos;
+
+  escaped = GNUNET_malloc(strlen(value)*2 + 1);
+  memset(escaped, 0, strlen(value)*2 + 1);
+  rpos = value;
+  wpos = escaped;
+  while (rpos[0] != '\0')
+    {
+      switch (rpos[0])
+       {
+       case '\\':
+       case ' ':
+         wpos[0] = '\\';
+         wpos[1] = rpos[0];
+         wpos += 2;
+         break;
+       default:
+         wpos[0] = rpos[0];
+         wpos++;
+       }
+      rpos++;
+    }
+  return escaped;
+}
+
 static int
 test_match(void * cls,
           const char * fn)
@@ -1048,10 +1077,8 @@
                                                   const char *value)
 {
   char * escaped;
-  char * wpos;
   char * old;
   char * nw;
-  const char * rpos;
   int ret;
 
   if (GNUNET_SYSERR
@@ -1072,28 +1099,7 @@
                                             option,
                                             NULL,
                                             &old);
-  escaped = GNUNET_malloc(strlen(value)*2 + 1);
-  memset(escaped, 0, strlen(value)*2 + 1);
-  rpos = value;
-  wpos = escaped;
-  while (1)
-    {
-      switch (rpos[0])
-       {
-       case '\0':
-         break; /* we are done! */
-       case '\\':
-       case ' ':
-         wpos[0] = '\\';
-         wpos[1] = rpos[0];
-         wpos += 2;
-         break;
-       default:
-         wpos[0] = rpos[0];
-         wpos++;
-       }
-      rpos++;
-    }
+  escaped = escape_name(value);
   nw = GNUNET_malloc(strlen(old) + strlen(escaped) + 2);
   strcpy(nw, old);
   strcat(nw, " ");
@@ -1106,7 +1112,7 @@
   GNUNET_free(old);
   GNUNET_free(nw);    
   GNUNET_free(escaped);
-  return GNUNET_SYSERR;
+  return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
 }
 
 
@@ -1129,6 +1135,7 @@
   char * list;
   char * pos;
   char * end;
+  char * match;
   char old;
   int ret;
   
@@ -1142,6 +1149,7 @@
                                           option,
                                           NULL,
                                           &list);
+  match = escape_name (value);
   ret = 0;
   pos = list;
   while (1)
@@ -1160,9 +1168,8 @@
                {
                case '\\':
                case ' ':
-                 memmove(end,
-                         &end[1],
-                         strlen(&end[1])+1);
+                 end++;
+                 break;
                case '\0':
                  /* illegal, but just keep it */
                  break; 
@@ -1178,17 +1185,21 @@
       if (strlen(pos) > 0) 
        {
          if (0 == strcmp(pos,
-                         value))
+                         match))
            {
              memmove(pos,
                      &end[1],
                      strlen(&end[1])+1);
+             
+             if (pos != list)
+               pos[-1] = ' '; /* previously changed to "\0" */
              ret = GNUNET_GC_set_configuration_value_string(cfg,
                                                             ectx,
                                                             section,
                                                             option,
                                                             list);
              GNUNET_free(list);              
+             GNUNET_free(match);
              return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
            }
        }
@@ -1197,6 +1208,7 @@
       pos = end + 1;     
     }
   GNUNET_free(list);
+  GNUNET_free(match);
   return GNUNET_NO;
 }
 

Modified: GNUnet/src/util/config/configtest.c
===================================================================
--- GNUnet/src/util/config/configtest.c 2008-09-17 17:11:48 UTC (rev 7712)
+++ GNUnet/src/util/config/configtest.c 2008-09-19 05:46:08 UTC (rev 7713)
@@ -42,22 +42,127 @@
   if (0 != strcmp ("b", c))
     {
       GNUNET_free (c);
-      return 1;
+      return 2;
     }
   GNUNET_free (c);
   if (0 != GNUNET_GC_get_configuration_value_number (cfg,
                                                      "test", "five", 0, 10, 9,
                                                      &l))
-    return 1;
+    return 3;
   if (5 != l)
-    return 1;
+    return 4;
   GNUNET_GC_set_configuration_value_string (cfg, NULL, "more", "c", "YES");
   if (GNUNET_NO ==
       GNUNET_GC_get_configuration_value_yesno (cfg, "more", "c", GNUNET_NO))
-    return 1;
+    return 5;
   return 0;
 }
 
+static const char * want[] = {
+  "/Hello",
+  "/File Name",
+  "/World",
+  NULL,
+  NULL,
+};
+
+static int
+check(void * data,
+      const char * fn)
+{
+  int * idx = data;
+
+  if (0 == strcmp(want[*idx], fn))
+    {
+      (*idx)++;    
+      return GNUNET_OK;
+    }
+  return GNUNET_SYSERR;
+}
+
+static int
+testConfigFilenames ()
+{
+  int idx;
+
+  idx = 0;
+  if (3 != GNUNET_GC_iterate_configuration_value_filenames (cfg, 
+                                                           "FILENAMES",
+                                                           "test",
+                                                           &check,
+                                                           &idx))
+    return 8;
+  if (idx != 3)
+    return 16;
+  if (GNUNET_OK !=
+      GNUNET_GC_remove_configuration_value_filename(cfg,
+                                                   NULL,
+                                                   "FILENAMES",
+                                                   "test",
+                                                   "/File Name"))
+    return 24;
+
+  if (GNUNET_NO !=
+      GNUNET_GC_remove_configuration_value_filename(cfg,
+                                                   NULL,
+                                                   "FILENAMES",
+                                                   "test",
+                                                   "/File Name"))
+    return 32;
+  if (GNUNET_NO !=
+      GNUNET_GC_remove_configuration_value_filename(cfg,
+                                                   NULL,
+                                                   "FILENAMES",
+                                                   "test",
+                                                   "Stuff"))
+    return 40;
+
+  if (GNUNET_NO !=
+      GNUNET_GC_append_configuration_value_filename(cfg,
+                                                   NULL,
+                                                   "FILENAMES",
+                                                   "test",
+                                                   "/Hello"))
+    return 48;
+  if (GNUNET_NO !=
+      GNUNET_GC_append_configuration_value_filename(cfg,
+                                                   NULL,
+                                                   "FILENAMES",
+                                                   "test",
+                                                   "/World"))
+    return 56;
+  
+  if (GNUNET_YES !=
+      GNUNET_GC_append_configuration_value_filename(cfg,
+                                                   NULL,
+                                                   "FILENAMES",
+                                                   "test",
+                                                   "/File 1"))
+    return 64;
+
+  if (GNUNET_YES !=
+      GNUNET_GC_append_configuration_value_filename(cfg,
+                                                   NULL,
+                                                   "FILENAMES",
+                                                   "test",
+                                                   "/File 2"))
+    return 72;
+
+  idx = 0;
+  want[1] = "/World";
+  want[2] = "/File 1";
+  want[3] = "/File 2";
+  if (4 != GNUNET_GC_iterate_configuration_value_filenames (cfg, 
+                                                           "FILENAMES",
+                                                           "test",
+                                                           &check,
+                                                           &idx))
+    return 80;
+  if (idx != 4)
+    return 88;
+  return 0;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -81,8 +186,14 @@
   GNUNET_GE_ASSERT (ectx, cfg != NULL);
   GNUNET_os_init (ectx);
   failureCount += testConfig ();
+  failureCount += testConfigFilenames ();
 
   if (failureCount != 0)
-    return 1;
+    {
+      fprintf(stderr,
+             "Test failed: %u\n",
+             failureCount);
+      return 1;
+    }
   return 0;
 }

Modified: GNUnet/src/util/config/testconfig.conf
===================================================================
--- GNUnet/src/util/config/testconfig.conf      2008-09-17 17:11:48 UTC (rev 
7712)
+++ GNUnet/src/util/config/testconfig.conf      2008-09-19 05:46:08 UTC (rev 
7713)
@@ -17,7 +17,10 @@
 boom = "1 2 3 testing"
 trailing = YES 
 
+[FILENAMES]
+test = "/Hello /File\ Name /World"
 
+
 [TESTING]
 WEAKRANDOM = YES
 

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2008-09-17 17:11:48 UTC (rev 7712)
+++ GNUnet/todo 2008-09-19 05:46:08 UTC (rev 7713)
@@ -1,7 +1,6 @@
 This is just the current plan, plans change.
 
 0.8.1 [8'08] (aka "growth"):
-- test extended config API
 - fix gnunet-auto-share
 
 - Publishing:





reply via email to

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