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