|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #include <s32mem.h> |
|
17 #include "ineturilistsession.h" |
|
18 #include "ineturilistserver.h" |
|
19 #include "ineturiimpl.h" |
|
20 #include "ineturiproperties.h" |
|
21 #include "urilistreadstream.h" |
|
22 #include <uri8.h> |
|
23 |
|
24 |
|
25 const TInt KNumConnectRetries = 5; |
|
26 |
|
27 _LIT( KServerCode, "INETURILISTSERVER" ); |
|
28 |
|
29 RInetUriListSession::RInetUriListSession () |
|
30 { |
|
31 |
|
32 } |
|
33 |
|
34 RInetUriListSession::~RInetUriListSession () |
|
35 { |
|
36 Close (); |
|
37 } |
|
38 |
|
39 /** |
|
40 Connects to the ineturilist server, attempting to start if necessary. |
|
41 */ |
|
42 TInt RInetUriListSession::Connect () |
|
43 { |
|
44 TInt retry = KNumConnectRetries; |
|
45 TVersion version ( KInetUriListServerMajorVersion, |
|
46 KInetUriListServerMinorVersion, |
|
47 KInetUriListServerBuildVersion ); |
|
48 FOREVER |
|
49 { |
|
50 TInt err = CreateSession ( KInetUriListServerName, version ); |
|
51 |
|
52 if ( err != KErrNotFound && err != KErrServerTerminated ) |
|
53 { |
|
54 return err; |
|
55 } |
|
56 // need to restart server |
|
57 if ( --retry == 0 ) |
|
58 { |
|
59 return err; |
|
60 } |
|
61 err = StartServer (); |
|
62 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
63 { |
|
64 return err; |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 void RInetUriListSession::Close () |
|
70 { |
|
71 if ( Handle() ) |
|
72 { |
|
73 RSessionBase::Close (); |
|
74 } |
|
75 } |
|
76 |
|
77 |
|
78 TInt RInetUriListSession::StartServer () |
|
79 { |
|
80 const TInt KIntServerType = 0x20009D70; |
|
81 const TUidType serverUid ( KNullUid, KNullUid, TUid::Uid( KIntServerType ) ); |
|
82 |
|
83 TRequestStatus started ( KRequestPending ); |
|
84 TRendezvous rendezvous; |
|
85 rendezvous.iId = RThread ().Id (); // id of this thread |
|
86 rendezvous.iStatus = &started; |
|
87 |
|
88 RProcess server; |
|
89 TInt err = server.Create( KServerCode, |
|
90 TPtrC ( reinterpret_cast < TText* > ( &rendezvous ), |
|
91 sizeof ( rendezvous ) / sizeof ( TText ) ), serverUid ); |
|
92 |
|
93 if ( err != KErrNone ) |
|
94 { |
|
95 return err; |
|
96 } |
|
97 |
|
98 server.SetPriority ( EPriorityHigh ); |
|
99 |
|
100 TRequestStatus stat; |
|
101 server.Rendezvous ( stat ); |
|
102 if ( stat != KRequestPending ) |
|
103 { |
|
104 server.Kill ( 0 ); // abort startup |
|
105 } |
|
106 else |
|
107 { |
|
108 server.Resume (); // logon OK - start the server |
|
109 } |
|
110 User::WaitForRequest ( stat ); // wait for start or death |
|
111 server.Close (); |
|
112 return stat.Int (); |
|
113 } |
|
114 |
|
115 /** |
|
116 Returns a buffer of size specified as argument. |
|
117 |
|
118 */ |
|
119 CBufFlat* RInetUriListSession::GetBufferLC ( TInt aSize ) |
|
120 { |
|
121 CBufFlat* buffer = CBufFlat::NewL ( aSize ); |
|
122 CleanupStack::PushL ( buffer ); |
|
123 buffer->ExpandL ( 0, aSize ); |
|
124 return buffer; |
|
125 } |
|
126 |
|
127 /** |
|
128 Sends the IPC data packet the server for adding into the storage. On return of |
|
129 the IPC call the URI Id & Property ID will be updated. |
|
130 |
|
131 @param aInetUri The URI object with its associated properties. The URI Id & property |
|
132 Id will be updated on this object on return of the IPC call. |
|
133 */ |
|
134 void RInetUriListSession::AddL ( CInetUriImpl& aInetUri ) |
|
135 { |
|
136 TInt uriSize = aInetUri.Size (); |
|
137 |
|
138 CBufFlat* inBuffer = GetBufferLC ( uriSize ); |
|
139 |
|
140 RBufWriteStream writeStream ( *inBuffer ); |
|
141 CleanupClosePushL ( writeStream ); |
|
142 |
|
143 // Pack the data |
|
144 aInetUri.PackL ( writeStream ); |
|
145 |
|
146 TPtr8 ptr ( inBuffer->Ptr (0) ); |
|
147 |
|
148 TInt uriId = 0; |
|
149 TInt propId = 0; |
|
150 |
|
151 TPckgBuf < TInt > uriIdBuffer ( uriId ); |
|
152 TPckgBuf < TInt > propIdBuffer ( propId ); |
|
153 |
|
154 TIpcArgs args ( &ptr, &uriIdBuffer, &propIdBuffer ); |
|
155 const TInt result = SendReceive ( CInetUriListServer::EAddUri, args ); |
|
156 |
|
157 User::LeaveIfError ( result ); |
|
158 |
|
159 aInetUri.SetUriId ( uriIdBuffer() ); |
|
160 aInetUri.Properties().SetPropId ( propIdBuffer() ); |
|
161 |
|
162 CleanupStack::PopAndDestroy ( 2 ); // writeStream, inBuffer |
|
163 } |
|
164 |
|
165 /** |
|
166 Sends the IPC data packet to the server for removing from the storage. |
|
167 |
|
168 @param aInetUri The URI object with its associated properties that need to be |
|
169 removed from the storage |
|
170 */ |
|
171 void RInetUriListSession::RemoveL ( const CInetUriImpl& aInetUri ) |
|
172 { |
|
173 // Only URI Id & Properties ID need to be sent to the server which will issue a |
|
174 // DELETE statement based on the Properties ID to the DB storage |
|
175 TPckg < TInt > uriIdBuffer ( aInetUri.UriId() ); |
|
176 TPckg < TInt > propIdBuffer ( aInetUri.Properties().PropId() ); |
|
177 TIpcArgs args ( &uriIdBuffer, &propIdBuffer ); |
|
178 |
|
179 const TInt result = SendReceive ( CInetUriListServer::ERemoveUri, args ); |
|
180 User::LeaveIfError ( result ); |
|
181 } |
|
182 /** |
|
183 Sends the IPC data packet to the server for updating the storage. Only favouritename |
|
184 and listtype will be updated. |
|
185 |
|
186 @param aInetUri The URI object whose favouritename & listype that need updation |
|
187 */ |
|
188 void RInetUriListSession::UpdateL ( const CInetUriImpl& aInetUri ) |
|
189 { |
|
190 // Only Favourite Name & List type can be updated. Sent the |
|
191 // IPC args with those values and the URI ID |
|
192 TPckg < TUint32 > propIdBuffer ( aInetUri.Properties().PropId() ); |
|
193 TPckg < InetUriList::TListType > listTypeBuffer ( aInetUri.Properties().ListType() ); |
|
194 |
|
195 TIpcArgs args ( &propIdBuffer, &listTypeBuffer, &( aInetUri.Properties().FavouriteName() ) ); |
|
196 |
|
197 const TInt result = SendReceive ( CInetUriListServer::EUpdateUri, args ); |
|
198 User::LeaveIfError ( result ); |
|
199 } |
|
200 |
|
201 /** |
|
202 Counts the number of URIs present in the list for a given servicetype & listtype. The data will |
|
203 be packaged and send to the server. The count value will be returned as a return value to |
|
204 the SendReceive fn |
|
205 */ |
|
206 TInt RInetUriListSession::Count ( InetUriList::TServiceType aServiceType, InetUriList::TListType aListType ) |
|
207 { |
|
208 TPckg < InetUriList::TServiceType > stBuffer ( aServiceType ); |
|
209 TPckg < InetUriList::TListType > ltBuffer ( aListType ); |
|
210 |
|
211 TIpcArgs args ( &stBuffer, <Buffer ); |
|
212 return SendReceive ( CInetUriListServer::EUriCount, args ); |
|
213 } |
|
214 |
|
215 /** |
|
216 Get the listtype for a URI, given a servicetype |
|
217 */ |
|
218 TInt RInetUriListSession::GetListTypeL ( const TDesC8& aUri, InetUriList::TServiceType aServiceType, InetUriList::TListType& aListType ) |
|
219 { |
|
220 // InetUriList::TListType lt; |
|
221 |
|
222 TPckg < InetUriList::TServiceType > stBuffer ( aServiceType ); |
|
223 TPckgBuf < InetUriList::TListType > ltBuffer;// ( lt ); |
|
224 |
|
225 TIpcArgs args ( &aUri, &stBuffer, <Buffer ); |
|
226 |
|
227 const TInt result = SendReceive ( CInetUriListServer::EListType, args ); |
|
228 if ( result != KErrNone ) |
|
229 { |
|
230 User::Leave ( result ); |
|
231 } |
|
232 |
|
233 aListType = ltBuffer(); |
|
234 |
|
235 return result; |
|
236 } |
|
237 |
|
238 /** |
|
239 Queries the URI in the list by providing query arguments. The server will setup a stream |
|
240 and the handle will be returned as a return value for SendReceive fn. Using that handle |
|
241 client can stream the query result. |
|
242 */ |
|
243 CUriListReadStream* RInetUriListSession::QueryUriL ( const TQueryArgs& aArgs ) |
|
244 { |
|
245 TPckg < TQueryArgs > queryArgs ( aArgs ); |
|
246 TIpcArgs args ( &queryArgs ); |
|
247 const TInt result = SendReceive ( CInetUriListServer::EQuery, args ); |
|
248 User::LeaveIfError ( result ); |
|
249 |
|
250 return CUriListReadStream::NewL( *this, result ); |
|
251 } |
|
252 |
|
253 /** |
|
254 Queries the URI in the list by providing query arguments. The server will return |
|
255 the policydata by writing it back into IpcArgs. And return value for SendReceive |
|
256 fn contains the length of the aCharset filled by server. |
|
257 aArgs contains Query args and aCharSet is an out parameter. |
|
258 */ |
|
259 TInt RInetUriListSession::QueryTldInfo ( const TPolicyQueryArgs& aArgs, TPtr8& aCharSet ) |
|
260 { |
|
261 const TDesC8& inputUri = *(reinterpret_cast<TDesC8*> ( aArgs.Get ( TPolicyQueryArgs::ETldUri ) )); |
|
262 TPckg < TPolicyQueryArgs > queryArgs ( aArgs ); |
|
263 TIpcArgs args ( &inputUri, &queryArgs, &aCharSet ); |
|
264 return SendReceive ( CInetUriListServer::EQueryTldInfo, args ); |
|
265 } |
|
266 |
|
267 /** |
|
268 Fetch the length of Policy data |
|
269 */ |
|
270 TInt RInetUriListSession::PolicyDataLength ( const TPolicyQueryArgs& aArgs ) |
|
271 { |
|
272 const TDesC8& inputUri = *(reinterpret_cast<TDesC8*> ( aArgs.Get ( TPolicyQueryArgs::ETldUri ) )); |
|
273 TPckg < TPolicyQueryArgs > queryArgs ( aArgs ); |
|
274 TIpcArgs args (&inputUri, &queryArgs ); |
|
275 return SendReceive ( CInetUriListServer::EPolicyLength, args ); |
|
276 } |
|
277 |
|
278 /** |
|
279 Identifies whether the given Uri is BlackListed or Whitelisted |
|
280 */ |
|
281 TInt RInetUriListSession::GetHostType ( const TPolicyQueryArgs& aArgs ) |
|
282 { |
|
283 const TDesC8& inputUri = *(reinterpret_cast<TDesC8*> ( aArgs.Get ( TPolicyQueryArgs::ETldUri ) )); |
|
284 TIpcArgs args (&inputUri); |
|
285 TInt err = SendReceive ( CInetUriListServer::ETldListType, args ); |
|
286 return err; |
|
287 } |
|
288 |
|
289 /** |
|
290 Queries the URI in the list by providing query arguments and a URI. The server will setup |
|
291 a stream and the handle will be returned as a return value for SendReceive fn. Using that |
|
292 handle, client can stream the query result. |
|
293 */ |
|
294 CUriListReadStream* RInetUriListSession::QueryUriL ( const TDesC8& aUri, const TQueryArgs& aArgs ) |
|
295 { |
|
296 TPckg < TQueryArgs > queryArgs ( aArgs ); |
|
297 TIpcArgs args ( &aUri, &queryArgs ); |
|
298 const TInt result = SendReceive ( CInetUriListServer::EQueryWithUri, args ); |
|
299 User::LeaveIfError ( result ); |
|
300 |
|
301 return CUriListReadStream::NewL( *this, result ); |
|
302 } |
|
303 |
|
304 /** |
|
305 The query results stream has been setup in the server and the server stream handle is |
|
306 returned via QueryUriL call. Read the query results using that handle. |
|
307 */ |
|
308 TInt RInetUriListSession::ReadQueryResults ( TInt aHandle, TPtr8& aPtr ) |
|
309 { |
|
310 TIpcArgs args ( aHandle, &aPtr ); |
|
311 |
|
312 return SendReceive ( CInetUriListServer::EReadQueryResults, args ); |
|
313 } |
|
314 |
|
315 /** |
|
316 Close the server stream handle. |
|
317 */ |
|
318 void RInetUriListSession::CloseSrvStream ( TInt aHandle ) |
|
319 { |
|
320 TIpcArgs args ( aHandle ); |
|
321 |
|
322 SendReceive ( CInetUriListServer::ECloseSrvStream, args ); |
|
323 } |