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 *);
33 #define TF_GENERIC "t"
34 #define TF_QUEUE_CONTROL "c"
35 #define TF_QUEUE_DATA "d"
37 #define TF_TRANSFORM "s"
42 /* FIXME: Define new logging mechanism? */
50 void log(byte *, ...);
51 void die(byte *, ...) NONRET;
53 void open_log_file(byte *);
56 #define ASSERT(x) do { if (!(x)) die("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
58 #define ASSERT(x) do { } while(0)
64 void *xrealloc(void *, uns);
65 byte *stralloc(byte *);
67 /* Content-Type pattern matching and filters */
69 int match_ct_patt(byte *, byte *);
77 /* FIXME: What to do with this? */
79 struct odes { /* Object description */
84 struct oattr { /* Object attribute */
85 struct oattr *next, *same;
90 void obj_dump(struct odes *);
91 struct odes *obj_fload(FILE *, byte *);
92 struct odes *obj_new(void);
93 struct odes *obj_load(byte *);
94 void obj_fwrite(FILE *, struct odes *);
95 void obj_write(byte *, struct odes *);
96 void obj_free(struct odes *);
97 struct oattr *find_attr(struct odes *, uns);
98 struct oattr *find_attr_last(struct odes *, uns);
99 uns del_attr(struct odes *, struct oattr *);
100 byte *find_aval(struct odes *, uns);
101 struct oattr *set_attr(struct odes *, uns, byte *);
102 struct oattr *set_attr_num(struct odes *, uns, uns);
103 struct oattr *add_attr(struct odes *, struct oattr *, uns, byte *);
104 struct oattr *prepend_attr(struct odes *, uns, byte *);
110 #define OID_MIN 0x10000 /* Values less than this have special meaning */
113 void mk_obj_name(byte *, oid_t, byte *);
114 int dump_obj_to_file(byte *, oid_t, struct odes *, int);
118 int wordsplit(byte *, byte **, uns);
122 int match_pattern(byte *, byte *);
123 int match_pattern_nocase(byte *, byte *);
127 void md5_to_hex(byte *, byte *);
128 void hex_to_md5(byte *, byte *);
131 #define MD5_HEX_SIZE 33
140 void init_timer(void);
145 typedef struct regex regex;
147 regex *rx_compile(byte *r);
148 void rx_free(regex *r);
149 int rx_match(regex *r, byte *s);
150 int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen);
158 void *mmap_file(byte *name, unsigned *len);