SOAPUtils.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 SOAPUTILS_H
  18. #define SOAPUTILS_H
  19. #include "soapH.h"
  20. #include "SOAPAlloc.h"
  21. #include <kopano/zcdefs.h>
  22. #include <kopano/kcodes.h>
  23. #include <kopano/pcuser.hpp>
  24. #include <kopano/ustringutil.h>
  25. #include <list>
  26. #include <string>
  27. namespace KC {
  28. // SortOrderSets
  29. extern void FreeSortOrderArray(struct sortOrderArray *lpsSortOrder);
  30. extern int CompareSortOrderArray(const struct sortOrderArray *lpsSortOrder1, const struct sortOrderArray *lpsSortOrder2);
  31. // PropTagArrays
  32. extern ECRESULT CopyPropTagArray(struct soap *soap, const struct propTagArray* lpPTsSrc, struct propTagArray** lppsPTsDst);
  33. extern void FreePropTagArray(struct propTagArray *lpsPropTags, bool bFreeBase = true);
  34. // RowSets
  35. void FreeRowSet(struct rowSet *lpRowSet, bool bBasePointerDel);
  36. // Restrictions
  37. extern ECRESULT FreeRestrictTable(struct restrictTable *lpRestrict, bool base = true);
  38. extern ECRESULT CopyRestrictTable(struct soap *soap, const struct restrictTable *lpSrc, struct restrictTable **lppDst);
  39. // SearchCriteria
  40. extern ECRESULT CopySearchCriteria(struct soap *soap, const struct searchCriteria *lpSrc, struct searchCriteria **lppDst);
  41. extern ECRESULT FreeSearchCriteria(struct searchCriteria *lpSearchCriteria);
  42. // PropValArrays
  43. extern ECRESULT FreePropValArray(struct propValArray *lpPropValArray, bool bFreeBase = false);
  44. extern struct propVal *FindProp(const struct propValArray *lpPropValArray, unsigned int ulPropTag);
  45. extern ECRESULT CopyPropValArray(const struct propValArray *lpSrc, struct propValArray *lpDst, struct soap *soap);
  46. extern ECRESULT CopyPropValArray(const struct propValArray *lpSrc, struct propValArray **lppDst, struct soap *soap);
  47. extern ECRESULT MergePropValArray(struct soap *soap, const struct propValArray *lpsPropValArray1, const struct propValArray *lpsPropValArray2, struct propValArray *lpPropValArrayNew);
  48. // PropVals
  49. extern ECRESULT CompareProp(const struct propVal *lpProp1, const struct propVal *lpProp2, const ECLocale &locale, int *lpCompareResult);
  50. extern ECRESULT CompareMVPropWithProp(struct propVal *lpMVProp1, const struct propVal *lpProp2, unsigned int ulType, const ECLocale &locale, bool* lpfMatch);
  51. size_t PropSize(const struct propVal *);
  52. ECRESULT FreePropVal(struct propVal *lpProp, bool bBasePointerDel);
  53. ECRESULT CopyPropVal(const struct propVal *lpSrc, struct propVal *lpDst, struct soap *soap = NULL, bool bTruncate = false);
  54. ECRESULT CopyPropVal(const struct propVal *lpSrc, struct propVal **lppDst, struct soap *soap = NULL, bool bTruncate = false); /* allocates new lpDst and calls other version */
  55. // EntryList
  56. ECRESULT CopyEntryList(struct soap *soap, struct entryList *lpSrc, struct entryList **lppDst);
  57. ECRESULT FreeEntryList(struct entryList *lpEntryList, bool bFreeBase = true);
  58. // EntryId
  59. ECRESULT CopyEntryId(struct soap *soap, entryId* lpSrc, entryId** lppDst);
  60. ECRESULT FreeEntryId(entryId* lpEntryId, bool bFreeBase);
  61. // Notification
  62. ECRESULT FreeNotificationStruct(notification *lpNotification, bool bFreeBase=true);
  63. ECRESULT CopyNotificationStruct(struct soap *, const notification *from, notification &to);
  64. ECRESULT FreeNotificationArrayStruct(notificationArray *lpNotifyArray, bool bFreeBase);
  65. ECRESULT CopyNotificationArrayStruct(notificationArray *lpNotifyArrayFrom, notificationArray *lpNotifyArrayTo);
  66. // Rights
  67. ECRESULT FreeRightsArray(struct rightsArray *lpRights);
  68. ECRESULT CopyRightsArrayToSoap(struct soap *soap, struct rightsArray *lpRightsArraySrc, struct rightsArray **lppRightsArrayDst);
  69. // userobjects
  70. ECRESULT CopyUserDetailsToSoap(unsigned int ulId, entryId *lpUserEid, const objectdetails_t &details, bool bCopyBinary,
  71. struct soap *soap, struct user *lpUser);
  72. ECRESULT CopyUserDetailsFromSoap(struct user *lpUser, std::string *lpstrExternId, objectdetails_t *details, struct soap *soap);
  73. ECRESULT CopyGroupDetailsToSoap(unsigned int ulId, entryId *lpGroupEid, const objectdetails_t &details, bool bCopyBinary,
  74. struct soap *soap, struct group *lpGroup);
  75. ECRESULT CopyGroupDetailsFromSoap(struct group *lpGroup, std::string *lpstrExternId, objectdetails_t *details, struct soap *soap);
  76. ECRESULT CopyCompanyDetailsToSoap(unsigned int ulId, entryId *lpCompanyEid, unsigned int ulAdmin, entryId *lpAdminEid,
  77. const objectdetails_t &details, bool bCopyBinary, struct soap *soap, struct company *lpCompany);
  78. ECRESULT CopyCompanyDetailsFromSoap(struct company *lpCompany, std::string *lpstrExternId, unsigned int ulAdmin,
  79. objectdetails_t *details, struct soap *soap);
  80. ULONG NormalizePropTag(ULONG ulPropTag);
  81. const char *GetSourceAddr(struct soap *soap);
  82. size_t SearchCriteriaSize(const struct searchCriteria *);
  83. size_t RestrictTableSize(const struct restrictTable *);
  84. size_t PropValArraySize(const struct propValArray *);
  85. size_t EntryListSize(const struct entryList *);
  86. size_t EntryIdSize(const entryId *);
  87. size_t NotificationStructSize(const notification *);
  88. size_t PropTagArraySize(const struct propTagArray *);
  89. size_t SortOrderArraySize(const struct sortOrderArray *);
  90. class DynamicPropValArray _kc_final {
  91. public:
  92. DynamicPropValArray(struct soap *soap, unsigned int ulHint = 10);
  93. ~DynamicPropValArray();
  94. // Copies the passed propVal
  95. ECRESULT AddPropVal(struct propVal &propVal);
  96. // Return a propvalarray of all properties passed
  97. ECRESULT GetPropValArray(struct propValArray *lpPropValArray);
  98. private:
  99. ECRESULT Resize(unsigned int ulSize);
  100. struct soap *m_soap;
  101. struct propVal *m_lpPropVals;
  102. unsigned int m_ulCapacity;
  103. unsigned int m_ulPropCount = 0;
  104. };
  105. class DynamicPropTagArray _kc_final {
  106. public:
  107. DynamicPropTagArray(struct soap *soap);
  108. ECRESULT AddPropTag(unsigned int ulPropTag);
  109. BOOL HasPropTag(unsigned int ulPropTag) const;
  110. ECRESULT GetPropTagArray(struct propTagArray *lpPropTagArray);
  111. private:
  112. std::list<unsigned int> m_lstPropTags;
  113. struct soap *m_soap;
  114. };
  115. // The structure of the data stored in soap->user on the server side
  116. struct SOAPINFO {
  117. CONNECTION_TYPE ulConnectionType;
  118. int (*fparsehdr)(struct soap *soap, const char *key, const char *val);
  119. bool bProxy;
  120. void (*fdone)(struct soap *soap, void *param);
  121. void *fdoneparam;
  122. ECSESSIONID ulLastSessionId; // Session ID of the last processed request
  123. struct timespec threadstart; // Start count of when the thread started processing the request
  124. double start; // Start timestamp of when we started processing the request
  125. const char *szFname;
  126. };
  127. static inline struct SOAPINFO *soap_info(struct soap *s)
  128. {
  129. return static_cast<struct SOAPINFO *>(s->user);
  130. }
  131. } /* namespace */
  132. #endif