henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "p2p/base/sessiondescription.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 12 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 13 | namespace cricket { |
| 14 | |
| 15 | ContentInfo* FindContentInfoByName( |
| 16 | ContentInfos& contents, const std::string& name) { |
| 17 | for (ContentInfos::iterator content = contents.begin(); |
| 18 | content != contents.end(); ++content) { |
| 19 | if (content->name == name) { |
| 20 | return &(*content); |
| 21 | } |
| 22 | } |
| 23 | return NULL; |
| 24 | } |
| 25 | |
| 26 | const ContentInfo* FindContentInfoByName( |
| 27 | const ContentInfos& contents, const std::string& name) { |
| 28 | for (ContentInfos::const_iterator content = contents.begin(); |
| 29 | content != contents.end(); ++content) { |
| 30 | if (content->name == name) { |
| 31 | return &(*content); |
| 32 | } |
| 33 | } |
| 34 | return NULL; |
| 35 | } |
| 36 | |
| 37 | const ContentInfo* FindContentInfoByType( |
| 38 | const ContentInfos& contents, const std::string& type) { |
| 39 | for (ContentInfos::const_iterator content = contents.begin(); |
| 40 | content != contents.end(); ++content) { |
| 41 | if (content->type == type) { |
| 42 | return &(*content); |
| 43 | } |
| 44 | } |
| 45 | return NULL; |
| 46 | } |
| 47 | |
| 48 | const std::string* ContentGroup::FirstContentName() const { |
| 49 | return (!content_names_.empty()) ? &(*content_names_.begin()) : NULL; |
| 50 | } |
| 51 | |
| 52 | bool ContentGroup::HasContentName(const std::string& content_name) const { |
| 53 | return (std::find(content_names_.begin(), content_names_.end(), |
| 54 | content_name) != content_names_.end()); |
| 55 | } |
| 56 | |
| 57 | void ContentGroup::AddContentName(const std::string& content_name) { |
| 58 | if (!HasContentName(content_name)) { |
| 59 | content_names_.push_back(content_name); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | bool ContentGroup::RemoveContentName(const std::string& content_name) { |
| 64 | ContentNames::iterator iter = std::find( |
| 65 | content_names_.begin(), content_names_.end(), content_name); |
| 66 | if (iter == content_names_.end()) { |
| 67 | return false; |
| 68 | } |
| 69 | content_names_.erase(iter); |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | SessionDescription* SessionDescription::Copy() const { |
| 74 | SessionDescription* copy = new SessionDescription(*this); |
| 75 | // Copy all ContentDescriptions. |
| 76 | for (ContentInfos::iterator content = copy->contents_.begin(); |
| 77 | content != copy->contents().end(); ++content) { |
| 78 | content->description = content->description->Copy(); |
| 79 | } |
| 80 | return copy; |
| 81 | } |
| 82 | |
| 83 | const ContentInfo* SessionDescription::GetContentByName( |
| 84 | const std::string& name) const { |
| 85 | return FindContentInfoByName(contents_, name); |
| 86 | } |
| 87 | |
| 88 | ContentInfo* SessionDescription::GetContentByName( |
| 89 | const std::string& name) { |
| 90 | return FindContentInfoByName(contents_, name); |
| 91 | } |
| 92 | |
| 93 | const ContentDescription* SessionDescription::GetContentDescriptionByName( |
| 94 | const std::string& name) const { |
| 95 | const ContentInfo* cinfo = FindContentInfoByName(contents_, name); |
| 96 | if (cinfo == NULL) { |
| 97 | return NULL; |
| 98 | } |
| 99 | |
| 100 | return cinfo->description; |
| 101 | } |
| 102 | |
| 103 | ContentDescription* SessionDescription::GetContentDescriptionByName( |
| 104 | const std::string& name) { |
| 105 | ContentInfo* cinfo = FindContentInfoByName(contents_, name); |
| 106 | if (cinfo == NULL) { |
| 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | return cinfo->description; |
| 111 | } |
| 112 | |
| 113 | const ContentInfo* SessionDescription::FirstContentByType( |
| 114 | const std::string& type) const { |
| 115 | return FindContentInfoByType(contents_, type); |
| 116 | } |
| 117 | |
| 118 | const ContentInfo* SessionDescription::FirstContent() const { |
| 119 | return (contents_.empty()) ? NULL : &(*contents_.begin()); |
| 120 | } |
| 121 | |
| 122 | void SessionDescription::AddContent(const std::string& name, |
| 123 | const std::string& type, |
| 124 | ContentDescription* description) { |
| 125 | contents_.push_back(ContentInfo(name, type, description)); |
| 126 | } |
| 127 | |
| 128 | void SessionDescription::AddContent(const std::string& name, |
| 129 | const std::string& type, |
| 130 | bool rejected, |
| 131 | ContentDescription* description) { |
| 132 | contents_.push_back(ContentInfo(name, type, rejected, description)); |
| 133 | } |
| 134 | |
deadbeef | 25ed435 | 2016-12-12 18:37:36 -0800 | [diff] [blame] | 135 | void SessionDescription::AddContent(const std::string& name, |
| 136 | const std::string& type, |
| 137 | bool rejected, |
| 138 | bool bundle_only, |
| 139 | ContentDescription* description) { |
| 140 | contents_.push_back( |
| 141 | ContentInfo(name, type, rejected, bundle_only, description)); |
| 142 | } |
| 143 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 144 | bool SessionDescription::RemoveContentByName(const std::string& name) { |
| 145 | for (ContentInfos::iterator content = contents_.begin(); |
| 146 | content != contents_.end(); ++content) { |
| 147 | if (content->name == name) { |
| 148 | delete content->description; |
| 149 | contents_.erase(content); |
| 150 | return true; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | bool SessionDescription::AddTransportInfo(const TransportInfo& transport_info) { |
| 158 | if (GetTransportInfoByName(transport_info.content_name) != NULL) { |
| 159 | return false; |
| 160 | } |
| 161 | transport_infos_.push_back(transport_info); |
| 162 | return true; |
| 163 | } |
| 164 | |
| 165 | bool SessionDescription::RemoveTransportInfoByName(const std::string& name) { |
| 166 | for (TransportInfos::iterator transport_info = transport_infos_.begin(); |
| 167 | transport_info != transport_infos_.end(); ++transport_info) { |
| 168 | if (transport_info->content_name == name) { |
| 169 | transport_infos_.erase(transport_info); |
| 170 | return true; |
| 171 | } |
| 172 | } |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | const TransportInfo* SessionDescription::GetTransportInfoByName( |
| 177 | const std::string& name) const { |
| 178 | for (TransportInfos::const_iterator iter = transport_infos_.begin(); |
| 179 | iter != transport_infos_.end(); ++iter) { |
| 180 | if (iter->content_name == name) { |
| 181 | return &(*iter); |
| 182 | } |
| 183 | } |
| 184 | return NULL; |
| 185 | } |
| 186 | |
| 187 | TransportInfo* SessionDescription::GetTransportInfoByName( |
| 188 | const std::string& name) { |
| 189 | for (TransportInfos::iterator iter = transport_infos_.begin(); |
| 190 | iter != transport_infos_.end(); ++iter) { |
| 191 | if (iter->content_name == name) { |
| 192 | return &(*iter); |
| 193 | } |
| 194 | } |
| 195 | return NULL; |
| 196 | } |
| 197 | |
| 198 | void SessionDescription::RemoveGroupByName(const std::string& name) { |
| 199 | for (ContentGroups::iterator iter = content_groups_.begin(); |
| 200 | iter != content_groups_.end(); ++iter) { |
| 201 | if (iter->semantics() == name) { |
| 202 | content_groups_.erase(iter); |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | bool SessionDescription::HasGroup(const std::string& name) const { |
| 209 | for (ContentGroups::const_iterator iter = content_groups_.begin(); |
| 210 | iter != content_groups_.end(); ++iter) { |
| 211 | if (iter->semantics() == name) { |
| 212 | return true; |
| 213 | } |
| 214 | } |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | const ContentGroup* SessionDescription::GetGroupByName( |
| 219 | const std::string& name) const { |
| 220 | for (ContentGroups::const_iterator iter = content_groups_.begin(); |
| 221 | iter != content_groups_.end(); ++iter) { |
| 222 | if (iter->semantics() == name) { |
| 223 | return &(*iter); |
| 224 | } |
| 225 | } |
| 226 | return NULL; |
| 227 | } |
| 228 | |
| 229 | } // namespace cricket |