Get rid of the regular expressions when evaluating variable names and

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.
This commit is contained in:
Stefan Berger 2010-04-04 10:34:52 -04:00
parent 5288b2ad8e
commit a44b23ba63
4 changed files with 24 additions and 40 deletions

View 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);
}

View 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__, \

View File

@ -22,8 +22,6 @@
#include <config.h>
#include <regex.h>
#include "internal.h"
#include "memory.h"
@ -35,13 +33,6 @@
#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);
}

View 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 */