From bed7d341e16cc8eac3990ebf0747270c70625384 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Fri, 22 Nov 2019 16:55:22 +0100 Subject: simplify dialplan cfg, use freeswitch_dialplan_dgsm.py from osmo-hlr.git Change-Id: Ida2de649dc0c83e6f56c9e78af065acea7935002 --- net/templates/freeswitch/conf/dialplan/public.xml | 46 +--------------- net/templates/freeswitch/freeswitch.sh | 9 +++- .../freeswitch/python/dialplan-dgsm/__init__.py | 63 ---------------------- 3 files changed, 9 insertions(+), 109 deletions(-) delete mode 100644 net/templates/freeswitch/python/dialplan-dgsm/__init__.py diff --git a/net/templates/freeswitch/conf/dialplan/public.xml b/net/templates/freeswitch/conf/dialplan/public.xml index 86537ca..340e83c 100644 --- a/net/templates/freeswitch/conf/dialplan/public.xml +++ b/net/templates/freeswitch/conf/dialplan/public.xml @@ -1,29 +1,12 @@ - - - - - + @@ -41,34 +24,9 @@ - - - - - - - - - - - diff --git a/net/templates/freeswitch/freeswitch.sh b/net/templates/freeswitch/freeswitch.sh index cbf075b..988e60b 100755 --- a/net/templates/freeswitch/freeswitch.sh +++ b/net/templates/freeswitch/freeswitch.sh @@ -1,9 +1,14 @@ #!/bin/sh -NETDIR="$(cd $(dirname "$0")/..; pwd)" +DIALPLANDIR="$(cd $(dirname "$0")/../../../src/osmo-hlr/contrib/dgsm; pwd)" (sleep 5; echo; echo; echo "NOTE: type 'shutdown' to quit"; echo) & + +if ! [ -e "$DIALPLANDIR/freeswitch_dialplan_dgsm.py" ]; then + echo "ERROR: freeswitch_dialplan_dgsm.py not found in: $DIALPLANDIR" + exit 1 +fi set -ex -export PYTHONPATH="$NETDIR/freeswitch/python:$PYTHONPATH" +export PYTHONPATH="$PYTHONPATH:$DIALPLANDIR" if ! [ -d /usr/lib/freeswitch/mod ]; then echo "ERROR: missing dir /usr/lib/freeswitch/mod" diff --git a/net/templates/freeswitch/python/dialplan-dgsm/__init__.py b/net/templates/freeswitch/python/dialplan-dgsm/__init__.py deleted file mode 100644 index 11b2f36..0000000 --- a/net/templates/freeswitch/python/dialplan-dgsm/__init__.py +++ /dev/null @@ -1,63 +0,0 @@ -import json -import subprocess - - -def query_mslookup(service_type, id, id_type='msisdn'): - query_str = '%s.%s.%s' % (service_type, id, id_type) - print('[dialplan-dgsm] mslookup: ' + query_str) - - result_line = subprocess.check_output([ - 'osmo-mslookup-client', query_str, '-f', 'json']) - if isinstance(result_line, bytes): - result_line = result_line.decode('ascii') - - print('[dialplan-dgsm] mslookup result: ' + result_line) - return json.loads(result_line) - - -def handler(session, args): - """ Handle calls: bridge to the SIP server found with mslookup. """ - print('[dialplan-dgsm] call handler') - msisdn = session.getVariable('destination_number') - - # Run osmo-mslookup-client binary. We have also tried to directly call the C functions with ctypes but this has - # lead to hard-to-debug segfaults. - try: - result = query_mslookup("sip.voice", msisdn) - - # This example only makes use of IPv4 - if not result['v4']: - print('[dialplan-dgsm] no IPv4 result from mslookup') - session.hangup('UNALLOCATED_NUMBER') - return - - sip_ip, sip_port = result['v4'] # osmo-dev defaults: same as ${SIPCON_LOCAL} - dial_str = 'sofia/internal/sip:{}@{}:{}'.format(msisdn, sip_ip, sip_port) - print('[dialplan-dgsm] dial_str: ' + str(dial_str)) - - session.execute('bridge', dial_str) - except: - print('[dialplan-dgsm]: exception during call handler') - session.hangup('UNALLOCATED_NUMBER') - - -def fsapi(session, stream, env, args): - """ Freeswitch refuses to load the module without this. """ - stream.write(env.serialize()) - - -def main(): - import argparse - - parser = argparse.ArgumentParser() - parser.add_argument('id', type=int) - parser.add_argument('-i', '--id-type', default='msisdn', help='default: "msisdn"') - parser.add_argument('-s', '--service', default='sip.voice', help='default: "sip.voice"') - args = parser.parse_args() - - result = query_mslookup(args.service, args.id, args.id_type) - print(json.dumps(result)) - - -if __name__ == '__main__': - main() -- cgit v1.2.3