<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<tt>Hi Pat,<br>
<br>
OK :).<br>
<br>
Well, the usage of the -1 index is inconsistent with the rest of
the indexes - for positive indexes are used to "overwrite" an
existing value, not to add a new one. This is why the usage of -1
to add may be misleading, as you would expect to actually
overwrite the last value :).<br>
<br>
I committed a patch on trunk/2.3 that adds the "append" index for
AVPs :<br>
$(avp(name)[append]) = "last value";<br>
<br>
<a class="moz-txt-link-freetext" href="https://github.com/OpenSIPS/opensips/commit/466fbf045179188c39fefe5b48ec581c37023a5b">https://github.com/OpenSIPS/opensips/commit/466fbf045179188c39fefe5b48ec581c37023a5b</a><br>
<br>
You may consider using it (it is fully 2.2 compatible) and
starting with 2.3 version you will get rid of additional patches
;).<br>
<br>
Regards,<br>
</tt>
<pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
<div class="moz-cite-prefix">On 12.10.2016 18:02, Pat Burke wrote:<br>
</div>
<blockquote
cite="mid:dd29af11dfbb21496fc5b93810c76c68@voxtelesys.com"
type="cite">
<title></title>
<div class="iw_mail" dir="ltr">
<div>Hello Bogdan,</div>
<div><br>
</div>
<div>You are exactly correct. We have a patch in pv_set_avp in
pvar.c that allows -1. I don't know who put that in, but it
works great. I will put the patch into my 2.2 code.</div>
<div><br>
</div>
<div>The method was updated to</div>
<div>
<div> if(idxf == PV_IDX_INT || idxf == PV_IDX_PVAR) /*
if the avp is indexed */</div>
<div> {</div>
<div> if (idx == -1) { </div>
<div> if (add_avp_last(flags, avp_name,
avp_val)<0) {</div>
<div> LM_ERR("error - cannot
add AVP\n");</div>
<div> goto error;</div>
<div> }</div>
<div> } else if(replace_avp(flags, avp_name,
avp_val, idx)< 0) {</div>
<div> LM_ERR("Failed to replace
avp\n");</div>
<div> goto error;</div>
<div> }</div>
<div> }</div>
<div> </div>
</div>
<div><br>
</div>
<div>from</div>
<div><br>
</div>
<div>
<div> if(idxf == PV_IDX_INT || idxf == PV_IDX_PVAR) /*
if the avp is indexed */</div>
<div> {</div>
<div> if(replace_avp(flags, avp_name, avp_val,
idx)< 0)</div>
<div> {</div>
<div> LM_ERR("Failed to replace
avp\n");</div>
<div> goto error;</div>
<div> }</div>
<div> }</div>
<div> </div>
</div>
<div>Thanks again,</div>
<div>Pat Burke</div>
<div><br>
</div>
<br>
<br>
<blockquote class="reply_block" dir="ltr" style="border-left:
2px solid blue; margin: 5pt 0 5pt 10pt; padding: 0 0 0 5pt;
font-size: 13px; font-family: tahoma,helvetica,sans-serif;">
<hr size="1">-----Original Message-----<br>
From: "Bogdan-Andrei Iancu" <<a moz-do-not-send="true"
href="mailto:bogdan@opensips.org">bogdan@opensips.org</a>><br>
To: "OpenSIPS users mailling list" <<a
moz-do-not-send="true"
href="mailto:users@lists.opensips.org">users@lists.opensips.org</a>>,
"Pat Burke" <<a moz-do-not-send="true"
href="mailto:pat@voxtelesys.com">pat@voxtelesys.com</a>><br>
Date: 10/12/16 03:47<br>
Subject: [Spam] Re: [OpenSIPS-Users] OpensSIPS 2.2 - avps with
an index of -1<br>
<br>
<tt>Hi Pat,<br>
<br>
Are you sure the -1 index works for you? I just tested with
an 1.11 code and got:<br>
<br>
Oct 12 11:35:12 [29913] ERROR:core:replace_avp: Index with
negative value<br>
Oct 12 11:35:12 [29913] ERROR:core:pv_set_avp: Failed to
replace avp<br>
Oct 12 11:35:12 [29913] ERROR:core:do_assign: setting PV
failed<br>
<br>
I don't think negative indexes were ever supported for AVPs.<br>
<br>
Are you sure you do not have a patch for 1.11 to allow
negative values ?<br>
<br>
Regards,<br>
</tt>
<pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
<div class="moz-cite-prefix">On 12.10.2016 03:04, Pat Burke
wrote:<br>
</div>
<blockquote
cite="mid:cd746f68a1af900ee0b36437d54fa6c6@voxtelesys.com"
type="cite">
<div class="iw_mail" dir="ltr">In OpenSIPS 1.11 you were
able to use the index of -1 on AVP's to put items into an
AVP as a FIFO instead of a LIFO.
<div><br>
</div>
<div>Here is what I mean.</div>
<div><br>
</div>
<div>$(avp(list)[-1]) = 1;</div>
<div>$(avp(list)[-1]) = 2;<br>
<div>$(avp(list)[-1]) = 3;</div>
<div>
<div>$(avp(list)[-1]) = 4;</div>
</div>
<div>
<div>$(avp(list)[-1]) = 5;</div>
</div>
<div><br>
</div>
<div>this would result the values coming off as a FIFO</div>
<div>$avp(list) is 1</div>
<div>
<div>$avp(list) = NULL;</div>
<div>$avp(list) is 2</div>
</div>
<div>
<div>$avp(list) = NULL;</div>
<div>$avp(list) is 3</div>
</div>
<div>
<div>$avp(list) = NULL;</div>
<div>$avp(list) is 4</div>
</div>
<div>
<div>$avp(list) = NULL;</div>
<div>$avp(list) is 5</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Just pushing the items onto the AVP creates a LIFO</div>
<div>
<div>$avp(list) = 1;</div>
<div>
<div>
<div>$avp(list) = 2;</div>
</div>
<div>
<div>$avp(list) = 3;</div>
</div>
<div>
<div>$avp(list) = 4;</div>
</div>
<div>
<div>$avp(list) = 5;</div>
</div>
<div>
<div><br>
</div>
</div>
<div>this would result the values coming off as</div>
<div>$avp(list) is 5</div>
<div>
<div>$avp(list) = NULL;</div>
<div>$avp(list) is 4</div>
</div>
<div>
<div>$avp(list) = NULL;</div>
<div>$avp(list) is 3</div>
</div>
<div>
<div>$avp(list) = NULL;</div>
<div>$avp(list) is 2</div>
</div>
<div>
<div>$avp(list) = NULL;</div>
<div>$avp(list) is 1</div>
</div>
</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>So my question is how do I create a FIFO without
having to keep an index to ensure that I am adding the
item to the end. When porting the code from 1.11 to
2.2 I get an error "ERROR:core:replace_avp: Index with
negative value" when I use the -1.</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div style="font-family: arial, helvetica, sans-serif;
font-size: 16px;"><span data-mce-style="color:
#808080; font-family: arial,helvetica,sans-serif;
font-size: 11pt;" style="color: rgb(128, 128,
128); font-size: 11pt;">Regards,</span></div>
<div style="font-family: arial, helvetica, sans-serif;
font-size: 16px;">
<span data-mce-style="color: #808080; font-family:
arial,helvetica,sans-serif; font-size: 11pt;"
style="color: rgb(128, 128, 128); font-size:
11pt;"><strong>Pat Burke</strong></span><br>
<br>
<div><br>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Users mailing list<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a></pre>
</blockquote>
<br>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>