ECICS.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 ECICS_H
  18. #define ECICS_H
  19. #include <kopano/zcdefs.h>
  20. #include "ECSession.h"
  21. #include <set>
  22. struct soap;
  23. namespace KC {
  24. // This class is used to pass SOURCEKEYs internally between parts of the server backend. You can use it as a char* to get the data, use size() to get the size,
  25. // and have various ways of creating new SOURCEKEYs, including using a GUID and an ID, which is used for kopano-generated source keys.
  26. class SOURCEKEY _kc_final {
  27. public:
  28. SOURCEKEY(void) : ulSize(0) {}
  29. SOURCEKEY(const SOURCEKEY &s) : ulSize(s.ulSize)
  30. {
  31. if (ulSize > 0) {
  32. lpData.reset(new char[s.ulSize]);
  33. memcpy(lpData.get(), s.lpData.get(), s.ulSize);
  34. }
  35. }
  36. SOURCEKEY(SOURCEKEY &&o) :
  37. ulSize(o.ulSize), lpData(std::move(o.lpData))
  38. {}
  39. SOURCEKEY(unsigned int z, const char *d) : ulSize(z)
  40. {
  41. if (d != nullptr && z > 0) {
  42. lpData.reset(new char[ulSize]);
  43. memcpy(lpData.get(), d, ulSize);
  44. }
  45. }
  46. SOURCEKEY(const GUID &guid, unsigned long long ullId) :
  47. ulSize(sizeof(GUID) + 6), lpData(new char[ulSize])
  48. {
  49. memcpy(&lpData[0], &guid, sizeof(guid));
  50. memcpy(&lpData[sizeof(GUID)], &ullId, ulSize - sizeof(GUID));
  51. }
  52. SOURCEKEY(const struct xsd__base64Binary &sourcekey) :
  53. ulSize(sourcekey.__size)
  54. {
  55. if (ulSize > 0) {
  56. lpData.reset(new char[ulSize]);
  57. memcpy(this->lpData.get(), sourcekey.__ptr, sourcekey.__size);
  58. }
  59. }
  60. SOURCEKEY& operator= (const SOURCEKEY &s) {
  61. if(&s == this) return *this;
  62. lpData.reset(new char[s.ulSize]);
  63. ulSize = s.ulSize;
  64. memcpy(lpData.get(), s.lpData.get(), ulSize);
  65. return *this;
  66. }
  67. bool operator == (const SOURCEKEY &s) const {
  68. if(this == &s)
  69. return true;
  70. if(ulSize != s.ulSize)
  71. return false;
  72. return memcmp(lpData.get(), s.lpData.get(), s.ulSize) == 0;
  73. }
  74. bool operator < (const SOURCEKEY &s) const {
  75. if(this == &s)
  76. return false;
  77. if(ulSize == s.ulSize)
  78. return memcmp(lpData.get(), s.lpData.get(), ulSize) < 0;
  79. else if(ulSize > s.ulSize) {
  80. int d = memcmp(lpData.get(), s.lpData.get(), s.ulSize);
  81. return (d == 0) ? false : (d < 0); // If the compared part is equal, the shortes is less (s)
  82. } else {
  83. int d = memcmp(lpData.get(), s.lpData.get(), ulSize);
  84. return (d == 0) ? true : (d < 0); // If the compared part is equal, the shortes is less (this)
  85. }
  86. }
  87. operator unsigned char *(void) const { return reinterpret_cast<unsigned char *>(lpData.get()); }
  88. operator std::string(void) const { return std::string(lpData.get(), ulSize); }
  89. unsigned int size() const { return ulSize; }
  90. bool empty() const { return ulSize == 0; }
  91. private:
  92. unsigned int ulSize;
  93. std::unique_ptr<char[]> lpData;
  94. };
  95. ECRESULT AddChange(BTSession *lpecSession, unsigned int ulSyncId, const SOURCEKEY &sSourceKey, const SOURCEKEY &sParentSourceKey, unsigned int ulChange, unsigned int ulFlags = 0, bool fForceNewChangeKey = false, std::string *lpstrChangeKey = NULL, std::string *lpstrChangeList = NULL);
  96. ECRESULT AddABChange(BTSession *lpecSession, unsigned int ulChange, SOURCEKEY sSourceKey, SOURCEKEY sParentSourceKey);
  97. ECRESULT GetChanges(struct soap *soap, ECSession *lpSession, SOURCEKEY sSourceKeyFolder, unsigned int ulSyncId, unsigned int ulChangeId, unsigned int ulChangeType, unsigned int ulFlags, struct restrictTable *lpsRestrict, unsigned int *lpulMaxChangeId, icsChangesArray **lppChanges);
  98. ECRESULT GetSyncStates(struct soap *soap, ECSession *lpSession, mv_long ulaSyncId, syncStateArray *lpsaSyncState);
  99. extern _kc_export void *CleanupSyncsTable(void *);
  100. extern _kc_export void *CleanupSyncedMessagesTable(void *);
  101. /**
  102. * Adds the message specified by sSourceKey to the last set of syncedmessages for the syncer identified by
  103. * ulSyncId. This causes GetChanges to know that the message is available on the client so it doesn't need
  104. * to send a add to the client.
  105. *
  106. * @param[in] lpDatabase
  107. * Pointer to the database.
  108. * @param[in] ulSyncId
  109. * The sync id of the client for whom the message is to be registered.
  110. * @param[in] sSourceKey
  111. * The source key of the message.
  112. * @param[in] sParentSourceKey
  113. * THe source key of the folder containing the message.
  114. */
  115. ECRESULT AddToLastSyncedMessagesSet(ECDatabase *lpDatabase, unsigned int ulSyncId, const SOURCEKEY &sSourceKey, const SOURCEKEY &sParentSourceKey);
  116. ECRESULT CheckWithinLastSyncedMessagesSet(ECDatabase *lpDatabase, unsigned int ulSyncId, const SOURCEKEY &sSourceKey);
  117. ECRESULT RemoveFromLastSyncedMessagesSet(ECDatabase *lpDatabase, unsigned int ulSyncId, const SOURCEKEY &sSourceKey, const SOURCEKEY &sParentSourceKey);
  118. } /* namespace */
  119. #endif