Mercurial > noffle
diff src/configfile.c @ 249:0340b9c17edc noffle
[svn] *** empty log message ***
author | mirkol |
---|---|
date | Tue, 14 May 2002 15:25:45 +0100 |
parents | bf290632d29e |
children | 18d6c61ed4e7 |
line wrap: on
line diff
--- a/src/configfile.c Tue Mar 26 17:52:48 2002 +0000 +++ b/src/configfile.c Tue May 14 15:25:45 2002 +0100 @@ -6,7 +6,7 @@ SPOOLDIR VERSION - $Id: configfile.c 341 2001-12-09 11:32:31Z bears $ + $Id: configfile.c 381 2002-05-14 14:25:45Z mirkol $ */ #if HAVE_CONFIG_H @@ -690,6 +690,50 @@ return line; } +/* very simple date parser. + * examples: + * now+ + */ +static Bool +get_simpledate( time_t *timeoffsetp, FilterRuleDateEnumType *vartimep, const char *val) +{ + float timef; + + if ( ! strncasecmp( val, "invalid", 7 ) ) + { + *vartimep = INVALID; + return TRUE; + } + else if ( ! strncasecmp( val, "now", 3 ) ) + { + val += 3; + *vartimep = NOW; + } + else if ( ! strncasecmp( val, "lastupdate", 10 ) ) + { + val += 10; + *vartimep = LASTUPDATE; + } + else + { + *vartimep = FIXED; + *timeoffsetp = Utl_parseNewsDate( val ); + if ( *timeoffsetp == (time_t) -1 ) + return FALSE; + else + return TRUE; + } + /* NOW, LASTUPDATE +/- number of days. */ + timef = atof( val ) * 86400.0 ; /* 24 * 60 * 60 == 86400 */ + + /* let's assume more than 10 years of timeoffset are a mistake. */ + if ( timef > 31536000.0 || timef < -31536000.0 ) + return FALSE; + *timeoffsetp = (time_t) timef; + /* Todo: check if any garbage follows. */ + return TRUE; +} + static void getFilter( const char *line ) { @@ -730,33 +774,49 @@ rule.type = RULE_NEWSGROUP; else if ( strcmp( ruleName, "subject" ) == 0 ) rule.type = RULE_SUBJECT; + else if ( strcmp( ruleName, "reference" ) == 0 ) + rule.type = RULE_REFERENCE; else if ( strcmp( ruleName, "from" ) == 0 ) rule.type = RULE_FROM; else if ( strcmp( ruleName, "msgid" ) == 0 ) rule.type = RULE_MSGID; else if ( strcmp( ruleName, "bytes" ) == 0 ) - rule.type = RULE_BYTES_LT; + rule.type = RULE_BYTES_EQ; else if ( strcmp( ruleName, "lines" ) == 0 ) - rule.type = RULE_LINES_LT; + rule.type = RULE_LINES_EQ; else if ( strcmp( ruleName, "refs" ) == 0 ) - rule.type = RULE_NOREFS_LT; + rule.type = RULE_NOREFS_EQ; else if ( strcmp( ruleName, "xposts" ) == 0 ) - rule.type = RULE_XPOSTS_LT; + rule.type = RULE_XPOSTS_EQ; else if ( strcmp( ruleName, "post-status" ) == 0 ) rule.type = RULE_POST_STATUS; + else if ( strcmp( ruleName, "date" ) == 0 ) + rule.type = RULE_DATE_EQ; + /* date<lastupdate-12 equals older=lastupdate-12 + * date>now+1.5 equals newer=now+1.5 + * date=now equals older=now+1 AND newer=now-1 + * Stupid people like Mirko keep making mistakes + * if they're forced using date< or date>. + */ + else if ( strcmp( ruleName, "older" ) == 0 ) + rule.type = RULE_DATE_LT; + else if ( strcmp( ruleName, "newer" ) == 0 ) + rule.type = RULE_DATE_GT; + else if ( strcmp( ruleName, "action" ) != 0 ) goto synErr; - if ( rule.type == RULE_BYTES_LT || - rule.type == RULE_LINES_LT || - rule.type == RULE_NOREFS_LT || - rule.type == RULE_XPOSTS_LT ) + if ( rule.type == RULE_BYTES_EQ || + rule.type == RULE_LINES_EQ || + rule.type == RULE_NOREFS_EQ || + rule.type == RULE_XPOSTS_EQ || + rule.type == RULE_DATE_EQ ) { - if ( *l == '=' ) - rule.type += 1; + if ( *l == '<' ) + rule.type--; else if ( *l == '>' ) - rule.type += 2; - else if ( *l != '<' ) + rule.type++; + else if ( *l != '=' ) goto synErr; } else if ( *l != '=' ) @@ -796,6 +856,7 @@ goto synErr; } else if (rule.type == RULE_POST_STATUS ) + { if ( ( strcmp( value, "yes" ) == 0 ) || \ ( strcmp( value, "no" ) == 0 ) || \ ( strncmp( value, "mod", 3 ) == 0 ) ) @@ -803,6 +864,17 @@ rule.data.postAllow = value[0]; /* 'y','n' or 'm' */ else goto synErr; + } + else if ( rule.type == RULE_DATE_LT || + rule.type == RULE_DATE_EQ || + rule.type == RULE_DATE_GT ) + { + if ( !get_simpledate( &rule.data.reftime.timeoffset, &rule.data.reftime.vartime, value ) ) + goto synErr; + if ( rule.type != RULE_DATE_EQ && + rule.data.reftime.vartime == INVALID ) + goto synErr; + } else { char * endVal;