Esempio n. 1
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
}
Esempio n. 2
0
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;
    }
  }

}
Esempio n. 3
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;
}
ControllerDiscoveryMDNS::ControllerDiscoveryMDNS( TPContext * context, const String & n, int _port , int _http_port )
    :
    poll( NULL ),
    server( NULL ),
    group( NULL ),
    name( n ),
    ready( false ),
    port( _port ),
    http_port( _http_port )
{
    avahi_set_allocator( avahi_glib_allocator() );

    poll = avahi_glib_poll_new( NULL, TRICKPLAY_PRIORITY );
    g_assert( poll );

    AvahiServerConfig config;
    avahi_server_config_init( &config );

    config.publish_workstation = 0;

    int error;

    server = avahi_server_new( avahi_glib_poll_get( poll ), &config, avahi_server_callback, this, &error );

    if ( !server )
    {
        g_warning( "FAILED TO CREATE AVAHI SERVER : %s", avahi_strerror( error ) );
    }
}
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
}
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;
}
Esempio n. 7
0
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
}
Esempio n. 8
0
Browser::Browser(QObject *parent)
    : QAbstractListModel(parent) {
    poll_.reset(avahi_glib_poll_new(nullptr, G_PRIORITY_DEFAULT));
    if (!poll_) {
        throw std::runtime_error("Could not create AvahiGLibPoll");
    }

    AvahiServerConfig config_backing { nullptr, };
    std::unique_ptr<AvahiServerConfig, decltype(&avahi_server_config_free)>
        config(avahi_server_config_init(&config_backing),
               avahi_server_config_free);
    config->publish_hinfo = false;
    config->publish_addresses = false;
    config->publish_workstation = false;
    config->publish_domain = false;
    config->disable_publishing = true;

    int error = 0;
    server_.reset(avahi_server_new(
                      avahi_glib_poll_get(poll_.get()), config.get(),
                      &Browser::serverCallback, this, &error));
    if (!server_) {
        throw std::runtime_error(std::string("Could not create AvahiServer: ")
                                 + avahi_strerror(error));
    }

    roles[RoleServiceName] = "serviceName";
    roles[RoleHostName] = "hostName";
    roles[RoleAddress] = "address";
    roles[RolePort] = "port";
    roles[RoleTxt] = "txt";
}
Avahi::PresencePublisher::PresencePublisher (Ekiga::ServiceCore& core_,
					     Ekiga::PersonalDetails& details_,
					     Ekiga::CallCore& call_core_):
  core(core_), details(details_), call_core(call_core_),
  client(NULL), group(NULL)
{
  display_name = details.get_display_name ();
  details.updated.connect (boost::bind (&Avahi::PresencePublisher::on_details_updated, this));
  name = avahi_strdup (display_name.c_str ());
  glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
  create_client ();
}
Esempio n. 10
0
static void
aur_avahi_init (AurAvahi * avahi)
{
  AurAvahiPrivate *priv = avahi->priv =
      G_TYPE_INSTANCE_GET_PRIVATE (avahi, AUR_TYPE_AVAHI, AurAvahiPrivate);

  priv->service_name = g_strdup ("Aurena media server");

  priv->glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
  priv->poll_api = avahi_glib_poll_get (priv->glib_poll);
  priv->port = 5457;
}
Esempio n. 11
0
File: shell.c Progetto: GNOME/libepc
static void
epc_shell_init (void)
{
  if (G_UNLIKELY (NULL == epc_shell_avahi_poll))
    {
      gnutls_global_init ();
      avahi_set_allocator (avahi_glib_allocator ());
      /* deprecated: g_atexit (epc_shell_exit); */

      epc_shell_avahi_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
      g_assert (NULL != epc_shell_avahi_poll);

      /* TODO?
      bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
      bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
      */
    }
}
Esempio n. 12
0
static void
register_service (void)
{
	int error;
	const AvahiPoll *poll_api;
	AvahiGLibPoll *glib_poll;
	AvahiClient *client = NULL;

	name = avahi_strdup ("XMMS2 mDNS Agent");

	glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
	poll_api = avahi_glib_poll_get (glib_poll);

	client = avahi_client_new (poll_api, 0, client_callback, NULL, &error);
	if (!client) {
		printf ("Failed to create Avahi client: %s\n", avahi_strerror (error));
		avahi_client_free (client);
		avahi_glib_poll_free (glib_poll);
	}

}
Esempio n. 13
0
static AvahiClient *
get_global_avahi_client (GError **error)
{
    static AvahiGLibPoll *glib_poll = NULL;
    int avahi_error;

    if (!avahi_initialized)
    {
        avahi_initialized = TRUE;

        if (glib_poll == NULL)
        {
            avahi_set_allocator (avahi_glib_allocator ());
            glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
        }

        /* Create a new AvahiClient instance */
        global_client = avahi_client_new (avahi_glib_poll_get (glib_poll),
                                          AVAHI_CLIENT_NO_FAIL,
                                          avahi_client_callback,
                                          glib_poll,
                                          &avahi_error);

        if (global_client == NULL)
        {
            g_set_error (error,
                         G_IO_ERROR,
                         G_IO_ERROR_FAILED,
                         _("Error initializing Avahi: %s"),
                         avahi_strerror (avahi_error));
            goto out;
        }
    }

out:

    return global_client;
}
Esempio n. 14
0
File: avahi.c Progetto: cjd/lyricue
int publish_avahi(int port_passed, char *type_in_passed) {
    int error;
    AvahiGLibPoll *glib_poll;
    port = port_passed;
    type_in = strndup(type_in_passed,32);

    avahi_set_allocator (avahi_glib_allocator ());

    /* Create the GLIB Adaptor */
    glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);

    name = avahi_strdup("Lyricue Display");

    /* Allocate a new client */
    client = avahi_client_new(avahi_glib_poll_get(glib_poll), 0, client_callback, NULL, &error);

    /* Check if creating the client object succeeded */
    if (!client) {
        l_debug("Failed to create client: %s", avahi_strerror(error));
        unpublish_avahi();
    }

    
    /* Create the service browser */
    if (miniviews==NULL) {
        miniviews = g_hash_table_new(g_str_hash, g_str_equal);
    }
    if (sb == NULL) {
        if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET, "_lyricue._tcp", NULL, 0, browse_callback, client))) {
            l_debug("Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client)));
        }
    }


    return 0;
}
void NetworkServicesProviderAvahi::startUpdating()
{
    const AvahiPoll* pollApi;
    int error;    

    if (m_avahiClient)
        return;

    m_glibPoll = avahi_glib_poll_new(0, G_PRIORITY_DEFAULT);
    pollApi = avahi_glib_poll_get(m_glibPoll);

    /* Create a new AvahiClient instance */
    m_avahiClient = avahi_client_new(pollApi, (AvahiClientFlags)0, avahiClientCallback, static_cast<void*>(this), &error);

    /* Check the error return code */
    if (!m_avahiClient) {
        /* Print out the error string */
        g_warning("Error initializing Avahi: %s", avahi_strerror(error));

        avahi_glib_poll_free(m_glibPoll);

        notifyDiscoveryFinished();
    }
}
Esempio n. 16
0
gboolean
daap_mdns_setup ()
{
	const AvahiPoll *av_poll;

	GMainLoop *ml = NULL;
	gint errval;
	struct timeval tv;
	browse_callback_userdata_t *browse_userdata;

	if (gl_poll) {
		goto fail;
	}

	browse_userdata = g_new0 (browse_callback_userdata_t, 1);

	avahi_set_allocator (avahi_glib_allocator ());

	ml = g_main_loop_new (NULL, FALSE);

	gl_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
	av_poll = avahi_glib_poll_get (gl_poll);

	avahi_elapse_time (&tv, 2000, 0);
	av_poll->timeout_new (av_poll, &tv, daap_mdns_timeout, NULL);

	client = avahi_client_new (av_poll, 0, daap_mdns_client_cb, ml, &errval);
	if (!client) {
		goto fail;
	}

	browse_userdata->client = client;
	browse_userdata->mainloop = ml;

	browser = avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
	                                     AVAHI_PROTO_UNSPEC, "_daap._tcp", NULL,
	                                     0, daap_mdns_browse_cb,
	                                     browse_userdata);
	if (!browser) {
		goto fail;
	}

	return TRUE;

fail:
	if (ml)
		g_main_loop_unref (ml);

	if (client)
		avahi_client_free (client);
	client = NULL;
	browser = NULL;

	g_free (browse_userdata);

	if (gl_poll)
		avahi_glib_poll_free (gl_poll);
	gl_poll = NULL;

	return FALSE;
}
Esempio n. 17
0
int
main (AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[])
{
    GMainLoop *loop = NULL;
    const AvahiPoll *poll_api;
    AvahiGLibPoll *glib_poll;
    AvahiClient *client;
    struct timeval tv;
    const char *version;
    int error;

    /* Optional: Tell avahi to use g_malloc and g_free */
    avahi_set_allocator (avahi_glib_allocator ());

    /* Create the GLIB main loop */
    loop = g_main_loop_new (NULL, FALSE);

    /* Create the GLIB Adaptor */
    glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
    poll_api = avahi_glib_poll_get (glib_poll);

    /* Example, schedule a timeout event with the Avahi API */
    avahi_elapse_time (&tv,                         /* timeval structure */
            1000,                                   /* 1 second */
            0);                                     /* "jitter" - Random additional delay from 0 to this value */

    poll_api->timeout_new (poll_api,                /* The AvahiPoll object */
                      &tv,                          /* struct timeval indicating when to go activate */
                      avahi_timeout_event,          /* Pointer to function to call */
                      NULL);                        /* User data to pass to function */

    /* Schedule a timeout event with the glib api */
    g_timeout_add (5000,                            /* 5 seconds */
            avahi_timeout_event_glib,               /* Pointer to function callback */
            loop);                                  /* User data to pass to function */

    /* Create a new AvahiClient instance */
    client = avahi_client_new (poll_api,            /* AvahiPoll object from above */
                               0,
            avahi_client_callback,                  /* Callback function for Client state changes */
            loop,                                   /* User data */
            &error);                                /* Error return */

    /* Check the error return code */
    if (client == NULL)
    {
        /* Print out the error string */
        g_warning ("Error initializing Avahi: %s", avahi_strerror (error));

        goto fail;
    }

    /* Make a call to get the version string from the daemon */
    version = avahi_client_get_version_string (client);

    /* Check if the call suceeded */
    if (version == NULL)
    {
        g_warning ("Error getting version string: %s", avahi_strerror (avahi_client_errno (client)));

        goto fail;
    }

    g_message ("Avahi Server Version: %s", version);

    /* Start the GLIB Main Loop */
    g_main_loop_run (loop);

fail:
    /* Clean up */
    g_main_loop_unref (loop);
    avahi_client_free (client);
    avahi_glib_poll_free (glib_poll);

    return 0;
}