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.

2097 lines
56 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. hArray.cpp
  7. Index manager for wins db
  8. FILE HISTORY:
  9. Oct 13 1997 EricDav Created
  10. */
  11. #include "stdafx.h"
  12. #include "wins.h"
  13. #include "memmngr.h"
  14. #include "harray.h"
  15. #include "mbstring.h"
  16. #include "vrfysrv.h"
  17. // the lstrcmpA fucntion converts the dbcs string to Unicode using the ACP
  18. // and then does a string compare. So, we need to do the OEMCP conversion
  19. // and then call the string compare ourselves.
  20. int
  21. lstrcmpOEM(
  22. LPCSTR lpString1,
  23. LPCSTR lpString2
  24. )
  25. {
  26. CString str1, str2;
  27. MBCSToWide((LPSTR) lpString1, str1, WINS_NAME_CODE_PAGE);
  28. MBCSToWide((LPSTR) lpString2, str2, WINS_NAME_CODE_PAGE);
  29. return lstrcmp(str1, str2);
  30. }
  31. /*!--------------------------------------------------------------------------
  32. Class CHRowIndex
  33. ---------------------------------------------------------------------------*/
  34. CHRowIndex::CHRowIndex(INDEX_TYPE IndexType)
  35. : m_dbType(IndexType), m_bAscending(TRUE)
  36. {
  37. }
  38. CHRowIndex::~CHRowIndex()
  39. {
  40. }
  41. /*!--------------------------------------------------------------------------
  42. CHRowIndex::GetType
  43. -
  44. Author: EricDav
  45. ---------------------------------------------------------------------------*/
  46. HRESULT
  47. CHRowIndex::GetType(INDEX_TYPE * pIndexType)
  48. {
  49. if (pIndexType)
  50. *pIndexType = m_dbType;
  51. return hrOK;
  52. }
  53. /*!--------------------------------------------------------------------------
  54. CHRowIndex::SetArray
  55. -
  56. Author: EricDav
  57. ---------------------------------------------------------------------------*/
  58. HRESULT
  59. CHRowIndex::SetArray(HRowArray & hrowArray)
  60. {
  61. m_hrowArray.Copy(hrowArray);
  62. return hrOK;
  63. }
  64. /*!--------------------------------------------------------------------------
  65. CHRowIndex::GetHRow
  66. -
  67. Author: EricDav
  68. ---------------------------------------------------------------------------*/
  69. HROW
  70. CHRowIndex::GetHRow(int nIndex)
  71. {
  72. Assert(nIndex >= 0);
  73. Assert(nIndex <= m_hrowArray.GetSize());
  74. if (nIndex < 0 ||
  75. nIndex >= m_hrowArray.GetSize())
  76. {
  77. return NULL;
  78. }
  79. return m_hrowArray.GetAt(nIndex);
  80. }
  81. /*!--------------------------------------------------------------------------
  82. CHRowIndex::GetIndex
  83. -
  84. Author: EricDav
  85. ---------------------------------------------------------------------------*/
  86. int
  87. CHRowIndex::GetIndex(HROW hrow)
  88. {
  89. Assert(hrow != 0);
  90. LPHROW phrow = (LPHROW) BSearch((const void *)&hrow,
  91. (const void *)m_hrowArray.GetData(),
  92. (size_t) m_hrowArray.GetSize(),
  93. (size_t) sizeof(HROW));
  94. int nIndex = (int) (phrow - (LPHROW) m_hrowArray.GetData());
  95. Assert(nIndex >= 0);
  96. Assert(nIndex <= m_hrowArray.GetSize());
  97. int nComp, nIndexTemp;
  98. nComp = BCompare(&hrow, phrow);
  99. if (nComp == 0)
  100. {
  101. // found the right one, check the previous one to return the first
  102. // record in a list of duplicates
  103. nIndexTemp = nIndex;
  104. while (nIndexTemp && nComp == 0)
  105. {
  106. *phrow = (HROW) m_hrowArray.GetAt(--nIndexTemp);
  107. nComp = BCompare(&hrow, phrow);
  108. }
  109. if (nIndexTemp == nIndex)
  110. return nIndex; // nIndex should be zero here as well
  111. else
  112. if (nComp == 0)
  113. return nIndexTemp; // nIndexTemp should be 0 in this case
  114. else
  115. return nIndexTemp++;
  116. }
  117. return -1;
  118. }
  119. /*!--------------------------------------------------------------------------
  120. CHRowIndex::Add
  121. -
  122. Author: EricDav
  123. ---------------------------------------------------------------------------*/
  124. HRESULT
  125. CHRowIndex::Add(HROW hrow, BOOL bEnd)
  126. {
  127. // if we are loading the array then just stick this on the end
  128. if (bEnd)
  129. {
  130. m_hrowArray.Add(hrow);
  131. }
  132. else
  133. {
  134. if (m_hrowArray.GetSize() == 0)
  135. {
  136. m_hrowArray.Add(hrow);
  137. }
  138. else
  139. {
  140. LPHROW phrow = (LPHROW) BSearch((const void *)&hrow,
  141. (const void *)m_hrowArray.GetData(),
  142. (size_t) m_hrowArray.GetSize(),
  143. (size_t) sizeof(HROW));
  144. int nIndex = (int) (phrow - (LPHROW) m_hrowArray.GetData());
  145. Assert(nIndex >= 0);
  146. Assert(nIndex <= m_hrowArray.GetSize());
  147. int nComp;
  148. if (m_bAscending)
  149. nComp = BCompare(&hrow, phrow);
  150. else
  151. nComp = BCompareD(&hrow, phrow);
  152. if (nComp < 0)
  153. {
  154. // Insert before phrow
  155. m_hrowArray.InsertAt(nIndex, hrow);
  156. }
  157. else
  158. {
  159. // insert after phrow
  160. m_hrowArray.InsertAt(nIndex + 1, hrow);
  161. }
  162. }
  163. }
  164. return hrOK;
  165. }
  166. /*!--------------------------------------------------------------------------
  167. CHRowIndex::Remove
  168. -
  169. Author: EricDav
  170. ---------------------------------------------------------------------------*/
  171. HRESULT
  172. CHRowIndex::Remove(HROW hrow)
  173. {
  174. // do a bsearch for the record and then remove
  175. LPHROW phrow = (LPHROW) BSearch((const void*)&hrow,
  176. (const void*)m_hrowArray.GetData(),
  177. (size_t)m_hrowArray.GetSize(),
  178. (size_t)sizeof(HROW));
  179. // make sure the record is in the database, may not be if we aren't
  180. // filtering
  181. if (phrow)
  182. {
  183. int nComp = BCompare(&hrow, phrow);
  184. Assert(nComp == 0);
  185. if (nComp != 0)
  186. return E_FAIL;
  187. // calculate the index
  188. int nIndex = (int) (phrow - (LPHROW) m_hrowArray.GetData());
  189. Assert(nIndex >= 0);
  190. Assert(nIndex <= m_hrowArray.GetSize());
  191. m_hrowArray.RemoveAt((int) nIndex);
  192. }
  193. return hrOK;
  194. }
  195. /*!--------------------------------------------------------------------------
  196. CHRowIndex::BSearch
  197. Modified bsearch which returns the closest or equal element in
  198. an array
  199. Author: EricDav
  200. ---------------------------------------------------------------------------*/
  201. void *
  202. CHRowIndex::BSearch (const void *key,
  203. const void *base,
  204. size_t num,
  205. size_t width)
  206. {
  207. char *lo = (char *)base;
  208. char *hi = (char *)base + (num - 1) * width;
  209. char *mid = NULL;
  210. unsigned int half = 0;
  211. int result = 0;
  212. while (lo <= hi)
  213. if (half = num / 2)
  214. {
  215. mid = lo + (num & 1 ? half : (half - 1)) * width;
  216. if (m_bAscending)
  217. {
  218. if (!(result = BCompare(key,mid)))
  219. return(mid);
  220. else if (result < 0)
  221. {
  222. hi = mid - width;
  223. num = num & 1 ? half : half-1;
  224. }
  225. else
  226. {
  227. lo = mid + width;
  228. num = half;
  229. }
  230. }
  231. else
  232. {
  233. if (!(result = BCompareD(key,mid)))
  234. return(mid);
  235. else if (result < 0)
  236. {
  237. hi = mid - width;
  238. num = num & 1 ? half : half-1;
  239. }
  240. else
  241. {
  242. lo = mid + width;
  243. num = half;
  244. }
  245. }
  246. }
  247. else if (num)
  248. return(lo);
  249. else
  250. break;
  251. return(mid);
  252. }
  253. /*!--------------------------------------------------------------------------
  254. Class CIndexMgr
  255. ---------------------------------------------------------------------------*/
  256. CIndexMgr::CIndexMgr()
  257. {
  258. m_posCurrentIndex = NULL;
  259. m_posFilteredIndex = NULL;
  260. m_posLastIndex = NULL;
  261. m_posUpdatedIndex = NULL;
  262. m_bFiltered = FALSE;
  263. }
  264. CIndexMgr::~CIndexMgr()
  265. {
  266. Reset();
  267. }
  268. /*!--------------------------------------------------------------------------
  269. CIndexMgr::Initialize
  270. -
  271. Author: EricDav
  272. ---------------------------------------------------------------------------*/
  273. HRESULT
  274. CIndexMgr::Initialize()
  275. {
  276. HRESULT hr = hrOK;
  277. CSingleLock cl(&m_cs);
  278. cl.Lock();
  279. COM_PROTECT_TRY
  280. {
  281. // cleanup
  282. Reset();
  283. // Create one index, the named index
  284. CIndexName * pName = new CIndexName();
  285. m_posCurrentIndex = m_listIndicies.AddTail((CHRowIndex *) pName);
  286. m_posUpdatedIndex = m_posCurrentIndex;
  287. // this will be the current index, we need the Named Index also
  288. // for the total count
  289. CFilteredIndexName *pFilteredName = new CFilteredIndexName() ;
  290. m_posFilteredIndex = m_listFilteredIndices.AddTail((CHRowIndex *) pFilteredName);
  291. }
  292. COM_PROTECT_CATCH
  293. return hr;
  294. }
  295. /*!--------------------------------------------------------------------------
  296. CIndexMgr::Reset
  297. -
  298. Author: EricDav
  299. ---------------------------------------------------------------------------*/
  300. HRESULT
  301. CIndexMgr::Reset()
  302. {
  303. CSingleLock cl(&m_cs);
  304. cl.Lock();
  305. while (m_listIndicies.GetCount() > 0)
  306. {
  307. delete m_listIndicies.RemoveHead();
  308. }
  309. while(m_listFilteredIndices.GetCount() > 0 )
  310. {
  311. delete m_listFilteredIndices.RemoveHead();
  312. }
  313. return hrOK;
  314. }
  315. /*!--------------------------------------------------------------------------
  316. CIndexMgr::GetTotalCount
  317. The index sorted by name contains the total database and should
  318. always be available. Use this for the total count.
  319. Author: EricDav
  320. ---------------------------------------------------------------------------*/
  321. UINT
  322. CIndexMgr::GetTotalCount()
  323. {
  324. CSingleLock cl(&m_cs);
  325. cl.Lock();
  326. CHRowIndex * pIndex = GetNameIndex();
  327. if (pIndex == NULL)
  328. return 0;
  329. return (UINT)pIndex->GetArray().GetSize();
  330. }
  331. /*!--------------------------------------------------------------------------
  332. CIndexMgr::GetCurrentCount
  333. The current count may differ depending upon if the current Index
  334. is a filtered index.
  335. Author: EricDav
  336. ---------------------------------------------------------------------------*/
  337. UINT
  338. CIndexMgr::GetCurrentCount()
  339. {
  340. CSingleLock cl(&m_cs);
  341. cl.Lock();
  342. CHRowIndex * pIndex ;
  343. if (!m_bFiltered)
  344. pIndex = m_listIndicies.GetAt(m_posUpdatedIndex);
  345. else
  346. pIndex = m_listFilteredIndices.GetAt(m_posUpdatedIndex);
  347. if (pIndex == NULL)
  348. return 0;
  349. return (UINT)pIndex->GetArray().GetSize();
  350. }
  351. /*!--------------------------------------------------------------------------
  352. CIndexMgr::AddHRow
  353. -
  354. Author: EricDav
  355. ---------------------------------------------------------------------------*/
  356. HRESULT
  357. CIndexMgr::AddHRow(HROW hrow, BOOL bEnd, BOOL bFilterChecked)
  358. {
  359. CSingleLock cl(&m_cs);
  360. cl.Lock();
  361. INDEX_TYPE indexType;
  362. HRESULT hr = hrOK;
  363. POSITION pos = m_listIndicies.GetHeadPosition();
  364. COM_PROTECT_TRY
  365. {
  366. while (pos)
  367. {
  368. CHRowIndex * pIndex = m_listIndicies.GetNext(pos);
  369. // check the INDEX type of the HRowIndex,
  370. // if filtered, need to add, depending on
  371. // whether the filter holds good
  372. pIndex->GetType(&indexType);
  373. if (indexType != INDEX_TYPE_FILTER)
  374. pIndex->Add(hrow, bEnd);
  375. }
  376. pos = m_listFilteredIndices.GetHeadPosition();
  377. while(pos)
  378. {
  379. CHRowIndex * pIndex = m_listFilteredIndices.GetNext(pos);
  380. pIndex->GetType(&indexType);
  381. if (indexType != INDEX_TYPE_FILTER)
  382. break;
  383. BOOL bCheck = bFilterChecked ?
  384. TRUE :
  385. ((CFilteredIndexName*)pIndex)->CheckForFilter(&hrow);
  386. if (bCheck)
  387. pIndex->Add(hrow, bEnd);
  388. }
  389. }
  390. COM_PROTECT_CATCH
  391. return hr;
  392. }
  393. /*!--------------------------------------------------------------------------
  394. CIndexMgr::AcceptHRow
  395. -
  396. Author: FlorinT
  397. ---------------------------------------------------------------------------*/
  398. BOOL
  399. CIndexMgr::AcceptWinsRecord(WinsRecord *pWinsRecord)
  400. {
  401. CSingleLock cl(&m_cs);
  402. cl.Lock();
  403. POSITION pos = m_listFilteredIndices.GetHeadPosition();
  404. while(pos)
  405. {
  406. CHRowIndex *pIndex = m_listFilteredIndices.GetNext(pos);
  407. INDEX_TYPE indexType;
  408. pIndex->GetType(&indexType);
  409. if (indexType != INDEX_TYPE_FILTER)
  410. break;
  411. if (((CFilteredIndexName*)pIndex)->CheckWinsRecordForFilter(pWinsRecord))
  412. return TRUE;
  413. }
  414. return FALSE;
  415. }
  416. /*!--------------------------------------------------------------------------
  417. CIndexMgr::RemoveHRow
  418. -
  419. Author: EricDav
  420. ---------------------------------------------------------------------------*/
  421. HRESULT
  422. CIndexMgr::RemoveHRow(HROW hrow)
  423. {
  424. CSingleLock cl(&m_cs);
  425. cl.Lock();
  426. HRESULT hr = hrOK;
  427. POSITION pos = m_listIndicies.GetHeadPosition();
  428. COM_PROTECT_TRY
  429. {
  430. // remove from the normal list
  431. while (pos)
  432. {
  433. CHRowIndex * pIndex = m_listIndicies.GetNext(pos);
  434. pIndex->Remove(hrow);
  435. }
  436. // now remove from the filtered list
  437. pos = m_listFilteredIndices.GetHeadPosition();
  438. while (pos)
  439. {
  440. CHRowIndex * pIndex = m_listFilteredIndices.GetNext(pos);
  441. pIndex->Remove(hrow);
  442. }
  443. }
  444. COM_PROTECT_CATCH
  445. return hr;
  446. }
  447. /*!--------------------------------------------------------------------------
  448. CIndexMgr::Sort
  449. -
  450. Author: EricDav
  451. ---------------------------------------------------------------------------*/
  452. HRESULT
  453. CIndexMgr::Sort(WINSDB_SORT_TYPE SortType, DWORD dwSortOptions)
  454. {
  455. CSingleLock cl(&m_cs);
  456. cl.Lock();
  457. HRESULT hr = hrOK;
  458. CHRowIndex * pNameIndex;
  459. CHRowIndex * pNewIndex;
  460. POSITION pos;
  461. INDEX_TYPE indexType;
  462. BOOL bAscending = (dwSortOptions & WINSDB_SORT_ASCENDING) ? TRUE : FALSE;
  463. if (!m_bFiltered)
  464. {
  465. // check to see if we have an index for this.
  466. pos = m_listIndicies.GetHeadPosition();
  467. while (pos)
  468. {
  469. POSITION posTemp = pos;
  470. CHRowIndex * pIndex = m_listIndicies.GetNext(pos);
  471. pIndex->GetType(&indexType);
  472. if (indexType == SortType)
  473. {
  474. if (pIndex->IsAscending() != bAscending)
  475. {
  476. pIndex->SetAscending(bAscending);
  477. pIndex->Sort();
  478. }
  479. m_posCurrentIndex = posTemp;
  480. m_posUpdatedIndex = m_posCurrentIndex;
  481. // m_posLastIndex = m_posCurrentIndex;
  482. return hrOK;
  483. }
  484. }
  485. }
  486. // to save memory, remove all old indicies, except the name index
  487. CleanupIndicies();
  488. // if not, create one
  489. switch (SortType)
  490. {
  491. case INDEX_TYPE_NAME:
  492. pNewIndex = new CIndexName();
  493. break;
  494. case INDEX_TYPE_IP:
  495. pNewIndex = new CIndexIpAddr();
  496. break;
  497. case INDEX_TYPE_VERSION:
  498. pNewIndex = new CIndexVersion();
  499. break;
  500. case INDEX_TYPE_TYPE:
  501. pNewIndex = new CIndexType();
  502. break;
  503. case INDEX_TYPE_EXPIRATION:
  504. pNewIndex = new CIndexExpiration();
  505. break;
  506. case INDEX_TYPE_STATE:
  507. pNewIndex = new CIndexState();
  508. break;
  509. case INDEX_TYPE_STATIC:
  510. pNewIndex = new CIndexStatic();
  511. break;
  512. case INDEX_TYPE_OWNER:
  513. pNewIndex = new CIndexOwner();
  514. break;
  515. case INDEX_TYPE_FILTER:
  516. //pNewIndex = new CIndexFilter();
  517. break;
  518. default:
  519. Panic1("Invalid sort type passed to IndexMgr::Sort %d\n", SortType);
  520. break;
  521. }
  522. Assert(pNewIndex);
  523. if (!m_bFiltered)
  524. pNameIndex = GetNameIndex();
  525. else
  526. pNameIndex = GetFilteredNameIndex();
  527. Assert(pNameIndex);
  528. // copy the array from the named index
  529. pNewIndex->SetArray(pNameIndex->GetArray());
  530. pNewIndex->SetAscending(bAscending);
  531. pNewIndex->Sort();
  532. if (!m_bFiltered)
  533. {
  534. m_posCurrentIndex = m_listIndicies.AddTail(pNewIndex);
  535. m_posUpdatedIndex = m_posCurrentIndex;
  536. }
  537. else
  538. {
  539. POSITION posTemp = m_posFilteredIndex = m_listFilteredIndices.AddTail(pNewIndex);
  540. m_posUpdatedIndex = posTemp;// m_posFilteredIndex;
  541. }
  542. Assert(m_posCurrentIndex);
  543. return hr;
  544. }
  545. /*!--------------------------------------------------------------------------
  546. CIndexMgr::GetNameIndex
  547. -
  548. Author: EricDav
  549. ---------------------------------------------------------------------------*/
  550. CHRowIndex *
  551. CIndexMgr::GetNameIndex()
  552. {
  553. CSingleLock cl(&m_cs);
  554. cl.Lock();
  555. INDEX_TYPE indexType;
  556. POSITION pos = m_listIndicies.GetHeadPosition();
  557. while (pos)
  558. {
  559. CHRowIndex * pIndex = m_listIndicies.GetNext(pos);
  560. pIndex->GetType(&indexType);
  561. if (indexType == INDEX_TYPE_NAME)
  562. return pIndex;
  563. }
  564. return NULL;
  565. }
  566. /*!--------------------------------------------------------------------------
  567. CIndexMgr::GetFilteredNameIndex
  568. -
  569. Author: EricDav
  570. ---------------------------------------------------------------------------*/
  571. CHRowIndex *
  572. CIndexMgr::GetFilteredNameIndex()
  573. {
  574. CSingleLock cl(&m_cs);
  575. cl.Lock();
  576. INDEX_TYPE indexType;
  577. POSITION pos = m_listFilteredIndices.GetHeadPosition();
  578. while (pos)
  579. {
  580. CHRowIndex * pIndex = m_listFilteredIndices.GetNext(pos);
  581. pIndex->GetType(&indexType);
  582. if (indexType == INDEX_TYPE_FILTER)
  583. return pIndex;
  584. }
  585. return NULL;
  586. }
  587. /*!--------------------------------------------------------------------------
  588. CIndexMgr::CleanupIndicies
  589. Removes all indicies except the name index, and a filtered view
  590. Author: EricDav
  591. ---------------------------------------------------------------------------*/
  592. void
  593. CIndexMgr::CleanupIndicies()
  594. {
  595. CSingleLock cl(&m_cs);
  596. cl.Lock();
  597. INDEX_TYPE indexType;
  598. // clean up the non-filtered indicies
  599. POSITION pos = m_listIndicies.GetHeadPosition();
  600. while (pos)
  601. {
  602. POSITION posLast = pos;
  603. CHRowIndex * pIndex = m_listIndicies.GetNext(pos);
  604. pIndex->GetType(&indexType);
  605. if (indexType == INDEX_TYPE_NAME ||
  606. indexType == INDEX_TYPE_FILTER)
  607. continue;
  608. m_listIndicies.RemoveAt(posLast);
  609. delete pIndex;
  610. }
  611. // now clean up the filtered indicies
  612. pos = m_listFilteredIndices.GetHeadPosition();
  613. // delete all except the first one which is the filetered
  614. // name index
  615. //CHRowIndex * pIndex = m_listFilteredIndices.GetNext(pos);
  616. while (pos)
  617. {
  618. POSITION posLast = pos;
  619. CHRowIndex * pIndex = m_listFilteredIndices.GetNext(pos);
  620. pIndex->GetType(&indexType);
  621. if (indexType == INDEX_TYPE_NAME ||
  622. indexType == INDEX_TYPE_FILTER)
  623. continue;
  624. m_listFilteredIndices.RemoveAt(posLast);
  625. delete pIndex;
  626. }
  627. }
  628. /*!--------------------------------------------------------------------------
  629. CIndexMgr::GetHRow
  630. Returns an hrow based on an index into the current sorted list
  631. Author: EricDav
  632. ---------------------------------------------------------------------------*/
  633. HRESULT
  634. CIndexMgr::GetHRow(int nIndex, LPHROW phrow)
  635. {
  636. CSingleLock cl(&m_cs);
  637. cl.Lock();
  638. Assert(m_posCurrentIndex != NULL);
  639. //CHRowIndex * pIndex = m_listIndicies.GetAt(m_posCurrentIndex);
  640. CHRowIndex * pIndex;
  641. if (!m_bFiltered)
  642. pIndex = m_listIndicies.GetAt(m_posUpdatedIndex);
  643. else
  644. pIndex = m_listFilteredIndices.GetAt(m_posFilteredIndex);
  645. Assert(pIndex);
  646. if (phrow)
  647. *phrow = pIndex->GetHRow(nIndex);
  648. return hrOK;
  649. }
  650. /*!--------------------------------------------------------------------------
  651. CIndexMgr::GetIndex
  652. Returns the index of an hrow from the current sorted list
  653. Author: EricDav
  654. ---------------------------------------------------------------------------*/
  655. HRESULT
  656. CIndexMgr::GetIndex(HROW hrow, int * pIndex)
  657. {
  658. CSingleLock cl(&m_cs);
  659. cl.Lock();
  660. Assert(m_posCurrentIndex != NULL);
  661. //CHRowIndex * pCurrentIndex = m_listIndicies.GetAt(m_posCurrentIndex);
  662. CHRowIndex * pCurrentIndex;
  663. if (!m_bFiltered)
  664. pCurrentIndex = m_listIndicies.GetAt(m_posUpdatedIndex);
  665. else
  666. pCurrentIndex = m_listFilteredIndices.GetAt(m_posFilteredIndex);
  667. Assert(pCurrentIndex);
  668. if (pIndex)
  669. *pIndex = pCurrentIndex->GetIndex(hrow);
  670. return hrOK;
  671. }
  672. HRESULT
  673. CIndexMgr::Filter(WINSDB_FILTER_TYPE FilterType, DWORD dwParam1, DWORD dwParam2)
  674. {
  675. CSingleLock cl(&m_cs);
  676. cl.Lock();
  677. HRESULT hr = hrOK;
  678. CHRowIndex* pNameIndex;
  679. CHRowIndex* pNewIndex;
  680. POSITION pos;
  681. INDEX_TYPE indexType;
  682. UINT uCount;
  683. UINT i;
  684. BOOL bCheck = FALSE;
  685. HROW hrow;
  686. HRowArray hrowArray;
  687. pNewIndex = GetFilteredNameIndex();
  688. Assert(pNewIndex);
  689. // clear the filtered name index first.
  690. pNewIndex->SetArray(hrowArray);
  691. pNameIndex = GetNameIndex();
  692. Assert(pNameIndex);
  693. // do the filtering here.
  694. uCount = GetTotalCount();
  695. for(i = 0; i< uCount; i++)
  696. {
  697. hrow = pNameIndex->GetHRow(i);
  698. if (hrow)
  699. bCheck = ((CFilteredIndexName *)pNewIndex)->CheckForFilter(&hrow);
  700. if (bCheck)
  701. pNewIndex->Add(hrow, TRUE);
  702. }
  703. // check to see if the filtered view has been sorted on something else besides
  704. // the name. If so, switch back the index to the named index because
  705. // otherwise we will need to resort which can be time consuming...
  706. if (m_listFilteredIndices.GetAt(m_posFilteredIndex) != pNewIndex)
  707. {
  708. m_posFilteredIndex = m_listFilteredIndices.Find(pNewIndex);
  709. }
  710. // get the current position of the filtered index in the list of indices
  711. m_posUpdatedIndex = m_posFilteredIndex;
  712. Assert(m_posUpdatedIndex);
  713. m_bFiltered = TRUE;
  714. return hr;
  715. }
  716. HRESULT
  717. CIndexMgr::AddFilter(WINSDB_FILTER_TYPE FilterType, DWORD dwParam1, DWORD dwParam2, LPCOLESTR strParam3)
  718. {
  719. CSingleLock cl(&m_cs);
  720. cl.Lock();
  721. HRESULT hr = hrOK;
  722. CFilteredIndexName *pFilterName = (CFilteredIndexName *)GetFilteredNameIndex();
  723. pFilterName->AddFilter(FilterType, dwParam1, dwParam2, strParam3);
  724. m_bFiltered = TRUE;
  725. return hr;
  726. }
  727. HRESULT
  728. CIndexMgr::ClearFilter(WINSDB_FILTER_TYPE FilterType)
  729. {
  730. CSingleLock cl(&m_cs);
  731. cl.Lock();
  732. HRESULT hr = hrOK;
  733. CFilteredIndexName *pFilterName = (CFilteredIndexName *)GetFilteredNameIndex();
  734. pFilterName->ClearFilter(FilterType);
  735. m_bFiltered = FALSE;
  736. // m_posCurrentIndex = m_posLastIndex;
  737. return hr;
  738. }
  739. HRESULT
  740. CIndexMgr::SetActiveView(WINSDB_VIEW_TYPE ViewType)
  741. {
  742. CSingleLock cl(&m_cs);
  743. cl.Lock();
  744. HRESULT hr = hrOK;
  745. switch(ViewType)
  746. {
  747. case WINSDB_VIEW_FILTERED_DATABASE:
  748. m_bFiltered = TRUE;
  749. //m_posCurrentIndex = m_posFilteredIndex;
  750. m_posUpdatedIndex = m_posFilteredIndex;
  751. break;
  752. case WINSDB_VIEW_ENTIRE_DATABASE:
  753. m_bFiltered = FALSE;
  754. //m_posCurrentIndex = m_posLastIndex;
  755. m_posUpdatedIndex = m_posCurrentIndex;
  756. break;
  757. default:
  758. break;
  759. }
  760. return hr;
  761. }
  762. /*!--------------------------------------------------------------------------
  763. Class CIndexName
  764. ---------------------------------------------------------------------------*/
  765. /*!--------------------------------------------------------------------------
  766. CIndexName::BCompare
  767. -
  768. Author: EricDav
  769. ---------------------------------------------------------------------------*/
  770. int
  771. CIndexName::BCompare(const void * elem1, const void * elem2)
  772. {
  773. LPHROW phrow1 = (LPHROW) elem1;
  774. LPHROW phrow2 = (LPHROW) elem2;
  775. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  776. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  777. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  778. (LPCSTR) &pRec1->szRecordName[0];
  779. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  780. (LPCSTR) &pRec2->szRecordName[0];
  781. return lstrcmpOEM(puChar1, puChar2);
  782. }
  783. int
  784. CIndexName::BCompareD(const void *elem1, const void *elem2)
  785. {
  786. return -BCompare(elem1, elem2);
  787. }
  788. /*!--------------------------------------------------------------------------
  789. CIndexName::Sort
  790. -
  791. Author: EricDav
  792. ---------------------------------------------------------------------------*/
  793. HRESULT
  794. CIndexName::Sort()
  795. {
  796. if (m_bAscending)
  797. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  798. else
  799. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  800. return hrOK;
  801. }
  802. /*!--------------------------------------------------------------------------
  803. CIndexName::QCompare
  804. -
  805. Author: EricDav
  806. ---------------------------------------------------------------------------*/
  807. int __cdecl
  808. CIndexName::QCompareA(const void * elem1, const void * elem2)
  809. {
  810. LPHROW phrow1 = (LPHROW) elem1;
  811. LPHROW phrow2 = (LPHROW) elem2;
  812. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  813. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  814. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  815. (LPCSTR) &pRec1->szRecordName[0];
  816. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  817. (LPCSTR) &pRec2->szRecordName[0];
  818. return lstrcmpOEM(puChar1, puChar2);
  819. }
  820. int __cdecl
  821. CIndexName::QCompareD(const void * elem1, const void * elem2)
  822. {
  823. return -QCompareA(elem1, elem2);
  824. }
  825. /*!--------------------------------------------------------------------------
  826. Class CIndexType
  827. ---------------------------------------------------------------------------*/
  828. /*!--------------------------------------------------------------------------
  829. CIndexType::BCompare
  830. -
  831. Author: EricDav
  832. ---------------------------------------------------------------------------*/
  833. int
  834. CIndexType::BCompare(const void * elem1, const void * elem2)
  835. {
  836. LPHROW phrow1 = (LPHROW) elem1;
  837. LPHROW phrow2 = (LPHROW) elem2;
  838. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  839. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  840. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  841. (LPCSTR) &pRec1->szRecordName[0];
  842. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  843. (LPCSTR) &pRec2->szRecordName[0];
  844. if ((unsigned char) puChar1[15] > (unsigned char) puChar2[15])
  845. return 1;
  846. else
  847. if ((unsigned char) puChar1[15] < (unsigned char) puChar2[15])
  848. return -1;
  849. else
  850. return lstrcmpOEM(puChar1, puChar2);
  851. }
  852. int
  853. CIndexType::BCompareD(const void *elem1, const void *elem2)
  854. {
  855. return -BCompare(elem1, elem2);
  856. }
  857. /*!--------------------------------------------------------------------------
  858. CIndexType::Sort
  859. -
  860. Author: EricDav
  861. ---------------------------------------------------------------------------*/
  862. HRESULT
  863. CIndexType::Sort()
  864. {
  865. if (m_bAscending)
  866. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  867. else
  868. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  869. return hrOK;
  870. }
  871. /*!--------------------------------------------------------------------------
  872. CIndexType::QCompare
  873. -
  874. Author: EricDav
  875. ---------------------------------------------------------------------------*/
  876. int __cdecl
  877. CIndexType::QCompareA(const void * elem1, const void * elem2)
  878. {
  879. LPHROW phrow1 = (LPHROW) elem1;
  880. LPHROW phrow2 = (LPHROW) elem2;
  881. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  882. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  883. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  884. (LPCSTR) &pRec1->szRecordName[0];
  885. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  886. (LPCSTR) &pRec2->szRecordName[0];
  887. DWORD dwAddr1, dwAddr2;
  888. if (pRec1->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  889. {
  890. // if this record has multiple addresses, we want the 2nd
  891. // address, because the 1st address is always the WINS server
  892. // first dword is the count.
  893. LPDWORD pdwIpAddrs = (LPDWORD) pRec1->dwIpAdd;
  894. dwAddr1 = pdwIpAddrs[2];
  895. }
  896. else
  897. {
  898. dwAddr1 = (DWORD) pRec1->dwIpAdd;
  899. }
  900. if (pRec2->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  901. {
  902. // if this record has multiple addresses, we want the 2nd
  903. // address, because the 1st address is always the WINS server
  904. // first dword is the count.
  905. LPDWORD pdwIpAddrs = (LPDWORD) pRec2->dwIpAdd;
  906. dwAddr2 = pdwIpAddrs[2];
  907. }
  908. else
  909. {
  910. dwAddr2 = (DWORD) pRec2->dwIpAdd;
  911. }
  912. // check the types first. If they are the same, sort by IP address.
  913. // if for some reason the IP addresses are the same then sort by name.
  914. if ((unsigned char) puChar1[15] > (unsigned char) puChar2[15])
  915. return 1;
  916. else
  917. if ((unsigned char) puChar1[15] < (unsigned char) puChar2[15])
  918. return -1;
  919. else
  920. if (dwAddr1 > dwAddr2)
  921. return 1;
  922. else
  923. if (dwAddr1 < dwAddr2)
  924. return -1;
  925. else
  926. return lstrcmpOEM(puChar1, puChar2);
  927. }
  928. int __cdecl
  929. CIndexType::QCompareD(const void * elem1, const void * elem2)
  930. {
  931. return -QCompareA(elem1, elem2);
  932. }
  933. /*!--------------------------------------------------------------------------
  934. Class CIndexIpAddr
  935. ---------------------------------------------------------------------------*/
  936. /*!--------------------------------------------------------------------------
  937. CIndexIpAddr::BCompare
  938. -
  939. Author: EricDav
  940. ---------------------------------------------------------------------------*/
  941. int
  942. CIndexIpAddr::BCompare(const void * elem1, const void * elem2)
  943. {
  944. LPHROW phrow1 = (LPHROW) elem1;
  945. LPHROW phrow2 = (LPHROW) elem2;
  946. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  947. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  948. DWORD dwAddr1, dwAddr2;
  949. if (pRec1->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  950. {
  951. // if this record has multiple addresses, we want the 2nd
  952. // address, because the 1st address is always the WINS server
  953. // first dword is the count.
  954. LPDWORD pdwIpAddrs = (LPDWORD) pRec1->dwIpAdd;
  955. dwAddr1 = pdwIpAddrs[2];
  956. }
  957. else
  958. {
  959. dwAddr1 = (DWORD) pRec1->dwIpAdd;
  960. }
  961. if (pRec2->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  962. {
  963. // if this record has multiple addresses, we want the 2nd
  964. // address, because the 1st address is always the WINS server
  965. // first dword is the count.
  966. LPDWORD pdwIpAddrs = (LPDWORD) pRec2->dwIpAdd;
  967. dwAddr2 = pdwIpAddrs[2];
  968. }
  969. else
  970. {
  971. dwAddr2 = (DWORD) pRec2->dwIpAdd;
  972. }
  973. if (dwAddr1 > dwAddr2)
  974. return 1;
  975. else
  976. if (dwAddr1 < dwAddr2)
  977. return -1;
  978. else
  979. {
  980. // if the addresses are the same, compare types, then names
  981. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  982. (LPCSTR) &pRec1->szRecordName[0];
  983. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  984. (LPCSTR) &pRec2->szRecordName[0];
  985. if ((unsigned char) puChar1[15] > (unsigned char) puChar2[15])
  986. return 1;
  987. else
  988. if ((unsigned char) puChar1[15] < (unsigned char) puChar2[15])
  989. return -1;
  990. else
  991. return lstrcmpOEM(puChar1, puChar2);
  992. }
  993. }
  994. int
  995. CIndexIpAddr::BCompareD(const void *elem1, const void *elem2)
  996. {
  997. return -BCompare(elem1, elem2);
  998. }
  999. /*!--------------------------------------------------------------------------
  1000. CIndexIpAddr::Sort
  1001. -
  1002. Author: EricDav
  1003. ---------------------------------------------------------------------------*/
  1004. HRESULT
  1005. CIndexIpAddr::Sort()
  1006. {
  1007. if (m_bAscending)
  1008. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1009. else
  1010. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1011. return hrOK;
  1012. }
  1013. /*!--------------------------------------------------------------------------
  1014. CIndexIpAddr::QCompare
  1015. -
  1016. Author: EricDav
  1017. ---------------------------------------------------------------------------*/
  1018. int __cdecl
  1019. CIndexIpAddr::QCompareA(const void * elem1, const void * elem2)
  1020. {
  1021. LPHROW phrow1 = (LPHROW) elem1;
  1022. LPHROW phrow2 = (LPHROW) elem2;
  1023. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1024. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1025. DWORD dwAddr1, dwAddr2;
  1026. if (pRec1->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  1027. {
  1028. // if this record has multiple addresses, we want the 2nd
  1029. // address, because the 1st address is always the WINS server
  1030. // first dword is the count.
  1031. LPDWORD pdwIpAddrs = (LPDWORD) pRec1->dwIpAdd;
  1032. dwAddr1 = pdwIpAddrs[2];
  1033. }
  1034. else
  1035. {
  1036. dwAddr1 = (DWORD) pRec1->dwIpAdd;
  1037. }
  1038. if (pRec2->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  1039. {
  1040. // if this record has multiple addresses, we want the 2nd
  1041. // address, because the 1st address is always the WINS server
  1042. // first dword is the count.
  1043. LPDWORD pdwIpAddrs = (LPDWORD) pRec2->dwIpAdd;
  1044. dwAddr2 = pdwIpAddrs[2];
  1045. }
  1046. else
  1047. {
  1048. dwAddr2 = (DWORD) pRec2->dwIpAdd;
  1049. }
  1050. if (dwAddr1 > dwAddr2)
  1051. return 1;
  1052. else
  1053. if (dwAddr1 < dwAddr2)
  1054. return -1;
  1055. else
  1056. {
  1057. // if the addresses are the same, compare types, then names
  1058. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1059. (LPCSTR) &pRec1->szRecordName[0];
  1060. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1061. (LPCSTR) &pRec2->szRecordName[0];
  1062. if ((unsigned char) puChar1[15] > (unsigned char) puChar2[15])
  1063. return 1;
  1064. else
  1065. if ((unsigned char) puChar1[15] < (unsigned char) puChar2[15])
  1066. return -1;
  1067. else
  1068. return lstrcmpOEM(puChar1, puChar2);
  1069. }
  1070. }
  1071. int __cdecl
  1072. CIndexIpAddr::QCompareD(const void * elem1, const void * elem2)
  1073. {
  1074. return -QCompareA(elem1, elem2);
  1075. }
  1076. /*!--------------------------------------------------------------------------
  1077. Class CIndexVersion
  1078. ---------------------------------------------------------------------------*/
  1079. /*!--------------------------------------------------------------------------
  1080. CIndexVersion::BCompare
  1081. -
  1082. Author: EricDav
  1083. ---------------------------------------------------------------------------*/
  1084. int
  1085. CIndexVersion::BCompare(const void * elem1, const void * elem2)
  1086. {
  1087. LPHROW phrow1 = (LPHROW) elem1;
  1088. LPHROW phrow2 = (LPHROW) elem2;
  1089. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1090. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1091. if (pRec1->liVersion.QuadPart > pRec2->liVersion.QuadPart)
  1092. return 1;
  1093. else
  1094. if (pRec1->liVersion.QuadPart < pRec2->liVersion.QuadPart)
  1095. return -1;
  1096. else
  1097. return 0;
  1098. }
  1099. int
  1100. CIndexVersion::BCompareD(const void *elem1, const void *elem2)
  1101. {
  1102. return -BCompare(elem1, elem2);
  1103. }
  1104. /*!--------------------------------------------------------------------------
  1105. CIndexVersion::Sort
  1106. -
  1107. Author: EricDav
  1108. ---------------------------------------------------------------------------*/
  1109. HRESULT
  1110. CIndexVersion::Sort()
  1111. {
  1112. if (m_bAscending)
  1113. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1114. else
  1115. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1116. return hrOK;
  1117. }
  1118. /*!--------------------------------------------------------------------------
  1119. CIndexVersion::QCompare
  1120. -
  1121. Author: EricDav
  1122. ---------------------------------------------------------------------------*/
  1123. int __cdecl
  1124. CIndexVersion::QCompareA(const void * elem1, const void * elem2)
  1125. {
  1126. LPHROW phrow1 = (LPHROW) elem1;
  1127. LPHROW phrow2 = (LPHROW) elem2;
  1128. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1129. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1130. if (pRec1->liVersion.QuadPart > pRec2->liVersion.QuadPart)
  1131. return 1;
  1132. else
  1133. if (pRec1->liVersion.QuadPart < pRec2->liVersion.QuadPart)
  1134. return -1;
  1135. else
  1136. return 0;
  1137. }
  1138. int __cdecl
  1139. CIndexVersion::QCompareD(const void * elem1, const void * elem2)
  1140. {
  1141. return -QCompareA(elem1, elem2);
  1142. }
  1143. /*!--------------------------------------------------------------------------
  1144. Class CIndexExpiration
  1145. ---------------------------------------------------------------------------*/
  1146. /*!--------------------------------------------------------------------------
  1147. CIndexExpiration::BCompare
  1148. -
  1149. Author: EricDav
  1150. ---------------------------------------------------------------------------*/
  1151. int
  1152. CIndexExpiration::BCompare(const void * elem1, const void * elem2)
  1153. {
  1154. LPHROW phrow1 = (LPHROW) elem1;
  1155. LPHROW phrow2 = (LPHROW) elem2;
  1156. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1157. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1158. if (pRec1->dwExpiration > pRec2->dwExpiration)
  1159. return 1;
  1160. else
  1161. if (pRec1->dwExpiration < pRec2->dwExpiration)
  1162. return -1;
  1163. else
  1164. return 0;
  1165. }
  1166. int
  1167. CIndexExpiration::BCompareD(const void *elem1, const void *elem2)
  1168. {
  1169. return -BCompare(elem1, elem2);
  1170. }
  1171. /*!--------------------------------------------------------------------------
  1172. CIndexExpiration::Sort
  1173. -
  1174. Author: EricDav
  1175. ---------------------------------------------------------------------------*/
  1176. HRESULT
  1177. CIndexExpiration::Sort()
  1178. {
  1179. if (m_bAscending)
  1180. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1181. else
  1182. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1183. return hrOK;
  1184. }
  1185. /*!--------------------------------------------------------------------------
  1186. CIndexExpiration::QCompare
  1187. -
  1188. Author: EricDav
  1189. ---------------------------------------------------------------------------*/
  1190. int __cdecl
  1191. CIndexExpiration::QCompareA(const void * elem1, const void * elem2)
  1192. {
  1193. LPHROW phrow1 = (LPHROW) elem1;
  1194. LPHROW phrow2 = (LPHROW) elem2;
  1195. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1196. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1197. if (pRec1->dwExpiration > pRec2->dwExpiration)
  1198. return 1;
  1199. else
  1200. if (pRec1->dwExpiration < pRec2->dwExpiration)
  1201. return -1;
  1202. else
  1203. return 0;
  1204. }
  1205. int __cdecl
  1206. CIndexExpiration::QCompareD(const void * elem1, const void * elem2)
  1207. {
  1208. return -QCompareA(elem1, elem2);
  1209. }
  1210. /*!--------------------------------------------------------------------------
  1211. Class CIndexState
  1212. ---------------------------------------------------------------------------*/
  1213. /*!--------------------------------------------------------------------------
  1214. CIndexState::BCompare
  1215. -
  1216. Author: EricDav
  1217. ---------------------------------------------------------------------------*/
  1218. int
  1219. CIndexState::BCompare(const void * elem1, const void * elem2)
  1220. {
  1221. LPHROW phrow1 = (LPHROW) elem1;
  1222. LPHROW phrow2 = (LPHROW) elem2;
  1223. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1224. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1225. int nPri1 = 0, nPri2 = 0;
  1226. // calculate relative priorities
  1227. if (pRec1->szRecordName[18] & WINSDB_REC_ACTIVE)
  1228. nPri1 = 0;
  1229. else
  1230. if (pRec1->szRecordName[18] & WINSDB_REC_RELEASED)
  1231. nPri1 = 1;
  1232. else
  1233. if (pRec1->szRecordName[18] & WINSDB_REC_TOMBSTONE)
  1234. nPri1 = 2;
  1235. else
  1236. if (pRec1->szRecordName[18] & WINSDB_REC_DELETED)
  1237. nPri1 = 3;
  1238. // now for record 2
  1239. if (pRec2->szRecordName[18] & WINSDB_REC_ACTIVE)
  1240. nPri2 = 0;
  1241. else
  1242. if (pRec2->szRecordName[18] & WINSDB_REC_RELEASED)
  1243. nPri2 = 1;
  1244. else
  1245. if (pRec2->szRecordName[18] & WINSDB_REC_TOMBSTONE)
  1246. nPri2 = 2;
  1247. else
  1248. if (pRec2->szRecordName[18] & WINSDB_REC_DELETED)
  1249. nPri2 = 3;
  1250. if (nPri1 > nPri2)
  1251. return 1;
  1252. else
  1253. if (nPri1 < nPri2)
  1254. return -1;
  1255. else
  1256. {
  1257. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1258. (LPCSTR) &pRec1->szRecordName[0];
  1259. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1260. (LPCSTR) &pRec2->szRecordName[0];
  1261. return lstrcmpOEM(puChar1, puChar2);
  1262. }
  1263. }
  1264. int
  1265. CIndexState::BCompareD(const void *elem1, const void *elem2)
  1266. {
  1267. return -BCompare(elem1, elem2);
  1268. }
  1269. /*!--------------------------------------------------------------------------
  1270. CIndexState::Sort
  1271. -
  1272. Author: EricDav
  1273. ---------------------------------------------------------------------------*/
  1274. HRESULT
  1275. CIndexState::Sort()
  1276. {
  1277. if (m_bAscending)
  1278. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1279. else
  1280. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1281. return hrOK;
  1282. }
  1283. /*!--------------------------------------------------------------------------
  1284. CIndexState::QCompare
  1285. -
  1286. Author: EricDav
  1287. ---------------------------------------------------------------------------*/
  1288. int __cdecl
  1289. CIndexState::QCompareA(const void * elem1, const void * elem2)
  1290. {
  1291. LPHROW phrow1 = (LPHROW) elem1;
  1292. LPHROW phrow2 = (LPHROW) elem2;
  1293. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1294. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1295. int nPri1 = 0, nPri2 = 0;
  1296. // calculate relative priorities
  1297. if (pRec1->szRecordName[18] & WINSDB_REC_ACTIVE)
  1298. nPri1 = 0;
  1299. else
  1300. if (pRec1->szRecordName[18] & WINSDB_REC_RELEASED)
  1301. nPri1 = 1;
  1302. else
  1303. if (pRec1->szRecordName[18] & WINSDB_REC_TOMBSTONE)
  1304. nPri1 = 2;
  1305. else
  1306. if (pRec1->szRecordName[18] & WINSDB_REC_DELETED)
  1307. nPri1 = 3;
  1308. // now for record 2
  1309. if (pRec2->szRecordName[18] & WINSDB_REC_ACTIVE)
  1310. nPri2 = 0;
  1311. else
  1312. if (pRec2->szRecordName[18] & WINSDB_REC_RELEASED)
  1313. nPri2 = 1;
  1314. else
  1315. if (pRec2->szRecordName[18] & WINSDB_REC_TOMBSTONE)
  1316. nPri2 = 2;
  1317. else
  1318. if (pRec2->szRecordName[18] & WINSDB_REC_DELETED)
  1319. nPri2 = 3;
  1320. if (nPri1 > nPri2)
  1321. return 1;
  1322. else
  1323. if (nPri1 < nPri2)
  1324. return -1;
  1325. else
  1326. {
  1327. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1328. (LPCSTR) &pRec1->szRecordName[0];
  1329. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1330. (LPCSTR) &pRec2->szRecordName[0];
  1331. return lstrcmpOEM(puChar1, puChar2);
  1332. }
  1333. }
  1334. int __cdecl
  1335. CIndexState::QCompareD(const void * elem1, const void * elem2)
  1336. {
  1337. return -QCompareA(elem1, elem2);
  1338. }
  1339. /*!--------------------------------------------------------------------------
  1340. Class CIndexStatic
  1341. ---------------------------------------------------------------------------*/
  1342. /*!--------------------------------------------------------------------------
  1343. CIndexStatic::BCompare
  1344. -
  1345. Author: EricDav
  1346. ---------------------------------------------------------------------------*/
  1347. int
  1348. CIndexStatic::BCompare(const void * elem1, const void * elem2)
  1349. {
  1350. LPHROW phrow1 = (LPHROW) elem1;
  1351. LPHROW phrow2 = (LPHROW) elem2;
  1352. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1353. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1354. BOOL bStatic1 = pRec1->szRecordName[18] & LOBYTE(LOWORD(WINSDB_REC_STATIC));
  1355. BOOL bStatic2 = pRec2->szRecordName[18] & LOBYTE(LOWORD(WINSDB_REC_STATIC));
  1356. if (bStatic1 && !bStatic2)
  1357. return 1;
  1358. else
  1359. if (!bStatic1 && bStatic2)
  1360. return -1;
  1361. else
  1362. {
  1363. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1364. (LPCSTR) &pRec1->szRecordName[0];
  1365. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1366. (LPCSTR) &pRec2->szRecordName[0];
  1367. return lstrcmpOEM(puChar1, puChar2);
  1368. }
  1369. }
  1370. int
  1371. CIndexStatic::BCompareD(const void *elem1, const void *elem2)
  1372. {
  1373. return -BCompare(elem1, elem2);
  1374. }
  1375. /*!--------------------------------------------------------------------------
  1376. CIndexStatic::Sort
  1377. -
  1378. Author: EricDav
  1379. ---------------------------------------------------------------------------*/
  1380. HRESULT
  1381. CIndexStatic::Sort()
  1382. {
  1383. if (m_bAscending)
  1384. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1385. else
  1386. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1387. return hrOK;
  1388. }
  1389. /*!--------------------------------------------------------------------------
  1390. CIndexStatic::QCompare
  1391. -
  1392. Author: EricDav
  1393. ---------------------------------------------------------------------------*/
  1394. int __cdecl
  1395. CIndexStatic::QCompareA(const void * elem1, const void * elem2)
  1396. {
  1397. LPHROW phrow1 = (LPHROW) elem1;
  1398. LPHROW phrow2 = (LPHROW) elem2;
  1399. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1400. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1401. BOOL bStatic1 = pRec1->szRecordName[18] & LOBYTE(LOWORD(WINSDB_REC_STATIC));
  1402. BOOL bStatic2 = pRec2->szRecordName[18] & LOBYTE(LOWORD(WINSDB_REC_STATIC));
  1403. if (bStatic1 && !bStatic2)
  1404. return 1;
  1405. else
  1406. if (!bStatic1 && bStatic2)
  1407. return -1;
  1408. else
  1409. {
  1410. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1411. (LPCSTR) &pRec1->szRecordName[0];
  1412. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1413. (LPCSTR) &pRec2->szRecordName[0];
  1414. return lstrcmpOEM(puChar1, puChar2);
  1415. }
  1416. }
  1417. int __cdecl
  1418. CIndexStatic::QCompareD(const void * elem1, const void * elem2)
  1419. {
  1420. return -QCompareA(elem1, elem2);
  1421. }
  1422. /*!--------------------------------------------------------------------------
  1423. Class CIndexOwner
  1424. ---------------------------------------------------------------------------*/
  1425. /*!--------------------------------------------------------------------------
  1426. CIndexOwner::BCompare
  1427. -
  1428. Author: EricDav
  1429. ---------------------------------------------------------------------------*/
  1430. int
  1431. CIndexOwner::BCompare(const void * elem1, const void * elem2)
  1432. {
  1433. LPHROW phrow1 = (LPHROW) elem1;
  1434. LPHROW phrow2 = (LPHROW) elem2;
  1435. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1436. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1437. if (pRec1->dwOwner > pRec2->dwOwner)
  1438. {
  1439. return 1;
  1440. }
  1441. else
  1442. if (pRec1->dwOwner < pRec2->dwOwner)
  1443. {
  1444. return -1;
  1445. }
  1446. else
  1447. {
  1448. // if the addresses are the same, compare names
  1449. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1450. (LPCSTR) &pRec1->szRecordName[0];
  1451. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1452. (LPCSTR) &pRec2->szRecordName[0];
  1453. return lstrcmpOEM(puChar1, puChar2);
  1454. }
  1455. }
  1456. int
  1457. CIndexOwner::BCompareD(const void *elem1, const void *elem2)
  1458. {
  1459. return -BCompare(elem1, elem2);
  1460. }
  1461. /*!--------------------------------------------------------------------------
  1462. CIndexStatic::Sort
  1463. -
  1464. Author: EricDav
  1465. ---------------------------------------------------------------------------*/
  1466. HRESULT
  1467. CIndexOwner::Sort()
  1468. {
  1469. if (m_bAscending)
  1470. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1471. else
  1472. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1473. return hrOK;
  1474. }
  1475. /*!--------------------------------------------------------------------------
  1476. CIndexStatic::QCompare
  1477. -
  1478. Author: EricDav
  1479. ---------------------------------------------------------------------------*/
  1480. int __cdecl
  1481. CIndexOwner::QCompareA(const void * elem1, const void * elem2)
  1482. {
  1483. LPHROW phrow1 = (LPHROW) elem1;
  1484. LPHROW phrow2 = (LPHROW) elem2;
  1485. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1486. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1487. if (pRec1->dwOwner > pRec2->dwOwner)
  1488. {
  1489. return 1;
  1490. }
  1491. else
  1492. if (pRec1->dwOwner < pRec2->dwOwner)
  1493. {
  1494. return -1;
  1495. }
  1496. else
  1497. {
  1498. // if the addresses are the same, compare names
  1499. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1500. (LPCSTR) &pRec1->szRecordName[0];
  1501. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1502. (LPCSTR) &pRec2->szRecordName[0];
  1503. return lstrcmpOEM(puChar1, puChar2);
  1504. }
  1505. }
  1506. int __cdecl
  1507. CIndexOwner::QCompareD(const void * elem1, const void * elem2)
  1508. {
  1509. return -QCompareA(elem1, elem2);
  1510. }
  1511. HRESULT CFilteredIndexName::AddFilter(WINSDB_FILTER_TYPE FilterType, DWORD dwData1, DWORD dwData2, LPCOLESTR strData3)
  1512. {
  1513. HRESULT hr = hrOK;
  1514. tIpReference ipRef;
  1515. switch (FilterType)
  1516. {
  1517. case WINSDB_FILTER_BY_TYPE:
  1518. m_mapFilterTypes.SetAt(dwData1, (BOOL&) dwData2);
  1519. break;
  1520. case WINSDB_FILTER_BY_OWNER:
  1521. m_dwaFilteredOwners.Add(dwData1);
  1522. break;
  1523. case WINSDB_FILTER_BY_IPADDR:
  1524. ipRef.Address = dwData1;
  1525. ipRef.Mask = dwData2;
  1526. m_taFilteredIp.Add(ipRef);
  1527. break;
  1528. case WINSDB_FILTER_BY_NAME:
  1529. UINT nData3Len;
  1530. nData3Len = (_tcslen(strData3)+1)*sizeof(TCHAR);
  1531. m_pchFilteredName = new char[nData3Len];
  1532. if (m_pchFilteredName != NULL)
  1533. {
  1534. #ifdef _UNICODE
  1535. if (WideCharToMultiByte(CP_OEMCP,
  1536. 0,
  1537. strData3,
  1538. -1,
  1539. m_pchFilteredName,
  1540. nData3Len,
  1541. NULL,
  1542. NULL) == 0)
  1543. {
  1544. delete m_pchFilteredName;
  1545. m_pchFilteredName = NULL;
  1546. }
  1547. #else
  1548. CharToOem(strData3, m_pchFilteredName);
  1549. #endif
  1550. //m_pchFilteredName = _strupr(m_pchFilteredName);
  1551. m_bMatchCase = dwData1;
  1552. }
  1553. break;
  1554. default:
  1555. Panic0("Invalid filter type passed to CFilteredIndexName::AddFilter");
  1556. break;
  1557. }
  1558. return hr;
  1559. }
  1560. BOOL CFilteredIndexName::CheckForFilter(LPHROW hrowCheck)
  1561. {
  1562. UINT nCountOwner = (UINT)m_dwaFilteredOwners.GetSize();
  1563. UINT nCountType = m_mapFilterTypes.GetHashTableSize();
  1564. UINT nCountIPAddrs = (UINT)m_taFilteredIp.GetSize();
  1565. BOOL bOwnerFilter = (nCountOwner == 0);
  1566. BOOL bTypeFilter = (nCountType == 0);
  1567. BOOL bIPAddrsFilter = (nCountIPAddrs == 0);
  1568. BOOL bNameFilter = (m_pchFilteredName == NULL);
  1569. LPWINSDBRECORD pRec = (LPWINSDBRECORD) *hrowCheck;
  1570. UINT i, j;
  1571. LPCSTR puChar;
  1572. for (i = 0; !bOwnerFilter && i < nCountOwner; i++)
  1573. {
  1574. if (pRec->dwOwner == m_dwaFilteredOwners.GetAt(i))
  1575. bOwnerFilter = TRUE;
  1576. }
  1577. if (!bOwnerFilter)
  1578. return FALSE;
  1579. puChar = (IS_DBREC_LONGNAME(pRec)) ?
  1580. (LPCSTR) *((char **) pRec->szRecordName) :
  1581. (LPCSTR) &pRec->szRecordName[0];
  1582. if (!bTypeFilter)
  1583. {
  1584. DWORD dwType = puChar[0xF];
  1585. if (!m_mapFilterTypes.Lookup(dwType, bTypeFilter))
  1586. {
  1587. // no entry for this name type. Check the FFFF name type (other) to see if we should
  1588. // show it.
  1589. dwType = 0xFFFF;
  1590. m_mapFilterTypes.Lookup(dwType, bTypeFilter);
  1591. }
  1592. }
  1593. if (!bTypeFilter)
  1594. return FALSE;
  1595. for (i = 0; !bIPAddrsFilter && i < nCountIPAddrs; i++)
  1596. {
  1597. if (pRec->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  1598. {
  1599. LPDWORD pdwIpAddrs = (LPDWORD) pRec->dwIpAdd;
  1600. for (j=0; !bIPAddrsFilter && j < pdwIpAddrs[0]; j+=2)
  1601. {
  1602. bIPAddrsFilter = SubnetMatching(m_taFilteredIp[i], pdwIpAddrs[j+2]);
  1603. }
  1604. }
  1605. else
  1606. {
  1607. bIPAddrsFilter = SubnetMatching(m_taFilteredIp[i], (DWORD)pRec->dwIpAdd);
  1608. }
  1609. }
  1610. if(!bIPAddrsFilter)
  1611. return FALSE;
  1612. if (!bNameFilter)
  1613. {
  1614. bNameFilter = (PatternMatching(puChar, m_pchFilteredName, 16) == NULL);
  1615. }
  1616. return bNameFilter;
  1617. }
  1618. BOOL CFilteredIndexName::CheckWinsRecordForFilter(WinsRecord *pWinsRecord)
  1619. {
  1620. UINT nCountOwner = (UINT)m_dwaFilteredOwners.GetSize();
  1621. UINT nCountType = m_mapFilterTypes.GetHashTableSize();
  1622. UINT nCountIPAddrs = (UINT)m_taFilteredIp.GetSize();
  1623. BOOL bOwnerFilter = (nCountOwner == 0);
  1624. BOOL bTypeFilter = (nCountType == 0);
  1625. BOOL bIPAddrsFilter = (nCountIPAddrs == 0);
  1626. BOOL bNameFilter = (m_pchFilteredName == NULL);
  1627. UINT i, j;
  1628. //-------------------------------------
  1629. // check the owner filter first, if any
  1630. for (i = 0; !bOwnerFilter && i < nCountOwner; i++)
  1631. {
  1632. if (pWinsRecord->dwOwner == m_dwaFilteredOwners.GetAt(i))
  1633. bOwnerFilter = TRUE;
  1634. }
  1635. if (!bOwnerFilter)
  1636. return FALSE;
  1637. //-------------------------------------
  1638. // check the type filter if any
  1639. if (!bTypeFilter)
  1640. {
  1641. if (!m_mapFilterTypes.Lookup(pWinsRecord->dwType, bTypeFilter))
  1642. {
  1643. // no entry for this name type. Check the FFFF name type (other) to see if we should
  1644. // show it.
  1645. DWORD dwType = 0xFFFF;
  1646. m_mapFilterTypes.Lookup(dwType, bTypeFilter);
  1647. }
  1648. }
  1649. if (!bTypeFilter)
  1650. return FALSE;
  1651. //-------------------------------------
  1652. // check the IP address filter if any
  1653. for (i = 0; !bIPAddrsFilter && i < nCountIPAddrs; i++)
  1654. {
  1655. if (pWinsRecord->dwState & WINSDB_REC_MULT_ADDRS)
  1656. {
  1657. for (j=0; !bIPAddrsFilter && j < pWinsRecord->dwNoOfAddrs; j++)
  1658. {
  1659. bIPAddrsFilter = SubnetMatching(m_taFilteredIp[i], pWinsRecord->dwIpAdd[j]);
  1660. }
  1661. }
  1662. else
  1663. {
  1664. bIPAddrsFilter = SubnetMatching(m_taFilteredIp[i], pWinsRecord->dwIpAdd[0]);
  1665. }
  1666. }
  1667. if(!bIPAddrsFilter)
  1668. return FALSE;
  1669. //-------------------------------------
  1670. // check the name filter if any
  1671. if (!bNameFilter)
  1672. {
  1673. bNameFilter = (PatternMatching(pWinsRecord->szRecordName, m_pchFilteredName, 16) == NULL);
  1674. }
  1675. return bNameFilter;
  1676. }
  1677. LPCSTR CFilteredIndexName::PatternMatching(LPCSTR pName, LPCSTR pPattern, INT nNameLen)
  1678. {
  1679. LPCSTR pNameBak = pName;
  1680. // it is guaranteed here we have a valid (not NULL) pattern
  1681. while (*pPattern != '\0' && pName-pNameBak < nNameLen)
  1682. {
  1683. BOOL bChMatch = (*pPattern == *pName);
  1684. if (!m_bMatchCase && !bChMatch)
  1685. {
  1686. bChMatch = (islower(*pPattern) && _toupper(*pPattern) == *pName) ||
  1687. (islower(*pName) && *pPattern == _toupper(*pName));
  1688. }
  1689. if (*pPattern == '?' || bChMatch)
  1690. {
  1691. pPattern++;
  1692. }
  1693. else if (*pPattern == '*')
  1694. {
  1695. LPCSTR pTrail = pName;
  1696. INT nTrailLen = nNameLen-(UINT)(pTrail-pNameBak);
  1697. pPattern++;
  1698. while ((pName = PatternMatching(pTrail, pPattern, nTrailLen)) != NULL)
  1699. {
  1700. pTrail++;
  1701. nTrailLen--;
  1702. if (*pTrail == '\0' || nTrailLen <= 0)
  1703. break;
  1704. }
  1705. return pName;
  1706. }
  1707. else if (!bChMatch)
  1708. {
  1709. // in the test above, note that even in the unikely case *pName == '\0'
  1710. // *pName will not match *pPattern so the loop is still broken - which is
  1711. // the desired behavior. In this case the pattern was not consummed
  1712. // and the name was, so the return will indicate the matching failed
  1713. break;
  1714. }
  1715. pName++;
  1716. }
  1717. return *pPattern == '\0' ? NULL : pName;
  1718. }
  1719. BOOL CFilteredIndexName::SubnetMatching(tIpReference &IpRefPattern, DWORD dwIPAddress)
  1720. {
  1721. DWORD dwMask;
  1722. return (IpRefPattern.Address & IpRefPattern.Mask) == (dwIPAddress & IpRefPattern.Mask);
  1723. }
  1724. HRESULT CFilteredIndexName::ClearFilter(WINSDB_FILTER_TYPE FilterType)
  1725. {
  1726. HRESULT hr = hrOK;
  1727. switch(FilterType)
  1728. {
  1729. case WINSDB_FILTER_BY_TYPE:
  1730. m_mapFilterTypes.RemoveAll();
  1731. break;
  1732. case WINSDB_FILTER_BY_OWNER:
  1733. m_dwaFilteredOwners.RemoveAll();
  1734. break;
  1735. case WINSDB_FILTER_BY_IPADDR:
  1736. m_taFilteredIp.RemoveAll();
  1737. break;
  1738. case WINSDB_FILTER_BY_NAME:
  1739. if (m_pchFilteredName != NULL)
  1740. {
  1741. delete m_pchFilteredName;
  1742. m_pchFilteredName = NULL;
  1743. }
  1744. break;
  1745. default:
  1746. Panic0("Invalid filter type passed to CFilteredIndexName::ClearFilter");
  1747. break;
  1748. }
  1749. return hr;
  1750. }