📄 galsearchformathandler.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 "GALSearchFormatHandler.h"
#include "Memtracking.h"
#include "Settings.h"
#include "RequestParameters.h"
#include "Includes.h"
#include "utilities.h"
static ParseParameters s_GALParseParameters;
static ParsePropertyMapping s_GALPropertyMapping[NUM_GAL_PROPERTIES + 1];
/*------------------------------------------------------------------------------
CGALSearchFormatHandler::CGALSearchFormatHandler
Constructor
------------------------------------------------------------------------------*/
CGALSearchFormatHandler::CGALSearchFormatHandler() : CGenericFormatHandler()
{
MemTrackAdd();
}
/*------------------------------------------------------------------------------
CGALSearchFormatHandler::~CGALSearchFormatHandler
Destructor
------------------------------------------------------------------------------*/
CGALSearchFormatHandler::~CGALSearchFormatHandler()
{
MemTrackRemove();
}
/*------------------------------------------------------------------------------
CGALSearchFormatHandler::BuildParseTable
Builds the parse table from registry values
------------------------------------------------------------------------------*/
HRESULT CGALSearchFormatHandler::BuildParseTable()
{
s_GALParseParameters.c_wszNewDataRecordName = c_SettingGALNewDataRecord;
s_GALPropertyMapping[0].idx = GAL_PARSE_DISPLAYNAME;
s_GALPropertyMapping[0].c_wszProperty = (const WCHAR*)c_SettingGALDispName;
s_GALPropertyMapping[1].idx = GAL_PARSE_ALIAS;
s_GALPropertyMapping[1].c_wszProperty = (const WCHAR*)c_SettingGALAlias;
s_GALPropertyMapping[2].idx = GAL_PARSE_OFFICE;
s_GALPropertyMapping[2].c_wszProperty = (const WCHAR*)c_SettingGALOffice;
s_GALPropertyMapping[3].idx = GAL_PARSE_PHONE;
s_GALPropertyMapping[3].c_wszProperty = (const WCHAR*)c_SettingGALPhone;
s_GALPropertyMapping[4].idx = GAL_PARSE_SMTP;
s_GALPropertyMapping[4].c_wszProperty = (const WCHAR*)c_SettingGALSMTP;
s_GALPropertyMapping[5].idx = INVALID_PARSE_INDEX;
s_GALPropertyMapping[5].c_wszProperty = NULL;
s_GALParseParameters.c_rgPropertyMappings = s_GALPropertyMapping;
return S_OK;
}
/*------------------------------------------------------------------------------
CGALSearchFormatHandler::Initialize
Initializes the class instance
Parameters:
c_wszServername: Server name
c_wszUsername: Username
c_wszPassword: Ignored
pvParam: (VOID cast) GALSearchCriteria struct *
Returns (HRESULT):
------------------------------------------------------------------------------*/
HRESULT CGALSearchFormatHandler::Initialize(
const WCHAR * c_wszServername,
VOID * pvParam
)
{
HRESULT hr = CGenericFormatHandler::Initialize(&s_GALParseParameters);
if (SUCCEEDED(hr))
{
//ce::wstring's assign does a str copy
if (!m_strServerName.assign(c_wszServername))
{
hr = E_OUTOFMEMORY;
}
}
//assign all the members of the search struct
PREFAST_ASSERT(pvParam);
GALSearchCriteria *pCriteria = (GALSearchCriteria*)pvParam;
if (SUCCEEDED(hr))
{
if (
(pCriteria->wszAlias && !m_strSearchAlias.assign(pCriteria->wszAlias)) ||
(pCriteria->wszFirstName && !m_strSearchFirstName.assign(pCriteria->wszFirstName)) ||
(pCriteria->wszLastName && !m_strSearchLastName.assign(pCriteria->wszLastName))
)
{
hr = E_OUTOFMEMORY;
}
}
return hr;
}
/*------------------------------------------------------------------------------
CGALSearchFormatHandler::GetFormattedHttpParameters
Method: GET
Body: <empty>
Url : <server>/exchange/username/?cmd=galfind&<criteria fmt>
------------------------------------------------------------------------------*/
HRESULT CGALSearchFormatHandler::GetFormattedHttpParameters(
BSTR * pbstrMethod,
BSTR * pbstrUrl,
BSTR * pbstrBody
)
{
//check initialization
if (m_strServerName[0] == L'\0')
{
return OWAEC_E_NOSERVER;
}
//check params
PREFAST_ASSERT(
pbstrMethod != NULL &&
pbstrUrl != NULL &&
pbstrBody != NULL
);
HRESULT hr = S_OK;
WCHAR wszBuffer[MAX_PATH] = L"";
ce::wstring wstrUrl;
//allocate the method
*pbstrMethod = SysAllocString(c_SettingGALMethod);
if (*pbstrMethod == NULL)
{
hr = E_OUTOFMEMORY;
goto exit;
}
//sprintf the server and username into the buffer
hr = StringCchPrintf(
wszBuffer,
ARRAYSIZE(wszBuffer),
c_SettingGALUrlFmt,
(const WCHAR*)m_strServerName.get_buffer()
);
if (FAILED(hr))
{
ASSERT(FALSE);
goto exit;
}
//append additional gal criteria to the buffer
if (! wstrUrl.assign(wszBuffer))
{
hr = E_OUTOFMEMORY;
goto exit;
}
if (m_strSearchAlias[0] != L'\0')
{
ce::auto_bstr bstrEncodedSearchAlias;
hr = EncodeString(
m_strSearchAlias,
&bstrEncodedSearchAlias
);
if (FAILED(hr))
{
ASSERT(FALSE);
goto exit;
}
if (! wstrUrl.append(c_SettingGALAppendAlias) ||
! wstrUrl.append(bstrEncodedSearchAlias)
)
{
hr = E_OUTOFMEMORY;
goto exit;
}
}
if (m_strSearchFirstName[0] != L'\0')
{
ce::auto_bstr bstrEncodedFirstName;
hr = EncodeString(
m_strSearchFirstName,
&bstrEncodedFirstName
);
if (FAILED(hr))
{
ASSERT(FALSE);
goto exit;
}
if (! wstrUrl.append(c_SettingGALAppendFirstName) ||
! wstrUrl.append(bstrEncodedFirstName)
)
{
hr = E_OUTOFMEMORY;
goto exit;
}
}
if (m_strSearchLastName[0] != L'\0')
{
ce::auto_bstr bstrEncodedLastName;
hr = EncodeString(
m_strSearchLastName,
&bstrEncodedLastName
);
if (FAILED(hr))
{
ASSERT(FALSE);
goto exit;
}
if (! wstrUrl.append(c_SettingGALAppendLastName) ||
! wstrUrl.append(bstrEncodedLastName)
)
{
hr = E_OUTOFMEMORY;
goto exit;
}
}
//allocate the url
*pbstrUrl = SysAllocString(wstrUrl);
if (*pbstrUrl == NULL)
{
hr = E_OUTOFMEMORY;
goto exit;
}
//the body comes from the registry
*pbstrBody = SysAllocString(c_SettingGALBodyFmt);
if (*pbstrBody == NULL)
{
hr = E_OUTOFMEMORY;
goto exit;
}
exit:
//cleanup - if something failed deallocate all buffers
if (FAILED(hr))
{
//SysFreeString(NULL) is legal
SysFreeString(*pbstrBody);
SysFreeString(*pbstrMethod);
SysFreeString(*pbstrUrl);
}
return hr;
}
/*------------------------------------------------------------------------------
CGALSearchFormatHandler::SetAdditionalHeaders
Set the params from the registry
------------------------------------------------------------------------------*/
HRESULT CGALSearchFormatHandler::SetAdditionalHeaders(
IXMLHTTPRequest * piRequest
)
{
PREFAST_ASSERT(piRequest != NULL);
return CGenericFormatHandler::SetAdditionalHeadersFromValue(
piRequest,
c_SettingGALAdditionalHeaderName,
c_SettingGALAdditionalHeaderValue
);
}
/*------------------------------------------------------------------------------
CGALSearchFormatHandler::GetDataRecordSize
Returns the size of a GAL DataRecord
------------------------------------------------------------------------------*/
INT CGALSearchFormatHandler::GetDataRecordSize()
{
return NUM_GAL_PROPERTIES;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -