📄 freebusyformathandler.cpp
字号:
s_FBDPropertyMapping[2].idx = FBD_PARSE_EMAIL;
s_FBDPropertyMapping[2].c_wszProperty = (const WCHAR*)c_SettingFBDEmailAddress;
s_FBDPropertyMapping[3].idx = INVALID_PARSE_INDEX;
s_FBDPropertyMapping[3].c_wszProperty = NULL;
s_FBDParseParameters.c_rgPropertyMappings = s_FBDPropertyMapping;
return S_OK;
}
/*------------------------------------------------------------------------------
CFreeBusyFormatHandler::Initialize
Initializes this instance of the format handler
------------------------------------------------------------------------------*/
HRESULT CFreeBusyFormatHandler::Initialize(
const WCHAR * c_wszServername,
VOID * pvParam
)
{
PREFAST_ASSERT(pvParam);
HRESULT hr = CGenericFormatHandler::Initialize(&s_FBDParseParameters);
FreeBusyCriteria *pCriteria = reinterpret_cast<FreeBusyCriteria*>(pvParam);
PREFAST_ASSERT(pCriteria && pCriteria->wszAlias && pCriteria->pstStart);
memcpy(&m_stStart, pCriteria->pstStart, sizeof(SYSTEMTIME));
m_stStart.wMinute = 0;
m_stStart.wSecond = 0;
m_stStart.wMilliseconds = 0;
if (SUCCEEDED(hr))
{
//ce::wstring's assign does a str copy
if (!m_strServerName.assign(c_wszServername))
{
hr = E_OUTOFMEMORY;
}
}
if (SUCCEEDED(hr))
{
//assign all the members of the search struct
if (!m_strSearchAlias.assign(pCriteria->wszAlias))
{
hr = E_OUTOFMEMORY;
}
}
//Ensure we have a valid search length variable
if (SUCCEEDED(hr) && sm_SearchLength == 0)
{
INT res = _wtoi(c_SettingFBSSearchLength);
if (res <= 0)
{
//pick 12 as the fail all default
res = 12;
}
sm_SearchLength = res;
}
return hr;
}
/*------------------------------------------------------------------------------
CFreeBusyFormatHandler::GetFormattedHttpParameters
Get's the method and body from the registry, and fill's in the missing params
from the url with the desired alias to search on
------------------------------------------------------------------------------*/
HRESULT CFreeBusyFormatHandler::GetFormattedHttpParameters(
BSTR * pbstrMethod,
BSTR * pbstrUrl,
BSTR * pbstrBody
)
{
//check initialization
if (m_strServerName[0] == L'\0')
{
return OWAEC_E_NOSERVER;
}
if (m_strSearchAlias[0] == L'\0')
{
return OWAEC_E_INVALIDSEARCH;
}
//check params (internal function)
PREFAST_ASSERT (
pbstrMethod != NULL &&
pbstrUrl != NULL &&
pbstrBody != NULL &&
sm_SearchLength > 0
);
//buffer to use for sprintf'ing
WCHAR wszFormatBuffer [MAX_PATH] = L"";
HRESULT hr = S_OK;
WCHAR wszStartDayBuffer [CCH_DAY_BUFFER] = L"",
wszStartTimeBuffer[CCH_TIME_BUFFER] = L"",
wszEndDayBuffer [CCH_DAY_BUFFER] = L"",
wszEndTimeBuffer [CCH_TIME_BUFFER] = L"",
wszTimeZone [CCH_TIMEZONE_BUFFER] = L"";
SYSTEMTIME stEnd = {0};
ce::auto_bstr bstrEncodedSearchAlias;
//Format all the time buffers
FillTimeZoneBuffer (wszTimeZone, ARRAYSIZE(wszTimeZone));
FillDayBuffer (wszStartDayBuffer, ARRAYSIZE(wszStartDayBuffer) , &m_stStart);
FillTimeBuffer(wszStartTimeBuffer, ARRAYSIZE(wszStartTimeBuffer), &m_stStart);
GetEndTime(&m_stStart, &stEnd, sm_SearchLength);
FillDayBuffer(wszEndDayBuffer, ARRAYSIZE(wszEndDayBuffer) , &stEnd);
FillTimeBuffer(wszEndTimeBuffer, ARRAYSIZE(wszEndTimeBuffer), &stEnd);
hr = EncodeString(
m_strSearchAlias,
&bstrEncodedSearchAlias
);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
//allocate the method
*pbstrMethod = SysAllocString(c_SettingFBSMethod);
if (*pbstrMethod == NULL)
{
hr = E_OUTOFMEMORY;
}
if (SUCCEEDED(hr))
{
//sprintf the server and username into the buffer
hr = StringCchPrintf(
wszFormatBuffer,
ARRAYSIZE(wszFormatBuffer),
c_SettingFBSUrlFmt,
(const WCHAR*)m_strServerName.get_buffer()
);
}
if (SUCCEEDED(hr))
{
//append additional gal criteria to the buffer
WCHAR *pwchCopyBuffer = wszFormatBuffer + wcslen(wszFormatBuffer);
//inlined macro - better way????
#define CatMe(appendstr) \
Cat(wszFormatBuffer, ARRAYSIZE(wszFormatBuffer)-1, &pwchCopyBuffer, (const WCHAR*)(appendstr))
//Use OR as a short circuit to check return vals
if (! CatMe(L"&start=") ||
! CatMe(wszStartDayBuffer) ||
! CatMe(wszStartTimeBuffer) ||
! CatMe(wszTimeZone) ||
! CatMe(L"&end=") ||
! CatMe(wszEndDayBuffer) ||
! CatMe(wszEndTimeBuffer) ||
! CatMe(wszTimeZone) ||
! CatMe(L"&interval=") ||
! CatMe(c_SettingFBSIntervalLength) ||
! CatMe(L"&u=SMTP:") ||
! CatMe(bstrEncodedSearchAlias)
)
{
hr = E_FAIL;
}
}
if (SUCCEEDED(hr))
{
//allocate the url
*pbstrUrl = SysAllocString(wszFormatBuffer);
if (*pbstrUrl == NULL)
{
hr = E_OUTOFMEMORY;
}
}
if (SUCCEEDED(hr))
{
//fill the body
*pbstrBody = SysAllocString(c_SettingFBSBodyFmt);
if (*pbstrBody == NULL)
{
hr = E_OUTOFMEMORY;
}
}
//cleanup - if something failed deallocate all buffers
if (FAILED(hr))
{
//SysFreeString(NULL) is legal
SysFreeString(*pbstrBody);
SysFreeString(*pbstrMethod);
SysFreeString(*pbstrUrl);
}
return hr;
}
/*------------------------------------------------------------------------------
CFreeBusyFormatHandler::SetAdditionalHeaders
Sets additional header in the http request for the fbd search
------------------------------------------------------------------------------*/
HRESULT CFreeBusyFormatHandler::SetAdditionalHeaders(
IXMLHTTPRequest * piRequest
)
{
PREFAST_ASSERT(piRequest != NULL);
return CGenericFormatHandler::SetAdditionalHeadersFromValue(
piRequest,
c_SettingFBSAdditionalHeaderName,
c_SettingFBSAdditionalHeaderValue
);
}
/*------------------------------------------------------------------------------
CFreeBusyFormatHandler::GetDataRecordSize
Returns the size of a free-busy datarecord
------------------------------------------------------------------------------*/
INT CFreeBusyFormatHandler::GetDataRecordSize()
{
return NUM_FBD_PROPERTIES;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -