]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/DLLX/DNSSDService.h
mDNSResponder-212.1.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / DLLX / DNSSDService.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2009 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: DNSSDService.h,v $
20 Revision 1.1 2009/05/26 04:43:54 herscher
21 <rdar://problem/3948252> COM component that can be used with any .NET language and VB.
22
23
24 */
25
26 #pragma once
27 #include "resource.h" // main symbols
28
29 #include "DLLX.h"
30 #include "DNSSDEventManager.h"
31 #include <CommonServices.h>
32 #include <DebugServices.h>
33 #include <dns_sd.h>
34 #include <map>
35
36
37 #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
38 #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
39 #endif
40
41
42
43 // CDNSSDService
44
45 class ATL_NO_VTABLE CDNSSDService :
46 public CComObjectRootEx<CComSingleThreadModel>,
47 public CComCoClass<CDNSSDService, &CLSID_DNSSDService>,
48 public IDispatchImpl<IDNSSDService, &IID_IDNSSDService, &LIBID_Bonjour, /*wMajor =*/ 1, /*wMinor =*/ 0>
49 {
50 public:
51
52 typedef CComObjectRootEx<CComSingleThreadModel> Super;
53
54 CDNSSDService()
55 :
56 m_isPrimary( FALSE ),
57 m_eventManager( NULL ),
58 m_stopped( FALSE ),
59 m_primary( NULL ),
60 m_subord( NULL )
61 {
62 }
63
64 DECLARE_REGISTRY_RESOURCEID(IDR_DNSSDSERVICE)
65
66
67 BEGIN_COM_MAP(CDNSSDService)
68 COM_INTERFACE_ENTRY(IDNSSDService)
69 COM_INTERFACE_ENTRY(IDispatch)
70 END_COM_MAP()
71
72 DECLARE_PROTECT_FINAL_CONSTRUCT()
73
74 HRESULT
75 FinalConstruct();
76
77 void
78 FinalRelease();
79
80 public:
81
82 inline DNSServiceRef
83 GetPrimaryRef()
84 {
85 return m_primary;
86 }
87
88 inline void
89 SetPrimaryRef( DNSServiceRef primary )
90 {
91 m_primary = primary;
92 }
93
94 inline DNSServiceRef
95 GetSubordRef()
96 {
97 return m_subord;
98 }
99
100 inline void
101 SetSubordRef( DNSServiceRef subord )
102 {
103 m_subord = subord;
104 }
105
106 inline CDNSSDEventManager*
107 GetEventManager()
108 {
109 return m_eventManager;
110 }
111
112 inline void
113 SetEventManager( IDNSSDEventManager * eventManager )
114 {
115 if ( m_eventManager )
116 {
117 m_eventManager->Release();
118 m_eventManager = NULL;
119 }
120
121 if ( eventManager )
122 {
123 m_eventManager = dynamic_cast< CDNSSDEventManager* >( eventManager );
124 check( m_eventManager );
125 m_eventManager->AddRef();
126 }
127 }
128
129 inline BOOL
130 Stopped()
131 {
132 return m_stopped;
133 }
134
135 private:
136
137 static void DNSSD_API
138 DomainEnumReply
139 (
140 DNSServiceRef sdRef,
141 DNSServiceFlags flags,
142 uint32_t ifIndex,
143 DNSServiceErrorType errorCode,
144 const char *replyDomain,
145 void *context
146 );
147
148 static void DNSSD_API
149 BrowseReply
150 (
151 DNSServiceRef sdRef,
152 DNSServiceFlags flags,
153 uint32_t interfaceIndex,
154 DNSServiceErrorType errorCode,
155 const char *serviceName,
156 const char *regtype,
157 const char *replyDomain,
158 void *context
159 );
160
161 static void DNSSD_API
162 ResolveReply
163 (
164 DNSServiceRef sdRef,
165 DNSServiceFlags flags,
166 uint32_t interfaceIndex,
167 DNSServiceErrorType errorCode,
168 const char *fullname,
169 const char *hosttarget,
170 uint16_t port,
171 uint16_t txtLen,
172 const unsigned char *txtRecord,
173 void *context
174 );
175
176 static void DNSSD_API
177 RegisterReply
178 (
179 DNSServiceRef sdRef,
180 DNSServiceFlags flags,
181 DNSServiceErrorType errorCode,
182 const char *name,
183 const char *regtype,
184 const char *domain,
185 void *context
186 );
187
188 static void DNSSD_API
189 QueryRecordReply
190 (
191 DNSServiceRef sdRef,
192 DNSServiceFlags flags,
193 uint32_t interfaceIndex,
194 DNSServiceErrorType errorCode,
195 const char *fullname,
196 uint16_t rrtype,
197 uint16_t rrclass,
198 uint16_t rdlen,
199 const void *rdata,
200 uint32_t ttl,
201 void *context
202 );
203
204 static void DNSSD_API
205 GetAddrInfoReply
206 (
207 DNSServiceRef sdRef,
208 DNSServiceFlags flags,
209 uint32_t interfaceIndex,
210 DNSServiceErrorType errorCode,
211 const char *hostname,
212 const struct sockaddr *address,
213 uint32_t ttl,
214 void *context
215 );
216
217 static void DNSSD_API
218 NATPortMappingReply
219 (
220 DNSServiceRef sdRef,
221 DNSServiceFlags flags,
222 uint32_t interfaceIndex,
223 DNSServiceErrorType errorCode,
224 uint32_t externalAddress, /* four byte IPv4 address in network byte order */
225 DNSServiceProtocol protocol,
226 uint16_t internalPort,
227 uint16_t externalPort, /* may be different than the requested port */
228 uint32_t ttl, /* may be different than the requested ttl */
229 void *context
230 );
231
232 static void DNSSD_API
233 RegisterRecordReply
234 (
235 DNSServiceRef sdRef,
236 DNSRecordRef RecordRef,
237 DNSServiceFlags flags,
238 DNSServiceErrorType errorCode,
239 void *context
240 );
241
242 inline BOOL
243 ShouldHandleReply( DNSServiceErrorType errorCode, CDNSSDEventManager *& eventManager );
244
245 static LRESULT CALLBACK
246 WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
247
248 typedef std::map< SOCKET, CDNSSDService* > SocketMap;
249
250 static BOOL m_registeredWindowClass;
251 static HWND m_hiddenWindow;
252 static SocketMap m_socketMap;
253 CDNSSDEventManager * m_eventManager;
254 BOOL m_stopped;
255 BOOL m_isPrimary;
256 DNSServiceRef m_primary;
257 DNSServiceRef m_subord;
258 public:
259 STDMETHOD(EnumerateDomains)(DNSSDFlags flags, ULONG ifIndex, IDNSSDEventManager *eventManager, IDNSSDService **service);
260 STDMETHOD(Browse)(DNSSDFlags flags, ULONG interfaceIndex, BSTR regtype, BSTR domain, IDNSSDEventManager* eventManager, IDNSSDService** sdref);
261 STDMETHOD(Resolve)(DNSSDFlags flags, ULONG ifIndex, BSTR serviceName, BSTR regType, BSTR domain, IDNSSDEventManager* eventManager, IDNSSDService** service);
262 STDMETHOD(Register)(DNSSDFlags flags, ULONG ifIndex, BSTR name, BSTR regType, BSTR domain, BSTR host, USHORT port, ITXTRecord *record, IDNSSDEventManager *eventManager, IDNSSDService **service);
263 STDMETHOD(QueryRecord)(DNSSDFlags flags, ULONG ifIndex, BSTR fullname, DNSSDRRType rrtype, DNSSDRRClass rrclass, IDNSSDEventManager *eventManager, IDNSSDService **service);
264 STDMETHOD(RegisterRecord)(DNSSDFlags flags, ULONG ifIndex, BSTR fullname, DNSSDRRType rrtype, DNSSDRRClass rrclass, VARIANT rdata, ULONG ttl, IDNSSDEventManager* eventManager, IDNSSDRecord** record);
265 STDMETHOD(AddRecord)(DNSSDFlags flags, DNSSDRRType rrtype, VARIANT rdata, ULONG ttl, IDNSSDRecord ** record);
266 STDMETHOD(ReconfirmRecord)(DNSSDFlags flags, ULONG ifIndex, BSTR fullname, DNSSDRRType rrtype, DNSSDRRClass rrclass, VARIANT rdata);
267 STDMETHOD(GetProperty)(BSTR prop, VARIANT * value);
268 STDMETHOD(GetAddrInfo)(DNSSDFlags flags, ULONG ifIndex, DNSSDAddressFamily addressFamily, BSTR hostname, IDNSSDEventManager *eventManager, IDNSSDService **service);
269 STDMETHOD(NATPortMappingCreate)(DNSSDFlags flags, ULONG ifIndex, DNSSDAddressFamily addressFamily, DNSSDProtocol protocol, USHORT internalPort, USHORT externalPort, ULONG ttl, IDNSSDEventManager *eventManager, IDNSSDService **service);
270 STDMETHOD(Stop)(void);
271 };
272
273 OBJECT_ENTRY_AUTO(__uuidof(DNSSDService), CDNSSDService)