ncdengine/provider/server/src/ncdengineconfigurationimpl.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:   CNcdEngineConfiguration implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bautils.h>
       
    20 
       
    21 #include "ncdengineconfigurationimpl.h"
       
    22 #include "ncdproviderutils.h"
       
    23 #include "catalogsutils.h"
       
    24 #include "catalogsuids.h"
       
    25 #include "ncdprotocolutils.h"
       
    26 #include "catalogsconstants.h"
       
    27 #include "ncdproviderdefines.h"
       
    28 #include "ncdutils.h"
       
    29 #include "ncddeviceservice.h"
       
    30 
       
    31 namespace NcdEngineConfiguration
       
    32     {
       
    33     _LIT8( KVersion, "version" );
       
    34     _LIT8( KType, "type" );
       
    35     _LIT8( KProvisioning, "provisioning" );
       
    36     _LIT8( KNetwork, "network" );
       
    37     _LIT8( KMcc, "mcc" );
       
    38     _LIT8( KMnc, "mnc" );
       
    39     _LIT8( KFixedAp, "fixed-access-point" );
       
    40     _LIT8( KAccessPointSettings, "access-point-settings" );
       
    41     _LIT8( KApId, "id" );
       
    42     _LIT8( KApDetail, "detail" );
       
    43     _LIT8( KApDetailId, "id" );
       
    44     _LIT8( KApDetailValue, "value" );
       
    45     }
       
    46 
       
    47 _LIT( KEngineDefaultType, "vanilla" );
       
    48 _LIT( KEngineDefaultVersion, "1.0" );
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CNcdEngineConfiguration* CNcdEngineConfiguration::NewL( MNcdDeviceService& aDeviceService )
       
    56     {
       
    57     CNcdEngineConfiguration* self = new( ELeave ) CNcdEngineConfiguration( aDeviceService );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );
       
    61     return self;    
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Destructor
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CNcdEngineConfiguration::~CNcdEngineConfiguration()
       
    69     {
       
    70     DLTRACEIN((""));
       
    71     delete iType;
       
    72     delete iVersion;
       
    73     delete iProvisioning;
       
    74     delete iUid;    
       
    75     delete iMcc;
       
    76     delete iMnc;
       
    77     delete iApId;
       
    78     delete iApDetailId;
       
    79     delete iApDetailValue;
       
    80     delete iCorrectApId;
       
    81     
       
    82     iHomeMcc.Close();
       
    83     iHomeMnc.Close();
       
    84     
       
    85     iApDetails.ResetAndDestroy();
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // Configuration reader
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CNcdEngineConfiguration::ReadConfigurationL( const TDesC& aFilename )
       
    93     {
       
    94     DLTRACEIN(( _L("Config file: %S"), &aFilename ));
       
    95     CNcdConfigurationParser* parser = CNcdConfigurationParser::NewLC( *this );
       
    96     DLTRACE(("Reading file"));
       
    97 
       
    98     // find the file from engine's private paths
       
    99     HBufC* filename = FindEngineFileL( CNcdProviderUtils::FileSession(),
       
   100         aFilename );
       
   101     CleanupStack::PushL( filename );                        
       
   102 
       
   103     // Read the file
       
   104     HBufC8* data = ReadFileL( CNcdProviderUtils::FileSession(), *filename );
       
   105     
       
   106     CleanupStack::PopAndDestroy( filename );
       
   107     CleanupStack::PushL( data );
       
   108     DLTRACE(("Start parsing"));
       
   109     
       
   110     // Parse the file
       
   111     parser->ParseL( *data );
       
   112     CleanupStack::PopAndDestroy( 2, parser ); // data, parser
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // 
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 const TDesC& CNcdEngineConfiguration::EngineType() const
       
   121     {
       
   122     return *iType;
       
   123     }
       
   124     
       
   125 // ---------------------------------------------------------------------------
       
   126 // 
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 const TDesC& CNcdEngineConfiguration::EngineVersion() const
       
   130     {
       
   131     return *iVersion;
       
   132     }
       
   133     
       
   134 // ---------------------------------------------------------------------------
       
   135 // 
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 const TDesC& CNcdEngineConfiguration::EngineUid() const
       
   139     {
       
   140     return *iUid;
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // Provisioning getter
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 const TDesC& CNcdEngineConfiguration::EngineProvisioning() const
       
   148     {    
       
   149     return *iProvisioning;
       
   150     }
       
   151 
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // Installation drive getter
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 const TDesC& CNcdEngineConfiguration::EngineInstallDrive() const
       
   158     {
       
   159     return iInstallationDrive;
       
   160     }
       
   161 
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // Engine temp drive
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 TInt CNcdEngineConfiguration::EngineTempDrive() const
       
   168     {
       
   169     return static_cast<TInt>( iDataDrive );
       
   170     }
       
   171     
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // Client data path getter
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 HBufC* CNcdEngineConfiguration::ClientDataPathLC(
       
   178     const TDesC& aClientId,
       
   179     TBool aTemp )
       
   180     {
       
   181     DLTRACEIN((""));
       
   182     TPath path;
       
   183     CreatePrivatePathL( 
       
   184         CNcdProviderUtils::FileSession(), 
       
   185         iDataDrive.Name(), 
       
   186         path );
       
   187 
       
   188     path.Append( aClientId );
       
   189     path.Append( KDirectorySeparator );
       
   190     if ( aTemp ) 
       
   191         {
       
   192         path.Append( NcdProviderDefines::KTempNamespace() );
       
   193         }
       
   194     else
       
   195         {
       
   196         path.Append( NcdProviderDefines::KDataNamespace() );
       
   197         }
       
   198     path.Append( KDirectorySeparator );
       
   199     BaflUtils::EnsurePathExistsL( CNcdProviderUtils::FileSession(), path );
       
   200     
       
   201     DLTRACEOUT( ( _L("Path: %S"), &path ) );
       
   202     return path.AllocLC();
       
   203     }
       
   204 
       
   205     
       
   206 TBool CNcdEngineConfiguration::UseFixedAp() const 
       
   207     {
       
   208     DLTRACEIN((""));
       
   209     TBool retValue = iApDetails.Count() > 0;
       
   210     DLINFO(("retValue: %d", retValue ))
       
   211     return retValue;
       
   212     }
       
   213     
       
   214     
       
   215 const RPointerArray<CNcdKeyValuePair>& CNcdEngineConfiguration::FixedApDetails() const 
       
   216     {
       
   217     DLTRACEIN((""));
       
   218     return iApDetails;
       
   219     }
       
   220 
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // Client data path cleaner
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CNcdEngineConfiguration::ClearClientDataL( 
       
   227     const TDesC& aClientId, 
       
   228     TBool aTemp )
       
   229     {
       
   230     DLTRACEIN(( _L("aClient: %S"), &aClientId ));
       
   231     // Get the path and delete the directory
       
   232     HBufC* path = ClientDataPathLC( aClientId, aTemp );
       
   233     CFileMan* fileman = CFileMan::NewL( CNcdProviderUtils::FileSession() );
       
   234     CleanupStack::PushL( fileman );    
       
   235     User::LeaveIfError( fileman->RmDir( *path ) );
       
   236     CleanupStack::PopAndDestroy( 2, path ); // fileman, path        
       
   237     
       
   238     DLTRACEOUT(("Client data path cleaned successfully"));
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // 
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 void CNcdEngineConfiguration::ConfigurationElementEndL( 
       
   246     const TDesC8& aElement, 
       
   247     const TDesC8& aData )
       
   248     {
       
   249     DLTRACEIN(( "Element: %S, data: %S", &aElement, &aData ));
       
   250     
       
   251     if ( aElement == NcdEngineConfiguration::KAccessPointSettings() ) 
       
   252         {
       
   253         iParseApDetails = EFalse;
       
   254         }
       
   255     else if ( iParseApDetails && aElement == NcdEngineConfiguration::KApDetail() )
       
   256         {
       
   257         DASSERT( iApDetailId && iApDetailValue );
       
   258         CNcdKeyValuePair* detail = CNcdKeyValuePair::NewLC( *iApDetailId, *iApDetailValue );
       
   259         iApDetails.AppendL( detail );
       
   260         CleanupStack::Pop( detail );
       
   261         delete iApDetailId;
       
   262         iApDetailId = NULL;
       
   263         delete iApDetailValue;
       
   264         iApDetailValue = NULL;
       
   265         }
       
   266     else if ( !aData.Length() )
       
   267         {
       
   268         DLTRACEOUT(("No data."));
       
   269         return;
       
   270         }        
       
   271     else if ( aElement == NcdEngineConfiguration::KType() ) 
       
   272         {        
       
   273         NcdProtocolUtils::AssignDesL( iType, aData );
       
   274         }
       
   275     else if ( aElement == NcdEngineConfiguration::KVersion() ) 
       
   276         {
       
   277         NcdProtocolUtils::AssignDesL( iVersion, aData );
       
   278         }
       
   279     else if ( aElement == NcdEngineConfiguration::KProvisioning() ) 
       
   280         {
       
   281         NcdProtocolUtils::AssignDesL( iProvisioning, aData );
       
   282         }
       
   283     else 
       
   284         {
       
   285         DLINFO(("Unknown element in the engine configuration file"));
       
   286         }
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // 
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CNcdEngineConfiguration::ConfigurationAttributeL( 
       
   294     const TDesC8& aElement, 
       
   295     const TDesC8& aAttribute, 
       
   296     const TDesC8& aValue )
       
   297     {
       
   298     DLTRACEIN(( "Element: %S, attribute: %S, value: %S", &aElement, &aAttribute, &aValue ));
       
   299     
       
   300     if ( aElement == NcdEngineConfiguration::KNetwork() && !iApIdFound ) 
       
   301         {
       
   302         if ( aAttribute == NcdEngineConfiguration::KMcc() ) 
       
   303             {
       
   304             NcdProtocolUtils::AssignDesL( iMcc, aValue );
       
   305             }
       
   306         else if ( aAttribute == NcdEngineConfiguration::KMnc() ) 
       
   307             {
       
   308             NcdProtocolUtils::AssignDesL( iMnc, aValue );
       
   309             }
       
   310         else if ( aAttribute == NcdEngineConfiguration::KFixedAp() ) 
       
   311             {
       
   312             NcdProtocolUtils::AssignDesL( iApId, aValue );
       
   313             }
       
   314         if ( iMcc && iMnc && iApId ) 
       
   315             {
       
   316             // All the attributes read, check whether the MCC/MNC match the current ones.
       
   317             iDeviceService.HomeNetworkInfoL( iHomeMcc, iHomeMnc );
       
   318             if ( iHomeMcc == *iMcc && iHomeMnc == *iMnc ) 
       
   319                 {
       
   320                 // Now we know the AP id we must use.
       
   321                 iApIdFound = ETrue;
       
   322                 NcdProtocolUtils::AssignDesL( iCorrectApId, *iApId );
       
   323                 DLINFO((("correct ap id found: %S"), iCorrectApId ));
       
   324                 }
       
   325             delete iMcc;
       
   326             iMcc = NULL;
       
   327             delete iMnc;
       
   328             iMnc = NULL;
       
   329             delete iApId;
       
   330             iApId = NULL;  
       
   331             }
       
   332         }                
       
   333     
       
   334     if ( aElement == NcdEngineConfiguration::KAccessPointSettings() ) 
       
   335         {
       
   336         if ( aAttribute == NcdEngineConfiguration::KApId() ) 
       
   337             {
       
   338             if ( iApIdFound && *iCorrectApId == aValue ) 
       
   339                 {
       
   340                 // This is the correct AP.
       
   341                 iParseApDetails = ETrue;
       
   342                 }
       
   343             }
       
   344         else 
       
   345             {
       
   346             DLINFO(("Unknown attribute in the engine configuration file"));
       
   347             }
       
   348         }
       
   349         
       
   350     if ( iParseApDetails && aElement == NcdEngineConfiguration::KApDetail() ) 
       
   351         {
       
   352         if ( aAttribute == NcdEngineConfiguration::KApDetailId() ) 
       
   353             {            
       
   354             NcdProtocolUtils::AssignDesL( iApDetailId, aValue );
       
   355             }
       
   356         else if ( aAttribute == NcdEngineConfiguration::KApDetailValue() ) 
       
   357             {
       
   358             NcdProtocolUtils::AssignDesL( iApDetailValue, aValue );
       
   359             }
       
   360         }
       
   361     }
       
   362     
       
   363 // ---------------------------------------------------------------------------
       
   364 // 
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 void CNcdEngineConfiguration::ConfigurationError( TInt /*aError*/ )
       
   368     {
       
   369     DLERROR(("Some error occurred during parsing"));
       
   370     }
       
   371     
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // 
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 CNcdEngineConfiguration::CNcdEngineConfiguration( MNcdDeviceService& aDeviceService )
       
   378     : iParseApDetails( EFalse ), iApIdFound( EFalse ), iDeviceService( aDeviceService )
       
   379     {
       
   380     }
       
   381     
       
   382 // ---------------------------------------------------------------------------
       
   383 // 
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 void CNcdEngineConfiguration::ConstructL()
       
   387     {
       
   388     DLTRACEIN((""));
       
   389     iType = KEngineDefaultType().AllocL();
       
   390     iVersion = KEngineDefaultVersion().AllocL();
       
   391     iProvisioning = KNullDesC().AllocL();
       
   392     iUid = CleanUidName( TUid::Uid( KCatalogsServerUid ) ).AllocL();
       
   393     iHomeMcc.CreateL( MNcdDeviceService::KMccLength );
       
   394     iHomeMnc.CreateL( MNcdDeviceService::KMncLength );
       
   395     
       
   396     TFileName engineExe( RProcess().FileName() );
       
   397     TParsePtrC parseDrive( engineExe );
       
   398     iInstallationDrive = parseDrive.Drive();
       
   399         
       
   400     // Determine the drive used for temp and data
       
   401     iDataDrive = TDriveUnit( DetermineDataDriveL() );    
       
   402        
       
   403     DLTRACEOUT(( _L("Install drive: %S"), &iInstallationDrive ));
       
   404     }
       
   405 
       
   406 
       
   407 // ---------------------------------------------------------------------------
       
   408 // Determines the drive where data files are stored (temporarily)
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 TDriveNumber CNcdEngineConfiguration::DetermineDataDriveL() const
       
   412     {
       
   413     DLTRACEIN((""));
       
   414     TInt64 freeOnE = 0;
       
   415     TInt64 freeOnC = 0;
       
   416         
       
   417     TDriveNumber drive = EDriveC;
       
   418     TRAPD( err, freeOnE = FreeDiskSpaceL( CNcdProviderUtils::FileSession(),
       
   419         EDriveE ) );
       
   420     
       
   421     // Drive E exists and has free space
       
   422     if ( freeOnE && err == KErrNone ) 
       
   423         {
       
   424         // No trap because if this fails then we're in trouble already
       
   425         freeOnC = FreeDiskSpaceL( CNcdProviderUtils::FileSession(),
       
   426             EDriveC );
       
   427         if ( freeOnE > freeOnC ) 
       
   428             {
       
   429             DLINFO(("Using E: as temp drive"));
       
   430             drive = EDriveE;
       
   431             }
       
   432         }
       
   433     return drive;
       
   434     }
       
   435