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.

172 lines
5.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Declares the class EapProfile.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef EAPPROFILE_H
  11. #define EAPPROFILE_H
  12. #pragma once
  13. // Manages the EAP configuration for a profile.
  14. class EapProfile
  15. {
  16. public:
  17. struct ConstConfigData
  18. {
  19. DWORD length;
  20. const BYTE* value;
  21. };
  22. struct ConfigData
  23. {
  24. DWORD length;
  25. BYTE* value;
  26. operator const ConstConfigData&() const throw ();
  27. operator ConstConfigData&() throw ();
  28. };
  29. EapProfile() throw ();
  30. ~EapProfile() throw ();
  31. HRESULT Assign(const EapProfile& rhs) throw ();
  32. // Load the profile's state from a VARIANT. The VARIANT is in the format
  33. // used by the SDOs. This function does not clear the supplied VARIANT.
  34. HRESULT Load(VARIANT& src) throw ();
  35. // Store the profile's state to a VARIANT. The VARIANT is in the format used
  36. // by the SDOs. The caller is responsible for deleting the returned VARIANT.
  37. HRESULT Store(VARIANT& dst) throw ();
  38. // Returns the number of types configured.
  39. size_t Size() const throw ();
  40. // Returns true if there are no types configured.
  41. bool IsEmpty() const throw ();
  42. // Clears all the configuration data.
  43. void Clear() throw ();
  44. // Clears all the configuration data except the specified type.
  45. void ClearExcept(BYTE type) throw ();
  46. // Erases the config for the specified type. Has no effect if the type is
  47. // not currently set.
  48. void Erase(BYTE type) throw ();
  49. // Retrieves the config for the specified EAP type. The data is in the
  50. // format used by IEAPProviderConfig2. Returns a zero-length value if the
  51. // per-profile config is not present for the specified type.
  52. void Get(BYTE type, ConstConfigData& dst) const throw ();
  53. // Set the config for the specified EAP type. The data is in the format used
  54. // by IEAPProviderConfig2.
  55. HRESULT Set(BYTE type, const ConstConfigData& newConfig) throw ();
  56. // Pop the the configuration for a single type in the format used by the
  57. // run-time EAP host. Caller is responsible for freeing the returned buffer
  58. // using CoTaskMemFree. Behavior is undefined if IsEmpty() == true.
  59. void Pop(ConfigData& dst) throw ();
  60. void Swap(EapProfile& other) throw ();
  61. private:
  62. // The data type used for the sequence.
  63. typedef unsigned short SeqNum;
  64. // Size of the sequence number in bytes.
  65. static const size_t seqNumSize = 2;
  66. // Maximum number of chunks that the sequence number can support.
  67. static const size_t maxChunks = 0x10000;
  68. // Size of the SDO header: type byte + seqNumSize
  69. static const size_t sdoHeaderSize = 1 + seqNumSize;
  70. // Extract/Insert the sequence bytes.
  71. static SeqNum ExtractSequence(const BYTE* src) throw ();
  72. static void InsertSequence(SeqNum seq, BYTE* dst) throw ();
  73. // Concatenates the config chunks from the supplied VARIANTs and appends it
  74. // to the internal array. The chunks must all be from the same EAP type.
  75. HRESULT GatherAndAppend(
  76. const VARIANT* first,
  77. const VARIANT* last
  78. ) throw ();
  79. // Breaks the config into chunks and stores it in dst. dst must point to
  80. // enough storage to hold the scattered config. Upon return, dst points to
  81. // the element immediately after the scattered chunks.
  82. HRESULT Scatter(
  83. const ConstConfigData& src,
  84. VARIANT*& dst
  85. ) throw ();
  86. // Ensures that the internal array can hold at least newCapacity elements.
  87. HRESULT Reserve(size_t newCapacity) throw ();
  88. // Returns the number of chunks required to scatter 'data'.
  89. static size_t ChunksRequired(const ConstConfigData& data) throw ();
  90. // Returns the length of the embedded SAFEARRAY of BYTEs. Does not check the
  91. // validity of 'src'.
  92. static DWORD ExtractLength(const VARIANT& src) throw ();
  93. // Returns the data from the embedded SAFEARRAY of BYTEs. Does not check the
  94. // validity of 'src'.
  95. static const BYTE* ExtractString(const VARIANT& src) throw ();
  96. // Used for sorting chunks by type and sequence.
  97. static bool LessThan(const VARIANT& lhs, const VARIANT& rhs) throw ();
  98. // Ensures that 'value' contains a valid config chunk.
  99. static HRESULT ValidateConfigChunk(const VARIANT& value) throw ();
  100. // The maximum size of a chunk, not counting the type and sequence bytes.
  101. static const size_t maxChunkSize = 4050;
  102. // The beginning of the config array. This array is stored in run-time
  103. // format, e.g., all chunks have been gathered and the value contains a lead
  104. // type byte, but not a sequence number.
  105. ConfigData* begin;
  106. // The end of the configured types.
  107. ConfigData* end;
  108. // The capacity of the array.
  109. size_t capacity;
  110. // Not implemented.
  111. EapProfile(const EapProfile&);
  112. EapProfile& operator=(const EapProfile&);
  113. };
  114. inline EapProfile::ConfigData::operator
  115. const EapProfile::ConstConfigData&() const throw ()
  116. {
  117. return *reinterpret_cast<const ConstConfigData*>(this);
  118. }
  119. inline EapProfile::ConfigData::operator EapProfile::ConstConfigData&() throw ()
  120. {
  121. return *reinterpret_cast<ConstConfigData*>(this);
  122. }
  123. inline size_t EapProfile::Size() const throw ()
  124. {
  125. return end - begin;
  126. }
  127. inline bool EapProfile::IsEmpty() const throw ()
  128. {
  129. return begin == end;
  130. }
  131. #endif // EAPPROFILE_H