annotate src/protocols/rendezvous/mdns_cache.c @ 9802:acf175d9f79b

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