Annotation of embedaddon/strongswan/src/libcharon/plugins/eap_simaka_sql/eap_simaka_sql_plugin.c, revision 1.1.1.1
1.1 misho 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 "eap_simaka_sql_plugin.h"
17: #include "eap_simaka_sql_card.h"
18: #include "eap_simaka_sql_provider.h"
19:
20: #include <daemon.h>
21:
22: typedef struct private_eap_simaka_sql_t private_eap_simaka_sql_t;
23:
24: /**
25: * Private data of an eap_simaka_sql_t object.
26: */
27: struct private_eap_simaka_sql_t {
28:
29: /**
30: * Public eap_simaka_sql_plugin_t interface.
31: */
32: eap_simaka_sql_plugin_t public;
33:
34: /**
35: * (U)SIM card
36: */
37: eap_simaka_sql_card_t *card;
38:
39: /**
40: * (U)SIM provider
41: */
42: eap_simaka_sql_provider_t *provider;
43:
44: /**
45: * Database with triplets/quintuplets
46: */
47: database_t *db;
48: };
49:
50: METHOD(plugin_t, get_name, char*,
51: private_eap_simaka_sql_t *this)
52: {
53: return "eap-simaka-sql";
54: }
55:
56: /**
57: * Load database
58: */
59: static bool load_db(private_eap_simaka_sql_t *this,
60: plugin_feature_t *feature, bool reg, void *data)
61: {
62: if (reg)
63: {
64: bool remove_used;
65: char *uri;
66:
67: uri = lib->settings->get_str(lib->settings,
68: "%s.plugins.eap-simaka-sql.database", NULL,
69: lib->ns);
70: if (!uri)
71: {
72: DBG1(DBG_CFG, "eap-simaka-sql database URI missing");
73: return FALSE;
74: }
75: this->db = lib->db->create(lib->db, uri);
76: if (!this->db)
77: {
78: DBG1(DBG_CFG, "opening eap-simaka-sql database failed");
79: return FALSE;
80: }
81: remove_used = lib->settings->get_bool(lib->settings,
82: "%s.plugins.eap-simaka-sql.remove_used", FALSE,
83: lib->ns);
84:
85: this->provider = eap_simaka_sql_provider_create(this->db, remove_used);
86: this->card = eap_simaka_sql_card_create(this->db, remove_used);
87: return TRUE;
88: }
89: this->card->destroy(this->card);
90: this->provider->destroy(this->provider);
91: this->db->destroy(this->db);
92: this->card = NULL;
93: this->provider = NULL;
94: this->db = NULL;
95: return TRUE;
96: }
97:
98: /**
99: * Callback providing our card to register
100: */
101: static simaka_card_t* get_card(private_eap_simaka_sql_t *this)
102: {
103: return &this->card->card;
104: }
105:
106: /**
107: * Callback providing our provider to register
108: */
109: static simaka_provider_t* get_provider(private_eap_simaka_sql_t *this)
110: {
111: return &this->provider->provider;
112: }
113:
114: METHOD(plugin_t, get_features, int,
115: private_eap_simaka_sql_t *this, plugin_feature_t *features[])
116: {
117: static plugin_feature_t f[] = {
118: PLUGIN_CALLBACK((void*)load_db, NULL),
119: PLUGIN_PROVIDE(CUSTOM, "eap-simaka-sql-db"),
120: PLUGIN_DEPENDS(DATABASE, DB_ANY),
121: PLUGIN_SDEPEND(DATABASE, DB_SQLITE),
122: PLUGIN_SDEPEND(DATABASE, DB_MYSQL),
123: PLUGIN_CALLBACK(simaka_manager_register, get_card),
124: PLUGIN_PROVIDE(CUSTOM, "aka-card"),
125: PLUGIN_DEPENDS(CUSTOM, "aka-manager"),
126: PLUGIN_DEPENDS(CUSTOM, "eap-simaka-sql-db"),
127: PLUGIN_PROVIDE(CUSTOM, "sim-card"),
128: PLUGIN_DEPENDS(CUSTOM, "sim-manager"),
129: PLUGIN_DEPENDS(CUSTOM, "eap-simaka-sql-db"),
130: PLUGIN_CALLBACK(simaka_manager_register, get_provider),
131: PLUGIN_PROVIDE(CUSTOM, "aka-provider"),
132: PLUGIN_DEPENDS(CUSTOM, "aka-manager"),
133: PLUGIN_DEPENDS(CUSTOM, "eap-simaka-sql-db"),
134: PLUGIN_PROVIDE(CUSTOM, "sim-provider"),
135: PLUGIN_DEPENDS(CUSTOM, "sim-manager"),
136: PLUGIN_DEPENDS(CUSTOM, "eap-simaka-sql-db"),
137: };
138: *features = f;
139: return countof(f);
140: }
141:
142: METHOD(plugin_t, destroy, void,
143: private_eap_simaka_sql_t *this)
144: {
145: free(this);
146: }
147:
148: /**
149: * See header
150: */
151: plugin_t *eap_simaka_sql_plugin_create()
152: {
153: private_eap_simaka_sql_t *this;
154:
155: INIT(this,
156: .public = {
157: .plugin = {
158: .get_name = _get_name,
159: .get_features = _get_features,
160: .destroy = _destroy,
161: },
162: },
163: );
164:
165: return &this->public.plugin;
166: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>