/src/strongswan/src/libstrongswan/plugins/constraints/constraints_plugin.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2010 Martin Willi |
3 | | * |
4 | | * Copyright (C) secunet Security Networks AG |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify it |
7 | | * under the terms of the GNU General Public License as published by the |
8 | | * Free Software Foundation; either version 2 of the License, or (at your |
9 | | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, but |
12 | | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
13 | | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 | | * for more details. |
15 | | */ |
16 | | |
17 | | #include "constraints_plugin.h" |
18 | | |
19 | | #include <library.h> |
20 | | #include "constraints_validator.h" |
21 | | |
22 | | typedef struct private_constraints_plugin_t private_constraints_plugin_t; |
23 | | |
24 | | /** |
25 | | * private data of constraints_plugin |
26 | | */ |
27 | | struct private_constraints_plugin_t { |
28 | | |
29 | | /** |
30 | | * public functions |
31 | | */ |
32 | | constraints_plugin_t public; |
33 | | |
34 | | /** |
35 | | * Validator implementation instance. |
36 | | */ |
37 | | constraints_validator_t *validator; |
38 | | }; |
39 | | |
40 | | METHOD(plugin_t, get_name, char*, |
41 | | private_constraints_plugin_t *this) |
42 | 0 | { |
43 | 0 | return "constraints"; |
44 | 0 | } |
45 | | |
46 | | /** |
47 | | * Register validator |
48 | | */ |
49 | | static bool plugin_cb(private_constraints_plugin_t *this, |
50 | | plugin_feature_t *feature, bool reg, void *cb_data) |
51 | 0 | { |
52 | 0 | if (reg) |
53 | 0 | { |
54 | 0 | lib->credmgr->add_validator(lib->credmgr, &this->validator->validator); |
55 | 0 | } |
56 | 0 | else |
57 | 0 | { |
58 | 0 | lib->credmgr->remove_validator(lib->credmgr, |
59 | 0 | &this->validator->validator); |
60 | 0 | } |
61 | 0 | return TRUE; |
62 | 0 | } |
63 | | |
64 | | METHOD(plugin_t, get_features, int, |
65 | | private_constraints_plugin_t *this, plugin_feature_t *features[]) |
66 | 0 | { |
67 | 0 | static plugin_feature_t f[] = { |
68 | 0 | PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL), |
69 | 0 | PLUGIN_PROVIDE(CUSTOM, "constraints"), |
70 | 0 | PLUGIN_SDEPEND(CERT_DECODE, CERT_X509), |
71 | 0 | }; |
72 | 0 | *features = f; |
73 | 0 | return countof(f); |
74 | 0 | } |
75 | | |
76 | | METHOD(plugin_t, destroy, void, |
77 | | private_constraints_plugin_t *this) |
78 | 0 | { |
79 | 0 | this->validator->destroy(this->validator); |
80 | 0 | free(this); |
81 | 0 | } |
82 | | |
83 | | /* |
84 | | * see header file |
85 | | */ |
86 | | PLUGIN_DEFINE(constraints) |
87 | 0 | { |
88 | 0 | private_constraints_plugin_t *this; |
89 | |
|
90 | 0 | INIT(this, |
91 | 0 | .public = { |
92 | 0 | .plugin = { |
93 | 0 | .get_name = _get_name, |
94 | 0 | .get_features = _get_features, |
95 | 0 | .destroy = _destroy, |
96 | 0 | }, |
97 | 0 | }, |
98 | 0 | .validator = constraints_validator_create(), |
99 | 0 | ); |
100 | |
|
101 | 0 | return &this->public.plugin; |
102 | 0 | } |