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.

221 lines
6.7 KiB

  1. #include "nt.h"
  2. #include "ntrtl.h"
  3. #include "nturtl.h"
  4. #include "windows.h"
  5. #include <sxsapi.h>
  6. #include "fusionxml.h"
  7. #include "debmacro.h"
  8. #include "fusionbuffer.h"
  9. #include "util.h"
  10. void
  11. SxspCopyXmlStringToBuffer(
  12. PCSXS_XML_DOCUMENT Document,
  13. ULONG String,
  14. CBaseStringBuffer *Buffer
  15. )
  16. {
  17. if (String != 0)
  18. {
  19. if (String < Document->StringCount)
  20. {
  21. Buffer->Win32Assign(L"\"", 1);
  22. Buffer->Win32Append(Document->Strings[String].Buffer, Document->Strings[String].Length / sizeof(WCHAR));
  23. Buffer->Win32Append(L"\"", 1);
  24. }
  25. else
  26. {
  27. Buffer->Win32Assign(L"invalid index", 13);
  28. }
  29. }
  30. else
  31. {
  32. Buffer->Win32Assign(L"none", 4);
  33. }
  34. }
  35. void
  36. SxspDumpXmlAttributes(
  37. PCWSTR PerLinePrefix,
  38. PCSXS_XML_DOCUMENT Document,
  39. ULONG AttributeCount,
  40. PCSXS_XML_ATTRIBUTE Attributes
  41. );
  42. void
  43. SxspDumpXmlSubTree(
  44. PCWSTR PerLinePrefix,
  45. PCSXS_XML_DOCUMENT Document,
  46. PCSXS_XML_NODE Node
  47. )
  48. {
  49. if (Node == NULL)
  50. {
  51. FusionpDbgPrintEx(FUSION_DBG_LEVEL_XMLTREE, "%lsSXS_XML_NODE (NULL)\n");
  52. }
  53. else
  54. {
  55. CSmallStringBuffer buffFlags;
  56. CStringBuffer buffType;
  57. const SIZE_T cchPLP = (PerLinePrefix != NULL) ? wcslen(PerLinePrefix) : 0;
  58. #if 0
  59. static const FUSION_FLAG_FORMAT_MAP_ENTRY s_rgXmlNodeFlags[] =
  60. {
  61. };
  62. ::FusionpFormatFlags(Node->Flags, true, NUMBER_OF(s_rgXmlNodeFlags), s_rgXmlNodeFlags, &buffFlags);
  63. #endif
  64. #define TYPE_ENTRY(x) case x: buffType.Win32Assign(L ## #x, NUMBER_OF( #x ) - 1); break;
  65. switch (Node->Type)
  66. {
  67. default: buffType.Win32Assign(L"unknown", 7); break;
  68. TYPE_ENTRY(SXS_XML_NODE_TYPE_XML_DECL)
  69. TYPE_ENTRY(SXS_XML_NODE_TYPE_ELEMENT)
  70. TYPE_ENTRY(SXS_XML_NODE_TYPE_PCDATA)
  71. TYPE_ENTRY(SXS_XML_NODE_TYPE_CDATA)
  72. }
  73. #undef TYPE_ENTRY
  74. FusionpDbgPrintEx(
  75. FUSION_DBG_LEVEL_XMLTREE,
  76. "%lsSXS_XML_NODE (%p) (Flags, Type, Parent) = (%08lx : %ls, %ls , %p)\n",
  77. PerLinePrefix, Node, Node->Flags, static_cast<PCWSTR>(buffFlags), static_cast<PCWSTR>(buffType), Node->Parent);
  78. switch (Node->Type)
  79. {
  80. default:
  81. break;
  82. case SXS_XML_NODE_TYPE_XML_DECL:
  83. if (Node->XMLDecl.AttributeCount == 0)
  84. {
  85. FusionpDbgPrintEx(
  86. FUSION_DBG_LEVEL_XMLTREE,
  87. "%ls XMLDecl.AttributeCount: %lu\n",
  88. PerLinePrefix, Node->XMLDecl.AttributeCount);
  89. }
  90. else
  91. {
  92. CStringBuffer buffNewPLP;
  93. buffNewPLP.Win32Assign(PerLinePrefix, cchPLP);
  94. buffNewPLP.Win32Append(L" ", 3);
  95. SxspDumpXmlAttributes(buffNewPLP, Document, Node->XMLDecl.AttributeCount, Node->XMLDecl.Attributes);
  96. }
  97. break;
  98. case SXS_XML_NODE_TYPE_ELEMENT:
  99. {
  100. CStringBuffer buffNewPLP;
  101. CStringBuffer buffNS, buffN;
  102. LIST_ENTRY *ple = NULL;
  103. buffNewPLP.Win32Assign(PerLinePrefix, cchPLP);
  104. buffNewPLP.Win32Append(L" ", 3);
  105. SxspCopyXmlStringToBuffer(Document, Node->Element.NamespaceString, &buffNS);
  106. SxspCopyXmlStringToBuffer(Document, Node->Element.NameString, &buffN);
  107. FusionpDbgPrintEx(
  108. FUSION_DBG_LEVEL_XMLTREE,
  109. "%ls Element (.Namespace, .Name): ( %ls , %ls )\n",
  110. PerLinePrefix, static_cast<PCWSTR>(buffNS), static_cast<PCWSTR>(buffN));
  111. if (Node->Element.AttributeCount != 0)
  112. SxspDumpXmlAttributes(buffNewPLP, Document, Node->Element.AttributeCount, Node->Element.Attributes);
  113. ple = Node->Element.ChildListHead.Flink;
  114. while (ple != &Node->Element.ChildListHead)
  115. {
  116. SxspDumpXmlSubTree(buffNewPLP, Document, reinterpret_cast<PSXS_XML_NODE>(CONTAINING_RECORD(ple, SXS_XML_NODE, SiblingLink)));
  117. ple = ple->Flink;
  118. }
  119. break;
  120. }
  121. case SXS_XML_NODE_TYPE_PCDATA:
  122. {
  123. CStringBuffer buff;
  124. SxspCopyXmlStringToBuffer(Document, Node->PCDataString, &buff);
  125. FusionpDbgPrintEx(
  126. FUSION_DBG_LEVEL_XMLTREE,
  127. "%ls PCDataString: %lu (%ls)\n",
  128. PerLinePrefix, Node->PCDataString, static_cast<PCWSTR>(buff));
  129. break;
  130. }
  131. case SXS_XML_NODE_TYPE_CDATA:
  132. {
  133. CStringBuffer buff;
  134. SxspCopyXmlStringToBuffer(Document, Node->CDataString, &buff);
  135. FusionpDbgPrintEx(
  136. FUSION_DBG_LEVEL_XMLTREE,
  137. "%ls CDataString: %lu (%ls)\n",
  138. PerLinePrefix, Node->CDataString, static_cast<PCWSTR>(buff));
  139. break;
  140. }
  141. }
  142. }
  143. }
  144. void
  145. SxspDumpXmlTree(
  146. ULONG Flags,
  147. PCSXS_XML_DOCUMENT Document
  148. )
  149. {
  150. LIST_ENTRY *ple = Document->ElementListHead.Flink;
  151. while (ple != &Document->ElementListHead)
  152. {
  153. SxspDumpXmlSubTree(L"", Document, CONTAINING_RECORD(ple, SXS_XML_NODE, SiblingLink));
  154. ple = ple->Flink;
  155. }
  156. }
  157. void
  158. SxspDumpXmlAttributes(
  159. PCWSTR PerLinePrefix,
  160. PCSXS_XML_DOCUMENT Document,
  161. ULONG AttributeCount,
  162. PCSXS_XML_ATTRIBUTE Attributes
  163. )
  164. {
  165. ULONG i;
  166. CStringBuffer buffNS, buffN, buffV;
  167. for (i=0; i<AttributeCount; i++)
  168. {
  169. SxspCopyXmlStringToBuffer(Document, Attributes[i].NamespaceString, &buffNS);
  170. SxspCopyXmlStringToBuffer(Document, Attributes[i].NameString, &buffN);
  171. SxspCopyXmlStringToBuffer(Document, Attributes[i].ValueString, &buffV);
  172. FusionpDbgPrintEx(
  173. FUSION_DBG_LEVEL_XMLTREE,
  174. "%lsSXS_XML_ATTRIBUTE %lu of %lu (at %p): Flags: %08lx; (NS, N, V) = (%ls , %ls , %ls)\n",
  175. PerLinePrefix, i + 1, AttributeCount, &Attributes[i], Attributes[i].Flags, static_cast<PCWSTR>(buffNS), static_cast<PCWSTR>(buffN), static_cast<PCWSTR>(buffV));
  176. #if 0
  177. "%ls Flags: %08lx\n"
  178. "%ls NamespaceString: %lu (%ls)\n"
  179. "%ls NameString: %lu (%ls)\n"
  180. "%ls ValueString: %lu (%ls)\n",
  181. PerLinePrefix, i + 1, AttributeCount, &Attributes[i],
  182. PerLinePrefix, Attributes[i].Flags,
  183. PerLinePrefix, Attributes[i].NamespaceString, static_cast<PCWSTR>(buffNS),
  184. PerLinePrefix, Attributes[i].NameString, static_cast<PCWSTR>(buffN),
  185. PerLinePrefix, Attributes[i].ValueString, static_cast<PCWSTR>(buffV));
  186. #endif
  187. }
  188. }