2 This file is part of avahi.
4 avahi is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 avahi is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12 Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with avahi; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <avahi-common/llist.h>
28 #include <avahi-common/malloc.h>
33 typedef struct AvahiRecordListItem AvahiRecordListItem;
35 struct AvahiRecordListItem {
41 AVAHI_LLIST_FIELDS(AvahiRecordListItem, items);
44 struct AvahiRecordList {
45 AVAHI_LLIST_HEAD(AvahiRecordListItem, read);
46 AVAHI_LLIST_HEAD(AvahiRecordListItem, unread);
51 AvahiRecordList *avahi_record_list_new(void) {
54 if (!(l = avahi_new(AvahiRecordList, 1))) {
55 avahi_log_error("avahi_new() failed.");
59 AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->read);
60 AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->unread);
62 l->all_flush_cache = 1;
66 void avahi_record_list_free(AvahiRecordList *l) {
69 avahi_record_list_flush(l);
73 static void item_free(AvahiRecordList *l, AvahiRecordListItem *i) {
78 AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->read, i);
80 AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->unread, i);
82 avahi_record_unref(i->record);
86 void avahi_record_list_flush(AvahiRecordList *l) {
90 item_free(l, l->read);
92 item_free(l, l->unread);
94 l->all_flush_cache = 1;
97 AvahiRecord* avahi_record_list_next(AvahiRecordList *l, int *ret_flush_cache, int *ret_unicast_response, int *ret_auxiliary) {
99 AvahiRecordListItem *i;
101 if (!(i = l->unread))
106 r = avahi_record_ref(i->record);
107 if (ret_unicast_response)
108 *ret_unicast_response = i->unicast_response;
110 *ret_flush_cache = i->flush_cache;
112 *ret_auxiliary = i->auxiliary;
114 AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->unread, i);
115 AVAHI_LLIST_PREPEND(AvahiRecordListItem, items, l->read, i);
122 static AvahiRecordListItem *get(AvahiRecordList *l, AvahiRecord *r) {
123 AvahiRecordListItem *i;
128 for (i = l->read; i; i = i->items_next)
129 if (avahi_record_equal_no_ttl(i->record, r))
132 for (i = l->unread; i; i = i->items_next)
133 if (avahi_record_equal_no_ttl(i->record, r))
139 void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, int flush_cache, int unicast_response, int auxiliary) {
140 AvahiRecordListItem *i;
148 if (!(i = avahi_new(AvahiRecordListItem, 1))) {
149 avahi_log_error("avahi_new() failed.");
153 i->unicast_response = unicast_response;
154 i->flush_cache = flush_cache;
155 i->auxiliary = auxiliary;
156 i->record = avahi_record_ref(r);
159 l->all_flush_cache = l->all_flush_cache && flush_cache;
161 AVAHI_LLIST_PREPEND(AvahiRecordListItem, items, l->unread, i);
164 void avahi_record_list_drop(AvahiRecordList *l, AvahiRecord *r) {
165 AvahiRecordListItem *i;
170 if (!(i = get(l, r)))
176 int avahi_record_list_is_empty(AvahiRecordList *l) {
179 return !l->unread && !l->read;
182 int avahi_record_list_all_flush_cache(AvahiRecordList *l) {
185 /* Return TRUE if all entries in this list have flush_cache set */
187 return l->all_flush_cache;