提交 7a221646 编写于 作者: S Sławek Kapłoński 提交者: Michal Privoznik

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: NMichal Privoznik <mprivozn@redhat.com>
上级 5f2a1327
......@@ -2676,6 +2676,7 @@ virUUIDParse;
# util/virxml.h
virXMLCheckIllegalChars;
virXMLChildElementCount;
virXMLExtractNamespaceXML;
virXMLNodeSanitizeNamespaces;
......
......@@ -462,6 +462,33 @@ virXPathLongLong(const char *xpath,
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:
* @node: XML dom node pointer
......
......@@ -181,6 +181,10 @@ int virXMLInjectNamespace(xmlNodePtr node,
void virXMLNodeSanitizeNamespaces(xmlNodePtr node);
int virXMLCheckIllegalChars(const char *nodeName,
const char *str,
const char *illegal);
struct _virXMLValidator {
xmlRelaxNGParserCtxtPtr rngParser;
xmlRelaxNGPtr rng;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册