forked from voipmonitor/sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calltable.h
1998 lines (1828 loc) · 58.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 support@voipmonitor.org
* 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
#include <queue>
#include <map>
#include <list>
#include <set>
#include <arpa/inet.h>
#include <time.h>
#include <limits.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 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 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 SS7_IAM 1
#define SS7_ACM 6
#define SS7_CPG 44
#define SS7_ANM 9
#define SS7_REL 12
#define SS7_RLC 16
#define USE_UNREPLIED_INVITE_MESSAGE 0
struct s_dtmf {
enum e_type {
sip_info,
inband,
rfc2833
};
e_type type;
double ts;
char dtmf;
unsigned int saddr;
unsigned int 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 hash_node_call {
hash_node_call *next;
Call *call;
int8_t iscaller;
u_int16_t is_rtcp;
s_sdp_flags sdp_flags;
};
struct hash_node {
hash_node *next;
hash_node_call *calls;
u_int32_t addr;
u_int16_t port;
};
struct ip_port_call_info_rtp {
volatile u_int32_t saddr;
volatile u_int16_t sport;
volatile u_int32_t daddr;
volatile u_int16_t dport;
volatile time_t last_packet_time;
};
struct rtp_crypto_config {
unsigned tag;
string suite;
string key;
u_int64_t from_time_us;
};
struct ip_port_call_info {
ip_port_call_info() {
rtp_crypto_config_list = NULL;
canceled = false;
for(int i = 0; i < 2; i++) {
callerd_confirm_sdp[i] = 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
};
u_int32_t addr;
u_int8_t type_addr;
u_int16_t port;
int8_t iscaller;
string sessid;
list<rtp_crypto_config> *rtp_crypto_config_list;
string to;
string branch;
u_int32_t sip_src_addr;
s_sdp_flags sdp_flags;
ip_port_call_info_rtp rtp[2];
bool canceled;
int8_t callerd_confirm_sdp[2];
};
struct raws_t {
int ssrc_index;
int rawiterator;
int codec;
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__max
};
struct sCallField {
eCallField fieldType;
const char *fieldName;
};
class Call_abstract {
public:
Call_abstract(int call_type, time_t time);
~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);
int calltime() { return first_packet_time; };
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)) ?
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;
time_t first_packet_time;
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;
protected:
list<u_int64_t> tarPosSip;
list<u_int64_t> tarPosRtp;
list<u_int64_t> tarPosGraph;
private:
volatile u_int16_t chunkBuffersCount;
};
/**
* This class implements operations on call
*/
class Call : public Call_abstract {
public:
struct sSipcalleRD_IP {
sSipcalleRD_IP() {
for(unsigned i = 0; i < MAX_SIPCALLERDIP; i++) {
sipcallerip[i] = 0;
sipcalledip[i] = 0;
sipcalledip_mod = 0;
sipcallerport[i] = 0;
sipcalledport[i] = 0;
sipcalledport_mod = 0;
}
}
u_int32_t sipcallerip[MAX_SIPCALLERDIP];
u_int32_t sipcalledip[MAX_SIPCALLERDIP];
u_int32_t sipcalledip_mod;
u_int16_t sipcallerport[MAX_SIPCALLERDIP];
u_int16_t sipcalledport[MAX_SIPCALLERDIP];
u_int16_t sipcalledport_mod;
};
struct sMergeLegInfo {
sMergeLegInfo() {
seenbye = false;
seenbye_time_usec = 0;
seenbyeandok = false;
seenbyeandok_time_usec = 0;
}
bool seenbye;
u_int64_t seenbye_time_usec;
bool seenbyeandok;
u_int64_t seenbyeandok_time_usec;
};
struct sInviteSD_Addr {
sInviteSD_Addr() {
confirmed = false;
counter = 0;
counter_reverse = 0;
}
u_int32_t saddr;
u_int32_t daddr;
u_int16_t sport;
u_int16_t 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 = 0,
const char *SIPrequest = NULL,
const char *SIPresponse = NULL, int SIPresponseNum = 0) {
this->time = time;
if(SIPrequest && SIPrequest[0]) {
this->SIPrequest = SIPrequest;
}
if(SIPresponse && SIPresponse[0]) {
this->SIPresponse = SIPresponse;
}
this->SIPresponseNum = SIPresponseNum;
}
u_int64_t time;
string SIPrequest;
string SIPresponse;
int SIPresponseNum;
};
struct sRtcpXrDataItem {
timeval tv;
int16_t moslq;
int16_t nlr;
};
struct sRtcpXrDataSsrc : public list<sRtcpXrDataItem> {
void add(timeval tv, int16_t moslq, int16_t nlr) {
sRtcpXrDataItem dataItem;
dataItem.tv = tv;
dataItem.moslq = moslq;
dataItem.nlr = nlr;
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) {
(*this)[ssrc].add(tv, moslq, nlr);
}
};
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_long 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_long last_ssrc_time_ms;
};
public:
bool is_ssl; //!< call was decrypted
RTP *rtp[MAX_SSRC_PER_CALL]; //!< array of RTP streams
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
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;
char byecseq[2][32];
char invitecseq[32];
char messagecseq[32];
char registercseq[32];
char cancelcseq[32];
char updatecseq[32];
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 OR TO CANEL within the Call
u_int64_t seenbyeandok_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
int rtpmap[MAX_IP_PER_CALL][MAX_RTPMAP]; //!< rtpmap for every rtp stream
RTP tmprtp; //!< temporary structure used to decode information from frame
RTP *lastcallerrtp; //!< last RTP stream from caller
RTP *lastcalledrtp; //!< last RTP stream from called
u_int32_t saddr; //!< source IP address of first INVITE
unsigned short sport; //!< source port of first INVITE
u_int32_t daddr;
unsigned short 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
int silencerecording;
int recordingpausedby182;
int msgcount;
int regcount;
int reg401count;
int reg401count_distinct;
u_int32_t reg401count_sipcallerip[MAX_SIPCALLERDIP];
int reg403count;
int reg403count_distinct;
u_int32_t reg403count_sipcallerip[MAX_SIPCALLERDIP];
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
unsigned long long flags1; //!< bit flags used to store max 64 flags
volatile unsigned int rtppacketsinqueue;
volatile int end_call_rtp;
volatile int push_call_to_calls_queue;
volatile int push_register_to_registers_queue;
#if USE_UNREPLIED_INVITE_MESSAGE
unsigned int unrepliedinvite;
unsigned int unrepliedmessage;
#endif
unsigned int ps_drop;
unsigned int ps_ifdrop;
char forcemark[2];
queue<u_int64_t> forcemark_time[2];
volatile int _forcemark_lock;
int first_codec;
bool has_second_merged_leg;
float a_mos_lqo;
float b_mos_lqo;
time_t progress_time; //!< time in seconds of 18X response
time_t first_rtp_time; //!< time in seconds of first RTP packet
unsigned int first_rtp_time_usec;
time_t connect_time; //!< time in seconds of 200 OK
unsigned int connect_time_usec;
time_t last_packet_time;
time_t last_rtp_a_packet_time;
time_t last_rtp_b_packet_time;
unsigned int first_packet_usec;
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_usec;
u_int64_t first_response_100_time_usec;
u_int64_t first_response_xxx_time_usec;
u_int64_t first_message_time_usec;
u_int64_t first_response_200_time_usec;
uint8_t caller_sipdscp;
uint8_t called_sipdscp;
int isfax;
char seenudptl;
bool exists_udptl_data;
bool not_acceptable;
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)
u_int32_t sipcallerip[MAX_SIPCALLERDIP]; //!< SIP signalling source IP address
u_int32_t sipcalledip[MAX_SIPCALLERDIP]; //!< SIP signalling destination IP address
u_int32_t sipcalledip_mod;
u_int16_t sipcallerport[MAX_SIPCALLERDIP];
u_int16_t sipcalledport[MAX_SIPCALLERDIP];
u_int16_t sipcalledport_mod;
map<string, sSipcalleRD_IP> map_sipcallerdip;
u_int32_t lastsipcallerip;
bool sipcallerdip_reverse;
list<sInviteSD_Addr> invite_sdaddr;
list<sInviteSD_Addr> rinvite_sdaddr;
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;
unsigned int lastsrcip;
unsigned int lastdstip;
unsigned int 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 _proxies_lock;
list<unsigned int> 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;
int 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;
time_t last_mgcp_connect_packet_time;
/**
* 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, time_t time);
/**
* destructor
*
*/
~Call();
int get_index_by_ip_port(in_addr_t addr, unsigned short port, bool use_sip_src_addr = false);
int get_index_by_sessid_to(char *sessid, char *to, in_addr_t sip_src_addr, ip_port_call_info::eTypeAddr type_addr);
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(in_addr_t sip_src_addr, in_addr_t addr, ip_port_call_info::eTypeAddr type_addr, unsigned short port, pcap_pkthdr *header,
char *sessid, list<rtp_crypto_config> *rtp_crypto_config_list, char *to, char *branch, int iscaller, int *rtpmap, s_sdp_flags sdp_flags);
bool refresh_data_ip_port(in_addr_t addr, unsigned short port, pcap_pkthdr *header,
list<rtp_crypto_config> *rtp_crypto_config_list, int iscaller, int *rtpmap, s_sdp_flags sdp_flags);
void add_ip_port_hash(in_addr_t sip_src_addr, in_addr_t addr, ip_port_call_info::eTypeAddr type_addr, unsigned short port, pcap_pkthdr *header,
char *sessid, list<rtp_crypto_config> *rtp_crypto_config_list, char *to, char *branch, int iscaller, int *rtpmap, s_sdp_flags sdp_flags);
void cancel_ip_port_hash(in_addr_t sip_src_addr, char *to, char *branch);
/**
* @brief get pointer to PcapDumper of the writing pcap file
*
* @return pointer to PcapDumper
*/
PcapDumper *getPcap() { return(&this->pcap); }
PcapDumper *getPcapSip() { return(&this->pcapSip); }
PcapDumper *getPcapRtp() { return(&this->pcapRtp); }
/**
* @brief get time of the last seen packet which belongs to this call
*
* @return time of the last packet in seconds from UNIX epoch
*/
time_t get_last_packet_time() { return last_packet_time; };
/**
* @brief get time of the last seen rtp packet which belongs to this call
*
* @return time of the last rtp packet in seconds from UNIX epoch
*/
time_t get_last_rtp_packet_time() { return max(last_rtp_a_packet_time, last_rtp_b_packet_time); };
/**
* @brief set time of the last seen packet which belongs to this call
*
* this time is used for calculating lenght of the call
*
*/
void set_last_packet_time(time_t mtime) { if(mtime > last_packet_time) last_packet_time = mtime; };
void set_last_mgcp_connect_packet_time(time_t mtime) { if(mtime > last_mgcp_connect_packet_time) last_mgcp_connect_packet_time = mtime; };
/**
* @brief get first time of the the packet which belongs to this call
*
* this time is used as start of the call in CDR record
*
* @return time of the first packet in seconds from UNIX epoch
*/
time_t get_first_packet_time() { return first_packet_time; };
/**
* @brief set first time of the the packet which belongs to this call
*
*/
void set_first_packet_time(time_t mtime, unsigned int usec) { first_packet_time = mtime; first_packet_usec = usec;};
/**
* handle hold times
*
*/
void HandleHold(bool sdp_sendonly, bool sdp_sendrecv);
/**
* @brief convert raw files to one WAV
*
*/
int convertRawToWav();
/**
* @brief save call to database
*
*/
int saveToDb(bool enableBatchIfPossible = true);
int saveAloneByeToDb(bool enableBatchIfPossible = true);
/**
* @brief save register msgs to database
*
*/
int saveRegisterToDb(bool enableBatchIfPossible = true);
/**
* @brief save sip MSSAGE to database
*
*/
int saveMessageToDb(bool enableBatchIfPossible = true);
/**
* @brief calculate duration of the call
*
* @return lenght of the call in seconds
*/
int duration() { return (typeIs(MGCP) ? last_mgcp_connect_packet_time : last_packet_time) - first_packet_time; };
int connect_duration() { return(connect_time ? duration() - (connect_time - first_packet_time) : 0); };
int duration_active() { return(getGlobalPacketTimeS() - first_packet_time); };
int connect_duration_active() { return(connect_time ? duration_active() - (connect_time - first_packet_time) : 0); };
/**
* @brief remove call from hash table
*
*/
void hashRemove();
void skinnyTablesRemove();
void removeFindTables(bool set_end_call = false);
/**
* @brief remove all RTP
*
*/
void removeRTP();
/**
* @brief stop recording packets to pcap file
*
*/
void stoprecording();
/**
* @brief save call to register tables and remove from calltable
*
*/
void saveregister(time_t currtime);
/**
* @brief print debug information for the call to stdout
*
*/
void evProcessRtpStream(int index_ip_port, bool by_dest, u_int32_t saddr, u_int16_t sport, u_int32_t daddr, u_int16_t dport, time_t time) {
if(index_ip_port < ipport_n) {
if(!ip_port[index_ip_port].rtp[by_dest].saddr) {
ip_port[index_ip_port].rtp[by_dest].saddr = saddr;
ip_port[index_ip_port].rtp[by_dest].sport = sport;
ip_port[index_ip_port].rtp[by_dest].daddr = daddr;
ip_port[index_ip_port].rtp[by_dest].dport = dport;
this->evStartRtpStream(index_ip_port, saddr, sport, daddr, dport, time);
}
ip_port[index_ip_port].rtp[by_dest].last_packet_time = time;
}
}
void evDestroyIpPortRtpStream(int index_ip_port) {
if(index_ip_port < ipport_n) {
for(int i = 0; i < 2; i++) {
if(ip_port[index_ip_port].rtp[i].saddr) {
this->evEndRtpStream(index_ip_port,
ip_port[index_ip_port].rtp[i].saddr,
ip_port[index_ip_port].rtp[i].sport,
ip_port[index_ip_port].rtp[i].daddr,
ip_port[index_ip_port].rtp[i].dport,
ip_port[index_ip_port].rtp[i].last_packet_time);
}
}
this->nullIpPortInfoRtpStream(index_ip_port);
}
}
void nullIpPortInfoRtpStream(int index_ip_port) {
if(index_ip_port < ipport_n) {
for(int i = 0; i < 2; i++) {
ip_port[index_ip_port].rtp[i].saddr = 0;
ip_port[index_ip_port].rtp[i].sport = 0;
ip_port[index_ip_port].rtp[i].daddr = 0;
ip_port[index_ip_port].rtp[i].dport = 0;
ip_port[index_ip_port].rtp[i].last_packet_time = 0;
}
}
}
void evStartRtpStream(int index_ip_port, u_int32_t saddr, u_int16_t sport, u_int32_t daddr, u_int16_t dport, time_t time);
void evEndRtpStream(int index_ip_port, u_int32_t saddr, u_int16_t sport, u_int32_t daddr, u_int16_t dport, time_t time);
void addtocachequeue(string file);
static void _addtocachequeue(string file);
void addtofilesqueue(eTypeSpoolFile typeSpoolFile, string file, long long writeBytes);
static void _addtofilesqueue(eTypeSpoolFile typeSpoolFile, string file, string dirnamesqlfiles, long long writeBytes, int spoolIndex);
float mos_lqo(char *deg, int samplerate);
void handle_dtmf(char dtmf, double dtmf_time, unsigned int saddr, unsigned int daddr, s_dtmf::e_type dtmf_type);