]> git.saurik.com Git - apple/mdnsresponder.git/blobdiff - mDNSWindows/ControlPanel/ConfigPropertySheet.cpp
mDNSResponder-544.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / ControlPanel / ConfigPropertySheet.cpp
index bcf0f7a0cd0ba07edc01b11d00f153d01071f5eb..5fae9555268d2da87df0e5affb5089e4f0411a44 100755 (executable)
  * 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.
-
-    Change History (most recent first):
-
-$Log: ConfigPropertySheet.cpp,v $
-Revision 1.5  2006/08/14 23:25:28  cheshire
-Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
-
-Revision 1.4  2005/10/05 20:46:50  herscher
-<rdar://problem/4192011> Move Wide-Area preferences to another part of the registry so they don't removed during an update-install.
-
-Revision 1.3  2005/03/03 19:55:22  shersche
-<rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
-
-
-*/
+ */
 
 #include "ConfigPropertySheet.h"
 #include <WinServices.h>
+extern "C"
+{
+#include <ClientCommon.h>
+}
 #include <process.h>
 
 // Custom events
 
 #define WM_DATAREADY           ( WM_USER + 0x100 )
-#define WM_REGISTRYCHANGED     ( WM_USER + 0x101 )
 
 
 IMPLEMENT_DYNCREATE(CConfigPropertySheet, CPropertySheet)
@@ -50,11 +39,10 @@ CConfigPropertySheet::CConfigPropertySheet()
 :
        CPropertySheet(),
        m_browseDomainsRef( NULL ),
-       m_regDomainsRef( NULL ),
        m_thread( NULL ),
        m_threadExited( NULL )
 {
-       AddPage(&m_firstPage);
+       AddPage(&m_firstPage );
        AddPage(&m_secondPage);
        AddPage(&m_thirdPage);
 
@@ -76,7 +64,6 @@ BEGIN_MESSAGE_MAP(CConfigPropertySheet, CPropertySheet)
        //{{AFX_MSG_MAP(CConfigPropertySheet)
        //}}AFX_MSG_MAP
        ON_MESSAGE( WM_DATAREADY, OnDataReady )
-       ON_MESSAGE( WM_REGISTRYCHANGED, OnRegistryChanged )
 END_MESSAGE_MAP()
 
 
@@ -94,9 +81,6 @@ CConfigPropertySheet::OnInitDialog()
        err = SetupBrowsing();
        require_noerr( err, exit );
 
-       err = SetupRegistryNotifications();
-       require_noerr( err, exit );     
-
 exit:
 
        return b;
@@ -125,7 +109,7 @@ CConfigPropertySheet::OnCommand(WPARAM wParam, LPARAM lParam)
 //     CConfigPropertySheet::OnDataReady
 //---------------------------------------------------------------------------------------------------------------------------
 
-LONG
+LRESULT
 CConfigPropertySheet::OnDataReady(WPARAM inWParam, LPARAM inLParam)
 {
        if (WSAGETSELECTERROR(inLParam) && !(HIWORD(inLParam)))
@@ -140,29 +124,6 @@ CConfigPropertySheet::OnDataReady(WPARAM inWParam, LPARAM inLParam)
                {
                        DNSServiceProcessResult( m_browseDomainsRef );
                }
-               else if ( m_regDomainsRef && DNSServiceRefSockFD( m_regDomainsRef ) == (int) sock )
-               {
-                       DNSServiceProcessResult( m_regDomainsRef );
-               }
-       }
-
-       return 0;
-}
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-//     CConfigPropertySheet::OnRegistryChanged
-//---------------------------------------------------------------------------------------------------------------------------
-
-afx_msg LONG
-CConfigPropertySheet::OnRegistryChanged( WPARAM inWParam, LPARAM inLParam )
-{
-       DEBUG_UNUSED( inWParam );
-       DEBUG_UNUSED( inLParam );
-
-       if ( GetActivePage() == &m_firstPage )
-       {
-               m_firstPage.OnRegistryChanged();
        }
 
        return 0;
@@ -178,9 +139,6 @@ CConfigPropertySheet::OnEndDialog()
 {
        OSStatus err;
 
-       err = TearDownRegistryNotifications();
-       check_noerr( err );
-
        err = TearDownBrowsing();
        check_noerr( err );
 }
@@ -203,14 +161,6 @@ CConfigPropertySheet::SetupBrowsing()
        err = WSAAsyncSelect( DNSServiceRefSockFD( m_browseDomainsRef ), m_hWnd, WM_DATAREADY, FD_READ|FD_CLOSE );
        require_noerr( err, exit );
 
-       // Start browsing for registration domains
-
-       err = DNSServiceEnumerateDomains( &m_regDomainsRef, kDNSServiceFlagsRegistrationDomains, 0, RegDomainsReply, this );
-       require_noerr( err, exit );
-
-       err = WSAAsyncSelect( DNSServiceRefSockFD( m_regDomainsRef ), m_hWnd, WM_DATAREADY, FD_READ|FD_CLOSE );
-       require_noerr( err, exit );
-
 exit:
 
        if ( err )
@@ -241,97 +191,6 @@ CConfigPropertySheet::TearDownBrowsing()
                m_browseDomainsRef = NULL;
        }
 
-       if ( m_regDomainsRef )
-       {
-               err = WSAAsyncSelect( DNSServiceRefSockFD( m_regDomainsRef ), m_hWnd, 0, 0 );
-               check_noerr( err );
-
-               DNSServiceRefDeallocate( m_regDomainsRef );
-       
-               m_regDomainsRef = NULL;
-       }
-
-       return err;
-}
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-//     CConfigPropertySheet::SetupRegistryNotifications
-//---------------------------------------------------------------------------------------------------------------------------
-
-OSStatus
-CConfigPropertySheet::SetupRegistryNotifications()
-{
-       unsigned int    threadId;
-       OSStatus                err;
-
-       check( m_threadExited == NULL );
-       check( m_thread == NULL );
-
-       err = RegCreateKey( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\DynDNS\\State\\Hostnames", &m_statusKey );
-       require_noerr( err, exit );
-       
-       m_threadExited = CreateEvent( NULL, FALSE, FALSE, NULL );
-       err = translate_errno( m_threadExited, (OSStatus) GetLastError(), kUnknownErr );
-       require_noerr( err, exit );
-
-       // Create thread with _beginthreadex() instead of CreateThread() to avoid memory leaks when using static run-time 
-       // libraries. See <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createthread.asp>.
-       
-       m_thread = (HANDLE) _beginthreadex_compat( NULL, 0, WatchRegistry, this, 0, &threadId );
-       err = translate_errno( m_thread, (OSStatus) GetLastError(), kUnknownErr );
-       require_noerr( err, exit );
-
-exit:
-
-       if ( err )
-       {
-               TearDownRegistryNotifications();
-       }
-
-       return err;
-}
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-//     CConfigPropertySheet::TearDownRegistryNotifications
-//---------------------------------------------------------------------------------------------------------------------------
-
-OSStatus
-CConfigPropertySheet::TearDownRegistryNotifications()
-{
-       OSStatus err = kNoErr;
-
-       if ( m_statusKey )
-       {
-               EnterCriticalSection( &m_lock );
-
-               RegCloseKey( m_statusKey );
-               m_statusKey = NULL;
-
-               LeaveCriticalSection( &m_lock );
-       }
-
-       if ( m_threadExited )
-       {
-               err = WaitForSingleObject( m_threadExited, 5 * 1000 );
-               require_noerr( err, exit );
-       }
-
-exit:
-
-       if ( m_threadExited )
-       {
-               CloseHandle( m_threadExited );
-               m_threadExited = NULL;
-       }
-
-       if ( m_thread )
-       {
-               CloseHandle( m_thread );
-               m_thread = NULL;
-       }
-
        return err;
 }
 
@@ -384,38 +243,6 @@ CConfigPropertySheet::DecodeDomainName( const char * raw, CString & decoded )
 }
 
 
-//---------------------------------------------------------------------------------------------------------------------------
-//     CConfigPropertySheet::GetNextLabel
-//---------------------------------------------------------------------------------------------------------------------------
-
-const char*
-CConfigPropertySheet::GetNextLabel( const char * cstr, char label[64] )
-{
-       char *ptr = label;
-       while (*cstr && *cstr != '.')                                                           // While we have characters in the label...
-               {
-               char c = *cstr++;
-               if (c == '\\')
-                       {
-                       c = *cstr++;
-                       if (isdigit(cstr[-1]) && isdigit(cstr[0]) && isdigit(cstr[1]))
-                               {
-                               int v0 = cstr[-1] - '0';                                                // then interpret as three-digit decimal
-                               int v1 = cstr[ 0] - '0';
-                               int v2 = cstr[ 1] - '0';
-                               int val = v0 * 100 + v1 * 10 + v2;
-                               if (val <= 255) { c = (char)val; cstr += 2; }   // If valid three-digit decimal value, use it
-                               }
-                       }
-               *ptr++ = c;
-               if (ptr >= label+64) return(NULL);
-               }
-       if (*cstr) cstr++;                                                                                      // Skip over the trailing dot (if present)
-       *ptr++ = 0;
-       return(cstr);
-}
-
-
 //---------------------------------------------------------------------------------------------------------------------------
 //     CConfigPropertySheet::BrowseDomainsReply
 //---------------------------------------------------------------------------------------------------------------------------
@@ -452,8 +279,6 @@ CConfigPropertySheet::BrowseDomainsReply
                goto exit;
        }
 
-
-
        err = self->DecodeDomainName( replyDomain, decoded );
        require_noerr( err, exit );
 
@@ -474,105 +299,3 @@ exit:
 
        return;
 }
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-//     CConfigPropertySheet::RegDomainsReply
-//---------------------------------------------------------------------------------------------------------------------------
-
-void DNSSD_API
-CConfigPropertySheet::RegDomainsReply
-                                                       (
-                                                       DNSServiceRef                   sdRef,
-                                                       DNSServiceFlags                 flags,
-                                                       uint32_t                                interfaceIndex,
-                                                       DNSServiceErrorType             errorCode,
-                                                       const char                      *       replyDomain,
-                                                       void                            *       context
-                                                       )
-{
-       CConfigPropertySheet    *       self = reinterpret_cast<CConfigPropertySheet*>(context);
-       CString                                         decoded;
-       OSStatus                                        err;
-
-       DEBUG_UNUSED( sdRef );
-       DEBUG_UNUSED( interfaceIndex );
-
-       if ( errorCode )
-       {
-               goto exit;
-       }
-
-       check( replyDomain );
-       
-       // Ignore local domains
-
-       if ( strcmp( replyDomain, "local." ) == 0 )
-       {
-               goto exit;
-       }
-
-       err = self->DecodeDomainName( replyDomain, decoded );
-       require_noerr( err, exit );
-
-       // Remove trailing '.'
-
-       decoded.TrimRight( '.' );
-
-       if ( flags & kDNSServiceFlagsAdd )
-       {
-               if ( self->GetActivePage() == &self->m_secondPage )
-               {
-                       self->m_secondPage.OnAddRegistrationDomain( decoded );
-               }
-
-               self->m_regDomains.push_back( decoded );
-       }
-       else
-       {
-               if ( self->GetActivePage() == &self->m_secondPage )
-               {
-                       self->m_secondPage.OnRemoveRegistrationDomain( decoded );
-               }
-
-               self->m_regDomains.remove( decoded );
-       }
-
-exit:
-
-       return;
-}
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-//     CConfigPropertySheet::WatchRegistry
-//---------------------------------------------------------------------------------------------------------------------------
-
-unsigned WINAPI
-CConfigPropertySheet::WatchRegistry ( LPVOID inParam )
-{
-       bool done = false;
-
-       CConfigPropertySheet * self = reinterpret_cast<CConfigPropertySheet*>(inParam);
-       check( self );
-
-       while ( !done )
-       {
-               RegNotifyChangeKeyValue( self->m_statusKey, TRUE, REG_NOTIFY_CHANGE_LAST_SET, NULL, FALSE );
-
-               EnterCriticalSection( &self->m_lock );
-
-               done = ( self->m_statusKey == NULL ) ? true : false;
-
-               if ( !done )
-               {
-                       self->PostMessage( WM_REGISTRYCHANGED, 0, 0 );
-               }
-
-               LeaveCriticalSection( &self->m_lock );
-       }
-
-       SetEvent( self->m_threadExited );
-
-       return 0;
-}