Fix reporting of errors against virConnect object in XML apis

This commit is contained in:
Daniel P. Berrange 2008-07-25 14:27:25 +00:00
parent cb29913fb1
commit 9351cb0ab0
8 changed files with 148 additions and 116 deletions

View File

@ -1,3 +1,11 @@
Fri Jul 25 15:21:27 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/xml.c, src/xml.h: Take a virConnectPtr object as param
for all methods to allow proper error reporting.
* src/lxc_conf.c, src/domain_conf.c, src/network_conf.c,
src/storage_conf.c, src/test.c: Pass virConnect object
to XML routines
Fri Jul 25 15:03:27 BST 2008 Daniel P. Berrange <berrange@redhat.com> Fri Jul 25 15:03:27 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/xend_internal.c, src/xend_internal.h: Expose the * src/xend_internal.c, src/xend_internal.h: Expose the

View File

@ -1303,7 +1303,7 @@ static int virDomainLifecycleParseXML(virConnectPtr conn,
int *val, int *val,
int defaultVal) int defaultVal)
{ {
char *tmp = virXPathString(xpath, ctxt); char *tmp = virXPathString(conn, xpath, ctxt);
if (tmp == NULL) { if (tmp == NULL) {
*val = defaultVal; *val = defaultVal;
} else { } else {
@ -1397,7 +1397,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
def->id = -1; def->id = -1;
/* Find out what type of QEMU virtualization to use */ /* 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("missing domain type attribute")); "%s", _("missing domain type attribute"));
goto error; goto error;
@ -1411,13 +1411,13 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE(tmp); VIR_FREE(tmp);
/* Extract domain name */ /* 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); virDomainReportError(conn, VIR_ERR_NO_NAME, NULL);
goto error; goto error;
} }
/* Extract domain uuid */ /* Extract domain uuid */
tmp = virXPathString("string(./uuid[1])", ctxt); tmp = virXPathString(conn, "string(./uuid[1])", ctxt);
if (!tmp) { if (!tmp) {
int err; int err;
if ((err = virUUIDGenerate(def->uuid))) { if ((err = virUUIDGenerate(def->uuid))) {
@ -1436,19 +1436,19 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
} }
/* Extract domain memory */ /* 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("missing memory element")); "%s", _("missing memory element"));
goto error; 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; 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; def->vcpus = 1;
tmp = virXPathString("string(./vcpu[1]/@cpuset)", ctxt); tmp = virXPathString(conn, "string(./vcpu[1]/@cpuset)", ctxt);
if (tmp) { if (tmp) {
char *set = tmp; char *set = tmp;
def->cpumasklen = VIR_DOMAIN_CPUMASK_LEN; def->cpumasklen = VIR_DOMAIN_CPUMASK_LEN;
@ -1463,7 +1463,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE(tmp); VIR_FREE(tmp);
} }
if ((n = virXPathNodeSet("./features/*", ctxt, &nodes)) > 0) { if ((n = virXPathNodeSet(conn, "./features/*", ctxt, &nodes)) > 0) {
for (i = 0 ; i < n ; i++) { for (i = 0 ; i < n ; i++) {
int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name); int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name);
if (val < 0) { if (val < 0) {
@ -1490,15 +1490,15 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
goto error; goto error;
tmp = virXPathString("string(./clock/@offset)", ctxt); tmp = virXPathString(conn, "string(./clock/@offset)", ctxt);
if (tmp && STREQ(tmp, "localtime")) if (tmp && STREQ(tmp, "localtime"))
def->localtime = 1; def->localtime = 1;
VIR_FREE(tmp); VIR_FREE(tmp);
def->os.bootloader = virXPathString("string(./bootloader)", ctxt); def->os.bootloader = virXPathString(conn, "string(./bootloader)", ctxt);
def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", 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.type) {
if (def->os.bootloader) { if (def->os.bootloader) {
def->os.type = strdup("xen"); def->os.type = strdup("xen");
@ -1532,7 +1532,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
goto error; 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) { if (!def->os.arch) {
const char *defaultArch = virCapabilitiesDefaultGuestArch(caps, def->os.type); const char *defaultArch = virCapabilitiesDefaultGuestArch(caps, def->os.type);
if (defaultArch == NULL) { if (defaultArch == NULL) {
@ -1547,7 +1547,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
} }
} }
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) { if (!def->os.machine) {
const char *defaultMachine = virCapabilitiesDefaultGuestMachine(caps, const char *defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
def->os.type, def->os.type,
@ -1561,14 +1561,14 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
} }
if (!def->os.bootloader) { if (!def->os.bootloader) {
def->os.kernel = virXPathString("string(./os/kernel[1])", ctxt); def->os.kernel = virXPathString(conn, "string(./os/kernel[1])", ctxt);
def->os.initrd = virXPathString("string(./os/initrd[1])", ctxt); def->os.initrd = virXPathString(conn, "string(./os/initrd[1])", ctxt);
def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt); def->os.cmdline = virXPathString(conn, "string(./os/cmdline[1])", ctxt);
def->os.root = virXPathString("string(./os/root[1])", ctxt); def->os.root = virXPathString(conn, "string(./os/root[1])", ctxt);
def->os.loader = virXPathString("string(./os/loader[1])", ctxt); def->os.loader = virXPathString(conn, "string(./os/loader[1])", ctxt);
/* analysis of the boot devices */ /* 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract boot device")); "%s", _("cannot extract boot device"));
goto error; goto error;
@ -1598,7 +1598,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE(nodes); VIR_FREE(nodes);
} }
def->emulator = virXPathString("string(./devices/emulator[1])", ctxt); def->emulator = virXPathString(conn, "string(./devices/emulator[1])", ctxt);
if (!def->emulator) { if (!def->emulator) {
const char *type = virDomainVirtTypeToString(def->virtType); const char *type = virDomainVirtTypeToString(def->virtType);
if (!type) { if (!type) {
@ -1622,7 +1622,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
} }
/* analysis of the disk devices */ /* 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract disk devices")); "%s", _("cannot extract disk devices"));
goto error; goto error;
@ -1652,7 +1652,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE(nodes); VIR_FREE(nodes);
/* analysis of the network devices */ /* 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract network devices")); "%s", _("cannot extract network devices"));
goto error; goto error;
@ -1670,7 +1670,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
/* analysis of the character devices */ /* 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract parallel devices")); "%s", _("cannot extract parallel devices"));
goto error; goto error;
@ -1687,7 +1687,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
} }
VIR_FREE(nodes); 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract serial devices")); "%s", _("cannot extract serial devices"));
goto error; goto error;
@ -1709,7 +1709,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
* devices which is the legacy syntax for the same thing * devices which is the legacy syntax for the same thing
*/ */
if (def->serials == NULL) { 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, virDomainChrDefPtr chr = virDomainChrDefParseXML(conn,
node); node);
if (!chr) if (!chr)
@ -1731,7 +1731,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
/* analysis of the input devices */ /* 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract input devices")); "%s", _("cannot extract input devices"));
goto error; goto error;
@ -1763,7 +1763,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE(nodes); VIR_FREE(nodes);
/* analysis of the input devices */ /* 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract graphics devices")); "%s", _("cannot extract graphics devices"));
goto error; goto error;
@ -1799,7 +1799,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
/* analysis of the sound devices */ /* 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, virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract sound devices")); "%s", _("cannot extract sound devices"));
goto error; goto error;

View File

@ -210,7 +210,7 @@ static int lxcParseDomainInterfaces(virConnectPtr conn,
DEBUG0("parsing nets"); DEBUG0("parsing nets");
res = virXPathNodeSet("/domain/devices/interface", contextPtr, &list); res = virXPathNodeSet(conn, "/domain/devices/interface", contextPtr, &list);
if (res > 0) { if (res > 0) {
for (i = 0; i < res; ++i) { for (i = 0; i < res; ++i) {
netDef = calloc(1, sizeof(lxc_net_def_t)); netDef = calloc(1, sizeof(lxc_net_def_t));
@ -338,7 +338,7 @@ static int lxcParseDomainName(virConnectPtr conn, char **name,
{ {
char *res; char *res;
res = virXPathString("string(/domain/name[1])", contextPtr); res = virXPathString(conn, "string(/domain/name[1])", contextPtr);
if (res == NULL) { if (res == NULL) {
lxcError(conn, NULL, VIR_ERR_NO_NAME, NULL); lxcError(conn, NULL, VIR_ERR_NO_NAME, NULL);
return(-1); return(-1);
@ -353,7 +353,7 @@ static int lxcParseDomainUUID(virConnectPtr conn, unsigned char *uuid,
{ {
char *res; char *res;
res = virXPathString("string(/domain/uuid[1])", contextPtr); res = virXPathString(conn, "string(/domain/uuid[1])", contextPtr);
if (res == NULL) { if (res == NULL) {
if (virUUIDGenerate(uuid)) { if (virUUIDGenerate(uuid)) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
@ -384,7 +384,7 @@ static int lxcParseDomainMounts(virConnectPtr conn,
xmlNodePtr *list; xmlNodePtr *list;
int res; int res;
res = virXPathNodeSet("/domain/devices/filesystem", contextPtr, &list); res = virXPathNodeSet(conn, "/domain/devices/filesystem", contextPtr, &list);
if (res > 0) { if (res > 0) {
for (i = 0; i < res; ++i) { for (i = 0; i < res; ++i) {
if (VIR_ALLOC(mountObj) < 0) { if (VIR_ALLOC(mountObj) < 0) {
@ -422,7 +422,7 @@ static int lxcParseDomainInit(virConnectPtr conn, char** init,
{ {
char *res; char *res;
res = virXPathString("string(/domain/os/init[1])", contextPtr); res = virXPathString(conn, "string(/domain/os/init[1])", contextPtr);
if (res == NULL) { if (res == NULL) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
_("invalid or missing init element")); _("invalid or missing init element"));
@ -446,7 +446,7 @@ static int lxcParseDomainTty(virConnectPtr conn, char **tty, xmlXPathContextPtr
{ {
char *res; char *res;
res = virXPathString("string(/domain/devices/console[1]/@tty)", contextPtr); res = virXPathString(conn, "string(/domain/devices/console[1]/@tty)", contextPtr);
if (res == NULL) { if (res == NULL) {
/* make sure the tty string is empty */ /* make sure the tty string is empty */
*tty = strdup(""); *tty = strdup("");
@ -466,7 +466,7 @@ static int lxcParseDomainMemory(virConnectPtr conn, int* memory, xmlXPathContext
long res; long res;
int rc; 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))) { if ((rc == -2) || ((rc == 0) && (res <= 0))) {
*memory = -1; *memory = -1;
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,

View File

@ -243,14 +243,14 @@ virNetworkDefParseXML(virConnectPtr conn,
} }
/* Extract network name */ /* Extract network name */
def->name = virXPathString("string(./name[1])", ctxt); def->name = virXPathString(conn, "string(./name[1])", ctxt);
if (!def->name) { if (!def->name) {
virNetworkReportError(conn, VIR_ERR_NO_NAME, NULL); virNetworkReportError(conn, VIR_ERR_NO_NAME, NULL);
goto error; goto error;
} }
/* Extract network uuid */ /* Extract network uuid */
tmp = virXPathString("string(./uuid[1])", ctxt); tmp = virXPathString(conn, "string(./uuid[1])", ctxt);
if (!tmp) { if (!tmp) {
int err; int err;
if ((err = virUUIDGenerate(def->uuid))) { if ((err = virUUIDGenerate(def->uuid))) {
@ -269,16 +269,16 @@ virNetworkDefParseXML(virConnectPtr conn,
} }
/* Parse bridge information */ /* Parse bridge information */
def->bridge = virXPathString("string(./bridge[1]/@name)", ctxt); def->bridge = virXPathString(conn, "string(./bridge[1]/@name)", ctxt);
tmp = virXPathString("string(./bridge[1]/@stp)", ctxt); tmp = virXPathString(conn, "string(./bridge[1]/@stp)", ctxt);
def->stp = (tmp && STREQ(tmp, "off")) ? 0 : 1; def->stp = (tmp && STREQ(tmp, "off")) ? 0 : 1;
VIR_FREE(tmp); 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->delay = 0;
def->ipAddress = virXPathString("string(./ip[1]/@address)", ctxt); def->ipAddress = virXPathString(conn, "string(./ip[1]/@address)", ctxt);
def->netmask = virXPathString("string(./ip[1]/@netmask)", ctxt); def->netmask = virXPathString(conn, "string(./ip[1]/@netmask)", ctxt);
if (def->ipAddress && if (def->ipAddress &&
def->netmask) { def->netmask) {
/* XXX someday we want IPv6 too, so inet_aton won't work there */ /* XXX someday we want IPv6 too, so inet_aton won't work there */
@ -307,14 +307,14 @@ virNetworkDefParseXML(virConnectPtr conn,
goto error; goto error;
} }
if ((dhcp = virXPathNode("./ip[1]/dhcp[1]", ctxt)) && if ((dhcp = virXPathNode(conn, "./ip[1]/dhcp[1]", ctxt)) &&
virNetworkDHCPRangeDefParseXML(conn, def, dhcp) < 0) virNetworkDHCPRangeDefParseXML(conn, def, dhcp) < 0)
goto error; goto error;
} }
/* IPv4 forwarding setup */ /* IPv4 forwarding setup */
if (virXPathBoolean("count(./forward) > 0", ctxt)) { if (virXPathBoolean(conn, "count(./forward) > 0", ctxt)) {
if (!def->ipAddress || if (!def->ipAddress ||
!def->netmask) { !def->netmask) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
@ -322,7 +322,7 @@ virNetworkDefParseXML(virConnectPtr conn,
goto error; goto error;
} }
tmp = virXPathString("string(./forward[1]/@mode)", ctxt); tmp = virXPathString(conn, "string(./forward[1]/@mode)", ctxt);
if (tmp) { if (tmp) {
if ((def->forwardType = virNetworkForwardTypeFromString(tmp)) < 0) { if ((def->forwardType = virNetworkForwardTypeFromString(tmp)) < 0) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
@ -336,7 +336,7 @@ virNetworkDefParseXML(virConnectPtr conn,
} }
def->forwardDev = virXPathString("string(./forward[1]/@dev)", ctxt); def->forwardDev = virXPathString(conn, "string(./forward[1]/@dev)", ctxt);
} else { } else {
def->forwardType = VIR_NETWORK_FORWARD_NONE; def->forwardType = VIR_NETWORK_FORWARD_NONE;
} }

View File

@ -149,14 +149,14 @@ static int
virStoragePoolDefParseAuthChap(virConnectPtr conn, virStoragePoolDefParseAuthChap(virConnectPtr conn,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
virStoragePoolAuthChapPtr auth) { 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) { if (auth->login == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing auth host attribute")); "%s", _("missing auth host attribute"));
return -1; 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) { if (auth->passwd == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing auth passwd attribute")); "%s", _("missing auth passwd attribute"));
@ -174,7 +174,7 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
char *mode; char *mode;
long v; long v;
mode = virXPathString("string(/pool/permissions/mode)", ctxt); mode = virXPathString(conn, "string(/pool/permissions/mode)", ctxt);
if (!mode) { if (!mode) {
perms->mode = 0700; perms->mode = 0700;
} else { } else {
@ -187,10 +187,10 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
} }
} }
if (virXPathNode("/pool/permissions/owner", ctxt) == NULL) { if (virXPathNode(conn, "/pool/permissions/owner", ctxt) == NULL) {
perms->uid = getuid(); perms->uid = getuid();
} else { } 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, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("malformed owner element")); "%s", _("malformed owner element"));
return -1; return -1;
@ -198,10 +198,10 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
perms->uid = (int)v; perms->uid = (int)v;
} }
if (virXPathNode("/pool/permissions/group", ctxt) == NULL) { if (virXPathNode(conn, "/pool/permissions/group", ctxt) == NULL) {
perms->uid = getgid(); perms->uid = getgid();
} else { } 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, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("malformed group element")); "%s", _("malformed group element"));
return -1; return -1;
@ -210,7 +210,7 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
} }
/* NB, we're ignoring missing labels here - they'll simply inherit */ /* 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; return 0;
} }
@ -248,13 +248,13 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
goto cleanup; 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, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing name element")); "%s", _("missing name element"));
goto cleanup; goto cleanup;
} }
uuid = virXPathString("string(/pool/uuid)", ctxt); uuid = virXPathString(conn, "string(/pool/uuid)", ctxt);
if (uuid == NULL) { if (uuid == NULL) {
if (virUUIDGenerate(ret->uuid) < 0) { if (virUUIDGenerate(ret->uuid) < 0) {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
@ -271,7 +271,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
} }
if (options->formatFromString) { 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) { if ((ret->source.format = (options->formatFromString)(conn, format)) < 0) {
VIR_FREE(format); VIR_FREE(format);
goto cleanup; goto cleanup;
@ -280,7 +280,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
} }
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) { 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, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing source host name")); "%s", _("missing source host name"));
goto cleanup; goto cleanup;
@ -290,7 +290,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
xmlNodePtr *nodeset = NULL; xmlNodePtr *nodeset = NULL;
int nsource, i; 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, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("cannot extract source devices")); "%s", _("cannot extract source devices"));
goto cleanup; goto cleanup;
@ -314,7 +314,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
ret->source.ndevice = nsource; ret->source.ndevice = nsource;
} }
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) { 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, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing source path")); "%s", _("missing source path"));
goto cleanup; goto cleanup;
@ -322,7 +322,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
} }
authType = virXPathString("string(/pool/source/auth/@type)", ctxt); authType = virXPathString(conn, "string(/pool/source/auth/@type)", ctxt);
if (authType == NULL) { if (authType == NULL) {
ret->source.authType = VIR_STORAGE_POOL_AUTH_NONE; ret->source.authType = VIR_STORAGE_POOL_AUTH_NONE;
} else { } else {
@ -343,7 +343,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
goto cleanup; 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, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing target path")); "%s", _("missing target path"));
goto cleanup; goto cleanup;
@ -522,7 +522,7 @@ virStorageVolDefParsePerms(virConnectPtr conn,
char *mode; char *mode;
long v; long v;
mode = virXPathString("string(/volume/permissions/mode)", ctxt); mode = virXPathString(conn, "string(/volume/permissions/mode)", ctxt);
if (!mode) { if (!mode) {
perms->mode = 0600; perms->mode = 0600;
} else { } else {
@ -535,20 +535,20 @@ virStorageVolDefParsePerms(virConnectPtr conn,
} }
} }
if (virXPathNode("/volume/permissions/owner", ctxt) == NULL) { if (virXPathNode(conn, "/volume/permissions/owner", ctxt) == NULL) {
perms->uid = getuid(); perms->uid = getuid();
} else { } 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, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing owner element")); "%s", _("missing owner element"));
return -1; return -1;
} }
perms->uid = (int)v; perms->uid = (int)v;
} }
if (virXPathNode("/volume/permissions/group", ctxt) == NULL) { if (virXPathNode(conn, "/volume/permissions/group", ctxt) == NULL) {
perms->gid = getgid(); perms->gid = getgid();
} else { } 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, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing owner element")); "%s", _("missing owner element"));
return -1; return -1;
@ -557,7 +557,7 @@ virStorageVolDefParsePerms(virConnectPtr conn,
} }
/* NB, we're ignoring missing labels here - they'll simply inherit */ /* 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; return 0;
} }
@ -662,7 +662,7 @@ virStorageVolDefParseDoc(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
ret->name = virXPathString("string(/volume/name)", ctxt); ret->name = virXPathString(conn, "string(/volume/name)", ctxt);
if (ret->name == NULL) { if (ret->name == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing name element")); "%s", _("missing name element"));
@ -670,10 +670,10 @@ virStorageVolDefParseDoc(virConnectPtr conn,
} }
/* Auto-generated so deliberately ignore */ /* 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); capacity = virXPathString(conn, "string(/volume/capacity)", ctxt);
unit = virXPathString("string(/volume/capacity/@unit)", ctxt); unit = virXPathString(conn, "string(/volume/capacity/@unit)", ctxt);
if (capacity == NULL) { if (capacity == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR, virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing capacity element")); "%s", _("missing capacity element"));
@ -684,9 +684,9 @@ virStorageVolDefParseDoc(virConnectPtr conn,
VIR_FREE(capacity); VIR_FREE(capacity);
VIR_FREE(unit); VIR_FREE(unit);
allocation = virXPathString("string(/volume/allocation)", ctxt); allocation = virXPathString(conn, "string(/volume/allocation)", ctxt);
if (allocation) { 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) if (virStorageSize(conn, unit, allocation, &ret->allocation) < 0)
goto cleanup; goto cleanup;
VIR_FREE(allocation); VIR_FREE(allocation);
@ -695,9 +695,9 @@ virStorageVolDefParseDoc(virConnectPtr conn,
ret->allocation = ret->capacity; 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) { 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) { if ((ret->target.format = (options->formatFromString)(conn, format)) < 0) {
VIR_FREE(format); VIR_FREE(format);
goto cleanup; goto cleanup;

View File

@ -362,7 +362,7 @@ static int testOpenFromFile(virConnectPtr conn,
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo)); memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
nodeInfo = &privconn->nodeInfo; 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) { if (ret == 0) {
nodeInfo->nodes = l; nodeInfo->nodes = l;
} else if (ret == -2) { } else if (ret == -2) {
@ -370,7 +370,7 @@ static int testOpenFromFile(virConnectPtr conn,
goto error; goto error;
} }
ret = virXPathLong("string(/node/cpu/sockets[1])", ctxt, &l); ret = virXPathLong(conn, "string(/node/cpu/sockets[1])", ctxt, &l);
if (ret == 0) { if (ret == 0) {
nodeInfo->sockets = l; nodeInfo->sockets = l;
} else if (ret == -2) { } else if (ret == -2) {
@ -378,7 +378,7 @@ static int testOpenFromFile(virConnectPtr conn,
goto error; goto error;
} }
ret = virXPathLong("string(/node/cpu/cores[1])", ctxt, &l); ret = virXPathLong(conn, "string(/node/cpu/cores[1])", ctxt, &l);
if (ret == 0) { if (ret == 0) {
nodeInfo->cores = l; nodeInfo->cores = l;
} else if (ret == -2) { } else if (ret == -2) {
@ -386,7 +386,7 @@ static int testOpenFromFile(virConnectPtr conn,
goto error; goto error;
} }
ret = virXPathLong("string(/node/cpu/threads[1])", ctxt, &l); ret = virXPathLong(conn, "string(/node/cpu/threads[1])", ctxt, &l);
if (ret == 0) { if (ret == 0) {
nodeInfo->threads = l; nodeInfo->threads = l;
} else if (ret == -2) { } else if (ret == -2) {
@ -395,7 +395,7 @@ static int testOpenFromFile(virConnectPtr conn,
} }
nodeInfo->cpus = nodeInfo->cores * nodeInfo->threads * nodeInfo->sockets * nodeInfo->nodes; 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 (ret == 0) {
if (l < nodeInfo->cpus) { if (l < nodeInfo->cpus) {
nodeInfo->cpus = l; nodeInfo->cpus = l;
@ -404,7 +404,7 @@ static int testOpenFromFile(virConnectPtr conn,
testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node active cpu")); testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node active cpu"));
goto error; goto error;
} }
ret = virXPathLong("string(/node/cpu/mhz[1])", ctxt, &l); ret = virXPathLong(conn, "string(/node/cpu/mhz[1])", ctxt, &l);
if (ret == 0) { if (ret == 0) {
nodeInfo->mhz = l; nodeInfo->mhz = l;
} else if (ret == -2) { } else if (ret == -2) {
@ -412,14 +412,14 @@ static int testOpenFromFile(virConnectPtr conn,
goto error; goto error;
} }
str = virXPathString("string(/node/cpu/model[1])", ctxt); str = virXPathString(conn, "string(/node/cpu/model[1])", ctxt);
if (str != NULL) { if (str != NULL) {
strncpy(nodeInfo->model, str, sizeof(nodeInfo->model)-1); strncpy(nodeInfo->model, str, sizeof(nodeInfo->model)-1);
nodeInfo->model[sizeof(nodeInfo->model)-1] = '\0'; nodeInfo->model[sizeof(nodeInfo->model)-1] = '\0';
VIR_FREE(str); VIR_FREE(str);
} }
ret = virXPathLong("string(/node/memory[1])", ctxt, &l); ret = virXPathLong(conn, "string(/node/memory[1])", ctxt, &l);
if (ret == 0) { if (ret == 0) {
nodeInfo->memory = l; nodeInfo->memory = l;
} else if (ret == -2) { } else if (ret == -2) {
@ -427,7 +427,7 @@ static int testOpenFromFile(virConnectPtr conn,
goto error; goto error;
} }
ret = virXPathNodeSet("/node/domain", ctxt, &domains); ret = virXPathNodeSet(conn, "/node/domain", ctxt, &domains);
if (ret < 0) { if (ret < 0) {
testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node domain list")); testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node domain list"));
goto error; goto error;
@ -464,7 +464,7 @@ static int testOpenFromFile(virConnectPtr conn,
if (domains != NULL) if (domains != NULL)
VIR_FREE(domains); VIR_FREE(domains);
ret = virXPathNodeSet("/node/network", ctxt, &networks); ret = virXPathNodeSet(conn, "/node/network", ctxt, &networks);
if (ret < 0) { if (ret < 0) {
testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node network list")); testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node network list"));
goto error; goto error;

View File

@ -22,8 +22,6 @@
#include "buf.h" #include "buf.h"
#include "util.h" #include "util.h"
#include "memory.h" #include "memory.h"
#include "xend_internal.h" /* for is_sound_* functions */
/** /**
* virXMLError: * virXMLError:
@ -66,14 +64,16 @@ virXMLError(virConnectPtr conn, virErrorNumber error, const char *info,
* if the evaluation failed. * if the evaluation failed.
*/ */
char * char *
virXPathString(const char *xpath, xmlXPathContextPtr ctxt) virXPathString(virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt)
{ {
xmlXPathObjectPtr obj; xmlXPathObjectPtr obj;
xmlNodePtr relnode; xmlNodePtr relnode;
char *ret; char *ret;
if ((ctxt == NULL) || (xpath == NULL)) { if ((ctxt == NULL) || (xpath == NULL)) {
virXMLError(NULL, VIR_ERR_INTERNAL_ERROR, virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathString()"), 0); _("Invalid parameter to virXPathString()"), 0);
return (NULL); return (NULL);
} }
@ -87,7 +87,7 @@ virXPathString(const char *xpath, xmlXPathContextPtr ctxt)
ret = strdup((char *) obj->stringval); ret = strdup((char *) obj->stringval);
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
if (ret == NULL) { if (ret == NULL) {
virXMLError(NULL, VIR_ERR_NO_MEMORY, _("strdup failed"), 0); virXMLError(conn, VIR_ERR_NO_MEMORY, _("strdup failed"), 0);
} }
ctxt->node = relnode; ctxt->node = relnode;
return (ret); return (ret);
@ -105,13 +105,16 @@ virXPathString(const char *xpath, xmlXPathContextPtr ctxt)
* or -1 if the evaluation failed. * or -1 if the evaluation failed.
*/ */
int int
virXPathNumber(const char *xpath, xmlXPathContextPtr ctxt, double *value) virXPathNumber(virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt,
double *value)
{ {
xmlXPathObjectPtr obj; xmlXPathObjectPtr obj;
xmlNodePtr relnode; xmlNodePtr relnode;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) { if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
virXMLError(NULL, VIR_ERR_INTERNAL_ERROR, virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNumber()"), 0); _("Invalid parameter to virXPathNumber()"), 0);
return (-1); return (-1);
} }
@ -143,14 +146,17 @@ virXPathNumber(const char *xpath, xmlXPathContextPtr ctxt, double *value)
* value doesn't have a long format. * value doesn't have a long format.
*/ */
int int
virXPathLong(const char *xpath, xmlXPathContextPtr ctxt, long *value) virXPathLong(virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt,
long *value)
{ {
xmlXPathObjectPtr obj; xmlXPathObjectPtr obj;
xmlNodePtr relnode; xmlNodePtr relnode;
int ret = 0; int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) { if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
virXMLError(NULL, VIR_ERR_INTERNAL_ERROR, virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNumber()"), 0); _("Invalid parameter to virXPathNumber()"), 0);
return (-1); return (-1);
} }
@ -195,14 +201,17 @@ virXPathLong(const char *xpath, xmlXPathContextPtr ctxt, long *value)
* value doesn't have a long format. * value doesn't have a long format.
*/ */
int int
virXPathULong(const char *xpath, xmlXPathContextPtr ctxt, unsigned long *value) virXPathULong(virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt,
unsigned long *value)
{ {
xmlXPathObjectPtr obj; xmlXPathObjectPtr obj;
xmlNodePtr relnode; xmlNodePtr relnode;
int ret = 0; int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) { if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
virXMLError(NULL, VIR_ERR_INTERNAL_ERROR, virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNumber()"), 0); _("Invalid parameter to virXPathNumber()"), 0);
return (-1); return (-1);
} }
@ -251,14 +260,16 @@ virXMLPropString(xmlNodePtr node,
* Returns 0 if false, 1 if true, or -1 if the evaluation failed. * Returns 0 if false, 1 if true, or -1 if the evaluation failed.
*/ */
int int
virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt) virXPathBoolean(virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt)
{ {
xmlXPathObjectPtr obj; xmlXPathObjectPtr obj;
xmlNodePtr relnode; xmlNodePtr relnode;
int ret; int ret;
if ((ctxt == NULL) || (xpath == NULL)) { if ((ctxt == NULL) || (xpath == NULL)) {
virXMLError(NULL, VIR_ERR_INTERNAL_ERROR, virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathBoolean()"), 0); _("Invalid parameter to virXPathBoolean()"), 0);
return (-1); return (-1);
} }
@ -287,14 +298,16 @@ virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt)
* Returns a pointer to the node or NULL if the evaluation failed. * Returns a pointer to the node or NULL if the evaluation failed.
*/ */
xmlNodePtr xmlNodePtr
virXPathNode(const char *xpath, xmlXPathContextPtr ctxt) virXPathNode(virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt)
{ {
xmlXPathObjectPtr obj; xmlXPathObjectPtr obj;
xmlNodePtr relnode; xmlNodePtr relnode;
xmlNodePtr ret; xmlNodePtr ret;
if ((ctxt == NULL) || (xpath == NULL)) { if ((ctxt == NULL) || (xpath == NULL)) {
virXMLError(NULL, VIR_ERR_INTERNAL_ERROR, virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNode()"), 0); _("Invalid parameter to virXPathNode()"), 0);
return (NULL); return (NULL);
} }
@ -326,15 +339,17 @@ virXPathNode(const char *xpath, xmlXPathContextPtr ctxt)
* must be freed) or -1 if the evaluation failed. * must be freed) or -1 if the evaluation failed.
*/ */
int int
virXPathNodeSet(const char *xpath, xmlXPathContextPtr ctxt, virXPathNodeSet(virConnectPtr conn,
xmlNodePtr ** list) const char *xpath,
xmlXPathContextPtr ctxt,
xmlNodePtr **list)
{ {
xmlXPathObjectPtr obj; xmlXPathObjectPtr obj;
xmlNodePtr relnode; xmlNodePtr relnode;
int ret; int ret;
if ((ctxt == NULL) || (xpath == NULL)) { if ((ctxt == NULL) || (xpath == NULL)) {
virXMLError(NULL, VIR_ERR_INTERNAL_ERROR, virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNodeSet()"), 0); _("Invalid parameter to virXPathNodeSet()"), 0);
return (-1); return (-1);
} }
@ -354,7 +369,7 @@ virXPathNodeSet(const char *xpath, xmlXPathContextPtr ctxt,
ret = obj->nodesetval->nodeNr; ret = obj->nodesetval->nodeNr;
if (list != NULL && ret) { if (list != NULL && ret) {
if (VIR_ALLOC_N(*list, ret) < 0) { if (VIR_ALLOC_N(*list, ret) < 0) {
virXMLError(NULL, VIR_ERR_NO_MEMORY, virXMLError(conn, VIR_ERR_NO_MEMORY,
_("allocate string array"), _("allocate string array"),
ret * sizeof(**list)); ret * sizeof(**list));
ret = -1; ret = -1;

View File

@ -11,28 +11,37 @@
#include <libxml/tree.h> #include <libxml/tree.h>
#include <libxml/xpath.h> #include <libxml/xpath.h>
int virXPathBoolean (const char *xpath, int virXPathBoolean (virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt); xmlXPathContextPtr ctxt);
char * virXPathString (const char *xpath, char * virXPathString (virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt); xmlXPathContextPtr ctxt);
int virXPathNumber (const char *xpath, int virXPathNumber (virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
double *value); double *value);
int virXPathInt (const char *xpath, int virXPathInt (virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
int *value); int *value);
int virXPathUInt (const char *xpath, int virXPathUInt (virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
unsigned int *value); unsigned int *value);
int virXPathLong (const char *xpath, int virXPathLong (virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
long *value); long *value);
int virXPathULong (const char *xpath, int virXPathULong (virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
unsigned long *value); unsigned long *value);
xmlNodePtr virXPathNode (const char *xpath, xmlNodePtr virXPathNode (virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt); xmlXPathContextPtr ctxt);
int virXPathNodeSet (const char *xpath, int virXPathNodeSet (virConnectPtr conn,
const char *xpath,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
xmlNodePtr **list); xmlNodePtr **list);