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.

140 lines
5.1 KiB

  1. //
  2. // MODULE: APGTSBESREAD.H
  3. //
  4. // PURPOSE: BES file reading classes
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Oleg Kalosha
  9. //
  10. // ORIGINAL DATE: 7-29-98
  11. //
  12. // NOTES:
  13. // Typical BES file content might be:
  14. // <FORM METHOD=POST ACTION="/scripts/samples/search/query.idq">
  15. // <INPUT TYPE=HIDDEN NAME="CiMaxRecordsPerPage" VALUE="10">
  16. // <INPUT TYPE=HIDDEN NAME="CiScope" VALUE="/">
  17. // <INPUT TYPE=HIDDEN NAME="TemplateName" VALUE="query">
  18. // <INPUT TYPE=HIDDEN NAME="HTMLQueryForm" VALUE="/samples/search/query.htm">
  19. // Enter items to search for
  20. // <INPUT TYPE=TEXT NAME="CiRestriction" VALUE="print OR &quot;network print&quot;">
  21. // <INPUT TYPE=SUBMIT VALUE="Search">
  22. // </FORM>
  23. // See corresponding .cpp file for details of restrictions & for other notes.
  24. //
  25. // Version Date By Comments
  26. //--------------------------------------------------------------------
  27. // V3.0 08-04-98 OK
  28. // V3.0 08-31-98 JM support both returning a raw & an URL encoded form
  29. //
  30. #ifndef __APGTSBESREAD_H_
  31. #define __APGTSBESREAD_H_
  32. #include "fileread.h"
  33. ////////////////////////////////////////////////////////////////////////////////////
  34. // CAPGTSBESReaderException
  35. ////////////////////////////////////////////////////////////////////////////////////
  36. class CAPGTSBESReader;
  37. class CAPGTSBESReaderException : public CFileReaderException
  38. {
  39. public:
  40. enum eAPGTSBESErr { eEV_GTS_ERROR_BES_MISS_TYPE_TAG, // %1 %2 Backend search file does not have TYPE tag (make sure tag is all caps in file): TYPE= %3 %4
  41. eEV_GTS_ERROR_BES_MISS_CT_TAG, // %1 %2 Backend search file is missing close tag '>' for TYPE tag %3 %4
  42. eEV_GTS_ERROR_BES_MISS_CN_TAG, // %1 %2 Backend search file is missing close tag '>' for NAME tag %3 %4
  43. eEV_GTS_ERROR_BES_MISS_CV_TAG // %1 %2 Backend search file is missing close tag '>' for VALUE tag %3 %4
  44. } m_eAPGTSBESErr;
  45. public:
  46. // source_file is LPCSTR rather than LPCTSTR because __FILE__ is char[35]
  47. CAPGTSBESReaderException(CFileReader* reader, eAPGTSBESErr err, LPCSTR source_file, int line);
  48. };
  49. ////////////////////////////////////////////////////////////////////////////////////
  50. // CBESPair
  51. // represents name value pair for TYPE=TEXT field in a form
  52. // value (BESStr) will reflect what we're searching for.
  53. ////////////////////////////////////////////////////////////////////////////////////
  54. struct CBESPair
  55. {
  56. // data
  57. CString Name; // in the example in the notes at the head of this file,
  58. // this would be "CiRestriction"
  59. // code
  60. CString GetBESStr() const {return BESStr;}
  61. CBESPair& operator << (const vector<CString>& in);
  62. protected:
  63. CString BESStr; // value
  64. };
  65. ////////////////////////////////////////////////////////////////////////////////////
  66. // CAPGTSBESReader
  67. // Read BES file
  68. // Includes interface to modify content of BES file into GET-POST method
  69. ////////////////////////////////////////////////////////////////////////////////////
  70. class CAPGTSBESReader : public CTextFileReader
  71. {
  72. public:
  73. static LPCTSTR FORM;
  74. static LPCTSTR METHOD;
  75. static LPCTSTR ACTION;
  76. static LPCTSTR INPUT;
  77. static LPCTSTR TYPE;
  78. static LPCTSTR NAME;
  79. static LPCTSTR VALUE;
  80. static LPCTSTR HIDDEN;
  81. static LPCTSTR TEXT;
  82. public:
  83. static void URLEncodeString(const CString& in, CString& out);
  84. static bool DecodeInputString(CFileReader* reader, const CString& str, CString& type, CString& name, CString& value);
  85. protected:
  86. CString m_strURLEncodedForm; // URL-encoded entire form (name-value pairs for a
  87. // GET-method query) including the string to search on.
  88. CBESPair m_SearchText; // contains non-URL-encoded BES name - value pair
  89. // Initial BES content resides in CFileReader::m_StreamData,
  90. // but is really of no interest.
  91. vector<CString> m_arrBESStr; // contains array of encoded partial search strings
  92. // for BES search. In practice, these correspond to
  93. // certain node/state pairs
  94. vector<CString> m_arrRawForm; // contains array of unparsed strings exactly as they
  95. // come from the BES file
  96. int m_iBES; // index of element in m_arrRawForm before which
  97. // we place search string (to build a whole form).
  98. vector<CString> m_arrURLEncodedForm; // contains array of parsed and encoded strings
  99. public:
  100. CAPGTSBESReader(CPhysicalFileReader * pPhysicalFileReader, LPCTSTR szDefaultContents = NULL);
  101. ~CAPGTSBESReader();
  102. void GenerateBES(
  103. const vector<CString> & arrstrIn,
  104. CString & strEncoded,
  105. CString & strRaw);
  106. protected:
  107. CAPGTSBESReader& operator << (const CString& in); // add (AND) new clause into search expression.
  108. CAPGTSBESReader& operator >> (const CString& in); // roll back clause addition
  109. CAPGTSBESReader& ClearSearchString();
  110. void GetURLEncodedForm(CString&);
  111. void GetRawForm(CString&);
  112. protected:
  113. virtual void Parse();
  114. protected:
  115. virtual void BuildURLEncodedForm();
  116. virtual bool IsMethodString(const CString&) const;
  117. virtual bool IsBESString(const CString&) const;
  118. virtual bool IsTypeString(const CString&) const;
  119. virtual bool ParseMethodString(const CString& in, CString& out);
  120. virtual bool ParseBESString(const CString& in, CBESPair& out);
  121. virtual bool ParseTypeString(const CString& in, CString& out);
  122. };
  123. #endif