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

📄 provisionmanager.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        return E_POINTER;
    }

    if (riid == IID_IUnknown)
    {
        *ppvObject = static_cast<IUnknown*>(static_cast<ISAXContentHandler*>(this));
    }
    else if (riid == IID_ISAXContentHandler)
    {
        *ppvObject = static_cast<ISAXContentHandler*>(this);
    }
    else if (riid == IID_IRTCEventNotification)
    {
        *ppvObject = static_cast<IRTCEventNotification*>(this); 
    }
    else
    {
        *ppvObject = NULL;
        return E_NOINTERFACE;
    }

    static_cast<IUnknown*>(*ppvObject)->AddRef();
    return S_OK;
}

////////////////////////////////////////////////////////////////////////////////
// ISAXContentHandler methods

/*------------------------------------------------------------------------------
    ProvisionManager_t::endDocument

    Receives notification of the end of document

    Parameters:
        : none

    Returns:
        - S_OK returned if no errors occur
        - E_FAIL returned if the parse operation should be aborted
------------------------------------------------------------------------------*/
HRESULT
ProvisionManager_t::endDocument(
    void
    )
{
    return S_OK;
}

/*------------------------------------------------------------------------------
    ProvisionManager_t::endElement

    Receives notification of the end of an element

    Parameters:
        : IN - const wchar_t* - The element's name space URI
        : IN - int - The length for the namespace URI
        : IN - const wchar_t* - The element's local name string
        : IN - int - The length of the local name
        : IN - const wchar_t* - The QName (with prefix)
        : IN - int - The length of the QName
        : IN - ISAXAttributes* - The attributes attached to the element

    Returns:
        - S_OK returned if no errors occur
        - E_FAIL returned if the parse operation should be aborted
------------------------------------------------------------------------------*/
HRESULT
ProvisionManager_t::endElement(
    const wchar_t *pwchNamespaceUri,
    int cchNamespaceUri,
    const wchar_t *pwchLocalName,
    int cchLocalName,
    const wchar_t *pwchQName,
    int cchQName
    )
{
    HRESULT hr;
    ProvisionElement_e ProvisionXMLElementType;
    int Index; 

    if (m_ElementsStack.empty())
    {
        return E_FAIL;
    }

    hr = GetElementType(
            pwchLocalName, 
            cchLocalName, 
            &ProvisionXMLElementType, 
            &Index
            );
    
    if (SUCCEEDED(hr))
    {
        hr = (ProvisionXMLElementType == m_ElementsStack.front()) ? S_OK : E_FAIL;
        if (SUCCEEDED(hr))
        {
            m_ElementsStack.pop_front();
            ASSERT((ElementStart != ProvisionXMLElementType) || m_ElementsStack.empty());
        }
    }

    if (FAILED(hr))
    {
        ; 
    }

    return hr;
}

/*------------------------------------------------------------------------------
    ProvisionManager_t::startDocument

    Receives notification of the beginning of document

    Parameters:
        : none

    Returns:
        - S_OK returned if no errors occur
        - E_FAIL returned if the parse operation should be aborted
------------------------------------------------------------------------------*/
HRESULT
ProvisionManager_t::startDocument(
    void
    )
{
    // Before parsing the XML the state should be the following:
    // 1. No XML elements in the stack
    if (!m_ElementsStack.empty())
    {
        ASSERT(0);
        return E_FAIL;
    }

    return S_OK;
}

/*------------------------------------------------------------------------------
    ProvisionManager_t::startElement

    Receives notification of the start of an element

    Parameters:
        : IN - const wchar_t* - The element's name space URI
        : IN - int - The length for the namespace URI
        : IN - const wchar_t* - The element's local name string
        : IN - int - The length of the local name
        : IN - const wchar_t* - The QName (with prefix)
        : IN - int - The length of the QName
        : IN - ISAXAttributes* - The attributes attached to the element

    Returns:
        - S_OK returned if no errors occur
        - E_FAIL returned if the parse operation should be aborted
------------------------------------------------------------------------------*/
HRESULT
ProvisionManager_t::startElement(
    const wchar_t*  pwchNamespaceUri,
    int             cchNamespaceUri,
    const wchar_t*  pwchLocalName,
    int             cchLocalName,
    const wchar_t*  pwchQName,
    int             cchQName,
    ISAXAttributes* pAttributes
    )
{
    ProvisionElement_e ProvisionXMLElementType;
    int Index; 

    HRESULT hr = GetElementType(
                    pwchLocalName, 
                    cchLocalName, 
                    &ProvisionXMLElementType, 
                    &Index
                    );
    
    if (FAILED(hr))
    {
        return hr; 
    }

    switch (ProvisionXMLElementType)
    {
        case ElementStart:
            // Opening element must be at level 0
            if (!m_ElementsStack.empty()) 
            {
                return E_FAIL; 
            }
            
            break; 

        case ElementSet:
        case ElementDelete:
        case ElementQuery:
            if (!IsXMLElementHierarchyValid(&sc_ProvisionElements[Index]))
            {
                return E_FAIL; 
            }

            hr = HandleVerbs(
                    ProvisionXMLElementType, 
                    pAttributes
                    ); 

            break; 

        default:
            ASSERT(ElementUnknown == ProvisionXMLElementType);
            break;
    }

    if (FAILED(hr))
    {
        return hr; 
    }

    if (!m_ElementsStack.push_front(ProvisionXMLElementType))
    {
        return E_OUTOFMEMORY;
    }

    return hr;
}

/*------------------------------------------------------------------------------
    ProvisionManager_t::HandleVerbs
    
    Description
    
    Parameters:
        ElementType: 
        pAttributes: 
    
    Returns (HRESULT): 
------------------------------------------------------------------------------*/
HRESULT
ProvisionManager_t::HandleVerbs(
    ProvisionElement_e  ElementType, 
    ISAXAttributes*     pAttributes
    )
{
    if (pAttributes == NULL)
    {
        return E_INVALIDARG; 
    }
    
    switch (ElementType)
    {
        case ElementSet: 
            return HandleSet(pAttributes); 

        case ElementDelete:
            return HandleDelete(pAttributes); 

        case ElementQuery:
            return HandleQuery(pAttributes); 

        default:
            break;             
    }

    return E_FAIL; 
}

/*------------------------------------------------------------------------------
    ProvisionManager_t::HandleSet
    
    Description
    
    Parameters:
        : 
    
    Returns (HRESULT): 
------------------------------------------------------------------------------*/
HRESULT
ProvisionManager_t::HandleSet(
    ISAXAttributes* pAttributes
    )
{
    if (pAttributes == NULL)
    {
        return E_INVALIDARG; 
    }

    int AttributesCount; 

    HRESULT hr = pAttributes->getLength(&AttributesCount); 
    if (FAILED(hr))
    {
        return hr;        
    }

    //there must be 2 attributs (name and value) associated with 'set'
    if (AttributesCount != 2)
    {
        return E_FAIL; 
    }

    ProvisionSetting_t* pSetting     = NULL; 
    pfnValidator        pfnValidator = NULL; 

    for (int Index = 0; Index < AttributesCount; Index ++)
    {
        const WCHAR*            pAttributeName; 
        const WCHAR*            pAttributeValue; 
        int                     AttributeNameLength; 
        int                     AttributeValueLength; 
        ProvisionAttribute_e    AttributeType; 

        hr = pAttributes->getLocalName(
                            Index, 
                            &pAttributeName, 
                            &AttributeNameLength
                            ); 
        if (FAILED(hr))
        {
            ASSERT(FALSE); 
            return hr; 
        }

        hr = GetAttributeType(
                    pAttributeName, 
                    AttributeNameLength, 
                    &AttributeType
                    ); 
        if (FAILED(hr))
        {
            ASSERT(FALSE); 
            return hr; 
        }

        hr = pAttributes->getValue(
                            Index, 
                            &pAttributeValue, 
                            &AttributeValueLength
                            ); 
        if (FAILED(hr))
        {
            ASSERT(FALSE); 
            return hr; 
        }

        switch (AttributeType)
        {
            case AttributeName: 
                if (Index != 0)
                {
                    ASSERT(FALSE); 
                    return E_UNEXPECTED; 
                }

                hr = GetProvisionSetting(
                            pAttributeValue, 
                            AttributeValueLength, 
                            &pSetting, 
                            &pfnValidator
                            ); 
                if (FAILED(hr))
                {
                    return hr;  
                }
                
                if (pSetting == NULL)
                {
                    ASSERT(FALSE); 
                    return E_UNEXPECTED;  
                }
                
                break; 
                
            case AttributeValue: 
                if (Index != 1)
                {
                    ASSERT(FALSE); 
                    return E_UNEXPECTED; 
                }

                if (!((this->*pfnValidator)(
                                pAttributeValue, 
                                AttributeValueLength
                                )))
                {
                    return PROVISION_E_INVALID_SETTING; 
                }

                if (m_Flags & VALIDATE_XML_ONLY)
                {
                    return S_OK; 
                }

                hr = pSetting->Set(
                                m_UpdateSettingCategory, 
                                pAttributeValue, 
                                AttributeValueLength
                                ); 
                if (SUCCEEDED(hr))
                {
                    m_UpdatedFlags |= pSetting->GetSettingFlag(); 
                }

                break; 
                
            default: 
                ASSERT(FALSE); 
                return E_UNEXPECTED;
                
        }
                            
    }

    return hr; 
    
}

/*------------------------------------------------------------------------------
    ProvisionManager_t::HandleQuery
    
    Handle the 'Query' element
    
    Parameters:
        pAttributes:  
    
    Returns (HRESULT): 
------------------------------------------------------------------------------*/
HRESULT
ProvisionManager_t::HandleQuery(
    ISAXAttributes* pAttributes
    )
{

    if (pAttributes == NULL)
    {
        return E_INVALIDARG; 
    }

    int AttributesCount; 

    HRESULT hr = pAttributes->getLength(&AttributesCount); 
    if (FAILED(hr))
    {
        return hr;        
    }

    //there must be 1 attribut (name) associated with 'query'
    if (AttributesCount != 1)
    {
        return E_FAIL; 
    }

⌨️ 快捷键说明

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