diff options
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 81 |
1 files changed, 74 insertions, 7 deletions
diff --git a/src/config.c b/src/config.c index 1c10591..66ea944 100644 --- a/src/config.c +++ b/src/config.c @@ -57,6 +57,8 @@ typedef enum { TOK_BlockSubject, TOK_SubjectMacro, TOK_Blacklist, + TOK_Include, + TOK_AllowTo, TOK_VarHostname, TOK_VarPort, TOK_VarUsername, @@ -128,6 +130,8 @@ static const Command cmd_table[]= {"block_subject", TOK_BlockSubject}, {"subject_macro", TOK_SubjectMacro}, {"blacklist", TOK_Blacklist}, + {"include", TOK_Include}, + {"allow_to", TOK_AllowTo}, /* Variables */ @@ -160,6 +164,7 @@ static const Command cmd_table[]= /* ---------------------------------------- REQUIRED PROTOS */ static Token GetToken(FILE *fp, DString *ret); +static int Parse(FILE *fp); /* ---------------------------------------- COMMAND HANDLER UTILS @@ -417,6 +422,22 @@ static int DoDomain(FILE *fp) DBBlockSubject(domain,re); break; + case TOK_AllowTo: + GetToken(fp,&ds); + + ds=ExpandRE(ds); + + if (!(re=RECompile(ds->text))) + { + DSAddCP(error,"Bad regular expression: "); + DSAddDS(error,ds); + DSFree(ds); + return FALSE; + } + + DBAllowTo(domain,re); + break; + default: DSAddCP(error,"Unexpected string in domain command: "); DSAddDS(error,ds); @@ -576,6 +597,42 @@ static int DoBlacklist(FILE *fp) } +static int DoInclude(FILE *fp) +{ + FILE *inc; + DString ds; + Token tok; + int ret; + + ds=DSInit(); + + tok=GetToken(fp,&ds); + + if (tok==TOK_EOF) + { + DSAddCP(error,"Unexpected EOF in include command"); + DSFree(ds); + return FALSE; + } + + if (!(inc=fopen(ds->text,"r"))) + { + DSAddCP(error,"Couldn't open include file "); + DSAddDS(error,ds); + DSFree(ds); + return FALSE; + } + + DSFree(ds); + + ret=Parse(inc); + + fclose(inc); + + return ret; +} + + /* ---------------------------------------- PRVIVATE FUNCTIONS */ static int Getc(FILE *fp) @@ -752,6 +809,11 @@ static int Parse(FILE *fp) ok=FALSE; break; + case TOK_Include: + if (!DoInclude(fp)) + ok=FALSE; + break; + case TOK_Expression: DSAddCP(error,"Unknown command in config file: "); DSAddDS(error,txt); @@ -780,7 +842,7 @@ static int Parse(FILE *fp) /* ---------------------------------------- INTERFACES */ -int ConfigLoad(void) +int ConfigLoad(const char *path) { DString ds; FILE *fp; @@ -793,14 +855,19 @@ int ConfigLoad(void) password=CopyStr(""); log=CopyStr(""); - if (!getenv("HOME")) - return FALSE; - ds=DSInit(); - DSAddCP(ds,getenv("HOME")); - DSAddChar(ds,'/'); - DSAddCP(ds,".kbsrc"); + if (path) + DSAddCP(ds,path); + else + { + if (!getenv("HOME")) + return FALSE; + + DSAddCP(ds,getenv("HOME")); + DSAddChar(ds,'/'); + DSAddCP(ds,".kbsrc"); + } if ((fp=fopen(ds->text,"r"))) ret=Parse(fp); |