summaryrefslogtreecommitdiffstats
path: root/src/gtk-helpers/abrt-keyring.c
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2011-03-14 18:14:07 +0100
committerJiri Moskovcak <jmoskovc@redhat.com>2011-03-14 18:14:07 +0100
commit1147945856ed4431ab3b49f88c8c0aa11c6ad8e1 (patch)
tree099a7176332c2dbd48ca33b84cca955087d227b7 /src/gtk-helpers/abrt-keyring.c
parent73cc48d58dd43bd54d0c00f2fb6b5441bb250dcf (diff)
downloadabrt-1147945856ed4431ab3b49f88c8c0aa11c6ad8e1.tar.gz
abrt-1147945856ed4431ab3b49f88c8c0aa11c6ad8e1.tar.xz
abrt-1147945856ed4431ab3b49f88c8c0aa11c6ad8e1.zip
forgot to push the libreportgtk
Diffstat (limited to 'src/gtk-helpers/abrt-keyring.c')
-rw-r--r--src/gtk-helpers/abrt-keyring.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/gtk-helpers/abrt-keyring.c b/src/gtk-helpers/abrt-keyring.c
new file mode 100644
index 00000000..6ced7a9d
--- /dev/null
+++ b/src/gtk-helpers/abrt-keyring.c
@@ -0,0 +1,108 @@
+#include <gnome-keyring.h>
+#include <string.h>
+#include <stdlib.h>
+#include "abrtlib.h"
+
+static char *keyring;
+
+static guint32 search_item_id(const char *event_name)
+{
+ GnomeKeyringAttributeList *attrs = gnome_keyring_attribute_list_new();
+ GList *found;
+ //let's hope 0 is not valid item_id
+ guint32 item_id = 0;
+ gnome_keyring_attribute_list_append_string(attrs, "libreportEventConfig", event_name);
+ GnomeKeyringResult result = gnome_keyring_find_items_sync(
+ GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ attrs,
+ &found);
+ if(result != GNOME_KEYRING_RESULT_OK)
+ return item_id;
+ if(found)
+ {
+ item_id = ((GnomeKeyringFound *)found->data)->item_id;
+ gnome_keyring_found_list_free(found);
+ }
+ return item_id;
+}
+
+void abrt_keyring_save_settings(const char *event_name, event_config_t *ec)
+{
+ GList *l;
+ GnomeKeyringAttributeList *attrs = gnome_keyring_attribute_list_new();
+ guint32 item_id;
+ /* add string id which we use to search for items */
+ gnome_keyring_attribute_list_append_string(attrs, "libreportEventConfig", event_name);
+ for(l = g_list_first(ec->options); l != NULL; l = g_list_next(l))
+ {
+ event_option_t *op = (event_option_t *)l->data;
+ gnome_keyring_attribute_list_append_string(attrs, op->name, op->value);
+ }
+
+ GnomeKeyringResult result;
+ item_id = search_item_id(event_name);
+ if(item_id)
+ {
+ VERB2 log("updating item with id: %i", item_id);
+ /* found existing item, so just update the values */
+ result = gnome_keyring_item_set_attributes_sync(keyring, item_id, attrs);
+ }
+ else
+ {
+ /* did't find existing item, so create a new one */
+ result = gnome_keyring_item_create_sync(keyring,
+ GNOME_KEYRING_ITEM_GENERIC_SECRET, /* type */
+ event_name, /* display name */
+ attrs, /* attributes */
+ NULL, /* secret - no special handling for password it's stored in attrs */
+ 1, /* update if exist */
+ &item_id);
+ VERB2 log("created new item with id: %i", item_id);
+ }
+
+ if(result != GNOME_KEYRING_RESULT_OK)
+ {
+ VERB2 log("error occured, settings is not saved!");
+ return;
+ }
+ VERB2 log("saved");
+}
+
+void abrt_keyring_load_settings(const char *event_name, event_config_t *ec)
+{
+ GnomeKeyringAttributeList *attrs = gnome_keyring_attribute_list_new();
+ guint item_id = search_item_id(event_name);
+ if(!item_id)
+ return;
+ GnomeKeyringResult result = gnome_keyring_item_get_attributes_sync(
+ keyring,
+ item_id,
+ &attrs);
+ VERB2 log("num attrs %i", attrs->len);
+ if(result != GNOME_KEYRING_RESULT_OK)
+ return;
+ guint index;
+ for(index = 0; index < attrs->len; index++)
+ {
+ VERB2 log("load %s", g_array_index(attrs, GnomeKeyringAttribute, index).name);
+ //VERB2 log("load %s", g_array_index(attrs, GnomeKeyringAttribute, index).value);
+ }
+}
+
+void init_gnome_keyring()
+{
+ if(!gnome_keyring_is_available())
+ {
+ VERB2 log("Cannot connect to the Gnome Keyring daemon.");
+ return;
+ }
+ GnomeKeyringResult result = gnome_keyring_get_default_keyring_sync(&keyring);
+ if(result != GNOME_KEYRING_RESULT_OK || keyring == NULL)
+ VERB2 log("can't get the default kerying");
+ /*
+ The default keyring might not be set - in that case result = OK, but the
+ keyring = NULL
+ use gnome_keyring_list_keyring_names () to list all and pick the first one?
+ */
+ VERB2 log("%s", keyring);
+} \ No newline at end of file