?? exchangeclient.cpp
字號:
return E_POINTER;
}
if (
pCriteria->wszAlias == NULL &&
pCriteria->wszFirstName == NULL &&
pCriteria->wszLastName == NULL
)
{
return OWAEC_E_INVALIDSEARCH;
}
//create the format handler
pHandler = new CGALSearchFormatHandler();
if (pHandler == NULL)
{
hr = E_OUTOFMEMORY;
}
if (SUCCEEDED(hr))
{
//dispatch the event to the queue
hr = DispatchRequest(
e_ecrtGALSearch,
reinterpret_cast<VOID*>(pCriteria),
reinterpret_cast<IExchangeClientFormatHandler*>(pHandler),
ppiRequest
);
}
SafeRelease(pHandler);
return hr;
}
/*------------------------------------------------------------------------------
CExchangeClient::RequestFreeBusyData
Initiates a free-busy request with the specified criteria
------------------------------------------------------------------------------*/
HRESULT CExchangeClient::RequestFreeBusyData(
FreeBusyCriteria * pCriteria,
IExchangeClientRequest * * ppiRequest
)
{
HRESULT hr = S_OK;
CFreeBusyFormatHandler *pHandler = NULL;
FILETIME ftVerify = {0};
if (!m_fInitialized)
{
return OWAEC_E_NOTINITIALIZED;
}
//Check parameters
if (pCriteria == NULL)
{
return E_POINTER;
}
if (pCriteria->wszAlias == NULL || pCriteria->pstStart == NULL)
{
return OWAEC_E_INVALIDSEARCH;
}
//verify the systemtime struct is a valid struct, by using the built in Win32 API
if (! SystemTimeToFileTime(pCriteria->pstStart, &ftVerify))
{
return E_INVALIDARG;
}
//create the format handler
pHandler = new CFreeBusyFormatHandler();
if (pHandler == NULL)
{
hr = E_OUTOFMEMORY;
}
if (SUCCEEDED(hr))
{
//dispatch the event to the queue
hr = DispatchRequest(
e_ecrtFreeBusy,
reinterpret_cast<VOID*>(pCriteria),
reinterpret_cast<IExchangeClientFormatHandler*>(pHandler),
ppiRequest
);
}
SafeRelease(pHandler);
return hr;
}
/*------------------------------------------------------------------------------
CExchangeClient::DispatchRequest
Create the actual request structure, fill in the out parameter and send the
request to the request queue
Parameters:
: RequestType
: Parameters used to initialize the format handler
: The format handler
: The request to return to the user
Returns (HRESULT): Indicating whether the request was successfully dispatched
------------------------------------------------------------------------------*/
HRESULT CExchangeClient::DispatchRequest(
ExchangeClientRequestType rt,
VOID* pvRequestParams,
IExchangeClientFormatHandler *piHandler,
IExchangeClientRequest **ppiRequest
)
{
//verified by caller
PREFAST_ASSERT(piHandler);
HRESULT hr = S_OK;
CComObject<CExchangeClientRequest> *pRequestObject = NULL;
//check params
if (ppiRequest == NULL)
{
return E_POINTER;
}
//create the out param
hr = CComObject<CExchangeClientRequest>::CreateInstance(&pRequestObject);
if (SUCCEEDED(hr))
{
///TODO: Get rid of username/password blob's... and remove them from the processing...
//Initialize the format handler
hr = piHandler->Initialize(
m_wstrServer,
pvRequestParams
);
}
if (SUCCEEDED(hr))
{
//set it's type
hr = pRequestObject->Initialize(
this,
piHandler,
rt
);
}
if (SUCCEEDED(hr))
{
//get the correct interface for the users outparam
hr = pRequestObject->QueryInterface(
IID_IExchangeClientRequest,
(void**)ppiRequest
);
}
if (SUCCEEDED(hr))
{
//Add the new request to the queue
hr = AddNewRequest(pRequestObject);
}
if (FAILED(hr))
{
//if the request was not successfully added to the queue, release the reference added by
//query interface
SafeRelease(*ppiRequest);
}
return hr;
}
/*------------------------------------------------------------------------------
CExchangeClient::CallbackOnMainThread
Posts a message to the hidden window (which receives messages by the thread
containing the message pump (main thread) and performs a callback through
the registered callback interface
------------------------------------------------------------------------------*/
HRESULT CExchangeClient::CallbackOnMainThread(
CExchangeClientRequest * pRequestObject,
ExchangeClientRequestStatus ecrs
)
{
PREFAST_ASSERT(pRequestObject);
IExchangeClientRequest *piRequest = NULL;
HRESULT hr = S_OK;
hr = pRequestObject->QueryInterface(
IID_IExchangeClientRequest,
(void**)&piRequest
);
ASSERT(SUCCEEDED(hr));
if (SUCCEEDED(hr))
{
PostMessage(m_hwndCallback, ECM_USER_CALLBACK, (WPARAM)piRequest, (LPARAM)ecrs);
}
//leave the reference on the object - it will be released in the message handler
//e.g. m_hwndCallback's message proc
return hr;
}
/*------------------------------------------------------------------------------
CExchangeClient::BypassOWALoginPage
Bypass the OWA login page by POSTing the credentials to the server
------------------------------------------------------------------------------*/
HRESULT CExchangeClient::BypassOWALoginPage(
IXMLHTTPRequest * piRequest
)
{
TRACE();
WCHAR wszBuffer[MAX_PATH] = L"";
HRESULT hr = S_OK;
WCHAR wszPlainDomUser [100] = L"";
WCHAR wszPlainPassword[100] = L"";
ce::auto_bstr bstrUrl, bstrBody, bstrMethod, bstrResponseHeaders, bstrEncodedServer, bstrEncodedUserName, bstrEncodedPassword;
//ensure that this is an SSL connection since the creds are going to be sent
//in plaintext
if (wcsnicmp(L"https", (const WCHAR*)m_wstrServer, 5) != 0)
{
ASSERT(! "Can only bypass the OWA page with an SSL connection" );
return E_FAIL;
}
if (SUCCEEDED(hr))
{
bstrMethod = SysAllocString(c_SettingAuthMethod);
if (bstrMethod == NULL)
{
hr = E_OUTOFMEMORY;
}
}
if (SUCCEEDED(hr))
{
//get the url ready
hr = StringCchPrintf(
wszBuffer,
ARRAYSIZE(wszBuffer),
(const WCHAR*)c_SettingAuthUrlFmt,
(const WCHAR*)m_wstrServer.get_buffer()
);
}
if (SUCCEEDED(hr))
{
bstrUrl = SysAllocString(wszBuffer);
if (bstrUrl == NULL)
{
hr = E_OUTOFMEMORY;
}
}
if (SUCCEEDED(hr))
{
hr = GetLoggedInUserInformation(
wszPlainDomUser,
ARRAYSIZE(wszPlainDomUser),
CRED_ITEM_DOMAINUSERNAME
);
}
if (SUCCEEDED(hr))
{
WCHAR wszDmn[3] = L"", wszUsr[3] = L"";
hr = GetPlaintextCredentials(
wszDmn,
ARRAYSIZE(wszDmn),
wszUsr,
ARRAYSIZE(wszUsr),
wszPlainPassword,
ARRAYSIZE(wszPlainPassword)
);
}
//Encode the parameters such that a string 123&456 is seen as 123%26456
if (SUCCEEDED(hr))
{
hr = EncodeString(
m_wstrServer,
&bstrEncodedServer
);
}
if (SUCCEEDED(hr))
{
hr = EncodeString(
wszPlainDomUser,
&bstrEncodedUserName
);
}
if (SUCCEEDED(hr))
{
hr = EncodeString(
wszPlainPassword,
&bstrEncodedPassword
);
}
if (SUCCEEDED(hr))
{
ZeroMemory(wszBuffer, ARRAYSIZE(wszBuffer) * sizeof(WCHAR));
hr = StringCchPrintf(
wszBuffer,
ARRAYSIZE(wszBuffer),
(const WCHAR*)c_SettingAuthBodyFmt,
bstrEncodedServer,
bstrEncodedUserName,
bstrEncodedPassword
);
}
if (SUCCEEDED(hr))
{
bstrBody = SysAllocString(wszBuffer);
if (bstrBody == NULL)
{
hr = E_OUTOFMEMORY;
}
}
if (SUCCEEDED(hr))
{
VARIANT vAsync = {0},
vUName = {0},
vPWord = {0};
vAsync.vt = VT_BOOL; vAsync.bVal = FALSE;
vUName.vt = VT_BSTR; vUName.bstrVal = NULL;
vPWord.vt = VT_BSTR; vPWord.bstrVal = NULL;
hr = piRequest->open(
bstrMethod,
bstrUrl,
vAsync,
vUName,
vPWord
);
ASSERT(SUCCEEDED(hr));
}
if (SUCCEEDED(hr))
{
VARIANT vBody = {0};
vBody.vt = VT_BSTR; vBody.bstrVal = bstrBody;
hr = piRequest->send(vBody);
}
return hr;
}
/*------------------------------------------------------------------------------
CExchangeClient::CancelMe
Cancels a request by removing it from the queue.
Parameters:
pRequestObj: The request to find and remove
Returns (HRESULT): S_OK - the request was found and removed
S_FALSE - the request has already run
------------------------------------------------------------------------------*/
HRESULT CExchangeClient::CancelMe(
CExchangeClientRequest *pRequestObj
)
{
PREFAST_ASSERT(pRequestObj);
HRESULT hr = S_OK;
LockRequests();
//Locate the object in the container class
RequestQueue::iterator it = std::find(
m_queuePendingRequests.begin(),
m_queuePendingRequests.end(),
pRequestObj
);
if (it == m_queuePendingRequests.end())
{
hr = S_FALSE;
}
else
{
(*it)->Release();
m_queuePendingRequests.erase(it);
hr = S_OK;
}
UnlockRequests();
return hr;
}
/*------------------------------------------------------------------------------
CExchangeClient::CancelPendingRequests
Cancels all pending requests by removing them from the waiting queue
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CExchangeClient::CancelPendingRequests()
{
if (!m_fInitialized)
{
return OWAEC_E_NOTINITIALIZED;
}
LockRequests();
DEBUGMSG(ZONE_OWAEC_TRACING_INFORMATIONAL, (L"Cancelling %d requests", m_queuePendingRequests.size()));
RequestQueue::iterator it = m_queuePendingRequests.begin();
while (it != m_queuePendingRequests.end())
{
(*it)->Release();
it++;
}
//clear the whole queue
m_queuePendingRequests.erase(m_queuePendingRequests.begin(), m_queuePendingRequests.end());
UnlockRequests();
return S_OK;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -