⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serversettings.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "ServerSettings.hpp"
#include "VoIPNotify.hpp"
#include "PhoneAPI.hpp"
#include <winuserm.h>

const WCHAR c_UserXPath[]               = L"provision/user"; 
const WCHAR c_SIPProxyXPath[]           = L"provision/sipsrv[@role = 'proxy']"; 
const WCHAR c_SIPRegistrarXPath[]       = L"provision/sipsrv[@role = 'registrar']"; 
const WCHAR c_VoicemailNumberXPath[]    = L"voip-provision/query[@name = \"VoicemailNumber\"]"; 

const WCHAR c_Account[]     = L"account"; 
const WCHAR c_Password[]    = L"password"; 
const WCHAR c_Uri[]         = L"uri"; 
const WCHAR c_Addr[]        = L"addr"; 
const WCHAR c_Protocol[]    = L"protocol"; 
const WCHAR c_Value[]       = L"value"; 

HRESULT 
GetAttributeValue(
    IXMLDOMNode*    pCurrentNode, 
    const WCHAR*    c_pAttributeName, 
    BSTR*           pbstrAttributeValue
    )
{
    if (pCurrentNode == NULL ||
        c_pAttributeName == NULL ||
        c_pAttributeName[0] == L'\0' ||
        pbstrAttributeValue == NULL)
    {
        return E_INVALIDARG; 
    }

    *pbstrAttributeValue = NULL; 

    //prepare the bstr attribute name
    ce::auto_bstr bstrAttributeName = SysAllocString(c_pAttributeName); 
    if (bstrAttributeName == NULL)
    {
        return E_OUTOFMEMORY; 
    }
    
    //get the attribute collection for this node
    CComPtr<IXMLDOMNamedNodeMap>   cpAttributeMap;          
    HRESULT hr = pCurrentNode->get_attributes(&cpAttributeMap); 
    if (hr != S_OK)
    {
        return hr; 
    }

    //get name attribute and its value
    CComPtr<IXMLDOMNode>  cpAttribute; 
    hr = cpAttributeMap->getNamedItem(
                            bstrAttributeName, 
                            &cpAttribute
                            ); 
    if (hr != S_OK)
    {
        return hr; 
    }

    //get the attribute value
    hr = cpAttribute->get_text(pbstrAttributeValue); 
    if (wcslen(*pbstrAttributeValue) == 0)
    {
        return S_FALSE; 
    }

    return hr; 

}

HRESULT
GetAttributeValueForXPath(
    IXMLDOMDocument*    pDocument, 
    const WCHAR*        c_pXPath, 
    const WCHAR*        c_pAttributeName, 
    BSTR*               pbstrValue
    )
{
    if (pDocument == NULL ||
        c_pXPath ==  NULL ||
        c_pXPath[0] == L'\0' ||
        c_pAttributeName == NULL ||
        c_pAttributeName[0] == L'\0' ||
        pbstrValue == NULL)
    {
        return E_INVALIDARG; 
    }

    ce::auto_bstr bstrXPath = SysAllocString(c_pXPath); 
    if (bstrXPath == NULL)
    {
        return E_OUTOFMEMORY; 
    }

    CComPtr<IXMLDOMNode> cpNode;     
    HRESULT hr = pDocument->selectSingleNode(
                                bstrXPath, 
                                &cpNode
                                ); 
    if (hr != S_OK)
    {
        return hr; 
    }

    return GetAttributeValue(
                    cpNode, 
                    c_pAttributeName, 
                    pbstrValue
                    ); 
    
}

HRESULT
GetAccountName(
    IXMLDOMDocument*    pDocument, 
    BSTR*               pbstrValue
    )
{
    if (pbstrValue == NULL)
    {
        return E_INVALIDARG; 
    }
    
    if (pDocument == NULL)
    {
        // this category is not available
        return S_FALSE; 
    }

    return GetAttributeValueForXPath(
                pDocument, 
                c_UserXPath, 
                c_Account, 
                pbstrValue
                ); 

}

HRESULT
GetPassword(
    IXMLDOMDocument*    pDocument, 
    BSTR*               pbstrValue
    )
{
    if (pbstrValue == NULL)
    {
        return E_INVALIDARG; 
    }
    
    if (pDocument == NULL)
    {
        // this category is not available
        return S_FALSE; 
    }

    return GetAttributeValueForXPath(
                pDocument, 
                c_UserXPath, 
                c_Password, 
                pbstrValue
                ); 

}

HRESULT
GetUri(
    IXMLDOMDocument*    pDocument, 
    BSTR*               pbstrValue
    )
{
    if (pbstrValue == NULL)
    {
        return E_INVALIDARG; 
    }
    
    if (pDocument == NULL)
    {
        // this category is not available
        return S_FALSE; 
    }

    return GetAttributeValueForXPath(
                pDocument, 
                c_UserXPath, 
                c_Uri, 
                pbstrValue
                ); 

}

HRESULT
GetSIPProxy(
    IXMLDOMDocument*    pDocument, 
    BSTR*               pbstrValue
    )
{
    if (pbstrValue == NULL)
    {
        return E_INVALIDARG; 
    }
    
    if (pDocument == NULL)
    {
        // this category is not available
        return S_FALSE; 
    }

    return GetAttributeValueForXPath(
                pDocument, 
                c_SIPProxyXPath, 
                c_Addr, 
                pbstrValue
                ); 
}

HRESULT
GetSIPRegistrar(
    IXMLDOMDocument*    pDocument, 
    BSTR*               pbstrValue
    )
{
    if (pbstrValue == NULL)
    {
        return E_INVALIDARG; 
    }
    
    if (pDocument == NULL)
    {
        // this category is not available
        return S_FALSE; 
    }

    return GetAttributeValueForXPath(
                pDocument, 
                c_SIPRegistrarXPath, 
                c_Addr, 
                pbstrValue
                ); 

}
    
HRESULT
GetSIPTransport(
    IXMLDOMDocument*    pDocument, 
    BSTR*               pbstrValue
    )
{
    if (pbstrValue == NULL)
    {
        return E_INVALIDARG; 
    }
    
    if (pDocument == NULL)
    {
        // this category is not available
        return S_FALSE; 
    }

    return GetAttributeValueForXPath(
                pDocument, 
                c_SIPProxyXPath, 
                c_Protocol, 
                pbstrValue
                ); 
}


HRESULT
GetVoicemailNumber(
    IXMLDOMDocument*    pDocument, 
    BSTR*               pbstrValue
    )
{
    if (pbstrValue == NULL)
    {
        return E_INVALIDARG; 
    }
    
    if (pDocument == NULL)
    {
        // this category is not available
        return S_FALSE; 
    }

    return GetAttributeValueForXPath(
                pDocument, 
                c_VoicemailNumberXPath, 
                c_Value, 
                pbstrValue
                ); 
}

HRESULT
GetExchangeServer(
    IXMLDOMDocument*    pDocument, 
    BSTR*               pbstrValue
    )
{
    if (pbstrValue == NULL)
    {
        return E_INVALIDARG; 
    }
    
    if (pDocument != NULL)
    {
        //getting exchange server doesn't need IXMLDOMDocument
        return E_INVALIDARG; 
    }

    *pbstrValue = NULL; 

    WCHAR Value[MAX_PATH] = L""; 
    HRESULT hr = RegistryGetString(
                    SN_VOIP_EXCHANGESERVER_ROOT, 
                    SN_VOIP_EXCHANGESERVER_PATH, 
                    SN_VOIP_EXCHANGESERVER_VALUE, 
                    Value, 
                    _countof(Value)
                    ); 
    if (SUCCEEDED(hr))
    {
        *pbstrValue = SysAllocString(Value); 
    }
    else if (HRESULT_CODE(hr) == ERROR_FILE_NOT_FOUND)
    {
        *pbstrValue = SysAllocString(L"");         
        hr = S_FALSE;
    }
    else if (FAILED(hr))
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -