LibreOffice Module vcl (master)  1
driverblocklist.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #ifndef INCLUDED_VCL_DRIVERBLOCKLIST_HXX
11 #define INCLUDED_VCL_DRIVERBLOCKLIST_HXX
12 
13 #include <vcl/dllapi.h>
14 #include <xmlreader/xmlreader.hxx>
15 #include <vector>
16 
17 namespace DriverBlocklist
18 {
19 VCL_DLLPUBLIC bool IsDeviceBlocked(const OUString& blocklistURL, const OUString& driverVersion,
20  const OUString& vendorId, const OUString& deviceId);
21 
22 #ifdef _WIN32
23 VCL_DLLPUBLIC int32_t GetWindowsVersion();
24 #endif
25 
27 {
33 };
35 
38 
39 VCL_DLLPUBLIC OUStringLiteral GetVendorNameFromId(uint32_t id);
40 
41 // The rest should be private (only for the unittest).
42 
44 {
45 };
46 
48 {
61 };
62 
64 {
65  DRIVER_LESS_THAN, // driver < version
66  DRIVER_LESS_THAN_OR_EQUAL, // driver <= version
67  DRIVER_GREATER_THAN, // driver > version
68  DRIVER_GREATER_THAN_OR_EQUAL, // driver >= version
69  DRIVER_EQUAL, // driver == version
70  DRIVER_NOT_EQUAL, // driver != version
71  DRIVER_BETWEEN_EXCLUSIVE, // driver > version && driver < versionMax
72  DRIVER_BETWEEN_INCLUSIVE, // driver >= version && driver <= versionMax
73  DRIVER_BETWEEN_INCLUSIVE_START, // driver >= version && driver < versionMax
75 };
76 
77 struct DriverInfo
78 {
79  DriverInfo(OperatingSystem os, const OUString& vendor, VersionComparisonOp op,
80  uint64_t driverVersion, bool bWhiteListed = false,
81  const char* suggestedVersion = nullptr);
82 
83  DriverInfo();
84 
86  OUString maAdapterVendor;
87  std::vector<OUString> maDevices;
88 
90 
92 
93  /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
94  uint64_t mnDriverVersion;
96  static uint64_t allDriverVersions;
97 
99  OUString maMsg;
100 };
101 
103 {
104 public:
105  Parser(const OUString& rURL, std::vector<DriverInfo>& rDriverList);
106  bool parse();
107 
108 private:
109  void handleEntry(DriverInfo& rDriver, xmlreader::XmlReader& rReader);
110  void handleList(xmlreader::XmlReader& rReader);
111  void handleContent(xmlreader::XmlReader& rReader);
112  static void handleDevices(DriverInfo& rDriver, xmlreader::XmlReader& rReader);
113 
114  enum class BlockType
115  {
116  WHITELIST,
117  BLACKLIST,
118  UNKNOWN
119  };
120 
122  std::vector<DriverInfo>& mrDriverList;
123  OUString maURL;
124 };
125 
127 
128 bool VCL_DLLPUBLIC FindBlocklistedDeviceInList(std::vector<DriverInfo>& aDeviceInfos,
129  OUString const& sDriverVersion,
130  OUString const& sAdapterVendorID,
131  OUString const& sAdapterDeviceID,
132  OperatingSystem system,
133  const OUString& blocklistURL = OUString());
134 
135 #define GFX_DRIVER_VERSION(a, b, c, d) \
136  ((uint64_t(a) << 48) | (uint64_t(b) << 32) | (uint64_t(c) << 16) | uint64_t(d))
137 
138 inline uint64_t V(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
139 {
140  // We make sure every driver number is padded by 0s, this will allow us the
141  // easiest 'compare as if decimals' approach. See ParseDriverVersion for a
142  // more extensive explanation of this approach.
143  while (b > 0 && b < 1000)
144  {
145  b *= 10;
146  }
147  while (c > 0 && c < 1000)
148  {
149  c *= 10;
150  }
151  while (d > 0 && d < 1000)
152  {
153  d *= 10;
154  }
155  return GFX_DRIVER_VERSION(a, b, c, d);
156 }
157 
158 } // namespace
159 
160 #endif
161 
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VersionComparisonOp meComparisonOp
std::vector< OUString > maDevices
uint64_t V(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
static OUString GetVendorId(const OString &rString)
uint32_t vendorId
DeviceVendor GetVendorFromId(uint32_t id)
Returns vendor for the given vendor ID, or VendorAll if not known.
OUStringLiteral GetVendorNameFromId(uint32_t id)
#define GFX_DRIVER_VERSION(a, b, c, d)
UNKNOWN
bool IsDeviceBlocked(const OUString &blocklistURL, const OUString &driverVersion, const OUString &vendorId, const OUString &deviceId)
const int DeviceVendorMax
bool FindBlocklistedDeviceInList(std::vector< DriverInfo > &aDeviceInfos, OUString const &sDriverVersion, OUString const &sAdapterVendorID, OUString const &sAdapterDeviceID, OperatingSystem system, const OUString &blocklistURL)
std::vector< DriverInfo > & mrDriverList
bool parse(OUString const &uri, SourceProviderScannerData *data)