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.

1300 lines
31 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1999 - 2002 **/
  4. /**********************************************************************/
  5. /*
  6. hArray.cpp
  7. Index manager for IPSecMon
  8. FILE HISTORY:
  9. Nov 29 1999 Ning Sun Created
  10. */
  11. #include "stdafx.h"
  12. #include "spddb.h"
  13. #include "harray.h"
  14. #include "mbstring.h"
  15. #include "spdutil.h"
  16. extern const DWORD INDEX_TYPE_DEFAULT = 0;
  17. int __cdecl CompareFilterName(const void *elem1, const void *elem2);
  18. int __cdecl CompareFilterSourceAddr(const void *elem1, const void *elem2);
  19. int __cdecl CompareFilterDestAddr(const void *elem1, const void *elem2);
  20. int __cdecl CompareFilterSrcPort(const void *elem1, const void *elem2);
  21. int __cdecl CompareFilterDestPort(const void *elem1, const void *elem2);
  22. int __cdecl CompareFilterProtocol(const void *elem1, const void *elem2);
  23. int __cdecl CompareFilterDirection(const void *elem1, const void *elem2);
  24. int __cdecl CompareFilterWeight(const void *elem1, const void *elem2);
  25. int __cdecl CompareFilterPolicyName(const void *elem1, const void *elem2);
  26. int __cdecl CompareFilterIfType(const void *elem1, const void *elem2);
  27. int __cdecl CompareFilterInboundFlag(const void *elem1, const void *elem2);
  28. int __cdecl CompareFilterOutboundFlag(const void *elem1, const void *elem2);
  29. int __cdecl CompareFilterFlag(const void *elem1, const void *elem2);
  30. int __cdecl CompareMmFilterName(const void *elem1, const void *elem2);
  31. int __cdecl CompareMmFilterSourceAddr(const void *elem1, const void *elem2);
  32. int __cdecl CompareMmFilterDestAddr(const void *elem1, const void *elem2);
  33. int __cdecl CompareMmFilterDirection(const void *elem1, const void *elem2);
  34. int __cdecl CompareMmFilterWeight(const void *elem1, const void *elem2);
  35. int __cdecl CompareMmFilterPolicyName(const void *elem1, const void *elem2);
  36. int __cdecl CompareMmFilterAuth(const void *elem1, const void *elem2);
  37. int __cdecl CompareMmFilterIfType(const void *elem1, const void *elem2);
  38. int __cdecl CompareMmPolicyName(const void *elem1, const void *elem2);
  39. int __cdecl CompareMmPolicyOfferNumber(const void *elem1, const void *elem2);
  40. int __cdecl CompareQmPolicyName(const void *elem1, const void *elem2);
  41. int __cdecl CompareQmPolicyOfferNumber(const void *elem1, const void *elem2);
  42. int __cdecl CompareMmSAMeAddr(const void *elem1, const void *elem2);
  43. int __cdecl CompareMmSAPeerAddr(const void *elem1, const void *elem2);
  44. int __cdecl CompareMmSAAuth(const void *elem1, const void *elem2);
  45. int __cdecl CompareMmSAEncryption(const void *elem1, const void *elem2);
  46. int __cdecl CompareMmSAIntegrity(const void *elem1, const void *elem2);
  47. int __cdecl CompareMmSADhGroup(const void *elem1, const void *elem2);
  48. int __cdecl CompareQmSAPolicyName(const void *elem1, const void *elem2);
  49. int __cdecl CompareQmSAAuth(const void *elem1, const void *elem2);
  50. int __cdecl CompareQmSAConf(const void *elem1, const void *elem2);
  51. int __cdecl CompareQmSAIntegrity(const void *elem1, const void *elem2);
  52. int __cdecl CompareQmSASrc(const void *elem1, const void *elem2);
  53. int __cdecl CompareQmSADest(const void *elem1, const void *elem2);
  54. int __cdecl CompareQmSAProtocol(const void *elem1, const void *elem2);
  55. int __cdecl CompareQmSASrcPort(const void *elem1, const void *elem2);
  56. int __cdecl CompareQmSADestPort(const void *elem1, const void *elem2);
  57. int __cdecl CompareQmSAMyTnlEp(const void *elem1, const void *elem2);
  58. int __cdecl CompareQmSAPeerTnlEp(const void *elem1, const void *elem2);
  59. int __cdecl CompareFilterSrcTnl(const void *elem1, const void *elem2);
  60. int __cdecl CompareFilterDestTnl(const void *elem1, const void *elem2);
  61. typedef int (__cdecl *PFNCompareProc)(const void *, const void *);
  62. //This structure saves the pair of sort type and sort function
  63. struct SortTypeAndCompareProcPair
  64. {
  65. DWORD dwType;
  66. PFNCompareProc pCompareProc;
  67. };
  68. SortTypeAndCompareProcPair TypeProcMmFilter[] =
  69. {
  70. {IDS_COL_FLTR_NAME, CompareMmFilterName},
  71. {IDS_COL_FLTR_SRC, CompareMmFilterSourceAddr},
  72. {IDS_COL_FLTR_DEST, CompareMmFilterDestAddr},
  73. {IDS_COL_FLTR_DIR, CompareMmFilterDirection},
  74. {IDS_COL_MM_FLTR_POL, CompareMmFilterPolicyName},
  75. {IDS_COL_MM_FLTR_AUTH, CompareMmFilterAuth},
  76. {IDS_COL_IF_TYPE, CompareMmFilterIfType},
  77. {IDS_COL_FLTR_WEIGHT, CompareMmFilterWeight},
  78. {INDEX_TYPE_DEFAULT, NULL} //NULL means do nothing during sort
  79. };
  80. SortTypeAndCompareProcPair TypeProcMmPolicy[] =
  81. {
  82. {IDS_COL_MM_POL_NAME, CompareMmPolicyName},
  83. {IDS_COL_MM_POL_OFFER, CompareMmPolicyOfferNumber},
  84. {INDEX_TYPE_DEFAULT, NULL} //NULL means do nothing during sort
  85. };
  86. //SortTypeAndCompareProcPair
  87. SortTypeAndCompareProcPair TypeProcMmSA[] =
  88. {
  89. {IDS_COL_MM_SA_ME, CompareMmSAMeAddr},
  90. {IDS_COL_MM_SA_PEER, CompareMmSAPeerAddr},
  91. {IDS_COL_MM_SA_AUTH, CompareMmSAAuth},
  92. {IDS_COL_MM_SA_ENCRYPITON, CompareMmSAEncryption},
  93. {IDS_COL_MM_SA_INTEGRITY, CompareMmSAIntegrity},
  94. {IDS_COL_MM_SA_DH, CompareMmSADhGroup},
  95. {INDEX_TYPE_DEFAULT, NULL} //NULL means do nothing during sort
  96. };
  97. SortTypeAndCompareProcPair TypeProcQmFilter[] =
  98. {
  99. {IDS_COL_FLTR_NAME, CompareFilterName},
  100. {IDS_COL_FLTR_SRC, CompareFilterSourceAddr},
  101. {IDS_COL_FLTR_SRC_PORT, CompareFilterSrcPort},
  102. {IDS_COL_FLTR_DEST, CompareFilterDestAddr},
  103. {IDS_COL_FLTR_DEST_PORT, CompareFilterDestPort},
  104. {IDS_COL_FLTR_SRC_TNL, CompareFilterSrcTnl},
  105. {IDS_COL_FLTR_DEST_TNL, CompareFilterDestTnl},
  106. {IDS_COL_FLTR_PROT, CompareFilterProtocol},
  107. {IDS_COL_FLTR_DIR, CompareFilterDirection},
  108. {IDS_COL_QM_POLICY, CompareFilterPolicyName},
  109. {IDS_COL_IF_TYPE, CompareFilterIfType},
  110. {IDS_COL_FLTR_WEIGHT, CompareFilterWeight},
  111. {IDS_COL_FLTR_OUT_FLAG, CompareFilterOutboundFlag},
  112. {IDS_COL_FLTR_IN_FLAG, CompareFilterInboundFlag},
  113. {IDS_COL_FLTR_FLAG, CompareFilterFlag},
  114. {INDEX_TYPE_DEFAULT, NULL} //NULL means do nothing during sort
  115. };
  116. SortTypeAndCompareProcPair TypeProcQmPolicy[] =
  117. {
  118. {IDS_COL_QM_POL_NAME, CompareQmPolicyName},
  119. {IDS_COL_QM_POL_OFFER, CompareQmPolicyOfferNumber},
  120. {INDEX_TYPE_DEFAULT, NULL} //NULL means do nothing during sort
  121. };
  122. SortTypeAndCompareProcPair TypeProcQmSA[] =
  123. {
  124. {IDS_COL_QM_SA_POL, CompareQmSAPolicyName},
  125. {IDS_COL_QM_SA_AUTH, CompareQmSAAuth},
  126. {IDS_COL_QM_SA_CONF, CompareQmSAConf},
  127. {IDS_COL_QM_SA_INTEGRITY, CompareQmSAIntegrity},
  128. {IDS_COL_QM_SA_SRC, CompareQmSASrc},
  129. {IDS_COL_QM_SA_DEST, CompareQmSADest},
  130. {IDS_COL_QM_SA_PROT, CompareQmSAProtocol},
  131. {IDS_COL_QM_SA_SRC_PORT, CompareQmSASrcPort},
  132. {IDS_COL_QM_SA_DES_PORT, CompareQmSADestPort},
  133. {IDS_COL_QM_SA_MY_TNL, CompareQmSAMyTnlEp},
  134. {IDS_COL_QM_SA_PEER_TNL, CompareQmSAPeerTnlEp},
  135. {INDEX_TYPE_DEFAULT, NULL} //NULL means do nothing during sort
  136. };
  137. CColumnIndex::CColumnIndex(DWORD dwIndexType, PCOMPARE_FUNCTION pfnCompare)
  138. : CIndexArray(),
  139. m_dwIndexType(dwIndexType),
  140. m_pfnCompare(pfnCompare),
  141. m_dwSortOption(SORT_ASCENDING)
  142. {
  143. }
  144. HRESULT CColumnIndex::Sort()
  145. {
  146. if (NULL != m_pfnCompare)
  147. {
  148. qsort(GetData(), (size_t)GetSize(), sizeof(void *), m_pfnCompare);
  149. }
  150. return S_OK;
  151. }
  152. void* CColumnIndex::GetIndexedItem(int nIndex)
  153. {
  154. return ((m_dwSortOption & SORT_ASCENDING)) ? GetAt(GetSize() - nIndex -1) : GetAt(nIndex);
  155. }
  156. CIndexManager::CIndexManager()
  157. : m_DefaultIndex(INDEX_TYPE_DEFAULT, NULL), //NULL means do nothing during sort
  158. m_posCurrentIndex(NULL)
  159. {
  160. }
  161. CIndexManager::~CIndexManager()
  162. {
  163. Reset();
  164. }
  165. void
  166. CIndexManager::Reset()
  167. {
  168. while (m_listIndicies.GetCount() > 0)
  169. {
  170. delete m_listIndicies.RemoveHead();
  171. }
  172. m_posCurrentIndex = NULL;
  173. m_DefaultIndex.RemoveAll();
  174. }
  175. int
  176. CIndexManager::AddItem(void *pItem)
  177. {
  178. return (int)m_DefaultIndex.Add(pItem);
  179. }
  180. void * CIndexManager::GetItemData(int nIndex)
  181. {
  182. CColumnIndex * pIndex = NULL;
  183. if (NULL == m_posCurrentIndex)
  184. {
  185. //use the default index
  186. pIndex = &m_DefaultIndex;
  187. }
  188. else
  189. {
  190. pIndex = m_listIndicies.GetAt(m_posCurrentIndex);
  191. }
  192. Assert(pIndex);
  193. if (nIndex < pIndex->GetSize() && nIndex >= 0)
  194. {
  195. return pIndex->GetIndexedItem(nIndex);
  196. }
  197. else
  198. {
  199. Panic0("We dont have that index!");
  200. return NULL;
  201. }
  202. }
  203. DWORD CIndexManager::GetCurrentIndexType()
  204. {
  205. DWORD dwIndexType;
  206. if (m_posCurrentIndex)
  207. {
  208. CColumnIndex * pIndex = m_listIndicies.GetAt(m_posCurrentIndex);
  209. dwIndexType = pIndex->GetType();
  210. }
  211. else
  212. {
  213. dwIndexType = m_DefaultIndex.GetType();
  214. }
  215. return dwIndexType;
  216. }
  217. DWORD CIndexManager::GetCurrentSortOption()
  218. {
  219. DWORD dwSortOption;
  220. if (m_posCurrentIndex)
  221. {
  222. CColumnIndex * pIndex = m_listIndicies.GetAt(m_posCurrentIndex);
  223. dwSortOption = pIndex->GetSortOption();
  224. }
  225. else
  226. {
  227. dwSortOption = m_DefaultIndex.GetSortOption();
  228. }
  229. return dwSortOption;
  230. }
  231. HRESULT
  232. CIndexMgrFilter::SortFilters(
  233. DWORD dwSortType,
  234. DWORD dwSortOptions
  235. )
  236. {
  237. HRESULT hr = hrOK;
  238. POSITION posLast;
  239. POSITION pos;
  240. DWORD dwIndexType;
  241. pos = m_listIndicies.GetHeadPosition();
  242. while (pos)
  243. {
  244. posLast = pos;
  245. CColumnIndex * pIndex = m_listIndicies.GetNext(pos);
  246. dwIndexType = pIndex->GetType();
  247. // the index for this type already exists, just sort accordingly
  248. if (dwIndexType == dwSortType)
  249. {
  250. pIndex->SetSortOption(dwSortOptions);
  251. m_posCurrentIndex = posLast;
  252. return hrOK;
  253. }
  254. }
  255. // if not, create one
  256. CColumnIndex * pNewIndex = NULL;
  257. for (int i = 0; i < DimensionOf(TypeProcQmFilter); i++)
  258. {
  259. if (TypeProcQmFilter[i].dwType == dwSortType)
  260. {
  261. pNewIndex = new CColumnIndex(dwSortType, TypeProcQmFilter[i].pCompareProc);
  262. break;
  263. }
  264. }
  265. Assert(pNewIndex);
  266. if (NULL == pNewIndex)
  267. {
  268. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  269. }
  270. // copy the array from the original index
  271. pNewIndex->Copy(m_DefaultIndex);
  272. pNewIndex->SetSortOption(dwSortOptions);
  273. pNewIndex->Sort();
  274. m_posCurrentIndex = m_listIndicies.AddTail(pNewIndex);
  275. return hr;
  276. }
  277. HRESULT
  278. CIndexMgrMmFilter::SortMmFilters(
  279. DWORD dwSortType,
  280. DWORD dwSortOptions
  281. )
  282. {
  283. HRESULT hr = hrOK;
  284. POSITION posLast;
  285. POSITION pos;
  286. DWORD dwIndexType;
  287. pos = m_listIndicies.GetHeadPosition();
  288. while (pos)
  289. {
  290. posLast = pos;
  291. CColumnIndex * pIndex = m_listIndicies.GetNext(pos);
  292. dwIndexType = pIndex->GetType();
  293. // the index for this type already exists, just sort accordingly
  294. if (dwIndexType == dwSortType)
  295. {
  296. pIndex->SetSortOption(dwSortOptions);
  297. m_posCurrentIndex = posLast;
  298. return hrOK;
  299. }
  300. }
  301. // if not, create one
  302. CColumnIndex * pNewIndex = NULL;
  303. for (int i = 0; i < DimensionOf(TypeProcMmFilter); i++)
  304. {
  305. if (TypeProcMmFilter[i].dwType == dwSortType)
  306. {
  307. pNewIndex = new CColumnIndex(dwSortType, TypeProcMmFilter[i].pCompareProc);
  308. break;
  309. }
  310. }
  311. Assert(pNewIndex);
  312. if (NULL == pNewIndex)
  313. {
  314. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  315. }
  316. // copy the array from the original index
  317. pNewIndex->Copy(m_DefaultIndex);
  318. pNewIndex->SetSortOption(dwSortOptions);
  319. pNewIndex->Sort();
  320. m_posCurrentIndex = m_listIndicies.AddTail(pNewIndex);
  321. return hr;
  322. }
  323. HRESULT
  324. CIndexMgrMmPolicy::Sort(
  325. DWORD dwSortType,
  326. DWORD dwSortOptions
  327. )
  328. {
  329. HRESULT hr = hrOK;
  330. POSITION posLast;
  331. POSITION pos;
  332. DWORD dwIndexType;
  333. pos = m_listIndicies.GetHeadPosition();
  334. while (pos)
  335. {
  336. posLast = pos;
  337. CColumnIndex * pIndex = m_listIndicies.GetNext(pos);
  338. dwIndexType = pIndex->GetType();
  339. // the index for this type already exists, just sort accordingly
  340. if (dwIndexType == dwSortType)
  341. {
  342. pIndex->SetSortOption(dwSortOptions);
  343. m_posCurrentIndex = posLast;
  344. return hrOK;
  345. }
  346. }
  347. // if not, create one
  348. CColumnIndex * pNewIndex = NULL;
  349. for (int i = 0; i < DimensionOf(TypeProcMmPolicy); i++)
  350. {
  351. if (TypeProcMmPolicy[i].dwType == dwSortType)
  352. {
  353. pNewIndex = new CColumnIndex(dwSortType, TypeProcMmPolicy[i].pCompareProc);
  354. break;
  355. }
  356. }
  357. Assert(pNewIndex);
  358. if (NULL == pNewIndex)
  359. {
  360. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  361. }
  362. // copy the array from the original index
  363. pNewIndex->Copy(m_DefaultIndex);
  364. pNewIndex->SetSortOption(dwSortOptions);
  365. pNewIndex->Sort();
  366. m_posCurrentIndex = m_listIndicies.AddTail(pNewIndex);
  367. return hr;
  368. }
  369. HRESULT
  370. CIndexMgrQmPolicy::Sort(
  371. DWORD dwSortType,
  372. DWORD dwSortOptions
  373. )
  374. {
  375. HRESULT hr = hrOK;
  376. POSITION posLast;
  377. POSITION pos;
  378. DWORD dwIndexType;
  379. pos = m_listIndicies.GetHeadPosition();
  380. while (pos)
  381. {
  382. posLast = pos;
  383. CColumnIndex * pIndex = m_listIndicies.GetNext(pos);
  384. dwIndexType = pIndex->GetType();
  385. // the index for this type already exists, just sort accordingly
  386. if (dwIndexType == dwSortType)
  387. {
  388. pIndex->SetSortOption(dwSortOptions);
  389. m_posCurrentIndex = posLast;
  390. return hrOK;
  391. }
  392. }
  393. // if not, create one
  394. CColumnIndex * pNewIndex = NULL;
  395. for (int i = 0; i < DimensionOf(TypeProcQmPolicy); i++)
  396. {
  397. if (TypeProcQmPolicy[i].dwType == dwSortType)
  398. {
  399. pNewIndex = new CColumnIndex(dwSortType, TypeProcQmPolicy[i].pCompareProc);
  400. break;
  401. }
  402. }
  403. Assert(pNewIndex);
  404. if (NULL == pNewIndex)
  405. {
  406. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  407. }
  408. // copy the array from the original index
  409. pNewIndex->Copy(m_DefaultIndex);
  410. pNewIndex->SetSortOption(dwSortOptions);
  411. pNewIndex->Sort();
  412. m_posCurrentIndex = m_listIndicies.AddTail(pNewIndex);
  413. return hr;
  414. }
  415. HRESULT
  416. CIndexMgrMmSA::Sort(
  417. DWORD dwSortType,
  418. DWORD dwSortOptions
  419. )
  420. {
  421. HRESULT hr = hrOK;
  422. POSITION posLast;
  423. POSITION pos;
  424. DWORD dwIndexType;
  425. pos = m_listIndicies.GetHeadPosition();
  426. while (pos)
  427. {
  428. posLast = pos;
  429. CColumnIndex * pIndex = m_listIndicies.GetNext(pos);
  430. dwIndexType = pIndex->GetType();
  431. // the index for this type already exists, just sort accordingly
  432. if (dwIndexType == dwSortType)
  433. {
  434. pIndex->SetSortOption(dwSortOptions);
  435. m_posCurrentIndex = posLast;
  436. return hrOK;
  437. }
  438. }
  439. // if not, create one
  440. CColumnIndex * pNewIndex = NULL;
  441. for (int i = 0; i < DimensionOf(TypeProcMmSA); i++)
  442. {
  443. if (TypeProcMmSA[i].dwType == dwSortType)
  444. {
  445. pNewIndex = new CColumnIndex(dwSortType, TypeProcMmSA[i].pCompareProc);
  446. break;
  447. }
  448. }
  449. Assert(pNewIndex);
  450. if (NULL == pNewIndex)
  451. {
  452. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  453. }
  454. // copy the array from the original index
  455. pNewIndex->Copy(m_DefaultIndex);
  456. pNewIndex->SetSortOption(dwSortOptions);
  457. pNewIndex->Sort();
  458. m_posCurrentIndex = m_listIndicies.AddTail(pNewIndex);
  459. return hr;
  460. }
  461. HRESULT
  462. CIndexMgrQmSA::Sort(
  463. DWORD dwSortType,
  464. DWORD dwSortOptions
  465. )
  466. {
  467. HRESULT hr = hrOK;
  468. POSITION posLast;
  469. POSITION pos;
  470. DWORD dwIndexType;
  471. pos = m_listIndicies.GetHeadPosition();
  472. while (pos)
  473. {
  474. posLast = pos;
  475. CColumnIndex * pIndex = m_listIndicies.GetNext(pos);
  476. dwIndexType = pIndex->GetType();
  477. // the index for this type already exists, just sort accordingly
  478. if (dwIndexType == dwSortType)
  479. {
  480. pIndex->SetSortOption(dwSortOptions);
  481. m_posCurrentIndex = posLast;
  482. return hrOK;
  483. }
  484. }
  485. // if not, create one
  486. CColumnIndex * pNewIndex = NULL;
  487. for (int i = 0; i < DimensionOf(TypeProcQmSA); i++)
  488. {
  489. if (TypeProcQmSA[i].dwType == dwSortType)
  490. {
  491. pNewIndex = new CColumnIndex(dwSortType, TypeProcQmSA[i].pCompareProc);
  492. break;
  493. }
  494. }
  495. Assert(pNewIndex);
  496. if (NULL == pNewIndex)
  497. {
  498. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  499. }
  500. // copy the array from the original index
  501. pNewIndex->Copy(m_DefaultIndex);
  502. pNewIndex->SetSortOption(dwSortOptions);
  503. pNewIndex->Sort();
  504. m_posCurrentIndex = m_listIndicies.AddTail(pNewIndex);
  505. return hr;
  506. }
  507. int __cdecl CompareFilterName(const void *elem1, const void *elem2)
  508. {
  509. CFilterInfo *pFilter1;
  510. CFilterInfo *pFilter2;
  511. pFilter1 = *((CFilterInfo**)elem1);
  512. pFilter2 = *((CFilterInfo**)elem2);
  513. return pFilter1->m_stName.CompareNoCase(pFilter2->m_stName);
  514. }
  515. int __cdecl CompareFilterSourceAddr(const void *elem1, const void *elem2)
  516. {
  517. CFilterInfo *pFilter1;
  518. CFilterInfo *pFilter2;
  519. pFilter1 = *((CFilterInfo**)elem1);
  520. pFilter2 = *((CFilterInfo**)elem2);
  521. CString str1;
  522. CString str2;
  523. AddressToString(pFilter1->m_SrcAddr, &str1);
  524. AddressToString(pFilter2->m_SrcAddr, &str2);
  525. return str1.CompareNoCase(str2);
  526. }
  527. int __cdecl CompareFilterDestAddr(const void *elem1, const void *elem2)
  528. {
  529. CFilterInfo *pFilter1;
  530. CFilterInfo *pFilter2;
  531. pFilter1 = *((CFilterInfo**)elem1);
  532. pFilter2 = *((CFilterInfo**)elem2);
  533. CString str1;
  534. CString str2;
  535. AddressToString(pFilter1->m_DesAddr, &str1);
  536. AddressToString(pFilter2->m_DesAddr, &str2);
  537. return str1.CompareNoCase(str2);
  538. }
  539. int __cdecl CompareFilterSrcPort(const void *elem1, const void *elem2)
  540. {
  541. CFilterInfo *pFilter1;
  542. CFilterInfo *pFilter2;
  543. pFilter1 = *((CFilterInfo**)elem1);
  544. pFilter2 = *((CFilterInfo**)elem2);
  545. return (int)pFilter1->m_SrcPort.wPort - (int)pFilter2->m_SrcPort.wPort;
  546. }
  547. int __cdecl CompareFilterDestPort(const void *elem1, const void *elem2)
  548. {
  549. CFilterInfo *pFilter1;
  550. CFilterInfo *pFilter2;
  551. pFilter1 = *((CFilterInfo**)elem1);
  552. pFilter2 = *((CFilterInfo**)elem2);
  553. return (int)pFilter1->m_DesPort.wPort - (int)pFilter2->m_DesPort.wPort;
  554. }
  555. int __cdecl CompareFilterSrcTnl(const void *elem1, const void *elem2)
  556. {
  557. CFilterInfo *pFilter1;
  558. CFilterInfo *pFilter2;
  559. pFilter1 = *((CFilterInfo**)elem1);
  560. pFilter2 = *((CFilterInfo**)elem2);
  561. CString str1;
  562. CString str2;
  563. TnlEpToString(pFilter1->m_FilterType, pFilter1->m_MyTnlAddr, &str1);
  564. TnlEpToString(pFilter2->m_FilterType, pFilter2->m_MyTnlAddr, &str2);
  565. return str1.CompareNoCase(str2);
  566. }
  567. int __cdecl CompareFilterDestTnl(const void *elem1, const void *elem2)
  568. {
  569. CFilterInfo *pFilter1;
  570. CFilterInfo *pFilter2;
  571. pFilter1 = *((CFilterInfo**)elem1);
  572. pFilter2 = *((CFilterInfo**)elem2);
  573. CString str1;
  574. CString str2;
  575. TnlEpToString(pFilter1->m_FilterType, pFilter1->m_PeerTnlAddr, &str1);
  576. TnlEpToString(pFilter2->m_FilterType, pFilter2->m_PeerTnlAddr, &str2);
  577. return str1.CompareNoCase(str2);
  578. }
  579. int __cdecl CompareFilterProtocol(const void *elem1, const void *elem2)
  580. {
  581. CFilterInfo *pFilter1;
  582. CFilterInfo *pFilter2;
  583. pFilter1 = *((CFilterInfo**)elem1);
  584. pFilter2 = *((CFilterInfo**)elem2);
  585. CString st1;
  586. CString st2;
  587. ProtocolToString(pFilter1->m_Protocol, &st1);
  588. ProtocolToString(pFilter2->m_Protocol, &st2);
  589. return st1.CompareNoCase(st2);
  590. }
  591. int __cdecl CompareFilterDirection(const void *elem1, const void *elem2)
  592. {
  593. CFilterInfo *pFilter1;
  594. CFilterInfo *pFilter2;
  595. pFilter1 = *((CFilterInfo**)elem1);
  596. pFilter2 = *((CFilterInfo**)elem2);
  597. CString st1;
  598. CString st2;
  599. DirectionToString(pFilter1->m_dwDirection, &st1);
  600. DirectionToString(pFilter2->m_dwDirection, &st2);
  601. return st1.CompareNoCase(st2);
  602. }
  603. int __cdecl CompareFilterPolicyName(const void *elem1, const void *elem2)
  604. {
  605. CFilterInfo *pFilter1;
  606. CFilterInfo *pFilter2;
  607. pFilter1 = *((CFilterInfo**)elem1);
  608. pFilter2 = *((CFilterInfo**)elem2);
  609. return pFilter1->m_stPolicyName.CompareNoCase(pFilter2->m_stPolicyName);
  610. }
  611. int __cdecl CompareFilterIfType(const void *elem1, const void *elem2)
  612. {
  613. CFilterInfo *pFilter1;
  614. CFilterInfo *pFilter2;
  615. pFilter1 = *((CFilterInfo**)elem1);
  616. pFilter2 = *((CFilterInfo**)elem2);
  617. CString st1;
  618. CString st2;
  619. InterfaceTypeToString(pFilter1->m_InterfaceType, &st1);
  620. InterfaceTypeToString(pFilter2->m_InterfaceType, &st2);
  621. return st1.CompareNoCase(st2);
  622. }
  623. int __cdecl CompareFilterOutboundFlag(const void *elem1, const void *elem2)
  624. {
  625. CFilterInfo *pFilter1;
  626. CFilterInfo *pFilter2;
  627. pFilter1 = *((CFilterInfo**)elem1);
  628. pFilter2 = *((CFilterInfo**)elem2);
  629. CString st1;
  630. CString st2;
  631. FilterFlagToString(pFilter1->m_OutboundFilterAction, &st1);
  632. FilterFlagToString(pFilter2->m_OutboundFilterAction, &st2);
  633. return st1.CompareNoCase(st2);
  634. }
  635. int __cdecl CompareFilterInboundFlag(const void *elem1, const void *elem2)
  636. {
  637. CFilterInfo *pFilter1;
  638. CFilterInfo *pFilter2;
  639. pFilter1 = *((CFilterInfo**)elem1);
  640. pFilter2 = *((CFilterInfo**)elem2);
  641. CString st1;
  642. CString st2;
  643. FilterFlagToString(pFilter1->m_InboundFilterAction, &st1);
  644. FilterFlagToString(pFilter2->m_InboundFilterAction, &st2);
  645. return st1.CompareNoCase(st2);
  646. }
  647. int __cdecl CompareFilterFlag(const void *elem1, const void *elem2)
  648. {
  649. CFilterInfo *pFilter1;
  650. CFilterInfo *pFilter2;
  651. pFilter1 = *((CFilterInfo**)elem1);
  652. pFilter2 = *((CFilterInfo**)elem2);
  653. CString st1;
  654. CString st2;
  655. FilterFlagToString(
  656. (FILTER_DIRECTION_INBOUND == pFilter1->m_dwDirection) ?
  657. pFilter1->m_InboundFilterAction : pFilter1->m_OutboundFilterAction,
  658. &st1
  659. );
  660. FilterFlagToString(
  661. (FILTER_DIRECTION_INBOUND == pFilter2->m_dwDirection) ?
  662. pFilter2->m_InboundFilterAction : pFilter2->m_OutboundFilterAction,
  663. &st2
  664. );
  665. return st1.CompareNoCase(st2);
  666. }
  667. int __cdecl CompareFilterWeight(const void *elem1, const void *elem2)
  668. {
  669. CFilterInfo *pFilter1;
  670. CFilterInfo *pFilter2;
  671. pFilter1 = *((CFilterInfo**)elem1);
  672. pFilter2 = *((CFilterInfo**)elem2);
  673. return (int)pFilter1->m_dwWeight - (int)pFilter2->m_dwWeight;
  674. }
  675. int __cdecl CompareMmFilterName(const void *elem1, const void *elem2)
  676. {
  677. CMmFilterInfo *pFilter1;
  678. CMmFilterInfo *pFilter2;
  679. pFilter1 = *((CMmFilterInfo**)elem1);
  680. pFilter2 = *((CMmFilterInfo**)elem2);
  681. return pFilter1->m_stName.CompareNoCase(pFilter2->m_stName);
  682. }
  683. int __cdecl CompareMmFilterSourceAddr(const void *elem1, const void *elem2)
  684. {
  685. CMmFilterInfo *pFilter1;
  686. CMmFilterInfo *pFilter2;
  687. pFilter1 = *((CMmFilterInfo**)elem1);
  688. pFilter2 = *((CMmFilterInfo**)elem2);
  689. CString str1;
  690. CString str2;
  691. AddressToString(pFilter1->m_SrcAddr, &str1);
  692. AddressToString(pFilter2->m_SrcAddr, &str2);
  693. return str1.CompareNoCase(str2);
  694. }
  695. int __cdecl CompareMmFilterDestAddr(const void *elem1, const void *elem2)
  696. {
  697. CMmFilterInfo *pFilter1;
  698. CMmFilterInfo *pFilter2;
  699. pFilter1 = *((CMmFilterInfo**)elem1);
  700. pFilter2 = *((CMmFilterInfo**)elem2);
  701. CString str1;
  702. CString str2;
  703. AddressToString(pFilter1->m_DesAddr, &str1);
  704. AddressToString(pFilter2->m_DesAddr, &str2);
  705. return str1.CompareNoCase(str2);
  706. }
  707. int __cdecl CompareMmFilterDirection(const void *elem1, const void *elem2)
  708. {
  709. CMmFilterInfo *pFilter1;
  710. CMmFilterInfo *pFilter2;
  711. pFilter1 = *((CMmFilterInfo**)elem1);
  712. pFilter2 = *((CMmFilterInfo**)elem2);
  713. CString st1;
  714. CString st2;
  715. DirectionToString(pFilter1->m_dwDirection, &st1);
  716. DirectionToString(pFilter2->m_dwDirection, &st2);
  717. return st1.CompareNoCase(st2);
  718. }
  719. int __cdecl CompareMmFilterWeight(const void *elem1, const void *elem2)
  720. {
  721. CMmFilterInfo *pFilter1;
  722. CMmFilterInfo *pFilter2;
  723. pFilter1 = *((CMmFilterInfo**)elem1);
  724. pFilter2 = *((CMmFilterInfo**)elem2);
  725. return (int)pFilter1->m_dwWeight - (int)pFilter2->m_dwWeight;
  726. }
  727. int __cdecl CompareMmFilterPolicyName(const void *elem1, const void *elem2)
  728. {
  729. CMmFilterInfo *pFilter1;
  730. CMmFilterInfo *pFilter2;
  731. pFilter1 = *((CMmFilterInfo**)elem1);
  732. pFilter2 = *((CMmFilterInfo**)elem2);
  733. return pFilter1->m_stPolicyName.CompareNoCase(pFilter2->m_stPolicyName);
  734. }
  735. int __cdecl CompareMmFilterAuth(const void *elem1, const void *elem2)
  736. {
  737. CMmFilterInfo *pFilter1;
  738. CMmFilterInfo *pFilter2;
  739. pFilter1 = *((CMmFilterInfo**)elem1);
  740. pFilter2 = *((CMmFilterInfo**)elem2);
  741. return pFilter1->m_stAuthDescription.CompareNoCase(pFilter2->m_stAuthDescription);
  742. }
  743. int __cdecl CompareMmFilterIfType(const void *elem1, const void *elem2)
  744. {
  745. CMmFilterInfo *pFilter1;
  746. CMmFilterInfo *pFilter2;
  747. pFilter1 = *((CMmFilterInfo**)elem1);
  748. pFilter2 = *((CMmFilterInfo**)elem2);
  749. CString str1;
  750. CString str2;
  751. InterfaceTypeToString(pFilter1->m_InterfaceType, &str1);
  752. InterfaceTypeToString(pFilter2->m_InterfaceType, &str2);
  753. return str1.CompareNoCase(str2);
  754. }
  755. int __cdecl CompareMmPolicyName(const void *elem1, const void *elem2)
  756. {
  757. CMmPolicyInfo * pPolicy1;
  758. CMmPolicyInfo * pPolicy2;
  759. pPolicy1 = *((CMmPolicyInfo**)elem1);
  760. pPolicy2 = *((CMmPolicyInfo**)elem2);
  761. return pPolicy1->m_stName.CompareNoCase(pPolicy2->m_stName);
  762. }
  763. int __cdecl CompareMmPolicyOfferNumber(const void *elem1, const void *elem2)
  764. {
  765. CMmPolicyInfo * pPolicy1;
  766. CMmPolicyInfo * pPolicy2;
  767. pPolicy1 = *((CMmPolicyInfo**)elem1);
  768. pPolicy2 = *((CMmPolicyInfo**)elem2);
  769. return pPolicy1->m_dwOfferCount - pPolicy2->m_dwOfferCount;
  770. }
  771. int __cdecl CompareQmPolicyName(const void *elem1, const void *elem2)
  772. {
  773. CQmPolicyInfo * pPolicy1;
  774. CQmPolicyInfo * pPolicy2;
  775. pPolicy1 = *((CQmPolicyInfo**)elem1);
  776. pPolicy2 = *((CQmPolicyInfo**)elem2);
  777. return pPolicy1->m_stName.CompareNoCase(pPolicy2->m_stName);
  778. }
  779. int __cdecl CompareQmPolicyOfferNumber(const void *elem1, const void *elem2)
  780. {
  781. CQmPolicyInfo * pPolicy1;
  782. CQmPolicyInfo * pPolicy2;
  783. pPolicy1 = *((CQmPolicyInfo**)elem1);
  784. pPolicy2 = *((CQmPolicyInfo**)elem2);
  785. return (int)(pPolicy1->m_arrOffers.GetSize() - pPolicy2->m_arrOffers.GetSize());
  786. }
  787. int __cdecl CompareMmSAMeAddr(const void *elem1, const void *elem2)
  788. {
  789. CMmSA * pSA1;
  790. CMmSA * pSA2;
  791. CString st1;
  792. CString st2;
  793. pSA1 = *((CMmSA**)elem1);
  794. pSA2 = *((CMmSA**)elem2);
  795. AddressToString(pSA1->m_MeAddr, &st1);
  796. AddressToString(pSA2->m_MeAddr, &st2);
  797. return st1.CompareNoCase(st2);
  798. }
  799. int __cdecl CompareMmSAPeerAddr(const void *elem1, const void *elem2)
  800. {
  801. CMmSA * pSA1;
  802. CMmSA * pSA2;
  803. CString st1;
  804. CString st2;
  805. pSA1 = *((CMmSA**)elem1);
  806. pSA2 = *((CMmSA**)elem2);
  807. AddressToString(pSA1->m_PeerAddr, &st1);
  808. AddressToString(pSA2->m_PeerAddr, &st2);
  809. return st1.CompareNoCase(st2);
  810. }
  811. int __cdecl CompareMmSAAuth(const void *elem1, const void *elem2)
  812. {
  813. CMmSA * pSA1;
  814. CMmSA * pSA2;
  815. CString st1;
  816. CString st2;
  817. pSA1 = *((CMmSA**)elem1);
  818. pSA2 = *((CMmSA**)elem2);
  819. MmAuthToString(pSA1->m_Auth, &st1);
  820. MmAuthToString(pSA2->m_Auth, &st2);
  821. return st1.CompareNoCase(st2);
  822. }
  823. int __cdecl CompareMmSAEncryption(const void *elem1, const void *elem2)
  824. {
  825. CMmSA * pSA1;
  826. CMmSA * pSA2;
  827. CString st1;
  828. CString st2;
  829. pSA1 = *((CMmSA**)elem1);
  830. pSA2 = *((CMmSA**)elem2);
  831. DoiEspAlgorithmToString(pSA1->m_SelectedOffer.m_EncryptionAlgorithm, &st1);
  832. DoiEspAlgorithmToString(pSA2->m_SelectedOffer.m_EncryptionAlgorithm, &st2);
  833. return st1.CompareNoCase(st2);
  834. }
  835. int __cdecl CompareMmSAIntegrity(const void *elem1, const void *elem2)
  836. {
  837. CMmSA * pSA1;
  838. CMmSA * pSA2;
  839. CString st1;
  840. CString st2;
  841. pSA1 = *((CMmSA**)elem1);
  842. pSA2 = *((CMmSA**)elem2);
  843. DoiAuthAlgorithmToString(pSA1->m_SelectedOffer.m_HashingAlgorithm, &st1);
  844. DoiAuthAlgorithmToString(pSA2->m_SelectedOffer.m_HashingAlgorithm, &st2);
  845. return st1.CompareNoCase(st2);
  846. }
  847. int __cdecl CompareMmSADhGroup(const void *elem1, const void *elem2)
  848. {
  849. CMmSA * pSA1;
  850. CMmSA * pSA2;
  851. CString st1;
  852. CString st2;
  853. pSA1 = *((CMmSA**)elem1);
  854. pSA2 = *((CMmSA**)elem2);
  855. DhGroupToString(pSA1->m_SelectedOffer.m_dwDHGroup, &st1);
  856. DhGroupToString(pSA2->m_SelectedOffer.m_dwDHGroup, &st2);
  857. return st1.CompareNoCase(st2);
  858. }
  859. int __cdecl CompareQmSAPolicyName(const void *elem1, const void *elem2)
  860. {
  861. CQmSA * pSA1;
  862. CQmSA * pSA2;
  863. pSA1 = *((CQmSA**)elem1);
  864. pSA2 = *((CQmSA**)elem2);
  865. return pSA1->m_stPolicyName.CompareNoCase(pSA2->m_stPolicyName);
  866. }
  867. int __cdecl CompareQmSAAuth(const void *elem1, const void *elem2)
  868. {
  869. CQmSA * pSA1;
  870. CQmSA * pSA2;
  871. CString st1;
  872. CString st2;
  873. pSA1 = *((CQmSA**)elem1);
  874. pSA2 = *((CQmSA**)elem2);
  875. QmAlgorithmToString(QM_ALGO_AUTH, &pSA1->m_SelectedOffer, &st1);
  876. QmAlgorithmToString(QM_ALGO_AUTH, &pSA2->m_SelectedOffer, &st2);
  877. return st1.CompareNoCase(st2);
  878. }
  879. int __cdecl CompareQmSAConf(const void *elem1, const void *elem2)
  880. {
  881. CQmSA * pSA1;
  882. CQmSA * pSA2;
  883. CString st1;
  884. CString st2;
  885. pSA1 = *((CQmSA**)elem1);
  886. pSA2 = *((CQmSA**)elem2);
  887. QmAlgorithmToString(QM_ALGO_ESP_CONF, &pSA1->m_SelectedOffer, &st1);
  888. QmAlgorithmToString(QM_ALGO_ESP_CONF, &pSA2->m_SelectedOffer, &st2);
  889. return st1.CompareNoCase(st2);
  890. }
  891. int __cdecl CompareQmSAIntegrity(const void *elem1, const void *elem2)
  892. {
  893. CQmSA * pSA1;
  894. CQmSA * pSA2;
  895. CString st1;
  896. CString st2;
  897. pSA1 = *((CQmSA**)elem1);
  898. pSA2 = *((CQmSA**)elem2);
  899. QmAlgorithmToString(QM_ALGO_ESP_INTEG, &pSA1->m_SelectedOffer, &st1);
  900. QmAlgorithmToString(QM_ALGO_ESP_INTEG, &pSA2->m_SelectedOffer, &st2);
  901. return st1.CompareNoCase(st2);
  902. }
  903. int __cdecl CompareQmSASrc(const void *elem1, const void *elem2)
  904. {
  905. CQmSA * pSA1;
  906. CQmSA * pSA2;
  907. CString st1;
  908. CString st2;
  909. pSA1 = *((CQmSA**)elem1);
  910. pSA2 = *((CQmSA**)elem2);
  911. AddressToString(pSA1->m_QmDriverFilter.m_SrcAddr, &st1);
  912. AddressToString(pSA2->m_QmDriverFilter.m_SrcAddr, &st2);
  913. return st1.CompareNoCase(st2);
  914. }
  915. int __cdecl CompareQmSADest(const void *elem1, const void *elem2)
  916. {
  917. CQmSA * pSA1;
  918. CQmSA * pSA2;
  919. CString st1;
  920. CString st2;
  921. pSA1 = *((CQmSA**)elem1);
  922. pSA2 = *((CQmSA**)elem2);
  923. AddressToString(pSA1->m_QmDriverFilter.m_DesAddr, &st1);
  924. AddressToString(pSA2->m_QmDriverFilter.m_DesAddr, &st2);
  925. return st1.CompareNoCase(st2);
  926. }
  927. int __cdecl CompareQmSAProtocol(const void *elem1, const void *elem2)
  928. {
  929. CQmSA * pSA1;
  930. CQmSA * pSA2;
  931. CString st1;
  932. CString st2;
  933. pSA1 = *((CQmSA**)elem1);
  934. pSA2 = *((CQmSA**)elem2);
  935. ProtocolToString(pSA1->m_QmDriverFilter.m_Protocol, &st1);
  936. ProtocolToString(pSA2->m_QmDriverFilter.m_Protocol, &st2);
  937. return st1.CompareNoCase(st2);
  938. }
  939. int __cdecl CompareQmSASrcPort(const void *elem1, const void *elem2)
  940. {
  941. CQmSA * pSA1;
  942. CQmSA * pSA2;
  943. CString st1;
  944. CString st2;
  945. pSA1 = *((CQmSA**)elem1);
  946. pSA2 = *((CQmSA**)elem2);
  947. PortToString(pSA1->m_QmDriverFilter.m_SrcPort, &st1);
  948. PortToString(pSA2->m_QmDriverFilter.m_SrcPort, &st2);
  949. return st1.CompareNoCase(st2);
  950. }
  951. int __cdecl CompareQmSADestPort(const void *elem1, const void *elem2)
  952. {
  953. CQmSA * pSA1;
  954. CQmSA * pSA2;
  955. CString st1;
  956. CString st2;
  957. pSA1 = *((CQmSA**)elem1);
  958. pSA2 = *((CQmSA**)elem2);
  959. PortToString(pSA1->m_QmDriverFilter.m_DesPort, &st1);
  960. PortToString(pSA2->m_QmDriverFilter.m_DesPort, &st2);
  961. return st1.CompareNoCase(st2);
  962. }
  963. int __cdecl CompareQmSAMyTnlEp(const void *elem1, const void *elem2)
  964. {
  965. CQmSA * pSA1;
  966. CQmSA * pSA2;
  967. CString st1;
  968. CString st2;
  969. pSA1 = *((CQmSA**)elem1);
  970. pSA2 = *((CQmSA**)elem2);
  971. TnlEpToString(pSA1->m_QmDriverFilter.m_Type,
  972. pSA1->m_QmDriverFilter.m_MyTunnelEndpt,
  973. &st1);
  974. TnlEpToString(pSA2->m_QmDriverFilter.m_Type,
  975. pSA2->m_QmDriverFilter.m_MyTunnelEndpt,
  976. &st2);
  977. return st1.CompareNoCase(st2);
  978. }
  979. int __cdecl CompareQmSAPeerTnlEp(const void *elem1, const void *elem2)
  980. {
  981. CQmSA * pSA1;
  982. CQmSA * pSA2;
  983. CString st1;
  984. CString st2;
  985. pSA1 = *((CQmSA**)elem1);
  986. pSA2 = *((CQmSA**)elem2);
  987. TnlEpToString(pSA1->m_QmDriverFilter.m_Type,
  988. pSA1->m_QmDriverFilter.m_PeerTunnelEndpt,
  989. &st1);
  990. TnlEpToString(pSA2->m_QmDriverFilter.m_Type,
  991. pSA2->m_QmDriverFilter.m_PeerTunnelEndpt,
  992. &st2);
  993. return st1.CompareNoCase(st2);
  994. }