sapi_contacts_vpbk/src/contactinterface.cpp
changeset 0 14df0fbfcc4e
equal deleted inserted replaced
-1:000000000000 0:14df0fbfcc4e
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Provides interface between the AIW FrameWork and Service Provider.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <LiwVariant.h>
       
    19 #include <LiwGenericParam.h>
       
    20 #include <LiwCommon.h>
       
    21 
       
    22 #include <CVPbkContactLinkArray.h>
       
    23 #include <CVPbkContactStoreUriArray.h>
       
    24 #include <CVPbkContactManager.h>
       
    25 #include <MVPbkContactStoreList.h>
       
    26 #include <TVPbkContactStoreUriPtr.h>
       
    27 #include <MVPbkContactLink.h>
       
    28 
       
    29 // User Includes
       
    30 #include "contactservice.h"
       
    31 #include "contactinterface.h"
       
    32 #include "contactinterfacecallback.h"
       
    33 #include "searchfields.h"
       
    34 #include "contactservice.hrh"
       
    35 #include "contacterrormessage.hrh"
       
    36 #include "../../inc/serviceerrno.h"
       
    37 #include "contactsmaxlength.h"
       
    38 
       
    39 using namespace LIW;
       
    40 
       
    41 #define KMissingArg -100
       
    42 
       
    43 /*
       
    44 -----------------------------------------------------------------------------
       
    45     CContactInterface::CContactInterface()
       
    46     Description    : Constructor
       
    47     Return values  : N/A
       
    48 -----------------------------------------------------------------------------
       
    49 */
       
    50 CContactInterface::CContactInterface()
       
    51                 : iContactService( NULL ),
       
    52                   iErrorMess(NULL),
       
    53                   iDburi(NULL)
       
    54     {
       
    55     }
       
    56 
       
    57 /*
       
    58 -----------------------------------------------------------------------------
       
    59     void CContactInterface::ConstructL()
       
    60     Description         : Symbian 2nd phase constructor can leave.
       
    61     Return values       : N/A
       
    62 -----------------------------------------------------------------------------
       
    63 */
       
    64 void CContactInterface::ConstructL()
       
    65     {
       
    66     iContactService = CContactService::NewL();    
       
    67 	iErrorMess = HBufC::NewL(250);    
       
    68     }
       
    69 /*
       
    70 -----------------------------------------------------------------------------
       
    71     CContactInterface* CContactInterface::NewL()
       
    72     Description                       : Two-phased constructor.
       
    73     Return values                     : CContactInterface object pointer
       
    74 
       
    75 -----------------------------------------------------------------------------
       
    76 */
       
    77 EXPORT_C CContactInterface* CContactInterface::NewL()
       
    78     {
       
    79     CContactInterface* self = new ( ELeave ) CContactInterface();
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL();
       
    82     CleanupStack::Pop( self );
       
    83     return self;
       
    84     }
       
    85 /*
       
    86 -----------------------------------------------------------------------------
       
    87     CContactInterface::~CContactInterface()
       
    88     Description     : Destructor, free allocated resources
       
    89     Return values   : N/A
       
    90 -----------------------------------------------------------------------------
       
    91 */
       
    92 CContactInterface::~CContactInterface()
       
    93     {
       
    94     delete iContactService;
       
    95     delete iErrorMess;
       
    96     delete iDburi;
       
    97     iCallbackMap.ResetAndDestroy();
       
    98     iCallbackMap.Close();		
       
    99     }
       
   100     
       
   101 /*
       
   102 -----------------------------------------------------------------------------
       
   103     CContactInterface::GetFieldMaxLength()
       
   104     Description     : Gets the max length of the field.
       
   105     Return values   : MaxLength
       
   106 -----------------------------------------------------------------------------
       
   107 */    
       
   108     
       
   109 TInt CContactInterface :: GetFieldMaxLength(TInt aFieldKeyID, TDesC& aDbUri)
       
   110     {
       
   111     TInt fieldmaxlength = -1;
       
   112     switch(aFieldKeyID)
       
   113         {
       
   114             case R_VPBK_FIELD_TYPE_LASTNAME     :
       
   115             case R_VPBK_FIELD_TYPE_FIRSTNAME    :
       
   116             case R_VPBK_FIELD_TYPE_SECONDNAME   :
       
   117             case R_VPBK_FIELD_TYPE_DEPARTMENT   :
       
   118             case R_VPBK_FIELD_TYPE_JOBTITLE	    : 
       
   119         	case R_VPBK_FIELD_TYPE_ASSTNAME    	:
       
   120             case R_VPBK_FIELD_TYPE_ASSTPHONE    :
       
   121         	case R_VPBK_FIELD_TYPE_SPOUSE		:
       
   122             case R_VPBK_FIELD_TYPE_CHILDREN	    :
       
   123             case R_VPBK_FIELD_TYPE_COMPANYNAME  :
       
   124             case R_VPBK_FIELD_TYPE_MIDDLENAME   :           
       
   125             case R_VPBK_FIELD_TYPE_ADDRSTREETGEN:
       
   126             case R_VPBK_FIELD_TYPE_ADDRSTREETHOME:
       
   127             case R_VPBK_FIELD_TYPE_ADDRSTREETWORK:
       
   128             case R_VPBK_FIELD_TYPE_ADDRLOCALGEN	:
       
   129             case R_VPBK_FIELD_TYPE_ADDRLOCALHOME:
       
   130             case R_VPBK_FIELD_TYPE_ADDRLOCALWORK:
       
   131             case R_VPBK_FIELD_TYPE_ADDRREGIONGEN:
       
   132             case R_VPBK_FIELD_TYPE_ADDRREGIONHOME:
       
   133             case R_VPBK_FIELD_TYPE_ADDRREGIONWORK:            
       
   134             case R_VPBK_FIELD_TYPE_ADDRCOUNTRYGEN:
       
   135             case R_VPBK_FIELD_TYPE_ADDRCOUNTRYHOME:
       
   136             case R_VPBK_FIELD_TYPE_ADDRCOUNTRYWORK:
       
   137         	case R_VPBK_FIELD_TYPE_ADDREXTGEN:
       
   138         	case R_VPBK_FIELD_TYPE_ADDREXTHOME:
       
   139         	case R_VPBK_FIELD_TYPE_ADDREXTWORK:            
       
   140                 {
       
   141                 // a very bad fix for sim case 
       
   142                 if(aFieldKeyID == R_VPBK_FIELD_TYPE_LASTNAME && (aDbUri.CompareF(KSimDataBaseOne) == 0))
       
   143                     {
       
   144                     //comparing the database uri for sim and setting the length
       
   145                     fieldmaxlength = KMaLengthFourteen;                        
       
   146                     }
       
   147                 else
       
   148                     {
       
   149                     fieldmaxlength = KMaxLengthFifty;     
       
   150                     }                                                    
       
   151                 break;
       
   152                 }
       
   153                 
       
   154            case R_VPBK_FIELD_TYPE_MOBILEPHONEGEN  :
       
   155            case R_VPBK_FIELD_TYPE_MOBILEPHONEHOME :
       
   156            case R_VPBK_FIELD_TYPE_MOBILEPHONEWORK :
       
   157            case R_VPBK_FIELD_TYPE_LANDPHONEGEN	  :
       
   158            case R_VPBK_FIELD_TYPE_LANDPHONEHOME	  :
       
   159            case R_VPBK_FIELD_TYPE_LANDPHONEWORK   :
       
   160            case R_VPBK_FIELD_TYPE_VIDEONUMBERHOME :
       
   161            case R_VPBK_FIELD_TYPE_VIDEONUMBERWORK :
       
   162            case R_VPBK_FIELD_TYPE_VIDEONUMBERGEN  :
       
   163            case R_VPBK_FIELD_TYPE_CARPHONE		  :
       
   164            case R_VPBK_FIELD_TYPE_PAGERNUMBER	  :
       
   165            case R_VPBK_FIELD_TYPE_FAXNUMBERHOME   :
       
   166            case R_VPBK_FIELD_TYPE_FAXNUMBERWORK   :
       
   167            case R_VPBK_FIELD_TYPE_FAXNUMBERGEN	  :
       
   168                {
       
   169                fieldmaxlength = KMaxLengthFourtyEight;
       
   170                break;
       
   171                }
       
   172           case R_VPBK_FIELD_TYPE_ADDRPOGEN		  :
       
   173           case R_VPBK_FIELD_TYPE_ADDRPOHOME		  :
       
   174           case R_VPBK_FIELD_TYPE_ADDRPOWORK		  :
       
   175           case R_VPBK_FIELD_TYPE_ADDRPOSTCODEGEN  :
       
   176           case R_VPBK_FIELD_TYPE_ADDRPOSTCODEHOME :
       
   177           case R_VPBK_FIELD_TYPE_ADDRPOSTCODEWORK : 
       
   178               {
       
   179               fieldmaxlength = KMaxLengthTwenty; 
       
   180               break; 
       
   181               }
       
   182           case R_VPBK_FIELD_TYPE_PREFIX:
       
   183           case R_VPBK_FIELD_TYPE_SUFFIX:
       
   184               {
       
   185               fieldmaxlength = KMaxLengthTen;
       
   186               break;
       
   187               }
       
   188           
       
   189           case R_VPBK_FIELD_TYPE_DTMFSTRING:
       
   190               {
       
   191               fieldmaxlength =  KMaxLengthSixty;
       
   192               break;
       
   193               }
       
   194           
       
   195           case R_VPBK_FIELD_TYPE_SIP:
       
   196           case R_VPBK_FIELD_TYPE_POC:
       
   197           case R_VPBK_FIELD_TYPE_VOIPHOME:
       
   198           case R_VPBK_FIELD_TYPE_VOIPWORK:
       
   199           case R_VPBK_FIELD_TYPE_VOIPGEN:
       
   200           case R_VPBK_FIELD_TYPE_SWIS:
       
   201               {
       
   202               fieldmaxlength =  KMaxLengthHundred;
       
   203               break;
       
   204               }
       
   205           case R_VPBK_FIELD_TYPE_EMAILGEN :
       
   206           case R_VPBK_FIELD_TYPE_EMAILWORK:
       
   207           case R_VPBK_FIELD_TYPE_EMAILHOME:
       
   208               {
       
   209               fieldmaxlength =  KMaxLengthOneHundredAndFifty;
       
   210               break;
       
   211               }
       
   212           case R_VPBK_FIELD_TYPE_ADDRLABELHOME:
       
   213           case R_VPBK_FIELD_TYPE_ADDRLABELGEN:
       
   214           case R_VPBK_FIELD_TYPE_ADDRLABELWORK :
       
   215               {
       
   216               fieldmaxlength =  KMaxLengthTwoHundredAndFifty;
       
   217               break;
       
   218               }
       
   219           case R_VPBK_FIELD_TYPE_LOCPRIVACY:
       
   220           case R_VPBK_FIELD_TYPE_RINGTONE:
       
   221               {
       
   222               fieldmaxlength = KMaxLengthTwoHundredAndFiftySix;
       
   223               break;
       
   224               }
       
   225            case R_VPBK_FIELD_TYPE_URLWORK:
       
   226            case R_VPBK_FIELD_TYPE_URLHOME:
       
   227            case R_VPBK_FIELD_TYPE_URLGEN:
       
   228            case R_VPBK_FIELD_TYPE_NOTE:
       
   229            case R_VPBK_FIELD_TYPE_SYNCCLASS:
       
   230               {
       
   231               fieldmaxlength = KMaxLengthThousand;
       
   232               break;
       
   233               }
       
   234         }
       
   235     return fieldmaxlength;    
       
   236     }
       
   237 
       
   238 /*
       
   239 -----------------------------------------------------------------------------
       
   240     CContactInterface::ExecuteCmdL()
       
   241     Description     : This is called by the consumer with command to execute.
       
   242     Return values   : N/A
       
   243 -----------------------------------------------------------------------------
       
   244 */
       
   245 EXPORT_C void CContactInterface::
       
   246     ExecuteCmdL(const TDesC8& aCmdName,
       
   247                 const CLiwGenericParamList& aInParamList,
       
   248                 CLiwGenericParamList& aOutParamList,
       
   249                 TUint aCmdOptions,
       
   250                 MLiwNotifyCallback* aCallback)
       
   251     {    
       
   252     //Top level TRAP for all the api's
       
   253     TRAPD(returnCode,
       
   254           ProcessCmdL(aCmdName,
       
   255                       aInParamList,
       
   256                       aOutParamList,
       
   257                       aCmdOptions,
       
   258                       aCallback));      
       
   259     //append the appropriate error code.
       
   260     TInt32 SapiErr = SapiError(returnCode);
       
   261     aOutParamList.AppendL(TLiwGenericParam(KErrorCode,
       
   262                           TLiwVariant((TInt32)SapiErr)));
       
   263     }
       
   264 
       
   265 /*
       
   266 ---------------------------------------------------------------------------
       
   267  CContactInterface::SapiError(err)
       
   268  Description      :This function is called by the user to get mapped SAPI
       
   269                    generic error code from symbian error codes.
       
   270   Return values   :Integer Value TInt.
       
   271 ---------------------------------------------------------------------------
       
   272 */
       
   273 TInt CContactInterface::SapiError( TInt aSymbianErr )
       
   274     {
       
   275     TInt sapiErr(SErrGeneralError);
       
   276 
       
   277    	switch (aSymbianErr)
       
   278     	{
       
   279    		case KErrBadName:
       
   280    		case KErrArgument:
       
   281    		    {
       
   282    		    sapiErr = SErrBadArgumentType;
       
   283    		    break;
       
   284    		    }
       
   285    		case KErrNotSupported:
       
   286    		    {
       
   287    		    sapiErr = SErrServiceNotSupported;
       
   288    		    break;
       
   289    		    }
       
   290    		case KErrInUse:
       
   291    		    {
       
   292    		    sapiErr = SErrServiceInUse;
       
   293    		    break;
       
   294    		    }
       
   295    		case KErrAccessDenied:
       
   296    		    {
       
   297    		    sapiErr = SErrAccessDenied;
       
   298    		    break;
       
   299    		    }
       
   300     	case KErrNoMemory:
       
   301 	    	{
       
   302     		sapiErr = SErrNoMemory;
       
   303     		break;
       
   304     		}
       
   305    		case KErrAlreadyExists:
       
   306    		    {
       
   307    		    sapiErr = SErrEntryExists;
       
   308    		    break;
       
   309    		    }
       
   310    		case KErrNotReady:
       
   311    		    {
       
   312    		    sapiErr = SErrServiceNotReady;
       
   313    		    break;
       
   314    		    }
       
   315    		case KErrNotFound:
       
   316    		    {
       
   317    		    sapiErr = SErrNotFound;
       
   318    		    break;
       
   319    		    }
       
   320     	case KErrNone:
       
   321     		{
       
   322     		sapiErr = SErrNone;
       
   323     		break;
       
   324     		}
       
   325     	case KErrPathNotFound:
       
   326     		{
       
   327     		sapiErr = SErrPathNotFound;
       
   328     		break;
       
   329     		}
       
   330     	case KMissingArg:
       
   331     		{
       
   332     		sapiErr = SErrMissingArgument;
       
   333     		break;
       
   334     		}
       
   335     	default:
       
   336     		{
       
   337     		sapiErr = SErrGeneralError;
       
   338 	    	}
       
   339    	}
       
   340     return sapiErr;
       
   341     }
       
   342 
       
   343 /*
       
   344 -----------------------------------------------------------------------------
       
   345     CContactInterface::Close()
       
   346     Description     : This is called by the consumer to delete the handle.
       
   347     Return values   : N/A
       
   348 -----------------------------------------------------------------------------
       
   349 */
       
   350 void CContactInterface::Close()
       
   351     {
       
   352     delete this;
       
   353     }
       
   354 
       
   355 /*
       
   356 -----------------------------------------------------------------------------
       
   357     CContactInterface::ContactIDUTFToStreamL()
       
   358     Description     : This method is used to convert the UTF to stream.
       
   359     Return values   : N/A
       
   360 -----------------------------------------------------------------------------
       
   361 */
       
   362 HBufC8* CContactInterface::ContactIDUTFToStreamL(TDesC&  aContactIDUTF)
       
   363     {
       
   364     TInt len = aContactIDUTF.Length();    
       
   365     HBufC8* buf = HBufC8 :: NewL(len);    
       
   366     buf->Des().SetLength(len);
       
   367     TUint16* ptr =  const_cast<TUint16*>(aContactIDUTF.Ptr());
       
   368     TUint8* ptr8 = const_cast<TUint8*>(buf->Des().Ptr());
       
   369     
       
   370     for(TInt i=0; i<len; i++)
       
   371         {
       
   372         TUint c = ptr[i];
       
   373         if(c>=0x100)
       
   374          c = c & 0x00ff;        
       
   375         ptr8[i] = (TUint8)c;    
       
   376         }       
       
   377     return buf;         
       
   378     }
       
   379     
       
   380 /*
       
   381 -----------------------------------------------------------------------------
       
   382     CContactInterface::ProcessAddDataL(const CLiwMap* aMap,
       
   383  									   TPtrC& aDbUri,
       
   384  									   CSingleContact* aContact)
       
   385     Description     : Constructs a contact from the fields that exist in the map..
       
   386     Return values   : N/A
       
   387 -----------------------------------------------------------------------------
       
   388 */
       
   389 
       
   390 void CContactInterface::ProcessAddDataL(const CLiwMap* aMap, 										
       
   391  										CSingleContact* aContact,
       
   392  										CLiwGenericParamList& aOutParamList)
       
   393     {
       
   394     TBool atleastOneField = EFalse;
       
   395     iDburi = HBufC::NewL(VPbkContactStoreUris::DefaultCntDbUri().Length());    
       
   396     //set the DBUri to the default value.    
       
   397     iDburi->Des().Copy(VPbkContactStoreUris::DefaultCntDbUri());
       
   398     //get the number of entries in the map
       
   399     TInt keyCount = aMap->Count();
       
   400 
       
   401     for(TInt index=0;index<keyCount;index++)
       
   402         {
       
   403         //iterate through each entry in the map
       
   404         //starting from the first element
       
   405 
       
   406         //this variable should be reemoved
       
   407         //when the AtL signature is changed in LIW.
       
   408         TBuf8<KMaxName> fieldKey;
       
   409         TLiwVariant fieldVal;
       
   410         CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup ,&fieldVal) );
       
   411 
       
   412         //AtL gives us the key stored at a particular index
       
   413         aMap->AtL(index, fieldKey);
       
   414         //check whether the key is DBUri
       
   415         //if it is extract it and mark it.
       
   416         if( fieldKey.Compare(KDBUri) == 0 )
       
   417             {
       
   418             //get the DBUri from the map
       
   419             if(aMap->FindL(fieldKey, fieldVal))
       
   420                 {
       
   421                 if(fieldVal.AsDes().CompareF(KNullDesC)!=0)
       
   422                     { 
       
   423                     delete iDburi;
       
   424                     iDburi = NULL;                                  
       
   425                     iDburi = HBufC::NewL(fieldVal.AsDes().Length());
       
   426                     iDburi->Des().Copy(fieldVal.AsDes());                    
       
   427                     }
       
   428                 }
       
   429             }
       
   430         else if( fieldKey.Compare(KContactId) == 0 )
       
   431             {
       
   432             //get the contact ID  from the map
       
   433             if(aMap->FindL(fieldKey, fieldVal))
       
   434                 {
       
   435                 TPtrC cntIdUnicode = fieldVal.AsDes();      
       
   436 				if(cntIdUnicode == NULL)
       
   437 					{
       
   438 					aOutParamList.AppendL(TLiwGenericParam (KErrorMessage,
       
   439 					                      TLiwVariant(KAddWrongContactId)));  	
       
   440 					User::Leave(KErrArgument); 
       
   441 					}
       
   442           
       
   443                 HBufC8* cntid = ContactIDUTFToStreamL(cntIdUnicode);                
       
   444                 aContact->SetContactIdL(*cntid);
       
   445                 delete cntid;
       
   446                 }
       
   447             }
       
   448         else
       
   449             {            
       
   450             //if the key is not uri and is not a contact id
       
   451             //search for the field
       
   452             if(CSearchFields::GetIdFromFieldKey(fieldKey) == -1)
       
   453                 {
       
   454                 TBuf<25> buff;
       
   455                 buff.Copy(fieldKey);
       
   456                 TBuf<KMaxName> errmsg(KAddInvalidFieldKey);
       
   457                 errmsg.Append(buff);                                
       
   458             	aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   459             	                      TLiwVariant(errmsg)));  	
       
   460 				User::Leave(KErrArgument);     
       
   461                 }                                        
       
   462 			aMap->FindL(fieldKey,fieldVal);
       
   463        	 	if(EVariantTypeMap == fieldVal.TypeId())
       
   464                 {
       
   465                 const CLiwMap* pMap = fieldVal.AsMap();
       
   466                 if(pMap)
       
   467                     {
       
   468                     TLiwVariant labelVar;
       
   469 				    CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &labelVar) );
       
   470                     
       
   471                     TLiwVariant valueVar;
       
   472 				    CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueVar) );
       
   473 
       
   474                     TLiwVariant nextVar;
       
   475                     CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &nextVar) );
       
   476                     while(1)
       
   477                         {
       
   478 						//Get field label and value from map
       
   479 					if(pMap->FindL(KFieldLabel, labelVar))				
       
   480 						{
       
   481 						if(EVariantTypeDesC !=  labelVar.TypeId())	
       
   482 					 		{
       
   483 							TPtr16  err(iErrorMess->Des());
       
   484 							TBuf<KMaxName> buf;
       
   485 							buf.Copy(labelVar.AsData());							
       
   486 							err.Append(KAddCnt);
       
   487 							err.Append(buf);
       
   488 							err.Append(KAddInvalidStr);
       
   489 							aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(*iErrorMess) ) );  
       
   490 							CleanupStack::Pop(&nextVar);
       
   491 							nextVar.Reset();
       
   492 							CleanupStack::Pop(&valueVar);
       
   493 							valueVar.Reset();
       
   494 							CleanupStack::Pop(&labelVar);
       
   495 							labelVar.Reset();
       
   496     						CleanupStack::Pop(&fieldVal);
       
   497     						fieldVal.Reset();
       
   498     						err.Delete(0,iErrorMess->Length());
       
   499 							User::Leave(KErrArgument); 														
       
   500 							}							
       
   501 						}
       
   502 					TBool date = EFalse;                        
       
   503 						//Set contact item field value
       
   504 					if(pMap->FindL(KFieldValue, valueVar))	
       
   505 						{
       
   506                         if((fieldKey.Compare(KDate) == 0 || (fieldKey.Compare(KAnniversary) == 0)))
       
   507 	                        {
       
   508 	                        if(EVariantTypeTTime != valueVar.TypeId())
       
   509 	                        {
       
   510 							TPtr16  err(iErrorMess->Des());
       
   511 							TBuf<KMaxName> buf;
       
   512 							buf.Copy(valueVar.AsData());
       
   513 							err.Append(KAddCnt);
       
   514 							err.Append(buf);
       
   515 							err.Append(KAddInvalidTime);
       
   516 
       
   517 							aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(*iErrorMess) ) );  
       
   518 							CleanupStack::Pop(&nextVar);
       
   519 							nextVar.Reset();
       
   520 							CleanupStack::Pop(&valueVar);
       
   521 							valueVar.Reset();
       
   522 							CleanupStack::Pop(&labelVar);
       
   523 							labelVar.Reset();
       
   524     						CleanupStack::Pop(&fieldVal);
       
   525     						fieldVal.Reset();
       
   526     						err.Delete(0,iErrorMess->Length());
       
   527 							User::Leave(KErrArgument); 														
       
   528 	                        }
       
   529                         date = ETrue;
       
   530                         }
       
   531 
       
   532 						if((EVariantTypeDesC !=  valueVar.TypeId())	&& (date == EFalse))
       
   533 							{
       
   534 							TPtr16  err(iErrorMess->Des());
       
   535 							TBuf<KMaxName> buf;
       
   536 							buf.Copy(valueVar.AsData());
       
   537 							err.Append(KAddCnt);
       
   538 							err.Append(buf);
       
   539 							err.Append(KAddInvalidStr);
       
   540 
       
   541 							aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(*iErrorMess) ) );  
       
   542 							CleanupStack::Pop(&nextVar);
       
   543 							nextVar.Reset();
       
   544 							CleanupStack::Pop(&valueVar);
       
   545 							valueVar.Reset();
       
   546 							CleanupStack::Pop(&labelVar);
       
   547 							labelVar.Reset();
       
   548     						CleanupStack::Pop(&fieldVal);
       
   549     						fieldVal.Reset();
       
   550     						err.Delete(0,iErrorMess->Length());
       
   551 							User::Leave(KErrArgument); 														
       
   552 							}					
       
   553 						}
       
   554                         CSingleContactField* field =
       
   555                             CSingleContactField::NewL();
       
   556                         CleanupStack::PushL(field);
       
   557                         if(date)
       
   558                             {
       
   559                             field->SetFieldParamsL(fieldKey,
       
   560     						                       labelVar.AsDes(),
       
   561     					    	                   KNullDesC);
       
   562     					    field->SetDateTime(valueVar.AsTTime());	                   
       
   563     	                    }
       
   564                         else 
       
   565                             {
       
   566     						field->SetFieldParamsL(fieldKey,
       
   567                                                    labelVar.AsDes(),
       
   568                                                    valueVar.AsDes());
       
   569                             	
       
   570                             }
       
   571                         aContact->AddFieldToContactL(field);
       
   572                         atleastOneField = ETrue;
       
   573                         CleanupStack::Pop(field);
       
   574                         if(pMap->FindL(KFieldNext,nextVar))
       
   575                             {
       
   576                             if(EVariantTypeMap == nextVar.TypeId())
       
   577                                 {
       
   578                                 pMap = nextVar.AsMap();
       
   579                                 }
       
   580                             else
       
   581                             	{
       
   582 				                //if the map is not found
       
   583 				                //Leave with the error code
       
   584 				                aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   585 				                                      TLiwVariant(KAddNextFieldType)));
       
   586 				                User::Leave(KErrArgument);
       
   587                             	}
       
   588                             }
       
   589                         else //EVariantTypeNull
       
   590                             {
       
   591                             break;
       
   592                             }
       
   593                         }  //end of while
       
   594                     CleanupStack::Pop(&nextVar);    
       
   595                     nextVar.Reset();
       
   596 					CleanupStack::Pop(&valueVar);
       
   597 					valueVar.Reset();
       
   598 					CleanupStack::Pop(&labelVar);
       
   599 					labelVar.Reset();
       
   600                     }
       
   601                 else
       
   602                     {
       
   603                     //if the map is not found
       
   604                     //Leave with the error code
       
   605                     aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   606                                           TLiwVariant(KAddInvalidFieldType)));
       
   607                     User::Leave(KErrArgument);
       
   608                     }
       
   609                 }
       
   610             else
       
   611                 {
       
   612 				CleanupStack::Pop(&fieldVal);
       
   613 				fieldVal.Reset();
       
   614 				TPtr16  err(iErrorMess->Des());
       
   615 				TBuf<KMaxName> fld;
       
   616 				fld.Copy(fieldKey);
       
   617 				err.Append(fld);
       
   618 				err.Append(_L(",Invalid Type,Map is Required"));
       
   619 				aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,
       
   620 				                       TLiwVariant(*iErrorMess) ) );  
       
   621 				err.Delete(0,iErrorMess->Length()); 
       
   622 				User::Leave(KErrArgument); 
       
   623 
       
   624 				}	
       
   625             }            
       
   626 		CleanupStack::Pop(&fieldVal);
       
   627 		fieldVal.Reset();    
       
   628         } //end of for
       
   629     //checking for the maximum length (this is a temporary check since there is no support from vpbk)
       
   630     CSingleContactField* contactfield = NULL;
       
   631     TPtrC8 fieldKey(KNullDesC8);
       
   632     TPtrC fieldLabel(KNullDesC);
       
   633     TPtrC fieldValue(KNullDesC);
       
   634     TInt fieldCount = aContact->FieldCount(); 
       
   635     for( TInt i=0;i<fieldCount;i++ ) 
       
   636         {                
       
   637         contactfield = aContact->FieldAt(i);
       
   638         if(contactfield) 
       
   639             {
       
   640             contactfield->GetFieldDataL(fieldKey, fieldLabel, fieldValue);            
       
   641 			 if(!(fieldKey.Compare(KDate) == 0 || fieldKey.Compare(KAnniversary) == 0))
       
   642 			 {
       
   643 	            if(fieldValue.Length() > GetFieldMaxLength(CSearchFields::GetIdFromFieldKey(fieldKey), *iDburi))
       
   644 	        		{
       
   645 	        		TPtr16  err(iErrorMess->Des());
       
   646 	        		TBuf<KMaxName> fld;
       
   647 					fld.Copy(fieldKey);				
       
   648 					err.Append(_L("Contacts : Add : Field Value too long for key : "));
       
   649 					err.Append(fld);
       
   650 					
       
   651 	        		aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   652 	                                      TLiwVariant(*iErrorMess)));
       
   653 	                
       
   654 	                err.Delete(0,iErrorMess->Length());
       
   655 	        		User::Leave(KErrArgument);    
       
   656 	        		}     
       
   657 			 	
       
   658 			 }
       
   659             }
       
   660             
       
   661         }
       
   662        
       
   663 	if(atleastOneField == EFalse)
       
   664 		{
       
   665         aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   666                               TLiwVariant(KAddKeyNotSpecified)));
       
   667 		User::Leave(KErrArgument);
       
   668 		}				
       
   669     } //End of function : ProcessAddDataL()
       
   670 
       
   671 
       
   672 /*
       
   673 -----------------------------------------------------------------------------
       
   674     CContactInterface::ProcessCmdL(const TDesC8& aCmdName,
       
   675                                     const CLiwGenericParamList& aInParamList,
       
   676                                     CLiwGenericParamList& aOutParamList,
       
   677                                     TUint aCmdOptions,
       
   678                                     MLiwNotifyCallback* aCallback )
       
   679     Description     : This function processes the commands like add, delete, organise,
       
   680                      getlist.....etc.
       
   681     Return values   : N/A
       
   682 -----------------------------------------------------------------------------
       
   683 */
       
   684 void CContactInterface::ProcessCmdL(const TDesC8& aCmdName,
       
   685                                     const CLiwGenericParamList& aInParamList,
       
   686                                     CLiwGenericParamList& aOutParamList,
       
   687                                     TUint aCmdOptions,
       
   688                                     MLiwNotifyCallback* aCallback )
       
   689     {
       
   690     TInt returnCode = KErrNone;
       
   691     TInt transId = 0;
       
   692 	//if callback parameter is not null then retrieve the transaction id.
       
   693     if(aCallback && aCmdOptions == KLiwOptASyncronous)
       
   694         {
       
   695         transId = aCallback->GetTransactionID();
       
   696 
       
   697         CContactCallbackMap* map =
       
   698             new (ELeave) CContactCallbackMap(transId,
       
   699                                              aCallback);
       
   700         CleanupStack::PushL(map);
       
   701         iCallbackMap.AppendL(map);
       
   702         CleanupStack::Pop(map);
       
   703 
       
   704         //In case of async calls, also set the transaction id
       
   705         aOutParamList.AppendL(TLiwGenericParam(KTransactionID,
       
   706                               TLiwVariant((TInt32)transId)));
       
   707 
       
   708         }
       
   709     else if((aCmdOptions == KLiwOptASyncronous) && (!aCallback))
       
   710     	{
       
   711     	//Leave with the error code
       
   712         aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   713                           TLiwVariant(KCallbackNotFound)));
       
   714         User::Leave(KErrArgument);
       
   715     	}
       
   716     else if(aCallback && (aCmdOptions == 0))
       
   717 	    {
       
   718         aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   719                           TLiwVariant(KCallbackNotFound)));
       
   720         User::Leave(KErrArgument);
       
   721 	    	
       
   722 	    }	
       
   723     
       
   724     if( aCmdName.CompareF(KCmdCancel) == 0) // for cancel asynchronous request
       
   725 	    {
       
   726 		if(aCmdOptions != KLiwOptCancel)
       
   727 			{
       
   728 	    	//Leave with the error code
       
   729 	        aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   730 	                          TLiwVariant(KCancleCommandoptionWrong)));
       
   731 	        User::Leave(KErrArgument);
       
   732 				
       
   733 			}
       
   734  		returnCode = CancelCommandL(aInParamList,
       
   735  									aOutParamList);
       
   736 		if(returnCode != KErrNone)
       
   737 			{
       
   738 			//Leave with the error code
       
   739 			aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   740 									TLiwVariant(KCancelUnsuccessful)));
       
   741 			User::Leave(returnCode);
       
   742 			}
       
   743     	}
       
   744     //check for the command name,...if Import proceed further.
       
   745     else if ( (aCmdName.CompareF( KCmdImport ) == 0))
       
   746         {
       
   747         ImportCommandL(aInParamList,
       
   748                        aOutParamList,
       
   749                        aCallback,
       
   750                        aCmdOptions,
       
   751                        transId);
       
   752         }
       
   753     //check for the command name,...if Export, proceed further.
       
   754     else if ( (aCmdName.CompareF( KCmdExport ) == 0))
       
   755         {
       
   756         ExportCommandL(aInParamList,
       
   757                        aOutParamList,
       
   758                        aCallback,
       
   759                        aCmdOptions,
       
   760                        transId);
       
   761         }
       
   762     //check for the command name,...if Add, proceed further.
       
   763 	else if ( (aCmdName.CompareF( KCmdAdd ) == 0))
       
   764         {
       
   765         AddCommandL(aInParamList,
       
   766                     aOutParamList,
       
   767                     aCallback,
       
   768                     aCmdOptions,
       
   769                     transId);
       
   770         }
       
   771    //check for the command name,...if Delete, proceed further.
       
   772    else if ( (aCmdName.CompareF( KCmdDelete ) == 0))
       
   773         {
       
   774         DeleteCommandL(aInParamList,
       
   775                        aOutParamList,
       
   776                        aCallback,
       
   777                        aCmdOptions,
       
   778                        transId);
       
   779 	    }
       
   780 
       
   781 	   //check for the command name,...if OrganiseGroups, proceed further.
       
   782     else if ( (aCmdName.CompareF( KCmdOrganiseGroups ) == 0))
       
   783         {
       
   784         OrganiseGroupCommandL(aInParamList,
       
   785                                            aOutParamList,
       
   786             	                           aCallback,
       
   787             	                           aCmdOptions,
       
   788             	                           transId);
       
   789         }
       
   790    //Passing arguments for GetList command
       
   791    else if( aCmdName.CompareF( KCmdGetList ) == 0 )
       
   792         {
       
   793         GetListCommandL(aInParamList,
       
   794                         aOutParamList,
       
   795                         aCallback,
       
   796                         aCmdOptions,
       
   797                         transId);
       
   798         }
       
   799    else 
       
   800    		{
       
   801         //Leave with the error code
       
   802         aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   803                           TLiwVariant(KCommandNotSupported)));
       
   804         User::Leave(KErrNotSupported);
       
   805    		}
       
   806 
       
   807     } //end of ProcessCmdL
       
   808 
       
   809 /*
       
   810 -----------------------------------------------------------------------------
       
   811     CContactInterface::GetListCommandL(const CLiwGenericParamList& aInParamList,
       
   812                                        CLiwGenericParamList& aOutParamList,
       
   813                                        MLiwNotifyCallback* aCallback,
       
   814                                        TUint aCmdOptions,
       
   815                                        TInt aTransId)
       
   816     Description     : This function parses the input param list
       
   817                     : and calls the Getlist API
       
   818     Return values   : N/A
       
   819 -----------------------------------------------------------------------------
       
   820 */
       
   821 void CContactInterface::
       
   822      GetListCommandL(const CLiwGenericParamList& aInParamList,
       
   823                      CLiwGenericParamList& aOutParamList,
       
   824                      MLiwNotifyCallback* aCallback,
       
   825                      TUint aCmdOptions,
       
   826                      TInt aTransId)
       
   827     {    
       
   828     const TLiwGenericParam* paramContentType = NULL;
       
   829 	const TLiwGenericParam* paramGetListData = NULL;
       
   830     const TLiwGenericParam* paramGetListSortOrder = NULL;
       
   831 
       
   832     TInt pos = 0;
       
   833 	//Get the content type: it can be "contact" or "group" 
       
   834 	paramContentType = aInParamList.FindFirst( pos, KType );
       
   835 	if(!paramContentType)
       
   836 		{
       
   837 			if(aInParamList.Count()>0)
       
   838 				paramContentType = &aInParamList[0] ;
       
   839 			
       
   840 			if(!paramContentType || paramContentType->Name().Compare(KNullDesC8) != 0)
       
   841 				{
       
   842 				aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KGetListContentTypeMissing) ) );  
       
   843 				User::Leave(KMissingArg); 
       
   844 				}		
       
   845         	if(aInParamList.Count()>1)    	
       
   846         		paramGetListData = &aInParamList[1]; 
       
   847         	
       
   848     		if(aInParamList.Count()>2)
       
   849 	            paramGetListSortOrder = &aInParamList[2] ;
       
   850 		}	
       
   851 	pos = 0;
       
   852     //Get the filter criteria, the value of which is a Map
       
   853     paramGetListData = aInParamList.FindFirst( pos, KFilter );    
       
   854     
       
   855     pos = 0;
       
   856     paramGetListSortOrder = aInParamList.FindFirst( pos, KSort );    	
       
   857 	
       
   858 	TLiwVariant cnttyp = paramContentType->Value();
       
   859 	if(EVariantTypeDesC !=  cnttyp.TypeId())
       
   860 		{
       
   861 		cnttyp.Reset();
       
   862 
       
   863 		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KGetListWrongContentType) ) );  
       
   864 		User::Leave(KErrArgument);			
       
   865 		}
       
   866 			 
       
   867     //Retrieve the map
       
   868     const CLiwMap* pMap = NULL;
       
   869     if(paramGetListData)
       
   870         {
       
   871         TLiwVariant getlistdata = paramGetListData->Value();
       
   872         if(EVariantTypeMap != getlistdata.TypeId() )
       
   873 	        {
       
   874 	        getlistdata.Reset();
       
   875 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KGetListInvalidFilterType) ) );  
       
   876 			User::Leave(KErrArgument);			
       
   877 	        }
       
   878         pMap = getlistdata.AsMap();
       
   879 	    getlistdata.Reset();
       
   880         }
       
   881 		
       
   882  	const CLiwMap* sortMap = NULL;
       
   883 
       
   884  	if(paramGetListSortOrder)
       
   885  	{
       
   886  	TLiwVariant map =  paramGetListSortOrder->Value();
       
   887  	
       
   888  	if(EVariantTypeMap == map.TypeId())
       
   889 	 	{
       
   890 	 	sortMap= paramGetListSortOrder->Value().AsMap();	
       
   891 	 	}
       
   892  	else
       
   893 	 	{
       
   894 		map.Reset();
       
   895 		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KGetListInvalidSortType) ) );  
       
   896 		User::Leave(KErrArgument);			
       
   897 	
       
   898 	 	}
       
   899  	map.Reset();	
       
   900  	}
       
   901         
       
   902     //Get the type of the list requested
       
   903     Ttype listType = EContacts;
       
   904     TPtrC contentType;
       
   905 
       
   906     contentType.Set(paramContentType->Value().AsDes());
       
   907 
       
   908 	 //Based on content type set the value of the enum Ttype
       
   909 	if(contentType.Compare(KDatabase) == 0)
       
   910 		{
       
   911 		listType = EDatabase;
       
   912 		}
       
   913 	else if(contentType.Compare(KGroup) == 0)
       
   914 		{
       
   915 		listType = EGroups;
       
   916 		}
       
   917 	else if(contentType.Compare(KContact) == 0)
       
   918 		{
       
   919 		listType = EContacts;
       
   920 		}
       
   921 	else
       
   922     	{ 
       
   923     	aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   924                               TLiwVariant(KGetListInvalidContentType)));   
       
   925     	User::Leave(KErrArgument);
       
   926     	}
       
   927 
       
   928 	TLiwVariant uriofDb;
       
   929     CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &uriofDb) );
       
   930 
       
   931 	TLiwVariant groupId;
       
   932     CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &groupId) );
       
   933 
       
   934     TPtrC8 ptrToCntId(KNullDesC8);
       
   935 	HBufC8* cntid = NULL;
       
   936 	CContactIter* iter;
       
   937 	CContactIterator* iterator;
       
   938 	TPtrC dbUri(VPbkContactStoreUris::DefaultCntDbUri());	
       
   939 	//Switch based on the Ttype var value
       
   940 	switch(listType)
       
   941 	    {	    
       
   942 		case EDatabase:
       
   943 		    //In case it is GetList of dabases, the call is synchronous
       
   944 			iter = CContactIter::NewL();			
       
   945 			CleanupStack::PushL(iter);
       
   946 			iContactService->GetListL(*iter);
       
   947 		    CleanupStack::Pop(iter);
       
   948 		    //Setting the output param
       
   949 			if(iter)
       
   950 				{
       
   951 			    iterator = CContactIterator::NewL(iter);
       
   952 			    CleanupStack::PushL(iterator);
       
   953 		        aOutParamList.AppendL(TLiwGenericParam(KReturnValue,
       
   954 		                              TLiwVariant(iterator)));
       
   955 		        
       
   956 		        CleanupStack::Pop(iterator);
       
   957 		        iterator->DecRef();
       
   958                 CleanupStack::Pop(&groupId);
       
   959                 groupId.Reset();
       
   960                 CleanupStack::Pop(&uriofDb);
       
   961                 uriofDb.Reset();
       
   962 				return;
       
   963 				}
       
   964 			break;
       
   965 		case EGroups:
       
   966             //In case it is GetList of groups, its asynchronous
       
   967             //All that is required to get the list of groups is the database name
       
   968             //(in case its null default database is used) and callback function
       
   969             if(pMap && (EFalse != pMap->FindL(KDBUri, uriofDb)))
       
   970                  {
       
   971                  if(uriofDb.AsDes().Compare(KNullDesC)!= 0)
       
   972                      {
       
   973                      dbUri.Set(uriofDb.AsDes());
       
   974                      }
       
   975                  }
       
   976             // Get the contact id, in case it is specified single contact is retrived
       
   977             // If content is NULL, search is performed using search criteria
       
   978             // If the ID is mentioned then the search value and fields are ignored.
       
   979             if(pMap && (EFalse != pMap->FindL(KGroupId, groupId)))
       
   980                  {
       
   981                  TPtrC ptr = groupId.AsDes();
       
   982                  cntid = ContactIDUTFToStreamL(ptr);                 
       
   983                  CleanupStack::PushL(cntid);
       
   984                  if(aCmdOptions == KLiwOptASyncronous)
       
   985                     {
       
   986                 	CContactInterfaceCallback* contactCallback =
       
   987                 	    CContactInterfaceCallback::NewL();
       
   988                     CleanupStack :: PushL(contactCallback);
       
   989                    	 contactCallback->SetParams(aCallback,
       
   990                    	                            aTransId,
       
   991                    	                            &aInParamList);
       
   992                    	 //Call GetList in case of retrieval of a
       
   993                    	 //single contact whose id is known
       
   994                         iContactService->GetListL(contactCallback,
       
   995         										  aTransId,
       
   996         										  listType,
       
   997         										  *cntid,
       
   998         										  KNullDesC,
       
   999         										  NULL,
       
  1000         										  EAsc,
       
  1001         										  dbUri);
       
  1002 
       
  1003                     CleanupStack :: Pop(contactCallback);
       
  1004                     CleanupStack::PopAndDestroy(cntid);  
       
  1005                     }
       
  1006              else
       
  1007                     {
       
  1008                     //it is assumed that the call is synchronous
       
  1009                     CContactIter* iter =
       
  1010                     iContactService->GetListL(listType,
       
  1011                                               *cntid,
       
  1012                                               KNullDesC,
       
  1013                                               NULL,
       
  1014                                               EAsc,
       
  1015                                               dbUri);
       
  1016                     aOutParamList.AppendL(TLiwGenericParam( KErrorCode,
       
  1017                                           TLiwVariant((TInt32)SErrNone)));
       
  1018                     //Setting the output param
       
  1019                     CContactIterator* iterator=CContactIterator::NewL(iter);
       
  1020                     CleanupStack::PushL(iterator);
       
  1021                     aOutParamList.AppendL(TLiwGenericParam(KReturnValue,
       
  1022                                           TLiwVariant(iterator)));                                                             
       
  1023                     CleanupStack::Pop(iterator);
       
  1024                     iterator->DecRef();
       
  1025                     CleanupStack::PopAndDestroy(cntid);
       
  1026                     CleanupStack::Pop(&groupId);
       
  1027                     groupId.Reset();
       
  1028                     CleanupStack::Pop(&uriofDb);
       
  1029                     uriofDb.Reset();
       
  1030                     return;
       
  1031                     }
       
  1032              break;
       
  1033              }                 
       
  1034             if(aCmdOptions == KLiwOptASyncronous)
       
  1035                 {
       
  1036                 CContactInterfaceCallback* contactCallback =
       
  1037                     CContactInterfaceCallback::NewL();
       
  1038                 CleanupStack :: PushL(contactCallback);
       
  1039                 contactCallback->SetParams(aCallback,
       
  1040                                            aTransId,
       
  1041                                            &aInParamList);
       
  1042                 //Call the contactservice api
       
  1043                     iContactService->GetListL(contactCallback,
       
  1044                                               aTransId,
       
  1045                                               listType,
       
  1046                                               ptrToCntId,
       
  1047                                               KNullDesC,
       
  1048                                               NULL,
       
  1049                                               EAsc,
       
  1050                                               dbUri);
       
  1051 
       
  1052                 CleanupStack :: Pop(contactCallback);
       
  1053                 }
       
  1054             else
       
  1055                 {
       
  1056                 //it is assumed that the call is synchronous
       
  1057                 CContactIter* iter =
       
  1058                     iContactService->GetListL(listType,
       
  1059                                               ptrToCntId,
       
  1060                                               KNullDesC,
       
  1061     										  NULL,
       
  1062     										  EAsc,
       
  1063                                               dbUri);
       
  1064                 //Setting the output param
       
  1065                 CContactIterator* iterator=CContactIterator::NewL(iter);
       
  1066                 CleanupStack::PushL(iterator);
       
  1067                 aOutParamList.AppendL(TLiwGenericParam( KReturnValue,
       
  1068                                       TLiwVariant(iterator) ));                                                      
       
  1069                 CleanupStack::Pop(iterator);
       
  1070                 iterator->DecRef(); 
       
  1071                	CleanupStack::Pop(&groupId);
       
  1072                	groupId.Reset();
       
  1073                 CleanupStack::Pop(&uriofDb);
       
  1074                 uriofDb.Reset();
       
  1075                 return;
       
  1076                 }
       
  1077             break;
       
  1078 		case EContacts:
       
  1079 		    //In case it is GetList of contacts, its asynchronous
       
  1080             //Get the database uri, if not specified default database is used
       
  1081             if(pMap && (EFalse != pMap->FindL(KDBUri,uriofDb)))
       
  1082                  {
       
  1083                  if(uriofDb.AsDes().Compare(KNullDesC)!= 0)
       
  1084                      {
       
  1085                      dbUri.Set(uriofDb.AsDes());
       
  1086                      }
       
  1087                  }
       
  1088             TLiwVariant contactId;
       
  1089             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &contactId) );
       
  1090 
       
  1091             // Get the contact id, in case it is specified single contact is retrived
       
  1092             // If content is NULL, search is performed using search criteria
       
  1093             // If the ID is mentioned then the search value and fields are ignored.
       
  1094             if(pMap && (EFalse != pMap->FindL(KContactId, contactId)))
       
  1095                  {
       
  1096                  TPtrC ptr = contactId.AsDes();
       
  1097                  cntid = ContactIDUTFToStreamL(ptr);                 
       
  1098                  CleanupStack::PushL(cntid);
       
  1099                  if(aCmdOptions == KLiwOptASyncronous)
       
  1100                     {
       
  1101                 	CContactInterfaceCallback* contactCallback =
       
  1102                 	    CContactInterfaceCallback::NewL();
       
  1103                     CleanupStack :: PushL(contactCallback);
       
  1104                    	 contactCallback->SetParams(aCallback,
       
  1105                    	                            aTransId,
       
  1106                    	                            &aInParamList);
       
  1107                    	 //Call GetList in case of retrieval of a
       
  1108                    	 //single contact whose id is known
       
  1109                         iContactService->GetListL(contactCallback,
       
  1110         										  aTransId,
       
  1111         										  listType,
       
  1112         										  *cntid,
       
  1113         										  KNullDesC,
       
  1114         										  NULL,
       
  1115         										  EAsc,
       
  1116         										  dbUri);
       
  1117 
       
  1118                     CleanupStack :: Pop(contactCallback);
       
  1119                     CleanupStack::PopAndDestroy(cntid);  
       
  1120                     }
       
  1121              else
       
  1122                     {
       
  1123                     //it is assumed that the call is synchronous
       
  1124                     CContactIter* iter =
       
  1125                     iContactService->GetListL(listType,
       
  1126                                               *cntid,
       
  1127                                               KNullDesC,
       
  1128                                               NULL,
       
  1129                                               EAsc,
       
  1130                                               dbUri);
       
  1131                     aOutParamList.AppendL(TLiwGenericParam( KErrorCode,
       
  1132                                           TLiwVariant((TInt32)SErrNone)));
       
  1133                     //Setting the output param
       
  1134                     CContactIterator* iterator=CContactIterator::NewL(iter);
       
  1135                     CleanupStack::PushL(iterator);
       
  1136                     aOutParamList.AppendL(TLiwGenericParam(KReturnValue,
       
  1137                                           TLiwVariant(iterator)));                                                             
       
  1138                     CleanupStack::Pop(iterator);
       
  1139                     iterator->DecRef(); 
       
  1140                     CleanupStack::PopAndDestroy(cntid);
       
  1141                     CleanupStack::Pop(&contactId);
       
  1142                     contactId.Reset();
       
  1143                     CleanupStack::Pop(&groupId);
       
  1144                	    groupId.Reset();
       
  1145                     CleanupStack::Pop(&uriofDb);
       
  1146                     uriofDb.Reset();
       
  1147                     return;
       
  1148                     }
       
  1149 	         CleanupStack::Pop(&contactId);
       
  1150 	         contactId.Reset();
       
  1151              break;
       
  1152              }            
       
  1153             CleanupStack::Pop(&contactId);
       
  1154 			contactId.Reset();
       
  1155             TLiwVariant searchVal;
       
  1156             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &searchVal) );
       
  1157 
       
  1158             TPtrC srchVal(KNullDesC);
       
  1159             TLiwVariant searchFieldKeys;
       
  1160             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &searchFieldKeys) );
       
  1161 
       
  1162             //Get the searchval, the value to be searched in the fields specified.
       
  1163             //If the value is NULL, the whole database is listed as an output
       
  1164             if(pMap && (EFalse != pMap->FindL(KSearchVal,searchVal)))
       
  1165                  {
       
  1166 		         if(EVariantTypeDesC != searchVal.TypeId())
       
  1167 		         	{
       
  1168                      CleanupStack::Pop(&searchVal);
       
  1169                      searchVal.Reset();
       
  1170      	    		 aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KGetListInvalidSearchVal) ) );  
       
  1171 		    		 User::Leave(KErrArgument); 
       
  1172 		         	}
       
  1173                  if(searchVal.AsDes().Compare(KNullDesC))
       
  1174                  srchVal.Set(searchVal.AsDes());
       
  1175                  }
       
  1176 
       
  1177             CSearchFields* searchFields = NULL;
       
  1178             // Get the search fields, fields in which
       
  1179             //the given searchval is to looked for
       
  1180             // in all the contacts of the database.
       
  1181             //If not specified, fields are first and last name
       
  1182             // by default
       
  1183 					
       
  1184             TLiwVariant order;
       
  1185             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &order) );
       
  1186 
       
  1187             TPtrC sortOrder;
       
  1188             TOrder srtOrder = EAsc;
       
  1189 
       
  1190             if(NULL != paramGetListSortOrder)
       
  1191                 {
       
  1192 				if(EFalse != sortMap->FindL(KOrder, order))
       
  1193                     {
       
  1194 			    	if(EVariantTypeDesC != order.TypeId())
       
  1195 				    	{
       
  1196 					    CleanupStack::Pop(&order);
       
  1197 					    order.Reset();
       
  1198 			    		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KGetListSortOrderValue) ) );  
       
  1199 			    		User::Leave(KErrArgument); 
       
  1200 				    		
       
  1201 				    	}
       
  1202                     sortOrder.Set(order.AsDes());
       
  1203 
       
  1204                     // Set the TOrder variable to the sort order preference
       
  1205                     if( sortOrder.CompareF( KAscending ) == 0)
       
  1206                         {
       
  1207                         srtOrder = EAsc;
       
  1208                         }
       
  1209                     else if(sortOrder.CompareF( KDescending ) == 0)
       
  1210                         {
       
  1211                         srtOrder = EDesc;
       
  1212                         }
       
  1213                     else
       
  1214                         {
       
  1215 					    CleanupStack::Pop(&order);
       
  1216 					    order.Reset();
       
  1217                         aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1218                         TLiwVariant(KGetListInvalidSortordVal))); 
       
  1219                         User::Leave(KErrArgument);     
       
  1220                         }    
       
  1221                     }    
       
  1222                 }
       
  1223 
       
  1224 
       
  1225             if(aCmdOptions == KLiwOptASyncronous)
       
  1226                 {
       
  1227                 CContactInterfaceCallback* contactCallback =
       
  1228                     CContactInterfaceCallback::NewL();
       
  1229                 CleanupStack :: PushL(contactCallback);
       
  1230                 contactCallback->SetParams(aCallback,
       
  1231                                            aTransId,
       
  1232                                            &aInParamList);
       
  1233 
       
  1234 
       
  1235                 //Call to GetList in case of searching
       
  1236                     iContactService->GetListL(contactCallback,
       
  1237         									  aTransId,
       
  1238         									  listType,
       
  1239         									  ptrToCntId,
       
  1240         									  srchVal,
       
  1241         									  searchFields,
       
  1242         									  srtOrder,
       
  1243         									  dbUri);
       
  1244 
       
  1245                 CleanupStack :: Pop(contactCallback);
       
  1246                 }
       
  1247             else
       
  1248                 {
       
  1249                 //it is assumed that the call is synchronous
       
  1250                 CContactIter* iter =
       
  1251                     iContactService->GetListL(listType,
       
  1252 											  ptrToCntId,
       
  1253 											  srchVal,
       
  1254 											  searchFields,
       
  1255 											  srtOrder,
       
  1256 											  dbUri);
       
  1257 
       
  1258                 aOutParamList.AppendL(TLiwGenericParam(KErrorCode,
       
  1259                                       TLiwVariant((TInt32)SErrNone)));
       
  1260 
       
  1261                 //Setting the output param
       
  1262                 CContactIterator* iterator=CContactIterator::NewL(iter);
       
  1263                 CleanupStack::PushL(iterator);
       
  1264                 aOutParamList.AppendL(TLiwGenericParam(KReturnValue,
       
  1265                                       TLiwVariant(iterator)));
       
  1266                 CleanupStack::Pop(iterator);
       
  1267                 iterator->DecRef();             
       
  1268                 CleanupStack::Pop(&order);
       
  1269                 order.Reset();
       
  1270                 CleanupStack::Pop(&searchFieldKeys);
       
  1271                 searchFieldKeys.Reset();
       
  1272                 CleanupStack::Pop(&searchVal);
       
  1273                 searchVal.Reset();
       
  1274 				CleanupStack::Pop(&groupId);
       
  1275 				groupId.Reset();
       
  1276                 CleanupStack::Pop(&uriofDb);
       
  1277                 uriofDb.Reset();                                                            
       
  1278                 return;
       
  1279                 }
       
  1280                             
       
  1281             CleanupStack::Pop(&order);
       
  1282             order.Reset();
       
  1283             CleanupStack::Pop(&searchFieldKeys);
       
  1284             searchFieldKeys.Reset();
       
  1285             CleanupStack::Pop(&searchVal);
       
  1286             searchVal.Reset();
       
  1287             
       
  1288             break;                                  
       
  1289         	}
       
  1290 	CleanupStack::Pop(&groupId);
       
  1291 	groupId.Reset();
       
  1292     CleanupStack::Pop(&uriofDb);
       
  1293     uriofDb.Reset();
       
  1294     
       
  1295     if( aCallback && aCmdOptions == KLiwOptASyncronous )
       
  1296         {
       
  1297         //In case of async calls, also set the transaction id
       
  1298         aOutParamList.AppendL(TLiwGenericParam(KTransactionID,
       
  1299                               TLiwVariant((TInt32)aTransId )));
       
  1300         }
       
  1301     }
       
  1302 
       
  1303 /*
       
  1304 -----------------------------------------------------------------------------
       
  1305     CContactInterface::CancelCommandL(const CLiwGenericParamList& aInParamList,
       
  1306                                       MLiwNotifyCallback* aCallback,
       
  1307                                       TUint aCmdOptions,
       
  1308                                       TInt aTransId)
       
  1309     Description     : This function parses the input param list
       
  1310                     : and calls the Cancel on the given transaction id
       
  1311     Return values   : TInt
       
  1312 -----------------------------------------------------------------------------
       
  1313 */
       
  1314 
       
  1315 TInt CContactInterface::CancelCommandL(const CLiwGenericParamList& aInParamList,
       
  1316 					        	       CLiwGenericParamList& aOutParamList)                                	   
       
  1317 	{
       
  1318             
       
  1319     TInt32 transactionID = 0;
       
  1320 	TInt errCode = KErrArgument;
       
  1321 	TInt pos = 0;
       
  1322     const TLiwGenericParam* param = NULL;
       
  1323     TLiwGenericParam posbasedparam;
       
  1324 
       
  1325             param = aInParamList.FindFirst( pos, KTransactionID );
       
  1326             if((!param) && (aInParamList.Count()<=0))
       
  1327                 {
       
  1328 		        aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1329 		                              TLiwVariant(KCancelTransIdMissing)));
       
  1330 		        User::Leave(KMissingArg);
       
  1331                 }
       
  1332 			else 
       
  1333 				{
       
  1334                 pos = 0;
       
  1335                 aInParamList.AtL( pos, posbasedparam );	
       
  1336                 
       
  1337                 if (posbasedparam.Value().IsEmpty() )
       
  1338                     {
       
  1339                     param = NULL;
       
  1340                     }
       
  1341                 else
       
  1342                     {
       
  1343                     param = &posbasedparam;           
       
  1344                     }
       
  1345 				}                 
       
  1346             if( param )
       
  1347 			    {
       
  1348 			    param->Value().Get( transactionID );
       
  1349                 errCode = iContactService->Cancel( transactionID );
       
  1350 			    }
       
  1351 	    return errCode;	
       
  1352 	}
       
  1353 	
       
  1354 	
       
  1355 /*
       
  1356 -----------------------------------------------------------------------------
       
  1357     CContactInterface::AddCommandL(const CLiwGenericParamList& aInParamList,
       
  1358                                    MLiwNotifyCallback* aCallback,
       
  1359                                    TUint aCmdOptions,
       
  1360                                    TInt aTransId)
       
  1361     Description     : This function parses the input param list
       
  1362                     : and calls the Add API
       
  1363     Return values   : TInt
       
  1364 -----------------------------------------------------------------------------
       
  1365 */
       
  1366 
       
  1367 void CContactInterface::AddCommandL(const CLiwGenericParamList& aInParamList,
       
  1368                                     CLiwGenericParamList& aOutParamList,
       
  1369                                     MLiwNotifyCallback* aCallback,
       
  1370                                     TUint aCmdOptions,
       
  1371                                     TInt aTransId)
       
  1372     {
       
  1373     TInt pos = 0;
       
  1374     const TLiwGenericParam* paramAddData = NULL;
       
  1375     const TLiwGenericParam* paramContentType = NULL;
       
  1376 
       
  1377 	if(aInParamList.Count()<2)
       
  1378 		{
       
  1379 		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,
       
  1380 		                       TLiwVariant(KAddLessArguments) ) );  
       
  1381 		
       
  1382 		User::Leave(KMissingArg); 
       
  1383 
       
  1384 		}
       
  1385 	//get the content type and add data.    
       
  1386 	paramContentType = aInParamList.FindFirst( pos, KType );
       
  1387 	if(!paramContentType)
       
  1388 		{
       
  1389 		paramContentType = &aInParamList[0];					    		
       
  1390 		if(!paramContentType || paramContentType->Name().Compare(KNullDesC8) != 0)
       
  1391 			{
       
  1392 			// Append error message 
       
  1393 			aOutParamList.AppendL(TLiwGenericParam (KErrorMessage,
       
  1394 			                      TLiwVariant(KAddContentTypeMissing)));  
       
  1395 
       
  1396 			User::Leave(KMissingArg); 
       
  1397 			}
       
  1398 		}
       
  1399 	
       
  1400 	pos = 0;
       
  1401     //Get the add data, the value of which is a Map
       
  1402     paramAddData = aInParamList.FindFirst( pos, KData );
       
  1403     if(!paramAddData)
       
  1404     	{
       
  1405     	paramAddData = &aInParamList[1];
       
  1406     	
       
  1407 		if(!paramAddData || paramAddData->Name().Compare(KNullDesC8) != 0)
       
  1408 			{
       
  1409 			// Append error message 
       
  1410 			aOutParamList.AppendL(TLiwGenericParam ( KErrorMessage,
       
  1411 			                      TLiwVariant(KAddDataMissing) ) );  	
       
  1412 			User::Leave(KMissingArg); 
       
  1413 			}
       
  1414     	}
       
  1415     
       
  1416 	//get the content type.
       
  1417 	TLiwVariant contentTypeVar  = paramContentType->Value();
       
  1418 	
       
  1419 	if(EVariantTypeDesC != contentTypeVar.TypeId())
       
  1420 		{
       
  1421 		contentTypeVar.Reset();
       
  1422 		aOutParamList.AppendL(TLiwGenericParam ( KErrorMessage,
       
  1423 		                      TLiwVariant(KAddWrongContentType) ) );  	
       
  1424 		User::Leave(KErrArgument); 
       
  1425 			
       
  1426 		}
       
  1427 
       
  1428     //if content type is "Contacts" then....
       
  1429     if(contentTypeVar.AsDes().CompareF(KContact) == 0 )
       
  1430         {
       
  1431         contentTypeVar.Reset();
       
  1432         //get the liw map from the add data generic parameter.
       
  1433         //if map is not null then call the function ProcesAddDataL(),
       
  1434         //which will parse the map and gets dburi and creates a new contact.
       
  1435         const CLiwMap* pMap = paramAddData->Value().AsMap();
       
  1436         if( pMap )
       
  1437             {            
       
  1438             //create a new contact.
       
  1439             CSingleContact* contact = CSingleContact::NewL();
       
  1440             CleanupStack::PushL(contact);
       
  1441             //call to ProcessAddDataL to parse the
       
  1442             //map and create a new contact.
       
  1443             ProcessAddDataL(pMap, contact, aOutParamList);
       
  1444             
       
  1445             if( aCmdOptions == KLiwOptASyncronous )
       
  1446                 {
       
  1447                 CContactInterfaceCallback* contactCallback =
       
  1448                     CContactInterfaceCallback::NewL(contact);
       
  1449 
       
  1450                 CleanupStack :: PushL(contactCallback);
       
  1451                 //set the callback parameter values.
       
  1452                 contactCallback->SetParams(aCallback,
       
  1453                                            aTransId,
       
  1454                                            &aInParamList);
       
  1455 
       
  1456                 //invoke the main method of contactService
       
  1457                 //to add/edit a contact/group
       
  1458                 //into the database.
       
  1459                     iContactService->AddL(contactCallback,
       
  1460                                           aTransId,
       
  1461                                           contact,
       
  1462                                           KNullDesC8, //group id
       
  1463                                           KNullDesC, //group label
       
  1464                                           *iDburi);
       
  1465 
       
  1466                 CleanupStack :: Pop(contactCallback);
       
  1467                 }
       
  1468             else
       
  1469                 {
       
  1470                 //it is assumed that the call is synchronous
       
  1471                 TRAPD(err,iContactService->AddL(contact,
       
  1472                                                 KNullDesC8, //group id
       
  1473                                                 KNullDesC, //group label
       
  1474                                                 *iDburi));
       
  1475                 if(err == KErrNotSupported)
       
  1476                     {
       
  1477                     TInt errkey  = iContactService->GetErrKey();
       
  1478                     TPtrC8 ptr = CSearchFields::GetFieldKeyFromId(errkey);
       
  1479             		TBuf<25> buff;
       
  1480                     buff.Copy(ptr);
       
  1481                     TBuf<KMaxName> errmsg(KAddFieldKeyNotSupported);    		
       
  1482             		errmsg.Append(buff);
       
  1483                     aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1484                                           TLiwVariant(errmsg))); 
       
  1485                     User::Leave(err);                          
       
  1486                     }
       
  1487                 }            
       
  1488             CleanupStack::Pop(contact);
       
  1489             } //end of if pMap
       
  1490         else
       
  1491             {
       
  1492             aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1493                                   TLiwVariant(KAddInvalidDataType)));     
       
  1494             User::Leave(KErrArgument);                          
       
  1495             }     
       
  1496         } //end of if contentType == KContact
       
  1497     //if content type is "Groups", then....
       
  1498     else if(contentTypeVar.AsDes().CompareF(KGroup)==0)
       
  1499         {
       
  1500         contentTypeVar.Reset();
       
  1501         //get the map from the addgroup data.
       
  1502         const CLiwMap* pMap = paramAddData->Value().AsMap();
       
  1503         if(pMap)
       
  1504             {
       
  1505             TLiwVariant valueGrpid;
       
  1506 		    CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueGrpid) );
       
  1507 
       
  1508             TLiwVariant valueGrplabel;
       
  1509 		    CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueGrplabel));
       
  1510             
       
  1511 			TLiwVariant valueUri;
       
  1512 		    CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueUri) );
       
  1513 
       
  1514 			//set the Db Uri to default database.
       
  1515             TPtrC dbUri(VPbkContactStoreUris::DefaultCntDbUri());
       
  1516 
       
  1517             TPtrC grpIdUnicode(KNullDesC);
       
  1518             TPtrC grpLabel(KNullDesC);
       
  1519 
       
  1520             HBufC8* groupId = NULL;                
       
  1521             if( EFalse != pMap->FindL(KDBUri,valueUri))
       
  1522             {
       
  1523             if( valueUri.AsDes().CompareF(KNullDesC) != 0 )
       
  1524                 {
       
  1525                 dbUri.Set(valueUri.AsDes());
       
  1526                 }
       
  1527             }
       
  1528         if(EFalse != pMap->FindL(KGroupId,valueGrpid)) 
       
  1529             {
       
  1530             TPtrC grpIdUnicode = valueGrpid.AsDes();      
       
  1531 			if(grpIdUnicode == NULL)
       
  1532 				{
       
  1533 				CleanupStack::Pop(&valueGrpid);
       
  1534 				valueGrpid.Reset();
       
  1535 				aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KAddInvalGrpId) ) );  	
       
  1536 				User::Leave(KErrArgument); 
       
  1537 				//Leave	
       
  1538 				}
       
  1539             //Convert the values back to the 8 bit descriptor.
       
  1540             groupId = ContactIDUTFToStreamL(grpIdUnicode);                
       
  1541             }
       
  1542         else
       
  1543             {
       
  1544             groupId = KNullDesC8().AllocL();    
       
  1545             }
       
  1546         //get the values for dburi, group id and group label           
       
  1547         if(EFalse != pMap->FindL(KGroupLabel,valueGrplabel))
       
  1548             {                
       
  1549 			if(EVariantTypeDesC != valueGrplabel.TypeId())	
       
  1550 				{
       
  1551 				CleanupStack::Pop(&valueGrplabel);
       
  1552 				valueGrplabel.Reset();
       
  1553 				CleanupStack::Pop(&valueGrpid);
       
  1554 				valueGrpid.Reset();
       
  1555 
       
  1556 				aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KAddInvalGrpLabel) ) );  	
       
  1557 				User::Leave(KErrArgument); 
       
  1558 				//Leave	
       
  1559 				}
       
  1560             if( valueGrplabel.AsDes().CompareF(KNullDesC) != 0)	
       
  1561 				{
       
  1562 				grpLabel.Set(valueGrplabel.AsDes());	
       
  1563 				}
       
  1564 			else
       
  1565 				{
       
  1566 				aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KAddGroupLabelEmpty) ) );  	
       
  1567 				User::Leave(KErrArgument); 
       
  1568 				}
       
  1569             }
       
  1570         else
       
  1571             {
       
  1572             aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1573                                   TLiwVariant(KAddLabelMissing)));
       
  1574                                   
       
  1575             User::Leave(KErrArgument);                          
       
  1576             }    
       
  1577         CleanupStack :: PushL(groupId);
       
  1578         //All the params are retrieved now call the main api.
       
  1579         if( aCmdOptions == KLiwOptASyncronous )
       
  1580             {
       
  1581             CContactInterfaceCallback* contactCallback =
       
  1582                 CContactInterfaceCallback::NewL();
       
  1583 
       
  1584             CleanupStack :: PushL(contactCallback);
       
  1585             //set the parameters for callback
       
  1586             contactCallback->SetParams(aCallback,
       
  1587                                        aTransId,
       
  1588                                        &aInParamList);
       
  1589 
       
  1590             //invoke the main method of the contactService to Add/Edit Group.
       
  1591             iContactService->AddL(contactCallback,
       
  1592                                   aTransId,
       
  1593                                   NULL,
       
  1594                                   *groupId,
       
  1595                                   grpLabel,
       
  1596                                   dbUri);
       
  1597 
       
  1598             CleanupStack :: Pop(contactCallback);
       
  1599             }
       
  1600         else
       
  1601             {
       
  1602             //it is assumed that the call is synchronous
       
  1603             TRAPD(err,iContactService->AddL(NULL,
       
  1604                                   *groupId,
       
  1605                                   grpLabel,
       
  1606                                   dbUri));
       
  1607             if(err == KErrNotSupported)
       
  1608                 {
       
  1609                 TInt errkey  = iContactService->GetErrKey();
       
  1610                 TPtrC8 ptr = CSearchFields::GetFieldKeyFromId(errkey);
       
  1611         		TBuf<25> buff;
       
  1612                 buff.Copy(ptr);
       
  1613                 TBuf<KMaxName> errmsg(KAddFieldKeyNotSupported);    		
       
  1614         		errmsg.Append(buff);
       
  1615                 aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1616                                       TLiwVariant(errmsg))); 
       
  1617                 User::Leave(err);                          
       
  1618                 } 
       
  1619                                          
       
  1620             }
       
  1621 	        CleanupStack :: PopAndDestroy(groupId); 
       
  1622 	        CleanupStack::Pop(&valueUri);
       
  1623 	        valueUri.Reset();
       
  1624 	        CleanupStack::Pop(&valueGrplabel);                         
       
  1625 	        valueGrplabel.Reset();
       
  1626 			CleanupStack::Pop(&valueGrpid);
       
  1627 			valueGrpid.Reset();
       
  1628 		  }
       
  1629          else
       
  1630             {
       
  1631             aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1632                                   TLiwVariant(KAddInvalidDataType)));    
       
  1633 			User::Leave(KMissingArg); 
       
  1634             }     
       
  1635 
       
  1636         }
       
  1637 	else
       
  1638 	    {
       
  1639         contentTypeVar.Reset();
       
  1640 
       
  1641 	    aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1642 	                          TLiwVariant(KAddInvalidContentType)));     
       
  1643         User::Leave(KErrArgument);                          
       
  1644 	    }
       
  1645 	 
       
  1646     }
       
  1647 
       
  1648 /*
       
  1649 -----------------------------------------------------------------------------
       
  1650     CContactInterface::ImportCommandL(const CLiwGenericParamList& aInParamList,
       
  1651                                       MLiwNotifyCallback* aCallback,
       
  1652                                       TUint aCmdOptions,
       
  1653                                       TInt aTransId)
       
  1654     Description     : This function parses the input param list
       
  1655                     : and calls the Import API
       
  1656     Return values   : TInt
       
  1657 -----------------------------------------------------------------------------
       
  1658 */
       
  1659 void CContactInterface::ImportCommandL(const CLiwGenericParamList& aInParamList,
       
  1660                                        CLiwGenericParamList& aOutParamList,
       
  1661                                        MLiwNotifyCallback* aCallback,
       
  1662                                        TUint aCmdOptions,
       
  1663                                        TInt aTransId)
       
  1664     {
       
  1665     TInt pos = 0;
       
  1666     const TLiwGenericParam* paramImportData = NULL;
       
  1667     const TLiwGenericParam* paramContentType = NULL;
       
  1668 
       
  1669     //get the content type and import data.
       
  1670     paramContentType = aInParamList.FindFirst( pos, KType );
       
  1671     
       
  1672 	if(!paramContentType)
       
  1673 		{
       
  1674 		
       
  1675 		if(aInParamList.Count()<2)
       
  1676 			{
       
  1677 					
       
  1678 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KImportLessArguments) ) );  	
       
  1679 			User::Leave(KMissingArg); 
       
  1680 			}
       
  1681 			paramContentType = &aInParamList[0] ;
       
  1682 			if(!paramContentType || paramContentType->Name().Compare(KNullDesC8) != 0)
       
  1683 				{
       
  1684 				// Append error message 
       
  1685 				aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KImportContentTypeMissing) ) );  	
       
  1686 				User::Leave(KMissingArg); 
       
  1687 				}
       
  1688 		}	
       
  1689 	pos = 0;
       
  1690     //Get the delete data, the value of which is a Map
       
  1691     paramImportData = aInParamList.FindFirst( pos, KData );
       
  1692     if(!paramImportData)
       
  1693     	{
       
  1694 		if(aInParamList.Count()>1)
       
  1695 			paramImportData = &aInParamList[1] ;
       
  1696 		if(!paramImportData || paramImportData->Name().Compare(KNullDesC8) != 0)
       
  1697 			{
       
  1698 			// Append error message
       
  1699 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KImportDataMissing) ) );  	
       
  1700 			User::Leave(KMissingArg); 
       
  1701 			}
       
  1702     	}	
       
  1703     
       
  1704 	TLiwVariant cnttent = paramContentType->Value();
       
  1705 	
       
  1706 	if(EVariantTypeDesC !=cnttent.TypeId())
       
  1707 		{
       
  1708 		cnttent.Reset();
       
  1709 		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KImportWrongContentType) ) );  	
       
  1710 		User::Leave(KErrArgument); 
       
  1711 			
       
  1712 		}
       
  1713 	cnttent.Reset();
       
  1714 
       
  1715     TPtrC contentType;
       
  1716 	contentType.Set(paramContentType->Value().AsDes());
       
  1717 
       
  1718 	// Check for content type
       
  1719 	
       
  1720 	if(contentType !=KContact)
       
  1721 		{
       
  1722 			
       
  1723 		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KImportInvalidContentType) ) );  
       
  1724 		User::Leave(KErrArgument);			
       
  1725 		}
       
  1726 
       
  1727         //get the liw map from the import data generic parameter.
       
  1728         //if map is not null then get db name, source file from the
       
  1729         //contact has to be imported.
       
  1730         const CLiwMap* pMap = paramImportData->Value().AsMap();
       
  1731         if(NULL != pMap)
       
  1732             {
       
  1733             TPtrC  dburi(VPbkContactStoreUris::DefaultCntDbUri());
       
  1734             TLiwVariant valueFname;
       
  1735             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueFname) );
       
  1736 
       
  1737             TLiwVariant valueUri;
       
  1738             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueUri) );
       
  1739 
       
  1740             if( EFalse != pMap->FindL(KDBUri,valueUri))
       
  1741                 {
       
  1742                  if(EVariantTypeDesC != valueUri.TypeId())
       
  1743 	                {
       
  1744 	                
       
  1745 	                CleanupStack::Pop(&valueUri);
       
  1746 	                valueUri.Reset();
       
  1747 	                aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1748 	                                  TLiwVariant(KImportDbUriNotString)));     
       
  1749 	          		User::Leave(KErrArgument);			
       
  1750 	                	
       
  1751 	                }
       
  1752    
       
  1753                 if(valueUri.AsDes().CompareF(KNullDesC)!=0)
       
  1754                     {
       
  1755                     dburi.Set(valueUri.AsDes());
       
  1756                     }
       
  1757                 }
       
  1758             if(EFalse != pMap->FindL(KSourceFileNameParam,valueFname))
       
  1759                 {
       
  1760                 //get the uri and filename.
       
  1761                 if(EVariantTypeDesC != valueFname.TypeId())
       
  1762 	                {
       
  1763 	                CleanupStack::Pop(&valueUri);
       
  1764 	                valueUri.Reset();
       
  1765 	                CleanupStack::Pop(&valueFname);
       
  1766 	                valueFname.Reset();
       
  1767 	                
       
  1768 	                aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1769 	                                  TLiwVariant(KImportSrcFileNotString)));     
       
  1770 	          		User::Leave(KErrArgument);			
       
  1771 	                	
       
  1772 	                }
       
  1773                 TPtrC filename = valueFname.AsDes();
       
  1774 				TInt length = filename.Length();
       
  1775 				
       
  1776 				if(length > KMaxFileName)
       
  1777 					{
       
  1778 					aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1779 				                  TLiwVariant(KImportFileNameTooLong)));
       
  1780 					User::Leave(KErrBadName);
       
  1781 					}
       
  1782                 
       
  1783                 if( aCmdOptions == KLiwOptASyncronous )
       
  1784                     {
       
  1785                     CContactInterfaceCallback* contactCallback =
       
  1786                         CContactInterfaceCallback::NewL();
       
  1787 
       
  1788                     CleanupStack::PushL(contactCallback);
       
  1789                     //if callback is not null, set the params like
       
  1790                     //callback, transid..etc
       
  1791                     contactCallback->SetParams(aCallback,
       
  1792                                                aTransId,
       
  1793                                                &aInParamList);
       
  1794                     //invoke the main method of contact service
       
  1795                     //to import the contact.
       
  1796                         iContactService->ImportVCardToStoreL(contactCallback,
       
  1797                     										 aTransId,
       
  1798                     										 filename,
       
  1799                     										 dburi);
       
  1800                     CleanupStack::Pop(contactCallback);
       
  1801 
       
  1802                     }
       
  1803                 else
       
  1804                     {
       
  1805                     //it is assumed that the call is synchronous
       
  1806                     iContactService->ImportVCardToStoreL(filename,
       
  1807                     								     dburi);
       
  1808                     }
       
  1809                 }
       
  1810             else
       
  1811                 {
       
  1812                 aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1813                                   TLiwVariant(KImportSrcFileNameMissing)));     
       
  1814                 User::Leave(KMissingArg);
       
  1815                 }    
       
  1816             CleanupStack::Pop(&valueUri);    
       
  1817             valueUri.Reset();
       
  1818             CleanupStack::Pop(&valueFname);
       
  1819             valueFname.Reset();
       
  1820             }
       
  1821             
       
  1822         else
       
  1823             {
       
  1824             aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1825                                   TLiwVariant(KImportDataMapMissing)));
       
  1826             User::Leave(KMissingArg);
       
  1827             }    
       
  1828     }
       
  1829 
       
  1830 /*
       
  1831 -----------------------------------------------------------------------------
       
  1832     CContactInterface::ExportCommandL(const CLiwGenericParamList& aInParamList,
       
  1833                                       MLiwNotifyCallback* aCallback,
       
  1834                                       TUint aCmdOptions,
       
  1835                                       TInt aTransId)
       
  1836     Description     : This function parses the input param list
       
  1837                     : and calls the Export API
       
  1838     Return values   : TInt
       
  1839 -----------------------------------------------------------------------------
       
  1840 */
       
  1841 void CContactInterface::ExportCommandL(const CLiwGenericParamList& aInParamList,
       
  1842                                        CLiwGenericParamList& aOutParamList,
       
  1843                                        MLiwNotifyCallback* aCallback,
       
  1844                                        TUint aCmdOptions,
       
  1845                                        TInt aTransId)
       
  1846     {
       
  1847     TInt pos = 0;
       
  1848     const TLiwGenericParam* paramExportData = NULL;
       
  1849     const TLiwGenericParam* paramContentType = NULL;
       
  1850     //get the content type and export data.
       
  1851     paramContentType = aInParamList.FindFirst( pos, KType );
       
  1852 
       
  1853 	//get the content type and export data.    
       
  1854 	if(!paramContentType)
       
  1855 		{
       
  1856 		
       
  1857 		if(aInParamList.Count()<2)
       
  1858 			{
       
  1859 					
       
  1860 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KExportLessArguments) ) );  	
       
  1861 			User::Leave(KMissingArg); 
       
  1862 			}
       
  1863 		
       
  1864 		paramContentType = &aInParamList[0] ;
       
  1865 		if(!paramContentType || paramContentType->Name().Compare(KNullDesC8) != 0)
       
  1866 			{
       
  1867 			// Append error message
       
  1868 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KExportContentTypeMissing) ) );  	
       
  1869 			User::Leave(KMissingArg); 
       
  1870 			}
       
  1871 		}
       
  1872 	
       
  1873 	pos = 0;
       
  1874     //Get the export data, the value of which is a Map
       
  1875     paramExportData = aInParamList.FindFirst( pos, KData );
       
  1876     if(!paramExportData)
       
  1877     	{
       
  1878 		if(aInParamList.Count()>1)
       
  1879     		paramExportData = &aInParamList[1] ;
       
  1880 		if(!paramExportData || paramExportData->Name().Compare(KNullDesC8) != 0)
       
  1881 			{
       
  1882 			// Append error message
       
  1883 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KExportDataMissing) ) );  	
       
  1884 			User::Leave(KMissingArg); 
       
  1885 			}
       
  1886     	}	
       
  1887 
       
  1888 	TLiwVariant cnttent = paramContentType->Value();
       
  1889 	
       
  1890 	if(EVariantTypeDesC !=cnttent.TypeId())
       
  1891 		{
       
  1892 		cnttent.Reset();
       
  1893 		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KExportWrongContentType) ) );  	
       
  1894 		User::Leave(KErrArgument); 
       
  1895 			
       
  1896 		}
       
  1897 	cnttent.Reset();
       
  1898     	
       
  1899 
       
  1900 
       
  1901     TPtrC contentType;
       
  1902 	contentType.Set(paramContentType->Value().AsDes());
       
  1903 
       
  1904 	// Check for content type
       
  1905 	if(contentType.Compare(KContact) != 0) 
       
  1906 		{
       
  1907 			
       
  1908 		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KExportInvalidContentType) ) );  
       
  1909 		User::Leave(KErrArgument);			
       
  1910 		}
       
  1911 
       
  1912         //get the liw map from the export data generic parameter.
       
  1913         //if map is not null then get db name, contact id and dest file
       
  1914         //to whi the contact has to be exported.
       
  1915         const CLiwMap* pMap = paramExportData->Value().AsMap();
       
  1916         if(NULL != pMap)
       
  1917             {
       
  1918             TLiwVariant valueFname;
       
  1919             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueFname) );
       
  1920 
       
  1921             TLiwVariant valueUri;
       
  1922             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueUri) );
       
  1923 
       
  1924             TPtrC dburi(VPbkContactStoreUris::DefaultCntDbUri());
       
  1925             if( EFalse != pMap->FindL(KDBUri,valueUri))
       
  1926                 {
       
  1927                 if(EVariantTypeDesC != valueUri.TypeId())
       
  1928 					{
       
  1929 					aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1930 					              TLiwVariant(KExportDbUriNotString)));
       
  1931 					User::Leave(KErrArgument);
       
  1932 
       
  1933 					}
       
  1934                 if(valueUri.AsDes().CompareF(KNullDesC)!=0)
       
  1935                     {
       
  1936                     dburi.Set(valueUri.AsDes());
       
  1937                     }
       
  1938                 }
       
  1939             if(EFalse != pMap->FindL(KDestFileNameParam,valueFname))
       
  1940                 {
       
  1941                 
       
  1942                 if(EVariantTypeDesC !=valueFname.TypeId() )
       
  1943 					{
       
  1944 					aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1945 					                  TLiwVariant(KExportDestnFlNmWrongType)));
       
  1946 					User::Leave(KErrArgument);
       
  1947 					}
       
  1948                 TLiwVariant valueCntid;
       
  1949                 CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueCntid) );
       
  1950 
       
  1951                 if(EFalse != pMap->FindL(KContactId,valueCntid))
       
  1952                     {
       
  1953                     //get dburi, filename and contact id parameters from the map.
       
  1954 					if(EVariantTypeDesC != valueCntid.TypeId())
       
  1955 						{
       
  1956 						aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1957 						                  TLiwVariant(KExportContactIdWrongType)));
       
  1958 						User::Leave(KErrArgument);
       
  1959 
       
  1960 						}
       
  1961 						TPtrC filename = valueFname.AsDes();
       
  1962 						TInt length = filename.Length();
       
  1963 						
       
  1964 						if(length > KMaxFileName)
       
  1965 							{
       
  1966 							aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  1967 						                  TLiwVariant(KExportFileNameTooLong)));
       
  1968 							User::Leave(KErrBadName);
       
  1969 							}
       
  1970 
       
  1971 	                    TPtrC cntIdUnicode = valueCntid.AsDes();
       
  1972                     
       
  1973                     HBufC8* cntid = ContactIDUTFToStreamL(cntIdUnicode);
       
  1974                     CleanupStack::PushL(cntid);                    
       
  1975 
       
  1976                     if( aCmdOptions == KLiwOptASyncronous )
       
  1977                         {
       
  1978                         CContactInterfaceCallback* contactCallback =
       
  1979                             CContactInterfaceCallback::NewL();
       
  1980                         CleanupStack :: PushL(contactCallback);
       
  1981                         //if callback is not null, set the params like callback, transid..etc
       
  1982                         contactCallback->SetParams(aCallback,
       
  1983                                                    aTransId,
       
  1984                                                    &aInParamList);
       
  1985                         //invoke the main method of contact service to export the contact.
       
  1986                             iContactService->ExportVCardL(contactCallback,
       
  1987                                     					  aTransId,
       
  1988                                     					  filename,
       
  1989                                     					  *cntid ,
       
  1990                                     					  dburi);
       
  1991                         CleanupStack :: Pop(contactCallback);
       
  1992                         }
       
  1993                     else
       
  1994                         {
       
  1995                         //it is assumed that the call is synchronous
       
  1996                         iContactService->ExportVCardL(filename,
       
  1997                                                       *cntid,
       
  1998                                                 	  dburi);
       
  1999 
       
  2000 
       
  2001                         }
       
  2002                     CleanupStack :: PopAndDestroy(cntid);
       
  2003                     } //end of if Find of cntid
       
  2004                 else
       
  2005 	                {
       
  2006 	                aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2007 	                                      TLiwVariant(KExportContactIdMissing)));    
       
  2008         			User::Leave(KMissingArg);
       
  2009 	                                      
       
  2010 	                } 
       
  2011 	            CleanupStack::Pop(&valueCntid);
       
  2012                 valueCntid.Reset();
       
  2013                 }
       
  2014             else
       
  2015                 {
       
  2016                 aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2017                                       TLiwVariant(KExportDstFileNameMissing)));    
       
  2018     		    User::Leave(KMissingArg);
       
  2019 
       
  2020                 }
       
  2021             CleanupStack::Pop(&valueUri);
       
  2022             valueUri.Reset();
       
  2023             CleanupStack::Pop(&valueFname);
       
  2024             valueFname.Reset();
       
  2025             }
       
  2026         else
       
  2027             {
       
  2028             aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2029                                   TLiwVariant(KExportDataMapMissing)));    
       
  2030 	        User::Leave(KMissingArg);
       
  2031 
       
  2032             }    
       
  2033     }
       
  2034 
       
  2035 /*
       
  2036 -----------------------------------------------------------------------------
       
  2037     CContactInterface::DeleteCommandL(const CLiwGenericParamList& aInParamList,
       
  2038                                       MLiwNotifyCallback* aCallback,
       
  2039                                       TUint aCmdOptions,
       
  2040                                       TInt aTransId)
       
  2041     Description     : This function parses the input param list
       
  2042                     : and calls the Delete API
       
  2043     Return values   : TInt
       
  2044 -----------------------------------------------------------------------------
       
  2045 */
       
  2046 void CContactInterface::DeleteCommandL(const CLiwGenericParamList& aInParamList,
       
  2047                                        CLiwGenericParamList& aOutParamList,
       
  2048                                        MLiwNotifyCallback* aCallback,
       
  2049                                        TUint aCmdOptions,
       
  2050                                        TInt aTransId)
       
  2051     {
       
  2052     TInt pos = 0;
       
  2053     const TLiwGenericParam* paramDeleteData = NULL;
       
  2054     const TLiwGenericParam* paramContentType = NULL;
       
  2055 
       
  2056     //get the content type and delete data.
       
  2057     paramContentType = aInParamList.FindFirst(pos, KType);
       
  2058 	if(!paramContentType)
       
  2059 		{
       
  2060 
       
  2061 		if(aInParamList.Count()<1)
       
  2062 			{
       
  2063 					
       
  2064 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KDeleteLessArguments) ) );  	
       
  2065 			User::Leave(KMissingArg); 
       
  2066 			}
       
  2067 		if(aInParamList.Count()>0)
       
  2068 			paramContentType = &aInParamList[0] ;	
       
  2069 		if(!paramContentType || paramContentType->Name().Compare(KNullDesC8) != 0)
       
  2070 			{
       
  2071 			
       
  2072 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KDeleteContentTypeMissing) ) );  	
       
  2073 			User::Leave(KMissingArg); 
       
  2074 			}
       
  2075 		}
       
  2076 	
       
  2077 	pos = 0;
       
  2078     //Get the delete data, the value of which is a Map
       
  2079     paramDeleteData = aInParamList.FindFirst( pos, KData );
       
  2080     if(!paramDeleteData)
       
  2081     	{
       
  2082     	if(aInParamList.Count()>1)
       
  2083     		paramDeleteData = &aInParamList[1] ;
       
  2084 		if(!paramDeleteData || paramDeleteData->Name().Compare(KNullDesC8) != 0)
       
  2085 			{
       
  2086 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KDeleteDataMissing) ) );  	
       
  2087 			User::Leave(KMissingArg); 
       
  2088 			}
       
  2089     	}
       
  2090 	
       
  2091 	//Get the content type
       
  2092 	TLiwVariant contentTypeVar  = paramContentType->Value();
       
  2093 	
       
  2094 	if(EVariantTypeDesC !=contentTypeVar.TypeId())
       
  2095 		{
       
  2096 		contentTypeVar.Reset();
       
  2097 		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KDeleteWrongContentType) ) );  	
       
  2098 		User::Leave(KErrArgument); 
       
  2099 		
       
  2100 			
       
  2101 		}
       
  2102 	
       
  2103     //either gorups or contacts
       
  2104     if(contentTypeVar.AsDes() == KContact || contentTypeVar.AsDes() == KGroup)
       
  2105         {
       
  2106         //get the map from the delete data generic parameter.
       
  2107         const CLiwMap* pMap = paramDeleteData->Value().AsMap();
       
  2108         if( pMap )
       
  2109             {
       
  2110             TLiwVariant valueList;
       
  2111             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueList) );
       
  2112 
       
  2113             TLiwVariant valueUri;
       
  2114             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueUri) );
       
  2115 
       
  2116             TLiwVariant valueId;
       
  2117             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueId) );
       
  2118 
       
  2119             TPtrC dbUri(VPbkContactStoreUris::DefaultCntDbUri());
       
  2120             const CLiwList* contactIdList = NULL;
       
  2121 
       
  2122             if( EFalse != pMap->FindL(KDBUri,valueUri))
       
  2123                 {
       
  2124                 if(valueUri.AsDes().CompareF(KNullDesC)!=0)
       
  2125                     {
       
  2126                     dbUri.Set(valueUri.AsDes());
       
  2127                     }
       
  2128                 }
       
  2129             //get the dbUri and contact id list from the map.
       
  2130             if(EFalse != pMap->FindL(KList,valueList) )
       
  2131                 {
       
  2132 				if(EVariantTypeList != valueList.TypeId())
       
  2133 					{
       
  2134 					aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KDeleteInvalidTypeIdList) ) );  	
       
  2135 					User::Leave(KErrArgument); 
       
  2136 					}
       
  2137                 contactIdList = valueList.AsList();
       
  2138 				
       
  2139                 //get the contact id count in the list.
       
  2140                 TInt idCount = contactIdList->Count();
       
  2141                 //create the array of contact ids from the liw list.
       
  2142                 RPointerArray<TDesC8> contactIdArray;
       
  2143                 for(TInt index = 0; index < idCount; index++)
       
  2144                     {
       
  2145                     contactIdList->AtL(index, valueId);
       
  2146 					if(EVariantTypeDesC !=valueId.TypeId())
       
  2147 						{
       
  2148 						aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KDeleteInvalidIdType) ) );  	
       
  2149 						User::Leave(KErrArgument); 
       
  2150 						}
       
  2151                     
       
  2152                     TPtrC cntidptr = valueId.AsDes();
       
  2153                     HBufC8* cntid = ContactIDUTFToStreamL(cntidptr);
       
  2154                     CleanupStack :: PushL(cntid);                        
       
  2155                     contactIdArray.AppendL(cntid);
       
  2156                     CleanupStack :: Pop(cntid);
       
  2157 
       
  2158                     }
       
  2159                 if(aCmdOptions == KLiwOptASyncronous)
       
  2160                     {
       
  2161                     CContactInterfaceCallback* contactCallback =
       
  2162                         CContactInterfaceCallback::NewL();
       
  2163 
       
  2164                     CleanupStack :: PushL(contactCallback);
       
  2165                     //set the basic params of callback object.
       
  2166                     contactCallback->SetParams(aCallback,
       
  2167                                                aTransId,
       
  2168                                                &aInParamList);
       
  2169                     //invoke the main method of contactservice
       
  2170                     //to delete the list
       
  2171                     //contacts/groups.
       
  2172                         iContactService->DeleteL(contactCallback,
       
  2173                                     			 aTransId,
       
  2174                                     			 contactIdArray,
       
  2175                                     			 dbUri);
       
  2176 
       
  2177                     CleanupStack :: Pop(contactCallback);
       
  2178                     }
       
  2179                 else
       
  2180                     {
       
  2181                     //it is assumed that the call is synchronous
       
  2182                     iContactService->DeleteL(contactIdArray,
       
  2183                                              dbUri);
       
  2184                     }
       
  2185 
       
  2186                 }//if pMap
       
  2187             else
       
  2188                 {
       
  2189                 aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2190                                       TLiwVariant(KDeleteDataListMissing)));
       
  2191 				User::Leave(KMissingArg); 
       
  2192                 }   
       
  2193             CleanupStack::Pop(&valueId);
       
  2194             valueId.Reset();
       
  2195             CleanupStack::Pop(&valueUri);
       
  2196             valueUri.Reset();
       
  2197             CleanupStack::Pop(&valueList);
       
  2198             valueList.Reset();
       
  2199             }
       
  2200         else
       
  2201             {
       
  2202             aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2203                           TLiwVariant(KDeleteDataMapMissing)));    
       
  2204 			User::Leave(KMissingArg); 
       
  2205             } 
       
  2206         contentTypeVar.Reset();
       
  2207         }//if ContentType == KContact or KGroup
       
  2208     else
       
  2209         {
       
  2210         aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2211                           TLiwVariant(KDeleteInvalidContentType)));     
       
  2212         User::Leave(KErrArgument); 
       
  2213         }    
       
  2214     }
       
  2215 
       
  2216 /*
       
  2217 -----------------------------------------------------------------------------
       
  2218     CContactInterface::OrganiseGroupCommandL(const CLiwGenericParamList& aInParamList,
       
  2219                                              MLiwNotifyCallback* aCallback,
       
  2220                                              TUint aCmdOptions,
       
  2221                                              TInt aTransId)
       
  2222     Description     : This function parses the input param list
       
  2223                     : and calls the Organise API
       
  2224     Return values   : TInt
       
  2225 -----------------------------------------------------------------------------
       
  2226 */
       
  2227 void CContactInterface::OrganiseGroupCommandL(const CLiwGenericParamList& aInParamList,
       
  2228                                               CLiwGenericParamList& aOutParamList,
       
  2229                                               MLiwNotifyCallback* aCallback,
       
  2230                                               TUint aCmdOptions,
       
  2231                                               TInt aTransId)
       
  2232     {
       
  2233     TInt position = 0;
       
  2234     const TLiwGenericParam* paramOrganiseData = NULL;
       
  2235     const TLiwGenericParam* paramOperationType = NULL;
       
  2236     const TLiwGenericParam* paramContentType = NULL;
       
  2237 
       
  2238     //get the content type and Organise data.
       
  2239 	paramContentType = aInParamList.FindFirst( position, KType );
       
  2240 	if(!paramContentType)
       
  2241 		{
       
  2242 		if(aInParamList.Count()<3)
       
  2243 			{
       
  2244 
       
  2245 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KOrganiseLessArguments) ) );  	
       
  2246 			User::Leave(KMissingArg); 
       
  2247 			}
       
  2248 		
       
  2249 	
       
  2250 		paramContentType = &aInParamList[0] ;
       
  2251 		if(!paramContentType || paramContentType->Name().Compare(KNullDesC8) != 0)
       
  2252 			{
       
  2253 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KOrganiseContentTypeMissing) ) );  	
       
  2254 			User::Leave(KMissingArg); 
       
  2255 			}
       
  2256 		}
       
  2257 
       
  2258 	position = 0;
       
  2259     //Get the orgainse  data, the value of which is a Map
       
  2260     paramOrganiseData = aInParamList.FindFirst( position, KData );
       
  2261     if(!paramOrganiseData)
       
  2262     	{
       
  2263     	if(aInParamList.Count()>2)
       
  2264     		paramOrganiseData = &aInParamList[1] ;
       
  2265 		if(!paramOrganiseData || paramOrganiseData->Name().Compare(KNullDesC8) != 0)
       
  2266 			{
       
  2267 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KOrganiseDataMissing) ) );  	
       
  2268 			User::Leave(KMissingArg); 
       
  2269 			}
       
  2270     	}	
       
  2271 
       
  2272 	position = 0;
       
  2273     //Get the operation type, the value of which is a Map
       
  2274     paramOperationType = aInParamList.FindFirst( position, KOperationType );
       
  2275     if(!paramOperationType)
       
  2276     	{
       
  2277     	if(aInParamList.Count() == 3)
       
  2278     		paramOperationType = &aInParamList[2] ;
       
  2279 		if(!paramOperationType || paramOperationType->Name().Compare(KNullDesC8) != 0)
       
  2280 			{
       
  2281 			aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KOrganiseOperationTypeMissing) ) );  	
       
  2282 			User::Leave(KMissingArg); 
       
  2283 			}
       
  2284     	}	    	
       
  2285 
       
  2286     //get the content type..
       
  2287 	TLiwVariant contentTypeVar  = paramContentType->Value();
       
  2288 	
       
  2289 	if(EVariantTypeDesC !=contentTypeVar.TypeId())
       
  2290 		{
       
  2291 		contentTypeVar.Reset();
       
  2292 		aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KOrganiseWrongContentType) ) );  
       
  2293 
       
  2294 		User::Leave(KErrArgument); 
       
  2295 		}
       
  2296 
       
  2297     //if content type is " Groups", then....
       
  2298    	 if( contentTypeVar.AsDes() == KGroup)
       
  2299         {
       
  2300         //get the pointer to map in the organise data.
       
  2301         const CLiwMap* pMap = paramOrganiseData->Value().AsMap();
       
  2302         if( pMap )
       
  2303             {
       
  2304             TLiwVariant valueGroupid;
       
  2305             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueGroupid) );
       
  2306 
       
  2307             TLiwVariant valueList;
       
  2308             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueList) );
       
  2309             
       
  2310 			TLiwVariant valueUri;
       
  2311             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueUri) );
       
  2312 
       
  2313             TPtrC dbUri(VPbkContactStoreUris::DefaultCntDbUri());
       
  2314             TBool associateType = EFalse;
       
  2315             HBufC8* groupId = NULL;
       
  2316 
       
  2317 			if(EVariantTypeDesC != paramOperationType->Value().TypeId() )
       
  2318 				{
       
  2319 				aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KOrganiseOperationTypeWrong) ) );  	
       
  2320 				User::Leave(KErrArgument); 
       
  2321 				}
       
  2322 
       
  2323             if(paramOperationType->Value().AsDes().Compare(KAssociate)==0)
       
  2324                 {
       
  2325                 associateType = ETrue;
       
  2326                 }
       
  2327             else if(paramOperationType->Value().AsDes().Compare(KDissociate)==0)
       
  2328                 {
       
  2329                 associateType = EFalse;
       
  2330                 }
       
  2331             else
       
  2332                 {
       
  2333                 aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2334                           TLiwVariant(KOrganiseDataInvalidOpType)));
       
  2335                 User::Leave(KErrArgument);
       
  2336                 }
       
  2337 
       
  2338             const CLiwList* contactIdList = NULL;
       
  2339             //get the values for dburi, groupid, associatetype and id list.
       
  2340             if( EFalse != pMap->FindL(KDBUri,valueUri))
       
  2341                 {
       
  2342                 if(valueUri.AsDes().CompareF(KNullDesC)!=0)
       
  2343                     {
       
  2344                     dbUri.Set(valueUri.AsDes());
       
  2345                     }
       
  2346                 }
       
  2347                 
       
  2348             if(EFalse != pMap->FindL(KGroupId,valueGroupid))
       
  2349                 {
       
  2350 			 	if(EVariantTypeDesC != valueGroupid.TypeId())
       
  2351 				 	{
       
  2352 					aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KOrganiseWrongGrpIdType) ) );  	
       
  2353 
       
  2354 			        User::Leave(KErrArgument);
       
  2355 				 	}
       
  2356                 TPtrC grpid = valueGroupid.AsDes();
       
  2357                 groupId = ContactIDUTFToStreamL(grpid);                   
       
  2358                 }
       
  2359             else
       
  2360                 {
       
  2361                 aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2362                           TLiwVariant(KOrganiseGrpIdMissing)));
       
  2363                 User::Leave(KMissingArg);
       
  2364                 }
       
  2365                 
       
  2366              if(EFalse != pMap->FindL(KList,valueList))
       
  2367                 {
       
  2368 				if(EVariantTypeList != valueList.TypeId())
       
  2369 					{
       
  2370 					aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KOrganiseWrongIdListType) ) );  	
       
  2371 			        User::Leave(KErrArgument);
       
  2372 					}
       
  2373                 contactIdList = valueList.AsList();
       
  2374                 }
       
  2375             else
       
  2376                 {
       
  2377                 aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2378                           TLiwVariant(KOrganiseDataListMissing)));
       
  2379                 User::Leave(KMissingArg);
       
  2380                 }
       
  2381 
       
  2382             CleanupStack :: PushL(groupId);
       
  2383             //get the number of contact ids in the list.
       
  2384             TInt idCount = contactIdList->Count();
       
  2385             if(idCount == 0)
       
  2386 		        {
       
  2387 				aOutParamList.AppendL( TLiwGenericParam ( KErrorMessage,TLiwVariant(KOrganiseEmptyIdList) ) );  	
       
  2388 		        User::Leave(KErrArgument);
       
  2389 	            }
       
  2390             TLiwVariant valueId;
       
  2391             CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &valueId) );
       
  2392 
       
  2393             //create the contact id array and append the ids from the list to this
       
  2394             //contactIdArray
       
  2395             RPointerArray<TDesC8> contactIdArray;
       
  2396             CleanupClosePushL(contactIdArray);
       
  2397             
       
  2398             for(TInt index = 0; index < idCount; index++)
       
  2399                 {
       
  2400                 contactIdList->AtL(index, valueId);
       
  2401 				if(EVariantTypeDesC != valueId.TypeId())
       
  2402 					{
       
  2403 		            aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2404 		                      TLiwVariant(KOrganiseWrongIdType)));
       
  2405 		            User::Leave(KErrArgument);
       
  2406 					}
       
  2407              
       
  2408                 TPtrC cntIdUnicode = valueId.AsDes();
       
  2409                 HBufC8* cntid = ContactIDUTFToStreamL(cntIdUnicode);
       
  2410                 CleanupStack :: PushL(cntid);                    
       
  2411                 contactIdArray.AppendL(cntid);
       
  2412                 }
       
  2413             if(aCmdOptions == KLiwOptASyncronous)
       
  2414                 {
       
  2415                 CContactInterfaceCallback* contactCallback =
       
  2416                     CContactInterfaceCallback::NewL();
       
  2417 
       
  2418                 CleanupStack :: PushL(contactCallback);
       
  2419                 //Set the params of the contact callback
       
  2420                 contactCallback->SetParams(aCallback,
       
  2421                                            aTransId,
       
  2422                                            &aInParamList);
       
  2423                 //invoke the main method of the contactService
       
  2424                 //to Associate/Disassocite
       
  2425                 //list of contacts to/from the group.
       
  2426                     iContactService->OrganiseGroupsL(contactCallback,
       
  2427                         							 aTransId,
       
  2428                         							 *groupId,
       
  2429                         							 contactIdArray,
       
  2430                         							 associateType,
       
  2431                         							 dbUri);
       
  2432 
       
  2433                 CleanupStack :: Pop(contactCallback);
       
  2434                 }
       
  2435             else
       
  2436                 {
       
  2437                 //it is assumed that the call is synchronous
       
  2438                 iContactService->OrganiseGroupsL(*groupId,
       
  2439                                 				 contactIdArray,
       
  2440                                 				 associateType,
       
  2441                                 				 dbUri);
       
  2442                 }
       
  2443             //cleanup
       
  2444             CleanupStack::PopAndDestroy(contactIdArray.Count());
       
  2445             CleanupStack::PopAndDestroy();
       
  2446             CleanupStack::Pop(&valueId);
       
  2447             valueId.Reset();
       
  2448             CleanupStack::PopAndDestroy(groupId);
       
  2449             CleanupStack::Pop(&valueUri);
       
  2450             valueUri.Reset();
       
  2451             CleanupStack::Pop(&valueList);
       
  2452             valueList.Reset();
       
  2453             CleanupStack::Pop(&valueGroupid);
       
  2454             valueGroupid.Reset();
       
  2455             }
       
  2456         else
       
  2457             {
       
  2458             aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2459                           TLiwVariant(KOrganiseDataMapMissing)));  
       
  2460             User::Leave(KMissingArg);
       
  2461                             
       
  2462             }    
       
  2463         contentTypeVar.Reset();
       
  2464         }
       
  2465     else
       
  2466 	    {
       
  2467 	    aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
  2468 	                  TLiwVariant(KOrganiseInvalidContentType)));  
       
  2469 	    User::Leave(KMissingArg);
       
  2470 	    }
       
  2471     }