servicediscoveryandcontrol/pnp/test/upnp/upnpmessage/inc/cupnprequestparser.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 __CUPNPREQUESTPARSER_H_
       
    17 #define __CUPNPREQUESTPARSER_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 #include <rmemcell.h>
       
    27 
       
    28 // User includes
       
    29 #include "mhttpmessageparserobserver.h"
       
    30 #include "CRequest.h"
       
    31 #include "rhttpmessageparser.h"
       
    32 #include "mparserobserver.h"
       
    33 
       
    34 
       
    35 class CUpnpRequestParser: public CBase,
       
    36 							public MHttpMessageParserObserver,
       
    37 							public MHTTPDataSupplier
       
    38 	{
       
    39 public:
       
    40 	IMPORT_C static CUpnpRequestParser* NewL(MParserObserver& aObserver);
       
    41 	IMPORT_C virtual ~CUpnpRequestParser();
       
    42 	IMPORT_C void ParseRequest(RMemChunk& aMessage, CRequest* aRequest);
       
    43 	IMPORT_C void ResetParser();
       
    44 	inline void DataFailed ();
       
    45 	
       
    46 private: 
       
    47 	// methods from MHTTPDataSupplier
       
    48 	TBool GetNextDataPart(TPtrC8& aDataPart);
       
    49 	void ReleaseData();
       
    50 	TInt OverallDataSize();
       
    51 	TInt Reset();
       
    52 
       
    53 	// methods from MHttpMessageParserObserver
       
    54 	void GetDataPacket(TPtrC8& aData);
       
    55 	void ReleaseDataPacket();
       
    56 	void StartLineL(const TDesC8& aStartLine);
       
    57 	void HeaderL(const TDesC8& aFieldName, TDesC8& aFieldValue);
       
    58 	TInt BodySizeL();
       
    59 	void BodyChunkL(const TDesC8& aData);
       
    60 	void BodyCompleteL();
       
    61 	void MessageCompleteL(const TPtrC8& aExcessData);
       
    62 	TInt HandleParserError(TInt aError);
       
    63 	
       
    64 private:
       
    65 	CUpnpRequestParser(MParserObserver& aObserver);
       
    66 	void ConstructL();
       
    67 	
       
    68 	inline TBool BodyComplete();
       
    69 	inline TBool MessageComplete();
       
    70 	inline TBool NotifyReleaseData();
       
    71     inline TBool IsExcessData();
       
    72 
       
    73 private:
       
    74 
       
    75 	enum THttpResponseFlags
       
    76 		{
       
    77 		EBodyComplete			= 0x02,
       
    78 	    ENotifyReleaseData		= 0x10,
       
    79 		EBodyPresent			= 0x20,
       
    80 		EExcessData				= 0x40,
       
    81 		};
       
    82 
       
    83 private:
       
    84 	CRequest* 				iRequest;
       
    85 	RHttpMessageParser		iMessageParser;
       
    86 	TInt					iFlags;
       
    87 	TInt					iOverallDataSize;
       
    88 	MParserObserver& 		iObserver;
       
    89 	RArray<TPtrC8>			iBodyParts;	
       
    90 	RMemChunk				iMsgBuf;
       
    91 	RArray<TPtrC8>			iRawDataArray;
       
    92 	
       
    93 	__FLOG_DECLARATION_MEMBER;
       
    94 	};
       
    95 	
       
    96 inline TBool CUpnpRequestParser::BodyComplete()
       
    97 	{
       
    98 	return iFlags & EBodyComplete;
       
    99 	}
       
   100 
       
   101 inline TBool CUpnpRequestParser::NotifyReleaseData()
       
   102 	{
       
   103 	return iFlags & ENotifyReleaseData;
       
   104 	}
       
   105 
       
   106 inline TBool CUpnpRequestParser::IsExcessData()
       
   107  	{
       
   108  	return iFlags & EExcessData;
       
   109  	}
       
   110  	
       
   111 // Free up corrupted UDP data packet
       
   112 void CUpnpRequestParser::DataFailed ()
       
   113 	{
       
   114 	if ( !iMsgBuf.IsEmpty() )
       
   115 		{
       
   116 		iMsgBuf.Free ();
       
   117 		}
       
   118 	}
       
   119 		
       
   120 #endif /*CUPNPREQUESTPARSER_H_*/