| 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 #include "remoting/protocol/jingle_session.h" | 5 #include "remoting/protocol/jingle_session.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 if (is_session_active()) { | 240 if (is_session_active()) { |
| 241 // Send session-terminate message with the appropriate error code. | 241 // Send session-terminate message with the appropriate error code. |
| 242 JingleMessage::Reason reason; | 242 JingleMessage::Reason reason; |
| 243 switch (error) { | 243 switch (error) { |
| 244 case OK: | 244 case OK: |
| 245 reason = JingleMessage::SUCCESS; | 245 reason = JingleMessage::SUCCESS; |
| 246 break; | 246 break; |
| 247 case SESSION_REJECTED: | 247 case SESSION_REJECTED: |
| 248 case AUTHENTICATION_FAILED: | 248 case AUTHENTICATION_FAILED: |
| 249 case INVALID_ACCOUNT: |
| 249 reason = JingleMessage::DECLINE; | 250 reason = JingleMessage::DECLINE; |
| 250 break; | 251 break; |
| 251 case INVALID_ACCOUNT: | |
| 252 // TODO(zijiehe): Instead of using SECURITY_ERROR Jingle reason, add a | |
| 253 // new tag under crd namespace to export detail error reason to client. | |
| 254 reason = JingleMessage::SECURITY_ERROR; | |
| 255 break; | |
| 256 case INCOMPATIBLE_PROTOCOL: | 252 case INCOMPATIBLE_PROTOCOL: |
| 257 reason = JingleMessage::INCOMPATIBLE_PARAMETERS; | 253 reason = JingleMessage::INCOMPATIBLE_PARAMETERS; |
| 258 break; | 254 break; |
| 259 case HOST_OVERLOAD: | 255 case HOST_OVERLOAD: |
| 260 reason = JingleMessage::CANCEL; | 256 reason = JingleMessage::CANCEL; |
| 261 break; | 257 break; |
| 262 case MAX_SESSION_LENGTH: | 258 case MAX_SESSION_LENGTH: |
| 263 reason = JingleMessage::EXPIRED; | 259 reason = JingleMessage::EXPIRED; |
| 264 break; | 260 break; |
| 265 case HOST_CONFIGURATION_ERROR: | 261 case HOST_CONFIGURATION_ERROR: |
| 266 reason = JingleMessage::FAILED_APPLICATION; | 262 reason = JingleMessage::FAILED_APPLICATION; |
| 267 break; | 263 break; |
| 268 default: | 264 default: |
| 269 reason = JingleMessage::GENERAL_ERROR; | 265 reason = JingleMessage::GENERAL_ERROR; |
| 270 } | 266 } |
| 271 | 267 |
| 272 JingleMessage message(peer_address_, JingleMessage::SESSION_TERMINATE, | 268 JingleMessage message(peer_address_, JingleMessage::SESSION_TERMINATE, |
| 273 session_id_); | 269 session_id_); |
| 274 message.reason = reason; | 270 message.reason = reason; |
| 271 message.error_code = error; |
| 275 SendMessage(message); | 272 SendMessage(message); |
| 276 } | 273 } |
| 277 | 274 |
| 278 error_ = error; | 275 error_ = error; |
| 279 | 276 |
| 280 if (state_ != FAILED && state_ != CLOSED) { | 277 if (state_ != FAILED && state_ != CLOSED) { |
| 281 if (error != OK) { | 278 if (error != OK) { |
| 282 SetState(FAILED); | 279 SetState(FAILED); |
| 283 } else { | 280 } else { |
| 284 SetState(CLOSED); | 281 SetState(CLOSED); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 void JingleSession::OnTerminate(const JingleMessage& message, | 471 void JingleSession::OnTerminate(const JingleMessage& message, |
| 475 const ReplyCallback& reply_callback) { | 472 const ReplyCallback& reply_callback) { |
| 476 if (!is_session_active()) { | 473 if (!is_session_active()) { |
| 477 LOG(WARNING) << "Received unexpected session-terminate message."; | 474 LOG(WARNING) << "Received unexpected session-terminate message."; |
| 478 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); | 475 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); |
| 479 return; | 476 return; |
| 480 } | 477 } |
| 481 | 478 |
| 482 reply_callback.Run(JingleMessageReply::NONE); | 479 reply_callback.Run(JingleMessageReply::NONE); |
| 483 | 480 |
| 484 switch (message.reason) { | 481 error_ = message.error_code; |
| 485 case JingleMessage::SUCCESS: | 482 if (error_ == UNKNOWN_ERROR) { |
| 486 if (state_ == CONNECTING) { | 483 // get error code from message.reason for compatibility with older versions |
| 487 error_ = SESSION_REJECTED; | 484 // that do not add <error-code>. |
| 488 } else { | 485 switch (message.reason) { |
| 489 error_ = OK; | 486 case JingleMessage::SUCCESS: |
| 490 } | 487 if (state_ == CONNECTING) { |
| 491 break; | 488 error_ = SESSION_REJECTED; |
| 492 case JingleMessage::DECLINE: | 489 } else { |
| 493 error_ = AUTHENTICATION_FAILED; | 490 error_ = OK; |
| 494 break; | 491 } |
| 495 case JingleMessage::SECURITY_ERROR: | 492 break; |
| 496 error_ = INVALID_ACCOUNT; | 493 case JingleMessage::DECLINE: |
| 497 break; | 494 error_ = AUTHENTICATION_FAILED; |
| 498 case JingleMessage::CANCEL: | 495 break; |
| 499 error_ = HOST_OVERLOAD; | 496 case JingleMessage::CANCEL: |
| 500 break; | 497 error_ = HOST_OVERLOAD; |
| 501 case JingleMessage::EXPIRED: | 498 break; |
| 502 error_ = MAX_SESSION_LENGTH; | 499 case JingleMessage::EXPIRED: |
| 503 break; | 500 error_ = MAX_SESSION_LENGTH; |
| 504 case JingleMessage::INCOMPATIBLE_PARAMETERS: | 501 break; |
| 505 error_ = INCOMPATIBLE_PROTOCOL; | 502 case JingleMessage::INCOMPATIBLE_PARAMETERS: |
| 506 break; | 503 error_ = INCOMPATIBLE_PROTOCOL; |
| 507 case JingleMessage::FAILED_APPLICATION: | 504 break; |
| 508 error_ = HOST_CONFIGURATION_ERROR; | 505 case JingleMessage::FAILED_APPLICATION: |
| 509 break; | 506 error_ = HOST_CONFIGURATION_ERROR; |
| 510 case JingleMessage::GENERAL_ERROR: | 507 break; |
| 511 error_ = CHANNEL_CONNECTION_ERROR; | 508 case JingleMessage::GENERAL_ERROR: |
| 512 break; | 509 error_ = CHANNEL_CONNECTION_ERROR; |
| 513 default: | 510 break; |
| 514 error_ = UNKNOWN_ERROR; | 511 default: |
| 512 error_ = UNKNOWN_ERROR; |
| 513 } |
| 514 } else if (error_ == SESSION_REJECTED) { |
| 515 // For backward compatibility, we still use AUTHENTICATION_FAILED for |
| 516 // SESSION_REJECTED error. |
| 517 // TODO(zijiehe): Handle SESSION_REJECTED error in WebApp. Tracked by |
| 518 // http://crbug.com/618036. |
| 519 error_ = AUTHENTICATION_FAILED; |
| 515 } | 520 } |
| 516 | 521 |
| 517 if (error_ != OK) { | 522 if (error_ != OK) { |
| 518 SetState(FAILED); | 523 SetState(FAILED); |
| 519 } else { | 524 } else { |
| 520 SetState(CLOSED); | 525 SetState(CLOSED); |
| 521 } | 526 } |
| 522 } | 527 } |
| 523 | 528 |
| 524 bool JingleSession::InitializeConfigFromDescription( | 529 bool JingleSession::InitializeConfigFromDescription( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } | 606 } |
| 602 } | 607 } |
| 603 | 608 |
| 604 bool JingleSession::is_session_active() { | 609 bool JingleSession::is_session_active() { |
| 605 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || | 610 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || |
| 606 state_ == AUTHENTICATING || state_ == AUTHENTICATED; | 611 state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
| 607 } | 612 } |
| 608 | 613 |
| 609 } // namespace protocol | 614 } // namespace protocol |
| 610 } // namespace remoting | 615 } // namespace remoting |
| OLD | NEW |