|
1 // Copyright (c) 2004-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 // Name : CProxyResolveActor.cpp |
|
15 // Part of : ProxyResolver |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "CProxyResolveActor.h" |
|
22 #include "CProxyResolvingQueue.h" |
|
23 #include "CProxyQuery.h" |
|
24 #include <nifman.h> |
|
25 |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CProxyResolveActor::NewL |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CProxyResolveActor* CProxyResolveActor::NewL() |
|
32 { |
|
33 CProxyResolveActor* self = CProxyResolveActor::NewLC(); |
|
34 CleanupStack::Pop( self ); |
|
35 return self; |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CProxyResolveActor::NewLC |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CProxyResolveActor* CProxyResolveActor::NewLC() |
|
43 { |
|
44 CProxyResolveActor* self = new( ELeave )CProxyResolveActor(); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CProxyResolveActor::~CProxyResolveActor |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CProxyResolveActor::~CProxyResolveActor() |
|
55 { |
|
56 Cancel(); |
|
57 if ( iCurrentQuery ) |
|
58 { |
|
59 delete iCurrentQuery; |
|
60 } |
|
61 delete iRequestQueue; |
|
62 // close socket server |
|
63 iServer.Close(); |
|
64 |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CProxyResolveActor::ConstructL |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CProxyResolveActor::ConstructL () |
|
72 { |
|
73 iRequestQueue = CProxyResolvingQueue::NewL(); |
|
74 // connect the socket server |
|
75 User::LeaveIfError( iServer.Connect() ); |
|
76 } |
|
77 |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CProxyResolveActor::CProxyResolveActor |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CProxyResolveActor::CProxyResolveActor() |
|
84 : CActive( EPriorityStandard ) |
|
85 { |
|
86 CActiveScheduler::Add( this ); |
|
87 } |
|
88 |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CProxyResolveActor::ResolveProxyL |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CProxyResolveActor::ResolveProxyL( TUint& aRequestId, |
|
95 TUint32 aIapId, |
|
96 MSIPProxyResolverObserver& aObserver ) |
|
97 { |
|
98 CProxyQuery* query = CProxyQuery::NewL( iRequestQueue->NextRequestId(), |
|
99 aIapId, aObserver, *this, |
|
100 iServer ); |
|
101 |
|
102 // add the query to the queue |
|
103 iRequestQueue->AddQuery( *query ); |
|
104 |
|
105 // and return the ID to the user |
|
106 aRequestId = query->RequestId(); |
|
107 } |
|
108 |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // void CProxyResolveActor::ConnectionReady(CProxyQuery* aQuery) |
|
112 // |
|
113 // Callback from CProxyQuery, indicating that opening RConnection for |
|
114 // this query is successful and completed |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CProxyResolveActor::ConnectionReady( CProxyQuery* aQuery ) |
|
119 { |
|
120 if( !IsActive() ) |
|
121 { |
|
122 iCurrentQuery = aQuery; |
|
123 // detach this query from the queue (but do not delete) |
|
124 iRequestQueue->DetachByRequestId( aQuery->RequestId() ); |
|
125 // perform the actual query |
|
126 PerformDHCPQuery(); |
|
127 } |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // void CProxyResolveActor::PerformDHCPQuery() |
|
132 // |
|
133 // Perform the actual DHCP query using RConnection API call (Ioctl) |
|
134 // |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CProxyResolveActor::PerformDHCPQuery() |
|
138 { |
|
139 if ( iCurrentQuery && !IsActive() ) |
|
140 { |
|
141 //Make sure that the connection has been opened for this Query object |
|
142 if (iCurrentQuery->ConnectionOpened()) |
|
143 { |
|
144 iCurrentQuery->Connection().Ioctl( KCOLConfiguration, |
|
145 iCurrentQuery->CurrentQueryType(), |
|
146 iStatus, |
|
147 iCurrentQuery->GetBuf() ); |
|
148 SetActive(); |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CProxyResolveActor::RunL |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CProxyResolveActor::RunL() |
|
159 { |
|
160 TInt err = iStatus.Int(); |
|
161 |
|
162 switch( err ) |
|
163 { |
|
164 case KErrNone: |
|
165 { |
|
166 // store results of this query |
|
167 iCurrentQuery->AddResultsL(); |
|
168 //make a new query (SIP addresses or domain names) |
|
169 iCurrentQuery->SetNextIndex(); |
|
170 PerformDHCPQuery(); |
|
171 return; |
|
172 } |
|
173 |
|
174 case KErrCancel: // ignore the cancel error code |
|
175 break; |
|
176 |
|
177 default: |
|
178 { |
|
179 if ( iCurrentQuery->CurrentQueryType() == KConnGetSipServerDomain ) |
|
180 { |
|
181 // Completed domain names. Now try IP addresses. |
|
182 // Note: index is already 0. |
|
183 iCurrentQuery->SetQueryType( KConnGetSipServerAddr ); |
|
184 PerformDHCPQuery(); |
|
185 return; |
|
186 } |
|
187 else |
|
188 { |
|
189 // No more data available, send results to the owner |
|
190 iCurrentQuery->ResolvingRequestComplete(); |
|
191 } |
|
192 } |
|
193 break; |
|
194 } |
|
195 |
|
196 // Finally, delete this CProxyQuery and process the next one |
|
197 delete iCurrentQuery; |
|
198 iCurrentQuery = NULL; |
|
199 ResolveNext(); |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CProxyResolveActor::ResolveNext |
|
204 // Delete the current query and process the next one with opened RConnection |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CProxyResolveActor::ResolveNext() |
|
208 { |
|
209 if(!IsActive()) |
|
210 { |
|
211 if ( iCurrentQuery ) |
|
212 { |
|
213 delete iCurrentQuery; |
|
214 iCurrentQuery = NULL; |
|
215 } |
|
216 |
|
217 // get next CProxyQuery object, whose RConnection is opened |
|
218 iCurrentQuery = iRequestQueue->NextReadyQuery(); |
|
219 PerformDHCPQuery(); |
|
220 } |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CProxyResolveActor::RunError |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 TInt CProxyResolveActor::RunError( TInt aError ) |
|
228 { |
|
229 TInt err = KErrNone; |
|
230 // delete the query, as RunL leaved with aError. |
|
231 if ( iCurrentQuery ) |
|
232 { |
|
233 iCurrentQuery->ResolvingRequestFailed( aError ); |
|
234 delete iCurrentQuery ; |
|
235 iCurrentQuery = NULL; |
|
236 } |
|
237 if( aError == KErrNoMemory ) |
|
238 { |
|
239 err = aError; |
|
240 } |
|
241 ResolveNext(); |
|
242 return err; |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CProxyResolveActor::CancelById |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CProxyResolveActor::CancelById( TUint aRequestId ) |
|
250 { |
|
251 if ( iCurrentQuery && iCurrentQuery->RequestId() == aRequestId ) |
|
252 { |
|
253 Cancel(); |
|
254 iRequestQueue->DetachByRequestId( aRequestId ); |
|
255 delete iCurrentQuery; |
|
256 iCurrentQuery = NULL; |
|
257 ResolveNext(); |
|
258 } |
|
259 else |
|
260 { |
|
261 iRequestQueue->DeleteByRequestId( aRequestId ); |
|
262 } |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CProxyResolveActor::DoCancel |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 void CProxyResolveActor::DoCancel() |
|
270 { |
|
271 // if iCurrentQuery is not null, request has been issued for |
|
272 // the iCurrentQuery, do the cancel action |
|
273 if ( iCurrentQuery ) |
|
274 { |
|
275 iCurrentQuery->Connection().CancelIoctl(); |
|
276 } |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CProxyResolveActor::ErrorOccured |
|
281 // Callback from CProxyQuery, indicating that opening RConnection failed |
|
282 // |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CProxyResolveActor::ErrorOccured( TInt aError, CProxyQuery* aQuery ) |
|
286 { |
|
287 aQuery->ResolvingRequestFailed( aError ); |
|
288 iRequestQueue->DeleteByRequestId( aQuery->RequestId() ); |
|
289 } |