Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / security / nss / lib / pki1 / oidgen.perl
blob4d6d8ad0393ebebf2df654c1b9018d87bbe0fff0
1 #!perl
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is the Netscape security libraries.
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1994-2000
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s):
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
38 $cvs_id = '@(#) $RCSfile: oidgen.perl,v $ $Revision: 1.6 $ $Date: 2005/03/14 18:02:00 $';
39 $cfile = shift;
40 $hfile = shift;
41 $count = -1;
42 while(<>) {
43 s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/;
44 next if (/^\s*$/);
46 /^([\S]+)\s+([^"][\S]*|"[^"]*")/;
47 $name = $1;
48 $value = $2;
49 # This is certainly not the best way to dequote the data.
50 $value =~ s/"//g;
52 if( $name =~ "OID" ) {
53 $count++;
54 $x[$count]{$name} = $value;
55 $enc = encodeoid($value);
56 $x[$count]{" encoding"} = escapeoid($enc);
57 $x[$count]{" encoding length"} = length($enc);
58 } else {
59 if( $count < 0 ) {
60 $g{$name} = $value;
61 } else {
62 $x[$count]{$name} = $value;
67 # dodump();
69 doprint($cfile,$hfile);
71 sub dodump {
72 for( $i = 0; $i <= $count; $i++ ) {
73 print "number $i:\n";
74 %y = %{$x[$i]};
75 while(($n,$v) = each(%y)) {
76 print "\t$n ==> $v\n";
81 sub doprint {
82 open(CFILE, "> $cfile") || die "Can't open $cfile: $!";
83 open(HFILE, "> $hfile") || die "Can't open $hfile: $!";
85 print CFILE <<EOD
86 /* THIS IS A GENERATED FILE */
87 /* ***** BEGIN LICENSE BLOCK *****
88 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
90 * The contents of this file are subject to the Mozilla Public License Version
91 * 1.1 (the "License"); you may not use this file except in compliance with
92 * the License. You may obtain a copy of the License at
93 * http://www.mozilla.org/MPL/
95 * Software distributed under the License is distributed on an "AS IS" basis,
96 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
97 * for the specific language governing rights and limitations under the
98 * License.
100 * The Original Code is the Netscape security libraries.
102 * The Initial Developer of the Original Code is
103 * Netscape Communications Corporation.
104 * Portions created by the Initial Developer are Copyright (C) 1994-2000
105 * the Initial Developer. All Rights Reserved.
107 * Contributor(s):
109 * Alternatively, the contents of this file may be used under the terms of
110 * either the GNU General Public License Version 2 or later (the "GPL"), or
111 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
112 * in which case the provisions of the GPL or the LGPL are applicable instead
113 * of those above. If you wish to allow use of your version of this file only
114 * under the terms of either the GPL or the LGPL, and not to allow others to
115 * use your version of this file under the terms of the MPL, indicate your
116 * decision by deleting the provisions above and replace them with the notice
117 * and other provisions required by the GPL or the LGPL. If you do not delete
118 * the provisions above, a recipient may use your version of this file under
119 * the terms of any one of the MPL, the GPL or the LGPL.
121 * ***** END LICENSE BLOCK ***** */
123 #ifdef DEBUG
124 static const char CVS_ID[] = "$g{CVS_ID} ; $cvs_id";
125 #endif /* DEBUG */
127 #ifndef PKI1T_H
128 #include "pki1t.h"
129 #endif /* PKI1T_H */
131 const NSSOID nss_builtin_oids[] = {
135 for( $i = 0; $i <= $count; $i++ ) {
136 %y = %{$x[$i]};
137 print CFILE " {\n";
138 print CFILE "#ifdef DEBUG\n";
139 print CFILE " \"$y{TAG}\",\n";
140 print CFILE " \"$y{EXPL}\",\n";
141 print CFILE "#endif /* DEBUG */\n";
142 print CFILE " { \"", $y{" encoding"};
143 print CFILE "\", ", $y{" encoding length"}, " }\n";
145 if( $i == $count ) {
146 print CFILE " }\n";
147 } else {
148 print CFILE " },\n";
152 print CFILE "};\n\n";
154 print CFILE "const PRUint32 nss_builtin_oid_count = ", ($count+1), ";\n\n";
156 for( $i = 0; $i <= $count; $i++ ) {
157 %y = %{$x[$i]};
158 if( defined($y{NAME}) ) {
159 print CFILE "const NSSOID *$y{NAME} = (NSSOID *)&nss_builtin_oids[$i];\n";
163 print CFILE "\n";
165 $attrcount = -1;
166 for( $i = 0; $i <= $count; $i++ ) {
167 %y = %{$x[$i]};
168 if( defined($y{ATTR}) ) {
169 if( defined($y{NAME}) ) {
170 $attrcount++;
171 $attr[$attrcount]{ATTR} = $y{ATTR};
172 $attr[$attrcount]{NAME} = $y{NAME};
173 } else {
174 warn "Attribute $y{ATTR} has no name, and will be omitted!";
179 print CFILE "const nssAttributeTypeAliasTable nss_attribute_type_aliases[] = {\n";
181 for( $i = 0; $i <= $attrcount; $i++ ) {
182 %y = %{$attr[$i]};
183 print CFILE " {\n";
184 print CFILE " \"$y{ATTR}\",\n";
185 print CFILE " &$y{NAME}\n";
187 if( $i == $attrcount ) {
188 print CFILE " }\n";
189 } else {
190 print CFILE " },\n";
194 print CFILE "};\n\n";
196 print CFILE "const PRUint32 nss_attribute_type_alias_count = ", ($attrcount+1), ";\n\n";
198 print HFILE <<EOD
199 /* THIS IS A GENERATED FILE */
200 /* ***** BEGIN LICENSE BLOCK *****
201 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
203 * The contents of this file are subject to the Mozilla Public License Version
204 * 1.1 (the "License"); you may not use this file except in compliance with
205 * the License. You may obtain a copy of the License at
206 * http://www.mozilla.org/MPL/
208 * Software distributed under the License is distributed on an "AS IS" basis,
209 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
210 * for the specific language governing rights and limitations under the
211 * License.
213 * The Original Code is the Netscape security libraries.
215 * The Initial Developer of the Original Code is
216 * Netscape Communications Corporation.
217 * Portions created by the Initial Developer are Copyright (C) 1994-2000
218 * the Initial Developer. All Rights Reserved.
220 * Contributor(s):
222 * Alternatively, the contents of this file may be used under the terms of
223 * either the GNU General Public License Version 2 or later (the "GPL"), or
224 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
225 * in which case the provisions of the GPL or the LGPL are applicable instead
226 * of those above. If you wish to allow use of your version of this file only
227 * under the terms of either the GPL or the LGPL, and not to allow others to
228 * use your version of this file under the terms of the MPL, indicate your
229 * decision by deleting the provisions above and replace them with the notice
230 * and other provisions required by the GPL or the LGPL. If you do not delete
231 * the provisions above, a recipient may use your version of this file under
232 * the terms of any one of the MPL, the GPL or the LGPL.
234 * ***** END LICENSE BLOCK ***** */
236 #ifndef OIDDATA_H
237 #define OIDDATA_H
239 #ifdef DEBUG
240 static const char OIDDATA_CVS_ID[] = "$g{CVS_ID} ; $cvs_id";
241 #endif /* DEBUG */
243 #ifndef NSSPKI1T_H
244 #include "nsspki1t.h"
245 #endif /* NSSPKI1T_H */
250 for( $i = 0; $i <= $count; $i++ ) {
251 %y = %{$x[$i]};
252 if( defined($y{NAME}) ) {
253 print HFILE "extern const NSSOID *$y{NAME};\n";
257 print HFILE <<EOD
259 #endif /* OIDDATA_H */
263 close CFILE;
264 close HFILE;
267 sub encodenum {
268 my $v = $_[0];
269 my @d;
270 my $i;
271 my $rv = "";
273 while( $v > 128 ) {
274 push @d, ($v % 128);
275 $v /= 128;
277 push @d, ($v%128);
279 for( $i = @d-1; $i > 0; $i-- ) {
280 $rv = $rv . chr(128 + $d[$i]);
283 $rv = $rv . chr($d[0]);
285 return $rv;
288 sub encodeoid {
289 my @o = split(/\./, $_[0]);
290 my $rv = "";
291 my $i;
293 if( @o < 2 ) {
294 # NSS's special "illegal" encoding
295 return chr(128) . encodenum($o[0]);
298 $rv = encodenum($o[0] * 40 + $o[1]);
299 shift @o; shift @o;
301 foreach $i (@o) {
302 $rv = $rv . encodenum($i);
305 return $rv;
308 sub escapeoid {
309 my @v = unpack("C*", $_[0]);
310 my $a;
311 my $rv = "";
313 foreach $a (@v) {
314 $rv = $rv . sprintf("\\x%02x", $a);
317 return $rv;