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

📄 dialplanparser.hpp

📁 一个WinCE6。0下的IP phone的源代码
💻 HPP
字号:
//
// 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.
//
#pragma once

#ifndef __DIALPLANPARSER_HPP__
#define __DIALPLANPARSER_HPP__

#include <windows.h>
#include <msxml2.h>
#include <SAXContentHandlerImpl.h>
#include "DialEngine.hpp"
#include <string.hxx>

//forward declaration
class Settings_t; 

class DialPlanParser_t :
   public CSAXContentHandlerImpl
{
private:
    enum DialPlanElement_e
    {
        DialPlanElementStart,
        DialPlanElementHeader,
        DialPlanElementHost,
        DialPlanElementRule,
        DialPlanElementAutoDial, 
        UnknownElement, // MUST be last in the enumeration
    };

    struct XMLElement_t
    {
        WCHAR* m_pName;
        DialPlanElement_e m_Parent;
        BYTE m_Level;
    };

    enum DialingRuleAttribute_e
    {
        DialingRuleAttributePattern,
        DialingRuleAttributeDial,
        DialingRuleAttributeDisplay,
        DialingRuleAttributeTransfer,
        DialingRuleAttributeRestrict,
        UnknownAttribute, // MUST be last in the enumeration
    };

    enum RestrictOption_e
    {
        RestrictOptionVoIP,
        RestrictOptionCell,
        RestrictOptionSMS,
        RestrictOptionAll,
        UnknownOption, // MUST be last in the enumeration
    };

    enum AutoDialAttribute_e
    {
        AutoDialAttributePrefix, 
        AutoDialAttributeLength, 
        UnknownAutoDialAttribute, //MUST be last in the enumeration
    }; 

    enum DialPlanToken_e
    {
        DialPlanTokenHost,
    };

    struct XMLToken_t
    {
        const WCHAR* m_pName;
        ce::wstring m_Value;
    };

    enum FlushOperation_e
    {
        FlushOperationTransfer,
        FlushOperationDiscard,
        FlushOperationLast = FlushOperationDiscard,
    };

    // constants
    static const WCHAR sc_NameSpaceURI[];           // namespace for voip dial plan
    static const XMLElement_t sc_DialPlanElements[]; // supported XML elements
    static const WCHAR* sc_RuleAttributes[];        // supported Rule attributes
    static const WCHAR* sc_RestrictOptions[];       // supported options for restricted services
    static const WCHAR* sc_AutoDialAttributes[];    // suppported AutoDial attributes
    
    // DialPlanParser_t Flags
    static const DWORD PROCESSING_XML;              // enabled when parsing an XML
    static const DWORD VALIDATE_XML_ONLY;           // enabled when parser should only validate the XML (avoid allocations)
    static const DWORD FLUSHED_NEW_RULES;           // if this flag is disabled, parser cannot process a new XML
                                                    // ProcessXML's caller (on success) is responsible of calling FlushNewDialingRules
                                                    // to flush the new rules

    // members
    ULONG m_RefCount;
    DWORD m_Flags;                                  // DialPlanParser_t Flags
    ce::list<DialPlanElement_e> m_ElementsStack;    // stack of XML elements (for parsing)
    IRegularExpression_t* m_pIRegularExpressionParser; // used to validate all rules (valid when processing XML)
    DialingRuleQueue m_NewDialingRules;             // queue for the rules generated after succesful processing of XML
    AutoDialRuleQueue m_NewAutoDialRules;           // queue for the auto dial rules generated after successful processing of XML
    XMLToken_t m_XMLTokens[1];                      // replace tokens - host (sip:user@$host$)

public:
    // static functions
    static
    HRESULT CreateDialPlanParser(
        __deref_out_opt DialPlanParser_t** ppNewDialPlanParser
        );

    // member functions
    // Destructor
    ~DialPlanParser_t();

    // Validates dial plan XML
    HRESULT
    ValidateDialPlan(
        __in BSTR DialPlan
        );

    // IUnknown methods
    ULONG
    STDMETHODCALLTYPE
    AddRef(
        void
        );

    ULONG
    STDMETHODCALLTYPE
    Release(
        void
        );

    HRESULT
    STDMETHODCALLTYPE
    QueryInterface(
        REFIID riid,
        __deref_out_opt void** ppvObject
        );

    // ISAXContentHandler methods
    HRESULT
    STDMETHODCALLTYPE
    characters( 
        /* [in] */ __in_ecount_opt(cchChars) const wchar_t *pwchChars,
        /* [in] */ int cchChars
        );

    HRESULT
    STDMETHODCALLTYPE
    endDocument(
        void
        );

    HRESULT
    STDMETHODCALLTYPE
    endElement(
        /* [in] */ __in_ecount(cchNamespaceUri) const wchar_t *pwchNamespaceUri,
        /* [in] */ int cchNamespaceUri,
        /* [in] */ __in_ecount(cchLocalName) const wchar_t *pwchLocalName,
        /* [in] */ int cchLocalName,
        /* [in] */ __in_ecount_opt(cchQName) const wchar_t *pwchQName,
        /* [in] */ int cchQName
        );

    HRESULT
    STDMETHODCALLTYPE
    startDocument(
        void
        );

    HRESULT
    STDMETHODCALLTYPE
    startElement(
        /* [in] */ __in_ecount(cchNamespaceUri) const wchar_t *pwchNamespaceUri,
        /* [in] */ int cchNamespaceUri,
        /* [in] */ __in_ecount(cchLocalName) const wchar_t *pwchLocalName,
        /* [in] */ int cchLocalName,
        /* [in] */ __in_ecount_opt(cchQName) const wchar_t *pwchQName,
        /* [in] */ int cchQName,
        /* [in] */ __in_opt ISAXAttributes *pAttributes
        );

private:
    friend
    HRESULT
    DialEngine_t::UpdateDialPlan(
        void
        );

    friend
    static
    HRESULT
    DialEngine_t::CleanUpDialingRuleQueue(
        DialingRuleQueue*   pThisRules
        );

    friend
    static
    HRESULT
    DialEngine_t::CleanUpAutoDialRuleQueue(
        AutoDialRuleQueue*  pThisRules
        ); 

    // static functions

    // Cleans up the given DialingRuleQueue
    static
    HRESULT
    CleanUpDialingRuleQueue(
        __in DialingRuleQueue *pThisRules
        );

    // Cleans up the given AutoDialRuleQueue
    static
    HRESULT
    CleanUpAutoDialRuleQueue(
        __in AutoDialRuleQueue *pThisRules
        );

    // Gets type of dial plan element
    static
    HRESULT
    GetElementType(
        __in_ecount_opt(ElementNameLength) const WCHAR *pElementName,
        int ElementNameLength,
        __out DialPlanElement_e *pElementType
        );

    // Gets type of rule attribute
    static
    HRESULT
    GetRuleAttributeType(
        __in_ecount_opt(AttributeNameLength) const WCHAR *pAttributeName,
        int AttributeNameLength,
        __out DialingRuleAttribute_e* pRuleAttributeType
        );

    // Gets type of auto dial attribute
    static
    HRESULT
    GetAutoDialAttributeType(
        __in_ecount_opt(AttributeNameLength) const WCHAR *pAttributeName,
        int AttributeNameLength,
        __out AutoDialAttribute_e* pRuleAttributeType
        );

    // Validates a boolean attribute
    static
    HRESULT
    ValidateBooleanAttribute(
        __in_ecount(AttributeValueLength) const WCHAR *pAttributeValue,
        int AttributeValueLength,
        __out bool *pEnabled
        );

    // Debug functions
    static
    void
    DebugDumpDialingRuleQueue(
        __in DialingRuleQueue*  pThisRules
        );

    static 
    void
    DebugDumpAutoDialRuleQueue(
        __in AutoDialRuleQueue* pThisRules
        ); 

    // member functions

    // Constructor
    DialPlanParser_t();

    // Duplicates a template string
    HRESULT
    DuplicateTemplateString(
        __in_ecount(AttributeValueLength) const WCHAR *pAttributeValue,
        int AttributeValueLength,
        __deref_out_opt BSTR* pTemplateString
        );

    // Flushes the new rules
    HRESULT
    FlushNewRules(
        FlushOperation_e Operation,
        __out_opt DialingRuleQueue*  pDialingRuleQueue = NULL, 
        __out_opt AutoDialRuleQueue* pAutoDialQueue = NULL
        );

    // verifies hierarchy for an XMLElement_t 
    bool
    IsXMLElementHierarchyValid(
        __in const XMLElement_t* pThisElement
        );

    // Parses a dialing rule element and processes it at the same time
    HRESULT
    ProcessDialingRule(
        __in ISAXAttributes *pAttributes
        );

    // Parses a auto dial element and process it at the same time
    HRESULT
    ProcessAutoDial(
        __in ISAXAttributes *pAttributes
        );


    // Parses the XML and processes it at the same time
    HRESULT
    ProcessXML(
        __in BSTR DialPlan,
        BOOL ValidateOnly = FALSE
        );

    // Validates a regular expression attribute
    HRESULT
    ValidateRegularExpressionAttribute(
        __in_ecount(AttributeValueLength) const WCHAR *pAttributeValue,
        int AttributeValueLength,
        __deref_out_opt BSTR* pRegexString
        );

};

#endif /* __DIALPLANPARSER_HPP__ */

⌨️ 快捷键说明

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