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.

381 lines
7.3 KiB

  1. //
  2. // MODULE: APGTSCTX.CPP
  3. //
  4. // PURPOSE: Implementation file for Thread Context
  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. //
  12. // ORIGINAL DATE: 8-2-96
  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 04/09/98 JM/OK+ Local Version for NT5
  22. //
  23. //#include "windows.h"
  24. #include "stdafx.h"
  25. #include "time.h"
  26. #include "apgts.h"
  27. #include "ErrorEnums.h"
  28. #include "bnts.h"
  29. #include "BackupInfo.h"
  30. #include "cachegen.h"
  31. #include "apgtsinf.h"
  32. #include "apgtscmd.h"
  33. #include "apgtshtx.h"
  34. #include "apgtscls.h"
  35. #include "TSHOOT.h"
  36. int idcomp(const void *elem1, const void *elem2);
  37. //-----------------
  38. //
  39. APGTSContext::APGTSContext()
  40. {
  41. m_pConf = NULL;
  42. m_dwErr = 0;
  43. m_infer = NULL;
  44. m_currcfg = NULL;
  45. _tcscpy(m_resptype, _T("200 OK"));
  46. m_pszheader = NULL;
  47. m_pCtxt = NULL;
  48. m_pQry = NULL;
  49. return;
  50. }
  51. //
  52. //
  53. APGTSContext::APGTSContext( BNCTL *currcfg,
  54. CDBLoadConfiguration *pConf,
  55. CHttpQuery *pHttpQuery)
  56. {
  57. m_infer = NULL;
  58. Initialize(currcfg, pConf, pHttpQuery);
  59. return;
  60. }
  61. //
  62. //
  63. void APGTSContext::Initialize( BNCTL *currcfg,
  64. CDBLoadConfiguration *pConf,
  65. CHttpQuery *pHttpQuery)
  66. {
  67. struct tm *newtime;
  68. TCHAR buf[MAXBUF+1];
  69. m_pConf = pConf;
  70. m_dwErr = 0;
  71. m_infer = NULL;
  72. m_currcfg = currcfg;
  73. _tcscpy(m_resptype, _T("200 OK"));
  74. if (m_pszheader)
  75. delete m_pszheader;
  76. m_pszheader = new CString();
  77. if (m_pCtxt)
  78. delete m_pCtxt;
  79. m_pCtxt = new CString();
  80. m_pQry = pHttpQuery;
  81. if (m_pszheader)
  82. *m_pszheader += _T("Content-Type: text/html\r\n");
  83. m_pConf->GetVrootPath(m_vroot);
  84. time( &m_aclock );
  85. newtime = localtime( &m_aclock );
  86. _tcscpy(buf,_tasctime(newtime));
  87. if (_tcslen(buf))
  88. buf[_tcslen(buf)-1] = _T('\0');// remove cr
  89. // get ip address to put into event log
  90. DWORD bufsize = MAXBUF - 1;
  91. if (!m_pCtxt || !m_pszheader) {
  92. m_dwErr = EV_GTS_ERROR_NO_STRING;
  93. return;
  94. }
  95. if (!m_pQry) {
  96. m_dwErr = EV_GTS_ERROR_NO_QUERY;
  97. return;
  98. }
  99. // create inference engine and related structures
  100. m_infer = new CInfer(m_pCtxt);
  101. if (!m_infer) {
  102. m_dwErr = EV_GTS_ERROR_NO_INFER;
  103. return;
  104. }
  105. }
  106. void APGTSContext::RemoveSkips()
  107. {
  108. ASSERT(m_infer);
  109. if (m_infer)
  110. m_infer->RemoveSkips();
  111. return;
  112. }
  113. void APGTSContext::ResetService()
  114. {
  115. m_infer->ResetService();
  116. return;
  117. }
  118. void APGTSContext::RenderNext(CString &strPage)
  119. {
  120. CString strTmp;
  121. strTmp.LoadString(IDS_ER_ERRORS_OCCURED);
  122. if (m_pszheader) {
  123. *m_pszheader += _T("\r\n");
  124. }
  125. if (m_pCtxt) {
  126. if (m_dwErr)
  127. *m_pCtxt += strTmp;
  128. // write out CString here
  129. if (m_pCtxt->GetLength() > 0)
  130. strPage = m_pCtxt->GetBuffer(0);
  131. }
  132. else {
  133. strPage = strTmp;
  134. }
  135. return;
  136. }
  137. void APGTSContext::Empty()
  138. {
  139. *m_pCtxt = _T("");
  140. return;
  141. }
  142. //
  143. //
  144. APGTSContext::~APGTSContext()
  145. {
  146. // AfxMessageBox("Context");
  147. if (m_infer)
  148. delete m_infer;
  149. if (m_pCtxt)
  150. delete m_pCtxt;
  151. if (m_pszheader)
  152. delete m_pszheader;
  153. }
  154. // This must be called to process the data
  155. //
  156. //
  157. //
  158. void APGTSContext::DoContent(CHttpQuery *pQry)
  159. {
  160. CString strRefedCmd;
  161. CString strRefedValue;
  162. CString strTxt;
  163. ASSERT(NULL != pQry);
  164. m_pQry = pQry;
  165. if (m_pQry->GetFirst(strRefedCmd, strRefedValue)) {
  166. DWORD dwStat = ProcessCommands((LPCTSTR) strRefedCmd, (LPCTSTR) strRefedValue);
  167. if (dwStat != 0) {
  168. TCHAR temp[MAXCHAR];
  169. if (dwStat != EV_GTS_INF_FIRSTACC)
  170. m_dwErr = dwStat;
  171. _stprintf(temp, _T("%d"), 0); // used to put extended error here
  172. ReportWFEvent( _T("[apgtscxt]"), //Module Name
  173. _T("[EndCommands]"), //event
  174. //m_pszQuery,
  175. NULL,
  176. temp,
  177. dwStat );
  178. }
  179. }
  180. else {
  181. strTxt.LoadString(IDS_ER_NO_INPUT_PARAMS);
  182. *m_pCtxt += strTxt;
  183. ReportWFEvent( _T("[apgtscxt]"), //Module Name
  184. _T("[ProcessQuery]"), //event
  185. //m_ipstr,
  186. NULL,
  187. _T(""),
  188. EV_GTS_USER_NO_STRING );
  189. }
  190. }
  191. //
  192. //
  193. DWORD APGTSContext::ProcessCommands(LPCTSTR pszCmd,
  194. LPCTSTR pszValue)
  195. {
  196. DWORD dwStat = 0;
  197. CString strTxt;
  198. // first command should be troubleshooter type
  199. if (!_tcscmp(pszCmd, C_TYPE) || !_tcscmp(pszCmd, C_PRELOAD)) {
  200. DWORD dwOff;
  201. CHTMLInputTemplate *pInputTemplate;
  202. //CSearchForm *pBESearch = NULL;
  203. BCache *pAPI;
  204. if (m_pConf->FindAPIFromValue(m_currcfg, pszValue, &pInputTemplate, /*&pBESearch, */ &pAPI, &dwOff)) {
  205. if ((dwStat = m_infer->Initialize(/*pBESearch*/)) != 0) {
  206. strTxt.LoadString(IDS_ER_MISSING_API);
  207. *m_pCtxt += strTxt;
  208. }
  209. else {
  210. dwStat = DoInference(pszCmd, pszValue, pInputTemplate, pAPI, dwOff);
  211. }
  212. }
  213. else {
  214. dwStat = EV_GTS_ERROR_INF_BADTYPECMD;
  215. strTxt.LoadString(IDS_ER_UNEXP_CMDA);
  216. *m_pCtxt += strTxt;
  217. *m_pCtxt += pszValue;
  218. }
  219. }
  220. else if (!_tcscmp(pszCmd, C_FIRST)) {
  221. DisplayFirstPage();
  222. dwStat = EV_GTS_INF_FIRSTACC;
  223. }
  224. else {
  225. dwStat = EV_GTS_ERROR_INF_BADCMD;
  226. strTxt.LoadString(IDS_ER_UNEXP_CMD);
  227. *m_pCtxt += strTxt;
  228. *m_pCtxt += pszCmd;
  229. }
  230. return (dwStat);
  231. }
  232. //
  233. //
  234. DWORD APGTSContext::DoInference(LPCTSTR pszCmd,
  235. LPCTSTR pszValue,
  236. CHTMLInputTemplate *pInputTemplate,
  237. BCache *pAPI,
  238. DWORD dwOff)
  239. {
  240. DWORD dwCount = 0, dwStat = 0;
  241. BOOL bPreload = FALSE;
  242. CString strTxt;
  243. if (!_tcscmp(pszCmd, C_PRELOAD))
  244. bPreload = TRUE;
  245. pInputTemplate->SetInfer(m_infer, m_vroot);
  246. m_infer->SetBelief(pAPI);
  247. // set type troubleshooter type in template
  248. pInputTemplate->SetType(pszValue);
  249. m_infer->SetType(pszValue);
  250. int refedCmd, refedVal;
  251. BOOL bProbAsk = TRUE;
  252. // RSStack<CNode> InvertState;
  253. while (m_pQry->GetNext(refedCmd, refedVal))
  254. {
  255. dwCount++;
  256. if (!m_infer->FSetNodeOfIdh(refedCmd, refedVal))
  257. dwStat = EV_GTS_ERROR_INF_NODE_SET;
  258. }
  259. //
  260. if (0 == dwCount)
  261. {
  262. m_infer->SetProblemAsk();
  263. m_infer->ClearDoubleSkip();
  264. }
  265. else
  266. {
  267. m_infer->ClearProblemAsk();
  268. }
  269. if (!dwStat) {
  270. pInputTemplate->Print(dwCount, m_pCtxt);
  271. /*
  272. if (m_infer->IsService(m_pszheader))
  273. {
  274. strTxt.LoadString(IDS_I_OBJ_MOVED);
  275. _tcscpy(m_resptype, (LPCTSTR) strTxt);
  276. }
  277. */
  278. }
  279. else {
  280. strTxt.LoadString(IDS_ER_SVR_BAD_DATA);
  281. *m_pCtxt += strTxt;
  282. }
  283. return dwStat;
  284. }
  285. //
  286. //
  287. void APGTSContext::DisplayFirstPage()
  288. {
  289. DWORD i, apicount;
  290. CString strTxt;
  291. *m_pCtxt += _T("<html><head><title>");
  292. strTxt.LoadString(IDS_FP_TITLE);
  293. *m_pCtxt += strTxt;
  294. *m_pCtxt += _T("</title></head>\n");
  295. *m_pCtxt += _T("<body ");
  296. strTxt.LoadString(IDS_FP_BODY_ATTRIB);
  297. *m_pCtxt += strTxt;
  298. *m_pCtxt += _T(">\n<center><h1>");
  299. strTxt.LoadString(IDS_FP_HEADER);
  300. *m_pCtxt += strTxt;
  301. *m_pCtxt += VERSIONSTR;
  302. *m_pCtxt += _T("</h1></center>\n");
  303. *m_pCtxt = _T("<center>\n");
  304. apicount = m_pConf->GetFileCount(m_currcfg);
  305. if (!apicount) {
  306. strTxt.LoadString(IDS_ER_NO_API);
  307. *m_pCtxt += strTxt;
  308. }
  309. else {
  310. for (i=0;i<apicount;i++) {
  311. AfxFormatString1(strTxt, IDS_FORM_START, m_pConf->GetTagStr(m_currcfg, i));
  312. *m_pCtxt += strTxt;
  313. *m_pCtxt += _T("<INPUT TYPE=SUBMIT VALUE=\"");
  314. *m_pCtxt += m_pConf->GetTagStr(m_currcfg, i);
  315. *m_pCtxt += _T("\">\n");
  316. *m_pCtxt += _T("</FORM>\n");
  317. }
  318. }
  319. *m_pCtxt += _T("</center></body></html>\n");
  320. }
  321. // id compare in descending order
  322. //
  323. int idcomp(const void *elem1, const void *elem2)
  324. {
  325. return(((EVAL_WORD_METRIC *)elem2)->dwVal - ((EVAL_WORD_METRIC *)elem1)->dwVal);
  326. }