#include "config.h"
#include "lib/lib.h"
#include "crypt_mod.h"
+#include "queue.h"
/**
* struct CryptModule - A crypto plugin module
*
* A type of a variable to keep track of registered crypto modules.
*/
+
+STAILQ_HEAD(CryptModules, CryptModule)
+modules = STAILQ_HEAD_INITIALIZER(modules);
struct CryptModule
{
- crypt_module_specs_t specs;
- struct CryptModule *next, **prevp;
+ struct CryptModuleSpecs *specs;
+ STAILQ_ENTRY(CryptModule) entries;
};
-static struct CryptModule *modules;
-
/**
* crypto_module_register - Register a new crypto module
*/
-void crypto_module_register(crypt_module_specs_t specs)
+void crypto_module_register(struct CryptModuleSpecs *specs)
{
- struct CryptModule *module_new = safe_malloc(sizeof(*module_new));
-
- module_new->specs = specs;
- module_new->next = modules;
- if (modules)
- modules->prevp = &module_new->next;
- modules = module_new;
+ struct CryptModule *module = safe_calloc(1, sizeof(struct CryptModule));
+ module->specs = specs;
+ STAILQ_INSERT_HEAD(&modules, module, entries);
}
/**
* Return the crypto module specs for IDENTIFIER.
* This function is usually used via the CRYPT_MOD_CALL[_CHECK] macros.
*/
-crypt_module_specs_t crypto_module_lookup(int identifier)
+struct CryptModuleSpecs *crypto_module_lookup(int identifier)
{
- struct CryptModule *module = modules;
-
- while (module && (module->specs->identifier != identifier))
- module = module->next;
-
- return module ? module->specs : NULL;
+ struct CryptModule *module = NULL;
+ STAILQ_FOREACH(module, &modules, entries)
+ {
+ if (module->specs->identifier == identifier)
+ {
+ return module->specs;
+ }
+ }
+ return NULL;
}
*
* A structure to keep all crypto module functions together.
*/
-typedef struct CryptModuleFunctions
+struct CryptModuleFunctions
{
/* Common/General functions. */
crypt_func_init_t init;
crypt_func_smime_verify_sender_t smime_verify_sender;
crypt_func_smime_build_smime_entity_t smime_build_smime_entity;
crypt_func_smime_invoke_import_t smime_invoke_import;
-} crypt_module_functions_t;
+};
/**
* struct CryptModuleSpecs - Crypto API
*
* A structure to describe a crypto module.
*/
-typedef struct CryptModuleSpecs
+struct CryptModuleSpecs
{
int identifier; /**< Identifying bit */
- crypt_module_functions_t functions;
-} * crypt_module_specs_t;
+ struct CryptModuleFunctions functions;
+};
/*
High Level crypto module interface.
*/
-void crypto_module_register(crypt_module_specs_t specs);
-crypt_module_specs_t crypto_module_lookup(int identifier);
+void crypto_module_register(struct CryptModuleSpecs *specs);
+struct CryptModuleSpecs *crypto_module_lookup(int identifier);
/** If the crypto module identifier by IDENTIFIER has been registered,
call its function FUNC. Do nothing else. This may be used as an