Mercurial > hg > freeDiameter
annotate extensions/dict_dcca_starent/dict_dcca_starent.c @ 1499:71cc2c59e7dc
move generated AVPs into separate source files
Refactor dict_dcca_3gpp and dict_dcca_starent so
the generated source is in a separate add_avps.c.
Easier to maintain, and also compiles faster.
Improve the error logging for DICT_RULE failure.
author | Luke Mewburn <luke@mewburn.net> |
---|---|
date | Fri, 03 Apr 2020 12:11:11 +1100 |
parents | b98c9de78f58 |
children |
rev | line source |
---|---|
962
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
1 /* |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
2 * Dictionary definitions of objects specified in DCCA by Starent. |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
3 */ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
4 #include <freeDiameter/extension.h> |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
5 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
6 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
7 /* The content of this file follows the same structure as dict_base_proto.c */ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
8 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
9 #define CHECK_dict_search( _type, _criteria, _what, _result ) \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
10 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, (_type), (_criteria), (_what), (_result), ENOENT) ); |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
11 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
12 struct local_rules_definition { |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
13 char *avp_name; |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
14 enum rule_position position; |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
15 int min; |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
16 int max; |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
17 }; |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
18 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
19 #define RULE_ORDER( _position ) ((((_position) == RULE_FIXED_HEAD) || ((_position) == RULE_FIXED_TAIL)) ? 1 : 0 ) |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
20 |
1227 | 21 /* Attention! This version of the macro uses AVP_BY_NAME_ALL_VENDORS, in contrast to most other copies! */ |
962
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
22 #define PARSE_loc_rules( _rulearray, _parent) { \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
23 int __ar; \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
24 for (__ar=0; __ar < sizeof(_rulearray) / sizeof((_rulearray)[0]); __ar++) { \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
25 struct dict_rule_data __data = { NULL, \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
26 (_rulearray)[__ar].position, \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
27 0, \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
28 (_rulearray)[__ar].min, \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
29 (_rulearray)[__ar].max}; \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
30 __data.rule_order = RULE_ORDER(__data.rule_position); \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
31 CHECK_FCT( fd_dict_search( \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
32 fd_g_config->cnf_dict, \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
33 DICT_AVP, \ |
1227 | 34 AVP_BY_NAME_ALL_VENDORS, \ |
962
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
35 (_rulearray)[__ar].avp_name, \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
36 &__data.rule_avp, 0 ) ); \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
37 if ( !__data.rule_avp ) { \ |
1499
71cc2c59e7dc
move generated AVPs into separate source files
Luke Mewburn <luke@mewburn.net>
parents:
1470
diff
changeset
|
38 LOG_E( "AVP Not found: '%s'", (_rulearray)[__ar].avp_name ); \ |
962
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
39 return ENOENT; \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
40 } \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
41 CHECK_FCT_DO( fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &__data, _parent, NULL), \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
42 { \ |
1499
71cc2c59e7dc
move generated AVPs into separate source files
Luke Mewburn <luke@mewburn.net>
parents:
1470
diff
changeset
|
43 LOG_E( "Error on rule with AVP '%s'", \ |
962
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
44 (_rulearray)[__ar].avp_name ); \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
45 return EINVAL; \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
46 } ); \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
47 } \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
48 } |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
49 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
50 #define enumval_def_u32( _val_, _str_ ) \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
51 { _str_, { .u32 = _val_ }} |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
52 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
53 #define enumval_def_os( _len_, _val_, _str_ ) \ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
54 { _str_, { .os = { .data = (unsigned char *)_val_, .len = _len_ }}} |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
55 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
56 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
57 static int dict_dcca_starent_entry(char * conffile) |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
58 { |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
59 /* Applications section */ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
60 { |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
61 /* Create the vendors */ |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
62 { |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
63 struct dict_vendor_data vendor_data = { 8164, "Starent" }; |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
64 CHECK_FCT(fd_dict_new(fd_g_config->cnf_dict, DICT_VENDOR, &vendor_data, NULL, NULL)); |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
65 } |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
66 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
67 } |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
68 |
1499
71cc2c59e7dc
move generated AVPs into separate source files
Luke Mewburn <luke@mewburn.net>
parents:
1470
diff
changeset
|
69 extern int add_avps(); |
71cc2c59e7dc
move generated AVPs into separate source files
Luke Mewburn <luke@mewburn.net>
parents:
1470
diff
changeset
|
70 CHECK_FCT( add_avps() ); |
962
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
71 |
1227 | 72 /* Rules section */ |
73 | |
1275
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
74 /* SN-Remaining-Service-Unit */ |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
75 { |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
76 struct dict_object *rule_avp; |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
77 struct dict_avp_request vpa; |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
78 vpa.avp_vendor = 8164; |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
79 vpa.avp_name = "SN-Remaining-Service-Unit"; |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
80 CHECK_dict_search(DICT_AVP, AVP_BY_NAME_AND_VENDOR, &vpa, &rule_avp); |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
81 struct local_rules_definition rules[] = { |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
82 { "Tariff-Change-Usage", RULE_OPTIONAL, -1, 1 }, |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
83 { "CC-Time", RULE_OPTIONAL, -1, 1 }, |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
84 { "CC-Total-Octets", RULE_OPTIONAL, -1, 1 }, |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
85 { "CC-Input-Octets", RULE_OPTIONAL, -1, 1 }, |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
86 { "CC-Output-Octets", RULE_OPTIONAL, -1, 1 }, |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
87 { "CC-Service-Specific-Units", RULE_OPTIONAL, -1, 1 }, |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
88 { "Reporting-Reason", RULE_OPTIONAL, -1, 1 } |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
89 }; |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
90 PARSE_loc_rules( rules, rule_avp ); |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
91 } |
62bd95182f6d
Add more Starent AVPs, from Cisco's v15 documentation. Add one rule.
Thomas Klausner <tk@giga.or.at>
parents:
1227
diff
changeset
|
92 |
1227 | 93 /* SN-Total-Used-Service-Unit */ |
94 { | |
95 struct dict_object *rule_avp; | |
96 struct dict_avp_request vpa; | |
97 vpa.avp_vendor = 8164; | |
98 vpa.avp_name = "SN-Total-Used-Service-Unit"; | |
99 CHECK_dict_search(DICT_AVP, AVP_BY_NAME_AND_VENDOR, &vpa, &rule_avp); | |
100 struct local_rules_definition rules[] = { | |
101 { "Tariff-Change-Usage", RULE_OPTIONAL, -1, 1 }, | |
102 { "CC-Time", RULE_OPTIONAL, -1, 1 }, | |
103 { "CC-Total-Octets", RULE_OPTIONAL, -1, 1 }, | |
104 { "CC-Input-Octets", RULE_OPTIONAL, -1, 1 }, | |
105 { "CC-Output-Octets", RULE_OPTIONAL, -1, 1 }, | |
106 { "CC-Service-Specific-Units", RULE_OPTIONAL, -1, 1 }, | |
107 { "Reporting-Reason", RULE_OPTIONAL, -1, 1 } | |
108 }; | |
109 PARSE_loc_rules( rules, rule_avp ); | |
110 } | |
111 | |
112 /* SN-Usage-Monitoring-Control */ | |
113 { | |
114 struct dict_object *rule_avp; | |
115 struct dict_avp_request vpa; | |
116 vpa.avp_vendor = 8164; | |
117 vpa.avp_name = "SN-Usage-Monitoring-Control"; | |
118 CHECK_dict_search(DICT_AVP, AVP_BY_NAME_AND_VENDOR, &vpa, &rule_avp); | |
119 struct local_rules_definition rules[] = { | |
120 { "SN-Monitoring-Key", RULE_OPTIONAL, -1, 1 }, | |
121 { "SN-Usage-Monitoring", RULE_OPTIONAL, -1, 1 }, | |
122 { "SN-Usage-Volume", RULE_OPTIONAL, -1, 1 }, | |
123 }; | |
124 PARSE_loc_rules( rules, rule_avp ); | |
125 } | |
126 | |
1120
c473581adff2
Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents:
962
diff
changeset
|
127 LOG_D( "Extension 'Dictionary definitions for DCCA Starent' initialized"); |
962
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
128 return 0; |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
129 } |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
130 |
398e9b1ebf87
Add a dictionary for Starent vendor specific AVPs, following publicly available
Thomas Klausner <tk@giga.or.at>
parents:
diff
changeset
|
131 EXTENSION_ENTRY("dict_dcca_starent", dict_dcca_starent_entry, "dict_dcca_3gpp"); |