static void print_service_line(Config *config, char c, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, int nl) { char ifname[IF_NAMESIZE]; #if defined(HAVE_GDBM) || defined(HAVE_DBM) if (!config->no_db_lookup) type = stdb_lookup(type); #endif if (config->parsable) { char sn[AVAHI_DOMAIN_NAME_MAX], *e = sn; size_t l = sizeof(sn); printf("%c;%s;%s;%s;%s;%s%s", c, interface != AVAHI_IF_UNSPEC ? if_indextoname(interface, ifname) : ("n/a"), protocol != AVAHI_PROTO_UNSPEC ? avahi_proto_to_string(protocol) : ("n/a"), avahi_escape_label(name, strlen(name), &e, &l), type, domain, nl ? "\n" : ""); } else { char label[AVAHI_LABEL_MAX]; make_printable(name, label); printf("%c %6s %4s %-*s %-20s %s\n", c, interface != AVAHI_IF_UNSPEC ? if_indextoname(interface, ifname) : ("n/a"), protocol != AVAHI_PROTO_UNSPEC ? avahi_proto_to_string(protocol) : ("n/a"), n_columns-35, label, type, domain); } fflush(stdout); }
static void domain_browser_callback( AvahiDomainBrowser *b, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiBrowserEvent event, const char *domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void *userdata) { Config *c = userdata; assert(b); assert(c); switch (event) { case AVAHI_BROWSER_NEW: case AVAHI_BROWSER_REMOVE: { char ifname[IF_NAMESIZE]; if (c->parsable) printf("%c;%s;%s;%s\n", event == AVAHI_BROWSER_NEW ? '+' : '-', interface != AVAHI_IF_UNSPEC ? if_indextoname(interface, ifname) : "", protocol != AVAHI_PROTO_UNSPEC ? avahi_proto_to_string(protocol) : "", domain); else printf("%c %4s %4s %s\n", event == AVAHI_BROWSER_NEW ? '+' : '-', interface != AVAHI_IF_UNSPEC ? if_indextoname(interface, ifname) : "n/a", protocol != AVAHI_PROTO_UNSPEC ? avahi_proto_to_string(protocol) : "n/a", domain); break; } case AVAHI_BROWSER_FAILURE: fprintf(stderr, ("domain_browser failed: %s\n"), avahi_strerror(avahi_client_errno(client))); avahi_simple_poll_quit(simple_poll); break; case AVAHI_BROWSER_CACHE_EXHAUSTED: n_cache_exhausted --; check_terminate(c); break; case AVAHI_BROWSER_ALL_FOR_NOW: n_all_for_now --; check_terminate(c); break; } }
static void service_browser_callback( AVAHI_GCC_UNUSED AvahiSServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *service_name, const char *service_type, const char *domain_name, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, AVAHI_GCC_UNUSED void* userdata) { if (event == AVAHI_BROWSER_NEW) { struct Service *s; GtkTreeIter iter, piter; GtkTreePath *path, *ppath; gchar iface[256]; char name[IF_NAMESIZE]; s = g_new(struct Service, 1); s->service_name = g_strdup(service_name); s->domain_name = g_strdup(domain_name); s->interface = interface; s->protocol = protocol; s->service_type = g_hash_table_lookup(service_type_hash_table, service_type); g_assert(s->service_type); s->service_type->services = g_list_prepend(s->service_type->services, s); ppath = gtk_tree_row_reference_get_path(s->service_type->tree_ref); gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store), &piter, ppath); snprintf(iface, sizeof(iface), "%s %s", if_indextoname(interface, name), avahi_proto_to_string(protocol)); gtk_tree_store_append(tree_store, &iter, &piter); gtk_tree_store_set(tree_store, &iter, 0, s->service_name, 1, iface, 2, s, -1); path = gtk_tree_model_get_path(GTK_TREE_MODEL(tree_store), &iter); s->tree_ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(tree_store), path); gtk_tree_path_free(path); gtk_tree_view_expand_row(tree_view, ppath, FALSE); gtk_tree_path_free(ppath); } else if (event == AVAHI_BROWSER_REMOVE) {
std::string ServiceDescription::getProtocolString() const { return std::string( avahi_proto_to_string(protocol_) ); }
bool cAvahiServicesConfig::Parse(const char *s) { Clear(); _line = s; const char *tmp = skipspace(s); if ((tmp != NULL) && (tmp[0] != '#')) { cAvahiHelper options(tmp); _name = options.Get("name"); tmp = options.Get("protocol"); if (tmp != NULL) { if (strcmp(tmp, avahi_proto_to_string(AVAHI_PROTO_INET)) == 0) _protocol = AVAHI_PROTO_INET; else if (strcmp(tmp, avahi_proto_to_string(AVAHI_PROTO_INET6)) == 0) _protocol = AVAHI_PROTO_INET6; } _type = options.Get("type"); tmp = options.Get("port"); if ((tmp != NULL) && isnumber(tmp)) _port = atoi(tmp); int tmp_nr = 0; while (true) { tmp = options.Get("subtype", tmp_nr); if (tmp == NULL) break; _subtypes.Append(strdup(tmp)); tmp_nr++; } tmp_nr = 0; while (true) { tmp = options.Get("txt", tmp_nr); if (tmp == NULL) break; _txts.Append(strdup(tmp)); tmp_nr++; } _is_valid = true; if (*_name == NULL) { esyslog("avahi4vdr/services.conf: missing name at line '%s'", s); _is_valid = false; } else { if (strstr(*_name, "%h") != NULL) { char hostname[HOST_NAME_MAX]; if (gethostname(hostname, HOST_NAME_MAX) == 0) { char *n = strreplace(strdup(*_name), "%h", hostname); _name = n; free(n); } } } if (*_type == NULL) { esyslog("avahi4vdr/services.conf: missing type at line '%s'", s); _is_valid = false; } if (_port <= 0) { esyslog("avahi4vdr/services.conf: missing port at line '%s'", s); _is_valid = false; } } return true; }