GHashTable* dt_pwstorage_gkeyring_get(const gchar* slot) { GHashTable* table = g_hash_table_new_full (g_str_hash,g_str_equal, g_free, g_free); /* find item for slot */ GList *items=NULL; GnomeKeyringAttributeList *attributes; attributes = g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute)); gnome_keyring_attribute_list_append_string (attributes,"magic",PACKAGE_NAME); gnome_keyring_attribute_list_append_string (attributes,"slot",slot); gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,attributes,&items); gnome_keyring_attribute_list_free(attributes); /* if item found get the attributes into result table and return */ if (items) { GnomeKeyringFound *f = (GnomeKeyringFound *)items->data; /* get all attributes of found item */ gnome_keyring_item_get_attributes_sync (DARKTABLE_KEYRING,f->item_id,&attributes); /* build hash table result */ for (int i=0; i<attributes->len; i++) { GnomeKeyringAttribute *attribute = &gnome_keyring_attribute_list_index (attributes,i); if (attribute != NULL) { if( strcmp(attribute->name,"slot")!=0 && strcmp(attribute->name,"magic")!=0 ) g_hash_table_insert (table,g_strdup (attribute->name),g_strdup(attribute->value.string)); } else break; } gnome_keyring_attribute_list_free(attributes); gnome_keyring_found_free (items->data); } return table; }
static void detailed_key_listing(gchar *keyring, guint32 id) { GnomeKeyringAttributeList *attlist; GnomeKeyringResult result = gnome_keyring_item_get_attributes_sync(keyring, id, &attlist); if (result == GNOME_KEYRING_RESULT_OK) { GnomeKeyringAttribute att, *atts; int i; atts = (GnomeKeyringAttribute *)attlist->data; for (i = 0; i < attlist->len; i++) { att = atts[i]; if (att.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) { printf(" %s = '%s'\n", att.name, att.value.string); } else if (att.type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) { printf(" %s = %u\n", att.name, att.value.integer); } else { printf("Found %d\n", i); } } gnome_keyring_attribute_list_free(attlist); } }