|
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 // @file |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #ifndef HTTPSERVERFLOW_H_ |
|
20 #define HTTPSERVERFLOW_H_ |
|
21 |
|
22 //System Includes |
|
23 #include <comms-infras/ss_subconnflow.h> |
|
24 #include <comms-infras/ss_protflow.h> |
|
25 #include <comms-infras/eintsock.h> |
|
26 #include <rmemchunk.h> |
|
27 |
|
28 #include "upnpflowbase.h" |
|
29 #include "rsockethandler.h" |
|
30 #include "csocketopener.h" |
|
31 #include "httpserverhandler.h" |
|
32 #include "upnp_cf_msgs.h" |
|
33 //Local Includes |
|
34 |
|
35 using namespace ESock; |
|
36 |
|
37 class CHttpServer; |
|
38 |
|
39 class CHttpServerFlow: public CUPnPFlowBase, public MFlowBinderControl, |
|
40 /*Session Binder with Upper layer */ |
|
41 public MSessionData, public MSessionControl, public MHttpEventObserver |
|
42 { |
|
43 friend class CUPnPFlowFactory; |
|
44 public: |
|
45 static CHttpServerFlow* NewL(CSubConnectionFlowFactoryBase& aFactory, CProtocolIntfBase* aProtocolIntf, const TDesC8& aUri, const Messages::TNodeId& aSubConnId ); |
|
46 inline const TDesC8& Uri() const; |
|
47 |
|
48 private: |
|
49 |
|
50 struct TControlTransaction |
|
51 { |
|
52 TControlTransaction ( TInt aId, CServerTransaction& aTrans ) |
|
53 : iId ( aId ), |
|
54 iTransaction ( aTrans ), |
|
55 iReadComplete ( EFalse ), |
|
56 iReadTriggered ( EFalse ), |
|
57 iNotifyComplete ( EFalse ) |
|
58 { |
|
59 } |
|
60 |
|
61 CServerTransaction& iTransaction; |
|
62 TInt iId; |
|
63 TBool iNotifyComplete : 1; |
|
64 TBool iReadTriggered : 1; |
|
65 TBool iReadComplete : 1; |
|
66 }; |
|
67 |
|
68 |
|
69 // From CSubConnectionFlowBase |
|
70 virtual void ReceivedL ( const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage ); |
|
71 |
|
72 virtual MFlowBinderControl* DoGetBinderControlL(); |
|
73 |
|
74 //From MFlowBinderControl |
|
75 virtual MSessionControl* GetControlL (TInt aSessionType, MSessionControlNotify& aSessionControlNotify); |
|
76 virtual MSessionData* BindL(MSessionDataNotify& aNotify); |
|
77 virtual void Unbind(); |
|
78 virtual CSubConnectionFlowBase* Flow(); //returns its own flow |
|
79 |
|
80 // MSessionControl |
|
81 virtual void ActiveOpen(); |
|
82 inline virtual void ActiveOpen(const TDesC8& aConnectionData); |
|
83 inline virtual TInt PassiveOpen(TUint aQueueSize); |
|
84 inline virtual TInt PassiveOpen(TUint aQueueSize,const TDesC8& aConnectionData); |
|
85 inline virtual void AutoBind(); |
|
86 inline virtual void LocalName(TSockAddr& anAddr) const; |
|
87 inline virtual TInt SetLocalName(TSockAddr& anAddr); |
|
88 inline virtual void RemName(TSockAddr& anAddr) const; |
|
89 inline virtual TInt SetRemName(TSockAddr& anAddr); |
|
90 virtual void Shutdown(MSessionControl::TCloseType option); |
|
91 inline virtual void Shutdown(MSessionControl::TCloseType option, const TDesC8& aDisconnectionData); |
|
92 inline virtual TInt SecurityCheck(MProvdSecurityChecker* aSecurityChecker); |
|
93 virtual TInt GetOption(TUint level, TUint name, TDes8 &anOption) const; |
|
94 virtual TInt SetOption(TUint level, TUint name, const TDesC8 &anOption); |
|
95 inline virtual void Ioctl(TUint level, TUint name, TDes8 *anOption); |
|
96 inline virtual void CancelIoctl(TUint aLevel, TUint aName); |
|
97 inline virtual void Start(); |
|
98 |
|
99 // MSessionData |
|
100 inline virtual TUint Write(const TDesC8& aDesc,TUint aOptions, TSockAddr* anAddr = NULL); |
|
101 virtual TInt Write(RMBufChain& aData, TUint aOptions, TSockAddr* anAddr = NULL ); |
|
102 inline virtual void GetData(TDes8& aDesc,TUint options,TSockAddr* anAddr=NULL); |
|
103 virtual TInt GetData(RMBufChain& aData, TUint aLength,TUint aOptions,TSockAddr* anAddr=NULL); |
|
104 |
|
105 // From MHttpEventObserver |
|
106 virtual TInt OnHttpEvent ( CTransaction* aTransaction, THTTPEvent& aEvent ); |
|
107 |
|
108 |
|
109 void StartFlow ( TNodeCtxId aSender ); |
|
110 void StopFlow ( TNodeCtxId aSender ); |
|
111 |
|
112 void HandleUPnPResponseL ( CServerTransaction* aTrans, TInt aStatus, SMetaDataNetCtorExt* aInfo ); |
|
113 // ---------------------------------- |
|
114 // The following should be moved to a separate utils class |
|
115 TInt GetHeaderValue ( const CRequest& aRequest, TInt aFieldIndex, THTTPHdrVal& aFieldVal, const TStringTable& aTable ) const; |
|
116 TBool MatchHeaderValue ( const CRequest& aRequest, TInt aField, const TDesC8& aFieldValue, const TStringTable& aTable ); |
|
117 |
|
118 TBool IsValidNTHeader ( const CRequest& aRequest ); |
|
119 TBool IsValidContentTypeHeader ( const CRequest& aRequest ); |
|
120 TBool IsValidNTSHeader ( const CRequest& aRequest ); |
|
121 inline TBool IsValidCharset ( const CRequest& aRequest ); |
|
122 TBool IsValidManHeader ( const CRequest& aRequest); |
|
123 |
|
124 TBool IsHeaderPresent ( const CRequest& aRequest, TInt aField, const TStringTable& aTable ); |
|
125 void SetHeaderL ( CResponse& aRequest, TInt aFieldIndex, RMemChunk& aVal, const TStringTable& aTable ); |
|
126 void SetHeaderL ( CResponse& aRequest, TInt aFieldIndex, TInt aVal, const TStringTable& aTable ); |
|
127 void IterateHeaders ( CRequest& aRequest ); |
|
128 // ------------------------------------ |
|
129 |
|
130 TInt ValidateUPnPRequest ( const CTransaction& aTrans ); |
|
131 TInt ValidateSubscribeRequest ( const CTransaction& aTrans ); |
|
132 TInt ValidateUnsubscribeRequest ( const CTransaction& aTrans ); |
|
133 TInt ValidateNotifyRequest ( const CTransaction& aTrans ); |
|
134 TInt ValidatePostRequest ( const CTransaction& aTrans ); |
|
135 TInt ValidateMPostRequest ( const CTransaction& aTrans ); |
|
136 |
|
137 TInt RouteTransaction ( CServerTransaction& aTrans, THTTPEvent& aEvent ); |
|
138 |
|
139 TInt FindOrCreateControlTransaction ( CServerTransaction& aTrans ); |
|
140 TInt FindControlTransaction ( TInt aId ) const; |
|
141 TInt FindControlTransaction ( CServerTransaction& aTrans ) const; |
|
142 void RemoveControlTransaction ( TInt aId ); |
|
143 TInt AddControlTransaction ( TInt aId, CServerTransaction& aTrans ); |
|
144 TControlTransaction FirstControlTransactionToNotify () const; |
|
145 |
|
146 |
|
147 private: |
|
148 CHttpServerFlow(CSubConnectionFlowFactoryBase& aFactory, CProtocolIntfBase* aProtocolIntf, const Messages::TNodeId& aSubConnId ); |
|
149 ~CHttpServerFlow(); |
|
150 |
|
151 void ConstructL ( const TDesC8& aUri ); |
|
152 |
|
153 private: |
|
154 MSessionControlNotify* iSessionControlNotify; |
|
155 MSessionDataNotify* iSessionDataNotify; |
|
156 RBuf8 iUri; |
|
157 RArray <TControlTransaction> iControlTransactions; |
|
158 TInt iControlId; |
|
159 }; |
|
160 |
|
161 const TDesC8& CHttpServerFlow::Uri() const |
|
162 { |
|
163 return iUri; |
|
164 } |
|
165 |
|
166 #include "httpserverflow.inl" |
|
167 #endif // HTTPCLIENTFLOW_H |