comparison 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
comparison
equal deleted inserted replaced
248:cd022deb8390 249:0340b9c17edc
4 The following macros must be set, when compiling this file: 4 The following macros must be set, when compiling this file:
5 CONFIGFILE 5 CONFIGFILE
6 SPOOLDIR 6 SPOOLDIR
7 VERSION 7 VERSION
8 8
9 $Id: configfile.c 341 2001-12-09 11:32:31Z bears $ 9 $Id: configfile.c 381 2002-05-14 14:25:45Z mirkol $
10 */ 10 */
11 11
12 #if HAVE_CONFIG_H 12 #if HAVE_CONFIG_H
13 #include <config.h> 13 #include <config.h>
14 #endif 14 #endif
688 } 688 }
689 *value = '\0'; 689 *value = '\0';
690 return line; 690 return line;
691 } 691 }
692 692
693 /* very simple date parser.
694 * examples:
695 * now+
696 */
697 static Bool
698 get_simpledate( time_t *timeoffsetp, FilterRuleDateEnumType *vartimep, const char *val)
699 {
700 float timef;
701
702 if ( ! strncasecmp( val, "invalid", 7 ) )
703 {
704 *vartimep = INVALID;
705 return TRUE;
706 }
707 else if ( ! strncasecmp( val, "now", 3 ) )
708 {
709 val += 3;
710 *vartimep = NOW;
711 }
712 else if ( ! strncasecmp( val, "lastupdate", 10 ) )
713 {
714 val += 10;
715 *vartimep = LASTUPDATE;
716 }
717 else
718 {
719 *vartimep = FIXED;
720 *timeoffsetp = Utl_parseNewsDate( val );
721 if ( *timeoffsetp == (time_t) -1 )
722 return FALSE;
723 else
724 return TRUE;
725 }
726 /* NOW, LASTUPDATE +/- number of days. */
727 timef = atof( val ) * 86400.0 ; /* 24 * 60 * 60 == 86400 */
728
729 /* let's assume more than 10 years of timeoffset are a mistake. */
730 if ( timef > 31536000.0 || timef < -31536000.0 )
731 return FALSE;
732 *timeoffsetp = (time_t) timef;
733 /* Todo: check if any garbage follows. */
734 return TRUE;
735 }
736
693 static void 737 static void
694 getFilter( const char *line ) 738 getFilter( const char *line )
695 { 739 {
696 Str ruleBuf, value; 740 Str ruleBuf, value;
697 const char *l; 741 const char *l;
728 /* Do we know this rule? */ 772 /* Do we know this rule? */
729 if ( strcmp( ruleName, "group" ) == 0 ) 773 if ( strcmp( ruleName, "group" ) == 0 )
730 rule.type = RULE_NEWSGROUP; 774 rule.type = RULE_NEWSGROUP;
731 else if ( strcmp( ruleName, "subject" ) == 0 ) 775 else if ( strcmp( ruleName, "subject" ) == 0 )
732 rule.type = RULE_SUBJECT; 776 rule.type = RULE_SUBJECT;
777 else if ( strcmp( ruleName, "reference" ) == 0 )
778 rule.type = RULE_REFERENCE;
733 else if ( strcmp( ruleName, "from" ) == 0 ) 779 else if ( strcmp( ruleName, "from" ) == 0 )
734 rule.type = RULE_FROM; 780 rule.type = RULE_FROM;
735 else if ( strcmp( ruleName, "msgid" ) == 0 ) 781 else if ( strcmp( ruleName, "msgid" ) == 0 )
736 rule.type = RULE_MSGID; 782 rule.type = RULE_MSGID;
737 else if ( strcmp( ruleName, "bytes" ) == 0 ) 783 else if ( strcmp( ruleName, "bytes" ) == 0 )
738 rule.type = RULE_BYTES_LT; 784 rule.type = RULE_BYTES_EQ;
739 else if ( strcmp( ruleName, "lines" ) == 0 ) 785 else if ( strcmp( ruleName, "lines" ) == 0 )
740 rule.type = RULE_LINES_LT; 786 rule.type = RULE_LINES_EQ;
741 else if ( strcmp( ruleName, "refs" ) == 0 ) 787 else if ( strcmp( ruleName, "refs" ) == 0 )
742 rule.type = RULE_NOREFS_LT; 788 rule.type = RULE_NOREFS_EQ;
743 else if ( strcmp( ruleName, "xposts" ) == 0 ) 789 else if ( strcmp( ruleName, "xposts" ) == 0 )
744 rule.type = RULE_XPOSTS_LT; 790 rule.type = RULE_XPOSTS_EQ;
745 else if ( strcmp( ruleName, "post-status" ) == 0 ) 791 else if ( strcmp( ruleName, "post-status" ) == 0 )
746 rule.type = RULE_POST_STATUS; 792 rule.type = RULE_POST_STATUS;
793 else if ( strcmp( ruleName, "date" ) == 0 )
794 rule.type = RULE_DATE_EQ;
795 /* date<lastupdate-12 equals older=lastupdate-12
796 * date>now+1.5 equals newer=now+1.5
797 * date=now equals older=now+1 AND newer=now-1
798 * Stupid people like Mirko keep making mistakes
799 * if they're forced using date< or date>.
800 */
801 else if ( strcmp( ruleName, "older" ) == 0 )
802 rule.type = RULE_DATE_LT;
803 else if ( strcmp( ruleName, "newer" ) == 0 )
804 rule.type = RULE_DATE_GT;
805
747 else if ( strcmp( ruleName, "action" ) != 0 ) 806 else if ( strcmp( ruleName, "action" ) != 0 )
748 goto synErr; 807 goto synErr;
749 808
750 if ( rule.type == RULE_BYTES_LT || 809 if ( rule.type == RULE_BYTES_EQ ||
751 rule.type == RULE_LINES_LT || 810 rule.type == RULE_LINES_EQ ||
752 rule.type == RULE_NOREFS_LT || 811 rule.type == RULE_NOREFS_EQ ||
753 rule.type == RULE_XPOSTS_LT ) 812 rule.type == RULE_XPOSTS_EQ ||
754 { 813 rule.type == RULE_DATE_EQ )
755 if ( *l == '=' ) 814 {
756 rule.type += 1; 815 if ( *l == '<' )
816 rule.type--;
757 else if ( *l == '>' ) 817 else if ( *l == '>' )
758 rule.type += 2; 818 rule.type++;
759 else if ( *l != '<' ) 819 else if ( *l != '=' )
760 goto synErr; 820 goto synErr;
761 } 821 }
762 else if ( *l != '=' ) 822 else if ( *l != '=' )
763 goto synErr; 823 goto synErr;
764 824
794 { 854 {
795 if ( regcomp( &rule.data.regex, value, REG_EXTENDED ) != 0 ) 855 if ( regcomp( &rule.data.regex, value, REG_EXTENDED ) != 0 )
796 goto synErr; 856 goto synErr;
797 } 857 }
798 else if (rule.type == RULE_POST_STATUS ) 858 else if (rule.type == RULE_POST_STATUS )
859 {
799 if ( ( strcmp( value, "yes" ) == 0 ) || \ 860 if ( ( strcmp( value, "yes" ) == 0 ) || \
800 ( strcmp( value, "no" ) == 0 ) || \ 861 ( strcmp( value, "no" ) == 0 ) || \
801 ( strncmp( value, "mod", 3 ) == 0 ) ) 862 ( strncmp( value, "mod", 3 ) == 0 ) )
802 /* no need to type out "moderated" */ 863 /* no need to type out "moderated" */
803 rule.data.postAllow = value[0]; /* 'y','n' or 'm' */ 864 rule.data.postAllow = value[0]; /* 'y','n' or 'm' */
804 else 865 else
805 goto synErr; 866 goto synErr;
867 }
868 else if ( rule.type == RULE_DATE_LT ||
869 rule.type == RULE_DATE_EQ ||
870 rule.type == RULE_DATE_GT )
871 {
872 if ( !get_simpledate( &rule.data.reftime.timeoffset, &rule.data.reftime.vartime, value ) )
873 goto synErr;
874 if ( rule.type != RULE_DATE_EQ &&
875 rule.data.reftime.vartime == INVALID )
876 goto synErr;
877 }
806 else 878 else
807 { 879 {
808 char * endVal; 880 char * endVal;
809 int suffix; 881 int suffix;
810 882