This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnet_getdns.c
134 lines (107 loc) · 3.88 KB
/
net_getdns.c
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
#include "net_getdns.h"
#include <stdio.h>
struct __callback {
SV * userarg;
SV * callbackfn;
};
void
__getdns_callback(Net__GetDNS__XS__Context * context,
getdns_callback_type_t callback_type, Net__GetDNS__XS__Dict * response,
void * userarg, getdns_transaction_t transaction_id)
{
dSP;
struct __callback * cb;
if (!userarg) return;
cb = (struct __callback *)userarg;
if (!cb->callbackfn) return;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(sv_setref_pv(newSV(0), "Net::GetDNS::XS::ContextPtr", (void *)context)));
XPUSHs(sv_2mortal(newSVuv(callback_type)));
XPUSHs(sv_2mortal(sv_setref_pv(newSV(0), "Net::GetDNS::XS::DictPtr", (void *)response)));
XPUSHs(sv_2mortal(newSVsv(cb->userarg)));
XPUSHs(sv_2mortal(newSVuv(transaction_id)));
PUTBACK;
call_sv((SV*)(cb->callbackfn), G_VOID);
FREETMPS;
LEAVE;
SvREFCNT_dec(cb->callbackfn);
Safefree(cb);
}
getdns_return_t net_getdns_general(Net__GetDNS__XS__Context * context, const char *name, uint16_t request_type, Net__GetDNS__XS__Dict * extensions, SV * userarg, getdns_transaction_t * transaction_id, SV * callbackfn)
{
struct __callback * cb = 0;
if (!callbackfn) {
return GETDNS_RETURN_GENERIC_ERROR;
}
if (!SvOK(callbackfn)) {
return GETDNS_RETURN_GENERIC_ERROR;
}
Newxz(cb, 1, struct __callback);
if (!cb) return GETDNS_RETURN_MEMORY_ERROR;
if (SvOK(userarg)) {
SvGETMAGIC(userarg);
cb->userarg = userarg;
}
SvGETMAGIC(callbackfn);
cb->callbackfn = SvREFCNT_inc(newSVsv(callbackfn));
return getdns_general(context, name, request_type, extensions, cb, transaction_id, __getdns_callback);
}
getdns_return_t net_getdns_address(Net__GetDNS__XS__Context * context, const char *name, Net__GetDNS__XS__Dict * extensions, SV * userarg, getdns_transaction_t * transaction_id, SV * callbackfn)
{
struct __callback * cb = 0;
if (!callbackfn) {
return GETDNS_RETURN_GENERIC_ERROR;
}
if (!SvOK(callbackfn)) {
return GETDNS_RETURN_GENERIC_ERROR;
}
Newxz(cb, 1, struct __callback);
if (!cb) return GETDNS_RETURN_MEMORY_ERROR;
if (SvOK(userarg)) {
SvGETMAGIC(userarg);
cb->userarg = userarg;
}
SvGETMAGIC(callbackfn);
cb->callbackfn = SvREFCNT_inc(newSVsv(callbackfn));
return getdns_address(context, name, extensions, cb, transaction_id, __getdns_callback);
}
getdns_return_t net_getdns_hostname(Net__GetDNS__XS__Context * context, Net__GetDNS__XS__Dict * address, Net__GetDNS__XS__Dict * extensions, SV * userarg, getdns_transaction_t * transaction_id, SV * callbackfn)
{
struct __callback * cb = 0;
if (!callbackfn) {
return GETDNS_RETURN_GENERIC_ERROR;
}
if (!SvOK(callbackfn)) {
return GETDNS_RETURN_GENERIC_ERROR;
}
Newxz(cb, 1, struct __callback);
if (!cb) return GETDNS_RETURN_MEMORY_ERROR;
if (SvOK(userarg)) {
SvGETMAGIC(userarg);
cb->userarg = userarg;
}
SvGETMAGIC(callbackfn);
cb->callbackfn = SvREFCNT_inc(newSVsv(callbackfn));
return getdns_hostname(context, address, extensions, cb, transaction_id, __getdns_callback);
}
getdns_return_t net_getdns_service(Net__GetDNS__XS__Context * context, const char *name, Net__GetDNS__XS__Dict * extensions, SV * userarg, getdns_transaction_t * transaction_id, SV * callbackfn)
{
struct __callback * cb = 0;
if (!callbackfn) {
return GETDNS_RETURN_GENERIC_ERROR;
}
if (!SvOK(callbackfn)) {
return GETDNS_RETURN_GENERIC_ERROR;
}
Newxz(cb, 1, struct __callback);
if (!cb) return GETDNS_RETURN_MEMORY_ERROR;
if (SvOK(userarg)) {
SvGETMAGIC(userarg);
cb->userarg = userarg;
}
SvGETMAGIC(callbackfn);
cb->callbackfn = SvREFCNT_inc(newSVsv(callbackfn));
return getdns_service(context, name, extensions, cb, transaction_id, __getdns_callback);
}