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

SourceForge.net noreply at sourceforge.net
Tue Oct 6 17:08:55 CEST 2009


Bugs item #2868064, was opened at 2009-09-27 15:27
Message generated for change (Comment added) made by anca_vamanu
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: Anca Vamanu (anca_vamanu)
Date: 2009-10-06 18:08

Message:
Hi,
 
Indeed, when all indexes were requires and the first values were empty
string, they did not appear in the print. I have fixed that now. Please
update. But still I can not understand why you have problems with that
index 7. Here is my code:
	$avp(tp_trunkprefix) = "";
	$avp(tp_trunkprefix) = "";
	$avp(tp_trunkprefix) = "011";
	$avp(tp_trunkprefix) = "+";
	$avp(tp_trunkprefix) = "";
	$avp(tp_trunkprefix) = "00000";
	$avp(tp_trunkprefix) = "";
	$avp(tp_trunkprefix) = "";
	$avp(tp_trunkprefix) = "";
	$avp(tp_trunkprefix) = "";

	$avp(index) = 7;

	xlog("all: =$(avp(tp_trunkprefix)[*])\n");
	xlog("index=$avp(index) avp=$(avp(tp_trunkprefix)[$avp(index)])\n");
	$(avp(tp_trunkprefix)[$avp(index)])="";
	xlog("all after: =$(avp(tp_trunkprefix)[*])\n");
	xlog("index=$avp(index) avp=$(avp(tp_trunkprefix)[$avp(index)])\n");

	xlog("Printed\n");

And the result is:
all: =, , , , 00000, , +, 011, , , 
index=7 avp=011
all after: =, , , , 00000, , +, , , , 
index=7 avp=
Printed

Regards,
Anca


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

Comment By: Sergey Okhapkin (sokhapkin)
Date: 2009-10-06 17:44

Message:
One more note, empty avp values were not skipped before you made pvar fix:

Revision 6216 - (download) (annotate)
Mon Oct 5 15:19:10 2009 UTC (23 hours, 24 minutes ago) by anca_vamanu
File size: 94688 byte(s)

- fixed bug in pvar replace with index, problem when index was a pvar
(reported by Sergey Okhapkin, bug #2868064)


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

Comment By: Sergey Okhapkin (sokhapkin)
Date: 2009-10-06 17:27

Message:
As i noted already, xlog("all values: $(avp(tp_trunkprefix)[*])\n"); prints
NOT ALL values of indexed avp. Here are corresponding lines from
avp_print(), tp_trunkprefix is an alias for i:318.

INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=< / 0>
INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=< / 0>
INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=< / 0>
INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=< / 0>
INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=<00000 / 5>
INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=< / 0>
INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=<+ / 1>
INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=<011 / 3>
INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=< / 0>
INFO:avpops:ops_print_avp:                      id=<318>
INFO:avpops:ops_print_avp:                      val_str=< / 0>

avp[7] contains "011", xlog doesn't print first 4 empty sring values.


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

Comment By: Anca Vamanu (anca_vamanu)
Date: 2009-10-06 16:54

Message:
Hi,

Looking at you example it seems right and I don;t know why you expect
different results.
all values: 00000, , +, 011, ,
index=7 avp=
The avp at index 7 is in fact the eight element in the list. But as you
can see there are only 6 elements in the list. You can not have NULL values
and the empty string values appear there, so there are only 6 elements in
the list. Please try with a smaller index, 2 for example, will replace +
with empty string.

Regards,
Anca


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

Comment By: Sergey Okhapkin (sokhapkin)
Date: 2009-10-06 14: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 10: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 19: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 18: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 15: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 15: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 15: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 14: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-30 00: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 14: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 14: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 14: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