|
1 /* |
|
2 * Copyright (c) 2001-2009 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 the License "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 |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 @internalTechnology |
|
24 */ |
|
25 |
|
26 #include "explicit_http_session.h" |
|
27 |
|
28 #include <commdbconnpref.h> |
|
29 |
|
30 #include <cdblen.h> |
|
31 #include <metadatabase.h> |
|
32 #include <commsdattypesv1_1.h> |
|
33 using namespace CommsDat; |
|
34 |
|
35 |
|
36 _LIT(KSlashChar, "\\"); |
|
37 const TInt32 KMaxLenColonNumberStr = (1 + 10); // 1 Char for ':' and 10 Chars for TUint32 string |
|
38 |
|
39 EXPORT_C RExplicitHTTPSession::RExplicitHTTPSession() |
|
40 { |
|
41 } |
|
42 |
|
43 EXPORT_C void RExplicitHTTPSession::OpenL(const TUriC8& aUri, TUint32 aIapNumber, TBool aStartConnection) |
|
44 { |
|
45 BindConnectionL(aIapNumber, aStartConnection); |
|
46 |
|
47 /* |
|
48 Finally, get the proxy settings from the comms database. Note that if |
|
49 there is a problem with retrieving this info, we will use no proxy by |
|
50 default. |
|
51 The proxy which is retrieved is based on the scheme used by the URI |
|
52 to be opened. eg if the URI to be opened is https://myhost.com/... |
|
53 then the HTTPS proxy will be used |
|
54 */ |
|
55 |
|
56 HBufC8* proxy = NULL; |
|
57 |
|
58 TBool useProxy = EFalse; |
|
59 |
|
60 TRAPD(err, useProxy = UseProxyL(aUri.Extract(EUriScheme), proxy)); |
|
61 |
|
62 if (useProxy && !err) |
|
63 { |
|
64 RStringPool strPool = iHTTPSession.StringPool(); |
|
65 RHTTPConnectionInfo connInfo = iHTTPSession.ConnectionInfo(); |
|
66 |
|
67 CleanupStack::PushL(proxy); |
|
68 RStringF proxyAddr = strPool.OpenFStringL(*proxy); |
|
69 CleanupClosePushL(proxyAddr); |
|
70 |
|
71 THTTPHdrVal proxyUsage(strPool.StringF(HTTP::EUseProxy, |
|
72 RHTTPSession::GetTable())); |
|
73 |
|
74 connInfo.SetPropertyL(strPool.StringF(HTTP::EProxyUsage, |
|
75 RHTTPSession::GetTable()), proxyUsage); |
|
76 |
|
77 connInfo.SetPropertyL(strPool.StringF(HTTP::EProxyAddress, |
|
78 RHTTPSession::GetTable()), proxyAddr); |
|
79 |
|
80 CleanupStack::PopAndDestroy(2, proxy); // pop proxyAddr and proxy |
|
81 } |
|
82 } |
|
83 |
|
84 EXPORT_C void RExplicitHTTPSession::StartConnection(TRequestStatus& aStatus) |
|
85 { |
|
86 if (iIap) |
|
87 { |
|
88 TCommDbConnPref connectionPref; |
|
89 connectionPref.SetIapId(iIap); |
|
90 connectionPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
91 iConnection.Start(connectionPref, aStatus); |
|
92 } |
|
93 else |
|
94 { |
|
95 iConnection.Start(aStatus); |
|
96 } |
|
97 } |
|
98 |
|
99 EXPORT_C void RExplicitHTTPSession::CancelStart() |
|
100 { |
|
101 iConnection.Close(); |
|
102 iConnection.Open(iSocketServ); |
|
103 } |
|
104 |
|
105 EXPORT_C void RExplicitHTTPSession::Close() |
|
106 { |
|
107 iHTTPSession.Close(); |
|
108 iConnection.Close(); |
|
109 iSocketServ.Close(); |
|
110 } |
|
111 |
|
112 EXPORT_C RHTTPSession& RExplicitHTTPSession::HTTPSession() |
|
113 { |
|
114 return iHTTPSession; |
|
115 } |
|
116 |
|
117 void RExplicitHTTPSession::BindConnectionL(TUint32 aIap, TBool aStartConnection) |
|
118 { |
|
119 iIap = aIap; |
|
120 // Open the socket server to create the connection |
|
121 User::LeaveIfError(iSocketServ.Connect()); |
|
122 User::LeaveIfError(iConnection.Open(iSocketServ)); |
|
123 |
|
124 // we may wish to do an async connection start. |
|
125 if (aStartConnection) |
|
126 { |
|
127 // If the IAP number is non-zero, we have an explicit IAP to use |
|
128 if (iIap) |
|
129 { |
|
130 TCommDbConnPref connectionPref; |
|
131 connectionPref.SetIapId(iIap); |
|
132 connectionPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
133 User::LeaveIfError(iConnection.Start(connectionPref)); |
|
134 } |
|
135 else |
|
136 { |
|
137 User::LeaveIfError(iConnection.Start()); |
|
138 } |
|
139 } |
|
140 |
|
141 // Now open the real HTTP session and bind this session with the |
|
142 // socket server/connection |
|
143 iHTTPSession.OpenL(); |
|
144 RStringPool strPool = iHTTPSession.StringPool(); |
|
145 |
|
146 RHTTPConnectionInfo connInfo = iHTTPSession.ConnectionInfo(); |
|
147 |
|
148 connInfo.SetPropertyL(strPool.StringF(HTTP::EHttpSocketServ, |
|
149 RHTTPSession::GetTable()), THTTPHdrVal(iSocketServ.Handle())); |
|
150 |
|
151 connInfo.SetPropertyL(strPool.StringF(HTTP::EHttpSocketConnection, |
|
152 RHTTPSession::GetTable()), |
|
153 THTTPHdrVal(reinterpret_cast<TInt>(&iConnection))); |
|
154 } |
|
155 |
|
156 TBool RExplicitHTTPSession::UseProxyL(const TDesC8& aScheme, HBufC8*& aProxyServer) |
|
157 { |
|
158 TBool useProxy = EFalse; |
|
159 |
|
160 // Get the service id and service type from the connection |
|
161 TBuf<KCommsDbSvrMaxFieldLength> field; |
|
162 |
|
163 field = TPtrC(IAP); |
|
164 field.Append(KSlashChar); |
|
165 field.Append(TPtrC(IAP_SERVICE)); |
|
166 |
|
167 TUint32 serviceId; |
|
168 User::LeaveIfError(iConnection.GetIntSetting(field, serviceId)); |
|
169 |
|
170 field = TPtrC(IAP); |
|
171 field.Append(KSlashChar); |
|
172 field.Append(TPtrC(IAP_SERVICE_TYPE)); |
|
173 |
|
174 TBuf<KCommsDbSvrMaxFieldLength> serviceType; |
|
175 |
|
176 User::LeaveIfError(iConnection.GetDesSetting(field, serviceType)); |
|
177 |
|
178 // Now we've got the comms database, from the serviceId and serviceType, |
|
179 // get the proxy record |
|
180 |
|
181 // use commsDat API |
|
182 |
|
183 // Create CommmsDat seesion using latest version of commsdat |
|
184 CMDBSession* session = CMDBSession::NewLC(CMDBSession::LatestVersion()); |
|
185 //CMDBSession* session = CMDBSession::NewLC(KCommsDatVersion); |
|
186 |
|
187 // *************************************** |
|
188 // Create the CMDBRecordSet for the search |
|
189 // *************************************** |
|
190 CMDBRecordSet<CCDProxiesRecord>* pProxiesRecordSet = new (ELeave)CMDBRecordSet<CCDProxiesRecord>(KCDTIdProxiesRecord); |
|
191 CleanupStack::PushL(pProxiesRecordSet); |
|
192 |
|
193 CCDProxiesRecord* primingRecord = static_cast <CCDProxiesRecord*> (CCDRecordBase::RecordFactoryL(KCDTIdProxiesRecord)); |
|
194 CleanupStack::PushL(primingRecord); |
|
195 |
|
196 // ************************************ |
|
197 // build priming record for the search |
|
198 // ************************************ |
|
199 primingRecord->iServiceType.SetMaxLengthL(serviceType.Length()); |
|
200 primingRecord->iServiceType = serviceType; |
|
201 |
|
202 primingRecord->iService = serviceId; |
|
203 primingRecord->iUseProxyServer = ETrue; |
|
204 |
|
205 // Create 16-bit copy and set ProtocolName |
|
206 HBufC16* protocolName16 = HBufC16::NewLC(aScheme.Length()); |
|
207 TPtr16 ptr(protocolName16->Des()); |
|
208 ptr.Copy(aScheme); |
|
209 primingRecord->iProtocolName.SetMaxLengthL(ptr.Length()); |
|
210 primingRecord->iProtocolName = ptr; |
|
211 CleanupStack::PopAndDestroy(protocolName16); |
|
212 |
|
213 pProxiesRecordSet->iRecords.AppendL(primingRecord); |
|
214 CleanupStack::Pop(primingRecord); |
|
215 |
|
216 // ***************************** |
|
217 // Search for the priming record |
|
218 // ***************************** |
|
219 if (pProxiesRecordSet->FindL(*session)) |
|
220 { |
|
221 // Proxy is located so copy settings to aProxyServer |
|
222 TPtrC serverName(static_cast <CCDProxiesRecord*> (pProxiesRecordSet->iRecords[0])->iServerName); |
|
223 |
|
224 // Create the 8-bit version allowing extra characters for port number |
|
225 HBufC8* proxyServer = HBufC8::NewLC(serverName.Length() + KMaxLenColonNumberStr); |
|
226 |
|
227 TPtr8 ptr(proxyServer->Des()); |
|
228 ptr.Copy(serverName); |
|
229 |
|
230 ptr.Append(':'); |
|
231 ptr.AppendNum(static_cast <CCDProxiesRecord*> (pProxiesRecordSet->iRecords[0])->iPortNumber); |
|
232 useProxy = ETrue; |
|
233 CleanupStack::Pop(proxyServer); |
|
234 aProxyServer = proxyServer; |
|
235 } |
|
236 else |
|
237 { |
|
238 // do nothing |
|
239 // useProxy = FALSE |
|
240 } |
|
241 |
|
242 CleanupStack::PopAndDestroy(pProxiesRecordSet); |
|
243 CleanupStack::PopAndDestroy(session); |
|
244 |
|
245 return useProxy; |
|
246 } |