servicediscoveryandcontrol/pnp/test/upnp/upnpmessage/inc/cupnpresponseparser.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 // Copyright (c) 2008-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 __CUPNPRESPONSEPARSER_H_
       
    17 #define __CUPNPRESPONSEPARSER_H_
       
    18 
       
    19 // System includes
       
    20 #include <e32base.h>
       
    21 #include <http/mhttpdatasupplier.h>
       
    22 #include <http/framework/cheadercodec.h>
       
    23 #include <comms-infras/commsdebugutility.h>
       
    24 #include <http/thttptable.h>
       
    25 #include <rmemchunk.h>
       
    26 
       
    27 // User includes
       
    28 #include "mhttpmessageparserobserver.h"
       
    29 #include "CResponse.h"
       
    30 #include "rhttpmessageparser.h"
       
    31 #include "mparserobserver.h"
       
    32 
       
    33 
       
    34 class CUpnpResponseParser: public CBase,
       
    35 							public MHttpMessageParserObserver,
       
    36 							public MHTTPDataSupplier
       
    37 	{
       
    38 public:
       
    39 	IMPORT_C static CUpnpResponseParser* NewL(MParserObserver& aObserver);
       
    40 	IMPORT_C virtual ~CUpnpResponseParser();
       
    41 	IMPORT_C void ParseResponse(RMemChunk& aMessage, CResponse* aResponse);
       
    42 	IMPORT_C void ResetParser();
       
    43 	inline CResponse& Response();
       
    44 	
       
    45 private: 
       
    46 	// methods from MHTTPDataSupplier
       
    47 	TBool GetNextDataPart(TPtrC8& aDataPart);
       
    48 	void ReleaseData();
       
    49 	TInt OverallDataSize();
       
    50 	TInt Reset();
       
    51 
       
    52 	// methods from MHttpMessageParserObserver
       
    53 	void GetDataPacket(TPtrC8& aData);
       
    54 	void ReleaseDataPacket();
       
    55 	void StartLineL(const TDesC8& aStartLine);
       
    56 	void HeaderL(const TDesC8& aFieldName, TDesC8& aFieldValue);
       
    57 	TInt BodySizeL();
       
    58 	void BodyChunkL(const TDesC8& aData);
       
    59 	void BodyCompleteL();
       
    60 	void MessageCompleteL(const TPtrC8& aExcessData);
       
    61 	TInt HandleParserError(TInt aError);
       
    62 	
       
    63 private:
       
    64 	CUpnpResponseParser(MParserObserver& aObserver);
       
    65 	void ConstructL();
       
    66 
       
    67 	void ResetData();
       
    68 	inline TBool ConsumingResponse();
       
    69 	inline TBool BodyComplete();
       
    70 	inline TBool MessageComplete();
       
    71 	inline TBool GotTrailers();
       
    72 	inline TBool NotifyReleaseData();
       
    73 	inline TBool IsExcessData();
       
    74     
       
    75 private:
       
    76 
       
    77 	enum THttpResponseFlags
       
    78 		{
       
    79 		EConsumingResponse		= 0x01,
       
    80 		EBodyComplete			= 0x02,
       
    81 		EMessageComplete		= 0x04,
       
    82 	    ENotifyReleaseData		= 0x10,
       
    83 		EBodyPresent			= 0x20,
       
    84 		EExcessData				= 0x40		
       
    85 		};
       
    86 
       
    87 private:
       
    88 	CResponse* 				iResponse;
       
    89 	RHttpMessageParser		iMessageParser;
       
    90 	TInt					iFlags;
       
    91 	TInt					iOverallDataSize;
       
    92 	MParserObserver& 		iObserver;
       
    93 	RArray<TPtrC8>			iBodyParts;	
       
    94 	RMemChunk				iMsgBuf;
       
    95 	RArray<TPtrC8>			iRawDataArray;
       
    96 	
       
    97 	__FLOG_DECLARATION_MEMBER;
       
    98 	};
       
    99 	
       
   100 inline TBool CUpnpResponseParser::ConsumingResponse()
       
   101 	{
       
   102 	return iFlags & EConsumingResponse;
       
   103 	}
       
   104 
       
   105 inline TBool CUpnpResponseParser::BodyComplete()
       
   106 	{
       
   107 	return iFlags & EBodyComplete;
       
   108 	}
       
   109 
       
   110 inline TBool CUpnpResponseParser::MessageComplete()
       
   111 	{
       
   112 	return iFlags & EMessageComplete;
       
   113 	}
       
   114 
       
   115 inline TBool CUpnpResponseParser::NotifyReleaseData()
       
   116 	{
       
   117 	return iFlags & ENotifyReleaseData;
       
   118 	}
       
   119 		
       
   120 inline CResponse& CUpnpResponseParser::Response()
       
   121 	{
       
   122 	return (*iResponse);
       
   123 	}
       
   124 	
       
   125 inline TBool CUpnpResponseParser::IsExcessData()
       
   126 	{
       
   127 	return iFlags & EExcessData;	
       
   128 	}
       
   129 
       
   130 #endif /*CUPNPRESPONSEPARSER_H_*/