X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Fresources%2Frest_api%2Fhelpers%2FdecodeHex.sh;fp=example%2Fdiameter%2Flauncher%2Fresources%2Frest_api%2Fhelpers%2FdecodeHex.sh;h=ea8d9faeea97778ba6fdcbeb2d3d62c827291713;hb=c881c12ed7e116f1d43760a0d9873f860c10a357;hp=0000000000000000000000000000000000000000;hpb=af14877201a9856708ec43086a229777d9cb3da7;p=anna.git 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 index 0000000..ea8d9fa --- /dev/null +++ b/example/diameter/launcher/resources/rest_api/helpers/decodeHex.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +[ -z "$1" ] && { echo "Usage: " ; 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'"