4 This file is part of avahi.
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.
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.
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
29 #include <avahi-common/llist.h>
30 #include <avahi-common/malloc.h>
35 typedef struct AvahiRecordListItem AvahiRecordListItem;
37 struct AvahiRecordListItem {
43 AVAHI_LLIST_FIELDS(AvahiRecordListItem, items);
46 struct AvahiRecordList {
47 AVAHI_LLIST_HEAD(AvahiRecordListItem, read);
48 AVAHI_LLIST_HEAD(AvahiRecordListItem, unread);
53 AvahiRecordList *avahi_record_list_new(void) {
56 if (!(l = avahi_new(AvahiRecordList, 1))) {
57 avahi_log_error("avahi_new() failed.");
61 AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->read);
62 AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->unread);
64 l->all_flush_cache = 1;
68 void avahi_record_list_free(AvahiRecordList *l) {
71 avahi_record_list_flush(l);
75 static void item_free(AvahiRecordList *l, AvahiRecordListItem *i) {
80 AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->read, i);
82 AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->unread, i);
84 avahi_record_unref(i->record);
88 void avahi_record_list_flush(AvahiRecordList *l) {
92 item_free(l, l->read);
94 item_free(l, l->unread);
96 l->all_flush_cache = 1;
99 AvahiRecord* avahi_record_list_next(AvahiRecordList *l, int *ret_flush_cache, int *ret_unicast_response, int *ret_auxiliary) {
101 AvahiRecordListItem *i;
103 if (!(i = l->unread))
108 r = avahi_record_ref(i->record);
109 if (ret_unicast_response)
110 *ret_unicast_response = i->unicast_response;
112 *ret_flush_cache = i->flush_cache;
114 *ret_auxiliary = i->auxiliary;
116 AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->unread, i);
117 AVAHI_LLIST_PREPEND(AvahiRecordListItem, items, l->read, i);
124 static AvahiRecordListItem *get(AvahiRecordList *l, AvahiRecord *r) {
125 AvahiRecordListItem *i;
130 for (i = l->read; i; i = i->items_next)
131 if (avahi_record_equal_no_ttl(i->record, r))
134 for (i = l->unread; i; i = i->items_next)
135 if (avahi_record_equal_no_ttl(i->record, r))
141 void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, int flush_cache, int unicast_response, int auxiliary) {
142 AvahiRecordListItem *i;
150 if (!(i = avahi_new(AvahiRecordListItem, 1))) {
151 avahi_log_error("avahi_new() failed.");
155 i->unicast_response = unicast_response;
156 i->flush_cache = flush_cache;
157 i->auxiliary = auxiliary;
158 i->record = avahi_record_ref(r);
161 l->all_flush_cache = l->all_flush_cache && flush_cache;
163 AVAHI_LLIST_PREPEND(AvahiRecordListItem, items, l->unread, i);
166 void avahi_record_list_drop(AvahiRecordList *l, AvahiRecord *r) {
167 AvahiRecordListItem *i;
172 if (!(i = get(l, r)))
178 int avahi_record_list_is_empty(AvahiRecordList *l) {
181 return !l->unread && !l->read;
184 int avahi_record_list_all_flush_cache(AvahiRecordList *l) {
187 /* Return TRUE if all entries in this list have flush_cache set */
189 return l->all_flush_cache;