blob: 9cc0631c244abfd2b6b01d103f09234c1261dff5 [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001#!/usr/bin/env perl
2use strict;
3use Getopt::Std;
4
5our ($opt_V, $opt_v);
6
7# default to 3GPP
8my ($vendor) = 10415;
9my ($vendor_name) = "3GPP";
10
11sub convert_must_to_flags($) {
12 my ($allmust) = @_;
13 my ($mustfields) = "";
14 $mustfields .= "AVP_FLAG_VENDOR |" if ($allmust =~ m/V/);
15 $mustfields .= "AVP_FLAG_MANDATORY |" if ($allmust =~ m/M/);
16 $mustfields =~ s/ \|$//;
17 return $mustfields;
18}
19
20sub base_type($) {
21 my ($type) = @_;
22
23 return "AVP_TYPE_GROUPED" if ($type =~ m/Grouped/);
24 return "AVP_TYPE_OCTETSTRING" if ($type =~ m/(Address|DiameterIdentity|DiameterURI|OctetString|IPFilterRule|Time|UTF8String)/);
25 return "AVP_TYPE_INTEGER32" if ($type =~ m/Enumerated|Integer32/);
26 return "AVP_TYPE_INTEGER64" if ($type =~ m/Integer64/);
27 return "AVP_TYPE_UNSIGNED32" if ($type =~ m/Unsigned32/);
28 return "AVP_TYPE_UNSIGNED64" if ($type =~ m/Unsigned64/);
29 return "AVP_TYPE_FLOAT32" if ($type =~ m/Float32/);
30 return "AVP_TYPE_FLOAT64" if ($type =~ m/Float64/);
31
32 return "UNKNOWN TYPE: $type";
33}
34
35sub print_insert($$) {
36 my ($type, $name) = @_;
37 my $avp_type;
38
39 if ($type =~ m/(Grouped|OctetString|Integer32|Integer64|Unsigned32|Unsigned64|Float32|Float64)/) {
40 $avp_type = "NULL";
41 } elsif ($type =~ m/Enumerated/) {
42 print "\t\tstruct dict_object *type;\n";
43 print "\t\tstruct dict_type_data tdata = { AVP_TYPE_INTEGER32, \"" . ($vendor_name ? "$vendor_name/" : "") ."Enumerated($name)\", NULL, NULL, NULL };\n";
44 # XXX: add enumerated values
45 print "\t\tCHECK_dict_new(DICT_TYPE, &tdata, NULL, &type);\n";
46 $avp_type = "type";
47 } else {
48 $avp_type = "${type}_type";
49 }
50
51 print "\t\tCHECK_dict_new(DICT_AVP, &data, $avp_type, NULL);\n";
52}
53
54sub usage($) {
55 die("usage: org_to_fd.pl [-V vendor_name -v vendor_code] [file ...]\n");
56 exit(@_);
57}
58
59getopts("V:v:") || usage(1);
60
61if (defined($opt_v)) {
62 $vendor = $opt_v;
63 if (!defined($opt_V)) {
64 usage(1);
65 }
66 $vendor_name = $opt_V;
67}
68
69print "\t/* The following is created automatically. Do not modify. */\n";
70print "\t/* Changes will be lost during the next update. Modify the source org file instead. */\n\n";
71
72while (<>) {
73 my ($dummy, $name, $code, $section, $type, $must, $may, $shouldnot, $mustnot, $encr) = split /\|/;
74
75 next if ($name =~ m/Attribute Name/);
76 if ($name =~ m/ # (.*)/) {
77 print "\t/* $1 */\n";
78 next;
79 }
80
81
82 $name =~ s/ *//g;
83 $code =~ s/ *//g;
84 $type =~ s/ *//g;
85
86 print "\t/* $name */\n\t{\n\t\tstruct dict_avp_data data = {\n";
87 print "\t\t\t$code,\t/* Code */\n";
88 print "\t\t\t$vendor,\t/* Vendor */\n";
89 print "\t\t\t\"$name\",\t/* Name */\n";
90 print "\t\t\t" . convert_must_to_flags("$must, $mustnot") . ",\t/* Fixed flags */\n";
91 print "\t\t\t" . convert_must_to_flags("$must") . ",\t/* Fixed flag values */\n";
92 print "\t\t\t" . base_type($type) . "\t/* base type of data */\n";
93 print "\t\t};\n";
94 print_insert($type, $name);
95 print "\t};\n\n";
96}