]> mj.ucw.cz Git - libucw.git/blob - lib/lib.h
Added "name" parameter to obj_fload in order to get better error reporting
[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 int cf_read_err(byte *, struct cfitem *); /* Read with possible error, 1 = succeeded */
50
51 /* Logging */
52
53 #define L_DEBUG "<0>"
54 #define L_INFO "<2>"
55 #define L_WARN "<4>"
56 #define L_ERROR "<6>"
57 #define L_FATAL "<9>"
58
59 void log(byte *, ...);
60 void die(byte *, ...) NONRET;
61 void initlog(byte *);
62 void open_log_file(byte *);
63
64 /* Allocation */
65
66 void *xmalloc(uns);
67 void *xrealloc(void *, uns);
68 byte *stralloc(byte *);
69
70 /* Content-Type pattern matching and filters */
71
72 struct ct_filter;
73
74 int match_ct_patt(byte *, byte *);
75
76 struct ct_filter *new_ct_filter(void);
77 byte *add_ct_filter(struct ct_filter *, byte *);
78 int match_ct_filter(struct ct_filter *, byte *);
79
80 /* Binary log */
81
82 int log2(ulg);
83
84 /* obj.c */
85
86 struct odes {                           /* Object description */
87   struct oattr *attrs;
88   struct mempool *pool;
89 };
90
91 struct oattr {                          /* Object attribute */
92   struct oattr *next, *same;
93   byte attr;
94   byte val[1];
95 };
96
97 void obj_dump(struct odes *);
98 struct odes *obj_fload(FILE *, byte *);
99 struct odes *obj_new(void);
100 struct odes *obj_load(byte *);
101 void obj_fwrite(FILE *, struct odes *);
102 void obj_write(byte *, struct odes *);
103 void obj_free(struct odes *);
104 struct oattr *find_attr(struct odes *, uns);
105 struct oattr *find_attr_last(struct odes *, uns);
106 uns del_attr(struct odes *, struct oattr *);
107 byte *find_aval(struct odes *, uns);
108 struct oattr *set_attr(struct odes *, uns, byte *);
109 struct oattr *set_attr_num(struct odes *, uns, uns);
110 struct oattr *add_attr(struct odes *, struct oattr *, uns, byte *);
111 struct oattr *prepend_attr(struct odes *, uns, byte *);
112
113 /* oname.c */
114
115 #define OID_MIN 0x10000         /* Values less than this have special meaning */
116
117 ulg new_oid(uns);
118 void mk_obj_name(byte *, ulg, byte *);
119 int dump_obj_to_file(byte *, ulg, struct odes *, int);
120
121 /* wordsplit.c */
122
123 int wordsplit(byte *, byte **, uns);
124
125 /* pat(i)match.c */
126
127 int match_pattern(byte *, byte *);
128 int match_pattern_nocase(byte *, byte *);
129
130 /* md5hex.c */
131
132 void md5_to_hex(byte *, byte *);
133 void hex_to_md5(byte *, byte *);
134
135 #define MD5_SIZE 16
136 #define MD5_HEX_SIZE 33
137
138 /* prime.c */
139
140 int isprime(uns);
141 uns nextprime(uns);
142
143 /* timer.c */
144
145 void init_timer(void);
146 uns get_timer(void);
147
148 /* regex.c */
149
150 typedef struct regex regex;
151
152 regex *rx_compile(byte *r);
153 void rx_free(regex *r);
154 int rx_match(regex *r, byte *s);
155 int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen);
156
157 #endif