2 * Purple is the legal property of its developers, whose names are too numerous
3 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
24 #include "dns_sd_proxy.h"
26 static DNSServiceErrorType (DNSSD_API
* _DNSServiceAddRecord
)(DNSServiceRef sdRef
, DNSRecordRef
*RecordRef
, DNSServiceFlags flags
,
27 uint16_t rrtype
, uint16_t rdlen
, const void *rdata
, uint32_t ttl
);
28 static DNSServiceErrorType (DNSSD_API
* _DNSServiceBrowse
)(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
,
29 const char *regtype
, const char *domain
, DNSServiceBrowseReply callBack
, void *context
);
30 static int (DNSSD_API
* _DNSServiceConstructFullName
)(char *fullName
, const char *service
, const char *regtype
, const char *domain
);
31 static DNSServiceErrorType (DNSSD_API
* _DNSServiceGetAddrInfo
)(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
,
32 DNSServiceProtocol protocol
, const char *hostname
, DNSServiceGetAddrInfoReply callBack
, void *context
);
33 static DNSServiceErrorType (DNSSD_API
* _DNSServiceProcessResult
)(DNSServiceRef sdRef
);
34 static DNSServiceErrorType (DNSSD_API
* _DNSServiceQueryRecord
)(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
,
35 const char *fullname
, uint16_t rrtype
, uint16_t rrclass
, DNSServiceQueryRecordReply callBack
, void *context
);
36 static void (DNSSD_API
* _DNSServiceRefDeallocate
)(DNSServiceRef sdRef
);
37 static int (DNSSD_API
* _DNSServiceRefSockFD
)(DNSServiceRef sdRef
);
38 static DNSServiceErrorType (DNSSD_API
* _DNSServiceRegister
)(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
,
39 const char *name
, const char *regtype
, const char *domain
, const char *host
, uint16_t port
, uint16_t txtLen
,
40 const void *txtRecord
, DNSServiceRegisterReply callBack
, void *context
);
41 static DNSServiceErrorType (DNSSD_API
* _DNSServiceResolve
)(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
, const char *name
,
42 const char *regtype
, const char *domain
, DNSServiceResolveReply callBack
, void *context
);
43 static DNSServiceErrorType (DNSSD_API
* _DNSServiceRemoveRecord
)(DNSServiceRef sdRef
, DNSRecordRef RecordRef
, DNSServiceFlags flags
);
44 static DNSServiceErrorType (DNSSD_API
* _DNSServiceUpdateRecord
)(DNSServiceRef sdRef
, DNSRecordRef RecordRef
, DNSServiceFlags flags
,
45 uint16_t rdlen
, const void *rdata
, uint32_t ttl
);
46 static void (DNSSD_API
* _TXTRecordCreate
)(TXTRecordRef
*txtRecord
, uint16_t bufferLen
, void *buffer
);
47 static void (DNSSD_API
* _TXTRecordDeallocate
)(TXTRecordRef
*txtRecord
);
48 static const void * (DNSSD_API
* _TXTRecordGetBytesPtr
)(const TXTRecordRef
*txtRecord
);
49 static int16_t (DNSSD_API
* _TXTRecordGetLength
)(const TXTRecordRef
*txtRecord
);
50 static const void * (DNSSD_API
* _TXTRecordGetValuePtr
)(uint16_t txtLen
, const void *txtRecord
, const char *key
, uint8_t *valueLen
);
51 static DNSServiceErrorType (DNSSD_API
* _TXTRecordSetValue
)(TXTRecordRef
*txtRecord
, const char *key
, uint8_t valueSize
, const void *value
);
54 gboolean
dns_sd_available(void) {
55 static gboolean initialized
= FALSE
;
56 static gboolean loaded
= FALSE
;
60 if ((_DNSServiceAddRecord
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceAddRecord"))
61 && (_DNSServiceBrowse
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceBrowse"))
62 && (_DNSServiceConstructFullName
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceConstructFullName"))
63 && (_DNSServiceGetAddrInfo
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceGetAddrInfo"))
64 && (_DNSServiceProcessResult
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceProcessResult"))
65 && (_DNSServiceQueryRecord
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceQueryRecord"))
66 && (_DNSServiceRefDeallocate
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRefDeallocate"))
67 && (_DNSServiceRefSockFD
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRefSockFD"))
68 && (_DNSServiceRegister
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRegister"))
69 && (_DNSServiceResolve
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceResolve"))
70 && (_DNSServiceRemoveRecord
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRemoveRecord"))
71 && (_DNSServiceUpdateRecord
= (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceUpdateRecord"))
72 && (_TXTRecordCreate
= (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordCreate"))
73 && (_TXTRecordDeallocate
= (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordDeallocate"))
74 && (_TXTRecordGetBytesPtr
= (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetBytesPtr"))
75 && (_TXTRecordGetLength
= (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetLength"))
76 && (_TXTRecordGetValuePtr
= (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetValuePtr"))
77 && (_TXTRecordSetValue
= (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordSetValue"))) {
85 DNSServiceErrorType
_wpurple_DNSServiceAddRecord(DNSServiceRef sdRef
, DNSRecordRef
*RecordRef
, DNSServiceFlags flags
,
86 uint16_t rrtype
, uint16_t rdlen
, const void *rdata
, uint32_t ttl
) {
87 g_return_val_if_fail(_DNSServiceAddRecord
!= NULL
, kDNSServiceErr_Unknown
);
88 return (_DNSServiceAddRecord
)(sdRef
, RecordRef
, flags
, rrtype
, rdlen
, rdata
, ttl
);
91 DNSServiceErrorType
_wpurple_DNSServiceBrowse(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
,
92 const char *regtype
, const char *domain
, DNSServiceBrowseReply callBack
, void *context
) {
93 g_return_val_if_fail(_DNSServiceBrowse
!= NULL
, kDNSServiceErr_Unknown
);
94 return (_DNSServiceBrowse
)(sdRef
, flags
, interfaceIndex
, regtype
, domain
, callBack
, context
);
97 int _wpurple_DNSServiceConstructFullName(char *fullName
, const char *service
, const char *regtype
, const char *domain
) {
98 g_return_val_if_fail(_DNSServiceConstructFullName
!= NULL
, 0);
99 return (_DNSServiceConstructFullName
)(fullName
, service
, regtype
, domain
);
102 DNSServiceErrorType
_wpurple_DNSServiceGetAddrInfo(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
,
103 DNSServiceProtocol protocol
, const char *hostname
, DNSServiceGetAddrInfoReply callBack
, void *context
) {
104 g_return_val_if_fail(_DNSServiceGetAddrInfo
!= NULL
, 0);
105 return (_DNSServiceGetAddrInfo
)(sdRef
, flags
, interfaceIndex
, protocol
, hostname
, callBack
, context
);
108 DNSServiceErrorType
_wpurple_DNSServiceProcessResult(DNSServiceRef sdRef
) {
109 g_return_val_if_fail(_DNSServiceProcessResult
!= NULL
, kDNSServiceErr_Unknown
);
110 return (_DNSServiceProcessResult
)(sdRef
);
114 DNSServiceErrorType
_wpurple_DNSServiceQueryRecord(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
,
115 const char *fullname
, uint16_t rrtype
, uint16_t rrclass
, DNSServiceQueryRecordReply callBack
, void *context
) {
116 g_return_val_if_fail(_DNSServiceQueryRecord
!= NULL
, kDNSServiceErr_Unknown
);
117 return (_DNSServiceQueryRecord
)(sdRef
, flags
, interfaceIndex
, fullname
, rrtype
, rrclass
, callBack
, context
);
120 void _wpurple_DNSServiceRefDeallocate(DNSServiceRef sdRef
) {
121 g_return_if_fail(_DNSServiceRefDeallocate
!= NULL
);
122 (_DNSServiceRefDeallocate
)(sdRef
);
125 int _wpurple_DNSServiceRefSockFD(DNSServiceRef sdRef
) {
126 g_return_val_if_fail(_DNSServiceRefSockFD
!= NULL
, -1);
127 return (_DNSServiceRefSockFD
)(sdRef
);
130 DNSServiceErrorType
_wpurple_DNSServiceRegister(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
,
131 const char *name
, const char *regtype
, const char *domain
, const char *host
, uint16_t port
, uint16_t txtLen
,
132 const void *txtRecord
, DNSServiceRegisterReply callBack
, void *context
) {
133 g_return_val_if_fail(_DNSServiceRegister
!= NULL
, kDNSServiceErr_Unknown
);
134 return (_DNSServiceRegister
)(sdRef
, flags
, interfaceIndex
, name
, regtype
, domain
, host
, port
, txtLen
, txtRecord
, callBack
, context
);
137 DNSServiceErrorType
_wpurple_DNSServiceResolve(DNSServiceRef
*sdRef
, DNSServiceFlags flags
, uint32_t interfaceIndex
, const char *name
,
138 const char *regtype
, const char *domain
, DNSServiceResolveReply callBack
, void *context
) {
139 g_return_val_if_fail(_DNSServiceResolve
!= NULL
, kDNSServiceErr_Unknown
);
140 return (_DNSServiceResolve
)(sdRef
, flags
, interfaceIndex
, name
, regtype
, domain
, callBack
, context
);
143 DNSServiceErrorType
_wpurple_DNSServiceRemoveRecord(DNSServiceRef sdRef
, DNSRecordRef RecordRef
, DNSServiceFlags flags
) {
144 g_return_val_if_fail(_DNSServiceRemoveRecord
!= NULL
, kDNSServiceErr_Unknown
);
145 return (_DNSServiceRemoveRecord
)(sdRef
, RecordRef
, flags
);
148 DNSServiceErrorType
_wpurple_DNSServiceUpdateRecord(DNSServiceRef sdRef
, DNSRecordRef RecordRef
, DNSServiceFlags flags
,
149 uint16_t rdlen
, const void *rdata
, uint32_t ttl
) {
150 g_return_val_if_fail(_DNSServiceUpdateRecord
!= NULL
, kDNSServiceErr_Unknown
);
151 return (_DNSServiceUpdateRecord
)(sdRef
, RecordRef
, flags
, rdlen
, rdata
, ttl
);
154 void _wpurple_TXTRecordCreate(TXTRecordRef
*txtRecord
, uint16_t bufferLen
, void *buffer
) {
155 g_return_if_fail(_TXTRecordCreate
!= NULL
);
156 (_TXTRecordCreate
)(txtRecord
, bufferLen
, buffer
);
159 void _wpurple_TXTRecordDeallocate(TXTRecordRef
*txtRecord
) {
160 g_return_if_fail(_TXTRecordDeallocate
!= NULL
);
161 (_TXTRecordDeallocate
)(txtRecord
);
164 const void * _wpurple_TXTRecordGetBytesPtr(const TXTRecordRef
*txtRecord
) {
165 g_return_val_if_fail(_TXTRecordGetBytesPtr
!= NULL
, NULL
);
166 return (_TXTRecordGetBytesPtr
)(txtRecord
);
169 uint16_t _wpurple_TXTRecordGetLength(const TXTRecordRef
*txtRecord
) {
170 g_return_val_if_fail(_TXTRecordGetLength
!= NULL
, 0);
171 return (_TXTRecordGetLength
)(txtRecord
);
174 const void * _wpurple_TXTRecordGetValuePtr(uint16_t txtLen
, const void *txtRecord
, const char *key
, uint8_t *valueLen
) {
175 g_return_val_if_fail(_TXTRecordGetValuePtr
!= NULL
, NULL
);
176 return (_TXTRecordGetValuePtr
)(txtLen
, txtRecord
, key
, valueLen
);
179 DNSServiceErrorType
_wpurple_TXTRecordSetValue(TXTRecordRef
*txtRecord
, const char *key
, uint8_t valueSize
, const void *value
) {
180 g_return_val_if_fail(_TXTRecordSetValue
!= NULL
, kDNSServiceErr_Unknown
);
181 return (_TXTRecordSetValue
)(txtRecord
, key
, valueSize
, value
);