INCLUDES = \
- -I$(top_srcdir)/egg \
- -I$(top_srcdir)/gcr \
- -DSRCDIR=$(srcdir) \
+ -I$(top_builddir) \
+ -I$(top_srcdir) \
+ -DSRCDIR="\"$(srcdir)\"" \
-DGCR_API_SUBJECT_TO_CHANGE \
-DGCK_API_SUBJECT_TO_CHANGE \
+ -DGCR_COMPILATION \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(LIBGCRYPT_CFLAGS)
noinst_PROGRAMS = \
frob-certificate \
+ frob-gnupg-selector \
+ frob-parser \
frob-key \
+ frob-selector \
frob-unlock-options
--- /dev/null
- #include "gcr.h"
- #include "gcr-gnupg-collection.h"
- #include "gcr-gnupg-key.h"
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Author: Stef Walter <stefw@collabora.co.uk>
+ */
+
+#include "config.h"
+
++#include "gcr/gcr.h"
++#include "gcr/gcr-gnupg-collection.h"
++#include "gcr/gcr-gnupg-key.h"
+
+#include <gtk/gtk.h>
+
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+static void
+on_collection_loaded (GObject *source, GAsyncResult *result, gpointer unused)
+{
+ GError *error = NULL;
+
+ _gcr_gnupg_collection_load_finish (GCR_GNUPG_COLLECTION (source), result, &error);
+ if (error) {
+ g_warning ("collection load failed: %s", error->message);
+ g_clear_error (&error);
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ GcrCollection *collection;
+ GcrSelector *selector;
+ GtkDialog *dialog;
+
+ gtk_init (&argc, &argv);
+
+ dialog = GTK_DIALOG (gtk_dialog_new ());
+ g_object_ref_sink (dialog);
+
+ collection = _gcr_gnupg_collection_new (NULL);
+ selector = gcr_selector_new (collection, GCR_GNUPG_KEY_COLUMNS, GCR_SELECTOR_MODE_MULTIPLE);
+
+ gtk_widget_show (GTK_WIDGET (selector));
+ gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (dialog)), GTK_WIDGET (selector));
+
+ _gcr_gnupg_collection_load_async (GCR_GNUPG_COLLECTION (collection), NULL,
+ on_collection_loaded, NULL);
+
+ gtk_window_set_default_size (GTK_WINDOW (dialog), 550, 400);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 20);
+
+ g_object_unref (collection);
+
+ gtk_dialog_run (dialog);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ g_object_unref (dialog);
+
+ return 0;
+}
--- /dev/null
- #include "gcr.h"
+
+#include "config.h"
+
++#include "gcr/gcr.h"
+
+#include <gtk/gtk.h>
+
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+static void
+chdir_base_dir (char* argv0)
+{
+ gchar *dir, *base;
+
+ dir = g_path_get_dirname (argv0);
+ if (chdir (dir) < 0)
+ g_warning ("couldn't change directory to: %s: %s",
+ dir, g_strerror (errno));
+
+ base = g_path_get_basename (dir);
+ if (strcmp (base, ".libs") == 0) {
+ if (chdir ("..") < 0)
+ g_warning ("couldn't change directory to ..: %s",
+ g_strerror (errno));
+ }
+
+ g_free (base);
+ g_free (dir);
+}
+
+static void
+on_parser_parsed (GcrParser *parser, gpointer user_data)
+{
+ GcrSimpleCollection *collection = user_data;
+ GcrRenderer *renderer;
+
+ renderer = gcr_renderer_create (gcr_parser_get_parsed_label (parser),
+ gcr_parser_get_parsed_attributes (parser));
+
+ if (renderer) {
+ gcr_simple_collection_add (collection, G_OBJECT (renderer));
+ g_object_unref (renderer);
+ }
+}
+
+static void
+add_to_selector (GcrParser *parser, const gchar *path)
+{
+ GError *err = NULL;
+ guchar *data;
+ gsize n_data;
+
+ if (!g_file_get_contents (path, (gchar**)&data, &n_data, NULL))
+ g_error ("couldn't read file: %s", path);
+
+ if (!gcr_parser_parse_data (parser, data, n_data, &err))
+ g_error ("couldn't parse data: %s", err->message);
+
+ g_free (data);
+}
+
+int
+main (int argc, char *argv[])
+{
+ GcrCollection *collection;
+ GcrSelector *selector;
+ GtkDialog *dialog;
+ GcrParser *parser;
+ int i;
+
+ gtk_init (&argc, &argv);
+
+ dialog = GTK_DIALOG (gtk_dialog_new ());
+ g_object_ref_sink (dialog);
+
+ collection = gcr_simple_collection_new ();
+ selector = gcr_selector_new (collection, GCR_CERTIFICATE_COLUMNS, GCR_SELECTOR_MODE_MULTIPLE);
+
+ gtk_widget_show (GTK_WIDGET (selector));
+ gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (dialog)), GTK_WIDGET (selector));
+
+ gtk_window_set_default_size (GTK_WINDOW (dialog), 550, 400);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 20);
+
+ parser = gcr_parser_new ();
+ g_signal_connect (parser, "parsed", G_CALLBACK (on_parser_parsed), collection);
+
+ if (argc == 1) {
+ chdir_base_dir (argv[0]);
+ add_to_selector (parser, "files/ca-certificates.crt");
+ } else {
+ for (i = 1; i < argc; ++i)
+ add_to_selector (parser, argv[i]);
+ }
+
+ g_object_unref (parser);
+ g_object_unref (collection);
+
+ gtk_dialog_run (dialog);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ g_object_unref (dialog);
+
+ return 0;
+}
--- /dev/null
- #include "gcr.h"
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ Copyright (C) 2011 Collabora Ltd.
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stefw@collabora.co.uk>
+*/
+
+#include "config.h"
+
++#include "gcr/gcr.h"
+#include "gcr/gcr-util.h"
+
+#include <errno.h>
+
+static void
+on_line_parsed_match_template (const gchar *line, gpointer user_data)
+{
+ const gchar ***matching = user_data;
+
+ g_assert (matching);
+ g_assert (*matching);
+
+ /* Must be another line to match */
+ g_assert ((*matching)[0]);
+
+ /* Match this line against expected, and increment to next */
+ g_assert_cmpstr ((*matching)[0], ==, line);
+ (*matching)++;
+}
+
+static void
+test_parse_lines (void)
+{
+ GString *string = g_string_new ("first line\nsecond line\n\nlast line");
+ const gchar *matches[] = { "first line", "second line", "", NULL };
+ const gchar **matching = matches;
+
+ _gcr_util_parse_lines (string, FALSE, on_line_parsed_match_template, &matching);
+
+ /* All lines should have matched */
+ g_assert (*matching == NULL);
+
+ /* The last line should still be here */
+ g_assert_cmpstr (string->str, ==, "last line");
+ g_string_free (string, TRUE);
+}
+
+static void
+test_parse_lines_and_last (void)
+{
+ GString *string = g_string_new ("first line\nsecond line\n\nlast line");
+ const gchar *matches[] = { "first line", "second line", "", "last line", NULL };
+ const gchar **matching = matches;
+
+ _gcr_util_parse_lines (string, FALSE, on_line_parsed_match_template, &matching);
+ _gcr_util_parse_lines (string, TRUE, on_line_parsed_match_template, &matching);
+
+ /* All lines should have matched */
+ g_assert (*matching == NULL);
+
+ /* No more data */
+ g_assert_cmpstr (string->str, ==, "");
+ g_assert_cmpuint (string->len, ==, 0);
+ g_string_free (string, TRUE);
+}
+
+static void
+test_parse_lines_dos (void)
+{
+ GString *string = g_string_new ("first line\r\nsecond line\r\n\r\nlast line");
+ const gchar *matches[] = { "first line", "second line", "", "last line", NULL };
+ const gchar **matching = matches;
+
+ _gcr_util_parse_lines (string, FALSE, on_line_parsed_match_template, &matching);
+ _gcr_util_parse_lines (string, TRUE, on_line_parsed_match_template, &matching);
+
+ /* All lines should have matched */
+ g_assert (*matching == NULL);
+
+ /* No more data */
+ g_assert_cmpstr (string->str, ==, "");
+ g_assert_cmpuint (string->len, ==, 0);
+ g_string_free (string, TRUE);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/gcr/util/test_parse_lines", test_parse_lines);
+ g_test_add_func ("/gcr/util/test_parse_lines_and_last", test_parse_lines_and_last);
+ g_test_add_func ("/gcr/util/test_parse_lines_dos", test_parse_lines_dos);
+
+ return g_test_run ();
+}