]>
Commit | Line | Data |
---|---|---|
563f4f96 A |
1 | #!/usr/bin/perl |
2 | # | |
3 | # Copyright (c) 2003-2004 Apple Computer, Inc. All Rights Reserved. | |
4 | # | |
5 | # @APPLE_LICENSE_HEADER_START@ | |
6 | # | |
7 | # This file contains Original Code and/or Modifications of Original Code | |
8 | # as defined in and that are subject to the Apple Public Source License | |
9 | # Version 2.0 (the 'License'). You may not use this file except in | |
10 | # compliance with the License. Please obtain a copy of the License at | |
11 | # http://www.opensource.apple.com/apsl/ and read it before using this | |
12 | # file. | |
13 | # | |
14 | # The Original Code and all software distributed under the License are | |
15 | # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
19 | # Please see the License for the specific language governing rights and | |
20 | # limitations under the License. | |
21 | # | |
22 | # @APPLE_LICENSE_HEADER_END@ | |
23 | # | |
24 | # generatorX.pl - create error strings files from the Security header files | |
25 | # | |
26 | # John Hurley, Summer 2003. Based on generator.pl, Perry The Cynic, Fall 1999. | |
27 | # | |
28 | # Usage: | |
29 | # perl generatorX.pl input-directory output-directory <files> | |
30 | # | |
31 | # Currently supported files are SecBase.h, SecureTransport.h and Authorization.h | |
32 | # | |
33 | # perl generatorX.pl `pwd` `pwd` SecBase2.h SecureTransport2.h Authorization.h | |
34 | # | |
35 | # Input will be like: | |
36 | # | |
37 | # errSSLProtocol = -9800, /* SSL protocol error */ | |
38 | # errSSLNegotiation = -9801, /* Cipher Suite negotiation failure */ | |
39 | # | |
40 | # Output should be like (in Unicode): | |
41 | # | |
42 | # /* errSSLProtocol */ | |
43 | # "-9800" = "SSL protocol error"; | |
44 | # | |
45 | # /* errSSLNegotiation */ | |
46 | # "-9801" = "Cipher Suite negotiation failure"; | |
47 | # | |
48 | # Note that the list of errors must be numerically unique across all input files, or the strings file | |
49 | # will be invalid.Comments that span multiple lines will be ignored, as will lines with no comment. C++ | |
50 | # style comments are not supported. | |
51 | # | |
52 | use strict; | |
53 | use Encode; | |
54 | ||
55 | my $INPUTFILE=$ARGV[0]; # list of input files | |
56 | my $FRAMEWORK=$ARGV[1]; # directory containing Security.framework | |
57 | my $TARGETFILE=$ARGV[2]; # where to put the output file | |
58 | ||
59 | my $tabs = "\t\t\t"; # argument indentation (noncritical) | |
60 | my $warning = "This file was automatically generated. Do not edit on penalty of futility!"; | |
61 | ||
62 | # | |
63 | # Read error headers into memory (all just concatenated blindly) | |
64 | # | |
65 | open(ERR, "$INPUTFILE") or die "Cannot open $INPUTFILE"; | |
66 | $/=undef; # big gulp mode | |
67 | $_ = <ERR>; | |
68 | close(ERR); | |
69 | ||
70 | # | |
71 | # Prepare output file | |
72 | # | |
73 | open(OUT, ">$TARGETFILE") or die "Cannot write $TARGETFILE: $^E"; | |
74 | my $msg = "//\n// Security error code tables.\n// $warning\n//\n"; | |
75 | ||
76 | ||
77 | # | |
78 | # Extract errors from accumulated header text. Format: | |
79 | # errBlahWhatever = number, /* text */ | |
80 | # | |
81 | my @errorlines = | |
82 | m{(?:^\s*)(err[Sec|Authorization|SSL]\w+)(?:\s*=\s*)(-?\d+)(?:\s*,?\s*)(?:/\*\s*)(.*)(?:\*/)(?:$\s*)}gm; | |
83 | while (my $errx = shift @errorlines) | |
84 | { | |
85 | my $value = shift @errorlines; # or die; | |
86 | my $str = shift @errorlines; # or die; | |
87 | $str =~ s/\s*$//; # drop trailing white space | |
88 | if ( $value != 0) # can't output duplicate error codes | |
89 | { | |
90 | $msg = $msg . "\n/* $errx */\n\"$value\" = \"$str\";\n"; | |
91 | } | |
92 | }; | |
93 | $msg = $msg . "\n"; | |
94 | ||
95 | ||
96 | # | |
97 | # Extract errors from CSSM headers. Format: | |
98 | # CSSMERR_whatever = some compile-time C expression | |
99 | # [We just build a C program and running it. So sue us.] | |
100 | # | |
101 | my $PROG = "/tmp/cssmerrors.$$.c"; | |
102 | my $PROGB = "/tmp/cssmerrors.$$"; | |
103 | ||
104 | open(PROG, ">$PROG") or die "Cannot open $PROG"; | |
105 | print PROG <<END; | |
106 | #include <Security/cssmerr.h> | |
107 | #include <Security/cssmapple.h> | |
108 | #include <stdio.h> | |
109 | int main() { | |
110 | END | |
111 | @errorlines = | |
112 | m{(?:^\s*)CSSMERR_([A-Z_]+)\s+=}gm; | |
113 | for my $error (@errorlines) { | |
114 | print PROG "printf(\"\\n/* CSSMERR_$error */\\n\\\"%ld\\\" = \\\"$error\\\";\\n\", CSSMERR_$error);\n"; | |
115 | } | |
116 | print PROG "}\n"; | |
117 | close(PROG); | |
118 | ||
119 | system("cc", "-o", $PROGB, $PROG, "-I$FRAMEWORK/SecurityPieces/Headers") == 0 or die "cannot build CSSM collector"; | |
120 | open(PROGR, "$PROGB|") or die "Cannot run CSSM collector"; | |
121 | $msg .= <PROGR>; | |
122 | close(PROGR); | |
123 | ||
124 | # | |
125 | # Write output file and clean up | |
126 | # | |
127 | print OUT encode("UTF-16", $msg, Encode::FB_PERLQQ); | |
128 | close(OUT); |