]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/ExplorerPlugin/ExplorerBarWindow.h
mDNSResponder-161.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.8 2006/08/14 23:24:00 cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
22
23 Revision 1.7 2005/02/25 19:57:30 shersche
24 <rdar://problem/4023323> Remove FTP browsing from plugin
25
26 Revision 1.6 2005/01/27 22:27:03 shersche
27 Add m_about member for "About ..." 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 ExplorerBarWindow * obj;
190 bool needsLogin;
191
192 ServiceHandlerEntry( void )
193 {
194 type = NULL;
195 urlScheme = NULL;
196 ref = NULL;
197 obj = NULL;
198 needsLogin = false;
199 }
200
201 ~ServiceHandlerEntry( void )
202 {
203 int i;
204 int n;
205
206 n = (int) array.GetSize();
207 for( i = 0; i < n; ++i )
208 {
209 delete array[ i ];
210 }
211 }
212 };
213
214 typedef CArray < ServiceHandlerEntry *, ServiceHandlerEntry * > ServiceHandlerArray;
215
216 //===========================================================================================================================
217 // ExplorerBarWindow
218 //===========================================================================================================================
219
220 class ExplorerBar; // Forward Declaration
221
222 class ExplorerBarWindow : public CWnd
223 {
224 protected:
225
226 ExplorerBar * mOwner;
227 CTreeCtrl mTree;
228
229 ServiceHandlerArray mServiceHandlers;
230 DNSServiceRef mResolveServiceRef;
231
232 public:
233
234 ExplorerBarWindow( void );
235 virtual ~ExplorerBarWindow( void );
236
237 protected:
238
239 // General
240
241 afx_msg int OnCreate( LPCREATESTRUCT inCreateStruct );
242 afx_msg void OnDestroy( void );
243 afx_msg void OnSize( UINT inType, int inX, int inY );
244 afx_msg void OnDoubleClick( NMHDR *inNMHDR, LRESULT *outResult );
245 afx_msg LONG OnServiceEvent( WPARAM inWParam, LPARAM inLParam );
246
247 // Browsing
248
249 static void DNSSD_API
250 BrowseCallBack(
251 DNSServiceRef inRef,
252 DNSServiceFlags inFlags,
253 uint32_t inInterfaceIndex,
254 DNSServiceErrorType inErrorCode,
255 const char * inName,
256 const char * inType,
257 const char * inDomain,
258 void * inContext );
259 LONG OnServiceAdd( ServiceInfo * service );
260 LONG OnServiceRemove( ServiceInfo * service );
261
262 // Resolving
263
264 OSStatus StartResolve( ServiceInfo *inService );
265 void StopResolve( void );
266
267
268 void Stop( DNSServiceRef ref );
269
270
271 static void DNSSD_API
272 ResolveCallBack(
273 DNSServiceRef inRef,
274 DNSServiceFlags inFlags,
275 uint32_t inInterfaceIndex,
276 DNSServiceErrorType inErrorCode,
277 const char * inFullName,
278 const char * inHostName,
279 uint16_t inPort,
280 uint16_t inTXTSize,
281 const char * inTXT,
282 void * inContext );
283 LONG OnResolve( ResolveInfo * resolve );
284
285 // Accessors
286
287 public:
288
289 ExplorerBar * GetOwner( void ) const { return( mOwner ); }
290 void SetOwner( ExplorerBar *inOwner ) { mOwner = inOwner; }
291
292 DECLARE_MESSAGE_MAP()
293 private:
294
295 typedef std::list< DNSServiceRef > ServiceRefList;
296
297 HTREEITEM m_about;
298 ServiceRefList m_serviceRefs;
299 CImageList m_imageList;
300 };
301
302 #endif // __EXPLORER_BAR_WINDOW__