|
@@ -18,12 +18,11 @@
|
|
|
|
|
|
#include "configuration.hpp"
|
|
#include "configuration.hpp"
|
|
|
|
|
|
|
|
+#include "impl/utils.hpp"
|
|
|
|
+
|
|
#include <cassert>
|
|
#include <cassert>
|
|
#include <regex>
|
|
#include <regex>
|
|
|
|
|
|
-#include <iostream>
|
|
|
|
-#include <sstream>
|
|
|
|
-
|
|
|
|
namespace {
|
|
namespace {
|
|
|
|
|
|
bool parse_url(const std::string &url, std::vector<std::optional<std::string>> &result) {
|
|
bool parse_url(const std::string &url, std::vector<std::optional<std::string>> &result) {
|
|
@@ -45,27 +44,12 @@ bool parse_url(const std::string &url, std::vector<std::optional<std::string>> &
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-std::string url_decode(const std::string &str) {
|
|
|
|
- static const std::regex r(R"(%[0-9A-Fa-f]{2})", std::regex::extended);
|
|
|
|
-
|
|
|
|
- std::stringstream ss;
|
|
|
|
- std::smatch m;
|
|
|
|
- for (size_t i = 0; i < str.length(); ++i) {
|
|
|
|
- std::string substr = str.substr(i, 3);
|
|
|
|
- if (std::regex_match(substr, m, r)) {
|
|
|
|
- ss << static_cast<char>(std::stoi("0x" + substr.substr(1, 2), nullptr, 16));
|
|
|
|
- i += 2;
|
|
|
|
- } else {
|
|
|
|
- ss << str[i];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return ss.str();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
} // namespace
|
|
} // namespace
|
|
|
|
|
|
namespace rtc {
|
|
namespace rtc {
|
|
|
|
|
|
|
|
+namespace utils = impl::utils;
|
|
|
|
+
|
|
IceServer::IceServer(const string &url) {
|
|
IceServer::IceServer(const string &url) {
|
|
std::vector<optional<string>> opt;
|
|
std::vector<optional<string>> opt;
|
|
if (!parse_url(url, opt))
|
|
if (!parse_url(url, opt))
|
|
@@ -92,8 +76,8 @@ IceServer::IceServer(const string &url) {
|
|
relayType = RelayType::TurnTls;
|
|
relayType = RelayType::TurnTls;
|
|
}
|
|
}
|
|
|
|
|
|
- username = url_decode(opt[6].value_or(""));
|
|
|
|
- password = url_decode(opt[8].value_or(""));
|
|
|
|
|
|
+ username = utils::url_decode(opt[6].value_or(""));
|
|
|
|
+ password = utils::url_decode(opt[8].value_or(""));
|
|
|
|
|
|
hostname = opt[10].value();
|
|
hostname = opt[10].value();
|
|
while (!hostname.empty() && hostname.front() == '[')
|
|
while (!hostname.empty() && hostname.front() == '[')
|