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