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

search_common.c File Reference


Detailed Description

Common GUI search routines.

Author:
Raphael Manfredi
Date:
2003

#include "gui.h"
#include "search.h"
#include "settings.h"
#include "gtk-missing.h"
#include "search_xml.h"
#include <libxml/parser.h>
#include "gtk/statusbar.h"
#include "if/gui_property_priv.h"
#include "if/gnet_property.h"
#include "if/core/downloads.h"
#include "if/core/guid.h"
#include "if/core/sockets.h"
#include "if/bridge/ui2c.h"
#include "lib/atoms.h"
#include "lib/base32.h"
#include "lib/fuzzy.h"
#include "lib/file.h"
#include "lib/glib-missing.h"
#include "lib/vendors.h"
#include "lib/tm.h"
#include "lib/urn.h"
#include "lib/utf8.h"
#include "lib/zalloc.h"
#include "lib/walloc.h"
#include "lib/override.h"

Data Structures

struct  query

Functions

 RCSID ("$Id:search_common.c, v 1.74 2006/02/01 23:13:21 cbiere Exp $")
search_t * search_gui_get_current_search (void)
void search_gui_forget_current_search (void)
void on_option_menu_menu_item_activate (GtkMenuItem *unused_item, gpointer udata)
void search_gui_option_menu_searches_update (void)
void search_gui_option_menu_searches_select (const search_t *sch)
void search_gui_current_search (search_t *sch)
gboolean search_gui_new_search (const gchar *query, flag_t flags, search_t **search)
 Create a new search and start it.

void search_gui_free_alt_locs (record_t *rc)
 Free the alternate locations held within a file record.

gnet_host_vec_tsearch_gui_proxies_clone (gnet_host_vec_t *v)
 Clone the proxies list given by the core.

void search_gui_host_vec_free (gnet_host_vec_t *v)
 Free the cloned vector of host.

void search_gui_free_proxies (results_set_t *rs)
 Free the push proxies held within a result set.

void search_gui_free_record (record_t *rc)
 Free one file record.

const gchar * search_gui_extract_ext (const gchar *filename)
 Tries to extract the extenstion of a file from the filename.

void search_gui_clean_r_set (results_set_t *rs)
 This routine must be called when the results_set has been dispatched to all the opened searches.

void search_gui_free_r_set (results_set_t *rs)
 Free one results_set.

void search_gui_dispose_results (results_set_t *rs)
 Dispose of an empty search results, whose records have all been unreferenced by the searches.

void search_gui_ref_record (record_t *rc)
 Add a reference to the record but don't dare to redeem it!

void search_gui_unref_record (record_t *rc)
 Remove one reference to a file record.

void free_r_sets_helper (gpointer data, gpointer unused_udata)
 Free all the results_set's of a search.

void search_gui_free_r_sets (search_t *sch)
guint search_gui_hash_func (gconstpointer p)
gint search_gui_hash_key_compare (gconstpointer a, gconstpointer b)
void search_gui_remove_r_set (search_t *sch, results_set_t *rs)
 Remove reference to results in our search.

gboolean search_gui_result_is_dup (search_t *sch, record_t *rc)
 Check to see whether we already have a record for this file.

search_t * search_gui_find (gnet_search_t sh)
gchar * search_gui_get_filename_extension (const gchar *filename_utf8)
 Extract the filename extensions - if any - from the given UTF-8 encoded filename and convert it to lowercase.

record_tsearch_gui_create_record (results_set_t *rs, gnet_record_t *r)
 Create a new GUI record within `rs' from a Gnutella record.

results_set_tsearch_gui_create_results_set (GSList *schl, const gnet_results_set_t *r_set)
 Create a new GUI result set from a Gnutella one.

void on_search_entry_activate (GtkWidget *unused_widget, gpointer unused_udata)
void on_option_menu_search_changed (GtkOptionMenu *option_menu, gpointer unused_udata)
void search_gui_common_init (void)
 Initialize common structures.

void search_gui_common_shutdown (void)
 Destroy common structures.

void search_gui_check_alt_locs (results_set_t *rs, record_t *rc)
 Check for alternate locations in the result set, and enqueue the downloads if there are any.

void search_gui_set_sort_defaults (void)
 Makes the sort column and order of the current search the default settings.

void search_gui_store_searches (void)
 Persist searches to disk.

void search_gui_retrieve_searches (void)
 Retrieve searches from disk.

void search_matched (search_t *sch, results_set_t *rs)
 Called to dispatch results to the search window.

void search_gui_update_items (const struct search *sch)
 Update the label string showing search stats.

gboolean search_gui_is_expired (const struct search *sch)
gboolean search_gui_update_expiry (const struct search *sch)
void search_gui_got_results (GSList *schl, const gnet_results_set_t *r_set)
 Called when the core has finished parsing the result set, and the results need to be dispatched to the searches listed in `schl'.

void search_gui_flush (time_t now)
 Periodic timer to flush the accumulated hits during the period and dispatch them to the GUI.

void search_gui_add_targetted_search (gpointer data, gpointer unused_udata)
 Creates a new search based on the filename found and adds a filter to it based on the sha1 hash if it has one or the exact filename if it hasn't.

void search_gui_restart_search (search_t *sch)
 Restart a search from scratch, clearing all existing content.

void search_gui_parse_text_query (const gchar *s, struct query *query)
const gchar * search_gui_parse_query (const gchar *querystr, GList **rules, const gchar **error)
 Parses a query string as entered by the user.

void search_gui_filter_new (search_t *sch, GList *rules)
 Initializes a new filter for the search ``sch'' and adds the rules from the rule list ``rules'' (if any).

gchar * search_xml_indent (const gchar *s)
 Adds some indendation to XML-like text.

void search_gui_history_add (const gchar *s)
 Adds a search string to the search history combo.

void search_gui_new_search_entered (void)
 Create a new search from a query entered by the user.

gboolean search_gui_new_browse_host (const gchar *hostname, host_addr_t addr, guint16 port, const gchar *guid, gboolean push, const gnet_host_vec_t *proxies)
 Create a new "browse host" type search.


Variables

search_t * current_search = NULL
 The search currently displayed.

zone_trs_zone
 Allocation of results_set.

zone_trc_zone
 Allocation of record.

const gchar search_file [] = "searches"
 "old" file to searches

GSList * accumulated_rs = NULL
GList * list_search_history = NULL
GtkLabel * label_items_found = NULL
GtkLabel * label_search_expiry = NULL
struct {
   guint32   flag
   const gchar *   status
open_flags []
 Human readable translation of servent trailer open flags.


Function Documentation

void free_r_sets_helper gpointer  data,
gpointer  unused_udata
[inline, static]
 

Free all the results_set's of a search.

void on_option_menu_menu_item_activate GtkMenuItem *  unused_item,
gpointer  udata
[static]
 

void on_option_menu_search_changed GtkOptionMenu *  option_menu,
gpointer  unused_udata
 

void on_search_entry_activate GtkWidget *  unused_widget,
gpointer  unused_udata
 

RCSID "$Id:search_common.  c,
v 1.74 2006/02/01 23:13:21 cbiere Exp $" 
 

void search_gui_add_targetted_search gpointer  data,
gpointer  unused_udata
 

Creates a new search based on the filename found and adds a filter to it based on the sha1 hash if it has one or the exact filename if it hasn't.

Author:
Andrew Meredith <andrew@anvil.org>

void search_gui_check_alt_locs results_set_t rs,
record_t rc
 

Check for alternate locations in the result set, and enqueue the downloads if there are any.

Then free the alternate location from the record.

void search_gui_clean_r_set results_set_t rs  ) 
 

This routine must be called when the results_set has been dispatched to all the opened searches.

All the records that have not been used by a search are removed.

void search_gui_common_init void   ) 
 

Initialize common structures.

void search_gui_common_shutdown void   ) 
 

Destroy common structures.

record_t* search_gui_create_record results_set_t rs,
gnet_record_t r
 

Create a new GUI record within `rs' from a Gnutella record.

results_set_t* search_gui_create_results_set GSList *  schl,
const gnet_results_set_t r_set
 

Create a new GUI result set from a Gnutella one.

void search_gui_current_search search_t *  sch  ) 
 

void search_gui_dispose_results results_set_t rs  ) 
 

Dispose of an empty search results, whose records have all been unreferenced by the searches.

The results_set is therefore an empty shell, useless.

const gchar* search_gui_extract_ext const gchar *  filename  ) 
 

Tries to extract the extenstion of a file from the filename.

The return value is only valid until the function is called again.

void search_gui_filter_new search_t *  sch,
GList *  rules
 

Initializes a new filter for the search ``sch'' and adds the rules from the rule list ``rules'' (if any).

Parameters:
sch a new search
rules a GList with items of type (rule_t *). ``rules'' may be NULL.

search_t* search_gui_find gnet_search_t  sh  ) 
 

Returns:
a pointer to gui_search_t from gui_searches which has sh as search_handle. If none is found, return NULL.

void search_gui_flush time_t  now  ) 
 

Periodic timer to flush the accumulated hits during the period and dispatch them to the GUI.

void search_gui_forget_current_search void   ) 
 

void search_gui_free_alt_locs record_t rc  ) 
 

Free the alternate locations held within a file record.

void search_gui_free_proxies results_set_t rs  ) 
 

Free the push proxies held within a result set.

void search_gui_free_r_set results_set_t rs  ) 
 

Free one results_set.

Those records may be shared between several searches. So while the refcount is positive, we just decrement it and return without doing anything.

void search_gui_free_r_sets search_t *  sch  ) 
 

void search_gui_free_record record_t rc  )  [static]
 

Free one file record.

Those records may be inserted into some `dups' tables, at which time they have their refcount increased. They may later be removed from those tables and they will have their refcount decreased.

To ensure some level of sanity, we ask our callers to explicitely check for a refcount to be zero before calling us.

search_t* search_gui_get_current_search void   ) 
 

gchar* search_gui_get_filename_extension const gchar *  filename_utf8  ) 
 

Extract the filename extensions - if any - from the given UTF-8 encoded filename and convert it to lowercase.

If the extension exceeds a certain length, it is assumed that it's no extension but just a non-specific dot inside a filename.

Returns:
NULL if there's no filename extension, otherwise a pointer to a static string holding the lowercased extension.

void search_gui_got_results GSList *  schl,
const gnet_results_set_t r_set
 

Called when the core has finished parsing the result set, and the results need to be dispatched to the searches listed in `schl'.

guint search_gui_hash_func gconstpointer  p  ) 
 

gint search_gui_hash_key_compare gconstpointer  a,
gconstpointer  b
 

void search_gui_history_add const gchar *  s  )  [static]
 

Adds a search string to the search history combo.

Makes sure we do not get more than 10 entries in the history. Also makes sure we don't get duplicate history entries. If a string is already in history and it's added again, it's moved to the beginning of the history list.

void search_gui_host_vec_free gnet_host_vec_t v  ) 
 

Free the cloned vector of host.

gboolean search_gui_is_expired const struct search sch  ) 
 

gboolean search_gui_new_browse_host const gchar *  hostname,
host_addr_t  addr,
guint16  port,
const gchar *  guid,
gboolean  push,
const gnet_host_vec_t proxies
 

Create a new "browse host" type search.

Parameters:
hostname the DNS name of the host, or NULL if none known
addr the IP address of the host to browse
port the port to contact
guid the GUID of the remote host
push whether a PUSH request is neeed to reach remote host
proxies vector holding known push-proxies
Returns:
whether the browse host request could be launched.

gboolean search_gui_new_search const gchar *  query,
flag_t  flags,
search_t **  search
 

Create a new search and start it.

Use default reissue timeout.

void search_gui_new_search_entered void   ) 
 

Create a new search from a query entered by the user.

void search_gui_option_menu_searches_select const search_t *  sch  ) 
 

void search_gui_option_menu_searches_update void   ) 
 

const gchar* search_gui_parse_query const gchar *  querystr,
GList **  rules,
const gchar **  error
 

Parses a query string as entered by the user.

Parameters:
querystr must point to the query string.
**rules 
*error will point to an descriptive error message on failure.
Returns:
NULL if the query was not valid. Otherwise, the decoded query is returned.

void search_gui_parse_text_query const gchar *  s,
struct query query
[static]
 

gnet_host_vec_t* search_gui_proxies_clone gnet_host_vec_t v  ) 
 

Clone the proxies list given by the core.

void search_gui_ref_record record_t rc  ) 
 

Add a reference to the record but don't dare to redeem it!

void search_gui_remove_r_set search_t *  sch,
results_set_t rs
 

Remove reference to results in our search.

Last one to remove it will trigger a free.

void search_gui_restart_search search_t *  sch  ) 
 

Restart a search from scratch, clearing all existing content.

gboolean search_gui_result_is_dup search_t *  sch,
record_t rc
 

Check to see whether we already have a record for this file.

If we do, make sure that the index is still accurate, otherwise inform the interested parties about the change.

Returns:
true if the record is a duplicate.

void search_gui_retrieve_searches void   ) 
 

Retrieve searches from disk.

void search_gui_set_sort_defaults void   ) 
 

Makes the sort column and order of the current search the default settings.

void search_gui_store_searches void   ) 
 

Persist searches to disk.

void search_gui_unref_record record_t rc  ) 
 

Remove one reference to a file record.

If the record has no more references, remove it from its parent result set and free the record physically.

gboolean search_gui_update_expiry const struct search sch  ) 
 

void search_gui_update_items const struct search sch  ) 
 

Update the label string showing search stats.

void search_matched search_t *  sch,
results_set_t rs
 

Called to dispatch results to the search window.

gchar* search_xml_indent const gchar *  s  ) 
 

Adds some indendation to XML-like text.

The input text is assumed to be "flat" and well-formed. If these assumptions fail, the output might look worse than the input.

Parameters:
s the string to format.
Returns:
a newly allocated string.


Variable Documentation

GSList* accumulated_rs = NULL [static]
 

search_t* current_search = NULL [static]
 

The search currently displayed.

guint32 flag
 

GtkLabel* label_items_found = NULL [static]
 

GtkLabel* label_search_expiry = NULL [static]
 

GList* list_search_history = NULL [static]
 

struct { ... } open_flags[] [static]
 

Human readable translation of servent trailer open flags.

Decompiled flags are listed in the order of the table.

zone_t* rc_zone [static]
 

Allocation of record.

zone_t* rs_zone [static]
 

Allocation of results_set.

const gchar search_file[] = "searches" [static]
 

"old" file to searches

const gchar* status
 


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