Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

filter_core.h File Reference

#include "gui.h"
#include "if/core/filter.h"
#include "lib/host_addr.h"
#include "lib/misc.h"
#include "lib/pattern.h"

Go to the source code of this file.

Data Structures

struct  filter
struct  filter_property
 The following struct is used to hold the state information of filter properties. More...

struct  filter_result
 This is used to hold the result of a filter. More...

struct  rule
 Definition of a filter rule. More...


Defines

#define RULE_FLAG_NEGATE   (1 << 0)
#define RULE_FLAG_VALID   (1 << 1) /**< rule has valid target */
 rule has valid target

#define RULE_FLAG_ACTIVE   (1 << 2)
#define RULE_FLAG_SOFT   (1 << 3)
#define RULE_FLAG_SHADOW   (1 << 4) /**< rule is not yet committed */
 rule is not yet committed

#define FILTER_FLAG_ACTIVE   (1 << 0)
#define FILTER_FLAG_SHADOW   (1 << 4) /**< filter is not yet committed */
 filter is not yet committed

#define RULE_IS_VALID(r)   ((r != NULL) && (r->flags & RULE_FLAG_VALID))
#define RULE_IS_NEGATED(r)   ((r != NULL) && (r->flags & RULE_FLAG_NEGATE))
#define RULE_IS_ACTIVE(r)   ((r != NULL) && (r->flags & RULE_FLAG_ACTIVE))
#define RULE_IS_SOFT(r)   ((r != NULL) && (r->flags & RULE_FLAG_SOFT))
#define RULE_IS_SHADOWED(r)   ((r != NULL) && (r->flags & RULE_FLAG_SHADOW))
#define filter_is_active(f)   ((f != NULL) && (f->flags & FILTER_FLAG_ACTIVE))
#define filter_is_bound(f)   (f->search != NULL)
#define filter_is_shadowed(f)   ((f != NULL) && (f->flags & FILTER_FLAG_SHADOW))
#define FILTER_EXISTS   1
 Some error codes (0 means 'no error').


Typedefs

typedef filter filter_t
typedef filter_property filter_property_t
 The following struct is used to hold the state information of filter properties.

typedef filter_result filter_result_t
 This is used to hold the result of a filter.

typedef rule rule_t
 Definition of a filter rule.


Functions

filter_tfilter_new (const gchar *)
 Create a new filter with the given name.

filter_result_tfilter_record (struct search *, const struct record *)
gchar * filter_rule_condition_to_string (const rule_t *r)
 Convert a rule condition to a human readable string.

gchar * filter_rule_to_string (const rule_t *f)
 Convert the filter to a human readable string.

gboolean filter_is_builtin (const filter_t *f)
gboolean filter_is_global (const filter_t *f)
void filter_reset_stats (filter_t *filter)
 Reset the stats for a given filter.

void filter_rule_reset_stats (rule_t *rule)
 Reset the rule stats for a given rule.

rule_tfilter_duplicate_rule (const rule_t *rule)
 returns a new rule created with information based on the given rule with the appropriate filter_new_*_rule call.

rule_tfilter_new_ip_rule (const host_addr_t addr, guint8 mask, filter_t *, guint16)
rule_tfilter_new_jump_rule (filter_t *, guint16)
rule_tfilter_new_size_rule (filesize_t, filesize_t, filter_t *, guint16)
rule_tfilter_new_text_rule (const gchar *, gint, gboolean, filter_t *, guint16)
rule_tfilter_new_sha1_rule (const gchar *, const gchar *, filter_t *, guint16)
rule_tfilter_new_flag_rule (enum rule_flag_action stable, enum rule_flag_action busy, enum rule_flag_action push, filter_t *target, guint16 flags)
rule_tfilter_new_state_rule (enum filter_prop_state display, enum filter_prop_state download, filter_t *target, guint16 flags)
void filter_adapt_order (void)
 Reorders the filter according to the order in the user's table in the gui.

void filter_append_rule (filter_t *f, rule_t *const r)
 Append a new rule to a filter.

void filter_append_rule_to_session (filter_t *f, rule_t *const r)
 Append a new rule to the filter shadow.

void filter_revert_changes (void)
 Free the ressources for all added filters and forget all shadows.

void filter_apply_changes (void)
 Go through all the shadow filters, and commit the recorded changes to the associated filter.

void filter_close_dialog (gboolean)
 Close the filter dialog.

void filter_close_search (struct search *)
void filter_add_to_session (filter_t *f)
 Add a filter to the current editing session.

void filter_remove_from_session (filter_t *f)
 Mark the given filter as removed and delete it when the dialog changes are committed.

void filter_init (void)
 Initialize global filters.

void filter_new_for_search (struct search *s)
void filter_open_dialog (void)
 Open and initialize the filter dialog.

void filter_remove_rule_from_session (filter_t *, rule_t *const )
 Remove rule from a filter shadow.

void filter_replace_rule_in_session (filter_t *, rule_t *const , rule_t *const )
 Replaces filter rule A with filter rule B in filter .

void filter_set (filter_t *)
 Start working on the given filter.

void filter_set_enabled (filter_t *filter, gboolean active)
 Change the "enabled" flag of a filter.

void filter_shutdown (void)
 Free global filters and save state.

void filter_timer (void)
 Periodically update the filter display with current data.

void filter_update_targets (void)
 Trigger a rebuild of the target combos.

void filter_free_result (filter_result_t *)
 Free a filter_result returned by filter_record after it has been processed.

void filter_free_rule (rule_t *rule)
 Free memory reserved by rule respecting the type of the rule.

filter_tfilter_find_by_name_in_session (const gchar *name)
 Returns the filter with the given name in the session if it exists, otherwise returns NULL.

gboolean filter_is_valid_in_session (const filter_t *f)
 Checks wether a filter is existant in a filter editing session.

filter_tfilter_get_drop_target (void)
filter_tfilter_get_show_target (void)
filter_tfilter_get_download_target (void)
filter_tfilter_get_nodownload_target (void)
filter_tfilter_get_return_target (void)
filter_tfilter_get_global_pre (void)
filter_tfilter_get_global_post (void)
void filter_add_drop_sha1_rule (const struct record *rec, filter_t *filter)
 Adds a drop SHA1 rule to specified filter.

void filter_add_drop_name_rule (const struct record *rec, filter_t *filter)
 Adds a drop filename rule to specified filter.

void filter_add_drop_host_rule (const struct record *rec, filter_t *filter)
 Adds a drop host rule to specified filter.

void filter_add_download_sha1_rule (const struct record *rec, filter_t *filter)
 Adds a download SHA1 rule to specified filter.

void filter_add_download_name_rule (const struct record *rec, filter_t *filter)
 Adds a download filename rule to specified filter.


Variables

filter_twork_filter
 Public variables.


Define Documentation

#define FILTER_EXISTS   1
 

Some error codes (0 means 'no error').

#define FILTER_FLAG_ACTIVE   (1 << 0)
 

#define FILTER_FLAG_SHADOW   (1 << 4) /**< filter is not yet committed */
 

filter is not yet committed

#define filter_is_active  )     ((f != NULL) && (f->flags & FILTER_FLAG_ACTIVE))
 

#define filter_is_bound  )     (f->search != NULL)
 

#define filter_is_shadowed  )     ((f != NULL) && (f->flags & FILTER_FLAG_SHADOW))
 

#define RULE_FLAG_ACTIVE   (1 << 2)
 

#define RULE_FLAG_NEGATE   (1 << 0)
 

#define RULE_FLAG_SHADOW   (1 << 4) /**< rule is not yet committed */
 

rule is not yet committed

#define RULE_FLAG_SOFT   (1 << 3)
 

#define RULE_FLAG_VALID   (1 << 1) /**< rule has valid target */
 

rule has valid target

#define RULE_IS_ACTIVE  )     ((r != NULL) && (r->flags & RULE_FLAG_ACTIVE))
 

#define RULE_IS_NEGATED  )     ((r != NULL) && (r->flags & RULE_FLAG_NEGATE))
 

#define RULE_IS_SHADOWED  )     ((r != NULL) && (r->flags & RULE_FLAG_SHADOW))
 

#define RULE_IS_SOFT  )     ((r != NULL) && (r->flags & RULE_FLAG_SOFT))
 

#define RULE_IS_VALID  )     ((r != NULL) && (r->flags & RULE_FLAG_VALID))
 


Typedef Documentation

typedef struct filter_property filter_property_t
 

The following struct is used to hold the state information of filter properties.

A rule can set one or more of those properties to define how the record should be processed (displayed, downloaded, etc).

typedef struct filter_result filter_result_t
 

This is used to hold the result of a filter.

The props_set attribute holds the number of properties which have a state != UNKNOWN and the prop array holds the actual property informations.

typedef struct filter filter_t
 

typedef struct rule rule_t
 

Definition of a filter rule.


Function Documentation

void filter_adapt_order void   ) 
 

Reorders the filter according to the order in the user's table in the gui.

This should only be used after the user has reordered the table. It cannot properly cope with added or deleted items. This will also only work if a filter is currently being displayed in the table. If the filter dialog has not been initialized or not filter is currently worked on, it will silently fail.

void filter_add_download_name_rule const struct record rec,
filter_t filter
 

Adds a download filename rule to specified filter.

void filter_add_download_sha1_rule const struct record rec,
filter_t filter
 

Adds a download SHA1 rule to specified filter.

void filter_add_drop_host_rule const struct record rec,
filter_t filter
 

Adds a drop host rule to specified filter.

void filter_add_drop_name_rule const struct record rec,
filter_t filter
 

Adds a drop filename rule to specified filter.

void filter_add_drop_sha1_rule const struct record rec,
filter_t filter
 

Adds a drop SHA1 rule to specified filter.

void filter_add_to_session filter_t f  ) 
 

Add a filter to the current editing session.

Never try to add a filter twice. Returns a error code on failure and 0 on success.

void filter_append_rule filter_t f,
rule_t *const  r
 

Append a new rule to a filter.

If necessary also update the shadow. The addition of the rule cannot be cancelled by canceling the shadow. If no shadow for the filters exists, none is created.

void filter_append_rule_to_session filter_t f,
rule_t *const  r
 

Append a new rule to the filter shadow.

This call will fail with an assertion error if the rule is already existing in the shadow.

void filter_apply_changes void   ) 
 

Go through all the shadow filters, and commit the recorded changes to the associated filter.

We walk through the shadow->current list. Every item in shadow->removed will be removed from the searchs filter and the memory will be freed. Then shadow->current will be set as the new filter for that search.

void filter_close_dialog gboolean  commit  ) 
 

Close the filter dialog.

If commit is TRUE the changes are committed, otherwise dropped.

void filter_close_search struct search  ) 
 

rule_t* filter_duplicate_rule const rule_t r  ) 
 

returns a new rule created with information based on the given rule with the appropriate filter_new_*_rule call.

Defaults set by those calls (like RULE_FLAG_VALID) will also apply to the the returned rule.

filter_t* filter_find_by_name_in_session const gchar *  name  ) 
 

Returns the filter with the given name in the session if it exists, otherwise returns NULL.

If no session is started, it looks in the normal filter list.

void filter_free_result filter_result_t  ) 
 

Free a filter_result returned by filter_record after it has been processed.

void filter_free_rule rule_t rule  ) 
 

Free memory reserved by rule respecting the type of the rule.

filter_t* filter_get_download_target void   ) 
 

filter_t* filter_get_drop_target void   ) 
 

filter_t* filter_get_global_post void   ) 
 

filter_t* filter_get_global_pre void   ) 
 

filter_t* filter_get_nodownload_target void   ) 
 

filter_t* filter_get_return_target void   ) 
 

filter_t* filter_get_show_target void   ) 
 

void filter_init void   ) 
 

Initialize global filters.

gboolean filter_is_builtin const filter_t f  ) 
 

gboolean filter_is_global const filter_t f  ) 
 

gboolean filter_is_valid_in_session const filter_t f  ) 
 

Checks wether a filter is existant in a filter editing session.

If no session is started it checks wether the filter is valid in outside the session.

filter_t* filter_new const gchar *  name  ) 
 

Create a new filter with the given name.

Parameters:
name The name for the filter; must be UTF-8 encoded; the string will be copied.
Returns:
an initialized filter context.

rule_t* filter_new_flag_rule enum rule_flag_action  stable,
enum rule_flag_action  busy,
enum rule_flag_action  push,
filter_t target,
guint16  flags
 

void filter_new_for_search struct search s  ) 
 

rule_t* filter_new_ip_rule const host_addr_t  addr,
guint8  mask,
filter_t ,
guint16 
 

rule_t* filter_new_jump_rule filter_t ,
guint16 
 

rule_t* filter_new_sha1_rule const gchar *  ,
const gchar *  ,
filter_t ,
guint16 
 

rule_t* filter_new_size_rule filesize_t  ,
filesize_t  ,
filter_t ,
guint16 
 

rule_t* filter_new_state_rule enum filter_prop_state  display,
enum filter_prop_state  download,
filter_t target,
guint16  flags
 

rule_t* filter_new_text_rule const gchar *  ,
gint  ,
gboolean  ,
filter_t ,
guint16 
 

void filter_open_dialog void   ) 
 

Open and initialize the filter dialog.

filter_result_t* filter_record struct search ,
const struct record
 

void filter_remove_from_session filter_t f  ) 
 

Mark the given filter as removed and delete it when the dialog changes are committed.

void filter_remove_rule_from_session filter_t f,
rule_t *const  r
 

Remove rule from a filter shadow.

This call will fail with an assertion error if the rule has already been removed from the shadow or if it never was in the shadow. The memory associated with the rule will be freed.

void filter_replace_rule_in_session filter_t f,
rule_t *const  old_rule,
rule_t *const  new_rule
 

Replaces filter rule A with filter rule B in filter .

A must already be in the shadow and B must not!

CAUTION: ACTUALLY B MUST NOT BE IN ANY OTHER SEARCH !!!

The memory for A is freed in the process.

void filter_reset_stats filter_t filter  ) 
 

Reset the stats for a given filter.

void filter_revert_changes void   ) 
 

Free the ressources for all added filters and forget all shadows.

A running session will not be ended by this.

gchar* filter_rule_condition_to_string const rule_t r  ) 
 

Convert a rule condition to a human readable string.

void filter_rule_reset_stats rule_t rule  ) 
 

Reset the rule stats for a given rule.

gchar* filter_rule_to_string const rule_t f  ) 
 

Convert the filter to a human readable string.

void filter_set filter_t f  ) 
 

Start working on the given filter.

Set this filter as work_filter so we can commit the changed rules to this filter.

void filter_set_enabled filter_t filter,
gboolean  active
 

Change the "enabled" flag of a filter.

void filter_shutdown void   ) 
 

Free global filters and save state.

void filter_timer void   ) 
 

Periodically update the filter display with current data.

void filter_update_targets void   ) 
 

Trigger a rebuild of the target combos.


Variable Documentation

filter_t* work_filter
 

Public variables.


Generated on Sun Feb 12 10:50:01 2006 for Gtk-Gnutella by doxygen 1.3.6