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 $rsaref=1 if $_ eq "rsaref";
44 if (/^no-rc2$/) { $no_rc2=1; }
45 elsif (/^no-rc4$/) { $no_rc4=1; }
46 elsif (/^no-rc5$/) { $no_rc5=1; }
47 elsif (/^no-idea$/) { $no_idea=1; }
48 elsif (/^no-des$/) { $no_des=1; }
49 elsif (/^no-bf$/) { $no_bf=1; }
50 elsif (/^no-cast$/) { $no_cast=1; }
51 elsif (/^no-md2$/) { $no_md2=1; }
52 elsif (/^no-md5$/) { $no_md5=1; }
53 elsif (/^no-sha$/) { $no_sha=1; }
54 elsif (/^no-ripemd$/) { $no_ripemd=1; }
55 elsif (/^no-mdc2$/) { $no_mdc2=1; }
56 elsif (/^no-rsa$/) { $no_rsa=1; }
57 elsif (/^no-dsa$/) { $no_dsa=1; }
58 elsif (/^no-dh$/) { $no_dh=1; }
59 elsif (/^no-hmac$/) { $no_hmac=1; }
62 if (!$do_ssl && !$do_crypto)
64 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ] [rsaref]\n";
68 %ssl_list=&load_numbers($ssl_num);
70 %crypto_list=&load_numbers($crypto_num);
71 $max_crypto = $max_num;
75 $crypto ="crypto/crypto.h";
76 $crypto.=" crypto/des/des.h" unless $no_des;
77 $crypto.=" crypto/idea/idea.h" unless $no_idea;
78 $crypto.=" crypto/rc4/rc4.h" unless $no_rc4;
79 $crypto.=" crypto/rc5/rc5.h" unless $no_rc5;
80 $crypto.=" crypto/rc2/rc2.h" unless $no_rc2;
81 $crypto.=" crypto/bf/blowfish.h" unless $no_bf;
82 $crypto.=" crypto/cast/cast.h" unless $no_cast;
83 $crypto.=" crypto/md2/md2.h" unless $no_md2;
84 $crypto.=" crypto/md5/md5.h" unless $no_md5;
85 $crypto.=" crypto/mdc2/mdc2.h" unless $no_mdc2;
86 $crypto.=" crypto/sha/sha.h" unless $no_sha;
87 $crypto.=" crypto/ripemd/ripemd.h" unless $no_ripemd;
89 $crypto.=" crypto/bn/bn.h";
90 $crypto.=" crypto/rsa/rsa.h" unless $no_rsa;
91 $crypto.=" crypto/dsa/dsa.h" unless $no_dsa;
92 $crypto.=" crypto/dh/dh.h" unless $no_dh;
93 $crypto.=" crypto/hmac/hmac.h" unless $no_hmac;
95 $crypto.=" crypto/stack/stack.h";
96 $crypto.=" crypto/buffer/buffer.h";
97 $crypto.=" crypto/bio/bio.h";
98 $crypto.=" crypto/lhash/lhash.h";
99 $crypto.=" crypto/conf/conf.h";
100 $crypto.=" crypto/txt_db/txt_db.h";
102 $crypto.=" crypto/evp/evp.h";
103 $crypto.=" crypto/objects/objects.h";
104 $crypto.=" crypto/pem/pem.h";
105 #$crypto.=" crypto/meth/meth.h";
106 $crypto.=" crypto/asn1/asn1.h";
107 $crypto.=" crypto/asn1/asn1_mac.h";
108 $crypto.=" crypto/err/err.h";
109 $crypto.=" crypto/pkcs7/pkcs7.h";
110 $crypto.=" crypto/pkcs12/pkcs12.h";
111 $crypto.=" crypto/x509/x509.h";
112 $crypto.=" crypto/x509/x509_vfy.h";
113 $crypto.=" crypto/x509v3/x509v3.h";
114 $crypto.=" crypto/rand/rand.h";
115 $crypto.=" crypto/comp/comp.h";
116 $crypto.=" crypto/tmdiff.h";
118 @ssl_func = &do_defs("SSLEAY", $ssl);
119 @crypto_func = &do_defs("LIBEAY", $crypto);
125 open(OUT, ">>$ssl_num");
126 &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl, @ssl_func);
130 if($do_crypto == 1) {
131 open(OUT, ">>$crypto_num");
132 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto, @crypto_func);
138 &print_def_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_func)
141 &print_def_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_func)
153 foreach $file (split(/\s+/,$files))
155 open(IN,"<$file") || die "unable to open $file:$!\n";
157 my $line = "", $def= "";
169 last if (/BEGIN ERROR CODES/);
180 $cpp = 1 if /^#.*ifdef.*cplusplus/;
182 $cpp = 0 if /^#.*endif/;
186 s/\/\*.*?\*\///gs; # ignore comments
187 s/{[^{}]*}//gs; # ignore {} blocks
188 if (/^\#\s*ifndef (.*)/) {
192 } elsif (/^\#\s*if !defined\(([^\)]+)\)/) {
196 } elsif (/^\#\s*ifdef (.*)/) {
200 } elsif (/^\#\s*if defined(.*)/) {
204 } elsif (/^\#\s*endif/) {
208 } elsif (/^\#\s*else/) {
212 } elsif (/^\#\s*if\s+1/) {
220 if ($safe_stack_def &&
221 /^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
222 $funcs{"sk_${1}_new"} = 1;
223 $funcs{"sk_${1}_new_null"} = 1;
224 $funcs{"sk_${1}_free"} = 1;
225 $funcs{"sk_${1}_num"} = 1;
226 $funcs{"sk_${1}_value"} = 1;
227 $funcs{"sk_${1}_set"} = 1;
228 $funcs{"sk_${1}_zero"} = 1;
229 $funcs{"sk_${1}_push"} = 1;
230 $funcs{"sk_${1}_unshift"} = 1;
231 $funcs{"sk_${1}_find"} = 1;
232 $funcs{"sk_${1}_delete"} = 1;
233 $funcs{"sk_${1}_delete_ptr"} = 1;
234 $funcs{"sk_${1}_insert"} = 1;
235 $funcs{"sk_${1}_set_cmp_func"} = 1;
236 $funcs{"sk_${1}_dup"} = 1;
237 $funcs{"sk_${1}_pop_free"} = 1;
238 $funcs{"sk_${1}_shift"} = 1;
239 $funcs{"sk_${1}_pop"} = 1;
240 } elsif ($safe_stack_def &&
241 /^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
242 $funcs{"d2i_ASN1_SET_OF_${1}"} = 1;
243 $funcs{"i2d_ASN1_SET_OF_${1}"} = 1;
245 ($tag{'FreeBSD'} != 1) &&
246 ($tag{'CONST_STRICT'} != 1) &&
247 (($W32 && ($tag{'WIN16'} != 1)) ||
248 (!$W32 && ($tag{'WIN16'} != -1))) &&
249 ($tag{'PERL5'} != 1) &&
250 # ($tag{'_WINDLL'} != -1) &&
251 ((!$W32 && $tag{'_WINDLL'} != -1) ||
252 ($W32 && $tag{'_WINDLL'} != 1)) &&
253 ((($tag{'NO_FP_API'} != 1) && $W32) ||
254 (($tag{'NO_FP_API'} != -1) && !$W32)))
265 foreach (split /;/, $def) {
268 next if(/typedef\W/);
269 next if(/EVP_bf/ and $no_bf);
270 next if(/EVP_cast/ and $no_cast);
271 next if(/EVP_des/ and $no_des);
272 next if(/EVP_dss/ and $no_dsa);
273 next if(/EVP_idea/ and $no_idea);
274 next if(/EVP_md2/ and $no_md2);
275 next if(/EVP_md5/ and $no_md5);
276 next if(/EVP_rc2/ and $no_rc2);
277 next if(/EVP_rc4/ and $no_rc4);
278 next if(/EVP_rc5/ and $no_rc5);
279 next if(/EVP_ripemd/ and $no_ripemd);
280 next if(/EVP_sha/ and $no_sha);
281 if (/\(\*(\w*)\([^\)]+/) {
283 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) {
286 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
287 while (not /\(\)$/s) {
289 s/\([^\(\)]*\)\)$/\)/s;
294 } elsif (/\(/ and not (/=/)) {
295 print STDERR "File $file: cannot parse: $_;\n";
300 # Prune the returned functions
302 delete $funcs{"SSL_add_dir_cert_subjects_to_stack"};
303 delete $funcs{"des_crypt"};
304 delete $funcs{"RSA_PKCS1_RSAref"} unless $rsaref;
307 delete $funcs{"BIO_s_file_internal"};
308 delete $funcs{"BIO_new_file_internal"};
309 delete $funcs{"BIO_new_fp_internal"};
311 if(exists $funcs{"ERR_load_CRYPTO_strings"}) {
312 delete $funcs{"ERR_load_CRYPTO_strings"};
313 $funcs{"ERR_load_CRYPTOlib_strings"} = 1;
315 delete $funcs{"BIO_s_file"};
316 delete $funcs{"BIO_new_file"};
317 delete $funcs{"BIO_new_fp"};
320 delete $funcs{"BIO_s_log"};
323 push @ret, keys %funcs;
330 (*OUT,my $name,*nums,@functions)=@_;
340 ; Definition file for the DLL version of the $name library from OpenSSL
345 DESCRIPTION 'OpenSSL $name - http://www.openssl.org/'
351 CODE PRELOAD MOVEABLE
352 DATA PRELOAD MOVEABLE SINGLE
365 (@e)=grep(/^SSLeay/,@functions);
366 (@r)=grep(!/^SSLeay/,@functions);
367 @functions=((sort @e),(sort @r));
369 foreach $func (@functions) {
370 if (!defined($nums{$func})) {
371 printf STDERR "$func does not have a number assigned\n"
375 printf OUT " %s%-40s@%d\n",($W32)?"":"_",$func,$n;
388 open(IN,"<$name") || die "unable to open $name:$!\n";
395 $max_num = $a[1] if $a[1] > $max_num;
403 (*OUT,$name,*nums,my $start_num, my @functions)=@_;
405 print STDERR "Updating $name\n";
406 foreach $func (@functions) {
407 if (!exists $nums{$func}) {
409 printf OUT "%s%-40s%d\n","",$func, ++$start_num;
413 print STDERR "$new_funcs New Functions added\n";
415 print STDERR "No New Functions Added\n";