+static char *file_get_contents(char *fname) {
+ int fd = -1;
+ struct stat st;
+ ssize_t size;
+ char *buf = NULL;
+
+ assert(fname);
+
+ if (!(fd = open(fname, O_RDONLY))) {
+ avahi_log_error("Failed to open %s: %s", fname, strerror(errno));
+ goto fail;
+ }
+
+ if (fstat(fd, &st) < 0) {
+ avahi_log_error("stat(%s) failed: %s", fname, strerror(errno));
+ goto fail;
+ }
+
+ if (!(S_ISREG(st.st_mode))) {
+ avahi_log_error("Invalid file %s", fname);
+ goto fail;
+ }
+
+ if (st.st_size > 1024*1024) { /** 1MB */
+ avahi_log_error("File too large %s", fname);
+ goto fail;
+ }
+
+ buf = avahi_new(char, st.st_size+1);
+
+ if ((size = read(fd, buf, st.st_size)) < 0) {
+ avahi_log_error("read() failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ buf[size] = 0;
+
+ close(fd);
+ return buf;
+
+fail:
+ if (fd >= 0)
+ close(fd);
+
+ if (buf)
+ avahi_free(buf);
+
+ return NULL;
+
+}
+
+static DBusHandlerResult handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) {
+ char *path, *contents;