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

📄 tmapr.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//
// 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:    tmapr.cpp
// 
// Contents:
//
//  implementation file 
//
//        ITypeMapper classes  implemenation
//    
//
//-----------------------------------------------------------------------------
#include "headers.h"
#include "soapmapr.h"
#include "typemapr.h"
#include "utctime.h"
#include <math.h>
#include <limits.h>

#ifdef UNDER_CE
#include "WinCEUtils.h"
#include <windows.h>
#endif


static const WORD isSafe[128] =

    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0,    /* 2x   !"#$%&'()*+,-./  */
     3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0,    /* 3x  0123456789:;<=>?  */
     0, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1,    /* 4x  @ABCDEFGHIJKLMNO  */
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,    /* 5X  PQRSTUVWXYZ[\]^_  */
     0, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1,    /* 6x  `abcdefghijklmno  */
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0};   /* 7X  pqrstuvwxyz{|}~  DEL */

static const WCHAR hex[] = L"0123456789ABCDEF";


HRESULT defineNamespace(ISoapSerializer* pSoapSerializer, BSTR *pPrefix, const WCHAR * pNamespace1);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:HRESULT defineNamespace( ISoapSerializer* pSoapSerializer,  BSTR *pPrefix, const WCHAR * pNamespace1)
//
//  parameters:
//
//  description:
//      This function can be used the retrieve and or define a namespace.
//      on return the prefix is stored in  pPrefix
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT defineNamespace(
                ISoapSerializer* pSoapSerializer,
                BSTR *pPrefix,
                const WCHAR * pNamespace1)
{
    HRESULT hr = S_OK;

    *pPrefix = NULL;
    
    // is the first namespace defined
    pSoapSerializer->getPrefixForNamespace((BSTR) pNamespace1, pPrefix);
    if (!(*pPrefix))
    {
        CHK(pSoapSerializer->SoapNamespace( (BSTR)g_pwstrEmpty, (BSTR)pNamespace1));
        CHK(pSoapSerializer->getPrefixForNamespace( (BSTR)pNamespace1, pPrefix));
    }

Cleanup:
    ASSERT (SUCCEEDED(hr));
    return hr;
}





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: static inline BOOL _NoEscapeInUri(char b)
//
//  parameters:
//
//  description:
//
//  returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static inline BOOL _NoEscapeInUri(char b)
{
    return (isSafe[b] & 1);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: static inline BOOL _IsHex(char b) 
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static inline BOOL _IsHex(char b) 
{
    return (isSafe[b] & 2);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: static BOOL inline _IsEscaped(WCHAR *pch) 
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static BOOL inline _IsEscaped(WCHAR *pch)
{
    if (pch[0] > 127 || pch[1] > 127)
        return FALSE;
    return (_IsHex((char) pch[0]) && _IsHex((char) pch[1]) ? TRUE : FALSE);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: static WORD _HexToWord(char c) 
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static WORD _HexToWord(char c)
{
    if(c >= '0' && c <= '9')
        return (WORD) c - '0';
    if(c >= 'A' && c <= 'F')
        return (WORD) c - 'A' + 10;
    if(c >= 'a' && c <= 'f')
        return (WORD) c - 'a' + 10;

    ASSERT(FALSE);  //we have tried to use a non-hex number
    return (WORD) -1;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: static WCHAR _TranslateEscaped(WCHAR * pch)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////

static WCHAR _TranslateEscaped(WCHAR * pch)
{
    WCHAR ch;

    ch = (WCHAR) _HexToWord((char)*pch++) * 16; // hi nibble
    ch += _HexToWord((char)*pch); // lo nibble

    return ch;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: static HRESULT _EscapeURI(WCHAR * pSource, WCHAR * pTarget)
//
//  parameters:
//
//  description:
//        URI-encodes the source into target, assumes the target buffer is big enough ( 3* len(source))
//     in error case target contents is undefined, but 0-terminated
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static HRESULT _EscapeURI(WCHAR * pSource, WCHAR * pTarget)
{
    while (*pTarget = *pSource)
    {
        if (*pSource > 127)
            {
            *pTarget =0;
            return E_FAIL;
            }
            
            
        char c = (char)*pSource++;
        
        if (_NoEscapeInUri(c))
        {
            pTarget++;
        }
        else
        {
            *pTarget++ = (WCHAR) '%';
            *pTarget++ = hex[(c >> 4) & 15];
            *pTarget++ = hex[c & 15];
        }
    }
    return S_OK;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: static HRESULT _UnescapeURI(WCHAR * pSource)
//
//  parameters:
//
//  description:
//
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static HRESULT _UnescapeURI(WCHAR * pSource)
{
    HRESULT hr = S_OK;
    WCHAR *pTarget = pSource;

    while (*pTarget = *pSource ++)
    {
        if (*pTarget == '%')
        {
            if (_IsEscaped(pSource))
            {
                *pTarget = _TranslateEscaped(pSource);
                pSource += 2;
            }
            else
                hr = E_FAIL;
        }
        pTarget ++;
    }
    return hr;
}


 
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CStringMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
//
//  parameters:
//
//  description:
//      reading a string out of a soap message
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CStringMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
{
    HRESULT hr=S_OK;
    CAutoBSTR bstrText;
    CAutoRefc<IXMLDOMNode> pNodeOfMapper(_pNodeOfMapper);

    // make sure we got a node
    CHK_BOOL(pNodeOfMapper, E_INVALIDARG);
    // and create an additional refcount, since we are handling it in a CAutoRefc
    pNodeOfMapper->AddRef();

    // follow the Href if necessary
    CHK (FollowHref(&pNodeOfMapper));
    
    // now we have the right guy, get text
    CHK(pNodeOfMapper->get_text(&bstrText));
    
    // now let's put this guy into our comobject
    V_VT(pvar) = VT_BSTR;
    V_BSTR(pvar) = bstrText;

    // the variant took ownership of the bstr
    bstrText.PvReturn();


Cleanup: 
    ASSERT(SUCCEEDED(hr));
    
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CStringMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
//
//  parameters:
//
//  description:
//      mapping a string into a soap message
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CStringMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
{
    HRESULT hr;
    CVariant varChanged;

    CHK (ConvertData(*pvar, (VARIANT *)&varChanged, VT_BSTR));
    CHK( pSoapSerializer->writeString(V_BSTR(&varChanged)));    

Cleanup:
    ASSERT(SUCCEEDED(hr));
    
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CBoolMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
//
//  parameters:
//
//  description:
//      reading a string out of a soap message
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CBoolMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
{
    HRESULT hr = S_OK;
    CVariant cvar;
    CAutoBSTR bstrText;
    CAutoRefc<IXMLDOMNode> pNodeOfMapper(_pNodeOfMapper);

    // make sure we got a node
    CHK_BOOL(pNodeOfMapper, E_INVALIDARG);
    // and create an additional refcount, since we are handling it in a CAutoRefc
    pNodeOfMapper->AddRef();

    // follow the Href if necessary
    CHK (FollowHref(&pNodeOfMapper));


    // now we have the right guy, get text
    CHK(pNodeOfMapper->get_text(&bstrText));
    
    CHK (cvar.Assign(bstrText, false));    // now let's put this guy into our comobject
    bstrText.PvReturn();              // the variant took ownership of the bstr
    
    CHK (ConvertData((VARIANT)cvar, pvar, VT_BOOL));

Cleanup:
    ASSERT(SUCCEEDED(hr));
    
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CBoolMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
//
//  parameters:
//
//  description:
//      mapping a string into a soap message
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CBoolMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
{
    HRESULT hr=S_OK;
    CVariant varChanged;

    CHK (ConvertData(*pvar, (VARIANT *)&varChanged, VT_BOOL));

    if (V_BOOL(&varChanged) == VARIANT_TRUE)
        CHK( pSoapSerializer->writeString((BSTR)g_pwstrSOAPtrue))
    else
        CHK( pSoapSerializer->writeString((BSTR)g_pwstrSOAPfalse));

Cleanup:
    ASSERT(SUCCEEDED(hr));
    
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////

   

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CDoubleMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags,  VARIANT * pvar)
//
//  parameters:

⌨️ 快捷键说明

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