aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-11-20 12:37:41 +0100
committerlaforge <laforge@osmocom.org>2020-01-10 16:07:40 +0000
commit637bbfcd9275f8c47212b29b50110f56ba6397bf (patch)
tree81ccf72dd96689f95175327a6afe0fe65933527a /contrib
parentf10463c5fc6d9e786ab7c648d99f7450f9a25906 (diff)
add osmo-mslookup-client program
Standalone program using libosmo-mslookup to easily integrate with programs that want to connect services (SIP, SMS,...) to the current location of a subscriber. Also useful for manual testing. For a detailed overview of the D-GSM and mslookup related files, please see the elaborate comment at the top of mslookup.c (already added in an earlier patch). Change-Id: Ie68a5c1db04fb4dff00dc3c774a1162f5b9fabf7
Diffstat (limited to 'contrib')
-rw-r--r--contrib/Makefile.am5
-rw-r--r--contrib/dgsm/Makefile.am4
-rwxr-xr-xcontrib/dgsm/osmo-mslookup-pipe.py24
-rwxr-xr-xcontrib/dgsm/osmo-mslookup-socket.py35
4 files changed, 67 insertions, 1 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 3439c97..cfd0b15 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -1 +1,4 @@
-SUBDIRS = systemd
+SUBDIRS = \
+ systemd \
+ dgsm \
+ $(NULL)
diff --git a/contrib/dgsm/Makefile.am b/contrib/dgsm/Makefile.am
new file mode 100644
index 0000000..c759302
--- /dev/null
+++ b/contrib/dgsm/Makefile.am
@@ -0,0 +1,4 @@
+EXTRA_DIST = \
+ osmo-mslookup-pipe.py \
+ osmo-mslookup-socket.py \
+ $(NULL)
diff --git a/contrib/dgsm/osmo-mslookup-pipe.py b/contrib/dgsm/osmo-mslookup-pipe.py
new file mode 100755
index 0000000..b18bf5f
--- /dev/null
+++ b/contrib/dgsm/osmo-mslookup-pipe.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# vim: shiftwidth=4 tabstop=4 expandtab
+import subprocess
+import json
+
+def query_mslookup(query_str):
+ result = {'result': 'not-found'}
+ proc = subprocess.Popen(('osmo-mslookup-client', '-f', 'json', query_str),
+ stdout=subprocess.PIPE)
+ for line in iter(proc.stdout.readline,''):
+ if not line:
+ break
+ response = json.loads(line)
+ if response.get('result') == 'result':
+ result = response
+ print('Response: %r' % response)
+ return result
+
+if __name__ == '__main__':
+ import sys
+ query_str = '1000-5000@sip.voice.12345.msisdn'
+ if len(sys.argv) > 1:
+ query_str = sys.argv[1]
+ print('Final result: %r' % query_mslookup(query_str))
diff --git a/contrib/dgsm/osmo-mslookup-socket.py b/contrib/dgsm/osmo-mslookup-socket.py
new file mode 100755
index 0000000..a26ad9f
--- /dev/null
+++ b/contrib/dgsm/osmo-mslookup-socket.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# vim: shiftwidth=4 tabstop=4 expandtab
+import socket
+import time
+
+MSLOOKUP_SOCKET_PATH = '/tmp/mslookup'
+
+def query_mslookup_socket(query_str, socket_path=MSLOOKUP_SOCKET_PATH):
+ mslookup_socket = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+ mslookup_socket.setblocking(True)
+ mslookup_socket.connect(socket_path)
+ result = {'result': 'not-found'}
+ column_names = mslookup_socket.recv(1024).decode('ascii')
+ if not column_names:
+ return result
+ column_names = column_names.split('\t')
+ mslookup_socket.sendall(query_str.encode('ascii'))
+ while True:
+ csv = mslookup_socket.recv(1024).decode('ascii')
+ if not csv:
+ break
+ response = dict(zip(column_names, csv.split('\t')))
+ if response.get('result') == 'result':
+ result = response
+ print('Response: %r' % response)
+ return result
+
+if __name__ == '__main__':
+ import sys
+ print(
+ '\nPlease run separately: osmo-mslookup-client --socket /tmp/mslookup -d\n')
+ query_str = '1000-5000@sip.voice.12345.msisdn'
+ if len(sys.argv) > 1:
+ query_str = sys.argv[1]
+ print('Final result: %r' % query_mslookup_socket(query_str))