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

if/core/search.h

Go to the documentation of this file.
00001 /*
00002  * $Id: search.h 13870 2007-06-18 03:27:25Z cbiere $
00003  *
00004  * Copyright (c) 2001-2003, Raphael Manfredi, Richard Eckart
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *----------------------------------------------------------------------
00024  */
00025 
00026 #ifndef _if_core_search_h_
00027 #define _if_core_search_h_
00028 
00029 #include "common.h"
00030 
00031 #include "lib/misc.h"
00032 #include "lib/vendors.h"
00033 #include "if/core/nodes.h"
00034 
00035 /***
00036  *** Searches
00037  ***/
00038 typedef guint32 gnet_search_t;
00039 
00040 /*
00041  * Flags for search_new()
00042  */
00043 enum {
00044     SEARCH_F_PASSIVE    = 1 << 0,   
00045     SEARCH_F_ENABLED    = 1 << 1,   
00046     SEARCH_F_BROWSE     = 1 << 2,   
00047     SEARCH_F_LITERAL    = 1 << 3,   
00048     SEARCH_F_LOCAL      = 1 << 4    
00049 };
00050 
00051 typedef struct {
00052     guint8 data[4 + 2];     /* IPv4 address (BE) + Port (LE) */
00053 } gnet_ipv4_host_t;
00054 
00055 typedef struct {
00056     guint8 data[16 + 2];    /* IPv6 address + Port (LE) */
00057 } gnet_ipv6_host_t;
00058 
00059 /*
00060  * Host vectors held in query hits.
00061  */
00062 typedef struct gnet_host_vec {
00063     gnet_ipv4_host_t *hvec_v4;  
00064     gnet_ipv6_host_t *hvec_v6;  
00065     guint8 n_ipv4;              
00066     guint8 n_ipv6;              
00067 } gnet_host_vec_t;
00068 
00069 static inline gint
00070 gnet_host_vec_count(const gnet_host_vec_t *hvec)
00071 {
00072     return (gint) hvec->n_ipv4 + hvec->n_ipv6; 
00073 }
00074 
00075 static inline gnet_host_t
00076 gnet_host_vec_get(const gnet_host_vec_t *hvec, guint i)
00077 {
00078     gnet_host_t host;
00079     host_addr_t addr;
00080     guint16 port;
00081 
00082     g_assert(i < (guint) gnet_host_vec_count(hvec));
00083 
00084     if (i < hvec->n_ipv4) {
00085         addr = host_addr_peek_ipv4(hvec->hvec_v4[i].data);
00086         port = peek_le16(&hvec->hvec_v4[i].data[4]);
00087     } else {
00088         i -= hvec->n_ipv4;
00089         addr = host_addr_peek_ipv6(hvec->hvec_v6[i].data);
00090         port = peek_le16(&hvec->hvec_v6[i].data[16]);
00091     }
00092 
00093     gnet_host_set(&host, addr, port);
00094     return host;
00095 }
00096 
00097 gnet_host_vec_t *gnet_host_vec_alloc(void);
00098 void gnet_host_vec_free(gnet_host_vec_t **vec_ptr);
00099 gnet_host_vec_t *gnet_host_vec_copy(const gnet_host_vec_t *vec);
00100 void gnet_host_vec_add(gnet_host_vec_t *vec, host_addr_t addr, guint16 port);
00101 gnet_host_vec_t *gnet_host_vec_create(gnet_host_t *hvec, gint hcnt);
00102 
00103 /*
00104  * Result sets `status' flags.
00105  */
00106 enum {
00107      ST_GOOD_TOKEN          = (1 << 22), 
00108      ST_BROWSE              = (1 << 21), 
00109      ST_LOCAL               = (1 << 20), 
00110      ST_FW2FW               = (1 << 19), 
00111      ST_HOSTILE             = (1 << 18), 
00112      ST_UNREQUESTED         = (1 << 17), 
00113      ST_EVIL                = (1 << 16), 
00114      ST_ALT_SPAM            = (1 << 15), 
00115      ST_DUP_SPAM            = (1 << 14), 
00116      ST_NAME_SPAM           = (1 << 13), 
00117      ST_URL_SPAM            = (1 << 12), 
00118      ST_URN_SPAM            = (1 << 11), 
00119      ST_TLS                 = (1 << 10), 
00120      ST_BH                  = (1 << 9),  
00121      ST_KNOWN_VENDOR        = (1 << 8),  
00122      ST_PARSED_TRAILER      = (1 << 7),  
00123      ST_UDP                 = (1 << 6),  
00124      ST_BOGUS               = (1 << 5),  
00125      ST_PUSH_PROXY          = (1 << 4),  
00126      ST_GGEP                = (1 << 3),  
00127      ST_UPLOADED            = (1 << 2),  
00128      ST_BUSY                = (1 << 1),  
00129      ST_FIREWALL            = (1 << 0),  
00131      ST_SPAM    = (ST_ALT_SPAM|ST_DUP_SPAM|ST_NAME_SPAM|ST_URL_SPAM|ST_URN_SPAM)
00132 };
00133 
00134 /*
00135  * Processing of ignored files.
00136  */
00137 enum {
00138     SEARCH_IGN_DISPLAY_AS_IS,   
00139     SEARCH_IGN_DISPLAY_MARKED,  
00140     SEARCH_IGN_NO_DISPLAY,      
00141 };
00142 
00151 typedef struct gnet_results_set {
00152     host_addr_t addr;
00153     host_addr_t last_hop;       
00155     const gchar *guid;          
00156     const gchar *hostname;      
00157     const gchar *version;       
00158     const gchar *query;         
00159     gnet_host_vec_t *proxies;   
00160     GSList *records;
00161 
00162     time_t  stamp;              
00163     vendor_code_t vcode;        
00164     guint32 speed;
00165     guint32 num_recs;
00166     guint32 status;             
00168     flag_t  flags;
00169     guint16 port;
00170     guint16 country;            
00171     guint8 hops;
00172     guint8 ttl;
00173 } gnet_results_set_t;
00174 
00175 /*
00176  * Result record flags
00177  */
00178 enum {
00179     SR_DOWNLOADED   = (1 << 0),
00180     SR_IGNORED      = (1 << 1),
00181     SR_DONT_SHOW    = (1 << 2),
00182     SR_SPAM         = (1 << 3),
00183     SR_SHARED       = (1 << 4),
00184     SR_OWNED        = (1 << 5),
00185     SR_PARTIAL      = (1 << 6)
00186 };
00187 
00192 typedef struct gnet_record {
00193     const gchar  *name;         
00194     const struct sha1 *sha1;    
00195     const gchar  *tag;          
00196     const gchar  *xml;          
00197     const gchar  *path;         
00198     gnet_host_vec_t *alt_locs;  
00199     filesize_t size;            
00200     time_t  create_time;        
00201     guint32 file_index;         
00202     flag_t  flags;
00203 } gnet_record_t;
00204 
00205 
00209 typedef void (*search_got_results_listener_t)
00210     (GSList *, const gnet_results_set_t *);
00211 
00212 /*
00213  * Search public interface, visible only from the bridge.
00214  */
00215 
00216 #ifdef CORE_SOURCES
00217 
00218 gnet_search_t search_new(const gchar *, time_t create_time, guint lifetime,
00219         guint32 timeout, flag_t flags);
00220 void search_close(gnet_search_t sh);
00221 
00222 void search_start(gnet_search_t sh);
00223 void search_stop(gnet_search_t sh);
00224 
00225 /*  search_is_stopped doesn't exist yet!
00226 gboolean search_is_stopped(gnet_search_t sh);
00227 */
00228 
00229 void search_reissue(gnet_search_t sh);
00230 void search_add_kept(gnet_search_t sh, guint32 kept);
00231 
00232 const gchar *search_query(gnet_search_t sh);
00233 
00234 gboolean search_is_active(gnet_search_t sh);
00235 gboolean search_is_browse(gnet_search_t sh);
00236 gboolean search_is_expired(gnet_search_t sh);
00237 gboolean search_is_frozen(gnet_search_t sh);
00238 gboolean search_is_local(gnet_search_t sh);
00239 gboolean search_is_passive(gnet_search_t sh);
00240 
00241 void search_set_reissue_timeout(gnet_search_t sh, guint32 timeout);
00242 guint32 search_get_reissue_timeout(gnet_search_t sh);
00243 guint search_get_lifetime(gnet_search_t sh);
00244 time_t search_get_create_time(gnet_search_t sh);
00245 void search_set_create_time(gnet_search_t sh, time_t t);
00246 
00247 void search_free_alt_locs(gnet_record_t *rc);
00248 
00249 void search_update_items(gnet_search_t sh, guint32 items);
00250 
00251 gboolean search_browse(gnet_search_t sh,
00252     const gchar *hostname, host_addr_t addr, guint16 port,
00253     const gchar *guid, const gnet_host_vec_t *proxies, guint32 flags);
00254 gboolean search_locally(gnet_search_t sh, const gchar *query);
00255 guint search_handle_magnet(const gchar *url);
00256 
00257 #endif /* CORE_SOURCES */
00258 #endif /* _if_core_search_h_ */
00259 
00260 /* vi: set ts=4 sw=4 cindent: */

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