-
Notifications
You must be signed in to change notification settings - Fork 1
/
calltable.h
2591 lines (2384 loc) · 76.8 KB
/
calltable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Martin Vit [email protected]
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2.
*/
/* Calls are stored into indexed array.
* Into one calltable is stored SIP call-id and IP-port of SDP session
*/
#ifndef CALLTABLE_H
#define CALLTABLE_H
// experimental modes:
#define NEW_RTP_FIND__NODES 0
#define NEW_RTP_FIND__PORT_NODES 0
#define NEW_RTP_FIND__MAP_LIST 0
#define NEW_RTP_FIND__NODES__PORT_MODE 1
#define NEW_RTP_FIND__NODES__LIST 0
#define HASH_RTP_FIND__LIST 0
#include <queue>
#include <map>
#include <list>
#include <set>
#include <deque>
#include <vector>
#include <arpa/inet.h>
#include <time.h>
#include <limits.h>
#include <semaphore.h>
#include <pcap.h>
#include <string>
#include "mgcp.h"
#include "rtp.h"
#include "tools.h"
#include "sql_db.h"
#include "voipmonitor.h"
#include "tools_fifo_buffer.h"
#include "record_array.h"
#define MAX_IP_PER_CALL 40 //!< total maxumum of SDP sessions for one call-id
#define MAX_SSRC_PER_CALL 40 //!< total maxumum of SDP sessions for one call-id
#define MAX_FNAME 256 //!< max len of stored call-id
#define MAX_RTPMAP 40 //!< max rtpmap records
#define MAXNODE 150000
#define MAX_SIPCALLERDIP 8
#define MAXLEN_SDP_SESSID 30
#define MAXLEN_SDP_LABEL 20
#define INVITE 1
#define BYE 2
#define CANCEL 3
#define RES10X 100
#define RES18X 180
#define RES182 182
#define RES2XX 200
#define RES2XX_INVITE 200001
#define RES300 300
#define RES3XX 399
#define RES401 401
#define RES403 403
#define RES404 404
#define RES4XX 400
#define RES5XX 500
#define RES6XX 600
#define REGISTER 4
#define MESSAGE 5
#define INFO 6
#define SUBSCRIBE 7
#define OPTIONS 8
#define NOTIFY 9
#define ACK 10
#define PRACK 11
#define PUBLISH 12
#define REFER 13
#define UPDATE 14
#define SKINNY_NEW 100
#define SS7 200
#define MGCP 300
#define IS_SIP_RES18X(sip_method) (sip_method == RES18X || sip_method == RES182)
#define IS_SIP_RES3XX(sip_method) (sip_method == RES300 || sip_method == RES3XX)
#define IS_SIP_RES4XX(sip_method) (sip_method == RES401 || sip_method == RES403 || sip_method == RES404 || sip_method == RES4XX)
#define IS_SIP_RESXXX(sip_method) (sip_method == RES10X || sip_method == RES18X || sip_method == RES182 || sip_method == RES2XX || IS_SIP_RES3XX(sip_method) || IS_SIP_RES4XX(sip_method) || sip_method == RES5XX || sip_method == RES6XX)
#define FLAG_SAVERTP (1 << 0)
#define FLAG_SAVERTCP (1 << 1)
#define FLAG_SAVESIP (1 << 2)
#define FLAG_SAVEREGISTER (1 << 3)
#define FLAG_SAVEAUDIO (1 << 4)
#define FLAG_FORMATAUDIO_WAV (1 << 5)
#define FLAG_FORMATAUDIO_OGG (1 << 6)
#define FLAG_SAVEAUDIO_WAV (FLAG_SAVEAUDIO|FLAG_FORMATAUDIO_WAV)
#define FLAG_SAVEAUDIO_OGG (FLAG_SAVEAUDIO|FLAG_FORMATAUDIO_OGG)
#define FLAG_SAVEGRAPH (1 << 7)
#define FLAG_SAVERTPHEADER (1 << 8)
#define FLAG_SKIPCDR (1 << 9)
#define FLAG_RUNSCRIPT (1 << 10)
#define FLAG_RUNAMOSLQO (1 << 11)
#define FLAG_RUNBMOSLQO (1 << 12)
#define FLAG_HIDEMESSAGE (1 << 13)
#define FLAG_USE_SPOOL_2 (1 << 14)
#define FLAG_SAVEDTMFDB (1 << 15)
#define FLAG_SAVEDTMFPCAP (1 << 16)
#define CDR_NEXT_MAX 10
#define CDR_CHANGE_SRC_PORT_CALLER (1 << 0)
#define CDR_CHANGE_SRC_PORT_CALLED (1 << 1)
#define CDR_UNCONFIRMED_BYE (1 << 2)
#define CDR_ALONE_UNCONFIRMED_BYE (1 << 3)
#define CDR_SRTP_WITHOUT_KEY (1 << 4)
#define CDR_FAS_DETECTED (1 << 5)
#define CDR_ZEROSSRC_DETECTED (1 << 6)
#define CDR_SIPALG_DETECTED (1 << 7)
#define CDR_TELEVENT_EXISTS_REQUEST (1 << 8)
#define CDR_TELEVENT_EXISTS_RESPONSE (1 << 9)
#define CDR_SIP_FRAGMENTED (1 << 10)
#define CDR_RTP_FRAGMENTED (1 << 11)
#define CDR_RTP_STREAM_IN_MULTIPLE_CALLS (1 << 0)
#define CDR_RTP_STREAM_IS_AB (1 << 1)
#define CDR_RTP_STREAM_IS_CALLER (1 << 2)
#define CDR_RTP_STREAM_IS_CALLED (1 << 3)
#define SS7_IAM 1
#define SS7_ACM 6
#define SS7_CPG 44
#define SS7_ANM 9
#define SS7_REL 12
#define SS7_RLC 16
#define NOFAX 0
#define T38FAX 1
#define T30FAX 2
#define iscaller_is_set(iscaller) (iscaller >= 0)
#define iscaller_index(iscaller) (iscaller > 0 ? 1 : 0)
#define iscaller_inv_index(iscaller) (iscaller > 0 ? 0 : 1)
#define iscaller_description(iscaller) (iscaller > 0 ? "caller" : (iscaller == 0 ? "called" : "unknown"))
#define iscaller_inv_description(iscaller) (iscaller > 0 ? "called" : (iscaller == 0 ? "caller" : "unknown"))
#define enable_save_dtmf_db (flags & FLAG_SAVEDTMFDB)
#define enable_save_dtmf_pcap(call) (call->flags & FLAG_SAVEDTMFPCAP)
#define MAXIMUM_CHC_THREADS 3
struct s_dtmf {
enum e_type {
sip_info,
inband,
rfc2833
};
e_type type;
double ts;
char dtmf;
vmIP saddr;
vmIP daddr;
};
enum e_sdp_protocol {
sdp_proto_na,
sdp_proto_rtp,
sdp_proto_srtp,
sdp_proto_t38,
sdp_proto_msrp,
sdp_proto_sprt
};
struct s_sdp_flags {
s_sdp_flags() {
is_fax = 0;
rtcp_mux = 0;
protocol = sdp_proto_na;
}
int operator != (const s_sdp_flags &other) {
return(is_fax != other.is_fax ||
rtcp_mux != other.rtcp_mux);
}
int8_t is_fax;
int8_t rtcp_mux;
int8_t protocol;
};
struct call_rtp {
Call *call;
int8_t iscaller;
u_int16_t is_rtcp;
s_sdp_flags sdp_flags;
};
#if (NEW_RTP_FIND__NODES && NEW_RTP_FIND__NODES__LIST) || HASH_RTP_FIND__LIST || NEW_RTP_FIND__MAP_LIST
struct node_call_rtp : public list<call_rtp*> {
};
#else
struct node_call_rtp : public call_rtp {
node_call_rtp *next;
};
#endif
struct node_call_rtp_ip_port {
node_call_rtp_ip_port *next;
#if HASH_RTP_FIND__LIST
node_call_rtp calls;
#else
node_call_rtp *calls;
#endif
vmIP addr;
vmPort port;
};
struct node_call_rtp_ports {
node_call_rtp_ports() {
#if NEW_RTP_FIND__NODES && NEW_RTP_FIND__NODES__LIST
#else
memset(ports, 0, sizeof(ports));
#endif
}
#if NEW_RTP_FIND__NODES && NEW_RTP_FIND__NODES__LIST
#if NEW_RTP_FIND__NODES__PORT_MODE == 1
node_call_rtp ports[256];
#else
node_call_rtp ports[256*256];
#endif
#else
#if NEW_RTP_FIND__NODES__PORT_MODE == 1
node_call_rtp *ports[256];
#else
node_call_rtp *ports[256*256];
#endif
#endif
};
struct ip_port_call_info_rtp {
vmIP saddr;
vmPort sport;
vmIP daddr;
vmPort dport;
time_t last_packet_time;
};
struct rtp_crypto_config {
unsigned tag;
string suite;
string key;
u_int64_t from_time_us;
};
struct s_sdp_media_data {
s_sdp_media_data() {
ip.clear();
port.clear();
label[0] = 0;
inactive_ip0 = 0;
rtp_crypto_config_list = NULL;
exists_payload_televent = false;
}
vmIP ip;
vmPort port;
char label[MAXLEN_SDP_LABEL];
s_sdp_flags sdp_flags;
int8_t inactive_ip0;
list<rtp_crypto_config> *rtp_crypto_config_list;
RTPMAP rtpmap[MAX_RTPMAP];
bool exists_payload_televent;
};
struct ip_port_call_info {
ip_port_call_info() {
rtp_crypto_config_list = NULL;
canceled = false;
}
~ip_port_call_info() {
if(rtp_crypto_config_list) {
delete rtp_crypto_config_list;
}
}
void setSdpCryptoList(list<rtp_crypto_config> *rtp_crypto_config_list, u_int64_t from_time_us) {
if(rtp_crypto_config_list && rtp_crypto_config_list->size()) {
if(!this->rtp_crypto_config_list) {
this->rtp_crypto_config_list = new FILE_LINE(0) list<rtp_crypto_config>;
for(list<rtp_crypto_config>::iterator iter = rtp_crypto_config_list->begin(); iter != rtp_crypto_config_list->end(); iter++) {
iter->from_time_us = from_time_us;
this->rtp_crypto_config_list->push_back(*iter);
}
} else {
for(list<rtp_crypto_config>::iterator iter = rtp_crypto_config_list->begin(); iter != rtp_crypto_config_list->end(); iter++) {
bool exists = false;
for(list<rtp_crypto_config>::iterator iter2 = this->rtp_crypto_config_list->begin(); iter2 != this->rtp_crypto_config_list->end(); iter2++) {
if(iter->suite == iter2->suite && iter->key == iter2->key) {
exists = true;
break;
}
}
if(!exists) {
iter->from_time_us = from_time_us;
this->rtp_crypto_config_list->push_back(*iter);
}
}
}
}
}
enum eTypeAddr {
_ta_base,
_ta_natalias,
_ta_sdp_reverse_ipport
};
vmIP addr;
u_int8_t type_addr;
vmPort port;
int8_t iscaller;
string sessid;
string sdp_label;
list<rtp_crypto_config> *rtp_crypto_config_list;
string to;
string branch;
vmIP sip_src_addr;
s_sdp_flags sdp_flags;
ip_port_call_info_rtp rtp[2];
bool canceled;
};
struct raws_t {
int ssrc_index;
int rawiterator;
int codec;
int frame_size;
struct timeval tv;
string filename;
};
enum eCallField {
cf_na,
cf_callreference,
cf_callid,
cf_calldate,
cf_calldate_num,
cf_lastpackettime,
cf_duration,
cf_connect_duration,
cf_caller,
cf_called,
cf_caller_country,
cf_called_country,
cf_caller_international,
cf_called_international,
cf_callername,
cf_callerdomain,
cf_calleddomain,
cf_calleragent,
cf_calledagent,
cf_callerip,
cf_calledip,
cf_callerip_country,
cf_calledip_country,
cf_sipproxies,
cf_lastSIPresponseNum,
cf_rtp_src,
cf_rtp_dst,
cf_rtp_src_country,
cf_rtp_dst_country,
cf_callercodec,
cf_calledcodec,
cf_src_mosf1,
cf_src_mosf2,
cf_src_mosAD,
cf_dst_mosf1,
cf_dst_mosf2,
cf_dst_mosAD,
cf_src_jitter,
cf_dst_jitter,
cf_src_loss,
cf_dst_loss,
cf_src_loss_last10sec,
cf_dst_loss_last10sec,
cf_id_sensor,
cf_vlan,
cf_custom_header,
cf__max
};
struct sCallField {
eCallField fieldType;
const char *fieldName;
};
struct sCseq {
inline void null() {
method = -1;
number = 0;
}
inline bool is_set() {
return(method > 0);
}
inline const bool operator == (const sCseq &cseq_other) {
return(this->method == cseq_other.method &&
this->number == cseq_other.number);
}
inline const bool operator != (const sCseq &cseq_other) {
return(this->method != cseq_other.method ||
this->number != cseq_other.number);
}
int method;
u_int32_t number;
};
class Call_abstract {
public:
Call_abstract(int call_type, u_int64_t time_us);
virtual ~Call_abstract() {
alloc_flag = 0;
}
int getTypeBase() { return(type_base); }
bool typeIs(int type) { return(type_base == type || (type_next && type_next == type)); }
bool typeIsOnly(int type) { return(type_base == type && type_next == 0); }
bool typeIsNot(int type) { return(!typeIs(type)); }
bool addNextType(int type);
u_int32_t calltime_s() { return TIME_US_TO_S(first_packet_time_us); };
u_int64_t calltime_us() { return first_packet_time_us; };
struct timeval *get_calltime_tv(struct timeval *ts) {
ts->tv_sec = TIME_US_TO_S(first_packet_time_us);
ts->tv_usec = TIME_US_TO_DEC_US(first_packet_time_us);
return(ts);
}
string get_sensordir();
string get_pathname(eTypeSpoolFile typeSpoolFile, const char *substSpoolDir = NULL);
string get_filename(eTypeSpoolFile typeSpoolFile, const char *fileExtension = NULL);
string get_pathfilename(eTypeSpoolFile typeSpoolFile, const char *fileExtension = NULL);
string dirnamesqlfiles();
char *get_fbasename_safe();
const char *getSpoolDir(eTypeSpoolFile typeSpoolFile) {
return(::getSpoolDir(typeSpoolFile, getSpoolIndex()));
}
int getSpoolIndex() {
extern sExistsColumns existsColumns;
return((flags & FLAG_USE_SPOOL_2) && isSetSpoolDir2() &&
((typeIs(INVITE) && existsColumns.cdr_next_spool_index) ||
(typeIs(MESSAGE) && existsColumns.message_spool_index) ||
(typeIs(REGISTER) && existsColumns.register_state_spool_index && existsColumns.register_failed_spool_index)) ?
1 :
0);
}
bool isEmptyChunkBuffersCount() {
return(!chunkBuffersCount);
}
void incChunkBuffers() {
__sync_add_and_fetch(&chunkBuffersCount, 1);
}
void decChunkBuffers() {
__sync_sub_and_fetch(&chunkBuffersCount, 1);
}
void addTarPos(u_int64_t pos, int type);
bool isAllocFlagOK() {
return(alloc_flag);
}
public:
uint16_t alloc_flag;
int type_base;
int type_next;
u_int64_t first_packet_time_us;
char fbasename[MAX_FNAME];
char fbasename_safe[MAX_FNAME];
u_int64_t fname_register;
int useSensorId;
int useDlt;
pcap_t *useHandle;
string force_spool_path;
volatile unsigned int flags;
void *user_data;
int user_data_type;
protected:
list<u_int64_t> tarPosSip;
list<u_int64_t> tarPosRtp;
list<u_int64_t> tarPosGraph;
private:
volatile u_int16_t chunkBuffersCount;
};
struct sChartsCacheCallData {
map<u_int32_t, cEvalFormula::sValue> value_map;
};
/**
* This class implements operations on call
*/
class Call : public Call_abstract {
public:
enum eTable {
_t_cdr = 1,
_t_cdr_next = 2,
_t_cdr_next_end = 20,
_t_cdr_country_code = 21,
_t_cdr_proxy,
_t_cdr_sipresp,
_t_cdr_siphistory,
_t_cdr_rtp,
_t_cdr_sdp
};
enum eStoreFlags {
_sf_charts_cache = 1
};
struct sSipcalleRD_IP {
sSipcalleRD_IP() {
for(unsigned i = 0; i < MAX_SIPCALLERDIP; i++) {
sipcallerip[i].clear();
sipcalledip[i].clear();
sipcalledip_mod.clear();
sipcallerport[i].clear();
sipcalledport[i].clear();
sipcalledport_mod.clear();
}
}
vmIP sipcallerip[MAX_SIPCALLERDIP];
vmIP sipcalledip[MAX_SIPCALLERDIP];
vmIP sipcalledip_mod;
vmPort sipcallerport[MAX_SIPCALLERDIP];
vmPort sipcalledport[MAX_SIPCALLERDIP];
vmPort sipcalledport_mod;
};
struct sMergeLegInfo {
sMergeLegInfo() {
seenbye = false;
seenbye_time_usec = 0;
seenbyeandok = false;
seenbyeandok_time_usec = 0;
seencancelandok = false;
seencancelandok_time_usec = 0;
}
bool seenbye;
u_int64_t seenbye_time_usec;
bool seenbyeandok;
u_int64_t seenbyeandok_time_usec;
bool seencancelandok;
u_int64_t seencancelandok_time_usec;
};
struct sInviteSD_Addr {
sInviteSD_Addr() {
confirmed = false;
counter = 0;
counter_reverse = 0;
}
vmIP saddr;
vmIP daddr;
vmPort sport;
vmPort dport;
bool confirmed;
unsigned counter;
unsigned counter_reverse;
string caller;
string called;
string called_invite;
};
struct sSipResponse {
sSipResponse(const char *SIPresponse = NULL, int SIPresponseNum = 0) {
if(SIPresponse) {
this->SIPresponse = SIPresponse;
}
this->SIPresponseNum = SIPresponseNum;
}
string SIPresponse;
int SIPresponseNum;
};
struct sSipHistory {
sSipHistory(u_int64_t time_us = 0,
const char *SIPrequest = NULL,
const char *SIPresponse = NULL, int SIPresponseNum = 0) {
this->time_us = time_us;
if(SIPrequest && SIPrequest[0]) {
this->SIPrequest = SIPrequest;
}
if(SIPresponse && SIPresponse[0]) {
this->SIPresponse = SIPresponse;
}
this->SIPresponseNum = SIPresponseNum;
}
u_int64_t time_us;
string SIPrequest;
string SIPresponse;
int SIPresponseNum;
};
struct sRtcpXrDataItem {
timeval tv;
int16_t moslq;
int16_t nlr;
vmIP ip_local;
vmIP ip_remote;
};
struct sRtcpXrDataSsrc : public list<sRtcpXrDataItem> {
void add(timeval tv, int16_t moslq, int16_t nlr, vmIP ip_local, vmIP ip_remote) {
sRtcpXrDataItem dataItem;
dataItem.tv = tv;
dataItem.moslq = moslq;
dataItem.nlr = nlr;
dataItem.ip_local = ip_local;
dataItem.ip_remote = ip_remote;
this->push_back(dataItem);
}
};
struct sRtcpXrData : public map<u_int32_t, sRtcpXrDataSsrc> {
void add(u_int32_t ssrc, timeval tv, int16_t moslq, int16_t nlr, vmIP ip_local, vmIP ip_remote) {
(*this)[ssrc].add(tv, moslq, nlr, ip_local, ip_remote);
}
};
struct sUdptlDumper {
sUdptlDumper() {
dumper = NULL;
last_seq = 0;
}
~sUdptlDumper() {
if(dumper) {
delete dumper;
}
}
PcapDumper *dumper;
unsigned last_seq;
};
enum eVoicemail {
voicemail_na,
voicemail_active,
voicemail_inactive
};
struct sAudioBufferData {
sAudioBufferData() {
audiobuffer = NULL;
clearLast();
}
void set(void **destBuffer, int seqno, u_int32_t ssrc, struct timeval *ts) {
if(audiobuffer && audiobuffer->is_enable()) {
u_int64_t actTimeMS = getTimeMS(ts);
if(!last_seq || !last_ssrc ||
(last_ssrc == ssrc ?
(last_seq < seqno || (last_seq - seqno) > 30000) :
last_ssrc_time_ms < actTimeMS - 200)) {
*destBuffer = audiobuffer;
last_seq = seqno;
last_ssrc = ssrc;
last_ssrc_time_ms = actTimeMS;
}
}
}
void clearLast() {
last_seq = 0;
last_ssrc = 0;
last_ssrc_time_ms = 0;
}
FifoBuffer *audiobuffer;
int last_seq;
u_int32_t last_ssrc;
u_int64_t last_ssrc_time_ms;
};
enum eTxtType {
txt_type_na,
txt_type_sdp_xml
};
struct sTxt {
u_int64_t time;
eTxtType type;
string txt;
};
public:
bool is_ssl; //!< call was decrypted
RTP *rtp[MAX_SSRC_PER_CALL]; //!< array of RTP streams
RTP *rtpab[2];
map<int, class RTPsecure*> rtp_secure_map;
volatile int rtplock;
unsigned long call_id_len; //!< length of call-id
string call_id; //!< call-id from SIP session
map<string, bool> *call_id_alternative;
volatile int _call_id_alternative_lock;
char callername[256]; //!< callerid name from SIP header
char caller[256]; //!< From: xxx
char caller_domain[256]; //!< From: xxx
char called[256]; //!< To: xxx
map<string, string> called_invite_branch_map;
char called_domain[256]; //!< To: xxx
char contact_num[64]; //!<
char contact_domain[128]; //!<
char digest_username[64]; //!<
char digest_realm[64]; //!<
int register_expires;
sCseq byecseq[2];
sCseq invitecseq;
list<sCseq> invitecseq_next;
deque<sCseq> invitecseq_in_dialog;
sCseq messagecseq;
sCseq registercseq;
sCseq cancelcseq;
sCseq updatecseq;
char custom_header1[256]; //!< Custom SIP header
char match_header[128]; //!< Custom SIP header
bool seeninvite; //!< true if we see SIP INVITE within the Call
bool seeninviteok; //!< true if we see SIP INVITE within the Call
bool seenmessage;
bool seenmessageok;
bool seenbye; //!< true if we see SIP BYE within the Call
u_int64_t seenbye_time_usec;
bool seenbyeandok; //!< true if we see SIP OK TO BYE within the Call
u_int64_t seenbyeandok_time_usec;
bool seencancelandok; //!< true if we see SIP OK TO CANCEL within the Call
u_int64_t seencancelandok_time_usec;
bool unconfirmed_bye;
bool seenRES2XX;
bool seenRES2XX_no_BYE;
bool seenRES18X;
bool sighup; //!< true if call is saving during sighup
char a_ua[1024]; //!< caller user agent
char b_ua[1024]; //!< callee user agent
RTPMAP rtpmap[MAX_IP_PER_CALL][MAX_RTPMAP]; //!< rtpmap for every rtp stream
RTP *lastcallerrtp; //!< last RTP stream from caller
RTP *lastcalledrtp; //!< last RTP stream from called
vmIP saddr; //!< source IP address of first INVITE
vmPort sport; //!< source port of first INVITE
vmIP daddr;
vmPort dport;
int whohanged; //!< who hanged up. 0 -> caller, 1-> callee, -1 -> unknown
int recordstopped; //!< flag holding if call was stopped to avoid double free
int dtmfflag; //!< used for holding dtmf states
unsigned int dtmfflag2[2]; //!< used for holding dtmf states
double lastdtmf_time; //!< used for holding time of last dtmf
string hold_times; //!< used for record hold times
bool hold_status; //!< hold status var
bool is_fas_detected; //!< detected FAS (False Answer Supervision)
bool is_zerossrc_detected; //!< detected zero SSRC
bool is_sipalg_detected; //!< detected sip-alg
int silencerecording;
int recordingpausedby182;
int msgcount;
int regcount;
int regcount_after_4xx;
int reg401count;
int reg401count_all;
list<d_item2<vmIP, u_int16_t> > reg401count_sipcallerip_vlan;
int reg403count;
int reg404count;
int reg200count;
int regstate;
bool regresponse;
timeval regrrdstart; // time of first REGISTER
int regrrddiff; // RRD diff time REGISTER<->OK in [ms]- RFC6076
uint64_t regsrcmac; // mac if ether layer present in REGISTER
int last_sip_method;
volatile unsigned int rtppacketsinqueue;
volatile int end_call_rtp;
volatile int end_call_hash_removed;
volatile int push_call_to_calls_queue;
volatile int push_register_to_registers_queue;
unsigned int ps_drop;
unsigned int ps_ifdrop;
vector<u_int64_t> forcemark_time;
volatile int _forcemark_lock;
int first_codec;
bool has_second_merged_leg;
float a_mos_lqo;
float b_mos_lqo;
u_int64_t progress_time_us; //!< time in u_seconds of 18X response
u_int64_t first_rtp_time_us; //!< time in u_seconds of first RTP packet
u_int64_t connect_time_us; //!< time in u_seconds of 200 OK
u_int64_t last_signal_packet_time_us;
u_int64_t last_rtp_packet_time_us;
u_int64_t last_rtp_a_packet_time_us;
u_int64_t last_rtp_b_packet_time_us;
time_t destroy_call_at;
time_t destroy_call_at_bye;
time_t destroy_call_at_bye_confirmed;
std::queue <s_dtmf> dtmf_history;
u_int64_t first_invite_time_us;
u_int64_t first_response_100_time_us;
u_int64_t first_response_xxx_time_us;
u_int64_t first_message_time_us;
u_int64_t first_response_200_time_us;
uint8_t caller_sipdscp;
uint8_t called_sipdscp;
int isfax;
char seenudptl;
bool exists_udptl_data;
bool not_acceptable;
bool sip_fragmented;
bool rtp_fragmented;
void *rtp_cur[2]; //!< last RTP structure in direction 0 and 1 (iscaller = 1)
void *rtp_prev[2]; //!< previouse RTP structure in direction 0 and 1 (iscaller = 1)
vmIP sipcallerip[MAX_SIPCALLERDIP]; //!< SIP signalling source IP address
vmIP sipcalledip[MAX_SIPCALLERDIP]; //!< SIP signalling destination IP address
vmIP sipcalledip_mod;
vmIP sipcalledip_rslt;
vmPort sipcallerport[MAX_SIPCALLERDIP];
vmPort sipcalledport[MAX_SIPCALLERDIP];
vmPort sipcalledport_mod;
vmPort sipcalledport_rslt;
map<string, sSipcalleRD_IP> map_sipcallerdip;
vmIP lastsipcallerip;
bool sipcallerdip_reverse;
list<sInviteSD_Addr> invite_sdaddr;
list<sInviteSD_Addr> rinvite_sdaddr;
list<unsigned> invite_sdaddr_order;
char lastSIPresponse[128];
int lastSIPresponseNum;
list<sSipResponse> SIPresponse;
list<sSipHistory> SIPhistory;
bool new_invite_after_lsr487;
bool cancel_lsr487;
int reason_sip_cause;
string reason_sip_text;
int reason_q850_cause;
string reason_q850_text;
char *contenttype;
char *message;
char *message_info;
int content_length;
unsigned int dcs;
eVoicemail voicemail;
int last_callercodec; //!< Last caller codec
int last_calledcodec; //!< Last called codec
int codec_caller;
int codec_called;
unsigned max_length_sip_data;
unsigned max_length_sip_packet;
sAudioBufferData audioBufferData[2];
unsigned int skinny_partyid;
int *listening_worker_run;
pthread_mutex_t listening_worker_run_lock;
int thread_num;
int thread_num_rd;
char oneway;
char absolute_timeout_exceeded;
char zombie_timeout_exceeded;
char bye_timeout_exceeded;
char rtp_timeout_exceeded;
char sipwithoutrtp_timeout_exceeded;
char oneway_timeout_exceeded;
char force_terminate;
char pcap_drop;
vmIP lastsrcip;
vmIP lastdstip;
vmPort lastsrcport;
void *listening_worker_args;
int ssrc_n; //!< last index of rtp array
int ipport_n; //!< last index of addr and port array
RTP *lastraw[2];
string geoposition;
/* obsolete
map<string, string> custom_headers;
*/
map<int, map<int, dstring> > custom_headers_content_cdr;
map<int, map<int, dstring> > custom_headers_content_message;
volatile int _custom_headers_content_sync;
volatile int _proxies_lock;
list<vmIP> proxies;
bool onInvite;
bool onCall_2XX;
bool onCall_18X;
bool updateDstnumOnAnswer;
bool updateDstnumFromMessage;
bool force_close;
unsigned int caller_silence;
unsigned int called_silence;
unsigned int caller_noise;
unsigned int called_noise;
unsigned int caller_lastsilence;
unsigned int called_lastsilence;
unsigned int caller_clipping_8k;
unsigned int called_clipping_8k;
u_int16_t vlan;
unsigned int lastcallerssrc;
unsigned int lastcalledssrc;
map<string, sMergeLegInfo> mergecalls;
volatile int _mergecalls_lock;
bool rtp_zeropackets_stored;
sRtcpXrData rtcpXrData;
unsigned last_udptl_seq;
u_int32_t iscaller_consecutive[2];
string mgcp_callid;
list<u_int32_t> mgcp_transactions;
map<u_int32_t, sMgcpRequest> mgcp_requests;
map<u_int32_t, sMgcpResponse> mgcp_responses;
u_int64_t last_mgcp_connect_packet_time_us;
u_int64_t counter;
static u_int64_t counter_s;
bool syslog_sdp_multiplication;
list<sTxt> txt;
volatile int _txt_lock;
bool televent_exists_request;
bool televent_exists_response;
/**
* constructor
*
* @param call_id unique identification of call parsed from packet
* @param call_id_len lenght of the call_id buffer
* @param time time of the first packet
*
*/
Call(int call_type, char *call_id, unsigned long call_id_len, vector<string> *call_id_alternative, u_int64_t time_us);
/**
* destructor
*
*/
~Call();
int get_index_by_ip_port(vmIP addr, vmPort port, bool use_sip_src_addr = false);
int get_index_by_sessid_to(char *sessid, char *to, vmIP sip_src_addr, ip_port_call_info::eTypeAddr type_addr);
int get_index_by_iscaller(int iscaller);
bool is_multiple_to_branch();
bool to_is_canceled(char *to);
string get_to_not_canceled();
/**
* @brief close all rtp[].gfileRAW
*
* close all RTP[].gfileRAW to flush writes
*
*/
void closeRawFiles();
/**
* @brief read RTP packet
*
* Used for reading RTP packet
*
*/
bool read_rtp(struct packet_s *packetS, int iscaller, bool find_by_dest, bool stream_in_multiple_calls, char is_fax, char enable_save_packet, char *ifname = NULL);
inline bool _read_rtp(struct packet_s *packetS, int iscaller, bool find_by_dest, bool stream_in_multiple_calls, char *ifname, bool *record_dtmf, bool *disable_save);
inline void _save_rtp(packet_s *packetS, char is_fax, char enable_save_packet, bool record_dtmf, bool forceVirtualUdp = false);
/**
* @brief read RTCP packet
*
* Used for reading RTCP packet
*
*/
bool read_rtcp(struct packet_s *packetS, int iscaller, char enable_save_packet);
void read_dtls(struct packet_s *packetS);
/**
* @brief adds RTP stream to the this Call
*
* Adds RTP stream to the this Call which is identified by IP address and port number
*
* @param addr IP address of the RTP stream
* @param port port number of the RTP stream
*
* @return return 0 on success, 1 if IP and port is duplicated and -1 on failure
*/
int add_ip_port(vmIP sip_src_addr, vmIP addr, ip_port_call_info::eTypeAddr type_addr, vmPort port, pcap_pkthdr *header,
char *sessid, char *sdp_label, list<rtp_crypto_config> *rtp_crypto_config_list, char *to, char *branch, int iscaller, RTPMAP *rtpmap, s_sdp_flags sdp_flags);