forked from kvishnivetsky/sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalltable.h
3058 lines (2838 loc) · 89.9 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"
#include "calltable_base.h"
#include "dtls.h"
#define MAX_IP_PER_CALL 40 //!< total maxumum of SDP sessions for one call-id
#define MAX_SSRC_PER_CALL_FIX 40 //!< total maxumum of SDP sessions for one call-id
#if CALL_RTP_DYNAMIC_ARRAY
typedef vector<RTP*> CALL_RTP_DYNAMIC_ARRAY_TYPE;
#endif
#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_SAVESIP (1 << 1)
#define FLAG_SAVERTP (1 << 2)
#define FLAG_SAVERTPHEADER (1 << 3)
#define FLAG_SAVERTP_VIDEO (1 << 4)
#define FLAG_SAVERTP_VIDEO_HEADER (1 << 5)
#define FLAG_PROCESSING_RTP_VIDEO (1 << 6)
#define FLAG_SAVEMRCP (1 << 7)
#define FLAG_SAVERTCP (1 << 8)
#define FLAG_SAVEREGISTER (1 << 9)
#define FLAG_SAVEAUDIO (1 << 10)
#define FLAG_FORMATAUDIO_WAV (1 << 11)
#define FLAG_FORMATAUDIO_OGG (1 << 12)
#define FLAG_SAVEAUDIO_WAV (FLAG_SAVEAUDIO|FLAG_FORMATAUDIO_WAV)
#define FLAG_SAVEAUDIO_OGG (FLAG_SAVEAUDIO|FLAG_FORMATAUDIO_OGG)
#define FLAG_SAVEGRAPH (1 << 13)
#define FLAG_SKIPCDR (1 << 14)
#define FLAG_RUNSCRIPT (1 << 15)
#define FLAG_RUNAMOSLQO (1 << 16)
#define FLAG_RUNBMOSLQO (1 << 17)
#define FLAG_HIDEMESSAGE (1 << 18)
#define FLAG_USE_SPOOL_2 (1 << 19)
#define FLAG_SAVEDTMFDB (1 << 20)
#define FLAG_SAVEDTMFPCAP (1 << 21)
#define FLAG_SAVEOPTIONSDB (1 << 22)
#define FLAG_SAVEOPTIONSPCAP (1 << 23)
#define FLAG_SAVENOTIFYDB (1 << 24)
#define FLAG_SAVENOTIFYPCAP (1 << 25)
#define FLAG_SAVESUBSCRIBEDB (1 << 26)
#define FLAG_SAVESUBSCRIBEPCAP (1 << 27)
#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_SDP_EXISTS_MEDIA_TYPE_AUDIO (1 << 12)
#define CDR_SDP_EXISTS_MEDIA_TYPE_IMAGE (1 << 13)
#define CDR_SDP_EXISTS_MEDIA_TYPE_VIDEO (1 << 14)
#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_SAM 2
#define SS7_ACM 6
#define SS7_CPG 44
#define SS7_ANM 9
#define SS7_REL 12
#define SS7_RLC 16
#define SS7_FLAG_SONUS (1 << 0)
#define SS7_FLAG_RUDP (1 << 1)
#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)
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,
sdp_proto_tcp_mrcpv2
};
struct s_sdp_flags : public s_sdp_flags_base {
s_sdp_flags() {
protocol = sdp_proto_na;
}
inline int operator != (const s_sdp_flags &other) {
return(*(s_sdp_flags_base*)this != other);
}
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 srtp_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;
srtp_crypto_config_list = NULL;
srtp_fingerprint = NULL;
exists_payload_televent = false;
}
vmIP ip;
vmPort port;
char label[MAXLEN_SDP_LABEL];
s_sdp_flags sdp_flags;
int8_t inactive_ip0;
list<srtp_crypto_config> *srtp_crypto_config_list;
string *srtp_fingerprint;
RTPMAP rtpmap[MAX_RTPMAP];
bool exists_payload_televent;
};
struct ip_port_call_info {
ip_port_call_info() {
srtp = false;
srtp_crypto_config_list = NULL;
srtp_fingerprint = NULL;
canceled = false;
}
~ip_port_call_info() {
if(srtp_crypto_config_list) {
delete srtp_crypto_config_list;
}
if(srtp_fingerprint) {
delete srtp_fingerprint;
}
}
void setSrtp() {
srtp = true;
}
void setSrtpCryptoConfig(list<srtp_crypto_config> *srtp_crypto_config_list, u_int64_t from_time_us) {
if(srtp_crypto_config_list && srtp_crypto_config_list->size()) {
if(!this->srtp_crypto_config_list) {
this->srtp_crypto_config_list = new FILE_LINE(0) list<srtp_crypto_config>;
for(list<srtp_crypto_config>::iterator iter = srtp_crypto_config_list->begin(); iter != srtp_crypto_config_list->end(); iter++) {
iter->from_time_us = from_time_us;
this->srtp_crypto_config_list->push_back(*iter);
}
} else {
for(list<srtp_crypto_config>::iterator iter = srtp_crypto_config_list->begin(); iter != srtp_crypto_config_list->end(); iter++) {
bool exists = false;
for(list<srtp_crypto_config>::iterator iter2 = this->srtp_crypto_config_list->begin(); iter2 != this->srtp_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->srtp_crypto_config_list->push_back(*iter);
}
}
}
}
}
void setSrtpFingerprint(string *srtp_fingerprint) {
if(srtp_fingerprint) {
if(!this->srtp_fingerprint) {
this->srtp_fingerprint = new FILE_LINE(0) string;
}
*this->srtp_fingerprint = *srtp_fingerprint;
}
}
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;
bool srtp;
list<srtp_crypto_config> *srtp_crypto_config_list;
string *srtp_fingerprint;
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_callerip_encaps,
cf_calledip_encaps,
cf_callerip_encaps_prot,
cf_calledip_encaps_prot,
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;
};
#define P_FLAGS_IMAX 10
#define P_FLAGS_MAX 200
class Call_abstract {
public:
enum ePFlags {
_p_flag_na,
_p_flag_dumper_open, // 1
_p_flag_dumper_open_ok, // 2
_p_flag_dumper_dump, // 3
_p_flag_dumper_dump_end, // 4
_p_flag_dumper_dump_close, // 5
_p_flag_dumper_dump_close_2, // 6
_p_flag_dumper_dump_close_3, // 7
_p_flag_dumper_dump_close_4, // 8
_p_flag_dumper_dump_close_5, // 9
_p_flag_dumper_dump_close_end, // 10
_p_flag_dumper_dump_close_not_async, // 11
_p_flag_dumper_set_state_close, // 12
_p_flag_init_tar_buffer, // 13
_p_flag_init_tar_buffer_end, // 14
_p_flag_fzh_close, // 15
_p_flag_fzh_flushbuffer_1, // 16
_p_flag_fzh_flushbuffer_2, // 17
_p_flag_fzh_flushbuffer_3, // 18
_p_flag_fzh_flushtar_1, // 19
_p_flag_fzh_flushtar_2, // 20
_p_flag_fzh_flushtar_3, // 21
_p_flag_fzh_write_1, // 22
_p_flag_fzh_write_2, // 23
_p_flag_fzh_compress_ev_1, // 24
_p_flag_fzh_compress_ev_2, // 25
_p_flag_chb_add_tar_pos, // 26
_p_flag_destroy_tar_buffer, // 27
_p_flag_inc_chunk_buffer, // 28
_p_flag_dec_chunk_buffer // 29
};
struct sChbIndex {
inline sChbIndex(void *chb, const char *name) {
this->chb = chb;
this->name = name;
}
void *chb;
string name;
friend inline const bool operator < (const sChbIndex &i1, const sChbIndex &i2) {
return(i1.chb < i2.chb ? 1 : i1.chb > i2.chb ? 0 :
i1.name < i2.name);
}
};
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);
}
#if DEBUG_ASYNC_TAR_WRITE
bool isEmptyChunkBuffersCount() {
__SYNC_LOCK(chunkBuffersCount_sync);
bool rslt = chunkBuffersMap.size() == 0;
__SYNC_UNLOCK(chunkBuffersCount_sync);
return(rslt);
}
int getChunkBuffersCount() {
__SYNC_LOCK(chunkBuffersCount_sync);
int rslt = chunkBuffersMap.size();
__SYNC_UNLOCK(chunkBuffersCount_sync);
return(rslt);
}
bool incChunkBuffers(u_char index, void *chb, const char *name) {
bool rslt = false;
__SYNC_LOCK(chunkBuffersCount_sync);
this->addPFlag(index, _p_flag_inc_chunk_buffer);
map<sChbIndex, bool>::iterator iter = chunkBuffersMap.find(sChbIndex(chb, name));
if(iter == chunkBuffersMap.end()) {
chunkBuffersMap[sChbIndex(chb, name)] = true;
rslt = true;
}
__SYNC_UNLOCK(chunkBuffersCount_sync);
return(rslt);
}
bool decChunkBuffers(u_char index, void *chb, const char *name) {
bool rslt = false;
__SYNC_LOCK(chunkBuffersCount_sync);
this->addPFlag(index, _p_flag_dec_chunk_buffer);
map<sChbIndex, bool>::iterator iter = chunkBuffersMap.find(sChbIndex(chb, name));
if(iter != chunkBuffersMap.end()) {
chunkBuffersMap.erase(iter);
rslt = true;
}
__SYNC_UNLOCK(chunkBuffersCount_sync);
return(rslt);
}
void addPFlag(u_char index, u_char pflag) {
if(index >= 0 && index < P_FLAGS_IMAX && isAllocFlagOK() && p_flags_count[index] < P_FLAGS_MAX - 1) {
p_flags[index][p_flags_count[index]++] = pflag;
}
}
bool isChunkBuffersCountSyncOK() {
return(chunkBuffersCount_sync == 0 || chunkBuffersCount_sync == 1);
}
bool isChunkBuffersCountSyncOK_wait() {
if(isChunkBuffersCountSyncOK()) {
return(true);
}
for(unsigned i = 0; i < 3; i++) {
usleep(10);
if(isChunkBuffersCountSyncOK()) {
return(true);
}
}
return(false);
}
#else
bool isEmptyChunkBuffersCount() {
return(chunkBuffersCount == 0);
}
int getChunkBuffersCount() {
return(chunkBuffersCount);
}
void incChunkBuffers() {
__SYNC_INC(chunkBuffersCount);
}
void decChunkBuffers() {
if(chunkBuffersCount == 0) {
syslog(LOG_NOTICE, "invalid zero sync in decChunkBuffers in call %s", fbasename);
}
__SYNC_DEC(chunkBuffersCount);
}
#endif
void addTarPos(u_int64_t pos, int type);
bool isAllocFlagOK() {
return(alloc_flag == 1);
}
bool isAllocFlagSetAsFree() {
return(alloc_flag == 0);
}
public:
volatile uint8_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 long 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:
#if DEBUG_ASYNC_TAR_WRITE
map<sChbIndex, bool> chunkBuffersMap;
volatile int chunkBuffersCount_sync;
u_char p_flags[P_FLAGS_IMAX][P_FLAGS_MAX];
u_char p_flags_count[P_FLAGS_IMAX];
#else
volatile int chunkBuffersCount;
#endif
u_int64_t created_at;
friend class cDestroyCallsInfo;
friend class ChunkBuffer;
};
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_db = 1,
_sf_charts_cache = 2
};
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;
seenauthfailed = false;
seenauthfailed_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;
bool seenauthfailed;
u_int64_t seenauthfailed_time_usec;
};
struct sInviteSD_Addr {
sInviteSD_Addr() {
confirmed = false;
counter = 0;
counter_reverse = 0;
}
vmIP saddr;
vmIP daddr;
vmIP saddr_first;
vmIP daddr_first;
u_int8_t saddr_first_protocol;
u_int8_t daddr_first_protocol;
vmPort sport;
vmPort dport;
bool confirmed;
unsigned counter;
unsigned counter_reverse;
string caller;
string called;
string called_invite;
string branch;
};
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_fix[MAX_SSRC_PER_CALL_FIX]; //!< array of RTP streams
int ssrc_n; //!< last index of rtp array
#if CALL_RTP_DYNAMIC_ARRAY
vector<RTP*> *rtp_dynamic;
#endif
volatile bool rtp_remove_flag;
RTP *rtpab[2];
map<int, class RTPsecure*> rtp_secure_map;
cDtls *dtls;
volatile int rtplock_sync;
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, dstring> 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 seenauthfailed;
u_int64_t seenauthfailed_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
bool rtpmap_used_flags[MAX_IP_PER_CALL];
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;
bool save_energylevels;
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
list<u_int32_t> *reg_tcp_seq;
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 sipcallerip_encaps;
vmIP sipcalledip_encaps;
u_int8_t sipcallerip_encaps_prot;
u_int8_t sipcalledip_encaps_prot;
vmIP sipcalledip_rslt;
vmIP sipcalledip_encaps_rslt;
u_int8_t sipcalledip_encaps_prot_rslt;
vmPort sipcallerport[MAX_SIPCALLERDIP];