First public contribution.
1 // Copyright (c) 2001-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include "TUriCInternal.h"
20 #include <uriutilscommon.h>
22 #include "UriUtilsInternal.h"
23 #include "TValidator.h"
25 #include <escapeutils.h>
31 _LIT(KUriPanicCategory,"URI-BASE");
35 // Implementation of TUriC8
44 EXPORT_C TUriC8::TUriC8()
46 // Reset the component table and the Uri
51 Retrieves the specified component in the uri.
54 @param aComponent The enum specifying the component.
55 @return A constant reference to a descriptor pointer to the specified
58 EXPORT_C const TDesC8& TUriC8::Extract(TUriComponent aComponent) const
60 __ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
62 return iComponent[aComponent];
66 Indicates whether the specified component is present in the uri.
69 @param aComponent The enum specifying the component.
70 @return A boolean value of ETrue if the desired component is present,
71 or EFalse if the desired component is not present.
73 EXPORT_C TBool TUriC8::IsPresent(TUriComponent aComponent) const
75 __ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
77 return TBool(iComponent[aComponent].Ptr());
81 Checks the scheme to be valid. If there is no scheme then the return value
82 indicates an invalid scheme.
85 @return A boolean value of ETrue if the scheme is valid, or EFalse if
88 EXPORT_C TBool TUriC8::IsSchemeValid() const
90 if( !IsPresent(EUriScheme) )
94 return HasValidSchemeChars(iComponent[EUriScheme]);
98 Compares the specified component against the one in the uri passed in.
101 @param aUri The uri to compare components against.
102 @param aComponent The enum specifying the component to compare.
103 @return An integer value of zero if the components are the same,
104 any other value if the components are not the same.
106 EXPORT_C TInt TUriC8::Compare(const TUriC8& aUri, TUriComponent aComponent) const
108 __ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
110 // Does the component exist in both the Uri's
111 if( IsPresent(aComponent) && aUri.IsPresent(aComponent) )
113 if( aComponent == EUriScheme || aComponent == EUriHost )
115 // Do case insensitive compare for scheme and host
116 return (iComponent[aComponent].CompareF(aUri.iComponent[aComponent]));
120 // Do case sensitive compare for all other components
121 return (iComponent[aComponent].Compare(aUri.iComponent[aComponent]));
129 Retrieves the descriptor for the entire uri.
132 @return A const reference to a descriptor pointer to the uri.
134 EXPORT_C const TDesC8& TUriC8::UriDes() const
142 Ensures that all components of the URI are valid. If the method returns
143 KUriUtilsErrInvalidUri then one or more components are not valid. It is
144 possible for URIs declared valid by this method to be, on detailed inspection,
147 @return KErrNone for vaild URIs, KUriUtilsErrInvalidUri for invalid URIs or KErrNotSupported.
149 EXPORT_C TInt TUriC8::Validate() const
151 return DoValidate(*this);
155 Compares the given URI to determine if it is equivalent to this URI. It is possible
156 for URIs declared NOT equivalent by this method to be equvalent to a level not checked
160 @param aUri Contains URI to compare
161 @return ETrue if the two URIs are equivalent otherwise EFalse
163 EXPORT_C TInt TUriC8::Equivalent(const TUriC8& aUri) const
165 TInt result = EFalse;
166 TRAPD(error, result = DoEquivalenceL(*this, aUri));
167 if (error != KErrNone)
175 Retrieves the uri without the fragment component.
178 @param aUriNoFrag An output parameter which is set the non-reference
181 EXPORT_C void TUriC8::UriWithoutFragment(TPtrC8& aUriNoFrag) const
183 if( IsPresent(EUriFragment) )
185 // There is a fragment, find where it starts
186 TInt fragmentStartPos = iUriDes.Locate(KFragmentDelimiter);
187 aUriNoFrag.Set(iUriDes.Left(fragmentStartPos));
190 aUriNoFrag.Set(iUriDes);
195 Create a new HBufC descriptor containing the desired component or the full URI.
197 @param aComponent The component to convert into Unicode (EUriScheme - EUriFragment), or
198 the full URI (EUriComplete -- the default).
199 @return The descriptor containing the desired component.
201 EXPORT_C HBufC* TUriC8::DisplayFormL(TUriComponent aComponent) const
205 if (aComponent == EUriComplete)
207 component.Set(iUriDes);
210 { // extract the specified component, will Panic if invalid
211 component.Set( Extract(aComponent) );
213 // convert descriptor from UTF-8 into Unicode
214 return EscapeUtils::ConvertToUnicodeFromUtf8L(component);
219 Resets the descriptor pointers for the uri components and the uri.
222 @post All uri component information is removed and the uri descriptor is
227 // Set descriptor pointers to NULL and lengths to zero
228 for( TInt i=0; i<EUriMaxComponents; ++i )
230 iComponent[i].Set(NULL,0);
237 // Implementation of TUriC16
244 @deprecated Deprecated in 9.1
246 EXPORT_C TUriC16::TUriC16()
248 // Reset the component table and the Uri
253 Retrieves the specified component in the uri.
256 @deprecated Deprecated in 9.1
257 @param aComponent The enum specifying the component.
258 @return A constant reference to a descriptor pointer to the specified component.
260 EXPORT_C const TDesC16& TUriC16::Extract(TUriComponent aComponent) const
262 __ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
264 return iComponent[aComponent];
268 Indicates whether the specified component is present in the uri.
271 @deprecated Deprecated in 9.1
272 @param aComponent The enum specifying the component.
273 @return A boolean value of ETrue if the desired component is present,
274 or EFalse if the desired component is not present.
276 EXPORT_C TBool TUriC16::IsPresent(TUriComponent aComponent) const
278 __ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
280 return TBool(iComponent[aComponent].Ptr());
284 Checks to see if the scheme is valid. If there is no scheme then the return value
285 indicates an invalid scheme (EFalse).
288 @deprecated Deprecated in 9.1
289 @return A boolean value of ETrue if the scheme is valid, or EFalse if
292 EXPORT_C TBool TUriC16::IsSchemeValid() const
294 if( !IsPresent(EUriScheme) )
298 return HasValidSchemeChars(iComponent[EUriScheme]);
302 Compares the specified component against the one in the uri passed in.
305 @deprecated Deprecated in 9.1
306 @param aUri The uri to compare components against.
307 @param aComponent The enum specifying the component to compare.
308 @return An integer value of zero if the components are the same, any other
309 value if the components are not the same.
311 EXPORT_C TBool TUriC16::Compare(const TUriC16& aUri, TUriComponent aComponent) const
313 __ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
315 // Does the component exist in both the Uri's
316 if( IsPresent(aComponent) && aUri.IsPresent(aComponent) )
318 if( aComponent == EUriScheme || aComponent == EUriHost )
320 // Do case insensitive compare for scheme and host
321 return (iComponent[aComponent].CompareF(aUri.iComponent[aComponent]));
325 // Do case sensitive compare for all other components
326 return (iComponent[aComponent].Compare(aUri.iComponent[aComponent]));
334 Retrieves the descriptor for the entire uri.
337 @deprecated Deprecated in 9.1
338 @return A const reference to a descriptor pointer to the uri.
340 EXPORT_C const TDesC16& TUriC16::UriDes() const
346 @deprecated Deprecated in 9.1 -- provided for compatibility
348 Ensures that all components of the URI are valid. If the method returns
349 KUriUtilsErrInvalidUri then one or more components are not valid. It is possible
350 for URIs declared valid by this method to be, on detailed inspection, invalid.
352 @return KErrNone for vaild URIs, KUriUtilsErrInvalidUri for invalid URIs or KErrNotSupported.
354 EXPORT_C TInt TUriC16::Validate() const
356 TInt result = KErrNone;
357 TRAPD(error, result = ValidateL());
360 // problem allocating resourses
367 @deprecated Deprecated in 9.1 -- provided for compatibility
369 Compares the given URI to determine if it is equivalent to this URI. It is possible
370 for URIs declared NOT equivalent by this method to be equvalent to a level not checked
372 @param aUri Contains URI to compare
373 @return ETrue if the two URIs are equivalent otherwise EFalse
375 EXPORT_C TInt TUriC16::Equivalent(const TUriC16& aUri) const
377 TInt result = KErrNone;
378 TRAPD(error, result = EquivalentL(aUri.UriDes()));
381 // problem allocating resourses
387 Retrieves the uri without the fragment component.
390 @deprecated Deprecated in 9.1
391 @param aUriNoFrag An output parameter which is set the non-reference
395 EXPORT_C void TUriC16::UriWithoutFragment(TPtrC16& aUriNoFrag) const
397 if( IsPresent(EUriFragment) )
399 // There is a fragment, find where it starts
400 TInt fragmentStartPos = iUriDes.Locate(KFragmentDelimiter);
401 aUriNoFrag.Set(iUriDes.Left(fragmentStartPos));
404 aUriNoFrag.Set(iUriDes);
409 Create a new HBufC descriptor containing the desired component or the full URI.
410 @deprecated Deprecated in 9.1 - provided for compatibility
412 @param aComponent The component to convert into Unicode (EUriScheme - EUriFragment), or
413 the full URI (EUriComplete -- the default).
414 @return The descriptor containing the desired component.
416 EXPORT_C HBufC* TUriC16::DisplayFormL(TUriComponent aComponent) const
418 if ( aComponent == EUriComplete) // extract the full URI
420 return iUriDes.AllocL();
422 return Extract(aComponent).AllocL();
427 Resets the descriptor pointers for the uri components and the uri.
430 @post All uri component information is removed and the uri descriptor is
433 void TUriC16::Reset()
435 // Set descriptor pointers to NULL and lengths to zero
436 for( TInt i=0; i<EUriMaxComponents; ++i )
438 iComponent[i].Set(NULL,0);
444 @deprecated Deprecated in 9.1
446 Ensures that all components of the URI are valid. If the method returns
447 KUriUtilsErrInvalidUri then one or more components are not valid. It is possible
448 for URIs declared valid by this method to be, on detailed inspection, invalid.
450 @return KErrNone for vaild URIs, KUriUtilsErrInvalidUri for invalid URIs or KErrNotSupported.
452 TInt TUriC16::ValidateL() const
456 HBufC8* uri8 = CreateUri8LC(UriDes());
457 TUriParser8 uriParser;
458 if(uriParser.Parse(*uri8) != KErrNone)
460 result = KUriUtilsErrInvalidUri;
464 result = DoValidate(uriParser);
467 CleanupStack::PopAndDestroy(uri8);
472 @deprecated Deprecated in 9.1
474 Compares the given URI to determine if it is equivalent to this URI. It is possible
475 for URIs declared NOT equivalent by this method to be equvalent to a level not checked
477 @param aUri Contains URI to compare
478 @return ETrue if the two URIs are equivalent otherwise EFalse
480 TBool TUriC16::EquivalentL(const TDesC16& aUri) const
482 HBufC8* lhs = CreateUri8LC(UriDes());
483 HBufC8* rhs = CreateUri8LC(aUri);
485 TUriParser8 lhsParser;
486 if(lhsParser.Parse(*lhs) != KErrNone)
488 User::Leave(KUriUtilsErrInvalidUri);
491 TUriParser8 rhsParser;
492 if(rhsParser.Parse(*rhs) != KErrNone)
494 User::Leave(KUriUtilsErrInvalidUri);
497 TBool result = DoEquivalenceL(lhsParser, rhsParser);
499 CleanupStack::PopAndDestroy(2);
505 // Implementation of LOCAL functions
510 Checks the scheme for invalid characters. The scheme is invalid if it is empty.
513 @param aScheme The descriptor with the scheme.
514 @return A boolean value of ETrue if all the characters in the scheme
515 are valid, otherwise EFalse.
517 template<class TPtrCType>
518 LOCAL_C TBool HasValidSchemeChars(const TPtrCType& aScheme)
520 TInt length = aScheme.Length();
521 TBool valid = ( length && TChar(aScheme[0]).IsAlpha() );
523 // Start checking from the second character
525 while( valid && i<length )
527 TChar c = aScheme[i];
528 valid = c.IsAlphaDigit() || c==KPlusChar || c==KMinusChar || c==KPeriodChar;
537 // File URI Implementation - CUri8
540 #ifdef __SECURE_DATA__
542 Generates a fully-qualified filename from a file URI object.
544 The form of the returned filename depends on the file location, as follows:
545 - public file on a fixed drive:
547 file://c/path/to/file/name.ext -> c:\path\to\file\name.ext
550 - public file on removable media drive:
551 The fully-qualified filename is resolved by finding the first drive on which the file exists.
552 If the file does not exist, this will Leave with KErrNotFound
554 file://ext-media/path/to/file/name.ext -> f:\path\to\file\name.ext
556 (where f: is the first drive found containing "\path\to\file\name.ext")
558 - private file on fixed drive:
560 file://private/c/path/to/file/name.ext -> c:\private\0x1001234f\path\to\file\name.ext
562 (where 0x1001234f is the SID of the current application)
564 - private file on removable media drive:
566 file://private/ext-media/path/to/file/name.ext -> h:\private\0x1001234f\path\to\file\name.ext
568 (where h: is the first drive found containing "\private\0x1001234f\path\to\file\name.ext")
570 The returned file name is not guaranteed to exist except where specified above.
572 Be warned that this method may be slow when resolving special paths (like "/ext-media")
574 @leave KErrNotSupported URI does not specify a local file
575 @leave KErrNotFound If the URI indicates the file is on removable media and the file does not exist on any.
577 @return A descriptor containing the fully-qualified filename.
578 @pre Object is fully constructed.
582 Generates a fully-qualified filename from a file URI object.
584 The form of the returned filename depends on the file location, as follows:
585 - public file on a fixed drive:
587 file://c/path/to/file/name.ext -> c:\path\to\file\name.ext
590 - public file on removable media drive:
591 The fully-qualified filename is resolved by finding the first drive on which the file exists.
592 If the file does not exist, this will Leave with KErrNotFound
594 file://ext-media/path/to/file/name.ext -> f:\path\to\file\name.ext
596 (where f: is the first drive found containing "\path\to\file\name.ext")
598 The returned file name is not guaranteed to exist except where specified above.
600 Be warned that this method may be slow when resolving special paths (like "/ext-media")
602 @leave KErrNotSupported URI does not specify a local file
603 @leave KErrNotFound If the URI indicates the file is on removable media and the file does not exist on any.
605 @return A descriptor containing the fully-qualified filename.
606 @pre Object is fully constructed.
609 EXPORT_C HBufC* TUriC8::GetFileNameL() const
611 return GetFileNameL(EUriFileNameFull);
616 This creates a file name from the URI, changing the network path separator (/) to the
617 local file system path separator (\\).
619 If called with EUriFileNamePath, this will generate a file name containing the path relative to the drive.
620 Any parameters in the URI are stripped off:
622 http://www.foo.com/dir/file/name.ext;param1;param2 -> \dir\file\name.ext
625 If called with EUriFileNameTail, this will generate a just the name, with no directories or drive.
626 Any parameters in the URI are stripped off:
628 http://www.foo.com/dir/file/name.ext;param1;param2 -> name.ext
631 EUriFileNamePath and EUriFileNameTail can be used for any hierarchical URI (http, ftp, file, etc)
632 and may have unexpected behaviour when called on any other type of URI.
634 If called with EUriFileNameFull, this will convert the URI into a fully-qualified filename. this is only valid
635 for file URIs and will Leave if called on any other type of URI. The form of the returned filename is described in
636 GetFileNameL with no arguments.
638 @leave KErrNotSupported The URI scheme cannot be converted into the desired type
640 @pre Object is fully constructed.
641 @param aType specifies what part of the filename is to be converted. The default is EUriFileNameFull).
642 @return A descriptor containing the desired filename components.
644 EXPORT_C HBufC* TUriC8::GetFileNameL(TUriFileName aType) const
646 TBool isFileUri = Extract(EUriScheme).Compare(KFileUriScheme8) == 0;
647 if(aType == EUriFileNameFull && !isFileUri)
649 User::Leave(KErrNotSupported);
651 return ResolveFileNameL(Extract(EUriPath), aType, isFileUri);
657 // File URI Implementation - CUri16
661 #ifdef __SECURE_DATA__
663 Generates a fully-qualified filename from a file URI object.
665 The form of the returned filename depends on the file location, as follows:
666 - public file on a fixed drive:
668 file://c/path/to/file/name.ext -> c:\path\to\file\name.ext
671 - public file on removable media drive:
672 The fully-qualified filename is resolved by finding the first drive on which the file exists.
673 If the file does not exist, this will Leave with KErrNotFound
675 file://ext-media/path/to/file/name.ext -> f:\path\to\file\name.ext
677 (where f: is the first drive found containing "\path\to\file\name.ext")
679 - private file on fixed drive:
681 file://private/c/path/to/file/name.ext -> c:\private\0x1001234f\path\to\file\name.ext
683 (where 0x1001234f is the SID of the current application)
685 - private file on removable media drive:
687 file://private/ext-media/path/to/file/name.ext -> h:\private\0x1001234f\path\to\file\name.ext
689 (where h: is the first drive found containing "\private\0x1001234f\path\to\file\name.ext")
691 The returned file name is not guaranteed to exist except where specified above.
693 Be warned that this method may be slow when resolving special paths (like "/ext-media")
695 @leave KErrNotSupported URI does not specify a local file
696 @leave KErrNotFound If the URI indicates the file is on removable media and the file does not exist on any.
698 @return A descriptor containing the fully-qualified filename.
699 @pre Object is fully constructed.
704 Generates a fully-qualified filename from a file URI object.
706 The form of the returned filename depends on the file location, as follows:
707 - public file on a fixed drive:
709 file://c/path/to/file/name.ext -> c:\path\to\file\name.ext
712 - public file on removable media drive:
713 The fully-qualified filename is resolved by finding the first drive on which the file exists.
714 If the file does not exist, this will Leave with KErrNotFound
716 file://ext-media/path/to/file/name.ext -> f:\path\to\file\name.ext
718 (where f: is the first drive found containing "\path\to\file\name.ext")
720 The returned file name is not guaranteed to exist except where specified above.
722 Be warned that this method may be slow when resolving special paths (like "/ext-media")
724 @leave KErrNotSupported URI does not specify a local file
725 @leave KErrNotFound If the URI indicates the file is on removable media and the file does not exist on any.
727 @return A descriptor containing the fully-qualified filename.
728 @pre Object is fully constructed.
732 EXPORT_C HBufC* TUriC16::GetFileNameL() const
734 return GetFileNameL(EUriFileNameFull);
739 This creates a file name from the URI, changing the network path separator (/) to the
740 local file system path separator (\\).
742 If called with EUriFileNamePath, this will generate a file name containing the path relative to the drive.
743 Any parameters in the URI are stripped off:
745 http://www.foo.com/dir/file/name.ext;param1;param2 -> \dir\file\name.ext
748 If called with EUriFileNameTail, this will generate a just the name, with no directories or drive.
749 Any parameters in the URI are stripped off:
751 http://www.foo.com/dir/file/name.ext;param1;param2 -> name.ext
754 EUriFileNamePath and EUriFileNameTail can be used for any hierarchical URI (http, ftp, file)
755 and may have unexpected behaviour when called on any other type of URI.
757 If called with EUriFileNameFull, this will convert the URI into a fully-qualified filename. this is only valid
758 for file URIs and will Leave if called on any other type of URI. The form of the returned filename is described in
759 GetFileNameL with no arguments.
761 @leave KErrNotSupported The URI scheme cannot be converted into the desired type
763 @pre Object is fully constructed.
764 @param aType specifies what part of the filename is to be converted. The default is (EUriFileNameFull).
765 @return A descriptor containing the desired filename components.
767 EXPORT_C HBufC* TUriC16::GetFileNameL(TUriFileName aType) const
769 TBool isFileUri = Extract(EUriScheme).Compare(KFileUriScheme16) == 0;
771 if(aType == EUriFileNameFull && !isFileUri )
773 User::Leave(KErrNotSupported);
776 HBufC8* fileUriPath8 = HBufC8::NewLC(Extract(EUriPath).Length());
777 fileUriPath8->Des().Copy(Extract(EUriPath));
778 HBufC* absFileName = ResolveFileNameL(*fileUriPath8, aType, isFileUri);
779 CleanupStack::PopAndDestroy(fileUriPath8);
786 // Implementation of LOCAL functions
791 Function used to convert '\' to '/' and vice versa.
794 @param aDesPtr A descriptor reference to the string.
795 @param aPathSeperatorFrom A path seperator to be converted (from)
796 @param aPathSeperatorTo A path seperator to converte (To).
798 void ChangePathSeparator(TDes& aDesPtr, TUint aPathSeperatorFrom, TUint aPathSeperatorTo)
800 for(TInt offset = aDesPtr.Length() - 1;offset >= 0;offset--)
802 if (aDesPtr[offset] == aPathSeperatorFrom)
804 aDesPtr[offset] = TUint16(aPathSeperatorTo);
810 Function used to generate a fully qualified file name for a public or private file
811 stored on a fix drive or a removable media drive from File URI path (parameter aFileUriPath).
813 This will be called by API GetFileName() to generate and return a filename.
815 @leave KErrBadName if the path doesn't contain valid drivename.
817 @param aFileUriPath A descriptor reference to the File URI's path component.
818 @return A pointer to a buffer containing the resolved fully qualified filename
819 if the file uri path is not empty or a top level dir on main drive (C:\\)
821 HBufC* GetFullFileNameFromFileUriPathL(const TDesC& aFileUriPath)
823 TFileName filename(KDefaultPath);
825 TInt origLength = aFileUriPath.Length();
828 return filename.AllocL();
832 TPtrC fileUriPath(aFileUriPath);
834 //skip KUriPathSeparator (/) from the Uri path
835 if (fileUriPath[0] == KUriPathSeparator)
840 fileUriPath.Set(aFileUriPath.Right(origLength - index));
843 TBool fsOpen = EFalse;
845 #ifdef __SECURE_DATA__
846 if (fileUriPath.Left(KPrivate().Length()).Compare(KPrivate) == 0)
848 index += KPrivate().Length();
849 User::LeaveIfError(fs.Connect());
850 CleanupClosePushL(fs);
852 User::LeaveIfError(fs.PrivatePath(filename));
853 filename.Insert(0, KDefaultPath().Left((KDefaultPath().Length() - 1) )); //Insert <drive>:
854 fileUriPath.Set(aFileUriPath.Right(origLength - index));
858 TBool isExtMedia = (fileUriPath.Left(KExtMedia().Length()).Compare(KExtMedia) == 0);
861 TUint driveLetter = fileUriPath[0];
862 //Checking for valid driveletter (should between A to Z or a to z) and followed by Uri path seperator "/"
863 if ( fileUriPath[1] != KUriPathSeparator ||
864 ( (driveLetter < 'A' || driveLetter > 'Z') &&
865 (driveLetter < 'a' || driveLetter > 'z') ) )
867 User::Leave(KErrBadName);
869 index += (KDefaultPath().Length() - 1); //skip <driveLetter>/
870 filename[0] = TUint16(driveLetter);
874 index += KExtMedia().Length();
877 filename.Append(aFileUriPath.Right(origLength - index));
880 ChangePathSeparator(filename, KUriPathSeparator, KFilePathSeparator);
884 if (fsOpen == EFalse)
886 User::LeaveIfError(fs.Connect());
887 CleanupClosePushL(fs);
891 TDriveInfo driveInfo;
892 TInt err = KErrNotFound;
894 for (TInt driveNum = EDriveA; driveNum <= EDriveZ && err!=KErrNone; driveNum++)
896 if (fs.Drive(driveInfo, driveNum ) == KErrNone
897 && (driveInfo.iDriveAtt & KDriveAttRemovable))
899 filename[0]= TInt16('A' + driveNum);
901 err = fs.Att(filename, attValue);
904 User::LeaveIfError(err);
909 CleanupStack::PopAndDestroy(&fs);
912 return filename.AllocL();
916 Creates an 8 bit URI descriptor from an 16 bit one
918 @param aBuf16 The full 16 bit URI descriptor
919 @return Pointer to the newly created 8 bit URI descriptor
920 are valid, otherwise EFalse.
922 HBufC8* CreateUri8LC(const TDesC16& aBuf16)
924 TInt length = aBuf16.Length();
925 HBufC8* newBuf = HBufC8::NewMaxLC(length);
926 TPtr8 des8Ptr = newBuf->Des();
927 for (TInt i = 0; i < length; ++i)
929 des8Ptr[i] = static_cast<TText8>(aBuf16[i]);
935 Check the components of a URI to ensure they are all valid
938 @param aUri The URI to check
939 @return KErrNone if all components are valid, otherwise one of the 'invalid' error codes
941 TInt DoValidate(const TUriC8& aUri)
944 TPtrC8 subComponent(aUri.Extract(EUriScheme));
945 if (!HasValidSchemeChars(subComponent))
947 result = KUriUtilsErrInvalidScheme;
949 else if(SchemeType(subComponent) == ESchemeTypeSip)
950 //To validate Sip uri
952 TValidatorSip validator(aUri);
953 result = validator.Validate();
955 else if(SchemeType(subComponent) == ESchemeTypeTel)
956 //To validate Tel uri
958 TValidatorTel validator(aUri);
959 result = validator.Validate();
963 result = KErrNotSupported;
970 Compare the components of two URIs to see if they identify the same resource
973 @param aLhs The left hand side URI to compare
974 @param aRhs The right hand side URI to compare
975 @return ETrue if they point to the same resource, EFalse otherwise.
977 TInt DoEquivalenceL(const TUriC8& aLhs, const TUriC8& aRhs)
980 if (SchemeType(aLhs.Extract(EUriScheme)) == ESchemeTypeSip)
982 TEquivSip equiv(aLhs, aRhs);
983 result = equiv.EquivalentL();
987 // unknown scheme so assume network scheme
988 TEquiv equiv(aLhs, aRhs);
989 result = equiv.EquivalentL();
997 Get the desired part of the filename from the URI path
999 @param aPath A descriptor reference to the File URI's path component.
1000 @param aType enum value of TUriFileName.
1001 @param aIsFileUri Specifies the whether it is FileUri or not.
1002 @return Pointer to the newly created URI descriptor which contains the
1003 desired part of the filename from the URI path.
1005 HBufC* ResolveFileNameL(const TDesC8& aPath, TUriFileName aType, TBool aIsFileUri)
1008 HBufC8* fileUriPath8 = EscapeUtils::EscapeDecodeL(aPath);
1009 CleanupStack::PushL(fileUriPath8);
1011 // convert to unicode
1012 HBufC* fileUriPath = EscapeUtils::ConvertToUnicodeFromUtf8L(*fileUriPath8);
1013 CleanupStack::PopAndDestroy(fileUriPath8);
1014 CleanupStack::PushL(fileUriPath);
1016 HBufC* absFileName = NULL; // setting to NULL makes compiler happy
1019 /* awlays do full conversion for file URIs
1020 It's not optimal time-wise, but it uses the least code and is
1021 forward-compatible. */
1022 absFileName = GetFullFileNameFromFileUriPathL(*fileUriPath);
1023 CleanupStack::PopAndDestroy(fileUriPath);
1024 if ( aType == EUriFileNameFull )
1028 fileUriPath = absFileName; // code below uses fileUriPath
1029 CleanupStack::PushL(fileUriPath);
1030 TPtr path(fileUriPath->Des());
1031 path.Delete(0,2); // delete drive and ':' (always begins with drive letter and :)
1033 else // not a file URI
1034 { // convert '/' to '\' for all other URIs
1035 TPtr path(fileUriPath->Des());
1036 ChangePathSeparator(path, KUriPathSeparator, KFilePathSeparator);
1039 // EUriFileNameFull must only ever be used with a file URI. Failures should be caught by the caller
1040 __ASSERT_DEBUG(aType != EUriFileNameFull,
1041 User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
1044 GetFileComponent(name, *fileUriPath, aType ); // get path or tail
1045 if (name.Length() == fileUriPath->Length())
1046 { // no changes, just return fileUriPath
1047 absFileName = fileUriPath;
1048 CleanupStack::Pop(fileUriPath);
1052 absFileName = name.AllocL();
1053 CleanupStack::PopAndDestroy(fileUriPath);
1060 Gets the desired file path or tail.
1062 @param aNewName An outparameter, reference to descriptor .
1063 @param aOldName An inparameter descriptor reference.
1064 @param aType enum value of TUriFileName.
1066 void GetFileComponent(TPtrC& aNewName, const TDesC& aOldName, TUriFileName aType )
1068 __ASSERT_ALWAYS(aType != EUriFileNameFull, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
1070 aNewName.Set(aOldName);
1071 // chop off everything after the first ;
1072 TInt pos = aNewName.Locate(KParamDelimiter);
1073 if( pos == 0 ) // the ; is at the start
1075 aNewName.Set(KNullDesC);
1078 { // set to the text untilt he ;
1079 aNewName.Set(aNewName.Left(pos));
1081 if( aType == EUriFileNameTail)
1083 // chop off everything before the last /
1084 TInt pos = aNewName.LocateReverse(KFilePathSeparator);
1085 if( pos >=0 ) // there is a /
1087 if( pos >= aNewName.Length() - 1 ) // the / is at the end
1089 aNewName.Set(KNullDesC);
1092 { // set to the text following the last /
1093 aNewName.Set(aNewName.Right(aNewName.Length()-1-pos));