// // convert unicode string to cipher type // HRESULT Wstr2CipherType ( _In_ LPCWSTR pszSrc, _Out_ PIHV_CIPHER_TYPE pCipherType ) { HRESULT hr = S_OK; DWORD dwIndex = 0; if ( (!pCipherType) || (!pszSrc) ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } for ( dwIndex = 0; dwIndex < MAX_CIPHER_TYPES; dwIndex++ ) { if ( 0 == wcscmp( gppszIhvCipherTypes[dwIndex], pszSrc ) ) { (*pCipherType) = (IHV_CIPHER_TYPE) dwIndex; BAIL( ); } } // String not found. hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); error: return hr; }
HRESULT CIhvSecurityProfile::GetFullSecurityFlag ( BOOL* pbUseFullSecurity ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_FSFLAG_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); hr = Wstr2Bool ( bstrData, pbUseFullSecurity ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
HRESULT CIhvSecurityProfile::SetSecurityType ( IHV_SECURITY_TYPE SecurityType ) { HRESULT hr = S_OK; BSTR bstrText = NULL; hr = SecurityType2Bstr ( SecurityType, &bstrText ); BAIL_ON_FAILURE( hr ); hr = PutTextInNode ( SEC_ATYPE_XPATH, bstrText ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrText ); return hr; }
// Accessor. HRESULT CIhvSecurityProfile::GetAuthType ( PIHV_AUTH_TYPE pAuthType ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_ATYPE_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); if ( NULL == bstrData ) { hr = E_POINTER; BAIL_ON_FAILURE( hr ); } hr = Wstr2AuthType ( bstrData, pAuthType ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
HRESULT CIhvSecurityProfile::SetParamDWORD ( DWORD dwNewValue ) { HRESULT hr = S_OK; BSTR bstrText = NULL; hr = Dword2Bstr ( dwNewValue, &bstrText ); BAIL_ON_FAILURE( hr ); hr = PutTextInNode ( SEC_PARAM2_XPATH, bstrText ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrText ); return hr; }
// Accessor. HRESULT CIhvConnectivityProfile::GetParam1 ( DWORD* pdwParam1 ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( CON_PARAM1_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); if ( NULL == bstrData ) { hr = E_POINTER; BAIL_ON_FAILURE( hr ); } hr = Wstr2Dword ( bstrData, pdwParam1 ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
// // convert unicode string to BOOL // HRESULT Wstr2Bool ( _In_ LPCWSTR pszSrc, _Out_ BOOL* pbDest ) { HRESULT hr = S_OK; if ( (!pbDest) || (!pszSrc) ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } if ( 0 == wcscmp( L"TRUE", pszSrc ) ) { (*pbDest) = TRUE; } else if ( 0 == wcscmp( L"FALSE", pszSrc ) ) { (*pbDest) = FALSE; } else { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } error: return hr; }
HRESULT CIhvSecurityProfile::SetFullSecurityFlag ( BOOL bUseFullSecurity ) { HRESULT hr = S_OK; BSTR bstrText = NULL; hr = Bool2Bstr ( bUseFullSecurity, &bstrText ); BAIL_ON_FAILURE( hr ); hr = PutTextInNode ( SEC_FSFLAG_XPATH, bstrText ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrText ); return hr; }
HRESULT CIhvSecurityProfile::GetSecurityType ( PIHV_SECURITY_TYPE pSecurityType ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_ATYPE_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); hr = Wstr2SecurityType ( bstrData, pSecurityType ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
HRESULT CIhvProfileBase::EmitXml ( OUT BSTR* pbstrIhvProfile ) { HRESULT hr = S_OK; if ( !pbstrIhvProfile ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } if ( !m_pRootNode ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = m_pRootNode->get_xml( pbstrIhvProfile ); BAIL_ON_FAILURE( hr ); error: return hr; }
// Convert unicode string to BSTR. NULL safe. HRESULT Wstr2Bstr ( _In_ LPCWSTR pszSrc, _Outptr_ BSTR* pbstrDest ) { HRESULT hr = S_OK; if ( !pbstrDest ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } (*pbstrDest) = NULL; if ( !pszSrc ) { BAIL( ); } (*pbstrDest) = SysAllocString( pszSrc ); if ( !(*pbstrDest) ) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } error: return hr; }
HRESULT CIhvSecurityProfile::SetCipherType ( IHV_CIPHER_TYPE CipherType ) { HRESULT hr = S_OK; BSTR bstrText = NULL; hr = CipherType2Bstr ( CipherType, &bstrText ); BAIL_ON_FAILURE( hr ); hr = PutTextInNode ( SEC_ETYPE_XPATH, bstrText ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrText ); return hr; }
HRESULT CIhvSecurityProfile::GetParamDWORD ( DWORD* pdwParam1 ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_PARAM2_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); hr = Wstr2Dword ( bstrData, pdwParam1 ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
HRESULT CIhvSecurityProfile::GetCipherType ( PIHV_CIPHER_TYPE pCipherType ) { HRESULT hr = S_OK; BSTR bstrData = NULL; hr = GetTextFromNode ( SEC_ETYPE_XPATH, &bstrData ); BAIL_ON_FAILURE( hr ); hr = Wstr2CipherType ( bstrData, pCipherType ); BAIL_ON_FAILURE( hr ); error: SYS_FREE_STRING( bstrData ); return hr; }
// // convert unicode string to auth type // HRESULT Wstr2AuthType ( IN LPCWSTR pszSrc, OUT PIHV_AUTH_TYPE pAuthType ) { HRESULT hr = S_OK; DWORD dwIndex = 0; if ( (!pAuthType) || (!pszSrc) ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } for ( dwIndex = 0; dwIndex < MAX_AUTH_TYPES; dwIndex++ ) { if ( 0 == wcscmp( gppszIhvAuthTypes[dwIndex], pszSrc ) ) { (*pAuthType) = (IHV_AUTH_TYPE) dwIndex; BAIL( ); } } // String not found. hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); error: return hr; }
HRESULT CIhvConnectivityProfile::GetNativeData ( LPVOID* ppvData ) { HRESULT hr = S_OK; PIHV_CONNECTIVITY_PROFILE pIhvProfile = NULL; BSTR bstrParam2 = NULL; if ( !ppvData ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } pIhvProfile = (PIHV_CONNECTIVITY_PROFILE) malloc( sizeof( IHV_CONNECTIVITY_PROFILE ) ); if ( !pIhvProfile ) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } ZeroMemory( pIhvProfile, sizeof( IHV_CONNECTIVITY_PROFILE ) ); hr = GetParamBSTR ( &bstrParam2 ); BAIL_ON_FAILURE( hr ); hr = Wstr2Wstr ( bstrParam2, &(pIhvProfile->pszParam2) ); BAIL_ON_FAILURE( hr ); hr = GetParamDWORD ( &(pIhvProfile->dwParam1) ); BAIL_ON_FAILURE( hr ); // Transfering local cache to OUT parameter. (*ppvData) = pIhvProfile; pIhvProfile = NULL; error: if ( pIhvProfile ) { free( pIhvProfile->pszParam2 ); // NULL Safe. free( pIhvProfile ); } SYS_FREE_STRING( bstrParam2 ); return hr; }
// base function to obtain text from // node described by XPATH. HRESULT CIhvProfileBase::GetTextFromNode ( IN LPCWSTR pszQuery, OUT BSTR* pbstrText ) { HRESULT hr = S_OK; BSTR bstrQuery = NULL; IXMLDOMNode* pQueryNode = NULL; ASSERT( pszQuery ); ASSERT( pbstrText ); // if node is NULL, return empty string. if ( !m_pRootNode ) { hr = Wstr2Bstr ( L"", pbstrText ); BAIL( ); } hr = Wstr2Bstr ( pszQuery, &bstrQuery ); BAIL_ON_FAILURE( hr ); hr = m_pRootNode->selectSingleNode( bstrQuery, &pQueryNode ); BAIL_ON_FAILURE( hr ); if (!pQueryNode) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = pQueryNode->get_text( pbstrText ); BAIL_ON_FAILURE( hr ); if ( !(*pbstrText) ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } error: RELEASE_INTERFACE( pQueryNode ); SYS_FREE_STRING( bstrQuery ); return hr; }
// Convert unicode string to unicode string. NULL safe. // string allocated by malloc and freed by free. HRESULT Wstr2Wstr ( _In_ LPCWSTR pszSrc, _Outptr_ LPWSTR* ppszDest ) { HRESULT hr = S_OK; size_t len = 0; if ( !ppszDest ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } (*ppszDest) = NULL; if ( !pszSrc ) { BAIL( ); } len = 1 + wcslen( pszSrc ); len *= sizeof( WCHAR ); (*ppszDest) = (LPWSTR) PrivateMemoryAlloc( len ); if ( !(*ppszDest) ) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } CopyMemory( (*ppszDest), pszSrc, len ); error: return hr; }
// // convert unicode string to DWORD // HRESULT Wstr2Dword ( _In_ LPCWSTR pszSrc, _Out_ DWORD* pdwDest ) { HRESULT hr = S_OK; if ( (!pdwDest) || (!pszSrc) ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } (*pdwDest) = (DWORD) _wtol( pszSrc ); error: return hr; }
// Accessor. HRESULT CIhvConnectivityProfile::GetParam2 ( BSTR* pbstrValue ) { HRESULT hr = S_OK; hr = GetTextFromNode ( CON_PARAM2_XPATH, pbstrValue ); BAIL_ON_FAILURE( hr ); error: return hr; }
HRESULT CIhvSecurityProfile::SetParamBSTR ( BSTR bstrNewValue ) { HRESULT hr = S_OK; hr = PutTextInNode ( SEC_PARAM1_XPATH, bstrNewValue ); BAIL_ON_FAILURE( hr ); error: return hr; }
HRESULT CIhvSecurityProfile::GetParamBSTR ( BSTR* pbstrValue ) { HRESULT hr = S_OK; hr = GetTextFromNode ( SEC_PARAM1_XPATH, pbstrValue ); BAIL_ON_FAILURE( hr ); error: return hr; }
// // Calls the accessors to build native data. // HRESULT CIhvSecurityProfile::GetNativeData ( LPVOID* ppvData ) { HRESULT hr = S_OK; PIHV_SECURITY_PROFILE pIhvProfile = NULL; BSTR bstrParam2 = NULL; if ( !ppvData ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } pIhvProfile = (PIHV_SECURITY_PROFILE) PrivateMemoryAlloc( sizeof( IHV_SECURITY_PROFILE ) ); if ( !pIhvProfile ) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } pIhvProfile->bUseIhvConnectivityOnly = ( m_pRootNode == NULL ); // Ignoring errors since structure is already // populated with defaults. hr = GetFullSecurityFlag ( &(pIhvProfile->bUseFullSecurity) ); hr = GetAuthType ( &(pIhvProfile->AuthType) ); hr = GetCipherType ( &(pIhvProfile->CipherType) ); hr = GetParam1 ( &(pIhvProfile->dwParam1) ); hr = GetParam2 ( &bstrParam2 ); BAIL_ON_FAILURE( hr ); if ( NULL == bstrParam2 ) { hr = E_POINTER; BAIL_ON_FAILURE( hr ); } hr = Wstr2Wstr ( bstrParam2, &(pIhvProfile->pszParam2) ); // Consuming earlier failures. hr = S_OK; // Transfering local cache to OUT parameter. (*ppvData) = pIhvProfile; pIhvProfile = NULL; error: if ( pIhvProfile ) { PrivateMemoryFree( pIhvProfile->pszParam2 ); // NULL Safe. PrivateMemoryFree( pIhvProfile ); } SYS_FREE_STRING( bstrParam2 ); return hr; }
DWORD ConvertStringToKey ( BYTE* pbKeyData, DWORD* pdwKeyLen ) { DWORD dwResult = ERROR_SUCCESS; HRESULT hr = S_OK; CHAR szKey[ MAX_KEY_STRING_LENGTH + 2 ] = {0}; DWORD dwKeyStringLen = 0; DWORD dwIndex = 0; if ( (!pbKeyData) || (!pdwKeyLen) || ( 0 == (*pdwKeyLen) ) || ( (*pdwKeyLen) % sizeof( WCHAR ) ) ) { dwResult = ERROR_INVALID_PARAMETER; BAIL_ON_WIN32_ERROR( dwResult ); } dwKeyStringLen = (DWORD) wcslen( (LPWSTR) pbKeyData ); if ( MAX_KEY_STRING_LENGTH < dwKeyStringLen ) { dwResult = ERROR_BAD_FORMAT; BAIL_ON_WIN32_ERROR( dwResult ); } // Converting the UNICODE string to // ANSI string in scratch pad. hr = StringCchPrintfA ( szKey, MAX_KEY_STRING_LENGTH + 1, "%S", (WCHAR*) pbKeyData ); BAIL_ON_FAILURE( hr ); ASSERT( dwKeyStringLen == (DWORD) strlen( szKey )); if ( ( 5 == dwKeyStringLen ) || ( 13 == dwKeyStringLen ) ) { // Copying the ANSI string back to original buffer. hr = StringCchPrintfA ( (CHAR*) pbKeyData, (*pdwKeyLen), "%s", szKey ); BAIL_ON_FAILURE( hr ); // The strings are direct representations // of the Wep Key and can be directly returned. (*pdwKeyLen) = dwKeyStringLen; TRACE_MESSAGE_VAL( "Received WEP key of length = ", (*pdwKeyLen) ); BAIL( ); } if (( 10 != dwKeyStringLen ) && ( 26 != dwKeyStringLen )) { // Wrong length input dwResult = ERROR_BAD_FORMAT; BAIL_ON_WIN32_ERROR( dwResult ); } for( dwIndex = 0; dwIndex < (dwKeyStringLen / 2); dwIndex++ ) { dwResult = ConvertHexCharToNibble ( szKey[ 2 * dwIndex ], TRUE, &(pbKeyData[ dwIndex ]) ); BAIL_ON_WIN32_ERROR( dwResult ); dwResult = ConvertHexCharToNibble ( szKey[ 1 + (2 * dwIndex) ], FALSE, &(pbKeyData[ dwIndex ]) ); BAIL_ON_WIN32_ERROR( dwResult ); } (*pdwKeyLen) = dwKeyStringLen / 2; TRACE_MESSAGE_VAL( "Received WEP key of length = ", (*pdwKeyLen) ); error: return WIN32_COMBINED_ERROR( dwResult, hr ); }
HRESULT CWlanManager::GetHostedNetworkKey( CAtlString& strKey ) { HRESULT hr = S_OK; DWORD dwError = ERROR_SUCCESS; BOOL bIsPassPhrase = FALSE; BOOL bPersistent = FALSE; PUCHAR pucSecondaryKey = NULL; DWORD dwSecondaryKeyLength = 0; WCHAR strSecondaryKey[WLAN_MAX_NAME_LENGTH]; // get the user security key dwError = WlanHostedNetworkQuerySecondaryKey( m_WlanHandle, &dwSecondaryKeyLength, &pucSecondaryKey, &bIsPassPhrase, &bPersistent, NULL, NULL ); BAIL_ON_WIN32_ERROR(dwError, hr); int cchKey = 0; if (dwSecondaryKeyLength > 0) { // Must be passphrase _ASSERT(bIsPassPhrase); // convert the key if (bIsPassPhrase) { #pragma prefast(suppress:26035, "If the key is a pass phrase, it is guaranteed to be null-terminated.") cchKey = MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, (LPCSTR)pucSecondaryKey, dwSecondaryKeyLength, strSecondaryKey, sizeof(strSecondaryKey) / sizeof(strSecondaryKey[0]) -1 ); } } if(cchKey == 0) { // secondary key is not set or not passphrase // set a temporary one CAtlString strTmpKey = L"HostedNetwork12345"; hr = SetHostedNetworkKey(strTmpKey); BAIL_ON_FAILURE(hr); strKey = strTmpKey; } else { // got the key strKey = strSecondaryKey; } error: if (pucSecondaryKey != NULL) { WlanFreeMemory(pucSecondaryKey); pucSecondaryKey = NULL; } return hr; }
// Converts string to security profile. DWORD GetIhvSecurityProfile ( PDOT11EXT_IHV_SECURITY_PROFILE pDot11ExtIhvSecProfile, PIHV_SECURITY_PROFILE* ppSecurityProfile ) { HRESULT hr = S_OK; BOOL bComInitialized = FALSE; BSTR bstrIhvProfile = NULL; PIHV_SECURITY_PROFILE pSecurityProfile = NULL; CIhvSecurityProfile* pIhvProfile = NULL; ASSERT( pDot11ExtIhvSecProfile ); ASSERT( ppSecurityProfile ); // Data structure is multi-thread safe because // it is both allocated and freed by current // function. hr = CoInitializeEx ( NULL, COINIT_MULTITHREADED ); BAIL_ON_FAILURE( hr ); bComInitialized = TRUE; pIhvProfile = new(std::nothrow) CIhvSecurityProfile; if (!pIhvProfile) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } hr = Wstr2Bstr ( pDot11ExtIhvSecProfile->pszXmlFragmentIhvSecurity, &bstrIhvProfile ); BAIL_ON_FAILURE( hr ); hr = pIhvProfile->LoadXml ( bstrIhvProfile ); BAIL_ON_FAILURE( hr ); hr = pIhvProfile->GetNativeData ( (LPVOID*) &pSecurityProfile ); BAIL_ON_FAILURE( hr ); if ( pDot11ExtIhvSecProfile->bUseMSOnex && pSecurityProfile->bUseFullSecurity ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } (*ppSecurityProfile) = pSecurityProfile; pSecurityProfile = NULL; error: SYS_FREE_STRING( bstrIhvProfile ); FreeIhvSecurityProfile ( &pSecurityProfile ); delete pIhvProfile; if ( bComInitialized ) { CoUninitialize( ); } return WIN32_FROM_HRESULT( hr ); }
// // Calls the accessors to build native data. // HRESULT CIhvConnectivityProfile::GetNativeData ( LPVOID* ppvData ) { HRESULT hr = S_OK; PIHV_CONNECTIVITY_PROFILE pIhvProfile = NULL; BSTR bstrParam2 = NULL; if ( !ppvData ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } pIhvProfile = (PIHV_CONNECTIVITY_PROFILE) PrivateMemoryAlloc( sizeof( IHV_CONNECTIVITY_PROFILE ) ); if ( !pIhvProfile ) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } // Ignoring errors since structure is already // populated with defaults. hr = GetParam2 ( &bstrParam2 ); hr = Wstr2Wstr ( bstrParam2, &(pIhvProfile->pszParam2) ); hr = GetParam1 ( &(pIhvProfile->dwParam1) ); // Consuming earlier failures. hr = S_OK; // Transfering local cache to OUT parameter. (*ppvData) = pIhvProfile; pIhvProfile = NULL; error: if ( pIhvProfile ) { PrivateMemoryFree( pIhvProfile->pszParam2 ); // NULL Safe. PrivateMemoryFree( pIhvProfile ); } SYS_FREE_STRING( bstrParam2 ); return hr; }
HRESULT CIhvProfileBase::LoadXml ( IN BSTR bstrProfileData ) { HRESULT hr = S_OK; IXMLDOMDocument* pDOMDoc = NULL; IXMLDOMElement* pDocElem = NULL; BSTR bstrIhvProfile = NULL; VARIANT_BOOL vfSuccess; if ( !bstrProfileData ) { hr = GetDefaultXml( &bstrIhvProfile ); BAIL_ON_FAILURE( hr ); } else { bstrIhvProfile = bstrProfileData; } if ( m_pRootNode ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = CoCreateInstance ( CLSID_DOMDocument, NULL, CLSCTX_ALL, IID_IXMLDOMDocument, (LPVOID *) &pDOMDoc ); BAIL_ON_FAILURE( hr ); hr = pDOMDoc->loadXML ( bstrIhvProfile, &vfSuccess ); BAIL_ON_FAILURE( hr ); if ( VARIANT_TRUE != vfSuccess ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = pDOMDoc->get_documentElement ( &pDocElem ); BAIL_ON_FAILURE( hr ); // Caching the pointer to the document element // in a member variable. m_pRootNode = pDocElem; pDocElem = NULL; error: if ( !bstrProfileData ) { SYS_FREE_STRING( bstrIhvProfile ); } RELEASE_INTERFACE( pDOMDoc ); RELEASE_INTERFACE( pDocElem ); return hr; }
HRESULT CIhvSecurityProfile::GetNativeData ( LPVOID* ppvData ) { HRESULT hr = S_OK; PIHV_SECURITY_PROFILE pIhvProfile = NULL; BSTR bstrParam2 = NULL; if ( !ppvData ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } pIhvProfile = (PIHV_SECURITY_PROFILE) malloc( sizeof( IHV_SECURITY_PROFILE ) ); if ( !pIhvProfile ) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } ZeroMemory( pIhvProfile, sizeof( IHV_SECURITY_PROFILE ) ); hr = GetFullSecurityFlag ( &(pIhvProfile->bUseFullSecurity) ); BAIL_ON_FAILURE( hr ); hr = GetAuthType ( &(pIhvProfile->AuthType) ); BAIL_ON_FAILURE( hr ); hr = GetCipherType ( &(pIhvProfile->CipherType) ); BAIL_ON_FAILURE( hr ); hr = GetParamDWORD ( &(pIhvProfile->dwParam1) ); BAIL_ON_FAILURE( hr ); hr = GetParamBSTR ( &bstrParam2 ); BAIL_ON_FAILURE( hr ); if ( NULL == bstrParam2 ) { hr = E_POINTER; BAIL_ON_FAILURE( hr ); } hr = Wstr2Wstr ( bstrParam2, &(pIhvProfile->pszParam2) ); BAIL_ON_FAILURE( hr ); // Transfering local cache to OUT parameter. (*ppvData) = pIhvProfile; pIhvProfile = NULL; error: if ( pIhvProfile ) { free( pIhvProfile->pszParam2 ); // NULL Safe. free( pIhvProfile ); } SYS_FREE_STRING( bstrParam2 ); return hr; }
HRESULT CIhvProfileBase::PutTextInNode ( IN LPCWSTR pszQuery, IN BSTR bstrText ) { HRESULT hr = S_OK; BSTR bstrQuery = NULL; BSTR bstrOrig = NULL; BOOL bPut = TRUE; IXMLDOMNode* pQueryNode = NULL; if ( !m_pRootNode ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } if ( (!pszQuery) || (!bstrText) ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } hr = Wstr2Bstr ( pszQuery, &bstrQuery ); BAIL_ON_FAILURE( hr ); hr = m_pRootNode->selectSingleNode( bstrQuery, &pQueryNode ); BAIL_ON_FAILURE( hr ); if (!pQueryNode) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = pQueryNode->get_text( &bstrOrig ); BAIL_ON_FAILURE( hr ); if ( bstrOrig && ( 0 == wcscmp( bstrOrig, bstrText ) ) ) { bPut = FALSE; } if ( bPut ) { hr = pQueryNode->put_text( bstrText ); BAIL_ON_FAILURE( hr ); SetModified( ); } error: RELEASE_INTERFACE( pQueryNode ); SYS_FREE_STRING( bstrQuery ); SYS_FREE_STRING( bstrOrig ); return hr; }