-/*
+/* -*- Mode: C; tab-width: 4 -*-
+ *
* Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
* limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
-
- Change History (most recent first):
-
-$Log: SecondPage.cpp,v $
-Revision 1.5 2005/04/05 04:15:46 shersche
-RegQueryString was returning uninitialized strings if the registry key couldn't be found, so always initialize strings before checking the registry key.
-
-Revision 1.4 2005/04/05 03:52:14 shersche
-<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.
-
-Revision 1.3 2005/03/03 19:55:22 shersche
-<rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
-
-
-*/
+ */
#include "SecondPage.h"
#include "resource.h"
#include <WinServices.h>
+#define MAX_KEY_LENGTH 255
+
IMPLEMENT_DYNCREATE(CSecondPage, CPropertyPage)
OSStatus err;
- err = RegCreateKey( HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\" kServiceName L"\\Parameters\\DynDNS\\Setup\\" kServiceDynDNSRegistrationDomains, &m_setupKey );
+ err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\DynDNS\\Setup\\" kServiceDynDNSRegistrationDomains, 0,
+ NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &m_setupKey, NULL );
check_noerr( err );
}
CSecondPage::OnSetActive()
{
CConfigPropertySheet * psheet;
- DWORD dwSize;
- DWORD enabled;
DWORD err;
BOOL b = CPropertyPage::OnSetActive();
err = Populate( m_regDomainsBox, m_setupKey, psheet->m_regDomains );
check_noerr( err );
- dwSize = sizeof( DWORD );
- err = RegQueryValueEx( m_setupKey, L"Enabled", NULL, NULL, (LPBYTE) &enabled, &dwSize );
- m_advertiseServicesButton.SetCheck( ( !err && enabled ) ? BST_CHECKED : BST_UNCHECKED );
- m_regDomainsBox.EnableWindow( ( !err && enabled ) );
- m_sharedSecretButton.EnableWindow( (!err && enabled ) );
-
exit:
return b;
CSecondPage::Commit( CComboBox & box, HKEY key, DWORD enabled )
{
CString selected;
+ HKEY subKey = NULL;
+ TCHAR subKeyName[MAX_KEY_LENGTH];
+ DWORD cSubKeys = 0;
+ DWORD cbMaxSubKey;
+ DWORD cchMaxClass;
+ DWORD dwSize;
+ int i;
OSStatus err = kNoErr;
+ // First, remove all the entries that are there
+
+ err = RegQueryInfoKey( key, NULL, NULL, NULL, &cSubKeys, &cbMaxSubKey, &cchMaxClass, NULL, NULL, NULL, NULL, NULL );
+ require_noerr( err, exit );
+
+ for ( i = 0; i < (int) cSubKeys; i++ )
+ {
+ dwSize = MAX_KEY_LENGTH;
+
+ err = RegEnumKeyEx( key, 0, subKeyName, &dwSize, NULL, NULL, NULL, NULL );
+ require_noerr( err, exit );
+
+ err = RegDeleteKey( key, subKeyName );
+ require_noerr( err, exit );
+ }
+
// Get selected text
box.GetWindowText( selected );
// Save selected text in registry. This will trigger mDNSResponder to setup
// DynDNS config again
- err = RegSetValueEx( key, L"", 0, REG_SZ, (LPBYTE) (LPCTSTR) selected, ( selected.GetLength() + 1 ) * sizeof( TCHAR ) );
- check_noerr( err );
+ err = RegCreateKeyEx( key, selected, 0,
+ NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &subKey, NULL );
+ require_noerr( err, exit );
- err = RegSetValueEx( key, L"Enabled", 0, REG_DWORD, (LPBYTE) &enabled, sizeof( DWORD ) );
+ err = RegSetValueEx( subKey, L"Enabled", 0, REG_DWORD, (LPBYTE) &enabled, sizeof( DWORD ) );
check_noerr( err );
+exit:
+
+ if ( subKey )
+ {
+ RegCloseKey( subKey );
+ subKey = NULL;
+ }
+
return err;
}
CSharedSecret dlg;
- dlg.m_key = name;
+ dlg.Load( name );
if ( dlg.DoModal() == IDOK )
{
OSStatus
CSecondPage::Populate( CComboBox & box, HKEY key, StringList & l )
{
- TCHAR rawString[kDNSServiceMaxDomainName + 1];
- DWORD rawStringLen;
CString string;
+ HKEY subKey = NULL;
+ DWORD dwSize;
+ DWORD enabled = 0;
+ TCHAR subKeyName[MAX_KEY_LENGTH];
+ DWORD cSubKeys = 0;
+ DWORD cbMaxSubKey;
+ DWORD cchMaxClass;
OSStatus err;
err = RegQueryString( key, L"UserDefined", string );
}
}
- // Now look to see if there is a selected string, and if so,
- // select it
+ err = RegQueryInfoKey( key, NULL, NULL, NULL, &cSubKeys, &cbMaxSubKey, &cchMaxClass, NULL, NULL, NULL, NULL, NULL );
+ require_noerr( err, exit );
- rawString[0] = '\0';
+ if ( cSubKeys > 0 )
+ {
+ dwSize = MAX_KEY_LENGTH;
+
+ err = RegEnumKeyEx( key, 0, subKeyName, &dwSize, NULL, NULL, NULL, NULL );
+ require_noerr( err, exit );
- rawStringLen = sizeof( rawString );
+ err = RegOpenKey( key, subKeyName, &subKey );
+ require_noerr( err, exit );
- err = RegQueryValueEx( key, L"", 0, NULL, (LPBYTE) rawString, &rawStringLen );
+ dwSize = sizeof( DWORD );
+ err = RegQueryValueEx( subKey, L"Enabled", NULL, NULL, (LPBYTE) &enabled, &dwSize );
+ require_noerr( err, exit );
- string = rawString;
-
- if ( !err && ( string.GetLength() != 0 ) )
- {
// See if it's there
- if ( box.SelectString( -1, string ) == CB_ERR )
+ if ( box.SelectString( -1, subKeyName ) == CB_ERR )
{
// If not, add it
- box.AddString( string );
+ box.AddString( subKeyName );
}
- box.SelectString( -1, string );
+ box.SelectString( -1, subKeyName );
+
+ RegCloseKey( subKey );
+ subKey = NULL;
}
+exit:
+
+ m_advertiseServicesButton.SetCheck( ( !err && enabled ) ? BST_CHECKED : BST_UNCHECKED );
+ m_regDomainsBox.EnableWindow( ( !err && enabled ) );
+ m_sharedSecretButton.EnableWindow( (!err && enabled ) );
+
return err;
}
HKEY key = NULL;
OSStatus err;
- err = RegCreateKey( HKEY_LOCAL_MACHINE, (LPCTSTR) name, &key );
+ err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, (LPCTSTR) name, 0,
+ NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &key, NULL );
require_noerr( err, exit );
err = RegSetValueEx( key, L"Enabled", 0, REG_DWORD, (LPBYTE) &enabled, sizeof( DWORD ) );