00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00037
00038 typedef guint32 gnet_search_t;
00039
00040
00041
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];
00053 } gnet_ipv4_host_t;
00054
00055 typedef struct {
00056 guint8 data[16 + 2];
00057 } gnet_ipv6_host_t;
00058
00059
00060
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
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
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
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
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
00226
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
00258 #endif
00259
00260