<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:915555109;
mso-list-type:hybrid;
mso-list-template-ids:712699186 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
{mso-level-number-format:bullet;
mso-level-text:\F0B7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Symbol;}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Kingsley,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I think the issue here is the nested variable name references. I think within route csv_filter, you are actually setting a variable called “$var(N11_resultvar_name)”, not a variable with the name of the contents of that variable.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I believe you can easily confirm this with two things:<o:p></o:p></p>
<ul style="margin-top:0in" type="disc">
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1">Remove (or ignore) the parameter providing the variable name and hardcode it to “N9_hdrval” in csv_filter for a test. You should see the variable is now set when printed after.<o:p></o:p></li></ul>
<p class="MsoListParagraph">and/or<o:p></o:p></p>
<ul style="margin-top:0in" type="disc">
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1">Add another log after csv_filter that prints the contents of $var($var(N11_resultvar_name)). I think you will find it also contains the correct value.<o:p></o:p></li></ul>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><span style="color:black">Ben Newlin </span><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Users <users-bounces@lists.opensips.org> on behalf of Kingsley Tart <kingsley@dns99.co.uk><br>
<b>Date: </b>Friday, May 7, 2021 at 1:08 PM<br>
<b>To: </b>Liviu Chircu <liviu@opensips.org>, OpenSIPS users mailling list <users@lists.opensips.org><br>
<b>Subject: </b>Re: [OpenSIPS-Users] routing function variable scope<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">On Wed, 2021-04-28 at 15:27 +0300, Liviu Chircu wrote:<br>
> On 28.04.2021 15:19, Kingsley Tart wrote:<br>
> > Is there a better way, apart from trying to make sure that<br>
> > variables in<br>
> > each function don't share names with variables in other functions?<br>
> <br>
> No, you have to manage those iterator names and make sure the logic <br>
> still holds during nested calls.<br>
<br>
Hi,<br>
<br>
I have now ran into the opposite problem! Given that values seem to be<br>
globally shared, I am now trying to use a sub-function to set the value<br>
of a $var() variable from a parent function, but the changed value gets<br>
lost when the sub function quits.<br>
<br>
Here is the code:<br>
<br>
route[bhah] {<br>
xlog("ALLOW BEFORE=\"$var(N9_hdrval)\"\n");<br>
route(csv_filter, $var(N9_hdrval), "(?i)^ *(OPTIONS|INVITE|ACK|BYE|CANCEL|UPDATE|PRACK|MESSAGE) *$", "N9_hdrval");<br>
xlog("ALLOW AFTER=\"$var(N9_hdrval)\"\n");<br>
}<br>
<br>
<br>
route[csv_filter] {<br>
$var(N11_srcCSV) = $param(1);<br>
$var(N11_filter_regex) = $param(2);<br>
$var(N11_resultvar_name) = $param(3);<br>
<br>
$var(N11_result) = "";<br>
$var(N11_pos) = $(var(N11_srcCSV){csv.count}) - 1;<br>
while ($var(N11_pos) >= 0) {<br>
$var(N11_element) = $(var(N11_srcCSV){csv.value,$var(N11_pos)});<br>
if (pcre_match($var(N11_element), $var(N11_filter_regex))) {<br>
$var(N11_result) = $var(N11_element) + "," + $var(N11_result);<br>
}<br>
$var(N11_pos) = $var(N11_pos) - 1;<br>
}<br>
$var(N11_resultLen) = $(var(N11_result){s.len}) - 1;<br>
$var($var(N11_resultvar_name)) = $(var(N11_result){s.substr,0,$var(N11_resultLen)});<br>
xlog("FILTERED var($var(N11_resultvar_name))=\"$var($var(N11_resultvar_name))\"\n");<br>
}<br>
<br>
<br>
But this is what gets logged:<br>
<br>
opensips[21955]: ALLOW BEFORE="OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, REFER, MESSAGE"<br>
opensips[21955]: FILTERED var(N9_hdrval)="OPTIONS, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE"<br>
opensips[21955]: ALLOW AFTER="OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, REFER, MESSAGE"<br>
<br>
<br>
This is what I was hoping to get:<br>
<br>
opensips[21955]: ALLOW BEFORE="OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, REFER, MESSAGE"<br>
opensips[21955]: FILTERED var(N9_hdrval)="OPTIONS, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE"<br>
opensips[21955]: ALLOW AFTER="OPTIONS, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE"<br>
<br>
<br>
Have I done something silly here?<br>
<br>
Cheers,<br>
Kingsley.<br>
<br>
<br>
_______________________________________________<br>
Users mailing list<br>
Users@lists.opensips.org<br>
<a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><o:p></o:p></p>
</div>
</div>
</body>
</html>