File: host.h

package info (click to toggle)
xqf 1.0.6-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 4,048 kB
  • sloc: ansic: 31,166; sh: 1,451; xml: 1,039; makefile: 257; perl: 131
file content (72 lines) | stat: -rw-r--r-- 2,057 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* XQF - Quake server browser and launcher
 * Copyright (C) 1998-2000 Roman Pozlevich <roma@botik.ru>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

#ifndef __HOST_H__
#define __HOST_H__

#include <gtk/gtk.h>


#define HOST_CACHE_MAX_AGE  (7 * 24 * 60 * 60)  /* one week */
#define HOST_CACHE_MAX_SIZE 5000


extern int hosts_total (void);
extern GSList *all_hosts (void);
extern struct host *host_add (const char *address);
extern struct host *host_add_in (struct in_addr addr);
extern void host_unref (struct host *h);

extern GSList *merge_host_to_resolve  (GSList *hosts, struct host *h);
extern GSList *merge_hosts_to_resolve (GSList *hosts, GSList *servers);

extern void host_cache_save (void);
extern void host_cache_load (void);
extern void host_cache_clear (void);

static inline void host_ref (struct host *h) {
	if (h) {
		h->ref_count++;
	}
}

static inline GSList *host_list_add (GSList *list, struct host *h) {
	if (g_slist_find (list, h) == NULL) {
		list = g_slist_prepend (list, h);
		host_ref (h);
	}
	return list;
}

static inline GSList *host_list_remove (GSList *list, struct host *h) {
	if (g_slist_find (list, h)) {
		list = g_slist_remove (list, h);
		host_unref (h);
	}
	return list;
}

static inline void host_list_free (GSList *list) {
	if (list) {
		g_slist_foreach (list, (GFunc) host_unref, NULL);
		g_slist_free (list);
	}
}


#endif /* __HOST_H__ */