|
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 : CSIPServerResolver.cpp |
|
15 // Part of : ServerResolver |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <uriutils.h> |
|
22 #include "CSIPServerResolver.h" |
|
23 #include "CSIPHostResolver.h" |
|
24 #include "CServerQuery.h" |
|
25 #include "sipuri.h" |
|
26 #include "uricontainer.h" |
|
27 #include "siphostport.h" |
|
28 #include "sipviaheader.h" |
|
29 |
|
30 #include "MSIPResolvingResult.h" |
|
31 #include "CSIPNaptrOrigDomain.h" |
|
32 #include "CSIPSRVOrigDomain.h" |
|
33 #include "CSIPQuerySrv.h" |
|
34 #include "MSIPHostResolver.h" |
|
35 |
|
36 #include "CSIPQueryA_AAAA.h" |
|
37 #include "CSIPA_AAAAOrigDomain.h" |
|
38 #include "CSIPQueryData.h" |
|
39 #include "sipstrings.h" |
|
40 #include "sipstrconsts.h" |
|
41 #include "siperr.h" |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // CSIPServerResolver::NewL |
|
45 // ---------------------------------------------------------------------------- |
|
46 // |
|
47 CSIPServerResolver* CSIPServerResolver::NewL( RSocketServ& aServer, |
|
48 RConnection& aConnection ) |
|
49 { |
|
50 CSIPServerResolver* self = NewLC( aServer, aConnection ); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // CSIPServerResolver::NewLC |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 CSIPServerResolver* CSIPServerResolver::NewLC( RSocketServ& aServer, |
|
60 RConnection& aConnection ) |
|
61 { |
|
62 CSIPServerResolver* self = new ( ELeave ) CSIPServerResolver(); |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL( aServer, aConnection ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------------------------------- |
|
69 // CSIPServerResolver::CSIPServerResolver |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 CSIPServerResolver::CSIPServerResolver() |
|
73 { |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // CSIPServerResolver::ConstructL |
|
78 // ---------------------------------------------------------------------------- |
|
79 // |
|
80 void CSIPServerResolver::ConstructL( RSocketServ& aServer, |
|
81 RConnection& aConnection ) |
|
82 { |
|
83 iResolver = CSIPHostResolver::NewL( aServer, aConnection ); |
|
84 } |
|
85 |
|
86 // ---------------------------------------------------------------------------- |
|
87 // CSIPServerResolver::~CSIPServerResolver |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 CSIPServerResolver::~CSIPServerResolver() |
|
91 { |
|
92 delete iResolver; |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CSIPServerResolver::GetByURIL |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 void CSIPServerResolver::GetByURIL( |
|
100 const CURIContainer& aURI, |
|
101 TBool aSkipNaptrAndSrvQueries, |
|
102 RPointerArray< MSIPResolvingResult >& aResult, |
|
103 MSIPServerResolverObserver* aObserver ) |
|
104 { |
|
105 __ASSERT_ALWAYS( aURI.IsSIPURI(), User::Leave( KErrSIPInvalidURIType ) ); |
|
106 |
|
107 const CSIPURI& uri = *(aURI.SIPURI()); |
|
108 |
|
109 TBool forceUDP( EFalse ); |
|
110 RStringF protocol = TransportProtocolL( uri, forceUDP ); |
|
111 |
|
112 TUint port( uri.HostPort().Port() ); |
|
113 |
|
114 HBufC8* host = NULL; |
|
115 if ( uri.HasParam( SIPStrings::StringF( SipStrConsts::EMaddr ) ) ) |
|
116 { |
|
117 host = uri.ParamValue( |
|
118 SIPStrings::StringF( SipStrConsts::EMaddr ) ).DesC().AllocL(); |
|
119 } |
|
120 else |
|
121 { |
|
122 host = uri.HostPort().Host().AllocL(); |
|
123 } |
|
124 CleanupStack::PushL( host ); |
|
125 |
|
126 if ( !( UriUtils::HostType( *host ) == UriUtils::ETextHost ) && port == 0 ) |
|
127 { |
|
128 // The host is an IP address and there is no explicit port is in the URI |
|
129 TBool useTls = |
|
130 ( protocol == SIPStrings::StringF( SipStrConsts::ETLS ) ); |
|
131 port = DefaultPort( useTls ); |
|
132 } |
|
133 |
|
134 if ( ( UriUtils::HostType( *host ) == UriUtils::ETextHost ) && |
|
135 aSkipNaptrAndSrvQueries ) |
|
136 { |
|
137 if ( protocol == SIPStrings::StringF( SipStrConsts::EEmpty ) ) |
|
138 { |
|
139 protocol.Close(); |
|
140 protocol = DefaultTransport( uri.IsSIPSURI() ); |
|
141 } |
|
142 if ( port == 0 ) |
|
143 { |
|
144 port = DefaultPort( uri.IsSIPSURI() ); |
|
145 } |
|
146 } |
|
147 |
|
148 ChooseQueryL( aObserver, *host, aResult, uri.IsSIPSURI(), |
|
149 port, protocol, forceUDP, aSkipNaptrAndSrvQueries ); |
|
150 |
|
151 CleanupStack::PopAndDestroy( host ); |
|
152 } |
|
153 |
|
154 // ---------------------------------------------------------------------------- |
|
155 // CSIPServerResolver::GetByViaL |
|
156 // ---------------------------------------------------------------------------- |
|
157 // |
|
158 void CSIPServerResolver::GetByViaL( |
|
159 CSIPViaHeader& aVia, |
|
160 RPointerArray< MSIPResolvingResult >& aResult, |
|
161 MSIPServerResolverObserver* aObserver ) |
|
162 { |
|
163 TUint port( aVia.SentByHostPort().Port() ); |
|
164 |
|
165 HBufC8* host = NULL; |
|
166 |
|
167 if ( aVia.HasParam(SIPStrings::StringF(SipStrConsts::EMaddr)) ) |
|
168 { |
|
169 host = aVia.ParamValue( SIPStrings::StringF( |
|
170 SipStrConsts::EMaddr ) ).DesC().AllocLC(); |
|
171 } |
|
172 else |
|
173 { |
|
174 host = aVia.SentByHostPort().Host().AllocLC(); |
|
175 } |
|
176 |
|
177 if ( !( UriUtils::HostType( *host ) == UriUtils::ETextHost ) ) |
|
178 { |
|
179 if ( port == 0 ) |
|
180 { |
|
181 port = KSIPDefaultPort; |
|
182 } |
|
183 } |
|
184 |
|
185 ChooseQueryL( aObserver, *host, aResult, EFalse, port, aVia.Transport() ); |
|
186 |
|
187 CleanupStack::PopAndDestroy( host ); |
|
188 } |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // CSIPServerResolver::Cancel |
|
192 // ---------------------------------------------------------------------------- |
|
193 // |
|
194 void CSIPServerResolver::Cancel( MSIPServerResolverObserver* aObserver ) |
|
195 { |
|
196 iResolver->CancelGetByURI( aObserver ); |
|
197 } |
|
198 |
|
199 // ---------------------------------------------------------------------------- |
|
200 // CSIPServerResolver::ChooseQueryL |
|
201 // ---------------------------------------------------------------------------- |
|
202 // |
|
203 void CSIPServerResolver::ChooseQueryL( |
|
204 MSIPServerResolverObserver* aObserver, |
|
205 const TDesC8& aTarget, |
|
206 RPointerArray< MSIPResolvingResult >& aResult, |
|
207 TBool aSipsUri, |
|
208 TUint aPort, |
|
209 RStringF aProtocol, |
|
210 TBool aForceUDP, |
|
211 TBool aSkipNaptrAndSrvQueries ) |
|
212 { |
|
213 CSIPQueryData* querydata = CSIPQueryData::NewL( aObserver, |
|
214 aPort, |
|
215 aProtocol, |
|
216 aTarget, |
|
217 *iResolver, |
|
218 aResult, |
|
219 aSipsUri, |
|
220 aForceUDP ); |
|
221 CleanupStack::PushL( querydata ); |
|
222 CServerQuery* query = CServerQuery::NewL( aObserver, querydata ); |
|
223 CleanupStack::Pop( querydata ); |
|
224 CleanupStack::PushL( query ); |
|
225 |
|
226 if ( aPort || aSkipNaptrAndSrvQueries ) |
|
227 { |
|
228 SetA_AAAAQueryL( query ); |
|
229 } |
|
230 else |
|
231 { |
|
232 if ( aProtocol != SIPStrings::StringF( SipStrConsts::EEmpty ) ) |
|
233 { |
|
234 SetSRVQueryL( query ); |
|
235 } |
|
236 else |
|
237 { |
|
238 // NAPTR query is done only when resolving by URI, and neither the |
|
239 // transport protocol nor port was specified in the URI. |
|
240 SetNaptrQueryL( query ); |
|
241 } |
|
242 } |
|
243 |
|
244 CleanupStack::Pop( query ); |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------------------------------- |
|
248 // CSIPServerResolver::SetA_AAAAQueryL |
|
249 // ---------------------------------------------------------------------------- |
|
250 // |
|
251 void CSIPServerResolver::SetA_AAAAQueryL( CServerQuery* aQuery ) |
|
252 { |
|
253 CSIPA_AAAAOrigDomain* querycondition = |
|
254 CSIPA_AAAAOrigDomain::NewL( *aQuery ); |
|
255 CleanupStack::PushL( querycondition ); |
|
256 aQuery->SetQueryConditionL( querycondition ); |
|
257 CleanupStack::Pop( querycondition ); |
|
258 iResolver->GetByQueryL( aQuery ); |
|
259 } |
|
260 |
|
261 // ---------------------------------------------------------------------------- |
|
262 // CSIPServerResolver::SetSRVQueryL |
|
263 // ---------------------------------------------------------------------------- |
|
264 // |
|
265 void CSIPServerResolver::SetSRVQueryL( CServerQuery* aQuery ) |
|
266 { |
|
267 CSIPSRVOrigDomain* querycondition = CSIPSRVOrigDomain::NewL( *aQuery ); |
|
268 CleanupStack::PushL( querycondition ); |
|
269 aQuery->SetQueryConditionL( querycondition ); |
|
270 CleanupStack::Pop( querycondition ); |
|
271 iResolver->GetByQueryL( aQuery ); |
|
272 } |
|
273 |
|
274 // ---------------------------------------------------------------------------- |
|
275 // CSIPServerResolver::SetNaptrQueryL |
|
276 // ---------------------------------------------------------------------------- |
|
277 // |
|
278 void CSIPServerResolver::SetNaptrQueryL( CServerQuery* aQuery ) |
|
279 { |
|
280 CSIPNaptrOrigDomain* querycondition = CSIPNaptrOrigDomain::NewL( *aQuery ); |
|
281 CleanupStack::PushL( querycondition ); |
|
282 aQuery->SetQueryConditionL( querycondition ); |
|
283 CleanupStack::Pop( querycondition ); |
|
284 iResolver->GetByQueryL( aQuery ); |
|
285 } |
|
286 |
|
287 // ---------------------------------------------------------------------------- |
|
288 // CSIPServerResolver::TransportProtocolL |
|
289 // ---------------------------------------------------------------------------- |
|
290 // |
|
291 RStringF CSIPServerResolver::TransportProtocolL( |
|
292 const CSIPURI& aURI, |
|
293 TBool& aForceUdp ) const |
|
294 { |
|
295 aForceUdp = EFalse; |
|
296 |
|
297 RStringF protocol = |
|
298 aURI.ParamValue( SIPStrings::StringF( SipStrConsts::ETransport ) ); |
|
299 |
|
300 if ( protocol == SIPStrings::StringF( SipStrConsts::EEmpty ) ) |
|
301 { |
|
302 // Add explicit transport protocol |
|
303 // if there is a port in the URI or the host is an IP address |
|
304 const CSIPHostPort& hostPort( aURI.HostPort() ); |
|
305 if ( hostPort.HasPort() || |
|
306 !( UriUtils::HostType( hostPort.Host() ) == UriUtils::ETextHost ) ) |
|
307 { |
|
308 protocol = DefaultTransport( aURI.IsSIPSURI() ); |
|
309 } |
|
310 } |
|
311 else |
|
312 { |
|
313 if ( aURI.IsSIPSURI() && |
|
314 protocol == SIPStrings::StringF( SipStrConsts::EUDP ) ) |
|
315 { |
|
316 User::Leave( KErrNotSupported ); |
|
317 } |
|
318 |
|
319 __ASSERT_ALWAYS( |
|
320 ( protocol == SIPStrings::StringF( SipStrConsts::ETCP ) || |
|
321 protocol == SIPStrings::StringF( SipStrConsts::EUDP ) || |
|
322 protocol == SIPStrings::StringF( SipStrConsts::ETLS ) ), |
|
323 User::Leave( KErrNotSupported ) ); |
|
324 |
|
325 aForceUdp = ( protocol == SIPStrings::StringF( SipStrConsts::EUDP ) ); |
|
326 } |
|
327 return protocol; |
|
328 } |
|
329 |
|
330 // ---------------------------------------------------------------------------- |
|
331 // CSIPServerResolver::DefaultTransport |
|
332 // ---------------------------------------------------------------------------- |
|
333 // |
|
334 RStringF CSIPServerResolver::DefaultTransport( TBool aSipsUri ) const |
|
335 { |
|
336 RStringF protocol( SIPStrings::StringF( SipStrConsts::EUDP ) ); |
|
337 if ( aSipsUri ) |
|
338 { |
|
339 protocol = SIPStrings::StringF( SipStrConsts::ETLS ); |
|
340 } |
|
341 return protocol; |
|
342 } |
|
343 |
|
344 // ---------------------------------------------------------------------------- |
|
345 // CSIPServerResolver::DefaultPort |
|
346 // ---------------------------------------------------------------------------- |
|
347 // |
|
348 TUint CSIPServerResolver::DefaultPort( TBool aUseTls ) const |
|
349 { |
|
350 TUint port( KSIPDefaultPort ); |
|
351 if ( aUseTls ) |
|
352 { |
|
353 port = KSIPsDefaultPort; |
|
354 } |
|
355 return port; |
|
356 } |