TT#35507 use domain sms_peer preference for SMS outbound routing

* smsc_peer preference is mandatory for NGCP::Utils::SMS::send_sms()
      and contains a handle of one of the avilable group=smsc id
    * sms_journal is extended to also store smsc_peer

Change-Id: I1a368b55c263bb5ea2acda004bbaf463d6431413
changes/42/20642/3
Kirill Solomko 8 years ago
parent db1d5ef95b
commit 091dee6d0b

@ -12,6 +12,7 @@ use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::Sems;
use NGCP::Panel::Utils::SMS;
use NGCP::Panel::Utils::Preferences;
sub allowed_methods{
@ -108,9 +109,18 @@ sub POST :Allow {
}
if($status eq "ACCEPT") {
$c->log->info("status for pcc sms of $callid is $status, forward sms");
my $smsc_peer = '';
my $smsc_peer_rs = NGCP::Panel::Utils::Preferences::get_dom_preference_rs(
c => $c, attribute => 'smsc_peer',
prov_domain => $sms->provisioning_voip_subscriber->domain,
);
if ($smsc_peer_rs && $smsc_peer_rs->first && $smsc_peer_rs->first->value) {
my $smsc_peer = $smsc_peer_rs->first->value;
}
try {
NGCP::Panel::Utils::SMS::send_sms(
c => $c,
smsc_peer => $smsc_peer,
caller => $sms->caller,
callee => $sms->callee,
text => $sms->text,

@ -6,6 +6,7 @@ use parent qw/NGCP::Panel::Role::Entities NGCP::Panel::Role::API::SMS/;
use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::Utf8;
use NGCP::Panel::Utils::SMS;
use NGCP::Panel::Utils::Preferences;
__PACKAGE__->set_config();
@ -116,6 +117,7 @@ sub create_item {
}
my $test_mode = $c->request->params->{test_mode} // '';
my $session;
my $smsc_peer = '';
try {
my $parts = NGCP::Panel::Utils::SMS::get_number_of_parts($resource->{text});
$session = NGCP::Panel::Utils::SMS::init_prepaid_billing(c => $c,
@ -130,10 +132,20 @@ sub create_item {
}
$session->{coding} = NGCP::Panel::Utils::SMS::get_coding($resource->{text});
my $smsc_peer_rs = NGCP::Panel::Utils::Preferences::get_dom_preference_rs(
c => $c, attribute => 'smsc_peer',
prov_domain => $subscriber->domain,
);
if ($smsc_peer_rs && $smsc_peer_rs->first && $smsc_peer_rs->first->value) {
my $smsc_peer = $smsc_peer_rs->first->value;
}
if ( 'dont_send_sms' ne $test_mode ) {
NGCP::Panel::Utils::SMS::send_sms(
c => $c,
smsc_peer => $smsc_peer,
caller => $resource->{caller},
callee => $resource->{callee},
text => $resource->{text},
@ -178,6 +190,7 @@ sub create_item {
coding => $session->{coding},
status => $session->{status} // '',
reason => $session->{reason} // '',
smsc_peer => $smsc_peer,
});
return $item;

@ -78,6 +78,7 @@ sub receive :Chained('list') :PathPart('receive') :Args(0) {
my $pcc_timeout = $c->config->{pcc}->{timeout};
my $pcc_enabled = 0;
my ($pcc_uuid, $pcc_token);
my $smsc_peer = '';
UUID::generate($pcc_uuid);
UUID::unparse($pcc_uuid, $pcc_token);
my $fwd_pref_rs = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
@ -97,6 +98,14 @@ sub receive :Chained('list') :PathPart('receive') :Args(0) {
}
$c->log->info("pcc is set to $pcc_enabled for prov subscriber id " . $prov_dbalias->subscriber_id);
my $smsc_peer_rs = NGCP::Panel::Utils::Preferences::get_dom_preference_rs(
c => $c, attribute => 'smsc_peer',
prov_domain => $prov_dbalias->domain,
);
if ($smsc_peer_rs && $smsc_peer_rs->first && $smsc_peer_rs->first->value) {
my $smsc_peer = $smsc_peer_rs->first->value;
}
my $created_item = NGCP::Utils::SMS::add_journal_record({
c => $c,
prov_subscriber => $prov_dbalias->subscriber,
@ -107,6 +116,7 @@ sub receive :Chained('list') :PathPart('receive') :Args(0) {
pcc_status => "none",
pcc_token => $pcc_token,
coding => $coding,
smsc_peer => $smsc_peer,
});
# check for cfs
@ -199,6 +209,7 @@ sub receive :Chained('list') :PathPart('receive') :Args(0) {
pcc_status => $pcc_status,
pcc_token => $pcc_token,
coding => $coding,
smsc_peer => $smsc_peer,
});
if($pcc_enabled && $pcc_url) {
@ -227,6 +238,7 @@ sub receive :Chained('list') :PathPart('receive') :Args(0) {
my $error_msg;
NGCP::Panel::Utils::SMS::send_sms(
c => $c,
smsc_peer => $smsc_peer;
caller => $to, # use the original to as new from
callee => $dst,
text => $text,

@ -36,6 +36,7 @@ sub send_sms {
my $text = $args{text};
my $coding = $args{coding};
my $err_code = $args{err_code};
my $smsc_peer = $args{smsc_peer};
if (!defined $err_code || ref $err_code ne 'CODE') {
$err_code = sub { return; };
@ -52,6 +53,15 @@ sub send_sms {
my $user = $c->config->{sms}{user};
my $pass = $c->config->{sms}{pass};
my @smsc = grep { $_->{id} and $_->{id} eq $id } @{$config->{sms}{smsc}};
if ($#smsc == -1) {
&{$err_code}("Error sending sms: invalid smsc peer id");
return;
}
my $charset = $smsc[0]->{charset} // 'utf-8';
my $fullpath = "$schema://$host:$port$path";
my $ua = LWP::UserAgent->new(
#ssl_opts => { verify_hostname => 0, SSL_verify_mode => 0 },
@ -59,7 +69,8 @@ sub send_sms {
);
my $uri = URI->new($fullpath);
$uri->query_form(
charset => "utf-8",
smsc => $smsc_peer,
charset => $charset,
coding => $coding,
user => "$user",
pass => "$pass",

Loading…
Cancel
Save