MT#5633 add presence support on scenario.

Add XCap client script.
mr3.2.1
Victor Seva 13 years ago
parent babfc1485b
commit 3b62b419c8

@ -254,6 +254,14 @@ function run_sipp
fi
capture
if [ -e ${SCEN_CHECK_DIR}/presence.sh ]; then
echo "$(date) - Presence xcap"
${SCEN_CHECK_DIR}/presence.sh
if [ $? -ne 0 ]; then
error_helper "error in presence.sh" 17
fi
fi
for res in $(find ${SCEN_CHECK_DIR} -type f -name 'sipp_scenario_responder[0-9][0-9].xml'| sort); do
base=$(basename $res .xml)
is_enabled $(basename $res)

@ -0,0 +1,72 @@
#!/bin/bash
#
# Copyright: 2013 Sipwise Development Team <support@sipwise.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# On Debian systems, the complete text of the GNU General
# Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
#
BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}"
BIN_DIR="${BASE_DIR}/bin"
LOG_DIR="${BASE_DIR}/log"
RESULT_DIR="${BASE_DIR}/result"
DOMAIN="spce.test"
DIR="${BASE_DIR}/scenarios"
error_flag=0
function clean
{
find ${DIR} -type f -name 'presence_*.xml' -exec rm {} \;
}
function usage
{
echo "Usage: generate_tests.sh [-h] [-c] [-d directory] digest presence_file.xml"
echo "Options:"
echo -e "\tc: clean. Removes all generated presence files"
echo -e "\td: directory"
echo -e "\th: this help"
echo "Args:"
echo -e "\tdigest: testuserX@domain:password"
}
while getopts 'hcd:' opt; do
case $opt in
h) usage; exit 0;;
c) clean; exit 0;;
d) DIR=$OPTARG;;
esac
done
shift $(($OPTIND - 1))
if [[ $# -ne 2 ]]; then
echo "Wrong number or arguments"
usage
exit 1
fi
if [ ! -e "${2}" ]; then
echo "No ${2} file found"
exit 1
fi
# subscriber part
subs=$(echo ${1}|cut -f1 -d:)
curl -T ${2} -X PUT --digest -k -u ${1} \
https://127.0.0.1:1080/xcap/pres-rules/users/sip:${subs}/presrules
if [ $? -ne 0 ]; then
echo "error sending xcap info"
exit 1
fi
#EOF

@ -29,6 +29,7 @@ use IO::File;
use YAML;
use Text::CSV;
use Template;
use Data::Dumper;
sub usage
{
@ -58,6 +59,7 @@ if (exists $ENV{'BASE_DIR'})
$template_dir = File::Spec->catfile(abs_path($ENV{'BASE_DIR'}), 'scenarios', 'templates');
}
our $template_reg = 'sipp_scenario_responder_reg.xml.tt2';
our $template_presence = 'pres-rules.xml.tt2';
our $tt = Template->new({
INCLUDE_PATH => $template_dir,
@ -72,7 +74,7 @@ sub new_csv
sub get_subs_info
{
my ($data_sub, $data) = @_;
my ($data_sub, $data, $presence) = @_;
if (defined($data_sub->{$data->{domain}}))
{
my $domain = $data->{domain};
@ -81,7 +83,7 @@ sub get_subs_info
my $username = $data->{username};
my $subs = $data_sub->{$domain}->{$username};
$data->{password} = $subs->{password};
eval { $data->{number} = $subs->{cc}.$subs->{ac}.$subs->{sn}; };
eval { $data->{number} = $subs->{cc}.$subs->{ac}.$subs->{sn}; } unless defined($presence);
}
else
{
@ -155,4 +157,34 @@ sub generate_reg
$tt->process($template_reg, $vars, $fn) or die($tt->error(), "\n");
}
sub generate_presence
{
my @rules;
my ($data) = @_;
foreach (@{$data->{presence}})
{
eval { get_subs_info($data->{subscribers}, $_); };
$_->{password} = "" unless defined($_->{password});
my $vars = { users => @{$_->{allow}} };
my $fn = File::Spec->catfile($base_check_dir, "presence_".$_->{username}."_".$_->{domain}.".xml");
$tt->process($template_presence, $vars, $fn) or die($tt->error(), "\n");
undef $fn;
my $digest = $_->{username}."@".$_->{domain}.":".$_->{password};
push @rules, "$bin_dir/presence.sh $digest $template_dir/$template_presence"
}
if(scalar(@rules)>0)
{
my $file = "$base_check_dir/presence.sh";
my $fn = IO::File->new($file, "w") or die("can't create $file");
print {$fn} "#!/bin/bash\n";
foreach(@rules)
{
print {$fn} "$_\n";
}
chmod(0755, $fn);
undef $fn;
}
}
generate($cf);
generate_presence($cf);

3
debian/control vendored

@ -8,7 +8,8 @@ Homepage: http://www.sipwise.com/
Package: kamailio-config-tests
Architecture: all
Depends: libgraphviz-perl,
Depends: curl,
libgraphviz-perl,
libtemplate-perl,
libtext-csv-perl,
ngcp-ossbss-clients-perl,

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ruleset xmlns="urn:ietf:params:xml:ns:common-policy">
<rule id="presence_allow">
<conditions>
<identity>[% FOREACH user IN users -%]<one id="sip:[% users -%]"/>[% END -%]</identity>
</conditions>
<actions>
<sub-handling xmlns="urn:ietf:params:xml:ns:pres-rules">allow</sub-handling>
</actions>
<transformations>
<provide-devices xmlns="urn:ietf:params:xml:ns:pres-rules">
<all-devices/>
</provide-devices>
<provide-persons xmlns="urn:ietf:params:xml:ns:pres-rules">
<all-persons/>
</provide-persons>
<provide-services xmlns="urn:ietf:params:xml:ns:pres-rules">
<all-services/>
</provide-services>
</transformations>
</rule>
</ruleset>
Loading…
Cancel
Save