Example #1
0
static void
handle_channels_cb (TpSimpleHandler *handler,
    TpAccount *account,
    TpConnection *connection,
    GList *channels,
    GList *requests_satisfied,
    gint64 user_action_time,
    TpHandleChannelsContext *context,
    gpointer user_data)
{
  VinoTubeServersManager *self = user_data;
  VinoTubeServer *server;
  GdkDisplay *display;
  GdkScreen *screen;
  /* the server is listenning only on lo as only the tube is supposed to
  connect to it */
  gchar * network_interface = "lo";
  GList *l;
  TpStreamTubeChannel *channel = NULL;

  for (l = channels; l != NULL; l = g_list_next (l))
    {
      TpStreamTubeChannel *chan = l->data;

      if (!TP_IS_STREAM_TUBE_CHANNEL (chan))
        continue;

      if (tp_proxy_get_invalidated (chan) != NULL)
        continue;

      if (tp_strdiff (tp_stream_tube_channel_get_service (chan), "rfb"))
        continue;

      channel = chan;
      break;
    }

  if (channel == NULL)
    {
      /* No stream tube channel ?! */
      GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
          "No stream tube channel" };

      tp_handle_channels_context_fail (context, &error);
      return;
    }

  display = gdk_display_get_default ();
  screen = gdk_display_get_default_screen (display);

  server = g_object_new (VINO_TYPE_TUBE_SERVER,
      "display-status-icon",  0,
      "prompt-enabled",       0,
      "view-only",            0,
      "network-interface",    network_interface,
      "use-alternative-port", 1,
      "alternative-port",     self->priv->alternative_port,
      "auth-methods",         1,
      "require-encryption",   0,
      "vnc-password",         NULL,
      "on-hold",              0,
      "screen",               screen,
      "lock-screen",          0,
      "disable-background",   0,
      "use-upnp",             0,
      "tube",                 channel,
      NULL);

  self->priv->vino_tube_servers = g_slist_prepend
      (self->priv->vino_tube_servers, server);

  g_signal_connect (G_OBJECT (server), "disconnected", G_CALLBACK
      (vino_tube_servers_manager_disconnected_cb), self);

  self->priv->alternative_port++;

  vino_tube_server_share_with_tube (server, NULL);

  tp_handle_channels_context_accept (context);
}
static void
handle_channels_cb (TpSimpleHandler *handler,
  TpAccount *account,
  TpConnection *connection,
  GList *channels,
  GList *request_satisfied,
  gint64 user_aciton_time,
  TpHandleChannelsContext *handler_context,
  gpointer user_data)
{
  TpChannel *channel = channels->data;
  gchar *path = g_build_filename (
    g_get_user_config_dir (),
    "phoenix",
    "auth",
    NULL);
  GFile *file = g_file_new_for_path (path);
  GFileIOStream *stream;
  GDataInputStream *input = NULL;
  char *password = NULL;
  char *line;

  if (g_list_length (channels) != 1)
    {
      GError err = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
        "Can only handle one channel at a time" };
      tp_handle_channels_context_fail (handler_context,
        &err);
      goto out;
    }

  stream = g_file_open_readwrite (file, NULL, NULL);

  if (stream == NULL)
    {
      GError err = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
        "No authenication data stored" };
      tp_handle_channels_context_fail (handler_context,
        &err);
      goto out;
    }

  input = g_data_input_stream_new (
    g_io_stream_get_input_stream (G_IO_STREAM (stream)));
  while ((line = g_data_input_stream_read_line_utf8 (input, NULL, NULL, NULL))
      != NULL)
    {
      gchar **r = g_strsplit (line, " ", 2);
      if (r[0] == NULL || r[1] == NULL)
        continue;

      if (!tp_strdiff (r[0], tp_account_get_path_suffix (account)))
        {
          password = g_strdup (r[1]);
          printf ("Found password: %s\n", password);
          g_strfreev(r);
          break;
        }
      g_strfreev(r);
    }
  g_object_unref (input);

  if (password == NULL)
    {
      GError err = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
        "No authenication data stored for this account" };
      tp_handle_channels_context_fail (handler_context,
        &err);
      goto out;
    }

  tp_handle_channels_context_accept (handler_context);

  tp_cli_channel_interface_sasl_authentication_connect_to_sasl_status_changed
    (channel, sasl_status_changed_cb, NULL, NULL, NULL, NULL);
  provide_password (channel, password);

out:
  g_free (path);
  g_free (password);
}