Example #1
0
void load_data(void)
{
	SoupCookieJar *cookie_jar;
	GTlsDatabase *tlsdb;
	GError *error = NULL;

	/* load cookies */
	if (!private_browsing) {
		ripcurl->Files.cookie_file = g_build_filename(ripcurl->Files.config_dir, cookie_file, NULL);
		if (!ripcurl->Files.cookie_file) {
			print_err("error building cookie file path\n");
		} else {
			cookie_jar = soup_cookie_jar_text_new(ripcurl->Files.cookie_file, FALSE);
			soup_session_add_feature(ripcurl->Global.soup_session, SOUP_SESSION_FEATURE(cookie_jar));
		}
	}

	/* ssl */
	tlsdb = g_tls_file_database_new(ca_file, &error);
	if (error) {
		print_err("error loading ssl database %s: %s\n", ca_file, error->message);
		g_error_free(error);
	}
	g_object_set(G_OBJECT(ripcurl->Global.soup_session), "tls-database", tlsdb, NULL);
	g_object_set(G_OBJECT(ripcurl->Global.soup_session), "ssl-strict", strict_ssl, NULL);

	/* load bookmarks */
	ripcurl->Files.bookmarks_file = g_build_filename(ripcurl->Files.config_dir, bookmarks_file, NULL);
	if (!ripcurl->Files.bookmarks_file) {
		print_err("error building bookmarks file path\n");
	} else {
		ripcurl->Global.bookmarks = read_file(ripcurl->Files.bookmarks_file, ripcurl->Global.bookmarks);
		ripcurl->Global.bookmarks= g_list_reverse(ripcurl->Global.bookmarks);
	}

	/* load history */
	ripcurl->Files.history_file = g_build_filename(ripcurl->Files.config_dir, history_file, NULL);
	if (!ripcurl->Files.history_file) {
		print_err("error building history file path\n");
	} else {
		ripcurl->Global.history = read_file(ripcurl->Files.history_file, ripcurl->Global.history);
	}
}
Example #2
0
static const gchar *
parse_cert_option_as_database (JsonObject *options,
                               const gchar *option,
                               GTlsDatabase **database)
{
  gboolean temporary = FALSE;
  GError *error = NULL;
  const gchar *problem;
  const gchar *file;
  const gchar *data;
  gchar *path;
  gint fd;

  problem = parse_option_file_or_data (options, option, &file, &data);
  if (problem)
    return problem;

  if (file)
    {
      path = expand_filename (file);
      problem = NULL;
    }
  else if (data)
    {
      temporary = TRUE;
      path = g_build_filename (g_get_user_runtime_dir (), "cockpit-bridge-cert-authority.XXXXXX", NULL);
      fd = g_mkstemp (path);
      if (fd < 0)
        {
          g_warning ("couldn't create temporary directory: %s: %s", path, g_strerror (errno));
          problem = "internal-error";
        }
      else
        {
          close (fd);
          if (!g_file_set_contents (path, data, -1, &error))
            {
              g_warning ("couldn't write temporary data to: %s: %s", path, error->message);
              problem = "internal-error";
              g_clear_error (&error);
            }
        }
    }
  else
    {
      /* Not specified */
      *database = NULL;
      return NULL;
    }

  if (problem == NULL)
    {
      *database = g_tls_file_database_new (path, &error);
      if (error)
        {
          g_warning ("couldn't load certificate data: %s: %s", path, error->message);
          problem = "internal-error";
          g_clear_error (&error);
        }
    }

  /* Leave around when problem, for debugging */
  if (temporary && problem == NULL)
    g_unlink (path);

  g_free (path);

  return problem;
}