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

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/p2p/base/sessionmessages.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 2010, 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
#ifndef TALK_P2P_BASE_SESSIONMESSAGES_H_
 
29
#define TALK_P2P_BASE_SESSIONMESSAGES_H_
 
30
 
 
31
#include <string>
 
32
#include <vector>
 
33
#include <map>
 
34
 
 
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"
 
40
 
 
41
namespace cricket {
 
42
 
 
43
struct ParseError;
 
44
struct WriteError;
 
45
class Candidate;
 
46
class ContentParser;
 
47
class TransportParser;
 
48
 
 
49
typedef std::vector<Candidate> Candidates;
 
50
typedef std::map<std::string, ContentParser*> ContentParserMap;
 
51
typedef std::map<std::string, TransportParser*> TransportParserMap;
 
52
 
 
53
enum ActionType {
 
54
  ACTION_UNKNOWN,
 
55
 
 
56
  ACTION_SESSION_INITIATE,
 
57
  ACTION_SESSION_INFO,
 
58
  ACTION_SESSION_ACCEPT,
 
59
  ACTION_SESSION_REJECT,
 
60
  ACTION_SESSION_TERMINATE,
 
61
 
 
62
  ACTION_TRANSPORT_INFO,
 
63
  ACTION_TRANSPORT_ACCEPT,
 
64
 
 
65
  ACTION_DESCRIPTION_INFO,
 
66
};
 
67
 
 
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.
 
73
 
 
74
struct SessionMessage {
 
75
  SessionMessage() : action_elem(NULL), stanza(NULL) {}
 
76
 
 
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) {}
 
81
 
 
82
  std::string id;
 
83
  std::string from;
 
84
  std::string to;
 
85
  SignalingProtocol protocol;
 
86
  ActionType type;
 
87
  std::string sid;  // session id
 
88
  std::string initiator;
 
89
 
 
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;
 
95
};
 
96
 
 
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 {
 
101
  TransportInfo() {}
 
102
 
 
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) {}
 
109
 
 
110
  std::string content_name;
 
111
  std::string transport_type;  // xmlns of <transport>
 
112
  Candidates candidates;
 
113
};
 
114
 
 
115
typedef std::vector<TransportInfo> TransportInfos;
 
116
 
 
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) {}
 
121
 
 
122
  ~ContentMessage() {
 
123
    if (owns_contents) {
 
124
      for (ContentInfos::iterator content = contents.begin();
 
125
           content != contents.end(); content++) {
 
126
        delete content->description;
 
127
      }
 
128
    }
 
129
  }
 
130
 
 
131
  // Caller takes ownership of contents.
 
132
  ContentInfos ClearContents() {
 
133
    ContentInfos out;
 
134
    contents.swap(out);
 
135
    owns_contents = false;
 
136
    return out;
 
137
  }
 
138
 
 
139
  bool owns_contents;
 
140
  ContentInfos contents;
 
141
  TransportInfos transports;
 
142
  ContentGroups groups;
 
143
};
 
144
 
 
145
typedef ContentMessage SessionInitiate;
 
146
typedef ContentMessage SessionAccept;
 
147
// Note that a DescriptionInfo does not have TransportInfos.
 
148
typedef ContentMessage DescriptionInfo;
 
149
 
 
150
struct SessionTerminate {
 
151
  SessionTerminate() {}
 
152
 
 
153
  explicit SessionTerminate(const std::string& reason) :
 
154
      reason(reason) {}
 
155
 
 
156
  std::string reason;
 
157
  std::string debug_reason;
 
158
};
 
159
 
 
160
struct SessionRedirect {
 
161
  std::string target;
 
162
};
 
163
 
 
164
 
 
165
bool IsSessionMessage(const buzz::XmlElement* stanza);
 
166
bool ParseSessionMessage(const buzz::XmlElement* stanza,
 
167
                         SessionMessage* msg,
 
168
                         ParseError* error);
 
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,
 
173
                      ParseError* error);
 
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,
 
182
                          ParseError* error);
 
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,
 
189
                          XmlElements* elems,
 
190
                          WriteError* error);
 
191
bool ParseSessionAccept(SignalingProtocol protocol,
 
192
                        const buzz::XmlElement* action_elem,
 
193
                        const ContentParserMap& content_parsers,
 
194
                        const TransportParserMap& transport_parsers,
 
195
                        SessionAccept* accept,
 
196
                        ParseError* error);
 
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,
 
203
                        XmlElements* elems,
 
204
                        WriteError* error);
 
205
bool ParseSessionTerminate(SignalingProtocol protocol,
 
206
                           const buzz::XmlElement* action_elem,
 
207
                           SessionTerminate* term,
 
208
                           ParseError* error);
 
209
void WriteSessionTerminate(SignalingProtocol protocol,
 
210
                           const SessionTerminate& term,
 
211
                           XmlElements* elems);
 
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,
 
217
                          ParseError* error);
 
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,
 
226
                         ParseError* error);
 
227
bool WriteTransportInfos(SignalingProtocol protocol,
 
228
                         const TransportInfos& tinfos,
 
229
                         const TransportParserMap& trans_parsers,
 
230
                         XmlElements* elems,
 
231
                         WriteError* error);
 
232
// Handles both Gingle and Jingle syntax.
 
233
bool FindSessionRedirect(const buzz::XmlElement* stanza,
 
234
                         SessionRedirect* redirect);
 
235
}  // namespace cricket
 
236
 
 
237
#endif  // TALK_P2P_BASE_SESSIONMESSAGES_H_