summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-02-17 14:00:10 +0100
committerToni Uhlig <matzeton@googlemail.com>2021-02-17 14:00:10 +0100
commita1805eb89195f9079105a5b256395306c42ede95 (patch)
tree7fa56a09a7a0ce4a07df8d7d550dc1e80dd60ddc /examples
parent893f43705132dfeb64dd33dc8697193f463708c0 (diff)
Added JSON schema files and a Python schema validator.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/py-schema-validation/py-schema-validation.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/py-schema-validation/py-schema-validation.py b/examples/py-schema-validation/py-schema-validation.py
new file mode 100755
index 000000000..407c7b814
--- /dev/null
+++ b/examples/py-schema-validation/py-schema-validation.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+
+sys.path.append(os.path.dirname(sys.argv[0]) + '/../../dependencies')
+import nDPIsrvd
+from nDPIsrvd import nDPIsrvdSocket, TermColor
+
+class Stats:
+ lines_processed = 0
+ print_dot_every = 10
+ next_lines_print = print_dot_every
+
+def onJsonLineRecvd(json_dict, current_flow, global_user_data):
+ validation_done = nDPIsrvd.validateAgainstSchema(json_dict)
+
+ global_user_data.lines_processed += 1
+ if global_user_data.lines_processed % global_user_data.print_dot_every == 0:
+ sys.stdout.write('.')
+ sys.stdout.flush()
+ if global_user_data.lines_processed == global_user_data.next_lines_print:
+ global_user_data.next_lines_print *= 2
+ sys.stdout.write(str(global_user_data.lines_processed))
+ sys.stdout.flush()
+
+ return validation_done
+
+if __name__ == '__main__':
+ argparser = nDPIsrvd.defaultArgumentParser()
+ args = argparser.parse_args()
+ address = nDPIsrvd.validateAddress(args)
+
+ sys.stderr.write('Recv buffer size: {}\n'.format(nDPIsrvd.NETWORK_BUFFER_MAX_SIZE))
+ sys.stderr.write('Connecting to {} ..\n'.format(address[0]+':'+str(address[1]) if type(address) is tuple else address))
+
+ nDPIsrvd.initSchemaValidator(os.path.dirname(sys.argv[0]) + '/../../schema')
+
+ nsock = nDPIsrvdSocket()
+ nsock.connect(address)
+ nsock.loop(onJsonLineRecvd, Stats())