8738
|
1 /**
|
|
2 * @file mdns_cache.c Multicast DNS resource record caching code.
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Gaim is the legal property of its developers, whose names are too numerous
|
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
8 * source distribution.
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * This program is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License
|
|
21 * along with this program; if not, write to the Free Software
|
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 *
|
|
24 */
|
|
25
|
|
26 #include "internal.h"
|
|
27
|
|
28 #include "mdns.h"
|
8834
|
29 #include "mdns_cache.h"
|
8738
|
30
|
8806
|
31 GSList *rrs = NULL;
|
|
32
|
8834
|
33 static ResourceRecord *
|
|
34 mdns_cache_find(gchar *name, unsigned short type)
|
|
35 {
|
|
36 ResourceRecord *rr;
|
|
37 GSList *cur;
|
|
38
|
|
39 g_return_val_if_fail(name != NULL, NULL);
|
|
40 g_return_val_if_fail((type != 0) || (type != RENDEZVOUS_RRTYPE_ALL), NULL);
|
|
41
|
|
42 for (cur = rrs; cur != NULL; cur = cur->next) {
|
|
43 rr = cur->data;
|
|
44 if ((type == rr->type) && (!strcmp(name, rr->name)))
|
|
45 return rr;
|
|
46 }
|
|
47
|
|
48 return NULL;
|
|
49 }
|
|
50
|
8806
|
51 void
|
|
52 mdns_cache_add(const ResourceRecord *rr)
|
|
53 {
|
|
54 ResourceRecord *new;
|
8738
|
55
|
8806
|
56 g_return_if_fail(rr != NULL);
|
8834
|
57 g_return_if_fail((rr->type != 0) && (rr->type != RENDEZVOUS_RRTYPE_ALL));
|
8806
|
58
|
8834
|
59 mdns_cache_remove(rr->name, rr->type);
|
|
60
|
8806
|
61 new = mdns_copy_rr(rr);
|
|
62 rrs = g_slist_prepend(rrs, new);
|
|
63 }
|
|
64
|
|
65 void
|
8834
|
66 mdns_cache_remove(gchar *name, unsigned short type)
|
8738
|
67 {
|
8834
|
68 ResourceRecord *rr;
|
|
69
|
|
70 g_return_if_fail(name != NULL);
|
|
71 g_return_if_fail((type != 0) && (type != RENDEZVOUS_RRTYPE_ALL));
|
8738
|
72
|
8834
|
73 rr = mdns_cache_find(name, type);
|
|
74 if (rr == NULL)
|
|
75 return;
|
8738
|
76
|
8834
|
77 rrs = g_slist_remove(rrs, rr);
|
8738
|
78 mdns_free_rr(rr);
|
|
79 }
|
|
80
|
8806
|
81 void
|
|
82 mdns_cache_remove_all()
|
8738
|
83 {
|
8806
|
84 mdns_free_rrs(rrs);
|
8840
|
85 rrs = NULL;
|
8738
|
86 }
|
|
87
|
8806
|
88 void
|
|
89 mdns_cache_respond(int fd, const Question *q)
|
8738
|
90 {
|
|
91 GSList *slist;
|
|
92 ResourceRecord *cur;
|
|
93
|
|
94 g_return_if_fail(q != NULL);
|
|
95
|
8834
|
96 for (slist = rrs; slist != NULL; slist = slist->next) {
|
8738
|
97 cur = slist->data;
|
8840
|
98 if (((q->type == RENDEZVOUS_RRTYPE_ALL) || (q->type == cur->type)) && (!strcmp(q->name, cur->name))) {
|
|
99 mdns_send_rr(fd, cur);
|
8834
|
100 }
|
8738
|
101 }
|
|
102 }
|