omadm/omadmextensions/adapters/imps/src/nsmldmimpsadapter.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Device Management IMPS Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // TaH 3.6.2005 Added the checking of Name, PrefAddr, AAuthName and AAuthSecret lenght. 
       
    21 //              and corrected the fetching of PrefConRef parameter.
       
    22 // TaH 16.6.2005 Some minor changes done according the code review comments.
       
    23 // TaH 8.7.2005 Corrected errors ESBA-6DYMFL, ESBA-6DYNMK and ESBA-6DYMNV
       
    24 // TaH 27.9.2005 Dynamic node names changed, 
       
    25 //				 reduced number of warnings caused by debug logs writtings.
       
    26 
       
    27 // INCLUDE FILES
       
    28 
       
    29 
       
    30 #include <msvids.h>
       
    31 #include <implementationproxy.h> // For TImplementationProxy definition
       
    32 #include <utf.h>
       
    33 #include <iapprefs.h>
       
    34 #include <commdb.h>
       
    35 #include <cdbcols.h>			 // CommsDB columname defs
       
    36 #include <sysutil.h>
       
    37 #include <e32des8.h>
       
    38 #include <cimpssapsettings.h>         //CIMPSSAPSettings
       
    39 #include <cimpssapsettingsstore.h>    //CWWVSAPSettingsStore
       
    40 #include <cimpssapsettingslist.h>     //CIMPSSAPSettingsList
       
    41 #include <featmgr.h>
       
    42 #include "nsmldmimpluids.h"
       
    43 #include "nsmldmimpsadapter.h"
       
    44 #include "nsmldebug.h"
       
    45 #include "nsmlconstants.h"
       
    46 #include "nsmldmconst.h"
       
    47 #include "nsmldmiapmatcher.h"
       
    48 #include "nsmldmuri.h"
       
    49 
       
    50 // EXTERNAL DATA STRUCTURES
       
    51 
       
    52 // EXTERNAL FUNCTION PROTOTYPES  
       
    53 
       
    54 // CONSTANTS
       
    55 
       
    56 // MACROS
       
    57 
       
    58 // LOCAL CONSTANTS AND MACROS
       
    59 
       
    60 // MODULE DATA STRUCTURES
       
    61 
       
    62 // LOCAL FUNCTION PROTOTYPES
       
    63 
       
    64 // FORWARD DECLARATIONS
       
    65 
       
    66 #ifndef __WINS__
       
    67 // This lowers the unnecessary compiler warning (armv5) to remark.
       
    68 // "Warning:  #174-D: expression has no effect..." is caused by 
       
    69 // DBG_ARGS8 macro in no-debug builds.
       
    70 #pragma diag_remark 174
       
    71 #endif
       
    72 
       
    73 // ============================= LOCAL FUNCTIONS ==============================
       
    74 
       
    75 // ============================ MEMBER FUNCTIONS ==============================
       
    76 	
       
    77 // ----------------------------------------------------------------------------
       
    78 // CNSmlDmImpsAdapter::CNSmlDmImpsAdapter()
       
    79 // C++ default constructor can NOT contain any code, that
       
    80 // might leave.
       
    81 // ----------------------------------------------------------------------------
       
    82 
       
    83 CNSmlDmImpsAdapter::CNSmlDmImpsAdapter(TAny* aEcomArguments) : 
       
    84         CSmlDmAdapter(aEcomArguments)
       
    85 	{
       
    86 	_DBG_FILE( "CNSmlDmImpsAdapter::CNSmlDmImpsAdapter(): begin" );
       
    87 	_DBG_FILE( "CNSmlDmImpsAdapter::CNSmlDmImpsAdapter(): end" );
       
    88 	}
       
    89 
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 // CNSmlDmImpsAdapter::ConstructL()
       
    93 // Symbian 2nd phase constructor can leave. 
       
    94 // The global variables are created here.
       
    95 // ----------------------------------------------------------------------------
       
    96 void CNSmlDmImpsAdapter::ConstructL( MSmlDmCallback *aDmCallback )
       
    97 	{
       
    98 	iCallBack = aDmCallback;
       
    99 	FeatureManager::InitializeLibL();
       
   100   iFeatMgrInitialized = ETrue;
       
   101 	}
       
   102 
       
   103 // ----------------------------------------------------------------------------
       
   104 // CNSmlDmImpsAdapter* CNSmlDmImpsAdapter::NewL( )
       
   105 // Two-phased constructor.
       
   106 // ----------------------------------------------------------------------------
       
   107 CNSmlDmImpsAdapter* CNSmlDmImpsAdapter::NewL( MSmlDmCallback* aDmCallback )
       
   108 	{
       
   109 	_DBG_FILE( "CNSmlDmImpsAdapter::NewL(): begin" );
       
   110 	CNSmlDmImpsAdapter* self = NewLC( aDmCallback );
       
   111 	CleanupStack::Pop();
       
   112 	_DBG_FILE( "CNSmlDmImpsAdapter::NewL(): end" );	
       
   113 	return self;
       
   114 	}
       
   115 
       
   116 // ----------------------------------------------------------------------------
       
   117 // CNSmlDmImpsAdapter* CNSmlDmImpsAdapter::NewLC( )
       
   118 // Two-phased constructor.
       
   119 // ----------------------------------------------------------------------------
       
   120 CNSmlDmImpsAdapter* CNSmlDmImpsAdapter::NewLC( MSmlDmCallback* aDmCallback )
       
   121 	{
       
   122 	_DBG_FILE( "CNSmlDmImpsAdapter::NewLC(): begin" );
       
   123 	CNSmlDmImpsAdapter* self = new( ELeave ) CNSmlDmImpsAdapter( aDmCallback );
       
   124 	CleanupStack::PushL( self );
       
   125 	self->ConstructL( aDmCallback );
       
   126 	_DBG_FILE( "CNSmlDmImpsAdapter::NewLC(): end" );
       
   127 	return self;
       
   128 	}
       
   129 
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // CNSmlDmImpsAdapter::~CNSmlDmImpsAdapter()    
       
   133 // Destructor, the global variables are deleted here.
       
   134 // ----------------------------------------------------------------------------
       
   135 CNSmlDmImpsAdapter::~CNSmlDmImpsAdapter()
       
   136 	{
       
   137 	_DBG_FILE( "CNSmlDmImpsAdapter::~CNSmlDmImpsAdapter(): begin" );
       
   138 	if(iFeatMgrInitialized)
       
   139     		{
       
   140     			FeatureManager::UnInitializeLib();
       
   141     		}
       
   142 
       
   143     _DBG_FILE( "CNSmlDmImpsAdapter::~CNSmlDmImpsAdapter(): end" );
       
   144 	}
       
   145 
       
   146 // ----------------------------------------------------------------------------
       
   147 //  CNSmlDmImpsAdapter::DDFVersionL()
       
   148 //  The method returns the DDFVersion number.
       
   149 // ----------------------------------------------------------------------------
       
   150 void CNSmlDmImpsAdapter::DDFVersionL( CBufBase& aDDFVersion )
       
   151 	{
       
   152 	_DBG_FILE( "CNSmlDmImpsAdapter::DDFVersionL( TDes& aDDFVersion ): begin" );
       
   153 	aDDFVersion.InsertL( 0,KNSmlDMImpsDDFVersion );
       
   154 	_DBG_FILE( "CNSmlDmImpsAdapter::DDFVersionL( TDes& aDDFVersion ): end" );
       
   155 	}
       
   156 
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 //  CNSmlDmImpsAdapter::DDFStructureL()
       
   160 //  The method creates the DDFStructure
       
   161 // ----------------------------------------------------------------------------
       
   162 void CNSmlDmImpsAdapter::DDFStructureL( MSmlDmDDFObject& aDDF )
       
   163 	{
       
   164 	_DBG_FILE( "CNSmlDmImpsAdapter::DDFStructureL(): begin" );
       
   165 	
       
   166 	TSmlDmAccessTypes allAccessTypes;
       
   167     allAccessTypes.SetAdd();  
       
   168 	allAccessTypes.SetDelete();
       
   169 	allAccessTypes.SetGet();
       
   170 	allAccessTypes.SetReplace();
       
   171 
       
   172 	TSmlDmAccessTypes accessTypesAddGet;
       
   173     accessTypesAddGet.SetAdd();  
       
   174 	accessTypesAddGet.SetGet();
       
   175     
       
   176 	TSmlDmAccessTypes accessTypesGet;
       
   177 	accessTypesGet.SetGet();
       
   178 	
       
   179 	TSmlDmAccessTypes accessTypesNoDel;
       
   180     accessTypesNoDel.SetAdd();  
       
   181 	accessTypesNoDel.SetGet();
       
   182 	accessTypesNoDel.SetReplace();
       
   183 
       
   184 	TSmlDmAccessTypes accessTypesASecret;
       
   185 	accessTypesASecret.SetAdd();
       
   186 	accessTypesASecret.SetDelete();
       
   187 	accessTypesASecret.SetReplace();
       
   188 	
       
   189     
       
   190   // IMPS
       
   191     MSmlDmDDFObject& imps = aDDF.AddChildObjectL( KNSmlDMImpsNodeName );
       
   192     FillNodeInfoL( imps, 
       
   193                     accessTypesGet, 
       
   194                     MSmlDmDDFObject::EOne,
       
   195                     MSmlDmDDFObject::EPermanent, 
       
   196                     MSmlDmDDFObject::ENode, KNSmlDMImpsDescr );
       
   197 
       
   198     // run-time node under IMPS
       
   199     // IMPS/<X>
       
   200     MSmlDmDDFObject& rtNode = imps.AddChildObjectGroupL(); 
       
   201     FillNodeInfoL( rtNode, 
       
   202                 allAccessTypes,
       
   203                 MSmlDmDDFObject::EZeroOrMore, 
       
   204                 MSmlDmDDFObject::EDynamic, 
       
   205                 MSmlDmDDFObject::ENode, 
       
   206                 KNSmlDMDynamicNodeDescr );
       
   207     
       
   208     // AppID
       
   209     MSmlDmDDFObject& appId = rtNode.AddChildObjectL( KNSmlDMImpsAppId );
       
   210     FillNodeInfoL( appId, 
       
   211                    accessTypesAddGet, 
       
   212                    MSmlDmDDFObject::EZeroOrOne, 
       
   213                    MSmlDmDDFObject::EDynamic, 
       
   214                    MSmlDmDDFObject::EChr, 
       
   215                    KNSmlDMImpsAppIDDescr );
       
   216 
       
   217     // Name
       
   218     MSmlDmDDFObject& name = rtNode.AddChildObjectL( KNSmlDMImpsName );
       
   219     FillNodeInfoL( name, 
       
   220                    allAccessTypes, 
       
   221                    MSmlDmDDFObject::EZeroOrOne, 
       
   222                    MSmlDmDDFObject::EDynamic, 
       
   223                    MSmlDmDDFObject::EChr, 
       
   224                    KNSmlDMImpsNameDescr );
       
   225 
       
   226     // PrefConRef
       
   227     MSmlDmDDFObject& prefConRef = rtNode.AddChildObjectL( KNSmlDMImpsPrefConRef );
       
   228     FillNodeInfoL( prefConRef, 
       
   229                    allAccessTypes, 
       
   230                    MSmlDmDDFObject::EZeroOrOne, 
       
   231                    MSmlDmDDFObject::EDynamic, 
       
   232                    MSmlDmDDFObject::EChr, 
       
   233                    KNSmlDMImpsPrefConRefDescr );
       
   234 
       
   235     // PrefAddr
       
   236     MSmlDmDDFObject& prefAddr = rtNode.AddChildObjectL( KNSmlDMImpsPrefAddr );
       
   237     FillNodeInfoL( prefAddr, 
       
   238                    allAccessTypes, 
       
   239                    MSmlDmDDFObject::EZeroOrOne, 
       
   240                    MSmlDmDDFObject::EDynamic, 
       
   241                    MSmlDmDDFObject::EChr, 
       
   242                    KNSmlDMImpsPrefAddrDescr );
       
   243 
       
   244     // AppAuth
       
   245     MSmlDmDDFObject& appAuth = rtNode.AddChildObjectL( KNSmlDMImpsAppAuth );
       
   246     FillNodeInfoL( appAuth, 
       
   247                    allAccessTypes, 
       
   248                    MSmlDmDDFObject::EZeroOrOne,
       
   249                    MSmlDmDDFObject::EDynamic,
       
   250                    MSmlDmDDFObject::ENode,
       
   251                    KNSmlDMImpsAppAuthDescr );
       
   252 	
       
   253     // Run-time node under AppAuth
       
   254     MSmlDmDDFObject& rtNodeAppAuth = appAuth.AddChildObjectGroupL(); 
       
   255     FillNodeInfoL( rtNodeAppAuth, 
       
   256                    allAccessTypes, 
       
   257                    MSmlDmDDFObject::EZeroOrMore, 
       
   258                    MSmlDmDDFObject::EDynamic, 
       
   259                    MSmlDmDDFObject::ENode, 
       
   260                    KNSmlDMDynamicNodeDescr );
       
   261 
       
   262     // AAuthLevel
       
   263     MSmlDmDDFObject& AAuthLevel = rtNodeAppAuth.AddChildObjectL( KNSmlDMImpsAAuthLevel );
       
   264     FillNodeInfoL( AAuthLevel,
       
   265                    allAccessTypes,
       
   266                    MSmlDmDDFObject::EOne,
       
   267                    MSmlDmDDFObject::EDynamic,
       
   268                    MSmlDmDDFObject::EChr,
       
   269                    KNSmlDMImpsAAuthLevelDescr );
       
   270 
       
   271     // AAuthName
       
   272     MSmlDmDDFObject& AAuthName = rtNodeAppAuth.AddChildObjectL( KNSmlDMImpsAAuthName );
       
   273     FillNodeInfoL( AAuthName,
       
   274                    allAccessTypes,
       
   275                    MSmlDmDDFObject::EZeroOrOne,
       
   276                    MSmlDmDDFObject::EDynamic,
       
   277                    MSmlDmDDFObject::EChr,
       
   278                    KNSmlDMImpsAAuthNameDescr );
       
   279 
       
   280     // AAuthSecret
       
   281     MSmlDmDDFObject& AAuthSecret = rtNodeAppAuth.AddChildObjectL( KNSmlDMImpsAAuthSecret );
       
   282     FillNodeInfoL( AAuthSecret,
       
   283                    accessTypesASecret,
       
   284                    MSmlDmDDFObject::EZeroOrOne,
       
   285                    MSmlDmDDFObject::EDynamic,
       
   286                    MSmlDmDDFObject::EChr,
       
   287                    KNSmlDMImpsAAuthSecretDescr );
       
   288 
       
   289     // Services
       
   290     MSmlDmDDFObject& service = rtNode.AddChildObjectL( KNSmlDMImpsServices );
       
   291     FillNodeInfoL( service, 
       
   292                    accessTypesNoDel, 
       
   293                    MSmlDmDDFObject::EZeroOrOne, 
       
   294                    MSmlDmDDFObject::EDynamic, 
       
   295                    MSmlDmDDFObject::EChr, 
       
   296                    KNSmlDMImpsServicesDescr );
       
   297 
       
   298     // Ext
       
   299     MSmlDmDDFObject& extNode = rtNode.AddChildObjectL( KNSmlDMImpsExtNode );
       
   300     FillNodeInfoL( extNode, 
       
   301                    allAccessTypes, 
       
   302                    MSmlDmDDFObject::EZeroOrOne,
       
   303                    MSmlDmDDFObject::EDynamic,
       
   304                    MSmlDmDDFObject::ENode, 
       
   305                    KNSmlDMImpsExtNodeDescr );
       
   306 
       
   307     // PEPCompliant
       
   308     MSmlDmDDFObject& pepCompliant = extNode.AddChildObjectL( KNSmlDMImpsPepCompliant );
       
   309     FillNodeInfoL( pepCompliant, 
       
   310                    allAccessTypes, 
       
   311                    MSmlDmDDFObject::EOne, 
       
   312                    MSmlDmDDFObject::EDynamic, 
       
   313                    MSmlDmDDFObject::EBool, 
       
   314                    KNSmlDMImpsPepCompliantDescr );
       
   315             
       
   316 	_DBG_FILE( "CNSmlDmImpsAdapter::DDFStructureL(): end" );
       
   317 	}
       
   318 
       
   319 // ----------------------------------------------------------------------------
       
   320 // CNSmlDmImpsAdapter::AddNodeObjectL()
       
   321 // The method adds new node.
       
   322 // - Check number of uri segments
       
   323 // - If number of segements = 2
       
   324 //  	 - Read all dynamic nodes under IMPS from the DMTree
       
   325 //  	 - Check that the new node name does not already exist
       
   326 //	   - If exists
       
   327 //	    --> return error status "AlreadyExists"
       
   328 //	   - If does not exist, create new SAP to the database 
       
   329 //              and use the node name as temporary SAP name
       
   330 //	   - Map the received index to the URI.
       
   331 // - If number of segments = 3 or 4
       
   332 //     - Check that there exists a SAP with given LUID value in db
       
   333 //	   - If does not exist
       
   334 //		  --> return error status "NotFound"
       
   335 //	   - If exists
       
   336 //	    --> if number of segments = 4
       
   337 //		    - check that there does not already exist the dynamic node 
       
   338 //                  ( only one dynamic allowed )
       
   339 //			  - if exists
       
   340 // 			   --> Return error status invalid object
       
   341 //	   - Set mapping for DB index and URI.
       
   342 // ----------------------------------------------------------------------------
       
   343 void CNSmlDmImpsAdapter::AddNodeObjectL( const TDesC8& aURI, 
       
   344         const TDesC8& aParentLUID, const TInt aStatusRef )
       
   345 	{
       
   346 	_DBG_FILE( "CNSmlDmImpsAdapter::AddNodeObjectL(): begin" );
       
   347 
       
   348     CIMPSSAPSettings* ownSap = CIMPSSAPSettings::NewL();
       
   349 	CleanupStack::PushL( ownSap );
       
   350     CIMPSSAPSettingsStore* ownStore = CIMPSSAPSettingsStore::NewL();
       
   351 	CleanupStack::PushL( ownStore );
       
   352     CIMPSSAPSettingsList* ownList = CIMPSSAPSettingsList::NewL();   
       
   353 	CleanupStack::PushL( ownList );
       
   354 
       
   355     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   356     TInt numOfSegs = NSmlDmURI::NumOfURISegs( aURI );
       
   357     TPtrC8 checkedNode = NSmlDmURI::LastURISeg( aURI );
       
   358     
       
   359     if ( ( numOfSegs == 2 ) && 
       
   360          ( aURI.Match( KNSmlDMImpsRootAndDyn ) != KErrNotFound ) )
       
   361         {   
       
   362         status = CSmlDmAdapter::EOk;
       
   363 
       
   364         // Read all dynamic nodes under IMPS from tree
       
   365         CSmlDmAdapter::TError stat;
       
   366         CBufBase *allNodes = CBufFlat::NewL( KNSmlDMReservingData );
       
   367     	CleanupStack::PushL( allNodes );
       
   368 	    iCallBack->FetchLinkL( KNSmlDMImpsNodeName, *allNodes, stat );
       
   369 
       
   370         // Check if the second node is found
       
   371         TInt startIndex = 0;        
       
   372         for( TInt i = 0; i < allNodes->Size(); i++ )
       
   373             {
       
   374             if( allNodes->Ptr(0)[i] == '/' || i == allNodes->Size()-1 )
       
   375                 {
       
   376                 TPtrC8 uriSeg8Ptr = allNodes->Ptr( startIndex ).Mid( 0, i-startIndex );    			                
       
   377                 if ( uriSeg8Ptr.Compare( checkedNode ) == 0 )        
       
   378                     {
       
   379                     status = EAlreadyExists;
       
   380                     break;
       
   381                     }
       
   382                 startIndex = i + 1;
       
   383                 }  // if ( allNodes->Ptr )            
       
   384             } // for
       
   385         CleanupStack::PopAndDestroy(); // allNodes
       
   386 
       
   387         if  ( status == CSmlDmAdapter::EOk )
       
   388             {
       
   389             // the item does not exist - create it to the db    
       
   390             RFs fs;
       
   391             User::LeaveIfError( fs.Connect() );
       
   392             CleanupClosePushL( fs );
       
   393             if ( SysUtil::FFSSpaceBelowCriticalLevelL( &fs, 
       
   394                                                        KNSmlDMSAPSettings ) )
       
   395 	            {
       
   396                 _DBG_FILE( "CNSmlDmImpsAdapter::AddNodeObjectL(): DISK FULL end" );
       
   397                 status = CSmlDmAdapter::EDiskFull; // Disk full
       
   398                 }
       
   399             else
       
   400                 {
       
   401                 ResetSapL( ownSap );
       
   402                 
       
   403                 TBufC8<5> tmpName( KNSmlDMImpsName ); 
       
   404                 status = UpdateValueL( tmpName, checkedNode, ownSap );
       
   405 				if ( status == CSmlDmAdapter::EOk  )
       
   406     				{ 		        			    
       
   407 					TUint32 uid32 = ownStore->StoreNewSAPL( ownSap, EIMPSIMAccessGroup );
       
   408 					TInt uid( uid32 );
       
   409 				    _DBG_FILE( "CNSmlDmImpsAdapter::AddNodeObjectL(): New SAP added" );
       
   410       		    	HBufC8 *luidDes = IntToDes8LC( uid );
       
   411 	            	iCallBack->SetMappingL( aURI, *luidDes );
       
   412        		    	CleanupStack::PopAndDestroy(); // luidDes
       
   413     				}
       
   414                 }  //disk size
       
   415             CleanupStack::PopAndDestroy(); // fs
       
   416             }
       
   417         }
       
   418 	// AppAuth nodes        
       
   419     else if ( ( ( numOfSegs == 3 ) && 
       
   420                 ( aURI.Match( KNSmlDMImpsWholeAppAuthUri ) != KErrNotFound ) )
       
   421            || ( ( numOfSegs == 4 ) && 
       
   422                 ( aURI.Match( KNSmlDMImpsWholeAppAuthDynUri ) != KErrNotFound ) ) )
       
   423         {
       
   424     	  if( aParentLUID.Length() > 0 )
       
   425 		    {
       
   426         // Check that Store is not empty
       
   427         // causes leaving if empty db is tried to read
       
   428         	TInt count = 0;
       
   429         	count = ownStore->SAPCountL( EIMPSAccessFilterAll );
       
   430         	DBG_ARGS8(_S8("IMPS::Count of SAPs in store = %d \n"), count );
       
   431             if ( count > 0 )
       
   432                 {
       
   433     	        TInt uid = DesToInt( aParentLUID );
       
   434     	        TUint32 uid32( uid );
       
   435                 ownStore->PopulateSAPSettingsListL( *ownList, 
       
   436                                                     EIMPSAccessFilterAll );
       
   437                 _DBG_FILE( "CNSmlDmImpsAdapter::AddNodeObjectL(): SAP settings list" );
       
   438                	TBool found = EFalse;
       
   439                 for ( TInt i = 0; i < count; i++ )
       
   440                     {
       
   441                     TUint32 id32 = ownList->UidForIndex( i );
       
   442                     if ( id32 == uid32 )
       
   443                         {
       
   444                         found = ETrue;
       
   445                         if ( numOfSegs == 4 )
       
   446                             {
       
   447                             // There can be only one dynamic node, 
       
   448                             // check that there is not one
       
   449                             TPtrC8 ptrToParentUri = NSmlDmURI::RemoveLastSeg( aURI );
       
   450 	                            // Read dynamic nodes under AppAuth from tree
       
   451                             CSmlDmAdapter::TError stat;
       
   452                             CBufBase *dynNodes = CBufFlat::NewL( KNSmlDMReservingData );
       
   453     	                    CleanupStack::PushL( dynNodes );
       
   454 	                        iCallBack->FetchLinkL( ptrToParentUri, *dynNodes, stat );
       
   455 	                        TInt len = dynNodes->Size();	                        
       
   456                             if ( len > 0 )                             
       
   457                                 {
       
   458                                 status = EInvalidObject;
       
   459                                 }
       
   460                             else
       
   461                                 {
       
   462                                 iCallBack->SetMappingL( aURI, aParentLUID );
       
   463                                 }
       
   464                             CleanupStack::PopAndDestroy(); // dynNodes
       
   465                             }
       
   466                         else
       
   467                             {
       
   468             	    	    iCallBack->SetMappingL( aURI, aParentLUID );
       
   469                             }
       
   470                         break;
       
   471                         }
       
   472                     } // for
       
   473 		                    
       
   474                 if ( !found )
       
   475                     {
       
   476    	                status = CSmlDmAdapter::ENotFound;
       
   477        	            }            
       
   478                 } // count
       
   479             }  // aParentLUID length
       
   480         else
       
   481         	{
       
   482 	        status = CSmlDmAdapter::ENotFound;
       
   483             }  
       
   484         } // aParentLUID length
       
   485         
       
   486 	// Ext node
       
   487    	else if ( ( numOfSegs == 3 ) && 
       
   488    	          ( aURI.Match( KNSmlDMImpsWholeExtUri ) != KErrNotFound ) )
       
   489 		{
       
   490        	if( aParentLUID.Length() > 0 )
       
   491 		    {
       
   492         // Check that Store is not empty
       
   493         // causes leaving if empty db is tried to read
       
   494         	TInt count = 0;
       
   495             count = ownStore->SAPCountL( EIMPSAccessFilterAll );
       
   496             DBG_ARGS8(_S8("IMPS::Count of SAPs in store = %d \n"), count );
       
   497             if ( count > 0 )
       
   498                 {
       
   499    	        	TInt uid = DesToInt( aParentLUID );
       
   500    	        	TUint32 uid32( uid );
       
   501                 ownStore->PopulateSAPSettingsListL( *ownList, EIMPSAccessFilterAll );
       
   502                 _DBG_FILE( "CNSmlDmImpsAdapter::AddNodeobjectL(): SAP settings list" );
       
   503                 TBool found = EFalse;
       
   504                 for ( TInt i = 0; i < count; i++ )
       
   505                     {
       
   506                     TUint32 id32 = ownList->UidForIndex( i );
       
   507                     if ( id32 == uid32 )
       
   508                         {
       
   509                         found = ETrue;
       
   510           	    	    iCallBack->SetMappingL( aURI, aParentLUID );
       
   511                         break;
       
   512                         }
       
   513                     } // for
       
   514                 if ( !found )
       
   515                     {
       
   516                     status = CSmlDmAdapter::ENotFound;
       
   517                     }            
       
   518 	            } // count            	
       
   519             }  // aParentLUID length
       
   520         else
       
   521         	{
       
   522 	        status = CSmlDmAdapter::ENotFound;
       
   523             }  
       
   524         } // aParentLUID length
       
   525         
       
   526     else 
       
   527         {
       
   528         status = CSmlDmAdapter::EInvalidObject;
       
   529         }
       
   530 
       
   531     CleanupStack::PopAndDestroy( 3 ); // ownList, ownStore, ownSap
       
   532 
       
   533     iCallBack->SetStatusL( aStatusRef, status );
       
   534     _DBG_FILE( "CNSmlDmImpsAdapter::AddNodeObjectL(): end" );
       
   535 
       
   536     return;
       
   537 	}
       
   538 
       
   539 
       
   540 // ----------------------------------------------------------------------------
       
   541 //  CNSmlDmImpsAdapter::UpdateLeafObjectL()
       
   542 //  The method updates the leaf value.
       
   543 //  - Check that LUID length > 0
       
   544 //	- Check that there exists SAP with uid which is same as received LUID value.
       
   545 //  - If exists
       
   546 //	  --> update received parameter value to db
       
   547 //  - else
       
   548 //	  --> return error status
       
   549 // ----------------------------------------------------------------------------
       
   550 void CNSmlDmImpsAdapter::UpdateLeafObjectL( const TDesC8& aURI, 
       
   551                                             const TDesC8& aLUID, 
       
   552                                             const TDesC8& aObject, 
       
   553 											const TDesC8& /*aType*/, 
       
   554 											TInt aStatusRef )	
       
   555     {
       
   556     _DBG_FILE( "CNSmlDmImpsAdapter::UpdateLeafObjectL(): begin" );
       
   557 
       
   558 // Used only in Test purpose
       
   559 //   TBuf8<50> tmpUriBuf = aURI;
       
   560 //   TBuf8<50> tmpLuidBuf = aLUID;   
       
   561 //   DBG_ARGS8(_S8("IMPS Luid / Uri : Luid = %S  Uri = %S \n"), &tmpLuidBuf, &tmpUriBuf );     
       
   562 
       
   563     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   564 
       
   565     CIMPSSAPSettings* ownSap = CIMPSSAPSettings::NewL();
       
   566     CleanupStack::PushL( ownSap );
       
   567     CIMPSSAPSettingsStore* ownStore = CIMPSSAPSettingsStore::NewL();
       
   568     CleanupStack::PushL( ownStore );
       
   569 
       
   570     TPtrC8 lastSeg = NSmlDmURI::LastURISeg( aURI );
       
   571 
       
   572     if( aLUID.Length() > 0 )
       
   573         {	    
       
   574         // Check that Store is not empty and find the correct SAP
       
   575         TInt sapFound = GetCorrectSapL( aLUID, 
       
   576                                         ownSap, 
       
   577                                         ownStore );                    	  	
       
   578         if ( sapFound == KErrNone )                    	  
       
   579             {        
       
   580             if ( lastSeg.Compare( KNSmlDMImpsPepCompliant ) == 0 )
       
   581                 {
       
   582                 TInt stat = UpdatePEPValueL( aURI, 
       
   583                                              aObject, 
       
   584                                              aLUID, 
       
   585                                              ownSap, 
       
   586                                              ownStore );
       
   587                 if ( stat != KErrNone )
       
   588                     { 
       
   589                     status = CSmlDmAdapter::EError;
       
   590                     }
       
   591                 }
       
   592             else if ( lastSeg.Compare( KNSmlDMImpsAppId ) == 0 )
       
   593                 {
       
   594                 // Only value "wA" is accepted for AppID parameter
       
   595                 if ( aObject.Compare( KNSmlDMImpsDefaultAppID ) != 0 )
       
   596                     {
       
   597                     status = CSmlDmAdapter::EInvalidObject;
       
   598                     }	  		
       
   599                 }			  				  	
       
   600             else
       
   601                 {
       
   602                 TInt uid = DesToInt( aLUID );
       
   603                 TUint32 Uid32( uid );
       
   604                 status = UpdateValueL( lastSeg, aObject, ownSap );        
       
   605                 if ( status == KErrNone )
       
   606                     {    
       
   607                     ownStore->UpdateOldSAPL( ownSap, Uid32 );					
       
   608                     _DBG_FILE( "CNSmlDmImpsAdapter::UpdateLeafObjectL(): SAP updated" );
       
   609                     }		  	
       
   610                 }
       
   611             }	// sapFound
       
   612     		  			  	
       
   613         else if ( sapFound == KErrNotFound )                    	 
       
   614             {      		
       
   615             status = CSmlDmAdapter::ENotFound;
       
   616             }  
       
   617         else
       
   618             {
       
   619             status = CSmlDmAdapter::EError;
       
   620             }
       
   621         } // aLUID length
       
   622     else
       
   623         {
       
   624         status = CSmlDmAdapter::ENotFound;
       
   625         }  
       
   626 
       
   627     iCallBack->SetStatusL( aStatusRef, status );
       
   628 
       
   629     CleanupStack::PopAndDestroy( 2 ); // ownStore, ownSap
       
   630 
       
   631     _DBG_FILE( "CNSmlDmImpsAdapter::UpdateLeafObjectL( ): end" );
       
   632     	
       
   633     return;
       
   634     }
       
   635 
       
   636 // ----------------------------------------------------------------------------
       
   637 //  CNSmlDmImpsAdapter::UpdateLeafObjectL()
       
   638 //  Method not used. Used if streaming in use.
       
   639 // ----------------------------------------------------------------------------
       
   640 void CNSmlDmImpsAdapter::UpdateLeafObjectL( const TDesC8& /*aURI*/, 
       
   641                                             const TDesC8& /*aLUID*/, 
       
   642                                             RWriteStream*& /*aStream*/, 
       
   643                                             const TDesC8& /*aType*/, 
       
   644                                             TInt aStatusRef )
       
   645     {
       
   646     _DBG_FILE( "CNSmlDmImpsAdapter::UpdateLeafObjectL(): begin" );
       
   647     iCallBack->SetStatusL(aStatusRef, CSmlDmAdapter::EError);
       
   648     _DBG_FILE( "CNSmlDmImpsAdapter::UpdateLeafObjectL( ): end" );
       
   649     }
       
   650 
       
   651 // ----------------------------------------------------------------------------
       
   652 // void CNSmlDmImpsAdapter::FetchLeafObjectSizeL()
       
   653 // Fetches data object and returns its size.
       
   654 // - Take last URI segment and request the value for requested parameter 
       
   655 //      by using method FetchObjectL.
       
   656 // - Take the size of received parameter value and change it to descriptor
       
   657 // - Return the size and status
       
   658 // ----------------------------------------------------------------------------
       
   659 void CNSmlDmImpsAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, 
       
   660                                                const TDesC8& aLUID, 
       
   661                                                const TDesC8& aType, 
       
   662                                                const TInt aResultsRef, 
       
   663                                                const TInt aStatusRef )
       
   664     {
       
   665     _DBG_FILE("CNSmlDmImpsAdapter::FetchLeafObjectSizeL(): begin");
       
   666 
       
   667     CBufBase *currentURISegmentList = CBufFlat::NewL( KNSmlDMReservingMaxData );
       
   668     CleanupStack::PushL( currentURISegmentList );
       
   669     TPtrC8 fetchedLeaf = NSmlDmURI::LastURISeg( aURI );    
       
   670 
       
   671     CSmlDmAdapter::TError status = FetchObjectL( fetchedLeaf, 
       
   672                                                  aLUID, 
       
   673                                                  *currentURISegmentList );
       
   674 
       
   675     if ( status == CSmlDmAdapter::EOk )
       
   676         {
       
   677         TInt objSizeInBytes = currentURISegmentList->Size();
       
   678         TBuf8<16> stringObjSizeInBytes;
       
   679         stringObjSizeInBytes.Num( objSizeInBytes );
       
   680         currentURISegmentList->Reset();
       
   681         currentURISegmentList->InsertL( 0, stringObjSizeInBytes );
       
   682 
       
   683         iCallBack->SetResultsL( aResultsRef, *currentURISegmentList, aType );
       
   684         }
       
   685 
       
   686     iCallBack->SetStatusL( aStatusRef, status );
       
   687     CleanupStack::PopAndDestroy();  //currentURISegmentList
       
   688 	
       
   689     _DBG_FILE("CNSmlDmImpsAdapter::FetchLeafObjectSizeL(): end");
       
   690     }
       
   691     
       
   692 // ----------------------------------------------------------------------------
       
   693 // CNSmlDmImpsAdapter::DeleteObjectL()
       
   694 // The method deletes the requested parameter values.
       
   695 // - Check number of segments
       
   696 // - If number of segments > 2
       
   697 // 	 --> check that the SAP which the deletion involves exists in DB 
       
   698 //          and get SAP to ownSap
       
   699 //   - If number of segments = 2
       
   700 //	   --> delete whole SAP from the DB
       
   701 //	 - If number of segments > 2 and <= 5
       
   702 //	   --> check the requested parameter and delete the value from it in DB
       
   703 // - If number of segments < 1 or > 5 or given SAP is not found from DB
       
   704 //	 --> return error status
       
   705 // ----------------------------------------------------------------------------
       
   706 void CNSmlDmImpsAdapter::DeleteObjectL( const TDesC8& aURI, 
       
   707                                         const TDesC8& aLUID, 
       
   708                                         TInt aStatusRef )
       
   709     {
       
   710     _DBG_FILE( "CNSmlDmImpsAdapter::DeleteLeafObjectL( ): begin" );
       
   711 
       
   712     CIMPSSAPSettings* ownSap = CIMPSSAPSettings::NewL();
       
   713     CleanupStack::PushL( ownSap );
       
   714     CIMPSSAPSettingsStore* ownStore = CIMPSSAPSettingsStore::NewL();
       
   715     CleanupStack::PushL( ownStore );
       
   716 
       
   717     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
   718 
       
   719     // Check the number of uri segments to find out is a node or a leaf deleted 
       
   720     TInt numOfSegs = NSmlDmURI::NumOfURISegs( aURI );
       
   721 
       
   722     if ( numOfSegs < 2 || numOfSegs > 5 )
       
   723         {
       
   724         // Sap does not exist, return error status
       
   725         status = CSmlDmAdapter::EInvalidObject;
       
   726         iCallBack->SetStatusL( aStatusRef, status );
       
   727         return;
       
   728         }
       
   729 
       
   730     if( aLUID.Length() > 0 )
       
   731         {
       
   732         // Check that Store is not empty, 
       
   733         // causes leaving if empty db is tried to read
       
   734         TInt sapFound = KErrNotFound;
       
   735         sapFound = GetCorrectSapL( aLUID, 
       
   736                                    ownSap, 
       
   737                                    ownStore ); 
       
   738         if ( sapFound == KErrNone )
       
   739             {   		
       
   740             TInt uid = DesToInt( aLUID );
       
   741             TUint32 Uid32( uid );
       
   742             if ( numOfSegs == 2 )
       
   743                 {
       
   744                 // delete SAP
       
   745                 ownStore->DeleteSAPL( Uid32 );
       
   746                 _DBG_FILE( "CNSmlDmImpsAdapter::DeleteObjectL(): SAP deleted" );
       
   747                 }  // if numOfSegs
       
   748             else 
       
   749                 {            
       
   750                 TPtrC8 deletedLeaf = NSmlDmURI::LastURISeg( aURI );    
       
   751                 if ( ( deletedLeaf.Compare( KNSmlDMImpsPepCompliant ) == 0 ) ||              
       
   752                    ( deletedLeaf.Compare( KNSmlDMImpsExtNode ) == 0 ) )
       
   753                     {
       
   754                     TBuf8<5> tmpPep( KNSmlDMImpsDefaultIM );  //False		    	    
       
   755                     TInt stat = EOk;
       
   756                     if ( deletedLeaf.Compare( KNSmlDMImpsExtNode ) == 0 )
       
   757                         {
       
   758                         HBufC8 *tmpUri = HBufC8::NewLC( aURI.Length() + 14 );
       
   759                         TPtr8 tmpUriPtr = tmpUri->Des();
       
   760 
       
   761                         // URI: IMPS/<x>/PEPCompliant
       
   762                         tmpUriPtr.Format( aURI );
       
   763                         tmpUriPtr.Append( KNSmlDMImpsSeparator8 );
       
   764                         tmpUriPtr.Append( KNSmlDMImpsPepCompliant );
       
   765                         stat = UpdatePEPValueL( tmpUriPtr, 
       
   766                                                 tmpPep, 
       
   767                                                 aLUID, 
       
   768                                                 ownSap, 
       
   769                                                 ownStore );
       
   770                         CleanupStack::PopAndDestroy();  // tmpUri
       
   771                         }
       
   772                     else
       
   773                         {
       
   774                         stat = UpdatePEPValueL( aURI, 
       
   775                                                 tmpPep, 
       
   776                                                 aLUID, 
       
   777                                                 ownSap, 
       
   778                                                 ownStore );                    
       
   779                         }
       
   780                     if ( stat != KErrNone )
       
   781                         { 
       
   782                         status = CSmlDmAdapter::EError;
       
   783                         }
       
   784                     }  // stat
       
   785                 else
       
   786                     {
       
   787                     status  = DeleteValueL( aURI, ownSap );
       
   788                     if ( status == EOk )
       
   789                         {                        
       
   790                         // update the SAP to db 
       
   791                         ownStore->UpdateOldSAPL( ownSap, Uid32 );
       
   792                         _DBG_FILE( "CNSmlDmImpsAdapter::DeleteObjectL(): SAP updated" );
       
   793                         }			  		                	
       
   794                     }  // status 
       
   795                 } // numOfSegs
       
   796             }  // sapFound
       
   797         else if ( sapFound == KErrNotFound )                    	 
       
   798             {      		
       
   799             status = CSmlDmAdapter::ENotFound;
       
   800             }  
       
   801         else
       
   802             {
       
   803             status = CSmlDmAdapter::EError;
       
   804             }
       
   805         }  // LUID length
       
   806     else
       
   807         {
       
   808         status = CSmlDmAdapter::ENotFound;
       
   809         }
       
   810     
       
   811     iCallBack->SetStatusL( aStatusRef, status );
       
   812 
       
   813     CleanupStack::PopAndDestroy( 2 );  // ownSap, ownStore
       
   814 
       
   815     _DBG_FILE( "CNSmlDmImpsAdapter::DeleteLeafObjectL( ): end" );
       
   816 
       
   817     return;
       
   818     }
       
   819     
       
   820 // ----------------------------------------------------------------------------
       
   821 //  CNSmlDmImpsAdapter::FetchLeafObjectL()
       
   822 // The method returns the requested parameter value from DB
       
   823 // - Take last URI segment and request the value for requested parameter 
       
   824 //          by using method FetchObjectL.
       
   825 // - Return the parameter value and status
       
   826 // ----------------------------------------------------------------------------
       
   827 void CNSmlDmImpsAdapter::FetchLeafObjectL( const TDesC8& aURI, 
       
   828                                            const TDesC8& aLUID, 
       
   829                                            const TDesC8& aType, 
       
   830                                            TInt aResultsRef, 
       
   831                                            TInt aStatusRef )
       
   832     {
       
   833     _DBG_FILE( "CNSmlDmImpsAdapter::FetchLeafObjectL(): begin" );    
       
   834 
       
   835     CBufBase *currentURISegmentList = CBufFlat::NewL( KNSmlDMReservingMaxData );
       
   836     CleanupStack::PushL( currentURISegmentList );
       
   837     TPtrC8 fetchedLeaf = NSmlDmURI::LastURISeg( aURI );    
       
   838     CSmlDmAdapter::TError status = FetchObjectL( fetchedLeaf, 
       
   839                                                  aLUID, 
       
   840                                                  *currentURISegmentList );
       
   841 
       
   842     if ( status == CSmlDmAdapter::EOk )
       
   843         {
       
   844         iCallBack->SetResultsL( aResultsRef, *currentURISegmentList, aType );
       
   845         }
       
   846 
       
   847     iCallBack->SetStatusL( aStatusRef, status );
       
   848     CleanupStack::PopAndDestroy();  //currentURISegmentList
       
   849 
       
   850     _DBG_FILE( "CNSmlDmImpsAdapter::FetchLeafObjectL(): end" );
       
   851 
       
   852     return;
       
   853     }
       
   854 
       
   855 
       
   856 // ----------------------------------------------------------------------------
       
   857 //  void CNSmlDmImpsAdapter::ChildURIListL()
       
   858 //  The method returns the child nodes or leafs under requested node. 
       
   859 //  - Check number of URI segments. 
       
   860 //  - If number of segments = 1
       
   861 //    --> check if the dynamic node name is found by setting the DB uid
       
   862 //              against the LUID value in aPreviousURISegmentList 
       
   863 // 	      - If the name is found, it is taken to the result list, 
       
   864 //		  - else the index number of SAP is converted to the name 
       
   865 //              and returned as node name
       
   866 //  - If number of segments > 1 and < 5
       
   867 //	  --> check that given LUID is found as index in DB 
       
   868 //              and get the SAP data to ownSap
       
   869 //      - if number of segments = 2 or 4
       
   870 //		  --> return parameter under dynamic node
       
   871 // 	    - if number of segments = 3
       
   872 //		  --> return the name of dynamic node under AppAuth node.
       
   873 //  - Return the results and status
       
   874 //  - In error case return error status
       
   875 // ----------------------------------------------------------------------------
       
   876 void CNSmlDmImpsAdapter::ChildURIListL( const TDesC8& aURI, 
       
   877                                         const TDesC8& aLUID, 
       
   878                                         const CArrayFix<TSmlDmMappingInfo>& aPreviousURISegmentList, 
       
   879                                         TInt aResultsRef, 
       
   880                                         TInt aStatusRef )
       
   881     {
       
   882     _DBG_FILE( "CNSmlDmImpsAdapter::ChildURIListL(): begin" );
       
   883         
       
   884 // Used only in Test purpose
       
   885 //   TBuf8<50> tmpUriBuf = aURI;
       
   886 //   TBuf8<50> tmpLuidBuf = aLUID;   
       
   887 //   DBG_ARGS8(_S8("IMPS Luid / Uri : Luid = %S  Uri = %S \n"), &tmpLuidBuf, &tmpUriBuf );     
       
   888         
       
   889     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;    
       
   890                         
       
   891     CIMPSSAPSettings* ownSap = CIMPSSAPSettings::NewL();
       
   892     CleanupStack::PushL( ownSap );
       
   893     CIMPSSAPSettingsStore* ownStore = CIMPSSAPSettingsStore::NewL();
       
   894     CleanupStack::PushL( ownStore );
       
   895     CIMPSSAPSettingsList* ownList = CIMPSSAPSettingsList::NewL();   
       
   896     CleanupStack::PushL( ownList );
       
   897 
       
   898     TInt numOfSegs = NSmlDmURI::NumOfURISegs( aURI );
       
   899 
       
   900     CBufBase *currentURISegmentList = CBufFlat::NewL( KNSmlDMReservingMaxData );
       
   901     CleanupStack::PushL( currentURISegmentList );
       
   902 
       
   903     if ( numOfSegs == 1 )
       
   904         {
       
   905         if ( aURI.Compare( KNSmlDMImpsNodeName ) == 0 )
       
   906             {   
       
   907             ownStore->PopulateSAPSettingsListL( *ownList, EIMPSAccessFilterAll );
       
   908             _DBG_FILE( "CNSmlDmImpsAdapter::ChildURIListL(): SAP settings list" );
       
   909             TInt32 id32; 
       
   910             TInt count = 0;
       
   911             count = ownStore->SAPCountL( EIMPSAccessFilterAll );			
       
   912             DBG_ARGS8(_S8("IMPS::Count of SAPs in store = %d "), count );
       
   913             TInt prevUriSegListCount = aPreviousURISegmentList.Count();
       
   914             DBG_ARGS8(_S8("IMPS::Count of luids in prevUriSegList = %d "), 
       
   915                            prevUriSegListCount );
       
   916 			
       
   917             for ( TInt i = 0; i < count; i++ )
       
   918                 {
       
   919                 id32 = ownList->UidForIndex( i );
       
   920                 TInt id( id32 );
       
   921                 DBG_ARGS8(_S8("IMPS::Sap id = %d"), id );
       
   922 		
       
   923                 HBufC8* name=0;
       
   924                 TBool found = EFalse;
       
   925                 // Go through the previousUriSegmentList
       
   926 			 
       
   927                 for( TInt prevListIx = 0; 
       
   928                      prevListIx < aPreviousURISegmentList.Count(); 
       
   929                      prevListIx++ )
       
   930                     {
       
   931                      // Check if the Sap id is found from segment list
       
   932                     if( id == DesToInt( aPreviousURISegmentList.At( prevListIx ).iURISegLUID ) )
       
   933                         {
       
   934                         found = ETrue;
       
   935                         // If id is found, take the urisegment from segment list
       
   936                         name = aPreviousURISegmentList.At( prevListIx ).iURISeg.AllocLC();
       
   937                         DBG_ARGS8(_S8("InList: Id = %d Seg %S"), id, 
       
   938                                   &aPreviousURISegmentList.At( prevListIx ).iURISeg);                                            
       
   939                         break;
       
   940                         }
       
   941                     } // for prevListIx
       
   942                 if( !found )
       
   943                     {
       
   944                     // id not found from previousUriSegmentList
       
   945                     // change the id to segment name
       
   946 
       
   947                     name = HBufC8::NewLC( 20 ); 
       
   948                     TPtr8 namePtr = name->Des();
       
   949                     namePtr = KNSMLDMImpsDynNodeName;
       
   950                     namePtr.AppendNum( i+1 );
       
   951 
       
   952                     HBufC8 *uri = HBufC8::NewLC( aURI.Length() + name->Length() + 1 );
       
   953                     TPtr8 uriPtr = uri->Des();
       
   954                     // Format the whole URI
       
   955                     uriPtr.Format( aURI );
       
   956                     uriPtr.Append( KNSmlDMImpsSeparator );
       
   957                     uriPtr.Append( name->Des() );
       
   958                     HBufC8 *luid = IntToDes8LC( id );
       
   959                     // Map the received uri to id
       
   960                     iCallBack->SetMappingL( uriPtr, *luid );
       
   961     	    		
       
   962 // Used only in Test purpose
       
   963 //    	    		TBuf8<50> uriBuf = uriPtr;
       
   964 //                    DBG_ARGS8(_S8("NotInList, mapping done: Luid = %d  Uri = %S "), 
       
   965 //                                   id, &uriBuf );
       
   966       	    		   		
       
   967                     CleanupStack::PopAndDestroy( 2 ); //uri,luid
       
   968                     }                    
       
   969                 TPtr8 namePtr = name->Des();
       
   970                 currentURISegmentList->InsertL( currentURISegmentList->Size(), 
       
   971                                                 namePtr );
       
   972                 if( i + 1 < count )
       
   973                     {
       
   974                     currentURISegmentList->InsertL( currentURISegmentList->Size(), 
       
   975                                                     KNSmlDMImpsSeparator8 );
       
   976                     }
       
   977                 CleanupStack::PopAndDestroy( ); // name              
       
   978                 } // for i < count
       
   979               
       
   980             iCallBack->SetResultsL( aResultsRef, 
       
   981                                     *currentURISegmentList, 
       
   982                                     KNullDesC8 );	            			                
       
   983             }  // aUri
       
   984         else 
       
   985             {
       
   986             status = CSmlDmAdapter::EInvalidObject;
       
   987             }  // aUri
       
   988         } 
       
   989     else if ( ( numOfSegs > 1 ) && ( numOfSegs < 5 ) )
       
   990         {
       
   991         if( aLUID.Length() > 0 )
       
   992             {                   
       
   993             // Check that Store is not empty
       
   994             // causes leaving if empty db is tried to read
       
   995             TInt sapFound = KErrNotFound;
       
   996             sapFound = GetCorrectSapL( aLUID, ownSap, ownStore );
       
   997             if ( sapFound == KErrNone)
       
   998                 {
       
   999                 if ( ( numOfSegs == 2 ) && 
       
  1000                      ( aURI.Match( KNSmlDMImpsRootAndDyn ) != KErrNotFound ) )
       
  1001                     {
       
  1002                     // List leafs
       
  1003                     currentURISegmentList->InsertL( currentURISegmentList->Size(), 
       
  1004                                                     KNSmlDMImpsRtNode() );
       
  1005                                                                         
       
  1006                     iCallBack->SetResultsL( aResultsRef, 
       
  1007                                             *currentURISegmentList, 
       
  1008                                             KNullDesC8 );
       
  1009                     }  // numOfSegs
       
  1010                 else if ( ( numOfSegs == 3 ) && 
       
  1011                           ( aURI.Match( KNSmlDMImpsWholeExtUri ) != KErrNotFound ) )
       
  1012                     {
       
  1013                     currentURISegmentList->InsertL( currentURISegmentList->Size(), 
       
  1014                                                     KNSmlDMImpsPepCompliant() );            
       
  1015                     iCallBack->SetResultsL( aResultsRef, 
       
  1016                                             *currentURISegmentList, 
       
  1017                                             KNullDesC8 );
       
  1018                     }
       
  1019                 else if ( ( numOfSegs == 3 ) && 
       
  1020                           ( aURI.Match( KNSmlDMImpsWholeAppAuthUri ) != KErrNotFound ) )
       
  1021                     {
       
  1022                     HBufC8* name=0;
       
  1023                     TInt count = aPreviousURISegmentList.Count();
       
  1024                     if ( count > 0 ) 
       
  1025                         {
       
  1026                         for( TInt prevListIx = 0; prevListIx < count; prevListIx++ )
       
  1027                             {
       
  1028                             name = aPreviousURISegmentList.At( prevListIx ).iURISeg.AllocLC();
       
  1029                             TPtr8 namePtr = name->Des();
       
  1030                             currentURISegmentList->InsertL( currentURISegmentList->Size(), 
       
  1031                                                             namePtr );                 
       
  1032                             if( prevListIx + 1 < count )
       
  1033                                 {
       
  1034                                 currentURISegmentList->InsertL( currentURISegmentList->Size(), 
       
  1035                                                                 KNSmlDMImpsSeparator8 );
       
  1036                                 }
       
  1037                             CleanupStack::PopAndDestroy();  // name
       
  1038                             } // for
       
  1039                         }  // if count > 0
       
  1040                     else
       
  1041                         {
       
  1042                         if ( ( ownSap->SAPUserId().Compare(KNSmlDMImpsNotDefined ) == 0 ) &&
       
  1043                              ( ownSap->SAPUserPassword().Compare(KNSmlDMImpsNotDefined ) == 0 ) )
       
  1044                             {                    
       
  1045                             }
       
  1046                         else
       
  1047                             {
       
  1048                             HBufC8 *uri = HBufC8::NewLC( aURI.Length() + 9 );
       
  1049                             TPtr8 uriPtr = uri->Des();
       
  1050                             uriPtr.Format( aURI );
       
  1051                             uriPtr.Append( KNSmlDMImpsSeparator );
       
  1052                             uriPtr.Append( KNSmlDMRtNode );
       
  1053                             iCallBack->SetMappingL( uriPtr, aLUID );
       
  1054                             currentURISegmentList->InsertL( currentURISegmentList->Size(), 
       
  1055                                                             KNSmlDMRtNode8() );
       
  1056                             CleanupStack::PopAndDestroy(); //uri
       
  1057                             }
       
  1058                         }
       
  1059                     iCallBack->SetResultsL( aResultsRef, 
       
  1060                                             *currentURISegmentList, 
       
  1061                                             KNullDesC8 );                              
       
  1062                     }
       
  1063                 else if ( ( numOfSegs == 4 ) && 
       
  1064                           ( aURI.Match( KNSmlDMImpsWholeAppAuthDynUri ) != KErrNotFound ) )
       
  1065                     {
       
  1066                     currentURISegmentList->InsertL( currentURISegmentList->Size(), 
       
  1067                                                     KNSmlDMAppAuthRtNode() );            
       
  1068                     iCallBack->SetResultsL( aResultsRef, 
       
  1069                                             *currentURISegmentList, 
       
  1070                                             KNullDesC8 );
       
  1071                     }                                                              
       
  1072                 else
       
  1073                     {
       
  1074                     status = CSmlDmAdapter::EInvalidObject;
       
  1075                     }
       
  1076                 }  // sapFound
       
  1077             else if ( sapFound == KErrNotFound )                    	 
       
  1078                 {      		
       
  1079                 status = CSmlDmAdapter::ENotFound;
       
  1080                 }  
       
  1081             else
       
  1082                 {
       
  1083                 status = CSmlDmAdapter::EError;
       
  1084                 }
       
  1085             }  // luid len
       
  1086         else  
       
  1087             {
       
  1088             status = CSmlDmAdapter::ENotFound;
       
  1089             }
       
  1090         } // numOfSegs
       
  1091     else 
       
  1092         {
       
  1093         status = CSmlDmAdapter::EInvalidObject;
       
  1094         }
       
  1095 
       
  1096 // Used only in Test purpose
       
  1097     DBG_ARGS8(_S8("Status = %d \n"), status );       
       
  1098         
       
  1099     iCallBack->SetStatusL( aStatusRef, status );
       
  1100     
       
  1101     CleanupStack::PopAndDestroy( 4 ); // currentUriSegmentList, ownSap, ownStore, ownList
       
  1102 
       
  1103     _DBG_FILE( "CNSmlDmImpsAdapter::ChildURIListL(): end" );
       
  1104     return;
       
  1105     }
       
  1106 
       
  1107 // ----------------------------------------------------------------------------
       
  1108 // CNSmlDmImpsAdapter::CompleteOutstandingCmdsL()
       
  1109 // ----------------------------------------------------------------------------
       
  1110 void CNSmlDmImpsAdapter::CompleteOutstandingCmdsL()
       
  1111     {
       
  1112     _DBG_FILE( "CNSmlDmImpsAdapter::EndMessageL(): begin" );
       
  1113     _DBG_FILE( "CNSmlDmImpsAdapter::EndMessageL(): end" );
       
  1114     }
       
  1115 
       
  1116 //==============================================================================
       
  1117 // CNSmlDmImpsAdapter::ExecuteCommandL()
       
  1118 //==============================================================================
       
  1119 void CNSmlDmImpsAdapter::ExecuteCommandL( const TDesC8& /*aURI*/, 
       
  1120                                           const TDesC8& /*aLUID*/, 
       
  1121                                           const TDesC8& /*aArgument*/, 
       
  1122                                           const TDesC8& /*aType*/, 
       
  1123                                           const TInt aStatusRef )
       
  1124     {
       
  1125     //Not supported
       
  1126     _DBG_FILE( "CNSmlDmImpsAdapter::ExecuteCommandL(): begin" );
       
  1127     iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
  1128     _DBG_FILE( "CNSmlDmImpsAdapter::ExecuteCommandL(): end" );
       
  1129     }
       
  1130 
       
  1131 //==============================================================================
       
  1132 // CNSmlDmImpsAdapter::ExecuteCommandL()
       
  1133 //==============================================================================
       
  1134 void CNSmlDmImpsAdapter::ExecuteCommandL( const TDesC8& /*aURI*/, 
       
  1135                                           const TDesC8& /*aLUID*/, 
       
  1136                                           RWriteStream*& /*aStream*/, 
       
  1137                                           const TDesC8& /*aType*/, 
       
  1138                                           const TInt aStatusRef )
       
  1139     {
       
  1140     //Not supported
       
  1141     _DBG_FILE( "CNSmlDmImpsAdapter::ExecuteCommandL(): begin" );
       
  1142     iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
  1143     _DBG_FILE( "CNSmlDmImpsAdapter::ExecuteCommandL(): end" );
       
  1144     }
       
  1145 
       
  1146 //==============================================================================
       
  1147 // CNSmlDmImpsAdapter::CopyCommandL()
       
  1148 //==============================================================================
       
  1149 void CNSmlDmImpsAdapter::CopyCommandL( const TDesC8& /*aTargetURI*/, 
       
  1150                                        const TDesC8& /*aTargetLUID*/, 
       
  1151                                        const TDesC8& /*aSourceURI*/, 
       
  1152                                        const TDesC8& /*aSourceLUID*/, 
       
  1153                                        const TDesC8& /*aType*/, 
       
  1154                                        TInt aStatusRef )
       
  1155     {    
       
  1156     //Not supported
       
  1157     _DBG_FILE( "CNSmlDmImpsAdapter::CopyCommandL(): begin" );
       
  1158     iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
  1159     _DBG_FILE( "CNSmlDmImpsAdapter::CopyCommandL(): end" );
       
  1160     }
       
  1161 
       
  1162 //==============================================================================
       
  1163 // CNSmlDmImpsAdapter::StartAtomicL()
       
  1164 //==============================================================================
       
  1165 void CNSmlDmImpsAdapter::StartAtomicL()
       
  1166     {
       
  1167     //Not supported
       
  1168     _DBG_FILE( "CNSmlDmImpsAdapter::StartAtomicL(): begin" );
       
  1169     _DBG_FILE( "CNSmlDmImpsAdapter::StartAtomicL(): end" );
       
  1170     }
       
  1171 
       
  1172 //==============================================================================
       
  1173 // CNSmlDmImpsAdapter::CommitAtomicL()
       
  1174 //==============================================================================
       
  1175 void CNSmlDmImpsAdapter::CommitAtomicL()
       
  1176     {
       
  1177     //Not supported
       
  1178     _DBG_FILE( "CNSmlDmImpsAdapter::CommitAtomicL(): begin" );
       
  1179     _DBG_FILE( "CNSmlDmImpsAdapter::CommitAtomicL(): end" );
       
  1180     }
       
  1181     
       
  1182 //==============================================================================
       
  1183 // CNSmlDmImpsAdapter::RollbackAtomicL()
       
  1184 //==============================================================================
       
  1185 void CNSmlDmImpsAdapter::RollbackAtomicL()
       
  1186     {
       
  1187     //Not supported
       
  1188     _DBG_FILE( "CNSmlDmImpsAdapter::RollbackAtomicL(): begin" );
       
  1189     _DBG_FILE( "CNSmlDmImpsAdapter::RollbackAtomicL(): end" );
       
  1190     }
       
  1191 
       
  1192 //==============================================================================
       
  1193 // CNSmlDmImpsAdapter::StreamingSupport()
       
  1194 //==============================================================================
       
  1195 TBool CNSmlDmImpsAdapter::StreamingSupport( TInt& /*aItemSize*/ )
       
  1196     {
       
  1197     _DBG_FILE( "CNSmlDmImpsAdapter::StreamingSupport(): begin" );
       
  1198     _DBG_FILE( "CNSmlDmImpsAdapter::StreamingSupport(): end" );
       
  1199     return EFalse;
       
  1200     }
       
  1201 
       
  1202 //==============================================================================
       
  1203 // CNSmlDmImpsAdapter::StreamCommittedL()
       
  1204 //==============================================================================
       
  1205 void CNSmlDmImpsAdapter::StreamCommittedL()
       
  1206     {
       
  1207     //Not supported
       
  1208     _DBG_FILE( "CNSmlDmImpsAdapter::StreamCommittedL(): begin" );
       
  1209     _DBG_FILE( "CNSmlDmImpsAdapter::StreamCommittedL(): end" );
       
  1210     }
       
  1211 
       
  1212 
       
  1213 // ----------------------------------------------------------------------------
       
  1214 // Converts 16 bit descriptor to integer value.
       
  1215 // ----------------------------------------------------------------------------
       
  1216 TInt CNSmlDmImpsAdapter::DesToInt( const TDesC& aLuid )
       
  1217     {
       
  1218     TLex16 lex( aLuid );
       
  1219     TInt value = 0;
       
  1220     lex.Val( value );
       
  1221     return value;
       
  1222     }
       
  1223 
       
  1224 // ----------------------------------------------------------------------------
       
  1225 // Converts 8 bit descriptor to integer value.
       
  1226 // ----------------------------------------------------------------------------
       
  1227 TInt CNSmlDmImpsAdapter::DesToInt( const TDesC8& aLuid )
       
  1228     {
       
  1229     TLex8 lex( aLuid );
       
  1230     TInt value = 0;
       
  1231     lex.Val( value );
       
  1232     return value;
       
  1233     }
       
  1234 
       
  1235 // ----------------------------------------------------------------------------
       
  1236 // Converts integer value to 8 bit descriptor.
       
  1237 // ----------------------------------------------------------------------------
       
  1238 HBufC8* CNSmlDmImpsAdapter::IntToDes8LC( const TInt aLuid )
       
  1239     {
       
  1240     HBufC8* buf = HBufC8::NewLC( 10 ); //10 = max length of 32bit integer
       
  1241     TPtr8 ptrBuf = buf->Des();
       
  1242     ptrBuf.Num( aLuid );
       
  1243     return buf;
       
  1244     }
       
  1245 
       
  1246 // ----------------------------------------------------------------------------
       
  1247 // Converts integer value to 16 bit descriptor.
       
  1248 // ----------------------------------------------------------------------------
       
  1249 HBufC* CNSmlDmImpsAdapter::IntToDesLC( const TInt aLuid )
       
  1250     {
       
  1251     HBufC* buf = HBufC::NewLC( 10 ); //10 = max length of 32bit integer
       
  1252     TPtr ptrBuf = buf->Des();
       
  1253     ptrBuf.Num( aLuid );
       
  1254     return buf;
       
  1255     }
       
  1256 
       
  1257 // ----------------------------------------------------------------------------
       
  1258 // CNSmlDmImpsAdapter::FillNodeInfoL()
       
  1259 // Fills the node info in ddf structure
       
  1260 // ----------------------------------------------------------------------------
       
  1261 void CNSmlDmImpsAdapter::FillNodeInfoL( MSmlDmDDFObject& aNode, 
       
  1262                                         const TSmlDmAccessTypes aAccTypes, 
       
  1263                                         MSmlDmDDFObject::TOccurence aOccurrence,
       
  1264                                         MSmlDmDDFObject::TScope aScope, 
       
  1265                                         MSmlDmDDFObject::TDFFormat aFormat, 
       
  1266                                         const TDesC8& aDescription )
       
  1267     {
       
  1268     aNode.SetAccessTypesL( aAccTypes );
       
  1269     aNode.SetOccurenceL( aOccurrence );
       
  1270     aNode.SetScopeL( aScope );
       
  1271     aNode.SetDFFormatL( aFormat );
       
  1272     if( aFormat != MSmlDmDDFObject::ENode )
       
  1273         {
       
  1274         aNode.AddDFTypeMimeTypeL( KNSmlDMImpsTextPlain );
       
  1275         }
       
  1276     aNode.SetDescriptionL( aDescription );
       
  1277     }
       
  1278 
       
  1279 // ----------------------------------------------------------------------------
       
  1280 // CNSmlDmImpsAdapter::ConvertTo8LC()
       
  1281 // Converts string value to 8-bit
       
  1282 // ----------------------------------------------------------------------------
       
  1283 TDesC8& CNSmlDmImpsAdapter::ConvertTo8LC( const TDesC& aSource )
       
  1284     {    
       
  1285     HBufC8* buf = HBufC8::NewLC( aSource.Length()*2 );
       
  1286     TPtr8 bufPtr = buf->Des();
       
  1287     CnvUtfConverter::ConvertFromUnicodeToUtf8( bufPtr, aSource );
       
  1288 
       
  1289     return *buf;
       
  1290     }
       
  1291 
       
  1292 // ----------------------------------------------------------------------------
       
  1293 // CNSmlDmImpsAdapter::ConvertTo16LC()
       
  1294 // Converts string value to 16-bit
       
  1295 // ----------------------------------------------------------------------------
       
  1296 TDesC16& CNSmlDmImpsAdapter::ConvertTo16LC( const TDesC8& aSource )
       
  1297     {
       
  1298     HBufC16* buf16 = HBufC16::NewLC( aSource.Length() );
       
  1299     TPtr bufPtr16 = buf16->Des();
       
  1300 
       
  1301     CnvUtfConverter::ConvertToUnicodeFromUtf8( bufPtr16, aSource );
       
  1302 
       
  1303     return *buf16;
       
  1304     }
       
  1305 
       
  1306 // ----------------------------------------------------------------------------
       
  1307 // CNSmlDmImpsAdapter::ResetSapL();
       
  1308 // Initializes all fields with empty string.
       
  1309 // ----------------------------------------------------------------------------
       
  1310 void CNSmlDmImpsAdapter::ResetSapL( CIMPSSAPSettings* aSap )
       
  1311     {
       
  1312     aSap->SetSAPNameL( KNSmlDMImpsNotDefined );
       
  1313     aSap->SetSAPAddressL( KNSmlDMImpsNotDefined );
       
  1314     aSap->SetSAPUserIdL( KNSmlDMImpsNotDefined );
       
  1315     aSap->SetSAPUserPasswordL( KNSmlDMImpsNotDefined );
       
  1316     aSap->SetAccessPoint( 0 );
       
  1317     aSap->SetHighLevelServices( EIMPSServicesUnknown ); 
       
  1318     return;
       
  1319     }
       
  1320 
       
  1321 // ----------------------------------------------------------------------------
       
  1322 // CNSmlDmImpsAdapter::UpdateValueL();
       
  1323 // Updates the given leaf value. 
       
  1324 // Checks that the object is not too long and returns error status if is.
       
  1325 // ----------------------------------------------------------------------------
       
  1326 CSmlDmAdapter::TError CNSmlDmImpsAdapter::UpdateValueL( const TDesC8& aUpdatedLeaf, 
       
  1327                                                         const TDesC8& aObject, 
       
  1328                                                         CIMPSSAPSettings* aSap )
       
  1329     {
       
  1330     _DBG_FILE( "CNSmlDmImpsAdapter::UpdateValueL(): begin" );		
       
  1331     
       
  1332     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
  1333 
       
  1334     if ( aUpdatedLeaf.Compare( KNSmlDMImpsName ) == 0 )
       
  1335         {
       
  1336         // Check the length of SapName
       
  1337         if ( aObject.Length() <= KNSmlDMMaxNameLen )
       
  1338             {
       
  1339             aSap->SetSAPNameL( ConvertTo16LC( aObject ) );
       
  1340             CleanupStack::PopAndDestroy();  // ConvertTo16LC            
       
  1341             }
       
  1342         else
       
  1343             {
       
  1344             // length of SapName is too long
       
  1345             status = CSmlDmAdapter::ETooLargeObject; 
       
  1346             }
       
  1347         }    
       
  1348     else if ( aUpdatedLeaf.Compare( KNSmlDMImpsPrefAddr ) == 0 )
       
  1349         {
       
  1350         // Check the length of PrefAddr
       
  1351         if ( aObject.Length() <= KNSmlDMMaxAddrLen )
       
  1352             {
       
  1353             aSap->SetSAPAddressL( ConvertTo16LC( aObject ) );
       
  1354             CleanupStack::PopAndDestroy(); // ConvertTo16LC
       
  1355             }
       
  1356         else
       
  1357             {
       
  1358             // length of PrefAddr is too long
       
  1359             status = CSmlDmAdapter::ETooLargeObject; 
       
  1360             }                
       
  1361         }
       
  1362     else if ( aUpdatedLeaf.Compare( KNSmlDMImpsAAuthName ) == 0 )
       
  1363         {
       
  1364         // Check the length of AAuthName
       
  1365         if ( aObject.Length() <= KNSmlDMMaxNameLen )
       
  1366             {
       
  1367             aSap->SetSAPUserIdL( ConvertTo16LC( aObject ) );
       
  1368             CleanupStack::PopAndDestroy(); // ConvertTo16LC
       
  1369             }
       
  1370         else
       
  1371             {
       
  1372             // length of AuthName is too long
       
  1373             status = CSmlDmAdapter::ETooLargeObject; 
       
  1374             }        
       
  1375         }
       
  1376     else if ( aUpdatedLeaf.Compare( KNSmlDMImpsAAuthSecret ) == 0 )
       
  1377         {
       
  1378         // Check the length of AAuthSecret
       
  1379         if ( aObject.Length() <= KNSmlDMMaxNameLen )
       
  1380             {
       
  1381             aSap->SetSAPUserPasswordL( ConvertTo16LC( aObject ) );
       
  1382             CleanupStack::PopAndDestroy(); // ConvertTo16LC
       
  1383             }
       
  1384         else
       
  1385             {
       
  1386             // length of AuthSecret is too long
       
  1387             status = CSmlDmAdapter::ETooLargeObject; 
       
  1388             }        
       
  1389         }        
       
  1390     else if ( aUpdatedLeaf.Compare( KNSmlDMImpsPrefConRef ) == 0 )
       
  1391         {
       
  1392         // find out the access point link        
       
  1393         TPtrC8 objectPtr= NSmlDmURI::RemoveDotSlash( aObject );
       
  1394 
       
  1395 // Used only in Test purpose
       
  1396 //   TBuf8<50> tmpObjBuf = objectPtr;   
       
  1397 //   DBG_ARGS8(_S8("IMPS : AP = %S \n"), &tmpObjBuf );     
       
  1398 
       
  1399         HBufC8* luid = iCallBack->GetLuidAllocL( objectPtr );
       
  1400         CleanupStack::PushL( luid );
       
  1401 
       
  1402 // Used only in Test purpose
       
  1403 //        DBG_ARGS8(_S8("Luid length = %d \n"), luid->Length() );     
       
  1404 
       
  1405         if( luid->Length() > 0 )
       
  1406             {
       
  1407             TInt uid = DesToInt( *luid );
       
  1408             TUint32 uid32( uid );
       
  1409             aSap->SetAccessPoint( uid32 );  
       
  1410             }
       
  1411         else
       
  1412             {
       
  1413             status = CSmlDmAdapter::ENotFound;
       
  1414             }
       
  1415 
       
  1416         CleanupStack::PopAndDestroy(); // luid        
       
  1417         }
       
  1418             
       
  1419     else if ( aUpdatedLeaf.Compare( KNSmlDMImpsAAuthLevel ) == 0 )
       
  1420         {
       
  1421         if ( ( aObject.Length() > 0 ) && 
       
  1422              ( aObject.Compare( KNSmlDMImpsDefaultAAuthLevel ) != 0 ) )
       
  1423             {
       
  1424             status = CSmlDmAdapter::EInvalidObject;
       
  1425             }
       
  1426         }       
       
  1427     else if ( aUpdatedLeaf.Compare( KNSmlDMImpsServices ) == 0 )
       
  1428         {
       
  1429         // Change the text to int value    
       
  1430         TUint32 serv = EIMPSServicesUnknown;
       
  1431 
       
  1432         TBool imFlag = EFalse;
       
  1433         TBool psFlag = EFalse;
       
  1434         TBool grFlag = EFalse;
       
  1435         
       
  1436         TInt len = aObject.Length();
       
  1437         TInt startIndex = 0;  // tells the start point of value
       
  1438         TInt endIndex = 1;  // tells the end point of value
       
  1439         while ( endIndex < len )
       
  1440             {
       
  1441 //            TPtrC8 objPtr = aObject.Mid( startIndex, 2 );
       
  1442             TBufC8<2> str = aObject.Mid( startIndex, 2 );
       
  1443             if ( str.Match( KNSmlDMImpsServiceIM ) != KErrNotFound )
       
  1444                 {
       
  1445                 if ( imFlag == EFalse )
       
  1446                     {
       
  1447                     // IM service found	
       
  1448                     serv |= EIMPSServicesIM;
       
  1449                     imFlag = ETrue;
       
  1450                     }                    	    					                
       
  1451                 else
       
  1452                     {
       
  1453                     status = CSmlDmAdapter::EInvalidObject;
       
  1454                     break;
       
  1455                     }            
       
  1456                 }
       
  1457             else if ( str.Match( KNSmlDMImpsServicePS ) != KErrNotFound )
       
  1458                 {
       
  1459                 if ( psFlag == EFalse )
       
  1460                     {
       
  1461                     // PS service found	
       
  1462                     serv |= EIMPSServicesPEC;
       
  1463                     psFlag = ETrue;
       
  1464                     }                    	    					                
       
  1465                 else
       
  1466                     {
       
  1467                     status = CSmlDmAdapter::EInvalidObject;
       
  1468                     break;
       
  1469                     }            
       
  1470                 }
       
  1471             else if ( str.Match( KNSmlDMImpsServiceGR ) != KErrNotFound )
       
  1472                 {
       
  1473                 if ( grFlag == EFalse )
       
  1474                     {
       
  1475                     // GR service found	
       
  1476                     serv |= EIMPSServicesGroups;
       
  1477                     grFlag = ETrue;
       
  1478                     }                    	    					                
       
  1479                 else
       
  1480                     {
       
  1481                     status = CSmlDmAdapter::EInvalidObject;
       
  1482                     break;
       
  1483                     }            
       
  1484                 }      	    	          
       
  1485             else
       
  1486                 {
       
  1487                 status = CSmlDmAdapter::EInvalidObject;
       
  1488                 break;
       
  1489                 }            
       
  1490             startIndex = endIndex + 1;
       
  1491             if ( startIndex < len )
       
  1492                 {
       
  1493                 TBufC8<1> chr = aObject.Mid( startIndex, 1 );
       
  1494                 if ( chr.Match( KNSmlDMImpsSemiColon ) == KErrNotFound )
       
  1495                     {
       
  1496                     status = CSmlDmAdapter::EInvalidObject;
       
  1497                     break;                    
       
  1498                     }
       
  1499                 }
       
  1500             startIndex++;
       
  1501             endIndex = startIndex + 1;
       
  1502             }  // while
       
  1503 
       
  1504             // Set Services
       
  1505         if ( status == KErrNone )
       
  1506             {
       
  1507             aSap->SetHighLevelServices( serv );	    	                    
       
  1508             }	
       
  1509         }  // KNSmlDMImpsServices
       
  1510     else  // Unknown leaf
       
  1511         {
       
  1512         status = CSmlDmAdapter::EInvalidObject;
       
  1513         }        
       
  1514 
       
  1515     _DBG_FILE( "CNSmlDmImpsAdapter::UpdateValueL(): end" );		
       
  1516             
       
  1517     return status;
       
  1518     }
       
  1519 
       
  1520 // ----------------------------------------------------------------------------
       
  1521 // CNSmlDmImpsAdapter::UpdatePEPValueL();
       
  1522 // If PEP value is changed, deletes the existing SAP and creates new one with 
       
  1523 // received access group and sets new mappings to all nodes and leafs
       
  1524 // ----------------------------------------------------------------------------
       
  1525 CSmlDmAdapter::TError CNSmlDmImpsAdapter::UpdatePEPValueL( const TDesC8& aURI, 
       
  1526                                                            const TDesC8& aObject, 
       
  1527                                                            const TDesC8& aLUID, 
       
  1528                                                            CIMPSSAPSettings* aSap, 
       
  1529                                                            CIMPSSAPSettingsStore* aStore )
       
  1530     {	
       
  1531     _DBG_FILE( "CNSmlDmImpsAdapter::UpdatePEPValueL(): begin" );		
       
  1532 
       
  1533     HBufC8 *object = HBufC8::NewLC( aObject.Length() );
       
  1534     TPtr8 objPtr = object->Des();
       
  1535     objPtr.Format( aObject );
       
  1536     objPtr.UpperCase();
       
  1537     
       
  1538     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
  1539     TInt uid = DesToInt ( aLUID );
       
  1540     TUint32 uid32( uid );
       
  1541     
       
  1542     TIMPSAccessGroup newAccGroup = EIMPSIMAccessGroup;
       
  1543     if ( ( objPtr.Compare( KNSmlDMImpsDefaultPEC ) == 0 ) 
       
  1544         || ( objPtr.Compare( KNSmlDMImpsDefPEC ) == 0 ) )
       
  1545         {
       
  1546         newAccGroup = EIMPSPECAccessGroup;
       
  1547         }
       
  1548     else if ( ( objPtr.Compare( KNSmlDMImpsDefaultIM ) == 0 ) 
       
  1549         || ( objPtr.Compare( KNSmlDMImpsDefIM ) == 0 ) )
       
  1550         {
       
  1551         newAccGroup = EIMPSIMAccessGroup;
       
  1552         }
       
  1553     else
       
  1554         {
       
  1555         status = CSmlDmAdapter::EInvalidObject;
       
  1556         }        
       
  1557 
       
  1558     CleanupStack::PopAndDestroy(); // object
       
  1559  
       
  1560     TIMPSAccessGroup oldAccGroup = aSap->AccessGroup();
       
  1561     if ( oldAccGroup != newAccGroup )
       
  1562         {	        
       
  1563         // The AccessGroup should be changed.    	        
       
  1564         // Check mapping first
       
  1565         
       
  1566         TPtrC8 ptrToExtUri = NSmlDmURI::RemoveLastSeg( aURI ); // IMPS/<x>/Ext            
       
  1567         TPtrC8 ptrToDynNode = NSmlDmURI::RemoveLastSeg( ptrToExtUri ); // IMPS/<x>
       
  1568 
       
  1569         HBufC8 *appAuthUri = HBufC8::NewLC( ptrToDynNode.Length() + 
       
  1570                                      KNSmlDMMaxNameLen );
       
  1571         TPtr8 appAuthPtr= appAuthUri->Des();
       
  1572 
       
  1573         // URI: IMPS/<x>/AppAuth
       
  1574         appAuthPtr.Format( ptrToDynNode );
       
  1575         appAuthPtr.Append( KNSmlDMImpsSeparator8 );
       
  1576         appAuthPtr.Append( KNSmlDMImpsAppAuth );
       
  1577 		
       
  1578 // Used only in Test purpose
       
  1579 //        TBuf8<50> tmpUriBuf = appAuthPtr;
       
  1580 //        DBG_ARGS8(_S8("Fetched Uri = %S"), &tmpUriBuf );     
       
  1581 
       
  1582         // Get dynamic node under AppAuth
       
  1583         CBufBase *allNodes = CBufFlat::NewL( KNSmlDMReservingData );
       
  1584         CleanupStack::PushL( allNodes );
       
  1585         iCallBack->FetchLinkL( appAuthPtr, *allNodes, status );
       
  1586 		    
       
  1587 // Used only in Test purpose
       
  1588         DBG_ARGS8(_S8("Status = %d \n"), status );     
       
  1589 		    
       
  1590         if( status == CSmlDmAdapter::EOk )
       
  1591             {               	        	
       
  1592             // Delete existing SAP
       
  1593             aStore->DeleteSAPL( uid32 );
       
  1594             _DBG_FILE( "CNSmlDmImpsAdapter::UpdatePEPValueL(): SAP deleted" );
       
  1595         
       
  1596             // Create new with correct AccessGroup        
       
  1597             uid32 = aStore->StoreNewSAPL( aSap, newAccGroup );
       
  1598             uid = TInt( uid32 );
       
  1599             _DBG_FILE( "CNSmlDmImpsAdapter::UpdatePEPValueL(): New SAP added" );
       
  1600 		
       
  1601             // Set mappings to new UID
       
  1602             HBufC8 *luidDes = IntToDes8LC( TInt( uid ) );
       
  1603         	
       
  1604             // URI: IMPS/<x>/Ext/PEPCompliant
       
  1605             iCallBack->SetMappingL( aURI, *luidDes );
       
  1606 
       
  1607             // URI: IMPS/<x>/Ext        	
       
  1608             iCallBack->SetMappingL( ptrToExtUri, *luidDes );
       
  1609 
       
  1610             // URI: IMPS/<x>
       
  1611             iCallBack->SetMappingL( ptrToDynNode, *luidDes );
       
  1612         
       
  1613             // URI: IMPS/<x>/AppAuth
       
  1614             iCallBack->SetMappingL( appAuthPtr, *luidDes );		
       
  1615 
       
  1616        	    if ( allNodes->Size() > 0 )
       
  1617                 {
       
  1618                 TPtrC8 uriSeg8Ptr = allNodes->Ptr( 0 );
       
  1619 
       
  1620                 // URI: IMPS/<x>/AppAuth/<x>
       
  1621                 HBufC8 *authUri = HBufC8::NewLC( appAuthPtr.Length() + 
       
  1622                                                  uriSeg8Ptr.Length() );				
       
  1623                 TPtr8 authUriPtr= authUri->Des();
       
  1624                 authUriPtr.Format( appAuthPtr );
       
  1625                 authUriPtr.Append( KNSmlDMImpsSeparator8 );
       
  1626                 authUriPtr.Append( uriSeg8Ptr );
       
  1627                 iCallBack->SetMappingL( authUriPtr, *luidDes );
       
  1628                 
       
  1629                 CleanupStack::PopAndDestroy(); // authUri
       
  1630                 }
       
  1631             CleanupStack::PopAndDestroy(); // luidDes
       
  1632             }
       
  1633 		
       
  1634         CleanupStack::PopAndDestroy( 2 ); // appAuthUri, allNodes
       
  1635         } // oldValue != newValue  	
       
  1636 
       
  1637     _DBG_FILE( "CNSmlDmImpsAdapter::UpdatePEPValueL(): end" );		
       
  1638 
       
  1639     return status;
       
  1640     }
       
  1641 
       
  1642 // ----------------------------------------------------------------------------
       
  1643 // CNSmlDmImpsAdapter::DeleteValueL();
       
  1644 // Initializes the given leaf field with empty string.
       
  1645 // ----------------------------------------------------------------------------
       
  1646 CSmlDmAdapter::TError CNSmlDmImpsAdapter::DeleteValueL( const TDesC8& aUri, 
       
  1647                                                         CIMPSSAPSettings* aSap )
       
  1648     {
       
  1649     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
  1650 
       
  1651     TPtrC8 deletedLeaf = NSmlDmURI::LastURISeg( aUri );
       
  1652     TPtrC8 ptrToParentUri = NSmlDmURI::RemoveLastSeg( aUri );
       
  1653     TPtrC8 parentSeg = NSmlDmURI::LastURISeg( ptrToParentUri );
       
  1654 
       
  1655     if ( deletedLeaf.Compare( KNSmlDMImpsName ) == 0)
       
  1656         {
       
  1657         aSap->SetSAPNameL( ConvertTo16LC( parentSeg ) );
       
  1658         CleanupStack::PopAndDestroy();
       
  1659         }
       
  1660     else if ( deletedLeaf.Compare( KNSmlDMImpsPrefAddr ) == 0)
       
  1661         {
       
  1662         aSap->SetSAPAddressL( KNSmlDMImpsNotDefined );
       
  1663         }
       
  1664     else if ( deletedLeaf.Compare( KNSmlDMImpsAAuthName ) == 0)
       
  1665         {
       
  1666         aSap->SetSAPUserIdL( KNSmlDMImpsNotDefined );
       
  1667         }
       
  1668     else if ( deletedLeaf.Compare( KNSmlDMImpsAAuthSecret ) == 0)
       
  1669         {
       
  1670         aSap->SetSAPUserPasswordL( KNSmlDMImpsNotDefined );
       
  1671         }
       
  1672     else if ( deletedLeaf.Compare( KNSmlDMImpsPrefConRef ) == 0 )
       
  1673         {
       
  1674         aSap->SetAccessPoint( 0 );  
       
  1675         }
       
  1676     else if ( deletedLeaf.Compare( KNSmlDMImpsAAuthLevel ) == 0 )
       
  1677         {
       
  1678         // AAuthLevel is not stored anywhere so it can not be deleted either
       
  1679         }
       
  1680     else if ( ( aUri.Match( KNSmlDMImpsWholeAppAuthUri ) != KErrNotFound ) ||
       
  1681             ( aUri.Match( KNSmlDMImpsWholeAppAuthDynUri ) != KErrNotFound ) )
       
  1682         {
       
  1683         aSap->SetSAPUserIdL( KNSmlDMImpsNotDefined );
       
  1684         aSap->SetSAPUserPasswordL( KNSmlDMImpsNotDefined );
       
  1685         }
       
  1686     else if ( deletedLeaf.Compare( KNSmlDMImpsServices ) == 0 )
       
  1687         {
       
  1688         status = CSmlDmAdapter::EError;
       
  1689         }
       
  1690     else  // Unknown leaf
       
  1691         {
       
  1692         status = CSmlDmAdapter::EInvalidObject;
       
  1693         }
       
  1694                 
       
  1695     return status;
       
  1696     }
       
  1697 
       
  1698 // ----------------------------------------------------------------------------
       
  1699 // CNSmlDmImpsAdapter::FetchObjectL();
       
  1700 // The method reads the requested parameter value from DB
       
  1701 // - Check that the requested SAP exists in DB by checking that 
       
  1702 //      the uid with LUID value exists.
       
  1703 // - Get SAP data to aSap
       
  1704 // - Read the requested parameter value
       
  1705 // - In error case return error status
       
  1706 // ----------------------------------------------------------------------------
       
  1707 CSmlDmAdapter::TError CNSmlDmImpsAdapter::FetchObjectL( const TDesC8& aUri, 
       
  1708                                                         const TDesC8& aLUID, 
       
  1709                                                         CBufBase& aObject )
       
  1710     {	
       
  1711     CSmlDmAdapter::TError status = CSmlDmAdapter::EOk;
       
  1712     
       
  1713     CIMPSSAPSettings* ownSap = CIMPSSAPSettings::NewL();
       
  1714     CleanupStack::PushL( ownSap );
       
  1715     CIMPSSAPSettingsStore* ownStore = CIMPSSAPSettingsStore::NewL();
       
  1716     CleanupStack::PushL( ownStore );
       
  1717     
       
  1718     if( aLUID.Length() > 0 )
       
  1719         {
       
  1720         // Check that Store is not empty
       
  1721         // causes leaving if empty db is tried to read
       
  1722         TInt sapFound = KErrNotFound;
       
  1723         sapFound = GetCorrectSapL( aLUID, ownSap, ownStore );
       
  1724         if ( sapFound == KErrNone )
       
  1725             {
       
  1726             // Sap exist, read value of correct leaf
       
  1727             if ( aUri.Compare( KNSmlDMImpsName ) == 0 )
       
  1728                 {
       
  1729                 aObject.InsertL( 0, ConvertTo8LC( ownSap->SAPName() ) );
       
  1730                 CleanupStack::PopAndDestroy();  // ConvertTo8LC
       
  1731                 }
       
  1732             else if ( aUri.Compare( KNSmlDMImpsPrefAddr ) == 0 )
       
  1733                 {
       
  1734                 aObject.InsertL( 0, ConvertTo8LC( ownSap->SAPAddress() ) );
       
  1735                 CleanupStack::PopAndDestroy();  // ConvertTo8LC
       
  1736                 }
       
  1737             else if ( aUri.Compare( KNSmlDMImpsAAuthName ) == 0 )
       
  1738                 {
       
  1739                 aObject.InsertL( 0, ConvertTo8LC( ownSap->SAPUserId() ) );
       
  1740                 CleanupStack::PopAndDestroy();  // ConvertTo8LC
       
  1741                 }
       
  1742             else if ( aUri.Compare( KNSmlDMImpsAAuthSecret ) == 0 )
       
  1743                 {
       
  1744                 // Requesting password not allowed.
       
  1745                 status = EError;
       
  1746                 }
       
  1747             else if ( aUri.Compare( KNSmlDMImpsPepCompliant ) == 0 )
       
  1748                 {
       
  1749                 TIMPSAccessGroup accGroup = ownSap->AccessGroup();
       
  1750                 if ( accGroup == EIMPSPECAccessGroup )	    	
       
  1751                     { 
       
  1752                     aObject.InsertL( 0, KNSmlDMImpsDefaultPEC );  		
       
  1753                     }
       
  1754                 else
       
  1755                     {
       
  1756                     aObject.InsertL( 0, KNSmlDMImpsDefaultIM );  						  					  	
       
  1757                     }
       
  1758                 }  // PEPCompliant
       
  1759             else if ( aUri.Compare( KNSmlDMImpsPrefConRef ) == 0 )
       
  1760                 {            
       
  1761                 HBufC8* buf = IntToDes8LC( ownSap->AccessPoint() );
       
  1762                 TUint idFromDb = DesToInt( buf->Des() );
       
  1763                 CleanupStack::PopAndDestroy( ); // buf
       
  1764                 
       
  1765                 CBufBase *allIAPs = CBufFlat::NewL( KNSmlDMReservingData );
       
  1766                 CleanupStack::PushL( allIAPs );
       
  1767                 iCallBack->FetchLinkL( GetConRef(), *allIAPs, status );
       
  1768 		    
       
  1769                 TBool found = EFalse;
       
  1770                 if( status == CSmlDmAdapter::EOk )
       
  1771                     {
       
  1772                     TInt startIndex = 0;
       
  1773         
       
  1774                     for( TInt i = 0; i < allIAPs->Size(); i++ )
       
  1775                         {
       
  1776                         if( allIAPs->Ptr(0)[i] == '/' || i == allIAPs->Size()-1 )
       
  1777                             {
       
  1778                             HBufC8 *uriSegment=0;
       
  1779                             TPtrC8 uriSeg8Ptr = allIAPs->Ptr( startIndex ).Mid( 0, i-startIndex );                				
       
  1780                             uriSegment = uriSeg8Ptr.AllocLC();
       
  1781                             HBufC8 *uri = HBufC8::NewLC( GetConRef().Length() + 1 + uriSegment->Length() );
       
  1782                             TPtr8 uriPtr= uri->Des();
       
  1783                             uriPtr.Format( GetConRef());
       
  1784                             uriPtr.Append( KNSmlDMImpsSeparator );
       
  1785                             uriPtr.Append( *uriSegment );
       
  1786                             HBufC8* luid = iCallBack->GetLuidAllocL( uriPtr );
       
  1787                             CleanupStack::PushL( luid );
       
  1788 
       
  1789                             if( luid->Length() > 0 )
       
  1790                                 {
       
  1791                                 TInt iapId = DesToInt( luid->Des() );
       
  1792                                 if( iapId == idFromDb )
       
  1793                                     {
       
  1794                                     found = ETrue;
       
  1795                                     aObject.InsertL( 0, uriPtr );
       
  1796                                     CleanupStack::PopAndDestroy( 3 ); // uriSegment, uri, luid
       
  1797                                     break;
       
  1798                                     }                                
       
  1799                                 }  // if luid
       
  1800 					        
       
  1801                             startIndex = i + 1;
       
  1802                             CleanupStack::PopAndDestroy( 3 ); // uriSegment, uri, luid
       
  1803                             } //end if allIaps...
       
  1804                         } //end for
       
  1805                     }
       
  1806                 CleanupStack::PopAndDestroy(); //allIaps
       
  1807                 if( !found )
       
  1808                     {
       
  1809                     status = CSmlDmAdapter::ENotFound;
       
  1810                     }
       
  1811                 } // PrefConRef
       
  1812 
       
  1813             else if ( aUri.Compare( KNSmlDMImpsAppId ) == 0 )
       
  1814                 {
       
  1815                 // AppID is not used yet so return default value
       
  1816                 aObject.InsertL( 0, KNSmlDMImpsDefaultAppID ); 
       
  1817                 }
       
  1818             else if ( aUri.Compare( KNSmlDMImpsAAuthLevel ) == 0 )
       
  1819                 {
       
  1820                 // Check from the database if the AAuthName or AAuthSecret are defined
       
  1821                 // if they are, return default value
       
  1822                 if ( ( ownSap->SAPUserId().Compare(KNSmlDMImpsNotDefined ) == 0 ) &&
       
  1823                      ( ownSap->SAPUserPassword().Compare(KNSmlDMImpsNotDefined ) == 0 ) )
       
  1824                     // AAuthName and AAuthSecret are not defined 
       
  1825                     {
       
  1826                     aObject.InsertL( 0, KNSmlDMImpsNotDefined8 ); 
       
  1827                     }
       
  1828                 else
       
  1829                     {
       
  1830                     aObject.InsertL( 0, KNSmlDMImpsDefaultAAuthLevel ); 
       
  1831                     }
       
  1832                 }   // AppID                 
       
  1833             else if ( aUri.Compare( KNSmlDMImpsServices ) == 0 )
       
  1834                 {
       
  1835                 HBufC8 *services=0;
       
  1836                 TUint32 serv = EIMPSServicesUnknown;
       
  1837                 services = HBufC8::NewLC( 11 ); 
       
  1838                 TPtr8 servicesPtr = services->Des();
       
  1839             	
       
  1840                 serv = ownSap->HighLevelServices();
       
  1841                 switch ( serv )
       
  1842                     {
       
  1843                     case ( EIMPSServicesIM ):
       
  1844                         {
       
  1845                         servicesPtr.Format( KNSmlDMImpsServiceIM );
       
  1846                         break;
       
  1847                         }
       
  1848                     case ( EIMPSServicesPEC ):
       
  1849                         {
       
  1850                         servicesPtr.Format( KNSmlDMImpsServicePS );            			
       
  1851                         break;
       
  1852                         }
       
  1853                     case ( EIMPSServicesIM | EIMPSServicesPEC ):
       
  1854                         {
       
  1855                         servicesPtr.Format( KNSmlDMImpsServiceIM );
       
  1856                         servicesPtr.Append( KNSmlDMImpsSemiColon );
       
  1857                         servicesPtr.Append( KNSmlDMImpsServicePS );
       
  1858                         break;
       
  1859                         }
       
  1860                     case ( EIMPSServicesGroups ):
       
  1861                         {
       
  1862                         servicesPtr.Format( KNSmlDMImpsServiceGR );           			
       
  1863                         break;
       
  1864                         }
       
  1865                     case ( EIMPSServicesIM | EIMPSServicesGroups ):
       
  1866                         {
       
  1867                         servicesPtr.Format( KNSmlDMImpsServiceIM );
       
  1868                         servicesPtr.Append( KNSmlDMImpsSemiColon );
       
  1869                         servicesPtr.Append( KNSmlDMImpsServiceGR );
       
  1870                         break;
       
  1871                         }
       
  1872                         case ( EIMPSServicesPEC | EIMPSServicesGroups ):
       
  1873                         {
       
  1874                         servicesPtr.Format( KNSmlDMImpsServicePS );
       
  1875                         servicesPtr.Append( KNSmlDMImpsSemiColon );
       
  1876                         servicesPtr.Append( KNSmlDMImpsServiceGR );
       
  1877                         break;
       
  1878                         }
       
  1879             		case ( EIMPSServicesIM | EIMPSServicesPEC | EIMPSServicesGroups ):
       
  1880             			{
       
  1881 						servicesPtr.Format( KNSmlDMImpsServiceIM );
       
  1882 						servicesPtr.Append( KNSmlDMImpsSemiColon );
       
  1883                         servicesPtr.Append( KNSmlDMImpsServicePS );
       
  1884                         servicesPtr.Append( KNSmlDMImpsSemiColon );
       
  1885                         servicesPtr.Append( KNSmlDMImpsServiceGR );
       
  1886 
       
  1887 						break;
       
  1888             			}
       
  1889             		default:
       
  1890         	    		{
       
  1891                         servicesPtr.Format( KNSmlDMImpsNotDefined8 );	            		
       
  1892                         break;
       
  1893                         }
       
  1894                     }  // Service      		            		            	
       
  1895                     aObject.InsertL( 0, servicesPtr );
       
  1896                     CleanupStack::PopAndDestroy(); // services     		        
       
  1897                 } 
       
  1898             else  
       
  1899                 {
       
  1900                 status = CSmlDmAdapter::EInvalidObject;
       
  1901                 }
       
  1902             }  // sapFound
       
  1903         else if ( sapFound == KErrNotFound )                    	 
       
  1904             {      		
       
  1905             status = CSmlDmAdapter::ENotFound;
       
  1906             }  
       
  1907         else
       
  1908             {
       
  1909             status = CSmlDmAdapter::EError;
       
  1910             }
       
  1911 
       
  1912         }  // aLUID length
       
  1913     else  
       
  1914         {
       
  1915         status = CSmlDmAdapter::ENotFound;
       
  1916         }
       
  1917 
       
  1918     CleanupStack::PopAndDestroy( 2 ); // ownSap, ownStore
       
  1919         
       
  1920     return status;
       
  1921     }
       
  1922 
       
  1923 // ----------------------------------------------------------------------------
       
  1924 // CNSmlDmImpsAdapter::GetCorrectSapL();
       
  1925 // The method reads the requested parameter value from DB
       
  1926 // - Check that the requested SAP exists in DB by checking 
       
  1927 //      that the index with LUID value exists.
       
  1928 // - Get SAP data to aSap
       
  1929 // - Read the requested parameter value
       
  1930 // - In error case return error status
       
  1931 // ----------------------------------------------------------------------------
       
  1932 TInt CNSmlDmImpsAdapter::GetCorrectSapL( const TDesC8& aLUID, 
       
  1933                                          CIMPSSAPSettings* aSap, 
       
  1934                                          CIMPSSAPSettingsStore* aStore )
       
  1935     {	
       
  1936     // If value of Stat is KErrNone, the Sap has been found. 
       
  1937     // If it is KErrNotFound, the Sap does not exist.
       
  1938     // Else the stat returns error status.
       
  1939     CIMPSSAPSettingsList* ownList = CIMPSSAPSettingsList::NewL();   
       
  1940     CleanupStack::PushL( ownList );
       
  1941 	
       
  1942     TInt stat = KErrNotFound;
       
  1943 	
       
  1944         // Check that Store is not empty
       
  1945         // causes leaving if empty db is tried to read
       
  1946     TInt count = 0;
       
  1947     count = aStore->SAPCountL( EIMPSAccessFilterAll ) ;
       
  1948     DBG_ARGS8(_S8("IMPS::Count of SAPs in store = %d \n"), count );
       
  1949     if ( count > 0 )
       
  1950         {
       
  1951         TInt uid = DesToInt( aLUID );
       
  1952         TUint32 uid32( uid );
       
  1953         aStore->PopulateSAPSettingsListL( *ownList, EIMPSAccessFilterAll );
       
  1954         _DBG_FILE( "CNSmlDmImpsAdapter::GetCorrectSapL(): SAP settings list" );
       
  1955         for ( TInt i = 0; i < count; i++ )
       
  1956             {
       
  1957             TUint32 id32 = ownList->UidForIndex( i );
       
  1958             if ( id32 == uid32 )
       
  1959                 {
       
  1960                 aStore->GetSAPL( uid32, aSap );
       
  1961                 _DBG_FILE( "CNSmlDmImpsAdapter::GetCorrectSapL(): SAP requested" );
       
  1962                 stat = KErrNone;
       
  1963                 break;
       
  1964                 }
       
  1965             } // for        	   
       
  1966         } // if count
       
  1967 
       
  1968     CleanupStack::PopAndDestroy(); // ownList
       
  1969 
       
  1970     return stat;
       
  1971     }
       
  1972 
       
  1973 // ----------------------------------------------------------------------------
       
  1974 // TImplementationProxy ImplementationTable[]
       
  1975 // Needed because of ECOM architecture
       
  1976 // ----------------------------------------------------------------------------
       
  1977 #ifndef IMPLEMENTATION_PROXY_ENTRY
       
  1978 #define IMPLEMENTATION_PROXY_ENTRY( aUid, aFuncPtr ) { {aUid}, ( aFuncPtr ) }
       
  1979 #endif
       
  1980 const TImplementationProxy ImplementationTable[] = 
       
  1981     {
       
  1982     IMPLEMENTATION_PROXY_ENTRY( KNSmlDMImpsAdapterImplUid, 
       
  1983                                 CNSmlDmImpsAdapter::NewL )
       
  1984     };
       
  1985 
       
  1986 // ----------------------------------------------------------------------------
       
  1987 //
       
  1988 // ----------------------------------------------------------------------------
       
  1989 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
  1990     {
       
  1991     _DBG_FILE( "ImplementationGroupProxy() for CNSmlDmImpsAdapter: begin" );
       
  1992     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
  1993     _DBG_FILE( "ImplementationGroupProxy() for CNSmlDmImpsAdapter: end" );
       
  1994     return ImplementationTable;
       
  1995     }
       
  1996 
       
  1997 
       
  1998 // ----------------------------------------------------------------------------
       
  1999 //
       
  2000 // ----------------------------------------------------------------------------
       
  2001 void CNSmlDmImpsAdapter::HandleSessionEventL( TMsvSessionEvent /*aEvent*/, 
       
  2002                                               TAny* /*aArg1*/, 
       
  2003                                               TAny* /*aArg2*/, 
       
  2004                                               TAny* /*aArg3*/ )
       
  2005     {
       
  2006     _DBG_FILE( "CNSmlDmImpsAdapter::HandleSessionEventL(): begin" );
       
  2007 
       
  2008     _DBG_FILE( "CNSmlDmImpsAdapter::HandleSessionEventL(): end" );
       
  2009     }
       
  2010     
       
  2011 // ------------------------------------------------------------------------------------------------
       
  2012 // CNSmlDmImpsAdapter::const TDesC8& GetConRef()
       
  2013 // Returns the connection reference
       
  2014 // ------------------------------------------------------------------------------------------------
       
  2015 const TDesC8& CNSmlDmImpsAdapter::GetConRef()
       
  2016 	{
       
  2017 	if(FeatureManager::FeatureSupported(KFeatureIdFfDmConnmoAdapter))
       
  2018 		{
       
  2019 			return KNSmlDMImpsConnMOIAPUri();
       
  2020 		}
       
  2021 	else
       
  2022 		{
       
  2023 			return KNSmlDMImpsIAPUri();
       
  2024 		}	
       
  2025   }	    
       
  2026 
       
  2027 
       
  2028 // End of file
       
  2029