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_core_util_defines_hpp
10 #define anna_core_util_defines_hpp
20 // For cstd0x compatibility we will use stdint.h types instead of std:: ones on cstdint:
21 //#include <cstdint> when C++11 available
23 // For xml representations (xml::Compiler and json::functions::json2xml)
24 #define ANNA_XML_INDENTATION_SPACES 3
28 #define DECODE2BYTES_INDX_VALUETYPE(buffer,indx,value_type) ((((value_type)buffer[indx] << 8) & 0xFF00) + ((value_type)buffer[indx+1] & 0x00FF))
29 #define DECODE3BYTES_INDX_VALUETYPE(buffer,indx,value_type) ((((value_type)buffer[indx] << 16) & 0xFF0000) + (((value_type)buffer[indx+1] << 8) & 0x00FF00) + ((value_type)buffer[indx+2] & 0x0000FF))
30 #define DECODE4BYTES_INDX_VALUETYPE(buffer,indx,value_type) ((((value_type)buffer[indx] << 24) & 0xFF000000) + (((value_type)buffer[indx+1] << 16) & 0x00FF0000) + (((value_type)buffer[indx+2] << 8) & 0x0000FF00) + ((value_type)buffer[indx+3] & 0x000000FF))
32 //#define DECODE2BYTES_VALUETYPE(buffer,value_type) DECODE2BYTES_INDX_VALUETYPE(buffer,0,value_type)
33 //#define DECODE3BYTES_VALUETYPE(buffer,value_type) DECODE3BYTES_INDX_VALUETYPE(buffer,0,value_type)
34 //#define DECODE4BYTES_VALUETYPE(buffer,value_type) DECODE4BYTES_INDX_VALUETYPE(buffer,0,value_type)
45 // TYPE BITS (bytes) Format
46 // ----------------------- ------------------ ---------------------------
47 // unsigned long int 32/64 (4/8) lu
48 // long int 32/64 (4/8) ld
50 // unsigned long long int 64 (8) llu
51 // long long int 64 (8) lld
55 // long double 80 (10) Lf
57 // pointer = S.O. word 32/64 p
60 /** Alias for unsigned integer with 8 bits */
62 typedef unsigned char U8;
64 /** Alias for signed integer with 8 bits */
68 /** Alias for unsigned integer with 16 bits */
71 /** Alias for signed integer with 16 bits */
74 /** Alias for unsigned integer with 32 bits */
77 /** Alias for signed integer with 32 bits */
80 /** Alias for unsigned integer with 64 bits */
83 /** Alias for signed integer with 64 bits */
86 /** Alias for float: floating number with 32 bits (1-8-23) */
89 /** Alias for double: floating number with 64 bits (1-11-52) */
92 /** Alias for long double: floating number with 80 bits (1-15-64) */
93 typedef long double F80;
95 /** Alias for unsigned integer with 32 bits used to contain 24 bits */
102 * Typedef for socket literal representation: <ip|hostname>:<port>
104 typedef std::pair <std::string, int> socket_t;
107 * Typedef for sockets (socket_t) vector
109 typedef std::vector<socket_t> socket_v;
110 typedef std::vector<socket_t>::const_iterator socket_v_it;
116 Struct for called and calling party number from Q763 Signalling System No. 7
\96 ISDN user part formats and codes
122 |---------|---------|---------|---------|---------|---------|---------|---------|
123 1 | O/E | Nature of address indicator |
124 |---------|---------|---------|---------|---------|---------|---------|---------|
125 2 | INN | Numbering plan indicator | spare |
126 |---------|---------|---------|---------|---------|---------|---------|---------|
127 3 | 2nd address signal | 1st address signal |
128 |---------|---------|---------|---------|---------|---------|---------|---------|
129 ... ... ... ... ... ... ... ... ...
130 |---------|---------|---------|---------|---------|---------|---------|---------|
131 m | Filler (if necessary) | nth address signal |
132 |---------|---------|---------|---------|---------|---------|---------|---------|
138 |---------|---------|---------|---------|---------|---------|---------|---------|
139 1 | O/E | Nature of address indicator |
140 |---------|---------|---------|---------|---------|---------|---------|---------|
141 2 | NI | Numbering plan indicator |Add.Pres.Restr.Ind | Screening Ind |
142 |---------|---------|---------|---------|---------|---------|---------|---------|
143 3 | 2nd address signal | 1st address signal |
144 |---------|---------|---------|---------|---------|---------|---------|---------|
145 ... ... ... ... ... ... ... ... ...
146 |---------|---------|---------|---------|---------|---------|---------|---------|
147 m | Filler (if necessary) | nth address signal |
148 |---------|---------|---------|---------|---------|---------|---------|---------|
153 /** odd/even (1/0) indicator */
156 /** Return true when have odd number of digits */
157 bool isOdd() { return OddEven; }
158 /** Return true when have even number of digits */
159 bool isEven() { return !isOdd(); }
163 Nature of address indicator
165 0 0 0 0 0 0 1 subscriber number (national use)
166 0 0 0 0 0 1 0 unknown (national use)
167 0 0 0 0 0 1 1 national (significant) number (national use)
168 0 0 0 0 1 0 0 international number
171 0 0 0 0 1 0 1 network-specific number (national use) ITU-T Q.763 (12/1999) 23
172 0 0 0 0 1 1 0 network routing number in national (significant) number format (national use)
173 0 0 0 0 1 1 1 network routing number in network-specific number format (national use)
174 0 0 0 1 0 0 0 network routing number concatenated with Called Directory Number (national use)
175 1 1 0 1 1 1 1 to 0 0 0 1 0 0 1 spare
176 1 1 1 1 1 1 0 to 1 1 1 0 0 0 0 reserved for national use
180 0 0 0 0 1 1 0 to 1 1 0 1 1 1 1 spare
181 1 1 1 0 0 0 0 to 1 1 1 1 1 1 0 reserved for national use
185 short NatureOfAddress;
187 /** Return true when Nature Of Address is 'subscriber number (national use)' */
188 bool NatureOfAddress_SubscriberNumber() { return (NatureOfAddress == 1); }
189 /** Return true when Nature Of Address is 'unknown (national use)' */
190 bool NatureOfAddress_Unknown() { return (NatureOfAddress == 2); }
191 /** Return true when Nature Of Address is 'national (significant) number (national use)' */
192 bool NatureOfAddress_NationalNumber() { return (NatureOfAddress == 3); }
193 /** Return true when Nature Of Address is 'international number' */
194 bool NatureOfAddress_InternationalNumber() { return (NatureOfAddress == 4); }
198 Internal Network Number indicator (INN) (only for called party number)
199 0 routing to internal network number allowed
200 1 routing to internal network number not allowed
203 short InternalNetworkNumber;
205 /** Return true when Internal Network Number Indicator is 'routing to internal network number allowed' */
206 bool InternalNetworkNumber_RoutingToInternalNetworkNumberAllowed() { return (InternalNetworkNumber == 0); }
207 /** Return true when Internal Network Number Indicator is 'routing to internal network number not allowed' */
208 bool InternalNetworkNumber_RoutingToInternalNetworkNumberNotAllowed() { return (InternalNetworkNumber == 1); }
212 Number Incomplete indicator (NI) (only for calling party number)
217 short NumberIncomplete;
219 /** Return true when Number Incomplete Indicator is 'complete' */
220 bool NumberIncomplete_Complete() { return (NumberIncomplete == 0); }
221 /** Return true when Number Incomplete Indicator is 'incomplete' */
222 bool NumberIncomplete_Incomplete() { return (NumberIncomplete == 1); }
226 Numbering plan indicator
228 0 0 1 ISDN (Telephony) numbering plan (ITU-T Recommendation E.164)
230 0 1 1 Data numbering plan (ITU-T Recommendation X.121) (national use)
231 1 0 0 Telex numbering plan (ITU-T Recommendation F.69) (national use)
232 1 0 1 reserved for national use
233 1 1 0 reserved for national use
239 /** Return true when Numbering Plan is 'ISDN (Telephony) numbering plan (ITU-T Recommendation E.164)' */
240 bool NumberingPlan_ISDN() { return (NumberingPlan == 1); }
241 /** Return true when Numbering Plan is 'Data numbering plan (ITU-T Recommendation X.121) (national use)' */
242 bool NumberingPlan_Data() { return (NumberingPlan == 3); }
243 /** Return true when Numbering Plan is 'Telex numbering plan (ITU-T Recommendation F.69) (national use)' */
244 bool NumberingPlan_Telex() { return (NumberingPlan == 4); }
248 Address presentation restricted indicator (only for calling party number)
249 0 0 presentation allowed
250 0 1 presentation restricted
251 1 0 address not available (Note 1) (national use)
252 1 1 reserved for restriction by the network
253 NOTE 1
\96 If the parameter is included and the address presentation restricted indicator indicates
254 address not available, octets 3 to n are omitted, the subfields in items 'OddEven', 'NatureOfAddress',
255 'NumberIncomplete' and 'NumberingPlan' are coded with 0's, and the subfield 'Screening' is coded with 11.
258 short AddressPresentationRestricted;
260 /** Return true when Address Presentation Restricted is 'presentation allowed' */
261 bool AddressPresentationRestricted_PresentationAllowed() { return (AddressPresentationRestricted == 0); }
262 /** Return true when Address Presentation Restricted is 'presentation restricted' */
263 bool AddressPresentationRestricted_PresentationRestricted() { return (AddressPresentationRestricted == 1); }
264 /** Return true when Address Presentation Restricted is 'address not available (Note 1) (national use)' */
265 bool AddressPresentationRestricted_AddressNotAvailable() { return (AddressPresentationRestricted == 2); }
266 /** Return true when Address Presentation Restricted is 'reserved for restriction by the network' */
267 bool AddressPresentationRestricted_ReservedForRestrictionByTheNetwork() { return (AddressPresentationRestricted == 3); }
271 Screening indicator (only for calling party number)
272 0 0 reserved (Note 2)
273 0 1 user provided, verified and passed
274 1 0 reserved (Note 2)
276 NOTE 2
\96 Code 00 and 10 are reserved for "user provided, not verified" and "user provided, verified
277 and failed" respectively. Codes 00 and 10 are for national use.
282 /** Return true when Screening is 'user provided, verified and passed' */
283 bool Screening_UserProvidedVerifiedAndPassed() { return (Screening == 1); }
284 /** Return true when Screening is 'network provided' */
285 bool Screening_NetworkProvided() { return (Screening == 3); }
306 1 1 1 1 ST (for called party number, spare in calling party number)
307 The most significant address signal is sent first. Subsequent address signals are sent in
308 successive 4-bit fields.
310 Filler: In case of an odd number of address signals, the filler code 0000 is inserted after the last
319 InternalNetworkNumber = 0;
320 NumberIncomplete = 0;
322 AddressPresentationRestricted = 0;
328 * Class string representation
330 * @param calledOrCalling Boolean about being called party number or calling one
332 * @return String with class content
334 std::string asString(bool calledOrCalling) {
337 result = "OddEven: ";
338 sprintf(aux, "%d", OddEven); result += std::string(aux);
339 result += " | NatureOfAddress: ";
341 if(calledOrCalling) {
342 sprintf(aux, "%d", NatureOfAddress); result += std::string(aux);
343 result += " | InternalNetworkNumber: ";
345 sprintf(aux, "%d", InternalNetworkNumber); result += std::string(aux);
346 result += " | NumberIncomplete: ";
349 sprintf(aux, "%d", NumberIncomplete); result += std::string(aux);
350 result += " | NumberingPlan: ";
351 sprintf(aux, "%d", NumberingPlan); result += std::string(aux);
353 if(!calledOrCalling) {
354 result += " | AddressPresentationRestricted: ";
355 sprintf(aux, "%d", AddressPresentationRestricted); result += std::string(aux);
356 result += " | Screening: ";
357 sprintf(aux, "%d", Screening); result += std::string(aux);
360 result += " | Digits: ";
361 result += (Digits != "") ? Digits : "<null>";
365 // int getEncodedLength() {
367 // bool filler = OddEven;
368 // bool hasDigits = (Digits.size() > 0);
369 // return (2 + Digits.size()/2 + ((hasDigits && filler) ? 1:0));
372 } isup_number_t; // ISDN user part parameters
376 * IANA Address Family Numbers
377 * @see http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml
381 //Number Description Reference
382 //------ ---------------------------------------------------- ---------
384 IPv4 = 1, //IP (IP version 4)
385 IPv6 = 2, //IP6 (IP version 6)
387 // 4 HDLC (8-bit multidrop)
389 // 6 802 (includes all 802 media plus Ethernet "canonical format")
391 E164 = 8 //E.164 (SMDS, Frame Relay, ATM)
393 // 10 X.121 (X.25, Frame Relay)
398 // 15 E.164 with NSAP format subaddress [UNI-3.1] [Andy_Malis]
399 // 16 DNS (Domain Name System)
400 // 17 Distinguished Name [Charles_Lynn]
401 // 18 AS Number [Charles_Lynn]
402 // 19 XTP over IP version 4 [Mike_Saul]
403 // 20 XTP over IP version 6 [Mike_Saul]
404 // 21 XTP native mode XTP [Mike_Saul]
405 // 22 Fibre Channel World-Wide Port Name [Mark_Bakke]
406 // 23 Fibre Channel World-Wide Node Name [Mark_Bakke]
407 // 24 GWID [Subra_Hegde]
408 // 25 AFI for L2VPN information [RFC4761][RFC6074]
409 // 26-16383 Unassigned
410 // 16384 EIGRP Common Service Family [Donnie_Savage] 2008-05-13
411 // 16385 EIGRP IPv4 Service Family [Donnie_Savage] 2008-05-13
412 // 16386 EIGRP IPv6 Service Family [Donnie_Savage] 2008-05-13
413 // 16387 LISP Canonical Address Format (LCAF) [David_Meyer] 2009-11-12
414 // 16388-32767 Unassigned
415 // 32768-65534 Unassigned
420 * Version description
421 * @param v Version type
422 * @return Version description
424 static const char* asText(const _v v) throw() { // anna_declare_enum is not safe, because labels don't have to match a sequence
425 if(v == IPv4) return "IPv4";
427 if(v == IPv6) return "IPv6";
429 if(v == E164) return "E164";
434 } iana_address_version_t;
438 Struct for IANA Addresses
442 /** address version */
445 /** address printable value. No checkings are done regarding specific version (application responsability) */
449 /** Gets the address version */
450 const U16 & getVersion() const throw() { return Version; }
452 /** Gets the address printable value */
453 const char * getValue() const throw() { return Value.c_str(); }
458 /** Return true when is an IPv4 address */
459 bool isIPv4() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv4); }
460 /** Return true when is an IPv6 address */
461 bool isIPv6() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv6); }
462 /** Return true when is an E164 (SMDS, Frame Relay, ATM) address */
463 bool isE164() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::E164); }
465 /** Sets version for IPv4 address and address itself. Checking is not performed (could assign IPv6 instead ...) */
466 void setIPv4(const char *value) throw() { Version = iana_address_version_t::IPv4; Value = value ? value : ""; }
468 /** Sets version for IPv6 address and address itself. Checking is not performed (could assign IPv4 instead ...) */
469 void setIPv6(const char *value) throw() { Version = iana_address_version_t::IPv6; Value = value ? value : ""; }
471 /** Sets version for E164 address and address itself. Checking is not performed ... */
472 void setE164(const char *value) throw() { Version = iana_address_version_t::E164; Value = value ? value : ""; }
476 * Class string representation
478 * @return String with class content
480 std::string asString() const throw() {
482 result += Value.c_str(); // assume that all IANA addresses have a printable representation
484 const char *versionAsText = iana_address_version_t::asText((iana_address_version_t::_v)Version);
487 result += versionAsText;
491 result += "IANA version '";
493 sprintf(aux, "%d", Version);