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