upnp/upnpstack/upnputils/src/upnpfileutils.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2005-2006 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:  File utils
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include <e32base.h>
       
    21 #include <charconv.h>
       
    22 #include <f32file.h>
       
    23 #include <apgcli.h>
       
    24 #include <apmrec.h>
       
    25 #include <sysutil.h>
       
    26 #define KLogFile _L("DLNAWebServer.txt")
       
    27 #include "upnpcustomlog.h"
       
    28 #include "upnpcons.h"
       
    29 #include "upnpfileutils.h"
       
    30 #include "upnpstring.h"
       
    31 #include "uri8.h"
       
    32 #include "in_sock.h"
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 namespace UpnpFileUtil
       
    36     {
       
    37     // -----------------------------------------------------------------------------
       
    38     // UpnpFileUtil::ReadFileL
       
    39     // Reads the specified file and returns a pointer to HBufC8 holding the 
       
    40     // information.
       
    41     // -----------------------------------------------------------------------------
       
    42     //
       
    43     EXPORT_C HBufC8* ReadFileL(const TDesC16& aFilename)
       
    44         {
       
    45         LOGS1("UpnpFileUtil::ReadFileL - File: %S", &aFilename);
       
    46 
       
    47         RFs fs;
       
    48         HBufC8* buffer = NULL;
       
    49         TInt error = fs.Connect();
       
    50         if ( error == KErrNone )
       
    51             {
       
    52             CleanupClosePushL( fs );
       
    53 
       
    54             RFile file;
       
    55             error = file.Open(fs, aFilename, EFileRead|EFileShareAny );
       
    56             if ( error == KErrNone )
       
    57                 {
       
    58                 CleanupClosePushL( file );
       
    59 
       
    60                 TInt fileSize;
       
    61                 error = file.Size(fileSize);
       
    62                 if ( error == KErrNone )
       
    63                     {
       
    64                     buffer = HBufC8::NewLC(fileSize);
       
    65                     buffer->Des().SetLength(0);
       
    66 
       
    67                     TPtr8 ptr = buffer->Des();
       
    68                     error = file.Read( ptr );
       
    69                     if ( error == KErrNone )
       
    70                         {
       
    71                         CleanupStack::Pop( buffer );
       
    72                         }
       
    73                     else
       
    74                         {
       
    75                         CleanupStack::PopAndDestroy( buffer );
       
    76                         buffer = NULL;
       
    77                         }
       
    78                     }
       
    79 
       
    80                 // Close File
       
    81                 CleanupStack::PopAndDestroy(); 
       
    82                 }
       
    83             else
       
    84                 {
       
    85                 LOGS1("UpnpFileUtil::ReadFileL - RFile::Open() failed: %d", error);
       
    86                 }
       
    87 
       
    88             // Close FS
       
    89             CleanupStack::PopAndDestroy(); 
       
    90             }
       
    91         else
       
    92             {
       
    93             LOGS1("UpnpFileUtil::ReadFileL - RFs::Connect() failed: %d", error );
       
    94             }
       
    95 
       
    96         // In case of an error, we leave as error would mean that the 
       
    97         // file system is down. Shouldn't fail in any other case.
       
    98         User::LeaveIfError( error );
       
    99 
       
   100         return buffer;
       
   101         }
       
   102 
       
   103     // -----------------------------------------------------------------------------
       
   104     // UpnpFileUtil::GetMimeTypeForFileL
       
   105     // - In emulator, checks the filename, and returns mimetype-string depending 
       
   106     //   on extension.
       
   107     // - In Target device, uses RApaLsSession (Application server) to find out 
       
   108     //   file's mime type.
       
   109     // -----------------------------------------------------------------------------
       
   110     //
       
   111     EXPORT_C HBufC8* GetMimeTypeForFileL(const TDesC16& aFilename)
       
   112         {
       
   113         LOGS1("UpnpFileUtil::GetMimeTypeForFileL - Getting mime type for file: %S", &aFilename);
       
   114 
       
   115         HBufC8* mimetype = NULL;
       
   116 
       
   117         // Added extra functionality, due to DLNA requirements for XML files mime type.
       
   118         // In mime type for xml files there should be explicitly defined used charset
       
   119         // and RApaLsSession service doesn't provide such a functionality.
       
   120 
       
   121         // Check extension, if its .xml - set mime type to text/xml and check used encoding
       
   122         _LIT8(KXmlUtf8, "text/xml; charset=\"utf-8\"");
       
   123         TParse parse;
       
   124         parse.Set( aFilename, NULL, NULL );
       
   125         TBufC16<KMaxName> ext( parse.Ext() );
       
   126 
       
   127         if ( ext.FindC( KXml16 ) == 0 && ext.Length() == KXml16().Length() )
       
   128             {
       
   129             // Extension says that's XML but we check content to be sure and get encoding
       
   130             
       
   131 
       
   132             mimetype = HBufC8::NewL( KXmlUtf8().Length() );
       
   133             mimetype->Des().Zero();
       
   134             mimetype->Des().Append( KXmlUtf8() );
       
   135             return mimetype;
       
   136             }
       
   137 
       
   138         // If it's not a XML file then use built-in service.
       
   139 
       
   140         RApaLsSession sess;
       
   141         TInt error = sess.Connect();
       
   142         // We have FS, File and RApaLs open
       
   143         if ( error == KErrNone )
       
   144             {
       
   145             CleanupClosePushL( sess );
       
   146 
       
   147             TUid id = TUid::Uid( 0 );
       
   148 
       
   149             TDataType type;
       
   150 
       
   151             error = sess.AppForDocument( aFilename, id, type );
       
   152             if( error == KErrNone && type != TDataType())
       
   153                 {
       
   154                 mimetype = HBufC8::NewL( type.Des8().Length() + UpnpString::KLineFeed().Length() );
       
   155                 mimetype->Des().Append( type.Des8() );
       
   156                 }
       
   157             else
       
   158                 {
       
   159                 error = KErrNotFound;
       
   160                 LOGS1("UpnpFileUtil::GetMimeTypeForFileL - AppForDocument failed: %d", error );
       
   161                 }
       
   162 
       
   163             CleanupStack::PopAndDestroy( &sess );
       
   164             }
       
   165         else
       
   166             {
       
   167             LOGS1("UpnpFileUtil::GetMimeTypeForFileL - RFile::Open failed: %d", error );
       
   168             }
       
   169 
       
   170         if( error != KErrNone)
       
   171             {
       
   172             mimetype = GetMimeTypeByExtensionL( aFilename );
       
   173             }
       
   174 
       
   175         LOGS("UpnpFileUtil::GetMimeTypeForFileL - MIME type resolved: " );
       
   176         LOGT( mimetype->Des() );
       
   177 
       
   178         return mimetype;
       
   179         }
       
   180 
       
   181     // -----------------------------------------------------------------------------
       
   182     // UpnpFileUtil::GetMimeTypeByExtensionL
       
   183     // - In emulator, checks the filename, and returns mimetype-string depending 
       
   184     //   on extension.
       
   185     // - In Target device, uses RApaLsSession (Application server) to find out 
       
   186     //   file's mime type.
       
   187     // -----------------------------------------------------------------------------
       
   188     //
       
   189     HBufC8* GetMimeTypeByExtensionL( const TDesC16& aFilename )
       
   190         {
       
   191         LOGS("UpnpFileUtil::GetMimeTypeForFileL - Starting search by file extension");
       
   192 
       
   193         HBufC8* mimetype = NULL;
       
   194 
       
   195         TParse parse;
       
   196 
       
   197         parse.Set( aFilename, NULL, NULL );
       
   198 
       
   199         TBufC16<KMaxName> ext( parse.Ext() );
       
   200 
       
   201         // FindC and length calculation is used,
       
   202         // beacause compareC does not work for undefined reason  
       
   203 
       
   204         if ( ext.FindC( KHtml16 ) == 0 && ext.Length() == KHtml16().Length() )
       
   205             {
       
   206             mimetype = HBufC8::NewLC( KHtml().Length() );
       
   207             mimetype->Des().Zero();
       
   208             mimetype->Des().Append( KHtml() );
       
   209             }
       
   210         else if ( ext.FindC( KXml16 ) == 0 && ext.Length() == KXml16().Length() )
       
   211             {
       
   212             mimetype = HBufC8::NewLC( KXml().Length() );
       
   213             mimetype->Des().Zero();
       
   214             mimetype->Des().Append( KXml() );
       
   215             }
       
   216         else if ( ext.FindC( KTxt16 ) == 0 && ext.Length() == KTxt16().Length() )
       
   217             {
       
   218             mimetype = HBufC8::NewLC( KTxt().Length() );
       
   219             mimetype->Des().Zero();
       
   220             mimetype->Des().Append( KTxt() );
       
   221             }
       
   222         else if ( ( ext.FindC( KJpg16 ) == 0 && ext.Length() == KJpg16().Length() ) ||
       
   223                 ( ext.FindC( KJpeg16 ) == 0 && ext.Length() == KJpeg16().Length() ) )
       
   224             {
       
   225             mimetype = HBufC8::NewLC( KJpg().Length() );
       
   226             mimetype->Des().Zero();
       
   227             mimetype->Des().Append( KJpg() );
       
   228             }
       
   229         else if ( ext.FindC( KGif16 ) == 0 && ext.Length() == KGif16().Length() )
       
   230             {
       
   231             mimetype = HBufC8::NewLC( KGif().Length() );
       
   232             mimetype->Des().Zero();
       
   233             mimetype->Des().Append( KGif() );
       
   234             }
       
   235         else if ( ext.FindC( KPng16 ) == 0 && ext.Length() == KPng16().Length() )
       
   236             {
       
   237             mimetype = HBufC8::NewLC( KPng().Length() );
       
   238             mimetype->Des().Zero();
       
   239             mimetype->Des().Append( KPng() );
       
   240             }
       
   241         else if ( ( ext.FindC( KMpg16 ) == 0 && ext.Length() == KMpg16().Length() ) ||
       
   242                 ( ext.FindC( KMpeg16 ) == 0 && ext.Length() == KMpeg16().Length() ) )
       
   243             {
       
   244             mimetype = HBufC8::NewLC( KMpeg().Length() );
       
   245             mimetype->Des().Zero();
       
   246             mimetype->Des().Append( KMpeg() );
       
   247             }
       
   248         else if ( ext.FindC( KAvi16 ) == 0 && ext.Length() == KAvi16().Length() )
       
   249             {
       
   250             mimetype =HBufC8::NewLC( KAvi().Length() );
       
   251             mimetype->Des().Zero();
       
   252             mimetype->Des().Append( KAvi() );
       
   253             }
       
   254         else if ( ext.FindC( KMp316 ) == 0 && ext.Length() == KMp316().Length() )
       
   255             {
       
   256             mimetype = HBufC8::NewLC( KMp3().Length() );
       
   257             mimetype->Des().Zero();
       
   258             mimetype->Des().Append( KMp3() );
       
   259             }
       
   260 
       
   261         // If type was not found, then set empty it here
       
   262         if ( !mimetype )
       
   263             {
       
   264             // We can't return mimetype=NULL;
       
   265             
       
   266             // Allocate one lenght mime.
       
   267             mimetype = HBufC8::NewLC( 1 );
       
   268             }
       
   269         CleanupStack::Pop( mimetype );
       
   270 
       
   271         return mimetype;
       
   272         }
       
   273 
       
   274     // -----------------------------------------------------------------------------
       
   275     // ExtractNumFromIP
       
   276     // -----------------------------------------------------------------------------
       
   277     //    
       
   278     TInt ExtractNumFromIP(TPtrC8 ippart)
       
   279         {
       
   280 
       
   281         TInt ipdef=KIPNumMin;
       
   282         TLex8 lexip = TLex8(ippart);
       
   283         TInt errorip = lexip.Val(ipdef);
       
   284 
       
   285         if (errorip == KErrNone)
       
   286         return ipdef;
       
   287         else
       
   288         return KErrNotFound;
       
   289 
       
   290         }
       
   291     // -----------------------------------------------------------------------------
       
   292     // Returns drive number
       
   293     // -----------------------------------------------------------------------------
       
   294     //
       
   295     TInt DriveNumberFromPath( const TDesC16& aPath, RFs& aFs )
       
   296         {
       
   297         TInt drive_num;
       
   298         TParse p;
       
   299         p.Set( aPath, NULL, NULL );
       
   300         TPtrC pointer = p.Drive();
       
   301         TLex lineParser( pointer.Ptr() );
       
   302         TChar ch = lineParser.Get();
       
   303 
       
   304         //sets the default drive or the found value
       
   305         if( aFs.CharToDrive( ch, drive_num )<KErrNone )
       
   306             {
       
   307             drive_num=EDriveC;
       
   308             }
       
   309         return drive_num;
       
   310         }
       
   311 
       
   312     // -----------------------------------------------------------------------------
       
   313     // ExtractUrlPathHost
       
   314     // -----------------------------------------------------------------------------
       
   315     //
       
   316     TBool ExtractUrlPathHost(const TDesC8& aUrl, TInt& aParseError )
       
   317         {
       
   318         TUriParser8 up;
       
   319         aParseError = up.Parse(aUrl);
       
   320         if ( aParseError != KErrNone )
       
   321             {
       
   322             return EFalse;
       
   323             }
       
   324 
       
   325         TPtrC8 hostt(up.Extract(EUriHost));
       
   326         TInt posOfFirstDot( 0 );
       
   327         TInt posOfSecondDot( 0 );
       
   328         TInt posOfThirdDot( 0 );
       
   329 
       
   330         posOfFirstDot = hostt.FindC( UpnpString::KDot8() );
       
   331 
       
   332         //position of the first dot in IP address must be from 1 to 3
       
   333         if( (posOfFirstDot < KErrNone ) || ((posOfFirstDot> 3 ) || (posOfFirstDot < 1)))
       
   334             {
       
   335             return EFalse;
       
   336             }
       
   337         else
       
   338             {
       
   339             TPtrC8 ip1;
       
   340             ip1.Set( hostt.Left( posOfFirstDot));
       
   341 
       
   342             TInt ip1def = ExtractNumFromIP(ip1);
       
   343 
       
   344             if ((ip1def> KIPNumMax) || (ip1def < KIPNumMin ))
       
   345                 {
       
   346                 return EFalse;
       
   347                 }
       
   348 
       
   349             hostt.Set(hostt.Mid(posOfFirstDot + UpnpString::KDot8().Length()));
       
   350             posOfSecondDot = hostt.FindC( UpnpString::KDot8() );
       
   351 
       
   352             //position of the dot in IP address must from 1 to 3 starting from the position of former dot
       
   353             if( (posOfSecondDot < KErrNone) || ((posOfSecondDot> 3 ) || (posOfSecondDot < 1)))
       
   354                 {
       
   355                 return EFalse;
       
   356                 }
       
   357             else
       
   358                 {
       
   359                 TPtrC8 ip2;
       
   360                 ip2.Set( hostt.Left( posOfSecondDot));
       
   361 
       
   362                 ip1def = ExtractNumFromIP(ip2);
       
   363 
       
   364                 if ((ip1def == KErrNotFound) || (ip1def> KIPNumMax))
       
   365                     {
       
   366                     return EFalse;
       
   367                     }
       
   368 
       
   369                 hostt.Set(hostt.Mid(posOfSecondDot + UpnpString::KDot8().Length()));
       
   370                 posOfThirdDot = hostt.FindC( UpnpString::KDot8() );
       
   371 
       
   372                 //position of the dot in IP address must from 1 to 3 starting from the position of former dot					
       
   373                 if( (posOfThirdDot < KErrNone ) || ((posOfThirdDot> 3 ) || (posOfThirdDot < 1)))
       
   374                     {
       
   375                     return EFalse;
       
   376                     }
       
   377                 else
       
   378                     {
       
   379                     TPtrC8 ip3;
       
   380                     ip3.Set( hostt.Left( posOfThirdDot));
       
   381 
       
   382                     ip1def = ExtractNumFromIP(ip3);
       
   383 
       
   384                     if ((ip1def == KErrNotFound) || (ip1def> KIPNumMax))
       
   385                         {
       
   386                         return EFalse;
       
   387                         }
       
   388 
       
   389                     TPtrC8 ip4;
       
   390                     ip4.Set(hostt.Mid(posOfThirdDot + UpnpString::KDot8().Length()));
       
   391 
       
   392                     //position of the dot in IP address must from 1 to 3 starting from the position of former dot							
       
   393                     if((ip4.Length() < 1) || (ip4.Length()> 3))
       
   394                         {
       
   395                         return EFalse;
       
   396                         }
       
   397 
       
   398                     ip1def = ExtractNumFromIP (ip4);
       
   399 
       
   400                     if ((ip1def == KErrNotFound) || (ip1def> KIPNumMax))
       
   401                         {
       
   402                         return EFalse;
       
   403                         }
       
   404                     else
       
   405                         {
       
   406                         return ETrue;
       
   407                         }
       
   408 
       
   409                     }
       
   410                 }
       
   411             }
       
   412         }
       
   413 
       
   414     // -----------------------------------------------------------------------------
       
   415     // ExtractUrlPath
       
   416     // -----------------------------------------------------------------------------
       
   417     //
       
   418     EXPORT_C TPtrC8 ExtractUrlPath(
       
   419         const TDesC8& aUrl, TPtrC8& aFilename, TPtrC8& aScheme, TInt& aParseError )
       
   420         {
       
   421 
       
   422         LOGS("CHttpFolderUrlMatch::ExtractUrlPath()");
       
   423         TUriParser8 up;
       
   424         aParseError = up.Parse(aUrl);
       
   425         if( aParseError != KErrNone)
       
   426             {
       
   427             return KNullDesC8();
       
   428             }
       
   429         TPtrC8 path(up.Extract(EUriPath));
       
   430         TPtrC8 scheme(up.Extract(EUriScheme));
       
   431         TPtrC8 port(up.Extract(EUriPort));
       
   432         TPtrC8 host(up.Extract(EUriHost));
       
   433         TInt position (0);
       
   434         TPtrC8 urlPath;
       
   435 
       
   436         if(up.IsPresent(EUriScheme))
       
   437             {
       
   438 
       
   439             if(scheme.Compare(UpnpHTTP::KSchemeHTTP8()) == 0)
       
   440                 {
       
   441                 aScheme.Set(scheme);
       
   442 
       
   443                 //separator test
       
   444                 position = aUrl.FindC(UpnpHTTP::KSchemeSeparator());
       
   445                 if (position != KErrNotFound)
       
   446                     {
       
   447                     if ((up.IsPresent(EUriHost)) && (host != KNullDesC8()))
       
   448                         {
       
   449                         if( ExtractUrlPathHost(aUrl, aParseError ) )
       
   450                             {
       
   451                             TUint portdef(0);
       
   452                             TLex8 lex = TLex8(port);
       
   453                             TInt error = lex.Val(portdef, EDecimal);
       
   454                             if((up.IsPresent(EUriPort)) && (port != KNullDesC8()) && (error == KErrNone) )
       
   455                                 {
       
   456                                 urlPath.Set(path);
       
   457                                 }
       
   458                             else
       
   459                                 {
       
   460                                 return KNullDesC8();
       
   461                                 }
       
   462                             }
       
   463                         else
       
   464                             {
       
   465                             return KNullDesC8();
       
   466                             }
       
   467                         }
       
   468                     else
       
   469                         {
       
   470                         return KNullDesC8();
       
   471                         }
       
   472                     }
       
   473                 else
       
   474                     {
       
   475                     return KNullDesC8();
       
   476                     }
       
   477 
       
   478                 }
       
   479             else
       
   480                 {
       
   481                 return KNullDesC8();
       
   482                 }
       
   483             }
       
   484         else
       
   485             {
       
   486             TInt posOfFirstSlashnohttp( 0 );
       
   487             posOfFirstSlashnohttp = path.FindC( UpnpString::KSlash() );
       
   488 
       
   489             if( (posOfFirstSlashnohttp < KErrNone ) || (posOfFirstSlashnohttp != 0))
       
   490                 {
       
   491                 return KNullDesC8();
       
   492                 }
       
   493             else
       
   494                 {
       
   495                 urlPath.Set(aUrl);
       
   496                 }
       
   497             }
       
   498 
       
   499         TInt posOfFirstSlash( 0 );
       
   500         TInt posOfLastSlash( 0 );
       
   501         posOfFirstSlash = urlPath.FindC( UpnpString::KSlash() );
       
   502 
       
   503         if( posOfFirstSlash < KErrNone )
       
   504             {
       
   505             return KNullDesC8();
       
   506             }
       
   507         else
       
   508             {
       
   509             TInt posOfTwoSlashes( 0 );
       
   510             posOfTwoSlashes = urlPath.FindC(UpnpString::KDoubleSlash());
       
   511             if((posOfTwoSlashes == KErrNone ) || (posOfTwoSlashes> KErrNone) )
       
   512                 {
       
   513                 return KNullDesC8();
       
   514                 }
       
   515             posOfLastSlash = urlPath.LocateReverse( UpnpString::KSlash()[0] );
       
   516             if( posOfLastSlash == posOfFirstSlash )
       
   517                 {
       
   518                 aFilename.Set( urlPath.Mid( posOfLastSlash + UpnpString::KSlash().Length()) );
       
   519                 return KNullDesC8();
       
   520                 }
       
   521             else
       
   522                 {
       
   523                 aFilename.Set( urlPath.Mid( posOfLastSlash + UpnpString::KSlash().Length()) );
       
   524                 urlPath.Set( urlPath.Mid( posOfFirstSlash + UpnpString::KSlash().Length() ) );
       
   525                 urlPath.Set( urlPath.Left( posOfLastSlash - UpnpString::KSlash().Length() ) );
       
   526                 return urlPath;
       
   527 
       
   528                 }
       
   529             }
       
   530         }
       
   531 
       
   532     // -----------------------------------------------------------------------------
       
   533     // ExtractUrlPath
       
   534     // -----------------------------------------------------------------------------
       
   535     //
       
   536     EXPORT_C TPtrC8 ExtractUrlPath(const TDesC8& aUrl, TInt& aParseError )
       
   537         {
       
   538         TPtrC8 fileName;
       
   539         TPtrC8 scheme;
       
   540         return ExtractUrlPath(aUrl, fileName, scheme, aParseError );
       
   541         }
       
   542     // -----------------------------------------------------------------------------
       
   543     // ExtractUrlPath
       
   544     // -----------------------------------------------------------------------------
       
   545     //
       
   546     EXPORT_C TPtrC8 ExtractUrlPath(const TDesC8& aUrl, TPtrC8& aFilename, TInt& aParseError)
       
   547         {
       
   548         TPtrC8 scheme;
       
   549         return ExtractUrlPath(aUrl, aFilename, scheme, aParseError );
       
   550         }
       
   551 
       
   552     // -----------------------------------------------------------------------------
       
   553     // ConvertUrlToFolder
       
   554     // -----------------------------------------------------------------------------
       
   555     //
       
   556     EXPORT_C HBufC8* SwitchToBackSlashL(const TDesC8& aUrl)
       
   557         {
       
   558         TInt position( 0 );
       
   559 
       
   560         HBufC8* result = HBufC8::NewL(aUrl.Length() + aUrl.Length()/2);
       
   561 
       
   562         TPtr8 ptrResult(result->Des());
       
   563         ptrResult.Copy(aUrl);
       
   564 
       
   565         // replace / with '\\'
       
   566         while ( ( position = ptrResult.Locate( UpnpString::KSlash()[0] ) ) != KErrNotFound )
       
   567             {
       
   568             ptrResult.Replace( position, 1, UpnpString::KDoubleBackSlash() );
       
   569             }
       
   570         return result;
       
   571 
       
   572         }
       
   573     // -----------------------------------------------------------------------------
       
   574     // ConvertUrlToFolder
       
   575     // -----------------------------------------------------------------------------
       
   576     //
       
   577     EXPORT_C HBufC* SwitchToBackSlashL(const TDesC& aUrl)
       
   578         {
       
   579         TInt position( 0 );
       
   580 
       
   581         HBufC* result = HBufC::NewL(aUrl.Length() + aUrl.Length()/2);
       
   582 
       
   583         TPtr ptrResult(result->Des());
       
   584         ptrResult.Copy(aUrl);
       
   585 
       
   586         // replace / with '\\'
       
   587         while ( ( position = ptrResult.Locate( UpnpString::KSlash()[0] ) ) != KErrNotFound )
       
   588             {
       
   589             ptrResult.Replace( position, 1, UpnpString::KDoubleBackSlash16() );
       
   590             }
       
   591         return result;
       
   592 
       
   593         }
       
   594     // -----------------------------------------------------------------------------
       
   595     // Checks if the disk is short of the space requested
       
   596     // -----------------------------------------------------------------------------
       
   597     //
       
   598     EXPORT_C TBool CheckDiskSpaceShortL( const TDesC16& aPath, TInt aSize, RFs& aFs )
       
   599         {
       
   600         TInt drive_num = UpnpFileUtil::DriveNumberFromPath( aPath, aFs );
       
   601         return SysUtil::DiskSpaceBelowCriticalLevelL ( &aFs, aSize, drive_num );
       
   602         }
       
   603 
       
   604     // -----------------------------------------------------------------------------
       
   605     // Checks if the disk is short of the space requested
       
   606     // -----------------------------------------------------------------------------
       
   607     //
       
   608     EXPORT_C TBool CheckDiskSpaceShortL( TDriveNumber aDriveNumber, TInt aSize )
       
   609         {
       
   610         RFs fs;
       
   611         User::LeaveIfError( fs.Connect() );
       
   612         CleanupClosePushL( fs );
       
   613         TBool result = SysUtil::DiskSpaceBelowCriticalLevelL ( &fs, aSize, aDriveNumber );
       
   614         CleanupStack::PopAndDestroy( &fs );
       
   615         return result;
       
   616         }
       
   617      
       
   618     // -----------------------------------------------------------------------------
       
   619     // Parses uri
       
   620     // -----------------------------------------------------------------------------
       
   621     //
       
   622     EXPORT_C TInt ParseUri( const TDesC8& aUrl )
       
   623         {
       
   624         TUriParser8 up;
       
   625         return up.Parse( aUrl );
       
   626         }
       
   627     
       
   628 
       
   629     }
       
   630 
       
   631 //  End of File