simpleengine/presencedm/src/presencedmadapter.cpp
changeset 0 c8caa15ef882
child 12 e6a66db4e9d0
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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:    OMA Presence Settings Device Management Adapter's source file 
       
    15 *
       
    16 */
       
    17  
       
    18 #include <implementationproxy.h>
       
    19 #include <nsmldmuri.h>
       
    20 #include <utf.h>
       
    21 #include <badesca.h>
       
    22 #include <StringLoader.h>
       
    23 
       
    24 #include "presencedmadapter.h"
       
    25 #include "presencedmlogger.h"
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CPresenceDMAdapter::NewL()
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CPresenceDMAdapter* CPresenceDMAdapter::NewL(MSmlDmCallback* aDmCallback )
       
    32     {
       
    33     PRES_DM_LOG(LOG_LIT("NewL start"));    
       
    34     CPresenceDMAdapter* self = new (ELeave) CPresenceDMAdapter( aDmCallback );
       
    35     PRES_DM_LOG(LOG_LIT(" NewL end"));    
       
    36     return self;
       
    37     }
       
    38     
       
    39 // -----------------------------------------------------------------------------
       
    40 // CPresenceDMAdapter::CPresenceDMAdapter()
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CPresenceDMAdapter::CPresenceDMAdapter(MSmlDmCallback* aDmCallback) : 
       
    44     CSmlDmAdapter( aDmCallback ), iGetSetID(KErrNotFound)
       
    45     {
       
    46     PRES_DM_LOG(LOG_LIT("CPresenceDMAdapter")); 
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CPresenceDMAdapter::~CPresenceDMAdapter()
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CPresenceDMAdapter::~CPresenceDMAdapter()
       
    54     {
       
    55     PRES_DM_LOG(LOG_LIT("~CPresenceDMAdapter")); 
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 //  CPresenceDMAdapter::DDFVersionL
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CPresenceDMAdapter::DDFVersionL(CBufBase& aDDFVersion)
       
    63     {
       
    64     PRES_DM_LOG(LOG_LIT("DDFVersionL"));   
       
    65     aDDFVersion.InsertL( 0, KPresDMDDFVersion );    
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 //  CPresenceDMAdapter::DDFStructureL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CPresenceDMAdapter::DDFStructureL( MSmlDmDDFObject& aDDF )
       
    73     {
       
    74     PRES_DM_LOG(LOG_LIT("DDFStructureL"));    
       
    75 
       
    76     // For OMA_PRESENCE 
       
    77     TSmlDmAccessTypes accessTypeGet;
       
    78     accessTypeGet.SetGet();
       
    79      
       
    80     // For OMA_PRESENCE/<X> 
       
    81     TSmlDmAccessTypes accessTypeAll;
       
    82     accessTypeAll.SetAdd();
       
    83     accessTypeAll.SetGet();
       
    84     accessTypeAll.SetReplace();
       
    85     accessTypeAll.SetDelete();
       
    86     
       
    87     // For leaf nodes
       
    88     TSmlDmAccessTypes accessTypeNoDelete;
       
    89     accessTypeNoDelete.SetAdd();
       
    90     accessTypeNoDelete.SetGet();
       
    91     accessTypeNoDelete.SetReplace();
       
    92 
       
    93     // ./OMA_PRESENCE
       
    94     MSmlDmDDFObject& omaPresNode = aDDF.AddChildObjectL( KPresDMNodeName );
       
    95     FillNodeInfoL( omaPresNode, accessTypeGet, MSmlDmDDFObject::EOne,
       
    96                   MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
    97                   KPresDMNodeNameDescription );
       
    98                   
       
    99     // ./OMA_PRESENCE/<X> 
       
   100     MSmlDmDDFObject& runTimeNode = omaPresNode.AddChildObjectGroupL();
       
   101     FillNodeInfoL( runTimeNode, accessTypeAll, MSmlDmDDFObject::EZeroOrMore,
       
   102                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode,
       
   103                   KPresDmDynamicDescription );
       
   104     
       
   105     // ./OMA_PRESENCE/<X>/NAME            
       
   106     MSmlDmDDFObject& nameNode = runTimeNode.AddChildObjectL( KPresDMName );
       
   107     FillNodeInfoL( nameNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   108                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   109                   KPresDMNameDescription );
       
   110             
       
   111     // ./OMA_PRESENCE/<X>/PROVIDER-ID           
       
   112     MSmlDmDDFObject& providerIdNode = runTimeNode.AddChildObjectL( KPresDMProviderId );
       
   113     FillNodeInfoL( providerIdNode, accessTypeNoDelete,MSmlDmDDFObject::EZeroOrOne,
       
   114                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   115                   KPresDMProviderIdDescription );    
       
   116                                
       
   117     // ./OMA_PRESENCE/<X>/ToConRef
       
   118     MSmlDmDDFObject& toConRefNode = runTimeNode.AddChildObjectL( KPresDMToConRef );
       
   119     FillNodeInfoL( toConRefNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   120                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode,
       
   121                   KPresDMToConRefDescription);
       
   122                   
       
   123         // ./OMA_PRESENCE/<X>/ToConRef/SIP-PROFILE (Towards SIP ID)                                         
       
   124         MSmlDmDDFObject& napIdSIPNode = toConRefNode.AddChildObjectL( KPresDMSIPProfile );
       
   125         FillNodeInfoL( napIdSIPNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne, 
       
   126                       MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode,
       
   127                       KPresDMSIPProfileDescription );
       
   128                   
       
   129             // ./OMA_PRESENCE/<X>/ToConRef/SIP-PROFILE/ConRef (The actual SIP ID)                                    
       
   130             MSmlDmDDFObject& conRefSipNode = napIdSIPNode.AddChildObjectL( KPresDMConRef );
       
   131             FillNodeInfoL( conRefSipNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne, 
       
   132                           MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   133                           KPresDMConRefDescription );
       
   134                   
       
   135         // ./OMA_PRESENCE/<X>/ToConRef/XDM-SET (To XDM-ID) (Towards XDM ID)                                         
       
   136         MSmlDmDDFObject& napIdToXDMNode = toConRefNode.AddChildObjectL( KPresDMXDMSet );
       
   137         FillNodeInfoL( napIdToXDMNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne, 
       
   138                       MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode,
       
   139                       KPresDMXDMSetDescription );
       
   140                   
       
   141             // ./OMA_PRESENCE/<X>/ToConRef/XDM-SET/ConRef (actual XDM node)       
       
   142             MSmlDmDDFObject& conRefXDMNode = napIdToXDMNode.AddChildObjectL( KPresDMConRef );
       
   143             FillNodeInfoL( conRefXDMNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne, 
       
   144                           MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr,
       
   145                           KPresDMConRefDescription );                 
       
   146                                    
       
   147     // ./OMA_PRESENCE/<X>/CLIENT-DATA-OBJ-LIMIT          
       
   148     MSmlDmDDFObject& dataObjNode = runTimeNode.AddChildObjectL( KPresDMClientObjDataLim );
       
   149     FillNodeInfoL( dataObjNode, accessTypeNoDelete, MSmlDmDDFObject::EOne,
       
   150                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EInt,
       
   151                   KPresDMClientObjDataLimDescription );
       
   152                   
       
   153     // ./OMA_PRESENCE/<X>/CONTENT-SERVER-URI
       
   154     MSmlDmDDFObject& ContentSrvNode = runTimeNode.AddChildObjectL( KPresDMContentSrvUri );
       
   155     FillNodeInfoL( ContentSrvNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   156                   MSmlDmDDFObject::EDynamic,MSmlDmDDFObject::EChr,
       
   157                   KPresDMContentSrvUriDescription );            
       
   158                   
       
   159     // ./OMA_PRESENCE/<X>/SOURCE-THROTTLE-PUBLISH   
       
   160     MSmlDmDDFObject& srcThrotNode = runTimeNode.AddChildObjectL( KPresDMSrcThPublish );
       
   161     FillNodeInfoL( srcThrotNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   162                   MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EInt,
       
   163                   KPresDMSrcThPublishDescription );     
       
   164                   
       
   165         // ./OMA_PRESENCE/<X>/MAX-NUMBER-OF-PRESENCE-SUBSCRIPTIONS  
       
   166     MSmlDmDDFObject& maxSubsNode = runTimeNode.AddChildObjectL( KPresDMMaxPresSubs );
       
   167     FillNodeInfoL( maxSubsNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   168                   MSmlDmDDFObject::EDynamic,MSmlDmDDFObject::EInt,
       
   169                   KPresDMMaxPresSubsDescription ); 
       
   170                     
       
   171     // ./OMA_PRESENCE/<X>/MAX-NUMBER-OF-SUBSCRIPTIONS-IN-PRESENCE-LIST   
       
   172     MSmlDmDDFObject& maxSubsListNode = runTimeNode.AddChildObjectL( KPresDMMaxPresSubsInLists );
       
   173     FillNodeInfoL( maxSubsListNode, accessTypeNoDelete, MSmlDmDDFObject::EZeroOrOne,
       
   174                   MSmlDmDDFObject::EDynamic,MSmlDmDDFObject::EInt,
       
   175                   KPresDMMaxPresSubsInListsDescription );
       
   176                   
       
   177     // ./OMA_PRESENCE/<X>/SERVICE-URI-TEMPLATE
       
   178     MSmlDmDDFObject& serUriTempNode = runTimeNode.AddChildObjectL( KPresDMServiceUriTemp );
       
   179     FillNodeInfoL( serUriTempNode, accessTypeNoDelete, MSmlDmDDFObject::EOne,
       
   180                   MSmlDmDDFObject::EDynamic,MSmlDmDDFObject::EChr,
       
   181                   KPresDMServiceUriTempDescription );
       
   182   
       
   183     PRES_DM_LOG(LOG_LIT(" DDFStructureL end"));  
       
   184     }
       
   185     
       
   186 // -----------------------------------------------------------------------------
       
   187 // CPresenceDMAdapter::ChildURIListL
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CPresenceDMAdapter::ChildURIListL( const TDesC8& aUri, 
       
   191                                        const TDesC8& /*aLUID*/, 
       
   192                                        const CArrayFix<TSmlDmMappingInfo>& 
       
   193                                        /*aPreviousURISegmentList*/, 
       
   194                                        const TInt aResultsRef, 
       
   195                                        const TInt aStatusRef )
       
   196     {
       
   197     PRES_DM_LOG(LOG_LIT8("ChildURIListL(%S): begin"), &aUri);
       
   198     const TInt KPresDMSegmentNameLen = 50;
       
   199     
       
   200     CSmlDmAdapter::TError retValue = CSmlDmAdapter::EOk;
       
   201 
       
   202     CBufBase* currentList = CBufFlat::NewL(1);
       
   203     CleanupStack::PushL( currentList ); // << currentList
       
   204     
       
   205     const TPtrC8 lastUriSeg = NSmlDmURI::LastURISeg( aUri );
       
   206     TBuf8<KPresDMSegmentNameLen> segmentName;
       
   207     
       
   208     // ./OMA_PRESENCE
       
   209     if( !lastUriSeg.Compare( KPresDMNodeName ) ) 
       
   210         {
       
   211         PRES_DM_LOG(LOG_LIT8("  ./OMA_PRESENCE"));
       
   212         RArray<TInt> settingIds;
       
   213         CleanupClosePushL( settingIds );    // << settingIds
       
   214         CDesCArray* names = PresSettingsApi::GetAllSetsNamesLC(settingIds);
       
   215         TInt IdCount = settingIds.Count();
       
   216         
       
   217         PRES_DM_LOG(LOG_LIT("   IdCount = %d"), IdCount);
       
   218             
       
   219         for( TInt i(0); i < IdCount; i++ )
       
   220             {
       
   221             TInt id = settingIds[i];
       
   222             segmentName.Copy( KNullDesC8 );
       
   223             segmentName.AppendNum( id );
       
   224             currentList->InsertL( currentList->Size(), segmentName);
       
   225             currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   226             }
       
   227         CleanupStack::PopAndDestroy(names);
       
   228         CleanupStack::PopAndDestroy(1); // settingIds, 
       
   229         
       
   230         Callback().SetResultsL( aResultsRef, *currentList, KNullDesC8 );
       
   231         Callback().SetStatusL( aStatusRef, retValue );
       
   232         CleanupStack::PopAndDestroy( currentList ); // >>> currentList
       
   233         currentList = NULL;
       
   234         return;
       
   235         }   
       
   236 
       
   237     // ./OMA_PRESENCE/X
       
   238     if( NSmlDmURI::NumOfURISegs( aUri ) == KPresDMLevel ) // if Uri segments are 2
       
   239                                                // we are certainly at x
       
   240                                                // level   
       
   241         {
       
   242         PRES_DM_LOG(LOG_LIT8("  ./OMA_PRESENCE/X"));
       
   243         
       
   244         segmentName.Copy( KPresDMName );
       
   245         currentList->InsertL( currentList->Size(), segmentName );
       
   246         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   247         
       
   248         segmentName.Copy( KPresDMProviderId );
       
   249         currentList->InsertL( currentList->Size(), segmentName );
       
   250         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   251         
       
   252         segmentName.Copy( KPresDMToConRef );
       
   253         currentList->InsertL( currentList->Size(), segmentName );
       
   254         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   255                 
       
   256         segmentName.Copy( KPresDMClientObjDataLim );
       
   257         currentList->InsertL( currentList->Size(), segmentName );
       
   258         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   259         
       
   260         segmentName.Copy( KPresDMContentSrvUri );
       
   261         currentList->InsertL( currentList->Size(), segmentName );
       
   262         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   263         
       
   264         segmentName.Copy( KPresDMSrcThPublish );
       
   265         currentList->InsertL( currentList->Size(), segmentName );
       
   266         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   267         
       
   268         segmentName.Copy( KPresDMMaxPresSubs );
       
   269         currentList->InsertL( currentList->Size(), segmentName );
       
   270         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   271         
       
   272         segmentName.Copy( KPresDMMaxPresSubsInLists );
       
   273         currentList->InsertL( currentList->Size(), segmentName );
       
   274         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   275         
       
   276         segmentName.Copy( KPresDMServiceUriTemp );
       
   277         currentList->InsertL( currentList->Size(), segmentName );
       
   278         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   279         }
       
   280         
       
   281     // ./OMA_PRESENCE/X/ToConRef   
       
   282     else if ( !lastUriSeg.Compare( KPresDMToConRef ) ) 
       
   283         {
       
   284         PRES_DM_LOG(LOG_LIT8("  ./OMA_PRESENCE/X/ToConRef"));
       
   285         segmentName.Copy( KPresDMSIPProfile );
       
   286         currentList->InsertL( currentList->Size(), segmentName );
       
   287         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   288         
       
   289         segmentName.Copy( KPresDMXDMSet );
       
   290         currentList->InsertL( currentList->Size(), segmentName );
       
   291         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   292         }
       
   293     
       
   294     // ./OMA_PRESENCE/X/ToConRef/SIP-ID    
       
   295     else if ( !lastUriSeg.Compare( KPresDMSIPProfile ) ) 
       
   296         {
       
   297         PRES_DM_LOG(LOG_LIT8("  ./OMA_PRESENCE/X/ToConRef/SIP-ID"));
       
   298         segmentName.Copy( KPresDMConRef );
       
   299         currentList->InsertL( currentList->Size(), segmentName );
       
   300         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   301         }
       
   302     
       
   303     // ./OMA_PRESENCE/X/ToConRef/XDM-ID      
       
   304     else if ( !lastUriSeg.Compare( KPresDMXDMSet ) )
       
   305         {
       
   306         PRES_DM_LOG(LOG_LIT8("  ./OMA_PRESENCE/X/ToConRef/XDM-ID"));
       
   307         segmentName.Copy( KPresDMConRef );
       
   308         currentList->InsertL( currentList->Size(), segmentName );
       
   309         currentList->InsertL( currentList->Size(), KPresDMSeparator );
       
   310         }
       
   311         
       
   312     else
       
   313         {
       
   314         // if none of asked nodes found return error.
       
   315         retValue = CSmlDmAdapter::ENotFound;
       
   316         }
       
   317        
       
   318     Callback().SetResultsL( aResultsRef, *currentList, KNullDesC8 );
       
   319     Callback().SetStatusL( aStatusRef, retValue );
       
   320     CleanupStack::PopAndDestroy( currentList ); // >>> currentList  
       
   321     PRES_DM_LOG(LOG_LIT(" ChildURIListL(): end") );
       
   322     }    
       
   323  
       
   324 // -----------------------------------------------------------------------------
       
   325 //  CPresenceDMAdapter::FetchLeafObjectL
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 void CPresenceDMAdapter::FetchLeafObjectL( const TDesC8& aUri, 
       
   329                                       const TDesC8& /*aLUID*/, 
       
   330                                       const TDesC8& aType, 
       
   331                                       const TInt aResultsRef, 
       
   332                                       const TInt aStatusRef )
       
   333     {
       
   334     PRES_DM_LOG(LOG_LIT8("FetchLeafObjectL(%S): start"), &aUri );
       
   335     CBufBase* result = CBufFlat::NewL( KPresDMDefaultResultSize );
       
   336     CleanupStack::PushL( result );    // << result
       
   337     CSmlDmAdapter::TError status = FetchObjectL( aUri, *result );
       
   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     PRES_DM_LOG(LOG_LIT(" FetchLeafObjectL(): end") );
       
   346     }
       
   347     
       
   348 // -----------------------------------------------------------------------------
       
   349 // CSmlDmAdapter::TError FetchObjectL
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 CSmlDmAdapter::TError CPresenceDMAdapter::FetchObjectL( const TDesC8& aUri, 
       
   353                                                    CBufBase& aObject)
       
   354     {
       
   355     PRES_DM_LOG(LOG_LIT8("FetchObjectL(%S): start"), &aUri);
       
   356     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   357    
       
   358     TPresSettingsSet tempSet;
       
   359     TPresSettingsProperty property;
       
   360 
       
   361     HBufC8* luid = Callback().GetLuidAllocL( aUri );
       
   362     PRES_DM_LOG(LOG_LIT8("   GetLuidAllocL() => '%S'"), luid );
       
   363     TInt settingsId = DesToInt( *luid );
       
   364     
       
   365     PRES_DM_LOG(LOG_LIT("   settingsId after callback:%d"), settingsId);
       
   366     
       
   367     // check whether above found id is valid or not
       
   368     if (!IsPresIDValidL(settingsId))
       
   369         {
       
   370         //try to find it another way
       
   371         if( NSmlDmURI::NumOfURISegs( aUri ) > 1 )
       
   372             {
       
   373             TPtrC8 idSegment = NSmlDmURI::URISeg( aUri, 2 );
       
   374             settingsId = DesToInt(idSegment);
       
   375             if(!IsPresIDValidL(settingsId))
       
   376                 {
       
   377                 status = CSmlDmAdapter::ENotFound;
       
   378                 }
       
   379             PRES_DM_LOG(LOG_LIT("   settingsId found local way:%d"), settingsId);
       
   380             }
       
   381         }
       
   382     
       
   383     // if previous settings id processing was ok
       
   384     if (status == CSmlDmAdapter::EOk)
       
   385         {
       
   386         TPtrC8 lastUriSeg = NSmlDmURI::LastURISeg( aUri );
       
   387         // NAME
       
   388         if( Match(lastUriSeg, KPresDMName ) )
       
   389             {
       
   390             property = EPresPropSetName;  
       
   391             }
       
   392         // PROVIDER-ID  
       
   393         else if( Match(lastUriSeg, KPresDMProviderId ) )
       
   394             {
       
   395             property = EPresPropProviderID;
       
   396             }
       
   397         // Client object data limit 
       
   398         else if( Match(lastUriSeg, KPresDMClientObjDataLim) )
       
   399             {
       
   400             property = EPresPropObjectSize;  
       
   401             }
       
   402         // content server Uri
       
   403         else if( Match(lastUriSeg, KPresDMContentSrvUri) )
       
   404             {
       
   405             property = EPresPropContSrvAdd;  
       
   406             }
       
   407         // Source throttle publish
       
   408         else if( Match(lastUriSeg, KPresDMSrcThPublish) )
       
   409             {
       
   410             property = EPresPropPubInterval;  
       
   411             }
       
   412         // Max pres subs
       
   413         else if( Match(lastUriSeg, KPresDMMaxPresSubs ) )
       
   414             {
       
   415             property = EPresPropMaxSubs;  
       
   416             }
       
   417         // max subs in lists    
       
   418         else if( Match(lastUriSeg, KPresDMMaxPresSubsInLists ) )
       
   419             {
       
   420             property = EPresPropMaxCntInList;  
       
   421             }
       
   422         // service uri template     
       
   423         else if( Match(lastUriSeg, KPresDMServiceUriTemp ) )
       
   424             {
       
   425             property = EPresPropDomainSyntax;  
       
   426             }       
       
   427             
       
   428         // ConRef/TO-SIP
       
   429         // ConRef/TO-XDM        
       
   430         else if( Match( lastUriSeg, KPresDMConRef) )
       
   431             {
       
   432             TPtrC8 conRefUri = NSmlDmURI::RemoveLastSeg( aUri );
       
   433             TPtrC8 lastConRefSeg = NSmlDmURI::LastURISeg( conRefUri );
       
   434             
       
   435             if( Match( lastConRefSeg, KPresDMSIPProfile ) )
       
   436                 {
       
   437                 property = EPresPropSIPProfile;
       
   438                 }  
       
   439             else if( Match( lastConRefSeg, KPresDMXDMSet ) )
       
   440                 {
       
   441                 property = EPresPropXDMSet;
       
   442                 }  
       
   443             else
       
   444                 {
       
   445                 status = CSmlDmAdapter::ENotFound;
       
   446                 }
       
   447             }
       
   448         else
       
   449             {
       
   450             status = CSmlDmAdapter::ENotFound;
       
   451             }
       
   452         }
       
   453     
       
   454     // known property
       
   455     if ( status == CSmlDmAdapter::EOk )
       
   456         {
       
   457         status = GetPropertyL( settingsId, property, aObject ) ;
       
   458         PRES_DM_LOG(LOG_LIT("   GetPropertyL status: %d"), status); 
       
   459         }
       
   460         
       
   461     PRES_DM_LOG(LOG_LIT(" FetchObjectL: ends"));    
       
   462     return status;
       
   463     }  
       
   464          
       
   465 // -----------------------------------------------------------------------------
       
   466 // CPresenceDMAdapter::FetchLeafObjectSizeL
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 void CPresenceDMAdapter::FetchLeafObjectSizeL( const TDesC8& aUri, 
       
   470                                               const TDesC8& /*aLUID*/, 
       
   471                                               const TDesC8& aType, 
       
   472                                               const TInt aResultsRef, 
       
   473                                               const TInt aStatusRef )
       
   474     {
       
   475     PRES_DM_LOG(LOG_LIT8("FetchLeafObjectSizeL(%S): begins"), &aUri); 
       
   476     CBufBase* result = CBufFlat::NewL( KPresDMDefaultResultSize );
       
   477     CleanupStack::PushL( result );
       
   478     CSmlDmAdapter::TError status = FetchObjectL( aUri, *result );
       
   479     PRES_DM_LOG(LOG_LIT("   FetchObjectL: status = %d"), status); 
       
   480     if( status == CSmlDmAdapter::EOk )
       
   481         {
       
   482         TInt objSizeInBytes = result->Size();
       
   483         PRES_DM_LOG(LOG_LIT("   objSizeInBytes = %d"), objSizeInBytes); 
       
   484         
       
   485         TBuf8<KPresDMObjectSizeWidth> stringObjSizeInBytes;
       
   486         stringObjSizeInBytes.Num( objSizeInBytes );
       
   487         
       
   488         result->Reset();
       
   489         result->InsertL( 0, stringObjSizeInBytes );
       
   490         
       
   491         Callback().SetResultsL( aResultsRef, *result, aType );
       
   492         }   
       
   493         
       
   494     Callback().SetStatusL( aStatusRef, status) ;
       
   495     CleanupStack::PopAndDestroy(result);    
       
   496     PRES_DM_LOG(LOG_LIT(" FetchLeafObjectSizeL: ends")); 
       
   497     }
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // CPresenceDMAdapter::UpdateLeafObjectL()
       
   501 // -----------------------------------------------------------------------------
       
   502 //
       
   503 void CPresenceDMAdapter::UpdateLeafObjectL(const TDesC8& aUri, 
       
   504                                          const TDesC8& /*aLUID*/, 
       
   505                                          const TDesC8& aObject, 
       
   506                                          const TDesC8& /*aType*/, 
       
   507                                          const TInt aStatusRef)
       
   508     {
       
   509     PRES_DM_LOG(LOG_LIT8("UpdateLeafObjectL(%S): starts"), &aUri); 
       
   510     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   511     
       
   512     TPresSettingsSet tempSet;
       
   513     TPresSettingsProperty property;
       
   514 
       
   515     HBufC8* luid = Callback().GetLuidAllocL( aUri );
       
   516     TInt settingsId = DesToInt( *luid );
       
   517     
       
   518     PRES_DM_LOG(LOG_LIT("   settingsId after callback:%d"), settingsId);
       
   519     
       
   520     // check whether above found id is valid or not
       
   521     if (!IsPresIDValidL(settingsId))
       
   522         {
       
   523         //try to find it another way
       
   524         if( NSmlDmURI::NumOfURISegs( aUri ) > 1 )
       
   525             {
       
   526             TPtrC8 idSegment = NSmlDmURI::URISeg( aUri, 2 );
       
   527             settingsId = DesToInt(idSegment);
       
   528             if (!IsPresIDValidL(settingsId))
       
   529                 {
       
   530                 status = CSmlDmAdapter::ENotFound;
       
   531                 }
       
   532             PRES_DM_LOG(LOG_LIT("   settingsId found local way:%d"), settingsId);
       
   533             }
       
   534         }
       
   535     
       
   536     // if previous settings id processing was ok
       
   537     if (status == CSmlDmAdapter::EOk)
       
   538         {
       
   539         TPtrC8 lastUriSeg = NSmlDmURI::LastURISeg( aUri );
       
   540 
       
   541         // NAME
       
   542         if( Match(lastUriSeg, KPresDMName ) )
       
   543             {
       
   544             property = EPresPropSetName;  
       
   545             }
       
   546         // PROVIDER-ID  
       
   547         else if( Match(lastUriSeg, KPresDMProviderId ) )
       
   548             {
       
   549             property = EPresPropProviderID;  
       
   550             }
       
   551         // Client object data limit 
       
   552         else if( Match(lastUriSeg, KPresDMClientObjDataLim) )
       
   553             {
       
   554             property = EPresPropObjectSize;  
       
   555             }
       
   556         // content server Uri
       
   557         else if( Match(lastUriSeg, KPresDMContentSrvUri) )
       
   558             {
       
   559             property = EPresPropContSrvAdd;  
       
   560             }
       
   561         // Source throttle publish
       
   562         else if( Match(lastUriSeg, KPresDMSrcThPublish) )
       
   563             {
       
   564             property = EPresPropPubInterval;  
       
   565             }
       
   566         // Max pres subs
       
   567         else if( Match(lastUriSeg, KPresDMMaxPresSubs ) )
       
   568             {
       
   569             property = EPresPropMaxSubs;  
       
   570             }
       
   571         // max subs in lists    
       
   572         else if( Match(lastUriSeg, KPresDMMaxPresSubsInLists ) )
       
   573             {
       
   574             property = EPresPropMaxCntInList;  
       
   575             }
       
   576         // service uri template     
       
   577         else if( Match(lastUriSeg, KPresDMServiceUriTemp ) )
       
   578             {
       
   579             property = EPresPropDomainSyntax;  
       
   580             }       
       
   581             
       
   582         // ToConRef/TO-SIP/ConRef
       
   583         // ToConRef/TO-XDM/ConRef       
       
   584         else if( Match( lastUriSeg, KPresDMConRef) )
       
   585             {
       
   586             TPtrC8 conRefUri = NSmlDmURI::RemoveLastSeg( aUri );
       
   587             TPtrC8 lastConRefSeg = NSmlDmURI::LastURISeg( conRefUri );
       
   588             
       
   589             if( Match( lastConRefSeg, KPresDMSIPProfile ) )
       
   590                 {
       
   591                 property = EPresPropSIPProfile;
       
   592                 }  
       
   593             else if( Match( lastConRefSeg, KPresDMXDMSet ) )
       
   594                 {
       
   595                 property = EPresPropXDMSet;
       
   596                 }  
       
   597             else
       
   598                 {
       
   599                 status = CSmlDmAdapter::ENotFound;
       
   600                 }
       
   601             }
       
   602         else
       
   603             {
       
   604             status = CSmlDmAdapter::ENotFound;
       
   605             }
       
   606         }
       
   607         
       
   608     else // if id is not valid
       
   609         {
       
   610         status = CSmlDmAdapter::ENotFound;    
       
   611         }
       
   612 
       
   613     // known property and id is ok
       
   614     if ( status == CSmlDmAdapter::EOk )
       
   615         {
       
   616         status = UpdatePropertyL( settingsId, property, aObject ); 
       
   617         PRES_DM_LOG(LOG_LIT("   UpdatePropertyL status: %d"), status); 
       
   618         }
       
   619 
       
   620     Callback().SetStatusL(aStatusRef, status); 
       
   621         
       
   622     PRES_DM_LOG(LOG_LIT(" UpdateLeafObjectL: ends")); 
       
   623     }
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // CPresenceDMAdapter::AddNodeObjectL
       
   627 // -----------------------------------------------------------------------------
       
   628 //
       
   629 void CPresenceDMAdapter::AddNodeObjectL( const TDesC8& aUri, 
       
   630                                     const TDesC8& /*aParentLUID*/, 
       
   631                                     const TInt aStatusRef )
       
   632     {
       
   633     PRES_DM_LOG(LOG_LIT8("AddNodeObjectL(%S): begins"), &aUri);   
       
   634   
       
   635     CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
       
   636     HBufC* lastUriSegment;
       
   637     
       
   638     if (!NSmlDmURI::RemoveLastSeg( aUri ).Compare( KPresDMNodeName ))
       
   639         {
       
   640         // Both the Name and provider id of new set, we are setting from
       
   641         // lastUrisegment, they will expectedly changed by the next calls
       
   642         // to this function by the framework
       
   643         lastUriSegment = ConvertLC(NSmlDmURI::LastURISeg(aUri));
       
   644         TPresSettingsSet mySet; // New set to be created
       
   645         
       
   646         // Processing for set name
       
   647         if (lastUriSegment->Length() > KPresSetNameMaxLength)
       
   648             (mySet.iSetName).Copy(lastUriSegment->Left(KPresSetNameMaxLength));
       
   649         else
       
   650             (mySet.iSetName).Copy(lastUriSegment->Des());
       
   651         CheckDuplicateNameL(mySet.iSetName, 0);
       
   652         
       
   653         // Processing for provider ID
       
   654         if (lastUriSegment->Length() > KPresProviderIDMaxLength)
       
   655             (mySet.iProviderID).Copy(lastUriSegment->Left(KPresProviderIDMaxLength));
       
   656         else
       
   657             (mySet.iProviderID).Copy(lastUriSegment->Des());
       
   658         
       
   659         TInt id = PresSettingsApi::CreateSetL(mySet);
       
   660         PRES_DM_LOG(LOG_LIT("   New set id(%d)"), id);  
       
   661         HBufC8* luid = IntToDes8LC( id ); // << luid
       
   662         Callback().SetMappingL( aUri, *luid );
       
   663         CleanupStack::PopAndDestroy(luid); // luid
       
   664         CleanupStack::PopAndDestroy(lastUriSegment); //lastUriSegment
       
   665         
       
   666 
       
   667         if(id>0) // if set is created successfully
       
   668             {
       
   669             status =  CSmlDmAdapter::EOk;            
       
   670             }
       
   671         }
       
   672     Callback().SetStatusL( aStatusRef, status );
       
   673     PRES_DM_LOG(LOG_LIT("   status(%d)"), status);  
       
   674     PRES_DM_LOG(LOG_LIT(" AddNodeObjectL: ends"));
       
   675     }
       
   676     
       
   677 // -----------------------------------------------------------------------------
       
   678 // CPresenceDMAdapter::DeleteObjectL
       
   679 // -----------------------------------------------------------------------------
       
   680 //
       
   681 void CPresenceDMAdapter::DeleteObjectL( const TDesC8& aUri, 
       
   682                                    const TDesC8& aLUID, 
       
   683                                    const TInt aStatusRef )
       
   684     {
       
   685     PRES_DM_LOG(LOG_LIT8("DeleteObjectL(%S): begins"), &aUri);   
       
   686     //only node object deletion is possible
       
   687 
       
   688     CSmlDmAdapter::TError status = CSmlDmAdapter::EError;
       
   689     if ( !NSmlDmURI::RemoveLastSeg( aUri ).Compare( KPresDMNodeName ) )
       
   690         {
       
   691         TInt id = DesToInt( aLUID );
       
   692         TInt error = PresSettingsApi::RemoveSetL(id); 
       
   693         if ( error == KErrNone )
       
   694             {
       
   695             status = CSmlDmAdapter::EOk;
       
   696             }
       
   697     PRES_DM_LOG(LOG_LIT("   id(%d), error(%d), satus(%d)"), id, error, status);       
       
   698         }
       
   699     Callback().SetStatusL( aStatusRef, status );
       
   700     PRES_DM_LOG(LOG_LIT(" DeleteObjectL: ends"));   
       
   701     }
       
   702     
       
   703 // -----------------------------------------------------------------------------
       
   704 // CPresenceDMAdapter::UpdateLeafObjectL
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 void CPresenceDMAdapter::UpdateLeafObjectL( const TDesC8& /*aUri*/, 
       
   708                                            const TDesC8& /*aLUID*/, 
       
   709                                            RWriteStream*& /*aStream*/, 
       
   710                                            const TDesC8& /*aType*/, 
       
   711                                            const TInt aStatusRef )
       
   712     {
       
   713     PRES_DM_LOG(LOG_LIT("UpdateLeafObjectL: begins"));      
       
   714     // Update from stream not used
       
   715     Callback().SetStatusL(aStatusRef, CSmlDmAdapter::EError);
       
   716     
       
   717     PRES_DM_LOG(LOG_LIT(" UpdateLeafObjectL(stream): end"));      
       
   718     }
       
   719     
       
   720 // -----------------------------------------------------------------------------
       
   721 // CPresenceDMAdapter::ExecuteCommandL()
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 void CPresenceDMAdapter::ExecuteCommandL( const TDesC8& /*aUri*/, 
       
   725                                          const TDesC8& /*aLUID*/, 
       
   726                                          const TDesC8& /*aArgument*/, 
       
   727                                          const TDesC8& /*aType*/, 
       
   728                                          const TInt aStatusRef )
       
   729     {
       
   730     // Not supported 
       
   731     PRES_DM_LOG(LOG_LIT("ExecuteCommandL"));    
       
   732     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   733     }
       
   734 
       
   735 // -----------------------------------------------------------------------------
       
   736 // CPresenceDMAdapter::ExecuteCommandL()
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 void CPresenceDMAdapter::ExecuteCommandL( const TDesC8& /*aUri*/, 
       
   740                                          const TDesC8& /*aLUID*/, 
       
   741                                          RWriteStream*& /*aStream*/, 
       
   742                                          const TDesC8& /*aType*/, 
       
   743                                          const TInt aStatusRef )
       
   744     {
       
   745     // Not supported
       
   746     PRES_DM_LOG(LOG_LIT("ExecuteCommandL"));
       
   747     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   748     }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // CPresenceDMAdapter::CopyCommandL()
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 void CPresenceDMAdapter::CopyCommandL( const TDesC8& /*aTargetURI*/, 
       
   755                                       const TDesC8& /*aTargetLUID*/, 
       
   756                                       const TDesC8& /*aSourceURI*/, 
       
   757                                       const TDesC8& /*aSourceLUID*/, 
       
   758                                       const TDesC8& /*aType*/, 
       
   759                                       TInt aStatusRef )
       
   760     {
       
   761     // Not supported
       
   762     PRES_DM_LOG(LOG_LIT("CopyCommandL"));    
       
   763     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   764     }
       
   765 
       
   766 // -----------------------------------------------------------------------------
       
   767 // CPresenceDMAdapter::StartAtomicL()
       
   768 // -----------------------------------------------------------------------------
       
   769 //
       
   770 void CPresenceDMAdapter::StartAtomicL()
       
   771     {
       
   772     PRES_DM_LOG(LOG_LIT("StartAtomicL"));
       
   773     // Not supported
       
   774     }
       
   775 
       
   776 // -----------------------------------------------------------------------------
       
   777 // CPresenceDMAdapter::CommitAtomicL()
       
   778 // -----------------------------------------------------------------------------
       
   779 //
       
   780 void CPresenceDMAdapter::CommitAtomicL()
       
   781     {
       
   782     PRES_DM_LOG(LOG_LIT("CommitAtomicL"));
       
   783     // Not supported
       
   784     }
       
   785 
       
   786 // -----------------------------------------------------------------------------
       
   787 // CPresenceDMAdapter::RollbackAtomicL()
       
   788 // -----------------------------------------------------------------------------
       
   789 //
       
   790 void CPresenceDMAdapter::RollbackAtomicL()
       
   791     {
       
   792     PRES_DM_LOG(LOG_LIT("RollbackAtomicL"));
       
   793     // Not supported
       
   794     }
       
   795 
       
   796 // -----------------------------------------------------------------------------
       
   797 // CPresenceDMAdapter::StreamingSupport()
       
   798 // -----------------------------------------------------------------------------
       
   799 //
       
   800 TBool CPresenceDMAdapter::StreamingSupport( TInt& /*aItemSize*/ )
       
   801     {
       
   802     PRES_DM_LOG(LOG_LIT("StreamingSupport"));    
       
   803     return EFalse;
       
   804     }
       
   805 
       
   806 // -----------------------------------------------------------------------------
       
   807 // CPresenceDMAdapter::StreamCommittedL()
       
   808 // -----------------------------------------------------------------------------
       
   809 //
       
   810 void CPresenceDMAdapter::StreamCommittedL()
       
   811     {
       
   812     PRES_DM_LOG(LOG_LIT("StreamCommittedL"));    
       
   813     // Not supported
       
   814     }
       
   815     
       
   816 // -----------------------------------------------------------------------------
       
   817 // CPresenceDMAdapter::CompleteOutstandingCmdsL()
       
   818 // -----------------------------------------------------------------------------
       
   819 //
       
   820 void CPresenceDMAdapter::CompleteOutstandingCmdsL()
       
   821     {
       
   822     PRES_DM_LOG(LOG_LIT("CompleteOutstandingCmdsL"));      
       
   823     }
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CPresenceDMAdapter::GetPropertyL
       
   827 // -----------------------------------------------------------------------------
       
   828 //
       
   829 CSmlDmAdapter::TError CPresenceDMAdapter::GetPropertyL( TInt aSetId, 
       
   830                                                   TPresSettingsProperty aProperty, 
       
   831                                                   CBufBase& aObject )
       
   832     {
       
   833     PRES_DM_LOG(LOG_LIT(" GetPropertyL(%d, %d)"),aSetId,aProperty);      
       
   834     
       
   835     HBufC* value = NULL;
       
   836     TInt error( KErrNone );
       
   837     
       
   838     
       
   839     // Get the set only if we dont have it in internal buffer
       
   840     if(iGetSetID != aSetId)
       
   841         {
       
   842         error = PresSettingsApi:: SettingsSetL(aSetId, iGetSet);
       
   843         if(error==KErrNone)
       
   844             iGetSetID = aSetId;
       
   845         PRES_DM_LOG(LOG_LIT("   error(%d)"),error);  
       
   846         }
       
   847         
       
   848     if (error == KErrNone)
       
   849         {
       
   850         switch (aProperty)
       
   851             {
       
   852             case EPresPropSetName:
       
   853                 value = (iGetSet.iSetName).AllocLC();                    
       
   854                 break;
       
   855             case EPresPropProviderID:
       
   856                 value = (iGetSet.iProviderID).AllocLC();
       
   857                 break;
       
   858             case EPresPropSIPProfile:
       
   859                 return GetConRefFromSipIDL(iGetSet.iSipProfile, aObject);
       
   860             case EPresPropXDMSet:
       
   861                 return GetConRefFromXdmIDL(iGetSet.iXDMSetting, aObject);
       
   862             case EPresPropObjectSize:
       
   863                 value = IntToDesLC(iGetSet.iObjectSize);
       
   864                 break;
       
   865             case EPresPropContSrvAdd:
       
   866                 value = (iGetSet.iContSrvrAdd).AllocLC();
       
   867                 break;
       
   868             case EPresPropPubInterval:
       
   869                 value = IntToDesLC(iGetSet.iPublicationInt);
       
   870                 break;
       
   871             case EPresPropMaxSubs:
       
   872                 value = IntToDesLC(iGetSet.iMaxSubscriptions);
       
   873                 break;
       
   874             case EPresPropMaxCntInList:
       
   875                 value = IntToDesLC(iGetSet.iMaxContactsInList);
       
   876                 break;
       
   877             case EPresPropDomainSyntax:
       
   878                 value = (iGetSet.iDomainSyntax).AllocLC();
       
   879                 break;
       
   880             default:
       
   881                 error = KErrNotFound;
       
   882                 break;
       
   883             }
       
   884         }
       
   885         
       
   886     PRES_DM_LOG(LOG_LIT("   value = %S"), &(*value));       
       
   887         
       
   888     if ( error == KErrNone )
       
   889         {
       
   890         HBufC8* utfValue = ConvertLC( *value ); // << utfValue
       
   891         aObject.InsertL( 0, *utfValue );
       
   892         CleanupStack::PopAndDestroy(utfValue);  // >>> utfValue
       
   893         CleanupStack::PopAndDestroy(value);  // >>> value
       
   894         PRES_DM_LOG(LOG_LIT(" return( EOk )"));  
       
   895         return CSmlDmAdapter::EOk;
       
   896         }
       
   897     PRES_DM_LOG(LOG_LIT(" return( ENotFound )"));      
       
   898     return CSmlDmAdapter::ENotFound;
       
   899     }
       
   900     
       
   901 
       
   902 // -----------------------------------------------------------------------------
       
   903 // CPresenceDMAdapter::UpdatePropertyL
       
   904 // -----------------------------------------------------------------------------
       
   905 //
       
   906 CSmlDmAdapter::TError CPresenceDMAdapter::UpdatePropertyL( TInt aSetId, 
       
   907                                                      TPresSettingsProperty aProperty, 
       
   908                                                      const TDesC8& aObject )
       
   909     {
       
   910     PRES_DM_LOG(LOG_LIT(" UpdatePropertyL(%d, %d)"),aSetId,aProperty);     
       
   911     
       
   912     TInt valueInt(KErrNotFound);
       
   913     HBufC* value = ConvertLC(aObject); // value
       
   914     TPtr ptr = value->Des();
       
   915     CSmlDmAdapter::TError result = CSmlDmAdapter::EError;
       
   916     TInt error(KErrNone);
       
   917     
       
   918     // we handle SIP and XDM references in a different way
       
   919     if(aProperty == EPresPropSIPProfile)
       
   920         {
       
   921         valueInt = GetSipIdFromConRefL(aObject);
       
   922         }
       
   923         
       
   924     else if(aProperty == EPresPropXDMSet)
       
   925         {
       
   926         valueInt = GetXdmIdFromConRefL(aObject);
       
   927         }
       
   928     
       
   929     // for all other properties use normal way to get value    
       
   930     else
       
   931         {
       
   932         valueInt = DesToInt(aObject); 
       
   933         }
       
   934         
       
   935     // for str properties
       
   936     if(PresSettingsApi::IsStr(aProperty))
       
   937         {
       
   938         if (SetProperLength(aProperty, ptr))
       
   939             {
       
   940             if(aProperty == EPresPropSetName)
       
   941                 {
       
   942                 CheckDuplicateNameL(ptr, aSetId);                
       
   943                 }
       
   944             PRES_DM_LOG(LOG_LIT("   value = %S"),&(*value));      
       
   945             error = PresSettingsApi::UpdatePropertyL( aSetId, aProperty, *value);
       
   946             if(error == KErrNone)
       
   947                 result = CSmlDmAdapter::EOk;    
       
   948             
       
   949             }
       
   950         else
       
   951             result = CSmlDmAdapter::EInvalidObject;        
       
   952         }
       
   953     // for int properties    
       
   954     else if(valueInt > KErrNotFound) // if valid value
       
   955         {
       
   956         PRES_DM_LOG(LOG_LIT("   valueInt = %d"), valueInt);
       
   957         error = PresSettingsApi::UpdatePropertyL( aSetId, aProperty, valueInt);
       
   958         if(error == KErrNone)
       
   959             result = CSmlDmAdapter::EOk;
       
   960         }
       
   961     else
       
   962         result = CSmlDmAdapter::ENotFound;
       
   963     
       
   964     CleanupStack::PopAndDestroy(value);
       
   965     
       
   966     
       
   967     PRES_DM_LOG(LOG_LIT("   error(%d) , result(%d)"), error, result);
       
   968     return result;
       
   969     }
       
   970 
       
   971 // -----------------------------------------------------------------------------
       
   972 // CPresenceDMAdapter::Match
       
   973 // -----------------------------------------------------------------------------
       
   974 //
       
   975 TBool CPresenceDMAdapter::Match( const TDesC8& aLeft, const TDesC8& aRight )
       
   976     {
       
   977     if ( !aLeft.Compare( aRight ) )
       
   978         {
       
   979         return ETrue;
       
   980         }
       
   981     return EFalse;
       
   982     }         
       
   983  
       
   984  // -----------------------------------------------------------------------------
       
   985 // CPresenceDMAdapter::FillNodeInfoL
       
   986 // ------------------------------------------------------------------------------
       
   987 //
       
   988 void CPresenceDMAdapter::FillNodeInfoL( MSmlDmDDFObject& aNode,
       
   989                                        TSmlDmAccessTypes aAccTypes,
       
   990                                        MSmlDmDDFObject::TOccurence aOccurrence, 
       
   991                                        MSmlDmDDFObject::TScope aScope, 
       
   992                                        MSmlDmDDFObject::TDFFormat aFormat,
       
   993                                        const TDesC8& aDescription)
       
   994     {
       
   995     aNode.SetAccessTypesL( aAccTypes );
       
   996     aNode.SetOccurenceL( aOccurrence );
       
   997     aNode.SetScopeL( aScope );
       
   998     aNode.SetDFFormatL( aFormat );
       
   999     
       
  1000     if( aFormat!= MSmlDmDDFObject::ENode )
       
  1001         {
       
  1002         aNode.AddDFTypeMimeTypeL( KPresDMTextPlain );
       
  1003         }
       
  1004     aNode.SetDescriptionL( aDescription );
       
  1005     }
       
  1006     
       
  1007 // -----------------------------------------------------------------------------
       
  1008 // CPresenceDMAdapter::ConvertLC
       
  1009 // -----------------------------------------------------------------------------
       
  1010 //  
       
  1011 HBufC8* CPresenceDMAdapter::ConvertLC( const TDesC& aSource ) const
       
  1012     {   
       
  1013     HBufC8* destination = HBufC8::NewLC( aSource.Length() );
       
  1014     TPtr8 bufferPtr = destination->Des();
       
  1015     CnvUtfConverter::ConvertFromUnicodeToUtf8( bufferPtr, aSource );
       
  1016     return destination;
       
  1017     }   
       
  1018     
       
  1019 // -----------------------------------------------------------------------------
       
  1020 // CPresenceDMAdapter::ConvertLC
       
  1021 // -----------------------------------------------------------------------------
       
  1022 //  
       
  1023 HBufC*  CPresenceDMAdapter::ConvertLC( const TDesC8& aSource ) const 
       
  1024     {   
       
  1025     HBufC* destination = HBufC::NewLC(aSource.Length());
       
  1026     TPtr bufferPtr = destination->Des();
       
  1027     CnvUtfConverter::ConvertToUnicodeFromUtf8( bufferPtr, aSource );
       
  1028     return destination;
       
  1029     }
       
  1030 
       
  1031 // ----------------------------------------------------------------------------
       
  1032 // CPresenceDMAdapter::DesToInt
       
  1033 // ----------------------------------------------------------------------------
       
  1034 TInt CPresenceDMAdapter::DesToInt( const TDesC8& aLuid ) const
       
  1035     {
       
  1036     TLex8 lex( aLuid );
       
  1037     TInt value ( KErrNotFound );
       
  1038     lex.Val( value );
       
  1039     return value;
       
  1040     }
       
  1041 
       
  1042 // ----------------------------------------------------------------------------
       
  1043 // CPresenceDMAdapter::IntToDes8LC
       
  1044 // ----------------------------------------------------------------------------
       
  1045 HBufC8* CPresenceDMAdapter::IntToDes8LC( const TInt aLuid ) const
       
  1046     {
       
  1047     // 10 = max length of 32bit integer
       
  1048     HBufC8* buf = HBufC8::NewLC( KPresDMMaxIntLength ); // << buf
       
  1049     TPtr8 ptrBuf = buf->Des();
       
  1050     ptrBuf.Num( aLuid );
       
  1051     return buf;
       
  1052     }
       
  1053 
       
  1054 // ----------------------------------------------------------------------------
       
  1055 // CPresenceDMAdapter::IntToDesLC
       
  1056 // ----------------------------------------------------------------------------
       
  1057 HBufC* CPresenceDMAdapter::IntToDesLC( const TInt aLuid ) const
       
  1058     {
       
  1059     // 10 = max length of 32bit integer
       
  1060     HBufC* buf = HBufC::NewLC( KPresDMMaxIntLength ); // << buf
       
  1061     TPtr ptrBuf = buf->Des();
       
  1062     ptrBuf.Num( aLuid );
       
  1063     return buf;
       
  1064     }
       
  1065     
       
  1066 // -----------------------------------------------------------------------------
       
  1067 // CPresenceDMAdapter::GetConRefFromSipIDL
       
  1068 // -----------------------------------------------------------------------------
       
  1069 //
       
  1070 CSmlDmAdapter::TError CPresenceDMAdapter::GetConRefFromSipIDL( TInt aSipID,
       
  1071                                                       CBufBase& aObject)
       
  1072     {
       
  1073     PRES_DM_LOG(LOG_LIT(" GetConRefFromSipIDL(aSipId:%d)"),aSipID);
       
  1074 
       
  1075     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
  1076     
       
  1077     TBool found(EFalse);
       
  1078     
       
  1079     if( aSipID != KErrNotFound )
       
  1080         {
       
  1081         CBufBase* result = CBufFlat::NewL(1);
       
  1082         CleanupStack::PushL(result);    // << result
       
  1083         
       
  1084         // Request all the sip settings identifiers 
       
  1085         Callback().FetchLinkL( KPresDMSipDMNode, *result, status);
       
  1086         PRES_DM_LOG(LOG_LIT("   FetchLinkL(SIP) status : %d"), status );
       
  1087         
       
  1088         if( status == EOk )
       
  1089             {
       
  1090             TPtr8 uriSeg8Ptr = result->Ptr(0);
       
  1091             
       
  1092             HBufC8* uriSegBuffer = uriSeg8Ptr.AllocLC(); // << uriSegBuffer
       
  1093             PRES_DM_LOG(LOG_LIT8("   uri : '%S'"), uriSegBuffer );
       
  1094             
       
  1095             TPtr8 uriSegBufferPtr = uriSegBuffer->Des();
       
  1096             
       
  1097             TInt numOfUriSegs = NSmlDmURI::NumOfURISegs(uriSeg8Ptr);
       
  1098             
       
  1099             TBuf8<100> idLinkBuffer;
       
  1100             
       
  1101             TInt foundId(KErrNotFound);
       
  1102             
       
  1103                      
       
  1104             // Check if given SIP set id match with any of found
       
  1105             // SIP settings identifiers
       
  1106             while( numOfUriSegs > 0 )
       
  1107                 {
       
  1108                 idLinkBuffer = NSmlDmURI::LastURISeg(uriSegBufferPtr);
       
  1109                 uriSegBufferPtr = NSmlDmURI::RemoveLastSeg(uriSegBufferPtr);
       
  1110                 
       
  1111                 idLinkBuffer.Insert(0, KPresDMSipDMNode);
       
  1112                 idLinkBuffer.Insert(3, KPresDMSeparator);
       
  1113                 idLinkBuffer.Append(KPresDMSeparator);
       
  1114                 idLinkBuffer.Append(KPresDMSipIdPrefix);
       
  1115                 
       
  1116                 TPtrC8 finalLink = idLinkBuffer;
       
  1117                         
       
  1118                 //Reqest the ID
       
  1119                 result->Reset();
       
  1120                 Callback().FetchLinkL( finalLink, *result, status);
       
  1121                 PRES_DM_LOG(LOG_LIT8("   FetchLinkL(%S) status : %d"), &idLinkBuffer, status );                        
       
  1122                 if( status == EOk )
       
  1123                     {
       
  1124                     foundId = DesToInt(result->Ptr(0));
       
  1125                     PRES_DM_LOG(LOG_LIT("   foundId : %d"), foundId );                        
       
  1126                     if (foundId == aSipID)
       
  1127                         {
       
  1128                         found = ETrue;
       
  1129                         aObject.InsertL(0, NSmlDmURI::RemoveLastSeg(finalLink));
       
  1130                         break;
       
  1131                         }
       
  1132                     }
       
  1133                 
       
  1134                 numOfUriSegs--;  
       
  1135                 }
       
  1136             CleanupStack::PopAndDestroy( uriSegBuffer );    // >>> uriSegBuffer
       
  1137             }
       
  1138         
       
  1139         CleanupStack::PopAndDestroy( result );    // >>> result
       
  1140         }
       
  1141     if(found == EFalse)
       
  1142         {
       
  1143         status = CSmlDmAdapter::ENotFound;
       
  1144         }
       
  1145         
       
  1146     PRES_DM_LOG(LOG_LIT(" GetConRefFromSipIDL(%d): ends"), status);    
       
  1147     
       
  1148     return status;
       
  1149     
       
  1150     }
       
  1151     
       
  1152 // -----------------------------------------------------------------------------
       
  1153 // CPresenceDMAdapter::GetConRefFromXdmIDL
       
  1154 // -----------------------------------------------------------------------------
       
  1155 //
       
  1156 CSmlDmAdapter::TError CPresenceDMAdapter::GetConRefFromXdmIDL( TInt aXdmID,
       
  1157                                                       CBufBase& aObject)
       
  1158     {
       
  1159     PRES_DM_LOG(LOG_LIT(" GetConRefFromXdmIDL(aXdmId:%d)"),aXdmID);
       
  1160 
       
  1161     CSmlDmAdapter::TError status = CSmlDmAdapter::ENotFound;
       
  1162     
       
  1163     if( aXdmID != KErrNotFound )
       
  1164         {
       
  1165         CBufBase* result = CBufFlat::NewL(1);
       
  1166         CleanupStack::PushL(result);    // << result
       
  1167         
       
  1168         // Request all the XDM settings identifiers 
       
  1169         Callback().FetchLinkL( KPresDMXdmDMNode, *result, status);
       
  1170         PRES_DM_LOG(LOG_LIT("   FetchLinkL(XDM) status : %d"), status );
       
  1171         TInt id(KErrNotFound);
       
  1172         
       
  1173         TPtrC8 lastUriSegXdm;
       
  1174         
       
  1175         if( status == EOk )
       
  1176             {
       
  1177             TPtr8 uriSeg8Ptr = result->Ptr(0);
       
  1178             
       
  1179             HBufC8* uriSegBuffer = uriSeg8Ptr.AllocLC();
       
  1180             
       
  1181             TPtr8 uriSegBufferPtr = uriSegBuffer->Des();
       
  1182             
       
  1183             TInt numOfUriSegs = NSmlDmURI::NumOfURISegs(uriSeg8Ptr);
       
  1184             
       
  1185             // Check if the Presence settings XDM settings id match with one of the found
       
  1186             // XDM settings identifiers
       
  1187             while( numOfUriSegs > 0)
       
  1188                 {
       
  1189                 lastUriSegXdm.Set(NSmlDmURI::LastURISeg(uriSegBufferPtr));
       
  1190                 uriSegBufferPtr = NSmlDmURI::RemoveLastSeg(uriSegBufferPtr);
       
  1191                 id = DesToInt(lastUriSegXdm);
       
  1192 
       
  1193                 if(id == aXdmID)
       
  1194                     {
       
  1195                     // Total length of the sip settings link where one is for
       
  1196                     // the separator
       
  1197                     TInt XDMLinkLength = KPresDMXdmDMNode().Length() + 
       
  1198                                          KPresDMSeparator().Length() +
       
  1199                                          lastUriSegXdm.Length();
       
  1200                     HBufC8* XDMLink = HBufC8::NewLC( XDMLinkLength );   // <<< XDMLink
       
  1201                     
       
  1202                     TPtr8 XDMLinkPtr = XDMLink->Des();
       
  1203                     
       
  1204                     XDMLinkPtr.Append( KPresDMXdmDMNode );
       
  1205                     XDMLinkPtr.Append( KPresDMSeparator );
       
  1206                     XDMLinkPtr.Append( lastUriSegXdm );
       
  1207                     
       
  1208                     aObject.InsertL( 0, XDMLinkPtr );
       
  1209                     
       
  1210                     CleanupStack::PopAndDestroy( XDMLink );   // >>> XDMLink
       
  1211                     status = CSmlDmAdapter::EOk;
       
  1212                     break;
       
  1213                     }
       
  1214                 numOfUriSegs--;
       
  1215                 }
       
  1216             CleanupStack::PopAndDestroy( uriSegBuffer );    // >>> uriSegBuffer
       
  1217             }
       
  1218         CleanupStack::PopAndDestroy( result );    // >>> result
       
  1219         }
       
  1220         
       
  1221     PRES_DM_LOG(LOG_LIT(" GetConRefFromXdmIDL(%d): ends"), status);   
       
  1222     return status;
       
  1223     } 
       
  1224     
       
  1225 // -----------------------------------------------------------------------------
       
  1226 // CPresenceDMAdapter::IsPresIDValidL
       
  1227 // -----------------------------------------------------------------------------
       
  1228 //
       
  1229 TBool CPresenceDMAdapter::IsPresIDValidL(TInt aSetId)
       
  1230     {
       
  1231     TPresSettingsSet tempSet;
       
  1232     if ((PresSettingsApi::SettingsSetL(aSetId,tempSet)) == KErrNone)
       
  1233         return ETrue;
       
  1234     PRES_DM_LOG(LOG_LIT8(" IsPresIDValidL - Invalid settings : %d"), aSetId );
       
  1235     return EFalse;   
       
  1236     }
       
  1237     
       
  1238 // -----------------------------------------------------------------------------
       
  1239 // CPresenceDMAdapter::GetSipIdFromConRefL
       
  1240 // -----------------------------------------------------------------------------
       
  1241 //
       
  1242 TInt CPresenceDMAdapter::GetSipIdFromConRefL(const TDesC8& aUri )
       
  1243     {
       
  1244     PRES_DM_LOG(LOG_LIT8(" GetSipIdFromConRefL(%S)"),&aUri);
       
  1245     
       
  1246     CSmlDmAdapter::TError status = EOk;
       
  1247     TInt returnId(KErrNotFound);
       
  1248     
       
  1249     CBufBase* result = CBufFlat::NewL(1);
       
  1250     CleanupStack::PushL(result);    // << result
       
  1251 
       
  1252     // make all SIP profiles known
       
  1253     Callback().FetchLinkL( KPresDMSipDMNode, *result, status );
       
  1254     
       
  1255     //TBuf8<300> resultBuf;
       
  1256     //result->Read(0, resultBuf,result->Size());
       
  1257     
       
  1258     TPtrC8 uri = NSmlDmURI::RemoveDotSlash( aUri );
       
  1259     TBuf8<50> object = uri;
       
  1260         
       
  1261     object.Append( KPresDMSeparator );
       
  1262     object.Append( KPresDMSipIdPrefix );
       
  1263     
       
  1264     result->Reset();
       
  1265     Callback().FetchLinkL( object, *result, status);
       
  1266     
       
  1267     //resultBuf.Zero();
       
  1268     //result->Read(0, resultBuf,result->Size());
       
  1269         
       
  1270     if( status == EOk )
       
  1271         {
       
  1272         TUint32 id = DesToInt( result->Ptr( 0 ) );
       
  1273         returnId = (TInt)id;       
       
  1274         }
       
  1275     CleanupStack::PopAndDestroy( result );   // >>> result   
       
  1276     
       
  1277     PRES_DM_LOG(LOG_LIT("   status(%d), returnId(%d): end"), status, returnId);
       
  1278   
       
  1279     return returnId;       
       
  1280     }
       
  1281         
       
  1282 // -----------------------------------------------------------------------------
       
  1283 // CPresenceDMAdapter::GetXdmIdFromConRefL
       
  1284 // -----------------------------------------------------------------------------
       
  1285 //
       
  1286 TInt CPresenceDMAdapter::GetXdmIdFromConRefL(const TDesC8& aUri )
       
  1287     {
       
  1288     PRES_DM_LOG(LOG_LIT8(" GetXdmIdFromConRefL(%S)"),&aUri);
       
  1289     const TInt KPresDMIdDesSize = 10;
       
  1290     
       
  1291     CSmlDmAdapter::TError status = EOk;
       
  1292     TInt id( KErrNotFound );
       
  1293     TBuf8<KPresDMIdDesSize> idDes;
       
  1294     
       
  1295     CBufBase* result = CBufFlat::NewL(1);
       
  1296     CleanupStack::PushL(result);    // << result
       
  1297 
       
  1298     TPtrC8 uri = NSmlDmURI::RemoveDotSlash( aUri );
       
  1299     // Request the xdm settings identifier
       
  1300     Callback().FetchLinkL( uri, *result, status);
       
  1301         
       
  1302     if( status == EOk ) // if the link is valid. Wont use result
       
  1303         {
       
  1304         TPtrC8 idSegment = NSmlDmURI::LastURISeg(aUri);
       
  1305         id = DesToInt(idSegment);
       
  1306         }
       
  1307     CleanupStack::PopAndDestroy( result );   // >>> result   
       
  1308     
       
  1309     PRES_DM_LOG(LOG_LIT("   status(%d), id(%d): end"), status, id);
       
  1310     return id;       
       
  1311     }
       
  1312     
       
  1313 // ---------------------------------------------------------------------------
       
  1314 // CPresenceDMAdapter::GetPrefixL()
       
  1315 // ---------------------------------------------------------------------------
       
  1316 // 
       
  1317 HBufC* CPresenceDMAdapter::GetPrefixL( HBufC* aName )
       
  1318     {
       
  1319     TPtrC prefix = aName->Des();
       
  1320     TInt lastBrace = aName->LocateReverse('(');
       
  1321     if ( lastBrace != KErrNotFound )
       
  1322         {
       
  1323         // aName looks like "<prefix><brace><something>".
       
  1324         // See if <something> is an integer number and
       
  1325         // <something> ends to a brace.
       
  1326         TPtrC num = aName->Right( aName->Length() - lastBrace - 1 );
       
  1327         TInt val;
       
  1328         TLex lex( num );
       
  1329         if ( lex.Val( val ) == KErrNone && num.Locate(')') == num.Length() - 1 )
       
  1330             {
       
  1331             // Yes, the trailer is an integer.
       
  1332             prefix.Set( aName->Left( lastBrace ) );
       
  1333             }
       
  1334         }
       
  1335     return prefix.AllocL();
       
  1336     }    
       
  1337     
       
  1338 // -----------------------------------------------------------------------------
       
  1339 // CPresenceDMAdapter::CheckDuplicateNameL
       
  1340 // Checks if duplicate named Presence Settings. Rename if same.
       
  1341 // -----------------------------------------------------------------------------
       
  1342 void CPresenceDMAdapter::CheckDuplicateNameL( TDes& aSetName, const TInt& aSetId)
       
  1343     {
       
  1344     PRES_DM_LOG(LOG_LIT(" CheckDuplicateNameL(%S, %d)"),&aSetName, aSetId);
       
  1345     
       
  1346 	_LIT( KPresDMNumbering, "(%N)" );
       
  1347     const TInt KPresDMFormatExtraLen = 6;
       
  1348     
       
  1349     HBufC* newName = HBufC::NewLC(KPresSetNameMaxLength);
       
  1350     newName->Des().Copy(aSetName);
       
  1351 
       
  1352 	RArray<TInt> setIds;
       
  1353 	CleanupClosePushL( setIds );
       
  1354 	CDesCArray* names = PresSettingsApi::GetAllSetsNamesLC(setIds);
       
  1355 	TInt count(setIds.Count());
       
  1356 	
       
  1357     newName = newName->ReAlloc( 
       
  1358         newName->Length() + KPresDMFormatExtraLen );// enough for formatting
       
  1359 
       
  1360     HBufC* tempSetName = NULL;
       
  1361     TInt pos = 0;// used as dummy
       
  1362     TInt found = 0;
       
  1363     TInt index = 1;
       
  1364     TPtr ptr = newName->Des();
       
  1365     
       
  1366     // do the actual checking of name
       
  1367     found = names->Find( *newName, pos );
       
  1368     while ( found == 0 )
       
  1369         {
       
  1370         if ( !tempSetName )
       
  1371             {
       
  1372             tempSetName = GetPrefixL( newName );
       
  1373             tempSetName = tempSetName->ReAlloc( 
       
  1374                 tempSetName->Length() + KPresDMFormatExtraLen );// enough for formatting
       
  1375             CleanupStack::PushL( tempSetName );
       
  1376             tempSetName->Des().Append( KPresDMNumbering );
       
  1377             }
       
  1378         StringLoader::Format( ptr, *tempSetName, -1, index );
       
  1379         found = names->Find( *newName, pos );
       
  1380         index++;
       
  1381         }
       
  1382 
       
  1383     // cleanup
       
  1384     if ( tempSetName )
       
  1385         {
       
  1386         CleanupStack::PopAndDestroy( tempSetName ); //tempSetName
       
  1387         }
       
  1388     
       
  1389     CleanupStack::PopAndDestroy(names); // names
       
  1390     CleanupStack::PopAndDestroy(1); // setIds 
       
  1391 
       
  1392     aSetName.Copy(newName->Des());
       
  1393     CleanupStack::PopAndDestroy( newName );
       
  1394     
       
  1395     PRES_DM_LOG(LOG_LIT(" CheckDuplicateNameL(%S): end"),&aSetName);
       
  1396     }
       
  1397     
       
  1398 // -----------------------------------------------------------------------------
       
  1399 // CPresenceDMAdapter::SetProperLength
       
  1400 // -----------------------------------------------------------------------------
       
  1401 TBool CPresenceDMAdapter::SetProperLength(TPresSettingsProperty aProp, TPtr& aValue)
       
  1402     {
       
  1403     PRES_DM_LOG(LOG_LIT(" SetProperLength(%d)"),aProp);
       
  1404     
       
  1405     TBool result(ETrue);
       
  1406     switch (aProp)
       
  1407         {
       
  1408         case EPresPropSetName:
       
  1409             if(aValue.Length() > KPresSetNameMaxLength)
       
  1410                 aValue = aValue.Left(KPresSetNameMaxLength);
       
  1411             break;
       
  1412         
       
  1413         case EPresPropContSrvAdd:
       
  1414             if(aValue.Length() > KContentSrvrAddMaxLength)
       
  1415                 result = EFalse;            
       
  1416             break;
       
  1417             
       
  1418         case EPresPropDomainSyntax:
       
  1419             if(aValue.Length() > KPresDomainSyntxMaxLength)
       
  1420                 result = EFalse;
       
  1421             break;
       
  1422         
       
  1423         case EPresPropProviderID:
       
  1424             if(aValue.Length() > KPresProviderIDMaxLength)
       
  1425                 aValue = aValue.Left(KPresProviderIDMaxLength);
       
  1426             break;
       
  1427         default:
       
  1428             break;
       
  1429         }
       
  1430     PRES_DM_LOG(LOG_LIT(" SetProperLength(%d): end"),result);
       
  1431     return result;   
       
  1432     }
       
  1433 
       
  1434 // End of File
       
  1435 
       
  1436 
       
  1437