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 TALK_XMPP_LOGINTASK_H_
29#define TALK_XMPP_LOGINTASK_H_
30
31#include <string>
32#include <vector>
33
34#include "talk/xmpp/jid.h"
35#include "talk/xmpp/xmppengine.h"
36#include "webrtc/base/logging.h"
37#include "webrtc/base/scoped_ptr.h"
38
39namespace buzz {
40
41class XmlElement;
42class XmppEngineImpl;
43class SaslMechanism;
44
45
46// TODO: Rename to LoginTask.
47class XmppLoginTask {
48
49public:
50  XmppLoginTask(XmppEngineImpl *pctx);
51  ~XmppLoginTask();
52
53  bool IsDone()
54    { return state_ == LOGINSTATE_DONE; }
55  void IncomingStanza(const XmlElement * element, bool isStart);
56  void OutgoingStanza(const XmlElement *element);
57  void set_allow_non_google_login(bool b)
58    { allowNonGoogleLogin_ = b; }
59
60private:
61  enum LoginTaskState {
62    LOGINSTATE_INIT = 0,
63    LOGINSTATE_STREAMSTART_SENT,
64    LOGINSTATE_STARTED_XMPP,
65    LOGINSTATE_TLS_INIT,
66    LOGINSTATE_AUTH_INIT,
67    LOGINSTATE_BIND_INIT,
68    LOGINSTATE_TLS_REQUESTED,
69    LOGINSTATE_SASL_RUNNING,
70    LOGINSTATE_BIND_REQUESTED,
71    LOGINSTATE_SESSION_REQUESTED,
72    LOGINSTATE_DONE,
73  };
74
75  const XmlElement * NextStanza();
76  bool Advance();
77  bool HandleStartStream(const XmlElement * element);
78  bool HandleFeatures(const XmlElement * element);
79  const XmlElement * GetFeature(const QName & name);
80  bool Failure(XmppEngine::Error reason);
81  void FlushQueuedStanzas();
82
83  XmppEngineImpl * pctx_;
84  bool authNeeded_;
85  bool allowNonGoogleLogin_;
86  LoginTaskState state_;
87  const XmlElement * pelStanza_;
88  bool isStart_;
89  std::string iqId_;
90  rtc::scoped_ptr<XmlElement> pelFeatures_;
91  Jid fullJid_;
92  std::string streamId_;
93  rtc::scoped_ptr<std::vector<XmlElement *> > pvecQueuedStanzas_;
94
95  rtc::scoped_ptr<SaslMechanism> sasl_mech_;
96
97#ifdef _DEBUG
98  static const rtc::ConstantLabel LOGINTASK_STATES[];
99#endif  // _DEBUG
100};
101
102}
103
104#endif  //  TALK_XMPP_LOGINTASK_H_
105