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.

2121 lines
59 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. COM_PROTECT_TRY
  489. {
  490. // if not, create one
  491. switch (SortType)
  492. {
  493. case INDEX_TYPE_NAME:
  494. pNewIndex = new CIndexName();
  495. break;
  496. case INDEX_TYPE_IP:
  497. pNewIndex = new CIndexIpAddr();
  498. break;
  499. case INDEX_TYPE_VERSION:
  500. pNewIndex = new CIndexVersion();
  501. break;
  502. case INDEX_TYPE_TYPE:
  503. pNewIndex = new CIndexType();
  504. break;
  505. case INDEX_TYPE_EXPIRATION:
  506. pNewIndex = new CIndexExpiration();
  507. break;
  508. case INDEX_TYPE_STATE:
  509. pNewIndex = new CIndexState();
  510. break;
  511. case INDEX_TYPE_STATIC:
  512. pNewIndex = new CIndexStatic();
  513. break;
  514. case INDEX_TYPE_OWNER:
  515. pNewIndex = new CIndexOwner();
  516. break;
  517. case INDEX_TYPE_FILTER:
  518. //pNewIndex = new CIndexFilter();
  519. break;
  520. default:
  521. Panic1("Invalid sort type passed to IndexMgr::Sort %d\n", SortType);
  522. break;
  523. }
  524. }
  525. COM_PROTECT_CATCH
  526. if (FHrSucceeded(hr))
  527. {
  528. Assert(pNewIndex);
  529. if (!m_bFiltered)
  530. pNameIndex = GetNameIndex();
  531. else
  532. pNameIndex = GetFilteredNameIndex();
  533. Assert(pNameIndex);
  534. COM_PROTECT_TRY
  535. {
  536. // copy the array from the named index
  537. pNewIndex->SetArray(pNameIndex->GetArray());
  538. }
  539. COM_PROTECT_CATCH
  540. }
  541. if (FHrSucceeded(hr))
  542. {
  543. pNewIndex->SetAscending(bAscending);
  544. pNewIndex->Sort();
  545. if (!m_bFiltered)
  546. {
  547. m_posCurrentIndex = m_listIndicies.AddTail(pNewIndex);
  548. m_posUpdatedIndex = m_posCurrentIndex;
  549. }
  550. else
  551. {
  552. POSITION posTemp = m_posFilteredIndex = m_listFilteredIndices.AddTail(pNewIndex);
  553. m_posUpdatedIndex = posTemp;// m_posFilteredIndex;
  554. }
  555. Assert(m_posCurrentIndex);
  556. }
  557. if (!FHrSucceeded(hr))
  558. {
  559. if (pNewIndex != NULL)
  560. delete pNewIndex;
  561. }
  562. return hr;
  563. }
  564. /*!--------------------------------------------------------------------------
  565. CIndexMgr::GetNameIndex
  566. -
  567. Author: EricDav
  568. ---------------------------------------------------------------------------*/
  569. CHRowIndex *
  570. CIndexMgr::GetNameIndex()
  571. {
  572. CSingleLock cl(&m_cs);
  573. cl.Lock();
  574. INDEX_TYPE indexType;
  575. POSITION pos = m_listIndicies.GetHeadPosition();
  576. while (pos)
  577. {
  578. CHRowIndex * pIndex = m_listIndicies.GetNext(pos);
  579. pIndex->GetType(&indexType);
  580. if (indexType == INDEX_TYPE_NAME)
  581. return pIndex;
  582. }
  583. return NULL;
  584. }
  585. /*!--------------------------------------------------------------------------
  586. CIndexMgr::GetFilteredNameIndex
  587. -
  588. Author: EricDav
  589. ---------------------------------------------------------------------------*/
  590. CHRowIndex *
  591. CIndexMgr::GetFilteredNameIndex()
  592. {
  593. CSingleLock cl(&m_cs);
  594. cl.Lock();
  595. INDEX_TYPE indexType;
  596. POSITION pos = m_listFilteredIndices.GetHeadPosition();
  597. while (pos)
  598. {
  599. CHRowIndex * pIndex = m_listFilteredIndices.GetNext(pos);
  600. pIndex->GetType(&indexType);
  601. if (indexType == INDEX_TYPE_FILTER)
  602. return pIndex;
  603. }
  604. return NULL;
  605. }
  606. /*!--------------------------------------------------------------------------
  607. CIndexMgr::CleanupIndicies
  608. Removes all indicies except the name index, and a filtered view
  609. Author: EricDav
  610. ---------------------------------------------------------------------------*/
  611. void
  612. CIndexMgr::CleanupIndicies()
  613. {
  614. CSingleLock cl(&m_cs);
  615. cl.Lock();
  616. INDEX_TYPE indexType;
  617. // clean up the non-filtered indicies
  618. POSITION pos = m_listIndicies.GetHeadPosition();
  619. while (pos)
  620. {
  621. POSITION posLast = pos;
  622. CHRowIndex * pIndex = m_listIndicies.GetNext(pos);
  623. pIndex->GetType(&indexType);
  624. if (indexType == INDEX_TYPE_NAME ||
  625. indexType == INDEX_TYPE_FILTER)
  626. continue;
  627. m_listIndicies.RemoveAt(posLast);
  628. delete pIndex;
  629. }
  630. // now clean up the filtered indicies
  631. pos = m_listFilteredIndices.GetHeadPosition();
  632. // delete all except the first one which is the filetered
  633. // name index
  634. //CHRowIndex * pIndex = m_listFilteredIndices.GetNext(pos);
  635. while (pos)
  636. {
  637. POSITION posLast = pos;
  638. CHRowIndex * pIndex = m_listFilteredIndices.GetNext(pos);
  639. pIndex->GetType(&indexType);
  640. if (indexType == INDEX_TYPE_NAME ||
  641. indexType == INDEX_TYPE_FILTER)
  642. continue;
  643. m_listFilteredIndices.RemoveAt(posLast);
  644. delete pIndex;
  645. }
  646. }
  647. /*!--------------------------------------------------------------------------
  648. CIndexMgr::GetHRow
  649. Returns an hrow based on an index into the current sorted list
  650. Author: EricDav
  651. ---------------------------------------------------------------------------*/
  652. HRESULT
  653. CIndexMgr::GetHRow(int nIndex, LPHROW phrow)
  654. {
  655. CSingleLock cl(&m_cs);
  656. cl.Lock();
  657. Assert(m_posCurrentIndex != NULL);
  658. //CHRowIndex * pIndex = m_listIndicies.GetAt(m_posCurrentIndex);
  659. CHRowIndex * pIndex;
  660. if (!m_bFiltered)
  661. pIndex = m_listIndicies.GetAt(m_posUpdatedIndex);
  662. else
  663. pIndex = m_listFilteredIndices.GetAt(m_posFilteredIndex);
  664. Assert(pIndex);
  665. if (phrow)
  666. *phrow = pIndex->GetHRow(nIndex);
  667. return hrOK;
  668. }
  669. /*!--------------------------------------------------------------------------
  670. CIndexMgr::GetIndex
  671. Returns the index of an hrow from the current sorted list
  672. Author: EricDav
  673. ---------------------------------------------------------------------------*/
  674. HRESULT
  675. CIndexMgr::GetIndex(HROW hrow, int * pIndex)
  676. {
  677. CSingleLock cl(&m_cs);
  678. cl.Lock();
  679. Assert(m_posCurrentIndex != NULL);
  680. //CHRowIndex * pCurrentIndex = m_listIndicies.GetAt(m_posCurrentIndex);
  681. CHRowIndex * pCurrentIndex;
  682. if (!m_bFiltered)
  683. pCurrentIndex = m_listIndicies.GetAt(m_posUpdatedIndex);
  684. else
  685. pCurrentIndex = m_listFilteredIndices.GetAt(m_posFilteredIndex);
  686. Assert(pCurrentIndex);
  687. if (pIndex)
  688. *pIndex = pCurrentIndex->GetIndex(hrow);
  689. return hrOK;
  690. }
  691. HRESULT
  692. CIndexMgr::Filter(WINSDB_FILTER_TYPE FilterType, DWORD dwParam1, DWORD dwParam2)
  693. {
  694. CSingleLock cl(&m_cs);
  695. cl.Lock();
  696. HRESULT hr = hrOK;
  697. CHRowIndex* pNameIndex;
  698. CHRowIndex* pNewIndex;
  699. POSITION pos;
  700. INDEX_TYPE indexType;
  701. UINT uCount;
  702. UINT i;
  703. BOOL bCheck = FALSE;
  704. HROW hrow;
  705. HRowArray hrowArray;
  706. pNewIndex = GetFilteredNameIndex();
  707. Assert(pNewIndex);
  708. // clear the filtered name index first.
  709. pNewIndex->SetArray(hrowArray);
  710. pNameIndex = GetNameIndex();
  711. Assert(pNameIndex);
  712. // do the filtering here.
  713. uCount = GetTotalCount();
  714. for(i = 0; i< uCount; i++)
  715. {
  716. hrow = pNameIndex->GetHRow(i);
  717. if (hrow)
  718. bCheck = ((CFilteredIndexName *)pNewIndex)->CheckForFilter(&hrow);
  719. if (bCheck)
  720. pNewIndex->Add(hrow, TRUE);
  721. }
  722. // check to see if the filtered view has been sorted on something else besides
  723. // the name. If so, switch back the index to the named index because
  724. // otherwise we will need to resort which can be time consuming...
  725. if (m_listFilteredIndices.GetAt(m_posFilteredIndex) != pNewIndex)
  726. {
  727. m_posFilteredIndex = m_listFilteredIndices.Find(pNewIndex);
  728. }
  729. // get the current position of the filtered index in the list of indices
  730. m_posUpdatedIndex = m_posFilteredIndex;
  731. Assert(m_posUpdatedIndex);
  732. m_bFiltered = TRUE;
  733. return hr;
  734. }
  735. HRESULT
  736. CIndexMgr::AddFilter(WINSDB_FILTER_TYPE FilterType, DWORD dwParam1, DWORD dwParam2, LPCOLESTR strParam3)
  737. {
  738. CSingleLock cl(&m_cs);
  739. cl.Lock();
  740. HRESULT hr = hrOK;
  741. CFilteredIndexName *pFilterName = (CFilteredIndexName *)GetFilteredNameIndex();
  742. pFilterName->AddFilter(FilterType, dwParam1, dwParam2, strParam3);
  743. m_bFiltered = TRUE;
  744. return hr;
  745. }
  746. HRESULT
  747. CIndexMgr::ClearFilter(WINSDB_FILTER_TYPE FilterType)
  748. {
  749. CSingleLock cl(&m_cs);
  750. cl.Lock();
  751. HRESULT hr = hrOK;
  752. CFilteredIndexName *pFilterName = (CFilteredIndexName *)GetFilteredNameIndex();
  753. pFilterName->ClearFilter(FilterType);
  754. m_bFiltered = FALSE;
  755. // m_posCurrentIndex = m_posLastIndex;
  756. return hr;
  757. }
  758. HRESULT
  759. CIndexMgr::SetActiveView(WINSDB_VIEW_TYPE ViewType)
  760. {
  761. CSingleLock cl(&m_cs);
  762. cl.Lock();
  763. HRESULT hr = hrOK;
  764. switch(ViewType)
  765. {
  766. case WINSDB_VIEW_FILTERED_DATABASE:
  767. m_bFiltered = TRUE;
  768. //m_posCurrentIndex = m_posFilteredIndex;
  769. m_posUpdatedIndex = m_posFilteredIndex;
  770. break;
  771. case WINSDB_VIEW_ENTIRE_DATABASE:
  772. m_bFiltered = FALSE;
  773. //m_posCurrentIndex = m_posLastIndex;
  774. m_posUpdatedIndex = m_posCurrentIndex;
  775. break;
  776. default:
  777. break;
  778. }
  779. return hr;
  780. }
  781. /*!--------------------------------------------------------------------------
  782. Class CIndexName
  783. ---------------------------------------------------------------------------*/
  784. /*!--------------------------------------------------------------------------
  785. CIndexName::BCompare
  786. -
  787. Author: EricDav
  788. ---------------------------------------------------------------------------*/
  789. int
  790. CIndexName::BCompare(const void * elem1, const void * elem2)
  791. {
  792. LPHROW phrow1 = (LPHROW) elem1;
  793. LPHROW phrow2 = (LPHROW) elem2;
  794. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  795. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  796. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  797. (LPCSTR) &pRec1->szRecordName[0];
  798. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  799. (LPCSTR) &pRec2->szRecordName[0];
  800. return lstrcmpOEM(puChar1, puChar2);
  801. }
  802. int
  803. CIndexName::BCompareD(const void *elem1, const void *elem2)
  804. {
  805. return -BCompare(elem1, elem2);
  806. }
  807. /*!--------------------------------------------------------------------------
  808. CIndexName::Sort
  809. -
  810. Author: EricDav
  811. ---------------------------------------------------------------------------*/
  812. HRESULT
  813. CIndexName::Sort()
  814. {
  815. if (m_bAscending)
  816. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  817. else
  818. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  819. return hrOK;
  820. }
  821. /*!--------------------------------------------------------------------------
  822. CIndexName::QCompare
  823. -
  824. Author: EricDav
  825. ---------------------------------------------------------------------------*/
  826. int __cdecl
  827. CIndexName::QCompareA(const void * elem1, const void * elem2)
  828. {
  829. LPHROW phrow1 = (LPHROW) elem1;
  830. LPHROW phrow2 = (LPHROW) elem2;
  831. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  832. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  833. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  834. (LPCSTR) &pRec1->szRecordName[0];
  835. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  836. (LPCSTR) &pRec2->szRecordName[0];
  837. return lstrcmpOEM(puChar1, puChar2);
  838. }
  839. int __cdecl
  840. CIndexName::QCompareD(const void * elem1, const void * elem2)
  841. {
  842. return -QCompareA(elem1, elem2);
  843. }
  844. /*!--------------------------------------------------------------------------
  845. Class CIndexType
  846. ---------------------------------------------------------------------------*/
  847. /*!--------------------------------------------------------------------------
  848. CIndexType::BCompare
  849. -
  850. Author: EricDav
  851. ---------------------------------------------------------------------------*/
  852. int
  853. CIndexType::BCompare(const void * elem1, const void * elem2)
  854. {
  855. LPHROW phrow1 = (LPHROW) elem1;
  856. LPHROW phrow2 = (LPHROW) elem2;
  857. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  858. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  859. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  860. (LPCSTR) &pRec1->szRecordName[0];
  861. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  862. (LPCSTR) &pRec2->szRecordName[0];
  863. if ((unsigned char) puChar1[15] > (unsigned char) puChar2[15])
  864. return 1;
  865. else
  866. if ((unsigned char) puChar1[15] < (unsigned char) puChar2[15])
  867. return -1;
  868. else
  869. return lstrcmpOEM(puChar1, puChar2);
  870. }
  871. int
  872. CIndexType::BCompareD(const void *elem1, const void *elem2)
  873. {
  874. return -BCompare(elem1, elem2);
  875. }
  876. /*!--------------------------------------------------------------------------
  877. CIndexType::Sort
  878. -
  879. Author: EricDav
  880. ---------------------------------------------------------------------------*/
  881. HRESULT
  882. CIndexType::Sort()
  883. {
  884. if (m_bAscending)
  885. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  886. else
  887. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  888. return hrOK;
  889. }
  890. /*!--------------------------------------------------------------------------
  891. CIndexType::QCompare
  892. -
  893. Author: EricDav
  894. ---------------------------------------------------------------------------*/
  895. int __cdecl
  896. CIndexType::QCompareA(const void * elem1, const void * elem2)
  897. {
  898. LPHROW phrow1 = (LPHROW) elem1;
  899. LPHROW phrow2 = (LPHROW) elem2;
  900. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  901. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  902. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  903. (LPCSTR) &pRec1->szRecordName[0];
  904. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  905. (LPCSTR) &pRec2->szRecordName[0];
  906. DWORD dwAddr1, dwAddr2;
  907. if (pRec1->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  908. {
  909. // if this record has multiple addresses, we want the 2nd
  910. // address, because the 1st address is always the WINS server
  911. // first dword is the count.
  912. LPDWORD pdwIpAddrs = (LPDWORD) pRec1->dwIpAdd;
  913. dwAddr1 = pdwIpAddrs[2];
  914. }
  915. else
  916. {
  917. dwAddr1 = (DWORD) pRec1->dwIpAdd;
  918. }
  919. if (pRec2->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  920. {
  921. // if this record has multiple addresses, we want the 2nd
  922. // address, because the 1st address is always the WINS server
  923. // first dword is the count.
  924. LPDWORD pdwIpAddrs = (LPDWORD) pRec2->dwIpAdd;
  925. dwAddr2 = pdwIpAddrs[2];
  926. }
  927. else
  928. {
  929. dwAddr2 = (DWORD) pRec2->dwIpAdd;
  930. }
  931. // check the types first. If they are the same, sort by IP address.
  932. // if for some reason the IP addresses are the same then sort by name.
  933. if ((unsigned char) puChar1[15] > (unsigned char) puChar2[15])
  934. return 1;
  935. else
  936. if ((unsigned char) puChar1[15] < (unsigned char) puChar2[15])
  937. return -1;
  938. else
  939. if (dwAddr1 > dwAddr2)
  940. return 1;
  941. else
  942. if (dwAddr1 < dwAddr2)
  943. return -1;
  944. else
  945. return lstrcmpOEM(puChar1, puChar2);
  946. }
  947. int __cdecl
  948. CIndexType::QCompareD(const void * elem1, const void * elem2)
  949. {
  950. return -QCompareA(elem1, elem2);
  951. }
  952. /*!--------------------------------------------------------------------------
  953. Class CIndexIpAddr
  954. ---------------------------------------------------------------------------*/
  955. /*!--------------------------------------------------------------------------
  956. CIndexIpAddr::BCompare
  957. -
  958. Author: EricDav
  959. ---------------------------------------------------------------------------*/
  960. int
  961. CIndexIpAddr::BCompare(const void * elem1, const void * elem2)
  962. {
  963. LPHROW phrow1 = (LPHROW) elem1;
  964. LPHROW phrow2 = (LPHROW) elem2;
  965. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  966. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  967. DWORD dwAddr1, dwAddr2;
  968. if (pRec1->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  969. {
  970. // if this record has multiple addresses, we want the 2nd
  971. // address, because the 1st address is always the WINS server
  972. // first dword is the count.
  973. LPDWORD pdwIpAddrs = (LPDWORD) pRec1->dwIpAdd;
  974. dwAddr1 = pdwIpAddrs[2];
  975. }
  976. else
  977. {
  978. dwAddr1 = (DWORD) pRec1->dwIpAdd;
  979. }
  980. if (pRec2->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  981. {
  982. // if this record has multiple addresses, we want the 2nd
  983. // address, because the 1st address is always the WINS server
  984. // first dword is the count.
  985. LPDWORD pdwIpAddrs = (LPDWORD) pRec2->dwIpAdd;
  986. dwAddr2 = pdwIpAddrs[2];
  987. }
  988. else
  989. {
  990. dwAddr2 = (DWORD) pRec2->dwIpAdd;
  991. }
  992. if (dwAddr1 > dwAddr2)
  993. return 1;
  994. else
  995. if (dwAddr1 < dwAddr2)
  996. return -1;
  997. else
  998. {
  999. // if the addresses are the same, compare types, then names
  1000. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1001. (LPCSTR) &pRec1->szRecordName[0];
  1002. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1003. (LPCSTR) &pRec2->szRecordName[0];
  1004. if ((unsigned char) puChar1[15] > (unsigned char) puChar2[15])
  1005. return 1;
  1006. else
  1007. if ((unsigned char) puChar1[15] < (unsigned char) puChar2[15])
  1008. return -1;
  1009. else
  1010. return lstrcmpOEM(puChar1, puChar2);
  1011. }
  1012. }
  1013. int
  1014. CIndexIpAddr::BCompareD(const void *elem1, const void *elem2)
  1015. {
  1016. return -BCompare(elem1, elem2);
  1017. }
  1018. /*!--------------------------------------------------------------------------
  1019. CIndexIpAddr::Sort
  1020. -
  1021. Author: EricDav
  1022. ---------------------------------------------------------------------------*/
  1023. HRESULT
  1024. CIndexIpAddr::Sort()
  1025. {
  1026. if (m_bAscending)
  1027. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1028. else
  1029. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1030. return hrOK;
  1031. }
  1032. /*!--------------------------------------------------------------------------
  1033. CIndexIpAddr::QCompare
  1034. -
  1035. Author: EricDav
  1036. ---------------------------------------------------------------------------*/
  1037. int __cdecl
  1038. CIndexIpAddr::QCompareA(const void * elem1, const void * elem2)
  1039. {
  1040. LPHROW phrow1 = (LPHROW) elem1;
  1041. LPHROW phrow2 = (LPHROW) elem2;
  1042. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1043. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1044. DWORD dwAddr1, dwAddr2;
  1045. if (pRec1->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  1046. {
  1047. // if this record has multiple addresses, we want the 2nd
  1048. // address, because the 1st address is always the WINS server
  1049. // first dword is the count.
  1050. LPDWORD pdwIpAddrs = (LPDWORD) pRec1->dwIpAdd;
  1051. dwAddr1 = pdwIpAddrs[2];
  1052. }
  1053. else
  1054. {
  1055. dwAddr1 = (DWORD) pRec1->dwIpAdd;
  1056. }
  1057. if (pRec2->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  1058. {
  1059. // if this record has multiple addresses, we want the 2nd
  1060. // address, because the 1st address is always the WINS server
  1061. // first dword is the count.
  1062. LPDWORD pdwIpAddrs = (LPDWORD) pRec2->dwIpAdd;
  1063. dwAddr2 = pdwIpAddrs[2];
  1064. }
  1065. else
  1066. {
  1067. dwAddr2 = (DWORD) pRec2->dwIpAdd;
  1068. }
  1069. if (dwAddr1 > dwAddr2)
  1070. return 1;
  1071. else
  1072. if (dwAddr1 < dwAddr2)
  1073. return -1;
  1074. else
  1075. {
  1076. // if the addresses are the same, compare types, then names
  1077. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1078. (LPCSTR) &pRec1->szRecordName[0];
  1079. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1080. (LPCSTR) &pRec2->szRecordName[0];
  1081. if ((unsigned char) puChar1[15] > (unsigned char) puChar2[15])
  1082. return 1;
  1083. else
  1084. if ((unsigned char) puChar1[15] < (unsigned char) puChar2[15])
  1085. return -1;
  1086. else
  1087. return lstrcmpOEM(puChar1, puChar2);
  1088. }
  1089. }
  1090. int __cdecl
  1091. CIndexIpAddr::QCompareD(const void * elem1, const void * elem2)
  1092. {
  1093. return -QCompareA(elem1, elem2);
  1094. }
  1095. /*!--------------------------------------------------------------------------
  1096. Class CIndexVersion
  1097. ---------------------------------------------------------------------------*/
  1098. /*!--------------------------------------------------------------------------
  1099. CIndexVersion::BCompare
  1100. -
  1101. Author: EricDav
  1102. ---------------------------------------------------------------------------*/
  1103. int
  1104. CIndexVersion::BCompare(const void * elem1, const void * elem2)
  1105. {
  1106. LPHROW phrow1 = (LPHROW) elem1;
  1107. LPHROW phrow2 = (LPHROW) elem2;
  1108. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1109. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1110. if (pRec1->liVersion.QuadPart > pRec2->liVersion.QuadPart)
  1111. return 1;
  1112. else
  1113. if (pRec1->liVersion.QuadPart < pRec2->liVersion.QuadPart)
  1114. return -1;
  1115. else
  1116. return 0;
  1117. }
  1118. int
  1119. CIndexVersion::BCompareD(const void *elem1, const void *elem2)
  1120. {
  1121. return -BCompare(elem1, elem2);
  1122. }
  1123. /*!--------------------------------------------------------------------------
  1124. CIndexVersion::Sort
  1125. -
  1126. Author: EricDav
  1127. ---------------------------------------------------------------------------*/
  1128. HRESULT
  1129. CIndexVersion::Sort()
  1130. {
  1131. if (m_bAscending)
  1132. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1133. else
  1134. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1135. return hrOK;
  1136. }
  1137. /*!--------------------------------------------------------------------------
  1138. CIndexVersion::QCompare
  1139. -
  1140. Author: EricDav
  1141. ---------------------------------------------------------------------------*/
  1142. int __cdecl
  1143. CIndexVersion::QCompareA(const void * elem1, const void * elem2)
  1144. {
  1145. LPHROW phrow1 = (LPHROW) elem1;
  1146. LPHROW phrow2 = (LPHROW) elem2;
  1147. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1148. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1149. if (pRec1->liVersion.QuadPart > pRec2->liVersion.QuadPart)
  1150. return 1;
  1151. else
  1152. if (pRec1->liVersion.QuadPart < pRec2->liVersion.QuadPart)
  1153. return -1;
  1154. else
  1155. return 0;
  1156. }
  1157. int __cdecl
  1158. CIndexVersion::QCompareD(const void * elem1, const void * elem2)
  1159. {
  1160. return -QCompareA(elem1, elem2);
  1161. }
  1162. /*!--------------------------------------------------------------------------
  1163. Class CIndexExpiration
  1164. ---------------------------------------------------------------------------*/
  1165. /*!--------------------------------------------------------------------------
  1166. CIndexExpiration::BCompare
  1167. -
  1168. Author: EricDav
  1169. ---------------------------------------------------------------------------*/
  1170. int
  1171. CIndexExpiration::BCompare(const void * elem1, const void * elem2)
  1172. {
  1173. LPHROW phrow1 = (LPHROW) elem1;
  1174. LPHROW phrow2 = (LPHROW) elem2;
  1175. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1176. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1177. if (pRec1->dwExpiration > pRec2->dwExpiration)
  1178. return 1;
  1179. else
  1180. if (pRec1->dwExpiration < pRec2->dwExpiration)
  1181. return -1;
  1182. else
  1183. return 0;
  1184. }
  1185. int
  1186. CIndexExpiration::BCompareD(const void *elem1, const void *elem2)
  1187. {
  1188. return -BCompare(elem1, elem2);
  1189. }
  1190. /*!--------------------------------------------------------------------------
  1191. CIndexExpiration::Sort
  1192. -
  1193. Author: EricDav
  1194. ---------------------------------------------------------------------------*/
  1195. HRESULT
  1196. CIndexExpiration::Sort()
  1197. {
  1198. if (m_bAscending)
  1199. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1200. else
  1201. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1202. return hrOK;
  1203. }
  1204. /*!--------------------------------------------------------------------------
  1205. CIndexExpiration::QCompare
  1206. -
  1207. Author: EricDav
  1208. ---------------------------------------------------------------------------*/
  1209. int __cdecl
  1210. CIndexExpiration::QCompareA(const void * elem1, const void * elem2)
  1211. {
  1212. LPHROW phrow1 = (LPHROW) elem1;
  1213. LPHROW phrow2 = (LPHROW) elem2;
  1214. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1215. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1216. if (pRec1->dwExpiration > pRec2->dwExpiration)
  1217. return 1;
  1218. else
  1219. if (pRec1->dwExpiration < pRec2->dwExpiration)
  1220. return -1;
  1221. else
  1222. return 0;
  1223. }
  1224. int __cdecl
  1225. CIndexExpiration::QCompareD(const void * elem1, const void * elem2)
  1226. {
  1227. return -QCompareA(elem1, elem2);
  1228. }
  1229. /*!--------------------------------------------------------------------------
  1230. Class CIndexState
  1231. ---------------------------------------------------------------------------*/
  1232. /*!--------------------------------------------------------------------------
  1233. CIndexState::BCompare
  1234. -
  1235. Author: EricDav
  1236. ---------------------------------------------------------------------------*/
  1237. int
  1238. CIndexState::BCompare(const void * elem1, const void * elem2)
  1239. {
  1240. LPHROW phrow1 = (LPHROW) elem1;
  1241. LPHROW phrow2 = (LPHROW) elem2;
  1242. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1243. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1244. int nPri1 = 0, nPri2 = 0;
  1245. // calculate relative priorities
  1246. if (pRec1->szRecordName[18] & WINSDB_REC_ACTIVE)
  1247. nPri1 = 0;
  1248. else
  1249. if (pRec1->szRecordName[18] & WINSDB_REC_RELEASED)
  1250. nPri1 = 1;
  1251. else
  1252. if (pRec1->szRecordName[18] & WINSDB_REC_TOMBSTONE)
  1253. nPri1 = 2;
  1254. else
  1255. if (pRec1->szRecordName[18] & WINSDB_REC_DELETED)
  1256. nPri1 = 3;
  1257. // now for record 2
  1258. if (pRec2->szRecordName[18] & WINSDB_REC_ACTIVE)
  1259. nPri2 = 0;
  1260. else
  1261. if (pRec2->szRecordName[18] & WINSDB_REC_RELEASED)
  1262. nPri2 = 1;
  1263. else
  1264. if (pRec2->szRecordName[18] & WINSDB_REC_TOMBSTONE)
  1265. nPri2 = 2;
  1266. else
  1267. if (pRec2->szRecordName[18] & WINSDB_REC_DELETED)
  1268. nPri2 = 3;
  1269. if (nPri1 > nPri2)
  1270. return 1;
  1271. else
  1272. if (nPri1 < nPri2)
  1273. return -1;
  1274. else
  1275. {
  1276. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1277. (LPCSTR) &pRec1->szRecordName[0];
  1278. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1279. (LPCSTR) &pRec2->szRecordName[0];
  1280. return lstrcmpOEM(puChar1, puChar2);
  1281. }
  1282. }
  1283. int
  1284. CIndexState::BCompareD(const void *elem1, const void *elem2)
  1285. {
  1286. return -BCompare(elem1, elem2);
  1287. }
  1288. /*!--------------------------------------------------------------------------
  1289. CIndexState::Sort
  1290. -
  1291. Author: EricDav
  1292. ---------------------------------------------------------------------------*/
  1293. HRESULT
  1294. CIndexState::Sort()
  1295. {
  1296. if (m_bAscending)
  1297. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1298. else
  1299. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1300. return hrOK;
  1301. }
  1302. /*!--------------------------------------------------------------------------
  1303. CIndexState::QCompare
  1304. -
  1305. Author: EricDav
  1306. ---------------------------------------------------------------------------*/
  1307. int __cdecl
  1308. CIndexState::QCompareA(const void * elem1, const void * elem2)
  1309. {
  1310. LPHROW phrow1 = (LPHROW) elem1;
  1311. LPHROW phrow2 = (LPHROW) elem2;
  1312. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1313. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1314. int nPri1 = 0, nPri2 = 0;
  1315. // calculate relative priorities
  1316. if (pRec1->szRecordName[18] & WINSDB_REC_ACTIVE)
  1317. nPri1 = 0;
  1318. else
  1319. if (pRec1->szRecordName[18] & WINSDB_REC_RELEASED)
  1320. nPri1 = 1;
  1321. else
  1322. if (pRec1->szRecordName[18] & WINSDB_REC_TOMBSTONE)
  1323. nPri1 = 2;
  1324. else
  1325. if (pRec1->szRecordName[18] & WINSDB_REC_DELETED)
  1326. nPri1 = 3;
  1327. // now for record 2
  1328. if (pRec2->szRecordName[18] & WINSDB_REC_ACTIVE)
  1329. nPri2 = 0;
  1330. else
  1331. if (pRec2->szRecordName[18] & WINSDB_REC_RELEASED)
  1332. nPri2 = 1;
  1333. else
  1334. if (pRec2->szRecordName[18] & WINSDB_REC_TOMBSTONE)
  1335. nPri2 = 2;
  1336. else
  1337. if (pRec2->szRecordName[18] & WINSDB_REC_DELETED)
  1338. nPri2 = 3;
  1339. if (nPri1 > nPri2)
  1340. return 1;
  1341. else
  1342. if (nPri1 < nPri2)
  1343. return -1;
  1344. else
  1345. {
  1346. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1347. (LPCSTR) &pRec1->szRecordName[0];
  1348. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1349. (LPCSTR) &pRec2->szRecordName[0];
  1350. return lstrcmpOEM(puChar1, puChar2);
  1351. }
  1352. }
  1353. int __cdecl
  1354. CIndexState::QCompareD(const void * elem1, const void * elem2)
  1355. {
  1356. return -QCompareA(elem1, elem2);
  1357. }
  1358. /*!--------------------------------------------------------------------------
  1359. Class CIndexStatic
  1360. ---------------------------------------------------------------------------*/
  1361. /*!--------------------------------------------------------------------------
  1362. CIndexStatic::BCompare
  1363. -
  1364. Author: EricDav
  1365. ---------------------------------------------------------------------------*/
  1366. int
  1367. CIndexStatic::BCompare(const void * elem1, const void * elem2)
  1368. {
  1369. LPHROW phrow1 = (LPHROW) elem1;
  1370. LPHROW phrow2 = (LPHROW) elem2;
  1371. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1372. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1373. BOOL bStatic1 = pRec1->szRecordName[18] & LOBYTE(LOWORD(WINSDB_REC_STATIC));
  1374. BOOL bStatic2 = pRec2->szRecordName[18] & LOBYTE(LOWORD(WINSDB_REC_STATIC));
  1375. if (bStatic1 && !bStatic2)
  1376. return 1;
  1377. else
  1378. if (!bStatic1 && bStatic2)
  1379. return -1;
  1380. else
  1381. {
  1382. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1383. (LPCSTR) &pRec1->szRecordName[0];
  1384. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1385. (LPCSTR) &pRec2->szRecordName[0];
  1386. return lstrcmpOEM(puChar1, puChar2);
  1387. }
  1388. }
  1389. int
  1390. CIndexStatic::BCompareD(const void *elem1, const void *elem2)
  1391. {
  1392. return -BCompare(elem1, elem2);
  1393. }
  1394. /*!--------------------------------------------------------------------------
  1395. CIndexStatic::Sort
  1396. -
  1397. Author: EricDav
  1398. ---------------------------------------------------------------------------*/
  1399. HRESULT
  1400. CIndexStatic::Sort()
  1401. {
  1402. if (m_bAscending)
  1403. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1404. else
  1405. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1406. return hrOK;
  1407. }
  1408. /*!--------------------------------------------------------------------------
  1409. CIndexStatic::QCompare
  1410. -
  1411. Author: EricDav
  1412. ---------------------------------------------------------------------------*/
  1413. int __cdecl
  1414. CIndexStatic::QCompareA(const void * elem1, const void * elem2)
  1415. {
  1416. LPHROW phrow1 = (LPHROW) elem1;
  1417. LPHROW phrow2 = (LPHROW) elem2;
  1418. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1419. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1420. BOOL bStatic1 = pRec1->szRecordName[18] & LOBYTE(LOWORD(WINSDB_REC_STATIC));
  1421. BOOL bStatic2 = pRec2->szRecordName[18] & LOBYTE(LOWORD(WINSDB_REC_STATIC));
  1422. if (bStatic1 && !bStatic2)
  1423. return 1;
  1424. else
  1425. if (!bStatic1 && bStatic2)
  1426. return -1;
  1427. else
  1428. {
  1429. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1430. (LPCSTR) &pRec1->szRecordName[0];
  1431. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1432. (LPCSTR) &pRec2->szRecordName[0];
  1433. return lstrcmpOEM(puChar1, puChar2);
  1434. }
  1435. }
  1436. int __cdecl
  1437. CIndexStatic::QCompareD(const void * elem1, const void * elem2)
  1438. {
  1439. return -QCompareA(elem1, elem2);
  1440. }
  1441. /*!--------------------------------------------------------------------------
  1442. Class CIndexOwner
  1443. ---------------------------------------------------------------------------*/
  1444. /*!--------------------------------------------------------------------------
  1445. CIndexOwner::BCompare
  1446. -
  1447. Author: EricDav
  1448. ---------------------------------------------------------------------------*/
  1449. int
  1450. CIndexOwner::BCompare(const void * elem1, const void * elem2)
  1451. {
  1452. LPHROW phrow1 = (LPHROW) elem1;
  1453. LPHROW phrow2 = (LPHROW) elem2;
  1454. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1455. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1456. if (pRec1->dwOwner > pRec2->dwOwner)
  1457. {
  1458. return 1;
  1459. }
  1460. else
  1461. if (pRec1->dwOwner < pRec2->dwOwner)
  1462. {
  1463. return -1;
  1464. }
  1465. else
  1466. {
  1467. // if the addresses are the same, compare names
  1468. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1469. (LPCSTR) &pRec1->szRecordName[0];
  1470. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1471. (LPCSTR) &pRec2->szRecordName[0];
  1472. return lstrcmpOEM(puChar1, puChar2);
  1473. }
  1474. }
  1475. int
  1476. CIndexOwner::BCompareD(const void *elem1, const void *elem2)
  1477. {
  1478. return -BCompare(elem1, elem2);
  1479. }
  1480. /*!--------------------------------------------------------------------------
  1481. CIndexStatic::Sort
  1482. -
  1483. Author: EricDav
  1484. ---------------------------------------------------------------------------*/
  1485. HRESULT
  1486. CIndexOwner::Sort()
  1487. {
  1488. if (m_bAscending)
  1489. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareA);
  1490. else
  1491. qsort(m_hrowArray.GetData(), (size_t)m_hrowArray.GetSize(), sizeof(HROW), QCompareD);
  1492. return hrOK;
  1493. }
  1494. /*!--------------------------------------------------------------------------
  1495. CIndexStatic::QCompare
  1496. -
  1497. Author: EricDav
  1498. ---------------------------------------------------------------------------*/
  1499. int __cdecl
  1500. CIndexOwner::QCompareA(const void * elem1, const void * elem2)
  1501. {
  1502. LPHROW phrow1 = (LPHROW) elem1;
  1503. LPHROW phrow2 = (LPHROW) elem2;
  1504. LPWINSDBRECORD pRec1 = (LPWINSDBRECORD) *phrow1;
  1505. LPWINSDBRECORD pRec2 = (LPWINSDBRECORD) *phrow2;
  1506. if (pRec1->dwOwner > pRec2->dwOwner)
  1507. {
  1508. return 1;
  1509. }
  1510. else
  1511. if (pRec1->dwOwner < pRec2->dwOwner)
  1512. {
  1513. return -1;
  1514. }
  1515. else
  1516. {
  1517. // if the addresses are the same, compare names
  1518. LPCSTR puChar1 = (IS_DBREC_LONGNAME(pRec1)) ? (LPCSTR) *((char **) pRec1->szRecordName) :
  1519. (LPCSTR) &pRec1->szRecordName[0];
  1520. LPCSTR puChar2 = (IS_DBREC_LONGNAME(pRec2)) ? (LPCSTR) *((char **) pRec2->szRecordName) :
  1521. (LPCSTR) &pRec2->szRecordName[0];
  1522. return lstrcmpOEM(puChar1, puChar2);
  1523. }
  1524. }
  1525. int __cdecl
  1526. CIndexOwner::QCompareD(const void * elem1, const void * elem2)
  1527. {
  1528. return -QCompareA(elem1, elem2);
  1529. }
  1530. HRESULT CFilteredIndexName::AddFilter(WINSDB_FILTER_TYPE FilterType, DWORD dwData1, DWORD dwData2, LPCOLESTR strData3)
  1531. {
  1532. HRESULT hr = hrOK;
  1533. tIpReference ipRef;
  1534. switch (FilterType)
  1535. {
  1536. case WINSDB_FILTER_BY_TYPE:
  1537. m_mapFilterTypes.SetAt(dwData1, (BOOL&) dwData2);
  1538. break;
  1539. case WINSDB_FILTER_BY_OWNER:
  1540. m_dwaFilteredOwners.Add(dwData1);
  1541. break;
  1542. case WINSDB_FILTER_BY_IPADDR:
  1543. ipRef.Address = dwData1;
  1544. ipRef.Mask = dwData2;
  1545. m_taFilteredIp.Add(ipRef);
  1546. break;
  1547. case WINSDB_FILTER_BY_NAME:
  1548. UINT nData3Len;
  1549. nData3Len = (_tcslen(strData3)+1)*sizeof(TCHAR);
  1550. m_pchFilteredName = new char[nData3Len];
  1551. if (m_pchFilteredName != NULL)
  1552. {
  1553. #ifdef _UNICODE
  1554. if (WideCharToMultiByte(CP_OEMCP,
  1555. 0,
  1556. strData3,
  1557. -1,
  1558. m_pchFilteredName,
  1559. nData3Len,
  1560. NULL,
  1561. NULL) == 0)
  1562. {
  1563. delete m_pchFilteredName;
  1564. m_pchFilteredName = NULL;
  1565. }
  1566. #else
  1567. CharToOem(strData3, m_pchFilteredName);
  1568. #endif
  1569. //m_pchFilteredName = _strupr(m_pchFilteredName);
  1570. m_bMatchCase = dwData1;
  1571. }
  1572. break;
  1573. default:
  1574. Panic0("Invalid filter type passed to CFilteredIndexName::AddFilter");
  1575. break;
  1576. }
  1577. return hr;
  1578. }
  1579. BOOL CFilteredIndexName::CheckForFilter(LPHROW hrowCheck)
  1580. {
  1581. UINT nCountOwner = (UINT)m_dwaFilteredOwners.GetSize();
  1582. UINT nCountType = m_mapFilterTypes.GetHashTableSize();
  1583. UINT nCountIPAddrs = (UINT)m_taFilteredIp.GetSize();
  1584. BOOL bOwnerFilter = (nCountOwner == 0);
  1585. BOOL bTypeFilter = (nCountType == 0);
  1586. BOOL bIPAddrsFilter = (nCountIPAddrs == 0);
  1587. BOOL bNameFilter = (m_pchFilteredName == NULL);
  1588. LPWINSDBRECORD pRec = (LPWINSDBRECORD) *hrowCheck;
  1589. UINT i, j;
  1590. LPCSTR puChar;
  1591. for (i = 0; !bOwnerFilter && i < nCountOwner; i++)
  1592. {
  1593. if (pRec->dwOwner == m_dwaFilteredOwners.GetAt(i))
  1594. bOwnerFilter = TRUE;
  1595. }
  1596. if (!bOwnerFilter)
  1597. return FALSE;
  1598. puChar = (IS_DBREC_LONGNAME(pRec)) ?
  1599. (LPCSTR) *((char **) pRec->szRecordName) :
  1600. (LPCSTR) &pRec->szRecordName[0];
  1601. if (!bTypeFilter)
  1602. {
  1603. DWORD dwType = puChar[0xF];
  1604. if (!m_mapFilterTypes.Lookup(dwType, bTypeFilter))
  1605. {
  1606. // no entry for this name type. Check the FFFF name type (other) to see if we should
  1607. // show it.
  1608. dwType = 0xFFFF;
  1609. m_mapFilterTypes.Lookup(dwType, bTypeFilter);
  1610. }
  1611. }
  1612. if (!bTypeFilter)
  1613. return FALSE;
  1614. for (i = 0; !bIPAddrsFilter && i < nCountIPAddrs; i++)
  1615. {
  1616. if (pRec->szRecordName[18] & WINSDB_REC_MULT_ADDRS)
  1617. {
  1618. LPDWORD pdwIpAddrs = (LPDWORD) pRec->dwIpAdd;
  1619. for (j=0; !bIPAddrsFilter && j < pdwIpAddrs[0]; j+=2)
  1620. {
  1621. bIPAddrsFilter = SubnetMatching(m_taFilteredIp[i], pdwIpAddrs[j+2]);
  1622. }
  1623. }
  1624. else
  1625. {
  1626. bIPAddrsFilter = SubnetMatching(m_taFilteredIp[i], (DWORD)pRec->dwIpAdd);
  1627. }
  1628. }
  1629. if(!bIPAddrsFilter)
  1630. return FALSE;
  1631. if (!bNameFilter)
  1632. {
  1633. bNameFilter = (PatternMatching(puChar, m_pchFilteredName, 16) == NULL);
  1634. }
  1635. return bNameFilter;
  1636. }
  1637. BOOL CFilteredIndexName::CheckWinsRecordForFilter(WinsRecord *pWinsRecord)
  1638. {
  1639. UINT nCountOwner = (UINT)m_dwaFilteredOwners.GetSize();
  1640. UINT nCountType = m_mapFilterTypes.GetHashTableSize();
  1641. UINT nCountIPAddrs = (UINT)m_taFilteredIp.GetSize();
  1642. BOOL bOwnerFilter = (nCountOwner == 0);
  1643. BOOL bTypeFilter = (nCountType == 0);
  1644. BOOL bIPAddrsFilter = (nCountIPAddrs == 0);
  1645. BOOL bNameFilter = (m_pchFilteredName == NULL);
  1646. UINT i, j;
  1647. //-------------------------------------
  1648. // check the owner filter first, if any
  1649. for (i = 0; !bOwnerFilter && i < nCountOwner; i++)
  1650. {
  1651. if (pWinsRecord->dwOwner == m_dwaFilteredOwners.GetAt(i))
  1652. bOwnerFilter = TRUE;
  1653. }
  1654. if (!bOwnerFilter)
  1655. return FALSE;
  1656. //-------------------------------------
  1657. // check the type filter if any
  1658. if (!bTypeFilter)
  1659. {
  1660. DWORD dwType;
  1661. // keep in mind the name's type is in the lowest 16 bits of pWinsRecord->dwType
  1662. // (see WinsIntfToWinsRecord())
  1663. dwType = pWinsRecord->dwType & 0x0000ffff;
  1664. if (!m_mapFilterTypes.Lookup(dwType, bTypeFilter))
  1665. {
  1666. // no entry for this name type. Check the FFFF name type (other) to see if we should
  1667. // show it.
  1668. dwType = 0xFFFF;
  1669. m_mapFilterTypes.Lookup(dwType, bTypeFilter);
  1670. }
  1671. }
  1672. if (!bTypeFilter)
  1673. return FALSE;
  1674. //-------------------------------------
  1675. // check the IP address filter if any
  1676. for (i = 0; !bIPAddrsFilter && i < nCountIPAddrs; i++)
  1677. {
  1678. if (pWinsRecord->dwState & WINSDB_REC_MULT_ADDRS)
  1679. {
  1680. for (j=0; !bIPAddrsFilter && j < pWinsRecord->dwNoOfAddrs; j++)
  1681. {
  1682. bIPAddrsFilter = SubnetMatching(m_taFilteredIp[i], pWinsRecord->dwIpAdd[j]);
  1683. }
  1684. }
  1685. else
  1686. {
  1687. bIPAddrsFilter = SubnetMatching(m_taFilteredIp[i], pWinsRecord->dwIpAdd[0]);
  1688. }
  1689. }
  1690. if(!bIPAddrsFilter)
  1691. return FALSE;
  1692. //-------------------------------------
  1693. // check the name filter if any
  1694. if (!bNameFilter)
  1695. {
  1696. bNameFilter = (PatternMatching(pWinsRecord->szRecordName, m_pchFilteredName, 16) == NULL);
  1697. }
  1698. return bNameFilter;
  1699. }
  1700. LPCSTR CFilteredIndexName::PatternMatching(LPCSTR pName, LPCSTR pPattern, INT nNameLen)
  1701. {
  1702. LPCSTR pNameBak = pName;
  1703. // it is guaranteed here we have a valid (not NULL) pattern
  1704. while (*pPattern != '\0' && pName-pNameBak < nNameLen)
  1705. {
  1706. BOOL bChMatch = (*pPattern == *pName);
  1707. if (!m_bMatchCase && !bChMatch)
  1708. {
  1709. bChMatch = (islower(*pPattern) && _toupper(*pPattern) == *pName) ||
  1710. (islower(*pName) && *pPattern == _toupper(*pName));
  1711. }
  1712. if (*pPattern == '?' || bChMatch)
  1713. {
  1714. pPattern++;
  1715. }
  1716. else if (*pPattern == '*')
  1717. {
  1718. LPCSTR pTrail = pName;
  1719. INT nTrailLen = nNameLen-(UINT)(pTrail-pNameBak);
  1720. pPattern++;
  1721. while ((pName = PatternMatching(pTrail, pPattern, nTrailLen)) != NULL)
  1722. {
  1723. pTrail++;
  1724. nTrailLen--;
  1725. if (*pTrail == '\0' || nTrailLen <= 0)
  1726. break;
  1727. }
  1728. return pName;
  1729. }
  1730. else if (!bChMatch)
  1731. {
  1732. // in the test above, note that even in the unikely case *pName == '\0'
  1733. // *pName will not match *pPattern so the loop is still broken - which is
  1734. // the desired behavior. In this case the pattern was not consummed
  1735. // and the name was, so the return will indicate the matching failed
  1736. break;
  1737. }
  1738. pName++;
  1739. }
  1740. return *pPattern == '\0' ? NULL : pName;
  1741. }
  1742. BOOL CFilteredIndexName::SubnetMatching(tIpReference &IpRefPattern, DWORD dwIPAddress)
  1743. {
  1744. DWORD dwMask;
  1745. return (IpRefPattern.Address & IpRefPattern.Mask) == (dwIPAddress & IpRefPattern.Mask);
  1746. }
  1747. HRESULT CFilteredIndexName::ClearFilter(WINSDB_FILTER_TYPE FilterType)
  1748. {
  1749. HRESULT hr = hrOK;
  1750. switch(FilterType)
  1751. {
  1752. case WINSDB_FILTER_BY_TYPE:
  1753. m_mapFilterTypes.RemoveAll();
  1754. break;
  1755. case WINSDB_FILTER_BY_OWNER:
  1756. m_dwaFilteredOwners.RemoveAll();
  1757. break;
  1758. case WINSDB_FILTER_BY_IPADDR:
  1759. m_taFilteredIp.RemoveAll();
  1760. break;
  1761. case WINSDB_FILTER_BY_NAME:
  1762. if (m_pchFilteredName != NULL)
  1763. {
  1764. delete m_pchFilteredName;
  1765. m_pchFilteredName = NULL;
  1766. }
  1767. break;
  1768. default:
  1769. Panic0("Invalid filter type passed to CFilteredIndexName::ClearFilter");
  1770. break;
  1771. }
  1772. return hr;
  1773. }