Hi all,
I'm trying to develop an extension to support SNOM's number guessing
feature (I don't know if it's somehow a standard but description on how
it works is here:
http://kb.snom.com/kb/index.php?View=entry&CategoryID=14&EntryID=14)
As I have to do some 'complicated' db queries I was thinking to use PERL
module to handle number guessing request from the phone.
I see there's no way (please correct me if I'm wrong) from OpenSER,
neither from OpenSER::Message, to send a stateless reply with a
customized body (SNOM says that possible number completion shoud be
included in the body of a 200 OK reply).
For this reason I have to use Net::SIP to generate the reply packet but
I'm doing something wrong as OpenSER is not forwarding it back to the
client.
Test client is a Snom 360 and is behind a NAT, OpenSER has a public IP
Here is my routing logic in openser.cfg
------------------- BEGIN openser.cfg
route{
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
};
if (msg:len >= 2048 ) {
sl_send_reply("513", "Message too big");
exit;
};
if (nat_uac_test("19")) {
fix_nated_contact();
force_rport();
setbflag(6);
}
if (method=="PUBLISH") {
if ($hdr(Event)=="number-guessing") {
log("- Initial PUBLISH\n");
t_newtran();
t_on_reply("1");
perl_exec("numberguessing");
exit;
}
sl_send_reply("501", "Not implemented");
exit;
}
if (method=="REGISTER") {
if (nat_uac_test("19")) {
fix_nated_contact();
force_rport();
setbflag(6);
}
save("location");
exit;
};
exit;
}
route[1] {
log("--------------------- Stateful Reply\n");
if (!t_relay()) {
sl_reply_error();
};
exit;
}
------------------- END openser.cfg
Here is my Simple Perl
------------------- BEGIN net-sip.pl
use OpenSER qw ( log );
use OpenSER::Constants;
use Net::SIP;
# Predefined body, not querying db yet
my $body = '"Franky Chang" sip:101@192.168.0.1;user=phone
"Steven Jones" sip:102@192.168.0.1;user=phone
"Marie Sun" sip:103@192.168.0.1;user=phone
';
sub numberguessing {
my $m = shift;
my $pkt = Net::SIP::Request->new( $m->getMessage() );
my $resp = $pkt->create_response(200, "OK");
$resp->set_body($body);
$resp->add_header('Content-Type','application/number-guessing');
my $leg = Net::SIP::Leg->new(
addr => '111.222.333.444', port => '5061');
$leg->deliver( $resp, '111.222.333.444:5060' );
# 111.222.333.444 is the IP of OpenSER
# I'm sending from port 5061 to port 5060
return 1;
}
------------------- END net-sip.pl
OpenSER in verbose debugging module says that it cannot find a matching
transaction for the 200 OK reply (probably because is originated from
port 5061 and it has never forwarded it to that port ? )
Here is OpenSER DEBUG log:
0(24828) SIP Reply (status):
0(24828) version: <SIP/2.0>
0(24828) status: <200>
0(24828) reason: <OK>
0(24828) parse_headers: flags=2
0(24828) get_hdr_field: cseq <cseq>: <1> <PUBLISH>
0(24828) DEBUG:parse_to:end of header reached, state=10
0(24828) DBUG:parse_to: display={"Edoardo"},
ruri={sip:eserra@111.222.333.444}
0(24828) DEBUG: get_hdr_field: <to> [43]; uri=[sip:eserra@111.222.333.444]
0(24828) DEBUG: to body ["Edoardo" <sip:eserra@111.222.333.444>
]
0(24828) Found param type 232, <branch> = <z9hG4bK-m3j054b6d8q6>; state=6
0(24828) Found param type 235, <rport> = <n/a>; state=17
0(24828) end of header reached, state=5
0(24828) parse_headers: Via found, flags=2
0(24828) parse_headers: this is the first via
0(24828) After parse_msg...
0(24828) DEBUG:forward_reply: found module tm, passing reply to it
0(24828) DEBUG: t_check: start=0xffffffff
0(24828) parse_headers: flags=22
0(24828) DEBUG: t_reply_matching: failure to match a transaction
0(24828) DEBUG: t_check: end=(nil)
0(24828) parse_headers: flags=4
0(24828) DEBUG: get_hdr_body : content_length=135
0(24828) found end of header
0(24828) ERROR:forward_reply: no 2nd via found in reply
0(24828) DEBUG:destroy_avp_list: destroying list (nil)
0(24828) receive_msg: cleaning up
Here is also the tshark dump of the 2 packets (PUBLISH and its reply)
Request-Line: PUBLISH sip:eserra@213.92.23.108 SIP/2.0
Message Header
Via: SIP/2.0/UDP 192.168.254.151:2051;branch=z9hG4bK-ma9r5n0t4jfq;rport
From: "Edoardo" <sip:eserra@111.222.333.444>;tag=39wlni6ex1
To: "Edoardo" <sip:eserra@111.222.333.444>
Call-ID: 3c27c039249b-jml9w7t9sywx
CSeq: 1 PUBLISH
Max-Forwards: 70
Event: number-guessing
Content-Type: application/text
Content-Length: 25
Message body
Number: 10\r\n
Max-Hits: 3\r\n
Status-Line: SIP/2.0 200 OK
Message Header
call-id: 3c27c0daa600-emnlo1xcejtn
cseq: 1 PUBLISH
from: "Edoardo" <sip:eserra@111.222.333.444>;tag=6c1y8pp3fb
to: "Edoardo" <sip:eserra@111.222.333.444>
via: SIP/2.0/UDP 192.168.254.151:2051;branch=z9hG4bK-623oddiyzg56;rport
content-type: application/number-guessing
Content-Length: 135
Message body
"Franky Chang" sip:101@192.168.0.1;user=phone\n
"Steven Jones" sip:102@192.168.0.1;user=phone\n
"Marie Sun" sip:103@192.168.0.1;user=phone\n
Hope this info is enough for a debug :)
Tnx in advance
Regards
Edoardo Serra
EXSORSA LLC