From: Lennart Poettering Date: Thu, 28 Jul 2005 00:01:44 +0000 (+0000) Subject: * drop trailing dot in avahi_normalize_name() X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=de0452f2ed4520c48fcd30e3999a044844b89f37;p=catta * drop trailing dot in avahi_normalize_name() git-svn-id: file:///home/lennart/svn/public/avahi/trunk@180 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/avahi-common/rr.c b/avahi-common/rr.c index 2a25321..c510e7f 100644 --- a/avahi-common/rr.c +++ b/avahi-common/rr.c @@ -182,7 +182,6 @@ const gchar *avahi_dns_type_to_string(guint16 type) { } } - gchar *avahi_key_to_string(const AvahiKey *k) { g_assert(k); g_assert(k->ref >= 1); diff --git a/avahi-common/util.c b/avahi-common/util.c index c9a3143..8be7b88 100644 --- a/avahi-common/util.c +++ b/avahi-common/util.c @@ -84,13 +84,12 @@ gchar *avahi_normalize_name(const gchar *s) { unescape_uneeded(s, tmp, sizeof(tmp)); - if ((l = strlen(tmp)) == 0) - return g_strdup("."); + l = strlen(tmp); - if (tmp[l-1] == '.') - return g_strdup(tmp); + while (l > 0 && tmp[l-1] == '.') + tmp[--l] = 0; - return g_strdup_printf("%s.", tmp); + return g_strdup(tmp); } gint avahi_timeval_compare(const GTimeVal *a, const GTimeVal *b) { diff --git a/avahi-core/browse-domain.c b/avahi-core/browse-domain.c index 06ad64a..7a95611 100644 --- a/avahi-core/browse-domain.c +++ b/avahi-core/browse-domain.c @@ -63,7 +63,7 @@ AvahiDomainBrowser *avahi_domain_browser_new(AvahiServer *server, gint interface b = g_new(AvahiDomainBrowser, 1); b->server = server; - b->domain_name = avahi_normalize_name(domain ? domain : "local."); + b->domain_name = avahi_normalize_name(domain ? domain : "local"); b->callback = callback; b->userdata = userdata; diff --git a/avahi-core/browse-service-type.c b/avahi-core/browse-service-type.c index 21c1157..bc0e0fc 100644 --- a/avahi-core/browse-service-type.c +++ b/avahi-core/browse-service-type.c @@ -92,7 +92,7 @@ AvahiServiceTypeBrowser *avahi_service_type_browser_new(AvahiServer *server, gin b = g_new(AvahiServiceTypeBrowser, 1); b->server = server; - b->domain_name = avahi_normalize_name(domain ? domain : "local."); + b->domain_name = avahi_normalize_name(domain ? domain : "local"); b->callback = callback; b->userdata = userdata; diff --git a/avahi-core/browse-service.c b/avahi-core/browse-service.c index 280de6e..500ec31 100644 --- a/avahi-core/browse-service.c +++ b/avahi-core/browse-service.c @@ -95,12 +95,12 @@ AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, gint interfa b = g_new(AvahiServiceBrowser, 1); b->server = server; - b->domain_name = avahi_normalize_name(domain ? domain : "local."); + b->domain_name = avahi_normalize_name(domain ? domain : "local"); b->service_type = avahi_normalize_name(service_type); b->callback = callback; b->userdata = userdata; - n = g_strdup_printf("%s%s", b->service_type, b->domain_name); + n = g_strdup_printf("%s.%s", b->service_type, b->domain_name); k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR); g_free(n); diff --git a/avahi-core/dns.c b/avahi-core/dns.c index 5213e97..f5d4075 100644 --- a/avahi-core/dns.c +++ b/avahi-core/dns.c @@ -432,7 +432,6 @@ gint avahi_dns_packet_consume_string(AvahiDnsPacket *p, gchar *ret_string, guint p->rindex += 1+k; return 0; - } gconstpointer avahi_dns_packet_get_rptr(AvahiDnsPacket *p) { diff --git a/avahi-core/resolve-service.c b/avahi-core/resolve-service.c index 8fe9fd2..6567d37 100644 --- a/avahi-core/resolve-service.c +++ b/avahi-core/resolve-service.c @@ -208,7 +208,7 @@ AvahiServiceResolver *avahi_service_resolver_new(AvahiServer *server, gint inter r = g_new(AvahiServiceResolver, 1); r->server = server; - r->service_name = avahi_normalize_name(name); + r->service_name = g_strdup(name); r->service_type = avahi_normalize_name(type); r->domain_name = avahi_normalize_name(domain); r->callback = callback; @@ -221,7 +221,7 @@ AvahiServiceResolver *avahi_service_resolver_new(AvahiServer *server, gint inter n = t; l = sizeof(t); avahi_escape_label((guint8*) name, strlen(name), &n, &l); - snprintf(n, l, ".%s%s", r->service_type, r->domain_name); + snprintf(n, l, ".%s.%s", r->service_type, r->domain_name); avahi_elapse_time(&tv, 1000, 0); r->time_event = avahi_time_event_queue_add(server->time_event_queue, &tv, time_event_callback, r); diff --git a/avahi-core/server.c b/avahi-core/server.c index 9619ab4..b3ab009 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -1249,7 +1249,7 @@ gint avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name) { withdraw_host_rrs(s); g_free(s->domain_name); - s->domain_name = domain_name ? avahi_normalize_name(domain_name) : g_strdup("local."); + s->domain_name = domain_name ? avahi_normalize_name(domain_name) : g_strdup("local"); update_fqdn(s); delayed_register_stuff(s); @@ -1347,7 +1347,7 @@ AvahiServer *avahi_server_new(GMainContext *c, const AvahiServerConfig *sc, Avah /* Get host name */ s->host_name = s->config.host_name ? avahi_normalize_name(s->config.host_name) : avahi_get_host_name(); s->host_name[strcspn(s->host_name, ".")] = 0; - s->domain_name = s->config.domain_name ? avahi_normalize_name(s->config.domain_name) : g_strdup("local."); + s->domain_name = s->config.domain_name ? avahi_normalize_name(s->config.domain_name) : g_strdup("local"); s->host_name_fqdn = NULL; update_fqdn(s); @@ -1717,6 +1717,7 @@ gint avahi_server_add_service_strlst( AvahiStringList *strlst) { gchar ptr_name[256], svc_name[256], ename[64], enum_ptr[256]; + gchar *t, *d; AvahiRecord *r; gint ret = 0; @@ -1735,9 +1736,12 @@ gint avahi_server_add_service_strlst( if (!host) host = s->host_name_fqdn; - snprintf(ptr_name, sizeof(ptr_name), "%s.%s", type, domain); - snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, type, domain); + d = avahi_normalize_name(domain); + t = avahi_normalize_name(type); + snprintf(ptr_name, sizeof(ptr_name), "%s.%s", t, d); + snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, t, d); + ret = avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, AVAHI_DEFAULT_TTL, ptr_name, svc_name); r = avahi_record_new_full(svc_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME); @@ -1750,9 +1754,12 @@ gint avahi_server_add_service_strlst( ret |= avahi_server_add_txt_strlst(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst); - snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", domain); + 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); + g_free(d); + g_free(t); + return ret; } @@ -1870,7 +1877,7 @@ gint avahi_server_add_dns_server_name( guint16 port /** should be 53 */) { gint ret = -1; - gchar t[256]; + gchar t[256], *d; AvahiRecord *r; g_assert(s); @@ -1883,7 +1890,9 @@ gint avahi_server_add_dns_server_name( } else domain = s->domain_name; - snprintf(t, sizeof(t), "%s.%s", type == AVAHI_DNS_SERVER_RESOLVE ? "_domain._udp" : "_dns-update._udp", domain); + d = avahi_normalize_name(domain); + snprintf(t, sizeof(t), "%s.%s", type == AVAHI_DNS_SERVER_RESOLVE ? "_domain._udp" : "_dns-update._udp", d); + g_free(d); r = avahi_record_new_full(t, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME); r->data.srv.priority = 0; @@ -1896,7 +1905,6 @@ gint avahi_server_add_dns_server_name( return ret; } - static void post_query_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) { AvahiKey *k = userdata; diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c index 7be5ee0..a1582ab 100644 --- a/avahi-daemon/dbus-protocol.c +++ b/avahi-daemon/dbus-protocol.c @@ -199,6 +199,7 @@ static DBusHandlerResult msg_signal_filter_impl(DBusConnection *c, DBusMessage * avahi_log_info("dbus: name acquired (%s)", name); return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) { gchar *name, *old, *new; @@ -289,6 +290,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, entry_group_free(i); return respond_ok(c, m); + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Commit")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -298,6 +300,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, avahi_entry_group_commit(i->entry_group); return respond_ok(c, m); + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "GetState")) { DBusMessage *reply; gint32 t; @@ -314,6 +317,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, dbus_message_unref(reply); return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService")) { gint32 interface, protocol; gchar *type, *name, *domain, *host; @@ -353,6 +357,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, avahi_log_info("Successfully added service: %s", name); return respond_ok(c, m); + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress")) { gint32 interface, protocol; gchar *name, *address; diff --git a/todo b/todo index 1822fa9..208d2c7 100644 --- a/todo +++ b/todo @@ -1,6 +1,7 @@ todo: +* finish DBUS stuff * release! -* drop trailing dot on avahi_normalize_name() + later: * support for special domain PTR records based on local IP subnet address * Changes resulting in updated RFC of 7th June 2005: @@ -44,3 +45,4 @@ done: * test against apple test suite * sensible logging * c++ support +* drop trailing dot on avahi_normalize_name()