XDMEngine/XdmDeviceManagement/src/xdmdmadapter.cpp
changeset 36 a4b9e097ca0b
parent 0 c8caa15ef882
child 8 aca99fb8a3dd
equal deleted inserted replaced
32:32463a6c57b3 36:a4b9e097ca0b
       
     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:    DM OMA XDM Settings Adapter
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <implementationproxy.h>
       
    22 #include <utf.h>
       
    23 #include <nsmldmuri.h>
       
    24 #include <XdmSettingsApi.h>
       
    25 #include <XdmSettingsCollection.h>
       
    26 #include <XdmSettingsProperty.h>
       
    27 #include "xdmdmadapter.h"
       
    28 
       
    29 #ifdef _DEBUG
       
    30     #include <flogger.h>
       
    31 #endif
       
    32 
       
    33 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CXdmDMAdapter::NewL( )
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CXdmDMAdapter* CXdmDMAdapter::NewL( MSmlDmCallback* aDmCallback )
       
    40     {
       
    41     CXdmDMAdapter* self = new (ELeave) CXdmDMAdapter( aDmCallback );
       
    42 #ifdef _DEBUG
       
    43     WriteToLog(_L8("CXdmDMAdapter::NewL(): end") );
       
    44 #endif
       
    45     return self;
       
    46     }
       
    47     
       
    48 // -----------------------------------------------------------------------------
       
    49 // CXdmDMAdapter::CXdmDMAdapter()
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CXdmDMAdapter::CXdmDMAdapter( MSmlDmCallback* aDmCallback ) : 
       
    53 CSmlDmAdapter( aDmCallback )
       
    54     {
       
    55 #ifdef _DEBUG
       
    56     WriteToLog(_L8("CXdmDMAdapter::CXdmDMAdapter()") );
       
    57 #endif
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CXdmDMAdapter::~CXdmDMAdapter()
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CXdmDMAdapter::~CXdmDMAdapter()
       
    65     {
       
    66 #ifdef _DEBUG
       
    67     WriteToLog(_L8("CXdmDMAdapter::~CXdmDMAdapter()") );
       
    68 #endif
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 //  CXdmDMAdapter::DDFVersionL
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CXdmDMAdapter::DDFVersionL( CBufBase& aDDFVersion )
       
    76     {   
       
    77     aDDFVersion.InsertL( 0, KXdmDDFVersion );
       
    78 #ifdef _DEBUG
       
    79     WriteToLog(_L8("CXdmDMAdapter::DDFVersionL(TDes& aDDFVersion)") );
       
    80 #endif
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 //  CXdmDMAdapter::DDFStructureL
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CXdmDMAdapter::DDFStructureL( MSmlDmDDFObject& aDDF )
       
    88     {
       
    89 #ifdef _DEBUG
       
    90     WriteToLog(_L8("CXdmDMAdapter::DDFStructureL(): begin") );
       
    91 #endif    
       
    92 
       
    93     // For OMA_XDM 
       
    94     TSmlDmAccessTypes accTypeGet;
       
    95     accTypeGet.SetGet();
       
    96      
       
    97     // For OMA_XDM/<X> 
       
    98     TSmlDmAccessTypes accTypeAll;
       
    99     accTypeAll.SetAdd();
       
   100     accTypeAll.SetGet();
       
   101     accTypeAll.SetReplace();
       
   102     accTypeAll.SetDelete();
       
   103     
       
   104     // For leaf nodes
       
   105     TSmlDmAccessTypes accTypeNoDelete;
       
   106     accTypeNoDelete.SetAdd();
       
   107     accTypeNoDelete.SetGet();
       
   108     accTypeNoDelete.SetReplace();
       
   109 
       
   110     // ./OMA_XDM
       
   111     MSmlDmDDFObject& omaXdmNode = aDDF.AddChildObjectL( KXdmDmNodeName );
       
   112     FillNodeInfoL( omaXdmNode, accTypeGet, MSmlDmDDFObject::EOne,
       
   113                   MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   114                   KXdmDmNodeNameDescription );
       
   115                   
       
   116     // ./OMA_XDM/<X> 
       
   117     MSmlDmDDFObject& rtNode = omaXdmNode.AddChildObjectGroupL();
       
   118     FillNodeInfoL( rtNode, accTypeAll, MSmlDmDDFObject::EOneOrMore,
       
   119                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode,
       
   120                   KXdmDmDynamicDescription );
       
   121 
       
   122     // ./OMA_XDM/<X>/APPID            
       
   123     MSmlDmDDFObject& appIdNode = rtNode.AddChildObjectL( KXdmDmAppId );
       
   124     FillNodeInfoL( appIdNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   125                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   126                   KXdmDmAppIdDescription );
       
   127                   
       
   128     // ./OMA_XDM/<X>/NAME            
       
   129     MSmlDmDDFObject& nameNode = rtNode.AddChildObjectL( KXdmDmName );
       
   130     FillNodeInfoL( nameNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   131                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   132                   KXdmDmNameDescription );
       
   133             
       
   134     // ./OMA_XDM/<X>/PROVIDER-ID           
       
   135     MSmlDmDDFObject& provIdNode = rtNode.AddChildObjectL( KXdmDmProviderId );
       
   136     FillNodeInfoL( provIdNode, accTypeNoDelete,MSmlDmDDFObject::EZeroOrOne,
       
   137                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   138                   KXdmDmProviderIdDescription );    
       
   139                                
       
   140     // ./OMA_XDM/<X>/ToConRef
       
   141     MSmlDmDDFObject& toConRefNode = rtNode.AddChildObjectL( KXdmDmToConRef );
       
   142     FillNodeInfoL( toConRefNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   143                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode,
       
   144                   KXdmDmToConRefDescription);
       
   145                   
       
   146     // ./OMA_XDM/<X>/ToConRef/<X> (TO-NAPID)          
       
   147     MSmlDmDDFObject& napIdNode = toConRefNode.AddChildObjectL( KXdmDmToNapId );
       
   148     FillNodeInfoL( napIdNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne, 
       
   149                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode,
       
   150                   KXdmDmToNapIdDescription );                 
       
   151                                    
       
   152     // ./OMA_XDM/<X>/ToConRef/TO-NAPID/ConRef                                             
       
   153     MSmlDmDDFObject& napIdRefNode = napIdNode.AddChildObjectL( KXdmDmConRef );
       
   154     FillNodeInfoL( napIdRefNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne, 
       
   155                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   156                   KXdmDmConRefDescription );
       
   157                   
       
   158     // ./OMA_XDM/<X>/ToConRef/<X> (SIP)          
       
   159     MSmlDmDDFObject& sipNode = toConRefNode.AddChildObjectL( KXdmDmSip );
       
   160     FillNodeInfoL( sipNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne, 
       
   161                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode,
       
   162                   KXdmDmSipDescription );                 
       
   163                                    
       
   164     // ./OMA_XDM/<X>/ToConRef/SIP/ConRef                                             
       
   165     MSmlDmDDFObject& sipRefNode = sipNode.AddChildObjectL( KXdmDmConRef );
       
   166     FillNodeInfoL( sipRefNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne, 
       
   167                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   168                   KXdmDmConRefDescription );
       
   169     
       
   170     // ./OMA_XDM/<X>/URI          
       
   171     MSmlDmDDFObject& uriNode = rtNode.AddChildObjectL( KXdmDmUri );
       
   172     FillNodeInfoL( uriNode, accTypeNoDelete, MSmlDmDDFObject::EOne,
       
   173                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   174                   KXdmDmUriDescription );  
       
   175                   
       
   176     // ./OMA_XDM/<X>/AAUTHNAME         
       
   177     MSmlDmDDFObject& userIdNode = rtNode.AddChildObjectL( KXdmDmAAuthName );
       
   178     FillNodeInfoL( userIdNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   179                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   180                   KXdmDmAAuthNameDescription );     
       
   181                   
       
   182     // ./OMA_XDM/<X>/AAUTHSECRET         
       
   183     MSmlDmDDFObject& pwdNode = rtNode.AddChildObjectL( KXdmDmAAuthSecret );
       
   184     FillNodeInfoL( pwdNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   185                   MSmlDmDDFObject::EDynamic,MSmlDmDDFObject::EChr,
       
   186                   KXdmDmAAuthSecretDescription ); 
       
   187                     
       
   188     // ./OMA_XDM/<X>/AAUTHTYPE         
       
   189     MSmlDmDDFObject& authTypeNode = rtNode.AddChildObjectL( KXdmDmAAuthType );
       
   190     FillNodeInfoL( authTypeNode, accTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   191                   MSmlDmDDFObject::EDynamic,MSmlDmDDFObject::EChr,
       
   192                   KXdmDmAAuthTypeDescription );
       
   193   
       
   194 #ifdef _DEBUG
       
   195     WriteToLog(_L8("CXdmDMAdapter::DDFStructureL(): end") );
       
   196 #endif 
       
   197     }
       
   198     
       
   199 // -----------------------------------------------------------------------------
       
   200 // CXdmDMAdapter::ChildURIListL
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 void CXdmDMAdapter::ChildURIListL( const TDesC8& aUri, 
       
   204                                    const TDesC8& /*aLUID*/, 
       
   205                                    const CArrayFix<TSmlDmMappingInfo>& 
       
   206                                        /*aPreviousURISegmentList*/, 
       
   207                                    const TInt aResultsRef, 
       
   208                                    const TInt aStatusRef )
       
   209     {
       
   210 #ifdef _DEBUG
       
   211     WriteToLog(_L8("CXdmDMAdapter::ChildURIListL(): begin") );
       
   212 #endif    
       
   213     
       
   214     CSmlDmAdapter::TError retValue = CSmlDmAdapter::EOk;
       
   215 
       
   216     CBufBase* currentList = CBufFlat::NewL( 1 );
       
   217     CleanupStack::PushL( currentList ); // << currentList
       
   218     
       
   219     const TPtrC8 lastUriSeg = NSmlDmURI::LastURISeg( aUri );
       
   220     TBuf8<KSmlMaxURISegLen> segmentName;
       
   221  
       
   222     // ./OMA_XDM
       
   223     if( Match( lastUriSeg, KXdmDmNodeName ) ) 
       
   224         {
       
   225         RArray<TInt> settingIds;
       
   226         CleanupClosePushL( settingIds );    // << settingIds
       
   227         CDesCArray* names = TXdmSettingsApi::CollectionNamesLC( settingIds ); // << names
       
   228         TInt idCount = settingIds.Count();
       
   229         for( TInt i(0); i < idCount; i++ )
       
   230             {
       
   231             segmentName.Copy( KNullDesC8 ); 
       
   232             segmentName.AppendNum( settingIds[i] );
       
   233             currentList->InsertL( currentList->Size(), segmentName );
       
   234             currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   235             }
       
   236         Callback().SetResultsL( aResultsRef, *currentList, KNullDesC8 );
       
   237         Callback().SetStatusL( aStatusRef, retValue );
       
   238         CleanupStack::PopAndDestroy( 3, currentList ); // >>> settingIds, names, currentList
       
   239         return;
       
   240         }   
       
   241 
       
   242     // ./OMA_XDM/X   
       
   243     if( NSmlDmURI::NumOfURISegs( aUri ) == KXdmDmLevel )   
       
   244         {
       
   245         segmentName.Copy( KXdmDmAppId );
       
   246         currentList->InsertL( currentList->Size(), segmentName );
       
   247         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   248         
       
   249         segmentName.Copy( KXdmDmName );
       
   250         currentList->InsertL( currentList->Size(), segmentName );
       
   251         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   252         
       
   253         segmentName.Copy( KXdmDmProviderId );
       
   254         currentList->InsertL( currentList->Size(), segmentName );
       
   255         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   256         
       
   257         segmentName.Copy( KXdmDmToConRef );
       
   258         currentList->InsertL( currentList->Size(), segmentName );
       
   259         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   260                 
       
   261         segmentName.Copy( KXdmDmUri );
       
   262         currentList->InsertL( currentList->Size(), segmentName );
       
   263         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   264         
       
   265         segmentName.Copy( KXdmDmAAuthName );
       
   266         currentList->InsertL( currentList->Size(), segmentName );
       
   267         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   268         
       
   269         segmentName.Copy( KXdmDmAAuthSecret );
       
   270         currentList->InsertL( currentList->Size(), segmentName );
       
   271         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   272         
       
   273         segmentName.Copy( KXdmDmAAuthType );
       
   274         currentList->InsertL( currentList->Size(), segmentName );
       
   275         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   276         }
       
   277         
       
   278     // ./OMA_XDM/X/ToConRef   
       
   279     else if ( Match( lastUriSeg, KXdmDmToConRef ) ) 
       
   280         {
       
   281         segmentName.Copy( KXdmDmSip );
       
   282         currentList->InsertL( currentList->Size(), segmentName );
       
   283         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   284         
       
   285         segmentName.Copy( KXdmDmToNapId );
       
   286         currentList->InsertL( currentList->Size(), segmentName );
       
   287         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   288         }
       
   289         
       
   290     // ./OMA_XDM/X/ToConRef/SIP
       
   291     else if( Match( lastUriSeg, KXdmDmSip ) ) 
       
   292         {
       
   293         segmentName.Copy( KXdmDmConRef );
       
   294         currentList->InsertL( currentList->Size(), segmentName );
       
   295         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   296         }
       
   297         
       
   298     // ./OMA_XDM/X/ToConRef/TO-NAPID
       
   299     else if( Match ( lastUriSeg, KXdmDmToNapId ) ) 
       
   300         {
       
   301         segmentName.Copy( KXdmDmConRef );
       
   302         currentList->InsertL( currentList->Size(), segmentName );
       
   303         currentList->InsertL( currentList->Size(), KXdmDmSeparator );
       
   304         }
       
   305     else
       
   306         {
       
   307         // if none of asked nodes found return error.
       
   308         retValue = CSmlDmAdapter::ENotFound;
       
   309         }
       
   310        
       
   311     Callback().SetResultsL( aResultsRef, *currentList, KNullDesC8 );
       
   312     Callback().SetStatusL( aStatusRef, retValue );
       
   313     CleanupStack::PopAndDestroy( currentList ); // >>> currentList  
       
   314 #ifdef _DEBUG
       
   315     WriteToLog(_L8("CXdmDMAdapter::ChildURIListL(): end") );
       
   316 #endif
       
   317     }    
       
   318  
       
   319 // -----------------------------------------------------------------------------
       
   320 //  CXdmDMAdapter::FetchLeafObjectL
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 void CXdmDMAdapter::FetchLeafObjectL( const TDesC8& aUri, 
       
   324                                       const TDesC8& aLUID, 
       
   325                                       const TDesC8& aType, 
       
   326                                       const TInt aResultsRef, 
       
   327                                       const TInt aStatusRef )
       
   328     {
       
   329 #ifdef _DEBUG
       
   330     WriteToLog(_L8("CXdmDMAdapter::FetchLeafObjectL(): begin") );
       
   331 #endif  
       
   332 
       
   333     TInt settingsId = FindSettingsIdL( aLUID, aUri );
       
   334 
       
   335     CBufBase* result = CBufFlat::NewL( KXdmDefaultResultSize );
       
   336     CleanupStack::PushL( result );    // << result
       
   337     CSmlDmAdapter::TError status = FetchObjectL( aUri, *result, settingsId );
       
   338     if( status == CSmlDmAdapter::EOk )
       
   339         {
       
   340         Callback().SetResultsL( aResultsRef, *result, aType );
       
   341         }
       
   342     Callback().SetStatusL( aStatusRef, status );
       
   343     CleanupStack::PopAndDestroy( result );  // >>> result
       
   344     
       
   345 #ifdef _DEBUG
       
   346     WriteToLog(_L8("CXdmDMAdapter::FetchLeafObjectL(): end") );
       
   347 #endif
       
   348     }
       
   349     
       
   350 // -----------------------------------------------------------------------------
       
   351 // CSmlDmAdapter::TError FetchObjectL
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 CSmlDmAdapter::TError CXdmDMAdapter::FetchObjectL( const TDesC8& aUri, 
       
   355                                                    CBufBase& aObject,
       
   356                                                    TInt aSettingsId )
       
   357     {
       
   358 #ifdef _DEBUG
       
   359     WriteToLog(_L8("CXdmDMAdapter::FetchObjectL(): begin") );
       
   360 #endif    
       
   361     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   362       
       
   363     TXdmSettingsProperty property ( EXdmPropNotFound );
       
   364     TPtrC8 lastUriSeg = NSmlDmURI::LastURISeg( aUri );
       
   365     // APPID
       
   366     if( Match( lastUriSeg, KXdmDmAppId ) )
       
   367         {
       
   368         property = EXdmPropAppId;                          
       
   369         }
       
   370     // NAME
       
   371     else if( Match( lastUriSeg, KXdmDmName ) )
       
   372         {
       
   373         property = EXdmPropName;  
       
   374         }   
       
   375     // PROVIDER-ID  
       
   376     else if( Match( lastUriSeg, KXdmDmProviderId ) )
       
   377         {
       
   378         property = EXdmPropProvId;  
       
   379         }
       
   380     // URI
       
   381     else if( Match( lastUriSeg, KXdmDmUri) )
       
   382         {
       
   383         property = EXdmPropUri;  
       
   384         }
       
   385     // AAUTHNAME
       
   386     else if( Match( lastUriSeg, KXdmDmAAuthName) )
       
   387         {
       
   388         property = EXdmPropAuthName;  
       
   389         }
       
   390     // AAUTHSECRET
       
   391     else if( Match( lastUriSeg, KXdmDmAAuthSecret) )
       
   392         {
       
   393         property = EXdmPropAuthSecret;  
       
   394         }
       
   395     // AAUTHTYPE
       
   396     else if( Match( lastUriSeg, KXdmDmAAuthType ) )
       
   397         {
       
   398         property = EXdmPropAuthType;  
       
   399         }       
       
   400     // ToConRef/SIP/ConRef
       
   401     // ToConRef/TO-NAPID/ConRef     
       
   402     else if( Match( lastUriSeg, KXdmDmConRef) )
       
   403         {
       
   404         TPtrC8 conRefUri = NSmlDmURI::RemoveLastSeg( aUri );
       
   405         TPtrC8 lastConRefSeg = NSmlDmURI::LastURISeg( conRefUri );
       
   406         
       
   407         if( Match( lastConRefSeg, KXdmDmSip ) )
       
   408             {
       
   409             return FetchSipConRefL( aSettingsId, aObject );
       
   410             }  
       
   411         else if( Match( lastConRefSeg, KXdmDmToNapId ) )
       
   412             {
       
   413             HBufC* value = NULL;
       
   414             TInt error( KErrNone );
       
   415             TRAP( error, ( value = TXdmSettingsApi::PropertyL( aSettingsId, EXdmPropToNapId ) ) );
       
   416             if ( error == KErrNone )
       
   417                 {
       
   418                 CleanupStack::PushL( value );   // << value
       
   419                 TInt iapId = DesToInt( *value ); 
       
   420                 CleanupStack::PopAndDestroy( value );   // >>> value
       
   421                 HBufC8* uri = URIFromIapIdL( iapId );
       
   422                 if( uri )
       
   423                     {
       
   424                     CleanupStack::PushL( uri ); // << uri
       
   425                     aObject.InsertL( 0, uri->Des() );
       
   426                     status = CSmlDmAdapter::EOk;
       
   427                     CleanupStack::PopAndDestroy( uri ); // uri
       
   428                     }
       
   429                 else
       
   430                     {
       
   431                     status = CSmlDmAdapter::ENotFound;
       
   432                     }
       
   433                 return status;
       
   434                 }
       
   435             }
       
   436         }
       
   437     else
       
   438         {
       
   439         status = CSmlDmAdapter::ENotFound;
       
   440         }
       
   441     // known property
       
   442     if ( status == CSmlDmAdapter::EOk )
       
   443         {
       
   444         status = GetPropertyL( aSettingsId, property, aObject ); 
       
   445         }
       
   446 
       
   447 #ifdef _DEBUG
       
   448     WriteToLog(_L8("CXdmDMAdapter::FetchObjectL(): end") );
       
   449 #endif    
       
   450     return status;
       
   451     }  
       
   452          
       
   453 // -----------------------------------------------------------------------------
       
   454 // CXdmDMAdapter::FetchLeafObjectSizeL
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 void CXdmDMAdapter::FetchLeafObjectSizeL( const TDesC8& aUri, 
       
   458                                           const TDesC8& aLUID, 
       
   459                                           const TDesC8& aType, 
       
   460                                           const TInt aResultsRef, 
       
   461                                           const TInt aStatusRef )
       
   462     {
       
   463 #ifdef _DEBUG
       
   464     WriteToLog(_L8("CXdmDMAdapter::FetchLeafObjectSizeL(): begin") );
       
   465 #endif
       
   466 
       
   467     TInt settingsId = FindSettingsIdL( aLUID, aUri );
       
   468     
       
   469     CBufBase* result = CBufFlat::NewL( KXdmDefaultResultSize );
       
   470     CleanupStack::PushL( result );
       
   471     CSmlDmAdapter::TError status = FetchObjectL( aUri, *result, settingsId );
       
   472     
       
   473     if( status == CSmlDmAdapter::EOk )
       
   474         {
       
   475         TInt objSizeInBytes = result->Size();
       
   476         
       
   477         TBuf8<KXdmDmObjectSizeWidth> stringObjSizeInBytes;
       
   478         stringObjSizeInBytes.Num( objSizeInBytes );
       
   479         
       
   480         result->Reset();
       
   481         result->InsertL( 0, stringObjSizeInBytes );
       
   482         
       
   483         Callback().SetResultsL( aResultsRef, *result, aType );
       
   484         }   
       
   485         
       
   486     Callback().SetStatusL( aStatusRef, status );
       
   487     CleanupStack::PopAndDestroy( result );  // >>> result
       
   488 #ifdef _DEBUG
       
   489     WriteToLog(_L8("CXdmDMAdapter::FetchLeafObjectSizeL(): end") );
       
   490  #endif
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CXdmDMAdapter::UpdateLeafObjectL()
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 void CXdmDMAdapter::UpdateLeafObjectL( const TDesC8& aUri, 
       
   498                                        const TDesC8& aLUID, 
       
   499                                        const TDesC8& aObject, 
       
   500                                        const TDesC8& /*aType*/, 
       
   501                                        const TInt aStatusRef )
       
   502     {
       
   503 #ifdef _DEBUG
       
   504     WriteToLog(_L8("CXdmDMAdapter::UpdateLeafObjectL(): begin") );
       
   505 #endif   
       
   506     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   507 
       
   508     TInt settingsId = FindSettingsIdL( aLUID, aUri );
       
   509     
       
   510     TXdmSettingsProperty property;
       
   511     TPtrC8 lastUriSeg = NSmlDmURI::LastURISeg( aUri );
       
   512     // APPID
       
   513     if( Match( lastUriSeg, KXdmDmAppId ) )
       
   514         {
       
   515         property = EXdmPropAppId;                          
       
   516         }
       
   517     // NAME
       
   518     else if( Match( lastUriSeg, KXdmDmName ) )
       
   519         {
       
   520         // first check if the new value is same as earlier
       
   521         HBufC* current = NULL;
       
   522         TInt error( KErrNone );
       
   523         TRAP( error, ( current = TXdmSettingsApi::PropertyL( settingsId, EXdmPropName ) ) );
       
   524         if ( error == KErrNone )
       
   525             {
       
   526             TBool same ( EFalse );
       
   527             CleanupStack::PushL( current );   // << current
       
   528             HBufC8* current8 = ConvertLC( *current ); // << current8
       
   529             if ( Match( current8->Des(), aObject ) )
       
   530                 {
       
   531                 same = ETrue;
       
   532                 }
       
   533             CleanupStack::PopAndDestroy( 2, current8 );  // >>> current, current8
       
   534             if ( same )
       
   535                 {
       
   536                 Callback().SetStatusL( aStatusRef, status );
       
   537                 return;
       
   538                 }
       
   539             }
       
   540         // if the name is already in use, new name with index is created
       
   541         HBufC* value = CheckExistingNamesLC( aObject );     // << value
       
   542         TRAP( error, TXdmSettingsApi::UpdatePropertyL( settingsId, *value, EXdmPropName ) );
       
   543         CleanupStack::PopAndDestroy( value );                      // >>> value
       
   544         if ( error != KErrNone )
       
   545             {
       
   546             status = CSmlDmAdapter::ENotFound;
       
   547             }
       
   548         Callback().SetStatusL( aStatusRef, status );
       
   549         return;  
       
   550         }   
       
   551     // PROVIDER-ID  
       
   552     else if( Match( lastUriSeg, KXdmDmProviderId ) )
       
   553         {
       
   554         property = EXdmPropProvId;  
       
   555         }
       
   556     // URI
       
   557     else if( Match( lastUriSeg, KXdmDmUri) )
       
   558         {
       
   559         property = EXdmPropUri;  
       
   560         }
       
   561     // AAUTHNAME
       
   562     else if( Match( lastUriSeg, KXdmDmAAuthName) )
       
   563         {
       
   564         property = EXdmPropAuthName;  
       
   565         }
       
   566     // AAUTHSECRET
       
   567     else if( Match( lastUriSeg, KXdmDmAAuthSecret) )
       
   568         {
       
   569         property = EXdmPropAuthSecret;  
       
   570         }
       
   571     // AAUTHTYPE
       
   572     else if( Match( lastUriSeg, KXdmDmAAuthType ) )
       
   573         {
       
   574         property = EXdmPropAuthType;  
       
   575         }           
       
   576     // ToConRef/TO-NAPID/ConRef
       
   577     // ToConRef/SIP/ConRef
       
   578     else if( Match( lastUriSeg, KXdmDmConRef ) )
       
   579         {
       
   580         TPtrC8 conRefUri = NSmlDmURI::RemoveLastSeg( aUri );
       
   581         TPtrC8 lastConRefSeg = NSmlDmURI::LastURISeg( conRefUri );
       
   582         if( Match( lastConRefSeg, KXdmDmToNapId ) )
       
   583             {
       
   584             TInt iapId = IapIdFromURIL( aObject );
       
   585             HBufC8* idBuf = IntToDes8LC( iapId ); // << idBuf
       
   586             status = UpdatePropertyL( settingsId, EXdmPropToNapId, *idBuf ); 
       
   587             CleanupStack::PopAndDestroy( idBuf );        // >>> idBuf
       
   588             Callback().SetStatusL( aStatusRef, status ); 
       
   589  #ifdef _DEBUG
       
   590     WriteToLog(_L8("CXdmDMAdapter::UpdateLeafObjectL(): TO_NAPID/ConRef end") );
       
   591  #endif
       
   592             return;
       
   593             } 
       
   594         else if( Match( lastConRefSeg, KXdmDmSip ) )
       
   595             {
       
   596             TInt sipId = GetSipIdL( aObject );
       
   597             HBufC8* idBuf = IntToDes8LC( sipId ); // << idBuf
       
   598             status = UpdatePropertyL( settingsId, EXdmPropToAppRef, *idBuf ); 
       
   599             CleanupStack::PopAndDestroy( idBuf );        // >>> idBuf
       
   600             Callback().SetStatusL( aStatusRef, status ); 
       
   601  #ifdef _DEBUG
       
   602     WriteToLog(_L8("CXdmDMAdapter::UpdateLeafObjectL(): SIP/ConRef end") );
       
   603  #endif
       
   604             return;
       
   605             }  
       
   606         else
       
   607             {
       
   608             status = CSmlDmAdapter::ENotFound;
       
   609             }           
       
   610         }  
       
   611     else
       
   612         {
       
   613         status = CSmlDmAdapter::ENotFound;
       
   614         }
       
   615     // known property
       
   616     if ( status == CSmlDmAdapter::EOk )
       
   617         {
       
   618         status = UpdatePropertyL( settingsId, property, aObject ); 
       
   619         }
       
   620 
       
   621     Callback().SetStatusL( aStatusRef, status ); 
       
   622         
       
   623 #ifdef _DEBUG
       
   624     WriteToLog(_L8("CXdmDMAdapter::UpdateLeafObjectL(): end") );
       
   625  #endif
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // CXdmDMAdapter::AddNodeObjectL
       
   630 // -----------------------------------------------------------------------------
       
   631 //
       
   632 void CXdmDMAdapter::AddNodeObjectL( const TDesC8& aUri, 
       
   633                                     const TDesC8& /*aParentLUID*/, 
       
   634                                     const TInt aStatusRef )
       
   635     {
       
   636 #ifdef _DEBUG
       
   637     WriteToLog(_L8("CXdmDMAdapter::AddNodeObjectL(): begin") );
       
   638 #endif    
       
   639   
       
   640     CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
       
   641     if ( Match( NSmlDmURI::RemoveLastSeg( aUri ), KXdmDmNodeName ) )
       
   642         {
       
   643         // create new set
       
   644         CXdmSettingsCollection* collection = new ( ELeave ) CXdmSettingsCollection;
       
   645         CleanupStack::PushL( collection );  // << collection
       
   646         collection->AppendL( KXdmDefaultId, EXdmPropSettingsId );
       
   647         TInt id = TXdmSettingsApi::CreateCollectionL( *collection );
       
   648         HBufC8* luid = IntToDes8LC( id );   // << luid
       
   649         Callback().SetMappingL( aUri, *luid );
       
   650         CleanupStack::PopAndDestroy( 2, luid );   // >>> collection, luid  
       
   651         status =  CSmlDmAdapter::EOk;  
       
   652 #ifdef _DEBUG
       
   653     WriteToLog(_L8("CXdmDMAdapter::AddNodeObjectL(): Settings created id=%d"), id );
       
   654 #endif
       
   655         }
       
   656     Callback().SetStatusL( aStatusRef, status );
       
   657     
       
   658 #ifdef _DEBUG
       
   659     WriteToLog(_L8("CXdmDMAdapter::AddNodeObjectL(): end") );
       
   660 #endif
       
   661     }
       
   662     
       
   663 // -----------------------------------------------------------------------------
       
   664 // CXdmDMAdapter::DeleteObjectL
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 void CXdmDMAdapter::DeleteObjectL( const TDesC8& aUri, 
       
   668                                    const TDesC8& aLUID, 
       
   669                                    const TInt aStatusRef )
       
   670     {
       
   671 #ifdef _DEBUG
       
   672     WriteToLog(_L8("CXdmDMAdapter::DeleteObjectL( ): begin") );
       
   673 #endif
       
   674 
       
   675     CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
       
   676     if ( Match( NSmlDmURI::RemoveLastSeg( aUri ), KXdmDmNodeName ) )
       
   677         {
       
   678         TInt id = FindSettingsIdL( aLUID, aUri );
       
   679         TInt error (KErrNone );
       
   680         TRAP( error, TXdmSettingsApi::RemoveCollectionL( id ) ); 
       
   681         if ( error == KErrNone )
       
   682             {
       
   683             status = CSmlDmAdapter::EOk;
       
   684             }
       
   685 #ifdef _DEBUG
       
   686     WriteToLog(_L8("CXdmDMAdapter::DeleteObjectL(): Settings deleted id=%d"), id );
       
   687 #endif
       
   688         }
       
   689     Callback().SetStatusL( aStatusRef, status );
       
   690     
       
   691 #ifdef _DEBUG
       
   692     WriteToLog(_L8("CXdmDMAdapter::DeleteObjectL( ): end") );
       
   693 #endif
       
   694     }
       
   695     
       
   696 // -----------------------------------------------------------------------------
       
   697 // CXdmDMAdapter::UpdateLeafObjectL
       
   698 // -----------------------------------------------------------------------------
       
   699 //
       
   700 void CXdmDMAdapter::UpdateLeafObjectL( const TDesC8& /*aUri*/, 
       
   701                                        const TDesC8& /*aLUID*/, 
       
   702                                        RWriteStream*& /*aStream*/, 
       
   703                                        const TDesC8& /*aType*/, 
       
   704                                        const TInt aStatusRef )
       
   705     {  
       
   706     // Update from stream not used
       
   707     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   708     }
       
   709     
       
   710 // -----------------------------------------------------------------------------
       
   711 // CXdmDMAdapter::ExecuteCommandL()
       
   712 // -----------------------------------------------------------------------------
       
   713 //
       
   714 void CXdmDMAdapter::ExecuteCommandL( const TDesC8& /*aUri*/, 
       
   715                                      const TDesC8& /*aLUID*/, 
       
   716                                      const TDesC8& /*aArgument*/, 
       
   717                                      const TDesC8& /*aType*/, 
       
   718                                      const TInt aStatusRef )
       
   719     {
       
   720     // Not supported 
       
   721     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   722     }
       
   723 
       
   724 // -----------------------------------------------------------------------------
       
   725 // CXdmDMAdapter::ExecuteCommandL()
       
   726 // -----------------------------------------------------------------------------
       
   727 //
       
   728 void CXdmDMAdapter::ExecuteCommandL( const TDesC8& /*aUri*/, 
       
   729                                      const TDesC8& /*aLUID*/, 
       
   730                                      RWriteStream*& /*aStream*/, 
       
   731                                      const TDesC8& /*aType*/, 
       
   732                                      const TInt aStatusRef )
       
   733     {
       
   734     // Not supported
       
   735     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   736     }
       
   737 
       
   738 // -----------------------------------------------------------------------------
       
   739 // CXdmDMAdapter::CopyCommandL()
       
   740 // -----------------------------------------------------------------------------
       
   741 //
       
   742 void CXdmDMAdapter::CopyCommandL( const TDesC8& /*aTargetURI*/, 
       
   743                                   const TDesC8& /*aTargetLUID*/, 
       
   744                                   const TDesC8& /*aSourceURI*/, 
       
   745                                   const TDesC8& /*aSourceLUID*/, 
       
   746                                   const TDesC8& /*aType*/, 
       
   747                                   TInt aStatusRef )
       
   748     {
       
   749     // Not supported
       
   750     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   751     }
       
   752 
       
   753 // -----------------------------------------------------------------------------
       
   754 // CXdmDMAdapter::StartAtomicL()
       
   755 // -----------------------------------------------------------------------------
       
   756 //
       
   757 void CXdmDMAdapter::StartAtomicL()
       
   758     {
       
   759     // Not supported
       
   760     }
       
   761 
       
   762 // -----------------------------------------------------------------------------
       
   763 // CXdmDMAdapter::CommitAtomicL()
       
   764 // -----------------------------------------------------------------------------
       
   765 //
       
   766 void CXdmDMAdapter::CommitAtomicL()
       
   767     {
       
   768     // Not supported
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // CXdmDMAdapter::RollbackAtomicL()
       
   773 // -----------------------------------------------------------------------------
       
   774 //
       
   775 void CXdmDMAdapter::RollbackAtomicL()
       
   776     {
       
   777     // Not supported
       
   778     }
       
   779 
       
   780 // -----------------------------------------------------------------------------
       
   781 // CXdmDMAdapter::StreamingSupport()
       
   782 // -----------------------------------------------------------------------------
       
   783 //
       
   784 TBool CXdmDMAdapter::StreamingSupport( TInt& /*aItemSize*/ )
       
   785     {
       
   786     return EFalse;
       
   787     }
       
   788 
       
   789 // -----------------------------------------------------------------------------
       
   790 // CXdmDMAdapter::StreamCommittedL()
       
   791 // -----------------------------------------------------------------------------
       
   792 //
       
   793 void CXdmDMAdapter::StreamCommittedL()
       
   794     {
       
   795     // Not supported
       
   796     }
       
   797     
       
   798 // -----------------------------------------------------------------------------
       
   799 // CXdmDMAdapter::CompleteOutstandingCmdsL()
       
   800 // -----------------------------------------------------------------------------
       
   801 //
       
   802 void CXdmDMAdapter::CompleteOutstandingCmdsL()
       
   803     {
       
   804 #ifdef _DEBUG
       
   805     WriteToLog(_L8("CXdmDMAdapter::CompleteOutstandingCmdsL()") );  
       
   806 #endif
       
   807     }
       
   808 
       
   809 // -----------------------------------------------------------------------------
       
   810 // CXdmDMAdapter::GetPropertyL
       
   811 // -----------------------------------------------------------------------------
       
   812 //
       
   813 CSmlDmAdapter::TError CXdmDMAdapter::GetPropertyL( TInt aSettingsId, 
       
   814                                                    TXdmSettingsProperty aProperty, 
       
   815                                                    CBufBase& aObject )
       
   816     {
       
   817     HBufC* value = NULL;
       
   818     TInt error( KErrNone );
       
   819     TRAP( error, ( value = TXdmSettingsApi::PropertyL( aSettingsId, aProperty ) ) );
       
   820     if ( error == KErrNone )
       
   821         {
       
   822         CleanupStack::PushL( value );           // << value
       
   823         HBufC8* utfValue = ConvertLC( *value ); // << utfValue
       
   824         aObject.InsertL( 0, *utfValue );
       
   825         CleanupStack::PopAndDestroy( 2, utfValue );       // >>> value, utfValue
       
   826         return CSmlDmAdapter::EOk;
       
   827         }
       
   828     return CSmlDmAdapter::ENotFound;
       
   829     }
       
   830     
       
   831 
       
   832 // -----------------------------------------------------------------------------
       
   833 // CXdmDMAdapter::UpdatePropertyL
       
   834 // -----------------------------------------------------------------------------
       
   835 //
       
   836 CSmlDmAdapter::TError CXdmDMAdapter::UpdatePropertyL( TInt aSettingsId, 
       
   837                                                       TXdmSettingsProperty aProperty, 
       
   838                                                       const TDesC8& aObject )
       
   839     {
       
   840     HBufC* value = ConvertLC( aObject ); // << value
       
   841     TInt error( KErrNone );
       
   842     TRAP( error, TXdmSettingsApi::UpdatePropertyL( aSettingsId, *value, aProperty )  );
       
   843     CleanupStack::PopAndDestroy( value );     // >>> value
       
   844 
       
   845     if ( error == KErrNone )
       
   846         {
       
   847         return CSmlDmAdapter::EOk;
       
   848         }
       
   849     return CSmlDmAdapter::ENotFound;
       
   850     }
       
   851           
       
   852  
       
   853 // -----------------------------------------------------------------------------
       
   854 // CXdmDMAdapter::FillNodeInfoL
       
   855 // ------------------------------------------------------------------------------
       
   856 //
       
   857 void CXdmDMAdapter::FillNodeInfoL( MSmlDmDDFObject& aNode,
       
   858                                    TSmlDmAccessTypes aAccTypes,
       
   859                                    MSmlDmDDFObject::TOccurence aOccurrence, 
       
   860                                    MSmlDmDDFObject::TScope aScope, 
       
   861                                    MSmlDmDDFObject::TDFFormat aFormat,
       
   862                                    const TDesC8& aDescription)
       
   863     {
       
   864     aNode.SetAccessTypesL( aAccTypes );
       
   865     aNode.SetOccurenceL( aOccurrence );
       
   866     aNode.SetScopeL( aScope );
       
   867     aNode.SetDFFormatL( aFormat );
       
   868     
       
   869     if( aFormat != MSmlDmDDFObject::ENode )
       
   870         {
       
   871         aNode.AddDFTypeMimeTypeL( KXdmDmTextPlain );
       
   872         }
       
   873     aNode.SetDescriptionL( aDescription );
       
   874     }
       
   875     
       
   876 
       
   877 // ----------------------------------------------------------------------------
       
   878 // CXdmDMAdapter::IapIdFromURIL
       
   879 // ----------------------------------------------------------------------------
       
   880 //
       
   881 TInt CXdmDMAdapter::IapIdFromURIL( const TDesC8& aUri )
       
   882     {
       
   883     TInt id( KErrNotFound );
       
   884     MSmlDmAdapter::TError status( MSmlDmAdapter::EError );
       
   885     CBufBase* result = CBufFlat::NewL(1);
       
   886     CleanupStack::PushL( result );  // << result
       
   887        
       
   888     TPtrC8 uri = NSmlDmURI::RemoveDotSlash( aUri ); 
       
   889     // Request the identifier 
       
   890     Callback().FetchLinkL( uri, *result, status );
       
   891     
       
   892     if( status == MSmlDmAdapter::EOk )
       
   893         {
       
   894         HBufC8* luid = Callback().GetLuidAllocL( uri ); 
       
   895         if ( luid && luid->Length() )
       
   896             {
       
   897             id = DesToInt( *luid );
       
   898             } 
       
   899         delete luid;
       
   900         luid = NULL;
       
   901         }
       
   902 
       
   903     CleanupStack::PopAndDestroy( result );  // >>> result
       
   904     return id;
       
   905     } 
       
   906 
       
   907 // ----------------------------------------------------------------------------
       
   908 // CXdmDMAdapter::URIFromIapIdL
       
   909 // ----------------------------------------------------------------------------
       
   910 //
       
   911 HBufC8* CXdmDMAdapter::URIFromIapIdL( TInt aId )
       
   912     {
       
   913     CBufBase *allIds = CBufFlat::NewL(KXdmDmIdTableSize);
       
   914     CleanupStack::PushL( allIds );  // << allIds
       
   915     MSmlDmAdapter::TError status;
       
   916     // Fetch all IAP ids
       
   917     Callback().FetchLinkL( KXdmDmAP, *allIds, status );
       
   918 
       
   919     if ( status == MSmlDmAdapter::EOk )
       
   920         {   
       
   921         TInt index(0);
       
   922         TInt segStart(0);
       
   923         while ( index != KErrNotFound )
       
   924             { 
       
   925             // Get pointer from segStart            
       
   926             TPtrC8 allIdsPtr = allIds->Ptr(segStart).Mid(0);
       
   927             // Find the end of the segment
       
   928             index = allIdsPtr.Locate('/');
       
   929             HBufC8* uriSeg = NULL;
       
   930             // This is the last one
       
   931             if ( index == KErrNotFound )
       
   932                 {
       
   933                 TPtrC8 uriSeg8Ptr = allIds->Ptr(segStart);
       
   934                 uriSeg = uriSeg8Ptr.AllocLC();  // << uriSeg
       
   935                 }
       
   936             else
       
   937                 {
       
   938                 TPtrC8 uriSeg8Ptr = allIds->Ptr(segStart).Mid( 0, index );
       
   939                 uriSeg = uriSeg8Ptr.AllocLC();  // << uriSeg8Ptr
       
   940                 }
       
   941             // Construct the uri
       
   942             HBufC8* uri = HBufC8::NewLC( KXdmDmAP().Length() 
       
   943                                          + KXdmDmSeparator().Length() 
       
   944                                          + uriSeg->Length() ); // << uri
       
   945             TPtr8 uriPtr = uri->Des();
       
   946             uriPtr.Format( KXdmDmAP );
       
   947             uriPtr.Append( KXdmDmSeparator );
       
   948             uriPtr.Append( *uriSeg );
       
   949             // Get the luid from the uri
       
   950             HBufC8* luid = Callback().GetLuidAllocL( uriPtr );
       
   951             if ( luid && luid->Length() > 0 )
       
   952                 {
       
   953                 // No need to push luid to the CleanupStack
       
   954                 TInt id = DesToInt( luid->Des() );
       
   955                 delete luid;
       
   956                 luid = NULL;
       
   957                 if ( id == aId )
       
   958                     {
       
   959                     // The correct one found
       
   960                     CleanupStack::Pop();  // >>> uri
       
   961                     CleanupStack::PopAndDestroy( 2, allIds );  // >>> uriSeg, allIds
       
   962                     return uri;
       
   963                     }
       
   964                 }
       
   965             // This was wrong, delete and get the next one
       
   966             CleanupStack::PopAndDestroy( 2, uriSeg ); // >>> uri, uriSeg
       
   967             segStart += index + 1;
       
   968             }        
       
   969         }
       
   970     CleanupStack::PopAndDestroy( allIds ); // >>> allIds
       
   971     return NULL;
       
   972     }  
       
   973 // -----------------------------------------------------------------------------
       
   974 // CXdmDMAdapter::GetSipIdL
       
   975 // -----------------------------------------------------------------------------
       
   976 //
       
   977 TInt CXdmDMAdapter::GetSipIdL( const TDesC8& aUri )
       
   978     {
       
   979 
       
   980     CSmlDmAdapter::TError status = EOk;
       
   981     CBufBase* result = CBufFlat::NewL(1);
       
   982     CleanupStack::PushL( result );    // << result
       
   983 
       
   984     TPtrC8 uri = NSmlDmURI::RemoveDotSlash( aUri );
       
   985     // Request the sip settings identifier
       
   986     Callback().FetchLinkL( uri, *result, status);
       
   987         
       
   988     if( status == EOk )
       
   989         {
       
   990         TUint32 id( 0 );
       
   991         TPtrC8 hexIndex = uri.Right( KXdmDmHexLength );
       
   992         TLex8 lexer( hexIndex );
       
   993         lexer.Val( id, EHex );
       
   994         CleanupStack::PopAndDestroy( result );   // >>> result   
       
   995         return id;       
       
   996         }
       
   997     CleanupStack::PopAndDestroy( result );   // >>> result   
       
   998     return KErrNotFound;       
       
   999     }
       
  1000 // -----------------------------------------------------------------------------
       
  1001 // CXdmDMAdapter::FetchSipConRefL
       
  1002 // -----------------------------------------------------------------------------
       
  1003 //
       
  1004 CSmlDmAdapter::TError CXdmDMAdapter::FetchSipConRefL( TInt aSettingsId,
       
  1005                                                       CBufBase& aObject)
       
  1006     {
       
  1007 
       
  1008     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
  1009     TInt sipSettingsId( KErrNotFound );
       
  1010     
       
  1011     HBufC* value = NULL;
       
  1012     TInt error( KErrNone );
       
  1013     TRAP( error, ( value = TXdmSettingsApi::PropertyL( aSettingsId, EXdmPropToAppRef ) ) );
       
  1014     if ( error == KErrNone )
       
  1015         {
       
  1016         sipSettingsId = DesToInt( *value );
       
  1017         delete value;
       
  1018         value = NULL;
       
  1019         }
       
  1020     
       
  1021     if( sipSettingsId != KErrNotFound )
       
  1022         {
       
  1023         CBufBase* result = CBufFlat::NewL(1);
       
  1024         CleanupStack::PushL(result);    // << result
       
  1025         
       
  1026         // Request all the sip settings identifiers 
       
  1027         Callback().FetchLinkL( KXdmDmSip, *result, status);
       
  1028         
       
  1029         if( status == EOk )
       
  1030             {
       
  1031             TPtr8 uriSeg8Ptr = result->Ptr(0);
       
  1032             
       
  1033             HBufC8* uriSegBuffer = uriSeg8Ptr.AllocL();
       
  1034             CleanupStack::PushL( uriSegBuffer );  // << uriSegBuffer
       
  1035             
       
  1036             TPtr8 uriSegBufferPtr = uriSegBuffer->Des();
       
  1037             
       
  1038             TInt numOfUriSegs = NSmlDmURI::NumOfURISegs(uriSeg8Ptr);
       
  1039             
       
  1040             // Check if the SIP settings id match with one of the found
       
  1041             // SIP settings identifiers
       
  1042             while( numOfUriSegs > 1)
       
  1043                 {
       
  1044                 uriSegBufferPtr = NSmlDmURI::RemoveLastSeg(uriSegBufferPtr);
       
  1045                 
       
  1046                 TPtrC8 hexIndex = uriSegBufferPtr.Right(KXdmDmHexLength);
       
  1047                 
       
  1048                 TUint32 id(0);
       
  1049                 TLex8 lexer(hexIndex);
       
  1050                 if( lexer.Val(id, EHex) == KErrNone )
       
  1051                     {
       
  1052                     if( id == sipSettingsId )
       
  1053                         {
       
  1054                         TPtrC8 lastUriSegSip = NSmlDmURI::LastURISeg(uriSegBufferPtr);
       
  1055                         
       
  1056                         // Total length of the sip settings link where one is for
       
  1057                         // the separator
       
  1058                         TInt sipLinkLength = KXdmDmSip().Length() + 
       
  1059                                              KXdmDmSeparator().Length() +
       
  1060                                              lastUriSegSip.Length();
       
  1061                         HBufC8* sipLink = HBufC8::NewLC( sipLinkLength );   // <<< sipLink
       
  1062                         
       
  1063                         TPtr8 sipLinkPtr = sipLink->Des();
       
  1064                         sipLinkPtr.Append( KXdmDmSip );
       
  1065                         sipLinkPtr.Append( KXdmDmSeparator );
       
  1066                         sipLinkPtr.Append( lastUriSegSip );
       
  1067                         
       
  1068                         aObject.InsertL( 0, sipLinkPtr );
       
  1069                         
       
  1070                         CleanupStack::PopAndDestroy( sipLink );   // >>> sipLink
       
  1071                         break;
       
  1072                         }
       
  1073                     }
       
  1074                 
       
  1075                 numOfUriSegs -= 1;  
       
  1076                 }
       
  1077             
       
  1078             CleanupStack::PopAndDestroy( uriSegBuffer );    // >>> uriSegBuffer
       
  1079             }
       
  1080         
       
  1081         CleanupStack::PopAndDestroy( result );    // >>> result
       
  1082         }
       
  1083     else
       
  1084         {
       
  1085         status = CSmlDmAdapter::ENotFound;
       
  1086         }
       
  1087     
       
  1088     return status;
       
  1089     }   
       
  1090 
       
  1091 // -----------------------------------------------------------------------------
       
  1092 // CXdmDMAdapter::FindSettingsIdL
       
  1093 // -----------------------------------------------------------------------------
       
  1094 //      
       
  1095 TInt CXdmDMAdapter::FindSettingsIdL( const TDesC8& aLUID, const TDesC8& aUri )
       
  1096     {
       
  1097     TInt settingsId(0);
       
  1098     if ( aLUID.Length() > 0 )
       
  1099         {
       
  1100         settingsId = DesToInt( aLUID );
       
  1101         return settingsId;
       
  1102         }
       
  1103     else
       
  1104         {
       
  1105         TPtrC8 name = NSmlDmURI:: URISeg( aUri, KXdmDmLevel );
       
  1106         settingsId = DesToInt( name );
       
  1107         HBufC8* luid = IntToDes8LC( settingsId ); // << luid
       
  1108         Callback().SetMappingL( aUri, *luid );
       
  1109         CleanupStack::PopAndDestroy( luid ); // luid 
       
  1110         return settingsId;
       
  1111         }
       
  1112     }
       
  1113 
       
  1114 // -----------------------------------------------------------------------------
       
  1115 // CXdmDMAdapter::CheckExistingNamesLC()
       
  1116 // -----------------------------------------------------------------------------
       
  1117 // 
       
  1118 HBufC* CXdmDMAdapter::CheckExistingNamesLC( const TDesC8& aName )
       
  1119     {    
       
  1120     TBool ready( EFalse );  
       
  1121     RArray<TInt> settingIds;
       
  1122     CleanupClosePushL( settingIds );                // << settingIds
       
  1123     CDesCArray* settingNames = TXdmSettingsApi::CollectionNamesLC( settingIds ); // << settingNames
       
  1124     TInt index( 0 );
       
  1125     TBuf<512> tempName;
       
  1126     while ( !ready )
       
  1127         {
       
  1128         TBool found ( EFalse );
       
  1129         TInt count = settingNames->MdcaCount();
       
  1130         tempName.Copy( aName );
       
  1131         if ( index > 0 )
       
  1132             {
       
  1133             tempName.Append( KXdmDmStartBracket );
       
  1134             tempName.AppendNumFixedWidth( index, EDecimal, 2 );
       
  1135             tempName.Append( KXdmDmCloseBracket );
       
  1136             }
       
  1137         for ( TInt i(0); i < count && !found; i++ )
       
  1138             {
       
  1139             if ( !settingNames->MdcaPoint(i).CompareF( tempName ) )
       
  1140                 {
       
  1141                 found = ETrue;
       
  1142                 index++;
       
  1143                 }
       
  1144             }
       
  1145         if ( !found )
       
  1146             {
       
  1147             ready = ETrue;
       
  1148             }
       
  1149         }
       
  1150     CleanupStack::PopAndDestroy( 2 );   // >>> settingNames, settingIds
       
  1151     HBufC* newName = tempName.AllocLC();    // << newName
       
  1152     return newName;
       
  1153     }
       
  1154     
       
  1155 // -----------------------------------------------------------------------------
       
  1156 // CXdmDMAdapter::Match
       
  1157 // -----------------------------------------------------------------------------
       
  1158 //
       
  1159 TBool CXdmDMAdapter::Match( const TDesC8& aLeft, const TDesC8& aRight )
       
  1160     {
       
  1161     if ( !aLeft.Compare( aRight ) )
       
  1162         {
       
  1163         return ETrue;
       
  1164         }
       
  1165     return EFalse;
       
  1166     }
       
  1167     
       
  1168 // -----------------------------------------------------------------------------
       
  1169 // CXdmDMAdapter::ConvertLC
       
  1170 // -----------------------------------------------------------------------------
       
  1171 //  
       
  1172 HBufC8* CXdmDMAdapter::ConvertLC( const TDesC& aSource )
       
  1173     {   
       
  1174     HBufC8* destination = HBufC8::NewLC( aSource.Length() ); // << destination
       
  1175     TPtr8 bufferPtr = destination->Des();
       
  1176     CnvUtfConverter::ConvertFromUnicodeToUtf8( bufferPtr, aSource );
       
  1177     return destination;
       
  1178     }   
       
  1179     
       
  1180 // -----------------------------------------------------------------------------
       
  1181 // CXdmDMAdapter::ConvertLC
       
  1182 // -----------------------------------------------------------------------------
       
  1183 //  
       
  1184 HBufC*  CXdmDMAdapter::ConvertLC( const TDesC8& aSource )
       
  1185     {   
       
  1186     HBufC* destination = HBufC::NewLC( aSource.Length() );  // << destination
       
  1187     TPtr bufferPtr = destination->Des();
       
  1188     CnvUtfConverter::ConvertToUnicodeFromUtf8( bufferPtr, aSource );
       
  1189     return destination;
       
  1190     }
       
  1191 // ----------------------------------------------------------------------------
       
  1192 // CXdmDMAdapter::DesToInt
       
  1193 // ----------------------------------------------------------------------------
       
  1194 TInt CXdmDMAdapter::DesToInt( const TDesC& aSource ) const
       
  1195     {
       
  1196     TLex16 lex( aSource );
       
  1197     TInt value ( KErrNotFound );
       
  1198     lex.Val( value );
       
  1199     return value;
       
  1200     }
       
  1201 
       
  1202 // ----------------------------------------------------------------------------
       
  1203 // CXdmDMAdapter::DesToInt
       
  1204 // ----------------------------------------------------------------------------
       
  1205 TInt CXdmDMAdapter::DesToInt( const TDesC8& aSource ) const
       
  1206     {
       
  1207     TLex8 lex( aSource );
       
  1208     TInt value ( KErrNotFound );
       
  1209     lex.Val( value );
       
  1210     return value;
       
  1211     }
       
  1212 
       
  1213 // ----------------------------------------------------------------------------
       
  1214 // CXdmDMAdapter::IntToDes8LC
       
  1215 // ----------------------------------------------------------------------------
       
  1216 HBufC8* CXdmDMAdapter::IntToDes8LC( const TInt aSource )
       
  1217     {
       
  1218     // 10 = max length of 32bit integer
       
  1219     HBufC8* buf = HBufC8::NewLC( KXdmDmMaxIntLength ); // << buf
       
  1220     TPtr8 ptrBuf = buf->Des();
       
  1221     ptrBuf.Num( aSource );
       
  1222     return buf;
       
  1223     }
       
  1224 
       
  1225 // ----------------------------------------------------
       
  1226 // CXdmDMAdapter::WriteToLog
       
  1227 // DEBUG only
       
  1228 // ----------------------------------------------------
       
  1229 //
       
  1230 #ifdef _DEBUG
       
  1231 void CXdmDMAdapter::WriteToLog( TRefByValue<const TDesC8> aFmt,... )                                 
       
  1232     {
       
  1233     VA_LIST list;
       
  1234     VA_START( list, aFmt );
       
  1235     TBuf8<KXdmDmLogBufferMaxSize> buf;
       
  1236     buf.FormatList( aFmt, list );
       
  1237     RFileLogger::Write( KXdmDmLogDir, KXdmDmLogFile, EFileLoggingModeAppend, buf );
       
  1238     }                           
       
  1239 #endif                              
       
  1240                                 
       
  1241 // End of File
       
  1242 
       
  1243 
       
  1244