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

165 lines
3.6 KiB

  1. //
  2. // MODULE: SNIFF.CPP
  3. //
  4. // PURPOSE: sniffing class
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Oleg Kalosha
  9. //
  10. // ORIGINAL DATE: 12-11-98
  11. //
  12. // NOTES: This is base abstract class which performs sniffing
  13. //
  14. // Version Date By Comments
  15. //--------------------------------------------------------------------
  16. // V3.2 12-11-98 OK
  17. //
  18. #pragma warning(disable:4786)
  19. #include "stdafx.h"
  20. #include "Sniff.h"
  21. #include "SniffConnector.h"
  22. #include "SniffController.h"
  23. #include "Topic.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[]=__FILE__;
  27. #define new DEBUG_NEW
  28. #endif
  29. // the problem is, that JavaScript returns 0xffffffff, but VBScript returns
  30. // 0x0000ffff, so we define SNIFF_FAIL_MASK as 0x0000ffff and use it as mask to
  31. // determine if sniffing was successful. Expression 0xffffffff & SNIFF_FAIL_MASK
  32. // will have the same result as expression 0x0000ffff & SNIFF_FAIL_MASK.
  33. // This define SHOULD NOT BE USED OUTSIDE THIS FILE!
  34. #define SNIFF_FAIL_MASK 0x0000ffff
  35. //////////////////////////////////////////////////////////////////////////////////////
  36. // CSniff implementation
  37. // called as public interface function when resniffing
  38. bool CSniff::Resniff(CSniffedArr& arrSniffed)
  39. {
  40. bool ret = false;
  41. LOCKOBJECT();
  42. for (CSniffedArr::iterator i = arrSniffed.begin(); i < arrSniffed.end(); i++)
  43. {
  44. IST state = SNIFF_FAILURE_RESULT;
  45. if (GetSniffController()->AllowResniff(i->nid()))
  46. {
  47. if (SniffNodeInternal(i->nid(), &state))
  48. {
  49. if (state != i->state())
  50. {
  51. *i = CNodeStatePair(i->nid(), state);
  52. ret = true;
  53. }
  54. }
  55. else
  56. {
  57. arrSniffed.erase(i);
  58. i--;
  59. ret = true;
  60. }
  61. }
  62. }
  63. UNLOCKOBJECT();
  64. return ret;
  65. }
  66. // called as public interface function when sniffing on start up
  67. bool CSniff::SniffAll(CSniffedArr& arrOut)
  68. {
  69. bool ret = false;
  70. vector<NID> arrNodes;
  71. vector<ESTDLBL> arrTypeExclude;
  72. LOCKOBJECT();
  73. arrTypeExclude.push_back(ESTDLBL_problem);
  74. arrOut.clear();
  75. if (GetTopic()->GetNodeArrayExcludeType(arrNodes, arrTypeExclude))
  76. {
  77. for (vector<NID>::iterator i = arrNodes.begin(); i < arrNodes.end(); i++)
  78. {
  79. if (GetSniffController()->AllowAutomaticOnStartSniffing(*i))
  80. {
  81. IST state = SNIFF_FAILURE_RESULT;
  82. if (SniffNodeInternal(*i, &state))
  83. {
  84. arrOut.push_back(CNodeStatePair(*i, state));
  85. ret = true;
  86. }
  87. }
  88. }
  89. }
  90. UNLOCKOBJECT();
  91. return ret;
  92. }
  93. // called as public interface function when sniffing on the fly
  94. bool CSniff::SniffNode(NID numNodeID, IST* pnumNodeState)
  95. {
  96. bool ret = false;
  97. LOCKOBJECT();
  98. if (GetSniffController()->AllowAutomaticOnFlySniffing(numNodeID))
  99. ret = SniffNodeInternal(numNodeID, pnumNodeState);
  100. UNLOCKOBJECT();
  101. return ret;
  102. }
  103. bool CSniff::SniffNodeInternal(NID numNodeID, IST* pnumNodeState)
  104. {
  105. CString strNodeName;
  106. if (!GetTopic()->IsRead())
  107. return false;
  108. strNodeName = GetTopic()->GetNodeSymName(numNodeID);
  109. if (strNodeName.IsEmpty())
  110. return false;
  111. long res = GetSniffConnector()->PerformSniffing(strNodeName, _T(""), _T(""));
  112. if ((res & SNIFF_FAIL_MASK) == SNIFF_FAIL_MASK)
  113. {
  114. *pnumNodeState = SNIFF_FAILURE_RESULT;
  115. return false;
  116. }
  117. *pnumNodeState = res;
  118. return true;
  119. }
  120. void CSniff::SetAllowAutomaticSniffingPolicy(bool set)
  121. {
  122. GetSniffController()->SetAllowAutomaticSniffingPolicy(set);
  123. }
  124. void CSniff::SetAllowManualSniffingPolicy(bool set)
  125. {
  126. GetSniffController()->SetAllowManualSniffingPolicy(set);
  127. }
  128. bool CSniff::GetAllowAutomaticSniffingPolicy()
  129. {
  130. return GetSniffController()->GetAllowAutomaticSniffingPolicy();
  131. }
  132. bool CSniff::GetAllowManualSniffingPolicy()
  133. {
  134. return GetSniffController()->GetAllowManualSniffingPolicy();
  135. }