ECImportContentsChangesProxy.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 "phpconfig.h"
  18. #include <kopano/platform.h>
  19. #include <kopano/ecversion.h>
  20. #include <cstdio>
  21. #include <ctime>
  22. #include <cmath>
  23. using namespace std;
  24. extern "C" {
  25. // Remove these defines to remove warnings
  26. #undef PACKAGE_VERSION
  27. #undef PACKAGE_TARNAME
  28. #undef PACKAGE_NAME
  29. #undef PACKAGE_STRING
  30. #undef PACKAGE_BUGREPORT
  31. #if !__GNUC_PREREQ(6,0)
  32. #define zend_isnan(a) std::isnan(a)
  33. #endif
  34. #include "php.h"
  35. #include "php_globals.h"
  36. #include "ext/standard/info.h"
  37. #include "ext/standard/php_string.h"
  38. }
  39. // A very, very nice PHP #define that causes link errors in MAPI when you have multiple
  40. // files referencing MAPI....
  41. #undef inline
  42. /***************************************************************
  43. * MAPI Includes
  44. ***************************************************************/
  45. #include <mapi.h>
  46. #include <mapix.h>
  47. #include <mapiutil.h>
  48. #include <mapispi.h>
  49. #include <mapitags.h>
  50. #include <mapicode.h>
  51. #define USES_IID_IMAPIProp
  52. #define USES_IID_IMAPIContainer
  53. #define USES_IID_IMsgStore
  54. #define USES_IID_IMessage
  55. #define USES_IID_IExchangeManageStore
  56. #include <edkguid.h>
  57. #include <edkmdb.h>
  58. #include "ECImportContentsChangesProxy.h"
  59. #include "typeconversion.h"
  60. static char *name_mapi_message;
  61. static int le_mapi_message;
  62. ECImportContentsChangesProxy::ECImportContentsChangesProxy(const zval *v TSRMLS_DC) :
  63. m_cRef(1)
  64. {
  65. ZVAL_OBJ(&m_lpObj, Z_OBJ_P(v));
  66. Z_ADDREF(m_lpObj);
  67. }
  68. ECImportContentsChangesProxy::~ECImportContentsChangesProxy() {
  69. Z_DELREF(m_lpObj);
  70. }
  71. ULONG ECImportContentsChangesProxy::AddRef() {
  72. return ++m_cRef;
  73. }
  74. ULONG ECImportContentsChangesProxy::Release() {
  75. if (--m_cRef == 0) {
  76. delete this;
  77. return 0;
  78. }
  79. return m_cRef;
  80. }
  81. HRESULT ECImportContentsChangesProxy::QueryInterface(REFIID iid, void **lpvoid) {
  82. if(iid == IID_IExchangeImportContentsChanges) {
  83. AddRef();
  84. *lpvoid = this;
  85. return hrSuccess;
  86. }
  87. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  88. }
  89. HRESULT ECImportContentsChangesProxy::GetLastError(HRESULT hResult, ULONG ulFlags, LPMAPIERROR *lppMAPIError) {
  90. return MAPI_E_NO_SUPPORT;
  91. }
  92. HRESULT ECImportContentsChangesProxy::Config(LPSTREAM lpStream, ULONG ulFlags) {
  93. zval pvalFuncName;
  94. zval pvalReturn;
  95. zval pvalArgs[2];
  96. if(lpStream) {
  97. Z_LVAL_P(&pvalArgs[0]) = (long)lpStream;
  98. Z_TYPE_INFO_P(&pvalArgs[0]) = IS_RESOURCE;
  99. } else {
  100. ZVAL_NULL(&pvalArgs[0]);
  101. }
  102. ZVAL_LONG(&pvalArgs[1], ulFlags);
  103. ZVAL_STRING(&pvalFuncName, "Config");
  104. if (call_user_function(NULL, &m_lpObj, &pvalFuncName, &pvalReturn, 2, pvalArgs TSRMLS_CC) == FAILURE) {
  105. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Config method not present on ImportContentsChanges object");
  106. return MAPI_E_CALL_FAILED;
  107. }
  108. convert_to_long_ex(&pvalReturn);
  109. return pvalReturn.value.lval;
  110. }
  111. HRESULT ECImportContentsChangesProxy::UpdateState(LPSTREAM lpStream) {
  112. zval pvalFuncName;
  113. zval pvalReturn;
  114. zval pvalArgs[1];
  115. if(lpStream) {
  116. Z_LVAL_P(&pvalArgs[0]) = (long)lpStream;
  117. Z_TYPE_INFO_P(&pvalArgs[0]) = IS_RESOURCE;
  118. } else {
  119. ZVAL_NULL(&pvalArgs[0]);
  120. }
  121. ZVAL_STRING(&pvalFuncName, "UpdateState");
  122. if (call_user_function(NULL, &m_lpObj, &pvalFuncName, &pvalReturn, 1, pvalArgs TSRMLS_CC) == FAILURE) {
  123. php_error_docref(NULL TSRMLS_CC, E_WARNING, "UpdateState method not present on ImportContentsChanges object");
  124. return MAPI_E_CALL_FAILED;
  125. }
  126. convert_to_long_ex(&pvalReturn);
  127. return pvalReturn.value.lval;
  128. }
  129. HRESULT ECImportContentsChangesProxy::ImportMessageChange(ULONG cValues, LPSPropValue lpPropArray, ULONG ulFlags, LPMESSAGE * lppMessage) {
  130. zval pvalFuncName;
  131. zval pvalReturn;
  132. zval pvalArgs[3];
  133. IMessage *lpMessage = NULL;
  134. HRESULT hr = PropValueArraytoPHPArray(cValues, lpPropArray, &pvalArgs[0] TSRMLS_CC);
  135. if(hr != hrSuccess) {
  136. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert MAPI propvalue array to PHP");
  137. return hr;
  138. }
  139. ZVAL_LONG(&pvalArgs[1], ulFlags);
  140. ZVAL_NULL(&pvalArgs[2]);
  141. ZVAL_STRING(&pvalFuncName, "ImportMessageChange");
  142. if (call_user_function(NULL, &m_lpObj, &pvalFuncName, &pvalReturn, 3, pvalArgs TSRMLS_CC) == FAILURE) {
  143. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ImportMessageChange method not present on ImportContentsChanges object");
  144. return MAPI_E_CALL_FAILED;
  145. }
  146. convert_to_long_ex(&pvalReturn);
  147. hr = pvalReturn.value.lval;
  148. if(hr != hrSuccess)
  149. return hr;
  150. lpMessage = (IMessage *) zend_fetch_resource(Z_RES_P(&pvalReturn) TSRMLS_CC, name_mapi_message, le_mapi_message);
  151. if(!lpMessage) {
  152. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ImportMessageChange() must return a valid MAPI message resource in the last argument when returning OK (0)");
  153. return MAPI_E_CALL_FAILED;
  154. }
  155. if(lppMessage)
  156. *lppMessage = lpMessage;
  157. return hrSuccess;
  158. }
  159. HRESULT ECImportContentsChangesProxy::ImportMessageDeletion(ULONG ulFlags, LPENTRYLIST lpSourceEntryList) {
  160. zval pvalFuncName;
  161. zval pvalReturn;
  162. zval pvalArgs[2];
  163. ZVAL_LONG(&pvalArgs[0], ulFlags);
  164. SBinaryArraytoPHPArray(lpSourceEntryList, &pvalArgs[1] TSRMLS_CC);
  165. ZVAL_STRING(&pvalFuncName, "ImportMessageDeletion");
  166. if (call_user_function(NULL, &m_lpObj, &pvalFuncName, &pvalReturn, 2, pvalArgs TSRMLS_CC) == FAILURE) {
  167. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ImportMessageDeletion method not present on ImportContentsChanges object");
  168. return MAPI_E_CALL_FAILED;
  169. }
  170. convert_to_long_ex(&pvalReturn);
  171. return pvalReturn.value.lval;
  172. }
  173. HRESULT ECImportContentsChangesProxy::ImportPerUserReadStateChange(ULONG cElements, LPREADSTATE lpReadState) {
  174. zval pvalFuncName;
  175. zval pvalReturn;
  176. zval pvalArgs[1];
  177. ReadStateArraytoPHPArray(cElements, lpReadState, &pvalArgs[0] TSRMLS_CC);
  178. ZVAL_STRING(&pvalFuncName, "ImportPerUserReadStateChange");
  179. if (call_user_function(NULL, &m_lpObj, &pvalFuncName, &pvalReturn, 1, pvalArgs TSRMLS_CC) == FAILURE) {
  180. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ImportPerUserReadStateChange method not present on ImportContentsChanges object");
  181. return MAPI_E_CALL_FAILED;
  182. }
  183. convert_to_long_ex(&pvalReturn);
  184. return pvalReturn.value.lval;
  185. }
  186. HRESULT ECImportContentsChangesProxy::ImportMessageMove(ULONG cbSourceKeySrcFolder, BYTE *pbSourceKeySrcFolder, ULONG cbSourceKeySrcMessage, BYTE *pbSourceKeySrcMessage, ULONG cbPCLMessage, BYTE *pbPCLMessage, ULONG cbSourceKeyDestMessage, BYTE *pbSourceKeyDestMessage, ULONG cbChangeNumDestMessage, BYTE *pbChangeNumDestMessage) {
  187. return MAPI_E_NO_SUPPORT;
  188. }