-
Notifications
You must be signed in to change notification settings - Fork 84
/
ACSettingsFile.c
275 lines (229 loc) · 9.7 KB
/
ACSettingsFile.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*******************************************************************************************
* 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 "CWCommon.h"
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
#define CW_SETTINGS_FILE "settings.ac.txt"
#define CWMIN_DEFAULT 3
#define CWMAX_DEFAULT 10
#define AIFS_DEFAULT 1
FILE* gSettingsFile=NULL;
WTPQosValues* gDefaultQosValues=NULL;
int gHostapd_port;
char* gHostapd_unix_path;
void CWExtractValue(char* start, char** startValue, char** endValue, int* offset)
{
*offset=strspn (start+1, " \t\n\r");
*startValue = start +1+ *offset;
*offset=strcspn (*startValue, " \t\n\r");
*endValue = *startValue + *offset -1;
}
CWBool CWParseSettingsFile()
{
char *line = NULL;
gSettingsFile = fopen (CW_SETTINGS_FILE, "rb");
if (gSettingsFile == NULL) {
CWErrorRaiseSystemError(CW_ERROR_GENERAL);
}
CW_CREATE_ARRAY_ERR(gDefaultQosValues, NUM_QOS_PROFILES, WTPQosValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
while((line = (char*)CWGetCommand(gSettingsFile)) != NULL)
{
char* startTag=NULL;
char* endTag=NULL;
if((startTag=strchr (line, '<'))==NULL)
{
CW_FREE_OBJECT(line);
continue;
}
if((endTag=strchr (line, '>'))==NULL)
{
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "CWMIN_VOICE", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=CWMIN_DEFAULT;
gDefaultQosValues[VOICE_QUEUE_INDEX].cwMin = value;
CWDebugLog("CWMIN_VOICE: %d", gDefaultQosValues[VOICE_QUEUE_INDEX].cwMin);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "CWMAX_VOICE", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=CWMAX_DEFAULT;
gDefaultQosValues[VOICE_QUEUE_INDEX].cwMax = value;
CWDebugLog("CWMAX_VOICE: %d", gDefaultQosValues[VOICE_QUEUE_INDEX].cwMax);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "AIFS_VOICE", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=AIFS_DEFAULT;
gDefaultQosValues[VOICE_QUEUE_INDEX].AIFS = value;
CWDebugLog("AIFS_VOICE: %d", gDefaultQosValues[VOICE_QUEUE_INDEX].AIFS);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "CWMIN_VIDEO", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=CWMIN_DEFAULT;
gDefaultQosValues[VIDEO_QUEUE_INDEX].cwMin = value;
CWDebugLog("CWMIN_VIDEO: %d", gDefaultQosValues[VIDEO_QUEUE_INDEX].cwMin);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "CWMAX_VIDEO", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=CWMAX_DEFAULT;
gDefaultQosValues[VIDEO_QUEUE_INDEX].cwMax = value;
CWDebugLog("CWMAX_VIDEO: %d", gDefaultQosValues[VIDEO_QUEUE_INDEX].cwMax);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "AIFS_VIDEO", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=AIFS_DEFAULT;
gDefaultQosValues[VIDEO_QUEUE_INDEX].AIFS = value;
CWDebugLog("AIFS_VIDEO: %d", gDefaultQosValues[VIDEO_QUEUE_INDEX].AIFS);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "CWMIN_BEST_EFFORT", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=CWMIN_DEFAULT;
gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].cwMin = value;
CWDebugLog("CWMIN_BEST_EFFORT: %d", gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].cwMin);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "CWMAX_BEST_EFFORT", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=CWMAX_DEFAULT;
gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].cwMax = value;
CWDebugLog("CWMAX_BEST_EFFORT: %d", gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].cwMax);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "AIFS_BEST_EFFORT", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=AIFS_DEFAULT;
gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].AIFS = value;
CWDebugLog("AIFS_BEST_EFFORT: %d", gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].AIFS);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "CWMIN_BACKGROUND", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=CWMIN_DEFAULT;
gDefaultQosValues[BACKGROUND_QUEUE_INDEX].cwMin = value;
CWDebugLog("CWMIN_BACKGROUND: %d", gDefaultQosValues[BACKGROUND_QUEUE_INDEX].cwMin);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "CWMAX_BACKGROUND", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=CWMAX_DEFAULT;
gDefaultQosValues[BACKGROUND_QUEUE_INDEX].cwMax = value;
CWDebugLog("CWMAX_BACKGROUND: %d", gDefaultQosValues[BACKGROUND_QUEUE_INDEX].cwMax);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "AIFS_BACKGROUND", endTag-startTag-1))
{
int value = atoi(endTag+1);
if(value==0) value=AIFS_DEFAULT;
gDefaultQosValues[BACKGROUND_QUEUE_INDEX].AIFS = value;
CWDebugLog("AIFS_BACKGROUND: %d", gDefaultQosValues[BACKGROUND_QUEUE_INDEX].AIFS);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "AC_HOSTAPD_PORT", endTag-startTag-1))
{
gHostapd_port = atoi(endTag+1);
CWDebugLog("Hostapd Port connection: %d", gHostapd_port);
CW_FREE_OBJECT(line);
continue;
}
if (!strncmp(startTag+1, "AC_HOSTAPD_UNIX_PATH", endTag-startTag-1))
{
char* startValue=NULL;
char* endValue=NULL;
int offset = 0;
CWExtractValue(endTag, &startValue, &endValue, &offset);
CW_CREATE_STRING_ERR(gHostapd_unix_path, offset, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY,NULL););
strncpy(gHostapd_unix_path, startValue, offset);
gHostapd_unix_path[offset] ='\0';
CWDebugLog("Hostapd Unix Domain Path: %s",gHostapd_unix_path);
CW_FREE_OBJECT(line);
continue;
}
CW_FREE_OBJECT(line);
}
/*
* Elena Agostini - 02/2014
*
* BUG Valgrind: values not initialized
* gDefaultQosValues[*]queueDepth
* gDefaultQosValues[*]dot1PTag
* gDefaultQosValues[*]DSCPTag
*/
gDefaultQosValues[VOICE_QUEUE_INDEX].queueDepth = 0;
gDefaultQosValues[VOICE_QUEUE_INDEX].dot1PTag = 0;
gDefaultQosValues[VOICE_QUEUE_INDEX].DSCPTag = 0;
gDefaultQosValues[VIDEO_QUEUE_INDEX].queueDepth = 0;
gDefaultQosValues[VIDEO_QUEUE_INDEX].dot1PTag = 0;
gDefaultQosValues[VIDEO_QUEUE_INDEX].DSCPTag = 0;
gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].queueDepth = 0;
gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].dot1PTag = 0;
gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].DSCPTag = 0;
gDefaultQosValues[BACKGROUND_QUEUE_INDEX].queueDepth = 0;
gDefaultQosValues[BACKGROUND_QUEUE_INDEX].dot1PTag = 0;
gDefaultQosValues[BACKGROUND_QUEUE_INDEX].DSCPTag = 0;
return CW_TRUE;
}