src.ctf.lttng-live: make live_viewer_connection::url an std::string
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 2 Feb 2024 17:46:38 +0000 (17:46 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Change-Id: I863b77f2b109312809df088adf374461550aac88
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8469
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12384
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/lttng-live/viewer-connection.cpp
src/plugins/ctf/lttng-live/viewer-connection.hpp

index 4a71508e720baf7429ef70490de6a02b406419a9..5bb7007f33cc56d5a9f385f9eb140247d56e2e1f 100644 (file)
@@ -229,13 +229,13 @@ static int parse_url(struct live_viewer_connection *viewer_connection)
     char error_buf[256] = {0};
     struct bt_common_lttng_live_url_parts lttng_live_url_parts = {};
     int ret = -1;
-    const char *path = viewer_connection->url->str;
 
-    if (!path) {
+    if (viewer_connection->url.empty()) {
         goto end;
     }
 
-    lttng_live_url_parts = bt_common_parse_lttng_live_url(path, error_buf, sizeof(error_buf));
+    lttng_live_url_parts = bt_common_parse_lttng_live_url(viewer_connection->url.c_str(), error_buf,
+                                                          sizeof(error_buf));
     if (!lttng_live_url_parts.proto) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Invalid LTTng live URL format: {}",
                                      error_buf);
@@ -502,7 +502,7 @@ end:
     return ret;
 }
 
-static int list_append_session(bt_value *results, GString *base_url,
+static int list_append_session(bt_value *results, const std::string& base_url,
                                const struct lttng_viewer_session *session,
                                struct live_viewer_connection *viewer_connection)
 {
@@ -528,20 +528,20 @@ static int list_append_session(bt_value *results, GString *base_url,
         goto end;
     }
 
-    if (base_url->len < 1) {
+    if (base_url.empty()) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger,
                                      "Error: base_url length smaller than 1.");
         ret = -1;
         goto end;
     }
+
     /*
      * key = "url",
      * value = <string>,
      */
     insert_status = bt_value_map_insert_string_entry(
         map, "url",
-        fmt::format("{}/host/{}/{}", base_url->str, session->hostname, session->session_name)
-            .c_str());
+        fmt::format("{}/host/{}/{}", base_url, session->hostname, session->session_name).c_str());
     if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error inserting \"url\" entry.");
         ret = -1;
@@ -1600,12 +1600,7 @@ enum lttng_live_viewer_status live_viewer_connection_create(
     viewer_connection->port = -1;
     viewer_connection->in_query = in_query;
     viewer_connection->lttng_live_msg_iter = lttng_live_msg_iter;
-    viewer_connection->url = g_string_new(url);
-    if (!viewer_connection->url) {
-        BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Failed to allocate URL buffer");
-        status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
-        goto error;
-    }
+    viewer_connection->url = url;
 
     BT_CPPLOGD_SPEC(viewer_connection->logger, "Establishing connection to url \"{}\"...", url);
     status = lttng_live_connect_viewer(viewer_connection);
@@ -1643,14 +1638,10 @@ void live_viewer_connection_destroy(struct live_viewer_connection *viewer_connec
     }
 
     BT_CPPLOGD_SPEC(viewer_connection->logger, "Closing connection to relay: relay-url=\"{}\"",
-                    viewer_connection->url->str);
+                    viewer_connection->url);
 
     lttng_live_disconnect_viewer(viewer_connection);
 
-    if (viewer_connection->url) {
-        g_string_free(viewer_connection->url, true);
-    }
-
     if (viewer_connection->relay_hostname) {
         g_string_free(viewer_connection->relay_hostname, true);
     }
index 4dfae18ca81d70847377eb9842024b131bf4ddea..707ce80b6741a0db254f2028758b5c20074a7f2c 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef LTTNG_LIVE_VIEWER_CONNECTION_H
 #define LTTNG_LIVE_VIEWER_CONNECTION_H
 
+#include <string>
+
 #include <glib.h>
 #include <stdint.h>
 
@@ -54,7 +56,7 @@ struct live_viewer_connection
 
     bt2c::Logger logger;
 
-    GString *url = nullptr;
+    std::string url;
 
     GString *relay_hostname = nullptr;
     GString *target_hostname = nullptr;
This page took 0.025902 seconds and 4 git commands to generate.