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.

359 lines
11 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)-284-7511 [email protected]
  9. //
  10. // AUTHOR: Roman Mach, Joe Mabel
  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. // V3.0 7-22-98 JM Major revision, deprecate IDH.
  21. // V3.1 1-06-99 JM Extract APGTSEXT.H
  22. //
  23. #if !defined(APGTSCLS_H_INCLUDED)
  24. #define APGTSCLS_H_INCLUDED
  25. #if _MSC_VER >= 1000
  26. #pragma once
  27. #endif // _MSC_VER >= 1000
  28. #include"apgtsinf.h"
  29. #include "apgtslog.h"
  30. #include "LogString.h"
  31. #include "apgtspl.h"
  32. #include "maxbuf.h"
  33. #include "apgts.h"
  34. #include <map>
  35. using namespace std;
  36. // string constants involved in commands from sysop to take various actions.
  37. #define SZ_OP_ACTION "TSHOOOT" // Preface to all operator actions. Note the extra "O".
  38. #define SZ_EMERGENCY_DEF SZ_OP_ACTION
  39. #define SZ_RELOAD_TOPIC "E1" // Reload one topic
  40. #define SZ_KILL_THREAD "E2" // Kill (and restart) one pool thread
  41. #define SZ_RELOAD_ALL_TOPICS "E3" // Reload all monitored files.
  42. #define SZ_SET_REG "E4" // Set a registry value.
  43. #define SZ_KILL_STUCK_THREADS "E8" // Kill (and restart) all stuck pool threads
  44. #define SZ_EMERGENCY_REBOOT "E9" // want to reboot this DLL.
  45. // The product version is loaded from the resource file upon DLL startup.
  46. // Used for APGTS logging and status page reporting.
  47. extern CString gstrProductVersion;
  48. // HTTP spec for document type. For validation of incoming HTTP POST request.
  49. #define CONT_TYPE_STR "application/x-www-form-urlencoded"
  50. class CHttpQuery {
  51. public:
  52. CHttpQuery();
  53. ~CHttpQuery();
  54. BOOL GetFirst(LPCTSTR szInput, TCHAR *pchName, TCHAR *pchValue);
  55. BOOL GetNext(TCHAR *pchName, TCHAR *pchValue);
  56. void Push(LPCTSTR szPushed);
  57. protected:
  58. BOOL LoopFind(TCHAR *pchName, TCHAR *pchValue);
  59. void AddBuffer( TCHAR ch, TCHAR *tostr);
  60. void PutStr(LPCTSTR instr, TCHAR *addtostr);
  61. static void CleanStr(TCHAR *str);
  62. protected:
  63. enum decstates {
  64. ST_GETNEXT,
  65. ST_FINDNAME,
  66. ST_GETDATA,
  67. ST_DECODEHEX1,
  68. ST_DECODEHEX2,
  69. ST_GETFIRST,
  70. };
  71. decstates m_state; // used to track where we are in putting together
  72. // characters while deciphering HTTP encoding.
  73. CString m_strInput; // The original input buffer, containing name/value pairs.
  74. // It is also possible to "push" a pair onto the front of
  75. // this buffer
  76. int m_nIndex; // index into the string of m_strInput. Keeps track of
  77. // where we are in the parse.
  78. };
  79. // forward declaration
  80. class CDBLoadConfiguration;
  81. class CTopic;
  82. class CSniffConnector;
  83. //
  84. //
  85. class APGTSContext
  86. {
  87. private:
  88. //
  89. // this nested class is an internal manager if nid-value pairs container
  90. //
  91. class CCommandsAddManager;
  92. class CCommands
  93. {
  94. friend class CCommandsAddManager;
  95. private:
  96. //
  97. // this nested class represent name/value pairs we get from an HTML form
  98. //
  99. class NID_VALUE_PAIR
  100. {
  101. friend class CCommands;
  102. private:
  103. NID nid; // Note two special values:
  104. // nidProblem: value is a node
  105. // nidNil: ignore value
  106. int value; // typically a node state, but for nidProblem, it's
  107. // problem node NID
  108. public:
  109. bool operator<(const NID_VALUE_PAIR & pair)const
  110. {return nid<pair.nid || value<pair.value;};
  111. bool operator==(const NID_VALUE_PAIR & pair)const
  112. {return nid==pair.nid || value==pair.value;};
  113. };
  114. private:
  115. vector<NID_VALUE_PAIR>m_arrPair;
  116. private: // CAddManager is managing addition to object of this class
  117. int Add( NID nid, int value );
  118. public:
  119. CCommands() {}
  120. ~CCommands() {}
  121. int GetSize() const;
  122. void RemoveAll();
  123. bool GetAt( int nIndex, NID &nid, int &value ) const;
  124. void RotateProblemPageToFront();
  125. };
  126. //
  127. // this nested class is an internal manager of additions to
  128. // "Commands: and "Sniffed" objects of CCommands class
  129. //
  130. class CCommandsAddManager
  131. {
  132. CCommands& m_Commands;
  133. CCommands& m_Sniffed;
  134. public:
  135. CCommandsAddManager(CCommands& commands, CCommands& sniffed) : m_Commands(commands), m_Sniffed(sniffed) {}
  136. ~CCommandsAddManager() {}
  137. public:
  138. void Add(NID nid, int value, bool sniffed);
  139. };
  140. //
  141. // this nested class is an internal manager if name-value pairs container
  142. // carrying additional imformation from HTMP form
  143. //
  144. class CAdditionalInfo
  145. {
  146. private:
  147. //
  148. // this nested class represent name/value pairs we get from an HTML form
  149. //
  150. class NAME_VALUE_PAIR
  151. {
  152. friend class CAdditionalInfo;
  153. private:
  154. CString name;
  155. CString value;
  156. public:
  157. bool operator<(const NAME_VALUE_PAIR & pair)const
  158. {return name<pair.name;};
  159. bool operator==(const NAME_VALUE_PAIR & pair)const
  160. {return name==pair.name;};
  161. };
  162. private:
  163. vector<NAME_VALUE_PAIR>m_arrPair;
  164. public:
  165. CAdditionalInfo() {}
  166. ~CAdditionalInfo() {}
  167. int GetSize() const;
  168. void RemoveAll();
  169. bool GetAt( int nIndex, CString& name, CString& value ) const;
  170. int Add( const CString& name, const CString& value );
  171. };
  172. protected:
  173. enum eOpAction {eNoOpAction, eReloadTopic, eKillThread, eReloadAllTopics, eSetReg};
  174. public:
  175. APGTSContext( CAbstractECB *pECB,
  176. CDBLoadConfiguration *pConf,
  177. CHTMLLog *pLog,
  178. GTS_STATISTIC *pStat,
  179. CSniffConnector* pSniffConnector);
  180. ~APGTSContext();
  181. void ProcessQuery();
  182. static BOOL StrIsDigit(LPCTSTR pSz);
  183. CString RetCurrentTopic() const;
  184. protected:
  185. void CheckAndLogCookie();
  186. void DoContent();
  187. DWORD ProcessCommands(LPTSTR pszCmd, LPTSTR pszValue);
  188. VOID ClearCommandList();
  189. VOID ClearSniffedList();
  190. VOID ClearAdditionalInfoList();
  191. //bool PlaceNodeInCommandList(NID nid, IST ist);
  192. //bool PlaceNodeInSniffedList(NID nid, IST ist);
  193. //bool PlaceInAdditionalInfoList(const CString& name, const CString& value);
  194. VOID SetNodesPerCommandList();
  195. VOID SetNodesPerSniffedList();
  196. VOID ProcessAdditionalInfoList();
  197. VOID ReadPolicyInfo();
  198. VOID LogNodesPerCommandList();
  199. CString GetStartOverLink();
  200. bool StripSniffedNodePrefix(LPTSTR szName);
  201. DWORD DoInference(
  202. LPTSTR pszCmd,
  203. LPTSTR pszValue,
  204. CTopic * pTopic,
  205. bool bUsesIDH);
  206. DWORD NextCommand(LPTSTR pszCmd, LPTSTR pszValue, bool bUsesIDH);
  207. DWORD NextAdditionalInfo(LPTSTR pszCmd, LPTSTR pszValue);
  208. DWORD NextIgnore(LPTSTR pszCmd, LPTSTR pszValue);
  209. NID NIDFromSymbolicName(LPCTSTR szNodeName);
  210. char *GetCookieValue(char *pszName, char *pszNameValue);
  211. void asctimeCookie(const struct tm &gmt, char * szOut);
  212. void SetError(LPCTSTR szMessage);
  213. // Operator actions
  214. eOpAction IdentifyOperatorAction(CAbstractECB *pECB);
  215. eOpAction ParseOperatorAction(CAbstractECB *pECB, CString & strArg);
  216. void ExecuteOperatorAction(
  217. CAbstractECB *pECB,
  218. eOpAction action,
  219. const CString & strArg);
  220. // Status pages: code is in separate StatusPage.cpp
  221. void DisplayFirstPage(bool bHasPwd);
  222. void DisplayFurtherGlobalStatusPage();
  223. void DisplayThreadStatusOverviewPage();
  224. void DisplayTopicStatusPage(LPCTSTR topic_name);
  225. bool ShowFullFirstPage(bool bHasPwd);
  226. void InsertPasswordInForm();
  227. void BeginSelfAddressingForm();
  228. protected:
  229. CAbstractECB *m_pECB; // effectively, everything that came in from
  230. // the user in a submitted HTML form
  231. DWORD m_dwErr;
  232. // The next 2 are arrays of TCHAR rather than being CString, because it's easier
  233. // for when they need to be passed to methods of EXTENSION_CONTROL_BLOCK
  234. TCHAR m_ipstr[MAXBUF]; // Remote IP address (who submitted the form)
  235. TCHAR m_resptype[MAXBUF]; // HTTP response type e.g. "200 OK",
  236. // "302 Object Moved"
  237. CString m_strHeader; // header for response file (indicates whether
  238. // we're sending HTML, setting a cookie, etc.)
  239. // >>> $UNICODE Is it OK that this is CString (based
  240. // on TCHAR) or should it always be char? JM 10/27/98
  241. CString m_strText; // this is where we build the string to pass
  242. // back over the net.
  243. // >>> $UNICODE Is it OK that this is CString (based
  244. // on TCHAR) or should it always be char? JM 10/27/98
  245. CString m_strLocalIPAddress; // IP address (in the dotted form) for the local machine
  246. // If not defined: GetLength() == 0
  247. CLogString m_logstr; // We log to this object & when we're all done
  248. // destructor writes it to the log.
  249. CHttpQuery m_Qry; // takes in raw URL-encoded string, gives us
  250. // functions to get back scanned pairs.
  251. CDBLoadConfiguration *m_pConf; // contains support-file data structures
  252. CString m_strVRoot; // Local URL to this DLL
  253. TCHAR *m_pszQuery; // a copy of what came in via GET or POST
  254. CInfer m_infer; // belief-network handler, unique to this request
  255. // This works out what node to show and builds HTML
  256. // fragments for the HTI template to render.
  257. CHTMLLog *m_pLog; // access to writing to the log.
  258. bool m_bPostType; // TRUE = post, FALSE = get
  259. DWORD m_dwBytes; // length of query string in chars, excluding
  260. // terminating null.
  261. GTS_STATISTIC *m_pStat;
  262. CCommandsAddManager m_CommandsAddManager; // manages adding data to m_Commands and m_Sniffed
  263. CCommands m_Commands; // name/value pairs we get from an HTML form
  264. CCommands m_Sniffed; // name/value pairs (for sniffed nodes) we get
  265. // from an HTML form; "SNIFFED_" already stripped out.
  266. CAdditionalInfo m_AdditionalInfo; // name/value pairs we get from HTML. They represent
  267. // additional info. Additional info is name/value
  268. // pair other then command pair (C_TYPE, C_TOPIC or C_PRELOAD),
  269. // though first in name/value pair's sequence
  270. // will be a command.
  271. bool m_bPreload; // TRUE = name/value pairs aren't really from a
  272. // user, they're from a sniffer.
  273. bool m_bNewCookie; // true = we had to create a new cookie for this
  274. // query: they didn't already have one.
  275. CHourlyDailyCounter * const m_pcountUnknownTopics; // count requests where the topic is not known in
  276. // the LST file.
  277. CHourlyDailyCounter * const m_pcountAllAccessesFinish; // Each time we finish with any sort of request,
  278. // successful or not, this gets incremented.
  279. CHourlyDailyCounter * const m_pcountStatusAccesses; // Each time we finish a request for system status
  280. CHourlyDailyCounter * const m_pcountOperatorActions; // Count operator action requests.
  281. CString m_TopicName;
  282. // You can compile with the NOPWD option to suppress all password checking.
  283. // This is intended mainly for creating test versions with this feature suppressed.
  284. #ifndef NOPWD
  285. CString m_strTempPwd; // temporary password (if this is a status request)
  286. #endif // ifndef NOPWD
  287. // You can compile with the SHOWPROGRESS option to get a report on the progress of this page.
  288. #ifdef SHOWPROGRESS
  289. time_t timeCreateContext;
  290. time_t timeStartInfer;
  291. time_t timeEndInfer;
  292. time_t timeEndRender;
  293. #endif // SHOWPROGRESS
  294. private:
  295. // Functions to set and retrieve an alternate HTI file name.
  296. void SetAltHTIname( const CString& strHTIname );
  297. CString GetAltHTIname() const;
  298. CString m_strAltHTIname; // name of the alternate HTI template file if specified.
  299. typedef map<CString,CString> CCookiePairs;
  300. CCookiePairs m_mapCookiesPairs; // Map of command line cookie name-value pairs.
  301. };
  302. // global prototypes
  303. //UINT PoolTask(LPVOID);
  304. UINT WINAPI PoolTask( LPVOID lpParams );
  305. bool ProcessRequest(CPoolQueue & PoolQueue);
  306. DWORD WINAPI DirNotifyTask( LPDWORD lpParams );
  307. /////////////////////////////////////////////////////////////////////////////
  308. #endif // APGTSCLS_H_INCLUDED