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.

499 lines
16 KiB

  1. //
  2. // MODULE: APGTSINF.H
  3. //
  4. // PURPOSE: Inference support header
  5. //
  6. // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint
  7. //
  8. // COMPANY: Saltmine Creative, Inc. (206)-633-4743 [email protected]
  9. //
  10. // AUTHOR: Roman Mach
  11. // further work by Richard Meadows (RWM), Joe Mabel, Oleg Kalosha
  12. //
  13. // ORIGINAL DATE: 8-2-96
  14. //
  15. // NOTES:
  16. // 1. Based on Print Troubleshooter DLL
  17. //
  18. // Version Date By Comments
  19. //--------------------------------------------------------------------
  20. // V0.1 - RM Original
  21. // V0.2 6/4/97 RWM Local Version for Memphis
  22. // V0.3 3/24/98 JM Local Version for NT5
  23. #include "ErrorEnums.h"
  24. #include "sniff.h"
  25. typedef unsigned int NID; // numeric node ID in the form used by BNTS
  26. // Please Note: these values are mirrored in dtguiapi.bas, please keep in sync
  27. const NID nidNil = 12346;
  28. const NID nidService = 12345;
  29. #define IDH_BYE 101 // success page
  30. #define IDH_FAIL 102 // "no more recommendations" page
  31. typedef UINT IDH; // help index. For values where a NID is defined,
  32. // add idhFirst to get an IDH. IDH_BYE & IDH_FAIL
  33. // are also good IDHs.
  34. const IDH idhFirst = 1000;
  35. #define IDH_FROM_NID(NID) (NID + idhFirst)
  36. #define IDH_SERVICE IDH_FROM_NID(nidService)
  37. #define MAXBUF 256 * 2
  38. #define MAXPROBID 100 // allow for this many problem nodes in a network
  39. enum { cnidMacSkip = 32 }; // max # of "skipped" nodes
  40. typedef TCHAR* TSZ;
  41. typedef const TCHAR* TSZC;// >>> why distinguished from TSZ?
  42. typedef unsigned int CNID; // a count of node IDs.
  43. typedef unsigned int IST; // state number (associated with a node)
  44. // 0 - normal
  45. // 1 - abnormal
  46. // 102 - skipped
  47. #define MAX_NID 64 // allow for this many nodes to be given states by user on the
  48. // way to solving the problem
  49. void WideToMB(const WCHAR *szIn, CHAR *szOut); // Converts Unicode chars to Multi Byte.
  50. class GTSCacheGenerator; // forward reference
  51. class GTSAPI : public BNTS
  52. {
  53. #define SZ_CACHE_NAME _T(".tsc")
  54. public:
  55. GTSAPI(TCHAR *binfile, TCHAR *tagstr, TCHAR *szResourcePath);
  56. virtual ~GTSAPI();
  57. BOOL BNodeSet(int state, bool bset); // Old comment says "For debugging" but I doubt it.
  58. // Maybe that's just why its public. - JM 3/98
  59. void AddValue(int value);
  60. // Temporary BNTS wrappers for unicode build with non unicode bnts.dll
  61. CString m_strResult;
  62. BOOL BMultiByteReadModel(LPCTSTR szcFn, LPCSTR szcFnError);
  63. BOOL BReadModel (LPCTSTR szcFn, LPCSTR szcFnError = NULL)
  64. {
  65. #ifndef _UNICODE
  66. return BNTS::BReadModel(szcFn, szcFnError);
  67. #else
  68. return BMultiByteReadModel(szcFn, szcFnError);
  69. #endif
  70. };
  71. BOOL BMultiByteNodePropItemStr(LPCTSTR szcPropType, int index);
  72. virtual BOOL BNodePropItemStr(TSZC szcPropType, int index)
  73. {
  74. #ifndef _UNICODE
  75. return BNTS::BNodePropItemStr(szcPropType, index);
  76. #else
  77. return BMultiByteNodePropItemStr(szcPropType, index);
  78. #endif
  79. };
  80. BOOL BMultiByteNetPropItemStr(LPCTSTR szcPropType, int index);
  81. virtual BOOL BNetPropItemStr(TSZC szcPropType, int index)
  82. {
  83. #ifndef _UNICODE
  84. return BNTS::BNetPropItemStr(szcPropType, index);
  85. #else
  86. return BMultiByteNetPropItemStr(szcPropType, index);
  87. #endif
  88. };
  89. LPCTSTR SzcMultiByteResult();
  90. virtual LPCTSTR SzcResult()
  91. {
  92. #ifndef _UNICODE
  93. return BNTS::SzcResult();
  94. #else
  95. return SzcMultiByteResult();
  96. #endif
  97. };
  98. int IMultiByteNode(LPCTSTR szSymName);
  99. virtual int INode(LPCTSTR szSymName)
  100. {
  101. #ifndef _UNICODE
  102. return BNTS::INode(szSymName);
  103. #else
  104. return IMultiByteNode(szSymName);
  105. #endif
  106. };
  107. // Temporary BNTS wrappers for debug build with release bnts.dll
  108. /*
  109. BOOL BNetPropItemStr(LPCTSTR szPropItem, int index, CString &str)
  110. {
  111. BOOL bRet;
  112. str.GetBuffer(STRBUFSIZE);
  113. bRet = BNTS::BNetPropItemStr(szPropItem, index, str);
  114. str.ReleaseBuffer();
  115. return bRet;
  116. };
  117. BOOL BNodePropItemStr(LPCTSTR szPropItem, int index, CString &str)
  118. {
  119. BOOL bRet;
  120. str.GetBuffer(STRBUFSIZE);
  121. bRet = BNTS::BNodePropItemStr(szPropItem, index, str);
  122. str.ReleaseBuffer();
  123. return bRet;
  124. };
  125. void NodeStateName(int index, CString &str)
  126. {
  127. str.GetBuffer(STRBUFSIZE);
  128. BNTS::NodeStateName(index, str);
  129. str.ReleaseBuffer();
  130. return;
  131. };
  132. void NodeSymName(CString &str)
  133. {
  134. str.GetBuffer(STRBUFSIZE);
  135. BNTS::NodeSymName(str);
  136. str.ReleaseBuffer();
  137. return;
  138. };
  139. void NodeFullName(CString &str)
  140. {
  141. str.GetBuffer(STRBUFSIZE);
  142. BNTS::NodeFullName(str);
  143. str.ReleaseBuffer();
  144. return;
  145. };
  146. */
  147. // Regular functions.
  148. //virtual BOOL NodeSet(NID nid, IST ist);
  149. VOID ResetNodes();
  150. DWORD Reload(/*CWordList *pWXList*/);
  151. DWORD GetStatus();
  152. UINT GetProblemArray(IDH **idh);
  153. IDH GetProblemAsk();
  154. UINT GetNodeList(NID **pNid, IST **pIst);
  155. int GTSGetRecommendations(CNID& cnid, NID rgnid[]);
  156. void RemoveRecommendation(int Nid);
  157. VOID GetSearchWords(/*CWordList *pWords*/);
  158. DWORD EvalWord(TCHAR *token);
  159. //WNODE_ELEM *GetWNode(NID nid);
  160. BOOL BNodeSetCurrent(int node);
  161. VOID ScanAPIKeyWords(/*CWordList *pWXList*/);
  162. protected:
  163. VOID Destroy();
  164. protected:
  165. GTSCacheGenerator m_CacheGen;
  166. // These 2 arrays tie together nodes & their states
  167. NID m_rgnid[MAX_NID];
  168. IST m_rgist[MAX_NID];
  169. IST m_rgsniff[MAX_NID]; // array of states, showing if the node was sniffed
  170. UINT m_cnid; // current size of m_rgnid, m_rgist; number of nodes to which
  171. // a state has been assigned.
  172. TCHAR m_binfile[MAXBUF]; // name of DSC file (>>> full path or not?)
  173. // >>>should be renamed! DSC file replaced BIN file.
  174. TCHAR m_tagstr[MAXBUF];
  175. TCHAR m_szResourcePath[MAXBUF]; // full path of resource directory
  176. DWORD m_dwErr;
  177. TCHAR* m_pchHtml;
  178. IDH m_idstore[MAXPROBID]; // problem node convenience array in the
  179. // form of IDH values
  180. UINT m_currid; // Despite bad name, number of values in m_idstore
  181. IDH m_probask; // IDH value corresponding to ProblemAsk: number of nodes
  182. // in the network + 1000
  183. CBNCache *m_pCache; // cache for states of this network
  184. };
  185. ////////////////////////////////////////////////////////////////////////////////////////
  186. // BCache class declaration
  187. //
  188. // these are returns by GTSGetRecommendations member function
  189. //
  190. #define RECOMMEND_SUCCESS 1
  191. #define RECOMMEND_FAIL 0
  192. #define RECOMMEND_IMPOSSIBLE 99
  193. #define RECOMMEND_NODE_WORKED 100
  194. #define RECOMMEND_NO_MORE_DATA 101
  195. //
  196. #define NODE_ID_NONE -1
  197. //
  198. class CHttpQuery;
  199. class BCache : public GTSAPI, public CSniffedNodeContainer
  200. {
  201. public:
  202. BCache(TCHAR *binfile, TCHAR *tagstr, TCHAR *szResourcePath, const CString& strFile);
  203. ~BCache();
  204. void SetHttpQuery(CHttpQuery *p) {m_pHttpQuery = p;return;};
  205. UINT StatesFromServ();
  206. UINT StatesNowSet();
  207. DWORD Initialize(/*CWordList *pWXList*/);
  208. DWORD ReadModel();
  209. void ReadCacheFile(LPCTSTR szCache);
  210. int GTSGetRecommendations(CNID& cnid, NID rgnid[], bool bSniffed =false);
  211. void RemoveRecommendation(int Nid);
  212. BOOL NodeSet(NID nid, IST ist, bool bPrevious);
  213. void ResetNodes();
  214. int CNode();
  215. BOOL BImpossible();
  216. BOOL BNetPropItemStr(LPCTSTR szPropType, int index);
  217. BOOL BNetPropItemReal(LPCTSTR szPropType, int index, double &dbl);
  218. BOOL BNodeSetCurrent(int node);
  219. int INode(LPCTSTR szNodeSymName);
  220. ESTDLBL ELblNode();
  221. int INodeCst();
  222. BOOL BNodeSet(int istate, bool bSet = true);
  223. int INodeState();
  224. void NodeStateName(int istate);
  225. void NodeSymName();
  226. void NodeFullName();
  227. BOOL BNodePropItemStr(LPCTSTR szPropType, int index);
  228. BOOL BNodePropItenReal(LPCTSTR szPropType, int index, double &dbl);
  229. void NodeBelief();
  230. bool BValidNet();
  231. bool BValidNode();
  232. void Clear();
  233. void RemoveStates() {m_NodeState.RemoveAll();};
  234. void RemoveNode(int Node) {VERIFY(m_NodeState.RemoveKey(Node));};
  235. LPCTSTR SzcResult() const;
  236. void ReadTheDscModel(int From = TSERR_ENGINE_BNTS_READ);
  237. const CArray<int, int>& GetArrLastSniffed();
  238. int GetCountRecommendedNodes();
  239. int GetCountSniffedRecommendedNodes();
  240. bool IsReverse();
  241. void SetReverse(bool);
  242. void SetRunWithKnownProblem(bool);
  243. bool IsRunWithKnownProblem();
  244. void SetAdditionalDataOnNodeSet(NID nid);
  245. protected:
  246. int GetIndexNodeInCache(NID nid);
  247. protected:
  248. CHttpQuery *m_pHttpQuery;
  249. BOOL CheckNode(int Node);
  250. void AddToCache(CString &strCacheFile, const CString& strCacheFileWithinCHM);
  251. BOOL m_bNeedModel; // TRUE -> Need to read the model before querying the bnts library.
  252. BOOL m_bModelRead;
  253. BOOL m_bDeleteModelFile;
  254. CString m_strModelFile; // Filename of model file
  255. CString m_strFile; // name of *.dsz or *.dsc file inside *.chm file
  256. // (in this case network file is actually a *.chm file)
  257. int m_CurNode;
  258. CMap<int, int, int, int>m_NodeState;
  259. CString m_strResult;
  260. CArray<int, int> m_arrNidLastSniffed; // array in sniffed nodes traversed during last navigation
  261. bool m_bReverse; // indicated if the current movement is in the forward or reverse direction
  262. bool m_bRunWithKnownProblem; //indicates that the tshooter was started with known problem
  263. };
  264. typedef struct tag_TShooter
  265. {
  266. TCHAR m_szName[MAXBUF];
  267. TCHAR m_szDisplayName[MAXBUF];
  268. } TShooter;
  269. //
  270. //
  271. class CInfer
  272. {
  273. public:
  274. CInfer( CString *pCtxt);
  275. ~CInfer();
  276. void ClearDoubleSkip() {m_SkippedTwice.RemoveAll();};
  277. VOID AssertFailed(TSZC szcFile, UINT iline, TSZC szcCond, BOOL fFatal);
  278. DWORD Initialize(/*CSearchForm *pBESearch*/);
  279. void LoadTShooters(HKEY hRegKey);
  280. int GetCount() {return m_acnid;};
  281. void BackUp(int nid, int state);
  282. void ClearBackup() {m_Backup.Clear();};
  283. void WriteProblem();
  284. BOOL FSetNodeOfIdh(IDH, IST);
  285. int GetForcedRecommendation();
  286. int Finish(CString *cstr);
  287. void ResetService();
  288. VOID PrintRecommendations();
  289. VOID WriteOutLogs();
  290. VOID SetBelief(BCache *pAPI);
  291. TCHAR *EvalData(UINT var_index);
  292. BOOL NextVar(UINT var_index);
  293. BOOL InitVar(UINT var_index);
  294. void SetProblemAsk();
  295. void ClearProblemAsk();
  296. void SetType(LPCTSTR type);
  297. BOOL IsService(CString *cstr);
  298. VOID RemoveSkips();
  299. CSniffedNodeContainer* GetSniffedNodeContainer() {return m_api;}
  300. protected:
  301. void GetBackButton(CString &strBack);
  302. void GetNextButton(CString &strNext);
  303. void GetStartButton(CString &strStart);
  304. void GetStd3ButtonEnList(CString *cstr, bool bIncludeBackButton, bool bIncludeNextButton, bool bIncludeStartButton);
  305. bool GetNetPropItemStrs(TSZC item, UINT Res, CString *cstr);
  306. bool GetNodePropItemStrs(TSZC item, UINT Res, CString *cstr);
  307. VOID GetByeMsg(LPCTSTR szIdh, CString *cstr);
  308. VOID GetFailMsg(LPCTSTR szIdh, CString *cstr);
  309. VOID GetServiceMsg(LPCTSTR szIdh, CString *cstr);
  310. VOID GetSkippedNodesMsg(LPCTSTR szIdh, CString *cstr);
  311. VOID GetImpossibleNodesMsg(LPCTSTR szIdh, CString *cstr);
  312. VOID GetFixRadios(LPCTSTR szIdh, CString *cstr);
  313. VOID GetInfoRadios(LPCTSTR szIdh, CString *cstr);
  314. VOID PrintMessage(TSZC szcFormat, ...) const;
  315. VOID PrintString(TSZC szcFormat, ...) const;
  316. void WriteResult(UINT name, UINT value, BOOL bSet, TSZC szctype, CString *cstr) const;
  317. VOID CloseTable();
  318. BOOL FxGetNode(NID nid, BOOL fStatus, CString *cstr) const;
  319. void FxGetState(CString *cstr);
  320. void FxInitState(NID nid);
  321. VOID GetIdhPage(IDH idh, CString *cstr);
  322. bool BelongsOnProblemPage(int index);
  323. VOID GetIdhProblemPage(IDH idh, CString *cstr);
  324. VOID OutputBackend(CString *cstr) const;
  325. BOOL DisplayTerms(/*CWordList *pWords, */CString *cstr, BOOL bText, BOOL bOr) const;
  326. VOID AddBackendDebug(CString *cstr) const;
  327. void GetTS(CString *pCtmp);
  328. private:
  329. VOID AddSkip(NID nid);
  330. BOOL FSkip(NID nid) const;
  331. void SaveNID(UINT nid);
  332. private:
  333. CBackupInfo m_Backup;
  334. UINT m_cnidSkip; // count of elements in m_rgnidSkip
  335. NID m_rgnidSkip[cnidMacSkip]; // nodes for which the user has been unable to give
  336. // a yes or no answer.
  337. UINT m_ilineStat;
  338. BOOL m_fDone; // (>>> Not well-understood 11/04/97 JM)
  339. // Set TRUE when we write out service, fail, or
  340. // success page, but there's some scenario where
  341. // we clear it "so that the Previous button will work"
  342. // on BYE page"
  343. UINT m_ishowService; // >>> (JM 12/97) I suspect this is the same as OnlineTS's
  344. // BOOL m_bAnythingElse; which is documented as
  345. // Set TRUE if user wants to see if there is anything
  346. // else they can try (obtained from a service node in the
  347. // previous call to the DLL
  348. IDH m_idhQuestion; // >>> (JM 12/97) I suspect this is the same as OnlineTS's
  349. // NID m_nidAnythingElse; which is documented as
  350. // Node to use if m_bAnythingElse is TRUE
  351. private:
  352. CString *m_pCtmp; // (uses new) just a scratch buffer
  353. int m_cShooters; // a count of troubleshooting belief networks. JM strongly
  354. // suspects 3/98 that in Local TS it never gets past 1.
  355. // >>> presumably count of m_aShooters, so why don't we just
  356. // use GetCount(), anyway?.
  357. int m_iShooter; // index of a troubleshooting belief network. JM strongly
  358. // suspects 3/98 that in Local TS it is always 0.
  359. // presumably index into m_aShooters.
  360. CMap<int, int, int, int>m_SkippedTwice;
  361. CArray<TShooter, TShooter &> m_aShooters;
  362. NID m_cnid; // number of positions used in m_rgnid
  363. NID m_rgnid[64]; // node numbers of recommendations the user has visited
  364. NID m_question_rgnid[64]; // new recommendations. We only care about the first
  365. // recommendation not already offered and skipped.
  366. UINT m_cur_rec; // index into m_rgnid. We use this to loop through as we write
  367. // the "visited node table"
  368. UINT m_max_rec; // number of defined values in m_question_rgnid
  369. UINT m_cur_rec_inid;
  370. // The next 3 variables deal with states of a single node N, typically m_rgnid[m_cur_rec]
  371. UINT m_cur_state_set; // state value of node N
  372. UINT m_cur_cst; // count of states of node N
  373. UINT m_cur_ist; // index into states of node N, used to build a list of radio
  374. // buttons and log entries.
  375. UINT m_problemAsk; // >>> A thinly disguised Boolean. >>>(I think) something to do with
  376. // whether we return data on the problem node (vs. state-dependent
  377. // data) JM 10/30//97
  378. TCHAR m_problem[200]; // once a problem is chosen, this is where we put the associated
  379. // text description of the problem. Full text description plus
  380. // a hidden data field.
  381. NID m_firstNid;
  382. UINT m_firstSet;
  383. TCHAR m_tstype[30]; // symbolic name of troubleshooter
  384. //
  385. // now in the CSniffedContainer object
  386. /*
  387. IDH m_idhSniffedRecommendation; // if a recommendation from a sniffer overrides normal
  388. // method of getting a recommendation, here's where we store it.
  389. // Otherwise, nidNil+idhFirst.
  390. */
  391. protected:
  392. TSZ m_szFile;
  393. FILE* m_pfile;
  394. BOOL m_bHttp;
  395. CHAR m_szTemp1[MAXBUF];
  396. CString *m_pCtxt; // points to a buffer passed in to constructor. This is where
  397. // we build the HTML to pass back to the user
  398. TCHAR m_currdir[MAXBUF];
  399. CString *m_pResult; // A string to indicate (in the log) a FINAL result of a
  400. // Troubleshoot session. e.g. ">Success", ">Nothing Else",
  401. // ">Anything Else?", ">Help Elsewhere"
  402. CString *m_pSearchStr; // a string consisting of the search words implied by our node
  403. // choices, separated by "and" or "or" (depending on the
  404. // value of m_pBESearch->IsAND). Used as part of Back End
  405. // Search redirection. >>> Probably irrelevant to Local TS,
  406. // which doesn't use BES
  407. BCache *m_api; // cache for associated belief network
  408. BOOL m_bService;
  409. NID m_nidPreloadCheck;
  410. CNID m_acnid; // count of nodes at *m_api
  411. };