syncmlfw/ds/syncagent/src/nsmldscmds.cpp
branchRCL_3
changeset 25 b183ec05bd8c
parent 24 13d7c31c74e0
child 26 19bba8228ff0
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
    16 */
    16 */
    17 
    17 
    18 #define SYNCML_V3
    18 #define SYNCML_V3
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <SyncMLObservers.h>
    20 #include <SyncMLObservers.h>
    21 #include <SyncMLNotifierParams.h>
       
    22 #include <SyncMLNotifier.h>
       
    23 #include <nsmlconstants.h>
    21 #include <nsmlconstants.h>
    24 #include <nsmldebug.h>
    22 #include <nsmldebug.h>
    25 #include <nsmlphoneinfo.h>
    23 #include <nsmlphoneinfo.h>
    26 #include <nsmlunicodeconverter.h>
    24 #include <nsmlunicodeconverter.h>
    27 #include <centralrepository.h>
       
    28 // common includes with DM
    25 // common includes with DM
    29 #include "nsmlcliagconstants.h"
    26 #include "nsmlcliagconstants.h"
    30 #include "NSmlCmdsBase.h"
    27 #include "NSmlCmdsBase.h"
    31 #include "NSmlAgentBase.h"
    28 #include "NSmlAgentBase.h"
    32 #include "NSmlStatusContainer.h"
    29 #include "NSmlStatusContainer.h"
    47 #include "nsmldscontent.h"
    44 #include "nsmldscontent.h"
    48 #include "NSmlDSAgent.h"
    45 #include "NSmlDSAgent.h"
    49 #include "nsmldserror.h"
    46 #include "nsmldserror.h"
    50 #include "nsmlfilter.h"
    47 #include "nsmlfilter.h"
    51 #include "nsmldssettings.h"
    48 #include "nsmldssettings.h"
       
    49 #include "nsmldsoperatorsettings.h"
    52 #include "nsmldsbatchbuffer.h"
    50 #include "nsmldsbatchbuffer.h"
    53 #include "nsmldshostclient.h"
    51 #include "nsmldshostclient.h"
    54 #include "nsmloperatordefines.h"
    52 #include <nsmloperatorerrorcrkeys.h> // KCRUidOperatorDatasyncErrorKeys
    55 #include "NsmlOperatorErrorCRKeys.h"
    53 #include <nsmldevinfextdatacontainerplugin.h>
    56 
    54 
    57 #ifndef __WINS__
    55 #ifndef __WINS__
    58 // This lowers the unnecessary compiler warning (armv5) to remark.
    56 // This lowers the unnecessary compiler warning (armv5) to remark.
    59 // "Warning:  #174-D: expression has no effect..." is caused by 
    57 // "Warning:  #174-D: expression has no effect..." is caused by 
    60 // DBG_ARGS8 macro in no-debug builds.
    58 // DBG_ARGS8 macro in no-debug builds.
    62 #endif
    60 #endif
    63 
    61 
    64 
    62 
    65 // CONSTANTS
    63 // CONSTANTS
    66 _LIT8( KNSmlRoot, "/" );
    64 _LIT8( KNSmlRoot, "/" );
    67 static const TInt KMaxLength = 255;
       
    68 const TUid KRepositoryId =  { 0x2000CF7E };   
       
    69 const TInt KNsmlDsOrphanEvent = 0xB ;
       
    70 
    65 
    71 // ============================ MEMBER FUNCTIONS ===============================
    66 // ============================ MEMBER FUNCTIONS ===============================
    72 
    67 
    73 // -----------------------------------------------------------------------------
    68 // -----------------------------------------------------------------------------
    74 // CNSmlDSCmds::CNSmlDSCmds()
    69 // CNSmlDSCmds::CNSmlDSCmds()
  1542 			{
  1537 			{
  1543 			iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand );
  1538 			iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand );
  1544 			iAgent->Interrupt( TNSmlError::ESmlAlertInvalid, EFalse, EFalse );
  1539 			iAgent->Interrupt( TNSmlError::ESmlAlertInvalid, EFalse, EFalse );
  1545 			return;
  1540 			return;
  1546 			}
  1541 			}
  1547 		
  1542 
  1548 		//Read min and max times
  1543 		// SyncmlNotifier Dependency is removed
  1549 		// MINDT 
       
  1550 		TInt mindt = AlertParameter( aAlert->itemList->item->data, KNSmlDSAgentMINDT );
       
  1551 		// MAXDT 
       
  1552 		TInt maxdt = AlertParameter( aAlert->itemList->item->data, KNSmlDSAgentMAXDT );
       
  1553 		
       
  1554 		HBufC* alertData = AlertDataLC( aAlert->itemList );
       
  1555 		
       
  1556 		//Fill notifier params
       
  1557 		TSyncMLDlgNotifParams params;
       
  1558 		params.iNoteType = ESyncMLInfoNote;
       
  1559 		params.iServerMsg = TBufC<KSyncMLMaxServerMsgLength>(alertData->Des());
       
  1560 		
       
  1561 		CleanupStack::PopAndDestroy(); //alertData
       
  1562 	
       
  1563 		//Pack data and start notifier	
       
  1564 		RNotifier notifier;
       
  1565 		User::LeaveIfError( notifier.Connect() );
       
  1566 		CleanupClosePushL(notifier);
       
  1567 		
       
  1568 		TPckgBuf<TBool> resBuf;
       
  1569 
       
  1570 		TRequestStatus status;
       
  1571 			
       
  1572 		TSyncMLDlgNotifParamsPckg data(params);
       
  1573    					
       
  1574 		notifier.StartNotifierAndGetResponse( status, KSyncMLDlgNotifierUid, data, resBuf );
       
  1575 		User::WaitForRequest(status);
       
  1576 		
       
  1577 		CleanupStack::PopAndDestroy(); //notifier, 
       
  1578 		
       
  1579 		return;
  1544 		return;
  1580 		}
  1545 		}
  1581 
  1546 
  1582 	// Target element
  1547 	// Target element
  1583 	if ( initAlert )
  1548 	if ( initAlert )
  1717 			}
  1682 			}
  1718 		StoreSyncType( alertCode );
  1683 		StoreSyncType( alertCode );
  1719 		}
  1684 		}
  1720 		
  1685 		
  1721 	// status 406 is returned if <Filter> is present BUT the session continues
  1686 	// status 406 is returned if <Filter> is present BUT the session continues
  1722 	if (  aAlert->itemList && aAlert->itemList->item )
  1687 	if ( aAlert->itemList->item )
  1723 	    {
  1688 	    {
  1724 	    if ( aAlert->itemList->item->target )
  1689 	    if ( aAlert->itemList->item->target )
  1725 	        {
  1690 	        {
  1726     	    if ( aAlert->itemList->item->target->filter )
  1691     	    if ( aAlert->itemList->item->target->filter )
  1727 	            {
  1692 	            {
  1958 	            {
  1923 	            {
  1959 	            iDSContent.SetServerItemCount( nocNum );
  1924 	            iDSContent.SetServerItemCount( nocNum );
  1960 	            }
  1925 	            }
  1961 			iDSObserver.OnSyncMLSyncProgress(
  1926 			iDSObserver.OnSyncMLSyncProgress(
  1962             	MSyncMLProgressObserver::ESmlReceivingModificationsFromServer,
  1927             	MSyncMLProgressObserver::ESmlReceivingModificationsFromServer,
  1963 	        	iDSContent.ServerItemCount(), 0 );
  1928 	        	iDSContent.ServerItemCount(), iDSContent.TaskId() );
  1964 			}
  1929 			}
  1965 
  1930 
  1966         // If number of changes is more than batch limit then batch is used if
  1931         // If number of changes is more than batch limit then batch is used if
  1967         // plug in adapter supports batch mode
  1932         // plug in adapter supports batch mode
  1968 	    if ( iDSContent.ServerItemCount() >= KNSmlBatchLimit && !iMoreData )
  1933 	    if ( iDSContent.ServerItemCount() >= KNSmlBatchLimit && !iMoreData )
  2488 	CleanupStack::PushL( devInf );
  2453 	CleanupStack::PushL( devInf );
  2489 	
  2454 	
  2490 	// VerDTD element
  2455 	// VerDTD element
  2491 	PcdataNewL ( devInf->verdtd, KNSmlAgentVerDTD12 );
  2456 	PcdataNewL ( devInf->verdtd, KNSmlAgentVerDTD12 );
  2492 
  2457 
       
  2458     TBool isOperator = EFalse;
       
  2459     TInt profileId( iAgent->ProfileId() );
       
  2460     CNSmlDSOperatorSettings* settings = CNSmlDSOperatorSettings::NewLC();
       
  2461 
       
  2462     CNSmlDSSettings* dsSettings = CNSmlDSSettings::NewLC();
       
  2463     CNSmlDSProfile* profile = dsSettings->ProfileL( profileId );
       
  2464 
       
  2465     if( profile )
       
  2466         {
       
  2467         CleanupStack::PushL( profile );
       
  2468         isOperator = settings->IsOperatorProfileL( 
       
  2469             profile->StrValue( EDSProfileServerId ) );
       
  2470         CleanupStack::PopAndDestroy( profile );
       
  2471         }
       
  2472     
  2493 	// Man element (manufacturer)
  2473 	// Man element (manufacturer)
  2494 	HBufC* manufacturer = HBufC::NewLC( 50 );
  2474 	HBufC* manufacturer = HBufC::NewLC( 50 );
  2495 	TPtr manufacturerPtr( manufacturer->Des() );
  2475 	TPtr manufacturerPtr( manufacturer->Des() );
  2496 	iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneManufacturer, manufacturerPtr );
       
  2497 	HBufC8* manufacturerInUTF8( NULL );
  2476 	HBufC8* manufacturerInUTF8( NULL );
  2498 	NSmlUnicodeConverter::HBufC8InUTF8LC( *manufacturer, manufacturerInUTF8 );
  2477     if ( isOperator )
       
  2478         {
       
  2479         manufacturerInUTF8 = settings->CustomManValueLC();
       
  2480         if ( manufacturerInUTF8->Length() == 0 )
       
  2481             {
       
  2482             CleanupStack::PopAndDestroy();// manufacturerInUTF8
       
  2483             iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneManufacturer, manufacturerPtr );
       
  2484             NSmlUnicodeConverter::HBufC8InUTF8LC( *manufacturer, manufacturerInUTF8 );
       
  2485             }
       
  2486         }
       
  2487     else
       
  2488         {
       
  2489         iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneManufacturer, manufacturerPtr );
       
  2490         NSmlUnicodeConverter::HBufC8InUTF8LC( *manufacturer, manufacturerInUTF8 );
       
  2491         }
  2499 	PcdataNewL ( devInf->man, *manufacturerInUTF8 );
  2492 	PcdataNewL ( devInf->man, *manufacturerInUTF8 );
  2500 	CleanupStack::PopAndDestroy( 2 ); // manufacturerInUTF8, manufacturer
  2493 	CleanupStack::PopAndDestroy( 2 ); // manufacturerInUTF8, manufacturer
  2501 	
  2494 	
  2502 	PcdataNewL ( devInf->fwv, KNullDesC8() );
  2495 	PcdataNewL ( devInf->fwv, KNullDesC8() );
  2503 	
  2496 	
  2504 	// Mod element (model name)
  2497 	// Mod element (model name)
  2505 	TBool isOperator = EFalse;
       
  2506 	TInt profileId( iAgent->ProfileId() );
       
  2507 	CNSmlDSSettings* settings = CNSmlDSSettings::NewLC();
       
  2508 	CNSmlDSProfile* profile = settings->ProfileL( profileId );
       
  2509 	
       
  2510 	if( profile )
       
  2511 	    {
       
  2512 	    CleanupStack::PushL( profile );
       
  2513 	    isOperator = settings->IsOperatorProfileL( 
       
  2514 	        profile->StrValue( EDSProfileServerId ) );
       
  2515 	    CleanupStack::PopAndDestroy( profile );
       
  2516 	    }
       
  2517 
       
  2518 	HBufC* model = HBufC::NewLC( 50 );
  2498 	HBufC* model = HBufC::NewLC( 50 );
  2519 	TPtr modelPtr = model->Des();
  2499 	TPtr modelPtr = model->Des();
  2520 	HBufC8* modelInUTF8 = NULL;
  2500 	HBufC8* modelInUTF8 = NULL;
  2521 	if ( isOperator )
  2501 	if ( isOperator )
  2522 	    {
  2502 	    {
  2523 	    modelInUTF8 = settings->OperatorProfileModValueLC();
  2503 	    modelInUTF8 = settings->CustomModValueLC();
  2524 	    if ( modelInUTF8->Length() == 0 )
  2504 	    if ( modelInUTF8->Length() == 0 )
  2525 	        {
  2505 	        {
  2526 	        CleanupStack::PopAndDestroy();// modelInUTF8
  2506 	        CleanupStack::PopAndDestroy();// modelInUTF8
  2527 	        iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneModelId, modelPtr );
  2507 	        iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneModelId, modelPtr );
  2528 	        NSmlUnicodeConverter::HBufC8InUTF8LC( *model, modelInUTF8 );
  2508 	        NSmlUnicodeConverter::HBufC8InUTF8LC( *model, modelInUTF8 );
  2536 	PcdataNewL ( devInf->mod, *modelInUTF8 );
  2516 	PcdataNewL ( devInf->mod, *modelInUTF8 );
  2537 	CleanupStack::PopAndDestroy( 2 );   // modelInUTF8, model
  2517 	CleanupStack::PopAndDestroy( 2 );   // modelInUTF8, model
  2538 	// SwV element (software version)
  2518 	// SwV element (software version)
  2539 	if ( isOperator )
  2519 	if ( isOperator )
  2540 	    {
  2520 	    {
  2541 	    HBufC8* swv = settings->OperatorProfileSWVValueLC();
  2521 	    HBufC8* swv = settings->CustomSwvValueLC();
  2542 	    if ( swv->Length() > 0 )
  2522 	    if ( swv->Length() > 0 )
  2543 	        {
  2523 	        {
  2544 	        PcdataNewL ( devInf->swv, *swv );
  2524 	        PcdataNewL ( devInf->swv, *swv );
  2545 	        }
  2525 	        }
  2546 	    else
  2526 	    else
  2552 	else
  2532 	else
  2553 	    {
  2533 	    {
  2554 	    PcdataNewL ( devInf->swv, iPhoneInfo->SwVersionL() );
  2534 	    PcdataNewL ( devInf->swv, iPhoneInfo->SwVersionL() );
  2555 	    }
  2535 	    }
  2556 
  2536 
  2557 	CleanupStack::PopAndDestroy( settings );
  2537 	CleanupStack::PopAndDestroy( 2, settings );
  2558 
  2538 
  2559 	PcdataNewL ( devInf->hwv, KNullDesC8() );
  2539 	PcdataNewL ( devInf->hwv, KNullDesC8() );
  2560 
  2540 
  2561 	// DevId element  
  2541 	// DevId element  
  2562 	HBufC* devId = HBufC::NewLC( 50 );
  2542 	HBufC* devId = HBufC::NewLC( 50 );
  2581 	devInf->flags += SmlUTC_f;
  2561 	devInf->flags += SmlUTC_f;
  2582 
  2562 
  2583 	// DataStore elements
  2563 	// DataStore elements
  2584 	SmlDevInfDatastoreList_t** currDatastorePtr = &devInf->datastore;
  2564 	SmlDevInfDatastoreList_t** currDatastorePtr = &devInf->datastore;
  2585 
  2565 
  2586     // Operator DevInf ext fields enabler : START
  2566 	// Operator specific Device info extensions (XNam, XVal)
  2587     InsertOperatorExtensionDevInfFieldsL( devInf );
  2567 	if( isOperator )
  2588     // Operator DevInf ext fields enabler : END
  2568 		{
  2589 	
  2569 		TRAPD( err, InsertOperatorExtensionDevInfFieldsL( devInf ) );
       
  2570 		if( err != KErrNone )
       
  2571 			{
       
  2572 			DBG_FILE( _S8( "CNSmlDSCmds::DoDeviceInfoL(): Leave in InsertOperatorExtensionDevInfFieldsL()" ) );
       
  2573 			DBG_FILE_CODE( err, _S8("Error code") );
       
  2574 			}
       
  2575 		}
       
  2576 
  2590     iDSContent.SetToFirst();
  2577     iDSContent.SetToFirst();
  2591 
  2578 
  2592 	do
  2579 	do
  2593 		{
  2580 		{
  2594 		if ( iDSContent.Interrupted() )
  2581 		if ( iDSContent.Interrupted() )
  3618 							iBatchBuffer->Increase();
  3605 							iBatchBuffer->Increase();
  3619 							}
  3606 							}
  3620 						}
  3607 						}
  3621 						
  3608 						
  3622 					iItemOpened = EFalse;
  3609 					iItemOpened = EFalse;
  3623 					SmlStatus_t* status = NULL;
  3610 					
  3624 					SmlItemList_t** itemList;
       
  3625 					CRepository* rep = NULL;
       
  3626 					switch ( returnCode )
  3611 					switch ( returnCode )
  3627 						{
  3612 						{
  3628 						case KErrNone:
  3613 						case KErrNone:
  3629 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusItemAdded );
  3614 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusItemAdded );
  3630 
  3615 
  3655 							break;
  3640 							break;
  3656 							
  3641 							
  3657 						case KErrNotSupported:
  3642 						case KErrNotSupported:
  3658 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat );
  3643 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat );
  3659 							break;
  3644 							break;
  3660 							
       
  3661 						case KErrPathNotFound:			
       
  3662 						    // Read the Orphan Event ID from the cenrep
       
  3663 						    rep = CRepository::NewLC(KRepositoryId);
       
  3664                             TRAPD( err, rep->Get(KNsmlDsOrphanEvent, iNewUid) );
       
  3665                             DBG_ARGS(_S("read the cenrep %d %d"), err, iNewUid);
       
  3666                             User::LeaveIfError(err);
       
  3667                             CleanupStack::PopAndDestroy(rep);
       
  3668 							
       
  3669 						    _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : Invalid Parent"));
       
  3670 						    statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusMovedPermanently );
       
  3671 						    DBG_ARGS(_S("Invalid parent: statusid %d"), statusId);
       
  3672 						    status = iStatusToServer->StatusItem( statusId );
       
  3673 						    DBG_ARGS(_S("Invalid parent: status %d"), status);
       
  3674 						    if( status )
       
  3675                                 {
       
  3676                                 SmlItemList_t* newItemList = new( ELeave ) SmlItemList_t;
       
  3677                                 _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : creating a new item"));
       
  3678                                 newItemList->item = new( ELeave ) SmlItem_t;
       
  3679                                 _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : creating a new data"));
       
  3680                                 iStatusToServer->FillItemDataL( newItemList->item );
       
  3681                                 _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : updating"));
       
  3682                                 
       
  3683                                 itemList = &(status->itemList);
       
  3684                                 while ( *itemList )
       
  3685                                     {
       
  3686                                     itemList = &(*itemList)->next;
       
  3687                                     }
       
  3688                                 *itemList = newItemList;
       
  3689                                 _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : updated"));
       
  3690                                 }
       
  3691 						    if ( !iBatchModeOn )
       
  3692                                 {
       
  3693                                 iDSContent.IncreaseServerItemsAdded();
       
  3694                                 clientModifications.iNumAdded = 1;
       
  3695                                 
       
  3696                                 if ( !iAtomicModeOn )
       
  3697                                     {
       
  3698                                     iDSContent.CreateNewMapItemL( iNewUid, aUID, 0 );
       
  3699                                     }
       
  3700                                 else
       
  3701                                     {
       
  3702                                     iDSContent.CreateNewMapItemL( iNewUid, aUID, iAtomicId );
       
  3703                                     }
       
  3704                                 }
       
  3705                             else
       
  3706                                 {
       
  3707                                 clientModifications.iNumAdded = 1;
       
  3708                                 iBatchBuffer->SetStatusEntryId( statusId );
       
  3709                                 }
       
  3710 						    break;
       
  3711 							
  3645 							
  3712 						default:
  3646 						default:
  3713 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed );
  3647 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed );
  3714 							break;
  3648 							break;
  3715 						}
  3649 						}
  3863 							break;
  3797 							break;
  3864 							
  3798 							
  3865 						case KErrNotSupported:
  3799 						case KErrNotSupported:
  3866 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat );
  3800 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat );
  3867 							break;
  3801 							break;
  3868 							
       
  3869 						case KErrPathNotFound:
       
  3870 						    _DBG_FILE(_S8("CNSmlDSCmds:: REPLACE UpdateL : Invalid Parent"));
       
  3871 						    statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusMovedPermanently );
       
  3872 						    break;
       
  3873 							
  3802 							
  3874 						default:
  3803 						default:
  3875 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed );
  3804 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed );
  3876 							break;
  3805 							break;
  3877 						}
  3806 						}
  4760 	aNumericUid = KNullDataItemId;
  4689 	aNumericUid = KNullDataItemId;
  4761 
  4690 
  4762 	return lexer.Val( aNumericUid );
  4691 	return lexer.Val( aNumericUid );
  4763 	}
  4692 	}
  4764 
  4693 
  4765 // -----------------------------------------------------------------------------
       
  4766 // CNSmlDSCmds::InsertOperatorExtensionDevInfFieldsL
       
  4767 // Adds operator specific extension DevInf fields <XNam> and <XVal>
       
  4768 // Currently only one <XNam> and one corresponding <XVal> field is supported
       
  4769 // -----------------------------------------------------------------------------
       
  4770 //
       
  4771 void CNSmlDSCmds::InsertOperatorExtensionDevInfFieldsL(SmlDevInfDevInfPtr_t& aDevInf)
       
  4772     {
       
  4773     TInt error = KErrNotFound;
       
  4774     CRepository *operatorSettingsCenrep = NULL;
       
  4775     
       
  4776     // TRAP the creation of operator cenrep handle, because we don't want to 
       
  4777     // leave if the cenrep is not present
       
  4778     TRAP( error, operatorSettingsCenrep = CRepository::NewL( KNsmlOperatorCenrepUID ));
       
  4779     if( error != KErrNone )
       
  4780         {
       
  4781         // operator cenrep not found
       
  4782         return;
       
  4783         }
       
  4784     else
       
  4785         {
       
  4786         CleanupStack::PushL( operatorSettingsCenrep );
       
  4787 
       
  4788         // get the server id from the current profile
       
  4789         TInt profileId( iAgent->ProfileId() );
       
  4790         CNSmlDSSettings* dsSettings = CNSmlDSSettings::NewLC();
       
  4791         CNSmlDSProfile* profile = NULL;
       
  4792         TRAP( error, profile = dsSettings->ProfileL( profileId ) );
       
  4793         
       
  4794         if( error != KErrNone || !profile )
       
  4795             {
       
  4796             // if there was an error in reading profile from the profile ID
       
  4797             // return do not proceed to change the DevInf
       
  4798             CleanupStack::PopAndDestroy( dsSettings );
       
  4799             CleanupStack::PopAndDestroy( operatorSettingsCenrep );
       
  4800             return; 
       
  4801             }
       
  4802         
       
  4803         HBufC* buffSerVerId = HBufC::NewLC( KMaxLength );
       
  4804         TPtr ptrCurrentServerId = buffSerVerId->Des();
       
  4805         ptrCurrentServerId.Copy( profile->StrValue( EDSProfileServerId ) );
       
  4806         
       
  4807         // get the server id from operator cenrep
       
  4808         HBufC* buffCenrepServerId = HBufC::NewLC( KMaxLength );
       
  4809         TPtr ptrCenrepServerId = buffCenrepServerId->Des();        
       
  4810         error = operatorSettingsCenrep->Get( KNsmlOperatorProfileServerId, ptrCenrepServerId);
       
  4811         
       
  4812         // if serverID read from operator cenrep and current profile match only then attempt to
       
  4813         // add devInf extension fields
       
  4814         if( error == KErrNone && ptrCenrepServerId.Compare( ptrCurrentServerId ) == 0 )
       
  4815             {
       
  4816             // create 16-bit buffers to read XNam and XVal field values from cenrep
       
  4817             HBufC* buffXNamField = HBufC::NewLC( KMaxLength );
       
  4818             HBufC* buffXValField = HBufC::NewLC( KMaxLength );
       
  4819             TPtr xNamField = buffXNamField->Des();
       
  4820             TPtr xValField = buffXValField->Des();            
       
  4821         
       
  4822             TInt keyErrorXNam = operatorSettingsCenrep->Get( KNsmlOperatorDevInfExtXNam, xNamField );
       
  4823             TInt keyErrorXVal = operatorSettingsCenrep->Get( KNsmlOperatorDevInfExtXVal, xValField );
       
  4824                 
       
  4825             if( keyErrorXNam == KErrNone && keyErrorXVal == KErrNone &&
       
  4826                 xNamField.Length() > 0 && xValField.Length() > 0 )
       
  4827                 {
       
  4828                 // create 8-bit buffers of exact necessary length
       
  4829                 // to write extn. fields in dev-inf
       
  4830                 HBufC8* buffXNam = HBufC8::NewLC( xNamField.Length() );
       
  4831                 HBufC8* buffXVal = HBufC8::NewLC( xValField.Length() );
       
  4832 
       
  4833                 TPtr8 xnam = buffXNam->Des();
       
  4834                 TPtr8 xval = buffXVal->Des();
       
  4835 
       
  4836                 // copy extn fields from 16-bit desc. to 8-bit desc.
       
  4837                 xnam.Copy( xNamField );
       
  4838                 xval.Copy( xValField );
       
  4839     
       
  4840                 SmlPcdataPtr_t XNamData;
       
  4841                 PcdataNewL( XNamData, xnam );
       
  4842     
       
  4843                 SmlPcdataPtr_t XValData;
       
  4844                 PcdataNewL( XValData, xval );
       
  4845     
       
  4846                 SmlPcdataListPtr_t listPtr = new (ELeave) SmlPcdataList_t;
       
  4847                 listPtr->data = XValData;
       
  4848                 listPtr->next = NULL;
       
  4849     
       
  4850                 SmlDevInfExtPtr_t extElementPtr = new (ELeave) SmlDevInfExt_t;
       
  4851                 extElementPtr->xnam = XNamData;
       
  4852                 extElementPtr->xval = listPtr; 
       
  4853     
       
  4854                 SmlDevInfExtListPtr_t extListPtr = new (ELeave) SmlDevInfExtList_t;
       
  4855                 extListPtr->data = extElementPtr;
       
  4856                 extListPtr->next = NULL;
       
  4857     
       
  4858                 aDevInf->ext = extListPtr;
       
  4859     
       
  4860                 CleanupStack::PopAndDestroy( buffXVal );
       
  4861                 CleanupStack::PopAndDestroy( buffXNam );
       
  4862                 }
       
  4863             CleanupStack::PopAndDestroy( buffXValField );
       
  4864             CleanupStack::PopAndDestroy( buffXNamField );     
       
  4865             }
       
  4866 
       
  4867         CleanupStack::PopAndDestroy( buffCenrepServerId );   
       
  4868         CleanupStack::PopAndDestroy( buffSerVerId );
       
  4869         CleanupStack::PopAndDestroy( dsSettings );
       
  4870         CleanupStack::PopAndDestroy( operatorSettingsCenrep );
       
  4871         }
       
  4872     }
       
  4873 
       
  4874 //-----------------------------------------------------------------------------
  4694 //-----------------------------------------------------------------------------
  4875 // CNSmlDSCmds::StoreSyncType
  4695 // CNSmlDSCmds::StoreSyncType
  4876 // Checks if received Alert Code is a sync type and tries to convert
  4696 // Checks if received Alert Code is a sync type and tries to convert
  4877 // it to Sync Type (TSmlSyncType).
  4697 // it to Sync Type (TSmlSyncType).
  4878 //-----------------------------------------------------------------------------
  4698 //-----------------------------------------------------------------------------
  4915             rep->Set( KNsmlOpDsSyncType, syncType );
  4735             rep->Set( KNsmlOpDsSyncType, syncType );
  4916             delete rep;
  4736             delete rep;
  4917             }
  4737             }
  4918         }
  4738         }
  4919     }
  4739     }
       
  4740 
       
  4741 // ----------------------------------------------------------------------------
       
  4742 // CNSmlDSCmds::InsertOperatorExtensionDevInfFieldsL
       
  4743 // Adds operator specific extension fields <XNam> and <XVal> to Device info
       
  4744 // ----------------------------------------------------------------------------
       
  4745 //
       
  4746 void CNSmlDSCmds::InsertOperatorExtensionDevInfFieldsL( 
       
  4747     SmlDevInfDevInfPtr_t& aDevInf )
       
  4748     {
       
  4749     // Instantiate Extension Data container ECom plugin 
       
  4750     CNSmlDevInfExtDataContainerPlugin* extensionPlugin = NULL;
       
  4751     TRAPD( err, extensionPlugin = CNSmlDevInfExtDataContainerPlugin::NewL() );
       
  4752     if( err == KErrNone )
       
  4753         {
       
  4754         CleanupStack::PushL( extensionPlugin );
       
  4755 
       
  4756         if( extensionPlugin->GetExtensionCountL() > 0 )
       
  4757             {
       
  4758             // Create a list for extensions
       
  4759             SmlDevInfExtListPtr_t extList = new ( ELeave ) SmlDevInfExtList_t;
       
  4760             CleanupStack::PushL( extList );
       
  4761             extList->data = NULL;
       
  4762             extList->next = NULL;
       
  4763 
       
  4764             for( TInt i = 0; i < extensionPlugin->GetExtensionCountL(); i++ )
       
  4765                 {
       
  4766                 // Create new <Ext> element and insert it to extension list
       
  4767                 SmlDevInfExtPtr_t extElement = new ( ELeave ) SmlDevInfExt_t;
       
  4768                 CleanupStack::PushL( extElement );
       
  4769 
       
  4770                 // Handle <XNam>
       
  4771                 PcdataNewL( extElement->xnam, extensionPlugin->GetExtNameL( i ) );
       
  4772 
       
  4773                 // Handle <XVal>
       
  4774                 if( extensionPlugin->GetExtValueCountL( i ) > 0 )
       
  4775                     {
       
  4776                     SmlPcdataListPtr_t xValList = new ( ELeave ) SmlPcdataList_t;
       
  4777                     CleanupStack::PushL( xValList );
       
  4778                     xValList->data = NULL;
       
  4779                     xValList->next = NULL;
       
  4780 
       
  4781                     for( TInt j = 0; j < extensionPlugin->GetExtValueCountL( i ); j++ )
       
  4782                         {
       
  4783                         AppendToXValListL( xValList, 
       
  4784                             extensionPlugin->GetExtValueL( i, j ) );
       
  4785                         }
       
  4786                     extElement->xval = xValList;
       
  4787                     CleanupStack::Pop( xValList );
       
  4788                     }
       
  4789                 else
       
  4790                     {
       
  4791                     extElement->xval = NULL;
       
  4792                     }
       
  4793                 AppendToExtensionListL( extList, extElement );
       
  4794                 CleanupStack::Pop( extElement );
       
  4795                 }
       
  4796 
       
  4797             // Add extensions as a part of DevInfo structure
       
  4798             aDevInf->ext = extList;
       
  4799             CleanupStack::Pop( extList );
       
  4800             }
       
  4801 
       
  4802         // Do the cleanup
       
  4803         CleanupStack::PopAndDestroy( extensionPlugin );
       
  4804         REComSession::FinalClose();
       
  4805         }
       
  4806     }
       
  4807 
       
  4808 // ----------------------------------------------------------------------------
       
  4809 // CNSmlDSCmds::AppendToExtensionListL
       
  4810 // ----------------------------------------------------------------------------
       
  4811 //
       
  4812 void CNSmlDSCmds::AppendToExtensionListL( SmlDevInfExtListPtr_t aExtList, 
       
  4813     SmlDevInfExtPtr_t aExtItem )
       
  4814     {
       
  4815     if( !aExtList->data )
       
  4816         {
       
  4817         // This is the first item to be added to the list
       
  4818         aExtList->data = aExtItem;
       
  4819         aExtList->next = NULL;
       
  4820         }
       
  4821     else
       
  4822         {
       
  4823         // List is not empty
       
  4824         SmlDevInfExtListPtr_t newExtListItem = new ( ELeave ) SmlDevInfExtList_t;
       
  4825         newExtListItem->data = aExtItem;
       
  4826         newExtListItem->next = NULL;
       
  4827     
       
  4828         // Search the end of the extension list & add new item
       
  4829         SmlDevInfExtListPtr_t tmp = aExtList;
       
  4830         while( tmp->next )
       
  4831             {
       
  4832             tmp = tmp->next;
       
  4833             }
       
  4834         tmp->next = newExtListItem;
       
  4835         }
       
  4836     }
       
  4837 
       
  4838 // ----------------------------------------------------------------------------
       
  4839 // CNSmlDSCmds::AppendToXValListL
       
  4840 // ----------------------------------------------------------------------------
       
  4841 //
       
  4842 void CNSmlDSCmds::AppendToXValListL( SmlPcdataListPtr_t aXValList,
       
  4843     const TDesC8& aXVal )
       
  4844     {
       
  4845     if( !aXValList->data )
       
  4846         {
       
  4847         // This is the first item to be added to the list
       
  4848         PcdataNewL( aXValList->data, aXVal );
       
  4849         aXValList->next = NULL;
       
  4850         }
       
  4851     else
       
  4852         {
       
  4853         // List is not empty
       
  4854         SmlPcdataListPtr_t newXValItem = new ( ELeave ) SmlPcdataList_t;
       
  4855         CleanupStack::PushL( newXValItem );
       
  4856         PcdataNewL( newXValItem->data, aXVal );
       
  4857         CleanupStack::Pop( newXValItem );
       
  4858         newXValItem->next = NULL;
       
  4859     
       
  4860         // Search the end of the extension list & add new item
       
  4861         SmlPcdataListPtr_t tmp = aXValList;
       
  4862         while( tmp->next )
       
  4863             {
       
  4864             tmp = tmp->next;
       
  4865             }
       
  4866         tmp->next = newXValItem;
       
  4867         }
       
  4868     }
       
  4869 
  4920 // End of File
  4870 // End of File