Filters
This commit is contained in:
parent
372b11ba1f
commit
ca506e92e9
5 changed files with 130 additions and 13 deletions
|
@ -3,7 +3,8 @@
|
||||||
* (C)2005, Dan Ponte
|
* (C)2005, Dan Ponte
|
||||||
* BSDL w/ advert.
|
* BSDL w/ advert.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/include/phoned.h,v 1.4 2005/06/10 00:21:23 dcp1990 Exp $ */
|
/* $Amigan: phoned/include/phoned.h,v 1.5 2005/06/12 16:30:53 dcp1990 Exp $ */
|
||||||
|
#include <pcre.h> /* fugly, I know... */
|
||||||
#define VERSION "0.1"
|
#define VERSION "0.1"
|
||||||
#define LOGFILE "/var/log/phoned.log"
|
#define LOGFILE "/var/log/phoned.log"
|
||||||
#define SOCKETFILE "/tmp/phoned.sock"
|
#define SOCKETFILE "/tmp/phoned.sock"
|
||||||
|
@ -65,9 +66,22 @@ typedef struct c_t {
|
||||||
#define CTACT_ANS 0x10
|
#define CTACT_ANS 0x10
|
||||||
#define CTACT_PLAY 0x20
|
#define CTACT_PLAY 0x20
|
||||||
#define CTACT_REC 0x40
|
#define CTACT_REC 0x40
|
||||||
|
struct af {
|
||||||
|
char* not_email;
|
||||||
|
char* play_file;
|
||||||
|
char* record_file;
|
||||||
|
};
|
||||||
|
typedef struct rx_t {
|
||||||
|
pcre* prex;
|
||||||
|
const char* error;
|
||||||
|
int erroroffset;
|
||||||
|
} regex_t;
|
||||||
typedef struct cnd_t {
|
typedef struct cnd_t {
|
||||||
|
char* filtername;
|
||||||
char* name;
|
char* name;
|
||||||
char* number;
|
char* number;
|
||||||
|
regex_t namerx;
|
||||||
|
regex_t numbrx;
|
||||||
int action;
|
int action;
|
||||||
struct af actflags;
|
struct af actflags;
|
||||||
int flags;
|
int flags;
|
||||||
|
@ -103,3 +117,4 @@ void flush_lists(void);
|
||||||
void addtoaddrs(const char* par);
|
void addtoaddrs(const char* par);
|
||||||
void modem_hread(char* cbuf);
|
void modem_hread(char* cbuf);
|
||||||
void cid_log(cid_t* c);
|
void cid_log(cid_t* c);
|
||||||
|
cond_t* add_condition(char* filtname, char* nameregex, char* numregex, int action);
|
||||||
|
|
|
@ -21,18 +21,31 @@ info yylval.number = LL_INFO; return LNUML;
|
||||||
garbage yylval.number = LL_GARBAGE; return LNUML;
|
garbage yylval.number = LL_GARBAGE; return LNUML;
|
||||||
warn yylval.number = LL_WARN; return LNUML;
|
warn yylval.number = LL_WARN; return LNUML;
|
||||||
notify return NOTIFY;
|
notify return NOTIFY;
|
||||||
|
filter return FILTER;
|
||||||
|
filters return FILTERS;
|
||||||
|
action return ACTION;
|
||||||
|
name return NAME;
|
||||||
|
number return PHNUM;
|
||||||
|
mail yylval.number = CTACT_RNOT; return ACTN;
|
||||||
|
hangup yylval.number = CTACT_HUP; return ACTN;
|
||||||
|
ignore yylval.number = CTACT_IGN; return ACTN;
|
||||||
|
play yylval.number = CTACT_PLAY; return ACTN;
|
||||||
|
record yylval.number = CTACT_REC; return ACTN;
|
||||||
modemdev return MODDEV;
|
modemdev return MODDEV;
|
||||||
\| return OR;
|
\| return OR;
|
||||||
\" return QUOTE;
|
\" return QUOTE;
|
||||||
\{ return OBRACE;
|
\{ return OBRACE;
|
||||||
\} return CBRACE;
|
\} return CBRACE;
|
||||||
\/[a-zA-Z0-9/._-]+ yylval.string = strdup(yytext); return PATH;
|
\/[^\n]+\/ yylval.string = strdup(yytext); return REGEX;
|
||||||
|
\/[a-zA-Z0-9/._-]+ yylval.string = strdup(yytext); return PATH;
|
||||||
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} yylval.string = strdup(yytext); return IPADDR;
|
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} yylval.string = strdup(yytext); return IPADDR;
|
||||||
|
[a-zA-Z0-9_-]+ yylval.string = strdup(yytext); return FNAME;
|
||||||
; return SCOLON;
|
; return SCOLON;
|
||||||
\n chrcnt = 0; ++lincnt;/* DONOTHING */
|
\n chrcnt = 0; ++lincnt;/* DONOTHING */
|
||||||
[\t ] /* DONOTHING */
|
[\t ] /* DONOTHING */
|
||||||
. /* DO nothing */
|
. /* DO nothing */
|
||||||
%%
|
%%
|
||||||
|
/* \/[a-zA-Z0-9/._\[\]\\*()^$+-]+\/ yylval.string = strdup(yytext); return REGEX; */
|
||||||
int parse(fp)
|
int parse(fp)
|
||||||
FILE** fp;
|
FILE** fp;
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
int chrcnt = 0;
|
int chrcnt = 0;
|
||||||
int lincnt = 1;
|
int lincnt = 1;
|
||||||
int yylex(void);
|
int yylex(void);
|
||||||
|
char *numrx = 0x0, *namrx = 0x0;
|
||||||
|
int factn = 0x0;
|
||||||
extern char* yytext;
|
extern char* yytext;
|
||||||
extern struct conf cf;
|
extern struct conf cf;
|
||||||
void yyerror(str)
|
void yyerror(str)
|
||||||
|
@ -27,14 +29,18 @@ int yywrap(void)
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
%token NOTIFY OBRACE CBRACE SCOLON QUOTE MODDEV MAIN LLEVEL OR
|
%token NOTIFY OBRACE CBRACE SCOLON QUOTE MODDEV MAIN LLEVEL OR
|
||||||
%token <number> LNUML
|
%token FILTERS ACTION NAME PHNUM FILTER
|
||||||
%token <string> IPADDR PATH
|
/* HANGUP IGNOREIT PLAY RECORD */
|
||||||
|
%token <number> LNUML ACTN
|
||||||
|
%token <string> IPADDR PATH REGEX FNAME
|
||||||
%%
|
%%
|
||||||
commands:
|
commands:
|
||||||
|
|
|
|
||||||
commands command SCOLON
|
commands command SCOLON
|
||||||
;
|
;
|
||||||
command:
|
command:
|
||||||
|
filters
|
||||||
|
|
|
||||||
notify
|
notify
|
||||||
|
|
|
|
||||||
main
|
main
|
||||||
|
@ -81,6 +87,68 @@ devpath:
|
||||||
cf.modemdev = $2;
|
cf.modemdev = $2;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
/* filters */
|
||||||
|
filters:
|
||||||
|
FILTERS filterlist
|
||||||
|
;
|
||||||
|
filterlist:
|
||||||
|
OBRACE filtbds CBRACE
|
||||||
|
;
|
||||||
|
filtbds:
|
||||||
|
|
|
||||||
|
filtbds filtbd SCOLON
|
||||||
|
;
|
||||||
|
filtbd:
|
||||||
|
FILTER FNAME OBRACE filtersts CBRACE
|
||||||
|
{
|
||||||
|
add_condition($2, namrx, numrx, factn);
|
||||||
|
free($2);
|
||||||
|
if(namrx != 0x0) free(namrx);
|
||||||
|
if(numrx != 0x0) free(numrx);
|
||||||
|
factn = 0x0;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
filtersts:
|
||||||
|
|
|
||||||
|
filtersts filterst SCOLON
|
||||||
|
;
|
||||||
|
filterst:
|
||||||
|
fname
|
||||||
|
|
|
||||||
|
fnumb
|
||||||
|
|
|
||||||
|
faction
|
||||||
|
;
|
||||||
|
fname:
|
||||||
|
NAME REGEX
|
||||||
|
{
|
||||||
|
namrx = $2;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
fnumb:
|
||||||
|
PHNUM REGEX
|
||||||
|
{
|
||||||
|
numrx = $2;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
faction:
|
||||||
|
ACTION facts
|
||||||
|
;
|
||||||
|
facts:
|
||||||
|
|
|
||||||
|
fact facts
|
||||||
|
;
|
||||||
|
fact:
|
||||||
|
ACTN OR
|
||||||
|
{
|
||||||
|
factn |= $1;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
ACTN
|
||||||
|
{
|
||||||
|
factn |= $1;
|
||||||
|
}
|
||||||
|
;
|
||||||
/* loglevels */
|
/* loglevels */
|
||||||
loglevel:
|
loglevel:
|
||||||
LLEVEL llvls
|
LLEVEL llvls
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/phoned/filters.c,v 1.2 2005/06/12 15:22:56 dcp1990 Exp $ */
|
/* $Amigan: phoned/phoned/filters.c,v 1.3 2005/06/12 16:30:57 dcp1990 Exp $ */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -39,7 +39,8 @@ cond_t* topcond = 0x0;
|
||||||
pthread_mutex_t condmx = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t condmx = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
/* BROKEN! Do not use! */
|
/* BROKEN! Do not use! */
|
||||||
cond_t* add_condition(nameregex, numregex, action)
|
cond_t* add_condition(filtname, nameregex, numregex, action)
|
||||||
|
char* filtname;
|
||||||
char* nameregex;
|
char* nameregex;
|
||||||
char* numregex;
|
char* numregex;
|
||||||
int action;
|
int action;
|
||||||
|
@ -56,12 +57,25 @@ cond_t* add_condition(nameregex, numregex, action)
|
||||||
c->next = nc;
|
c->next = nc;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&condmx); /* done */
|
pthread_mutex_unlock(&condmx); /* done */
|
||||||
nc->name = strdup(nameregex);
|
nc->name = strdup(filtname);
|
||||||
nc->number = strdup(numregex);
|
if(nameregex != 0x0) {
|
||||||
nc->namerx.prex = pcre_compile(nc->name, 0x0, &nc->namerx.error,
|
nc->name = strdup(nameregex);
|
||||||
&nc->namerx.erroroffset, NULL);
|
nc->namerx.prex = pcre_compile(nc->name, 0x0, &nc->namerx.error,
|
||||||
nc->numbrx.prex = pcre_compile(nc->number, 0x0, &nc->numbrx.error,
|
&nc->namerx.erroroffset, NULL);
|
||||||
&nc->numbrx.erroroffset, NULL);
|
} else {
|
||||||
|
nc->name = NULL;
|
||||||
|
nc->namerx.prex = 0x0;
|
||||||
|
}
|
||||||
|
if(numregex != 0x0) {
|
||||||
|
nc->number = strdup(numregex);
|
||||||
|
nc->numbrx.prex = pcre_compile(nc->number, 0x0, &nc->numbrx.error,
|
||||||
|
&nc->numbrx.erroroffset, NULL);
|
||||||
|
} else {
|
||||||
|
nc->number = NULL;
|
||||||
|
nc->numbrx.prex = 0x0;
|
||||||
|
}
|
||||||
nc->action = action;
|
nc->action = action;
|
||||||
|
lprintf(info, "Added filter %s, namerx = %s, numrx = %s, action = 0x%x\n",
|
||||||
|
filtname, nameregex, numregex, action);
|
||||||
return nc;
|
return nc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
main {
|
main {
|
||||||
modemdev "/dev/cuaa2";
|
modemdev "/dev/cuaa2";
|
||||||
loglevels all;
|
loglevel all;
|
||||||
|
};
|
||||||
|
filters {
|
||||||
|
filter test1 {
|
||||||
|
name /PONTE/;
|
||||||
|
number /^782.*/;
|
||||||
|
action ignore|hangup;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
notify {
|
notify {
|
||||||
10.10.10.255;
|
10.10.10.255;
|
||||||
|
|
Loading…
Reference in a new issue