mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
virxml: Add function to check if string contains some illegal chars
This new function can be used to check if e.g. name of XML node don't contains forbidden chars like "/" or "\n". Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
5f2a132786
commit
7a2216460f
@ -2676,6 +2676,7 @@ virUUIDParse;
|
|||||||
|
|
||||||
|
|
||||||
# util/virxml.h
|
# util/virxml.h
|
||||||
|
virXMLCheckIllegalChars;
|
||||||
virXMLChildElementCount;
|
virXMLChildElementCount;
|
||||||
virXMLExtractNamespaceXML;
|
virXMLExtractNamespaceXML;
|
||||||
virXMLNodeSanitizeNamespaces;
|
virXMLNodeSanitizeNamespaces;
|
||||||
|
@ -462,6 +462,33 @@ virXPathLongLong(const char *xpath,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virXMLCheckIllegalChars:
|
||||||
|
* @nodeName: Name of checked node
|
||||||
|
* @str: string to check
|
||||||
|
* @illegal: illegal chars to check
|
||||||
|
*
|
||||||
|
* If string contains any of illegal chars VIR_ERR_XML_DETAIL error will be
|
||||||
|
* reported.
|
||||||
|
*
|
||||||
|
* Returns: 0 if string don't contains any of given characters, -1 otherwise
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virXMLCheckIllegalChars(const char *nodeName,
|
||||||
|
const char *str,
|
||||||
|
const char *illegal)
|
||||||
|
{
|
||||||
|
char *c;
|
||||||
|
if ((c = strpbrk(str, illegal))) {
|
||||||
|
virReportError(VIR_ERR_XML_DETAIL,
|
||||||
|
_("invalid char in %s: %c"), nodeName, *c);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXMLPropString:
|
* virXMLPropString:
|
||||||
* @node: XML dom node pointer
|
* @node: XML dom node pointer
|
||||||
|
@ -181,6 +181,10 @@ int virXMLInjectNamespace(xmlNodePtr node,
|
|||||||
|
|
||||||
void virXMLNodeSanitizeNamespaces(xmlNodePtr node);
|
void virXMLNodeSanitizeNamespaces(xmlNodePtr node);
|
||||||
|
|
||||||
|
int virXMLCheckIllegalChars(const char *nodeName,
|
||||||
|
const char *str,
|
||||||
|
const char *illegal);
|
||||||
|
|
||||||
struct _virXMLValidator {
|
struct _virXMLValidator {
|
||||||
xmlRelaxNGParserCtxtPtr rngParser;
|
xmlRelaxNGParserCtxtPtr rngParser;
|
||||||
xmlRelaxNGPtr rng;
|
xmlRelaxNGPtr rng;
|
||||||
|
Loading…
Reference in New Issue
Block a user