I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2011-04-12 09:59:58.439121-07 by dmw
Simple.pm : register() can return wrong 'expires' value

Net::SIP::Simple->register() can return wrong 'expires' value


I think that the handling of expires value in the register() function is incorrect. The current logic in the function is this:


1) get value from Expires: header
2) examine contacts only if Expires is not defined (this is backwards, Expires should be fallback value, not priority)
3) examine *all* contacts returned in Contact: header, regardless if they are us (this is clearly wrong too, it should only evaluate the contact that matches us)
4) use the smallest expires value found among all contacts (this doesn't make sense to me)


the logic should be, imo:


1) get value from Expires: header
2) find *our* contact in Contact: header.
  a) If not found, expires should be set to 0 (== we're not registered)
  b) if contact found, and contains expires param, use that value
  c) if contact found, and no expires param, fall back to value from Expires header
  d) if contact found, quit looking (there should only be one contact to match ours, afaik)

here's a patch with uses this new logic:

~# diff -u /root/.cpan/build/Net-SIP-0.62-Ia3TBm/lib/Net/SIP/Simple.pm /usr/local/share/perl/5.10.0 +/Net/SIP/Simple.pm --- /root/.cpan/build/Net-SIP-0.62-Ia3TBm/lib/Net/SIP/Simple.pm 2010-05-31 02:51:59.000000000 -0700 +++ /usr/local/share/perl/5.10.0/Net/SIP/Simple.pm 2011-04-12 08:59:09.000000000 -0700 @@ -323,14 +323,23 @@ my $cb = sub { my ($self,$cb_final,$expires,$endpoint,$ctx,$errno,$code,$packet,$leg,$from) = @_; if ( $code && $code =~m{^2\d\d} ) { + # prevailing logic should go like this: + # if we have a contact match, and ... + # if contact has 'expires' param, use this value + # else use Expires header + # else if response contains no contacts to match ours, our registration is expired, so return +0 my $exp = $packet->get_header( 'Expires' ); - if ( ! defined $exp ) { - foreach my $c ( $packet->get_header( 'contact' ) ) { - my ($addr,$p) = sip_hdrval2parts( contact => $c ); - defined( my $e = $p->{expires} ) || next; - $exp = $e if ! defined($exp) || $e < $exp; + my $match = 0; + foreach my $c ($packet->get_header( 'contact' )) { + my ($addr,$p) = sip_hdrval2parts( contact => $c ); + if ($match = sip_uri_eq($contact,$addr) ) { + $exp = $p->{expires} if defined $p->{expires}; + last; } } + + $exp = 0 unless $match; + $$expires = $exp; invoke_callback( $cb_final, 'OK', expires => $exp );
Direct Responses: 13306 | 13309 | Write a response
Posted on 2011-04-12 22:22:24.521501-07 by bukvy in response to 13305
Re: Simple.pm : register() can return wrong 'expires' value
Thank. But I wonder, had someone tried this module with real VoIP? And were there some good results ( and what VoIP it was) ? For I have not been successful with www.sipnet.ru .
Direct Responses: 13308 | Write a response
Posted on 2011-04-14 22:53:31.476746-07 by noxxi in response to 13306
Re: Simple.pm : register() can return wrong 'expires' value
Yes, there are various people using it, reporting bugs and also add new features. Just have a look at the Changes file where the bug reports and sometimes fixes come from. But, it has a version number <1.0 for a reason :)
Direct Responses: Write a response
Posted on 2011-04-14 22:57:18.798413-07 by noxxi in response to 13305
Re: Simple.pm : register() can return wrong 'expires' value
Thanks for reporting the bug and I'll try to add the fix to the next version. But for more bugs I would ask you to use the perl biugtracking system to report bugs, it makes it easier to track.
E.g. use perlbug or report via https://rt.cpan.org/Public/Dist/Display.html?Name=Net-SIP
Direct Responses: 13310 | Write a response
Posted on 2011-04-14 23:26:36.605624-07 by noxxi in response to 13309
Re: Simple.pm : register() can return wrong 'expires' value
fix is uploaded to CPAN in 0.62_6, see also https://github.com/noxxi/p5-net-sip
Direct Responses: Write a response