|
1 // Copyright (c) 2007-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 // ineturilist.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 #include "ineturilistimpl.h" |
|
20 #include "ineturiimpl.h" |
|
21 #include <uriutils.h> |
|
22 |
|
23 CInetUriListImpl::CInetUriListImpl () |
|
24 { |
|
25 } |
|
26 |
|
27 CInetUriListImpl::~CInetUriListImpl () |
|
28 { |
|
29 iInetUriListSession.Close (); |
|
30 } |
|
31 /** |
|
32 Standard factory construction method |
|
33 |
|
34 */ |
|
35 CInetUriListImpl* CInetUriListImpl::NewL () |
|
36 { |
|
37 CInetUriListImpl* self = new ( ELeave ) CInetUriListImpl (); |
|
38 CleanupStack::PushL ( self ); |
|
39 self->ConstructL (); |
|
40 CleanupStack::Pop ( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 void CInetUriListImpl::ConstructL () |
|
45 { |
|
46 User::LeaveIfError ( iInetUriListSession.Connect () ); |
|
47 } |
|
48 /** |
|
49 Add a new URI to the storage. The session with the server must have been already opened. |
|
50 |
|
51 @param aInetUri A fully constructed URI object |
|
52 |
|
53 */ |
|
54 void CInetUriListImpl::AddL ( const RInetUri& aInetUri ) |
|
55 { |
|
56 // Add to the database |
|
57 iInetUriListSession.AddL ( aInetUri.Impl() ); |
|
58 } |
|
59 |
|
60 /** |
|
61 Removes the URI from the storage. Function will leave if the URI object is read-only |
|
62 |
|
63 @leave KErrUriReadOnly The URI object is read-only and cannot be removed |
|
64 */ |
|
65 void CInetUriListImpl::RemoveL ( const RInetUri& aInetUri ) |
|
66 { |
|
67 // Only URIs with read-write permission can be removed |
|
68 aInetUri.Impl().LeaveIfReadOnlyL (); |
|
69 |
|
70 // Remove from the list and database |
|
71 iInetUriListSession.RemoveL ( aInetUri.Impl() ); |
|
72 } |
|
73 |
|
74 /** |
|
75 Updates the URI in the storage. Only favouritename & listtype will be updated |
|
76 |
|
77 @param aInetUri URI object |
|
78 @leave KErrUriReadOnly The URI object is read-only and cannot be modified |
|
79 */ |
|
80 void CInetUriListImpl::UpdateL ( const RInetUri& aInetUri ) |
|
81 { |
|
82 // Only URIs with read-write permission can be updated |
|
83 aInetUri.Impl().LeaveIfReadOnlyL (); |
|
84 |
|
85 // Update the list and database |
|
86 iInetUriListSession.UpdateL ( aInetUri.Impl() ); |
|
87 } |
|
88 |
|
89 /** |
|
90 Counts the number of URIs in the list, given ServiceType and a ListType |
|
91 */ |
|
92 TInt CInetUriListImpl::Count ( InetUriList::TServiceType aServiceType, InetUriList::TListType aListType ) |
|
93 { |
|
94 return iInetUriListSession.Count ( aServiceType, aListType ); |
|
95 } |
|
96 |
|
97 /** |
|
98 Retrieves the Listtype of a give URI, given ServiceType. |
|
99 |
|
100 @return KErrUriNotFound The URI is not found in the list |
|
101 KErrNone The URI is found in the list and the aListType value is set. |
|
102 */ |
|
103 TInt CInetUriListImpl::GetListType ( const TDesC8& aUri, InetUriList::TServiceType aServiceType, InetUriList::TListType& aListType ) |
|
104 { |
|
105 TInt ret = KErrNone; |
|
106 TRAPD ( err, ret = iInetUriListSession.GetListTypeL ( DoNormalisationLC ( aUri, NULL ), aServiceType, aListType ); CleanupStack::PopAndDestroy (); ); |
|
107 if ( err != KErrNone ) |
|
108 ret = err; |
|
109 return ret; |
|
110 } |
|
111 |
|
112 /** |
|
113 Queries the URI in the list, given ServiceType & URI as argument. An exact URI match |
|
114 will be performed. |
|
115 |
|
116 @param aUri URI descriptor |
|
117 @param aServiceType Servicetype which the URI represents |
|
118 |
|
119 @return A RInetUri object. Application can use this object for further operations |
|
120 @leave KErrUriNotFound The URI is not found in the list for the given servicetype |
|
121 */ |
|
122 RInetUri CInetUriListImpl::QueryUriL ( const TDesC8& aUri, InetUriList::TServiceType aServiceType ) |
|
123 { |
|
124 TQueryArgs args ( aServiceType, InetUriList::EExact ); |
|
125 CUriListReadStream* uriListStream = iInetUriListSession.QueryUriL ( DoNormalisationLC ( aUri, NULL ), args ); |
|
126 CleanupStack::PushL ( uriListStream ); |
|
127 |
|
128 TInt totalRecords = uriListStream->ReadUriListL (); |
|
129 |
|
130 if ( totalRecords <= 0 ) |
|
131 { |
|
132 User::Leave ( InetUriList::KErrUriNotFound ); |
|
133 } |
|
134 |
|
135 RInetUri inetUri = UnpackL ( uriListStream->BufReadStream() ); |
|
136 CleanupStack::PopAndDestroy (2); // uriListStream, object added in DoSyntaxNormalisationLC |
|
137 return inetUri; |
|
138 } |
|
139 |
|
140 /** |
|
141 Queries for the URI in the list. |
|
142 |
|
143 @param aArgs Query argument. The ServiceType is mandatory and need to be set with the argument. |
|
144 Other query parameters are optional |
|
145 @param aQueryCallback The callback function that will be called to return the query results |
|
146 @param aUriCustomiser The callback function that need to implement the customisation of the URI if the application wishes |
|
147 |
|
148 @leave KErrServiceTypeNotPresent The servicetype value is not present in the query argument and is mandatory |
|
149 |
|
150 */ |
|
151 void CInetUriListImpl::QueryUriL ( const TQueryArgs& aArgs, MQueryResultsCallback& aQueryCallback, MUriCustomiser* aUriCustomiser ) |
|
152 { |
|
153 // Check service type is present in the args. Without service type no query operation |
|
154 // will be performed |
|
155 if ( aArgs.Get ( TQueryArgs::EServiceType ) == KErrNotFound ) |
|
156 { |
|
157 User::Leave ( InetUriList::KErrServiceTypeNotPresent ); |
|
158 } |
|
159 |
|
160 CUriListReadStream* uriListStream = NULL; |
|
161 |
|
162 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
163 if ( aArgs.Get ( TQueryArgs::EUri ) != KErrNotFound ) |
|
164 { |
|
165 const TDesC8& uri = *(reinterpret_cast<TDesC8*> ( aArgs.Get ( TQueryArgs::EUri ) )); |
|
166 // Do normalisation |
|
167 TPtrC8 customisedUri ( DoNormalisationLC ( uri, aUriCustomiser ) ); |
|
168 uriListStream = iInetUriListSession.QueryUriL ( customisedUri, aArgs ); |
|
169 CleanupStack::PopAndDestroy (); // objects added in DoNormalisationLC |
|
170 } |
|
171 else |
|
172 { |
|
173 uriListStream = iInetUriListSession.QueryUriL ( aArgs ); |
|
174 } |
|
175 #else |
|
176 if ( aArgs.IsSet ( TQueryArgs::EUri ) ) |
|
177 { |
|
178 const TDesC8& uri = *(reinterpret_cast<TDesC8*> ( aArgs.Get ( TQueryArgs::EUri ) )); |
|
179 // Do normalisation |
|
180 TPtrC8 customisedUri ( DoNormalisationLC ( uri, aUriCustomiser ) ); |
|
181 uriListStream = iInetUriListSession.QueryUriL ( customisedUri, aArgs ); |
|
182 CleanupStack::PopAndDestroy (); // objects added in DoNormalisationLC |
|
183 } |
|
184 else |
|
185 { |
|
186 uriListStream = iInetUriListSession.QueryUriL ( aArgs ); |
|
187 } |
|
188 |
|
189 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
190 |
|
191 CleanupStack::PushL ( uriListStream ); |
|
192 |
|
193 RetrieveResultsL ( *uriListStream, aQueryCallback ); |
|
194 |
|
195 CleanupStack::PopAndDestroy (); // uriListStream |
|
196 |
|
197 } |
|
198 |
|
199 /** |
|
200 Retrieves the query results from the server. The stream will be closed once the client has received |
|
201 all the records or upon request by the application via the reqturn value of query results callback function |
|
202 */ |
|
203 void CInetUriListImpl::RetrieveResultsL ( CUriListReadStream& aListStream, MQueryResultsCallback& aQueryCallback ) |
|
204 { |
|
205 TBool bContinue = ETrue; |
|
206 do |
|
207 { |
|
208 TInt totalRecords = aListStream.ReadUriListL (); |
|
209 if ( totalRecords <= 0 ) |
|
210 { |
|
211 bContinue = EFalse; |
|
212 } |
|
213 |
|
214 |
|
215 for ( TInt i = 1; i <= totalRecords; ++i ) |
|
216 { |
|
217 // Unpack and do callback |
|
218 RInetUri inetUri = UnpackL ( aListStream.BufReadStream() ); |
|
219 if ( !aQueryCallback.OnQueryResultsL ( inetUri ) ) |
|
220 { |
|
221 // Client has asked to stop the retrieval of query resuls |
|
222 // break the operation. |
|
223 bContinue = EFalse; |
|
224 break; |
|
225 } |
|
226 } |
|
227 } while ( bContinue ); |
|
228 } |
|
229 |
|
230 /** |
|
231 Unpacks the data stream and constructs a full URI object |
|
232 */ |
|
233 RInetUri CInetUriListImpl::UnpackL ( RReadStream& aStream ) |
|
234 { |
|
235 CInetUriImpl* inetUri = CInetUriImpl::NewL (); |
|
236 CleanupStack::PushL ( inetUri ) ; |
|
237 inetUri->UnpackL ( aStream ); |
|
238 RInetUri inetUriObj; |
|
239 inetUriObj.Attach ( *inetUri ); |
|
240 CleanupStack::Pop (); //inetUri |
|
241 return inetUriObj; |
|
242 } |
|
243 |
|
244 |
|
245 /** |
|
246 Does the syntax based normalisation. If the MUriCustomiser is set then it customises the URI, |
|
247 that is, do the protocol/scheme-based normalisation on the URI. The customisation algorithm needs |
|
248 to be implemented by the application. |
|
249 */ |
|
250 const TDesC8& CInetUriListImpl::DoNormalisationLC ( const TDesC8& aUri, MUriCustomiser* aUriCustomiser ) |
|
251 { |
|
252 // Do a syntax based normalisation |
|
253 TUriParser8 uriParser; |
|
254 User::LeaveIfError ( uriParser.Parse ( aUri ) ); |
|
255 CUri8* normalisedUri = UriUtils::NormaliseUriL ( uriParser ); |
|
256 CleanupStack::PushL ( normalisedUri ); |
|
257 if ( aUriCustomiser ) |
|
258 { |
|
259 normalisedUri = aUriCustomiser->OnUriCustomisationL ( normalisedUri->Uri() ); |
|
260 CleanupStack::PopAndDestroy (); // Added after UriUtils::NormaliseUriL |
|
261 CleanupStack::PushL ( normalisedUri ); |
|
262 } |
|
263 return normalisedUri->Uri().UriDes(); |
|
264 } |
|
265 |
|
266 /** |
|
267 Queries on Uri either to fetch the TLD Policy data or get the List type of the given Uri. |
|
268 |
|
269 @param aArgs TPolicyQueryArgs argument. The Uri and Querytype are mandatory. |
|
270 To fetch Charset, List type is Mandatory, whereas to fetch List type it is not. |
|
271 @param aResultArgs is out parmeter contains either List type info or Charset info. Based on the QueryType. |
|
272 |
|
273 @leave KErrInvalidTLD The TLD type if No policy data is available for the given TLD and Requested ListType. |
|
274 */ |
|
275 void CInetUriListImpl::QueryTldInfoL ( const TPolicyQueryArgs& aArgs, TQueryResults& aResultArgs ) |
|
276 { |
|
277 // Check Uri type is present in the args. |
|
278 if ( aArgs.Get ( TPolicyQueryArgs::ETldUri ) == KErrNotFound ) |
|
279 { |
|
280 User::Leave ( InetUriList::KErrTldUriNotPresent ); |
|
281 } |
|
282 // Query type is present in the args. |
|
283 // Without these no query operation will be performed |
|
284 if ( aArgs.Get ( TPolicyQueryArgs::ETldQueryType ) == KErrNotFound ) |
|
285 { |
|
286 User::Leave ( InetUriList::KErrTldQueryTypeNotPresent ); |
|
287 } |
|
288 |
|
289 InetUriList::TTLDQueryType queryType (InetUriList::EPolicyListType); |
|
290 queryType = static_cast < InetUriList::TTLDQueryType > ( aArgs.Get ( TPolicyQueryArgs::ETldQueryType ) ); |
|
291 |
|
292 // Identify the Host type whether it is WhiteListed or BlackListed |
|
293 if ( queryType == InetUriList::EPolicyListType ) |
|
294 { |
|
295 InetUriList::TListType lt(InetUriList::EBlackList); |
|
296 TInt result = iInetUriListSession.GetHostType(aArgs); |
|
297 User::LeaveIfError( result ); |
|
298 lt = static_cast < InetUriList::TListType > ( result ); |
|
299 aResultArgs.Set(lt); |
|
300 } |
|
301 //fetch Policy data and send the results in TQueryResults |
|
302 else |
|
303 { |
|
304 HBufC8* results(NULL); |
|
305 results = FetchPolicyDataL ( aArgs ); |
|
306 //owner ship of results with TQueryResults |
|
307 aResultArgs.Set(results); |
|
308 } |
|
309 } |
|
310 |
|
311 /** |
|
312 Fetch Policy data |
|
313 */ |
|
314 HBufC8* CInetUriListImpl::FetchPolicyDataL(const TPolicyQueryArgs& aArgs ) |
|
315 { |
|
316 TInt policyLength = iInetUriListSession.PolicyDataLength( aArgs ); |
|
317 //Policy file contains empty body for Requested white/Black listed data |
|
318 User::LeaveIfError ( policyLength ); |
|
319 HBufC8* policydata = HBufC8::NewL( policyLength ); |
|
320 CleanupStack::PushL( policydata ); |
|
321 TPtr8 ptr ( policydata->Des() ) ; |
|
322 TInt err = iInetUriListSession.QueryTldInfo( aArgs, ptr ); |
|
323 CleanupStack::Pop( policydata ); |
|
324 User::LeaveIfError( err ); |
|
325 return policydata; |
|
326 } |
|
327 |