Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: remoting/signaling/xmpp_login_handler.h

Issue 958703003: Remove dependency on XMPP implementation in WebRTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/signaling/xmpp_login_handler.h
diff --git a/remoting/signaling/xmpp_login_handler.h b/remoting/signaling/xmpp_login_handler.h
new file mode 100644
index 0000000000000000000000000000000000000000..aa479fc6a4fa966a0e33c4ad71b660fbcaa019af
--- /dev/null
+++ b/remoting/signaling/xmpp_login_handler.h
@@ -0,0 +1,127 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_
+#define REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "remoting/signaling/signal_strategy.h"
+
+namespace remoting {
+
+class XmppStreamParser;
+
+// XmppLoginHandler handles authentication handshake for XmppConnection. It
weitao 2015/02/28 07:23:49 s/XmppConnection/XmppSignalStrategy ?
Sergey Ulanov 2015/03/02 18:11:09 Done.
+// receives incoming data using onDataReceived(), calls Delegate::SendMessage()
+// to send outgoing messages and calls Delegate::OnHandshakeDone() after
+// authentication is finished successfully or Delegate::OnError() on error.
+//
+// See RFC3920 for description of XMPP and authentication handshake.
+class XmppLoginHandler {
+ public:
+ class Delegate {
+ public:
+ Delegate() {}
+
+ virtual void SendMessage(const std::string& message) = 0;
+ virtual void StartTls() = 0;
+ virtual void OnHandshakeDone(const std::string& jid,
+ scoped_ptr<XmppStreamParser> parser) = 0;
+ virtual void OnLoginHandlerError(SignalStrategy::Error error) = 0;
+
+ protected:
+ virtual ~Delegate() {}
+ };
+
+ XmppLoginHandler(const std::string& server,
+ const std::string& username,
+ const std::string& auth_token,
+ const std::string& auth_service,
+ bool need_handshake_before_tls,
+ Delegate* delegate);
+ ~XmppLoginHandler();
+
+ void Start();
+ void OnDataReceived(const std::string& data);
+ void OnTlsStarted();
+
+ private:
+ // States the handshake goes through. States are iterated from INIT to DONE
+ // sequentially, except for ERROR state which may be accepted at any point.
+ //
+ // Following messages are sent/received in each state:
+ // INIT
+ // client -> server: Stream header
+ // client -> server: <starttls>
+ // WAIT_STREAM_HEADER
+ // client <- server: Stream header with list of supported features which
+ // should include starttls.
+ // WAIT_STARTTLS_RESPONSE
+ // client <- server: <proceed>
+ // STARTING_TLS
+ // TLS handshake
+ // client -> server: Stream header
+ // client -> server: <auth> message with the OAuth2 token.
+ // WAIT_STREAM_HEADER_AFTER_TLS
+ // client <- server: Stream header with list of supported authentication
+ // methods which is expected to include X-OAUTH2
+ // WAIT_AUTH_RESULT
+ // client <- server: <success> or <failure>
+ // client -> server: Stream header
+ // client -> server: <bind>
+ // client -> server: <iq><session/></iq> to start the session
+ // WAIT_STREAM_HEADER_AFTER_AUTH
+ // client <- server: Stream header with list of features that should
+ // include <bind>.
+ // WAIT_BIND_RESULT
+ // client <- server: <bind> result with JID.
+ // WAIT_SESSION_IQ_RESULT
+ // client <- server: result for <iq><session/></iq>
+ // DONE
+ enum class State {
+ INIT,
+ WAIT_STREAM_HEADER,
+ WAIT_STARTTLS_RESPONSE,
+ STARTING_TLS,
+ WAIT_STREAM_HEADER_AFTER_TLS,
+ WAIT_AUTH_RESULT,
+ WAIT_STREAM_HEADER_AFTER_AUTH,
+ WAIT_BIND_RESULT,
+ WAIT_SESSION_IQ_RESULT,
+ DONE,
+ ERROR,
+ };
+
+ // Callbacks for XmppStreamParser.
+ void OnStanza(scoped_ptr<buzz::XmlElement> stanza);
+ void OnParserError();
+
+ // Helper used to send stream header.
+ void StartStream(const std::string& first_message);
+
+ // Report the |error| to the delegate and changes |state_| to ERROR,
+ void OnError(SignalStrategy::Error error);
+
+ std::string server_;
+ std::string username_;
+ std::string auth_token_;
+ std::string auth_service_;
+ std::string auth_mechanism_;
+ bool need_handshake_before_tls_;
+ Delegate* delegate_;
+
+ State state_;
+
+ std::string jid_;
+
+ scoped_ptr<XmppStreamParser> stream_parser_;
+
+ DISALLOW_COPY_AND_ASSIGN(XmppLoginHandler);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698