|
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 g_return_if_fail(rr != NULL);
|
|
8834
|
55 g_return_if_fail((rr->type != 0) && (rr->type != RENDEZVOUS_RRTYPE_ALL));
|
|
8806
|
56
|
|
8834
|
57 mdns_cache_remove(rr->name, rr->type);
|
|
|
58
|
|
8806
|
59 new = mdns_copy_rr(rr);
|
|
|
60 rrs = g_slist_prepend(rrs, new);
|
|
|
61 }
|
|
|
62
|
|
|
63 void
|
|
8834
|
64 mdns_cache_remove(gchar *name, unsigned short type)
|
|
8738
|
65 {
|
|
8834
|
66 ResourceRecord *rr;
|
|
|
67
|
|
|
68 g_return_if_fail(name != NULL);
|
|
|
69 g_return_if_fail((type != 0) && (type != RENDEZVOUS_RRTYPE_ALL));
|
|
8738
|
70
|
|
8834
|
71 rr = mdns_cache_find(name, type);
|
|
|
72 if (rr == NULL)
|
|
|
73 return;
|
|
8738
|
74
|
|
8834
|
75 rrs = g_slist_remove(rrs, rr);
|
|
8738
|
76 mdns_free_rr(rr);
|
|
|
77 }
|
|
|
78
|
|
9944
|
79 void mdns_cache_remove_all()
|
|
8738
|
80 {
|
|
9944
|
81 while (resourcerecords != NULL)
|
|
|
82 mdns_cache_remove(resourcerecords->data);
|
|
8840
|
83 rrs = NULL;
|
|
8738
|
84 }
|
|
|
85
|
|
9944
|
86 void mdns_cache_respond(int fd, Question *q)
|
|
8738
|
87 {
|
|
|
88 GSList *slist;
|
|
|
89 ResourceRecord *cur;
|
|
|
90
|
|
|
91 g_return_if_fail(q != NULL);
|
|
|
92
|
|
8834
|
93 for (slist = rrs; slist != NULL; slist = slist->next) {
|
|
8738
|
94 cur = slist->data;
|
|
8840
|
95 if (((q->type == RENDEZVOUS_RRTYPE_ALL) || (q->type == cur->type)) && (!strcmp(q->name, cur->name))) {
|
|
|
96 mdns_send_rr(fd, cur);
|
|
8834
|
97 }
|
|
8738
|
98 }
|
|
|
99 }
|