~ubuntu-branches/ubuntu/karmic/gtk-gnutella/karmic

« back to all changes in this revision

Viewing changes to src/search_gui_common.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Kleineidam
  • Date: 2004-05-22 15:26:55 UTC
  • Revision ID: james.westby@ubuntu.com-20040522152655-lyi6iaswmy4hq4wy
Tags: upstream-0.93.3.0
ImportĀ upstreamĀ versionĀ 0.93.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: search_gui_common.h,v 1.13 2004/01/04 04:03:49 wyldfire Exp $
 
3
 *
 
4
 * Copyright (c) 2003, Raphael Manfredi
 
5
 *
 
6
 *----------------------------------------------------------------------
 
7
 * This file is part of gtk-gnutella.
 
8
 *
 
9
 *  gtk-gnutella is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  gtk-gnutella is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with gtk-gnutella; if not, write to the Free Software
 
21
 *  Foundation, Inc.:
 
22
 *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 *----------------------------------------------------------------------
 
24
 */
 
25
 
 
26
#ifndef _search_gui_common_h_
 
27
#define _search_gui_common_h_
 
28
 
 
29
#include <time.h>
 
30
#include <glib.h>
 
31
 
 
32
#include "gnet.h"
 
33
 
 
34
#define TAB_UPDATE_TIME 5               /* Update search tabs after 5 seconds */
 
35
 
 
36
/*
 
37
 * A results_set structure factorizes the common information from a Query Hit
 
38
 * packet, and then has a list of individual records, one for each hit.
 
39
 *
 
40
 * A single structure is created for each Query Hit packet we receive, but
 
41
 * then it can be dispatched for displaying some of its records to the
 
42
 * various searches in presence.  Each time the structure is dispatched,
 
43
 * the `refcount' is incremented, so that we don't free it and its content
 
44
 * until it has been "forgotten" that many times.
 
45
 *
 
46
 * NB: we reuse the pure data structure gnet_host_vec_t from the core.  It
 
47
 *     is purely descriptive anyway.
 
48
 */
 
49
typedef struct results_set {
 
50
        gint refcount;                          /* Number of "struct search" this belongs to */
 
51
 
 
52
        gchar *guid;                            /* Servent's GUID (atom) */
 
53
        guint32 ip;
 
54
        guint16 port;
 
55
        guint16 status;                         /* Parsed status bits from trailer */
 
56
        guint16 speed;
 
57
        time_t  stamp;                          /* Reception time of the hit */
 
58
        guchar  vendor[4];                      /* Vendor code */
 
59
        gchar *version;                         /* Version information (atom) */
 
60
        gnet_host_vec_t *proxies;       /* Optional: known push proxies */
 
61
        gchar *hostname;                        /* Optional: server's hostname */
 
62
 
 
63
        guint32 num_recs;
 
64
        GSList *records;
 
65
    GSList *schl;
 
66
} results_set_t;
 
67
 
 
68
/*
 
69
 * A host.
 
70
 */
 
71
typedef struct host {
 
72
        guint32 ip;
 
73
        guint16 port;
 
74
} host_t;
 
75
 
 
76
/*
 
77
 * Host vector held in query hits.
 
78
 */
 
79
typedef struct host_vec {
 
80
        host_t *hvec;                           /* Vector of alternate locations */
 
81
        gint hvcnt;                                     /* Amount of hosts in vector */
 
82
} host_vec_t;
 
83
 
 
84
/*
 
85
 * An individual hit.  It referes to a file entry on the remote servent,
 
86
 * as identified by the parent results_set structure that contains this hit.
 
87
 *
 
88
 * When a record is kept in a search window for display, it is put into
 
89
 * a hash table and its `refcount' is incremented: since the parent structure
 
90
 * can be dispatched to various searches, each record can be inserted in so
 
91
 * many different hash tables (one per search).
 
92
 */
 
93
typedef struct record {
 
94
        results_set_t *results_set;     /* Parent, containing record */
 
95
        gint refcount;                          /* Number of hash tables it has been put to */
 
96
 
 
97
        gchar  *name;                           /* File name */
 
98
        guint32 size;                           /* Size of file, in bytes */
 
99
        guint32 index;                          /* Index for GET command */
 
100
        guint32 count;                          /* Number of children */
 
101
        gchar  *sha1;                           /* SHA1 URN (binary form, atom) */
 
102
        gchar  *tag;                            /* Optional tag data string (atom) */
 
103
        gchar  *info;                           /* Short version of tag (atom) */
 
104
        gnet_host_vec_t *alt_locs;      /* Optional alternate locations for record */
 
105
    flag_t  flags;              /* same flags as in gnet_record_t */
 
106
} record_t;
 
107
 
 
108
/*
 
109
 * Global Functions
 
110
 */
 
111
 
 
112
typedef struct search search_t;
 
113
 
 
114
void search_matched(search_t *sch, results_set_t *rs);
 
115
 
 
116
void search_gui_common_init(void);
 
117
void search_gui_common_shutdown(void);
 
118
 
 
119
search_t *search_gui_get_current_search(void);
 
120
void search_gui_set_current_search(search_t *sch);
 
121
void search_gui_forget_current_search();
 
122
void search_gui_current_search(search_t *sch);
 
123
 
 
124
void search_gui_free_alt_locs(record_t *rc);
 
125
void search_gui_free_proxies(results_set_t *rs);
 
126
void search_gui_free_record(record_t *rc);
 
127
void search_gui_clean_r_set(results_set_t *rs);
 
128
void search_gui_free_r_set(results_set_t *rs);
 
129
void search_gui_dispose_results(results_set_t *rs);
 
130
void search_gui_ref_record(record_t *rc);
 
131
void search_gui_unref_record(record_t *rc);
 
132
void search_gui_free_r_sets(search_t *sch);
 
133
guint search_gui_hash_func(const record_t *key);
 
134
gint search_gui_hash_key_compare(const record_t *a, const record_t *b);
 
135
void search_gui_remove_r_set(search_t *sch, results_set_t *rs);
 
136
gboolean search_gui_result_is_dup(search_t *sch, record_t *rc);
 
137
search_t *search_gui_find(gnet_search_t sh);
 
138
record_t *search_gui_create_record(results_set_t *rs, gnet_record_t *r) ;
 
139
void search_gui_check_alt_locs(results_set_t *rs, record_t *rc);
 
140
void search_gui_store_searches(void);
 
141
void search_gui_retrieve_searches(void);
 
142
void search_gui_got_results(GSList *schl, const gnet_results_set_t *r_set);
 
143
void search_gui_flush(time_t);
 
144
 
 
145
#endif /* _search_gui_common_h_ */