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.

206 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name :
  4. parse.hxx
  5. Abstract:
  6. Simple parser class for extrapolating HTTP headers information
  7. Author:
  8. John Ludeman (JohnL) 18-Jan-1995
  9. Project:
  10. HTTP server
  11. Revision History:
  12. --*/
  13. # ifndef _PARSE_HXX_
  14. # define _PARSE_HXX_
  15. //
  16. // Simple class for parsing all those lovely "Field: value\r\n" protocols
  17. // Token and copy functions stop at the terminating '\n' and '\r' is
  18. // considered white space. All methods except NextLine() stop at the end
  19. // of the line.
  20. //
  21. class INET_PARSER
  22. {
  23. public:
  24. dllexp INET_PARSER( CHAR * pszStart );
  25. //
  26. // Be careful about destruction. The Parser will attempt to restore any
  27. // modifications to the string it is parsing
  28. //
  29. dllexp ~INET_PARSER( VOID );
  30. //
  31. // Returns the current position in the buffer w/o any terminators
  32. //
  33. dllexp CHAR * QueryPos( VOID );
  34. //
  35. // Returns the current zero terminated token. If list mode is on, then
  36. // ',' is considered a delimiter.
  37. //
  38. dllexp CHAR * QueryToken( VOID );
  39. //
  40. // Returns the current zero terminated line
  41. //
  42. dllexp CHAR * QueryLine( VOID );
  43. //
  44. // Skips to the first token after the next '\n'
  45. //
  46. dllexp CHAR * NextLine( VOID );
  47. //
  48. // Returns the next non-white string after the current string with a
  49. // zero terminator. The end of the token is '\n' or white space
  50. //
  51. dllexp CHAR * NextToken( VOID );
  52. //
  53. // Returns the next non-white string after the current string with a
  54. // zero terminator. The end of the token is '\n', white space or ch.
  55. //
  56. dllexp CHAR * NextToken( CHAR ch );
  57. //
  58. // Move position cch characters into the current token. Automatically
  59. // moves to next non-white space character
  60. //
  61. dllexp VOID operator+=( int cch )
  62. { if ( cch ) while ( cch-- && *m_pszPos ) m_pszPos++;
  63. EatWhite();
  64. }
  65. //
  66. // Look for the character ch, stops at '\r' or '\n'
  67. //
  68. dllexp CHAR * SkipTo( CHAR ch );
  69. //
  70. // If list mode is on, then commas and semi-colons are considered
  71. // delimiters, otherwise only white space is considered
  72. //
  73. dllexp VOID SetListMode( BOOL fListMode );
  74. //
  75. // Sets the current pointer to passed position
  76. //
  77. dllexp VOID SetPtr( CHAR * pch );
  78. //
  79. // Returns the next semi-colon delimited parameter in the character
  80. // stream as a zero terminated, white space trimmed string
  81. //
  82. dllexp CHAR * NextParam( VOID )
  83. { return NextToken( ';' ); }
  84. //
  85. // Returns the next comma delmited item in the character stream as
  86. // a zero terminated, white space trimmed string
  87. //
  88. dllexp CHAR * NextItem( VOID )
  89. { return NextToken( ',' ); }
  90. //
  91. // Copies from the current position to the first white space character
  92. // (or \r or \n). If fAdvance is TRUE, the position is automatically
  93. // moved to the next token.
  94. //
  95. dllexp BOOL CopyToken( STR * pstr,
  96. BOOL fAdvanceToken = FALSE );
  97. //
  98. // Copies from the current parse position to the first of a \r or \n and
  99. // trims any white space
  100. //
  101. dllexp BOOL CopyToEOL( STR * pstr,
  102. BOOL fAdvanceLine = FALSE );
  103. //
  104. // Same as CopyToEOL except the data is appended to pstr
  105. //
  106. dllexp BOOL AppendToEOL( STR * pstr,
  107. BOOL fAdvanceLine = FALSE );
  108. //
  109. // Moves the current parse position to the first white or non-white
  110. // character after the current position
  111. //
  112. dllexp CHAR * EatWhite( VOID )
  113. { return m_pszPos = AuxEatWhite(); }
  114. dllexp CHAR * EatNonWhite( VOID )
  115. { return m_pszPos = AuxEatNonWhite(); }
  116. //
  117. // Undoes any temporary terminators in the string
  118. //
  119. dllexp VOID RestoreBuffer( VOID )
  120. { RestoreToken(); RestoreLine(); }
  121. protected:
  122. dllexp CHAR * AuxEatWhite( VOID );
  123. dllexp CHAR * AuxEatNonWhite( CHAR ch = '\0' );
  124. dllexp CHAR * AuxSkipTo( CHAR ch );
  125. dllexp VOID TerminateToken( CHAR ch = '\0' );
  126. dllexp VOID RestoreToken( VOID );
  127. dllexp VOID TerminateLine( VOID );
  128. dllexp VOID RestoreLine( VOID );
  129. private:
  130. //
  131. // Current position in parse buffer
  132. //
  133. CHAR * m_pszPos;
  134. //
  135. // If we have to temporarily zero terminate a token or line these
  136. // members contain the information
  137. //
  138. CHAR * m_pszTokenTerm;
  139. CHAR m_chTokenTerm;
  140. CHAR * m_pszLineTerm;
  141. CHAR m_chLineTerm;
  142. BOOL m_fListMode;
  143. };
  144. # endif // _PARSE_HXX_
  145.