]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/ExplorerPlugin/ExplorerBarWindow.h
mDNSResponder-212.1.tar.gz
[apple/mdnsresponder.git] / Clients / ExplorerPlugin / ExplorerBarWindow.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2003-2004 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: ExplorerBarWindow.h,v $
20 Revision 1.9 2009/03/30 18:49:15 herscher
21 <rdar://problem/5925472> Current Bonjour code does not compile on Windows
22 <rdar://problem/5187308> Move build train to Visual Studio 2005
23
24 Revision 1.8 2006/08/14 23:24:00 cheshire
25 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
26
27 Revision 1.7 2005/02/25 19:57:30 shersche
28 <rdar://problem/4023323> Remove FTP browsing from plugin
29
30 Revision 1.6 2005/01/27 22:27:03 shersche
31 Add m_about member for "About ..." tree item
32
33 Revision 1.5 2004/07/26 05:47:31 shersche
34 use TXTRecord APIs, fix bug in locating service to be removed
35
36 Revision 1.4 2004/07/20 06:49:18 shersche
37 clean up socket handling code
38
39 Revision 1.3 2004/07/13 21:24:21 rpantos
40 Fix for <rdar://problem/3701120>.
41
42 Revision 1.2 2004/06/27 14:59:59 shersche
43 reference count service info to handle multi-homed hosts
44
45 Revision 1.1 2004/06/18 04:34:59 rpantos
46 Move to Clients from mDNSWindows
47
48 Revision 1.3 2004/04/15 01:00:05 bradley
49 Removed support for automatically querying for A/AAAA records when resolving names. Platforms
50 without .local name resolving support will need to manually query for A/AAAA records as needed.
51
52 Revision 1.2 2004/04/08 09:43:43 bradley
53 Changed callback calling conventions to __stdcall so they can be used with C# delegates.
54
55 Revision 1.1 2004/01/30 03:01:56 bradley
56 Explorer Plugin to browse for DNS-SD advertised Web and FTP servers from within Internet Explorer.
57
58 */
59
60 #ifndef __EXPLORER_BAR_WINDOW__
61 #define __EXPLORER_BAR_WINDOW__
62
63 #pragma once
64
65 #include "afxtempl.h"
66
67 #include "dns_sd.h"
68 #include <list>
69
70 //===========================================================================================================================
71 // Structures
72 //===========================================================================================================================
73
74 // Forward Declarations
75
76 struct ServiceHandlerEntry;
77 class ExplorerBarWindow;
78
79 // ServiceInfo
80
81 struct ServiceInfo
82 {
83 CString displayName;
84 char * name;
85 char * type;
86 char * domain;
87 uint32_t ifi;
88 HTREEITEM item;
89 ServiceHandlerEntry * handler;
90 DWORD refs;
91
92 ServiceInfo( void )
93 {
94 item = NULL;
95 type = NULL;
96 domain = NULL;
97 handler = NULL;
98 }
99
100 ~ServiceInfo( void )
101 {
102 if( name )
103 {
104 free( name );
105 }
106 if( type )
107 {
108 free( type );
109 }
110 if( domain )
111 {
112 free( domain );
113 }
114 }
115 };
116
117 typedef CArray < ServiceInfo *, ServiceInfo * > ServiceInfoArray;
118
119 // TextRecord
120
121 struct TextRecord
122 {
123 uint8_t * mData;
124 uint16_t mSize;
125
126 TextRecord( void )
127 {
128 mData = NULL;
129 mSize = 0;
130 }
131
132 ~TextRecord( void )
133 {
134 if( mData )
135 {
136 free( mData );
137 }
138 }
139
140 void GetData( void *outData, uint16_t *outSize )
141 {
142 if( outData )
143 {
144 *( (void **) outData ) = mData;
145 }
146 if( outSize )
147 {
148 *outSize = mSize;
149 }
150 }
151
152 OSStatus SetData( const void *inData, uint16_t inSize )
153 {
154 OSStatus err;
155 uint8_t * newData;
156
157 newData = (uint8_t *) malloc( inSize );
158 require_action( newData, exit, err = kNoMemoryErr );
159 memcpy( newData, inData, inSize );
160
161 if( mData )
162 {
163 free( mData );
164 }
165 mData = newData;
166 mSize = inSize;
167 err = kNoErr;
168
169 exit:
170 return( err );
171 }
172 };
173
174 // ResolveInfo
175
176 struct ResolveInfo
177 {
178 CString host;
179 uint16_t port;
180 uint32_t ifi;
181 TextRecord txt;
182 ServiceHandlerEntry * handler;
183 };
184
185 // ServiceHandlerEntry
186
187 struct ServiceHandlerEntry
188 {
189 const char * type;
190 const char * urlScheme;
191 DNSServiceRef ref;
192 ServiceInfoArray array;
193 ExplorerBarWindow * obj;
194 bool needsLogin;
195
196 ServiceHandlerEntry( void )
197 {
198 type = NULL;
199 urlScheme = NULL;
200 ref = NULL;
201 obj = NULL;
202 needsLogin = false;
203 }
204
205 ~ServiceHandlerEntry( void )
206 {
207 int i;
208 int n;
209
210 n = (int) array.GetSize();
211 for( i = 0; i < n; ++i )
212 {
213 delete array[ i ];
214 }
215 }
216 };
217
218 typedef CArray < ServiceHandlerEntry *, ServiceHandlerEntry * > ServiceHandlerArray;
219
220 //===========================================================================================================================
221 // ExplorerBarWindow
222 //===========================================================================================================================
223
224 class ExplorerBar; // Forward Declaration
225
226 class ExplorerBarWindow : public CWnd
227 {
228 protected:
229
230 ExplorerBar * mOwner;
231 CTreeCtrl mTree;
232
233 ServiceHandlerArray mServiceHandlers;
234 DNSServiceRef mResolveServiceRef;
235
236 public:
237
238 ExplorerBarWindow( void );
239 virtual ~ExplorerBarWindow( void );
240
241 protected:
242
243 // General
244
245 afx_msg int OnCreate( LPCREATESTRUCT inCreateStruct );
246 afx_msg void OnDestroy( void );
247 afx_msg void OnSize( UINT inType, int inX, int inY );
248 afx_msg void OnDoubleClick( NMHDR *inNMHDR, LRESULT *outResult );
249 afx_msg LRESULT OnServiceEvent( WPARAM inWParam, LPARAM inLParam );
250
251 // Browsing
252
253 static void DNSSD_API
254 BrowseCallBack(
255 DNSServiceRef inRef,
256 DNSServiceFlags inFlags,
257 uint32_t inInterfaceIndex,
258 DNSServiceErrorType inErrorCode,
259 const char * inName,
260 const char * inType,
261 const char * inDomain,
262 void * inContext );
263 LONG OnServiceAdd( ServiceInfo * service );
264 LONG OnServiceRemove( ServiceInfo * service );
265
266 // Resolving
267
268 OSStatus StartResolve( ServiceInfo *inService );
269 void StopResolve( void );
270
271
272 void Stop( DNSServiceRef ref );
273
274
275 static void DNSSD_API
276 ResolveCallBack(
277 DNSServiceRef inRef,
278 DNSServiceFlags inFlags,
279 uint32_t inInterfaceIndex,
280 DNSServiceErrorType inErrorCode,
281 const char * inFullName,
282 const char * inHostName,
283 uint16_t inPort,
284 uint16_t inTXTSize,
285 const char * inTXT,
286 void * inContext );
287 LONG OnResolve( ResolveInfo * resolve );
288
289 // Accessors
290
291 public:
292
293 ExplorerBar * GetOwner( void ) const { return( mOwner ); }
294 void SetOwner( ExplorerBar *inOwner ) { mOwner = inOwner; }
295
296 DECLARE_MESSAGE_MAP()
297 private:
298
299 typedef std::list< DNSServiceRef > ServiceRefList;
300
301 HTREEITEM m_about;
302 ServiceRefList m_serviceRefs;
303 CImageList m_imageList;
304 };
305
306 #endif // __EXPLORER_BAR_WINDOW__