00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _gtk_filter_core_h_
00027 #define _gtk_filter_core_h_
00028
00029 #include "gui.h"
00030 #include "if/core/filter.h"
00031 #include "lib/host_addr.h"
00032 #include "lib/misc.h"
00033 #include "lib/pattern.h"
00034
00035
00036
00037
00038
00039 struct record;
00040
00041 typedef struct filter {
00042 gchar *name;
00043 GList *ruleset;
00044 struct search *search;
00045 gboolean visited;
00046 gint32 refcount;
00047 flag_t flags;
00048 guint32 match_count;
00049 guint32 fail_count;
00050 } filter_t;
00051
00052 #define RULE_FLAG_NEGATE (1 << 0)
00053 #define RULE_FLAG_VALID (1 << 1)
00054 #define RULE_FLAG_ACTIVE (1 << 2)
00055 #define RULE_FLAG_SOFT (1 << 3)
00056 #define RULE_FLAG_SHADOW (1 << 4)
00058 #define FILTER_FLAG_ACTIVE (1 << 0)
00059 #define FILTER_FLAG_SHADOW (1 << 4)
00061 #define RULE_IS_VALID(r) ((r != NULL) && (r->flags & RULE_FLAG_VALID))
00062 #define RULE_IS_NEGATED(r) ((r != NULL) && (r->flags & RULE_FLAG_NEGATE))
00063 #define RULE_IS_ACTIVE(r) ((r != NULL) && (r->flags & RULE_FLAG_ACTIVE))
00064 #define RULE_IS_SOFT(r) ((r != NULL) && (r->flags & RULE_FLAG_SOFT))
00065 #define RULE_IS_SHADOWED(r) ((r != NULL) && (r->flags & RULE_FLAG_SHADOW))
00066
00067 #define filter_is_active(f) ((f != NULL) && (f->flags & FILTER_FLAG_ACTIVE))
00068 #define filter_is_bound(f) (f->search != NULL)
00069 #define filter_is_shadowed(f) ((f != NULL) && (f->flags & FILTER_FLAG_SHADOW))
00070
00071
00075 #define FILTER_EXISTS 1
00076
00082 typedef struct filter_property {
00083 filter_prop_state_t state;
00084 gpointer user_data;
00085 } filter_property_t;
00086
00092 typedef struct filter_result {
00093 gint props_set;
00094 filter_property_t props[MAX_FILTER_PROP];
00095 } filter_result_t;
00096
00097
00098
00102 typedef struct rule {
00103 enum rule_type type;
00104 flag_t flags;
00105 guint32 match_count;
00106 guint32 fail_count;
00107 filter_t *target;
00108 union {
00109 struct _f_text {
00110 gint case_sensitive:1;
00111 enum rule_text_type type;
00112 gchar *match;
00113 size_t match_len;
00114 union {
00115 cpattern_t *pattern;
00116 GList *words;
00117 regex_t *re;
00118 } u;
00119 } text;
00120 struct _f_ip {
00121 host_addr_t addr;
00122 guint8 mask;
00123 } ip;
00124 struct _f_size {
00125 filesize_t lower;
00126 filesize_t upper;
00127 } size;
00128 struct _f_sha1 {
00129 gchar *hash;
00130 gchar *filename;
00131 } sha1;
00132 struct _f_flag {
00133 enum rule_flag_action busy;
00134 enum rule_flag_action stable;
00135 enum rule_flag_action push;
00136 } flag;
00137 struct _f_state {
00138 enum filter_prop_state display;
00139 enum filter_prop_state download;
00140 } state;
00141 } u;
00142 } rule_t;
00143
00144
00145
00149 extern filter_t *work_filter;
00150
00151
00152
00153
00154
00155
00156 filter_t *filter_new(const gchar *);
00157 filter_result_t *filter_record(struct search *, const struct record *);
00158 gchar *filter_rule_condition_to_string(const rule_t *r);
00159 gchar *filter_rule_to_string(const rule_t *f);
00160 gboolean filter_is_builtin(const filter_t *f);
00161 gboolean filter_is_global(const filter_t *f);
00162 void filter_reset_stats(filter_t *filter);
00163 void filter_rule_reset_stats(rule_t *rule);
00164 rule_t *filter_duplicate_rule(const rule_t *rule);
00165 rule_t *filter_new_ip_rule(const host_addr_t addr,
00166 guint8 mask, filter_t *, guint16);
00167 rule_t *filter_new_jump_rule(filter_t *,guint16);
00168 rule_t *filter_new_size_rule(filesize_t, filesize_t, filter_t *, guint16);
00169 rule_t *filter_new_text_rule(const gchar *, gint,
00170 gboolean, filter_t *, guint16);
00171 rule_t *filter_new_sha1_rule(const gchar *, const gchar *, filter_t *, guint16);
00172 rule_t *filter_new_flag_rule
00173 (enum rule_flag_action stable, enum rule_flag_action busy,
00174 enum rule_flag_action push, filter_t *target, guint16 flags);
00175 rule_t *filter_new_state_rule
00176 (enum filter_prop_state display, enum filter_prop_state download,
00177 filter_t *target, guint16 flags);
00178 void filter_adapt_order(void);
00179 void filter_append_rule(filter_t *f, rule_t * const r);
00180 void filter_append_rule_to_session(filter_t * f, rule_t * const r);
00181 void filter_revert_changes(void);
00182 void filter_apply_changes(void);
00183 void filter_close_dialog(gboolean);
00184 void filter_close_search(struct search *);
00185 void filter_add_to_session(filter_t *f);
00186 void filter_remove_from_session(filter_t *f);
00187 void filter_init(void);
00188 void filter_new_for_search(struct search *s);
00189 void filter_open_dialog(void);
00190 void filter_remove_rule_from_session(filter_t *, rule_t * const);
00191 void filter_replace_rule_in_session(filter_t *, rule_t * const, rule_t * const);
00192 void filter_set(filter_t *);
00193 void filter_set_enabled(filter_t *filter, gboolean active);
00194 void filter_shutdown(void);
00195 void filter_timer(void);
00196 void filter_update_targets(void);
00197 void filter_free_result(filter_result_t *);
00198 void filter_free_rule(rule_t *rule);
00199 filter_t *filter_find_by_name_in_session(const gchar *name);
00200 gboolean filter_is_valid_in_session(const filter_t *f);
00201 filter_t *filter_get_drop_target(void);
00202 filter_t *filter_get_show_target(void);
00203 filter_t *filter_get_download_target(void);
00204 filter_t *filter_get_nodownload_target(void);
00205 filter_t *filter_get_return_target(void);
00206 filter_t *filter_get_global_pre(void);
00207 filter_t *filter_get_global_post(void);
00208
00209
00210
00211
00212
00213 void filter_add_drop_sha1_rule(const struct record *rec, filter_t *filter);
00214 void filter_add_drop_name_rule(const struct record *rec, filter_t *filter);
00215 void filter_add_drop_host_rule(const struct record *rec, filter_t *filter);
00216 void filter_add_download_sha1_rule(const struct record *rec, filter_t *filter);
00217 void filter_add_download_name_rule(const struct record *rec, filter_t *filter);
00218
00219 #endif
00220
00221