|
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 #include "debug.h"
|
|
|
28
|
|
|
29 #include "mdns.h"
|
|
8834
|
30 #include "mdns_cache.h"
|
|
8738
|
31
|
|
8806
|
32 GSList *rrs = NULL;
|
|
|
33
|
|
8834
|
34 static ResourceRecord *
|
|
|
35 mdns_cache_find(gchar *name, unsigned short type)
|
|
|
36 {
|
|
|
37 ResourceRecord *rr;
|
|
|
38 GSList *cur;
|
|
|
39
|
|
|
40 g_return_val_if_fail(name != NULL, NULL);
|
|
|
41 g_return_val_if_fail((type != 0) || (type != RENDEZVOUS_RRTYPE_ALL), NULL);
|
|
|
42
|
|
|
43 for (cur = rrs; cur != NULL; cur = cur->next) {
|
|
|
44 rr = cur->data;
|
|
|
45 if ((type == rr->type) && (!strcmp(name, rr->name)))
|
|
|
46 return rr;
|
|
|
47 }
|
|
|
48
|
|
|
49 return NULL;
|
|
|
50 }
|
|
|
51
|
|
8806
|
52 void
|
|
|
53 mdns_cache_add(const ResourceRecord *rr)
|
|
|
54 {
|
|
|
55 ResourceRecord *new;
|
|
8738
|
56
|
|
8806
|
57 g_return_if_fail(rr != NULL);
|
|
8834
|
58 g_return_if_fail((rr->type != 0) && (rr->type != RENDEZVOUS_RRTYPE_ALL));
|
|
8806
|
59
|
|
8834
|
60 mdns_cache_remove(rr->name, rr->type);
|
|
|
61
|
|
|
62 printf("caching %d\n", rr->type);
|
|
8806
|
63 new = mdns_copy_rr(rr);
|
|
|
64 rrs = g_slist_prepend(rrs, new);
|
|
|
65 }
|
|
|
66
|
|
|
67 void
|
|
8834
|
68 mdns_cache_remove(gchar *name, unsigned short type)
|
|
8738
|
69 {
|
|
8834
|
70 ResourceRecord *rr;
|
|
|
71
|
|
|
72 g_return_if_fail(name != NULL);
|
|
|
73 g_return_if_fail((type != 0) && (type != RENDEZVOUS_RRTYPE_ALL));
|
|
8738
|
74
|
|
8834
|
75 rr = mdns_cache_find(name, type);
|
|
|
76 if (rr == NULL)
|
|
|
77 return;
|
|
8738
|
78
|
|
8834
|
79 rrs = g_slist_remove(rrs, rr);
|
|
8738
|
80 mdns_free_rr(rr);
|
|
|
81 }
|
|
|
82
|
|
8806
|
83 void
|
|
|
84 mdns_cache_remove_all()
|
|
8738
|
85 {
|
|
8806
|
86 mdns_free_rrs(rrs);
|
|
8840
|
87 rrs = NULL;
|
|
8738
|
88 }
|
|
|
89
|
|
8806
|
90 void
|
|
|
91 mdns_cache_respond(int fd, const Question *q)
|
|
8738
|
92 {
|
|
|
93 GSList *slist;
|
|
|
94 ResourceRecord *cur;
|
|
|
95
|
|
|
96 g_return_if_fail(q != NULL);
|
|
8834
|
97 printf("query for q->type=%d, q->name=%s\n", q->type, q->name);
|
|
8738
|
98
|
|
8834
|
99 for (slist = rrs; slist != NULL; slist = slist->next) {
|
|
8738
|
100 cur = slist->data;
|
|
8840
|
101 if (((q->type == RENDEZVOUS_RRTYPE_ALL) || (q->type == cur->type)) && (!strcmp(q->name, cur->name))) {
|
|
8834
|
102 printf("responding to cur->type=%d, cur->name=%s\n", cur->type, cur->name);
|
|
8840
|
103 mdns_send_rr(fd, cur);
|
|
8834
|
104 }
|
|
8738
|
105 }
|
|
|
106 }
|