Bläddra i källkod

- fixup_regex added

Jan Janak 20 år sedan
förälder
incheckning
f671296776
2 ändrade filer med 48 tillägg och 0 borttagningar
  1. 39 0
      sr_module.c
  2. 9 0
      sr_module.h

+ 39 - 0
sr_module.c

@@ -42,6 +42,7 @@
 #include "mem/mem.h"
 #include "ut.h"
 
+#include <regex.h>
 #include <dlfcn.h>
 #include <strings.h>
 #include <stdlib.h>
@@ -580,3 +581,41 @@ int fixup_int_2(void** param, int param_no)
 	
 	return 0;
 }
+
+
+int fixup_regex_12(void** param, int param_no)
+{
+	regex_t* re;
+
+	if ((re=pkg_malloc(sizeof(regex_t)))==0) return E_OUT_OF_MEM;
+	if (regcomp(re, *param, REG_EXTENDED|REG_ICASE|REG_NEWLINE) ){
+		pkg_free(re);
+		LOG(L_ERR, "ERROR: fixup_regex_12: Bad regular expression '%s'\n", (char*)*param);
+		return E_BAD_RE;
+	}
+	/* free string */
+	pkg_free(*param);
+	/* replace it with the compiled re */
+	*param=re;
+	return 0;
+}
+
+
+int fixup_regex_1(void** param, int param_no)
+{
+	if (param_no == 1) {
+		return fixup_regex_12(param, param_no);
+	}
+
+	return 0;
+}
+
+
+int fixup_regex_2(void** param, int param_no)
+{
+	if (param_no == 2) {
+		return fixup_regex_12(param, param_no);
+	}
+
+	return 0;
+}

+ 9 - 0
sr_module.h

@@ -183,4 +183,13 @@ int fixup_int_1(void** param, int param_no);
 /* Convert second parameter from char* to long */
 int fixup_int_2(void** param, int param_no);
 
+/* Compile regular expressions in both parameters */
+int fixup_regex_12(void** param, int param_no);
+
+/* Compile regular expression in first parameter */
+int fixup_regex_1(void** param, int param_no);
+
+/* Compile regular expression in second parameter */
+int fixup_regex_2(void** param, int param_no);
+
 #endif /* sr_module_h */