dbcreator/commsdatcreator/src/cdcprocessorbase.cpp
changeset 56 dd6aaa97e7b1
parent 0 5a93021fdf25
equal deleted inserted replaced
52:bbe4544dfd31 56:dd6aaa97e7b1
       
     1 /*
       
     2 * Copyright (c) 2004 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:   Implementation of the class CProcessorBase
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "cdcprocessorbase.h"
       
    24 #include "cdcreaderbase.h"
       
    25 #include "cdclogger.h"
       
    26 
       
    27 #include <cmmanagerext.h>
       
    28 #include <cmconnectionmethoddef.h>
       
    29 #include <cmconnectionmethodext.h>
       
    30 #include <cmdestinationext.h>
       
    31 #include <datamobilitycommsdattypes.h>
       
    32 
       
    33 
       
    34 using namespace CMManager;
       
    35 
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // CProcessorBase::CProcessorBase
       
    41 // Constructor.
       
    42 // ---------------------------------------------------------
       
    43 //
       
    44 CProcessorBase::CProcessorBase( CReaderBase* aFileReader,
       
    45                                 RCmManagerExt& aCmManager,
       
    46                                 RPointerArray< RCmConnectionMethodExt >& aPluginArray,
       
    47                                 RPointerArray< HBufC >& aPluginNames ) :
       
    48         iFileReader( aFileReader ), 
       
    49         iProxyEnabled( EFalse ),
       
    50         iIsProtected( EFalse )
       
    51     {
       
    52     iCmManager = &aCmManager;
       
    53     
       
    54     iPluginArray = &aPluginArray;
       
    55     iPluginName = &aPluginNames;
       
    56     }
       
    57 
       
    58 
       
    59 CProcessorBase::CProcessorBase( CReaderBase* aFileReader,
       
    60                         RCmManagerExt& aCmManager,
       
    61                         RPointerArray< RCmConnectionMethodExt >& aPluginArray,
       
    62                         RPointerArray< HBufC >& aPluginNames,
       
    63                         RPointerArray< RCmDestinationExt >& aDestArray,
       
    64                         RPointerArray< HBufC >& aDestNames ) :
       
    65         iFileReader( aFileReader ), 
       
    66         iProxyEnabled( EFalse ),
       
    67         iIsProtected( EFalse )
       
    68     {
       
    69     iCmManager = &aCmManager;
       
    70     
       
    71     iPluginArray = &aPluginArray;
       
    72     iPluginName = &aPluginNames;
       
    73     
       
    74     iDestArray = &aDestArray;
       
    75     iDestName = &aDestNames;
       
    76     }
       
    77 
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CProcessorBase::~CProcessorBase
       
    81 // Destructor.
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 CProcessorBase::~CProcessorBase()
       
    85     {
       
    86     iPlugin.Close();
       
    87     if( iName )
       
    88         {
       
    89         delete iName;
       
    90         }
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // CProcessorBase::ParseFileL
       
    96 // ---------------------------------------------------------
       
    97 //
       
    98 //PseudoCode:
       
    99 // 0010 locates the next access point within the text file
       
   100 // 0020 parses the location and reads the input data to TagContainer
       
   101 // 0030 from TagContainer creates Access Point Item Object
       
   102 // 0040 using the Access Point Item Object creates a new AP record in CommsDat
       
   103 // 0050 clears TagContainer
       
   104 //
       
   105 void CProcessorBase::ParseFileL()
       
   106     {
       
   107     //LocateAP : locates the access points within the text file
       
   108     while ( iFileReader->LocateAPL() )
       
   109         {
       
   110         //ParseAPL : parses the location, reads the input data to TagContainer
       
   111         iFileReader->ParseAPL();
       
   112         
       
   113         //from TagContainer creates Access Point Item Object
       
   114         ProcessTagL( iFileReader->FieldIDPresent() );
       
   115                 
       
   116         //adds the Access Point Item Object to CommsDB
       
   117         ProcessAPL();
       
   118             
       
   119         //clear TagContainer
       
   120         TagContainer().Clear();
       
   121             
       
   122         }//while    
       
   123         
       
   124     CLOG_WRITE( "---------------------\n" )
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CProcessorPacketData::ProcessTagL
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 void CProcessorBase::ProcessTagL( TBool /*aFieldIDPresent*/ )
       
   132     {
       
   133     iProxyEnabled= EFalse;
       
   134     iIsProtected = EFalse;
       
   135 
       
   136     Reset();
       
   137     TInt aCMId = -1;
       
   138     for ( TInt idx(0); idx < TagContainer().Count(); idx++)
       
   139         {
       
   140         if ( TagContainer().FieldId( idx ) == ECmId)
       
   141             {
       
   142             HBufC16* ptrTag = TagContainer().Tag(idx);
       
   143             TLex16 lex(ptrTag->Des());
       
   144             TInt err = lex.Val(aCMId);
       
   145             if (err != KErrNone)
       
   146                 {
       
   147                 User::Leave(err);    
       
   148                 }
       
   149             break;
       
   150             }
       
   151         }
       
   152     if (aCMId == -1)
       
   153         {
       
   154         iPlugin = iCmManager->CreateConnectionMethodL( iBearerType );        
       
   155         CLOG_WRITE( "ConnectionMethod created without ECmId.");
       
   156         }
       
   157     else
       
   158         {
       
   159         iPlugin = iCmManager->CreateConnectionMethodL( iBearerType, aCMId);        
       
   160         CLOG_WRITE_FORMAT( "ConnectionMethod created. ECmId:%d", aCMId);
       
   161         }
       
   162      
       
   163     for ( TInt idx(0); idx < TagContainer().Count(); idx++)
       
   164         {
       
   165         HBufC16* ptrTag = TagContainer().Tag(idx);
       
   166         TInt field =  TagContainer().FieldId( idx );
       
   167 
       
   168         TBool processed = SetGeneralFieldL( field, ptrTag );
       
   169         if( !processed )
       
   170             {
       
   171             ProcessSpecialFieldsL( field, ptrTag, idx );
       
   172             }
       
   173         }
       
   174         
       
   175     AddToPluginArrayL();
       
   176     
       
   177     }
       
   178 
       
   179 // --------------------------------------------------------
       
   180 // CProcessorBase::TagContainer()
       
   181 // --------------------------------------------------------
       
   182 CTagContainer& CProcessorBase::TagContainer()
       
   183     {
       
   184     return iFileReader->TagContainer();    
       
   185     }
       
   186 
       
   187 
       
   188 // --------------------------------------------------------
       
   189 // CProcessorBase::AddToPluginArrayL()
       
   190 // --------------------------------------------------------
       
   191 void CProcessorBase::AddToPluginArrayL()
       
   192     {
       
   193     if( !iName )
       
   194         {
       
   195         CLOG_WRITE( "Error: No plugin name !!!" )
       
   196         }    
       
   197     else
       
   198         {
       
   199         const RCmConnectionMethodExt* newItem = new (ELeave) 
       
   200                 RCmConnectionMethodExt( iPlugin );
       
   201     
       
   202         iPluginArray->Append( newItem );
       
   203         iPluginName->Append( iName->AllocL() );
       
   204         
       
   205         delete iName;
       
   206         iName = NULL;
       
   207         
       
   208         iPlugin.Close();
       
   209         }
       
   210     }
       
   211 
       
   212 // --------------------------------------------------------
       
   213 // CProcessorBase::GetLastPluginL()
       
   214 // --------------------------------------------------------
       
   215 RCmConnectionMethodExt& CProcessorBase::GetLastPluginL()
       
   216     {
       
   217     return GetPluginL( PluginCount() - 1 );
       
   218                 
       
   219     }    
       
   220 
       
   221 // --------------------------------------------------------
       
   222 // CProcessorBase::GetPluginL()
       
   223 // --------------------------------------------------------
       
   224 RCmConnectionMethodExt& CProcessorBase::GetPluginL( TInt aPos )
       
   225     {
       
   226 
       
   227     return *(iPluginArray->operator[]( aPos ));
       
   228                 
       
   229     }    
       
   230 
       
   231 // --------------------------------------------------------
       
   232 // CProcessorBase::PluginCount()
       
   233 // --------------------------------------------------------
       
   234 TInt CProcessorBase::PluginCount()
       
   235     {
       
   236 
       
   237     return iPluginArray->Count();
       
   238                 
       
   239     }    
       
   240 
       
   241 // ---------------------------------------------------------
       
   242 // CProcessorBase::FindDestinationL
       
   243 // ---------------------------------------------------------
       
   244 //
       
   245 RCmDestinationExt* CProcessorBase::FindDestinationL( HBufC* aName )
       
   246     {
       
   247     for( TInt i(0); i < iDestName->Count(); i++ )
       
   248         {
       
   249         HBufC *name = (*iDestName)[i];
       
   250         if( aName->Compare( *name  ) == 0 )
       
   251             {
       
   252             return (*iDestArray)[ i ];
       
   253             }
       
   254         }
       
   255     CLOG_WRITE_FORMAT("Warning: Destination not found: %S", aName );
       
   256     return NULL;
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------
       
   260 // CProcessorBase::GetDestinationIdL
       
   261 // ---------------------------------------------------------
       
   262 //
       
   263 TInt CProcessorBase::GetDestinationIdL( HBufC16* aName )
       
   264     {
       
   265     RCmDestinationExt* dest = FindDestinationL( aName );
       
   266     
       
   267     TInt ret( KErrNotFound );
       
   268     if( dest != NULL )
       
   269         {
       
   270         ret = dest->Id();
       
   271         }
       
   272         
       
   273     return ret;    
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------
       
   277 // CProcessorBase::FindPluginL
       
   278 // ---------------------------------------------------------
       
   279 // 
       
   280 RCmConnectionMethodExt* CProcessorBase::FindPluginL( HBufC* aName )
       
   281     {
       
   282     TInt pos;
       
   283     return FindPluginL( aName, pos );
       
   284     } 
       
   285  
       
   286 // ---------------------------------------------------------
       
   287 // CProcessorBase::FindPluginL
       
   288 // ---------------------------------------------------------
       
   289 //
       
   290 RCmConnectionMethodExt* CProcessorBase::FindPluginL( HBufC* aName, TInt& aPos )
       
   291     {
       
   292     RCmConnectionMethodExt* ret( NULL );
       
   293     
       
   294     aPos = CheckPluginName( aName );
       
   295     if ( aPos != KErrNotFound )
       
   296         {
       
   297         ret = (*iPluginArray)[ aPos ];
       
   298         }
       
   299     else
       
   300         {
       
   301         CLOG_WRITE_FORMAT("Warning: Connection method not found: %S", aName );
       
   302         }
       
   303 
       
   304     return ret;
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------
       
   308 // CProcessorBase::CheckPluginName
       
   309 // ---------------------------------------------------------
       
   310 //
       
   311 TInt CProcessorBase::CheckPluginName( HBufC* aName )
       
   312     {
       
   313     TInt ret( KErrNotFound );
       
   314     
       
   315     for( TInt i = 0; i < iPluginName->Count() && ret == KErrNotFound; i++ )
       
   316         {
       
   317         HBufC *name = (*iPluginName)[i];
       
   318         if( aName->Compare( *name  ) == 0 )
       
   319             {
       
   320             ret = i;
       
   321             }
       
   322         }
       
   323     return ret;
       
   324     }
       
   325 
       
   326 
       
   327 
       
   328 // ---------------------------------------------------------
       
   329 // CProcessorBase::GetPluginIdL
       
   330 // ---------------------------------------------------------
       
   331 //
       
   332 TInt CProcessorBase::GetPluginIdL( HBufC16* aName )
       
   333     {
       
   334     RCmConnectionMethodExt* cm = FindPluginL( aName );
       
   335     
       
   336     TInt ret( KErrNotFound );
       
   337     if( cm != NULL )
       
   338         {
       
   339         ret = cm->GetIntAttributeL( CMManager::ECmIapId );
       
   340         }
       
   341         
       
   342     return ret;    
       
   343     }
       
   344 
       
   345     
       
   346 // ---------------------------------------------------------
       
   347 // CProcessorBase::ProcessAPL
       
   348 // ---------------------------------------------------------
       
   349 //
       
   350 void CProcessorBase::ProcessAPL()
       
   351     {
       
   352     RCmConnectionMethodExt& plugin = GetLastPluginL();
       
   353     if( iIsProtected )
       
   354         {
       
   355         plugin.SetBoolAttributeL( ECmProtected, ETrue );
       
   356         }
       
   357         
       
   358     // Writes into the log file.
       
   359     DoLogL();
       
   360     }
       
   361     
       
   362 // ---------------------------------------------------------
       
   363 // CProcessorBase::ProcessAPL
       
   364 // ---------------------------------------------------------
       
   365 //
       
   366 TBool CProcessorBase::SetGeneralFieldL( TInt aField, HBufC* aPtrTag )
       
   367     {
       
   368     TBool processed( ETrue );
       
   369     switch( aField )
       
   370         {
       
   371         case ECmName:     
       
   372             {
       
   373             // If input is not empty
       
   374             if ( aPtrTag->CompareF( KStrEmpty ) != 0 )
       
   375                 {
       
   376                 TInt pos = CheckPluginName( aPtrTag );
       
   377                 if( pos != KErrNotFound )
       
   378                     {
       
   379                     CLOG_WRITE_FORMAT("Warning: plugin exist. It might be renamed ! : %S", aPtrTag );
       
   380                     }
       
   381                 iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   382                 if( !iName )
       
   383                     {
       
   384                     iName = aPtrTag->AllocL();
       
   385                     }
       
   386                 }
       
   387             break;
       
   388             }
       
   389         case ECmStartPage:
       
   390             {
       
   391             // If input is not empty
       
   392             if ( aPtrTag->CompareF( KStrEmpty ) != 0 )
       
   393                 {
       
   394                 iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   395                 }
       
   396             break;
       
   397             }
       
   398         case ECmHidden:              //fall through
       
   399         case ECmMetaHiddenAgent:     //fall through
       
   400         case ECmMetaHighlight:       //fall through
       
   401             {
       
   402             if( aPtrTag->CompareF( KStrNo ) == 0 )
       
   403                 {
       
   404                 iPlugin.SetBoolAttributeL( aField, EFalse );
       
   405                 }
       
   406             else if( aPtrTag->CompareF( KStrYes ) == 0 )
       
   407                 {
       
   408                 iPlugin.SetBoolAttributeL( aField, ETrue );
       
   409                 }
       
   410             else
       
   411                 {
       
   412                 iPlugin.SetBoolAttributeL( aField, EFalse );
       
   413                 switch ( aField )
       
   414                     {
       
   415                     case ECmHidden:
       
   416                         CLOG_WRITE( "! Error : Invalid Hidden. Default:No");
       
   417                         break;
       
   418                     case ECmMetaHiddenAgent:
       
   419                         CLOG_WRITE( "! Error : Invalid HiddenAgent. Default:No");
       
   420                         break;
       
   421                     case ECmMetaHighlight:
       
   422                         CLOG_WRITE( "! Error : Invalid Highlight. Default:No");
       
   423                         break;
       
   424                     }
       
   425                 }
       
   426             break;
       
   427             }
       
   428         case ECmSeamlessnessLevel:
       
   429             {
       
   430             if ( aPtrTag->CompareF( KStrNotRoamedTo ) == 0 )
       
   431                 {
       
   432                 iPlugin.SetIntAttributeL( aField,
       
   433                                         CMManager::ESeamlessnessNotRoamedTo );
       
   434                 }
       
   435             else if ( aPtrTag->CompareF( KStrConfirmFirst ) == 0 )
       
   436                 {
       
   437                 iPlugin.SetIntAttributeL( aField,
       
   438                                         CMManager::ESeamlessnessConfirmFirst );
       
   439                 }
       
   440             else if ( aPtrTag->CompareF( KStrShowProgress ) == 0 )
       
   441                 {
       
   442                 iPlugin.SetIntAttributeL( aField,
       
   443                                         CMManager::ESeamlessnessShowprogress );
       
   444                 }
       
   445             else if ( aPtrTag->CompareF( KStrFullySeamless ) == 0 )
       
   446                 {
       
   447                 iPlugin.SetIntAttributeL( aField,
       
   448                                         CMManager::ESeamlessnessFullySeamless );
       
   449                 }
       
   450             break;
       
   451             }
       
   452             
       
   453         case ECmProtected:
       
   454             {
       
   455             // Protection
       
   456             if ( aPtrTag->CompareF( KStrYes ) == 0 )
       
   457                 {
       
   458                 iIsProtected = ETrue;
       
   459                 }
       
   460             else if ( aPtrTag->CompareF( KStrNo ) != 0 )
       
   461                 {
       
   462                 CLOG_WRITE( "! Error : Invalid Protected value. Default:No" )
       
   463                 }
       
   464             break;
       
   465             }
       
   466             
       
   467         default:
       
   468             {
       
   469             processed = EFalse;
       
   470             }        
       
   471         }
       
   472         
       
   473     return processed;
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------
       
   477 // CProcessorBase::DoLogL
       
   478 // ---------------------------------------------------------
       
   479 //
       
   480 
       
   481 void CProcessorBase::DoLogL()
       
   482     {
       
   483     
       
   484     TInt lastPos = iPluginArray->Count() - 1;
       
   485     
       
   486     CLOG_WRITE( "Internet Access Point created:" )
       
   487     CLOG_WRITE_FORMAT( "\t Connection name: %S ", (*iPluginName)[ lastPos ] );
       
   488     
       
   489     if ( iIsProtected )
       
   490         {
       
   491         CLOG_WRITE( "\t Protected" )
       
   492         }
       
   493     else
       
   494         {
       
   495         CLOG_WRITE( "\t Not protected" )
       
   496         }
       
   497     }
       
   498 // ---------------------------------------------------------
       
   499 // CProcessorBase::SetAddressFromServerL
       
   500 // ---------------------------------------------------------
       
   501 //
       
   502 
       
   503 void CProcessorBase::SetAddressFromServerL( TInt aIPField1, 
       
   504                                            TInt aIPField2, 
       
   505                                            TInt aAddrFromSField,
       
   506                                            TInt aIPField1IP6,
       
   507                                            TInt aIPField2IP6,
       
   508                                            TInt aAddrFromSFieldIP6 )
       
   509     {
       
   510         //calculate and set Ip6AddrFromServer
       
   511         HBufC *pIp1 = NULL;        
       
   512         HBufC *pIp2 = NULL;        
       
   513         pIp1 = iPlugin.GetStringAttributeL( aIPField1IP6 );
       
   514         CleanupStack::PushL( pIp1 );
       
   515         pIp2 = iPlugin.GetStringAttributeL( aIPField2IP6 );
       
   516         CleanupStack::PushL( pIp2 );
       
   517         _LIT( KDynIpv6Address, "0:0:0:0:0:0:0:0" );
       
   518         if ( ( pIp1->Compare( KDynIpv6Address ) == 0 ) &&
       
   519              ( pIp2->Compare( KDynIpv6Address ) == 0 ) )
       
   520             {
       
   521             iPlugin.SetBoolAttributeL( aAddrFromSFieldIP6, ETrue );
       
   522             }
       
   523         else
       
   524             {
       
   525             iPlugin.SetBoolAttributeL( aAddrFromSFieldIP6, EFalse );
       
   526             }
       
   527         CleanupStack::PopAndDestroy( 2,pIp1 );
       
   528 
       
   529         //calculate and set AddrFromServer
       
   530         pIp1 = iPlugin.GetStringAttributeL( aIPField1 );
       
   531         CleanupStack::PushL( pIp1 );
       
   532         pIp2 = iPlugin.GetStringAttributeL( aIPField2 );
       
   533         CleanupStack::PushL( pIp2 );    
       
   534         _LIT( KDynIpAddress, "0.0.0.0" );
       
   535         if ( ( pIp1->Compare( KDynIpAddress ) == 0 ) &&
       
   536              ( pIp2->Compare( KDynIpAddress ) == 0 ) )
       
   537             {
       
   538             iPlugin.SetBoolAttributeL( aAddrFromSField, ETrue );
       
   539             }
       
   540         else
       
   541             {
       
   542             iPlugin.SetBoolAttributeL( aAddrFromSField, EFalse );
       
   543             }
       
   544         CleanupStack::PopAndDestroy( 2,pIp1 );        
       
   545     }
       
   546 
       
   547 // End of File.