/* * Copyright 2017 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #include "pc/ice_server_parsing.h" #include <stddef.h> #include <cctype> // For std::isdigit. #include <string> #include <tuple> #include "p2p/base/port_interface.h" #include "rtc_base/arraysize.h" #include "rtc_base/checks.h" #include "rtc_base/ip_address.h" #include "rtc_base/logging.h" #include "rtc_base/socket_address.h" #include "rtc_base/string_encode.h" #include "rtc_base/string_to_number.h" namespace webrtc { namespace { // Number of tokens must be preset when TURN uri has transport param. const size_t kTurnTransportTokensNum = …; // The default stun port. const int kDefaultStunPort = …; const int kDefaultStunTlsPort = …; const char kTransport[] = …; // Allowed characters in hostname per RFC 3986 Appendix A "reg-name" const char kRegNameCharacters[] = …; // sub-delims // NOTE: Must be in the same order as the ServiceType enum. const char* kValidIceServiceTypes[] = …; // NOTE: A loop below assumes that the first value of this enum is 0 and all // other values are incremental. enum class ServiceType { … }; static_assert …; // `in_str` should follow of RFC 7064/7065 syntax, but with an optional // "?transport=" already stripped. I.e., // stunURI = scheme ":" host [ ":" port ] // scheme = "stun" / "stuns" / "turn" / "turns" // host = IP-literal / IPv4address / reg-name // port = *DIGIT // Return tuple is service_type, host, with service_type == ServiceType::INVALID // on failure. std::tuple<ServiceType, absl::string_view> GetServiceTypeAndHostnameFromUri( absl::string_view in_str) { … } absl::optional<int> ParsePort(absl::string_view in_str) { … } // This method parses IPv6 and IPv4 literal strings, along with hostnames in // standard hostname:port format. // Consider following formats as correct. // `hostname:port`, |[IPV6 address]:port|, |IPv4 address|:port, // `hostname`, |[IPv6 address]|, |IPv4 address|. // Return tuple is success, host, port. std::tuple<bool, absl::string_view, int> ParseHostnameAndPortFromString( absl::string_view in_str, int default_port) { … } // Adds a STUN or TURN server to the appropriate list, // by parsing `url` and using the username/password in `server`. RTCError ParseIceServerUrl( const PeerConnectionInterface::IceServer& server, absl::string_view url, cricket::ServerAddresses* stun_servers, std::vector<cricket::RelayServerConfig>* turn_servers) { … } } // namespace RTCError ParseIceServersOrError( const PeerConnectionInterface::IceServers& servers, cricket::ServerAddresses* stun_servers, std::vector<cricket::RelayServerConfig>* turn_servers) { … } RTCErrorType ParseIceServers( const PeerConnectionInterface::IceServers& servers, cricket::ServerAddresses* stun_servers, std::vector<cricket::RelayServerConfig>* turn_servers) { … } } // namespace webrtc