-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWTPSettingsFile.c
96 lines (78 loc) · 3.74 KB
/
WTPSettingsFile.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
/*******************************************************************************************
* 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 "CWCommon.h"
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
#define CW_SETTINGS_FILE "settings.wtp.txt"
FILE* gSettingsFile=NULL;
char* gInterfaceName=NULL;
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);
}
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, "IF_NAME", endTag-startTag-1))
{
char* startValue=NULL;
char* endValue=NULL;
int offset = 0;
CWExtractValue(endTag, &startValue, &endValue, &offset);
CW_CREATE_STRING_ERR(gInterfaceName, offset+1, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY,NULL););
strncpy(gInterfaceName, startValue, offset);
gInterfaceName[offset] ='\0';
CWLog(": %s", gInterfaceName);
CW_FREE_OBJECT(line);
continue;
}
CW_FREE_OBJECT(line);
}
return CW_TRUE;
}