reintegrated two-sim branch providing SIM card plugin API
[strongswan.git] / src / charon / sa / authenticators / eap / sim_manager.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 * $Id$
16 */
17
18 #include "sim_manager.h"
19
20 #include <utils/linked_list.h>
21
22 typedef struct private_sim_manager_t private_sim_manager_t;
23
24 /**
25 * Private data of an sim_manager_t object.
26 */
27 struct private_sim_manager_t {
28
29 /**
30 * Public sim_manager_t interface.
31 */
32 sim_manager_t public;
33
34 /**
35 * list of added cards
36 */
37 linked_list_t *cards;
38
39 /**
40 * list of added provider
41 */
42 linked_list_t *provider;
43 };
44
45 /**
46 * Implementation of sim_manager_t.add_card
47 */
48 static void add_card(private_sim_manager_t *this, sim_card_t *card)
49 {
50 this->cards->insert_last(this->cards, card);
51 }
52
53 /**
54 * Implementation of sim_manager_t.remove_card
55 */
56 static void remove_card(private_sim_manager_t *this, sim_card_t *card)
57 {
58 this->cards->remove(this->cards, card, NULL);
59 }
60
61 /**
62 * Implementation of sim_manager_t.create_card_enumerator
63 */
64 static enumerator_t* create_card_enumerator(private_sim_manager_t *this)
65 {
66 return this->cards->create_enumerator(this->cards);
67 }
68
69 /**
70 * Implementation of sim_manager_t.add_provider
71 */
72 static void add_provider(private_sim_manager_t *this,
73 sim_provider_t *provider)
74 {
75 this->provider->insert_last(this->provider, provider);
76 }
77
78 /**
79 * Implementation of sim_manager_t.remove_provider
80 */
81 static void remove_provider(private_sim_manager_t *this,
82 sim_provider_t *provider)
83 {
84 this->provider->remove(this->provider, provider, NULL);
85 }
86
87 /**
88 * Implementation of sim_manager_t.create_provider_enumerator
89 */
90 static enumerator_t* create_provider_enumerator(private_sim_manager_t *this)
91 {
92 return this->provider->create_enumerator(this->provider);
93 }
94
95 /**
96 * Implementation of sim_manager_t.destroy.
97 */
98 static void destroy(private_sim_manager_t *this)
99 {
100 this->cards->destroy(this->cards);
101 this->provider->destroy(this->provider);
102 free(this);
103 }
104
105 /**
106 * See header
107 */
108 sim_manager_t *sim_manager_create()
109 {
110 private_sim_manager_t *this = malloc_thing(private_sim_manager_t);
111
112 this->public.add_card = (void(*)(sim_manager_t*, sim_card_t *card))add_card;
113 this->public.remove_card = (void(*)(sim_manager_t*, sim_card_t *card))remove_card;
114 this->public.create_card_enumerator = (enumerator_t*(*)(sim_manager_t*))create_card_enumerator;
115 this->public.add_provider = (void(*)(sim_manager_t*, sim_provider_t *provider))add_provider;
116 this->public.remove_provider = (void(*)(sim_manager_t*, sim_provider_t *provider))remove_provider;
117 this->public.create_provider_enumerator = (enumerator_t*(*)(sim_manager_t*))create_provider_enumerator;
118 this->public.destroy = (void(*)(sim_manager_t*))destroy;
119
120 this->cards = linked_list_create();
121 this->provider = linked_list_create();
122
123 return &this->public;
124 }
125