Main Page | Modules | Alphabetical List | Data Structures | Directories | 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/base16.h"
#include "lib/base32.h"
#include "lib/file.h"
#include "lib/glib-missing.h"
#include "lib/iso3166.h"
#include "lib/magnet.h"
#include "lib/slist.h"
#include "lib/tm.h"
#include "lib/url.h"
#include "lib/urn.h"
#include "lib/utf8.h"
#include "lib/walloc.h"
#include "lib/zalloc.h"
#include "lib/override.h"

Data Structures

struct  browse_request

Functions

GdkColor * gui_color_get (const enum gui_color id)
void gui_color_set (const enum gui_color id, GdkColor *color)
void gui_color_init (GtkWidget *widget)
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_results_set_free (results_set_t *rs)
void search_gui_remove_record (record_t *rc)
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.
guint search_gui_hash_func (gconstpointer p)
gint search_gui_hash_key_compare (gconstpointer a, gconstpointer b)
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)
const 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.
const gchar * search_gui_get_info (const record_t *rc, const gchar *vinfo)
record_tsearch_gui_create_record (const gnet_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 on_spinbutton_adjustment_value_changed (GtkAdjustment *unused_adj, gpointer data)
void search_gui_common_init (void)
 Initialize common structures.
void search_gui_common_shutdown (void)
 Destroy common structures.
void search_gui_check_alt_locs (record_t *rc)
 Check for alternate locations in the result set, and enqueue the downloads if there are any.
void search_gui_download (record_t *rc)
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.
const gchar * search_gui_get_route (const struct results_set *rs)
enum gui_color search_gui_color_for_record (const record_t *const rc)
void search_gui_set_record_info (results_set_t *rs)
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_info (void)
void search_gui_flush (time_t now, gboolean force)
 Periodic timer to flush the accumulated hits during the period and dispatch them to the GUI.
void search_gui_parse_text_query (const gchar *text, struct query *query)
 Parse the given query text and looks for negative patterns.
void clear_error_str (const gchar ***error_str)
gboolean search_gui_handle_magnet (const gchar *url, const gchar **error_str)
gboolean search_gui_handle_url (const gchar *url, const gchar **error_str)
gboolean search_gui_handle_urn (const gchar *urn, const gchar **error_str)
gboolean search_gui_handle_sha1 (const gchar *text, const gchar **error_str)
gboolean search_gui_handle_local (const gchar *query, const gchar **error_str)
void browse_request_free (struct browse_request **req_ptr)
void search_gui_browse_helper (const host_addr_t *addrs, size_t n, gpointer user_data)
 Called when we got a reply from the ADNS process.
void search_gui_browse (const gchar *host, guint16 port, guint32 flags)
gboolean search_gui_handle_browse (const gchar *s, const gchar **error_str)
void search_gui_query_free (struct query **query_ptr)
 Frees a "struct query" and nullifies the given pointer.
querysearch_gui_handle_query (const gchar *query_str, flag_t flags, const gchar **error_str)
 Handles 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 *text)
 Adds a search string to the search history combo.
gboolean search_gui_insert_query (const gchar *text)
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, const gnet_host_vec_t *proxies, guint32 flags)
 Create a new "browse host" type search.
gint search_gui_cmp_sha1s (const struct sha1 *a, const struct sha1 *b)
void search_gui_duplicate_search (search_t *search)
void search_gui_restart_search (search_t *search)
 Restart a search from scratch, clearing all existing content.
void search_gui_resume_search (search_t *search)
void search_gui_stop_search (search_t *search)
void on_popup_search_list_close_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_list_restart_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_list_resume_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_list_clear_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_list_stop_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_list_duplicate_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
gboolean on_search_list_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer unused_udata)
void search_gui_refresh_popup (void)
void on_popup_search_close_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_download_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_edit_filter_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_duplicate_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_restart_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_resume_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_stop_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_expand_all_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
void on_popup_search_collapse_all_activate (GtkMenuItem *unused_menuitem, gpointer unused_udata)
const gchar * search_gui_query (const search_t *search)
gboolean search_gui_is_browse (const search_t *search)
gboolean search_gui_is_enabled (const search_t *search)
gboolean search_gui_is_local (const search_t *search)
gboolean search_gui_is_passive (const search_t *search)
const gchar * search_gui_nice_size (const record_t *rc)
const gchar * search_gui_get_vendor (const struct results_set *rs)
gchar * gnet_host_vec_to_string (const gnet_host_vec_t *hvec)
void search_gui_set_details (const record_t *rc)

Variables

search_t * current_search
 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
slist_taccumulated_rs
GList * list_search_history
GtkLabel * label_items_found
GtkLabel * label_search_expiry
struct {
   guint32   flag
   const gchar *   status
open_flags []
 Human readable translation of servent trailer open flags.
struct {
   const gchar *const   spec
   GdkColor   color
colors []


Function Documentation

void browse_request_free struct browse_request **  req_ptr  )  [static]
 

void clear_error_str const gchar ***  error_str  )  [static]
 

gchar* gnet_host_vec_to_string const gnet_host_vec_t hvec  ) 
 

GdkColor* gui_color_get const enum gui_color  id  ) 
 

void gui_color_init GtkWidget *  widget  ) 
 

void gui_color_set const enum gui_color  id,
GdkColor *  color
 

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_popup_search_close_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_collapse_all_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_download_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_duplicate_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_edit_filter_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_expand_all_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_list_clear_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_list_close_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_list_duplicate_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_list_restart_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_list_resume_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_list_stop_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_restart_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_resume_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_popup_search_stop_activate GtkMenuItem *  unused_menuitem,
gpointer  unused_udata
 

void on_search_entry_activate GtkWidget *  unused_widget,
gpointer  unused_udata
 

gboolean on_search_list_button_press_event GtkWidget *  widget,
GdkEventButton *  event,
gpointer  unused_udata
 

void on_spinbutton_adjustment_value_changed GtkAdjustment *  unused_adj,
gpointer  data
[static]
 

void search_gui_browse const gchar *  host,
guint16  port,
guint32  flags
[static]
 

void search_gui_browse_helper const host_addr_t addrs,
size_t  n,
gpointer  user_data
[static]
 

Called when we got a reply from the ADNS process.

void search_gui_check_alt_locs record_t rc  )  [static]
 

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

Then free the alternate location from the record.

gint search_gui_cmp_sha1s const struct sha1 a,
const struct sha1 b
 

enum gui_color search_gui_color_for_record const record_t *const   rc  ) 
 

void search_gui_common_init void   ) 
 

Initialize common structures.

void search_gui_common_shutdown void   ) 
 

Destroy common structures.

record_t* search_gui_create_record const gnet_results_set_t rs,
gnet_record_t r
[static]
 

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
[static]
 

Create a new GUI result set from a Gnutella one.

void search_gui_current_search search_t *  sch  ) 
 

void search_gui_download record_t rc  ) 
 

void search_gui_duplicate_search search_t *  search  ) 
 

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,
gboolean  force
 

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

void search_gui_flush_info void   )  [static]
 

void search_gui_forget_current_search void   ) 
 

void search_gui_free_alt_locs record_t rc  )  [static]
 

Free the alternate locations held within a file record.

void search_gui_free_proxies results_set_t rs  )  [static]
 

Free the push proxies held within a result set.

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   ) 
 

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

const gchar* search_gui_get_info const record_t rc,
const gchar *  vinfo
[static]
 

< Show only first chars of tag

const gchar* search_gui_get_route const struct results_set rs  ) 
 

Returns:
a string showing the route information for the given result record. The return string uses a static buffer.
Note:
If the result is from a local search or browse host, NULL is returned.

const gchar* search_gui_get_vendor const struct results_set rs  ) 
 

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

gboolean search_gui_handle_browse const gchar *  s,
const gchar **  error_str
 

gboolean search_gui_handle_local const gchar *  query,
const gchar **  error_str
 

gboolean search_gui_handle_magnet const gchar *  url,
const gchar **  error_str
 

struct query* search_gui_handle_query const gchar *  query_str,
flag_t  flags,
const gchar **  error_str
 

Handles a query string as entered by the user.

This does also handle magnets and special search strings. These will be handled immediately which means that multiple searches and downloads might have been initiated when the functions returns.

Parameters:
query_str must point to the query string.
flags Diverse SEARCH_F_* flags.
error_str Will be set to NULL on success or point to an error message for the user on failure.
Returns:
NULL if no search should be created. This is not necessarily a failure condition, check error_str instead. If a search should be created, an initialized "struct query" is returned.

gboolean search_gui_handle_sha1 const gchar *  text,
const gchar **  error_str
 

gboolean search_gui_handle_url const gchar *  url,
const gchar **  error_str
 

gboolean search_gui_handle_urn const gchar *  urn,
const gchar **  error_str
 

guint search_gui_hash_func gconstpointer  p  ) 
 

gint search_gui_hash_key_compare gconstpointer  a,
gconstpointer  b
 

void search_gui_history_add const gchar *  text  )  [static]
 

Adds a search string to the search history combo.

Makes sure we do not get more than 50 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  )  [static]
 

Free the cloned vector of host.

gboolean search_gui_insert_query const gchar *  text  ) 
 

gboolean search_gui_is_browse const search_t *  search  ) 
 

gboolean search_gui_is_enabled const search_t *  search  ) 
 

gboolean search_gui_is_expired const struct search sch  ) 
 

gboolean search_gui_is_local const search_t *  search  ) 
 

gboolean search_gui_is_passive const search_t *  search  ) 
 

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

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
proxies vector holding known push-proxies
flags connection flags like SOCK_F_PUSH, SOCK_F_TLS etc.
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.

Note:
`*search' may be set to NULL even on success. You have to check this explicitely.

void search_gui_new_search_entered void   ) 
 

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

const gchar* search_gui_nice_size const record_t rc  ) 
 

void search_gui_option_menu_searches_select const search_t *  sch  ) 
 

void search_gui_option_menu_searches_update void   ) 
 

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

Parse the given query text and looks for negative patterns.

That means "blah -zadda" will be converted to "blah" and a word filter is added to discard results matching "zadda". A minus followed by a space or another minus is always used literally. A plus character has the opposite effect. In either case, the pattern will not be part of the emitted search term.

TODO: Add support for quoted terms like "yadda -'blah blah'".

gnet_host_vec_t* search_gui_proxies_clone gnet_host_vec_t v  ) 
 

Clone the proxies list given by the core.

const gchar* search_gui_query const search_t *  search  ) 
 

void search_gui_query_free struct query **  query_ptr  ) 
 

Frees a "struct query" and nullifies the given pointer.

void search_gui_ref_record record_t rc  ) 
 

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

void search_gui_refresh_popup void   ) 
 

void search_gui_remove_record record_t rc  )  [static]
 

void search_gui_restart_search search_t *  search  ) 
 

Restart a search from scratch, clearing all existing content.

gboolean search_gui_result_is_dup search_t *  sch,
record_t rc
[static]
 

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_results_set_free results_set_t rs  )  [static]
 

void search_gui_resume_search search_t *  search  ) 
 

void search_gui_retrieve_searches void   ) 
 

Retrieve searches from disk.

void search_gui_set_details const record_t rc  ) 
 

void search_gui_set_record_info results_set_t rs  )  [static]
 

void search_gui_set_sort_defaults void   ) 
 

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

void search_gui_stop_search search_t *  search  ) 
 

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
[static]
 

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

slist_t* accumulated_rs [static]
 

GdkColor color
 

struct { ... } colors[] [static]
 

search_t* current_search [static]
 

The search currently displayed.

guint32 flag
 

GtkLabel* label_items_found [static]
 

GtkLabel* label_search_expiry [static]
 

GList* list_search_history [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* const spec
 

const gchar* status
 


Generated on Sat Jun 30 17:53:30 2007 for gtk-gnutella by  doxygen 1.3.9.1