Re: [SR-Users] How to determine size (number of elements) in xavp stack?

2021-11-09 Thread Daniel-Constantin Mierla
Ahh, right, xavp_count() -- didn't remember about it, although I
implemented the function :-) .

Cheers,
Daniel

On 09.11.21 13:17, Chaigneau, Nicolas wrote:
> A C function already exists for that: xavp_count.
> Hereafter, the code for a PV that I added to a custom module to do the job.
>
>
>
> static pv_export_t mod_pvs[] = {
>   {STR_STATIC_INIT("xavp_size"), PVT_OTHER, pv_getf_xavp_size, 0, 
> pv_parse_string, 0, 0, 0},
>   /* Usage: $xavp_size( name );
>* Get the number of rows stored in xavp "name".
>* Result is integer: the number of rows.
>*/
>
>   { {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
> };
>
>
> /**
>  * Get the number of rows stored in an xavp.
>  */
> static int pv_getf_xavp_size(struct sip_msg *msg, pv_param_t *param, 
> pv_value_t *res)
> {
>   if (msg == NULL || param == NULL || param->pvn.type != PV_NAME_INTSTR) {
>   LM_ERR("Invalid parameters\n");
>   return -1;
>   }
>
>   int c = xavp_count(>pvn.u.isname.name.s, NULL);
>
>   return pv_get_sintval(msg, param, res, c);
> }
>
> /**
>  * Invoked upon server startup.
>  * Parse "" and store the string.
>  */
> static int pv_parse_string(pv_spec_p sp, str *in)
> {
>   if (sp == NULL || in == NULL || in->len <= 0) {
>   LM_ERR("Invalid parameters\n");
>   return -1;
>   }
>
>   LM_DBG("in: [%.*s]\n", in->len, in->s);
>
>   str pvs;
>   pvs = *in;
>   trim();
>
>   sp->pvp.pvn.type = PV_NAME_INTSTR;
>   sp->pvp.pvn.u.isname.type = AVP_NAME_STR;
>   sp->pvp.pvn.u.isname.name.s = pvs;
>
>   return 0;
> }
>
>
>
> -Message d'origine-
> De : sr-users  De la part de 
> Daniel-Constantin Mierla
> Envoyé : mardi 9 novembre 2021 08:33
> À : Kamailio (SER) - Users Mailing List; Benoît Panizzon
> Objet : Re: [SR-Users] How to determine size (number of elements) in xavp 
> stack?
>
> ***This mail has been sent by an external source***
>
> Hello,
>
> I do not remember any function to count xavps at this moment, it can be added 
> of course if someone wants to make a pull request. Otherwise, the options is 
> looping with index through all xavps for the name you want. A c function will 
> have to do the same, internally there is no field keeping the number of 
> avp/xavp with same name.
>
> Cheers,
> Daniel
>
> On 08.11.21 16:21, Benoît Panizzon wrote:
>> Dear Community
>>
>> In my previous post I mentioned my problem with sql_xquery
>>
>> I fear I used this wrong.
>>
>> $dbr is probably only populated if sql_query is used. Anyway, it is 
>> always 0 in my testings, even if I clearly get a result.
>>
>> Now I would like to know how many results I have. How can I determine 
>> the size of an $xavp stack (or array)?
>>
>> Or is there another way to get the number of rows returned by a 
>> sql_xquery without looping an index through all rows?
>>
>> --
>> Mit freundlichen Grüssen
>>
>> -Benoît Panizzon- @ HomeOffice und normal erreichbar
>> -- 
>> I m p r o W a r e   A G-Leiter Commerce Kunden
>> __
>>
>> Zurlindenstrasse 29 Tel  +41 61 826 93 00
>> CH-4133 PrattelnFax  +41 61 826 93 01
>> Schweiz Web  http://www.imp.ch
>> __
>>
>> __
>> Kamailio - Users Mailing List - Non Commercial Discussions
>>   * sr-users@lists.kamailio.org
>> Important: keep the mailing list in the recipients, do not reply only to the 
>> sender!
>> Edit mailing list options or unsubscribe:
>>   * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
> --
> Daniel-Constantin Mierla -- www.asipto.com www.twitter.com/miconda -- 
> www.linkedin.com/in/miconda Kamailio Advanced Training - Online Nov 08-11, 
> 2021 (Europe Timezone) - Feb 21-24, 2022 (America Timezone)
>   * https://www.asipto.com/sw/kamailio-advanced-training-online/
>
>
> __
> Kamailio - Users Mailing List - Non Commercial Discussions
>   * sr-users@lists.kamailio.org
> Important: keep the mailing list in the recipients, do not reply only to the 
> sender!
> Edit mailing list options or unsubscribe:
>   * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
> This message contains information that may be privileged or confidential and 
> is the property of the Capgemini Group. It is intended only for the person to 
> whom it is addressed. If you are not the intended recipient, you are not 
> authorized to read, print, retain, copy, disseminate, distribute, or use this 
> message or any part thereof. If you receive this message in error, please 
> notify the sender immediately and delete all copies of this message.

-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio Advanced Training - Online
Nov 08-11, 2021 (Europe Timezone) - Feb 21-24, 2022 

Re: [SR-Users] How to determine size (number of elements) in xavp stack?

2021-11-08 Thread Daniel-Constantin Mierla
Hello,

I do not remember any function to count xavps at this moment, it can be
added of course if someone wants to make a pull request. Otherwise, the
options is looping with index through all xavps for the name you want. A
c function will have to do the same, internally there is no field
keeping the number of avp/xavp with same name.

Cheers,
Daniel

On 08.11.21 16:21, Benoît Panizzon wrote:
> Dear Community
>
> In my previous post I mentioned my problem with sql_xquery
>
> I fear I used this wrong.
>
> $dbr is probably only populated if sql_query is used. Anyway, it is
> always 0 in my testings, even if I clearly get a result.
>
> Now I would like to know how many results I have. How can I determine
> the size of an $xavp stack (or array)?
>
> Or is there another way to get the number of rows returned by a
> sql_xquery without looping an index through all rows?
>
> -- 
> Mit freundlichen Grüssen
>
> -Benoît Panizzon- @ HomeOffice und normal erreichbar
> -- 
> I m p r o W a r e   A G-Leiter Commerce Kunden
> __
>
> Zurlindenstrasse 29 Tel  +41 61 826 93 00
> CH-4133 PrattelnFax  +41 61 826 93 01
> Schweiz Web  http://www.imp.ch
> __
>
> __
> Kamailio - Users Mailing List - Non Commercial Discussions
>   * sr-users@lists.kamailio.org
> Important: keep the mailing list in the recipients, do not reply only to the 
> sender!
> Edit mailing list options or unsubscribe:
>   * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users

-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio Advanced Training - Online
Nov 08-11, 2021 (Europe Timezone) - Feb 21-24, 2022 (America Timezone)
  * https://www.asipto.com/sw/kamailio-advanced-training-online/


__
Kamailio - Users Mailing List - Non Commercial Discussions
  * sr-users@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:
  * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users


[SR-Users] How to determine size (number of elements) in xavp stack?

2021-11-08 Thread Benoît Panizzon
Dear Community

In my previous post I mentioned my problem with sql_xquery

I fear I used this wrong.

$dbr is probably only populated if sql_query is used. Anyway, it is
always 0 in my testings, even if I clearly get a result.

Now I would like to know how many results I have. How can I determine
the size of an $xavp stack (or array)?

Or is there another way to get the number of rows returned by a
sql_xquery without looping an index through all rows?

-- 
Mit freundlichen Grüssen

-Benoît Panizzon- @ HomeOffice und normal erreichbar
-- 
I m p r o W a r e   A G-Leiter Commerce Kunden
__

Zurlindenstrasse 29 Tel  +41 61 826 93 00
CH-4133 PrattelnFax  +41 61 826 93 01
Schweiz Web  http://www.imp.ch
__

__
Kamailio - Users Mailing List - Non Commercial Discussions
  * sr-users@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:
  * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users