From d1dd07145bb3db5c6fd77c55aea762eb79ab3b5c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 10 Oct 2005 22:34:06 +0000 Subject: * rename avahi_service_name_snprint() to avahi_service_name_join() * add avahi_service_name_split() and make everything use it * change avahi_normalize_name() to work on a supplied buffer instead of malloc'ed memory. * add avahi_normalize_name_strdup() that retains the old behaviour avahi_normalize_name() * same thing for avahi_get_host_name()/avahi_get_host_name_strdup() * Rewrite domain name escaping and validity checking code * Remove superfluous memory allocationsfrom various browsers and do some other major cleanups * add new global macro AVAHI_CHECK_VALIDITY_RETURN_NULL() and modify many things to make use of it * add AVAHI_LABEL_MAX * patch everything to make use of AVAHI_LABEL_MAX and AVAHI_DOMAIN_NAME_MAX * add pretty printing for NS records * add partial pretty printing for SOA records * add many more validity checks to various user API functions git-svn-id: file:///home/lennart/svn/public/avahi/trunk@708 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/resolve-service.c | 50 +++++++++++++------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) (limited to 'avahi-core/resolve-service.c') diff --git a/avahi-core/resolve-service.c b/avahi-core/resolve-service.c index de347e2..43b61d2 100644 --- a/avahi-core/resolve-service.c +++ b/avahi-core/resolve-service.c @@ -397,40 +397,26 @@ AvahiSServiceResolver *avahi_s_service_resolver_new( AvahiSServiceResolver *r; AvahiKey *k; - char t[256]; + char n[AVAHI_DOMAIN_NAME_MAX]; int ret; assert(server); assert(type); assert(callback); - assert(aprotocol == AVAHI_PROTO_UNSPEC || aprotocol == AVAHI_PROTO_INET || aprotocol == AVAHI_PROTO_INET6); - - if (!AVAHI_IF_VALID(interface)) { - avahi_server_set_errno(server, AVAHI_ERR_INVALID_INTERFACE); - return NULL; - } - - if (name && !avahi_is_valid_service_name(name)) { - avahi_server_set_errno(server, AVAHI_ERR_INVALID_SERVICE_NAME); - return NULL; - } - - if (!avahi_is_valid_service_type(type)) { - avahi_server_set_errno(server, AVAHI_ERR_INVALID_SERVICE_TYPE); - return NULL; - } - - if (domain && !avahi_is_valid_domain_name(domain)) { - avahi_server_set_errno(server, AVAHI_ERR_INVALID_DOMAIN_NAME); - return NULL; - } + AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE); + AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL); + AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(aprotocol), AVAHI_ERR_INVALID_PROTOCOL); + AVAHI_CHECK_VALIDITY_RETURN_NULL(server, !domain || avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME); + AVAHI_CHECK_VALIDITY_RETURN_NULL(server, !name || avahi_is_valid_service_name(name), AVAHI_ERR_INVALID_SERVICE_NAME); + AVAHI_CHECK_VALIDITY_RETURN_NULL(server, avahi_is_valid_service_type(type), AVAHI_ERR_INVALID_SERVICE_TYPE); + AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST|AVAHI_LOOKUP_NO_TXT|AVAHI_LOOKUP_NO_ADDRESS), AVAHI_ERR_INVALID_FLAGS); if (!domain) domain = server->domain_name; - - if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST|AVAHI_LOOKUP_NO_TXT|AVAHI_LOOKUP_NO_ADDRESS)) { - avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS); + + if ((ret = avahi_service_name_join(n, sizeof(n), name, type, domain)) < 0) { + avahi_server_set_errno(server, ret); return NULL; } @@ -441,8 +427,8 @@ AvahiSServiceResolver *avahi_s_service_resolver_new( r->server = server; r->service_name = avahi_strdup(name); - r->service_type = avahi_normalize_name(type); - r->domain_name = avahi_normalize_name(domain); + r->service_type = avahi_normalize_name_strdup(type); + r->domain_name = avahi_normalize_name_strdup(domain); r->callback = callback; r->userdata = userdata; r->address_protocol = aprotocol; @@ -455,13 +441,7 @@ AvahiSServiceResolver *avahi_s_service_resolver_new( r->time_event = NULL; AVAHI_LLIST_PREPEND(AvahiSServiceResolver, resolver, server->service_resolvers, r); - if ((ret = avahi_service_name_snprint(t, sizeof(t), name, r->service_type, r->domain_name)) < 0) { - avahi_server_set_errno(server, ret); - avahi_s_service_resolver_free(r); - return NULL; - } - - k = avahi_key_new(t, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV); + k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV); r->record_browser_srv = avahi_s_record_browser_new(server, interface, protocol, k, flags & ~(AVAHI_LOOKUP_NO_TXT|AVAHI_LOOKUP_NO_ADDRESS), record_browser_callback, r); avahi_key_unref(k); @@ -471,7 +451,7 @@ AvahiSServiceResolver *avahi_s_service_resolver_new( } if (!(flags & AVAHI_LOOKUP_NO_TXT)) { - k = avahi_key_new(t, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT); + k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT); r->record_browser_txt = avahi_s_record_browser_new(server, interface, protocol, k, flags & ~(AVAHI_LOOKUP_NO_TXT|AVAHI_LOOKUP_NO_ADDRESS), record_browser_callback, r); avahi_key_unref(k); -- cgit