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.

144 lines
3.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // vsadnary.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file declares the class VSADictionary.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 03/07/1998 Original version.
  16. // 09/16/1998 Add additional fields to VSA definition.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #ifndef _VSADNARY_H_
  20. #define _VSADNARY_H_
  21. #if _MSC_VER >= 1000
  22. #pragma once
  23. #endif
  24. #include <hashmap.h>
  25. #include <iaspolcy.h>
  26. #include <nocopy.h>
  27. //////////
  28. // Struct representing an entry in the dictionary.
  29. //////////
  30. struct VSADef
  31. {
  32. DWORD vendorID; // RADIUS Vendor-Id.
  33. DWORD vendorType; // RADIUS Vendor-Type.
  34. DWORD vendorTypeWidth; // Width in bytes of the Vendor-Type field.
  35. DWORD vendorLengthWidth; // Width in bytes of the Vendor-Length field.
  36. DWORD iasID; // IAS protocol-independent attribute ID.
  37. IASTYPE iasType; // The IAS attribute syntax.
  38. /////////
  39. // Functors used for indexing VSADef objects.
  40. /////////
  41. struct HashByIAS {
  42. DWORD operator()(const VSADef& v) const throw ()
  43. { return v.iasID; }
  44. };
  45. struct EqualByIAS {
  46. bool operator()(const VSADef& lhs, const VSADef& rhs) const throw ()
  47. { return lhs.iasID == rhs.iasID; }
  48. };
  49. struct HashByRADIUS {
  50. DWORD operator()(const VSADef& v) const throw ()
  51. { return v.vendorID ^ v.vendorType; }
  52. };
  53. struct EqualByRADIUS {
  54. bool operator()( const VSADef& lhs, const VSADef& rhs) const throw ()
  55. { return memcmp(&lhs, &rhs, 3 * sizeof(DWORD)) == 0; }
  56. };
  57. };
  58. ///////////////////////////////////////////////////////////////////////////////
  59. //
  60. // CLASS
  61. //
  62. // VSADictionary
  63. //
  64. // DESCRIPTION
  65. //
  66. // This class indexes all the information necessary for converting
  67. // vendor specific attributes between RADIUS format and IAS protocol-
  68. // independent format.
  69. //
  70. ///////////////////////////////////////////////////////////////////////////////
  71. class VSADictionary
  72. : NonCopyable
  73. {
  74. public:
  75. VSADictionary()
  76. : refCount(0)
  77. { }
  78. // Retrieve a definition based on the IAS attribute ID.
  79. const VSADef* find(DWORD iasID) const throw ()
  80. {
  81. VSADef key;
  82. key.iasID = iasID;
  83. return byIAS.find(key);
  84. }
  85. // Retrieve a definition based on the RADIUS vendor ID, type, and width.
  86. const VSADef* find(const VSADef& key) const throw ()
  87. {
  88. return byRADIUS.find(key);
  89. }
  90. // Initialize the dictionary for use.
  91. HRESULT initialize() throw ();
  92. // Shutdown the dictionary after use.
  93. void shutdown() throw ();
  94. protected:
  95. // Clear the indices.
  96. void clear() throw ()
  97. {
  98. byIAS.clear();
  99. byRADIUS.clear();
  100. }
  101. // Insert a new definition into the dictionary.
  102. void insert(const VSADef& newDef)
  103. {
  104. byIAS.multi_insert(newDef);
  105. byRADIUS.multi_insert(newDef);
  106. }
  107. typedef hash_table< VSADef,
  108. VSADef::HashByIAS,
  109. VSADef,
  110. identity< VSADef >,
  111. VSADef::EqualByIAS
  112. > IASMap;
  113. typedef hash_table< VSADef,
  114. VSADef::HashByRADIUS,
  115. VSADef,
  116. identity< VSADef >,
  117. VSADef::EqualByRADIUS
  118. > RADIUSMap;
  119. IASMap byIAS; // Indexed by IAS attribute ID.
  120. RADIUSMap byRADIUS; // Indexed by RADIUS Vendor-Id, Vendor-Type, and width.
  121. DWORD refCount; // Initialization reference count.
  122. };
  123. #endif // _VSADNARY_H_