Leaked source code of windows server 2003
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.

167 lines
3.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: query.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "pch.h"
  11. #include <SnapBase.h>
  12. #include "query.h"
  13. #include "editor.h"
  14. #ifdef DEBUG_ALLOCATOR
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. #endif
  21. ///////////////////////////////////////////////////////////////////////////////
  22. CADSIQueryObject::CADSIQueryObject()
  23. {
  24. m_bInitialized = FALSE;
  25. m_pwszFilter = NULL;
  26. m_pObj = NULL;
  27. m_SearchHandle = NULL;
  28. aSearchPref = NULL;
  29. }
  30. CADSIQueryObject::~CADSIQueryObject()
  31. {
  32. if (m_SearchHandle)
  33. {
  34. m_pObj->CloseSearchHandle (m_SearchHandle);
  35. }
  36. if (aSearchPref != NULL)
  37. {
  38. delete aSearchPref;
  39. aSearchPref = NULL;
  40. }
  41. }
  42. HRESULT CADSIQueryObject::Init(IDirectorySearch * pObj)
  43. {
  44. HRESULT hr = S_OK;
  45. m_pObj = pObj;
  46. m_bInitialized = TRUE;
  47. return hr;
  48. }
  49. HRESULT CADSIQueryObject::Init(CString ObjPath, CCredentialObject* pCredObject)
  50. {
  51. HRESULT hr, hCredResult;
  52. hr = OpenObjectWithCredentials(
  53. pCredObject,
  54. ObjPath,
  55. IID_IDirectorySearch,
  56. (LPVOID*) &m_pObj
  57. );
  58. if (SUCCEEDED(hr))
  59. {
  60. m_bInitialized = TRUE;
  61. }
  62. else
  63. {
  64. m_bInitialized = FALSE;
  65. m_pObj = NULL;
  66. }
  67. return hr;
  68. }
  69. HRESULT CADSIQueryObject::SetAttributeList (LPTSTR *pszAttribs, INT cAttrs)
  70. {
  71. m_pszAttribs = pszAttribs;
  72. m_nAttrs = cAttrs;
  73. return S_OK;
  74. }
  75. const int nSearchPrefs = 4;
  76. HRESULT CADSIQueryObject::SetSearchPrefs (ADS_SCOPEENUM scope, ULONG nMaxObjectCount)
  77. {
  78. HRESULT hr;
  79. int nNumPrefs = nSearchPrefs;
  80. if (nMaxObjectCount == 0)
  81. {
  82. nNumPrefs--;
  83. }
  84. aSearchPref = new ADS_SEARCHPREF_INFO[nNumPrefs];
  85. if (m_bInitialized)
  86. {
  87. aSearchPref[0].dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE;
  88. aSearchPref[0].vValue.dwType = ADSTYPE_INTEGER;
  89. aSearchPref[0].vValue.Integer = scope;
  90. aSearchPref[1].dwSearchPref = ADS_SEARCHPREF_ASYNCHRONOUS;
  91. aSearchPref[1].vValue.dwType = ADSTYPE_BOOLEAN;
  92. aSearchPref[1].vValue.Boolean = TRUE;
  93. aSearchPref[2].dwSearchPref = ADS_SEARCHPREF_PAGESIZE;
  94. aSearchPref[2].vValue.dwType = ADSTYPE_INTEGER;
  95. aSearchPref[2].vValue.Integer = QUERY_PAGESIZE;
  96. if (nMaxObjectCount > 0)
  97. {
  98. aSearchPref[3].dwSearchPref = ADS_SEARCHPREF_SIZE_LIMIT;
  99. aSearchPref[3].vValue.dwType = ADSTYPE_INTEGER;
  100. aSearchPref[3].vValue.Integer = nMaxObjectCount;
  101. }
  102. hr = m_pObj->SetSearchPreference (aSearchPref, nNumPrefs);
  103. delete aSearchPref;
  104. aSearchPref = NULL;
  105. }
  106. else
  107. {
  108. hr = E_ADS_BAD_PATHNAME;
  109. }
  110. return hr;
  111. }
  112. const int NUM_PREFS=3;
  113. HRESULT CADSIQueryObject::DoQuery()
  114. {
  115. HRESULT hr;
  116. if (m_bInitialized)
  117. {
  118. hr = m_pObj->ExecuteSearch (m_pwszFilter,
  119. m_pszAttribs,
  120. m_nAttrs,
  121. &m_SearchHandle);
  122. }
  123. else
  124. {
  125. hr = E_ADS_BAD_PATHNAME;
  126. }
  127. return hr;
  128. }
  129. HRESULT CADSIQueryObject::GetNextRow()
  130. {
  131. if (m_bInitialized)
  132. {
  133. return m_pObj->GetNextRow (m_SearchHandle);
  134. }
  135. return E_ADS_BAD_PATHNAME;
  136. }
  137. HRESULT CADSIQueryObject::GetColumn(LPWSTR Attribute, PADS_SEARCH_COLUMN pColumnData)
  138. {
  139. if (m_bInitialized)
  140. {
  141. return m_pObj->GetColumn (m_SearchHandle,
  142. Attribute,
  143. pColumnData);
  144. }
  145. return E_ADS_BAD_PATHNAME;
  146. }