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

📄 exchangerequest.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 "ExchangeRequest.h"
#include "DataItemArray.h"
#include <msxml2.h>
#include "ExchangeClient.h"
#include "..\baseclass\FormatHandler.h"
#include "XMLDataRecordParser.h"
#include "RequestParameters.h"
#include "HttpCodes.h"
#include "Settings.h"
#include "utilities.h"
#include "SecurityUtils.h"

#ifdef DEBUG
    const WCHAR *c_rgstrStatus[] =
    {
        L"e_ecrsPending",
        L"e_ecrsInProgress",
        L"e_ecrsSending",
        L"e_ecrsBypassingOWAPage",
        L"e_ecrsSucceeded",
        L"e_ecrsOutOfMemory",
        L"e_ecrsParseFailed",
        L"e_ecrsHttpFailure",
        L"e_ecrsFailedToSend",
        L"e_ecrsFailedToBypassAuthPage",
        L"e_ecrsCancelled",
        L"e_ecrsNoCredentials",
    };
#endif //DEBUG

/*------------------------------------------------------------------------------
    CExchangeClientRequest::CExchangeClientRequest
    
    Constructor
------------------------------------------------------------------------------*/
CExchangeClientRequest::CExchangeClientRequest()
{
    MemTrackAdd();
    TRACE_(ZONE_OWAEC_TRACING_CTOR);
    m_Status          = e_ecrsPending;
    m_Type            = e_ecrtInvalid;
    m_lHttpStatus     = 0;
    m_pDataRecordList     = NULL;
    m_pClient         = NULL;
    m_piFormatHandler = NULL;
    m_fCanceled       = 0;
    
}

/*------------------------------------------------------------------------------
    CExchangeClientRequest::~CExchangeClientRequest
    
    Destructor
------------------------------------------------------------------------------*/
CExchangeClientRequest::~CExchangeClientRequest()
{
    TRACE_(ZONE_OWAEC_TRACING_CTOR);
    MemTrackRemove();
    
    SafeRelease(m_piFormatHandler);
    SafeRelease(m_pClient);
    SafeRelease(m_pDataRecordList);
}

/*------------------------------------------------------------------------------
    CExchangeClientRequest::Initialize
    
    Initializes this instance with the type, format handler and client to 
    callback into
------------------------------------------------------------------------------*/
HRESULT CExchangeClientRequest::Initialize(
    CExchangeClient * pClient, 
    IExchangeClientFormatHandler * piFormatHandler,
    ExchangeClientRequestType    ecrt
    )
{
    //Check params
    if (pClient == NULL || piFormatHandler == NULL)
    {
        return E_POINTER;
    }

    m_pClient = pClient;
    m_pClient->AddRef();

    m_piFormatHandler = piFormatHandler;
    m_piFormatHandler->AddRef();

    m_Type = ecrt;
    return S_OK;
}

/*------------------------------------------------------------------------------
    CExchangeClientRequest::GetStatus
    
    Get the current status of this request
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CExchangeClientRequest::GetStatus(
    ExchangeClientRequestStatus * pStatus
    )
{
    //Check params
    if (pStatus == NULL)
    {
        return E_POINTER;
    }
    *pStatus = m_Status;
    return S_OK;
}

/*------------------------------------------------------------------------------
    CExchangeClientRequest::GetType
    
    Get the type of this request
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CExchangeClientRequest::GetType(
    ExchangeClientRequestType * pType
    )
{
    //Check params
    if (pType == NULL)
    {
        return E_POINTER;
    }

    *pType = m_Type;
    return S_OK;
}

/*------------------------------------------------------------------------------
    CExchangeClientRequest::GetHttpStatus
    
    Get the latest http status associated with this request
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CExchangeClientRequest::GetHttpStatus(LONG * plHttpStatus)
{
    if (plHttpStatus == NULL)
    {
        return E_POINTER;
    }

    *plHttpStatus = m_lHttpStatus;
    return S_OK;
}

/*------------------------------------------------------------------------------
    CExchangeClientRequest::GetDataItemArray
    
    If this request succeeded, get the data associated with the request representing
    the results
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CExchangeClientRequest::GetDataItemArray(
    IExchangeClientDataItemArray * * ppiArray
    )
{
    //Check params
    if (ppiArray == NULL)
    {
        return E_POINTER;
    }

    *ppiArray = NULL;

    //Ensure that this request succeeded
    if (m_pDataRecordList == NULL || m_Status != e_ecrsSucceeded)
    {
        return OWAEC_E_NODATA; 
    }

    CComObject<CExchangeClientDataItemArray>  *pDataItemArrayObject  = NULL;
    HRESULT                                    hr                    = S_OK;  

    //Create the object
    hr = CComObject<CExchangeClientDataItemArray>::CreateInstance(&pDataItemArrayObject);

    //Set the correct properties
    if (SUCCEEDED(hr))
    {
        hr = pDataItemArrayObject->SetType(m_Type);
        ASSERT(SUCCEEDED(hr));
    }

    if (SUCCEEDED(hr))
    {
        hr = pDataItemArrayObject->SetDataRecordList(m_pDataRecordList);
        ASSERT(SUCCEEDED(hr));
    }

    //QI for the correct interface for the out param
    if (SUCCEEDED(hr))
    {
        hr = pDataItemArrayObject->QueryInterface(
            IID_IExchangeClientDataItemArray,
            reinterpret_cast<VOID**>(ppiArray)
            );
    }

    return hr;
}

/*------------------------------------------------------------------------------
    CExchangeClientRequest::UpdateStatus
    
    Update the internal status and post a callback message to the main thread
    
    Parameters:
        ecrs: The new status
------------------------------------------------------------------------------*/
HRESULT CExchangeClientRequest::UpdateStatus(
    ExchangeClientRequestStatus ecrs
    )
{
    DEBUGMSG(ZONE_OWAEC_TRACING_INFORMATIONAL, (L"OWAExchangeClient:: Request %08x updating status to %s", this, c_rgstrStatus[ecrs]));
    m_Status = ecrs;
    return m_pClient->CallbackOnMainThread(
        this, 
        ecrs
        );
}
/*------------------------------------------------------------------------------
    CExchangeClientRequest::Process
    
    Process this request - send the data and bypass the login page if necessary
------------------------------------------------------------------------------*/
HRESULT     CExchangeClientRequest::Process(
    IXMLHTTPRequest  *piHttpRequest,
    CXMLDataRecordParser *pParser
    )
{
    TRACE();
    //Internal API - all the params should be valid
    PREFAST_ASSERT(piHttpRequest && pParser);

    HRESULT       hr                  = S_OK;
    BOOL          fSuccessfulResponse = TRUE,
                  fTryLoginPage       = FALSE;

    ce::auto_bstr bstrResponse;

    WCHAR wszIgnoredDomUsername[2] = L"",
          wszIgnoredPassword   [2] = L"";
    //Ensure that there are credentials on the system
    if (! PhoneHasCredentials())
    {
        (VOID)UpdateStatus(e_ecrsNoCredentials);
        DEBUGMSG(ZONE_OWAEC_ERROR, (L"OWAExchangeClient:: No credentials"));
        hr = E_FAIL;
        goto error;
    }
    
    //Inform the caller that this request is being processed
    (VOID)UpdateStatus(e_ecrsInProgress);

    if (Canceled())
        goto cancel;

    //Try sending the request
    hr = SendRequest(piHttpRequest);
    if (FAILED(hr))
    {
        DEBUGMSG(ZONE_OWAEC_ERROR, (L"OWAExchangeClient:: Sending the request failed hr = 0x%x", hr));
        UpdateStatus(e_ecrsFailedToSend);
        goto error;
    }

    if (Canceled())
        goto cancel;
    
    //If we successfully got a response, but got the OWA login page as the response
    //POST to the login page and resend the request
    if (ResponseIsOWALoginPage(piHttpRequest))
    {
        fTryLoginPage = TRUE;
        (VOID)UpdateStatus(e_ecrsBypassingOWAPage);

⌨️ 快捷键说明

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