]> git.ipfire.org Git - thirdparty/dhcp.git/blame - dhcpctl/callback.c
Support for asynchronous ddns per ticket 19216 - convert to using isclib and
[thirdparty/dhcp.git] / dhcpctl / callback.c
CommitLineData
fe4ab6d6
TL
1/* callback.c
2
3 The dhcpctl callback object. */
4
5/*
706792c9 6 * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
98311e4b 7 * Copyright (c) 1999-2003 by Internet Software Consortium
fe4ab6d6 8 *
98311e4b
DH
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.
fe4ab6d6 12 *
98311e4b
DH
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.
fe4ab6d6 20 *
98311e4b
DH
21 * Internet Systems Consortium, Inc.
22 * 950 Charter Street
23 * Redwood City, CA 94063
24 * <info@isc.org>
2c85ac9b 25 * https://www.isc.org/
49733f31 26 *
98311e4b 27 * This software has been written for Internet Systems Consortium
49733f31 28 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
98311e4b 29 * To learn more about Internet Systems Consortium, see
2c85ac9b 30 * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
49733f31
TL
31 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
32 * ``http://www.nominum.com''.
fe4ab6d6
TL
33 */
34
fe5b0fdd 35#include "dhcpd.h"
6a4c4be8 36#include <omapip/omapip_p.h>
fe4ab6d6
TL
37#include "dhcpctl.h"
38
39/* dhcpctl_set_callback
40
41 synchronous, with asynchronous aftereffect
42 handle is some object upon which some kind of process has been
43 started - e.g., an open, an update or a refresh.
44 data is an anonymous pointer containing some information that
45 the callback will use to figure out what event completed.
46 return value of 0 means callback was successfully set, a nonzero
47 status code is returned otherwise.
48 Upon completion of whatever task is in process, the callback
49 will be passed the handle to the object, a status code
50 indicating what happened, and the anonymous pointer passed to */
51
52dhcpctl_status dhcpctl_set_callback (dhcpctl_handle h, void *data,
53 void (*func) (dhcpctl_handle,
54 dhcpctl_status, void *))
55{
56 dhcpctl_callback_object_t *callback;
57 omapi_object_t *inner;
fe4ab6d6 58
4bd8800e 59 callback = dmalloc (sizeof *callback, MDL);
fe4ab6d6
TL
60 if (!callback)
61 return ISC_R_NOMEMORY;
62
63 /* Tie the callback object to the innermost object in the chain. */
64 for (inner = h; inner -> inner; inner = inner -> inner)
65 ;
4bd8800e
TL
66 omapi_object_reference (&inner -> inner,
67 (omapi_object_t *)callback, MDL);
68 omapi_object_reference ((omapi_object_t **)&callback -> outer,
69 inner, MDL);
fe4ab6d6
TL
70
71 /* Save the actual handle pointer we were passed for the callback. */
4bd8800e 72 omapi_object_reference (&callback -> object, h, MDL);
fe4ab6d6
TL
73 callback -> data = data;
74 callback -> callback = func;
75
76 return ISC_R_SUCCESS;
77}
78
79/* Callback methods (not meant to be called directly) */
80
81isc_result_t dhcpctl_callback_set_value (omapi_object_t *h,
82 omapi_object_t *id,
83 omapi_data_string_t *name,
84 omapi_typed_data_t *value)
85{
86 if (h -> type != dhcpctl_callback_type)
98bf1607 87 return DHCP_R_INVALIDARG;
fe4ab6d6
TL
88
89 if (h -> inner && h -> inner -> type -> set_value)
90 return (*(h -> inner -> type -> set_value))
91 (h -> inner, id, name, value);
92 return ISC_R_NOTFOUND;
93}
94
95isc_result_t dhcpctl_callback_get_value (omapi_object_t *h,
96 omapi_object_t *id,
97 omapi_data_string_t *name,
98 omapi_value_t **value)
99{
100 if (h -> type != dhcpctl_callback_type)
98bf1607 101 return DHCP_R_INVALIDARG;
fe4ab6d6
TL
102
103 if (h -> inner && h -> inner -> type -> get_value)
104 return (*(h -> inner -> type -> get_value))
105 (h -> inner, id, name, value);
106 return ISC_R_NOTFOUND;
107}
108
109isc_result_t dhcpctl_callback_signal_handler (omapi_object_t *o,
b1b7b521 110 const char *name, va_list ap)
fe4ab6d6
TL
111{
112 dhcpctl_callback_object_t *p;
113 isc_result_t waitstatus;
114
115 if (o -> type != dhcpctl_callback_type)
98bf1607 116 return DHCP_R_INVALIDARG;
fe4ab6d6
TL
117 p = (dhcpctl_callback_object_t *)o;
118
119 /* Not a signal we recognize? */
120 if (strcmp (name, "ready")) {
121 if (p -> inner && p -> inner -> type -> signal_handler)
122 return (*(p -> inner -> type -> signal_handler))
123 (p -> inner, name, ap);
124 return ISC_R_NOTFOUND;
125 }
126
127 if (p -> object -> type == dhcpctl_remote_type) {
128 waitstatus = (((dhcpctl_remote_object_t *)
129 (p -> object)) -> waitstatus);
130 } else
131 waitstatus = ISC_R_SUCCESS;
132
133 /* Do the callback. */
134 if (p -> callback)
135 (*(p -> callback)) (p -> object, waitstatus, p -> data);
136
137 return ISC_R_SUCCESS;
138}
139
4bd8800e
TL
140isc_result_t dhcpctl_callback_destroy (omapi_object_t *h,
141 const char *file, int line)
fe4ab6d6
TL
142{
143 dhcpctl_callback_object_t *p;
144 if (h -> type != dhcpctl_callback_type)
98bf1607 145 return DHCP_R_INVALIDARG;
fe4ab6d6
TL
146 p = (dhcpctl_callback_object_t *)h;
147 if (p -> handle)
148 omapi_object_dereference ((omapi_object_t **)&p -> handle,
4bd8800e 149 file, line);
fe4ab6d6
TL
150 return ISC_R_SUCCESS;
151}
152
153/* Write all the published values associated with the object through the
154 specified connection. */
155
156isc_result_t dhcpctl_callback_stuff_values (omapi_object_t *c,
157 omapi_object_t *id,
158 omapi_object_t *p)
159{
fe4ab6d6 160 if (p -> type != dhcpctl_callback_type)
98bf1607 161 return DHCP_R_INVALIDARG;
fe4ab6d6
TL
162
163 if (p -> inner && p -> inner -> type -> stuff_values)
164 return (*(p -> inner -> type -> stuff_values)) (c, id,
165 p -> inner);
166 return ISC_R_SUCCESS;
167}
168