1 #!/usr/local/bin/perl -w
3 my $config = "crypto/err/openssl.ec";
10 my $staticloader = "";
16 $config = shift @ARGV;
17 } elsif($arg eq "-debug") {
20 } elsif($arg eq "-rebuild") {
23 } elsif($arg eq "-recurse") {
26 } elsif($arg eq "-reindex") {
29 } elsif($arg eq "-nostatic") {
32 } elsif($arg eq "-staticloader") {
33 $staticloader = "static ";
35 } elsif($arg eq "-write") {
44 @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <fips/*.c>,
50 # Read in the config file
52 open(IN, "<$config") || die "Can't open config file $config";
58 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
69 } elsif (/^F\s+(\S+)/) {
70 # Add extra function with $1
71 } elsif (/^R\s+(\S+)\s+(\S+)/) {
79 # Scan each header file in turn and make a list of error codes
82 while (($hdr, $lib) = each %libinc)
84 next if($hdr eq "NONE");
85 print STDERR "Scanning header file $hdr\n" if $debug;
86 my $line = "", $def= "", $linenr = 0, $gotfile = 0;
87 if (open(IN, "<$hdr")) {
91 print STDERR "line: $linenr\r" if $debug;
93 last if(/BEGIN\s+ERROR\s+CODES/);
104 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
106 $cpp = 0 if /^#.*endif/;
110 next if (/^\#/); # skip preprocessor directives
112 s/\/\*.*?\*\///gs; # ignore comments
113 s/{[^{}]*}//gs; # ignore {} blocks
115 if (/\{|\/\*/) { # Add a } so editor works...
123 print STDERR " \r" if $debug;
125 foreach (split /;/, $def) {
127 print STDERR "def: $defnr\r" if $debug;
131 next if(/typedef\W/);
132 if (/\(\*(\w*)\([^\)]+/) {
134 $name =~ tr/[a-z]/[A-Z]/;
136 } elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s){
139 } elsif (/\w+\W+\w+\W*\(.*\)(\s*__attribute__\(.*\)\s*)?$/s) {
140 while (not /\(\)(\s*__attribute__\(.*\)\s*)?$/s) {
141 s/[^\(\)]*\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
142 s/\([^\(\)]*\)\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
145 /(\w+(\{[0-9]+\})?)\W*\(\)/s;
147 $name =~ tr/[a-z]/[A-Z]/;
149 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
150 print STDERR "Header $hdr: cannot parse: $_;\n";
154 print STDERR " \r" if $debug;
158 # Scan function and reason codes and store them: keep a note of the
163 if(/^\#define\s+(\S+)\s+(\S+)/) {
166 next if $name =~ /^${lib}err/;
167 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
168 print STDERR "Invalid error code $name\n";
172 $rcodes{$name} = $code;
173 if(!(exists $rextra{$name}) &&
174 ($code > $rmax{$lib}) ) {
178 if($code > $fmax{$lib}) {
181 $fcodes{$name} = $code;
189 # Scan each C source file and look for function and reason codes
190 # This is done by looking for strings that "look like" function or
191 # reason codes: basically anything consisting of all upper case and
192 # numerics which has _F_ or _R_ in it and which has the name of an
193 # error library at the start. This seems to work fine except for the
194 # oddly named structure BIO_F_CTX which needs to be ignored.
195 # If a code doesn't exist in list compiled from headers then mark it
196 # with the value "X" as a place holder to give it a value later.
197 # Store all function and reason codes found in %ufcodes and %urcodes
198 # so all those unreferenced can be printed out.
201 print STDERR "Files loaded: " if $debug;
202 foreach $file (@source) {
203 # Don't parse the error source file.
204 next if exists $cskip{$file};
205 print STDERR $file if $debug;
206 open(IN, "<$file") || die "Can't open source file $file\n";
208 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
209 next unless exists $csrc{$2};
210 next if($1 eq "BIO_F_BUFFER_CTX");
212 if(!exists $fcodes{$1}) {
216 $notrans{$1} = 1 unless exists $ftrans{$3};
218 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
219 next unless exists $csrc{$2};
221 if(!exists $rcodes{$1}) {
229 print STDERR "\n" if $debug;
231 # Now process each library in turn.
233 foreach $lib (keys %csrc)
235 my $hfile = $hinc{$lib};
236 my $cfile = $csrc{$lib};
237 if(!$fnew{$lib} && !$rnew{$lib}) {
238 print STDERR "$lib:\t\tNo new error codes\n";
239 next unless $rebuild;
241 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
242 print STDERR " $rnew{$lib} New Reasons.\n";
243 next unless $dowrite;
246 # If we get here then we have some new error codes so we
247 # need to rebuild the header file and C file.
249 # Make a sorted list of error and reason codes for later use.
251 my @function = sort grep(/^${lib}_/,keys %fcodes);
252 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
254 # Rewrite the header file
256 if (open(IN, "<$hfile")) {
257 # Copy across the old file
260 last if (/BEGIN ERROR CODES/);
265 "/* ====================================================================\n",
266 " * Copyright (c) 2001-2004 The OpenSSL Project. All rights reserved.\n",
268 " * Redistribution and use in source and binary forms, with or without\n",
269 " * modification, are permitted provided that the following conditions\n",
272 " * 1. Redistributions of source code must retain the above copyright\n",
273 " * notice, this list of conditions and the following disclaimer. \n",
275 " * 2. Redistributions in binary form must reproduce the above copyright\n",
276 " * notice, this list of conditions and the following disclaimer in\n",
277 " * the documentation and/or other materials provided with the\n",
278 " * distribution.\n",
280 " * 3. All advertising materials mentioning features or use of this\n",
281 " * software must display the following acknowledgment:\n",
282 " * \"This product includes software developed by the OpenSSL Project\n",
283 " * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
285 " * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
286 " * endorse or promote products derived from this software without\n",
287 " * prior written permission. For written permission, please contact\n",
288 " * openssl-core\@openssl.org.\n",
290 " * 5. Products derived from this software may not be called \"OpenSSL\"\n",
291 " * nor may \"OpenSSL\" appear in their names without prior written\n",
292 " * permission of the OpenSSL Project.\n",
294 " * 6. Redistributions of any form whatsoever must retain the following\n",
295 " * acknowledgment:\n",
296 " * \"This product includes software developed by the OpenSSL Project\n",
297 " * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
299 " * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
300 " * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
301 " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
302 " * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
303 " * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
304 " * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
305 " * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
306 " * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
307 " * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
308 " * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
309 " * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
310 " * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
311 " * ====================================================================\n",
313 " * This product includes cryptographic software written by Eric Young\n",
314 " * (eay\@cryptsoft.com). This product includes software written by Tim\n",
315 " * Hudson (tjh\@cryptsoft.com).\n",
319 "#ifndef HEADER_${lib}_ERR_H\n",
320 "#define HEADER_${lib}_ERR_H\n",
322 "/* BEGIN ERROR CODES */\n";
324 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
329 /* The following lines are auto generated by the script mkerr.pl. Any changes
330 * made after this point may be overwritten when the script is next run.
335 ${staticloader}void ERR_load_${lib}_strings(void);
340 ${staticloader}void ERR_load_${lib}_strings(void);
341 ${staticloader}void ERR_unload_${lib}_strings(void);
342 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
343 #define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
348 /* Error codes for the $lib functions. */
350 /* Function codes. */
353 foreach $i (@function) {
354 $z=6-int(length($i)/8);
355 if($fcodes{$i} eq "X") {
356 $fcodes{$i} = ++$fmax{$lib};
357 print STDERR "New Function code $i\n" if $debug;
359 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
362 print OUT "\n/* Reason codes. */\n";
364 foreach $i (@reasons) {
365 $z=6-int(length($i)/8);
366 if($rcodes{$i} eq "X") {
367 $rcodes{$i} = ++$rmax{$lib};
368 print STDERR "New Reason code $i\n" if $debug;
370 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
381 # Rewrite the C source file containing the error details.
383 # First, read any existing reason string definitions:
384 my %err_reason_strings;
385 if (open(IN,"<$cfile")) {
387 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
388 $err_reason_strings{$1} = $2;
396 $hfile =~ /([^\/]+)$/;
397 $hincf = "<openssl/$1>";
399 $hincf = "\"$hfile\"";
403 open (OUT,">$cfile") || die "Can't open $cfile for writing";
407 /* ====================================================================
408 * Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved.
410 * Redistribution and use in source and binary forms, with or without
411 * modification, are permitted provided that the following conditions
414 * 1. Redistributions of source code must retain the above copyright
415 * notice, this list of conditions and the following disclaimer.
417 * 2. Redistributions in binary form must reproduce the above copyright
418 * notice, this list of conditions and the following disclaimer in
419 * the documentation and/or other materials provided with the
422 * 3. All advertising materials mentioning features or use of this
423 * software must display the following acknowledgment:
424 * "This product includes software developed by the OpenSSL Project
425 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
427 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
428 * endorse or promote products derived from this software without
429 * prior written permission. For written permission, please contact
430 * openssl-core\@OpenSSL.org.
432 * 5. Products derived from this software may not be called "OpenSSL"
433 * nor may "OpenSSL" appear in their names without prior written
434 * permission of the OpenSSL Project.
436 * 6. Redistributions of any form whatsoever must retain the following
438 * "This product includes software developed by the OpenSSL Project
439 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
441 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
442 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
443 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
444 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
445 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
446 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
447 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
448 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
449 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
450 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
451 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
452 * OF THE POSSIBILITY OF SUCH DAMAGE.
453 * ====================================================================
455 * This product includes cryptographic software written by Eric Young
456 * (eay\@cryptsoft.com). This product includes software written by Tim
457 * Hudson (tjh\@cryptsoft.com).
461 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
462 * made to it will be overwritten when the script next updates this file,
463 * only reason strings will be preserved.
467 #include <openssl/err.h>
470 /* BEGIN ERROR CODES */
471 #ifndef OPENSSL_NO_ERR
472 static ERR_STRING_DATA ${lib}_str_functs[]=
475 # Add each function code: if a function name is found then use it.
476 foreach $i (@function) {
478 $i =~ /^${lib}_F_(\S+)$/;
480 if(exists $ftrans{$fn}) {
483 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
489 static ERR_STRING_DATA ${lib}_str_reasons[]=
492 # Add each reason code.
493 foreach $i (@reasons) {
496 if (exists $err_reason_strings{$i}) {
497 $rn = $err_reason_strings{$i};
499 $i =~ /^${lib}_R_(\S+)$/;
501 $rn =~ tr/_[A-Z]/ [a-z]/;
503 $nspc = 40 - length($i) unless length($i) > 40;
505 print OUT "{${i}${nspc},\"$rn\"},\n";
514 ${staticloader}void ERR_load_${lib}_strings(void)
521 #ifndef OPENSSL_NO_ERR
522 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
523 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
536 #ifdef ${lib}_LIB_NAME
537 static ERR_STRING_DATA ${lib}_lib_name[]=
539 {0 ,${lib}_LIB_NAME},
545 static int ${lib}_lib_error_code=0;
546 static int ${lib}_error_init=1;
548 ${staticloader}void ERR_load_${lib}_strings(void)
550 if (${lib}_lib_error_code == 0)
551 ${lib}_lib_error_code=ERR_get_next_error_library();
553 if (${lib}_error_init)
556 #ifndef OPENSSL_NO_ERR
557 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
558 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
561 #ifdef ${lib}_LIB_NAME
562 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
563 ERR_load_strings(0,${lib}_lib_name);
568 ${staticloader}void ERR_unload_${lib}_strings(void)
570 if (${lib}_error_init == 0)
572 #ifndef OPENSSL_NO_ERR
573 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
574 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
577 #ifdef ${lib}_LIB_NAME
578 ERR_unload_strings(0,${lib}_lib_name);
584 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
586 if (${lib}_lib_error_code == 0)
587 ${lib}_lib_error_code=ERR_get_next_error_library();
588 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
595 undef %err_reason_strings;
598 if($debug && defined(%notrans)) {
599 print STDERR "The following function codes were not translated:\n";
600 foreach(sort keys %notrans)
606 # Make a list of unreferenced function and reason codes
608 foreach (keys %fcodes) {
609 push (@funref, $_) unless exists $ufcodes{$_};
612 foreach (keys %rcodes) {
613 push (@runref, $_) unless exists $urcodes{$_};
616 if($debug && defined(@funref) ) {
617 print STDERR "The following function codes were not referenced:\n";
618 foreach(sort @funref)
624 if($debug && defined(@runref) ) {
625 print STDERR "The following reason codes were not referenced:\n";
626 foreach(sort @runref)