2 * Sherlock Library -- Object Functions
4 * (c) 1997--2004 Martin Mares <mj@ucw.cz>
5 * (c) 2004, Robert Spalek <robert@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
11 #ifndef _SHERLOCK_OBJECT_H
12 #define _SHERLOCK_OBJECT_H
14 #define MAX_ATTR_SIZE 1024 /* Maximum length an attribute can ever have (including name and trailing 0) */
19 struct odes { /* Object description */
22 struct oattr *cached_attr;
25 struct oattr { /* Object attribute */
26 struct oattr *next, *same;
31 void obj_dump(struct odes *);
32 struct odes *obj_new(struct mempool *);
33 int obj_read(struct fastbuf *, struct odes *);
34 void obj_read_multi(struct fastbuf *, struct odes *);
35 void obj_write(struct fastbuf *, struct odes *);
36 void obj_write_nocheck(struct fastbuf *, struct odes *);
37 struct oattr *obj_find_attr(struct odes *, uns);
38 struct oattr *obj_find_attr_last(struct odes *, uns);
39 uns obj_del_attr(struct odes *, struct oattr *);
40 byte *obj_find_aval(struct odes *, uns);
41 struct oattr *obj_set_attr(struct odes *, uns, byte *);
42 struct oattr *obj_set_attr_num(struct odes *, uns, uns);
43 struct oattr *obj_add_attr(struct odes *, uns, byte *);
44 struct oattr *obj_add_attr_ref(struct odes *o, uns x, byte *v); // no strdup()
45 struct oattr *obj_prepend_attr(struct odes *, uns, byte *);
46 struct oattr *obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte *v);
47 void obj_move_attr_to_head(struct odes *o, uns);
48 void obj_move_attr_to_tail(struct odes *o, uns);
50 /* buck2obj.c: Reading of objects from buckets */
54 struct buck2obj_buf *buck2obj_alloc(void);
55 void buck2obj_free(struct buck2obj_buf *buf);
57 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);
58 struct odes *obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, uns buck_len, struct fastbuf *body, uns *body_start);
59 /* If body_start != NULL, then only the header is parsed and *body_start is
60 * set to the position of the body. This function does a plenty of optimizations
61 * and if the body fastbuf is overwritable (body->can_overwrite_buffer), it can keep the
62 * attribute values stored on their original locations in the fastbuf's buffer.
63 * However, no such things are performed when reading the header only.
66 /* obj2buck.c: Generating buckets from objects */
68 void attr_set_type(uns type);
70 byte *put_attr(byte *ptr, uns type, byte *val, uns len);
71 byte *put_attr_str(byte *ptr, uns type, byte *val);
72 byte *put_attr_vformat(byte *ptr, uns type, byte *mask, va_list va);
73 byte *put_attr_format(byte *ptr, uns type, char *mask, ...) __attribute__((format(printf,3,4)));
74 byte *put_attr_num(byte *ptr, uns type, uns val);
76 void bput_attr(struct fastbuf *b, uns type, byte *val, uns len);
77 void bput_attr_str(struct fastbuf *b, uns type, byte *val);
78 void bput_attr_vformat(struct fastbuf *b, uns type, byte *mask, va_list va);
79 void bput_attr_format(struct fastbuf *b, uns type, char *mask, ...) __attribute__((format(printf,3,4)));
80 void bput_attr_num(struct fastbuf *b, uns type, uns val);