applayerprotocols/httptransportfw/httpmessage/thttpdataparser.h
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __THTTPDATAPARSER_H__
       
    17 #define __THTTPDATAPARSER_H__
       
    18 
       
    19 #include <e32std.h>
       
    20 
       
    21 class MHttpBufferSupplier;
       
    22 
       
    23 class THttpDataParser 
       
    24 /**
       
    25 	The THttpDataParser provides the functionality to parse a data buffer for
       
    26 	lines, as specified in RFC2616. This states in section 2.2 that the end of
       
    27 	line marker for all protocol elements (except the entity body) as the 
       
    28 	sequence CR LF.
       
    29 
       
    30 	Parsed lines are copied into a buffer supplied by an MHttpBufferSupplier
       
    31 	object. If there is not enough space for the line date, the data parser
       
    32 	asks the buffer supplier to resize the buffer to at least the required size.
       
    33 
       
    34 	When parsing a header field line values can be folded onto multiple lines
       
    35 	if the continuation line begins with one or more SPs or HTs. This is known
       
    36 	as LWS and can be replaced by a single SP without changing any of the 
       
    37 	semantics.
       
    38 
       
    39 	Also, some tolerence has been built-in for robustness. The data parser can
       
    40 	parse for lines were the end of line marker is just a LF - the leading CR
       
    41 	has been omitted. This tolerance is suggested in section 19.4 of RFC2616.
       
    42 	There is also tolerence to spurios CRs in the data.
       
    43 	@internalComponent
       
    44 	@see		MHttpBufferSupplier
       
    45 */
       
    46 	{
       
    47 public:	// enums
       
    48 
       
    49 	enum TParseResult
       
    50 /**	
       
    51 	The TParseResult enumeration defines the possible result of a specified data
       
    52 	parsing request.
       
    53 */
       
    54 		{
       
    55 		/** The requested parse for a line was successful.
       
    56 		*/
       
    57 		ELineParsed			=0,
       
    58 
       
    59 		/** The requested parse was not successful due to a lack of data.
       
    60 		*/
       
    61 		EPartialData,
       
    62 
       
    63 		/** The requested parse for an empty line was successful.
       
    64 		*/
       
    65 		EEmptyLine,
       
    66 
       
    67 		/** The requested parse for the specified data chunk was successful.
       
    68 		*/
       
    69 		EGotData
       
    70 		};
       
    71 
       
    72 public:	// methods
       
    73 
       
    74 	THttpDataParser(MHttpBufferSupplier& aBufferSupplier);
       
    75 
       
    76 	TParseResult GetLineL(TPtrC8& aLine);
       
    77 	TParseResult GetHeaderLineL(TPtrC8& aLine);
       
    78 	TParseResult GetData(TPtrC8& aData, TInt aMaxSize);
       
    79 
       
    80 	void SetData(const TDesC8& aData);
       
    81 	void UnparsedData(TPtrC8& aData);
       
    82 
       
    83 	void Reset();
       
    84 
       
    85 private:	// enums
       
    86 
       
    87 	enum TDataParserState
       
    88 /**	
       
    89 	The TDataParserState enumeration defines the state machine for the data 
       
    90 	parser when performing a requested line parse. This can be either a standard
       
    91 	line or a header value line.
       
    92 */
       
    93 		{
       
    94 		/**	The data parser is idle. It ready to parse for another line or for
       
    95 			a data chunk.
       
    96 		*/
       
    97 		EIdle				= 0,
       
    98 
       
    99 		/**	The data parser has not found the start of a CRLF. More data is
       
   100 			required.
       
   101 		*/
       
   102 		EPendingMoreData,
       
   103 
       
   104 		/** The data parser has found a CR. The LF is the next expected character.
       
   105 		*/
       
   106 		EPendingLF,
       
   107 
       
   108 		/**	The data parser has found a CR at the start of its data buffer. This
       
   109 			indicates that an empty line has been found. The LF is the next
       
   110 			expected character.
       
   111 		*/
       
   112 		EPendingEmptyLine,
       
   113 
       
   114 		/**	The LF of non-empty line has been found. The next expected character
       
   115 			should not be a SP or a HT which would otherwise indicate LWS 
       
   116 			when searching for a header line. In the case of a standard line any
       
   117 			character is expected.
       
   118 		*/
       
   119 		EPendingFoundLine
       
   120 		};
       
   121 
       
   122 
       
   123 	enum TLineType
       
   124 /**	
       
   125 	The TLineType enumeration defines the type of line that the data parser has
       
   126 	been requested to parse. There are two types - a standard line and a header
       
   127 	line. The difference is that a header line is delimited by a CRLF that is not
       
   128 	followed by one or more SPs or HTs.
       
   129 */
       
   130 		{
       
   131 		/**	This specifies a standard line - delimited by a CRLF.
       
   132 		*/
       
   133 		EStandardLine		= 0,
       
   134 
       
   135 		/**	This specifies a header line - delimited by a CRLF that is not
       
   136 			followed by one or more SPs or HTs.
       
   137 		*/
       
   138 		EHeaderLine
       
   139 		};
       
   140 
       
   141 private:	// methods
       
   142 
       
   143 	void AppendToBufferL(const TDesC8& aData);
       
   144 	TParseResult GetLineL(TPtrC8& aLine, TLineType aLineType);
       
   145 	TInt FindEOLMarker(TChar& aEOLMarker);
       
   146 
       
   147 private:	// attributes
       
   148 
       
   149 	MHttpBufferSupplier&	iBufferSupplier;
       
   150 	TDataParserState		iState;
       
   151 	TPtrC8					iData;
       
   152 	TPtr8					iLineBuffer;
       
   153 
       
   154 	};
       
   155 
       
   156 #endif	// __THTTPDATAPARSER_H__