XDMEngine/XdmProvisioning/src/xdmprovitem.cpp
changeset 33 ad6f19461b2a
parent 0 c8caa15ef882
child 25 e53c01f160bc
equal deleted inserted replaced
29:0da3f27f7ab2 33:ad6f19461b2a
       
     1 /*
       
     2 * Copyright (c) 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:    Provisioning item.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <CWPParameter.h>
       
    23 #include <CWPCharacteristic.h>
       
    24 #include <commdb.h>
       
    25 #include <XdmSettingsCollection.h>
       
    26 #include <XdmSettingsApi.h>
       
    27 
       
    28 #include "xdmprovitem.h"
       
    29 
       
    30 #ifdef _DEBUG
       
    31     #include "xdmprovadapter.h"
       
    32 #endif
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CXdmProvItem::CXdmProvItem
       
    37 // 
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CXdmProvItem::CXdmProvItem():
       
    41     iXdmSettingsId( KErrNotFound ),
       
    42     iAppId( KNullDesC ),
       
    43     iAppName( KNullDesC ),
       
    44     iProviderId( KNullDesC ),
       
    45     iSipReference( NULL ),
       
    46     iToNapId( KNullDesC ),
       
    47     iNapId( NULL ),
       
    48     iNapName( KNullDesC ),
       
    49     iAppRef( KNullDesC ),
       
    50     iXcapRootUri( KNullDesC ),
       
    51     iUserName( KNullDesC ),
       
    52     iPassword( KNullDesC ),
       
    53     iAuthType( KNullDesC ),
       
    54     iSettingsSaved( EFalse )
       
    55     {
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CXdmProvItem::NewL
       
    60 // Two-phased constructor.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CXdmProvItem* CXdmProvItem::NewL()
       
    64     {
       
    65     CXdmProvItem* self = new (ELeave) CXdmProvItem();
       
    66     return self;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CXdmProvItem::~CXdmProvItem
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CXdmProvItem::~CXdmProvItem()
       
    74     {
       
    75     iToAppReferences.Close();
       
    76     delete iSipReference;
       
    77     delete iNapId;
       
    78     }    
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CXdmProvItem::Validate
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 TBool CXdmProvItem::Validate() const
       
    85     {
       
    86     if ( !iAppId.Length() )
       
    87         {
       
    88 #ifdef _DEBUG 
       
    89     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::Validate  iAppId missing" ) );
       
    90 #endif
       
    91         return EFalse;
       
    92         }
       
    93     else if ( iAppId.Compare( KXdmProvAppId ) )
       
    94         {
       
    95 #ifdef _DEBUG 
       
    96     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::Validate wrong iAppId" ) );
       
    97 #endif
       
    98         return EFalse;
       
    99         }
       
   100     else if ( !iAppName.Length() )
       
   101         {
       
   102 #ifdef _DEBUG 
       
   103     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::Validate iAppName missing" ) );
       
   104 #endif
       
   105         return EFalse;
       
   106         }
       
   107      else if ( !iToNapId.Length() )
       
   108         {
       
   109 #ifdef _DEBUG 
       
   110     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::Validate iNapId missing" ) );
       
   111 #endif
       
   112         return EFalse;
       
   113         }
       
   114      else if ( !iXcapRootUri.Length() )
       
   115         {
       
   116 #ifdef _DEBUG 
       
   117     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::Validate iXcapRootUri missing" ) );
       
   118 #endif
       
   119         return EFalse;
       
   120         }
       
   121     else
       
   122         {
       
   123 #ifdef _DEBUG 
       
   124     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::Validate returns true" ) );
       
   125 #endif
       
   126         return ETrue;   
       
   127         }
       
   128     }
       
   129         
       
   130 // -----------------------------------------------------------------------------
       
   131 // CXdmProvItem::Name
       
   132 // -----------------------------------------------------------------------------
       
   133 //  
       
   134 const TDesC& CXdmProvItem::Name() const
       
   135     {
       
   136     return iAppName; 
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CXdmProvItem::ApplicationId
       
   141 // -----------------------------------------------------------------------------
       
   142 //  
       
   143 const TDesC& CXdmProvItem::ApplicationId() const
       
   144     {
       
   145     return iAppId;
       
   146     }
       
   147     
       
   148 // -----------------------------------------------------------------------------
       
   149 // CXdmProvItem::XdmSettingsId
       
   150 // -----------------------------------------------------------------------------
       
   151 //  
       
   152 TInt CXdmProvItem::XdmSettingsId() const
       
   153     {
       
   154     return iXdmSettingsId;
       
   155     }
       
   156     
       
   157 // -----------------------------------------------------------------------------
       
   158 // CXdmProvItem::AppReference
       
   159 // -----------------------------------------------------------------------------
       
   160 //  
       
   161 const TDesC& CXdmProvItem::AppReference() const
       
   162     {
       
   163     return iAppRef;
       
   164     }
       
   165     
       
   166 // -----------------------------------------------------------------------------
       
   167 // CXdmProvItem::SaveL
       
   168 // -----------------------------------------------------------------------------
       
   169 //  
       
   170 TInt CXdmProvItem::SaveL()
       
   171     {
       
   172 #ifdef _DEBUG 
       
   173     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::SaveL" ) );
       
   174 #endif
       
   175  
       
   176     if( !iSettingsSaved )
       
   177         {
       
   178         CXdmSettingsCollection* settings = new (ELeave) CXdmSettingsCollection();
       
   179         CleanupStack::PushL( settings );            // << settings
       
   180         settings->AppendL( iAppId, EXdmPropAppId );
       
   181         CheckExistingNamesL();
       
   182         settings->AppendL( iAppName, EXdmPropName );
       
   183         settings->AppendL( iProviderId, EXdmPropProvId );
       
   184         FindAccessPointIdL();              
       
   185         settings->AppendL( *iNapId, EXdmPropToNapId );
       
   186         if( iSipReference )
       
   187             {
       
   188             settings->AppendL( *iSipReference, EXdmPropToAppRef ); 
       
   189             }
       
   190         settings->AppendL( iXcapRootUri, EXdmPropUri );
       
   191         settings->AppendL( iUserName, EXdmPropAuthName );
       
   192         settings->AppendL( iPassword, EXdmPropAuthSecret );
       
   193         settings->AppendL( iAuthType, EXdmPropAuthType );
       
   194         iXdmSettingsId = TXdmSettingsApi::CreateCollectionL( *settings );
       
   195         CleanupStack::PopAndDestroy( settings );    // >>> settings
       
   196         iSettingsSaved = ETrue;
       
   197 #ifdef _DEBUG 
       
   198     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::SaveL settings saved" ) );
       
   199 #endif
       
   200         }
       
   201     
       
   202     return KErrNone;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CXdmProvItem::ToAppReferences
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 const RArray<TPtrC>& CXdmProvItem::ToAppReferences() const
       
   210     {
       
   211     return iToAppReferences;
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CXdmProvItem::VisitL
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CXdmProvItem::VisitL( CWPCharacteristic& aCharacteristic )
       
   219     {
       
   220     if ( KWPResource == aCharacteristic.Type( ) )
       
   221         {
       
   222          aCharacteristic.AcceptL( *this );
       
   223 #ifdef _DEBUG 
       
   224     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::VisitL CWPCharacteristic" ) );
       
   225 #endif
       
   226         }
       
   227      }
       
   228         
       
   229 // -----------------------------------------------------------------------------
       
   230 // CXdmProvItem::VisitL
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CXdmProvItem::VisitL( CWPParameter& aParameter )
       
   234     {
       
   235 #ifdef _DEBUG 
       
   236     HBufC8* value = HBufC8::NewLC( aParameter.Value().Length() );   // << value
       
   237     TPtr8 bufferPtr = value->Des();
       
   238     bufferPtr.Copy( aParameter.Value() );
       
   239     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::VisitL CWPParameter aParameter.Value() =%S" ), &bufferPtr );
       
   240     CleanupStack::PopAndDestroy( value );                           // >>> value
       
   241 #endif
       
   242     switch( aParameter.ID() )
       
   243         {
       
   244         case EWPParameterAppID:
       
   245             {
       
   246             iAppId.Set( aParameter.Value() );
       
   247 #ifdef _DEBUG 
       
   248     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterAppID" ) );
       
   249 #endif
       
   250             }
       
   251             break;
       
   252     
       
   253         case EWPParameterProviderID:
       
   254             {
       
   255             iProviderId.Set( aParameter.Value() );
       
   256 #ifdef _DEBUG 
       
   257     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterProviderID" ) );
       
   258 #endif
       
   259             }
       
   260             break;
       
   261 
       
   262         case EWPParameterName:
       
   263             {
       
   264             iAppName.Set( aParameter.Value() );
       
   265 #ifdef _DEBUG 
       
   266     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterName" ) );
       
   267 #endif
       
   268             }
       
   269             break;  
       
   270             
       
   271         case EWPParameterToAppRef:
       
   272             {
       
   273             iToAppReferences.Append( aParameter.Value() );  
       
   274 #ifdef _DEBUG 
       
   275     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterToAppRef" ) );
       
   276 #endif
       
   277             }
       
   278             break;
       
   279     
       
   280         case EWPParameterToNapID:
       
   281             {
       
   282             iToNapId.Set( aParameter.Value() );
       
   283 #ifdef _DEBUG 
       
   284     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterToNapID" ) );
       
   285 #endif
       
   286             }
       
   287             break; 
       
   288             
       
   289         case EWPParameterURI:
       
   290             {
       
   291             iXcapRootUri.Set( aParameter.Value() );
       
   292 #ifdef _DEBUG 
       
   293     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterURI" ) );
       
   294 #endif
       
   295             }
       
   296             break;
       
   297 
       
   298         case EWPParameterAAuthName:
       
   299             {
       
   300             iUserName.Set( aParameter.Value() );
       
   301 #ifdef _DEBUG 
       
   302     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterAAuthName" ) );
       
   303 #endif
       
   304             }
       
   305             break;  
       
   306             
       
   307         case EWPParameterAAuthSecret:
       
   308             {
       
   309             iPassword.Set( aParameter.Value() );
       
   310 #ifdef _DEBUG 
       
   311     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterAAuthSecret" ) );
       
   312 #endif
       
   313             }
       
   314             break;
       
   315       
       
   316         case EWPParameterAAuthType:
       
   317             {
       
   318             iAuthType.Set( aParameter.Value() );
       
   319 #ifdef _DEBUG 
       
   320     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterAAuthType" ) );
       
   321 #endif
       
   322             }
       
   323             break; 
       
   324             
       
   325         case EWPParameterAppRef:
       
   326             {
       
   327             iAppRef.Set( aParameter.Value() );
       
   328 #ifdef _DEBUG 
       
   329     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::EWPParameterAppRef" ) );
       
   330 #endif
       
   331             }
       
   332             break;   
       
   333         default:
       
   334             {
       
   335             DetermineNamedParameter( aParameter.Name(), aParameter.Value() );
       
   336             }
       
   337             break;
       
   338         }
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CXdmProvItem::DetermineNamedParameter
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CXdmProvItem::DetermineNamedParameter( const TDesC& aName, const TDesC& aValue )
       
   346     {
       
   347     if ( !aName.Compare( KXdmProvAppRef ) )
       
   348         {
       
   349         iAppRef.Set( aValue );
       
   350         }
       
   351     else if ( !aName.Compare( KXdmProvToAppRef ) )
       
   352         {
       
   353         iToAppReferences.Append( aValue ); 
       
   354         }
       
   355     }
       
   356 // -----------------------------------------------------------------------------
       
   357 // CXdmProvItem::VisitLinkL
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 void CXdmProvItem::VisitLinkL( CWPCharacteristic& aLink )
       
   361     {
       
   362 #ifdef _DEBUG 
       
   363     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::VisitLinkL" ) );
       
   364 #endif
       
   365     if( KWPNapDef == aLink.Type() )
       
   366         {        
       
   367         // check that this is the correct one 
       
   368         CArrayFix<TPtrC>* napId = new (ELeave) CArrayFixFlat<TPtrC>(1);
       
   369         CleanupStack::PushL( napId );           // << napId
       
   370         aLink.ParameterL( EWPParameterNapID, napId );
       
   371         if ( 0 < napId->Count() )
       
   372             {
       
   373             if ( !napId->At(0).Compare( iToNapId ) )
       
   374                 {
       
   375                 SetNapDefL( aLink );
       
   376                 }
       
   377             }      
       
   378         CleanupStack::PopAndDestroy( napId );   // >>> napId
       
   379         }
       
   380     }
       
   381     
       
   382 // -----------------------------------------------------------------------------
       
   383 // CXdmProvItem::SetNapDefL
       
   384 // -----------------------------------------------------------------------------
       
   385 //  
       
   386 void CXdmProvItem::SetNapDefL ( CWPCharacteristic& aLink )
       
   387     {
       
   388 #ifdef _DEBUG 
       
   389     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::SetNapDefL" ) );
       
   390 #endif  
       
   391     // find the name of the access point 
       
   392     CArrayFix<TPtrC>* name = new (ELeave) CArrayFixFlat<TPtrC>(1);
       
   393     CleanupStack::PushL( name );        // << name
       
   394     aLink.ParameterL( EWPParameterName, name );
       
   395     if ( name->Count() > 0 )
       
   396         {
       
   397         iNapName.Set( name->At(0) );
       
   398         }
       
   399     CleanupStack::PopAndDestroy( name ); // >>> name
       
   400         
       
   401 #ifdef _DEBUG 
       
   402     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::SetNapDefL done" ) );
       
   403 #endif  
       
   404     }
       
   405 // -----------------------------------------------------------------------------
       
   406 // CXdmProvItem::SetSipSettingsIdL
       
   407 // -----------------------------------------------------------------------------
       
   408 //  
       
   409 void CXdmProvItem::SetSipSettingsIdL( const TDesC8& aStorageIdValue )
       
   410     {
       
   411     delete iSipReference;
       
   412     iSipReference = NULL;
       
   413     iSipReference = HBufC::NewL( aStorageIdValue.Length() ); 
       
   414     iSipReference->Des().Copy( aStorageIdValue );
       
   415     }   
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CXdmProvItem::FindAccessPointIdL
       
   419 // -----------------------------------------------------------------------------
       
   420 // 
       
   421 void CXdmProvItem::FindAccessPointIdL ()
       
   422     {       
       
   423             
       
   424     TInt result( KErrNone );
       
   425     TUint32 idNum;
       
   426     TBuf<KXdmProvNameLength> name;   
       
   427     // Get IAP names and ids from the database
       
   428     CCommsDatabase* commsDb = CCommsDatabase::NewL( EDatabaseTypeIAP ); 
       
   429     CleanupStack::PushL( commsDb );             // << commsDb
       
   430     commsDb->ShowHiddenRecords();    
       
   431     CCommsDbTableView* view = commsDb->OpenTableLC( TPtrC( IAP ) ); // << view    
       
   432     result = view->GotoFirstRecord();
       
   433     
       
   434     while( KErrNone == result )
       
   435         {
       
   436         view->ReadTextL( TPtrC( COMMDB_NAME ), name );
       
   437         if ( KErrNotFound != name.Find( iNapName ) )
       
   438             {
       
   439             view->ReadUintL( TPtrC( COMMDB_ID ), idNum );
       
   440 #ifdef _DEBUG 
       
   441     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::FindAccessPointIdL IAP found id=%d" ), idNum );
       
   442 #endif
       
   443             }
       
   444         result = view->GotoNextRecord();
       
   445         }
       
   446 #ifdef _DEBUG 
       
   447     CXdmProvAdapter::WriteToLog( _L8( "CXdmProvItem::FindAccessPointIdL IAP using id=%d" ), idNum );
       
   448 #endif
       
   449     CleanupStack::PopAndDestroy( 2, commsDb );  // >>> view, commsDb
       
   450     TBuf<KXdmProvIdLength> id;
       
   451     id.AppendNum( idNum, EDecimal );
       
   452     delete iNapId;
       
   453     iNapId = NULL;
       
   454     iNapId = id.AllocL();
       
   455     }
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CXdmProvItem::CheckExistingNamesL()
       
   459 // -----------------------------------------------------------------------------
       
   460 // 
       
   461 void CXdmProvItem::CheckExistingNamesL( )
       
   462     {    
       
   463     TBool ready( EFalse );  
       
   464     RArray<TInt> settingIds;
       
   465     CleanupClosePushL( settingIds );                // << settingIds
       
   466     CDesCArray* settingNames = TXdmSettingsApi::CollectionNamesLC( settingIds ); // << settingNames
       
   467     TInt index( 0 );
       
   468     while ( !ready )
       
   469         {
       
   470         TBool found ( EFalse );
       
   471         TInt count = settingNames->MdcaCount();
       
   472         TBuf<KXdmProvBufLength> tempName;
       
   473         tempName.Copy( iAppName );
       
   474         if ( index > 0 )
       
   475             {
       
   476             tempName.Append( KXdmProvStartBracket );
       
   477             tempName.AppendNumFixedWidth( index, EDecimal, 2 );
       
   478             tempName.Append( KXdmProvCloseBracket );
       
   479             }
       
   480         for ( TInt i(0); i < count && !found; i++ )
       
   481             {
       
   482             if ( !settingNames->MdcaPoint(i).CompareF( tempName ) )
       
   483                 {
       
   484                 found = ETrue;
       
   485                 index++;
       
   486                 }
       
   487             }
       
   488         if ( !found )
       
   489             {
       
   490             ready = ETrue;
       
   491             iAppName.Set( tempName );
       
   492             }
       
   493         }
       
   494     // only number used in next function, type of RArray
       
   495     CleanupStack::PopAndDestroy( 2 );  // >>> settingNames, settingIds
       
   496     }
       
   497 
       
   498 
       
   499 //  End of File  
       
   500