* List of loaded libraries, as lib_entry_t
*/
linked_list_t *libs;
+
+ /**
+ * Slot event callback function
+ */
+ pkcs11_manager_token_event_t cb;
+
+ /**
+ * Slot event user data
+ */
+ void *data;
};
/**
DBG1(DBG_CFG, " found token in slot '%s':%lu (%s)",
entry->name, slot, info.slotDescription);
handle_token(entry, slot);
+ entry->this->cb(entry->this->data, entry->lib, slot, TRUE);
}
else
{
DBG1(DBG_CFG, "token removed from slot '%s':%lu (%s)",
entry->name, slot, info.slotDescription);
+ entry->this->cb(entry->this->data, entry->lib, slot, FALSE);
}
}
/**
* See header
*/
-pkcs11_manager_t *pkcs11_manager_create()
+pkcs11_manager_t *pkcs11_manager_create(pkcs11_manager_token_event_t cb,
+ void *data)
{
private_pkcs11_manager_t *this;
enumerator_t *enumerator;
.destroy = _destroy,
},
.libs = linked_list_create(),
+ .cb = cb,
+ .data = data,
);
enumerator = lib->settings->create_section_enumerator(lib->settings,
typedef struct pkcs11_manager_t pkcs11_manager_t;
+#include <library.h>
+
+#include "pkcs11_library.h"
+
+/**
+ * Token event callback function.
+ *
+ * @param data user supplied data, as passed to pkcs11_manager_create()
+ * @param p11 loaded PKCS#11 library token belongs to
+ * @param slot slot number the event occured in
+ * @param add TRUE if token was added to the slot, FALSE if removed
+ */
+typedef void (*pkcs11_manager_token_event_t)(void *data, pkcs11_library_t *p11,
+ CK_SLOT_ID slot, bool add);
+
+
/**
* Manages multiple PKCS#11 libraries with hot pluggable slots
*/
/**
* Create a pkcs11_manager instance.
*/
-pkcs11_manager_t *pkcs11_manager_create();
+pkcs11_manager_t *pkcs11_manager_create(pkcs11_manager_token_event_t cb,
+ void *data);
#endif /** PKCS11_MANAGER_H_ @}*/
#include "pkcs11_plugin.h"
#include <library.h>
+#include <debug.h>
#include "pkcs11_manager.h"
pkcs11_manager_t *manager;
};
+/**
+ * Token event callback function
+ */
+static void token_event_cb(private_pkcs11_plugin_t *this, pkcs11_library_t *p11,
+ CK_SLOT_ID slot, bool add)
+{
+}
+
METHOD(plugin_t, destroy, void,
private_pkcs11_plugin_t *this)
{
INIT(this,
.public.plugin.destroy = _destroy,
- .manager = pkcs11_manager_create(),
);
+ this->manager = pkcs11_manager_create((void*)token_event_cb, this);
+
return &this->public.plugin;
}