Remove warnings
[anna.git] / include / anna / diameter / codec / basetypes / Address.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #ifndef anna_diameter_codec_basetypes_Address_hpp
10 #define anna_diameter_codec_basetypes_Address_hpp
11
12
13 // Local
14 #include <anna/diameter/codec/basetypes/OctetString.hpp>
15
16 #include <anna/config/defines.hpp>
17
18
19 namespace anna {
20
21 namespace diameter {
22
23 namespace codec {
24
25 class Avp;
26
27 namespace basetypes {
28
29 /**
30 * Diameter Address container
31 *
32 * Diameter address includes 2 bytes with ip version and 4/16 more for IPv4 and IPv6 respectively
33 *
34 * <pre>
35 *    IPv6 ADDRESS FORMAT CONSIDERATIONS
36 *
37 *      IPv6 addresses have two logical parts: a 64-bit network prefix, and a 64-bit host address part.
38 *      The host address is often automatically generated from the interface MAC address.
39 *      An IPv6 address is represented by 8 groups of 16-bit hexadecimal values separated by colons (:) shown as follows:
40 *
41 *      A typical example of an IPv6 address is
42 *
43 *          2001:0db8:85a3:0000:0000:8a2e:0370:7334.
44 *
45 *      The hexadecimal digits are case-insensitive.
46 *
47 *      The 128-bit IPv6 address can be abbreviated with the following rules:
48 *
49 *          * Rule one: Leading zeroes within a 16-bit value may be omitted. For example, the address fe80:0000:0000:0000:0202:b3ff:fe1e:8329
50 *                      may be written as fe80:0:0:0:202:b3ff:fe1e:8329
51 *
52 *          * Rule two: A single occurrence of consecutive groups of zeroes within an address may be replaced by a double colon.
53 *                      For example, fe80:0:0:0:202:b3ff:fe1e:8329 becomes fe80::202:b3ff:fe1e:8329
54 *
55 *
56 *    RULE ONE IS AUTOMATICALLY APPLIED BY sscanf and %X parsing
57 *    RULE TWO IS NOT APPLIED OVER THIS CLASS METHODS
58 *
59 *
60 *      In environments of dual-stack hosts that support both IPv4 and IPv6, an IPv4 address is expressed as an IPv6 address in an IPv6-mapped address.
61 *      For example, the IPv4-mapped IPv6 address ::ffff:c000:280 is usually written as ::ffff:192.0.2.128, thus expressing clearly the original IPv4
62 *      address that was mapped to IPv6.
63 *
64 *      The address ::ffff:1.2.3.4 is IPv4-mapped, different than address ::1.2.3.4 which is IPV4-compatible.
65 * </pre>
66 */
67 class Address : OctetString {
68
69   iana_address_t a_address;
70   bool a_abbreviatePresentation; // specially for IPv6 address type
71
72
73   // Only for derived diameter type:
74   void updateBasic() throw(anna::RuntimeException);
75
76   void setPrintableString(const char * printableString) throw(anna::RuntimeException);
77
78
79 public:
80
81   /**
82   * Default constructor
83   */
84   Address() : a_abbreviatePresentation(true) {};
85
86   /**
87   * Destructor
88   */
89   virtual ~Address() {;}
90  
91   /**
92   * Presentation mode: abbreviate (i.e. two standard rules applied for IPv6) or expanded (i.e. groups of zeroes on IP address)
93   *
94   * @param abb Abbreviate mode boolean indicator
95   */
96   void setAbbreviatePresentation(bool abb) throw() { a_abbreviatePresentation = abb; };
97
98
99
100   // Class-specific ////////////////////////////////////////////////////////////////////////////////////
101   //
102   /**
103   * Gets the IANA address
104   *
105   * @return IANA address
106   */
107   const iana_address_t& getIANAAddress() const throw() { return a_address; }
108
109   /**
110   * Sets the IANA address
111   *
112   * @param address IANA address
113   */
114   void setIANAAddress(const iana_address_t& address) throw(anna::RuntimeException) { a_address = address; updateBasic(); }
115   //
116   //////////////////////////////////////////////////////////////////////////////////////////////////////
117
118
119   // gets
120
121   std::string getFormatName() const throw() { return "Address"; }
122
123
124   // helpers
125
126   /**
127   * Gets the natural/smart string representation for IANA address
128   * Launch exception when data is not printable: only IPv4 and IPv6 are printable-supported
129   *
130   * @return Natural/smart string representation for IANA address (only IPv4 and IPv6 are printable-supported)
131   */
132   std::string asPrintableString() throw(anna::RuntimeException);
133
134
135   std::string asString() throw(anna::RuntimeException) { return a_address.asString(); }
136
137
138   // sets
139
140   void decode(const char* buffer, const int size) throw(anna::RuntimeException);
141
142
143   // exports /////////////////////////////
144   using AvpData::getSize;
145   using AvpData::code;
146   //using OctetString::asPrintableString;
147   using AvpData::asDataBlockString;
148   using OctetString::asString;
149   using AvpData::asHexString;
150   //using OctetString::decode;
151   using AvpData::fromPrintableString;
152   using AvpData::fromHexString;
153 };
154
155 }
156 }
157 }
158 }
159
160 #endif