ECABEntryID.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <kopano/platform.h>
  18. #include <kopano/ECABEntryID.h>
  19. #include <kopano/ECGuid.h>
  20. #include <mapicode.h>
  21. namespace KC {
  22. /* This is a copy from the definition in kcore.hpp. It's for internal use only as we
  23. * don't want to expose the format of the entry id. */
  24. struct ABEID {
  25. BYTE abFlags[4];
  26. GUID guid;
  27. ULONG ulVersion;
  28. ULONG ulType;
  29. ULONG ulId;
  30. char szExId[1];
  31. char szPadding[3];
  32. ABEID(ULONG ulType, GUID guid, ULONG ulId) {
  33. memset(this, 0, sizeof(ABEID));
  34. this->ulType = ulType;
  35. this->guid = guid;
  36. this->ulId = ulId;
  37. }
  38. };
  39. static ABEID g_sDefaultEid(MAPI_MAILUSER, MUIDECSAB, 0);
  40. unsigned char *g_lpDefaultEid = (unsigned char*)&g_sDefaultEid;
  41. const unsigned int g_cbDefaultEid = sizeof(g_sDefaultEid);
  42. static ABEID g_sEveryOneEid(MAPI_DISTLIST, MUIDECSAB, 1);
  43. unsigned char *g_lpEveryoneEid = (unsigned char*)&g_sEveryOneEid;
  44. const unsigned int g_cbEveryoneEid = sizeof(g_sEveryOneEid);
  45. static ABEID g_sSystemEid(MAPI_MAILUSER, MUIDECSAB, 2);
  46. unsigned char *g_lpSystemEid = (unsigned char*)&g_sSystemEid;
  47. const unsigned int g_cbSystemEid = sizeof(g_sSystemEid);
  48. static HRESULT CheckEntryId(unsigned int cbEntryId, const ENTRYID *lpEntryId,
  49. unsigned int ulId, unsigned int ulType, bool *lpbResult)
  50. {
  51. bool bResult = true;
  52. if (cbEntryId < sizeof(ABEID) || lpEntryId == NULL || lpbResult == NULL)
  53. return MAPI_E_INVALID_PARAMETER;
  54. auto lpEid = reinterpret_cast<const ABEID *>(lpEntryId);
  55. if (lpEid->ulId != ulId)
  56. bResult = false;
  57. else if (lpEid->ulType != ulType)
  58. bResult = false;
  59. else if (lpEid->ulVersion == 1 && lpEid->szExId[0])
  60. bResult = false;
  61. *lpbResult = bResult;
  62. return hrSuccess;
  63. }
  64. HRESULT EntryIdIsDefault(unsigned int cbEntryId, const ENTRYID *lpEntryId,
  65. bool *lpbResult)
  66. {
  67. return CheckEntryId(cbEntryId, lpEntryId, 0, MAPI_MAILUSER, lpbResult);
  68. }
  69. HRESULT EntryIdIsSystem(unsigned int cbEntryId, const ENTRYID *lpEntryId,
  70. bool *lpbResult)
  71. {
  72. return CheckEntryId(cbEntryId, lpEntryId, 2, MAPI_MAILUSER, lpbResult);
  73. }
  74. HRESULT EntryIdIsEveryone(unsigned int cbEntryId, const ENTRYID *lpEntryId,
  75. bool *lpbResult)
  76. {
  77. return CheckEntryId(cbEntryId, lpEntryId, 1, MAPI_DISTLIST, lpbResult);
  78. }
  79. HRESULT GetNonPortableObjectId(unsigned int cbEntryId,
  80. const ENTRYID *lpEntryId, unsigned int *lpulObjectId)
  81. {
  82. if (cbEntryId < sizeof(ABEID) || lpEntryId == NULL || lpulObjectId == NULL)
  83. return MAPI_E_INVALID_PARAMETER;
  84. *lpulObjectId = reinterpret_cast<const ABEID *>(lpEntryId)->ulId;
  85. return hrSuccess;
  86. }
  87. HRESULT GetNonPortableObjectType(unsigned int cbEntryId,
  88. const ENTRYID *lpEntryId, ULONG *lpulObjectType)
  89. {
  90. if (cbEntryId < sizeof(ABEID) || lpEntryId == NULL || lpulObjectType == NULL)
  91. return MAPI_E_INVALID_PARAMETER;
  92. *lpulObjectType = reinterpret_cast<const ABEID *>(lpEntryId)->ulType;
  93. return hrSuccess;
  94. }
  95. } /* namespace */