Filters
This commit is contained in:
parent
372b11ba1f
commit
ca506e92e9
@ -3,7 +3,8 @@
|
||||
* (C)2005, Dan Ponte
|
||||
* 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 LOGFILE "/var/log/phoned.log"
|
||||
#define SOCKETFILE "/tmp/phoned.sock"
|
||||
@ -65,9 +66,22 @@ typedef struct c_t {
|
||||
#define CTACT_ANS 0x10
|
||||
#define CTACT_PLAY 0x20
|
||||
#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 {
|
||||
char* filtername;
|
||||
char* name;
|
||||
char* number;
|
||||
regex_t namerx;
|
||||
regex_t numbrx;
|
||||
int action;
|
||||
struct af actflags;
|
||||
int flags;
|
||||
@ -103,3 +117,4 @@ void flush_lists(void);
|
||||
void addtoaddrs(const char* par);
|
||||
void modem_hread(char* cbuf);
|
||||
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;
|
||||
warn yylval.number = LL_WARN; return LNUML;
|
||||
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;
|
||||
\| return OR;
|
||||
\" return QUOTE;
|
||||
\{ return OBRACE;
|
||||
\} 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;
|
||||
[a-zA-Z0-9_-]+ yylval.string = strdup(yytext); return FNAME;
|
||||
; return SCOLON;
|
||||
\n chrcnt = 0; ++lincnt;/* DONOTHING */
|
||||
[\t ] /* DONOTHING */
|
||||
. /* DO nothing */
|
||||
%%
|
||||
/* \/[a-zA-Z0-9/._\[\]\\*()^$+-]+\/ yylval.string = strdup(yytext); return REGEX; */
|
||||
int parse(fp)
|
||||
FILE** fp;
|
||||
{
|
||||
|
@ -12,6 +12,8 @@
|
||||
int chrcnt = 0;
|
||||
int lincnt = 1;
|
||||
int yylex(void);
|
||||
char *numrx = 0x0, *namrx = 0x0;
|
||||
int factn = 0x0;
|
||||
extern char* yytext;
|
||||
extern struct conf cf;
|
||||
void yyerror(str)
|
||||
@ -27,14 +29,18 @@ int yywrap(void)
|
||||
}
|
||||
%}
|
||||
%token NOTIFY OBRACE CBRACE SCOLON QUOTE MODDEV MAIN LLEVEL OR
|
||||
%token <number> LNUML
|
||||
%token <string> IPADDR PATH
|
||||
%token FILTERS ACTION NAME PHNUM FILTER
|
||||
/* HANGUP IGNOREIT PLAY RECORD */
|
||||
%token <number> LNUML ACTN
|
||||
%token <string> IPADDR PATH REGEX FNAME
|
||||
%%
|
||||
commands:
|
||||
|
|
||||
commands command SCOLON
|
||||
;
|
||||
command:
|
||||
filters
|
||||
|
|
||||
notify
|
||||
|
|
||||
main
|
||||
@ -81,6 +87,68 @@ devpath:
|
||||
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 */
|
||||
loglevel:
|
||||
LLEVEL llvls
|
||||
|
@ -27,7 +27,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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 <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -39,7 +39,8 @@ cond_t* topcond = 0x0;
|
||||
pthread_mutex_t condmx = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* BROKEN! Do not use! */
|
||||
cond_t* add_condition(nameregex, numregex, action)
|
||||
cond_t* add_condition(filtname, nameregex, numregex, action)
|
||||
char* filtname;
|
||||
char* nameregex;
|
||||
char* numregex;
|
||||
int action;
|
||||
@ -56,12 +57,25 @@ cond_t* add_condition(nameregex, numregex, action)
|
||||
c->next = nc;
|
||||
}
|
||||
pthread_mutex_unlock(&condmx); /* done */
|
||||
nc->name = strdup(nameregex);
|
||||
nc->number = strdup(numregex);
|
||||
nc->namerx.prex = pcre_compile(nc->name, 0x0, &nc->namerx.error,
|
||||
&nc->namerx.erroroffset, NULL);
|
||||
nc->numbrx.prex = pcre_compile(nc->number, 0x0, &nc->numbrx.error,
|
||||
&nc->numbrx.erroroffset, NULL);
|
||||
nc->name = strdup(filtname);
|
||||
if(nameregex != 0x0) {
|
||||
nc->name = strdup(nameregex);
|
||||
nc->namerx.prex = pcre_compile(nc->name, 0x0, &nc->namerx.error,
|
||||
&nc->namerx.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;
|
||||
lprintf(info, "Added filter %s, namerx = %s, numrx = %s, action = 0x%x\n",
|
||||
filtname, nameregex, numregex, action);
|
||||
return nc;
|
||||
}
|
||||
|
@ -1,6 +1,13 @@
|
||||
main {
|
||||
modemdev "/dev/cuaa2";
|
||||
loglevels all;
|
||||
loglevel all;
|
||||
};
|
||||
filters {
|
||||
filter test1 {
|
||||
name /PONTE/;
|
||||
number /^782.*/;
|
||||
action ignore|hangup;
|
||||
};
|
||||
};
|
||||
notify {
|
||||
10.10.10.255;
|
||||
|
Loading…
Reference in New Issue
Block a user