mkerr.pl 23 KB

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