kamailio: backport and move to PCRE2
[feed/telephony.git] / net / kamailio / patches / 030-regex-clang-format-for-coherent-indentation-and-codi.patch
1 From fb7c59cafceb35628d40c727dbfa2990335b922a Mon Sep 17 00:00:00 2001
2 From: Victor Seva <linuxmaniac@torreviejawireless.org>
3 Date: Wed, 17 May 2023 16:37:10 +0200
4 Subject: [PATCH] regex: clang-format for coherent indentation and coding style
5
6 ---
7 src/modules/regex/regex_mod.c | 313 ++++++++++++++++------------------
8 1 file changed, 150 insertions(+), 163 deletions(-)
9
10 --- a/src/modules/regex/regex_mod.c
11 +++ b/src/modules/regex/regex_mod.c
12 @@ -49,9 +49,9 @@ MODULE_VERSION
13 #define START 0
14 #define RELOAD 1
15
16 -#define FILE_MAX_LINE 500 /*!< Max line size in the file */
17 -#define MAX_GROUPS 20 /*!< Max number of groups */
18 -#define GROUP_MAX_SIZE 8192 /*!< Max size of a group */
19 +#define FILE_MAX_LINE 500 /*!< Max line size in the file */
20 +#define MAX_GROUPS 20 /*!< Max number of groups */
21 +#define GROUP_MAX_SIZE 8192 /*!< Max size of a group */
22
23
24 static int regex_init_rpc(void);
25 @@ -66,12 +66,12 @@ gen_lock_t *reload_lock;
26 * Module exported parameter variables
27 */
28 static char *file;
29 -static int max_groups = MAX_GROUPS;
30 -static int group_max_size = GROUP_MAX_SIZE;
31 -static int pcre_caseless = 0;
32 -static int pcre_multiline = 0;
33 -static int pcre_dotall = 0;
34 -static int pcre_extended = 0;
35 +static int max_groups = MAX_GROUPS;
36 +static int group_max_size = GROUP_MAX_SIZE;
37 +static int pcre_caseless = 0;
38 +static int pcre_multiline = 0;
39 +static int pcre_dotall = 0;
40 +static int pcre_extended = 0;
41
42
43 /*
44 @@ -100,119 +100,117 @@ static void free_shared_memory(void);
45 /*
46 * Script functions
47 */
48 -static int w_pcre_match(struct sip_msg* _msg, char* _s1, char* _s2);
49 -static int w_pcre_match_group(struct sip_msg* _msg, char* _s1, char* _s2);
50 +static int w_pcre_match(struct sip_msg *_msg, char *_s1, char *_s2);
51 +static int w_pcre_match_group(struct sip_msg *_msg, char *_s1, char *_s2);
52
53
54 /*
55 * Exported functions
56 */
57 -static cmd_export_t cmds[] =
58 -{
59 - { "pcre_match", (cmd_function)w_pcre_match, 2, fixup_spve_spve, 0,
60 - REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
61 - { "pcre_match_group", (cmd_function)w_pcre_match_group, 2, fixup_spve_spve, 0,
62 - REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
63 - { "pcre_match_group", (cmd_function)w_pcre_match_group, 1, fixup_spve_null, 0,
64 - REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
65 - { 0, 0, 0, 0, 0, 0 }
66 -};
67 +static cmd_export_t cmds[] = {
68 + {"pcre_match", (cmd_function)w_pcre_match, 2, fixup_spve_spve, 0,
69 + REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE
70 + | LOCAL_ROUTE},
71 + {"pcre_match_group", (cmd_function)w_pcre_match_group, 2,
72 + fixup_spve_spve, 0,
73 + REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE
74 + | LOCAL_ROUTE},
75 + {"pcre_match_group", (cmd_function)w_pcre_match_group, 1,
76 + fixup_spve_null, 0,
77 + REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE
78 + | LOCAL_ROUTE},
79 + {0, 0, 0, 0, 0, 0}};
80
81
82 /*
83 * Exported parameters
84 */
85 -static param_export_t params[] = {
86 - {"file", PARAM_STRING, &file },
87 - {"max_groups", INT_PARAM, &max_groups },
88 - {"group_max_size", INT_PARAM, &group_max_size },
89 - {"pcre_caseless", INT_PARAM, &pcre_caseless },
90 - {"pcre_multiline", INT_PARAM, &pcre_multiline },
91 - {"pcre_dotall", INT_PARAM, &pcre_dotall },
92 - {"pcre_extended", INT_PARAM, &pcre_extended },
93 - {0, 0, 0}
94 -};
95 +static param_export_t params[] = {{"file", PARAM_STRING, &file},
96 + {"max_groups", INT_PARAM, &max_groups},
97 + {"group_max_size", INT_PARAM, &group_max_size},
98 + {"pcre_caseless", INT_PARAM, &pcre_caseless},
99 + {"pcre_multiline", INT_PARAM, &pcre_multiline},
100 + {"pcre_dotall", INT_PARAM, &pcre_dotall},
101 + {"pcre_extended", INT_PARAM, &pcre_extended}, {0, 0, 0}};
102
103
104 /*
105 * Module interface
106 */
107 struct module_exports exports = {
108 - "regex", /*!< module name */
109 - DEFAULT_DLFLAGS, /*!< dlopen flags */
110 - cmds, /*!< exported functions */
111 - params, /*!< exported parameters */
112 - 0, /*!< exported RPC functions */
113 - 0, /*!< exported pseudo-variables */
114 - 0, /*!< response handling function */
115 - mod_init, /*!< module initialization function */
116 - 0, /*!< per-child init function */
117 - destroy /*!< destroy function */
118 + "regex", /*!< module name */
119 + DEFAULT_DLFLAGS, /*!< dlopen flags */
120 + cmds, /*!< exported functions */
121 + params, /*!< exported parameters */
122 + 0, /*!< exported RPC functions */
123 + 0, /*!< exported pseudo-variables */
124 + 0, /*!< response handling function */
125 + mod_init, /*!< module initialization function */
126 + 0, /*!< per-child init function */
127 + destroy /*!< destroy function */
128 };
129
130
131 -
132 /*! \brief
133 * Init module function
134 */
135 static int mod_init(void)
136 {
137 - if(regex_init_rpc()<0)
138 - {
139 + if(regex_init_rpc() < 0) {
140 LM_ERR("failed to register RPC commands\n");
141 return -1;
142 }
143
144 /* Group matching feature */
145 - if (file == NULL) {
146 + if(file == NULL) {
147 LM_NOTICE("'file' parameter is not set, group matching disabled\n");
148 } else {
149 /* Create and init the lock */
150 reload_lock = lock_alloc();
151 - if (reload_lock == NULL) {
152 + if(reload_lock == NULL) {
153 LM_ERR("cannot allocate reload_lock\n");
154 goto err;
155 }
156 - if (lock_init(reload_lock) == NULL) {
157 + if(lock_init(reload_lock) == NULL) {
158 LM_ERR("cannot init the reload_lock\n");
159 lock_dealloc(reload_lock);
160 goto err;
161 }
162
163 /* PCRE options */
164 - if (pcre_caseless != 0) {
165 + if(pcre_caseless != 0) {
166 LM_DBG("PCRE CASELESS enabled\n");
167 pcre_options = pcre_options | PCRE_CASELESS;
168 }
169 - if (pcre_multiline != 0) {
170 + if(pcre_multiline != 0) {
171 LM_DBG("PCRE MULTILINE enabled\n");
172 pcre_options = pcre_options | PCRE_MULTILINE;
173 }
174 - if (pcre_dotall != 0) {
175 + if(pcre_dotall != 0) {
176 LM_DBG("PCRE DOTALL enabled\n");
177 pcre_options = pcre_options | PCRE_DOTALL;
178 }
179 - if (pcre_extended != 0) {
180 + if(pcre_extended != 0) {
181 LM_DBG("PCRE EXTENDED enabled\n");
182 pcre_options = pcre_options | PCRE_EXTENDED;
183 }
184 LM_DBG("PCRE options: %i\n", pcre_options);
185
186 /* Pointer to pcres */
187 - if ((pcres_addr = shm_malloc(sizeof(pcre **))) == 0) {
188 + if((pcres_addr = shm_malloc(sizeof(pcre **))) == 0) {
189 LM_ERR("no memory for pcres_addr\n");
190 goto err;
191 }
192
193 /* Integer containing the number of pcres */
194 - if ((num_pcres = shm_malloc(sizeof(int))) == 0) {
195 + if((num_pcres = shm_malloc(sizeof(int))) == 0) {
196 LM_ERR("no memory for num_pcres\n");
197 goto err;
198 }
199
200 /* Load the pcres */
201 LM_DBG("loading pcres...\n");
202 - if (load_pcres(START)) {
203 + if(load_pcres(START)) {
204 LM_ERR("failed to load pcres\n");
205 goto err;
206 }
207 @@ -251,21 +249,21 @@ static int load_pcres(int action)
208 /* Get the lock */
209 lock_get(reload_lock);
210
211 - if (!(f = fopen(file, "r"))) {
212 + if(!(f = fopen(file, "r"))) {
213 LM_ERR("could not open file '%s'\n", file);
214 goto err;
215 }
216
217 /* Array containing each pattern in the file */
218 - if ((patterns = pkg_malloc(sizeof(char*) * max_groups)) == 0) {
219 + if((patterns = pkg_malloc(sizeof(char *) * max_groups)) == 0) {
220 LM_ERR("no more memory for patterns\n");
221 fclose(f);
222 goto err;
223 }
224 - memset(patterns, 0, sizeof(char*) * max_groups);
225 + memset(patterns, 0, sizeof(char *) * max_groups);
226
227 - for (i=0; i<max_groups; i++) {
228 - if ((patterns[i] = pkg_malloc(sizeof(char) * group_max_size)) == 0) {
229 + for(i = 0; i < max_groups; i++) {
230 + if((patterns[i] = pkg_malloc(sizeof(char) * group_max_size)) == 0) {
231 LM_ERR("no more memory for patterns[%d]\n", i);
232 fclose(f);
233 goto err;
234 @@ -276,26 +274,27 @@ static int load_pcres(int action)
235 /* Read the file and extract the patterns */
236 memset(line, 0, FILE_MAX_LINE);
237 i = -1;
238 - while (fgets(line, FILE_MAX_LINE-4, f) != NULL) {
239 + while(fgets(line, FILE_MAX_LINE - 4, f) != NULL) {
240
241 /* Ignore comments and lines starting by space, tab, CR, LF */
242 - if(isspace(line[0]) || line[0]=='#') {
243 + if(isspace(line[0]) || line[0] == '#') {
244 memset(line, 0, FILE_MAX_LINE);
245 continue;
246 }
247
248 /* First group */
249 - if (i == -1 && line[0] != '[') {
250 - LM_ERR("first group must be initialized with [0] before any regular expression\n");
251 + if(i == -1 && line[0] != '[') {
252 + LM_ERR("first group must be initialized with [0] before any "
253 + "regular expression\n");
254 fclose(f);
255 goto err;
256 }
257
258 /* New group */
259 - if (line[0] == '[') {
260 + if(line[0] == '[') {
261 i++;
262 /* Check if there are more patterns than the max value */
263 - if (i >= max_groups) {
264 + if(i >= max_groups) {
265 LM_ERR("max patterns exceeded\n");
266 fclose(f);
267 goto err;
268 @@ -309,14 +308,14 @@ static int load_pcres(int action)
269
270 llen = strlen(line);
271 /* Check if the patter size is too big (aprox) */
272 - if (strlen(patterns[i]) + llen >= group_max_size - 4) {
273 + if(strlen(patterns[i]) + llen >= group_max_size - 4) {
274 LM_ERR("pattern max file exceeded\n");
275 fclose(f);
276 goto err;
277 }
278
279 /* Append ')' at the end of the line */
280 - if (line[llen - 1] == '\n') {
281 + if(line[llen - 1] == '\n') {
282 line[llen - 1] = ')';
283 line[llen] = '\n';
284 line[llen + 1] = '\0';
285 @@ -328,7 +327,7 @@ static int load_pcres(int action)
286
287 /* Append '(' at the beginning of the line */
288 llen = strlen(patterns[i]);
289 - memcpy(patterns[i]+llen, "(", 1);
290 + memcpy(patterns[i] + llen, "(", 1);
291 llen++;
292
293 /* Append the line to the current pattern (including the ending 0) */
294 @@ -340,16 +339,16 @@ static int load_pcres(int action)
295
296 fclose(f);
297
298 - if(num_pcres_tmp==0) {
299 + if(num_pcres_tmp == 0) {
300 LM_ERR("no expressions in the file\n");
301 goto err;
302 }
303
304 /* Fix the patterns */
305 - for (i=0; i < num_pcres_tmp; i++) {
306 + for(i = 0; i < num_pcres_tmp; i++) {
307
308 /* Convert empty groups in unmatcheable regular expression ^$ */
309 - if (strlen(patterns[i]) == 1) {
310 + if(strlen(patterns[i]) == 1) {
311 patterns[i][0] = '^';
312 patterns[i][1] = '$';
313 patterns[i][2] = '\0';
314 @@ -357,13 +356,13 @@ static int load_pcres(int action)
315 }
316
317 /* Delete possible '\n' at the end of the pattern */
318 - if (patterns[i][strlen(patterns[i])-1] == '\n') {
319 - patterns[i][strlen(patterns[i])-1] = '\0';
320 + if(patterns[i][strlen(patterns[i]) - 1] == '\n') {
321 + patterns[i][strlen(patterns[i]) - 1] = '\0';
322 }
323
324 /* Replace '\n' with '|' (except at the end of the pattern) */
325 - for (j=0; j < strlen(patterns[i]); j++) {
326 - if (patterns[i][j] == '\n' && j != strlen(patterns[i])-1) {
327 + for(j = 0; j < strlen(patterns[i]); j++) {
328 + if(patterns[i][j] == '\n' && j != strlen(patterns[i]) - 1) {
329 patterns[i][j] = '|';
330 }
331 }
332 @@ -374,38 +373,38 @@ static int load_pcres(int action)
333
334 /* Log the group patterns */
335 LM_INFO("num groups = %d\n", num_pcres_tmp);
336 - for (i=0; i < num_pcres_tmp; i++) {
337 - LM_INFO("<group[%d]>%s</group[%d]> (size = %i)\n", i, patterns[i],
338 - i, (int)strlen(patterns[i]));
339 + for(i = 0; i < num_pcres_tmp; i++) {
340 + LM_INFO("<group[%d]>%s</group[%d]> (size = %i)\n", i, patterns[i], i,
341 + (int)strlen(patterns[i]));
342 }
343
344 /* Temporal pointer of pcres */
345 - if ((pcres_tmp = pkg_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
346 + if((pcres_tmp = pkg_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
347 LM_ERR("no more memory for pcres_tmp\n");
348 goto err;
349 }
350 - for (i=0; i<num_pcres_tmp; i++) {
351 + for(i = 0; i < num_pcres_tmp; i++) {
352 pcres_tmp[i] = NULL;
353 }
354
355 /* Compile the patters */
356 - for (i=0; i<num_pcres_tmp; i++) {
357 + for(i = 0; i < num_pcres_tmp; i++) {
358
359 - pcre_tmp = pcre_compile(patterns[i], pcre_options, &pcre_error,
360 - &pcre_erroffset, NULL);
361 - if (pcre_tmp == NULL) {
362 + pcre_tmp = pcre_compile(
363 + patterns[i], pcre_options, &pcre_error, &pcre_erroffset, NULL);
364 + if(pcre_tmp == NULL) {
365 LM_ERR("pcre_tmp compilation of '%s' failed at offset %d: %s\n",
366 patterns[i], pcre_erroffset, pcre_error);
367 goto err;
368 }
369 pcre_rc = pcre_fullinfo(pcre_tmp, NULL, PCRE_INFO_SIZE, &pcre_size);
370 - if (pcre_rc) {
371 + if(pcre_rc) {
372 printf("pcre_fullinfo on compiled pattern[%i] yielded error: %d\n",
373 i, pcre_rc);
374 goto err;
375 }
376
377 - if ((pcres_tmp[i] = pkg_malloc(pcre_size)) == 0) {
378 + if((pcres_tmp[i] = pkg_malloc(pcre_size)) == 0) {
379 LM_ERR("no more memory for pcres_tmp[%i]\n", i);
380 goto err;
381 }
382 @@ -417,22 +416,22 @@ static int load_pcres(int action)
383 }
384
385 /* Copy to shared memory */
386 - if (action == RELOAD) {
387 - for(i=0; i<*num_pcres; i++) { /* Use the previous num_pcres value */
388 - if (pcres[i]) {
389 + if(action == RELOAD) {
390 + for(i = 0; i < *num_pcres; i++) { /* Use the previous num_pcres value */
391 + if(pcres[i]) {
392 shm_free(pcres[i]);
393 }
394 }
395 shm_free(pcres);
396 }
397 - if ((pcres = shm_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
398 + if((pcres = shm_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
399 LM_ERR("no more memory for pcres\n");
400 goto err;
401 }
402 memset(pcres, 0, sizeof(pcre *) * num_pcres_tmp);
403 - for (i=0; i<num_pcres_tmp; i++) {
404 + for(i = 0; i < num_pcres_tmp; i++) {
405 pcre_rc = pcre_fullinfo(pcres_tmp[i], NULL, PCRE_INFO_SIZE, &pcre_size);
406 - if ((pcres[i] = shm_malloc(pcre_size)) == 0) {
407 + if((pcres[i] = shm_malloc(pcre_size)) == 0) {
408 LM_ERR("no more memory for pcres[%i]\n", i);
409 goto err;
410 }
411 @@ -442,12 +441,12 @@ static int load_pcres(int action)
412 *pcres_addr = pcres;
413
414 /* Free used memory */
415 - for (i=0; i<num_pcres_tmp; i++) {
416 + for(i = 0; i < num_pcres_tmp; i++) {
417 pkg_free(pcres_tmp[i]);
418 }
419 pkg_free(pcres_tmp);
420 /* Free allocated slots for unused patterns */
421 - for (i = num_pcres_tmp; i < max_groups; i++) {
422 + for(i = num_pcres_tmp; i < max_groups; i++) {
423 pkg_free(patterns[i]);
424 }
425 pkg_free(patterns);
426 @@ -456,26 +455,26 @@ static int load_pcres(int action)
427 return 0;
428
429 err:
430 - if (patterns) {
431 - for(i=0; i<max_groups; i++) {
432 - if (patterns[i]) {
433 + if(patterns) {
434 + for(i = 0; i < max_groups; i++) {
435 + if(patterns[i]) {
436 pkg_free(patterns[i]);
437 }
438 }
439 pkg_free(patterns);
440 }
441 - if (pcres_tmp) {
442 - for (i=0; i<num_pcres_tmp; i++) {
443 - if (pcres_tmp[i]) {
444 + if(pcres_tmp) {
445 + for(i = 0; i < num_pcres_tmp; i++) {
446 + if(pcres_tmp[i]) {
447 pkg_free(pcres_tmp[i]);
448 }
449 }
450 pkg_free(pcres_tmp);
451 }
452 - if (reload_lock) {
453 + if(reload_lock) {
454 lock_release(reload_lock);
455 }
456 - if (action == START) {
457 + if(action == START) {
458 free_shared_memory();
459 }
460 return -1;
461 @@ -486,9 +485,9 @@ static void free_shared_memory(void)
462 {
463 int i;
464
465 - if (pcres) {
466 - for(i=0; i<*num_pcres; i++) {
467 - if (pcres[i]) {
468 + if(pcres) {
469 + for(i = 0; i < *num_pcres; i++) {
470 + if(pcres[i]) {
471 shm_free(pcres[i]);
472 }
473 }
474 @@ -496,21 +495,21 @@ static void free_shared_memory(void)
475 pcres = NULL;
476 }
477
478 - if (num_pcres) {
479 + if(num_pcres) {
480 shm_free(num_pcres);
481 num_pcres = NULL;
482 }
483
484 - if (pcres_addr) {
485 + if(pcres_addr) {
486 shm_free(pcres_addr);
487 pcres_addr = NULL;
488 }
489
490 - if (reload_lock) {
491 + if(reload_lock) {
492 lock_destroy(reload_lock);
493 lock_dealloc(reload_lock);
494 reload_lock = NULL;
495 - }
496 + }
497 }
498
499
500 @@ -519,32 +518,32 @@ static void free_shared_memory(void)
501 */
502
503 /*! \brief Return true if the argument matches the regular expression parameter */
504 -static int ki_pcre_match(sip_msg_t* msg, str* string, str* regex)
505 +static int ki_pcre_match(sip_msg_t *msg, str *string, str *regex)
506 {
507 pcre *pcre_re = NULL;
508 int pcre_rc;
509 const char *pcre_error;
510 int pcre_erroffset;
511
512 - pcre_re = pcre_compile(regex->s, pcre_options, &pcre_error, &pcre_erroffset, NULL);
513 - if (pcre_re == NULL) {
514 + pcre_re = pcre_compile(
515 + regex->s, pcre_options, &pcre_error, &pcre_erroffset, NULL);
516 + if(pcre_re == NULL) {
517 LM_ERR("pcre_re compilation of '%s' failed at offset %d: %s\n",
518 regex->s, pcre_erroffset, pcre_error);
519 return -4;
520 }
521
522 - pcre_rc = pcre_exec(
523 - pcre_re, /* the compiled pattern */
524 - NULL, /* no extra data - we didn't study the pattern */
525 - string->s, /* the matching string */
526 - (int)(string->len), /* the length of the subject */
527 - 0, /* start at offset 0 in the string */
528 - 0, /* default options */
529 - NULL, /* output vector for substring information */
530 - 0); /* number of elements in the output vector */
531 + pcre_rc = pcre_exec(pcre_re, /* the compiled pattern */
532 + NULL, /* no extra data - we didn't study the pattern */
533 + string->s, /* the matching string */
534 + (int)(string->len), /* the length of the subject */
535 + 0, /* start at offset 0 in the string */
536 + 0, /* default options */
537 + NULL, /* output vector for substring information */
538 + 0); /* number of elements in the output vector */
539
540 /* Matching failed: handle error cases */
541 - if (pcre_rc < 0) {
542 + if(pcre_rc < 0) {
543 switch(pcre_rc) {
544 case PCRE_ERROR_NOMATCH:
545 LM_DBG("'%s' doesn't match '%s'\n", string->s, regex->s);
546 @@ -562,28 +561,26 @@ static int ki_pcre_match(sip_msg_t* msg,
547 }
548
549 /*! \brief Return true if the argument matches the regular expression parameter */
550 -static int w_pcre_match(struct sip_msg* _msg, char* _s1, char* _s2)
551 +static int w_pcre_match(struct sip_msg *_msg, char *_s1, char *_s2)
552 {
553 str string;
554 str regex;
555
556 - if (_s1 == NULL) {
557 + if(_s1 == NULL) {
558 LM_ERR("bad parameters\n");
559 return -2;
560 }
561
562 - if (_s2 == NULL) {
563 + if(_s2 == NULL) {
564 LM_ERR("bad parameters\n");
565 return -2;
566 }
567
568 - if (fixup_get_svalue(_msg, (gparam_p)_s1, &string))
569 - {
570 + if(fixup_get_svalue(_msg, (gparam_p)_s1, &string)) {
571 LM_ERR("cannot print the format for string\n");
572 return -3;
573 }
574 - if (fixup_get_svalue(_msg, (gparam_p)_s2, &regex))
575 - {
576 + if(fixup_get_svalue(_msg, (gparam_p)_s2, &regex)) {
577 LM_ERR("cannot print the format for regex\n");
578 return -3;
579 }
580 @@ -592,17 +589,17 @@ static int w_pcre_match(struct sip_msg*
581 }
582
583 /*! \brief Return true if the string argument matches the pattern group parameter */
584 -static int ki_pcre_match_group(sip_msg_t* _msg, str* string, int num_pcre)
585 +static int ki_pcre_match_group(sip_msg_t *_msg, str *string, int num_pcre)
586 {
587 int pcre_rc;
588
589 /* Check if group matching feature is enabled */
590 - if (file == NULL) {
591 + if(file == NULL) {
592 LM_ERR("group matching is disabled\n");
593 return -2;
594 }
595
596 - if (num_pcre >= *num_pcres) {
597 + if(num_pcre >= *num_pcres) {
598 LM_ERR("invalid pcre index '%i', there are %i pcres\n", num_pcre,
599 *num_pcres);
600 return -4;
601 @@ -610,20 +607,19 @@ static int ki_pcre_match_group(sip_msg_t
602
603 lock_get(reload_lock);
604
605 - pcre_rc = pcre_exec(
606 - (*pcres_addr)[num_pcre], /* the compiled pattern */
607 - NULL, /* no extra data - we didn't study the pattern */
608 - string->s, /* the matching string */
609 - (int)(string->len), /* the length of the subject */
610 - 0, /* start at offset 0 in the string */
611 - 0, /* default options */
612 - NULL, /* output vector for substring information */
613 - 0); /* number of elements in the output vector */
614 + pcre_rc = pcre_exec((*pcres_addr)[num_pcre], /* the compiled pattern */
615 + NULL, /* no extra data - we didn't study the pattern */
616 + string->s, /* the matching string */
617 + (int)(string->len), /* the length of the subject */
618 + 0, /* start at offset 0 in the string */
619 + 0, /* default options */
620 + NULL, /* output vector for substring information */
621 + 0); /* number of elements in the output vector */
622
623 lock_release(reload_lock);
624
625 /* Matching failed: handle error cases */
626 - if (pcre_rc < 0) {
627 + if(pcre_rc < 0) {
628 switch(pcre_rc) {
629 case PCRE_ERROR_NOMATCH:
630 LM_DBG("'%s' doesn't match pcres[%i]\n", string->s, num_pcre);
631 @@ -640,29 +636,27 @@ static int ki_pcre_match_group(sip_msg_t
632 }
633
634 /*! \brief Return true if the string argument matches the pattern group parameter */
635 -static int w_pcre_match_group(struct sip_msg* _msg, char* _s1, char* _s2)
636 +static int w_pcre_match_group(struct sip_msg *_msg, char *_s1, char *_s2)
637 {
638 str string, group;
639 unsigned int num_pcre = 0;
640
641 - if (_s1 == NULL) {
642 + if(_s1 == NULL) {
643 LM_ERR("bad parameters\n");
644 return -3;
645 }
646
647 - if (_s2 == NULL) {
648 + if(_s2 == NULL) {
649 num_pcre = 0;
650 } else {
651 - if (fixup_get_svalue(_msg, (gparam_p)_s2, &group))
652 - {
653 + if(fixup_get_svalue(_msg, (gparam_p)_s2, &group)) {
654 LM_ERR("cannot print the format for second param\n");
655 return -5;
656 }
657 str2int(&group, &num_pcre);
658 }
659
660 - if (fixup_get_svalue(_msg, (gparam_p)_s1, &string))
661 - {
662 + if(fixup_get_svalue(_msg, (gparam_p)_s1, &string)) {
663 LM_ERR("cannot print the format for first param\n");
664 return -5;
665 }
666 @@ -676,42 +670,35 @@ static int w_pcre_match_group(struct sip
667 */
668
669 /*! \brief Reload pcres by reading the file again */
670 -void regex_rpc_reload(rpc_t* rpc, void* ctx)
671 +void regex_rpc_reload(rpc_t *rpc, void *ctx)
672 {
673 /* Check if group matching feature is enabled */
674 - if (file == NULL) {
675 + if(file == NULL) {
676 LM_NOTICE("'file' parameter is not set, group matching disabled\n");
677 rpc->fault(ctx, 500, "Group matching not enabled");
678 return;
679 }
680 LM_INFO("reloading pcres...\n");
681 - if (load_pcres(RELOAD)) {
682 + if(load_pcres(RELOAD)) {
683 LM_ERR("failed to reload pcres\n");
684 rpc->fault(ctx, 500, "Failed to reload");
685 return;
686 }
687 LM_INFO("reload success\n");
688 -
689 }
690
691 -static const char* regex_rpc_reload_doc[2] = {
692 - "Reload regex file",
693 - 0
694 -};
695 +static const char *regex_rpc_reload_doc[2] = {"Reload regex file", 0};
696
697 rpc_export_t regex_rpc_cmds[] = {
698 - {"regex.reload", regex_rpc_reload,
699 - regex_rpc_reload_doc, 0},
700 - {0, 0, 0, 0}
701 -};
702 + {"regex.reload", regex_rpc_reload, regex_rpc_reload_doc, 0},
703 + {0, 0, 0, 0}};
704
705 /**
706 * register RPC commands
707 */
708 static int regex_init_rpc(void)
709 {
710 - if (rpc_register_array(regex_rpc_cmds)!=0)
711 - {
712 + if(rpc_register_array(regex_rpc_cmds) != 0) {
713 LM_ERR("failed to register RPC commands\n");
714 return -1;
715 }