Reimplemented mem pool to support multiple leases for a single identity
[strongswan.git] / src / libhydra / 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
16 /**
17 * @defgroup attribute_manager attribute_manager
18 * @{ @ingroup attributes
19 */
20
21 #ifndef ATTRIBUTE_MANAGER_H_
22 #define ATTRIBUTE_MANAGER_H_
23
24 #include "attribute_provider.h"
25 #include "attribute_handler.h"
26
27 typedef struct attribute_manager_t attribute_manager_t;
28
29 /**
30 * The attribute manager hands out attributes or handles them.
31 *
32 * The attribute manager manages both, attribute providers and attribute
33 * handlers. Attribute providers are responsible to hand out attributes if
34 * a connecting peer requests them. Handlers handle such attributes if they
35 * are received on the requesting peer.
36 */
37 struct attribute_manager_t {
38
39 /**
40 * Acquire a virtual IP address to assign to a peer.
41 *
42 * @param pool pool name to acquire address from
43 * @param id peer identity to get address forua
44 * @param requested IP in configuration request
45 * @return allocated address, NULL to serve none
46 */
47 host_t* (*acquire_address)(attribute_manager_t *this,
48 char *pool, identification_t *id,
49 host_t *requested);
50
51 /**
52 * Release a previously acquired address.
53 *
54 * @param pool pool name from which the address was acquired
55 * @param address address to release
56 * @param id peer identity to get address for
57 */
58 void (*release_address)(attribute_manager_t *this,
59 char *pool, host_t *address, identification_t *id);
60
61 /**
62 * Create an enumerator over attributes to hand out to a peer.
63 *
64 * @param pool pool name to get attributes from
65 * @param id peer identity to hand out attributes to
66 * @param vip virtual IP to assign to peer, if any
67 * @return enumerator (configuration_attribute_type_t, chunk_t)
68 */
69 enumerator_t* (*create_responder_enumerator)(attribute_manager_t *this,
70 char *pool, identification_t *id, host_t *vip);
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 server server from which the attribute was received
91 * @param handler handler we requested the attribute for, if any
92 * @param type type of configuration attribute
93 * @param data associated attribute data
94 * @return handler which handled this attribute, NULL if none
95 */
96 attribute_handler_t* (*handle)(attribute_manager_t *this,
97 identification_t *server, attribute_handler_t *handler,
98 configuration_attribute_type_t type, chunk_t data);
99
100 /**
101 * Release an attribute previously handle()d by a handler.
102 *
103 * @param handler handler returned by handle() for this attribute
104 * @param server server from which the attribute was received
105 * @param type type of attribute to release
106 * @param data associated attribute data
107 */
108 void (*release)(attribute_manager_t *this, attribute_handler_t *handler,
109 identification_t *server,
110 configuration_attribute_type_t type,
111 chunk_t data);
112
113 /**
114 * Create an enumerator over attributes to request from server.
115 *
116 * @param id server identity to hand out attributes to
117 * @param vip virtual IP going to request, if any
118 * @return enumerator (attribute_handler_t, ca_type_t, chunk_t)
119 */
120 enumerator_t* (*create_initiator_enumerator)(attribute_manager_t *this,
121 identification_t *id, host_t *vip);
122
123 /**
124 * Register an attribute handler to the manager.
125 *
126 * @param handler attribute handler to register
127 */
128 void (*add_handler)(attribute_manager_t *this,
129 attribute_handler_t *handler);
130
131 /**
132 * Unregister an attribute handler from the manager.
133 *
134 * @param handler attribute handler to unregister
135 */
136 void (*remove_handler)(attribute_manager_t *this,
137 attribute_handler_t *handler);
138
139 /**
140 * Destroy a attribute_manager instance.
141 */
142 void (*destroy)(attribute_manager_t *this);
143 };
144
145 /**
146 * Create a attribute_manager instance.
147 */
148 attribute_manager_t *attribute_manager_create();
149
150 #endif /** ATTRIBUTE_MANAGER_H_ @}*/