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.

196 lines
3.9 KiB

  1. //
  2. // MODULE: SNIFF.CPP
  3. //
  4. // PURPOSE: sniffed data container
  5. //
  6. // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint
  7. //
  8. // COMPANY: Saltmine Creative, Inc. (206)-633-4743 [email protected]
  9. //
  10. // AUTHOR: Oleg Kalosha
  11. //
  12. // ORIGINAL DATE: 3-27-99
  13. //
  14. // NOTES:
  15. // 1. Based on Print Troubleshooter DLL
  16. //
  17. // Version Date By Comments
  18. //--------------------------------------------------------------------
  19. // V0.1 - RM Original
  20. // V0.2 6/4/97 RWM Local Version for Memphis
  21. // V0.3 3/24/98 JM Local Version for NT5
  22. #include "stdafx.h"
  23. #include "sniff.h"
  24. #include "apgts.h"
  25. #include "bnts.h"
  26. #include "BackupInfo.h"
  27. #include "cachegen.h"
  28. #include "apgtsinf.h"
  29. //////////////////////////////////////////////////////////////////////////////////////
  30. // CSniffedNodeContainer class definition
  31. //
  32. CSniffedNodeContainer::CSniffedNodeContainer()
  33. : m_pBNTS(NULL)
  34. {
  35. }
  36. CSniffedNodeContainer::CSniffedNodeContainer(GTSAPI* bnts)
  37. : m_pBNTS(bnts)
  38. {
  39. }
  40. CSniffedNodeContainer::~CSniffedNodeContainer()
  41. {
  42. }
  43. void CSniffedNodeContainer::SetBNTS(GTSAPI* bnts)
  44. {
  45. m_pBNTS = bnts;
  46. }
  47. inline GTSAPI* CSniffedNodeContainer::GetBNTS()
  48. {
  49. return m_pBNTS;
  50. }
  51. bool CSniffedNodeContainer::AddNode(CString name, int state)
  52. {
  53. if (GetBNTS())
  54. {
  55. CSniffedNodeInfo info(name, state);
  56. // use GTSAPI:: since it should be unicode - compliant
  57. if (SNIFF_INVALID_NODE_ID != (info.m_iId = m_pBNTS->GTSAPI::INode(LPCTSTR(name))))
  58. {
  59. if (!HasNode(info.m_iId))
  60. {
  61. m_arrInfo.Add(info);
  62. return true;
  63. }
  64. }
  65. }
  66. return false;
  67. }
  68. bool CSniffedNodeContainer::ResetIds()
  69. {
  70. CArray<CSniffedNodeInfo, CSniffedNodeInfo&> tmp;
  71. tmp.Copy(m_arrInfo);
  72. Flush();
  73. for (int i = 0; i < m_arrInfo.GetSize(); i++)
  74. {
  75. if (!AddNode(m_arrInfo[i].m_strName, m_arrInfo[i].m_iState))
  76. {
  77. m_arrInfo.Copy(tmp);
  78. return false;
  79. }
  80. }
  81. return true;
  82. }
  83. bool CSniffedNodeContainer::HasNode(int id)
  84. {
  85. for (int i = 0; i < m_arrInfo.GetSize(); i++)
  86. if (m_arrInfo[i].m_iId == id)
  87. return true;
  88. return false;
  89. }
  90. bool CSniffedNodeContainer::GetState(int id, int* state)
  91. {
  92. for (int i = 0; i < m_arrInfo.GetSize(); i++)
  93. {
  94. if (m_arrInfo[i].m_iId == id)
  95. {
  96. *state = m_arrInfo[i].m_iState;
  97. return true;
  98. }
  99. }
  100. return false;
  101. }
  102. inline
  103. bool CSniffedNodeContainer::IsEmpty()
  104. {
  105. return 0 == m_arrInfo.GetSize();
  106. }
  107. void CSniffedNodeContainer::Flush()
  108. {
  109. m_arrInfo.RemoveAll();
  110. }
  111. CSniffedNodeInfo* CSniffedNodeContainer::GetInfo(int id)
  112. {
  113. for (int i = 0; i < m_arrInfo.GetSize(); i++)
  114. if (m_arrInfo[i].m_iId == id)
  115. return &m_arrInfo[i];
  116. return NULL;
  117. }
  118. bool CSniffedNodeContainer::GetLabel(int id, int* label)
  119. {
  120. for (int i = 0; i < m_arrInfo.GetSize(); i++)
  121. {
  122. if (m_arrInfo[i].m_iId == id)
  123. {
  124. if (SNIFF_INVALID_NODE_LABEL != m_arrInfo[i].m_iLabel)
  125. {
  126. *label = m_arrInfo[i].m_iLabel;
  127. }
  128. else
  129. {
  130. if (GetLabelFromBNTS(id, label))
  131. {
  132. // once we have got label from BNTS - save it
  133. m_arrInfo[i].m_iLabel = *label;
  134. }
  135. else
  136. {
  137. return false;
  138. }
  139. }
  140. return true;
  141. }
  142. }
  143. return false;
  144. }
  145. bool CSniffedNodeContainer::GetLabelFromBNTS(int node, int* label)
  146. {
  147. // work strictly with BNTS class
  148. int old_node = m_pBNTS->BNTS::INodeCurrent();
  149. if (m_pBNTS->BNTS::BNodeSetCurrent(node))
  150. {
  151. *label = m_pBNTS->BNTS::ELblNode();
  152. m_pBNTS->BNTS::BNodeSetCurrent(old_node); // we do not check if successful - old_node might be -1
  153. return true;
  154. }
  155. return false;
  156. }
  157. int CSniffedNodeContainer::GetSniffedFixobsThatWorked()
  158. {
  159. for (int i = 0; i < m_arrInfo.GetSize(); i++)
  160. {
  161. int label = SNIFF_INVALID_NODE_LABEL;
  162. if (GetLabel(m_arrInfo[i].m_iId, &label) && // fixobs node is set to 1 - WORKED!
  163. ESTDLBL_fixobs == label &&
  164. m_arrInfo[i].m_iState == 1
  165. )
  166. return m_arrInfo[i].m_iId;
  167. }
  168. return SNIFF_INVALID_NODE_ID;
  169. }