]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/ExplorerPlugin/ExplorerBarWindow.h
mDNSResponder-379.27.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
18 #ifndef __EXPLORER_BAR_WINDOW__
19 #define __EXPLORER_BAR_WINDOW__
20
21 #pragma once
22
23 #include "afxtempl.h"
24
25 #include "dns_sd.h"
26 #include <list>
27
28 //===========================================================================================================================
29 // Structures
30 //===========================================================================================================================
31
32 // Forward Declarations
33
34 struct ServiceHandlerEntry;
35 class ExplorerBarWindow;
36
37 // ServiceInfo
38
39 struct ServiceInfo
40 {
41 CString displayName;
42 char * name;
43 char * type;
44 char * domain;
45 uint32_t ifi;
46 HTREEITEM item;
47 ServiceHandlerEntry * handler;
48 DWORD refs;
49
50 ServiceInfo( void )
51 {
52 item = NULL;
53 type = NULL;
54 domain = NULL;
55 handler = NULL;
56 }
57
58 ~ServiceInfo( void )
59 {
60 if( name )
61 {
62 free( name );
63 }
64 if( type )
65 {
66 free( type );
67 }
68 if( domain )
69 {
70 free( domain );
71 }
72 }
73 };
74
75 typedef CArray < ServiceInfo *, ServiceInfo * > ServiceInfoArray;
76
77 // TextRecord
78
79 struct TextRecord
80 {
81 uint8_t * mData;
82 uint16_t mSize;
83
84 TextRecord( void )
85 {
86 mData = NULL;
87 mSize = 0;
88 }
89
90 ~TextRecord( void )
91 {
92 if( mData )
93 {
94 free( mData );
95 }
96 }
97
98 void GetData( void *outData, uint16_t *outSize )
99 {
100 if( outData )
101 {
102 *( (void **) outData ) = mData;
103 }
104 if( outSize )
105 {
106 *outSize = mSize;
107 }
108 }
109
110 OSStatus SetData( const void *inData, uint16_t inSize )
111 {
112 OSStatus err;
113 uint8_t * newData;
114
115 newData = (uint8_t *) malloc( inSize );
116 require_action( newData, exit, err = kNoMemoryErr );
117 memcpy( newData, inData, inSize );
118
119 if( mData )
120 {
121 free( mData );
122 }
123 mData = newData;
124 mSize = inSize;
125 err = kNoErr;
126
127 exit:
128 return( err );
129 }
130 };
131
132 // ResolveInfo
133
134 struct ResolveInfo
135 {
136 CString host;
137 uint16_t port;
138 uint32_t ifi;
139 TextRecord txt;
140 ServiceHandlerEntry * handler;
141 };
142
143 // ServiceHandlerEntry
144
145 struct ServiceHandlerEntry
146 {
147 const char * type;
148 const char * urlScheme;
149 DNSServiceRef ref;
150 ServiceInfoArray array;
151 ExplorerBarWindow * obj;
152 bool needsLogin;
153
154 ServiceHandlerEntry( void )
155 {
156 type = NULL;
157 urlScheme = NULL;
158 ref = NULL;
159 obj = NULL;
160 needsLogin = false;
161 }
162
163 ~ServiceHandlerEntry( void )
164 {
165 int i;
166 int n;
167
168 n = (int) array.GetSize();
169 for( i = 0; i < n; ++i )
170 {
171 delete array[ i ];
172 }
173 }
174 };
175
176 typedef CArray < ServiceHandlerEntry *, ServiceHandlerEntry * > ServiceHandlerArray;
177
178 //===========================================================================================================================
179 // ExplorerBarWindow
180 //===========================================================================================================================
181
182 class ExplorerBar; // Forward Declaration
183
184 class ExplorerBarWindow : public CWnd
185 {
186 protected:
187
188 ExplorerBar * mOwner;
189 CTreeCtrl mTree;
190
191 ServiceHandlerArray mServiceHandlers;
192 DNSServiceRef mResolveServiceRef;
193
194 public:
195
196 ExplorerBarWindow( void );
197 virtual ~ExplorerBarWindow( void );
198
199 protected:
200
201 // General
202
203 afx_msg int OnCreate( LPCREATESTRUCT inCreateStruct );
204 afx_msg void OnDestroy( void );
205 afx_msg void OnSize( UINT inType, int inX, int inY );
206 afx_msg void OnDoubleClick( NMHDR *inNMHDR, LRESULT *outResult );
207 afx_msg LRESULT OnServiceEvent( WPARAM inWParam, LPARAM inLParam );
208
209 // Browsing
210
211 static void DNSSD_API
212 BrowseCallBack(
213 DNSServiceRef inRef,
214 DNSServiceFlags inFlags,
215 uint32_t inInterfaceIndex,
216 DNSServiceErrorType inErrorCode,
217 const char * inName,
218 const char * inType,
219 const char * inDomain,
220 void * inContext );
221 LONG OnServiceAdd( ServiceInfo * service );
222 LONG OnServiceRemove( ServiceInfo * service );
223
224 // Resolving
225
226 OSStatus StartResolve( ServiceInfo *inService );
227 void StopResolve( void );
228
229
230 void Stop( DNSServiceRef ref );
231
232
233 static void DNSSD_API
234 ResolveCallBack(
235 DNSServiceRef inRef,
236 DNSServiceFlags inFlags,
237 uint32_t inInterfaceIndex,
238 DNSServiceErrorType inErrorCode,
239 const char * inFullName,
240 const char * inHostName,
241 uint16_t inPort,
242 uint16_t inTXTSize,
243 const char * inTXT,
244 void * inContext );
245 LONG OnResolve( ResolveInfo * resolve );
246
247 // Accessors
248
249 public:
250
251 ExplorerBar * GetOwner( void ) const { return( mOwner ); }
252 void SetOwner( ExplorerBar *inOwner ) { mOwner = inOwner; }
253
254 DECLARE_MESSAGE_MAP()
255 private:
256
257 typedef std::list< DNSServiceRef > ServiceRefList;
258
259 HTREEITEM m_about;
260 ServiceRefList m_serviceRefs;
261 CImageList m_imageList;
262 };
263
264 #endif // __EXPLORER_BAR_WINDOW__