syncmlfw/ds/syncagent/src/nsmldscmds.cpp
changeset 63 e0c1916b8ddc
parent 57 f5b689a4f7a2
equal deleted inserted replaced
57:f5b689a4f7a2 63:e0c1916b8ddc
    44 #include "nsmldscontent.h"
    44 #include "nsmldscontent.h"
    45 #include "NSmlDSAgent.h"
    45 #include "NSmlDSAgent.h"
    46 #include "nsmldserror.h"
    46 #include "nsmldserror.h"
    47 #include "nsmlfilter.h"
    47 #include "nsmlfilter.h"
    48 #include "nsmldssettings.h"
    48 #include "nsmldssettings.h"
       
    49 #include "nsmldsoperatorsettings.h"
    49 #include "nsmldsbatchbuffer.h"
    50 #include "nsmldsbatchbuffer.h"
    50 #include "nsmldshostclient.h"
    51 #include "nsmldshostclient.h"
    51 
    52 #include <nsmloperatorerrorcrkeys.h> // KCRUidOperatorDatasyncErrorKeys
       
    53 #include <nsmldevinfextdatacontainerplugin.h>
    52 
    54 
    53 #ifndef __WINS__
    55 #ifndef __WINS__
    54 // This lowers the unnecessary compiler warning (armv5) to remark.
    56 // This lowers the unnecessary compiler warning (armv5) to remark.
    55 // "Warning:  #174-D: expression has no effect..." is caused by 
    57 // "Warning:  #174-D: expression has no effect..." is caused by 
    56 // DBG_ARGS8 macro in no-debug builds.
    58 // DBG_ARGS8 macro in no-debug builds.
  1676 					SwitchAlertCode( alertCode );
  1678 					SwitchAlertCode( alertCode );
  1677 					iDSContent.SetSyncTypeL( alertCode );
  1679 					iDSContent.SetSyncTypeL( alertCode );
  1678 					}
  1680 					}
  1679 				}
  1681 				}
  1680 			}
  1682 			}
       
  1683 		StoreSyncType( alertCode );
  1681 		}
  1684 		}
  1682 		
  1685 		
  1683 	// 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
  1684 	if ( aAlert->itemList->item )
  1687 	if ( aAlert->itemList->item )
  1685 	    {
  1688 	    {
  2450 	CleanupStack::PushL( devInf );
  2453 	CleanupStack::PushL( devInf );
  2451 	
  2454 	
  2452 	// VerDTD element
  2455 	// VerDTD element
  2453 	PcdataNewL ( devInf->verdtd, KNSmlAgentVerDTD12 );
  2456 	PcdataNewL ( devInf->verdtd, KNSmlAgentVerDTD12 );
  2454 
  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     
  2455 	// Man element (manufacturer)
  2473 	// Man element (manufacturer)
  2456 	HBufC* manufacturer = HBufC::NewLC( 50 );
  2474 	HBufC* manufacturer = HBufC::NewLC( 50 );
  2457 	TPtr manufacturerPtr( manufacturer->Des() );
  2475 	TPtr manufacturerPtr( manufacturer->Des() );
  2458 	iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneManufacturer, manufacturerPtr );
       
  2459 	HBufC8* manufacturerInUTF8( NULL );
  2476 	HBufC8* manufacturerInUTF8( NULL );
  2460 	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         }
  2461 	PcdataNewL ( devInf->man, *manufacturerInUTF8 );
  2492 	PcdataNewL ( devInf->man, *manufacturerInUTF8 );
  2462 	CleanupStack::PopAndDestroy( 2 ); // manufacturerInUTF8, manufacturer
  2493 	CleanupStack::PopAndDestroy( 2 ); // manufacturerInUTF8, manufacturer
  2463 	
  2494 	
  2464 	PcdataNewL ( devInf->fwv, KNullDesC8() );
  2495 	PcdataNewL ( devInf->fwv, KNullDesC8() );
  2465 	
  2496 	
  2466 	// Mod element (model name)
  2497 	// Mod element (model name)
  2467 	HBufC* model = HBufC::NewLC( 50 );
  2498 	HBufC* model = HBufC::NewLC( 50 );
  2468 	TPtr modelPtr = model->Des();  
  2499 	TPtr modelPtr = model->Des();
  2469 	iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneModelId, modelPtr );
       
  2470 	HBufC8* modelInUTF8 = NULL;
  2500 	HBufC8* modelInUTF8 = NULL;
  2471 	NSmlUnicodeConverter::HBufC8InUTF8LC( *model, modelInUTF8 );
  2501 	if ( isOperator )
       
  2502 	    {
       
  2503 	    modelInUTF8 = settings->CustomModValueLC();
       
  2504 	    if ( modelInUTF8->Length() == 0 )
       
  2505 	        {
       
  2506 	        CleanupStack::PopAndDestroy();// modelInUTF8
       
  2507 	        iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneModelId, modelPtr );
       
  2508 	        NSmlUnicodeConverter::HBufC8InUTF8LC( *model, modelInUTF8 );
       
  2509 	        }
       
  2510 	    }
       
  2511 	else
       
  2512 	    {
       
  2513 	    iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneModelId, modelPtr );
       
  2514 	    NSmlUnicodeConverter::HBufC8InUTF8LC( *model, modelInUTF8 );
       
  2515 	    }
  2472 	PcdataNewL ( devInf->mod, *modelInUTF8 );
  2516 	PcdataNewL ( devInf->mod, *modelInUTF8 );
  2473 	CleanupStack::PopAndDestroy( 2 );   // modelInUTF8, model
  2517 	CleanupStack::PopAndDestroy( 2 );   // modelInUTF8, model
  2474 	// SwV element (software version)
  2518 	// SwV element (software version)
  2475 	PcdataNewL ( devInf->swv, iPhoneInfo->SwVersionL() );
  2519 	if ( isOperator )
       
  2520 	    {
       
  2521 	    HBufC8* swv = settings->CustomSwvValueLC();
       
  2522 	    if ( swv->Length() > 0 )
       
  2523 	        {
       
  2524 	        PcdataNewL ( devInf->swv, *swv );
       
  2525 	        }
       
  2526 	    else
       
  2527 	        {
       
  2528 	        PcdataNewL ( devInf->swv, iPhoneInfo->SwVersionL() );
       
  2529 	        }
       
  2530 	    CleanupStack::PopAndDestroy( swv );
       
  2531 	    }
       
  2532 	else
       
  2533 	    {
       
  2534 	    PcdataNewL ( devInf->swv, iPhoneInfo->SwVersionL() );
       
  2535 	    }
       
  2536 
       
  2537 	CleanupStack::PopAndDestroy( 2, settings );
  2476 
  2538 
  2477 	PcdataNewL ( devInf->hwv, KNullDesC8() );
  2539 	PcdataNewL ( devInf->hwv, KNullDesC8() );
  2478 
  2540 
  2479 	// DevId element  
  2541 	// DevId element  
  2480 	HBufC* devId = HBufC::NewLC( 50 );
  2542 	HBufC* devId = HBufC::NewLC( 50 );
  2498 	// SupportUTC element
  2560 	// SupportUTC element
  2499 	devInf->flags += SmlUTC_f;
  2561 	devInf->flags += SmlUTC_f;
  2500 
  2562 
  2501 	// DataStore elements
  2563 	// DataStore elements
  2502 	SmlDevInfDatastoreList_t** currDatastorePtr = &devInf->datastore;
  2564 	SmlDevInfDatastoreList_t** currDatastorePtr = &devInf->datastore;
       
  2565 
       
  2566 	// Operator specific Device info extensions (XNam, XVal)
       
  2567 	if( isOperator )
       
  2568 		{
       
  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 		}
  2503 
  2576 
  2504     iDSContent.SetToFirst();
  2577     iDSContent.SetToFirst();
  2505 
  2578 
  2506 	do
  2579 	do
  2507 		{
  2580 		{
  4616 	aNumericUid = KNullDataItemId;
  4689 	aNumericUid = KNullDataItemId;
  4617 
  4690 
  4618 	return lexer.Val( aNumericUid );
  4691 	return lexer.Val( aNumericUid );
  4619 	}
  4692 	}
  4620 
  4693 
       
  4694 //-----------------------------------------------------------------------------
       
  4695 // CNSmlDSCmds::StoreSyncType
       
  4696 // Checks if received Alert Code is a sync type and tries to convert
       
  4697 // it to Sync Type (TSmlSyncType).
       
  4698 //-----------------------------------------------------------------------------
       
  4699 //
       
  4700 void CNSmlDSCmds::StoreSyncType( const TDes8& aAlertCode )
       
  4701     {
       
  4702     TInt syncType = KErrNotFound;
       
  4703 
       
  4704     if ( aAlertCode == KNSmlDSTwoWay )
       
  4705         {
       
  4706         syncType = ESmlTwoWay;
       
  4707         }
       
  4708     else if ( aAlertCode == KNSmlDSOneWayFromServer )
       
  4709         {
       
  4710         syncType = ESmlOneWayFromServer;
       
  4711         }
       
  4712     else if ( aAlertCode == KNSmlDSOneWayFromClient )
       
  4713         {
       
  4714         syncType = ESmlOneWayFromClient;
       
  4715         }
       
  4716     else if ( aAlertCode == KNSmlDSSlowSync )
       
  4717         {
       
  4718         syncType = ESmlSlowSync;
       
  4719         }
       
  4720     else if ( aAlertCode == KNSmlDSRefreshFromServer )
       
  4721         {
       
  4722         syncType = ESmlRefreshFromServer;
       
  4723         }
       
  4724     else if ( aAlertCode == KNSmlDSRefreshFromClient )
       
  4725         {
       
  4726         syncType = ESmlRefreshFromClient;
       
  4727         }
       
  4728 
       
  4729     if ( syncType != KErrNotFound )
       
  4730         {
       
  4731         CRepository* rep = NULL;
       
  4732         TRAPD ( err, rep = CRepository::NewL( KCRUidOperatorDatasyncErrorKeys ) );
       
  4733         if ( err == KErrNone )
       
  4734             {
       
  4735             rep->Set( KNsmlOpDsSyncType, syncType );
       
  4736             delete rep;
       
  4737             }
       
  4738         }
       
  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 
  4621 // End of File
  4870 // End of File