]>
Commit | Line | Data |
---|---|---|
6d311938 DSH |
1 | #!/usr/local/bin/perl -w |
2 | ||
3 | my $config = "crypto/err/openssl.ec"; | |
c7235be6 | 4 | my $hprefix = "openssl/"; |
6d311938 DSH |
5 | my $debug = 0; |
6 | my $rebuild = 0; | |
73934800 | 7 | my $static = 1; |
6d311938 DSH |
8 | my $recurse = 0; |
9 | my $reindex = 0; | |
73934800 | 10 | my $dowrite = 0; |
6343e2fa | 11 | my $staticloader = ""; |
6d311938 | 12 | |
bc3cae7e DSH |
13 | my $pack_errcode; |
14 | my $load_errcode; | |
15 | ||
f3d2a9db | 16 | my $errcount; |
74daafaa | 17 | my $year = (localtime)[5] + 1900; |
f3d2a9db | 18 | |
6d311938 DSH |
19 | while (@ARGV) { |
20 | my $arg = $ARGV[0]; | |
21 | if($arg eq "-conf") { | |
22 | shift @ARGV; | |
23 | $config = shift @ARGV; | |
c7235be6 UM |
24 | } elsif($arg eq "-hprefix") { |
25 | shift @ARGV; | |
26 | $hprefix = shift @ARGV; | |
6d311938 DSH |
27 | } elsif($arg eq "-debug") { |
28 | $debug = 1; | |
29 | shift @ARGV; | |
30 | } elsif($arg eq "-rebuild") { | |
31 | $rebuild = 1; | |
32 | shift @ARGV; | |
33 | } elsif($arg eq "-recurse") { | |
34 | $recurse = 1; | |
35 | shift @ARGV; | |
36 | } elsif($arg eq "-reindex") { | |
37 | $reindex = 1; | |
38 | shift @ARGV; | |
73934800 DSH |
39 | } elsif($arg eq "-nostatic") { |
40 | $static = 0; | |
41 | shift @ARGV; | |
6343e2fa RL |
42 | } elsif($arg eq "-staticloader") { |
43 | $staticloader = "static "; | |
44 | shift @ARGV; | |
73934800 DSH |
45 | } elsif($arg eq "-write") { |
46 | $dowrite = 1; | |
6d311938 | 47 | shift @ARGV; |
0b4b8ba6 DSH |
48 | } elsif($arg eq "-help" || $arg eq "-h" || $arg eq "-?" || $arg eq "--help") { |
49 | print STDERR <<"EOF"; | |
50 | mkerr.pl [options] ... | |
51 | ||
52 | Options: | |
53 | ||
54 | -conf F Use the config file F instead of the default one: | |
55 | crypto/err/openssl.ec | |
56 | ||
57 | -hprefix P Prepend the filenames in generated #include <header> | |
58 | statements with prefix P. Default: 'openssl/' (without | |
59 | the quotes, naturally) | |
60 | ||
61 | -debug Turn on debugging verbose output on stderr. | |
62 | ||
63 | -rebuild Rebuild all header and C source files, irrespective of the | |
64 | fact if any error or function codes have been added/removed. | |
65 | Default: only update files for libraries which saw change | |
66 | (of course, this requires '-write' as well, or no | |
67 | files will be touched!) | |
68 | ||
69 | -recurse scan a preconfigured set of directories / files for error and | |
70 | function codes: | |
71 | (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <apps/*.c>) | |
72 | When this option is NOT specified, the filelist is taken from | |
73 | the commandline instead. Here, wildcards may be embedded. (Be | |
74 | sure to escape those to prevent the shell from expanding them | |
75 | for you when you wish mkerr.pl to do so instead.) | |
76 | Default: take file list to scan from the command line. | |
77 | ||
78 | -reindex Discard the numeric values previously assigned to the error | |
79 | and function codes as extracted from the scanned header files; | |
80 | instead renumber all of them starting from 100. (Note that | |
81 | the numbers assigned through 'R' records in the config file | |
82 | remain intact.) | |
83 | Default: keep previously assigned numbers. (You are warned | |
84 | when collisions are detected.) | |
85 | ||
86 | -nostatic Generates a different source code, where these additional | |
87 | functions are generated for each library specified in the | |
88 | config file: | |
89 | void ERR_load_<LIB>_strings(void); | |
90 | void ERR_unload_<LIB>_strings(void); | |
91 | void ERR_<LIB>_error(int f, int r, char *fn, int ln); | |
92 | #define <LIB>err(f,r) ERR_<LIB>_error(f,r,__FILE__,__LINE__) | |
93 | while the code facilitates the use of these in an environment | |
94 | where the error support routines are dynamically loaded at | |
95 | runtime. | |
96 | Default: 'static' code generation. | |
97 | ||
98 | -staticloader Prefix generated functions with the 'static' scope modifier. | |
99 | Default: don't write any scope modifier prefix. | |
100 | ||
101 | -write Actually (over)write the generated code to the header and C | |
102 | source files as assigned to each library through the config | |
103 | file. | |
104 | Default: don't write. | |
105 | ||
106 | -help / -h / -? / --help Show this help text. | |
107 | ||
108 | ... Additional arguments are added to the file list to scan, | |
109 | assuming '-recurse' was NOT specified on the command line. | |
110 | ||
111 | EOF | |
112 | exit 1; | |
6d311938 DSH |
113 | } else { |
114 | last; | |
115 | } | |
116 | } | |
117 | ||
118 | if($recurse) { | |
ccb9643f | 119 | @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>); |
6d311938 DSH |
120 | } else { |
121 | @source = @ARGV; | |
122 | } | |
123 | ||
124 | # Read in the config file | |
125 | ||
126 | open(IN, "<$config") || die "Can't open config file $config"; | |
127 | ||
128 | # Parse config file | |
129 | ||
130 | while(<IN>) | |
131 | { | |
132 | if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) { | |
133 | $hinc{$1} = $2; | |
016cadfb | 134 | $libinc{$2} = $1; |
6d311938 DSH |
135 | $cskip{$3} = $1; |
136 | if($3 ne "NONE") { | |
137 | $csrc{$1} = $3; | |
0b4b8ba6 DSH |
138 | $fmax{$1} = 100; |
139 | $rmax{$1} = 100; | |
2adc42e4 BM |
140 | $fassigned{$1} = ":"; |
141 | $rassigned{$1} = ":"; | |
6d311938 DSH |
142 | $fnew{$1} = 0; |
143 | $rnew{$1} = 0; | |
144 | } | |
145 | } elsif (/^F\s+(\S+)/) { | |
146 | # Add extra function with $1 | |
147 | } elsif (/^R\s+(\S+)\s+(\S+)/) { | |
148 | $rextra{$1} = $2; | |
149 | $rcodes{$1} = $2; | |
6d311938 DSH |
150 | } |
151 | } | |
152 | ||
153 | close IN; | |
154 | ||
155 | # Scan each header file in turn and make a list of error codes | |
156 | # and function names | |
157 | ||
016cadfb | 158 | while (($hdr, $lib) = each %libinc) |
6d311938 DSH |
159 | { |
160 | next if($hdr eq "NONE"); | |
161 | print STDERR "Scanning header file $hdr\n" if $debug; | |
f924200e RL |
162 | my $line = "", $def= "", $linenr = 0, $gotfile = 0; |
163 | if (open(IN, "<$hdr")) { | |
164 | $gotfile = 1; | |
165 | while(<IN>) { | |
166 | $linenr++; | |
167 | print STDERR "line: $linenr\r" if $debug; | |
168 | ||
169 | last if(/BEGIN\s+ERROR\s+CODES/); | |
170 | if ($line ne '') { | |
171 | $_ = $line . $_; | |
172 | $line = ''; | |
173 | } | |
6d311938 | 174 | |
f924200e RL |
175 | if (/\\$/) { |
176 | $line = $_; | |
177 | next; | |
178 | } | |
6d311938 | 179 | |
2d43a894 AP |
180 | if(/\/\*/) { |
181 | if (not /\*\//) { # multiline comment... | |
182 | $line = $_; # ... just accumulate | |
183 | next; | |
184 | } else { | |
185 | s/\/\*.*?\*\///gs; # wipe it | |
186 | } | |
187 | } | |
188 | ||
f924200e | 189 | if ($cpp) { |
2d43a894 AP |
190 | $cpp++ if /^#\s*if/; |
191 | $cpp-- if /^#\s*endif/; | |
f924200e RL |
192 | next; |
193 | } | |
2d43a894 | 194 | $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration |
6d311938 | 195 | |
f924200e | 196 | next if (/^\#/); # skip preprocessor directives |
6d311938 | 197 | |
f924200e | 198 | s/{[^{}]*}//gs; # ignore {} blocks |
6d311938 | 199 | |
f924200e RL |
200 | if (/\{|\/\*/) { # Add a } so editor works... |
201 | $line = $_; | |
202 | } else { | |
203 | $def .= $_; | |
204 | } | |
6d311938 DSH |
205 | } |
206 | } | |
207 | ||
f6cd2d38 RL |
208 | print STDERR " \r" if $debug; |
209 | $defnr = 0; | |
47a9d527 DSH |
210 | # Delete any DECLARE_ macros |
211 | $def =~ s/DECLARE_\w+\([\w,\s]+\)//gs; | |
6d311938 | 212 | foreach (split /;/, $def) { |
f6cd2d38 RL |
213 | $defnr++; |
214 | print STDERR "def: $defnr\r" if $debug; | |
215 | ||
2d43a894 AP |
216 | # The goal is to collect function names from function declarations. |
217 | ||
0c6c96d4 | 218 | s/^[\n\s]*//g; |
6d311938 | 219 | s/[\n\s]*$//g; |
2d43a894 AP |
220 | |
221 | # Skip over recognized non-function declarations | |
68e57536 | 222 | next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/); |
2d43a894 | 223 | |
47a9d527 DSH |
224 | # Remove STACK_OF(foo) |
225 | s/STACK_OF\(\w+\)/void/; | |
226 | ||
2d43a894 AP |
227 | # Reduce argument lists to empty () |
228 | # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {} | |
68e57536 AP |
229 | while(/\(.*\)/s) { |
230 | s/\([^\(\)]+\)/\{\}/gs; | |
231 | s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f | |
232 | } | |
2d43a894 AP |
233 | # pretend as we didn't use curly braces: {} -> () |
234 | s/\{\}/\(\)/gs; | |
235 | ||
236 | if (/(\w+)\s*\(\).*/s) { # first token prior [first] () is | |
237 | my $name = $1; # a function name! | |
6d311938 DSH |
238 | $name =~ tr/[a-z]/[A-Z]/; |
239 | $ftrans{$name} = $1; | |
2d43a894 | 240 | } elsif (/[\(\)]/ and not (/=/)) { |
6d311938 DSH |
241 | print STDERR "Header $hdr: cannot parse: $_;\n"; |
242 | } | |
243 | } | |
244 | ||
f6cd2d38 RL |
245 | print STDERR " \r" if $debug; |
246 | ||
6d311938 DSH |
247 | next if $reindex; |
248 | ||
249 | # Scan function and reason codes and store them: keep a note of the | |
250 | # maximum code used. | |
251 | ||
f924200e | 252 | if ($gotfile) { |
2adc42e4 | 253 | while(<IN>) { |
d2f8517a | 254 | if(/^\#\s*define\s+(\S+)\s+(\S+)/) { |
6d311938 DSH |
255 | $name = $1; |
256 | $code = $2; | |
6343e2fa | 257 | next if $name =~ /^${lib}err/; |
6d311938 DSH |
258 | unless($name =~ /^${lib}_([RF])_(\w+)$/) { |
259 | print STDERR "Invalid error code $name\n"; | |
260 | next; | |
261 | } | |
262 | if($1 eq "R") { | |
263 | $rcodes{$name} = $code; | |
2adc42e4 | 264 | if ($rassigned{$lib} =~ /:$code:/) { |
0b4b8ba6 | 265 | print STDERR "!! ERROR: $lib reason code $code assigned twice (collision at $name)\n"; |
f3d2a9db | 266 | ++$errcount; |
2adc42e4 BM |
267 | } |
268 | $rassigned{$lib} .= "$code:"; | |
6d311938 DSH |
269 | if(!(exists $rextra{$name}) && |
270 | ($code > $rmax{$lib}) ) { | |
271 | $rmax{$lib} = $code; | |
272 | } | |
273 | } else { | |
2adc42e4 | 274 | if ($fassigned{$lib} =~ /:$code:/) { |
0b4b8ba6 | 275 | print STDERR "!! ERROR: $lib function code $code assigned twice (collision at $name)\n"; |
f3d2a9db | 276 | ++$errcount; |
2adc42e4 BM |
277 | } |
278 | $fassigned{$lib} .= "$code:"; | |
6d311938 DSH |
279 | if($code > $fmax{$lib}) { |
280 | $fmax{$lib} = $code; | |
281 | } | |
282 | $fcodes{$name} = $code; | |
283 | } | |
284 | } | |
2adc42e4 | 285 | } |
6d311938 | 286 | } |
a07b4dc0 BM |
287 | |
288 | if ($debug) { | |
a07b4dc0 BM |
289 | if (defined($fmax{$lib})) { |
290 | print STDERR "Max function code fmax" . "{" . "$lib" . "} = $fmax{$lib}\n"; | |
2adc42e4 BM |
291 | $fassigned{$lib} =~ m/^:(.*):$/; |
292 | @fassigned = sort {$a <=> $b} split(":", $1); | |
293 | print STDERR " @fassigned\n"; | |
294 | } | |
295 | if (defined($rmax{$lib})) { | |
296 | print STDERR "Max reason code rmax" . "{" . "$lib" . "} = $rmax{$lib}\n"; | |
297 | $rassigned{$lib} =~ m/^:(.*):$/; | |
298 | @rassigned = sort {$a <=> $b} split(":", $1); | |
299 | print STDERR " @rassigned\n"; | |
a07b4dc0 BM |
300 | } |
301 | } | |
302 | ||
52cc46a2 BM |
303 | if ($lib eq "SSL") { |
304 | if ($rmax{$lib} >= 1000) { | |
305 | print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n"; | |
306 | print STDERR "!! Any new alerts must be added to $config.\n"; | |
f3d2a9db | 307 | ++$errcount; |
52cc46a2 BM |
308 | print STDERR "\n"; |
309 | } | |
310 | } | |
6d311938 DSH |
311 | close IN; |
312 | } | |
313 | ||
314 | # Scan each C source file and look for function and reason codes | |
315 | # This is done by looking for strings that "look like" function or | |
316 | # reason codes: basically anything consisting of all upper case and | |
317 | # numerics which has _F_ or _R_ in it and which has the name of an | |
318 | # error library at the start. This seems to work fine except for the | |
319 | # oddly named structure BIO_F_CTX which needs to be ignored. | |
320 | # If a code doesn't exist in list compiled from headers then mark it | |
321 | # with the value "X" as a place holder to give it a value later. | |
6e781e8e DSH |
322 | # Store all function and reason codes found in %ufcodes and %urcodes |
323 | # so all those unreferenced can be printed out. | |
6d311938 DSH |
324 | |
325 | ||
326 | foreach $file (@source) { | |
327 | # Don't parse the error source file. | |
328 | next if exists $cskip{$file}; | |
2d43a894 | 329 | print STDERR "File loaded: ".$file."\r" if $debug; |
0c6c96d4 | 330 | open(IN, "<$file") || die "Can't open source file $file\n"; |
6d311938 | 331 | while(<IN>) { |
0b4b8ba6 DSH |
332 | # skip obsoleted source files entirely! |
333 | last if(/^#error\s+obsolete/); | |
334 | ||
6e781e8e | 335 | if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { |
6d311938 DSH |
336 | next unless exists $csrc{$2}; |
337 | next if($1 eq "BIO_F_BUFFER_CTX"); | |
6e781e8e | 338 | $ufcodes{$1} = 1; |
6d311938 DSH |
339 | if(!exists $fcodes{$1}) { |
340 | $fcodes{$1} = "X"; | |
341 | $fnew{$2}++; | |
342 | } | |
6e781e8e | 343 | $notrans{$1} = 1 unless exists $ftrans{$3}; |
0b4b8ba6 | 344 | print STDERR "Function: $1\t= $fcodes{$1} (lib: $2, name: $3)\n" if $debug; |
6d311938 DSH |
345 | } |
346 | if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) { | |
347 | next unless exists $csrc{$2}; | |
6e781e8e | 348 | $urcodes{$1} = 1; |
6d311938 DSH |
349 | if(!exists $rcodes{$1}) { |
350 | $rcodes{$1} = "X"; | |
351 | $rnew{$2}++; | |
352 | } | |
0b4b8ba6 | 353 | print STDERR "Reason: $1\t= $rcodes{$1} (lib: $2)\n" if $debug; |
6d311938 DSH |
354 | } |
355 | } | |
356 | close IN; | |
357 | } | |
a07b4dc0 | 358 | print STDERR " \n" if $debug; |
6d311938 DSH |
359 | |
360 | # Now process each library in turn. | |
361 | ||
362 | foreach $lib (keys %csrc) | |
363 | { | |
364 | my $hfile = $hinc{$lib}; | |
365 | my $cfile = $csrc{$lib}; | |
366 | if(!$fnew{$lib} && !$rnew{$lib}) { | |
367 | print STDERR "$lib:\t\tNo new error codes\n"; | |
368 | next unless $rebuild; | |
369 | } else { | |
370 | print STDERR "$lib:\t\t$fnew{$lib} New Functions,"; | |
371 | print STDERR " $rnew{$lib} New Reasons.\n"; | |
73934800 | 372 | next unless $dowrite; |
6d311938 DSH |
373 | } |
374 | ||
375 | # If we get here then we have some new error codes so we | |
376 | # need to rebuild the header file and C file. | |
377 | ||
378 | # Make a sorted list of error and reason codes for later use. | |
379 | ||
380 | my @function = sort grep(/^${lib}_/,keys %fcodes); | |
381 | my @reasons = sort grep(/^${lib}_/,keys %rcodes); | |
382 | ||
383 | # Rewrite the header file | |
384 | ||
f924200e RL |
385 | if (open(IN, "<$hfile")) { |
386 | # Copy across the old file | |
387 | while(<IN>) { | |
6d311938 DSH |
388 | push @out, $_; |
389 | last if (/BEGIN ERROR CODES/); | |
f924200e RL |
390 | } |
391 | close IN; | |
392 | } else { | |
393 | push @out, | |
394 | "/* ====================================================================\n", | |
74daafaa | 395 | " * Copyright (c) 2001-$year The OpenSSL Project. All rights reserved.\n", |
f924200e RL |
396 | " *\n", |
397 | " * Redistribution and use in source and binary forms, with or without\n", | |
398 | " * modification, are permitted provided that the following conditions\n", | |
399 | " * are met:\n", | |
400 | " *\n", | |
401 | " * 1. Redistributions of source code must retain the above copyright\n", | |
402 | " * notice, this list of conditions and the following disclaimer. \n", | |
403 | " *\n", | |
404 | " * 2. Redistributions in binary form must reproduce the above copyright\n", | |
405 | " * notice, this list of conditions and the following disclaimer in\n", | |
406 | " * the documentation and/or other materials provided with the\n", | |
407 | " * distribution.\n", | |
408 | " *\n", | |
409 | " * 3. All advertising materials mentioning features or use of this\n", | |
410 | " * software must display the following acknowledgment:\n", | |
411 | " * \"This product includes software developed by the OpenSSL Project\n", | |
412 | " * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n", | |
413 | " *\n", | |
414 | " * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n", | |
415 | " * endorse or promote products derived from this software without\n", | |
416 | " * prior written permission. For written permission, please contact\n", | |
417 | " * openssl-core\@openssl.org.\n", | |
418 | " *\n", | |
419 | " * 5. Products derived from this software may not be called \"OpenSSL\"\n", | |
420 | " * nor may \"OpenSSL\" appear in their names without prior written\n", | |
421 | " * permission of the OpenSSL Project.\n", | |
422 | " *\n", | |
423 | " * 6. Redistributions of any form whatsoever must retain the following\n", | |
424 | " * acknowledgment:\n", | |
425 | " * \"This product includes software developed by the OpenSSL Project\n", | |
426 | " * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n", | |
427 | " *\n", | |
428 | " * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n", | |
429 | " * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n", | |
430 | " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n", | |
431 | " * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n", | |
432 | " * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n", | |
433 | " * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n", | |
434 | " * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n", | |
435 | " * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n", | |
436 | " * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n", | |
437 | " * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n", | |
438 | " * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n", | |
439 | " * OF THE POSSIBILITY OF SUCH DAMAGE.\n", | |
440 | " * ====================================================================\n", | |
441 | " *\n", | |
442 | " * This product includes cryptographic software written by Eric Young\n", | |
443 | " * (eay\@cryptsoft.com). This product includes software written by Tim\n", | |
444 | " * Hudson (tjh\@cryptsoft.com).\n", | |
445 | " *\n", | |
446 | " */\n", | |
447 | "\n", | |
448 | "#ifndef HEADER_${lib}_ERR_H\n", | |
449 | "#define HEADER_${lib}_ERR_H\n", | |
450 | "\n", | |
4c1a6e00 LJ |
451 | "#ifdef __cplusplus\n", |
452 | "extern \"C\" {\n", | |
453 | "#endif\n", | |
454 | "\n", | |
f924200e | 455 | "/* BEGIN ERROR CODES */\n"; |
6d311938 | 456 | } |
6d311938 DSH |
457 | open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n"; |
458 | ||
459 | print OUT @out; | |
460 | undef @out; | |
461 | print OUT <<"EOF"; | |
462 | /* The following lines are auto generated by the script mkerr.pl. Any changes | |
463 | * made after this point may be overwritten when the script is next run. | |
464 | */ | |
6343e2fa RL |
465 | EOF |
466 | if($static) { | |
467 | print OUT <<"EOF"; | |
468 | ${staticloader}void ERR_load_${lib}_strings(void); | |
957b6db3 | 469 | |
6343e2fa RL |
470 | EOF |
471 | } else { | |
472 | print OUT <<"EOF"; | |
473 | ${staticloader}void ERR_load_${lib}_strings(void); | |
474 | ${staticloader}void ERR_unload_${lib}_strings(void); | |
475 | ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line); | |
476 | #define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__) | |
957b6db3 | 477 | |
6343e2fa RL |
478 | EOF |
479 | } | |
480 | print OUT <<"EOF"; | |
6d311938 DSH |
481 | /* Error codes for the $lib functions. */ |
482 | ||
483 | /* Function codes. */ | |
484 | EOF | |
485 | ||
486 | foreach $i (@function) { | |
487 | $z=6-int(length($i)/8); | |
488 | if($fcodes{$i} eq "X") { | |
2adc42e4 BM |
489 | $fassigned{$lib} =~ m/^:([^:]*):/; |
490 | $findcode = $1; | |
491 | if (!defined($findcode)) { | |
492 | $findcode = $fmax{$lib}; | |
493 | } | |
494 | while ($fassigned{$lib} =~ m/:$findcode:/) { | |
495 | $findcode++; | |
496 | } | |
497 | $fcodes{$i} = $findcode; | |
498 | $fassigned{$lib} .= "$findcode:"; | |
6d311938 DSH |
499 | print STDERR "New Function code $i\n" if $debug; |
500 | } | |
501 | printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z; | |
502 | } | |
503 | ||
504 | print OUT "\n/* Reason codes. */\n"; | |
505 | ||
506 | foreach $i (@reasons) { | |
507 | $z=6-int(length($i)/8); | |
508 | if($rcodes{$i} eq "X") { | |
2adc42e4 BM |
509 | $rassigned{$lib} =~ m/^:([^:]*):/; |
510 | $findcode = $1; | |
511 | if (!defined($findcode)) { | |
512 | $findcode = $rmax{$lib}; | |
513 | } | |
514 | while ($rassigned{$lib} =~ m/:$findcode:/) { | |
515 | $findcode++; | |
516 | } | |
517 | $rcodes{$i} = $findcode; | |
518 | $rassigned{$lib} .= "$findcode:"; | |
6d311938 DSH |
519 | print STDERR "New Reason code $i\n" if $debug; |
520 | } | |
521 | printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z; | |
522 | } | |
523 | print OUT <<"EOF"; | |
524 | ||
525 | #ifdef __cplusplus | |
526 | } | |
527 | #endif | |
528 | #endif | |
6d311938 DSH |
529 | EOF |
530 | close OUT; | |
531 | ||
532 | # Rewrite the C source file containing the error details. | |
533 | ||
59fc2b0f BM |
534 | # First, read any existing reason string definitions: |
535 | my %err_reason_strings; | |
536 | if (open(IN,"<$cfile")) { | |
537 | while (<IN>) { | |
538 | if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) { | |
539 | $err_reason_strings{$1} = $2; | |
540 | } | |
47a9d527 DSH |
541 | if (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) { |
542 | if (!exists $ftrans{$1} && ($1 ne $2)) { | |
543 | print STDERR "WARNING: Mismatched function string $2\n"; | |
544 | $ftrans{$1} = $2; | |
545 | } | |
546 | } | |
59fc2b0f BM |
547 | } |
548 | close(IN); | |
549 | } | |
550 | ||
47a9d527 | 551 | |
170afce5 DSH |
552 | my $hincf; |
553 | if($static) { | |
554 | $hfile =~ /([^\/]+)$/; | |
c7235be6 | 555 | $hincf = "<${hprefix}$1>"; |
170afce5 DSH |
556 | } else { |
557 | $hincf = "\"$hfile\""; | |
558 | } | |
559 | ||
bc3cae7e DSH |
560 | # If static we know the error code at compile time so use it |
561 | # in error definitions. | |
562 | ||
563 | if ($static) | |
564 | { | |
565 | $pack_errcode = "ERR_LIB_${lib}"; | |
566 | $load_errcode = "0"; | |
567 | } | |
568 | else | |
569 | { | |
570 | $pack_errcode = "0"; | |
571 | $load_errcode = "ERR_LIB_${lib}"; | |
572 | } | |
573 | ||
6d311938 DSH |
574 | |
575 | open (OUT,">$cfile") || die "Can't open $cfile for writing"; | |
576 | ||
577 | print OUT <<"EOF"; | |
578 | /* $cfile */ | |
579 | /* ==================================================================== | |
74daafaa | 580 | * Copyright (c) 1999-$year The OpenSSL Project. All rights reserved. |
6d311938 DSH |
581 | * |
582 | * Redistribution and use in source and binary forms, with or without | |
583 | * modification, are permitted provided that the following conditions | |
584 | * are met: | |
585 | * | |
586 | * 1. Redistributions of source code must retain the above copyright | |
587 | * notice, this list of conditions and the following disclaimer. | |
588 | * | |
589 | * 2. Redistributions in binary form must reproduce the above copyright | |
590 | * notice, this list of conditions and the following disclaimer in | |
591 | * the documentation and/or other materials provided with the | |
592 | * distribution. | |
593 | * | |
594 | * 3. All advertising materials mentioning features or use of this | |
595 | * software must display the following acknowledgment: | |
596 | * "This product includes software developed by the OpenSSL Project | |
597 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | |
598 | * | |
599 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | |
600 | * endorse or promote products derived from this software without | |
601 | * prior written permission. For written permission, please contact | |
602 | * openssl-core\@OpenSSL.org. | |
603 | * | |
604 | * 5. Products derived from this software may not be called "OpenSSL" | |
605 | * nor may "OpenSSL" appear in their names without prior written | |
606 | * permission of the OpenSSL Project. | |
607 | * | |
608 | * 6. Redistributions of any form whatsoever must retain the following | |
609 | * acknowledgment: | |
610 | * "This product includes software developed by the OpenSSL Project | |
611 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | |
612 | * | |
613 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | |
614 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
615 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
616 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | |
617 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
618 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
619 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
620 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
621 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
622 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
623 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
624 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
625 | * ==================================================================== | |
626 | * | |
627 | * This product includes cryptographic software written by Eric Young | |
628 | * (eay\@cryptsoft.com). This product includes software written by Tim | |
629 | * Hudson (tjh\@cryptsoft.com). | |
630 | * | |
631 | */ | |
632 | ||
633 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | |
59fc2b0f BM |
634 | * made to it will be overwritten when the script next updates this file, |
635 | * only reason strings will be preserved. | |
6d311938 DSH |
636 | */ |
637 | ||
638 | #include <stdio.h> | |
639 | #include <openssl/err.h> | |
170afce5 | 640 | #include $hincf |
6d311938 DSH |
641 | |
642 | /* BEGIN ERROR CODES */ | |
487550b6 | 643 | #ifndef OPENSSL_NO_ERR |
bc3cae7e DSH |
644 | |
645 | #define ERR_FUNC(func) ERR_PACK($pack_errcode,func,0) | |
646 | #define ERR_REASON(reason) ERR_PACK($pack_errcode,0,reason) | |
647 | ||
6d311938 DSH |
648 | static ERR_STRING_DATA ${lib}_str_functs[]= |
649 | { | |
650 | EOF | |
651 | # Add each function code: if a function name is found then use it. | |
652 | foreach $i (@function) { | |
653 | my $fn; | |
654 | $i =~ /^${lib}_F_(\S+)$/; | |
655 | $fn = $1; | |
656 | if(exists $ftrans{$fn}) { | |
657 | $fn = $ftrans{$fn}; | |
6d311938 | 658 | } |
bc3cae7e DSH |
659 | # print OUT "{ERR_PACK($pack_errcode,$i,0),\t\"$fn\"},\n"; |
660 | print OUT "{ERR_FUNC($i),\t\"$fn\"},\n"; | |
6d311938 DSH |
661 | } |
662 | print OUT <<"EOF"; | |
663 | {0,NULL} | |
664 | }; | |
665 | ||
666 | static ERR_STRING_DATA ${lib}_str_reasons[]= | |
667 | { | |
668 | EOF | |
669 | # Add each reason code. | |
670 | foreach $i (@reasons) { | |
671 | my $rn; | |
bc3cae7e | 672 | my $rstr = "ERR_REASON($i)"; |
6d311938 | 673 | my $nspc = 0; |
59fc2b0f BM |
674 | if (exists $err_reason_strings{$i}) { |
675 | $rn = $err_reason_strings{$i}; | |
676 | } else { | |
677 | $i =~ /^${lib}_R_(\S+)$/; | |
678 | $rn = $1; | |
679 | $rn =~ tr/_[A-Z]/ [a-z]/; | |
680 | } | |
bc3cae7e | 681 | $nspc = 40 - length($rstr) unless length($rstr) > 40; |
6d311938 | 682 | $nspc = " " x $nspc; |
bc3cae7e | 683 | print OUT "{${rstr}${nspc},\"$rn\"},\n"; |
6d311938 DSH |
684 | } |
685 | if($static) { | |
686 | print OUT <<"EOF"; | |
687 | {0,NULL} | |
688 | }; | |
689 | ||
690 | #endif | |
691 | ||
6343e2fa | 692 | ${staticloader}void ERR_load_${lib}_strings(void) |
6d311938 | 693 | { |
47a9d527 | 694 | #ifndef OPENSSL_NO_ERR |
6d311938 | 695 | |
47a9d527 | 696 | if (ERR_func_error_string(${lib}_str_functs[0].error) == NULL) |
6d311938 | 697 | { |
bc3cae7e DSH |
698 | ERR_load_strings($load_errcode,${lib}_str_functs); |
699 | ERR_load_strings($load_errcode,${lib}_str_reasons); | |
6d311938 | 700 | } |
47a9d527 | 701 | #endif |
6d311938 DSH |
702 | } |
703 | EOF | |
704 | } else { | |
705 | print OUT <<"EOF"; | |
706 | {0,NULL} | |
707 | }; | |
708 | ||
709 | #endif | |
710 | ||
711 | #ifdef ${lib}_LIB_NAME | |
712 | static ERR_STRING_DATA ${lib}_lib_name[]= | |
713 | { | |
714 | {0 ,${lib}_LIB_NAME}, | |
715 | {0,NULL} | |
716 | }; | |
717 | #endif | |
718 | ||
719 | ||
6343e2fa RL |
720 | static int ${lib}_lib_error_code=0; |
721 | static int ${lib}_error_init=1; | |
6d311938 | 722 | |
6343e2fa | 723 | ${staticloader}void ERR_load_${lib}_strings(void) |
6d311938 | 724 | { |
6d311938 DSH |
725 | if (${lib}_lib_error_code == 0) |
726 | ${lib}_lib_error_code=ERR_get_next_error_library(); | |
727 | ||
6343e2fa | 728 | if (${lib}_error_init) |
6d311938 | 729 | { |
6343e2fa | 730 | ${lib}_error_init=0; |
487550b6 | 731 | #ifndef OPENSSL_NO_ERR |
6d311938 DSH |
732 | ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs); |
733 | ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons); | |
734 | #endif | |
735 | ||
736 | #ifdef ${lib}_LIB_NAME | |
737 | ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0); | |
738 | ERR_load_strings(0,${lib}_lib_name); | |
525f51f6 | 739 | #endif |
6d311938 DSH |
740 | } |
741 | } | |
742 | ||
6343e2fa RL |
743 | ${staticloader}void ERR_unload_${lib}_strings(void) |
744 | { | |
745 | if (${lib}_error_init == 0) | |
746 | { | |
747 | #ifndef OPENSSL_NO_ERR | |
748 | ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs); | |
749 | ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons); | |
750 | #endif | |
751 | ||
752 | #ifdef ${lib}_LIB_NAME | |
753 | ERR_unload_strings(0,${lib}_lib_name); | |
754 | #endif | |
755 | ${lib}_error_init=1; | |
756 | } | |
757 | } | |
758 | ||
759 | ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line) | |
6d311938 DSH |
760 | { |
761 | if (${lib}_lib_error_code == 0) | |
762 | ${lib}_lib_error_code=ERR_get_next_error_library(); | |
763 | ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line); | |
764 | } | |
765 | EOF | |
766 | ||
767 | } | |
768 | ||
769 | close OUT; | |
59fc2b0f | 770 | undef %err_reason_strings; |
6d311938 DSH |
771 | } |
772 | ||
296aca9d | 773 | if($debug && %notrans) { |
6d311938 | 774 | print STDERR "The following function codes were not translated:\n"; |
6e781e8e DSH |
775 | foreach(sort keys %notrans) |
776 | { | |
777 | print STDERR "$_\n"; | |
778 | } | |
779 | } | |
780 | ||
781 | # Make a list of unreferenced function and reason codes | |
782 | ||
783 | foreach (keys %fcodes) { | |
784 | push (@funref, $_) unless exists $ufcodes{$_}; | |
785 | } | |
786 | ||
787 | foreach (keys %rcodes) { | |
788 | push (@runref, $_) unless exists $urcodes{$_}; | |
789 | } | |
790 | ||
c434f7f8 | 791 | if($debug && @funref) { |
6e781e8e DSH |
792 | print STDERR "The following function codes were not referenced:\n"; |
793 | foreach(sort @funref) | |
794 | { | |
795 | print STDERR "$_\n"; | |
796 | } | |
797 | } | |
798 | ||
c434f7f8 | 799 | if($debug && @runref) { |
6e781e8e DSH |
800 | print STDERR "The following reason codes were not referenced:\n"; |
801 | foreach(sort @runref) | |
6d311938 DSH |
802 | { |
803 | print STDERR "$_\n"; | |
804 | } | |
805 | } | |
f3d2a9db BL |
806 | |
807 | if($errcount) { | |
808 | print STDERR "There were errors, failing...\n\n"; | |
809 | exit $errcount; | |
810 | } | |
811 |