OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #ifndef WEBRTC_LIBJINGLE_XMPP_XMPPCLIENT_H_ |
| 12 #define WEBRTC_LIBJINGLE_XMPP_XMPPCLIENT_H_ |
| 13 |
| 14 #include <memory> |
| 15 #include <string> |
| 16 |
| 17 #include "webrtc/libjingle/xmpp/asyncsocket.h" |
| 18 #include "webrtc/libjingle/xmpp/xmppclientsettings.h" |
| 19 #include "webrtc/libjingle/xmpp/xmppengine.h" |
| 20 #include "webrtc/libjingle/xmpp/xmpptask.h" |
| 21 #include "webrtc/base/sigslot.h" |
| 22 #include "webrtc/base/task.h" |
| 23 |
| 24 namespace buzz { |
| 25 |
| 26 class PreXmppAuth; |
| 27 class CaptchaChallenge; |
| 28 |
| 29 // Just some non-colliding number. Could have picked "1". |
| 30 #define XMPP_CLIENT_TASK_CODE 0x366c1e47 |
| 31 |
| 32 ///////////////////////////////////////////////////////////////////// |
| 33 // |
| 34 // XMPPCLIENT |
| 35 // |
| 36 ///////////////////////////////////////////////////////////////////// |
| 37 // |
| 38 // See Task first. XmppClient is a parent task for XmppTasks. |
| 39 // |
| 40 // XmppClient is a task which is designed to be the parent task for |
| 41 // all tasks that depend on a single Xmpp connection. If you want to, |
| 42 // for example, listen for subscription requests forever, then your |
| 43 // listener should be a task that is a child of the XmppClient that owns |
| 44 // the connection you are using. XmppClient has all the utility methods |
| 45 // that basically drill through to XmppEngine. |
| 46 // |
| 47 // XmppClient is just a wrapper for XmppEngine, and if I were writing it |
| 48 // all over again, I would make XmppClient == XmppEngine. Why? |
| 49 // XmppEngine needs tasks too, for example it has an XmppLoginTask which |
| 50 // should just be the same kind of Task instead of an XmppEngine specific |
| 51 // thing. It would help do certain things like GAIA auth cleaner. |
| 52 // |
| 53 ///////////////////////////////////////////////////////////////////// |
| 54 |
| 55 class XmppClient : public XmppTaskParentInterface, |
| 56 public XmppClientInterface, |
| 57 public sigslot::has_slots<> |
| 58 { |
| 59 public: |
| 60 explicit XmppClient(rtc::TaskParent * parent); |
| 61 virtual ~XmppClient(); |
| 62 |
| 63 XmppReturnStatus Connect(const XmppClientSettings & settings, |
| 64 const std::string & lang, |
| 65 AsyncSocket * socket, |
| 66 PreXmppAuth * preauth); |
| 67 |
| 68 virtual int ProcessStart(); |
| 69 virtual int ProcessResponse(); |
| 70 XmppReturnStatus Disconnect(); |
| 71 |
| 72 sigslot::signal1<XmppEngine::State> SignalStateChange; |
| 73 XmppEngine::Error GetError(int *subcode); |
| 74 |
| 75 // When there is a <stream:error> stanza, return the stanza |
| 76 // so that they can be handled. |
| 77 const XmlElement *GetStreamError(); |
| 78 |
| 79 // When there is an authentication error, we may have captcha info |
| 80 // that the user can use to unlock their account |
| 81 CaptchaChallenge GetCaptchaChallenge(); |
| 82 |
| 83 // When authentication is successful, this returns the service token |
| 84 // (if we used GAIA authentication) |
| 85 std::string GetAuthMechanism(); |
| 86 std::string GetAuthToken(); |
| 87 |
| 88 XmppReturnStatus SendRaw(const std::string & text); |
| 89 |
| 90 XmppEngine* engine(); |
| 91 |
| 92 sigslot::signal2<const char *, int> SignalLogInput; |
| 93 sigslot::signal2<const char *, int> SignalLogOutput; |
| 94 |
| 95 // As XmppTaskParentIntreface |
| 96 virtual XmppClientInterface* GetClient() { return this; } |
| 97 |
| 98 // As XmppClientInterface |
| 99 virtual XmppEngine::State GetState() const; |
| 100 virtual const Jid& jid() const; |
| 101 virtual std::string NextId(); |
| 102 virtual XmppReturnStatus SendStanza(const XmlElement *stanza); |
| 103 virtual XmppReturnStatus SendStanzaError(const XmlElement * pelOriginal, |
| 104 XmppStanzaError code, |
| 105 const std::string & text); |
| 106 virtual void AddXmppTask(XmppTask *, XmppEngine::HandlerLevel); |
| 107 virtual void RemoveXmppTask(XmppTask *); |
| 108 |
| 109 private: |
| 110 friend class XmppTask; |
| 111 |
| 112 void OnAuthDone(); |
| 113 |
| 114 // Internal state management |
| 115 enum { |
| 116 STATE_PRE_XMPP_LOGIN = STATE_NEXT, |
| 117 STATE_START_XMPP_LOGIN = STATE_NEXT + 1, |
| 118 }; |
| 119 int Process(int state) { |
| 120 switch (state) { |
| 121 case STATE_PRE_XMPP_LOGIN: return ProcessTokenLogin(); |
| 122 case STATE_START_XMPP_LOGIN: return ProcessStartXmppLogin(); |
| 123 default: return Task::Process(state); |
| 124 } |
| 125 } |
| 126 |
| 127 std::string GetStateName(int state) const { |
| 128 switch (state) { |
| 129 case STATE_PRE_XMPP_LOGIN: return "PRE_XMPP_LOGIN"; |
| 130 case STATE_START_XMPP_LOGIN: return "START_XMPP_LOGIN"; |
| 131 default: return Task::GetStateName(state); |
| 132 } |
| 133 } |
| 134 |
| 135 int ProcessTokenLogin(); |
| 136 int ProcessStartXmppLogin(); |
| 137 void EnsureClosed(); |
| 138 |
| 139 class Private; |
| 140 friend class Private; |
| 141 std::unique_ptr<Private> d_; |
| 142 |
| 143 bool delivering_signal_; |
| 144 bool valid_; |
| 145 }; |
| 146 |
| 147 } |
| 148 |
| 149 #endif // WEBRTC_LIBJINGLE_XMPP_XMPPCLIENT_H_ |
OLD | NEW |