]> git.meshlink.io Git - catta/blobdiff - avahi-core/rrlist.c
actually enforce that we never print more than 20 bytes from arbitrary records in...
[catta] / avahi-core / rrlist.c
index ce4640c9ccd5b5736cb55f6c3217d7d030df5abd..915ecbb87bccb3297e5d5187c6d4d4978ebfdf33 100644 (file)
   USA.
 ***/
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <assert.h>
+
 #include <avahi-common/llist.h>
+#include <avahi-common/malloc.h>
+
 #include "rrlist.h"
+#include "log.h"
 
 typedef struct AvahiRecordListItem AvahiRecordListItem;
 
 struct AvahiRecordListItem {
-    gboolean read;
+    int read;
     AvahiRecord *record;
-    gboolean unicast_response;
-    gboolean flush_cache;
-    gboolean auxiliary;
+    int unicast_response;
+    int flush_cache;
+    int auxiliary;
     AVAHI_LLIST_FIELDS(AvahiRecordListItem, items);
 };
 
-
 struct AvahiRecordList {
     AVAHI_LLIST_HEAD(AvahiRecordListItem, read);
     AVAHI_LLIST_HEAD(AvahiRecordListItem, unread);
+
+    int all_flush_cache;
 };
 
 AvahiRecordList *avahi_record_list_new(void) {
-    AvahiRecordList *l = g_new(AvahiRecordList, 1);
+    AvahiRecordList *l;
+
+    if (!(l = avahi_new(AvahiRecordList, 1))) {
+        avahi_log_error("avahi_new() failed.");
+        return NULL;
+    }
+    
     AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->read);
     AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->unread);
+
+    l->all_flush_cache = 1;
     return l;
 }
 
 void avahi_record_list_free(AvahiRecordList *l) {
-    g_assert(l);
+    assert(l);
 
     avahi_record_list_flush(l);
-    g_free(l);
+    avahi_free(l);
 }
 
 static void item_free(AvahiRecordList *l, AvahiRecordListItem *i) {
-    g_assert(l);
-    g_assert(i);
+    assert(l);
+    assert(i);
 
     if (i->read) 
         AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->read, i);
@@ -63,39 +82,41 @@ static void item_free(AvahiRecordList *l, AvahiRecordListItem *i) {
         AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->unread, i);
     
     avahi_record_unref(i->record);
-    g_free(i);
+    avahi_free(i);
 }
 
 void avahi_record_list_flush(AvahiRecordList *l) {
-    g_assert(l);
+    assert(l);
     
     while (l->read)
         item_free(l, l->read);
     while (l->unread)
         item_free(l, l->unread);
+
+    l->all_flush_cache = 1;
 }
 
-AvahiRecord* avahi_record_list_next(AvahiRecordList *l, gboolean *flush_cache, gboolean *unicast_response, gboolean *auxiliary) {
+AvahiRecord* avahi_record_list_next(AvahiRecordList *l, int *ret_flush_cache, int *ret_unicast_response, int *ret_auxiliary) {
     AvahiRecord *r;
     AvahiRecordListItem *i;
 
     if (!(i = l->unread))
         return NULL;
 
-    g_assert(!i->read);
+    assert(!i->read);
     
     r = avahi_record_ref(i->record);
-    if (unicast_response)
-        *unicast_response = i->unicast_response;
-    if (flush_cache)
-        *flush_cache = i->flush_cache;
-    if (auxiliary)
-        *auxiliary = i->auxiliary;
+    if (ret_unicast_response)
+        *ret_unicast_response = i->unicast_response;
+    if (ret_flush_cache)
+        *ret_flush_cache = i->flush_cache;
+    if (ret_auxiliary)
+        *ret_auxiliary = i->auxiliary;
 
     AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->unread, i);
     AVAHI_LLIST_PREPEND(AvahiRecordListItem, items, l->read, i);
 
-    i->read = TRUE;
+    i->read = 1;
     
     return r;
 }
@@ -103,8 +124,8 @@ AvahiRecord* avahi_record_list_next(AvahiRecordList *l, gboolean *flush_cache, g
 static AvahiRecordListItem *get(AvahiRecordList *l, AvahiRecord *r) {
     AvahiRecordListItem *i;
 
-    g_assert(l);
-    g_assert(r);
+    assert(l);
+    assert(r);
     
     for (i = l->read; i; i = i->items_next)
         if (avahi_record_equal_no_ttl(i->record, r))
@@ -117,30 +138,36 @@ static AvahiRecordListItem *get(AvahiRecordList *l, AvahiRecord *r) {
     return NULL;
 }
 
-void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, gboolean flush_cache, gboolean unicast_response, gboolean auxiliary) {
+void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, int flush_cache, int unicast_response, int auxiliary) {
     AvahiRecordListItem *i;
         
-    g_assert(l);
-    g_assert(r);
+    assert(l);
+    assert(r);
 
     if (get(l, r))
         return;
 
-    i = g_new(AvahiRecordListItem, 1);
+    if (!(i = avahi_new(AvahiRecordListItem, 1))) {
+        avahi_log_error("avahi_new() failed.");
+        return;
+    }
+    
     i->unicast_response = unicast_response;
     i->flush_cache = flush_cache;
     i->auxiliary = auxiliary;
     i->record = avahi_record_ref(r);
-    i->read = FALSE;
+    i->read = 0;
 
+    l->all_flush_cache = l->all_flush_cache && flush_cache;
+    
     AVAHI_LLIST_PREPEND(AvahiRecordListItem, items, l->unread, i);
 }
 
 void avahi_record_list_drop(AvahiRecordList *l, AvahiRecord *r) {
     AvahiRecordListItem *i;
 
-    g_assert(l);
-    g_assert(r);
+    assert(l);
+    assert(r);
 
     if (!(i = get(l, r)))
         return;
@@ -148,8 +175,16 @@ void avahi_record_list_drop(AvahiRecordList *l, AvahiRecord *r) {
     item_free(l, i);
 }
 
-gboolean avahi_record_list_empty(AvahiRecordList *l) {
-    g_assert(l);
+int avahi_record_list_is_empty(AvahiRecordList *l) {
+    assert(l);
     
     return !l->unread && !l->read;
 }
+
+int avahi_record_list_all_flush_cache(AvahiRecordList *l) {
+    assert(l);
+
+    /* Return TRUE if all entries in this list have flush_cache set */
+    
+    return l->all_flush_cache;
+}