Filters should work now; just write the actual glue to do stuff
This commit is contained in:
parent
6f972aaf18
commit
fee619108b
4 changed files with 134 additions and 7 deletions
|
@ -26,6 +26,10 @@ filters return FILTERS;
|
||||||
action return ACTION;
|
action return ACTION;
|
||||||
name return NAME;
|
name return NAME;
|
||||||
number return PHNUM;
|
number return PHNUM;
|
||||||
|
flags return FLAGS;
|
||||||
|
stopproc yylval.number = CTFLG_STOPPROC; return FLAG;
|
||||||
|
cname yylval.number = CTFLG_CHECKNAME; return FLAG;
|
||||||
|
cnumber yylval.number = CTFLG_CHECKNUMB; return FLAG;
|
||||||
mail yylval.number = CTACT_RNOT; return ACTN;
|
mail yylval.number = CTACT_RNOT; return ACTN;
|
||||||
hangup yylval.number = CTACT_HUP; return ACTN;
|
hangup yylval.number = CTACT_HUP; return ACTN;
|
||||||
ignore yylval.number = CTACT_IGN; return ACTN;
|
ignore yylval.number = CTACT_IGN; return ACTN;
|
||||||
|
|
|
@ -14,6 +14,7 @@ int lincnt = 1;
|
||||||
int yylex(void);
|
int yylex(void);
|
||||||
char *numrx = 0x0, *namrx = 0x0;
|
char *numrx = 0x0, *namrx = 0x0;
|
||||||
int factn = 0x0;
|
int factn = 0x0;
|
||||||
|
int ctflags = 0x0;
|
||||||
extern char* yytext;
|
extern char* yytext;
|
||||||
extern struct conf cf;
|
extern struct conf cf;
|
||||||
void yyerror(str)
|
void yyerror(str)
|
||||||
|
@ -29,9 +30,9 @@ int yywrap(void)
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
%token NOTIFY OBRACE CBRACE SCOLON QUOTE MODDEV MAIN LLEVEL OR
|
%token NOTIFY OBRACE CBRACE SCOLON QUOTE MODDEV MAIN LLEVEL OR
|
||||||
%token FILTERS ACTION NAME PHNUM FILTER
|
%token FILTERS ACTION NAME PHNUM FILTER FLAGS
|
||||||
/* HANGUP IGNOREIT PLAY RECORD */
|
/* HANGUP IGNOREIT PLAY RECORD */
|
||||||
%token <number> LNUML ACTN
|
%token <number> LNUML ACTN FLAG
|
||||||
%token <string> IPADDR PATH REGEX FNAME
|
%token <string> IPADDR PATH REGEX FNAME
|
||||||
%%
|
%%
|
||||||
commands:
|
commands:
|
||||||
|
@ -101,11 +102,12 @@ filtbds:
|
||||||
filtbd:
|
filtbd:
|
||||||
FILTER FNAME OBRACE filtersts CBRACE
|
FILTER FNAME OBRACE filtersts CBRACE
|
||||||
{
|
{
|
||||||
add_condition($2, namrx, numrx, factn);
|
add_condition($2, namrx, numrx, factn, ctflags);
|
||||||
free($2);
|
free($2);
|
||||||
if(namrx != 0x0) free(namrx);
|
if(namrx != 0x0) free(namrx);
|
||||||
if(numrx != 0x0) free(numrx);
|
if(numrx != 0x0) free(numrx);
|
||||||
factn = 0x0;
|
factn = 0x0;
|
||||||
|
ctflags = 0x0;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
filtersts:
|
filtersts:
|
||||||
|
@ -118,6 +120,8 @@ filterst:
|
||||||
fnumb
|
fnumb
|
||||||
|
|
|
|
||||||
faction
|
faction
|
||||||
|
|
|
||||||
|
fflags
|
||||||
;
|
;
|
||||||
fname:
|
fname:
|
||||||
NAME REGEX
|
NAME REGEX
|
||||||
|
@ -131,6 +135,24 @@ fnumb:
|
||||||
numrx = $2;
|
numrx = $2;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
fflags:
|
||||||
|
FLAGS flgs
|
||||||
|
;
|
||||||
|
flgs:
|
||||||
|
|
|
||||||
|
flg flgs
|
||||||
|
;
|
||||||
|
flg:
|
||||||
|
FLAG OR
|
||||||
|
{
|
||||||
|
ctflags |= $1;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
ACTN
|
||||||
|
{
|
||||||
|
ctflags |= $1;
|
||||||
|
}
|
||||||
|
;
|
||||||
faction:
|
faction:
|
||||||
ACTION facts
|
ACTION facts
|
||||||
;
|
;
|
||||||
|
|
108
phoned/filters.c
108
phoned/filters.c
|
@ -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.7 2005/06/12 18:56:20 dcp1990 Exp $ */
|
/* $Amigan: phoned/phoned/filters.c,v 1.8 2005/06/12 22:01:23 dcp1990 Exp $ */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -43,7 +43,8 @@ void free_cond_elms(cond)
|
||||||
free(cond->name);
|
free(cond->name);
|
||||||
free(cond->number);
|
free(cond->number);
|
||||||
free(cond->filtername);
|
free(cond->filtername);
|
||||||
free(cond->namerx.prex);
|
if(cond->namerx.prex != NULL) free(cond->namerx.prex);
|
||||||
|
if(cond->numbrx.prex != NULL) free(cond->numbrx.prex);
|
||||||
}
|
}
|
||||||
void free_condition(h, traverse)
|
void free_condition(h, traverse)
|
||||||
cond_t* h;
|
cond_t* h;
|
||||||
|
@ -68,16 +69,17 @@ void free_condition(h, traverse)
|
||||||
pthread_mutex_unlock(&condmx);
|
pthread_mutex_unlock(&condmx);
|
||||||
}
|
}
|
||||||
|
|
||||||
cond_t* add_condition(filtname, nameregex, numregex, action)
|
cond_t* add_condition(filtname, nameregex, numregex, action, flags)
|
||||||
char* filtname;
|
char* filtname;
|
||||||
char* nameregex;
|
char* nameregex;
|
||||||
char* numregex;
|
char* numregex;
|
||||||
int action;
|
int action;
|
||||||
|
int flags;
|
||||||
{
|
{
|
||||||
cond_t *c, *nc;
|
cond_t *c, *nc;
|
||||||
nc = malloc(sizeof(cond_t));
|
nc = malloc(sizeof(cond_t));
|
||||||
memset(nc, 0, sizeof(cond_t));
|
memset(nc, 0, sizeof(cond_t));
|
||||||
pthread_mutex_lock(&condmx); /* ALWAYS do this if dealing with next, last or topcond!! */
|
pthread_mutex_lock(&condmx); /* ALWAYS do this if dealing with any part, for it may be freed! */
|
||||||
if(topcond == 0x0)
|
if(topcond == 0x0)
|
||||||
topcond = nc;
|
topcond = nc;
|
||||||
else {
|
else {
|
||||||
|
@ -90,22 +92,120 @@ cond_t* add_condition(filtname, nameregex, numregex, action)
|
||||||
nc->name = strdup(nameregex);
|
nc->name = strdup(nameregex);
|
||||||
nc->namerx.prex = pcre_compile(nc->name, 0x0, &nc->namerx.error,
|
nc->namerx.prex = pcre_compile(nc->name, 0x0, &nc->namerx.error,
|
||||||
&nc->namerx.erroroffset, NULL);
|
&nc->namerx.erroroffset, NULL);
|
||||||
|
if(nc->namerx.prex == NULL) {
|
||||||
|
lprintf(error, "NAME PCRE compilation failed at offset %d: %s\n", nc->namerx.erroroffset, nc->namerx.error);
|
||||||
|
} else {
|
||||||
|
pcre_fullinfo(nc->namerx.prex, NULL, PCRE_INFO_SIZE, &nc->namerx.pcresize);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
nc->name = NULL;
|
nc->name = NULL;
|
||||||
nc->namerx.prex = 0x0;
|
nc->namerx.prex = 0x0;
|
||||||
}
|
}
|
||||||
if(numregex != 0x0) {
|
if(numregex != 0x0) {
|
||||||
nc->number = strdup(numregex);
|
nc->number = strdup(numregex);
|
||||||
|
nc->numbrx.pcresize = 0x0;
|
||||||
nc->numbrx.prex = pcre_compile(nc->number, 0x0, &nc->numbrx.error,
|
nc->numbrx.prex = pcre_compile(nc->number, 0x0, &nc->numbrx.error,
|
||||||
&nc->numbrx.erroroffset, NULL);
|
&nc->numbrx.erroroffset, NULL);
|
||||||
|
if(nc->numbrx.prex == NULL) {
|
||||||
|
lprintf(error, "NUMBER PCRE compilation failed at offset %d: %s\n", nc->numbrx.erroroffset, nc->numbrx.error);
|
||||||
|
} else {
|
||||||
|
pcre_fullinfo(nc->numbrx.prex, NULL, PCRE_INFO_SIZE, &nc->numbrx.pcresize);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
nc->number = NULL;
|
nc->number = NULL;
|
||||||
nc->numbrx.prex = 0x0;
|
nc->numbrx.prex = 0x0;
|
||||||
}
|
}
|
||||||
nc->action = action;
|
nc->action = action;
|
||||||
|
nc->flags = flags;
|
||||||
lprintf(info, "Added filter %s, namerx = %s, numrx = %s, action = %b\n",
|
lprintf(info, "Added filter %s, namerx = %s, numrx = %s, action = %b\n",
|
||||||
filtname, nameregex, numregex, action, "\10" SCTACT_IGN "IGNORE" SCTACT_HUP "HANGUP"
|
filtname, nameregex, numregex, action, "\10" SCTACT_IGN "IGNORE" SCTACT_HUP "HANGUP"
|
||||||
SCTACT_RNOT "MAIL" SCTACT_ANS "ANSWER" SCTACT_PLAY "PLAY" SCTACT_REC "RECORD\n");
|
SCTACT_RNOT "MAIL" SCTACT_ANS "ANSWER" SCTACT_PLAY "PLAY" SCTACT_REC "RECORD\n");
|
||||||
pthread_mutex_unlock(&condmx); /* done */
|
pthread_mutex_unlock(&condmx); /* done */
|
||||||
return nc;
|
return nc;
|
||||||
}
|
}
|
||||||
|
cond_t* copy_condition(con)
|
||||||
|
cond_t* con;
|
||||||
|
{
|
||||||
|
cond_t* c;
|
||||||
|
c = malloc(sizeof(cond_t));
|
||||||
|
memset(c, 0, sizeof(cond_t));
|
||||||
|
c->filtername = strdup(con->filtername);
|
||||||
|
if(con->name != NULL)
|
||||||
|
c->name = strdup(con->name);
|
||||||
|
/* XXX: is this safe? */
|
||||||
|
if(con->namerx.prex != NULL) {
|
||||||
|
c->namerx.pcresize = con->namerx.pcresize;
|
||||||
|
c->namerx.prex = malloc(c->namerx.pcresize);
|
||||||
|
memmove(c->namerx.prex, con->namerx.prex, c->namerx.pcresize);
|
||||||
|
}
|
||||||
|
if(con->number != NULL)
|
||||||
|
c->number = strdup(con->number);
|
||||||
|
if(con->numbrx.prex != NULL) {
|
||||||
|
c->numbrx.pcresize = con->numbrx.pcresize;
|
||||||
|
c->numbrx.prex = malloc(c->numbrx.pcresize);
|
||||||
|
memmove(c->numbrx.prex, con->numbrx.prex, c->numbrx.pcresize);
|
||||||
|
}
|
||||||
|
c->action = con->action;
|
||||||
|
c->flags = con->flags;
|
||||||
|
/* next and last won't be copied; this is for a *single* node */
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
void check_condition(cid)
|
||||||
|
cid_t* cid;
|
||||||
|
{
|
||||||
|
cond_t *ourcond = 0x0, *c, *d, *e;
|
||||||
|
int rcna = -1, rcnu = -1;
|
||||||
|
int ovec[30];
|
||||||
|
int result = 0;
|
||||||
|
pthread_mutex_lock(&condmx);
|
||||||
|
c = topcond;
|
||||||
|
while(c != NULL) {
|
||||||
|
if(c->namerx.prex != NULL)
|
||||||
|
rcna = pcre_exec(c->namerx.prex, NULL, cid->name, strlen(cid->name), 0, 0, ovec, 30);
|
||||||
|
if(c->numbrx.prex != NULL)
|
||||||
|
rcnu = pcre_exec(c->numbrx.prex, NULL, cid->number, strlen(cid->number), 0, 0, ovec, 30);
|
||||||
|
if(rcna > -1) result |= CTFLG_CHECKNAME;
|
||||||
|
if(rcnu > -1) result |= CTFLG_CHECKNUMB;
|
||||||
|
result = result >> 1;
|
||||||
|
if(result >= (c->flags >> 1)) { /* aren't we clever? */
|
||||||
|
if(ourcond == 0x0) {
|
||||||
|
ourcond = copy_condition(c); /* we copy this so if something blocks later on, threads can still continue */
|
||||||
|
} else {
|
||||||
|
e = copy_condition(c);
|
||||||
|
for(d = ourcond; d->next != 0x0; d = d->next);
|
||||||
|
e->last = d;
|
||||||
|
d->next = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(c->flags & CTFLG_STOPPROC) break;
|
||||||
|
result = 0x0;
|
||||||
|
rcna = -1;
|
||||||
|
rcnu = -1;
|
||||||
|
c = c->next;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&condmx); /* we're done with that stuff now since we have our own copies */
|
||||||
|
c = ourcond;
|
||||||
|
while(c != NULL) {
|
||||||
|
if(c->action & CTACT_IGN) {
|
||||||
|
c = c->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(c->action & CTACT_HUP) {
|
||||||
|
lprintf(error, "Hangup not yet implemented! Check back later. (cond %s)\n", c->filtername);
|
||||||
|
}
|
||||||
|
if(c->action & CTACT_RNOT) {
|
||||||
|
lprintf(error, "Mail not yet implemented! Check back later. (cond %s)\n", c->filtername);
|
||||||
|
}
|
||||||
|
if(c->action & CTACT_ANS) {
|
||||||
|
lprintf(error, "Answer not yet implemented! Check back later. (cond %s)\n", c->filtername);
|
||||||
|
}
|
||||||
|
if(c->action & CTACT_PLAY) {
|
||||||
|
lprintf(error, "Play not yet implemented! Check back later. (cond %s)\n", c->filtername);
|
||||||
|
}
|
||||||
|
if(c->action & CTACT_REC) {
|
||||||
|
lprintf(error, "Record not yet implemented! Check back later. (cond %s)\n", c->filtername);
|
||||||
|
}
|
||||||
|
c = c->next;
|
||||||
|
}
|
||||||
|
free_condition(ourcond, 0x1);
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ filters {
|
||||||
name /PONTE/;
|
name /PONTE/;
|
||||||
number /^782.*/;
|
number /^782.*/;
|
||||||
action ignore|hangup;
|
action ignore|hangup;
|
||||||
|
flags cname|cnumber;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
notify {
|
notify {
|
||||||
|
|
Loading…
Reference in a new issue