1 #!/usr/local/bin/perl -w
5 # It does this by parsing the header files and looking for the
6 # prototyped functions: it then prunes the output.
9 $crypto_num="util/libeay.num";
10 $ssl_num= "util/ssleay.num";
19 # Set this to make typesafe STACK definitions appear in DEF
23 open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n";
25 $options=$1 if (/^OPTIONS=(.*)$/);
29 foreach (@ARGV, split(/ /, $options))
37 $do_ssl=1 if $_ eq "ssleay";
38 $do_ssl=1 if $_ eq "ssl";
39 $do_crypto=1 if $_ eq "libeay";
40 $do_crypto=1 if $_ eq "crypto";
41 $do_update=1 if $_ eq "update";
42 $do_ctest=1 if $_ eq "ctest";
43 $rsaref=1 if $_ eq "rsaref";
45 if (/^no-rc2$/) { $no_rc2=1; }
46 elsif (/^no-rc4$/) { $no_rc4=1; }
47 elsif (/^no-rc5$/) { $no_rc5=1; }
48 elsif (/^no-idea$/) { $no_idea=1; }
49 elsif (/^no-des$/) { $no_des=1; }
50 elsif (/^no-bf$/) { $no_bf=1; }
51 elsif (/^no-cast$/) { $no_cast=1; }
52 elsif (/^no-md2$/) { $no_md2=1; }
53 elsif (/^no-md5$/) { $no_md5=1; }
54 elsif (/^no-sha$/) { $no_sha=1; }
55 elsif (/^no-ripemd$/) { $no_ripemd=1; }
56 elsif (/^no-mdc2$/) { $no_mdc2=1; }
57 elsif (/^no-rsa$/) { $no_rsa=1; }
58 elsif (/^no-dsa$/) { $no_dsa=1; }
59 elsif (/^no-dh$/) { $no_dh=1; }
60 elsif (/^no-hmac$/) { $no_hmac=1; }
64 if (!$do_ssl && !$do_crypto)
66 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ] [rsaref]\n";
70 %ssl_list=&load_numbers($ssl_num);
72 %crypto_list=&load_numbers($crypto_num);
73 $max_crypto = $max_num;
77 $crypto ="crypto/crypto.h";
78 $crypto.=" crypto/des/des.h" unless $no_des;
79 $crypto.=" crypto/idea/idea.h" unless $no_idea;
80 $crypto.=" crypto/rc4/rc4.h" unless $no_rc4;
81 $crypto.=" crypto/rc5/rc5.h" unless $no_rc5;
82 $crypto.=" crypto/rc2/rc2.h" unless $no_rc2;
83 $crypto.=" crypto/bf/blowfish.h" unless $no_bf;
84 $crypto.=" crypto/cast/cast.h" unless $no_cast;
85 $crypto.=" crypto/md2/md2.h" unless $no_md2;
86 $crypto.=" crypto/md5/md5.h" unless $no_md5;
87 $crypto.=" crypto/mdc2/mdc2.h" unless $no_mdc2;
88 $crypto.=" crypto/sha/sha.h" unless $no_sha;
89 $crypto.=" crypto/ripemd/ripemd.h" unless $no_ripemd;
91 $crypto.=" crypto/bn/bn.h";
92 $crypto.=" crypto/rsa/rsa.h" unless $no_rsa;
93 $crypto.=" crypto/dsa/dsa.h" unless $no_dsa;
94 $crypto.=" crypto/dh/dh.h" unless $no_dh;
95 $crypto.=" crypto/hmac/hmac.h" unless $no_hmac;
97 $crypto.=" crypto/stack/stack.h";
98 $crypto.=" crypto/buffer/buffer.h";
99 $crypto.=" crypto/bio/bio.h";
100 $crypto.=" crypto/lhash/lhash.h";
101 $crypto.=" crypto/conf/conf.h";
102 $crypto.=" crypto/txt_db/txt_db.h";
104 $crypto.=" crypto/evp/evp.h";
105 $crypto.=" crypto/objects/objects.h";
106 $crypto.=" crypto/pem/pem.h";
107 #$crypto.=" crypto/meth/meth.h";
108 $crypto.=" crypto/asn1/asn1.h";
109 $crypto.=" crypto/asn1/asn1_mac.h";
110 $crypto.=" crypto/err/err.h";
111 $crypto.=" crypto/pkcs7/pkcs7.h";
112 $crypto.=" crypto/pkcs12/pkcs12.h";
113 $crypto.=" crypto/x509/x509.h";
114 $crypto.=" crypto/x509/x509_vfy.h";
115 $crypto.=" crypto/x509v3/x509v3.h";
116 $crypto.=" crypto/rand/rand.h";
117 $crypto.=" crypto/comp/comp.h";
118 $crypto.=" crypto/tmdiff.h";
120 @ssl_func = &do_defs("SSLEAY", $ssl);
121 @crypto_func = &do_defs("LIBEAY", $crypto);
127 open(OUT, ">>$ssl_num");
128 &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl, @ssl_func);
132 if($do_crypto == 1) {
133 open(OUT, ">>$crypto_num");
134 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto, @crypto_func);
138 } elsif ($do_ctest) {
142 /* Test file to check all DEF file symbols are present by trying
143 * to link to all of them. This is *not* intended to be run!
149 &print_test_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_func)
152 &print_test_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_func)
159 &print_def_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_func)
162 &print_def_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_func)
174 foreach $file (split(/\s+/,$files))
176 open(IN,"<$file") || die "unable to open $file:$!\n";
178 my $line = "", $def= "";
190 last if (/BEGIN ERROR CODES/);
201 $cpp = 1 if /^#.*ifdef.*cplusplus/;
203 $cpp = 0 if /^#.*endif/;
207 s/\/\*.*?\*\///gs; # ignore comments
208 s/{[^{}]*}//gs; # ignore {} blocks
209 if (/^\#\s*ifndef (.*)/) {
213 } elsif (/^\#\s*if !defined\(([^\)]+)\)/) {
217 } elsif (/^\#\s*ifdef (.*)/) {
221 } elsif (/^\#\s*if defined(.*)/) {
225 } elsif (/^\#\s*endif/) {
229 } elsif (/^\#\s*else/) {
233 } elsif (/^\#\s*if\s+1/) {
238 } elsif (/^\#\s*if\s+0/) {
246 if ($safe_stack_def &&
247 /^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
248 $funcs{"sk_${1}_new"} = 1;
249 $funcs{"sk_${1}_new_null"} = 1;
250 $funcs{"sk_${1}_free"} = 1;
251 $funcs{"sk_${1}_num"} = 1;
252 $funcs{"sk_${1}_value"} = 1;
253 $funcs{"sk_${1}_set"} = 1;
254 $funcs{"sk_${1}_zero"} = 1;
255 $funcs{"sk_${1}_push"} = 1;
256 $funcs{"sk_${1}_unshift"} = 1;
257 $funcs{"sk_${1}_find"} = 1;
258 $funcs{"sk_${1}_delete"} = 1;
259 $funcs{"sk_${1}_delete_ptr"} = 1;
260 $funcs{"sk_${1}_insert"} = 1;
261 $funcs{"sk_${1}_set_cmp_func"} = 1;
262 $funcs{"sk_${1}_dup"} = 1;
263 $funcs{"sk_${1}_pop_free"} = 1;
264 $funcs{"sk_${1}_shift"} = 1;
265 $funcs{"sk_${1}_pop"} = 1;
266 $funcs{"sk_${1}_sort"} = 1;
267 } elsif ($safe_stack_def &&
268 /^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
269 $funcs{"d2i_ASN1_SET_OF_${1}"} = 1;
270 $funcs{"i2d_ASN1_SET_OF_${1}"} = 1;
271 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
272 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) {
274 $funcs{"PEM_read_${1}"} = 1;
275 $funcs{"PEM_write_${1}"} = 1;
277 $funcs{"PEM_read_bio_${1}"} = 1;
278 $funcs{"PEM_write_bio_${1}"} = 1;
280 ($tag{'TRUE'} != -1) &&
281 ($tag{'FreeBSD'} != 1) &&
282 ($tag{'CONST_STRICT'} != 1) &&
283 (($W32 && ($tag{'WIN16'} != 1)) ||
284 (!$W32 && ($tag{'WIN16'} != -1))) &&
285 ($tag{'PERL5'} != 1) &&
286 # ($tag{'_WINDLL'} != -1) &&
287 ((!$W32 && $tag{'_WINDLL'} != -1) ||
288 ($W32 && $tag{'_WINDLL'} != 1)) &&
289 ((($tag{'NO_FP_API'} != 1) && $W32) ||
290 (($tag{'NO_FP_API'} != -1) && !$W32)))
301 foreach (split /;/, $def) {
304 next if(/typedef\W/);
305 next if(/EVP_bf/ and $no_bf);
306 next if(/EVP_cast/ and $no_cast);
307 next if(/EVP_des/ and $no_des);
308 next if(/EVP_dss/ and $no_dsa);
309 next if(/EVP_idea/ and $no_idea);
310 next if(/EVP_md2/ and $no_md2);
311 next if(/EVP_md5/ and $no_md5);
312 next if(/EVP_rc2/ and $no_rc2);
313 next if(/EVP_rc4/ and $no_rc4);
314 next if(/EVP_rc5/ and $no_rc5);
315 next if(/EVP_ripemd/ and $no_ripemd);
316 next if(/EVP_sha/ and $no_sha);
317 if (/\(\*(\w*)\([^\)]+/) {
319 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) {
322 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
323 while (not /\(\)$/s) {
325 s/\([^\(\)]*\)\)$/\)/s;
330 } elsif (/\(/ and not (/=/)) {
331 print STDERR "File $file: cannot parse: $_;\n";
336 # Prune the returned functions
338 delete $funcs{"SSL_add_dir_cert_subjects_to_stack"};
339 delete $funcs{"des_crypt"};
340 delete $funcs{"RSA_PKCS1_RSAref"} unless $rsaref;
343 delete $funcs{"BIO_s_file_internal"};
344 delete $funcs{"BIO_new_file_internal"};
345 delete $funcs{"BIO_new_fp_internal"};
347 if(exists $funcs{"ERR_load_CRYPTO_strings"}) {
348 delete $funcs{"ERR_load_CRYPTO_strings"};
349 $funcs{"ERR_load_CRYPTOlib_strings"} = 1;
351 delete $funcs{"BIO_s_file"};
352 delete $funcs{"BIO_new_file"};
353 delete $funcs{"BIO_new_fp"};
356 delete $funcs{"BIO_s_log"};
359 push @ret, keys %funcs;
366 (*OUT,my $name,*nums,@functions)=@_;
369 (@e)=grep(/^SSLeay/,@functions);
370 (@r)=grep(!/^SSLeay/,@functions);
371 @functions=((sort @e),(sort @r));
373 foreach $func (@functions) {
374 if (!defined($nums{$func})) {
375 printf STDERR "$func does not have a number assigned\n"
379 print OUT "\t$func();\n";
386 (*OUT,my $name,*nums,@functions)=@_;
396 ; Definition file for the DLL version of the $name library from OpenSSL
401 DESCRIPTION 'OpenSSL $name - http://www.openssl.org/'
407 CODE PRELOAD MOVEABLE
408 DATA PRELOAD MOVEABLE SINGLE
421 (@e)=grep(/^SSLeay/,@functions);
422 (@r)=grep(!/^SSLeay/,@functions);
423 @functions=((sort @e),(sort @r));
425 foreach $func (@functions) {
426 if (!defined($nums{$func})) {
427 printf STDERR "$func does not have a number assigned\n"
431 printf OUT " %s%-40s@%d\n",($W32)?"":"_",$func,$n;
444 open(IN,"<$name") || die "unable to open $name:$!\n";
451 $max_num = $a[1] if $a[1] > $max_num;
459 (*OUT,$name,*nums,my $start_num, my @functions)=@_;
461 print STDERR "Updating $name\n";
462 foreach $func (@functions) {
463 if (!exists $nums{$func}) {
465 printf OUT "%s%-40s%d\n","",$func, ++$start_num;
469 print STDERR "$new_funcs New Functions added\n";
471 print STDERR "No New Functions Added\n";