]> git.meshlink.io Git - catta/blob - avahi-core/rrlist.c
* add auxiliary records to packet
[catta] / avahi-core / rrlist.c
1 /* $Id$ */
2
3 /***
4   This file is part of avahi.
5  
6   avahi is free software; you can redistribute it and/or modify it
7   under the terms of the GNU Lesser General Public License as
8   published by the Free Software Foundation; either version 2.1 of the
9   License, or (at your option) any later version.
10  
11   avahi is distributed in the hope that it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14   Public License for more details.
15  
16   You should have received a copy of the GNU Lesser General Public
17   License along with avahi; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19   USA.
20 ***/
21
22 #include "rrlist.h"
23 #include "llist.h"
24
25 typedef struct AvahiRecordListItem AvahiRecordListItem;
26
27 struct AvahiRecordListItem {
28     AvahiRecord *record;
29     gboolean unicast_response;
30     gboolean flush_cache;
31     AVAHI_LLIST_FIELDS(AvahiRecordListItem, items);
32 };
33
34
35 struct AvahiRecordList {
36     AVAHI_LLIST_HEAD(AvahiRecordListItem, items);
37 };
38
39 AvahiRecordList *avahi_record_list_new(void) {
40     AvahiRecordList *l = g_new(AvahiRecordList, 1);
41     AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->items);
42     return l;
43 }
44
45 void avahi_record_list_free(AvahiRecordList *l) {
46     g_assert(l);
47
48     avahi_record_list_flush(l);
49     g_free(l);
50 }
51
52 static void item_free(AvahiRecordList *l, AvahiRecordListItem *i) {
53     g_assert(i);
54
55     AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->items, i);
56     avahi_record_unref(i->record);
57     g_free(i);
58 }
59
60 void avahi_record_list_flush(AvahiRecordList *l) {
61     g_assert(l);
62     
63     while (l->items)
64         item_free(l, l->items);
65 }
66
67 AvahiRecord* avahi_record_list_pop(AvahiRecordList *l, gboolean *flush_cache, gboolean *unicast_response) {
68     AvahiRecord *r;
69
70     if (!l->items)
71         return NULL;
72     
73     r = avahi_record_ref(l->items->record);
74     if (unicast_response) *unicast_response = l->items->unicast_response;
75     if (flush_cache) *flush_cache = l->items->flush_cache;
76
77     item_free(l, l->items);
78     
79     return r;
80 }
81
82 void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, gboolean flush_cache, gboolean unicast_response) {
83     AvahiRecordListItem *i;
84         
85     g_assert(l);
86     g_assert(r);
87     
88     for (i = l->items; i; i = i->items_next)
89         if (avahi_record_equal_no_ttl(i->record, r))
90             return;
91
92     i = g_new(AvahiRecordListItem, 1);
93     i->unicast_response = unicast_response;
94     i->flush_cache = flush_cache;
95     i->record = avahi_record_ref(r);
96     AVAHI_LLIST_PREPEND(AvahiRecordListItem, items, l->items, i);
97 }
98
99 void avahi_record_list_drop(AvahiRecordList *l, AvahiRecord *r) {
100     AvahiRecordListItem *i;
101
102     g_assert(l);
103     g_assert(r);
104
105     for (i = l->items; i; i = i->items_next)
106         if (avahi_record_equal_no_ttl(i->record, r)) {
107             item_free(l, i);
108             break;
109         }
110 }
111
112
113 gboolean avahi_record_list_empty(AvahiRecordList *l) {
114     g_assert(l);
115     
116     return !l->items;
117 }