]> git.meshlink.io Git - catta/blobdiff - avahi-daemon/dbus-util.c
Enough is enough! I have had it with these motherf**ng gcc on this motherf**ng shut...
[catta] / avahi-daemon / dbus-util.c
index 09826d335afecd070e0011ad40deb72186303760..ca08d7b1dffb1461c57aed62fc187b51e39704ac 100644 (file)
 #include <avahi-core/log.h>
 #include <avahi-core/core.h>
 
+#ifdef ENABLE_CHROOT
+#include "chroot.h"
+#endif
+
 #include "main.h"
 #include "dbus-util.h"
 
@@ -155,15 +159,21 @@ const char *avahi_dbus_map_resolve_signal_name(AvahiResolverEvent e) {
     abort();
 }
 
-static char *file_get_contents(char *fname) {
+static char *file_get_contents(const char *fname) {
     int fd = -1;
     struct stat st;
     ssize_t size;
     char *buf = NULL;
-    
+
     assert(fname);
+    
+#ifdef ENABLE_CHROOT
+    fd = avahi_chroot_helper_get_fd(fname);
+#else
+    fd = open(fname, O_RDONLY);
+#endif
 
-    if (!(fd = open(fname, O_RDONLY))) {
+    if (fd < 0) {
         avahi_log_error("Failed to open %s: %s", fname, strerror(errno));
         goto fail;
     }
@@ -193,12 +203,13 @@ static char *file_get_contents(char *fname) {
     buf[size] = 0;
 
     close(fd);
+
     return buf;
     
 fail:
     if (fd >= 0)
         close(fd);
-
+    
     if (buf)
         avahi_free(buf);
 
@@ -207,7 +218,7 @@ fail:
 }
 
 DBusHandlerResult avahi_dbus_handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) {
-    char *path, *contents;
+    char *contents, *path;
     DBusError error;
     
     assert(c);
@@ -220,7 +231,7 @@ DBusHandlerResult avahi_dbus_handle_introspect(DBusConnection *c, DBusMessage *m
         avahi_log_error("Error parsing Introspect message: %s", error.message);
         goto fail;
     }
-    
+
     path = avahi_strdup_printf("%s/%s", AVAHI_DBUS_INTROSPECTION_DIR, fname);
     contents = file_get_contents(path);
     avahi_free(path);
@@ -316,9 +327,9 @@ int avahi_dbus_read_strlst(DBusMessage *m, int idx, AvahiStringList **l) {
     dbus_message_iter_recurse(&iter, &sub);
         
     for (;;) {
-        DBusMessageIter sub2;
         int at, n;
-        uint8_t *k;
+        const uint8_t *k;
+        DBusMessageIter sub2;
         
         if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID)
             break;
@@ -329,7 +340,14 @@ int avahi_dbus_read_strlst(DBusMessage *m, int idx, AvahiStringList **l) {
             goto fail;
 
         dbus_message_iter_recurse(&sub, &sub2);
+            
+        k = (const uint8_t*) "";
+        n = 0;
         dbus_message_iter_get_fixed_array(&sub2, &k, &n);
+
+        if (!k)
+            k = (const uint8_t*) "";
+            
         strlst = avahi_string_list_add_arbitrary(strlst, k, n);
         
         dbus_message_iter_next(&sub);
@@ -361,3 +379,17 @@ int avahi_dbus_is_our_own_service(Client *c, AvahiIfIndex interface, AvahiProtoc
     return 0;
 }
 
+int avahi_dbus_append_rdata(DBusMessage *message, const void *rdata, size_t size) {
+    DBusMessageIter iter, sub;
+    assert(message);
+    dbus_message_iter_init_append(message, &iter);
+    if (!(dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &sub)) ||
+        !(dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &rdata, size)) ||
+        !(dbus_message_iter_close_container(&iter, &sub)))
+        return -1;
+    
+    return 0;
+}