OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_PROTOCOL_AUTHENTICATOR_H_ | 5 #ifndef REMOTING_PROTOCOL_AUTHENTICATOR_H_ |
6 #define REMOTING_PROTOCOL_AUTHENTICATOR_H_ | 6 #define REMOTING_PROTOCOL_AUTHENTICATOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 | 12 |
12 namespace buzz { | 13 namespace buzz { |
13 class XmlElement; | 14 class XmlElement; |
14 } // namespace buzz | 15 } // namespace buzz |
15 | 16 |
16 namespace remoting { | 17 namespace remoting { |
17 namespace protocol { | 18 namespace protocol { |
18 | 19 |
19 class ChannelAuthenticator; | 20 class ChannelAuthenticator; |
(...skipping 11 matching lines...) Expand all Loading... |
31 // and session-accept messages or in a session-info | 32 // and session-accept messages or in a session-info |
32 // message. Session-info messages are used only if authenticators need | 33 // message. Session-info messages are used only if authenticators need |
33 // to exchange more than one message. | 34 // to exchange more than one message. |
34 class Authenticator { | 35 class Authenticator { |
35 public: | 36 public: |
36 // Allowed state transitions: | 37 // Allowed state transitions: |
37 // When ProcessMessage() is called: | 38 // When ProcessMessage() is called: |
38 // WAITING_MESSAGE -> MESSAGE_READY | 39 // WAITING_MESSAGE -> MESSAGE_READY |
39 // WAITING_MESSAGE -> ACCEPTED | 40 // WAITING_MESSAGE -> ACCEPTED |
40 // WAITING_MESSAGE -> REJECTED | 41 // WAITING_MESSAGE -> REJECTED |
| 42 // WAITING_MESSAGE -> PROCESSING_MESSAGE |
| 43 // After asynchronous message processing finishes: |
| 44 /// PROCESSING_MESSAGE -> MESSAGE_READY |
41 // When GetNextMessage() is called: | 45 // When GetNextMessage() is called: |
42 // MESSAGE_READY -> WAITING_MESSAGE | 46 // MESSAGE_READY -> WAITING_MESSAGE |
43 // MESSAGE_READY -> ACCEPTED | 47 // MESSAGE_READY -> ACCEPTED |
44 enum State { | 48 enum State { |
45 // Waiting for the next message from the peer. | 49 // Waiting for the next message from the peer. |
46 WAITING_MESSAGE, | 50 WAITING_MESSAGE, |
47 | 51 |
48 // Next message is ready to be sent to the peer. | 52 // Next message is ready to be sent to the peer. |
49 MESSAGE_READY, | 53 MESSAGE_READY, |
50 | 54 |
51 // Session is authenticated successufully. | 55 // Session is authenticated successufully. |
52 ACCEPTED, | 56 ACCEPTED, |
53 | 57 |
54 // Session is rejected. | 58 // Session is rejected. |
55 REJECTED, | 59 REJECTED, |
| 60 |
| 61 // Asynchronously processing the last message from the peer. |
| 62 PROCESSING_MESSAGE, |
56 }; | 63 }; |
57 | 64 |
58 enum RejectionReason { | 65 enum RejectionReason { |
59 INVALID_CREDENTIALS, | 66 INVALID_CREDENTIALS, |
60 PROTOCOL_ERROR, | 67 PROTOCOL_ERROR, |
61 }; | 68 }; |
62 | 69 |
63 // Returns true if |message| is an Authenticator message. | 70 // Returns true if |message| is an Authenticator message. |
64 static bool IsAuthenticatorMessage(const buzz::XmlElement* message); | 71 static bool IsAuthenticatorMessage(const buzz::XmlElement* message); |
65 | 72 |
66 // Creates an empty Authenticator message, owned by the caller. | 73 // Creates an empty Authenticator message, owned by the caller. |
67 static scoped_ptr<buzz::XmlElement> CreateEmptyAuthenticatorMessage(); | 74 static scoped_ptr<buzz::XmlElement> CreateEmptyAuthenticatorMessage(); |
68 | 75 |
69 // Finds Authenticator message among child elements of |message|, or | 76 // Finds Authenticator message among child elements of |message|, or |
70 // returns NULL otherwise. | 77 // returns NULL otherwise. |
71 static const buzz::XmlElement* FindAuthenticatorMessage( | 78 static const buzz::XmlElement* FindAuthenticatorMessage( |
72 const buzz::XmlElement* message); | 79 const buzz::XmlElement* message); |
73 | 80 |
74 Authenticator() {} | 81 Authenticator() {} |
75 virtual ~Authenticator() {} | 82 virtual ~Authenticator() {} |
76 | 83 |
77 // Returns current state of the authenticator. | 84 // Returns current state of the authenticator. |
78 virtual State state() const = 0; | 85 virtual State state() const = 0; |
79 | 86 |
80 // Returns rejection reason. Can be called only when in REJECTED state. | 87 // Returns rejection reason. Can be called only when in REJECTED state. |
81 virtual RejectionReason rejection_reason() const = 0; | 88 virtual RejectionReason rejection_reason() const = 0; |
82 | 89 |
83 // Called in response to incoming message received from the peer. | 90 // Called in response to incoming message received from the peer. |
84 // Should only be called when in WAITING_MESSAGE state. Caller | 91 // Should only be called when in WAITING_MESSAGE state. Caller retains |
85 // retains ownership of |message|. | 92 // ownership of |message|. |resume_callback| will be called when processing is |
86 virtual void ProcessMessage(const buzz::XmlElement* message) = 0; | 93 // finished. The implementation must guarantee that |resume_callback| is not |
| 94 // called after the Authenticator is destroyed. |
| 95 virtual void ProcessMessage(const buzz::XmlElement* message, |
| 96 const base::Closure& resume_callback) = 0; |
87 | 97 |
88 // Must be called when in MESSAGE_READY state. Returns next | 98 // Must be called when in MESSAGE_READY state. Returns next |
89 // authentication message that needs to be sent to the peer. | 99 // authentication message that needs to be sent to the peer. |
90 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() = 0; | 100 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() = 0; |
91 | 101 |
92 // Creates new authenticator for a channel. Can be called only in | 102 // Creates new authenticator for a channel. Can be called only in |
93 // the ACCEPTED state. | 103 // the ACCEPTED state. |
94 virtual scoped_ptr<ChannelAuthenticator> | 104 virtual scoped_ptr<ChannelAuthenticator> |
95 CreateChannelAuthenticator() const = 0; | 105 CreateChannelAuthenticator() const = 0; |
96 }; | 106 }; |
(...skipping 15 matching lines...) Expand all Loading... |
112 virtual scoped_ptr<Authenticator> CreateAuthenticator( | 122 virtual scoped_ptr<Authenticator> CreateAuthenticator( |
113 const std::string& local_jid, | 123 const std::string& local_jid, |
114 const std::string& remote_jid, | 124 const std::string& remote_jid, |
115 const buzz::XmlElement* first_message) = 0; | 125 const buzz::XmlElement* first_message) = 0; |
116 }; | 126 }; |
117 | 127 |
118 } // namespace protocol | 128 } // namespace protocol |
119 } // namespace remoting | 129 } // namespace remoting |
120 | 130 |
121 #endif // REMOTING_PROTOCOL_AUTHENTICATOR_H_ | 131 #endif // REMOTING_PROTOCOL_AUTHENTICATOR_H_ |
OLD | NEW |