summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c113
1 files changed, 109 insertions, 4 deletions
diff --git a/src/config.c b/src/config.c
index 616fabf..268198d 100644
--- a/src/config.c
+++ b/src/config.c
@@ -53,6 +53,7 @@ typedef enum {
TOK_BlockUser,
TOK_AllowSubject,
TOK_BlockSubject,
+ TOK_SubjectMacro,
TOK_VarHostname,
TOK_VarPort,
TOK_VarUsername,
@@ -77,10 +78,17 @@ typedef struct Command
Token token;
} Command;
+typedef struct
+ {
+ char *macro;
+ char *expansion;
+ } Macro;
+
/* ---------------------------------------- GLOBALS
*/
static DString error;
+
static char *hostname=NULL;
static char *username=NULL;
static char *password=NULL;
@@ -93,6 +101,9 @@ static int testmode=FALSE;
static int blockhtml=FALSE;
static int verbose=TRUE;
+static int no_macro=0;
+static Macro *macro=NULL;
+
/* ---------------------------------------- COMMAND TABLE
*/
@@ -110,6 +121,7 @@ static const Command cmd_table[]=
{"block_user", TOK_BlockUser},
{"allow_subject", TOK_AllowSubject},
{"block_subject", TOK_BlockSubject},
+ {"subject_macro", TOK_SubjectMacro},
/* Variables
*/
@@ -143,6 +155,48 @@ static const Command cmd_table[]=
static Token GetToken(FILE *fp, DString *ret);
+/* ---------------------------------------- COMMAND HANDLER UTILS
+*/
+static DString ExpandRE(DString re)
+{
+ DString new;
+ Macro *m;
+ char *p;
+ int f;
+
+ new=DSInit();
+
+ p=re->text;
+
+ while(*p)
+ {
+ m=NULL;
+
+ for(f=0;f<no_macro && !m;f++)
+ {
+ if (strncmp(p,macro[f].macro,strlen(macro[f].macro))==0)
+ {
+ m=macro+f;
+ }
+ }
+
+ if (!m)
+ {
+ DSAddChar(new,*p);
+ p++;
+ }
+ else
+ {
+ DSAddCP(new,m->expansion);
+ p+=strlen(m->macro);
+ }
+ }
+
+ DSFree(re);
+ return new;
+}
+
+
/* ---------------------------------------- COMMAND HANDLERS
*/
static int DoSet(FILE *fp)
@@ -252,7 +306,6 @@ static int DoDomain(FILE *fp)
{
DString ds;
Token tok;
- int status=TRUE;
Domain *domain;
RE_Expression re;
@@ -327,6 +380,8 @@ static int DoDomain(FILE *fp)
case TOK_AllowSubject:
GetToken(fp,&ds);
+ ds=ExpandRE(ds);
+
if (!(re=RECompile(ds->text)))
{
DSAddCP(error,"Bad regular expression: ");
@@ -341,6 +396,8 @@ static int DoDomain(FILE *fp)
case TOK_BlockSubject:
GetToken(fp,&ds);
+ ds=ExpandRE(ds);
+
if (!(re=RECompile(ds->text)))
{
DSAddCP(error,"Bad regular expression: ");
@@ -371,7 +428,6 @@ static int DoTrustedUsers(FILE *fp)
{
DString ds;
Token tok;
- int status=TRUE;
ds=DSInit();
@@ -406,7 +462,6 @@ static int DoTrustedDomains(FILE *fp)
{
DString ds;
Token tok;
- int status=TRUE;
ds=DSInit();
@@ -433,6 +488,42 @@ static int DoTrustedDomains(FILE *fp)
}
+static int DoSubjectMacro(FILE *fp)
+{
+ DString arg[2];
+ int f;
+
+ for(f=0;f<2;f++)
+ {
+ arg[f]=DSInit();
+
+ if (GetToken(fp,&arg[f])==TOK_EOF)
+ {
+ DSAddCP(error,"Unexpected EOF in subject_macro");
+ return FALSE;
+ }
+ }
+
+ if (arg[0]->len==0 || arg[1]->len==0)
+ {
+ DSAddCP(error,"Can't use zero length strings in subject_macro");
+ return FALSE;
+ }
+
+ no_macro++;
+
+ macro=Realloc(macro,sizeof *macro * no_macro);
+
+ macro[no_macro-1].macro=CopyStr(arg[0]->text);
+ macro[no_macro-1].expansion=CopyStr(arg[1]->text);
+
+ for(f=0;f<2;f++)
+ DSFree(arg[f]);
+
+ return TRUE;
+}
+
+
/* ---------------------------------------- PRVIVATE FUNCTIONS
*/
static int Getc(FILE *fp)
@@ -570,7 +661,6 @@ static int Parse(FILE *fp)
{
DString txt;
Token tok;
- char *p;
txt=DSInit();
@@ -600,6 +690,11 @@ static int Parse(FILE *fp)
ok=FALSE;
break;
+ case TOK_SubjectMacro:
+ if (!DoSubjectMacro(fp))
+ ok=FALSE;
+ break;
+
case TOK_Expression:
DSAddCP(error,"Unknown command in config file: ");
DSAddDS(error,txt);
@@ -725,6 +820,16 @@ int ConfigInt(ConfigIntVar var)
void ConfigClose(void)
{
+ int f;
+
+ for(f=0;f<no_macro;f++)
+ {
+ free(macro[f].macro);
+ free(macro[f].expansion);
+ }
+
+ free(macro);
+
DSFree(error);
free(hostname);
free(username);