ISC DHCP 4.4.3-P1
A reference DHCPv4 and DHCPv6 implementation
 
Loading...
Searching...
No Matches
callback.c
Go to the documentation of this file.
1/* callback.c
2
3 The dhcpctl callback object. */
4
5/*
6 * Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1999-2003 by Internet Software Consortium
8 *
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 *
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.
20 *
21 * Internet Systems Consortium, Inc.
22 * PO Box 360
23 * Newmarket, NH 03857 USA
24 * <info@isc.org>
25 * https://www.isc.org/
26 *
27 */
28
29#include "dhcpd.h"
30#include <omapip/omapip_p.h>
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
47 void (*func) (dhcpctl_handle,
48 dhcpctl_status, void *))
49{
51 omapi_object_t *inner;
52
53 callback = dmalloc (sizeof *callback, MDL);
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 ;
60 omapi_object_reference (&inner -> inner,
61 (omapi_object_t *)callback, MDL);
62 omapi_object_reference ((omapi_object_t **)&callback -> outer,
63 inner, MDL);
64
65 /* Save the actual handle pointer we were passed for the callback. */
66 omapi_object_reference (&callback -> object, h, MDL);
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
79{
80 if (h -> type != dhcpctl_callback_type)
81 return DHCP_R_INVALIDARG;
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
93{
94 if (h -> type != dhcpctl_callback_type)
95 return DHCP_R_INVALIDARG;
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
104 const char *name, va_list ap)
105{
107 isc_result_t waitstatus;
108
109 if (o -> type != dhcpctl_callback_type)
110 return DHCP_R_INVALIDARG;
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
135 const char *file, int line)
136{
138 if (h -> type != dhcpctl_callback_type)
139 return DHCP_R_INVALIDARG;
141 if (p -> handle)
143 file, line);
144 return ISC_R_SUCCESS;
145}
146
147/* Write all the published values associated with the object through the
148 specified connection. */
149
151 omapi_object_t *id,
153{
154 if (p -> type != dhcpctl_callback_type)
155 return DHCP_R_INVALIDARG;
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}
isc_result_t dhcpctl_callback_signal_handler(omapi_object_t *o, const char *name, va_list ap)
Definition callback.c:103
isc_result_t dhcpctl_callback_get_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value)
Definition callback.c:89
dhcpctl_status dhcpctl_set_callback(dhcpctl_handle h, void *data, void(*func)(dhcpctl_handle, dhcpctl_status, void *))
Definition callback.c:46
isc_result_t dhcpctl_callback_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *p)
Definition callback.c:150
isc_result_t dhcpctl_callback_destroy(omapi_object_t *h, const char *file, int line)
Definition callback.c:134
isc_result_t dhcpctl_callback_set_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_typed_data_t *value)
Definition callback.c:75
omapi_object_type_t * dhcpctl_remote_type
Definition dhcpctl.c:37
omapi_object_type_t * dhcpctl_callback_type
Definition dhcpctl.c:36
omapi_object_t * dhcpctl_handle
Definition dhcpctl.h:35
isc_result_t dhcpctl_status
Definition dhcpctl.h:34
const char int line
Definition dhcpd.h:3802
const char * file
Definition dhcpd.h:3802
#define ISC_R_SUCCESS
#define MDL
Definition omapip.h:567
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
Definition alloc.c:593
struct __omapi_object omapi_object_t
Definition omapip.h:39
isc_result_t omapi_object_reference(omapi_object_t **, omapi_object_t *, const char *, int)
Definition alloc.c:571
void * dmalloc(size_t, const char *, int)
Definition alloc.c:57
#define DHCP_R_INVALIDARG
Definition result.h:49
Definition data.h:289
Definition data.h:205