3 The dhcpctl remote object. */
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:
13 * http://www.isc.org/isc-license-1.0.html.
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.
19 * Support and other services are available for ISC products - see
20 * http://www.isc.org for more information.
23 #include <omapip/omapip_p.h>
28 synchronous - creates a local handle for a host entry.
29 returns nonzero status code if the local host entry couldn't
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" */
35 dhcpctl_status
dhcpctl_new_object (dhcpctl_handle
*h
,
36 dhcpctl_handle connection
,
37 const char *object_type
)
39 dhcpctl_remote_object_t
*m
;
43 m
= dmalloc (sizeof *m
, MDL
);
45 return ISC_R_NOMEMORY
;
46 memset (m
, 0, sizeof *m
);
47 m
-> type
= dhcpctl_remote_type
;
49 rc_register_mdl (m
, m
-> refcnt
);
51 g
= (omapi_object_t
*)0;
52 status
= omapi_generic_new (&g
, MDL
);
53 if (status
!= ISC_R_SUCCESS
) {
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
);
63 status
= omapi_object_reference (&g
-> outer
,
64 (omapi_object_t
*)m
, MDL
);
66 if (status
!= ISC_R_SUCCESS
) {
67 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
68 omapi_object_dereference (&g
, MDL
);
72 status
= omapi_typed_data_new (MDL
, &m
-> rtype
,
73 omapi_datatype_string
,
75 if (status
!= ISC_R_SUCCESS
) {
76 omapi_object_dereference ((omapi_object_t
**)&m
, MDL
);
77 omapi_object_dereference (&g
, MDL
);
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
)
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
96 DHCPCTL_CREATE - if the object doesn't exist, create it
97 DHCPCTL_UPDATE - update the object on the server using the
99 DHCPCTL_EXCL - error if the object exists and DHCPCTL_CREATE
100 was also specified */
102 dhcpctl_status
dhcpctl_open_object (dhcpctl_handle h
,
103 dhcpctl_handle connection
,
107 omapi_object_t
*message
= (omapi_object_t
*)0;
108 dhcpctl_remote_object_t
*remote
;
110 if (h
-> type
!= dhcpctl_remote_type
)
111 return ISC_R_INVALIDARG
;
112 remote
= (dhcpctl_remote_object_t
*)h
;
114 status
= omapi_message_new (&message
, MDL
);
115 if (status
!= ISC_R_SUCCESS
)
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
);
123 status
= omapi_set_object_value (message
, (omapi_object_t
*)0,
125 if (status
!= ISC_R_SUCCESS
) {
126 omapi_object_dereference (&message
, MDL
);
129 if (flags
& DHCPCTL_CREATE
) {
130 status
= omapi_set_boolean_value (message
, (omapi_object_t
*)0,
132 if (status
!= ISC_R_SUCCESS
) {
133 omapi_object_dereference (&message
, MDL
);
137 if (flags
& DHCPCTL_UPDATE
) {
138 status
= omapi_set_boolean_value (message
, (omapi_object_t
*)0,
140 if (status
!= ISC_R_SUCCESS
) {
141 omapi_object_dereference (&message
, MDL
);
145 if (flags
& DHCPCTL_EXCL
) {
146 status
= omapi_set_boolean_value (message
, (omapi_object_t
*)0,
148 if (status
!= ISC_R_SUCCESS
) {
149 omapi_object_dereference (&message
, MDL
);
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
);
163 status
= omapi_message_register (message
);
164 if (status
!= ISC_R_SUCCESS
) {
165 omapi_object_dereference (&message
, MDL
);
168 return omapi_protocol_send_message (connection
-> outer
,
170 message
, (omapi_object_t
*)0);
173 /* Callback methods (not meant to be called directly) */
175 isc_result_t
dhcpctl_remote_set_value (omapi_object_t
*h
,
177 omapi_data_string_t
*name
,
178 omapi_typed_data_t
*value
)
180 dhcpctl_remote_object_t
*ro
;
184 if (h
-> type
!= dhcpctl_remote_type
)
185 return ISC_R_INVALIDARG
;
186 ro
= (dhcpctl_remote_object_t
*)h
;
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
;
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
;
201 isc_result_t
dhcpctl_remote_get_value (omapi_object_t
*h
,
203 omapi_data_string_t
*name
,
204 omapi_value_t
**value
)
206 if (h
-> type
!= dhcpctl_remote_type
)
207 return ISC_R_INVALIDARG
;
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
;
215 isc_result_t
dhcpctl_remote_signal_handler (omapi_object_t
*o
,
216 const char *name
, va_list ap
)
218 dhcpctl_remote_object_t
*p
;
219 omapi_typed_data_t
*tv
;
221 if (o
-> type
!= dhcpctl_remote_type
)
222 return ISC_R_INVALIDARG
;
223 p
= (dhcpctl_remote_object_t
*)o
;
225 if (!strcmp (name
, "updated")) {
226 p
-> waitstatus
= ISC_R_SUCCESS
;
227 return omapi_signal_in (o
-> inner
, "ready");
229 if (!strcmp (name
, "status")) {
230 p
-> waitstatus
= va_arg (ap
, isc_result_t
);
232 omapi_typed_data_dereference (&p
-> message
, MDL
);
233 tv
= va_arg (ap
, omapi_typed_data_t
*);
235 omapi_typed_data_reference (&p
-> message
, tv
, MDL
);
236 return omapi_signal_in (o
-> inner
, "ready");
239 if (p
-> inner
&& p
-> inner
-> type
-> signal_handler
)
240 return (*(p
-> inner
-> type
-> signal_handler
))
241 (p
-> inner
, name
, ap
);
243 return ISC_R_SUCCESS
;
246 isc_result_t
dhcpctl_remote_destroy (omapi_object_t
*h
,
247 const char *file
, int line
)
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
;
254 omapi_object_dereference ((omapi_object_t
**)&p
-> handle
,
256 return ISC_R_SUCCESS
;
259 /* Write all the published values associated with the object through the
260 specified connection. */
262 isc_result_t
dhcpctl_remote_stuff_values (omapi_object_t
*c
,
268 if (p
-> type
!= dhcpctl_remote_type
)
269 return ISC_R_INVALIDARG
;
271 if (p
-> inner
&& p
-> inner
-> type
-> stuff_values
)
272 return (*(p
-> inner
-> type
-> stuff_values
)) (c
, id
,
274 return ISC_R_SUCCESS
;