Merge lp:~mardy/signon-keyring-extension/libsecret into lp:signon-keyring-extension

Proposed by Alberto Mardegan
Status: Merged
Approved by: Ken VanDine
Approved revision: 30
Merged at revision: 30
Proposed branch: lp:~mardy/signon-keyring-extension/libsecret
Merge into: lp:signon-keyring-extension
Diff against target: 782 lines (+231/-322)
8 files modified
common-vars.pri (+1/-1)
debian/changelog (+7/-0)
debian/control (+1/-1)
src/secrets-storage.cpp (+70/-132)
src/secrets-storage.h (+0/-1)
src/src.pro (+3/-1)
tests/mocked-gnome-keyring.c (+148/-185)
tests/tests.pro (+1/-1)
To merge this branch: bzr merge lp:~mardy/signon-keyring-extension/libsecret
Reviewer Review Type Date Requested Status
Ken VanDine Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+171224@code.launchpad.net

Commit message

Migrate from libgnome-keyring to libsecret

Also tag a new upstream release.

Description of the change

Migrate from libgnome-keyring to libsecret

Also tag a new upstream release.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Excellent, looks much better than the gnome-keyring API. Tests pass and it works on the phone, ship it!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'common-vars.pri'
2--- common-vars.pri 2013-06-03 15:28:51 +0000
3+++ common-vars.pri 2013-06-25 07:19:28 +0000
4@@ -14,7 +14,7 @@
5 # Project version
6 # remember to update debian/* files if you changes this
7 #-----------------------------------------------------------------------------
8-PROJECT_VERSION = 0.5.1
9+PROJECT_VERSION = 0.6
10
11 # End of File
12
13
14=== modified file 'debian/changelog'
15--- debian/changelog 2013-06-05 18:49:03 +0000
16+++ debian/changelog 2013-06-25 07:19:28 +0000
17@@ -1,3 +1,10 @@
18+signon-keyring-extension (0.6-0ubuntu1) UNRELEASED; urgency=low
19+
20+ * New upstream version
21+ - migrate from libgnome-keyring to libsecret
22+
23+ -- Alberto Mardegan <alberto.mardegan@canonical.com> Tue, 25 Jun 2013 10:14:29 +0300
24+
25 signon-keyring-extension (0.5.1daily13.06.05.1-0ubuntu1) saucy; urgency=low
26
27 [ Ken VanDine ]
28
29=== modified file 'debian/control'
30--- debian/control 2013-06-03 15:28:51 +0000
31+++ debian/control 2013-06-25 07:19:28 +0000
32@@ -2,7 +2,7 @@
33 Priority: optional
34 Maintainer: Ubuntu Desktop Team <ubuntu-desktop@lists.ubuntu.com>
35 Build-Depends: debhelper (>= 9),
36- libgnome-keyring-dev,
37+ libsecret-1-dev,
38 pkg-config,
39 qt5-default,
40 qt5-qmake,
41
42=== modified file 'src/secrets-storage.cpp'
43--- src/secrets-storage.cpp 2013-04-26 11:32:40 +0000
44+++ src/secrets-storage.cpp 2013-06-25 07:19:28 +0000
45@@ -25,10 +25,19 @@
46 #include "secrets-storage.h"
47
48 #include <QDataStream>
49-#include <gnome-keyring.h>
50+#include <libsecret/secret.h>
51
52 using namespace SignOn;
53
54+static const SecretSchema signonSchema = {
55+ "com.ubuntu.OnlineAccounts.Secrets", SECRET_SCHEMA_DONT_MATCH_NAME,
56+ {
57+ { "signon-type", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
58+ { "signon-id", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
59+ { "signon-method", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
60+ }
61+};
62+
63 SecretsStorage::SecretsStorage(QObject *parent) :
64 AbstractSecretsStorage(parent),
65 m_keyringName()
66@@ -46,17 +55,7 @@
67 if (configuration.contains(QLatin1String("KeyringName"))) {
68 m_keyringName = configuration.value(QLatin1String("KeyringName")).toByteArray();
69 } else {
70- GnomeKeyringResult ret;
71- gchar *name;
72-
73- ret = gnome_keyring_get_default_keyring_sync(&name);
74- if (ret != GNOME_KEYRING_RESULT_OK) {
75- BLAME() << "Couldn't get default keyring name:" << ret;
76- return false;
77- }
78-
79- m_keyringName = QByteArray(name);
80- g_free(name);
81+ m_keyringName = QByteArray(SECRET_COLLECTION_DEFAULT);
82 }
83 TRACE() << "Using keyring:" << m_keyringName;
84
85@@ -157,39 +156,36 @@
86 quint32 method,
87 const QByteArray &secret)
88 {
89- GnomeKeyringResult ret;
90- guint32 createdItemId;
91-
92 TRACE() << "Storing secret:" << id <<
93 "type:" << type <<
94 "method:" << method;
95
96- GnomeKeyringAttributeList *attributes = gnome_keyring_attribute_list_new();
97- gnome_keyring_attribute_list_append_uint32(attributes, "signon-type", type);
98- gnome_keyring_attribute_list_append_uint32(attributes, "signon-id", id);
99- if (type == Data) {
100- gnome_keyring_attribute_list_append_uint32(attributes,
101- "signon-method", method);
102- }
103-
104 QString displayName =
105 QString::fromLatin1("Ubuntu Web Account: id %1-%2").arg(id).arg(type);
106 QByteArray ba = displayName.toUtf8();
107
108- ret = gnome_keyring_item_create_sync(keyring(),
109- GNOME_KEYRING_ITEM_GENERIC_SECRET,
110- ba.constData(),
111- attributes,
112- secret.constData(),
113- TRUE,
114- &createdItemId);
115- gnome_keyring_attribute_list_free(attributes);
116- if (ret != GNOME_KEYRING_RESULT_OK) {
117- TRACE() << "Got error from GNOME keyring:" << ret;
118+ const gchar *signonMethod = (type == Data) ? "signon-method" : NULL;
119+
120+ gboolean ok;
121+ GError *error = NULL;
122+ ok = secret_password_store_sync(&signonSchema,
123+ keyring(),
124+ ba.constData(),
125+ secret.constData(),
126+ NULL,
127+ &error,
128+ "signon-type", type,
129+ "signon-id", id,
130+ signonMethod, method,
131+ NULL);
132+
133+
134+ if (!ok) {
135+ TRACE() << "Got error from GNOME keyring:" << error->message;
136+ g_error_free(error);
137 return false;
138 }
139
140- Q_UNUSED(createdItemId);
141 return true;
142 }
143
144@@ -198,50 +194,29 @@
145 quint32 method,
146 QByteArray &secret)
147 {
148- GList *found = 0;
149- GnomeKeyringResult ret;
150-
151 TRACE() << "id:" << id << "type:" << type << "method:" << method;
152- GnomeKeyringAttributeList *attributes = gnome_keyring_attribute_list_new();
153- gnome_keyring_attribute_list_append_uint32(attributes, "signon-type", type);
154- gnome_keyring_attribute_list_append_uint32(attributes, "signon-id", id);
155- if (type == Data) {
156- gnome_keyring_attribute_list_append_uint32(attributes, "signon-method",
157- method);
158- }
159-
160- ret = gnome_keyring_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET,
161- attributes,
162- &found);
163- gnome_keyring_attribute_list_free(attributes);
164- if (ret != GNOME_KEYRING_RESULT_OK) {
165- TRACE() << "Credentials loading failed:" << ret;
166+
167+ const gchar *signonMethod = (type == Data) ? "signon-method" : NULL;
168+
169+ GError *error = NULL;
170+ gchar *data = secret_password_lookup_sync(&signonSchema,
171+ NULL,
172+ &error,
173+ "signon-type", type,
174+ "signon-id", id,
175+ signonMethod, method,
176+ NULL);
177+
178+ if (error != NULL) {
179+ TRACE() << "Credentials loading failed:" << error->message;
180+ g_error_free(error);
181 return false;
182 }
183
184- for (GList *list = found; list != 0; list = list->next) {
185- GnomeKeyringFound *result = (GnomeKeyringFound *)list->data;
186-
187- if (!isActiveKeyring(result->keyring))
188- continue;
189-
190- GnomeKeyringItemInfo *info;
191- ret = gnome_keyring_item_get_info_sync(result->keyring,
192- result->item_id,
193- &info);
194- if (ret != GNOME_KEYRING_RESULT_OK) {
195- TRACE() << "Error loading credentials:" << ret;
196- break;
197- }
198-
199- gchar *data = gnome_keyring_item_info_get_secret(info);
200- secret = QByteArray(data);
201- g_free(data);
202- gnome_keyring_item_info_free(info);
203- }
204- gnome_keyring_found_list_free(found);
205-
206- return ret == GNOME_KEYRING_RESULT_OK;
207+ secret = QByteArray(data);
208+ g_free(data);
209+
210+ return data != NULL;
211 }
212
213 bool SecretsStorage::removeSecrets(SignonSecretType type,
214@@ -249,78 +224,41 @@
215 quint32 method,
216 QueryFields fields)
217 {
218- GList *found = 0;
219- GnomeKeyringResult ret;
220+ GHashTable *attributes = g_hash_table_new(g_str_hash, g_str_equal);
221+ gchar id_str[16];
222+ gchar method_str[16];
223+ gchar type_str[16];
224
225- GnomeKeyringAttributeList *attributes = gnome_keyring_attribute_list_new();
226 if (fields & IdField) {
227- gnome_keyring_attribute_list_append_uint32(attributes,
228- "signon-id", id);
229+ snprintf(id_str, sizeof(id_str), "%d", id);
230+ g_hash_table_insert(attributes, gpointer("signon-id"), id_str);
231 }
232 if (fields & MethodField) {
233- gnome_keyring_attribute_list_append_uint32(attributes,
234- "signon-method", method);
235+ snprintf(method_str, sizeof(method_str), "%d", method);
236+ g_hash_table_insert(attributes, gpointer("signon-method"), method_str);
237 }
238 if (fields & TypeField) {
239- gnome_keyring_attribute_list_append_uint32(attributes,
240- "signon-type", type);
241+ snprintf(type_str, sizeof(type_str), "%d", type);
242+ g_hash_table_insert(attributes, gpointer("signon-type"), type_str);
243 }
244
245- ret = gnome_keyring_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET,
246- attributes,
247- &found);
248- if (ret != GNOME_KEYRING_RESULT_OK) {
249- if (ret == GNOME_KEYRING_RESULT_NO_MATCH) {
250- return true;
251- }
252- TRACE() << "Credentials search failed:" << ret;
253+ GError *error = NULL;
254+ secret_password_clearv_sync(&signonSchema,
255+ attributes,
256+ NULL,
257+ &error);
258+ if (error != NULL) {
259+ TRACE() << "Credentials search failed:" << error->message;
260+ g_error_free(error);
261 return false;
262 }
263
264- for (GList *list = found; list != 0; list = list->next) {
265- GnomeKeyringFound *result = (GnomeKeyringFound *)list->data;
266-
267- if (!isActiveKeyring(result->keyring))
268- continue;
269-
270- ret = gnome_keyring_item_delete_sync(result->keyring, result->item_id);
271- if (ret != GNOME_KEYRING_RESULT_OK) {
272- TRACE() << "Error deleting credentials:" << ret;
273- break;
274- }
275- }
276- gnome_keyring_found_list_free(found);
277-
278- return ret == GNOME_KEYRING_RESULT_OK;
279+ g_hash_table_unref(attributes);
280+
281+ return true;
282 }
283
284 const char *SecretsStorage::keyring() const
285 {
286 return m_keyringName.isEmpty() ? 0 : m_keyringName.constData();
287 }
288-
289-bool SecretsStorage::isActiveKeyring(const char *keyringName) const
290-{
291- /* This method is needed not to apply the same hack in different parts of
292- * the code.
293- */
294- const gchar *activeKeyringName = keyring();
295- if (qstrcmp(keyringName, activeKeyringName) == 0)
296- return true;
297-
298- /* Unfortunately GNOME keyring doesn't return the proper name of the
299- * default keyring (it returns NULL). This means that if the active
300- * keyring is the default keyring the above string comparison would fail.
301- * In other words, if the current keyring is NULL, we have no clue on what
302- * to return from this method.
303- * https://bugzilla.gnome.org/show_bug.cgi?id=664454
304- *
305- * If the current keyring is NULL, we just return true.
306- */
307- if (activeKeyringName == 0) {
308- return true;
309- } else {
310- return false;
311- }
312-}
313-
314
315=== modified file 'src/secrets-storage.h'
316--- src/secrets-storage.h 2011-11-21 12:46:50 +0000
317+++ src/secrets-storage.h 2013-06-25 07:19:28 +0000
318@@ -82,7 +82,6 @@
319 quint32 method,
320 QueryFields fields);
321 const char *keyring() const;
322- bool isActiveKeyring(const char *keyringName) const;
323
324 QByteArray m_keyringName;
325 };
326
327=== modified file 'src/src.pro'
328--- src/src.pro 2011-11-18 17:06:13 +0000
329+++ src/src.pro 2013-06-25 07:19:28 +0000
330@@ -16,9 +16,11 @@
331
332 QMAKE_CXXFLAGS += -Wno-missing-field-initializers
333
334+DEFINES += QT_NO_KEYWORDS
335+
336 PKGCONFIG += \
337 SignOnExtension \
338- gnome-keyring-1
339+ libsecret-1
340
341 # The following use of pkg-config + sed is a hack to workaround a qmake
342 # limitation: the CFLAGS variable is not used with the moc compiler, so the
343
344=== modified file 'tests/mocked-gnome-keyring.c'
345--- tests/mocked-gnome-keyring.c 2012-08-14 12:26:01 +0000
346+++ tests/mocked-gnome-keyring.c 2013-06-25 07:19:28 +0000
347@@ -21,18 +21,18 @@
348 */
349
350 #include "mocked-gnome-keyring.h"
351-#include <gnome-keyring.h>
352+#include <libsecret/secret.h>
353
354-#define DEFAULT_KEYRING "mock-keyring"
355+#define DEFAULT_KEYRING SECRET_COLLECTION_DEFAULT
356
357 static GHashTable *keyrings = NULL;
358 static guint32 last_item_id = 123;
359
360 typedef struct {
361 guint32 id;
362- GnomeKeyringItemType type;
363+ const SecretSchema *schema;
364 char *display_name;
365- GnomeKeyringAttributeList *attributes;
366+ GHashTable *attributes;
367 char *secret;
368 } MockedItem;
369
370@@ -40,55 +40,52 @@
371 GList *items;
372 } MockedKeyring;
373
374+static GHashTable *
375+copy_g_hash_table(GHashTable *table)
376+{
377+ GHashTable *copy;
378+ GHashTableIter iter;
379+ gpointer key, value;
380+
381+ copy = g_hash_table_new_full(g_str_hash, g_str_equal,
382+ g_free, g_free);
383+ g_hash_table_iter_init(&iter, table);
384+ while (g_hash_table_iter_next(&iter, &key, &value)) {
385+ g_hash_table_insert(copy, g_strdup(key), g_strdup(value));
386+ }
387+
388+ return copy;
389+}
390+
391 static MockedItem *
392-mocked_item_new(GnomeKeyringItemType type,
393+mocked_item_new(const SecretSchema *schema,
394 const char *display_name,
395- GnomeKeyringAttributeList *attributes,
396+ GHashTable *attributes,
397 const char *secret)
398 {
399 MockedItem *item = g_slice_new0(MockedItem);
400 item->id = last_item_id++;
401- item->type = type;
402+ item->schema = schema;
403 item->display_name = g_strdup(display_name);
404- item->attributes = gnome_keyring_attribute_list_copy(attributes);
405+ item->attributes = copy_g_hash_table(attributes);
406 item->secret = g_strdup(secret);
407 return item;
408 }
409
410 static gboolean
411-attributes_are_equal (GnomeKeyringAttribute *a1,
412- GnomeKeyringAttribute *a2)
413-{
414- if (g_strcmp0(a1->name, a2->name) != 0) return FALSE;
415- if (a1->type != a2->type) return FALSE;
416- if (a1->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
417- return g_strcmp0(a1->value.string, a2->value.string) == 0;
418- } else {
419- return a1->value.integer == a2->value.integer;
420- }
421-}
422-
423-static gboolean
424 mocked_item_has_attributes(MockedItem *item,
425- GnomeKeyringAttributeList *attributes)
426+ GHashTable *attributes)
427 {
428- guint i, j;
429-
430- for (i = 0; i < attributes->len; i++) {
431- gboolean found = FALSE;
432- GnomeKeyringAttribute *required =
433- &g_array_index(attributes, GnomeKeyringAttribute, i);
434-
435- for (j = 0; j < item->attributes->len; j++) {
436- GnomeKeyringAttribute *attribute =
437- &g_array_index(item->attributes, GnomeKeyringAttribute, j);
438- if (attributes_are_equal(attribute, required)) {
439- found = TRUE;
440- break;
441- }
442- }
443-
444- if (!found) return FALSE;
445+ GHashTableIter iter;
446+ gpointer key, value;
447+
448+ g_hash_table_iter_init(&iter, attributes);
449+ while (g_hash_table_iter_next(&iter, &key, &value)) {
450+ gpointer item_value;
451+
452+ item_value = g_hash_table_lookup(item->attributes, key);
453+ if (item_value == NULL || g_strcmp0(item_value, value) != 0)
454+ return FALSE;
455 }
456
457 return TRUE;
458@@ -98,24 +95,11 @@
459 mocked_item_free(MockedItem *item)
460 {
461 g_free(item->display_name);
462- gnome_keyring_attribute_list_free(item->attributes);
463+ g_hash_table_unref(item->attributes);
464 g_free(item->secret);
465 g_slice_free(MockedItem, item);
466 }
467
468-static MockedItem *
469-mocked_keyring_get_item(MockedKeyring *keyring, guint32 item_id)
470-{
471- GList *list;
472-
473- for (list = keyring->items; list != NULL; list = g_list_next(list)) {
474- MockedItem *item = list->data;
475- if (item->id == item_id) return item;
476- }
477-
478- return NULL;
479-}
480-
481 static MockedKeyring *
482 mocked_keyring_new()
483 {
484@@ -131,174 +115,153 @@
485 g_hash_table_insert(keyrings, TEST_KEYRING, mocked_keyring_new());
486 }
487
488-GnomeKeyringResult
489-gnome_keyring_get_default_keyring_sync(char **keyring)
490+GList *
491+find_items(const SecretSchema *schema,
492+ GHashTable *attributes)
493 {
494- *keyring = g_strdup(DEFAULT_KEYRING);
495- return GNOME_KEYRING_RESULT_OK;
496+ GHashTableIter iter;
497+ const gchar *keyring_name;
498+ MockedKeyring *keyring;
499+ GList *results = NULL;
500+
501+ g_return_val_if_fail (attributes != NULL, NULL);
502+
503+ g_hash_table_iter_init(&iter, keyrings);
504+ while (g_hash_table_iter_next(&iter,
505+ (gpointer)&keyring_name,
506+ (gpointer)&keyring)) {
507+ GList *list;
508+
509+ for (list = keyring->items; list != NULL; list = g_list_next(list)) {
510+ MockedItem *item = list->data;
511+ if (item->schema != schema) continue;
512+
513+ if (!mocked_item_has_attributes(item, attributes)) continue;
514+
515+ results = g_list_prepend(results, item);
516+ }
517+ }
518+
519+ return results;
520 }
521
522-GnomeKeyringResult
523-gnome_keyring_item_create_sync(const char *keyring,
524- GnomeKeyringItemType type,
525- const char *display_name,
526- GnomeKeyringAttributeList *attributes,
527- const char *secret,
528- gboolean update_if_exists,
529- guint32 *item_id)
530+gboolean
531+secret_password_store_sync(const SecretSchema *schema,
532+ const gchar *collection,
533+ const gchar *display_name,
534+ const gchar *secret,
535+ G_GNUC_UNUSED GCancellable *cancellable,
536+ GError **error,
537+ ...)
538 {
539- GList *list, *found = NULL;
540- GnomeKeyringFound *existing_result = NULL;
541+ GList *found = NULL;
542 MockedKeyring *mocked_keyring;
543-
544- g_return_val_if_fail (keyring != NULL,
545- GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
546- g_return_val_if_fail (type < GNOME_KEYRING_ITEM_LAST_TYPE,
547- GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
548-
549- mocked_keyring = g_hash_table_lookup (keyrings, keyring);
550- if (G_UNLIKELY (mocked_keyring == NULL))
551- return GNOME_KEYRING_RESULT_NO_SUCH_KEYRING;
552-
553- gnome_keyring_find_items_sync(type, attributes, &found);
554- for (list = found; list != NULL; list = g_list_next(list)) {
555- GnomeKeyringFound *result = list->data;
556- if (g_strcmp0(result->keyring, keyring) == 0) {
557- existing_result = result;
558- break;
559- }
560+ GHashTable *attributes;
561+ gpointer existing_result;
562+ va_list va;
563+
564+ g_return_val_if_fail (schema != NULL, FALSE);
565+ g_return_val_if_fail (collection != NULL, FALSE);
566+
567+ g_debug("%s, collection %s", G_STRFUNC, collection);
568+ mocked_keyring = g_hash_table_lookup (keyrings, collection);
569+ if (G_UNLIKELY (mocked_keyring == NULL)) {
570+ g_set_error_literal(error, G_DBUS_ERROR, G_DBUS_ERROR_BAD_ADDRESS,
571+ "No such keyring");
572+ return FALSE;
573 }
574- gnome_keyring_found_list_free(found);
575+
576+ va_start (va, error);
577+ attributes = secret_attributes_buildv (schema, va);
578+ va_end (va);
579+
580+ found = find_items(schema, attributes);
581+ existing_result = (found != NULL) ? found->data : NULL;
582+ g_list_free(found);
583
584 if (existing_result != NULL) {
585- if (!update_if_exists) return GNOME_KEYRING_RESULT_ALREADY_EXISTS;
586-
587 /* Update the existing item */
588- MockedItem *item = mocked_keyring_get_item(mocked_keyring,
589- existing_result->item_id);
590- g_assert(item != NULL);
591+ MockedItem *item = existing_result;
592
593 g_free(item->display_name);
594 item->display_name = g_strdup(display_name);
595
596 g_free(item->secret);
597 item->secret = g_strdup(secret);
598-
599- if (item_id != NULL)
600- *item_id = item->id;
601 } else {
602 MockedItem *item =
603- mocked_item_new(type, display_name, attributes, secret);
604- if (item_id != NULL)
605- *item_id = item->id;
606+ mocked_item_new(schema, display_name, attributes, secret);
607
608 mocked_keyring->items = g_list_prepend(mocked_keyring->items,
609 item);
610 }
611- return GNOME_KEYRING_RESULT_OK;
612-}
613-
614-GnomeKeyringResult
615-gnome_keyring_find_items_sync(GnomeKeyringItemType type,
616- GnomeKeyringAttributeList *attributes,
617- GList **found)
618+
619+ g_hash_table_unref(attributes);
620+ return TRUE;
621+}
622+
623+gchar *
624+secret_password_lookup_sync(const SecretSchema *schema,
625+ G_GNUC_UNUSED GCancellable *cancellable,
626+ GError **error,
627+ ...)
628+{
629+ MockedItem *item;
630+ GHashTable *attributes;
631+ GList *found;
632+ va_list va;
633+
634+ g_return_val_if_fail (schema != NULL, FALSE);
635+ g_debug("%s", G_STRFUNC);
636+
637+ va_start (va, error);
638+ attributes = secret_attributes_buildv (schema, va);
639+ va_end (va);
640+
641+ found = find_items(schema, attributes);
642+ item = (found != NULL) ? found->data : NULL;
643+ g_list_free(found);
644+
645+ if (item) {
646+ g_debug("Found: %s", item->secret);
647+ } else {
648+ g_debug("Item not found");
649+ }
650+ return item ? g_strdup(item->secret) : NULL;
651+}
652+
653+gboolean
654+secret_password_clearv_sync(const SecretSchema* schema,
655+ GHashTable *attributes,
656+ G_GNUC_UNUSED GCancellable *cancellable,
657+ G_GNUC_UNUSED GError **error)
658 {
659 GHashTableIter iter;
660 const gchar *keyring_name;
661 MockedKeyring *keyring;
662- GList *results = NULL;
663+ gboolean found = FALSE;
664
665- g_return_val_if_fail (type < GNOME_KEYRING_ITEM_LAST_TYPE,
666- GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
667+ g_return_val_if_fail (schema != NULL, FALSE);
668+ g_debug("%s", G_STRFUNC);
669
670 g_hash_table_iter_init(&iter, keyrings);
671 while (g_hash_table_iter_next(&iter,
672 (gpointer)&keyring_name,
673 (gpointer)&keyring)) {
674- GList *list;
675+ GList *list, *next;
676
677- for (list = keyring->items; list != NULL; list = g_list_next(list)) {
678- GnomeKeyringFound *found;
679+ for (list = keyring->items; list != NULL; list = next) {
680 MockedItem *item = list->data;
681- if (item->type != type) continue;
682+ next = g_list_next(list);
683+ if (item->schema != schema) continue;
684
685 if (!mocked_item_has_attributes(item, attributes)) continue;
686
687- found = g_slice_new0(GnomeKeyringFound);
688- found->keyring = g_strdup(keyring_name);
689- found->item_id = item->id;
690- found->attributes =
691- gnome_keyring_attribute_list_copy(item->attributes);
692- found->secret = g_strdup(item->secret);
693- results = g_list_prepend(results, found);
694+ g_debug("Found item!");
695+ mocked_item_free(item);
696+ keyring->items = g_list_delete_link(keyring->items, list);
697+ found = TRUE;
698 }
699 }
700-
701- *found = results;
702- return results != NULL ?
703- GNOME_KEYRING_RESULT_OK : GNOME_KEYRING_RESULT_NO_MATCH;
704-}
705-
706-void
707-gnome_keyring_found_free(GnomeKeyringFound *found)
708-{
709- g_free(found->keyring);
710- gnome_keyring_attribute_list_free(found->attributes);
711- g_free(found->secret);
712- g_slice_free(GnomeKeyringFound, found);
713-}
714-
715-GnomeKeyringResult
716-gnome_keyring_item_get_info_sync(const char *keyring,
717- guint32 id,
718- GnomeKeyringItemInfo **info)
719-{
720- GnomeKeyringItemInfo *result;
721- MockedKeyring *mocked_keyring;
722- MockedItem *item;
723-
724- g_return_val_if_fail (keyring != NULL,
725- GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
726-
727- mocked_keyring = g_hash_table_lookup (keyrings, keyring);
728- if (G_UNLIKELY (mocked_keyring == NULL))
729- return GNOME_KEYRING_RESULT_NO_SUCH_KEYRING;
730-
731- item = mocked_keyring_get_item(mocked_keyring, id);
732- if (item == NULL) return GNOME_KEYRING_RESULT_NO_MATCH;
733-
734- result = gnome_keyring_item_info_new();
735- gnome_keyring_item_info_set_type(result, item->type);
736- gnome_keyring_item_info_set_display_name(result, item->display_name);
737- gnome_keyring_item_info_set_secret(result, item->secret);
738- *info = result;
739- return GNOME_KEYRING_RESULT_OK;
740-}
741-
742-GnomeKeyringResult
743-gnome_keyring_item_delete_sync(const char *keyring,
744- guint32 item_id)
745-{
746- MockedKeyring *mocked_keyring;
747- MockedItem *item;
748- GList *list;
749-
750- g_return_val_if_fail (keyring != NULL,
751- GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
752-
753- mocked_keyring = g_hash_table_lookup (keyrings, keyring);
754- if (G_UNLIKELY (mocked_keyring == NULL))
755- return GNOME_KEYRING_RESULT_NO_SUCH_KEYRING;
756-
757- for (list = mocked_keyring->items;
758- list != NULL;
759- list = g_list_next(list)) {
760- item = list->data;
761- if (item->id == item_id) break;
762- }
763-
764- if (list == NULL) return GNOME_KEYRING_RESULT_NO_MATCH;
765- mocked_item_free(item);
766- mocked_keyring->items = g_list_delete_link(mocked_keyring->items, list);
767- return GNOME_KEYRING_RESULT_OK;
768+ return found;
769 }
770
771=== modified file 'tests/tests.pro'
772--- tests/tests.pro 2012-12-05 16:16:14 +0000
773+++ tests/tests.pro 2013-06-25 07:19:28 +0000
774@@ -15,7 +15,7 @@
775
776 PKGCONFIG += \
777 SignOnExtension \
778- gnome-keyring-1
779+ libsecret-1
780
781 HEADERS = \
782 keyring-test.h

Subscribers

People subscribed via source and target branches