you can call save() for 200ok received from downstream. In case you deal with nat or multiple local sockets, you need to call the functions for fixing the registration as well as storing the local socket.
The processing can be like:
- forward register
- if getting 200ok, call save() for it
- if local timeout, call save in failure route -- you will have to call it via a sub-route, because save() is only allowed in request route and reply route, although failure_route should be safe for it
- if other reply from downstram, let it go to the phone
# we need to track the reply to the REGISTER since we need to also save locally
if ( is_method("REGISTER") ) {
t_on_reply("REGISTER_REPLY");
t_on_failure("REGISTER_FAILURE");
}
onreply_route[REGISTER_REPLY] {
# Got a reply to a register from upstream. Save locally if its an OK
if (t_check_status("200")) {
save("location", "0x02", "sip:$tU@local.domain.com");
append_hf("X-Runway-Trace: Runway saved registration as $tU@local.domain.com\r\n");
}
}
U 2013/09/17 13:22:58.004730 10.64.5.16:5060 -> x.x.x.60:5060
REGISTER sip:vc2.connection-telecom.com SIP/2.0.
Via: SIP/2.0/UDP 10.64.5.16;branch=z9hG4bK66a6.f18d2a5.0.
Via: SIP/2.0/UDP 172.16.230.1:50108;branch=z9hG4bK-d8754z-f3d2c8070cecc90e-1---d8754z-;rport=50108.
Max-Forwards: 16.
Contact: <sip:2686959@172.16.230.1:50108;rinstance=36d56481f191d185;transport=udp>;expires=0.
To: "vc2 2686959"<sip:2686959@xxxx.connection-telecom.com>.
From: "vc2 2686959"<sip:2686959@xxxx.connection-telecom.com>;tag=114bde0a.
Call-ID: ZmUyY2JiOWQzMWE3OTM3YTNjNTM1OGUxOTE5Njc2ZTk.
CSeq: 4 REGISTER.
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO.
User-Agent: Bria 3 release 3.5.4 stamp 70878.
Authorization: Digest username="2686959",realm="xxxx.connection-telecom.com",nonce="52383baf2e3b9efcb10180e2ad059ff0ae7fa675",uri="sip:vc2.connection-telecom.com",response="bad296f5041c869c330f015c4dcb6351",algorithm=MD5.
Content-Length: 0.
P-hint: outbound.
U 2013/09/17 13:22:58.226378 x.x.x.60:5060 -> 10.64.5.16:5060
SIP/2.0 200 OK.
Via: SIP/2.0/UDP 10.64.5.16;branch=z9hG4bK66a6.f18d2a5.0;rport=5060.
Via: SIP/2.0/UDP 172.16.230.1:50108;branch=z9hG4bK-d8754z-f3d2c8070cecc90e-1---d8754z-;rport=50108.
To: "vc2 2686959"<sip:2686959@xxxx.connection-telecom.com>;tag=4bb452afea88ea368a51bf5f3eee867d.8da4.
From: "vc2 2686959"<sip:2686959@xxxx.connection-telecom.com>;tag=114bde0a.
Call-ID: ZmUyY2JiOWQzMWE3OTM3YTNjNTM1OGUxOTE5Njc2ZTk.
CSeq: 4 REGISTER.
Server: Telviva SIP proxy.
Content-Length: 0.