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.

185 lines
7.5 KiB

  1. //
  2. // MODULE: APGTSHTIREAD.H
  3. //
  4. // PURPOSE: HTI template file reading classes
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Oleg Kalosha
  9. //
  10. // ORIGINAL DATE: 8-12-98
  11. //
  12. // NOTES:
  13. //
  14. // Version Date By Comments
  15. //--------------------------------------------------------------------
  16. // V3.0 08-04-98 OK
  17. //
  18. #ifndef __APGTSHTIREAD_H_
  19. #define __APGTSHTIREAD_H_
  20. #include "templateread.h"
  21. #include "HTMLFrag.h"
  22. // these are not really commands, just service symbols
  23. #define COMMAND_STARTSTR _T("<!GTS")
  24. #define COMMAND_ENDSTR _T(">")
  25. #define COMMAND_IFSTR _T("if")
  26. #define COMMAND_STARTVARSTR _T("$")
  27. // JSM V3.2 -- used to decode string argumentss
  28. #define COMMAND_DOUBLEQUOTE _T("\"")
  29. #define COMMAND_ESCAPECHAR _T("\\")
  30. // commands that have to be interpreted
  31. #define COMMAND_ELSESTR _T("else")
  32. #define COMMAND_ENDIFSTR _T("endif")
  33. #define COMMAND_FORANYSTR _T("forany")
  34. #define COMMAND_ENDFORSTR _T("endfor")
  35. // commands that presume putting substitution string on their place
  36. #define COMMAND_DISPLAYSTR _T("display")
  37. #define COMMAND_RESOURCESTR _T("resource")
  38. // command that brings general information, that can be processed
  39. // in classes inherited from CHTMLFragmentsTS
  40. #define COMMAND_INFORMATION _T("information")
  41. // command that makes CHTMLFragmentsTS store some value
  42. #define COMMAND_VALUE _T("value")
  43. // command that substitutes Network Property in the HTML:
  44. #define COMMAND_PROPERTY _T("property")
  45. //
  46. // V3.2 Additions.
  47. #define COMMAND_ELSEIFSTR _T("elseif")
  48. #define COMMAND_COOKIE _T("<!Cookie")
  49. #define DELIMITER_POSTFIX _T("!")
  50. #define DELIMITER_PREFIX _T("_")
  51. //
  52. // NO error handling here - whatever the result is, it will be accepted,
  53. // the program flow should go to the end. NO throw exception.
  54. //
  55. ///////////////////////////////////////////////////////////////////////////////////////////
  56. // CAPGTSHTIReader
  57. // Term "Interpret" here is: unwind initial script with <!GTS forany $Something> or
  58. // <!GTS if $Something> to <!GTS forany $Something!24_SomethingElse!2...>
  59. // This interpreted script is to be ready for direct substitutions of <!GTS display ...>
  60. // and <!GTS resource ...>, which are only commands left in the interpreted script
  61. ///////////////////////////////////////////////////////////////////////////////////////////
  62. class CAPGTSHTIReader : public CTemplateReader
  63. {
  64. protected: // we can use data in inherited class
  65. vector<CString> m_arrInterpreted; // (partly) interpreted template - some clauses
  66. // are interpreted, when fully parsed - ready
  67. // for simple template substitution.
  68. const CHTMLFragments* m_pFragments;
  69. public:
  70. CAPGTSHTIReader(CPhysicalFileReader * pPhysicalFileReader, LPCTSTR szDefaultContents = NULL);
  71. ~CAPGTSHTIReader();
  72. protected:
  73. virtual void Parse(); // do nothing - no traditional parsing, we first have to interpret
  74. public:
  75. void CreatePage( const CHTMLFragments& fragments,
  76. CString& out,
  77. const map<CString,CString> & mapStrs,
  78. CString strHTTPcookies= _T("") );
  79. bool HasHistoryTable();
  80. // JSM V3.2 returns a vector containing all net props which appear
  81. // in the HTI file in lines like <!GTS property "fooprop">
  82. void ExtractNetProps(vector<CString> &arr_props);
  83. protected:
  84. // level below CreatePage(...)
  85. virtual void InitializeInterpreted(); // init string array with data read from HTI file
  86. virtual void Interpret(); // zoom this template in a simple template where all we need is string substitution
  87. virtual void ParseInterpreted(); // perform this substitution
  88. virtual void SetOutputToInterpreted(); // set standard template output (m_StreamOutput)
  89. // from interpreted m_arrInterpreted
  90. //
  91. // we can read output by CTemplateReader::GetOutput();
  92. //
  93. protected:
  94. // level below ...Interpret...(...)
  95. bool ExtractClause(vector<CString>& arr_text,
  96. long* pstart_index,
  97. vector<CString>& arr_clause);
  98. bool InterpretClause(vector<CString>& arr_clause);
  99. protected:
  100. // used by previous ExtractClause
  101. // start_index is supposed to be positioned to beginning of clause
  102. bool ExtractClause(vector<CString>& arr_text,
  103. long* pstart_index,
  104. vector<CString>& arr_clause,
  105. const CString& str_start_command,
  106. const CString& str_end_command);
  107. // used by InterpretClause
  108. bool InterpretForanyClause(vector<CString>& arr_clause);
  109. bool InterpretIfClause(vector<CString>& arr_clause);
  110. // lowest level - parsing and changing <!GTS &...> - strings
  111. // This function extracts command from line
  112. bool GetCommand(const CString& line, CString& command);
  113. // This command composes <!GTS operator $variable>
  114. bool ComposeCommand(const CString& oper, const CString& variable, CString& command);
  115. // This function extracts variable from line
  116. bool GetVariable(const CString& line, CString& variable);
  117. // This function parses variable like Recommendations!199_States!99 into array
  118. void ParseVariable(const CString& variable, FragmentIDVector& out);
  119. // This function composes variable from array
  120. void ComposeVariable(const FragmentIDVector& parsed, CString& variable);
  121. // This function substitutes <!GTS ....> in "line" with "str_substitution"
  122. bool SubstituteCommandBlockWith(const CString& str_substitution, CString& line);
  123. // This function composes command block <!GTS command $variable >
  124. void ComposeCommandBlock(const CString& command, const CString& variable, CString& command_block);
  125. // NOTION of prefix - postfix. Prefix - parent variable, delimited by "_" from our variable,
  126. // and postfix - number, delimited from our variable by "!"
  127. // This function forms variable like Recommendations!11 where postfix == 11
  128. void PostfixVariable(const long postfix, CString& variable);
  129. // This function forms variable like Recommendations!1_State where prefix == Recommendations!1
  130. void PrefixVariable(const CString& prefix, CString& variable);
  131. private:
  132. // VERY low level
  133. // This function reads command and variable from the <!GTS command $variable > block
  134. bool GetCommandVariableFromControlBlock(const CString& control_block, CString& command, CString& variable);
  135. // This function reads command block (<!GTS command $variable >) from line
  136. bool GetControlBlockFromLine(const CString& line, CString& control_block);
  137. // JSM V3.2
  138. // extracts a string argument from a part of the command block; called by GetCommandVariableFromControlBlock
  139. CString GetStringArg(const CString & strText);
  140. // Converts a double-quoted string w/ an `escape character' to a correct CString.
  141. CString GetEscapedText(const CString &strText);
  142. // utility function called by the above:
  143. CString RemoveEscapesFrom(const CString &strIn);
  144. #ifdef __DEBUG_CUSTOM
  145. public:
  146. bool FlushOutputStreamToFile(const CString& file_name);
  147. #endif
  148. private:
  149. // This function handles the substituting of "<!Cookie" clauses with the either
  150. // values from cookies or the default value.
  151. void SubstituteCookieValues( CString& strText );
  152. // This function searches the HTTP cookies for a given cookie name and attribute. If
  153. // found, this function returns a value of true and the located cookie value.
  154. bool LocateCookieValue( const CString& strCookieName,
  155. const CString& strCookieAttr,
  156. CString& strCookieValue );
  157. private:
  158. CString m_strHTTPcookies; // V3.2 Enhancement, contains cookies from HTTP header
  159. // which are used in the Online Troubleshooter.
  160. map<CString,CString> m_mapCookies;
  161. };
  162. #endif // __APGTSHTIREAD_H_