X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-daemon%2Fstatic-services.c;h=03824fde497b04511de758302a7ed47a3ee0bb07;hb=b789f76475170c84fce85383279aa8f683ad1ff9;hp=89e81227e03de549034cacf13587ea868a31de8d;hpb=d7a2e63033dd0d2d248b4cab7bf35e78f4049354;p=catta diff --git a/avahi-daemon/static-services.c b/avahi-daemon/static-services.c index 89e8122..03824fd 100644 --- a/avahi-daemon/static-services.c +++ b/avahi-daemon/static-services.c @@ -34,9 +34,11 @@ #include #include -#include +#include +#include #include "main.h" +#include "static-services.h" typedef struct StaticService StaticService; typedef struct StaticServiceGroup StaticServiceGroup; @@ -61,7 +63,7 @@ struct StaticServiceGroup { gchar *name, *chosen_name; gboolean replace_wildcards; - AvahiEntryGroup *entry_group; + AvahiSEntryGroup *entry_group; AVAHI_LLIST_HEAD(StaticService, services); AVAHI_LLIST_FIELDS(StaticServiceGroup, groups); }; @@ -150,7 +152,8 @@ static void static_service_free(StaticService *s) { static void static_service_group_free(StaticServiceGroup *g) { g_assert(g); - remove_static_service_group_from_server(g); + if (g->entry_group) + avahi_s_entry_group_free(g->entry_group); while (g->services) static_service_free(g->services); @@ -163,7 +166,7 @@ static void static_service_group_free(StaticServiceGroup *g) { g_free(g); } -static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *eg, AvahiEntryGroupState state, gpointer userdata) { +static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *eg, AvahiEntryGroupState state, gpointer userdata) { StaticServiceGroup *g = userdata; g_assert(s); @@ -178,11 +181,11 @@ static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *eg, AvahiEntry g_free(g->chosen_name); g->chosen_name = n; - g_message("Service name conflict for \"%s\" (%s), retrying with \"%s\".", g->name, g->filename, g->chosen_name); + avahi_log_notice("Service name conflict for \"%s\" (%s), retrying with \"%s\".", g->name, g->filename, g->chosen_name); add_static_service_group_to_server(g); - } else - g_message("Service \"%s\" (%s) successfully establised.", g->chosen_name, g->filename); + } else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED) + avahi_log_info("Service \"%s\" (%s) successfully established.", g->chosen_name, g->filename); } static void add_static_service_group_to_server(StaticServiceGroup *g) { @@ -190,9 +193,6 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) { g_assert(g); - if (g->entry_group) - return; - if (g->chosen_name) g_free(g->chosen_name); @@ -200,8 +200,11 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) { g->chosen_name = replacestr(g->name, "%h", avahi_server_get_host_name(avahi_server)); else g->chosen_name = g_strdup(g->name); - - g->entry_group = avahi_entry_group_new(avahi_server, entry_group_callback, g); + + if (!g->entry_group) + g->entry_group = avahi_s_entry_group_new(avahi_server, entry_group_callback, g); + + g_assert(avahi_s_entry_group_is_empty(g->entry_group)); for (s = g->services; s; s = s->services_next) { @@ -209,25 +212,25 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) { avahi_server, g->entry_group, -1, AF_UNSPEC, - s->type, g->chosen_name, + g->chosen_name, s->type, s->domain_name, s->host_name, s->port, s->txt_records) < 0) { - g_message("Failed to add service '%s' of type '%s', ignoring service group (%s)", g->chosen_name, s->type, g->filename); + avahi_log_error("Failed to add service '%s' of type '%s', ignoring service group (%s): %s", + g->chosen_name, s->type, g->filename, + avahi_strerror(avahi_server_errno(avahi_server))); remove_static_service_group_from_server(g); return; } } - avahi_entry_group_commit(g->entry_group); + avahi_s_entry_group_commit(g->entry_group); } static void remove_static_service_group_from_server(StaticServiceGroup *g) { g_assert(g); - if (g->entry_group) { - avahi_entry_group_free(g->entry_group); - g->entry_group = NULL; - } + if (g->entry_group) + avahi_s_entry_group_reset(g->entry_group); } typedef enum { @@ -313,14 +316,14 @@ static void XMLCALL xml_start(void *data, const char *el, const char *attr[]) { u->current_tag = XML_TAG_TXT_RECORD; } else { - g_message("%s: parse failure: didn't expect element <%s>.", u->group->filename, el); + avahi_log_error("%s: parse failure: didn't expect element <%s>.", u->group->filename, el); u->failed = TRUE; } return; invalid_attr: - g_message("%s: parse failure: invalid attribute for element <%s>.", u->group->filename, el); + avahi_log_error("%s: parse failure: invalid attribute for element <%s>.", u->group->filename, el); u->failed = TRUE; return; } @@ -336,7 +339,7 @@ static void XMLCALL xml_end(void *data, const char *el) { case XML_TAG_SERVICE_GROUP: if (!u->group->name || !u->group->services) { - g_message("%s: parse failure: service group incomplete.", u->group->filename); + avahi_log_error("%s: parse failure: service group incomplete.", u->group->filename); u->failed = TRUE; return; } @@ -346,8 +349,8 @@ static void XMLCALL xml_end(void *data, const char *el) { case XML_TAG_SERVICE: - if (u->service->port == 0 || !u->service->type) { - g_message("%s: parse failure: service incomplete.", u->group->filename); + if (!u->service->type) { + avahi_log_error("%s: parse failure: service incomplete.", u->group->filename); u->failed = TRUE; return; } @@ -366,8 +369,8 @@ static void XMLCALL xml_end(void *data, const char *el) { p = u->buf ? atoi(u->buf) : 0; - if (p <= 0 || p > 0xFFFF) { - g_message("%s: parse failure: invalid port specification \"%s\".", u->group->filename, u->buf); + if (p < 0 || p > 0xFFFF) { + avahi_log_error("%s: parse failure: invalid port specification \"%s\".", u->group->filename, u->buf); u->failed = TRUE; return; } @@ -484,17 +487,17 @@ static gint static_service_group_load(StaticServiceGroup *g) { g->replace_wildcards = FALSE; if (!(parser = XML_ParserCreate(NULL))) { - g_warning("XML_ParserCreate() failed."); + avahi_log_error("XML_ParserCreate() failed."); goto finish; } if ((fd = open(g->filename, O_RDONLY)) < 0) { - g_warning("open(\"%s\", O_RDONLY): %s", g->filename, strerror(errno)); + avahi_log_error("open(\"%s\", O_RDONLY): %s", g->filename, strerror(errno)); goto finish; } if (fstat(fd, &st) < 0) { - g_warning("fstat(): %s", strerror(errno)); + avahi_log_error("fstat(): %s", strerror(errno)); goto finish; } @@ -511,17 +514,17 @@ static gint static_service_group_load(StaticServiceGroup *g) { #define BUFSIZE (10*1024) if (!(buffer = XML_GetBuffer(parser, BUFSIZE))) { - g_warning("XML_GetBuffer() failed."); + avahi_log_error("XML_GetBuffer() failed."); goto finish; } if ((n = read(fd, buffer, BUFSIZE)) < 0) { - g_warning("read(): %s\n", strerror(errno)); + avahi_log_error("read(): %s\n", strerror(errno)); goto finish; } if (!XML_ParseBuffer(parser, n, n == 0)) { - g_warning("XML_ParseBuffer() failed at line %d: %s.\n", XML_GetCurrentLineNumber(parser), XML_ErrorString(XML_GetErrorCode(parser))); + avahi_log_error("XML_ParseBuffer() failed at line %d: %s.\n", XML_GetCurrentLineNumber(parser), XML_ErrorString(XML_GetErrorCode(parser))); goto finish; } @@ -551,9 +554,11 @@ static void load_file(gchar *n) { if (strcmp(g->filename, n) == 0) return; + avahi_log_info("Loading service file %s", n); + g = static_service_group_new(n); if (static_service_group_load(g) < 0) { - g_warning("Failed to load service group file %s, ignoring.", g->filename); + avahi_log_error("Failed to load service group file %s, ignoring.", g->filename); static_service_group_free(g); } } @@ -571,24 +576,24 @@ void static_service_load(void) { if (stat(g->filename, &st) < 0) { if (errno == ENOENT) - g_message("Service group file %s vanished, removing seervices.", g->filename); + avahi_log_info("Service group file %s vanished, removing services.", g->filename); else - g_warning("Failed to stat() file %s, ignoring: %s", g->filename, strerror(errno)); + avahi_log_warn("Failed to stat() file %s, ignoring: %s", g->filename, strerror(errno)); static_service_group_free(g); } else if (st.st_mtime != g->mtime) { - g_message("Service group file %s changed, reloading.", g->filename); + avahi_log_info("Service group file %s changed, reloading.", g->filename); if (static_service_group_load(g) < 0) { - g_warning("Failed to load service group file %s, removing service.", g->filename); + avahi_log_warn("Failed to load service group file %s, removing service.", g->filename); static_service_group_free(g); } } } memset(&globbuf, 0, sizeof(globbuf)); - if (glob(AVAHI_SERVICE_DIRECTORY "/*.service", GLOB_ERR, NULL, &globbuf) != 0) - g_warning("glob() failed.\n"); + if (glob(AVAHI_SERVICE_DIR "/*.service", GLOB_ERR, NULL, &globbuf) != 0) + avahi_log_error("Failed to read service directory."); else { for (p = globbuf.gl_pathv; *p; p++) load_file(*p);