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.

308 lines
4.6 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"
  17. // protocols Token and copy functions stop at the terminating
  18. // '\n' and '\r' is considered white space. All methods except
  19. // NextLine() stop at the end of the line.
  20. //
  21. class ODBC_PARSER
  22. {
  23. public:
  24. ODBC_PARSER(
  25. CHAR * pszStart
  26. );
  27. //
  28. // Be careful about destruction. The Parser will attempt to
  29. // restore any modifications to the string it is parsing
  30. //
  31. ~ODBC_PARSER( VOID );
  32. //
  33. // Returns the current position in the buffer w/o any terminators
  34. //
  35. CHAR *
  36. QueryPos(
  37. VOID
  38. );
  39. //
  40. // Returns the current zero terminated token. If list mode is on,
  41. // then ',' is considered a delimiter.
  42. //
  43. CHAR *
  44. QueryToken(
  45. VOID
  46. );
  47. //
  48. // Returns the current zero terminated line
  49. //
  50. CHAR *
  51. QueryLine(
  52. VOID
  53. );
  54. //
  55. // Skips to the first token after the next '\n'
  56. //
  57. CHAR *
  58. NextLine(
  59. VOID
  60. );
  61. //
  62. // Returns the next non-white string after the current string with a
  63. // zero terminator. The end of the token is '\n' or white space
  64. //
  65. CHAR *
  66. NextToken(
  67. VOID
  68. );
  69. //
  70. // Returns the next non-white string after the current string with a
  71. // zero terminator. The end of the token is '\n', white space or ch.
  72. //
  73. CHAR *
  74. NextToken(
  75. CHAR ch
  76. );
  77. //
  78. // Move position cch characters into the current token. Automatically
  79. // moves to next non-white space character
  80. //
  81. VOID
  82. operator+=(
  83. int cch
  84. )
  85. {
  86. if ( cch )
  87. {
  88. while ( cch-- && *m_pszPos )
  89. {
  90. m_pszPos++;
  91. }
  92. }
  93. EatWhite();
  94. }
  95. //
  96. // Look for the character ch, stops at '\r' or '\n'
  97. //
  98. CHAR *
  99. SkipTo(
  100. CHAR ch
  101. );
  102. //
  103. // If list mode is on, then commas and semi-colons are considered
  104. // delimiters, otherwise only white space is considered
  105. //
  106. VOID
  107. SetListMode(
  108. BOOL fListMode
  109. );
  110. //
  111. // Sets the current pointer to passed position
  112. //
  113. VOID
  114. SetPtr(
  115. CHAR * pch
  116. );
  117. //
  118. // Returns the next semi-colon delimited parameter in the character
  119. // stream as a zero terminated, white space trimmed string
  120. //
  121. CHAR *
  122. NextParam(
  123. VOID
  124. )
  125. {
  126. return NextToken( ';' );
  127. }
  128. //
  129. // Returns the next comma delmited item in the character stream as
  130. // a zero terminated, white space trimmed string
  131. //
  132. CHAR *
  133. NextItem(
  134. VOID
  135. )
  136. {
  137. return NextToken( ',' );
  138. }
  139. //
  140. // Copies from the current position to the first white space character
  141. // (or \r or \n). If fAdvance is TRUE, the position is automatically
  142. // moved to the next token.
  143. //
  144. HRESULT
  145. CopyToken(
  146. STRA * pstr,
  147. BOOL fAdvanceToken = FALSE
  148. );
  149. //
  150. // Copies from the current parse position to the first of a \r or \n
  151. // and trims any white space
  152. //
  153. HRESULT
  154. CopyToEOL(
  155. STRA * pstr,
  156. BOOL fAdvanceLine = FALSE
  157. );
  158. //
  159. // Same as CopyToEOL except the data is appended to pstr
  160. //
  161. HRESULT
  162. AppendToEOL(
  163. STRA * pstr,
  164. BOOL fAdvanceLine = FALSE
  165. );
  166. //
  167. // Moves the current parse position to the first white or non-white
  168. // character after the current position
  169. //
  170. CHAR *
  171. EatWhite(
  172. VOID
  173. )
  174. {
  175. return m_pszPos = AuxEatWhite();
  176. }
  177. CHAR *
  178. EatNonWhite(
  179. VOID
  180. )
  181. {
  182. return m_pszPos = AuxEatNonWhite();
  183. }
  184. //
  185. // Undoes any temporary terminators in the string
  186. //
  187. VOID
  188. RestoreBuffer(
  189. VOID
  190. )
  191. {
  192. RestoreToken();
  193. RestoreLine();
  194. }
  195. protected:
  196. CHAR *
  197. AuxEatWhite(
  198. VOID
  199. );
  200. CHAR *
  201. AuxEatNonWhite(
  202. CHAR ch = '\0'
  203. );
  204. CHAR *
  205. AuxSkipTo(
  206. CHAR ch
  207. );
  208. VOID
  209. TerminateToken(
  210. CHAR ch = '\0'
  211. );
  212. VOID
  213. RestoreToken(
  214. VOID
  215. );
  216. VOID
  217. TerminateLine(
  218. VOID
  219. );
  220. VOID
  221. RestoreLine(
  222. VOID
  223. );
  224. private:
  225. //
  226. // Current position in parse buffer
  227. //
  228. CHAR * m_pszPos;
  229. //
  230. // If we have to temporarily zero terminate a token or line these
  231. // members contain the information
  232. //
  233. CHAR * m_pszTokenTerm;
  234. CHAR m_chTokenTerm;
  235. CHAR * m_pszLineTerm;
  236. CHAR m_chLineTerm;
  237. BOOL m_fListMode;
  238. };
  239. # endif // _PARSE_HXX_