The generic XML parsing routines can generate various
errors. We were not passing a virConnectPtr object into
any of them, so the errors were not propagated back to
the calling app correctly. This fixes that problem
domain_conf.c | 60 ++++++++++++++++++++++++++++-----------------------------
lxc_conf.c | 14 ++++++-------
network_conf.c | 22 ++++++++++----------
storage_conf.c | 60 ++++++++++++++++++++++++++++-----------------------------
test.c | 20 +++++++++----------
xml.c | 53 ++++++++++++++++++++++++++++++++------------------
xml.h | 27 +++++++++++++++++--------
7 files changed, 140 insertions(+), 116 deletions(-)
Daniel
diff -r 4dbf0dba3661 src/domain_conf.c
--- a/src/domain_conf.c Thu Jul 03 16:50:15 2008 +0100
+++ b/src/domain_conf.c Thu Jul 03 16:50:19 2008 +0100
@@ -1291,7 +1291,7 @@
int *val,
int defaultVal)
{
- char *tmp = virXPathString(xpath, ctxt);
+ char *tmp = virXPathString(conn, xpath, ctxt);
if (tmp == NULL) {
*val = defaultVal;
} else {
@@ -1385,7 +1385,7 @@
def->id = -1;
/* Find out what type of QEMU virtualization to use */
- if (!(tmp = virXPathString("string(./@type)", ctxt))) {
+ if (!(tmp = virXPathString(conn, "string(./@type)", ctxt))) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("missing domain type
attribute"));
goto error;
@@ -1399,13 +1399,13 @@
VIR_FREE(tmp);
/* Extract domain name */
- if (!(def->name = virXPathString("string(./name[1])", ctxt))) {
+ if (!(def->name = virXPathString(conn, "string(./name[1])", ctxt))) {
virDomainReportError(conn, VIR_ERR_NO_NAME, NULL);
goto error;
}
/* Extract domain uuid */
- tmp = virXPathString("string(./uuid[1])", ctxt);
+ tmp = virXPathString(conn, "string(./uuid[1])", ctxt);
if (!tmp) {
int err;
if ((err = virUUIDGenerate(def->uuid))) {
@@ -1424,19 +1424,19 @@
}
/* Extract domain memory */
- if (virXPathULong("string(./memory[1])", ctxt, &def->maxmem) < 0)
{
+ if (virXPathULong(conn, "string(./memory[1])", ctxt, &def->maxmem)
< 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("missing memory element"));
goto error;
}
- if (virXPathULong("string(./currentMemory[1])", ctxt, &def->memory)
< 0)
+ if (virXPathULong(conn, "string(./currentMemory[1])", ctxt,
&def->memory) < 0)
def->memory = def->maxmem;
- if (virXPathULong("string(./vcpu[1])", ctxt, &def->vcpus) < 0)
+ if (virXPathULong(conn, "string(./vcpu[1])", ctxt, &def->vcpus) <
0)
def->vcpus = 1;
- tmp = virXPathString("string(./vcpu[1]/@cpuset)", ctxt);
+ tmp = virXPathString(conn, "string(./vcpu[1]/@cpuset)", ctxt);
if (tmp) {
char *set = tmp;
def->cpumasklen = VIR_DOMAIN_CPUMASK_LEN;
@@ -1451,7 +1451,7 @@
VIR_FREE(tmp);
}
- if ((n = virXPathNodeSet("./features/*", ctxt, &nodes)) > 0) {
+ if ((n = virXPathNodeSet(conn, "./features/*", ctxt, &nodes)) > 0)
{
for (i = 0 ; i < n ; i++) {
int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name);
if (val < 0) {
@@ -1478,15 +1478,15 @@
goto error;
- tmp = virXPathString("string(./clock/@offset)", ctxt);
+ tmp = virXPathString(conn, "string(./clock/@offset)", ctxt);
if (tmp && STREQ(tmp, "localtime"))
def->localtime = 1;
VIR_FREE(tmp);
- def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
- def->os.bootloaderArgs = virXPathString("string(./bootloader_args)",
ctxt);
+ def->os.bootloader = virXPathString(conn, "string(./bootloader)",
ctxt);
+ def->os.bootloaderArgs = virXPathString(conn,
"string(./bootloader_args)", ctxt);
- def->os.type = virXPathString("string(./os/type[1])", ctxt);
+ def->os.type = virXPathString(conn, "string(./os/type[1])", ctxt);
if (!def->os.type) {
if (def->os.bootloader) {
def->os.type = strdup("xen");
@@ -1520,7 +1520,7 @@
goto error;
}
- def->os.arch = virXPathString("string(./os/type[1]/@arch)", ctxt);
+ def->os.arch = virXPathString(conn, "string(./os/type[1]/@arch)",
ctxt);
if (!def->os.arch) {
const char *defaultArch = virCapabilitiesDefaultGuestArch(caps,
def->os.type);
if (defaultArch == NULL) {
@@ -1535,7 +1535,7 @@
}
}
- def->os.machine = virXPathString("string(./os/type[1]/@machine)",
ctxt);
+ def->os.machine = virXPathString(conn, "string(./os/type[1]/@machine)",
ctxt);
if (!def->os.machine) {
const char *defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
def->os.type,
@@ -1549,14 +1549,14 @@
}
if (!def->os.bootloader) {
- def->os.kernel = virXPathString("string(./os/kernel[1])", ctxt);
- def->os.initrd = virXPathString("string(./os/initrd[1])", ctxt);
- def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
- def->os.root = virXPathString("string(./os/root[1])", ctxt);
- def->os.loader = virXPathString("string(./os/loader[1])", ctxt);
+ def->os.kernel = virXPathString(conn, "string(./os/kernel[1])",
ctxt);
+ def->os.initrd = virXPathString(conn, "string(./os/initrd[1])",
ctxt);
+ def->os.cmdline = virXPathString(conn, "string(./os/cmdline[1])",
ctxt);
+ def->os.root = virXPathString(conn, "string(./os/root[1])", ctxt);
+ def->os.loader = virXPathString(conn, "string(./os/loader[1])",
ctxt);
/* analysis of the boot devices */
- if ((n = virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./os/boot", ctxt, &nodes)) < 0)
{
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract boot
device"));
goto error;
@@ -1586,7 +1586,7 @@
VIR_FREE(nodes);
}
- def->emulator = virXPathString("string(./devices/emulator[1])", ctxt);
+ def->emulator = virXPathString(conn, "string(./devices/emulator[1])",
ctxt);
if (!def->emulator) {
const char *type = virDomainVirtTypeToString(def->virtType);
if (!type) {
@@ -1610,7 +1610,7 @@
}
/* analysis of the disk devices */
- if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/disk", ctxt, &nodes)) < 0)
{
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract disk
devices"));
goto error;
@@ -1640,7 +1640,7 @@
VIR_FREE(nodes);
/* analysis of the network devices */
- if ((n = virXPathNodeSet("./devices/interface", ctxt, &nodes)) < 0)
{
+ if ((n = virXPathNodeSet(conn, "./devices/interface", ctxt, &nodes))
< 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract network
devices"));
goto error;
@@ -1658,7 +1658,7 @@
/* analysis of the character devices */
- if ((n = virXPathNodeSet("./devices/parallel", ctxt, &nodes)) < 0)
{
+ if ((n = virXPathNodeSet(conn, "./devices/parallel", ctxt, &nodes))
< 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract parallel
devices"));
goto error;
@@ -1675,7 +1675,7 @@
}
VIR_FREE(nodes);
- if ((n = virXPathNodeSet("./devices/serial", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/serial", ctxt, &nodes)) <
0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract serial
devices"));
goto error;
@@ -1697,7 +1697,7 @@
* devices which is the legacy syntax for the same thing
*/
if (def->serials == NULL) {
- if ((node = virXPathNode("./devices/console[1]", ctxt)) != NULL) {
+ if ((node = virXPathNode(conn, "./devices/console[1]", ctxt)) != NULL)
{
virDomainChrDefPtr chr = virDomainChrDefParseXML(conn,
node);
if (!chr)
@@ -1719,7 +1719,7 @@
/* analysis of the input devices */
- if ((n = virXPathNodeSet("./devices/input", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/input", ctxt, &nodes)) <
0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract input
devices"));
goto error;
@@ -1751,7 +1751,7 @@
VIR_FREE(nodes);
/* analysis of the input devices */
- if ((n = virXPathNodeSet("./devices/graphics", ctxt, &nodes)) < 0)
{
+ if ((n = virXPathNodeSet(conn, "./devices/graphics", ctxt, &nodes))
< 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract graphics
devices"));
goto error;
@@ -1787,7 +1787,7 @@
/* analysis of the sound devices */
- if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/sound", ctxt, &nodes)) <
0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract sound
devices"));
goto error;
diff -r 4dbf0dba3661 src/lxc_conf.c
--- a/src/lxc_conf.c Thu Jul 03 16:50:15 2008 +0100
+++ b/src/lxc_conf.c Thu Jul 03 16:50:19 2008 +0100
@@ -210,7 +210,7 @@
DEBUG0("parsing nets");
- res = virXPathNodeSet("/domain/devices/interface", contextPtr, &list);
+ res = virXPathNodeSet(conn, "/domain/devices/interface", contextPtr,
&list);
if (res > 0) {
for (i = 0; i < res; ++i) {
netDef = calloc(1, sizeof(lxc_net_def_t));
@@ -338,7 +338,7 @@
{
char *res;
- res = virXPathString("string(/domain/name[1])", contextPtr);
+ res = virXPathString(conn, "string(/domain/name[1])", contextPtr);
if (res == NULL) {
lxcError(conn, NULL, VIR_ERR_NO_NAME, NULL);
return(-1);
@@ -353,7 +353,7 @@
{
char *res;
- res = virXPathString("string(/domain/uuid[1])", contextPtr);
+ res = virXPathString(conn, "string(/domain/uuid[1])", contextPtr);
if (res == NULL) {
if (virUUIDGenerate(uuid)) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -384,7 +384,7 @@
xmlNodePtr *list;
int res;
- res = virXPathNodeSet("/domain/devices/filesystem", contextPtr,
&list);
+ res = virXPathNodeSet(conn, "/domain/devices/filesystem", contextPtr,
&list);
if (res > 0) {
for (i = 0; i < res; ++i) {
if (VIR_ALLOC(mountObj) < 0) {
@@ -422,7 +422,7 @@
{
char *res;
- res = virXPathString("string(/domain/os/init[1])", contextPtr);
+ res = virXPathString(conn, "string(/domain/os/init[1])", contextPtr);
if (res == NULL) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
_("invalid or missing init element"));
@@ -446,7 +446,7 @@
{
char *res;
- res = virXPathString("string(/domain/devices/console[1]/@tty)",
contextPtr);
+ res = virXPathString(conn, "string(/domain/devices/console[1]/@tty)",
contextPtr);
if (res == NULL) {
/* make sure the tty string is empty */
*tty = strdup("");
@@ -466,7 +466,7 @@
long res;
int rc;
- rc = virXPathLong("string(/domain/memory[1])", contextPtr, &res);
+ rc = virXPathLong(conn, "string(/domain/memory[1])", contextPtr,
&res);
if ((rc == -2) || ((rc == 0) && (res <= 0))) {
*memory = -1;
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
diff -r 4dbf0dba3661 src/network_conf.c
--- a/src/network_conf.c Thu Jul 03 16:50:15 2008 +0100
+++ b/src/network_conf.c Thu Jul 03 16:50:19 2008 +0100
@@ -239,14 +239,14 @@
}
/* Extract network name */
- def->name = virXPathString("string(./name[1])", ctxt);
+ def->name = virXPathString(conn, "string(./name[1])", ctxt);
if (!def->name) {
virNetworkReportError(conn, VIR_ERR_NO_NAME, NULL);
goto error;
}
/* Extract network uuid */
- tmp = virXPathString("string(./uuid[1])", ctxt);
+ tmp = virXPathString(conn, "string(./uuid[1])", ctxt);
if (!tmp) {
int err;
if ((err = virUUIDGenerate(def->uuid))) {
@@ -265,16 +265,16 @@
}
/* Parse bridge information */
- def->bridge = virXPathString("string(./bridge[1]/@name)", ctxt);
- tmp = virXPathString("string(./bridge[1]/@stp)", ctxt);
+ def->bridge = virXPathString(conn, "string(./bridge[1]/@name)", ctxt);
+ tmp = virXPathString(conn, "string(./bridge[1]/@stp)", ctxt);
def->stp = (tmp && STREQ(tmp, "off")) ? 0 : 1;
VIR_FREE(tmp);
- if (virXPathULong("string(./bridge[1]/@delay)", ctxt, &def->delay)
< 0)
+ if (virXPathULong(conn, "string(./bridge[1]/@delay)", ctxt,
&def->delay) < 0)
def->delay = 0;
- def->ipAddress = virXPathString("string(./ip[1]/@address)", ctxt);
- def->netmask = virXPathString("string(./ip[1]/@netmask)", ctxt);
+ def->ipAddress = virXPathString(conn, "string(./ip[1]/@address)",
ctxt);
+ def->netmask = virXPathString(conn, "string(./ip[1]/@netmask)", ctxt);
if (def->ipAddress &&
def->netmask) {
/* XXX someday we want IPv6 too, so inet_aton won't work there */
@@ -303,14 +303,14 @@
goto error;
}
- if ((dhcp = virXPathNode("./ip[1]/dhcp[1]", ctxt)) &&
+ if ((dhcp = virXPathNode(conn, "./ip[1]/dhcp[1]", ctxt)) &&
virNetworkDHCPRangeDefParseXML(conn, def, dhcp) < 0)
goto error;
}
/* IPv4 forwarding setup */
- if (virXPathBoolean("count(./forward) > 0", ctxt)) {
+ if (virXPathBoolean(conn, "count(./forward) > 0", ctxt)) {
if (!def->ipAddress ||
!def->netmask) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -318,7 +318,7 @@
goto error;
}
- tmp = virXPathString("string(./forward[1]/@mode)", ctxt);
+ tmp = virXPathString(conn, "string(./forward[1]/@mode)", ctxt);
if (tmp) {
if ((def->forwardType = virNetworkForwardTypeFromString(tmp)) < 0) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -332,7 +332,7 @@
}
- def->forwardDev = virXPathString("string(./forward[1]/@dev)",
ctxt);
+ def->forwardDev = virXPathString(conn, "string(./forward[1]/@dev)",
ctxt);
} else {
def->forwardType = VIR_NETWORK_FORWARD_NONE;
}
diff -r 4dbf0dba3661 src/storage_conf.c
--- a/src/storage_conf.c Thu Jul 03 16:50:15 2008 +0100
+++ b/src/storage_conf.c Thu Jul 03 16:50:19 2008 +0100
@@ -149,14 +149,14 @@
virStoragePoolDefParseAuthChap(virConnectPtr conn,
xmlXPathContextPtr ctxt,
virStoragePoolAuthChapPtr auth) {
- auth->login = virXPathString("string(/pool/source/auth/@login)", ctxt);
+ auth->login = virXPathString(conn, "string(/pool/source/auth/@login)",
ctxt);
if (auth->login == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing auth host
attribute"));
return -1;
}
- auth->passwd = virXPathString("string(/pool/source/auth/@passwd)",
ctxt);
+ auth->passwd = virXPathString(conn, "string(/pool/source/auth/@passwd)",
ctxt);
if (auth->passwd == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing auth passwd
attribute"));
@@ -174,7 +174,7 @@
char *mode;
long v;
- mode = virXPathString("string(/pool/permissions/mode)", ctxt);
+ mode = virXPathString(conn, "string(/pool/permissions/mode)", ctxt);
if (!mode) {
perms->mode = 0700;
} else {
@@ -187,10 +187,10 @@
}
}
- if (virXPathNode("/pool/permissions/owner", ctxt) == NULL) {
+ if (virXPathNode(conn, "/pool/permissions/owner", ctxt) == NULL) {
perms->uid = getuid();
} else {
- if (virXPathLong("number(/pool/permissions/owner)", ctxt, &v) <
0) {
+ if (virXPathLong(conn, "number(/pool/permissions/owner)", ctxt, &v)
< 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("malformed owner
element"));
return -1;
@@ -198,10 +198,10 @@
perms->uid = (int)v;
}
- if (virXPathNode("/pool/permissions/group", ctxt) == NULL) {
+ if (virXPathNode(conn, "/pool/permissions/group", ctxt) == NULL) {
perms->uid = getgid();
} else {
- if (virXPathLong("number(/pool/permissions/group)", ctxt, &v) <
0) {
+ if (virXPathLong(conn, "number(/pool/permissions/group)", ctxt, &v)
< 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("malformed group
element"));
return -1;
@@ -210,7 +210,7 @@
}
/* NB, we're ignoring missing labels here - they'll simply inherit */
- perms->label = virXPathString("string(/pool/permissions/label)", ctxt);
+ perms->label = virXPathString(conn, "string(/pool/permissions/label)",
ctxt);
return 0;
}
@@ -248,13 +248,13 @@
goto cleanup;
}
- if ((ret->name = virXPathString("string(/pool/name)", ctxt)) == NULL) {
+ if ((ret->name = virXPathString(conn, "string(/pool/name)", ctxt)) ==
NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing name element"));
goto cleanup;
}
- uuid = virXPathString("string(/pool/uuid)", ctxt);
+ uuid = virXPathString(conn, "string(/pool/uuid)", ctxt);
if (uuid == NULL) {
if (virUUIDGenerate(ret->uuid) < 0) {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -271,7 +271,7 @@
}
if (options->formatFromString) {
- char *format = virXPathString("string(/pool/source/format/@type)",
ctxt);
+ char *format = virXPathString(conn,
"string(/pool/source/format/@type)", ctxt);
if ((ret->source.format = (options->formatFromString)(conn, format)) <
0) {
VIR_FREE(format);
goto cleanup;
@@ -280,7 +280,7 @@
}
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) {
- if ((ret->source.host.name =
virXPathString("string(/pool/source/host/@name)", ctxt)) == NULL) {
+ if ((ret->source.host.name = virXPathString(conn,
"string(/pool/source/host/@name)", ctxt)) == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing source host
name"));
goto cleanup;
@@ -290,7 +290,7 @@
xmlNodePtr *nodeset = NULL;
int nsource, i;
- if ((nsource = virXPathNodeSet("/pool/source/device", ctxt,
&nodeset)) <= 0) {
+ if ((nsource = virXPathNodeSet(conn, "/pool/source/device", ctxt,
&nodeset)) <= 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("cannot extract source
devices"));
goto cleanup;
@@ -314,7 +314,7 @@
ret->source.ndevice = nsource;
}
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) {
- if ((ret->source.dir =
virXPathString("string(/pool/source/dir/@path)", ctxt)) == NULL) {
+ if ((ret->source.dir = virXPathString(conn,
"string(/pool/source/dir/@path)", ctxt)) == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing source path"));
goto cleanup;
@@ -322,7 +322,7 @@
}
- authType = virXPathString("string(/pool/source/auth/@type)", ctxt);
+ authType = virXPathString(conn, "string(/pool/source/auth/@type)", ctxt);
if (authType == NULL) {
ret->source.authType = VIR_STORAGE_POOL_AUTH_NONE;
} else {
@@ -343,7 +343,7 @@
goto cleanup;
}
- if ((ret->target.path = virXPathString("string(/pool/target/path)",
ctxt)) == NULL) {
+ if ((ret->target.path = virXPathString(conn,
"string(/pool/target/path)", ctxt)) == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing target path"));
goto cleanup;
@@ -522,7 +522,7 @@
char *mode;
long v;
- mode = virXPathString("string(/volume/permissions/mode)", ctxt);
+ mode = virXPathString(conn, "string(/volume/permissions/mode)", ctxt);
if (!mode) {
perms->mode = 0600;
} else {
@@ -535,20 +535,20 @@
}
}
- if (virXPathNode("/volume/permissions/owner", ctxt) == NULL) {
+ if (virXPathNode(conn, "/volume/permissions/owner", ctxt) == NULL) {
perms->uid = getuid();
} else {
- if (virXPathLong("number(/volume/permissions/owner)", ctxt, &v)
< 0) {
+ if (virXPathLong(conn, "number(/volume/permissions/owner)", ctxt,
&v) < 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing owner element"));
return -1;
}
perms->uid = (int)v;
}
- if (virXPathNode("/volume/permissions/group", ctxt) == NULL) {
+ if (virXPathNode(conn, "/volume/permissions/group", ctxt) == NULL) {
perms->gid = getgid();
} else {
- if (virXPathLong("number(/volume/permissions/group)", ctxt, &v)
< 0) {
+ if (virXPathLong(conn, "number(/volume/permissions/group)", ctxt,
&v) < 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing owner element"));
return -1;
@@ -557,7 +557,7 @@
}
/* NB, we're ignoring missing labels here - they'll simply inherit */
- perms->label = virXPathString("string(/volume/permissions/label)",
ctxt);
+ perms->label = virXPathString(conn, "string(/volume/permissions/label)",
ctxt);
return 0;
}
@@ -662,7 +662,7 @@
goto cleanup;
}
- ret->name = virXPathString("string(/volume/name)", ctxt);
+ ret->name = virXPathString(conn, "string(/volume/name)", ctxt);
if (ret->name == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing name element"));
@@ -670,10 +670,10 @@
}
/* Auto-generated so deliberately ignore */
- /*ret->key = virXPathString("string(/volume/key)", ctxt);*/
+ /*ret->key = virXPathString(conn, "string(/volume/key)", ctxt);*/
- capacity = virXPathString("string(/volume/capacity)", ctxt);
- unit = virXPathString("string(/volume/capacity/@unit)", ctxt);
+ capacity = virXPathString(conn, "string(/volume/capacity)", ctxt);
+ unit = virXPathString(conn, "string(/volume/capacity/@unit)", ctxt);
if (capacity == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing capacity element"));
@@ -684,9 +684,9 @@
VIR_FREE(capacity);
VIR_FREE(unit);
- allocation = virXPathString("string(/volume/allocation)", ctxt);
+ allocation = virXPathString(conn, "string(/volume/allocation)", ctxt);
if (allocation) {
- unit = virXPathString("string(/volume/allocation/@unit)", ctxt);
+ unit = virXPathString(conn, "string(/volume/allocation/@unit)", ctxt);
if (virStorageSize(conn, unit, allocation, &ret->allocation) < 0)
goto cleanup;
VIR_FREE(allocation);
@@ -695,9 +695,9 @@
ret->allocation = ret->capacity;
}
- ret->target.path = virXPathString("string(/volume/target/path)", ctxt);
+ ret->target.path = virXPathString(conn, "string(/volume/target/path)",
ctxt);
if (options->formatFromString) {
- char *format = virXPathString("string(/volume/target/format/@type)",
ctxt);
+ char *format = virXPathString(conn,
"string(/volume/target/format/@type)", ctxt);
if ((ret->target.format = (options->formatFromString)(conn, format)) <
0) {
VIR_FREE(format);
goto cleanup;
diff -r 4dbf0dba3661 src/test.c
--- a/src/test.c Thu Jul 03 16:50:15 2008 +0100
+++ b/src/test.c Thu Jul 03 16:50:19 2008 +0100
@@ -362,7 +362,7 @@
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
nodeInfo = &privconn->nodeInfo;
- ret = virXPathLong("string(/node/cpu/nodes[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/nodes[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->nodes = l;
} else if (ret == -2) {
@@ -370,7 +370,7 @@
goto error;
}
- ret = virXPathLong("string(/node/cpu/sockets[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/sockets[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->sockets = l;
} else if (ret == -2) {
@@ -378,7 +378,7 @@
goto error;
}
- ret = virXPathLong("string(/node/cpu/cores[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/cores[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->cores = l;
} else if (ret == -2) {
@@ -386,7 +386,7 @@
goto error;
}
- ret = virXPathLong("string(/node/cpu/threads[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/threads[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->threads = l;
} else if (ret == -2) {
@@ -395,7 +395,7 @@
}
nodeInfo->cpus = nodeInfo->cores * nodeInfo->threads * nodeInfo->sockets
* nodeInfo->nodes;
- ret = virXPathLong("string(/node/cpu/active[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/active[1])", ctxt, &l);
if (ret == 0) {
if (l < nodeInfo->cpus) {
nodeInfo->cpus = l;
@@ -404,7 +404,7 @@
testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node active cpu"));
goto error;
}
- ret = virXPathLong("string(/node/cpu/mhz[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/mhz[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->mhz = l;
} else if (ret == -2) {
@@ -412,14 +412,14 @@
goto error;
}
- str = virXPathString("string(/node/cpu/model[1])", ctxt);
+ str = virXPathString(conn, "string(/node/cpu/model[1])", ctxt);
if (str != NULL) {
strncpy(nodeInfo->model, str, sizeof(nodeInfo->model)-1);
nodeInfo->model[sizeof(nodeInfo->model)-1] = '\0';
VIR_FREE(str);
}
- ret = virXPathLong("string(/node/memory[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/memory[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->memory = l;
} else if (ret == -2) {
@@ -427,7 +427,7 @@
goto error;
}
- ret = virXPathNodeSet("/node/domain", ctxt, &domains);
+ ret = virXPathNodeSet(conn, "/node/domain", ctxt, &domains);
if (ret < 0) {
testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node domain list"));
goto error;
@@ -466,7 +466,7 @@
domains = NULL;
}
- ret = virXPathNodeSet("/node/network", ctxt, &networks);
+ ret = virXPathNodeSet(conn, "/node/network", ctxt, &networks);
if (ret < 0) {
testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node network
list"));
goto error;
diff -r 4dbf0dba3661 src/xml.c
--- a/src/xml.c Thu Jul 03 16:50:15 2008 +0100
+++ b/src/xml.c Thu Jul 03 16:50:19 2008 +0100
@@ -22,8 +22,6 @@
#include "buf.h"
#include "util.h"
#include "memory.h"
-#include "xend_internal.h" /* for is_sound_* functions */
-
/**
* virXMLError:
@@ -66,14 +64,16 @@
* if the evaluation failed.
*/
char *
-virXPathString(const char *xpath, xmlXPathContextPtr ctxt)
+virXPathString(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
char *ret;
if ((ctxt == NULL) || (xpath == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathString()"), 0);
return (NULL);
}
@@ -87,7 +87,7 @@
ret = strdup((char *) obj->stringval);
xmlXPathFreeObject(obj);
if (ret == NULL) {
- virXMLError(NULL, VIR_ERR_NO_MEMORY, _("strdup failed"), 0);
+ virXMLError(conn, VIR_ERR_NO_MEMORY, _("strdup failed"), 0);
}
ctxt->node = relnode;
return (ret);
@@ -105,13 +105,16 @@
* or -1 if the evaluation failed.
*/
int
-virXPathNumber(const char *xpath, xmlXPathContextPtr ctxt, double *value)
+virXPathNumber(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt,
+ double *value)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNumber()"), 0);
return (-1);
}
@@ -143,14 +146,17 @@
* value doesn't have a long format.
*/
int
-virXPathLong(const char *xpath, xmlXPathContextPtr ctxt, long *value)
+virXPathLong(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt,
+ long *value)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNumber()"), 0);
return (-1);
}
@@ -195,14 +201,17 @@
* value doesn't have a long format.
*/
int
-virXPathULong(const char *xpath, xmlXPathContextPtr ctxt, unsigned long *value)
+virXPathULong(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt,
+ unsigned long *value)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNumber()"), 0);
return (-1);
}
@@ -251,14 +260,16 @@
* Returns 0 if false, 1 if true, or -1 if the evaluation failed.
*/
int
-virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt)
+virXPathBoolean(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
int ret;
if ((ctxt == NULL) || (xpath == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathBoolean()"), 0);
return (-1);
}
@@ -287,14 +298,16 @@
* Returns a pointer to the node or NULL if the evaluation failed.
*/
xmlNodePtr
-virXPathNode(const char *xpath, xmlXPathContextPtr ctxt)
+virXPathNode(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
xmlNodePtr ret;
if ((ctxt == NULL) || (xpath == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNode()"), 0);
return (NULL);
}
@@ -326,15 +339,17 @@
* must be freed) or -1 if the evaluation failed.
*/
int
-virXPathNodeSet(const char *xpath, xmlXPathContextPtr ctxt,
- xmlNodePtr ** list)
+virXPathNodeSet(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt,
+ xmlNodePtr **list)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
int ret;
if ((ctxt == NULL) || (xpath == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNodeSet()"), 0);
return (-1);
}
@@ -354,7 +369,7 @@
ret = obj->nodesetval->nodeNr;
if (list != NULL && ret) {
if (VIR_ALLOC_N(*list, ret) < 0) {
- virXMLError(NULL, VIR_ERR_NO_MEMORY,
+ virXMLError(conn, VIR_ERR_NO_MEMORY,
_("allocate string array"),
ret * sizeof(**list));
ret = -1;
diff -r 4dbf0dba3661 src/xml.h
--- a/src/xml.h Thu Jul 03 16:50:15 2008 +0100
+++ b/src/xml.h Thu Jul 03 16:50:19 2008 +0100
@@ -11,28 +11,37 @@
#include <libxml/tree.h>
#include <libxml/xpath.h>
-int virXPathBoolean (const char *xpath,
+int virXPathBoolean (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt);
-char * virXPathString (const char *xpath,
+char * virXPathString (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt);
-int virXPathNumber (const char *xpath,
+int virXPathNumber (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
double *value);
-int virXPathInt (const char *xpath,
+int virXPathInt (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
int *value);
-int virXPathUInt (const char *xpath,
+int virXPathUInt (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
unsigned int *value);
-int virXPathLong (const char *xpath,
+int virXPathLong (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
long *value);
-int virXPathULong (const char *xpath,
+int virXPathULong (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
unsigned long *value);
-xmlNodePtr virXPathNode (const char *xpath,
+xmlNodePtr virXPathNode (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt);
-int virXPathNodeSet (const char *xpath,
+int virXPathNodeSet (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
xmlNodePtr **list);
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|