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