mkerr.pl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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(/^\#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-2009 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. /* The following lines are auto generated by the script mkerr.pl. Any changes
  405. * made after this point may be overwritten when the script is next run.
  406. */
  407. EOF
  408. if($static) {
  409. print OUT <<"EOF";
  410. ${staticloader}void ERR_load_${lib}_strings(void);
  411. EOF
  412. } else {
  413. print OUT <<"EOF";
  414. ${staticloader}void ERR_load_${lib}_strings(void);
  415. ${staticloader}void ERR_unload_${lib}_strings(void);
  416. ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
  417. #define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
  418. EOF
  419. }
  420. print OUT <<"EOF";
  421. /* Error codes for the $lib functions. */
  422. /* Function codes. */
  423. EOF
  424. foreach $i (@function) {
  425. $z=6-int(length($i)/8);
  426. if($fcodes{$i} eq "X") {
  427. $fassigned{$lib} =~ m/^:([^:]*):/;
  428. $findcode = $1;
  429. if (!defined($findcode)) {
  430. $findcode = $fmax{$lib};
  431. }
  432. while ($fassigned{$lib} =~ m/:$findcode:/) {
  433. $findcode++;
  434. }
  435. $fcodes{$i} = $findcode;
  436. $fassigned{$lib} .= "$findcode:";
  437. print STDERR "New Function code $i\n" if $debug;
  438. }
  439. printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
  440. }
  441. print OUT "\n/* Reason codes. */\n";
  442. foreach $i (@reasons) {
  443. $z=6-int(length($i)/8);
  444. if($rcodes{$i} eq "X") {
  445. $rassigned{$lib} =~ m/^:([^:]*):/;
  446. $findcode = $1;
  447. if (!defined($findcode)) {
  448. $findcode = $rmax{$lib};
  449. }
  450. while ($rassigned{$lib} =~ m/:$findcode:/) {
  451. $findcode++;
  452. }
  453. $rcodes{$i} = $findcode;
  454. $rassigned{$lib} .= "$findcode:";
  455. print STDERR "New Reason code $i\n" if $debug;
  456. }
  457. printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
  458. }
  459. print OUT <<"EOF";
  460. #ifdef __cplusplus
  461. }
  462. #endif
  463. #endif
  464. EOF
  465. close OUT;
  466. # Rewrite the C source file containing the error details.
  467. # First, read any existing reason string definitions:
  468. my %err_reason_strings;
  469. if (open(IN,"<$cfile")) {
  470. while (<IN>) {
  471. if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
  472. $err_reason_strings{$1} = $2;
  473. }
  474. if (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) {
  475. if (!exists $ftrans{$1} && ($1 ne $2)) {
  476. print STDERR "WARNING: Mismatched function string $2\n";
  477. $ftrans{$1} = $2;
  478. }
  479. }
  480. }
  481. close(IN);
  482. }
  483. my $hincf;
  484. if($static) {
  485. $hfile =~ /([^\/]+)$/;
  486. $hincf = "<${hprefix}$1>";
  487. } else {
  488. $hincf = "\"$hfile\"";
  489. }
  490. # If static we know the error code at compile time so use it
  491. # in error definitions.
  492. if ($static)
  493. {
  494. $pack_errcode = "ERR_LIB_${lib}";
  495. $load_errcode = "0";
  496. }
  497. else
  498. {
  499. $pack_errcode = "0";
  500. $load_errcode = "ERR_LIB_${lib}";
  501. }
  502. open (OUT,">$cfile") || die "Can't open $cfile for writing";
  503. print OUT <<"EOF";
  504. /* $cfile */
  505. /* ====================================================================
  506. * Copyright (c) 1999-2009 The OpenSSL Project. All rights reserved.
  507. *
  508. * Redistribution and use in source and binary forms, with or without
  509. * modification, are permitted provided that the following conditions
  510. * are met:
  511. *
  512. * 1. Redistributions of source code must retain the above copyright
  513. * notice, this list of conditions and the following disclaimer.
  514. *
  515. * 2. Redistributions in binary form must reproduce the above copyright
  516. * notice, this list of conditions and the following disclaimer in
  517. * the documentation and/or other materials provided with the
  518. * distribution.
  519. *
  520. * 3. All advertising materials mentioning features or use of this
  521. * software must display the following acknowledgment:
  522. * "This product includes software developed by the OpenSSL Project
  523. * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
  524. *
  525. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  526. * endorse or promote products derived from this software without
  527. * prior written permission. For written permission, please contact
  528. * openssl-core\@OpenSSL.org.
  529. *
  530. * 5. Products derived from this software may not be called "OpenSSL"
  531. * nor may "OpenSSL" appear in their names without prior written
  532. * permission of the OpenSSL Project.
  533. *
  534. * 6. Redistributions of any form whatsoever must retain the following
  535. * acknowledgment:
  536. * "This product includes software developed by the OpenSSL Project
  537. * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
  538. *
  539. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  540. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  541. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  542. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  543. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  544. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  545. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  546. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  547. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  548. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  549. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  550. * OF THE POSSIBILITY OF SUCH DAMAGE.
  551. * ====================================================================
  552. *
  553. * This product includes cryptographic software written by Eric Young
  554. * (eay\@cryptsoft.com). This product includes software written by Tim
  555. * Hudson (tjh\@cryptsoft.com).
  556. *
  557. */
  558. /* NOTE: this file was auto generated by the mkerr.pl script: any changes
  559. * made to it will be overwritten when the script next updates this file,
  560. * only reason strings will be preserved.
  561. */
  562. #include <stdio.h>
  563. #include <openssl/err.h>
  564. #include $hincf
  565. /* BEGIN ERROR CODES */
  566. #ifndef OPENSSL_NO_ERR
  567. #define ERR_FUNC(func) ERR_PACK($pack_errcode,func,0)
  568. #define ERR_REASON(reason) ERR_PACK($pack_errcode,0,reason)
  569. static ERR_STRING_DATA ${lib}_str_functs[]=
  570. {
  571. EOF
  572. # Add each function code: if a function name is found then use it.
  573. foreach $i (@function) {
  574. my $fn;
  575. $i =~ /^${lib}_F_(\S+)$/;
  576. $fn = $1;
  577. if(exists $ftrans{$fn}) {
  578. $fn = $ftrans{$fn};
  579. }
  580. # print OUT "{ERR_PACK($pack_errcode,$i,0),\t\"$fn\"},\n";
  581. print OUT "{ERR_FUNC($i),\t\"$fn\"},\n";
  582. }
  583. print OUT <<"EOF";
  584. {0,NULL}
  585. };
  586. static ERR_STRING_DATA ${lib}_str_reasons[]=
  587. {
  588. EOF
  589. # Add each reason code.
  590. foreach $i (@reasons) {
  591. my $rn;
  592. my $rstr = "ERR_REASON($i)";
  593. my $nspc = 0;
  594. if (exists $err_reason_strings{$i}) {
  595. $rn = $err_reason_strings{$i};
  596. } else {
  597. $i =~ /^${lib}_R_(\S+)$/;
  598. $rn = $1;
  599. $rn =~ tr/_[A-Z]/ [a-z]/;
  600. }
  601. $nspc = 40 - length($rstr) unless length($rstr) > 40;
  602. $nspc = " " x $nspc;
  603. print OUT "{${rstr}${nspc},\"$rn\"},\n";
  604. }
  605. if($static) {
  606. print OUT <<"EOF";
  607. {0,NULL}
  608. };
  609. #endif
  610. ${staticloader}void ERR_load_${lib}_strings(void)
  611. {
  612. #ifndef OPENSSL_NO_ERR
  613. if (ERR_func_error_string(${lib}_str_functs[0].error) == NULL)
  614. {
  615. ERR_load_strings($load_errcode,${lib}_str_functs);
  616. ERR_load_strings($load_errcode,${lib}_str_reasons);
  617. }
  618. #endif
  619. }
  620. EOF
  621. } else {
  622. print OUT <<"EOF";
  623. {0,NULL}
  624. };
  625. #endif
  626. #ifdef ${lib}_LIB_NAME
  627. static ERR_STRING_DATA ${lib}_lib_name[]=
  628. {
  629. {0 ,${lib}_LIB_NAME},
  630. {0,NULL}
  631. };
  632. #endif
  633. static int ${lib}_lib_error_code=0;
  634. static int ${lib}_error_init=1;
  635. ${staticloader}void ERR_load_${lib}_strings(void)
  636. {
  637. if (${lib}_lib_error_code == 0)
  638. ${lib}_lib_error_code=ERR_get_next_error_library();
  639. if (${lib}_error_init)
  640. {
  641. ${lib}_error_init=0;
  642. #ifndef OPENSSL_NO_ERR
  643. ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
  644. ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
  645. #endif
  646. #ifdef ${lib}_LIB_NAME
  647. ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
  648. ERR_load_strings(0,${lib}_lib_name);
  649. #endif
  650. }
  651. }
  652. ${staticloader}void ERR_unload_${lib}_strings(void)
  653. {
  654. if (${lib}_error_init == 0)
  655. {
  656. #ifndef OPENSSL_NO_ERR
  657. ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
  658. ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
  659. #endif
  660. #ifdef ${lib}_LIB_NAME
  661. ERR_unload_strings(0,${lib}_lib_name);
  662. #endif
  663. ${lib}_error_init=1;
  664. }
  665. }
  666. ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
  667. {
  668. if (${lib}_lib_error_code == 0)
  669. ${lib}_lib_error_code=ERR_get_next_error_library();
  670. ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
  671. }
  672. EOF
  673. }
  674. close OUT;
  675. undef %err_reason_strings;
  676. }
  677. if($debug && defined(%notrans)) {
  678. print STDERR "The following function codes were not translated:\n";
  679. foreach(sort keys %notrans)
  680. {
  681. print STDERR "$_\n";
  682. }
  683. }
  684. # Make a list of unreferenced function and reason codes
  685. foreach (keys %fcodes) {
  686. push (@funref, $_) unless exists $ufcodes{$_};
  687. }
  688. foreach (keys %rcodes) {
  689. push (@runref, $_) unless exists $urcodes{$_};
  690. }
  691. if($debug && defined(@funref) ) {
  692. print STDERR "The following function codes were not referenced:\n";
  693. foreach(sort @funref)
  694. {
  695. print STDERR "$_\n";
  696. }
  697. }
  698. if($debug && defined(@runref) ) {
  699. print STDERR "The following reason codes were not referenced:\n";
  700. foreach(sort @runref)
  701. {
  702. print STDERR "$_\n";
  703. }
  704. }
  705. if($errcount) {
  706. print STDERR "There were errors, failing...\n\n";
  707. exit $errcount;
  708. }