- if (host && !avahi_is_valid_domain_name(host))
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME);
-
- if (port == 0)
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PORT);
-
- escape_service_name(ename, sizeof(ename), name);
-
- if (!domain)
- domain = s->domain_name;
-
- if (!host)
- host = s->host_name_fqdn;
-
- if (!(d = avahi_normalize_name(domain)) ||
- !(t = avahi_normalize_name(type)) ||
- !(h = avahi_normalize_name(host))) {
- ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
- goto fail;
- }
-
- snprintf(ptr_name, sizeof(ptr_name), "%s.%s", t, d);
- snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, t, d);
-
- if ((ret = avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, AVAHI_DEFAULT_TTL, ptr_name, svc_name)) < 0)
- goto fail;
-
- 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;
- }
-
- r->data.srv.priority = 0;
- r->data.srv.weight = 0;
- r->data.srv.port = port;
- r->data.srv.name = h;
- h = NULL;
- ret = avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, r);
- avahi_record_unref(r);
-
- if (ret < 0)
- goto fail;
-
- ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
- strlst = NULL;
-
- if (ret < 0)
- goto fail;
-
- 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);
-
-fail:
-
- avahi_free(d);
- avahi_free(t);
- avahi_free(h);
-
- avahi_string_list_free(strlst);
-
- return ret;
-}
-
-int avahi_server_add_service_strlst(
- AvahiServer *s,
- AvahiEntryGroup *g,
- AvahiIfIndex interface,
- AvahiProtocol protocol,
- const char *name,
- const char *type,
- const char *domain,
- const char *host,
- uint16_t port,
- AvahiStringList *strlst) {
-
- assert(s);
- assert(type);
- assert(name);
-
- return server_add_service_strlst_nocopy(s, g, interface, protocol, name, type, domain, host, port, avahi_string_list_copy(strlst));
-}
-
-int avahi_server_add_service_va(
- AvahiServer *s,
- AvahiEntryGroup *g,
- AvahiIfIndex interface,
- AvahiProtocol protocol,
- const char *name,
- const char *type,
- const char *domain,
- const char *host,
- uint16_t port,
- va_list va){
-
- assert(s);
- assert(type);
- assert(name);
-
- return server_add_service_strlst_nocopy(s, g, interface, protocol, name, type, domain, host, port, avahi_string_list_new_va(va));
-}
-
-int avahi_server_add_service(
- AvahiServer *s,
- AvahiEntryGroup *g,
- AvahiIfIndex interface,
- AvahiProtocol protocol,
- const char *name,
- const char *type,
- const char *domain,
- const char *host,
- uint16_t port,
- ... ){
-
- va_list va;
- int ret;
-
- assert(s);
- assert(type);
- assert(name);
-
- va_start(va, port);
- ret = avahi_server_add_service_va(s, g, interface, protocol, name, type, domain, host, port, va);
- va_end(va);
- return ret;
-}
-
-static void hexstring(char *s, size_t sl, const void *p, size_t pl) {
- static const char hex[] = "0123456789abcdef";
- int b = 0;
- const uint8_t *k = p;
-
- while (sl > 1 && pl > 0) {
- *(s++) = hex[(b ? *k : *k >> 4) & 0xF];
-
- if (b) {
- k++;
- pl--;
- }