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