]> mj.ucw.cz Git - libucw.git/blob - lib/object.h
Fixed a bug in parsing of replies -- the parse tree of each card was trimmed
[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 uns obj_find_anum(struct odes *, uns, uns);
38 struct oattr *obj_set_attr(struct odes *, uns, byte *);
39 struct oattr *obj_set_attr_num(struct odes *, uns, uns);
40 struct oattr *obj_add_attr(struct odes *, uns, byte *);
41 struct oattr *obj_add_attr_ref(struct odes *o, uns x, byte *v); // no strdup()
42 struct oattr *obj_prepend_attr(struct odes *, uns, byte *);
43 struct oattr *obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte *v);
44 void obj_move_attr_to_head(struct odes *o, uns);
45 void obj_move_attr_to_tail(struct odes *o, uns);
46
47 /* buck2obj.c: Reading of objects from buckets */
48
49 struct parsed_attr {
50   int attr;
51   byte *val;
52   uns len;
53 };
54 struct buck2obj_buf;
55
56 void get_attr_set_type(uns type);
57 int get_attr(byte **pos, byte *end, struct parsed_attr *attr);
58 int bget_attr(struct fastbuf *b, struct parsed_attr *attr);
59
60 struct buck2obj_buf *buck2obj_alloc(void);
61 void buck2obj_free(struct buck2obj_buf *buf);
62
63 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);
64 struct odes *obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, uns buck_len, struct fastbuf *body, uns *body_start);
65   /* If body_start != NULL, then only the header is parsed and *body_start is
66    * set to the position of the body. This function does a plenty of optimizations
67    * and if the body fastbuf is overwritable (body->can_overwrite_buffer), it can keep the
68    * attribute values stored on their original locations in the fastbuf's buffer.
69    * However, no such things are performed when reading the header only.
70    */
71
72 int obj_read(struct fastbuf *, struct odes *);
73
74 /* obj2buck.c: Generating buckets from objects */
75
76 void put_attr_set_type(uns type);
77
78 uns size_attr(uns len);
79
80 byte *put_attr(byte *ptr, uns type, byte *val, uns len);
81 byte *put_attr_str(byte *ptr, uns type, byte *val);
82 byte *put_attr_vformat(byte *ptr, uns type, byte *mask, va_list va);
83 byte *put_attr_format(byte *ptr, uns type, char *mask, ...) __attribute__((format(printf,3,4)));
84 byte *put_attr_num(byte *ptr, uns type, uns val);
85 byte *put_attr_separator(byte *ptr);
86
87 void bput_attr(struct fastbuf *b, uns type, byte *val, uns len);
88 void bput_attr_str(struct fastbuf *b, uns type, byte *val);
89 void bput_attr_vformat(struct fastbuf *b, uns type, byte *mask, va_list va);
90 void bput_attr_format(struct fastbuf *b, uns type, char *mask, ...) __attribute__((format(printf,3,4)));
91 void bput_attr_num(struct fastbuf *b, uns type, uns val);
92 void bput_attr_separator(struct fastbuf *b);
93
94 void obj_write(struct fastbuf *, struct odes *);
95 void obj_write_nocheck(struct fastbuf *, struct odes *);
96
97 #endif