]> mj.ucw.cz Git - libucw.git/blob - lib/lib.h
Syncing crashed repository with my work tree.
[libucw.git] / lib / lib.h
1 /*
2  *      Sherlock Library -- Miscellaneous Functions
3  *
4  *      (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #ifndef _SHERLOCK_LIB_H
8 #define _SHERLOCK_LIB_H
9
10 #include <lib/config.h>
11
12 /* Temporary Files */
13
14 #define TMP_DIR "tmp"
15 #define TMP_DIR_LEN 3
16
17 struct tempfile {
18   int fh;
19   byte name[32];
20 };
21
22 void open_temp(struct tempfile *, byte *);
23 void delete_temp(struct tempfile *);
24 ulg temprand(uns);
25
26 #define TF_GENERIC "t"
27 #define TF_QUEUE_CONTROL "c"
28 #define TF_QUEUE_DATA "d"
29 #define TF_DECODE "x"
30 #define TF_TRANSFORM "s"
31 #define TF_OBJECT "o"
32
33 /* Config Files */
34
35 struct cfitem {
36   byte *name;
37   int type;
38   void *var;
39 };
40
41 #define CI_STOP 0
42 #define CI_INT 1
43 #define CI_STRING 2
44 #define CI_FUNCTION 3
45
46 typedef byte *(*ci_func)(struct cfitem *, byte *);
47
48 void cf_read(byte *, struct cfitem *);
49
50 /* Logging */
51
52 #define L_DEBUG "<0>"
53 #define L_INFO "<2>"
54 #define L_WARN "<4>"
55 #define L_ERROR "<6>"
56 #define L_FATAL "<9>"
57
58 void log(byte *, ...);
59 void die(byte *, ...) NONRET;
60 void initlog(byte *);
61 void open_log_file(byte *);
62
63 /* Allocation */
64
65 void *xmalloc(uns);
66 void *xrealloc(void *, uns);
67 byte *stralloc(byte *);
68
69 /* Content-Type pattern matching and filters */
70
71 struct ct_filter;
72
73 int match_ct_patt(byte *, byte *);
74
75 struct ct_filter *new_ct_filter(void);
76 byte *add_ct_filter(struct ct_filter *, byte *);
77 int match_ct_filter(struct ct_filter *, byte *);
78
79 /* Binary log */
80
81 int log2(ulg);
82
83 /* obj.c */
84
85 struct odes {                           /* Object description */
86   struct oattr *attrs;
87   struct mempool *pool;
88 };
89
90 struct oattr {                          /* Object attribute */
91   struct oattr *next, *same;
92   byte attr;
93   byte val[1];
94 };
95
96 void obj_dump(struct odes *);
97 struct odes *obj_fload(FILE *);
98 struct odes *obj_new(void);
99 struct odes *obj_load(byte *);
100 void obj_fwrite(FILE *, struct odes *);
101 void obj_write(byte *, struct odes *);
102 void obj_free(struct odes *);
103 struct oattr *find_attr(struct odes *, uns);
104 struct oattr *find_attr_last(struct odes *, uns);
105 uns del_attr(struct odes *, struct oattr *);
106 byte *find_aval(struct odes *, uns);
107 struct oattr *set_attr(struct odes *, uns, byte *);
108 struct oattr *set_attr_num(struct odes *, uns, uns);
109 struct oattr *add_attr(struct odes *, struct oattr *, uns, byte *);
110 struct oattr *prepend_attr(struct odes *, uns, byte *);
111
112 /* oname.c */
113
114 #define OID_MIN 0x10000         /* Values less than this have special meaning */
115
116 ulg new_oid(uns);
117 void mk_obj_name(byte *, ulg, byte *);
118 int dump_obj_to_file(byte *, ulg, struct odes *, int);
119
120 /* wordsplit.c */
121
122 int wordsplit(byte *, byte **, uns);
123
124 /* pat(i)match.c */
125
126 int match_pattern(byte *, byte *);
127 int match_pattern_nocase(byte *, byte *);
128
129 /* md5hex.c */
130
131 void md5_to_hex(byte *, byte *);
132 void hex_to_md5(byte *, byte *);
133
134 #define MD5_SIZE 16
135 #define MD5_HEX_SIZE 33
136
137 /* prime.c */
138
139 int isprime(uns);
140 uns nextprime(uns);
141
142 /* timer.c */
143
144 void init_timer(void);
145 uns get_timer(void);
146
147 /* regex.c */
148
149 typedef struct regex regex;
150
151 regex *rx_compile(byte *r);
152 void rx_free(regex *r);
153 int rx_match(regex *r, byte *s);
154 int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen);
155
156 #endif