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.

141 lines
3.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Declares the class XmlWriter.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef XMLWRITER_H
  11. #define XMLWRITER_H
  12. #pragma once
  13. #include "iaspolcy.h"
  14. struct IASClass;
  15. // Used for converting IAS requests into an XML document.
  16. class XmlWriter
  17. {
  18. public:
  19. // data types
  20. enum DataType
  21. {
  22. nonNegativeInteger,
  23. string,
  24. hexBinary,
  25. ipv4Address,
  26. sqlDateTime
  27. };
  28. XmlWriter();
  29. ~XmlWriter() throw ();
  30. void StartDocument();
  31. void EndDocument();
  32. void InsertElement(
  33. const wchar_t* name,
  34. const wchar_t* value,
  35. DataType dataType
  36. );
  37. void InsertAttribute(
  38. const wchar_t* name,
  39. const IASATTRIBUTE& value
  40. );
  41. const wchar_t* GetDocument() const throw ();
  42. private:
  43. void InsertInteger(
  44. const wchar_t* name,
  45. DWORD value
  46. );
  47. void InsertInetAddr(
  48. const wchar_t* name,
  49. DWORD value
  50. );
  51. void InsertString(
  52. const wchar_t* name,
  53. const IAS_STRING& value
  54. );
  55. void InsertOctetString(
  56. const wchar_t* name,
  57. const IAS_OCTET_STRING& value
  58. );
  59. void InsertUTCTime(
  60. const wchar_t* name,
  61. const FILETIME& value
  62. );
  63. void InsertMicrosoftClass(
  64. const wchar_t* name,
  65. const IASClass& value
  66. );
  67. // Takes no action and returns false if value isn't printable UTF-8.
  68. bool InsertUtf8(
  69. const wchar_t* name,
  70. const char* value,
  71. DWORD valueLen
  72. );
  73. void InsertBinHex(
  74. const wchar_t* name,
  75. const IAS_OCTET_STRING& value
  76. );
  77. void Append(wchar_t c);
  78. void Append(const wchar_t* sz);
  79. void AppendStartTag(const wchar_t* name);
  80. void AppendStartTag(const wchar_t* name, DataType dataType);
  81. void AppendEndTag(const wchar_t* name);
  82. static wchar_t ConvertIntegerToHexWChar(unsigned char src) throw ();
  83. // Reserves nchar additional characters in the buffer and returns a pointer
  84. // to the beginning of the storage.
  85. wchar_t* Reserve(size_t nchar);
  86. // Ensures that the capacity of the scratch buffer is at least nchar. Does
  87. // not preserve the existing contents.
  88. void ReserveScratch(size_t nchar);
  89. // Initial size of the buffer.
  90. static const size_t initialCapacity = 2048;
  91. // Document buffer.
  92. wchar_t* begin;
  93. wchar_t* next;
  94. wchar_t* end;
  95. // 512 is enough to convert any RADIUS attribute to bin.hex.
  96. static const size_t minScratchCapcity = 512;
  97. // Scratch buffer used for conversions.
  98. wchar_t* scratch;
  99. size_t scratchCapacity;
  100. static const wchar_t rootElementName[];
  101. // Not implemented.
  102. XmlWriter(const XmlWriter&);
  103. XmlWriter& operator=(const XmlWriter&);
  104. };
  105. inline const wchar_t* XmlWriter::GetDocument() const throw ()
  106. {
  107. return begin;
  108. }
  109. #endif // XMLWRITER_H