User Tools

Site Tools


tutorials:faq:main

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
tutorials:faq:main [2019/08/02 17:10]
henningw [General]
tutorials:faq:main [2020/10/15 08:32]
miconda
Line 191: Line 191:
 </code> </code>
  
 +??? Why parts of From/To header appear many times?
 +
 +!!! After doing header management operations, it can result that parts of From/To header are duplicated or the result is the concatenation of many values. That is related to previous question, because the changes are not applied immediately and updates to parts of headers are not a simple set operation.
 +
 +For example, if From username is "alice" and the operations in the config file are:
 +
 +<code c>
 +$fU = "bob";
 +...
 +$fU = "carol";
 +</code>
 +
 +The result can be that From username is "bobcarol".
 +
 +One solution is to use **msg_apply_changes()** in between:
 +
 +<code c>
 +$fU = "bob";
 +msg_apply_changes();
 +...
 +$fU = "carol";
 +</code>
 +
 +Another solution is to keep the value in a variable (e.g., avp or xavp) and do the operation only once, like:
 +
 +<code c>
 +$xavp(fuser) = "bob";
 +...
 +$xavp(fuser[0]) = "carol";
 +...
 +$fU = $xavp(fuser);
 +</code>
 +
 +Updating From/To headers is recommended to be done in **branch_route**, specially if it is needed to have different value for outgoing branches.
 +
 +The examples above were with assignments to $fU (can be other vars as well, such as $fu, $tU, $tu, ..), but it is the same behaviour when using functions such as uac_replace_from() or uac_replace_to().
  
 ??? How to set different header values for each destination of a SIP request? ??? How to set different header values for each destination of a SIP request?
Line 516: Line 552:
 ??? How to iterate through the items in a comma separated string? ??? How to iterate through the items in a comma separated string?
  
-!!! If you have a variable holding a string like "a,b,c,d" and want to get each character separately, you have to use a WHILE loop and {s.select,index,separator} transformationIf there is no value at the given index, then the transformation will return $nullthus you have to use a variable as index, incrementing it until you get a $null.+!!! If you have a variable holding a string like "a,b,c,d" and want to get each character separately, you have to use a WHILE loop with {s.count,separator} and {s.select,index,separator} transformations.
  
 Here is an example: Here is an example:
Line 523: Line 559:
 $var(x) = "a,b,c,d"; $var(x) = "a,b,c,d";
 $var(i) = 0; $var(i) = 0;
 +$var(n) = $(var(x){s.count,,});
  
-while( $(var(x){s.select,$var(i),,})!=$null ) {+while( $var(i<= $var(n) ) {
    xlog("token at position $var(i) is: $(var(x){s.select,$var(i),,})\n");    xlog("token at position $var(i) is: $(var(x){s.select,$var(i),,})\n");
    $var(i) = $var(i) + 1;    $var(i) = $var(i) + 1;
tutorials/faq/main.txt ยท Last modified: 2021/08/27 08:11 by miconda