|
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 : CSIPHostResolver.cpp |
|
15 // Part of : ServerResolver |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "CSIPHostResolver.h" |
|
22 #include "CServerQuery.h" |
|
23 #include "CRequestQueue.h" |
|
24 #include "MSIPServerResolverObserver.h" |
|
25 #include "siperr.h" |
|
26 |
|
27 // ---------------------------------------------------------------------------- |
|
28 // CSIPHostResolver::CSIPHostResolver |
|
29 // ---------------------------------------------------------------------------- |
|
30 // |
|
31 CSIPHostResolver::CSIPHostResolver() |
|
32 : CActive( EPriorityStandard ) |
|
33 { |
|
34 CActiveScheduler::Add( this ); |
|
35 } |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // CSIPHostResolver::ConstructL |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 void CSIPHostResolver::ConstructL ( RSocketServ& aServer, |
|
42 RConnection& aConnection ) |
|
43 { |
|
44 iObserverCancel = EFalse; |
|
45 iFailed = EFalse; |
|
46 User::LeaveIfError( iResolver.Open( aServer, KAfInet, KProtocolInetUdp, |
|
47 aConnection ) ); |
|
48 iRequestQueue = CRequestQueue::NewL(); |
|
49 |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // CSIPHostResolver::NewL |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 CSIPHostResolver* CSIPHostResolver::NewL( RSocketServ& aServer, |
|
57 RConnection& aConnection ) |
|
58 { |
|
59 CSIPHostResolver* self = NewLC( aServer, aConnection ); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // CSIPHostResolver::NewLC |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 CSIPHostResolver* CSIPHostResolver::NewLC( RSocketServ& aServer, |
|
69 RConnection& aConnection ) |
|
70 { |
|
71 CSIPHostResolver* self = new ( ELeave ) CSIPHostResolver(); |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL( aServer, aConnection ); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // CSIPHostResolver::~CSIPHostResolver |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 CSIPHostResolver::~CSIPHostResolver() |
|
82 { |
|
83 Cancel(); |
|
84 iResolver.Close(); |
|
85 delete iRequestQueue; |
|
86 delete iQuery; |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // CSIPHostResolver::GetByQueryL |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 void CSIPHostResolver::GetByQueryL ( CServerQuery* aQuery ) |
|
94 { |
|
95 if( !IsActive() && !iQuery ) |
|
96 { |
|
97 iQuery = aQuery; |
|
98 iQuery->Query( *this ); |
|
99 SetActive(); |
|
100 } |
|
101 else |
|
102 { |
|
103 if ( iQuery->ServerResolverObserver() == |
|
104 aQuery->ServerResolverObserver() ) |
|
105 { |
|
106 User::Leave( KErrAlreadyExists ); |
|
107 } |
|
108 iRequestQueue->AddL( *aQuery ); |
|
109 } |
|
110 } |
|
111 |
|
112 // ---------------------------------------------------------------------------- |
|
113 // CSIPHostResolver::CancelGetByURI |
|
114 // ---------------------------------------------------------------------------- |
|
115 // |
|
116 void CSIPHostResolver::CancelGetByURI( MSIPServerResolverObserver* aObserver ) |
|
117 { |
|
118 if ( iQuery != 0 && iQuery->ServerResolverObserver() == aObserver ) |
|
119 { |
|
120 Cancel(); |
|
121 ResolveNext(); |
|
122 } |
|
123 else |
|
124 { |
|
125 iRequestQueue->CancelQuery( aObserver ); |
|
126 } |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CSIPHostResolver::RunL |
|
131 // ---------------------------------------------------------------------------- |
|
132 // |
|
133 void CSIPHostResolver::RunL() |
|
134 { |
|
135 iFailed = EFalse; |
|
136 TBool subquery = EFalse; |
|
137 TInt status = iStatus.Int(); |
|
138 |
|
139 MSIPServerResolverObserver* observer = NULL; |
|
140 |
|
141 if(iQuery != 0) |
|
142 { |
|
143 observer = iQuery->ServerResolverObserver(); |
|
144 |
|
145 if ( iQuery && !iObserverCancel ) |
|
146 { |
|
147 subquery = iQuery->HandleQueryResultL( iStatus.Int() ); |
|
148 } |
|
149 |
|
150 if ( subquery ) |
|
151 { |
|
152 iQuery->Query( *this ); |
|
153 SetActive(); |
|
154 } |
|
155 else |
|
156 { |
|
157 delete iQuery; |
|
158 iQuery = NULL; |
|
159 ResolveNext(); |
|
160 } |
|
161 } |
|
162 else |
|
163 { |
|
164 delete iQuery; |
|
165 iQuery = NULL; |
|
166 ResolveNext(); |
|
167 } |
|
168 |
|
169 |
|
170 if ( !subquery && ( status != KErrNone || iFailed ) && !iObserverCancel) |
|
171 { |
|
172 if ( status != KErrNoMemory ) |
|
173 { |
|
174 status = KErrSIPResolvingFailure; |
|
175 } |
|
176 if(observer != 0) |
|
177 observer->ErrorOccured( status ); |
|
178 } |
|
179 else |
|
180 { |
|
181 iObserverCancel = EFalse; |
|
182 } |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------------- |
|
186 // CSIPHostResolver::RunError |
|
187 // ---------------------------------------------------------------------------- |
|
188 // |
|
189 TInt CSIPHostResolver::RunError ( TInt aError ) |
|
190 { |
|
191 TInt err = KErrNone; |
|
192 // Complete the query, as RunL has not completed it. |
|
193 if ( iQuery ) |
|
194 { |
|
195 MSIPServerResolverObserver* observer = iQuery->ServerResolverObserver(); |
|
196 delete iQuery; |
|
197 iQuery = NULL; |
|
198 observer->ErrorOccured( aError ); |
|
199 } |
|
200 |
|
201 if ( aError == KErrNoMemory ) |
|
202 { |
|
203 err = aError; |
|
204 } |
|
205 |
|
206 return err; |
|
207 } |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // CSIPHostResolver::ResolveNext |
|
211 // ---------------------------------------------------------------------------- |
|
212 // |
|
213 void CSIPHostResolver::ResolveNext() |
|
214 { |
|
215 if ( !IsActive() ) |
|
216 { |
|
217 iQuery = iRequestQueue->NextQuery(); |
|
218 if ( iQuery ) |
|
219 { |
|
220 iQuery->Query( *this ); |
|
221 SetActive(); |
|
222 } |
|
223 } |
|
224 } |
|
225 |
|
226 // ---------------------------------------------------------------------------- |
|
227 // CSIPHostResolver::DoCancel |
|
228 // ---------------------------------------------------------------------------- |
|
229 // |
|
230 void CSIPHostResolver::DoCancel () |
|
231 { |
|
232 iResolver.Cancel(); |
|
233 if ( iQuery ) |
|
234 { |
|
235 iObserverCancel = ETrue; |
|
236 delete iQuery; |
|
237 iQuery = NULL; |
|
238 } |
|
239 } |
|
240 |
|
241 // ---------------------------------------------------------------------------- |
|
242 // CSIPHostResolver::Resolver |
|
243 // ---------------------------------------------------------------------------- |
|
244 // |
|
245 RHostResolver& CSIPHostResolver::Resolver () |
|
246 { |
|
247 return iResolver; |
|
248 } |
|
249 |
|
250 // ---------------------------------------------------------------------------- |
|
251 // CSIPHostResolver::RequestStatus |
|
252 // ---------------------------------------------------------------------------- |
|
253 // |
|
254 TRequestStatus& CSIPHostResolver::RequestStatus () |
|
255 { |
|
256 return iStatus; |
|
257 } |
|
258 |
|
259 // ---------------------------------------------------------------------------- |
|
260 // CSIPHostResolver::SetIPListFailed |
|
261 // ---------------------------------------------------------------------------- |
|
262 // |
|
263 void CSIPHostResolver::SetIPListFailed( TBool aFailed ) |
|
264 { |
|
265 iFailed = aFailed; |
|
266 } |