Validation: validation function
@@ -33,20 +33,14 @@ int elektraValidationGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key
return 1;
}
-int elektraValidationSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
-{
- Key * cur = 0;
-
- while ((cur = ksNext (returned)) != 0)
+static int validateKey(Key *key, Key *parentKey)
{
- const Key * regexMeta = keyGetMeta (cur, "check/validation");
+ const Key * regexMeta = keyGetMeta (key, "check/validation");
- if (!regexMeta) continue;
-
- const Key * icaseMeta = keyGetMeta (cur, "check/validation/ignorecase");
- const Key * matchMeta = keyGetMeta (cur, "check/validation/match");
- const Key * invertMeta = keyGetMeta (cur, "check/validation/invert");
- const Key * typeMeta = keyGetMeta (cur, "check/validation/type");
+ const Key * icaseMeta = keyGetMeta (key, "check/validation/ignorecase");
+ const Key * matchMeta = keyGetMeta (key, "check/validation/match");
+ const Key * invertMeta = keyGetMeta (key, "check/validation/invert");
+ const Key * typeMeta = keyGetMeta (key, "check/validation/type");
int lineValidation = 0;
int wordValidation = 0;
@@ -117,19 +111,19 @@ int elektraValidationSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key
ELEKTRA_SET_ERROR (41, parentKey, buffer);
regfree (&regex);
if (freeString) elektraFree (regexString);
- return -1;
+ return 0;
}
int match = 0;
if (!wordValidation)
{
- ret = regexec (&regex, keyString (cur), 1, &offsets, 0);
+ ret = regexec (&regex, keyString (key), 1, &offsets, 0);
if (ret == 0) match = 1;
}
else
{
char * savePtr;
char * token;
- char * string = (char *)keyString (cur);
+ char * string = (char *)keyString (key);
while ((token = strtok_r (string, " \t\n", &savePtr)) != NULL)
{
ret = regexec (&regex, token, 1, &offsets, 0);
@@ -145,13 +139,13 @@ int elektraValidationSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key
if (!match)
{
- const Key * msg = keyGetMeta (cur, "check/validation/message");
+ const Key * msg = keyGetMeta (key, "check/validation/message");
if (msg)
{
ELEKTRA_SET_ERROR (42, parentKey, keyString (msg));
regfree (&regex);
if (freeString) elektraFree (regexString);
- return -1;
+ return 0;
}
else
{
@@ -160,12 +154,27 @@ int elektraValidationSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key
ELEKTRA_SET_ERROR (42, parentKey, buffer);
regfree (&regex);
if (freeString) elektraFree (regexString);
- return -1;
+ return 0;
}
}
regfree (&regex);
if (freeString) elektraFree (regexString);
+ return 1;
+}
+
+int elektraValidationSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
+{
+ Key * cur = 0;
+
+ while ((cur = ksNext (returned)) != 0)
+ {
+ const Key * regexMeta = keyGetMeta (cur, "check/validation");
+
+ if (!regexMeta) continue;
+ int rc = validateKey(cur, parentKey);
+ if(!rc)
+ return -1;
}
return 1; /* success */
