Browse code

core: fixup helper for igp and regexp params

Daniel-Constantin Mierla authored on 27/09/2021 10:31:59
Showing 2 changed files
... ...
@@ -251,6 +251,50 @@ int fixup_free_regexp_regexp(void** param, int param_no)
251 251
 	return fixup_free_regexp_null(param, 1);
252 252
 }
253 253
 
254
+int fixup_igp_regexp(void** param, int param_no)
255
+{
256
+	struct regex_fixup* re;
257
+
258
+	if (param_no == 1) {
259
+		return fixup_igp_null(param, param_no);
260
+	}
261
+	if (param_no == 2) {
262
+		if ((re=pkg_malloc(sizeof(*re))) ==0) {
263
+			PKG_MEM_ERROR;
264
+			goto error;
265
+		}
266
+		if (regcomp(&re->regex, *param,
267
+					REG_EXTENDED|REG_ICASE|REG_NEWLINE))
268
+			goto error;
269
+		re->orig = *param;
270
+		*param = re;
271
+	}
272
+	return 0;
273
+error:
274
+	if (re)
275
+		pkg_free(re);
276
+	return E_UNSPEC;
277
+}
278
+
279
+int fixup_free_igp_regexp(void** param, int param_no)
280
+{
281
+	struct regex_fixup* re;
282
+
283
+	if (param_no == 1) {
284
+		return fixup_free_igp_null(param, param_no);
285
+	}
286
+	if (param_no == 2) {
287
+		if (*param) {
288
+			re = *param;
289
+			*param = re->orig;
290
+			regfree(&re->regex);
291
+			pkg_free(re);
292
+		}
293
+	}
294
+	return 0;
295
+}
296
+
297
+
254 298
 /* fixup_pvar_*() has to be written "by hand", since
255 299
    it needs to save the original pointer (the fixup users expects
256 300
    a pointer to the pv_spec_t in *param and hence the original value
... ...
@@ -159,4 +159,7 @@ free_fixup_function mod_fix_get_fixup_free(fixup_function f);
159 159
 int fixup_vstr_all(void** param, int param_no);
160 160
 int fixup_free_vstr_all(void** param, int param_no);
161 161
 int fixup_get_vstr_buf(sip_msg_t *msg, pv_elem_t *p, char *buf, int blen);
162
+
163
+int fixup_igp_regexp(void** param, int param_no);
164
+int fixup_free_igp_regexp(void** param, int param_no);
162 165
 #endif