ECImportHierarchyChangesProxy.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 "ECImportHierarchyChangesProxy.h"
  59. #include "typeconversion.h"
  60. ECImportHierarchyChangesProxy::ECImportHierarchyChangesProxy(const zval *v TSRMLS_DC) :
  61. m_cRef(1)
  62. {
  63. ZVAL_OBJ(&m_lpObj, Z_OBJ_P(v));
  64. Z_ADDREF(m_lpObj);
  65. }
  66. ECImportHierarchyChangesProxy::~ECImportHierarchyChangesProxy() {
  67. Z_DELREF(m_lpObj);
  68. }
  69. ULONG ECImportHierarchyChangesProxy::AddRef() {
  70. return ++m_cRef;
  71. }
  72. ULONG ECImportHierarchyChangesProxy::Release() {
  73. if (--m_cRef == 0) {
  74. delete this;
  75. return 0;
  76. }
  77. return m_cRef;
  78. }
  79. HRESULT ECImportHierarchyChangesProxy::QueryInterface(REFIID iid, void **lpvoid) {
  80. if(iid == IID_IExchangeImportHierarchyChanges) {
  81. AddRef();
  82. *lpvoid = this;
  83. return hrSuccess;
  84. }
  85. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  86. }
  87. HRESULT ECImportHierarchyChangesProxy::GetLastError(HRESULT hResult, ULONG ulFlags, LPMAPIERROR *lppMAPIError) {
  88. return MAPI_E_NO_SUPPORT;
  89. }
  90. HRESULT ECImportHierarchyChangesProxy::Config(LPSTREAM lpStream, ULONG ulFlags) {
  91. zval pvalFuncName;
  92. zval pvalReturn;
  93. zval pvalArgs[2];
  94. if(lpStream) {
  95. Z_LVAL_P(&pvalArgs[0]) = (long)lpStream;
  96. Z_TYPE_INFO_P(&pvalArgs[0]) = IS_RESOURCE;
  97. } else {
  98. ZVAL_NULL(&pvalArgs[0]);
  99. }
  100. ZVAL_LONG(&pvalArgs[1], ulFlags);
  101. ZVAL_STRING(&pvalFuncName, "Config");
  102. if (call_user_function(NULL, &m_lpObj, &pvalFuncName, &pvalReturn, 2, pvalArgs TSRMLS_CC) == FAILURE) {
  103. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Config method not present on ImportHierarchyChanges object");
  104. return MAPI_E_CALL_FAILED;
  105. }
  106. convert_to_long_ex(&pvalReturn);
  107. return pvalReturn.value.lval;
  108. }
  109. HRESULT ECImportHierarchyChangesProxy::UpdateState(LPSTREAM lpStream) {
  110. zval pvalFuncName;
  111. zval pvalReturn;
  112. zval pvalArgs[1];
  113. if(lpStream) {
  114. Z_LVAL_P(&pvalArgs[0]) = (long)lpStream;
  115. Z_TYPE_INFO_P(&pvalArgs[0]) = IS_RESOURCE;
  116. } else {
  117. ZVAL_NULL(&pvalArgs[0]);
  118. }
  119. ZVAL_STRING(&pvalFuncName, "UpdateState");
  120. if (call_user_function(NULL, &m_lpObj, &pvalFuncName, &pvalReturn, 1, pvalArgs TSRMLS_CC) == FAILURE) {
  121. php_error_docref(NULL TSRMLS_CC, E_WARNING, "UpdateState method not present on ImportHierarchyChanges object");
  122. return MAPI_E_CALL_FAILED;
  123. }
  124. convert_to_long_ex(&pvalReturn);
  125. return pvalReturn.value.lval;
  126. }
  127. HRESULT ECImportHierarchyChangesProxy::ImportFolderChange(ULONG cValues, LPSPropValue lpPropArray) {
  128. zval pvalFuncName;
  129. zval pvalReturn;
  130. zval pvalArgs[1];
  131. HRESULT hr = PropValueArraytoPHPArray(cValues, lpPropArray, &pvalArgs[0] TSRMLS_CC);
  132. if(hr != hrSuccess) {
  133. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert MAPI propvalue array to PHP");
  134. return hr;
  135. }
  136. ZVAL_STRING(&pvalFuncName, "ImportFolderChange");
  137. if (call_user_function(NULL, &m_lpObj, &pvalFuncName, &pvalReturn, 1, pvalArgs TSRMLS_CC) == FAILURE) {
  138. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ImportFolderChange method not present on ImportHierarchyChanges object");
  139. return MAPI_E_CALL_FAILED;
  140. }
  141. convert_to_long_ex(&pvalReturn);
  142. return pvalReturn.value.lval;
  143. }
  144. HRESULT ECImportHierarchyChangesProxy::ImportFolderDeletion(ULONG ulFlags, LPENTRYLIST lpSourceEntryList) {
  145. zval pvalFuncName;
  146. zval pvalReturn;
  147. zval pvalArgs[2];
  148. ZVAL_LONG(&pvalArgs[0], ulFlags);
  149. SBinaryArraytoPHPArray(lpSourceEntryList, &pvalArgs[1] TSRMLS_CC);
  150. ZVAL_STRING(&pvalFuncName, "ImportFolderDeletion");
  151. if (call_user_function(NULL, &m_lpObj, &pvalFuncName, &pvalReturn, 2, pvalArgs TSRMLS_CC) == FAILURE) {
  152. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ImportFolderDeletion method not present on ImportHierarchyChanges object");
  153. return MAPI_E_CALL_FAILED;
  154. }
  155. convert_to_long_ex(&pvalReturn);
  156. return pvalReturn.value.lval;
  157. }