From: Michal Privoznik Date: Fri, 3 Feb 2023 13:57:47 +0000 (+0100) Subject: remote_driver: Move URI re-generation into a function X-Git-Tag: v9.1.0-rc1~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c71c159248d2a2d2e766861c41a26c6a1537a5d7;p=thirdparty%2Flibvirt.git remote_driver: Move URI re-generation into a function 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 Reviewed-by: Peter Krempa --- diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 6a226999df..cce9e7ddaf 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -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 {