dbcreator/commsdatcreator/Src/cdcprocessorpacketdata.cpp
changeset 0 5a93021fdf25
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Implementation of the class CProcessorPacketData
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "cdcprocessorpacketdata.h"
       
    24 #include "cdclogger.h"
       
    25 #include "cdctagcontainer.h"
       
    26 
       
    27 #include <etelpckt.h>
       
    28 #include <cmpluginpacketdatadef.h>
       
    29 #include <cmpluginbaseeng.h>
       
    30 #include <cmconnectionmethoddef.h>
       
    31 #include <cmmanagerext.h>
       
    32 #include <datamobilitycommsdattypes.h>
       
    33 
       
    34 #include <centralrepository.h>
       
    35 #include <pdpcontextmanagerinternalcrkeys.h>
       
    36 
       
    37 using namespace CMManager;
       
    38 
       
    39 // CONSTANTS
       
    40 
       
    41 const TUint32 KDefaultPortNum = 80;
       
    42 const TInt32 KDefaultLinger = 0;
       
    43 const TUint KIapColumn        = 0x00000100;
       
    44 const TUint KLingerColumn     = 0x00000200;
       
    45 const TUint KColumnMask       = 0xFFFFFF00;
       
    46 const TUint KRowMask          = 0x000000FF;
       
    47 
       
    48 // These constants are used to identify tags of iInFile.
       
    49 
       
    50 //ISP types
       
    51 _LIT16( KStrISPInternet,      "0" );
       
    52 _LIT16( KStrISPWAP,      "1" );
       
    53 
       
    54 //Connection type
       
    55 _LIT16( KStrContinuous,      "Continuous" );
       
    56 _LIT16( KStrTemporary,       "Temporary" );
       
    57 
       
    58 //Password authentication
       
    59 _LIT16( KStrPwdAuthNormal,   "Normal" );
       
    60 _LIT16( KStrPwdAuthSecure,   "Secure" );
       
    61 
       
    62 //Network types
       
    63 _LIT16( KStrNetworkIPv4,     "IPv4" );
       
    64 _LIT16( KStrNetworkIPv6,     "IPv6" );
       
    65 
       
    66 
       
    67 // ================= MEMBER FUNCTIONS =======================
       
    68 CLingerElement::~CLingerElement()
       
    69     {
       
    70     delete iName;
       
    71     delete iLinger;
       
    72     }
       
    73 // ---------------------------------------------------------
       
    74 // CProcessorPacketData::NewL
       
    75 // ---------------------------------------------------------
       
    76 //
       
    77 CProcessorPacketData* CProcessorPacketData::NewL( 
       
    78                                 CReaderBase* aFileReader,
       
    79                                 RCmManagerExt& aCmManager,
       
    80                                 RPointerArray< RCmConnectionMethodExt >& aPluginArray,
       
    81                                 RPointerArray< HBufC >& aPluginNames,
       
    82                                 RPointerArray< CLingerElement >& aLingerSettings)
       
    83     {
       
    84     CProcessorPacketData* self = new ( ELeave ) CProcessorPacketData
       
    85                                                             ( aFileReader,
       
    86                                                               aCmManager,
       
    87                                                               aPluginArray,
       
    88                                                               aPluginNames,
       
    89                                                               aLingerSettings);
       
    90     CleanupStack::PushL( self );
       
    91 
       
    92     // From base class
       
    93     self->ConstructL();
       
    94     CleanupStack::Pop( self ); // self
       
    95     return self;
       
    96     }
       
    97     
       
    98     
       
    99 // ---------------------------------------------------------
       
   100 // CProcessorPacketData::~CProcessorPacketData
       
   101 // ---------------------------------------------------------
       
   102 //
       
   103 CProcessorPacketData::~CProcessorPacketData()
       
   104     {
       
   105     }
       
   106      
       
   107      
       
   108 // ---------------------------------------------------------
       
   109 // CProcessorPacketData::ConstructL
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 void CProcessorPacketData::ConstructL()
       
   113     {
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // CProcessorPacketData::CProcessorPacketData
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 CProcessorPacketData::CProcessorPacketData( CReaderBase* aFileReader,
       
   122                       RCmManagerExt& aCmManager,
       
   123                       RPointerArray< RCmConnectionMethodExt >& aPluginArray,
       
   124                       RPointerArray< HBufC >& aPluginNames,
       
   125                       RPointerArray< CLingerElement >& aLingerSettings ) :
       
   126                                       CProcessorBase( aFileReader,
       
   127                                                       aCmManager,
       
   128                                                       aPluginArray,
       
   129                                                       aPluginNames )
       
   130                                       
       
   131     {
       
   132     iLingerSettings = &aLingerSettings;
       
   133     iBearerType = KUidPacketDataBearerType;
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------
       
   137 // CProcessorPacketData::ProcessTagL
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 void CProcessorPacketData::ProcessSpecialFieldsL( TInt aField, HBufC* aPtrTag, TInt /*aDx*/ )
       
   141     {
       
   142 
       
   143     switch ( aField )
       
   144         {
       
   145         case EPacketDataAPName:               //fall through
       
   146         case EPacketDataIFAuthName:           //fall through
       
   147         case EPacketDataIFAuthPass:           //fall through
       
   148         case EPacketDataIPAddr:               //fall through
       
   149             {
       
   150              // Unicode 16-bit text
       
   151             iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   152 
       
   153             break;
       
   154             }
       
   155         case EPacketDataIPNameServer1:        //fall through
       
   156         case EPacketDataIPNameServer2:        //fall through
       
   157         case EPacketDataIPIP6NameServer1:     //fall through
       
   158         case EPacketDataIPIP6NameServer2:     //fall through
       
   159             {
       
   160             iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   161             SetAddressFromServerL( EPacketDataIPNameServer1,
       
   162                                   EPacketDataIPNameServer2,
       
   163                                   EPacketDataIPDNSAddrFromServer,
       
   164                                   EPacketDataIPIP6NameServer1,
       
   165                                   EPacketDataIPIP6NameServer2,
       
   166                                   EPacketDataIPIP6DNSAddrFromServer );    
       
   167             break;
       
   168             }
       
   169         case ECmWapIPGatewayAddress:
       
   170             {
       
   171              // Unicode 16-bit text
       
   172             if ( aPtrTag->Length() )
       
   173                 {
       
   174                 iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   175                 }
       
   176 
       
   177             break;
       
   178             }
       
   179         case EPacketDataIFPromptForAuth:
       
   180             {
       
   181             // Boolean
       
   182             if ( !aPtrTag->CompareF( KStrYes ) )
       
   183                 {
       
   184                 iPlugin.SetBoolAttributeL( aField, ETrue );
       
   185                 }
       
   186             else if ( !aPtrTag->CompareF( KStrNo ) )
       
   187                 {
       
   188                 iPlugin.SetBoolAttributeL( aField, EFalse );
       
   189                 }
       
   190             else
       
   191                 {
       
   192                 //no valid data is given - use default value
       
   193                 iPlugin.SetBoolAttributeL( aField, EFalse );
       
   194                 CLOG_WRITE( "! Error : Invalid Prompt password. Default:No");
       
   195                 }
       
   196 
       
   197             break;
       
   198             }
       
   199         case EPacketDataUseEdge:
       
   200             {
       
   201             // Boolean
       
   202             if ( !aPtrTag->CompareF( KStrYes ) )
       
   203                 {
       
   204                 iPlugin.SetBoolAttributeL( aField, ETrue );
       
   205                 }
       
   206             else if ( !aPtrTag->CompareF( KStrNo ) )
       
   207                 {
       
   208                 iPlugin.SetBoolAttributeL( aField, EFalse );
       
   209                 }
       
   210             else
       
   211                 {
       
   212                 //no valid data is given - use default value
       
   213                 iPlugin.SetBoolAttributeL( aField, ETrue );
       
   214                 CLOG_WRITE( "! Error : Invalid Use EDGE. Default:Yes");
       
   215                 }
       
   216 
       
   217             break;
       
   218             }
       
   219         case EPacketDataLinger:
       
   220             {
       
   221             // Pair linger with name for later saving
       
   222             CLingerElement* linger = new (ELeave) CLingerElement;
       
   223 
       
   224             CleanupStack::PushL( linger );
       
   225                     
       
   226             linger->iName = iName->AllocL();
       
   227             linger->iLinger = aPtrTag->AllocL(); 
       
   228                                             
       
   229             iLingerSettings->AppendL(linger);
       
   230                     
       
   231             CleanupStack::Pop( linger );
       
   232             break;
       
   233             }
       
   234         case ECmWapIPSecurity:
       
   235             {
       
   236              // TBool                
       
   237             if ( !aPtrTag->CompareF( KStrOn ) )
       
   238                 {
       
   239                 iPlugin.SetBoolAttributeL( aField, ETrue );
       
   240                 }
       
   241             else if ( !aPtrTag->CompareF( KStrOff ) )
       
   242                 {
       
   243                 iPlugin.SetBoolAttributeL( aField, EFalse );
       
   244                 }
       
   245             else
       
   246                 {
       
   247                 //no valid data is given - default data is used
       
   248                 iPlugin.SetBoolAttributeL( aField, ETrue );
       
   249                 CLOG_WRITE( "! Error : Invalid WTLS security setting. Default:On");
       
   250                 }
       
   251 
       
   252             break;
       
   253             }
       
   254         case ECmWapIPWSPOption:
       
   255             {
       
   256             // UInt                
       
   257             if ( !aPtrTag->CompareF( KStrContinuous ) )
       
   258                 {
       
   259                 iPlugin.SetIntAttributeL( aField, 
       
   260                                   EWapWspOptionConnectionOriented );
       
   261                 }
       
   262             else if ( !aPtrTag->CompareF( KStrTemporary ) )
       
   263                 {
       
   264                 iPlugin.SetIntAttributeL( aField, 
       
   265                                   EWapWspOptionConnectionless );
       
   266                 }
       
   267             else
       
   268                 {
       
   269                 //no valid data is given - default data is used
       
   270                 iPlugin.SetIntAttributeL( aField, 
       
   271                                   EWapWspOptionConnectionOriented );
       
   272                 CLOG_WRITE( "! Error : Invalid connection type. Default:Continuous");
       
   273                 }
       
   274 
       
   275             break;
       
   276             }
       
   277             
       
   278         case ECmProxyProtocolName:
       
   279         	{
       
   280         	// Do not enable proxy in this case yet
       
   281         	iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   282         	break;
       
   283         	}
       
   284                          
       
   285         case ECmProxyServerName:    
       
   286             {
       
   287             // First set proxy usage to enabled
       
   288             if( !iProxyEnabled )
       
   289                 {
       
   290                 iPlugin.SetBoolAttributeL( ECmProxyUsageEnabled, ETrue );
       
   291                 iProxyEnabled = ETrue;
       
   292                 }
       
   293             // Long text
       
   294             iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   295             break;
       
   296             }
       
   297         case ECmProxyPortNumber:
       
   298             {
       
   299             // First set proxy usage to enabled
       
   300             if( !iProxyEnabled )
       
   301                 {
       
   302                 iPlugin.SetBoolAttributeL( ECmProxyUsageEnabled, ETrue );
       
   303                 iProxyEnabled = ETrue;
       
   304                 }
       
   305              // TUint32 and should be read as text.
       
   306             TPtrC16 portptr = aPtrTag->Right( aPtrTag->Length() );
       
   307             TLex16 lex( portptr );
       
   308             TUint32 portnum( 0 );
       
   309             if ( lex.Val( portnum, EDecimal ) == KErrNone )
       
   310                 {
       
   311                 iPlugin.SetIntAttributeL( aField, portnum );
       
   312                 }
       
   313             else 
       
   314                 {
       
   315                 //no valid data is given - default value is used
       
   316                 iPlugin.SetIntAttributeL( aField, KDefaultPortNum );
       
   317                 CLOG_WRITE( "! Error : Invalid port number. Default:80");  
       
   318                 }
       
   319             break;
       
   320             }
       
   321         case EPacketDataDisablePlainTextAuth:
       
   322             {
       
   323              // TBool                
       
   324             if ( !aPtrTag->CompareF( KStrPwdAuthNormal ) )
       
   325                 {
       
   326                 // Normal, => auth. not secure, plain text NOT disabled
       
   327                 iPlugin.SetBoolAttributeL( aField, EFalse );
       
   328                 }
       
   329             else if ( !aPtrTag->CompareF( KStrPwdAuthSecure ) )
       
   330                 {
       
   331                 // Secure, => auth. secure, plain text disabled
       
   332                 iPlugin.SetBoolAttributeL( aField, ETrue );
       
   333                 }
       
   334             else
       
   335                 {
       
   336                 //no valid data is given - default value is used
       
   337                 CLOG_WRITE( "! Error : Invalid password authentication. Default:Secure ");  
       
   338                 iPlugin.SetBoolAttributeL( aField, ETrue );
       
   339                 }
       
   340             break;
       
   341             }
       
   342         case EPacketDataPDPType:
       
   343             {
       
   344             if ( !aPtrTag->CompareF( KStrNetworkIPv4 ) )
       
   345                 {
       
   346                 iPlugin.SetIntAttributeL( aField, RPacketContext::EPdpTypeIPv4 );
       
   347                 }
       
   348             else if ( !aPtrTag->CompareF( KStrNetworkIPv6 ) )
       
   349                 {
       
   350                 iPlugin.SetIntAttributeL( aField, RPacketContext::EPdpTypeIPv6 );
       
   351                 }
       
   352             else
       
   353                 {
       
   354                 iPlugin.SetIntAttributeL( aField, RPacketContext::EPdpTypeIPv4 );
       
   355                 CLOG_WRITE( "! Error : Invalid Network type. Default:IPv4" )
       
   356                 }
       
   357             break;
       
   358             }
       
   359         case EPacketDataApType:
       
   360         		{
       
   361         		if ( !aPtrTag->CompareF( KStrISPInternet ) )
       
   362             		{
       
   363             		iPlugin.SetIntAttributeL( aField, 0 );              
       
   364                 }
       
   365             else if ( !aPtrTag->CompareF( KStrISPWAP ) )
       
   366                 {
       
   367                 iPlugin.SetIntAttributeL( aField, 1 );                              
       
   368             		}
       
   369             else
       
   370                	{
       
   371                	iPlugin.SetIntAttributeL( aField, 2 );
       
   372                 }  
       
   373         		break;
       
   374         	}
       
   375         default:
       
   376             {
       
   377             break;
       
   378             }
       
   379         }//switch
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------
       
   383 // CProcessorPacketData::AddLingerL
       
   384 // ---------------------------------------------------------
       
   385 //
       
   386 void CProcessorPacketData::AddLingerL( const TInt aIapId, const TInt aLingerInterval)
       
   387     {
       
   388     TInt    err( KErrNone );
       
   389     
       
   390     // Open repository
       
   391     CRepository* repository = CRepository::NewLC( KCRUidPDPContextManager );
       
   392     
       
   393     // Find if an entry for "iapId" already exists in CentRep 
       
   394     RArray< TUint32 > foundKeys;
       
   395     foundKeys.Reset();
       
   396     
       
   397     err = repository->FindEqL( KIapColumn,       // partial key
       
   398                                KColumnMask,      // key mask
       
   399                                aIapId,           // value
       
   400                                foundKeys );      // found keys
       
   401     
       
   402     if ( err == KErrNone || err == KErrNotFound )
       
   403         {
       
   404         if ( foundKeys.Count() == 0 )
       
   405             {
       
   406             // Add a new entry
       
   407             TInt arrayCount( 0 );
       
   408             
       
   409             // Get number of iapId&linger entries in Centrep
       
   410             err = repository->Get( KPdpContextManagerLingerArrayCount, 
       
   411                                    arrayCount );
       
   412         
       
   413             if ( err == KErrNone )
       
   414                 {
       
   415                 arrayCount++;
       
   416                 
       
   417                 err = repository->Create( ( KIapColumn | arrayCount ), aIapId ); 
       
   418                 
       
   419                 if ( err == KErrNone )
       
   420                     {
       
   421                     err = repository->Create( ( KLingerColumn | arrayCount ), 
       
   422                                                aLingerInterval );     
       
   423                     }
       
   424                 
       
   425                 if ( err == KErrNone )
       
   426                     {
       
   427                     // Update number of iapId&linger entries in Centrep
       
   428                     err = repository->Set( KPdpContextManagerLingerArrayCount, 
       
   429                                            arrayCount );
       
   430                     }
       
   431                 }
       
   432             }
       
   433         else
       
   434             {
       
   435             // Update existing entry on current row
       
   436             TInt32 row = foundKeys[ 0 ] & KRowMask;
       
   437             
       
   438             err = repository->Set( ( KLingerColumn | row ), aLingerInterval ); 
       
   439             }         
       
   440         }
       
   441         
       
   442     foundKeys.Close();
       
   443     CleanupStack::PopAndDestroy( repository );
       
   444     
       
   445     User::LeaveIfError( err );
       
   446     }
       
   447 
       
   448 // ---------------------------------------------------------
       
   449 // CProcessorPacketData::SaveLingerSettingsL
       
   450 // ---------------------------------------------------------
       
   451 //
       
   452 void CProcessorPacketData::SaveLingerSettingsL()
       
   453     {
       
   454     for ( TInt i(0); i < iLingerSettings->Count(); i++ )
       
   455         {
       
   456         TInt id = GetPluginIdL(((*iLingerSettings)[i])->iName);
       
   457         
       
   458         TLex16 lex(*((*iLingerSettings)[i])->iLinger);
       
   459         TInt linger( 0 );
       
   460         if ( lex.Val( linger ) == KErrNone )         
       
   461             {
       
   462             AddLingerL( id, linger);
       
   463             }
       
   464             else 
       
   465             {
       
   466             // no valid data is given - default value is used
       
   467             AddLingerL( id, KDefaultLinger); 
       
   468             }
       
   469         }
       
   470         iLingerSettings->ResetAndDestroy();
       
   471     }
       
   472      
       
   473 // End of File.