1 /* 2 * libjingle 3 * Copyright 2011, Google Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 // This file contains a class used for creating and parsing ROAP messages 29 // as defined in http://tools.ietf.org/html/draft-jennings-rtcweb-signaling-01. 30 // The RoapSession is responsible for keeping track of ROAP specific 31 // attributes such as offerSessionId etc of a single session but not the logic 32 // for when to create a specific message. 33 34 #ifndef TALK_APP_WEBRTC_ROAPSESSION_H_ 35 #define TALK_APP_WEBRTC_ROAPSESSION_H_ 36 37 #include <string> 38 #include <vector> 39 40 #include "talk/app/webrtc/roaperrorcodes.h" 41 #include "talk/base/basictypes.h" 42 43 namespace webrtc { 44 45 class RoapAnswer; 46 class RoapError; 47 class RoapMessageBase; 48 class RoapOffer; 49 50 class RoapSession { 51 public: 52 // ParseResult is the result of parsing a message. 53 // It can be either an identified message type or a detected error. 54 enum ParseResult { 55 kOffer, 56 kAnswerMoreComing, // More coming flag set. The SDP contains candidates. 57 kAnswer, 58 kOk, 59 kShutDown, 60 kError, 61 // The messages below are errors that can occur during parsing. 62 kParseConflict, // Conflict detected during parsing of offer. 63 kParseDoubleConflict, // Double conflict detected during parsing of offer. 64 kInvalidMessage // The parsed message is invalid. 65 }; 66 67 RoapSession(); 68 69 // Creates a ROAP offer message based on the provided session description 70 // including candidates. This will update states in the ROAP sessions 71 // variables such as sequence number and create a local session id. 72 std::string CreateOffer(const std::string& desc); 73 74 // Creates a ROAP answer message based on the provided session description. 75 // An offer must have been parsed before this function can be called. 76 std::string CreateAnswer(const std::string& desc); 77 std::string CreateOk(); 78 std::string CreateShutDown(); 79 std::string CreateErrorMessage(RoapErrorCode error); 80 ParseResult Parse(const std::string& msg); 81 RoapErrorCode RemoteError(); 82 RemoteDescription()83 const std::string& RemoteDescription() { return remote_desc_; } 84 85 private: 86 ParseResult ValidateOffer(RoapOffer* received_offer); 87 ParseResult ValidateAnswer(RoapAnswer* received_answer); 88 ParseResult ValidateOk(const RoapMessageBase& message); 89 ParseResult ValidateError(const RoapError& message); 90 91 uint32 seq_; // Sequence number of current message exchange. 92 std::string local_id_; // offererSessionId / answerSessionId of local peer. 93 std::string remote_id_; // offererSessionId / answerSessionId of remote peer. 94 uint32 local_tie_breaker_; // tieBreaker of last sent offer. 95 bool waiting_for_answer_; 96 97 std::string received_offer_id_; // offererSessionId in last received message. 98 std::string received_answer_id_; // answerSessionId in last received message. 99 uint32 received_seq_; // Sequence number of last received message. 100 std::string session_token_; 101 std::string response_token_; 102 103 std::string remote_desc_; 104 RoapErrorCode remote_error_; 105 }; 106 107 } // namespace webrtc 108 109 #endif // TALK_APP_WEBRTC_ROAPSESSION_H_ 110