///---------------------------------------------------------------------------- /// /// Copyright (c) 2007-2008, AOL LLC /// All rights reserved. /// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: /// Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. /// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. /// Neither the name of the AOL LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS /// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT /// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR /// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR /// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, /// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, /// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR /// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF /// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING /// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS /// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /// ///---------------------------------------------------------------------------- #include // printf #include "AccCore.h" // AIMCC main header #include "AccSupport.h" // AIMCC C++ helper classes #ifdef _MSC_VER #pragma comment(lib, "acccore.lib") // aimcc main lib #pragma comment(lib, "accuuidlib.lib") // aimcc uuid lib #endif using namespace AIMCC; class CSampleApp : public CAccEventSink { public: HRESULT Init(const char* userName, const char* password) { // 1. create aimcc main object, hook up for events // 2. set information to identify this client // 3. specify username and password, and sign on HRESULT hr; if (SUCCEEDED(hr = AccCreateSession(IID_IAccSession, (void**)&m_sp)) && SUCCEEDED(hr = Advise(m_sp))) { CAccPtr spClientInfo; hr = m_sp->get_ClientInfo(&spClientInfo); if (SUCCEEDED(hr)) { CAccVariant desc("accsample (key=ju13LC0KMdgmkiO0)"); spClientInfo->put_Property(AccClientInfoProp_Description, desc); if (SUCCEEDED(hr = m_sp->put_Identity(CAccBstr(userName)))) hr = m_sp->SignOn(CAccBstr(password)); } } return hr; } HRESULT Run() { // run a message loop until AccPostQuit is called return AccMessageLoop(); } void Term() { // clean up events and aimcc object Unadvise(m_sp); m_sp = NULL; } void OnStateChange( IAccSession* piSession, AccSessionState state, AccResult hr) { // quit when we go offline printf("state change: state=%d, hr=%08X\n", state, hr); if (state == AccSessionState_Offline) AccPostQuit(hr); } void OnSecondarySessionStateChange( IAccSession* piSession, IAccSecondarySession* piSecSession, AccSecondarySessionState state, AccResult hr) { // always accept incoming IM sessions if (state == AccSecondarySessionState_ReceivedProposal) { AccSecondarySessionServiceId id; piSecSession->get_ServiceId(&id); if (id == AccSecondarySessionServiceId_Im) piSecSession->Accept(); } } void OnImReceived( IAccSession* piSession, IAccImSession* piImSession, IAccParticipant* piSender, IAccIm* piIm) { // signoff when we get an IM that says "quit" CAccBstr text; piIm->GetConvertedText(OLESTR("text/plain"), &text); if (text == OLESTR("quit")) m_sp->SignOff(); } private: CAccPtr m_sp; }; int main(int argc, char* argv[]) { // check args if (argc != 3) { printf("usage: accsample username password\n"); return -1; } // create the app object and sign on CAccPtr sp(new CSampleApp); HRESULT hr = (sp) ? sp->Init(argv[1], argv[2]) : E_OUTOFMEMORY; if (FAILED(hr)) { printf("initialization error, hr=%08X\n", hr); return (int)hr; } // run the message loop hr = sp->Run(); sp->Term(); return (int)hr; }