[sr-dev] How to get dialog duration in miliseconds?
Mino Haluz
mino.haluz at gmail.com
Mon Feb 11 08:33:30 CET 2013
Thanks, yes, I already solved it like this:
int pv_get_timenows2(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
//time_t t;
struct timeval tv;
char buf[30];
str _s;
gettimeofday(&tv, NULL);
unsigned long long msEpoch =
(unsigned long long)(tv.tv_sec) * 1000 +
(unsigned long long)(tv.tv_usec) / 1000;
_s.len = sprintf(buf, "%lld", msEpoch);
_s.s = (char *)malloc(_s.len+1);
strcpy(_s.s, buf);
return pv_get_strval(msg, param, res, &_s);
}
I know that it is rather C related question, but I would like to avoid some
memory leaks in kamailio.
pv_get_strval seems to be some builtin kamailio function, so the question
is, does it free _s.s automatically ?
Mino
On Fri, Feb 8, 2013 at 10:14 PM, Daniel-Constantin Mierla <miconda at gmail.com
> wrote:
> The problem is that buf is allocated on the stack, on a zone reserved for
> pv_get_timenows2() function, which is destroyed as soon as the function
> execution ends.
>
> You either define buf as static, or you allocate it dynamically in the
> function and free it later.
>
> Cheers,
> Daniel
>
>
> On 2/7/13 7:25 PM, Mino Haluz wrote:
>
> I added new pseudovariale $TMS which gives time in miliseconds. If I print
> $TMS value it is ok, but when I assign it to avp, it gives strange values.
>
> pv_time.c
>
> int pv_get_timenows2(struct sip_msg *msg, pv_param_t *param,
> pv_value_t *res)
> {
> struct timeval tv;
> char buf[30];
> str _s;
> gettimeofday(&tv, NULL);
> unsigned long long msEpoch =
> (unsigned long long)(tv.tv_sec) * 1000 +
> (unsigned long long)(tv.tv_usec) / 1000;
> _s.len = sprintf(buf, "%lld", msEpoch);
> _s.s = buf; //<------- I think problem is here
> return pv_get_strval(msg, param, res, &_s);
> }
>
> So how should I properly copy buf to _s ?
>
> Thanks,
> Mino
>
>
>
>
>
> On Thu, Feb 7, 2013 at 11:00 AM, Mino Haluz <mino.haluz at gmail.com> wrote:
>
>> Hi,
>>
>> I assume there is no avp or function which could give me duration of
>> ended dialog in miliseconds (I have to send it in RADIUS message). I can
>> run some bash script which could return me this value but seems to me bit
>> awkward.
>>
>> How you would do it? To adjust dialog module so that it could return it
>> to some avp value within dialog-end event route and thus save it to radius?
>>
>> Mino
>>
>
>
>
> _______________________________________________
> sr-dev mailing listsr-dev at lists.sip-router.orghttp://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
>
> --
> Daniel-Constantin Mierla - http://www.asipto.comhttp://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
> Kamailio World Conference, April 16-17, 2013, Berlin
> - http://conference.kamailio.com -
>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20130211/f5594819/attachment.htm>
More information about the sr-dev
mailing list