regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / tools / validate-diameter-xml.sh
blobac9140a732e179c28b2d826f40dff20687b6b4b9
1 #!/usr/bin/env bash
3 # A small script to run xmllint on the Diameter XML files (after doing some
4 # fixups to those files).
6 # Copyright 2016 Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
8 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 1998 Gerald Combs
11 # SPDX-License-Identifier: GPL-2.0-or-later
13 if ! type -p sed > /dev/null
14 then
15 echo "'sed' is needed to run $0." 1>&2
16 # Exit cleanly because we don't want pre-commit to fail just because
17 # someone doesn't have the tools...
18 exit 0
20 if ! type -p xmllint > /dev/null
21 then
22 echo "'xmllint' is needed to run $0." 1>&2
23 # Exit cleanly because we don't want pre-commit to fail just because
24 # someone doesn't have the tools...
25 exit 0
28 src_dir="$(dirname "$0")/.."
29 diameter_dir="$src_dir/resources/protocols/diameter"
31 # Ideally this would work regardless of our cwd
32 if [ ! -r "$diameter_dir/dictionary.xml" ]
33 then
34 echo "Couldn't find $diameter_dir/dictionary.xml" 1>&2
35 exit 1
37 if [ ! -r "$diameter_dir/dictionary.dtd" ]
38 then
39 echo "Couldn't find $diameter_dir/dictionary.dtd" 1>&2
40 exit 1
43 if ! tmpdir=$(mktemp -d); then
44 echo "Could not create temporary directory" >&2
45 exit 1
47 trap 'rm -rf "$tmpdir"' EXIT
49 # First edit all the AVP names that start with "3GPP" to indicate "TGPP".
50 # XML doesn't allow ID's to start with a digit but:
51 # 1) We don't *really* care if it's valid XML
52 # 2) (but) we do want to use xmllint to find problems
53 # 3) (and) users see the AVP names. Showing them "TGPP" instead of "3GPP"
54 # is annoying enough to warrant this extra work.
56 # Declare and populate associative exceptions array
57 declare -A exceptions=(
58 ["3GPP"]="TGPP"
59 ["5QI"]="FiveQI"
62 # Loop through the exceptions, building the sed options
63 sedopts=
64 for e in ${!exceptions[@]}; do
65 sedopts="${sedopts}s/name=\"$e/name=\"${exceptions[$e]}/;"
66 done
68 # Delete the last character, i.e., the trailing semicolon
69 sedopts=${sedopts%?}
71 cp "$diameter_dir/dictionary.dtd" "$tmpdir" || exit 1
72 for f in "$diameter_dir"/*.xml
74 sed "${sedopts}" "$f" > "$tmpdir/${f##*/}" || exit 1
75 done
77 xmllint --noout --noent --postvalid "$tmpdir/dictionary.xml" &&
78 echo "Diameter dictionary is (mostly) valid XML."
81 # Editor modelines - https://www.wireshark.org/tools/modelines.html
83 # Local variables:
84 # c-basic-offset: 8
85 # tab-width: 8
86 # indent-tabs-mode: t
87 # End:
89 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
90 # :indentSize=8:tabSize=8:noTabs=false: