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
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...
20 if ! type -p xmllint
> /dev
/null
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...
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" ]
34 echo "Couldn't find $diameter_dir/dictionary.xml" 1>&2
37 if [ ! -r "$diameter_dir/dictionary.dtd" ]
39 echo "Couldn't find $diameter_dir/dictionary.dtd" 1>&2
43 if ! tmpdir
=$
(mktemp
-d); then
44 echo "Could not create temporary directory" >&2
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
=(
62 # Loop through the exceptions, building the sed options
64 for e
in ${!exceptions[@]}; do
65 sedopts
="${sedopts}s/name=\"$e/name=\"${exceptions[$e]}/;"
68 # Delete the last character, i.e., the trailing semicolon
71 cp "$diameter_dir/dictionary.dtd" "$tmpdir" ||
exit 1
72 for f
in "$diameter_dir"/*.xml
74 sed "${sedopts}" "$f" > "$tmpdir/${f##*/}" ||
exit 1
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
89 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
90 # :indentSize=8:tabSize=8:noTabs=false: