view src/filter.h @ 223:ffb1848a39db noffle

[svn] * src/util.c: Improve (correct) error detection when updating timestamp file. * src/content.h, src/content.c: Return Boolean success/fail from Cont_write. Also ensure cont.first isn't polluted in the event of a failed update. * src/client.c,src/control.c,src/fetch.c,src/noffle.c,src/post.c, src/pseudo.c: If Cont_write fails, don't do actions that need it to have worked. Typically, don't update first and last article numbers in group database. * src/server.c: If groupinfo.lastupdate is unreadable or corrupt, spot this and report it and give an explicit error when processing NNTP NEWGROUPS command.
author bears
date Sun, 09 Dec 2001 12:31:57 +0000
parents 21200ce10e68
children 0340b9c17edc
line wrap: on
line source

/*
  filter.h

  Article filtering.

  $Id: filter.h 331 2001-11-22 12:04:45Z mirkol $
*/

#ifndef	FILTER_H
#define	FILTER_H

#include <sys/types.h>
#include <regex.h>
#include "fetchlist.h"
#include "over.h"

/* The possible actions in a filter. */
typedef enum {
    FILTER_FULL,
    FILTER_XOVER,
    FILTER_THREAD,
    FILTER_DISCARD,
    FILTER_DEFAULT
} FilterAction;

/* Representation of a rule. */
typedef enum {
    RULE_NEWSGROUP,					/* Wildmat data */
    RULE_SUBJECT,					/* Regex data */
    RULE_FROM,
    RULE_MSGID,
    RULE_BYTES_LT, RULE_BYTES_EQ, RULE_BYTES_GT,	/* Number data */
    RULE_LINES_LT, RULE_LINES_EQ, RULE_LINES_GT,
    RULE_NOREFS_LT, RULE_NOREFS_EQ, RULE_NOREFS_GT,
    RULE_XPOSTS_LT, RULE_XPOSTS_EQ, RULE_XPOSTS_GT,
    RULE_POST_STATUS					/* 'y','n','m' */
} FilterRuleType;

typedef union {
    regex_t regex;
    unsigned long amount;
    char *grp;
    char postAllow; /* 'y','n','m' */
} FilterRuleData;

typedef struct {
    FilterRuleType type;
    FilterRuleData data;
} FilterRule;

/* A single filter is a collection of rules with an action. */
typedef struct {
    int nRules;
    int maxRules;
    FilterRule *rules;
    FilterAction action;
} Filter;

/* Add a filter to the list of filters. */
void
Flt_addFilter( const Filter *f );

/*
 * Run the rules over the supplied overview. If a specific rule fires,
 * returns its action. If no rule fires, return the default read mode.
 */
FilterAction
Flt_checkFilters( const char *thisGrp, const char *newsgroups,
		  const Over *ov, FetchMode mode );

/*
 * Build and access a filter
 */
Filter *
new_Filter( void );

void
del_Filter( Filter *f );

FilterAction
Flt_action( const Filter *f );

int
Flt_nRules( const Filter *f );

Bool
Flt_getNewsgroups( void );

FilterRule
Flt_rule( const Filter *f, int ruleNo );

void
Flt_setAction( Filter *f, FilterAction action );

void
Flt_addRule( Filter *f, FilterRule rule );

#endif	/* FILTER_H */