| 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 |