Сущность технологии СОМ. Библиотека программиста   ::   Бокс Дональд

Страница: 509 из 528

exe \n»

« where:\n»

« action = /sessions|/chat:session|/delete:session\n»

« user = /user:domain\\user /password:pw |»

«/anonymous | \n»

« host = /host:hostname | \n»;

printf(psz);

return -1;

}

// utility function for printing a list of strings

void PrintAllStrings(IEnumString *pes)

{

enum { CHUNKSIZE = 64 };

OLECHAR *rgpwsz[CHUNKSIZE];

ULONG cFetched;

HRESULT hr;

do

{

hr = pes->Next(CHUNKSIZE, rgpwsz, &cFetched);

if (SUCCEEDED(hr))

{

for (ULONG i = 0; i < cFetched; i++)

if (rgpwsz[i])

{

wprintf(L"%s\n", rgpwsz[i]);

CoTaskMemFree(rgpwsz[i]);

}

}

} while (hr == S_OK);

}

// utility function to print initial state of

// a chat session

void PrintToDate(IChatSession *pcs)

{

IEnumString *pes = 0;

HRESULT hr = pcs->GetStatements(&pes);

if (SUCCEEDED(hr))

{

PrintAllStrings(pes);

pes->Release();

}

}

// this class implements the callback interface

// that receives chat notifications. It simply

// prints the event to the console

class EventSink : public IChatSessionEvents

{

public:

STDMETHODIMP QueryInterface(REFIID riid, void**ppv)

{

if (riid == IID_IUnknown)

*ppv = static_cast(this);

else if (riid == IID_IChatSessionEvents)

*ppv = static_cast(this);

else

return (*ppv = 0), E_NOINTERFACE;

reinterpret_cast(*ppv)->AddRef();

return S_OK;

}

STDMETHODIMP_(ULONG) AddRef(void)

{

return 2;

}

STDMETHODIMP_(ULONG) Release(void)

{

return 1;

}

STDMETHODIMP OnNewStatement(const OLECHAR *pwszUser,

const OLECHAR *pwszStmt)

{

wprintf(L"%-14s: %s\n", pwszUser, pwszStmt);

return S_OK;

}

STDMETHODIMP OnNewUser(const OLECHAR *pwszUser)

{

wprintf(L"\n\n>>> Say Hello to %s\n\n", pwszUser);

return S_OK;

}

STDMETHODIMP OnUserLeft(const OLECHAR *pwszUser)

{

wprintf(L"\n\n>>> Say Bye to %s\n\n", pwszUser);

return S_OK;

}

};

// type of operations this client can perform

enum ACTION

{

ACTION_NONE,

ACTION_CHAT,

ACTION_DELETE_SESSION,

ACTION_LIST_SESSION_NAMES,

};

// run chat command

void Chat(const OLECHAR *pwszSession,

IChatSessionManager *pcsm, // manager

COAUTHIDENTITY *pcai, // user

bool bAnonymous) // anonymous

{

// create or get the named session

IChatSession *pcs = 0;

HRESULT hr = pcsm->FindSession(pwszSession, FALSE,

TRUE, &pcs);

if (SUCCEEDED(hr))

{

// adjust security blanket for session interface

if (!bAnonymous)

hr = CoSetProxyBlanket(pcs, RPC_C_AUTHN_WINNT,

RPC_C_AUTHZ_NONE, 0,

|< Пред. 507 508 509 510 511 След. >|

Контакты: [email protected]