ECXPProvider.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <kopano/memory.hpp>
  19. #include <mapi.h>
  20. #include <mapispi.h>
  21. #include <mapiutil.h>
  22. #include <kopano/ECGuid.h>
  23. #include <kopano/ECInterfaceDefs.h>
  24. #include "kcore.hpp"
  25. #include "ECXPProvider.h"
  26. #include "ECXPLogon.h"
  27. #include "WSTransport.h"
  28. #include "Mem.h"
  29. #include <kopano/Util.h>
  30. #include <kopano/ECDebug.h>
  31. #include "ClientUtil.h"
  32. #include "EntryPoint.h"
  33. #include <kopano/charset/convstring.h>
  34. #include <kopano/ECGetText.h>
  35. using namespace KCHL;
  36. ECXPProvider::ECXPProvider() : ECUnknown("IXPProvider")
  37. {
  38. }
  39. ECXPProvider::~ECXPProvider()
  40. {
  41. if(m_lpIdentityProps)
  42. ECFreeBuffer(m_lpIdentityProps);
  43. }
  44. HRESULT ECXPProvider::Create(ECXPProvider **lppECXPProvider) {
  45. auto lpECXPProvider = new(std::nothrow) ECXPProvider;
  46. if (lpECXPProvider == nullptr)
  47. return MAPI_E_NOT_ENOUGH_MEMORY;
  48. auto ret = lpECXPProvider->QueryInterface(IID_ECXPProvider,
  49. reinterpret_cast<void **>(lppECXPProvider));
  50. if (ret != hrSuccess)
  51. delete lpECXPProvider;
  52. return ret;
  53. }
  54. HRESULT ECXPProvider::QueryInterface(REFIID refiid, void **lppInterface)
  55. {
  56. REGISTER_INTERFACE2(ECXPProvider, this);
  57. REGISTER_INTERFACE2(IXPProvider, &this->m_xXPProvider);
  58. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  59. }
  60. HRESULT ECXPProvider::Shutdown(ULONG * lpulFlags)
  61. {
  62. return hrSuccess;
  63. }
  64. HRESULT ECXPProvider::TransportLogon(LPMAPISUP lpMAPISup, ULONG ulUIParam, LPTSTR lpszProfileName, ULONG * lpulFlags, LPMAPIERROR * lppMAPIError, LPXPLOGON * lppXPLogon)
  65. {
  66. HRESULT hr = hrSuccess;
  67. object_ptr<ECXPLogon> lpXPLogon;
  68. object_ptr<WSTransport> lpTransport;
  69. ECMapProvider::const_iterator iterMap;
  70. std::string strServerURL;
  71. std::string strUniqueId;
  72. BOOL bOffline = FALSE;
  73. convstring tstrProfileName(lpszProfileName, *lpulFlags);
  74. std::string strDisplayName;
  75. // Get transport by looking at how we have logged on. We assume here that a message store or addressbook has been
  76. // logged on before calling TransportLogon and therefore the connection type is never CT_UNSPECIFIED.
  77. iterMap = g_mapProviders.find(tstrProfileName);
  78. // Online if: no entry in map, OR map specifies online mode
  79. if (iterMap == g_mapProviders.cend() ||
  80. iterMap->second.ulConnectType == CT_ONLINE) {
  81. // Online
  82. hr = WSTransport::HrOpenTransport(lpMAPISup, &~lpTransport, FALSE);
  83. bOffline = FALSE;
  84. } else {
  85. // Offline
  86. hr = WSTransport::HrOpenTransport(lpMAPISup, &~lpTransport, TRUE);
  87. bOffline = TRUE;
  88. }
  89. if (hr != hrSuccess)
  90. return MAPI_E_FAILONEPROVIDER;
  91. hr = ECXPLogon::Create(tstrProfileName, bOffline, this, lpMAPISup, &~lpXPLogon);
  92. if(hr != hrSuccess)
  93. return hr;
  94. hr = lpXPLogon->QueryInterface(IID_IXPLogon, (void **)lppXPLogon);
  95. if(hr != hrSuccess)
  96. return hr;
  97. AddChild(lpXPLogon);
  98. // Set profile identity
  99. hr = ClientUtil::HrSetIdentity(lpTransport, lpMAPISup, &m_lpIdentityProps);
  100. if(hr != hrSuccess)
  101. return hr;
  102. // Initialize statusrow
  103. strDisplayName = convert_to<std::string>(g_strManufacturer.c_str()) + _A(" Transport");
  104. hr = ClientUtil::HrInitializeStatusRow(strDisplayName.c_str(), MAPI_TRANSPORT_PROVIDER, lpMAPISup, m_lpIdentityProps, 0);
  105. if(hr != hrSuccess)
  106. return hr;
  107. *lpulFlags = 0;
  108. *lppMAPIError = NULL;
  109. return hrSuccess;
  110. }
  111. DEF_HRMETHOD1(TRACE_MAPI, ECXPProvider, XPProvider, QueryInterface, (REFIID, refiid), (void **, lppInterface))
  112. DEF_ULONGMETHOD1(TRACE_MAPI, ECXPProvider, XPProvider, AddRef, (void))
  113. DEF_ULONGMETHOD1(TRACE_MAPI, ECXPProvider, XPProvider, Release, (void))
  114. DEF_HRMETHOD1(TRACE_MAPI, ECXPProvider, XPProvider, Shutdown, (ULONG *, lpulFlags))
  115. DEF_HRMETHOD1(TRACE_MAPI, ECXPProvider, XPProvider, TransportLogon, (LPMAPISUP, lpMAPISup), (ULONG, ulUIParam), (LPTSTR, lpszProfileName), (ULONG *, lpulFlags), (LPMAPIERROR *, lppMAPIError), (LPXPLOGON *, lppXPLogon))