]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Get rid of the regular expressions when evaluating variable names and
authorStefan Berger <stefanb@us.ibm.com>
Sun, 4 Apr 2010 14:34:52 +0000 (10:34 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Sun, 4 Apr 2010 14:34:52 +0000 (10:34 -0400)
values. Rather use the strspn() function. Along with this cleanup the
initialization function for the code that used the regular expression
can also be removed.

src/conf/nwfilter_conf.c
src/conf/nwfilter_conf.h
src/conf/nwfilter_params.c
src/conf/nwfilter_params.h

index 7c71ece18b97f5bc4c9134423ae0d84109565fdf..c8dda044e547d3752275aa08d946265047dda943 100644 (file)
@@ -2635,16 +2635,13 @@ int virNWFilterConfLayerInit(virHashIterator domUpdateCB)
     if (virMutexInit(&updateMutex))
         return 1;
 
-    if (virNWFilterParamConfLayerInit())
-        return 1;
-
     return 0;
 }
 
 
 void virNWFilterConfLayerShutdown(void)
 {
-    virNWFilterParamConfLayerShutdown();
+    virMutexDestroy(&updateMutex);
 }
 
 
index bac67efc45e0913c8339eb9408755342e85fe8aa..8ab0b8966481f57c54fff8423341d320fbf65090 100644 (file)
@@ -568,9 +568,6 @@ void virNWFilterPoolObjUnlock(virNWFilterPoolObjPtr obj);
 int virNWFilterConfLayerInit(virHashIterator domUpdateCB);
 void virNWFilterConfLayerShutdown(void);
 
-int virNWFilterParamConfLayerInit(void);
-void virNWFilterParamConfLayerShutdown(void);
-
 # define virNWFilterReportError(conn, code, fmt...)                          \
         (void)conn;                                                          \
         virReportErrorHelper(NULL, VIR_FROM_NWFILTER, code, __FILE__,  \
index 286c5ef1bfe5dfa7fd3554b1c5b10c82106f043a..a1c30bb7513c656fc5037dc99de481464e0f4cef 100644 (file)
@@ -22,8 +22,6 @@
 
 #include <config.h>
 
-#include <regex.h>
-
 #include "internal.h"
 
 #include "memory.h"
 
 #define VIR_FROM_THIS VIR_FROM_NWFILTER
 
-/*
- * regular expressions for parameter names and values
- */
-static regex_t regex_nam;
-static regex_t regex_val;
-
-
 static void
 hashDealloc(void *payload, const char *name ATTRIBUTE_UNUSED)
 {
@@ -215,6 +206,21 @@ err_exit:
 
 
 #ifndef PROXY
+
+static bool
+isValidVarName(const char *var)
+{
+    return var[strspn(var, VALID_VARNAME)] == 0;
+}
+
+
+static bool
+isValidVarValue(const char *value)
+{
+    return value[strspn(value, VALID_VARVALUE)] == 0;
+}
+
+
 virNWFilterHashTablePtr
 virNWFilterParseParamAttributes(xmlNodePtr cur)
 {
@@ -234,9 +240,9 @@ virNWFilterParseParamAttributes(xmlNodePtr cur)
                 nam = virXMLPropString(cur, "name");
                 val = virXMLPropString(cur, "value");
                 if (nam != NULL && val != NULL) {
-                    if (regexec(&regex_nam, nam, 0, NULL, 0) != 0)
+                    if (!isValidVarName(nam))
                         goto skip_entry;
-                    if (regexec(&regex_val, val, 0, NULL, 0) != 0)
+                    if (!isValidVarValue(nam))
                         goto skip_entry;
                     if (virNWFilterHashTablePut(table, nam, val, 1)) {
                         VIR_FREE(nam);
@@ -296,25 +302,3 @@ virNWFilterFormatParamAttributes(virNWFilterHashTablePtr table,
 
     return virBufferContentAndReset(&buf);
 }
-
-
-int virNWFilterParamConfLayerInit(void) {
-
-    if (regcomp(&regex_nam, "^[a-zA-Z0-9_]+$"  ,
-                            REG_NOSUB|REG_EXTENDED) != 0)
-        return 1;
-
-    if (regcomp(&regex_val, "^[a-zA-Z0-9_.:]+$",
-                            REG_NOSUB|REG_EXTENDED) != 0) {
-        regfree(&regex_nam);
-        return 1;
-    }
-
-    return 0;
-}
-
-
-void virNWFilterParamConfLayerShutdown(void) {
-    regfree(&regex_nam);
-    regfree(&regex_val);
-}
index 5b4afba609047aa634e33bce99ecde72b9754835..dd9750e676ee8d0508210f37ae0d883ce7c20adf 100644 (file)
@@ -50,4 +50,10 @@ int virNWFilterHashTablePutAll(virConnectPtr conn,
                                virNWFilterHashTablePtr src,
                                virNWFilterHashTablePtr dest);
 
+# define VALID_VARNAME \
+  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
+
+# define VALID_VARVALUE \
+  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:"
+
 #endif /* NWFILTER_PARAMS_H */