gnome-keyring r1388 - in trunk: . gp11 gp11/reference/tmpl gp11/tests



Author: nnielsen
Date: Sun Dec 14 00:39:44 2008
New Revision: 1388
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1388&view=rev

Log:
	* gp11/gp11.h
	* gp11/gp11-call.c:
	* gp11/gp11-object.c:
	* gp11/gp11-private.h:
	* gp11/gp11-session.c:
	* gp11/gp11-slot.c:
	* gp11/gp11-test-gp11-object.c: Don't tie an object to a session unless
	explicitly requested. Automatically open a session for object operations
	(usually pooled).


Modified:
   trunk/ChangeLog
   trunk/gp11/gp11-call.c
   trunk/gp11/gp11-object.c
   trunk/gp11/gp11-private.h
   trunk/gp11/gp11-session.c
   trunk/gp11/gp11-slot.c
   trunk/gp11/gp11.h
   trunk/gp11/reference/tmpl/gp11.sgml
   trunk/gp11/tests/unit-test-gp11-object.c

Modified: trunk/gp11/gp11-call.c
==============================================================================
--- trunk/gp11/gp11-call.c	(original)
+++ trunk/gp11/gp11-call.c	Sun Dec 14 00:39:44 2008
@@ -361,10 +361,9 @@
                        gsize args_size, gpointer destroy)
 {
 	GP11Arguments *args;
-	GP11Module *module;
 	GP11Call *call;
 
-	g_assert (G_IS_OBJECT (object));
+	g_assert (!object || G_IS_OBJECT (object));
 	g_assert (func);
 	
 	if (!destroy)
@@ -375,11 +374,6 @@
 	g_assert (args_size >= sizeof (GP11Arguments));
 	
 	args = g_malloc0 (args_size);
-	g_object_get (object, "module", &module, "handle", &args->handle, NULL);
-	g_assert (GP11_IS_MODULE (module));
-	args->pkcs11 = module->funcs;
-	g_object_unref (module);
-	
 	call = g_object_new (GP11_TYPE_CALL, NULL);
 	call->destroy = (GDestroyNotify)destroy;
 	call->func = (GP11CallFunc)func;
@@ -390,31 +384,32 @@
 	call->args = args;
 	call->args->call = call;
 
+	/* Setup call object if available */
+	if (object != NULL)
+		_gp11_call_async_object (call, object);
+
 	return args;
 }
 
-void 
-_gp11_call_async_short (gpointer data, GAsyncReadyCallback callback,
-                        gpointer user_data)
+void
+_gp11_call_async_object (GP11Call *call, gpointer object)
 {
-	GP11Arguments *args = (GP11Arguments*)data;
-	
-	g_assert (GP11_IS_CALL (args->call));
+	GP11Module *module;
 	
-	args->call->callback = callback;
-	args->call->user_data = user_data;
+	g_assert (GP11_IS_CALL (call));
+	g_assert (call->args);
 	
-	/* Already complete, so just push it for processing in main loop */
-	g_assert (completed_queue);
-	g_async_queue_push (completed_queue, args->call);
+	g_object_get (object, "module", &module, "handle", &call->args->handle, NULL);
+	g_assert (GP11_IS_MODULE (module));
+	call->args->pkcs11 = module->funcs;
+	g_object_unref (module);
 }
 
-void
-_gp11_call_async_go (gpointer data, GCancellable *cancellable, 
-                     GAsyncReadyCallback callback, gpointer user_data)
+GP11Call*
+_gp11_call_async_ready (gpointer data, GCancellable *cancellable, 
+                        GAsyncReadyCallback callback, gpointer user_data)
 {
 	GP11Arguments *args = (GP11Arguments*)data;
-	
 	g_assert (GP11_IS_CALL (args->call));
 	
 	args->call->cancellable = cancellable;
@@ -426,12 +421,29 @@
 	args->call->callback = callback;
 	args->call->user_data = user_data;
 	
+	return args->call;
+}
+
+void
+_gp11_call_async_go (GP11Call *call)
+{
+	g_assert (GP11_IS_CALL (call));
+	g_assert (call->args->pkcs11);
+	
 	g_assert (thread_pool);
-	g_thread_pool_push (thread_pool, args->call, NULL);
+	g_thread_pool_push (thread_pool, call, NULL);
+}
+
+void
+_gp11_call_async_ready_go (gpointer data, GCancellable *cancellable, 
+                           GAsyncReadyCallback callback, gpointer user_data)
+{
+	GP11Call *call = _gp11_call_async_ready (data, cancellable, callback, user_data);
+	_gp11_call_async_go (call);
 }
 
 gboolean
-_gp11_call_basic_finish (gpointer object, GAsyncResult *result, GError **err)
+_gp11_call_basic_finish (GAsyncResult *result, GError **err)
 {
 	CK_RV rv;
 	
@@ -444,3 +456,15 @@
 	g_set_error (err, GP11_ERROR, rv, "%s", gp11_message_from_rv (rv));
 	return FALSE;	
 }
+
+void
+_gp11_call_async_short (GP11Call *call, CK_RV rv)
+{
+	g_assert (GP11_IS_CALL (call));
+	
+	call->rv = rv;
+
+	/* Already complete, so just push it for processing in main loop */
+	g_assert (completed_queue);
+	g_async_queue_push (completed_queue, call);
+}

Modified: trunk/gp11/gp11-object.c
==============================================================================
--- trunk/gp11/gp11-object.c	(original)
+++ trunk/gp11/gp11-object.c	Sun Dec 14 00:39:44 2008
@@ -31,13 +31,75 @@
 enum {
 	PROP_0,
 	PROP_MODULE,
-	PROP_SESSION,
-	PROP_HANDLE
+	PROP_SLOT,
+	PROP_HANDLE,
+	PROP_SESSION
 };
 
 G_DEFINE_TYPE (GP11Object, gp11_object, G_TYPE_OBJECT);
 
 /* ----------------------------------------------------------------------------
+ * INTERNAL
+ */
+
+static void
+run_call_with_session (GP11Call *call, GP11Session *session)
+{
+	g_assert (GP11_IS_CALL (call));
+	g_assert (GP11_IS_SESSION (session));
+	
+	/* Hold onto this session for the length of the call */
+	g_object_set_data_full (G_OBJECT (call), "call-opened-session", session, g_object_unref);
+
+	_gp11_call_async_object (call, session);
+	_gp11_call_async_go (call);	
+}
+
+static void
+opened_session (GObject *obj, GAsyncResult *result, gpointer user_data)
+{
+	GP11Session *session;
+	GError *err = NULL;
+	GP11Call *call;
+	
+	g_assert (GP11_IS_CALL (user_data));
+	call = GP11_CALL (user_data);
+	
+	session = gp11_slot_open_session_finish (GP11_SLOT (obj), result, &err);
+	
+	/* Transtfer the error to the outer call and finish */
+	if (!session) {
+		_gp11_call_async_short (user_data, err->code);
+		g_error_free (err);
+	}
+
+	run_call_with_session (GP11_CALL (user_data), session);
+}
+
+static void
+require_session_async (GP11Object *object, GP11Call *call, 
+                       gulong flags, GCancellable *cancellable)
+{
+	g_assert (GP11_IS_OBJECT (object));
+	
+	if (object->session)
+		run_call_with_session (call, object->session);
+	else
+		gp11_slot_open_session_async (object->slot, flags, cancellable, opened_session, call);
+}
+
+static GP11Session*
+require_session_sync (GP11Object *object, gulong flags, GError **err)
+{
+	g_assert (GP11_IS_OBJECT (object));
+
+	if (object->session) 
+		return g_object_ref (object->session);
+	
+	return gp11_slot_open_session (object->slot, flags, err);
+}
+
+/* ----------------------------------------------------------------------------
  * OBJECT
  */
 
@@ -57,6 +119,9 @@
 	case PROP_MODULE:
 		g_value_set_object (value, object->module);
 		break;
+	case PROP_SLOT:
+		g_value_set_object (value, object->slot);
+		break;
 	case PROP_SESSION:
 		g_value_set_object (value, object->session);
 		break;
@@ -79,11 +144,14 @@
 		g_return_if_fail (object->module);
 		g_object_ref (object->module);
 		break;
+	case PROP_SLOT:
+		g_return_if_fail (!object->slot);
+		object->slot = g_value_get_object (value);
+		g_return_if_fail (object->slot);
+		g_object_ref (object->slot);
+		break;
 	case PROP_SESSION:
-		g_return_if_fail (!object->session);
-		object->session = g_value_get_object (value);
-		g_return_if_fail (object->session);
-		g_object_ref (object->session);
+		gp11_object_set_session (object, g_value_get_object (value));
 		break;
 	case PROP_HANDLE:
 		g_return_if_fail (!object->handle);
@@ -97,13 +165,17 @@
 {
 	GP11Object *object = GP11_OBJECT (obj);
 	
-	if (object->session)
-		g_object_unref (object->session);
-	object->session = NULL;
+	if (object->slot)
+		g_object_unref (object->slot);
+	object->slot = NULL;
 	
 	if (object->module)
 		g_object_unref (object->module);
 	object->module = NULL;
+	
+	if (object->session)
+		g_object_unref (object->session);
+	object->session = NULL;
 
 	G_OBJECT_CLASS (gp11_object_parent_class)->dispose (obj);
 }
@@ -113,8 +185,10 @@
 {
 	GP11Object *object = GP11_OBJECT (obj);
 
-	g_assert (object->session == NULL);
+	g_assert (object->slot == NULL);
 	g_assert (object->module == NULL);
+	g_assert (object->session == NULL);
+	
 	object->handle = 0;
 	
 	G_OBJECT_CLASS (gp11_object_parent_class)->finalize (obj);
@@ -136,13 +210,17 @@
 		g_param_spec_object ("module", "Module", "PKCS11 Module",
 		                     GP11_TYPE_MODULE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
-	g_object_class_install_property (gobject_class, PROP_SESSION,
-		g_param_spec_object ("session", "Session", "PKCS11 Session",
-		                     GP11_TYPE_SESSION, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+	g_object_class_install_property (gobject_class, PROP_SLOT,
+		g_param_spec_object ("slot", "slot", "PKCS11 Slot",
+		                     GP11_TYPE_SLOT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
 	g_object_class_install_property (gobject_class, PROP_HANDLE,
 		g_param_spec_uint ("handle", "Object Handle", "PKCS11 Object Handle",
 		                   0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+	g_object_class_install_property (gobject_class, PROP_SESSION,
+		g_param_spec_object ("session", "session", "PKCS11 Session to make calls on",
+		                     GP11_TYPE_SESSION, G_PARAM_READWRITE));
 }
 
 /* ----------------------------------------------------------------------------
@@ -151,7 +229,7 @@
 
 /**
  * gp11_object_from_handle:
- * @session: The session on which this object is available.
+ * @slot: The slot on which this object is present.
  * @handle: The raw handle of the object. 
  * 
  * Initialize a GP11Object from a raw PKCS#11 handle. Normally you would use 
@@ -160,15 +238,15 @@
  * Return value: The new GP11Object. You should use g_object_unref() when done with this object.
  **/
 GP11Object*
-gp11_object_from_handle (GP11Session *session, CK_OBJECT_HANDLE handle)
+gp11_object_from_handle (GP11Slot *slot, CK_OBJECT_HANDLE handle)
 {
-	g_return_val_if_fail (GP11_IS_SESSION (session), NULL);
-	return g_object_new (GP11_TYPE_OBJECT, "module", session->module, "handle", handle, "session", session, NULL);
+	g_return_val_if_fail (GP11_IS_SLOT (slot), NULL);
+	return g_object_new (GP11_TYPE_OBJECT, "module", slot->module, "handle", handle, "slot", slot, NULL);
 }
 
 /**
  * gp11_objects_from_handle_array:
- * @session: The session on which these objects are available.
+ * @slot: The slot on which these objects are present.
  * @attr: The raw object handles, contained in an attribute.
  * 
  * Initialize a list of GP11Object from raw PKCS#11 handles contained inside 
@@ -179,18 +257,18 @@
  * this list. 
  **/
 GList*
-gp11_objects_from_handle_array (GP11Session *session, const GP11Attribute *attr)
+gp11_objects_from_handle_array (GP11Slot *slot, const GP11Attribute *attr)
 {
 	GList *results = NULL;
 	CK_OBJECT_HANDLE *array;
 	guint i, n_array;
 	
-	g_return_val_if_fail (GP11_IS_SESSION (session), NULL);
+	g_return_val_if_fail (GP11_IS_SLOT (slot), NULL);
 	
 	array = (CK_OBJECT_HANDLE*)attr->value;
 	n_array = attr->length / sizeof (CK_OBJECT_HANDLE);
 	for (i = 0; i < n_array; ++i)
-		results = g_list_prepend (results, gp11_object_from_handle (session, array[i]));
+		results = g_list_prepend (results, gp11_object_from_handle (slot, array[i]));
 	return g_list_reverse (results);
 }
 
@@ -209,6 +287,52 @@
 	return object->handle;
 }
 
+/**
+ * gp11_object_get_session:
+ * @object: The object
+ * 
+ * Get the PKCS#11 session assigned to make calls on when operating
+ * on this object.  
+ * 
+ * This will only return a session if it was set explitly on this 
+ * object. By default an object will open and close sessions 
+ * appropriate for its calls.
+ * 
+ * Return value: The assigned session.   
+ **/
+GP11Session*
+gp11_object_get_session (GP11Object *object)
+{
+	g_return_val_if_fail (GP11_IS_OBJECT (object), NULL);
+	return object->session;
+}
+
+/**
+ * gp11_object_get_session:
+ * @object: The object
+ * @session: The assigned session
+ * 
+ * Set the PKCS#11 session assigned to make calls on when operating
+ * on this object.  
+ * 
+ * It isn't always necessary to assign a session to an object. 
+ * By default an object will open and close sessions appropriate for 
+ * its calls.
+ * 
+ * If you assign a read-only session, then calls on this object
+ * that modify the state of the object will probably fail.
+ **/
+void
+gp11_object_set_session (GP11Object *object, GP11Session *session)
+{
+	g_return_if_fail (GP11_IS_OBJECT (object));
+	if (object->session)
+		g_object_unref (object->session);
+	object->session = session;
+	if (object->session)
+		g_object_ref (object->session);
+}
+
 /* DESTROY */
 
 typedef struct _Destroy {
@@ -253,10 +377,19 @@
 gp11_object_destroy_full (GP11Object *object, GCancellable *cancellable, GError **err)
 {
 	Destroy args = { GP11_ARGUMENTS_INIT, 0 };
+	GP11Session *session;
+	gboolean ret = FALSE;
+	
 	g_return_val_if_fail (GP11_IS_OBJECT (object), FALSE);
-	g_return_val_if_fail (GP11_IS_SESSION (object->session), FALSE);
+	g_return_val_if_fail (GP11_IS_SLOT (object->slot), FALSE);
+	
 	args.object = object->handle;
-	return _gp11_call_sync (object->session, perform_destroy, &args, cancellable, err);
+
+	session = require_session_sync (object, CKF_RW_SESSION, err);
+	if (session)
+		ret = _gp11_call_sync (session, perform_destroy, &args, cancellable, err);
+	g_object_unref (session);
+	return ret;
 }
 
 /**
@@ -274,14 +407,16 @@
                            GAsyncReadyCallback callback, gpointer user_data)
 {
 	Destroy* args;
+	GP11Call *call;
 
 	g_return_if_fail (GP11_IS_OBJECT (object));
-	g_return_if_fail (GP11_IS_SESSION (object->session));
+	g_return_if_fail (GP11_IS_SLOT (object->slot));
 
-	args = _gp11_call_async_prep (object->session, object, perform_destroy, sizeof (*args), NULL);
+	args = _gp11_call_async_prep (NULL, object, perform_destroy, sizeof (*args), NULL);
 	args->object = object->handle;
 	
-	_gp11_call_async_go (args, cancellable, callback, user_data);
+	call = _gp11_call_async_ready (args, cancellable, callback, user_data);
+	require_session_async (object, call, CKF_RW_SESSION, cancellable);
 }
 
 /**
@@ -298,7 +433,7 @@
 gboolean
 gp11_object_destroy_finish (GP11Object *object, GAsyncResult *result, GError **err)
 {
-	return _gp11_call_basic_finish (object, result, err);
+	return _gp11_call_basic_finish (result, err);
 }
 
 typedef struct _SetAttributes {
@@ -387,6 +522,8 @@
                       GCancellable *cancellable, GError **err)
 {
 	SetAttributes args;
+	GP11Session *session;
+	gboolean ret = FALSE;
 	
 	g_return_val_if_fail (GP11_IS_OBJECT (object), FALSE);
 	
@@ -394,7 +531,11 @@
 	args.attrs = attrs;
 	args.object = object->handle;
 
-	return _gp11_call_sync (object->session, perform_set_attributes, &args, cancellable, err);
+	session = require_session_sync (object, CKF_RW_SESSION, err);
+	if (session)
+		ret = _gp11_call_sync (session, perform_set_attributes, &args, cancellable, err);
+	g_object_unref (session);
+	return ret;
 }
 
 /**
@@ -413,16 +554,18 @@
                        GAsyncReadyCallback callback, gpointer user_data)
 {
 	SetAttributes *args;
-
+	GP11Call *call;
+	
 	g_return_if_fail (GP11_IS_OBJECT (object));
 
-	args = _gp11_call_async_prep (object->session, object, perform_set_attributes, 
+	args = _gp11_call_async_prep (object->slot, object, perform_set_attributes, 
 	                              sizeof (*args), free_set_attributes);
 	args->attrs = attrs;
 	gp11_attributes_ref (attrs);
 	args->object = object->handle;
 	
-	_gp11_call_async_go (args, cancellable, callback, user_data);
+	call = _gp11_call_async_ready (args, cancellable, callback, user_data);
+	require_session_async (object, call, CKF_RW_SESSION, cancellable);
 }
 
 /**
@@ -439,7 +582,7 @@
 gboolean
 gp11_object_set_finish (GP11Object *object, GAsyncResult *result, GError **err)
 {
-	return _gp11_call_basic_finish (object, result, err);
+	return _gp11_call_basic_finish (result, err);
 }
 
 typedef struct _GetAttributes {
@@ -592,19 +735,26 @@
                       GCancellable *cancellable, GError **err)
 {
 	GetAttributes args;
+	GP11Session *session;
 	
 	g_return_val_if_fail (GP11_IS_OBJECT (object), FALSE);
 	
+	session = require_session_sync (object, 0, err);
+	if (!session)
+		return FALSE;
+	
 	memset (&args, 0, sizeof (args));
 	args.attr_types = (gulong*)attr_types;
 	args.n_attr_types = n_attr_types;
 	args.object = object->handle;
 
-	if (!_gp11_call_sync (object->session, perform_get_attributes, &args, cancellable, err)) {
+	if (!_gp11_call_sync (session, perform_get_attributes, &args, cancellable, err)) {
 		gp11_attributes_unref (args.results);
+		g_object_unref (session);
 		return NULL;
 	}
 	
+	g_object_unref (session);
 	return args.results;
 }
 
@@ -625,7 +775,8 @@
                        GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
 {
 	GetAttributes *args;
-
+	GP11Call *call;
+	
 	g_return_if_fail (GP11_IS_OBJECT (object));
 
 	args = _gp11_call_async_prep (object->session, object, perform_get_attributes, 
@@ -635,7 +786,8 @@
 		args->attr_types = g_memdup (attr_types, sizeof (gulong) * n_attr_types);
 	args->object = object->handle;
 	
-	_gp11_call_async_go (args, cancellable, callback, user_data);
+	call = _gp11_call_async_ready (args, cancellable, callback, user_data);
+	require_session_async (object, call, 0, cancellable);
 }
 
 /**
@@ -658,7 +810,7 @@
 	GP11Attributes *results;
 	GetAttributes *args;
 	
-	if (!_gp11_call_basic_finish (object, result, err))
+	if (!_gp11_call_basic_finish (result, err))
 		return NULL;
 	
 	args = _gp11_call_arguments (result, GetAttributes);
@@ -762,3 +914,4 @@
 	gp11_attributes_unref (attrs);
 	return attr;
 }
+

Modified: trunk/gp11/gp11-private.h
==============================================================================
--- trunk/gp11/gp11-private.h	(original)
+++ trunk/gp11/gp11-private.h	Sun Dec 14 00:39:44 2008
@@ -126,17 +126,26 @@
                                                            gsize args_size,
                                                            gpointer destroy_func);
 
-void               _gp11_call_async_go                    (gpointer args, 
+GP11Call*          _gp11_call_async_ready                 (gpointer args, 
                                                            GCancellable *cancellable, 
                                                            GAsyncReadyCallback callback, 
                                                            gpointer user_data);
 
-void                _gp11_call_async_short                (gpointer data, 
-                                                           GAsyncReadyCallback callback,
+void               _gp11_call_async_go                    (GP11Call *call);
+
+void               _gp11_call_async_ready_go              (gpointer args, 
+                                                           GCancellable *cancellable, 
+                                                           GAsyncReadyCallback callback, 
                                                            gpointer user_data);
 
-gboolean           _gp11_call_basic_finish                (gpointer object,
-                                                           GAsyncResult *result,
+
+void               _gp11_call_async_short                 (GP11Call *call, 
+                                                           CK_RV rv);
+
+gboolean           _gp11_call_basic_finish                (GAsyncResult *result,
                                                            GError **err);
 
+void               _gp11_call_async_object                (GP11Call *call,
+                                                           gpointer object);
+
 #endif /* GP11_PRIVATE_H_ */

Modified: trunk/gp11/gp11-session.c
==============================================================================
--- trunk/gp11/gp11-session.c	(original)
+++ trunk/gp11/gp11-session.c	Sun Dec 14 00:39:44 2008
@@ -354,7 +354,7 @@
 	args->pin = pin && n_pin ? g_memdup (pin, n_pin) : NULL;
 	args->n_pin = n_pin;
 	
-	_gp11_call_async_go (args, cancellable, callback, user_data);
+	_gp11_call_async_ready_go (args, cancellable, callback, user_data);
 
 }
 
@@ -371,7 +371,7 @@
 gboolean
 gp11_session_login_finish (GP11Session *session, GAsyncResult *result, GError **err)
 {
-	return _gp11_call_basic_finish (session, result, err);
+	return _gp11_call_basic_finish (result, err);
 }
 
 
@@ -432,7 +432,7 @@
                            GAsyncReadyCallback callback, gpointer user_data)
 {
 	GP11Arguments *args = _gp11_call_async_prep (session, session, perform_logout, 0, NULL);
-	_gp11_call_async_go (args, cancellable, callback, user_data);
+	_gp11_call_async_ready_go (args, cancellable, callback, user_data);
 }
 
 /**
@@ -448,7 +448,7 @@
 gboolean
 gp11_session_logout_finish (GP11Session *session, GAsyncResult *result, GError **err)
 {
-	return _gp11_call_basic_finish (session, result, err);
+	return _gp11_call_basic_finish (result, err);
 }
 
 
@@ -546,7 +546,7 @@
 	CreateObject args = { GP11_ARGUMENTS_INIT, attrs, 0 };
 	if (!_gp11_call_sync (session, perform_create_object, &args, cancellable, err))
 		return NULL;
-	return gp11_object_from_handle (session, args.object);
+	return gp11_object_from_handle (session->slot, args.object);
 }
 
 /**
@@ -569,7 +569,7 @@
 	                                            sizeof (*args), free_create_object);
 	args->attrs = attrs;
 	gp11_attributes_ref (attrs);
-	_gp11_call_async_go (args, cancellable, callback, user_data);
+	_gp11_call_async_ready_go (args, cancellable, callback, user_data);
 }
 
 /**
@@ -587,10 +587,10 @@
 {
 	CreateObject *args;
 	
-	if (!_gp11_call_basic_finish (session, result, err))
+	if (!_gp11_call_basic_finish (result, err))
 		return NULL;
 	args = _gp11_call_arguments (result, CreateObject);
-	return gp11_object_from_handle (session, args->object);
+	return gp11_object_from_handle (session->slot, args->object);
 }
 
 
@@ -673,7 +673,7 @@
 	
 	while (n_objects > 0) {
 		results = g_list_prepend (results, 
-		                gp11_object_from_handle (session, objects[--n_objects]));
+		                gp11_object_from_handle (session->slot, objects[--n_objects]));
 	}
 	
 	return g_list_reverse (results);
@@ -772,7 +772,7 @@
 	                                           sizeof (*args), free_find_objects);
 	args->attrs = attrs;
 	gp11_attributes_ref (attrs);
-	_gp11_call_async_go (args, cancellable, callback, user_data);
+	_gp11_call_async_ready_go (args, cancellable, callback, user_data);
 }
 
 /**
@@ -790,7 +790,7 @@
 {
 	FindObjects *args;
 	
-	if (!_gp11_call_basic_finish (session, result, err))
+	if (!_gp11_call_basic_finish (result, err))
 		return NULL;
 	args = _gp11_call_arguments (result, FindObjects);
 	return objlist_from_handles (session, args->objects, args->n_objects);

Modified: trunk/gp11/gp11-slot.c
==============================================================================
--- trunk/gp11/gp11-slot.c	(original)
+++ trunk/gp11/gp11-slot.c	Sun Dec 14 00:39:44 2008
@@ -917,6 +917,7 @@
 gp11_slot_open_session_async (GP11Slot *slot, gulong flags, GCancellable *cancellable, 
                               GAsyncReadyCallback callback, gpointer user_data)
 {
+	GP11Call *call;
 	OpenSession *args = _gp11_call_async_prep (slot, slot, perform_open_session,
 	                                           sizeof (*args), NULL);
 	
@@ -924,10 +925,11 @@
 	args->session = pop_session_table (slot, flags);
 	args->flags = flags;
 	
+	call = _gp11_call_async_ready (args, cancellable, callback, user_data);
 	if (args->session)
-		_gp11_call_async_short (args, callback, user_data);
+		_gp11_call_async_short (call, CKR_OK);
 	else
-		_gp11_call_async_go (args, cancellable, callback, user_data);
+		_gp11_call_async_go (call);
 }
 
 /**
@@ -946,7 +948,7 @@
 {
 	OpenSession *args;
 	
-	if (!_gp11_call_basic_finish (slot, result, err))
+	if (!_gp11_call_basic_finish (result, err))
 		return NULL;
 	
 	args = _gp11_call_arguments (result, OpenSession);

Modified: trunk/gp11/gp11.h
==============================================================================
--- trunk/gp11/gp11.h	(original)
+++ trunk/gp11/gp11.h	Sun Dec 14 00:39:44 2008
@@ -1197,6 +1197,7 @@
 	GObject parent;
 	
 	GP11Module *module;
+	GP11Slot *slot;
 	GP11Session *session;
 	CK_OBJECT_HANDLE handle;
 };
@@ -1207,14 +1208,19 @@
 
 GType               gp11_object_get_type                    (void) G_GNUC_CONST;
 
-GP11Object*         gp11_object_from_handle                 (GP11Session *session, 
+GP11Object*         gp11_object_from_handle                 (GP11Slot *slot, 
                                                              CK_OBJECT_HANDLE handle);
 
-GList*              gp11_objects_from_handle_array          (GP11Session *session,
+GList*              gp11_objects_from_handle_array          (GP11Slot *slot,
                                                              const GP11Attribute *attr);
 
 CK_OBJECT_HANDLE    gp11_object_get_handle                  (GP11Object *object);
 
+GP11Session*        gp11_object_get_session                 (GP11Object *object);
+
+void                gp11_object_set_session                 (GP11Object *object,
+                                                             GP11Session *session);
+
 #ifdef UNIMPLEMENTED
 
 GP11Object*         gp11_object_copy                        (GP11Object *object,

Modified: trunk/gp11/reference/tmpl/gp11.sgml
==============================================================================
--- trunk/gp11/reference/tmpl/gp11.sgml	(original)
+++ trunk/gp11/reference/tmpl/gp11.sgml	Sun Dec 14 00:39:44 2008
@@ -2504,6 +2504,11 @@
 
 </para>
 
+<!-- ##### ARG GP11Object:slot ##### -->
+<para>
+
+</para>
+
 <!-- ##### FUNCTION gp11_object_get_type ##### -->
 <para>
 
@@ -2517,7 +2522,7 @@
 
 </para>
 
- session: 
+ slot: 
 @handle: 
 @Returns: 
 
@@ -2527,7 +2532,7 @@
 
 </para>
 
- session: 
+ slot: 
 @attr: 
 @Returns: 
 

Modified: trunk/gp11/tests/unit-test-gp11-object.c
==============================================================================
--- trunk/gp11/tests/unit-test-gp11-object.c	(original)
+++ trunk/gp11/tests/unit-test-gp11-object.c	Sun Dec 14 00:39:44 2008
@@ -33,7 +33,7 @@
 	SUCCESS_RES(session, err);
 	
 	/* Our module always exports a token object with this */
-	object = gp11_object_from_handle (session, 2);
+	object = gp11_object_from_handle (session->slot, 2);
 	g_assert (object != NULL);
 }
 
@@ -47,12 +47,12 @@
 
 DEFINE_TEST(object_props)
 {
-	GP11Session *sess;
+	GP11Slot *slot;
 	GP11Module *mod;
 	CK_OBJECT_HANDLE handle;
-	g_object_get (object, "session", &sess, "module", &mod, "handle", &handle, NULL);
-	g_assert (sess == session);
-	g_object_unref (session);
+	g_object_get (object, "slot", &slot, "module", &mod, "handle", &handle, NULL);
+	g_assert (slot == session->slot);
+	g_object_unref (slot);
 	g_assert (module == mod);
 	g_object_unref (mod);
 	g_assert (handle == 2);
@@ -367,3 +367,51 @@
 	g_assert (objects == NULL);
 	gp11_list_unref_free (objects);
 }
+
+DEFINE_TEST(explicit_sessions)
+{
+	GP11Session *sess;
+	GAsyncResult *result = NULL;
+	GP11Attributes *attrs;
+	GError *err = NULL;
+	gulong klass;
+	gchar *value = NULL;
+	gulong types[2] = { CKA_CLASS, CKA_LABEL };
+	
+	/* Set an explicit session */
+	gp11_object_set_session (object, session);
+	g_assert (gp11_object_get_session (object) == session);
+	g_object_get (object, "session", &sess, NULL);
+	g_assert (sess == session);
+	
+	/* Simple */
+	attrs = gp11_object_get (object, &err, CKA_CLASS, CKA_LABEL, -1);
+	SUCCESS_RES (attrs, err);
+	if (attrs != NULL) {
+		g_assert (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == CKO_DATA);
+		g_assert (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "TEST LABEL") == 0);
+		g_free (value); value = NULL;
+		gp11_attributes_unref (attrs);
+	}
+
+	/* Async */
+	gp11_object_get_async (object, types, 2, NULL, fetch_async_result, &result);
+	WAIT_UNTIL (result);
+	g_assert (result != NULL);
+
+	attrs = gp11_object_get_finish (object, result, &err);
+	g_object_unref (result);
+	SUCCESS_RES (attrs, err);
+	if (attrs != NULL) {
+		g_assert (gp11_attributes_find_ulong (attrs, CKA_CLASS, &klass) && klass == CKO_DATA);
+		g_assert (gp11_attributes_find_string (attrs, CKA_LABEL, &value) && strcmp (value, "TEST LABEL") == 0);
+		g_free (value); value = NULL;
+		gp11_attributes_unref (attrs);
+	}
+
+	/* Set it to null and make sure taht works */
+	gp11_object_set_session (object, NULL);
+	g_assert (gp11_object_get_session (object) == NULL);
+	g_object_get (object, "session", &sess, NULL);
+	g_assert (sess == NULL);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]