Adjust for symbol name changes.
[dragonfly.git] / contrib / dhcp-3.0 / includes / tree.h
1 /* tree.h
2
3    Definitions for address trees... */
4
5 /*
6  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1996-2003 by Internet Software Consortium
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  *
21  *   Internet Systems Consortium, Inc.
22  *   950 Charter Street
23  *   Redwood City, CA 94063
24  *   <info@isc.org>
25  *   http://www.isc.org/
26  *
27  * This software has been written for Internet Systems Consortium
28  * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
29  * To learn more about Internet Systems Consortium, see
30  * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
31  * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
32  * ``http://www.nominum.com''.
33  */
34
35 /* A pair of pointers, suitable for making a linked list. */
36 typedef struct _pair {
37         caddr_t car;
38         struct _pair *cdr;
39 } *pair;
40
41 struct option_chain_head {
42         int refcnt;
43         pair first;
44 };
45
46 struct enumeration_value {
47         const char *name;
48         u_int8_t value;
49 };
50
51 struct enumeration {
52         struct enumeration *next;
53         const char *name;
54         struct enumeration_value *values;
55 };      
56
57 /* Tree node types... */
58 #define TREE_CONCAT             1
59 #define TREE_HOST_LOOKUP        2
60 #define TREE_CONST              3
61 #define TREE_LIMIT              4
62 #define TREE_DATA_EXPR          5
63
64 /* A data buffer with a reference count. */
65 struct buffer {
66         int refcnt;
67         unsigned char data [1];
68 };
69
70 /* XXX The mechanism by which data strings are returned is currently
71    XXX broken: rather than returning an ephemeral pointer, we create
72    XXX a reference to the data in the caller's space, which the caller
73    XXX then has to dereference - instead, the reference should be
74    XXX ephemeral by default and be made a persistent reference explicitly. */
75 /* XXX on the other hand, it seems to work pretty nicely, so maybe the
76    XXX above comment is meshuggenah. */
77
78 /* A string of data bytes, possibly accompanied by a larger buffer. */
79 struct data_string {
80         struct buffer *buffer;
81         const unsigned char *data;
82         unsigned len;   /* Does not include NUL terminator, if any. */
83         int terminated;
84 };
85
86 enum expression_context {
87         context_any, /* indefinite */
88         context_boolean,
89         context_data,
90         context_numeric,
91         context_dns,
92         context_data_or_numeric, /* indefinite */
93         context_function
94 };
95
96 struct fundef {
97         int refcnt;
98         struct string_list *args;
99         struct executable_statement *statements;
100 };
101
102 struct binding_value {
103         int refcnt;
104         enum {
105                 binding_boolean,
106                 binding_data,
107                 binding_numeric,
108                 binding_dns,
109                 binding_function
110         } type;
111         union value {
112                 struct data_string data;
113                 unsigned long intval;
114                 int boolean;
115 #if defined (NSUPDATE)
116                 ns_updrec *dns;
117 #endif
118                 struct fundef *fundef;
119                 struct binding_value *bv;
120         } value;
121 };
122
123 struct binding {
124         struct binding *next;
125         char *name;
126         struct binding_value *value;
127 };
128
129 struct binding_scope {
130         int refcnt;
131         struct binding_scope *outer;
132         struct binding *bindings;
133 };
134
135 /* Expression tree structure. */
136
137 enum expr_op {
138         expr_none,
139         expr_match,
140         expr_check,
141         expr_equal,
142         expr_substring,
143         expr_suffix,
144         expr_concat,
145         expr_host_lookup,
146         expr_and,
147         expr_or,
148         expr_not,
149         expr_option,
150         expr_hardware,
151         expr_packet,
152         expr_const_data,
153         expr_extract_int8,
154         expr_extract_int16,
155         expr_extract_int32,
156         expr_encode_int8,
157         expr_encode_int16,
158         expr_encode_int32,
159         expr_const_int,
160         expr_exists,
161         expr_encapsulate,
162         expr_known,
163         expr_reverse,
164         expr_leased_address,
165         expr_binary_to_ascii,
166         expr_config_option,
167         expr_host_decl_name,
168         expr_pick_first_value,
169         expr_lease_time,
170         expr_dns_transaction,
171         expr_static,
172         expr_ns_add,
173         expr_ns_delete,
174         expr_ns_exists,
175         expr_ns_not_exists,
176         expr_not_equal,
177         expr_null,
178         expr_variable_exists,
179         expr_variable_reference,
180         expr_filename,
181         expr_sname,
182         expr_arg,
183         expr_funcall,
184         expr_function,
185         expr_add,
186         expr_subtract,
187         expr_multiply,
188         expr_divide,
189         expr_remainder,
190         expr_binary_and,
191         expr_binary_or,
192         expr_binary_xor,
193         expr_client_state
194 };
195
196 struct expression {
197         int refcnt;
198         enum expr_op op;
199         union {
200                 struct {
201                         struct expression *expr;
202                         struct expression *offset;
203                         struct expression *len;
204                 } substring;
205                 struct expression *equal [2];
206                 struct expression *and [2];
207                 struct expression *or [2];
208                 struct expression *not;
209                 struct expression *add;
210                 struct expression *subtract;
211                 struct expression *multiply;
212                 struct expression *divide;
213                 struct expression *remainder;
214                 struct collection *check;
215                 struct {
216                         struct expression *expr;
217                         struct expression *len;
218                 } suffix;
219                 struct option *option;
220                 struct option *config_option;
221                 struct {
222                         struct expression *offset;
223                         struct expression *len;
224                 } packet;
225                 struct data_string const_data;
226                 struct expression *extract_int;
227                 struct expression *encode_int;
228                 unsigned long const_int;
229                 struct expression *concat [2];
230                 struct dns_host_entry *host_lookup;
231                 struct option *exists;
232                 struct data_string encapsulate;
233                 struct {
234                         struct expression *base;
235                         struct expression *width;
236                         struct expression *seperator;
237                         struct expression *buffer;
238                 } b2a;
239                 struct {
240                         struct expression *width;
241                         struct expression *buffer;
242                 } reverse;
243                 struct {
244                         struct expression *car;
245                         struct expression *cdr;
246                 } pick_first_value;
247                 struct {
248                         struct expression *car;
249                         struct expression *cdr;
250                 } dns_transaction;
251                 struct {
252                         unsigned rrclass;
253                         unsigned rrtype;
254                         struct expression *rrname;
255                         struct expression *rrdata;
256                         struct expression *ttl;
257                 } ns_add;
258                 struct {
259                         unsigned rrclass;
260                         unsigned rrtype;
261                         struct expression *rrname;
262                         struct expression *rrdata;
263                 } ns_delete, ns_exists, ns_not_exists;
264                 char *variable;
265                 struct {
266                         struct expression *val;
267                         struct expression *next;
268                 } arg;
269                 struct {
270                         char *name;
271                         struct expression *arglist;
272                 } funcall;
273                 struct fundef *func;
274         } data;
275         int flags;
276 #       define EXPR_EPHEMERAL   1
277 };              
278
279 /* DNS host entry structure... */
280 struct dns_host_entry {
281         int refcnt;
282         TIME timeout;
283         struct data_string data;
284         char hostname [1];
285 };
286
287 struct option_cache; /* forward */
288 struct packet; /* forward */
289 struct option_state; /* forward */
290 struct decoded_option_state; /* forward */
291 struct lease; /* forward */
292 struct client_state; /* forward */
293
294 struct universe {
295         const char *name;
296         struct option_cache *(*lookup_func) (struct universe *,
297                                              struct option_state *,
298                                              unsigned);
299         void (*save_func) (struct universe *, struct option_state *,
300                            struct option_cache *);
301         void (*foreach) (struct packet *,
302                          struct lease *, struct client_state *,
303                          struct option_state *, struct option_state *,
304                          struct binding_scope **, struct universe *, void *,
305                          void (*) (struct option_cache *, struct packet *,
306                                    struct lease *, struct client_state *,
307                                    struct option_state *,
308                                    struct option_state *,
309                                    struct binding_scope **,
310                                    struct universe *, void *));
311         void (*delete_func) (struct universe *universe,
312                              struct option_state *, int);
313         int (*option_state_dereference) (struct universe *,
314                                          struct option_state *,
315                                          const char *, int);
316         int (*decode) (struct option_state *,
317                        const unsigned char *, unsigned, struct universe *);
318         int (*encapsulate) (struct data_string *, struct packet *,
319                             struct lease *, struct client_state *,
320                             struct option_state *, struct option_state *,
321                             struct binding_scope **,
322                             struct universe *);
323         void (*store_tag) PROTO ((unsigned char *, u_int32_t));
324         void (*store_length) PROTO ((unsigned char *, u_int32_t));
325         int tag_size, length_size;
326         option_hash_t *hash;
327         struct option *options [256];
328         struct option *enc_opt;
329         int index;
330 };
331
332 struct option {
333         const char *name;
334         const char *format;
335         struct universe *universe;
336         unsigned code;
337 };