Exemple #1
0
STDMETHODIMP CTXTRecord::GetValueForKey(BSTR key, VARIANT* value)
{
	std::string		keyUTF8;
	const void	*	rawValue;
	uint8_t			rawValueLen;
	BOOL			ok	= TRUE;
	HRESULT			hr	= S_OK;

	VariantClear( value );

	if ( m_byteArray.size() > 0 )
	{
		ok = BSTRToUTF8( key, keyUTF8 );
		require_action( ok, exit, hr = S_FALSE );

		rawValue = TXTRecordGetValuePtr( ( uint16_t ) m_byteArray.size(), &m_byteArray[ 0 ], keyUTF8.c_str(), &rawValueLen );

		if ( rawValue )
		{
			ok = ByteArrayToVariant( rawValue, rawValueLen, value );
			require_action( ok, exit, hr = S_FALSE );
		}
	}

exit:

	return hr;
}
void DNSSD_API
CDNSSD::QueryRecordReply
		(
		DNSServiceRef                       sdRef,
		DNSServiceFlags                     flags,
		uint32_t                            ifIndex,
		DNSServiceErrorType                 errorCode,
		const char                          *fullNameUTF8,
		uint16_t                            rrtype,
		uint16_t                            rrclass,
		uint16_t                            rdlen,
		const void                          *rdata,
		uint32_t                            ttl,
		void                                *context
		)
{
	CComObject<CDNSSDService> * service;
	int err;
	
	service = ( CComObject< CDNSSDService>* ) context;
	require_action( service, exit, err = kDNSServiceErr_Unknown );

	if ( !service->Stopped() )
	{
		IQueryRecordListener * listener;

		listener = ( IQueryRecordListener* ) service->GetListener();
		require_action( listener, exit, err = kDNSServiceErr_Unknown );

		if ( !errorCode )
		{
			CComBSTR	fullName;
			VARIANT		var;
			BOOL		ok;

			ok = UTF8ToBSTR( fullNameUTF8, fullName );
			require_action( ok, exit, err = kDNSServiceErr_Unknown );
			ok = ByteArrayToVariant( rdata, rdlen, &var );
			require_action( ok, exit, err = kDNSServiceErr_Unknown );

			listener->QueryRecordAnswered( service, ( DNSSDFlags ) flags, ifIndex, fullName, ( DNSSDRRType ) rrtype, ( DNSSDRRClass ) rrclass, var, ttl );
		}
		else
		{
			listener->QueryRecordFailed( service, ( DNSSDError ) errorCode );
		}
	}

exit:

	return;
}
Exemple #3
0
STDMETHODIMP CTXTRecord::GetValueAtIndex(ULONG index, VARIANT* retval)
{
	char				keyBuf[ 64 ];
	uint8_t				rawValueLen;
	const void		*	rawValue;
	CComBSTR			temp;
	DNSServiceErrorType	err;
	BOOL				ok;
	HRESULT				hr = S_OK;

	err = TXTRecordGetItemAtIndex( ( uint16_t ) m_byteArray.size(), &m_byteArray[ 0 ], ( uint16_t ) index, sizeof( keyBuf ), keyBuf, &rawValueLen, &rawValue );
	require_action( !err, exit, hr = S_FALSE );

	ok = ByteArrayToVariant( rawValue, rawValueLen, retval );
	require_action( ok, exit, hr = S_FALSE );

exit:

	return hr;
}
STDMETHODIMP CDNSSD::GetProperty(BSTR prop, VARIANT * value )
{
	std::string			propUTF8;
	std::vector< BYTE >	byteArray;
	SAFEARRAY		*	psa			= NULL;
	BYTE			*	pData		= NULL;
	uint32_t			elems		= 0;
	DNSServiceErrorType	err			= 0;
	BOOL				ok = TRUE;

	// Convert BSTR params to utf8
	ok = BSTRToUTF8( prop, propUTF8 );
	require_action( ok, exit, err = kDNSServiceErr_BadParam );

	// Setup the byte array
	require_action( V_VT( value ) == ( VT_ARRAY|VT_UI1 ), exit, err = kDNSServiceErr_Unknown );
	psa = V_ARRAY( value );
	require_action( psa, exit, err = kDNSServiceErr_Unknown );
	require_action( SafeArrayGetDim( psa ) == 1, exit, err = kDNSServiceErr_Unknown );
	byteArray.reserve( psa->rgsabound[0].cElements );
	byteArray.assign( byteArray.capacity(), 0 );
	elems = ( uint32_t ) byteArray.capacity();

	// Call the function and package the return value in the Variant
	err = DNSServiceGetProperty( propUTF8.c_str(), &byteArray[ 0 ], &elems );
	require_noerr( err, exit );
	ok = ByteArrayToVariant( &byteArray[ 0 ], elems, value );
	require_action( ok, exit, err = kDNSSDError_Unknown );

exit:

	if ( psa )
	{
		SafeArrayUnaccessData( psa );
		psa = NULL;
	}

	return err;
}