-
Notifications
You must be signed in to change notification settings - Fork 9
/
options.c
204 lines (183 loc) · 6.58 KB
/
options.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
/*
* PROJECT: ReactOS System Regression Testing Utility
* LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
* PURPOSE: Loading the utility settings
* COPYRIGHT: Copyright 2008-2009 Christoph von Wittich <[email protected]>
* Copyright 2009 Colin Finck <[email protected]>
* Copyright 2012-2015 Pierre Schweitzer <[email protected]>
*/
#include "sysreg.h"
bool LoadSettings(const char* XmlConfig)
{
xmlDocPtr xml = NULL;
xmlXPathObjectPtr obj = NULL;
xmlXPathContextPtr ctxt = NULL;
char TempStr[255];
int Stage;
const char* StageNames[] = {
"firststage",
"secondstage",
"thirdstage"
};
xml = xmlReadFile(XmlConfig, NULL, 0);
if (!xml)
return false;
ctxt = xmlXPathNewContext(xml);
if (!ctxt)
{
xmlFreeDoc(xml);
return false;
}
obj = xmlXPathEval(BAD_CAST"string(/settings/@file)",ctxt);
if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)))
{
strncpy(AppSettings.Filename, (char *)obj->stringval, 254);
}
if (obj)
xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST"string(/settings/@vm)",ctxt);
if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)))
{
strncpy(AppSettings.Name, (char *)obj->stringval, 79);
}
if (obj)
xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST"string(/settings/general/vm/@type)",ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING))
{
if (xmlStrcasecmp(obj->stringval, BAD_CAST"vmwareplayer") == 0)
AppSettings.VMType = TYPE_VMWARE_PLAYER;
else if (xmlStrcasecmp(obj->stringval, BAD_CAST"virtualbox") == 0)
AppSettings.VMType = TYPE_VIRTUALBOX;
}
if (obj)
xmlXPathFreeObject(obj);
if (AppSettings.VMType == TYPE_VMWARE_PLAYER || AppSettings.VMType == TYPE_VIRTUALBOX)
{
obj = xmlXPathEval(BAD_CAST"string(/settings/general/vm/@serial)",ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING) && obj->stringval[0] != 0)
{
strcpy(AppSettings.Specific.VMwarePlayer.Path, (char *)obj->stringval);
}
if (obj)
xmlXPathFreeObject(obj);
}
obj = xmlXPathEval(BAD_CAST"number(/settings/general/timeout/@ms)",ctxt);
if ((obj != NULL) && (obj->type == XPATH_NUMBER))
{
/* when no value is set - return value is negative
* which means infinite */
AppSettings.Timeout = (int)obj->floatval;
}
if (obj)
xmlXPathFreeObject(obj);
/* First set current time, then add timeout value */
AppSettings.GlobalTimeout = time(0);
obj = xmlXPathEval(BAD_CAST"number(/settings/general/globaltimeout/@s)",ctxt);
if ((obj != NULL) && (obj->type == XPATH_NUMBER))
{
AppSettings.GlobalTimeout += (int)obj->floatval;
}
if (obj)
xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST"number(/settings/general/breakontimeout/@value)",ctxt);
if ((obj != NULL) && (obj->type == XPATH_NUMBER))
{
AppSettings.BreakOnTimeOut = false;
if ((unsigned int)obj->floatval == 1)
AppSettings.BreakOnTimeOut = true;
}
if (obj)
xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST"number(/settings/general/maxcachehits/@value)",ctxt);
if ((obj != NULL) && (obj->type == XPATH_NUMBER))
{
AppSettings.MaxCacheHits = (unsigned int)obj->floatval;
}
if (obj)
xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST"number(/settings/general/maxretries/@value)",ctxt);
if ((obj != NULL) && (obj->type == XPATH_NUMBER))
{
AppSettings.MaxRetries = (unsigned int)obj->floatval;
}
if (obj)
xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST"number(/settings/general/maxconts/@value)",ctxt);
if ((obj != NULL) && (obj->type == XPATH_NUMBER))
{
AppSettings.MaxConts = (unsigned int)obj->floatval;
}
if (obj)
xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST"number(/settings/general/hdd/@size)",ctxt);
if ((obj != NULL) && (obj->type == XPATH_NUMBER))
{
if (obj->floatval <= 0)
AppSettings.ImageSize = 512;
else
AppSettings.ImageSize = (int)obj->floatval;
}
if (obj)
xmlXPathFreeObject(obj);
for (Stage = 0; Stage < NUM_STAGES; Stage++)
{
strcpy(TempStr, "string(/settings/");
strcat(TempStr, StageNames[Stage]);
strcat(TempStr, "/@bootdevice)");
obj = xmlXPathEval((xmlChar*) TempStr,ctxt);
if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)))
{
strncpy(AppSettings.Stage[Stage].BootDevice, (char *)obj->stringval, 7);
}
if (obj)
xmlXPathFreeObject(obj);
strcpy(TempStr, "string(/settings/");
strcat(TempStr, StageNames[Stage]);
strcat(TempStr, "/@hookcommand)");
obj = xmlXPathEval((xmlChar*) TempStr,ctxt);
if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)))
{
strncpy(AppSettings.Stage[Stage].HookCommand, (char *)obj->stringval, 254);
}
if (obj)
xmlXPathFreeObject(obj);
strcpy(TempStr, "string(/settings/");
strcat(TempStr, StageNames[Stage]);
strcat(TempStr, "/success/@on)");
obj = xmlXPathEval((xmlChar*) TempStr,ctxt);
if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)))
{
strncpy(AppSettings.Stage[Stage].Checkpoint, (char *)obj->stringval, 79);
}
if (obj)
xmlXPathFreeObject(obj);
}
xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
xml = xmlReadFile(AppSettings.Filename, NULL, 0);
if (!xml)
return false;
ctxt = xmlXPathNewContext(xml);
if (!ctxt)
{
xmlFreeDoc(xml);
return false;
}
obj = xmlXPathEval(BAD_CAST"string(/domain/devices/disk[@device='disk']/source/@file)",ctxt);
if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)))
{
strncpy(AppSettings.HardDiskImage, (char *)obj->stringval, 254);
}
if (obj)
xmlXPathFreeObject(obj);
xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
return true;
}