]> git.ipfire.org Git - thirdparty/dhcp.git/blob - dhcpctl/remote.c
Fix compilation errors introduced in the last set of checkins.
[thirdparty/dhcp.git] / dhcpctl / remote.c
1 /* remote.c
2
3 The dhcpctl remote object. */
4
5 /*
6 * Copyright (c) 1996-1999 Internet Software Consortium.
7 * Use is subject to license terms which appear in the file named
8 * ISC-LICENSE that should have accompanied this file when you
9 * received it. If a file named ISC-LICENSE did not accompany this
10 * file, or you are not sure the one you have is correct, you may
11 * obtain an applicable copy of the license at:
12 *
13 * http://www.isc.org/isc-license-1.0.html.
14 *
15 * This file is part of the ISC DHCP distribution. The documentation
16 * associated with this file is listed in the file DOCUMENTATION,
17 * included in the top-level directory of this release.
18 *
19 * Support and other services are available for ISC products - see
20 * http://www.isc.org for more information.
21 */
22
23 #include <omapip/omapip_p.h>
24 #include "dhcpctl.h"
25
26 /* dhcpctl_new_object
27
28 synchronous - creates a local handle for a host entry.
29 returns nonzero status code if the local host entry couldn't
30 be created
31 stores handle to host through h if successful, and returns zero.
32 object_type is a pointer to a NUL-terminated string containing
33 the ascii name of the type of object being accessed - e.g., "host" */
34
35 dhcpctl_status dhcpctl_new_object (dhcpctl_handle *h,
36 dhcpctl_handle connection,
37 const char *object_type)
38 {
39 dhcpctl_remote_object_t *m;
40 omapi_object_t *g;
41 isc_result_t status;
42
43 m = dmalloc (sizeof *m, MDL);
44 if (!m)
45 return ISC_R_NOMEMORY;
46 memset (m, 0, sizeof *m);
47 m -> type = dhcpctl_remote_type;
48 m -> refcnt = 1;
49 rc_register_mdl (m, m -> refcnt);
50
51 g = (omapi_object_t *)0;
52 status = omapi_generic_new (&g, MDL);
53 if (status != ISC_R_SUCCESS) {
54 dfree (m, MDL);
55 return status;
56 }
57 status = omapi_object_reference (&m -> inner, g, MDL);
58 if (status != ISC_R_SUCCESS) {
59 omapi_object_dereference ((omapi_object_t **)&m, MDL);
60 omapi_object_dereference (&g, MDL);
61 return status;
62 }
63 status = omapi_object_reference (&g -> outer,
64 (omapi_object_t *)m, MDL);
65
66 if (status != ISC_R_SUCCESS) {
67 omapi_object_dereference ((omapi_object_t **)&m, MDL);
68 omapi_object_dereference (&g, MDL);
69 return status;
70 }
71
72 status = omapi_typed_data_new (MDL, &m -> rtype,
73 omapi_datatype_string,
74 object_type);
75 if (status != ISC_R_SUCCESS) {
76 omapi_object_dereference ((omapi_object_t **)&m, MDL);
77 omapi_object_dereference (&g, MDL);
78 return status;
79 }
80
81 status = omapi_object_reference (h, (omapi_object_t *)m, MDL);
82 omapi_object_dereference ((omapi_object_t **)&m, MDL);
83 omapi_object_dereference (&g, MDL);
84 if (status != ISC_R_SUCCESS)
85 return status;
86
87 return status;
88 }
89
90 /* asynchronous - just queues the request
91 returns nonzero status code if open couldn't be queued
92 returns zero if open was queued
93 h is a handle to an object created by dhcpctl_new_object
94 connection is a connection to a DHCP server
95 flags include:
96 DHCPCTL_CREATE - if the object doesn't exist, create it
97 DHCPCTL_UPDATE - update the object on the server using the
98 attached parameters
99 DHCPCTL_EXCL - error if the object exists and DHCPCTL_CREATE
100 was also specified */
101
102 dhcpctl_status dhcpctl_open_object (dhcpctl_handle h,
103 dhcpctl_handle connection,
104 int flags)
105 {
106 isc_result_t status;
107 omapi_object_t *message = (omapi_object_t *)0;
108 dhcpctl_remote_object_t *remote;
109
110 if (h -> type != dhcpctl_remote_type)
111 return ISC_R_INVALIDARG;
112 remote = (dhcpctl_remote_object_t *)h;
113
114 status = omapi_message_new (&message, MDL);
115 if (status != ISC_R_SUCCESS)
116 return status;
117 status = omapi_set_int_value (message, (omapi_object_t *)0,
118 "op", OMAPI_OP_OPEN);
119 if (status != ISC_R_SUCCESS) {
120 omapi_object_dereference (&message, MDL);
121 return status;
122 }
123 status = omapi_set_object_value (message, (omapi_object_t *)0,
124 "object", h);
125 if (status != ISC_R_SUCCESS) {
126 omapi_object_dereference (&message, MDL);
127 return status;
128 }
129 if (flags & DHCPCTL_CREATE) {
130 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
131 "create", 1);
132 if (status != ISC_R_SUCCESS) {
133 omapi_object_dereference (&message, MDL);
134 return status;
135 }
136 }
137 if (flags & DHCPCTL_UPDATE) {
138 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
139 "update", 1);
140 if (status != ISC_R_SUCCESS) {
141 omapi_object_dereference (&message, MDL);
142 return status;
143 }
144 }
145 if (flags & DHCPCTL_EXCL) {
146 status = omapi_set_boolean_value (message, (omapi_object_t *)0,
147 "exclusive", 1);
148 if (status != ISC_R_SUCCESS) {
149 omapi_object_dereference (&message, MDL);
150 return status;
151 }
152 }
153
154 if (remote -> rtype) {
155 status = omapi_set_value_str (message, (omapi_object_t *)0,
156 "type", remote -> rtype);
157 if (status != ISC_R_SUCCESS) {
158 omapi_object_dereference (&message, MDL);
159 return status;
160 }
161 }
162
163 status = omapi_message_register (message);
164 if (status != ISC_R_SUCCESS) {
165 omapi_object_dereference (&message, MDL);
166 return status;
167 }
168 return omapi_protocol_send_message (connection -> outer,
169 (omapi_object_t *)0,
170 message, (omapi_object_t *)0);
171 }
172
173 /* Callback methods (not meant to be called directly) */
174
175 isc_result_t dhcpctl_remote_set_value (omapi_object_t *h,
176 omapi_object_t *id,
177 omapi_data_string_t *name,
178 omapi_typed_data_t *value)
179 {
180 dhcpctl_remote_object_t *ro;
181 unsigned long rh;
182 isc_result_t status;
183
184 if (h -> type != dhcpctl_remote_type)
185 return ISC_R_INVALIDARG;
186 ro = (dhcpctl_remote_object_t *)h;
187
188 if (!omapi_ds_strcmp (name, "remote-handle")) {
189 status = omapi_get_int_value (&rh, value);
190 if (status == ISC_R_SUCCESS)
191 ro -> remote_handle = rh;
192 return status;
193 }
194
195 if (h -> inner && h -> inner -> type -> set_value)
196 return (*(h -> inner -> type -> set_value))
197 (h -> inner, id, name, value);
198 return ISC_R_NOTFOUND;
199 }
200
201 isc_result_t dhcpctl_remote_get_value (omapi_object_t *h,
202 omapi_object_t *id,
203 omapi_data_string_t *name,
204 omapi_value_t **value)
205 {
206 if (h -> type != dhcpctl_remote_type)
207 return ISC_R_INVALIDARG;
208
209 if (h -> inner && h -> inner -> type -> get_value)
210 return (*(h -> inner -> type -> get_value))
211 (h -> inner, id, name, value);
212 return ISC_R_NOTFOUND;
213 }
214
215 isc_result_t dhcpctl_remote_signal_handler (omapi_object_t *o,
216 const char *name, va_list ap)
217 {
218 dhcpctl_remote_object_t *p;
219 omapi_typed_data_t *tv;
220
221 if (o -> type != dhcpctl_remote_type)
222 return ISC_R_INVALIDARG;
223 p = (dhcpctl_remote_object_t *)o;
224
225 if (!strcmp (name, "updated")) {
226 p -> waitstatus = ISC_R_SUCCESS;
227 return omapi_signal_in (o -> inner, "ready");
228 }
229 if (!strcmp (name, "status")) {
230 p -> waitstatus = va_arg (ap, isc_result_t);
231 if (p -> message)
232 omapi_typed_data_dereference (&p -> message, MDL);
233 tv = va_arg (ap, omapi_typed_data_t *);
234 if (tv)
235 omapi_typed_data_reference (&p -> message, tv, MDL);
236 return omapi_signal_in (o -> inner, "ready");
237 }
238
239 if (p -> inner && p -> inner -> type -> signal_handler)
240 return (*(p -> inner -> type -> signal_handler))
241 (p -> inner, name, ap);
242
243 return ISC_R_SUCCESS;
244 }
245
246 isc_result_t dhcpctl_remote_destroy (omapi_object_t *h,
247 const char *file, int line)
248 {
249 dhcpctl_remote_object_t *p;
250 if (h -> type != dhcpctl_remote_type)
251 return ISC_R_INVALIDARG;
252 p = (dhcpctl_remote_object_t *)h;
253 if (p -> handle)
254 omapi_object_dereference ((omapi_object_t **)&p -> handle,
255 file, line);
256 return ISC_R_SUCCESS;
257 }
258
259 /* Write all the published values associated with the object through the
260 specified connection. */
261
262 isc_result_t dhcpctl_remote_stuff_values (omapi_object_t *c,
263 omapi_object_t *id,
264 omapi_object_t *p)
265 {
266 int i;
267
268 if (p -> type != dhcpctl_remote_type)
269 return ISC_R_INVALIDARG;
270
271 if (p -> inner && p -> inner -> type -> stuff_values)
272 return (*(p -> inner -> type -> stuff_values)) (c, id,
273 p -> inner);
274 return ISC_R_SUCCESS;
275 }
276