2 * Sherlock Library -- Miscellaneous Functions
4 * (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
7 #ifndef _SHERLOCK_LIB_H
8 #define _SHERLOCK_LIB_H
10 #include "lib/config.h"
12 /* Ugly structure handling macros */
14 #define OFFSETOF(s, i) ((unsigned int)&((s *)0)->i)
15 #define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i)))
16 #define ALIGN(s, a) (((s)+a-1)&~(a-1))
28 void open_temp(struct tempfile *, byte *);
29 void delete_temp(struct tempfile *);
32 #define TF_GENERIC "t"
33 #define TF_QUEUE_CONTROL "c"
34 #define TF_QUEUE_DATA "d"
36 #define TF_TRANSFORM "s"
52 typedef byte *(*ci_func)(struct cfitem *, byte *);
54 void cf_read(byte *, struct cfitem *);
55 int cf_read_err(byte *, struct cfitem *); /* Read with possible error, 1 = succeeded */
65 void log(byte *, ...);
66 void die(byte *, ...) NONRET;
68 void open_log_file(byte *);
71 #define ASSERT(x) do { if (!(x)) die("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
73 #define ASSERT(x) do { } while(0)
79 void *xrealloc(void *, uns);
80 byte *stralloc(byte *);
82 /* Content-Type pattern matching and filters */
86 int match_ct_patt(byte *, byte *);
88 struct ct_filter *new_ct_filter(void);
89 byte *add_ct_filter(struct ct_filter *, byte *);
90 int match_ct_filter(struct ct_filter *, byte *);
98 struct odes { /* Object description */
100 struct mempool *pool;
103 struct oattr { /* Object attribute */
104 struct oattr *next, *same;
109 void obj_dump(struct odes *);
110 struct odes *obj_fload(FILE *, byte *);
111 struct odes *obj_new(void);
112 struct odes *obj_load(byte *);
113 void obj_fwrite(FILE *, struct odes *);
114 void obj_write(byte *, struct odes *);
115 void obj_free(struct odes *);
116 struct oattr *find_attr(struct odes *, uns);
117 struct oattr *find_attr_last(struct odes *, uns);
118 uns del_attr(struct odes *, struct oattr *);
119 byte *find_aval(struct odes *, uns);
120 struct oattr *set_attr(struct odes *, uns, byte *);
121 struct oattr *set_attr_num(struct odes *, uns, uns);
122 struct oattr *add_attr(struct odes *, struct oattr *, uns, byte *);
123 struct oattr *prepend_attr(struct odes *, uns, byte *);
127 #define OID_MIN 0x10000 /* Values less than this have special meaning */
130 void mk_obj_name(byte *, oid_t, byte *);
131 int dump_obj_to_file(byte *, oid_t, struct odes *, int);
135 int wordsplit(byte *, byte **, uns);
139 int match_pattern(byte *, byte *);
140 int match_pattern_nocase(byte *, byte *);
144 void md5_to_hex(byte *, byte *);
145 void hex_to_md5(byte *, byte *);
148 #define MD5_HEX_SIZE 33
157 void init_timer(void);
162 typedef struct regex regex;
164 regex *rx_compile(byte *r);
165 void rx_free(regex *r);
166 int rx_match(regex *r, byte *s);
167 int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen);
171 void scan_obj_tree(byte *, void (*)(oid_t, byte *));
179 void *mmap_file(byte *name, unsigned *len);