📄 tmapr.cpp
字号:
goto Cleanup;
}
hr = saveList(pISoapSerializer, pChildren);
Cleanup:
ASSERT(hr==S_OK);
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CDOMMapper::saveList(ISoapSerializer *pISoapSerializer, IXMLDOMNodeList *pNodeList)
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CDOMMapper::saveList(ISoapSerializer *pISoapSerializer, IXMLDOMNodeList *pNodeList)
{
HRESULT hr = S_OK;
CAutoRefc<IXMLDOMNode> pChild=0;
if (pNodeList)
{
CHK(pNodeList->reset());
while (pNodeList->nextNode(&pChild)==S_OK && pChild)
{
hr = saveNode(pISoapSerializer, pChild);
if (FAILED(hr))
{
goto Cleanup;
}
pChild.Clear();
}
}
Cleanup:
ASSERT(hr==S_OK);
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CDOMMapper::saveAttributes(ISoapSerializer *pISoapSerializer, IXMLDOMNode *pNode)
//
// parameters:
//
// description:
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CDOMMapper::saveAttributes(ISoapSerializer *pISoapSerializer, IXMLDOMNode *pNode)
{
HRESULT hr = S_OK;
CAutoRefc<IXMLDOMNamedNodeMap> pIXMLDOMNamedNodeMap = 0;
CAutoRefc<IXMLDOMNode> pAttrNode=0;
hr = pNode->get_attributes(&pIXMLDOMNamedNodeMap);
if (FAILED(hr) || pIXMLDOMNamedNodeMap == 0)
{
goto Cleanup;
}
while (pIXMLDOMNamedNodeMap->nextNode(&pAttrNode)==S_OK && pAttrNode != 0)
{
hr = saveNode(pISoapSerializer, pAttrNode);
if (FAILED(hr))
{
goto Cleanup;
}
pAttrNode.Clear();
}
Cleanup:
ASSERT(hr==S_OK);
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CURIMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags, VARIANT * pvar)
//
// parameters:
//
// description:
// reading a string out of a soap message
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CURIMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags, VARIANT * pvar)
{
HRESULT hr = S_OK;
CAutoBSTR bstrText;
CAutoRefc<IXMLDOMNode> pNode(NULL);
CAutoBSTR bstrFinal;
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 (_UnescapeURI(bstrText));
// now we need to copy the final to get the correct LENGTH of the string
// in order for BSTR compares
CHK (bstrFinal.Assign(bstrText));
V_VT(pvar) = VT_BSTR;
V_BSTR(pvar) = bstrFinal; // now let's put this guy into our variant
bstrFinal.PvReturn(); // the variant took ownership of the bstr
Cleanup:
ASSERT(SUCCEEDED(hr));
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CURIMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags, VARIANT * pvar)
//
// parameters:
//
// description:
// mapping a string into a soap message
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CURIMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags, VARIANT * pvar)
{
HRESULT hr=S_OK;
WCHAR *pResult = L"";
BSTR bstr = NULL;
ULONG ulLen = 0;
CHK_BOOL(V_VT(pvar) == VT_BSTR, E_INVALIDARG);
bstr = V_BSTR(pvar);
ulLen = wcslen(bstr);
if (ulLen > 0)
{
ulLen = ulLen*3+1;
#ifndef UNDER_CE
pResult = (WCHAR *) _alloca(ulLen * 2);
#else
__try{
pResult = (WCHAR *) _alloca(ulLen * 2);
}
__except(1){
return E_OUTOFMEMORY;
}
#endif
CHK (_EscapeURI (bstr, pResult));
}
CHK( pSoapSerializer->writeString((BSTR)pResult ));
Cleanup:
ASSERT(SUCCEEDED(hr));
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CBinaryMapper::init(ISoapTypeMapperFactory *ptypeFactory, IXMLDOMNode * pSchema, enXSDType xsdType)
//
// parameters:
//
// description:
// for schemas before 2001 it
// checks if the passed in schemanode is
// a) a restriction base node
// b) specifies the supported bin64 encoding
// in 2001 this should only be called for the correct type
// returns:
// S_OK
// E_FAIL if wrong schema
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CBinaryMapper::init(ISoapTypeMapperFactory *ptypeFactory, IXMLDOMNode * pSchema, enXSDType xsdType)
{
HRESULT hr = S_OK;
CAutoRefc<IXMLDOMNode> pNode;
CAutoBSTR bstrEncoding;
// we should only initialize once
// check for needed parameter
CHK_BOOL(ptypeFactory, E_INVALIDARG);
// start initializing
CHK(CTypeMapper::init(ptypeFactory, pSchema, xsdType));
CHK(_XSDFindRevision(pSchema, &m_enRevision));
if (m_enRevision == enSchema1999 || m_enRevision == enSchema2000)
{
XPathState xp;
CAutoFormat autoFormat;
CHK (xp.init(pSchema));
CHK(autoFormat.sprintf(L"xmlns:schema='%s'", _XSDSchemaNS(m_enRevision)));
CHK (xp.addNamespace(&autoFormat));
showNode(pSchema);
CHK(pSchema->selectSingleNode(_T("descendant-or-self::schema:simpleType/schema:restriction/schema:encoding"), &pNode));
if (pNode)
{
CHK(_WSDLUtilFindAttribute(pNode, _T("value"), &bstrEncoding));
if (_tcscmp(bstrEncoding, _T("base64")) != 0)
{
CHK(E_INVALIDARG);
}
}
}
Cleanup:
ASSERT(SUCCEEDED(hr));
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CBinaryMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags, VARIANT * pvar)
//
// parameters:
//
// description:
// reading a string out of a soap message
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CBinaryMapper::read(IXMLDOMNode *_pNodeOfMapper, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags, VARIANT * pvar)
{
HRESULT hr = S_OK;
CAutoBSTR bstrText;
#ifndef UNDER_CE
BYTE * pbOut(NULL);
#else
BYTE *pbOut = NULL;
#endif
DWORD dwOut;
UINT uiLen;
BYTE HUGEP *pbBytes;
SAFEARRAYBOUND rgsabound[1];
#ifndef UNDER_CE
SAFEARRAY *psa(NULL);
#else
SAFEARRAY *psa = NULL;
#endif
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));
uiLen=::SysStringLen(bstrText);
// only if we have some data, we will create the array, otherwise we will create NULL array
if (uiLen > 0)
{
pbOut = new BYTE[uiLen];
CHK_BOOL (pbOut, E_OUTOFMEMORY);
dwOut = uiLen;
if (Base64DecodeW(bstrText, uiLen, pbOut, &dwOut)!= ERROR_SUCCESS)
{
hr = E_FAIL;
goto Cleanup;
}
// now create a SafeArray back out of the decoded values
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = dwOut;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
CHK_BOOL(psa, E_OUTOFMEMORY);
CHK(SafeArrayAccessData(psa, (void HUGEP **) &pbBytes))
memcpy(pbBytes, pbOut, dwOut);
CHK(SafeArrayUnaccessData(psa));
}
V_VT(pvar) = VT_ARRAY | VT_UI1;
V_ARRAY(pvar) = psa;
Cleanup:
ASSERT(SUCCEEDED(hr));
delete [] pbOut;
return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function: HRESULT CBinaryMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags, VARIANT * pvar)
//
// parameters:
//
// description:
// mapping a string into a soap message
//
// returns:
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CBinaryMapper::write(ISoapSerializer* pSoapSerializer, BSTR bstrEncoding, enEncodingStyle enStyle, long lFlags, VARIANT * pvar)
{
HRESULT hr=S_OK;
DWORD dwIn;
DWORD dwOut;
CAutoBSTR pbstrValue;
BYTE HUGEP *pbBytes;
long lUBound;
long lLBound;
SAFEARRAY *psa;
VARTYPE vartype;
if (V_ISBYREF(pvar))
{
psa = *V_ARRAYREF(pvar);
vartype = V_VT(pvar) & ~VT_BYREF;
}
else
{
psa = V_ARRAY(pvar);
vartype = V_VT(pvar);
}
CHK_BOOL(vartype == (VT_ARRAY | VT_UI1), E_INVALIDARG);
if (psa)
{
// the array can actually be NULL, we will just not output any data in that case
CHK_BOOL((SafeArrayGetDim(psa)==1), E_INVALIDARG);
CHK(SafeArrayGetUBound(psa, 1, &lUBound));
CHK(SafeArrayGetLBound(psa, 1, &lLBound));
dwIn = lUBound - lLBound + 1;
// Allocate enough memory for full final translation quantum.
dwOut = ((dwIn + 2) / 3) * 4;
// and enough for CR-LF pairs for every CB_BASE64LINEMAX character line.
dwOut += 2 * ((dwOut + 64 - 1) / 64);
CHK(pbstrValue.AllocBSTR(dwOut));
CHK(SafeArrayAccessData(psa, (void HUGEP **) &pbBytes))
CHK_BOOL (Base64EncodeW(pbBytes, dwIn, pbstrValue, &dwOut)==ERROR_SUCCESS, E_FAIL);
CHK(SafeArrayUnaccessData(psa));
CHK(pSoapSerializer->writeString(pbstrValue));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -