summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-08-02 23:57:07 +0000
committerLennart Poettering <lennart@poettering.net>2005-08-02 23:57:07 +0000
commitf43187377e0c89ba02ca23e88efa01bbb255e037 (patch)
tree92dba5140c3932bf0debf2362a82f4f3b5d92bad
parent1a912326734243e57a461c48131c1a0402318b5a (diff)
* replace guchar and gint by AvahiProtocol, AvahiIfIndex at many places where it make sense
* change avahi_add_{service,txt}_strlst() to copy the string list * gcc warning fixes from Ikke * limit number of DBUS connections * limit objects created by a DBUS client * limit number of clients * limit number of entries a client may create * add legal blurb to avahi-discover * remove some obsolete import prototypes from avahi-discover * don't include config.h in dbus.h * add string definitions for DBUS errors git-svn-id: file:///home/lennart/svn/public/avahi/trunk@212 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r--avahi-common/dbus.h15
-rw-r--r--avahi-core/avahi-test.c16
-rw-r--r--avahi-core/browse-dns-server.c14
-rw-r--r--avahi-core/browse-domain.c4
-rw-r--r--avahi-core/browse-service-type.c4
-rw-r--r--avahi-core/browse-service.c4
-rw-r--r--avahi-core/browse.c6
-rw-r--r--avahi-core/core.h4
-rw-r--r--avahi-core/resolve-address.c6
-rw-r--r--avahi-core/resolve-host-name.c6
-rw-r--r--avahi-core/resolve-service.c10
-rw-r--r--avahi-core/server.c88
-rw-r--r--avahi-core/server.h6
-rw-r--r--avahi-daemon/avahi-dbus.conf.in1
-rw-r--r--avahi-daemon/dbus-protocol.c176
-rw-r--r--avahi-daemon/main.c5
-rw-r--r--avahi-daemon/simple-protocol.c6
-rw-r--r--avahi-daemon/static-services.c2
-rw-r--r--avahi-discover/main.c40
-rw-r--r--todo4
20 files changed, 303 insertions, 114 deletions
diff --git a/avahi-common/dbus.h b/avahi-common/dbus.h
index f6ad4d2..08f16f1 100644
--- a/avahi-common/dbus.h
+++ b/avahi-common/dbus.h
@@ -1,4 +1,6 @@
#ifndef foodbushfoo
+#define foodbushfoo
+
/* $Id$ */
/***
@@ -20,9 +22,7 @@
USA.
***/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+AVAHI_C_DECL_BEGIN
#define AVAHI_DBUS_NAME "org.freedesktop.Avahi"
#define AVAHI_DBUS_INTERFACE_SERVER AVAHI_DBUS_NAME".Server"
@@ -32,4 +32,13 @@
#define AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER AVAHI_DBUS_NAME".ServiceTypeBrowser"
#define AVAHI_DBUS_INTERFACE_SERVICE_BROWSER AVAHI_DBUS_NAME".ServiceBrowser"
+#define AVAHI_DBUS_ERROR_INVALID_SERVICE "org.freedesktop.Avahi.InvalidServiceError"
+#define AVAHI_DBUS_ERROR_INVALID_ADDRESS "org.freedesktop.Avahi.InvalidAddressError"
+#define AVAHI_DBUS_ERROR_TIMEOUT "org.freedesktop.Avahi.TimeoutError"
+#define AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS "org.freedesktop.Avahi.TooManyClientsError"
+#define AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS "org.freedesktop.Avahi.TooManyObjectsError"
+#define AVAHI_DBUS_ERROR_TOO_MANY_ENTRIES "org.freedesktop.Avahi.TooManyEntriesError"
+
+AVAHI_C_DECL_END
+
#endif
diff --git a/avahi-core/avahi-test.c b/avahi-core/avahi-test.c
index f966659..d91e698 100644
--- a/avahi-core/avahi-test.c
+++ b/avahi-core/avahi-test.c
@@ -51,7 +51,7 @@ static gboolean dump_timeout(gpointer data) {
return TRUE;
}
-static void record_browser_callback(AvahiRecordBrowser *r, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
gchar *t;
g_assert(r);
@@ -150,7 +150,7 @@ fail:
group = NULL;
}
-static void hnr_callback(AvahiHostNameResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *hostname, const AvahiAddress *a, gpointer userdata) {
+static void hnr_callback(AvahiHostNameResolver *r, AvahiIfIndex iface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *hostname, const AvahiAddress *a, gpointer userdata) {
gchar t[64];
if (a)
@@ -159,7 +159,7 @@ static void hnr_callback(AvahiHostNameResolver *r, gint iface, guchar protocol,
avahi_log_debug("HNR: (%i.%i) <%s> -> %s [%s]", iface, protocol, hostname, a ? t : "n/a", event == AVAHI_RESOLVER_FOUND ? "found" : "timeout");
}
-static void ar_callback(AvahiAddressResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const AvahiAddress *a, const gchar *hostname, gpointer userdata) {
+static void ar_callback(AvahiAddressResolver *r, AvahiIfIndex iface, AvahiProtocol protocol, AvahiBrowserEvent event, const AvahiAddress *a, const gchar *hostname, gpointer userdata) {
gchar t[64];
avahi_address_snprint(t, sizeof(t), a);
@@ -167,21 +167,21 @@ static void ar_callback(AvahiAddressResolver *r, gint iface, guchar protocol, Av
avahi_log_debug("AR: (%i.%i) %s -> <%s> [%s]", iface, protocol, t, hostname ? hostname : "n/a", event == AVAHI_RESOLVER_FOUND ? "found" : "timeout");
}
-static void db_callback(AvahiDomainBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata) {
+static void db_callback(AvahiDomainBrowser *b, AvahiIfIndex iface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata) {
avahi_log_debug("DB: (%i.%i) <%s> [%s]", iface, protocol, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
}
-static void stb_callback(AvahiServiceTypeBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) {
+static void stb_callback(AvahiServiceTypeBrowser *b, AvahiIfIndex iface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) {
avahi_log_debug("STB: (%i.%i) %s in <%s> [%s]", iface, protocol, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
}
-static void sb_callback(AvahiServiceBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *name, const gchar *service_type, const gchar *domain, gpointer userdata) {
+static void sb_callback(AvahiServiceBrowser *b, AvahiIfIndex iface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *name, const gchar *service_type, const gchar *domain, gpointer userdata) {
avahi_log_debug("SB: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
}
-static void sr_callback(AvahiServiceResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *name, const gchar*service_type, const gchar*domain_name, const gchar*hostname, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata) {
+static void sr_callback(AvahiServiceResolver *r, AvahiIfIndex iface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *name, const gchar*service_type, const gchar*domain_name, const gchar*hostname, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata) {
if (event == AVAHI_RESOLVER_TIMEOUT)
avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s> [timeout]", iface, protocol, name, service_type, domain_name);
@@ -196,7 +196,7 @@ static void sr_callback(AvahiServiceResolver *r, gint iface, guchar protocol, Av
}
}
-static void dsb_callback(AvahiDNSServerBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar*hostname, const AvahiAddress *a, guint16 port, gpointer userdata) {
+static void dsb_callback(AvahiDNSServerBrowser *b, AvahiIfIndex iface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar*hostname, const AvahiAddress *a, guint16 port, gpointer userdata) {
gchar t[64];
avahi_address_snprint(t, sizeof(t), a);
avahi_log_debug("DSB: (%i.%i): %s/%s:%i [%s]", iface, protocol, hostname, t, port, event == AVAHI_BROWSER_NEW ? "new" : "remove");
diff --git a/avahi-core/browse-dns-server.c b/avahi-core/browse-dns-server.c
index 9dd4798..f8e8f30 100644
--- a/avahi-core/browse-dns-server.c
+++ b/avahi-core/browse-dns-server.c
@@ -35,8 +35,8 @@ typedef struct AvahiDNSServerInfo AvahiDNSServerInfo;
struct AvahiDNSServerInfo {
AvahiDNSServerBrowser *browser;
- gint interface;
- guchar protocol;
+ AvahiIfIndex interface;
+ AvahiProtocol protocol;
AvahiRecord *srv_record;
AvahiHostNameResolver *host_name_resolver;
AvahiAddress address;
@@ -51,7 +51,7 @@ struct AvahiDNSServerBrowser {
AvahiRecordBrowser *record_browser;
AvahiDNSServerBrowserCallback callback;
gpointer userdata;
- guchar aprotocol;
+ AvahiProtocol aprotocol;
guint n_info;
@@ -59,7 +59,7 @@ struct AvahiDNSServerBrowser {
AVAHI_LLIST_HEAD(AvahiDNSServerInfo, info);
};
-static AvahiDNSServerInfo* get_server_info(AvahiDNSServerBrowser *b, gint interface, guchar protocol, AvahiRecord *r) {
+static AvahiDNSServerInfo* get_server_info(AvahiDNSServerBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *r) {
AvahiDNSServerInfo *i;
g_assert(b);
@@ -90,7 +90,7 @@ static void server_info_free(AvahiDNSServerBrowser *b, AvahiDNSServerInfo *i) {
g_free(i);
}
-static void host_name_resolver_callback(AvahiHostNameResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata) {
+static void host_name_resolver_callback(AvahiHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata) {
AvahiDNSServerInfo *i = userdata;
g_assert(r);
@@ -107,7 +107,7 @@ static void host_name_resolver_callback(AvahiHostNameResolver *r, gint interface
i->host_name_resolver = NULL;
}
-static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
AvahiDNSServerBrowser *b = userdata;
g_assert(rr);
@@ -148,7 +148,7 @@ static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, gucha
}
}
-AvahiDNSServerBrowser *avahi_dns_server_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiDNSServerType type, guchar aprotocol, AvahiDNSServerBrowserCallback callback, gpointer userdata) {
+AvahiDNSServerBrowser *avahi_dns_server_browser_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const gchar *domain, AvahiDNSServerType type, AvahiProtocol aprotocol, AvahiDNSServerBrowserCallback callback, gpointer userdata) {
AvahiDNSServerBrowser *b;
AvahiKey *k;
gchar *n = NULL;
diff --git a/avahi-core/browse-domain.c b/avahi-core/browse-domain.c
index 30745f6..c6331b4 100644
--- a/avahi-core/browse-domain.c
+++ b/avahi-core/browse-domain.c
@@ -38,7 +38,7 @@ struct AvahiDomainBrowser {
AVAHI_LLIST_FIELDS(AvahiDomainBrowser, browser);
};
-static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
AvahiDomainBrowser *b = userdata;
gchar *n;
@@ -53,7 +53,7 @@ static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, gucha
g_free(n);
}
-AvahiDomainBrowser *avahi_domain_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiDomainBrowserType type, AvahiDomainBrowserCallback callback, gpointer userdata) {
+AvahiDomainBrowser *avahi_domain_browser_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const gchar *domain, AvahiDomainBrowserType type, AvahiDomainBrowserCallback callback, gpointer userdata) {
AvahiDomainBrowser *b;
AvahiKey *k;
gchar *n = NULL;
diff --git a/avahi-core/browse-service-type.c b/avahi-core/browse-service-type.c
index bc0e0fc..7cd6cf7 100644
--- a/avahi-core/browse-service-type.c
+++ b/avahi-core/browse-service-type.c
@@ -41,7 +41,7 @@ struct AvahiServiceTypeBrowser {
AVAHI_LLIST_FIELDS(AvahiServiceTypeBrowser, browser);
};
-static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
AvahiServiceTypeBrowser *b = userdata;
gchar *n, *e, *c;
@@ -82,7 +82,7 @@ fail:
g_free(n);
}
-AvahiServiceTypeBrowser *avahi_service_type_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiServiceTypeBrowserCallback callback, gpointer userdata) {
+AvahiServiceTypeBrowser *avahi_service_type_browser_new(AvahiServer *server, gint interface, AvahiProtocol protocol, const gchar *domain, AvahiServiceTypeBrowserCallback callback, gpointer userdata) {
AvahiServiceTypeBrowser *b;
AvahiKey *k;
gchar *n = NULL;
diff --git a/avahi-core/browse-service.c b/avahi-core/browse-service.c
index 500ec31..f72ce6c 100644
--- a/avahi-core/browse-service.c
+++ b/avahi-core/browse-service.c
@@ -42,7 +42,7 @@ struct AvahiServiceBrowser {
AVAHI_LLIST_FIELDS(AvahiServiceBrowser, browser);
};
-static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
AvahiServiceBrowser *b = userdata;
gchar *n, *e, *c, *s;
gchar service[128];
@@ -84,7 +84,7 @@ fail:
g_free(n);
}
-AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *service_type, const gchar *domain, AvahiServiceBrowserCallback callback, gpointer userdata) {
+AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const gchar *service_type, const gchar *domain, AvahiServiceBrowserCallback callback, gpointer userdata) {
AvahiServiceBrowser *b;
AvahiKey *k;
gchar *n = NULL;
diff --git a/avahi-core/browse.c b/avahi-core/browse.c
index 897cb2b..5f4d216 100644
--- a/avahi-core/browse.c
+++ b/avahi-core/browse.c
@@ -32,8 +32,8 @@ struct AvahiRecordBrowser {
AvahiServer *server;
AvahiKey *key;
- gint interface;
- guchar protocol;
+ AvahiIfIndex interface;
+ AvahiProtocol protocol;
guint sec_delay;
AvahiTimeEvent *time_event;
@@ -116,7 +116,7 @@ static gboolean scan_idle_callback(gpointer data) {
return FALSE;
}
-AvahiRecordBrowser *avahi_record_browser_new(AvahiServer *server, gint interface, guchar protocol, AvahiKey *key, AvahiRecordBrowserCallback callback, gpointer userdata) {
+AvahiRecordBrowser *avahi_record_browser_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key, AvahiRecordBrowserCallback callback, gpointer userdata) {
AvahiRecordBrowser *b, *t;
GTimeVal tv;
diff --git a/avahi-core/core.h b/avahi-core/core.h
index c09aec4..bacb97e 100644
--- a/avahi-core/core.h
+++ b/avahi-core/core.h
@@ -253,7 +253,7 @@ gint avahi_server_add_txt_strlst(
AvahiEntryFlags flags,
guint32 ttl,
const gchar *name,
- AvahiStringList *strlst /**< TXT decord data as a AvahiString. Only the pointer to the object and not the object itself is copied into the RR. Therefore you should not free the strlst object yourself, this will be done by the library. If you want to add multiple records with the same RR data you MUST copy the strlst object prior to calling this function with avahi_strlst_copy(). */ );
+ AvahiStringList *strlst /**< TXT decord data as a AvahiString. This routine makes a deep copy of this object. */ );
/** Add an IP address mapping to the server. This will add both the
* host-name-to-address and the reverse mapping to the server. See
@@ -302,7 +302,7 @@ gint avahi_server_add_service_va(
guint16 port,
va_list va);
-/** Mostly identical to avahi_server_add_service(), but takes an AvahiStringList object for the TXT records. The AvahiStringList object is not copied. You need to make a copy if this object if you want to reuse it. The object is freed if the RR is removed from the server. */
+/** Mostly identical to avahi_server_add_service(), but takes an AvahiStringList object for the TXT records. The AvahiStringList object is copied. */
gint avahi_server_add_service_strlst(
AvahiServer *s,
AvahiEntryGroup *g,
diff --git a/avahi-core/resolve-address.c b/avahi-core/resolve-address.c
index a4ed594..d315ac9 100644
--- a/avahi-core/resolve-address.c
+++ b/avahi-core/resolve-address.c
@@ -40,7 +40,7 @@ struct AvahiAddressResolver {
AVAHI_LLIST_FIELDS(AvahiAddressResolver, resolver);
};
-static void finish(AvahiAddressResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, AvahiRecord *record) {
+static void finish(AvahiAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, AvahiRecord *record) {
g_assert(r);
avahi_record_browser_free(r->record_browser);
@@ -54,7 +54,7 @@ static void finish(AvahiAddressResolver *r, gint interface, guchar protocol, Ava
r->callback(r, interface, protocol, event, &r->address, record ? record->data.ptr.name : NULL, r->userdata);
}
-static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
AvahiAddressResolver *r = userdata;
g_assert(rr);
@@ -78,7 +78,7 @@ static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
finish(r, -1, AVAHI_PROTO_UNSPEC, AVAHI_RESOLVER_TIMEOUT, NULL);
}
-AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, gint interface, guchar protocol, const AvahiAddress *address, AvahiAddressResolverCallback callback, gpointer userdata) {
+AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const AvahiAddress *address, AvahiAddressResolverCallback callback, gpointer userdata) {
AvahiAddressResolver *r;
AvahiKey *k;
gchar *n;
diff --git a/avahi-core/resolve-host-name.c b/avahi-core/resolve-host-name.c
index fadfc85..0ab2e73 100644
--- a/avahi-core/resolve-host-name.c
+++ b/avahi-core/resolve-host-name.c
@@ -41,7 +41,7 @@ struct AvahiHostNameResolver {
AVAHI_LLIST_FIELDS(AvahiHostNameResolver, resolver);
};
-static void finish(AvahiHostNameResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, AvahiRecord *record) {
+static void finish(AvahiHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, AvahiRecord *record) {
AvahiAddress a;
g_assert(r);
@@ -81,7 +81,7 @@ static void finish(AvahiHostNameResolver *r, gint interface, guchar protocol, Av
r->callback(r, interface, protocol, event, record ? record->key->name : r->host_name, record ? &a : NULL, r->userdata);
}
-static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
AvahiHostNameResolver *r = userdata;
g_assert(rr);
@@ -104,7 +104,7 @@ static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
finish(r, -1, AVAHI_PROTO_UNSPEC, AVAHI_RESOLVER_TIMEOUT, NULL);
}
-AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *server, gint interface, guchar protocol, const gchar *host_name, guchar aprotocol, AvahiHostNameResolverCallback callback, gpointer userdata) {
+AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const gchar *host_name, guchar aprotocol, AvahiHostNameResolverCallback callback, gpointer userdata) {
AvahiHostNameResolver *r;
AvahiKey *k;
GTimeVal tv;
diff --git a/avahi-core/resolve-service.c b/avahi-core/resolve-service.c
index cf07d91..b15af4f 100644
--- a/avahi-core/resolve-service.c
+++ b/avahi-core/resolve-service.c
@@ -33,10 +33,10 @@ struct AvahiServiceResolver {
gchar *service_name;
gchar *service_type;
gchar *domain_name;
- guchar address_protocol;
+ AvahiProtocol address_protocol;
- gint interface;
- guchar protocol;
+ AvahiIfIndex interface;
+ AvahiProtocol protocol;
AvahiRecordBrowser *record_browser_srv;
AvahiRecordBrowser *record_browser_txt;
@@ -121,7 +121,7 @@ static void finish(AvahiServiceResolver *r, AvahiResolverEvent event) {
}
}
-static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
AvahiServiceResolver *r = userdata;
g_assert(rr);
@@ -192,7 +192,7 @@ static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
finish(r, AVAHI_RESOLVER_TIMEOUT);
}
-AvahiServiceResolver *avahi_service_resolver_new(AvahiServer *server, gint interface, guchar protocol, const gchar *name, const gchar *type, const gchar *domain, guchar aprotocol, AvahiServiceResolverCallback callback, gpointer userdata) {
+AvahiServiceResolver *avahi_service_resolver_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const gchar *name, const gchar *type, const gchar *domain, AvahiProtocol aprotocol, AvahiServiceResolverCallback callback, gpointer userdata) {
AvahiServiceResolver *r;
AvahiKey *k;
GTimeVal tv;
diff --git a/avahi-core/server.c b/avahi-core/server.c
index bd4f536..4507aea 100644
--- a/avahi-core/server.c
+++ b/avahi-core/server.c
@@ -1435,7 +1435,7 @@ void avahi_server_free(AvahiServer* s) {
g_free(s);
}
-static gint check_record_conflict(AvahiServer *s, gint interface, guchar protocol, AvahiRecord *r, AvahiEntryFlags flags) {
+static gint check_record_conflict(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *r, AvahiEntryFlags flags) {
AvahiEntry *e;
g_assert(s);
@@ -1468,8 +1468,8 @@ static gint check_record_conflict(AvahiServer *s, gint interface, guchar protoco
gint avahi_server_add(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
AvahiEntryFlags flags,
AvahiRecord *r) {
@@ -1559,8 +1559,8 @@ void avahi_server_dump(AvahiServer *s, AvahiDumpCallback callback, gpointer user
gint avahi_server_add_ptr(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
AvahiEntryFlags flags,
guint32 ttl,
const gchar *name,
@@ -1581,8 +1581,8 @@ gint avahi_server_add_ptr(
gint avahi_server_add_address(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
AvahiEntryFlags flags,
const gchar *name,
AvahiAddress *a) {
@@ -1630,11 +1630,11 @@ gint avahi_server_add_address(
return ret;
}
-gint avahi_server_add_txt_strlst(
+static gint server_add_txt_strlst_nocopy(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
AvahiEntryFlags flags,
guint32 ttl,
const gchar *name,
@@ -1653,26 +1653,39 @@ gint avahi_server_add_txt_strlst(
return ret;
}
+gint avahi_server_add_txt_strlst(
+ AvahiServer *s,
+ AvahiEntryGroup *g,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiEntryFlags flags,
+ guint32 ttl,
+ const gchar *name,
+ AvahiStringList *strlst) {
+
+ return server_add_txt_strlst_nocopy(s, g, interface, protocol, flags, ttl, name, avahi_string_list_copy(strlst));
+}
+
gint avahi_server_add_txt_va(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
AvahiEntryFlags flags,
guint32 ttl,
const gchar *name,
va_list va) {
-
+
g_assert(s);
- return avahi_server_add_txt_strlst(s, g, interface, protocol, flags, ttl, name, avahi_string_list_new_va(va));
+ return server_add_txt_strlst_nocopy(s, g, interface, protocol, flags, ttl, name, avahi_string_list_new_va(va));
}
gint avahi_server_add_txt(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
AvahiEntryFlags flags,
guint32 ttl,
const gchar *name,
@@ -1712,11 +1725,11 @@ static void escape_service_name(gchar *d, guint size, const gchar *s) {
*(d++) = 0;
}
-gint avahi_server_add_service_strlst(
+static gint server_add_service_strlst_nocopy(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
const gchar *name,
const gchar *type,
const gchar *domain,
@@ -1760,7 +1773,7 @@ gint avahi_server_add_service_strlst(
ret |= avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, r);
avahi_record_unref(r);
- ret |= avahi_server_add_txt_strlst(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
+ ret |= server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
g_snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", d);
ret |=avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, AVAHI_DEFAULT_TTL, enum_ptr, ptr_name);
@@ -1771,11 +1784,26 @@ gint avahi_server_add_service_strlst(
return ret;
}
+gint avahi_server_add_service_strlst(
+ AvahiServer *s,
+ AvahiEntryGroup *g,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const gchar *name,
+ const gchar *type,
+ const gchar *domain,
+ const gchar *host,
+ guint16 port,
+ AvahiStringList *strlst) {
+
+ return server_add_service_strlst_nocopy(s, g, interface, protocol, name, type, domain, host, port, avahi_string_list_copy(strlst));
+}
+
gint avahi_server_add_service_va(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
const gchar *name,
const gchar *type,
const gchar *domain,
@@ -1787,14 +1815,14 @@ gint avahi_server_add_service_va(
g_assert(type);
g_assert(name);
- return avahi_server_add_service_strlst(s, g, interface, protocol, name, type, domain, host, port, avahi_string_list_new_va(va));
+ return server_add_service_strlst_nocopy(s, g, interface, protocol, name, type, domain, host, port, avahi_string_list_new_va(va));
}
gint avahi_server_add_service(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
const gchar *name,
const gchar *type,
const gchar *domain,
@@ -1840,8 +1868,8 @@ static void hexstring(gchar *s, size_t sl, const void *p, size_t pl) {
gint avahi_server_add_dns_server_address(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
const gchar *domain,
AvahiDNSServerType type,
const AvahiAddress *address,
@@ -1877,8 +1905,8 @@ gint avahi_server_add_dns_server_address(
gint avahi_server_add_dns_server_name(
AvahiServer *s,
AvahiEntryGroup *g,
- gint interface,
- guchar protocol,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
const gchar *domain,
AvahiDNSServerType type,
const gchar *name,
@@ -1923,7 +1951,7 @@ static void post_query_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpo
avahi_interface_post_query(i, k, FALSE);
}
-void avahi_server_post_query(AvahiServer *s, gint interface, guchar protocol, AvahiKey *key) {
+void avahi_server_post_query(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key) {
g_assert(s);
g_assert(key);
diff --git a/avahi-core/server.h b/avahi-core/server.h
index 9a1fca3..97febc5 100644
--- a/avahi-core/server.h
+++ b/avahi-core/server.h
@@ -55,8 +55,8 @@ struct AvahiEntry {
AvahiEntryFlags flags;
AvahiRecord *record;
- gint interface;
- guchar protocol;
+ AvahiIfIndex interface;
+ AvahiProtocol protocol;
AVAHI_LLIST_FIELDS(AvahiEntry, entries);
AVAHI_LLIST_FIELDS(AvahiEntry, by_key);
@@ -133,7 +133,7 @@ struct AvahiServer {
gboolean avahi_server_entry_match_interface(AvahiEntry *e, AvahiInterface *i);
-void avahi_server_post_query(AvahiServer *s, gint interface, guchar protocol, AvahiKey *key);
+void avahi_server_post_query(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key);
void avahi_server_prepare_response(AvahiServer *s, AvahiInterface *i, AvahiEntry *e, gboolean unicast_response, gboolean auxiliary);
void avahi_server_prepare_matching_responses(AvahiServer *s, AvahiInterface *i, AvahiKey *k, gboolean unicast_response);
diff --git a/avahi-daemon/avahi-dbus.conf.in b/avahi-daemon/avahi-dbus.conf.in
index 485c03e..416c8dc 100644
--- a/avahi-daemon/avahi-dbus.conf.in
+++ b/avahi-daemon/avahi-dbus.conf.in
@@ -20,5 +20,6 @@
</policy>
<limit name="max_match_rules_per_connection">512</limit>
+ <limit name="max_connections_per_user">20</limit>
</busconfig>
diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c
index 0631f72..0813617 100644
--- a/avahi-daemon/dbus-protocol.c
+++ b/avahi-daemon/dbus-protocol.c
@@ -48,11 +48,17 @@ typedef struct ServiceTypeBrowserInfo ServiceTypeBrowserInfo;
typedef struct ServiceBrowserInfo ServiceBrowserInfo;
typedef struct ServiceResolverInfo ServiceResolverInfo;
+#define MAX_CLIENTS 20
+#define MAX_OBJECTS_PER_CLIENT 50
+#define MAX_ENTRIES_PER_ENTRY_GROUP 20
+
struct EntryGroupInfo {
guint id;
Client *client;
AvahiEntryGroup *entry_group;
gchar *path;
+
+ gint n_entries;
AVAHI_LLIST_FIELDS(EntryGroupInfo, entry_groups);
};
@@ -112,6 +118,7 @@ struct Client {
guint id;
gchar *name;
guint current_id;
+ gint n_objects;
AVAHI_LLIST_FIELDS(Client, clients);
AVAHI_LLIST_HEAD(EntryGroupInfo, entry_groups);
@@ -126,6 +133,7 @@ struct Client {
struct Server {
DBusConnection *bus;
AVAHI_LLIST_HEAD(Client, clients);
+ gint n_clients;
guint current_id;
};
@@ -139,6 +147,10 @@ static void entry_group_free(EntryGroupInfo *i) {
dbus_connection_unregister_object_path(server->bus, i->path);
g_free(i->path);
AVAHI_LLIST_REMOVE(EntryGroupInfo, entry_groups, i->client->entry_groups, i);
+
+ i->client->n_objects--;
+ g_assert(i->client->n_objects >= 0);
+
g_free(i);
}
@@ -149,6 +161,10 @@ static void host_name_resolver_free(HostNameResolverInfo *i) {
avahi_host_name_resolver_free(i->host_name_resolver);
dbus_message_unref(i->message);
AVAHI_LLIST_REMOVE(HostNameResolverInfo, host_name_resolvers, i->client->host_name_resolvers, i);
+
+ i->client->n_objects--;
+ g_assert(i->client->n_objects >= 0);
+
g_free(i);
}
@@ -159,6 +175,10 @@ static void address_resolver_free(AddressResolverInfo *i) {
avahi_address_resolver_free(i->address_resolver);
dbus_message_unref(i->message);
AVAHI_LLIST_REMOVE(AddressResolverInfo, address_resolvers, i->client->address_resolvers, i);
+
+ i->client->n_objects--;
+ g_assert(i->client->n_objects >= 0);
+
g_free(i);
}
@@ -170,6 +190,10 @@ static void domain_browser_free(DomainBrowserInfo *i) {
dbus_connection_unregister_object_path(server->bus, i->path);
g_free(i->path);
AVAHI_LLIST_REMOVE(DomainBrowserInfo, domain_browsers, i->client->domain_browsers, i);
+
+ i->client->n_objects--;
+ g_assert(i->client->n_objects >= 0);
+
g_free(i);
}
@@ -181,6 +205,10 @@ static void service_type_browser_free(ServiceTypeBrowserInfo *i) {
dbus_connection_unregister_object_path(server->bus, i->path);
g_free(i->path);
AVAHI_LLIST_REMOVE(ServiceTypeBrowserInfo, service_type_browsers, i->client->service_type_browsers, i);
+
+ i->client->n_objects--;
+ g_assert(i->client->n_objects >= 0);
+
g_free(i);
}
@@ -192,6 +220,10 @@ static void service_browser_free(ServiceBrowserInfo *i) {
dbus_connection_unregister_object_path(server->bus, i->path);
g_free(i->path);
AVAHI_LLIST_REMOVE(ServiceBrowserInfo, service_browsers, i->client->service_browsers, i);
+
+ i->client->n_objects--;
+ g_assert(i->client->n_objects >= 0);
+
g_free(i);
}
@@ -202,6 +234,10 @@ static void service_resolver_free(ServiceResolverInfo *i) {
avahi_service_resolver_free(i->service_resolver);
dbus_message_unref(i->message);
AVAHI_LLIST_REMOVE(ServiceResolverInfo, service_resolvers, i->client->service_resolvers, i);
+
+ i->client->n_objects--;
+ g_assert(i->client->n_objects >= 0);
+
g_free(i);
}
@@ -231,9 +267,14 @@ static void client_free(Client *c) {
while (c->service_resolvers)
service_resolver_free(c->service_resolvers);
+ g_assert(c->n_objects == 0);
+
g_free(c->name);
AVAHI_LLIST_REMOVE(Client, clients, server->clients, c);
g_free(c);
+
+ server->n_clients --;
+ g_assert(server->n_clients >= 0);
}
static Client *client_get(const gchar *name, gboolean create) {
@@ -249,11 +290,15 @@ static Client *client_get(const gchar *name, gboolean create) {
if (!create)
return NULL;
+ if (server->n_clients >= MAX_CLIENTS)
+ return NULL;
+
/* If not existant yet, create a new entry */
client = g_new(Client, 1);
client->id = server->current_id++;
client->name = g_strdup(name);
client->current_id = 0;
+ client->n_objects = 0;
AVAHI_LLIST_HEAD_INIT(EntryGroupInfo, client->entry_groups);
AVAHI_LLIST_HEAD_INIT(HostNameResolverInfo, client->host_name_resolvers);
AVAHI_LLIST_HEAD_INIT(AddressResolverInfo, client->address_resolvers);
@@ -263,6 +308,10 @@ static Client *client_get(const gchar *name, gboolean create) {
AVAHI_LLIST_HEAD_INIT(ServiceResolverInfo, client->service_resolvers);
AVAHI_LLIST_PREPEND(Client, clients, server->clients, client);
+
+ server->n_clients++;
+ g_assert(server->n_clients > 0);
+
return client;
}
@@ -504,6 +553,12 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m,
goto fail;
}
+ if (i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP) {
+ avahi_log_warn("Too many entries per entry group, client request failed.");
+ dbus_free_string_array(txt);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_ENTRIES, NULL);
+ }
+
strlst = avahi_string_list_new_from_array((const gchar**) txt, txt_len);
dbus_free_string_array(txt);
@@ -515,9 +570,12 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m,
if (avahi_server_add_service_strlst(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, host, port, strlst) < 0) {
avahi_log_warn("Failed to add service: %s", name);
- return respond_error(c, m, "org.freedesktop.Avahi.InvalidServiceError", NULL);
- } /* else */
-/* avahi_log_info("Successfully added service: %s", name); */
+ avahi_string_list_free(strlst);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_INVALID_SERVICE, NULL);
+ } else
+ i->n_entries ++;
+
+ avahi_string_list_free(strlst);
return respond_ok(c, m);
@@ -537,16 +595,21 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m,
goto fail;
}
+ if (i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP) {
+ avahi_log_warn("Too many entries per entry group, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_ENTRIES, NULL);
+ }
+
if (!(avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a))) {
avahi_log_warn("Error parsing address data");
- return respond_error(c, m, "org.freedesktop.Avahi.InvalidAddressError", NULL);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_INVALID_ADDRESS, NULL);
}
if (avahi_server_add_address(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, 0, name, &a) < 0) {
avahi_log_warn("Failed to add service: %s", name);
- return respond_error(c, m, "org.freedesktop.Avahi.InvalidAddressError", NULL);
- }/* else */
-/* avahi_log_info("Successfully added address: %s -> %s", name, address); */
+ return respond_error(c, m, AVAHI_DBUS_ERROR_INVALID_ADDRESS, NULL);
+ } else
+ i->n_entries ++;
return respond_ok(c, m);
}
@@ -591,7 +654,7 @@ static void host_name_resolver_callback(AvahiHostNameResolver *r, AvahiIfIndex i
} else {
g_assert(event == AVAHI_RESOLVER_TIMEOUT);
- reply = dbus_message_new_error(i->message, "org.freedesktop.Avahi.TimeoutError", NULL);
+ reply = dbus_message_new_error(i->message, AVAHI_DBUS_ERROR_TIMEOUT, NULL);
}
dbus_connection_send(server->bus, reply, NULL);
@@ -631,7 +694,7 @@ static void address_resolver_callback(AvahiAddressResolver *r, AvahiIfIndex inte
} else {
g_assert(event == AVAHI_RESOLVER_TIMEOUT);
- reply = dbus_message_new_error(i->message, "org.freedesktop.Avahi.TimeoutError", NULL);
+ reply = dbus_message_new_error(i->message, AVAHI_DBUS_ERROR_TIMEOUT, NULL);
}
dbus_connection_send(server->bus, reply, NULL);
@@ -912,7 +975,7 @@ static void service_resolver_callback(
} else {
g_assert(event == AVAHI_RESOLVER_TIMEOUT);
- reply = dbus_message_new_error(i->message, "org.freedesktop.Avahi.TimeoutError", NULL);
+ reply = dbus_message_new_error(i->message, AVAHI_DBUS_ERROR_TIMEOUT, NULL);
}
dbus_connection_send(server->bus, reply, NULL);
@@ -1034,14 +1097,24 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
goto fail;
}
- client = client_get(dbus_message_get_sender(m), TRUE);
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
i = g_new(EntryGroupInfo, 1);
i->id = ++client->current_id;
i->client = client;
i->path = g_strdup_printf("/Client%u/EntryGroup%u", client->id, i->id);
+ i->n_entries = 0;
AVAHI_LLIST_PREPEND(EntryGroupInfo, entry_groups, client->entry_groups, i);
-
+ client->n_objects++;
+
if (!(i->entry_group = avahi_entry_group_new(avahi_server, entry_group_callback, i))) {
avahi_log_warn("Failed to create entry group");
entry_group_free(i);
@@ -1068,12 +1141,21 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
goto fail;
}
- client = client_get(dbus_message_get_sender(m), TRUE);
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
i = g_new(HostNameResolverInfo, 1);
i->client = client;
i->message = dbus_message_ref(m);
AVAHI_LLIST_PREPEND(HostNameResolverInfo, host_name_resolvers, client->host_name_resolvers, i);
+ client->n_objects++;
if (!(i->host_name_resolver = avahi_host_name_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, (AvahiProtocol) aprotocol, host_name_resolver_callback, i))) {
host_name_resolver_free(i);
@@ -1102,16 +1184,24 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
if (!avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a)) {
avahi_log_warn("Error parsing address data");
- return respond_error(c, m, "org.freedesktop.Avahi.InvalidAddressError", NULL);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_INVALID_ADDRESS, NULL);
+ }
+
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
}
-
- client = client_get(dbus_message_get_sender(m), TRUE);
i = g_new(AddressResolverInfo, 1);
i->client = client;
i->message = dbus_message_ref(m);
-
AVAHI_LLIST_PREPEND(AddressResolverInfo, address_resolvers, client->address_resolvers, i);
+ client->n_objects++;
if (!(i->address_resolver = avahi_address_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, &a, address_resolver_callback, i))) {
address_resolver_free(i);
@@ -1147,7 +1237,15 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
goto fail;
}
- client = client_get(dbus_message_get_sender(m), TRUE);
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
if (!*domain)
domain = NULL;
@@ -1156,8 +1254,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
i->id = ++client->current_id;
i->client = client;
i->path = g_strdup_printf("/Client%u/DomainBrowser%u", client->id, i->id);
-
AVAHI_LLIST_PREPEND(DomainBrowserInfo, domain_browsers, client->domain_browsers, i);
+ client->n_objects++;
if (!(i->domain_browser = avahi_domain_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, domain, (AvahiDomainBrowserType) type, domain_browser_callback, i))) {
avahi_log_warn("Failed to create domain browser");
@@ -1192,7 +1290,16 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
goto fail;
}
- client = client_get(dbus_message_get_sender(m), TRUE);
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
if (!*domain)
domain = NULL;
@@ -1201,8 +1308,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
i->id = ++client->current_id;
i->client = client;
i->path = g_strdup_printf("/Client%u/ServiceTypeBrowser%u", client->id, i->id);
-
AVAHI_LLIST_PREPEND(ServiceTypeBrowserInfo, service_type_browsers, client->service_type_browsers, i);
+ client->n_objects++;
if (!(i->service_type_browser = avahi_service_type_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, domain, service_type_browser_callback, i))) {
avahi_log_warn("Failed to create service type browser");
@@ -1238,7 +1345,16 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
goto fail;
}
- client = client_get(dbus_message_get_sender(m), TRUE);
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
if (!*domain)
domain = NULL;
@@ -1247,8 +1363,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
i->id = ++client->current_id;
i->client = client;
i->path = g_strdup_printf("/Client%u/ServiceBrowser%u", client->id, i->id);
-
AVAHI_LLIST_PREPEND(ServiceBrowserInfo, service_browsers, client->service_browsers, i);
+ client->n_objects++;
if (!(i->service_browser = avahi_service_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, type, domain, service_browser_callback, i))) {
avahi_log_warn("Failed to create service browser");
@@ -1278,7 +1394,15 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
goto fail;
}
- client = client_get(dbus_message_get_sender(m), TRUE);
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
if (!*domain)
domain = NULL;
@@ -1287,6 +1411,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
i->client = client;
i->message = dbus_message_ref(m);
AVAHI_LLIST_PREPEND(ServiceResolverInfo, service_resolvers, client->service_resolvers, i);
+ client->n_objects++;
if (!(i->service_resolver = avahi_service_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, (AvahiProtocol) aprotocol, service_resolver_callback, i))) {
service_resolver_free(i);
@@ -1337,6 +1462,7 @@ int dbus_protocol_setup(GMainLoop *loop) {
server = g_malloc(sizeof(Server));
server->clients = NULL;
server->current_id = 0;
+ server->n_clients = 0;
server->bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
if (dbus_error_is_set(&error)) {
@@ -1379,6 +1505,8 @@ void dbus_protocol_shutdown(void) {
while (server->clients)
client_free(server->clients);
+ g_assert(server->n_clients == 0);
+
if (server->bus) {
dbus_connection_disconnect(server->bus);
dbus_connection_unref(server->bus);
diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c
index 4891d10..7d83c46 100644
--- a/avahi-daemon/main.c
+++ b/avahi-daemon/main.c
@@ -714,7 +714,7 @@ int main(int argc, char *argv[]) {
argv0 = argv[0];
daemon_pid_file_ident = (const char *) argv0;
- daemon_log_ident = argv0;
+ daemon_log_ident = (char*) argv0;
daemon_pid_file_proc = pid_file_proc;
if (parse_command_line(&config, argc, argv) < 0)
@@ -781,6 +781,9 @@ int main(int argc, char *argv[]) {
/* Child */
}
+
+ printf("%s "PACKAGE_VERSION" starting up.\n", argv0);
+
chdir("/");
if (make_runtime_dir() < 0)
diff --git a/avahi-daemon/simple-protocol.c b/avahi-daemon/simple-protocol.c
index 9a1b1e2..f7c3f1e 100644
--- a/avahi-daemon/simple-protocol.c
+++ b/avahi-daemon/simple-protocol.c
@@ -164,7 +164,7 @@ static void client_output_printf(Client *c, const gchar *format, ...) {
}
-static void host_name_resolver_callback(AvahiHostNameResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *hostname, const AvahiAddress *a, gpointer userdata) {
+static void host_name_resolver_callback(AvahiHostNameResolver *r, AvahiIfIndex iface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *hostname, const AvahiAddress *a, gpointer userdata) {
Client *c = userdata;
g_assert(c);
@@ -181,7 +181,7 @@ static void host_name_resolver_callback(AvahiHostNameResolver *r, gint iface, gu
c->state = CLIENT_DEAD;
}
-static void address_resolver_callback(AvahiAddressResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const AvahiAddress *a, const gchar *hostname, gpointer userdata) {
+static void address_resolver_callback(AvahiAddressResolver *r, AvahiIfIndex iface, AvahiProtocol protocol, AvahiBrowserEvent event, const AvahiAddress *a, const gchar *hostname, gpointer userdata) {
Client *c = userdata;
@@ -195,7 +195,7 @@ static void address_resolver_callback(AvahiAddressResolver *r, gint iface, gucha
c->state = CLIENT_DEAD;
}
-static void dns_server_browser_callback(AvahiDNSServerBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *host_name, const AvahiAddress *a, guint16 port, gpointer userdata) {
+static void dns_server_browser_callback(AvahiDNSServerBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *host_name, const AvahiAddress *a, guint16 port, gpointer userdata) {
Client *c = userdata;
gchar t[64];
diff --git a/avahi-daemon/static-services.c b/avahi-daemon/static-services.c
index 0ac6326..1f9b765 100644
--- a/avahi-daemon/static-services.c
+++ b/avahi-daemon/static-services.c
@@ -213,7 +213,7 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) {
-1, AF_UNSPEC,
g->chosen_name, s->type,
s->domain_name, s->host_name, s->port,
- avahi_string_list_copy(s->txt_records)) < 0) {
+ s->txt_records) < 0) {
avahi_log_error("Failed to add service '%s' of type '%s', ignoring service group (%s)", g->chosen_name, s->type, g->filename);
remove_static_service_group_from_server(g);
return;
diff --git a/avahi-discover/main.c b/avahi-discover/main.c
index 5e99bf8..daecdaa 100644
--- a/avahi-discover/main.c
+++ b/avahi-discover/main.c
@@ -1,3 +1,24 @@
+/* $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
@@ -8,6 +29,7 @@
#include <glade/glade.h>
#include <avahi-core/core.h>
#include <avahi-common/strlst.h>
+#include <avahi-common/util.h>
struct ServiceType;
@@ -16,8 +38,8 @@ struct Service {
gchar *service_name;
gchar *domain_name;
- gint interface;
- guchar protocol;
+ AvahiIfIndex interface;
+ AvahiProtocol protocol;
GtkTreeRowReference *tree_ref;
};
@@ -40,11 +62,7 @@ static GHashTable *service_type_hash_table = NULL;
static AvahiServiceResolver *service_resolver = NULL;
static struct Service *current_service = NULL;
-/* very, very ugly: just import these two internal but useful functions from libavahi-core by hand */
-guint avahi_domain_hash(const gchar *s);
-gboolean avahi_domain_equal(const gchar *a, const gchar *b);
-
-static struct Service *get_service(const gchar *service_type, const gchar *service_name, const gchar*domain_name, gint interface, guchar protocol) {
+static struct Service *get_service(const gchar *service_type, const gchar *service_name, const gchar*domain_name, AvahiIfIndex interface, AvahiProtocol protocol) {
struct ServiceType *st;
GList *l;
@@ -94,7 +112,7 @@ static void free_service(struct Service *s) {
g_free(s);
}
-static void service_browser_callback(AvahiServiceBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *service_name, const gchar *service_type, const gchar *domain_name, gpointer userdata) {
+static void service_browser_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_name, const gchar *service_type, const gchar *domain_name, gpointer userdata) {
if (event == AVAHI_BROWSER_NEW) {
struct Service *s;
@@ -136,7 +154,7 @@ static void service_browser_callback(AvahiServiceBrowser *b, gint interface, guc
}
}
-static void service_type_browser_callback(AvahiServiceTypeBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) {
+static void service_type_browser_callback(AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) {
struct ServiceType *st;
GtkTreePath *path;
GtkTreeIter iter;
@@ -210,7 +228,7 @@ static struct Service *get_service_on_cursor(void) {
}
-static void service_resolver_callback(AvahiServiceResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const gchar *name, const gchar *type, const gchar *domain, const gchar *host_name, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata) {
+static void service_resolver_callback(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const gchar *name, const gchar *type, const gchar *domain, const gchar *host_name, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata) {
struct Service *s;
g_assert(r);
@@ -240,7 +258,7 @@ static void tree_view_on_cursor_changed(GtkTreeView *tv, gpointer userdata) {
service_resolver = avahi_service_resolver_new(server, s->interface, s->protocol, s->service_name, s->service_type->service_type, s->domain_name, AF_UNSPEC, service_resolver_callback, s);
}
-gboolean main_window_on_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) {
+static gboolean main_window_on_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) {
gtk_main_quit();
return FALSE;
}
diff --git a/todo b/todo
index beae6e8..44c7af3 100644
--- a/todo
+++ b/todo
@@ -1,8 +1,10 @@
todo:
* finish DBUS stuff:
- enforce limits
- - allow NUL bytes in TXT records
+ - allow NUL bytes in TXT records
* release!
+* add internal error codes
+* add entry_group::reset()
later:
* support for special domain PTR records based on local IP subnet address