2012-02-24 18:48:55 +00:00
|
|
|
/*
|
|
|
|
* viruri.c: URI parsing wrappers for libxml2 functions
|
|
|
|
*
|
2014-09-03 19:39:21 +00:00
|
|
|
* Copyright (C) 2012-2014 Red Hat, Inc.
|
2012-02-24 18:48:55 +00:00
|
|
|
*
|
2012-07-27 09:39:53 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-27 09:39:53 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2012-02-24 18:48:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "viruri.h"
|
|
|
|
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2015-11-06 09:44:53 +00:00
|
|
|
#include "virlog.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2015-11-06 09:44:53 +00:00
|
|
|
#include "virutil.h"
|
Centralize error reporting for URI parsing/formatting problems
Move error reporting out of the callers, into virURIParse
and virURIFormat, to get consistency.
* include/libvirt/virterror.h, src/util/virterror.c: Add VIR_FROM_URI
* src/util/viruri.c, src/util/viruri.h: Add error reporting
* src/esx/esx_driver.c, src/libvirt.c, src/libxl/libxl_driver.c,
src/lxc/lxc_driver.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
src/remote/remote_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/vmx/vmx.c, src/xen/xen_driver.c,
src/xen/xend_internal.c, tests/viruritest.c: Remove error
reporting
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-03-20 12:16:54 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_URI
|
|
|
|
|
2015-11-06 09:44:53 +00:00
|
|
|
VIR_LOG_INIT("util.uri");
|
|
|
|
|
2012-03-20 13:59:32 +00:00
|
|
|
static int
|
|
|
|
virURIParamAppend(virURIPtr uri,
|
|
|
|
const char *name,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
char *pname = NULL;
|
|
|
|
char *pvalue = NULL;
|
|
|
|
|
2013-05-24 07:19:51 +00:00
|
|
|
if (VIR_STRDUP(pname, name) < 0 || VIR_STRDUP(pvalue, value) < 0)
|
|
|
|
goto error;
|
2012-03-20 13:59:32 +00:00
|
|
|
|
2013-07-04 10:17:18 +00:00
|
|
|
if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0)
|
2013-05-24 07:19:51 +00:00
|
|
|
goto error;
|
2012-03-20 13:59:32 +00:00
|
|
|
|
|
|
|
uri->params[uri->paramsCount].name = pname;
|
|
|
|
uri->params[uri->paramsCount].value = pvalue;
|
|
|
|
uri->params[uri->paramsCount].ignore = 0;
|
|
|
|
uri->paramsCount++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:53:22 +00:00
|
|
|
error:
|
2012-03-20 13:59:32 +00:00
|
|
|
VIR_FREE(pname);
|
|
|
|
VIR_FREE(pvalue);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virURIParseParams(virURIPtr uri)
|
|
|
|
{
|
|
|
|
const char *end, *eq;
|
|
|
|
const char *query = uri->query;
|
|
|
|
|
|
|
|
if (!query || query[0] == '\0')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (*query) {
|
|
|
|
char *name = NULL, *value = NULL;
|
|
|
|
|
|
|
|
/* Find the next separator, or end of the string. */
|
2012-10-17 09:23:12 +00:00
|
|
|
end = strchr(query, '&');
|
2012-03-20 13:59:32 +00:00
|
|
|
if (!end)
|
2012-10-17 09:23:12 +00:00
|
|
|
end = strchr(query, ';');
|
2012-03-20 13:59:32 +00:00
|
|
|
if (!end)
|
2012-10-17 09:23:12 +00:00
|
|
|
end = query + strlen(query);
|
2012-03-20 13:59:32 +00:00
|
|
|
|
|
|
|
/* Find the first '=' character between here and end. */
|
2012-10-17 09:23:12 +00:00
|
|
|
eq = strchr(query, '=');
|
2012-03-20 13:59:32 +00:00
|
|
|
if (eq && eq >= end) eq = NULL;
|
|
|
|
|
2014-09-03 19:39:21 +00:00
|
|
|
if (end == query) {
|
|
|
|
/* Empty section (eg. "&&"). */
|
2012-03-20 13:59:32 +00:00
|
|
|
goto next;
|
2014-09-03 19:39:21 +00:00
|
|
|
} else if (!eq) {
|
|
|
|
/* If there is no '=' character, then we have just "name"
|
|
|
|
* and consistent with CGI.pm we assume value is "".
|
|
|
|
*/
|
2012-10-17 09:23:12 +00:00
|
|
|
name = xmlURIUnescapeString(query, end - query, NULL);
|
2012-03-20 13:59:32 +00:00
|
|
|
if (!name) goto no_memory;
|
2014-09-03 19:39:21 +00:00
|
|
|
} else if (eq+1 == end) {
|
|
|
|
/* Or if we have "name=" here (works around annoying
|
|
|
|
* problem when calling xmlURIUnescapeString with len = 0).
|
|
|
|
*/
|
2012-10-17 09:23:12 +00:00
|
|
|
name = xmlURIUnescapeString(query, eq - query, NULL);
|
2012-03-20 13:59:32 +00:00
|
|
|
if (!name) goto no_memory;
|
2014-09-03 19:39:21 +00:00
|
|
|
} else if (query == eq) {
|
|
|
|
/* If the '=' character is at the beginning then we have
|
|
|
|
* "=value" and consistent with CGI.pm we _ignore_ this.
|
|
|
|
*/
|
2012-03-20 13:59:32 +00:00
|
|
|
goto next;
|
2014-09-03 19:39:21 +00:00
|
|
|
} else {
|
|
|
|
/* Otherwise it's "name=value". */
|
2012-10-17 09:23:12 +00:00
|
|
|
name = xmlURIUnescapeString(query, eq - query, NULL);
|
2012-03-20 13:59:32 +00:00
|
|
|
if (!name)
|
|
|
|
goto no_memory;
|
2012-10-17 09:23:12 +00:00
|
|
|
value = xmlURIUnescapeString(eq+1, end - (eq+1), NULL);
|
2012-03-20 13:59:32 +00:00
|
|
|
if (!value) {
|
|
|
|
VIR_FREE(name);
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append to the parameter set. */
|
|
|
|
if (virURIParamAppend(uri, name, value ? value : "") < 0) {
|
|
|
|
VIR_FREE(name);
|
|
|
|
VIR_FREE(value);
|
2014-06-27 06:44:15 +00:00
|
|
|
return -1;
|
2012-03-20 13:59:32 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(name);
|
|
|
|
VIR_FREE(value);
|
|
|
|
|
|
|
|
next:
|
|
|
|
query = end;
|
|
|
|
if (*query) query ++; /* skip '&' separator */
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-02-24 18:48:55 +00:00
|
|
|
/**
|
|
|
|
* virURIParse:
|
|
|
|
* @uri: URI to parse
|
|
|
|
*
|
|
|
|
* Wrapper for xmlParseURI
|
|
|
|
*
|
|
|
|
* Unfortunately there are few things that should be managed after
|
|
|
|
* parsing the URI. Fortunately there is only one thing now and its
|
|
|
|
* removing of square brackets around IPv6 addresses.
|
|
|
|
*
|
|
|
|
* @returns the parsed uri object with some fixes
|
|
|
|
*/
|
|
|
|
virURIPtr
|
|
|
|
virURIParse(const char *uri)
|
|
|
|
{
|
2012-03-20 13:33:41 +00:00
|
|
|
xmlURIPtr xmluri;
|
|
|
|
virURIPtr ret = NULL;
|
2012-02-24 18:48:55 +00:00
|
|
|
|
2012-03-20 13:33:41 +00:00
|
|
|
xmluri = xmlParseURI(uri);
|
|
|
|
|
|
|
|
if (!xmluri) {
|
Centralize error reporting for URI parsing/formatting problems
Move error reporting out of the callers, into virURIParse
and virURIFormat, to get consistency.
* include/libvirt/virterror.h, src/util/virterror.c: Add VIR_FROM_URI
* src/util/viruri.c, src/util/viruri.h: Add error reporting
* src/esx/esx_driver.c, src/libvirt.c, src/libxl/libxl_driver.c,
src/lxc/lxc_driver.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
src/remote/remote_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/vmx/vmx.c, src/xen/xen_driver.c,
src/xen/xend_internal.c, tests/viruritest.c: Remove error
reporting
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-03-20 12:16:54 +00:00
|
|
|
/* libxml2 does not tell us what failed. Grr :-( */
|
2012-07-18 10:26:24 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unable to parse URI %s"), uri);
|
Centralize error reporting for URI parsing/formatting problems
Move error reporting out of the callers, into virURIParse
and virURIFormat, to get consistency.
* include/libvirt/virterror.h, src/util/virterror.c: Add VIR_FROM_URI
* src/util/viruri.c, src/util/viruri.h: Add error reporting
* src/esx/esx_driver.c, src/libvirt.c, src/libxl/libxl_driver.c,
src/lxc/lxc_driver.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
src/remote/remote_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/vmx/vmx.c, src/xen/xen_driver.c,
src/xen/xend_internal.c, tests/viruritest.c: Remove error
reporting
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-03-20 12:16:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:17:18 +00:00
|
|
|
if (VIR_ALLOC(ret) < 0)
|
2013-05-24 07:19:51 +00:00
|
|
|
goto error;
|
2012-03-20 13:33:41 +00:00
|
|
|
|
2013-05-24 07:19:51 +00:00
|
|
|
if (VIR_STRDUP(ret->scheme, xmluri->scheme) < 0)
|
|
|
|
goto error;
|
|
|
|
if (VIR_STRDUP(ret->server, xmluri->server) < 0)
|
|
|
|
goto error;
|
2012-03-20 13:33:41 +00:00
|
|
|
ret->port = xmluri->port;
|
2013-05-24 07:19:51 +00:00
|
|
|
if (VIR_STRDUP(ret->path, xmluri->path) < 0)
|
|
|
|
goto error;
|
2012-03-20 13:33:41 +00:00
|
|
|
#ifdef HAVE_XMLURI_QUERY_RAW
|
2013-05-24 07:19:51 +00:00
|
|
|
if (VIR_STRDUP(ret->query, xmluri->query_raw) < 0)
|
|
|
|
goto error;
|
2012-03-20 13:33:41 +00:00
|
|
|
#else
|
2013-05-24 07:19:51 +00:00
|
|
|
if (VIR_STRDUP(ret->query, xmluri->query) < 0)
|
|
|
|
goto error;
|
2012-03-20 13:33:41 +00:00
|
|
|
#endif
|
2013-05-24 07:19:51 +00:00
|
|
|
if (VIR_STRDUP(ret->fragment, xmluri->fragment) < 0)
|
|
|
|
goto error;
|
|
|
|
if (VIR_STRDUP(ret->user, xmluri->user) < 0)
|
|
|
|
goto error;
|
2012-03-20 13:33:41 +00:00
|
|
|
|
2014-10-07 15:27:40 +00:00
|
|
|
/* Strip square bracket from an IPv6 address.
|
|
|
|
* The function modifies the string in-place. Even after such
|
|
|
|
* modification, it is OK to free the URI with xmlFreeURI. */
|
|
|
|
virStringStripIPv6Brackets(ret->server);
|
2012-02-24 18:48:55 +00:00
|
|
|
|
2012-03-20 13:59:32 +00:00
|
|
|
if (virURIParseParams(ret) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2012-03-20 13:33:41 +00:00
|
|
|
xmlFreeURI(xmluri);
|
|
|
|
|
2012-02-24 18:48:55 +00:00
|
|
|
return ret;
|
2012-03-20 13:33:41 +00:00
|
|
|
|
2014-03-25 06:53:22 +00:00
|
|
|
error:
|
2012-03-20 13:33:41 +00:00
|
|
|
xmlFreeURI(xmluri);
|
|
|
|
virURIFree(ret);
|
|
|
|
return NULL;
|
2012-02-24 18:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virURIFormat:
|
|
|
|
* @uri: URI to format
|
|
|
|
*
|
|
|
|
* Wrapper for xmlSaveUri
|
|
|
|
*
|
|
|
|
* This function constructs back everything that @ref virURIParse
|
|
|
|
* changes after parsing
|
|
|
|
*
|
|
|
|
* @returns the constructed uri as a string
|
|
|
|
*/
|
|
|
|
char *
|
2012-03-20 13:37:55 +00:00
|
|
|
virURIFormat(virURIPtr uri)
|
2012-02-24 18:48:55 +00:00
|
|
|
{
|
2012-03-20 13:33:41 +00:00
|
|
|
xmlURI xmluri;
|
2012-02-24 18:48:55 +00:00
|
|
|
char *tmpserver = NULL;
|
|
|
|
char *ret;
|
|
|
|
|
2012-03-20 13:33:41 +00:00
|
|
|
memset(&xmluri, 0, sizeof(xmluri));
|
|
|
|
|
|
|
|
xmluri.scheme = uri->scheme;
|
|
|
|
xmluri.server = uri->server;
|
|
|
|
xmluri.port = uri->port;
|
|
|
|
xmluri.path = uri->path;
|
2012-03-26 10:23:45 +00:00
|
|
|
#ifdef HAVE_XMLURI_QUERY_RAW
|
|
|
|
xmluri.query_raw = uri->query;
|
|
|
|
#else
|
2012-03-20 13:33:41 +00:00
|
|
|
xmluri.query = uri->query;
|
2012-03-26 10:23:45 +00:00
|
|
|
#endif
|
2012-03-20 13:33:41 +00:00
|
|
|
xmluri.fragment = uri->fragment;
|
2012-04-05 15:52:42 +00:00
|
|
|
xmluri.user = uri->user;
|
2012-03-20 13:33:41 +00:00
|
|
|
|
2012-02-24 18:48:55 +00:00
|
|
|
/* First check: does it make sense to do anything */
|
2012-03-20 13:33:41 +00:00
|
|
|
if (xmluri.server != NULL &&
|
|
|
|
strchr(xmluri.server, ':') != NULL) {
|
2012-02-24 18:48:55 +00:00
|
|
|
|
2013-07-04 10:17:18 +00:00
|
|
|
if (virAsprintf(&tmpserver, "[%s]", xmluri.server) < 0)
|
2012-02-24 18:48:55 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-03-20 13:33:41 +00:00
|
|
|
xmluri.server = tmpserver;
|
2012-02-24 18:48:55 +00:00
|
|
|
}
|
|
|
|
|
2014-10-03 16:27:01 +00:00
|
|
|
/*
|
|
|
|
* This helps libxml2 deal with the difference
|
|
|
|
* between uri:/absolute/path and uri:///absolute/path.
|
|
|
|
*/
|
|
|
|
if (!xmluri.server && !xmluri.port)
|
|
|
|
xmluri.port = -1;
|
|
|
|
|
2012-03-20 13:33:41 +00:00
|
|
|
ret = (char *)xmlSaveUri(&xmluri);
|
Centralize error reporting for URI parsing/formatting problems
Move error reporting out of the callers, into virURIParse
and virURIFormat, to get consistency.
* include/libvirt/virterror.h, src/util/virterror.c: Add VIR_FROM_URI
* src/util/viruri.c, src/util/viruri.h: Add error reporting
* src/esx/esx_driver.c, src/libvirt.c, src/libxl/libxl_driver.c,
src/lxc/lxc_driver.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
src/remote/remote_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/vmx/vmx.c, src/xen/xen_driver.c,
src/xen/xend_internal.c, tests/viruritest.c: Remove error
reporting
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-03-20 12:16:54 +00:00
|
|
|
if (!ret) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-02-24 18:48:55 +00:00
|
|
|
|
2014-03-25 06:53:22 +00:00
|
|
|
cleanup:
|
2012-03-20 13:33:41 +00:00
|
|
|
VIR_FREE(tmpserver);
|
2012-02-24 18:48:55 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-03-20 11:59:42 +00:00
|
|
|
|
|
|
|
|
2012-03-20 13:59:32 +00:00
|
|
|
char *virURIFormatParams(virURIPtr uri)
|
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-05-24 10:14:02 +00:00
|
|
|
bool amp = false;
|
2012-03-20 13:59:32 +00:00
|
|
|
|
|
|
|
for (i = 0; i < uri->paramsCount; ++i) {
|
|
|
|
if (!uri->params[i].ignore) {
|
2012-10-17 09:23:12 +00:00
|
|
|
if (amp) virBufferAddChar(&buf, '&');
|
|
|
|
virBufferStrcat(&buf, uri->params[i].name, "=", NULL);
|
|
|
|
virBufferURIEncodeString(&buf, uri->params[i].value);
|
2013-05-24 10:14:02 +00:00
|
|
|
amp = true;
|
2012-03-20 13:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buf) < 0)
|
2012-03-20 13:59:32 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
}
|
|
|
|
|
2012-03-20 11:59:42 +00:00
|
|
|
/**
|
|
|
|
* virURIFree:
|
|
|
|
* @uri: uri to free
|
|
|
|
*
|
|
|
|
* Frees the URI
|
|
|
|
*/
|
|
|
|
void virURIFree(virURIPtr uri)
|
|
|
|
{
|
2012-03-20 13:59:32 +00:00
|
|
|
size_t i;
|
|
|
|
|
2012-03-20 13:33:41 +00:00
|
|
|
if (!uri)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(uri->scheme);
|
|
|
|
VIR_FREE(uri->server);
|
2012-03-20 13:59:32 +00:00
|
|
|
VIR_FREE(uri->user);
|
2012-03-20 13:33:41 +00:00
|
|
|
VIR_FREE(uri->path);
|
|
|
|
VIR_FREE(uri->query);
|
2012-03-20 13:59:32 +00:00
|
|
|
VIR_FREE(uri->fragment);
|
|
|
|
|
2013-05-21 07:58:16 +00:00
|
|
|
for (i = 0; i < uri->paramsCount; i++) {
|
2012-03-20 13:59:32 +00:00
|
|
|
VIR_FREE(uri->params[i].name);
|
|
|
|
VIR_FREE(uri->params[i].value);
|
|
|
|
}
|
|
|
|
VIR_FREE(uri->params);
|
|
|
|
|
2012-03-20 13:33:41 +00:00
|
|
|
VIR_FREE(uri);
|
2012-03-20 11:59:42 +00:00
|
|
|
}
|
2015-11-06 09:44:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define URI_ALIAS_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
|
|
|
|
|
|
|
|
static int
|
2016-07-08 12:52:26 +00:00
|
|
|
virURIFindAliasMatch(char *const*aliases, const char *alias,
|
2015-11-06 09:44:53 +00:00
|
|
|
char **uri)
|
|
|
|
{
|
|
|
|
size_t alias_len;
|
|
|
|
|
|
|
|
alias_len = strlen(alias);
|
2016-07-08 12:52:26 +00:00
|
|
|
while (*aliases) {
|
2015-11-06 09:44:53 +00:00
|
|
|
char *offset;
|
|
|
|
size_t safe;
|
|
|
|
|
2016-07-08 12:52:26 +00:00
|
|
|
if (!(offset = strchr(*aliases, '='))) {
|
2015-11-06 09:44:53 +00:00
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
|
|
|
_("Malformed 'uri_aliases' config entry '%s', "
|
2016-07-08 12:52:26 +00:00
|
|
|
"expected 'alias=uri://host/path'"), *aliases);
|
2015-11-06 09:44:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-07-08 12:52:26 +00:00
|
|
|
safe = strspn(*aliases, URI_ALIAS_CHARS);
|
|
|
|
if (safe < (offset - *aliases)) {
|
2015-11-06 09:44:53 +00:00
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
|
|
|
_("Malformed 'uri_aliases' config entry '%s', "
|
|
|
|
"aliases may only contain 'a-Z, 0-9, _, -'"),
|
2016-07-08 12:52:26 +00:00
|
|
|
*aliases);
|
2015-11-06 09:44:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-07-08 12:52:26 +00:00
|
|
|
if (alias_len == (offset - *aliases) &&
|
|
|
|
STREQLEN(*aliases, alias, alias_len)) {
|
2015-11-06 09:44:53 +00:00
|
|
|
VIR_DEBUG("Resolved alias '%s' to '%s'",
|
|
|
|
alias, offset+1);
|
|
|
|
return VIR_STRDUP(*uri, offset+1);
|
|
|
|
}
|
|
|
|
|
2016-07-08 12:52:26 +00:00
|
|
|
aliases++;
|
2015-11-06 09:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("No alias found for '%s', continuing...",
|
|
|
|
alias);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virURIResolveAlias:
|
|
|
|
* @conf: configuration file handler
|
|
|
|
* @alias: URI alias to be resolved
|
|
|
|
* @uri: URI object reference where the resolved URI should be stored
|
|
|
|
*
|
|
|
|
* Resolves @alias to a canonical URI according to our configuration
|
|
|
|
* file.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virURIResolveAlias(virConfPtr conf, const char *alias, char **uri)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2016-07-08 12:52:26 +00:00
|
|
|
char **aliases = NULL;
|
2015-11-06 09:44:53 +00:00
|
|
|
|
|
|
|
*uri = NULL;
|
|
|
|
|
2016-07-08 12:52:26 +00:00
|
|
|
if (virConfGetValueStringList(conf, "uri_aliases", false, &aliases) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (aliases && *aliases) {
|
|
|
|
ret = virURIFindAliasMatch(aliases, alias, uri);
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(aliases);
|
2016-07-08 12:52:26 +00:00
|
|
|
} else {
|
2015-11-06 09:44:53 +00:00
|
|
|
ret = 0;
|
2016-07-08 12:52:26 +00:00
|
|
|
}
|
2015-11-06 09:44:53 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|