From c1d9b9cffd6f756339c1d98a2d2914d49195cb41 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 11 Oct 2005 00:18:57 +0000 Subject: add support for service subtypes: avahi_server_add_service_subtype() git-svn-id: file:///home/lennart/svn/public/avahi/trunk@714 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/publish.h | 12 +++++++ avahi-core/server.c | 98 +++++++++++++++++++++++++++++++++------------------- avahi-core/server.h | 7 ++++ 3 files changed, 82 insertions(+), 35 deletions(-) (limited to 'avahi-core') diff --git a/avahi-core/publish.h b/avahi-core/publish.h index 4143bb3..aa9eae0 100644 --- a/avahi-core/publish.h +++ b/avahi-core/publish.h @@ -208,6 +208,18 @@ int avahi_server_add_service_strlst( uint16_t port, AvahiStringList *strlst); +/** Add a subtype for an already existing service */ +int avahi_server_add_service_subtype( + AvahiServer *s, + AvahiSEntryGroup *g, + AvahiIfIndex interface, + AvahiProtocol protocol, + AvahiPublishFlags flags, + const char *name, /**< Specify the name of main service you already added here */ + const char *type, /**< Specify the main type of the service you already added here */ + const char *domain, /**< Specify the main type of the service you already added here */ + const char *subtype /**< The new subtype for the specified service */ ); + /** The type of DNS server */ typedef enum { AVAHI_DNS_SERVER_RESOLVE, /**< Unicast DNS servers for normal resolves (_domain._udp)*/ diff --git a/avahi-core/server.c b/avahi-core/server.c index 8082ea3..fdc53d5 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -1935,40 +1935,13 @@ static int server_add_service_strlst_nocopy( assert(type); assert(name); - if (!AVAHI_IF_VALID(interface)) { - ret = avahi_server_set_errno(s, AVAHI_ERR_INVALID_INTERFACE); - goto fail; - } - - if (!AVAHI_PROTO_VALID(protocol)) { - ret = avahi_server_set_errno(s, AVAHI_ERR_INVALID_PROTOCOL); - goto fail; - } - - if (!AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_NO_COOKIE|AVAHI_PUBLISH_IS_PROXY)) { - ret = avahi_server_set_errno(s, AVAHI_ERR_INVALID_FLAGS); - goto fail; - } - - if (!avahi_is_valid_service_name(name)) { - ret = avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_NAME); - goto fail; - } - - if (!avahi_is_valid_service_type(type)) { - ret = avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_TYPE); - goto fail; - } - - if (domain && !avahi_is_valid_domain_name(domain)) { - ret = avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME); - goto fail; - } - - if (host && !avahi_is_valid_domain_name(host)) { - ret = avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME); - goto fail; - } + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_PROTO_VALID(interface), AVAHI_ERR_INVALID_PROTOCOL); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_NO_COOKIE|AVAHI_PUBLISH_IS_PROXY), AVAHI_ERR_INVALID_FLAGS); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, avahi_is_valid_service_name(name), AVAHI_ERR_INVALID_SERVICE_NAME); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, avahi_is_valid_service_type(type), AVAHI_ERR_INVALID_SERVICE_TYPE); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, !domain || avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, !host || avahi_is_valid_domain_name(host), AVAHI_ERR_INVALID_HOST_NAME); if (!domain) domain = s->domain_name; @@ -1983,12 +1956,18 @@ static int server_add_service_strlst_nocopy( if ((ret = avahi_service_name_join(svc_name, sizeof(svc_name), name, type, domain)) < 0 || (ret = avahi_service_name_join(ptr_name, sizeof(ptr_name), NULL, type, domain)) < 0 || - (ret = avahi_service_name_join(enum_ptr, sizeof(enum_ptr), NULL, "_services._dns-sd._udp", domain)) < 0) + (ret = avahi_service_name_join(enum_ptr, sizeof(enum_ptr), NULL, "_services._dns-sd._udp", domain)) < 0) { + avahi_server_set_errno(s, ret); goto fail; + } + /* Add service enumeration PTR record */ + if ((ret = avahi_server_add_ptr(s, g, interface, protocol, flags & AVAHI_PUBLISH_IS_PROXY, AVAHI_DEFAULT_TTL, ptr_name, svc_name)) < 0) goto fail; + /* Add SRV record */ + if (!(r = avahi_record_new_full(svc_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME))) { ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); goto fail; @@ -2005,6 +1984,8 @@ static int server_add_service_strlst_nocopy( if (ret < 0) goto fail; + /* Add TXT record */ + if (!(flags & AVAHI_PUBLISH_NO_COOKIE)) strlst = add_magic_cookie(s, strlst); @@ -2014,6 +1995,8 @@ static int server_add_service_strlst_nocopy( if (ret < 0) goto fail; + /* Add service type enumeration record */ + ret = avahi_server_add_ptr(s, g, interface, protocol, (flags & AVAHI_PUBLISH_IS_PROXY), AVAHI_DEFAULT_TTL, enum_ptr, ptr_name); fail: @@ -2024,6 +2007,8 @@ fail: return ret; } + + int avahi_server_add_service_strlst( AvahiServer *s, AvahiSEntryGroup *g, @@ -2091,6 +2076,49 @@ int avahi_server_add_service( return ret; } +int avahi_server_add_service_subtype( + AvahiServer *s, + AvahiSEntryGroup *g, + AvahiIfIndex interface, + AvahiProtocol protocol, + AvahiPublishFlags flags, + const char *name, + const char *type, + const char *domain, + const char *subtype) { + + int ret = AVAHI_OK; + char svc_name[AVAHI_DOMAIN_NAME_MAX], ptr_name[AVAHI_DOMAIN_NAME_MAX]; + + assert(name); + assert(type); + assert(subtype); + + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_PROTO_VALID(interface), AVAHI_ERR_INVALID_PROTOCOL); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_NO_COOKIE|AVAHI_PUBLISH_IS_PROXY), AVAHI_ERR_INVALID_FLAGS); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, avahi_is_valid_service_name(name), AVAHI_ERR_INVALID_SERVICE_NAME); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, avahi_is_valid_service_type(type), AVAHI_ERR_INVALID_SERVICE_TYPE); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, !domain || avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME); + AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, avahi_is_valid_service_type(subtype), AVAHI_ERR_INVALID_SERVICE_SUBTYPE); + + if (!domain) + domain = s->domain_name; + + if ((ret = avahi_service_name_join(svc_name, sizeof(svc_name), name, type, domain)) < 0 || + (ret = avahi_service_name_join(ptr_name, sizeof(ptr_name), NULL, subtype, domain)) < 0) { + avahi_server_set_errno(s, ret); + goto fail; + } + + if ((ret = avahi_server_add_ptr(s, g, interface, protocol, flags & AVAHI_PUBLISH_IS_PROXY, AVAHI_DEFAULT_TTL, ptr_name, svc_name)) < 0) + goto fail; + +fail: + + return ret; +} + static void hexstring(char *s, size_t sl, const void *p, size_t pl) { static const char hex[] = "0123456789abcdef"; int b = 0; diff --git a/avahi-core/server.h b/avahi-core/server.h index 300ae8b..e7e77a2 100644 --- a/avahi-core/server.h +++ b/avahi-core/server.h @@ -182,4 +182,11 @@ int avahi_server_set_errno(AvahiServer *s, int error); } \ } +#define AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(server, expression, error) {\ + if (!(expression)) { \ + ret = avahi_server_set_errno((server), (error)); \ + goto fail; \ + } \ +} + #endif -- cgit