]>
git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/ControlPanel/FirstPage.cpp
1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 Change History (most recent first):
19 $Log: FirstPage.cpp,v $
20 Revision 1.6 2006/08/14 23:25:28 cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
23 Revision 1.5 2005/10/05 20:46:50 herscher
24 <rdar://problem/4192011> Move Wide-Area preferences to another part of the registry so they don't removed during an update-install.
26 Revision 1.4 2005/04/05 03:52:14 shersche
27 <rdar://problem/4066485> Registering with shared secret key doesn't work. Additionally, mDNSResponder wasn't dynamically re-reading it's DynDNS setup after setting a shared secret key.
29 Revision 1.3 2005/03/07 18:27:42 shersche
30 <rdar://problem/4037940> Fix problem when ControlPanel commits changes to the browse domain list
32 Revision 1.2 2005/03/03 19:55:22 shersche
33 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
38 #include "FirstPage.h"
41 #include "ConfigPropertySheet.h"
42 #include "SharedSecret.h"
44 #define MAX_KEY_LENGTH 255
47 IMPLEMENT_DYNCREATE(CFirstPage
, CPropertyPage
)
49 //---------------------------------------------------------------------------------------------------------------------------
50 // CFirstPage::CFirstPage
51 //---------------------------------------------------------------------------------------------------------------------------
53 CFirstPage::CFirstPage()
55 CPropertyPage(CFirstPage::IDD
),
56 m_ignoreHostnameChange( false ),
60 //{{AFX_DATA_INIT(CFirstPage)
65 err
= RegCreateKey( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\DynDNS\\State\\Hostnames", &m_statusKey
);
68 err
= RegCreateKey( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\DynDNS\\Setup\\Hostnames", &m_setupKey
);
72 CFirstPage::~CFirstPage()
76 RegCloseKey( m_statusKey
);
82 RegCloseKey( m_setupKey
);
88 //---------------------------------------------------------------------------------------------------------------------------
89 // CFirstPage::DoDataExchange
90 //---------------------------------------------------------------------------------------------------------------------------
92 void CFirstPage::DoDataExchange(CDataExchange
* pDX
)
94 CPropertyPage::DoDataExchange(pDX
);
95 //{{AFX_DATA_MAP(CFirstPage)
97 DDX_Control(pDX
, IDC_EDIT1
, m_hostnameControl
);
98 DDX_Control(pDX
, IDC_FAILURE
, m_failureIcon
);
99 DDX_Control(pDX
, IDC_SUCCESS
, m_successIcon
);
102 BEGIN_MESSAGE_MAP(CFirstPage
, CPropertyPage
)
103 //{{AFX_MSG_MAP(CFirstPage)
105 ON_BN_CLICKED(IDC_BUTTON1
, OnBnClickedSharedSecret
)
106 ON_EN_CHANGE(IDC_EDIT1
, OnEnChangeHostname
)
110 //---------------------------------------------------------------------------------------------------------------------------
111 // CFirstPage::OnEnChangedHostname
112 //---------------------------------------------------------------------------------------------------------------------------
114 void CFirstPage::OnEnChangeHostname()
116 if ( !m_ignoreHostnameChange
)
123 //---------------------------------------------------------------------------------------------------------------------------
124 // CFirstPage::OnBnClickedSharedSecret
125 //---------------------------------------------------------------------------------------------------------------------------
127 void CFirstPage::OnBnClickedSharedSecret()
131 m_hostnameControl
.GetWindowText( name
);
137 if ( dlg
.DoModal() == IDOK
)
140 DWORD dwSize
= sizeof( DWORD
);
145 // We have now updated the secret, however the system service
146 // doesn't know about it yet. So we're going to update the
147 // registry with a dummy value which will cause the system
148 // service to re-initialize it's DynDNS setup
151 RegQueryValueEx( m_setupKey
, L
"Wakeup", NULL
, NULL
, (LPBYTE
) &wakeup
, &dwSize
);
155 err
= RegSetValueEx( m_setupKey
, L
"Wakeup", 0, REG_DWORD
, (LPBYTE
) &wakeup
, sizeof( DWORD
) );
156 require_noerr( err
, exit
);
165 //---------------------------------------------------------------------------------------------------------------------------
166 // CFirstPage::SetModified
167 //---------------------------------------------------------------------------------------------------------------------------
169 void CFirstPage::SetModified( BOOL bChanged
)
171 m_modified
= bChanged
? true : false;
173 CPropertyPage::SetModified( bChanged
);
177 //---------------------------------------------------------------------------------------------------------------------------
178 // CFirstPage::OnSetActive
179 //---------------------------------------------------------------------------------------------------------------------------
182 CFirstPage::OnSetActive()
184 TCHAR name
[kDNSServiceMaxDomainName
+ 1];
185 DWORD nameLen
= ( kDNSServiceMaxDomainName
+ 1 ) * sizeof( TCHAR
);
188 BOOL b
= CPropertyPage::OnSetActive();
194 err
= RegQueryValueEx( m_setupKey
, L
"", NULL
, NULL
, (LPBYTE
) name
, &nameLen
);
198 m_ignoreHostnameChange
= true;
199 m_hostnameControl
.SetWindowText( name
);
200 m_ignoreHostnameChange
= false;
204 // Check the status of this hostname
213 //---------------------------------------------------------------------------------------------------------------------------
215 //---------------------------------------------------------------------------------------------------------------------------
227 //---------------------------------------------------------------------------------------------------------------------------
228 // CFirstPage::Commit
229 //---------------------------------------------------------------------------------------------------------------------------
238 m_hostnameControl
.GetWindowText( name
);
240 // Convert to lower case
244 // Remove trailing dot
246 name
.TrimRight( '.' );
248 err
= RegSetValueEx( m_setupKey
, L
"", 0, REG_SZ
, (LPBYTE
) (LPCTSTR
) name
, ( name
.GetLength() + 1 ) * sizeof( TCHAR
) );
249 require_noerr( err
, exit
);
251 err
= RegSetValueEx( m_setupKey
, L
"Enabled", 0, REG_DWORD
, (LPBYTE
) &enabled
, sizeof( DWORD
) );
252 require_noerr( err
, exit
);
260 //---------------------------------------------------------------------------------------------------------------------------
261 // CFirstPage::CheckStatus
262 //---------------------------------------------------------------------------------------------------------------------------
265 CFirstPage::CheckStatus()
268 DWORD dwSize
= sizeof( DWORD
);
271 // Get the status field
273 err
= RegQueryValueEx( m_statusKey
, L
"Status", NULL
, NULL
, (LPBYTE
) &status
, &dwSize
);
274 require_noerr( err
, exit
);
276 ShowStatus( status
);
284 //---------------------------------------------------------------------------------------------------------------------------
285 // CFirstPage::ShowStatus
286 //---------------------------------------------------------------------------------------------------------------------------
289 CFirstPage::ShowStatus( DWORD status
)
293 m_failureIcon
.ShowWindow( SW_HIDE
);
294 m_successIcon
.ShowWindow( SW_SHOW
);
298 m_failureIcon
.ShowWindow( SW_SHOW
);
299 m_successIcon
.ShowWindow( SW_HIDE
);
304 //---------------------------------------------------------------------------------------------------------------------------
305 // CFirstPage::OnRegistryChanged
306 //---------------------------------------------------------------------------------------------------------------------------
309 CFirstPage::OnRegistryChanged()