-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOMAPI.xs
More file actions
263 lines (227 loc) · 4.81 KB
/
OMAPI.xs
File metadata and controls
263 lines (227 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <dhcpctl.h>
#include <isc-dhcp/result.h>
#include <isc-dhcp/types.h>
#include <omapip/omapip.h>
#include "const.h"
#ifndef HAVE_OMAPI_GENERIC_OBJECT_T
typedef struct __omapi_generic_object {
OMAPI_OBJECT_PREAMBLE;
omapi_value_t **values;
u_int8_t *changed;
int nvalues, va_max;
} omapi_generic_object_t;
#endif
static dhcpctl_handle *
sv2dhcpctl_handle(SV *sv)
{
if (SvROK(sv) && sv_isa(sv,"DHCP::OMAPI::Handle"))
return (dhcpctl_handle *)SvIV(SvRV(sv));
else
croak("Argument to sv2dhcpctl_handle not blessed package \"DHCP::OMAPI::Handle\"");
}
MODULE = DHCP::OMAPI::Handle PACKAGE = DHCP::OMAPI::Handle PREFIX = dhcpctl_
PROTOTYPES: ENABLE
void
initialize(self)
SV *self
CODE:
{
dhcpctl_initialize();
}
dhcpctl_handle *
new(self)
SV *self
CODE:
{
dhcpctl_handle *handle = (dhcpctl_handle *)safemalloc(sizeof(dhcpctl_handle));
memset(handle,0,sizeof(*handle));
RETVAL = handle;
}
OUTPUT:
RETVAL
int
dhcpctl_disconnect(self)
dhcpctl_handle *self
PREINIT:
isc_result_t status;
CODE:
{
RETVAL = 1;
status = omapi_disconnect ((*self) -> outer -> outer, 1);
if (status != ISC_R_SUCCESS) {
fprintf (stderr, "disconnect failed (%s)\n", isc_result_totext (status));
RETVAL = 0;
}
}
OUTPUT:
RETVAL
int
dhcpctl_connect(self,host,port,key_name,algorithm,secret)
dhcpctl_handle *self
SV *host
int port
SV *key_name
SV *algorithm
SV *secret
CODE:
{
dhcpctl_handle authenticator;
dhcpctl_status ret;
// rgc - timeout start
static void null(int i) {}
int timeout = 60;
void (*old_handler)();
old_handler = signal(SIGALRM, null);
(void) alarm(timeout);
// rgc - timeout end
if (SvOK(key_name) && SvOK(algorithm) && SvOK(secret))
{
dhcpctl_handle authenticator;
char *str;
size_t len;
str = SvPV(secret,len);
memset(&authenticator,0,sizeof(authenticator));
dhcpctl_new_authenticator(&authenticator,SvPV_nolen(key_name),SvPV_nolen(algorithm),str,len);
ret = dhcpctl_connect(self,SvPV_nolen(host),port,authenticator);
}
else
{
//fprintf(stderr,"connecting to %s:%d\n",SvPV_nolen(host),port);
ret = dhcpctl_connect(self,SvPV_nolen(host),port,NULL);
}
// rgc - timeout start
(void) alarm(0);
(void) signal(SIGALRM, old_handler);
// rgc - timeout end
RETVAL = (int)ret;
}
OUTPUT:
RETVAL
dhcpctl_handle *
dhcpctl_new_object(object,connection,object_type)
dhcpctl_handle *object
dhcpctl_handle *connection
char *object_type
CODE:
{
dhcpctl_new_object(object,*connection,object_type);
RETVAL = object;
}
OUTPUT:
RETVAL
int
dhcpctl_open_object(object,connection,flags)
dhcpctl_handle *object
dhcpctl_handle *connection
int flags
CODE:
{
dhcpctl_status ret = dhcpctl_open_object(*object,*connection,flags);
//fprintf(stderr,"open_object flags=%d\n",flags);
if (ret != ISC_R_SUCCESS)
{
goto cleanup;
}
dhcpctl_wait_for_completion(*object,&ret);
cleanup:
RETVAL = (int)ret;
}
OUTPUT:
RETVAL
int
dhcpctl_object_update(object,connection)
dhcpctl_handle *object
dhcpctl_handle *connection
CODE:
{
dhcpctl_status ret = dhcpctl_object_update(*connection,*object);
if (ret != ISC_R_SUCCESS)
{
fprintf(stderr,"object_update failed\n");
goto cleanup;
}
dhcpctl_wait_for_completion(*object,&ret);
cleanup:
RETVAL = (int)ret;
}
OUTPUT:
RETVAL
SV *
dhcpctl_get_value(object,attribute)
dhcpctl_handle *object
char *attribute
CODE:
{
dhcpctl_data_string value = NULL;
SV *out = NULL;
dhcpctl_status ret = dhcpctl_get_value(&value,*object,attribute);
if (ret == ISC_R_SUCCESS)
{
out = newSVpv(value->value,value->len);
dhcpctl_data_string_dereference(&value,MDL);
}
else
{
out = &PL_sv_undef;
}
RETVAL = out;
}
OUTPUT:
RETVAL
void
dhcpctl_attributes(object)
dhcpctl_handle *object
PREINIT:
dhcpctl_remote_object_t *r = (dhcpctl_remote_object_t *)*object;
omapi_generic_object_t *g = (omapi_generic_object_t *)(r->inner);
int i;
PPCODE:
if (g != NULL)
{
for (i = 0; i < g->nvalues; i++)
{
omapi_value_t *v = g->values[i];
XPUSHs(newSVpv(v->name->value,(int)v->name->len));
}
}
void
dhcpctl_set_value(object, value, attribute)
dhcpctl_handle *object
SV *value
char *attribute
CODE:
{
dhcpctl_data_string data = NULL;
char *str;
size_t len;
str = SvPV(value,len);
omapi_data_string_new(&data,len,MDL);
memcpy(data->value,str,len);
dhcpctl_set_value(*object,data,attribute);
}
char *
result_totext(self,res)
SV *self
int res
CODE:
{
RETVAL = (char *)isc_result_totext((isc_result_t)res);
}
OUTPUT:
RETVAL
MODULE = DHCP::OMAPI PACKAGE = DHCP::OMAPI
double
constant(sv,arg)
PREINIT:
STRLEN len;
INPUT:
SV * sv
char * s = SvPV(sv, len);
int arg
CODE:
RETVAL = constant(s,len,arg);
OUTPUT:
RETVAL