Index: remoting/protocol/jingle_session.cc |
diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc |
index 40f06579db13724e9c3b0da708ee6c4b63c4c98b..2a94538870968271c8647429b9e2069bddadb20c 100644 |
--- a/remoting/protocol/jingle_session.cc |
+++ b/remoting/protocol/jingle_session.cc |
@@ -45,6 +45,8 @@ JingleSession::JingleSession( |
jid_ = cricket_session_->remote_name(); |
cricket_session_->SignalState.connect(this, &JingleSession::OnSessionState); |
cricket_session_->SignalError.connect(this, &JingleSession::OnSessionError); |
+ cricket_session_->SignalInfoMessage.connect( |
+ this, &JingleSession::OnSessionInfoMessage); |
} |
JingleSession::~JingleSession() { |
@@ -244,6 +246,25 @@ void JingleSession::OnSessionError( |
} |
} |
+void JingleSession::OnSessionInfoMessage(cricket::Session* session, |
+ const buzz::XmlElement* message) { |
+ DCHECK_EQ(cricket_session_,session); |
+ |
+ const buzz::XmlElement* auth_message = |
+ Authenticator::FindAuthenticatorMessage(message); |
+ if (auth_message) { |
+ if (state_ != CONNECTED || |
Wez
2011/12/03 00:21:05
It might be clearer to have AUTHENTICATING and CON
Sergey Ulanov
2011/12/06 19:37:07
I agree, but it is not related to this CL.
|
+ authenticator_->state() != Authenticator::WAITING_MESSAGE) { |
+ LOG(WARNING) << "Received unexpected authenticator message " |
+ << auth_message->Str(); |
+ return; |
+ } |
+ |
+ authenticator_->ProcessMessage(auth_message); |
+ ProcessAuthenticationStep(); |
+ } |
+} |
+ |
void JingleSession::OnInitiate() { |
DCHECK(CalledOnValidThread()); |
jid_ = cricket_session_->remote_name(); |
@@ -287,16 +308,10 @@ bool JingleSession::InitializeConfigFromDescription( |
return false; |
} |
- DCHECK(authenticator_->state() == Authenticator::WAITING_MESSAGE); |
+ DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); |
authenticator_->ProcessMessage(auth_message); |
- // Support for more than two auth message is not implemented yet. |
- DCHECK(authenticator_->state() != Authenticator::WAITING_MESSAGE && |
- authenticator_->state() != Authenticator::MESSAGE_READY); |
- |
- if (authenticator_->state() != Authenticator::ACCEPTED) { |
- return false; |
- } |
+ // Initialize session configuration. |
SessionConfig config; |
if (!content_description->config()->GetFinalConfig(&config)) { |
LOG(ERROR) << "Connection response does not specify configuration"; |
@@ -326,8 +341,12 @@ void JingleSession::OnAccept() { |
SetState(CONNECTED); |
- if (authenticator_->state() == Authenticator::ACCEPTED) |
+ // Process authentication. |
+ if (authenticator_->state() == Authenticator::ACCEPTED) { |
SetState(AUTHENTICATED); |
+ } else { |
+ ProcessAuthenticationStep(); |
+ } |
} |
void JingleSession::OnTerminate() { |
@@ -382,8 +401,6 @@ void JingleSession::AcceptConnection() { |
DCHECK(authenticator_->state() == Authenticator::WAITING_MESSAGE); |
authenticator_->ProcessMessage(auth_message); |
- // Support for more than two auth message is not implemented yet. |
- DCHECK(authenticator_->state() != Authenticator::WAITING_MESSAGE); |
if (authenticator_->state() == Authenticator::REJECTED) { |
CloseInternal(net::ERR_CONNECTION_FAILED, AUTHENTICATION_FAILED); |
return; |
@@ -396,11 +413,28 @@ void JingleSession::AcceptConnection() { |
buzz::XmlElement* auth_reply = NULL; |
if (authenticator_->state() == Authenticator::MESSAGE_READY) |
auth_reply = authenticator_->GetNextMessage(); |
- DCHECK_EQ(authenticator_->state(), Authenticator::ACCEPTED); |
+ DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY); |
cricket_session_->Accept( |
CreateSessionDescription(candidate_config, auth_reply)); |
} |
+void JingleSession::ProcessAuthenticationStep() { |
+ DCHECK_EQ(state_, CONNECTED); |
+ |
+ while (authenticator_->state() == Authenticator::MESSAGE_READY) { |
+ buzz::XmlElement* auth_message = authenticator_->GetNextMessage(); |
+ cricket::XmlElements message; |
+ message.push_back(auth_message); |
+ cricket_session_->SendInfoMessage(message); |
+ } |
+ |
+ if (authenticator_->state() == Authenticator::ACCEPTED) { |
+ SetState(AUTHENTICATED); |
+ } else if (authenticator_->state() == Authenticator::REJECTED) { |
+ CloseInternal(net::ERR_CONNECTION_ABORTED, AUTHENTICATION_FAILED); |
+ } |
+} |
+ |
void JingleSession::AddChannelConnector( |
const std::string& name, JingleChannelConnector* connector) { |
DCHECK(channel_connectors_.find(name) == channel_connectors_.end()); |