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
22 #define DECODE2BYTES_INDX_VALUETYPE(buffer,indx,value_type) ((((value_type)buffer[indx] << 8) & 0xFF00) + ((value_type)buffer[indx+1] & 0x00FF))
23 #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))
24 #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))
26 //#define DECODE2BYTES_VALUETYPE(buffer,value_type) DECODE2BYTES_INDX_VALUETYPE(buffer,0,value_type)
27 //#define DECODE3BYTES_VALUETYPE(buffer,value_type) DECODE3BYTES_INDX_VALUETYPE(buffer,0,value_type)
28 //#define DECODE4BYTES_VALUETYPE(buffer,value_type) DECODE4BYTES_INDX_VALUETYPE(buffer,0,value_type)
33 // type bits (bytes) % Diameter Data typedef
34 // -----------------------------------------------------------------------
35 // unsigned short int 16 (2) hu U16
36 // short int 16 (2) hd S16
37 // unsigned int 32 (4) u Unsigned32 (*) U32
38 // int 32 (4) d Integer32 (*) S32
40 // Integer. Its length traditionally depends on the length of the system's Word type, thus in MSDOS
41 // it is 16 bits long, whereas in 32 bit systems (like Windows 9x/2000/NT and systems that work under
42 // protected mode in x86 systems) it is 32 bits long (4 bytes)
44 // Como está previsto que en algunas máquinas la palabra sea de 16 bits, los enteros serían
45 // de 16 y por ello C contempla: int (serían 16 bits), long int (32), long long int (64). Sin embargo
46 // en la práctica, 'int = long int = 32' y 'long long int = 64'.
48 // (*) Por un mal hábito, representamos enteros de 32 bits con el tipo 'int'/'unsigned int' de
49 // toda la vida, sin darnos cuenta de que en alguna máquina antigua, no tendría 32 bits.
50 // Corregir lo anterior sería tan sencillo como poner S32 = long int (no int),
51 // y U32 = unsigned long int (no unsigned int). Pero no lo vamos a hacer.
53 // El tipo 'long' tiene un tamaño que corresponde con el ancho de palabra del S.O.
54 // En Solaris (palabra de 64) tenemos long = 64 = long long
55 // En linux (palabra de 32) tenemos long = 32, long long = 64
56 // En linux64 (palabra de 64) tenemos long = 64 = long long
58 // unsigned long int 32/64 (4/8) lu
59 // long int 32/64 (4/8) ld
61 // unsigned long long int 64 (8) llu Unsigned64 U64
62 // long long int 64 (8) lld Integer64 S64
66 // long double 80 (10) Lf
69 /** Alias for unsigned char: unsigned integer with 8 bits */
70 typedef unsigned char U8;
72 /** Alias for char: signed integer with 8 bits */
75 /** Alias for unsigned short int: unsigned integer with 16 bits */
76 typedef unsigned short int U16;
78 /** Alias for short int: signed integer with 16 bits */
79 typedef short int S16;
81 /** Alias for unsigned int: unsigned integer with 32 bits */
82 typedef unsigned int U32;
84 /** Alias for int: signed integer with 32 bits */
87 ///** Alias for unsigned long long: unsigned integer with 64 bits */
88 //typedef unsigned long long int U64;
90 ///** Alias for long long: signed integer with 64 bits */
91 //typedef long long int S64;
94 /** Alias for long long: signed integer with 64 bits */
96 /** Alias for unsigned long long: unsigned integer with 64 bits */
97 typedef u_int64_t U64;
100 /** Alias for long long: signed integer with 64 bits */
101 typedef long long int S64;
102 /** Alias for unsigned long long: unsigned integer with 64 bits */
103 typedef unsigned long long int U64;
106 /** Alias for float: floating number with 32 bits (1-8-23) */
109 /** Alias for double: floating number with 64 bits (1-11-52) */
112 /** Alias for unsigned int: unsigned integer with 32 bits used to contain 24 bits */
119 * Typedef for socket literal representation: <ip|hostname>:<port>
121 typedef std::pair <std::string, int> socket_t;
124 * Typedef for sockets (socket_t) vector
126 typedef std::vector<socket_t> socket_v;
127 typedef std::vector<socket_t>::const_iterator socket_v_it;
133 Struct for called and calling party number from Q763 Signalling System No. 7
\96 ISDN user part formats and codes
139 |---------|---------|---------|---------|---------|---------|---------|---------|
140 1 | O/E | Nature of address indicator |
141 |---------|---------|---------|---------|---------|---------|---------|---------|
142 2 | INN | Numbering plan indicator | spare |
143 |---------|---------|---------|---------|---------|---------|---------|---------|
144 3 | 2nd address signal | 1st address signal |
145 |---------|---------|---------|---------|---------|---------|---------|---------|
146 ... ... ... ... ... ... ... ... ...
147 |---------|---------|---------|---------|---------|---------|---------|---------|
148 m | Filler (if necessary) | nth address signal |
149 |---------|---------|---------|---------|---------|---------|---------|---------|
155 |---------|---------|---------|---------|---------|---------|---------|---------|
156 1 | O/E | Nature of address indicator |
157 |---------|---------|---------|---------|---------|---------|---------|---------|
158 2 | NI | Numbering plan indicator |Add.Pres.Restr.Ind | Screening Ind |
159 |---------|---------|---------|---------|---------|---------|---------|---------|
160 3 | 2nd address signal | 1st address signal |
161 |---------|---------|---------|---------|---------|---------|---------|---------|
162 ... ... ... ... ... ... ... ... ...
163 |---------|---------|---------|---------|---------|---------|---------|---------|
164 m | Filler (if necessary) | nth address signal |
165 |---------|---------|---------|---------|---------|---------|---------|---------|
170 /** odd/even (1/0) indicator */
173 /** Return true when have odd number of digits */
174 bool isOdd() { return OddEven; }
175 /** Return true when have even number of digits */
176 bool isEven() { return !isOdd(); }
180 Nature of address indicator
182 0 0 0 0 0 0 1 subscriber number (national use)
183 0 0 0 0 0 1 0 unknown (national use)
184 0 0 0 0 0 1 1 national (significant) number (national use)
185 0 0 0 0 1 0 0 international number
188 0 0 0 0 1 0 1 network-specific number (national use) ITU-T Q.763 (12/1999) 23
189 0 0 0 0 1 1 0 network routing number in national (significant) number format (national use)
190 0 0 0 0 1 1 1 network routing number in network-specific number format (national use)
191 0 0 0 1 0 0 0 network routing number concatenated with Called Directory Number (national use)
192 1 1 0 1 1 1 1 to 0 0 0 1 0 0 1 spare
193 1 1 1 1 1 1 0 to 1 1 1 0 0 0 0 reserved for national use
197 0 0 0 0 1 1 0 to 1 1 0 1 1 1 1 spare
198 1 1 1 0 0 0 0 to 1 1 1 1 1 1 0 reserved for national use
202 short NatureOfAddress;
204 /** Return true when Nature Of Address is 'subscriber number (national use)' */
205 bool NatureOfAddress_SubscriberNumber() { return (NatureOfAddress == 1); }
206 /** Return true when Nature Of Address is 'unknown (national use)' */
207 bool NatureOfAddress_Unknown() { return (NatureOfAddress == 2); }
208 /** Return true when Nature Of Address is 'national (significant) number (national use)' */
209 bool NatureOfAddress_NationalNumber() { return (NatureOfAddress == 3); }
210 /** Return true when Nature Of Address is 'international number' */
211 bool NatureOfAddress_InternationalNumber() { return (NatureOfAddress == 4); }
215 Internal Network Number indicator (INN) (only for called party number)
216 0 routing to internal network number allowed
217 1 routing to internal network number not allowed
220 short InternalNetworkNumber;
222 /** Return true when Internal Network Number Indicator is 'routing to internal network number allowed' */
223 bool InternalNetworkNumber_RoutingToInternalNetworkNumberAllowed() { return (InternalNetworkNumber == 0); }
224 /** Return true when Internal Network Number Indicator is 'routing to internal network number not allowed' */
225 bool InternalNetworkNumber_RoutingToInternalNetworkNumberNotAllowed() { return (InternalNetworkNumber == 1); }
229 Number Incomplete indicator (NI) (only for calling party number)
234 short NumberIncomplete;
236 /** Return true when Number Incomplete Indicator is 'complete' */
237 bool NumberIncomplete_Complete() { return (NumberIncomplete == 0); }
238 /** Return true when Number Incomplete Indicator is 'incomplete' */
239 bool NumberIncomplete_Incomplete() { return (NumberIncomplete == 1); }
243 Numbering plan indicator
245 0 0 1 ISDN (Telephony) numbering plan (ITU-T Recommendation E.164)
247 0 1 1 Data numbering plan (ITU-T Recommendation X.121) (national use)
248 1 0 0 Telex numbering plan (ITU-T Recommendation F.69) (national use)
249 1 0 1 reserved for national use
250 1 1 0 reserved for national use
256 /** Return true when Numbering Plan is 'ISDN (Telephony) numbering plan (ITU-T Recommendation E.164)' */
257 bool NumberingPlan_ISDN() { return (NumberingPlan == 1); }
258 /** Return true when Numbering Plan is 'Data numbering plan (ITU-T Recommendation X.121) (national use)' */
259 bool NumberingPlan_Data() { return (NumberingPlan == 3); }
260 /** Return true when Numbering Plan is 'Telex numbering plan (ITU-T Recommendation F.69) (national use)' */
261 bool NumberingPlan_Telex() { return (NumberingPlan == 4); }
265 Address presentation restricted indicator (only for calling party number)
266 0 0 presentation allowed
267 0 1 presentation restricted
268 1 0 address not available (Note 1) (national use)
269 1 1 reserved for restriction by the network
270 NOTE 1
\96 If the parameter is included and the address presentation restricted indicator indicates
271 address not available, octets 3 to n are omitted, the subfields in items 'OddEven', 'NatureOfAddress',
272 'NumberIncomplete' and 'NumberingPlan' are coded with 0's, and the subfield 'Screening' is coded with 11.
275 short AddressPresentationRestricted;
277 /** Return true when Address Presentation Restricted is 'presentation allowed' */
278 bool AddressPresentationRestricted_PresentationAllowed() { return (AddressPresentationRestricted == 0); }
279 /** Return true when Address Presentation Restricted is 'presentation restricted' */
280 bool AddressPresentationRestricted_PresentationRestricted() { return (AddressPresentationRestricted == 1); }
281 /** Return true when Address Presentation Restricted is 'address not available (Note 1) (national use)' */
282 bool AddressPresentationRestricted_AddressNotAvailable() { return (AddressPresentationRestricted == 2); }
283 /** Return true when Address Presentation Restricted is 'reserved for restriction by the network' */
284 bool AddressPresentationRestricted_ReservedForRestrictionByTheNetwork() { return (AddressPresentationRestricted == 3); }
288 Screening indicator (only for calling party number)
289 0 0 reserved (Note 2)
290 0 1 user provided, verified and passed
291 1 0 reserved (Note 2)
293 NOTE 2
\96 Code 00 and 10 are reserved for "user provided, not verified" and "user provided, verified
294 and failed" respectively. Codes 00 and 10 are for national use.
299 /** Return true when Screening is 'user provided, verified and passed' */
300 bool Screening_UserProvidedVerifiedAndPassed() { return (Screening == 1); }
301 /** Return true when Screening is 'network provided' */
302 bool Screening_NetworkProvided() { return (Screening == 3); }
323 1 1 1 1 ST (for called party number, spare in calling party number)
324 The most significant address signal is sent first. Subsequent address signals are sent in
325 successive 4-bit fields.
327 Filler: In case of an odd number of address signals, the filler code 0000 is inserted after the last
336 InternalNetworkNumber = 0;
337 NumberIncomplete = 0;
339 AddressPresentationRestricted = 0;
345 * Class string representation
347 * @param calledOrCalling Boolean about being called party number or calling one
349 * @return String with class content
351 std::string asString(bool calledOrCalling) {
354 result = "OddEven: ";
355 sprintf(aux, "%d", OddEven); result += std::string(aux);
356 result += " | NatureOfAddress: ";
358 if(calledOrCalling) {
359 sprintf(aux, "%d", NatureOfAddress); result += std::string(aux);
360 result += " | InternalNetworkNumber: ";
362 sprintf(aux, "%d", InternalNetworkNumber); result += std::string(aux);
363 result += " | NumberIncomplete: ";
366 sprintf(aux, "%d", NumberIncomplete); result += std::string(aux);
367 result += " | NumberingPlan: ";
368 sprintf(aux, "%d", NumberingPlan); result += std::string(aux);
370 if(!calledOrCalling) {
371 result += " | AddressPresentationRestricted: ";
372 sprintf(aux, "%d", AddressPresentationRestricted); result += std::string(aux);
373 result += " | Screening: ";
374 sprintf(aux, "%d", Screening); result += std::string(aux);
377 result += " | Digits: ";
378 result += (Digits != "") ? Digits : "<null>";
382 // int getEncodedLength() {
384 // bool filler = OddEven;
385 // bool hasDigits = (Digits.size() > 0);
386 // return (2 + Digits.size()/2 + ((hasDigits && filler) ? 1:0));
389 } isup_number_t; // ISDN user part parameters
393 * IANA Address Family Numbers
394 * @see http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml
398 //Number Description Reference
399 //------ ---------------------------------------------------- ---------
401 IPv4 = 1, //IP (IP version 4)
402 IPv6 = 2, //IP6 (IP version 6)
404 // 4 HDLC (8-bit multidrop)
406 // 6 802 (includes all 802 media plus Ethernet "canonical format")
408 E164 = 8 //E.164 (SMDS, Frame Relay, ATM)
410 // 10 X.121 (X.25, Frame Relay)
415 // 15 E.164 with NSAP format subaddress [UNI-3.1] [Andy_Malis]
416 // 16 DNS (Domain Name System)
417 // 17 Distinguished Name [Charles_Lynn]
418 // 18 AS Number [Charles_Lynn]
419 // 19 XTP over IP version 4 [Mike_Saul]
420 // 20 XTP over IP version 6 [Mike_Saul]
421 // 21 XTP native mode XTP [Mike_Saul]
422 // 22 Fibre Channel World-Wide Port Name [Mark_Bakke]
423 // 23 Fibre Channel World-Wide Node Name [Mark_Bakke]
424 // 24 GWID [Subra_Hegde]
425 // 25 AFI for L2VPN information [RFC4761][RFC6074]
426 // 26-16383 Unassigned
427 // 16384 EIGRP Common Service Family [Donnie_Savage] 2008-05-13
428 // 16385 EIGRP IPv4 Service Family [Donnie_Savage] 2008-05-13
429 // 16386 EIGRP IPv6 Service Family [Donnie_Savage] 2008-05-13
430 // 16387 LISP Canonical Address Format (LCAF) [David_Meyer] 2009-11-12
431 // 16388-32767 Unassigned
432 // 32768-65534 Unassigned
437 * Version description
438 * @param v Version type
439 * @return Version description
441 static const char* asText(const _v v) throw() { // anna_declare_enum is not safe, because labels don't have to match a sequence
442 if(v == IPv4) return "IPv4";
444 if(v == IPv6) return "IPv6";
446 if(v == E164) return "E164";
451 } iana_address_version_t;
455 Struct for IANA Addresses
459 /** address version */
462 /** address printable value. No checkings are done regarding specific version (application responsability) */
466 /** Gets the address version */
467 const U16 & getVersion() const throw() { return Version; }
469 /** Gets the address printable value */
470 const char * getValue() const throw() { return Value.c_str(); }
475 /** Return true when is an IPv4 address */
476 bool isIPv4() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv4); }
477 /** Return true when is an IPv6 address */
478 bool isIPv6() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv6); }
479 /** Return true when is an E164 (SMDS, Frame Relay, ATM) address */
480 bool isE164() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::E164); }
482 /** Sets version for IPv4 address and address itself. Checking is not performed (could assign IPv6 instead ...) */
483 void setIPv4(const char *value) throw() { Version = iana_address_version_t::IPv4; Value = value ? value : ""; }
485 /** Sets version for IPv6 address and address itself. Checking is not performed (could assign IPv4 instead ...) */
486 void setIPv6(const char *value) throw() { Version = iana_address_version_t::IPv6; Value = value ? value : ""; }
488 /** Sets version for E164 address and address itself. Checking is not performed ... */
489 void setE164(const char *value) throw() { Version = iana_address_version_t::E164; Value = value ? value : ""; }
493 * Class string representation
495 * @return String with class content
497 std::string asString() const throw() {
499 result += Value.c_str(); // assume that all IANA addresses have a printable representation
501 const char *versionAsText = iana_address_version_t::asText((iana_address_version_t::_v)Version);
504 result += versionAsText;
508 result += "IANA version '";
510 sprintf(aux, "%d", Version);