|
1 /* |
|
2 * Copyright (c) 2007 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: This file contains class CDataRetriever. It encapsulates |
|
15 * http connection to the bsf |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef DATARETRIEVER_H |
|
21 #define DATARETRIEVER_H |
|
22 |
|
23 #include <e32base.h> |
|
24 |
|
25 #include <stringpool.h> |
|
26 #include <http.h> |
|
27 #include <es_sock.h> |
|
28 #include <commdbconnpref.h> |
|
29 #include <cmmanagerext.h> |
|
30 #include <hash.h> |
|
31 #include "M3GPPAuthenticationCallback.h" |
|
32 |
|
33 |
|
34 // HTTPHeader data lenghts |
|
35 const TInt KMaxHeaderNameLen = 32; |
|
36 const TInt KMaxHeaderValueLen = 128; |
|
37 const TInt KMaxBootstrapRespLen = 1024; |
|
38 |
|
39 |
|
40 // forward declarations |
|
41 class MBootstrapCallBack; |
|
42 |
|
43 class MHttpRequestEvents |
|
44 { |
|
45 public: |
|
46 virtual void EventRequestCompletedL(TInt aErrorCode) = 0; |
|
47 }; |
|
48 |
|
49 |
|
50 /** |
|
51 * Handles all events for the active transaction. |
|
52 */ |
|
53 class C3GPPBootstrapHttpHandler : public CBase, public MHTTPTransactionCallback |
|
54 { |
|
55 public: |
|
56 |
|
57 static C3GPPBootstrapHttpHandler* NewLC( MHttpRequestEvents* aEventSink, |
|
58 M3GPPAuthenticationCallback* aDataRetrieverCallBack ); |
|
59 static C3GPPBootstrapHttpHandler* NewL( MHttpRequestEvents* aEventSink, |
|
60 M3GPPAuthenticationCallback* aDataRetrieverCallBack ); |
|
61 virtual ~C3GPPBootstrapHttpHandler(); |
|
62 //methods from MHTTPTransactionCallback |
|
63 virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
64 virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
65 HBufC8* GetResponse(); // intended to contain the TID! |
|
66 |
|
67 void Reset(); |
|
68 private: |
|
69 C3GPPBootstrapHttpHandler( MHttpRequestEvents* aEventSink, |
|
70 M3GPPAuthenticationCallback* aDataRetrieverCallBack ); |
|
71 void ConstructL(); |
|
72 // handles HTTP 401 Authorization required |
|
73 TInt HandleAuthorizationChallengeL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
74 // HTTP DIGEST authentication stuff |
|
75 TInt FindHeaderPartToUseL(RHTTPTransaction aTransaction) const; |
|
76 void EncodeDigestAuthL( const RString& aUsername, const RString& aPW, |
|
77 RHTTPTransaction& aTransaction, TInt headerPart, const THTTPHdrVal& aRequestUri); |
|
78 TBool FindAuth(const TDesC8& aQop) const; |
|
79 void GenerateCNonce(TDes8& aNonce); |
|
80 void Hash(const TDesC8& aMessage, TDes8& aHash); |
|
81 void HATwoL(const RStringF& aMethod, const RString& aRequestUri, const TDesC8& aHentity, TDes8& aResult); |
|
82 void HAOneL(const RString& aUsername,const RString& aPW, const RString& aRealm, TDes8& aResult); |
|
83 void DigestCalcL( const TDesC8& aHentity,TDes8& result ); |
|
84 TInt CheckRspAuthL( RHTTPTransaction aTransaction ); |
|
85 |
|
86 private: |
|
87 // The digest calculator |
|
88 CMD5* iMD5Calculator; |
|
89 // A seed for random numbers, used for client nonces. |
|
90 TInt64 iSeed; |
|
91 MHttpRequestEvents* iEventSink; |
|
92 MHTTPDataSupplier* iRespBody; |
|
93 HBufC8* iResponse; |
|
94 TBool iSucceeded; |
|
95 RString iUsername; |
|
96 RString iPassword; |
|
97 RString iNonce; |
|
98 RString iCnonce; |
|
99 RString iUri; |
|
100 RString iRealm; |
|
101 RStringF iMethod; |
|
102 M3GPPAuthenticationCallback* iDataRetrieverCallBack; |
|
103 }; |
|
104 |
|
105 |
|
106 |
|
107 class CDataRetriever : public CBase, public MHttpRequestEvents |
|
108 { |
|
109 public: |
|
110 static CDataRetriever* NewLC( MBootstrapCallBack* aBootstrapCallBack ); |
|
111 static CDataRetriever* NewL( MBootstrapCallBack* aBootstrapCallBack ); |
|
112 ~CDataRetriever(); |
|
113 void MakeRequestL( TRequestStatus* aRequestStatus, |
|
114 const TDesC8& aIdentity, |
|
115 const TDesC8& aRealm, |
|
116 const TDesC8& aBsfUri, |
|
117 const TDesC8& aReferrerNAFUri, |
|
118 const TInt& aIAPID ); |
|
119 |
|
120 void CancelRequest(); |
|
121 HBufC8 * QueryResponseValueL(); |
|
122 // event from httphandler when request has been completed, |
|
123 //aErrorCode is standard symbian error codes |
|
124 void EventRequestCompletedL(TInt aErrorCode); |
|
125 |
|
126 private: |
|
127 void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue); |
|
128 void SetupSessionL( const TInt& aIAPID ); |
|
129 TUint32 GetInternetDestIDL(); |
|
130 CDataRetriever( MBootstrapCallBack* aBootstrapCallBack ); |
|
131 void ConstructL(); |
|
132 TBool ValidateGivenIAPIDL( const TInt& aIAPID ); |
|
133 |
|
134 private: |
|
135 enum TInternalState |
|
136 { |
|
137 EReadyForRequest, // Ready and waiting for MakeRequest call |
|
138 EMakeRequestCalled, // Request function was called, now waiting for http request to complete |
|
139 }; |
|
140 |
|
141 private: |
|
142 TInternalState iInternalState; |
|
143 TRequestStatus* iCallerRequestStatus; // status of the caller |
|
144 RHTTPSession iHTTPSession; |
|
145 RHTTPTransaction iHTTPTransaction; |
|
146 RConnection iConnection; |
|
147 RSocketServ iSockServ; |
|
148 C3GPPBootstrapHttpHandler* iHttpHandler; // we own this |
|
149 MBootstrapCallBack* iBootstrapCallBack; // don't own this |
|
150 RCmManagerExt iCmManagerExt; |
|
151 }; |
|
152 |
|
153 |
|
154 |
|
155 #endif // DATARETRIEVER_H |
|
156 |
|
157 //EOF |