Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / isc-dhcp / includes / omapip / omapip_p.h
1 /* omapip_p.h
2
3    Private master include file for the OMAPI library. */
4
5 /*
6  * Copyright (c) 1996-2001 Internet Software Consortium.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of The Internet Software Consortium nor the names
19  *    of its contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * This software has been written for the Internet Software Consortium
37  * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38  * To learn more about the Internet Software Consortium, see
39  * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
40  * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
41  * ``http://www.nominum.com''.
42  */
43
44 #ifndef __OMAPIP_OMAPIP_P_H__
45 #define __OMAPIP_OMAPIP_P_H__
46
47 #ifndef __CYGWIN32__
48 #include <sys/types.h>
49 #include <netinet/in.h>
50 #include <sys/socket.h>
51 #include <sys/un.h>
52 #include <arpa/inet.h>
53
54 #include <netdb.h>
55 #else
56 #define fd_set cygwin_fd_set
57 #include <sys/types.h>
58 #endif
59 #include <fcntl.h>
60 #include <stdio.h>
61 #include <unistd.h>
62 #include <string.h>
63 #include <memory.h>
64 #include <stdlib.h>
65 #include <sys/stat.h>
66 #include <ctype.h>
67 #include <time.h>
68
69 #include "cdefs.h"
70 #include "osdep.h"
71
72 #include <isc-dhcp/dst.h>
73 #include <isc-dhcp/result.h>
74
75 #include <omapip/convert.h>
76 #include <omapip/hash.h>
77 #include <omapip/omapip.h>
78 #include <omapip/trace.h>
79
80 /* OMAPI protocol header, version 1.00 */
81 typedef struct {
82         u_int32_t authlen;      /* Length of authenticator. */
83         u_int32_t authid;       /* Authenticator object ID. */
84         u_int32_t op;           /* Opcode. */
85         omapi_handle_t handle;  /* Handle of object being operated on,
86                                    or zero. */
87         u_int32_t id;           /* Transaction ID. */
88         u_int32_t rid;  /* ID of transaction to which this is a response. */
89 } omapi_protocol_header_t;
90
91 #define OMAPI_PROTOCOL_VERSION  100
92
93 #define OMAPI_OP_OPEN           1
94 #define OMAPI_OP_REFRESH        2
95 #define OMAPI_OP_UPDATE         3
96 #define OMAPI_OP_NOTIFY         4
97 #define OMAPI_OP_STATUS         5
98 #define OMAPI_OP_DELETE         6
99
100 typedef enum {
101         omapi_connection_unconnected,
102         omapi_connection_connecting,
103         omapi_connection_connected,
104         omapi_connection_disconnecting,
105         omapi_connection_closed
106 } omapi_connection_state_t;
107
108 typedef enum {
109         omapi_protocol_intro_wait,
110         omapi_protocol_header_wait,
111         omapi_protocol_signature_wait,
112         omapi_protocol_name_wait,
113         omapi_protocol_name_length_wait,
114         omapi_protocol_value_wait,
115         omapi_protocol_value_length_wait
116 } omapi_protocol_state_t;
117
118 typedef struct __omapi_message_object {
119         OMAPI_OBJECT_PREAMBLE;
120         struct __omapi_message_object *next, *prev;
121         omapi_object_t *object;
122         omapi_object_t *notify_object;
123         struct __omapi_protocol_object *protocol_object;
124         u_int32_t authlen;
125         omapi_typed_data_t *authenticator;
126         u_int32_t authid;
127         omapi_object_t *id_object;
128         u_int32_t op;
129         u_int32_t h;
130         u_int32_t id;
131         u_int32_t rid;
132 } omapi_message_object_t;
133
134 typedef struct __omapi_remote_auth {
135         struct __omapi_remote_auth *next;
136         omapi_handle_t remote_handle;
137         omapi_object_t *a;
138 } omapi_remote_auth_t;
139
140 typedef struct __omapi_protocol_object {
141         OMAPI_OBJECT_PREAMBLE;
142         u_int32_t header_size;          
143         u_int32_t protocol_version;
144         u_int32_t next_xid;
145
146         omapi_protocol_state_t state;   /* Input state. */
147         int reading_message_values;     /* True if reading message-specific
148                                            values. */
149         omapi_message_object_t *message;        /* Incoming message. */
150         omapi_data_string_t *name;      /* Incoming name. */
151         omapi_typed_data_t *value;      /* Incoming value. */
152         isc_result_t verify_result;
153         omapi_remote_auth_t *default_auth; /* Default authinfo to use. */
154         omapi_remote_auth_t *remote_auth_list;  /* Authenticators active on
155                                                    this connection. */
156
157         isc_boolean_t insecure;         /* Set to allow unauthenticated
158                                            messages. */
159
160         isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *);
161 } omapi_protocol_object_t;
162
163 typedef struct {
164         OMAPI_OBJECT_PREAMBLE;
165
166         isc_boolean_t insecure;         /* Set to allow unauthenticated
167                                            messages. */
168
169         isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *);
170 } omapi_protocol_listener_object_t;
171
172 #include <omapip/buffer.h>
173
174 typedef struct __omapi_listener_object {
175         OMAPI_OBJECT_PREAMBLE;
176         int socket;             /* Connection socket. */
177         int index;
178         struct sockaddr_in address;
179         isc_result_t (*verify_addr) (omapi_object_t *, omapi_addr_t *);
180 } omapi_listener_object_t;
181
182 typedef struct __omapi_connection_object {
183         OMAPI_OBJECT_PREAMBLE;
184         int socket;             /* Connection socket. */
185         int32_t index;
186         omapi_connection_state_t state;
187         struct sockaddr_in remote_addr;
188         struct sockaddr_in local_addr;
189         omapi_addr_list_t *connect_list;        /* List of addresses to which
190                                                    to connect. */
191         int cptr;               /* Current element we are connecting to. */
192         u_int32_t bytes_needed; /* Bytes of input needed before wakeup. */
193         u_int32_t in_bytes;     /* Bytes of input already buffered. */
194         omapi_buffer_t *inbufs;
195         u_int32_t out_bytes;    /* Bytes of output in buffers. */
196         omapi_buffer_t *outbufs;
197         omapi_listener_object_t *listener;      /* Listener that accepted this
198                                                    connection, if any. */
199         DST_KEY *in_key;        /* Authenticator signing incoming
200                                    data. */
201         void *in_context;       /* Input hash context. */
202         DST_KEY *out_key;       /* Authenticator signing outgoing
203                                    data. */
204         void *out_context;      /* Output hash context. */
205 } omapi_connection_object_t;
206
207 typedef struct __omapi_io_object {
208         OMAPI_OBJECT_PREAMBLE;
209         struct __omapi_io_object *next;
210         int (*readfd) (omapi_object_t *);
211         int (*writefd) (omapi_object_t *);
212         isc_result_t (*reader) (omapi_object_t *);
213         isc_result_t (*writer) (omapi_object_t *);
214         isc_result_t (*reaper) (omapi_object_t *);
215 } omapi_io_object_t;
216
217 typedef struct __omapi_generic_object {
218         OMAPI_OBJECT_PREAMBLE;
219         omapi_value_t **values;
220         u_int8_t *changed;
221         int nvalues, va_max;
222 } omapi_generic_object_t;
223
224 typedef struct __omapi_waiter_object {
225         OMAPI_OBJECT_PREAMBLE;
226         int ready;
227         isc_result_t waitstatus;
228         struct __omapi_waiter_object *next;
229 } omapi_waiter_object_t;
230
231 #define OMAPI_HANDLE_TABLE_SIZE 120
232
233 typedef struct __omapi_handle_table {
234         omapi_handle_t first, limit;
235         omapi_handle_t next;
236         int leafp;
237         union {
238                 omapi_object_t *object;
239                 struct __omapi_handle_table *table;
240         } children [OMAPI_HANDLE_TABLE_SIZE];
241 } omapi_handle_table_t;
242
243 #include <omapip/alloc.h>
244
245 OMAPI_OBJECT_ALLOC_DECL (omapi_protocol, omapi_protocol_object_t,
246                          omapi_type_protocol)
247 OMAPI_OBJECT_ALLOC_DECL (omapi_protocol_listener,
248                          omapi_protocol_listener_object_t,
249                          omapi_type_protocol_listener)
250 OMAPI_OBJECT_ALLOC_DECL (omapi_connection,
251                          omapi_connection_object_t, omapi_type_connection)
252 OMAPI_OBJECT_ALLOC_DECL (omapi_listener,
253                          omapi_listener_object_t, omapi_type_listener)
254 OMAPI_OBJECT_ALLOC_DECL (omapi_io,
255                          omapi_io_object_t, omapi_type_io_object)
256 OMAPI_OBJECT_ALLOC_DECL (omapi_waiter,
257                          omapi_waiter_object_t, omapi_type_waiter)
258 OMAPI_OBJECT_ALLOC_DECL (omapi_generic,
259                          omapi_generic_object_t, omapi_type_generic)
260 OMAPI_OBJECT_ALLOC_DECL (omapi_message,
261                          omapi_message_object_t, omapi_type_message)
262
263 isc_result_t omapi_connection_sign_data (int mode,
264                                          DST_KEY *key,
265                                          void **context,
266                                          const unsigned char *data,
267                                          const unsigned len,
268                                          omapi_typed_data_t **result);
269 isc_result_t omapi_listener_connect (omapi_connection_object_t **obj,
270                                      omapi_listener_object_t *listener,
271                                      int socket,
272                                      struct sockaddr_in *remote_addr);
273 void omapi_listener_trace_setup (void);
274 void omapi_connection_trace_setup (void);
275 void omapi_buffer_trace_setup (void);
276 void omapi_connection_register (omapi_connection_object_t *,
277                                 const char *, int);
278 void trace_mr_init (void);
279
280 OMAPI_ARRAY_TYPE_DECL(omapi_listener, omapi_listener_object_t);
281 OMAPI_ARRAY_TYPE_DECL(omapi_connection, omapi_connection_object_t);
282
283 extern int log_priority;
284 extern int log_perror;
285 extern void (*log_cleanup) (void);
286
287 void log_fatal (const char *, ...)
288         __attribute__((__format__(__printf__,1,2)));
289 int log_error (const char *, ...)
290         __attribute__((__format__(__printf__,1,2)));
291 int log_info (const char *, ...)
292         __attribute__((__format__(__printf__,1,2)));
293 int log_debug (const char *, ...)
294         __attribute__((__format__(__printf__,1,2)));
295 void do_percentm (char *obuf, const char *ibuf);
296
297 isc_result_t uerr2isc (int);
298 isc_result_t ns_rcode_to_isc (int);
299
300 extern omapi_message_object_t *omapi_registered_messages;
301
302 #endif /* __OMAPIP_OMAPIP_P_H__ */