VIR_DEBUG("name \"%s\" to URI components:\n"
" scheme %s\n"
- " opaque %s\n"
- " authority %s\n"
" server %s\n"
" user %s\n"
" port %d\n"
" path %s\n",
alias ? alias : name,
- NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->opaque),
- NULLSTR(ret->uri->authority), NULLSTR(ret->uri->server),
+ NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->server),
NULLSTR(ret->uri->user), ret->uri->port,
NULLSTR(ret->uri->path));
*/
struct qparam *var;
int i;
- char *query;
if (conn->uri) {
-#ifdef HAVE_XMLURI_QUERY_RAW
- query = conn->uri->query_raw;
-#else
- query = conn->uri->query;
-#endif
- vars = qparam_query_parse (query);
+ vars = qparam_query_parse (conn->uri->query);
if (vars == NULL) goto failed;
for (i = 0; i < vars->n; i++) {
} else {
virURI tmpuri = {
.scheme = conn->uri->scheme,
-#ifdef HAVE_XMLURI_QUERY_RAW
- .query_raw = qparam_get_query (vars),
-#else
.query = qparam_get_query (vars),
-#endif
.path = conn->uri->path,
.fragment = conn->uri->fragment,
};
name = virURIFormat(&tmpuri);
-#ifdef HAVE_XMLURI_QUERY_RAW
- VIR_FREE(tmpuri.query_raw);
-#else
VIR_FREE(tmpuri.query);
-#endif
/* Restore transport scheme */
if (transport_str)
virURIPtr
virURIParse(const char *uri)
{
- virURIPtr ret = xmlParseURI(uri);
+ xmlURIPtr xmluri;
+ virURIPtr ret = NULL;
- if (!ret) {
+ xmluri = xmlParseURI(uri);
+
+ if (!xmluri) {
/* libxml2 does not tell us what failed. Grr :-( */
virURIReportError(VIR_ERR_INTERNAL_ERROR,
"Unable to parse URI %s", uri);
return NULL;
}
+ if (VIR_ALLOC(ret) < 0)
+ goto no_memory;
+
+ if (xmluri->scheme &&
+ !(ret->scheme = strdup(xmluri->scheme)))
+ goto no_memory;
+ if (xmluri->server &&
+ !(ret->server = strdup(xmluri->server)))
+ goto no_memory;
+ ret->port = xmluri->port;
+ if (xmluri->path &&
+ !(ret->path = strdup(xmluri->path)))
+ goto no_memory;
+#ifdef HAVE_XMLURI_QUERY_RAW
+ if (xmluri->query_raw &&
+ !(ret->query = strdup(xmluri->query_raw)))
+ goto no_memory;
+#else
+ if (xmluri->query &&
+ !(ret->query = strdup(xmluri->query)))
+ goto no_memory;
+#endif
+ if (xmluri->fragment &&
+ !(ret->fragment = strdup(xmluri->fragment)))
+ goto no_memory;
+
+
/* First check: does it even make sense to jump inside */
if (ret->server != NULL &&
ret->server[0] == '[') {
* the uri with xmlFreeURI() */
}
+ xmlFreeURI(xmluri);
+
return ret;
+
+no_memory:
+ virReportOOMError();
+ xmlFreeURI(xmluri);
+ virURIFree(ret);
+ return NULL;
}
/**
char *
virURIFormat(virURIPtr uri)
{
- char *backupserver = NULL;
+ xmlURI xmluri;
char *tmpserver = NULL;
char *ret;
+ memset(&xmluri, 0, sizeof(xmluri));
+
+ xmluri.scheme = uri->scheme;
+ xmluri.server = uri->server;
+ xmluri.port = uri->port;
+ xmluri.path = uri->path;
+ xmluri.query = uri->query;
+ xmluri.fragment = uri->fragment;
+
/* First check: does it make sense to do anything */
- if (uri->server != NULL &&
- strchr(uri->server, ':') != NULL) {
+ if (xmluri.server != NULL &&
+ strchr(xmluri.server, ':') != NULL) {
- backupserver = uri->server;
- if (virAsprintf(&tmpserver, "[%s]", uri->server) < 0)
+ if (virAsprintf(&tmpserver, "[%s]", xmluri.server) < 0)
return NULL;
- uri->server = tmpserver;
+ xmluri.server = tmpserver;
}
- ret = (char *) xmlSaveUri(uri);
+ ret = (char *)xmlSaveUri(&xmluri);
if (!ret) {
virReportOOMError();
goto cleanup;
}
cleanup:
- /* Put the fixed version back */
- if (tmpserver) {
- uri->server = backupserver;
- VIR_FREE(tmpserver);
- }
+ VIR_FREE(tmpserver);
return ret;
}
*/
void virURIFree(virURIPtr uri)
{
- xmlFreeURI(uri);
+ if (!uri)
+ return;
+
+ VIR_FREE(uri->scheme);
+ VIR_FREE(uri->server);
+ VIR_FREE(uri->path);
+ VIR_FREE(uri->query);
+ VIR_FREE(uri);
}
# include "internal.h"
-typedef xmlURI virURI;
-typedef xmlURIPtr virURIPtr;
+typedef struct _virURI virURI;
+typedef virURI *virURIPtr;
+
+struct _virURI {
+ char *scheme; /* the URI scheme */
+ char *server; /* the server part */
+ char *user; /* the user part */
+ int port; /* the port number */
+ char *path; /* the path string */
+ char *query; /* the query string */
+ char *fragment; /* the fragment string */
+};
virURIPtr virURIParse(const char *uri)
ATTRIBUTE_NONNULL(1);