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