1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_diameter_stack_Avp_hpp
10 #define anna_diameter_stack_Avp_hpp
14 #include <anna/diameter/defines.hpp>
15 #include <anna/diameter/stack/AvpRule.hpp>
16 #include <anna/core/util/MultiRangeExpression.hpp>
18 #include <anna/core/RuntimeException.hpp>
19 #include <anna/config/defines.hpp>
43 //typedef std::map<AvpId, AvpRule> avprule_container;
44 typedef std::map < int /*position*/, AvpRule > avprule_container;
45 typedef avprule_container::iterator avprule_iterator;
46 typedef avprule_container::const_iterator const_avprule_iterator;
52 //------------------------------------------------------------------------------
53 //-------------------------------------------------------------------- class Avp
54 //------------------------------------------------------------------------------
56 * Avp Reference information
63 bool operator()(const std::string &d1, const std::string &d2) const {
64 return (atoi(d1.c_str()) < atoi(d2.c_str()));
67 typedef std::map < std::string /* data */, std::string /* alias */, lessLabel > label_container;
68 typedef label_container::iterator label_iterator;
69 typedef label_container::const_iterator const_label_iterator;
75 None = -1, // Initialized
82 anna_declare_enum(FlagRule);
85 * FlagRule description
86 * @param v FlagRule type
87 * @return FlagRule description
89 static const char* asText(const FlagRule::_v v) throw(anna::RuntimeException) {
97 const Dictionary *a_dictionary;
100 std::string a_formatName;
101 std::string a_vendorName;
104 FlagRule::_v a_vBit, a_mBit, a_pBit;
107 MultiRangeExpression a_enums;
108 label_container a_labels;
111 avprule_container a_avprules;
112 bool a_allowFixedRule;
113 int a_avprulePosition;
115 void _initializeEnumsLabelsAndRules() throw() {
116 a_enums.setLiteral("");
119 a_allowFixedRule = true;
120 a_avprulePosition = 0;
123 void _initialize(const Dictionary *d) throw() {
128 a_vBit = FlagRule::mustnot;
129 a_mBit = FlagRule::must;
130 a_pBit = FlagRule::may;
132 _initializeEnumsLabelsAndRules();
137 Avp(const Dictionary *d = NULL) { _initialize(d); }
142 const AvpId & getId(void) const throw() { return a_id; }
143 const std::string & getName(void) const throw() { return a_name; }
144 const std::string & getFormatName(void) const throw() { return a_formatName; }
146 const FlagRule::_v & getVbit(void) const throw() { return a_vBit; }
147 const FlagRule::_v & getMbit(void) const throw() { return a_mBit; }
148 const FlagRule::_v & getPbit(void) const throw() { return a_pBit; }
149 bool mayEncrypt(void) const throw() { return a_mayEncrypt; }
151 const char * getEnums(void) const throw() { return a_enums.getLiteral(); }
152 const char * getAlias(const std::string data) const throw() {
153 std::map<std::string, std::string>::const_iterator it = a_labels.find(data);
154 return ((it != a_labels.end()) ? ((*it).second.c_str()) : NULL);
158 const_avprule_iterator avprule_begin() const throw() { return a_avprules.begin(); }
159 const_avprule_iterator avprule_end() const throw() { return a_avprules.end(); }
160 int avprule_size() const throw() { return a_avprules.size(); }
162 const_label_iterator label_begin() const throw() { return a_labels.begin(); }
163 const_label_iterator label_end() const throw() { return a_labels.end(); }
164 int label_size() const throw() { return a_labels.size(); }
168 bool allowEnum(int value) const throw() { return a_enums.contain(value); }
169 bool hasAliases(void) const throw() { return (a_labels.size() != 0); }
170 bool isChild(const AvpId & avp) const throw();
171 std::string getFlagsDescription(void) const throw();
172 std::string getFlagRulesDescription(void) const throw();
173 const Format * getFormat() const throw();
175 std::string asString(void) const throw();
176 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
181 void setCode(const S32 & c) throw(anna::RuntimeException) {
182 if(c < 0) throw anna::RuntimeException("Negative avp-code not allowed", ANNA_FILE_LOCATION);
187 void setVendorId(const S32 & v) throw(anna::RuntimeException) {
188 if(v < 0) throw anna::RuntimeException("Negative vendor-id not allowed", ANNA_FILE_LOCATION);
193 void setName(const std::string & n) throw(anna::RuntimeException) {
194 if(n == "") throw anna::RuntimeException("Empty avp-name string not allowed", ANNA_FILE_LOCATION);
199 void initialize(const Dictionary *d = NULL) throw() { _initialize(d); }
200 void setVendorName(const std::string & vn) throw() { a_vendorName = vn; }
201 void setFormatName(const std::string & fn) throw() { a_formatName = fn; }
202 void setVbit(const FlagRule::_v &v) throw() { a_vBit = v; }
203 void setMbit(const FlagRule::_v &m) throw() { a_mBit = m; }
204 void setPbit(const FlagRule::_v &p) throw() { a_pBit = p; } // deprecated flag ...
205 void setMayEncrypt(bool me) throw() { a_mayEncrypt = me; }
207 void setEnums(const char * e) throw() { a_enums.setLiteral(e); }
208 void addEnums(const char * e) throw() { a_enums.addLiteral(e); a_enums.simplifyLiteral(); }
210 // After format configuration:
211 void addLabel(const std::string & data, const std::string & alias) throw(anna::RuntimeException);
212 void addAvpRule(const AvpRule & avpRule) throw(anna::RuntimeException);