tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / dhcp / dhcpctl / remote.c
blob61e16c068db6c3bfc401015cf6a0ce2553c75702
1 /* remote.c
3 The dhcpctl remote object. */
5 /*
6 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1999-2003 by Internet Software Consortium
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.
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.
21 * Internet Systems Consortium, Inc.
22 * 950 Charter Street
23 * Redwood City, CA 94063
24 * <info@isc.org>
25 * http://www.isc.org/
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''.
35 #ifndef lint
36 static char copyright[] =
37 "$Id$ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
38 #endif /* not lint */
40 #include <omapip/omapip_p.h>
41 #include "dhcpctl.h"
43 /* dhcpctl_new_authenticator
45 synchronous - creates an authenticator object.
46 returns nonzero status code if the object couldn't be created
47 stores handle to authenticator through h if successful, and returns zero.
48 name is the authenticator name (NUL-terminated string).
49 algorithm is the NUL-terminated string name of the algorithm to use
50 (currently, only "hmac-md5" is supported).
51 secret and secret_len is the key secret. */
53 dhcpctl_status dhcpctl_new_authenticator (dhcpctl_handle *h,
54 const char *name,
55 const char *algorithm,
56 const unsigned char *secret,
57 unsigned secret_len)
59 struct auth_key *key = (struct auth_key *)0;
60 isc_result_t status;
62 status = omapi_auth_key_new (&key, MDL);
63 if (status != ISC_R_SUCCESS)
64 return status;
66 key -> name = dmalloc (strlen (name) + 1, MDL);
67 if (!key -> name) {
68 omapi_auth_key_dereference (&key, MDL);
69 return ISC_R_NOMEMORY;
71 strcpy (key -> name, name);
73 /* If the algorithm name isn't an FQDN, tack on the
74 .SIG-ALG.REG.NET. domain. */
75 if (strchr (algorithm, '.') == 0) {
76 static char add[] = ".SIG-ALG.REG.INT.";
77 key -> algorithm = dmalloc (strlen (algorithm) +
78 sizeof (add), MDL);
79 if (!key -> algorithm) {
80 omapi_auth_key_dereference (&key, MDL);
81 return ISC_R_NOMEMORY;
83 strcpy (key -> algorithm, algorithm);
84 strcat (key -> algorithm, add);
85 } else {
86 key -> algorithm = dmalloc (strlen (algorithm) + 1, MDL);
87 if (!key -> algorithm) {
88 omapi_auth_key_dereference (&key, MDL);
89 return ISC_R_NOMEMORY;
91 strcpy (key -> algorithm, algorithm);
94 status = omapi_data_string_new (&key -> key, secret_len, MDL);
95 if (status != ISC_R_SUCCESS) {
96 omapi_auth_key_dereference (&key, MDL);
97 return status;
99 memcpy (key -> key -> value, secret, secret_len);
100 key -> key -> len = secret_len;
102 *h = (dhcpctl_handle) key;
103 return ISC_R_SUCCESS;
107 /* dhcpctl_new_object
109 synchronous - creates a local handle for a host entry.
110 returns nonzero status code if the local host entry couldn't
111 be created
112 stores handle to host through h if successful, and returns zero.
113 object_type is a pointer to a NUL-terminated string containing
114 the ascii name of the type of object being accessed - e.g., "host" */
116 dhcpctl_status dhcpctl_new_object (dhcpctl_handle *h,
117 dhcpctl_handle connection,
118 const char *object_type)
120 dhcpctl_remote_object_t *m;
121 omapi_object_t *g;
122 isc_result_t status;
124 m = (dhcpctl_remote_object_t *)0;
125 status = omapi_object_allocate ((omapi_object_t **)&m,
126 dhcpctl_remote_type, 0, MDL);
127 if (status != ISC_R_SUCCESS)
128 return status;
130 g = (omapi_object_t *)0;
131 status = omapi_generic_new (&g, MDL);
132 if (status != ISC_R_SUCCESS) {
133 dfree (m, MDL);
134 return status;
136 status = omapi_object_reference (&m -> inner, g, MDL);
137 if (status != ISC_R_SUCCESS) {
138 omapi_object_dereference ((omapi_object_t **)&m, MDL);
139 omapi_object_dereference (&g, MDL);
140 return status;
142 status = omapi_object_reference (&g -> outer,
143 (omapi_object_t *)m, MDL);
145 if (status != ISC_R_SUCCESS) {
146 omapi_object_dereference ((omapi_object_t **)&m, MDL);
147 omapi_object_dereference (&g, MDL);
148 return status;
151 status = omapi_typed_data_new (MDL, &m -> rtype,
152 omapi_datatype_string,
153 object_type);
154 if (status != ISC_R_SUCCESS) {
155 omapi_object_dereference ((omapi_object_t **)&m, MDL);
156 omapi_object_dereference (&g, MDL);
157 return status;
160 status = omapi_object_reference (h, (omapi_object_t *)m, MDL);
161 omapi_object_dereference ((omapi_object_t **)&m, MDL);
162 omapi_object_dereference (&g, MDL);
163 if (status != ISC_R_SUCCESS)
164 return status;
166 return status;
169 /* asynchronous - just queues the request
170 returns nonzero status code if open couldn't be queued
171 returns zero if open was queued
172 h is a handle to an object created by dhcpctl_new_object
173 connection is a connection to a DHCP server
174 flags include:
175 DHCPCTL_CREATE - if the object doesn't exist, create it
176 DHCPCTL_UPDATE - update the object on the server using the
177 attached parameters
178 DHCPCTL_EXCL - error if the object exists and DHCPCTL_CREATE
179 was also specified */
181 dhcpctl_status dhcpctl_open_object (dhcpctl_handle h,
182 dhcpctl_handle connection,
183 int flags)
185 isc_result_t status;
186 omapi_object_t *message = (omapi_object_t *)0;
187 dhcpctl_remote_object_t *remote;
189 if (h -> type != dhcpctl_remote_type)
190 return ISC_R_INVALIDARG;
191 remote = (dhcpctl_remote_object_t *)h;
193 status = omapi_message_new (&message, MDL);
194 if (status != ISC_R_SUCCESS)
195 return status;
196 status = omapi_set_int_value (message, (omapi_object_t *)0,
197 "op", OMAPI_OP_OPEN);
198 if (status != ISC_R_SUCCESS) {
199 omapi_object_dereference (&message, MDL);
200 return status;
202 status = omapi_set_object_value (message, (omapi_object_t *)0,
203 "object", h);
204 if (status != ISC_R_SUCCESS) {
205 omapi_object_dereference (&message, MDL);
206 return status;
208 if (flags & DHCPCTL_CREATE) {
209 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
210 "create", 1);
211 if (status != ISC_R_SUCCESS) {
212 omapi_object_dereference (&message, MDL);
213 return status;
216 if (flags & DHCPCTL_UPDATE) {
217 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
218 "update", 1);
219 if (status != ISC_R_SUCCESS) {
220 omapi_object_dereference (&message, MDL);
221 return status;
224 if (flags & DHCPCTL_EXCL) {
225 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
226 "exclusive", 1);
227 if (status != ISC_R_SUCCESS) {
228 omapi_object_dereference (&message, MDL);
229 return status;
233 if (remote -> rtype) {
234 status = omapi_set_value_str (message, (omapi_object_t *)0,
235 "type", remote -> rtype);
236 if (status != ISC_R_SUCCESS) {
237 omapi_object_dereference (&message, MDL);
238 return status;
242 status = omapi_message_register (message);
243 if (status != ISC_R_SUCCESS) {
244 omapi_object_dereference (&message, MDL);
245 return status;
248 status = omapi_protocol_send_message (connection -> outer,
249 (omapi_object_t *)0,
250 message, (omapi_object_t *)0);
252 if (status != ISC_R_SUCCESS)
253 omapi_message_unregister (message);
255 omapi_object_dereference (&message, MDL);
256 return status;
259 /* Callback methods (not meant to be called directly) */
261 isc_result_t dhcpctl_remote_set_value (omapi_object_t *h,
262 omapi_object_t *id,
263 omapi_data_string_t *name,
264 omapi_typed_data_t *value)
266 dhcpctl_remote_object_t *ro;
267 unsigned long rh;
268 isc_result_t status;
270 if (h -> type != dhcpctl_remote_type)
271 return ISC_R_INVALIDARG;
272 ro = (dhcpctl_remote_object_t *)h;
274 if (!omapi_ds_strcmp (name, "remote-handle")) {
275 status = omapi_get_int_value (&rh, value);
276 if (status == ISC_R_SUCCESS)
277 ro -> remote_handle = rh;
278 return status;
281 if (h -> inner && h -> inner -> type -> set_value)
282 return (*(h -> inner -> type -> set_value))
283 (h -> inner, id, name, value);
284 return ISC_R_NOTFOUND;
287 isc_result_t dhcpctl_remote_get_value (omapi_object_t *h,
288 omapi_object_t *id,
289 omapi_data_string_t *name,
290 omapi_value_t **value)
292 if (h -> type != dhcpctl_remote_type)
293 return ISC_R_INVALIDARG;
295 if (h -> inner && h -> inner -> type -> get_value)
296 return (*(h -> inner -> type -> get_value))
297 (h -> inner, id, name, value);
298 return ISC_R_NOTFOUND;
301 isc_result_t dhcpctl_remote_signal_handler (omapi_object_t *o,
302 const char *name, va_list ap)
304 dhcpctl_remote_object_t *p;
305 omapi_typed_data_t *tv;
307 if (o -> type != dhcpctl_remote_type)
308 return ISC_R_INVALIDARG;
309 p = (dhcpctl_remote_object_t *)o;
311 if (!strcmp (name, "updated")) {
312 p -> waitstatus = ISC_R_SUCCESS;
313 if (o -> inner -> type == omapi_type_generic)
314 omapi_generic_clear_flags (o -> inner);
315 return omapi_signal_in (o -> inner, "ready");
317 if (!strcmp (name, "status")) {
318 p -> waitstatus = va_arg (ap, isc_result_t);
319 if (p -> message)
320 omapi_typed_data_dereference (&p -> message, MDL);
321 tv = va_arg (ap, omapi_typed_data_t *);
322 if (tv)
323 omapi_typed_data_reference (&p -> message, tv, MDL);
324 return omapi_signal_in (o -> inner, "ready");
327 if (p -> inner && p -> inner -> type -> signal_handler)
328 return (*(p -> inner -> type -> signal_handler))
329 (p -> inner, name, ap);
331 return ISC_R_SUCCESS;
334 isc_result_t dhcpctl_remote_destroy (omapi_object_t *h,
335 const char *file, int line)
337 dhcpctl_remote_object_t *p;
338 if (h -> type != dhcpctl_remote_type)
339 return ISC_R_INVALIDARG;
340 p = (dhcpctl_remote_object_t *)h;
341 if (p -> handle)
342 omapi_object_dereference ((omapi_object_t **)&p -> handle,
343 file, line);
344 if (p -> rtype)
345 omapi_typed_data_dereference ((omapi_typed_data_t **)&p->rtype,
346 file, line);
347 return ISC_R_SUCCESS;
350 /* Write all the published values associated with the object through the
351 specified connection. */
353 isc_result_t dhcpctl_remote_stuff_values (omapi_object_t *c,
354 omapi_object_t *id,
355 omapi_object_t *p)
357 int i;
359 if (p -> type != dhcpctl_remote_type)
360 return ISC_R_INVALIDARG;
362 if (p -> inner && p -> inner -> type -> stuff_values)
363 return (*(p -> inner -> type -> stuff_values)) (c, id,
364 p -> inner);
365 return ISC_R_SUCCESS;