Add first work package for REST API implementation
[anna.git] / example / diameter / launcher / resources / rest_api / helpers / decodeHex.sh
diff --git a/example/diameter/launcher/resources/rest_api/helpers/decodeHex.sh b/example/diameter/launcher/resources/rest_api/helpers/decodeHex.sh
new file mode 100755 (executable)
index 0000000..ea8d9fa
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+[ -z "$1" ] && { echo "Usage: <hex file from 'tsharkDecoder.sh'>" ; exit 1 ; }
+[ ! -f "$1" ] && { echo "Cannot find '$1' !" ; exit 1 ; }
+
+ENDPOINT=$(cat ../.httpServer 2>/dev/null)
+[ -z "${ENDPOINT}" ] && ENDPOINT=localhost:8000
+
+cd $(dirname $0)
+tmpfile=$(mktemp)
+cat << EOF > $tmpfile
+{
+  "diameterHex":"$(cat $1)"
+}
+EOF
+responseField=$(curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d@${tmpfile} http://${ENDPOINT}/decode 2>/dev/null | jq '.response')
+rm ${tmpfile}
+[ -z "${responseField}" ] && { echo "Unexpected error. Check that ADML is started and the corresponding diameter dictionary is loaded." ; exit 1 ; }
+
+# Remove surrounding quotes:
+base64=$(echo ${responseField} | tr -d '"')
+
+# Decode response (base64), which is xml:
+echo ${base64} | base64 -d > ${1}.xml
+echo "Created '${1}.xml'"
+
+# Also create the json version:
+diameterJsonHelper/xml2json.py ${1}.xml > ${1}.xml.json
+echo "Created '${1}.xml.json'"