Yate
yateiax.h
1
20
21#ifndef __YATEIAX_H
22#define __YATEIAX_H
23
24#include <yateclass.h>
25
26#ifdef _WINDOWS
27
28#ifdef LIBYIAX_EXPORTS
29#define YIAX_API __declspec(dllexport)
30#else
31#ifndef LIBYIAX_STATIC
32#define YIAX_API __declspec(dllimport)
33#endif
34#endif
35
36#endif /* _WINDOWS */
37
38#ifndef YIAX_API
39#define YIAX_API
40#endif
41
45namespace TelEngine {
46
47class IAXInfoElement; // A single IAX2 Information Element
48class IAXInfoElementString; // A single IAX2 text Information Element
49class IAXInfoElementNumeric; // A single IAX2 numeric Information Element
50class IAXInfoElementBinary; // A single IAX2 numeric Information Element
51class IAXIEList; // Information Element container
52class IAXAuthMethod; // Wrapper class for authentication methods values
53class IAXFormatDesc; // IAX format description
54class IAXFormat; // Wrapper class for formats
55class IAXControl; // Wrapper class for subclasses of frames of type IAX
56class IAXFrame; // This class holds an IAX frame
57class IAXFullFrame; // This class holds an IAX full frame
58class IAXFrameOut; // This class holds an outgoing IAX full frame
59class IAXTrunkInfo; // Trunk info
60class IAXMetaTrunkFrame; // Meta trunk frame
61class IAXMediaData; // IAX2 transaction media data
62class IAXTransaction; // An IAX2 transaction
63class IAXEvent; // Event class
64class IAXEngine; // IAX engine
65
66#define IAX_PROTOCOL_VERSION 0x0002 // Protocol version
67#define IAX2_MAX_CALLNO 32767 // Max call number value
68#define IAX2_MAX_TRANSINFRAMELIST 127 // Max transaction incoming frame list
69
70// Trunk frame header length
71#define IAX2_TRUNKFRAME_HEADERLENGTH 8
72// Trunk frame length
73#define IAX2_TRUNKFRAME_LEN_MIN 20 // 16 bytes: meta header + miniframe with timestamps header
74#define IAX2_TRUNKFRAME_LEN_DEF 1400
75// Trunk frame send interval in milliseconds
76#define IAX2_TRUNKFRAME_SEND_MIN 5
77#define IAX2_TRUNKFRAME_SEND_DEF 20
78
79// Frame retransmission
80#define IAX2_RETRANS_COUNT_MIN 1
81#define IAX2_RETRANS_COUNT_MAX 10
82#define IAX2_RETRANS_COUNT_DEF 4
83#define IAX2_RETRANS_INTERVAL_MIN 200
84#define IAX2_RETRANS_INTERVAL_MAX 5000
85#define IAX2_RETRANS_INTERVAL_DEF 500
86
87// Ping
88#define IAX2_PING_INTERVAL_MIN 10000
89#define IAX2_PING_INTERVAL_DEF 20000
90
91// Sent challenge timeout
92#define IAX2_CHALLENGETOUT_MIN 5000
93#define IAX2_CHALLENGETOUT_DEF 30000
94
99class YIAX_API IAXInfoElement : public RefObject
100{
101public:
105 enum Type {
106 textframe = 0x00, // Text Used internally only to generate an event of type Text
107 CALLED_NUMBER = 0x01, // Text
108 CALLING_NUMBER = 0x02, // Text
109 CALLING_ANI = 0x03, // Text
110 CALLING_NAME = 0x04, // Text
111 CALLED_CONTEXT = 0x05, // Text
112 USERNAME = 0x06, // Text
113 PASSWORD = 0x07, // Text
114 CAPABILITY = 0x08, // DW
115 FORMAT = 0x09, // DW
116 LANGUAGE = 0x0a, // Text
117 VERSION = 0x0b, // W Value: IAX_PROTOCOL_VERSION
118 ADSICPE = 0x0c, // W
119 DNID = 0x0d, // Text
120 AUTHMETHODS = 0x0e, // W
121 CHALLENGE = 0x0f, // Text
122 MD5_RESULT = 0x10, // Text
123 RSA_RESULT = 0x11, // Text
124 APPARENT_ADDR = 0x12, // BIN
125 REFRESH = 0x13, // W
126 DPSTATUS = 0x14, // W
127 CALLNO = 0x15, // W Max value: IAX2_MAX_CALLNO
128 CAUSE = 0x16, // Text
129 IAX_UNKNOWN = 0x17, // B
130 MSGCOUNT = 0x18, // W
131 AUTOANSWER = 0x19, // Null
132 MUSICONHOLD = 0x1a, // Text
133 TRANSFERID = 0x1b, // DW
134 RDNIS = 0x1c, // Text
135 PROVISIONING = 0x1d, // BIN
136 AESPROVISIONING = 0x1e, // BIN
137 DATETIME = 0x1f, // DW
138 DEVICETYPE = 0x20, // Text
139 SERVICEIDENT = 0x21, // BIN
140 FIRMWAREVER = 0x22, // W
141 FWBLOCKDESC = 0x23, // DW
142 FWBLOCKDATA = 0x24, // BIN
143 PROVVER = 0x25, // DW
144 CALLINGPRES = 0x26, // B
145 CALLINGTON = 0x27, // B
146 CALLINGTNS = 0x28, // W
147 SAMPLINGRATE = 0x29, // DW
148 CAUSECODE = 0x2a, // B
149 ENCRYPTION = 0x2b, // B
150 ENKEY = 0x2c, // BIN
151 CODEC_PREFS = 0x2d, // Text
152 RR_JITTER = 0x2e, // DW
153 RR_LOSS = 0x2f, // DW
154 RR_PKTS = 0x30, // DW
155 RR_DELAY = 0x31, // W
156 RR_DROPPED = 0x32, // DW
157 RR_OOO = 0x33, // DW
158 CALLTOKEN = 0x36, // BIN
159 CAPABILITY2 = 0x37, // BIN 1 byte version + array
160 FORMAT2 = 0x38, // BIN 1 byte version + array
161 };
162
167 inline IAXInfoElement(Type type) : m_type(type) {}
168
172 virtual ~IAXInfoElement() {}
173
178 inline Type type() const
179 { return m_type; }
180
185 virtual void toBuffer(DataBlock& buf);
186
191 virtual void toString(String& buf);
192
198 static inline const char* ieText(u_int8_t ieCode)
199 { return lookup(ieCode,s_ieData); }
200
206 static inline const char* causeName(int code)
207 { return lookup(code,s_causeName); }
208
215 static inline int causeCode(const char* name, int defVal = 0)
216 { return lookup(name,s_causeName,defVal); }
217
221 static const TokenDict s_causeName[];
222
226 static const TokenDict s_typeOfNumber[];
227
231 static const TokenDict s_presentation[];
232
236 static const TokenDict s_screening[];
237
238private:
239 static const TokenDict s_ieData[];// Association between IE type and text
240 Type m_type; // Type of this IE
241};
242
248{
249public:
256 inline IAXInfoElementString(Type type, const char* buf, unsigned len) : IAXInfoElement(type), m_strData(buf,(int)len)
257 {}
258
263
268 inline int length() const
269 { return m_strData.length(); }
270
275 inline String& data()
276 { return m_strData; }
277
282 virtual void toBuffer(DataBlock& buf);
283
288 virtual void toString(String& buf)
289 { buf << m_strData; }
290
291private:
292 String m_strData; // IE text data
293};
294
300{
301public:
308 IAXInfoElementNumeric(Type type, u_int32_t val, u_int8_t len);
309
314
319 inline int length() const
320 { return m_length; }
321
326 inline u_int32_t data() const
327 { return m_numericData; }
328
333 virtual void toBuffer(DataBlock& buf);
334
339 virtual void toString(String& buf);
340
341private:
342 u_int8_t m_length; // IE data length
343 u_int32_t m_numericData; // IE numeric data
344};
345
351{
352public:
359 IAXInfoElementBinary(Type type, unsigned char* buf, unsigned len) : IAXInfoElement(type), m_data(buf,len)
360 {}
361
366
371 inline int length() const
372 { return m_data.length(); }
373
378 inline DataBlock& data()
379 { return m_data; }
380
386 inline void setData(void* buf, unsigned len)
387 { m_data.assign(buf,len); }
388
393 virtual void toBuffer(DataBlock& buf);
394
401
408 static bool unpackIP(SocketAddr& addr, IAXInfoElementBinary* ie);
409
414 virtual void toString(String& buf);
415
416private:
417 DataBlock m_data; // IE binary data
418};
419
424class YIAX_API IAXIEList
425{
426public:
431
437 IAXIEList(const IAXFullFrame* frame, bool incoming = true);
438
443
448 inline bool invalidIEList() const
449 { return m_invalidIEList; }
450
454 inline void clear()
455 { m_list.clear(); }
456
461 inline bool empty()
462 { return 0 == m_list.skipNull(); }
463
468
473 inline bool validVersion() {
474 u_int32_t ver = 0xFFFF;
475 getNumeric(IAXInfoElement::VERSION,ver);
476 return ver == IAX_PROTOCOL_VERSION;
477 }
478
483 inline void appendIE(IAXInfoElement* ie)
484 { m_list.append(ie); }
485
492 inline bool appendIE(IAXIEList& src, IAXInfoElement::Type type) {
493 IAXInfoElement* ie = src.getIE(type,true);
494 if (ie)
495 appendIE(ie);
496 return ie != 0;
497 }
498
504 { m_list.append(new IAXInfoElement(type)); }
505
511 inline void appendString(IAXInfoElement::Type type, const String& src)
512 { m_list.append(new IAXInfoElementString(type,src.c_str(),src.length())); }
513
520 inline void appendString(IAXInfoElement::Type type, unsigned char* src, unsigned len)
521 { m_list.append(new IAXInfoElementString(type,(char*)src,len)); }
522
529 inline void appendNumeric(IAXInfoElement::Type type, u_int32_t value, u_int8_t len)
530 { m_list.append(new IAXInfoElementNumeric(type,value,len)); }
531
538 inline void appendBinary(IAXInfoElement::Type type, unsigned char* data, unsigned len)
539 { m_list.append(new IAXInfoElementBinary(type,data,len)); }
540
548 bool createFromFrame(const IAXFullFrame* frame, bool incoming = true);
549
554 void toBuffer(DataBlock& buf);
555
561 void toString(String& dest, const char* indent = 0);
562
569 IAXInfoElement* getIE(IAXInfoElement::Type type, bool remove = false);
570
578
585 bool getNumeric(IAXInfoElement::Type type, u_int32_t& dest);
586
594
595private:
596 bool m_invalidIEList; // Invalid IE flag
597 ObjList m_list; // The IE list
598};
599
604class YIAX_API IAXAuthMethod
605{
606public:
610 enum Type {
611 Text = 1,
612 MD5 = 2,
613 RSA = 4,
614 };
615
622 static void authList(String& dest, u_int16_t auth, char sep);
623
624 static TokenDict s_texts[];
625};
626
627
632class YIAX_API IAXFormatDesc
633{
634public:
639 : m_format(0), m_multiplier(1)
640 {}
641
646 inline u_int32_t format() const
647 { return m_format; }
648
653 inline unsigned int multiplier() const
654 { return m_multiplier; }
655
661 void setFormat(u_int32_t fmt, int type);
662
663protected:
664 u_int32_t m_format; // The format
665 unsigned int m_multiplier; // Format multiplier derived from sampling rate
666};
667
672class YIAX_API IAXFormat
673{
674public:
678 enum Formats {
679 G723_1 = (1 << 0),
680 GSM = (1 << 1),
681 ULAW = (1 << 2),
682 ALAW = (1 << 3),
683 G726 = (1 << 4),
684 ADPCM = (1 << 5),
685 SLIN = (1 << 6),
686 LPC10 = (1 << 7),
687 G729 = (1 << 8),
688 SPEEX = (1 << 9),
689 ILBC = (1 << 10),
690 G726AAL2 = (1 << 11),
691 G722 = (1 << 12),
692 AMR = (1 << 13),
693 // NOTE: GSM Half Rate is not defined in RFC5456
694 GSM_HR = (1 << 31),
695 AudioMask = G723_1 | GSM | ULAW | ALAW | G726 | ADPCM | SLIN | LPC10 | G729 | SPEEX |
696 ILBC | G726AAL2 | G722 | AMR | GSM_HR,
697 JPEG = (1 << 16),
698 PNG = (1 << 17),
699 ImageMask = JPEG | PNG,
700 H261 = (1 << 18),
701 H263 = (1 << 19),
702 H263p = (1 << 20),
703 H264 = (1 << 21),
704 VideoMask = H261 | H263 | H263p | H264,
705 };
706
710 enum Media {
711 Audio = 0,
712 Video,
713 Image,
714 TypeCount
715 };
716
721 inline IAXFormat(int type = Audio)
722 : m_type(type)
723 {}
724
729 inline int type() const
730 { return m_type; }
731
736 inline u_int32_t format() const
737 { return m_format.format(); }
738
743 inline u_int32_t in() const
744 { return m_formatIn.format(); }
745
750 inline u_int32_t out() const
751 { return m_formatOut.format(); }
752
758 inline const IAXFormatDesc& formatDesc(bool in) const
759 { return in ? m_formatIn : m_formatOut; }
760
765 inline const char* formatName() const
766 { return formatName(format()); }
767
772 inline const char* typeName() const
773 { return typeName(m_type); }
774
781 void set(u_int32_t* fmt, u_int32_t* fmtIn, u_int32_t* fmtOut);
782
790 static void formatList(String& dest, u_int32_t formats, const TokenDict* dict = 0,
791 const char* sep = ",");
792
799 static u_int32_t pickFormat(u_int32_t formats, u_int32_t format = 0);
800
808 static u_int32_t encode(const String& formats, const TokenDict* dict, char sep = ',');
809
816 static inline u_int32_t mask(u_int32_t value, int type) {
817 if (type == Audio)
818 return value & AudioMask;
819 if (type == Video)
820 return value & VideoMask;
821 if (type == Image)
822 return value & ImageMask;
823 return 0;
824 }
825
832 static inline u_int32_t clear(u_int32_t value, int type) {
833 if (type == Audio)
834 return value & ~AudioMask;
835 if (type == Video)
836 return value & ~VideoMask;
837 if (type == Image)
838 return value & ~ImageMask;
839 return value;
840 }
841
847 static inline const char* formatName(u_int32_t fmt)
848 { return lookup(fmt,s_formats); }
849
855 static inline const char* typeName(int type)
856 { return lookup(type,s_types); }
857
863 static inline const String& typeNameStr(int type)
864 { return s_typesList[type]; }
865
869 static const TokenDict s_formats[];
870
874 static const TokenDict s_types[];
875
879 static const String s_typesList[TypeCount];
880
881protected:
882 int m_type;
883 IAXFormatDesc m_format;
884 IAXFormatDesc m_formatIn;
885 IAXFormatDesc m_formatOut;
886};
887
892class YIAX_API IAXControl
893{
894public:
898 enum Type {
899 New = 0x01,
900 Ping = 0x02,
901 Pong = 0x03,
902 Ack = 0x04,
903 Hangup = 0x05,
904 Reject = 0x06,
905 Accept = 0x07,
906 AuthReq = 0x08,
907 AuthRep = 0x09,
908 Inval = 0x0a,
909 LagRq = 0x0b,
910 LagRp = 0x0c,
911 RegReq = 0x0d,
912 RegAuth = 0x0e,
913 RegAck = 0x0f,
914 RegRej = 0x10,
915 RegRel = 0x11,
916 VNAK = 0x12,
917 DpReq = 0x13,
918 DpRep = 0x14,
919 Dial = 0x15,
920 TxReq = 0x16,
921 TxCnt = 0x17,
922 TxAcc = 0x18,
923 TxReady = 0x19,
924 TxRel = 0x1a,
925 TxRej = 0x1b,
926 Quelch = 0x1c,
927 Unquelch = 0x1d,
928 Poke = 0x1e,
929 //Reserved = 0x1f,
930 MWI = 0x20,
931 Unsupport = 0x21,
932 Transfer = 0x22,
933 Provision = 0x23,
934 FwDownl = 0x24,
935 FwData = 0x25,
936 CallToken = 0x28,
937 };
938
944 static inline const char* typeText(int type)
945 { return lookup(type,s_types,0); }
946
947private:
948 static TokenDict s_types[]; // Keep the association between IAX control codes and their name
949};
950
955class YIAX_API IAXFrame : public RefObject
956{
957public:
961 enum Type {
962 DTMF = 0x01,
963 Voice = 0x02,
964 Video = 0x03,
965 Control = 0x04,
966 Null = 0x05,
967 IAX = 0x06,
968 Text = 0x07,
969 Image = 0x08,
970 HTML = 0x09,
971 Noise = 0x0a,
972 };
973
984 IAXFrame(Type type, u_int16_t sCallNo, u_int32_t tStamp, bool retrans,
985 const unsigned char* buf, unsigned int len, bool mark = false);
986
990 virtual ~IAXFrame();
991
996 inline Type type() const
997 { return m_type; }
998
1003 inline DataBlock& data()
1004 { return m_data; }
1005
1010 inline bool retrans() const
1011 { return m_retrans; }
1012
1017 inline u_int16_t sourceCallNo() const
1018 { return m_sCallNo; }
1019
1024 inline u_int32_t timeStamp() const
1025 { return m_tStamp; }
1026
1031 inline bool mark() const
1032 { return m_mark; }
1033
1039
1048 static IAXFrame* parse(const unsigned char* buf, unsigned int len, IAXEngine* engine = 0, const SocketAddr* addr = 0);
1049
1058 static inline void buildMiniFrame(DataBlock& dest, u_int16_t sCallNo, u_int32_t ts,
1059 void* data, unsigned int len) {
1060 unsigned char header[4] = {(unsigned char)(sCallNo >> 8),
1061 (unsigned char)sCallNo,(unsigned char)(ts >> 8),(unsigned char)ts};
1062 dest.assign(header,4);
1063 dest.append(data,len);
1064 }
1065
1075 static void buildVideoMetaFrame(DataBlock& dest, u_int16_t sCallNo, u_int32_t tStamp,
1076 bool mark, void* data, unsigned int len);
1077
1083 static u_int8_t packSubclass(u_int32_t value);
1084
1090 static u_int32_t unpackSubclass(u_int8_t value);
1091
1097 static inline const char* typeText(int type)
1098 { return lookup(type,s_types,0); }
1099
1100protected:
1105
1110
1111private:
1112 static TokenDict s_types[]; // Keep the association between IAX frame types and their names
1113 Type m_type; // Frame type
1114 u_int16_t m_sCallNo; // Source call number
1115 u_int32_t m_tStamp; // Frame timestamp
1116 bool m_mark; // Mark flag
1117};
1118
1123class YIAX_API IAXFullFrame : public IAXFrame
1124{
1125public:
1130 Hangup = 0x01,
1131 //Ring = 0x02,
1132 Ringing = 0x03,
1133 Answer = 0x04,
1134 Busy = 0x05,
1135 Congestion = 0x08,
1136 FlashHook = 0x09,
1137 Option = 0x0b,
1138 KeyRadio = 0x0c,
1139 UnkeyRadio = 0x0d,
1140 Progressing = 0x0e,
1141 Proceeding = 0x0f,
1142 Hold = 0x10,
1143 Unhold = 0x11,
1144 VidUpdate = 0x12,
1145 SrcUpdate = 0x14,
1146 StopSounds = 0xff,
1147 };
1148
1163 IAXFullFrame(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo,
1164 unsigned char oSeqNo, unsigned char iSeqNo,
1165 u_int32_t tStamp, bool retrans,
1166 const unsigned char* buf, unsigned int len, bool mark = false);
1167
1181 IAXFullFrame(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo,
1182 unsigned char oSeqNo, unsigned char iSeqNo,
1183 u_int32_t tStamp,
1184 const unsigned char* buf = 0, unsigned int len = 0, bool mark = false);
1185
1199 IAXFullFrame(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo,
1200 unsigned char oSeqNo, unsigned char iSeqNo,
1201 u_int32_t tStamp, IAXIEList* ieList, u_int16_t maxlen, bool mark = false);
1202
1206 virtual ~IAXFullFrame();
1207
1212 inline u_int16_t destCallNo() const
1213 { return m_dCallNo; }
1214
1219 inline unsigned char oSeqNo() const
1220 { return m_oSeqNo; }
1221
1226 inline unsigned char iSeqNo() const
1227 { return m_iSeqNo; }
1228
1233 inline u_int32_t subclass() const
1234 { return m_subclass; }
1235
1240 inline bool isAuthReq() const {
1241 return type() == IAXFrame::IAX &&
1242 (subclass() == IAXControl::AuthReq || subclass() == IAXControl::RegAuth);
1243 }
1244
1249 inline bool isInval() const
1250 { return type() == IAXFrame::IAX && subclass() == IAXControl::Inval; }
1251
1257
1262 void updateBuffer(u_int16_t maxlen);
1263
1269 { return m_ieList; }
1270
1276 bool updateIEList(bool incoming);
1277
1283 IAXIEList* removeIEList(bool delObj = true);
1284
1292 void toString(String& dest, const SocketAddr& local, const SocketAddr& remote,
1293 bool incoming);
1294
1300 static inline const char* controlTypeText(int type)
1301 { return lookup(type,s_controlTypes,0); }
1302
1303protected:
1307 virtual void destroyed();
1308
1309private:
1310 // Build frame buffer header
1311 void setDataHeader();
1312 static TokenDict s_controlTypes[]; // Keep the association between control types and their names
1313 u_int16_t m_dCallNo; // Destination call number
1314 unsigned char m_oSeqNo; // Out sequence number
1315 unsigned char m_iSeqNo; // In sequence number
1316 u_int32_t m_subclass; // Subclass
1317 IAXIEList* m_ieList; // List of IEs
1318};
1319
1324class YIAX_API IAXFrameOut : public IAXFullFrame
1325{
1326public:
1343 inline IAXFrameOut(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo,
1344 unsigned char oSeqNo, unsigned char iSeqNo, u_int32_t tStamp,
1345 const unsigned char* buf, unsigned int len,
1346 u_int16_t retransCount, u_int32_t retransIntervalMs,
1347 bool ackOnly, bool mark = false)
1348 : IAXFullFrame(type,subclass,sCallNo,dCallNo,oSeqNo,iSeqNo,tStamp,buf,len,mark),
1349 m_ack(false), m_ackOnly(ackOnly), m_retransCount(retransCount),
1350 m_retransTimeInterval(retransIntervalMs * 1000),
1351 m_nextTransTime(Time::now() + m_retransTimeInterval)
1352 {}
1353
1370 inline IAXFrameOut(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo,
1371 unsigned char oSeqNo, unsigned char iSeqNo, u_int32_t tStamp,
1372 IAXIEList* ieList, u_int16_t maxlen,
1373 u_int16_t retransCount, u_int32_t retransIntervalMs, bool ackOnly,
1374 bool mark = false)
1375 : IAXFullFrame(type,subclass,sCallNo,dCallNo,oSeqNo,iSeqNo,tStamp,ieList,maxlen,mark),
1376 m_ack(false), m_ackOnly(ackOnly), m_retransCount(retransCount),
1377 m_retransTimeInterval(retransIntervalMs * 1000),
1378 m_nextTransTime(Time::now() + m_retransTimeInterval)
1379 {}
1380
1385 {}
1386
1391 inline unsigned int retransCount() const
1392 { return m_retransCount; }
1393
1399 inline bool timeForRetrans(u_int64_t time) const
1400 { return time >= m_nextTransTime; }
1401
1405 inline void setRetrans() {
1406 if (m_retrans)
1407 return;
1408 m_retrans = true;
1409 ((unsigned char*)m_data.data())[2] |= 0x80;
1410 }
1411
1415 inline void transmitted() {
1416 if (!m_retransCount)
1417 return;
1418 m_retransCount--;
1419 m_retransTimeInterval *= 2;
1420 m_nextTransTime += m_retransTimeInterval;
1421 }
1422
1427 inline bool ack() const
1428 { return m_ack; }
1429
1433 inline void setAck()
1434 { m_ack = true; }
1435
1440 inline bool ackOnly() const
1441 { return m_ackOnly; }
1442
1447 inline bool canSetTimeout()
1448 { return m_retransTimeInterval != 0; }
1449
1454 inline void setTimeout(u_int64_t tout) {
1455 if (!m_retransTimeInterval)
1456 return;
1457 m_retransTimeInterval = 0;
1458 m_retransCount = 0;
1459 m_nextTransTime = tout;
1460 }
1461
1462private:
1463 bool m_ack; // Acknoledge flag
1464 bool m_ackOnly; // Frame need only ACK as a response
1465 u_int16_t m_retransCount; // Retransmission counter
1466 u_int32_t m_retransTimeInterval; // Retransmission interval
1467 u_int64_t m_nextTransTime; // Next transmission time
1468};
1469
1474class YIAX_API IAXTrunkInfo : public RefObject
1475{
1476public:
1481 : m_timestamps(true), m_sendInterval(IAX2_TRUNKFRAME_SEND_DEF),
1482 m_maxLen(IAX2_TRUNKFRAME_LEN_DEF),
1483 m_efficientUse(false), m_trunkInSyncUsingTs(true),
1484 m_trunkInTsDiffRestart(5000),
1485 m_retransCount(IAX2_RETRANS_COUNT_DEF),
1486 m_retransInterval(IAX2_RETRANS_INTERVAL_DEF),
1487 m_pingInterval(IAX2_PING_INTERVAL_DEF)
1488 {}
1489
1496 void init(const NamedList& params, const String& prefix = String::empty(),
1497 const IAXTrunkInfo* def = 0);
1498
1507 void initTrunking(const NamedList& params, const String& prefix = String::empty(),
1508 const IAXTrunkInfo* def = 0, bool out = true, bool in = true);
1509
1517 void updateTrunking(const NamedList& params, const String& prefix = String::empty(),
1518 bool out = true, bool in = true);
1519
1528 void dump(String& buf, const char* sep = " ", bool out = true, bool in = true,
1529 bool other = true);
1530
1531 bool m_timestamps; // Trunk type: with(out) timestamps
1532 unsigned int m_sendInterval; // Send interval
1533 unsigned int m_maxLen; // Max frame length
1534 bool m_efficientUse; // Outgoing trunking: use or not the trunk based on calls using it
1535 bool m_trunkInSyncUsingTs; // Incoming trunk without timestamps: use trunk
1536 // time or trunk timestamp to re-build frame ts
1537 u_int32_t m_trunkInTsDiffRestart; // Incoming trunk without timestamp: diff between
1538 // timestamps at which we restart
1539 unsigned int m_retransCount; // Frame retransmission counter
1540 unsigned int m_retransInterval; // Frame retransmission interval in milliseconds
1541 unsigned int m_pingInterval; // Ping interval in milliseconds
1542};
1543
1548class YIAX_API IAXMetaTrunkFrame : public RefObject, public Mutex
1549{
1550public:
1559 IAXMetaTrunkFrame(IAXEngine* engine, const SocketAddr& addr, bool timestamps,
1560 unsigned int maxLen, unsigned int sendInterval);
1561
1566
1571 inline const SocketAddr& addr() const
1572 { return m_addr; }
1573
1578 inline unsigned int calls() const
1579 { return m_calls; }
1580
1585 inline void changeCalls(bool add) {
1586 Lock lck(this);
1587 if (add)
1588 m_calls++;
1589 else if (m_calls)
1590 m_calls--;
1591 }
1592
1597 inline bool trunkTimestamps() const
1598 { return m_trunkTimestamps; }
1599
1604 inline unsigned int sendInterval() const
1605 { return m_sendInterval; }
1606
1611 inline unsigned int maxLen() const
1612 { return m_maxLen; }
1613
1621 unsigned int add(u_int16_t sCallNo, const DataBlock& data, u_int32_t tStamp);
1622
1628 inline bool timerTick(const Time& now = Time()) {
1629 if (m_dataAddIdx == IAX2_TRUNKFRAME_HEADERLENGTH || !m_send)
1630 return false;
1631 Lock lck(this);
1632 return (now > m_send) && doSend(now,true);
1633 }
1634
1639 inline bool send() {
1640 if (m_dataAddIdx == IAX2_TRUNKFRAME_HEADERLENGTH)
1641 return false;
1642 Lock lck(this);
1643 return m_dataAddIdx != IAX2_TRUNKFRAME_HEADERLENGTH && doSend();
1644 }
1645
1646private:
1647 IAXMetaTrunkFrame() {} // No default constructor
1648 // Send this frame to remote peer
1649 bool doSend(const Time& now = Time(), bool onTime = false);
1650 // Set timestamp and next time to send
1651 inline void setTimestamp(u_int64_t now) {
1652 m_timeStamp = now;
1653 m_send = now + (u_int64_t)m_sendInterval * 1000;
1654 }
1655 // Set next time to send
1656 inline void setSendTime(u_int64_t now)
1657 { m_send = now + (u_int64_t)m_sendInterval * 1000; }
1658
1659 // Set the timestamp of this frame
1660 inline void setTimestamp(u_int32_t tStamp) {
1661 m_data[4] = (u_int8_t)(tStamp >> 24);
1662 m_data[5] = (u_int8_t)(tStamp >> 16);
1663 m_data[6] = (u_int8_t)(tStamp >> 8);
1664 m_data[7] = (u_int8_t)tStamp;
1665 }
1666
1667 unsigned int m_calls; // The number of calls using it
1668 u_int8_t* m_data; // Data buffer
1669 u_int16_t m_dataAddIdx; // Current add index
1670 u_int64_t m_timeStamp; // First time data was added
1671 u_int64_t m_send; // Time to send
1672 u_int32_t m_lastSentTs; // Last sent timestamp
1673 unsigned int m_sendInterval;// Send interval in milliseconds
1674 IAXEngine* m_engine; // The engine that owns this frame
1675 SocketAddr m_addr; // Remote peer address
1676 bool m_trunkTimestamps; // Trunk type: with(out) timestamps
1677 unsigned int m_maxLen; // Max frame length
1678 unsigned int m_maxDataLen; // Max frame data length
1679 unsigned char m_miniHdrLen; // Miniframe header length
1680};
1681
1687class YIAX_API IAXMediaData
1688{
1689 friend class IAXTransaction;
1690public:
1695 : m_inMutex(false,"IAXTransaction::InMedia"),
1696 m_outMutex(false,"IAXTransaction::OutMedia"),
1697 m_startedIn(false), m_startedOut(false),
1698 m_outStartTransTs(0), m_outFirstSrcTs(0),
1699 m_lastOut(0), m_lastIn(0), m_sent(0), m_sentBytes(0),
1700 m_recv(0), m_recvBytes(0), m_ooPackets(0), m_ooBytes(0),
1701 m_showInNoFmt(true), m_showOutOldTs(true),
1702 m_dropOut(0), m_dropOutBytes(0)
1703 {}
1704
1709 inline void dropOut(unsigned int len) {
1710 if (len) {
1711 m_dropOut++;
1712 m_dropOutBytes += len;
1713 }
1714 }
1715
1720 void print(String& buf);
1721
1722protected:
1723 Mutex m_inMutex;
1724 Mutex m_outMutex;
1725 bool m_startedIn; // Incoming media started
1726 bool m_startedOut; // Outgoing media started
1727 int m_outStartTransTs; // Transaction timestamp where media send started
1728 unsigned int m_outFirstSrcTs; // First outgoing source packet timestamp as received from source
1729 u_int32_t m_lastOut; // Last transmitted mini timestamp
1730 u_int32_t m_lastIn; // Last received timestamp
1731 unsigned int m_sent; // Packets sent
1732 unsigned int m_sentBytes; // Bytes sent
1733 unsigned int m_recv; // Packets received
1734 unsigned int m_recvBytes; // Bytes received
1735 unsigned int m_ooPackets; // Dropped received out of order packets
1736 unsigned int m_ooBytes; // Dropped received out of order bytes
1737 bool m_showInNoFmt; // Show incoming media arrival without format debug
1738 bool m_showOutOldTs; // Show dropped media out debug message
1739 unsigned int m_dropOut; // The number of dropped outgoing packets
1740 unsigned int m_dropOutBytes; // The number of dropped outgoing bytes
1741};
1742
1748class YIAX_API IAXTransaction : public RefObject, public Mutex
1749{
1750 friend class IAXEvent;
1751 friend class IAXEngine;
1752public:
1756 enum Type {
1757 Incorrect, // Unsupported/unknown type
1758 New, // Media exchange call
1759 RegReq, // Registration
1760 RegRel, // Registration release
1761 Poke, // Ping
1762 //FwDownl,
1763 };
1764
1768 enum State {
1769 Connected, // Call leg established (Accepted) for transactions of type New
1770 NewLocalInvite, // New outgoing transaction: Poke/New/RegReq/RegRel
1771 NewLocalInvite_AuthRecv, // Auth request received for an outgoing transaction
1772 NewLocalInvite_RepSent, // Auth reply sent for an outgoing transaction
1773 NewRemoteInvite, // New incoming transaction: Poke/New/RegReq/RegRel
1774 NewRemoteInvite_AuthSent, // Auth sent for an incoming transaction
1775 NewRemoteInvite_RepRecv, // Auth reply received for an incoming transaction
1776 Unknown, // Initial state
1777 Terminated, // Terminated. No more frames accepted
1778 Terminating, // Terminating. Wait for ACK or timeout to terminate
1779 };
1780
1790 static IAXTransaction* factoryIn(IAXEngine* engine, IAXFullFrame* frame, u_int16_t lcallno, const SocketAddr& addr,
1791 void* data = 0);
1792
1802 static IAXTransaction* factoryOut(IAXEngine* engine, Type type, u_int16_t lcallno, const SocketAddr& addr,
1803 IAXIEList& ieList, void* data = 0);
1804
1809
1814 inline IAXEngine* getEngine() const
1815 { return m_engine; }
1816
1821 inline Type type() const
1822 { return m_type; }
1823
1828 inline const char* typeName()
1829 { return typeName(type()); }
1830
1835 inline State state() const
1836 { return m_state; }
1837
1842 inline const char* stateName()
1843 { return stateName(state()); }
1844
1849 inline u_int64_t timeStamp() const
1850 { return Time::msecNow() - m_timeStamp; }
1851
1856 inline bool outgoing() const
1857 { return m_localInitTrans; }
1858
1863 inline void setUserData(void* data)
1864 { m_userdata = data; }
1865
1870 inline void* getUserData() const
1871 { return m_userdata; }
1872
1877 inline u_int16_t localCallNo() const
1878 { return m_lCallNo; }
1879
1884 inline u_int16_t remoteCallNo() const
1885 { return m_rCallNo; }
1886
1891 inline const SocketAddr& remoteAddr() const
1892 { return m_addr; }
1893
1898 inline const String& username()
1899 { return m_username; }
1900
1905 inline const String& callingNo()
1906 { return m_callingNo; }
1907
1912 inline const String& callingName()
1913 { return m_callingName; }
1914
1919 inline const String& calledNo()
1920 { return m_calledNo; }
1921
1926 inline const String& calledContext()
1927 { return m_calledContext; }
1928
1933 inline const String& challenge()
1934 { return m_challenge; }
1935
1941 inline IAXFormat* getFormat(int type) {
1942 if (type == IAXFormat::Audio)
1943 return &m_format;
1944 if (type == IAXFormat::Video)
1945 return &m_formatVideo;
1946 return 0;
1947 }
1948
1955 if (type == IAXFormat::Audio)
1956 return &m_dataAudio;
1957 if (type == IAXFormat::Video)
1958 return &m_dataVideo;
1959 return 0;
1960 }
1961
1967 inline u_int32_t format(int type) {
1968 IAXFormat* fmt = getFormat(type);
1969 return fmt ? fmt->format() : 0;
1970 }
1971
1977 inline u_int32_t formatIn(int type) {
1978 IAXFormat* fmt = getFormat(type);
1979 return fmt ? fmt->in() : 0;
1980 }
1981
1987 inline u_int32_t formatOut(int type) {
1988 IAXFormat* fmt = getFormat(type);
1989 return fmt ? fmt->out() : 0;
1990 }
1991
1996 inline u_int32_t capability() const
1997 { return m_capability; }
1998
2003 inline u_int32_t expire() const
2004 { return m_expire; }
2005
2010 inline const String& authdata()
2011 { return m_authdata; }
2012
2016 inline void setDestroy()
2017 { m_destroy = true; }
2018
2023 void start();
2024
2032
2042 IAXTransaction* processMedia(DataBlock& data, u_int32_t tStamp,
2043 int type = IAXFormat::Audio, bool full = false, bool mark = false);
2044
2054 unsigned int sendMedia(const DataBlock& data, unsigned int tStamp, u_int32_t format,
2055 int type = IAXFormat::Audio, bool mark = false);
2056
2063 IAXEvent* getEvent(const Time& now = Time());
2064
2069 static unsigned char getMaxFrameList();
2070
2076 static bool setMaxFrameList(unsigned char value);
2077
2083 inline bool sendAnswer()
2084 { return sendConnected(IAXFullFrame::Answer); }
2085
2091 inline bool sendRinging()
2092 { return sendConnected(IAXFullFrame::Ringing); }
2093
2099 inline bool sendProgress()
2100 { return sendConnected(IAXFullFrame::Proceeding); }
2101
2110 bool sendAccept(unsigned int* expires = 0);
2111
2119 bool sendHangup(const char* cause = 0, u_int8_t code = 0);
2120
2128 bool sendReject(const char* cause = 0, u_int8_t code = 0);
2129
2135 bool sendAuth();
2136
2143 bool sendAuthReply(const String& response);
2144
2151 inline bool sendDtmf(u_int8_t dtmf)
2152 { return dtmf <= 127 ? sendConnected((IAXFullFrame::ControlType)dtmf,IAXFrame::DTMF) : false; }
2153
2160 bool sendText(const char* text);
2161
2168 inline bool sendNoise(u_int8_t noise)
2169 { return noise <= 127 ? sendConnected((IAXFullFrame::ControlType)noise,IAXFrame::Noise) : false; }
2170
2176 bool abortReg();
2177
2184 bool enableTrunking(IAXMetaTrunkFrame* trunkFrame, bool efficientUse);
2185
2191 void processCallToken(const DataBlock& callToken);
2192
2199 void processMiniNoTs(u_int32_t ts, ObjList& blocks, const Time& now = Time());
2200
2207 void print(bool printStats = false, bool printFrames = false, const char* location = "status");
2208
2214 static inline const char* typeName(int type)
2215 { return lookup(type,s_typeName); }
2216
2222 static inline const char* stateName(int state)
2223 { return lookup(state,s_stateName); }
2224
2228 static const TokenDict s_typeName[];
2229
2233 static const TokenDict s_stateName[];
2234
2239
2244
2249
2254
2255protected:
2265 IAXTransaction(IAXEngine* engine, IAXFullFrame* frame, u_int16_t lcallno, const SocketAddr& addr,
2266 void* data = 0);
2267
2277 IAXTransaction(IAXEngine* engine, Type type, u_int16_t lcallno, const SocketAddr& addr, IAXIEList& ieList,
2278 void* data = 0);
2279
2283 virtual void destroyed();
2284
2289 void init(IAXIEList& ieList);
2290
2297 bool incrementSeqNo(const IAXFullFrame* frame, bool inbound);
2298
2305
2311 bool changeState(State newState);
2312
2321 IAXEvent* terminate(u_int8_t evType, bool local, IAXFullFrame* frame = 0, bool createIEList = true);
2322
2330 IAXEvent* waitForTerminate(u_int8_t evType = 0, bool local = true, IAXFullFrame* frame = 0);
2331
2343 void postFrame(IAXFrame::Type type, u_int32_t subclass, void* data = 0, u_int16_t len = 0, u_int32_t tStamp = 0,
2344 bool ackOnly = false, bool mark = false);
2345
2355 void postFrameIes(IAXFrame::Type type, u_int32_t subclass, IAXIEList* ies, u_int32_t tStamp = 0,
2356 bool ackOnly = false);
2357
2364 bool sendFrame(IAXFrameOut* frame, bool vnak = false);
2365
2374 IAXEvent* createEvent(u_int8_t evType, bool local, IAXFullFrame* frame, State newState);
2375
2387 IAXEvent* createResponse(IAXFrameOut* frame, u_int8_t findType, u_int8_t findSubclass, u_int8_t evType, bool local, State newState);
2388
2395 IAXEvent* getEventResponse(IAXFrameOut* frame, bool& delFrame);
2396
2403 IAXEvent* getEventResponse_New(IAXFrameOut* frame, bool& delFrame);
2404
2410 IAXEvent* processAuthReq(IAXEvent* event);
2411
2418 IAXEvent* processAccept(IAXEvent* event);
2419
2425 IAXEvent* processAuthRep(IAXEvent* event);
2426
2433 IAXEvent* getEventResponse_Reg(IAXFrameOut* frame, bool& delFrame);
2434
2440 IAXEvent* processRegAck(IAXEvent* event);
2441
2448 IAXEvent* getEventStartTrans(IAXFullFrame* frame, bool& delFrame);
2449
2456 IAXEvent* getEventRequest(IAXFullFrame* frame, bool& delFrame);
2457
2464 IAXEvent* getEventRequest_New(IAXFullFrame* frame, bool& delFrame);
2465
2473
2481 bool findInFrameTimestamp(const IAXFullFrame* frameOut, IAXFrame::Type type, u_int32_t subclass);
2482
2488 bool findInFrameAck(const IAXFullFrame* frameOut);
2489
2494
2502 bool sendConnected(IAXFullFrame::ControlType subclass, IAXFrame::Type frametype = IAXFrame::Control);
2503
2508 void sendAck(const IAXFullFrame* frame);
2509
2513 void sendVNAK();
2514
2519 void sendUnsupport(u_int32_t subclass);
2520
2527 IAXEvent* processInternalOutgoingRequest(IAXFrameOut* frame, bool& delFrame);
2528
2535 IAXEvent* processInternalIncomingRequest(const IAXFullFrame* frame, bool& delFrame);
2536
2543 IAXEvent* processMidCallControl(IAXFullFrame* frame, bool& delFrame);
2544
2551 IAXEvent* processMidCallIAXControl(IAXFullFrame* frame, bool& delFrame);
2552
2559 IAXEvent* remoteRejectCall(IAXFullFrame* frame, bool& delFrame);
2560
2568
2575
2582 IAXEvent* internalReject(const char* reason, u_int8_t code);
2583
2589 void eventTerminated(IAXEvent* event);
2590
2596 inline IAXEvent* keepEvent(IAXEvent* event) {
2597 m_currentEvent = event;
2598 return event;
2599 }
2600
2601private:
2602 void adjustTStamp(u_int32_t& tStamp);
2603 void postFrame(IAXFrameOut* frame);
2604 void receivedVoiceMiniBeforeFull();
2605 void resetTrunk();
2606 void init();
2607 void setPendingEvent(IAXEvent* ev = 0);
2608 inline void restartTrunkIn(u_int64_t now, u_int32_t ts) {
2609 m_trunkInStartTime = now;
2610 u_int64_t dt = (now - m_lastVoiceFrameIn) / 1000;
2611 m_trunkInTsDelta = m_lastVoiceFrameInTs + (u_int32_t)dt;
2612 m_trunkInFirstTs = ts;
2613 }
2614 // Process accept format and caps
2615 bool processAcceptFmt(IAXIEList* list);
2616 // Process queued ACCEPT. Reject with given reason/code if not found
2617 // Reject with 'nomedia' if found and format is not acceptable
2618 IAXEvent* checkAcceptRecv(const char* reason, u_int8_t code);
2619
2620 // Params
2621 bool m_localInitTrans; // True: local initiated transaction
2622 bool m_localReqEnd; // Local client requested terminate
2623 Type m_type; // Transaction type
2624 State m_state; // Transaction state
2625 bool m_destroy; // Destroy flag
2626 bool m_accepted; // ACCEPT received and processed
2627 u_int64_t m_timeStamp; // Transaction creation timestamp
2628 u_int64_t m_timeout; // Transaction timeout in Terminating state
2629 SocketAddr m_addr; // Socket
2630 u_int16_t m_lCallNo; // Local peer call id
2631 u_int16_t m_rCallNo; // Remote peer call id
2632 unsigned char m_oSeqNo; // Outgoing frame sequence number
2633 unsigned char m_iSeqNo; // Incoming frame sequence number
2634 IAXEngine* m_engine; // Engine that owns this transaction
2635 void* m_userdata; // Arbitrary user data
2636 u_int32_t m_lastFullFrameOut; // Last transmitted full frame timestamp
2637 IAXMediaData m_dataAudio;
2638 IAXMediaData m_dataVideo;
2639 u_int16_t m_lastAck; // Last ack'd received frame's oseqno
2640 IAXEvent* m_pendingEvent; // Pointer to a pending event or 0
2641 IAXEvent* m_currentEvent; // Pointer to last generated event or 0
2642 // Outgoing frames management
2643 ObjList m_outFrames; // Transaction & protocol control outgoing frames
2644 unsigned int m_retransCount; // Retransmission counter. 0 --> Timeout
2645 unsigned int m_retransInterval; // Frame retransmission interval
2646 // Incoming frames management
2647 ObjList m_inFrames; // Transaction & protocol control incoming frames
2648 static unsigned char m_maxInFrames; // Max frames number allowed in m_inFrames
2649 // Call leg management
2650 u_int32_t m_pingInterval; // Ping remote peer interval
2651 u_int64_t m_timeToNextPing; // Time of the next Ping
2652 // Statistics
2653 u_int32_t m_inTotalFramesCount; // Total received frames
2654 u_int32_t m_inOutOfOrderFrames; // Total out of order frames
2655 u_int32_t m_inDroppedFrames; // Total dropped frames
2656 // Data
2657 IAXAuthMethod::Type m_authmethod; // Authentication method to use
2658 String m_username; // Username
2659 String m_callingNo; // Calling number
2660 String m_callingName; // Calling name
2661 String m_calledNo; // Called number
2662 String m_calledContext; // Called context
2663 String m_challenge; // Challenge
2664 String m_authdata; // Auth data received with auth reply
2665 u_int32_t m_expire; // Registration expiring time
2666 IAXFormat m_format; // Audio format
2667 IAXFormat m_formatVideo; // Video format
2668 u_int32_t m_capability; // Media capability of this transaction
2669 bool m_callToken; // Call token supported/expected
2670 unsigned int m_adjustTsOutThreshold; // Adjust outgoing data timestamp threshold
2671 unsigned int m_adjustTsOutOverrun; // Value used to adjust outgoing data timestamp on data
2672 // overrun (incoming data with rate greater then expected)
2673 unsigned int m_adjustTsOutUnderrun; // Value used to adjust outgoing data timestamp on data
2674 // underrun (incoming data with rate less then expected)
2675 u_int64_t m_lastVoiceFrameIn; // Time we received the last voice frame
2676 u_int32_t m_lastVoiceFrameInTs; // Timestamp in the last received voice frame
2677 int m_reqVoiceVNAK; // Send VNAK if not received full voice frame
2678 // Meta trunking
2679 IAXMetaTrunkFrame* m_trunkFrame; // Reference to a trunk frame if trunking is enabled for this transaction
2680 bool m_trunkFrameCallsSet; // Trunk frame calls increased
2681 bool m_trunkOutEfficientUse; // Use or not the trunk frame based on calls using it
2682 bool m_trunkOutSend; // Currently using the trunk frame
2683 bool m_trunkInSyncUsingTs; // Incoming trunk without timestamps: generate timestamp
2684 // using time or using trunk timestamp
2685 u_int64_t m_trunkInStartTime; // First time we received trunk in data
2686 u_int32_t m_trunkInTsDelta; // Value used to re-build ts: last voice timestamp
2687 u_int32_t m_trunkInTsDiffRestart; // Incoming trunk without timestamp: diff between timestamps at which we restart
2688 u_int32_t m_trunkInFirstTs; // Incoming trunk without timestamp: first trunk timestamp
2689 // Postponed start
2690 IAXIEList* m_startIEs; // Postponed start
2691};
2692
2697class YIAX_API IAXEvent
2698{
2699 friend class IAXTransaction;
2700 friend class IAXConnectionlessTransaction;
2701public:
2705 enum Type {
2706 DontSet = 0, // Used internal
2707 Invalid, // Invalid frame received
2708 Terminated, // Transaction terminated
2709 Timeout, // Transaction timeout
2710 NotImplemented, // Feature not implemented
2711 New, // New remote transaction
2712 AuthReq, // Auth request
2713 AuthRep, // Auth reply
2714 Accept, // Request accepted
2715 Hangup, // Remote hangup
2716 Reject, // Remote reject
2717 Busy, // Call busy
2718 Text, // Text frame received
2719 Dtmf, // DTMF frame received
2720 Noise, // Noise frame received
2721 Answer, // Call answered
2722 Quelch, // Quelch the call
2723 Unquelch, // Unquelch the call
2724 Progressing, // Call progressing
2725 Ringing, // Ringing
2726 };
2727
2733
2738 inline Type type() const
2739 { return m_type; }
2740
2745 inline bool local() const
2746 { return m_local; }
2747
2752 inline bool final() const
2753 { return m_final; }
2754
2758 inline void setFinal()
2759 { m_final = true; }
2760
2766 inline u_int8_t frameType()
2767 { return m_frameType; }
2768
2773 inline u_int32_t subclass()
2774 { return m_subClass; }
2775
2780 inline IAXEngine* getEngine() const
2781 { return m_transaction ? m_transaction->getEngine() : 0; }
2782
2787 inline IAXTransaction* getTransaction() const
2788 { return m_transaction; }
2789
2794 inline void* getUserData() const
2795 { return m_transaction ? m_transaction->getUserData() : 0; }
2796
2802 { return *m_ieList; }
2803
2804protected:
2814 IAXEvent(Type type, bool local, bool final, IAXTransaction* transaction, u_int8_t frameType = 0, u_int32_t subclass = 0);
2815
2824 IAXEvent(Type type, bool local, bool final, IAXTransaction* transaction, IAXFullFrame* frame = 0);
2825
2826private:
2827 inline IAXEvent() {} // Default constructor
2828
2829 Type m_type; // Event type
2830 u_int8_t m_frameType; // Frame type
2831 u_int32_t m_subClass; // Frame subclass
2832 bool m_local; // If true the event is generated locally, the receiver MUST not respond
2833 bool m_final; // Final event flag
2834 IAXTransaction* m_transaction; // Transaction that generated this event
2835 IAXIEList* m_ieList; // IAXInfoElement list
2836};
2837
2842class YIAX_API IAXEngine : public DebugEnabler, public Mutex
2843{
2844public:
2854 IAXEngine(const char* iface, int port, u_int32_t format, u_int32_t capab,
2855 const NamedList* params = 0, const char* name = "iaxengine");
2856
2861 virtual ~IAXEngine();
2862
2867 inline const String& name() const
2868 { return m_name; }
2869
2874 inline u_int8_t callerNumType() const
2875 { return m_callerNumType; }
2876
2881 inline u_int8_t callingPres() const
2882 { return m_callingPres; }
2883
2891
2899 IAXTransaction* addFrame(const SocketAddr& addr, const unsigned char* buf, unsigned int len);
2900
2908 IAXTransaction* findTransaction(const SocketAddr& addr, u_int16_t rCallNo);
2909
2918 virtual void processMedia(IAXTransaction* transaction, DataBlock& data, u_int32_t tStamp,
2919 int type, bool mark)
2920 {}
2921
2927 bool process();
2928
2933 inline unsigned int challengeTout() const
2934 { return m_challengeTout; }
2935
2940 inline u_int16_t maxFullFrameDataLen() const
2941 { return m_maxFullFrameDataLen; }
2942
2948 inline u_int32_t format(bool audio = true) const
2949 { return audio ? m_format : m_formatVideo; }
2950
2955 inline u_int32_t capability() const
2956 { return m_capability; }
2957
2964 inline void getOutDataAdjust(unsigned int& thres, unsigned int& over,
2965 unsigned int& under) const {
2966 thres = m_adjustTsOutThreshold;
2967 over = m_adjustTsOutOverrun;
2968 under = m_adjustTsOutUnderrun;
2969 }
2970
2977 void initOutDataAdjust(const NamedList& params, IAXTransaction* tr = 0);
2978
2983 void initialize(const NamedList& params);
2984
2990
3000 bool writeSocket(const void* buf, int len, const SocketAddr& addr, IAXFullFrame* frame = 0,
3001 unsigned int* sent = 0);
3002
3009 inline bool writeSocket(const SocketAddr& addr, IAXFullFrame* frame)
3010 { return !frame || writeSocket(frame->data().data(),frame->data().length(),addr,frame); }
3011
3016
3023
3030
3036 u_int32_t transactionCount();
3037
3043
3051 virtual bool mediaFormatChanged(IAXTransaction* trans, int type, u_int32_t format)
3052 { return false; }
3053
3061 virtual bool checkCallToken(const SocketAddr& addr, IAXFullFrame& frame);
3062
3071 bool acceptFormatAndCapability(IAXTransaction* trans, unsigned int* caps = 0,
3072 int type = IAXFormat::Audio);
3073
3078 virtual void defaultEventHandler(IAXEvent* event);
3079
3084 inline bool exiting() const
3085 { return m_exiting; }
3086
3090 virtual void setExiting();
3091
3099 void enableTrunking(IAXTransaction* trans, const NamedList* params,
3100 const String& prefix = String::empty());
3101
3109
3116 void initTrunkIn(IAXTransaction* trans, const NamedList* params,
3117 const String& prefix = String::empty());
3118
3125
3132 Lock lck(m_trunkInfoMutex);
3133 info = m_trunkInfoDef;
3134 return info != 0;
3135 }
3136
3143
3148
3153 inline Socket& socket()
3154 { return m_socket; }
3155
3160 inline const SocketAddr& addr() const
3161 { return m_addr; }
3162
3169 inline void setFormats(u_int32_t caps, u_int32_t fmtAudio, u_int32_t fmtVideo) {
3170 m_format = fmtAudio;
3171 m_formatVideo = fmtVideo;
3172 m_capability = caps;
3173 }
3174
3181 static inline int getPort(const NamedList& params, const String& param = "port")
3182 { return params.getIntValue(param,4569); }
3183
3190 static void getMD5FromChallenge(String& md5data, const String& challenge, const String& password);
3191
3198 static bool isMD5ChallengeCorrect(const String& md5data, const String& challenge, const String& password);
3199
3206 static void buildAddrSecret(String& buf, const String& secret,
3207 const SocketAddr& addr);
3208
3216 static int addrSecretAge(const String& buf, const String& secret,
3217 const SocketAddr& addr);
3218
3226 static inline void addKeyword(NamedList& list, const char* param,
3227 const TokenDict* tokens, unsigned int val) {
3228 const char* value = lookup(val,tokens);
3229 if (value)
3230 list.addParam(param,value);
3231 else
3232 list.addParam(param,String(val));
3233 }
3234
3245 static void decodeDateTime(u_int32_t dt, unsigned int& year, unsigned int& month,
3246 unsigned int& day, unsigned int& hour, unsigned int& minute, unsigned int& sec);
3247
3254 static unsigned int overallTout(unsigned int interval = IAX2_RETRANS_INTERVAL_DEF,
3255 unsigned int nRetrans = IAX2_RETRANS_COUNT_DEF);
3256
3257protected:
3263 bool processTrunkFrames(const Time& time = Time());
3264
3271 virtual void processEvent(IAXEvent* event);
3272
3279 IAXEvent* getEvent(const Time& now = Time());
3280
3285 u_int16_t generateCallNo();
3286
3291 void releaseCallNo(u_int16_t lcallno);
3292
3303 const SocketAddr& addr, IAXIEList& ieList,
3304 bool refTrans = false, bool startTrans = true);
3305
3313 bool bind(const char* iface, int port, bool force);
3314
3315 int m_trunking; // Trunking capability: negative: ok, otherwise: not enabled
3316
3317private:
3318 String m_name; // Engine name
3319 Socket m_socket; // Socket
3320 SocketAddr m_addr; // Address we are bound on
3321 ObjList** m_transList; // Full transactions
3322 ObjList m_incompleteTransList; // Incomplete transactions (no remote call number)
3323 bool m_lUsedCallNo[IAX2_MAX_CALLNO + 1]; // Used local call numnmbers flags
3324 int m_lastGetEvIndex; // getEvent: keep last array entry
3325 bool m_exiting; // Exiting flag
3326 // Parameters
3327 int m_maxFullFrameDataLen; // Max full frame data (IE list) length
3328 u_int16_t m_startLocalCallNo; // Start index of local call number allocation
3329 u_int16_t m_transListCount; // m_transList count
3330 unsigned int m_challengeTout; // Sent challenge timeout interval
3331 bool m_callToken; // Call token required on incoming calls
3332 String m_callTokenSecret; // Secret used to generate call tokens
3333 int m_callTokenAge; // Max allowed call token age
3334 bool m_showCallTokenFailures; // Print incoming call token failures to output
3335 bool m_rejectMissingCallToken; // Reject/ignore incoming calls without call token if mandatory
3336 bool m_printMsg; // Print frame to output
3337 u_int8_t m_callerNumType; // Caller number type
3338 u_int8_t m_callingPres; // Caller presentation + screening
3339 // Media
3340 u_int32_t m_format; // The default media format
3341 u_int32_t m_formatVideo; // Default video format
3342 u_int32_t m_capability; // The media capability
3343 unsigned int m_adjustTsOutThreshold; // Adjust outgoing data timestamp threshold
3344 unsigned int m_adjustTsOutOverrun; // Value used to adjust outgoing data timestamp on data
3345 // overrun (incoming data with rate greater then expected)
3346 unsigned int m_adjustTsOutUnderrun; // Value used to adjust outgoing data timestamp on data
3347 // underrun (incoming data with rate less then expected)
3348 // Trunking
3349 Mutex m_mutexTrunk; // Mutex for trunk operations
3350 ObjList m_trunkList; // Trunk frames list
3351 Mutex m_trunkInfoMutex; // Trunk info mutex
3352 RefPointer<IAXTrunkInfo> m_trunkInfoDef; // Defaults for trunk data
3353};
3354
3355}
3356
3357#endif /* __YATEIAX_H */
3358
3359/* vi: set ts=8 sw=4 sts=4 noet: */
A class that holds just a block of raw data.
Definition yateclass.h:4237
void append(void *value, unsigned int len)
Definition yateclass.h:4358
void * data() const
Definition yateclass.h:4289
unsigned int length() const
Definition yateclass.h:4321
DataBlock & assign(void *value, unsigned int len, bool copyData=true, unsigned int allocated=0)
DebugEnabler(int level=TelEngine::debugLevel(), bool enabled=true)
Definition yateclass.h:319
Wrapper class for authentication methods values.
Definition yateiax.h:605
static void authList(String &dest, u_int16_t auth, char sep)
Type
Definition yateiax.h:610
Wrapper class for subclasses of frames of type IAX.
Definition yateiax.h:893
Type
Definition yateiax.h:898
static const char * typeText(int type)
Definition yateiax.h:944
IAX engine class.
Definition yateiax.h:2843
virtual bool checkCallToken(const SocketAddr &addr, IAXFullFrame &frame)
bool trunkInfo(RefPointer< IAXTrunkInfo > &info)
Definition yateiax.h:3131
bool writeSocket(const void *buf, int len, const SocketAddr &addr, IAXFullFrame *frame=0, unsigned int *sent=0)
virtual ~IAXEngine()
virtual bool mediaFormatChanged(IAXTransaction *trans, int type, u_int32_t format)
Definition yateiax.h:3051
IAXTransaction * addFrame(const SocketAddr &addr, IAXFrame *frame)
static void getMD5FromChallenge(String &md5data, const String &challenge, const String &password)
unsigned int challengeTout() const
Definition yateiax.h:2933
bool bind(const char *iface, int port, bool force)
void runGetEvents()
static void buildAddrSecret(String &buf, const String &secret, const SocketAddr &addr)
void getOutDataAdjust(unsigned int &thres, unsigned int &over, unsigned int &under) const
Definition yateiax.h:2964
u_int16_t generateCallNo()
u_int8_t callingPres() const
Definition yateiax.h:2881
bool acceptFormatAndCapability(IAXTransaction *trans, unsigned int *caps=0, int type=IAXFormat::Audio)
IAXTransaction * startLocalTransaction(IAXTransaction::Type type, const SocketAddr &addr, IAXIEList &ieList, bool refTrans=false, bool startTrans=true)
static bool isMD5ChallengeCorrect(const String &md5data, const String &challenge, const String &password)
void sendInval(IAXFullFrame *frame, const SocketAddr &addr)
static void addKeyword(NamedList &list, const char *param, const TokenDict *tokens, unsigned int val)
Definition yateiax.h:3226
void initialize(const NamedList &params)
void readSocket(SocketAddr &addr)
u_int32_t capability() const
Definition yateiax.h:2955
void enableTrunking(IAXTransaction *trans, IAXTrunkInfo &data)
void initTrunkIn(IAXTransaction *trans, const NamedList *params, const String &prefix=String::empty())
void initOutDataAdjust(const NamedList &params, IAXTransaction *tr=0)
const SocketAddr & addr() const
Definition yateiax.h:3160
u_int8_t callerNumType() const
Definition yateiax.h:2874
u_int32_t format(bool audio=true) const
Definition yateiax.h:2948
bool exiting() const
Definition yateiax.h:3084
virtual void processMedia(IAXTransaction *transaction, DataBlock &data, u_int32_t tStamp, int type, bool mark)
Definition yateiax.h:2918
void releaseCallNo(u_int16_t lcallno)
void keepAlive(const SocketAddr &addr)
static unsigned int overallTout(unsigned int interval=IAX2_RETRANS_INTERVAL_DEF, unsigned int nRetrans=IAX2_RETRANS_COUNT_DEF)
void initTrunkIn(IAXTransaction *trans, IAXTrunkInfo &data)
u_int16_t maxFullFrameDataLen() const
Definition yateiax.h:2940
static int addrSecretAge(const String &buf, const String &secret, const SocketAddr &addr)
void removeTransaction(IAXTransaction *transaction)
IAXEvent * getEvent(const Time &now=Time())
void setFormats(u_int32_t caps, u_int32_t fmtAudio, u_int32_t fmtVideo)
Definition yateiax.h:3169
virtual void defaultEventHandler(IAXEvent *event)
bool processTrunkFrames(const Time &time=Time())
const String & name() const
Definition yateiax.h:2867
bool writeSocket(const SocketAddr &addr, IAXFullFrame *frame)
Definition yateiax.h:3009
IAXTransaction * addFrame(const SocketAddr &addr, const unsigned char *buf, unsigned int len)
void runProcessTrunkFrames()
static int getPort(const NamedList &params, const String &param="port")
Definition yateiax.h:3181
virtual void processEvent(IAXEvent *event)
IAXEngine(const char *iface, int port, u_int32_t format, u_int32_t capab, const NamedList *params=0, const char *name="iaxengine")
bool haveTransactions()
static void decodeDateTime(u_int32_t dt, unsigned int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &sec)
virtual void setExiting()
u_int32_t transactionCount()
bool process()
void enableTrunking(IAXTransaction *trans, const NamedList *params, const String &prefix=String::empty())
Socket & socket()
Definition yateiax.h:3153
IAXTransaction * findTransaction(const SocketAddr &addr, u_int16_t rCallNo)
Event class.
Definition yateiax.h:2698
IAXEvent(Type type, bool local, bool final, IAXTransaction *transaction, IAXFullFrame *frame=0)
Type
Definition yateiax.h:2705
u_int32_t subclass()
Definition yateiax.h:2773
void setFinal()
Definition yateiax.h:2758
IAXEngine * getEngine() const
Definition yateiax.h:2780
void * getUserData() const
Definition yateiax.h:2794
IAXTransaction * getTransaction() const
Definition yateiax.h:2787
IAXIEList & getList()
Definition yateiax.h:2801
bool local() const
Definition yateiax.h:2745
IAXEvent(Type type, bool local, bool final, IAXTransaction *transaction, u_int8_t frameType=0, u_int32_t subclass=0)
u_int8_t frameType()
Definition yateiax.h:2766
Type type() const
Definition yateiax.h:2738
IAX format description.
Definition yateiax.h:633
void setFormat(u_int32_t fmt, int type)
IAXFormatDesc()
Definition yateiax.h:638
u_int32_t format() const
Definition yateiax.h:646
unsigned int multiplier() const
Definition yateiax.h:653
Wrapper class for audio and video formats.
Definition yateiax.h:673
static u_int32_t encode(const String &formats, const TokenDict *dict, char sep=',')
static u_int32_t pickFormat(u_int32_t formats, u_int32_t format=0)
Formats
Definition yateiax.h:678
static void formatList(String &dest, u_int32_t formats, const TokenDict *dict=0, const char *sep=",")
static const TokenDict s_formats[]
Definition yateiax.h:869
const char * typeName() const
Definition yateiax.h:772
Media
Definition yateiax.h:710
static const char * formatName(u_int32_t fmt)
Definition yateiax.h:847
IAXFormat(int type=Audio)
Definition yateiax.h:721
const char * formatName() const
Definition yateiax.h:765
u_int32_t out() const
Definition yateiax.h:750
static const char * typeName(int type)
Definition yateiax.h:855
u_int32_t format() const
Definition yateiax.h:736
static u_int32_t mask(u_int32_t value, int type)
Definition yateiax.h:816
const IAXFormatDesc & formatDesc(bool in) const
Definition yateiax.h:758
int type() const
Definition yateiax.h:729
void set(u_int32_t *fmt, u_int32_t *fmtIn, u_int32_t *fmtOut)
u_int32_t in() const
Definition yateiax.h:743
static const String s_typesList[TypeCount]
Definition yateiax.h:879
static u_int32_t clear(u_int32_t value, int type)
Definition yateiax.h:832
static const String & typeNameStr(int type)
Definition yateiax.h:863
static const TokenDict s_types[]
Definition yateiax.h:874
This class holds an outgoing IAX full frame.
Definition yateiax.h:1325
virtual ~IAXFrameOut()
Definition yateiax.h:1384
void setRetrans()
Definition yateiax.h:1405
unsigned int retransCount() const
Definition yateiax.h:1391
IAXFrameOut(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo, unsigned char oSeqNo, unsigned char iSeqNo, u_int32_t tStamp, const unsigned char *buf, unsigned int len, u_int16_t retransCount, u_int32_t retransIntervalMs, bool ackOnly, bool mark=false)
Definition yateiax.h:1343
void transmitted()
Definition yateiax.h:1415
void setAck()
Definition yateiax.h:1433
bool canSetTimeout()
Definition yateiax.h:1447
bool ack() const
Definition yateiax.h:1427
bool timeForRetrans(u_int64_t time) const
Definition yateiax.h:1399
bool ackOnly() const
Definition yateiax.h:1440
IAXFrameOut(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo, unsigned char oSeqNo, unsigned char iSeqNo, u_int32_t tStamp, IAXIEList *ieList, u_int16_t maxlen, u_int16_t retransCount, u_int32_t retransIntervalMs, bool ackOnly, bool mark=false)
Definition yateiax.h:1370
void setTimeout(u_int64_t tout)
Definition yateiax.h:1454
This class holds an IAX frame.
Definition yateiax.h:956
static void buildMiniFrame(DataBlock &dest, u_int16_t sCallNo, u_int32_t ts, void *data, unsigned int len)
Definition yateiax.h:1058
Type
Definition yateiax.h:961
bool m_retrans
Definition yateiax.h:1109
bool mark() const
Definition yateiax.h:1031
static IAXFrame * parse(const unsigned char *buf, unsigned int len, IAXEngine *engine=0, const SocketAddr *addr=0)
virtual ~IAXFrame()
bool retrans() const
Definition yateiax.h:1010
virtual IAXFullFrame * fullFrame()
DataBlock & data()
Definition yateiax.h:1003
IAXFrame(Type type, u_int16_t sCallNo, u_int32_t tStamp, bool retrans, const unsigned char *buf, unsigned int len, bool mark=false)
static u_int32_t unpackSubclass(u_int8_t value)
u_int16_t sourceCallNo() const
Definition yateiax.h:1017
static u_int8_t packSubclass(u_int32_t value)
static void buildVideoMetaFrame(DataBlock &dest, u_int16_t sCallNo, u_int32_t tStamp, bool mark, void *data, unsigned int len)
DataBlock m_data
Definition yateiax.h:1104
static const char * typeText(int type)
Definition yateiax.h:1097
Type type() const
Definition yateiax.h:996
u_int32_t timeStamp() const
Definition yateiax.h:1024
This class holds an IAX full frame.
Definition yateiax.h:1124
virtual ~IAXFullFrame()
void updateBuffer(u_int16_t maxlen)
virtual void destroyed()
u_int32_t subclass() const
Definition yateiax.h:1233
u_int16_t destCallNo() const
Definition yateiax.h:1212
IAXFullFrame(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo, unsigned char oSeqNo, unsigned char iSeqNo, u_int32_t tStamp, IAXIEList *ieList, u_int16_t maxlen, bool mark=false)
ControlType
Definition yateiax.h:1129
virtual IAXFullFrame * fullFrame()
bool isAuthReq() const
Definition yateiax.h:1240
bool isInval() const
Definition yateiax.h:1249
IAXIEList * removeIEList(bool delObj=true)
IAXFullFrame(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo, unsigned char oSeqNo, unsigned char iSeqNo, u_int32_t tStamp, const unsigned char *buf=0, unsigned int len=0, bool mark=false)
bool updateIEList(bool incoming)
void toString(String &dest, const SocketAddr &local, const SocketAddr &remote, bool incoming)
unsigned char oSeqNo() const
Definition yateiax.h:1219
static const char * controlTypeText(int type)
Definition yateiax.h:1300
unsigned char iSeqNo() const
Definition yateiax.h:1226
IAXIEList * ieList()
Definition yateiax.h:1268
IAXFullFrame(Type type, u_int32_t subclass, u_int16_t sCallNo, u_int16_t dCallNo, unsigned char oSeqNo, unsigned char iSeqNo, u_int32_t tStamp, bool retrans, const unsigned char *buf, unsigned int len, bool mark=false)
Information Element container.
Definition yateiax.h:425
bool createFromFrame(const IAXFullFrame *frame, bool incoming=true)
bool appendIE(IAXIEList &src, IAXInfoElement::Type type)
Definition yateiax.h:492
bool empty()
Definition yateiax.h:461
void insertVersion()
void appendNumeric(IAXInfoElement::Type type, u_int32_t value, u_int8_t len)
Definition yateiax.h:529
void appendString(IAXInfoElement::Type type, unsigned char *src, unsigned len)
Definition yateiax.h:520
void toString(String &dest, const char *indent=0)
IAXIEList(const IAXFullFrame *frame, bool incoming=true)
bool getBinary(IAXInfoElement::Type type, DataBlock &dest)
bool validVersion()
Definition yateiax.h:473
void appendString(IAXInfoElement::Type type, const String &src)
Definition yateiax.h:511
void toBuffer(DataBlock &buf)
bool invalidIEList() const
Definition yateiax.h:448
void clear()
Definition yateiax.h:454
IAXInfoElement * getIE(IAXInfoElement::Type type, bool remove=false)
void appendNull(IAXInfoElement::Type type)
Definition yateiax.h:503
void appendBinary(IAXInfoElement::Type type, unsigned char *data, unsigned len)
Definition yateiax.h:538
bool getString(IAXInfoElement::Type type, String &dest)
void appendIE(IAXInfoElement *ie)
Definition yateiax.h:483
bool getNumeric(IAXInfoElement::Type type, u_int32_t &dest)
A single IAX2 numeric Information Element.
Definition yateiax.h:351
IAXInfoElementBinary(Type type, unsigned char *buf, unsigned len)
Definition yateiax.h:359
static IAXInfoElementBinary * packIP(const SocketAddr &addr)
void setData(void *buf, unsigned len)
Definition yateiax.h:386
virtual void toBuffer(DataBlock &buf)
int length() const
Definition yateiax.h:371
DataBlock & data()
Definition yateiax.h:378
static bool unpackIP(SocketAddr &addr, IAXInfoElementBinary *ie)
virtual void toString(String &buf)
virtual ~IAXInfoElementBinary()
Definition yateiax.h:365
A single IAX2 numeric Information Element.
Definition yateiax.h:300
virtual void toBuffer(DataBlock &buf)
int length() const
Definition yateiax.h:319
IAXInfoElementNumeric(Type type, u_int32_t val, u_int8_t len)
virtual void toString(String &buf)
u_int32_t data() const
Definition yateiax.h:326
virtual ~IAXInfoElementNumeric()
Definition yateiax.h:313
A single IAX2 text Information Element.
Definition yateiax.h:248
IAXInfoElementString(Type type, const char *buf, unsigned len)
Definition yateiax.h:256
virtual ~IAXInfoElementString()
Definition yateiax.h:262
virtual void toBuffer(DataBlock &buf)
int length() const
Definition yateiax.h:268
String & data()
Definition yateiax.h:275
virtual void toString(String &buf)
Definition yateiax.h:288
A single IAX2 Information Element.
Definition yateiax.h:100
Type
Definition yateiax.h:105
static const char * causeName(int code)
Definition yateiax.h:206
IAXInfoElement(Type type)
Definition yateiax.h:167
static const TokenDict s_screening[]
Definition yateiax.h:236
static const TokenDict s_presentation[]
Definition yateiax.h:231
static int causeCode(const char *name, int defVal=0)
Definition yateiax.h:215
virtual void toBuffer(DataBlock &buf)
static const TokenDict s_causeName[]
Definition yateiax.h:221
static const TokenDict s_typeOfNumber[]
Definition yateiax.h:226
static const char * ieText(u_int8_t ieCode)
Definition yateiax.h:198
Type type() const
Definition yateiax.h:178
virtual void toString(String &buf)
virtual ~IAXInfoElement()
Definition yateiax.h:172
IAX2 transaction media data.
Definition yateiax.h:1688
void dropOut(unsigned int len)
Definition yateiax.h:1709
void print(String &buf)
IAXMediaData()
Definition yateiax.h:1694
Meta trunk frame.
Definition yateiax.h:1549
virtual ~IAXMetaTrunkFrame()
IAXMetaTrunkFrame(IAXEngine *engine, const SocketAddr &addr, bool timestamps, unsigned int maxLen, unsigned int sendInterval)
const SocketAddr & addr() const
Definition yateiax.h:1571
unsigned int maxLen() const
Definition yateiax.h:1611
unsigned int calls() const
Definition yateiax.h:1578
void changeCalls(bool add)
Definition yateiax.h:1585
bool send()
Definition yateiax.h:1639
bool trunkTimestamps() const
Definition yateiax.h:1597
unsigned int sendInterval() const
Definition yateiax.h:1604
unsigned int add(u_int16_t sCallNo, const DataBlock &data, u_int32_t tStamp)
bool timerTick(const Time &now=Time())
Definition yateiax.h:1628
An IAX2 transaction.
Definition yateiax.h:1749
u_int16_t localCallNo() const
Definition yateiax.h:1877
static IAXTransaction * factoryOut(IAXEngine *engine, Type type, u_int16_t lcallno, const SocketAddr &addr, IAXIEList &ieList, void *data=0)
void eventTerminated(IAXEvent *event)
bool sendAccept(unsigned int *expires=0)
IAXEvent * getEventRequest(IAXFullFrame *frame, bool &delFrame)
void setUserData(void *data)
Definition yateiax.h:1863
IAXTransaction * processMedia(DataBlock &data, u_int32_t tStamp, int type=IAXFormat::Audio, bool full=false, bool mark=false)
bool sendNoise(u_int8_t noise)
Definition yateiax.h:2168
bool isFrameAcceptable(const IAXFullFrame *frame)
IAXEvent * processMidCallIAXControl(IAXFullFrame *frame, bool &delFrame)
IAXEvent * processMidCallControl(IAXFullFrame *frame, bool &delFrame)
IAXEvent * remoteRejectCall(IAXFullFrame *frame, bool &delFrame)
void print(bool printStats=false, bool printFrames=false, const char *location="status")
IAXTransaction(IAXEngine *engine, Type type, u_int16_t lcallno, const SocketAddr &addr, IAXIEList &ieList, void *data=0)
bool sendRinging()
Definition yateiax.h:2091
IAXTransaction(IAXEngine *engine, IAXFullFrame *frame, u_int16_t lcallno, const SocketAddr &addr, void *data=0)
static const TokenDict s_typeName[]
Definition yateiax.h:2228
Type
Definition yateiax.h:1756
virtual ~IAXTransaction()
void processCallToken(const DataBlock &callToken)
virtual void destroyed()
IAXFullFrame * findInFrame(IAXFrame::Type type, u_int32_t subclass)
IAXEvent * internalReject(const char *reason, u_int8_t code)
IAXEvent * createEvent(u_int8_t evType, bool local, IAXFullFrame *frame, State newState)
IAXEvent * processInternalIncomingRequest(const IAXFullFrame *frame, bool &delFrame)
bool findInFrameAck(const IAXFullFrame *frameOut)
static unsigned char getMaxFrameList()
IAXEvent * processAuthRep(IAXEvent *event)
IAXEngine * getEngine() const
Definition yateiax.h:1814
void init(IAXIEList &ieList)
void * getUserData() const
Definition yateiax.h:1870
const String & username()
Definition yateiax.h:1898
IAXEvent * waitForTerminate(u_int8_t evType=0, bool local=true, IAXFullFrame *frame=0)
void postFrameIes(IAXFrame::Type type, u_int32_t subclass, IAXIEList *ies, u_int32_t tStamp=0, bool ackOnly=false)
void postFrame(IAXFrame::Type type, u_int32_t subclass, void *data=0, u_int16_t len=0, u_int32_t tStamp=0, bool ackOnly=false, bool mark=false)
IAXEvent * getEventStartTrans(IAXFullFrame *frame, bool &delFrame)
u_int32_t expire() const
Definition yateiax.h:2003
u_int32_t capability() const
Definition yateiax.h:1996
static String s_iax_modNoAuthMethod
Definition yateiax.h:2238
bool sendProgress()
Definition yateiax.h:2099
IAXEvent * processAccept(IAXEvent *event)
bool sendAuthReply(const String &response)
IAXEvent * getEventRequest_New(IAXFullFrame *frame, bool &delFrame)
State
Definition yateiax.h:1768
u_int64_t timeStamp() const
Definition yateiax.h:1849
bool changeState(State newState)
IAXFormat * getFormat(int type)
Definition yateiax.h:1941
bool sendHangup(const char *cause=0, u_int8_t code=0)
bool findInFrameTimestamp(const IAXFullFrame *frameOut, IAXFrame::Type type, u_int32_t subclass)
IAXEvent * processInternalOutgoingRequest(IAXFrameOut *frame, bool &delFrame)
bool sendFrame(IAXFrameOut *frame, bool vnak=false)
bool sendDtmf(u_int8_t dtmf)
Definition yateiax.h:2151
bool sendText(const char *text)
void sendUnsupport(u_int32_t subclass)
unsigned int sendMedia(const DataBlock &data, unsigned int tStamp, u_int32_t format, int type=IAXFormat::Audio, bool mark=false)
bool sendReject(const char *cause=0, u_int8_t code=0)
static const char * typeName(int type)
Definition yateiax.h:2214
static String s_iax_modNoUsername
Definition yateiax.h:2253
IAXEvent * keepEvent(IAXEvent *event)
Definition yateiax.h:2596
const SocketAddr & remoteAddr() const
Definition yateiax.h:1891
const String & calledContext()
Definition yateiax.h:1926
u_int32_t formatIn(int type)
Definition yateiax.h:1977
static IAXTransaction * factoryIn(IAXEngine *engine, IAXFullFrame *frame, u_int16_t lcallno, const SocketAddr &addr, void *data=0)
IAXEvent * getEvent(const Time &now=Time())
const String & callingNo()
Definition yateiax.h:1905
const String & authdata()
Definition yateiax.h:2010
void setDestroy()
Definition yateiax.h:2016
u_int32_t format(int type)
Definition yateiax.h:1967
bool enableTrunking(IAXMetaTrunkFrame *trunkFrame, bool efficientUse)
static String s_iax_modInvalidAuth
Definition yateiax.h:2248
IAXEvent * processAuthReq(IAXEvent *event)
IAXTransaction * processFrame(IAXFrame *frame)
bool sendConnected(IAXFullFrame::ControlType subclass, IAXFrame::Type frametype=IAXFrame::Control)
IAXEvent * processRegAck(IAXEvent *event)
IAXEvent * getEventResponse_New(IAXFrameOut *frame, bool &delFrame)
bool sendAnswer()
Definition yateiax.h:2083
IAXEvent * getEventResponse(IAXFrameOut *frame, bool &delFrame)
static const char * stateName(int state)
Definition yateiax.h:2222
State state() const
Definition yateiax.h:1835
const String & calledNo()
Definition yateiax.h:1919
IAXTransaction * retransmitOnVNAK(u_int16_t seqNo)
static String s_iax_modNoMediaFormat
Definition yateiax.h:2243
void ackInFrames()
const String & callingName()
Definition yateiax.h:1912
IAXEvent * createResponse(IAXFrameOut *frame, u_int8_t findType, u_int8_t findSubclass, u_int8_t evType, bool local, State newState)
u_int16_t remoteCallNo() const
Definition yateiax.h:1884
IAXEvent * terminate(u_int8_t evType, bool local, IAXFullFrame *frame=0, bool createIEList=true)
void processMiniNoTs(u_int32_t ts, ObjList &blocks, const Time &now=Time())
IAXMediaData * getData(int type)
Definition yateiax.h:1954
Type type() const
Definition yateiax.h:1821
u_int32_t formatOut(int type)
Definition yateiax.h:1987
static const TokenDict s_stateName[]
Definition yateiax.h:2233
const char * typeName()
Definition yateiax.h:1828
static bool setMaxFrameList(unsigned char value)
bool outgoing() const
Definition yateiax.h:1856
IAXEvent * getEventResponse_Reg(IAXFrameOut *frame, bool &delFrame)
void sendAck(const IAXFullFrame *frame)
const char * stateName()
Definition yateiax.h:1842
IAXTransaction * processMediaFrame(const IAXFullFrame *frame, int type)
bool incrementSeqNo(const IAXFullFrame *frame, bool inbound)
const String & challenge()
Definition yateiax.h:1933
Trunk info.
Definition yateiax.h:1475
void updateTrunking(const NamedList &params, const String &prefix=String::empty(), bool out=true, bool in=true)
void dump(String &buf, const char *sep=" ", bool out=true, bool in=true, bool other=true)
void init(const NamedList &params, const String &prefix=String::empty(), const IAXTrunkInfo *def=0)
IAXTrunkInfo()
Definition yateiax.h:1480
void initTrunking(const NamedList &params, const String &prefix=String::empty(), const IAXTrunkInfo *def=0, bool out=true, bool in=true)
Ephemeral mutex or semaphore locking object.
Definition yateclass.h:5833
Mutex support.
Definition yateclass.h:5607
Mutex(bool recursive=false, const char *name=0)
A named string container class.
Definition yateclass.h:5016
int getIntValue(const String &name, int defvalue=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
NamedList & addParam(NamedString *param)
An object list class.
Definition yateclass.h:1454
Templated smart pointer class.
Definition yateclass.h:1306
A socket address holder.
Definition yateclass.h:6400
A generic socket class.
Definition yateclass.h:7361
A C-style string handling class.
Definition yateclass.h:2131
const char * c_str() const
Definition yateclass.h:2236
static const String & empty()
unsigned int length() const
Definition yateclass.h:2258
A time holding class.
Definition yateclass.h:3927
static u_int64_t msecNow()
Definition yatemime.h:34
Definition yateclass.h:848