On 05/17/2014 06:42 AM, Juha Heinanen wrote:
> sip-router writes:
> 
>> Details - This allows the use of pv's at match and subst rules on
>> dialplan module.
> 
> is there any performance penalty compared to current version when pvs
> are not used?

Calling to the new core function pv_check_format(str *) in the load
process in order to detect if the match/subst rule has pv vars.

pv_check_format code is in the first patch

relevant code in build_rule():

>  /*compile the expressions, and if ok, build the rule */
>  dpl_node_t * build_rule(db_val_t * values)
> @@ -359,9 +463,10 @@ dpl_node_t * build_rule(db_val_t * values)
>       pcre *match_comp, *subst_comp;
>       struct subst_expr *repl_comp;
>       dpl_node_t * new_rule;
> -     str match_exp, subst_exp, repl_exp, attrs;
> +     str match_exp, subst_exp, repl_exp, attrs, tmp;
>       int matchop;
>       int cap_cnt=0;
> +     unsigned int pv_flags = 0;
>  
>       matchop = VAL_INT(values+2);
>  
> @@ -377,11 +482,21 @@ dpl_node_t * build_rule(db_val_t * values)
>  
>       GET_STR_VALUE(match_exp, values, 3);
>       if(matchop == DP_REGEX_OP){
> -             match_comp = reg_ex_comp(match_exp.s, &cap_cnt);
> -             if(!match_comp){
> -                     LM_ERR("failed to compile match expression %.*s\n",
> -                                     match_exp.len, match_exp.s);
> -                     goto err;
> +             if(check_pv_marker(match_exp, &tmp))
> +                     pv_flags |= DP_PV_MATCH_M;
> +             if(pv_check_format(&tmp)<0){
> +                     pv_flags &= ~DP_PV_MATCH_MASK;
> +                     match_comp = reg_ex_comp(match_exp.s, &cap_cnt);
> +                     if(!match_comp){
> +                             LM_ERR("failed to compile match expression 
> %.*s\n",
> +                                             match_exp.len, match_exp.s);
> +                             goto err;
> +                     }
> +             }
> +             else{
> +                     pv_flags |= DP_PV_MATCH;
> +                     LM_DBG("match_exp DP_PV_MATCH_MASK\n");
> +                     match_comp = NULL;
>               }
>       }
>  
> @@ -398,26 +513,38 @@ dpl_node_t * build_rule(db_val_t * values)
>  
>       GET_STR_VALUE(subst_exp, values, 5);
>       if(subst_exp.s && subst_exp.len){
> -             subst_comp = reg_ex_comp(subst_exp.s, &cap_cnt);
> -             if(!subst_comp){
> -                     LM_ERR("failed to compile subst expression %.*s\n",
> -                                     subst_exp.len, subst_exp.s);
> -                     goto err;
> +             if(check_pv_marker(subst_exp, &tmp))
> +                     pv_flags |= DP_PV_SUBST_M;
> +             if(pv_check_format(&tmp)<0){
> +                     pv_flags &= ~DP_PV_SUBST_MASK;
> +                     subst_comp = reg_ex_comp(subst_exp.s, &cap_cnt);
> +                     if(!subst_comp){
> +                             LM_ERR("failed to compile subst expression 
> %.*s\n",
> +                                             subst_exp.len, subst_exp.s);
> +                             goto err;
> +                     }
> +                     if (cap_cnt > MAX_REPLACE_WITH) {
> +                             LM_ERR("subst expression %.*s has too many 
> sub-expressions\n",
> +                                             subst_exp.len, subst_exp.s);
> +                             goto err;
> +                     }
>               }
> -             if (cap_cnt > MAX_REPLACE_WITH) {
> -                     LM_ERR("subst expression %.*s has too many 
> sub-expressions\n",
> -                                     subst_exp.len, subst_exp.s);
> -                     goto err;
> +             else{
> +                     pv_flags |= DP_PV_SUBST;
> +                     LM_DBG("subst_exp DP_PV_SUBST_MASK\n");
> +                     subst_comp = NULL;
>               }
>       }
>  
> -     if (repl_comp && (cap_cnt < repl_comp->max_pmatch) && 
> -                     (repl_comp->max_pmatch != 0)) {
> -             LM_ERR("repl_exp %.*s refers to %d sub-expressions, but "
> -                             "subst_exp %.*s has only %d\n",
> -                             repl_exp.len, repl_exp.s, repl_comp->max_pmatch,
> -                             subst_exp.len, subst_exp.s, cap_cnt);
> -             goto err;
> +     if((pv_flags&DP_PV_MASK)==0) {
> +             if (repl_comp && (cap_cnt < repl_comp->max_pmatch) &&
> +                             (repl_comp->max_pmatch != 0)) {
> +                     LM_ERR("repl_exp %.*s refers to %d sub-expressions, but 
> "
> +                                     "subst_exp %.*s has only %d\n",
> +                                     repl_exp.len, repl_exp.s, 
> repl_comp->max_pmatch,
> +                                     subst_exp.len, subst_exp.s, cap_cnt);
> +                     goto err;
> +             }
>       }
>  
>       new_rule = (dpl_node_t *)shm_malloc(sizeof(dpl_node_t));
> @@ -450,6 +577,7 @@ dpl_node_t * build_rule(db_val_t * values)
>       new_rule->match_comp = match_comp;
>       new_rule->subst_comp = subst_comp;
>       new_rule->repl_comp  = repl_comp;
> +     new_rule->pv_flags = pv_flags;
>  
>       return new_rule;
>  
> @@ -550,6 +678,85 @@ err:
>       return -1;
>  }



Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to