[OpenSIPS-Devel] [ opensips-Bugs-2868064 ] Assign to indexed AVP fails.

SourceForge.net noreply at sourceforge.net
Tue Oct 6 13:08:54 CEST 2009


Bugs item #2868064, was opened at 2009-09-27 08:27
Message generated for change (Comment added) made by sokhapkin
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=1086410&aid=2868064&group_id=232389

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: core
Group: trunk
Status: Open
Resolution: Fixed
Priority: 5
Private: No
Submitted By: Sergey Okhapkin (sokhapkin)
Assigned to: Anca Vamanu (anca_vamanu)
Summary: Assign to indexed AVP fails.

Initial Comment:
The construction mentioned at http://www.opensips.org/Main/News0041 to assign a value to indexed variable

$avp(i:1)[0]="value";

yelds an error message from cfg parser. The following operator

$(avp(tp_trunkprefix)[$avp(index)])="";

is parsed OK, but doesn't update AVP value, the value remains old after operator execution, no errors/warnings in opensips log.

----------------------------------------------------------------------

>Comment By: Sergey Okhapkin (sokhapkin)
Date: 2009-10-06 07:08

Message:
Here is the output. Some elements in avp(tp_trunkprefix) have NULL (or
empty string) values and are not printed.

all values: 00000, , +, 011, ,
index=7 avp=
all values: 00000, , +, 011, ,
index=7 avp=
index=1  avp=15
index=1  avp=
Printed


----------------------------------------------------------------------

Comment By: Anca Vamanu (anca_vamanu)
Date: 2009-10-06 03:38

Message:
Hi,

Please print all the value before the replace and after.
xlog("all values: $(avp(tp_trunkprefix)[*])\n");

Regards,
Anca

----------------------------------------------------------------------

Comment By: Sergey Okhapkin (sokhapkin)
Date: 2009-10-05 12:13

Message:
Now xlog prints wrong initial value:

index=7 avp=
index=7 avp=
index=1  avp=15
index=1  avp=
Printed

avp_print() prints correct values.

----------------------------------------------------------------------

Comment By: Anca Vamanu (anca_vamanu)
Date: 2009-10-05 11:23

Message:
Hi, 

You were right, the error was when the index was a pvar. It was a typo
error. Please update and test.

Thanks and regards,
Anca

----------------------------------------------------------------------

Comment By: Sergey Okhapkin (sokhapkin)
Date: 2009-10-05 08:57

Message:
Your example works, but mine does not:

xlog("L_INFO", "index=$avp(index)
avp=$(avp(tp_trunkprefix)[$avp(index)])\n");
$(avp(tp_trunkprefix)[$avp(index)])="";
xlog("L_INFO", "index=$avp(index)
avp=$(avp(tp_trunkprefix)[$avp(index)])\n");

$avp(i:10) = 5;
$avp(i:10) = 15;
$avp(i:10) = 40;

$avp(i:5) = 1;
xlog("L_INFO", "index=$avp(i:5)  avp=$(avp(i:10)[$avp(i:5)])\n");
$(avp(i:10)[$avp(i:5)])="";
xlog("L_INFO", "index=$avp(i:5)  avp=$(avp(i:10)[$avp(i:5)])\n");
xlog("Printed\n");

prints:

index=7 avp=011
index=7 avp=+
index=1  avp=15
index=1  avp=
Printed


----------------------------------------------------------------------

Comment By: Anca Vamanu (anca_vamanu)
Date: 2009-10-05 08:39

Message:
Hi,

I tried an example very close to yours:

	$avp(i:10) = 5;
	$avp(i:10) = 15;
	$avp(i:10) = 40;

	$avp(i:5) = 1;
	xlog("L_INFO", "index=$avp(i:5)  avp=$(avp(i:10)[$avp(i:5)])\n");
	$(avp(i:10)[$avp(i:5)])="";
	xlog("L_INFO", "index=$avp(i:5)  avp=$(avp(i:10)[$avp(i:5)])\n");
	xlog("Printed\n");



Result:

index=1  avp=15
index=1  avp=
Printed

Regards,
Anca

----------------------------------------------------------------------

Comment By: Sergey Okhapkin (sokhapkin)
Date: 2009-10-05 08:25

Message:
I put \n when print avp, see my code below.

Try an example closer to mine, where avp value is used as an index.

----------------------------------------------------------------------

Comment By: Anca Vamanu (anca_vamanu)
Date: 2009-10-05 07:34

Message:
Hi,

Maybe you don't put '\n' after printing the avp. 
I have tested exactly with this code:

	$avp(i:10) = 5;
	$avp(i:10) = 15;
	$avp(i:10) = 40;

	xlog("avp=$(avp(i:10)[1])\n");
	$(avp(i:10)[1]) ="";
	xlog("avp=$(avp(i:10)[1])\n");
	xlog("Printed\n");

And the result is the correct one:
avp=15
avp=
Printed

regards,
Anca

----------------------------------------------------------------------

Comment By: Sergey Okhapkin (sokhapkin)
Date: 2009-09-29 17:12

Message:
Doesn't work to me. Execution of 

xlog("L_INFO", "index=$avp(index)
avp=$(avp(tp_trunkprefix)[$avp(index)])\n");
$(avp(tp_trunkprefix)[$avp(index)])="";
xlog("L_INFO", "index=$avp(index)
avp=$(avp(tp_trunkprefix)[$avp(index)])\n");

prints

index=7 avp=011
index=7 avp=+


----------------------------------------------------------------------

Comment By: Anca Vamanu (anca_vamanu)
Date: 2009-09-29 07:55

Message:
Hi,

Sorry, I was mistaken, It does not delete the value, but it replaces it
with an empty string. I have tested now more closely
Also I have fixed the errors in the documentation that you reported.

Regards,
Anca

----------------------------------------------------------------------

Comment By: Sergey Okhapkin (sokhapkin)
Date: 2009-09-29 07:42

Message:
Well, I need to set AVP value at certain index to an empty string, but
still have an access to [index+1] value. How can I do that? I don't like
the whole idea across opensips to remove variables instead of allowing
empty strings.

Regarding first construct see examples at
http://www.opensips.org/Resources/DocsCoreVar :

# delete the value located at a certain index 
$avp(i:17)[1] = NULL;

#overwrite the value at a certain index
$avp(i:17)[0] = "zero";


----------------------------------------------------------------------

Comment By: Anca Vamanu (anca_vamanu)
Date: 2009-09-29 07:30

Message:
Hi Sergey,

The first example that you typed in your post is indeed wrong because it
does not respect the avp syntax with name and index. The  example that was
written there was to show that it is about setting the value at a certain
index pvar[_index_]=NULL. The correct syntax for pseudovariables is here:
http://www.opensips.org/Resources/DocsCoreVar.
As for the second excerpt, attributing a 0 length string to an avp value
at a certain index has the result of deleting that value, I have tested
myself now and it works, To check it out I suggest to print all the values
in the avp before the operation and after. xlog("all values
$(avp(tp_trunkprefix[*])\n)");

Regards,
Anca


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=1086410&aid=2868064&group_id=232389



More information about the Devel mailing list