gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3584 - GNUnet/src/applications/fs/fsui


From: grothoff
Subject: [GNUnet-SVN] r3584 - GNUnet/src/applications/fs/fsui
Date: Tue, 31 Oct 2006 19:32:34 -0800 (PST)

Author: grothoff
Date: 2006-10-31 19:32:33 -0800 (Tue, 31 Oct 2006)
New Revision: 3584

Modified:
   GNUnet/src/applications/fs/fsui/deserialize.c
   GNUnet/src/applications/fs/fsui/serialize.c
Log:
serializing upload metadata and keywords

Modified: GNUnet/src/applications/fs/fsui/deserialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/deserialize.c       2006-11-01 03:17:05 UTC 
(rev 3583)
+++ GNUnet/src/applications/fs/fsui/deserialize.c       2006-11-01 03:32:33 UTC 
(rev 3584)
@@ -131,18 +131,20 @@
  *
  * @return OK on success, SYSERR on error
  */
-static int readFileInfo(struct GE_Context * ectx,
-                       int fd,
-                       ECRS_FileInfo * fi) {
+static struct ECRS_MetaData * 
+read_meta(struct GE_Context * ectx,
+         int fd) {
   unsigned int size;
   char * buf;
+  struct ECRS_MetaData * meta;
 
-  fi->meta = NULL;
-  fi->uri = NULL;
-  READINT(size);
+  if (read_int(fd, &size) != OK) {
+    GE_BREAK(ectx, 0);
+    return NULL;    
+  }
   if (size > 1024 * 1024) {
     GE_BREAK(ectx, 0);
-    return SYSERR;
+    return NULL;
   }
   buf = MALLOC(size);
   if (size != READ(fd,
@@ -150,18 +152,35 @@
                   size)) {
     FREE(buf);
     GE_BREAK(ectx, 0);
-    return SYSERR;
+    return NULL;
   }
-  fi->meta = ECRS_deserializeMetaData(ectx,
-                                     buf,
-                                     size);
-  if (fi->meta == NULL) {
+  meta = ECRS_deserializeMetaData(ectx,
+                                 buf,
+                                 size);
+  if (meta == NULL) {
     FREE(buf);
     GE_BREAK(ectx, 0);
-    return SYSERR;
+    return NULL;
   }
   FREE(buf);
+  return meta;
+}
 
+/**
+ * Read file info from file.
+ *
+ * @return OK on success, SYSERR on error
+ */
+static int readFileInfo(struct GE_Context * ectx,
+                       int fd,
+                       ECRS_FileInfo * fi) {
+  fi->meta = read_meta(ectx, fd);
+  if (fi->meta == NULL) {
+    GE_BREAK(ectx, 0);
+    return SYSERR;
+  }
+  fi->uri = NULL;
+
   fi->uri
     = read_uri(ectx, fd);
   if (fi->uri == NULL) {
@@ -529,7 +548,7 @@
     READINT(big);
     if (big == 0)
       return OK;
-    if ( (big != 1) && (big != 2) ) {
+    if ( (big < 1) || (big > 15) ) {
       GE_BREAK(NULL, 0);
       return SYSERR;
     }
@@ -554,12 +573,36 @@
     if (l.start_time != 0)
       l.start_time = (get_time() - stime) + l.start_time;
     l.uri = NULL;
-    if (big == 1)
+    if ( (big & 2) == 2)
       READURI(l.uri);
+    if ( (big & 4) == 4) {
+      l.keywords = read_uri(ctx->ectx, fd);
+      if (l.keywords == NULL) {
+       if (l.uri != NULL) 
+         ECRS_freeUri(l.uri);
+       GE_BREAK(NULL, 0);
+       break;
+      }
+    }
+    if ( (big & 8) == 8) {
+      l.meta = read_meta(ctx->ectx, fd);
+      if (l.meta == NULL) {
+       if (l.uri != NULL) 
+         ECRS_freeUri(l.uri);
+       if (l.keywords != NULL) 
+         ECRS_freeUri(l.keywords);
+       GE_BREAK(NULL, 0);
+       break;
+      }
+    }     
     l.filename = read_string(fd, 1024*1024);
     if (l.filename == NULL) {
       if (l.uri != NULL)
        ECRS_freeUri(l.uri);
+      if (l.meta != NULL)
+       ECRS_freeMetaData(l.meta);
+      if (l.keywords != NULL)
+       ECRS_freeUri(l.keywords);
       GE_BREAK(NULL, 0);
       break;
     }

Modified: GNUnet/src/applications/fs/fsui/serialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serialize.c 2006-11-01 03:17:05 UTC (rev 
3583)
+++ GNUnet/src/applications/fs/fsui/serialize.c 2006-11-01 03:32:33 UTC (rev 
3584)
@@ -69,20 +69,19 @@
        strlen(name));
 }
 
-
-static void writeFileInfo(struct GE_Context * ectx,
+static void writeMetaData(struct GE_Context * ectx,
                          int fd,
-                         const ECRS_FileInfo * fi) {
+                         const struct ECRS_MetaData * meta) {
   unsigned int size;
   char * buf;
 
-  size = ECRS_sizeofMetaData(fi->meta,
+  size = ECRS_sizeofMetaData(meta,
                             ECRS_SERIALIZE_FULL | ECRS_SERIALIZE_NO_COMPRESS);
   if (size > 1024 * 1024)
     size = 1024 * 1024;
   buf = MALLOC(size);
   ECRS_serializeMetaData(ectx,
-                        fi->meta,
+                        meta,
                         buf,
                         size,
                         ECRS_SERIALIZE_PART | ECRS_SERIALIZE_NO_COMPRESS);
@@ -91,6 +90,13 @@
        buf,
        size);
   FREE(buf);
+}
+
+
+static void writeFileInfo(struct GE_Context * ectx,
+                         int fd,
+                         const ECRS_FileInfo * fi) {
+  writeMetaData(ectx, fd, fi->meta);
   writeURI(fd, fi->uri);
 }
 
@@ -244,8 +250,17 @@
                            struct FSUI_Context * ctx,
                            struct FSUI_UploadList * upos,
                            int top) {
+  int bits;
+
   while (upos != NULL) {
-    WRITEINT(fd, (upos->uri != NULL) ? 1 : 2);    
+    bits = 1;
+    if (upos->uri != NULL)
+      bits |= 2;
+    if (upos->keywords != NULL)
+      bits |= 4;
+    if (upos->meta != NULL)
+      bits |= 8;
+    WRITEINT(fd, bits);
     WRITEINT(fd, 0x34D1F023);
     WRITEINT(fd, upos->state);
     WRITELONG(fd, upos->completed);
@@ -254,6 +269,10 @@
     WRITELONG(fd, upos->start_time);
     if (upos->uri != NULL)
       writeURI(fd, upos->uri);
+    if (upos->keywords != NULL)
+      writeURI(fd, upos->keywords);
+    if (upos->meta != NULL)
+      writeMetaData(ctx->ectx, fd, upos->meta);
     WRITESTRING(fd, upos->filename);
     writeUploadList(fd, ctx, upos->child, NO);
     if (top == YES)





reply via email to

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