aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2019-11-22 16:55:22 +0100
committerOliver Smith <osmith@sysmocom.de>2019-11-22 16:55:22 +0100
commitbed7d341e16cc8eac3990ebf0747270c70625384 (patch)
treec47ec2a02b9cef548f79f36676816737f818f315
parent6d5952474fe61179e71236307d88a6cbba7861a4 (diff)
simplify dialplan cfg, use freeswitch_dialplan_dgsm.py from osmo-hlr.gitosmith/freeswitch
-rw-r--r--net/templates/freeswitch/conf/dialplan/public.xml46
-rwxr-xr-xnet/templates/freeswitch/freeswitch.sh9
-rw-r--r--net/templates/freeswitch/python/dialplan-dgsm/__init__.py63
3 files changed, 9 insertions, 109 deletions
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 @@
-<!--
- NOTICE:
-
- This context is usually accessed via the external sip profile listening on port 5080.
-
- It is recommended to have separate inbound and outbound contexts. Not only for security
- but clearing up why you would need to do such a thing. You don't want outside un-authenticated
- callers hitting your default context which allows dialing calls thru your providers and results
- in Toll Fraud.
--->
-
-<!-- http://wiki.freeswitch.org/wiki/Dialplan_XML -->
<include>
<context name="public">
-
<extension name="unloop">
<condition field="${unroll_loops}" expression="^true$"/>
<condition field="${sip_looped_call}" expression="^true$">
<action application="deflect" data="${destination_number}"/>
</condition>
</extension>
- <!--
- Tag anything pass thru here as an outside_call so you can make sure not
- to create any routing loops based on the conditions that it came from
- the outside of the switch.
- -->
+
<extension name="outside_call" continue="true">
<condition>
<action application="set" data="outside_call=true"/>
@@ -41,34 +24,9 @@
<condition field="destination_number" expression=".*">
<action application="set" data="hangup_after_bridge=true"/>
<action application="set" data="session_in_hangup_hook=true"/>
- <action application="set" data="api_hangup_hook=python dialplan-dgsm"/>
<action application="set" data="ringback=%(2000, 4000, 440.0, 480.0)"/>
- <action application="python" data="dialplan-dgsm"/>
- <!--<action application="bridge" data="{absolute_codec_string='G729'}sofia/gateway/provider/${destination_number}" />-->
- </condition>
- </extension>
-
-
- <!--
- You can place files in the public directory to get included.
- -->
- <!--<X-PRE-PROCESS cmd="include" data="public/*.xml"/>-->
- <!--
- If you have made it this far lets challenge the caller and if they authenticate
- lets try what they dialed in the default context. (commented out by default)
- -->
- <!--
- <extension name="check_auth" continue="true">
- <condition field="${sip_authorized}" expression="^true$" break="never">
- <anti-action application="respond" data="407"/>
- </condition>
- </extension>
-
- <extension name="transfer_to_default">
- <condition>
- <action application="transfer" data="${destination_number} XML default"/>
+ <action application="python" data="freeswitch_dialplan_dgsm"/>
</condition>
</extension>
- -->
</context>
</include>
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()