X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-daemon%2Fstatic-services.c;h=e402a9853de94b07c70118e340b5d25554718282;hb=298a8cdb7b369d80a1d8bad2bd315d2a38c5a38f;hp=c155c22df6b157e51fec7030177fd8ab28b24a4f;hpb=7ada090e70d25937d27b2e93b0dab4d9d68c5d23;p=catta diff --git a/avahi-daemon/static-services.c b/avahi-daemon/static-services.c index c155c22..e402a98 100644 --- a/avahi-daemon/static-services.c +++ b/avahi-daemon/static-services.c @@ -35,6 +35,8 @@ #include #include +#include +#include #include #include "main.h" @@ -50,6 +52,7 @@ struct StaticService { char *domain_name; char *host_name; uint16_t port; + int protocol; AvahiStringList *txt_records; @@ -110,6 +113,7 @@ static StaticService *static_service_new(StaticServiceGroup *group) { s->type = s->host_name = s->domain_name = NULL; s->port = 0; + s->protocol = AVAHI_PROTO_UNSPEC; s->txt_records = NULL; @@ -192,15 +196,20 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) { StaticService *s; assert(g); + + if (g->entry_group && !avahi_s_entry_group_is_empty(g->entry_group)) + /* This service group is already registered in the server */ + return; - if (g->chosen_name) - avahi_free(g->chosen_name); - - if (g->replace_wildcards) - g->chosen_name = replacestr(g->name, "%h", avahi_server_get_host_name(avahi_server)); - else - g->chosen_name = avahi_strdup(g->name); + if (!g->chosen_name) { + + if (g->replace_wildcards) + g->chosen_name = replacestr(g->name, "%h", avahi_server_get_host_name(avahi_server)); + else + g->chosen_name = avahi_strdup(g->name); + } + if (!g->entry_group) g->entry_group = avahi_s_entry_group_new(avahi_server, entry_group_callback, g); @@ -211,7 +220,7 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) { if (avahi_server_add_service_strlst( avahi_server, g->entry_group, - -1, AF_UNSPEC, + -1, s->protocol, g->chosen_name, s->type, s->domain_name, s->host_name, s->port, s->txt_records) < 0) { @@ -242,6 +251,7 @@ typedef enum { XML_TAG_DOMAIN_NAME, XML_TAG_HOST_NAME, XML_TAG_PORT, + XML_TAG_PROTOCOL, XML_TAG_TXT_RECORD } xml_tag_name; @@ -308,6 +318,11 @@ static void XMLCALL xml_start(void *data, const char *el, const char *attr[]) { goto invalid_attr; u->current_tag = XML_TAG_PORT; + } else if (u->current_tag == XML_TAG_SERVICE && strcmp(el, "protocol") == 0) { + if (attr[0]) + goto invalid_attr; + + u->current_tag = XML_TAG_PROTOCOL; } else if (u->current_tag == XML_TAG_SERVICE && strcmp(el, "txt-record") == 0) { if (attr[0]) goto invalid_attr; @@ -379,6 +394,27 @@ static void XMLCALL xml_end(void *data, const char *el) { break; } + case XML_TAG_PROTOCOL: { + int protocol; + assert(u->service); + + if (u->buf && strcasecmp (u->buf, "ipv4") == 0) { + protocol = AVAHI_PROTO_INET; + } else if (u->buf && strcasecmp (u->buf, "ipv6") == 0) { + protocol = AVAHI_PROTO_INET6; + } else if (u->buf && strcasecmp (u->buf, "any") == 0) { + protocol = AVAHI_PROTO_UNSPEC; + } else { + avahi_log_error("%s: parse failure: invalid protocol specification \"%s\".", u->group->filename, u->buf); + u->failed = 1; + return; + } + + u->service->protocol = protocol; + u->current_tag = XML_TAG_SERVICE; + break; + } + case XML_TAG_TXT_RECORD: { assert(u->service); @@ -448,7 +484,9 @@ static void XMLCALL xml_cdata(void *data, const XML_Char *s, int len) { break; case XML_TAG_PORT: + case XML_TAG_PROTOCOL: case XML_TAG_TXT_RECORD: + assert(u->service); u->buf = append_cdata(u->buf, s, len); break;