gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r1108 - in GNUnet: . src/applications/fs/ecrs src/applicati


From: grothoff
Subject: [GNUnet-SVN] r1108 - in GNUnet: . src/applications/fs/ecrs src/applications/fs/fsui src/applications/fs/module src/applications/fs/tools src/applications/identity src/applications/session src/applications/stats src/applications/topology_default src/applications/topology_f2f src/include src/server src/util
Date: Tue, 28 Jun 2005 06:35:20 -0700 (PDT)

Author: grothoff
Date: 2005-06-28 06:34:52 -0700 (Tue, 28 Jun 2005)
New Revision: 1108

Modified:
   GNUnet/ChangeLog
   GNUnet/src/applications/fs/ecrs/indexinfo.c
   GNUnet/src/applications/fs/ecrs/namespace.c
   GNUnet/src/applications/fs/ecrs/unindex.c
   GNUnet/src/applications/fs/ecrs/upload.c
   GNUnet/src/applications/fs/ecrs/uri.c
   GNUnet/src/applications/fs/fsui/namespace_info.c
   GNUnet/src/applications/fs/fsui/unindex.c
   GNUnet/src/applications/fs/fsui/upload.c
   GNUnet/src/applications/fs/module/ondemand.c
   GNUnet/src/applications/fs/tools/gnunet-directory.c
   GNUnet/src/applications/identity/identity.c
   GNUnet/src/applications/session/connect.c
   GNUnet/src/applications/stats/clientapi.c
   GNUnet/src/applications/stats/statistics.c
   GNUnet/src/applications/stats/statistics.h
   GNUnet/src/applications/topology_default/topology.c
   GNUnet/src/applications/topology_f2f/topology.c
   GNUnet/src/include/gnunet_core.h
   GNUnet/src/include/gnunet_identity_service.h
   GNUnet/src/include/gnunet_util.h
   GNUnet/src/server/connection.c
   GNUnet/src/server/core.c
   GNUnet/src/server/handler.c
   GNUnet/src/server/handler.h
   GNUnet/src/server/tcpserver.c
   GNUnet/src/server/tcpserver.h
   GNUnet/src/util/hashing.c
   GNUnet/src/util/logging.c
   GNUnet/src/util/semaphore.c
   GNUnet/src/util/semaphoretest.c
   GNUnet/src/util/state.c
   GNUnet/src/util/statuscalls.c
   GNUnet/src/util/statuscallstest.c
   GNUnet/src/util/storage.c
Log:
fixing FIXMEs

Modified: GNUnet/ChangeLog
===================================================================
--- GNUnet/ChangeLog    2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/ChangeLog    2005-06-28 13:34:52 UTC (rev 1108)
@@ -1,3 +1,8 @@
+Tue Jun 28 13:41:58 UTC 2005
+       Fixed various open FIXMEs, including error handling,
+       bad performance and some memory leaks (gnunet-tools
+       only, not in gnunetd).
+       
 Mon Jun 27 17:21:09 CEST 2005
        Fixed double-free segfault.
        Fixed problem with session timeout not happening.

Modified: GNUnet/src/applications/fs/ecrs/indexinfo.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/indexinfo.c 2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/fs/ecrs/indexinfo.c 2005-06-28 13:34:52 UTC (rev 
1108)
@@ -61,16 +61,15 @@
   int cnt;
 };
 
-static void iiHelper(const char * fn,
-                    const char * dir,
-                    struct iiC * cls) {
+static int iiHelper(const char * fn,
+                   const char * dir,
+                   void * ptr) {
+  struct iiC * cls = ptr;
   char * fullName;
   char * lnkName;
   size_t size;
   int ret;
 
-  if (cls->cnt == SYSERR)
-    return;
   fullName = MALLOC(strlen(dir) + strlen(fn) + 4);
   strcpy(fullName, dir);
   strcat(fullName, DIR_SEPARATOR_STR);
@@ -89,11 +88,13 @@
        continue;
       }      
       if (errno != EINVAL) {
-       LOG_FILE_STRERROR(LOG_WARNING, "readlink", fullName);
+       LOG_FILE_STRERROR(LOG_WARNING, 
+                         "readlink", 
+                         fullName);
       }
       FREE(lnkName);
       FREE(fullName);
-      return; /* error */
+      return OK; /* error */
     } else {
       lnkName[ret] = '\0';
       break;
@@ -101,10 +102,15 @@
   }
   cls->cnt++;
   if (OK != cls->iterator(lnkName,
-                         cls->closure))
+                         cls->closure)) {
     cls->cnt = SYSERR;
+    FREE(fullName);      
+    FREE(lnkName);
+    return SYSERR;
+  }
   FREE(fullName);      
   FREE(lnkName);
+  return OK;
 }
 
 /**
@@ -142,7 +148,7 @@
   cls.closure = closure;
   cls.cnt = 0;
   scanDirectory(indexDirectory,
-               (DirectoryEntryCallback) &iiHelper,
+               &iiHelper,
                &cls);
   FREE(indexDirectory);
   return cls.cnt;

Modified: GNUnet/src/applications/fs/ecrs/namespace.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/namespace.c 2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/fs/ecrs/namespace.c 2005-06-28 13:34:52 UTC (rev 
1108)
@@ -281,13 +281,17 @@
   char * fileName;
   PrivateKeyEncoded * hke;
   char * dst;
-  unsigned short len;
+  unsigned long long len;
   HashCode512 namespace;
   PublicKey pk;
 
   /* FIRST: read and decrypt pseudonym! */
   fileName = getPseudonymFileName(name);
-  len = getFileSize(fileName);
+  if (OK != getFileSize(fileName,
+                       &len)) {
+    FREE(fileName);
+    return SYSERR;
+  }
   if (len < 2) {
     LOG(LOG_ERROR,
         _("File '%s' does not contain a pseudonym.\n"),
@@ -354,12 +358,16 @@
   char * fileName;
   PrivateKeyEncoded * hke;
   char * dst;
-  unsigned short len;
+  unsigned long long len;
   HashCode512 hc;
 
   /* FIRST: read pseudonym! */
   fileName = getPseudonymFileName(name);
-  len = getFileSize(fileName);
+  if (OK != getFileSize(fileName,
+                       &len)) {
+    FREE(fileName);
+    return SYSERR;
+  }
   if (len < 2) {
     LOG(LOG_ERROR,
         _("File '%s' does not contain a pseudonym.\n"),
@@ -487,15 +495,15 @@
   int cnt;
 };
 
-static int processFile_(char * name,
-                       char * dirName,
+static int processFile_(const char * name,
+                       const char * dirName,
                        void * cls) {
   struct lNCLS * c = cls;
   struct PrivateKey * hk;
   char * fileName;
   PrivateKeyEncoded * hke;
   char * dst;
-  unsigned short len;
+  unsigned long long len;
   HashCode512 namespace;
   PublicKey pk;
 
@@ -503,7 +511,11 @@
     return SYSERR;
 
   fileName = getPseudonymFileName(name);
-  len = getFileSize(fileName);
+  if (OK != getFileSize(fileName,
+                       &len)) {
+    FREE(fileName);
+    return OK;
+  }
   if (len < 2) {
     LOG(LOG_ERROR,
         _("File '%s' does not contain a pseudonym.\n"),
@@ -564,7 +576,7 @@
   myCLS.cnt = 0;
   dirName = getPseudonymFileName("");
   scanDirectory(dirName,
-               (DirectoryEntryCallback) &processFile_,
+               &processFile_,
                &myCLS);
   FREE(dirName);
   return myCLS.cnt;

Modified: GNUnet/src/applications/fs/ecrs/unindex.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/unindex.c   2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/fs/ecrs/unindex.c   2005-06-28 13:34:52 UTC (rev 
1108)
@@ -206,10 +206,12 @@
     BREAK();
     return SYSERR;
   }
+  if (OK != getFileSize(filename,
+                       &filesize)) 
+    return SYSERR;
   sock = getClientSocket();
   if (sock == NULL)
     return SYSERR;
-  filesize = getFileSize(filename);
   eta = 0;
   if (upcb != NULL)
     upcb(filesize, 0, eta, upcbClosure);

Modified: GNUnet/src/applications/fs/ecrs/upload.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/upload.c    2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/fs/ecrs/upload.c    2005-06-28 13:34:52 UTC (rev 
1108)
@@ -166,10 +166,12 @@
        filename);
     return SYSERR;
   }
+  if (OK != getFileSize(filename,
+                       &filesize)) 
+    return SYSERR;
   sock = getClientSocket();
   if (sock == NULL)
     return SYSERR;
-  filesize = getFileSize(filename);
   eta = 0;
   if (upcb != NULL)
     upcb(filesize, 0, eta, upcbClosure);

Modified: GNUnet/src/applications/fs/ecrs/uri.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/uri.c       2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/fs/ecrs/uri.c       2005-06-28 13:34:52 UTC (rev 
1108)
@@ -512,16 +512,29 @@
 
 
 /**
- * Duplicate URI.  FIXME: this is the QnD, costly
- * implementation.
+ * Duplicate URI.
  */
 URI * ECRS_dupUri(const URI * uri) {
-  char * tmp;
   struct ECRS_URI * ret;
+  int i;
 
-  tmp = ECRS_uriToString(uri);
-  ret = ECRS_stringToUri(tmp);
-  FREE(tmp);
+  ret = MALLOC(sizeof(URI));
+  memcpy(ret,
+        uri,
+        sizeof(URI));
+  switch (ret->type) {
+  case ksk:
+    if (ret->data.ksk.keywordCount > 0) {
+      ret->data.ksk.keywords 
+       = MALLOC(ret->data.ksk.keywordCount * sizeof(char*));
+      for (i=0;i<ret->data.ksk.keywordCount;i++) 
+       ret->data.ksk.keywords[i]
+         = STRDUP(uri->data.ksk.keywords[i]);      
+    }
+    break;
+  default:
+    break;
+  }
   return ret;
 }
 
@@ -653,33 +666,55 @@
 
 
 /**
- * Are these two URIs equal?  FIXME: not very efficient
- * implementation.  Also, for keyword URIs, we might
- * want to allow permuations.
+ * Are these two URIs equal?
  */
 int ECRS_equalsUri(const struct ECRS_URI * uri1,
                   const struct ECRS_URI * uri2) {
-  char * u1;
-  char * u2;
   int ret;
+  int i;
+  int j;
   
   GNUNET_ASSERT(uri1 != NULL);
   GNUNET_ASSERT(uri2 != NULL);
-  u1 = ECRS_uriToString(uri1);
-  u2 = ECRS_uriToString(uri2);
-  if ( (u1 == NULL) || (u2 == NULL)) {
-    BREAK();
-    FREENONNULL(u1);
-    FREENONNULL(u2);
+  if (uri1->type != uri2->type)
     return NO;
-  }
-  ret = strcmp(u1, u2);
-  FREE(u1);
-  FREE(u2);
-  if (ret == 0)
+  switch(uri1->type) {
+  case chk:
+    if (0 == memcmp(&uri1->data.chk,
+                   &uri2->data.chk,
+                   sizeof(FileIdentifier)))
+      return YES;
+    else
+      return NO;
+  case sks:
+    if (equalsHashCode512(&uri1->data.sks.namespace,
+                         &uri2->data.sks.namespace) &&
+       equalsHashCode512(&uri1->data.sks.identifier,
+                         &uri2->data.sks.identifier) )
+       
+      return YES;
+    else
+      return NO;
+  case ksk:
+    if (uri1->data.ksk.keywordCount !=
+       uri2->data.ksk.keywordCount)
+      return NO;
+    for (i=0;i<uri1->data.ksk.keywordCount;i++) {
+      ret = NO;
+      for (j=0;j<uri2->data.ksk.keywordCount;j++) {
+       if (0 == strcmp(uri1->data.ksk.keywords[i],
+                       uri2->data.ksk.keywords[j])) {
+         ret = YES;
+         break;
+       }
+      }
+      if (ret == NO)
+       return NO;                      
+    }
     return YES;
-  else
+  default:
     return NO;
+  }
 }
 
 

Modified: GNUnet/src/applications/fs/fsui/namespace_info.c
===================================================================
--- GNUnet/src/applications/fs/fsui/namespace_info.c    2005-06-27 22:08:16 UTC 
(rev 1107)
+++ GNUnet/src/applications/fs/fsui/namespace_info.c    2005-06-28 13:34:52 UTC 
(rev 1108)
@@ -76,8 +76,8 @@
 static int readNamespaceInfo(const char * namespaceName,
                             struct ECRS_MetaData ** meta,
                             int * ranking) {
+  unsigned long long len;
   unsigned int size;
-  unsigned int tag;
   char * buf;
   char * fn;
   char * fnBase;
@@ -98,28 +98,32 @@
   strcat(fn, namespaceName);
   FREE(fnBase);
 
-  tag = getFileSize(fn);
-  if (tag <= sizeof(int)) {
+  if (OK != getFileSize(fn,
+                       &len)) {
     FREE(fn);
     return SYSERR;
   }
-  if (tag > 16 * 1024 * 1024) {
+  if (len <= sizeof(int)) {
+    FREE(fn);
+    return SYSERR;
+  }
+  if (len > 16 * 1024 * 1024) {
     /* too big, must be invalid! remove! */
     BREAK();
     UNLINK(fn);
     FREE(fn);
     return SYSERR;
   }
-  buf = MALLOC(tag);
-  if (tag != readFile(fn,
-                     tag,
+  buf = MALLOC(len);
+  if (len != readFile(fn,
+                     len,
                      buf)) {
     FREE(buf);
     FREE(fn);
     return SYSERR;
   }
 
-  size = tag - sizeof(int);
+  size = len - sizeof(int);
   *ranking = ntohl(((int *) buf)[0]);
   if (OK != ECRS_deserializeMetaData(meta,
                                     &buf[sizeof(int)],
@@ -210,7 +214,6 @@
 typedef struct {
   FSUI_NamespaceIterator iterator;
   void * closure;
-  int ret;
 } LNClosure;
 
 static int localListNamespaceHelper(const HashCode512 * nsid,
@@ -221,8 +224,6 @@
   struct ECRS_MetaData * meta;
   int rating;
 
-  if (c->ret == SYSERR)
-    return SYSERR;
   if (OK != readNamespaceInfo(name,
                              &meta,
                              &rating)) {
@@ -235,41 +236,32 @@
                    meta,
                    rating);
   ECRS_freeMetaData(meta);
-  if (ret == SYSERR)
-    c->ret = ret;
-  else
-    c->ret++;
-  return OK;
+  return ret;
 }
 
-static void listNamespaceHelper(const char * fn,
-                               const char * dirName,
-                               void * cls) {
+static int listNamespaceHelper(const char * fn,
+                              const char * dirName,
+                              void * cls) {
   LNClosure * c = cls;
   int ret;
   struct ECRS_MetaData * meta;
   int rating;
   HashCode512 id;
 
-  if (c->ret == SYSERR)
-    return;
   if (OK != enc2hash(fn,
                     &id))
-    return; /* invalid name */
+    return OK; /* invalid name */
   if (OK != readNamespaceInfo(fn,
                              &meta,
                              &rating))
-    return; /* ignore entry */
+    return OK; /* ignore entry */
   ret = c->iterator(c->closure,
                    fn,
                    &id,
                    meta,
                    rating);
   ECRS_freeMetaData(meta);
-  if (ret == SYSERR)
-    c->ret = ret;
-  else
-    c->ret++;
+  return OK;
 }
 
 /**
@@ -283,14 +275,13 @@
                        FSUI_NamespaceIterator iterator,
                        void * closure) {
   LNClosure cls;
+  int ret;
 
   cls.iterator = iterator;
   cls.closure = closure;
-  cls.ret = 0;
-
   if (local == YES) {
-    ECRS_listNamespaces(&localListNamespaceHelper,
-                       &cls);
+    ret = ECRS_listNamespaces(&localListNamespaceHelper,
+                             &cls);
   } else {
     char * fn;
     char * fnBase;
@@ -305,12 +296,12 @@
     strcat(fn, DIR_SEPARATOR_STR);
     strcat(fn, NS_DIR);
     mkdirp(fn);
-    scanDirectory(fn,
-                 &listNamespaceHelper,
-                 &cls);
+    ret = scanDirectory(fn,
+                       &listNamespaceHelper,
+                       &cls);
     FREE(fn);
   }
-  return cls.ret;
+  return ret;
 }
 
 /**
@@ -367,22 +358,29 @@
   char * fn;
   struct UpdateData * buf;
   char * uri;
-  size_t size;
+  unsigned long long size;
   size_t pos;
 
   fn = getUpdateDataFilename(nsname,
                             lastId);
-  size = getFileSize(fn);
+  if (OK != getFileSize(fn,
+                       &size)) {
+    FREE(fn);
+    return SYSERR;
+  }
   if ( (size == 0) ||
        (size <= sizeof(struct UpdateData)) ||
-       (size > 1024 * 1024 * 16) )
+       (size > 1024 * 1024 * 16) ) {
+    FREE(fn);
     return SYSERR;
+  }
 
   buf = MALLOC(size);
   if (size != readFile(fn,
                       size,    
                       buf)) {
     FREE(buf);
+    FREE(fn);
     return SYSERR;
   }
   FREE(fn);
@@ -622,9 +620,10 @@
   int cnt;
 };
 
-void lNCHelper(const char * fil,
-              const char * dir,
-              struct lNCC * cls) {
+static int lNCHelper(const char * fil,
+                    const char * dir,
+                    void * ptr) {
+  struct lNCC * cls = ptr;
   ECRS_FileInfo fi;
   HashCode512 lastId;
   HashCode512 nextId;
@@ -633,11 +632,9 @@
   cron_t nextTime;
   cron_t now;
 
-  if (cls->cnt == SYSERR)
-    return;
   if (OK != enc2hash(fil,
                     &lastId))
-    return;
+    return OK;
   fi.uri = NULL;
   fi.meta = NULL;
   if (OK != readUpdateData(cls->name,
@@ -646,7 +643,7 @@
                           &fi,
                           &pubFreq,
                           &lastTime))
-    return;
+    return OK;
   cls->cnt++;
   if (pubFreq == ECRS_SBLOCK_UPDATE_SPORADIC) {
     nextTime = 0;
@@ -663,11 +660,14 @@
                      &nextId,
                      pubFreq,
                      nextTime)) {
-      cls->cnt = SYSERR;
+      ECRS_freeUri(fi.uri);
+      ECRS_freeMetaData(fi.meta);
+      return SYSERR;
     }
   }
   ECRS_freeUri(fi.uri);
   ECRS_freeMetaData(fi.meta);
+  return OK;
 }
 
 /**
@@ -687,9 +687,12 @@
   dirName = getUpdateDataFilename(name,
                                  NULL);
   mkdirp(dirName);
-  scanDirectory(dirName,
-               (DirectoryEntryCallback)&lNCHelper,
-               &cls);
+  if (SYSERR == scanDirectory(dirName,
+                             &lNCHelper,
+                             &cls)) {
+    FREE(dirName);
+    return SYSERR;
+  }
   FREE(dirName);
   return cls.cnt;
 }

Modified: GNUnet/src/applications/fs/fsui/unindex.c
===================================================================
--- GNUnet/src/applications/fs/fsui/unindex.c   2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/fs/fsui/unindex.c   2005-06-28 13:34:52 UTC (rev 
1108)
@@ -66,8 +66,6 @@
   FSUI_Event event;
   int ret;
 
-  printf("unindexing '%s'\n",
-        utc->filename);
   ret = ECRS_unindexFile(&utc->filename[1],
                         (ECRS_UploadProgressCallback) &progressCallback,
                         utc,
@@ -75,7 +73,11 @@
                         NULL);
   if (ret == OK) {
     event.type = FSUI_unindex_complete;
-    event.data.UnindexComplete.total = getFileSize(utc->filename);
+    if (OK != getFileSize(utc->filename,
+                         &event.data.UnindexComplete.total)) {
+      BREAK();
+      event.data.UnindexComplete.total = 0;
+    }
     event.data.UnindexComplete.filename = utc->filename;
     event.data.UnindexComplete.start_time = utc->start_time;
   } else {

Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c    2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/fs/fsui/upload.c    2005-06-28 13:34:52 UTC (rev 
1108)
@@ -192,15 +192,17 @@
 /**
  * For each file in the directory, upload (recursively).
  */
-static void dirEntryCallback(const char * filename,
-                            const char * dirName,
-                            UploadThreadClosure * utc) {
+static int dirEntryCallback(const char * filename,
+                           const char * dirName,
+                           void * ptr) {
+  UploadThreadClosure * utc = ptr;
   char * fn;
   struct ECRS_URI * uri;
   struct ECRS_URI * keywordUri;
   struct ECRS_MetaData * meta;
   FSUI_Event event;
   int ret;
+  unsigned long long len;
 
   fn = MALLOC(strlen(filename) + strlen(dirName) + 2);
   strcpy(fn, dirName);
@@ -223,7 +225,8 @@
     event.data.UploadComplete.total = utc->main_total;
     event.data.UploadComplete.filename = utc->filename;
     event.data.UploadComplete.uri = uri;
-    utc->main_completed += getFileSize(fn);
+    if (OK == getFileSize(fn, &len))
+      utc->main_completed += len;
     event.data.UploadComplete.eta
       = (cron_t) (utc->start_time +
                  (((double)(cronTime(NULL)
@@ -248,7 +251,7 @@
     prev = utc->dir;
     utc->dir = &current;
     scanDirectory(fn,
-                 (DirectoryEntryCallback)&dirEntryCallback,
+                 &dirEntryCallback,
                  utc);
     meta = NULL;
     utc->dir = prev;
@@ -300,6 +303,7 @@
     FSUI_trackURI(&utc->dir->fis[utc->dir->fiCount-1]);
   }
   FREE(fn);
+  return OK;
 }
 
 /**
@@ -318,7 +322,12 @@
     = ECRS_getFromMetaData(utc->meta,
                           EXTRACTOR_FILENAME);
   cronTime(&utc->start_time);
-  utc->main_total = getFileSize(utc->main_filename);
+
+  if (OK != getFileSize(utc->main_filename,
+                       &utc->main_total)) {
+    utc->main_total = 0;
+    /* or signal error?? */
+  }
   utc->main_completed = 0;
   ret = SYSERR;
   uri = NULL;
@@ -368,7 +377,7 @@
     utc->dir = &current;
     utc->filename = utc->main_filename;
     scanDirectory(utc->main_filename,
-                 (DirectoryEntryCallback)&dirEntryCallback,
+                 &dirEntryCallback,
                  utc);
     ret = uploadDirectory(utc,
                          utc->main_filename,

Modified: GNUnet/src/applications/fs/module/ondemand.c
===================================================================
--- GNUnet/src/applications/fs/module/ondemand.c        2005-06-27 22:08:16 UTC 
(rev 1107)
+++ GNUnet/src/applications/fs/module/ondemand.c        2005-06-28 13:34:52 UTC 
(rev 1108)
@@ -580,7 +580,11 @@
     return SYSERR;
   }
   pos = 0;
-  size = getFileSize(fn);
+  if (OK != getFileSize(fn, 
+                       &size)) {
+    FREE(fn);
+    return SYSERR;
+  }
   block = MALLOC(sizeof(DBlock) + blocksize);
   block->type = htonl(D_BLOCK);
   while (pos < size) {

Modified: GNUnet/src/applications/fs/tools/gnunet-directory.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-directory.c 2005-06-27 22:08:16 UTC 
(rev 1107)
+++ GNUnet/src/applications/fs/tools/gnunet-directory.c 2005-06-28 13:34:52 UTC 
(rev 1108)
@@ -64,36 +64,42 @@
 }
 
 static void printDirectory(const char * filename) {
-  unsigned int len;
+  unsigned long long len;
   struct ECRS_MetaData * md;
   char * data;
   int ret;
   char * name;
+  int fd;
 
   name = expandFileName(filename);
   printf(_("==> Directory '%s':\n"),
         name);
-  len = getFileSize(name);
-  if (len <= 0) {
+  if ( (OK != getFileSize(name,
+                         &len)) ||
+       (len == 0) ) {
     printf(_("=\tError reading directory.\n"));
     return;
   }
-  /* directories could be > 40 MB, but we should still support loading
-     them in this tool.  Thus override memory bound.  Note that we
-     might want to use mmap here at some point to avoid this
-     problem... */
-  data = xmalloc_unchecked_(len, __FILE__, __LINE__);
-  if (len != readFile(name, len, data)) {
-    BREAK();
-    FREE(data);
-    FREE(name);
-    return;
-  }
+#ifdef O_LARGEFILE
+  fd = fileopen(name,
+               O_LARGEFILE | O_RDONLY);
+#else
+  fd = fileopen(name,
+               O_RDONLY);
+#endif
+  data = MMAP(NULL,
+             len,
+             PROT_READ,
+             MAP_SHARED,
+             fd,
+             0);
   ret = ECRS_listDirectory(data,
                           len,
                           &md,
                           &printNode,
                           NULL);
+  MUNMAP(data, len);
+  closefile(fd);
   if (ret == -1)
     printf(_("File format error (not a GNUnet directory?)\n"));
   else

Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/identity/identity.c 2005-06-28 13:34:52 UTC (rev 
1108)
@@ -198,8 +198,9 @@
   hosts_[count_].strict   = NO;
   hash2enc(&identity->hashPubKey,
           &fil);
-  fn = MALLOC(strlen((char*)trustDirectory)+sizeof(EncName)+1);
-  buildFileName(trustDirectory, &fil, fn);
+  fn = MALLOC(strlen(trustDirectory)+sizeof(EncName)+1);
+  strcpy(fn, trustDirectory);
+  strcat(fn, (char*) &fil);
   if (sizeof(unsigned int) ==
       readFile(fn,
               sizeof(unsigned int),
@@ -266,9 +267,9 @@
 }
 
 
-static void cronHelper(const char * filename,
-                      const char * dirname,
-                      void * unused) {
+static int cronHelper(const char * filename,
+                     const char * dirname,
+                     void * unused) {
   PeerIdentity identity;
   EncName id;
   unsigned int protoNumber;
@@ -284,7 +285,7 @@
                       &identity.hashPubKey)) {
       addHostToKnown(&identity,
                     (unsigned short) protoNumber);
-      return;
+      return OK;
     }
   }
 
@@ -297,8 +298,11 @@
        filename,
        networkIdDirectory);
   else
-    LOG_FILE_STRERROR(LOG_ERROR, "unlink", fullname);
+    LOG_FILE_STRERROR(LOG_ERROR,
+                     "unlink",
+                     fullname);
   FREE(fullname);
+  return OK;
 }
 
 /**
@@ -419,9 +423,11 @@
  * Check if the filename matches the identity that we are searching
  * for. If yes, fill it in.
  */
-static void identity2HeloHelper(const char * fn,
-                               const char * dirName,
-                               struct TempStorage_ * res) {
+static int identity2HeloHelper(const char * fn,
+                              const char * dirName,
+                              void * ptr) {
+  struct TempStorage_ * res = ptr;
+
   if (strstr(fn, (char*)&res->enc) != NULL) {
     char * fileName;
     HELO_Message buffer;
@@ -476,6 +482,7 @@
     }
     FREE(fileName);
   }
+  return OK;
 }
 
 /**
@@ -568,7 +575,7 @@
       protocol);
 #endif
   scanDirectory(networkIdDirectory,
-               (DirectoryEntryCallback)&identity2HeloHelper,
+               &identity2HeloHelper,
                &tempStorage);
   *result = tempStorage.helo;
   return tempStorage.result;
@@ -721,8 +728,11 @@
                       HostIterator callback,
                       void * data) {
   int i;
-  int count = 0;
+  int count;
+  PeerIdentity hi;
+  unsigned short proto;
 
+  count = 0;
   MUTEX_LOCK(&lock_);
   for (i=0;i<count_;i++) {
     if (hostIdentityEquals(&hosts_[i].identity,
@@ -732,9 +742,6 @@
         (now >= hosts_[i].until) ) {
       count++;
       if (callback != NULL) {
-       PeerIdentity hi;
-       unsigned short proto;
-
        hi = hosts_[i].identity;
        proto = hosts_[i].protocol;
        MUTEX_UNLOCK(&lock_);
@@ -746,7 +753,21 @@
       }
     }
   }
-  /* FIXME: also iterate over temporary list */
+  for (i=0;i<MAX_TEMP_HOSTS;i++) {
+    if (tempHosts[i] == NULL)
+      continue;
+    count++;
+    if (callback != NULL) {
+      hi = tempHosts[i]->senderIdentity;
+      proto = tempHosts[i]->protocol;
+      MUTEX_UNLOCK(&lock_);
+      callback(&hi,
+              proto,
+              YES,
+              data);
+      MUTEX_LOCK(&lock_);
+    }      
+  }
   MUTEX_UNLOCK(&lock_);
   return count;
 }
@@ -765,10 +786,9 @@
   host->trust = host->trust & TRUST_ACTUAL_MASK;
   hash2enc(&host->identity.hashPubKey,
           &fil);
-  fn = MALLOC(strlen((char*)trustDirectory)+sizeof(EncName)+1);
-  buildFileName(trustDirectory,
-               &fil,
-               fn);
+  fn = MALLOC(strlen(trustDirectory)+sizeof(EncName)+1);
+  strcpy(fn, trustDirectory);
+  strcat(fn, (char*) &fil);
   if (host->trust == 0) {
     if (0 != UNLINK(fn)) {
       if (errno != ENOENT)

Modified: GNUnet/src/applications/session/connect.c
===================================================================
--- GNUnet/src/applications/session/connect.c   2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/session/connect.c   2005-06-28 13:34:52 UTC (rev 
1108)
@@ -632,9 +632,9 @@
  */
 static int acceptSessionKeyUpdate(const PeerIdentity * sender,
                                  const p2p_HEADER * msg) {
-  LOG(LOG_WARNING,
-      "rekeying not implemented\n");
-  /* FIXME: verify skey, notify core about new key */
+  acceptSessionKey(sender,
+                  msg,
+                  NULL);
   return OK;
 }
 

Modified: GNUnet/src/applications/stats/clientapi.c
===================================================================
--- GNUnet/src/applications/stats/clientapi.c   2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/stats/clientapi.c   2005-06-28 13:34:52 UTC (rev 
1108)
@@ -213,6 +213,7 @@
                              void * cls) {
   STATS_CS_GET_MESSAGE_SUPPORTED csStatMsg;
   unsigned short i;
+  unsigned short j;
   int supported;
   int ret;
 
@@ -221,18 +222,23 @@
     = htons(sizeof(STATS_CS_GET_MESSAGE_SUPPORTED));
   csStatMsg.header.type
     = htons(STATS_CS_PROTO_GET_P2P_MESSAGE_SUPPORTED);
-  for (i=0;i<65535;i++) {
-    csStatMsg.type = htons(i);
-    if (SYSERR == writeToSocket(sock,
-                               &csStatMsg.header))
-      return SYSERR;
-    if (SYSERR == readTCPResult(sock,
-                               &supported))
-      return SYSERR;
-    if (supported == YES) {
-      ret = processor(i, YES, cls);
-      if (ret != OK)
-       break;
+  for (j=2;j<4;j++) {
+    csStatMsg.handlerType = htons(j);
+    for (i=0;i<65535;i++) {
+      csStatMsg.type = htons(i);
+      if (SYSERR == writeToSocket(sock,
+                                 &csStatMsg.header))
+       return SYSERR;
+      if (SYSERR == readTCPResult(sock,
+                                 &supported))
+       return SYSERR;
+      if (supported == YES) {  
+       ret = processor(i, 
+                       (j == 2) ? YES : NO,
+                       cls);
+       if (ret != OK)
+         break;
+      }
     }
   }
   csStatMsg.header.type

Modified: GNUnet/src/applications/stats/statistics.c
===================================================================
--- GNUnet/src/applications/stats/statistics.c  2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/stats/statistics.c  2005-06-28 13:34:52 UTC (rev 
1108)
@@ -292,6 +292,7 @@
 static int handlep2pMessageSupported(ClientHandle sock,
                                     const CS_HEADER * message) {
   unsigned short type;
+  unsigned short htype;
   int supported;
   STATS_CS_GET_MESSAGE_SUPPORTED * cmsg;
 
@@ -301,8 +302,8 @@
   }
   cmsg = (STATS_CS_GET_MESSAGE_SUPPORTED *) message;
   type = ntohs(cmsg->type);
-  // FIXME: supported = coreAPI->isHandlerRegistered(type);
-  supported = NO;
+  htype = ntohs(cmsg->handlerType);
+  supported = coreAPI->isHandlerRegistered(type, htype);
   return coreAPI->sendValueToClient(sock, supported);
 }
 

Modified: GNUnet/src/applications/stats/statistics.h
===================================================================
--- GNUnet/src/applications/stats/statistics.h  2005-06-27 22:08:16 UTC (rev 
1107)
+++ GNUnet/src/applications/stats/statistics.h  2005-06-28 13:34:52 UTC (rev 
1108)
@@ -78,9 +78,12 @@
   unsigned short type;
 
   /**
-   * For 64-bit alignment...
+   * 0 for plaintext P2P,
+   * 1 for ciphertext P2P,
+   * 2 for either plaintext or ciphertext P2P,
+   * 3 for client-server
    */
-  unsigned short reserved;
+  unsigned short handlerType;
 
 } STATS_CS_GET_MESSAGE_SUPPORTED;
 

Modified: GNUnet/src/applications/topology_default/topology.c
===================================================================
--- GNUnet/src/applications/topology_default/topology.c 2005-06-27 22:08:16 UTC 
(rev 1107)
+++ GNUnet/src/applications/topology_default/topology.c 2005-06-28 13:34:52 UTC 
(rev 1108)
@@ -121,7 +121,7 @@
  * @param im structure responsible for the selection process
  */
 static void scanHelperSelect(const PeerIdentity * id,
-                            const unsigned short proto,
+                            unsigned short proto,
                             int confirmed,
                             IndexMatch * im) {
   if (hostIdentityEquals(coreAPI->myIdentity, id))

Modified: GNUnet/src/applications/topology_f2f/topology.c
===================================================================
--- GNUnet/src/applications/topology_f2f/topology.c     2005-06-27 22:08:16 UTC 
(rev 1107)
+++ GNUnet/src/applications/topology_f2f/topology.c     2005-06-28 13:34:52 UTC 
(rev 1108)
@@ -286,7 +286,7 @@
   char * tmp;
   char * fn;
   char * data;
-  size_t size;
+  unsigned long long size;
   size_t pos;
   EncName enc;
   HashCode512 hc;
@@ -309,7 +309,11 @@
     FREE(fn);
     return SYSERR;
   }
-  size = getFileSize(fn);
+  if (OK != getFileSize(fn,
+                       &size)) {
+    FREE(fn);
+    return SYSERR;
+  }
   data = MALLOC(size);
   if (size != readFile(fn, size, data)) {
     LOG(LOG_ERROR,

Modified: GNUnet/src/include/gnunet_core.h
===================================================================
--- GNUnet/src/include/gnunet_core.h    2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/include/gnunet_core.h    2005-06-28 13:34:52 UTC (rev 1108)
@@ -402,10 +402,24 @@
    * @return OK on success, SYSERR if there is a different
    *         handler for that type
    */
-  int (*unregisterHandler)(const unsigned short type,
+  int (*unregisterHandler)(unsigned short type,
                           MessagePartHandler callback);
 
   /**
+   * Is a handler registered for messages of the given type?
+   * @param type the message type
+   * @param handlerType 0 for plaintext P2P,
+   *                    1 for ciphertext P2P,
+   *                    2 for either plaintext or ciphertext P2P,
+   *                    3 for client-server
+   *        NO for ciphertext handlers, SYSERR for either
+   * @return number of handlers registered, 0 for none,
+   *        SYSERR for invalid value of handlerType
+   */
+  int (*isHandlerRegistered)(unsigned short type,
+                            unsigned short handlerType);
+
+  /**
    * Register a method as a handler for specific message
    * types. Only for encrypted messages!
    * @param type the message type
@@ -414,7 +428,7 @@
    * @return OK on success, SYSERR if there is already a
    *         handler for that type
    */
-  int (*registerPlaintextHandler)(const unsigned short type,
+  int (*registerPlaintextHandler)(unsigned short type,
                                  PlaintextMessagePartHandler callback);
 
   /**
@@ -427,7 +441,7 @@
    * @return OK on success, SYSERR if there is a different
    *         handler for that type
    */
-  int (*unregisterPlaintextHandler)(const unsigned short type,
+  int (*unregisterPlaintextHandler)(unsigned short type,
                                    PlaintextMessagePartHandler callback);
 
   /* ***************** traffic management ******************* */

Modified: GNUnet/src/include/gnunet_identity_service.h
===================================================================
--- GNUnet/src/include/gnunet_identity_service.h        2005-06-27 22:08:16 UTC 
(rev 1107)
+++ GNUnet/src/include/gnunet_identity_service.h        2005-06-28 13:34:52 UTC 
(rev 1108)
@@ -124,7 +124,7 @@
    * @return the number of known hosts matching
    */
   int (*forEachHost)(cron_t now,
-                    HostIterator callback,             
+                    HostIterator callback,
                     void * data);
 
   /**

Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h    2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/include/gnunet_util.h    2005-06-28 13:34:52 UTC (rev 1108)
@@ -485,9 +485,14 @@
  */
 typedef int (*CommandLineParser)(int argc, char * argv[]);
 
-typedef void (*DirectoryEntryCallback)(const char * filename,
-                                      const char * dirName,
-                                      void * data);
+/**
+ * Function called on each file in a directory.
+ * @return OK to continue to iterate,
+ *  SYSERR to abort iteration with error!
+ */
+typedef int (*DirectoryEntryCallback)(const char * filename,
+                                     const char * dirName,
+                                     void * data);
 
 /**
  * @brief description of a command line option (helptext)
@@ -1841,14 +1846,20 @@
 /**
  * Get the size of the file (or directory)
  * of the given file (in bytes).
+ *
+ * @return OK on success, SYSERR on error
  */
-unsigned long long getFileSize(const char * filename);
+int getFileSize(const char * filename,
+               unsigned long long * size);
 
 /**
  * Get the size of the file (or directory) without
  * counting symlinks.
+ *
+ * @return OK on success, SYSERR on error
  */
-unsigned long long getFileSizeWithoutSymlinks(const char * filename);
+int getFileSizeWithoutSymlinks(const char * filename,
+                              unsigned long long * size);
 
 /**
  * Get the number of blocks that are left on the partition that
@@ -1901,11 +1912,12 @@
  * @param buffer the data to write
  * @param n number of bytes to write
  * @param mode the mode for file permissions
+ * @return OK on success, SYSERR on error
  */
-void writeFile(const char * fileName,
-              const void * buffer,
-              unsigned int n,
-              const char * mode);
+int writeFile(const char * fileName,
+             const void * buffer,
+             unsigned int n,
+             const char * mode);
 
 /**
  * Copy a file.
@@ -1915,17 +1927,6 @@
             const char * dst);
 
 /**
- * Build a filename from directory and filename, completing like the shell does
- * @param dir the name of the directory, may contain ~/ or other shell stuff. 
Will
- *        NOT be freed!
- * @param fil the name of the file, will NOT be deallocated anymore!
- * @param result where to store the full file name (must be large enough!)
- */
-void buildFileName(const char * dir,
-                  const EncName * fil,
-                  char * result);
-
-/**
  * Scan a directory for files. The name of the directory
  * must be expanded first (!).
  * @param dirName the name of the directory

Modified: GNUnet/src/server/connection.c
===================================================================
--- GNUnet/src/server/connection.c      2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/server/connection.c      2005-06-28 13:34:52 UTC (rev 1108)
@@ -2103,6 +2103,7 @@
   be = lookForHost(peer);
   if (be != NULL) {
     cronTime(&be->isAlive);
+    identity->whitelistHost(peer);
     if ( ( (be->status & STAT_SKEY_SENT) > 0) &&
         ( (be->status & STAT_SKEY_RECEIVED) > 0) ) {
       if (be->session.tsession == NULL) {

Modified: GNUnet/src/server/core.c
===================================================================
--- GNUnet/src/server/core.c    2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/server/core.c    2005-06-28 13:34:52 UTC (rev 1108)
@@ -89,6 +89,7 @@
 static int loadApplicationModule(const char * rpos) {
   int ok;
   ShutdownList * nxt;
+  ShutdownList * spos;
   ApplicationInitMethod mptr;
   void * library;
   char * name;
@@ -161,9 +162,37 @@
   shutdownList = nxt;
   ok = mptr(&applicationCore);
   if (OK != ok) {
+    /* undo loading */
+    LOG(LOG_MESSAGE,
+       _("Failed to load plugin '%s' at %s:%d.  Unloading plugin.\n"),
+       name, __FILE__, __LINE__);
+    /* Note: we cannot assert that shutdownList == nxt here,
+       so we have to traverse the list again! */
     nxt->applicationInitialized = NO;
-    /* FIXME: undo loading? */
-    /* Note: we cannot assert that shutdownList == nxt here! */
+    if (shutdownList == nxt) {
+      spos = NULL;
+    } else {
+      spos = shutdownList;
+      while (spos->next != nxt) {
+       spos = spos->next;
+       if (spos == NULL) {
+         BREAK(); /* should never happen! */
+         return ok;
+       }
+      }
+    }
+    if (spos == NULL)
+      shutdownList = nxt->next;
+    else
+      spos->next = nxt->next;
+#if DEBUG_CORE
+    LOG(LOG_DEBUG,
+       "Unloading library '%s' at %s:%d.\n",
+       name, __FILE__, __LINE__);
+#endif
+    unloadDynamicLibrary(library);
+    FREE(name);
+    FREE(nxt);   
   }
   return ok;
 }
@@ -513,6 +542,7 @@
   applicationCore.unregisterHandler = &unregisterp2pHandler; /* handler.c*/
   applicationCore.registerPlaintextHandler = &registerPlaintextHandler; /* 
handler.c */
   applicationCore.unregisterPlaintextHandler = &unregisterPlaintextHandler; /* 
handler.c*/
+  applicationCore.isHandlerRegistered = &isHandlerRegistered; /* handler.c*/
 
   applicationCore.offerTSessionFor = &considerTakeover; /* connection.c */
   applicationCore.assignSessionKey = &assignSessionKey; /* connection.c */

Modified: GNUnet/src/server/handler.c
===================================================================
--- GNUnet/src/server/handler.c 2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/server/handler.c 2005-06-28 13:34:52 UTC (rev 1108)
@@ -111,7 +111,7 @@
  * @return OK on success, SYSERR if core threads are running
  *        and updates to the handler list are illegal!
  */
-int registerp2pHandler(const unsigned short type,
+int registerp2pHandler(unsigned short type,
                       MessagePartHandler callback) {
   int last;
 
@@ -154,7 +154,7 @@
  *        handler for that type or if core threads are running
  *        and updates to the handler list are illegal!
  */
-int unregisterp2pHandler(const unsigned short type,
+int unregisterp2pHandler(unsigned short type,
                         MessagePartHandler callback) {
   int pos;
   int last;
@@ -202,7 +202,7 @@
  * @return OK on success, SYSERR if core threads are running
  *        and updates to the handler list are illegal!
  */
-int registerPlaintextHandler(const unsigned short type,
+int registerPlaintextHandler(unsigned short type,
                             PlaintextMessagePartHandler callback) {
   int last;
 
@@ -245,7 +245,7 @@
  *        handler for that type or if core threads are running
  *        and updates to the handler list are illegal!
  */
-int unregisterPlaintextHandler(const unsigned short type,
+int unregisterPlaintextHandler(unsigned short type,
                               PlaintextMessagePartHandler callback) {
   int pos;
   int last;
@@ -281,7 +281,53 @@
 }
 
 
+
 /**
+ * Unregister a method as a handler for specific message types. Only
+ * for plaintext messages!
+ *
+ * @param type the message type
+ * @param callback the method to call if a message of
+ *        that type is received
+ * @return OK on success, SYSERR if there is a different
+ *        handler for that type or if core threads are running
+ *        and updates to the handler list are illegal!
+ */
+int isHandlerRegistered(unsigned short type,
+                       unsigned short handlerType) {
+  int pos;
+  int ret;
+  
+  if (handlerType == 3)
+    return isCSHandlerRegistered(type);
+  if (handlerType > 3) {
+    BREAK();
+    return SYSERR;
+  }
+  ret = 0;
+  MUTEX_LOCK(&handlerLock);    
+  if (type < plaintextmax_registeredType) {
+    pos = 0;
+    while (plaintextHandlers[type][pos] != NULL)
+      pos++;
+    if ( (handlerType == 0) ||
+        (handlerType == 2) )
+      ret += pos;
+  }
+  if (type < max_registeredType) {
+    pos = 0;
+    while (handlers[type][pos] != NULL) 
+      pos++;
+    if ( (handlerType == 1) ||
+        (handlerType == 2) )
+      ret += pos;
+  }
+  MUTEX_UNLOCK(&handlerLock);
+  return ret;
+}
+
+
+/**
  * Handle a message (that was decrypted if needed).
  * Processes the message by calling the registered
  * handler for each message part.
@@ -400,7 +446,7 @@
 static void handleMessage(TSession * tsession,
                          const PeerIdentity * sender,
                          const char * msg,
-                         const unsigned int size) {
+                         unsigned int size) {
   int ret;
 
   if (YES == identity->isBlacklistedStrict(sender) ) {

Modified: GNUnet/src/server/handler.h
===================================================================
--- GNUnet/src/server/handler.h 2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/server/handler.h 2005-06-28 13:34:52 UTC (rev 1108)
@@ -129,6 +129,20 @@
 int unregisterPlaintextHandler(const unsigned short type,
                               PlaintextMessagePartHandler callback);
 
+/**
+ * Is a handler registered for messages of the given type?
+ * @param type the message type
+ * @param handlerType 0 for plaintext P2P,
+ *                    1 for ciphertext P2P,
+ *                    2 for either plaintext or ciphertext P2P,
+ *                    3 for client-server
+ *        NO for ciphertext handlers, SYSERR for either
+ * @return number of handlers registered, 0 for none,
+ *        SYSERR for invalid value of handlerType
+ */
+int isHandlerRegistered(unsigned short type,
+                       unsigned short handlerType);
 
+
 #endif
 /* end of handler.h */

Modified: GNUnet/src/server/tcpserver.c
===================================================================
--- GNUnet/src/server/tcpserver.c       2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/server/tcpserver.c       2005-06-28 13:34:52 UTC (rev 1108)
@@ -792,7 +792,7 @@
  * @return OK on success, SYSERR if there is already a
  *         handler for that type
  */
-int registerCSHandler(const unsigned short type,
+int registerCSHandler(unsigned short type,
                      CSHandler callback) {
   MUTEX_LOCK(&handlerlock);
   if (type < max_registeredType) {
@@ -825,7 +825,7 @@
  * @return OK on success, SYSERR if there is no or another
  *         handler for that type
  */
-int unregisterCSHandler(const unsigned short type,
+int unregisterCSHandler(unsigned short type,
                        CSHandler callback) {
   MUTEX_LOCK(&handlerlock);
   if (type < max_registeredType) {
@@ -864,7 +864,24 @@
   return sendToClient(sock,
                      &rv.header);
 }
-                               
+                       
+/**
+ * Check if a handler is registered for a given
+ * message type.
+ *
+ * @param type the message type
+ * @return number of registered handlers (0 or 1)
+ */
+unsigned int isCSHandlerRegistered(unsigned short type) {
+  MUTEX_LOCK(&handlerlock);
+  if (type < max_registeredType) {
+    if (handlers[type] != NULL) {
+      MUTEX_UNLOCK(&handlerlock);
+      return 1;
+    }
+  }
+  MUTEX_UNLOCK(&handlerlock);
+  return 0;
+}
 
-
 /* end of tcpserver.c */

Modified: GNUnet/src/server/tcpserver.h
===================================================================
--- GNUnet/src/server/tcpserver.h       2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/server/tcpserver.h       2005-06-28 13:34:52 UTC (rev 1108)
@@ -56,7 +56,7 @@
  * @return OK on success, SYSERR if there is already a
  *         handler for that type
  */
-int registerCSHandler(const unsigned short type,
+int registerCSHandler(unsigned short type,
                      CSHandler callback);
 
 /**
@@ -70,7 +70,7 @@
  * @return OK on success, SYSERR if there is no or another
  *         handler for that type
  */
-int unregisterCSHandler(const unsigned short type,
+int unregisterCSHandler(unsigned short type,
                        CSHandler callback);
 
 int registerClientExitHandler(ClientExitHandler callback);
@@ -102,5 +102,14 @@
 
 void terminateClientConnection(ClientHandle sock);
 
+/**
+ * Check if a handler is registered for a given
+ * message type.
+ *
+ * @param type the message type
+ * @return number of registered handlers (0 or 1)
+ */
+unsigned int isCSHandlerRegistered(unsigned short type);
+
 #endif
 /* end of tcpserver.h */

Modified: GNUnet/src/util/hashing.c
===================================================================
--- GNUnet/src/util/hashing.c   2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/util/hashing.c   2005-06-28 13:34:52 UTC (rev 1108)
@@ -328,11 +328,14 @@
   int fh;
   struct sha512_ctx ctx;
 
+  if (OK != getFileSize(filename, 
+                       &len))
+    return SYSERR;
   fh = fileopen(filename,
 #ifdef O_LARGEFILE
-           O_RDONLY | O_LARGEFILE
+               O_RDONLY | O_LARGEFILE
 #else
-           O_RDONLY
+               O_RDONLY
 #endif
            );
   if (fh == -1) {
@@ -342,7 +345,6 @@
   sha512_init(&ctx);
   pos = 0;
   buf = MALLOC(65536);
-  len = getFileSize(filename);
   while (pos < len) {
     delta = 65536;
     if (len - pos < delta)
@@ -573,15 +575,17 @@
  */
 int hashCodeCompare(const HashCode512 * h1,
                    const HashCode512 * h2) {
+  unsigned int * i1;
+  unsigned int * i2;
   int i;
-  int diff;
-  /* FIXME: we can do this much more efficiently... */
-  for (i = sizeof(HashCode512)*8 - 1; i >= 0; --i) {
-    diff = getHashCodeBit(h2, i) - getHashCodeBit(h1, i);
-    if (diff < 0)
+
+  i1 = (unsigned int*) h1;
+  i2 = (unsigned int*) h2;
+  for (i=(sizeof(HashCode512) / sizeof(unsigned int))-1;i>=0;i--) {
+    if (i1[i] > i2[i])
+      return 1;
+    if (i1[i] < i2[i])
       return -1;
-    else if (diff > 0)
-      return 1;
   }
   return 0;
 }

Modified: GNUnet/src/util/logging.c
===================================================================
--- GNUnet/src/util/logging.c   2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/util/logging.c   2005-06-28 13:34:52 UTC (rev 1108)
@@ -111,9 +111,10 @@
 /**
  * Remove file if it is an old log
  */
-static void removeOldLog(const char * fil,
-       const char * dir,
-       struct logfiledef * def) {
+static int removeOldLog(const char * fil,
+                       const char * dir,
+                       void * ptr) {
+  struct logfiledef * def = ptr;
   struct tm t;
   char * fullname;
   const char * logdate;
@@ -128,7 +129,7 @@
        fullname,
        strlen(def->basename))) {
     FREE(fullname);
-    return;
+    return OK;
   }
   logdate = &fullname[strlen(def->basename)];
   ret = strptime(logdate,
@@ -137,7 +138,7 @@
   if ( (ret == NULL) ||
        (ret[0] != '\0') ) {
     FREE(fullname);
-    return; /* not a logfile */
+    return OK; /* not a logfile */
   }
 
   if (t.tm_year*365 + t.tm_yday + keepLog
@@ -145,6 +146,7 @@
     UNLINK(fullname);
 
   FREE(fullname);
+  return OK;
 }
 
 /**
@@ -209,8 +211,8 @@
         end--;
       *end = 0;
       scanDirectory(logdir,
-        (DirectoryEntryCallback) removeOldLog,
-        &def);
+                   &removeOldLog,
+                   &def);
       FREE(def.basename);
       FREE(logdir);
     }

Modified: GNUnet/src/util/semaphore.c
===================================================================
--- GNUnet/src/util/semaphore.c 2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/util/semaphore.c 2005-06-28 13:34:52 UTC (rev 1108)
@@ -69,7 +69,7 @@
   int internal; /* KLB_FIX */
   char * filename;
 #else
-  /* FIXME! */
+  /* PORT-ME! */
 #endif
 } IPC_Semaphore_Internal;
 
@@ -450,7 +450,7 @@
 #if LINUX
   /* IPC semaphore kludging for linux */
 
-  /* FIXME: ugly. why don't we start at count 0 and increment when opening? */
+  /* Why don't we start at count 0 and increment when opening? */
   #define PROCCOUNT 10000
 
   /**

Modified: GNUnet/src/util/semaphoretest.c
===================================================================
--- GNUnet/src/util/semaphoretest.c     2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/util/semaphoretest.c     2005-06-28 13:34:52 UTC (rev 1108)
@@ -7,7 +7,7 @@
 #include "platform.h"
 
 #include <sys/types.h>
-#ifndef MINGW             /* FIXME MINGW */
+#ifndef MINGW             /* PORT-ME MINGW */
 
 
 static Mutex lock;
@@ -320,7 +320,7 @@
   }
   return OK;
 }
-#endif /* FIXME MINGW */
+#endif /* PORT-ME MINGW */
 
 int main(int argc, char * argv[]){
   int ret = 0;

Modified: GNUnet/src/util/state.c
===================================================================
--- GNUnet/src/util/state.c     2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/util/state.c     2005-06-28 13:34:52 UTC (rev 1108)
@@ -117,7 +117,7 @@
   int fd;
   int size;
   char * fil;
-  size_t fsize;
+  unsigned long long fsize;
   size_t n;
 
   GNUNET_ASSERT(handle != NULL);
@@ -130,6 +130,11 @@
           "%s/%s",
           dbh,
           name);
+  if (OK != getFileSize(fil,
+                       &fsize)) {
+    FREE(fil);
+    return -1;
+  }
   fd = fileopen(fil,
            O_RDONLY,
            S_IRUSR);
@@ -137,7 +142,6 @@
     FREE(fil);
     return -1;
   }
-  fsize = getFileSize(fil);
   FREE(fil);
   if (fsize == 0) { /* also invalid! */
     closefile(fd);

Modified: GNUnet/src/util/statuscalls.c
===================================================================
--- GNUnet/src/util/statuscalls.c       2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/util/statuscalls.c       2005-06-28 13:34:52 UTC (rev 1108)
@@ -977,7 +977,7 @@
         dDiffIdle = dIdle - dLastIdle;
         dDiffUser = dUser - dLastUser;
 
-        /* FIXME MINGW: Multi-processor? */
+        /* PORT-ME MINGW: Multi-processor? */
         lastcpuresult = 100.0 - (dDiffIdle / (dDiffKernel + dDiffUser)) * 
100.0;
       }
       else

Modified: GNUnet/src/util/statuscallstest.c
===================================================================
--- GNUnet/src/util/statuscallstest.c   2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/util/statuscallstest.c   2005-06-28 13:34:52 UTC (rev 1108)
@@ -6,7 +6,7 @@
 #include "gnunet_util.h"
 #include "platform.h"
 
-/* FIXME: avoid making these non-static altogether! */
+/* OPTIMIZE-ME: avoid making these non-static altogether! */
 
 
 /**

Modified: GNUnet/src/util/storage.c
===================================================================
--- GNUnet/src/util/storage.c   2005-06-27 22:08:16 UTC (rev 1107)
+++ GNUnet/src/util/storage.c   2005-06-28 13:34:52 UTC (rev 1108)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002 Christian Grothoff (and other contributing authors)
+     (C) 2001, 2002, 2005 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
@@ -47,7 +47,7 @@
 #define                _IFLNK          0120000 /* symbolic link */
 #define        S_ISLNK(m)      (((m)&_IFMT) == _IFLNK)
 #else
-#error FIXME: need to port statfs (how much space is left on the drive?)
+#error PORT-ME: need to port statfs (how much space is left on the drive?)
 #endif
 #endif
 #endif
@@ -63,15 +63,15 @@
 #endif
 
 
-/* FIXME: Currently this function does not return errors */
-static void getSizeRec(const char * filename,
-                      const char * dirname,
-                      unsigned long long * size) {
+static int getSizeRec(const char * filename,
+                     const char * dirname,
+                     void * ptr) {
+  unsigned long long * size = ptr;
   struct stat buf;
   char * fn;
 
   if (filename == NULL)
-    return;
+    return SYSERR;
   if (dirname != NULL) {
     fn = MALLOC(strlen(filename) + strlen(dirname) + 2);
     fn[0] = '\0';
@@ -95,27 +95,32 @@
   if (0 != STAT(fn, &buf)) {
     LOG_FILE_STRERROR(LOG_EVERYTHING, "stat", fn);
     FREE(fn);
-    return;
+    return SYSERR;
   }
   *size += buf.st_size;
   if ( (S_ISDIR(buf.st_mode)) &&
        (!S_ISLNK(buf.st_mode)) ) {
-    scanDirectory(fn,
-                 (DirectoryEntryCallback)&getSizeRec,
-                 size);
+    if (SYSERR ==
+       scanDirectory(fn,
+                     &getSizeRec,
+                     size)) {
+      FREE(fn);
+      return SYSERR;
+    }
   }
   FREE(fn);
+  return OK;
 }
 
-/* FIXME: Currently this function does not return errors */
-static void getSizeWithoutSymlinksRec(const char * filename,
-                                     const char * dirname,
-                                     unsigned long long * size) {
+static int getSizeWithoutSymlinksRec(const char * filename,
+                                    const char * dirname,
+                                    void * ptr) {
+  unsigned long long * size = ptr;
   struct stat buf;
   char * fn;
 
   if (filename == NULL)
-    return;
+    return SYSERR;
   if (dirname != NULL) {
     fn = MALLOC(strlen(filename) + strlen(dirname) + 2);
     fn[0] = '\0';
@@ -137,19 +142,26 @@
     fn = STRDUP(filename);
 
   if (0 != STAT(fn, &buf)) {
-    LOG_FILE_STRERROR(LOG_EVERYTHING, "stat", fn);
+    LOG_FILE_STRERROR(LOG_EVERYTHING, 
+                     "stat", 
+                     fn);
     FREE(fn);
-    return;
+    return SYSERR;
   }
   if (! S_ISLNK(buf.st_mode))
     *size += buf.st_size;
   if ( (S_ISDIR(buf.st_mode)) &&
        (!S_ISLNK(buf.st_mode)) ) {
-    scanDirectory(fn,
-                 (DirectoryEntryCallback)&getSizeRec,
-                 size);
+    if (SYSERR ==
+       scanDirectory(fn,
+                     &getSizeWithoutSymlinksRec,
+                     size)) {
+      FREE(fn);
+      return SYSERR;
+    }
   }
   FREE(fn);
+  return OK;
 }
 
 /**
@@ -202,27 +214,28 @@
 /**
  * Get the size of the file (or directory)
  * of the given file (in bytes).
- * FIXME: Currently this function does not return errors
+ *
+ * @return SYSERR on error, OK on success
  */
-unsigned long long getFileSize(const char * filename) {
-  unsigned long long size;
-
-  size = 0;
-  getSizeRec(filename, "", &size);
-  return size;
+int getFileSize(const char * filename,
+               unsigned long long * size) {
+  GNUNET_ASSERT(size != NULL);
+  *size = 0;
+  return getSizeRec(filename, "", size);
 }
 
 /**
  * Get the size of the file (or directory) without
  * counting symlinks.
- * FIXME: Currently this function does not return errors
+ *
+ * @return SYSERR on error, OK on success
  */
-unsigned long long getFileSizeWithoutSymlinks(const char * filename) {
-  unsigned long long size;
+int getFileSizeWithoutSymlinks(const char * filename,
+                              unsigned long long * size) {
+  GNUNET_ASSERT(size != NULL);
+  *size = 0;
 
-  size = 0;
-  getSizeWithoutSymlinksRec(filename, "", &size);
-  return size;
+  return getSizeWithoutSymlinksRec(filename, "", size);
 }
 
 
@@ -467,52 +480,49 @@
  * @param buffer the data to write
  * @param n number of bytes to write
  * @param mode permissions to set on the file
+ * @return OK on success, SYSERR on error
  */
-void writeFile(const char * fileName,
-              const void * buffer,
-              unsigned int n,
-              const char *mode) {
+int writeFile(const char * fileName,
+             const void * buffer,
+             unsigned int n,
+             const char *mode) {
   int handle;
   /* open file, open with 600, create if not
      present, otherwise overwrite */
-  if ((fileName == NULL) || (buffer == NULL))
-    return;
+  if ( (fileName == NULL) ||
+       (buffer == NULL) )
+    return SYSERR;
   handle = fileopen(fileName,
-               O_CREAT|O_WRONLY,S_IRUSR|S_IWUSR);
+                   O_CREAT | O_WRONLY,
+                   S_IRUSR | S_IWUSR);
   if (handle == -1) {
-    LOG_FILE_STRERROR(LOG_WARNING, "open", fileName);
-    return;
+    LOG_FILE_STRERROR(LOG_WARNING,
+                     "open", 
+                     fileName);
+    return SYSERR;
   }
   /* write the buffer take length from the beginning */
-  if (n != WRITE(handle, buffer, n))
-    LOG_FILE_STRERROR(LOG_WARNING, "write", fileName);
-  CHMOD(fileName, atoo(mode));
+  if (n != WRITE(handle, buffer, n)) {
+    LOG_FILE_STRERROR(LOG_WARNING, 
+                     "write", 
+                     fileName);
+    closefile(handle);
+    return SYSERR;
+  }
+  CHMOD(fileName, 
+       atoo(mode));
   closefile(handle);
+  return OK;
 }
 
 /**
- * Build a filename from directory and filename, completing like the shell does
- * @param dir the name of the directory, may contain ~/ or other shell stuff. 
Will
- *        NOT be freed!
- * @param fil the name of the file, will NOT be deallocated anymore!
- * @param result where to store the full file name (must be large enough!)
- */
-void buildFileName(const char * dir,
-                  const EncName * fil,
-                  char * result) {
-  GNUNET_ASSERT((dir != NULL) && (fil != NULL) && (result != NULL));
-  strcpy(result, dir);
-  strcat(result, (char*)fil);
-}
-
-/**
  * Scan a directory for files. The name of the directory
  * must be expanded first (!).
  * @param dirName the name of the directory
  * @param callback the method to call for each file,
  *        can be NULL, in that case, we only count
  * @param data argument to pass to callback
- * @return the number of files found, -1 on error
+ * @return the number of files found, SYSERR on error
  */
 int scanDirectory(const char * dirName,
                  DirectoryEntryCallback callback,
@@ -523,31 +533,39 @@
   int count = 0;
 
   if (dirName == NULL)
-    return -1;
+    return SYSERR;
   if (0 != STAT(dirName, &istat)) {
-    LOG_FILE_STRERROR(LOG_WARNING, "stat", dirName);
-    return -1;
+    LOG_FILE_STRERROR(LOG_WARNING, 
+                     "stat", 
+                     dirName);
+    return SYSERR;
   }
   if (!S_ISDIR(istat.st_mode)) {
     LOG(LOG_ERROR,
        _("'%s' expected '%s' to be a directory!\n"),
        __FUNCTION__,
        dirName);
-    return -1;
+    return SYSERR;
   }
   errno = 0;
   dinfo = OPENDIR(dirName);
   if ((errno == EACCES) || (dinfo == NULL)) {
-    LOG_FILE_STRERROR(LOG_WARNING, "opendir", dirName);
-    return -1;
+    LOG_FILE_STRERROR(LOG_WARNING, 
+                     "opendir", 
+                     dirName);
+    return SYSERR;
   }
   while ((finfo = readdir(dinfo)) != NULL) {
     if (finfo->d_name[0] == '.')
       continue;
-    if (callback != NULL)
-      callback(finfo->d_name,
-              dirName,
-              data);
+    if (callback != NULL) {
+      if (OK != callback(finfo->d_name,
+                        dirName,
+                        data)) {
+       closedir(dinfo);
+       return SYSERR;
+      }
+    }  
     count++;
   }
   closedir(dinfo);
@@ -557,18 +575,25 @@
 /**
  * Callback for rm_minus_rf.
  */
-static void rmHelper(const char * fil,
-                    const char * dir,
-                    int * ok) {
+static int rmHelper(const char * fil,
+                   const char * dir,
+                   void * unused) {
   char * fn;
   size_t n;
 
   n = strlen(dir) + strlen(fil) + 2;
   fn = MALLOC(n);
-  SNPRINTF(fn, n, "%s/%s", dir, fil);
-  if (SYSERR == rm_minus_rf(fn))
-    *ok = SYSERR;
+  SNPRINTF(fn, 
+          n, 
+          "%s/%s",
+          dir, 
+          fil);
+  if (SYSERR == rm_minus_rf(fn)) {
+    FREE(fn);
+    return SYSERR;
+  }
   FREE(fn);
+  return OK;
 }
 
 /**
@@ -587,20 +612,22 @@
          sticky /tmp directory may result in EPERM on BSD.
          So we also explicitly check "isDirectory" */
        (YES == isDirectory(fileName)) ) {
-    int ok;
-
-    ok = OK;
-    scanDirectory(fileName,
-                 (DirectoryEntryCallback)&rmHelper,
-                 &ok);
-    if (ok == OK)
+    if (OK == scanDirectory(fileName,
+                           &rmHelper,
+                           NULL)) {
       if (0 != RMDIR(fileName)) {
-       LOG_FILE_STRERROR(LOG_WARNING, "rmdir", fileName);
-       ok = SYSERR;
+       LOG_FILE_STRERROR(LOG_WARNING,
+                         "rmdir",
+                         fileName);
+       return SYSERR;
       }
-    return ok;
+      return OK;
+    }
+    return SYSERR;
   } else {
-    LOG_FILE_STRERROR(LOG_WARNING, "unlink", fileName);
+    LOG_FILE_STRERROR(LOG_WARNING, 
+                     "unlink", 
+                     fileName);
     return SYSERR;
   }
 }
@@ -608,13 +635,13 @@
 void close_(int fd,
            const char * filename,
            int linenumber) {
-    if (0 != CLOSE(fd)) {
-       LOG(LOG_INFO,
-           _("'%s' failed at %s:%d with error: %s\n"),
-           "close",
-           filename,
-           linenumber, STRERROR(errno));
-      }
+  if (0 != CLOSE(fd)) {
+    LOG(LOG_INFO,
+       _("'%s' failed at %s:%d with error: %s\n"),
+       "close",
+       filename,
+       linenumber, STRERROR(errno));
+  }
 }
 
 #define COPY_BLK_SIZE 65536
@@ -636,21 +663,26 @@
   pos = 0;
   in = fileopen(src, O_RDONLY
 #ifdef O_LARGEFILE
-            | O_LARGEFILE
+               | O_LARGEFILE
 #endif
-           );
+               );
   if (in == -1)
     return SYSERR;
-  out = fileopen(dst, O_WRONLY | O_CREAT | O_EXCL
+  out = fileopen(dst, 
 #ifdef O_LARGEFILE
-            | O_LARGEFILE
+                O_LARGEFILE |
 #endif
-            , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+                O_WRONLY | O_CREAT | O_EXCL,
+                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
   if (out == -1) {
     closefile(in);
     return SYSERR;
   }
-  size = getFileSize(src);
+  if (OK != getFileSize(src,
+                       &size)) {
+    closefile(in);
+    return SYSERR;
+  }
   while (pos < size) {
     len = COPY_BLK_SIZE;
     if (len > size - pos)





reply via email to

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