summaryrefslogtreecommitdiff
path: root/ckcapi-session.h
diff options
context:
space:
mode:
Diffstat (limited to 'ckcapi-session.h')
-rw-r--r--ckcapi-session.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/ckcapi-session.h b/ckcapi-session.h
new file mode 100644
index 0000000..6007662
--- /dev/null
+++ b/ckcapi-session.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2007 Stef Walter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef CKCAPI_SESSION_H
+#define CKCAPI_SESSION_H
+
+#include "ckcapi.h"
+
+/* For operation_type in CkCapiSession */
+enum
+{
+ OPERATION_NONE = 0,
+ OPERATION_FIND = 1,
+};
+
+/* Callback to cancel a current operation */
+typedef void (*CkCapiSessionCancel) (struct _CkCapiSession* sess);
+
+/* Represents an open session */
+typedef struct _CkCapiSession
+{
+ CK_SESSION_HANDLE id; /* Unique ID for this session */
+ CK_SLOT_ID slot;
+ int in_call; /* Whether this session is use in PKCS#11 function */
+
+ HCERTSTORE store; /* Handle to an open certificate store */
+
+ int operation_type; /* Whether an operation is happening or not */
+ void* operation_data; /* Data for this operation */
+ CkCapiSessionCancel operation_cancel; /* Callback to cancel operation when necessary */
+
+ CkCapiHash* object_data;
+
+ CK_NOTIFY notify_callback; /* Application specified callback */
+ CK_VOID_PTR user_data; /* Argument for above */
+
+ int refs; /* Reference count */
+ HANDLE mutex; /* Mutex for protecting this structure */
+}
+CkCapiSession;
+
+/* Debug print something related to a session */
+#define DBGS(sess, msg) \
+ ckcapi_debug("S%d: %s", (sess) ? (sess)->id : 0, (msg))
+
+/* Create a session */
+CK_RV ckcapi_session_create (CK_SLOT_ID slot, CkCapiSession** ret);
+
+/* Destroy a session */
+void ckcapi_session_destroy (CkCapiSession* sess);
+
+/* Register a new session */
+CK_RV ckcapi_session_register (CkCapiSession* sess);
+
+/* Get a session from a handle, and lock it */
+CK_RV ckcapi_session_get_lock_ref (CK_ULONG id, int remove,
+ CkCapiSession **sess);
+
+/* Unlock and unreference a session */
+void ckcapi_session_unref_unlock (CkCapiSession* sess);
+
+/* Close all sessions on a certain slot/token */
+CK_RV ckcapi_session_close_all (CK_SLOT_ID slot);
+
+
+
+/* Start a find operation on a session */
+CK_RV ckcapi_session_find_init (CkCapiSession* sess,
+ CK_ATTRIBUTE_PTR templ,
+ CK_ULONG count);
+
+/* Return results from a find operation */
+CK_RV ckcapi_session_find (CkCapiSession* sess,
+ CK_OBJECT_HANDLE_PTR objects,
+ CK_ULONG max_object_count,
+ CK_ULONG_PTR object_count);
+
+/* End a find operation */
+CK_RV ckcapi_session_find_final (CkCapiSession* sess);
+
+
+
+
+/* Get object data for an object */
+CK_RV ckcapi_session_get_object_data (CkCapiSession* sess,
+ CkCapiObject* obj,
+ CkCapiObjectData** objdata);
+
+/* Get object data for an object handle */
+CK_RV ckcapi_session_get_object_data_for (CkCapiSession* sess,
+ CK_OBJECT_HANDLE hand,
+ CkCapiObjectData** objdata);
+
+/* Set object data for an object */
+void ckcapi_session_take_object_data (CkCapiSession* sess,
+ CkCapiObject* obj,
+ CkCapiObjectData* objdata);
+
+/* Clear object data for an object */
+void ckcapi_session_clear_object_data (CkCapiSession* sess,
+ CkCapiObject* obj);
+
+/* Enumerate object data for all objects */
+typedef void (*CkCapiEnumObjectData) (CkCapiSession* sess,
+ CkCapiObject* obj,
+ CkCapiObjectData* data,
+ void* arg);
+void ckcapi_session_enum_object_data (CkCapiSession* sess,
+ CkCapiEnumObjectData enum_func,
+ void* arg);
+
+void ckcapi_session_cleanup_all (void);
+
+#endif /* CKCAPI_SESSION_H */