static void dmap_mdns_browser_dispose (GObject * object) { DMAPMdnsBrowser *browser = DMAP_MDNS_BROWSER (object); GSList *walk; DMAPMdnsBrowserService *service; for (walk = browser->priv->services; walk; walk = walk->next) { service = (DMAPMdnsBrowserService *) walk->data; free_service (service); } g_slist_free (browser->priv->services); if (browser->priv->resolvers) { g_slist_foreach (browser->priv->resolvers, (GFunc) avahi_service_resolver_free, NULL); g_slist_free (browser->priv->resolvers); } if (browser->priv->service_browser) { avahi_service_browser_free (browser->priv->service_browser); } if (browser->priv->client) { avahi_client_free (browser->priv->client); } if (browser->priv->poll) { avahi_glib_poll_free (browser->priv->poll); } G_OBJECT_CLASS (dmap_mdns_browser_parent_class)->dispose (object); }
static void snra_client_finalize (GObject * object) { SnraClient *client = (SnraClient *) (object); if (client->avahi_sb) avahi_service_browser_free (client->avahi_sb); if (client->avahi_client) avahi_client_free (client->avahi_client); if (client->glib_poll) avahi_glib_poll_free (client->glib_poll); if (client->net_clock) gst_object_unref (client->net_clock); if (client->soup) g_object_unref (client->soup); if (client->json) g_object_unref (client->json); if (client->player) { GstBus *bus = gst_element_get_bus (client->player); gst_bus_remove_signal_watch (bus); gst_object_unref (bus); gst_object_unref (client->player); } g_free (client->server_host); g_free (client->connected_server); G_OBJECT_CLASS (snra_client_parent_class)->finalize (object); }
void AvahiBrowseQuery::stopBrowsing() { std::cout << "Stop browsing" << std::endl; avahi_threaded_poll_lock(querier->getThreadedPoll()); avahi_service_browser_free(browser); browser = NULL; avahi_threaded_poll_unlock(querier->getThreadedPoll()); }
static void browse_callback (AVAHI_GCC_UNUSED AvahiServiceBrowser * b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void *userdata) { SnraClient *client = userdata; switch (event) { case AVAHI_BROWSER_FAILURE: /* Respawn browser on a timer? */ avahi_service_browser_free (client->avahi_sb); client->timeout = g_timeout_add_seconds (1, (GSourceFunc) try_reconnect, client); return; case AVAHI_BROWSER_NEW:{ avahi_service_resolver_new (client->avahi_client, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, avahi_resolve_callback, client); break; } case AVAHI_BROWSER_REMOVE: case AVAHI_BROWSER_ALL_FOR_NOW: case AVAHI_BROWSER_CACHE_EXHAUSTED: break; } }
static void aur_client_finalize (GObject * object) { AurClient *client = (AurClient *) (object); #if HAVE_AVAHI if (client->avahi_sb) avahi_service_browser_free (client->avahi_sb); if (client->avahi_client) avahi_client_free (client->avahi_client); if (client->glib_poll) avahi_glib_poll_free (client->glib_poll); #endif if (client->net_clock) gst_object_unref (client->net_clock); if (client->soup) g_object_unref (client->soup); if (client->json) g_object_unref (client->json); if (client->player) { gst_object_unref (client->player); } if (client->context) g_main_context_unref (client->context); g_free (client->server_host); g_free (client->connected_server); g_free (client->uri); g_free (client->language); free_player_info (client->player_info); G_OBJECT_CLASS (aur_client_parent_class)->finalize (object); }
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: ; } }
/** * ssd: A BastileServiceDiscovery object * * Disconnects avahi * **/ static void disconnect (BastileServiceDiscovery *ssd) { if (ssd->priv->browser && ssd->priv->client) avahi_service_browser_free (ssd->priv->browser); ssd->priv->browser = NULL; if (ssd->priv->client) avahi_client_free (ssd->priv->client); ssd->priv->client = NULL; }
BrowseAvahi::~BrowseAvahi() { if (sb_) avahi_service_browser_free(sb_); if (client_) avahi_client_free(client_); if (simple_poll) avahi_simple_poll_free(simple_poll); }
/***************************************************************************** * 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; }
/***************************************************************************** * Close: cleanup *****************************************************************************/ static void Close( vlc_object_t *p_this ) { services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_sys_t *p_sys = p_sd->p_sys; avahi_service_browser_free( p_sys->sb ); avahi_client_free( p_sys->client ); avahi_threaded_poll_free( p_sys->poll ); vlc_dictionary_clear( &p_sys->services_name_to_input_item, NULL, NULL ); free( p_sys ); }
int avahi_discover_tvh(struct htsp_t* htsp) { AvahiClient *client = NULL; AvahiServiceBrowser *sb = NULL; int error; int ret = 1; /* Allocate main loop object */ if (!(simple_poll = avahi_simple_poll_new())) { fprintf(stderr, "Failed to create simple poll object.\n"); goto fail; } /* Allocate a new client */ client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error); /* Check wether creating the client object succeeded */ if (!client) { fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error)); goto fail; } /* Create the service browser */ if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET, "_htsp._tcp", NULL, 0, browse_callback, client))) { fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); goto fail; } /* Run the main loop */ avahi_simple_poll_loop(simple_poll); ret = 0; fail: /* Cleanup things */ if (sb) avahi_service_browser_free(sb); if (client) avahi_client_free(client); if (simple_poll) avahi_simple_poll_free(simple_poll); if (tvh_hostname) { htsp->host = tvh_hostname; htsp->ip = tvh_ip; htsp->port = tvh_port; } return ret; }
void BrowseAvahi::cleanUp() { if (sb_) avahi_service_browser_free(sb_); sb_ = NULL; if (client_) avahi_client_free(client_); client_ = NULL; if (simple_poll) avahi_simple_poll_free(simple_poll); simple_poll = NULL; }
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) { AvahiClient *client = NULL; AvahiRecordBrowser *sb = NULL; int error; int ret = 1; /* Allocate main loop object */ if (!(simple_poll = avahi_simple_poll_new())) { fprintf(stderr, "Failed to create simple poll object.\n"); goto fail; } /* Allocate a new client */ client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error); /* Check wether creating the client object succeeded */ if (!client) { fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error)); goto fail; } /* Create the service browser */ if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, 0, browse_callback, client))) { fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); goto fail; } /* Run the main loop */ avahi_simple_poll_loop(simple_poll); ret = 0; fail: /* Cleanup things */ if (sb) avahi_service_browser_free(sb); if (client) avahi_client_free(client); if (simple_poll) avahi_simple_poll_free(simple_poll); return ret; }
void e2avahi_resolve_cancel(const char* service_type, E2AvahiResolveCallback callback, void *userdata) { AvahiBrowserEntry entry(service_type, callback, userdata); AvahiBrowserEntryList::iterator it = std::find(avahi_browsers.begin(), avahi_browsers.end(), entry); if (it == avahi_browsers.end()) { eWarning("[Avahi] Cannot remove resolver for %s, not found", service_type); return; } if (it->browser) { avahi_service_browser_free(it->browser); it->browser = NULL; } avahi_browsers.erase(it); }
void _mdns_stop(BonjourDnsSd *data) { AvahiSessionImplData *idata = data->mdns_impl_data; if (idata == NULL || idata->client == NULL) return; if (idata->sb != NULL) avahi_service_browser_free(idata->sb); avahi_client_free(idata->client); avahi_glib_poll_free(idata->glib_poll); g_free(idata); data->mdns_impl_data = NULL; }
static int discover_host(AvahiAddress *addr, uint16_t *port) { struct avahi_discovery_data ddata; int ret = 0; AvahiClient *client; AvahiServiceBrowser *browser; AvahiSimplePoll *poll = avahi_simple_poll_new(); if (!poll) return -ENOMEM; client = avahi_client_new(avahi_simple_poll_get(poll), 0, NULL, NULL, &ret); if (!client) { ERROR("Unable to start ZeroConf client :%s\n", avahi_strerror(ret)); goto err_free_poll; } memset(&ddata, 0, sizeof(ddata)); ddata.poll = poll; ddata.address = addr; ddata.port = port; browser = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_iio._tcp", NULL, 0, __avahi_browser_cb, &ddata); if (!browser) { ret = avahi_client_errno(client); ERROR("Unable to create ZeroConf browser: %s\n", avahi_strerror(ret)); goto err_free_client; } DEBUG("Trying to discover host\n"); avahi_simple_poll_loop(poll); if (!ddata.found) ret = ENXIO; avahi_service_browser_free(browser); err_free_client: avahi_client_free(client); err_free_poll: avahi_simple_poll_free(poll); return -ret; /* we want a negative error code */ }
void avahi_client_free(AvahiClient *client) { assert(client); if (client->bus) /* Disconnect in advance, so that the free() functions won't * issue needless server calls */ #ifdef HAVE_DBUS_CONNECTION_CLOSE dbus_connection_close(client->bus); #else dbus_connection_disconnect(client->bus); #endif while (client->groups) avahi_entry_group_free(client->groups); while (client->domain_browsers) avahi_domain_browser_free(client->domain_browsers); while (client->service_browsers) avahi_service_browser_free(client->service_browsers); while (client->service_type_browsers) avahi_service_type_browser_free(client->service_type_browsers); while (client->service_resolvers) avahi_service_resolver_free(client->service_resolvers); while (client->host_name_resolvers) avahi_host_name_resolver_free(client->host_name_resolvers); while (client->address_resolvers) avahi_address_resolver_free(client->address_resolvers); while (client->record_browsers) avahi_record_browser_free(client->record_browsers); if (client->bus) dbus_connection_unref(client->bus); avahi_free(client->version_string); avahi_free(client->host_name); avahi_free(client->host_name_fqdn); avahi_free(client->domain_name); avahi_free(client); }
void avahi_dacp_dont_monitor(rtsp_conn_info *conn) { dacp_browser_struct *dbs = (dacp_browser_struct *)conn->mdns_private_pointer; if (dbs) { // stop and dispose of everything if ((dbs)->service_poll) avahi_threaded_poll_stop((dbs)->service_poll); if ((dbs)->service_browser) avahi_service_browser_free((dbs)->service_browser); if ((dbs)->service_client) avahi_client_free((dbs)->service_client); if ((dbs)->service_poll) avahi_threaded_poll_free((dbs)->service_poll); free((char *)(dbs)); conn->mdns_private_pointer = NULL; } else { debug(1, "DHCP Monitor is not running."); } }
static void avahi_client_reset_all() { for (AvahiServiceEntryList::iterator it = avahi_services.begin(); it != avahi_services.end(); ++it) { if (it->group) { avahi_entry_group_free(it->group); it->group = NULL; } } for (AvahiBrowserEntryList::iterator it = avahi_browsers.begin(); it != avahi_browsers.end(); ++it) { if (it->browser) { avahi_service_browser_free(it->browser); it->browser = NULL; } } }
bool CZeroconfBrowserAvahi::doRemoveServiceType ( const std::string& fcr_service_type ) { ScopedEventLoopBlock lock ( mp_poll ); tBrowserMap::iterator it = m_browsers.find ( fcr_service_type ); if ( it == m_browsers.end() ) return false; else { if ( it->second ) { avahi_service_browser_free ( it->second ); m_all_for_now_browsers.erase ( it->second ); } m_browsers.erase ( it ); //remove this serviceType from the list of discovered services for ( tDiscoveredServices::iterator it = m_discovered_services.begin(); it != m_discovered_services.end(); ++it ) if ( it->first.GetType() == fcr_service_type ) m_discovered_services.erase ( it++ ); } return true; }
gboolean dmap_mdns_browser_stop (DMAPMdnsBrowser * browser, GError ** error) { if (browser->priv->client == NULL) { g_set_error (error, DMAP_MDNS_BROWSER_ERROR, DMAP_MDNS_BROWSER_ERROR_NOT_RUNNING, "%s", _("MDNS service is not running")); return FALSE; } if (browser->priv->service_browser == NULL) { g_set_error (error, DMAP_MDNS_BROWSER_ERROR, DMAP_MDNS_BROWSER_ERROR_FAILED, "%s", _("Browser is not active")); return FALSE; } avahi_service_browser_free (browser->priv->service_browser); browser->priv->service_browser = NULL; return TRUE; }
Avahi::~Avahi() { if (discoveryClient) { avahi_client_free(discoveryClient); } if (publishClient) { avahi_client_free(publishClient); } if (simple_discovery_poll) { avahi_simple_poll_free(simple_discovery_poll); } if (sb) { avahi_service_browser_free(sb); } if (simple_publish_poll) { avahi_simple_poll_free(simple_publish_poll); } distrd->join(); pubtrd->join(); // TODO Auto-generated destructor stub }
int main( AVAHI_GCC_UNUSED int argc, char *argv[] ) { AvahiClient *client = NULL; AvahiServiceBrowser *serviceBrowser = NULL; char *myName; int error; int result = 1; TiVoUnit *tivo; myName = strrchr(argv[0], '/') + 1; if (myName == (NULL+1)) myName = argv[0]; openlog( myName, LOG_PID, LOG_DAEMON ); loginfo("started"); /* must be done before any threads start */ curl_global_init( CURL_GLOBAL_ALL ); /* Allocate main loop object */ bonjourThread = avahi_threaded_poll_new(); if ( !bonjourThread ) { logerror( "Failed to create threaded poll object." ); } else { /* Allocate a new client */ client = avahi_client_new( avahi_threaded_poll_get( bonjourThread ), 0, client_callback, NULL, &error ); /* Check wether creating the client object succeeded */ if ( !client ) { logerror( "Unable to create client: %s", avahi_strerror( error ) ); } else { /* Create the service browser */ serviceBrowser = avahi_service_browser_new( client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_tivo-device._tcp", NULL, 0, browseCallback, client ); if ( !serviceBrowser ) { logerror( "Unable to create service browser: %s", avahi_strerror( avahi_client_errno( client ) ) ); } else { /* start the background network scan for TiVos */ avahi_threaded_poll_start( bonjourThread ); /* hack: wait for some results to arrive */ sleep(5); /* what did we find? */ result = dumpTiVos(); avahi_threaded_poll_stop( bonjourThread ); avahi_service_browser_free( serviceBrowser ); } avahi_client_free( client ); } avahi_threaded_poll_free( bonjourThread ); } /* docs say no other threads may be running */ curl_global_cleanup(); loginfo( "stopped" ); closelog(); return result; }
~Implementation() { if (browser_) { avahi_service_browser_free(browser_); } }
AvahiServiceBrowser* avahi_service_browser_new( AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *type, const char *domain, AvahiLookupFlags flags, AvahiServiceBrowserCallback callback, void *userdata) { AvahiServiceBrowser *b = NULL; DBusMessage *message = NULL, *reply = NULL; DBusError error; char *path; int32_t i_protocol, i_interface; uint32_t u_flags; assert(client); assert(type); assert(callback); dbus_error_init(&error); if (!avahi_client_is_connected(client)) { avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); goto fail; } if (!domain) domain = ""; if (!(b = avahi_new(AvahiServiceBrowser, 1))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } b->client = client; b->callback = callback; b->userdata = userdata; b->path = NULL; b->type = b->domain = NULL; b->interface = interface; b->protocol = protocol; AVAHI_LLIST_PREPEND(AvahiServiceBrowser, service_browsers, client->service_browsers, b); if (!(b->type = avahi_strdup(type))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (domain && domain[0]) if (!(b->domain = avahi_strdup(domain))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceBrowserNew"))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; u_flags = (uint32_t) flags; if (!dbus_message_append_args( message, DBUS_TYPE_INT32, &i_interface, DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID)) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (!(reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error)) || dbus_error_is_set(&error)) { avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); goto fail; } if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) || dbus_error_is_set(&error) || !path) { avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); goto fail; } if (!(b->path = avahi_strdup(path))) { /* FIXME: We don't remove the object on the server side */ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } dbus_message_unref(message); dbus_message_unref(reply); return b; fail: if (dbus_error_is_set(&error)) { avahi_client_set_dbus_error(client, &error); dbus_error_free(&error); } if (b) avahi_service_browser_free(b); if (message) dbus_message_unref(message); if (reply) dbus_message_unref(reply); return NULL; }
int avahi_dacp_monitor(rtsp_conn_info *conn) { dacp_browser_struct *dbs = (dacp_browser_struct *)malloc(sizeof(dacp_browser_struct)); if (dbs == NULL) die("can not allocate a dacp_browser_struct."); conn->mdns_private_pointer = (void *)dbs; // create the threaded poll code int err; if (!(dbs->service_poll = avahi_threaded_poll_new())) { warn("couldn't create avahi threaded service_poll!"); if (dbs) { free((char *)dbs); } conn->mdns_private_pointer = NULL; return -1; } // create the service client if (!(dbs->service_client = avahi_client_new(avahi_threaded_poll_get(dbs->service_poll), AVAHI_CLIENT_NO_FAIL, service_client_callback, (void *)conn, &err))) { warn("couldn't create avahi service client: %s!", avahi_strerror(err)); if (dbs) { // should free the threaded poll code avahi_threaded_poll_free(dbs->service_poll); free((char *)dbs); } conn->mdns_private_pointer = NULL; return -1; } /* Create the service browser */ if (!(dbs->service_browser = avahi_service_browser_new(dbs->service_client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_dacp._tcp", NULL, 0, browse_callback, (void *)conn))) { warn("Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(dbs->service_client))); if (dbs) { // should free the threaded poll code and the service client avahi_client_free(dbs->service_client); avahi_threaded_poll_free(dbs->service_poll); free((char *)dbs); } conn->mdns_private_pointer = NULL; return -1; } // start the polling thread if (avahi_threaded_poll_start(dbs->service_poll) < 0) { warn("couldn't start avahi service_poll thread"); if (dbs) { // should free the threaded poll code and the service client and the service browser avahi_service_browser_free(dbs->service_browser); avahi_client_free(dbs->service_client); avahi_threaded_poll_free(dbs->service_poll); free((char *)dbs); } conn->mdns_private_pointer = NULL; return -1; } return 0; }
void Avahi::Heap::BrowserCallback (AvahiServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags /*flags*/) { switch (event) { case AVAHI_BROWSER_NEW: /* this may not be the final valid resolver pointer... * we'll take what our callback gets */ if (resolver) avahi_service_resolver_free (resolver); resolver = avahi_service_resolver_new (client, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, (AvahiLookupFlags)0, avahi_resolver_callback, this); #if DEBUG std::cout << __PRETTY_FUNCTION__ << " AVAHI_BROWSER_NEW" << std::endl; #endif if (resolver == NULL) std::cout << "resolver is NULL!" << std::endl; break; case AVAHI_BROWSER_REMOVE: #if DEBUG std::cout << __PRETTY_FUNCTION__ << " AVAHI_BROWSER_REMOVE" << std::endl; #endif for (iterator iter = begin (); iter != end (); ++iter) if ((*iter)->get_name () == name) { (*iter)->removed (*iter); break; } break; case AVAHI_BROWSER_CACHE_EXHAUSTED: // FIXME: do I care? #if DEBUG std::cout << __PRETTY_FUNCTION__ << " AVAHI_BROWSER_CACHE_EXHAUSTED" << std::endl; #endif break; case AVAHI_BROWSER_ALL_FOR_NOW: // FIXME: do I care? #if DEBUG std::cout << __PRETTY_FUNCTION__ << " AVAHI_BROWSER_ALL_FOR_NOW" << std::endl; #endif break; case AVAHI_BROWSER_FAILURE: #if DEBUG std::cout << __PRETTY_FUNCTION__ << " AVAHI_BROWSER_FAILURE" << std::endl; #endif avahi_service_browser_free (browser); browser = NULL; break; default: /* shouldn't happen */ #if DEBUG std::cout << __PRETTY_FUNCTION__ << " SHOULDN'T HAPPEN" << std::endl; #endif break; } }
static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex intf, AvahiProtocol proto, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *userdata) { struct mdns_browser *mb; AvahiServiceResolver *res; int family; mb = (struct mdns_browser *)userdata; switch (event) { case AVAHI_BROWSER_FAILURE: DPRINTF(E_LOG, L_MDNS, "Avahi Browser failure: %s\n", avahi_strerror(avahi_client_errno(mdns_client))); avahi_service_browser_free(b); b = avahi_service_browser_new(mdns_client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 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, avahi_strerror(avahi_client_errno(mdns_client))); } return; case AVAHI_BROWSER_NEW: DPRINTF(E_DBG, L_MDNS, "Avahi Browser: NEW service '%s' type '%s' proto %d\n", name, type, proto); res = avahi_service_resolver_new(mdns_client, intf, proto, name, type, domain, proto, 0, browse_resolve_callback, mb); if (!res) DPRINTF(E_LOG, L_MDNS, "Failed to create service resolver: %s\n", avahi_strerror(avahi_client_errno(mdns_client))); break; case AVAHI_BROWSER_REMOVE: DPRINTF(E_DBG, L_MDNS, "Avahi Browser: REMOVE service '%s' type '%s' proto %d\n", name, type, proto); switch (proto) { case AVAHI_PROTO_INET: family = AF_INET; break; case AVAHI_PROTO_INET6: family = AF_INET6; break; default: DPRINTF(E_INFO, L_MDNS, "Avahi Browser: unknown protocol %d\n", proto); family = AF_UNSPEC; break; } if (family != AF_UNSPEC) mb->cb(name, type, domain, NULL, family, NULL, -1, NULL); break; case AVAHI_BROWSER_ALL_FOR_NOW: case AVAHI_BROWSER_CACHE_EXHAUSTED: DPRINTF(E_DBG, L_MDNS, "Avahi Browser (%s): no more results (%s)\n", mb->type, (event == AVAHI_BROWSER_CACHE_EXHAUSTED) ? "CACHE_EXHAUSTED" : "ALL_FOR_NOW"); break; } }
static void init_local (void) { int i; MateVFSResult res; if (!started_local) { AvahiSimplePoll *simple_poll; const AvahiPoll *poll; AvahiClient *client = NULL; AvahiServiceBrowser **sb; struct timeval tv; int error; started_local = TRUE; for (i = 0; i < G_N_ELEMENTS (dns_sd_types); i++) { MateVFSDNSSDBrowseHandle *handle; res = mate_vfs_dns_sd_browse (&handle, "local", dns_sd_types[i].type, local_browse_callback, NULL, NULL); if (res == MATE_VFS_OK) { dns_sd_types[i].handle = handle; } } simple_poll = avahi_simple_poll_new (); if (simple_poll == NULL) { g_warning ("Failed to create simple poll object"); return; } poll = avahi_simple_poll_get (simple_poll); client = avahi_client_new (poll, 0, avahi_client_callback, simple_poll, &error); /* Check wether creating the client object succeeded */ if (client == NULL) { g_warning ("Failed to create client: %s\n", avahi_strerror (error)); avahi_simple_poll_free (simple_poll); return; } sb = g_new0 (AvahiServiceBrowser *, G_N_ELEMENTS (dns_sd_types)); for (i = 0; i < G_N_ELEMENTS (dns_sd_types); i++) { sb[i] = avahi_service_browser_new (client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, dns_sd_types[i].type, "local", AVAHI_LOOKUP_USE_MULTICAST, local_browse_callback_sync, simple_poll); } avahi_elapse_time (&tv, LOCAL_SYNC_BROWSE_DELAY_MSEC, 0); poll->timeout_new (poll, &tv, stop_poll_timeout, (void *)simple_poll); /* Run the main loop util reply or timeout */ for (;;) if (avahi_simple_poll_iterate (simple_poll, -1) != 0) break; for (i = 0; i < G_N_ELEMENTS (dns_sd_types); i++) { if (sb[i] != NULL) { avahi_service_browser_free (sb[i]); } } avahi_client_free (client); avahi_simple_poll_free (simple_poll); }
static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex intf, AvahiProtocol proto, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *userdata) { struct mdns_browser *mb; struct mdns_resolver *r; int family; mb = (struct mdns_browser *)userdata; switch (event) { case AVAHI_BROWSER_FAILURE: DPRINTF(E_LOG, L_MDNS, "Avahi Browser failure: %s\n", MDNSERR); avahi_service_browser_free(b); 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); return; } break; case AVAHI_BROWSER_NEW: DPRINTF(E_DBG, L_MDNS, "Avahi Browser: NEW service '%s' type '%s' proto %d\n", name, type, proto); CHECK_NULL(L_MDNS, r = calloc(1, sizeof(struct mdns_resolver))); r->resolver = avahi_service_resolver_new(mdns_client, intf, proto, name, type, domain, proto, 0, browse_resolve_callback, mb); if (!r->resolver) { DPRINTF(E_LOG, L_MDNS, "Failed to create service resolver: %s\n", MDNSERR); free(r); return; } r->name = strdup(name); r->proto = proto; r->next = resolver_list; resolver_list = r; break; case AVAHI_BROWSER_REMOVE: DPRINTF(E_DBG, L_MDNS, "Avahi Browser: REMOVE service '%s' type '%s' proto %d\n", name, type, proto); family = avahi_proto_to_af(proto); if (family != AF_UNSPEC) mb->cb(name, type, domain, NULL, family, NULL, -1, NULL); resolvers_cleanup(name, proto); break; case AVAHI_BROWSER_ALL_FOR_NOW: case AVAHI_BROWSER_CACHE_EXHAUSTED: DPRINTF(E_DBG, L_MDNS, "Avahi Browser (%s): no more results (%s)\n", mb->type, (event == AVAHI_BROWSER_CACHE_EXHAUSTED) ? "CACHE_EXHAUSTED" : "ALL_FOR_NOW"); break; } }