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.

131 lines
3.7 KiB

  1. //
  2. // Microsoft Corporation - Copyright 1997
  3. //
  4. //
  5. // MULTPARS.H - Multipart parser (CMultipartParse) header
  6. //
  7. // Turn this on to compile a file saving version
  8. // #define FILE_SAVE
  9. #ifndef _MULTPARS_H_
  10. #define _MULTPARS_H_
  11. enum LEXICON {
  12. LEX_UNKNOWN,
  13. LEX_SPACE,
  14. LEX_CRLF,
  15. LEX_BEGIN_COMMENT,
  16. LEX_END_COMMENT,
  17. LEX_QUOTE,
  18. LEX_SEMICOLON,
  19. LEX_SLASH,
  20. // Body keywords
  21. LEX_CONTENTDISP,
  22. LEX_CONTENTTYPE,
  23. // Field IDs
  24. LEX_NAMEFIELD,
  25. LEX_FILENAMEFIELD,
  26. // MIME types
  27. LEX_MULTIPART,
  28. LEX_TEXT,
  29. LEX_APPLICATION,
  30. LEX_AUDIO,
  31. LEX_IMAGE,
  32. LEX_MESSAGE,
  33. LEX_VIDEO,
  34. LEX_MIMEEXTENSION,
  35. // MIME subtypes
  36. LEX_FORMDATA,
  37. LEX_ATTACHMENT,
  38. LEX_MIXED,
  39. LEX_PLAIN,
  40. LEX_XMSDOWNLOAD,
  41. LEX_OCTETSTREAM,
  42. LEX_BINARY,
  43. // Boundary
  44. LEX_BOUNDARY, // "CR/LF" ended boundary string
  45. LEX_EOT, // double-dashed ended boundary string
  46. LEX_STARTBOUNDARY // boundary string missing first CR/LF
  47. };
  48. typedef struct {
  49. LPSTR lpszName; // token name
  50. LEXICON eLex; // token value
  51. DWORD cLength; // length of lpszName, filled in at runtime,
  52. // should be ZERO in table def
  53. DWORD dwColor; // debugging color to be used
  54. LPSTR lpszComment; // debugging comment to be displayed
  55. } PARSETABLE, *LPPARSETABLE;
  56. typedef struct {
  57. LEXICON eContentDisposition;
  58. LPSTR lpszNameField;
  59. LPSTR lpszFilenameField;
  60. LPSTR lpszBodyContents;
  61. DWORD dwContentType;
  62. DWORD dwContentSubtype;
  63. } BODYHEADERINFO, *LPBODYHEADERINFO;
  64. #define LPBHI LPBODYHEADERINFO
  65. class CMultipartParse : public CBase
  66. {
  67. public:
  68. CMultipartParse( LPECB lpEcb, LPSTR *lppszOut, LPSTR *lppszDebug, LPDUMPTABLE lpDT );
  69. ~CMultipartParse( );
  70. // Starts parsing data using infomation from server headers
  71. BOOL PreParse( LPBYTE lpbData, LPDWORD lpdwParsed );
  72. private:
  73. LPBYTE _lpbData; // Memory containing send data
  74. LPBYTE _lpbParse; // Current parse location into _lpbData
  75. LPBYTE _lpbLastParse; // Last location of Lex parsing
  76. LPSTR _lpszBoundary; // Boundary string
  77. DWORD _cbBoundary; // Boundary string length
  78. // Debugging Data dump
  79. DWORD _cbDT; // Counter
  80. // Lex
  81. LEXICON Lex( ); // finds next Lex
  82. BOOL BackupLex( LEXICON dwLex ); // moves back one Lex
  83. LPSTR FindTokenName( LEXICON dwLex ); // finds Lex's name
  84. BOOL GetToken( ); // moves post a token of valid
  85. // header characters
  86. // states
  87. BOOL ParseBody( ); // initial state
  88. BOOL BodyHeader( );
  89. BOOL ContentDisposition( LPBODYHEADERINFO lpBHI );
  90. BOOL ContentType( LPBODYHEADERINFO lpBHI );
  91. BOOL BodyContent( LPBODYHEADERINFO lpBHI );
  92. // utilities
  93. BOOL GetBoundaryString( LPBYTE lpbData );
  94. BOOL GetQuotedString( LPSTR *lppszBuf );
  95. BOOL HandleComments( );
  96. #ifndef FILE_SAVE
  97. BOOL MemoryCompare( LPBYTE lpbSrc1, LPBYTE lpbSrc2, DWORD dwSize );
  98. #endif
  99. BOOL FindNextBoundary( LPDWORD lpdwSize );
  100. // files
  101. BOOL HandleFile( LPSTR lpszFilename );
  102. #ifndef FILE_SAVE
  103. BOOL FileCompare( LPBYTE lpbStart, LPSTR lpszFilename, DWORD dwSize );
  104. #else // FILE_SAVE
  105. BOOL FileSave( LPBYTE lpbStart, LPSTR lpszFilename, DWORD dwSize );
  106. #endif // FILE_SAVE
  107. BOOL FixFilename( LPSTR lpszFilename, LPSTR *lppszNewFilename );
  108. CMultipartParse( );
  109. }; // CMultipartParse
  110. #endif // _MULTPARS_H_