]> mj.ucw.cz Git - libucw.git/blob - lib/object.h
enlarge MAX_ATTR_SIZE
[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 2500
15   /* Maximum length an attribute can ever have (including name and trailing 0).
16    * It has to be long enough to contain 1 URL, 1 reftext, and a few numbers
17    * (see 'x' attribute in labels).  */
18
19 struct fastbuf;
20 struct mempool;
21
22 struct odes {                           /* Object description */
23   struct oattr *attrs;
24   struct mempool *pool;
25   struct oattr *cached_attr;
26 };
27
28 struct oattr {                          /* Object attribute */
29   struct oattr *next, *same;
30   byte attr;
31   byte *val;
32 };
33
34 void obj_dump(struct odes *);
35 struct odes *obj_new(struct mempool *);
36 struct oattr *obj_find_attr(struct odes *, uns);
37 struct oattr *obj_find_attr_last(struct odes *, uns);
38 uns obj_del_attr(struct odes *, struct oattr *);
39 byte *obj_find_aval(struct odes *, uns);
40 uns obj_find_anum(struct odes *, uns, 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);
49
50 /* buck2obj.c: Reading of objects from buckets */
51
52 struct parsed_attr {
53   int attr;
54   byte *val;
55   uns len;
56 };
57 struct buck2obj_buf;
58
59 void get_attr_set_type(uns type);
60 int get_attr(byte **pos, byte *end, struct parsed_attr *attr);
61 int bget_attr(struct fastbuf *b, struct parsed_attr *attr);
62
63 struct buck2obj_buf *buck2obj_alloc(void);
64 void buck2obj_free(struct buck2obj_buf *buf);
65
66 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);
67 struct odes *obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, uns buck_len, struct fastbuf *body, uns *body_start);
68   /* If body_start != NULL, then only the header is parsed and *body_start is
69    * set to the position of the body. This function does a plenty of optimizations
70    * and if the body fastbuf is overwritable (body->can_overwrite_buffer), it can keep the
71    * attribute values stored on their original locations in the fastbuf's buffer.
72    * However, no such things are performed when reading the header only.
73    */
74
75 int obj_read(struct fastbuf *, struct odes *);
76
77 /* obj2buck.c: Generating buckets from objects */
78
79 void put_attr_set_type(uns type);
80
81 uns size_attr(uns len);
82
83 byte *put_attr(byte *ptr, uns type, byte *val, uns len);
84 byte *put_attr_str(byte *ptr, uns type, byte *val);
85 byte *put_attr_vformat(byte *ptr, uns type, byte *mask, va_list va);
86 byte *put_attr_format(byte *ptr, uns type, char *mask, ...) __attribute__((format(printf,3,4)));
87 byte *put_attr_num(byte *ptr, uns type, uns val);
88 byte *put_attr_separator(byte *ptr);
89
90 void bput_attr(struct fastbuf *b, uns type, byte *val, uns len);
91 void bput_attr_str(struct fastbuf *b, uns type, byte *val);
92 void bput_attr_vformat(struct fastbuf *b, uns type, byte *mask, va_list va);
93 void bput_attr_format(struct fastbuf *b, uns type, char *mask, ...) __attribute__((format(printf,3,4)));
94 void bput_attr_num(struct fastbuf *b, uns type, uns val);
95 void bput_attr_separator(struct fastbuf *b);
96
97 void obj_write(struct fastbuf *, struct odes *);
98 void obj_write_nocheck(struct fastbuf *, struct odes *);
99
100 #endif