xmppthread.cc revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch/* 2f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * libjingle 3f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * Copyright 2004--2005, Google Inc. 4f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * 53345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick * Redistribution and use in source and binary forms, with or without 6f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * modification, are permitted provided that the following conditions are met: 7f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * 83345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick * 1. Redistributions of source code must retain the above copyright notice, 9f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * this list of conditions and the following disclaimer. 10f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * 2. Redistributions in binary form must reproduce the above copyright notice, 11f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * this list of conditions and the following disclaimer in the documentation 12f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * and/or other materials provided with the distribution. 133345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick * 3. The name of the author may not be used to endorse or promote products 14f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * derived from this software without specific prior written permission. 15f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * 16f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 173345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 193345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 233345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 243345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch */ 27f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 28f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch#include "talk/xmpp/xmppclientsettings.h" 29f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch#include "talk/examples/login/xmppthread.h" 30f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch#include "talk/examples/login/xmppauth.h" 31f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 32f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdochnamespace { 33f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 34f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdochconst uint32 MSG_LOGIN = 1; 35f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdochconst uint32 MSG_DISCONNECT = 2; 36f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 37f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdochstruct LoginData: public talk_base::MessageData { 38f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch LoginData(const buzz::XmppClientSettings& s) : xcs(s) {} 39f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch virtual ~LoginData() {} 40f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 41f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch buzz::XmppClientSettings xcs; 42f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch}; 43f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 44f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch} // namespace 45f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 46f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen MurdochXmppThread::XmppThread() { 47f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch pump_ = new XmppPump(this); 48f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch} 49f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 50f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen MurdochXmppThread::~XmppThread() { 51f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch delete pump_; 52f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch} 53f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 54f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdochvoid XmppThread::ProcessMessages(int cms) { 55f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch talk_base::Thread::ProcessMessages(cms); 56f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch} 57f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 58f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdochvoid XmppThread::Login(const buzz::XmppClientSettings& xcs) { 59f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch Post(this, MSG_LOGIN, new LoginData(xcs)); 60f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch} 61f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 62f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdochvoid XmppThread::Disconnect() { 63f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch Post(this, MSG_DISCONNECT); 64f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch} 65f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 66f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdochvoid XmppThread::OnStateChange(buzz::XmppEngine::State state) { 67f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch} 68f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch 69f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdochvoid XmppThread::OnMessage(talk_base::Message* pmsg) { 70f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch if (pmsg->message_id == MSG_LOGIN) { 713345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick ASSERT(pmsg->pdata != NULL); 72f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch LoginData* data = reinterpret_cast<LoginData*>(pmsg->pdata); 73f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch pump_->DoLogin(data->xcs, new XmppSocket(false), new XmppAuth()); 74f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch delete data; 75f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch } else if (pmsg->message_id == MSG_DISCONNECT) { 76f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch pump_->DoDisconnect(); 77f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch } else { 783345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick ASSERT(false); 79f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch } 80f74420b3285b9fe04a7e00aa3b8c0ab07ea344bcBen Murdoch} 81