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

📄 dialengine.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 __DIALENGINE_HPP__
#define __DIALENGINE_HPP__

#include <windows.h>
#include <rtccore.h>
#include <atlbase.h>
#include <list.hxx>
#include "Settings.hpp"

//Modifying INCLUDE path in sources pulls in assert.h from private\apps\tele\inc
//instead of the SDK version in public\common\sdk\inc. Because of this a bunch
//of compile errors show up. Use relative path here as workaround to that issue.
#include "..\inc\regex.hpp"

//forward declaration
class VoIPApp_t;

// Dialing rule flags
#define DRF_TYPE_DIAL_STRING            0x0001 // enabled when rule defines dial string
#define DRF_TYPE_DISPLAY_STRING         0x0002 // enabled when rule defines display string
#define DRF_RESTRICT_OPTION_VOIP        0x0004 // enabled when rule blocks voip call
#define DRF_RESTRICT_OPTION_CELL        0x0008 // enabled when rule blocks cell call
#define DRF_RESTRICT_OPTION_SMS         0x0010 // enabled when rule blocks SMS messages
#define DRF_RESTRICT_OPTION_ALL         (DRF_RESTRICT_OPTION_VOIP | \
                                        DRF_RESTRICT_OPTION_CELL | \
                                        DRF_RESTRICT_OPTION_SMS) // enabled when rule blocks all options
#define DRF_TYPE_TRANSFER_STRING        0x0020 // enabled when rule defines transfer string

#define DRF_ALL_FLAGS_MASK              (DRF_TYPE_DIAL_STRING | \
                                        DRF_TYPE_DISPLAY_STRING | \
                                        DRF_TYPE_TRANSFER_STRING | \
                                        DRF_RESTRICT_OPTION_ALL) // mask for all supported flags

struct DialingRule_t
{
    IRegularExpression_t *m_pRegex;
    BSTR m_RegexString;
    BSTR m_DialString;
    BSTR m_DisplayString;
    BSTR m_TransferString;
    WORD m_Flags;

    // Cleans up the DialingRule_t structure
    HRESULT
    CleanUpDialingRule(
        void
        );

    // Flush the pre-compiled rules
    HRESULT
    FlushCompiledRegex(
        void
        ); 
};
typedef ce::list<DialingRule_t*> DialingRuleQueue;


struct AutoDialRule_t
{
    BSTR            m_Prefix; 
    unsigned int    m_PrefixLength; 
    unsigned int    m_TotalLength; 

    // Cleans up the AutoDialRule_t structure
    HRESULT
    CleanUpAutoDialRule(
        void
        ); 
}; 
typedef ce::list<AutoDialRule_t*> AutoDialRuleQueue; 

class DialEngine_t :
    public ISettingChangeHandler_t
{
private:
    enum FormatString_e
    {
        FormatStringToDial,
        FormatStringToDisplay,
        FormatStringToTransfer,
        FormatStringLast = FormatStringToTransfer,
    };

    enum SIPServerKeyword_e
    {
        SIPServerKeywordAddress,
        SIPServerKeywordHostName,
        SIPServerKeywordNone, // MUST be last in the enumeration
    };

    enum RegistryRegexAPI_e
    {
        RegexVoIPPhoneNumber,
        RegexSMSBlockedNumber,
    };

    // constants
    static const WCHAR      sc_DefaultDialPlan[];       // system file which defines the default dial plan
    static const WCHAR*     sc_SIPServerKeywords[];     // supported keywords used when formatting rules

    // members
    CComPtr<IRTCProfile>    m_cpRTCProfile;
    DialingRuleQueue*       m_pDialingRules;            // queue for the current dialing rules
    AutoDialRuleQueue*      m_pAutoDialRules;           // queue for the current autodial rules


public:
    //constants and enum's
    enum AccumulatorFormatResult_e
    {
        ResultDisregard = 0,
        ResultKeepAlways,
        ResultKeepIfIPCall,
    };

    // constants
    static const WCHAR sc_RegexNamePrefix[];            // prefix for regex names updated in the registry
    static const UINT sc_MinNumberOfDigits;             // minimum number of digits appended to regex names
    static const UINT sc_MaxRegexNameBuffer;            // maximum required buffer for regex names

    // member functions
    // Constructor/Destructor
    DialEngine_t();
    ~DialEngine_t();

    // Initializes the dial plan (uses custom plan if valid otherwise switches to default dial plan)
    HRESULT
    InitializeDialPlan(
        void
        );

    // UnInitializes the dial plan (removes dialing rules)
    HRESULT
    UnInitializeDialPlan(
        void
        );

    // Tells if user can only make cell calls to this number
    inline
    bool
    CanMakeCellularCall(
        __in const WCHAR *pDialString,
        int DialStringLength
        )
    {
        DWORD RestrictedServices;
        if (FAILED(GetPhoneNumberRestrictedServices(
                        pDialString,
                        DialStringLength,
                        &RestrictedServices
                        )))
        {
            return true;
        }
        return !(DRF_RESTRICT_OPTION_CELL & RestrictedServices);
    }

    // Tells if user can only make voip calls to this number
    inline
    bool
    CanMakeVoIPCall(
        __in const WCHAR *pDialString,
        int DialStringLength
        )
    {
        DWORD RestrictedServices;
        if (FAILED(GetPhoneNumberRestrictedServices(
                        pDialString,
                        DialStringLength,
                        &RestrictedServices
                        )))
        {
            return true;
        }
        return !(DRF_RESTRICT_OPTION_VOIP & RestrictedServices);
    }

    // Tells if user can send SMS messages to this number
    inline
    bool
    CanSendTextMessage(
        __in const WCHAR *pDialString,
        int DialStringLength
        )
    {
        DWORD RestrictedServices;
        if (FAILED(GetPhoneNumberRestrictedServices(
                        pDialString,
                        DialStringLength,
                        &RestrictedServices
                        )))
        {
            return true;
        }
        return !(DRF_RESTRICT_OPTION_SMS & RestrictedServices);
    }

    // Tells if this number is blocked for making calls
    inline
    bool
    IsPhoneNumberBlocked(
        __in const WCHAR *pDialString,
        int DialStringLength
        )
    {
        DWORD RestrictedServices;
        if (FAILED(GetPhoneNumberRestrictedServices(
                        pDialString,
                        DialStringLength,
                        &RestrictedServices
                        )))
        {
            return false;
        }
        return ((DRF_RESTRICT_OPTION_VOIP & RestrictedServices) &&
            (DRF_RESTRICT_OPTION_CELL & RestrictedServices));
    }

    bool
    IsPhoneNumberReadyForAutoDial(
        __in const WCHAR* pDialString
        ); 

    // Implements the ISettingChangeHandler_t interface
    HRESULT
    OnSettingsChange(
        DWORD SettingFlags
        );

    // Gets the phone numer to dial for a user dial string
    inline
    HRESULT
    GetPhoneNumberToDial(
        __in const WCHAR *pDialString,
        int DialStringLength,
        __in_opt IRTCProfile* pProfileToUse, //optional - if null use the "active" profile
        __deref_out_opt BSTR* pDialNumber
        )
    {
        return FormatPhoneNumber(
                        pDialString,
                        DialStringLength,
                        FormatStringToDial,
                        pProfileToUse,
                        pDialNumber
                        );
    }

    // Gets the phone numer to display for a user dial string
    inline
    HRESULT
    GetPhoneNumberToDisplay(
        __in const WCHAR *pDialString,
        int DialStringLength,
        __in_opt IRTCProfile*   pProfileToUse, //optional - if null use the "active" profile
        __deref_out_opt BSTR *pDisplayNumber
        )
    {
        return FormatPhoneNumber(
                        pDialString,
                        DialStringLength,
                        FormatStringToDisplay,
                        pProfileToUse, 
                        pDisplayNumber
                        );
    }

    // Gets the phone numer to transfer for a user dial string
    inline
    HRESULT
    GetPhoneNumberToTransfer(
        __in const WCHAR *pDialString,
        int DialStringLength,
        __deref_out_opt BSTR* pTransferNumber
        )
    {
        return FormatPhoneNumber(
                        pDialString,
                        DialStringLength,
                        FormatStringToTransfer,
                        NULL, //use default profile
                        pTransferNumber
                        );
    }

    // Update the current dial plan
    HRESULT
    UpdateDialPlan(
        void
        );

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

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

    // Release some cached resources 
    HRESULT
    ReleaseCachedResources(
        void
        ); 
    
private:

    // Finds first dialing rule which matches the user dial string
    // MUST have Lock ownership during entire use of the rule
    HRESULT
    FindMatch(
        __in_ecount(DialStringLength) const WCHAR* pDialString,
        int DialStringLength,
        __deref_out_opt const DialingRule_t** ppRuleFound
        );

    // Formats dial string based on dialing rules
    HRESULT
    FormatPhoneNumber(
        __in const WCHAR *pDialString,
        int DialStringLength,
        FormatString_e Format,
        __in_opt IRTCProfile* pProfileToUse,
        __deref_out_opt BSTR* pFormattedstring
        );

    // Gets restricted services for user dial string
    HRESULT
    GetPhoneNumberRestrictedServices(
        __in const WCHAR* pDialString,
        int DialStringLength,
        __out DWORD* pRestrictedServices
        );

    // Loads default plan from "\windows\dialplan.xml"
    HRESULT
    LoadDefaultDialPlan(
        __deref_out_opt BSTR *pDialPlanXML
        );

    // Loads custom plan from the registry
    HRESULT
    LoadCustomDialPlan(
        __deref_out_opt BSTR *pDialPlanXML
        );


    // Updates regular expresions in the registry (when dial plan is updated)
    void
    UpdateRegularExpressions(
        RegistryRegexAPI_e RegexAPI
        );
};

#endif /* __DIALENGINE_HPP__ */

⌨️ 快捷键说明

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