ECABProviderSwitch.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <new>
  18. #include <kopano/platform.h>
  19. #include <kopano/ECInterfaceDefs.h>
  20. #include <kopano/memory.hpp>
  21. #include <mapi.h>
  22. #include <mapiutil.h>
  23. #include <mapispi.h>
  24. #include "ECABProvider.h"
  25. #include <kopano/ECGetText.h>
  26. #include <kopano/ECGuid.h>
  27. #include <edkguid.h>
  28. #include <kopano/Trace.h>
  29. #include <kopano/ECDebug.h>
  30. #include <kopano/Util.h>
  31. #include "EntryPoint.h"
  32. #include <kopano/mapiext.h>
  33. #include "ECABProviderSwitch.h"
  34. #include "ProviderUtil.h"
  35. #include <kopano/charset/convstring.h>
  36. using namespace KCHL;
  37. ECABProviderSwitch::ECABProviderSwitch(void) : ECUnknown("ECABProviderSwitch")
  38. {
  39. }
  40. HRESULT ECABProviderSwitch::Create(ECABProviderSwitch **lppECABProvider)
  41. {
  42. return alloc_wrap<ECABProviderSwitch>().as(IID_ECABProvider, lppECABProvider);
  43. }
  44. HRESULT ECABProviderSwitch::QueryInterface(REFIID refiid, void **lppInterface)
  45. {
  46. REGISTER_INTERFACE(IID_ECABProvider, this);
  47. REGISTER_INTERFACE2(ECUnknown, this);
  48. REGISTER_INTERFACE2(IABProvider, &this->m_xABProvider);
  49. REGISTER_INTERFACE2(IUnknown, &this->m_xABProvider);
  50. REGISTER_INTERFACE3(ISelectUnicode, IUnknown, &this->m_xUnknown);
  51. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  52. }
  53. HRESULT ECABProviderSwitch::Shutdown(ULONG * lpulFlags)
  54. {
  55. return hrSuccess;
  56. }
  57. HRESULT ECABProviderSwitch::Logon(LPMAPISUP lpMAPISup, ULONG ulUIParam, LPTSTR lpszProfileName, ULONG ulFlags, ULONG * lpulcbSecurity, LPBYTE * lppbSecurity, LPMAPIERROR * lppMAPIError, LPABLOGON * lppABLogon)
  58. {
  59. HRESULT hr = hrSuccess;
  60. PROVIDER_INFO sProviderInfo;
  61. ULONG ulConnectType = CT_UNSPECIFIED;
  62. object_ptr<IABLogon> lpABLogon;
  63. object_ptr<IABProvider> lpOnline;
  64. convstring tstrProfileName(lpszProfileName, ulFlags);
  65. hr = GetProviders(&g_mapProviders, lpMAPISup, convstring(lpszProfileName, ulFlags).c_str(), ulFlags, &sProviderInfo);
  66. if (hr != hrSuccess)
  67. return hr;
  68. hr = sProviderInfo.lpABProviderOnline->QueryInterface(IID_IABProvider, &~lpOnline);
  69. if (hr != hrSuccess)
  70. return hr;
  71. // Online
  72. hr = lpOnline->Logon(lpMAPISup, ulUIParam, lpszProfileName, ulFlags, nullptr, nullptr, nullptr, &~lpABLogon);
  73. ulConnectType = CT_ONLINE;
  74. // Set the provider in the right connection type
  75. if (SetProviderMode(lpMAPISup, &g_mapProviders,
  76. convstring(lpszProfileName, ulFlags).c_str(), ulConnectType) != hrSuccess)
  77. return MAPI_E_INVALID_PARAMETER;
  78. if(hr != hrSuccess) {
  79. if (ulFlags & MDB_NO_DIALOG)
  80. return MAPI_E_FAILONEPROVIDER;
  81. else if(hr == MAPI_E_NETWORK_ERROR)
  82. /* for disable public folders, so you can work offline */
  83. return MAPI_E_FAILONEPROVIDER;
  84. else if (hr == MAPI_E_LOGON_FAILED)
  85. return MAPI_E_UNCONFIGURED; /* Linux error ?? */
  86. //hr = MAPI_E_LOGON_FAILED;
  87. else
  88. return MAPI_E_LOGON_FAILED;
  89. }
  90. hr = lpMAPISup->SetProviderUID((LPMAPIUID)&MUIDECSAB, 0);
  91. if(hr != hrSuccess)
  92. return hr;
  93. hr = lpABLogon->QueryInterface(IID_IABLogon, (void **)lppABLogon);
  94. if(hr != hrSuccess)
  95. return hr;
  96. if(lpulcbSecurity)
  97. *lpulcbSecurity = 0;
  98. if(lppbSecurity)
  99. *lppbSecurity = NULL;
  100. if (lppMAPIError)
  101. *lppMAPIError = NULL;
  102. return hrSuccess;
  103. }
  104. DEF_HRMETHOD1(TRACE_MAPI, ECABProviderSwitch, ABProvider, QueryInterface, (REFIID, refiid), (void **, lppInterface))
  105. DEF_ULONGMETHOD1(TRACE_MAPI, ECABProviderSwitch, ABProvider, AddRef, (void))
  106. DEF_ULONGMETHOD1(TRACE_MAPI, ECABProviderSwitch, ABProvider, Release, (void))
  107. DEF_HRMETHOD1(TRACE_MAPI, ECABProviderSwitch, ABProvider, Shutdown, (ULONG *, lpulFlags))
  108. DEF_HRMETHOD1(TRACE_MAPI, ECABProviderSwitch, ABProvider, Logon, (LPMAPISUP, lpMAPISup), (ULONG, ulUIParam), (LPTSTR, lpszProfileName), (ULONG, ulFlags), (ULONG *, lpulcbSecurity), (LPBYTE *, lppbSecurity), (LPMAPIERROR *, lppMAPIError), (LPABLOGON *, lppABLogon))