Source code of Windows XP (NT5)
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.

89 lines
2.0 KiB

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