]>
git.saurik.com Git - apple/security.git/blob - lib/generateErrStrings.pl
3 # Copyright (c) 2003-2004 Apple Computer, Inc. All Rights Reserved.
5 # @APPLE_LICENSE_HEADER_START@
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
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.
22 # @APPLE_LICENSE_HEADER_END@
24 # generatorX.pl - create error strings files from the Security header files
26 # John Hurley, Summer 2003. Based on generator.pl, Perry The Cynic, Fall 1999.
29 # perl generatorX.pl input-directory output-directory <files>
31 # Currently supported files are SecBase.h, SecureTransport.h and Authorization.h
33 # perl generatorX.pl `pwd` `pwd` SecBase2.h SecureTransport2.h Authorization.h
37 # errSSLProtocol = -9800, /* SSL protocol error */
38 # errSSLNegotiation = -9801, /* Cipher Suite negotiation failure */
40 # Output should be like (in Unicode):
42 # /* errSSLProtocol */
43 # "-9800" = "SSL protocol error";
45 # /* errSSLNegotiation */
46 # "-9801" = "Cipher Suite negotiation failure";
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.
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
59 my $tabs = "\t\t\t"; # argument indentation (noncritical)
60 my $warning = "This file was automatically generated. Do not edit on penalty of futility!";
63 # Read error headers into memory (all just concatenated blindly)
65 open(ERR
, "$INPUTFILE") or die "Cannot open $INPUTFILE";
66 $/=undef; # big gulp mode
73 open(OUT
, ">$TARGETFILE") or die "Cannot write $TARGETFILE: $^E";
74 my $msg = "//\n// Security error code tables.\n// $warning\n//\n";
78 # Extract errors from accumulated header text. Format:
79 # errBlahWhatever = number, /* text */
82 m{(?:^\s*)(err[Sec|Authorization|SSL]\w+)(?:\s*=\s*)(-?\d+)(?:\s*,?\s*)(?:/\*\s*)(.*)(?:\*/)(?:$\s*)}gm;
83 while (my $errx = shift @errorlines)
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
90 $msg = $msg . "\n/* $errx */\n\"$value\" = \"$str\";\n";
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.]
101 my $PROG = "/tmp/cssmerrors.$$.c";
102 my $PROGB = "/tmp/cssmerrors.$$";
104 open(PROG
, ">$PROG") or die "Cannot open $PROG";
106 #include <Security/cssmerr.h>
107 #include <Security/cssmapple.h>
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";
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";
125 # Write output file and clean up
127 print OUT encode
("UTF-16", $msg, Encode
::FB_PERLQQ
);