X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-daemon%2Fstatic-services.c;h=36f1608b7556accffe72f4dd9ca860a3a12ad3db;hb=7b7a022127d14b3a83d042c2aa52c76ec90554d2;hp=f6aa193f55558c208554114e2e2772216d399bc4;hpb=af548e38c2c282132ddac2a75a76218ff3be3175;p=catta diff --git a/avahi-daemon/static-services.c b/avahi-daemon/static-services.c index f6aa193..36f1608 100644 --- a/avahi-daemon/static-services.c +++ b/avahi-daemon/static-services.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "main.h" #include "static-services.h" @@ -201,14 +202,15 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) { /* 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); @@ -219,7 +221,8 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) { if (avahi_server_add_service_strlst( avahi_server, g->entry_group, - -1, s->protocol, + AVAHI_IF_UNSPEC, s->protocol, + s->host_name ? AVAHI_PUBLISH_IS_PROXY : 0, g->chosen_name, s->type, s->domain_name, s->host_name, s->port, s->txt_records) < 0) { @@ -250,7 +253,6 @@ typedef enum { XML_TAG_DOMAIN_NAME, XML_TAG_HOST_NAME, XML_TAG_PORT, - XML_TAG_PROTOCOL, XML_TAG_TXT_RECORD } xml_tag_name; @@ -284,19 +286,41 @@ static void XMLCALL xml_start(void *data, const char *el, const char *attr[]) { u->group->replace_wildcards = strcmp(attr[1], "yes") == 0; else goto invalid_attr; - } - if (attr[2]) - goto invalid_attr; + if (attr[2]) + goto invalid_attr; + } } else if (u->current_tag == XML_TAG_SERVICE_GROUP && strcmp(el, "service") == 0) { - if (attr[0]) - goto invalid_attr; + u->current_tag = XML_TAG_SERVICE; assert(!u->service); u->service = static_service_new(u->group); - u->current_tag = XML_TAG_SERVICE; + if (attr[0]) { + if (strcmp(attr[0], "protocol") == 0) { + AvahiProtocol protocol; + + if (strcmp(attr[1], "ipv4") == 0) { + protocol = AVAHI_PROTO_INET; + } else if (strcmp(attr[1], "ipv6") == 0) { + protocol = AVAHI_PROTO_INET6; + } else if (strcmp(attr[1], "any") == 0) { + protocol = AVAHI_PROTO_UNSPEC; + } else { + avahi_log_error("%s: parse failure: invalid protocol specification \"%s\".", u->group->filename, attr[1]); + u->failed = 1; + return; + } + + u->service->protocol = protocol; + } else + goto invalid_attr; + + if (attr[2]) + goto invalid_attr; + } + } else if (u->current_tag == XML_TAG_SERVICE && strcmp(el, "type") == 0) { if (attr[0]) goto invalid_attr; @@ -317,11 +341,6 @@ 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; @@ -393,27 +412,6 @@ 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); @@ -483,7 +481,6 @@ 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); @@ -590,7 +587,7 @@ static void load_file(char *n) { if (strcmp(g->filename, n) == 0) return; - avahi_log_info("Loading service file %s", n); + avahi_log_info("Loading service file %s.", n); g = static_service_group_new(n); if (static_service_group_load(g) < 0) {