static void avahi_client_init (DMAPMdnsBrowser * browser) { gint error = 0; avahi_set_allocator (avahi_glib_allocator ()); browser->priv->poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); if (!browser->priv->poll) { g_debug ("Unable to create AvahiGlibPoll object for mDNS"); } #ifdef HAVE_AVAHI_0_5 browser->priv->client = avahi_client_new (avahi_glib_poll_get (browser->priv->poll), (AvahiClientCallback) client_cb, browser, &error); #endif #ifdef HAVE_AVAHI_0_6 { AvahiClientFlags flags = 0; browser->priv->client = avahi_client_new (avahi_glib_poll_get (browser->priv->poll), flags, (AvahiClientCallback) client_cb, browser, &error); } #endif }
void avahi_register_game(Game * game) { #ifdef HAVE_AVAHI const AvahiPoll *poll_api; int error; glib_poll = avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT); poll_api = avahi_glib_poll_get(glib_poll); /* Allocate main loop object */ if (!poll_api) { log_message(MSG_ERROR, _("Avahi error: %s, %s\n"), _("Unable to register Avahi server"), "Failed to create glib poll object"); avahi_unregister_game(); return; } name = avahi_strdup(game->params->title); /* Allocate a new client */ client = avahi_client_new(poll_api, 0, client_callback, game, &error); /* Check whether creating the client object succeeded */ if (!client) { log_message(MSG_ERROR, _("Avahi error: %s, %s\n"), _("Unable to register Avahi server"), avahi_strerror(error)); avahi_unregister_game(); } #endif // HAVE_AVAHI }
void Publisher::doStart() { int error; // create poll object poller = avahi_threaded_poll_new(); if (poller == NULL) { std::cerr << "Could not create avahi threaded poll object." << std::endl; return; } // create client client = avahi_client_new( avahi_threaded_poll_get(poller), AVAHI_CLIENT_NO_FAIL, &Publisher::clientCallback, this, &error); if (client == NULL) { std::cerr << "Failed to create avahi client (" << avahi_strerror(error) << ")" << std::endl; return; } error = avahi_threaded_poll_start(poller); if (error < 0) { std::cerr << "Error starting avahi threaded poll (" << avahi_strerror(error) << ")" << std::endl; } else { running = true; } }
AvahiSession::AvahiSession() : mPoll(0), mClient(0), mGroup(0), mEntries(0), mServiceName(0) { int err; mServiceName = avahi_strdup(kSCRendezvousServiceName); mPoll = avahi_threaded_poll_new(); if (!mPoll) { scprintf("Zeroconf: failed to create poll API\n"); return; } mClient = avahi_client_new( avahi_threaded_poll_get(mPoll), (AvahiClientFlags)0, client_cb, this, &err); if (!mClient) { scprintf("Zeroconf: failed to create client: %s\n", avahi_strerror(err)); avahi_threaded_poll_free(mPoll); mPoll = 0; return; } avahi_threaded_poll_start(mPoll); }
static AvahiClient* epc_shell_get_avahi_client (GError **error) { g_return_val_if_fail (NULL != epc_shell_avahi_client || NULL != error, NULL); if (G_UNLIKELY (NULL == epc_shell_avahi_client)) { gint error_code = AVAHI_OK; epc_shell_init (); epc_shell_avahi_client = avahi_client_new (avahi_glib_poll_get (epc_shell_avahi_poll), AVAHI_CLIENT_NO_FAIL, epc_shell_avahi_client_cb, NULL, &error_code); if (NULL == epc_shell_avahi_client) g_set_error (error, EPC_AVAHI_ERROR, error_code, _("Cannot create Avahi client: %s"), avahi_strerror (error_code)); } return epc_shell_avahi_client; }
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) { AvahiSimplePoll *simple_poll; const AvahiPoll *poll_api; AvahiClient *client; AvahiRecordBrowser *r; simple_poll = avahi_simple_poll_new(); assert(simple_poll); poll_api = avahi_simple_poll_get(simple_poll); assert(poll_api); client = avahi_client_new(poll_api, 0, NULL, NULL, NULL); assert(client); r = avahi_record_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "ecstasy.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO, 0, callback, simple_poll); assert(r); avahi_simple_poll_loop(simple_poll); avahi_client_free(client); avahi_simple_poll_free(simple_poll); return 0; }
gboolean _mdns_init_session(BonjourDnsSd *data) { AvahiSessionImplData *idata = g_new0(AvahiSessionImplData, 1); const AvahiPoll *poll_api; int error; /* Tell avahi to use g_malloc and g_free */ avahi_set_allocator (avahi_glib_allocator ()); /* This currently depends on the glib mainloop, * we should make it use the libpurple abstraction */ idata->glib_poll = avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT); poll_api = avahi_glib_poll_get(idata->glib_poll); idata->client = avahi_client_new(poll_api, 0, NULL, data, &error); if (idata->client == NULL) { purple_debug_error("bonjour", "Error initializing Avahi: %s", avahi_strerror(error)); avahi_glib_poll_free(idata->glib_poll); g_free(idata); return FALSE; } data->mdns_impl_data = idata; return TRUE; }
/* * Tries to setup the Zeroconf thread and any * neccessary config setting. */ void tivo_bonjour_register(void) { int error; /* first of all we need to initialize our threading env */ ctx.threaded_poll = avahi_threaded_poll_new(); if (!ctx.threaded_poll) return; /* now we need to acquire a client */ ctx.client = avahi_client_new(avahi_threaded_poll_get(ctx.threaded_poll), AVAHI_CLIENT_NO_FAIL, client_callback, NULL, &error); if (!ctx.client) { DPRINTF(E_ERROR, L_SSDP, "Failed to create client object: %s\n", avahi_strerror(error)); tivo_bonjour_unregister(); return; } if (avahi_threaded_poll_start(ctx.threaded_poll) < 0) { DPRINTF(E_ERROR, L_SSDP, "Failed to create thread: %s\n", avahi_strerror(avahi_client_errno(ctx.client))); tivo_bonjour_unregister(); } else DPRINTF(E_INFO, L_SSDP, "Successfully started avahi loop\n"); }
static int avahi_register(char *srvname, int srvport) { debug(1, "avahi: avahi_register."); name = strdup(srvname); port = srvport; int err; if (!(tpoll = avahi_threaded_poll_new())) { warn("couldn't create avahi threaded tpoll!"); return -1; } if (!(client = avahi_client_new(avahi_threaded_poll_get(tpoll), 0, client_callback, NULL, &err))) { warn("couldn't create avahi client: %s!", avahi_strerror(err)); return -1; } // we need this to detect the IPv6 number we're advertising... // if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, config.regtype, NULL, 0, browse_callback, client))) { // warn("Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); // return -1; // } if (avahi_threaded_poll_start(tpoll) < 0) { warn("couldn't start avahi tpoll thread"); return -1; } return 0; }
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) { struct mdns_browser *mb; AvahiServiceBrowser *b; int error; switch (state) { case AVAHI_CLIENT_S_RUNNING: DPRINTF(E_LOG, L_MDNS, "Avahi state change: Client running\n"); if (!mdns_group) create_all_group_entries(); for (mb = browser_list; mb; mb = mb->next) { b = avahi_service_browser_new(mdns_client, AVAHI_IF_UNSPEC, mb->protocol, mb->type, NULL, 0, browse_callback, mb); if (!b) DPRINTF(E_LOG, L_MDNS, "Failed to recreate service browser (service type %s): %s\n", mb->type, MDNSERR); } break; case AVAHI_CLIENT_S_COLLISION: DPRINTF(E_LOG, L_MDNS, "Avahi state change: Client collision\n"); if(mdns_group) avahi_entry_group_reset(mdns_group); break; case AVAHI_CLIENT_FAILURE: DPRINTF(E_LOG, L_MDNS, "Avahi state change: Client failure\n"); error = avahi_client_errno(c); if (error == AVAHI_ERR_DISCONNECTED) { DPRINTF(E_LOG, L_MDNS, "Avahi Server disconnected, reconnecting\n"); avahi_client_free(mdns_client); mdns_group = NULL; mdns_client = avahi_client_new(&ev_poll_api, AVAHI_CLIENT_NO_FAIL, client_callback, NULL, &error); if (!mdns_client) DPRINTF(E_LOG, L_MDNS, "Failed to create new Avahi client: %s\n", avahi_strerror(error)); } else { DPRINTF(E_LOG, L_MDNS, "Avahi client failure: %s\n", avahi_strerror(error)); } break; case AVAHI_CLIENT_S_REGISTERING: DPRINTF(E_LOG, L_MDNS, "Avahi state change: Client registering\n"); if (mdns_group) avahi_entry_group_reset(mdns_group); break; case AVAHI_CLIENT_CONNECTING: DPRINTF(E_LOG, L_MDNS, "Avahi state change: Client connecting\n"); break; } }
/** * ssd: The BastileServiceDiscovery to init * * When compiled WITH_SHARING avahi will also be initialised and it will browse * for avahi services. **/ static void bastile_service_discovery_init (BastileServiceDiscovery *ssd) { ssd->priv = g_new0 (BastileServiceDiscoveryPriv, 1); ssd->services = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); #ifdef WITH_SHARING { int aerr; ssd->priv->client = avahi_client_new (bastile_util_dns_sd_get_poll (), 0, client_callback, ssd, &aerr); if (!ssd->priv->client) { g_warning ("DNS-SD initialization failed: %s", avahi_strerror (aerr)); return; } ssd->priv->browser = avahi_service_browser_new (ssd->priv->client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, HKP_SERVICE_TYPE, NULL, 0, browse_callback, ssd); if (!ssd->priv->browser) { g_warning ("Browsing for DNS-SD services failed: %s", avahi_strerror (avahi_client_errno (ssd->priv->client))); return; } } #endif /* WITH_SHARING */ }
int dns_service_publisher_start( dns_service_desc_t *service_desc ) { int ret = 0; int error; if( ! service_desc ) return 1; if( ! (threaded_poll = avahi_threaded_poll_new() ) ) { logging_printf(LOGGING_ERROR, "Unable to create publisher thread\n"); return 1; } sd_name_copy = avahi_strdup( service_desc->name ); sd_service_copy = avahi_strdup( service_desc->service ); sd_port = service_desc->port; use_ipv4 = service_desc->publish_ipv4; use_ipv6 = service_desc->publish_ipv6; client = avahi_client_new(avahi_threaded_poll_get(threaded_poll), 0, client_callback, NULL, &error); if (! client) { logging_printf(LOGGING_ERROR, "Failed to create client: %s\n", avahi_strerror(error)); return 1; } avahi_threaded_poll_start( threaded_poll ); return ret; }
AvahiClient * rb_daap_mdns_avahi_get_client (void) { if (g_once_init_enter (&client_init)) { AvahiClientFlags flags = 0; AvahiGLibPoll *apoll; int error = 0; avahi_set_allocator (avahi_glib_allocator ()); apoll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); if (apoll == NULL) { g_warning ("Unable to create AvahiGlibPoll object for mDNS"); } client = avahi_client_new (avahi_glib_poll_get (apoll), flags, (AvahiClientCallback) client_cb, NULL, &error); if (error != 0) { g_warning ("Unable to initialize mDNS: %s", avahi_strerror (error)); } g_once_init_leave (&client_init, 1); } return client; }
static void search_for_server (SnraClient * client) { const AvahiPoll *poll_api; int error; if (client->glib_poll == NULL) { client->glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); if (client->glib_poll == NULL) return; } poll_api = avahi_glib_poll_get (client->glib_poll); if (client->avahi_client == NULL) { client->avahi_client = avahi_client_new (poll_api, AVAHI_CLIENT_NO_FAIL, (AvahiClientCallback) snra_avahi_client_callback, client, &error); if (client->avahi_client == NULL) { fprintf (stderr, "Failed to connect to Avahi: %s", avahi_strerror (error)); return; } } }
void serverDNSSDInit(void) { #ifdef HAVE_DNSSD if (DNSServiceCreateConnection(&DNSSDMaster) != kDNSServiceErr_NoError) { fputs("Error: Unable to initialize Bonjour.\n", stderr); exit(1); } #elif defined(HAVE_AVAHI) int error; /* Error code, if any */ if ((DNSSDMaster = avahi_threaded_poll_new()) == NULL) { fputs("Error: Unable to initialize Bonjour.\n", stderr); exit(1); } if ((DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssd_client_cb, NULL, &error)) == NULL) { fputs("Error: Unable to initialize Bonjour.\n", stderr); exit(1); } avahi_threaded_poll_start(DNSSDMaster); #endif /* HAVE_DNSSD */ }
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) { AvahiSimplePoll *simple_poll; const AvahiPoll *poll_api; AvahiClient *client; AvahiServiceResolver *r; simple_poll = avahi_simple_poll_new(); assert(simple_poll); poll_api = avahi_simple_poll_get(simple_poll); assert(poll_api); client = avahi_client_new(poll_api, 0, NULL, NULL, NULL); assert(client); r = avahi_service_resolver_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, "_domain._udp", "0pointer.de", AVAHI_PROTO_UNSPEC, AVAHI_LOOKUP_NO_TXT, callback, simple_poll); assert(r); avahi_simple_poll_loop(simple_poll); avahi_client_free(client); avahi_simple_poll_free(simple_poll); return 0; }
void Avahi::Heap::load () { const AvahiPoll *poll_api = NULL; int error; /* let's make sure those are sanely initialized */ poll = NULL; client = NULL; resolver = NULL; avahi_set_allocator (avahi_glib_allocator ()); poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); poll_api = avahi_glib_poll_get (poll); /* this may not be the final valid client pointer according to * avahi's documentation... we'll take what our callback gets */ client = avahi_client_new (poll_api, (AvahiClientFlags)AVAHI_CLIENT_NO_FAIL, avahi_client_callback, this, &error); #if DEBUG if (client == NULL) std::cout << __PRETTY_FUNCTION__ << " client is NULL!" << std::endl; #endif }
void PublishAvahi::publish(const std::vector<AvahiService>& services) { this->services = services; AvahiClient *client = NULL; int error; /* Allocate main loop object */ if (!(simple_poll = avahi_simple_poll_new())) { logE << "Failed to create simple poll object.\n"; } /* Allocate a new client */ client = avahi_client_new(avahi_simple_poll_get(simple_poll), AVAHI_CLIENT_IGNORE_USER_CONFIG, client_callback, this, &error); /* Check wether creating the client object succeeded */ if (!client) { logE << "Failed to create client: " << avahi_strerror(error) << "\n"; } active_ = true; pollThread_ = std::thread(&PublishAvahi::worker, this); }
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) { Config *config = userdata; client = c; switch (state) { case AVAHI_CLIENT_FAILURE: if (config->no_fail && avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) { int error; /* We have been disconnected, so let reconnect */ fprintf(stderr, "Disconnected, reconnecting ...\n"); avahi_client_free(client); client = NULL; entry_group = NULL; if (!(client = avahi_client_new(avahi_simple_poll_get(simple_poll), AVAHI_CLIENT_NO_FAIL, client_callback, config, &error))) { fprintf(stderr, "Failed to create client object: %s\n", avahi_strerror(error)); avahi_simple_poll_quit(simple_poll); } } else { fprintf(stderr, "Client failure, exiting: %s\n", avahi_strerror(avahi_client_errno(c))); avahi_simple_poll_quit(simple_poll); } break; case AVAHI_CLIENT_S_RUNNING: if (register_stuff(config) < 0) avahi_simple_poll_quit(simple_poll); break; case AVAHI_CLIENT_S_COLLISION: if (config->verbose) fprintf(stderr, "Host name conflict\n"); if (entry_group) { avahi_entry_group_free(entry_group); entry_group = NULL; } break; case AVAHI_CLIENT_CONNECTING: if (config->verbose) fprintf(stderr, "Waiting for daemon ...\n"); break; case AVAHI_CLIENT_S_REGISTERING: ; } }
/***************************************************************************** * Open: initialize and create stuff *****************************************************************************/ static int Open( vlc_object_t *p_this ) { services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_sys_t *p_sys; int err; p_sd->p_sys = p_sys = calloc( 1, sizeof( services_discovery_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; p_sd->description = _("Zeroconf network services"); vlc_dictionary_init( &p_sys->services_name_to_input_item, 1 ); p_sys->poll = avahi_threaded_poll_new(); if( p_sys->poll == NULL ) { msg_Err( p_sd, "failed to create Avahi threaded poll" ); goto error; } p_sys->client = avahi_client_new( avahi_threaded_poll_get(p_sys->poll), 0, client_callback, p_sd, &err ); if( p_sys->client == NULL ) { msg_Err( p_sd, "failed to create avahi client: %s", avahi_strerror( err ) ); goto error; } for( unsigned i = 0; i < NB_PROTOCOLS; i++ ) { AvahiServiceBrowser *sb; sb = avahi_service_browser_new( p_sys->client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, protocols[i].psz_service_name, NULL, 0, browse_callback, p_sd ); if( sb == NULL ) { msg_Err( p_sd, "failed to create avahi service browser %s", avahi_strerror( avahi_client_errno(p_sys->client) ) ); goto error; } } avahi_threaded_poll_start( p_sys->poll ); return VLC_SUCCESS; error: if( p_sys->client != NULL ) avahi_client_free( p_sys->client ); if( p_sys->poll != NULL ) avahi_threaded_poll_free( p_sys->poll ); vlc_dictionary_clear( &p_sys->services_name_to_input_item, NULL, NULL ); free( p_sys ); return VLC_EGENERIC; }
void Avahi::PresencePublisher::create_client () { free_client (); // don't get the client there : wait what we'll get from the callback avahi_client_new (avahi_glib_poll_get (glib_poll), AVAHI_CLIENT_NO_FAIL, (AvahiClientCallback)client_cb, this, NULL); }
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) { Config *config = userdata; /* This function might be called when avahi_client_new() has not * returned yet.*/ client = c; switch (state) { case AVAHI_CLIENT_FAILURE: if (config->no_fail && avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) { int error; /* We have been disconnected, so let reconnect */ fprintf(stderr, ("Disconnected, reconnecting ...\n")); avahi_client_free(client); client = NULL; avahi_string_list_free(browsed_types); browsed_types = NULL; while (services) remove_service(config, services); browsing = 0; if (!(client = avahi_client_new(avahi_simple_poll_get(simple_poll), AVAHI_CLIENT_NO_FAIL, client_callback, config, &error))) { fprintf(stderr, ("Failed to create client object: %s\n"), avahi_strerror(error)); avahi_simple_poll_quit(simple_poll); } } else { fprintf(stderr, ("Client failure, exiting: %s\n"), avahi_strerror(avahi_client_errno(c))); avahi_simple_poll_quit(simple_poll); } break; case AVAHI_CLIENT_S_REGISTERING: case AVAHI_CLIENT_S_RUNNING: case AVAHI_CLIENT_S_COLLISION: if (!browsing) if (start(config) < 0) avahi_simple_poll_quit(simple_poll); break; case AVAHI_CLIENT_CONNECTING: if (config->verbose && !config->parsable) fprintf(stderr, ("Waiting for daemon ...\n")); break; } }
static void client_callback(AvahiClient *c, AvahiClientState state, void *userdata) { struct userdata *u = userdata; pa_assert(c); pa_assert(u); u->client = c; switch (state) { case AVAHI_CLIENT_S_REGISTERING: case AVAHI_CLIENT_S_RUNNING: case AVAHI_CLIENT_S_COLLISION: if (!u->sink_browser) { if (!(u->sink_browser = avahi_service_browser_new( c, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, SERVICE_TYPE_SINK, NULL, 0, browser_cb, u))) { pa_log("avahi_service_browser_new() failed: %s", avahi_strerror(avahi_client_errno(c))); pa_module_unload_request(u->module, true); } } break; case AVAHI_CLIENT_FAILURE: if (avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) { int error; pa_log_debug("Avahi daemon disconnected."); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { pa_log("avahi_client_new() failed: %s", avahi_strerror(error)); pa_module_unload_request(u->module, true); } } /* Fall through */ case AVAHI_CLIENT_CONNECTING: if (u->sink_browser) { avahi_service_browser_free(u->sink_browser); u->sink_browser = NULL; } break; default: ; } }
static void dnssd_client_cb(AvahiClient *c, /* I - Client */ AvahiClientState state, /* I - Current state */ void *userdata) /* I - User data (unused) */ { (void)userdata; int error; /* Error code, if any */ if (!c) return; switch (state) { default : NOTE("Ignore Avahi state %d.", state); break; case AVAHI_CLIENT_CONNECTING: NOTE("Waiting for Avahi server."); break; case AVAHI_CLIENT_S_RUNNING: NOTE("Avahi server connection got available, registering printer."); dnssd_register(c); break; case AVAHI_CLIENT_S_REGISTERING: case AVAHI_CLIENT_S_COLLISION: NOTE("Dropping printer registration because of possible host name change."); if (g_options.dnssd_data->ipp_ref) avahi_entry_group_reset(g_options.dnssd_data->ipp_ref); break; case AVAHI_CLIENT_FAILURE: if (avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) { NOTE("Avahi server disappeared, unregistering printer"); dnssd_unregister(); /* Renewing client */ if (g_options.dnssd_data->DNSSDClient) avahi_client_free(g_options.dnssd_data->DNSSDClient); if ((g_options.dnssd_data->DNSSDClient = avahi_client_new(avahi_threaded_poll_get (g_options.dnssd_data->DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssd_client_cb, NULL, &error)) == NULL) { ERR("Error: Unable to initialize DNS-SD client."); g_options.terminate = 1; } } else { ERR("Avahi server connection failure: %s", avahi_strerror(avahi_client_errno(c))); g_options.terminate = 1; } break; } }
static void client_callback(AvahiClient *client, AvahiClientState state, void *userdata) { ctx->client = client; switch (state) { case AVAHI_CLIENT_S_RUNNING: /* The server has startup successfully and registered its host * name on the network, so it's time to create our services */ if (!ctx->group) register_stuff(); break; case AVAHI_CLIENT_S_COLLISION: if (ctx->group) avahi_entry_group_reset(ctx->group); break; case AVAHI_CLIENT_FAILURE: { if (avahi_client_errno(client) == AVAHI_ERR_DISCONNECTED) { int error; avahi_client_free(ctx->client); ctx->client = NULL; ctx->group = NULL; /* Reconnect to the server */ if (!(ctx->client = avahi_client_new(avahi_threaded_poll_get(ctx->threaded_poll), AVAHI_CLIENT_NO_FAIL, client_callback, ctx, &error))) { LOG(log_error, logtype_afpd, "Failed to contact server: %s", avahi_strerror(error)); avahi_threaded_poll_quit(ctx->threaded_poll); } } else { LOG(log_error, logtype_afpd, "Client failure: %s", avahi_strerror(avahi_client_errno(client))); avahi_threaded_poll_quit(ctx->threaded_poll); } break; } case AVAHI_CLIENT_S_REGISTERING: break; case AVAHI_CLIENT_CONNECTING: break; } }
static void mdns_init_task(void *arg) { int error; mdns_client = avahi_client_new(&gcdpoll_api, AVAHI_CLIENT_NO_FAIL, client_callback, NULL, &error); if (!mdns_client) DPRINTF(E_WARN, L_MDNS, "mdns_init: Could not create Avahi client: %s\n", avahi_strerror(avahi_client_errno(mdns_client))); }
/***************************************************************************** * Open: initialize and create stuff *****************************************************************************/ static int Open( vlc_object_t *p_this ) { services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_sys_t *p_sys; int err; p_sd->p_sys = p_sys = calloc( 1, sizeof( services_discovery_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; vlc_dictionary_init( &p_sys->services_name_to_input_item, 1 ); p_sys->poll = avahi_threaded_poll_new(); if( p_sys->poll == NULL ) { msg_Err( p_sd, "failed to create Avahi threaded poll" ); goto error; } p_sys->client = avahi_client_new( avahi_threaded_poll_get(p_sys->poll), 0, client_callback, p_sd, &err ); if( p_sys->client == NULL ) { msg_Err( p_sd, "failed to create avahi client: %s", avahi_strerror( err ) ); goto error; } p_sys->sb = avahi_service_browser_new( p_sys->client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_vlc-http._tcp", NULL, 0, browse_callback, p_sd ); if( p_sys->sb == NULL ) { msg_Err( p_sd, "failed to create avahi service browser" ); goto error; } return VLC_SUCCESS; error: if( p_sys->sb != NULL ) avahi_service_browser_free( p_sys->sb ); if( p_sys->client != NULL ) avahi_client_free( p_sys->client ); if( p_sys->poll != NULL ) avahi_threaded_poll_free( p_sys->poll ); vlc_dictionary_clear( &p_sys->services_name_to_input_item, NULL, NULL ); free( p_sys ); return VLC_EGENERIC; }
static void client_callback(AvahiClient *client, AvahiClientState state, void *userdata) { struct context *ctx = userdata; ctx->client = client; switch (state) { case AVAHI_CLIENT_S_RUNNING: register_stuff(ctx); break; case AVAHI_CLIENT_S_COLLISION: case AVAHI_CLIENT_S_REGISTERING: if (ctx->group) avahi_entry_group_reset(ctx->group); break; case AVAHI_CLIENT_FAILURE: if (avahi_client_errno(client) == AVAHI_ERR_DISCONNECTED) { int error; avahi_client_free(ctx->client); ctx->client = NULL; ctx->group = NULL; /* Reconnect to the server */ if (!(ctx->client = avahi_client_new( avahi_threaded_poll_get(ctx->threaded_poll), AVAHI_CLIENT_NO_FAIL, client_callback, ctx, &error))) { rs_log_crit("Failed to contact server: %s", avahi_strerror(error)); avahi_threaded_poll_quit(ctx->threaded_poll); } } else { rs_log_crit("Client failure: %s", avahi_strerror(avahi_client_errno(client))); avahi_threaded_poll_quit(ctx->threaded_poll); } break; case AVAHI_CLIENT_CONNECTING: ; } }
bool CZeroconfAvahi::createClient() { if (mp_client) { avahi_client_free(mp_client); } mp_client = avahi_client_new(avahi_threaded_poll_get(mp_poll), AVAHI_CLIENT_NO_FAIL, &clientCallback,this,0); if (!mp_client) return false; return true; }
int pa__init(pa_module*m) { struct userdata *u; pa_modargs *ma = NULL; char *hn, *un; int error; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; u->module = m; u->native = pa_native_protocol_get(u->core); u->avahi_poll = pa_avahi_poll_new(m->core->mainloop); u->services = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); u->main_entry_group = NULL; un = pa_get_user_name_malloc(); hn = pa_get_host_name_malloc(); u->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s", un, hn), AVAHI_LABEL_MAX-1); pa_xfree(un); pa_xfree(hn); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { pa_log("avahi_client_new() failed: %s", avahi_strerror(error)); goto fail; } pa_modargs_free(ma); return 0; fail: pa__done(m); if (ma) pa_modargs_free(ma); return -1; }