Skip to content

Commit

Permalink
Merging several features in one commit:
Browse files Browse the repository at this point in the history
- Simple TCP manager interface implementation to interact with voipmonitor process. Commands implemented:
reload - will reload voipmonitor.conf and mysql filter_ip and filter_telnum. It will not reload interface, ring-buffer and mysql connection.
totalcalls - number of current calls
listcalls - return JSON formated information about calls - callreference, callid, callercodec, calledcodec, caller, callername, called, calldate, duration, callerip, calledip
listen - experimental look at manager.c
quit
- Experimental realtime voice decoding to FIFO files. Commercial WEB interface implements realtime listening for ALAW now.
- Add 2 new MySQL tables - filter_ip and filter_telnum. voipmonitor can now do recording per IP or per telephone numbers. IP filter is implemented with linked list of IP addresses. Complexity is N*M where N is number of rules and M is number of INVITE per second. Filter by telephone numbers are implemented with B-tree and hash which searches for number in constanst time regardless on number of rules.
  • Loading branch information
Martin Vit committed Oct 16, 2011
1 parent 88d99e0 commit 070a1e3
Showing 18 changed files with 1,085 additions and 56 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@
/codecs.h -text
config/init.d/voipmonitor -text
config/voipmonitor.conf -text
/filter_mysql.cpp -text
/filter_mysql.h -text
/format_ogg.cpp -text
/format_ogg.h -text
/format_slinear.cpp -text
@@ -80,6 +82,8 @@ jitterbuffer/frame.c -text
jitterbuffer/jitterbuf.c -text
jitterbuffer/jitterbuf.h -text
jitterbuffer/utils.c -text
/manager.cpp -text
/manager.h -text
/rtp.cpp -text
/rtp.h -text
simpleini/ConvertUTF.c -text
@@ -104,5 +108,7 @@ simpleini/testsi-UTF8.ini -text
simpleini/testsi.cpp -text
/sniff.cpp -text
/sniff.h -text
/tools.cpp -text
/tools.h -text
/voipmonitor.cpp -text
/voipmonitor.h -text
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
objects = codec_alaw.o codec_ulaw.o format_slinear.o format_wav.o format_ogg.o calltable.o rtp.o voipmonitor.o sniff.o jitterbuffer/astmm.o jitterbuffer/utils.o jitterbuffer/fixedjitterbuf.o jitterbuffer/jitterbuf.o jitterbuffer/abstract_jb.o jitterbuffer/frame.o gzstream/gzstream.o gzstream/libgzstream.a
objects = codec_alaw.o codec_ulaw.o format_slinear.o format_wav.o format_ogg.o calltable.o rtp.o voipmonitor.o sniff.o jitterbuffer/astmm.o jitterbuffer/utils.o jitterbuffer/fixedjitterbuf.o jitterbuffer/jitterbuf.o jitterbuffer/abstract_jb.o jitterbuffer/frame.o gzstream/gzstream.o gzstream/libgzstream.a manager.o tools.o filter_mysql.o
args = -g3 -Wall
#args = -O2 -Wall
CFLAGS+=-I /usr/local/include/mysql++/ -I /usr/include/mysql++/ -I /usr/include/mysql/ -g3 -Wall -I jitterbuffer/ -L/usr/local/lib/ -Lgzstream/
@@ -43,6 +43,15 @@ voipmonitor.o : voipmonitor.cpp voipmonitor.h
sniff.o : sniff.cpp sniff.h
g++ -c sniff.cpp $(args) ${CFLAGS}

manager.o : manager.cpp manager.h
g++ -c manager.cpp $(args) ${CFLAGS}

tools.o : tools.cpp tools.h
g++ -c tools.cpp $(args) ${CFLAGS}

filter_mysql.o : filter_mysql.cpp filter_mysql.h
g++ -c filter_mysql.cpp $(args) ${CFLAGS}

clean :
rm -f $(objects) voipmonitor gzstream/*.o libgzstream.a

30 changes: 29 additions & 1 deletion calltable.cpp
Original file line number Diff line number Diff line change
@@ -39,6 +39,9 @@
using namespace std;

extern int verbosity;
extern int opt_sip_register;
extern int opt_saveRTP;
extern int opt_saveSIP;
extern int opt_rtcp;
extern int opt_saveRAW; // save RTP payload RAW data?
extern int opt_saveWAV; // save RTP payload RAW data?
@@ -90,6 +93,9 @@ Call::Call(char *call_id, unsigned long call_id_len, time_t time, void *ct) {
for(int i = 0; i < MAX_SSRC_PER_CALL; i++) {
rtp[i] = NULL;
}
fifo1 = 0;
fifo2 = 0;
listening_worker_run = NULL;
}

/* destructor */
@@ -111,6 +117,11 @@ Call::~Call(){
delete rtp[i];
}
}

// tell listening_worker to stop listening
if(listening_worker_run) {
*listening_worker_run = 0;
}

if (get_f_pcap() != NULL){
pcap_dump_flush(get_f_pcap());
@@ -243,7 +254,7 @@ Call::read_rtp(unsigned char* data, int datalen, struct pcap_pkthdr *header, u_i
}
rtp_cur[iscaller] = rtp[ssrc_n];
sprintf(rtp[ssrc_n]->gfilename, "%s/%s.%d.graph%s", dirname(), fbasename, ssrc_n, opt_gzipGRAPH ? ".gz" : "");
if(opt_saveGRAPH) {
if(flags & FLAG_SAVEGRAPH) {
if(opt_gzipGRAPH) {
rtp[ssrc_n]->gfileGZ.open(rtp[ssrc_n]->gfilename);
} else {
@@ -897,6 +908,23 @@ Calltable::add(char *call_id, unsigned long call_id_len, time_t time, u_int32_t
calls++;
newcall->saddr = saddr;
newcall->sport = port;

//flags
if(opt_saveSIP)
newcall->flags |= FLAG_SAVESIP;

if(opt_saveRTP)
newcall->flags |= FLAG_SAVERTP;

if(opt_saveWAV)
newcall->flags |= FLAG_SAVEWAV;

if(opt_saveGRAPH)
newcall->flags |= FLAG_SAVEGRAPH;

if(opt_sip_register)
newcall->flags |= FLAG_SAVEREGISTER;

calls_list.push_front(newcall);
return newcall;
}
16 changes: 16 additions & 0 deletions calltable.h
Original file line number Diff line number Diff line change
@@ -39,6 +39,12 @@
#define RES18X 9
#define REGISTER 10

#define FLAG_SAVERTP (1 << 0)
#define FLAG_SAVESIP (1 << 1)
#define FLAG_SAVEREGISTER (1 << 2)
#define FLAG_SAVEWAV (1 << 3)
#define FLAG_SAVEGRAPH (1 << 4)

/**
* This class implements operations on call
*/
@@ -82,6 +88,16 @@ class Call {

char lastSIPresponse[128];
int lastSIPresponseNum;

int last_callercodec; //!< Last caller codec
int last_calledcodec; //!< Last called codec

int fifo1;
int fifo2;

unsigned int flags; //!< structure holding FLAGS*

int *listening_worker_run;

/**
* constructor
26 changes: 26 additions & 0 deletions cdrtable.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
CREATE TABLE `filter_ip` (
`id` int(32) NOT NULL auto_increment,
`ip` int(32) unsigned default NULL,
`mask` int(8) default NULL,
`rtp` tinyint(1) default '0',
`sip` tinyint(1) default '0',
`register` tinyint(1) default '0',
`graph` tinyint(1) default '0',
`wav` tinyint(1) default '0',
`note` TEXT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `filter_telnum` (
`id` int(32) NOT NULL auto_increment,
`prefix` int(32) unsigned default NULL,
`fixed_len` int(32) unsigned default 0,
`rtp` tinyint(1) default '0',
`sip` tinyint(1) default '0',
`register` tinyint(1) default '0',
`graph` tinyint(1) default '0',
`wav` tinyint(1) default '0',
`note` TEXT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `cdr` (
`ID` int(32) unsigned NOT NULL auto_increment,
`calldate` datetime NOT NULL,
27 changes: 27 additions & 0 deletions cdrtable.sql.3.0-3.1
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
ALTER TABLE cdr MODIFY whohanged ENUM('caller', 'callee') DEFAULT NULL;

CREATE TABLE `filter_ip` (
`id` int(32) NOT NULL auto_increment,
`ip` int(32) unsigned default NULL,
`mask` int(8) default NULL,
`rtp` tinyint(1) default '0',
`sip` tinyint(1) default '0',
`register` tinyint(1) default '0',
`graph` tinyint(1) default '0',
`wav` tinyint(1) default '0',
`note` TEXT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `filter_telnum` (
`id` int(32) NOT NULL auto_increment,
`prefix` int(32) unsigned default NULL,
`fixed_len` int(32) unsigned default 0,
`rtp` tinyint(1) default '0',
`sip` tinyint(1) default '0',
`register` tinyint(1) default '0',
`graph` tinyint(1) default '0',
`wav` tinyint(1) default '0',
`note` TEXT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Loading

0 comments on commit 070a1e3

Please sign in to comment.