Almost in all places where an URI is parsed we look for additional argument(s). The remote driver's parsing uses two macros EXTRACT_URI_ARG_STR() and EXTRACT_URI_ARG_BOOL() for that purpose. Expose these so that other places can be rewritten using those macros. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- po/POTFILES | 1 + src/remote/remote_driver.c | 58 +++++++++++--------------------------- src/util/viruri.h | 23 +++++++++++++++ 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/po/POTFILES b/po/POTFILES index 4e446aaf40..2d35def639 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -332,6 +332,7 @@ src/util/virtpm.c src/util/virtypedparam-public.c src/util/virtypedparam.c src/util/viruri.c +src/util/viruri.h src/util/virusb.c src/util/virutil.c src/util/virvhba.c diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 6a226999df..c41d5b414f 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -693,30 +693,6 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr conn, return rc != -1 && ret.supported; } -/* 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)) { \ - VIR_FREE(ARG_VAR); \ - ARG_VAR = g_strdup(var->value); \ - var->ignore = 1; \ - continue; \ - } - -#define EXTRACT_URI_ARG_BOOL(ARG_NAME, ARG_VAR) \ - if (STRCASEEQ(var->name, ARG_NAME)) { \ - int tmp; \ - if (virStrToLong_i(var->value, NULL, 10, &tmp) < 0) { \ - virReportError(VIR_ERR_INVALID_ARG, \ - _("Failed to parse value of URI component %s"), \ - var->name); \ - goto error; \ - } \ - ARG_VAR = tmp == 0; \ - var->ignore = 1; \ - continue; \ - } - - /* * URIs that this driver needs to handle: * @@ -796,23 +772,23 @@ doRemoteOpen(virConnectPtr conn, if (conn->uri) { for (i = 0; i < conn->uri->paramsCount; i++) { virURIParam *var = &conn->uri->params[i]; - EXTRACT_URI_ARG_STR("name", name); - EXTRACT_URI_ARG_STR("command", command); - EXTRACT_URI_ARG_STR("socket", sockname); - EXTRACT_URI_ARG_STR("auth", authtype); - EXTRACT_URI_ARG_STR("sshauth", sshauth); - EXTRACT_URI_ARG_STR("netcat", netcat); - EXTRACT_URI_ARG_STR("keyfile", keyfile); - EXTRACT_URI_ARG_STR("pkipath", pkipath); - EXTRACT_URI_ARG_STR("known_hosts", knownHosts); - EXTRACT_URI_ARG_STR("known_hosts_verify", knownHostsVerify); - EXTRACT_URI_ARG_STR("tls_priority", tls_priority); - EXTRACT_URI_ARG_STR("mode", mode_str); - EXTRACT_URI_ARG_STR("proxy", proxy_str); - EXTRACT_URI_ARG_BOOL("no_sanity", sanity); - EXTRACT_URI_ARG_BOOL("no_verify", verify); + VIR_EXTRACT_URI_ARG_STR("name", name); + VIR_EXTRACT_URI_ARG_STR("command", command); + VIR_EXTRACT_URI_ARG_STR("socket", sockname); + VIR_EXTRACT_URI_ARG_STR("auth", authtype); + VIR_EXTRACT_URI_ARG_STR("sshauth", sshauth); + VIR_EXTRACT_URI_ARG_STR("netcat", netcat); + VIR_EXTRACT_URI_ARG_STR("keyfile", keyfile); + VIR_EXTRACT_URI_ARG_STR("pkipath", pkipath); + VIR_EXTRACT_URI_ARG_STR("known_hosts", knownHosts); + VIR_EXTRACT_URI_ARG_STR("known_hosts_verify", knownHostsVerify); + VIR_EXTRACT_URI_ARG_STR("tls_priority", tls_priority); + VIR_EXTRACT_URI_ARG_STR("mode", mode_str); + VIR_EXTRACT_URI_ARG_STR("proxy", proxy_str); + VIR_EXTRACT_URI_ARG_BOOL("no_sanity", sanity, error); + VIR_EXTRACT_URI_ARG_BOOL("no_verify", verify, error); #ifndef WIN32 - EXTRACT_URI_ARG_BOOL("no_tty", tty); + VIR_EXTRACT_URI_ARG_BOOL("no_tty", tty, error); #endif if (STRCASEEQ(var->name, "authfile")) { @@ -1206,8 +1182,6 @@ doRemoteOpen(virConnectPtr conn, VIR_FREE(priv->hostname); return VIR_DRV_OPEN_ERROR; } -#undef EXTRACT_URI_ARG_STR -#undef EXTRACT_URI_ARG_BOOL static struct private_data * remoteAllocPrivateData(void) diff --git a/src/util/viruri.h b/src/util/viruri.h index 4f27fa26d2..0e4176c037 100644 --- a/src/util/viruri.h +++ b/src/util/viruri.h @@ -62,3 +62,26 @@ const char *virURIGetParam(virURI *uri, const char *name); bool virURICheckUnixSocket(virURI *uri); #define VIR_URI_SERVER(uri) ((uri) && (uri)->server ? (uri)->server : "localhost") + +/* helper macros to ease extraction of arguments from the URI */ +#define VIR_EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \ + if (STRCASEEQ(var->name, ARG_NAME)) { \ + g_free(ARG_VAR); \ + ARG_VAR = g_strdup(var->value); \ + var->ignore = 1; \ + continue; \ + } + +#define VIR_EXTRACT_URI_ARG_BOOL(ARG_NAME, ARG_VAR, LABEL) \ + if (STRCASEEQ(var->name, ARG_NAME)) { \ + int tmp; \ + if (virStrToLong_i(var->value, NULL, 10, &tmp) < 0) { \ + virReportError(VIR_ERR_INVALID_ARG, \ + _("Failed to parse value of URI component %s"), \ + var->name); \ + goto LABEL; \ + } \ + ARG_VAR = tmp == 0; \ + var->ignore = 1; \ + continue; \ + } -- 2.39.1