|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: URI parsing |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <nsmlunicodeconverter.h> |
|
21 #include<nsmlconstantdefs.h> |
|
22 #include "NSmlURI.h" |
|
23 #include "nsmlcliagconstants.h" |
|
24 |
|
25 // ============================ MEMBER FUNCTIONS =============================== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CNSmlURI::CNSmlURI |
|
29 // C++ constructor. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CNSmlURI::CNSmlURI() |
|
33 { |
|
34 iPort = KNSmlDefaultPort; |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CNSmlURI::NewL |
|
39 // Symbian two-phased constructor. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 EXPORT_C CNSmlURI* CNSmlURI::NewL() |
|
43 { |
|
44 CNSmlURI* self = CNSmlURI::NewLC(); |
|
45 CleanupStack::Pop(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CNSmlURI::NewL |
|
51 // Symbian two-phased constructor. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C CNSmlURI* CNSmlURI::NewL( const TDesC& aHostName, TBool aInternet ) |
|
55 { |
|
56 CNSmlURI* self = CNSmlURI::NewLC( aHostName, aInternet ); |
|
57 CleanupStack::Pop(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CNSmlURI::NewL |
|
63 // Symbian two-phased construtor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CNSmlURI* CNSmlURI::NewL( const TDesC8& aHostName, TBool aInternet ) |
|
67 { |
|
68 CNSmlURI* self = CNSmlURI::NewLC( aHostName, aInternet ); |
|
69 CleanupStack::Pop(); |
|
70 return self; |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CNSmlURI::NewLC |
|
75 // Symbian two-phased constructor. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CNSmlURI* CNSmlURI::NewLC() |
|
79 { |
|
80 CNSmlURI* self = new ( ELeave ) CNSmlURI; |
|
81 CleanupStack::PushL( self ); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CNSmlURI::NewLC |
|
87 // Symbian two-phased constructor. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C CNSmlURI* CNSmlURI::NewLC( const TDesC& aHostName, TBool aInternet ) |
|
91 { |
|
92 CNSmlURI* self = new ( ELeave ) CNSmlURI; |
|
93 CleanupStack::PushL( self ); |
|
94 self->ConstructL( aHostName, aInternet ); |
|
95 return self; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CNSmlURI::NewLC |
|
100 // Symbian two-phased constructor. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C CNSmlURI* CNSmlURI::NewLC( const TDesC8& aHostName, TBool aInternet ) |
|
104 { |
|
105 CNSmlURI* self = new ( ELeave ) CNSmlURI; |
|
106 CleanupStack::PushL( self ); |
|
107 self->ConstructL( aHostName, aInternet ); |
|
108 return self; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CNSmlURI::ConstructL |
|
113 // Symbian second phase constructor. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CNSmlURI::ConstructL( const TDesC& aHostName, TBool aInternet ) |
|
117 { |
|
118 SetHostNameL( aHostName, aInternet ); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CNSmlURI::ConstructL |
|
123 // Symbian second phase constructor. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CNSmlURI::ConstructL( const TDesC8& aHostName, TBool aInternet ) |
|
127 { |
|
128 SetHostNameL( aHostName, aInternet ); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CNSmlURI::~CNSmlURI |
|
133 // Destructor. |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 CNSmlURI::~CNSmlURI() |
|
137 { |
|
138 delete iHostName; |
|
139 delete iHostNameWithPort; |
|
140 delete iDatabase; |
|
141 delete iDatabaseWithoutColon; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CNSmlURI::operator= |
|
146 // Assignment operator. Creates a deep copy of the original object. |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C CNSmlURI& CNSmlURI::operator=( const CNSmlURI& aOther ) |
|
150 { |
|
151 if ( aOther.iHostName ) |
|
152 { |
|
153 delete iHostName; |
|
154 iHostName = NULL; |
|
155 iHostName = aOther.iHostName->AllocL(); |
|
156 } |
|
157 |
|
158 if ( aOther.iHostNameWithPort ) |
|
159 { |
|
160 delete iHostNameWithPort; |
|
161 iHostNameWithPort = NULL; |
|
162 iHostNameWithPort = aOther.iHostNameWithPort->AllocL(); |
|
163 } |
|
164 |
|
165 iPort = aOther.iPort; |
|
166 |
|
167 if ( aOther.iDatabase ) |
|
168 { |
|
169 delete iDatabase; |
|
170 iDatabase = NULL; |
|
171 iDatabase = aOther.iDatabase->AllocL(); |
|
172 } |
|
173 |
|
174 if ( aOther.iDatabaseWithoutColon ) |
|
175 { |
|
176 delete iDatabaseWithoutColon; |
|
177 iDatabaseWithoutColon = NULL; |
|
178 iDatabaseWithoutColon = aOther.iDatabaseWithoutColon->AllocL(); |
|
179 } |
|
180 |
|
181 iAbsoluteDatabaseURI = aOther.iAbsoluteDatabaseURI; |
|
182 |
|
183 return *this; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CNSmlURI::IsEqualL |
|
188 // Compares if two URIs are equal. |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C TBool CNSmlURI::IsEqualL( const CNSmlURI& aURI, TBool aIgnoreCase ) |
|
192 { |
|
193 TBool equalURI( EFalse ); |
|
194 HBufC* thisAbsoluteURI( AbsoluteURILC( this ) ); |
|
195 HBufC* otherAbsoluteURI( AbsoluteURILC( &aURI ) ); |
|
196 if( aIgnoreCase ) |
|
197 { |
|
198 if( thisAbsoluteURI->CompareF( otherAbsoluteURI->Des() ) == 0 ) |
|
199 { |
|
200 equalURI = ETrue; |
|
201 } |
|
202 |
|
203 } |
|
204 else |
|
205 { |
|
206 if ( *thisAbsoluteURI == *otherAbsoluteURI ) |
|
207 { |
|
208 equalURI = ETrue; |
|
209 } |
|
210 } |
|
211 |
|
212 CleanupStack::PopAndDestroy( 2 ); // otherAbsoluteURI, thisAbsoluteURI |
|
213 |
|
214 return equalURI; |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CNSmlURI::SetHostNameL |
|
219 // Sets the hostname. |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 EXPORT_C void CNSmlURI::SetHostNameL( const TDesC& aHostName, TBool aInternet ) |
|
223 { |
|
224 delete iHostName; |
|
225 iHostName = NULL; |
|
226 iHostName = aHostName.AllocL(); |
|
227 |
|
228 RemoveTrailingSlash( iHostName->Des() ); |
|
229 |
|
230 if ( aInternet ) |
|
231 { |
|
232 AddHTTPSchemeToHostnameL(); |
|
233 ExtractPortFromHostnameL(); |
|
234 } |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CNSmlURI::SetHostNameL |
|
239 // 8-bit variant of SetHostNameL. |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 EXPORT_C void CNSmlURI::SetHostNameL( const TDesC8& aHostName, TBool aInternet ) |
|
243 { |
|
244 HBufC* hostName; |
|
245 NSmlUnicodeConverter::HBufC16InUnicodeLC( aHostName, hostName ); |
|
246 |
|
247 SetHostNameL( *hostName, aInternet ); |
|
248 |
|
249 CleanupStack::PopAndDestroy(); // hostName |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CNSmlURI::SetPort |
|
254 // Sets the port. |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 EXPORT_C void CNSmlURI::SetPort( TInt aPort ) |
|
258 { |
|
259 iPort = aPort; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CNSmlURI::SetDatabaseL |
|
264 // Sets the database part of URI. |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 EXPORT_C void CNSmlURI::SetDatabaseL( const TDesC& aDatabase, TBool aRemoveColon ) |
|
268 { |
|
269 delete iDatabase; |
|
270 iDatabase = NULL; |
|
271 |
|
272 if ( aDatabase.FindF( KNSmlHttpHeader ) == 0 || aDatabase.FindF( KNSmlHttpsHeader ) == 0 || aDatabase.FindF( KNSmlIMEIHeader ) == 0 ) |
|
273 { |
|
274 iDatabase = HBufC::NewL( aDatabase.Length() ); |
|
275 |
|
276 if ( aDatabase.FindF( *iHostName ) == 0 ) |
|
277 { |
|
278 iAbsoluteDatabaseURI = EFalse; |
|
279 *iDatabase = aDatabase.Right( aDatabase.Length() - iHostName->Length() ); |
|
280 |
|
281 if ( iDatabase->Locate( '/' ) == 0 ) |
|
282 { |
|
283 *iDatabase = iDatabase->Right( iDatabase->Length() - 1 ); |
|
284 } |
|
285 } |
|
286 else |
|
287 { |
|
288 iAbsoluteDatabaseURI = ETrue; |
|
289 *iDatabase = aDatabase; |
|
290 } |
|
291 } |
|
292 else |
|
293 { |
|
294 iAbsoluteDatabaseURI = EFalse; |
|
295 |
|
296 if ( aDatabase.Length() >= KNSmlAgentRelativeURIPrefix().Length() ) |
|
297 { |
|
298 if ( aDatabase.FindF( KNSmlAgentRelativeURIPrefix ) == 0 ) |
|
299 { |
|
300 iDatabase = aDatabase.AllocL(); |
|
301 } |
|
302 else |
|
303 { |
|
304 iDatabase = HBufC::NewL( aDatabase.Length() + KNSmlAgentRelativeURIPrefix().Length() ); |
|
305 iDatabase->Des().Format( KNSmlAgentRelativeURIPrefix ); |
|
306 iDatabase->Des().Append( aDatabase ); |
|
307 } |
|
308 } |
|
309 else if ( aDatabase.Length() == 1 ) |
|
310 { |
|
311 if ( aDatabase[0] == '/' ) |
|
312 { |
|
313 iDatabase = aDatabase.AllocL(); |
|
314 } |
|
315 else |
|
316 { |
|
317 iDatabase = HBufC::NewL( 1 + KNSmlAgentRelativeURIPrefix().Length() ); |
|
318 iDatabase->Des().Format( KNSmlAgentRelativeURIPrefix ); |
|
319 iDatabase->Des().Append( aDatabase ); |
|
320 } |
|
321 } |
|
322 else |
|
323 { |
|
324 iDatabase = HBufC::NewL( 0 ); |
|
325 } |
|
326 } |
|
327 |
|
328 delete iDatabaseWithoutColon; |
|
329 iDatabaseWithoutColon = NULL; |
|
330 |
|
331 if ( aRemoveColon ) |
|
332 { |
|
333 if ( iDatabase->Locate( ':' ) == 3 ) |
|
334 { |
|
335 iDatabaseWithoutColon = iDatabase->AllocL(); |
|
336 iDatabaseWithoutColon->Des().Delete( 3, 1 ); |
|
337 } |
|
338 } |
|
339 } |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CNSmlURI::SetDatabaseL |
|
343 // 8-bit variant of SetDatabaseL. |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 EXPORT_C void CNSmlURI::SetDatabaseL( const TDesC8& aDatabase, TBool aRemoveColon ) |
|
347 { |
|
348 HBufC* database; |
|
349 NSmlUnicodeConverter::HBufC16InUnicodeLC( aDatabase, database ); |
|
350 SetDatabaseL( *database, aRemoveColon ); |
|
351 CleanupStack::PopAndDestroy(); // database |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CNSmlURI::HostName |
|
356 // Returns hostname. |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 EXPORT_C TPtrC CNSmlURI::HostName() |
|
360 { |
|
361 TPtrC hostName( *iHostName ); |
|
362 return hostName; |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CNSmlURI::HostNameWithPortL |
|
367 // Returns hostname URI with port number. |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 EXPORT_C TPtrC CNSmlURI::HostNameWithPortL( TBool aIncludingDefaultPort ) |
|
371 { |
|
372 delete iHostNameWithPort; |
|
373 iHostNameWithPort = NULL; |
|
374 iHostNameWithPort = HBufC::NewL( iHostName->Length() + 12 + KNSmlHttpHeaderSpace ); |
|
375 |
|
376 if (iPort == KNSmlDefaultPort && !aIncludingDefaultPort ) |
|
377 { |
|
378 *iHostNameWithPort = *iHostName; |
|
379 } |
|
380 else |
|
381 { |
|
382 if ( iHostName->FindF( KNSmlHttpHeader() ) != KErrNotFound ) |
|
383 { |
|
384 iHostNameWithPort->Des() += KNSmlHttpHeader; |
|
385 } |
|
386 else |
|
387 { |
|
388 if ( iHostName->FindF( KNSmlHttpsHeader() ) != KErrNotFound ) |
|
389 { |
|
390 iHostNameWithPort->Des() += KNSmlHttpsHeader; |
|
391 } |
|
392 } |
|
393 iHostNameWithPort->Des() += *IPAllocLC(); |
|
394 CleanupStack::PopAndDestroy(); |
|
395 iHostNameWithPort->Des() += _L(":"); |
|
396 TBuf<11> stringPort; |
|
397 stringPort.Num( iPort ); |
|
398 iHostNameWithPort->Des() += stringPort; |
|
399 iHostNameWithPort->Des() += *DocNameAllocLC(); |
|
400 CleanupStack::PopAndDestroy(); |
|
401 } |
|
402 |
|
403 TPtrC hostNameWithPort( *iHostNameWithPort ); |
|
404 return hostNameWithPort; |
|
405 } |
|
406 |
|
407 // ----------------------------------------------------------------------------- |
|
408 // CNSmlURI::HostNameInUTF8AllocLC |
|
409 // Returns hostname in 8-bit heap buffer. |
|
410 // ----------------------------------------------------------------------------- |
|
411 // |
|
412 EXPORT_C HBufC8* CNSmlURI::HostNameInUTF8AllocLC() |
|
413 { |
|
414 HBufC8* UTF8HostName; |
|
415 NSmlUnicodeConverter::HBufC8InUTF8LC( *iHostName, UTF8HostName ); |
|
416 return UTF8HostName; |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CNSmlURI::Database |
|
421 // Returns database. |
|
422 // ----------------------------------------------------------------------------- |
|
423 // |
|
424 EXPORT_C TPtrC CNSmlURI::Database() |
|
425 { |
|
426 TPtrC database( *iDatabase ); |
|
427 return database; |
|
428 } |
|
429 |
|
430 // ----------------------------------------------------------------------------- |
|
431 // CNSmlURI::DataBaseWithoutRelativePrefix |
|
432 // Returns database without relative URI prefix. |
|
433 // ----------------------------------------------------------------------------- |
|
434 // |
|
435 EXPORT_C TPtrC CNSmlURI::DataBaseWithoutRelativePrefix() |
|
436 { |
|
437 // database always contains the relative URI prefix |
|
438 if ( iDatabase->Length() > KNSmlAgentRelativeURIPrefix().Length() ) |
|
439 { |
|
440 if ( iDatabase->FindF( KNSmlAgentRelativeURIPrefix ) == 0 ) |
|
441 { |
|
442 return (*iDatabase).Mid( KNSmlAgentRelativeURIPrefix().Length() ); |
|
443 } |
|
444 } |
|
445 return (*iDatabase).Mid(0); |
|
446 } |
|
447 |
|
448 // ----------------------------------------------------------------------------- |
|
449 // CNSmlURI::SyncMLDatabaseAllocLC |
|
450 // Returns database in a new heap buffer. |
|
451 // ----------------------------------------------------------------------------- |
|
452 // |
|
453 EXPORT_C HBufC* CNSmlURI::SyncMLDatabaseAllocLC() |
|
454 { |
|
455 HBufC* shapedURI; |
|
456 |
|
457 if ( iDatabaseWithoutColon ) |
|
458 { |
|
459 if ( iDatabaseWithoutColon->FindF( KNSmlAgentRelativeURIPrefix ) == 0 ) |
|
460 { |
|
461 shapedURI = iDatabaseWithoutColon->AllocLC(); |
|
462 } |
|
463 else |
|
464 { |
|
465 shapedURI = HBufC::NewLC( iDatabaseWithoutColon->Length() + KNSmlAgentRelativeURIPrefix.iTypeLength ); |
|
466 shapedURI->Des() = KNSmlAgentRelativeURIPrefix; |
|
467 shapedURI->Des() += *iDatabaseWithoutColon; |
|
468 } |
|
469 } |
|
470 else |
|
471 { |
|
472 if ( iDatabase ) |
|
473 { |
|
474 if ( iAbsoluteDatabaseURI ) |
|
475 { |
|
476 shapedURI = iDatabase->AllocLC(); |
|
477 } |
|
478 else |
|
479 { |
|
480 if ( iDatabase->FindF( KNSmlAgentRelativeURIPrefix ) == 0 ) |
|
481 { |
|
482 shapedURI = iDatabase->AllocLC(); |
|
483 } |
|
484 else |
|
485 { |
|
486 shapedURI = HBufC::NewLC( iDatabase->Length() + KNSmlAgentRelativeURIPrefix.iTypeLength ); |
|
487 shapedURI->Des() = KNSmlAgentRelativeURIPrefix; |
|
488 shapedURI->Des() += *iDatabase; |
|
489 } |
|
490 } |
|
491 } |
|
492 else |
|
493 { |
|
494 shapedURI = HBufC::NewLC( 0 ); |
|
495 } |
|
496 } |
|
497 |
|
498 return shapedURI; |
|
499 } |
|
500 |
|
501 // ----------------------------------------------------------------------------- |
|
502 // CNSmlURI::DatabaseMatchesL |
|
503 // Compares if two database addresses match. |
|
504 // ----------------------------------------------------------------------------- |
|
505 // |
|
506 EXPORT_C TBool CNSmlURI::DatabaseMatchesL( const TDesC& aDatabase ) |
|
507 { |
|
508 HBufC* database( HBufC::NewL( aDatabase.Length() ) ); |
|
509 |
|
510 if( iDatabase->CompareF( aDatabase ) == 0 ) |
|
511 |
|
512 { |
|
513 return ETrue; |
|
514 } |
|
515 |
|
516 delete database; |
|
517 return EFalse; |
|
518 } |
|
519 |
|
520 // ----------------------------------------------------------------------------- |
|
521 // CNSmlURI::IPAllocLC |
|
522 // Returns hostname part of the address. |
|
523 // ----------------------------------------------------------------------------- |
|
524 // |
|
525 HBufC* CNSmlURI::IPAllocLC() |
|
526 { |
|
527 HBufC* IP = HBufC::NewLC ( iHostName->Length() + 2 ); |
|
528 HBufC* docName = HBufC::NewLC ( iHostName->Length() + 2 ); |
|
529 TPtr ptrIP = IP->Des(); |
|
530 TPtr ptrDocName = docName->Des(); |
|
531 ParseURIL( *iHostName, ptrIP, ptrDocName ); |
|
532 CleanupStack::PopAndDestroy(); // docName |
|
533 return IP; |
|
534 } |
|
535 |
|
536 // ----------------------------------------------------------------------------- |
|
537 // CNSmlURI::DocNameAllocLC |
|
538 // Returns path part of the address. |
|
539 // ----------------------------------------------------------------------------- |
|
540 // |
|
541 HBufC* CNSmlURI::DocNameAllocLC() |
|
542 { |
|
543 HBufC* docName = HBufC::NewLC ( iHostName->Length() + 2 ); |
|
544 HBufC* IP = HBufC::NewLC ( iHostName->Length() + 2 ); |
|
545 TPtr ptrDocName = docName->Des(); |
|
546 TPtr ptrIP = IP->Des(); |
|
547 ParseURIL( *iHostName, ptrIP, ptrDocName ); |
|
548 CleanupStack::PopAndDestroy(); // IP |
|
549 return docName; |
|
550 } |
|
551 |
|
552 // ----------------------------------------------------------------------------- |
|
553 // CNSmlURI::ParseURILL |
|
554 // Parses hostname and path components of the address. |
|
555 // ----------------------------------------------------------------------------- |
|
556 // |
|
557 void CNSmlURI::ParseURIL( const TDesC& aURI, TDes& aAddress, TDes& aDocName ) const |
|
558 { |
|
559 const TChar oneSlash( '/' ); |
|
560 |
|
561 HBufC* URI( aURI.AllocLC() ); |
|
562 TPtr ptrURI( URI->Des() ); |
|
563 aAddress.Zero(); |
|
564 aDocName.Zero(); |
|
565 |
|
566 TInt httpHeaderPos( ptrURI.FindF( KNSmlHttpHeader() ) ); |
|
567 TInt httpsHeaderPos( ptrURI.FindF( KNSmlHttpsHeader() ) ); |
|
568 |
|
569 // Skip http:// if found |
|
570 if( (httpHeaderPos != KErrNotFound) || (httpsHeaderPos != KErrNotFound) ) |
|
571 { |
|
572 TInt cutLength = (httpHeaderPos == KErrNotFound) ? KNSmlHttpsHeader().Length() : KNSmlHttpHeader().Length(); |
|
573 ptrURI = ptrURI.Right( ptrURI.Length() - cutLength ); |
|
574 } |
|
575 |
|
576 // Now extract server name and server path |
|
577 TInt firstSlash( ptrURI.Locate( oneSlash ) ); |
|
578 |
|
579 if( firstSlash != KErrNotFound ) |
|
580 { |
|
581 // Slash found -> grab address and rest is servername |
|
582 aAddress = ptrURI.Left( firstSlash ); |
|
583 aDocName = ptrURI.Right( ptrURI.Length() - firstSlash ); |
|
584 } |
|
585 else |
|
586 { |
|
587 aAddress = ptrURI; |
|
588 aDocName.Append( oneSlash ); |
|
589 } |
|
590 |
|
591 aAddress.ZeroTerminate(); |
|
592 aDocName.ZeroTerminate(); |
|
593 |
|
594 CleanupStack::PopAndDestroy(); // URI |
|
595 } |
|
596 |
|
597 // ----------------------------------------------------------------------------- |
|
598 // CNSmlURI::AbsoluteURILC |
|
599 // Returns absolute URI. |
|
600 // ----------------------------------------------------------------------------- |
|
601 // |
|
602 HBufC* CNSmlURI::AbsoluteURILC( const CNSmlURI* aURI ) const |
|
603 { |
|
604 HBufC* absoluteURI; |
|
605 |
|
606 if ( aURI->iAbsoluteDatabaseURI ) |
|
607 { |
|
608 absoluteURI = aURI->iDatabase->AllocLC(); |
|
609 } |
|
610 else |
|
611 { |
|
612 TInt hostNameLength( 0 ); |
|
613 TInt databaseLength( 0 ); |
|
614 |
|
615 if ( aURI->iHostName ) |
|
616 { |
|
617 hostNameLength = aURI->iHostName->Length(); |
|
618 } |
|
619 |
|
620 if ( aURI->iDatabaseWithoutColon ) |
|
621 { |
|
622 databaseLength = aURI->iDatabaseWithoutColon->Length(); |
|
623 } |
|
624 else |
|
625 { |
|
626 if ( aURI->iDatabase ) |
|
627 { |
|
628 databaseLength = aURI->iDatabase->Length(); |
|
629 } |
|
630 } |
|
631 |
|
632 absoluteURI = HBufC::NewLC( hostNameLength + KNSmlAgentURIDelimeter.iTypeLength + databaseLength ); |
|
633 TPtr absoluteURIPtr = absoluteURI->Des(); |
|
634 |
|
635 if ( aURI->iHostName ) |
|
636 { |
|
637 absoluteURIPtr.Format( *aURI->iHostName ); |
|
638 } |
|
639 |
|
640 absoluteURIPtr.Append( KNSmlAgentURIDelimeter ); |
|
641 |
|
642 if ( aURI->iDatabaseWithoutColon ) |
|
643 { |
|
644 absoluteURIPtr.Append( *aURI->iDatabaseWithoutColon ); |
|
645 } |
|
646 else |
|
647 { |
|
648 if ( aURI->iDatabase ) |
|
649 { |
|
650 absoluteURIPtr.Append( RemoveDotSlash( *aURI->iDatabase ) ); |
|
651 } |
|
652 } |
|
653 } |
|
654 |
|
655 return absoluteURI; |
|
656 } |
|
657 |
|
658 // ----------------------------------------------------------------------------- |
|
659 // CNSmlURI::AddHTTPSchemeToHostnameL |
|
660 // Adds HTTP prefix to the address if necessary. |
|
661 // ----------------------------------------------------------------------------- |
|
662 // |
|
663 void CNSmlURI::AddHTTPSchemeToHostnameL() |
|
664 { |
|
665 if ( !iHostName ) |
|
666 { |
|
667 return; |
|
668 } |
|
669 |
|
670 if( iHostName->FindF( KNSmlHttpHeader() ) == 0 || |
|
671 iHostName->FindF( KNSmlHttpsHeader() ) == 0 ) |
|
672 { |
|
673 return; |
|
674 } |
|
675 |
|
676 HBufC* tempHostName( HBufC::NewLC( iHostName->Length() + KNSmlHttpHeader.iTypeLength ) ); |
|
677 tempHostName->Des() = KNSmlHttpHeader; |
|
678 tempHostName->Des() += *iHostName; |
|
679 |
|
680 delete iHostName; |
|
681 iHostName = tempHostName; |
|
682 |
|
683 CleanupStack::Pop(); // tempHostName |
|
684 } |
|
685 |
|
686 // ----------------------------------------------------------------------------- |
|
687 // CNSmlURI::RemoveTrailingSlash |
|
688 // Removes a possible trailing slash |
|
689 // (e.g. http://myserver.com/sml/ -> http:// myserver.com/sml). |
|
690 // ----------------------------------------------------------------------------- |
|
691 // |
|
692 void CNSmlURI::RemoveTrailingSlash( TPtr aString ) const |
|
693 { |
|
694 if ( aString.Length() > 0 ) |
|
695 { |
|
696 if ( aString[aString.Length() - 1] == '/' ) |
|
697 { |
|
698 aString.Delete( aString.Length() - 1, 1 ); |
|
699 } |
|
700 } |
|
701 } |
|
702 |
|
703 // ----------------------------------------------------------------------------- |
|
704 // TPtrC16 CNSmlURI::RemoveDotSlash |
|
705 // Returns URI without dot and slash (./) in the beginning. |
|
706 // ----------------------------------------------------------------------------- |
|
707 // |
|
708 TPtrC16 CNSmlURI::RemoveDotSlash( const TDesC& aURI ) const |
|
709 { |
|
710 if ( aURI.FindF( KNSmlAgentRelativeURIPrefix ) == 0 ) |
|
711 { |
|
712 return aURI.Right( aURI.Length() - 2 ); |
|
713 } |
|
714 else |
|
715 { |
|
716 return aURI; |
|
717 } |
|
718 } |
|
719 |
|
720 // ----------------------------------------------------------------------------- |
|
721 // CNSmlURI::ExtractPortFromHostname |
|
722 // Extracts port from hostname (e.g. http://myserver.com:80/syncml). |
|
723 // ----------------------------------------------------------------------------- |
|
724 // |
|
725 void CNSmlURI::ExtractPortFromHostnameL() |
|
726 { |
|
727 TInt startPos( iHostName->LocateReverseF( ':' ) ); |
|
728 |
|
729 if ( startPos == KErrNotFound ) |
|
730 { |
|
731 return; |
|
732 } |
|
733 |
|
734 TInt endPos( (*iHostName).Mid( startPos ).LocateF( '/' ) ); |
|
735 |
|
736 if ( endPos == KErrNotFound ) |
|
737 { |
|
738 endPos = iHostName->Length() - startPos; |
|
739 } |
|
740 |
|
741 HBufC* tempName( HBufC::NewLC( iHostName->Length() ) ); |
|
742 |
|
743 tempName->Des().Append( (*iHostName).Left( startPos ) ); |
|
744 tempName->Des().Append( (*iHostName).Mid( startPos + endPos ) ); |
|
745 |
|
746 TLex lexer( (*iHostName).Mid( startPos + 1, endPos - 1 ) ); |
|
747 |
|
748 lexer.Val( iPort ); |
|
749 |
|
750 delete iHostName; |
|
751 iHostName = tempName; |
|
752 |
|
753 CleanupStack::Pop(); // tempName |
|
754 } |
|
755 |
|
756 // End of File |