ECImportHierarchyChangesProxy.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. extern "C" {
  24. // Remove these defines to remove warnings
  25. #undef PACKAGE_VERSION
  26. #undef PACKAGE_TARNAME
  27. #undef PACKAGE_NAME
  28. #undef PACKAGE_STRING
  29. #undef PACKAGE_BUGREPORT
  30. #include "php.h"
  31. #include "php_globals.h"
  32. #include "ext/standard/info.h"
  33. #include "ext/standard/php_string.h"
  34. }
  35. // A very, very nice PHP #define that causes link errors in MAPI when you have multiple
  36. // files referencing MAPI....
  37. #undef inline
  38. /***************************************************************
  39. * MAPI Includes
  40. ***************************************************************/
  41. #include <mapi.h>
  42. #include <mapix.h>
  43. #include <mapiutil.h>
  44. #include <mapispi.h>
  45. #include <mapitags.h>
  46. #include <mapicode.h>
  47. #define USES_IID_IMAPIProp
  48. #define USES_IID_IMAPIContainer
  49. #define USES_IID_IMsgStore
  50. #define USES_IID_IMessage
  51. #define USES_IID_IExchangeManageStore
  52. #include <edkguid.h>
  53. #include <edkmdb.h>
  54. #include "ECImportHierarchyChangesProxy.h"
  55. #include "typeconversion.h"
  56. ECImportHierarchyChangesProxy::ECImportHierarchyChangesProxy(zval *lpObj TSRMLS_DC) :
  57. m_cRef(1), m_lpObj(lpObj)
  58. {
  59. #if ZEND_MODULE_API_NO >= 20071006
  60. Z_ADDREF_P(m_lpObj);
  61. #else
  62. ZVAL_ADDREF(m_lpObj);
  63. #endif
  64. #ifdef ZTS
  65. this->TSRMLS_C = TSRMLS_C;
  66. #endif
  67. }
  68. ECImportHierarchyChangesProxy::~ECImportHierarchyChangesProxy() {
  69. zval_ptr_dtor(&m_lpObj);
  70. }
  71. ULONG ECImportHierarchyChangesProxy::AddRef() {
  72. return ++m_cRef;
  73. }
  74. ULONG ECImportHierarchyChangesProxy::Release() {
  75. if (--m_cRef == 0) {
  76. delete this;
  77. return 0;
  78. }
  79. return m_cRef;
  80. }
  81. HRESULT ECImportHierarchyChangesProxy::QueryInterface(REFIID iid, void **lpvoid) {
  82. if(iid == IID_IExchangeImportHierarchyChanges) {
  83. AddRef();
  84. *lpvoid = this;
  85. return hrSuccess;
  86. }
  87. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  88. }
  89. HRESULT ECImportHierarchyChangesProxy::GetLastError(HRESULT hResult, ULONG ulFlags, LPMAPIERROR *lppMAPIError) {
  90. return MAPI_E_NO_SUPPORT;
  91. }
  92. HRESULT ECImportHierarchyChangesProxy::Config(LPSTREAM lpStream, ULONG ulFlags) {
  93. HRESULT hr = hrSuccess;
  94. zval *pvalFuncName;
  95. zval *pvalReturn;
  96. zval *pvalArgs[2];
  97. MAKE_STD_ZVAL(pvalFuncName);
  98. MAKE_STD_ZVAL(pvalReturn);
  99. MAKE_STD_ZVAL(pvalArgs[0]);
  100. MAKE_STD_ZVAL(pvalArgs[1]);
  101. if (lpStream != nullptr)
  102. ZVAL_RESOURCE(pvalArgs[0], (long)lpStream);
  103. else
  104. ZVAL_NULL(pvalArgs[0]);
  105. ZVAL_LONG(pvalArgs[1], ulFlags);
  106. ZVAL_STRING(pvalFuncName, "Config" , 1);
  107. if(call_user_function(NULL, &m_lpObj, pvalFuncName, pvalReturn, 2, pvalArgs TSRMLS_CC) == FAILURE) {
  108. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Config method not present on ImportHierarchyChanges object");
  109. hr = MAPI_E_CALL_FAILED;
  110. goto exit;
  111. }
  112. convert_to_long_ex(&pvalReturn);
  113. hr = pvalReturn->value.lval;
  114. exit:
  115. zval_ptr_dtor(&pvalFuncName);
  116. zval_ptr_dtor(&pvalReturn);
  117. zval_ptr_dtor(&pvalArgs[0]);
  118. zval_ptr_dtor(&pvalArgs[1]);
  119. return hr;
  120. }
  121. HRESULT ECImportHierarchyChangesProxy::UpdateState(LPSTREAM lpStream) {
  122. HRESULT hr = hrSuccess;
  123. zval *pvalFuncName;
  124. zval *pvalReturn;
  125. zval *pvalArgs[1];
  126. MAKE_STD_ZVAL(pvalFuncName);
  127. MAKE_STD_ZVAL(pvalReturn);
  128. MAKE_STD_ZVAL(pvalArgs[0]);
  129. if (lpStream != nullptr)
  130. ZVAL_RESOURCE(pvalArgs[0], (long)lpStream);
  131. else
  132. ZVAL_NULL(pvalArgs[0]);
  133. ZVAL_STRING(pvalFuncName, "UpdateState" , 1);
  134. if(call_user_function(NULL, &m_lpObj, pvalFuncName, pvalReturn, 1, pvalArgs TSRMLS_CC) == FAILURE) {
  135. php_error_docref(NULL TSRMLS_CC, E_WARNING, "UpdateState method not present on ImportHierarchyChanges object");
  136. hr = MAPI_E_CALL_FAILED;
  137. goto exit;
  138. }
  139. convert_to_long_ex(&pvalReturn);
  140. hr = pvalReturn->value.lval;
  141. exit:
  142. zval_ptr_dtor(&pvalFuncName);
  143. zval_ptr_dtor(&pvalReturn);
  144. zval_ptr_dtor(&pvalArgs[0]);
  145. return hr;
  146. }
  147. HRESULT ECImportHierarchyChangesProxy::ImportFolderChange(ULONG cValues, LPSPropValue lpPropArray) {
  148. zval *pvalFuncName;
  149. zval *pvalReturn;
  150. zval *pvalArgs[1];
  151. HRESULT hr = hrSuccess;
  152. MAKE_STD_ZVAL(pvalFuncName);
  153. MAKE_STD_ZVAL(pvalReturn);
  154. hr = PropValueArraytoPHPArray(cValues, lpPropArray, &pvalArgs[0] TSRMLS_CC);
  155. if(hr != hrSuccess) {
  156. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert MAPI propvalue array to PHP");
  157. goto exit;
  158. }
  159. ZVAL_STRING(pvalFuncName, "ImportFolderChange", 1);
  160. if(call_user_function(NULL, &m_lpObj, pvalFuncName, pvalReturn, 1, pvalArgs TSRMLS_CC) == FAILURE) {
  161. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ImportFolderChange method not present on ImportHierarchyChanges object");
  162. hr = MAPI_E_CALL_FAILED;
  163. goto exit;
  164. }
  165. convert_to_long_ex(&pvalReturn);
  166. hr = pvalReturn->value.lval;
  167. if(hr != hrSuccess)
  168. goto exit;
  169. exit:
  170. zval_ptr_dtor(&pvalFuncName);
  171. zval_ptr_dtor(&pvalReturn);
  172. zval_ptr_dtor(&pvalArgs[0]);
  173. return hr;
  174. }
  175. HRESULT ECImportHierarchyChangesProxy::ImportFolderDeletion(ULONG ulFlags, LPENTRYLIST lpSourceEntryList) {
  176. HRESULT hr = hrSuccess;
  177. zval *pvalFuncName;
  178. zval *pvalReturn;
  179. zval *pvalArgs[2];
  180. MAKE_STD_ZVAL(pvalFuncName);
  181. MAKE_STD_ZVAL(pvalReturn);
  182. MAKE_STD_ZVAL(pvalArgs[0]);
  183. ZVAL_LONG(pvalArgs[0], ulFlags);
  184. SBinaryArraytoPHPArray(lpSourceEntryList, &pvalArgs[1] TSRMLS_CC);
  185. ZVAL_STRING(pvalFuncName, "ImportFolderDeletion" , 1);
  186. if(call_user_function(NULL, &m_lpObj, pvalFuncName, pvalReturn, 2, pvalArgs TSRMLS_CC) == FAILURE) {
  187. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ImportFolderDeletion method not present on ImportHierarchyChanges object");
  188. hr = MAPI_E_CALL_FAILED;
  189. goto exit;
  190. }
  191. convert_to_long_ex(&pvalReturn);
  192. hr = pvalReturn->value.lval;
  193. exit:
  194. zval_ptr_dtor(&pvalFuncName);
  195. zval_ptr_dtor(&pvalReturn);
  196. zval_ptr_dtor(&pvalArgs[0]);
  197. zval_ptr_dtor(&pvalArgs[1]);
  198. return hr;
  199. }