#endif
#ifdef HAVE_PCREPOSIX_H
+#define WITH_REGEX
# include <pcreposix.h>
#else
#ifdef HAVE_REGEX_H
+#define WITH_REGEX
# include <regex.h>
#endif
#endif
continue;
break;
-/* really HAVE_REGEX_H */
-#if 0
- /*
- * Attr-Name =~ "s/find/replace/"
- *
- * Very bad code. Barely working,
- * if at all.
- */
-
- case T_OP_REG_EQ:
- if (found &&
- (i->vp_strvalue[0] == 's')) {
- regex_t reg;
- regmatch_t match[1];
-
- char *str;
- char *p, *q;
-
- p = i->vp_strvalue + 1;
- q = strchr(p + 1, *p);
- if (!q || (q[strlen(q) - 1] != *p)) {
- tailfrom = i;
- continue;
- }
- str = strdup(i->vp_strvalue + 2);
- q = strchr(str, *p);
- *(q++) = '\0';
- q[strlen(q) - 1] = '\0';
-
- regcomp(®, str, 0);
- if (regexec(®, found->vp_strvalue,
- 1, match, 0) == 0) {
- fprintf(stderr, "\"%s\" will have %d to %d replaced with %s\n",
- found->vp_strvalue, match[0].rm_so,
- match[0].rm_eo, q);
-
- }
- regfree(®);
- free(str);
- }
- tailfrom = i; /* don't copy it over */
- continue;
- break;
-#endif
case T_OP_EQ: /* = */
/*
* FIXME: Tunnel attributes with
char *tc, *ts;
signed char tag;
int found_tag;
- char buffer[64];
+ char buffer[256];
const char *attrname = attribute;
/*
*/
case T_OP_REG_EQ: /* =~ */
case T_OP_REG_NE: /* !~ */
+#ifndef WITH_REGEX
+ fr_strerror_printf("Regular expressions are not supported");
+ return NULL;
+
+#else
if (!value) {
fr_strerror_printf("No regular expression found in %s",
vp->name);
}
pairbasicfree(vp);
+
+ if (1) {
+ int compare;
+ regex_t reg;
+
+ compare = regcomp(®, value, REG_EXTENDED);
+ if (compare != 0) {
+ regerror(compare, ®, buffer, sizeof(buffer));
+ fr_strerror_printf("Illegal regular expression in attribute: %s: %s",
+ attribute, buffer);
+ return NULL;
+ }
+ }
+
return pairmake_xlat(attribute, value, operator);
+#endif
}
/*
*/
case T_OP_REG_EQ:
case T_OP_REG_NE:
-#ifndef HAVE_REGEX_H
+#ifndef WITH_REGEX
return -1;
#else
{