/* Try to register the TiVo DNS SRV service type. */ static void register_stuff(void) { assert(ctx.client); if (!ctx.group) { ctx.group = avahi_entry_group_new(ctx.client, publish_reply, NULL); if (!ctx.group) { DPRINTF(E_ERROR, L_SSDP, "Failed to create entry group: %s\n", avahi_strerror(avahi_client_errno(ctx.client))); return; } } if (avahi_entry_group_is_empty(ctx.group)) { if (_add_svc("Music", "_tivo-music._tcp", "1", NULL) < 0) return; if (_add_svc("Photos", "_tivo-photos._tcp", "3", NULL) < 0) return; if (_add_svc("Videos", "_tivo-videostream._tcp", "2", "platform=pc/"SERVER_NAME) < 0) return; if (avahi_entry_group_commit(ctx.group) < 0) { DPRINTF(E_ERROR, L_SSDP, "Failed to commit entry group: %s\n", avahi_strerror(avahi_client_errno(ctx.client))); return; } } }
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) { switch (state) { case AVAHI_CLIENT_S_RUNNING: { static AvahiEntryGroup *group = NULL; if (!group) { avahi_entry_group_new(c, entry_group_callback, &group); } if (avahi_entry_group_is_empty(group)) { printf("Adding service '%s'\n", name); avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_http._tcp", NULL, NULL, 8080, NULL); avahi_entry_group_commit(group); } break; } case AVAHI_CLIENT_FAILURE: { break; } case AVAHI_CLIENT_S_COLLISION: { break; } case AVAHI_CLIENT_S_REGISTERING: { break; } case AVAHI_CLIENT_CONNECTING: { break; } } }
JNIEXPORT jint JNICALL Java_avahi4j_EntryGroup_is_1group_1empty(JNIEnv *e, jobject t, jlong ptr){ dprint("[LOG] Entering %s\n", __PRETTY_FUNCTION__); struct avahi4j_entry_group *group = (struct avahi4j_entry_group *) (uintptr_t) ptr; int result = avahi_entry_group_is_empty(group->group); CHECK_N_RET(avahi_entry_group_is_empty, result); }
void Publisher::createServices(AvahiClient *client) { int error; const char* name = info.getServiceName().c_str(); int port = info.getPort(); if (group == NULL) { group = avahi_entry_group_new(client, &Publisher::entryGroupCallback, this); if (group == NULL) { std::cerr << "Could not create avahi group (" << avahi_strerror(avahi_client_errno(client)) << ")." << std::endl; return; } } if (avahi_entry_group_is_empty(group)) { // new group or after reset error = avahi_entry_group_add_service(group, // group AVAHI_IF_UNSPEC, // interface AVAHI_PROTO_UNSPEC, // protocol to announce service with AVAHI_PUBLISH_USE_MULTICAST, // flags name, // service name serviceType, // service type NULL, // domain NULL, // host port, // port txtDataDeviceName.c_str(), txtDataProviderClassName.c_str(), txtDataSerialNumber.c_str(), NULL); // list of txt records if (error < 0) { // error if (error == AVAHI_ERR_COLLISION) { // collision with local service name nextName(); avahi_entry_group_reset(group); // retry createServices(client); } else { std::cerr << "Could not add service '" << name << "' (" << serviceType << ") to avahi group (" << avahi_strerror(error) << ")" << std::endl; return; } } // start registering the service error = avahi_entry_group_commit(group); if (error < 0) { std::cerr << "Could not commit avahi group " << "'" << name << "'" << " (" << avahi_strerror(error) << ")" << std::endl; } } }
static void create_cnames(AvahiClient *c) { struct runtime_data r; /* If this is the first time we're called, let's create a new entry group if necessary */ if ((!_group)&&(!(_group = avahi_entry_group_new(c, entry_group_callback, NULL)))) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r.main_server, "avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(c))); goto fail; } /* If the group is empty (either because it was just created, or because it was reset previously, add our entries. */ if (avahi_entry_group_is_empty(_group)) { char hostname[HOST_NAME_MAX+64] = "."; /* this dot will be overwritten with a count-byte, below */ if (gethostname(&hostname[1], sizeof(hostname)-1) < 0) perror("gethostname"); strncat(hostname, ".local", sizeof(hostname)); hostname[sizeof(hostname)-1] = '\0'; /* paranoia? */ /* Convert the hostname string into DNS's labelled-strings format */ int hostnameLen = strlen(hostname); char count = 0; int i; for (i=hostnameLen-1; i>=0; i--) { if (hostname[i] == '.') { hostname[i] = count; count = 0; } else count++; } for (i=0; (_cnames[i] != NULL); i++) { int ret = avahi_entry_group_add_record(_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)(AVAHI_PUBLISH_USE_MULTICAST|AVAHI_PUBLISH_ALLOW_MULTIPLE), _cnames[i], AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_CNAME, AVAHI_DEFAULT_TTL, hostname, hostnameLen+1); if (ret >= 0) ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r.main_server, "Published DNS-SD hostname alias [%s]", _cnames[i]); else { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r.main_server, "Failed to add CNAME record [%s]: %s", _cnames[i], avahi_strerror(ret)); goto fail; } } int ret = avahi_entry_group_commit(_group); if (ret < 0) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r.main_server, "Failed to commit entry group: %s", avahi_strerror(ret)); goto fail; } } return; fail: avahi_simple_poll_quit(_poll); }
void announcer::commit(AvahiEntryGroup *group) { assert(group != 0); if (!avahi_entry_group_is_empty(group)) { int rc = avahi_entry_group_commit(group); if (rc != AVAHI_OK) { handler(convert_error(rc)); } } }
void AvahiSession::CreateServices(AvahiClient* client) { int err; if (mGroup) { avahi_entry_group_reset(mGroup); } else { mGroup = avahi_entry_group_new(client, group_cb, this); if (!mGroup) { scprintf("Zeroconf: failed to create entry group: %s\n", avahi_strerror(avahi_client_errno(client))); return; } } mMutex.lock(); AvahiEntry* entry = mEntries; while (entry) { const char* type = SCRendezvousProtocolString(entry->mProto); err = avahi_entry_group_add_service( mGroup, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0, mServiceName, type, NULL, NULL, entry->mPort, NULL); if (err == AVAHI_ERR_COLLISION) { // BUG: shouldn't this actually be triggered in the entry // group callback? RenameService(); err = avahi_entry_group_add_service( mGroup, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0, mServiceName, type, NULL, NULL, entry->mPort, NULL); } if (err < 0) { scprintf("Zeroconf: failed to register service '%s': %s\n", mServiceName, avahi_strerror(err)); } entry = entry->mNext; } mMutex.unlock(); if (!avahi_entry_group_is_empty(mGroup)) { err = avahi_entry_group_commit(mGroup); if (err < 0) { scprintf("Zeroconf: failed to commit entry group: %s\n", avahi_strerror(err)); return; } } }
void create_services(AvahiClient *c) { char r[128]; int ret; assert(c); /* If this is the first time we're called, let's create a new * entry group if necessary */ if (!group) if (!(group = avahi_entry_group_new(c, entry_group_callback, NULL))) { std::cerr << "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)) << std::endl; } /* If the group is empty (either because it was just created, or * because it was reset previously, add our entries. */ if (avahi_entry_group_is_empty(group)) { std::cerr << "Adding service '" << name << "'" << std::endl; /* Create some random TXT data */ snprintf(r, sizeof(r), "random=%i", rand()); /* We will now add two services and one subtype to the entry * group. The two services have the same name, but differ in * the service type (IPP vs. BSD LPR). Only services with the * same name should be put in the same entry group. */ if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0, name.c_str(), "_heatSync._tcp", NULL, NULL, PORTINT, "version=0.1", NULL, NULL )) < 0) { //todo: magically put in version no. if (ret == AVAHI_ERR_COLLISION) { name = avahi_alternative_service_name(name.c_str()); std::cerr << "Service name collision, renaming service to '" << name << "'" << std::endl; avahi_entry_group_reset(group); create_services(c); return; } std::cerr << "Failed to add " << name << " service: " << avahi_strerror(ret) << std::endl; } /* Tell the server to register the service */ if ((ret = avahi_entry_group_commit(group)) < 0) { std::cerr << "Failed to commit entry group: " << avahi_strerror(ret) << std::endl; } } avahi_simple_poll_quit(simple_publish_poll); }
void CZeroconfAvahi::addService(tServiceMap::mapped_type fp_service_info, AvahiClient* fp_client) { assert(fp_client); CLog::Log(LOGDEBUG, "CZeroconfAvahi::addService() named: %s type: %s port:%i", fp_service_info->m_name.c_str(), fp_service_info->m_type.c_str(), fp_service_info->m_port); //create the group if it doesn't exist if (!fp_service_info->mp_group) { if (!(fp_service_info->mp_group = avahi_entry_group_new(fp_client, &CZeroconfAvahi::groupCallback, this))) { CLog::Log(LOGDEBUG, "CZeroconfAvahi::addService() avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(fp_client))); fp_service_info->mp_group = 0; return; } } // add entries to the group if it's empty int ret; if (avahi_entry_group_is_empty(fp_service_info->mp_group)) { if ((ret = avahi_entry_group_add_service_strlst(fp_service_info->mp_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), fp_service_info->m_name.c_str(), fp_service_info->m_type.c_str(), NULL, NULL, fp_service_info->m_port, fp_service_info->mp_txt) < 0)) { if (ret == AVAHI_ERR_COLLISION) { char* alt_name = avahi_alternative_service_name(fp_service_info->m_name.c_str()); fp_service_info->m_name = alt_name; avahi_free(alt_name); CLog::Log(LOGNOTICE, "CZeroconfAvahi::addService: Service name collision. Renamed to: %s", fp_service_info->m_name.c_str()); addService(fp_service_info, fp_client); return; } CLog::Log(LOGERROR, "CZeroconfAvahi::addService(): failed to add service named:%s@$(HOSTNAME) type:%s port:%i. Error:%s :/ FIXME!", fp_service_info->m_name.c_str(), fp_service_info->m_type.c_str(), fp_service_info->m_port, avahi_strerror(ret)); return; } } // Tell the server to register the service if ((ret = avahi_entry_group_commit(fp_service_info->mp_group)) < 0) { CLog::Log(LOGERROR, "CZeroconfAvahi::addService(): Failed to commit entry group! Error:%s", avahi_strerror(ret)); // TODO what now? reset the group? free it? } }
static void register_service(AvahiClient *c) { debug(1, "avahi: register_service."); if (!group) group = avahi_entry_group_new(c, egroup_callback, NULL); if (!group) debug(2, "avahi: avahi_entry_group_new failed"); else { if (!avahi_entry_group_is_empty(group)) return; int ret; AvahiIfIndex selected_interface; if (config.interface != NULL) selected_interface = config.interface_index; else selected_interface = AVAHI_IF_UNSPEC; #ifdef CONFIG_METADATA if (config.metadata_enabled) { ret = avahi_entry_group_add_service(group, selected_interface, AVAHI_PROTO_UNSPEC, 0, service_name, config.regtype, NULL, NULL, port, MDNS_RECORD_WITH_METADATA, NULL); if (ret == 0) debug(1, "avahi: request to add \"%s\" service with metadata", config.regtype); } else { #endif ret = avahi_entry_group_add_service(group, selected_interface, AVAHI_PROTO_UNSPEC, 0, service_name, config.regtype, NULL, NULL, port, MDNS_RECORD_WITHOUT_METADATA, NULL); if (ret == 0) debug(1, "avahi: request to add \"%s\" service without metadata", config.regtype); #ifdef CONFIG_METADATA } #endif if (ret < 0) debug(1, "avahi: avahi_entry_group_add_service failed"); else { ret = avahi_entry_group_commit(group); if (ret < 0) debug(1, "avahi: avahi_entry_group_commit failed"); } } }
static int register_stuff(Config *config) { assert(config); if (!entry_group) { if (!(entry_group = avahi_entry_group_new(client, entry_group_callback, config))) { fprintf(stderr, "Failed to create entry group: %s\n", avahi_strerror(avahi_client_errno(client))); return -1; } } assert(avahi_entry_group_is_empty(entry_group)); if (config->command == COMMAND_PUBLISH_ADDRESS) { if (avahi_entry_group_add_address(entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, config->name, &config->address) < 0) { fprintf(stderr, "Failed to add address: %s\n", avahi_strerror(avahi_client_errno(client))); return -1; } } else { AvahiStringList *i; assert(config->command == COMMAND_PUBLISH_SERVICE); if (avahi_entry_group_add_service_strlst(entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, config->name, config->stype, config->domain, config->host, config->port, config->txt) < 0) { fprintf(stderr, "Failed to add service: %s\n", avahi_strerror(avahi_client_errno(client))); return -1; } for (i = config->subtypes; i; i = i->next) if (avahi_entry_group_add_service_subtype(entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, config->name, config->stype, config->domain, (char*) i->text) < 0) { fprintf(stderr, "Failed to add subtype '%s': %s\n", i->text, avahi_strerror(avahi_client_errno(client))); return -1; } } avahi_entry_group_commit(entry_group); return 0; }
int Trick::Zeroconf::init() { #ifdef HAVE_ZEROCONF #if __linux int error; int ret ; char r[128] ; if (!(simple_poll = avahi_simple_poll_new())) { fprintf(stderr, "Failed to create simple poll object.\n"); return -1 ; } client = avahi_client_new(avahi_simple_poll_get(simple_poll), (AvahiClientFlags)0, NULL, NULL, &error); if ( client != NULL ) { group = avahi_entry_group_new(client, entry_group_callback, (void *)name.c_str()) ; if (avahi_entry_group_is_empty(group)) { ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0, name.c_str(), type.c_str(), NULL, NULL, var_server_get_port(), NULL, r, NULL) ; ret = avahi_entry_group_commit(group) ; } } #endif #if __APPLE__ DNSServiceErrorType error ; error = DNSServiceRegister(&dns_service_ref, 0, 0, name.c_str(), type.c_str(), NULL, NULL, htons(var_server_get_port()), 0, NULL, // txt record stuff NULL, NULL); // callback stuff #endif #endif return 0 ; }
/* * This function tries to register the AFP DNS * SRV service type. */ static void register_stuff(void) { uint port; const struct vol *volume; DSI *dsi; char name[MAXINSTANCENAMELEN+1]; AvahiStringList *strlist = NULL; AvahiStringList *strlist2 = NULL; char tmpname[256]; assert(ctx->client); if (!ctx->group) { if (!(ctx->group = avahi_entry_group_new(ctx->client, publish_reply, ctx))) { LOG(log_error, logtype_afpd, "Failed to create entry group: %s", avahi_strerror(avahi_client_errno(ctx->client))); goto fail; } } if (avahi_entry_group_is_empty(ctx->group)) { /* Register our service */ /* Build AFP volumes list */ int i = 0; strlist = avahi_string_list_add_printf(strlist, "sys=waMa=0,adVF=0x100"); for (volume = getvolumes(); volume; volume = volume->v_next) { if (convert_string(CH_UCS2, CH_UTF8_MAC, volume->v_u8mname, -1, tmpname, 255) <= 0) { LOG ( log_error, logtype_afpd, "Could not set Zeroconf volume name for TimeMachine"); goto fail; } if (volume->v_flags & AFPVOL_TM) { if (volume->v_uuid) { LOG(log_info, logtype_afpd, "Registering volume '%s' with UUID: '%s' for TimeMachine", volume->v_localname, volume->v_uuid); strlist = avahi_string_list_add_printf(strlist, "dk%u=adVN=%s,adVF=0xa1,adVU=%s", i++, tmpname, volume->v_uuid); } else { LOG(log_warning, logtype_afpd, "Registering volume '%s' for TimeMachine. But UUID is invalid.", volume->v_localname); strlist = avahi_string_list_add_printf(strlist, "dk%u=adVN=%s,adVF=0xa1", i++, tmpname); } } } /* AFP server */ for (dsi = ctx->obj->dsi; dsi; dsi = dsi->next) { port = getip_port((struct sockaddr *)&dsi->server); LOG(log_info, logtype_afpd, "hostname: %s", ctx->obj->options.hostname); if (convert_string(ctx->obj->options.unixcharset, CH_UTF8, ctx->obj->options.hostname, -1, name, MAXINSTANCENAMELEN) <= 0) { LOG(log_error, logtype_afpd, "Could not set Zeroconf instance name: %s", ctx->obj->options.hostname); goto fail; } if ((dsi->bonjourname = strdup(name)) == NULL) { LOG(log_error, logtype_afpd, "Could not set Zeroconf instance name"); goto fail; } LOG(log_info, logtype_afpd, "Registering server '%s' with Bonjour", dsi->bonjourname); if (avahi_entry_group_add_service(ctx->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, dsi->bonjourname, AFP_DNS_SERVICE_TYPE, NULL, NULL, port, NULL) < 0) { LOG(log_error, logtype_afpd, "Failed to add service: %s", avahi_strerror(avahi_client_errno(ctx->client))); goto fail; } if (i && avahi_entry_group_add_service_strlst(ctx->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, dsi->bonjourname, ADISK_SERVICE_TYPE, NULL, NULL, 9, /* discard */ strlist) < 0) { LOG(log_error, logtype_afpd, "Failed to add service: %s", avahi_strerror(avahi_client_errno(ctx->client))); goto fail; } /* if */ if (ctx->obj->options.mimicmodel) { strlist2 = avahi_string_list_add_printf(strlist2, "model=%s", ctx->obj->options.mimicmodel); if (avahi_entry_group_add_service_strlst(ctx->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, dsi->bonjourname, DEV_INFO_SERVICE_TYPE, NULL, NULL, 0, strlist2) < 0) { LOG(log_error, logtype_afpd, "Failed to add service: %s", avahi_strerror(avahi_client_errno(ctx->client))); goto fail; } } /* if (config->obj.options.mimicmodel) */ } /* for config*/ if (avahi_entry_group_commit(ctx->group) < 0) { LOG(log_error, logtype_afpd, "Failed to commit entry group: %s", avahi_strerror(avahi_client_errno(ctx->client))); goto fail; } } /* if avahi_entry_group_is_empty*/ return; fail: time(NULL); // avahi_threaded_poll_quit(ctx->threaded_poll); }
void PublishAvahi::create_services(AvahiClient *c) { assert(c); char *n; /// If this is the first time we're called, let's create a new entry group if necessary if (!group) { if (!(group = avahi_entry_group_new(c, entry_group_callback, this))) { logE << "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)) << "\n"; goto fail; } } /// If the group is empty (either because it was just created, or because it was reset previously, add our entries. int ret; if (avahi_entry_group_is_empty(group)) { logO << "Adding service '" << name << "'\n"; /// We will now add two services and one subtype to the entry group for (const auto& service: services_) { if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), name, service.name_.c_str(), NULL, NULL, service.port_, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) goto collision; logE << "Failed to add " << service.name_ << " service: " << avahi_strerror(ret) << "\n"; goto fail; } } /// Add an additional (hypothetic) subtype /* if ((ret = avahi_entry_group_add_service_subtype(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), name, "_printer._tcp", NULL, "_magic._sub._printer._tcp") < 0)) { fprintf(stderr, "Failed to add subtype _magic._sub._printer._tcp: %s\n", avahi_strerror(ret)); goto fail; } */ /// Tell the server to register the service if ((ret = avahi_entry_group_commit(group)) < 0) { logE << "Failed to commit entry group: " << avahi_strerror(ret) << "\n"; goto fail; } } return; collision: /// A service name collision with a local service happened. Let's pick a new name n = avahi_alternative_service_name(name); avahi_free(name); name = n; logO << "Service name collision, renaming service to '" << name << "'\n"; avahi_entry_group_reset(group); create_services(c); return; fail: avahi_simple_poll_quit(simple_poll); }
static void create_service (AurAvahi * avahi) { AurAvahiPrivate *priv = avahi->priv; int ret; do { if (priv->group == NULL) { priv->group = avahi_entry_group_new (priv->client, entry_group_callback, avahi); if (priv->group == NULL) { g_critical ("avahi_entry_group_new() failed: %s\n", avahi_strerror (avahi_client_errno (priv->client))); goto fail; } } /* If the group is empty (either because it was just created, or * because it was reset previously, add our entries. */ if (avahi_entry_group_is_empty (priv->group)) { g_message ("Adding service '%s' on port %d", priv->service_name, priv->port); ret = avahi_entry_group_add_service (priv->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, priv->service_name, "_aurena._tcp", NULL, NULL, priv->port, NULL); if (ret < 0) { if (ret == AVAHI_ERR_COLLISION) { /* A service name collision with a local service happened. Let's * pick a new name */ char *n = avahi_alternative_service_name (priv->service_name); g_free (priv->service_name); priv->service_name = n; g_message ("Service name collision, renaming service to '%s'\n", priv->service_name); avahi_entry_group_reset (priv->group); continue; } else { g_critical ("Failed to add _aurena._tcp service: %s", avahi_strerror (ret)); goto fail; } } #if 0 /* Add an additional (hypothetic) subtype */ if ((ret = avahi_entry_group_add_service_subtype (group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_printer._tcp", NULL, "_magic._sub._printer._tcp") < 0)) { fprintf (stderr, "Failed to add subtype _magic._sub._printer._tcp: %s\n", avahi_strerror (ret)); goto fail; } #endif if ((ret = avahi_entry_group_commit (priv->group)) < 0) { g_critical ("Failed to commit entry group: %s\n", avahi_strerror (ret)); } } return; } while (TRUE); fail: return; }
static void register_stuff(struct context *ctx) { if (!ctx->group) { if (!(ctx->group = avahi_entry_group_new(ctx->client, publish_reply, ctx))) { rs_log_crit("Failed to create entry group: %s", avahi_strerror(avahi_client_errno(ctx->client))); goto fail; } } if (avahi_entry_group_is_empty(ctx->group)) { char cpus[32] = ""; char machine[64] = "cc_machine=", version[64] = "cc_version="; char *m = NULL, *v = NULL; if (ctx->advertise_capabilities) { snprintf(cpus, sizeof(cpus), "cpus=%i", ctx->n_cpus); v = dcc_get_gcc_version(version+11, sizeof(version)-11); m = dcc_get_gcc_machine(machine+11, sizeof(machine)-11); } /* Register our service */ if (avahi_entry_group_add_service( ctx->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, ctx->name, ctx->service_type, NULL, NULL, ctx->port, !ctx->advertise_capabilities ? NULL : "txtvers=1", cpus, "distcc="PACKAGE_VERSION, "gnuhost="GNU_HOST, v ? version : NULL, m ? machine : NULL, NULL) < 0) { rs_log_crit("Failed to add service: %s", avahi_strerror(avahi_client_errno(ctx->client))); goto fail; } if (ctx->advertise_capabilities) { if (v && m) { char stype[128]; dcc_make_dnssd_subtype(stype, sizeof(stype), v, m); if (avahi_entry_group_add_service_subtype( ctx->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, ctx->name, ctx->service_type, NULL, stype) < 0) { rs_log_crit("Failed to add service: %s", avahi_strerror(avahi_client_errno(ctx->client))); goto fail; } } else rs_log_warning("Failed to determine CC version, not registering DNS-SD service subtype!"); } if (avahi_entry_group_commit(ctx->group) < 0) { rs_log_crit("Failed to commit entry group: %s", avahi_strerror(avahi_client_errno(ctx->client))); goto fail; } } return; fail: avahi_threaded_poll_quit(ctx->threaded_poll); }
static void create_services(AvahiClient *c) { char *n; char *path = NULL; int ret; assert(c); /* If this is the first time we're called, let's create a new * entry group if necessary */ if (!group) if (!(group = avahi_entry_group_new(c, entry_group_callback, NULL))) { tvhlog(LOG_ERR, "AVAHI", "avahi_enty_group_new() failed: %s", avahi_strerror(avahi_client_errno(c))); goto fail; } /* If the group is empty (either because it was just created, or * because it was reset previously, add our entries. */ if (avahi_entry_group_is_empty(group)) { tvhlog(LOG_DEBUG, "AVAHI", "Adding service '%s'", name); /* Add the service for HTSP */ if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_htsp._tcp", NULL, NULL,tvheadend_htsp_port, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) goto collision; tvhlog(LOG_ERR, "AVAHI", "Failed to add _htsp._tcp service: %s", avahi_strerror(ret)); goto fail; } if (tvheadend_webroot) { path = malloc(strlen(tvheadend_webroot) + 6); sprintf(path, "path=%s", tvheadend_webroot); } else { path = strdup("path=/"); } /* Add the service for HTTP */ if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_http._tcp", NULL, NULL, tvheadend_webui_port, path, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) goto collision; tvhlog(LOG_ERR, "AVAHI", "Failed to add _http._tcp service: %s", avahi_strerror(ret)); goto fail; } /* Tell the server to register the service */ if ((ret = avahi_entry_group_commit(group)) < 0) { tvhlog(LOG_ERR, "AVAHI", "Failed to commit entry group: %s", avahi_strerror(ret)); goto fail; } } free(path); return; collision: /* A service name collision with a local service happened. Let's * pick a new name */ n = avahi_alternative_service_name(name); avahi_free(name); name = n; tvhlog(LOG_ERR, "AVAHI", "Service name collision, renaming service to '%s'", name); avahi_entry_group_reset(group); create_services(c); return; fail: free(path); }
static void create_services(AvahiClient *c) { char *n, r[128]; int ret; assert(c); /* If this is the first time we're called, let's create a new * entry group if necessary */ if (!group) if (!(group = avahi_entry_group_new(c, entry_group_callback, NULL))) { fprintf(stderr, "avahi_entry_group_new() failed: %s\n", avahi_strerror(avahi_client_errno(c))); goto fail; } /* If the group is empty (either because it was just created, or * because it was reset previously, add our entries. */ if (avahi_entry_group_is_empty(group)) { fprintf(stderr, "Adding service '%s'\n", name); /* Create some random TXT data */ snprintf(r, sizeof(r), "random=%i", rand()); /* We will now add two services and one subtype to the entry * group. The two services have the same name, but differ in * the service type (IPP vs. BSD LPR). Only services with the * same name should be put in the same entry group. */ /* Add the service for IPP */ if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_ipp._tcp", NULL, NULL, 651, "test=blah", r, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) goto collision; fprintf(stderr, "Failed to add _ipp._tcp service: %s\n", avahi_strerror(ret)); goto fail; } /* Add the same service for BSD LPR */ if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_printer._tcp", NULL, NULL, 515, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) goto collision; fprintf(stderr, "Failed to add _printer._tcp service: %s\n", avahi_strerror(ret)); goto fail; } /* Add an additional (hypothetic) subtype */ if ((ret = avahi_entry_group_add_service_subtype(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_printer._tcp", NULL, "_magic._sub._printer._tcp") < 0)) { fprintf(stderr, "Failed to add subtype _magic._sub._printer._tcp: %s\n", avahi_strerror(ret)); goto fail; } /* Tell the server to register the service */ if ((ret = avahi_entry_group_commit(group)) < 0) { fprintf(stderr, "Failed to commit entry group: %s\n", avahi_strerror(ret)); goto fail; } } return; collision: /* A service name collision with a local service happened. Let's * pick a new name */ n = avahi_alternative_service_name(name); avahi_free(name); name = n; fprintf(stderr, "Service name collision, renaming service to '%s'\n", name); avahi_entry_group_reset(group); create_services(c); return; fail: avahi_simple_poll_quit(simple_poll); }
void CommunicationManager::createServices(AvahiClient *c) { char *n, r[128]; int ret; /* If this is the first time we're called, let's create a new * entry group if necessary */ if (!this->group) { if (!(group = avahi_entry_group_new(c, CommunicationManager::entryGroupCallback, NULL))) { cout << "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)) << endl; avahi_simple_poll_quit(simplePoll); return; } } /* If the group is empty (either because it was just created, or * because it was reset previously, add our entries. */ if (avahi_entry_group_is_empty(group)) { cout << "Adding service '" << name << "'" << endl;; /* Create some random TXT data */ snprintf(r, sizeof(r), "random=%i", rand()); /* We will now add two services and one subtype to the entry * group. The two services have the same name, but differ in * the service type (IPP vs. BSD LPR). Only services with the * same name should be put in the same entry group. */ /* Add the service for GingaMultimodalEvent*/ if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0, name, "_GingaMultimodalEvent._tcp", NULL, NULL, 1234, "test=blah", r, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) { /* A service name collision with a local service happened. * Let's pick a new name */ n = avahi_alternative_service_name(name); avahi_free(name); name = n; cout << "Service name collision, renaming service to '" << name << "'" << endl; avahi_entry_group_reset(group); createServices(c); return; } cout << "Failed to add _GingaMultimodalEvent._tcp service: " << avahi_strerror(ret) << endl; avahi_simple_poll_quit(simplePoll); return; } /* Tell the server to register the service */ if ((ret = avahi_entry_group_commit(group)) < 0) { cout << "Failed to commit entry group: " << avahi_strerror(ret) << endl; avahi_simple_poll_quit(simplePoll); } } }
static void create_services(AvahiClient *c) { char *n, r[128]; int ret; AvahiProtocol protocol; assert(c); /* If this is the first time we're called, let's create a new * entry group if necessary */ if (!group) if (!(group = avahi_entry_group_new(c, entry_group_callback, NULL))) { logging_printf( LOGGING_ERROR, "avahi_entry_group_new() failed: %s\n", avahi_strerror(avahi_client_errno(c))); goto fail; } /* If the group is empty (either because it was just created, or * because it was reset previously, add our entries. */ if (avahi_entry_group_is_empty(group)) { logging_printf(LOGGING_INFO, "Adding service '%s.%s'\n", sd_name_copy, sd_service_copy ); /* Create some random TXT data */ snprintf(r, sizeof(r), "random=%i", rand()); if( use_ipv4 && use_ipv6 ) { protocol = AVAHI_PROTO_UNSPEC; } else if( use_ipv4 ) { protocol = AVAHI_PROTO_INET; } else { protocol = AVAHI_PROTO_INET6; } if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, protocol, 0, sd_name_copy , sd_service_copy , NULL, NULL, sd_port, "test=blah", r, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) goto collision; logging_printf(LOGGING_ERROR, "Failed to add %s service: %s\n", sd_service_copy,avahi_strerror(ret)); goto fail; } /* Tell the server to register the service */ if ((ret = avahi_entry_group_commit(group)) < 0) { logging_printf(LOGGING_ERROR, "Failed to commit entry group: %s\n", avahi_strerror(ret)); goto fail; } } return; collision: /* A service name collision with a local service happened. Let's * pick a new name */ n = avahi_alternative_service_name( sd_name_copy ); avahi_free(sd_name_copy); sd_name_copy = n; logging_printf(LOGGING_WARN, "Service name collision, renaming service to '%s'\n", sd_name_copy ); avahi_entry_group_reset(group); create_services(c); return; fail: avahi_threaded_poll_quit(threaded_poll); }
void create_services(AvahiClient *c) { char *n; gchar *type_txt, *profile_txt, *data_txt; int ret; assert(c); /* If this is the first time we're called, let's create a new * entry group if necessary */ if (!group) if (!(group = avahi_entry_group_new(c, entry_group_callback, NULL))) { l_debug("avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(c))); goto fail; } /* If the group is empty (either because it was just created, or * because it was reset previously, add our entries. */ if (avahi_entry_group_is_empty(group)) { l_debug("Adding service '%s' type '%s'", name, type_in); /* Set type of service */ profile_txt = g_strdup_printf("profile=%s", profile); type_txt = g_strdup_printf("type=%s", type_in); if (extra_data == NULL) { extra_data = g_strdup(""); } data_txt = g_strdup_printf("data=%s", extra_data); /* Add the service for Lyricue Display */ if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_lyricue._tcp", NULL, NULL, port, type_txt, profile_txt, data_txt, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) goto collision; l_debug("Failed to add _lyricue._tcp service: %s", avahi_strerror(ret)); goto fail; } g_free(profile_txt); g_free(type_txt); g_free(data_txt); /* Tell the server to register the service */ if ((ret = avahi_entry_group_commit(group)) < 0) { l_debug("Failed to commit entry group: %s", avahi_strerror(ret)); goto fail; } } return; collision: /* A service name collision with a local service happened. Let's * pick a new name */ n = avahi_alternative_service_name(name); avahi_free(name); name = n; l_debug("Service name collision, renaming service to '%s'", name); avahi_entry_group_reset(group); create_services(c); return; fail: avahi_simple_poll_quit(simple_poll); }
static void create_service(struct service_data *j) { apr_pool_t *t; const char *n; char *p; struct runtime_data *r = j->runtime; char **type, **txt_record; AvahiStringList *strlist = NULL; if (!j->group) if (!(j->group = avahi_entry_group_new(r->client, service_callback, j))) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->main_server, "avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(r->client))); return; } ap_assert(j->group); ap_assert(avahi_entry_group_is_empty(j->group)); apr_pool_create(&t, r->pool); /* ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->main_server, "Service <%s>, host <%s>, port <%u>, location <%s>", j->name, j->host_name, j->port, j->location); */ if (j->chosen_name) n = j->chosen_name; else if (!j->name) n = avahi_client_get_host_name(r->client); else if (j->append_host_name) n = apr_pstrcat(t, j->name, avahi_client_get_host_name(r->client), NULL); else n = j->name; if (!j->pool) apr_pool_create(&j->pool, r->pool); if (n != j->chosen_name) { apr_pool_clear(j->pool); j->chosen_name = apr_pstrdup(j->pool, n); } p = j->location ? apr_pstrcat(t, "path=", j->location, NULL) : NULL; /* ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->main_server, "%s, %s", p, n); */ txt_record = (char **) j->txt_record->elts; for ( ; *txt_record ; txt_record++) strlist = avahi_string_list_add(strlist, *txt_record); if (p) strlist = avahi_string_list_add(strlist, p); if (apr_is_empty_array(j->types)) { if (avahi_entry_group_add_service_strlst( j->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, n, j->port == 443 ? "_https._tcp" : "_http._tcp", NULL, j->host_name, j->port, strlist) < 0) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->main_server, "avahi_entry_group_add_service_strlst(\"%s\") failed: %s", n, avahi_strerror(avahi_client_errno(r->client))); } const char * cnames = {j->host_name, NULL}; PublishAvahiCNames(cnames); } else { for (type = (char**) j->types->elts; *type; type++) { if (avahi_entry_group_add_service_strlst( j->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, n, *type, NULL, j->host_name, j->port, strlist) < 0) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->main_server, "avahi_entry_group_add_service_strlst(\"%s\") failed: %s", n, avahi_strerror(avahi_client_errno(r->client))); } const char * cnames = {j->host_name, NULL}; PublishAvahiCNames(cnames); } } avahi_string_list_free(strlist); if (avahi_entry_group_is_empty(j->group)) { avahi_entry_group_free(j->group); j->group = NULL; } else avahi_entry_group_commit(j->group); apr_pool_destroy(t); }