Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / vcl / opengl / win / blocklist_parser.cxx
blob8a6f9dbc4cdadfbff4e31262c2d893bb43f47386
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <opengl/win/blocklist_parser.hxx>
12 WinBlocklistParser::WinBlocklistParser(const OUString& rURL,
13 std::vector<wgl::DriverInfo>& rDriverList)
14 : meBlockType(BlockType::UNKNOWN)
15 , mrDriverList(rDriverList)
16 , maURL(rURL)
20 void WinBlocklistParser::parse()
22 xmlreader::XmlReader aReader(maURL);
23 handleContent(aReader);
26 namespace {
28 wgl::OperatingSystem getOperatingSystem(const OString& rString)
30 if (rString == "all")
32 return wgl::DRIVER_OS_ALL;
34 else if (rString == "xp")
36 return wgl::DRIVER_OS_WINDOWS_XP;
38 else if (rString == "server2003")
40 return wgl::DRIVER_OS_WINDOWS_SERVER_2003;
42 else if (rString == "vista")
44 return wgl::DRIVER_OS_WINDOWS_VISTA;
46 else if (rString == "7")
48 return wgl::DRIVER_OS_WINDOWS_7;
50 else if (rString == "8")
52 return wgl::DRIVER_OS_WINDOWS_8;
54 else if (rString == "8_1")
56 return wgl::DRIVER_OS_WINDOWS_8_1;
58 else if (rString == "10")
60 return wgl::DRIVER_OS_WINDOWS_10;
63 return wgl::DRIVER_OS_UNKNOWN;
66 wgl::VersionComparisonOp getComparison(const OString& rString)
68 if (rString == "less")
70 return wgl::DRIVER_LESS_THAN;
72 else if (rString == "less_equal")
74 return wgl::DRIVER_LESS_THAN_OR_EQUAL;
76 else if (rString == "greater")
78 return wgl::DRIVER_GREATER_THAN;
80 else if (rString == "greater_equal")
82 return wgl::DRIVER_GREATER_THAN_OR_EQUAL;
84 else if (rString == "equal")
86 return wgl::DRIVER_EQUAL;
88 else if (rString == "not_equal")
90 return wgl::DRIVER_NOT_EQUAL;
92 else if (rString == "between_exclusive")
94 return wgl::DRIVER_BETWEEN_EXCLUSIVE;
96 else if (rString == "between_inclusive")
98 return wgl::DRIVER_BETWEEN_INCLUSIVE;
100 else if (rString == "between_inclusive_start")
102 return wgl::DRIVER_BETWEEN_INCLUSIVE_START;
105 throw InvalidFileException();
108 OUString getVendor(const OString& rString)
110 if (rString == "all")
112 return "";
114 else if (rString == "intel")
116 return "0x8086";
118 else if (rString == "nvidia")
120 return "0x10de";
122 else if (rString == "amd")
124 return "0x1022";
126 else if (rString == "ati")
128 return "0x1002";
130 else if (rString == "microsoft")
132 return "0x1414";
134 else
136 // Allow having simply the hex number as such there, too. After all, it's hex numbers that
137 // are output to opengl_device.log.
138 return OStringToOUString(rString, RTL_TEXTENCODING_UTF8);
142 uint64_t getVersion(const OString& rString)
144 OUString aString = OStringToOUString(rString, RTL_TEXTENCODING_UTF8);
145 uint64_t nVersion;
146 bool bResult = wgl::ParseDriverVersion(aString, nVersion);
148 if (!bResult)
150 throw InvalidFileException();
153 return nVersion;
156 void handleDevices(wgl::DriverInfo& rDriver, xmlreader::XmlReader& rReader)
158 int nLevel = 1;
159 bool bInMsg = false;
161 while(true)
163 xmlreader::Span name;
164 int nsId;
166 xmlreader::XmlReader::Result res = rReader.nextItem(
167 xmlreader::XmlReader::Text::Normalized, &name, &nsId);
169 if (res == xmlreader::XmlReader::Result::Begin)
171 ++nLevel;
172 if (nLevel > 2)
173 throw InvalidFileException();
175 if (name.equals("msg"))
177 bInMsg = true;
179 else if (name.equals("device"))
181 int nsIdDeveice;
182 while (rReader.nextAttribute(&nsIdDeveice, &name))
184 if (name.equals("id"))
186 name = rReader.getAttributeValue(false);
187 OString aDeviceId(name.begin, name.length);
188 rDriver.maDevices.push_back(OStringToOUString(aDeviceId, RTL_TEXTENCODING_UTF8));
192 else
193 throw InvalidFileException();
195 else if (res == xmlreader::XmlReader::Result::End)
197 --nLevel;
198 bInMsg = false;
199 if (!nLevel)
200 break;
202 else if (res == xmlreader::XmlReader::Result::Text)
204 if (bInMsg)
206 OString sMsg(name.begin, name.length);
207 rDriver.maMsg = OStringToOUString(sMsg, RTL_TEXTENCODING_UTF8);
215 void WinBlocklistParser::handleEntry(wgl::DriverInfo& rDriver, xmlreader::XmlReader& rReader)
217 if (meBlockType == BlockType::WHITELIST)
219 rDriver.mbWhitelisted = true;
221 else if (meBlockType == BlockType::BLACKLIST)
223 rDriver.mbWhitelisted = false;
225 else if (meBlockType == BlockType::UNKNOWN)
227 throw InvalidFileException();
230 xmlreader::Span name;
231 int nsId;
233 while (rReader.nextAttribute(&nsId, &name))
235 if (name.equals("os"))
237 name = rReader.getAttributeValue(false);
238 OString sOS(name.begin, name.length);
239 rDriver.meOperatingSystem = getOperatingSystem(sOS);
241 else if (name.equals("vendor"))
243 name = rReader.getAttributeValue(false);
244 OString sVendor(name.begin, name.length);
245 rDriver.maAdapterVendor = getVendor(sVendor);
247 else if (name.equals("compare"))
249 name = rReader.getAttributeValue(false);
250 OString sCompare(name.begin, name.length);
251 rDriver.meComparisonOp = getComparison(sCompare);
253 else if (name.equals("version"))
255 name = rReader.getAttributeValue(false);
256 OString sVersion(name.begin, name.length);
257 rDriver.mnDriverVersion = getVersion(sVersion);
259 else if (name.equals("minVersion"))
261 name = rReader.getAttributeValue(false);
262 OString sMinVersion(name.begin, name.length);
263 rDriver.mnDriverVersion = getVersion(sMinVersion);
265 else if (name.equals("maxVersion"))
267 name = rReader.getAttributeValue(false);
268 OString sMaxVersion(name.begin, name.length);
269 rDriver.mnDriverVersionMax = getVersion(sMaxVersion);
271 else
273 OString aAttrName(name.begin, name.length);
274 SAL_WARN("vcl.opengl", "unsupported attribute: " << aAttrName);
278 handleDevices(rDriver, rReader);
281 void WinBlocklistParser::handleList(xmlreader::XmlReader& rReader)
283 xmlreader::Span name;
284 int nsId;
286 while (true)
288 xmlreader::XmlReader::Result res = rReader.nextItem(
289 xmlreader::XmlReader::Text::NONE, &name, &nsId);
291 if (res == xmlreader::XmlReader::Result::Begin)
293 if (name.equals("entry"))
295 wgl::DriverInfo aDriver;
296 handleEntry(aDriver, rReader);
297 mrDriverList.push_back(aDriver);
299 else if (name.equals("entryRange"))
301 wgl::DriverInfo aDriver;
302 handleEntry(aDriver, rReader);
303 mrDriverList.push_back(aDriver);
305 else
307 throw InvalidFileException();
310 else if (res == xmlreader::XmlReader::Result::End)
312 break;
317 void WinBlocklistParser::handleContent(xmlreader::XmlReader& rReader)
319 while (true)
321 xmlreader::Span name;
322 int nsId;
324 xmlreader::XmlReader::Result res = rReader.nextItem(
325 xmlreader::XmlReader::Text::NONE, &name, &nsId);
327 if (res == xmlreader::XmlReader::Result::Begin)
329 if (name.equals("whitelist"))
331 meBlockType = BlockType::WHITELIST;
332 handleList(rReader);
334 else if (name.equals("blacklist"))
336 meBlockType = BlockType::BLACKLIST;
337 handleList(rReader);
339 else if (name.equals("root"))
342 else
344 throw InvalidFileException();
347 else if (res == xmlreader::XmlReader::Result::End)
349 if (name.equals("whitelist")
351 name.equals("blacklist"))
353 meBlockType = BlockType::UNKNOWN;
356 else if (res == xmlreader::XmlReader::Result::Done)
358 break;
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */