I'm creating a simple application that registers to a ims core and then subscribes to the presence event package, I want to use this program to display changes in my presence to a console. I've gotten as far as registering, subscribing and receiving a notify but I can't seem to get the loop correct. The problem is that after registration I send out the subscribe over and over again. It seems that the timer isn't working properly. I've posted my code below as well as the debug 100 trace that seems like the problem.
use Net::SIP ':all';
# create new agent
use strict;
use warnings;
Net::SIP::Debug->level(100);
my $from = 'sip:+18563029050@ims.cableland.net';
my $to = 'sip:+18563029050@ims.cableland.net';
my $uri = 'sip:+18563029050@ims.cableland.net';
my $callid = '12345';
my $ua = Net::SIP::Simple->new(
outgoing_proxy => '10.253.24.93',
registrar => 'ims.cableland.net',
domain => 'ims.cableland.net',
from => 'sip:+18563029050@ims.cableland.net',
auth => [ '8563029050@ims.cableland.net','password' ],
);
# Register agent
print "registering user\n";
$ua->register;
print "creating subscribe message\n";
my $subscribe = Request->new( 'SUBSCRIBE', $uri, {
to => "<" . $uri .">",
from => "<" . $uri .">",
cseq => '1 SUBSCRIBE',
'call-id' => '12345',
contact => '<sip:+18563029050@10.253.24.174:5060>',
'event' => 'presence',
expires => '60000',
'P-Preferred-Identity' => "<" . $uri . ">",
'Accept' => 'application/pidf+xml'
});
print "setting up port to receive....\n";
$ua->{dispatcher}->set_receiver(\&receive);
$ua->add_timer(0,$ua->{dispatcher}->deliver($subscribe),30000);
my $stop_var = 0;
$ua->loop(60000,\$stop_var);
sub receive
{
print "packet received\n";
print "------------------\n";
my ($packet, $leg, $from_addr) = @_;
#print $packet->as_string;
my $callid = $packet->callid() or do {
DEBUG( 1, "no callid in packet. DROP" );
return;
};
my ( $request,$response ) = $packet->is_response
? ( undef,$packet )
: ( $packet, undef );
if ($response) {
my $code = $response->code;
if ($code eq '200') {
print "Received 200 ok\n";
return;
} else
{
print "received $code\n";
return;
}
}
else {
if ($request->method eq 'NOTIFY') {
print "received notify\n";
$ua->{dispatcher}->deliver($request->create_response( 200,'OK'), leg => $leg, dst_addr
+ => $from_addr );
}
}
}
1269377392.0003 DEBUG:<50> Net::SIP::Dispatcher::Eventloop::loop[135]: trigger timer(disp_expire) 1
+269377391.99868 repeat=1
1269377392.0004 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[140]: timer(disp_expire) gets rep
+eated at 1269377392
1269377392.0005 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[152]: timeout = 0.998549938201904
1269377392.0005 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[167]: handles=3
1269377393.0002 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[174]: can_read=
1269377393.0003 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[120]: timeout = 59985.3649139404
1269377393.0003 DEBUG:<50> Net::SIP::Dispatcher::Eventloop::loop[135]: trigger timer(disp_expire) 1
+269377392.99868 repeat=1
1269377393.0004 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[140]: timer(disp_expire) gets rep
+eated at 1269377393
1269377393.0005 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[152]: timeout = 0.998558044433594
1269377393.0005 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[167]: handles=3
1269377394.0004 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[174]: can_read=
1269377394.0004 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[120]: timeout = 59984.3647358418