[OpenSIPS-Users] Anyway to count the numbers of entires in a AVP?

Bogdan-Andrei Iancu bogdan at voice-system.ro
Mon Jun 21 16:00:19 CEST 2010


btw, we have full support for using json string (a more complex way of 
packing information that a simple CSV) - see 
http://www.opensips.org/html/docs/modules/1.6.x/json.html .

Also, if you do not want to deal with dynamic CSV tables, you can use 
even now the select transformation to extract each field.

Regards,
Bogdan

Brett Nemeroff wrote:
> That'd be fantastic
> $avp(s:values) = "8,5,6,9,2,4,5";
> $var(value_count) = $(avp(s:values){s.csv.count(\,)});
> $var(value_third)=$(avp(s:values){s.csv.select(\,,3)});
> $avp(s:value_array) = $(avp(s:values){s.csv.split(\,)});
> # Makes:
> # $avp(s:value_array)[0]=8;
> # $avp(s:value_array)[1]=5;
> # ...
> $avp(s:new_values) = $(avp(s:value_array){s.csv.join(\,)});
> # Makes $avp(s:new_values) == $avp(s:values);
> ... you get the idea.. typical string -> array funcs
>
>
> push, pop, first, last, min, max, avg.. All of those functions would 
> be really really really nice. Especially if they can handle floats. :D :D
> -Brett
>
> On Mon, Jun 21, 2010 at 8:40 AM, Bogdan-Andrei Iancu 
> <bogdan at voice-system.ro <mailto:bogdan at voice-system.ro>> wrote:
>
>     Ah, I see :) ....maybe we can make an new "csv" transformation....
>
>     Regards,
>     Bogdan
>
>     Brett Nemeroff wrote:
>     > Bogdan,
>     > Brad's AVP is a single AVP with  CSV. He'd like to count the
>     elements
>     > in the CSV.
>     >
>     > Some string array functions would be nice. :D
>     > -Brett
>     >
>     >
>     > On Mon, Jun 21, 2010 at 6:46 AM, Bogdan-Andrei Iancu
>     > <bogdan at voice-system.ro <mailto:bogdan at voice-system.ro>
>     <mailto:bogdan at voice-system.ro <mailto:bogdan at voice-system.ro>>>
>     wrote:
>     >
>     >     Hi Brad,
>     >
>     >     I guess you are looking for the set_count() function:
>     >
>     >    
>     http://www.opensips.org/html/docs/modules/1.6.x/cfgutils.html#id228574
>     >
>     >     Regards,
>     >     Bogdan
>     >
>     >
>     >     --
>     >     Bogdan-Andrei Iancu
>     >     OpenSIPS Bootcamp
>     >     20 - 24 September 2010, Frankfurt, Germany
>     >     www.voice-system.ro <http://www.voice-system.ro>
>     <http://www.voice-system.ro>
>     >
>     >
>     >
>     >     Brad Bendy wrote:
>     >     > Brett,
>     >     >
>     >     > I figured as much, but I thought I would try anyways.
>     >     >
>     >     > I think adding the "count" to the front the string is
>     going to be
>     >     > easiest method and use the select functions, much more
>     simpler!
>     >     >
>     >     > Thanks for the advice.
>     >     >
>     >     > On Sat, 2010-06-19 at 20:41 -0500, Brett Nemeroff wrote:
>     >     >
>     >     >> Brad,
>     >     >> param.count is for URI parameters and can't be used for
>     any old
>     >     >> format. If your string was in URI param format, I think it
>     >     would then
>     >     >> work:
>     >     >> http://www.opensips.org/Resources/DocsCoreTran16#toc36
>     >     >>
>     >     >>
>     >     >> I haven't used this transformation, but it appears you'd
>     take the
>     >     >> params off a URI and then use the transformations on the
>     params
>     >     >> themselves.
>     >     >>
>     >     >>
>     >     >> I think what I do to find out if I'm at the end is to use the
>     >     "select'
>     >     >> transformation and check the value of the return.
>     >     >>
>     >     >>
>     >     >> Alternatively, you *could* make the first element in your
>     list the
>     >     >> number of values to expect. Not sure if that's even an option
>     >     in your
>     >     >> case..
>     >     >>
>     >     >>
>     >     >> -Brett
>     >     >>
>     >     >>
>     >     >>
>     >     >>
>     >     >> On Sat, Jun 19, 2010 at 8:34 PM, Brad Bendy
>     >     >> <brad.bendy at benganetworks.com
>     <mailto:brad.bendy at benganetworks.com>
>     >     <mailto:brad.bendy at benganetworks.com
>     <mailto:brad.bendy at benganetworks.com>>> wrote:
>     >     >>         Hi list,
>     >     >>
>     >     >>         Ive got a AVP that gets a value from a memcached
>     store,
>     >     it's a
>     >     >>         set of
>     >     >>         integers separated by commas , ex: 4,34,1,10
>     >     >>
>     >     >>         Is there a way to return the number of entries?
>     In this
>     >     case
>     >     >>         id like to
>     >     >>         have a 4 returned.
>     >     >>
>     >     >>         I cannot get {param.count} to work, but im not
>     sure if it
>     >     >>         works like
>     >     >>         this or maybe im just not using is right.
>     >     >>
>     >     >>         Thanks for any help or suggestions
>     >     >>
>     >     >>
>     >     >>
>     >     >>
>     >     >>         _______________________________________________
>     >     >>         Users mailing list
>     >     >>         Users at lists.opensips.org
>     <mailto:Users at lists.opensips.org> <mailto:Users at lists.opensips.org
>     <mailto:Users at lists.opensips.org>>
>     >     >>        
>     http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>     >     >>
>     >     >>
>     >     >> _______________________________________________
>     >     >> Users mailing list
>     >     >> Users at lists.opensips.org
>     <mailto:Users at lists.opensips.org> <mailto:Users at lists.opensips.org
>     <mailto:Users at lists.opensips.org>>
>     >     >> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>     >     >>
>     >     >
>     >     >
>     >     > _______________________________________________
>     >     > Users mailing list
>     >     > Users at lists.opensips.org <mailto:Users at lists.opensips.org>
>     <mailto:Users at lists.opensips.org <mailto:Users at lists.opensips.org>>
>     >     > http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>     >     >
>     >     >
>     >
>     >
>     >     _______________________________________________
>     >     Users mailing list
>     >     Users at lists.opensips.org <mailto:Users at lists.opensips.org>
>     <mailto:Users at lists.opensips.org <mailto:Users at lists.opensips.org>>
>     >     http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>     >
>     >
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > Users mailing list
>     > Users at lists.opensips.org <mailto:Users at lists.opensips.org>
>     > http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>     >
>
>
>     --
>     Bogdan-Andrei Iancu
>     OpenSIPS Bootcamp
>     20 - 24 September 2010, Frankfurt, Germany
>     www.voice-system.ro <http://www.voice-system.ro>
>
>
>     _______________________________________________
>     Users mailing list
>     Users at lists.opensips.org <mailto:Users at lists.opensips.org>
>     http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>   


-- 
Bogdan-Andrei Iancu
OpenSIPS Bootcamp
20 - 24 September 2010, Frankfurt, Germany
www.voice-system.ro




More information about the Users mailing list