summaryrefslogtreecommitdiff
path: root/src/components/transport_manager/src
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/transport_manager/src')
-rw-r--r--src/components/transport_manager/src/cloud/cloud_device.cc28
-rw-r--r--src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc49
-rw-r--r--src/components/transport_manager/src/cloud/websocket_client_connection.cc4
3 files changed, 57 insertions, 24 deletions
diff --git a/src/components/transport_manager/src/cloud/cloud_device.cc b/src/components/transport_manager/src/cloud/cloud_device.cc
index 35510f4cf8..c1ad186ded 100644
--- a/src/components/transport_manager/src/cloud/cloud_device.cc
+++ b/src/components/transport_manager/src/cloud/cloud_device.cc
@@ -42,7 +42,15 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
CloudDevice::CloudDevice(std::string& host,
std::string& port,
std::string& name)
- : Device(name, std::string(name)), host_(host), port_(port) {}
+ : Device(name, std::string(name))
+ , endpoint_(CloudAppEndpoint{.host = host,
+ .port = port,
+ .path = "/",
+ .query = "",
+ .fragment = ""}) {}
+
+CloudDevice::CloudDevice(CloudAppEndpoint endpoint, std::string& name)
+ : Device(name, std::string(name)), endpoint_(endpoint) {}
bool CloudDevice::IsSameAs(const Device* other) const {
LOG4CXX_TRACE(logger_, "enter. device: " << other);
@@ -54,12 +62,18 @@ bool CloudDevice::IsSameAs(const Device* other) const {
return false;
}
- if (host_ != other_cloud_device->GetHost()) {
+ if (GetHost() != other_cloud_device->GetHost()) {
+ return false;
+ }
+
+ if (GetPort() != other_cloud_device->GetPort()) {
return false;
}
- if (port_ != other_cloud_device->GetPort()) {
+
+ if (GetTarget() != other_cloud_device->GetTarget()) {
return false;
}
+
return true;
}
@@ -68,11 +82,15 @@ ApplicationList CloudDevice::GetApplicationList() const {
}
const std::string& CloudDevice::GetHost() const {
- return host_;
+ return endpoint_.host;
}
const std::string& CloudDevice::GetPort() const {
- return port_;
+ return endpoint_.port;
+}
+
+const std::string CloudDevice::GetTarget() const {
+ return endpoint_.path + endpoint_.query + endpoint_.fragment;
}
} // namespace transport_adapter
diff --git a/src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc b/src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc
index e141a65ec0..622531b120 100644
--- a/src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc
+++ b/src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc
@@ -80,15 +80,20 @@ void CloudWebsocketTransportAdapter::CreateDevice(const std::string& uid) {
return;
}
- // Port after second colon in valid endpoint string
- std::size_t pos_port = uid.find(":");
- pos_port = uid.find(":", pos_port + 1);
+ std::string protocol_pattern = "(wss?)";
+ std::string host_pattern =
+ "(([^?#%\\\\/@:\\s]{1,})\\:?([^?#%\\\\/@\\s]*)\\@?([^?#%\\\\/\\s]*))";
+ std::string port_pattern = "(\\d{2,5})";
+ // Optional parameters
+ std::string path_pattern = "((\\/[^\\/#?\\s]+)*)?\\/?";
+ std::string query_pattern = "(\\?[^=&#\\s]*=?[^#\\s]*&?)?";
+ std::string fragment_pattern = "(#[^\\s]*)?";
// Extract host and port from endpoint string
- boost::regex group_pattern(
- "(wss?:\\/\\/)([A-Z\\d\\.-]{2,}\\.?([A-Z]{2,})?)(:)(\\d{2,5})(\\/"
- "[A-Z\\d\\.-]+)*\\/?",
- boost::regex::icase);
+ boost::regex group_pattern(protocol_pattern + ":\\/\\/" + host_pattern + ":" +
+ port_pattern + path_pattern + query_pattern +
+ fragment_pattern,
+ boost::regex::icase);
boost::smatch results;
std::string str = uid;
@@ -97,20 +102,30 @@ void CloudWebsocketTransportAdapter::CreateDevice(const std::string& uid) {
return;
}
- std::string host = results[2];
- std::string port = results[5];
+ LOG4CXX_DEBUG(logger_, "#Results: " << results.size());
+ std::string results_str;
+ for (size_t i = 0; i < results.size(); i++) {
+ results_str += " R[" + std::to_string(i) + "]:";
+ results_str +=
+ (results[i].length() != 0) ? results[i] : std::string("<EMPTY>");
+ }
+ LOG4CXX_DEBUG(logger_, "Results: " << results_str);
- LOG4CXX_DEBUG(logger_,
- "Results: " << results[0] << " " << results[1] << " "
- << results[2] << " " << results[3] << " "
- << results[4] << " " << results[5] << " ");
std::string device_id = uid;
- LOG4CXX_DEBUG(
- logger_,
- "Creating Cloud Device For Host: " << host << " and Port: " << port);
+ CloudAppEndpoint endpoint{.host = results[2],
+ .port = results[6],
+ .path = results[7] + "/",
+ .query = results[9],
+ .fragment = results[10]};
+
+ LOG4CXX_DEBUG(logger_,
+ "Creating Cloud Device For Host: "
+ << endpoint.host << " at Port: " << endpoint.port
+ << " with Target: "
+ << (endpoint.path + endpoint.query + endpoint.fragment));
- auto cloud_device = std::make_shared<CloudDevice>(host, port, device_id);
+ auto cloud_device = std::make_shared<CloudDevice>(endpoint, device_id);
DeviceVector devices{cloud_device};
diff --git a/src/components/transport_manager/src/cloud/websocket_client_connection.cc b/src/components/transport_manager/src/cloud/websocket_client_connection.cc
index a93a27ba40..ec2fb0bcfb 100644
--- a/src/components/transport_manager/src/cloud/websocket_client_connection.cc
+++ b/src/components/transport_manager/src/cloud/websocket_client_connection.cc
@@ -160,11 +160,11 @@ TransportAdapter::Error WebsocketClientConnection::Start() {
// Perform websocket handshake
if (cloud_properties.cloud_transport_type == "WS") {
- ws_.handshake(host, "/", ec);
+ ws_.handshake(host, cloud_device->GetTarget(), ec);
}
#ifdef ENABLE_SECURITY
else if (cloud_properties.cloud_transport_type == "WSS") {
- wss_.handshake(host, "/", ec);
+ wss_.handshake(host, cloud_device->GetTarget(), ec);
}
#endif // ENABLE_SECURITY
if (ec) {