WSStoreTableView.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. #include <new>
  17. #include <kopano/platform.h>
  18. #include "ECMsgStore.h"
  19. #include "WSStoreTableView.h"
  20. #include "Mem.h"
  21. #include <kopano/ECGuid.h>
  22. #include "SOAPUtils.h"
  23. #include "WSUtil.h"
  24. WSStoreTableView::WSStoreTableView(ULONG ulType, ULONG ulFlags, KCmd *lpCmd,
  25. std::recursive_mutex &lpDataLock, ECSESSIONID ecSessionId, ULONG cbEntryId,
  26. LPENTRYID lpEntryId, ECMsgStore *lpMsgStore, WSTransport *lpTransport) :
  27. WSTableView(ulType, ulFlags, lpCmd, lpDataLock, ecSessionId, cbEntryId,
  28. lpEntryId, lpTransport, "WSStoreTableView")
  29. {
  30. // OK, this is ugly, but the static row-wrapper routines need this object
  31. // to get the guid and other information that has to be inlined into the table row. Really,
  32. // the whole transport layer should have no references to the ECMAPI* classes, because that's
  33. // upside-down in the layer model, but having the transport layer first deliver the properties,
  34. // and have a different routine then go through all the properties is more memory intensive AND
  35. // slower as we have 2 passes to fill the queried rows.
  36. this->m_lpProvider = (void *)lpMsgStore;
  37. this->m_ulTableType = TABLETYPE_MS;
  38. }
  39. HRESULT WSStoreTableView::Create(ULONG ulType, ULONG ulFlags, KCmd *lpCmd,
  40. std::recursive_mutex &lpDataLock, ECSESSIONID ecSessionId, ULONG cbEntryId,
  41. LPENTRYID lpEntryId, ECMsgStore *lpMsgStore, WSTransport *lpTransport,
  42. WSTableView **lppTableView)
  43. {
  44. HRESULT hr = hrSuccess;
  45. auto lpTableView = new(std::nothrow) WSStoreTableView(ulType, ulFlags,
  46. lpCmd, lpDataLock, ecSessionId, cbEntryId,
  47. lpEntryId, lpMsgStore, lpTransport);
  48. if (lpTableView == nullptr)
  49. return MAPI_E_NOT_ENOUGH_MEMORY;
  50. hr = lpTableView->QueryInterface(IID_ECTableView, (void **) lppTableView);
  51. if(hr != hrSuccess)
  52. delete lpTableView;
  53. return hr;
  54. }
  55. HRESULT WSStoreTableView::QueryInterface(REFIID refiid, void **lppInterface)
  56. {
  57. REGISTER_INTERFACE3(ECTableView, WSTableView, this);
  58. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  59. }
  60. // WSTableMultiStore view
  61. WSTableMultiStore::WSTableMultiStore(ULONG ulFlags, KCmd *lpCmd,
  62. std::recursive_mutex &lpDataLock, ECSESSIONID ecSessionId, ULONG cbEntryId,
  63. LPENTRYID lpEntryId, ECMsgStore *lpMsgStore, WSTransport *lpTransport) :
  64. WSStoreTableView(MAPI_MESSAGE, ulFlags, lpCmd, lpDataLock, ecSessionId,
  65. cbEntryId, lpEntryId, lpMsgStore, lpTransport)
  66. {
  67. memset(&m_sEntryList, 0, sizeof(m_sEntryList));
  68. m_ulTableType = TABLETYPE_MULTISTORE;
  69. ulTableId = 0;
  70. }
  71. WSTableMultiStore::~WSTableMultiStore()
  72. {
  73. FreeEntryList(&m_sEntryList, false);
  74. }
  75. HRESULT WSTableMultiStore::Create(ULONG ulFlags, KCmd *lpCmd,
  76. std::recursive_mutex &lpDataLock, ECSESSIONID ecSessionId, ULONG cbEntryId,
  77. LPENTRYID lpEntryId, ECMsgStore *lpMsgStore, WSTransport *lpTransport,
  78. WSTableMultiStore **lppTableMultiStore)
  79. {
  80. HRESULT hr = hrSuccess;
  81. WSTableMultiStore *lpTableMultiStore = NULL;
  82. lpTableMultiStore = new WSTableMultiStore(ulFlags, lpCmd, lpDataLock, ecSessionId, cbEntryId, lpEntryId, lpMsgStore, lpTransport);
  83. // interface ?!
  84. hr = lpTableMultiStore->QueryInterface(IID_ECTableView, (void **) lppTableMultiStore);
  85. if(hr != hrSuccess)
  86. delete lpTableMultiStore;
  87. return hr;
  88. }
  89. HRESULT WSTableMultiStore::HrOpenTable()
  90. {
  91. ECRESULT er = erSuccess;
  92. HRESULT hr = hrSuccess;
  93. struct tableOpenResponse sResponse;
  94. LockSoap();
  95. if(this->ulTableId != 0)
  96. goto exit;
  97. //m_sEntryId is the id of a store
  98. if(SOAP_OK != lpCmd->ns__tableOpen(ecSessionId, m_sEntryId, m_ulTableType, MAPI_MESSAGE, this->ulFlags, &sResponse))
  99. er = KCERR_NETWORK_ERROR;
  100. else
  101. er = sResponse.er;
  102. hr = kcerr_to_mapierr(er);
  103. if(hr != hrSuccess)
  104. goto exit;
  105. this->ulTableId = sResponse.ulTableId;
  106. if (SOAP_OK != lpCmd->ns__tableSetMultiStoreEntryIDs(ecSessionId, ulTableId, &m_sEntryList, &er))
  107. er = KCERR_NETWORK_ERROR;
  108. hr = kcerr_to_mapierr(er);
  109. if(hr != hrSuccess)
  110. goto exit;
  111. exit:
  112. UnLockSoap();
  113. return hr;
  114. }
  115. HRESULT WSTableMultiStore::HrSetEntryIDs(LPENTRYLIST lpMsgList)
  116. {
  117. // Not really a transport function, but this is the best place for it for now
  118. return CopyMAPIEntryListToSOAPEntryList(lpMsgList, &m_sEntryList);
  119. }
  120. /*
  121. Miscellaneous tables are not really store tables, but the is the same, so it inherits from the store table
  122. Supported tables are the stats tables, and userstores table.
  123. */
  124. WSTableMisc::WSTableMisc(ULONG ulTableType, ULONG ulFlags, KCmd *lpCmd,
  125. std::recursive_mutex &lpDataLock, ECSESSIONID ecSessionId, ULONG cbEntryId,
  126. LPENTRYID lpEntryId, ECMsgStore *lpMsgStore, WSTransport *lpTransport) :
  127. // is MAPI_STATUS even valid here?
  128. WSStoreTableView(MAPI_STATUS, ulFlags, lpCmd, lpDataLock, ecSessionId,
  129. cbEntryId, lpEntryId, lpMsgStore, lpTransport)
  130. {
  131. m_ulTableType = ulTableType;
  132. ulTableId = 0;
  133. }
  134. HRESULT WSTableMisc::Create(ULONG ulTableType, ULONG ulFlags, KCmd *lpCmd,
  135. std::recursive_mutex &lpDataLock, ECSESSIONID ecSessionId, ULONG cbEntryId,
  136. LPENTRYID lpEntryId, ECMsgStore *lpMsgStore, WSTransport *lpTransport,
  137. WSTableMisc **lppTableMisc)
  138. {
  139. HRESULT hr = hrSuccess;
  140. auto lpTableMisc = new(std::nothrow) WSTableMisc(ulTableType, ulFlags,
  141. lpCmd, lpDataLock, ecSessionId, cbEntryId,
  142. lpEntryId, lpMsgStore, lpTransport);
  143. if (lpTableMisc == nullptr)
  144. return MAPI_E_NOT_ENOUGH_MEMORY;
  145. hr = lpTableMisc->QueryInterface(IID_ECTableView, (void **) lppTableMisc);
  146. if (hr != hrSuccess)
  147. delete lpTableMisc;
  148. return hr;
  149. }
  150. HRESULT WSTableMisc::HrOpenTable()
  151. {
  152. ECRESULT er = erSuccess;
  153. HRESULT hr = hrSuccess;
  154. struct tableOpenResponse sResponse;
  155. LockSoap();
  156. if(ulTableId != 0)
  157. goto exit;
  158. // the class is actually only to call this function with the correct ulTableType .... hmm.
  159. if(SOAP_OK != lpCmd->ns__tableOpen(ecSessionId, m_sEntryId, m_ulTableType, ulType, this->ulFlags, &sResponse))
  160. er = KCERR_NETWORK_ERROR;
  161. else
  162. er = sResponse.er;
  163. hr = kcerr_to_mapierr(er);
  164. if(hr != hrSuccess)
  165. goto exit;
  166. this->ulTableId = sResponse.ulTableId;
  167. exit:
  168. UnLockSoap();
  169. return hr;
  170. }
  171. // WSTableMailBox view
  172. WSTableMailBox::WSTableMailBox(ULONG ulFlags, KCmd *lpCmd,
  173. std::recursive_mutex &lpDataLock, ECSESSIONID ecSessionId,
  174. ECMsgStore *lpMsgStore, WSTransport *lpTransport) :
  175. WSStoreTableView(MAPI_STORE, ulFlags, lpCmd, lpDataLock, ecSessionId,
  176. 0, NULL, lpMsgStore, lpTransport)
  177. {
  178. m_ulTableType = TABLETYPE_MAILBOX;
  179. }
  180. HRESULT WSTableMailBox::Create(ULONG ulFlags, KCmd *lpCmd,
  181. std::recursive_mutex &lpDataLock, ECSESSIONID ecSessionId,
  182. ECMsgStore *lpMsgStore, WSTransport *lpTransport, WSTableMailBox **lppTable)
  183. {
  184. HRESULT hr = hrSuccess;
  185. auto lpTable = new(std::nothrow) WSTableMailBox(ulFlags, lpCmd,
  186. lpDataLock, ecSessionId, lpMsgStore, lpTransport);
  187. if (lpTable == nullptr)
  188. return MAPI_E_NOT_ENOUGH_MEMORY;
  189. //@todo add a new interface
  190. hr = lpTable->QueryInterface(IID_ECTableView, (void **) lppTable);
  191. if(hr != hrSuccess)
  192. delete lpTable;
  193. return hr;
  194. }