3
* Copyright 2010, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
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.
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.
28
#ifndef TALK_P2P_BASE_SESSIONMESSAGES_H_
29
#define TALK_P2P_BASE_SESSIONMESSAGES_H_
35
#include "talk/base/basictypes.h"
36
#include "talk/p2p/base/constants.h"
37
#include "talk/p2p/base/parsing.h"
38
#include "talk/p2p/base/sessiondescription.h" // Needed to delete contents.
39
#include "talk/xmllite/xmlelement.h"
47
class TransportParser;
49
typedef std::vector<Candidate> Candidates;
50
typedef std::map<std::string, ContentParser*> ContentParserMap;
51
typedef std::map<std::string, TransportParser*> TransportParserMap;
56
ACTION_SESSION_INITIATE,
58
ACTION_SESSION_ACCEPT,
59
ACTION_SESSION_REJECT,
60
ACTION_SESSION_TERMINATE,
62
ACTION_TRANSPORT_INFO,
63
ACTION_TRANSPORT_ACCEPT,
65
ACTION_DESCRIPTION_INFO,
68
// Abstraction of a <jingle> element within an <iq> stanza, per XMPP
69
// standard XEP-166. Can be serialized into multiple protocols,
70
// including the standard (Jingle) and the draft standard (Gingle).
71
// In general, used to communicate actions related to a p2p session,
72
// such accept, initiate, terminate, etc.
74
struct SessionMessage {
75
SessionMessage() : action_elem(NULL), stanza(NULL) {}
77
SessionMessage(SignalingProtocol protocol, ActionType type,
78
const std::string& sid, const std::string& initiator) :
79
protocol(protocol), type(type), sid(sid), initiator(initiator),
80
action_elem(NULL), stanza(NULL) {}
85
SignalingProtocol protocol;
87
std::string sid; // session id
88
std::string initiator;
90
// Used for further parsing when necessary.
91
// Represents <session> or <jingle>.
92
const buzz::XmlElement* action_elem;
93
// Mostly used for debugging.
94
const buzz::XmlElement* stanza;
97
// A TransportInfo is NOT a transport-info message. It is comparable
98
// to a "ContentInfo". A transport-info message is basically just a
99
// collection of TransportInfos.
100
struct TransportInfo {
103
TransportInfo(const std::string& content_name,
104
const std::string& transport_type,
105
const Candidates& candidates)
106
: content_name(content_name),
107
transport_type(transport_type),
108
candidates(candidates) {}
110
std::string content_name;
111
std::string transport_type; // xmlns of <transport>
112
Candidates candidates;
115
typedef std::vector<TransportInfo> TransportInfos;
117
// TODO: Break up this class so we don't have to typedef it into
118
// different classes.
119
struct ContentMessage {
120
ContentMessage() : owns_contents(false) {}
124
for (ContentInfos::iterator content = contents.begin();
125
content != contents.end(); content++) {
126
delete content->description;
131
// Caller takes ownership of contents.
132
ContentInfos ClearContents() {
135
owns_contents = false;
140
ContentInfos contents;
141
TransportInfos transports;
142
ContentGroups groups;
145
typedef ContentMessage SessionInitiate;
146
typedef ContentMessage SessionAccept;
147
// Note that a DescriptionInfo does not have TransportInfos.
148
typedef ContentMessage DescriptionInfo;
150
struct SessionTerminate {
151
SessionTerminate() {}
153
explicit SessionTerminate(const std::string& reason) :
157
std::string debug_reason;
160
struct SessionRedirect {
165
bool IsSessionMessage(const buzz::XmlElement* stanza);
166
bool ParseSessionMessage(const buzz::XmlElement* stanza,
169
// Will return an error if there is more than one content type.
170
bool ParseContentType(SignalingProtocol protocol,
171
const buzz::XmlElement* action_elem,
172
std::string* content_type,
174
void WriteSessionMessage(const SessionMessage& msg,
175
const XmlElements& action_elems,
176
buzz::XmlElement* stanza);
177
bool ParseSessionInitiate(SignalingProtocol protocol,
178
const buzz::XmlElement* action_elem,
179
const ContentParserMap& content_parsers,
180
const TransportParserMap& transport_parsers,
181
SessionInitiate* init,
183
bool WriteSessionInitiate(SignalingProtocol protocol,
184
const ContentInfos& contents,
185
const TransportInfos& tinfos,
186
const ContentParserMap& content_parsers,
187
const TransportParserMap& transport_parsers,
188
const ContentGroups& groups,
191
bool ParseSessionAccept(SignalingProtocol protocol,
192
const buzz::XmlElement* action_elem,
193
const ContentParserMap& content_parsers,
194
const TransportParserMap& transport_parsers,
195
SessionAccept* accept,
197
bool WriteSessionAccept(SignalingProtocol protocol,
198
const ContentInfos& contents,
199
const TransportInfos& tinfos,
200
const ContentParserMap& content_parsers,
201
const TransportParserMap& transport_parsers,
202
const ContentGroups& groups,
205
bool ParseSessionTerminate(SignalingProtocol protocol,
206
const buzz::XmlElement* action_elem,
207
SessionTerminate* term,
209
void WriteSessionTerminate(SignalingProtocol protocol,
210
const SessionTerminate& term,
212
bool ParseDescriptionInfo(SignalingProtocol protocol,
213
const buzz::XmlElement* action_elem,
214
const ContentParserMap& content_parsers,
215
const TransportParserMap& transport_parsers,
216
DescriptionInfo* description_info,
218
// Since a TransportInfo is not a transport-info message, and a
219
// transport-info message is just a collection of TransportInfos, we
220
// say Parse/Write TransportInfos for transport-info messages.
221
bool ParseTransportInfos(SignalingProtocol protocol,
222
const buzz::XmlElement* action_elem,
223
const ContentInfos& contents,
224
const TransportParserMap& trans_parsers,
225
TransportInfos* tinfos,
227
bool WriteTransportInfos(SignalingProtocol protocol,
228
const TransportInfos& tinfos,
229
const TransportParserMap& trans_parsers,
232
// Handles both Gingle and Jingle syntax.
233
bool FindSessionRedirect(const buzz::XmlElement* stanza,
234
SessionRedirect* redirect);
235
} // namespace cricket
237
#endif // TALK_P2P_BASE_SESSIONMESSAGES_H_