mkerr.pl 19 KB

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