Leaked source code of windows server 2003
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.

202 lines
6.1 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. #define TYPE_ENTRY(x) case x: buffType.Win32Assign(L ## #x, NUMBER_OF( #x ) - 1); break;
  59. switch (Node->Type)
  60. {
  61. default: buffType.Win32Assign(L"unknown", 7); break;
  62. TYPE_ENTRY(SXS_XML_NODE_TYPE_XML_DECL)
  63. TYPE_ENTRY(SXS_XML_NODE_TYPE_ELEMENT)
  64. TYPE_ENTRY(SXS_XML_NODE_TYPE_PCDATA)
  65. TYPE_ENTRY(SXS_XML_NODE_TYPE_CDATA)
  66. }
  67. #undef TYPE_ENTRY
  68. FusionpDbgPrintEx(
  69. FUSION_DBG_LEVEL_XMLTREE,
  70. "%lsSXS_XML_NODE (%p) (Flags, Type, Parent) = (%08lx : %ls, %ls , %p)\n",
  71. PerLinePrefix, Node, Node->Flags, static_cast<PCWSTR>(buffFlags), static_cast<PCWSTR>(buffType), Node->Parent);
  72. switch (Node->Type)
  73. {
  74. default:
  75. break;
  76. case SXS_XML_NODE_TYPE_XML_DECL:
  77. if (Node->XMLDecl.AttributeCount == 0)
  78. {
  79. FusionpDbgPrintEx(
  80. FUSION_DBG_LEVEL_XMLTREE,
  81. "%ls XMLDecl.AttributeCount: %lu\n",
  82. PerLinePrefix, Node->XMLDecl.AttributeCount);
  83. }
  84. else
  85. {
  86. CStringBuffer buffNewPLP;
  87. buffNewPLP.Win32Assign(PerLinePrefix, cchPLP);
  88. buffNewPLP.Win32Append(L" ", 3);
  89. SxspDumpXmlAttributes(buffNewPLP, Document, Node->XMLDecl.AttributeCount, Node->XMLDecl.Attributes);
  90. }
  91. break;
  92. case SXS_XML_NODE_TYPE_ELEMENT:
  93. {
  94. CStringBuffer buffNewPLP;
  95. CStringBuffer buffNS, buffN;
  96. LIST_ENTRY *ple = NULL;
  97. buffNewPLP.Win32Assign(PerLinePrefix, cchPLP);
  98. buffNewPLP.Win32Append(L" ", 3);
  99. SxspCopyXmlStringToBuffer(Document, Node->Element.NamespaceString, &buffNS);
  100. SxspCopyXmlStringToBuffer(Document, Node->Element.NameString, &buffN);
  101. FusionpDbgPrintEx(
  102. FUSION_DBG_LEVEL_XMLTREE,
  103. "%ls Element (.Namespace, .Name): ( %ls , %ls )\n",
  104. PerLinePrefix, static_cast<PCWSTR>(buffNS), static_cast<PCWSTR>(buffN));
  105. if (Node->Element.AttributeCount != 0)
  106. SxspDumpXmlAttributes(buffNewPLP, Document, Node->Element.AttributeCount, Node->Element.Attributes);
  107. ple = Node->Element.ChildListHead.Flink;
  108. while (ple != &Node->Element.ChildListHead)
  109. {
  110. SxspDumpXmlSubTree(buffNewPLP, Document, reinterpret_cast<PSXS_XML_NODE>(CONTAINING_RECORD(ple, SXS_XML_NODE, SiblingLink)));
  111. ple = ple->Flink;
  112. }
  113. break;
  114. }
  115. case SXS_XML_NODE_TYPE_PCDATA:
  116. {
  117. CStringBuffer buff;
  118. SxspCopyXmlStringToBuffer(Document, Node->PCDataString, &buff);
  119. FusionpDbgPrintEx(
  120. FUSION_DBG_LEVEL_XMLTREE,
  121. "%ls PCDataString: %lu (%ls)\n",
  122. PerLinePrefix, Node->PCDataString, static_cast<PCWSTR>(buff));
  123. break;
  124. }
  125. case SXS_XML_NODE_TYPE_CDATA:
  126. {
  127. CStringBuffer buff;
  128. SxspCopyXmlStringToBuffer(Document, Node->CDataString, &buff);
  129. FusionpDbgPrintEx(
  130. FUSION_DBG_LEVEL_XMLTREE,
  131. "%ls CDataString: %lu (%ls)\n",
  132. PerLinePrefix, Node->CDataString, static_cast<PCWSTR>(buff));
  133. break;
  134. }
  135. }
  136. }
  137. }
  138. void
  139. SxspDumpXmlTree(
  140. ULONG Flags,
  141. PCSXS_XML_DOCUMENT Document
  142. )
  143. {
  144. LIST_ENTRY *ple = Document->ElementListHead.Flink;
  145. while (ple != &Document->ElementListHead)
  146. {
  147. SxspDumpXmlSubTree(L"", Document, CONTAINING_RECORD(ple, SXS_XML_NODE, SiblingLink));
  148. ple = ple->Flink;
  149. }
  150. }
  151. void
  152. SxspDumpXmlAttributes(
  153. PCWSTR PerLinePrefix,
  154. PCSXS_XML_DOCUMENT Document,
  155. ULONG AttributeCount,
  156. PCSXS_XML_ATTRIBUTE Attributes
  157. )
  158. {
  159. ULONG i;
  160. CStringBuffer buffNS, buffN, buffV;
  161. for (i=0; i<AttributeCount; i++)
  162. {
  163. SxspCopyXmlStringToBuffer(Document, Attributes[i].NamespaceString, &buffNS);
  164. SxspCopyXmlStringToBuffer(Document, Attributes[i].NameString, &buffN);
  165. SxspCopyXmlStringToBuffer(Document, Attributes[i].ValueString, &buffV);
  166. FusionpDbgPrintEx(
  167. FUSION_DBG_LEVEL_XMLTREE,
  168. "%lsSXS_XML_ATTRIBUTE %lu of %lu (at %p): Flags: %08lx; (NS, N, V) = (%ls , %ls , %ls)\n",
  169. PerLinePrefix, i + 1, AttributeCount, &Attributes[i], Attributes[i].Flags, static_cast<PCWSTR>(buffNS), static_cast<PCWSTR>(buffN), static_cast<PCWSTR>(buffV));
  170. }
  171. }