From c3e813db9bc5afffa8a573f060fd177bf2e18e26 Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Thu, 24 Jun 2004 15:21:38 +0000 Subject: [PATCH] added a decoder from buckets to objects just a proposed version for now (it even is not in the Makefile) --- lib/buck2obj.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/buck2obj.h | 7 +++++ 2 files changed, 92 insertions(+) create mode 100644 lib/buck2obj.c create mode 100644 lib/buck2obj.h diff --git a/lib/buck2obj.c b/lib/buck2obj.c new file mode 100644 index 00000000..235c17db --- /dev/null +++ b/lib/buck2obj.c @@ -0,0 +1,85 @@ +/* + * Bucket -> Object converter + * + * (c) 2004, Robert Spalek + */ + +#include "lib/lib.h" +#include "lib/fastbuf.h" +#include "charset/unicode.h" +#include "lib/object.h" +#include "lib/bucket.h" +#include "lib/lizard.h" +#include "lib/buck2obj.h" + +#include + +static inline byte * +decode_attributes(byte *start, byte *end, struct odes *o) +{ + byte *p = start; + while (p < end) + { + uns len; + GET_UTF8(p, len); + if (!len) + break; + byte type = p[len]; + p[len] = 0; + obj_add_attr(o, type, p); + } + return p; +} + +int +extract_odes(struct obuck_header *hdr, struct fastbuf *body, struct odes *o, byte *buf, uns buf_len, struct lizard_buffer *lizard_buf) +{ + if (hdr->type < BUCKET_TYPE_V30C) + { + oa_allocate = 1; + obj_read_multi(body, o); + } + else + { + oa_allocate = 0; + /* Read all the bucket into 1 buffer, 0-copy if possible. */ + byte *start, *end; + uns len = bdirect_read_prepare(body, &start); + if (len < hdr->length) + { + if (hdr->length > buf_len) + { + errno = EFBIG; + return -1; + } + len = bread(body, buf, hdr->length); + start = buf; + } + end = start + len; + + /* Decode the header, 0-copy. */ + byte *p = decode_attributes(start, end, o); + + /* Decompress the body. */ + GET_UTF8(p, len); + int res = lizard_decompress_safe(p, lizard_buf, len); + if (res < 0) + return res; + if (res != (int) len) + { + errno = EINVAL; + return -1; + } + + /* Decode the body, 0-copy. */ + start = lizard_buf->ptr; + end = start + len; + p = decode_attributes(start, end, o); + if (p != end) + { + errno = EINVAL; + return -1; + } + } + return 0; +} diff --git a/lib/buck2obj.h b/lib/buck2obj.h new file mode 100644 index 00000000..9e272079 --- /dev/null +++ b/lib/buck2obj.h @@ -0,0 +1,7 @@ +/* + * Bucket -> Object converter + * + * (c) 2004, Robert Spalek + */ + +int extract_odes(struct obuck_header *hdr, struct fastbuf *body, struct odes *o, byte *buf, uns buf_len, struct lizard_buffer *lizard_buf); -- 2.39.2