remote: split out function for parsing URI scheme

The remoteSplitURISCheme method will be needed by source files beyond
the remote driver client.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2020-03-04 17:45:55 +00:00
parent 9949d9b28f
commit 849de2b844
3 changed files with 34 additions and 25 deletions

View File

@ -165,31 +165,6 @@ static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapsho
/*----------------------------------------------------------------------*/
/* Helper functions for remoteOpen. */
static int remoteSplitURIScheme(virURIPtr uri,
char **driver,
char **transport)
{
char *p = strchr(uri->scheme, '+');
*driver = *transport = NULL;
if (p)
*driver = g_strndup(uri->scheme, p - uri->scheme);
else
*driver = g_strdup(uri->scheme);
if (p) {
*transport = g_strdup(p + 1);
p = *transport;
while (*p) {
*p = g_ascii_tolower(*p);
p++;
}
}
return 0;
}
static int

View File

@ -37,3 +37,31 @@ VIR_ENUM_IMPL(remoteDriverMode,
"auto",
"legacy",
"direct");
int
remoteSplitURIScheme(virURIPtr uri,
char **driver,
char **transport)
{
char *p = strchr(uri->scheme, '+');
*driver = *transport = NULL;
if (p)
*driver = g_strndup(uri->scheme, p - uri->scheme);
else
*driver = g_strdup(uri->scheme);
if (p) {
*transport = g_strdup(p + 1);
p = *transport;
while (*p) {
*p = g_ascii_tolower(*p);
p++;
}
}
return 0;
}

View File

@ -21,6 +21,7 @@
#pragma once
#include "virenum.h"
#include "viruri.h"
typedef enum {
REMOTE_DRIVER_TRANSPORT_TLS,
@ -48,3 +49,8 @@ typedef enum {
} remoteDriverMode;
VIR_ENUM_DECL(remoteDriverMode);
int
remoteSplitURIScheme(virURIPtr uri,
char **driver,
char **transport);