mkerr.pl 23 KB

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