From 3ac41bae3d272535e5f32c2804638d33f59bce80 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Mon, 29 May 2017 16:07:34 +0200 Subject: [PATCH] TT#12264 Use outbound socket on peer registration Try to match up the peer_auth_realm with peer's ip or host, and if found, check for outbound_socket of this peer and use it as contact if found. Change-Id: I428c408d6f3b0796fab2306cc129478806ac9bd3 --- lib/NGCP/Panel/Utils/Sems.pm | 38 ++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/NGCP/Panel/Utils/Sems.pm b/lib/NGCP/Panel/Utils/Sems.pm index 54536c0b2e..1e5f22beea 100644 --- a/lib/NGCP/Panel/Utils/Sems.pm +++ b/lib/NGCP/Panel/Utils/Sems.pm @@ -4,6 +4,26 @@ use Sipwise::Base; use NGCP::Panel::Utils::XMLDispatcher; use Data::Dumper; +sub _get_outbound_socket { + my ($c, $prefs) = @_; + my ($contact, $transport); + my $peer_rs = $c->model('DB')->resultset('voip_peer_hosts')->search({ + -or => [ ip => $prefs->{peer_auth_realm}, host => $prefs->{peer_auth_realm} ] + }); + if($peer_rs->count) { + my $peer = $peer_rs->first; + my $outbound_sock_rs = NGCP::Panel::Utils::Preferences::get_peer_preference_rs( + c => $c, attribute => 'outbound_socket', + peer_host => $peer); + if($outbound_sock_rs->count) { + $contact = substr($outbound_sock_rs->first->value, 4); + $transport = ';transport=' . substr($outbound_sock_rs->first->value, 0, 3); + return { contact => $contact, transport => $transport }; + } + } + return; +} + sub create_peer_registration { my ($c, $prov_subscriber, $prefs) = @_; @@ -24,6 +44,13 @@ sub create_peer_registration { my $sid = $prov_subscriber->id; my $uuid = $prov_subscriber->uuid; my $contact = $c->config->{sip}->{lb_ext}; + my $transport = ''; + + my $outbound_sock = _get_outbound_socket($c, $prefs); + if($outbound_sock) { + $contact = $outbound_sock->{contact}; + $transport = $outbound_sock->{transport}; + } my @ret = $dispatcher->dispatch($c, "appserver", $all, 1, < @@ -34,7 +61,7 @@ sub create_peer_registration { $$prefs{peer_auth_user} $$prefs{peer_auth_pass} $$prefs{peer_auth_realm} - sip:$$prefs{peer_auth_user}\@$contact;uuid=$uuid + sip:$$prefs{peer_auth_user}\@$contact;uuid=$uuid$transport EOF @@ -84,6 +111,13 @@ sub update_peer_registration { my $sid = $prov_subscriber->id; my $uuid = $prov_subscriber->uuid; my $contact = $c->config->{sip}->{lb_ext}; + my $transport = ''; + + my $outbound_sock = _get_outbound_socket($c, $prefs); + if($outbound_sock) { + $contact = $outbound_sock->{contact}; + $transport = $outbound_sock->{transport}; + } use Data::Dumper; $c->log->debug("+++++++++++++++++++ old peer auth params: " . Dumper $oldprefs); @@ -101,7 +135,7 @@ sub update_peer_registration { $$prefs{peer_auth_user} $$prefs{peer_auth_pass} $$prefs{peer_auth_realm} - sip:$$prefs{peer_auth_user}\@$contact;uuid=$uuid + sip:$$prefs{peer_auth_user}\@$contact;uuid=$uuid$transport EOF