vendor/BIND: Update to 9.5.2-P3
[dragonfly.git] / contrib / bind / lib / dns / spnego_asn1.pl
blob93dd676752dfcf7235cd93395296b9a157afadde
1 #!/bin/bin/perl -w
3 # Copyright (C) 2006, 2007 Internet Systems Consortium, Inc. ("ISC")
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
17 # $Id: spnego_asn1.pl,v 1.4 2007/06/19 23:47:16 tbox Exp $
19 # Our SPNEGO implementation uses some functions generated by the
20 # Heimdal ASN.1 compiler, which this script then whacks a bit to make
21 # them work properly in this stripped down implementation. We don't
22 # want to require our users to have a copy of the compiler, so we ship
23 # the output of this script, but we need to keep the script around in
24 # any case to cope with future changes to the SPNEGO ASN.1 code, so we
25 # might as well supply the script for users who want it.
27 # Overall plan: run the ASN.1 compiler, run each of its output files
28 # through indent, fix up symbols and whack everything to be static.
29 # We use indent for two reasons: (1) to whack the Heimdal compiler's
30 # output into something closer to ISC's coding standard, and (2) to
31 # make it easier for this script to parse the result.
33 # Output from this script is C code which we expect to be #included
34 # into another C file, which is why everything generated by this
35 # script is marked "static". The intent is to minimize the number of
36 # extern symbols exported by the SPNEGO implementation, to avoid
37 # potential conflicts with the GSSAPI libraries.
39 ###
41 # Filename of the ASN.1 specification. Hardcoded for the moment
42 # since this script is intended for compiling exactly one module.
44 my $asn1_source = $ENV{ASN1_SOURCE} || "spnego.asn1";
46 # Heimdal ASN.1 compiler. This script was written using the version
47 # from Heimdal 0.7.1. To build this, download a copy of
48 # heimdal-0.7.1.tar.gz, configure and build with the default options,
49 # then look for the compiler in heimdal-0.7.1/lib/asn1/asn1_compile.
51 my $asn1_compile = $ENV{ASN1_COMPILE} || "asn1_compile";
53 # BSD indent program. This script was written using the version of
54 # indent that comes with FreeBSD 4.11-STABLE. The GNU project, as
55 # usual, couldn't resist the temptation to monkey with indent's
56 # command line syntax, so this probably won't work with GNU indent.
58 my $indent = $ENV{INDENT} || "indent";
60 ###
62 # Step 1: run the compiler. Input is the ASN.1 file. Outputs are a
63 # header file (name specified on command line without the .h suffix),
64 # a file called "asn1_files" listing the names of the other output
65 # files, and a set of files containing C code generated by the
66 # compiler for each data type that the compiler found.
68 if (! -r $asn1_source || system($asn1_compile, $asn1_source, "asn1")) {
69 die("Couldn't compile ASN.1 source file $asn1_source\n");
72 my @files = ("asn1.h");
74 open(F, "asn1_files")
75 or die("Couldn't open asn1_files: $!\n");
76 push(@files, split)
77 while (<F>);
78 close(F);
80 unlink("asn1_files");
82 ###
84 # Step 2: generate header block.
86 print(q~/*
87 * Copyright (C) 2006 Internet Systems Consortium, Inc. ("ISC")
89 * Permission to use, copy, modify, and distribute this software for any
90 * purpose with or without fee is hereby granted, provided that the above
91 * copyright notice and this permission notice appear in all copies.
93 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
94 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
95 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
96 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
97 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
98 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
99 * PERFORMANCE OF THIS SOFTWARE.
102 /* $Id: spnego_asn1.pl,v 1.4 2007/06/19 23:47:16 tbox Exp $ */
104 /*! \file
105 * \brief Method routines generated from SPNEGO ASN.1 module.
106 * See spnego_asn1.pl for details. Do not edit.
113 # Step 3: read and process each generated file, then delete it.
115 my $output;
117 for my $file (@files) {
119 my $is_static = 0;
121 system($indent, "-di1", "-ldi1", $file) == 0
122 or die("Couldn't indent $file");
124 unlink("$file.BAK");
126 open(F, $file)
127 or die("Couldn't open $file: $!");
129 while (<F>) {
131 # Symbol name fixups
133 s/heim_general_string/general_string/g;
134 s/heim_octet_string/octet_string/g;
135 s/heim_oid/oid/g;
136 s/heim_utf8_string/utf8_string/g;
138 # Convert all externs to statics
140 if (/^static/) {
141 $is_static = 1;
144 if (!/^typedef/ &&
145 !$is_static &&
146 /^[A-Za-z_][0-9A-Za-z_]*[ \t]*($|[^:0-9A-Za-z_])/) {
147 $_ = "static " . $_;
148 $is_static = 1;
151 if (/[{};]/) {
152 $is_static = 0;
155 # Suppress file inclusion, pass anything else through
157 if (!/#include/) {
158 $output .= $_;
162 close(F);
163 unlink($file);
166 # Step 4: Delete unused stuff to avoid code bloat and compiler warnings.
168 my @unused_functions = qw(ContextFlags2int
169 int2ContextFlags
170 asn1_ContextFlags_units
171 length_NegTokenInit
172 copy_NegTokenInit
173 length_NegTokenResp
174 copy_NegTokenResp
175 length_MechTypeList
176 length_MechType
177 copy_MechTypeList
178 length_ContextFlags
179 copy_ContextFlags
180 copy_MechType);
182 $output =~ s<^static [^\n]+\n$_\(.+?^}></* unused function: $_ */\n>ms
183 foreach (@unused_functions);
185 $output =~ s<^static .+$_\(.*\);$></* unused declaration: $_ */>m
186 foreach (@unused_functions);
188 $output =~ s<^static struct units ContextFlags_units\[\].+?^};>
189 </* unused variable: ContextFlags_units */>ms;
191 $output =~ s<^static int asn1_NegotiationToken_dummy_holder = 1;>
192 </* unused variable: asn1_NegotiationToken_dummy_holder */>ms;
194 $output =~ s<^static void\nfree_ContextFlags\(ContextFlags \* data\)\n{\n>
195 <$&\t(void)data;\n>ms;
197 # Step 5: Write the result.
199 print($output);