drop even more glue.
[apps/madmutt.git] / lib-crypt / crypt-mod.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 2004 g10 Code GmbH
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 #include <lib-lib/lib-lib.h>
11
12 #include "crypt-mod.h"
13
14 /* A type an a variable to keep track of registered crypto modules. */
15 typedef struct crypt_module *crypt_module_t;
16
17 struct crypt_module {
18   crypt_module_specs_t specs;
19   crypt_module_t next, *prevp;
20 };
21
22 static crypt_module_t modules;
23
24 /* Register a new crypto module. */
25 void crypto_module_register (crypt_module_specs_t specs)
26 {
27   crypt_module_t module_new = p_new(struct crypt_module, 1);
28
29   module_new->specs = specs;
30   module_new->next = modules;
31   if (modules)
32     modules->prevp = &module_new->next;
33   modules = module_new;
34 }
35
36 /* Return the crypto module specs for IDENTIFIER.  This function is
37    usually used via the CRYPT_MOD_CALL[_CHECK] macros. */
38 crypt_module_specs_t crypto_module_lookup (int identifier)
39 {
40   crypt_module_t module = modules;
41
42   while (module && (module->specs->identifier != identifier))
43     module = module->next;
44
45   return module ? module->specs : NULL;
46 }