]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/ExplorerPlugin/ExplorerBarWindow.h
mDNSResponder-98.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.6 2005/01/27 22:27:03 shersche
27 Add m_about member for "About Rendezvous" tree item
28
29 Revision 1.5 2004/07/26 05:47:31 shersche
30 use TXTRecord APIs, fix bug in locating service to be removed
31
32 Revision 1.4 2004/07/20 06:49:18 shersche
33 clean up socket handling code
34
35 Revision 1.3 2004/07/13 21:24:21 rpantos
36 Fix for <rdar://problem/3701120>.
37
38 Revision 1.2 2004/06/27 14:59:59 shersche
39 reference count service info to handle multi-homed hosts
40
41 Revision 1.1 2004/06/18 04:34:59 rpantos
42 Move to Clients from mDNSWindows
43
44 Revision 1.3 2004/04/15 01:00:05 bradley
45 Removed support for automatically querying for A/AAAA records when resolving names. Platforms
46 without .local name resolving support will need to manually query for A/AAAA records as needed.
47
48 Revision 1.2 2004/04/08 09:43:43 bradley
49 Changed callback calling conventions to __stdcall so they can be used with C# delegates.
50
51 Revision 1.1 2004/01/30 03:01:56 bradley
52 Explorer Plugin to browse for DNS-SD advertised Web and FTP servers from within Internet Explorer.
53
54 */
55
56 #ifndef __EXPLORER_BAR_WINDOW__
57 #define __EXPLORER_BAR_WINDOW__
58
59 #pragma once
60
61 #include "afxtempl.h"
62
63 #include "dns_sd.h"
64 #include <list>
65
66 //===========================================================================================================================
67 // Structures
68 //===========================================================================================================================
69
70 // Forward Declarations
71
72 struct ServiceHandlerEntry;
73 class ExplorerBarWindow;
74
75 // ServiceInfo
76
77 struct ServiceInfo
78 {
79 CString displayName;
80 char * name;
81 char * type;
82 char * domain;
83 uint32_t ifi;
84 HTREEITEM item;
85 ServiceHandlerEntry * handler;
86 DWORD refs;
87
88 ServiceInfo( void )
89 {
90 item = NULL;
91 type = NULL;
92 domain = NULL;
93 handler = NULL;
94 }
95
96 ~ServiceInfo( void )
97 {
98 if( name )
99 {
100 free( name );
101 }
102 if( type )
103 {
104 free( type );
105 }
106 if( domain )
107 {
108 free( domain );
109 }
110 }
111 };
112
113 typedef CArray < ServiceInfo *, ServiceInfo * > ServiceInfoArray;
114
115 // TextRecord
116
117 struct TextRecord
118 {
119 uint8_t * mData;
120 uint16_t mSize;
121
122 TextRecord( void )
123 {
124 mData = NULL;
125 mSize = 0;
126 }
127
128 ~TextRecord( void )
129 {
130 if( mData )
131 {
132 free( mData );
133 }
134 }
135
136 void GetData( void *outData, uint16_t *outSize )
137 {
138 if( outData )
139 {
140 *( (void **) outData ) = mData;
141 }
142 if( outSize )
143 {
144 *outSize = mSize;
145 }
146 }
147
148 OSStatus SetData( const void *inData, uint16_t inSize )
149 {
150 OSStatus err;
151 uint8_t * newData;
152
153 newData = (uint8_t *) malloc( inSize );
154 require_action( newData, exit, err = kNoMemoryErr );
155 memcpy( newData, inData, inSize );
156
157 if( mData )
158 {
159 free( mData );
160 }
161 mData = newData;
162 mSize = inSize;
163 err = kNoErr;
164
165 exit:
166 return( err );
167 }
168 };
169
170 // ResolveInfo
171
172 struct ResolveInfo
173 {
174 CString host;
175 uint16_t port;
176 uint32_t ifi;
177 TextRecord txt;
178 ServiceHandlerEntry * handler;
179 };
180
181 // ServiceHandlerEntry
182
183 struct ServiceHandlerEntry
184 {
185 const char * type;
186 const char * urlScheme;
187 DNSServiceRef ref;
188 ServiceInfoArray array;
189 HTREEITEM treeItem;
190 bool treeFirst;
191 ExplorerBarWindow * obj;
192 bool needsLogin;
193
194 ServiceHandlerEntry( void )
195 {
196 type = NULL;
197 urlScheme = NULL;
198 ref = NULL;
199 treeItem = NULL;
200 treeFirst = true;
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 LONG 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__