8bc80ca111ed0d18b588ff3e3ead7e60312f9d90
[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 * @return TRUE if address released to pool
58 */
59 bool (*release_address)(attribute_manager_t *this,
60 char *pool, host_t *address, identification_t *id);
61
62 /**
63 * Create an enumerator over attributes to hand out to a peer.
64 *
65 * @param pool list of pools names (char*) to query attributes from
66 * @param id peer identity to hand out attributes to
67 * @param vip list of virtual IPs (host_t*) to assign to peer
68 * @return enumerator (configuration_attribute_type_t, chunk_t)
69 */
70 enumerator_t* (*create_responder_enumerator)(attribute_manager_t *this,
71 linked_list_t *pool, identification_t *id,
72 linked_list_t *vips);
73
74 /**
75 * Register an attribute provider to the manager.
76 *
77 * @param provider attribute provider to register
78 */
79 void (*add_provider)(attribute_manager_t *this,
80 attribute_provider_t *provider);
81 /**
82 * Unregister an attribute provider from the manager.
83 *
84 * @param provider attribute provider to unregister
85 */
86 void (*remove_provider)(attribute_manager_t *this,
87 attribute_provider_t *provider);
88
89 /**
90 * Handle a configuration attribute by passing them to the handlers.
91 *
92 * @param server server from which the attribute was received
93 * @param handler handler we requested the attribute for, if any
94 * @param type type of configuration attribute
95 * @param data associated attribute data
96 * @return handler which handled this attribute, NULL if none
97 */
98 attribute_handler_t* (*handle)(attribute_manager_t *this,
99 identification_t *server, attribute_handler_t *handler,
100 configuration_attribute_type_t type, chunk_t data);
101
102 /**
103 * Release an attribute previously handle()d by a handler.
104 *
105 * @param handler handler returned by handle() for this attribute
106 * @param server server from which the attribute was received
107 * @param type type of attribute to release
108 * @param data associated attribute data
109 */
110 void (*release)(attribute_manager_t *this, attribute_handler_t *handler,
111 identification_t *server,
112 configuration_attribute_type_t type,
113 chunk_t data);
114
115 /**
116 * Create an enumerator over attributes to request from server.
117 *
118 * @param id server identity to hand out attributes to
119 * @param vip list of virtual IPs (host_t*) going to request
120 * @return enumerator (attribute_handler_t, ca_type_t, chunk_t)
121 */
122 enumerator_t* (*create_initiator_enumerator)(attribute_manager_t *this,
123 identification_t *id, linked_list_t *vips);
124
125 /**
126 * Register an attribute handler to the manager.
127 *
128 * @param handler attribute handler to register
129 */
130 void (*add_handler)(attribute_manager_t *this,
131 attribute_handler_t *handler);
132
133 /**
134 * Unregister an attribute handler from the manager.
135 *
136 * @param handler attribute handler to unregister
137 */
138 void (*remove_handler)(attribute_manager_t *this,
139 attribute_handler_t *handler);
140
141 /**
142 * Destroy a attribute_manager instance.
143 */
144 void (*destroy)(attribute_manager_t *this);
145 };
146
147 /**
148 * Create a attribute_manager instance.
149 */
150 attribute_manager_t *attribute_manager_create();
151
152 #endif /** ATTRIBUTE_MANAGER_H_ @}*/