ECABProvider.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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/ECInterfaceDefs.h>
  19. #include <kopano/memory.hpp>
  20. #include <mapi.h>
  21. #include <kopano/mapiext.h>
  22. #include <mapispi.h>
  23. #include <mapiutil.h>
  24. #include "kcore.hpp"
  25. #include <kopano/ECGuid.h>
  26. #include <edkguid.h>
  27. #include "ECABProvider.h"
  28. #include "ECABLogon.h"
  29. #include <kopano/ECDebug.h>
  30. #include <kopano/Util.h>
  31. #include "WSTransport.h"
  32. #include "ClientUtil.h"
  33. #include "EntryPoint.h"
  34. #include "pcutil.hpp"
  35. typedef KCHL::memory_ptr<ECUSER> ECUserPtr;
  36. #include <kopano/ECGetText.h>
  37. using namespace std;
  38. using namespace KCHL;
  39. ECABProvider::ECABProvider(ULONG ulFlags, const char *szClassName) :
  40. ECUnknown(szClassName)
  41. {
  42. m_ulFlags = ulFlags;
  43. }
  44. HRESULT ECABProvider::Create(ECABProvider **lppECABProvider)
  45. {
  46. return alloc_wrap<ECABProvider>(0, "ECABProvider").as(IID_ECABProvider, lppECABProvider);
  47. }
  48. HRESULT ECABProvider::QueryInterface(REFIID refiid, void **lppInterface)
  49. {
  50. REGISTER_INTERFACE2(ECABProvider, this);
  51. REGISTER_INTERFACE2(ECUnknown, this);
  52. REGISTER_INTERFACE2(IABProvider, &this->m_xABProvider);
  53. REGISTER_INTERFACE2(IUnknown, &this->m_xABProvider);
  54. REGISTER_INTERFACE3(ISelectUnicode, IUnknown, &this->m_xUnknown);
  55. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  56. }
  57. HRESULT ECABProvider::Shutdown(ULONG * lpulFlags)
  58. {
  59. return hrSuccess;
  60. }
  61. HRESULT ECABProvider::Logon(LPMAPISUP lpMAPISup, ULONG ulUIParam, LPTSTR lpszProfileName, ULONG ulFlags, ULONG * lpulcbSecurity, LPBYTE * lppbSecurity, LPMAPIERROR * lppMAPIError, LPABLOGON * lppABLogon)
  62. {
  63. HRESULT hr = hrSuccess;
  64. object_ptr<ECABLogon> lpABLogon;
  65. sGlobalProfileProps sProfileProps;
  66. LPMAPIUID lpGuid = NULL;
  67. object_ptr<WSTransport> lpTransport;
  68. if (lpMAPISup == nullptr || lppABLogon == nullptr)
  69. return MAPI_E_INVALID_PARAMETER;
  70. // Get the username and password from the profile settings
  71. hr = ClientUtil::GetGlobalProfileProperties(lpMAPISup, &sProfileProps);
  72. if(hr != hrSuccess)
  73. return hr;
  74. // Create a transport for this provider
  75. hr = WSTransport::Create(ulFlags, &~lpTransport);
  76. if(hr != hrSuccess)
  77. return hr;
  78. // Log on the transport to the server
  79. hr = lpTransport->HrLogon(sProfileProps);
  80. if(hr != hrSuccess)
  81. return hr;
  82. hr = ECABLogon::Create(lpMAPISup, lpTransport, sProfileProps.ulProfileFlags, (GUID *)lpGuid, &~lpABLogon);
  83. if(hr != hrSuccess)
  84. return hr;
  85. AddChild(lpABLogon);
  86. hr = lpABLogon->QueryInterface(IID_IABLogon, (void **)lppABLogon);
  87. if(hr != hrSuccess)
  88. return hr;
  89. if (lpulcbSecurity)
  90. *lpulcbSecurity = 0;
  91. if (lppbSecurity)
  92. *lppbSecurity = NULL;
  93. if (lppMAPIError)
  94. *lppMAPIError = NULL;
  95. return hrSuccess;
  96. }
  97. DEF_HRMETHOD1(TRACE_MAPI, ECABProvider, ABProvider, QueryInterface, (REFIID, refiid), (void **, lppInterface))
  98. DEF_ULONGMETHOD1(TRACE_MAPI, ECABProvider, ABProvider, AddRef, (void))
  99. DEF_ULONGMETHOD1(TRACE_MAPI, ECABProvider, ABProvider, Release, (void))
  100. DEF_HRMETHOD1(TRACE_MAPI, ECABProvider, ABProvider, Shutdown, (ULONG *, lpulFlags))
  101. DEF_HRMETHOD1(TRACE_MAPI, ECABProvider, ABProvider, Logon, (LPMAPISUP, lpMAPISup), (ULONG, ulUIParam), (LPTSTR, lpszProfileName), (ULONG, ulFlags), (ULONG *, lpulcbSecurity), (LPBYTE *, lppbSecurity), (LPMAPIERROR *, lppMAPIError), (LPABLOGON *, lppABLogon))