예제 #1
0
/* Called when publishing of service data completes */
static void publish_reply(AvahiEntryGroup *g,
			  AvahiEntryGroupState state,
			  AVAHI_GCC_UNUSED void *userdata)
{
	assert(ctx.group == NULL || g == ctx.group);

	switch (state) {
	case AVAHI_ENTRY_GROUP_ESTABLISHED:
		/* The entry group has been established successfully */
		DPRINTF(E_MAXDEBUG, L_SSDP, "publish_reply: AVAHI_ENTRY_GROUP_ESTABLISHED\n");
		break;
	case AVAHI_ENTRY_GROUP_COLLISION:
		/* With multiple names there's no way to know which one collided */
		DPRINTF(E_ERROR, L_SSDP, "publish_reply: AVAHI_ENTRY_GROUP_COLLISION: %s\n",
				avahi_strerror(avahi_client_errno(ctx.client)));
		avahi_threaded_poll_quit(ctx.threaded_poll);
		break;
	case AVAHI_ENTRY_GROUP_FAILURE:
		DPRINTF(E_ERROR, L_SSDP, "Failed to register service: %s\n",
				avahi_strerror(avahi_client_errno(ctx.client)));
		avahi_threaded_poll_quit(ctx.threaded_poll);
		break;
	case AVAHI_ENTRY_GROUP_UNCOMMITED:
	case AVAHI_ENTRY_GROUP_REGISTERING:
	default:
		break;
	}
}
예제 #2
0
/* Called when publishing of service data completes */
static void publish_reply(AvahiEntryGroup *g,
                          AvahiEntryGroupState state,
                          AVAHI_GCC_UNUSED void *userdata)
{
    assert(ctx->group == NULL || g == ctx->group);

    switch (state) {

    case AVAHI_ENTRY_GROUP_ESTABLISHED :
        /* The entry group has been established successfully */
        LOG(log_debug, logtype_afpd, "publish_reply: AVAHI_ENTRY_GROUP_ESTABLISHED");
        break;

    case AVAHI_ENTRY_GROUP_COLLISION:
        /* With multiple names there's no way to know which one collided */
        LOG(log_error, logtype_afpd, "publish_reply: AVAHI_ENTRY_GROUP_COLLISION",
            avahi_strerror(avahi_client_errno(ctx->client)));
        avahi_threaded_poll_quit(ctx->threaded_poll);
        break;

    case AVAHI_ENTRY_GROUP_FAILURE:
        LOG(log_error, logtype_afpd, "Failed to register service: %s",
            avahi_strerror(avahi_client_errno(ctx->client)));
        avahi_threaded_poll_quit(ctx->threaded_poll);
        break;

    case AVAHI_ENTRY_GROUP_UNCOMMITED:
        break;
    case AVAHI_ENTRY_GROUP_REGISTERING:
        break;
    }
}
예제 #3
0
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;
    }
}
예제 #4
0
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:
            ;
    }
}
예제 #5
0
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;
	}
}
예제 #6
0
static void service_client_callback(AvahiClient *c, AvahiClientState state, void *userdata) {
  int err;

  rtsp_conn_info *conn = (rtsp_conn_info *)userdata;
  dacp_browser_struct *dbs = (dacp_browser_struct *)conn->mdns_private_pointer;

  switch (state) {
  case AVAHI_CLIENT_S_REGISTERING:
    break;

  case AVAHI_CLIENT_S_RUNNING:
    break;

  case AVAHI_CLIENT_FAILURE:
    err = avahi_client_errno(c);
    debug(1, "avahi: service client failure: %s", avahi_strerror(err));

    if (err == AVAHI_ERR_DISCONNECTED) {
      /* We have been disconnected, so lets reconnect */
      avahi_client_free(c);
      c = NULL;

      if (!(dbs->service_client =
                avahi_client_new(avahi_threaded_poll_get(dbs->service_poll), AVAHI_CLIENT_NO_FAIL,
                                 service_client_callback, userdata, &err))) {
        warn("avahi: failed to create service client object: %s", avahi_strerror(err));
        avahi_threaded_poll_quit(dbs->service_poll);
      }
    } else {
      warn("avahi: service client failure: %s", avahi_strerror(err));
      avahi_threaded_poll_quit(dbs->service_poll);
    }
    break;

  case AVAHI_CLIENT_S_COLLISION:
    debug(2, "avahi: service client state is AVAHI_CLIENT_S_COLLISION...needs a rename: %s",
          service_name);
    break;

  case AVAHI_CLIENT_CONNECTING:
    debug(2, "avahi: service client received AVAHI_CLIENT_CONNECTING");
    break;

  default:
    debug(1, "avahi: unexpected and unhandled avahi service client state: %d", state);
    break;
  }
}
예제 #7
0
static void client_callback(AvahiClient *c, AvahiClientState state,
                            AVAHI_GCC_UNUSED void *userdata) {
  int err;

  switch (state) {
  case AVAHI_CLIENT_S_REGISTERING:
    if (group)
      avahi_entry_group_reset(group);
    break;

  case AVAHI_CLIENT_S_RUNNING:
    register_service(c);
    break;

  case AVAHI_CLIENT_FAILURE:
    err = avahi_client_errno(c);
    debug(1, "avahi: client failure: %s", avahi_strerror(err));

    if (err == AVAHI_ERR_DISCONNECTED) {
      /* We have been disconnected, so lets reconnect */
      avahi_client_free(c);
      c = NULL;
      group = NULL;

      if (!(client = avahi_client_new(avahi_threaded_poll_get(tpoll), AVAHI_CLIENT_NO_FAIL,
                                      client_callback, userdata, &err))) {
        warn("avahi: failed to create client object: %s", avahi_strerror(err));
        avahi_threaded_poll_quit(tpoll);
      }
    } else {
      warn("avahi: client failure: %s", avahi_strerror(err));
      avahi_threaded_poll_quit(tpoll);
    }
    break;

  case AVAHI_CLIENT_S_COLLISION:
    debug(2, "avahi: state is AVAHI_CLIENT_S_COLLISION...needs a rename: %s", service_name);
    break;

  case AVAHI_CLIENT_CONNECTING:
    debug(2, "avahi: received AVAHI_CLIENT_CONNECTING");
    break;

  default:
    debug(1, "avahi: unexpected and unhandled avahi client state: %d", state);
    break;
  }
}
예제 #8
0
void CZeroconfAvahi::shutdownCallback(AvahiTimeout *fp_e, void *fp_data)
{
  CZeroconfAvahi* p_instance = static_cast<CZeroconfAvahi*>(fp_data);
  //should only be called on shutdown
  if (p_instance->m_shutdown)
  {
    avahi_threaded_poll_quit(p_instance->mp_poll);
  }
}
예제 #9
0
파일: tivod.c 프로젝트: paul-chambers/tivod
static void client_callback( AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata )
{
    /* Called whenever the client or server state changes */

    if (state == AVAHI_CLIENT_FAILURE) {
        logerror( "Server connection failure: %s", avahi_strerror( avahi_client_errno(c) ) );
        avahi_threaded_poll_quit(bonjourThread);
    }
}
예제 #10
0
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;
  }
}
/**
 * Callback function that is called whenever an Entry Group state changes
 *
 * @param s An Avahi Server
 *
 * @param g An Avahi Entry Group
 *
 * @param state The state of the Entry Group
 *
 * @param userdata The Service that is involved in this state change
 *
 * @return void
 *
 */
static void 
entry_group_callback(	AvahiServer *s, 
						AvahiSEntryGroup *g, 
						AvahiEntryGroupState state, 
						AVAHI_GCC_UNUSED void *userdata) 
{    

	assert(s);

	//Service *_called_service = (Service*) avahi_s_entry_group_get_data(g);
	Service *called_service = (Service*) userdata;

	/* Called whenever the entry group state changes */

	switch (state) {

		case AVAHI_ENTRY_GROUP_ESTABLISHED:

			/* The entry group has been established successfully */
			fprintf(stderr, "Service '%s' successfully established.\n", called_service->zeroConfName);
			break;

			case AVAHI_ENTRY_GROUP_COLLISION: {
				char *n;

				/* A service name collision happened. Let's pick a new name */
				n = avahi_alternative_service_name(called_service->ID);
				avahi_free(called_service->ID);
				called_service->ID = n;

				fprintf(stderr, "Service name collision, renaming service to '%s'\n", name);

				/* And recreate the services */

				avahi_core_create_service(called_service);

				break;
			}

		case AVAHI_ENTRY_GROUP_FAILURE :

			fprintf(stderr, "Entry group failure: %s\n", avahi_strerror(avahi_server_errno(s)));

			/* Some kind of failure happened while we were registering our services */
			avahi_threaded_poll_quit(threaded_poll);
			break;

		case AVAHI_ENTRY_GROUP_UNCOMMITED:
		case AVAHI_ENTRY_GROUP_REGISTERING:
			;
	}
}
예제 #12
0
파일: bonjour.c 프로젝트: FLYKingdom/vlc
/*****************************************************************************
 * client_callback
 *****************************************************************************/
static void client_callback( AvahiClient *c, AvahiClientState state,
                             void * userdata )
{
    services_discovery_t *p_sd = ( services_discovery_t* )userdata;
    services_discovery_sys_t *p_sys = p_sd->p_sys;

    if( state == AVAHI_CLIENT_FAILURE &&
        (avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) )
    {
        msg_Err( p_sd, "avahi client disconnected" );
        avahi_threaded_poll_quit( p_sys->poll );
    }
}
예제 #13
0
static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol,
                            AvahiBrowserEvent event, const char *name, const char *type,
                            const char *domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
                            void *userdata) {
  rtsp_conn_info *conn = (rtsp_conn_info *)userdata;
  dacp_browser_struct *dbs = (dacp_browser_struct *)conn->mdns_private_pointer;
  assert(b);
  /* Called whenever a new services becomes available on the LAN or is removed from the LAN */
  switch (event) {
  case AVAHI_BROWSER_FAILURE:
    warn("avahi: browser failure.",
         avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))));
    avahi_threaded_poll_quit(tpoll);
    break;
  case AVAHI_BROWSER_NEW:
    debug(3, "(Browser) NEW: service '%s' of type '%s' in domain '%s'.", name, type, domain);
    /* We ignore the returned resolver object. In the callback
       function we free it. If the server is terminated before
       the callback function is called the server will free
       the resolver for us. */
    if (!(avahi_service_resolver_new(dbs->service_client, interface, protocol, name, type, domain,
                                     AVAHI_PROTO_UNSPEC, 0, resolve_callback, userdata)))
      debug(1, "Failed to resolve service '%s': %s.", name,
            avahi_strerror(avahi_client_errno(dbs->service_client)));
    break;
  case AVAHI_BROWSER_REMOVE:
    debug(3, "(Browser) REMOVE: service '%s' of type '%s' in domain '%s'.", name, type, domain);
    char *dacpid = strstr(name, "iTunes_Ctrl_");
    if (dacpid) {
      dacpid += strlen("iTunes_Ctrl_");
      if (strcmp(dacpid, conn->dacp_id) == 0) {
        if (conn->dacp_id != 0) {
          debug(1, "Client's DACP status withdrawn.");
          conn->dacp_port = 0;
#if defined(HAVE_DBUS) || defined(HAVE_MPRIS)          
          set_dacp_server_information(conn); // this will have the effect of telling the scanner that the DACP server is no longer working
#endif
        }
      }
    } else {
      debug(1, "Browse callback: Can't see a DACP string in a DACP Record!");
    }

    break;
  case AVAHI_BROWSER_ALL_FOR_NOW:
  case AVAHI_BROWSER_CACHE_EXHAUSTED:
    // debug(1, "(Browser) %s.", event == AVAHI_BROWSER_CACHE_EXHAUSTED ? "CACHE_EXHAUSTED" :
    // "ALL_FOR_NOW");
    break;
  }
}
예제 #14
0
void CZeroconfAvahi::clientCallback(AvahiClient* fp_client, AvahiClientState f_state, void* fp_data)
{
  CZeroconfAvahi* p_instance = static_cast<CZeroconfAvahi*>(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, "CZeroconfAvahi::clientCallback: client is up and running");
    p_instance->updateServices(fp_client);
    break;

  case AVAHI_CLIENT_FAILURE:
    CLog::Log(LOGINFO, "CZeroconfAvahi::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(tServiceMap::const_iterator it = p_instance->m_services.begin(); it != p_instance->m_services.end(); ++it)
    {
      it->second->mp_group = 0;
    }
    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, "CZeroconfAvahi::clientCallback: uiuui; coll or reg, anyways, resetting groups");
    for(tServiceMap::const_iterator it = p_instance->m_services.begin(); it != p_instance->m_services.end(); ++it)
    {
      if (it->second->mp_group)
        avahi_entry_group_reset(it->second->mp_group);
    }
    break;

  case AVAHI_CLIENT_CONNECTING:
    CLog::Log(LOGINFO, "CZeroconfAvahi::clientCallback: avahi server not available. But may become later...");
    break;
  }
}
예제 #15
0
/**
 * Callback function that is called whenever an Entry Group state changes
 *
 * @param g An Avahi Entry Group
 *
 * @param state The state of the Entry Group
 *
 * @param userdata The Service that is involved in this state change
 *
 * @return void
 *
 */
static void 
entry_group_callback(	AvahiEntryGroup *g, 
						AvahiEntryGroupState state, 
						AVAHI_GCC_UNUSED void *userdata ) 
{

	/* Called whenever the entry group state changes */

	switch (state) 
	{
		case AVAHI_ENTRY_GROUP_ESTABLISHED :
			/* The entry group has been established successfully */
			break;

		case AVAHI_ENTRY_GROUP_COLLISION : 
		{
			//char *n;

			/* A service name collision with a remote 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);*/

			/* And recreate the services */
			//create_services(avahi_entry_group_get_client(g));
			break;
		}

		case AVAHI_ENTRY_GROUP_FAILURE :

			//fprintf(stderr, "Entry group failure: %s\n", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))));

			/* Some kind of failure happened while we were registering our services */
			avahi_threaded_poll_quit(threaded_poll);
			break;

		case AVAHI_ENTRY_GROUP_UNCOMMITED:
		case AVAHI_ENTRY_GROUP_REGISTERING:
			;
	}
}
예제 #16
0
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) {
    assert(c);

    /* Called whenever the client or server state changes */

    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 */
            create_services(c);
            break;

        case AVAHI_CLIENT_FAILURE:

            logging_printf(LOGGING_ERROR, "Client failure: %s\n", avahi_strerror(avahi_client_errno(c)));
            avahi_threaded_poll_quit(threaded_poll);

            break;

        case AVAHI_CLIENT_S_COLLISION:

            /* Let's drop our registered services. When the server is back
             * in AVAHI_SERVER_RUNNING state we will register them
             * again with the new host name. */

        case AVAHI_CLIENT_S_REGISTERING:

            /* The server records are now being established. This
             * might be caused by a host name change. We need to wait
             * for our own records to register until the host name is
             * properly esatblished. */

            if (group)
                avahi_entry_group_reset(group);

            break;

        case AVAHI_CLIENT_CONNECTING:
            ;
    }
}
예제 #17
0
static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void *userdata) {
    assert(g == group || group == NULL);
    group = g;

    /* Called whenever the entry group state changes */

    switch (state) {
        case AVAHI_ENTRY_GROUP_ESTABLISHED :
            /* The entry group has been established successfully */
            logging_printf(LOGGING_INFO, "Service '%s' successfully established.\n", sd_name_copy);
            break;

        case AVAHI_ENTRY_GROUP_COLLISION : {
            char *n;

            /* A service name collision with a remote 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);

            /* And recreate the services */
            create_services( avahi_entry_group_get_client(g) );
            break;
        }

        case AVAHI_ENTRY_GROUP_FAILURE :

            logging_printf(LOGGING_WARN, "Entry group failure: %s\n", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))));

            /* Some kind of failure happened while we were registering our services */
            avahi_threaded_poll_quit(threaded_poll);
            break;

        case AVAHI_ENTRY_GROUP_UNCOMMITED:
        case AVAHI_ENTRY_GROUP_REGISTERING:
            ;
    }
}
예제 #18
0
/* Called when publishing of service data completes */
static void publish_reply(AvahiEntryGroup *UNUSED(g), AvahiEntryGroupState state, void *userdata) {
    struct context *ctx = userdata;

    switch (state) {

        case AVAHI_ENTRY_GROUP_COLLISION: {
            char *n;

            /* Pick a new name for our service */

            n = avahi_alternative_service_name(ctx->name);
            assert(n);

            avahi_free(ctx->name);
            ctx->name = n;

            register_stuff(ctx);
            break;
        }

        case AVAHI_ENTRY_GROUP_FAILURE:
            rs_log_crit("Failed to register service: %s", avahi_strerror(avahi_client_errno(ctx->client)));
            avahi_threaded_poll_quit(ctx->threaded_poll);
            break;

        case AVAHI_ENTRY_GROUP_ESTABLISHED:
            rs_log_info("registered as \"%s.%s.%s\"",
                        avahi_client_get_host_name(ctx->client),
                        ctx->service_type,
                        avahi_client_get_domain_name(ctx->client));
            break;

        case AVAHI_ENTRY_GROUP_UNCOMMITED:
        case AVAHI_ENTRY_GROUP_REGISTERING:
            ;
    }
}
예제 #19
0
void Client::cleanup() {
	avahi_threaded_poll_quit(msPoll);
        avahi_client_free(msAvahiClient);
}
예제 #20
0
void wxAvahiThreadPool::Quit(){
    avahi_threaded_poll_quit(m_pool);
}
예제 #21
0
파일: tivod.c 프로젝트: paul-chambers/tivod
static void browseCallback( AvahiServiceBrowser *b,
                            AvahiIfIndex interface,
                            AvahiProtocol protocol,
                            AvahiBrowserEvent event,
                            const char *name,
                            const char *type,
                            const char *domain,
                            AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
                            void* userdata )
{
    AvahiClient *c = userdata;
    TiVoUnit    *tivo, *prev, *next;

    /* Called whenever a new tivo becomes available on the LAN or is removed from the LAN */

    switch (event)
    {
    case AVAHI_BROWSER_NEW:  /* detected a new TiVo on the LAN */

        tivo = rememberTiVo( name );

        /* We don't save the resolver object returned by avahi_service_resolver_new().
           Instead, when the resolver calls the callback function with the results, the new
           TiVoUnit is added, then the resolver is freed. If the server terminates before
           the callback function is called, the server will free the resolver for us. */

        if ( !avahi_service_resolver_new( c, interface, protocol,
                                          name, type, domain,
                                          AVAHI_PROTO_UNSPEC, 0,
                                          resolveCallback, tivo) )
        {
            logerror( "Failed to resolve service '%s': %s", name, avahi_strerror(avahi_client_errno(c)) );
        }
        break;

    case AVAHI_BROWSER_REMOVE:  /* a TiVo disappeared from the LAN */

        loginfo( "TiVo '%s' disappeared from network", name );

        /*-- begin critical section --*/
        prev = NULL;
        tivo = tivoUnits;
        while ( tivo != NULL )
        {
            next = tivo->next;
            if ( !strcmp( tivo->name, name ) )
            {   /* found it, so unlink it */
                if ( prev == NULL )
                     tivoUnits  = next;
                else prev->next = next;
                /* prev itself stays put */
                forgetTiVo( tivo );
            }
            else prev = tivo;

            tivo = next;
        }
        /*-- end critical section --*/
        break;

    case AVAHI_BROWSER_CACHE_EXHAUSTED:
        loginfo( "(Browser) cache exhausted" );
        break;

    case AVAHI_BROWSER_ALL_FOR_NOW:
        loginfo( "(Browser) all for now" );
        break;

    case AVAHI_BROWSER_FAILURE:
        logerror( "(Browser) %s", avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))) );
        avahi_threaded_poll_quit( bonjourThread );
        return;
    }
}
예제 #22
0
void CZeroconfAvahi::groupCallback(AvahiEntryGroup *fp_group, AvahiEntryGroupState f_state, void * fp_data)
{
  CZeroconfAvahi* p_instance = static_cast<CZeroconfAvahi*>(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_ENTRY_GROUP_ESTABLISHED :
    // The entry group has been established successfully
    CLog::Log(LOGDEBUG, "CZeroconfAvahi::groupCallback: Service successfully established");
    break;

  case AVAHI_ENTRY_GROUP_COLLISION :
  {
    //need to find the ServiceInfo struct for this group
    tServiceMap::iterator it = p_instance->m_services.begin();
    for(; it != p_instance->m_services.end(); ++it)
    {
      if (it->second->mp_group == fp_group)
        break;
    }
    if( it != p_instance->m_services.end() ) {
      char* alt_name = avahi_alternative_service_name( it->second->m_name.c_str() );
      it->second->m_name = alt_name;
      avahi_free(alt_name);
      CLog::Log(LOGNOTICE, "CZeroconfAvahi::groupCallback: Service name collision. Renamed to: %s", it->second->m_name.c_str());
      p_instance->addService(it->second, p_instance->mp_client);
    }
    break;
  }

  case AVAHI_ENTRY_GROUP_FAILURE:
    CLog::Log(LOGERROR, "CZeroconfAvahi::groupCallback: Entry group failure: %s ",
              (fp_group) ?
              avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(fp_group)))
              : "Unknown");
    //free the group and set to 0 so it may be added later
    if (fp_group)
    {
      //need to find the ServiceInfo struct for this group
      tServiceMap::iterator it = p_instance->m_services.begin();
      for (; it != p_instance->m_services.end(); ++it)
      {
        if (it->second->mp_group == fp_group)
        {
          avahi_entry_group_free(it->second->mp_group);
          it->second->mp_group = 0;
          if (it->second->mp_txt)
          {
            avahi_string_list_free(it->second->mp_txt);
            it->second->mp_txt = NULL;
          }
          break;
        }
      }
    }
    break;

  case AVAHI_ENTRY_GROUP_UNCOMMITED:
  case AVAHI_ENTRY_GROUP_REGISTERING:
  default:
    break;
  }
}
예제 #23
0
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);
}
예제 #24
0
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);
}
예제 #25
0
void Publisher::quit() {
  avahi_threaded_poll_quit(poller);
  running = false;
}