|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32test.h> |
|
19 #include <f32file.h> |
|
20 #include <httpclientserver/mhttpauthenticationcallback.h> |
|
21 #include <httpclientserver/mhttptransactioncallback.h> |
|
22 #include <httpclientserver/mhttpdatasupplier.h> |
|
23 #include <httpclientserver/framework/logging.h> |
|
24 #include <httpclientserver/mhttpsessioneventcallback.h> |
|
25 |
|
26 class CHttpExampleUtils; |
|
27 class CHttpServerTransactionBase; |
|
28 |
|
29 class MTransactionNotify |
|
30 { |
|
31 public: |
|
32 virtual void OnTransactionCompleted ( CHttpServerTransactionBase* iTrans ) =0; |
|
33 }; |
|
34 class CHttpServer : public CBase, |
|
35 public MHTTPTransactionCreationCallback, |
|
36 public MTransactionNotify, |
|
37 public MHTTPSessionEventCallback |
|
38 { |
|
39 public: |
|
40 virtual ~CHttpServer(); |
|
41 static CHttpServer* NewLC(); |
|
42 static CHttpServer* NewL(); |
|
43 //void StartClientL(); |
|
44 void SetupClientL (); |
|
45 //virtual void StartHttpServer(); |
|
46 |
|
47 void ProcessSelectionL ( TInt aSelection ); |
|
48 |
|
49 TInt GetLocalHost ( TSockAddr& aAddr ); |
|
50 |
|
51 TDesC8& GetIPAddress(); |
|
52 |
|
53 void StartConnectionL(TInt aIapId); |
|
54 |
|
55 protected: |
|
56 CHttpServer(); |
|
57 void ConstructL(); |
|
58 private: |
|
59 |
|
60 enum TMenuItems |
|
61 { |
|
62 EStart = 1, |
|
63 EStop, |
|
64 EExit, |
|
65 }; |
|
66 |
|
67 void ResetTimeElapsed(); |
|
68 void DisplayTimeElapsed(); |
|
69 // |
|
70 void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue); |
|
71 void SetDefaults(TDes& aURL, TDes& aProxy, TDes& aHook, TDes& aSessionId); |
|
72 |
|
73 // From MHTTPTransactionCreationCallback |
|
74 RHTTPTransaction NewTransactionL ( const TUriC8& aUri, RStringF aMethod ); |
|
75 |
|
76 void OnTransactionCompleted ( CHttpServerTransactionBase* iTrans ); |
|
77 |
|
78 // From MHTTPSessionEventCallback |
|
79 virtual void MHFSessionRunL ( const THTTPSessionEvent& aEvent ); |
|
80 virtual TInt MHFSessionRunError ( TInt aError, const THTTPSessionEvent& aEvent ); |
|
81 |
|
82 void CleanupTransactions (); |
|
83 |
|
84 private: |
|
85 TTime iLastTimeStamp; |
|
86 TInt iDataChunkCount; |
|
87 |
|
88 RHTTPClientServerSession iSess; |
|
89 |
|
90 RFs iFileServ; |
|
91 TBool iManualPost; |
|
92 //CHttpExampleUtils* iUtils; |
|
93 RArray <CHttpServerTransactionBase*> iTransactions; |
|
94 RFile iLogFile; |
|
95 |
|
96 RBuf8 iIPAddr; |
|
97 |
|
98 // Connection |
|
99 RConnection iConnection; |
|
100 |
|
101 // SocketServer |
|
102 RSocketServ iSocketServ; |
|
103 |
|
104 __FLOG_DECLARATION_MEMBER; |
|
105 }; |
|
106 |
|
107 class CHttpServerTransactionBase : public CBase, public MHTTPTransactionCallback |
|
108 { |
|
109 public: |
|
110 virtual ~CHttpServerTransactionBase (); |
|
111 RHTTPTransaction Transaction () |
|
112 { |
|
113 return iTransaction; |
|
114 } |
|
115 |
|
116 protected: |
|
117 CHttpServerTransactionBase ( MTransactionNotify& aNotify, /*CHttpExampleUtils& aUtils,*/ RFs& aFileServ ); |
|
118 |
|
119 void SetHeaderL(RStringPool& aStringPool, RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue); |
|
120 |
|
121 void ConstructL ( RHTTPClientServerSession& aSession, const TUriC8& aUri, RStringF aMethod ); |
|
122 protected: |
|
123 // |
|
124 // methods from MHTTPTransactionCallback |
|
125 // |
|
126 virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
127 virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
128 |
|
129 protected: |
|
130 MTransactionNotify& iNotify; |
|
131 RFs& iFileServ; |
|
132 //CHttpExampleUtils& iUtils; // not owned |
|
133 RFile iFile; |
|
134 RHTTPTransaction iTransaction; |
|
135 |
|
136 __FLOG_DECLARATION_MEMBER; |
|
137 }; |
|
138 |
|
139 class CHttpDataTransmitter : public CHttpServerTransactionBase, public MHTTPDataSupplier |
|
140 { |
|
141 public: |
|
142 static CHttpDataTransmitter* NewL ( MTransactionNotify& aNotify, /*CHttpExampleUtils& aUtils,*/ RFs& aFileServ, RHTTPClientServerSession& aSession, const TUriC8& aUri, RStringF aMethod ); |
|
143 |
|
144 TInt OpenFile( const TDesC8& aHttpPath ); |
|
145 private: |
|
146 // |
|
147 // methods from MHTTPTransactionCallback |
|
148 // |
|
149 virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
150 virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
151 |
|
152 // From MHTTPDataSupplier |
|
153 virtual TBool GetNextDataPart(TPtrC8& aDataPart); |
|
154 virtual void ReleaseData(); |
|
155 virtual TInt OverallDataSize(); |
|
156 virtual TInt Reset(); |
|
157 |
|
158 private: |
|
159 CHttpDataTransmitter (MTransactionNotify& aNotify,/*CHttpExampleUtils& aUtils,*/ RFs& aFileServ); |
|
160 |
|
161 private: |
|
162 TBuf8 <4096> iData; |
|
163 TInt iDataToSend; |
|
164 TBuf8<32> iContentType; |
|
165 TBool iTransSubmitted; |
|
166 |
|
167 __FLOG_DECLARATION_MEMBER; |
|
168 }; |
|
169 |