Beispiel #1
0
VinagreConnection *
vinagre_connection_new_from_string (const gchar *uri, gchar **error_msg, gboolean use_bookmarks)
{
  VinagreConnection *conn = NULL;
  gint    port;
  gchar  *host, *protocol;
  VinagreProtocol *ext;

  if (!vinagre_connection_split_string (uri, NULL, &protocol, &host, &port, error_msg))
    return NULL;

  if (use_bookmarks)
    conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (),
				     protocol,
				     host,
				     port);
  if (!conn)
    {
      ext = vinagre_plugins_engine_get_plugin_by_protocol (vinagre_plugins_engine_get_default (),
							   protocol);
      if (!ext)
	goto finalize;

      conn = vinagre_protocol_new_connection (ext);
      vinagre_connection_set_host (conn, host);
      vinagre_connection_set_port (conn, port);
    }

finalize:
  g_free (host);
  g_free (protocol);
  return conn;
}
Beispiel #2
0
VinagreConnection *
vinagre_connection_new_from_string (const gchar *uri, gchar **error_msg, gboolean use_bookmarks)
{
  VinagreConnection *conn = NULL;
  gint    port;
  gchar  *host;

  if (!vinagre_connection_split_string (uri, &host, &port, error_msg))
    return NULL;

  if (use_bookmarks)
    conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (),
				     host,
				     port);
  if (!conn)
    {
      conn = vinagre_connection_new ();
      vinagre_connection_set_host (conn, host);
      vinagre_connection_set_port (conn, port);
    }

  g_free (host);
  return conn;
}
Beispiel #3
0
static VinagreConnection *
impl_new_connection_from_file (VinagreProtocol *plugin,
			       const gchar   *data,
			       gboolean	      use_bookmarks,
			       gchar	    **error_msg)
{
  GKeyFile	    *file;
  GError	    *error;
  gboolean	     loaded;
  gchar		    *host, *actual_host, *protocol;
  gint		     port;
  VinagreConnection *conn;

  *error_msg = NULL;
  conn = NULL;
  host = NULL;
  protocol = NULL;
  error = NULL;

  file = g_key_file_new ();
  loaded = g_key_file_load_from_data (file,
				      data,
				      -1,
				      0,
				      &error);
  if (!loaded)
    {
      if (error)
	{
	  *error_msg = g_strdup (error->message);
	  g_error_free (error);
	}
      else
	*error_msg = g_strdup (_("Could not parse the file."));

      goto the_end;
    }
  if (!g_key_file_has_group (file, "connection"))
    {
      /* Translators: Do not translate "connection". It's the name of a group in the .spice (.ini like) file. */
      *error_msg = g_strdup (_("The file is not a Spice one: Missing the group \"connection\"."));
      goto the_end;
    }

  if (!g_key_file_has_key (file, "connection", "host", NULL))
    {
      /* Translators: Do not translate "host". It's the name of a key in the .spice (.ini like) file. */
      *error_msg = g_strdup (_("The file is not a Spice one: Missing the key \"host\"."));
      goto the_end;
    }

  host = g_key_file_get_string (file, "connection", "host", NULL);
  port = g_key_file_get_integer (file, "connection", "port", NULL);
  if (!port)
    {
      if (!vinagre_connection_split_string (host, "spice", &protocol, &actual_host, &port, error_msg))
	goto the_end;

      g_free (host);
      host = actual_host;
    }

  if (use_bookmarks)
    conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (), "spice", host, port);
  if (!conn)
    {
      gchar *s_value;

      conn = vinagre_spice_connection_new ();
      vinagre_connection_set_host (conn, host);
      vinagre_connection_set_port (conn, port);

      s_value = g_key_file_get_string  (file, "connection", "password", NULL);
      vinagre_connection_set_password (conn, s_value);
      g_free (s_value);
    }

 the_end:

  g_free (host);
  g_free (protocol);
  g_key_file_free (file);
  return conn;

}
Beispiel #4
0
VinagreConnection *
vinagre_connection_new_from_file (const gchar *uri, gchar **error_msg, gboolean use_bookmarks)
{
  GKeyFile          *file;
  GError            *error;
  gboolean           loaded;
  VinagreConnection *conn;
  gchar             *host, *actual_host, *data;
  gint               port;
  int                file_size;
  GFile             *file_a;

  *error_msg = NULL;
  host = NULL;
  data = NULL;
  conn = NULL;
  error = NULL;
  file = NULL;
  conn = NULL;

  file_a = g_file_new_for_commandline_arg (uri);
  loaded = g_file_load_contents (file_a,
				 NULL,
				 &data,
				 &file_size,
				 NULL,
				 &error);
  if (!loaded)
    {
      if (error)
	{
	  *error_msg = g_strdup (error->message);
	  g_error_free (error);
	}
      else
	*error_msg = g_strdup (_("Could not open the file."));

      goto the_end;
    }

  file = g_key_file_new ();
  loaded = g_key_file_load_from_data (file,
				      data,
				      file_size,
				      0,
				      &error);
  if (!loaded)
    {
      if (error)
	{
	  *error_msg = g_strdup (error->message);
	  g_error_free (error);
	}
      else
	*error_msg = g_strdup (_("Could not parse the file."));

      goto the_end;
    }

  host = g_key_file_get_string (file, "connection", "host", NULL);
  port = g_key_file_get_integer (file, "connection", "port", NULL);
  if (host)
    {
      if (!port)
	{
	  if (!vinagre_connection_split_string (host, &actual_host, &port, error_msg))
	    goto the_end;

	  g_free (host);
	  host = actual_host;
	}

      if (use_bookmarks)
        conn = vinagre_bookmarks_exists (vinagre_bookmarks_get_default (), host, port);
      if (!conn)
	{
	  gchar *username, *password;
	  gint shared;
	  GError *e = NULL;

	  conn = vinagre_connection_new ();
	  vinagre_connection_set_host (conn, host);
	  vinagre_connection_set_port (conn, port);

	  username = g_key_file_get_string  (file, "connection", "username", NULL);
	  vinagre_connection_set_username (conn, username);
	  g_free (username);

	  password = g_key_file_get_string  (file, "connection", "password", NULL);
	  vinagre_connection_set_password (conn, password);
	  g_free (password);

	  shared = g_key_file_get_integer (file, "options", "shared", &e);
	  if (e)
	    g_error_free (e);
	  else
	    if (shared == 0 || shared == 1)
	      vinagre_connection_set_shared (conn, shared);
	    else
	      g_message (_("Bad value for 'shared' flag: %d. It is supposed to be 0 or 1. Ignoring it."), shared);
	}

      g_free (host);
    }
  else
    *error_msg = g_strdup (_("Could not find the host address in the file."));

the_end:
  g_free (data);
  g_object_unref (file_a);
  if (file)
    g_key_file_free (file);

  return conn;
}