1 /* |
1 /* |
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
28 |
28 |
29 #include <http/mhttpauthenticationcallback.h> |
29 #include <http/mhttpauthenticationcallback.h> |
30 #include <http/mhttptransactioncallback.h> |
30 #include <http/mhttptransactioncallback.h> |
31 #include <http/mhttpdatasupplier.h> |
31 #include <http/mhttpdatasupplier.h> |
32 |
32 |
33 #include <commdbconnpref.h> // TCommDbConnPref (since 7.0s) |
33 #include <extendedconnpref.h> // TExtendedConnPref, TConnPrefList, TConnectionInfo |
34 |
34 |
35 #include "wmdrmdladefaulthttpmanagerobserver.h" |
35 #include "wmdrmdladefaulthttpmanagerobserver.h" |
36 |
36 |
37 /** |
37 /** |
38 * CWmDrmDlaDefaultHttpManager |
38 * CWmDrmDlaDefaultHttpManager |
48 * THeader - encapsulates an HTTP header id and its value. |
48 * THeader - encapsulates an HTTP header id and its value. |
49 */ |
49 */ |
50 struct THeader |
50 struct THeader |
51 { |
51 { |
52 public: |
52 public: |
53 inline THeader( TInt aField, const TDesC8& aDesC ) : |
53 inline THeader( TInt aField, const TDesC8& aDesC ) : |
54 iField(aField), iVal(aDesC) {}; |
54 iField(aField), iVal(aDesC) {}; |
55 public: |
55 public: |
56 TInt iField; // e.g. 'HTTP::EAccept' |
56 TInt iField; // e.g. 'HTTP::EAccept' |
57 const TDesC8& iVal; // value: e.g. '*/*' |
57 const TDesC8& iVal; // value: e.g. '*/*' |
58 }; |
58 }; |
61 /** |
61 /** |
62 * Constructor. |
62 * Constructor. |
63 * @param aObserver - reference to observer |
63 * @param aObserver - reference to observer |
64 * @return address of an instance of this class |
64 * @return address of an instance of this class |
65 */ |
65 */ |
66 static CWmDrmDlaDefaultHttpManager* NewL( |
66 static CWmDrmDlaDefaultHttpManager* NewL( |
67 MWmDrmDlaDefaltHttpManagerObserver& aObserver ); |
67 MWmDrmDlaDefaltHttpManagerObserver& aObserver ); |
68 |
68 |
69 /** |
69 /** |
70 * Constructor. |
70 * Constructor. |
71 * @param aObserver - reference to observer |
71 * @param aObserver - reference to observer |
72 * @param aIapNumber - Internet Access Point to be used |
72 * @param aIapNumber - Internet Access Point to be used |
73 * @return address of an instance of this class |
73 * @return address of an instance of this class |
74 */ |
74 */ |
75 static CWmDrmDlaDefaultHttpManager* NewL( |
75 static CWmDrmDlaDefaultHttpManager* NewL( |
76 MWmDrmDlaDefaltHttpManagerObserver& aObserver, |
76 MWmDrmDlaDefaltHttpManagerObserver& aObserver, |
77 TUint32 aIapNumber ); |
77 TUint32 aIapNumber ); |
78 |
78 |
79 /** |
79 /** |
80 * Destructor. |
80 * Destructor. |
82 virtual ~CWmDrmDlaDefaultHttpManager(); |
82 virtual ~CWmDrmDlaDefaultHttpManager(); |
83 |
83 |
84 /** |
84 /** |
85 * Called to start the GET transaction using the configured IAP. |
85 * Called to start the GET transaction using the configured IAP. |
86 * @param aUrl - URL to be used for the transaction |
86 * @param aUrl - URL to be used for the transaction |
87 * @param aHeaders - a list of headers and their values to be |
87 * @param aHeaders - a list of headers and their values to be |
88 * included with the HTTP request |
88 * included with the HTTP request |
89 */ |
89 */ |
90 void Get( const TDesC8& aUrl, const RArray<THeader>& aHeaders ); |
90 void Get( const TDesC8& aUrl, const RArray<THeader>& aHeaders ); |
91 |
91 |
92 /** |
92 /** |
93 * Called to start the POST transaction using the configured IAP. |
93 * Called to start the POST transaction using the configured IAP. |
94 * @param aUrl - URL to be used for the transaction |
94 * @param aUrl - URL to be used for the transaction |
95 * @param aHeaders - a list of headers and their values to be |
95 * @param aHeaders - a list of headers and their values to be |
96 * included with the HTTP request |
96 * included with the HTTP request |
97 * @param aDataSupplier - interface to be used to get the POST data |
97 * @param aDataSupplier - interface to be used to get the POST data |
98 */ |
98 */ |
99 void Post( const TDesC8& aUrl, const RArray<THeader>& aHeaders, |
99 void Post( const TDesC8& aUrl, const RArray<THeader>& aHeaders, |
100 MHTTPDataSupplier* aDataSupplier ); |
100 MHTTPDataSupplier* aDataSupplier ); |
101 |
101 |
102 /** |
102 /** |
103 * To be called to stop an ongoing transaction instead of Cancel. |
103 * To be called to stop an ongoing transaction instead of Cancel. |
104 * Cancel SHOULD NOT BE CALLED by clients. |
104 * Cancel SHOULD NOT BE CALLED by clients. |
137 /** |
137 /** |
138 * Set the IAP connection for the next Get or Post |
138 * Set the IAP connection for the next Get or Post |
139 * @param aIapId The IAP connection that will be used |
139 * @param aIapId The IAP connection that will be used |
140 */ |
140 */ |
141 void SetIapId( TInt aIapId ); |
141 void SetIapId( TInt aIapId ); |
142 |
142 |
143 /** |
143 /** |
144 * Get the IAP Connection ID |
144 * Get the IAP Connection ID |
145 */ |
145 */ |
146 TInt IapId(); |
146 TInt IapId(); |
147 |
147 |
148 private: // From MHTTPTransactionCallback |
148 private: // From MHTTPTransactionCallback |
149 |
149 |
150 virtual void MHFRunL( RHTTPTransaction aTransaction, |
150 virtual void MHFRunL( RHTTPTransaction aTransaction, |
151 const THTTPEvent& aEvent ); |
151 const THTTPEvent& aEvent ); |
152 virtual TInt MHFRunError( TInt aError, RHTTPTransaction aTransaction, |
152 virtual TInt MHFRunError( TInt aError, RHTTPTransaction aTransaction, |
153 const THTTPEvent& aEvent ); |
153 const THTTPEvent& aEvent ); |
154 |
154 |
155 private: // From MHTTPAuthenticationCallback |
155 private: // From MHTTPAuthenticationCallback |
156 |
156 |
157 virtual TBool GetCredentialsL( const TUriC8& aURI, RString aRealm, |
157 virtual TBool GetCredentialsL( const TUriC8& aURI, RString aRealm, |
158 RStringF aAuthenticationType, |
158 RStringF aAuthenticationType, |
159 RString& aUsername, |
159 RString& aUsername, |
160 RString& aPassword ); |
160 RString& aPassword ); |
161 |
161 |
162 private: // From CActive |
162 private: // From CActive |
163 |
163 |
164 void DoCancel(); |
164 void DoCancel(); |
165 void RunL(); |
165 void RunL(); |
166 TInt RunError(TInt aError); |
166 TInt RunError(TInt aError); |
167 |
167 |
168 private: |
168 private: |
169 |
169 |
170 /** |
170 /** |
171 * Contructor |
171 * Contructor |
172 * @param aObserver An observer to monitor the HTTP communications |
172 * @param aObserver An observer to monitor the HTTP communications |
173 * @param aIap An IAP connection to use for HTTP communication |
173 * @param aIap An IAP connection to use for HTTP communication |
174 */ |
174 */ |
175 CWmDrmDlaDefaultHttpManager( |
175 CWmDrmDlaDefaultHttpManager( |
176 MWmDrmDlaDefaltHttpManagerObserver& aObserver, |
176 MWmDrmDlaDefaltHttpManagerObserver& aObserver, |
177 TUint32 aIapNumber ); |
177 TUint32 aIapNumber ); |
178 |
178 |
179 /** |
179 /** |
180 * Symbian OS 2nd phase constructor. |
180 * Symbian OS 2nd phase constructor. |
181 */ |
181 */ |
182 void ConstructL(); |
182 void ConstructL(); |
183 |
183 |
184 private: |
184 private: |
185 |
185 |
186 // State transition handlers |
186 // State transition handlers |
187 /** |
187 /** |
188 * Handler for the EStart state. |
188 * Handler for the EStart state. |
189 */ |
189 */ |
190 void InitializeL(); |
190 void InitializeL(); |
191 /** |
191 /** |
192 * Handler for the EInitialize state. |
192 * Handler for the EInitialize state. |
193 */ |
193 */ |
194 void Open(); |
194 void OpenL(); |
195 /** |
195 /** |
196 * Handler for the EOpen state. |
196 * Handler for the EOpenFailed state. |
|
197 */ |
|
198 void ReconnectL(); |
|
199 /** |
|
200 * Handler for the states EOpen and EReconnect. |
197 */ |
201 */ |
198 void SubmitL(); |
202 void SubmitL(); |
199 |
203 |
200 // Utility methods |
204 // Utility methods |
201 void DoStartL( const TDesC8& aUrl, const RArray<THeader>& aHeaders ); |
205 void DoStartL( const TDesC8& aUrl, const RArray<THeader>& aHeaders ); |
216 */ |
220 */ |
217 void CompleteSelf(); |
221 void CompleteSelf(); |
218 /** |
222 /** |
219 * Set the HTTP header to send |
223 * Set the HTTP header to send |
220 */ |
224 */ |
221 void SetHeaderL( RHTTPHeaders& aHeaders, TInt aHdrField, |
225 void SetHeaderL( RHTTPHeaders& aHeaders, TInt aHdrField, |
222 const TDesC8& aHdrValue ) const; |
226 const TDesC8& aHdrValue ) const; |
223 /** |
227 /** |
224 * Delete the username and password used in authentication |
228 * Delete the username and password used in authentication |
225 */ |
229 */ |
226 void DeleteUsernamePassword(); |
230 void DeleteUsernamePassword(); |
227 |
231 |
228 private: // Private types |
232 private: // Private types |
229 |
233 |
230 // Asynchronous connection states |
234 // Asynchronous connection states |
231 enum TState |
235 enum TState |
232 { |
236 { |
233 EConstructed, |
237 EConstructed, |
234 EStart, |
238 EStart, |
235 EInitialize, |
239 EInitialize, |
236 EOpen, |
240 EOpen, |
|
241 EOpenFailed, |
|
242 EReconnect, |
237 ESubmit |
243 ESubmit |
238 }; |
244 }; |
239 |
245 |
240 // HTTP operation: GET or POST |
246 // HTTP operation: GET or POST |
241 enum TOperation |
247 enum TOperation |
243 EGet, |
249 EGet, |
244 EPost |
250 EPost |
245 }; |
251 }; |
246 |
252 |
247 private: // Data |
253 private: // Data |
248 |
254 |
249 MWmDrmDlaDefaltHttpManagerObserver& iObserver; |
255 MWmDrmDlaDefaltHttpManagerObserver& iObserver; |
250 |
256 |
251 TState iState; // State of the asynch connection |
257 TState iState; // State of the asynch connection |
252 TInt iError; |
258 TInt iError; |
253 TBool iCredentialsOk; |
259 TBool iCredentialsOk; |
254 |
260 |
255 RSocketServ iSocketServer; |
261 RSocketServ iSocketServer; |
256 RConnection iConnection; |
262 RConnection iConnection; |
257 TCommDbConnPref iCommDbPrefs; |
263 |
|
264 TConnPrefList iPrefList; |
|
265 TExtendedConnPref iExtPrefs; |
258 |
266 |
259 TUint32 iIapNumber; |
267 TUint32 iIapNumber; |
260 |
268 |
261 RHTTPSession iHttpSession; |
269 RHTTPSession iHttpSession; |
262 RHTTPTransaction iHttpTransaction; |
270 RHTTPTransaction iHttpTransaction; |