This closes #5 . Be aware that this needs the #17 applied in order to work You can merge this Pull Request by running:
git pull https://github.com/linuxmaniac/kamailio vseva/dialplan_avp_list
Or you can view, comment on it, or merge it online at:
https://github.com/kamailio/kamailio/pull/18
-- Commit Summary --
* dialplan: using $(avp("key")[*]) on match rules * dialplan: using $(avp("key")[*]) on subst rules
-- File Changes --
M modules/dialplan/dialplan.h (2) M modules/dialplan/dp_repl.c (356)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/18.patch https://github.com/kamailio/kamailio/pull/18.diff
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18
The patch is quite big and I am trying to figure out the purpose. Was $(avp(x)[*]) not printed properly in the match or subst rules? It should, because its value is taken via common pv framework which evaluates it like for an xlog() parameter.
Can you give an example of a rule that doesn't work before this patch and works after?
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-69894418
This is the route that I'm using for testing this feature: ``` route[TEST] { pv_unset("$(avp(s:pbx_cli)[*])"); $avp(s:pbx_cli) = "1111"; $avp(s:pbx_cli) = "2222"; $avp(s:pbx_cli) = "3333"; $var(num) = "11118765"; if(dp_translate("2", "$var(num)/$avp(s:dest)")) { xlog("$var(num) translated to var $avp(s:dest) \n"); } $var(num) = "0022228765"; if(dp_translate("2", "$var(num)/$avp(s:dest)")) { xlog("$var(num) translated to var $avp(s:dest) \n"); } $var(num) = "00333387"; $(avp(s:cloud_pbx_cli)[*]) = "666"; if(dp_translate("2", "$var(num)/$avp(s:dest)")) { xlog("$var(num) translated to var $avp(s:dest) \n"); } if(dp_translate("1", "$var(num)/$avp(s:dest)")) { xlog("$var(num) translated to var $avp(s:dest) \n"); } } ``` This is the rules at dialplan: ``` sqlite> select * from dialplan; 1|1|1|2|^(00|+)([1-9][0-9]+)$|0|^(00|+)([1-9][0-9]+)$|\2| 2|2|1|2|^$avp(s:caller_cc)$avp(s:caller_ac)([1-9][0-9]+)$|0|^$avp(s:caller_cc)$avp(s:caller_ac)([1-9][0-9]+)$|\1| 3|1|2|0|^(00|+)([1-9][0-9]+)$|0|^(00|+)([1-9][0-9]+)$|\2| 4|2|2|0|^$avp(s:caller_cc)$avp(s:caller_ac)([1-9][0-9]+)$|0|^$avp(s:caller_cc)$avp(s:caller_ac)([1-9][0-9]+)$|\1| 5|1|2|1|^(00|+)([1-9][0-9]+)$|0|^(00|+)([1-9][0-9]+)$|\2| 6|2|2|1|^$avp(s:caller_cc)$avp(s:caller_ac)([1-9][0-9]+)$|0|^$avp(s:caller_cc)$avp(s:caller_ac)([1-9][0-9]+)$|\1| 7|2|2|1|^(00|+)?$(avp(s:pbx_cli)[*])([0-9]{3})$|0|^(00|+)?$(avp(s:pbx_cli)[*])([0-9]{3})$|\2| 8|2|2|1|^(00|+)?$(avp(s:pbx_cli)[*])([1-9]{2})$|0|^(00|+)?$(avp(s:pbx_cli)[*])([1-9]{2})$|$avp(s:cloud_pbx_cli)| ``` As you can see if you use $(avp(s:pbx_cli)[*]) you will get "333 3, 2222, 1111". So the normal behavior for print but not what we want. ``` 4(1425) DEBUG: dialplan [dp_repl.c:77]: dpl_dynamic_pcre(): compiled dynamic pcre expression: ^(00|+)?$(avp(s:pbx_cli)[*])([0-9]{3})$$ (^(00|+)?333 3, 2222, 1111([0-9]{3})$) 2
```
With the patch we are checking every value of the avp, one by one: ``` 4(5674) DEBUG: dialplan [dp_repl.c:249]: dpl_dynamic_pcre_list(): parsed pcre expression: ^(00|+)?$(avp(s:pbx_cli)[*])([0-9]{3})$$ 4(5674) DEBUG: dialplan [dp_repl.c:222]: dpl_dyn_pcre_comp(): compiled dynamic pcre expression: ^(00|+)?3333([0-9]{3})$ 2 4(5674) DEBUG: dialplan [dp_repl.c:222]: dpl_dyn_pcre_comp(): compiled dynamic pcre expression: ^(00|+)?2222([0-9]{3})$ 2 4(5674) DEBUG: dialplan [dp_repl.c:222]: dpl_dyn_pcre_comp(): compiled dynamic pcre expression: ^(00|+)?1111([0-9]{3})$ 2 4(5674) DEBUG: dialplan [dp_repl.c:628]: translate(): match check: [^(00|+)?1111([0-9]{3})$] -1 4(5674) DEBUG: dialplan [dp_repl.c:628]: translate(): match check: [^(00|+)?2222([0-9]{3})$] -1 4(5674) DEBUG: dialplan [dp_repl.c:628]: translate(): match check: [^(00|+)?3333([0-9]{3})$] -1 4(5674) DEBUG: dialplan [dp_repl.c:613]: translate(): regex operator testing over [00333387] ```
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-72834432
Rebased and changed dpl_get_avp_val() implementation using get_avp_val() as @miconda suggested
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-72860581
OK, I see now what you were looking for. I will think a bit about, because you remove the option of being able to use $(avp(x)[*]) as it returns for print.
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-73269648
What about having the $(avp(x)[*]) as it returns for print as the first value to check and then one value at the time?
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-74038126
It still changes the expected behaviour and somehow adds unnecessary complexity as I expect one wants a variant, not the both at the same time.
Perhaps the best is to have another index notation for this case, like: ``` $(avp(x)[+]) ``` or ``` $(avp(x)[**]) ```
The parser function of the index needs to be extended, but that should be easy. Then there are not many pvs using '*' index, thus would not be hard to propagate.
To decide: what to return in case of using the new index in print function (e.g., xlog) -- I would say the first value. CSV is available with '*'.
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-74041098
OK, ```$(avp(x)[+])``` seems nice and I will go for returning the first value on xlog. Agree?
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-74043585
ok - it could be defined as PV_IDX_ITR (from iterator).
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-74056918
Initial work introducing PV_INDX_ITR. Is there anything else to take care of?
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-74668548
It can be merge, testing will be easier afterwards ...
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-83662801
Closed #18.
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#event-259651626
Merged manually
--- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/pull/18#issuecomment-83687276