gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r7646 - in GNUnet/src: applications/fs/ecrs applications/fs


From: gnunet
Subject: [GNUnet-SVN] r7646 - in GNUnet/src: applications/fs/ecrs applications/fs/fsui applications/fs/namespace applications/fs/tools applications/identity include server util/config util/disk util/loggers util/pseudonym
Date: Sun, 31 Aug 2008 14:48:03 -0600 (MDT)

Author: grothoff
Date: 2008-08-31 14:48:02 -0600 (Sun, 31 Aug 2008)
New Revision: 7646

Modified:
   GNUnet/src/applications/fs/ecrs/indexinfo.c
   GNUnet/src/applications/fs/ecrs/namespace.c
   GNUnet/src/applications/fs/fsui/upload.c
   GNUnet/src/applications/fs/namespace/update_info.c
   GNUnet/src/applications/fs/tools/gnunet-auto-share.c
   GNUnet/src/applications/fs/tools/gnunet-insert.c
   GNUnet/src/applications/identity/identity.c
   GNUnet/src/applications/identity/identitytest.c
   GNUnet/src/include/gnunet_fsui_lib.h
   GNUnet/src/include/gnunet_identity_service.h
   GNUnet/src/include/gnunet_util_common.h
   GNUnet/src/include/gnunet_util_config.h
   GNUnet/src/include/gnunet_util_disk.h
   GNUnet/src/server/gnunet-peer-info.c
   GNUnet/src/util/config/config.c
   GNUnet/src/util/disk/storage.c
   GNUnet/src/util/loggers/file.c
   GNUnet/src/util/pseudonym/info.c
Log:
simplifying dir_scan API, extending config API

Modified: GNUnet/src/applications/fs/ecrs/indexinfo.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/indexinfo.c 2008-08-31 20:01:29 UTC (rev 
7645)
+++ GNUnet/src/applications/fs/ecrs/indexinfo.c 2008-08-31 20:48:02 UTC (rev 
7646)
@@ -66,18 +66,14 @@
 };
 
 static int
-iiHelper (const char *fn, const char *dir, void *ptr)
+iiHelper (void * ptr,
+         const char * fullName)
 {
   struct iiC *cls = ptr;
-  char *fullName;
   char *lnkName;
   unsigned int size;
   int ret;
 
-  fullName = GNUNET_malloc (strlen (dir) + strlen (fn) + 4);
-  strcpy (fullName, dir);
-  strcat (fullName, DIR_SEPARATOR_STR);
-  strcat (fullName, fn);
   size = 256;
   lnkName = GNUNET_malloc (size);
   while (1)
@@ -90,7 +86,6 @@
               if (size * 2 < size)
                 {
                   GNUNET_free (lnkName);
-                  GNUNET_free (fullName);
                   return GNUNET_OK;     /* error */
                 }
               GNUNET_array_grow (lnkName, size, size * 2);
@@ -104,7 +99,6 @@
                                            "readlink", fullName);
             }
           GNUNET_free (lnkName);
-          GNUNET_free (fullName);
           return GNUNET_OK;     /* error */
         }
       else
@@ -117,11 +111,9 @@
   if (GNUNET_OK != cls->iterator (lnkName, cls->closure))
     {
       cls->cnt = GNUNET_SYSERR;
-      GNUNET_free (fullName);
       GNUNET_free (lnkName);
       return GNUNET_SYSERR;
     }
-  GNUNET_free (fullName);
   GNUNET_free (lnkName);
   return GNUNET_OK;
 }

Modified: GNUnet/src/applications/fs/ecrs/namespace.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/namespace.c 2008-08-31 20:01:29 UTC (rev 
7645)
+++ GNUnet/src/applications/fs/ecrs/namespace.c 2008-08-31 20:48:02 UTC (rev 
7646)
@@ -514,36 +514,28 @@
 };
 
 static int
-processFile_ (const char *name, const char *dirName, void *cls)
+processFile_ (void *cls,
+             const char * fileName)
 {
   struct lNCLS *c = cls;
   struct GNUNET_RSA_PrivateKey *hk;
-  char *fileName;
   GNUNET_RSA_PrivateKeyEncoded *hke;
   char *dst;
   unsigned long long len;
   GNUNET_HashCode namespace;
   GNUNET_RSA_PublicKey pk;
-  GNUNET_HashCode pid;
-
-  if (GNUNET_OK != GNUNET_enc_to_hash (name, &pid))
-    return GNUNET_OK;           /* ignore */
-  fileName = getPseudonymFileName (c->ectx, c->cfg, &pid);
+  const char * name;
+  
   if (GNUNET_OK !=
       GNUNET_disk_file_size (c->ectx, fileName, &len, GNUNET_YES))
-    {
-      GNUNET_free (fileName);
-      return GNUNET_OK;
-    }
+    return GNUNET_OK;    
   if (len < 2)
     {
       GNUNET_GE_LOG (c->ectx,
                      GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
-                     _
-                     ("File `%s' does not contain a pseudonym, trying to 
remove.\n"),
+                     _("Format of file `%s' is invalid, trying to remove.\n"),
                      fileName);
       UNLINK (fileName);
-      GNUNET_free (fileName);
       return GNUNET_OK;
     }
   dst = GNUNET_malloc (len);
@@ -553,9 +545,10 @@
     {
       GNUNET_GE_LOG (c->ectx,
                      GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
-                     _("Format of file `%s' is invalid.\n"), fileName);
+                     _("Format of file `%s' is invalid, trying to remove.\n"), 
+                    fileName);
+      UNLINK (fileName);
       GNUNET_free (hke);
-      GNUNET_free (fileName);
       return GNUNET_OK;
     }
   hk = GNUNET_RSA_decode_key (hke);
@@ -567,16 +560,17 @@
                      _("Format of file `%s' is invalid, trying to remove.\n"),
                      fileName);
       UNLINK (fileName);
-      GNUNET_free (fileName);
       GNUNET_GE_BREAK (c->ectx, 0);
       return GNUNET_SYSERR;
     }
-  GNUNET_free (fileName);
   GNUNET_RSA_get_public_key (hk, &pk);
   GNUNET_RSA_free_key (hk);
   GNUNET_hash (&pk, sizeof (GNUNET_RSA_PublicKey), &namespace);
   if (NULL != c->cb)
     {
+      name = fileName;
+      while (NULL != strstr(name, DIR_SEPARATOR_STR))
+       name = 1 + strstr(name, DIR_SEPARATOR_STR);
       if (GNUNET_OK == c->cb (&namespace, name, c->cls))
         c->cnt++;
       else

Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c    2008-08-31 20:01:29 UTC (rev 
7645)
+++ GNUnet/src/applications/fs/fsui/upload.c    2008-08-31 20:48:02 UTC (rev 
7646)
@@ -639,21 +639,15 @@
                                                   *parent);
 
 static int
-addChildUpload (const char *name, const char *dirName, void *data)
+addChildUpload (void * data,
+               const char * filename)
 {
   struct GNUNET_FSUI_UploadList *parent = data;
-  char *filename;
   struct GNUNET_FSUI_UploadList *child;
   struct GNUNET_MetaData *md_tmp;
 
-  filename = GNUNET_malloc (strlen (dirName) + strlen (name) + 2);
-  strcpy (filename, dirName);
-  if (dirName[strlen (dirName) - 1] != DIR_SEPARATOR)
-    strcat (filename, DIR_SEPARATOR_STR);
-  strcat (filename, name);
   md_tmp = GNUNET_meta_data_create ();
   child = addUploads (parent->shared, filename, NULL, md_tmp, parent);
-  GNUNET_free (filename);
   GNUNET_meta_data_destroy (md_tmp);
   if (child == NULL)
     return GNUNET_SYSERR;

Modified: GNUnet/src/applications/fs/namespace/update_info.c
===================================================================
--- GNUnet/src/applications/fs/namespace/update_info.c  2008-08-31 20:01:29 UTC 
(rev 7645)
+++ GNUnet/src/applications/fs/namespace/update_info.c  2008-08-31 20:48:02 UTC 
(rev 7646)
@@ -206,7 +206,8 @@
 };
 
 static int
-list_namespace_contents_helper (const char *fil, const char *dir, void *ptr)
+list_namespace_contents_helper (void * ptr,
+                               const char *fullname)
 {
   struct ListNamespaceContentsClosure *cls = ptr;
   GNUNET_ECRS_FileInfo fi;
@@ -214,7 +215,16 @@
   char *lastId;
   char *nextId;
   int ret;
+  const char * fil;
 
+  if (strlen(fullname) < sizeof(GNUNET_EncName))
+    return GNUNET_OK;
+  fil = &fullname[strlen(fullname) + 1 - sizeof(GNUNET_EncName)];
+  if (fil[-1] != DIR_SEPARATOR)
+    {
+      GNUNET_GE_BREAK (cls->ectx, 0);
+      return GNUNET_OK;
+    }
   if (GNUNET_OK != GNUNET_enc_to_hash (fil, &lid))
     {
       GNUNET_GE_BREAK (cls->ectx, 0);

Modified: GNUnet/src/applications/fs/tools/gnunet-auto-share.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-auto-share.c        2008-08-31 
20:01:29 UTC (rev 7645)
+++ GNUnet/src/applications/fs/tools/gnunet-auto-share.c        2008-08-31 
20:48:02 UTC (rev 7646)
@@ -454,27 +454,20 @@
 }
 
 static int
-test_run (const char *filename, const char *dirName, void *cls)
+test_run (void * cls,
+         const char *fn)
 {
   struct DirectoryRecord *dr = cls;
   GNUNET_HashCode hc;
   struct FileRecord *rec;
   struct stat buf;
-  char *fn;
 
-  if (filename[0] == '.')
-    return GNUNET_OK;
   if (ul != NULL)
     return GNUNET_SYSERR;
-  fn = GNUNET_malloc (strlen (filename) + strlen (dirName) + 2);
-  strcpy (fn, dirName);
-  strcat (fn, DIR_SEPARATOR_STR);
-  strcat (fn, filename);
   if (0 != stat (fn, &buf))
     {
       fprintf (myout, _("Could not access `%s': %s\n"), fn, strerror (errno));
       fflush (myout);
-      GNUNET_free (fn);
       return GNUNET_OK;
     }
   rec = find_entry (dr, fn);
@@ -493,7 +486,6 @@
       if (GNUNET_NO == GNUNET_FS_test_indexed (sock, &rec->hc))
         {
           dr->run = 1;
-          GNUNET_free (fn);
           /* keep iterating to mark all other files in this tree! */
           return GNUNET_OK;
         }
@@ -513,7 +505,6 @@
     }
   if (S_ISDIR (buf.st_mode))
     GNUNET_disk_directory_scan (ectx, fn, &test_run, dr);
-  GNUNET_free (fn);
   return GNUNET_OK;
 }
 
@@ -570,39 +561,33 @@
 }
 
 static int
-probe_directory (const char *filename, const char *dirName, void *cls)
+probe_directory (void * cls,
+                const char *fn)
 {
   struct DirectoryRecord *dr = cls;
   struct stat buf;
   struct AddMetadataClosure amc;
   struct GNUNET_ECRS_URI *kuri;
-  char *fn;
   char *keys;
+  const char * filename;
 
   if (GNUNET_shutdown_test ())
     return GNUNET_SYSERR;       /* aborted */
-  if (filename[0] == '.')
-    return GNUNET_OK;
   if (ul != NULL)
     return GNUNET_SYSERR;
-  fn = GNUNET_malloc (strlen (filename) + strlen (dirName) + 2);
-  strcpy (fn, dirName);
-  strcat (fn, DIR_SEPARATOR_STR);
-  strcat (fn, filename);
   if (0 != stat (fn, &buf))
     {
       fprintf (myout, "Could not stat `%s': %s\n", fn, STRERROR (errno));
       fflush (myout);
-      GNUNET_free (fn);
       return GNUNET_OK;
     }
   dr->run = 0;
-  test_run (filename, dirName, dr);
+  test_run (dr, fn);
   if (0 == dr->run)
-    {
-      GNUNET_free (fn);
-      return GNUNET_OK;
-    }
+    return GNUNET_OK;    
+  filename = fn;
+  while (NULL != strstr(filename, DIR_SEPARATOR_STR))
+    filename = 1 + strstr(filename, DIR_SEPARATOR_STR);  
   amc.meta = GNUNET_meta_data_create ();
   amc.filename = filename;
   /* attaching a listener will prompt iteration
@@ -627,7 +612,6 @@
   if (kuri != NULL)
     GNUNET_ECRS_uri_destroy (kuri);
   GNUNET_meta_data_destroy (amc.meta);
-  GNUNET_free (fn);
   return GNUNET_SYSERR;
 }
 

Modified: GNUnet/src/applications/fs/tools/gnunet-insert.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-insert.c    2008-08-31 20:01:29 UTC 
(rev 7645)
+++ GNUnet/src/applications/fs/tools/gnunet-insert.c    2008-08-31 20:48:02 UTC 
(rev 7646)
@@ -125,26 +125,22 @@
 }
 
 static int
-listKeywords (const char *fn, const char *dir, void *cls)
+listKeywords (void * cls,
+             const char *fullName)
 {
   EXTRACTOR_ExtractorList *l = cls;
-  char *fullName;
   struct stat buf;
   EXTRACTOR_KeywordList *list;
+  const char * fn;
 
-  fullName = GNUNET_malloc (strlen (dir) + strlen (fn) + 2);
-  strcpy (fullName, dir);
-  if (dir[strlen (dir) - 1] != DIR_SEPARATOR)
-    strcat (fullName, DIR_SEPARATOR_STR);
-  strcat (fullName, fn);
   printf (_("Keywords for file `%s':\n"), fullName);
   if (0 != STAT (fullName, &buf))
-    {
-      GNUNET_free (fullName);
-      return GNUNET_OK;
-    }
+    return GNUNET_OK;    
   if (S_ISDIR (buf.st_mode))
     {
+      fn = fullName;
+      while (NULL != strstr(fn, DIR_SEPARATOR_STR))
+       fn = 1 + strstr(fn, DIR_SEPARATOR_STR);  
       printf ("%s - %s\n", dgettext ("libextractor", "filename"), fn);
       printf ("%s - %s\n",
               dgettext ("libextractor", "mimetype"),
@@ -160,7 +156,6 @@
       EXTRACTOR_printKeywords (stdout, list);
       EXTRACTOR_freeKeywords (list);
     }
-  GNUNET_free (fullName);
   return GNUNET_OK;
 }
 
@@ -370,7 +365,6 @@
       EXTRACTOR_ExtractorList *l;
       char *ex;
       char *dirname;
-      char *fname;
 
       l = EXTRACTOR_loadDefaultLibraries ();
       ex = NULL;
@@ -381,15 +375,7 @@
       GNUNET_free (ex);
       dirname = GNUNET_expand_file_name (ectx, filename);
       GNUNET_GE_ASSERT (ectx, dirname != NULL);
-      while ((strlen (dirname) > 0) &&
-             (dirname[strlen (dirname) - 1] == DIR_SEPARATOR))
-        dirname[strlen (dirname) - 1] = '\0';
-      fname = dirname;
-      while (strstr (fname, DIR_SEPARATOR_STR) != NULL)
-        fname = strstr (fname, DIR_SEPARATOR_STR) + 1;
-      GNUNET_GE_ASSERT (ectx, fname != dirname);
-      fname[-1] = '\0';
-      listKeywords (fname, dirname, l);
+      listKeywords (l, dirname);
       GNUNET_free (dirname);
       EXTRACTOR_removeAll (l);
       GNUNET_meta_data_destroy (meta);

Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2008-08-31 20:01:29 UTC (rev 
7645)
+++ GNUnet/src/applications/identity/identity.c 2008-08-31 20:48:02 UTC (rev 
7646)
@@ -153,7 +153,7 @@
  * @return filename of the form DIRECTORY/HOSTID.PROTOCOL
  */
 static char *
-getHostFileName (const GNUNET_PeerIdentity * id, unsigned short protocol)
+get_host_filename (const GNUNET_PeerIdentity * id, unsigned short protocol)
 {
   GNUNET_EncName fil;
   char *fn;
@@ -173,7 +173,7 @@
  * @return NULL if not found
  */
 static HostEntry *
-findHost (const GNUNET_PeerIdentity * id)
+lookup_host_entry (const GNUNET_PeerIdentity * id)
 {
   int i;
 
@@ -192,7 +192,7 @@
  * @param protocol the protocol for the host
  */
 static void
-addHostToKnown (const GNUNET_PeerIdentity * identity, unsigned short protocol)
+add_host_to_known_hosts (const GNUNET_PeerIdentity * identity, unsigned short 
protocol)
 {
   HostEntry *entry;
   int i;
@@ -202,7 +202,7 @@
 
   GNUNET_GE_ASSERT (ectx, numberOfHosts_ <= sizeOfHosts_);
   GNUNET_mutex_lock (lock_);
-  entry = findHost (identity);
+  entry = lookup_host_entry (identity);
   if (entry == NULL)
     {
       entry = GNUNET_malloc (sizeof (HostEntry));
@@ -260,7 +260,7 @@
  * @returns the actual change in trust (positive or negative)
  */
 static int
-changeHostTrust (const GNUNET_PeerIdentity * hostId, int value)
+change_host_trust (const GNUNET_PeerIdentity * hostId, int value)
 {
   HostEntry *host;
 
@@ -268,13 +268,18 @@
     return 0;
 
   GNUNET_mutex_lock (lock_);
-  host = findHost (hostId);
+  host = lookup_host_entry (hostId);
   if (host == NULL)
     {
-      addHostToKnown (hostId, GNUNET_TRANSPORT_PROTOCOL_NUMBER_NAT);
-      host = findHost (hostId);
+      if (value == 0)
+       {
+         GNUNET_mutex_unlock (lock_);
+         return 0;
+       }
+      add_host_to_known_hosts (hostId, GNUNET_TRANSPORT_PROTOCOL_NUMBER_NAT);
+      host = lookup_host_entry (hostId);
       if (host == NULL)
-        {
+        {       
           GNUNET_GE_BREAK (ectx, 0);
           GNUNET_mutex_unlock (lock_);
           return 0;
@@ -295,82 +300,63 @@
 }
 
 /**
- * Obtain the trust record of a peer.
- *
- * @param hostId the identity of the peer
- * @return the amount of trust we currently have in that peer
+ * Remove a file that should not be there.  LOG
+ * success or failure.
  */
-static unsigned int
-getHostTrust (const GNUNET_PeerIdentity * hostId)
+static void
+remove_garbage(const char *fullname)
 {
-  HostEntry *host;
-  unsigned int trust;
-
-  GNUNET_mutex_lock (lock_);
-  host = findHost (hostId);
-  if (host == NULL)
-    trust = 0;
+  if (0 == UNLINK (fullname))
+    GNUNET_GE_LOG (ectx,
+                  GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_ADMIN |
+                  GNUNET_GE_BULK,
+                  _
+                  ("File `%s' in directory `%s' does not match naming 
convention. "
+                   "Removed.\n"), fullname, networkIdDirectory);
   else
-    trust = host->trust & TRUST_ACTUAL_MASK;
-  GNUNET_mutex_unlock (lock_);
-  return trust;
+    GNUNET_GE_LOG_STRERROR_FILE (ectx,
+                                GNUNET_GE_ERROR | GNUNET_GE_USER |
+                                GNUNET_GE_BULK, "unlink", fullname);
 }
 
 
 static int
-cronHelper (const char *filename, const char *dirname, void *unused)
+hosts_directory_scan_callback (void * unused,
+           const char *fullname)
 {
   GNUNET_PeerIdentity identity;
   GNUNET_EncName id;
   unsigned int protoNumber;
-  char *fullname;
+  const char *filename;
 
-  GNUNET_GE_ASSERT (ectx, numberOfHosts_ <= sizeOfHosts_);
-  GNUNET_GE_ASSERT (ectx, sizeof (GNUNET_EncName) == 104);
-  if (2 == sscanf (filename, "%103c.%u", (char *) &id, &protoNumber))
+  if (GNUNET_disk_file_test (ectx, fullname) != GNUNET_YES)
+    return GNUNET_OK; /* ignore non-files */
+  if (strlen(fullname) < sizeof(GNUNET_EncName))
     {
-      id.encoding[sizeof (GNUNET_EncName) - 1] = '\0';
-      if (GNUNET_OK ==
-          GNUNET_enc_to_hash ((char *) &id, &identity.hashPubKey))
-        {
-          addHostToKnown (&identity, (unsigned short) protoNumber);
-          return GNUNET_OK;
-        }
+      remove_garbage(fullname);
+      return GNUNET_OK;
     }
-
-  fullname =
-    GNUNET_malloc (strlen (filename) + strlen (networkIdDirectory) + 1);
-  strcpy (fullname, networkIdDirectory);
-  strcat (fullname, filename);
-  if (GNUNET_disk_file_test (ectx, fullname) == GNUNET_YES)
+  filename = &fullname[strlen(fullname) + 1 - sizeof(GNUNET_EncName)];
+  if (filename[-1] != DIR_SEPARATOR)
     {
-      if (0 == UNLINK (fullname))
-        GNUNET_GE_LOG (ectx,
-                       GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_ADMIN |
-                       GNUNET_GE_BULK,
-                       _
-                       ("File `%s' in directory `%s' does not match naming 
convention. "
-                        "Removed.\n"), filename, networkIdDirectory);
-      else
-        GNUNET_GE_LOG_STRERROR_FILE (ectx,
-                                     GNUNET_GE_ERROR | GNUNET_GE_USER |
-                                     GNUNET_GE_BULK, "unlink", fullname);
+      remove_garbage(fullname);
+      return GNUNET_OK;
     }
-  else if (GNUNET_disk_directory_test (ectx, fullname) == GNUNET_YES)
+  GNUNET_GE_ASSERT (ectx, numberOfHosts_ <= sizeOfHosts_);
+  GNUNET_GE_ASSERT (ectx, sizeof (GNUNET_EncName) == 104);
+  if (2 != sscanf (filename, "%103c.%u", (char *) &id, &protoNumber))
     {
-      if (0 == RMDIR (fullname))
-        GNUNET_GE_LOG (ectx,
-                       GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_ADMIN |
-                       GNUNET_GE_BULK,
-                       _
-                       ("Directory `%s' in directory `%s' does not match 
naming convention. "
-                        "Removed.\n"), filename, networkIdDirectory);
-      else
-        GNUNET_GE_LOG_STRERROR_FILE (ectx,
-                                     GNUNET_GE_ERROR | GNUNET_GE_USER |
-                                     GNUNET_GE_BULK, "rmdir", fullname);
+      remove_garbage(fullname);
+      return GNUNET_OK;
+    }    
+  id.encoding[sizeof (GNUNET_EncName) - 1] = '\0';
+  if (GNUNET_OK !=
+      GNUNET_enc_to_hash ((char *) &id, &identity.hashPubKey))
+    {
+      remove_garbage(fullname);
+      return GNUNET_OK;
     }
-  GNUNET_free (fullname);
+  add_host_to_known_hosts (&identity, (unsigned short) protoNumber);
   return GNUNET_OK;
 }
 
@@ -391,7 +377,7 @@
                                    once every 5 min */
   lastRun = now;
   count =
-    GNUNET_disk_directory_scan (ectx, networkIdDirectory, &cronHelper, NULL);
+    GNUNET_disk_directory_scan (ectx, networkIdDirectory, 
&hosts_directory_scan_callback, NULL);
   if (count <= 0)
     {
       retries++;
@@ -417,14 +403,10 @@
                  GNUNET_PeerIdentity * result)
 {
   if (pubKey == NULL)
-    {
-      memset (&result, 0, sizeof (GNUNET_PeerIdentity));
-    }
-  else
-    {
-      GNUNET_hash (pubKey, sizeof (GNUNET_RSA_PublicKey),
-                   &result->hashPubKey);
-    }
+    memset (&result, 0, sizeof (GNUNET_PeerIdentity));    
+  else    
+    GNUNET_hash (pubKey, sizeof (GNUNET_RSA_PublicKey),
+                &result->hashPubKey);
 }
 
 /**
@@ -447,7 +429,7 @@
       return;
     }
   GNUNET_mutex_lock (lock_);
-  entry = findHost (&tmp->senderIdentity);
+  entry = lookup_host_entry (&tmp->senderIdentity);
   if ((entry != NULL) && (entry->helloCount > 0))
     {
       GNUNET_mutex_unlock (lock_);
@@ -525,7 +507,7 @@
                 }
             }
           /* also remove hello file itself */
-          fn = getHostFileName (identity, protocol);
+          fn = get_host_filename (identity, protocol);
           if (0 != UNLINK (fn))
             GNUNET_GE_LOG_STRERROR_FILE (ectx,
                                          GNUNET_GE_WARNING | GNUNET_GE_USER |
@@ -574,7 +556,7 @@
     }
   GNUNET_GE_ASSERT (ectx, numberOfHosts_ <= sizeOfHosts_);
   GNUNET_GE_ASSERT (ectx, msg != NULL);
-  fn = getHostFileName (&msg->senderIdentity, ntohs (msg->protocol));
+  fn = get_host_filename (&msg->senderIdentity, ntohs (msg->protocol));
   buffer = GNUNET_malloc (GNUNET_MAX_BUFFER_SIZE);
   if (GNUNET_disk_file_test (ectx, fn) == GNUNET_YES)
     {
@@ -599,8 +581,8 @@
   GNUNET_free (buffer);
 
   GNUNET_mutex_lock (lock_);
-  addHostToKnown (&msg->senderIdentity, ntohs (msg->protocol));
-  host = findHost (&msg->senderIdentity);
+  add_host_to_known_hosts (&msg->senderIdentity, ntohs (msg->protocol));
+  host = lookup_host_entry (&msg->senderIdentity);
   GNUNET_GE_ASSERT (ectx, host != NULL);
 
   for (i = 0; i < host->helloCount; i++)
@@ -687,7 +669,7 @@
         }
     }
 
-  host = findHost (hostId);
+  host = lookup_host_entry (hostId);
   if ((host == NULL) || (host->protocolCount == 0))
     {
       GNUNET_mutex_unlock (lock_);
@@ -712,7 +694,7 @@
     }
 
   /* do direct read */
-  fn = getHostFileName (hostId, protocol);
+  fn = get_host_filename (hostId, protocol);
   if (1 != GNUNET_disk_file_test (ectx, fn))
     {
       GNUNET_free (fn);
@@ -840,7 +822,7 @@
 
   GNUNET_GE_ASSERT (ectx, numberOfHosts_ <= sizeOfHosts_);
   GNUNET_mutex_lock (lock_);
-  entry = findHost (identity);
+  entry = lookup_host_entry (identity);
   if (entry == NULL)
     {
       for (i = 0; i < MAX_TEMP_HOSTS; i++)
@@ -912,7 +894,7 @@
 
   GNUNET_GE_ASSERT (ectx, numberOfHosts_ <= sizeOfHosts_);
   GNUNET_mutex_lock (lock_);
-  entry = findHost (identity);
+  entry = lookup_host_entry (identity);
   if (entry == NULL)
     {
       GNUNET_mutex_unlock (lock_);
@@ -958,7 +940,7 @@
 
   GNUNET_GE_ASSERT (ectx, numberOfHosts_ <= sizeOfHosts_);
   GNUNET_mutex_lock (lock_);
-  entry = findHost (identity);
+  entry = lookup_host_entry (identity);
   if (entry == NULL)
     {
       for (i = 0; i < MAX_TEMP_HOSTS; i++)
@@ -1140,14 +1122,12 @@
  * @brief delete expired HELLO entries in data/hosts/
  */
 static int
-discardHostsHelper (const char *filename, const char *dirname, void *now)
+discardHostsHelper (void * now,
+                   const char * fn)
 {
-  char *fn;
   struct stat hostStat;
   int hostFile;
 
-  fn = GNUNET_malloc (strlen (filename) + strlen (dirname) + 2);
-  sprintf (fn, "%s%s%s", dirname, DIR_SEPARATOR_STR, filename);
   hostFile = GNUNET_disk_file_open (ectx, fn, O_WRONLY);
   if (hostFile != -1)
     {
@@ -1161,8 +1141,6 @@
             UNLINK (fn);
         }
     }
-  GNUNET_free (fn);
-
   return GNUNET_OK;
 }
 
@@ -1330,7 +1308,7 @@
   reply->header.type = htons (GNUNET_CS_PROTO_IDENTITY_INFO);
   reply->peer = *identity;
   reply->last_message = GNUNET_htonll (last);
-  reply->trust = htonl (getHostTrust (identity));
+  reply->trust = htonl (change_host_trust (identity, 0));
   reply->bpm = htonl (bpm);
   memcpy (&reply[1], address, len);
   GNUNET_free_non_null (address);
@@ -1377,8 +1355,7 @@
   id.blacklistHost = &blacklistHost;
   id.isBlacklisted = &isBlacklisted;
   id.whitelistHost = &whitelistHost;
-  id.changeHostTrust = &changeHostTrust;
-  id.getHostTrust = &getHostTrust;
+  id.changeHostTrust = &change_host_trust;
 
   for (i = 0; i < MAX_TEMP_HOSTS; i++)
     memset (&tempHosts[i], 0, sizeof (HostEntry));

Modified: GNUnet/src/applications/identity/identitytest.c
===================================================================
--- GNUnet/src/applications/identity/identitytest.c     2008-08-31 20:01:29 UTC 
(rev 7645)
+++ GNUnet/src/applications/identity/identitytest.c     2008-08-31 20:48:02 UTC 
(rev 7646)
@@ -77,19 +77,19 @@
   pid = hello->senderIdentity;
   GNUNET_free (hello);
 
-  identity->changeHostTrust (&pid, -identity->getHostTrust (&pid));
+  identity->changeHostTrust (&pid, -identity->changeHostTrust (&pid, 0));
   ASSERT (4 == identity->changeHostTrust (&pid, 4));
   GNUNET_CORE_release_service (identity);
 
   identity = GNUNET_CORE_request_service ("identity");
-  ASSERT (4 == identity->getHostTrust (&pid));
+  ASSERT (4 == identity->changeHostTrust (&pid, 0));
   ASSERT (5 == identity->changeHostTrust (&pid, 5));
   ASSERT (-2 == identity->changeHostTrust (&pid, -2));
-  ASSERT (7 == identity->getHostTrust (&pid));
+  ASSERT (7 == identity->changeHostTrust (&pid, 0));
   ASSERT (-7 == identity->changeHostTrust (&pid, -40));
   pkey = identity->getPublicPrivateKey ();
   identity->getPeerIdentity (pkey, &pid);
-  ASSERT (0 == identity->getHostTrust (&pid));
+  ASSERT (0 == identity->changeHostTrust (&pid, 0));
 
   pkey = identity->getPublicPrivateKey ();
   ASSERT (GNUNET_OK == identity->signData ("TestData", 8, &sig));

Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h        2008-08-31 20:01:29 UTC (rev 
7645)
+++ GNUnet/src/include/gnunet_fsui_lib.h        2008-08-31 20:48:02 UTC (rev 
7646)
@@ -1039,7 +1039,7 @@
  */
 typedef int (*GNUNET_FSUI_DirectoryScanCallback) (void *data,
                                                   const char *filename,
-                                                  GNUNET_DirectoryEntryCallback
+                                                  GNUNET_FileNameCallback
                                                   dec, void *decClosure);
 
 /**

Modified: GNUnet/src/include/gnunet_identity_service.h
===================================================================
--- GNUnet/src/include/gnunet_identity_service.h        2008-08-31 20:01:29 UTC 
(rev 7645)
+++ GNUnet/src/include/gnunet_identity_service.h        2008-08-31 20:48:02 UTC 
(rev 7646)
@@ -209,11 +209,6 @@
    */
   int (*changeHostTrust) (const GNUNET_PeerIdentity * hostId, int value);
 
-  /**
-   * Obtain the trust record of the host.
-   */
-  unsigned int (*getHostTrust) (const GNUNET_PeerIdentity * hostId);
-
 } GNUNET_Identity_ServiceAPI;
 
 #if 0                           /* keep Emacsens' auto-indent happy */

Modified: GNUnet/src/include/gnunet_util_common.h
===================================================================
--- GNUnet/src/include/gnunet_util_common.h     2008-08-31 20:01:29 UTC (rev 
7645)
+++ GNUnet/src/include/gnunet_util_common.h     2008-08-31 20:48:02 UTC (rev 
7646)
@@ -39,6 +39,18 @@
 #define GNUNET_YES     1
 #define GNUNET_NO      0
 
+/**
+ * Function called with a filename.
+ *
+ * @param filename complete filename (absolute path)
+ * @param data user-defined context
+ * @return GNUNET_OK to continue to iterate,
+ *  GNUNET_SYSERR to abort iteration with error!
+ */
+typedef int (*GNUNET_FileNameCallback) (void *data,
+                                       const char *filename);
+
+
 #if __STDC_VERSION__ < 199901L
 # if __GNUC__ >= 2
 #  define __func__ __FUNCTION__

Modified: GNUnet/src/include/gnunet_util_config.h
===================================================================
--- GNUnet/src/include/gnunet_util_config.h     2008-08-31 20:01:29 UTC (rev 
7645)
+++ GNUnet/src/include/gnunet_util_config.h     2008-08-31 20:48:02 UTC (rev 
7646)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2006 Christian Grothoff (and other contributing authors)
+     (C) 2006, 2008 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -62,7 +62,7 @@
 /**
  * Parse a configuration file, add all of the options in the
  * file to the configuration environment.
- * @return 0 on success, -1 on error
+ * @return 0 on success, GNUNET_SYSERR on error
  */
 int GNUNET_GC_parse_configuration (struct GNUNET_GC_Configuration *cfg,
                                    const char *filename);
@@ -70,13 +70,13 @@
 /**
  * Test if there are configuration options that were
  * changed since the last save.
- * @return 0 if clean, 1 if dirty, -1 on error (i.e. last save failed)
+ * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error 
(i.e. last save failed)
  */
 int GNUNET_GC_test_dirty (struct GNUNET_GC_Configuration *cfg);
 
 /**
  * Write configuration file.
- * @return 0 on success, -1 on error
+ * @return 0 on success, GNUNET_SYSERR on error
  */
 int GNUNET_GC_write_configuration (struct GNUNET_GC_Configuration *cfg,
                                    const char *filename);
@@ -86,7 +86,7 @@
  * @param min minimal legal value
  * @param max maximal legal value
  * @param default default value (use indicated by return value)
- * @return 0 on success, -1 on error, 1 for default
+ * @return GNUNET_NO on success, GNUNET_SYSERR on error, GNUNET_YES for default
  */
 int GNUNET_GC_get_configuration_value_number (struct GNUNET_GC_Configuration
                                               *cfg, const char *section,
@@ -110,7 +110,7 @@
  *        will NOT be aliased, maybe NULL)
  * @param value will be set to a freshly allocated configuration
  *        value, or NULL if option is not specified and no default given
- * @return 0 on success, -1 on error, 1 for default
+ * @return GNUNET_NO on success, GNUNET_SYSERR on error, GNUNET_YES for default
  */
 int GNUNET_GC_get_configuration_value_string (struct GNUNET_GC_Configuration
                                               *cfg, const char *section,
@@ -125,7 +125,7 @@
  *        will NOT be aliased, may NOT be NULL)
  * @param value will be set to a freshly allocated configuration
  *        value, or NULL if option is not specified and no default given
- * @return 0 on success, -1 on error, 1 for default
+ * @return GNUNET_NO on success, GNUNET_SYSERR on error, GNUNET_YES for default
  */
 int GNUNET_GC_get_configuration_value_filename (struct GNUNET_GC_Configuration
                                                 *cfg, const char *section,
@@ -134,6 +134,17 @@
                                                 char **value);
 
 /**
+ * Iterate over the set of filenames stored in a configuration value.
+ *
+ * @return number of filenames iterated over, -1 on error
+ */
+int GNUNET_GC_iterate_configuration_value_filenames (struct 
GNUNET_GC_Configuration
+                                                    *cfg, const char *section,
+                                                    const char *option,
+                                                    GNUNET_FileNameCallback cb,
+                                                    void * cls);
+
+/**
  * Get a configuration value that should be in a set of
  * predefined strings
  *
@@ -143,7 +154,7 @@
  *        into set given by choices
  * @param value will be set to an entry in the legal list,
  *        or NULL if option is not specified and no default given
- * @return 0 on success, -1 on error, 1 for default
+ * @return GNUNET_NO on success, GNUNET_SYSERR on error, GNUNET_YES for default
  */
 int GNUNET_GC_get_configuration_value_choice (struct GNUNET_GC_Configuration
                                               *cfg, const char *section,
@@ -177,7 +188,7 @@
 
 /**
  * Set a configuration value that should be a number.
- * @return 0 on success, -1 on error (i.e. out of memory,
+ * @return 0 on success, GNUNET_SYSERR on error (i.e. out of memory,
  *   or update refused by registered callback)
  */
 int GNUNET_GC_set_configuration_value_number (struct GNUNET_GC_Configuration
@@ -191,7 +202,7 @@
 /**
  * Set a configuration value that should be a string.
  * @param value
- * @return 0 on success, -1 on error (i.e. out of memory,
+ * @return 0 on success, GNUNET_SYSERR on error (i.e. out of memory,
  *   or update refused by registered callback)
  */
 int GNUNET_GC_set_configuration_value_string (struct GNUNET_GC_Configuration
@@ -202,10 +213,42 @@
                                               const char *value);
 
 /**
+ * Remove a filename from a configuration value that
+ * represents a list of filenames
+ *
+ * @param value filename to remove
+ * @return GNUNET_OK on success,
+ *         GNUNET_NO if the filename is not in the list,
+ *         GNUNET_SYSERR on error
+ */
+int GNUNET_GC_remove_configuration_value_filename (struct 
GNUNET_GC_Configuration
+                                                  *cfg,
+                                                  struct GNUNET_GE_Context 
*ectx,
+                                                  const char *section,
+                                                  const char *option,
+                                                  const char *value);
+
+/**
+ * Append a filename to a configuration value that
+ * represents a list of filenames
+ *
+ * @param value filename to append
+ * @return GNUNET_OK on success,
+ *         GNUNET_NO if the filename already in the list
+ *         GNUNET_SYSERR on error
+ */
+int GNUNET_GC_append_configuration_value_filename (struct 
GNUNET_GC_Configuration
+                                                  *cfg,
+                                                  struct GNUNET_GE_Context 
*ectx,
+                                                  const char *section,
+                                                  const char *option,
+                                                  const char *value);
+
+/**
  * Set a configuration value that should be in a set of
  * predefined strings.
  * @param value
- * @return 0 on success, -1 on error (i.e. out of memory,
+ * @return 0 on success, GNUNET_SYSERR on error (i.e. out of memory,
  *   or update refused by registered callback)
  */
 int GNUNET_GC_set_configuration_value_choice (struct GNUNET_GC_Configuration
@@ -221,7 +264,7 @@
  * communicated, the client must query it.
  *
  * @param ectx context to log errors to
- * @return 0 if the change is ok, -1 if the change must be
+ * @return 0 if the change is ok, GNUNET_SYSERR if the change must be
  *         refused
  */
 typedef int (*GNUNET_GC_ChangeListener) (void *ctx,
@@ -234,7 +277,7 @@
  * Attach a callback that is notified whenever a
  * configuration option changes.<p>
  *
- * @return 0 on success, -1 on error
+ * @return 0 on success, GNUNET_SYSERR on error
  */
 int GNUNET_GC_attach_change_listener (struct GNUNET_GC_Configuration *cfg,
                                       GNUNET_GC_ChangeListener callback,
@@ -243,7 +286,7 @@
 /**
  * Attach a callback that is notified whenever a
  * configuration option changes.
- * @return 0 on success, -1 on error, 1 for no such handler registered
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO for no such 
handler registered
  */
 int GNUNET_GC_detach_change_listener (struct GNUNET_GC_Configuration *cfg,
                                       GNUNET_GC_ChangeListener callback,

Modified: GNUnet/src/include/gnunet_util_disk.h
===================================================================
--- GNUnet/src/include/gnunet_util_disk.h       2008-08-31 20:01:29 UTC (rev 
7645)
+++ GNUnet/src/include/gnunet_util_disk.h       2008-08-31 20:48:02 UTC (rev 
7646)
@@ -120,15 +120,6 @@
                            const char *src, const char *dst);
 
 /**
- * Function called on each file in a directory.
- * @return GNUNET_OK to continue to iterate,
- *  GNUNET_SYSERR to abort iteration with error!
- */
-typedef int (*GNUNET_DirectoryEntryCallback) (const char *filename,
-                                              const char *dirName,
-                                              void *data);
-
-/**
  * Scan a directory for files. The name of the directory
  * must be expanded first (!).
  *
@@ -139,7 +130,7 @@
  */
 int GNUNET_disk_directory_scan (struct GNUNET_GE_Context *ectx,
                                 const char *dirName,
-                                GNUNET_DirectoryEntryCallback callback,
+                                GNUNET_FileNameCallback callback,
                                 void *data);
 
 

Modified: GNUnet/src/server/gnunet-peer-info.c
===================================================================
--- GNUnet/src/server/gnunet-peer-info.c        2008-08-31 20:01:29 UTC (rev 
7645)
+++ GNUnet/src/server/gnunet-peer-info.c        2008-08-31 20:48:02 UTC (rev 
7646)
@@ -166,14 +166,14 @@
         printf ("%s\n", (char *) &enc);
       else
         printf (_("Peer `%s' with trust %8u\n"),
-                (char *) &enc, identity->getHostTrust (id));
+                (char *) &enc, identity->changeHostTrust (id, 0));
       return GNUNET_OK;
     }
   if (be_quiet)
     printf ("%s\n", (char *) &enc);
   else
     printf (_("Peer `%s' with trust %8u and address `%s'\n"),
-            (char *) &enc, identity->getHostTrust (id), info);
+            (char *) &enc, identity->changeHostTrust (id, 0), info);
   GNUNET_free (info);
   return GNUNET_OK;
 }

Modified: GNUnet/src/util/config/config.c
===================================================================
--- GNUnet/src/util/config/config.c     2008-08-31 20:01:29 UTC (rev 7645)
+++ GNUnet/src/util/config/config.c     2008-08-31 20:48:02 UTC (rev 7646)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2006, 2007 Christian Grothoff (and other contributing authors)
+     (C) 2006, 2007, 2008 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -107,7 +107,8 @@
 
   /**
    * Modification indication since last save
-   * 0 if clean, 1 if dirty, -1 on error (i.e. last save failed)
+   * GNUNET_NO if clean, GNUNET_YES if dirty,
+   * GNUNET_SYSERR on error (i.e. last save failed)
    */
   int dirty;
 
@@ -194,7 +195,7 @@
                                    GNUNET_GE_REQUEST, "fopen", fn);
       GNUNET_mutex_unlock (cfg->lock);
       GNUNET_free (fn);
-      return -1;
+      return GNUNET_SYSERR;
     }
   GNUNET_free (fn);
   ret = 0;
@@ -225,7 +226,7 @@
           char *expanded = GNUNET_expand_file_name (cfg->ectx,
                                                     value);
           if (0 != GNUNET_GC_parse_configuration (cfg, expanded))
-            ret = -1;           /* failed to parse included config */
+            ret = GNUNET_SYSERR;           /* failed to parse included config 
*/
         }
       else if (1 == sscanf (line, "[%99[^]]]", value))
         {
@@ -267,7 +268,7 @@
                                                               section,
                                                               tag,
                                                               &value[i])))
-            ret = -1;           /* could not set value */
+            ret = GNUNET_SYSERR;           /* could not set value */
         }
       else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag))
         {
@@ -283,7 +284,7 @@
                                                               cfg->ectx,
                                                               section, tag,
                                                               "")))
-            ret = -1;           /* could not set value */
+            ret = GNUNET_SYSERR;           /* could not set value */
         }
       else
         {
@@ -294,7 +295,7 @@
                          _
                          ("Syntax error in configuration file `%s' at line 
%d.\n"),
                          filename, nr);
-          ret = -1;
+          ret = GNUNET_SYSERR;
           break;
         }
     }
@@ -305,7 +306,7 @@
                                    GNUNET_GE_ADMIN | GNUNET_GE_IMMEDIATE |
                                    GNUNET_GE_BULK | GNUNET_GE_REQUEST,
                                    "fclose", filename);
-      ret = -1;
+      ret = GNUNET_SYSERR;
     }
   /* restore dirty flag - anything we set in the meantime
      came from disk */
@@ -344,7 +345,7 @@
                                    GNUNET_GE_ERROR | GNUNET_GE_USER |
                                    GNUNET_GE_IMMEDIATE, "fopen", fn);
       GNUNET_free (fn);
-      return -1;
+      return GNUNET_SYSERR;
     }
   GNUNET_free (fn);
   error = 0;
@@ -406,12 +407,12 @@
   if (error == 0)
     {
       ret = 0;
-      data->dirty = 0;          /* last write succeeded */
+      data->dirty = GNUNET_NO;          /* last write succeeded */
     }
   else
     {
-      ret = -1;
-      data->dirty = -1;         /* last write failed */
+      ret = GNUNET_SYSERR;
+      data->dirty = GNUNET_SYSERR;         /* last write failed */
     }
   GNUNET_mutex_unlock (data->lock);
   return ret;
@@ -493,7 +494,7 @@
         {
           /* recursive update to different value -- not allowed! */
           GNUNET_GE_BREAK (ectx, 0);
-          ret = -1;
+          ret = GNUNET_SYSERR;
         }
     }
   else
@@ -524,20 +525,20 @@
               e = findEntry (data, section, option);    /* side-effects of 
callback are possible! */
               i++;
             }
-          ret = -1;             /* error -- update refused */
+          ret = GNUNET_SYSERR;             /* error -- update refused */
         }
       else
         {
           /* all confirmed, commit! */
           if ((e->val == NULL) || (0 != strcmp (e->val, e->dirty_val)))
-            data->dirty = 1;
+            data->dirty = GNUNET_YES;
           GNUNET_free_non_null (e->val);
           e->val = e->dirty_val;
           e->dirty_val = NULL;
           ret = 0;
         }
     }
-  if (ret == -1)
+  if (ret == GNUNET_SYSERR)
     GNUNET_GE_LOG (ectx,
                    GNUNET_GE_USER | GNUNET_GE_BULK | GNUNET_GE_WARNING,
                    _
@@ -582,7 +583,7 @@
         {
           if ((*number >= min) && (*number <= max))
             {
-              ret = 0;
+              ret = GNUNET_NO;
             }
           else
             {
@@ -592,7 +593,7 @@
                              _("Configuration value '%llu' for '%s' "
                                "in section '%s' is out of legal bounds 
[%llu,%llu]\n"),
                              *number, option, section, min, max);
-              ret = -1;         /* error */
+              ret = GNUNET_SYSERR;
             }
         }
       else
@@ -602,7 +603,7 @@
                          _("Configuration value '%s' for '%s'"
                            " in section '%s' should be a number\n"),
                          val, option, section, min, max);
-          ret = -1;             /* error */
+          ret = GNUNET_SYSERR;
         }
     }
   else
@@ -611,7 +612,7 @@
       GNUNET_GC_set_configuration_value_number (cfg,
                                                 cfg->ectx, section, option,
                                                 def);
-      ret = 1;                  /* default */
+      ret = GNUNET_YES;                  /* default */
     }
   GNUNET_mutex_unlock (cfg->lock);
   return ret;
@@ -633,7 +634,7 @@
     {
       val = (e->dirty_val != NULL) ? e->dirty_val : e->val;
       *value = GNUNET_strdup (val);
-      ret = 0;
+      ret = GNUNET_NO;
     }
   else
     {
@@ -645,13 +646,13 @@
                          GNUNET_GE_ERROR,
                          "Configuration value for option `%s' in section `%s' 
required.\n",
                          option, section);
-          return -1;
+          return GNUNET_SYSERR;
         }
       *value = GNUNET_strdup (def);
       GNUNET_GC_set_configuration_value_string (cfg,
                                                 cfg->ectx, section, option,
                                                 def);
-      ret = 1;                  /* default */
+      ret = GNUNET_YES;                  /* default */
     }
   GNUNET_mutex_unlock (cfg->lock);
   return ret;
@@ -688,21 +689,21 @@
                          _("Configuration value '%s' for '%s'"
                            " in section '%s' is not in set of legal 
choices\n"),
                          val, option, section);
-          ret = -1;             /* error */
+          ret = GNUNET_SYSERR;
         }
       else
         {
           *value = choices[i];
-          ret = 0;
+          ret = GNUNET_NO;
         }
     }
   else
     {
       *value = def;
       if (def == NULL)
-        ret = -1;
+        ret = GNUNET_SYSERR;
       else
-        ret = 1;                /* default */
+        ret = GNUNET_YES;                /* default */
     }
   GNUNET_mutex_unlock (cfg->lock);
   return ret;
@@ -862,7 +863,7 @@
           if (0 != callback (ctx, cfg, cfg->ectx, s->name, e->key))
             {
               GNUNET_mutex_unlock (cfg->lock);
-              return -1;
+              return GNUNET_SYSERR;
             }
           s = &cfg->sections[i];        /* side-effects of callback are 
possible! */
         }
@@ -891,11 +892,11 @@
           cfg->listeners[i] = cfg->listeners[cfg->lsize - 1];
           GNUNET_array_grow (cfg->listeners, cfg->lsize, cfg->lsize - 1);
           GNUNET_mutex_unlock (cfg->lock);
-          return 0;
+          return GNUNET_OK;
         }
     }
   GNUNET_mutex_unlock (cfg->lock);
-  return -1;
+  return GNUNET_NO;
 }
 
 /**
@@ -942,3 +943,261 @@
     return GNUNET_YES;
   return GNUNET_NO;
 }
+
+
+/**
+ * Iterate over the set of filenames stored in a configuration value.
+ *
+ * @return number of filenames iterated over, -1 on error
+ */
+int GNUNET_GC_iterate_configuration_value_filenames (struct 
GNUNET_GC_Configuration
+                                                    *cfg, const char *section,
+                                                    const char *option,
+                                                    GNUNET_FileNameCallback cb,
+                                                    void * cls)
+{
+  char * list;
+  char * pos;
+  char * end;
+  char old;
+  int ret;
+  
+  if (GNUNET_NO ==
+      GNUNET_GC_have_configuration_value(cfg,
+                                        section,
+                                        option))
+    return 0;
+  GNUNET_GC_get_configuration_value_string(cfg,
+                                          section,
+                                          option,
+                                          NULL,
+                                          &list);
+  ret = 0;
+  pos = list;
+  while (1)
+    {
+      while (pos[0] == ' ')
+       pos++;
+      if (strlen(pos) == 0)
+       break;
+      end = pos + 1;
+      while ( (end[0] != ' ') &&
+             (end[0] != '\0') )
+       {
+         if (end[0] == '\\')
+           {
+             switch (end[1])
+               {
+               case '\\':
+               case ' ':
+                 memmove(end,
+                         &end[1],
+                         strlen(&end[1])+1);
+               case '\0':
+                 /* illegal, but just keep it */
+                 break; 
+               default:
+                 /* illegal, but just ignore that there was a '/' */
+                 break;
+               }
+           }
+         end++;
+       }             
+      old = end[0];
+      end[0] = '\0';
+      if (strlen(pos) > 0) 
+       {
+         ret++;
+         if ( (cb != NULL) &&
+              (GNUNET_OK != cb(cls, pos)) )
+           {
+             ret = GNUNET_SYSERR;
+             break;    
+           }
+       }
+      if (old == '\0')
+       break;
+      pos = end + 1;     
+    }
+  GNUNET_free(list);
+  return ret;            
+}
+
+static int
+test_match(void * cls,
+          const char * fn)
+{
+  const char * of = cls;
+  return (0 == strcmp(of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
+}
+
+/**
+ * Append a filename to a configuration value that
+ * represents a list of filenames
+ *
+ * @param value filename to append
+ * @return GNUNET_OK on success,
+ *         GNUNET_NO if the filename already in the list
+ *         GNUNET_SYSERR on error
+ */
+int GNUNET_GC_append_configuration_value_filename (struct 
GNUNET_GC_Configuration
+                                                  *cfg,
+                                                  struct GNUNET_GE_Context 
*ectx,
+                                                  const char *section,
+                                                  const char *option,
+                                                  const char *value)
+{
+  char * escaped;
+  char * wpos;
+  char * old;
+  char * nw;
+  const char * rpos;
+  int ret;
+
+  if (GNUNET_SYSERR
+      == GNUNET_GC_iterate_configuration_value_filenames(cfg,
+                                                        section,
+                                                        option,
+                                                        &test_match,
+                                                        (void*) value))
+    return GNUNET_NO; /* already exists */  
+  if (GNUNET_NO ==
+      GNUNET_GC_have_configuration_value(cfg,
+                                        section,
+                                        option))
+    old = GNUNET_strdup("");
+  else 
+    GNUNET_GC_get_configuration_value_string(cfg,
+                                            section,
+                                            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++;
+    }
+  nw = GNUNET_malloc(strlen(old) + strlen(escaped) + 2);
+  strcpy(nw, old);
+  strcat(nw, " ");
+  strcat(nw, escaped);
+  ret = GNUNET_GC_set_configuration_value_string(cfg,
+                                                ectx,
+                                                section,
+                                                option,
+                                                nw);
+  GNUNET_free(old);
+  GNUNET_free(nw);    
+  GNUNET_free(escaped);
+  return GNUNET_SYSERR;
+}
+
+
+/**
+ * Remove a filename from a configuration value that
+ * represents a list of filenames
+ *
+ * @param value filename to remove
+ * @return GNUNET_OK on success,
+ *         GNUNET_NO if the filename is not in the list,
+ *         GNUNET_SYSERR on error
+ */
+int GNUNET_GC_remove_configuration_value_filename (struct 
GNUNET_GC_Configuration
+                                                  *cfg,
+                                                  struct GNUNET_GE_Context 
*ectx,
+                                                  const char *section,
+                                                  const char *option,
+                                                  const char *value)
+{
+  char * list;
+  char * pos;
+  char * end;
+  char old;
+  int ret;
+  
+  if (GNUNET_NO ==
+      GNUNET_GC_have_configuration_value(cfg,
+                                        section,
+                                        option))
+    return GNUNET_NO;
+  GNUNET_GC_get_configuration_value_string(cfg,
+                                          section,
+                                          option,
+                                          NULL,
+                                          &list);
+  ret = 0;
+  pos = list;
+  while (1)
+    {
+      while (pos[0] == ' ')
+       pos++;
+      if (strlen(pos) == 0)
+       break;
+      end = pos + 1;
+      while ( (end[0] != ' ') &&
+             (end[0] != '\0') )
+       {
+         if (end[0] == '\\')
+           {
+             switch (end[1])
+               {
+               case '\\':
+               case ' ':
+                 memmove(end,
+                         &end[1],
+                         strlen(&end[1])+1);
+               case '\0':
+                 /* illegal, but just keep it */
+                 break; 
+               default:
+                 /* illegal, but just ignore that there was a '/' */
+                 break;
+               }
+           }
+         end++;
+       }             
+      old = end[0];
+      end[0] = '\0';
+      if (strlen(pos) > 0) 
+       {
+         if (0 == strcmp(pos,
+                         value))
+           {
+             memmove(pos,
+                     &end[1],
+                     strlen(&end[1])+1);
+             ret = GNUNET_GC_set_configuration_value_string(cfg,
+                                                            ectx,
+                                                            section,
+                                                            option,
+                                                            list);
+             GNUNET_free(list);              
+             return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
+           }
+       }
+      if (old == '\0')
+       break;
+      pos = end + 1;     
+    }
+  GNUNET_free(list);
+  return GNUNET_NO;
+}
+
+/* end of config.c */

Modified: GNUnet/src/util/disk/storage.c
===================================================================
--- GNUnet/src/util/disk/storage.c      2008-08-31 20:01:29 UTC (rev 7645)
+++ GNUnet/src/util/disk/storage.c      2008-08-31 20:48:02 UTC (rev 7646)
@@ -520,20 +520,29 @@
 int
 GNUNET_disk_directory_scan (struct GNUNET_GE_Context *ectx,
                             const char *dirName,
-                            GNUNET_DirectoryEntryCallback callback,
+                            GNUNET_FileNameCallback callback,
                             void *data)
 {
   DIR *dinfo;
   struct dirent *finfo;
   struct stat istat;
   int count = 0;
+  char * name;
+  char * dname;
+  unsigned int name_len;
+  unsigned int n_size;
 
   GNUNET_GE_ASSERT (ectx, dirName != NULL);
-  if (0 != STAT (dirName, &istat))
+  dname = GNUNET_expand_file_name(ectx, dirName);
+  while ( (strlen(dname) > 0) &&
+         (dname[strlen(dname)-1] == DIR_SEPARATOR) )
+    dname[strlen(dname)-1] = '\0';
+  if (0 != STAT (dname, &istat))
     {
       GNUNET_GE_LOG_STRERROR_FILE (ectx,
                                    GNUNET_GE_WARNING | GNUNET_GE_USER |
-                                   GNUNET_GE_BULK, "stat", dirName);
+                                   GNUNET_GE_BULK, "stat", dname);
+      GNUNET_free(dname);
       return GNUNET_SYSERR;
     }
   if (!S_ISDIR (istat.st_mode))
@@ -541,19 +550,24 @@
       GNUNET_GE_LOG (ectx,
                      GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
                      _("Expected `%s' to be a directory!\n"), dirName);
+      GNUNET_free(dname);
       return GNUNET_SYSERR;
     }
   errno = 0;
-  dinfo = OPENDIR (dirName);
+  dinfo = OPENDIR (dname);
   if ((errno == EACCES) || (dinfo == NULL))
     {
       GNUNET_GE_LOG_STRERROR_FILE (ectx,
                                    GNUNET_GE_WARNING | GNUNET_GE_USER |
-                                   GNUNET_GE_BULK, "opendir", dirName);
+                                   GNUNET_GE_BULK, "opendir", dname);
       if (dinfo != NULL)
         closedir (dinfo);
+      GNUNET_free(dname);
       return GNUNET_SYSERR;
     }
+  name_len = 256;
+  n_size = strlen(dname) + name_len + 2;
+  name = GNUNET_malloc(n_size);
   while ((finfo = readdir (dinfo)) != NULL)
     {
       if ((0 == strcmp (finfo->d_name, ".")) ||
@@ -561,41 +575,39 @@
         continue;
       if (callback != NULL)
         {
-          if (GNUNET_OK != callback (finfo->d_name, dirName, data))
+         if (name_len < strlen(finfo->d_name))
+           {
+             GNUNET_free(name);
+             name_len = strlen(finfo->d_name);
+             n_size = strlen(dname) + name_len + 2;
+             name = GNUNET_malloc(n_size);
+           }
+         /* dname can end in "/" only if dname == "/";
+            if dname does not end in "/", we need to add
+            a "/" (otherwise, we must not!) */
+         GNUNET_snprintf(name,
+                         n_size,
+                         "%s%s%s",
+                         dname,
+                         (strcmp(dname, DIR_SEPARATOR_STR) == 0) ? "" : 
DIR_SEPARATOR_STR,
+                         finfo->d_name);
+          if (GNUNET_OK != callback (name, data))
             {
               closedir (dinfo);
+             GNUNET_free(name);
+             GNUNET_free(dname);
               return GNUNET_SYSERR;
             }
         }
       count++;
     }
   closedir (dinfo);
+  GNUNET_free(name);
+  GNUNET_free(dname);
   return count;
 }
 
 /**
- * Callback for GNUNET_disk_directory_remove
- */
-static int
-rmHelper (const char *fil, const char *dir, void *ctx)
-{
-  struct GNUNET_GE_Context *ectx = ctx;
-  char *fn;
-  size_t n;
-
-  n = strlen (dir) + strlen (fil) + 2;
-  fn = GNUNET_malloc (n);
-  GNUNET_snprintf (fn, n, "%s/%s", dir, fil);
-  if (GNUNET_SYSERR == GNUNET_disk_directory_remove (ectx, fn))
-    {
-      GNUNET_free (fn);
-      return GNUNET_SYSERR;
-    }
-  GNUNET_free (fn);
-  return GNUNET_OK;
-}
-
-/**
  * Remove all files in a directory (rm -rf). Call with
  * caution.
  *
@@ -626,7 +638,10 @@
       return GNUNET_SYSERR;
     }
   if (GNUNET_SYSERR ==
-      GNUNET_disk_directory_scan (ectx, fileName, &rmHelper, ectx))
+      GNUNET_disk_directory_scan (ectx,
+                                 fileName, 
+                                 
(GNUNET_FileNameCallback)&GNUNET_disk_directory_remove,
+                                 ectx))
     return GNUNET_SYSERR;
   if (0 != RMDIR (fileName))
     {

Modified: GNUnet/src/util/loggers/file.c
===================================================================
--- GNUnet/src/util/loggers/file.c      2008-08-31 20:01:29 UTC (rev 7645)
+++ GNUnet/src/util/loggers/file.c      2008-08-31 20:48:02 UTC (rev 7646)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2006 Christian Grothoff (and other contributing authors)
+     (C) 2006, 2008 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -93,8 +93,11 @@
 
 } FileContext;
 
+/**
+ * Get the date format we use for logging.
+ */
 static char *
-getDateFormat ()
+get_date_format ()
 {
   char *datefmt;
   char *idx;
@@ -120,11 +123,11 @@
  * Remove file if it is an old log
  */
 static int
-removeOldLog (const char *fil, const char *dir, void *ptr)
+remove_old_log (void * ptr,
+               const char *fullname)
 {
   const FileContext *ctx = ptr;
   struct tm t;
-  char *fullname;
   const char *logdate;
   const char *ret;
   time_t curtime;
@@ -135,30 +138,18 @@
   time (&curtime);
   lcltime = *localtime (&curtime);
   def = ctx->basename;
-  fullname = GNUNET_malloc (strlen (dir) + strlen (fil) + 2);
-  strcpy (fullname, dir);
-  if (dir[strlen (dir) - 1] != DIR_SEPARATOR)
-    strcat (fullname, DIR_SEPARATOR_STR);
-  strcat (fullname, fil);
   if (0 != strncmp (def, fullname, strlen (def)))
-    {
-      GNUNET_free (fullname);
-      return GNUNET_OK;
-    }
+    return GNUNET_OK;    
   logdate = &fullname[strlen (def) + 1];
-  datefmt = getDateFormat ();
+  datefmt = get_date_format ();
   ret = strptime (logdate, datefmt, &t);
   GNUNET_free (datefmt);
   if ((ret == NULL) || (ret[0] != '\0'))
-    {
-      GNUNET_free (fullname);
-      return GNUNET_OK;         /* not a logfile */
-    }
+    return GNUNET_OK;         /* not a logfile */    
   if (ctx->logrotate
       + t.tm_year * 365 + t.tm_yday
       - lcltime.tm_year * 365 - lcltime.tm_yday <= 0)
-    UNLINK (fullname);          /* TODO: add ctx->fctx */
-  GNUNET_free (fullname);
+    UNLINK (fullname);          /* TODO: add ctx->ectx */
   return GNUNET_OK;
 }
 
@@ -167,7 +158,7 @@
  * formatted for appending to the filename.
  */
 static char *
-getLogFileName (const char *name)
+get_log_file_name (const char *name)
 {
   time_t curtime;
   struct tm lcltime;
@@ -178,7 +169,7 @@
 
   time (&curtime);
   lcltime = *localtime (&curtime);
-  datefmt = getDateFormat ();
+  datefmt = get_date_format ();
 #ifdef localtime_r
   localtime_r (&curtime, &lcltime);
 #else
@@ -197,6 +188,9 @@
   return ret;
 }
 
+/**
+ * Purge outdated log files.
+ */
 static void
 purge_old_logs (FileContext * fctx, const char *logfilename)
 {
@@ -206,13 +200,13 @@
   while ((strlen (dirname) > 0) &&
          (dirname[strlen (dirname) - 1] != DIR_SEPARATOR))
     dirname[strlen (dirname) - 1] = '\0';
-  GNUNET_disk_directory_scan (NULL, dirname, &removeOldLog, fctx);
+  GNUNET_disk_directory_scan (NULL, dirname, &remove_old_log, fctx);
   GNUNET_free (dirname);
 
 }
 
 static void
-filelogger (void *cls, GNUNET_GE_KIND kind, const char *date, const char *msg)
+file_log_callback (void *cls, GNUNET_GE_KIND kind, const char *date, const 
char *msg)
 {
   FileContext *fctx = cls;
   char *name;
@@ -221,7 +215,7 @@
   GNUNET_mutex_lock (fctx->lock);
   if (fctx->logrotate)
     {
-      name = getLogFileName (fctx->basename);
+      name = get_log_file_name (fctx->basename);
       if ((fctx->first_start == GNUNET_YES)
           || (0 != strcmp (name, fctx->filename)))
         {
@@ -281,7 +275,7 @@
 }
 
 static void
-fileclose (void *cls)
+file_logger_close_callback (void *cls)
 {
   FileContext *fctx = cls;
 
@@ -322,7 +316,7 @@
   GNUNET_get_time_int32 (&start);
   if (logrotate != 0)
     {
-      name = getLogFileName (filename);
+      name = get_log_file_name (filename);
     }
   else
     {
@@ -353,35 +347,45 @@
   fctx->lock = GNUNET_mutex_create (GNUNET_YES);
   purge_old_logs (fctx, name);
   return GNUNET_GE_create_context_callback (mask,
-                                            &filelogger, fctx, &fileclose,
+                                            &file_log_callback, fctx, 
+                                           &file_logger_close_callback,
                                             NULL);
 }
 
-
 /**
- * Create a logger that writes events to stderr
+ * Create a logger that writes events to the 
+ * given file (but does not delete or close it
+ * and does no logrotation).
  *
  * @param mask which events should be logged?
  */
-struct GNUNET_GE_Context *
-GNUNET_GE_create_context_stderr (int logDate, GNUNET_GE_KIND mask)
+static struct GNUNET_GE_Context *
+create_log_context_fd (int logDate,
+                      GNUNET_GE_KIND mask,
+                      FILE * fd)
 {
   FileContext *fctx;
 
   fctx = GNUNET_malloc (sizeof (FileContext));
+  memset(fctx, 0, sizeof(FileContext));
   fctx->logdate = logDate;
-  fctx->logrotate = 0;
-  fctx->handle = stderr;
-  fctx->filename = NULL;
-  fctx->basename = NULL;
-  fctx->user = NULL;
-  fctx->logstart = 0;
-  fctx->first_start = GNUNET_NO;
+  fctx->handle = fd;
   fctx->lock = GNUNET_mutex_create (GNUNET_YES);
   return GNUNET_GE_create_context_callback (mask,
-                                            &filelogger, fctx, &fileclose,
+                                            &file_log_callback, fctx, 
&file_logger_close_callback,
                                             NULL);
+}
 
+
+/**
+ * Create a logger that writes events to stderr
+ *
+ * @param mask which events should be logged?
+ */
+struct GNUNET_GE_Context *
+GNUNET_GE_create_context_stderr (int logDate, GNUNET_GE_KIND mask)
+{
+  return create_log_context_fd(logDate, mask, stderr);
 }
 
 /**
@@ -392,20 +396,7 @@
 struct GNUNET_GE_Context *
 GNUNET_GE_create_context_stdout (int logDate, GNUNET_GE_KIND mask)
 {
-  FileContext *fctx;
-
-  fctx = GNUNET_malloc (sizeof (FileContext));
-  fctx->logdate = logDate;
-  fctx->logrotate = 0;
-  fctx->first_start = GNUNET_NO;
-  fctx->handle = stdout;
-  fctx->filename = NULL;
-  fctx->basename = NULL;
-  fctx->user = NULL;
-  fctx->logstart = 0;
-  fctx->lock = GNUNET_mutex_create (GNUNET_YES);
-  return GNUNET_GE_create_context_callback (mask,
-                                            &filelogger, fctx, &fileclose,
-                                            NULL);
-
+  return create_log_context_fd(logDate, mask, stdout);
 }
+
+/* end of file.c */

Modified: GNUnet/src/util/pseudonym/info.c
===================================================================
--- GNUnet/src/util/pseudonym/info.c    2008-08-31 20:01:29 UTC (rev 7645)
+++ GNUnet/src/util/pseudonym/info.c    2008-08-31 20:48:02 UTC (rev 7646)
@@ -174,14 +174,21 @@
 };
 
 static int
-list_pseudonym_helper (const char *fn, const char *dirName, void *cls)
+list_pseudonym_helper (void * cls,
+                      const char *fullname)
 {
   struct ListPseudonymClosure *c = cls;
   int ret;
   GNUNET_HashCode id;
   int rating;
   struct GNUNET_MetaData *meta;
+  const char * fn;
 
+  if (strlen(fullname) < sizeof(GNUNET_EncName))
+    return GNUNET_OK;
+  fn = &fullname[strlen(fullname) + 1 - sizeof(GNUNET_EncName)];
+  if (fn[-1] != DIR_SEPARATOR)
+    return GNUNET_OK;
   ret = GNUNET_OK;
   if (GNUNET_OK != GNUNET_enc_to_hash (fn, &id))
     return GNUNET_OK;           /* invalid name */





reply via email to

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