LDAPCache.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef LDAPCACHE_H
  18. #define LDAPCACHE_H
  19. #include <kopano/zcdefs.h>
  20. #include <memory>
  21. #include <list>
  22. #include <map>
  23. #include <mutex>
  24. #include <string>
  25. #include <kopano/ECDefs.h>
  26. #include <kopano/pcuser.hpp>
  27. namespace KC {
  28. class LDAPUserPlugin;
  29. /**
  30. * @defgroup userplugin_ldap_cache LDAP user plugin cache
  31. * @ingroup userplugin_ldap
  32. * @{
  33. */
  34. /**
  35. * Cache type, std::string is LDAP DN sting
  36. */
  37. typedef std::map<objectid_t, std::string> dn_cache_t;
  38. typedef std::list<std::string> dn_list_t;
  39. /**
  40. * LDAP Cache which collects DNs with the matching
  41. * objectid and name.
  42. */
  43. class LDAPCache _kc_final {
  44. private:
  45. /* Protect mutex from being overriden */
  46. std::recursive_mutex m_hMutex;
  47. std::unique_ptr<dn_cache_t> m_lpCompanyCache; /* CONTAINER_COMPANY */
  48. std::unique_ptr<dn_cache_t> m_lpGroupCache; /* OBJECTCLASS_DISTLIST */
  49. std::unique_ptr<dn_cache_t> m_lpUserCache; /* OBJECTCLASS_USER */
  50. std::unique_ptr<dn_cache_t> m_lpAddressListCache; /* CONTAINER_ADDRESSLIST */
  51. public:
  52. LDAPCache();
  53. /**
  54. * Check if the requested objclass class is cached.
  55. *
  56. * @param[in] objclass
  57. * The objectclass which could be cached.
  58. * @return TRUE if the object class is cached.
  59. */
  60. bool isObjectTypeCached(objectclass_t objclass);
  61. /**
  62. * Add new entries for the object cache.
  63. *
  64. * @param[in] objclass
  65. * The objectclass which should be cached.
  66. * @param[in] lpCache
  67. * The data to add to the cache.
  68. */
  69. void setObjectDNCache(objectclass_t objclass, std::unique_ptr<dn_cache_t> lpCache);
  70. /**
  71. * Obtain the cached data
  72. *
  73. * @param[in] lpPlugin
  74. * Pointer to the plugin, if the objectclass was not cached,
  75. * lpPlugin->getAllObjects() will be called to fill the cache.
  76. * @param[in] objclass
  77. * The objectclass for which the cache is requested
  78. * @return The cache data
  79. */
  80. std::unique_ptr<dn_cache_t> getObjectDNCache(LDAPUserPlugin *lpPlugin, objectclass_t objclass);
  81. /**
  82. * Helper function: Search the cache for the direct parent for a DN.
  83. * If the DN has multiple parents only the parent closest to the DN will be returned.
  84. *
  85. * @param[in] lpCache
  86. * The cache which should be checked.
  87. * @param[in] dn
  88. * The DN for which the parent should be found.
  89. * @return The cache entry of the parent. Contents will be empty if no parent was found.
  90. */
  91. static objectid_t getParentForDN(const std::unique_ptr<dn_cache_t> &lpCache, const std::string &dn);
  92. /**
  93. * Helper function: List all DNs which are hierarchially below the given DN.
  94. *
  95. * @param[in] lpCache
  96. * The cache which should be checked.
  97. * @param[in] dn
  98. * The DN for which the children should be found
  99. * @return The list of children for the DN
  100. */
  101. static std::unique_ptr<dn_list_t> getChildrenForDN(const std::unique_ptr<dn_cache_t> &lpCache, const std::string &dn);
  102. /**
  103. * Search the cache to obtain the DN for an object based on the object id.
  104. *
  105. * @param[in] lpCache
  106. * The cache which should be checked.
  107. * @param[in] externid
  108. * The objectid which should be found in the cache
  109. * @return the DN for the object id
  110. */
  111. static std::string getDNForObject(const std::unique_ptr<dn_cache_t> &lpCache, const objectid_t &externid);
  112. /**
  113. * Check if the given DN is present in the DN list
  114. *
  115. * @param[in] lpList
  116. * The list which should be checked
  117. * @param[in] dn
  118. * The DN which should be found in the list
  119. * @return TRUE if the DN is found in the list
  120. */
  121. static bool isDNInList(const std::unique_ptr<dn_list_t> &lpList, const std::string &dn);
  122. };
  123. /** @} */
  124. } /* namespace */
  125. #endif /* LDAPCACHE_H */