]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/ControlPanel/FirstPage.cpp
mDNSResponder-107.3.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / ControlPanel / FirstPage.cpp
1 /*
2 * Copyright (c) 2002-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: FirstPage.cpp,v $
26 Revision 1.3 2005/03/07 18:27:42 shersche
27 <rdar://problem/4037940> Fix problem when ControlPanel commits changes to the browse domain list
28
29 Revision 1.2 2005/03/03 19:55:22 shersche
30 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
31
32
33 */
34
35 #include "FirstPage.h"
36 #include "resource.h"
37
38 #include "ConfigPropertySheet.h"
39 #include "SharedSecret.h"
40
41 #define MAX_KEY_LENGTH 255
42
43
44 IMPLEMENT_DYNCREATE(CFirstPage, CPropertyPage)
45
46 //---------------------------------------------------------------------------------------------------------------------------
47 // CFirstPage::CFirstPage
48 //---------------------------------------------------------------------------------------------------------------------------
49
50 CFirstPage::CFirstPage()
51 :
52 CPropertyPage(CFirstPage::IDD),
53 m_ignoreHostnameChange( false ),
54 m_statusKey( NULL )
55 {
56 //{{AFX_DATA_INIT(CFirstPage)
57 //}}AFX_DATA_INIT
58
59 OSStatus err;
60
61 err = RegCreateKey( HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\" kServiceName L"\\Parameters\\DynDNS\\State\\Hostnames", &m_statusKey );
62 check_noerr( err );
63
64 err = RegCreateKey( HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\" kServiceName L"\\Parameters\\DynDNS\\Setup\\Hostnames", &m_setupKey );
65 check_noerr( err );
66 }
67
68 CFirstPage::~CFirstPage()
69 {
70 if ( m_statusKey )
71 {
72 RegCloseKey( m_statusKey );
73 m_statusKey = NULL;
74 }
75
76 if ( m_setupKey )
77 {
78 RegCloseKey( m_setupKey );
79 m_setupKey = NULL;
80 }
81 }
82
83
84 //---------------------------------------------------------------------------------------------------------------------------
85 // CFirstPage::DoDataExchange
86 //---------------------------------------------------------------------------------------------------------------------------
87
88 void CFirstPage::DoDataExchange(CDataExchange* pDX)
89 {
90 CPropertyPage::DoDataExchange(pDX);
91 //{{AFX_DATA_MAP(CFirstPage)
92 //}}AFX_DATA_MAP
93 DDX_Control(pDX, IDC_EDIT1, m_hostnameControl);
94 DDX_Control(pDX, IDC_FAILURE, m_failureIcon);
95 DDX_Control(pDX, IDC_SUCCESS, m_successIcon);
96 }
97
98 BEGIN_MESSAGE_MAP(CFirstPage, CPropertyPage)
99 //{{AFX_MSG_MAP(CFirstPage)
100 //}}AFX_MSG_MAP
101 ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedSharedSecret)
102 ON_EN_CHANGE(IDC_EDIT1, OnEnChangeHostname)
103 END_MESSAGE_MAP()
104
105
106 //---------------------------------------------------------------------------------------------------------------------------
107 // CFirstPage::OnEnChangedHostname
108 //---------------------------------------------------------------------------------------------------------------------------
109
110 void CFirstPage::OnEnChangeHostname()
111 {
112 if ( !m_ignoreHostnameChange )
113 {
114 SetModified( TRUE );
115 }
116 }
117
118
119 //---------------------------------------------------------------------------------------------------------------------------
120 // CFirstPage::OnBnClickedSharedSecret
121 //---------------------------------------------------------------------------------------------------------------------------
122
123 void CFirstPage::OnBnClickedSharedSecret()
124 {
125 CString name;
126
127 m_hostnameControl.GetWindowText( name );
128
129 CSharedSecret dlg;
130
131 dlg.m_secretName = name;
132
133 if ( dlg.DoModal() == IDOK )
134 {
135 dlg.Commit();
136 }
137 }
138
139
140 //---------------------------------------------------------------------------------------------------------------------------
141 // CFirstPage::SetModified
142 //---------------------------------------------------------------------------------------------------------------------------
143
144 void CFirstPage::SetModified( BOOL bChanged )
145 {
146 m_modified = bChanged ? true : false;
147
148 CPropertyPage::SetModified( bChanged );
149 }
150
151
152 //---------------------------------------------------------------------------------------------------------------------------
153 // CFirstPage::OnSetActive
154 //---------------------------------------------------------------------------------------------------------------------------
155
156 BOOL
157 CFirstPage::OnSetActive()
158 {
159 TCHAR name[kDNSServiceMaxDomainName + 1];
160 DWORD nameLen = ( kDNSServiceMaxDomainName + 1 ) * sizeof( TCHAR );
161 DWORD err;
162
163 BOOL b = CPropertyPage::OnSetActive();
164
165 m_modified = FALSE;
166
167 if ( m_setupKey )
168 {
169 err = RegQueryValueEx( m_setupKey, L"", NULL, NULL, (LPBYTE) name, &nameLen );
170
171 if ( !err )
172 {
173 m_ignoreHostnameChange = true;
174 m_hostnameControl.SetWindowText( name );
175 m_ignoreHostnameChange = false;
176 }
177 }
178
179 // Check the status of this hostname
180
181 err = CheckStatus();
182 check_noerr( err );
183
184 return b;
185 }
186
187
188 //---------------------------------------------------------------------------------------------------------------------------
189 // CFirstPage::OnOK
190 //---------------------------------------------------------------------------------------------------------------------------
191
192 void
193 CFirstPage::OnOK()
194 {
195 if ( m_modified )
196 {
197 Commit();
198 }
199 }
200
201
202 //---------------------------------------------------------------------------------------------------------------------------
203 // CFirstPage::Commit
204 //---------------------------------------------------------------------------------------------------------------------------
205
206 void
207 CFirstPage::Commit()
208 {
209 DWORD enabled = 1;
210 CString name;
211 DWORD err;
212
213 m_hostnameControl.GetWindowText( name );
214
215 // Convert to lower case
216
217 name.MakeLower();
218
219 // Remove trailing dot
220
221 name.TrimRight( '.' );
222
223 err = RegSetValueEx( m_setupKey, L"", 0, REG_SZ, (LPBYTE) (LPCTSTR) name, ( name.GetLength() + 1 ) * sizeof( TCHAR ) );
224 require_noerr( err, exit );
225
226 err = RegSetValueEx( m_setupKey, L"Enabled", 0, REG_DWORD, (LPBYTE) &enabled, sizeof( DWORD ) );
227 require_noerr( err, exit );
228
229 exit:
230
231 return;
232 }
233
234
235 //---------------------------------------------------------------------------------------------------------------------------
236 // CFirstPage::CheckStatus
237 //---------------------------------------------------------------------------------------------------------------------------
238
239 OSStatus
240 CFirstPage::CheckStatus()
241 {
242 DWORD status = 0;
243 DWORD dwSize = sizeof( DWORD );
244 OSStatus err;
245
246 // Get the status field
247
248 err = RegQueryValueEx( m_statusKey, L"Status", NULL, NULL, (LPBYTE) &status, &dwSize );
249 require_noerr( err, exit );
250
251 ShowStatus( status );
252
253 exit:
254
255 return kNoErr;
256 }
257
258
259 //---------------------------------------------------------------------------------------------------------------------------
260 // CFirstPage::ShowStatus
261 //---------------------------------------------------------------------------------------------------------------------------
262
263 void
264 CFirstPage::ShowStatus( DWORD status )
265 {
266 if ( status )
267 {
268 m_failureIcon.ShowWindow( SW_HIDE );
269 m_successIcon.ShowWindow( SW_SHOW );
270 }
271 else
272 {
273 m_failureIcon.ShowWindow( SW_SHOW );
274 m_successIcon.ShowWindow( SW_HIDE );
275 }
276 }
277
278
279 //---------------------------------------------------------------------------------------------------------------------------
280 // CFirstPage::OnRegistryChanged
281 //---------------------------------------------------------------------------------------------------------------------------
282
283 void
284 CFirstPage::OnRegistryChanged()
285 {
286 CheckStatus();
287 }