Posted on 2010-01-27 02:38:51.929313-08 by koyot
URI problem through NET::SIP::Response ?! or maybe it's me :P
Yop, I'm playing around with this pretty cool module, but I got a issue when it's delivering a response, it looks like the method to get/resolve the URI from a packet forged by Response.pm it's not accessible (Inherit problem ?!). I'm too lazy to dig, and i just tweaked it by putting in static an URI into Dispatcher.pm, hopefully I'm just playing with one peer :P Anyway below you'll find a piece of code showing my problem ;-) The code is just replying a 200 OK to any REGISTER.
#!/usr/bin/perl -w use strict; use warnings; use Net::SIP; my $loop = Net::SIP::Dispatcher::Eventloop->new; my $leg = Net::SIP::Leg->new(addr => '127.0.0.1'); my $disp = Net::SIP::Dispatcher->new( [ $leg ], $loop, ); $disp->set_receiver(\&receive); $loop->loop; sub receive { my ($packet,$leg,$from_addr) = @_; print "\nPacket IN:\n"; print $packet->as_string; my ($request,$response) = $packet->is_request ? ($packet, undef) : (undef, $packet); my $cseq = $packet->cseq; my ($num,$method) = split( ' ', $cseq); if($request) { if($method eq 'REGISTER') { my $resp = $request->create_response('200', 'OK'); print "\nPacket OUT:\n"; print $resp->as_string; $disp->deliver($resp); } } }

To test this tiny server, i'm using sipsak
sipsak -vvvv -U -s sip:nobody@127.0.0.1:5060

test.pl - outpout :
Packet IN: REGISTER sip:127.0.0.1:5060 SIP/2.0 Via: SIP/2.0/UDP 192.168.10.102:50268;branch=z9hG4bK.1114d099;rport;alias From: sip:nobody@127.0.0.1:5060;tag=1fd46a2e To: sip:nobody@127.0.0.1:5060 Call-ID: 534014510@192.168.10.102 CSeq: 1 REGISTER Content-Length: 0 Max-Forwards: 70 User-Agent: sipsak 0.9.6 Expires: 15 Contact: sip:nobody@192.168.10.102:50268 Packet OUT: SIP/2.0 200 Ok Call-id: 534014510@192.168.10.102 Cseq: 1 REGISTER From: sip:nobody@127.0.0.1:5060;tag=1fd46a2e To: sip:nobody@127.0.0.1:5060 Via: SIP/2.0/UDP 192.168.10.102:50268;branch=z9hG4bK.1114d099;rport;alias Content-length: 0 Can't locate object method "uri" via package "Net::SIP::Response" at /usr/local/share/perl/5.10.0/N +et/SIP/Dispatcher.pm line 498.
By the way we can see as well that create_response doesn't switch the From / To of the received packed ;-) Regards and congrats for the good job ;-)
Direct Responses: 12264 | Write a response
Posted on 2010-01-27 05:38:30.103978-08 by noxxi in response to 12257
Re: URI problem through NET::SIP::Response ?! or maybe it's me :P
> sub receive { > my ($packet,$leg,$from_addr) = @_; > ... > my $resp = $request->create_response('200', 'OK'); > print "\nPacket OUT:\n"; > print $resp->as_string; > $disp->deliver($resp); > > Can't locate object method "uri" via package "Net::SIP::Response" at /usr/local/share/perl/5.10.0 +/Net/SIP/Dispatcher.pm line 498. It does not know where to deliver the packet, so it tries to look at a route header (non given) or at the URI. The latter fails, because it's a response object, not a request, and thus has no URI. Yes, it would be better to have a better error correction at this point :) Look at Net::SIP::Registrar where it solves the same problem. You have to give the leg and dst_addr to deliver, so that it knows where to deliver it: $disp->deliver($resp, leg => $leg, dst_addr => $from_addr ) > > By the way we can see as well that create_response doesn't switch the From / To of the received p +acked ;-) It should not switch them. See rfc3261, 8.2.6.2: The From field of the response MUST equal the From header field of the request..... If a request contained a To tag in the request, the To header field in the response MUST equal that of the request.
Direct Responses: 12271 | Write a response
Posted on 2010-01-27 18:24:41.785133-08 by koyot in response to 12264
Re: URI problem through NET::SIP::Response ?! or maybe it's me :P
Oky Thanks man for your reply, so it was my misunderstood ;-)
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.