1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/ckfw/builtins/certdata.perl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,181 @@ 1.4 +#!perl -w 1.5 +# 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 +use strict; 1.10 + 1.11 +my %constants; 1.12 +my $count = 0; 1.13 +my $o; 1.14 +my @objects = (); 1.15 +my @objsize; 1.16 + 1.17 +$constants{CKO_DATA} = "static const CK_OBJECT_CLASS cko_data = CKO_DATA;\n"; 1.18 +$constants{CK_TRUE} = "static const CK_BBOOL ck_true = CK_TRUE;\n"; 1.19 +$constants{CK_FALSE} = "static const CK_BBOOL ck_false = CK_FALSE;\n"; 1.20 + 1.21 +while(<>) { 1.22 + my @fields = (); 1.23 + my $size; 1.24 + 1.25 + s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/; 1.26 + next if (/^\s*$/); 1.27 + 1.28 + # This was taken from the perl faq #4. 1.29 + my $text = $_; 1.30 + push(@fields, $+) while $text =~ m{ 1.31 + "([^\"\\]*(?:\\.[^\"\\]*)*)"\s? # groups the phrase inside the quotes 1.32 + | ([^\s]+)\s? 1.33 + | \s 1.34 + }gx; 1.35 + push(@fields, undef) if substr($text,-1,1) eq '\s'; 1.36 + 1.37 + if( $fields[0] =~ /BEGINDATA/ ) { 1.38 + next; 1.39 + } 1.40 + 1.41 + if( $fields[1] =~ /MULTILINE/ ) { 1.42 + $fields[2] = ""; 1.43 + while(<>) { 1.44 + last if /END/; 1.45 + chomp; 1.46 + $fields[2] .= "\"$_\"\n"; 1.47 + } 1.48 + } 1.49 + 1.50 + if( $fields[1] =~ /UTF8/ ) { 1.51 + if( $fields[2] =~ /^"/ ) { 1.52 + ; 1.53 + } else { 1.54 + $fields[2] = "\"" . $fields[2] . "\""; 1.55 + } 1.56 + 1.57 + my $scratch = eval($fields[2]); 1.58 + 1.59 + $size = length($scratch) + 1; # null terminate 1.60 + } 1.61 + 1.62 + if( $fields[1] =~ /OCTAL/ ) { 1.63 + if( $fields[2] =~ /^"/ ) { 1.64 + ; 1.65 + } else { 1.66 + $fields[2] = "\"" . $fields[2] . "\""; 1.67 + } 1.68 + 1.69 + my $scratch = $fields[2]; 1.70 + $size = $scratch =~ tr/\\//; 1.71 + # no null termination 1.72 + } 1.73 + 1.74 + if( $fields[1] =~ /^CK_/ ) { 1.75 + my $lcv = $fields[2]; 1.76 + $lcv =~ tr/A-Z/a-z/; 1.77 + if( !defined($constants{$fields[2]}) ) { 1.78 + $constants{$fields[2]} = "static const $fields[1] $lcv = $fields[2];\n"; 1.79 + } 1.80 + 1.81 + $size = "sizeof($fields[1])"; 1.82 + $fields[2] = "&$lcv"; 1.83 + } 1.84 + 1.85 + if( $fields[0] =~ /CKA_CLASS/ ) { 1.86 + $count++; 1.87 + $objsize[$count] = 0; 1.88 + } 1.89 + 1.90 + @{$objects[$count][$objsize[$count]++]} = ( "$fields[0]", $fields[2], "$size" ); 1.91 + 1.92 + # print "$fields[0] | $fields[1] | $size | $fields[2]\n"; 1.93 +} 1.94 + 1.95 +doprint(); 1.96 + 1.97 +sub dudump { 1.98 +my $i; 1.99 +for( $i = 1; $i <= $count; $i++ ) { 1.100 + print "\n"; 1.101 + $o = $objects[$i]; 1.102 + my @ob = @{$o}; 1.103 + my $l; 1.104 + my $j; 1.105 + for( $j = 0; $j < @ob; $j++ ) { 1.106 + $l = $ob[$j]; 1.107 + my @a = @{$l}; 1.108 + print "$a[0] ! $a[1] ! $a[2]\n"; 1.109 + } 1.110 +} 1.111 + 1.112 +} 1.113 + 1.114 +sub doprint { 1.115 +my $i; 1.116 + 1.117 +print <<EOD 1.118 +/* THIS IS A GENERATED FILE */ 1.119 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.120 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.121 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.122 + 1.123 +#ifndef BUILTINS_H 1.124 +#include "builtins.h" 1.125 +#endif /* BUILTINS_H */ 1.126 + 1.127 +EOD 1.128 + ; 1.129 + 1.130 +foreach $b (sort values(%constants)) { 1.131 + print $b; 1.132 +} 1.133 + 1.134 +for( $i = 1; $i <= $count; $i++ ) { 1.135 + print "static const CK_ATTRIBUTE_TYPE nss_builtins_types_$i [] = {\n"; 1.136 + $o = $objects[$i]; 1.137 + my @ob = @{$o}; 1.138 + my $j; 1.139 + for( $j = 0; $j < @ob; $j++ ) { 1.140 + my $l = $ob[$j]; 1.141 + my @a = @{$l}; 1.142 + print " $a[0]"; 1.143 + if( $j+1 != @ob ) { 1.144 + print ", "; 1.145 + } 1.146 + } 1.147 + print "\n};\n"; 1.148 +} 1.149 + 1.150 +for( $i = 1; $i <= $count; $i++ ) { 1.151 + print "static const NSSItem nss_builtins_items_$i [] = {\n"; 1.152 + $o = $objects[$i]; 1.153 + my @ob = @{$o}; 1.154 + my $j; 1.155 + for( $j = 0; $j < @ob; $j++ ) { 1.156 + my $l = $ob[$j]; 1.157 + my @a = @{$l}; 1.158 + print " { (void *)$a[1], (PRUint32)$a[2] }"; 1.159 + if( $j+1 != @ob ) { 1.160 + print ",\n"; 1.161 + } else { 1.162 + print "\n"; 1.163 + } 1.164 + } 1.165 + print "};\n"; 1.166 +} 1.167 + 1.168 +print "\nbuiltinsInternalObject\n"; 1.169 +print "nss_builtins_data[] = {\n"; 1.170 + 1.171 +for( $i = 1; $i <= $count; $i++ ) { 1.172 + print " { $objsize[$i], nss_builtins_types_$i, nss_builtins_items_$i, {NULL} }"; 1.173 + if( $i == $count ) { 1.174 + print "\n"; 1.175 + } else { 1.176 + print ",\n"; 1.177 + } 1.178 +} 1.179 + 1.180 +print "};\n"; 1.181 + 1.182 +print "const PRUint32\n"; 1.183 +print "nss_builtins_nObjects = $count;\n"; 1.184 +}