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.

92 lines
2.4 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // FILE
  4. //
  5. // ntcache.h
  6. //
  7. // SYNOPSIS
  8. //
  9. // Declares the class NTCache.
  10. //
  11. // MODIFICATION HISTORY
  12. //
  13. // 05/11/1998 Original version.
  14. // 03/12/1999 Improve locking granularity.
  15. //
  16. ///////////////////////////////////////////////////////////////////////////////
  17. #ifndef _NTCACHE_H_
  18. #define _NTCACHE_H_
  19. #if _MSC_VER >= 1000
  20. #pragma once
  21. #endif
  22. #include <hashtbl.h>
  23. #include <iasutil.h>
  24. #include <ntdomain.h>
  25. ///////////////////////////////////////////////////////////////////////////////
  26. //
  27. // CLASS
  28. //
  29. // NTCache
  30. //
  31. // DESCRIPTION
  32. //
  33. // This class maintains a cache of NTDomain objects indexed by domain name.
  34. //
  35. ///////////////////////////////////////////////////////////////////////////////
  36. class NTCache
  37. : Guardable, NonCopyable
  38. {
  39. public:
  40. ~NTCache() throw ();
  41. // Flushes the cache.
  42. void clear() throw ();
  43. // Returns a connection to the specified domain. The client is responsible
  44. // for releasing the connection when done.
  45. DWORD getConnection(PCWSTR domainName, LDAPConnection** cxn) throw ();
  46. // Either retrieves an existing NTDomain object or creates a new one.
  47. // This method does not actually validate that the domain exists, so it
  48. // only fails when unable to allocate memory. The client is responsible
  49. // for releasing the domain when done.
  50. DWORD getDomain(PCWSTR domainName, NTDomain** domain) throw ();
  51. // Returns the mode of the specified domain.
  52. NTDomain::Mode getMode(PCWSTR domainName) throw ();
  53. protected:
  54. // Removes all expired domains from the cache.
  55. void evict() throw ();
  56. typedef PCWSTR Key;
  57. typedef NTDomain* Value;
  58. // Hash a domain object.
  59. struct Hasher {
  60. ULONG operator()(Key key) const throw ()
  61. { return hash_util::hash(key); }
  62. };
  63. // Extract the key (i.e., domainName) from a domain object.
  64. struct Extractor {
  65. Key operator()(const Value domain) const throw ()
  66. { return domain->getDomainName(); }
  67. };
  68. // Test two domain objects for equality.
  69. struct KeyMatch {
  70. bool operator()(Key key1, Key key2) const throw ()
  71. { return wcscmp(key1, key2) == 0; }
  72. };
  73. typedef hash_table<Key, Hasher, Value, Extractor, KeyMatch> DomainTable;
  74. DomainTable cache;
  75. };
  76. #endif // _NTCACHE_H_