1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_diameter_stack_Format_hpp
38 #define anna_diameter_stack_Format_hpp
41 #include <anna/diameter/codec/Format.hpp>
43 #include <anna/config/defines.hpp>
44 #include <anna/core/RuntimeException.hpp>
67 //------------------------------------------------------------------------------
68 //----------------------------------------------------------------- class Format
69 //------------------------------------------------------------------------------
71 * Format data container
74 const Dictionary *a_dictionary;
76 std::string a_parentName;
78 void _initialize(const Dictionary *d) throw() {
86 Format(const Dictionary *d = NULL) { _initialize(d); }
93 * Gets the format type name
95 * @return Format type name
97 const std::string & getName(void) const throw() { return a_name; }
100 * Gets the format parent type name
102 * @return Format parent type name, empty string for diameter basic format types (and reserved like 'Any, Unknown')
104 const std::string & getParentName(void) const throw() { return a_parentName; }
109 * Gets the diameter parent type reference
111 * @return Diameter parent type reference, NULL for diameter basic format types (and reserved like 'Any, Unknown')
113 const Format * getParent(void) const throw();
116 * The diameter format is a derived type
118 * @return The format is derived
120 bool isDerived(void) const throw() { return (a_parentName != ""); }
123 * The diameter format is a basic type:
124 * (OctetString, Integer32, Integer64, Unsigned32, Unsigned64, Float32, Float64, Grouped)
126 * @return The format is basic
128 bool isBasic(void) const throw() { return (!isDerived() && !isReserved()); }
131 * Gets the diameter basic format type from which a derived type inherit, or basic type itself for non-derived
133 * @return Diameter basic format type
135 codec::Format::_v getBasicType(void) const throw(anna::RuntimeException);
138 * The diameter format belongs to RFC3588 diameter format family:
139 * (OctetString, Integer32, Integer64, Unsigned32, Unsigned64, Float32, Float64, Grouped, Address, Time, UTF8String, DiameterIdentity, DiameterURI, Enumerated, IPFilterRule, QoSFilterRule)
141 * @return The format belongs to RFC3588
143 bool isRFC3588(void) const throw() { return (codec::Format::isRFC3588(a_name)); }
146 /** @return The format is 'Any' (generic AVP) */
147 bool isAny() const throw() { return (a_name == codec::Format::asText(codec::Format::Any)); }
148 // /** @return The format is 'Unknown' */
149 // bool isUnknown() const throw() { return (a_name == codec::Format::asText(codec::Format::Unknown)); }
152 /** @return The format is 'OctetString' */
153 bool isOctetString() const throw() { return (a_name == codec::Format::asText(codec::Format::OctetString)); }
154 /** @return The format is 'Integer32' */
155 bool isInteger32() const throw() { return (a_name == codec::Format::asText(codec::Format::Integer32)); }
156 /** @return The format is 'Integer64' */
157 bool isInteger64() const throw() { return (a_name == codec::Format::asText(codec::Format::Integer64)); }
158 /** @return The format is 'Unsigned32' */
159 bool isUnsigned32() const throw() { return (a_name == codec::Format::asText(codec::Format::Unsigned32)); }
160 /** @return The format is 'Unsigned64' */
161 bool isUnsigned64() const throw() { return (a_name == codec::Format::asText(codec::Format::Unsigned64)); }
162 /** @return The format is 'Float32' */
163 bool isFloat32() const throw() { return (a_name == codec::Format::asText(codec::Format::Float32)); }
164 /** @return The format is 'Float64' */
165 bool isFloat64() const throw() { return (a_name == codec::Format::asText(codec::Format::Float64)); }
166 /** @return The format is 'Grouped' */
167 bool isGrouped() const throw() { return (a_name == codec::Format::asText(codec::Format::Grouped)); }
168 /** @return The format is 'Address' */
169 bool isAddress() const throw() { return (a_name == codec::Format::asText(codec::Format::Address)); }
170 /** @return The format is 'Time' */
171 bool isTime() const throw() { return (a_name == codec::Format::asText(codec::Format::Time)); }
172 /** @return The format is 'UTF8String' */
173 bool isUTF8String() const throw() { return (a_name == codec::Format::asText(codec::Format::UTF8String)); }
174 /** @return The format is 'DiameterIdentity' */
175 bool isDiameterIdentity() const throw() { return (a_name == codec::Format::asText(codec::Format::DiameterIdentity)); }
176 /** @return The format is 'DiameterURI' */
177 bool isDiameterURI() const throw() { return (a_name == codec::Format::asText(codec::Format::DiameterURI)); }
178 /** @return The format is 'Enumerated' */
179 bool isEnumerated() const throw() { return (a_name == codec::Format::asText(codec::Format::Enumerated)); }
180 /** @return The format is 'IPFilterRule' */
181 bool isIPFilterRule() const throw() { return (a_name == codec::Format::asText(codec::Format::IPFilterRule)); }
182 /** @return The format is 'QoSFilterRule' */
183 bool isQoSFilterRule() const throw() { return (a_name == codec::Format::asText(codec::Format::QoSFilterRule)); }
186 * The diameter format is application-specific or a format type name not registered on dictionary
188 * @return The format is application-specific
190 bool isApplicationSpecific(void) const throw() { return (!isRFC3588() && !isReserved()); }
193 * The diameter format is reserved ('Any' for generic AVP, 'Unknown' for not registered avps)
195 * @return The format is reserved
197 bool isReserved(void) const throw() { return (codec::Format::isReserved(a_name)); }
200 * Class string representation
202 * @return String with class content
204 std::string asString(void) const throw();
207 * Class xml representation
209 * @return XML document with relevant information for this instance.
211 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
216 * @return Equality between two class instances
218 friend bool operator == (const Format & f1, const Format & f2) { return ((f1.getName() == f2.getName())); }
221 * @return Difference between two class instances
223 friend bool operator != (const Format & f1, const Format & f2) { return !(f1 == f2); }
228 * Initializes the class content
230 void initialize(const Dictionary *d = NULL) throw() { _initialize(d); }
233 * Sets Avp format type name
235 * @param type Avp format type name
237 void setName(const char * name) throw(anna::RuntimeException) {
238 if(name == NULL) throw anna::RuntimeException("Null Format-name not allowed", ANNA_FILE_LOCATION);
242 if(a_name == "") throw anna::RuntimeException("Empty Format-name not allowed", ANNA_FILE_LOCATION);
246 * Sets RFC3588 Avp format type name
248 * @param rfc3588Format RFC3588 format type
250 void setRFC3588(codec::Format::_v rfc3588Format) throw() {
251 setName(codec::Format::asText(rfc3588Format));
255 * Sets Diameter-basic avp format parent
257 * @param parent Diameter-basic avp format parent
259 void setParentName(const std::string & parentName) throw(anna::RuntimeException);