提交 bc1ff160 编写于 作者: D Daniel P. Berrange

Convert drivers over to use virURIPtr for query params

Convert drivers currently using the qparams APIs, to instead
use the virURIPtr query parameters directly.

* src/esx/esx_util.c, src/hyperv/hyperv_util.c,
  src/remote/remote_driver.c, src/xenapi/xenapi_utils.c: Remove
  use of qparams
* src/util/qparams.h, src/util/qparams.c: Delete
* src/Makefile.am, src/libvirt_private.syms: Remove qparams
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 4ae4ae4b
......@@ -70,7 +70,6 @@ UTIL_SOURCES = \
util/pci.c util/pci.h \
util/processinfo.c util/processinfo.h \
util/hostusb.c util/hostusb.h \
util/qparams.c util/qparams.h \
util/sexpr.c util/sexpr.h \
util/stats_linux.c util/stats_linux.h \
util/storage_file.c util/storage_file.h \
......
......@@ -28,7 +28,6 @@
#include "internal.h"
#include "datatypes.h"
#include "qparams.h"
#include "util.h"
#include "memory.h"
#include "logging.h"
......@@ -45,8 +44,6 @@ int
esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
{
int result = -1;
struct qparam_set *queryParamSet = NULL;
struct qparam *queryParam = NULL;
int i;
int noVerify;
int autoAnswer;
......@@ -62,14 +59,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
return -1;
}
queryParamSet = qparam_query_parse(uri->query);
if (queryParamSet == NULL) {
goto cleanup;
}
for (i = 0; i < queryParamSet->n; i++) {
queryParam = &queryParamSet->p[i];
for (i = 0; i < uri->paramsCount; i++) {
virURIParamPtr queryParam = &uri->params[i];
if (STRCASEEQ(queryParam->name, "transport")) {
VIR_FREE((*parsedUri)->transport);
......@@ -204,10 +195,6 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
esxUtil_FreeParsedUri(parsedUri);
}
if (queryParamSet != NULL) {
free_qparam_set(queryParamSet);
}
return result;
}
......
......@@ -24,7 +24,6 @@
#include "internal.h"
#include "datatypes.h"
#include "qparams.h"
#include "util.h"
#include "memory.h"
#include "logging.h"
......@@ -40,8 +39,6 @@ int
hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri)
{
int result = -1;
struct qparam_set *queryParamSet = NULL;
struct qparam *queryParam = NULL;
int i;
if (parsedUri == NULL || *parsedUri != NULL) {
......@@ -54,14 +51,8 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri)
return -1;
}
queryParamSet = qparam_query_parse(uri->query);
if (queryParamSet == NULL) {
goto cleanup;
}
for (i = 0; i < queryParamSet->n; i++) {
queryParam = &queryParamSet->p[i];
for (i = 0; i < uri->paramsCount; i++) {
virURIParamPtr queryParam = &uri->params[i];
if (STRCASEEQ(queryParam->name, "transport")) {
VIR_FREE((*parsedUri)->transport);
......@@ -103,10 +94,6 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri)
hypervFreeParsedUri(parsedUri);
}
if (queryParamSet != NULL) {
free_qparam_set(queryParamSet);
}
return result;
}
......
......@@ -917,12 +917,6 @@ virProcessInfoGetAffinity;
virProcessInfoSetAffinity;
# qparams.h
free_qparam_set;
qparam_get_query;
qparam_query_parse;
# secret_conf.h
virSecretDefFormat;
virSecretDefFree;
......
......@@ -35,7 +35,6 @@
#include "domain_event.h"
#include "driver.h"
#include "buf.h"
#include "qparams.h"
#include "remote_driver.h"
#include "remote_protocol.h"
#include "qemu_protocol.h"
......@@ -311,7 +310,6 @@ doRemoteOpen (virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags)
{
struct qparam_set *vars = NULL;
char *transport_str = NULL;
enum {
trans_tls,
......@@ -415,15 +413,11 @@ doRemoteOpen (virConnectPtr conn,
* feasibly it might contain variables needed by the real driver,
* although that won't be the case for now).
*/
struct qparam *var;
int i;
if (conn->uri) {
vars = qparam_query_parse (conn->uri->query);
if (vars == NULL) goto failed;
for (i = 0; i < vars->n; i++) {
var = &vars->p[i];
for (i = 0; i < conn->uri->paramsCount ; i++) {
virURIParamPtr var = &conn->uri->params[i];
if (STRCASEEQ (var->name, "name")) {
VIR_FREE(name);
name = strdup (var->value);
......@@ -484,7 +478,7 @@ doRemoteOpen (virConnectPtr conn,
} else {
virURI tmpuri = {
.scheme = conn->uri->scheme,
.query = qparam_get_query (vars),
.query = virURIFormatQuery(conn->uri),
.path = conn->uri->path,
.fragment = conn->uri->fragment,
};
......@@ -507,9 +501,6 @@ doRemoteOpen (virConnectPtr conn,
goto failed;
}
}
free_qparam_set (vars);
vars = NULL;
} else {
/* Probe URI server side */
if (!(name = strdup("")))
......@@ -732,8 +723,6 @@ doRemoteOpen (virConnectPtr conn,
out_of_memory:
virReportOOMError();
if (vars)
free_qparam_set (vars);
failed:
virNetClientProgramFree(priv->remoteProgram);
......
/* Copyright (C) 2007, 2009-2010 Red Hat, Inc.
*
* 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
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors:
* Richard W.M. Jones <rjones@redhat.com>
*
* Utility functions to help parse and assemble query strings.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "virterror_internal.h"
#include "buf.h"
#include "memory.h"
#include "qparams.h"
#include "viruri.h"
#define VIR_FROM_THIS VIR_FROM_NONE
struct qparam_set *
new_qparam_set (int init_alloc, ...)
{
va_list args;
struct qparam_set *ps;
const char *pname, *pvalue;
if (init_alloc <= 0) init_alloc = 1;
if (VIR_ALLOC(ps) < 0) {
virReportOOMError();
return NULL;
}
ps->n = 0;
ps->alloc = init_alloc;
if (VIR_ALLOC_N(ps->p, ps->alloc) < 0) {
VIR_FREE (ps);
virReportOOMError();
return NULL;
}
va_start (args, init_alloc);
while ((pname = va_arg (args, char *)) != NULL) {
pvalue = va_arg (args, char *);
if (append_qparam (ps, pname, pvalue) == -1) {
free_qparam_set (ps);
ps = NULL;
break;
}
}
va_end (args);
return ps;
}
int
append_qparams (struct qparam_set *ps, ...)
{
va_list args;
const char *pname, *pvalue;
int ret = 0;
va_start (args, ps);
while ((pname = va_arg (args, char *)) != NULL) {
pvalue = va_arg (args, char *);
if (append_qparam (ps, pname, pvalue) == -1) {
ret = -1;
break;
}
}
va_end (args);
return ret;
}
/* Ensure there is space to store at least one more parameter
* at the end of the set.
*/
static int
grow_qparam_set (struct qparam_set *ps)
{
if (ps->n >= ps->alloc) {
if (VIR_REALLOC_N(ps->p, ps->alloc * 2) < 0) {
virReportOOMError();
return -1;
}
ps->alloc *= 2;
}
return 0;
}
int
append_qparam (struct qparam_set *ps,
const char *name, const char *value)
{
char *pname, *pvalue;
pname = strdup (name);
if (!pname) {
virReportOOMError();
return -1;
}
pvalue = strdup (value);
if (!pvalue) {
VIR_FREE (pname);
virReportOOMError();
return -1;
}
if (grow_qparam_set (ps) == -1) {
VIR_FREE (pname);
VIR_FREE (pvalue);
return -1;
}
ps->p[ps->n].name = pname;
ps->p[ps->n].value = pvalue;
ps->p[ps->n].ignore = 0;
ps->n++;
return 0;
}
char *
qparam_get_query (const struct qparam_set *ps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
int i, amp = 0;
for (i = 0; i < ps->n; ++i) {
if (!ps->p[i].ignore) {
if (amp) virBufferAddChar (&buf, '&');
virBufferStrcat (&buf, ps->p[i].name, "=", NULL);
virBufferURIEncodeString (&buf, ps->p[i].value);
amp = 1;
}
}
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
return NULL;
}
return virBufferContentAndReset(&buf);
}
void
free_qparam_set (struct qparam_set *ps)
{
int i;
for (i = 0; i < ps->n; ++i) {
VIR_FREE (ps->p[i].name);
VIR_FREE (ps->p[i].value);
}
VIR_FREE (ps->p);
VIR_FREE (ps);
}
struct qparam_set *
qparam_query_parse (const char *query)
{
struct qparam_set *ps;
const char *end, *eq;
ps = new_qparam_set (0, NULL);
if (!ps) {
virReportOOMError();
return NULL;
}
if (!query || query[0] == '\0') return ps;
while (*query) {
char *name = NULL, *value = NULL;
/* Find the next separator, or end of the string. */
end = strchr (query, '&');
if (!end)
end = strchr (query, ';');
if (!end)
end = query + strlen (query);
/* Find the first '=' character between here and end. */
eq = strchr (query, '=');
if (eq && eq >= end) eq = NULL;
/* Empty section (eg. "&&"). */
if (end == query)
goto next;
/* If there is no '=' character, then we have just "name"
* and consistent with CGI.pm we assume value is "".
*/
else if (!eq) {
name = xmlURIUnescapeString (query, end - query, NULL);
if (!name) goto out_of_memory;
}
/* Or if we have "name=" here (works around annoying
* problem when calling xmlURIUnescapeString with len = 0).
*/
else if (eq+1 == end) {
name = xmlURIUnescapeString (query, eq - query, NULL);
if (!name) goto out_of_memory;
}
/* If the '=' character is at the beginning then we have
* "=value" and consistent with CGI.pm we _ignore_ this.
*/
else if (query == eq)
goto next;
/* Otherwise it's "name=value". */
else {
name = xmlURIUnescapeString (query, eq - query, NULL);
if (!name)
goto out_of_memory;
value = xmlURIUnescapeString (eq+1, end - (eq+1), NULL);
if (!value) {
VIR_FREE(name);
goto out_of_memory;
}
}
/* Append to the parameter set. */
if (append_qparam (ps, name, value ? value : "") == -1) {
VIR_FREE(name);
VIR_FREE(value);
goto out_of_memory;
}
VIR_FREE(name);
VIR_FREE(value);
next:
query = end;
if (*query) query ++; /* skip '&' separator */
}
return ps;
out_of_memory:
virReportOOMError();
free_qparam_set (ps);
return NULL;
}
/* Copyright (C) 2007 Red Hat, Inc.
*
* 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
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors:
* Richard W.M. Jones <rjones@redhat.com>
*
* Utility functions to help parse and assemble query strings.
*/
#ifndef _QPARAMS_H_
# define _QPARAMS_H_
/* Single web service query parameter 'name=value'. */
struct qparam {
char *name; /* Name (unescaped). */
char *value; /* Value (unescaped). */
int ignore; /* Ignore this field in qparam_get_query */
};
/* Set of parameters. */
struct qparam_set {
int n; /* number of parameters used */
int alloc; /* allocated space */
struct qparam *p; /* array of parameters */
};
/* New parameter set. */
extern struct qparam_set *new_qparam_set (int init_alloc, ...)
ATTRIBUTE_SENTINEL;
/* Appending parameters. */
extern int append_qparams (struct qparam_set *ps, ...)
ATTRIBUTE_SENTINEL;
extern int append_qparam (struct qparam_set *ps,
const char *name, const char *value);
/* Get a query string ("name=value&name=value&...") */
extern char *qparam_get_query (const struct qparam_set *ps);
/* Parse a query string into a parameter set. */
extern struct qparam_set *qparam_query_parse (const char *query);
extern void free_qparam_set (struct qparam_set *ps);
#endif /* _QPARAMS_H_ */
......@@ -35,7 +35,6 @@
#include "memory.h"
#include "buf.h"
#include "logging.h"
#include "qparams.h"
#include "viruri.h"
#include "xenapi_driver_private.h"
#include "xenapi_utils.h"
......@@ -98,21 +97,9 @@ xenapiUtil_ParseQuery(virConnectPtr conn, virURIPtr uri, int *noVerify)
{
int result = 0;
int i;
struct qparam_set *queryParamSet = NULL;
struct qparam *queryParam = NULL;
#ifdef HAVE_XMLURI_QUERY_RAW
queryParamSet = qparam_query_parse(uri->query_raw);
#else
queryParamSet = qparam_query_parse(uri->query);
#endif
if (queryParamSet == NULL) {
goto failure;
}
for (i = 0; i < queryParamSet->n; i++) {
queryParam = &queryParamSet->p[i];
for (i = 0; i < uri->paramsCount; i++) {
virURIParamPtr queryParam = &uri->params[i];
if (STRCASEEQ(queryParam->name, "no_verify")) {
if (noVerify == NULL) {
continue;
......@@ -127,9 +114,6 @@ xenapiUtil_ParseQuery(virConnectPtr conn, virURIPtr uri, int *noVerify)
}
cleanup:
if (queryParamSet != NULL) {
free_qparam_set(queryParamSet);
}
return result;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册