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.

365 lines
14 KiB

  1. //
  2. // MODULE: APGTSCLS.H
  3. //
  4. // PURPOSE: Class header file
  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/OK+ Local Version for NT5
  23. //
  24. // names as part of name/value pairs to pass in to queries
  25. #define C_TYPE _T("type") // name of the troubleshooting belief network
  26. #define C_FIRST _T("first") // show "first" page (a list of loaded troubleshooters)
  27. // although useful in the Online Troubleshooter, which
  28. // has lots of troubleshooting networks loaded at once,
  29. // this is probably useless in the Local TS, except maybe
  30. // to show VERSIONSTR.).
  31. #define C_SELECT _T("select") // UNSUPPORTED 3/98: Returns a page that has all of the
  32. // troubleshooting belief networks
  33. #define C_PRELOAD _T("preload") // relates to a 1997 prototype way of doing sniffing
  34. // with a separate OCX. Probably should not be
  35. // supported for 3/98 onwards.
  36. #define C_ASK_LIBRARY _T("asklibrary") // says, in effect, "establish contact with the
  37. // launch server & query it for what to do.
  38. #define VERSIONSTR _T("V3.0") // >>> Typically, should be changed for each major release.
  39. // no registry parameter can be larger than this value
  40. #define ABS_MAX_REG_PARAM_VAL 10000
  41. // these are settable in registry, defaults
  42. // resource directory (configuration/support files):
  43. #define DEF_FULLRESOURCE _T("c:\\inetsrv\\scripts\\apgts\\resource")
  44. // offsets for file types
  45. #define BNOFF_HTM 0
  46. #define BNOFF_DSC 1 // Are replacing bin with dsc.
  47. #define BNOFF_HTI 2
  48. #define BNOFF_BES 3
  49. #define MAXBNFILES 4
  50. // track a file for file change purposes
  51. // >>> I suspect this is not ultimately relevant to Local TS. This comes from an Online TS
  52. // consideration of updating when a new version of a TS belief NW is loaded. - JM
  53. typedef struct _FILECTL {
  54. WIN32_FIND_DATA FindData; // we really use this just for ftLastWriteTime. Using the
  55. // whole WIN32_FIND_DATA here makes some code a bit obscure.
  56. TCHAR szFilename[MAXBUF]; // just the filename (no path)
  57. TCHAR szFilepath[MAXBUF]; // full path name of file
  58. BOOL bChanged; // TRUE ==> File exists & its date/time differs from that
  59. // indicated by FindData.ftLastWriteTime
  60. BOOL bExist; // normally TRUE, set FALSE if we try to access the file
  61. // & it isn't there.
  62. BOOL bIndependent; // TRUE ==> this file is able to be changed independently of
  63. // any other file. As of 10/97, this is strictly historical,
  64. // but DSC files are arbitrarily considered dependent.
  65. CString strFile; // file name (for example, LAN.hti), if "szFilepath"
  66. // member contains *.chm file
  67. } FILECTL;
  68. // In Online TS there is one of these for each instance of a TS Belief Network and
  69. // there may be multiple instances of one troubleshooter. Probably overkill to isolate
  70. // as a separate struct for Local TS, but we inherited it.
  71. typedef struct _BNAPICFG {
  72. BCache *pAPI;
  73. CHTMLInputTemplate *pTemplate; // object corresponding to HTI file
  74. DWORD waitcount; // really a use count, >>> almost certainly irrelevant to
  75. // Local TS.
  76. TCHAR type[MAXBUF]; // symbolic name of the Belief Network
  77. TCHAR szFilepath[MAXBNFILES][MAXBUF]; // first dimension corresponds to different files
  78. // (DSC, HTI, BES) in the directory. Full filepath of each
  79. // of these files .Index should be a BNOFF constant.
  80. TCHAR szResPath[MAXBUF]; // path to the monitored directory which contains the support
  81. // files. Who knows why this is replicated here!
  82. CString strFile[MAXBNFILES];// file name (for example, LAN.hti), if "szFilepath"
  83. // member contains *.chm file
  84. } BNAPICFG;
  85. // In Online TS, one of these for API_A_OFF, one for API_B_OFF. Again, probably overkill
  86. // for local TS.
  87. typedef struct _BNCTL {
  88. HANDLE *pHandles; // array of handles to mutexes. certainly irrelevant to Local TS
  89. DWORD dwHandleCnt; // dimension of *pHandles
  90. BNAPICFG api; // Note contrast to Online TS, where this is an array.
  91. DWORD dwApiCnt; // Must be meaningless for Local TS: dimension of what's not
  92. // even an array
  93. } BNCTL;
  94. // track a directory for file change purposes. Again, probably overkill for local TS.
  95. typedef struct _BNDIRCFG {
  96. FILECTL file[MAXBNFILES]; // dimension corresponds to different files in the directory.
  97. // Index should be a BNOFF constant
  98. BOOL bDependChg; // Historically, TRUE ==> files are interdependent on an update
  99. TCHAR type[MAXBUF]; // symbolic name of the Belief Network
  100. TCHAR szResPath[MAXBUF]; // path to this directory. SAME FOR ALL TROUBLEHOOTERS as
  101. // of 10/97. Who knows why this is replicated here!
  102. } BNDIRCFG;
  103. //
  104. //
  105. #include "Rsstack.h"
  106. class APGTSContext;
  107. interface ILaunchTS;
  108. class CHttpQuery {
  109. public:
  110. CHttpQuery();
  111. ~CHttpQuery();
  112. void RemoveAll(){m_State.RemoveAll();};
  113. void Debug();
  114. void Initialize(const VARIANT FAR& varCmds, const VARIANT FAR& varVals, short size);
  115. void SetFirst(CString &strCmd, CString &strVal);
  116. void FinishInit(BCache *pApi, const VARIANT FAR& varCmds, const VARIANT FAR& varVals);
  117. void FinishInitFromServ(BCache *pApi, ILaunchTS *pLaunchTS);
  118. BOOL StrIsDigit(LPCTSTR pSz);
  119. BOOL GetFirst(CString &strPut, CString &strValue);
  120. void SetStackDirection();
  121. BOOL GetNext(int &refedCmd, int &refedVal /* TCHAR *pPut, TCHAR *pValue */ );
  122. CString GetTroubleShooter(); // Gets the first Vals BSTR.
  123. CString GetFirstCmd();
  124. BOOL GetValue(int &Value, int index);
  125. BOOL GetValue1(int &Value);
  126. BOOL BackUp(BCache *pApi, APGTSContext *pCtx);
  127. void RemoveNodes(BCache *pApi);
  128. void AddNodes(BCache *pApi);
  129. int StatesFromServ(){return m_nStatesFromServ;};
  130. void RestoreStatesFromServ();
  131. CString GetSubmitString(BCache *pApi);
  132. CString& GetMachine();
  133. CString& GetPNPDevice();
  134. CString& GetDeviceInstance();
  135. CString& GetGuidClass();
  136. void PushNodesLastSniffed(const CArray<int, int>& arr);
  137. protected:
  138. // The next 2 members are arrays of strings. See CHttpQuery::Initialize() for details of
  139. // the many conditions they must meet. Taken together, they constitute name/value
  140. // pairs to set initial conditions for the troubleshooter. The first pair indicates what
  141. // troubleshooting belief network to load, the second indicates the problem node,
  142. // additional pairs indicate other nodes to be set. All but the first are optional.
  143. VARIANT *m_pvarCmds;
  144. VARIANT *m_pvarVals;
  145. // The next 2 members are copies of the first pair in the above arrays.
  146. CString m_strCmd1; // should always be "type"
  147. CString m_strVal1; // name of the current troubleshooting belief network
  148. // The next 4 parameters are machine, device, device instance id and class GUID
  149. CString m_strMachineID;
  150. CString m_strPNPDeviceID;
  151. CString m_strDeviceInstanceID;
  152. CString m_strGuidClass;
  153. int m_CurrentUse; // >>> needs to be documented.
  154. int m_Size; // clearly correlated to the number of name/value pairs that come
  155. // in from TSLaunchServ or from an HTML "get"; once
  156. // initialization is complete, one more than the number of
  157. // CNodes in stack m_State. Sometimes this is incremented
  158. // in synch with pushing onto the stack, sometimes not.
  159. // >>> Is there any clean characterization of this variable?
  160. // >>> If anyone understands this better, please document. JM
  161. bool m_bReverseStack; /* Richard writes in a 3/14/98 email: "I had to add reverse
  162. stack to make the thing work when launched from the device
  163. manager. The theory is that the order of instantiations is
  164. not important. What happens is the recommendations we get
  165. are different if the nodes are instantiated in reverse order."
  166. >>> If you understand more about this, please document further. */
  167. UINT m_nStatesFromServ; // the number of nodes (including the problem node) whose states
  168. // were set by TSLaunchServ. This allows us to avoid showing a
  169. // BACK button when that would take us farther back than where
  170. // we started.
  171. class CNode
  172. {
  173. public:
  174. CNode() {cmd=0;val=0;sniffed=false;};
  175. int cmd; // An IDH-style node number. If this is an actual node, it's the
  176. // "raw" node number + idhFirst, and val is the state. If it's
  177. // <the count of nodes> + idhFirst, then val is the problem node.
  178. // There's also something about a special value for TRY_TS_AT_MICROSOFT
  179. // I (JM 3/98) believe that's something to do with an incomplete
  180. // plan of being able to dynamically download troubleshooters
  181. // from the net, but I could be wrong.
  182. // >>> Maybe type should be IDH?
  183. int val; // see documentation of cmd.
  184. bool sniffed; // indicates that the node was set as result of sniffing
  185. // really UGLY that we have to spread this flag all over the place
  186. // but the fact that multiple classes and data containers support
  187. // the simple process of navigation is not less UGLY!!!
  188. };
  189. // Despite being a stack, there are times we access members other than
  190. // by push and pop. According to Richard, stack was originally set up here
  191. // in support of BACK button, but m_bReverseStack was introduced because of a
  192. // situation (launching with problem node + other node(s) set) where
  193. // we needed to juggle things to pop problem node first.
  194. // (JM 4/1/98)
  195. RSStack<CNode> m_State;
  196. void ThrowBadParams(CString &str);
  197. CNode m_aStatesFromServ[55]; // Keep around a copy of the states set on instructions
  198. // from TS Launcher.
  199. // size is arbitrary, way larger than needed.
  200. };
  201. //
  202. //
  203. class CDBLoadConfiguration
  204. {
  205. public:
  206. CDBLoadConfiguration();
  207. CDBLoadConfiguration(HMODULE hModule, LPCTSTR szValue);
  208. ~CDBLoadConfiguration();
  209. void Initialize(HMODULE hModule, LPCTSTR szValue);
  210. void SetValues(CHttpQuery &httpQ);
  211. VOID ResetNodes();
  212. VOID ResetTemplate();
  213. TCHAR *GetFullResource();
  214. VOID GetVrootPath(TCHAR *tobuf);
  215. TCHAR *GetHtmFilePath(BNCTL *currcfg, DWORD i);
  216. TCHAR *GetBinFilePath(BNCTL *currcfg, DWORD i);
  217. TCHAR *GetHtiFilePath(BNCTL *currcfg, DWORD i);
  218. TCHAR *GetTagStr(BNCTL *currcfg, DWORD i);
  219. DWORD GetFileCount(BNCTL *currcfg);
  220. BNCTL *GetAPI();
  221. BOOL FindAPIFromValue( BNCTL *currcfg, \
  222. LPCTSTR type, \
  223. CHTMLInputTemplate **pIT, \
  224. /*CSearchForm **pBES,*/ \
  225. BCache **pAPI, \
  226. DWORD *dwOff);
  227. BOOL RescanRegistry(BOOL bChangeAllow);
  228. bool IsUsingCHM();
  229. protected:
  230. // variables corresponding to the registry; comments refer to initial values
  231. TCHAR m_szResourcePath[MAXBUF]; // DEF_FULLRESOURCE: resource directory
  232. CString m_strCHM; // name of CHM file if any
  233. BNCTL m_cfg; // In local TS, the one and only BNCTL (there are 2 in Online TS
  234. // as part of the reload strategy)
  235. BNDIRCFG m_dir; // Similarly, for the sole instance of the sole TS belief network
  236. DWORD m_bncfgsz; // a rather useless "dimension" of what is not an array in Local TS
  237. DWORD m_dwFilecount; // Badly named. Total number of instances of troubleshooters
  238. // mandated by APGTS.LST. Proabably totally irrelvant in Local TS
  239. TCHAR m_nullstr[2]; // null string, here so if we have to return a string pointer
  240. // which is not allocated, we can point them here instead.
  241. DWORD m_dwErr;
  242. protected:
  243. VOID GetDSCExtension(CString &strDSCExtension, LPCTSTR szValue);
  244. VOID InitializeToDefaults();
  245. VOID InitializeFileTimeList();
  246. DWORD CreateApi(TCHAR *szErrInfo);
  247. VOID DestroyApi();
  248. VOID LoadSingleTS(LPCTSTR szValue); // Replaces ProcessLstFile.
  249. BOOL CreatePaths(LPCTSTR szNetwork);
  250. VOID BackslashIt(TCHAR *str);
  251. BOOL GetResourceDirFromReg(LPCTSTR szNetwork);
  252. VOID ProcessEventReg(HMODULE hModule);
  253. VOID CreateEvtMF(HKEY hk, HMODULE hModule);
  254. VOID CreateEvtTS(HKEY hk);
  255. VOID ClearCfg(DWORD off);
  256. VOID InitializeSingleResourceData(LPCTSTR szValue); // Replaces InitializeMainResourceData when apgts is in an OLE Control.
  257. };
  258. //
  259. //
  260. typedef struct _EVAL_WORD_METRIC {
  261. DWORD dwVal;
  262. DWORD dwApiIdx;
  263. } EVAL_WORD_METRIC;
  264. //
  265. //
  266. class APGTSContext
  267. {
  268. public:
  269. APGTSContext();
  270. APGTSContext( BNCTL *currcfg,
  271. CDBLoadConfiguration *pConf,
  272. CHttpQuery *pHttpQuery);
  273. ~APGTSContext();
  274. void Initialize(BNCTL *currcfg,
  275. CDBLoadConfiguration *pConf,
  276. CHttpQuery *pHttpQuery);
  277. void DoContent(CHttpQuery *pQry);
  278. void RenderNext(CString &strPage);
  279. void Empty();
  280. void RemoveSkips();
  281. void ResetService();
  282. void BackUp(int nid, int state) {m_infer->BackUp(nid, state);};
  283. void ClearBackup() {m_infer->ClearBackup();};
  284. CSniffedNodeContainer* GetSniffedNodeContainer() {return m_infer ? m_infer->GetSniffedNodeContainer() : NULL;}
  285. protected:
  286. void StartContent();
  287. DWORD ProcessCommands(LPCTSTR pszCmd, LPCTSTR pszValue);
  288. DWORD DoInference(LPCTSTR pszCmd, LPCTSTR pszValue, CHTMLInputTemplate *pInputTemplate, BCache *pAPI, DWORD dwOff);
  289. TCHAR *GetCookieValue(CHAR *pszName, CHAR *pszNameValue);
  290. TCHAR *asctimeCookie(struct tm *gmt);
  291. void DisplayFirstPage();
  292. protected:
  293. DWORD m_dwErr;
  294. TCHAR m_vroot[MAXBUF]; // Local URL to this OCX
  295. TCHAR m_resptype[MAXBUF]; // HTTP response type e.g. "200 OK", "302 Object Moved"
  296. CString *m_pszheader; // In Online TS, header for response file (indicates whether
  297. // we're sending HTML, setting a cookie, etc.)
  298. // Not sure how this is relevant to Local TS.
  299. BNCTL *m_currcfg; // pointer to the BNCTL which we will use for this query
  300. CString *m_pCtxt; // this is where we build the string to pass back (the newly
  301. // constructed page)
  302. CHttpQuery *m_pQry; // takes in raw URL-encoded string, gives us
  303. // functions to get back scanned pairs.
  304. CDBLoadConfiguration *m_pConf; // contains support-file data structures
  305. CInfer *m_infer; // belief-network handler, unique to this request
  306. time_t m_aclock; // time we build this object
  307. };