syncmlfw/dm/syncagent/src/nsmldmcmds.cpp
branchRCL_3
changeset 62 19bba8228ff0
parent 61 b183ec05bd8c
child 76 3cdbd92ee07b
equal deleted inserted replaced
61:b183ec05bd8c 62:19bba8228ff0
    23 #include <utf.h>
    23 #include <utf.h>
    24 // FOTA
    24 // FOTA
    25 #include <DevManInternalCRKeys.h>
    25 #include <DevManInternalCRKeys.h>
    26 #include <featmgr.h>
    26 #include <featmgr.h>
    27 // FOTA end
    27 // FOTA end
    28 #include <devicedialogsymbian.h>
    28 #include <SyncMLNotifierParams.h>
    29 
    29 
    30 #include <nsmlconstants.h>
    30 #include <nsmlconstants.h>
    31 #include <nsmldebug.h>
    31 #include <nsmldebug.h>
    32 #include <nsmlphoneinfo.h>
    32 #include <nsmlphoneinfo.h>
    33 #include <nsmlunicodeconverter.h>
    33 #include <nsmlunicodeconverter.h>
    52 #include "WBXMLGeneratorError.h"
    52 #include "WBXMLGeneratorError.h"
    53 #include "WBXMLParser.h"
    53 #include "WBXMLParser.h"
    54 #include "smldtd.h"
    54 #include "smldtd.h"
    55 #include "smldef.h"
    55 #include "smldef.h"
    56 #include "nsmlagenttestdefines.h"
    56 #include "nsmlagenttestdefines.h"
    57 #include <hbdevicedialogsymbian.h>
       
    58 #include <hbsymbianvariant.h>
       
    59 // DM specific includes
    57 // DM specific includes
    60 #include "nsmldmagconstants.h"
    58 #include "nsmldmagconstants.h"
    61 #include "NSmlDMCmds.h"
    59 #include "NSmlDMCmds.h"
    62 #include "nsmldmerror.h"
    60 #include "nsmldmerror.h"
    63 #include <dmdevdialogclient.h>
       
    64 #include "OnlineSupportLogger.h"
       
    65 #ifdef __TEST_TREEMODULE
    61 #ifdef __TEST_TREEMODULE
    66 #include "nsmldmtestmodule.h"
    62 #include "nsmldmtestmodule.h"
    67 #else
    63 #else
    68 #include <nsmldmmodule.h>
    64 #include <nsmldmmodule.h>
    69 #endif
    65 #endif
    75 // DBG_ARGS8 macro in no-debug builds.
    71 // DBG_ARGS8 macro in no-debug builds.
    76 #pragma diag_remark 174
    72 #pragma diag_remark 174
    77 #endif
    73 #endif
    78 
    74 
    79 
    75 
    80 //const TUid KNSmlSyncDialogUid = { 0x101F876A };
    76 const TUid KNSmlSyncDialogUid = { 0x101F876A };
    81 // FOTA
    77 // FOTA
    82 const TInt KNSmlDmNoRequest = -1;
    78 const TInt KNSmlDmNoRequest = -1;
    83 // FOTA end
    79 // FOTA end
       
    80 const TInt KNSmlDmChoiceChunkMinSize = 32;
       
    81 const TInt KNSmlDmChoiceChunkMaxSize = 10000;
    84 
    82 
    85 _LIT8 ( KNSmlDMMetaTypeUserRequest, "org.openmobilealliance.dm.firmwareupdate.userrequest" );
    83 _LIT8 ( KNSmlDMMetaTypeUserRequest, "org.openmobilealliance.dm.firmwareupdate.userrequest" );
    86 _LIT8 ( KNSmlDMMetaFormatUserRequest, "chr" );
    84 _LIT8 ( KNSmlDMMetaFormatUserRequest, "chr" );
    87 
    85 _LIT(KChunkName,"AlertItems");
    88 const TUid dmagentuid =
    86 
    89             {
       
    90             0x101F6DE5
       
    91             };
       
    92 
       
    93 
       
    94 
       
    95 enum TSyncmlHbNotifierKeys 
       
    96 		{
       
    97 
       
    98      EHbSOSNotifierKeyStatus = 11, // status set will complete the client subscribe
       
    99      EHbSOSNotifierKeyStatusReturn = 12, // Return the content of actual status value accepted from UI
       
   100      
       
   101      EHbDMSyncNotifierKeyStatus = 13,
       
   102      EHbDMSyncNotifierKeyStatusReturn = 14
       
   103 		};
       
   104 
    87 
   105 // ---------------------------------------------------------
    88 // ---------------------------------------------------------
   106 // CNSmlDMCmds::NewL()
    89 // CNSmlDMCmds::NewL()
   107 // Creates new instance of CNSmlDMCmds 
    90 // Creates new instance of CNSmlDMCmds 
   108 // Does not leave instance pointer to CleanupStack.
    91 // Does not leave instance pointer to CleanupStack.
   321 			}
   304 			}
   322 		}
   305 		}
   323 	return valueNum; 
   306 	return valueNum; 
   324 	}
   307 	}
   325 
   308 
       
   309 //#ifdef RD_DM_TEXT_INPUT_ALERT
       
   310 // ---------------------------------------------------------
       
   311 // CNSmlDMCmds::AlertInputTypeParameter()
       
   312 // For 1102-User Input server alert
       
   313 // For Input Type optional parameter
       
   314 // ---------------------------------------------------------
       
   315 TInt CNSmlDMCmds::AlertInputTypeParameter( const SmlPcdata_t* aData, const TDesC8& aParamID ) const
       
   316 	{
       
   317 	_DBG_FILE("CNSmlDMCmds::AlertInputTypeParameter: begin");
       
   318 	TInt valueNum = 0;//alphanumeric by default
       
   319 	if ( aData )
       
   320 		{
       
   321 		if ( aData->content )
       
   322 			{
       
   323 			TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length );
       
   324 			TrimRightSpaceAndNull( parameters );
       
   325 			TInt startPos = parameters.Find( aParamID );
       
   326 			if ( startPos >= 0 )
       
   327 				{
       
   328 				if ( parameters.Length() > startPos + aParamID.Length() )
       
   329 					{
       
   330 					TPtrC8 strPart = parameters.Right( parameters.Length() - ( startPos + aParamID.Length() ) );
       
   331 					TInt length = 0;
       
   332 					TChar character = strPart[length];
       
   333 						
       
   334 						switch( character )
       
   335 						{
       
   336 							case 'A': //Alphanumeric
       
   337 							 valueNum = ESyncMLInputTypeAlphaNumeric;
       
   338 							 break;
       
   339 							case 'N': //Numeric
       
   340 							 valueNum = ESyncMLInputTypeNumeric;
       
   341 							 break;
       
   342 							case 'D': //Date
       
   343 							 valueNum = ESyncMLInputTypeDate;
       
   344 							 break;
       
   345 							case 'T': //Time
       
   346 							 valueNum = ESyncMLInputTypeTime;
       
   347 							 break;
       
   348 							case 'P': //Phone number
       
   349 							 valueNum = ESyncMLInputTypePhoneNumber;
       
   350 							 break;
       
   351 							case 'I': //Ip address
       
   352 							 valueNum = ESyncMLInputTypeIPAddress;
       
   353 							 break;
       
   354 						}
       
   355 					}
       
   356 				}
       
   357 			}
       
   358 		}
       
   359 		_DBG_FILE("CNSmlDMCmds::AlertInputTypeParameter: end");
       
   360 	return valueNum; 
       
   361 	}	
       
   362 	
       
   363 // ---------------------------------------------------------
       
   364 // CNSmlDMCmds::AlertEchoTypeParameter()
       
   365 // For 1102-User Input server alert
       
   366 // For Echo Type optional parameter
       
   367 // ---------------------------------------------------------	
       
   368 TInt CNSmlDMCmds::AlertEchoTypeParameter( const SmlPcdata_t* aData, const TDesC8& aParamID ) const
       
   369 	{
       
   370 	_DBG_FILE("CNSmlDMCmds::AlertEchoTypeParameter: begin");
       
   371 	TInt valueNum = 0;//Text by default
       
   372 	if ( aData )
       
   373 		{
       
   374 		if ( aData->content )
       
   375 			{
       
   376 			TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length );
       
   377 			TrimRightSpaceAndNull( parameters );
       
   378 			TInt startPos = parameters.Find( aParamID );
       
   379 			if ( startPos >= 0 )
       
   380 				{
       
   381 				if ( parameters.Length() > startPos + aParamID.Length() )
       
   382 					{
       
   383 					TPtrC8 strPart = parameters.Right( parameters.Length() - ( startPos + aParamID.Length() ) );
       
   384 					TInt length = 0;
       
   385 					TChar character = strPart[length];
       
   386 						switch( character )
       
   387 						{
       
   388 							 
       
   389 							case 'T': valueNum = ESyncMLEchoTypeText;
       
   390 							 break;
       
   391 							case 'P': valueNum = ESyncMLEchoTypePassword;
       
   392 							 break;
       
   393 							 default: 
       
   394 							 break;
       
   395 						}
       
   396 					}
       
   397 				}
       
   398 			}
       
   399 		}
       
   400 		_DBG_FILE("CNSmlDMCmds::AlertEchoTypeParameter: end");
       
   401 	return valueNum; 
       
   402 	}
       
   403 // ---------------------------------------------------------
       
   404 // CNSmlDMCmds::CheckDRPresence()
       
   405 // For 1102-User Input server alert
       
   406 // For Default Response item existence verification
       
   407 // ---------------------------------------------------------		
       
   408 TBool CNSmlDMCmds::CheckDRPresence( const SmlPcdata_t* aData, const TDesC8& aParamID ) const
       
   409    {
       
   410    	if ( aData )
       
   411 		{
       
   412 		if ( aData->content )
       
   413 			{
       
   414 			TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length );
       
   415 			TrimRightSpaceAndNull( parameters );
       
   416 			TInt startPos = parameters.Find( aParamID );
       
   417 			if ( startPos >= 0 )
       
   418 				{
       
   419 				 return ETrue;
       
   420 				}
       
   421 			}
       
   422 		}
       
   423 		return EFalse;
       
   424    }
       
   425 	
       
   426 // ---------------------------------------------------------
       
   427 // CNSmlDMCmds::AlertDefaultResponseParam()
       
   428 // For 1102-User Input server alert
       
   429 // For Default Response optional parameter
       
   430 // ---------------------------------------------------------
       
   431 TPtrC8 CNSmlDMCmds::AlertDefaultResponseParam( const SmlPcdata_t* aData, const TDesC8& aParamID ) const
       
   432 	{
       
   433 	_DBG_FILE("CNSmlDMCmds::AlertDefaultResponseParam: begin");
       
   434 	TLex8 value;
       
   435 	if ( aData )
       
   436 		{
       
   437 		if ( aData->content )
       
   438 			{
       
   439 			TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length );
       
   440 			TrimRightSpaceAndNull( parameters );
       
   441 			TInt startPos = parameters.Find( aParamID );
       
   442 			if ( startPos >= 0 )
       
   443 				{
       
   444 				if ( parameters.Length() > startPos + aParamID.Length() )
       
   445 					{
       
   446 					 TPtrC8 strPart = parameters.Right( parameters.Length() - ( startPos + aParamID.Length() ) );
       
   447 					TInt length = 0;
       
   448 					while ( length < strPart.Length() )
       
   449 						{
       
   450 						TChar character = strPart[length];
       
   451 						if ( character != '&' )
       
   452 							{
       
   453 							++length;
       
   454 							}
       
   455 						else
       
   456 							{
       
   457 							break;
       
   458 							}
       
   459 						}
       
   460 					TPtrC8 valueStr = strPart.Left(	length );
       
   461 					value.Assign( valueStr );
       
   462 										
       
   463 					}
       
   464 				}
       
   465 			}
       
   466 		}
       
   467 		_DBG_FILE("CNSmlDMCmds::AlertDefaultResponseParam: end");
       
   468 	 return value.Remainder();
       
   469 	}	
       
   470 //#endif
       
   471 
   326 // ---------------------------------------------------------
   472 // ---------------------------------------------------------
   327 // CNSmlDMCmds::AlertDataLC()
   473 // CNSmlDMCmds::AlertDataLC()
   328 // 
   474 // 
   329 // ---------------------------------------------------------
   475 // ---------------------------------------------------------
   330 HBufC8* CNSmlDMCmds::AlertDataLC( const SmlItemList_t* aItemList ) const
   476 HBufC8* CNSmlDMCmds::AlertDataLC( const SmlItemList_t* aItemList ) const
   508 	DoSourceL ( itemPtr->item->source, uri );
   654 	DoSourceL ( itemPtr->item->source, uri );
   509 	CleanupStack::PopAndDestroy();  // uri
   655 	CleanupStack::PopAndDestroy();  // uri
   510 
   656 
   511 	TPtr8 targeturi = HBufC8::NewLC ( (*aItemList[i].iTarget).Length())->Des();
   657 	TPtr8 targeturi = HBufC8::NewLC ( (*aItemList[i].iTarget).Length())->Des();
   512 	targeturi.Append ( *aItemList[i].iTarget);	
   658 	targeturi.Append ( *aItemList[i].iTarget);	
       
   659 	if(targeturi.Compare(KNullDesC8)!=0)
   513 	DoTargetL ( itemPtr->item->target, targeturi  );
   660 	DoTargetL ( itemPtr->item->target, targeturi  );
   514 	CleanupStack::PopAndDestroy();  // targeturi   
   661 	CleanupStack::PopAndDestroy();  // targeturi   
   515 	
   662 	
   516 	SmlMetInfMetInf_t* metInf;
   663 	SmlMetInfMetInf_t* metInf;
   517 	DoMetInfLC ( metInf ); 
   664 	DoMetInfLC ( metInf ); 
   967 	if ( alertCode == KNSmlDMAgentDisplayAlert ||
  1114 	if ( alertCode == KNSmlDMAgentDisplayAlert ||
   968 		 alertCode == KNSmlDMAgentContinueOrAbortAlert ||
  1115 		 alertCode == KNSmlDMAgentContinueOrAbortAlert ||
   969 		 alertCode == KNSmlDMAgentNextMessage ||
  1116 		 alertCode == KNSmlDMAgentNextMessage ||
   970 		 alertCode == KNSmlDMAgentSessionAbortAlert ||
  1117 		 alertCode == KNSmlDMAgentSessionAbortAlert ||
   971 		 alertCode == KNSmlDMAgentServerInitAlert ||
  1118 		 alertCode == KNSmlDMAgentServerInitAlert ||
   972 		 alertCode == KNSmlDMAgentClientInitAlert )
  1119 		 alertCode == KNSmlDMAgentClientInitAlert 
       
  1120 		 || alertCode == KNSmlDMAgentUserInputAlert 
       
  1121 		 || alertCode == KNSmlDMAgentSingleChoiceAlert 
       
  1122 		 || alertCode == KNSmlDMAgentMultipleChoiceAlert)
   973 		{
  1123 		{
   974 		HandleAlertsL(aAlert,statusID);
  1124 		HandleAlertsL(aAlert,statusID);
   975 		}
  1125 		}
   976 	else
  1126 	else
   977 		{
  1127 		{
  1008 // Handles Alert commands from a server.  
  1158 // Handles Alert commands from a server.  
  1009 // ---------------------------------------------------------
  1159 // ---------------------------------------------------------
  1010 void CNSmlDMCmds::HandleAlertsL( SmlAlert_t* aAlert, TInt& aStatusId)
  1160 void CNSmlDMCmds::HandleAlertsL( SmlAlert_t* aAlert, TInt& aStatusId)
  1011 	    {
  1161 	    {
  1012 	    TPtr8 alertCode = AlertCode( aAlert );
  1162 	    TPtr8 alertCode = AlertCode( aAlert );
  1013 	    if ( alertCode == KNSmlDMAgentDisplayAlert ||  alertCode == KNSmlDMAgentContinueOrAbortAlert )
  1163 	    if ( alertCode == KNSmlDMAgentDisplayAlert ||  alertCode == KNSmlDMAgentContinueOrAbortAlert 
       
  1164 	            || alertCode == KNSmlDMAgentUserInputAlert
       
  1165 	            || alertCode == KNSmlDMAgentSingleChoiceAlert
       
  1166 	            || alertCode == KNSmlDMAgentMultipleChoiceAlert )
  1014 	        {
  1167 	        {
  1015 	        if ( !aAlert->itemList )
  1168 	        if ( !aAlert->itemList )
  1016 	            {
  1169 	            {
  1017 	            iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand );
  1170 	            iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand );
  1018 	            iAgent->Interrupt( TNSmlError::ESmlAlertInvalid, EFalse, EFalse );
  1171 	            iAgent->Interrupt( TNSmlError::ESmlAlertInvalid, EFalse, EFalse );
  1031 	            }
  1184 	            }
  1032 	        else if(alertCode == KNSmlDMAgentContinueOrAbortAlert)
  1185 	        else if(alertCode == KNSmlDMAgentContinueOrAbortAlert)
  1033 	            {
  1186 	            {
  1034 	            HandleConfirmationAlertL(aAlert,aStatusId);
  1187 	            HandleConfirmationAlertL(aAlert,aStatusId);
  1035 	            }
  1188 	            }
  1036 
  1189 	        else if(alertCode == KNSmlDMAgentUserInputAlert)
       
  1190 	            {
       
  1191 	            HandleUserInputalertL(aAlert,aStatusId);
       
  1192 	            }
       
  1193 	        else if(alertCode == KNSmlDMAgentSingleChoiceAlert
       
  1194 	                || alertCode == KNSmlDMAgentMultipleChoiceAlert)
       
  1195 	            {	            	            
       
  1196 	            HandleChoiceAlertsL(aAlert,aStatusId);
       
  1197 	            }
  1037 	        else //
  1198 	        else //
  1038 	            {
  1199 	            {
  1039 
  1200 
  1040 	            }
  1201 	            }
  1041 	        }
  1202 	        }
  1042 	    }
  1203 	    }
  1043 
  1204 
       
  1205 // ---------------------------------------------------------
       
  1206 // CNSmlDMCmds::HandleChoiceAlertsL
       
  1207 // Handles Choice Alert commands from a server.  
       
  1208 // ---------------------------------------------------------
       
  1209 void CNSmlDMCmds::HandleChoiceAlertsL( SmlAlert_t* aAlert, TInt& aStatusId)
       
  1210     {    
       
  1211     const TChar KDRSeparator('-');
       
  1212     const TChar KChoiceItemSeparator(',');
       
  1213     TPtr8 alertCode = AlertCode( aAlert );
       
  1214     // MINDT 
       
  1215     TInt mindt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMINDT );
       
  1216     // MAXDT 
       
  1217     TInt maxdt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXDT );
       
  1218     if ( mindt > maxdt )
       
  1219         {
       
  1220         maxdt = mindt;
       
  1221         }   
       
  1222     TSyncMLDlgNotifParams notifyParams;
       
  1223     TInt maxlen = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXLEN );
       
  1224 
       
  1225     //check if iDR, Default response parameter is there or not
       
  1226     //DRPresent is used for destroying how many items in the pop up stack 
       
  1227     TBool DRPresent = CheckDRPresence( aAlert->itemList->item->data, KNSmlDMAgentDR );
       
  1228     if( DRPresent )
       
  1229         {
       
  1230         TPtrC8 DrPtr = AlertDefaultResponseParam( aAlert->itemList->item->data, KNSmlDMAgentDR );       
       
  1231         HBufC8* hptr = HBufC8::NewLC( DrPtr.Length()+ 4 ); //cs 1dr
       
  1232         TPtr8 DrBuf(hptr->Des());                           
       
  1233         if(alertCode == KNSmlDMAgentMultipleChoiceAlert)
       
  1234             {       
       
  1235             _DBG_FILE("drbuf multichoice");                     
       
  1236             DrBuf.Append(KDRSeparator);         
       
  1237             DrBuf.Append(DrPtr);
       
  1238             DrBuf.Append(KDRSeparator);         
       
  1239             }
       
  1240         else
       
  1241             {           
       
  1242             DrBuf.Append(DrPtr);
       
  1243             }
       
  1244         HBufC* DrBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L( DrBuf  );
       
  1245         CleanupStack::PushL( DrBuf16 ); //cs 2dr
       
  1246         notifyParams.iDR = *DrBuf16;
       
  1247         }
       
  1248     HBufC8* alertData = AlertDataLC( aAlert->itemList ); //cs 1
       
  1249     if ( alertData->Length() == 0)
       
  1250         {
       
  1251         if( DRPresent )
       
  1252             {
       
  1253             CleanupStack::PopAndDestroy(2);//alertData,hptr,DrBuf16
       
  1254             }	        
       
  1255         CleanupStack::PopAndDestroy();//alertData	        
       
  1256         iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand );
       
  1257         HandleAlertErrorL();
       
  1258         return;   
       
  1259         }
       
  1260 		
       
  1261     HBufC8* alertDataWithMDT = HBufC8::NewLC(alertData->Length()+KNSmlDMAgentMINDT().Length()+KNSmlDMAgentMAXDT().Length()+6); //cs 2
       
  1262     TPtr8 dataBuf = alertDataWithMDT->Des();
       
  1263     dataBuf.Append(*alertData);
       
  1264     HBufC* dataBuf16 = NULL;
       
  1265     TRAPD(errC,  dataBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(dataBuf));
       
  1266     if( errC == KErrCorrupt )
       
  1267         {
       
  1268         if( DRPresent )
       
  1269             {
       
  1270             CleanupStack::PopAndDestroy(2); //alertData hptr,DrBuf16,alertDataWithMDT
       
  1271             }	        
       
  1272         CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT	        
       
  1273         iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed );
       
  1274         return;
       
  1275         }
       
  1276     CleanupStack::PushL(dataBuf16);   //cs    3
       
  1277     //RNotifier notifier;
       
  1278     //User::LeaveIfError( notifier.Connect() );
       
  1279     //CleanupClosePushL(notifier); //cs
       
  1280     TPckgBuf<TBool> resBuf;    
       
  1281     /* 
       
  1282 	//TO reduce cyclomatic complexity
       
  1283 	if( dataBuf16->Length() > KSyncMLMaxServerMsgLength )
       
  1284         {
       
  1285         notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ;    
       
  1286         }
       
  1287     else
       
  1288         {
       
  1289         notifyParams.iServerMsg = *dataBuf16;   
       
  1290         }     */
       
  1291 	TInt datalength = FindMaxLength(dataBuf16->Length(),KSyncMLMaxServerMsgLength);	
       
  1292 	notifyParams.iServerMsg = (*dataBuf16).Left(datalength);  
       
  1293     notifyParams.iMaxTime = maxdt;
       
  1294     notifyParams.iMaxLength = maxlen;	                   
       
  1295     TRequestStatus status;      
       
  1296     _DBG_FILE("starting of choice alerts"); 
       
  1297     //Retrieve items list 
       
  1298     HBufC8* lengthbuf = HBufC8::NewLC(100); //cs 4
       
  1299     TInt NumItems = 0 ;
       
  1300     HBufC8* listitems = AlertChoiceItemsLC(aAlert->itemList,lengthbuf,NumItems);      //cs 5                  
       
  1301 	if(!NumItems)
       
  1302 	{
       
  1303 	if( DRPresent )
       
  1304             {
       
  1305             CleanupStack::PopAndDestroy(2); 
       
  1306             }	        
       
  1307         CleanupStack::PopAndDestroy(5); 	       
       
  1308         iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand );
       
  1309         return;
       
  1310 	}
       
  1311     notifyParams.iNumberOfItems = NumItems;         
       
  1312     HBufC* choiceitemslength = NULL;    
       
  1313     TRAPD(errL,  choiceitemslength = CnvUtfConverter::ConvertToUnicodeFromUtf8L(lengthbuf->Des()));
       
  1314     if( errL/* == KErrCorrupt*/ )//useful for low memory and other cases
       
  1315         {
       
  1316         if( DRPresent )
       
  1317             {
       
  1318             CleanupStack::PopAndDestroy(2); 
       
  1319             }	        
       
  1320         CleanupStack::PopAndDestroy(5); 	       
       
  1321         iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed );
       
  1322         return;
       
  1323         }
       
  1324     CleanupStack::PushL(choiceitemslength); //cs 6
       
  1325 
       
  1326    /* if( choiceitemslength->Length() > KSyncMLChoiceItemsLengthBuffer )
       
  1327         {
       
  1328         notifyParams.iItemLength = (*choiceitemslength).Left(KSyncMLChoiceItemsLengthBuffer) ;    
       
  1329         }
       
  1330     else
       
  1331         {
       
  1332         notifyParams.iItemLength = *choiceitemslength;
       
  1333         }   */
       
  1334    datalength = FindMaxLength(choiceitemslength->Length(),KSyncMLChoiceItemsLengthBuffer);			
       
  1335    notifyParams.iItemLength = (*choiceitemslength).Left(datalength);  
       
  1336     if( alertCode == KNSmlDMAgentMultipleChoiceAlert)
       
  1337         {
       
  1338         _DBG_FILE("multiple choice alerts");    
       
  1339         notifyParams.iNoteType = ESyncMLMultiChoiceQuery;
       
  1340         }
       
  1341     else
       
  1342         {
       
  1343         _DBG_FILE("single choice alerts");  
       
  1344         notifyParams.iNoteType = ESyncMLSingleChoiceQuery;
       
  1345         }             
       
  1346     if(iChunk.Handle())
       
  1347         iChunk.Close();
       
  1348     else
       
  1349         {
       
  1350         TTime now;
       
  1351         now.HomeTime();
       
  1352         TInt64 rand = now.Int64();
       
  1353         // Use timestamp to get a unique seed
       
  1354         TInt randnum = Math::Rand( rand );
       
  1355         TBuf<KSyncMLMaxProfileNameLength> chunkname;
       
  1356         chunkname.AppendNum(randnum);
       
  1357         chunkname.Append(KChunkName);
       
  1358         notifyParams.iChunkName = chunkname;
       
  1359         TInt err1 = iChunk.CreateGlobal( chunkname,
       
  1360                 KNSmlDmChoiceChunkMinSize, KNSmlDmChoiceChunkMaxSize );
       
  1361         DBG_FILE_CODE(err1,_S8("chunk creating error is "));
       
  1362         if( err1 < 0 && err1 != KErrAlreadyExists )
       
  1363             User::LeaveIfError(err1);
       
  1364         if( err1 == KErrAlreadyExists )
       
  1365             {    err1 = iChunk.OpenGlobal(chunkname,EFalse);
       
  1366             DBG_FILE_CODE(err1,_S8("chunk opening error is "));
       
  1367             User::LeaveIfError(err1);
       
  1368             }
       
  1369         }
       
  1370     TInt size1 = iChunk.Size();
       
  1371     DBG_FILE_CODE(size1,_S8("chunk size is "));
       
  1372 
       
  1373     RMemWriteStream chunkStream ( iChunk.Base(), iChunk.Size() );
       
  1374     CleanupClosePushL ( chunkStream ); //cs
       
  1375     chunkStream.WriteL ( listitems->Des() );
       
  1376     CleanupStack::PopAndDestroy(1);//chunkstream 
       
  1377     TPckgBuf<TSyncMLDlgNotifParams> pkgBuf( notifyParams );                            
       
  1378     TSyncMLDlgNotifReturnParams emptybuf;
       
  1379     TSyncMLDlgNotifReturnParamsPckg resultBuf( emptybuf );
       
  1380     RNotifier notifier;
       
  1381     User::LeaveIfError( notifier.Connect() );
       
  1382     CleanupClosePushL(notifier); //cs  7
       
  1383     _DBG_FILE("starting choice notifier");  
       
  1384     notifier.StartNotifierAndGetResponse( status, KNSmlSyncDialogUid, pkgBuf, resultBuf );
       
  1385     _DBG_FILE("notifier returned"); 
       
  1386     User::WaitForRequest( status );
       
  1387     CleanupStack::PopAndDestroy(4);//notifier,lengthbuf,listitems,choiceitemslength
       
  1388     iChunk.Close();
       
  1389     TBuf8<KSyncMLMaxAlertResultLength> rettext;
       
  1390     rettext.Copy( resultBuf().irettext.Left( KSyncMLMaxAlertResultLength ) );
       
  1391     if ( status != KErrNone )
       
  1392         {
       
  1393         TInt error = TNSmlError::ESmlStatusOperationCancelled ;
       
  1394         iStatusToServer->SetStatusCodeL( aStatusId, error );
       
  1395         HandleAlertErrorL();
       
  1396         }
       
  1397     else
       
  1398         {
       
  1399         //For sending data to server
       
  1400         if( alertCode == KNSmlDMAgentMultipleChoiceAlert)
       
  1401             {
       
  1402             SendMultiChoiceDataToServerL(rettext,aStatusId);                   
       
  1403             }
       
  1404         else
       
  1405             {
       
  1406             SmlPcdata_t* data = NULL;
       
  1407             PcdataNewL( data, rettext);
       
  1408             CleanupStack::PushL( data );
       
  1409             iStatusToServer->AddItemDataL( aStatusId, data );
       
  1410             CleanupStack::PopAndDestroy(); //data           
       
  1411             }           
       
  1412         }    
       
  1413     if( DRPresent ) 
       
  1414         CleanupStack::PopAndDestroy(2); //hptr,DrBuf16
       
  1415 
       
  1416     CleanupStack::PopAndDestroy(3); //notifier,alertData,alertDataWithMDT,dataBuf16     
       
  1417     }
       
  1418 
       
  1419 // ---------------------------------------------------------
       
  1420 // CNSmlDMCmds::SendMultiChoiceDataToServerL
       
  1421 // Sends Multiple Choice Alert status to server.  
       
  1422 // ---------------------------------------------------------
       
  1423 void CNSmlDMCmds::SendMultiChoiceDataToServerL(TDes8& aData,TInt& aStatusId)
       
  1424     {
       
  1425     const TChar KDRSeparator('-');
       
  1426     TPtrC8 temp1,temp2;
       
  1427     TInt prevcommapos = 0;
       
  1428     SmlPcdata_t* data = NULL;      
       
  1429     for(TInt i=0;i<aData.Length();i++)
       
  1430         {
       
  1431         //find a slash  
       
  1432 
       
  1433         if(aData[i]== KDRSeparator)
       
  1434             {
       
  1435             if(prevcommapos)
       
  1436                 {
       
  1437 
       
  1438                 temp1.Set(aData.Left(i));
       
  1439                 temp2.Set(temp1.Right(i-(prevcommapos+1)));
       
  1440                 prevcommapos=  i;
       
  1441                 }
       
  1442             else //firsttime finding comma
       
  1443                 {
       
  1444                 prevcommapos=  i;
       
  1445                 temp1.Set(aData.Left(i));
       
  1446                 temp2.Set(temp1.Right(i));
       
  1447                 }
       
  1448             //convert temp2 to number
       
  1449             PcdataNewL( data, temp2);
       
  1450             CleanupStack::PushL( data );
       
  1451             iStatusToServer->AddItemDataL( aStatusId, data );
       
  1452             CleanupStack::PopAndDestroy(); //data
       
  1453             data = NULL;
       
  1454 
       
  1455             }
       
  1456         }                           
       
  1457 
       
  1458     }
  1044 
  1459 
  1045 // ---------------------------------------------------------
  1460 // ---------------------------------------------------------
  1046 // CNSmlDMCmds::HandleConfirmationAlertL
  1461 // CNSmlDMCmds::HandleConfirmationAlertL
  1047 // Handles Confirmation Alert command from a server.  
  1462 // Handles Confirmation Alert command from a server.  
  1048 // ---------------------------------------------------------	
  1463 // ---------------------------------------------------------	
  1076         CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT
  1491         CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT
  1077         iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed );
  1492         iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed );
  1078         return;
  1493         return;
  1079         }
  1494         }
  1080     CleanupStack::PushL(dataBuf16);    
  1495     CleanupStack::PushL(dataBuf16);    
  1081    
  1496     RNotifier notifier;
       
  1497     User::LeaveIfError( notifier.Connect() );
       
  1498     CleanupClosePushL(notifier);
  1082     TPckgBuf<TBool> resBuf;
  1499     TPckgBuf<TBool> resBuf;
  1083     if( dataBuf16->Length() > KSyncMLMaxServerMsgLength )
  1500     if( dataBuf16->Length() > KSyncMLMaxServerMsgLength )
  1084         {
  1501         {
  1085         notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ;    
  1502         notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ;    
  1086         }
  1503         }
  1091     notifyParams.iMaxTime = maxdt;
  1508     notifyParams.iMaxTime = maxdt;
  1092     notifyParams.iMaxLength = maxlen;             
  1509     notifyParams.iMaxLength = maxlen;             
  1093     TRequestStatus status;      
  1510     TRequestStatus status;      
  1094     //Note type to Query note
  1511     //Note type to Query note
  1095     notifyParams.iNoteType = ESyncMLYesNoQuery;
  1512     notifyParams.iNoteType = ESyncMLYesNoQuery;
  1096     TPckgBuf<TSyncMLDlgNotifParams> pkgBuf(notifyParams);
  1513     TPckgBuf<TSyncMLDlgNotifParams> pkgBuf( notifyParams );
  1097     
  1514     notifier.StartNotifierAndGetResponse(status,KNSmlSyncDialogUid,pkgBuf,resBuf);
  1098     
  1515     User::WaitForRequest(status);
  1099     if(!IsHbSyncmlNotifierEnabledL())
  1516     TBool ret = resBuf();
  1100     {
  1517     if ( status == KErrCancel || status == KErrTimedOut )
  1101     	_DBG_FILE("starting notifier");  
       
  1102 
       
  1103     }
       
  1104     else
       
  1105     {
       
  1106  
       
  1107     TInt statusval;
       
  1108     ServerHbNotifierL(notifyParams.iNoteType, notifyParams.iServerMsg);
       
  1109     TInt err = RProperty::Get(dmagentuid, EHbDMSyncNotifierKeyStatusReturn, statusval);
       
  1110     	LOGSTRING2("get error status = %d", err);
       
  1111     	if(err == KErrNone)
       
  1112     		{
       
  1113     			status = statusval;
       
  1114     			LOGSTRING2("get statusval = %d", status.Int());
       
  1115     		}
       
  1116  
       
  1117     }
       
  1118     
       
  1119     if (status == KErrCancel || status == KErrTimedOut)
       
  1120         {
  1518         {
  1121         TInt error = status == KErrCancel ? TNSmlError::ESmlStatusNotModified : TNSmlError::ESmlStatusRequestTimeout;
  1519         TInt error = status == KErrCancel ? TNSmlError::ESmlStatusNotModified : TNSmlError::ESmlStatusRequestTimeout;
  1122         iStatusToServer->SetStatusCodeL( aStatusId, error );
  1520         iStatusToServer->SetStatusCodeL( aStatusId, error );
  1123         HandleAlertErrorL();
  1521         HandleAlertErrorL();
  1124         }
  1522         }
  1125     CleanupStack::PopAndDestroy(3); //alertData alertDataWithMDT,databuf16 
  1523     CleanupStack::PopAndDestroy(4); //alertData alertDataWithMDT,databuf16,notifier   
  1126     }
  1524     }
       
  1525 
       
  1526 // ---------------------------------------------------------
       
  1527 // CNSmlDMCmds::HandleUserInputalertL
       
  1528 // Handles user Text Input Alert command from a server.  
       
  1529 // ---------------------------------------------------------    
       
  1530  void CNSmlDMCmds::HandleUserInputalertL( SmlAlert_t* aAlert, TInt& aStatusId)
       
  1531      {     
       
  1532      // MINDT 
       
  1533      TInt mindt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMINDT );
       
  1534      // MAXDT 
       
  1535      TInt maxdt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXDT );
       
  1536      if ( mindt > maxdt )
       
  1537          {
       
  1538          maxdt = mindt;
       
  1539          }   
       
  1540      TSyncMLDlgNotifParams notifyParams;
       
  1541      TInt maxlen = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXLEN );
       
  1542      TInt InputType = AlertInputTypeParameter( aAlert->itemList->item->data, KNSmlDMAgentIT );
       
  1543      TInt EchoType = AlertEchoTypeParameter( aAlert->itemList->item->data, KNSmlDMAgentET );
       
  1544      //check if iDR, Default response parameter is there or not
       
  1545      //DRPresent is used for destroying how many items in the pop up stack 
       
  1546      TBool DRPresent = CheckDRPresence( aAlert->itemList->item->data, KNSmlDMAgentDR );
       
  1547      if( DRPresent )
       
  1548          {
       
  1549          TPtrC8 DrPtr = AlertDefaultResponseParam( aAlert->itemList->item->data, KNSmlDMAgentDR );       
       
  1550          HBufC8* hptr = HBufC8::NewLC( DrPtr.Length()+ 4 ); //cs
       
  1551          TPtr8 DrBuf(hptr->Des());                           
       
  1552 
       
  1553          DrBuf.Append(DrPtr);
       
  1554 
       
  1555          HBufC* DrBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L( DrBuf  );
       
  1556          CleanupStack::PushL( DrBuf16 );//cs
       
  1557          notifyParams.iDR = *DrBuf16;
       
  1558          }
       
  1559      HBufC8* alertData = AlertDataLC( aAlert->itemList );//cs
       
  1560      if ( alertData->Length() == 0)
       
  1561          {
       
  1562          if( DRPresent )
       
  1563              {
       
  1564              CleanupStack::PopAndDestroy(3);//alertData,hptr,DrBuf16
       
  1565              }
       
  1566          else
       
  1567              {
       
  1568              CleanupStack::PopAndDestroy();//alertData
       
  1569              }
       
  1570          iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand );
       
  1571          HandleAlertErrorL();
       
  1572          return;   
       
  1573          }
       
  1574      HBufC8* alertDataWithMDT = HBufC8::NewLC(alertData->Length()+KNSmlDMAgentMINDT().Length()+KNSmlDMAgentMAXDT().Length()+6);//cs
       
  1575      TPtr8 dataBuf = alertDataWithMDT->Des();
       
  1576      dataBuf.Append(*alertData);
       
  1577      HBufC* dataBuf16 = NULL;
       
  1578      TRAPD(errC,  dataBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(dataBuf));
       
  1579      if( errC == KErrCorrupt )
       
  1580          {
       
  1581          if( DRPresent )
       
  1582              {
       
  1583              CleanupStack::PopAndDestroy(4); //alertData hptr,DrBuf16,alertDataWithMDT
       
  1584              }
       
  1585          else
       
  1586              {
       
  1587              CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT
       
  1588              }
       
  1589          iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed );
       
  1590          return;
       
  1591          }
       
  1592      CleanupStack::PushL(dataBuf16);    //cs
       
  1593      RNotifier notifier;
       
  1594      User::LeaveIfError( notifier.Connect() );
       
  1595      CleanupClosePushL(notifier); //cs
       
  1596      TPckgBuf<TBool> resBuf;     
       
  1597      if( dataBuf16->Length() > KSyncMLMaxServerMsgLength )
       
  1598          {
       
  1599          notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ;    
       
  1600          }
       
  1601      else
       
  1602          {
       
  1603          notifyParams.iServerMsg = *dataBuf16;   
       
  1604          }     
       
  1605      notifyParams.iMaxTime = maxdt;
       
  1606      notifyParams.iMaxLength = maxlen;
       
  1607      notifyParams.iET = EchoType;
       
  1608      notifyParams.iIT = InputType;       
       
  1609      TRequestStatus status;      
       
  1610      //Note type to Text input note
       
  1611      notifyParams.iNoteType = ESyncMLInputQuery;
       
  1612      TPckgBuf<TSyncMLDlgNotifParams> pkgBuf( notifyParams );
       
  1613      TSyncMLDlgNotifReturnParams emptybuf;
       
  1614      TSyncMLDlgNotifReturnParamsPckg resultBuf( emptybuf );
       
  1615      notifier.StartNotifierAndGetResponse( status, KNSmlSyncDialogUid, pkgBuf, resultBuf );
       
  1616      User::WaitForRequest( status );
       
  1617      TBuf8<KSyncMLMaxDefaultResponseMsgLength> rettext;
       
  1618      rettext.Copy( resultBuf().irettext.Left( KSyncMLMaxDefaultResponseMsgLength ) );
       
  1619      if ( status == KErrCancel || status == KErrTimedOut || status ==  KErrAbort )
       
  1620          {
       
  1621          TInt error = TNSmlError::ESmlStatusOperationCancelled ;
       
  1622          iStatusToServer->SetStatusCodeL( aStatusId, error );
       
  1623          HandleAlertErrorL();
       
  1624          }
       
  1625      //For sending data to server    
       
  1626      SmlPcdata_t* data = NULL;
       
  1627      PcdataNewL( data, rettext);
       
  1628      CleanupStack::PushL( data );
       
  1629      iStatusToServer->AddItemDataL( aStatusId, data );
       
  1630      CleanupStack::PopAndDestroy(); //data
       
  1631      if( DRPresent ) 
       
  1632          CleanupStack::PopAndDestroy(6); //notifier,alertData,alertDataWithMDT,dataBuf16,hptr,DrBuf16
       
  1633      else
       
  1634          //#endif
       
  1635          CleanupStack::PopAndDestroy(4); //notifier,alertData,alertDataWithMDT,dataBuf16     
       
  1636      }
  1127 
  1637 
  1128  // ---------------------------------------------------------
  1638  // ---------------------------------------------------------
  1129  // CNSmlDMCmds::HandleDisplayAlertL
  1639  // CNSmlDMCmds::HandleDisplayAlertL
  1130  // Handles Display Alert command from a server.  
  1640  // Handles Display Alert command from a server.  
  1131  // ---------------------------------------------------------  
  1641  // ---------------------------------------------------------  
  1159          CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT
  1669          CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT
  1160          iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed );
  1670          iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed );
  1161          return;
  1671          return;
  1162          }
  1672          }
  1163      CleanupStack::PushL(dataBuf16);    
  1673      CleanupStack::PushL(dataBuf16);    
  1164     
  1674      RNotifier notifier;
       
  1675      User::LeaveIfError( notifier.Connect() );
       
  1676      CleanupClosePushL(notifier);
  1165      TPckgBuf<TBool> resBuf;
  1677      TPckgBuf<TBool> resBuf;
  1166      if( dataBuf16->Length() > KSyncMLMaxServerMsgLength )
  1678      if( dataBuf16->Length() > KSyncMLMaxServerMsgLength )
  1167          {
  1679          {
  1168          notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ;    
  1680          notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ;    
  1169          }
  1681          }
  1174      notifyParams.iMaxTime = maxdt;
  1686      notifyParams.iMaxTime = maxdt;
  1175      notifyParams.iMaxLength = maxlen;     
  1687      notifyParams.iMaxLength = maxlen;     
  1176      TRequestStatus status;              
  1688      TRequestStatus status;              
  1177      notifyParams.iNoteType = ESyncMLInfoNote;
  1689      notifyParams.iNoteType = ESyncMLInfoNote;
  1178      TPckgBuf<TSyncMLDlgNotifParams> pkgBuf( notifyParams );
  1690      TPckgBuf<TSyncMLDlgNotifParams> pkgBuf( notifyParams );
  1179     if(!IsHbSyncmlNotifierEnabledL())
  1691      notifier.StartNotifierAndGetResponse(status,KNSmlSyncDialogUid,pkgBuf,resBuf);
  1180         {
  1692      User::WaitForRequest(status);
  1181      
  1693      CleanupStack::PopAndDestroy(4); //alertData alertDataWithMDT,databuf16,notifier     
  1182         }
  1694      }
  1183     else
  1695 	
  1184         {
       
  1185         LOGSTRING("HandleDisplayAlertL Start test 1 start");  
       
  1186         ServerHbNotifierL(notifyParams.iNoteType, notifyParams.iServerMsg);
       
  1187         LOGSTRING("HandleDisplayAlertL Start test 2 end");
       
  1188         }
       
  1189     
       
  1190     CleanupStack::PopAndDestroy(3); //alertData alertDataWithMDT,databuf16   
       
  1191 
       
  1192 
       
  1193     }
       
  1194 
       
  1195 void CNSmlDMCmds::ServerHbNotifierL(TSyncMLDlgNoteTypes& aNotetype, TDesC& aServerMsg)
       
  1196     
       
  1197     {
       
  1198 				LOGSTRING("HandleDisplayAlertL ServerHbNotifier start");                
       
  1199         RDmDevDialog DmDevdialog;
       
  1200         TInt err = DmDevdialog.OpenL();
       
  1201         User::LeaveIfError(err);
       
  1202         TRequestStatus status = KRequestPending;
       
  1203         if(aNotetype == ESyncMLInfoNote)
       
  1204             {
       
  1205         DmDevdialog.ShowDisplayAlert(aServerMsg,status);
       
  1206             }
       
  1207             
       
  1208         else 
       
  1209             {
       
  1210         TInt timeout = 30; // dummy
       
  1211         TBuf<30> header; // dummy
       
  1212         DmDevdialog.ShowConfirmationAlert(timeout,header,aServerMsg,status);
       
  1213             }
       
  1214        
       
  1215         User::WaitForRequest(status);
       
  1216 
       
  1217 DmDevdialog.Close();
       
  1218         LOGSTRING("HandleDisplayAlertL ServerHbNotifier end");
       
  1219 
       
  1220 }
       
  1221 TBool CNSmlDMCmds::IsHbSyncmlNotifierEnabledL()
       
  1222     {
       
  1223     CRepository * rep =
       
  1224             CRepository::NewLC(KCRUidDeviceManagementInternalKeys);
       
  1225 
       
  1226     TInt notifierenabled = KErrNone;
       
  1227 
       
  1228     TInt err = rep->Get(KDevManEnableHbNotifier, notifierenabled);
       
  1229 
       
  1230     CleanupStack::PopAndDestroy(rep);
       
  1231 
       
  1232     if (err == KErrNone && notifierenabled)
       
  1233         {
       
  1234         return ETrue;
       
  1235         }
       
  1236     else
       
  1237         {
       
  1238         return EFalse;
       
  1239         }
       
  1240 
       
  1241     }
       
  1242 
       
  1243 // ---------------------------------------------------------
  1696 // ---------------------------------------------------------
  1244 // CNSmlDMCmds::ProcessSyncL()
  1697 // CNSmlDMCmds::ProcessSyncL()
  1245 // Process received Add, Replace and Delete commands
  1698 // Process received Add, Replace and Delete commands
  1246 // ---------------------------------------------------------
  1699 // ---------------------------------------------------------
  1247 void CNSmlDMCmds::ProcessSyncL( SmlSync_t* /*aSync*/ )
  1700 void CNSmlDMCmds::ProcessSyncL( SmlSync_t* /*aSync*/ )
  1834 	if ( !aItem->target||!aItem->target->locURI )
  2287 	if ( !aItem->target||!aItem->target->locURI )
  1835 		{
  2288 		{
  1836 		aStatusCode = TNSmlError::ESmlStatusIncompleteCommand;
  2289 		aStatusCode = TNSmlError::ESmlStatusIncompleteCommand;
  1837 		}
  2290 		}
  1838 	}
  2291 	}
       
  2292 
       
  2293 // ---------------------------------------------------------------------------------------------------------------
       
  2294 // CNSmlDMCmds::AlertChoiceItemsLC()
       
  2295 //  Retrieves the choice alerts information 
       
  2296 // ---------------------------------------------------------------------------------------------------------------
       
  2297 HBufC8* CNSmlDMCmds::AlertChoiceItemsLC(SmlItemList_t* aItemList,HBufC8*& aLengthBuf ,TInt& aNumItems ) const
       
  2298     {
       
  2299     /*cleanupstack contains
       
  2300      * top : tempdata
       
  2301      *      : unicodeData
       
  2302      * bottom: aLengthBuf
       
  2303      */
       
  2304 	 const TChar KDRSeparator('-');
       
  2305 const TChar KChoiceItemSeparator(',');
       
  2306     HBufC8* unicodeData = HBufC8::NewLC(200);
       
  2307     HBufC8* tempdata = NULL;
       
  2308     HBufC8* lengthbuf = aLengthBuf;
       
  2309     TBuf<20> lennum; 
       
  2310     SmlItemList_t* temp;
       
  2311     if (  aItemList )//Not null
       
  2312         {
       
  2313         if(aItemList->next)//removing header of dialog
       
  2314             {
       
  2315             temp = aItemList->next;
       
  2316             while(temp->next)
       
  2317                 {
       
  2318                 if (  temp->next->item )
       
  2319                     {
       
  2320                     if (  temp->next->item->data )
       
  2321                         {
       
  2322                         if (  temp->next->item->data->content )
       
  2323                             {
       
  2324                             TPtr8 data( (TUint8*)  temp->next->item->data->content,  temp->next->item->data->length, temp->next->item->data->length );
       
  2325                             TrimRightSpaceAndNull( data );
       
  2326                             tempdata = data.AllocLC();
       
  2327                             TInt length = data.Length();//item length
       
  2328                             //add length to buffer and add comma 
       
  2329                             if(lengthbuf->Des().MaxLength() > (lengthbuf->Des().Length() + 5/*bytes*/) )
       
  2330                                 {
       
  2331                                 if(length > KSyncMLMaxChoiceItemLength ) // choice item length restricting to 200
       
  2332                                     {
       
  2333                                     lennum.Num(KSyncMLMaxChoiceItemLength);
       
  2334                                     lengthbuf->Des().Append(lennum);
       
  2335                                     lengthbuf->Des().Append(KChoiceItemSeparator);                                    
       
  2336                                     }
       
  2337                                 else
       
  2338                                     {
       
  2339                                     lennum.Num(length);                            
       
  2340                                     lengthbuf->Des().Append(lennum);
       
  2341                                     lengthbuf->Des().Append(KChoiceItemSeparator);
       
  2342                                     }
       
  2343                                 }
       
  2344                             else
       
  2345                                 {
       
  2346                                 //Pop the aLengthBuf from cleanupstack and realloc
       
  2347                                 CleanupStack::Pop(3); //tempdata,unicodeData,aLengthBuf
       
  2348                                 lengthbuf = lengthbuf->ReAllocL(lengthbuf->Des().Length() + 100);
       
  2349                                 CleanupStack::PushL(lengthbuf);
       
  2350                                 CleanupStack::PushL(unicodeData);
       
  2351                                 CleanupStack::PushL(tempdata);
       
  2352                                 if(length > KSyncMLMaxChoiceItemLength ) // choice item length restricting to 200
       
  2353                                     {
       
  2354                                     lengthbuf->Des().AppendNum(KSyncMLMaxChoiceItemLength);
       
  2355                                     lengthbuf->Des().Append(KChoiceItemSeparator);  
       
  2356                                     }
       
  2357                                 else
       
  2358                                     {
       
  2359                                     lengthbuf->Des().AppendNum(length); //Append(length);
       
  2360                                     lengthbuf->Des().Append(KChoiceItemSeparator);
       
  2361                                     }
       
  2362                                 }
       
  2363                             if(unicodeData->Des().MaxLength()> (unicodeData->Des().Length() + length))
       
  2364                                 {
       
  2365                                 if(length > KSyncMLMaxChoiceItemLength ) // choice item length restricting to 200
       
  2366                                     {
       
  2367                                     unicodeData->Des().Append(tempdata->Des().Left(KSyncMLMaxChoiceItemLength)); 
       
  2368                                     }
       
  2369                                 else
       
  2370                                     {
       
  2371                                     unicodeData->Des().Append(tempdata->Des());
       
  2372                                     }
       
  2373                                 }
       
  2374                             else
       
  2375                                 {
       
  2376                                 CleanupStack::Pop(2);//tempdata,unicodeData
       
  2377                                 unicodeData = unicodeData->ReAllocL(unicodeData->Des().Length() + length + 200);
       
  2378                                 CleanupStack::PushL(unicodeData);
       
  2379                                 CleanupStack::PushL(tempdata);
       
  2380                                 if(length > KSyncMLMaxChoiceItemLength ) // choice item length restricting to 200
       
  2381                                     {
       
  2382                                     unicodeData->Des().Append(tempdata->Des().Left(KSyncMLMaxChoiceItemLength)); 
       
  2383                                     }
       
  2384                                 else
       
  2385                                     {
       
  2386                                     unicodeData->Des().Append(tempdata->Des());
       
  2387                                     }
       
  2388                                 }
       
  2389                             CleanupStack::PopAndDestroy(tempdata);
       
  2390                             aNumItems++;
       
  2391                             data.Zero();
       
  2392                             }
       
  2393                         }
       
  2394                     }
       
  2395                 temp = temp->next;
       
  2396                 }
       
  2397             }
       
  2398         }  
       
  2399         _DBG_FILE("CNSmlDMCmds::AlertDataLC: end"); 
       
  2400         aLengthBuf = lengthbuf;
       
  2401         return unicodeData;          
       
  2402     }
       
  2403 	
       
  2404 // ---------------------------------------------------------------------------------------------------------------
       
  2405 // CNSmlDMCmds::FindMaxLength()
       
  2406 // ---------------------------------------------------------------------------------------------------------------	
       
  2407 TInt CNSmlDMCmds::FindMaxLength(TInt aSourceLength, TInt aDestLength)
       
  2408 	{
       
  2409 	TInt length = 0;
       
  2410 	if(aSourceLength > aDestLength )
       
  2411 	 {
       
  2412 	  length = aDestLength;
       
  2413 	 }
       
  2414 	else
       
  2415 	 {
       
  2416 	  length = aSourceLength;	  
       
  2417 	 }
       
  2418 	return length;
       
  2419 	}