gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3549 - in GNUnet/src: applications/fs/fsui applications/fs


From: grothoff
Subject: [GNUnet-SVN] r3549 - in GNUnet/src: applications/fs/fsui applications/fs/tools include
Date: Tue, 24 Oct 2006 15:57:41 -0700 (PDT)

Author: grothoff
Date: 2006-10-24 15:57:29 -0700 (Tue, 24 Oct 2006)
New Revision: 3549

Modified:
   GNUnet/src/applications/fs/fsui/deserialize.c
   GNUnet/src/applications/fs/fsui/download.c
   GNUnet/src/applications/fs/fsui/fsui.c
   GNUnet/src/applications/fs/fsui/fsui.h
   GNUnet/src/applications/fs/fsui/serialize.c
   GNUnet/src/applications/fs/tools/gnunet-download.c
   GNUnet/src/include/gnunet_fsui_lib.h
Log:
keep metadata with download -- for mimetype

Modified: GNUnet/src/applications/fs/fsui/deserialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/deserialize.c       2006-10-24 21:56:49 UTC 
(rev 3548)
+++ GNUnet/src/applications/fs/fsui/deserialize.c       2006-10-24 22:57:29 UTC 
(rev 3549)
@@ -124,7 +124,55 @@
   }
 }
 
+
 /**
+ * Read file info from file.
+ *
+ * @return OK on success, SYSERR on error
+ */
+static int readFileInfo(struct GE_Context * ectx,
+                       int fd,
+                       ECRS_FileInfo * fi) {
+  unsigned int size;
+  char * buf;
+
+  fi->meta = NULL;
+  fi->uri = NULL;
+  READINT(size);
+  if (size > 1024 * 1024) {
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
+  buf = MALLOC(size);
+  if (size != READ(fd,
+                  buf,
+                  size)) {
+    FREE(buf);
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
+  fi->meta = ECRS_deserializeMetaData(ectx,
+                                     buf,
+                                     size);
+  if (fi->meta == NULL) {
+    FREE(buf);
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
+  FREE(buf);
+
+  fi->uri
+    = read_uri(ectx, fd);
+  if (fi->uri == NULL) {
+    ECRS_freeMetaData(fi->meta);
+    fi->meta = NULL;
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
+  return OK;
+}
+
+/**
  * (Recursively) read a download list from the given fd.  The returned
  * pointer is expected to be integrated into the tree either as a next
  * or child pointer such that the given parent becomes the parent of the
@@ -173,7 +221,9 @@
     FREE(ret);
     return NULL;
   }
-  if (NULL == (ret->uri = read_uri(ectx, fd))) {
+  if (OK != readFileInfo(ectx,
+                        fd,
+                        &ret->fi)) {
     FREE(ret->filename);
     FREE(ret);
     return NULL;
@@ -190,7 +240,8 @@
   }
   if (NO == ok) {
     FREE(ret->filename);
-    ECRS_freeUri(ret->uri);
+    ECRS_freeUri(ret->fi.uri);
+    ECRS_freeMetaData(ret->fi.meta);
     for (i=0;i<ret->completedDownloadsCount;i++) {
       if (ret->completedDownloads[i] != NULL)
        ECRS_freeUri(ret->completedDownloads[i]);
@@ -219,54 +270,6 @@
   return ret;
 }
 
-
-/**
- * Read file info from file.
- *
- * @return OK on success, SYSERR on error
- */
-static int readFileInfo(struct GE_Context * ectx,
-                       int fd,
-                       ECRS_FileInfo * fi) {
-  unsigned int size;
-  char * buf;
-
-  fi->meta = NULL;
-  fi->uri = NULL;
-  READINT(size);
-  if (size > 1024 * 1024) {
-    GE_BREAK(ectx, 0);
-    return SYSERR;
-  }
-  buf = MALLOC(size);
-  if (size != READ(fd,
-                  buf,
-                  size)) {
-    FREE(buf);
-    GE_BREAK(ectx, 0);
-    return SYSERR;
-  }
-  fi->meta = ECRS_deserializeMetaData(ectx,
-                                     buf,
-                                     size);
-  if (fi->meta == NULL) {
-    FREE(buf);
-    GE_BREAK(ectx, 0);
-    return SYSERR;
-  }
-  FREE(buf);
-
-  fi->uri
-    = read_uri(ectx, fd);
-  if (fi->uri == NULL) {
-    ECRS_freeMetaData(fi->meta);
-    fi->meta = NULL;
-    GE_BREAK(ectx, 0);
-    return SYSERR;
-  }
-  return OK;
-}
-
 static int checkMagic(int fd) {
   char magic[8];
 
@@ -351,14 +354,14 @@
     list->start_time += get_time() - stime;
     buf = read_string(fd, 1024 * 1024);
     if (buf == NULL) {
-      GE_BREAK(NULL, 0);       
-      break;
+       GE_BREAK(NULL, 0);
+       break;
     }
     list->uri
       = ECRS_stringToUri(NULL, buf);
     FREE(buf);
     if (list->uri == NULL) {
-      GE_BREAK(NULL, 0);       
+      GE_BREAK(NULL, 0);
       break;
     }
     if (! ECRS_isKeywordUri(list->uri)) {

Modified: GNUnet/src/applications/fs/fsui/download.c
===================================================================
--- GNUnet/src/applications/fs/fsui/download.c  2006-10-24 21:56:49 UTC (rev 
3548)
+++ GNUnet/src/applications/fs/fsui/download.c  2006-10-24 22:57:29 UTC (rev 
3549)
@@ -41,6 +41,7 @@
              unsigned int anonymityLevel,
              int is_recursive,
              const struct ECRS_URI * uri,
+             const struct ECRS_MetaData * meta,
              const char * filename,
              FSUI_DownloadList * parent);
 
@@ -69,7 +70,7 @@
       return OK; /* already complete! */
   pos = parent->child;
   while (pos != NULL) {
-    if (ECRS_equalsUri(pos->uri,
+    if (ECRS_equalsUri(pos->fi.uri,
                       fi->uri))
       return OK; /* already downloading */
     pos = pos->next;
@@ -111,6 +112,7 @@
                parent->anonymityLevel,
                YES,
                fi->uri,
+               fi->meta,
                fullName,
                parent);
   FREE(fullName);
@@ -158,7 +160,7 @@
   }
   event.data.DownloadProgress.eta = eta;
   event.data.DownloadProgress.filename = dl->filename;
-  event.data.DownloadProgress.uri = dl->uri;
+  event.data.DownloadProgress.uri = dl->fi.uri;
   event.data.DownloadProgress.last_block = lastBlock;
   event.data.DownloadProgress.last_size = lastBlockSize;
   dl->ctx->ecb(dl->ctx->ecbClosure,
@@ -223,7 +225,7 @@
   GE_ASSERT(ectx, dl->filename != NULL);
   ret = ECRS_downloadFile(dl->ctx->ectx,
                          dl->ctx->cfg,
-                         dl->uri,
+                         dl->fi.uri,
                          dl->filename,
                          dl->anonymityLevel,
                          &downloadProgressCallback,
@@ -239,7 +241,7 @@
     event.data.DownloadCompleted.dc.pcctx = dl->parent->cctx;
     event.data.DownloadCompleted.total = dl->total;
     event.data.DownloadCompleted.filename = dl->filename;
-    event.data.DownloadCompleted.uri = dl->uri;
+    event.data.DownloadCompleted.uri = dl->fi.uri;
     dl->ctx->ecb(dl->ctx->ecbClosure,
                 &event);
   } else if (dl->state == FSUI_ACTIVE) {
@@ -276,7 +278,7 @@
     size_t totalBytes;
     struct ECRS_MetaData * md;
 
-    totalBytes = ECRS_fileSize(dl->uri);
+    totalBytes = ECRS_fileSize(dl->fi.uri);
     fn = MALLOC(strlen(dl->filename) + 3 + strlen(GNUNET_DIRECTORY_EXT));
     strcpy(fn, dl->filename);
     if (fn[strlen(fn)-1] == '/') {
@@ -340,6 +342,7 @@
              unsigned int anonymityLevel,
              int is_recursive,
              const struct ECRS_URI * uri,
+             const struct ECRS_MetaData * meta,
              const char * filename,
              FSUI_DownloadList * parent) {
   FSUI_DownloadList * dl;
@@ -365,7 +368,8 @@
   dl->anonymityLevel = anonymityLevel;
   dl->ctx = ctx;
   dl->filename = STRDUP(filename);
-  dl->uri = ECRS_dupUri(uri);
+  dl->fi.uri = ECRS_dupUri(uri);
+  dl->fi.meta = ECRS_dupMetaData(meta);
   dl->total = ECRS_fileSize(uri);
   dl->child = NULL;
   dl->cctx = NULL;
@@ -375,9 +379,10 @@
   event.data.DownloadStarted.dc.cctx = NULL;
   event.data.DownloadStarted.dc.ppos = dl->parent;
   event.data.DownloadStarted.dc.pcctx = dl->parent->cctx;
-  event.data.DownloadStarted.total = ECRS_fileSize(dl->uri);
+  event.data.DownloadStarted.total = ECRS_fileSize(dl->fi.uri);
   event.data.DownloadStarted.filename = dl->filename;
-  event.data.DownloadStarted.uri = dl->uri;
+  event.data.DownloadStarted.uri = dl->fi.uri;
+  event.data.DownloadStarted.meta = dl->fi.meta;
   event.data.DownloadStarted.anonymityLevel = dl->anonymityLevel;
   dl->cctx = dl->ctx->ecb(dl->ctx->ecbClosure,
                          &event);
@@ -398,6 +403,7 @@
                   unsigned int anonymityLevel,                 
                   int doRecursive,
                   const struct ECRS_URI * uri,
+                  const struct ECRS_MetaData * meta,
                   const char * filename) {
   struct FSUI_DownloadList * ret;
 
@@ -406,6 +412,7 @@
                      anonymityLevel,
                      doRecursive,
                      uri,
+                     meta,
                      filename,
                      &ctx->activeDownloads);
   MUTEX_UNLOCK(ctx->lock);
@@ -591,7 +598,8 @@
   GROW(dl->completedDownloads,
        dl->completedDownloadsCount,
        0);
-  ECRS_freeUri(dl->uri);
+  ECRS_freeUri(dl->fi.uri);
+  ECRS_freeMetaData(dl->fi.meta);
   FREE(dl->filename);
   FREE(dl);
   return OK;

Modified: GNUnet/src/applications/fs/fsui/fsui.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.c      2006-10-24 21:56:49 UTC (rev 
3548)
+++ GNUnet/src/applications/fs/fsui/fsui.c      2006-10-24 22:57:29 UTC (rev 
3549)
@@ -86,7 +86,7 @@
       }
       event.data.DownloadResumed.eta = eta;
       event.data.DownloadResumed.filename = ret->filename;
-      event.data.DownloadResumed.uri = ret->uri;
+      event.data.DownloadResumed.uri = ret->fi.uri;
       event.data.DownloadResumed.anonymityLevel = ret->anonymityLevel;
       ret->cctx = ctx->ecb(ctx->ecbClosure, &event);
       if (ret->child != NULL)
@@ -371,7 +371,8 @@
 
   while (list != NULL) {
     freeDownloadList(list->child);
-    ECRS_freeUri(list->uri);
+    ECRS_freeUri(list->fi.uri);
+    ECRS_freeMetaData(list->fi.meta);
     FREE(list->filename);
     for (i=0;i<list->completedDownloadsCount;i++)
       ECRS_freeUri(list->completedDownloads[i]);

Modified: GNUnet/src/applications/fs/fsui/fsui.h
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.h      2006-10-24 21:56:49 UTC (rev 
3548)
+++ GNUnet/src/applications/fs/fsui/fsui.h      2006-10-24 22:57:29 UTC (rev 
3549)
@@ -206,7 +206,7 @@
   /**
    * URI for this download.
    */
-  struct ECRS_URI * uri;
+  ECRS_FileInfo fi;
 
   /**
    * Filename for this download.

Modified: GNUnet/src/applications/fs/fsui/serialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serialize.c 2006-10-24 21:56:49 UTC (rev 
3548)
+++ GNUnet/src/applications/fs/fsui/serialize.c 2006-10-24 22:57:29 UTC (rev 
3549)
@@ -69,6 +69,32 @@
        strlen(name));
 }
 
+
+static void writeFileInfo(struct GE_Context * ectx,
+                         int fd,
+                         const ECRS_FileInfo * fi) {
+  unsigned int size;
+  char * buf;
+
+  size = ECRS_sizeofMetaData(fi->meta,
+                            ECRS_SERIALIZE_FULL | ECRS_SERIALIZE_NO_COMPRESS);
+  if (size > 1024 * 1024)
+    size = 1024 * 1024;
+  buf = MALLOC(size);
+  ECRS_serializeMetaData(ectx,
+                        fi->meta,
+                        buf,
+                        size,
+                        ECRS_SERIALIZE_PART | ECRS_SERIALIZE_NO_COMPRESS);
+  WRITEINT(fd, size);
+  WRITE(fd,
+       buf,
+       size);
+  FREE(buf);
+  writeURI(fd, fi->uri);
+}
+
+
 /**
  * (recursively) write a download list.
  */
@@ -100,7 +126,9 @@
   WRITELONG(fd, list->completed);
   WRITELONG(fd, get_time() - list->startTime);
   WRITESTRING(fd, list->filename);
-  writeURI(fd, list->uri);
+  writeFileInfo(ectx,
+               fd, 
+               &list->fi);
   for (i=0;i<list->completedDownloadsCount;i++)
     writeURI(fd, list->completedDownloads[i]);
   writeDownloadList(ectx,
@@ -113,31 +141,6 @@
                    list->child);
 }
 
-
-static void writeFileInfo(struct GE_Context * ectx,
-                         int fd,
-                         const ECRS_FileInfo * fi) {
-  unsigned int size;
-  char * buf;
-
-  size = ECRS_sizeofMetaData(fi->meta,
-                            ECRS_SERIALIZE_FULL | ECRS_SERIALIZE_NO_COMPRESS);
-  if (size > 1024 * 1024)
-    size = 1024 * 1024;
-  buf = MALLOC(size);
-  ECRS_serializeMetaData(ectx,
-                        fi->meta,
-                        buf,
-                        size,
-                        ECRS_SERIALIZE_PART | ECRS_SERIALIZE_NO_COMPRESS);
-  WRITEINT(fd, size);
-  WRITE(fd,
-       buf,
-       size);
-  FREE(buf);
-  writeURI(fd, fi->uri);
-}
-
 static void writeCollection(int fd,
                            struct FSUI_Context * ctx) {
   if ( (ctx->collectionData == NULL) ||
@@ -153,7 +156,6 @@
 
 static void writeSearches(int fd,
                          struct FSUI_Context * ctx) {
-  char * tmp;
   FSUI_SearchList * spos;
   int i;
 
@@ -176,10 +178,7 @@
     WRITEINT(fd, spos->anonymityLevel);
     WRITEINT(fd, spos->sizeResultsReceived);
     WRITEINT(fd, spos->sizeUnmatchedResultsReceived);
-    tmp = ECRS_uriToString(spos->uri);
-    GE_ASSERT(NULL, tmp != NULL);
-    WRITESTRING(fd, tmp);
-    FREE(tmp);
+    writeURI(fd, spos->uri);
     for (i=0;i<spos->sizeResultsReceived;i++)
       writeFileInfo(ctx->ectx,
                    fd,

Modified: GNUnet/src/applications/fs/tools/gnunet-download.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-download.c  2006-10-24 21:56:49 UTC 
(rev 3548)
+++ GNUnet/src/applications/fs/tools/gnunet-download.c  2006-10-24 22:57:29 UTC 
(rev 3549)
@@ -140,6 +140,7 @@
   int try_rename;
   struct FSUI_Context * ctx;
   struct ECRS_URI * uri;
+  struct ECRS_MetaData * meta;
   int i;
 
   i = GNUNET_init(argc,
@@ -206,11 +207,14 @@
                   NULL);
   start_time = get_time();
   errorCode = 1;
+  meta = ECRS_createMetaData();
   dl = FSUI_startDownload(ctx,
                          anonymity,
                          do_recursive,
                          uri,
+                         meta,
                          filename);
+  ECRS_freeMetaData(meta);
   if (dl == NULL) {
     FSUI_stop(ctx);
     goto quit;

Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h        2006-10-24 21:56:49 UTC (rev 
3548)
+++ GNUnet/src/include/gnunet_fsui_lib.h        2006-10-24 22:57:29 UTC (rev 
3549)
@@ -428,6 +428,11 @@
        */
       const struct ECRS_URI * uri;
 
+      /**
+       * Metadata about the download.
+       */
+      const struct ECRS_MetaData * meta;
+
       unsigned int anonymityLevel;
 
     } DownloadStarted;
@@ -458,6 +463,11 @@
       const char * filename;
 
       /**
+       * Metadata about the download.
+       */
+      const struct ECRS_MetaData * meta;
+
+      /**
        * Original URI.
        */
       const struct ECRS_URI * uri;
@@ -780,6 +790,7 @@
                   unsigned int anonymityLevel,
                   int doRecursive,
                   const struct ECRS_URI * uri,
+                  const struct ECRS_MetaData * meta,
                   const char * filename); /* download.c */
 
 /**





reply via email to

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