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
25 #define DECODE2BYTES_INDX_VALUETYPE(buffer,indx,value_type) ((((value_type)buffer[indx] << 8) & 0xFF00) + ((value_type)buffer[indx+1] & 0x00FF))
26 #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))
27 #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))
29 //#define DECODE2BYTES_VALUETYPE(buffer,value_type) DECODE2BYTES_INDX_VALUETYPE(buffer,0,value_type)
30 //#define DECODE3BYTES_VALUETYPE(buffer,value_type) DECODE3BYTES_INDX_VALUETYPE(buffer,0,value_type)
31 //#define DECODE4BYTES_VALUETYPE(buffer,value_type) DECODE4BYTES_INDX_VALUETYPE(buffer,0,value_type)
42 // TYPE BITS (bytes) Format
43 // ----------------------- ------------------ ---------------------------
44 // unsigned long int 32/64 (4/8) lu
45 // long int 32/64 (4/8) ld
47 // unsigned long long int 64 (8) llu
48 // long long int 64 (8) lld
52 // long double 80 (10) Lf
54 // pointer = S.O. word 32/64 p
57 /** Alias for unsigned integer with 8 bits */
59 typedef unsigned char U8;
61 /** Alias for signed integer with 8 bits */
65 /** Alias for unsigned integer with 16 bits */
68 /** Alias for signed integer with 16 bits */
71 /** Alias for unsigned integer with 32 bits */
74 /** Alias for signed integer with 32 bits */
77 /** Alias for unsigned integer with 64 bits */
80 /** Alias for signed integer with 64 bits */
83 /** Alias for float: floating number with 32 bits (1-8-23) */
86 /** Alias for double: floating number with 64 bits (1-11-52) */
89 /** Alias for long double: floating number with 80 bits (1-15-64) */
90 typedef long double F80;
92 /** Alias for unsigned integer with 32 bits used to contain 24 bits */
99 * Typedef for socket literal representation: <ip|hostname>:<port>
101 typedef std::pair <std::string, int> socket_t;
104 * Typedef for sockets (socket_t) vector
106 typedef std::vector<socket_t> socket_v;
107 typedef std::vector<socket_t>::const_iterator socket_v_it;
113 Struct for called and calling party number from Q763 Signalling System No. 7
\96 ISDN user part formats and codes
119 |---------|---------|---------|---------|---------|---------|---------|---------|
120 1 | O/E | Nature of address indicator |
121 |---------|---------|---------|---------|---------|---------|---------|---------|
122 2 | INN | Numbering plan indicator | spare |
123 |---------|---------|---------|---------|---------|---------|---------|---------|
124 3 | 2nd address signal | 1st address signal |
125 |---------|---------|---------|---------|---------|---------|---------|---------|
126 ... ... ... ... ... ... ... ... ...
127 |---------|---------|---------|---------|---------|---------|---------|---------|
128 m | Filler (if necessary) | nth address signal |
129 |---------|---------|---------|---------|---------|---------|---------|---------|
135 |---------|---------|---------|---------|---------|---------|---------|---------|
136 1 | O/E | Nature of address indicator |
137 |---------|---------|---------|---------|---------|---------|---------|---------|
138 2 | NI | Numbering plan indicator |Add.Pres.Restr.Ind | Screening Ind |
139 |---------|---------|---------|---------|---------|---------|---------|---------|
140 3 | 2nd address signal | 1st address signal |
141 |---------|---------|---------|---------|---------|---------|---------|---------|
142 ... ... ... ... ... ... ... ... ...
143 |---------|---------|---------|---------|---------|---------|---------|---------|
144 m | Filler (if necessary) | nth address signal |
145 |---------|---------|---------|---------|---------|---------|---------|---------|
150 /** odd/even (1/0) indicator */
153 /** Return true when have odd number of digits */
154 bool isOdd() { return OddEven; }
155 /** Return true when have even number of digits */
156 bool isEven() { return !isOdd(); }
160 Nature of address indicator
162 0 0 0 0 0 0 1 subscriber number (national use)
163 0 0 0 0 0 1 0 unknown (national use)
164 0 0 0 0 0 1 1 national (significant) number (national use)
165 0 0 0 0 1 0 0 international number
168 0 0 0 0 1 0 1 network-specific number (national use) ITU-T Q.763 (12/1999) 23
169 0 0 0 0 1 1 0 network routing number in national (significant) number format (national use)
170 0 0 0 0 1 1 1 network routing number in network-specific number format (national use)
171 0 0 0 1 0 0 0 network routing number concatenated with Called Directory Number (national use)
172 1 1 0 1 1 1 1 to 0 0 0 1 0 0 1 spare
173 1 1 1 1 1 1 0 to 1 1 1 0 0 0 0 reserved for national use
177 0 0 0 0 1 1 0 to 1 1 0 1 1 1 1 spare
178 1 1 1 0 0 0 0 to 1 1 1 1 1 1 0 reserved for national use
182 short NatureOfAddress;
184 /** Return true when Nature Of Address is 'subscriber number (national use)' */
185 bool NatureOfAddress_SubscriberNumber() { return (NatureOfAddress == 1); }
186 /** Return true when Nature Of Address is 'unknown (national use)' */
187 bool NatureOfAddress_Unknown() { return (NatureOfAddress == 2); }
188 /** Return true when Nature Of Address is 'national (significant) number (national use)' */
189 bool NatureOfAddress_NationalNumber() { return (NatureOfAddress == 3); }
190 /** Return true when Nature Of Address is 'international number' */
191 bool NatureOfAddress_InternationalNumber() { return (NatureOfAddress == 4); }
195 Internal Network Number indicator (INN) (only for called party number)
196 0 routing to internal network number allowed
197 1 routing to internal network number not allowed
200 short InternalNetworkNumber;
202 /** Return true when Internal Network Number Indicator is 'routing to internal network number allowed' */
203 bool InternalNetworkNumber_RoutingToInternalNetworkNumberAllowed() { return (InternalNetworkNumber == 0); }
204 /** Return true when Internal Network Number Indicator is 'routing to internal network number not allowed' */
205 bool InternalNetworkNumber_RoutingToInternalNetworkNumberNotAllowed() { return (InternalNetworkNumber == 1); }
209 Number Incomplete indicator (NI) (only for calling party number)
214 short NumberIncomplete;
216 /** Return true when Number Incomplete Indicator is 'complete' */
217 bool NumberIncomplete_Complete() { return (NumberIncomplete == 0); }
218 /** Return true when Number Incomplete Indicator is 'incomplete' */
219 bool NumberIncomplete_Incomplete() { return (NumberIncomplete == 1); }
223 Numbering plan indicator
225 0 0 1 ISDN (Telephony) numbering plan (ITU-T Recommendation E.164)
227 0 1 1 Data numbering plan (ITU-T Recommendation X.121) (national use)
228 1 0 0 Telex numbering plan (ITU-T Recommendation F.69) (national use)
229 1 0 1 reserved for national use
230 1 1 0 reserved for national use
236 /** Return true when Numbering Plan is 'ISDN (Telephony) numbering plan (ITU-T Recommendation E.164)' */
237 bool NumberingPlan_ISDN() { return (NumberingPlan == 1); }
238 /** Return true when Numbering Plan is 'Data numbering plan (ITU-T Recommendation X.121) (national use)' */
239 bool NumberingPlan_Data() { return (NumberingPlan == 3); }
240 /** Return true when Numbering Plan is 'Telex numbering plan (ITU-T Recommendation F.69) (national use)' */
241 bool NumberingPlan_Telex() { return (NumberingPlan == 4); }
245 Address presentation restricted indicator (only for calling party number)
246 0 0 presentation allowed
247 0 1 presentation restricted
248 1 0 address not available (Note 1) (national use)
249 1 1 reserved for restriction by the network
250 NOTE 1
\96 If the parameter is included and the address presentation restricted indicator indicates
251 address not available, octets 3 to n are omitted, the subfields in items 'OddEven', 'NatureOfAddress',
252 'NumberIncomplete' and 'NumberingPlan' are coded with 0's, and the subfield 'Screening' is coded with 11.
255 short AddressPresentationRestricted;
257 /** Return true when Address Presentation Restricted is 'presentation allowed' */
258 bool AddressPresentationRestricted_PresentationAllowed() { return (AddressPresentationRestricted == 0); }
259 /** Return true when Address Presentation Restricted is 'presentation restricted' */
260 bool AddressPresentationRestricted_PresentationRestricted() { return (AddressPresentationRestricted == 1); }
261 /** Return true when Address Presentation Restricted is 'address not available (Note 1) (national use)' */
262 bool AddressPresentationRestricted_AddressNotAvailable() { return (AddressPresentationRestricted == 2); }
263 /** Return true when Address Presentation Restricted is 'reserved for restriction by the network' */
264 bool AddressPresentationRestricted_ReservedForRestrictionByTheNetwork() { return (AddressPresentationRestricted == 3); }
268 Screening indicator (only for calling party number)
269 0 0 reserved (Note 2)
270 0 1 user provided, verified and passed
271 1 0 reserved (Note 2)
273 NOTE 2
\96 Code 00 and 10 are reserved for "user provided, not verified" and "user provided, verified
274 and failed" respectively. Codes 00 and 10 are for national use.
279 /** Return true when Screening is 'user provided, verified and passed' */
280 bool Screening_UserProvidedVerifiedAndPassed() { return (Screening == 1); }
281 /** Return true when Screening is 'network provided' */
282 bool Screening_NetworkProvided() { return (Screening == 3); }
303 1 1 1 1 ST (for called party number, spare in calling party number)
304 The most significant address signal is sent first. Subsequent address signals are sent in
305 successive 4-bit fields.
307 Filler: In case of an odd number of address signals, the filler code 0000 is inserted after the last
316 InternalNetworkNumber = 0;
317 NumberIncomplete = 0;
319 AddressPresentationRestricted = 0;
325 * Class string representation
327 * @param calledOrCalling Boolean about being called party number or calling one
329 * @return String with class content
331 std::string asString(bool calledOrCalling) {
334 result = "OddEven: ";
335 sprintf(aux, "%d", OddEven); result += std::string(aux);
336 result += " | NatureOfAddress: ";
338 if(calledOrCalling) {
339 sprintf(aux, "%d", NatureOfAddress); result += std::string(aux);
340 result += " | InternalNetworkNumber: ";
342 sprintf(aux, "%d", InternalNetworkNumber); result += std::string(aux);
343 result += " | NumberIncomplete: ";
346 sprintf(aux, "%d", NumberIncomplete); result += std::string(aux);
347 result += " | NumberingPlan: ";
348 sprintf(aux, "%d", NumberingPlan); result += std::string(aux);
350 if(!calledOrCalling) {
351 result += " | AddressPresentationRestricted: ";
352 sprintf(aux, "%d", AddressPresentationRestricted); result += std::string(aux);
353 result += " | Screening: ";
354 sprintf(aux, "%d", Screening); result += std::string(aux);
357 result += " | Digits: ";
358 result += (Digits != "") ? Digits : "<null>";
362 // int getEncodedLength() {
364 // bool filler = OddEven;
365 // bool hasDigits = (Digits.size() > 0);
366 // return (2 + Digits.size()/2 + ((hasDigits && filler) ? 1:0));
369 } isup_number_t; // ISDN user part parameters
373 * IANA Address Family Numbers
374 * @see http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml
378 //Number Description Reference
379 //------ ---------------------------------------------------- ---------
381 IPv4 = 1, //IP (IP version 4)
382 IPv6 = 2, //IP6 (IP version 6)
384 // 4 HDLC (8-bit multidrop)
386 // 6 802 (includes all 802 media plus Ethernet "canonical format")
388 E164 = 8 //E.164 (SMDS, Frame Relay, ATM)
390 // 10 X.121 (X.25, Frame Relay)
395 // 15 E.164 with NSAP format subaddress [UNI-3.1] [Andy_Malis]
396 // 16 DNS (Domain Name System)
397 // 17 Distinguished Name [Charles_Lynn]
398 // 18 AS Number [Charles_Lynn]
399 // 19 XTP over IP version 4 [Mike_Saul]
400 // 20 XTP over IP version 6 [Mike_Saul]
401 // 21 XTP native mode XTP [Mike_Saul]
402 // 22 Fibre Channel World-Wide Port Name [Mark_Bakke]
403 // 23 Fibre Channel World-Wide Node Name [Mark_Bakke]
404 // 24 GWID [Subra_Hegde]
405 // 25 AFI for L2VPN information [RFC4761][RFC6074]
406 // 26-16383 Unassigned
407 // 16384 EIGRP Common Service Family [Donnie_Savage] 2008-05-13
408 // 16385 EIGRP IPv4 Service Family [Donnie_Savage] 2008-05-13
409 // 16386 EIGRP IPv6 Service Family [Donnie_Savage] 2008-05-13
410 // 16387 LISP Canonical Address Format (LCAF) [David_Meyer] 2009-11-12
411 // 16388-32767 Unassigned
412 // 32768-65534 Unassigned
417 * Version description
418 * @param v Version type
419 * @return Version description
421 static const char* asText(const _v v) throw() { // anna_declare_enum is not safe, because labels don't have to match a sequence
422 if(v == IPv4) return "IPv4";
424 if(v == IPv6) return "IPv6";
426 if(v == E164) return "E164";
431 } iana_address_version_t;
435 Struct for IANA Addresses
439 /** address version */
442 /** address printable value. No checkings are done regarding specific version (application responsability) */
446 /** Gets the address version */
447 const U16 & getVersion() const throw() { return Version; }
449 /** Gets the address printable value */
450 const char * getValue() const throw() { return Value.c_str(); }
455 /** Return true when is an IPv4 address */
456 bool isIPv4() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv4); }
457 /** Return true when is an IPv6 address */
458 bool isIPv6() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv6); }
459 /** Return true when is an E164 (SMDS, Frame Relay, ATM) address */
460 bool isE164() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::E164); }
462 /** Sets version for IPv4 address and address itself. Checking is not performed (could assign IPv6 instead ...) */
463 void setIPv4(const char *value) throw() { Version = iana_address_version_t::IPv4; Value = value ? value : ""; }
465 /** Sets version for IPv6 address and address itself. Checking is not performed (could assign IPv4 instead ...) */
466 void setIPv6(const char *value) throw() { Version = iana_address_version_t::IPv6; Value = value ? value : ""; }
468 /** Sets version for E164 address and address itself. Checking is not performed ... */
469 void setE164(const char *value) throw() { Version = iana_address_version_t::E164; Value = value ? value : ""; }
473 * Class string representation
475 * @return String with class content
477 std::string asString() const throw() {
479 result += Value.c_str(); // assume that all IANA addresses have a printable representation
481 const char *versionAsText = iana_address_version_t::asText((iana_address_version_t::_v)Version);
484 result += versionAsText;
488 result += "IANA version '";
490 sprintf(aux, "%d", Version);