Add features support to eap-sim-file plugin
[strongswan.git] / src / libcharon / plugins / eap_sim_file / eap_sim_file_plugin.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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 "eap_sim_file_plugin.h"
17 #include "eap_sim_file_card.h"
18 #include "eap_sim_file_provider.h"
19 #include "eap_sim_file_triplets.h"
20
21 #include <daemon.h>
22
23 #define TRIPLET_FILE IPSEC_CONFDIR "/ipsec.d/triplets.dat"
24
25 typedef struct private_eap_sim_file_t private_eap_sim_file_t;
26
27 /**
28 * Private data of an eap_sim_file_t object.
29 */
30 struct private_eap_sim_file_t {
31
32 /**
33 * Public eap_sim_file_plugin_t interface.
34 */
35 eap_sim_file_plugin_t public;
36
37 /**
38 * SIM card
39 */
40 eap_sim_file_card_t *card;
41
42 /**
43 * SIM provider
44 */
45 eap_sim_file_provider_t *provider;
46
47 /**
48 * Triplet source
49 */
50 eap_sim_file_triplets_t *triplets;
51 };
52
53 METHOD(plugin_t, get_name, char*,
54 private_eap_sim_file_t *this)
55 {
56 return "eap-sim-file";
57 }
58
59 /**
60 * Callback providing our card to register
61 */
62 static simaka_card_t* get_card(private_eap_sim_file_t *this)
63 {
64 return &this->card->card;
65 }
66
67 /**
68 * Callback providing our provider to register
69 */
70 static simaka_provider_t* get_provider(private_eap_sim_file_t *this)
71 {
72 return &this->provider->provider;
73 }
74
75 METHOD(plugin_t, get_features, int,
76 private_eap_sim_file_t *this, plugin_feature_t *features[])
77 {
78 static plugin_feature_t f[] = {
79 PLUGIN_CALLBACK(simaka_manager_register, get_card),
80 PLUGIN_PROVIDE(CUSTOM, "sim-card"),
81 PLUGIN_DEPENDS(CUSTOM, "sim-manager"),
82 PLUGIN_CALLBACK(simaka_manager_register, get_provider),
83 PLUGIN_PROVIDE(CUSTOM, "sim-provider"),
84 PLUGIN_DEPENDS(CUSTOM, "sim-manager"),
85 };
86 *features = f;
87 return countof(f);
88 }
89
90 METHOD(plugin_t, destroy, void,
91 private_eap_sim_file_t *this)
92 {
93 this->card->destroy(this->card);
94 this->provider->destroy(this->provider);
95 this->triplets->destroy(this->triplets);
96 free(this);
97 }
98
99 /**
100 * See header
101 */
102 plugin_t *eap_sim_file_plugin_create()
103 {
104 private_eap_sim_file_t *this;
105
106 INIT(this,
107 .public = {
108 .plugin = {
109 .get_name = _get_name,
110 .get_features = _get_features,
111 .destroy = _destroy,
112 },
113 },
114 .triplets = eap_sim_file_triplets_create(TRIPLET_FILE),
115 );
116 this->provider = eap_sim_file_provider_create(this->triplets);
117 this->card = eap_sim_file_card_create(this->triplets);
118
119 return &this->public.plugin;
120 }
121