diff options
author | Stefan Walter <stefw@src.gnome.org> | 2009-01-05 04:29:23 +0000 |
---|---|---|
committer | Stefan Walter <stefw@src.gnome.org> | 2009-01-05 04:29:23 +0000 |
commit | f89df3f8b3b0f7f42f1d69ff069054ca758f6be0 (patch) | |
tree | af16ae36b4d816e7f1a49748f82d09fe290ff1ba /gp11 | |
parent | 29392679144def0183662777d8ebbd86ee8e7d79 (diff) | |
download | gnome-keyring-f89df3f8b3b0f7f42f1d69ff069054ca758f6be0.tar.gz |
Fine tune function signatures.
* gp11/gp11.h:
* gp11/gp11-module.c:
* gp11/tests/unit-test-gp11-module.c: Fine tune function signatures.
svn path=/trunk/; revision=1432
Diffstat (limited to 'gp11')
-rw-r--r-- | gp11/gp11-module.c | 45 | ||||
-rw-r--r-- | gp11/gp11.h | 7 | ||||
-rw-r--r-- | gp11/tests/unit-test-gp11-module.c | 11 |
3 files changed, 42 insertions, 21 deletions
diff --git a/gp11/gp11-module.c b/gp11/gp11-module.c index eda82932..60def94c 100644 --- a/gp11/gp11-module.c +++ b/gp11/gp11-module.c @@ -966,20 +966,31 @@ gp11_module_set_auto_authenticate (GP11Module *self, gboolean auto_login) * gp11_object_get_session() function on the resulting objects. * * The function can return FALSE to stop the enumeration. + * + * Return value: If FALSE then an error prevented all matching objects from being enumerated. **/ -void +gboolean gp11_module_enumerate_objects (GP11Module *self, GP11ObjectForeachFunc func, gpointer user_data, ...) { GP11Attributes *attrs; + GError *error = NULL; va_list va; va_start (va, user_data); attrs = gp11_attributes_new_valist (g_realloc, va); va_end (va); - gp11_module_enumerate_objects_full (self, attrs, NULL, func, user_data); + gp11_module_enumerate_objects_full (self, attrs, NULL, func, user_data, &error); gp11_attributes_unref (attrs); + + if (error != NULL) { + g_warning ("enumerating objects failed: %s", error->message); + g_clear_error (&error); + return FALSE; + } + + return TRUE; } /** @@ -989,6 +1000,7 @@ gp11_module_enumerate_objects (GP11Module *self, GP11ObjectForeachFunc func, * @cancellable: Optional cancellation object, or NULL. * @func: Function to call for each object. * @user_data: Data to pass to the function. + * @error: Location to return error information. * * Call a function for every matching object on the module. This call may * block for an indefinite period. @@ -1001,16 +1013,18 @@ gp11_module_enumerate_objects (GP11Module *self, GP11ObjectForeachFunc func, * gp11_object_get_session() function on the resulting objects. * * The function can return FALSE to stop the enumeration. + * + * Return value: If FALSE then an error prevented all matching objects from being enumerated. **/ -void +gboolean gp11_module_enumerate_objects_full (GP11Module *self, GP11Attributes *attrs, GCancellable *cancellable, GP11ObjectForeachFunc func, - gpointer user_data) + gpointer user_data, GError **error) { gboolean stop = FALSE; + gboolean ret = TRUE; GList *objects, *o; GList *slots, *l; - GError *error = NULL; GP11Session *session; g_return_if_fail (GP11_IS_MODULE (self)); @@ -1020,17 +1034,18 @@ gp11_module_enumerate_objects_full (GP11Module *self, GP11Attributes *attrs, gp11_attributes_ref (attrs); slots = gp11_module_get_slots (self, TRUE); - for (l = slots; !stop && l; l = g_list_next (l)) { - session = gp11_slot_open_session (l->data, CKF_SERIAL_SESSION, &error); - if (error) { - g_warning ("couldn't open session on slot: %s", error->message); - g_clear_error (&error); + for (l = slots; ret && !stop && l; l = g_list_next (l)) { + session = gp11_slot_open_session (l->data, CKF_SERIAL_SESSION, error); + if (!session) { + ret = FALSE; + continue; } - objects = gp11_session_find_objects_full (session, attrs, cancellable, &error); - if (error) { - g_warning ("couldn't find objects on slot: %s", error->message); - g_clear_error (&error); + objects = gp11_session_find_objects_full (session, attrs, cancellable, error); + if (*error) { + ret = FALSE; + g_object_unref (session); + continue; } for (o = objects; !stop && o; o = g_list_next (o)) { @@ -1047,5 +1062,7 @@ gp11_module_enumerate_objects_full (GP11Module *self, GP11Attributes *attrs, gp11_list_unref_free (slots); gp11_attributes_unref (attrs); + + return ret; } diff --git a/gp11/gp11.h b/gp11/gp11.h index 452ea746..f8c36315 100644 --- a/gp11/gp11.h +++ b/gp11/gp11.h @@ -295,16 +295,17 @@ gboolean gp11_module_get_auto_authenticate (GP11Module *self) void gp11_module_set_auto_authenticate (GP11Module *self, gboolean auto_authenticate); -void gp11_module_enumerate_objects (GP11Module *self, +gboolean gp11_module_enumerate_objects (GP11Module *self, GP11ObjectForeachFunc func, gpointer user_data, ...); -void gp11_module_enumerate_objects_full (GP11Module *self, +gboolean gp11_module_enumerate_objects_full (GP11Module *self, GP11Attributes *attrs, GCancellable *cancellable, GP11ObjectForeachFunc func, - gpointer user_data); + gpointer user_data, + GError **error); #ifdef UNIMPLEMENTED void gp11_module_enumerate_objects_async (GP11Module *self, diff --git a/gp11/tests/unit-test-gp11-module.c b/gp11/tests/unit-test-gp11-module.c index f2564acf..63b15392 100644 --- a/gp11/tests/unit-test-gp11-module.c +++ b/gp11/tests/unit-test-gp11-module.c @@ -103,9 +103,11 @@ DEFINE_TEST(module_enumerate) { GP11Session *session; GP11Attributes *attrs; + gboolean ret; attrs = gp11_attributes_new (); - gp11_module_enumerate_objects_full (module, attrs, NULL, for_first_object, "first"); + ret = gp11_module_enumerate_objects_full (module, attrs, NULL, for_first_object, "first", NULL); + g_assert (ret); g_assert_cmpint (n_objects, ==, 1); g_assert (GP11_IS_OBJECT (last_object)); gp11_attributes_unref (attrs); @@ -118,9 +120,10 @@ DEFINE_TEST(module_enumerate) last_object = NULL; n_objects = 0; - gp11_module_enumerate_objects (module, for_each_object, "blah", - CKA_CLASS, GP11_ULONG, CKO_PRIVATE_KEY, - GP11_INVALID); + ret = gp11_module_enumerate_objects (module, for_each_object, "blah", + CKA_CLASS, GP11_ULONG, CKO_PRIVATE_KEY, + GP11_INVALID); + g_assert (ret); g_assert_cmpint (n_objects, ==, 2); g_assert (GP11_IS_OBJECT (last_object)); |