begin();
Unlock();
return S_OK;
}
STDMETHODIMP
StatementEnumerator::Clone(IEnumString **ppes)
{
if (ppes == 0)
return E_INVALIDARG;
if (*ppes = new StatementEnumerator(m_pThis))
return S_OK;
return E_OUTOFMEMORY;
}
// class ChatSessionClass /////////////////////
ChatSessionClass::ChatSessionClass(void)
: m_cStrongLocks(0)
{
InitializeCriticalSection(&m_csSessionLock);
}
ChatSessionClass::~ChatSessionClass(void)
{
DeleteCriticalSection(&m_csSessionLock);
}
void
ChatSessionClass::Lock(void)
{
EnterCriticalSection(&m_csSessionLock);
}
void
ChatSessionClass::Unlock(void)
{
LeaveCriticalSection(&m_csSessionLock);
}
// helper method to protect access to DeleteSession
// to only allow COMChat Admins to delete groups
bool
ChatSessionClass::CheckAccess(const OLECHAR *pwszUser)
{
if (wcscmp(pwszUser, L"anonymous") == 0)
return false;
TRUSTEEW trustee = {
0, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_NAME,
TRUSTEE_IS_USER, const_cast
(pwszUser)
};
BOOL bIsAllowed;
HRESULT hr = g_pacAdmins->IsAccessAllowed(&trustee,0,
COM_RIGHTS_EXECUTE,
&bIsAllowed);
if (FAILED(hr))
bIsAllowed = false;
return SUCCEEDED(hr) && bIsAllowed != FALSE;
}
// IUnknown methods
STDMETHODIMP
ChatSessionClass::QueryInterface(REFIID riid, void **ppv)
{
if (riid == IID_IUnknown)
*ppv = static_cast(this);
else if (riid == IID_IChatSessionManager)
*ppv = static_cast(this);
else if (riid == IID_IExternalConnection)
*ppv = static_cast(this);
else
return (*ppv = 0), E_NOINTERFACE;
reinterpret_cast(*ppv)->AddRef();
return S_OK;
}
STDMETHODIMP_(ULONG)
ChatSessionClass::AddRef(void)
{
return 2;
}
STDMETHODIMP_(ULONG)
ChatSessionClass::Release(void)
{
return 1;
}
// IExternalConnection methods
STDMETHODIMP_(DWORD)
ChatSessionClass::AddConnection(DWORD extconn, DWORD)
{
if (extconn & EXTCONN_STRONG)
{
ModuleLock();
return InterlockedIncrement(&m_cStrongLocks);
}
return 0;
}
STDMETHODIMP_(DWORD)
ChatSessionClass::ReleaseConnection(DWORD extconn, DWORD,
BOOL bLastReleaseKillsStub)
{
if (extconn & EXTCONN_STRONG)
{
LONG res = InterlockedDecrement(&m_cStrongLocks);
if (res == 0 && bLastReleaseKillsStub)
CoDisconnectObject(
static_cast(this), 0);
ModuleUnlock();
return res;
}
return 0;
}
// IChatSessionManager methods
STDMETHODIMP
ChatSessionClass::GetSessionNames(IEnumString **ppes)
{
if (ppes == 0)
return E_INVALIDARG;
if (*ppes = new SessionNamesEnumerator(this))
{
(*ppes)->AddRef();
return S_OK;
}
else
return E_OUTOFMEMORY;
}
STDMETHODIMP
ChatSessionClass::FindSession(const OLECHAR *pwszSessionName,
BOOL bDontCreate,
BOOL bAllowAnonymousAccess,
IChatSession **ppcs)
{
if (ppcs == 0)
return E_INVALIDARG;
HRESULT hr = E_FAIL;
*ppcs = 0;
OLECHAR *pwszUser = GetCaller();
Lock();
SESSIONMAP::iterator it = m_sessions.find(pwszSessionName);
if (it == m_sessions.