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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#ifndef foowideareahfoo
#define foowideareahfoo
/* $Id$ */
/***
This file is part of avahi.
avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
avahi 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 Lesser General
Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#include "lookup.h"
#include "browse.h"
typedef struct AvahiWideAreaLookupEngine AvahiWideAreaLookupEngine;
typedef struct AvahiWideAreaLookup AvahiWideAreaLookup;
typedef void (*AvahiWideAreaLookupCallback)(
AvahiWideAreaLookupEngine *e,
AvahiBrowserEvent event,
AvahiLookupResultFlags flags,
AvahiRecord *r,
void *userdata);
typedef struct AvahiWideAreaCacheEntry AvahiWideAreaCacheEntry;
struct AvahiWideAreaCacheEntry {
AvahiWideAreaLookupEngine *engine;
AvahiRecord *record;
struct timeval timestamp;
struct timeval expiry;
AvahiTimeEvent *time_event;
AVAHI_LLIST_FIELDS(AvahiWideAreaCacheEntry, by_key);
AVAHI_LLIST_FIELDS(AvahiWideAreaCacheEntry, cache);
};
struct AvahiWideAreaLookup {
AvahiWideAreaLookupEngine *engine;
int dead;
uint32_t id; /* effectively just an uint16_t, but we need it as an index for a hash table */
AvahiTimeEvent *time_event;
AvahiKey *key, *cname_key;
int n_send;
AvahiDnsPacket *packet;
AvahiWideAreaLookupCallback callback;
void *userdata;
AvahiAddress dns_server_used;
AVAHI_LLIST_FIELDS(AvahiWideAreaLookup, lookups);
AVAHI_LLIST_FIELDS(AvahiWideAreaLookup, by_key);
};
struct AvahiWideAreaLookupEngine {
AvahiServer *server;
int fd_ipv4, fd_ipv6;
AvahiWatch *watch_ipv4, *watch_ipv6;
uint16_t next_id;
/* Cache */
AVAHI_LLIST_HEAD(AvahiWideAreaCacheEntry, cache);
AvahiHashmap *cache_by_key;
unsigned cache_n_entries;
/* Lookups */
AVAHI_LLIST_HEAD(AvahiWideAreaLookup, lookups);
AvahiHashmap *lookups_by_id;
AvahiHashmap *lookups_by_key;
int cleanup_dead;
AvahiAddress dns_servers[AVAHI_WIDE_AREA_SERVERS_MAX];
unsigned n_dns_servers;
unsigned current_dns_server;
};
AvahiWideAreaLookupEngine *avahi_wide_area_engine_new(AvahiServer *s);
void avahi_wide_area_engine_free(AvahiWideAreaLookupEngine *e);
unsigned avahi_wide_area_scan_cache(AvahiWideAreaLookupEngine *e, AvahiKey *key, AvahiWideAreaLookupCallback callback, void *userdata);
void avahi_wide_area_cache_dump(AvahiWideAreaLookupEngine *e, AvahiDumpCallback callback, void* userdata);
void avahi_wide_area_set_servers(AvahiWideAreaLookupEngine *e, const AvahiAddress *a, unsigned n);
void avahi_wide_area_clear_cache(AvahiWideAreaLookupEngine *e);
void avahi_wide_area_cleanup(AvahiWideAreaLookupEngine *e);
int avahi_wide_area_has_servers(AvahiWideAreaLookupEngine *e);
AvahiRecord* tsig_sign_packet(const unsigned char* keyname, const unsigned char* key, unsigned keylength, AvahiDnsPacket *p, unsigned algorithm, uint16_t id);
void wide_area_publish(AvahiRecord *r, const char *zone, uint16_t id, int fd);
AvahiWideAreaLookup *avahi_wide_area_lookup_new(AvahiWideAreaLookupEngine *e, AvahiKey *key, AvahiWideAreaLookupCallback callback, void *userdata);
void avahi_wide_area_lookup_free(AvahiWideAreaLookup *q);
#endif
|