Add features support to af_alg plugin
[strongswan.git] / src / libstrongswan / plugins / af_alg / af_alg_plugin.c
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "af_alg_plugin.h"
17
18 #include <library.h>
19
20 #include "af_alg_hasher.h"
21 #include "af_alg_signer.h"
22 #include "af_alg_prf.h"
23 #include "af_alg_crypter.h"
24
25 typedef struct private_af_alg_plugin_t private_af_alg_plugin_t;
26
27 /**
28 * private data of af_alg_plugin
29 */
30 struct private_af_alg_plugin_t {
31
32 /**
33 * public functions
34 */
35 af_alg_plugin_t public;
36 };
37
38 METHOD(plugin_t, get_name, char*,
39 private_af_alg_plugin_t *this)
40 {
41 return "af-alg";
42 }
43
44 METHOD(plugin_t, get_features, int,
45 private_af_alg_plugin_t *this, plugin_feature_t *features[])
46 {
47 static plugin_feature_t f[AF_ALG_HASHER + AF_ALG_SIGNER +
48 AF_ALG_PRF + AF_ALG_CRYPTER + 4] = {};
49 static int count = 0;
50
51 if (!count)
52 { /* initialize only once */
53 f[count++] = PLUGIN_REGISTER(HASHER, af_alg_hasher_create);
54 af_alg_hasher_probe(f, &count);
55 f[count++] = PLUGIN_REGISTER(SIGNER, af_alg_signer_create);
56 af_alg_signer_probe(f, &count);
57 f[count++] = PLUGIN_REGISTER(PRF, af_alg_prf_create);
58 af_alg_prf_probe(f, &count);
59 f[count++] = PLUGIN_REGISTER(CRYPTER, af_alg_crypter_create);
60 af_alg_crypter_probe(f, &count);
61 }
62 *features = f;
63 return count;
64 }
65
66 METHOD(plugin_t, destroy, void,
67 private_af_alg_plugin_t *this)
68 {
69 free(this);
70 }
71
72 /*
73 * see header file
74 */
75 plugin_t *af_alg_plugin_create()
76 {
77 private_af_alg_plugin_t *this;
78
79 INIT(this,
80 .public = {
81 .plugin = {
82 .get_name = _get_name,
83 .get_features = _get_features,
84 .destroy = _destroy,
85 },
86 },
87 );
88
89 return &this->public.plugin;
90 }