-
Notifications
You must be signed in to change notification settings - Fork 84
/
WTPConfigFile.c
241 lines (197 loc) · 9.82 KB
/
WTPConfigFile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*******************************************************************************************
* Copyright (c) 2006-7 Laboratorio di Sistemi di Elaborazione e Bioingegneria Informatica *
* Universita' Campus BioMedico - Italy *
* *
* This program is free software; you can redistribute it and/or modify it under the terms *
* of the GNU General Public License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with this *
* program; if not, write to the: *
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, *
* MA 02111-1307, USA. *
* *
* In addition, as a special exception, the copyright holders give permission to link the *
* code of portions of this program with the OpenSSL library under certain conditions as *
* described in each individual source file, and distribute linked combinations including *
* the two. You must obey the GNU General Public License in all respects for all of the *
* code used other than OpenSSL. If you modify file(s) with this exception, you may *
* extend this exception to your version of the file(s), but you are not obligated to do *
* so. If you do not wish to do so, delete this exception statement from your version. *
* If you delete this exception statement from all source files in the program, then also *
* delete it here. *
*
* --------------------------------------------------------------------------------------- *
* Project: Capwap *
* *
* Author : Ludovico Rossi ([email protected]) *
* Del Moro Andrea ([email protected]) *
* Giovannini Federica ([email protected]) *
* Massimo Vellucci ([email protected]) *
* Mauro Bisson ([email protected]) *
*******************************************************************************************/
#include "CWWTP.h"
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
const char *CW_CONFIG_FILE = "config.wtp";
CWBool CWConfigFileInitLib() {
gConfigValuesCount = 14;
CW_CREATE_ARRAY_ERR(gConfigValues, gConfigValuesCount, CWConfigValue, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
gConfigValues[0].type = CW_STRING_ARRAY;
gConfigValues[0].code = "<AC_ADDRESSES>";
gConfigValues[0].endCode = "</AC_ADDRESSES>";
gConfigValues[0].value.str_array_value = NULL;
gConfigValues[0].count = 0;
gConfigValues[1].type = CW_INTEGER;
gConfigValues[1].code = "</WTP_FORCE_MTU>";
gConfigValues[1].value.int_value = 0;
gConfigValues[2].type = CW_STRING;
gConfigValues[2].code = "</WTP_LEV3_PROTOCOL>";
gConfigValues[2].value.str_value = NULL;
gConfigValues[3].type = CW_STRING;
gConfigValues[3].code = "</WTP_NAME>";
gConfigValues[3].value.str_value = NULL;
gConfigValues[4].type = CW_STRING;
gConfigValues[4].code = "</WTP_LOCATION>";
gConfigValues[4].value.str_value = NULL;
gConfigValues[5].type = CW_STRING;
gConfigValues[5].code = "</WTP_FORCE_AC_ADDRESS>";
gConfigValues[5].value.str_value = NULL;
gConfigValues[6].type = CW_STRING;
gConfigValues[6].code = "</WTP_FORCE_SECURITY>";
gConfigValues[6].value.str_value = NULL;
gConfigValues[7].type = CW_INTEGER;
gConfigValues[7].code = "</WTP_LOG_FILE_ENABLE>";
gConfigValues[7].value.int_value = 0;
gConfigValues[8].type = CW_INTEGER;
gConfigValues[8].code = "</WTP_LOG_FILE_SIZE>";
gConfigValues[8].value.int_value = DEFAULT_LOG_SIZE;
/* Elena Agostini - 02/2014: OpenSSL params config.wtp */
gConfigValues[9].type = CW_STRING;
gConfigValues[9].code = "</WTP_SECURITY_CERTIFICATE>";
gConfigValues[9].value.str_value = NULL;
gConfigValues[10].type = CW_STRING;
gConfigValues[10].code = "</WTP_SECURITY_KEYFILE>";
gConfigValues[10].value.str_value = NULL;
gConfigValues[11].type = CW_STRING;
gConfigValues[11].code = "</WTP_SECURITY_PASSWORD>";
gConfigValues[11].value.str_value = NULL;
/* Elena Agostini - 02/2014: Port number params config.wtp */
gConfigValues[12].type = CW_INTEGER;
gConfigValues[12].code = "</WTP_PORT_CONTROL>";
gConfigValues[12].value.int_value = -1;
gConfigValues[13].type = CW_INTEGER;
gConfigValues[13].code = "</WTP_PORT_DATA>";
gConfigValues[13].value.int_value = -1;
/*
gConfigValues[14].type = CW_STRING;
gConfigValues[14].code = "</WTP_LOG_FILE>";
gConfigValues[14].value.str_value = NULL;
*/
return CW_TRUE;
}
CWBool CWConfigFileDestroyLib() {
int i;
int indexBlank=0;
// save the preferences we read
CW_CREATE_ARRAY_ERR(gCWACAddresses, gConfigValues[0].count, char*, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
for(i = 0; i < gConfigValues[0].count; i++) {
CW_CREATE_STRING_FROM_STRING_ERR(gCWACAddresses[i], ((gConfigValues[0].value.str_array_value)[i])+indexBlank, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
gCWACCount = gConfigValues[0].count;
#ifdef CW_DEBUGGING
CW_PRINT_STRING_ARRAY(gCWACAddresses, gCWACCount);
#endif
gCWForceMTU = gConfigValues[1].value.int_value;
if(gConfigValues[2].value.str_value != NULL && !strcmp(gConfigValues[2].value.str_value, "IPv6")) {
gNetworkPreferredFamily = CW_IPv6;
} else { // default
gNetworkPreferredFamily = CW_IPv4;
}
if(gConfigValues[3].value.str_value != NULL) {
/*
* Elena Agostini - 02/2014
*
* Ignore spaces in configuration values
*/
CW_STRING_GET_START_WHITE_SPACES((gConfigValues[3].value.str_value), indexBlank);
CW_CREATE_STRING_FROM_STRING_ERR(gWTPName, (gConfigValues[3].value.str_value)+indexBlank, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
if(gConfigValues[4].value.str_value != NULL) {
/*
* Elena Agostini - 02/2014
*
* Ignore spaces in configuration values
*/
CW_STRING_GET_START_WHITE_SPACES((gConfigValues[4].value.str_value), indexBlank);
CW_CREATE_STRING_FROM_STRING_ERR(gWTPLocation, (gConfigValues[4].value.str_value)+indexBlank, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
if(gConfigValues[5].value.str_value != NULL) {
/*
* Elena Agostini - 02/2014
*
* Ignore spaces in configuration values
*/
CW_STRING_GET_START_WHITE_SPACES((gConfigValues[5].value.str_value), indexBlank);
CW_CREATE_STRING_FROM_STRING_ERR(gWTPForceACAddress, (gConfigValues[5].value.str_value)+indexBlank, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
/*
* Elena Agostini - 02/2014
*
* Ignore spaces in configuration values
*/
if(gConfigValues[6].value.str_value != NULL)
{
CW_STRING_GET_START_WHITE_SPACES((gConfigValues[6].value.str_value), indexBlank);
if(!strcmp((gConfigValues[6].value.str_value)+indexBlank, "PRESHARED")) {
gWTPForceSecurity = CW_PRESHARED;
} else {
/* default */
gWTPForceSecurity = CW_X509_CERTIFICATE;
}
}
/*
* Elena Agostini - 02/2014
*
* Ignore spaces in configuration values
* Get OpenSSL params values
*/
gEnabledLog=gConfigValues[7].value.int_value;
gMaxLogFileSize=gConfigValues[8].value.int_value;
if(gConfigValues[9].value.str_value != NULL) {
CW_STRING_GET_START_WHITE_SPACES((gConfigValues[9].value.str_value), indexBlank);
CW_CREATE_STRING_FROM_STRING_ERR(gWTPCertificate, (gConfigValues[9].value.str_value)+indexBlank, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
if(gConfigValues[10].value.str_value != NULL) {
CW_STRING_GET_START_WHITE_SPACES((gConfigValues[10].value.str_value), indexBlank);
CW_CREATE_STRING_FROM_STRING_ERR(gWTPKeyfile, (gConfigValues[10].value.str_value)+indexBlank, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
if(gConfigValues[11].value.str_value != NULL) {
CW_STRING_GET_START_WHITE_SPACES((gConfigValues[11].value.str_value), indexBlank);
CW_CREATE_STRING_FROM_STRING_ERR(gWTPPassword, (gConfigValues[11].value.str_value)+indexBlank, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
/* Elena Agostini - 02/2014: Port number params config.wtp */
WTP_PORT_CONTROL=gConfigValues[12].value.int_value;
WTP_PORT_DATA=gConfigValues[13].value.int_value;
/* Elena Agostini - 04/2014: custom WTP log file name */
/*
if(gConfigValues[14].value.str_value != NULL) {
CW_STRING_GET_START_WHITE_SPACES((gConfigValues[14].value.str_value), indexBlank);
CW_CREATE_STRING_FROM_STRING_ERR(WTP_LOG_FILE_NAME, (gConfigValues[14].value.str_value)+indexBlank, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
*/
for(i = 0; i < gConfigValuesCount; i++) {
if(gConfigValues[i].type == CW_STRING) {
CW_FREE_OBJECT(gConfigValues[i].value.str_value);
} else if(gConfigValues[i].type == CW_STRING_ARRAY) {
CW_FREE_OBJECTS_ARRAY((gConfigValues[i].value.str_array_value), gConfigValues[i].count);
}
}
CW_FREE_OBJECT(gConfigValues);
return CW_TRUE;
}