Home | History | Annotate | Download | only in xmpp
      1 /*
      2  * libjingle
      3  * Copyright 2004--2005, Google Inc.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are met:
      7  *
      8  *  1. Redistributions of source code must retain the above copyright notice,
      9  *     this list of conditions and the following disclaimer.
     10  *  2. Redistributions in binary form must reproduce the above copyright notice,
     11  *     this list of conditions and the following disclaimer in the documentation
     12  *     and/or other materials provided with the distribution.
     13  *  3. The name of the author may not be used to endorse or promote products
     14  *     derived from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef _logintask_h_
     29 #define _logintask_h_
     30 
     31 #include <string>
     32 #include "talk/base/logging.h"
     33 #include "talk/base/scoped_ptr.h"
     34 #include "talk/xmpp/jid.h"
     35 #include "talk/xmpp/xmppengine.h"
     36 
     37 namespace buzz {
     38 
     39 class XmlElement;
     40 class XmppEngineImpl;
     41 class SaslMechanism;
     42 
     43 
     44 class XmppLoginTask {
     45 
     46 public:
     47   XmppLoginTask(XmppEngineImpl *pctx);
     48   ~XmppLoginTask();
     49 
     50   bool IsDone()
     51     { return state_ == LOGINSTATE_DONE; }
     52   void IncomingStanza(const XmlElement * element, bool isStart);
     53   void OutgoingStanza(const XmlElement *element);
     54 
     55 private:
     56   enum LoginTaskState {
     57     LOGINSTATE_INIT = 0,
     58     LOGINSTATE_STREAMSTART_SENT,
     59     LOGINSTATE_STARTED_XMPP,
     60     LOGINSTATE_TLS_INIT,
     61     LOGINSTATE_AUTH_INIT,
     62     LOGINSTATE_BIND_INIT,
     63     LOGINSTATE_TLS_REQUESTED,
     64     LOGINSTATE_SASL_RUNNING,
     65     LOGINSTATE_BIND_REQUESTED,
     66     LOGINSTATE_SESSION_REQUESTED,
     67     LOGINSTATE_DONE,
     68   };
     69 
     70   const XmlElement * NextStanza();
     71   bool Advance();
     72   bool HandleStartStream(const XmlElement * element);
     73   bool HandleFeatures(const XmlElement * element);
     74   const XmlElement * GetFeature(const QName & name);
     75   bool Failure(XmppEngine::Error reason);
     76   void FlushQueuedStanzas();
     77 
     78   XmppEngineImpl * pctx_;
     79   bool authNeeded_;
     80   LoginTaskState state_;
     81   const XmlElement * pelStanza_;
     82   bool isStart_;
     83   std::string iqId_;
     84   talk_base::scoped_ptr<XmlElement> pelFeatures_;
     85   Jid fullJid_;
     86   std::string streamId_;
     87   talk_base::scoped_ptr<std::vector<XmlElement *> > pvecQueuedStanzas_;
     88 
     89   talk_base::scoped_ptr<SaslMechanism> sasl_mech_;
     90 
     91 #ifdef _DEBUG
     92   static const talk_base::ConstantLabel LOGINTASK_STATES[];
     93 #endif  // _DEBUG
     94 };
     95 
     96 }
     97 
     98 #endif
     99