annotate extra/soundsoftware/doxysafe.pl @ 1474:c4436fec34bf bug_494

Close obsolete branch bug_494
author Chris Cannam
date Sat, 10 Nov 2012 13:57:53 +0000
parents df89e7aa3ce8
children
rev   line source
chris@226 1 #!/usr/bin/perl -w
chris@226 2
chris@226 3 # Read a Doxyfile and print it out again to stdout, with only
chris@226 4 # whitelisted keys in it and with some keys set to pre-fixed values.
chris@226 5 #
chris@226 6 # Note that OUTPUT_DIRECTORY is not included; it should be added by
chris@226 7 # the caller
chris@226 8
chris@226 9 use strict;
chris@226 10
chris@226 11 my $txt = join "", <>;
chris@226 12 $txt =~ s/^\s*#.*$//gm;
chris@226 13 $txt =~ s/\\\n//gs;
chris@226 14 $txt =~ s/\r//g;
chris@226 15 $txt =~ s/\n\s*\n/\n/gs;
chris@226 16
chris@226 17 my %fixed = (
chris@226 18 FULL_PATH_NAMES => "NO",
chris@226 19 SYMBOL_CACHE_SIZE => 2,
chris@226 20 EXCLUDE_SYMLINKS => "YES",
chris@226 21 GENERATE_HTML => "YES",
chris@226 22 PERL_PATH => "/usr/bin/perl",
chris@226 23 HAVE_DOT => "YES",
chris@226 24 HTML_OUTPUT => ".",
chris@228 25 HTML_DYNAMIC_SECTIONS => "NO",
chris@226 26 SEARCHENGINE => "NO",
chris@226 27 DOT_FONTNAME => "FreeMono",
chris@226 28 DOT_FONTSIZE => 10,
chris@226 29 DOT_FONTPATH => "/usr/share/fonts/truetype/freefont",
chris@226 30 DOT_IMAGE_FORMAT => "png",
chris@226 31 DOT_PATH => "/usr/bin/dot",
chris@226 32 DOT_TRANSPARENT => "YES",
chris@226 33 );
chris@226 34
Chris@233 35 # These are the keys that are safe to take from the output and include
Chris@233 36 # in the output; they may still need to be checked for safe values (if
Chris@233 37 # file paths).
chris@226 38 my @safe = qw(
Chris@233 39 INPUT
Chris@233 40 FILE_PATTERNS
Chris@233 41 EXAMPLE_PATH
Chris@233 42 EXAMPLE_PATTERNS
Chris@233 43 IMAGE_PATH
Chris@233 44 INCLUDE_PATH
Chris@233 45 INCLUDE_FILE_PATTERNS
chris@226 46 DOXYFILE_ENCODING
chris@226 47 PROJECT_NAME
chris@226 48 PROJECT_NUMBER
chris@226 49 CREATE_SUBDIRS
chris@226 50 OUTPUT_LANGUAGE
chris@226 51 BRIEF_MEMBER_DESC
chris@226 52 REPEAT_BRIEF
chris@226 53 ABBREVIATE_BRIEF
chris@226 54 ALWAYS_DETAILED_SEC
chris@226 55 INLINE_INHERITED_MEMB
chris@226 56 STRIP_FROM_PATH
chris@226 57 STRIP_FROM_INC_PATH
chris@226 58 JAVADOC_AUTOBRIEF
chris@226 59 QT_AUTOBRIEF
chris@226 60 MULTILINE_CPP_IS_BRIEF
chris@226 61 INHERIT_DOCS
chris@226 62 SEPARATE_MEMBER_PAGES
chris@226 63 TAB_SIZE
chris@226 64 ALIASES
chris@226 65 OPTIMIZE_OUTPUT_FOR_C
chris@226 66 OPTIMIZE_OUTPUT_JAVA
chris@226 67 OPTIMIZE_FOR_FORTRAN
chris@226 68 OPTIMIZE_OUTPUT_VHDL
chris@226 69 EXTENSION_MAPPING
chris@226 70 BUILTIN_STL_SUPPORT
chris@226 71 CPP_CLI_SUPPORT
chris@226 72 SIP_SUPPORT
chris@226 73 IDL_PROPERTY_SUPPORT
chris@226 74 DISTRIBUTE_GROUP_DOC
chris@226 75 SUBGROUPING
chris@226 76 TYPEDEF_HIDES_STRUCT
chris@226 77 EXTRACT_ALL
chris@226 78 EXTRACT_PRIVATE
chris@226 79 EXTRACT_STATIC
chris@226 80 EXTRACT_LOCAL_CLASSES
chris@226 81 EXTRACT_LOCAL_METHODS
chris@226 82 EXTRACT_ANON_NSPACES
chris@226 83 HIDE_UNDOC_MEMBERS
chris@226 84 HIDE_UNDOC_CLASSES
chris@226 85 HIDE_FRIEND_COMPOUNDS
chris@226 86 HIDE_IN_BODY_DOCS
chris@226 87 INTERNAL_DOCS
chris@226 88 HIDE_SCOPE_NAMES
chris@226 89 SHOW_INCLUDE_FILES
chris@226 90 FORCE_LOCAL_INCLUDES
chris@226 91 INLINE_INFO
chris@226 92 SORT_MEMBER_DOCS
chris@226 93 SORT_BRIEF_DOCS
chris@226 94 SORT_MEMBERS_CTORS_1ST
chris@226 95 SORT_GROUP_NAMES
chris@226 96 SORT_BY_SCOPE_NAME
chris@226 97 GENERATE_TODOLIST
chris@226 98 GENERATE_TESTLIST
chris@226 99 GENERATE_BUGLIST
chris@226 100 GENERATE_DEPRECATEDLIST
chris@226 101 ENABLED_SECTIONS
chris@226 102 MAX_INITIALIZER_LINES
chris@226 103 SHOW_USED_FILES
chris@226 104 SHOW_DIRECTORIES
chris@226 105 SHOW_FILES
chris@226 106 SHOW_NAMESPACES
chris@226 107 QUIET
chris@226 108 WARNINGS
chris@226 109 WARN_IF_UNDOCUMENTED
chris@226 110 WARN_IF_DOC_ERROR
chris@226 111 WARN_NO_PARAMDOC
chris@226 112 INPUT_ENCODING
chris@226 113 RECURSIVE
chris@226 114 EXCLUDE
chris@226 115 EXCLUDE_SYMLINKS
chris@226 116 EXCLUDE_PATTERNS
chris@226 117 EXCLUDE_SYMBOLS
chris@226 118 EXAMPLE_RECURSIVE
chris@226 119 SOURCE_BROWSER
chris@226 120 INLINE_SOURCES
chris@226 121 STRIP_CODE_COMMENTS
chris@226 122 REFERENCED_BY_RELATION
chris@226 123 REFERENCES_RELATION
chris@226 124 REFERENCES_LINK_SOURCE
chris@226 125 VERBATIM_HEADERS
chris@226 126 ALPHABETICAL_INDEX
chris@226 127 COLS_IN_ALPHA_INDEX
chris@226 128 IGNORE_PREFIX
chris@226 129 HTML_TIMESTAMP
chris@226 130 HTML_ALIGN_MEMBERS
chris@226 131 ENABLE_PREPROCESSING
chris@226 132 MACRO_EXPANSION
chris@226 133 EXPAND_ONLY_PREDEF
chris@226 134 SEARCH_INCLUDES
chris@226 135 PREDEFINED
chris@226 136 EXPAND_AS_DEFINED
chris@226 137 SKIP_FUNCTION_MACROS
chris@226 138 ALLEXTERNALS
chris@226 139 EXTERNAL_GROUPS
chris@226 140 CLASS_DIAGRAMS
chris@226 141 HIDE_UNDOC_RELATIONS
chris@226 142 CLASS_GRAPH
chris@226 143 COLLABORATION_GRAPH
chris@226 144 GROUP_GRAPHS
chris@226 145 UML_LOOK
chris@226 146 TEMPLATE_RELATIONS
chris@226 147 INCLUDE_GRAPH
chris@226 148 INCLUDED_BY_GRAPH
chris@226 149 CALL_GRAPH
chris@226 150 CALLER_GRAPH
chris@226 151 GRAPHICAL_HIERARCHY
chris@226 152 DIRECTORY_GRAPH
chris@226 153 DOT_GRAPH_MAX_NODES
chris@226 154 MAX_DOT_GRAPH_DEPTH
chris@226 155 DOT_MULTI_TARGETS
chris@226 156 DOT_CLEANUP
chris@226 157 );
chris@226 158
chris@226 159 my %safehash;
chris@226 160 for my $sk (@safe) { $safehash{$sk} = 1; }
chris@226 161
chris@226 162 my @lines = split "\n", $txt;
chris@226 163
chris@226 164 my %settings;
chris@226 165
chris@226 166 sub is_safe {
chris@226 167 my $key = shift;
chris@226 168 defined $safehash{$key} and $safehash{$key} == 1;
chris@226 169 }
chris@226 170
chris@226 171 sub has_file_path {
chris@226 172 # Returns true if the given key expects a file path as a value.
chris@226 173 # We only need to test keys that are safe; unsafe keys have been
chris@226 174 # rejected already.
chris@226 175 my $key = shift;
chris@226 176 $key eq "INPUT" or
chris@226 177 $key =~ /^OUTPUT_/ or
chris@226 178 $key =~ /_PATH$/ or
chris@226 179 $key =~ /_PATTERNS$/;
chris@226 180 }
chris@226 181
chris@226 182 sub is_safe_file_path {
chris@226 183 my $value = shift;
chris@226 184 not $value =~ /^\// and not $value =~ /\.\./;
chris@226 185 }
chris@226 186
chris@226 187 foreach my $line (@lines) {
chris@226 188
chris@226 189 chomp $line;
chris@226 190 my ($key, $value) = split /\s*=\s*/, $line;
chris@226 191
chris@226 192 next if !defined $key;
chris@226 193
chris@226 194 if ($key =~ /^GENERATE_/ and not $key =~ /LIST$/) {
chris@226 195 print STDERR "NOTE: Setting $key explicitly to NO\n";
chris@226 196 $settings{$key} = "NO";
chris@226 197 next;
chris@226 198 }
chris@226 199
chris@226 200 if (!is_safe($key)) {
chris@226 201 print STDERR "NOTE: Skipping non-whitelisted key $key\n";
chris@226 202 next;
chris@226 203 }
chris@226 204
chris@226 205 if (has_file_path($key) and !is_safe_file_path($value)) {
chris@226 206 print STDERR "ERROR: Unsafe file path \"$value\" for key $key\n";
chris@226 207 exit 1;
chris@226 208 }
chris@226 209
chris@226 210 $settings{$key} = $value;
chris@226 211 }
chris@226 212
chris@228 213 foreach my $key (keys %fixed) {
chris@228 214 my $value = $fixed{$key};
chris@228 215 print STDERR "NOTE: Setting $key to fixed value $value\n";
chris@228 216 $settings{$key} = $value;
chris@228 217 }
chris@228 218
chris@226 219 print join "\n", map { "$_ = $settings{$_}" } keys %settings;
chris@226 220 print "\n";