compile the expressions, and if ok, build the rule */
| 465 | |
| 466 | /*compile the expressions, and if ok, build the rule */ |
| 467 | dpl_node_t * build_rule(db_val_t * values) |
| 468 | { |
| 469 | tmrec_expr *parsed_timerec; |
| 470 | pcre2_code * match_comp, *subst_comp; |
| 471 | struct subst_expr * repl_comp; |
| 472 | dpl_node_t * new_rule; |
| 473 | str match_exp, subst_exp, repl_exp, attrs, timerec; |
| 474 | int matchop; |
| 475 | uint32_t namecount; |
| 476 | |
| 477 | matchop = VAL_INT(values+2); |
| 478 | |
| 479 | if((matchop != REGEX_OP) && (matchop!=EQUAL_OP)){ |
| 480 | LM_ERR("invalid value for match operator\n"); |
| 481 | return NULL; |
| 482 | } |
| 483 | |
| 484 | parsed_timerec = 0; |
| 485 | match_comp = subst_comp = 0; |
| 486 | repl_comp = 0; |
| 487 | new_rule = 0; |
| 488 | |
| 489 | GET_STR_VALUE(match_exp, values, 3, 0); |
| 490 | if(matchop == REGEX_OP){ |
| 491 | |
| 492 | LM_DBG("Compiling %.*s expression with flag: %d\n", |
| 493 | match_exp.len, match_exp.s, VAL_INT(values+4)); |
| 494 | |
| 495 | match_comp = wrap_pcre_compile(match_exp.s, VAL_INT(values+4)); |
| 496 | |
| 497 | if(!match_comp){ |
| 498 | LM_ERR("failed to compile match expression \"%.*s\"\n", |
| 499 | match_exp.len, match_exp.s); |
| 500 | goto err; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | LM_DBG("building subst rule\n"); |
| 505 | GET_STR_VALUE(subst_exp, values, 5, 1); |
| 506 | if(!VAL_NULL(values+5) && subst_exp.s && subst_exp.len){ |
| 507 | /* subst regexp */ |
| 508 | subst_comp = wrap_pcre_compile(subst_exp.s, VAL_INT(values+4)); |
| 509 | if(subst_comp == NULL){ |
| 510 | LM_ERR("failed to compile subst expression \"%.*s\"\n", |
| 511 | subst_exp.len, subst_exp.s); |
| 512 | goto err; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | /* replace exp */ |
| 517 | GET_STR_VALUE(repl_exp, values, 6, 1); |
| 518 | if(!VAL_NULL(values+6) && repl_exp.len && repl_exp.s){ |
| 519 | repl_comp = repl_exp_parse(repl_exp); |
| 520 | if(!repl_comp){ |
| 521 | LM_ERR("failed to compile replacing expression \"%.*s\"\n", |
| 522 | repl_exp.len, repl_exp.s); |
| 523 | goto err; |
| 524 | } |
no test coverage detected