📄 freebusyformathandler.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 "FreeBusyFormatHandler.h"
#include "RequestParameters.h"
#include "Settings.h"
#include "Includes.h"
#include "Utilities.h"
#define CCH_DAY_BUFFER 12
#define CCH_TIME_BUFFER 11
#define CCH_TIMEZONE_BUFFER 10
static ParseParameters s_FBDParseParameters;
static ParsePropertyMapping s_FBDPropertyMapping[NUM_FBD_PROPERTIES + 1];
/*------------------------------------------------------------------------------
GetEndTime
Helper function to compute the end time of the free busy query.
Obtained by adding 12 hours to the start time
Parameters:
pstStart: [IN] The start time
pstEnd: [OUT] The end time
nHours: [IN] The number of hours to add to the start time to get the end time
------------------------------------------------------------------------------*/
VOID GetEndTime(
SYSTEMTIME *pstStart,
SYSTEMTIME *pstEnd,
UINT nHours
)
{
//Convert the time to a DWORDDWORD
ULONGLONG ullEnd = 0;
FILETIME ftStart = {0},
ftEnd = {0};
SystemTimeToFileTime(pstStart, &ftStart);
//bitwise turn the 2 DWORDs into 1 ULL
ullEnd = ((((ULONGLONG)ftStart.dwHighDateTime) << (sizeof(DWORD)*8)) | ftStart.dwLowDateTime);
//The ULL representation is in 100 of ns. We need to add 12 hours worth of 100 ns.
//add 12 hours =
ullEnd += (ULONGLONG)(
(ULONGLONG)nHours * // n hr
(ULONGLONG)60 * // 60 min/hr
(ULONGLONG)60 * // 60 sec/min
(ULONGLONG)1000 * // 1000 ms/sec
(ULONGLONG)10000 // 10^6 ns/ms / 100 ns = 10^4 100 ns
);
//reconvert the ull back to the 2 dwords
ftEnd.dwLowDateTime = (DWORD)ullEnd;
ftEnd.dwHighDateTime = (DWORD)(ullEnd >> (sizeof(DWORD)*8));
//convert back to a filetime
FileTimeToSystemTime(&ftEnd, pstEnd);
}
/*------------------------------------------------------------------------------
FillDayBuffer
Fills a buffer with the necessary "Day" format
as described on http://support.microsoft.com/?kbid=813268
Parameters:
wszBuffer: out buffer to fill
cchBuffer: cch of the buffer
pst: the time to convert
------------------------------------------------------------------------------*/
VOID FillDayBuffer(
WCHAR *wszBuffer,
UINT cchBuffer,
SYSTEMTIME *pst
)
{
PREFAST_ASSERT(pst && wszBuffer);
StringCchPrintf(
wszBuffer,
cchBuffer,
L"%4d-%02d-%02d",
pst->wYear,
pst->wMonth,
pst->wDay
);
}
/*------------------------------------------------------------------------------
FillTimeBuffer
Fills a buffer with the necessary time format for FB searches
Parameters:
wszBuffer: The out buffer
cchBuffer: cch of the out buffer
pst: the time to convert
------------------------------------------------------------------------------*/
VOID FillTimeBuffer(
WCHAR *wszBuffer,
UINT cchBuffer,
SYSTEMTIME *pst
)
{
PREFAST_ASSERT(pst && wszBuffer);
StringCchPrintf(
wszBuffer,
cchBuffer,
L"T%02d:%02d:%02d",
pst->wHour,
pst->wMinute,
pst->wSecond
);
}
/*------------------------------------------------------------------------------
FillTimeZoneBuffer
Fills the out buffer with the timezone adjustment time (ISO standard)
as desribed by http://support.microsoft.com/?kbid=813268
------------------------------------------------------------------------------*/
VOID FillTimeZoneBuffer(WCHAR *wszTimeZoneBuffer, INT cchBuffer)
{
TIME_ZONE_INFORMATION tzi = {0};
DWORD dwBias = GetTimeZoneInformation(&tzi);
BOOL fNeg = (tzi.Bias < 0);
if (fNeg)
tzi.Bias -= (2* tzi.Bias);
if (dwBias == TIME_ZONE_ID_STANDARD)
{
tzi.Bias += tzi.StandardBias;
}
else if (dwBias == TIME_ZONE_ID_DAYLIGHT)
{
tzi.Bias += tzi.DaylightBias;
}
StringCchPrintf(
wszTimeZoneBuffer,
cchBuffer,
L"%c%02d:00",
(fNeg) ? L'+' : L'-',
tzi.Bias / 60
);
}
/*------------------------------------------------------------------------------
Cat
Special Concatenation helper function used only in this module used for fast special
concatenations:
Given a pointer inside a buffer and a pointer to the head of a buffer, copies
a null-terminated string to the buffer at the specified inside location AND
moves up the inside pointer to the next viable copy locations
e.g.
wszBuffer [ c o p i e d s o f a r \0 * * * * * * * * ]
cchBuffer = 20 |
ppwchCopyLocation: | (points to the \0)
c_wszAppendMe: [ m o r e ]
result:
wszBuffer [ c o p i e d s o f a r m o r e \0 * * * ]
ppwchCopyLocation | (pointer moves up)
Returns (BOOL): TRUE if there is enough space to copy c_wszAppendMe, FALSE otherwise
------------------------------------------------------------------------------*/
inline BOOL Cat(WCHAR *wszBuffer, INT cchBuffer, WCHAR **ppwchCopyLocation, const WCHAR *c_wszAppendMe)
{
INT cchAppend = wcslen(c_wszAppendMe);
INT AvailabeBufferLength = (cchBuffer - (*ppwchCopyLocation - wszBuffer) - 1);
if (cchAppend <= AvailabeBufferLength )
{
StringCchCopy(*ppwchCopyLocation, AvailabeBufferLength, c_wszAppendMe);
*ppwchCopyLocation += cchAppend;
return TRUE;
}
return FALSE;
}
/*------------------------------------------------------------------------------
CFreeBusyFormatHandler::CFreeBusyFormatHandler
Constructor
------------------------------------------------------------------------------*/
CFreeBusyFormatHandler::CFreeBusyFormatHandler() : CGenericFormatHandler()
{
MemTrackAdd();
m_strSearchAlias = L"";
m_strServerName = L"";
ZeroMemory(&m_stStart, sizeof(SYSTEMTIME));
}
/*------------------------------------------------------------------------------
CFreeBusyFormatHandler::~CFreeBusyFormatHandler
Destructor
------------------------------------------------------------------------------*/
CFreeBusyFormatHandler::~CFreeBusyFormatHandler()
{
MemTrackRemove();
//ce::wstring's are self-maintaining
}
/*------------------------------------------------------------------------------
CFreeBusyFormatHandler::BuildParseTable
Builds a parsing table from values stored in the registry
Returns (HRESULT): Indicating success or failure
------------------------------------------------------------------------------*/
/* static */HRESULT CFreeBusyFormatHandler::BuildParseTable()
{
s_FBDParseParameters.c_wszNewDataRecordName = c_SettingFBDNewDataRecord;
s_FBDPropertyMapping[0].idx = FBD_PARSE_DISPLAYNAME;
s_FBDPropertyMapping[0].c_wszProperty = (const WCHAR*)c_SettingFBDDispName;
s_FBDPropertyMapping[1].idx = FBD_PARSE_FBDATA;
s_FBDPropertyMapping[1].c_wszProperty = (const WCHAR*)c_SettingFBDFreeBusy;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -