summaryrefslogtreecommitdiffstats
path: root/avahi-daemon
diff options
context:
space:
mode:
Diffstat (limited to 'avahi-daemon')
-rw-r--r--avahi-daemon/EntryGroup.introspect6
-rw-r--r--avahi-daemon/Makefile.am7
-rw-r--r--avahi-daemon/RecordBrowser.introspect67
-rw-r--r--avahi-daemon/Server.introspect13
-rw-r--r--avahi-daemon/chroot.c4
-rw-r--r--avahi-daemon/dbus-internal.h16
-rw-r--r--avahi-daemon/dbus-protocol.c69
-rw-r--r--avahi-daemon/dbus-record-browser.c158
-rw-r--r--avahi-daemon/dbus-service-browser.c1
-rw-r--r--avahi-daemon/dbus-util.c14
-rw-r--r--avahi-daemon/dbus-util.h2
11 files changed, 350 insertions, 7 deletions
diff --git a/avahi-daemon/EntryGroup.introspect b/avahi-daemon/EntryGroup.introspect
index bf2ea13..e49bbe6 100644
--- a/avahi-daemon/EntryGroup.introspect
+++ b/avahi-daemon/EntryGroup.introspect
@@ -94,9 +94,9 @@
<arg name="protocol" type="i" direction="in"/>
<arg name="flags" type="u" direction="in"/>
<arg name="name" type="s" direction="in"/>
- <arg name="clazz" type="i" direction="in"/>
- <arg name="type" type="i" direction="in"/>
- <arg name="ttl" type="i" direction="in"/>
+ <arg name="clazz" type="q" direction="in"/>
+ <arg name="type" type="q" direction="in"/>
+ <arg name="ttl" type="u" direction="in"/>
<arg name="rdata" type="ay" direction="in"/>
</method>
</interface>
diff --git a/avahi-daemon/Makefile.am b/avahi-daemon/Makefile.am
index 6e0ac84..23f5a97 100644
--- a/avahi-daemon/Makefile.am
+++ b/avahi-daemon/Makefile.am
@@ -97,7 +97,8 @@ avahi_daemon_SOURCES += \
dbus-service-type-browser.c \
dbus-sync-address-resolver.c \
dbus-sync-host-name-resolver.c \
- dbus-sync-service-resolver.c
+ dbus-sync-service-resolver.c \
+ dbus-record-browser.c
avahi_daemon_LDADD += \
../avahi-common/libdbus-common.la \
@@ -115,7 +116,8 @@ introspection_DATA = \
ServiceBrowser.introspect \
ServiceResolver.introspect \
AddressResolver.introspect \
- HostNameResolver.introspect
+ HostNameResolver.introspect \
+ RecordBrowser.introspect
endif
endif
@@ -134,6 +136,7 @@ EXTRA_DIST = \
ServiceResolver.introspect \
AddressResolver.introspect \
HostNameResolver.introspect \
+ RecordBrowser.introspect \
ssh.service \
example.service \
introspect.dtd \
diff --git a/avahi-daemon/RecordBrowser.introspect b/avahi-daemon/RecordBrowser.introspect
new file mode 100644
index 0000000..57c1e66
--- /dev/null
+++ b/avahi-daemon/RecordBrowser.introspect
@@ -0,0 +1,67 @@
+<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
+<?xml-stylesheet type="text/xsl" href="introspect.xsl"?>
+<!DOCTYPE node SYSTEM "introspect.dtd">
+
+<!-- $Id$ -->
+
+<!--
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+-->
+
+<node>
+
+ <interface name="org.freedesktop.DBus.Introspectable">
+ <method name="Introspect">
+ <arg name="data" type="s" direction="out" />
+ </method>
+ </interface>
+
+ <interface name="org.freedesktop.Avahi.RecordBrowser">
+
+ <method name="Free"/>
+
+ <signal name="ItemNew">
+ <arg name="interface" type="i"/>
+ <arg name="protocol" type="i"/>
+ <arg name="name" type="s"/>
+ <arg name="clazz" type="q"/>
+ <arg name="type" type="q"/>
+ <arg name="rdata" type="ay"/>
+ <arg name="flags" type="u"/>
+ </signal>
+
+ <signal name="ItemRemove">
+ <arg name="interface" type="i"/>
+ <arg name="protocol" type="i"/>
+ <arg name="name" type="s"/>
+ <arg name="clazz" type="q"/>
+ <arg name="type" type="q"/>
+ <arg name="rdata" type="ay"/>
+ <arg name="flags" type="u"/>
+ </signal>
+
+ <signal name="Failure">
+ <arg name="error" type="s"/>
+ </signal>
+
+ <signal name="AllForNow"/>
+
+ <signal name="CacheExhausted"/>
+
+ </interface>
+</node>
diff --git a/avahi-daemon/Server.introspect b/avahi-daemon/Server.introspect
index f8d88e9..ec2f042 100644
--- a/avahi-daemon/Server.introspect
+++ b/avahi-daemon/Server.introspect
@@ -192,5 +192,18 @@
<arg name="path" type="o" direction="out"/>
</method>
+
+ <method name="RecordBrowserNew">
+ <arg name="interface" type="i" direction="in"/>
+ <arg name="protocol" type="i" direction="in"/>
+ <arg name="name" type="s" direction="in"/>
+ <arg name="clazz" type="q" direction="in"/>
+ <arg name="type" type="q" direction="in"/>
+ <arg name="flags" type="u" direction="in"/>
+
+ <arg name="path" type="o" direction="out"/>
+ </method>
+
+
</interface>
</node>
diff --git a/avahi-daemon/chroot.c b/avahi-daemon/chroot.c
index 5478bce..5ca605d 100644
--- a/avahi-daemon/chroot.c
+++ b/avahi-daemon/chroot.c
@@ -54,6 +54,7 @@ enum {
AVAHI_CHROOT_GET_SERVICE_BROWSER_INTROSPECT,
AVAHI_CHROOT_GET_SERVICE_RESOLVER_INTROSPECT,
AVAHI_CHROOT_GET_SERVICE_TYPE_BROWSER_INTROSPECT,
+ AVAHI_CHROOT_GET_RECORD_BROWSER_INTROSPECT,
#endif
AVAHI_CHROOT_UNLINK_PID,
AVAHI_CHROOT_UNLINK_SOCKET,
@@ -73,6 +74,7 @@ static const char* const get_file_name_table[AVAHI_CHROOT_MAX] = {
AVAHI_DBUS_INTROSPECTION_DIR"/ServiceBrowser.introspect",
AVAHI_DBUS_INTROSPECTION_DIR"/ServiceResolver.introspect",
AVAHI_DBUS_INTROSPECTION_DIR"/ServiceTypeBrowser.introspect",
+ AVAHI_DBUS_INTROSPECTION_DIR"/RecordBrowser.introspect",
#endif
NULL,
NULL
@@ -91,6 +93,7 @@ static const char *const unlink_file_name_table[AVAHI_CHROOT_MAX] = {
NULL,
NULL,
NULL,
+ NULL,
#endif
AVAHI_DAEMON_RUNTIME_DIR"/pid",
AVAHI_SOCKET
@@ -233,6 +236,7 @@ static int helper_main(int fd) {
case AVAHI_CHROOT_GET_SERVICE_BROWSER_INTROSPECT:
case AVAHI_CHROOT_GET_SERVICE_RESOLVER_INTROSPECT:
case AVAHI_CHROOT_GET_SERVICE_TYPE_BROWSER_INTROSPECT:
+ case AVAHI_CHROOT_GET_RECORD_BROWSER_INTROSPECT:
#endif
case AVAHI_CHROOT_GET_RESOLV_CONF: {
int payload;
diff --git a/avahi-daemon/dbus-internal.h b/avahi-daemon/dbus-internal.h
index 49e398d..a49dae3 100644
--- a/avahi-daemon/dbus-internal.h
+++ b/avahi-daemon/dbus-internal.h
@@ -43,6 +43,7 @@ typedef struct ServiceTypeBrowserInfo ServiceTypeBrowserInfo;
typedef struct ServiceBrowserInfo ServiceBrowserInfo;
typedef struct SyncServiceResolverInfo SyncServiceResolverInfo;
typedef struct AsyncServiceResolverInfo AsyncServiceResolverInfo;
+typedef struct RecordBrowserInfo RecordBrowserInfo;
#define CLIENTS_MAX 256
#define OBJECTS_PER_CLIENT_MAX 50
@@ -137,6 +138,15 @@ struct AsyncServiceResolverInfo {
AVAHI_LLIST_FIELDS(AsyncServiceResolverInfo, async_service_resolvers);
};
+struct RecordBrowserInfo {
+ unsigned id;
+ Client *client;
+ AvahiSRecordBrowser *record_browser;
+ char *path;
+
+ AVAHI_LLIST_FIELDS(RecordBrowserInfo, record_browsers);
+};
+
struct Client {
unsigned id;
char *name;
@@ -154,6 +164,7 @@ struct Client {
AVAHI_LLIST_HEAD(ServiceBrowserInfo, service_browsers);
AVAHI_LLIST_HEAD(SyncServiceResolverInfo, sync_service_resolvers);
AVAHI_LLIST_HEAD(AsyncServiceResolverInfo, async_service_resolvers);
+ AVAHI_LLIST_HEAD(RecordBrowserInfo, record_browsers);
};
struct Server {
@@ -229,4 +240,9 @@ void avahi_dbus_async_service_resolver_callback(
void* userdata);
DBusHandlerResult avahi_dbus_msg_async_service_resolver_impl(DBusConnection *c, DBusMessage *m, void *userdata);
+
+void avahi_dbus_record_browser_free(RecordBrowserInfo *i);
+DBusHandlerResult avahi_dbus_msg_record_browser_impl(DBusConnection *c, DBusMessage *m, void *userdata);
+void avahi_dbus_record_browser_callback(AvahiSRecordBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, AvahiLookupResultFlags flags, void* userdata);
+
#endif
diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c
index c6c4a67..f01837a 100644
--- a/avahi-daemon/dbus-protocol.c
+++ b/avahi-daemon/dbus-protocol.c
@@ -100,6 +100,9 @@ static void client_free(Client *c) {
while (c->async_service_resolvers)
avahi_dbus_async_service_resolver_free(c->async_service_resolvers);
+ while (c->record_browsers)
+ avahi_dbus_record_browser_free(c->record_browsers);
+
assert(c->n_objects == 0);
avahi_free(c->name);
@@ -143,6 +146,7 @@ static Client *client_get(const char *name, int create) {
AVAHI_LLIST_HEAD_INIT(ServiceBrowserInfo, client->service_browsers);
AVAHI_LLIST_HEAD_INIT(SyncServiceResolverInfo, client->sync_service_resolvers);
AVAHI_LLIST_HEAD_INIT(AsyncServiceResolverInfo, client->async_service_resolvers);
+ AVAHI_LLIST_HEAD_INIT(RecordBrowserInfo, client->record_browsers);
AVAHI_LLIST_PREPEND(Client, clients, server->clients, client);
@@ -646,7 +650,6 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH
return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
}
-
if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) {
avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
@@ -888,6 +891,70 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH
dbus_connection_register_object_path(c, i->path, &vtable, i);
return avahi_dbus_respond_path(c, m, i->path);
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "RecordBrowserNew")) {
+ Client *client;
+ RecordBrowserInfo *i;
+ static const DBusObjectPathVTable vtable = {
+ NULL,
+ avahi_dbus_msg_record_browser_impl,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ };
+ int32_t interface, protocol;
+ uint32_t flags;
+ char *name;
+ uint16_t type, clazz;
+ AvahiKey *key;
+
+ if (!dbus_message_get_args(
+ m, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_UINT16, &clazz,
+ DBUS_TYPE_UINT16, &type,
+ DBUS_TYPE_UINT32, &flags,
+ DBUS_TYPE_INVALID) || !name) {
+ avahi_log_warn("Error parsing Server::RecordBrowserNew message");
+ goto fail;
+ }
+
+ if (!avahi_is_valid_domain_name(name))
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_INVALID_DOMAIN_NAME, NULL);
+
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
+ }
+
+ i = avahi_new(RecordBrowserInfo, 1);
+ i->id = ++client->current_id;
+ i->client = client;
+ i->path = avahi_strdup_printf("/Client%u/RecordBrowser%u", client->id, i->id);
+ AVAHI_LLIST_PREPEND(RecordBrowserInfo, record_browsers, client->record_browsers, i);
+ client->n_objects++;
+
+ key = avahi_key_new(name, clazz, type);
+ assert(key);
+
+ if (!(i->record_browser = avahi_s_record_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, key, (AvahiLookupFlags) flags, avahi_dbus_record_browser_callback, i))) {
+ avahi_key_unref(key);
+ avahi_dbus_record_browser_free(i);
+ return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
+ }
+
+ avahi_key_unref(key);
+
+ dbus_connection_register_object_path(c, i->path, &vtable, i);
+ return avahi_dbus_respond_path(c, m, i->path);
}
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
diff --git a/avahi-daemon/dbus-record-browser.c b/avahi-daemon/dbus-record-browser.c
new file mode 100644
index 0000000..e9ac6ab
--- /dev/null
+++ b/avahi-daemon/dbus-record-browser.c
@@ -0,0 +1,158 @@
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include <avahi-common/malloc.h>
+#include <avahi-common/dbus.h>
+#include <avahi-common/error.h>
+#include <avahi-core/log.h>
+
+#include "dbus-util.h"
+#include "dbus-internal.h"
+
+void avahi_dbus_record_browser_free(RecordBrowserInfo *i) {
+ assert(i);
+
+ if (i->record_browser)
+ avahi_s_record_browser_free(i->record_browser);
+ dbus_connection_unregister_object_path(server->bus, i->path);
+ avahi_free(i->path);
+ AVAHI_LLIST_REMOVE(RecordBrowserInfo, record_browsers, i->client->record_browsers, i);
+
+ i->client->n_objects--;
+ assert(i->client->n_objects >= 0);
+
+ avahi_free(i);
+}
+
+DBusHandlerResult avahi_dbus_msg_record_browser_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
+ DBusError error;
+ RecordBrowserInfo *i = userdata;
+
+ assert(c);
+ assert(m);
+ assert(i);
+
+ dbus_error_init(&error);
+
+ avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
+ dbus_message_get_interface(m),
+ dbus_message_get_path(m),
+ dbus_message_get_member(m));
+
+ /* Introspection */
+ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
+ return avahi_dbus_handle_introspect(c, m, "RecordBrowser.Introspect");
+
+ /* Access control */
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
+
+ if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "Free")) {
+
+ if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
+ avahi_log_warn("Error parsing RecordBrowser::Free message");
+ goto fail;
+ }
+
+ avahi_dbus_record_browser_free(i);
+ return avahi_dbus_respond_ok(c, m);
+
+ }
+
+ avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
+
+fail:
+ if (dbus_error_is_set(&error))
+ dbus_error_free(&error);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+void avahi_dbus_record_browser_callback(
+ AvahiSRecordBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ AvahiRecord *record,
+ AvahiLookupResultFlags flags,
+ void* userdata) {
+
+ RecordBrowserInfo *i = userdata;
+ DBusMessage *m = NULL;
+ int32_t i_interface, i_protocol;
+ uint32_t u_flags;
+
+ assert(b);
+ assert(i);
+
+ i_interface = (int32_t) interface;
+ i_protocol = (int32_t) protocol;
+ u_flags = (uint32_t) flags;
+
+ m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, avahi_dbus_map_browse_signal_name(event));
+
+ if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) {
+ uint8_t rdata[0xFFFF];
+ size_t size;
+ assert(record);
+
+ if (!(dbus_message_append_args(
+ m,
+ DBUS_TYPE_INT32, &i_interface,
+ DBUS_TYPE_INT32, &i_protocol,
+ DBUS_TYPE_STRING, &record->key->name,
+ DBUS_TYPE_UINT16, &record->key->clazz,
+ DBUS_TYPE_UINT16, &record->key->type,
+ DBUS_TYPE_INVALID)))
+ goto fail;
+
+ if ((size = avahi_rdata_serialize(record, rdata, sizeof(rdata))) == (size_t) -1 ||
+ avahi_dbus_append_rdata(m, rdata, size) < 0) {
+ avahi_log_debug(__FILE__": Failed to append rdata");
+ dbus_message_unref(m);
+ return;
+ }
+
+ dbus_message_append_args(
+ m,
+ DBUS_TYPE_UINT32, &u_flags,
+ DBUS_TYPE_INVALID);
+
+ } else if (event == AVAHI_BROWSER_FAILURE)
+ avahi_dbus_append_server_error(m);
+
+ dbus_message_set_destination(m, i->client->name);
+ dbus_connection_send(server->bus, m, NULL);
+ dbus_message_unref(m);
+
+ return;
+
+fail:
+
+ if (m)
+ dbus_message_unref(m);
+}
diff --git a/avahi-daemon/dbus-service-browser.c b/avahi-daemon/dbus-service-browser.c
index 2e65f66..dc10b81 100644
--- a/avahi-daemon/dbus-service-browser.c
+++ b/avahi-daemon/dbus-service-browser.c
@@ -48,7 +48,6 @@ void avahi_dbus_service_browser_free(ServiceBrowserInfo *i) {
avahi_free(i);
}
-
DBusHandlerResult avahi_dbus_msg_service_browser_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
DBusError error;
ServiceBrowserInfo *i = userdata;
diff --git a/avahi-daemon/dbus-util.c b/avahi-daemon/dbus-util.c
index 00d8a9d..76a6b73 100644
--- a/avahi-daemon/dbus-util.c
+++ b/avahi-daemon/dbus-util.c
@@ -372,3 +372,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;
+}
diff --git a/avahi-daemon/dbus-util.h b/avahi-daemon/dbus-util.h
index b8cb211..e994915 100644
--- a/avahi-daemon/dbus-util.h
+++ b/avahi-daemon/dbus-util.h
@@ -54,4 +54,6 @@ int avahi_dbus_read_strlst(DBusMessage *m, int idx, AvahiStringList **l);
int avahi_dbus_is_our_own_service(Client *c, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain);
+int avahi_dbus_append_rdata(DBusMessage *message, const void *rdata, size_t size);
+
#endif