void ofxAvahiClientBrowser::close(){ if (client) { avahi_client_free(client); } if (poll) { avahi_simple_poll_free(poll); } }
void Avahi::PresencePublisher::free_client () { if (client != NULL) { avahi_client_free (client); client = NULL; } }
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; } }
void QxtMDNS::cancelLookup() { if (qxt_d().recordbrowser != NULL) avahi_record_browser_free(qxt_d().recordbrowser); if (qxt_d().client != NULL) avahi_client_free(qxt_d().client); deleteLater(); }
static void mdns_deinit_task(void *arg) { struct mdns_group_entry *ge; struct mdns_browser *mb; AvahiWatch *w; AvahiTimeout *t; if (mdns_client) avahi_client_free(mdns_client); for (t = all_t; t; t = t->next) { if (t->timer) { dispatch_source_cancel(t->timer); dispatch_release(t->timer); t->timer = NULL; } } for (w = all_w; w; w = w->next) { if (w->w_read) { dispatch_source_cancel(w->w_read); dispatch_release(w->w_read); } if (w->w_write) { dispatch_source_cancel(w->w_write); dispatch_release(w->w_write); } } for (ge = group_entries; group_entries; ge = group_entries) { group_entries = ge->next; free(ge->name); free(ge->type); avahi_string_list_free(ge->txt); free(ge); } for (mb = browser_list; browser_list; mb = browser_list) { browser_list = mb->next; free(mb->type); free(mb); } }
/** * 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); }
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; } }
Avahi::Heap::~Heap () { if (resolver != NULL) avahi_service_resolver_free (resolver); if (client != NULL) avahi_client_free (client); if (poll != NULL) avahi_glib_poll_free (poll); }
static void free_global_avahi_client (void) { /* Remove current resolvers */ g_list_foreach (resolvers, (GFunc) remove_client_from_resolver, NULL); /* Destroy client */ avahi_client_free (global_client); global_client = NULL; avahi_initialized = FALSE; }
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; }
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: ; } }
static void aur_avahi_finalize (GObject * object) { AurAvahi *avahi = (AurAvahi *) (object); if (avahi->priv->group) avahi_entry_group_free (avahi->priv->group); if (avahi->priv->client) avahi_client_free (avahi->priv->client); avahi_glib_poll_free (avahi->priv->glib_poll); }
static int register_once() { AvahiClient *client = NULL; int error; int ret = 1; struct timeval tv; group = NULL; simple_poll = NULL; name = NULL; /* Allocate main loop object */ if (!(simple_poll = avahi_simple_poll_new())) { fprintf(stderr, "Failed to create simple poll object.\n"); goto fail; } name = avahi_strdup("MegaPrinter"); /* 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; } /* After 10s quit. */ avahi_simple_poll_get(simple_poll)->timeout_new( avahi_simple_poll_get(simple_poll), avahi_elapse_time(&tv, 300*10, 0), quit_callback, client); /* Run the main loop */ avahi_simple_poll_loop(simple_poll); ret = 0; fail: /* Cleanup things */ if (client) avahi_client_free(client); if (simple_poll) avahi_simple_poll_free(simple_poll); avahi_free(name); return ret; }
/***************************************************************************** * 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 ); }
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; }
/***************************************************************************** * 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; }
void CZeroconfBrowserAvahi::clientCallback ( AvahiClient* fp_client, AvahiClientState f_state, void* fp_data ) { CZeroconfBrowserAvahi* p_instance = static_cast<CZeroconfBrowserAvahi*> ( fp_data ); //store our thread ID and check for shutdown -> check details in destructor p_instance->m_thread_id = pthread_self(); if (p_instance->m_shutdown) { avahi_threaded_poll_quit(p_instance->mp_poll); return; } switch ( f_state ) { case AVAHI_CLIENT_S_RUNNING: { CLog::Log ( LOGDEBUG, "CZeroconfBrowserAvahi::clientCallback: client is up and running" ); for ( tBrowserMap::iterator it = p_instance->m_browsers.begin(); it != p_instance->m_browsers.end(); ++it ) { assert ( !it->second ); it->second = createServiceBrowser ( it->first, fp_client, fp_data ); } break; } case AVAHI_CLIENT_FAILURE: { CLog::Log ( LOGINFO, "CZeroconfBrowserAvahi::clientCallback: client failure. avahi-daemon stopped? Recreating client..." ); //We were forced to disconnect from server. now free and recreate the client object avahi_client_free ( fp_client ); p_instance->mp_client = 0; //freeing the client also frees all groups and browsers, pointers are undefined afterwards, so fix that now for ( tBrowserMap::iterator it = p_instance->m_browsers.begin(); it != p_instance->m_browsers.end(); ++it ) it->second = ( AvahiServiceBrowser* ) 0; //clean the list of discovered services and update gui (if someone is interested) p_instance->m_discovered_services.clear(); CGUIMessage message ( GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE_PATH ); message.SetStringParam ( "zeroconf://" ); g_windowManager.SendThreadMessage ( message ); p_instance->createClient(); break; } case AVAHI_CLIENT_S_COLLISION: case AVAHI_CLIENT_S_REGISTERING: //HERE WE SHOULD REMOVE ALL OF OUR SERVICES AND "RESCHEDULE" them for later addition CLog::Log ( LOGDEBUG, "CZeroconfBrowserAvahi::clientCallback: This should not happen" ); break; case AVAHI_CLIENT_CONNECTING: CLog::Log ( LOGINFO, "CZeroconfBrowserAvahi::clientCallback: avahi server not available. But may become later..." ); break; } }
void Avahi::Heap::ClientCallback (AvahiClient *_client, AvahiClientState state) { /* this is the good client pointer */ client = _client; switch (state) { case AVAHI_CLIENT_FAILURE: /* bad, bad: free the client and try to get another one... but * won't I tax the box? */ #if DEBUG std::cout << __PRETTY_FUNCTION__ << " AVAHI_CLIENT_FAILURE" << std::endl; #endif if (client != NULL) avahi_client_free (client); client = NULL; break; case AVAHI_CLIENT_S_RUNNING: /* ignore what we get from the new, as it may not be the final * valid browser pointer... we'll take what our callback gets */ avahi_service_browser_new (client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_sip._udp", NULL, (AvahiLookupFlags)0, avahi_browser_callback, this); #if DEBUG std::cout << __PRETTY_FUNCTION__ << " AVAHI_CLIENT_S_RUNNING" << std::endl; if (browser == NULL) std::cout << "but NULL browser!" << std::endl; #endif break; case AVAHI_CLIENT_CONNECTING: case AVAHI_CLIENT_S_REGISTERING: case AVAHI_CLIENT_S_COLLISION: /* do nothing */ #if DEBUG std::cout << __PRETTY_FUNCTION__ << " OTHER" << std::endl; #endif break; default: #if DEBUG std::cout << __PRETTY_FUNCTION__ << " SHOULDN'T HAPPEN" << std::endl; #endif /* shouldn't happen */ break; } }
PublishAvahi::~PublishAvahi() { active_ = false; pollThread_.join(); if (client_) avahi_client_free(client_); if (simple_poll) avahi_simple_poll_free(simple_poll); avahi_free(name); }
void stopRegisterService(const char* nameService){ pthread_cancel(myNewThread); /* Cleanup things */ if (client) avahi_client_free(client); if (simple_poll) avahi_simple_poll_free(simple_poll); avahi_free((void*)nameService); }
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) { AvahiClient *client = NULL; int error; int ret = 1; //struct timeval tv; // Not needed due no modifications made by avahi service // Comes from sample code /* Allocate main loop object */ if (!(simple_poll = avahi_simple_poll_new())) { fprintf(stderr, "Failed to create simple poll object.\n"); goto fail; } name = avahi_strdup("gbMon2"); /* 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; } /* After 10s do some weird modification to the service */ /* avahi_simple_poll_get(simple_poll)->timeout_new( avahi_simple_poll_get(simple_poll), avahi_elapse_time(&tv, 1000*10, 0), modify_callback, client); */ /* Run the main loop */ avahi_simple_poll_loop(simple_poll); ret = 0; fail: /* Cleanup things */ if (client) avahi_client_free(client); if (simple_poll) avahi_simple_poll_free(simple_poll); avahi_free(name); return ret; }
static void client_callback(AvahiClient *client, AvahiClientState state, void *userdata) { ctx.client = client; switch (state) { case AVAHI_CLIENT_S_RUNNING: /* The server has started up successfully and registered its host * name on the network, so it's time to create our services */ register_stuff(); 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 */ ctx.client = avahi_client_new( avahi_threaded_poll_get(ctx.threaded_poll), AVAHI_CLIENT_NO_FAIL, client_callback, &ctx, &error); if (!ctx.client) { DPRINTF(E_ERROR, L_SSDP, "Failed to contact server: %s\n", avahi_strerror(error)); avahi_threaded_poll_quit(ctx.threaded_poll); } } else { DPRINTF(E_ERROR, L_SSDP, "Client failure: %s\n", avahi_strerror(avahi_client_errno(client))); avahi_threaded_poll_quit(ctx.threaded_poll); } break; case AVAHI_CLIENT_CONNECTING: default: break; } }
void e2avahi_close() { if (avahi_client) { avahi_client_free(avahi_client); avahi_client = NULL; /* Remove all group entries */ for (AvahiServiceEntryList::iterator it = avahi_services.begin(); it != avahi_services.end(); ++it) { it->group = NULL; } } }
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; }
static void dnssdStop(void) { cupsd_printer_t *p; /* Current printer */ /* * De-register the individual printers */ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) dnssdDeregisterPrinter(p, 1, 0); /* * Shutdown the rest of the service refs... */ dnssdDeregisterInstance(&WebIFSrv, 0); # ifdef HAVE_DNSSD cupsdRemoveSelect(DNSServiceRefSockFD(DNSSDMaster)); DNSServiceRefDeallocate(DNSSDMaster); DNSSDMaster = NULL; # else /* HAVE_AVAHI */ if (DNSSDMaster) avahi_threaded_poll_stop(DNSSDMaster); if (DNSSDClient) { avahi_client_free(DNSSDClient); DNSSDClient = NULL; } if (DNSSDMaster) { avahi_threaded_poll_free(DNSSDMaster); DNSSDMaster = NULL; } # endif /* HAVE_DNSSD */ cupsArrayDelete(DNSSDPrinters); DNSSDPrinters = NULL; DNSSDPort = 0; }
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; }
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 }
/* * Tries to shutdown this loop impl. * Call this function from inside this thread. */ int av_zeroconf_unregister() { LOG(log_debug, logtype_afpd, "av_zeroconf_unregister"); if (ctx) { if (ctx->threaded_poll) avahi_threaded_poll_stop(ctx->threaded_poll); if (ctx->client) avahi_client_free(ctx->client); if (ctx->threaded_poll) avahi_threaded_poll_free(ctx->threaded_poll); free(ctx); ctx = NULL; } return 0; }
AvahiSession::~AvahiSession() { if (mClient) { avahi_threaded_poll_stop(mPoll); avahi_client_free(mClient); avahi_threaded_poll_free(mPoll); AvahiEntry* entry = mEntries; while (entry) { AvahiEntry* next = entry->mNext; delete entry; entry = next; } } free(mServiceName); }