servicediscoveryandcontrol/pnp/test/upnp/Server/Flow/inc/httpmudpflow.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 // httpudpflow.h
       
    15 // @file
       
    16 // @internalComponent
       
    17 // 
       
    18 //
       
    19 
       
    20 #ifndef __HTTPMUDPFLOW_H_
       
    21 #define __HTTPMUDPFLOW_H_
       
    22 
       
    23 //System Includes
       
    24 #include <comms-infras/ss_subconnflow.h>
       
    25 #include <comms-infras/ss_flowbinders.h>
       
    26 #include <comms-infras/ss_protflow.h>
       
    27 #include<in_sock.h>
       
    28 #include<es_sock.h>
       
    29 #include <rmemchunk.h>
       
    30 
       
    31 #include "upnpflowbase.h"
       
    32 #include "cupnprequestparser.h"
       
    33 #include "upnp_cf_msgs.h"
       
    34 #include "httpudpflow.h"
       
    35 #include "ctimermappeduri.h"
       
    36 
       
    37 class CCallbackArgument;
       
    38 NONSHARABLE_CLASS ( CRecvElement ) : public CBase
       
    39 	{
       
    40 	public:
       
    41 
       
    42 	CRecvElement ( RMemChunk& aData, const TAppProtAddr& aAddr )
       
    43 	: iData ( aData ),
       
    44 	iAddr ( aAddr )
       
    45 	{
       
    46 	}
       
    47 
       
    48 	~CRecvElement ()
       
    49 		{
       
    50 		if ( !iData.IsEmpty () )
       
    51 			{
       
    52 			iData.Free ();
       
    53 			}
       
    54 		}
       
    55 	const TAppProtAddr& Address () const
       
    56 		{
       
    57 		return iAddr;
       
    58 		}
       
    59 
       
    60 	RMemChunk& Data ()
       
    61 		{
       
    62 		return 	iData;
       
    63 		}
       
    64 
       
    65 	private:
       
    66 	RMemChunk 		iData;
       
    67 	TAppProtAddr	iAddr;
       
    68 	};
       
    69 
       
    70 typedef RArray < CRecvElement* > CRecvElements;
       
    71 
       
    72 NONSHARABLE_CLASS ( CHttpMUdpFlow ) : public CUPnPFlowBase,
       
    73 						 			 public MParserObserver
       
    74 	{
       
    75 	friend class CUPnPFlowFactory;
       
    76 
       
    77 	public:
       
    78 	static CHttpMUdpFlow* NewL ( CSubConnectionFlowFactoryBase& aFactory,
       
    79 							  CUPnPProtocolIntfBase* aProtocolIntf,
       
    80 						  		const TNodeId& aSubConnId );
       
    81 	~CHttpMUdpFlow ();
       
    82 
       
    83 	private:
       
    84 	CHttpMUdpFlow ( CSubConnectionFlowFactoryBase& aFactory,
       
    85 					CUPnPProtocolIntfBase* aProtocolIntf,
       
    86 					const TNodeId& aSubConnId );
       
    87 
       
    88 	void ConstructL ();
       
    89 	protected:
       
    90 
       
    91 	// From CSubConnectionFlowBase
       
    92 	void ReceivedL ( const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage );
       
    93 
       
    94 	// From MParserObserver
       
    95 	virtual void GotHeaders ();
       
    96 	inline virtual void GotBodyData ();
       
    97 	virtual void DataParsed();
       
    98 	virtual void ParsingComplete ( RMemChunk& aExcessData );
       
    99 	virtual void ParserError ( TInt aError );
       
   100 
       
   101 	void StartFlow ( TNodeCtxId aSender );
       
   102 	void StopFlow ( TNodeCtxId aSender );
       
   103 	void ParseIfOneRecvElement ();
       
   104 	void ParseElement ();
       
   105 	void RemoveFirstRecvElement ();
       
   106 
       
   107 	TInt ValidateRequest ();
       
   108 	TInt ValidateNotifyRequest ();
       
   109 	TInt ValidateMSearchRequest ();
       
   110 
       
   111 	// This should be moved
       
   112 	TInt GetHeaderValue ( const CRequest& aResponse, TInt aFieldIndex, THTTPHdrVal& aFieldVal, const TStringTable& aTable ) const;
       
   113 	TInt GetParamValue ( const CRequest& aResponse, TInt aFieldIndex, TInt aParamIndex, THTTPHdrVal& aParamVal, const TStringTable& aTable ) const;
       
   114 	TBool IsHeaderPresent ( const CRequest& aResponse, TInt aFieldIndex, const TStringTable& aTable ) const;
       
   115 	TBool IsValidCacheControlHeader ( const CRequest& aResponse ) const;
       
   116 	TBool IsValidManHeader ( const CRequest& aResponse ) const;
       
   117 	TBool IsValidHostHeader ( CRequest& aRequest ) const;
       
   118 
       
   119 	void CreateMulticastListener ();
       
   120 
       
   121 	void NotifyClients ();
       
   122 	void HandleNotifyRequestL ();
       
   123 	static TInt HandleMSearchRequestL (  TAny* aPtr );
       
   124 	void RegisterL ( TNodeCtxId aChannelId, RMemChunk& aST, CSearchTargetArray& aArray );
       
   125 	void Unregister ( TNodeCtxId aChannelId );
       
   126 	void ReadRequestValues ( RStringF& aLocation, TInt& aMaxAge );
       
   127 	void ReadRequestValues ( RStringF& aSt, RStringF& aUsn, RStringF& aNts);
       
   128 	void ReadRequestValues ( TInt& aMaxAge, RStringF& aSt );
       
   129 private:
       
   130 	void CreateTimerEntryL( );
       
   131 	TInt AdjustedDelay( TInt aTime );
       
   132 	inline RPointerArray<CCallbackArgument>& GetArgumentArray();
       
   133 	inline RPointerArray<CTimerMappedUri>& GetTimerArray();
       
   134 	inline CSearchTargetArray& GetSearchTargetArray();
       
   135 private:
       
   136 	CUpnpRequestParser* 	iRequestParser;
       
   137 
       
   138 	CHeaderCodec* 			iCodec;
       
   139 
       
   140 	CSearchTargetArray		iSearchTargetArray;
       
   141 	CSearchTargetArray		iNotifyTargetArray;
       
   142 	RArray <TNodeCtxId>		iListenRequestors; // This array will be used untill the flow binds to
       
   143 													// UDP listener.
       
   144 	RMBufChain				iReceivedData;
       
   145 	CRequest*				iUPnPRequest; // Used for parsing the request
       
   146 	CRecvElements			iRecvElements;
       
   147 	TNodeId					iAppProtIntfId;
       
   148 
       
   149 	TBool					iIsStarted;
       
   150 	TBool					iIsLeaving;
       
   151 	TNodeCtxId				iLastLeavingClient;
       
   152 	RStringPool				iStringPool;
       
   153 	CDeltaTimer* 			iDeltaTimer;
       
   154 	RPointerArray<CTimerMappedUri> 		iTimerMappedArray;
       
   155 	RPointerArray<CCallbackArgument> 	iCallbackArray;
       
   156 	};
       
   157 
       
   158 void CHttpMUdpFlow::GotBodyData ()
       
   159 	{
       
   160 	ASSERT (0);
       
   161 	}
       
   162 RPointerArray<CCallbackArgument>& CHttpMUdpFlow::GetArgumentArray()
       
   163 	{
       
   164 	return iCallbackArray;
       
   165 	}
       
   166 RPointerArray<CTimerMappedUri>& CHttpMUdpFlow::GetTimerArray()
       
   167 	{
       
   168 	return iTimerMappedArray;
       
   169 	}
       
   170 CSearchTargetArray& CHttpMUdpFlow::GetSearchTargetArray()
       
   171 	{
       
   172 	return iSearchTargetArray;
       
   173 	}
       
   174 
       
   175 /*
       
   176   This class holds the *This pointer of the object calling it so that the static
       
   177   methods being called on expiry of CDeltaTimer can operate on the attributes of 
       
   178   class
       
   179  
       
   180   @internalComponent
       
   181  */
       
   182 class CCallbackArgument: public CBase
       
   183 	{
       
   184 public:
       
   185 	static CCallbackArgument* NewL(TAny* aThis ,const TAppProtAddr& aAddress , const CSearchTarget* aStTarget);
       
   186 	inline ~CCallbackArgument();
       
   187 	inline TAny* GetThisPointer() const;
       
   188 	inline const TAppProtAddr& GetAddress() const;
       
   189 	inline const CSearchTarget* SearchTarget() const ;
       
   190 	inline void SetTimerEntry( TDeltaTimerEntry* aEntry);
       
   191 	inline const TDeltaTimerEntry* GetTimerEntry() const;
       
   192 private:
       
   193 	inline CCallbackArgument (TAny* aThis , const TAppProtAddr& aAddress , const CSearchTarget* aStTarget);
       
   194 		
       
   195 	TAny* iThisPointer;
       
   196 	TAppProtAddr iAddress;
       
   197 	const CSearchTarget* iSearchTarget;
       
   198 	TDeltaTimerEntry* iTimerEntry;
       
   199 	};
       
   200 
       
   201 /* Returns the pointer to the object it contains. */
       
   202 TAny* CCallbackArgument::GetThisPointer() const
       
   203 	{
       
   204 	return iThisPointer;
       
   205 	}
       
   206 
       
   207 const TAppProtAddr& CCallbackArgument::GetAddress() const
       
   208 	{
       
   209 	return iAddress;
       
   210 	}
       
   211 
       
   212 const CSearchTarget* CCallbackArgument::SearchTarget() const
       
   213 	{
       
   214 	return iSearchTarget;
       
   215 	}
       
   216 
       
   217 void CCallbackArgument::SetTimerEntry( TDeltaTimerEntry* aEntry)
       
   218 	{
       
   219 	iTimerEntry = aEntry;
       
   220 	}
       
   221 const TDeltaTimerEntry* CCallbackArgument::GetTimerEntry() const
       
   222 	{
       
   223 	return iTimerEntry;
       
   224 	}
       
   225 CCallbackArgument::CCallbackArgument (TAny* aThis , const TAppProtAddr& aAddress , const CSearchTarget* aStTarget):iThisPointer(aThis)
       
   226 		,iAddress( aAddress ), iSearchTarget( aStTarget )
       
   227 	{
       
   228 	
       
   229 	}
       
   230 
       
   231 CCallbackArgument::~CCallbackArgument()
       
   232 	{
       
   233 	}
       
   234 #endif // __HTTPMUDPFLOW_H