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

Side by Side 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, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_
6 #define REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "remoting/signaling/signal_strategy.h"
12
13 namespace remoting {
14
15 class XmppStreamParser;
16
17 // 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.
18 // receives incoming data using onDataReceived(), calls Delegate::SendMessage()
19 // to send outgoing messages and calls Delegate::OnHandshakeDone() after
20 // authentication is finished successfully or Delegate::OnError() on error.
21 //
22 // See RFC3920 for description of XMPP and authentication handshake.
23 class XmppLoginHandler {
24 public:
25 class Delegate {
26 public:
27 Delegate() {}
28
29 virtual void SendMessage(const std::string& message) = 0;
30 virtual void StartTls() = 0;
31 virtual void OnHandshakeDone(const std::string& jid,
32 scoped_ptr<XmppStreamParser> parser) = 0;
33 virtual void OnLoginHandlerError(SignalStrategy::Error error) = 0;
34
35 protected:
36 virtual ~Delegate() {}
37 };
38
39 XmppLoginHandler(const std::string& server,
40 const std::string& username,
41 const std::string& auth_token,
42 const std::string& auth_service,
43 bool need_handshake_before_tls,
44 Delegate* delegate);
45 ~XmppLoginHandler();
46
47 void Start();
48 void OnDataReceived(const std::string& data);
49 void OnTlsStarted();
50
51 private:
52 // States the handshake goes through. States are iterated from INIT to DONE
53 // sequentially, except for ERROR state which may be accepted at any point.
54 //
55 // Following messages are sent/received in each state:
56 // INIT
57 // client -> server: Stream header
58 // client -> server: <starttls>
59 // WAIT_STREAM_HEADER
60 // client <- server: Stream header with list of supported features which
61 // should include starttls.
62 // WAIT_STARTTLS_RESPONSE
63 // client <- server: <proceed>
64 // STARTING_TLS
65 // TLS handshake
66 // client -> server: Stream header
67 // client -> server: <auth> message with the OAuth2 token.
68 // WAIT_STREAM_HEADER_AFTER_TLS
69 // client <- server: Stream header with list of supported authentication
70 // methods which is expected to include X-OAUTH2
71 // WAIT_AUTH_RESULT
72 // client <- server: <success> or <failure>
73 // client -> server: Stream header
74 // client -> server: <bind>
75 // client -> server: <iq><session/></iq> to start the session
76 // WAIT_STREAM_HEADER_AFTER_AUTH
77 // client <- server: Stream header with list of features that should
78 // include <bind>.
79 // WAIT_BIND_RESULT
80 // client <- server: <bind> result with JID.
81 // WAIT_SESSION_IQ_RESULT
82 // client <- server: result for <iq><session/></iq>
83 // DONE
84 enum class State {
85 INIT,
86 WAIT_STREAM_HEADER,
87 WAIT_STARTTLS_RESPONSE,
88 STARTING_TLS,
89 WAIT_STREAM_HEADER_AFTER_TLS,
90 WAIT_AUTH_RESULT,
91 WAIT_STREAM_HEADER_AFTER_AUTH,
92 WAIT_BIND_RESULT,
93 WAIT_SESSION_IQ_RESULT,
94 DONE,
95 ERROR,
96 };
97
98 // Callbacks for XmppStreamParser.
99 void OnStanza(scoped_ptr<buzz::XmlElement> stanza);
100 void OnParserError();
101
102 // Helper used to send stream header.
103 void StartStream(const std::string& first_message);
104
105 // Report the |error| to the delegate and changes |state_| to ERROR,
106 void OnError(SignalStrategy::Error error);
107
108 std::string server_;
109 std::string username_;
110 std::string auth_token_;
111 std::string auth_service_;
112 std::string auth_mechanism_;
113 bool need_handshake_before_tls_;
114 Delegate* delegate_;
115
116 State state_;
117
118 std::string jid_;
119
120 scoped_ptr<XmppStreamParser> stream_parser_;
121
122 DISALLOW_COPY_AND_ASSIGN(XmppLoginHandler);
123 };
124
125 } // namespace remoting
126
127 #endif // REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698