Make setthetime() static per the prototype.
[dragonfly.git] / contrib / isc-dhcp / dhcpctl / callback.c
1 /* callback.c
2
3    The dhcpctl callback object. */
4
5 /*
6  * Copyright (c) 1999-2002 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 #include <omapip/omapip_p.h>
45 #include "dhcpctl.h"
46
47 /* dhcpctl_set_callback
48
49    synchronous, with asynchronous aftereffect
50    handle is some object upon which some kind of process has been
51    started - e.g., an open, an update or a refresh.
52    data is an anonymous pointer containing some information that
53    the callback will use to figure out what event completed.
54    return value of 0 means callback was successfully set, a nonzero
55    status code is returned otherwise.
56    Upon completion of whatever task is in process, the callback
57    will be passed the handle to the object, a status code
58    indicating what happened, and the anonymous pointer passed to  */
59
60 dhcpctl_status dhcpctl_set_callback (dhcpctl_handle h, void *data,
61                                      void (*func) (dhcpctl_handle,
62                                                    dhcpctl_status, void *))
63 {
64         dhcpctl_callback_object_t *callback;
65         omapi_object_t *inner;
66         isc_result_t status;
67
68         callback = dmalloc (sizeof *callback, MDL);
69         if (!callback)
70                 return ISC_R_NOMEMORY;
71
72         /* Tie the callback object to the innermost object in the chain. */
73         for (inner = h; inner -> inner; inner = inner -> inner)
74                 ;
75         omapi_object_reference (&inner -> inner,
76                                 (omapi_object_t *)callback, MDL);
77         omapi_object_reference ((omapi_object_t **)&callback -> outer,
78                                 inner, MDL);
79
80         /* Save the actual handle pointer we were passed for the callback. */
81         omapi_object_reference (&callback -> object, h, MDL);
82         callback -> data = data;
83         callback -> callback = func;
84         
85         return ISC_R_SUCCESS;
86 }
87
88 /* Callback methods (not meant to be called directly) */
89
90 isc_result_t dhcpctl_callback_set_value (omapi_object_t *h,
91                                          omapi_object_t *id,
92                                          omapi_data_string_t *name,
93                                          omapi_typed_data_t *value)
94 {
95         if (h -> type != dhcpctl_callback_type)
96                 return ISC_R_INVALIDARG;
97
98         if (h -> inner && h -> inner -> type -> set_value)
99                 return (*(h -> inner -> type -> set_value))
100                         (h -> inner, id, name, value);
101         return ISC_R_NOTFOUND;
102 }
103
104 isc_result_t dhcpctl_callback_get_value (omapi_object_t *h,
105                                          omapi_object_t *id,
106                                          omapi_data_string_t *name,
107                                          omapi_value_t **value)
108 {
109         if (h -> type != dhcpctl_callback_type)
110                 return ISC_R_INVALIDARG;
111         
112         if (h -> inner && h -> inner -> type -> get_value)
113                 return (*(h -> inner -> type -> get_value))
114                         (h -> inner, id, name, value);
115         return ISC_R_NOTFOUND;
116 }
117
118 isc_result_t dhcpctl_callback_signal_handler (omapi_object_t *o,
119                                               const char *name, va_list ap)
120 {
121         dhcpctl_callback_object_t *p;
122         isc_result_t waitstatus;
123
124         if (o -> type != dhcpctl_callback_type)
125                 return ISC_R_INVALIDARG;
126         p = (dhcpctl_callback_object_t *)o;
127
128         /* Not a signal we recognize? */
129         if (strcmp (name, "ready")) {
130                 if (p -> inner && p -> inner -> type -> signal_handler)
131                         return (*(p -> inner -> type -> signal_handler))
132                                 (p -> inner, name, ap);
133                 return ISC_R_NOTFOUND;
134         }
135
136         if (p -> object -> type == dhcpctl_remote_type) {
137                 waitstatus = (((dhcpctl_remote_object_t *)
138                                (p -> object)) -> waitstatus);
139         } else
140                 waitstatus = ISC_R_SUCCESS;
141
142         /* Do the callback. */
143         if (p -> callback)
144                 (*(p -> callback)) (p -> object, waitstatus, p -> data);
145
146         return ISC_R_SUCCESS;
147 }
148
149 isc_result_t dhcpctl_callback_destroy (omapi_object_t *h,
150                                        const char *file, int line)
151 {
152         dhcpctl_callback_object_t *p;
153         if (h -> type != dhcpctl_callback_type)
154                 return ISC_R_INVALIDARG;
155         p = (dhcpctl_callback_object_t *)h;
156         if (p -> handle)
157                 omapi_object_dereference ((omapi_object_t **)&p -> handle,
158                                           file, line);
159         return ISC_R_SUCCESS;
160 }
161
162 /* Write all the published values associated with the object through the
163    specified connection. */
164
165 isc_result_t dhcpctl_callback_stuff_values (omapi_object_t *c,
166                                             omapi_object_t *id,
167                                             omapi_object_t *p)
168 {
169         int i;
170
171         if (p -> type != dhcpctl_callback_type)
172                 return ISC_R_INVALIDARG;
173
174         if (p -> inner && p -> inner -> type -> stuff_values)
175                 return (*(p -> inner -> type -> stuff_values)) (c, id,
176                                                                 p -> inner);
177         return ISC_R_SUCCESS;
178 }
179