]> git.ipfire.org Git - people/ms/strongswan.git/blame - programs/charon/lib/asn1/oid.pl
- import of strongswan-2.7.0
[people/ms/strongswan.git] / programs / charon / lib / asn1 / oid.pl
CommitLineData
b5cb0210
MW
1#!/usr/bin/perl
2# Generates oid.h and oid.c out of oid.txt
3# Copyright (C) 2003-2004 Andreas Steffen, Zuercher Hochschule Winterthur
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License as published by the
7# Free Software Foundation; either version 2 of the License, or (at your
8# option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13# for more details.
14#
15
16$copyright="Copyright (C) 2003-2004 Andreas Steffen, Zuercher Hochschule Winterthur";
17$automatic="This file has been automatically generated by the script oid.pl";
18$warning="Do not edit manually!";
19
20print "oid.pl generating oid.h and oid.c\n";
21
22# Generate oid.h
23
24open(OID_H, ">oid.h")
25 or die "could not open 'oid.h': $!";
26
27print OID_H "/* Object identifiers (OIDs) used by FreeS/WAN\n",
28 " * ", $copyright, "\n",
29 " * \n",
30 " * ", $automatic, "\n",
31 " * ", $warning, "\n",
32 " */\n\n",
a8c09d8c
MW
33 "#ifndef OID_H_\n",
34 "#define OID_H_\n\n",
b5cb0210
MW
35 "typedef struct {\n",
36 " u_char octet;\n",
37 " u_int next;\n",
38 " u_int down;\n",
39 " const u_char *name;\n",
40 "} oid_t;\n",
41 "\n",
42 "extern const oid_t oid_names[];\n",
43 "\n",
44 "#define OID_UNKNOWN -1\n";
45
46# parse oid.txt
47
48open(SRC, "<oid.txt")
49 or die "could not open 'oid.txt': $!";
50
51$counter = 0;
52$max_name = 0;
53$max_order = 0;
54
55while ($line = <SRC>)
56{
57 $line =~ m/( *?)(0x\w{2})\s+(".*?")[ \t]*?([\w_]*?)\Z/;
58
59 @order[$counter] = length($1);
60 @octet[$counter] = $2;
61 @name[$counter] = $3;
62
63 if (length($1) > $max_order)
64 {
65 $max_order = length($1);
66 }
67 if (length($3) > $max_name)
68 {
69 $max_name = length($3);
70 }
71 if (length($4) > 0)
72 {
73 printf OID_H "#define %s%s%d\n", $4, "\t" x ((39-length($4))/8), $counter;
74 }
75 $counter++;
76}
77
a8c09d8c
MW
78print OID_H "\n#endif /* OID_H_ */\n";
79
b5cb0210
MW
80close SRC;
81close OID_H;
82
83# Generate oid.c
84
85open(OID_C, ">oid.c")
86 or die "could not open 'oid.c': $!";
87
88print OID_C "/* List of some useful object identifiers (OIDs)\n",
89 " * ", $copyright, "\n",
90 " * \n",
91 " * ", $automatic, "\n",
92 " * ", $warning, "\n",
93 " */\n",
94 "\n",
95 "#include <stdlib.h>\n",
96 "\n",
97 "#include \"oid.h\"\n",
98 "\n",
99 "const oid_t oid_names[] = {\n";
100
101for ($c = 0; $c < $counter; $c++)
102{
103 $next = 0;
104
105 for ($d = $c+1; $d < $counter && @order[$d] >= @order[$c]; $d++)
106 {
107 if (@order[$d] == @order[$c])
108 {
109 @next[$c] = $d;
110 last;
111 }
112 }
113
114 printf OID_C " {%s%s,%s%3d, %d, %s%s}%s /* %3d */\n"
115 ,' ' x @order[$c]
116 , @octet[$c]
117 , ' ' x (1 + $max_order - @order[$c])
118 , @next[$c]
119 , @order[$c+1] > @order[$c]
120 , @name[$c]
121 , ' ' x ($max_name - length(@name[$c]))
122 , $c != $counter-1 ? "," : " "
123 , $c;
124}
125
126print OID_C "};\n" ;
127close OID_C;