mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
util: xml: Introduce virXPathU(Int|LongLong)Base
In an effort to remove the 'Long' variants of XPath number fetching functions we need a way to replace the hex number parsing capability. The new helpers are created from the originals by adding a 'base' argument and keeping the original function as a wrapper to pass 10. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
90cb594cf6
commit
7160805e76
@ -3699,9 +3699,11 @@ virXPathNode;
|
|||||||
virXPathNodeSet;
|
virXPathNodeSet;
|
||||||
virXPathString;
|
virXPathString;
|
||||||
virXPathUInt;
|
virXPathUInt;
|
||||||
|
virXPathUIntBase;
|
||||||
virXPathULong;
|
virXPathULong;
|
||||||
virXPathULongHex;
|
virXPathULongHex;
|
||||||
virXPathULongLong;
|
virXPathULongLong;
|
||||||
|
virXPathULongLongBase;
|
||||||
|
|
||||||
|
|
||||||
# Let emacs know we want case-insensitive sorting
|
# Let emacs know we want case-insensitive sorting
|
||||||
|
@ -228,9 +228,10 @@ virXPathULongBase(const char *xpath,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXPathUInt:
|
* virXPathUIntBase:
|
||||||
* @xpath: the XPath string to evaluate
|
* @xpath: the XPath string to evaluate
|
||||||
* @ctxt: an XPath context
|
* @ctxt: an XPath context
|
||||||
|
* @base: base of the number to fetch @value as
|
||||||
* @value: the returned unsigned int value
|
* @value: the returned unsigned int value
|
||||||
*
|
*
|
||||||
* Convenience function to evaluate an XPath number. The @xpath expression
|
* Convenience function to evaluate an XPath number. The @xpath expression
|
||||||
@ -242,22 +243,32 @@ virXPathULongBase(const char *xpath,
|
|||||||
* value doesn't have an unsigned int format.
|
* value doesn't have an unsigned int format.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virXPathUInt(const char *xpath,
|
virXPathUIntBase(const char *xpath,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
unsigned int *value)
|
unsigned int base,
|
||||||
|
unsigned int *value)
|
||||||
{
|
{
|
||||||
g_autoptr(xmlXPathObject) obj = NULL;
|
g_autoptr(xmlXPathObject) obj = NULL;
|
||||||
|
|
||||||
if (!(obj = virXPathEvalString(xpath, ctxt)))
|
if (!(obj = virXPathEvalString(xpath, ctxt)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virStrToLong_ui((char *) obj->stringval, NULL, 10, value) < 0)
|
if (virStrToLong_ui((char *) obj->stringval, NULL, base, value) < 0)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virXPathUInt(const char *xpath,
|
||||||
|
xmlXPathContextPtr ctxt,
|
||||||
|
unsigned int *value)
|
||||||
|
{
|
||||||
|
return virXPathUIntBase(xpath, ctxt, 10, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXPathULong:
|
* virXPathULong:
|
||||||
* @xpath: the XPath string to evaluate
|
* @xpath: the XPath string to evaluate
|
||||||
@ -302,9 +313,10 @@ virXPathULongHex(const char *xpath,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXPathULongLong:
|
* virXPathULongLongBase:
|
||||||
* @xpath: the XPath string to evaluate
|
* @xpath: the XPath string to evaluate
|
||||||
* @ctxt: an XPath context
|
* @ctxt: an XPath context
|
||||||
|
* @base: base of the number to fetch @value as
|
||||||
* @value: the returned unsigned long long value
|
* @value: the returned unsigned long long value
|
||||||
*
|
*
|
||||||
* Convenience function to evaluate an XPath number. The @xpath expression
|
* Convenience function to evaluate an XPath number. The @xpath expression
|
||||||
@ -316,22 +328,32 @@ virXPathULongHex(const char *xpath,
|
|||||||
* value doesn't have a unsigned long long format.
|
* value doesn't have a unsigned long long format.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virXPathULongLong(const char *xpath,
|
virXPathULongLongBase(const char *xpath,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
unsigned long long *value)
|
unsigned int base,
|
||||||
|
unsigned long long *value)
|
||||||
{
|
{
|
||||||
g_autoptr(xmlXPathObject) obj = NULL;
|
g_autoptr(xmlXPathObject) obj = NULL;
|
||||||
|
|
||||||
if (!(obj = virXPathEvalString(xpath, ctxt)))
|
if (!(obj = virXPathEvalString(xpath, ctxt)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virStrToLong_ullp((char *) obj->stringval, NULL, 10, value) < 0)
|
if (virStrToLong_ullp((char *) obj->stringval, NULL, base, value) < 0)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virXPathULongLong(const char *xpath,
|
||||||
|
xmlXPathContextPtr ctxt,
|
||||||
|
unsigned long long *value)
|
||||||
|
{
|
||||||
|
return virXPathULongLongBase(xpath, ctxt, 10, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXPathLongLong:
|
* virXPathLongLong:
|
||||||
* @xpath: the XPath string to evaluate
|
* @xpath: the XPath string to evaluate
|
||||||
|
@ -51,6 +51,11 @@ virXPathInt(const char *xpath,
|
|||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
int *value);
|
int *value);
|
||||||
int
|
int
|
||||||
|
virXPathUIntBase(const char *xpath,
|
||||||
|
xmlXPathContextPtr ctxt,
|
||||||
|
unsigned int base,
|
||||||
|
unsigned int *value);
|
||||||
|
int
|
||||||
virXPathUInt(const char *xpath,
|
virXPathUInt(const char *xpath,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
unsigned int *value);
|
unsigned int *value);
|
||||||
@ -63,6 +68,11 @@ virXPathULong(const char *xpath,
|
|||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
unsigned long *value);
|
unsigned long *value);
|
||||||
int
|
int
|
||||||
|
virXPathULongLongBase(const char *xpath,
|
||||||
|
xmlXPathContextPtr ctxt,
|
||||||
|
unsigned int base,
|
||||||
|
unsigned long long *value);
|
||||||
|
int
|
||||||
virXPathULongLong(const char *xpath,
|
virXPathULongLong(const char *xpath,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
unsigned long long *value);
|
unsigned long long *value);
|
||||||
|
Loading…
Reference in New Issue
Block a user