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.

151 lines
4.0 KiB

  1. //
  2. // MODULE: SNIFFCONTROLLERLOCAL.CPP
  3. //
  4. // PURPOSE: sniff controller class for Local TS
  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: Concrete implementation of CSniffController class for Local TS
  13. //
  14. // Version Date By Comments
  15. //--------------------------------------------------------------------
  16. // V3.2 12-11-98 OK
  17. //
  18. #include "stdafx.h"
  19. #include "tshoot.h"
  20. #include "SniffControllerLocal.h"
  21. #include "Topic.h"
  22. #include "propnames.h"
  23. #ifdef _DEBUG
  24. #undef THIS_FILE
  25. static char THIS_FILE[]=__FILE__;
  26. #define new DEBUG_NEW
  27. #endif
  28. // Network property values from DSC/XTS file.
  29. #define SNIFF_LOCAL_YES _T("yes")
  30. #define SNIFF_LOCAL_NO _T("no")
  31. #define SNIFF_LOCAL_IMPLICIT _T("implicit")
  32. #define SNIFF_LOCAL_EXPLICIT _T("explicit")
  33. //////////////////////////////////////////////////////////////////////
  34. // CSniffControllerLocal implementation
  35. //////////////////////////////////////////////////////////////////////
  36. CSniffControllerLocal::CSniffControllerLocal(CTopic* pTopic)
  37. : m_pTopic(pTopic)
  38. {
  39. }
  40. CSniffControllerLocal::~CSniffControllerLocal()
  41. {
  42. }
  43. // This function provides us with a cheap test for existence of the sniffing property,
  44. // so that (for example) we don't have to fire the sniffing event for nodes where
  45. // sniffing is irrelevant.
  46. bool CSniffControllerLocal::IsSniffable(NID numNodeID)
  47. {
  48. CString str = m_pTopic->GetNodePropItemStr(numNodeID, H_NODE_SNIFF_SCRIPT);
  49. return !str.IsEmpty();
  50. }
  51. void CSniffControllerLocal::SetTopic(CTopic* pTopic)
  52. {
  53. m_pTopic = pTopic;
  54. }
  55. bool CSniffControllerLocal::AllowAutomaticOnStartSniffing(NID numNodeID)
  56. {
  57. if (!IsSniffable(numNodeID))
  58. return false;
  59. return CheckNetNodePropBool(H_NET_MAY_SNIFF_ON_STARTUP,
  60. H_NODE_MAY_SNIFF_ON_STARTUP,
  61. numNodeID)
  62. &&
  63. GetAllowAutomaticSniffingPolicy();
  64. }
  65. bool CSniffControllerLocal::AllowAutomaticOnFlySniffing(NID numNodeID)
  66. {
  67. if (!IsSniffable(numNodeID))
  68. return false;
  69. return CheckNetNodePropBool(H_NET_MAY_SNIFF_ON_FLY,
  70. H_NODE_MAY_SNIFF_ON_FLY,
  71. numNodeID)
  72. &&
  73. GetAllowAutomaticSniffingPolicy();
  74. }
  75. bool CSniffControllerLocal::AllowManualSniffing(NID numNodeID)
  76. {
  77. if (!IsSniffable(numNodeID))
  78. return false;
  79. return CheckNetNodePropBool(H_NET_MAY_SNIFF_MANUALLY,
  80. H_NODE_MAY_SNIFF_MANUALLY,
  81. numNodeID)
  82. &&
  83. GetAllowManualSniffingPolicy();
  84. }
  85. bool CSniffControllerLocal::AllowResniff(NID numNodeID)
  86. {
  87. if (!IsSniffable(numNodeID))
  88. return false;
  89. if (!GetAllowAutomaticSniffingPolicy())
  90. return false;
  91. CString net_resniff_policy = m_pTopic->GetNetPropItemStr(H_NET_RESNIFF_POLICY);
  92. net_resniff_policy.TrimLeft();
  93. net_resniff_policy.TrimRight();
  94. net_resniff_policy.MakeLower();
  95. if (net_resniff_policy == SNIFF_LOCAL_YES)
  96. return true;
  97. if (net_resniff_policy == SNIFF_LOCAL_NO)
  98. return false;
  99. // If we get this far, policy is left up to the individual node, so we need to know
  100. // the node's policy.
  101. CString node_resniff_policy = m_pTopic->GetNodePropItemStr(numNodeID, H_NODE_MAY_RESNIFF);
  102. node_resniff_policy.TrimLeft();
  103. node_resniff_policy.TrimRight();
  104. node_resniff_policy.MakeLower();
  105. if (net_resniff_policy == SNIFF_LOCAL_IMPLICIT)
  106. {
  107. return (node_resniff_policy != SNIFF_LOCAL_NO);
  108. }
  109. // default net policy is "explicit"
  110. return (node_resniff_policy == SNIFF_LOCAL_YES);
  111. }
  112. bool CSniffControllerLocal::CheckNetNodePropBool(LPCTSTR net_prop, LPCTSTR node_prop, NID node_id)
  113. {
  114. CString net = m_pTopic->GetNetPropItemStr(net_prop);
  115. CString node = m_pTopic->GetNodePropItemStr(node_id, node_prop);
  116. net. TrimLeft(); net .TrimRight(); net. MakeLower();
  117. node.TrimLeft(); node.TrimRight(); node.MakeLower();
  118. // Note assumption: if property is missing, default is always yes.
  119. if ((net.IsEmpty() || net == SNIFF_LOCAL_YES) && (node.IsEmpty() || node == SNIFF_LOCAL_YES))
  120. return true;
  121. return false;
  122. }