ReactOS  0.4.14-dev-358-gbef841c
xml2sdb.cpp File Reference
#include "xml2sdb.h"
#include "sdbpapi.h"
#include "tinyxml2.h"
#include <time.h>
#include <algorithm>
Include dependency graph for xml2sdb.cpp:

Go to the source code of this file.

Macros

#define C_ASSERT(expr)   extern char (*c_assert(void)) [(expr) ? 1 : -1]
 
#define REG_SZ   1
 
#define REG_DWORD   4
 
#define REG_QWORD   11
 

Functions

 C_ASSERT (sizeof(GUID)==16)
 
 C_ASSERT (sizeof(ULONG)==4)
 
 C_ASSERT (sizeof(LARGE_INTEGER)==8)
 
 C_ASSERT (sizeof(WCHAR)==2)
 
 C_ASSERT (sizeof(wchar_t)==2)
 
 C_ASSERT (sizeof(TAG)==2)
 
 C_ASSERT (sizeof(TAGID)==4)
 
VOID NTAPI RtlSecondsSince1970ToTime (IN ULONG SecondsSince1970, OUT PLARGE_INTEGER Time)
 
bool IsEmptyGuid (const GUID &g)
 
void RandomGuid (GUID &g)
 
std::string ToString (XMLHandle node)
 
std::string ToNodeName (XMLHandle node)
 
std::string ReadStringNode (XMLHandle dbNode, const char *nodeName)
 
DWORD ReadQWordNode (XMLHandle dbNode, const char *nodeName)
 
DWORD ReadDWordNode (XMLHandle dbNode, const char *nodeName)
 
unsigned char char2byte (char hexChar, bool *success=NULL)
 
static bool StringToGuid (const std::string &str, GUID &guid)
 
bool ReadGuidNode (XMLHandle dbNode, const char *nodeName, GUID &guid)
 
bool ReadBinaryNode (XMLHandle dbNode, const char *nodeName, std::vector< BYTE > &data)
 
template<typename T >
void ReadGeneric (XMLHandle dbNode, std::list< T > &result, const char *nodeName)
 
template<typename T >
bool WriteGeneric (PDB pdb, std::list< T > &data, Database &db)
 
static void InsertTagid (const sdbstring &name, TAGID tagid, std::map< sdbstring, TAGID > &lookup, const char *type)
 
static TAGID FindTagid (const sdbstring &name, const std::map< sdbstring, TAGID > &lookup)
 
bool xml_2_db (const char *xml, const WCHAR *sdb)
 

Variables

static const GUID GUID_NULL = { 0 }
 
static const char szCompilerVersion [] = "1.7.0.1"
 

Macro Definition Documentation

◆ C_ASSERT

#define C_ASSERT (   expr)    extern char (*c_assert(void)) [(expr) ? 1 : -1]

Definition at line 20 of file xml2sdb.cpp.

◆ REG_DWORD

#define REG_DWORD   4

Definition at line 408 of file xml2sdb.cpp.

◆ REG_QWORD

#define REG_QWORD   11

Definition at line 409 of file xml2sdb.cpp.

◆ REG_SZ

#define REG_SZ   1

Definition at line 406 of file xml2sdb.cpp.

Function Documentation

◆ C_ASSERT() [1/7]

C_ASSERT ( sizeof(GUID = =16)

◆ C_ASSERT() [2/7]

C_ASSERT ( sizeof(ULONG = =4)

◆ C_ASSERT() [3/7]

C_ASSERT ( sizeof(LARGE_INTEGER = =8)

◆ C_ASSERT() [4/7]

C_ASSERT ( sizeof(WCHAR = =2)

◆ C_ASSERT() [5/7]

C_ASSERT ( sizeof(wchar_t = =2)

◆ C_ASSERT() [6/7]

C_ASSERT ( sizeof(TAG = =2)

◆ C_ASSERT() [7/7]

C_ASSERT ( sizeof(TAGID = =4)

◆ char2byte()

unsigned char char2byte ( char  hexChar,
bool success = NULL 
)

Definition at line 108 of file xml2sdb.cpp.

109 {
110  if (hexChar >= '0' && hexChar <= '9')
111  return hexChar - '0';
112  if (hexChar >= 'A' && hexChar <= 'F')
113  return hexChar - 'A' + 10;
114  if (hexChar >= 'a' && hexChar <= 'f')
115  return hexChar - 'a' + 10;
116 
117  if (success)
118  *success = false;
119  return 0;
120 }
#define success(from, fromstr, to, tostr)
const char hexChar[]

Referenced by ReadBinaryNode(), and StringToGuid().

◆ FindTagid()

static TAGID FindTagid ( const sdbstring name,
const std::map< sdbstring, TAGID > &  lookup 
)
static

Definition at line 724 of file xml2sdb.cpp.

725 {
726  sdbstring nameLower = name;
727  std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
728  std::map<sdbstring, TAGID>::const_iterator it = lookup.find(nameLower);
729  if (it == lookup.end())
730  return 0;
731  return it->second;
732 }
std::basic_string< WCHAR > sdbstring
Definition: xml2sdb.h:27
static ULONG lookup[16]
Definition: vga.c:46
GLuint GLenum GLenum transform
Definition: glext.h:9407
int tolower(int c)
Definition: utclib.c:902
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by Database::FindFlagTagid(), Database::FindPatchTagid(), and Database::FindShimTagid().

◆ InsertTagid()

static void InsertTagid ( const sdbstring name,
TAGID  tagid,
std::map< sdbstring, TAGID > &  lookup,
const char type 
)
static

Definition at line 711 of file xml2sdb.cpp.

712 {
713  sdbstring nameLower = name;
714  std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
715  if (lookup.find(nameLower) != lookup.end())
716  {
717  std::string nameA(name.begin(), name.end());
718  SHIM_WARN("%s '%s' redefined\n", type, nameA.c_str());
719  return;
720  }
721  lookup[nameLower] = tagid;
722 }
std::basic_string< WCHAR > sdbstring
Definition: xml2sdb.h:27
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static ULONG lookup[16]
Definition: vga.c:46
char string[160]
Definition: util.h:11
Definition: name.c:36
GLuint GLenum GLenum transform
Definition: glext.h:9407
int tolower(int c)
Definition: utclib.c:902
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by Database::InsertFlagTagid(), Database::InsertPatchTagid(), and Database::InsertShimTagid().

◆ IsEmptyGuid()

bool IsEmptyGuid ( const GUID g)

Definition at line 46 of file xml2sdb.cpp.

47 {
48  return !memcmp(&g, &GUID_NULL, sizeof(GUID));
49 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLboolean GLboolean g
Definition: glext.h:6204
static const GUID GUID_NULL
Definition: xml2sdb.cpp:16

Referenced by Shim::toSdb(), Exe::toSdb(), Database::toSdb(), and Database::WriteBinary().

◆ RandomGuid()

void RandomGuid ( GUID g)

Definition at line 51 of file xml2sdb.cpp.

52 {
53  BYTE* p = (BYTE*)&g;
54  for (size_t n = 0; n < sizeof(GUID); ++n)
55  p[n] = (BYTE)(rand() % 0xff);
56 }
GLdouble n
Definition: glext.h:7729
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
GLboolean GLboolean g
Definition: glext.h:6204
unsigned char BYTE
Definition: mem.h:68
struct _GUID GUID
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by Shim::toSdb(), Exe::toSdb(), and Database::toSdb().

◆ ReadBinaryNode()

bool ReadBinaryNode ( XMLHandle  dbNode,
const char nodeName,
std::vector< BYTE > &  data 
)

Definition at line 222 of file xml2sdb.cpp.

223 {
224  std::string value = ReadStringNode(dbNode, nodeName);
225  value.erase(std::remove_if(value.begin(), value.end(), ::isspace), value.end());
226 
227  size_t length = value.size() / 2;
228  if (length * 2 != value.size())
229  return false;
230 
231  data.resize(length);
232  for (size_t n = 0; n < length; ++n)
233  {
234  data[n] = (BYTE)(char2byte(value[n * 2]) << 4 | char2byte(value[(n * 2) + 1]));
235  }
236  return true;
237 }
#define isspace(c)
Definition: acclib.h:69
GLdouble n
Definition: glext.h:7729
std::string ReadStringNode(XMLHandle dbNode, const char *nodeName)
Definition: xml2sdb.cpp:79
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
_STLP_INLINE_LOOP _ForwardIter remove_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred)
Definition: _algo.h:278
unsigned char BYTE
Definition: mem.h:68
char string[160]
Definition: util.h:11
unsigned char char2byte(char hexChar, bool *success=NULL)
Definition: xml2sdb.cpp:108

◆ ReadDWordNode()

DWORD ReadDWordNode ( XMLHandle  dbNode,
const char nodeName 
)

Definition at line 103 of file xml2sdb.cpp.

104 {
105  return static_cast<DWORD>(ReadQWordNode(dbNode, nodeName));
106 }
DWORD ReadQWordNode(XMLHandle dbNode, const char *nodeName)
Definition: xml2sdb.cpp:91

Referenced by Data::fromXml(), and MatchingFile::fromXml().

◆ ReadGeneric()

template<typename T >
void ReadGeneric ( XMLHandle  dbNode,
std::list< T > &  result,
const char nodeName 
)

Definition at line 267 of file xml2sdb.cpp.

268 {
269  XMLHandle node = dbNode.FirstChildElement(nodeName);
270  while (node.ToNode())
271  {
272  T object;
273  if (object.fromXml(node))
274  result.push_back(object);
275 
276  node = node.NextSiblingElement(nodeName);
277  }
278 }
#define T
Definition: mbstring.h:31
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition: tinyxml2.h:1814
GLuint64EXT * result
Definition: glext.h:11304
void * object
Definition: jmemsys.h:48
Definition: dlist.c:348

Referenced by ShimRef::fromXml(), Shim::fromXml(), Layer::fromXml(), Exe::fromXml(), and Database::fromXml().

◆ ReadGuidNode()

bool ReadGuidNode ( XMLHandle  dbNode,
const char nodeName,
GUID guid 
)

Definition at line 211 of file xml2sdb.cpp.

212 {
213  std::string value = ReadStringNode(dbNode, nodeName);
214  if (!StringToGuid(value, guid))
215  {
216  memset(&guid, 0, sizeof(GUID));
217  return false;
218  }
219  return true;
220 }
std::string ReadStringNode(XMLHandle dbNode, const char *nodeName)
Definition: xml2sdb.cpp:79
const GUID * guid
static bool StringToGuid(const std::string &str, GUID &guid)
Definition: xml2sdb.cpp:123
char string[160]
Definition: util.h:11
#define memset(x, y, z)
Definition: compat.h:39

Referenced by Shim::fromXml(), Exe::fromXml(), and Database::fromXml().

◆ ReadQWordNode()

DWORD ReadQWordNode ( XMLHandle  dbNode,
const char nodeName 
)

Definition at line 91 of file xml2sdb.cpp.

92 {
93  std::string value = ReadStringNode(dbNode, nodeName);
94  int base = 10;
95  if (value.size() > 2 && value[0] == '0' && value[1] == 'x')
96  {
97  base = 16;
98  value = value.substr(2);
99  }
100  return static_cast<QWORD>(strtoul(value.c_str(), NULL, base));
101 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
std::string ReadStringNode(XMLHandle dbNode, const char *nodeName)
Definition: xml2sdb.cpp:79
GLuint base
Definition: 3dtext.c:35
smooth NULL
Definition: ftsmooth.c:416
char string[160]
Definition: util.h:11

Referenced by Flag::fromXml(), Data::fromXml(), and ReadDWordNode().

◆ ReadStringNode()

std::string ReadStringNode ( XMLHandle  dbNode,
const char nodeName 
)

Definition at line 79 of file xml2sdb.cpp.

80 {
82  if (elem)
83  {
84  const char* rawVal = elem->Attribute(nodeName);
85  if (rawVal)
86  return std::string(rawVal);
87  }
88  return ToString(dbNode.FirstChildElement(nodeName));
89 }
static size_t elem
Definition: string.c:68
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition: tinyxml2.h:1814
char string[160]
Definition: util.h:11
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition: tinyxml2.h:1847
std::string ToString(XMLHandle node)
Definition: xml2sdb.cpp:59

Referenced by InExclude::fromXml(), ShimRef::fromXml(), FlagRef::fromXml(), Shim::fromXml(), Flag::fromXml(), Data::fromXml(), Layer::fromXml(), MatchingFile::fromXml(), Exe::fromXml(), Database::fromXml(), ReadBinaryNode(), ReadGuidNode(), and ReadQWordNode().

◆ RtlSecondsSince1970ToTime()

VOID NTAPI RtlSecondsSince1970ToTime ( IN ULONG  SecondsSince1970,
OUT PLARGE_INTEGER  Time 
)

Definition at line 406 of file time.c.

408 {
409  Time->QuadPart = ((LONGLONG)SecondsSince1970 * TICKSPERSEC) + TICKSTO1970;
410 }
#define TICKSTO1970
Definition: time.c:35
int64_t LONGLONG
Definition: typedefs.h:66
#define TICKSPERSEC
Definition: time.c:17
static PLARGE_INTEGER Time
Definition: time.c:105
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by Database::toSdb().

◆ StringToGuid()

static bool StringToGuid ( const std::string str,
GUID guid 
)
static

Definition at line 123 of file xml2sdb.cpp.

124 {
125  const char *lpszGUID = str.c_str();
126  BYTE* lpOut = (BYTE*)&guid;
127  int i = 0;
128  bool expectBrace = true;
129  while (i <= 37)
130  {
131  switch (i)
132  {
133  case 0:
134  if (*lpszGUID != '{')
135  {
136  i++;
137  expectBrace = false;
138  continue;
139  }
140  break;
141 
142  case 9:
143  case 14:
144  case 19:
145  case 24:
146  if (*lpszGUID != '-')
147  return false;
148  break;
149 
150  case 37:
151  return expectBrace == (*lpszGUID == '}');
152 
153  default:
154  {
155  CHAR ch = *lpszGUID, ch2 = lpszGUID[1];
156  unsigned char byte;
157  bool converted = true;
158 
159  byte = char2byte(ch, &converted) << 4 | char2byte(ch2, &converted);
160  if (!converted)
161  return false;
162 
163  switch (i)
164  {
165 #ifndef WORDS_BIGENDIAN
166  /* For Big Endian machines, we store the data such that the
167  * dword/word members can be read as DWORDS and WORDS correctly. */
168  /* Dword */
169  case 1:
170  lpOut[3] = byte;
171  break;
172  case 3:
173  lpOut[2] = byte;
174  break;
175  case 5:
176  lpOut[1] = byte;
177  break;
178  case 7:
179  lpOut[0] = byte;
180  lpOut += 4;
181  break;
182  /* Word */
183  case 10:
184  case 15:
185  lpOut[1] = byte;
186  break;
187  case 12:
188  case 17:
189  lpOut[0] = byte;
190  lpOut += 2;
191  break;
192 #endif
193  /* Byte */
194  default:
195  lpOut[0] = byte;
196  lpOut++;
197  break;
198  }
199 
200  lpszGUID++; /* Skip 2nd character of byte */
201  i++;
202  }
203  }
204 
205  lpszGUID++;
206  i++;
207  }
208  return false;
209 }
char CHAR
Definition: xmlstorage.h:175
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const GUID * guid
const WCHAR * str
unsigned char BYTE
Definition: mem.h:68
#define byte(x, n)
Definition: tomcrypt.h:118
unsigned char char2byte(char hexChar, bool *success=NULL)
Definition: xml2sdb.cpp:108

Referenced by ReadGuidNode().

◆ ToNodeName()

std::string ToNodeName ( XMLHandle  node)

Definition at line 69 of file xml2sdb.cpp.

70 {
71  tinyxml2::XMLNode* raw = node.ToNode();
72  const char* txt = raw ? raw->Value() : NULL;
73  if (txt)
74  return std::string(txt);
75  return std::string();
76 }
smooth NULL
Definition: ftsmooth.c:416
char string[160]
Definition: util.h:11
const char * Value() const
Definition: tinyxml2.cpp:719
Definition: dlist.c:348

Referenced by InExclude::fromXml(), and Database::fromXml().

◆ ToString()

std::string ToString ( XMLHandle  node)

Definition at line 59 of file xml2sdb.cpp.

60 {
61  XMLText* txtNode = node.FirstChild().ToText();
62  const char* txt = txtNode ? txtNode->Value() : NULL;
63  if (txt)
64  return std::string(txt);
65  return std::string();
66 }
smooth NULL
Definition: ftsmooth.c:416
char string[160]
Definition: util.h:11
const char * Value() const
Definition: tinyxml2.cpp:719
Definition: dlist.c:348

Referenced by DECLARE_INTERFACE_(), PcRegisterPhysicalConnectionToExternal(), ReadStringNode(), and RegisterConnection().

◆ WriteGeneric()

template<typename T >
bool WriteGeneric ( PDB  pdb,
std::list< T > &  data,
Database db 
)

Definition at line 281 of file xml2sdb.cpp.

282 {
283  for (typename std::list<T>::iterator it = data.begin(); it != data.end(); ++it)
284  {
285  if (!it->toSdb(pdb, db))
286  return false;
287  }
288  return true;
289 }
static PDB pdb
Definition: db.cpp:170
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

Referenced by Shim::toSdb(), Layer::toSdb(), Exe::toSdb(), and Database::toSdb().

◆ xml_2_db()

bool xml_2_db ( const char xml,
const WCHAR sdb 
)

Definition at line 765 of file xml2sdb.cpp.

766 {
767  Database db;
768  if (db.fromXml(xml))
769  {
770  return db.toSdb((LPCWSTR)sdb);
771  }
772  return false;
773 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
bool fromXml(const char *fileName)
Definition: xml2sdb.cpp:669
bool toSdb(LPCWSTR path)
Definition: xml2sdb.cpp:677

Referenced by run_one().

Variable Documentation

◆ GUID_NULL

const GUID GUID_NULL = { 0 }
static

Definition at line 16 of file xml2sdb.cpp.

Referenced by IsEmptyGuid().

◆ szCompilerVersion

const char szCompilerVersion[] = "1.7.0.1"
static

Definition at line 17 of file xml2sdb.cpp.

Referenced by Database::toSdb().