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

filter_core.c File Reference


Detailed Description

GUI filtering functions.

Author:
Raphael Manfredi

Richard Eckart

Date:
2001-2003

#include "common.h"
#include "filter.h"
#include "filter_core.h"
#include "search.h"
#include "gtk-missing.h"
#include "if/gui_property.h"
#include "if/gui_property_priv.h"
#include "lib/atoms.h"
#include "lib/walloc.h"
#include "lib/utf8.h"
#include "lib/glib-missing.h"
#include "lib/override.h"

Data Structures

struct  shadow
struct  filter_context
 Structure holding "global" variables during filtering. More...


Defines

#define FILTER_HIDE_ON_CLOSE
 If FILTER_HIDE_ON_CLOSE is defined, the filter dialog is only hidden when the dialog is closed instead the of the dialog being destroyed.

#define MATCH_RULE(filter, r, res)

Typedefs

typedef shadow shadow_t

Functions

 RCSID ("$Id:filter_core.c, v 1.34 2005/12/15 10:20:29 cbiere Exp $")
void filter_remove_rule (filter_t *f, rule_t *r)
 Removes a rule directly.

void filter_free (filter_t *f)
 Frees a filter and the filters assiciated with it and unregisters it from current and session filter lists.

void dump_ruleset (const GList *ruleset)
void dump_filter (const filter_t *filter)
void dump_shadow (const shadow_t *shadow)
gint shadow_filter_eq (gconstpointer a, gconstpointer b)
 Comparator function to match a shadow and a filter.

shadow_tshadow_find (filter_t *f)
 Get the shadow for the given filter.

shadow_tshadow_new (filter_t *f)
 Creates a new shadow for a given filter and registers it with our current shadow list.

void shadow_cancel (shadow_t *shadow)
 Forgets all about a given shadow and free's ressourcs for it.

void shadow_commit (shadow_t *shadow)
 Commit all the changes for a given shadow and then forget and free it.

void filter_refresh_display (GList *filter_list)
 Regenerates the filter tree and rules display from after a apply/revert.

void filter_open_dialog (void)
 Open and initialize the filter dialog.

void filter_close_dialog (gboolean commit)
 Close the filter dialog.

rule_tfilter_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.

rule_tfilter_new_text_rule (const gchar *match, gint type, gboolean case_sensitive, filter_t *target, guint16 flags)
rule_tfilter_new_ip_rule (const host_addr_t addr, guint8 mask, filter_t *target, guint16 flags)
rule_tfilter_new_size_rule (filesize_t lower, filesize_t upper, filter_t *target, guint16 flags)
rule_tfilter_new_jump_rule (filter_t *target, guint16 flags)
rule_tfilter_new_sha1_rule (const gchar *sha1, const gchar *filename, filter_t *target, guint16 flags)
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_set (filter_t *f)
 Start working on the given filter.

void filter_close_search (search_t *s)
 Clear the searches shadow, update the combobox and the filter bound to this search (search->ruleser).

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

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

const gchar * filter_lazy_utf8_to_ui_string (const gchar *src)
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 *r)
 Convert the filter to a human readable string.

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

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

void filter_new_for_search (search_t *s)
 Create a new filter bound to a search and register it.

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_free_rule (rule_t *r)
 Free memory reserved by rule respecting the type of the rule.

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_remove_rule_from_session (filter_t *f, rule_t *const r)
 Remove rule from a filter shadow.

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 .

void filter_adapt_order (void)
 Reorders the filter according to the order in the user's table in the gui.

filter_result_tfilter_record (search_t *sch, const struct record *rec)
 Check a particular record against the search filter and the global filters.

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

void filter_init (void)
 Initialize global filters.

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

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

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

void filter_reset_stats (filter_t *filter)
 Reset the stats for a given filter.

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

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

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

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_global (const filter_t *f)
gboolean filter_is_builtin (const filter_t *f)
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 = NULL
 Public variables.

GList * shadow_filters = NULL
GList * filters_added = NULL
GList * filters_removed = NULL
filter_tfilter_drop = NULL
filter_tfilter_show = NULL
filter_tfilter_download = NULL
filter_tfilter_nodownload = NULL
filter_tfilter_return = NULL
filter_tfilter_global_pre = NULL
filter_tfilter_global_post = NULL
GList * filters = NULL
GList * filters_current = NULL


Define Documentation

#define FILTER_HIDE_ON_CLOSE
 

If FILTER_HIDE_ON_CLOSE is defined, the filter dialog is only hidden when the dialog is closed instead the of the dialog being destroyed.

#define MATCH_RULE filter,
r,
res   ) 
 

Value:

do {                                                                \
    (res)->props_set++;                                             \
    (r)->match_count++;                                             \
    (prop_count)++;                                                 \
    (r)->target->match_count++;                                     \
    if (gui_debug >= 10)                                            \
        g_message("matched rule: %s", filter_rule_to_string((r)));  \
} while (0)


Typedef Documentation

typedef struct shadow shadow_t
 


Function Documentation

void dump_filter const filter_t filter  ) 
 

void dump_ruleset const GList *  ruleset  ) 
 

void dump_shadow const shadow_t shadow  ) 
 

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 search_t *  s  ) 
 

Clear the searches shadow, update the combobox and the filter bound to this search (search->ruleser).

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 filter_t f  )  [static]
 

Frees a filter and the filters assiciated with it and unregisters it from current and session filter lists.

void filter_free_result filter_result_t res  ) 
 

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

void filter_free_rule rule_t r  ) 
 

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.

const gchar* filter_lazy_utf8_to_ui_string const gchar *  src  )  [static]
 

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 search_t *  s  ) 
 

Create a new filter bound to a search and register it.

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

rule_t* filter_new_jump_rule filter_t target,
guint16  flags
 

rule_t* filter_new_sha1_rule const gchar *  sha1,
const gchar *  filename,
filter_t target,
guint16  flags
 

rule_t* filter_new_size_rule filesize_t  lower,
filesize_t  upper,
filter_t target,
guint16  flags
 

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 *  match,
gint  type,
gboolean  case_sensitive,
filter_t target,
guint16  flags
 

void filter_open_dialog void   ) 
 

Open and initialize the filter dialog.

filter_result_t* filter_record search_t *  sch,
const struct record rec
 

Check a particular record against the search filter and the global filters.

Returns a filter_property_t array with MAX_FILTER_PROP rows. This must be freed with filter_free_properties.

void filter_refresh_display GList *  filter_list  )  [static]
 

Regenerates the filter tree and rules display from after a apply/revert.

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 filter_t f,
rule_t r
 

Removes a rule directly.

The removal cannot be reversed by cancelling the shadow. The filter is removed from the active filter and from a potentially existing shadow as well. If no shadow exists, no shadow is created.

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 r  ) 
 

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.

RCSID "$Id:filter_core.  c,
v 1.34 2005/12/15 10:20:29 cbiere Exp $" 
 

void shadow_cancel shadow_t shadow  )  [static]
 

Forgets all about a given shadow and free's ressourcs for it.

At this point we can no longer assume that the shadow->current field contains a valid pointer. We may have been called to clean up a shadow for a filter whose ruleset has already been cleared. We don't clean up any memory that is owned by the associated filter.

void shadow_commit shadow_t shadow  )  [static]
 

Commit all the changes for a given shadow and then forget and free it.

gint shadow_filter_eq gconstpointer  a,
gconstpointer  b
[static]
 

Comparator function to match a shadow and a filter.

shadow_t* shadow_find filter_t f  )  [static]
 

Get the shadow for the given filter.

Returns NULL if the filter does not have a shadow yet.

shadow_t* shadow_new filter_t f  )  [static]
 

Creates a new shadow for a given filter and registers it with our current shadow list.


Variable Documentation

filter_t* filter_download = NULL [static]
 

filter_t* filter_drop = NULL [static]
 

filter_t* filter_global_post = NULL [static]
 

filter_t* filter_global_pre = NULL [static]
 

filter_t* filter_nodownload = NULL [static]
 

filter_t* filter_return = NULL [static]
 

filter_t* filter_show = NULL [static]
 

GList* filters = NULL
 

GList* filters_added = NULL [static]
 

GList* filters_current = NULL
 

GList* filters_removed = NULL [static]
 

GList* shadow_filters = NULL [static]
 

filter_t* work_filter = NULL
 

Public variables.


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