Mercurial > pidgin
comparison libpurple/protocols/bonjour/dns_sd_proxy.c @ 20761:fb70e89180a9
Don't link the bonjour prpl on win32 directly to the Apple Bonjour library, instead do everything indirectly and display an error message at login time indicating that Bonjour isn't installed. This should make the prpl more discoverable.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Wed, 03 Oct 2007 00:47:25 +0000 |
parents | |
children | 53691c081eab |
comparison
equal
deleted
inserted
replaced
20760:47fed8fe4884 | 20761:fb70e89180a9 |
---|---|
1 /** | |
2 * | |
3 * Purple is the legal property of its developers, whose names are too numerous | |
4 * to list here. Please refer to the COPYRIGHT file distributed with this | |
5 * source distribution. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU Library General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA. | |
20 */ | |
21 | |
22 #include "win32dep.h" | |
23 #include "dns_sd_proxy.h" | |
24 | |
25 #ifndef LINK_DNS_SD_DIRECTLY | |
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* _DNSServiceProcessResult)(DNSServiceRef sdRef); | |
32 static DNSServiceErrorType (DNSSD_API* _DNSServiceQueryRecord)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, | |
33 const char *fullname, uint16_t rrtype, uint16_t rrclass, DNSServiceQueryRecordReply callBack, void *context); | |
34 static void (DNSSD_API* _DNSServiceRefDeallocate)(DNSServiceRef sdRef); | |
35 static int (DNSSD_API* _DNSServiceRefSockFD)(DNSServiceRef sdRef); | |
36 static DNSServiceErrorType (DNSSD_API* _DNSServiceRegister)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, | |
37 const char *name, const char *regtype, const char *domain, const char *host, uint16_t port, uint16_t txtLen, | |
38 const void *txtRecord, DNSServiceRegisterReply callBack, void *context); | |
39 static DNSServiceErrorType (DNSSD_API* _DNSServiceResolve)(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, const char *name, | |
40 const char *regtype, const char *domain, DNSServiceResolveReply callBack, void *context); | |
41 static DNSServiceErrorType (DNSSD_API* _DNSServiceRemoveRecord)(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags); | |
42 static DNSServiceErrorType (DNSSD_API* _DNSServiceUpdateRecord)(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags, | |
43 uint16_t rdlen, const void *rdata, uint32_t ttl); | |
44 static void (DNSSD_API* _TXTRecordCreate)(TXTRecordRef *txtRecord, uint16_t bufferLen, void *buffer); | |
45 static void (DNSSD_API* _TXTRecordDeallocate)(TXTRecordRef *txtRecord); | |
46 static const void * (DNSSD_API* _TXTRecordGetBytesPtr)(const TXTRecordRef *txtRecord); | |
47 static int16_t (DNSSD_API* _TXTRecordGetLength)(const TXTRecordRef *txtRecord); | |
48 static const void * (DNSSD_API* _TXTRecordGetValuePtr)(uint16_t txtLen, const void *txtRecord, const char *key, uint8_t *valueLen); | |
49 static DNSServiceErrorType (DNSSD_API* _TXTRecordSetValue)(TXTRecordRef *txtRecord, const char *key, uint8_t valueSize, const void *value); | |
50 #endif | |
51 | |
52 gboolean dns_sd_available(void) { | |
53 #ifndef LINK_DNS_SD_DIRECTLY | |
54 static gboolean initialized = FALSE; | |
55 static gboolean loaded = FALSE; | |
56 | |
57 if (!initialized) { | |
58 initialized = TRUE; | |
59 if ((_DNSServiceAddRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceAddRecord")) | |
60 && (_DNSServiceBrowse = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceBrowse")) | |
61 && (_DNSServiceConstructFullName = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceConstructFullName")) | |
62 && (_DNSServiceProcessResult = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceProcessResult")) | |
63 && (_DNSServiceQueryRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceQueryRecord")) | |
64 && (_DNSServiceRefDeallocate = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRefDeallocate")) | |
65 && (_DNSServiceRefSockFD = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRefSockFD")) | |
66 && (_DNSServiceRegister = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRegister")) | |
67 && (_DNSServiceResolve = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceResolve")) | |
68 && (_DNSServiceRemoveRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceRemoveRecord")) | |
69 && (_DNSServiceUpdateRecord = (void *) wpurple_find_and_loadproc("dnssd.dll", "DNSServiceUpdateRecord")) | |
70 && (_TXTRecordCreate = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordCreate")) | |
71 && (_TXTRecordDeallocate = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordDeallocate")) | |
72 && (_TXTRecordGetBytesPtr = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetBytesPtr")) | |
73 && (_TXTRecordGetLength = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetLength")) | |
74 && (_TXTRecordGetValuePtr = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordGetValuePtr")) | |
75 && (_TXTRecordSetValue = (void *) wpurple_find_and_loadproc("dnssd.dll", "TXTRecordSetValue"))) { | |
76 loaded = TRUE; | |
77 } | |
78 } | |
79 return loaded; | |
80 #else | |
81 return TRUE; | |
82 #endif | |
83 } | |
84 | |
85 #ifndef LINK_DNS_SD_DIRECTLY | |
86 | |
87 DNSServiceErrorType _wpurple_DNSServiceAddRecord(DNSServiceRef sdRef, DNSRecordRef *RecordRef, DNSServiceFlags flags, | |
88 uint16_t rrtype, uint16_t rdlen, const void *rdata, uint32_t ttl) { | |
89 g_return_val_if_fail(_DNSServiceAddRecord != NULL, kDNSServiceErr_Unknown); | |
90 return (_DNSServiceAddRecord)(sdRef, RecordRef, flags, rrtype, rdlen, rdata, ttl); | |
91 } | |
92 | |
93 DNSServiceErrorType _wpurple_DNSServiceBrowse(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, | |
94 const char *regtype, const char *domain, DNSServiceBrowseReply callBack, void *context) { | |
95 g_return_val_if_fail(_DNSServiceBrowse != NULL, kDNSServiceErr_Unknown); | |
96 return (_DNSServiceBrowse)(sdRef, flags, interfaceIndex, regtype, domain, callBack, context); | |
97 } | |
98 | |
99 int _wpurple_DNSServiceConstructFullName(char *fullName, const char *service, const char *regtype, const char *domain) { | |
100 g_return_val_if_fail(_DNSServiceConstructFullName != NULL, 0); | |
101 return (_DNSServiceConstructFullName)(fullName, service, regtype, domain); | |
102 } | |
103 | |
104 DNSServiceErrorType _wpurple_DNSServiceProcessResult(DNSServiceRef sdRef) { | |
105 g_return_val_if_fail(_DNSServiceProcessResult != NULL, kDNSServiceErr_Unknown); | |
106 return (_DNSServiceProcessResult)(sdRef); | |
107 } | |
108 | |
109 | |
110 DNSServiceErrorType _wpurple_DNSServiceQueryRecord(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, | |
111 const char *fullname, uint16_t rrtype, uint16_t rrclass, DNSServiceQueryRecordReply callBack, void *context) { | |
112 g_return_val_if_fail(_DNSServiceQueryRecord != NULL, kDNSServiceErr_Unknown); | |
113 return (_DNSServiceQueryRecord)(sdRef, flags, interfaceIndex, fullname, rrtype, rrclass, callBack, context); | |
114 } | |
115 | |
116 void _wpurple_DNSServiceRefDeallocate(DNSServiceRef sdRef) { | |
117 g_return_if_fail(_DNSServiceRefDeallocate != NULL); | |
118 (_DNSServiceRefDeallocate)(sdRef); | |
119 } | |
120 | |
121 int _wpurple_DNSServiceRefSockFD(DNSServiceRef sdRef) { | |
122 g_return_val_if_fail(_DNSServiceRefSockFD != NULL, -1); | |
123 return (_DNSServiceRefSockFD)(sdRef); | |
124 } | |
125 | |
126 DNSServiceErrorType _wpurple_DNSServiceRegister(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, | |
127 const char *name, const char *regtype, const char *domain, const char *host, uint16_t port, uint16_t txtLen, | |
128 const void *txtRecord, DNSServiceRegisterReply callBack, void *context) { | |
129 g_return_val_if_fail(_DNSServiceRegister != NULL, kDNSServiceErr_Unknown); | |
130 return (_DNSServiceRegister)(sdRef, flags, interfaceIndex, name, regtype, domain, host, port, txtLen, txtRecord, callBack, context); | |
131 } | |
132 | |
133 DNSServiceErrorType _wpurple_DNSServiceResolve(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, const char *name, | |
134 const char *regtype, const char *domain, DNSServiceResolveReply callBack, void *context) { | |
135 g_return_val_if_fail(_DNSServiceResolve != NULL, kDNSServiceErr_Unknown); | |
136 return (_DNSServiceResolve)(sdRef, flags, interfaceIndex, name, regtype, domain, callBack, context); | |
137 } | |
138 | |
139 DNSServiceErrorType _wpurple_DNSServiceRemoveRecord(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags) { | |
140 g_return_val_if_fail(_DNSServiceRemoveRecord != NULL, kDNSServiceErr_Unknown); | |
141 return (_DNSServiceRemoveRecord)(sdRef, RecordRef, flags); | |
142 } | |
143 | |
144 DNSServiceErrorType _wpurple_DNSServiceUpdateRecord(DNSServiceRef sdRef, DNSRecordRef RecordRef, DNSServiceFlags flags, | |
145 uint16_t rdlen, const void *rdata, uint32_t ttl) { | |
146 g_return_val_if_fail(_DNSServiceUpdateRecord != NULL, kDNSServiceErr_Unknown); | |
147 return (_DNSServiceUpdateRecord)(sdRef, RecordRef, flags, rdlen, rdata, ttl); | |
148 } | |
149 | |
150 void _wpurple_TXTRecordCreate(TXTRecordRef *txtRecord, uint16_t bufferLen, void *buffer) { | |
151 g_return_if_fail(_TXTRecordCreate != NULL); | |
152 (_TXTRecordCreate)(txtRecord, bufferLen, buffer); | |
153 } | |
154 | |
155 void _wpurple_TXTRecordDeallocate(TXTRecordRef *txtRecord) { | |
156 g_return_if_fail(_TXTRecordDeallocate != NULL); | |
157 (_TXTRecordDeallocate)(txtRecord); | |
158 } | |
159 | |
160 const void * _wpurple_TXTRecordGetBytesPtr(const TXTRecordRef *txtRecord) { | |
161 g_return_val_if_fail(_TXTRecordGetBytesPtr != NULL, NULL); | |
162 return (_TXTRecordGetBytesPtr)(txtRecord); | |
163 } | |
164 | |
165 uint16_t _wpurple_TXTRecordGetLength(const TXTRecordRef *txtRecord) { | |
166 g_return_val_if_fail(_TXTRecordGetLength != NULL, 0); | |
167 return (_TXTRecordGetLength)(txtRecord); | |
168 } | |
169 | |
170 const void * _wpurple_TXTRecordGetValuePtr(uint16_t txtLen, const void *txtRecord, const char *key, uint8_t *valueLen) { | |
171 g_return_val_if_fail(_TXTRecordGetValuePtr != NULL, NULL); | |
172 return (_TXTRecordGetValuePtr)(txtLen, txtRecord, key, valueLen); | |
173 } | |
174 | |
175 DNSServiceErrorType _wpurple_TXTRecordSetValue(TXTRecordRef *txtRecord, const char *key, uint8_t valueSize, const void *value) { | |
176 g_return_val_if_fail(_TXTRecordSetValue != NULL, kDNSServiceErr_Unknown); | |
177 return (_TXTRecordSetValue)(txtRecord, key, valueSize, value); | |
178 } | |
179 | |
180 #endif /*LINK_DNS_SD_DIRECTLY*/ | |
181 |