void	DNSServiceDiscoveryDeallocate( dns_service_discovery_ref inRef )
{
	_dns_service_discovery_t *		obj;
	DNSStatus						err;
	
	check( inRef );
	check( inRef->ref );
	
	obj = (_dns_service_discovery_t *) inRef;
	switch( obj->type )
	{
		case kDNSServiceDiscoveryObjectTypeRegistration:
			if( inRef->ref )
			{
				err = DNSRegistrationRelease( (DNSRegistrationRef) inRef->ref, 0 );
				check_noerr( err );
			}
			free( inRef );
			break;
		
		case kDNSServiceDiscoveryObjectTypeDomainEnumeration:
			if( inRef->ref )
			{
				err = DNSBrowserRelease( (DNSBrowserRef) inRef->ref, 0 );
				check_noerr( err );
			}
			free( inRef );
			break;
		
		case kDNSServiceDiscoveryObjectTypeBrowser:
			if( inRef->ref )
			{
				err = DNSBrowserRelease( (DNSBrowserRef) inRef->ref, 0 );
				check_noerr( err );
			}
			free( inRef );
			break;
		
		case kDNSServiceDiscoveryObjectTypeResolver:
			if( inRef->ref )
			{
				err = DNSResolverRelease( (DNSResolverRef) inRef->ref, 0 );
				check_noerr( err );
			}
			free( inRef );
			break;
		
		default:
			debugf( DEBUG_NAME "unknown object type (%d)\n", obj->type );
			break;
	}
}
dns_service_discovery_ref
	DNSServiceDomainEnumerationCreate(
		int 								inRegistrationDomains,
		DNSServiceDomainEnumerationReply	inCallBack,
		void *								inContext )
{
	DNSStatus						err;
	dns_service_discovery_ref		result;
	dns_service_discovery_ref		obj;
	DNSBrowserRef					browser;
	DNSBrowserFlags					flags;
	
	result 	= NULL;
	browser	= NULL;
	
	// Allocate and initialize the object.
	
	obj = (dns_service_discovery_ref) malloc( sizeof( *obj ) );
	require_action( obj, exit, err = kDNSNoMemoryErr );
	
	obj->type 		= kDNSServiceDiscoveryObjectTypeDomainEnumeration;
	obj->ref 		= NULL;
	obj->callback	= inCallBack;
	obj->context	= inContext;
	
	// Create the underlying browser and start searching for domains.
	
	err = DNSBrowserCreate( 0, DNSServiceDomainEnumerationPrivateCallBack, obj, &browser );
	require_noerr( err, exit ); 
	obj->ref = browser;
	
	if( inRegistrationDomains )
	{
		flags = kDNSBrowserFlagRegistrationDomainsOnly;
	}
	else
	{
		flags = 0;
	}
	err = DNSBrowserStartDomainSearch( browser, flags );
	require_noerr( err, exit ); 
		
	// Success!
	
	result		= obj;
	browser		= NULL;
	obj			= NULL;
	
exit:
	if( browser )
	{
		DNSBrowserRelease( browser, 0 );
	}
	if( obj )
	{
		DNSServiceDiscoveryDeallocate( obj );
	}
	return( result );
}
ChooserDialog::~ChooserDialog( void )
{
	if( mBrowser )
	{
		DNSStatus		err;
		
		err = DNSBrowserRelease( mBrowser, 0 );
		assert( err == kDNSNoErr );
	}
}
dns_service_discovery_ref
	DNSServiceBrowserCreate(
		const char *			inType,
		const char *			inDomain,
		DNSServiceBrowserReply	inCallBack,
		void *					inContext )
{
	DNSStatus						err;
	dns_service_discovery_ref		result;
	dns_service_discovery_ref		obj;
	DNSBrowserRef					browser;
	
	result 	= NULL;
	browser	= NULL;
	
	// Allocate and initialize the object.
	
	obj = (dns_service_discovery_ref) malloc( sizeof( *obj ) );
	require_action( obj, exit, err = kDNSNoMemoryErr );
	
	obj->type 		= kDNSServiceDiscoveryObjectTypeBrowser;
	obj->ref 		= NULL;
	obj->callback	= inCallBack;
	obj->context	= inContext;
	
	// Create the underlying browser and start searching for domains.
	
	err = DNSBrowserCreate( 0, DNSServiceBrowserPrivateCallBack, obj, &browser );
	require_noerr( err, exit ); 
	obj->ref = browser;
	
	err = DNSBrowserStartServiceSearch( browser, 0, inType, inDomain );
	require_noerr( err, exit ); 
		
	// Success!
	
	result		= obj;
	browser		= NULL;
	obj			= NULL;
	
exit:
	if( browser )
	{
		DNSBrowserRelease( browser, 0 );
	}
	if( obj )
	{
		DNSServiceDiscoveryDeallocate( obj );
	}
	return( result );
}