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

📄 request.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//+----------------------------------------------------------------------------
//
// 
// File:   request.cpp
// 
// Contents:
//
//  ISAPI Extension that services SOAP packages.
//
//-----------------------------------------------------------------------------
#ifdef UNDER_CE
#include "WinCEUtils.h"
#endif

#include "isapihdr.h"


////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CRequest::Validate()
//
//  parameters:
//          
//  description:
//          Validates that the input message is a valid soap message
//  returns:
//          
////////////////////////////////////////////////////////////////////////////////////////////////////

HRESULT CRequest::Validate()
{
    // Anything that requires path/input validation will go here

    // Check against max POST size
    if(!stricmp(m_pECB->lpszMethod, "POST"))
    {
        if (m_pECB->cbTotalBytes > g_cbMaxPost)
        {
            m_pIStreamOut.SetErrorCode(Error_BadRequest);
            return E_ACCESSDENIED;
        }
    }
    return S_OK;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CRequest::ProcessParams()
//
//  parameters:
//          
//  description:
//           
//  returns:
//          
////////////////////////////////////////////////////////////////////////////////////////////////////

HRESULT CRequest::ProcessParams()
{

    return S_OK;

}

////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CRequest::GetHeaderParam(char *pstrHdr)
//
//  parameters:
//          
//  description:
//      Obtains the requested header value from the HTTP headers stream
//  returns:
//          
////////////////////////////////////////////////////////////////////////////////////////////////////
BSTR CRequest::GetHeaderParam(char *pstrHdr)
{
    char *pstr;
    char tempbuf[ONEK + 1];
    char tempbuf2[sizeof(WCHAR) * ONEK + 2];
    WCHAR   *pwstr;
    DWORD   cbSize = sizeof(tempbuf);
    DWORD   cchLen;
    BSTR    bstrValue;

    cchLen = strlen(pstrHdr);
    if (cchLen > (ONEK - 5))
        return NULL;
    strcpy(tempbuf2, "HTTP_");
    strncat(tempbuf2, pstrHdr, ONEK);
    if (m_pECB->GetServerVariable(m_pECB->ConnID, tempbuf2, (char *)tempbuf, &cbSize))
    {
        if (cbSize > ONEK)
            cbSize = ONEK;
        tempbuf[cbSize] = 0;
        cchLen = strlen(tempbuf);
        pstr = tempbuf;
        // Remove the quotes
        if ((*pstr == '\'') || (*pstr == '"'))
        {
            pstr++;
            cchLen -=2;
            pstr[cchLen] = 0;
        }    
        // Convert it to WCHAR and put it in a BSTR
        pwstr = (WCHAR *)tempbuf2;
        cchLen = CwchMultiByteToWideChar(0, pstr, cchLen, pwstr, ONEK);
        pwstr[cchLen] = 0;
        bstrValue = ::SysAllocString(pwstr);
        return bstrValue;
    }        
    return (BSTR)NULL;
}


////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CRequest::ProcessPathInfo()
//
//  parameters:
//          
//  description:
//      Get the vname, convert the vname to physical path name
//          for the WSDL and WSML files
//  returns:
//          
////////////////////////////////////////////////////////////////////////////////////////////////////

HRESULT CRequest::ProcessPathInfo()
{

    char *          pszPathInfo = m_pECB->lpszPathInfo; 
    char *          pszPathTranslated = m_pECB->lpszPathTranslated;
    
#ifndef UNDER_CE
    ULONG           cbFileLen;
    char            szApplPath[FOURK+1];
    DWORD           cchApplPath = FOURK;
    char *          psz;
    char            szApplMDPath[ONEK+1];
    DWORD           cchApplMDPath = ONEK;
    char            szURL[FOURK+1];
#else //in CE we have a 4k guard page, so moving these stack
      //allocations onto the heap
    char            *szApplPath = new char[FOURK+1];
    DWORD           cchApplPath = FOURK;
    char            *szApplMDPath = new char[ONEK+1];
    DWORD           cchApplMDPath = ONEK;
    HRESULT         hr = E_FAIL;
    
    CHK_MEM(szApplPath);
    CHK_MEM(szApplMDPath);
#endif 
    



    // We process two types of URLs
    //  1 - http://servername/virtualdirname/.../soapisap.dll
    //  2 - http://servername/virtualdirname/.../filename.wsdl
    //  In case 1, the virtualdirname is the name of the WSDL file
    //  In case 2, the filename.wsdl is the name of the WSDL file
    //  In both cases the WSDL file should be located in the directory 
    //  pointed by the URL.
    
    // Construct the WSDL file path & name
    if (pszPathInfo && *pszPathInfo)
    {
        // We have a .wsdl file in the URL
        cchApplPath = strlen(pszPathTranslated);
        if ((cchApplPath > FOURK) || (cchApplPath < 5) ||   
            (_strnicmp(&(pszPathTranslated[cchApplPath - 5]), ".WSDL", 5)))
        {
            m_pIStreamOut.SetErrorCode(Error_BadRequest);
#ifndef UNDER_CE
            return E_INVALIDARG;
#else       
            hr = E_INVALIDARG;
            goto Cleanup;
#endif 
        }        
        strncpy(szApplPath, pszPathTranslated, cchApplPath+1);
    }
    else
    {
        // URL with soapisap.dll 
        // Get the physical path for the virtual directory
        m_pECB->GetServerVariable(
            m_pECB->ConnID, "APPL_PHYSICAL_PATH", szApplPath, &cchApplPath);
        //
        // Get the application meta directory path
        // The last section in this path gives us the vname, which should be
        //  the same as WSDL file name.
        m_pECB->GetServerVariable(
            m_pECB->ConnID, "APPL_MD_PATH", szApplMDPath, &cchApplMDPath);
            
        ForwardToBackslash(szApplMDPath);
        cchApplMDPath--;
        if (szApplMDPath[cchApplMDPath] == 0)
            cchApplMDPath--;  // Point to last character before NULL
        while ((cchApplMDPath > 0) && (szApplMDPath[cchApplMDPath] != '\\'))
        {
            cchApplMDPath--;
        }
        if (cchApplMDPath > 0)
            cchApplMDPath++;    
        
        ForwardToBackslash(szApplPath);
        cchApplPath--;
        if (szApplPath[cchApplPath] == 0)
            cchApplPath--;  // Point to last character before NULL
        if ((cchApplPath > 0) && (szApplPath[cchApplPath] != '\\'))
            szApplPath[cchApplPath] = '\\';
        cchApplPath++;    
        while((cchApplPath < FOURK-6) && (szApplMDPath[cchApplMDPath] != '\0'))
            szApplPath[cchApplPath++] = szApplMDPath[cchApplMDPath++];
        ASSERT(cchApplPath + 5 < FOURK);   
        szApplPath[cchApplPath++] = '.' ;
        szApplPath[cchApplPath++] = 'W' ;
        szApplPath[cchApplPath++] = 'S' ;
        szApplPath[cchApplPath++] = 'D' ;
        szApplPath[cchApplPath++] = 'L' ;
        szApplPath[cchApplPath] = '\0' ;
    }    
    if (cchApplPath < 2) 
    {
        ASSERT(FALSE);
        m_pIStreamOut.SetErrorCode(Error_BadRequest);       
#ifndef UNDER_CE
        return E_INVALIDARG;
#else   
        hr = E_INVALIDARG;
        goto Cleanup;
#endif 
    }    
    m_pszWSDLFilePath = new char[cchApplPath+1];    
    m_pszWSMLFilePath = new char[cchApplPath+1];
    if ((m_pszWSMLFilePath == NULL) || (m_pszWSMLFilePath == NULL))
    {
        ASSERT(FALSE);
        m_pIStreamOut.SetErrorCode(Error_BadRequest);               
#ifndef UNDER_CE
        return E_OUTOFMEMORY;
#else
        hr = E_OUTOFMEMORY;
        goto Cleanup;
#endif 
    }
    strcpy(m_pszWSDLFilePath, szApplPath);
    strcpy(m_pszWSMLFilePath, szApplPath);
    m_pszWSMLFilePath[cchApplPath - 2] = 'm';
    
#ifdef UNDER_CE
    hr = S_OK;
Cleanup:
    if(szApplPath)
        delete [] szApplPath;
    if(szApplMDPath)
        delete [] szApplMDPath;
        
    return hr;
#else
    return S_OK;
#endif 
 
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: CRequest::ExecuteRequest()
//
//  parameters:
//          
//  description:
//          Executes the given request
//  returns:
//          
////////////////////////////////////////////////////////////////////////////////////////////////////

HRESULT CRequest::ExecuteRequest()
{
    HRESULT     hr = S_OK;
    VARIANT      varInput;
    CObjCache *  pObjCache = m_pThreadInfo->pObjCache;
    CThdCachedObj *pCachedObj = NULL;
    OBJ_STATE      objstate;
    CAutoBSTR    bstrSoapAction;
    CAutoRefc<IStream> pIStrmOut;

    
    VariantInit(&varInput);
    
    // Find out if we already have a cached SoapServer object
    //  servicing this file
    ASSERT(pObjCache);

    objstate = pObjCache->Find (m_pszWSDLFilePath, (void **) &pCachedObj);
    switch (objstate)
    {
    case OBJ_OK:
        // Everything is OK. We use this object
        ASSERT(pCachedObj);
        break;

⌨️ 快捷键说明

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