GCK_TYPE_OBJECT, G_PARAM_READWRITE));
}
-/* ----------------------------------------------------------------------------
- * PUBLIC
- */
+static void
+created_enumerator (GckUriData *uri_data,
+ const gchar *type)
+{
+ if (_gck_debugging) {
+ gchar *attrs, *uri;
+ attrs = uri_data->attributes ? _gck_attributes_format (uri_data->attributes) : NULL;
+ uri = uri_data ? gck_uri_build (uri_data, GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE) : NULL;
+ _gck_debug ("for = %s, tokens = %s, objects = %s", type, uri, attrs);
+ g_free (attrs);
+ g_free (uri);
+ }
+}
-GckEnumerator*
-_gck_enumerator_new (GList *modules_or_slots,
- GckSessionOptions session_options,
- GckUriData *uri_data)
+GckEnumerator *
+_gck_enumerator_new_for_modules (GList *modules,
+ GckSessionOptions session_options,
+ GckUriData *uri_data)
{
GckEnumerator *self;
GckEnumeratorState *state;
state->session_options = session_options;
- if (modules_or_slots && GCK_IS_SLOT (modules_or_slots->data)) {
- state->slots = gck_list_ref_copy (modules_or_slots);
- state->modules = NULL;
- state->handler = state_slots;
- } else {
- state->modules = gck_list_ref_copy (modules_or_slots);
- state->slots = NULL;
- state->handler = state_modules;
- }
+ state->modules = gck_list_ref_copy (modules);
+ state->slots = NULL;
+ state->handler = state_modules;
+ state->match = uri_data;
+ if (uri_data->attributes)
+ _gck_attributes_lock (uri_data->attributes);
+
+ created_enumerator (uri_data, "modules");
+ return self;
+}
+
+GckEnumerator *
+_gck_enumerator_new_for_slots (GList *slots,
+ GckSessionOptions session_options,
+ GckUriData *uri_data)
+{
+ GckEnumerator *self;
+ GckEnumeratorState *state;
+
+ self = g_object_new (GCK_TYPE_ENUMERATOR, NULL);
+ state = self->pv->the_state;
+
+ state->session_options = session_options;
+
+ state->slots = gck_list_ref_copy (slots);
+ state->modules = NULL;
+ state->handler = state_slots;
state->match = uri_data;
+
if (uri_data->attributes)
_gck_attributes_lock (uri_data->attributes);
- if (_gck_debugging) {
- gchar *attrs, *uri;
- attrs = uri_data->attributes ? _gck_attributes_format (uri_data->attributes) : NULL;
- uri = uri_data ? gck_uri_build (uri_data, GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE) : NULL;
- _gck_debug ("new enumerator: tokens = %s, objects = %s", uri, attrs);
- g_free (attrs);
- g_free (uri);
- }
+ created_enumerator (uri_data, "slots");
+ return self;
+}
+
+GckEnumerator *
+_gck_enumerator_new_for_session (GckSession *session,
+ GckUriData *uri_data)
+{
+ GckEnumerator *self;
+ GckEnumeratorState *state;
+ GckModule *module;
+
+ self = g_object_new (GCK_TYPE_ENUMERATOR, NULL);
+ state = self->pv->the_state;
+
+ state->session = g_object_ref (session);
+ state->modules = NULL;
+ state->slots = NULL;
+ state->handler = state_session;
+ state->match = uri_data;
+
+ state->slot = gck_session_get_slot (session);
+ state->token_info = gck_slot_get_token_info (state->slot);
+
+ module = gck_session_get_module (session);
+ state->funcs = gck_module_get_functions (module);
+ g_object_unref (module);
+
+ if (uri_data->attributes)
+ _gck_attributes_lock (uri_data->attributes);
+ created_enumerator (uri_data, "session");
return self;
}
GckEnumerator *en;
uri_data = gck_uri_data_new ();
- en = _gck_enumerator_new (test->modules, 0, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, 0, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
g_object_get (en, "object-type", &object_type, NULL);
uri_data = gck_uri_data_new ();
slots = gck_module_get_slots (test->module, FALSE);
- en = _gck_enumerator_new (slots, 0, uri_data);
+ en = _gck_enumerator_new_for_slots (slots, 0, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
g_object_unref (en);
gck_list_unref_free (slots);
GckObject *obj;
uri_data = gck_uri_data_new ();
- en = _gck_enumerator_new (test->modules, 0, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, 0, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
obj = gck_enumerator_next (en, NULL, &error);
uri_data = gck_uri_data_new ();
slots = gck_module_get_slots (test->module, FALSE);
- en = _gck_enumerator_new (slots, 0, uri_data);
+ en = _gck_enumerator_new_for_slots (slots, 0, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
obj = gck_enumerator_next (en, NULL, &error);
GckObject *obj, *obj2;
uri_data = gck_uri_data_new ();
- en = _gck_enumerator_new (test->modules, 0, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, 0, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
obj = gck_enumerator_next (en, NULL, &error);
GList *objects, *l;
uri_data = gck_uri_data_new ();
- en = _gck_enumerator_new (test->modules, 0, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, 0, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
objects = gck_enumerator_next_n (en, -1, NULL, &error);
GList *objects, *l;
uri_data = gck_uri_data_new ();
- en = _gck_enumerator_new (test->modules, 0, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, 0, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
gck_enumerator_next_async (en, -1, NULL, fetch_async_result, &result);
g_object_unref (en);
}
+
+static void
+test_enumerate_session (Test *test,
+ gconstpointer unused)
+{
+ GckEnumerator *en;
+ GckAttributes *attrs;
+ GError *error = NULL;
+ GckSession *session;
+ GckObject *obj;
+ GList *slots;
+
+ slots = gck_module_get_slots (test->module, FALSE);
+ g_assert (slots != NULL && GCK_IS_SLOT (slots->data));
+
+ session = gck_session_open (slots->data, 0, NULL, NULL, &error);
+ g_assert_no_error (error);
+
+ attrs = gck_attributes_new ();
+ en = gck_session_enumerate_objects (session, attrs);
+ g_assert (GCK_IS_ENUMERATOR (en));
+ gck_attributes_unref (attrs);
+
+ obj = gck_enumerator_next (en, NULL, &error);
+ g_assert (GCK_IS_OBJECT (obj));
+
+ g_object_unref (obj);
+ g_object_unref (en);
+ g_object_unref (session);
+ gck_list_unref_free (slots);
+}
+
static void
test_attribute_match (Test *test, gconstpointer unused)
{
uri_data = gck_uri_data_new ();
uri_data->attributes = gck_attributes_new ();
gck_attributes_add_string (uri_data->attributes, CKA_LABEL, "Private Capitalize Key");
- en = _gck_enumerator_new (test->modules, 0, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, 0, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
objects = gck_enumerator_next_n (en, -1, NULL, &error);
GckObject *obj;
uri_data = gck_uri_data_new ();
- en = _gck_enumerator_new (test->modules, GCK_SESSION_LOGIN_USER, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, GCK_SESSION_LOGIN_USER, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
interaction = mock_interaction_new ("booo");
G_CALLBACK (on_authenticate_token), GUINT_TO_POINTER (35));
uri_data = gck_uri_data_new ();
- en = _gck_enumerator_new (test->modules, GCK_SESSION_LOGIN_USER, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, GCK_SESSION_LOGIN_USER, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
obj = gck_enumerator_next (en, NULL, &error);
uri_data = gck_uri_data_new ();
uri_data->token_info = g_new0 (GckTokenInfo, 1);
uri_data->token_info->label = g_strdup ("Invalid token name");
- en = _gck_enumerator_new (test->modules, 0, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, 0, uri_data);
g_assert (GCK_IS_ENUMERATOR (en));
objects = gck_enumerator_next_n (en, -1, NULL, &error);
MockObject *mock;
uri_data = gck_uri_data_new ();
- en = _gck_enumerator_new (test->modules, 0, uri_data);
+ en = _gck_enumerator_new_for_modules (test->modules, 0, uri_data);
g_object_set (en, "object-type", mock_object_get_type (), NULL);
objects = gck_enumerator_next_n (en, -1, NULL, &error);
g_test_add ("/gck/enumerator/next_and_resume", Test, NULL, setup, test_next_and_resume, teardown);
g_test_add ("/gck/enumerator/next_n", Test, NULL, setup, test_next_n, teardown);
g_test_add ("/gck/enumerator/next_async", Test, NULL, setup, test_next_async, teardown);
+ g_test_add ("/gck/enumerator/session", Test, NULL, setup, test_enumerate_session, teardown);
g_test_add ("/gck/enumerator/authenticate-interaction", Test, NULL, setup, test_authenticate_interaction, teardown);
g_test_add ("/gck/enumerator/authenticate-compat", Test, NULL, setup, test_authenticate_compat, teardown);
g_test_add ("/gck/enumerator/attribute_match", Test, NULL, setup, test_attribute_match, teardown);