Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000
  6. //
  7. // File: auxml.cpp
  8. //
  9. // About: source file for AU related XML and schema data structure and functions
  10. //--------------------------------------------------------------------------
  11. #include "pch.h"
  12. #if 0
  13. HRESULT MYLoadXMLDoc(BSTR bstrXml, IXMLDOMDocument** ppDoc) //always offline
  14. {
  15. HRESULT hr;
  16. VARIANT_BOOL fSuccess ;
  17. // DEBUGMSG("MYLoadXMLDoc starts");
  18. hr = CoCreateInstance(__uuidof(DOMDocument),
  19. NULL,
  20. CLSCTX_INPROC_SERVER,
  21. __uuidof( IXMLDOMDocument),
  22. (void **) ppDoc);
  23. if (FAILED(hr))
  24. {
  25. DEBUGMSG("Warning: Fail to create DOM document with error %#lx", hr);
  26. goto done;
  27. }
  28. if (FAILED(hr = (*ppDoc)->put_validateOnParse(VARIANT_FALSE)) ||
  29. FAILED(hr = (*ppDoc)->put_resolveExternals(VARIANT_FALSE)) ||
  30. FAILED(hr = (*ppDoc)->put_async(VARIANT_FALSE)))
  31. {
  32. DEBUGMSG("Warning: Fail to set document properties with error %#lx", hr);
  33. SafeRelease(*ppDoc);
  34. goto done;
  35. }
  36. //
  37. // load the XML Doc from input string
  38. //
  39. if (S_OK != (hr = (*ppDoc)->loadXML(bstrXml, &fSuccess)))
  40. {
  41. DEBUGMSG("Warning: Fail to load document with error %#lx", hr);
  42. SafeRelease(*ppDoc);
  43. }
  44. if (S_FALSE == hr)
  45. {
  46. hr = E_FAIL;
  47. }
  48. done:
  49. // DEBUGMSG("MYLoadXMLDoc ends");
  50. return hr;
  51. }
  52. #endif
  53. #ifdef DBG
  54. void LOGFILE(LPTSTR szFileName, BSTR bstrMessage)
  55. {
  56. // USES_CONVERSION;
  57. TCHAR szLogFile[MAX_PATH] ;
  58. AUASSERT(_T('\0') != g_szWUDir[0]);
  59. if (FAILED(StringCchCopyEx(szLogFile, ARRAYSIZE(szLogFile), g_szWUDir, NULL, NULL, MISTSAFE_STRING_FLAGS)) ||
  60. FAILED(StringCchCatEx(szLogFile, ARRAYSIZE(szLogFile), szFileName, NULL, NULL, MISTSAFE_STRING_FLAGS)))
  61. {
  62. DEBUGMSG("file name and path too long");
  63. return;
  64. }
  65. HANDLE hFile = CreateFile(szLogFile, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, NULL, NULL);
  66. if (INVALID_HANDLE_VALUE == hFile)
  67. {
  68. DEBUGMSG("Fail to create file %S", T2W(szLogFile));
  69. return;
  70. }
  71. DWORD dwBytesWritten;
  72. BYTE bMagic1 = 0xff;
  73. BYTE bMagic2 = 0xfe;
  74. if (!WriteFile(hFile, &bMagic1, sizeof(bMagic1), &dwBytesWritten, NULL) ||
  75. !WriteFile(hFile, &bMagic2, sizeof(bMagic2), &dwBytesWritten, NULL) ||
  76. !WriteFile(hFile, bstrMessage, SysStringByteLen(bstrMessage), &dwBytesWritten, NULL))
  77. {
  78. DEBUGMSG("Fail to write to file %S with error %d", T2W(szLogFile), GetLastError());
  79. }
  80. CloseHandle(hFile);
  81. return;
  82. }
  83. #endif
  84. HRESULT LOGXMLFILE(LPCTSTR szFileName, BSTR bstrMessage)
  85. {
  86. IXMLDOMDocument *pxml;
  87. HRESULT hr ;
  88. TCHAR szLogFile[MAX_PATH] ;
  89. if (NULL == szFileName)
  90. { //no logging needed
  91. return E_INVALIDARG;
  92. }
  93. AUASSERT(_T('\0') != g_szWUDir[0]);
  94. if (FAILED(hr = StringCchCopyEx(szLogFile, ARRAYSIZE(szLogFile), g_szWUDir, NULL, NULL, MISTSAFE_STRING_FLAGS)) ||
  95. FAILED(hr = StringCchCatEx(szLogFile, ARRAYSIZE(szLogFile), szFileName, NULL, NULL, MISTSAFE_STRING_FLAGS)))
  96. {
  97. return hr;
  98. }
  99. CAU_BSTR aubsTmp;
  100. if (!aubsTmp.append(T2W(szLogFile)))
  101. {
  102. return E_OUTOFMEMORY;
  103. }
  104. if (SUCCEEDED(hr = LoadXMLDoc(bstrMessage, &pxml)))
  105. {
  106. if (FAILED(hr = SaveDocument(pxml, aubsTmp)))
  107. {
  108. DEBUGMSG("Warning: Fail to save xml file %S", T2W(szLogFile));
  109. }
  110. pxml->Release();
  111. }
  112. else
  113. {
  114. DEBUGMSG("Warning: fail to load ill formated xml with error %#lx", hr);
  115. #ifdef DBG
  116. TCHAR szBadFileName[MAX_PATH+1];
  117. if (SUCCEEDED(StringCchCopyEx(szBadFileName, ARRAYSIZE(szBadFileName), szFileName, NULL, NULL, MISTSAFE_STRING_FLAGS)) &&
  118. SUCCEEDED(StringCchCatEx(szBadFileName, ARRAYSIZE(szBadFileName), _T(".xml"), NULL, NULL, MISTSAFE_STRING_FLAGS)))
  119. {
  120. LOGFILE(szBadFileName, bstrMessage);
  121. }
  122. #endif
  123. }
  124. return hr;
  125. }