-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWTPConfigFile.c
141 lines (108 loc) · 5.87 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
/*******************************************************************************************
* 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. *
* *
* --------------------------------------------------------------------------------------- *
* 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 = 9;
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 = "</AC_LOG_FILE_ENABLE>";
gConfigValues[7].value.int_value = 0;
gConfigValues[8].type = CW_INTEGER;
gConfigValues[8].code = "</AC_LOG_FILE_SIZE>";
gConfigValues[8].value.int_value = DEFAULT_LOG_SIZE;
return CW_TRUE;
}
CWBool CWConfigFileDestroyLib() {
int i;
// 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], 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) {
CW_CREATE_STRING_FROM_STRING_ERR(gWTPName, (gConfigValues[3].value.str_value), return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
if(gConfigValues[4].value.str_value != NULL) {
CW_CREATE_STRING_FROM_STRING_ERR(gWTPLocation, (gConfigValues[4].value.str_value), return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
if(gConfigValues[5].value.str_value != NULL) {
CW_CREATE_STRING_FROM_STRING_ERR(gWTPForceACAddress, (gConfigValues[5].value.str_value), return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
}
if(gConfigValues[6].value.str_value != NULL && !strcmp(gConfigValues[6].value.str_value, "PRESHARED")) {
gWTPForceSecurity = CW_PRESHARED;
} else { // default
gWTPForceSecurity = CW_X509_CERTIFICATE;
}
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);
}
}
gEnabledLog=gConfigValues[7].value.int_value;
gMaxLogFileSize=gConfigValues[8].value.int_value;
CW_FREE_OBJECT(gConfigValues);
return CW_TRUE;
}