diff options
Diffstat (limited to 'src/dbase.c')
-rw-r--r-- | src/dbase.c | 136 |
1 files changed, 102 insertions, 34 deletions
diff --git a/src/dbase.c b/src/dbase.c index ce568af..aed142d 100644 --- a/src/dbase.c +++ b/src/dbase.c @@ -35,7 +35,6 @@ static const char id[]="$Id$"; #include "dbase.h" #include "dstring.h" #include "config.h" -#include "rexp.h" #include "util.h" @@ -43,29 +42,31 @@ static const char id[]="$Id$"; */ struct Domain { - char *name; - int def_block; - int no_user; - int no_block; - int no_allow; - char **user; - char **block; - char **allow; - Domain *next; - Domain *prev; + RE_Expression name; + int def_block; + int no_user; + int no_block; + int no_allow; + char **user; + RE_Expression *block; + RE_Expression *allow; + Domain *next; + Domain *prev; }; /* ---------------------------------------- GLOBALS */ -static Domain *head; -static Domain *tail; +static Domain *head; +static Domain *tail; -static int no_trusted_users=0; -static int no_trusted_domains=0; +static int no_trusted_users=0; +static int no_trusted_domains=0; -static char **trusted_user=NULL; -static char **trusted_domain=NULL; +static char **trusted_user=NULL; +static char **trusted_domain=NULL; + +static const char *reason; /* ---------------------------------------- PRVIVATE FUNCTIONS @@ -106,7 +107,7 @@ static const Domain *GetDomain(const char *domain) while(dom) { - if (RExpSearch(dom->name,domain)==RE_Found) + if (RESearch(dom->name,domain)) return dom; dom=dom->next; @@ -144,13 +145,13 @@ static void DeJunk(DString ds, const char *p) /* ---------------------------------------- INTERFACES */ -Domain *DBNewDomain(const char *regexp) +Domain *DBNewDomain(RE_Expression name) { Domain *dom; dom=Malloc(sizeof *dom); - dom->name=CopyStr(regexp); + dom->name=name; dom->def_block=FALSE; dom->no_user=0; @@ -187,19 +188,19 @@ void DBBlockUser(Domain *domain, const char *username) } -void DBAllowSubject(Domain *domain, const char *regexp) +void DBAllowSubject(Domain *domain, RE_Expression re) { domain->no_allow++; - domain->allow=Realloc(domain->allow,sizeof(char *)*domain->no_allow); - domain->allow[domain->no_allow-1]=CopyStr(regexp); + domain->allow=Realloc(domain->allow,sizeof(RE_Expression)*domain->no_allow); + domain->allow[domain->no_allow-1]=re; } -void DBBlockSubject(Domain *domain, const char *regexp) +void DBBlockSubject(Domain *domain, RE_Expression re) { domain->no_block++; - domain->block=Realloc(domain->block,sizeof(char *)*domain->no_block); - domain->block[domain->no_block-1]=CopyStr(regexp); + domain->block=Realloc(domain->block,sizeof(RE_Expression)*domain->no_block); + domain->block[domain->no_block-1]=re; } @@ -226,6 +227,8 @@ int DBBlockMessage(const POP3Message *msg) const Domain *dom; int f; + reason="None"; + if (IsTrustedDomain(msg->from_domain)) return FALSE; @@ -234,22 +237,27 @@ int DBBlockMessage(const POP3Message *msg) if (ConfigInt(CONFIG_BLOCKHTML) && strncmp(msg->content_type,html,strlen(html))==0) + { + reason="HTML message"; return TRUE; + } if (!(dom=GetDomain(msg->from_domain))) return FALSE; for(f=0;f<dom->no_user;f++) { + int res; + if (ConfigInt(CONFIG_CASESENSE)) - { - if (strcmp(dom->user[f],msg->from_uname)==0) - return TRUE; - } + res=strcmp(dom->user[f],msg->from_uname); else + res=strcasecmp(dom->user[f],msg->from_uname); + + if (res==0) { - if (strcasecmp(dom->user[f],msg->from_uname)==0) - return TRUE; + reason="disallowed name"; + return TRUE; } } @@ -262,7 +270,7 @@ int DBBlockMessage(const POP3Message *msg) for(f=0;f<dom->no_allow;f++) { - if (RExpSearch(dom->allow[f],ds->text)==RE_Found) + if (RESearch(dom->allow[f],ds->text)) { DSFree(ds); return FALSE; @@ -271,16 +279,76 @@ int DBBlockMessage(const POP3Message *msg) for(f=0;f<dom->no_block;f++) { - if (RExpSearch(dom->block[f],ds->text)==RE_Found) + if (RESearch(dom->block[f],ds->text)) { + reason="disallowed subject"; DSFree(ds); return TRUE; } } + reason="default"; DSFree(ds); return dom->def_block; } +const char *DBBlockReason(void) +{ + return reason; +} + + +void DBClose(void) +{ + Domain *d; + int f; + + for(f=0;f<no_trusted_domains;f++) + free(trusted_domain[f]); + + free(trusted_domain); + + for(f=0;f<no_trusted_users;f++) + free(trusted_user[f]); + + free(trusted_user); + + d=head; + + while(d) + { + Domain *t; + + t=d; + + d=d->next; + + for(f=0;f<t->no_user;f++) + free(t->user[f]); + + free(t->user); + + for(f=0;f<t->no_block;f++) + REFree(t->block[f]); + + free(t->block); + + for(f=0;f<t->no_allow;f++) + free(t->allow[f]); + + free(t->allow); + + free(t); + } + + no_trusted_users=0; + no_trusted_domains=0; + + head=tail=NULL; + trusted_user=NULL; + trusted_domain=NULL; +} + + /* END OF FILE */ |