61dd7e956b7f97fa60ae7e2ea372a9471ee72674
[strongswan.git] / Source / charon / configuration_manager.c
1 /**
2 * @file configuration.c
3 *
4 * @brief Configuration class used to store IKE_SA-configurations.
5 *
6 * Object of this type represents a configuration for an IKE_SA and its child_sa's.
7 *
8 */
9
10 /*
11 * Copyright (C) 2005 Jan Hutter, Martin Willi
12 * Hochschule fuer Technik Rapperswil
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 */
24
25 #include <stdlib.h>
26
27 #include "configuration_manager.h"
28
29 #include "types.h"
30 #include "utils/allocator.h"
31
32 /**
33 * Private data of an configuration_t object
34 */
35 typedef struct private_configuration_manager_s private_configuration_manager_t;
36
37 struct private_configuration_manager_s {
38
39 /**
40 * Public part
41 */
42 configuration_manager_t public;
43
44 };
45
46 static status_t get_remote_host(private_configuration_manager_t *this, char *name, host_t **host)
47 {
48 /* some hard coded users for testing */
49 host_t *remote;
50 if (strcmp(name, "pinflb30") == 0) {
51 remote = host_create(AF_INET, "152.96.193.130", 4500);
52 if (remote == NULL) {
53 return OUT_OF_RES;
54 }
55 return SUCCESS;
56 }
57 else if (strcmp(name, "pinflb31") == 0) {
58 remote = host_create(AF_INET, "152.96.193.131", 4500);
59 if (remote == NULL) {
60 return OUT_OF_RES;
61 }
62 return SUCCESS;
63 }
64 return NOT_FOUND;
65 }
66
67 static status_t get_local_host(private_configuration_manager_t *this, char *name, host_t **host)
68 {
69 /* use default route for now */
70 host_t *local;
71 local = host_create(AF_INET, "0.0.0.0", 4500);
72 if (local == NULL)
73 {
74 return OUT_OF_RES;
75 }
76 *host = local;
77 return SUCCESS;
78 }
79
80 static status_t get_proposals_for_host(private_configuration_manager_t *this, host_t *host, linked_list_iterator_t *list)
81 {
82 return FAILED;
83 }
84
85 static status_t select_proposals_for_host(private_configuration_manager_t *this, host_t *host, linked_list_iterator_t *in, linked_list_iterator_t *out)
86 {
87 return FAILED;
88 }
89
90
91 /**
92 * Implements function destroy of configuration_t.
93 * See #configuration_s.destroy for description.
94 */
95 static status_t destroy(private_configuration_manager_t *this)
96 {
97 allocator_free(this);
98 return SUCCESS;
99 }
100
101 /*
102 * Described in header-file
103 */
104 configuration_manager_t *configuration_manager_create()
105 {
106 private_configuration_manager_t *this = allocator_alloc_thing(private_configuration_manager_t);
107 if (this == NULL)
108 {
109 return NULL;
110 }
111
112 /* public functions */
113 this->public.destroy = (status_t(*)(configuration_manager_t*))destroy;
114 this->public.get_remote_host = (status_t(*)(configuration_manager_t*,char*,host_t**))get_remote_host;
115 this->public.get_local_host = (status_t(*)(configuration_manager_t*,char*,host_t**))get_local_host;
116 this->public.get_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,linked_list_iterator_t*))get_proposals_for_host;
117 this->public.select_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,linked_list_iterator_t*,linked_list_iterator_t*))select_proposals_for_host;
118
119
120 return (&this->public);
121 }