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.

91 lines
2.0 KiB

  1. #include <wininetp.h>
  2. #include "p3pglobal.h"
  3. #include "xmltree.h"
  4. const char *EmptyString = "";
  5. TreeNode::TreeNode() {
  6. pSibling = pDescendant = pParent = NULL;
  7. pAttribute = NULL;
  8. pszContents = NULL;
  9. }
  10. TreeNode::~TreeNode() {
  11. for (TreeNode *pn = pDescendant; pn; ) {
  12. TreeNode *temp = pn->pSibling;
  13. delete pn;
  14. pn = temp;
  15. }
  16. for (XMLAttribute *pa = pAttribute; pa; ) {
  17. XMLAttribute *temp = pa->pNext;
  18. free(pa->pszName);
  19. free(pa->pszValue);
  20. delete pa;
  21. pa = temp;
  22. }
  23. if (pszContents)
  24. free(pszContents);
  25. }
  26. void TreeNode::setContent(const char *pszData) {
  27. if (pszContents)
  28. free(pszContents);
  29. pszContents = pszData ? strdup(pszData) : NULL;
  30. }
  31. void TreeNode::defineAttribute(const char *pszName, const char *pszValue) {
  32. XMLAttribute *pNewAttribute = new XMLAttribute();
  33. pNewAttribute->pszName = strdup(pszName);
  34. pNewAttribute->pszValue = strdup(pszValue);
  35. pNewAttribute->pNext = pAttribute;
  36. /* Insert at beginning of attribute list */
  37. pAttribute = pNewAttribute;
  38. }
  39. const char *TreeNode::attribute(const char *pszAttrName) {
  40. for (XMLAttribute *pa = pAttribute; pa; pa=pa->pNext) {
  41. if (!strcmp(pa->pszName, pszAttrName))
  42. return pa->pszValue;
  43. }
  44. return NULL;
  45. }
  46. TreeNode *TreeNode::find(const char *pszElemName, unsigned int maxDepth) {
  47. /* fail search if the current node does not represent an XML tag... */
  48. if (nodetype!=NODE_ELEMENT)
  49. return NULL;
  50. else if (!strcmp(pszContents, pszElemName))
  51. return this; /* this is the node we are looking for */
  52. else if (maxDepth>0) {
  53. /* otherwise recursively search descendants... */
  54. if (maxDepth!=INFINITE)
  55. maxDepth--;
  56. for (TreeNode *pn=pDescendant; pn; pn=pn->pSibling)
  57. if (TreeNode *pNode = pn->find(pszElemName))
  58. return pNode;
  59. }
  60. return NULL;
  61. }