// 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;
}
HRESULT
CIhvSecurityProfile::GetDefaultXml
(
    BSTR* pbstrDefault
)
{
    SetModified();
	return Wstr2Bstr( g_szDefaultSecurityProfile, pbstrDefault );
}
HRESULT
CIhvConnectivityProfile::GetDefaultXml
(
    BSTR* pbstrDefault
)
{
    SetModified();
	return Wstr2Bstr( g_szDefaultConnectivityProfile, pbstrDefault );
}
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;
}
// 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 );
}