📄 formathandler.cpp
字号:
//
// 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 "FormatHandler.h"
#include "XMLDataRecordParser.h"
#include "RequestParameters.h"
/*------------------------------------------------------------------------------
CGenericFormatHandler::Initialize
Initializes the parseparameter parsing table
------------------------------------------------------------------------------*/
HRESULT CGenericFormatHandler::Initialize(
const ParseParameters * pParameters
)
{
if (pParameters == NULL)
{
return E_POINTER;
}
//ok to do a pointer copy since the struct is static const
m_pParameters = pParameters;
return S_OK;
}
/*------------------------------------------------------------------------------
CGenericFormatHandler::GetFormattedHttpParameters
For this given format handler - get the Http Parameters to be used in the
XMLHttpRequest -
Method - Method type to be sent in the header (e.g. GET, POST, SEARCH)
Url - Url to direct the request to (e.g. server.domain.com)
Body - Body of the http request
Default:
Must be overridden by subclasses
Returns:
E_NOTIMPL
------------------------------------------------------------------------------*/
HRESULT CGenericFormatHandler::GetFormattedHttpParameters(
BSTR * pbstrMethod,
BSTR * pbstrUrl,
BSTR * pbstrBody
)
{
return E_NOTIMPL;
}
/*------------------------------------------------------------------------------
CGenericFormatHandler::SetAdditionalHeaders
For the current XMLHttpRequest, sets any additional headers in the request
(for example: Content-Type:text/xml)
Default:
Additional headers are not necessary for this request
Returns:
S_FALSE
------------------------------------------------------------------------------*/
HRESULT CGenericFormatHandler::SetAdditionalHeaders(
IXMLHTTPRequest * piRequest
)
{
return S_FALSE;
}
/*------------------------------------------------------------------------------
CGenericFormatHandler::SetParsingFormat
Uses the internal parsing table to set the parsers datarecord and property tags
------------------------------------------------------------------------------*/
HRESULT CGenericFormatHandler::SetParsingFormat(
CXMLDataRecordParser * pParser
)
{
//Trusted internal function - assert on params
PREFAST_ASSERT(pParser != NULL);
//also assert that initialization was done correctly
PREFAST_ASSERT(m_pParameters != NULL);
HRESULT hr = S_OK;
//Set the "new datarecord" tag from the parse table
hr = pParser->SetNewDataRecordKeyword(m_pParameters->c_wszNewDataRecordName);
//Run through the mapping table and set the tag mapping
if (SUCCEEDED(hr))
{
const ParsePropertyMapping *pMapping = &(m_pParameters->c_rgPropertyMappings[0]);
while (SUCCEEDED(hr) && pMapping->c_wszProperty != NULL)
{
hr = pParser->SetDataRecordPropertyKeyword(
pMapping->idx,
pMapping->c_wszProperty
);
pMapping++;
}
}
ASSERT(SUCCEEDED(hr));
return hr;
}
/*------------------------------------------------------------------------------
CGenericFormatHandler::Initialize
Subclasses should perform necessary initializations here.
Default:
E_NOTIMPL
------------------------------------------------------------------------------*/
HRESULT CGenericFormatHandler::Initialize(
const WCHAR * c_wszServername,
VOID * pvParam
)
{
return E_NOTIMPL;
}
/*------------------------------------------------------------------------------
CGenericFormatHandler::SetAdditionalHeadersFromValue
Sets the additional headers from reg values if the headers exists
(are non-empty)
------------------------------------------------------------------------------*/
HRESULT CGenericFormatHandler::SetAdditionalHeadersFromValue(
IXMLHTTPRequest * piRequest,
const WCHAR * c_wszHeaderName,
const WCHAR * c_wszValue
)
{
PREFAST_ASSERT(piRequest && c_wszHeaderName && c_wszValue);
if (c_wszHeaderName[0] == L'\0' ||
c_wszValue[0] == L'\0'
)
{
return S_FALSE;
}
ce::auto_bstr bstrName, bstrValue;
HRESULT hr = S_OK;
bstrName = SysAllocString(c_wszHeaderName);
if (bstrName == NULL)
{
hr = E_OUTOFMEMORY;
}
if (SUCCEEDED(hr))
{
bstrValue = SysAllocString(c_wszValue);
if (bstrValue == NULL)
{
hr = E_OUTOFMEMORY;
}
}
if (SUCCEEDED(hr))
{
hr = piRequest->setRequestHeader(bstrName, bstrValue);
}
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -