]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
remote_driver: Move URI re-generation into a function
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 3 Feb 2023 13:57:47 +0000 (14:57 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 8 Feb 2023 15:50:45 +0000 (16:50 +0100)
There's a piece of code in doRemoteOpen() that is going to be
called twice. Instead of duplicating the code, move it into a
function that will be called twice, later on.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/remote/remote_driver.c

index 6a226999df326e9a9352b58b59afe9e415ac0dbc..cce9e7ddaf5be22bac3ee12e78bcfbe679d106f4 100644 (file)
@@ -693,6 +693,24 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr conn,
     return rc != -1 && ret.supported;
 }
 
+
+static char *
+remoteConnectFormatURI(virURI *uri,
+                       const char *driver_str)
+{
+    g_autofree char *query = NULL;
+    virURI tmpuri = {
+        .scheme = (char *)driver_str,
+        .path = uri->path,
+        .fragment = uri->fragment,
+    };
+
+    query = tmpuri.query = virURIFormatParams(uri);
+
+    return virURIFormat(&tmpuri);
+}
+
+
 /* helper macro to ease extraction of arguments from the URI */
 #define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \
     if (STRCASEEQ(var->name, ARG_NAME)) { \
@@ -833,16 +851,8 @@ doRemoteOpen(virConnectPtr conn,
                 /* Allow remote serve to probe */
                 name = g_strdup("");
             } else {
-                virURI tmpuri = {
-                    .scheme = (char *)driver_str,
-                    .query = virURIFormatParams(conn->uri),
-                    .path = conn->uri->path,
-                    .fragment = conn->uri->fragment,
-                };
-
-                name = virURIFormat(&tmpuri);
+                name = remoteConnectFormatURI(conn->uri, driver_str);
 
-                VIR_FREE(tmpuri.query);
             }
         }
     } else {