attribute_manager supports attribute_handler's to handle configuration attributes...
[strongswan.git] / src / charon / config / attributes / attribute_manager.h
1 /*
2 * Copyright (C) 2008-2009 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 /**
19 * @defgroup attribute_manager attribute_manager
20 * @{ @ingroup attributes
21 */
22
23 #ifndef ATTRIBUTE_MANAGER_H_
24 #define ATTRIBUTE_MANAGER_H_
25
26 #include <config/attributes/attribute_provider.h>
27 #include <config/attributes/attribute_handler.h>
28
29 typedef struct attribute_manager_t attribute_manager_t;
30
31 /**
32 * The attribute manager hands out attributes or handles them.
33 *
34 * The attribute manager manages both, attribute providers and attribute
35 * handlers. Attribute providers are responsible to hand out attributes if
36 * a connecting peer requests them. Handlers handle such attributes if they
37 * are received on the requesting peer.
38 */
39 struct attribute_manager_t {
40
41 /**
42 * Acquire a virtual IP address to assign to a peer.
43 *
44 * @param pool pool name to acquire address from
45 * @param id peer identity to get address forua
46 * @param requested IP in configuration request
47 * @return allocated address, NULL to serve none
48 */
49 host_t* (*acquire_address)(attribute_manager_t *this,
50 char *pool, identification_t *id,
51 host_t *requested);
52
53 /**
54 * Release a previously acquired address.
55 *
56 * @param pool pool name from which the address was acquired
57 * @param address address to release
58 * @param id peer identity to get address for
59 */
60 void (*release_address)(attribute_manager_t *this,
61 char *pool, host_t *address, identification_t *id);
62
63 /**
64 * Create an enumerator over attributes to hand out to a peer.
65 *
66 * @param id peer identity to hand out attributes to
67 * @return enumerator (configuration_attribute_type_t, chunk_t)
68 */
69 enumerator_t* (*create_attribute_enumerator)(attribute_manager_t *this,
70 identification_t *id);
71
72 /**
73 * Register an attribute provider to the manager.
74 *
75 * @param provider attribute provider to register
76 */
77 void (*add_provider)(attribute_manager_t *this,
78 attribute_provider_t *provider);
79 /**
80 * Unregister an attribute provider from the manager.
81 *
82 * @param provider attribute provider to unregister
83 */
84 void (*remove_provider)(attribute_manager_t *this,
85 attribute_provider_t *provider);
86
87 /**
88 * Handle a configuration attribute by passing them to the handlers.
89 *
90 * @param ike_sa IKE_SA where attribute was received
91 * @param type type of configuration attribute
92 * @param data associated attribute data
93 * @return handler which handled this attribute, NULL if none
94 */
95 attribute_handler_t* (*handle)(attribute_manager_t *this, ike_sa_t *ike_sa,
96 configuration_attribute_type_t type, chunk_t data);
97
98 /**
99 * Release an attribute previously handle()d by a handler.
100 *
101 * @param handler handler returned by handle() for this attribute
102 * @param ike_sa IKE_SA owning the attribute
103 * @param type type of attribute to release
104 * @param data associated attribute data
105 */
106 void (*release)(attribute_manager_t *this, attribute_handler_t *handler,
107 ike_sa_t *ike_sa, configuration_attribute_type_t type,
108 chunk_t data);
109
110 /**
111 * Register an attribute handler to the manager.
112 *
113 * @param handler attribute handler to register
114 */
115 void (*add_handler)(attribute_manager_t *this,
116 attribute_handler_t *handler);
117
118 /**
119 * Unregister an attribute handler from the manager.
120 *
121 * @param handler attribute handler to unregister
122 */
123 void (*remove_handler)(attribute_manager_t *this,
124 attribute_handler_t *handler);
125
126 /**
127 * Destroy a attribute_manager instance.
128 */
129 void (*destroy)(attribute_manager_t *this);
130 };
131
132 /**
133 * Create a attribute_manager instance.
134 */
135 attribute_manager_t *attribute_manager_create();
136
137 #endif /** ATTRIBUTE_MANAGER_H_ @}*/