]> xenbits.xensource.com Git - libvirt.git/commitdiff
virxml: Add function to check if string contains some illegal chars
authorSławek Kapłoński <slawek@kaplonski.pl>
Wed, 19 Oct 2016 20:57:46 +0000 (22:57 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 20 Oct 2016 10:49:22 +0000 (18:49 +0800)
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>
src/libvirt_private.syms
src/util/virxml.c
src/util/virxml.h

index 55b6a2402bf69566ca477bf373e335edd04b2532..bf503a58cce9c521f3784906c4ea45f0025aaeb9 100644 (file)
@@ -2676,6 +2676,7 @@ virUUIDParse;
 
 
 # util/virxml.h
+virXMLCheckIllegalChars;
 virXMLChildElementCount;
 virXMLExtractNamespaceXML;
 virXMLNodeSanitizeNamespaces;
index 03bd78437af181d8e3576f38d023e58cc22668cc..1438edc4ddd7b4cbf4b9d5d42a29decabdd1d197 100644 (file)
@@ -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
index 7a0a1dad7754e591d6ecb11eca1082978c5a5149..17fccd81f44789e92759768723fc70d9ca498c8d 100644 (file)
@@ -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;