ECFeatures.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #include "ECFeatures.h"
  18. #include "ECFeatureList.h"
  19. #include <kopano/CommonUtil.h>
  20. #include <kopano/mapi_ptr.h>
  21. using namespace std;
  22. namespace KC {
  23. /**
  24. * Checks if given feature name is an actual kopano feature.
  25. *
  26. * @param[in] feature name of the feature to check
  27. *
  28. * @return
  29. */
  30. bool isFeature(const char* feature)
  31. {
  32. for (size_t i = 0; i < ARRAY_SIZE(kopano_features); ++i)
  33. if (strcasecmp(feature, kopano_features[i]) == 0)
  34. return true;
  35. return false;
  36. }
  37. /**
  38. * Checks if the given feature name is present in the MV list in the given prop
  39. *
  40. * @param[in] feature check for this feature in the MV_STRING8 list in lpProps
  41. * @param[in] lpProps should be either PR_EC_(DIS/EN)ABLED_FEATURES_A
  42. *
  43. * @return MAPI Error code
  44. */
  45. HRESULT hasFeature(const char *feature, const SPropValue *lpProps)
  46. {
  47. if (!feature || !lpProps || PROP_TYPE(lpProps->ulPropTag) != PT_MV_STRING8)
  48. return MAPI_E_INVALID_PARAMETER;
  49. for (ULONG i = 0; i < lpProps->Value.MVszA.cValues; ++i)
  50. if (strcasecmp(lpProps->Value.MVszA.lppszA[i], feature) == 0)
  51. return hrSuccess;
  52. return MAPI_E_NOT_FOUND;
  53. }
  54. /**
  55. * Checks if the given feature name is present in the MV list in the given prop
  56. *
  57. * @param[in] feature check for this feature in the MV_STRING8 list in lpProps
  58. * @param[in] lpProps should be either PR_EC_(DIS/EN)ABLED_FEATURES_A
  59. *
  60. * @return MAPI Error code
  61. */
  62. HRESULT hasFeature(const wchar_t *feature, const SPropValue *lpProps)
  63. {
  64. if (!feature || !lpProps || PROP_TYPE(lpProps->ulPropTag) != PT_MV_UNICODE)
  65. return MAPI_E_INVALID_PARAMETER;
  66. for (ULONG i = 0; i < lpProps->Value.MVszW.cValues; ++i)
  67. if (wcscasecmp(lpProps->Value.MVszW.lppszW[i], feature) == 0)
  68. return hrSuccess;
  69. return MAPI_E_NOT_FOUND;
  70. }
  71. /**
  72. * Retrieve a property from the owner of the given store
  73. *
  74. * @param[in] lpStore Store of a user to get a property of
  75. * @param[in] ulPropTag Get this property from the owner of the store
  76. * @param[out] lpProps Prop value
  77. *
  78. * @return MAPI Error code
  79. */
  80. static HRESULT HrGetUserProp(IAddrBook *lpAddrBook, IMsgStore *lpStore,
  81. ULONG ulPropTag, LPSPropValue *lpProps)
  82. {
  83. SPropValuePtr ptrProps;
  84. MailUserPtr ptrUser;
  85. ULONG ulObjType;
  86. if (lpStore == NULL || PROP_TYPE(ulPropTag) != PT_MV_STRING8 ||
  87. lpProps == NULL)
  88. return MAPI_E_INVALID_PARAMETER;
  89. HRESULT hr = HrGetOneProp(lpStore, PR_MAILBOX_OWNER_ENTRYID, &~ptrProps);
  90. if (hr != hrSuccess)
  91. return hr;
  92. hr = lpAddrBook->OpenEntry(ptrProps->Value.bin.cb, reinterpret_cast<ENTRYID *>(ptrProps->Value.bin.lpb), &IID_IMailUser, 0, &ulObjType, &~ptrUser);
  93. if (hr != hrSuccess)
  94. return hr;
  95. hr = HrGetOneProp(ptrUser, ulPropTag, &~ptrProps);
  96. if (hr != hrSuccess)
  97. return hr;
  98. *lpProps = ptrProps.release();
  99. return hrSuccess;
  100. }
  101. /**
  102. * Check if a feature is present in a given enabled/disabled list
  103. *
  104. * @param[in] feature check this feature name
  105. * @param[in] lpStore Get information from this user store
  106. * @param[in] ulPropTag either enabled or disabled feature list property tag
  107. *
  108. * @return Only return true if explicitly set in property
  109. */
  110. static bool checkFeature(const char *feature, IAddrBook *lpAddrBook,
  111. IMsgStore *lpStore, ULONG ulPropTag)
  112. {
  113. SPropValuePtr ptrProps;
  114. if (feature == NULL || lpStore == NULL ||
  115. PROP_TYPE(ulPropTag) != PT_MV_STRING8)
  116. return MAPI_E_INVALID_PARAMETER == hrSuccess;
  117. HRESULT hr = HrGetUserProp(lpAddrBook, lpStore, ulPropTag, &~ptrProps);
  118. if (hr != hrSuccess)
  119. return false;
  120. return hasFeature(feature, ptrProps) == hrSuccess;
  121. }
  122. bool isFeatureDisabled(const char* feature, IAddrBook *lpAddrBook, IMsgStore *lpStore)
  123. {
  124. return checkFeature(feature, lpAddrBook, lpStore, PR_EC_DISABLED_FEATURES_A);
  125. }
  126. } /* namespace */