]> mj.ucw.cz Git - libucw.git/commitdiff
- obj_parse_dump() generalized to store apart the header and the body, and
authorRobert Spalek <robert@ucw.cz>
Sun, 4 Jul 2004 11:29:17 +0000 (11:29 +0000)
committerRobert Spalek <robert@ucw.cz>
Sun, 4 Jul 2004 11:29:17 +0000 (11:29 +0000)
  renamed to buck2obj_parse()
- added new obj_parse_dump() with the same interface as before; it is a
  wrapper of buck2obj_parse()

lib/buck2obj.c
lib/buck2obj.h

index b87326bba3f18653eb2b45cf41a9d6c365309a9b..b19963f7803284acdbaed5c5f53ef9d8d7db9bfa 100644 (file)
@@ -19,7 +19,7 @@
 #include <errno.h>
 #include <unistd.h>
 
-#define        RET_ERR(num)    ({ errno = num; return NULL; })
+#define        RET_ERR(num)    ({ errno = num; return -1; })
 
 #define        GBUF_TYPE       byte
 #define        GBUF_PREFIX(x)  bb_##x
@@ -84,24 +84,26 @@ decode_attributes(byte *ptr, byte *end, struct odes *o, uns can_overwrite)
   return ptr;
 }
 
-struct odes *
-obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, uns buck_len, struct fastbuf *body, uns *body_start)
+int
+buck2obj_parse(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fastbuf *body, struct odes *o_hdr, uns *body_start, struct odes *o_body)
 {
-  struct odes *o = obj_new(pool);
-
-  if (buck_type == BUCKET_TYPE_PLAIN || buck_type == BUCKET_TYPE_V30)
+  if (buck_type == BUCKET_TYPE_PLAIN)
+  {
+    if (body_start)
+      *body_start = 0;
+    obj_read_multi(body, o_hdr);       // ignore empty lines, read until EOF or NUL
+  }
+  else if (buck_type == BUCKET_TYPE_V30)
   {
-    if (!body_start)                   // header + body: ignore empty lines, read until EOF or NUL
+    sh_off_t start = btell(body);
+    obj_read(body, o_hdr);             // end on EOF or the first empty line
+    if (body_start)
+      *body_start = btell(body) - start;
+    else
     {
-      obj_read_multi(body, o);
+      obj_read(body, o_body);
       bgetc(body);
     }
-    else                               // header only: end on EOF or the first empty line
-    {
-      sh_off_t start = btell(body);
-      obj_read(body, o);
-      *body_start = btell(body) - start;
-    }
   }
   else if (buck_type == BUCKET_TYPE_V33 || buck_type == BUCKET_TYPE_V33_LIZARD)
   {
@@ -122,13 +124,13 @@ obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, u
     end = ptr + len;
 
     byte *start = ptr;
-    ptr = decode_attributes(ptr, end, o, 0);           // header
+    ptr = decode_attributes(ptr, end, o_hdr, 0);               // header
     if (body_start)
     {
       *body_start = ptr - start;
       if (!copied)
        bdirect_read_commit(body, ptr);
-      return o;
+      return 0;
     }
     if (buck_type == BUCKET_TYPE_V33_LIZARD)           // decompression
     {
@@ -138,14 +140,14 @@ obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, u
       ptr += 4;
       byte *new_ptr = lizard_decompress_safe(ptr, buf->lizard, len);
       if (!new_ptr)
-       return NULL;
+       return -1;
       if (!copied)
        bdirect_read_commit(body, end);
       ptr = new_ptr;
       end = ptr + len;
       copied = 1;
     }
-    ptr = decode_attributes(ptr, end, o, 2);           // body
+    ptr = decode_attributes(ptr, end, o_body, 2);      // body
     if (ptr != end)
       RET_ERR(EINVAL);
     if (!copied)
@@ -153,5 +155,15 @@ obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, u
   }
   else
     RET_ERR(EINVAL);
-  return o;
+  return 0;
+}
+
+struct odes *
+obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, uns buck_len, struct fastbuf *body, uns *body_start)
+{
+  struct odes *o = obj_new(pool);
+  if (buck2obj_parse(buf, buck_type, buck_len, body, o, body_start, o) < 0)
+    return NULL;
+  else
+    return o;
 }
index 4a12ea61a219e058c894a2a89c0636f604022d27..6e11c3a84be97fbc8dc84258e6e96b58cfa71cf2 100644 (file)
@@ -6,9 +6,12 @@
 
 struct buck2obj_buf;
 struct mempool;
+struct odes;
 
 struct buck2obj_buf *buck2obj_alloc(void);
 void buck2obj_free(struct buck2obj_buf *buf);
+
+int buck2obj_parse(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fastbuf *body, struct odes *o_hdr, uns *body_start, struct odes *o_body);
 struct odes *obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, uns buck_len, struct fastbuf *body, uns *body_start);
   /* If body_start != NULL, then only the header is parsed and *body_start is
    * set to the position of the body. This function does a plenty of optimizations