Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / p2p / base / transportdescription.h
1 /*
2  *  Copyright 2012 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
11 #ifndef WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_
12 #define WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_
13
14 #include <algorithm>
15 #include <string>
16 #include <vector>
17
18 #include "webrtc/p2p/base/candidate.h"
19 #include "webrtc/p2p/base/constants.h"
20 #include "webrtc/base/scoped_ptr.h"
21 #include "webrtc/base/sslfingerprint.h"
22
23 namespace cricket {
24
25 // SEC_ENABLED and SEC_REQUIRED should only be used if the session
26 // was negotiated over TLS, to protect the inline crypto material
27 // exchange.
28 // SEC_DISABLED: No crypto in outgoing offer, ignore any supplied crypto.
29 // SEC_ENABLED:  Crypto in outgoing offer and answer (if supplied in offer).
30 // SEC_REQUIRED: Crypto in outgoing offer and answer. Fail any offer with absent
31 //               or unsupported crypto.
32 enum SecurePolicy {
33   SEC_DISABLED,
34   SEC_ENABLED,
35   SEC_REQUIRED
36 };
37
38 // The transport protocol we've elected to use.
39 enum TransportProtocol {
40   ICEPROTO_GOOGLE,  // Google version of ICE protocol.
41   ICEPROTO_HYBRID,  // ICE, but can fall back to the Google version.
42   ICEPROTO_RFC5245  // Standard RFC 5245 version of ICE.
43 };
44 // The old name for TransportProtocol.
45 // TODO(juberti): remove this.
46 typedef TransportProtocol IceProtocolType;
47
48 // Whether our side of the call is driving the negotiation, or the other side.
49 enum IceRole {
50   ICEROLE_CONTROLLING = 0,
51   ICEROLE_CONTROLLED,
52   ICEROLE_UNKNOWN
53 };
54
55 // ICE RFC 5245 implementation type.
56 enum IceMode {
57   ICEMODE_FULL,  // As defined in http://tools.ietf.org/html/rfc5245#section-4.1
58   ICEMODE_LITE   // As defined in http://tools.ietf.org/html/rfc5245#section-4.2
59 };
60
61 // RFC 4145 - http://tools.ietf.org/html/rfc4145#section-4
62 // 'active':  The endpoint will initiate an outgoing connection.
63 // 'passive': The endpoint will accept an incoming connection.
64 // 'actpass': The endpoint is willing to accept an incoming
65 //            connection or to initiate an outgoing connection.
66 enum ConnectionRole {
67   CONNECTIONROLE_NONE = 0,
68   CONNECTIONROLE_ACTIVE,
69   CONNECTIONROLE_PASSIVE,
70   CONNECTIONROLE_ACTPASS,
71   CONNECTIONROLE_HOLDCONN,
72 };
73
74 extern const char CONNECTIONROLE_ACTIVE_STR[];
75 extern const char CONNECTIONROLE_PASSIVE_STR[];
76 extern const char CONNECTIONROLE_ACTPASS_STR[];
77 extern const char CONNECTIONROLE_HOLDCONN_STR[];
78
79 bool StringToConnectionRole(const std::string& role_str, ConnectionRole* role);
80 bool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str);
81
82 typedef std::vector<Candidate> Candidates;
83
84 struct TransportDescription {
85   TransportDescription()
86       : ice_mode(ICEMODE_FULL),
87         connection_role(CONNECTIONROLE_NONE) {}
88
89   TransportDescription(const std::string& transport_type,
90                        const std::vector<std::string>& transport_options,
91                        const std::string& ice_ufrag,
92                        const std::string& ice_pwd,
93                        IceMode ice_mode,
94                        ConnectionRole role,
95                        const rtc::SSLFingerprint* identity_fingerprint,
96                        const Candidates& candidates)
97       : transport_type(transport_type),
98         transport_options(transport_options),
99         ice_ufrag(ice_ufrag),
100         ice_pwd(ice_pwd),
101         ice_mode(ice_mode),
102         connection_role(role),
103         identity_fingerprint(CopyFingerprint(identity_fingerprint)),
104         candidates(candidates) {}
105   TransportDescription(const std::string& transport_type,
106                        const std::string& ice_ufrag,
107                        const std::string& ice_pwd)
108       : transport_type(transport_type),
109         ice_ufrag(ice_ufrag),
110         ice_pwd(ice_pwd),
111         ice_mode(ICEMODE_FULL),
112         connection_role(CONNECTIONROLE_NONE) {}
113   TransportDescription(const TransportDescription& from)
114       : transport_type(from.transport_type),
115         transport_options(from.transport_options),
116         ice_ufrag(from.ice_ufrag),
117         ice_pwd(from.ice_pwd),
118         ice_mode(from.ice_mode),
119         connection_role(from.connection_role),
120         identity_fingerprint(CopyFingerprint(from.identity_fingerprint.get())),
121         candidates(from.candidates) {}
122
123   TransportDescription& operator=(const TransportDescription& from) {
124     // Self-assignment
125     if (this == &from)
126       return *this;
127
128     transport_type = from.transport_type;
129     transport_options = from.transport_options;
130     ice_ufrag = from.ice_ufrag;
131     ice_pwd = from.ice_pwd;
132     ice_mode = from.ice_mode;
133     connection_role = from.connection_role;
134
135     identity_fingerprint.reset(CopyFingerprint(
136         from.identity_fingerprint.get()));
137     candidates = from.candidates;
138     return *this;
139   }
140
141   bool HasOption(const std::string& option) const {
142     return (std::find(transport_options.begin(), transport_options.end(),
143                       option) != transport_options.end());
144   }
145   void AddOption(const std::string& option) {
146     transport_options.push_back(option);
147   }
148   bool secure() const { return identity_fingerprint != NULL; }
149
150   static rtc::SSLFingerprint* CopyFingerprint(
151       const rtc::SSLFingerprint* from) {
152     if (!from)
153       return NULL;
154
155     return new rtc::SSLFingerprint(*from);
156   }
157
158   std::string transport_type;  // xmlns of <transport>
159   std::vector<std::string> transport_options;
160   std::string ice_ufrag;
161   std::string ice_pwd;
162   IceMode ice_mode;
163   ConnectionRole connection_role;
164
165   rtc::scoped_ptr<rtc::SSLFingerprint> identity_fingerprint;
166   Candidates candidates;
167 };
168
169 }  // namespace cricket
170
171 #endif  // WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_