Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.2 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: csession.hxx
  7. //
  8. // Contents: Microsoft OleDB/OleDS Session Object for ADSI
  9. //
  10. //
  11. // History: 08-01-96 shanksh Created.
  12. //
  13. //----------------------------------------------------------------------------
  14. #ifndef _CSESSION_HXX
  15. #define _CSESSION_HXX
  16. class CessionObject;
  17. class CSessionObject : INHERIT_TRACKING,
  18. public IGetDataSource,
  19. public IOpenRowset,
  20. public ISessionProperties,
  21. #if (!defined(BUILD_FOR_NT40))
  22. public IDBCreateCommand,
  23. public IBindResource
  24. #else
  25. public IDBCreateCommand
  26. #endif
  27. {
  28. private:
  29. LPUNKNOWN _pUnkOuter;
  30. //
  31. // No. of active commands
  32. //
  33. DWORD _cCommandsOpen;
  34. //
  35. // Utility object to manage properties
  36. //
  37. PCUTILPROP _pUtilProp;
  38. //
  39. // parent data source object
  40. //
  41. PCDSOObject _pDSO;
  42. IDirectorySearch * _pDSSearch;
  43. //
  44. // Credentials from the Data Source
  45. //
  46. CCredentials _Credentials;
  47. IMalloc * _pIMalloc;
  48. STDMETHODIMP
  49. GetDefaultColumnInfo(
  50. ULONG * pcColumns,
  51. DBCOLUMNINFO ** prgInfo,
  52. OLECHAR ** ppStringBuffer
  53. );
  54. STDMETHODIMP
  55. SetSearchPrefs(
  56. void
  57. );
  58. public:
  59. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR* ppvObj) ;
  60. DECLARE_STD_REFCOUNTING
  61. DECLARE_IGetDataSource_METHODS
  62. DECLARE_IOpenRowset_METHODS
  63. DECLARE_ISessionProperties_METHODS
  64. DECLARE_IDBCreateCommand_METHODS
  65. #if (!defined(BUILD_FOR_NT40))
  66. //IBindResource methods
  67. STDMETHODIMP Bind (
  68. IUnknown * punkOuter,
  69. LPCOLESTR pwszURL,
  70. DBBINDURLFLAG dwBindFlags,
  71. REFGUID rguid,
  72. REFIID riid,
  73. IAuthenticate * pAuthenticate,
  74. DBIMPLICITSESSION * pImplSession,
  75. DWORD * pdwBindStatus,
  76. IUnknown ** ppUnk
  77. );
  78. #endif
  79. inline void DecrementOpenCommands()
  80. {
  81. InterlockedDecrement( (LONG*) &_cCommandsOpen );
  82. }
  83. inline void IncrementOpenCommands()
  84. {
  85. InterlockedIncrement( (LONG*) &_cCommandsOpen );
  86. }
  87. inline BOOL IsCommandOpen()
  88. { return (_cCommandsOpen > 0) ? TRUE : FALSE;};
  89. inline HANDLE GetThreadToken()
  90. {
  91. return _pDSO->GetThreadToken();
  92. }
  93. inline BOOL IsIntegratedSecurity()
  94. {
  95. return _pDSO->IsIntegratedSecurity();
  96. }
  97. inline HRESULT SetUserName(LPWSTR lpszUserName)
  98. {
  99. return _Credentials.SetUserName(lpszUserName);
  100. }
  101. inline HRESULT SetPassword(LPWSTR lpszPassword)
  102. {
  103. return _Credentials.SetPassword(lpszPassword);
  104. }
  105. inline void SetAuthFlag(DWORD dwAuthFlag)
  106. {
  107. _Credentials.SetAuthFlags(dwAuthFlag);
  108. }
  109. CSessionObject::CSessionObject(LPUNKNOWN pUnkOuter);
  110. CSessionObject::~CSessionObject();
  111. BOOL FInit(CDSOObject *pDSO, CCredentials& Credentials );
  112. //Wrapper around IOpenRowset::OpenRowset for binding with
  113. //IAuthenticate information using IBindResource::Bind.
  114. HRESULT OpenRowsetWithCredentials (
  115. IUnknown * pUnkOuter,
  116. DBID * pTableID,
  117. DBID * pIndexID,
  118. REFIID riid,
  119. ULONG cPropertySets,
  120. DBPROPSET rgPropertySets[],
  121. CCredentials* pCredentials,
  122. IUnknown ** ppRowset
  123. );
  124. #if (!defined(BUILD_FOR_NT40))
  125. //Helper function for validating arguments of IBindResource::Bind
  126. HRESULT ValidateBindArgs(
  127. IUnknown * punkOuter,
  128. LPCOLESTR pwszURL,
  129. DBBINDURLFLAG dwBindFlags,
  130. REFGUID rguid,
  131. REFIID riid,
  132. IAuthenticate * pAuthenticate,
  133. DBIMPLICITSESSION * pImplSession,
  134. DWORD * pdwBindStatus,
  135. IUnknown ** ppUnk
  136. );
  137. //Helper Function for direct binding to a row
  138. HRESULT BindToRow(IUnknown *, LPCOLESTR, IAuthenticate *,
  139. DWORD, REFIID, IUnknown**);
  140. //Helper Function for direct binding to a rowset
  141. HRESULT BindToRowset(IUnknown*, LPCOLESTR, IAuthenticate *,
  142. DWORD, REFIID, IUnknown**);
  143. //Helper function to get Bind flags from init properties
  144. DWORD BindFlagsFromDbProps();
  145. //Helper function for direct binding to DataSource
  146. HRESULT BindToDataSource(IUnknown*, LPCOLESTR, IAuthenticate*,
  147. DWORD, REFIID, IUnknown**);
  148. //Helper function for building Absolute URL from Relative URL
  149. HRESULT BuildAbsoluteURL(CComBSTR, CComBSTR&);
  150. //Helper function to find out if a URL is absolute.
  151. //This just checks if the URL starts with one of the
  152. //allowed prefixes: LDAP,WINNT,NDS or NWCOMPAT
  153. bool bIsAbsoluteURL(LPCOLESTR);
  154. #endif
  155. };
  156. #endif