mkdef.pl 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. #!/usr/local/bin/perl -w
  2. #
  3. # generate a .def file
  4. #
  5. # It does this by parsing the header files and looking for the
  6. # prototyped functions: it then prunes the output.
  7. #
  8. # Intermediary files are created, call libeay.num and ssleay.num,
  9. # The format of these files is:
  10. #
  11. # routine-name nnnn vers info
  12. #
  13. # The "nnnn" and "vers" fields are the numeric id and version for the symbol
  14. # respectively. The "info" part is actually a colon-separated string of fields
  15. # with the following meaning:
  16. #
  17. # existence:platform:kind:algorithms
  18. #
  19. # - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
  20. # found somewhere in the source,
  21. # - "platforms" is empty if it exists on all platforms, otherwise it contains
  22. # comma-separated list of the platform, just as they are if the symbol exists
  23. # for those platforms, or prepended with a "!" if not. This helps resolve
  24. # symbol name variants for platforms where the names are too long for the
  25. # compiler or linker, or if the systems is case insensitive and there is a
  26. # clash, or the symbol is implemented differently (see
  27. # EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found
  28. # in the file crypto/symhacks.h.
  29. # The semantics for the platforms is that every item is checked against the
  30. # environment. For the negative items ("!FOO"), if any of them is false
  31. # (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
  32. # used. For the positive itms, if all of them are false in the environment,
  33. # the corresponding symbol can't be used. Any combination of positive and
  34. # negative items are possible, and of course leave room for some redundancy.
  35. # - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious.
  36. # - "algorithms" is a comma-separated list of algorithm names. This helps
  37. # exclude symbols that are part of an algorithm that some user wants to
  38. # exclude.
  39. #
  40. use lib ".";
  41. use configdata;
  42. use File::Spec::Functions;
  43. my $debug=0;
  44. my $crypto_num= catfile($config{sourcedir},"util","libeay.num");
  45. my $ssl_num= catfile($config{sourcedir},"util","ssleay.num");
  46. my $libname;
  47. my $do_update = 0;
  48. my $do_rewrite = 1;
  49. my $do_crypto = 0;
  50. my $do_ssl = 0;
  51. my $do_ctest = 0;
  52. my $do_ctestall = 0;
  53. my $do_checkexist = 0;
  54. my $VMSVAX=0;
  55. my $VMSNonVAX=0;
  56. my $VMS=0;
  57. my $W32=0;
  58. my $NT=0;
  59. my $OS2=0;
  60. my $linux=0;
  61. # Set this to make typesafe STACK definitions appear in DEF
  62. my $safe_stack_def = 0;
  63. my @known_platforms = ( "__FreeBSD__", "PERL5",
  64. "EXPORT_VAR_AS_FUNCTION", "ZLIB"
  65. );
  66. my @known_ossl_platforms = ( "VMS", "WIN32", "WINNT", "OS2" );
  67. my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
  68. "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
  69. "SHA256", "SHA512", "RMD160",
  70. "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "EC2M",
  71. "HMAC", "AES", "CAMELLIA", "SEED", "GOST",
  72. "SCRYPT", "CHACHA", "POLY1305",
  73. # EC_NISTP_64_GCC_128
  74. "EC_NISTP_64_GCC_128",
  75. # Envelope "algorithms"
  76. "EVP", "X509", "ASN1_TYPEDEFS",
  77. # Helper "algorithms"
  78. "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
  79. "LOCKING",
  80. # External "algorithms"
  81. "FP_API", "STDIO", "SOCK", "DGRAM",
  82. "CRYPTO_MDEBUG",
  83. # Engines
  84. "STATIC_ENGINE", "ENGINE", "HW", "GMP",
  85. # Entropy Gathering
  86. "EGD",
  87. # X.509v3 Signed Certificate Timestamps
  88. "SCT",
  89. # RFC3779
  90. "RFC3779",
  91. # TLS
  92. "PSK", "SRP", "HEARTBEATS",
  93. # CMS
  94. "CMS",
  95. # CryptoAPI Engine
  96. "CAPIENG",
  97. # SSL v3 method
  98. "SSL3_METHOD",
  99. # JPAKE
  100. "JPAKE",
  101. # NEXTPROTONEG
  102. "NEXTPROTONEG",
  103. # Deprecated functions
  104. "DEPRECATEDIN_0_9_8",
  105. "DEPRECATEDIN_1_0_0",
  106. "DEPRECATEDIN_1_1_0",
  107. # SCTP
  108. "SCTP",
  109. # SRTP
  110. "SRTP",
  111. # SSL TRACE
  112. "SSL_TRACE",
  113. # Unit testing
  114. "UNIT_TEST",
  115. # OCB mode
  116. "OCB",
  117. # APPLINK (win build feature?)
  118. "APPLINK"
  119. );
  120. my %disabled_algorithms;
  121. foreach (@known_algorithms) {
  122. $disabled_algorithms{$_} = 0;
  123. }
  124. # disabled by default
  125. $disabled_algorithms{"STATIC_ENGINE"} = 1;
  126. my $zlib;
  127. foreach (@ARGV, split(/ /, $config{options}))
  128. {
  129. $debug=1 if $_ eq "debug";
  130. $W32=1 if $_ eq "32";
  131. die "win16 not supported" if $_ eq "16";
  132. if($_ eq "NT") {
  133. $W32 = 1;
  134. $NT = 1;
  135. }
  136. if ($_ eq "VMS-VAX") {
  137. $VMS=1;
  138. $VMSVAX=1;
  139. }
  140. if ($_ eq "VMS-NonVAX") {
  141. $VMS=1;
  142. $VMSNonVAX=1;
  143. }
  144. if ($_ eq "linux") {
  145. $linux=1;
  146. }
  147. $VMS=$VMSNonVAX=1 if $_ eq "VMS";
  148. $OS2=1 if $_ eq "OS2";
  149. if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
  150. || $_ eq "enable-zlib-dynamic") {
  151. $zlib = 1;
  152. }
  153. $do_ssl=1 if $_ eq "ssleay";
  154. if ($_ eq "ssl") {
  155. $do_ssl=1;
  156. $libname=$_
  157. }
  158. $do_crypto=1 if $_ eq "libeay";
  159. if ($_ eq "crypto") {
  160. $do_crypto=1;
  161. $libname=$_;
  162. }
  163. $do_update=1 if $_ eq "update";
  164. $do_rewrite=1 if $_ eq "rewrite";
  165. $do_ctest=1 if $_ eq "ctest";
  166. $do_ctestall=1 if $_ eq "ctestall";
  167. $do_checkexist=1 if $_ eq "exist";
  168. #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
  169. if (/^--api=(\d+)\.(\d+)\.(\d+)$/) {
  170. my $apiv = sprintf "%x%02x%02x", $1, $2, $3;
  171. foreach (keys %disabled_algorithms) {
  172. if (/^DEPRECATEDIN_(\d+)_(\d+)_(\d+)$/) {
  173. my $depv = sprintf "%x%02x%02x", $1, $2, $3;
  174. $disabled_algorithms{$_} = 1 if $apiv ge $depv;
  175. }
  176. }
  177. }
  178. if (/^no-deprecated$/) {
  179. foreach (keys %disabled_algorithms) {
  180. if (/^DEPRECATEDIN_/) {
  181. $disabled_algorithms{$_} = 1;
  182. }
  183. }
  184. }
  185. elsif (/^(enable|disable|no)-(.*)$/) {
  186. my $alg = uc $2;
  187. $alg =~ tr/-/_/;
  188. if (exists $disabled_algorithms{$alg}) {
  189. $disabled_algorithms{$alg} = $1 eq "enable" ? 0 : 1;
  190. }
  191. }
  192. }
  193. if (!$libname) {
  194. if ($do_ssl) {
  195. $libname="SSLEAY";
  196. }
  197. if ($do_crypto) {
  198. $libname="LIBEAY";
  199. }
  200. }
  201. # If no platform is given, assume WIN32
  202. if ($W32 + $VMS + $OS2 + $linux == 0) {
  203. $W32 = 1;
  204. }
  205. die "Please, only one platform at a time"
  206. if ($W32 + $VMS + $OS2 + $linux > 1);
  207. if (!$do_ssl && !$do_crypto)
  208. {
  209. print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 | linux | VMS ]\n";
  210. exit(1);
  211. }
  212. %ssl_list=&load_numbers($ssl_num);
  213. $max_ssl = $max_num;
  214. %crypto_list=&load_numbers($crypto_num);
  215. $max_crypto = $max_num;
  216. my $ssl="include/openssl/ssl.h";
  217. $ssl.=" include/openssl/tls1.h";
  218. $ssl.=" include/openssl/srtp.h";
  219. my $crypto ="include/openssl/crypto.h";
  220. $crypto.=" crypto/include/internal/cryptlib.h";
  221. $crypto.=" crypto/include/internal/chacha.h"; # unless $no_chacha;
  222. $crypto.=" crypto/include/internal/poly1305.h"; # unless $no_poly1305;
  223. $crypto.=" include/internal/o_dir.h";
  224. $crypto.=" include/internal/o_str.h";
  225. $crypto.=" include/openssl/des.h" ; # unless $no_des;
  226. $crypto.=" include/openssl/idea.h" ; # unless $no_idea;
  227. $crypto.=" include/openssl/rc4.h" ; # unless $no_rc4;
  228. $crypto.=" include/openssl/rc5.h" ; # unless $no_rc5;
  229. $crypto.=" include/openssl/rc2.h" ; # unless $no_rc2;
  230. $crypto.=" include/openssl/blowfish.h" ; # unless $no_bf;
  231. $crypto.=" include/openssl/cast.h" ; # unless $no_cast;
  232. $crypto.=" include/openssl/whrlpool.h" ;
  233. $crypto.=" include/openssl/md2.h" ; # unless $no_md2;
  234. $crypto.=" include/openssl/md4.h" ; # unless $no_md4;
  235. $crypto.=" include/openssl/md5.h" ; # unless $no_md5;
  236. $crypto.=" include/openssl/mdc2.h" ; # unless $no_mdc2;
  237. $crypto.=" include/openssl/sha.h" ; # unless $no_sha;
  238. $crypto.=" include/openssl/ripemd.h" ; # unless $no_ripemd;
  239. $crypto.=" include/openssl/aes.h" ; # unless $no_aes;
  240. $crypto.=" include/openssl/camellia.h" ; # unless $no_camellia;
  241. $crypto.=" include/openssl/seed.h"; # unless $no_seed;
  242. $crypto.=" include/openssl/bn.h";
  243. $crypto.=" include/openssl/rsa.h" ; # unless $no_rsa;
  244. $crypto.=" include/openssl/dsa.h" ; # unless $no_dsa;
  245. $crypto.=" include/openssl/dh.h" ; # unless $no_dh;
  246. $crypto.=" include/openssl/ec.h" ; # unless $no_ec;
  247. $crypto.=" include/openssl/hmac.h" ; # unless $no_hmac;
  248. $crypto.=" include/openssl/cmac.h" ;
  249. $crypto.=" include/openssl/engine.h"; # unless $no_engine;
  250. $crypto.=" include/openssl/stack.h" ; # unless $no_stack;
  251. $crypto.=" include/openssl/buffer.h" ; # unless $no_buffer;
  252. $crypto.=" include/openssl/bio.h" ; # unless $no_bio;
  253. $crypto.=" include/openssl/dso.h" ; # unless $no_dso;
  254. $crypto.=" include/openssl/lhash.h" ; # unless $no_lhash;
  255. $crypto.=" include/openssl/conf.h";
  256. $crypto.=" include/openssl/txt_db.h";
  257. $crypto.=" include/openssl/evp.h" ; # unless $no_evp;
  258. $crypto.=" include/openssl/objects.h";
  259. $crypto.=" include/openssl/pem.h";
  260. #$crypto.=" include/openssl/meth.h";
  261. $crypto.=" include/openssl/asn1.h";
  262. $crypto.=" include/openssl/asn1t.h";
  263. $crypto.=" include/openssl/err.h" ; # unless $no_err;
  264. $crypto.=" include/openssl/pkcs7.h";
  265. $crypto.=" include/openssl/pkcs12.h";
  266. $crypto.=" include/openssl/x509.h";
  267. $crypto.=" include/openssl/x509_vfy.h";
  268. $crypto.=" include/openssl/x509v3.h";
  269. $crypto.=" include/openssl/ts.h";
  270. $crypto.=" include/openssl/rand.h";
  271. $crypto.=" include/openssl/comp.h" ; # unless $no_comp;
  272. $crypto.=" include/openssl/ocsp.h";
  273. $crypto.=" include/openssl/ui.h";
  274. #$crypto.=" include/openssl/store.h";
  275. $crypto.=" include/openssl/cms.h";
  276. $crypto.=" include/openssl/jpake.h";
  277. $crypto.=" include/openssl/srp.h";
  278. $crypto.=" include/openssl/modes.h";
  279. $crypto.=" include/openssl/async.h";
  280. my $symhacks="include/openssl/symhacks.h";
  281. my @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks);
  282. my @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks);
  283. if ($do_update) {
  284. if ($do_ssl == 1) {
  285. &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols);
  286. if ($do_rewrite == 1) {
  287. open(OUT, ">$ssl_num");
  288. &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols);
  289. } else {
  290. open(OUT, ">>$ssl_num");
  291. }
  292. &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols);
  293. close OUT;
  294. }
  295. if($do_crypto == 1) {
  296. &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols);
  297. if ($do_rewrite == 1) {
  298. open(OUT, ">$crypto_num");
  299. &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols);
  300. } else {
  301. open(OUT, ">>$crypto_num");
  302. }
  303. &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols);
  304. close OUT;
  305. }
  306. } elsif ($do_checkexist) {
  307. &check_existing(*ssl_list, @ssl_symbols)
  308. if $do_ssl == 1;
  309. &check_existing(*crypto_list, @crypto_symbols)
  310. if $do_crypto == 1;
  311. } elsif ($do_ctest || $do_ctestall) {
  312. print <<"EOF";
  313. /* Test file to check all DEF file symbols are present by trying
  314. * to link to all of them. This is *not* intended to be run!
  315. */
  316. int main()
  317. {
  318. EOF
  319. &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols)
  320. if $do_ssl == 1;
  321. &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols)
  322. if $do_crypto == 1;
  323. print "}\n";
  324. } else {
  325. &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
  326. if $do_ssl == 1;
  327. &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
  328. if $do_crypto == 1;
  329. }
  330. sub do_defs
  331. {
  332. my($name,$files,$symhacksfile)=@_;
  333. my $file;
  334. my @ret;
  335. my %syms;
  336. my %platform; # For anything undefined, we assume ""
  337. my %kind; # For anything undefined, we assume "FUNCTION"
  338. my %algorithm; # For anything undefined, we assume ""
  339. my %variant;
  340. my %variant_cnt; # To be able to allocate "name{n}" if "name"
  341. # is the same name as the original.
  342. my $cpp;
  343. my %unknown_algorithms = ();
  344. my $parens = 0;
  345. foreach $file (split(/\s+/,$symhacksfile." ".$files))
  346. {
  347. my $fn = catfile($config{sourcedir},$file);
  348. print STDERR "DEBUG: starting on $fn:\n" if $debug;
  349. open(IN,"<$fn") || die "unable to open $fn:$!\n";
  350. my $line = "", my $def= "";
  351. my %tag = (
  352. (map { $_ => 0 } @known_platforms),
  353. (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
  354. (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
  355. (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
  356. NOPROTO => 0,
  357. PERL5 => 0,
  358. _WINDLL => 0,
  359. CONST_STRICT => 0,
  360. TRUE => 1,
  361. );
  362. my $symhacking = $file eq $symhacksfile;
  363. my @current_platforms = ();
  364. my @current_algorithms = ();
  365. # params: symbol, alias, platforms, kind
  366. # The reason to put this subroutine in a variable is that
  367. # it will otherwise create it's own, unshared, version of
  368. # %tag and %variant...
  369. my $make_variant = sub
  370. {
  371. my ($s, $a, $p, $k) = @_;
  372. my ($a1, $a2);
  373. print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
  374. if (defined($p))
  375. {
  376. $a1 = join(",",$p,
  377. grep(!/^$/,
  378. map { $tag{$_} == 1 ? $_ : "" }
  379. @known_platforms));
  380. }
  381. else
  382. {
  383. $a1 = join(",",
  384. grep(!/^$/,
  385. map { $tag{$_} == 1 ? $_ : "" }
  386. @known_platforms));
  387. }
  388. $a2 = join(",",
  389. grep(!/^$/,
  390. map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
  391. @known_ossl_platforms));
  392. print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
  393. if ($a1 eq "") { $a1 = $a2; }
  394. elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
  395. if ($a eq $s)
  396. {
  397. if (!defined($variant_cnt{$s}))
  398. {
  399. $variant_cnt{$s} = 0;
  400. }
  401. $variant_cnt{$s}++;
  402. $a .= "{$variant_cnt{$s}}";
  403. }
  404. my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
  405. my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
  406. if (!grep(/^$togrep$/,
  407. split(/;/, defined($variant{$s})?$variant{$s}:""))) {
  408. if (defined($variant{$s})) { $variant{$s} .= ";"; }
  409. $variant{$s} .= $toadd;
  410. }
  411. print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
  412. };
  413. print STDERR "DEBUG: parsing ----------\n" if $debug;
  414. while(<IN>) {
  415. if($parens > 0) {
  416. #Inside a DEPRECATEDIN
  417. $stored_multiline .= $_;
  418. $stored_multiline =~ s|\R$||; # Better chomp
  419. print STDERR "DEBUG: Continuing multiline DEPRECATEDIN: $stored_multiline\n" if $debug;
  420. $parens = count_parens($stored_multiline);
  421. if ($parens == 0) {
  422. $def .= do_deprecated($stored_multiline,
  423. \@current_platforms,
  424. \@current_algorithms);
  425. }
  426. next;
  427. }
  428. if (/\/\* Error codes for the \w+ functions\. \*\//)
  429. {
  430. undef @tag;
  431. last;
  432. }
  433. if ($line ne '') {
  434. $_ = $line . $_;
  435. $line = '';
  436. }
  437. if (/\\$/) {
  438. $line = $`; # keep what was before the backslash
  439. next;
  440. }
  441. if(/\/\*/) {
  442. if (not /\*\//) { # multiline comment...
  443. $line = $_; # ... just accumulate
  444. next;
  445. } else {
  446. s/\/\*.*?\*\///gs;# wipe it
  447. }
  448. }
  449. if ($cpp) {
  450. $cpp++ if /^#\s*if/;
  451. $cpp-- if /^#\s*endif/;
  452. next;
  453. }
  454. $cpp = 1 if /^#.*ifdef.*cplusplus/;
  455. s/{[^{}]*}//gs; # ignore {} blocks
  456. print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
  457. print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
  458. if (/^\#\s*ifndef\s+(.*)/) {
  459. push(@tag,"-");
  460. push(@tag,$1);
  461. $tag{$1}=-1;
  462. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  463. } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
  464. push(@tag,"-");
  465. if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
  466. my $tmp_1 = $1;
  467. my $tmp_;
  468. foreach $tmp_ (split '\&\&',$tmp_1) {
  469. $tmp_ =~ /!defined\(([^\)]+)\)/;
  470. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  471. push(@tag,$1);
  472. $tag{$1}=-1;
  473. }
  474. } else {
  475. print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
  476. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  477. push(@tag,$1);
  478. $tag{$1}=-1;
  479. }
  480. } elsif (/^\#\s*ifdef\s+(\S*)/) {
  481. push(@tag,"-");
  482. push(@tag,$1);
  483. $tag{$1}=1;
  484. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  485. } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
  486. push(@tag,"-");
  487. if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
  488. my $tmp_1 = $1;
  489. my $tmp_;
  490. foreach $tmp_ (split '\|\|',$tmp_1) {
  491. $tmp_ =~ /defined\(([^\)]+)\)/;
  492. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  493. push(@tag,$1);
  494. $tag{$1}=1;
  495. }
  496. } else {
  497. print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
  498. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  499. push(@tag,$1);
  500. $tag{$1}=1;
  501. }
  502. } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
  503. my $tag_i = $#tag;
  504. while($tag[$tag_i] ne "-") {
  505. if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
  506. $tag{$tag[$tag_i]}=2;
  507. print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
  508. }
  509. $tag_i--;
  510. }
  511. } elsif (/^\#\s*endif/) {
  512. my $tag_i = $#tag;
  513. while($tag_i > 0 && $tag[$tag_i] ne "-") {
  514. my $t=$tag[$tag_i];
  515. print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
  516. if ($tag{$t}==2) {
  517. $tag{$t}=-1;
  518. } else {
  519. $tag{$t}=0;
  520. }
  521. print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
  522. pop(@tag);
  523. if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
  524. $t=$1;
  525. } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
  526. $t=$1;
  527. } else {
  528. $t="";
  529. }
  530. if ($t ne ""
  531. && !grep(/^$t$/, @known_algorithms)) {
  532. $unknown_algorithms{$t} = 1;
  533. #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
  534. }
  535. $tag_i--;
  536. }
  537. pop(@tag);
  538. } elsif (/^\#\s*else/) {
  539. my $tag_i = $#tag;
  540. while($tag[$tag_i] ne "-") {
  541. my $t=$tag[$tag_i];
  542. $tag{$t}= -$tag{$t};
  543. print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
  544. $tag_i--;
  545. }
  546. } elsif (/^\#\s*if\s+1/) {
  547. push(@tag,"-");
  548. # Dummy tag
  549. push(@tag,"TRUE");
  550. $tag{"TRUE"}=1;
  551. print STDERR "DEBUG: $file: found 1\n" if $debug;
  552. } elsif (/^\#\s*if\s+0/) {
  553. push(@tag,"-");
  554. # Dummy tag
  555. push(@tag,"TRUE");
  556. $tag{"TRUE"}=-1;
  557. print STDERR "DEBUG: $file: found 0\n" if $debug;
  558. } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
  559. && $symhacking && $tag{'TRUE'} != -1) {
  560. # This is for aliasing. When we find an alias,
  561. # we have to invert
  562. &$make_variant($1,$2);
  563. print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
  564. }
  565. if (/^\#/) {
  566. @current_platforms =
  567. grep(!/^$/,
  568. map { $tag{$_} == 1 ? $_ :
  569. $tag{$_} == -1 ? "!".$_ : "" }
  570. @known_platforms);
  571. push @current_platforms
  572. , grep(!/^$/,
  573. map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
  574. $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
  575. @known_ossl_platforms);
  576. @current_algorithms = ();
  577. @current_algorithms =
  578. grep(!/^$/,
  579. map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
  580. @known_algorithms);
  581. push @current_algorithms
  582. , grep(!/^$/,
  583. map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
  584. @known_algorithms);
  585. $def .=
  586. "#INFO:"
  587. .join(',',@current_platforms).":"
  588. .join(',',@current_algorithms).";";
  589. next;
  590. }
  591. if ($tag{'TRUE'} != -1) {
  592. if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
  593. next;
  594. } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  595. $def .= "int d2i_$3(void);";
  596. $def .= "int i2d_$3(void);";
  597. # Variant for platforms that do not
  598. # have to access globale variables
  599. # in shared libraries through functions
  600. $def .=
  601. "#INFO:"
  602. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  603. .join(',',@current_algorithms).";";
  604. $def .= "OPENSSL_EXTERN int $2_it;";
  605. $def .=
  606. "#INFO:"
  607. .join(',',@current_platforms).":"
  608. .join(',',@current_algorithms).";";
  609. # Variant for platforms that have to
  610. # access globale variables in shared
  611. # libraries through functions
  612. &$make_variant("$2_it","$2_it",
  613. "EXPORT_VAR_AS_FUNCTION",
  614. "FUNCTION");
  615. next;
  616. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  617. $def .= "int d2i_$3(void);";
  618. $def .= "int i2d_$3(void);";
  619. $def .= "int $3_free(void);";
  620. $def .= "int $3_new(void);";
  621. # Variant for platforms that do not
  622. # have to access globale variables
  623. # in shared libraries through functions
  624. $def .=
  625. "#INFO:"
  626. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  627. .join(',',@current_algorithms).";";
  628. $def .= "OPENSSL_EXTERN int $2_it;";
  629. $def .=
  630. "#INFO:"
  631. .join(',',@current_platforms).":"
  632. .join(',',@current_algorithms).";";
  633. # Variant for platforms that have to
  634. # access globale variables in shared
  635. # libraries through functions
  636. &$make_variant("$2_it","$2_it",
  637. "EXPORT_VAR_AS_FUNCTION",
  638. "FUNCTION");
  639. next;
  640. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
  641. /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
  642. $def .= "int d2i_$1(void);";
  643. $def .= "int i2d_$1(void);";
  644. $def .= "int $1_free(void);";
  645. $def .= "int $1_new(void);";
  646. # Variant for platforms that do not
  647. # have to access globale variables
  648. # in shared libraries through functions
  649. $def .=
  650. "#INFO:"
  651. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  652. .join(',',@current_algorithms).";";
  653. $def .= "OPENSSL_EXTERN int $1_it;";
  654. $def .=
  655. "#INFO:"
  656. .join(',',@current_platforms).":"
  657. .join(',',@current_algorithms).";";
  658. # Variant for platforms that have to
  659. # access globale variables in shared
  660. # libraries through functions
  661. &$make_variant("$1_it","$1_it",
  662. "EXPORT_VAR_AS_FUNCTION",
  663. "FUNCTION");
  664. next;
  665. } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  666. $def .= "int d2i_$2(void);";
  667. $def .= "int i2d_$2(void);";
  668. # Variant for platforms that do not
  669. # have to access globale variables
  670. # in shared libraries through functions
  671. $def .=
  672. "#INFO:"
  673. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  674. .join(',',@current_algorithms).";";
  675. $def .= "OPENSSL_EXTERN int $2_it;";
  676. $def .=
  677. "#INFO:"
  678. .join(',',@current_platforms).":"
  679. .join(',',@current_algorithms).";";
  680. # Variant for platforms that have to
  681. # access globale variables in shared
  682. # libraries through functions
  683. &$make_variant("$2_it","$2_it",
  684. "EXPORT_VAR_AS_FUNCTION",
  685. "FUNCTION");
  686. next;
  687. } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
  688. $def .= "int $1_free(void);";
  689. $def .= "int $1_new(void);";
  690. next;
  691. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  692. $def .= "int d2i_$2(void);";
  693. $def .= "int i2d_$2(void);";
  694. $def .= "int $2_free(void);";
  695. $def .= "int $2_new(void);";
  696. # Variant for platforms that do not
  697. # have to access globale variables
  698. # in shared libraries through functions
  699. $def .=
  700. "#INFO:"
  701. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  702. .join(',',@current_algorithms).";";
  703. $def .= "OPENSSL_EXTERN int $2_it;";
  704. $def .=
  705. "#INFO:"
  706. .join(',',@current_platforms).":"
  707. .join(',',@current_algorithms).";";
  708. # Variant for platforms that have to
  709. # access globale variables in shared
  710. # libraries through functions
  711. &$make_variant("$2_it","$2_it",
  712. "EXPORT_VAR_AS_FUNCTION",
  713. "FUNCTION");
  714. next;
  715. } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
  716. # Variant for platforms that do not
  717. # have to access globale variables
  718. # in shared libraries through functions
  719. $def .=
  720. "#INFO:"
  721. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  722. .join(',',@current_algorithms).";";
  723. $def .= "OPENSSL_EXTERN int $1_it;";
  724. $def .=
  725. "#INFO:"
  726. .join(',',@current_platforms).":"
  727. .join(',',@current_algorithms).";";
  728. # Variant for platforms that have to
  729. # access globale variables in shared
  730. # libraries through functions
  731. &$make_variant("$1_it","$1_it",
  732. "EXPORT_VAR_AS_FUNCTION",
  733. "FUNCTION");
  734. next;
  735. } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
  736. $def .= "int i2d_$1_NDEF(void);";
  737. } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
  738. next;
  739. } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
  740. $def .= "int $1_print_ctx(void);";
  741. next;
  742. } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  743. $def .= "int $2_print_ctx(void);";
  744. next;
  745. } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
  746. next;
  747. } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
  748. /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
  749. /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
  750. $def .=
  751. "#INFO:"
  752. .join(',',@current_platforms).":"
  753. .join(',',@current_algorithms).";";
  754. $def .= "int PEM_read_$1(void);";
  755. $def .= "int PEM_write_$1(void);";
  756. $def .=
  757. "#INFO:"
  758. .join(',',@current_platforms).":"
  759. .join(',',@current_algorithms).";";
  760. # Things that are everywhere
  761. $def .= "int PEM_read_bio_$1(void);";
  762. $def .= "int PEM_write_bio_$1(void);";
  763. next;
  764. } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
  765. /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
  766. /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
  767. $def .=
  768. "#INFO:"
  769. .join(',',@current_platforms).":"
  770. .join(',',@current_algorithms).";";
  771. $def .= "int PEM_write_$1(void);";
  772. $def .=
  773. "#INFO:"
  774. .join(',',@current_platforms).":"
  775. .join(',',@current_algorithms).";";
  776. # Things that are everywhere
  777. $def .= "int PEM_write_bio_$1(void);";
  778. next;
  779. } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
  780. /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
  781. $def .=
  782. "#INFO:"
  783. .join(',',@current_platforms).":"
  784. .join(',',@current_algorithms).";";
  785. $def .= "int PEM_read_$1(void);";
  786. $def .=
  787. "#INFO:"
  788. .join(',',@current_platforms).":"
  789. .join(',',@current_algorithms).";";
  790. # Things that are everywhere
  791. $def .= "int PEM_read_bio_$1(void);";
  792. next;
  793. } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  794. # Variant for platforms that do not
  795. # have to access globale variables
  796. # in shared libraries through functions
  797. $def .=
  798. "#INFO:"
  799. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  800. .join(',',@current_algorithms).";";
  801. $def .= "OPENSSL_EXTERN int _shadow_$2;";
  802. $def .=
  803. "#INFO:"
  804. .join(',',@current_platforms).":"
  805. .join(',',@current_algorithms).";";
  806. # Variant for platforms that have to
  807. # access globale variables in shared
  808. # libraries through functions
  809. &$make_variant("_shadow_$2","_shadow_$2",
  810. "EXPORT_VAR_AS_FUNCTION",
  811. "FUNCTION");
  812. } elsif (/^\s*DEPRECATEDIN/) {
  813. $parens = count_parens($_);
  814. if ($parens == 0) {
  815. $def .= do_deprecated($_,
  816. \@current_platforms,
  817. \@current_algorithms);
  818. } else {
  819. $stored_multiline = $_;
  820. $stored_multiline =~ s|\R$||;
  821. print STDERR "DEBUG: Found multiline DEPRECATEDIN starting with: $stored_multiline\n" if $debug;
  822. next;
  823. }
  824. } elsif ($tag{'CONST_STRICT'} != 1) {
  825. if (/\{|\/\*|\([^\)]*$/) {
  826. $line = $_;
  827. } else {
  828. $def .= $_;
  829. }
  830. }
  831. }
  832. }
  833. close(IN);
  834. my $algs;
  835. my $plays;
  836. print STDERR "DEBUG: postprocessing ----------\n" if $debug;
  837. foreach (split /;/, $def) {
  838. my $s; my $k = "FUNCTION"; my $p; my $a;
  839. s/^[\n\s]*//g;
  840. s/[\n\s]*$//g;
  841. next if(/\#undef/);
  842. next if(/typedef\W/);
  843. next if(/\#define/);
  844. # Reduce argument lists to empty ()
  845. # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
  846. while(/\(.*\)/s) {
  847. s/\([^\(\)]+\)/\{\}/gs;
  848. s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
  849. }
  850. # pretend as we didn't use curly braces: {} -> ()
  851. s/\{\}/\(\)/gs;
  852. s/STACK_OF\(\)/void/gs;
  853. s/LHASH_OF\(\)/void/gs;
  854. print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
  855. if (/^\#INFO:([^:]*):(.*)$/) {
  856. $plats = $1;
  857. $algs = $2;
  858. print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
  859. next;
  860. } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
  861. $s = $1;
  862. $k = "VARIABLE";
  863. print STDERR "DEBUG: found external variable $s\n" if $debug;
  864. } elsif (/TYPEDEF_\w+_OF/s) {
  865. next;
  866. } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
  867. $s = $1; # a function name!
  868. print STDERR "DEBUG: found function $s\n" if $debug;
  869. } elsif (/\(/ and not (/=/)) {
  870. print STDERR "File $file: cannot parse: $_;\n";
  871. next;
  872. } else {
  873. next;
  874. }
  875. $syms{$s} = 1;
  876. $kind{$s} = $k;
  877. $p = $plats;
  878. $a = $algs;
  879. $platform{$s} =
  880. &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
  881. $algorithm{$s} .= ','.$a;
  882. if (defined($variant{$s})) {
  883. foreach $v (split /;/,$variant{$s}) {
  884. (my $r, my $p, my $k) = split(/:/,$v);
  885. my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
  886. $syms{$r} = 1;
  887. if (!defined($k)) { $k = $kind{$s}; }
  888. $kind{$r} = $k."(".$s.")";
  889. $algorithm{$r} = $algorithm{$s};
  890. $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
  891. $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
  892. print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
  893. }
  894. }
  895. print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
  896. }
  897. }
  898. # Prune the returned symbols
  899. delete $syms{"bn_dump1"};
  900. $platform{"BIO_s_log"} .= ",!WIN32,!macintosh";
  901. $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
  902. $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
  903. $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
  904. $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
  905. $platform{"EVP_sha384"} = "!VMSVAX";
  906. $platform{"EVP_sha512"} = "!VMSVAX";
  907. $platform{"SHA384_Init"} = "!VMSVAX";
  908. $platform{"SHA384_Transform"} = "!VMSVAX";
  909. $platform{"SHA384_Update"} = "!VMSVAX";
  910. $platform{"SHA384_Final"} = "!VMSVAX";
  911. $platform{"SHA384"} = "!VMSVAX";
  912. $platform{"SHA512_Init"} = "!VMSVAX";
  913. $platform{"SHA512_Transform"} = "!VMSVAX";
  914. $platform{"SHA512_Update"} = "!VMSVAX";
  915. $platform{"SHA512_Final"} = "!VMSVAX";
  916. $platform{"SHA512"} = "!VMSVAX";
  917. # Info we know about
  918. push @ret, map { $_."\\".&info_string($_,"EXIST",
  919. $platform{$_},
  920. $kind{$_},
  921. $algorithm{$_}) } keys %syms;
  922. if (keys %unknown_algorithms) {
  923. print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
  924. print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
  925. }
  926. return(@ret);
  927. }
  928. # Param: string of comma-separated platform-specs.
  929. sub reduce_platforms
  930. {
  931. my ($platforms) = @_;
  932. my $pl = defined($platforms) ? $platforms : "";
  933. my %p = map { $_ => 0 } split /,/, $pl;
  934. my $ret;
  935. print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
  936. if $debug;
  937. # We do this, because if there's code like the following, it really
  938. # means the function exists in all cases and should therefore be
  939. # everywhere. By increasing and decreasing, we may attain 0:
  940. #
  941. # ifndef WIN16
  942. # int foo();
  943. # else
  944. # int _fat foo();
  945. # endif
  946. foreach $platform (split /,/, $pl) {
  947. if ($platform =~ /^!(.*)$/) {
  948. $p{$1}--;
  949. } else {
  950. $p{$platform}++;
  951. }
  952. }
  953. foreach $platform (keys %p) {
  954. if ($p{$platform} == 0) { delete $p{$platform}; }
  955. }
  956. delete $p{""};
  957. $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
  958. print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
  959. if $debug;
  960. return $ret;
  961. }
  962. sub info_string
  963. {
  964. (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
  965. my %a = defined($algorithms) ?
  966. map { $_ => 1 } split /,/, $algorithms : ();
  967. my $k = defined($kind) ? $kind : "FUNCTION";
  968. my $ret;
  969. my $p = &reduce_platforms($platforms);
  970. delete $a{""};
  971. $ret = $exist;
  972. $ret .= ":".$p;
  973. $ret .= ":".$k;
  974. $ret .= ":".join(',',sort keys %a);
  975. return $ret;
  976. }
  977. sub maybe_add_info
  978. {
  979. (my $name, *nums, my @symbols) = @_;
  980. my $sym;
  981. my $new_info = 0;
  982. my %syms=();
  983. foreach $sym (@symbols) {
  984. (my $s, my $i) = split /\\/, $sym;
  985. if (defined($nums{$s})) {
  986. $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
  987. (my $n, my $vers, my $dummy) = split /\\/, $nums{$s};
  988. if (!defined($dummy) || $i ne $dummy) {
  989. $nums{$s} = $n."\\".$vers."\\".$i;
  990. $new_info++;
  991. print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
  992. }
  993. }
  994. $syms{$s} = 1;
  995. }
  996. my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
  997. foreach $sym (@s) {
  998. (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
  999. if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
  1000. $new_info++;
  1001. print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
  1002. }
  1003. }
  1004. if ($new_info) {
  1005. print STDERR "$name: $new_info old symbols have updated info\n";
  1006. if (!$do_rewrite) {
  1007. print STDERR "You should do a rewrite to fix this.\n";
  1008. }
  1009. } else {
  1010. }
  1011. }
  1012. # Param: string of comma-separated keywords, each possibly prefixed with a "!"
  1013. sub is_valid
  1014. {
  1015. my ($keywords_txt,$platforms) = @_;
  1016. my (@keywords) = split /,/,$keywords_txt;
  1017. my ($falsesum, $truesum) = (0, 1);
  1018. # Param: one keyword
  1019. sub recognise
  1020. {
  1021. my ($keyword,$platforms) = @_;
  1022. if ($platforms) {
  1023. # platforms
  1024. if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; }
  1025. if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; }
  1026. if ($keyword eq "VMS" && $VMS) { return 1; }
  1027. if ($keyword eq "WIN32" && $W32) { return 1; }
  1028. if ($keyword eq "WINNT" && $NT) { return 1; }
  1029. if ($keyword eq "OS2" && $OS2) { return 1; }
  1030. # Special platforms:
  1031. # EXPORT_VAR_AS_FUNCTION means that global variables
  1032. # will be represented as functions. This currently
  1033. # only happens on VMS-VAX.
  1034. if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32)) {
  1035. return 1;
  1036. }
  1037. if ($keyword eq "ZLIB" && $zlib) { return 1; }
  1038. return 0;
  1039. } else {
  1040. # algorithms
  1041. if ($disabled_algorithms{$keyword} == 1) { return 0;}
  1042. # Nothing recognise as true
  1043. return 1;
  1044. }
  1045. }
  1046. foreach $k (@keywords) {
  1047. if ($k =~ /^!(.*)$/) {
  1048. $falsesum += &recognise($1,$platforms);
  1049. } else {
  1050. $truesum *= &recognise($k,$platforms);
  1051. }
  1052. }
  1053. print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
  1054. return (!$falsesum) && $truesum;
  1055. }
  1056. sub print_test_file
  1057. {
  1058. (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
  1059. my $n = 1; my @e; my @r;
  1060. my $sym; my $prev = ""; my $prefSSLeay;
  1061. (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
  1062. (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
  1063. @symbols=((sort @e),(sort @r));
  1064. foreach $sym (@symbols) {
  1065. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1066. my $v = 0;
  1067. $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
  1068. my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
  1069. my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
  1070. if (!defined($nums{$s})) {
  1071. print STDERR "Warning: $s does not have a number assigned\n"
  1072. if(!$do_update);
  1073. } elsif (is_valid($p,1) && is_valid($a,0)) {
  1074. my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
  1075. if ($prev eq $s2) {
  1076. print OUT "\t/* The following has already appeared previously */\n";
  1077. print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
  1078. }
  1079. $prev = $s2; # To warn about duplicates...
  1080. (my $nn, my $vers, my $ni) = split /\\/, $nums{$s2};
  1081. if ($v) {
  1082. print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
  1083. } else {
  1084. print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
  1085. }
  1086. }
  1087. }
  1088. }
  1089. sub get_version
  1090. {
  1091. return $config{version};
  1092. }
  1093. sub print_def_file
  1094. {
  1095. (*OUT,my $name,*nums,my @symbols)=@_;
  1096. my $n = 1; my @e; my @r; my @v; my $prev="";
  1097. my $liboptions="";
  1098. my $libname = $name;
  1099. my $http_vendor = 'www.openssl.org/';
  1100. my $version = get_version();
  1101. my $what = "OpenSSL: implementation of Secure Socket Layer";
  1102. my $description = "$what $version, $name - http://$http_vendor";
  1103. my $prevsymversion = "", $prevprevsymversion = "";
  1104. # For VMS
  1105. my $prevnum = 0;
  1106. my $symvtextcount = 0;
  1107. if ($W32)
  1108. { $libname.="32"; }
  1109. elsif ($OS2)
  1110. { # DLL names should not clash on the whole system.
  1111. # However, they should not have any particular relationship
  1112. # to the name of the static library. Chose descriptive names
  1113. # (must be at most 8 chars).
  1114. my %translate = (ssl => 'open_ssl', crypto => 'cryptssl');
  1115. $libname = $translate{$name} || $name;
  1116. $liboptions = <<EOO;
  1117. INITINSTANCE
  1118. DATA MULTIPLE NONSHARED
  1119. EOO
  1120. # Vendor field can't contain colon, drat; so we omit http://
  1121. $description = "\@#$http_vendor:$version#\@$what; DLL for library $name. Build for EMX -Zmtd";
  1122. }
  1123. if ($W32 || $OS2)
  1124. {
  1125. print OUT <<"EOF";
  1126. ;
  1127. ; Definition file for the DLL version of the $name library from OpenSSL
  1128. ;
  1129. LIBRARY $libname $liboptions
  1130. EOF
  1131. print "EXPORTS\n";
  1132. }
  1133. elsif ($VMS)
  1134. {
  1135. print OUT <<"EOF";
  1136. CASE_SENSITIVE=YES
  1137. SYMBOL_VECTOR=(-
  1138. EOF
  1139. $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
  1140. }
  1141. (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
  1142. (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
  1143. if ($VMS) {
  1144. # VMS needs to have the symbols on slot number order
  1145. @symbols=(map { $_->[1] }
  1146. sort { $a->[0] <=> $b->[0] }
  1147. map { (my $s, my $i) = $_ =~ /^(.*?)\\(.*)$/;
  1148. die "Error: $s doesn't have a number assigned\n"
  1149. if !defined($nums{$s});
  1150. (my $n, my @rest) = split /\\/, $nums{$s};
  1151. [ $n, $_ ] } (@e, @r, @v));
  1152. } else {
  1153. @symbols=((sort @e),(sort @r), (sort @v));
  1154. }
  1155. my ($baseversion, $currversion) = get_openssl_version();
  1156. my $thisversion;
  1157. do {
  1158. if (!defined($thisversion)) {
  1159. $thisversion = $baseversion;
  1160. } else {
  1161. $thisversion = get_next_version($thisversion);
  1162. }
  1163. foreach $sym (@symbols) {
  1164. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1165. my $v = 0;
  1166. $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
  1167. if (!defined($nums{$s})) {
  1168. die "Error: $s does not have a number assigned\n"
  1169. if(!$do_update);
  1170. } else {
  1171. (my $n, my $symversion, my $dummy) = split /\\/, $nums{$s};
  1172. next if $symversion ne $thisversion;
  1173. my %pf = ();
  1174. my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
  1175. my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
  1176. if (is_valid($p,1) && is_valid($a,0)) {
  1177. my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
  1178. if ($prev eq $s2) {
  1179. print STDERR "Warning: Symbol '",$s2,
  1180. "' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),
  1181. ", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
  1182. }
  1183. $prev = $s2; # To warn about duplicates...
  1184. if($linux) {
  1185. if ($symversion ne $prevsymversion) {
  1186. if ($prevsymversion ne "") {
  1187. if ($prevprevsymversion ne "") {
  1188. print OUT "} OPENSSL_"
  1189. ."$prevprevsymversion;\n\n";
  1190. } else {
  1191. print OUT "};\n\n";
  1192. }
  1193. }
  1194. print OUT "OPENSSL_$symversion {\n global:\n";
  1195. $prevprevsymversion = $prevsymversion;
  1196. $prevsymversion = $symversion;
  1197. }
  1198. print OUT " $s2;\n";
  1199. } elsif ($VMS) {
  1200. while(++$prevnum < $n) {
  1201. my $symline=" ,SPARE -\n ,SPARE -\n";
  1202. if ($symvtextcount + length($symline) - 2 > 1024) {
  1203. print OUT ")\nSYMBOL_VECTOR=(-\n";
  1204. $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
  1205. }
  1206. if ($symvtextcount == 16) {
  1207. # Take away first comma
  1208. $symline =~ s/,//;
  1209. }
  1210. print OUT $symline;
  1211. $symvtextcount += length($symline) - 2;
  1212. }
  1213. (my $s_uc = $s) =~ tr/a-z/A-Z/;
  1214. my $symtype=
  1215. $v ? "DATA" : "PROCEDURE";
  1216. my $symline=
  1217. ($s_uc ne $s
  1218. ? " ,$s_uc/$s=$symtype -\n ,$s=$symtype -\n"
  1219. : " ,$s=$symtype -\n ,SPARE -\n");
  1220. if ($symvtextcount + length($symline) - 2 > 1024) {
  1221. print OUT ")\nSYMBOL_VECTOR=(-\n";
  1222. $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
  1223. }
  1224. if ($symvtextcount == 16) {
  1225. # Take away first comma
  1226. $symline =~ s/,//;
  1227. }
  1228. print OUT $symline;
  1229. $symvtextcount += length($symline) - 2;
  1230. } elsif($v && !$OS2) {
  1231. printf OUT " %s%-39s @%-8d DATA\n",
  1232. ($W32)?"":"_",$s2,$n;
  1233. } else {
  1234. printf OUT " %s%-39s @%d\n",
  1235. ($W32||$OS2)?"":"_",$s2,$n;
  1236. }
  1237. }
  1238. }
  1239. }
  1240. } while ($thisversion ne $currversion);
  1241. if ($linux) {
  1242. if ($prevprevsymversion ne "") {
  1243. print OUT " local: *;\n} OPENSSL_$prevprevsymversion;\n\n";
  1244. } else {
  1245. print OUT " local: *;\n};\n\n";
  1246. }
  1247. } elsif ($VMS) {
  1248. print OUT ")\n";
  1249. (my $libvmaj, my $libvmin, my $libvedit) =
  1250. $currversion =~ /^(\d+)_(\d+)_(\d+)$/;
  1251. # The reason to multiply the edit number with 100 is to make space
  1252. # for the possibility that we want to encode the patch letters
  1253. print OUT "GSMATCH=LEQUAL,",($libvmaj * 100 + $libvmin),",",($libvedit * 100),"\n";
  1254. }
  1255. printf OUT "\n";
  1256. }
  1257. sub load_numbers
  1258. {
  1259. my($name)=@_;
  1260. my(@a,%ret);
  1261. my $prevversion;
  1262. $max_num = 0;
  1263. $num_noinfo = 0;
  1264. $prev = "";
  1265. $prev_cnt = 0;
  1266. my ($baseversion, $currversion) = get_openssl_version();
  1267. open(IN,"<$name") || die "unable to open $name:$!\n";
  1268. while (<IN>) {
  1269. s|\R$||; # Better chomp
  1270. s/#.*$//;
  1271. next if /^\s*$/;
  1272. @a=split;
  1273. if (defined $ret{$a[0]}) {
  1274. # This is actually perfectly OK
  1275. #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
  1276. }
  1277. if ($max_num > $a[1]) {
  1278. print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
  1279. }
  1280. elsif ($max_num == $a[1]) {
  1281. # This is actually perfectly OK
  1282. #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
  1283. if ($a[0] eq $prev) {
  1284. $prev_cnt++;
  1285. $a[0] .= "{$prev_cnt}";
  1286. }
  1287. }
  1288. else {
  1289. $prev_cnt = 0;
  1290. }
  1291. if ($#a < 2) {
  1292. # Existence will be proven later, in do_defs
  1293. $ret{$a[0]}=$a[1];
  1294. $num_noinfo++;
  1295. } else {
  1296. #Sanity check the version number
  1297. if (defined $prevversion) {
  1298. check_version_lte($prevversion, $a[2]);
  1299. }
  1300. check_version_lte($a[2], $currversion);
  1301. $prevversion = $a[2];
  1302. $ret{$a[0]}=$a[1]."\\".$a[2]."\\".$a[3]; # \\ is a special marker
  1303. }
  1304. $max_num = $a[1] if $a[1] > $max_num;
  1305. $prev=$a[0];
  1306. }
  1307. if ($num_noinfo) {
  1308. print STDERR "Warning: $num_noinfo symbols were without info.";
  1309. if ($do_rewrite) {
  1310. printf STDERR " The rewrite will fix this.\n";
  1311. } else {
  1312. printf STDERR " You should do a rewrite to fix this.\n";
  1313. }
  1314. }
  1315. close(IN);
  1316. return(%ret);
  1317. }
  1318. sub parse_number
  1319. {
  1320. (my $str, my $what) = @_;
  1321. (my $n, my $v, my $i) = split(/\\/,$str);
  1322. if ($what eq "n") {
  1323. return $n;
  1324. } else {
  1325. return $i;
  1326. }
  1327. }
  1328. sub rewrite_numbers
  1329. {
  1330. (*OUT,$name,*nums,@symbols)=@_;
  1331. my $thing;
  1332. my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
  1333. my $r; my %r; my %rsyms;
  1334. foreach $r (@r) {
  1335. (my $s, my $i) = split /\\/, $r;
  1336. my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
  1337. $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
  1338. $r{$a} = $s."\\".$i;
  1339. $rsyms{$s} = 1;
  1340. }
  1341. my %syms = ();
  1342. foreach $_ (@symbols) {
  1343. (my $n, my $i) = split /\\/;
  1344. $syms{$n} = 1;
  1345. }
  1346. my @s=sort {
  1347. &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
  1348. || $a cmp $b
  1349. } keys %nums;
  1350. foreach $sym (@s) {
  1351. (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
  1352. next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
  1353. next if defined($rsyms{$sym});
  1354. print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
  1355. $i="NOEXIST::FUNCTION:"
  1356. if !defined($i) || $i eq "" || !defined($syms{$sym});
  1357. my $s2 = $sym;
  1358. $s2 =~ s/\{[0-9]+\}$//;
  1359. printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
  1360. if (exists $r{$sym}) {
  1361. (my $s, $i) = split /\\/,$r{$sym};
  1362. my $s2 = $s;
  1363. $s2 =~ s/\{[0-9]+\}$//;
  1364. printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
  1365. }
  1366. }
  1367. }
  1368. sub update_numbers
  1369. {
  1370. (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
  1371. my $new_syms = 0;
  1372. my $basevers;
  1373. my $vers;
  1374. ($basevers, $vers) = get_openssl_version();
  1375. my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
  1376. my $r; my %r; my %rsyms;
  1377. foreach $r (@r) {
  1378. (my $s, my $i) = split /\\/, $r;
  1379. my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
  1380. $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
  1381. $r{$a} = $s."\\".$i;
  1382. $rsyms{$s} = 1;
  1383. }
  1384. foreach $sym (@symbols) {
  1385. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1386. next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
  1387. next if defined($rsyms{$sym});
  1388. die "ERROR: Symbol $sym had no info attached to it."
  1389. if $i eq "";
  1390. if (!exists $nums{$s}) {
  1391. $new_syms++;
  1392. my $s2 = $s;
  1393. $s2 =~ s/\{[0-9]+\}$//;
  1394. printf OUT "%s%-39s %d\t%s\t%s\n","",$s2, ++$start_num,$vers,$i;
  1395. if (exists $r{$s}) {
  1396. ($s, $i) = split /\\/,$r{$s};
  1397. $s =~ s/\{[0-9]+\}$//;
  1398. printf OUT "%s%-39s %d\t%s\t%s\n","",$s, $start_num,$vers,$i;
  1399. }
  1400. }
  1401. }
  1402. if($new_syms) {
  1403. print STDERR "$name: Added $new_syms new symbols\n";
  1404. } else {
  1405. print STDERR "$name: No new symbols added\n";
  1406. }
  1407. }
  1408. sub check_existing
  1409. {
  1410. (*nums, my @symbols)=@_;
  1411. my %existing; my @remaining;
  1412. @remaining=();
  1413. foreach $sym (@symbols) {
  1414. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1415. $existing{$s}=1;
  1416. }
  1417. foreach $sym (keys %nums) {
  1418. if (!exists $existing{$sym}) {
  1419. push @remaining, $sym;
  1420. }
  1421. }
  1422. if(@remaining) {
  1423. print STDERR "The following symbols do not seem to exist:\n";
  1424. foreach $sym (@remaining) {
  1425. print STDERR "\t",$sym,"\n";
  1426. }
  1427. }
  1428. }
  1429. sub count_parens
  1430. {
  1431. my $line = shift(@_);
  1432. my $open = $line =~ tr/\(//;
  1433. my $close = $line =~ tr/\)//;
  1434. return $open - $close;
  1435. }
  1436. #Parse opensslv.h to get the current version number. Also work out the base
  1437. #version, i.e. the lowest version number that is binary compatible with this
  1438. #version
  1439. sub get_openssl_version()
  1440. {
  1441. my $fn = catfile($config{sourcedir},"include","openssl","opensslv.h");
  1442. open (IN, "$fn") || die "Can't open opensslv.h";
  1443. while(<IN>) {
  1444. if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
  1445. my $suffix = $2;
  1446. (my $baseversion = $1) =~ s/\./_/g;
  1447. close IN;
  1448. return ($baseversion."0", $baseversion.$suffix);
  1449. }
  1450. }
  1451. die "Can't find OpenSSL version number\n";
  1452. }
  1453. #Given an OpenSSL version number, calculate the next version number. If the
  1454. #version number gets to a.b.czz then we go to a.b.(c+1)
  1455. sub get_next_version()
  1456. {
  1457. my $thisversion = shift;
  1458. my ($base, $letter) = $thisversion =~ /^(\d_\d_\d)([a-z]{0,2})$/;
  1459. if ($letter eq "zz") {
  1460. my $lastnum = substr($base, -1);
  1461. return substr($base, 0, length($base)-1).(++$lastnum);
  1462. }
  1463. return $base.get_next_letter($letter);
  1464. }
  1465. #Given the letters off the end of an OpenSSL version string, calculate what
  1466. #the letters for the next release would be.
  1467. sub get_next_letter()
  1468. {
  1469. my $thisletter = shift;
  1470. my $baseletter = "";
  1471. my $endletter;
  1472. if ($thisletter eq "") {
  1473. return "a";
  1474. }
  1475. if ((length $thisletter) > 1) {
  1476. ($baseletter, $endletter) = $thisletter =~ /([a-z]+)([a-z])/;
  1477. } else {
  1478. $endletter = $thisletter;
  1479. }
  1480. if ($endletter eq "z") {
  1481. return $thisletter."a";
  1482. } else {
  1483. return $baseletter.(++$endletter);
  1484. }
  1485. }
  1486. #Check if a version is less than or equal to the current version. Its a fatal
  1487. #error if not. They must also only differ in letters, or the last number (i.e.
  1488. #the first two numbers must be the same)
  1489. sub check_version_lte()
  1490. {
  1491. my ($testversion, $currversion) = @_;
  1492. my $lentv;
  1493. my $lencv;
  1494. my $cvbase;
  1495. my ($cvnums) = $currversion =~ /^(\d_\d_\d)[a-z]*$/;
  1496. my ($tvnums) = $testversion =~ /^(\d_\d_\d)[a-z]*$/;
  1497. #Die if we can't parse the version numbers or they don't look sane
  1498. die "Invalid version number: $testversion and $currversion\n"
  1499. if (!defined($cvnums) || !defined($tvnums)
  1500. || length($cvnums) != 5
  1501. || length($tvnums) != 5);
  1502. #If the base versions (without letters) don't match check they only differ
  1503. #in the last number
  1504. if ($cvnums ne $tvnums) {
  1505. die "Invalid version number: $testversion "
  1506. ."for current version $currversion\n"
  1507. if (substr($cvnums, -1) < substr($tvnums, -1)
  1508. || substr($cvnums, 0, 4) ne substr($tvnums, 0, 4));
  1509. return;
  1510. }
  1511. #If we get here then the base version (i.e. the numbers) are the same - they
  1512. #only differ in the letters
  1513. $lentv = length $testversion;
  1514. $lencv = length $currversion;
  1515. #If the testversion has more letters than the current version then it must
  1516. #be later (or malformed)
  1517. if ($lentv > $lencv) {
  1518. die "Invalid version number: $testversion "
  1519. ."is greater than $currversion\n";
  1520. }
  1521. #Get the last letter from the current version
  1522. my ($cvletter) = $currversion =~ /([a-z])$/;
  1523. if (defined $cvletter) {
  1524. ($cvbase) = $currversion =~ /(\d_\d_\d[a-z]*)$cvletter$/;
  1525. } else {
  1526. $cvbase = $currversion;
  1527. }
  1528. die "Unable to parse version number $currversion" if (!defined $cvbase);
  1529. my $tvbase;
  1530. my ($tvletter) = $testversion =~ /([a-z])$/;
  1531. if (defined $tvletter) {
  1532. ($tvbase) = $testversion =~ /(\d_\d_\d[a-z]*)$tvletter$/;
  1533. } else {
  1534. $tvbase = $testversion;
  1535. }
  1536. die "Unable to parse version number $testversion" if (!defined $tvbase);
  1537. if ($lencv > $lentv) {
  1538. #If current version has more letters than testversion then testversion
  1539. #minus the final letter must be a substring of the current version
  1540. die "Invalid version number $testversion "
  1541. ."is greater than $currversion or is invalid\n"
  1542. if (index($cvbase, $tvbase) != 0);
  1543. } else {
  1544. #If both versions have the same number of letters then they must be
  1545. #equal up to the last letter, and the last letter in testversion must
  1546. #be less than or equal to the last letter in current version.
  1547. die "Invalid version number $testversion "
  1548. ."is greater than $currversion\n"
  1549. if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));
  1550. }
  1551. }
  1552. sub do_deprecated()
  1553. {
  1554. my ($decl, $plats, $algs) = @_;
  1555. $decl =~ /^\s*(DEPRECATEDIN_\d+_\d+_\d+)\s*\((.*)\)\s*$/
  1556. or die "Bad DEPRECTEDIN: $decl\n";
  1557. my $info1 .= "#INFO:";
  1558. $info1 .= join(',', @{$plats}) . ":";
  1559. my $info2 = $info1;
  1560. $info1 .= join(',',@{$algs}, $1) . ";";
  1561. $info2 .= join(',',@{$algs}) . ";";
  1562. return $info1 . $2 . ";" . $info2;
  1563. }