~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/app/webrtc/roapmessages.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 contain classes for parsing and serializing ROAP messages.
 
29
// The ROAP messages are defined in
 
30
// http://tools.ietf.org/html/draft-jennings-rtcweb-signaling-01.
 
31
 
 
32
#ifndef TALK_APP_WEBRTC_ROAPMESSAGES_H_
 
33
#define TALK_APP_WEBRTC_ROAPMESSAGES_H_
 
34
 
 
35
#include <string>
 
36
 
 
37
#include "talk/app/webrtc/roaperrorcodes.h"
 
38
#include "talk/base/basictypes.h"
 
39
#include "talk/base/json.h"
 
40
 
 
41
namespace webrtc {
 
42
 
 
43
class RoapMessageBase {
 
44
 public:
 
45
  enum RoapMessageType {
 
46
    kOffer = 0,
 
47
    kAnswer = 1,
 
48
    kOk = 2,
 
49
    kShutdown = 3,
 
50
    kError = 4,
 
51
    kInvalid = 5,
 
52
  };
 
53
  RoapMessageBase();
 
54
  RoapMessageBase(RoapMessageType type,
 
55
                  const std::string& offer_session_id,
 
56
                  const std::string& answer_session_id,
 
57
                  const std::string& session_token,
 
58
                  const std::string& response_token,
 
59
                  uint32 seq);
 
60
 
 
61
  bool Parse(const std::string& message);
 
62
  std::string Serialize();
 
63
 
 
64
  RoapMessageType type() const { return type_; }
 
65
  const std::string& offer_session_id() const { return offer_session_id_; }
 
66
  const std::string& answer_session_id() const { return answer_session_id_; }
 
67
  const std::string& session_token() const { return session_token_; }
 
68
  const std::string& response_token() const { return response_token_; }
 
69
  uint32 seq() const { return seq_; }
 
70
 
 
71
 protected:
 
72
  virtual void SerializeElement(Json::Value* message);
 
73
  Json::Value jmessage_;  // Contains the parsed json message.
 
74
 
 
75
 private:
 
76
  RoapMessageType type_;
 
77
  std::string offer_session_id_;
 
78
  std::string answer_session_id_;
 
79
  std::string session_token_;
 
80
  std::string response_token_;
 
81
  uint32 seq_;
 
82
};
 
83
 
 
84
class RoapAnswer : public RoapMessageBase {
 
85
 public:
 
86
  // Ctor for creating a new RoapAnswer used for deserialization.
 
87
  // Call Parse after creating this object to parse an answer based on the
 
88
  // message in |base|.
 
89
  explicit RoapAnswer(const RoapMessageBase& base);
 
90
 
 
91
  // Ctor for creating a new RoapAnswer used for serialization.
 
92
  // See the specification for a full description of the arguments.
 
93
  // |desc| is the session description in sdp-format, including ice candidates.
 
94
  RoapAnswer(const std::string& offer_session_id,
 
95
             const std::string& answer_session_id,
 
96
             const std::string& session_token,
 
97
             const std::string& response_token,
 
98
             uint32 seq,
 
99
             const std::string& desc);
 
100
  bool Parse();
 
101
 
 
102
  // Get remote SessionDescription if the session description has been parsed.
 
103
  // Empty string otherwise.
 
104
  const std::string& SessionDescription() const { return desc_; }
 
105
  bool more_coming() const { return more_coming_ ; }
 
106
 
 
107
 protected:
 
108
  virtual void SerializeElement(Json::Value* message);
 
109
 
 
110
 private:
 
111
  bool more_coming_;
 
112
  std::string desc_;
 
113
};
 
114
 
 
115
class RoapOffer : public RoapMessageBase {
 
116
 public:
 
117
  // Ctor for creating a new RoapOffer used for deserialization.
 
118
  // Call Parse after creating this object to parse an answer based on the
 
119
  // message in |base|.
 
120
  explicit RoapOffer(const RoapMessageBase& base);
 
121
  // Ctor for creating a new RoapOffer used for serialization.
 
122
  // See the specification for a full description of the arguments.
 
123
  // |desc| is the session description in sdp-format, including ice candidates.
 
124
  RoapOffer(const std::string& offer_session_id,
 
125
            const std::string& answer_session_id,
 
126
            const std::string& session_token,
 
127
            uint32 seq,
 
128
            uint32 tie_breaker,
 
129
            const std::string& desc);
 
130
  bool Parse();
 
131
 
 
132
  uint32 tie_breaker() const { return tie_breaker_; }
 
133
  // Get remote SessionDescription if the session description has been parsed.
 
134
  // Empty string otherwise.
 
135
  const std::string& SessionDescription() const { return desc_; }
 
136
 
 
137
 protected:
 
138
  virtual void SerializeElement(Json::Value* message);
 
139
 
 
140
 private:
 
141
  uint32 tie_breaker_;
 
142
  std::string desc_;
 
143
};
 
144
 
 
145
class RoapError : public RoapMessageBase {
 
146
 public:
 
147
  explicit RoapError(const RoapMessageBase& base);
 
148
  RoapError(const std::string& offer_session_id,
 
149
            const std::string& answer_session_id,
 
150
            const std::string& session_token,
 
151
            const std::string& response_token,
 
152
            uint32 seq,
 
153
            RoapErrorCode error);
 
154
  bool Parse();
 
155
  RoapErrorCode error() const { return error_; }
 
156
 
 
157
 protected:
 
158
  virtual void SerializeElement(Json::Value* message);
 
159
 
 
160
 private:
 
161
  RoapErrorCode error_;
 
162
};
 
163
 
 
164
class RoapOk : public RoapMessageBase {
 
165
 public:
 
166
  explicit RoapOk(const RoapMessageBase& base);
 
167
  RoapOk(const std::string& offer_session_id,
 
168
         const std::string& answer_session_id,
 
169
         const std::string& session_token,
 
170
         const std::string& response_token,
 
171
         uint32 seq);
 
172
};
 
173
 
 
174
class RoapShutdown : public RoapMessageBase {
 
175
 public:
 
176
  explicit RoapShutdown(const RoapMessageBase& base);
 
177
  RoapShutdown(const std::string& offer_session_id,
 
178
               const std::string& answer_session_id,
 
179
               const std::string& session_token,
 
180
               uint32 seq);
 
181
};
 
182
 
 
183
}  // namespace webrtc
 
184
 
 
185
#endif  // TALK_APP_WEBRTC_ROAPMESSAGES_H_