mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: introduce virXMLPropStringLimit
The virXMLPropStringLimit is an equivalent of virXPathStringLimit which should be preferred if you already have a XML dom node or if you need to parse more than one property. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
361ff0a088
commit
827cf58d50
@ -2960,6 +2960,7 @@ virXMLNodeToString;
|
|||||||
virXMLParseHelper;
|
virXMLParseHelper;
|
||||||
virXMLPickShellSafeComment;
|
virXMLPickShellSafeComment;
|
||||||
virXMLPropString;
|
virXMLPropString;
|
||||||
|
virXMLPropStringLimit;
|
||||||
virXMLSaveFile;
|
virXMLSaveFile;
|
||||||
virXMLValidateAgainstSchema;
|
virXMLValidateAgainstSchema;
|
||||||
virXMLValidatorFree;
|
virXMLValidatorFree;
|
||||||
|
@ -92,6 +92,24 @@ virXPathString(const char *xpath,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *
|
||||||
|
virXMLStringLimitInternal(char *value,
|
||||||
|
size_t maxlen,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
if (value != NULL && strlen(value) >= maxlen) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("'%s' value longer than '%zu' bytes"),
|
||||||
|
name, maxlen);
|
||||||
|
VIR_FREE(value);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXPathStringLimit:
|
* virXPathStringLimit:
|
||||||
* @xpath: the XPath string to evaluate
|
* @xpath: the XPath string to evaluate
|
||||||
@ -111,15 +129,7 @@ virXPathStringLimit(const char *xpath,
|
|||||||
{
|
{
|
||||||
char *tmp = virXPathString(xpath, ctxt);
|
char *tmp = virXPathString(xpath, ctxt);
|
||||||
|
|
||||||
if (tmp != NULL && strlen(tmp) >= maxlen) {
|
return virXMLStringLimitInternal(tmp, maxlen, xpath);
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("\'%s\' value longer than %zu bytes"),
|
|
||||||
xpath, maxlen);
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -506,6 +516,30 @@ virXMLPropString(xmlNodePtr node,
|
|||||||
return (char *)xmlGetProp(node, BAD_CAST name);
|
return (char *)xmlGetProp(node, BAD_CAST name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virXMLPropStringLimit:
|
||||||
|
* @node: XML dom node pointer
|
||||||
|
* @name: Name of the property (attribute) to get
|
||||||
|
* @maxlen: maximum permitted length of the string
|
||||||
|
*
|
||||||
|
* Wrapper for virXMLPropString, which validates the length of the returned
|
||||||
|
* string.
|
||||||
|
*
|
||||||
|
* Returns a new string which must be deallocated by the caller or NULL if
|
||||||
|
* the evaluation failed.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
virXMLPropStringLimit(xmlNodePtr node,
|
||||||
|
const char *name,
|
||||||
|
size_t maxlen)
|
||||||
|
{
|
||||||
|
char *tmp = (char *)xmlGetProp(node, BAD_CAST name);
|
||||||
|
|
||||||
|
return virXMLStringLimitInternal(tmp, maxlen, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXPathBoolean:
|
* virXPathBoolean:
|
||||||
* @xpath: the XPath string to evaluate
|
* @xpath: the XPath string to evaluate
|
||||||
|
@ -73,6 +73,9 @@ int virXPathNodeSet(const char *xpath,
|
|||||||
xmlNodePtr **list);
|
xmlNodePtr **list);
|
||||||
char * virXMLPropString(xmlNodePtr node,
|
char * virXMLPropString(xmlNodePtr node,
|
||||||
const char *name);
|
const char *name);
|
||||||
|
char * virXMLPropStringLimit(xmlNodePtr node,
|
||||||
|
const char *name,
|
||||||
|
size_t maxlen);
|
||||||
long virXMLChildElementCount(xmlNodePtr node);
|
long virXMLChildElementCount(xmlNodePtr node);
|
||||||
|
|
||||||
/* Internal function; prefer the macros below. */
|
/* Internal function; prefer the macros below. */
|
||||||
|
Loading…
Reference in New Issue
Block a user