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.

168 lines
4.7 KiB

  1. #include "nt.h"
  2. #include "ntrtl.h"
  3. #include "nturtl.h"
  4. #include "windows.h"
  5. #include <sxsapi.h>
  6. #include "debmacro.h"
  7. #include "fusiontrace.h"
  8. BOOL
  9. SxspFindNextSibling(
  10. ULONG Flags,
  11. PCSXS_XML_DOCUMENT Document,
  12. const LIST_ENTRY *ChildList,
  13. PCSXS_XML_NODE CurrentChild,
  14. PCSXS_XML_NAMED_REFERENCE Reference,
  15. PCSXS_XML_NODE &rpChild
  16. )
  17. {
  18. BOOL fSuccess = FALSE;
  19. FN_TRACE_WIN32(fSuccess);
  20. LIST_ENTRY *pNext;
  21. PCSXS_XML_NODE pChild = NULL;
  22. rpChild = NULL;
  23. PARAMETER_CHECK(Flags == 0);
  24. PARAMETER_CHECK(ChildList != NULL);
  25. PARAMETER_CHECK(CurrentChild != NULL);
  26. PARAMETER_CHECK(Reference != NULL);
  27. pNext = CurrentChild->SiblingLink.Flink;
  28. while (pNext != ChildList)
  29. {
  30. pChild = CONTAINING_RECORD(pNext, SXS_XML_NODE, SiblingLink);
  31. PCSXS_XML_STRING NamespaceString = &Document->Strings[pChild->Element.NamespaceString];
  32. PCSXS_XML_STRING NameString = &Document->Strings[pChild->Element.NameString];
  33. if ((Reference->NamespaceLength == NamespaceString->Length) &&
  34. (Reference->NameLength == NameString->Length) &&
  35. ((Reference->NamespaceLength == 0) ||
  36. (memcmp(Reference->Namespace, NamespaceString->Buffer, Reference->NamespaceLength) == 0)) &&
  37. ((Reference->NameLength == 0) ||
  38. (memcmp(Reference->Name, NameString->Buffer, Reference->NameLength) == 0)))
  39. {
  40. break;
  41. }
  42. pNext = pNext->Flink;
  43. }
  44. if (pNext != ChildList)
  45. {
  46. // Goodness, we found one!
  47. rpChild = pChild;
  48. }
  49. fSuccess = TRUE;
  50. Exit:
  51. return fSuccess;
  52. }
  53. BOOL
  54. SxspFindChild(
  55. ULONG Flags,
  56. PCSXS_XML_DOCUMENT Document,
  57. const LIST_ENTRY *ChildList,
  58. PCSXS_XML_NAMED_REFERENCE Reference,
  59. PCSXS_XML_NODE &rpChild
  60. )
  61. {
  62. BOOL fSuccess = FALSE;
  63. FN_TRACE_WIN32(fSuccess);
  64. rpChild = NULL;
  65. PARAMETER_CHECK(Flags == 0);
  66. PARAMETER_CHECK(ChildList != NULL);
  67. PARAMETER_CHECK(Reference != NULL);
  68. IFW32FALSE_EXIT(::SxspFindNextSibling(0, Document, ChildList, CONTAINING_RECORD(ChildList, SXS_XML_NODE, SiblingLink), Reference, rpChild));
  69. fSuccess = TRUE;
  70. Exit:
  71. return fSuccess;
  72. }
  73. BOOL
  74. SxspEnumXmlNodes(
  75. ULONG Flags,
  76. PCSXS_XML_DOCUMENT Document,
  77. const LIST_ENTRY *CurrentChildList,
  78. PCSXS_XML_NODE_PATH PathToMatch,
  79. ULONG NextElementPathIndex,
  80. PSXS_ENUM_XML_NODES_CALLBACK Callback,
  81. PVOID CallbackContext,
  82. BOOL *ContinueEnumerationOut
  83. )
  84. {
  85. BOOL fSuccess = FALSE;
  86. FN_TRACE_WIN32(fSuccess);
  87. const LIST_ENTRY *pNext = CurrentChildList;
  88. PCSXS_XML_NODE pChild;
  89. PCSXS_XML_NAMED_REFERENCE pReference;
  90. if (ContinueEnumerationOut != NULL)
  91. *ContinueEnumerationOut = TRUE;
  92. PARAMETER_CHECK(Flags == 0);
  93. PARAMETER_CHECK(Document != NULL);
  94. PARAMETER_CHECK(CurrentChildList != NULL);
  95. PARAMETER_CHECK(PathToMatch != NULL);
  96. PARAMETER_CHECK(NextElementPathIndex < PathToMatch->ElementCount);
  97. PARAMETER_CHECK(Callback != NULL);
  98. PARAMETER_CHECK(ContinueEnumerationOut != NULL);
  99. pReference = PathToMatch->Elements[NextElementPathIndex++];
  100. for (;;)
  101. {
  102. // find the next matching sibling at this level of the tree
  103. IFW32FALSE_EXIT(::SxspFindNextSibling(0, Document, CurrentChildList, CONTAINING_RECORD(pNext, SXS_XML_NODE, SiblingLink), pReference, pChild));
  104. if (pChild == NULL)
  105. break;
  106. INTERNAL_ERROR_CHECK(pChild->Type == SXS_XML_NODE_TYPE_ELEMENT);
  107. // If we're at the leaves of the reference path to match, call the callback.
  108. if (NextElementPathIndex == PathToMatch->ElementCount)
  109. (*Callback)(CallbackContext, pChild, ContinueEnumerationOut);
  110. else
  111. IFW32FALSE_EXIT(::SxspEnumXmlNodes(0, Document, &pChild->Element.ChildListHead, PathToMatch, NextElementPathIndex, Callback, CallbackContext, ContinueEnumerationOut));
  112. // If the callback said to stop, bail out.
  113. if (!*ContinueEnumerationOut)
  114. break;
  115. }
  116. fSuccess = TRUE;
  117. Exit:
  118. return fSuccess;
  119. }
  120. BOOL
  121. SxsEnumXmlNodes(
  122. ULONG Flags,
  123. PCSXS_XML_DOCUMENT Document,
  124. PCSXS_XML_NODE_PATH PathToMatch,
  125. PSXS_ENUM_XML_NODES_CALLBACK Callback,
  126. PVOID CallbackContext
  127. )
  128. {
  129. BOOL fSuccess = FALSE;
  130. FN_TRACE_WIN32(fSuccess);
  131. BOOL ContinueEnumeration;
  132. PARAMETER_CHECK(Flags == 0);
  133. PARAMETER_CHECK(PathToMatch != NULL);
  134. PARAMETER_CHECK(Callback != NULL);
  135. IFW32FALSE_EXIT(::SxspEnumXmlNodes(0, Document, &Document->ElementListHead, PathToMatch, 0, Callback, CallbackContext, &ContinueEnumeration));
  136. fSuccess = TRUE;
  137. Exit:
  138. return fSuccess;
  139. }