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