gboolean
matchKeyring(gconstpointer user_data, gpointer data)
{
  GnomeKeyringFound* found = static_cast<GnomeKeyringFound*>(data);
  const char* keyring = static_cast<const char*>(user_data);
  gboolean keep = !strcmp(found->keyring, keyring);
  if (!keep) {
    gnome_keyring_found_free(found);
  }
  return keep;
}
Exemple #2
0
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;
}