2 * Generating Buckets from Objects
4 * (c) 2004, Robert Spalek <robert@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "lib/fastbuf.h"
12 #include "lib/ff-utf8.h"
13 #include "lib/bucket.h"
14 #include "lib/object.h"
23 put_attr_set_type(uns type)
27 case BUCKET_TYPE_PLAIN:
36 case BUCKET_TYPE_V33_LIZARD:
41 die("Don't know how to generate buckets of type %08x", type);
48 ASSERT(len <= MAX_ATTR_SIZE);
52 return len + utf8_space(len);
59 put_attr(byte *ptr, uns type, byte *val, uns len)
63 PUT_UTF8_32(ptr, len+1);
64 memcpy(ptr, val, len);
71 memcpy(ptr, val, len);
79 put_attr_str(byte *ptr, uns type, byte *val)
81 return put_attr(ptr, type, val, strlen(val));
85 put_attr_vformat(byte *ptr, uns type, byte *mask, va_list va)
89 uns len = vsprintf(ptr+1, mask, va);
92 byte tmp[6], *tmp_end = tmp;
93 PUT_UTF8_32(tmp_end, len+1);
94 uns l = tmp_end - tmp;
95 memmove(ptr+l, ptr+1, len);
109 ptr += vsprintf(ptr, mask, va);
116 put_attr_format(byte *ptr, uns type, char *mask, ...)
120 byte *ret = put_attr_vformat(ptr, type, mask, va);
126 put_attr_num(byte *ptr, uns type, uns val)
130 uns len = sprintf(ptr+1, "%d", val) + 1;
136 ptr += sprintf(ptr, "%c%d\n", type, val);
141 put_attr_separator(byte *ptr)
149 bput_attr(struct fastbuf *b, uns type, byte *val, uns len)
153 bput_utf8_32(b, len+1);
166 bput_attr_str(struct fastbuf *b, uns type, byte *val)
168 bput_attr(b, type, val, strlen(val));
172 bput_attr_vformat(struct fastbuf *b, uns type, byte *mask, va_list va)
176 int len = vsnprintf(NULL, 0, mask, va);
178 die("vsnprintf() does not support size=0");
179 bput_utf8_32(b, len+1);
180 vbprintf(b, mask, va);
186 vbprintf(b, mask, va);
192 bput_attr_format(struct fastbuf *b, uns type, char *mask, ...)
196 bput_attr_vformat(b, type, mask, va);
201 bput_attr_num(struct fastbuf *b, uns type, uns val)
206 uns len = sprintf(tmp, "%d", val);
212 bprintf(b, "%c%d\n", type, val);
216 bput_attr_separator(struct fastbuf *b)
223 obj_write(struct fastbuf *f, struct odes *d)
225 for(struct oattr *a=d->attrs; a; a=a->next)
226 for(struct oattr *b=a; b; b=b->same)
229 for (z = b->val; *z; z++)
230 if (*z < ' ' && *z != '\t')
232 log(L_ERROR, "obj_dump: Found non-ASCII character %02x (URL might be %s) in %c%s", *z, obj_find_aval(d, 'U'), a->attr, b->val);
235 ASSERT(z - b->val <= MAX_ATTR_SIZE-2);
236 bput_attr_str(f, a->attr, b->val);
241 obj_write_nocheck(struct fastbuf *f, struct odes *d)
243 for(struct oattr *a=d->attrs; a; a=a->next)
244 for(struct oattr *b=a; b; b=b->same)
245 bput_attr_str(f, a->attr, b->val);