1/*
2 * libjingle
3 * Copyright 2004--2005, 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_SESSIONDESCRIPTION_H_
29#define TALK_P2P_BASE_SESSIONDESCRIPTION_H_
30
31#include <string>
32#include <vector>
33
34namespace cricket {
35
36// Describes a session content. Individual content types inherit from
37// this class.  Analagous to a <jingle><content><description> or
38// <session><description>.
39class ContentDescription {
40 public:
41  virtual ~ContentDescription() {}
42};
43
44// Analagous to a <jingle><content> or <session><description>.
45// name = name of <content name="...">
46// type = xmlns of <content>
47struct ContentInfo {
48  ContentInfo() : description(NULL) {}
49  ContentInfo(const std::string& name,
50              const std::string& type,
51              const ContentDescription* description) :
52      name(name), type(type), description(description) {}
53  std::string name;
54  std::string type;
55  const ContentDescription* description;
56};
57
58typedef std::vector<ContentInfo> ContentInfos;
59const ContentInfo* FindContentInfoByName(
60    const ContentInfos& contents, const std::string& name);
61const ContentInfo* FindContentInfoByType(
62    const ContentInfos& contents, const std::string& type);
63
64// Describes a collection of contents, each with its own name and
65// type.  Analgous to a <jingle> or <session> stanza.  Assumes that
66// contents are unique be name, but doesn't enforce that.
67class SessionDescription {
68 public:
69  SessionDescription() {}
70  explicit SessionDescription(const ContentInfos& contents) :
71      contents_(contents) {}
72  const ContentInfo* GetContentByName(const std::string& name) const;
73  const ContentInfo* FirstContentByType(const std::string& type) const;
74  // Takes ownership of ContentDescription*.
75  void AddContent(const std::string& name,
76                  const std::string& type,
77                  const ContentDescription* description);
78  // TODO: Implement RemoveContent when it's needed for
79  // content-remove Jingle messages.
80  // void RemoveContent(const std::string& name);
81  const ContentInfos& contents() const { return contents_; }
82
83  ~SessionDescription() {
84    for (ContentInfos::iterator content = contents_.begin();
85         content != contents_.end(); content++) {
86      delete content->description;
87    }
88  }
89
90 private:
91  ContentInfos contents_;
92};
93
94// Indicates whether a ContentDescription was an offer or an answer, as
95// described in http://www.ietf.org/rfc/rfc3264.txt. CA_UPDATE
96// indicates a jingle update message which contains a subset of a full
97// session description
98enum ContentAction {
99  CA_OFFER, CA_ANSWER, CA_UPDATE
100};
101
102// Indicates whether a ContentDescription was sent by the local client
103// or received from the remote client.
104enum ContentSource {
105  CS_LOCAL, CS_REMOTE
106};
107
108}  // namespace cricket
109
110#endif  // TALK_P2P_BASE_SESSIONDESCRIPTION_H_
111