-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathcalltable.h
4501 lines (4235 loc) · 140 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 REINVITE 1000
#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)
enum eCallBitFlag {
_CALL_BIT_SAVESIP,
_CALL_BIT_SAVERTP,
_CALL_BIT_SAVERTPHEADER,
_CALL_BIT_SAVERTP_VIDEO,
_CALL_BIT_SAVERTP_VIDEO_HEADER,
_CALL_BIT_PROCESSING_RTP_VIDEO,
_CALL_BIT_SAVEMRCP,
_CALL_BIT_SAVERTCP,
_CALL_BIT_SAVEREGISTERDB,
_CALL_BIT_SAVEREGISTERPCAP,
_CALL_BIT_SAVEAUDIO,
_CALL_BIT_FORMATAUDIO_WAV,
_CALL_BIT_FORMATAUDIO_OGG,
_CALL_BIT_AUDIOTRANSCRIBE,
_CALL_BIT_SAVEGRAPH,
_CALL_BIT_SAVEAUDIOGRAPH,
_CALL_BIT_SKIPCDR,
_CALL_BIT_RUNSCRIPT,
_CALL_BIT_RUNAMOSLQO,
_CALL_BIT_RUNBMOSLQO,
_CALL_BIT_HIDEMESSAGE,
_CALL_BIT_USE_SPOOL_2,
_CALL_BIT_SAVEDTMFDB,
_CALL_BIT_SAVEDTMFPCAP,
_CALL_BIT_SAVEOPTIONSDB,
_CALL_BIT_SAVEOPTIONSPCAP,
_CALL_BIT_SAVENOTIFYDB,
_CALL_BIT_SAVENOTIFYPCAP,
_CALL_BIT_SAVESUBSCRIBEDB,
_CALL_BIT_SAVESUBSCRIBEPCAP
};
#define CALL_FLAG(bit) (((u_int64_t)1) << (bit))
#define FLAG_SAVESIP CALL_FLAG(_CALL_BIT_SAVESIP)
#define FLAG_SAVERTP CALL_FLAG(_CALL_BIT_SAVERTP)
#define FLAG_SAVERTPHEADER CALL_FLAG(_CALL_BIT_SAVERTPHEADER)
#define FLAG_SAVERTP_VIDEO CALL_FLAG(_CALL_BIT_SAVERTP_VIDEO)
#define FLAG_SAVERTP_VIDEO_HEADER CALL_FLAG(_CALL_BIT_SAVERTP_VIDEO_HEADER)
#define FLAG_PROCESSING_RTP_VIDEO CALL_FLAG(_CALL_BIT_PROCESSING_RTP_VIDEO)
#define FLAG_SAVEMRCP CALL_FLAG(_CALL_BIT_SAVEMRCP)
#define FLAG_SAVERTCP CALL_FLAG(_CALL_BIT_SAVERTCP)
#define FLAG_SAVEREGISTERDB CALL_FLAG(_CALL_BIT_SAVEREGISTERDB)
#define FLAG_SAVEREGISTERPCAP CALL_FLAG(_CALL_BIT_SAVEREGISTERPCAP)
#define FLAG_SAVEAUDIO CALL_FLAG(_CALL_BIT_SAVEAUDIO)
#define FLAG_FORMATAUDIO_WAV CALL_FLAG(_CALL_BIT_FORMATAUDIO_WAV)
#define FLAG_FORMATAUDIO_OGG CALL_FLAG(_CALL_BIT_FORMATAUDIO_OGG)
#define FLAG_SAVEAUDIO_WAV (FLAG_SAVEAUDIO|FLAG_FORMATAUDIO_WAV)
#define FLAG_SAVEAUDIO_OGG (FLAG_SAVEAUDIO|FLAG_FORMATAUDIO_OGG)
#define FLAG_AUDIOTRANSCRIBE CALL_FLAG(_CALL_BIT_AUDIOTRANSCRIBE)
#define FLAG_SAVEGRAPH CALL_FLAG(_CALL_BIT_SAVEGRAPH)
#define FLAG_SAVEAUDIOGRAPH CALL_FLAG(_CALL_BIT_SAVEAUDIOGRAPH)
#define FLAG_SKIPCDR CALL_FLAG(_CALL_BIT_SKIPCDR)
#define FLAG_RUNSCRIPT CALL_FLAG(_CALL_BIT_RUNSCRIPT)
#define FLAG_RUNAMOSLQO CALL_FLAG(_CALL_BIT_RUNAMOSLQO)
#define FLAG_RUNBMOSLQO CALL_FLAG(_CALL_BIT_RUNBMOSLQO)
#define FLAG_HIDEMESSAGE CALL_FLAG(_CALL_BIT_HIDEMESSAGE)
#define FLAG_USE_SPOOL_2 CALL_FLAG(_CALL_BIT_USE_SPOOL_2)
#define FLAG_SAVEDTMFDB CALL_FLAG(_CALL_BIT_SAVEDTMFDB)
#define FLAG_SAVEDTMFPCAP CALL_FLAG(_CALL_BIT_SAVEDTMFPCAP)
#define FLAG_SAVEOPTIONSDB CALL_FLAG(_CALL_BIT_SAVEOPTIONSDB)
#define FLAG_SAVEOPTIONSPCAP CALL_FLAG(_CALL_BIT_SAVEOPTIONSPCAP)
#define FLAG_SAVENOTIFYDB CALL_FLAG(_CALL_BIT_SAVENOTIFYDB)
#define FLAG_SAVENOTIFYPCAP CALL_FLAG(_CALL_BIT_SAVENOTIFYPCAP)
#define FLAG_SAVESUBSCRIBEDB CALL_FLAG(_CALL_BIT_SAVESUBSCRIBEDB)
#define FLAG_SAVESUBSCRIBEPCAP CALL_FLAG(_CALL_BIT_SAVESUBSCRIBEPCAP)
#define CDR_FLAG(bit) (((u_int64_t)1) << (bit))
enum eCdrBitFlag {
_CDR_BIT_CHANGE_SRC_PORT_CALLER,
_CDR_BIT_CHANGE_SRC_PORT_CALLED,
_CDR_BIT_UNCONFIRMED_BYE,
_CDR_BIT_ALONE_UNCONFIRMED_BYE,
_CDR_BIT_SRTP_WITHOUT_KEY,
_CDR_BIT_FAS_DETECTED,
_CDR_BIT_ZEROSSRC_DETECTED,
_CDR_BIT_SIPALG_DETECTED,
_CDR_BIT_TELEVENT_EXISTS_REQUEST,
_CDR_BIT_TELEVENT_EXISTS_RESPONSE,
_CDR_BIT_SIP_FRAGMENTED,
_CDR_BIT_RTP_FRAGMENTED,
_CDR_BIT_SDP_EXISTS_MEDIA_TYPE_AUDIO,
_CDR_BIT_SDP_EXISTS_MEDIA_TYPE_IMAGE,
_CDR_BIT_SDP_EXISTS_MEDIA_TYPE_VIDEO,
_CDR_BIT_PROCLIM_SUPPRESS_RTP_READ,
_CDR_BIT_PROCLIM_SUPPRESS_RTP_PROC,
_CDR_BIT_RTCP_EXISTS,
_CDR_BIT_PCAP_IN_SAFESPOOLDIR,
_CDR_BIT_PCAP_DUMP_ERROR_DTL,
_CDR_BIT_PCAP_DUMP_ERROR_MAXPCAPSIZE,
_CDR_BIT_PCAP_DUMP_ERROR_CAPLEN,
_CDR_BIT_RTP_DUPL_SEQ,
_CDR_BIT_SAVE_FLAGS,
_CDR_BIT_SAVE_SIP_PCAP,
_CDR_BIT_SAVE_RTP_PCAP,
_CDR_BIT_SAVE_RTP_PAYLOAD_PCAP,
_CDR_BIT_SAVE_RTCP_PCAP,
_CDR_BIT_SAVE_RTP_GRAPH,
_CDR_BIT_SAVE_AUDIO,
_CDR_BIT_SAVE_AUDIOGRAPH,
_CDR_BIT_PROTO_TCP,
_CDR_BIT_PROTO_UDP
};
#define CDR_CHANGE_SRC_PORT_CALLER CDR_FLAG(_CDR_BIT_CHANGE_SRC_PORT_CALLER)
#define CDR_CHANGE_SRC_PORT_CALLED CDR_FLAG(_CDR_BIT_CHANGE_SRC_PORT_CALLED)
#define CDR_UNCONFIRMED_BYE CDR_FLAG(_CDR_BIT_UNCONFIRMED_BYE)
#define CDR_ALONE_UNCONFIRMED_BYE CDR_FLAG(_CDR_BIT_ALONE_UNCONFIRMED_BYE)
#define CDR_SRTP_WITHOUT_KEY CDR_FLAG(_CDR_BIT_SRTP_WITHOUT_KEY)
#define CDR_FAS_DETECTED CDR_FLAG(_CDR_BIT_FAS_DETECTED)
#define CDR_ZEROSSRC_DETECTED CDR_FLAG(_CDR_BIT_ZEROSSRC_DETECTED)
#define CDR_SIPALG_DETECTED CDR_FLAG(_CDR_BIT_SIPALG_DETECTED)
#define CDR_TELEVENT_EXISTS_REQUEST CDR_FLAG(_CDR_BIT_TELEVENT_EXISTS_REQUEST)
#define CDR_TELEVENT_EXISTS_RESPONSE CDR_FLAG(_CDR_BIT_TELEVENT_EXISTS_RESPONSE)
#define CDR_SIP_FRAGMENTED CDR_FLAG(_CDR_BIT_SIP_FRAGMENTED)
#define CDR_RTP_FRAGMENTED CDR_FLAG(_CDR_BIT_RTP_FRAGMENTED)
#define CDR_SDP_EXISTS_MEDIA_TYPE_AUDIO CDR_FLAG(_CDR_BIT_SDP_EXISTS_MEDIA_TYPE_AUDIO)
#define CDR_SDP_EXISTS_MEDIA_TYPE_IMAGE CDR_FLAG(_CDR_BIT_SDP_EXISTS_MEDIA_TYPE_IMAGE)
#define CDR_SDP_EXISTS_MEDIA_TYPE_VIDEO CDR_FLAG(_CDR_BIT_SDP_EXISTS_MEDIA_TYPE_VIDEO)
#define CDR_PROCLIM_SUPPRESS_RTP_READ CDR_FLAG(_CDR_BIT_PROCLIM_SUPPRESS_RTP_READ)
#define CDR_PROCLIM_SUPPRESS_RTP_PROC CDR_FLAG(_CDR_BIT_PROCLIM_SUPPRESS_RTP_PROC)
#define CDR_RTCP_EXISTS CDR_FLAG(_CDR_BIT_RTCP_EXISTS)
#define CDR_PCAP_IN_SAFESPOOLDIR CDR_FLAG(_CDR_BIT_PCAP_IN_SAFESPOOLDIR)
#define CDR_PCAP_DUMP_ERROR_DTL CDR_FLAG(_CDR_BIT_PCAP_DUMP_ERROR_DTL)
#define CDR_PCAP_DUMP_ERROR_MAXPCAPSIZE CDR_FLAG(_CDR_BIT_PCAP_DUMP_ERROR_MAXPCAPSIZE)
#define CDR_PCAP_DUMP_ERROR_CAPLEN CDR_FLAG(_CDR_BIT_PCAP_DUMP_ERROR_CAPLEN)
#define CDR_RTP_DUPL_SEQ CDR_FLAG(_CDR_BIT_RTP_DUPL_SEQ)
#define CDR_SAVE_FLAGS CDR_FLAG(_CDR_BIT_SAVE_FLAGS)
#define CDR_SAVE_SIP_PCAP CDR_FLAG(_CDR_BIT_SAVE_SIP_PCAP)
#define CDR_SAVE_RTP_PCAP CDR_FLAG(_CDR_BIT_SAVE_RTP_PCAP)
#define CDR_SAVE_RTP_PAYLOAD_PCAP CDR_FLAG(_CDR_BIT_SAVE_RTP_PAYLOAD_PCAP)
#define CDR_SAVE_RTCP_PCAP CDR_FLAG(_CDR_BIT_SAVE_RTCP_PCAP)
#define CDR_SAVE_RTP_GRAPH CDR_FLAG(_CDR_BIT_SAVE_RTP_GRAPH)
#define CDR_SAVE_AUDIO CDR_FLAG(_CDR_BIT_SAVE_AUDIO)
#define CDR_SAVE_AUDIOGRAPH CDR_FLAG(_CDR_BIT_SAVE_AUDIOGRAPH)
#define CDR_PROTO_TCP CDR_FLAG(_CDR_BIT_PROTO_TCP)
#define CDR_PROTO_UDP CDR_FLAG(_CDR_BIT_PROTO_UDP)
#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 {
class CallBranch *c_branch;
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;
ptime = 0;
}
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;
u_int16_t ptime;
};
struct s_sdp_store_data {
vmIPport ip_port;
bool is_caller;
u_int16_t ptime;
inline const bool operator == (const s_sdp_store_data &other) {
return(this->ip_port == other.ip_port &&
this->is_caller == other.is_caller);
}
};
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 to_uri;
string domain_to;
string domain_to_uri;
string branch;
vmIP sip_src_addr;
s_sdp_flags sdp_flags;
u_int16_t ptime;
ip_port_call_info_rtp rtp[2];
bool canceled;
};
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 CallStructs {
public:
struct sInviteCseqData {
sInviteCseqData(u_int64_t time_us = 0) {
this->time_us = time_us;
first_response_100_time_us = 0;
first_response_200_time_us = 0;
first_response_xxx_time_us = 0;
}
u_int64_t time_us;
u_int64_t first_response_100_time_us;
u_int64_t first_response_200_time_us;
u_int64_t first_response_xxx_time_us;
};
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;
map<u_int32_t, u_int32_t> counter_by_cseq;
map<u_int32_t, u_int32_t> counter_reverse_by_cseq;
map<u_int32_t, sInviteCseqData> cseq_data;
string caller;
string called;
string called_invite;
string branch;
};
struct sInviteSD_OrderItem {
inline sInviteSD_OrderItem(unsigned order, u_int64_t ts) {
this->order = order;
this->ts = ts;
}
unsigned order;
u_int64_t ts;
};
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 sSipPacketInfo {
u_int64_t time_us;
vmIPport src;
vmIPport dst;
string sip_first_line;
u_int32_t sip_length;
u_int32_t packet_length;
sCseq cseq;
string getJson();
};
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;
seenokbye = false;
seenokbye_time_usec = 0;
seenbye_and_ok = false;
seenbye_and_ok_time_usec = 0;
seencancel = false;
seencancel_time_usec = 0;
seencancel_and_ok = false;
seencancel_and_ok_time_usec = 0;
seenauthfailed = false;
seenauthfailed_time_usec = 0;
}
bool seenbye;
u_int64_t seenbye_time_usec;
bool seenokbye;
u_int64_t seenokbye_time_usec;
bool seenbye_and_ok;
u_int64_t seenbye_and_ok_time_usec;
bool seencancel;
u_int64_t seencancel_time_usec;
bool seencancel_and_ok;
u_int64_t seencancel_and_ok_time_usec;
bool seenauthfailed;
u_int64_t seenauthfailed_time_usec;
};
struct sCalledInviteBranchItem {
string to;
string to_uri;
string domain_to;
string domain_to_uri;
};
};
class CallBranch : public CallStructs {
public:
CallBranch(Call *call = NULL, unsigned branch_id = 0);
virtual ~CallBranch();
inline void invite_list_lock() {
__SYNC_LOCK_USLEEP(_invite_list_lock, 50);
}
inline void invite_list_unlock() {
__SYNC_UNLOCK(_invite_list_lock);
}
inline bool is_closed() {
return(seenbye ||
seencancel ||
ignore_rtp_after_response_time_usec ||
(lastSIPresponseNum / 100 == 4 && !(lastSIPresponseNum == 401 || lastSIPresponseNum == 407 || lastSIPresponseNum == 491)) ||
lastSIPresponseNum / 100 == 5 ||
lastSIPresponseNum / 100 == 6);
}
void proxy_add(vmIP ip, vmPort port) {
if(ip.isSet()) {
proxies_lock();
proxies.push_back(vmIPport(ip, port));
proxies_unlock();
}
}
bool in_proxy(vmIP ip, vmPort port) {
proxies_lock();
bool rslt = find(proxies.begin(), proxies.end(), vmIPport(ip, port)) != proxies.end();
proxies_unlock();
return(rslt);
}
void proxies_undup(set<vmIP> *proxies_undup, list<vmIPport> *proxies = NULL, vmIPport *exclude = NULL);
void proxies_lock() {
__SYNC_LOCK(this->_proxies_lock);
}
void proxies_unlock() {
__SYNC_UNLOCK(this->_proxies_lock);
}
int64_t get_min_response_100_time_us();
int64_t get_min_response_xxx_time_us();
string get_sip_packets_info_json();
public:
Call *call;
unsigned branch_id;
string branch_call_id;
string branch_fbasename;
vector<sInviteSD_Addr> invite_sdaddr;
map<vmIPportLink, unsigned> invite_sdaddr_map;
vector<sInviteSD_Addr> rinvite_sdaddr;
map<vmIPportLink, unsigned> rinvite_sdaddr_map;
vector<sInviteSD_OrderItem> invite_sdaddr_order;
u_int64_t invite_sdaddr_last_ts;
int8_t invite_sdaddr_all_confirmed;
bool invite_sdaddr_bad_order;
vmIP saddr;
vmPort sport;
vmIP daddr;
vmPort dport;
sCseq invitecseq;
list<sCseq> invitecseq_next;
deque<sCseq> invitecseq_in_dialog;
sCseq byecseq[2];
sCseq messagecseq;
sCseq cancelcseq;
sCseq updatecseq;
string callername;
string caller;
string caller_domain;
string called_to;
string called_uri;
string called_final;
string called_domain_to;
string called_domain_uri;
string called_domain_final;
string caller_tag;
string called_tag_to;
string contact_num;
string contact_domain;
string digest_username;
string digest_realm;
string custom_header1;
string match_header;
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 sipcallerip_rslt;
vmIP sipcalledip_rslt;
vmIP sipcallerip_encaps_rslt;
vmIP sipcalledip_encaps_rslt;
u_int8_t sipcallerip_encaps_prot_rslt;
u_int8_t sipcalledip_encaps_prot_rslt;
vmPort sipcallerport[MAX_SIPCALLERDIP];
vmPort sipcalledport[MAX_SIPCALLERDIP];
vmPort sipcalledport_mod;
vmPort sipcallerport_rslt;
vmPort sipcalledport_rslt;
bool sipcallerdip_reverse;
volatile int _proxies_lock;
list<vmIPport> proxies;
int whohanged;
char oneway;
vmIP lastsrcip;
vmIP lastdstip;
vmIP lastsipcallerip;
vmPort lastsrcport;
map<string, sSipcalleRD_IP> map_sipcallerdip;
map<string, sCalledInviteBranchItem> called_invite_branch_map;
string lastSIPresponse;
int lastSIPresponseNum;
list<sSipResponse> SIPresponse;
list<sSipHistory> SIPhistory;
list<sSipPacketInfo*> SIPpacketInfoList;
bool new_invite_after_lsr487;
bool cancel_lsr487;
int reason_sip_cause;
string reason_sip_text;
int reason_q850_cause;
string reason_q850_text;
string a_ua;
string b_ua;
bool seeninvite;
bool seeninviteok;
bool seenmessage;
bool seenmessageok;
bool seenbye;
u_int64_t seenbye_time_usec;
bool seenokbye;
u_int64_t seenokbye_time_usec;
bool seenbye_and_ok;
bool seenbye_and_ok_permanent;
u_int64_t seenbye_and_ok_time_usec;
bool seencancel;
u_int64_t seencancel_time_usec;
bool seencancel_and_ok;
u_int64_t seencancel_and_ok_time_usec;
bool seenauthfailed;
u_int64_t seenauthfailed_time_usec;
u_int64_t ignore_rtp_after_response_time_usec;
bool unconfirmed_bye;
bool seenRES2XX;
bool seenRES2XX_no_BYE;
bool seenRES18X;
u_int16_t vlan;
bool is_sipalg_detected;
ip_port_call_info ip_port[MAX_IP_PER_CALL];
int ipport_n;
bool logged_max_ip_per_call;
volatile int end_call_rtp;
volatile int end_call_hash_removed;
RTPMAP rtpmap[MAX_IP_PER_CALL][MAX_RTPMAP];
bool rtpmap_used_flags[MAX_IP_PER_CALL];
volatile int rtp_ip_port_counter;
#if CHECK_HASHTABLE_FOR_ALL_CALLS
volatile int rtp_ip_port_counter_add;
#endif
volatile int _invite_list_lock;
bool updateDstnumOnAnswer;
bool updateDstnumFromMessage;
string last_via_branch;
};
struct raws_t {
int ssrc_index;
int rawiterator;
int codec;
int frame_size;
int bit_rate;
struct timeval tv;
string filename;
class RTP *rtp;
};
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_mosf1_avg,
cf_src_mosf1_min,
cf_src_mosf2,
cf_src_mosf2_avg,
cf_src_mosf2_min,
cf_src_mosAD,
cf_src_mosAD_avg,
cf_src_mosAD_min,
cf_dst_mosf1,
cf_dst_mosf1_avg,
cf_dst_mosf1_min,
cf_dst_mosf2,
cf_dst_mosf2_avg,
cf_dst_mosf2_min,
cf_dst_mosAD,
cf_dst_mosAD_avg,
cf_dst_mosAD_min,
cf_src_jitter,
cf_src_jitter_avg,
cf_src_jitter_max,
cf_dst_jitter,
cf_dst_jitter_avg,
cf_dst_jitter_max,
cf_src_received,
cf_dst_received,
cf_src_loss_abs,
cf_dst_loss_abs,
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;
};
#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;
if(nat_aliases) {
delete nat_aliases;
}
}
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) ||