messagingfw/msgsrvnstore/server/src/MCLIENT.CPP
changeset 22 bde600d88860
parent 0 8e480a14352b
child 31 b9e74fff3740
child 34 b66b8f3a7fd8
equal deleted inserted replaced
21:08008ce8a6df 22:bde600d88860
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <s32std.h>
       
    17 #include <s32mem.h>
       
    18 
       
    19 
       
    20 #include "MSVIPC.H"
       
    21 #include "MSERVER.H"
       
    22 #include "MSVREGIP.H"
       
    23 
       
    24 #include "MCLIENT.H"
       
    25 #include "MCLENTRY.H"
       
    26 #include "MSVPANIC.H"
       
    27 #include "MSVAPI.H"
       
    28 #include "MsvSecurityCapabilitySet.h"
       
    29 #include <mmsvstoremanager.h>
       
    30 #include <tmsvsystemprogress.h>
       
    31 #include <tnonoperationmtmdata.h>
       
    32 
       
    33 _LIT(KMsvServerExe, "msexe.exe");
       
    34 
       
    35 #if defined _UNICODE
       
    36 const TUid KMsvMsexExeUid={0x1000484B};
       
    37 #else
       
    38 const TUid KMsvMsexExeUid={0x1000484A};
       
    39 #endif
       
    40 
       
    41 const TInt KMsvRetryTimeout=100000;
       
    42 const TInt KMsvRetryCount=10;
       
    43 
       
    44 static TInt StartServer()
       
    45 	{
       
    46 	const TUidType serverUid(KNullUid, KNullUid, KMsvMsexExeUid);
       
    47 	RProcess server;
       
    48 	TInt r = server.Create(KMsvServerExe, KNullDesC, serverUid);
       
    49 
       
    50 	if( r != KErrNone )
       
    51 		return r;
       
    52 	
       
    53 	TRequestStatus status;
       
    54 	server.Rendezvous(status);
       
    55 	if( status != KRequestPending )
       
    56 		server.Kill(0); // abort start-up
       
    57 	else
       
    58 		server.Resume();	// wait for server start-up.
       
    59 	User::WaitForRequest(status);
       
    60 	
       
    61 	// If the server panics on start-up, then exit reason may still be zero,
       
    62 	// which is not distinguishable from KErrNone.		
       
    63 	r = (server.ExitType() == EExitPanic ) ? KErrGeneral : status.Int();
       
    64 	server.Close();
       
    65 	return r;	
       
    66 	}
       
    67 
       
    68 //********************************
       
    69 //RMsvServerSession
       
    70 //**********************************
       
    71 
       
    72 /**
       
    73 Constructor.
       
    74 
       
    75 @capability None
       
    76 */
       
    77 EXPORT_C RMsvServerSession::RMsvServerSession()
       
    78 : iBuffer(NULL)
       
    79 	{}
       
    80 
       
    81 
       
    82 /**
       
    83 Destructor.
       
    84 
       
    85 @capability None
       
    86 */
       
    87 EXPORT_C RMsvServerSession::~RMsvServerSession()
       
    88 	{
       
    89 	delete iBuffer;
       
    90 	}
       
    91 
       
    92 #if defined (__EPOC32__)
       
    93 /**
       
    94 Connect to the messaging server, and starts it if is not already running.
       
    95  
       
    96 The default number of message slots is 14.
       
    97 
       
    98 @param aFs File server handle
       
    99 @return System wide error codes
       
   100 
       
   101 @capability None
       
   102 */
       
   103 EXPORT_C TInt RMsvServerSession::Connect(RFs& aFs)
       
   104 #else
       
   105 EXPORT_C TInt RMsvServerSession::Connect(RFs& /*aFs*/)
       
   106 #endif
       
   107 	{
       
   108 	if (iBuffer==NULL)
       
   109 		{
       
   110 		iBuffer = HBufC8::New(KMsvSessionBufferLength);
       
   111 		if (iBuffer==NULL)
       
   112 			return KErrNoMemory;
       
   113 		}
       
   114 
       
   115 
       
   116 	TInt retry = KMsvRetryCount;
       
   117 	FOREVER
       
   118 		{
       
   119 		TInt r = CreateSession(KMsvServerName, Version(), KMsvNumberOfSlots);
       
   120 	 	if( r != KErrNotFound && r != KErrServerTerminated && r != KErrServerBusy )
       
   121 			return r;
       
   122 		if( --retry == 0 )
       
   123 			return r;
       
   124 		if( r == KErrServerBusy )
       
   125 			User::After(KMsvRetryTimeout);
       
   126 		r = StartServer();
       
   127 		if( r != KErrNone && r != KErrAlreadyExists )
       
   128 			return r;		
       
   129 		}
       
   130 
       
   131 	}
       
   132 
       
   133 	
       
   134 /**
       
   135 Gets the version number of the server.
       
   136 
       
   137 @return Version number
       
   138 
       
   139 @capability None
       
   140 */
       
   141 EXPORT_C TVersion RMsvServerSession::Version(void) const
       
   142 	{
       
   143 	return(TVersion(KMsvServerMajorVersionNumber,KMsvServerMinorVersionNumber,KMsvServerBuildVersionNumber));
       
   144 	}
       
   145 
       
   146 
       
   147 /** 
       
   148 Makes a request for session event notifications.
       
   149 
       
   150 @param aChange Packaged notification information (a TMsvNotifBuffer object)
       
   151 @param aSequence notification sequence number (a packaged TUint) 
       
   152 @param aRequestStatus Asynchronous request status
       
   153 
       
   154 @capability None
       
   155 */
       
   156 EXPORT_C void RMsvServerSession::QueueSessionEventRequest(TDes8& aChange, TDes8& aSequence, TRequestStatus& aRequestStatus)
       
   157 	{
       
   158 	SendReceive(EMsvNotifySessionEvent, TIpcArgs(&aChange,&aSequence), aRequestStatus);
       
   159 	}
       
   160 
       
   161 /**
       
   162 Cancels a request for session event notifications.
       
   163 
       
   164 @return System wide error codes
       
   165 
       
   166 @capability None
       
   167 */
       
   168 EXPORT_C TInt RMsvServerSession::CancelSessionEventRequest()
       
   169 	{
       
   170 	return SendReceive(EMsvCancelSessionEventNotification);
       
   171 	}
       
   172 
       
   173 
       
   174 /**
       
   175 Set a session as an observer only.
       
   176 
       
   177 @return System wide error codes
       
   178 
       
   179 @capability None
       
   180 */
       
   181 TInt RMsvServerSession::SetSessionAsObserver()
       
   182 	{
       
   183 	return SendReceive(EMsvSetSessionAsObserver);
       
   184 	}
       
   185 
       
   186 void RMsvServerSession::SendEntryDataL(TMsvOp aOperationId, const TMsvEntry& aEntry)
       
   187 //
       
   188 // Sends the entry data in a synchronous call
       
   189 //
       
   190 	{
       
   191 	// package up the entry into a packed entry
       
   192 	TMsvPackedEntry packedEntry(iBuffer);
       
   193 	TInt error = packedEntry.PackEntry(aEntry);
       
   194 	while(error!=KErrNone)
       
   195 		{
       
   196 		// increase the size of the buffer and try again
       
   197 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
   198 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
   199 		error = packedEntry.PackEntry(aEntry);
       
   200 		}
       
   201 
       
   202 	// pass data to the server
       
   203 	User::LeaveIfError(SendReceive(EMsvOperationData, TIpcArgs(aOperationId,iBuffer)));
       
   204 	}
       
   205 
       
   206 void RMsvServerSession::SendOperationDataL(TMsvOp aOperationId, const CMsvEntrySelection& aSelection, TInt aParameter1, TInt aParameter2)
       
   207 //
       
   208 // Sends the operation data in a synchronous call
       
   209 //
       
   210 	{
       
   211 	PackOperationDataL(aSelection, aParameter1, aParameter2);
       
   212 
       
   213 	// package up the entry into a packed entry
       
   214 	User::LeaveIfError(SendReceive(EMsvOperationData, TIpcArgs(aOperationId,iBuffer)));
       
   215 	}
       
   216 
       
   217 void RMsvServerSession::PackOperationDataL(const CMsvEntrySelection& aSelection, TInt aParameter1, TInt aParameter2)
       
   218 	{
       
   219 	TMsvPackedOperation packedOperation(iBuffer);
       
   220 	TInt error = packedOperation.Pack(aSelection, aParameter1, aParameter2);
       
   221 	while(error!=KErrNone)
       
   222 		{
       
   223 		// increase the size of the buffer and try again
       
   224 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
   225 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
   226 		error = packedOperation.Pack(aSelection, aParameter1, aParameter2);
       
   227 		}
       
   228 	}
       
   229 
       
   230 void RMsvServerSession::SendCommandDataL(TMsvOp aOperationId, const CMsvEntrySelection& aSelection, TInt aCommand, const TDesC8& aParameter)
       
   231 //
       
   232 // Sends the operation data in a synchronous call
       
   233 //
       
   234 	{
       
   235 	TMsvPackedOperation packedOperation(iBuffer);
       
   236 	TInt error = packedOperation.Pack(aSelection, aCommand);
       
   237 	while(error!=KErrNone)
       
   238 		{
       
   239 		// increase the size of the buffer and try again
       
   240 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
   241 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
   242 		error = packedOperation.Pack(aSelection, aCommand);
       
   243 		}
       
   244 
       
   245 	// package up the entry into a packed entry
       
   246 	User::LeaveIfError(SendReceive(EMsvCommandData, TIpcArgs(aOperationId,iBuffer,&aParameter)));
       
   247 	}
       
   248 
       
   249 
       
   250 
       
   251 /**
       
   252 Creates an entry in the message server index (asynchronously) with the supplied owner ID.
       
   253 
       
   254 @param aEntry Entry to create
       
   255 @param aOperationId Operation identifier
       
   256 @param aOwnerId The ID of the owning process
       
   257 @param aRequestStatus Asynchronous request status
       
   258 
       
   259 @capability None A client with no capabilities can create an entry only if the entry is    
       
   260 under a local service, is in an unprotected folder, is not a service entry, and, if part of 
       
   261 an existing message, if that message is owned by the client.  
       
   262 
       
   263 @capability WriteDeviceData Required if the entry is a service. 
       
   264 
       
   265 @capability ReadUserData Required in some circumstances: see the note below.   
       
   266 
       
   267 @capability WriteUserData Required in some circumstances: see the note below.
       
   268 
       
   269 @capability Note The capabilities required to create an entry that is not a service vary depending on the 
       
   270 following conditions:  
       
   271 
       
   272 -# Entry to be created is part of an existing message: 
       
   273 	-# Entry is under the local service:
       
   274 		-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   275 		-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   276 		-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   277 		-# Entry is in an unprotected folder and the existing entry is not owned by the client: ReadUserData + WriteUserData
       
   278 		-# Entry is in an unprotected folder and the existing entry is owned by the client: no capabilities
       
   279 	-# Entry is under a remote service:
       
   280 		-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   281 		-# The Outbox is unprotected and the existing entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   282 		-# The Outbox is unprotected and the existing entry is not owned by the client: ReadUserData + WriteUserData + 
       
   283 		MTM-specified capabilities (of the MTM for the remote service)
       
   284 -# Entry to be created is not part of an existing message: 
       
   285 	-# Entry is under the local service:
       
   286 		-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   287 		-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   288 		-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   289 		-# Entry is in an unprotected folder: no capabilities
       
   290 	-# Entry is under a remote service:
       
   291 		-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   292 		-# The Outbox is unprotected: MTM-specified capabilities (of the MTM for the remote service) 
       
   293 
       
   294 @internalComponent
       
   295 */
       
   296 EXPORT_C void RMsvServerSession::CreateEntryL(const TMsvEntry& aEntry, TMsvOp aOperationId, TSecureId aOwnerId, TRequestStatus& aRequestStatus)
       
   297 //
       
   298 // Creates an entry in the index for aEntry.
       
   299 //
       
   300 	{
       
   301 	TestSlotAvailableL();
       
   302 	SendEntryDataL(aOperationId, aEntry);
       
   303 	aRequestStatus=KRequestPending;
       
   304 	SendReceive(EMsvCreateEntry, TIpcArgs(aOperationId, aOwnerId), aRequestStatus);
       
   305 	}
       
   306 
       
   307 
       
   308 
       
   309 /**
       
   310 Creates an entry in the message server index (synchronously).
       
   311 
       
   312 @param aEntry Entry to create
       
   313 @param aOperationId Operation identifier
       
   314 @param aOwnerId The ID of the owning process
       
   315 
       
   316 @capability None A client with no capabilities can create an entry only if the entry is    
       
   317 under a local service, is in an unprotected folder, is not a service entry, and, if part of 
       
   318 an existing message, if that message is owned by the client.  
       
   319 
       
   320 @capability WriteDeviceData Required if the entry is a service. 
       
   321 
       
   322 @capability ReadUserData Required in some circumstances: see the note below.   
       
   323 
       
   324 @capability WriteUserData Required in some circumstances: see the note below.
       
   325 
       
   326 @capability Note The capabilities required to create an entry that is not a service vary depending on the 
       
   327 following conditions:  
       
   328 
       
   329 -# Entry to be created is part of an existing message: 
       
   330 	-# Entry is under the local service:
       
   331 		-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   332 		-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   333 		-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   334 		-# Entry is in an unprotected folder and the existing entry is not owned by the client: ReadUserData + WriteUserData
       
   335 		-# Entry is in an unprotected folder and the existing entry is owned by the client: no capabilities
       
   336 	-# Entry is under a remote service:
       
   337 		-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   338 		-# The Outbox is unprotected and the existing entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   339 		-# The Outbox is unprotected and the existing entry is not owned by the client: ReadUserData + WriteUserData + 
       
   340 		MTM-specified capabilities (of the MTM for the remote service)
       
   341 -# Entry to be created is not part of an existing message: 
       
   342 	-# Entry is under the local service:
       
   343 		-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   344 		-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   345 		-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   346 		-# Entry is in an unprotected folder: no capabilities
       
   347 	-# Entry is under a remote service:
       
   348 		-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   349 		-# The Outbox is unprotected: MTM-specified capabilities (of the MTM for the remote service) 
       
   350 
       
   351 @internalComponent
       
   352 */
       
   353 EXPORT_C void RMsvServerSession::CreateEntryL(const TMsvEntry& aEntry, TMsvOp aOperationId, TSecureId aOwnerId)
       
   354 //
       
   355 // Creates an entry in the index for aEntry.
       
   356 //
       
   357 	{
       
   358 	TestSlotAvailableL();
       
   359 	SendEntryDataL(aOperationId, aEntry);
       
   360 	User::LeaveIfError(SendReceive(EMsvCreateEntry,TIpcArgs(aOperationId, aOwnerId)));
       
   361 	}
       
   362 
       
   363 
       
   364 	
       
   365 /**
       
   366 Changes the contents of a message server entry (asynchronously).
       
   367 
       
   368 @param aEntry Entry to change
       
   369 @param aOperationId Operation identifier
       
   370 @param aOwnerId The ID of the owning process
       
   371 @param aRequestStatus Asynchronous request status
       
   372 
       
   373 @capability None A client with no capabilities can access an entry only if the entry is    
       
   374 under a local service, is owned by the client, is in an unprotected folder,  
       
   375 and is not a service entry. 
       
   376 
       
   377 @capability WriteDeviceData Required if the entry is a service. 
       
   378 
       
   379 @capability ReadUserData Required in some circumstances: see the note below.   
       
   380 
       
   381 @capability WriteUserData Required in some circumstances: see the note below.
       
   382 
       
   383 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   384 following conditions:  
       
   385 
       
   386 - Entry is under the local service:
       
   387 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   388 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   389 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   390 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   391 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   392 
       
   393 - Entry is under a remote service:
       
   394 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   395 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   396 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   397 	MTM-specified capabilities (of the MTM for the remote service)
       
   398 
       
   399 @internalComponent
       
   400 */
       
   401 EXPORT_C void RMsvServerSession::ChangeEntryL(const TMsvEntry& aEntry, TMsvOp aOperationId, TSecureId aOwnerId, TRequestStatus& aRequestStatus)
       
   402 //
       
   403 // Changes the content of an entry
       
   404 //
       
   405 	{
       
   406 	TestSlotAvailableL();
       
   407 	SendEntryDataL(aOperationId, aEntry);
       
   408 	aRequestStatus=KRequestPending;
       
   409 	SendReceive(EMsvChangeEntry, TIpcArgs(aOperationId, aOwnerId), aRequestStatus);
       
   410 	}
       
   411 
       
   412 
       
   413 
       
   414 
       
   415 /**
       
   416 Changes the contents of a message server entry (synchronously).
       
   417 
       
   418 @param aEntry Entry to create
       
   419 @param aOwnerId The ID of the owning process
       
   420 @param aOperationId Operation identifier
       
   421 
       
   422 @capability None A client with no capabilities can access an entry only if the entry is    
       
   423 under a local service, is owned by the client, is in an unprotected folder,  
       
   424 and is not a service entry. 
       
   425 
       
   426 @capability WriteDeviceData Required if the entry is a service. 
       
   427 
       
   428 @capability ReadUserData Required in some circumstances: see the note below.   
       
   429 
       
   430 @capability WriteUserData Required in some circumstances: see the note below.
       
   431 
       
   432 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   433 following conditions:  
       
   434 
       
   435 - Entry is under the local service:
       
   436 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   437 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   438 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   439 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   440 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   441 
       
   442 - Entry is under a remote service:
       
   443 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   444 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   445 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   446 	MTM-specified capabilities (of the MTM for the remote service)
       
   447 
       
   448 @internalComponent
       
   449 */
       
   450 EXPORT_C void RMsvServerSession::ChangeEntryL(const TMsvEntry& aEntry, TMsvOp aOperationId, TSecureId aOwnerId)
       
   451 //
       
   452 // Changes the content of an entry
       
   453 //
       
   454 	{
       
   455 	TestSlotAvailableL();
       
   456 	SendEntryDataL(aOperationId, aEntry);
       
   457 	User::LeaveIfError(SendReceive(EMsvChangeEntry, TIpcArgs(aOperationId, aOwnerId)));
       
   458 	}
       
   459 
       
   460 
       
   461 /**
       
   462 Gets the index entry with the specified unique id.
       
   463 @param aId ID of the entry to get
       
   464 @param aService On return, the ID of the service to which the entry belongs
       
   465 @param aEntry On return, the index entry with the specified ID
       
   466 @return System wide error code
       
   467 
       
   468 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
   469 
       
   470 @capability ReadUserData This is required to access any entry where the condition 
       
   471 described for no capabilities does not apply.
       
   472 */
       
   473 EXPORT_C TInt RMsvServerSession::GetEntry(TMsvId aId, TMsvId& aService, TMsvEntry& aEntry)
       
   474 	{
       
   475 	TRAPD(error, DoGetEntryL(aId, aService, aEntry));
       
   476 	return error;
       
   477 	}
       
   478 
       
   479 void RMsvServerSession::DoGetEntryL(TMsvId aId, TMsvId& aService, TMsvEntry& aEntry)
       
   480 	{
       
   481 	// pass the buffer to receive the data through
       
   482 	TPtr8 ptr=iBuffer->Des();
       
   483 	// get the service the entry i sunder
       
   484 	TPckg<TMsvId> service(aService);
       
   485 	// signal the server
       
   486 	TInt error = SendReceive(EMsvGetEntry,TIpcArgs(aId,&ptr,&service));
       
   487 	while(error == KErrOverflow)
       
   488 		{
       
   489 		// increase the size of the buffer and try again
       
   490 		iBuffer->Des().SetLength(0);
       
   491 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
   492 		// pass the buffer to receive the data through
       
   493 		TPtr8 ptr=iBuffer->Des();
       
   494 		error = SendReceive(EMsvGetEntry,TIpcArgs(aId,&ptr,&service));
       
   495 		}
       
   496 	User::LeaveIfError(error);
       
   497 	TMsvPackedEntry packedEntry(iBuffer);
       
   498 	packedEntry.UnpackEntry(aEntry);
       
   499 	}
       
   500 
       
   501 /**
       
   502 Gets the children of the index entry with the specified unique id.
       
   503 
       
   504 @param aId ID of the entry to get
       
   505 @param aEntries On return, the entry's children. If an error is returned, aEntries is unchanged.
       
   506 @param aOrdering Sorting and grouping rules for the returned entries
       
   507 @return System wide error code
       
   508 
       
   509 @capability None Only children that the client owns are returned. 
       
   510 
       
   511 @capability ReadUserData All children of the entry are returned
       
   512 */
       
   513 EXPORT_C TInt RMsvServerSession::GetChildren(TMsvId aId, CArrayPtrFlat<CMsvClientEntry>& aEntries, const TMsvSelectionOrdering& aOrdering)
       
   514 	{
       
   515 	TInt origCount=aEntries.Count();
       
   516 	TRAPD(leave, DoGetChildrenL(aId, aEntries, aOrdering));
       
   517 	if (leave!=KErrNone)
       
   518 		{
       
   519 		TInt count=aEntries.Count();
       
   520 		while (count>origCount)
       
   521 			{
       
   522 			delete aEntries.At(--count);
       
   523 			aEntries.Delete(count);
       
   524 			}
       
   525 		}
       
   526 	return leave;
       
   527 	}
       
   528 
       
   529 
       
   530 void RMsvServerSession::DoGetChildrenL(TMsvId aId, CArrayPtrFlat<CMsvClientEntry>& aEntries, const TMsvSelectionOrdering& aOrdering)
       
   531 //
       
   532 // Gets the children of the index entry with the Unique id aId.
       
   533 //
       
   534 	{
       
   535 	// package up the Id into a children details class
       
   536 	TPckgBuf<TMsvChildrenDetails> details;
       
   537 	details().iParentId = aId;
       
   538 	// pass the sort order
       
   539 	TPckgC<TMsvSelectionOrdering> package2(aOrdering);
       
   540 	// pass the buffer to receive the data through
       
   541 	TPtr8 ptr=iBuffer->Des();
       
   542 	// signal the server
       
   543 	TInt error = SendReceive(EMsvGetChildren, TIpcArgs(&details,&package2,&ptr));
       
   544 		
       
   545 	if (error!=KErrNone && error!=KErrOverflow)
       
   546 		User::Leave(error);
       
   547 
       
   548 	// unpack the entries from the buffer
       
   549 	TMsvPackedEntryArray packedEntryArray(iBuffer);
       
   550 	for (TInt count=0; count<details().iNumberChildrenInArray; count++)
       
   551 		{
       
   552 		TMsvEntry entry;
       
   553 		User::LeaveIfError(packedEntryArray.UnpackEntry(count, entry));
       
   554 		CMsvClientEntry* cEntry = CMsvClientEntry::NewLC(entry, EMsvClientChild);
       
   555 		aEntries.AppendL(cEntry);
       
   556 		CleanupStack::Pop(); // cEntry
       
   557 		}
       
   558 	
       
   559 	// if there are more entries - get them
       
   560 	if (error==KErrOverflow)
       
   561 		DoGetRemainingChildrenL(details, aEntries);
       
   562 	}
       
   563 
       
   564 void RMsvServerSession::DoGetRemainingChildrenL(TPckgBuf<TMsvChildrenDetails>& aDetails, CArrayPtrFlat<CMsvClientEntry>& aEntries)
       
   565 //
       
   566 // Gets the remaining children 
       
   567 //
       
   568 	{
       
   569 	TInt error=KErrOverflow;
       
   570 	while (error==KErrOverflow)
       
   571 		{
       
   572 		// package up the Id into a children details class & pass the buffer to receive the data through
       
   573 		TPtr8 ptr=iBuffer->Des();
       
   574 		// get some more entries
       
   575 		error = SendReceive(EMsvGetRemainingChildren,TIpcArgs(&aDetails,NULL,&ptr));
       
   576 		if (error!=KErrNone && error!=KErrOverflow)
       
   577 			User::Leave(error);
       
   578 
       
   579 		if (aDetails().iNumberChildrenInArray == 0)
       
   580 			{
       
   581 			if (error == KErrOverflow)
       
   582 				{
       
   583 				// The buffer isn't big enough for the current entry
       
   584 				// we must resize the buffer or we're in an infinite loop
       
   585 				iBuffer->Des().SetLength(0);
       
   586 				iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
   587 				}
       
   588 			}
       
   589 		else
       
   590 			{
       
   591 			// unpack the entries from the buffer
       
   592 			TMsvPackedEntryArray packedEntryArray(iBuffer);
       
   593 			for (TInt count=0; count<aDetails().iNumberChildrenInArray; count++)
       
   594 				{
       
   595 				TMsvEntry entry;
       
   596 				User::LeaveIfError(packedEntryArray.UnpackEntry(count, entry));
       
   597 				CMsvClientEntry* cEntry = CMsvClientEntry::NewLC(entry, EMsvClientChild);
       
   598 				aEntries.AppendL(cEntry);
       
   599 				CleanupStack::Pop(); // cEntry
       
   600 				}
       
   601 			}
       
   602 		}
       
   603 	}
       
   604 
       
   605 
       
   606 
       
   607 /**
       
   608 Delete the specified message server entries (asynchronously).
       
   609 
       
   610 @param aSelection Entries to delete
       
   611 @param aOperationId Operation identifier
       
   612 @param aRequestStatus Asynchronous request status
       
   613 
       
   614 @capability None A client with no capabilities can access an entry only if the entry is    
       
   615 under a local service, is owned by the client, is in an unprotected folder,  
       
   616 and is not a service entry. 
       
   617 
       
   618 @capability WriteDeviceData Required if the entry is a service. 
       
   619 
       
   620 @capability ReadUserData Required in some circumstances: see the note below.   
       
   621 
       
   622 @capability WriteUserData Required in some circumstances: see the note below.
       
   623 
       
   624 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   625 following conditions:  
       
   626 
       
   627 - Entry is under the local service:
       
   628 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   629 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   630 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   631 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   632 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   633 
       
   634 - Entry is under a remote service:
       
   635 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   636 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   637 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   638 	MTM-specified capabilities (of the MTM for the remote service)
       
   639 */
       
   640 EXPORT_C void RMsvServerSession::DeleteEntriesL(const CMsvEntrySelection& aSelection, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
   641 	{
       
   642 	TestSlotAvailableL();
       
   643 	// send the data to the server
       
   644 	SendOperationDataL(aOperationId, aSelection);
       
   645 	// start the operation
       
   646 	aRequestStatus=KRequestPending;
       
   647 	SendReceive(EMsvDeleteEntries, TIpcArgs(aOperationId), aRequestStatus);
       
   648 	}
       
   649 
       
   650 
       
   651 /**
       
   652 Delete the specified message server entries (synchronously).
       
   653 
       
   654 @param aSelection Entries to delete
       
   655 @param aOperationId Operation identifier
       
   656 
       
   657 @capability None A client with no capabilities can access an entry only if the entry is    
       
   658 under a local service, is owned by the client, is in an unprotected folder,  
       
   659 and is not a service entry. 
       
   660 
       
   661 @capability WriteDeviceData Required if the entry is a service. 
       
   662 
       
   663 @capability ReadUserData Required in some circumstances: see the note below.   
       
   664 
       
   665 @capability WriteUserData Required in some circumstances: see the note below.
       
   666 
       
   667 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   668 following conditions:  
       
   669 
       
   670 - Entry is under the local service:
       
   671 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   672 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   673 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   674 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   675 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   676 
       
   677 - Entry is under a remote service:
       
   678 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   679 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   680 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   681 	MTM-specified capabilities (of the MTM for the remote service)
       
   682 */
       
   683 EXPORT_C void RMsvServerSession::DeleteEntriesL(const CMsvEntrySelection& aSelection, TMsvOp aOperationId)
       
   684 	{
       
   685 	TestSlotAvailableL();
       
   686 	// send the data to the server
       
   687 	SendOperationDataL(aOperationId, aSelection);
       
   688 	User::LeaveIfError(SendReceive(EMsvDeleteEntries, TIpcArgs(aOperationId)));
       
   689 	}
       
   690 
       
   691 /**
       
   692 Locks a message server entry.
       
   693 
       
   694 This prevents it from being accessed by other clients. 
       
   695 
       
   696 This function is intended only for test purposes.
       
   697 
       
   698 @param aId ID of the entry to lock
       
   699 @return System wide error code
       
   700 @see RMsvServerSession::ReleaseEntry
       
   701 
       
   702 @capability Note When the __REMOVE_MESSAGING_API_V1__ macro is defined, the
       
   703 function is policed against the capabilities of the message server (Read/Write Device Data, 
       
   704 Protected Server, Network Control, Network Services, Local Services and Read 
       
   705 User Data). When the macro is not defined, the function is not policed. 
       
   706 */
       
   707 EXPORT_C TInt RMsvServerSession::LockEntry(TMsvId aId)
       
   708 	{
       
   709 	return SendReceive(EMsvLockEntry, TIpcArgs(aId));
       
   710 	}
       
   711 
       
   712 
       
   713 /**
       
   714 Releases the lock on an entry.
       
   715 
       
   716 This function is intended only for test purposes.
       
   717 
       
   718 @param aId ID of the locked entry to release
       
   719 @return System wide error code
       
   720 @see RMsvServerSession::LockEntry
       
   721 
       
   722 @capability Note When the __REMOVE_MESSAGING_API_V1__ macro is defined, the
       
   723 function is policed against the capabilities of the message server (Read/Write Device Data, 
       
   724 Protected Server, Network Control, Network Services, Local Services and Read 
       
   725 User Data). When the macro is not defined, the function is not policed. 
       
   726 */
       
   727 EXPORT_C TInt RMsvServerSession::ReleaseEntry(TMsvId aId)
       
   728 	{
       
   729 	return SendReceive(EMsvReleaseEntry, TIpcArgs(aId));
       
   730 	}
       
   731 
       
   732 
       
   733 /**
       
   734 Tests if a client can read from a specified message store.
       
   735 A locked store cannot be read from.
       
   736 
       
   737 @param aId ID of the entry that owns the store
       
   738 @return KErrNone if the store can be read from; another system wide error code if not.
       
   739 
       
   740 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
   741 
       
   742 @capability ReadUserData This is required to access any entry where the condition 
       
   743 described for no capabilities does not apply.
       
   744 */
       
   745 EXPORT_C TInt RMsvServerSession::ReadStore(TMsvId aId)
       
   746 	{
       
   747 	// package an TInt to get the id back
       
   748 	return SendReceive(EMsvReadStore, TIpcArgs(aId));
       
   749 	}
       
   750 
       
   751 
       
   752 /**
       
   753 Locks a store for writing.
       
   754 
       
   755 @param aId ID of the entry that owns the store
       
   756 @return System wide error code
       
   757 @see RMsvServerSession::ReleaseStore
       
   758 
       
   759 @capability None A client with no capabilities can access an entry only if the entry is    
       
   760 under a local service, is owned by the client, is in an unprotected folder,  
       
   761 and is not a service entry. 
       
   762 
       
   763 @capability WriteDeviceData Required if the entry is a service. 
       
   764 
       
   765 @capability ReadUserData Required in some circumstances: see the note below.   
       
   766 
       
   767 @capability WriteUserData Required in some circumstances: see the note below.
       
   768 
       
   769 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   770 following conditions:  
       
   771 
       
   772 - Entry is under the local service:
       
   773 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   774 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   775 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   776 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   777 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   778 
       
   779 - Entry is under a remote service:
       
   780 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   781 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   782 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   783 	MTM-specified capabilities (of the MTM for the remote service)
       
   784 */
       
   785 EXPORT_C TInt RMsvServerSession::LockStore(TMsvId aId)
       
   786 	{
       
   787 	// package an TInt to get the id back
       
   788 	return SendReceive(EMsvLockStore, TIpcArgs(aId));
       
   789 	}
       
   790 
       
   791 /**
       
   792 Releases the lock on a store.
       
   793 
       
   794 @param aId ID of the entry that owns the store
       
   795 @return System wide error code
       
   796 @see RMsvServerSession::LockStore
       
   797 
       
   798 @capability None A client with no capabilities can access an entry only if the entry is    
       
   799 under a local service, is owned by the client, is in an unprotected folder,  
       
   800 and is not a service entry. 
       
   801 
       
   802 @capability WriteDeviceData Required if the entry is a service. 
       
   803 
       
   804 @capability ReadUserData Required in some circumstances: see the note below.   
       
   805 
       
   806 @capability WriteUserData Required in some circumstances: see the note below.
       
   807 
       
   808 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   809 following conditions:  
       
   810 
       
   811 - Entry is under the local service:
       
   812 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   813 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   814 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   815 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   816 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   817 
       
   818 - Entry is under a remote service:
       
   819 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   820 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   821 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   822 	MTM-specified capabilities (of the MTM for the remote service)
       
   823 */
       
   824 EXPORT_C TInt RMsvServerSession::ReleaseStore(TMsvId aId)
       
   825 	{
       
   826 	return SendReceive(EMsvReleaseStore, TIpcArgs(aId));
       
   827 	}
       
   828 
       
   829 
       
   830 /**
       
   831 Decrements the number of readers on a store.
       
   832 
       
   833 @param aId ID of the entry that owns the store
       
   834 @return System wide error code
       
   835 
       
   836 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
   837 
       
   838 @capability ReadUserData This is required to access any entry where the condition 
       
   839 described for no capabilities does not apply.
       
   840 */
       
   841 TInt RMsvServerSession::DecStoreReaderCount(TMsvId aId)
       
   842 	{
       
   843 	return SendReceive(EMsvDecStoreReaderCount,TIpcArgs(aId));
       
   844 	}
       
   845 
       
   846 
       
   847 /**
       
   848 Closes the message server.
       
   849 
       
   850 The function results in the session sending a shutdown session notification 
       
   851 (TMsvSessionEvent::EMsvCloseSession) to all current sessions. The Message 
       
   852 Server closes when all sessions have been closed.
       
   853  
       
   854 @capability WriteDeviceData
       
   855 */
       
   856 EXPORT_C void RMsvServerSession::CloseMessageServer()
       
   857 	{
       
   858 	SendReceive(EMsvCloseServer);
       
   859 	}
       
   860 
       
   861 
       
   862 /**
       
   863 Gets registry information for the MTMs for a specified MTM DLL type (client, server, UI, UI data).  
       
   864 
       
   865 @param aMtmDllTypeUid UID of the MTM DLL type
       
   866 @param aRegisteredMtmDllArray On return, an array of registry information for the MTMs of the specified type.
       
   867 @param aTimeoutMicroSeconds32 
       
   868 @return System wide error code
       
   869 
       
   870 @capability None
       
   871 */
       
   872 EXPORT_C TInt RMsvServerSession::FillRegisteredMtmDllArray(TUid aMtmDllTypeUid,CRegisteredMtmDllArray& aRegisteredMtmDllArray,TTimeIntervalMicroSeconds32 aTimeoutMicroSeconds32)
       
   873 	{
       
   874 	// pass the buffer to receive the data through
       
   875 	TPtr8 ptr=iBuffer->Des();
       
   876 	// signal the server
       
   877 	TInt error = SendReceive(EMsvFillRegisteredMtmDllArray,TIpcArgs(aMtmDllTypeUid.iUid, &ptr));
       
   878 	if (error==KErrNone)
       
   879 		{
       
   880 		RDesReadStream readStream(*iBuffer);
       
   881 		TRAP(error, TMsvPackedRegisteredMtmDllArray::UnpackRegisteredMtmDllArrayL(readStream, aRegisteredMtmDllArray, aTimeoutMicroSeconds32, *this));
       
   882 		}
       
   883 
       
   884 	return error;
       
   885 	}
       
   886 
       
   887 /**
       
   888 Installs a new MTM group.
       
   889  
       
   890 @param aFullName The full path name of the MTM group file
       
   891 @return System wide error code
       
   892 
       
   893 @capability WriteDeviceData
       
   894 */
       
   895 EXPORT_C TInt RMsvServerSession::InstallMtmGroup(const TDesC& aFullName)
       
   896 	{
       
   897 	return SendReceive(EMsvInstallMtmGroup,TIpcArgs(&aFullName));
       
   898 	}
       
   899 
       
   900 /**
       
   901 Uninstalls an MTM group.
       
   902  
       
   903 @param aFullName The full path name of the MTM group file
       
   904 @return System wide error code
       
   905 
       
   906 @capability WriteDeviceData
       
   907 */
       
   908 EXPORT_C TInt RMsvServerSession::DeInstallMtmGroup(const TDesC& aFullName)
       
   909 	{
       
   910 	return SendReceive(EMsvDeInstallMtmGroup,TIpcArgs(&aFullName));
       
   911 	}
       
   912 
       
   913 /**
       
   914 Increments the usage reference count for a specified MTM group. 
       
   915 
       
   916 @param aMtmTypeUid MTM group UID
       
   917 @return System wide error code
       
   918 @see RMsvServerSession::ReleaseMtmGroup
       
   919 
       
   920 @capability None
       
   921 */
       
   922 EXPORT_C TInt RMsvServerSession::UseMtmGroup(TUid aMtmTypeUid)
       
   923 	{
       
   924 	// package up the Id of the entry required
       
   925 	return SendReceive(EMsvUseMtmGroup,TIpcArgs(aMtmTypeUid.iUid));
       
   926 	}
       
   927 
       
   928 /**
       
   929 Decrements the usage reference count for a specified MTM group.
       
   930 
       
   931 @param aMtmTypeUid MTM group UID
       
   932 @return System wide error code
       
   933 
       
   934 @capability None
       
   935 */
       
   936 EXPORT_C TInt RMsvServerSession::ReleaseMtmGroup(TUid aMtmTypeUid)
       
   937 	{
       
   938 	// package up the Id of the entry required
       
   939 	return SendReceive(EMsvReleaseMtmGroup,TIpcArgs(aMtmTypeUid.iUid));
       
   940 	}
       
   941 
       
   942 /**
       
   943 Gets the registration data for an MTM group.
       
   944 
       
   945 @param aMtmTypeUid MTM group UID
       
   946 @return Registration data for the specified MTM group
       
   947 @leave System wide error code
       
   948 
       
   949 @capability None
       
   950 */
       
   951 EXPORT_C CMtmGroupData* RMsvServerSession::GetMtmGroupDataL(TUid aMtmTypeUid)
       
   952 	{
       
   953 	TPtr8 ptr=iBuffer->Des();
       
   954 	// package up the Id of the entry required and pass the buffer to receive the data through
       
   955 	User::LeaveIfError(SendReceive(EMsvGetMtmGroupData,TIpcArgs(aMtmTypeUid.iUid,&ptr)));
       
   956 	RDesReadStream readStream(*iBuffer);
       
   957 	return CMtmGroupData::NewL(readStream);
       
   958 	}
       
   959 
       
   960 
       
   961 /**
       
   962 Gets capabilities required to use the specified MTM.
       
   963 
       
   964 @param aMtmTypeUid MTM UID
       
   965 @param aCapSet On return, capabilities required to use the specified MTM.
       
   966 
       
   967 @capability None
       
   968 */
       
   969 void RMsvServerSession::GetMtmRequiredCapabilitiesL(TUid aMtmTypeUid, TCapabilitySet& aCapSet) const
       
   970 	{
       
   971 	TPtr8 ptr=iBuffer->Des();
       
   972 	User::LeaveIfError(SendReceive(EMsvGetMtmRequiredCapabilities, TIpcArgs(aMtmTypeUid.iUid, &ptr)));
       
   973 	RDesReadStream readStream(*iBuffer);
       
   974 	MsvSecurityCapabilitySetUtils::InternalizeL(readStream,aCapSet);
       
   975 	}
       
   976 	
       
   977 
       
   978 /**
       
   979 Cancels a specified operation.
       
   980 
       
   981 @param aId Operation identifier
       
   982 @param aProgress On return, progress information for the operation
       
   983 @return System wide error code
       
   984 
       
   985 @capability None
       
   986 */
       
   987 EXPORT_C TInt RMsvServerSession::CancelOperation(TMsvOp aId, TDes8& aProgress)
       
   988 	{
       
   989 	TInt ret = SendReceive(EMsvCancelOperation, TIpcArgs(aId,&aProgress));
       
   990 	if (ret>0)
       
   991 		{
       
   992 		aProgress.SetLength(ret);
       
   993 		ret=KErrNone;
       
   994 		}
       
   995 	else
       
   996 		{
       
   997 		aProgress.SetLength(0);
       
   998 		if (ret==KErrNotReady)
       
   999 			ret=KErrNone;
       
  1000 		}
       
  1001 	return ret;
       
  1002 	}
       
  1003 
       
  1004 
       
  1005 /**
       
  1006 Gets progress information for an operation.
       
  1007 
       
  1008 @param aId Operation identifier
       
  1009 @param aProgress On return, progress information for the operation
       
  1010 @return System wide error code
       
  1011 
       
  1012 @capability None
       
  1013 */
       
  1014 EXPORT_C TInt RMsvServerSession::OperationProgress(TMsvOp aId, TDes8& aProgress)
       
  1015 	{
       
  1016 	TInt ret = SendReceive(EMsvOperationProgress, TIpcArgs(aId,&aProgress));
       
  1017 	if (ret>0)
       
  1018 		{
       
  1019 		aProgress.SetLength(ret);
       
  1020 		ret=KErrNone;
       
  1021 		}
       
  1022 	else
       
  1023 		aProgress.SetLength(0);
       
  1024 	return ret;
       
  1025 	}
       
  1026 
       
  1027 /**
       
  1028 Obtains the progress information that is defined by and understood by the system as well as client MTM's
       
  1029 
       
  1030 @param aId Operation identifier
       
  1031 @param aProgress On return, progress information for the operation
       
  1032 @return System wide error code
       
  1033 
       
  1034 @capability None
       
  1035 */
       
  1036 EXPORT_C TInt RMsvServerSession::OperationSystemProgress(TMsvOp aId, TMsvSystemProgress& aProgress)
       
  1037 	{
       
  1038 	TPckg<TMsvSystemProgress> sysProgressPkg(aProgress);
       
  1039 	return SendReceive(EMsvOperationSystemProgress, TIpcArgs(aId,&sysProgressPkg));
       
  1040 	}
       
  1041 
       
  1042 /**
       
  1043 Obtains the final progress information for an operation.
       
  1044 The associated server side objects are then deleted.
       
  1045 
       
  1046 @param aId Operation identifier
       
  1047 @param aProgress On return, progress information for the operation
       
  1048 @return System wide error code
       
  1049 
       
  1050 @capability None
       
  1051 */
       
  1052 EXPORT_C TInt RMsvServerSession::OperationCompletion(TMsvOp aId, TDes8& aProgress)
       
  1053 	{
       
  1054 	TInt ret = SendReceive(EMsvOperationCompletion, TIpcArgs(aId,&aProgress));
       
  1055 	if (ret>0)
       
  1056 		{
       
  1057 		aProgress.SetLength(ret);
       
  1058 		ret=KErrNone;
       
  1059 		}
       
  1060 	else
       
  1061 		aProgress.SetLength(0);
       
  1062 	return ret;
       
  1063 	}
       
  1064 
       
  1065 
       
  1066 /**
       
  1067 Moves the specified message server entries (asynchronously).
       
  1068 
       
  1069 @param aSelection The IDs of the entry to move. On return, contains the children that could not be fully moved. 
       
  1070 @param aTarget The ID of the new parent 
       
  1071 @param aOperationId Operation identifier
       
  1072 @param aRequestStatus Asynchronous request status
       
  1073 
       
  1074 @capability None A client with no capabilities can move an entry only if both source and target entries
       
  1075 are under a local service, are owned by the client, and are in an unprotected folder.
       
  1076 
       
  1077 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1078 
       
  1079 @capability WriteUserData Required in some circumstances: see the note below.
       
  1080 
       
  1081 @capability Note The function tests that the caller has capabilities to modify the 
       
  1082 the source entry (see RMsvServerSession::ChangeEntryL) and to create under the target
       
  1083 entry (see RMsvServerSession::CreateEntryL).
       
  1084 */
       
  1085 EXPORT_C void RMsvServerSession::MoveEntriesL(const CMsvEntrySelection& aSelection, TMsvId aTarget, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
  1086 	{
       
  1087 	TestSlotAvailableL();
       
  1088 	// send the data to the server
       
  1089 	SendOperationDataL(aOperationId, aSelection, aTarget);
       
  1090 	// start the operation
       
  1091 	aRequestStatus=KRequestPending;
       
  1092 	SendReceive(EMsvMoveEntries, TIpcArgs(aOperationId), aRequestStatus);
       
  1093 	}
       
  1094 
       
  1095 /**
       
  1096 Moves the specified message server entries (synchronously).
       
  1097 
       
  1098 @param aSelection The IDs of the entry to move. On return, contains the children that could not be fully moved. 
       
  1099 @param aTarget The ID of the new parent entry
       
  1100 @param aOperationId Operation identifier
       
  1101 
       
  1102 @capability None A client with no capabilities can move an entry only if both source and target entries
       
  1103 are under a local service, are owned by the client, and are in an unprotected folder.
       
  1104 
       
  1105 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1106 
       
  1107 @capability WriteUserData Required in some circumstances: see the note below.
       
  1108 
       
  1109 @capability Note The function tests that the caller has capabilities to modify the 
       
  1110 the source entry (see RMsvServerSession::ChangeEntryL) and to create under the target
       
  1111 entry (see RMsvServerSession::CreateEntryL).
       
  1112 */
       
  1113 EXPORT_C void RMsvServerSession::MoveEntriesL(const CMsvEntrySelection& aSelection, TMsvId aTarget, TMsvOp aOperationId)
       
  1114 	{
       
  1115 	TestSlotAvailableL();
       
  1116 	// send the data to the server
       
  1117 	SendOperationDataL(aOperationId, aSelection, aTarget);
       
  1118 	// start the operation
       
  1119 	User::LeaveIfError(SendReceive(EMsvMoveEntries, TIpcArgs(aOperationId)));
       
  1120 	}
       
  1121 
       
  1122 /**
       
  1123 Copies the specified message server entries (synchronously).
       
  1124 
       
  1125 @param aSelection The IDs of the source entries to copy. On return, contains the children that could not be fully copied. 
       
  1126 @param aTarget The ID of the destination parent entry
       
  1127 @param aOperationId Operation identifier
       
  1128 
       
  1129 @capability None A client with no capabilities can copy an entry only if both source and target entries
       
  1130 are under a local service, are owned by the client, and are in an unprotected folder.
       
  1131 
       
  1132 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1133 
       
  1134 @capability WriteUserData Required in some circumstances: see the note below.
       
  1135 
       
  1136 @capability Note The function tests that the caller has capabilities to create under the 
       
  1137 target entry (see RMsvServerSession::CreateEntryL).
       
  1138 */
       
  1139 EXPORT_C void RMsvServerSession::CopyEntriesL(const CMsvEntrySelection& aSelection, TMsvId aTarget, TMsvOp aOperationId)
       
  1140 	{
       
  1141 	TestSlotAvailableL();
       
  1142 	// send the data to the server
       
  1143 	SendOperationDataL(aOperationId, aSelection, aTarget);
       
  1144 	// start the operation
       
  1145 	User::LeaveIfError(SendReceive(EMsvCopyEntries, TIpcArgs(aOperationId)));
       
  1146 	}
       
  1147 
       
  1148 
       
  1149 /**
       
  1150 Copies the specified message server entries (asynchronously).
       
  1151 
       
  1152 @param aSelection The IDs of the source entries to copy. On return, contains the children that could not be fully copied. 
       
  1153 @param aTarget The ID of the destination parent entry
       
  1154 @param aOperationId Operation identifier
       
  1155 @param aRequestStatus Asynchronous request status
       
  1156 
       
  1157 @capability None A client with no capabilities can copy an entry only if both source and target entries
       
  1158 are under a local service, are owned by the client, and are in an unprotected folder.
       
  1159 
       
  1160 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1161 
       
  1162 @capability WriteUserData Required in some circumstances: see the note below.
       
  1163 
       
  1164 @capability Note The function tests that the caller has capabilities to create under the 
       
  1165 target entry (see RMsvServerSession::CreateEntryL).
       
  1166 */
       
  1167 EXPORT_C void RMsvServerSession::CopyEntriesL(const CMsvEntrySelection& aSelection, TMsvId aTarget, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
  1168 	{
       
  1169 	TestSlotAvailableL();
       
  1170 	// send the data to the server
       
  1171 	SendOperationDataL(aOperationId, aSelection, aTarget);
       
  1172 	// start the operation
       
  1173 	aRequestStatus=KRequestPending;
       
  1174 	SendReceive(EMsvCopyEntries, TIpcArgs(aOperationId), aRequestStatus);
       
  1175 	}
       
  1176 
       
  1177 
       
  1178 /**
       
  1179 Passes an MTM-specific operation to the associated server-side MTM by means of the Message Server (asynchronously). 
       
  1180 
       
  1181 @param aSelection A selection of entries that may be relevant to the operation 
       
  1182 @param aCommandId The command ID. The interpretation of the command is MTM-specific. 
       
  1183 @param aParameter A descriptor containing operation-specific parameters 
       
  1184 @param aOperationId Operation identifier
       
  1185 @param aRequestStatus Asynchronous request status
       
  1186 
       
  1187 @capability ReadUserData    
       
  1188 @capability WriteUserData
       
  1189 @capability Note A client application needs to have any additional capabilities that are specified by 
       
  1190 the MTM for the message type, as well as ReadUserData and WriteUserData. 
       
  1191 
       
  1192 @see RMsvServerSession::GetMTMRequiredCapabilitiesL
       
  1193 */
       
  1194 EXPORT_C void RMsvServerSession::TransferCommandL(const CMsvEntrySelection& aSelection, TInt aCommandId, const TDesC8& aParameter, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
  1195 	{
       
  1196 	TestSlotAvailableL();
       
  1197 	// send the operation data to the server
       
  1198 	SendCommandDataL(aOperationId, aSelection, aCommandId, aParameter);
       
  1199 	// start the operation
       
  1200 	aRequestStatus=KRequestPending;
       
  1201 	SendReceive(EMsvMtmCommand, TIpcArgs(aOperationId), aRequestStatus);
       
  1202 	}
       
  1203 
       
  1204 /**
       
  1205 Passes an MTM-specific operation to the associated server-side MTM by means of the Message Server (synchronously). 
       
  1206 
       
  1207 @param aSelection A selection of entries that may be relevant to the operation 
       
  1208 @param aCommandId The command ID. The interpretation of the command is MTM-specific. 
       
  1209 @param aParameter A descriptor containing operation-specific parameters 
       
  1210 @param aOperationId Operation identifier
       
  1211 
       
  1212 @capability ReadUserData    
       
  1213 @capability WriteUserData
       
  1214 @capability Note A client application needs to have any additional capabilities that are specified by 
       
  1215 the MTM for the message type, as well as ReadUserData and WriteUserData. 
       
  1216 
       
  1217 @see RMsvServerSession::GetMTMRequiredCapabilitiesL
       
  1218 */
       
  1219 EXPORT_C TInt RMsvServerSession::TransferCommandL(const CMsvEntrySelection& aSelection, TInt aCommandId, const TDesC8& aParameter, TMsvOp aOperationId)
       
  1220 	{
       
  1221 	TestSlotAvailableL();
       
  1222 	// send the operation data to the server
       
  1223 	SendCommandDataL(aOperationId, aSelection, aCommandId, aParameter);
       
  1224 	// start the operation
       
  1225 	return SendReceive(EMsvMtmCommand, TIpcArgs(aOperationId));
       
  1226 	}
       
  1227 
       
  1228 
       
  1229 /**
       
  1230 Gets the MTM that would perform an operation using two specified entries.
       
  1231 
       
  1232 @param aId1 ID of first entry
       
  1233 @param aId2 ID of second entry
       
  1234 @param aMtm On return, the UID of the MTM that would be used 
       
  1235 @param aService On return, the ID of the service that would be used 
       
  1236 @return System wide error code
       
  1237 
       
  1238 @capability None
       
  1239 */
       
  1240 EXPORT_C TInt RMsvServerSession::OperationMtmL(TMsvId aId1, TMsvId aId2, TUid& aMtm, TMsvId& aService)
       
  1241 	{
       
  1242 	TPckg<TUid> uid(aMtm);
       
  1243 	TPckg<TMsvId> service(aService);
       
  1244 	return SendReceive(EMsvOperationMtm, TIpcArgs(aId1,aId2,&uid,&service));
       
  1245 	}
       
  1246 
       
  1247 
       
  1248 /**
       
  1249 Stops any operations that a Server-side MTM for the specified service is running, 
       
  1250 and then unloads the Server-side MTM.
       
  1251 
       
  1252 The current operation and any queued operations are cancelled.
       
  1253  
       
  1254 @param aServiceId ID of the service
       
  1255 @return System wide error code
       
  1256 
       
  1257 @capability Note A client application needs to have any capabilities that are specified by 
       
  1258 the MTM.
       
  1259 
       
  1260 @see RMsvServerSession::GetMTMRequiredCapabilitiesL
       
  1261 */
       
  1262 EXPORT_C TInt RMsvServerSession::StopService(TMsvId aServiceId)
       
  1263 	{
       
  1264 	return SendReceive(EMsvStopService, TIpcArgs(aServiceId));
       
  1265 	}
       
  1266 
       
  1267 
       
  1268 /**
       
  1269 Tests if a Server-side MTM for a particular service is loaded by the Message 
       
  1270 Server.
       
  1271 
       
  1272 The Server-side MTM does not have to be executing a command: it may be 
       
  1273 waiting for another command.
       
  1274 
       
  1275 @param aServiceId The ID of the relevant service 
       
  1276 @return ETrue if the Server-side MTM for the service is loaded, otherwise EFalse 
       
  1277 
       
  1278 @capability None
       
  1279 */
       
  1280 EXPORT_C TBool RMsvServerSession::ServiceActive(TMsvId aServiceId)
       
  1281 	{
       
  1282 	return SendReceive(EMsvServiceActive, TIpcArgs(aServiceId)); 
       
  1283 	}
       
  1284 
       
  1285 /** 
       
  1286 Gets the current progress information from the Server-side MTM for the specified 
       
  1287 service.
       
  1288 
       
  1289 It is typically used by User Interface MTMs. The format of the progress information 
       
  1290 returned in the aProgress buffer is MTM-specific.
       
  1291 
       
  1292 Calling this function results in the Message Server calling CBaseServerMtm::Progress() 
       
  1293 on the relevant Server-side MTM. 
       
  1294 
       
  1295 Note that the progress information is independent of which message client 
       
  1296 application started the current operation. 
       
  1297 
       
  1298 @param aServiceId The ID of the service from which to get the progress information 
       
  1299 @param aProgress On return, a descriptor holding progress information. It is 
       
  1300 the caller's responsibility to ensure the descriptor is large enough for this information. 
       
  1301 @return KErrNone: success; KErrNotFound: The service is not active (the relevant Server-side MTM is not loaded 
       
  1302 by the Message Server); KErrOverflow: The descriptor was too small for the progress information
       
  1303 
       
  1304 @capability None
       
  1305 */
       
  1306 EXPORT_C TInt RMsvServerSession::ServiceProgress(TMsvId aServiceId, TDes8& aProgress)
       
  1307 	{
       
  1308 	TInt ret = SendReceive(EMsvServiceProgress, TIpcArgs(aServiceId,&aProgress));
       
  1309 	if (ret>0)
       
  1310 		{
       
  1311 		aProgress.SetLength(ret);
       
  1312 		ret=KErrNone;
       
  1313 		}
       
  1314 	else
       
  1315 		aProgress.SetLength(0);
       
  1316 	return ret;
       
  1317 	}
       
  1318 
       
  1319 /** 
       
  1320 Deletes the specified entry from the Message Server. 
       
  1321 
       
  1322 The call is guaranteed not to fail. If the entry cannot be deleted immediately, 
       
  1323 it will be deleted later.
       
  1324 
       
  1325 @param aId The ID of the entry to remove 
       
  1326 
       
  1327 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1328 under a local service, is owned by the client, is in an unprotected folder,  
       
  1329 and is not a service entry. 
       
  1330 
       
  1331 @capability WriteDeviceData Required if the entry is a service. 
       
  1332 
       
  1333 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1334 
       
  1335 @capability WriteUserData Required in some circumstances: see the note below.
       
  1336 
       
  1337 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1338 following conditions:  
       
  1339 
       
  1340 - Entry is under the local service:
       
  1341 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1342 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1343 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1344 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1345 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1346 
       
  1347 - Entry is under a remote service:
       
  1348 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1349 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1350 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1351 	MTM-specified capabilities (of the MTM for the remote service)
       
  1352 */
       
  1353 EXPORT_C void RMsvServerSession::RemoveEntry(TMsvId aId)
       
  1354 	{
       
  1355 	SendReceive(EMsvRemoveEntry, TIpcArgs(aId));
       
  1356 	}
       
  1357 
       
  1358 /**
       
  1359 Gets the path of the folder in which the Message Server data is stored.
       
  1360 
       
  1361 @param aDirectory Descriptor to hold returned path 
       
  1362 @return System wide error code
       
  1363 */
       
  1364 EXPORT_C TInt RMsvServerSession::GetMessageDirectory(TDes& aDirectory)
       
  1365 	{
       
  1366 	return SendReceive(EMsvGetMessageDirectory, TIpcArgs(&aDirectory));
       
  1367 	}
       
  1368 
       
  1369 /**
       
  1370 Gets the drive on which the Message Server data is stored.
       
  1371 
       
  1372 @return Drive, as a TDriveNumber value
       
  1373 
       
  1374 @capability None
       
  1375 */
       
  1376 TInt RMsvServerSession::GetMessageDrive()
       
  1377 	{
       
  1378 	return SendReceive(EMsvGetMessageDrive);
       
  1379 	}
       
  1380 
       
  1381 
       
  1382 void RMsvServerSession::TestSlotAvailableL()
       
  1383 //
       
  1384 //
       
  1385 //
       
  1386 	{
       
  1387 	User::LeaveIfError(SendReceive(EMsvSlotAvailable));
       
  1388 	}
       
  1389 
       
  1390 
       
  1391 /**
       
  1392 Set failure condition to simulate (for test purposes).
       
  1393 @param aType 
       
  1394 @param aArg1 
       
  1395 @param aArg2 
       
  1396 @param aArg3 
       
  1397 
       
  1398 @capability Note When the __REMOVE_MESSAGING_API_V1__ macro is defined, the
       
  1399 function is policed against the capabilities of the message server (Read/Write Device Data, 
       
  1400 Protected Server, Network Control, Network Services, Local Services and Read 
       
  1401 User Data). When the macro is not defined, the function is not policed. 
       
  1402 */
       
  1403 EXPORT_C void RMsvServerSession::SetFailure(TInt aType, TInt aArg1, TInt aArg2, TInt aArg3)
       
  1404 	{
       
  1405 	SendReceive(EMsvSetFailure,TIpcArgs(aType,aArg1,aArg2,aArg3));
       
  1406 	}
       
  1407 
       
  1408 /** Sets or clears multiple fields in a selection of entries.
       
  1409 
       
  1410 Fields to change are specified using a bitmask of TMsvAttribute values. 
       
  1411 @param aSelection The entries to change
       
  1412 @param aSetAttributes A bitmask of the fields to set
       
  1413 @param aClearAttributes A bitmask of the fields to clear
       
  1414 @see TMsvAttribute 
       
  1415 
       
  1416 @capability WriteUserData 
       
  1417 
       
  1418 @capability Note Clients with no capabilities that own entries in an unprotected folder cannot use this IPC call. 
       
  1419 Instead, they must change attributes by using ChangeEntryL on each entry.
       
  1420 */
       
  1421 EXPORT_C void RMsvServerSession::ChangeAttributesL(const CMsvEntrySelection& aSelection, TUint aSetAttributes, TUint aClearAttributes)
       
  1422 	{
       
  1423 	PackOperationDataL(aSelection, aSetAttributes, aClearAttributes);
       
  1424 	User::LeaveIfError(SendReceive(EMsvChangeAttributes,TIpcArgs(iBuffer)));
       
  1425 	}
       
  1426 
       
  1427 /**
       
  1428 Gets a filtered list of children of a specified message entry.
       
  1429 @param aId Message entry of which to get children
       
  1430 @param aFilter Filter by which various message entries can be excluded
       
  1431 @param aSelection On return, a list of message entry IDs
       
  1432 
       
  1433 @capability None Only children that the client owns are returned. 
       
  1434 
       
  1435 @capability ReadUserData All children of the entry are returned
       
  1436 */
       
  1437 EXPORT_C void RMsvServerSession::GetChildIdsL(TMsvId aId, const CMsvEntryFilter& aFilter, CMsvEntrySelection& aSelection)
       
  1438 	{
       
  1439 	TMsvPackedEntryFilter package(iBuffer);
       
  1440 	User::LeaveIfError(package.PackFilter(aFilter));
       
  1441 
       
  1442 	TPtr8 ptr=iBuffer->Des();
       
  1443 
       
  1444 	TInt error = SendReceive(EMsvGetChildIds,TIpcArgs(&ptr,aId));
       
  1445 
       
  1446 	while(error == KErrOverflow)
       
  1447 		{
       
  1448 		// increase the size of the buffer and try again
       
  1449 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  1450 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  1451 		TMsvPackedEntryFilter package1(iBuffer);
       
  1452 		User::LeaveIfError(package1.PackFilter(aFilter));
       
  1453 		TPtr8 ptr2=iBuffer->Des();
       
  1454 		error = SendReceive(EMsvGetChildIds,TIpcArgs(&ptr2,aId));
       
  1455 		}	
       
  1456 	User::LeaveIfError(error);
       
  1457 	TInt temp1(0); 
       
  1458 	TInt temp2(0);
       
  1459 	TMsvPackedOperation op(iBuffer);
       
  1460 	op.UnpackL(aSelection, temp1, temp2);
       
  1461 	}
       
  1462 
       
  1463 
       
  1464 
       
  1465 
       
  1466 /** 
       
  1467 Load the Message Server index from the specified drive.
       
  1468 
       
  1469 Progress information is provided by a TMsvIndexLoadProgress object.
       
  1470 
       
  1471 If an error occurs, the index is unchanged.
       
  1472 
       
  1473 @param aDrive The drive holding the Message Server index, specified 
       
  1474 by a TDriveNumber value
       
  1475 @param aOperationId Operation identifier
       
  1476 @param aRequestStatus Asynchronous completion status 
       
  1477 @leave KErrServerBusy Cannot change drive because there are outstanding Message 
       
  1478 Server operations.
       
  1479 
       
  1480 @capability WriteDeviceData
       
  1481 */
       
  1482 void RMsvServerSession::ChangeDriveL(TInt aDrive, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
  1483 	{
       
  1484 	__ASSERT_ALWAYS(RFs::IsValidDrive(aDrive), PanicServer(EMsvInvalidDrive));
       
  1485 	TestSlotAvailableL();
       
  1486 
       
  1487 	// start the operation
       
  1488 	aRequestStatus = KRequestPending;
       
  1489 	SendReceive(EMsvChangeDrive, TIpcArgs(aOperationId,TInt(aDrive)), aRequestStatus);
       
  1490 	}
       
  1491 	
       
  1492 	
       
  1493 /** 
       
  1494 Copy the Message Store to the specified drive.
       
  1495 
       
  1496 Progress information is provided by a TMsvCopyProgress object.
       
  1497 
       
  1498 If an error occurs, copying is stopped.
       
  1499 
       
  1500 @param aDrive The drive holding the Message Server index, specified 
       
  1501 by a TDriveUnit value
       
  1502 @param aOperationId Operation identifier
       
  1503 @param aStatus Asynchronous completion status 
       
  1504 @leave KErrServerBusy Cannot copy store because there are outstanding Message 
       
  1505 Server operations.
       
  1506 
       
  1507 @capability WriteDeviceData*/
       
  1508 
       
  1509 void RMsvServerSession::CopyStoreL(const TDriveUnit& aDrive, TMsvOp aOperationId, TRequestStatus& aStatus)                     
       
  1510 	{
       
  1511 	__ASSERT_ALWAYS(RFs::IsValidDrive(aDrive), PanicServer(EMsvInvalidDrive));
       
  1512 	TestSlotAvailableL();
       
  1513 
       
  1514 	// start the operation
       
  1515 	SendReceive(EMsvCopyStore, TIpcArgs(aOperationId,TInt(aDrive)), aStatus);
       
  1516 	}
       
  1517 
       
  1518 	
       
  1519 /** 
       
  1520 Delete the Message Store to the specified drive.
       
  1521 
       
  1522 Progress information is provided by a TMsvDeleteProgress object.
       
  1523 
       
  1524 If an error occurs, deleting is stopped.
       
  1525 
       
  1526 @param aDrive The drive holding the Message Server index, specified 
       
  1527 by a TDriveUnit value
       
  1528 @param aOperationId Operation identifier
       
  1529 @param aStatus Asynchronous completion status 
       
  1530 @leave KErrServerBusy Cannot delete store because there are outstanding Message 
       
  1531 Server operations.
       
  1532 
       
  1533 @capability WriteDeviceData
       
  1534 */
       
  1535 void RMsvServerSession::DeleteStoreL(const TDriveUnit& aDrive, TMsvOp aOperationId, TRequestStatus& aStatus)                     
       
  1536 	{
       
  1537 	__ASSERT_ALWAYS(RFs::IsValidDrive(aDrive), PanicServer(EMsvInvalidDrive));
       
  1538 	TestSlotAvailableL();
       
  1539 
       
  1540 	// start the operation
       
  1541 	SendReceive(EMsvDeleteStore, TIpcArgs(aOperationId,TInt(aDrive)), aStatus);
       
  1542 	}
       
  1543 	
       
  1544 	
       
  1545 
       
  1546 /**
       
  1547 Gets the number of outstanding operations.
       
  1548 
       
  1549 @return The number of outstanding operations 
       
  1550 
       
  1551 @capability None
       
  1552 */
       
  1553 TInt RMsvServerSession::OutstandingOperationsL()
       
  1554 	{
       
  1555 	TInt count;
       
  1556 	TPckg<TBool> package(count);
       
  1557 
       
  1558 	User::LeaveIfError(SendReceive(EMsvOutstandingOperations, TIpcArgs(&package)));
       
  1559 	return count;
       
  1560 	}
       
  1561 
       
  1562 /**
       
  1563 Get the notification sequence number.
       
  1564 
       
  1565 @return Notification sequence number
       
  1566 
       
  1567 @capability None
       
  1568 */
       
  1569 TUint32 RMsvServerSession::NotifySequenceL()
       
  1570 	{
       
  1571 	TUint32 sequence;
       
  1572 	TPckg<TUint32> package(sequence);
       
  1573 
       
  1574 	User::LeaveIfError(SendReceive(EMsvGetNotifySequence, TIpcArgs(&package)));
       
  1575 	return sequence;
       
  1576 	}
       
  1577 
       
  1578 
       
  1579 /**
       
  1580 Sets whether the session's observer should be notified of events related to 
       
  1581 changes in message server entries.
       
  1582 
       
  1583 If the flag is set to true, the session observer will be notified of all events types. 
       
  1584 If it is set to false, the observer will not be notified of events of types EMsvEntriesCreated, 
       
  1585 EMsvEntriesChanged, EMsvEntriesDeleted, or EMsvEntriesMoved. (Event types are enumerated in  
       
  1586 MMsvSessionObserver::TMsvSessionEvent.) 
       
  1587 
       
  1588 @param aReceive Event request flag
       
  1589 @return System wide error code
       
  1590 @see MMsvSessionObserver::TMsvSessionEvent
       
  1591 
       
  1592 @capability None
       
  1593 */
       
  1594 EXPORT_C TInt RMsvServerSession::SetReceiveEntryEvents(TBool aReceive)
       
  1595 	{
       
  1596 	// Send the uid type in message and Make request
       
  1597 	return SendReceive(EMsvSetReceiveEntyEvents, TIpcArgs(aReceive));
       
  1598 	}
       
  1599 
       
  1600 // from MMsvStoreManager
       
  1601 /** 
       
  1602 Creates a new attachment file in the message store for the message entry specified.
       
  1603 This function allows clients to create a new empty file and stream data to it. 
       
  1604 The empty attachment file is passed back to the client using an opened file handle 
       
  1605 to the file in the message store.
       
  1606 
       
  1607 @param aEntryId Entry to create the attachment for
       
  1608 @param aFileName The attachment filename
       
  1609 @param aFile On return, open file handle to the new attachment file . Ownership is transferred. The caller must close the file handle .
       
  1610 @return True if the file created was named as specified, otherwise false 
       
  1611 
       
  1612 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1613 under a local service, is owned by the client, is in an unprotected folder,  
       
  1614 and is not a service entry. 
       
  1615 
       
  1616 @capability WriteDeviceData Required if the entry is a service. 
       
  1617 
       
  1618 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1619 
       
  1620 @capability WriteUserData Required in some circumstances: see the note below.
       
  1621 
       
  1622 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1623 following conditions:  
       
  1624 
       
  1625 - Entry is under the local service:
       
  1626 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1627 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1628 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1629 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1630 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1631 
       
  1632 - Entry is under a remote service:
       
  1633 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1634 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1635 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1636 	MTM-specified capabilities (of the MTM for the remote service)
       
  1637 */
       
  1638 EXPORT_C TBool RMsvServerSession::CreateAttachmentForWriteL(TMsvId aEntryId, TDes& aFileName, RFile& aFile)
       
  1639 	{
       
  1640 	TPckg<TInt> pckgSubSessionHandle(0);  // intitialise
       
  1641 	TPckg<TBool> pckgFileNameChanged(EFalse);  // intitialise
       
  1642 	// session handle (RFs)received from TransferToClient() in server			
       
  1643 	TInt sessionHandle = User::LeaveIfError(SendReceive(EMsvCreateAttachmentForWrite,TIpcArgs(aEntryId,&aFileName,&pckgSubSessionHandle,&pckgFileNameChanged)));
       
  1644 	
       
  1645 	// Adopt the file handle from server
       
  1646 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  1647 
       
  1648 	return pckgFileNameChanged();
       
  1649 	}
       
  1650 
       
  1651 /** 
       
  1652 Allows clients to replace an existing attachment file and allows clients to stream data to it.
       
  1653 
       
  1654 Replaces an existing attachment file in the message store for the message entry specified by the aEntryId 
       
  1655 parameter. The attachment filename is set to the filename indicated by the aFilename parameter. 
       
  1656 If an attachment with the supplied name does not exist, a new file is created. The empty attachment
       
  1657 file is passed back to the client using an opened file handle to the file in the message store.
       
  1658 
       
  1659 @param aEntryId The entry for which an attachment needs to be created in the message store
       
  1660 @param aFilename The name of the attachment file to be created
       
  1661 @param aFile On return, The created file handle for the attachment file.Ownership is transferred . The caller must close the file handle .
       
  1662 
       
  1663 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1664 under a local service, is owned by the client, is in an unprotected folder,  
       
  1665 and is not a service entry. 
       
  1666 
       
  1667 @capability WriteDeviceData Required if the entry is a service. 
       
  1668 
       
  1669 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1670 
       
  1671 @capability WriteUserData Required in some circumstances: see the note below.
       
  1672 
       
  1673 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1674 following conditions:  
       
  1675 
       
  1676 - Entry is under the local service:
       
  1677 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1678 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1679 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1680 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1681 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1682 
       
  1683 - Entry is under a remote service:
       
  1684 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1685 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1686 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1687 	MTM-specified capabilities (of the MTM for the remote service)
       
  1688 */	
       
  1689 EXPORT_C void RMsvServerSession::ReplaceAttachmentForWriteL(TMsvId aEntryId, TDes& aFileName, RFile& aFile)
       
  1690 	{
       
  1691 	TPckg<TInt> pckgSubSessionHandle(0);  // intitialise
       
  1692 
       
  1693 	// session handle (RFs)received from TransferToClient() in server			
       
  1694 	TInt sessionHandle = User::LeaveIfError(SendReceive(EMsvReplaceAttachmentForWrite,TIpcArgs(aEntryId,&aFileName,&pckgSubSessionHandle)));
       
  1695 	
       
  1696 	// Adopt the file handle from server
       
  1697 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  1698 	}
       
  1699 
       
  1700 /** 
       
  1701 Opens an existing attachment file in the message store for the message entry specified.
       
  1702 This function allows clients to view attachment files.
       
  1703 
       
  1704 @param aEntryId Entry that has the attachment
       
  1705 @param aFilePath The attachment filename
       
  1706 @param aFile On return, open file handle to the attachment file. Ownership is transferred . The caller must close the file handle .
       
  1707 
       
  1708 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
  1709 
       
  1710 @capability ReadUserData This is required to access any entry where the condition 
       
  1711 described for no capabilities does not apply.
       
  1712 */
       
  1713 EXPORT_C void RMsvServerSession::OpenAttachmentL(TMsvId aEntryId, const TDesC& aFilePath, RFile& aFile)
       
  1714 	{
       
  1715 	TPckg<TInt> pckgSubSessionHandle(0);   // initialise
       
  1716 	// session handle (RFs)received from TransferToClient() in server			
       
  1717 	TInt sessionHandle = SendReceive(EMsvOpenAttachment,TIpcArgs(aEntryId,&aFilePath,&pckgSubSessionHandle));
       
  1718 	
       
  1719 	// Adopt the file handle from server
       
  1720 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  1721 	}
       
  1722 
       
  1723 	
       
  1724 /** 
       
  1725 Opens an existing attachment file in the message store for the message entry specified.
       
  1726 This function allows clients to edit attachment files.
       
  1727 
       
  1728 @param aEntryId Entry that has the attachment
       
  1729 @param aFilePath The attachment filename
       
  1730 @param aFile On return, open file handle to the attachment file .Ownership is transferred . The caller must close the file handle .
       
  1731 
       
  1732 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1733 under a local service, is owned by the client, is in an unprotected folder,  
       
  1734 and is not a service entry.
       
  1735 
       
  1736 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1737 
       
  1738 @capability WriteUserData Required in some circumstances: see the note below.
       
  1739 
       
  1740 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1741 following conditions:  
       
  1742 
       
  1743 - Entry is under the local service:
       
  1744 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1745 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1746 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1747 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1748 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1749 
       
  1750 - Entry is under a remote service:
       
  1751 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1752 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1753 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1754 	MTM-specified capabilities (of the MTM for the remote service)
       
  1755 */
       
  1756 EXPORT_C void RMsvServerSession::OpenAttachmentForWriteL(TMsvId aEntryId, const TDesC& aFilePath, RFile& aFile)
       
  1757 	{
       
  1758 	TPckg<TInt> pckgSubSessionHandle(0);   // initialise
       
  1759 	// session handle (RFs)received from TransferToClient() in server			
       
  1760 	TInt sessionHandle = SendReceive(EMsvOpenAttachmentForWrite,TIpcArgs(aEntryId,&aFilePath,&pckgSubSessionHandle));
       
  1761 	
       
  1762 	// Adopt the file handle from server
       
  1763 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  1764 	}
       
  1765 
       
  1766 /** 
       
  1767 Deletes an existing attachment file in the message store.
       
  1768 
       
  1769 @param aEntryId Entry that has the attachment
       
  1770 @param aFilePath The attachment filename
       
  1771 
       
  1772 @return System wide error code 
       
  1773 
       
  1774 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1775 under a local service, is owned by the client, is in an unprotected folder,  
       
  1776 and is not a service entry. 
       
  1777 
       
  1778 @capability WriteDeviceData Required if the entry is a service. 
       
  1779 
       
  1780 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1781 
       
  1782 @capability WriteUserData Required in some circumstances: see the note below.
       
  1783 
       
  1784 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1785 following conditions:  
       
  1786 
       
  1787 - Entry is under the local service:
       
  1788 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1789 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1790 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1791 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1792 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1793 
       
  1794 - Entry is under a remote service:
       
  1795 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1796 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1797 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1798 	MTM-specified capabilities (of the MTM for the remote service)
       
  1799 */
       
  1800 EXPORT_C TInt RMsvServerSession::DeleteAttachment(TMsvId aEntryId, const TDesC& aFilePath)
       
  1801 	{
       
  1802 	return SendReceive(EMsvDeleteAttachment,TIpcArgs(aEntryId,&aFilePath));
       
  1803 	}
       
  1804 
       
  1805 /** 
       
  1806 Renames an existing attachment file.
       
  1807 
       
  1808 Renames an existing attachment file in the message store associated with the
       
  1809 message entry specified by the aEntryId parameter. The attachment is 
       
  1810 identified by the file path specified by the aOldFilePath parameter and renamed to
       
  1811 the name supplied in the aNewName paramter.
       
  1812 
       
  1813 @param aEntryId The entry whose attachment needs to be renamed from the message store
       
  1814 @param aOldFilePath The name and path of the attachment file to be renamed.
       
  1815 @param aNewName The new name of the attachment file.
       
  1816 @return KErrNone if successful, otherwise any of the system wide error codes.
       
  1817 
       
  1818 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1819 under a local service, is owned by the client, is in an unprotected folder,  
       
  1820 and is not a service entry. 
       
  1821 
       
  1822 @capability WriteDeviceData Required if the entry is a service. 
       
  1823 
       
  1824 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1825 
       
  1826 @capability WriteUserData Required in some circumstances: see the note below.
       
  1827 
       
  1828 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1829 following conditions:  
       
  1830 
       
  1831 - Entry is under the local service:
       
  1832 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1833 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1834 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1835 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1836 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1837 
       
  1838 - Entry is under a remote service:
       
  1839 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1840 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1841 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1842 	MTM-specified capabilities (of the MTM for the remote service)
       
  1843 */	
       
  1844 EXPORT_C TInt RMsvServerSession::RenameAttachment(TMsvId aEntryId, const TDesC& aOldFilePath, const TDesC& aNewName)
       
  1845 	{
       
  1846 	return SendReceive(EMsvRenameAttachment,TIpcArgs(aEntryId, &aOldFilePath, &aNewName));
       
  1847 	}
       
  1848 
       
  1849 /** 
       
  1850 Checks if the attachment filename specified exists in the store.
       
  1851 
       
  1852 @param aFilePath The complete attachment file path specification
       
  1853 
       
  1854 @capability None
       
  1855 
       
  1856 @return ETrue if the attachment exists, otherwise EFalse
       
  1857 */
       
  1858 EXPORT_C TBool RMsvServerSession::FileExistsL(const TDesC& aFilePath)
       
  1859 	{
       
  1860 	TInt err = SendReceive(EMsvFileExists, TIpcArgs(&aFilePath));
       
  1861 	if( err == KErrNotFound )
       
  1862 		{
       
  1863 		return EFalse;
       
  1864 		}
       
  1865 		
       
  1866 	User::LeaveIfError(err);
       
  1867 	return ETrue;
       
  1868 	}
       
  1869 
       
  1870 /** 
       
  1871 Get the file path where the attachments for a particular entry are stored.
       
  1872 
       
  1873 @param aEntryId The message entry Id.
       
  1874 @param aFilePath On return this will contain the filepath for the attachments.
       
  1875 
       
  1876 @capability None
       
  1877 */
       
  1878 EXPORT_C void RMsvServerSession::AttachmentFilePathL(TMsvId aEntryId, TDes& aFilePath)
       
  1879 	{
       
  1880 	User::LeaveIfError(SendReceive(EMsvGetAttachmentFilePath, TIpcArgs(aEntryId, &aFilePath)));
       
  1881 	}
       
  1882 
       
  1883 /** 
       
  1884 Opens for reading a message store file for the message entry specified.
       
  1885 
       
  1886 @param aEntryId Entry that has the store
       
  1887 @param aFile On return, open file handle to the store.Ownership is transferred . The caller must close the file handle .
       
  1888 
       
  1889 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
  1890 
       
  1891 @capability ReadUserData This is required to access any entry where the condition 
       
  1892 described for no capabilities does not apply.
       
  1893 */
       
  1894 EXPORT_C TInt RMsvServerSession::OpenFileStoreForRead(TMsvId aEntryId, RFile& aFile)
       
  1895 	{
       
  1896 	TPckg<TInt> pckgSubSessionHandle(0);  // initialise
       
  1897 
       
  1898 	// session handle (RFs) received from TransferToClient() in server	
       
  1899 	TInt sessionHandle = SendReceive(EMsvOpenFileStoreForRead,TIpcArgs(aEntryId,&pckgSubSessionHandle));
       
  1900 	if( sessionHandle < KErrNone )
       
  1901 		return sessionHandle;
       
  1902 	
       
  1903 	// Adopt the file handle from server
       
  1904 	return aFile.AdoptFromServer(sessionHandle ,pckgSubSessionHandle());
       
  1905 	}
       
  1906 
       
  1907 /** 
       
  1908 Opens a temporary store file for the message entry specified.
       
  1909 
       
  1910 The function returns an open read-write file handle with an exclusive share to the temporary store file. 
       
  1911 This method, along with ReplaceFileStoreL, allows the message store classes to write data to the store 
       
  1912 file for a particular message entry.
       
  1913 
       
  1914 @param aEntryId Entry with which to associate the store
       
  1915 @param aFile On return, open file handle to the store. Ownership is transferred . The caller must close the file handle .
       
  1916 
       
  1917 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1918 under a local service, is owned by the client, is in an unprotected folder,  
       
  1919 and is not a service entry. 
       
  1920 
       
  1921 @capability WriteDeviceData Required if the entry is a service. 
       
  1922 
       
  1923 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1924 
       
  1925 @capability WriteUserData Required in some circumstances: see the note below.
       
  1926 
       
  1927 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1928 following conditions:  
       
  1929 
       
  1930 - Entry is under the local service:
       
  1931 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1932 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1933 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1934 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1935 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1936 
       
  1937 - Entry is under a remote service:
       
  1938 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1939 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1940 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1941 	MTM-specified capabilities (of the MTM for the remote service)
       
  1942 */
       
  1943 EXPORT_C void RMsvServerSession::OpenTempStoreFileL(TMsvId aEntryId, RFile& aFile)
       
  1944 	{
       
  1945 	TPckg<TInt> pckgSubSessionHandle(0);  // intitialise
       
  1946 	
       
  1947 	// session handle (RFs) received from TransferToClient() in server
       
  1948 	TInt sessionHandle = SendReceive(EMsvOpenTempStoreFile,TIpcArgs(aEntryId,&pckgSubSessionHandle));
       
  1949 	
       
  1950 	// Adopt the file handle from server
       
  1951 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle ,pckgSubSessionHandle()));
       
  1952 	}
       
  1953 	
       
  1954 /** 
       
  1955 Replaces the current store file with the temporary store file, created from OpenTempStoreFileL, for the specified message entry.
       
  1956 
       
  1957 @param aEntryId Entry associated with the store
       
  1958 
       
  1959 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1960 under a local service, is owned by the client, is in an unprotected folder,  
       
  1961 and is not a service entry. 
       
  1962 
       
  1963 @capability WriteDeviceData Required if the entry is a service. 
       
  1964 
       
  1965 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1966 
       
  1967 @capability WriteUserData Required in some circumstances: see the note below.
       
  1968 
       
  1969 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1970 following conditions:  
       
  1971 
       
  1972 - Entry is under the local service:
       
  1973 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1974 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1975 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1976 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1977 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1978 
       
  1979 - Entry is under a remote service:
       
  1980 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1981 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1982 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1983 	MTM-specified capabilities (of the MTM for the remote service)
       
  1984 */
       
  1985 EXPORT_C void RMsvServerSession::ReplaceFileStoreL(TMsvId aEntryId)
       
  1986 	{
       
  1987 	User::LeaveIfError(SendReceive(EMsvReplaceFileStore,TIpcArgs(aEntryId)));
       
  1988 	}
       
  1989 
       
  1990 /** 
       
  1991 Deletes the store file associated with the specified message entry.
       
  1992 
       
  1993 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1994 under a local service, is owned by the client, is in an unprotected folder,  
       
  1995 and is not a service entry. 
       
  1996 
       
  1997 @capability WriteDeviceData Required if the entry is a service. 
       
  1998 
       
  1999 @capability ReadUserData Required in some circumstances: see the note below.   
       
  2000 
       
  2001 @capability WriteUserData Required in some circumstances: see the note below.
       
  2002 
       
  2003 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  2004 following conditions:  
       
  2005 
       
  2006 - Entry is under the local service:
       
  2007 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  2008 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  2009 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  2010 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  2011 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  2012 
       
  2013 - Entry is under a remote service:
       
  2014 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  2015 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  2016 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  2017 	MTM-specified capabilities (of the MTM for the remote service)
       
  2018 */
       
  2019 EXPORT_C void RMsvServerSession::DeleteFileStoreL(TMsvId aEntryId)
       
  2020 	{
       
  2021 	User::LeaveIfError(SendReceive(EMsvDeleteFileStore,TIpcArgs(aEntryId)));
       
  2022 	}
       
  2023 
       
  2024 /** 
       
  2025 Tests if a store file exists for the specified message entry.
       
  2026 
       
  2027 @param aEntryId Entry associated with the store
       
  2028 
       
  2029 @return ETrue if the store file exists, otherwise EFalse.
       
  2030 
       
  2031 @capability None
       
  2032 */
       
  2033 EXPORT_C TBool RMsvServerSession::FileStoreExistsL(TMsvId aEntryId) const
       
  2034 	{
       
  2035 	return SendReceive(EMsvFileStoreExists,TIpcArgs(aEntryId));
       
  2036 	}
       
  2037 
       
  2038 /** 
       
  2039 Checks a flag in the message server that is set when the server
       
  2040 deletes a corrupt index file. Then clears the flag.
       
  2041 	
       
  2042 It is intended to allow the message centre UI to check whether
       
  2043 a corrupt index has been deleted on startup. If it has the UI
       
  2044 may inform the user about the loss of their messages.
       
  2045     
       
  2046 @return ETrue if a corrupt index flag was present indicating that
       
  2047 a corrupt index file has been deleted since the last time this
       
  2048 function was called.
       
  2049  
       
  2050 @capability None
       
  2051 */
       
  2052 TBool RMsvServerSession::GetAndClearIndexCorruptFlagL()
       
  2053 	{
       
  2054 	TInt result=User::LeaveIfError(SendReceive(EMsvGetAndClearIndexCorruptFlag));
       
  2055 	return result==0 ? EFalse : ETrue;
       
  2056 	}
       
  2057 	
       
  2058 /** Checks if the specified drive has a Message Server index on it.
       
  2059 
       
  2060 @param aDrive Drive to check
       
  2061 @return True if aDrive has a Message Server index, otherwise false
       
  2062 @capability None
       
  2063 */
       
  2064 TBool RMsvServerSession::DriveContainsStoreL(TDriveUnit aDrive)
       
  2065 	{
       
  2066 	TInt result=User::LeaveIfError(SendReceive(EMsvDriveContainsStore,TIpcArgs(aDrive)));
       
  2067 	return result==0 ? EFalse : ETrue;
       
  2068 	}
       
  2069 
       
  2070 /** Checks to see if the currently selected drive contains the correct mail store.
       
  2071 
       
  2072 If the message store is present on an external drive, we have to check if the same drive is 
       
  2073 mounted or not before storing the mail.
       
  2074 
       
  2075 @return ETrue if the same drive is mounted. otherwise returns EFalse
       
  2076 @capability None
       
  2077 */
       
  2078 EXPORT_C TBool RMsvServerSession::MessageStoreDrivePresentL()
       
  2079 	{
       
  2080 	TInt result = User::LeaveIfError(SendReceive(EMsvMessageStoreDrivePresent));	
       
  2081 	return result== 0 ? EFalse : ETrue;
       
  2082 	}
       
  2083 
       
  2084 EXPORT_C TBool RMsvServerSession::CreateShareProtectedAttachmentForWriteL(TMsvId /*aEntryId*/, TDes& /*aFilename*/, RFile& /*aFile*/)
       
  2085 	{
       
  2086 	User::Leave(KErrNotSupported);
       
  2087 	//Avoid complier errors and warnings...
       
  2088 	return EFalse;
       
  2089 	}
       
  2090 
       
  2091 /** 
       
  2092 Get the file path where the plain body text for a particular entry will be stored.
       
  2093 @param aBodyTextId 	The TMsvId of the body text entry.
       
  2094 @param aFilePath 	On return this will contain the filepath for the plainbody text.
       
  2095 @capability None
       
  2096 */
       
  2097 EXPORT_C void RMsvServerSession::BodyTextFilePathL(TMsvId aBodyTextId, TDes& aFilePath)
       
  2098  	{
       
  2099  	User::LeaveIfError(SendReceive(EMsvGetBodyTextFilePath, TIpcArgs(aBodyTextId, &aFilePath)));
       
  2100 	}
       
  2101 
       
  2102 /** 
       
  2103 Open the bodytext file whose path is given in aFileName.
       
  2104 @param aFile	 	 The RFile reference that is to be opened.
       
  2105 @param aBodyTextId	 The TMsvId of the body text entry.
       
  2106 @capability ReadUserData
       
  2107 */
       
  2108 EXPORT_C void RMsvServerSession::OpenBodyTextFileForReadL(RFile& aFile, TMsvId aBodyTextId, const TDesC& aFilePath)
       
  2109 	{
       
  2110 	TPckg<TInt> pckgSubSessionHandle(0);
       
  2111 	TInt sessionHandle = User::LeaveIfError(SendReceive(EMsvOpenTextFileForRead, TIpcArgs(aBodyTextId,  &aFilePath, &pckgSubSessionHandle)));
       
  2112 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  2113 	}
       
  2114 
       
  2115 /** 
       
  2116 Create a plainbody text file whose path is given in aFilePath.
       
  2117 @param aFile 	  	The RFile reference that is to be opened.
       
  2118 @param aBodyTextId  The TMsvId of the body text entry.
       
  2119 @capability WriteUserData
       
  2120 */
       
  2121 EXPORT_C void RMsvServerSession::CreatePlainTextFileL(RFile& aFile, TMsvId aBodyTextId)
       
  2122 	{
       
  2123 	TPckg<TInt> pckgSubSessionHandle(0);
       
  2124 	TInt sessionHandle = User::LeaveIfError(SendReceive(EMsvCreatePlainTextFile, TIpcArgs(aBodyTextId, &pckgSubSessionHandle)));
       
  2125 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  2126 	}
       
  2127 
       
  2128 /** 
       
  2129 Deletes  a plainbody text file whose path is given in aFilePath.
       
  2130 @param aBodyTextId	 The TMsvId of the body text entry.
       
  2131 @capability WriteUserData
       
  2132 */
       
  2133 EXPORT_C void RMsvServerSession::DeletePlainTextFileL(TMsvId aBodyTextId)
       
  2134 	{
       
  2135 	User::LeaveIfError(SendReceive(EMsvDeletePlainTextFile, TIpcArgs(aBodyTextId)));
       
  2136 	}
       
  2137 
       
  2138 /** 
       
  2139 Replaces  a plainbody text file whose Id is given in aBodyTextId.
       
  2140 @param aBodyTextId 	  The TMsvId of the body text entry.
       
  2141 @capability WriteUserData
       
  2142 */	
       
  2143 EXPORT_C void RMsvServerSession::ReplacePlainTextFileL(TMsvId aBodyTextId)
       
  2144 	{
       
  2145 	User::LeaveIfError(SendReceive(EMsvReplacePlainTextFile,TIpcArgs(aBodyTextId)));
       
  2146 	}
       
  2147 
       
  2148 
       
  2149 
       
  2150 #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT)
       
  2151 /**
       
  2152  * GetChildrenAll()
       
  2153  *
       
  2154  * @param TMsvId:                ID of the parent entry.
       
  2155  * @param TMsvSelectionOrdering: Sorting and grouping rules for the returned entries.
       
  2156  * @param CArrayPtrFlat<CMsvClientEntry>: On return, the entry's children. If an error is returned, aEntries is unchanged.
       
  2157  * @return TInt:                 System wide error code
       
  2158  *
       
  2159  * @capability None Only children that the client owns are returned. 
       
  2160  * @capability ReadUserData All children of the entry are returned
       
  2161  *
       
  2162  * Gets the children of a parent entry specified as first argument.
       
  2163  * If the passed parent is a standard folder the function will fetch 
       
  2164  * entries from all drives currently present in the preferred drive list.
       
  2165  */
       
  2166 EXPORT_C TInt RMsvServerSession::GetChildrenAll(TMsvId aId, CArrayPtrFlat<CMsvClientEntry>& aEntries, const TMsvSelectionOrdering& aOrdering)
       
  2167 	{
       
  2168 	TInt origCount = aEntries.Count();
       
  2169 	TInt leave = KErrNone;
       
  2170 	
       
  2171 	TRAP(leave, DoGetChildrenAllL(aId, aEntries, aOrdering));
       
  2172 	if(KErrNone != leave)
       
  2173 		{
       
  2174 		TInt count=aEntries.Count();
       
  2175 		while(count > origCount)
       
  2176 			{
       
  2177 			delete aEntries.At(--count);
       
  2178 			aEntries.Delete(count);
       
  2179 			}
       
  2180 		}
       
  2181 	return leave;
       
  2182 	}
       
  2183 
       
  2184 
       
  2185 void RMsvServerSession::DoGetChildrenAllL(TMsvId aId, CArrayPtrFlat<CMsvClientEntry>& aEntries, const TMsvSelectionOrdering& aOrdering)
       
  2186 //
       
  2187 // Gets the children of the index entry with the Unique id aId.
       
  2188 //
       
  2189 	{
       
  2190 	// package up the Id into a children details class
       
  2191 	TPckgBuf<TMsvChildrenDetails> details;
       
  2192 	details().iParentId = aId;
       
  2193 	// pass the sort order
       
  2194 	TPckgC<TMsvSelectionOrdering> package2(aOrdering);
       
  2195 	// pass the buffer to receive the data through
       
  2196 	TPtr8 ptr=iBuffer->Des();
       
  2197 	
       
  2198 	// signal the server
       
  2199 	TInt error = SendReceive(EMsvGetChildrenALL, TIpcArgs(&details,&package2,&ptr));
       
  2200 
       
  2201 	if (error!=KErrNone && error!=KErrOverflow)
       
  2202 		User::Leave(error);
       
  2203 
       
  2204 	// unpack the entries from the buffer
       
  2205 	TMsvPackedEntryArray packedEntryArray(iBuffer);
       
  2206 	for (TInt count=0; count<details().iNumberChildrenInArray; count++)
       
  2207 		{
       
  2208 		TMsvEntry entry;
       
  2209 		User::LeaveIfError(packedEntryArray.UnpackEntry(count, entry));
       
  2210 		CMsvClientEntry* cEntry = CMsvClientEntry::NewLC(entry, EMsvClientChild);
       
  2211 		aEntries.AppendL(cEntry);
       
  2212 		CleanupStack::Pop(); // cEntry
       
  2213 		}
       
  2214 	
       
  2215 	// if there are more entries - get them
       
  2216 	if (error==KErrOverflow)
       
  2217 		DoGetRemainingChildrenL(details, aEntries);
       
  2218 	}
       
  2219 	
       
  2220 	
       
  2221 	
       
  2222 
       
  2223 /** 
       
  2224  * GetChildIdsAllL()
       
  2225  *
       
  2226  * @param TMsvId:          ID of the parent entry.
       
  2227  * @param CMsvEntryFilter: Filter by which various message entries can be excluded.
       
  2228  * @return aSelection:     A list of message entry IDs
       
  2229  *
       
  2230  * @capability None Only children that the client owns are returned. 
       
  2231  * @capability ReadUserData All children of the entry are returned
       
  2232  *
       
  2233  * Gets the children of a parent entry specified as first argument.
       
  2234  * If the passed parent is a standard folder the function will fetch 
       
  2235  * entries from all drives currently present in the preferred drive list.
       
  2236  */
       
  2237 EXPORT_C void RMsvServerSession::GetChildIdsAllL(TMsvId aId, const CMsvEntryFilter& aFilter, CMsvEntrySelection& aSelection)
       
  2238 	{
       
  2239 	TMsvPackedEntryFilter package(iBuffer);
       
  2240 	User::LeaveIfError(package.PackFilter(aFilter));
       
  2241 
       
  2242 	TPtr8 ptr=iBuffer->Des();
       
  2243 
       
  2244 	TInt error = SendReceive(EMsvGetChildIdsALL, TIpcArgs(&ptr, aId));
       
  2245 	while(error == KErrOverflow)
       
  2246 		{
       
  2247 		// increase the size of the buffer and try again
       
  2248 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2249 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2250 		TMsvPackedEntryFilter package1(iBuffer);
       
  2251 		User::LeaveIfError(package1.PackFilter(aFilter));
       
  2252 		TPtr8 ptr2=iBuffer->Des();
       
  2253 		error = SendReceive(EMsvGetChildIdsALL,TIpcArgs(&ptr2,aId));
       
  2254 		}
       
  2255 		
       
  2256 	User::LeaveIfError(error);
       
  2257 	TInt temp1(0); 
       
  2258 	TInt temp2(0);
       
  2259 	TMsvPackedOperation op(iBuffer);
       
  2260 	op.UnpackL(aSelection, temp1, temp2);
       
  2261 	}
       
  2262 
       
  2263 
       
  2264 
       
  2265 
       
  2266 /**
       
  2267  * CurrentDriveInfo()
       
  2268  *
       
  2269  * @return TDriveNumber: Drive number of the current drive
       
  2270  *						 in the preferred drive list.
       
  2271  * @return TUint	   : Priority of the drive.
       
  2272  *
       
  2273  * Code changes for PREQ 557.
       
  2274  * The function returns the current drive of message server.
       
  2275  */ 
       
  2276 EXPORT_C void RMsvServerSession::CurrentDriveInfoL(TDriveNumber& aDriveNumber, TUint& aPriority)
       
  2277 	{
       
  2278 	TPckg<TDriveNumber> driveNum(aDriveNumber);
       
  2279 	TPckg<TUint> priority(aPriority);
       
  2280 		
       
  2281 	User::LeaveIfError(SendReceive(EMsvGetCurrentDriveInfo, TIpcArgs(&driveNum, &priority)));
       
  2282 	}
       
  2283 
       
  2284 
       
  2285 
       
  2286 /**
       
  2287  * DriveList()
       
  2288  *
       
  2289  * @return RArray<TDriveNumber>: List of drive number present in 
       
  2290  *         the preferred drive list arranged in decrementing order
       
  2291  *         of their priority.
       
  2292  *
       
  2293  * Code changes for PREQ 557.
       
  2294  */
       
  2295 EXPORT_C void RMsvServerSession::DriveListL(RArray<TDriveNumber>& aDriveList)
       
  2296 	{
       
  2297 	TPtr8 ptr = iBuffer->Des();	
       
  2298 	User::LeaveIfError(SendReceive(EMsvGetDriveList, TIpcArgs(&ptr)));
       
  2299 
       
  2300 	// Unpack the entries from the buffer.
       
  2301 	TMsvPackedDriveIdOperation packedDriveIdOperation(iBuffer);
       
  2302 	packedDriveIdOperation.UnpackL(aDriveList);	
       
  2303 	}
       
  2304 
       
  2305 
       
  2306 
       
  2307 
       
  2308 /**
       
  2309  * AvailableDriveListL()
       
  2310  *
       
  2311  * @return RArray<TDriveNumber>: List of drive number of available
       
  2312  *         drives present in the preferred drive list arranged in 
       
  2313  *         decrementing order of their priority.
       
  2314  *
       
  2315  * Code changes for PREQ 557.
       
  2316  * NOTE: A drive number is available only if it has a valid 
       
  2317  * (readable and of correct version) message store in it.
       
  2318  */
       
  2319 EXPORT_C void RMsvServerSession::AvailableDriveListL(RArray<TDriveNumber>& aDriveList)
       
  2320 	{
       
  2321 	TPtr8 ptr = iBuffer->Des();	
       
  2322 	User::LeaveIfError(SendReceive(EMsvGetAvailableDriveList, TIpcArgs(&ptr)));
       
  2323 	
       
  2324 	// Unpack the entries from the buffer.
       
  2325 	TMsvPackedDriveIdOperation packedDriveIdOperation(iBuffer);
       
  2326 	packedDriveIdOperation.UnpackL(aDriveList);	
       
  2327 	}
       
  2328 
       
  2329 
       
  2330 
       
  2331 
       
  2332 /**
       
  2333  * AddDriveL()
       
  2334  *
       
  2335  * @param  TDriveNumber: Drive number of the drive
       
  2336  *						 to be added.
       
  2337  * @param TUint        : Priority of the drive.
       
  2338  * @return TUint       : New priority of the added drive.
       
  2339  *
       
  2340  * Code changes for PREQ 557.
       
  2341  * The function adds the passed drive in the preferred drive list.
       
  2342  * The location of the drive in the list is specified by the priority 
       
  2343  * of the drive as specified in the second argument. 
       
  2344  *
       
  2345  * - If the priority value of the drive is more than the number of 
       
  2346  * elements in the preferred drive list, the function appends the drive 
       
  2347  * at the end of the list. The new priority of the drive is returned as 
       
  2348  * the second argument.
       
  2349  * - If the priority of the new drive is higher than the current drive 
       
  2350  * of message server, and if the new drive has a media in it, the message 
       
  2351  * server will perform implicit changeDrive and sends a notification to 
       
  2352  * all registered client processes about the change.
       
  2353  * - If the drive does not contain a valid version of message store the 
       
  2354  * function updates the drive status to EMsvMessageStoreNotSupported and 
       
  2355  * sends appropriate notification to the client process. The drive's content 
       
  2356  * will not be visible to any of the client processes.
       
  2357  * - If the message store/message index database in the media is corrupt, 
       
  2358  * the server will delete the message store and create a fresh message store
       
  2359  * and related files in the media.
       
  2360  * - If the number of drive already present in the preferred list is eight,
       
  2361  * the function will return appropriate error message. 
       
  2362  * - In all cases mentioned above, if the drive is successfully added to the 
       
  2363  * preferred drive list the function will also update the central repository 
       
  2364  * with the new preferred drive list.
       
  2365  */ 
       
  2366 EXPORT_C void RMsvServerSession::AddDriveL(TDriveNumber aDriveNumber, TUint& aPriority)
       
  2367 	{
       
  2368 	TUint newPriority = aPriority;
       
  2369 	TPckg<TUint> priorityPkg(newPriority);
       
  2370 	if(!RFs::IsValidDrive(aDriveNumber))
       
  2371 		{
       
  2372 		User::Leave(KErrArgument);
       
  2373 		}
       
  2374 	User::LeaveIfError(SendReceive(EMsvAddDriveToDriveList, TIpcArgs(aDriveNumber, aPriority, &priorityPkg)));
       
  2375 	aPriority = newPriority;
       
  2376 	}
       
  2377 
       
  2378 
       
  2379 
       
  2380 /**
       
  2381  * RemoveDriveL()
       
  2382  *
       
  2383  * @param  TDriveNumber: Drive number of the drive
       
  2384  *						 to be removed.
       
  2385  *
       
  2386  * Code changes for PREQ 557.
       
  2387  * The function removes the drive from the preferred
       
  2388  * drive list. If the current drive is being removed, 
       
  2389  * the next available drive in the preferred drive list 
       
  2390  * becomes the current drive. The device internal drive 
       
  2391  * cannot be removed from the preferred drive list. 
       
  2392  * Appropriate notification will be sent to the client 
       
  2393  * process if there is a change in the current drive. 
       
  2394  * The function will also update the central repository 
       
  2395  * accordingly.
       
  2396  */ 
       
  2397  EXPORT_C void RMsvServerSession::RemoveDriveL(TDriveNumber aDriveNumber)
       
  2398  	{
       
  2399 	if(!RFs::IsValidDrive(aDriveNumber))
       
  2400 		{
       
  2401 		User::Leave(KErrArgument);
       
  2402 		}
       
  2403 	User::LeaveIfError(SendReceive(EMsvRemoveDriveFromDriveList, TIpcArgs(aDriveNumber)));
       
  2404  	}
       
  2405  	
       
  2406  	
       
  2407  	
       
  2408  /**
       
  2409  * UpdateDrivePriorityL()
       
  2410  *
       
  2411  * @param  TDriveNumber: Drive number of the drive
       
  2412  *						 to be updated.
       
  2413  * @param  TUint       : Priority of the drive.
       
  2414  * @return TUint       : New priority of the drive.
       
  2415  *
       
  2416  * Code changes for PREQ 557.
       
  2417  * The function updates the priority of the drive 
       
  2418  * already present in the preferred drive list. If 
       
  2419  * the priority being mentioned is greater than the 
       
  2420  * number of drive present in the list, the drive 
       
  2421  * will be added at the end of the preferred drive list. 
       
  2422  * The function will then return the new priority of 
       
  2423  * the drive. If updating a priority makes a non-current 
       
  2424  * drive the current drive or vice-versa, the function 
       
  2425  * will implicitly perform changeDrive() and send the 
       
  2426  * notification to all registered client. It will return
       
  2427  * error if the said drive is not already present in the 
       
  2428  * preferred drive list.
       
  2429  */ 
       
  2430 EXPORT_C void RMsvServerSession::UpdateDrivePriorityL(TDriveNumber aDriveNumber, TUint& aPriority)
       
  2431 	{
       
  2432 	TUint newPriority = aPriority;
       
  2433 	TPckg<TUint> priorityPkg(newPriority);
       
  2434 	if(!RFs::IsValidDrive(aDriveNumber))
       
  2435 		{
       
  2436 		User::Leave(KErrArgument);
       
  2437 		}
       
  2438 	User::LeaveIfError(SendReceive(EMsvUpdateDrivePriority, TIpcArgs(aDriveNumber, aPriority, &priorityPkg)));
       
  2439 	aPriority = newPriority;
       
  2440 	}
       
  2441 	
       
  2442 
       
  2443 #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE)
       
  2444 void RMsvServerSession::ResetRepositoryL()
       
  2445 	{
       
  2446 	User::LeaveIfError(SendReceive(EMsvResetRepository));
       
  2447 	}
       
  2448 #endif 	// #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE)
       
  2449 #endif  // #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT)	
       
  2450 
       
  2451 
       
  2452 
       
  2453 /**
       
  2454 Gets data from a server MTM that is not related to any operation being performed on
       
  2455 that MTM.
       
  2456 
       
  2457 @param aServiceId The ID of the service from which to get the data
       
  2458 @param aType The type of MTM data to get.
       
  2459 @param aMtmData A packaged buffer to store the data
       
  2460 
       
  2461 @return KErrNone if successful or one of the system wide error codes
       
  2462 */
       
  2463 TInt RMsvServerSession::GetNonOperationMtmData(TMsvId aServiceId, const TNonOperationMtmDataType& aMtmDataType, TDes8& aMtmData)
       
  2464 	{
       
  2465 	return SendReceive(EMsvGetNonOperationMtmData, TIpcArgs(aServiceId, aMtmDataType, &aMtmData));
       
  2466 	}
       
  2467 
       
  2468 
       
  2469 /** 
       
  2470 SearchSort Request on Header and/or Body part
       
  2471 @param aQuery SearchSortQuery object
       
  2472 @param aOperationId Opertion Id
       
  2473 @param aMarkQuery TBool for QueryId, whether needs to mark at server side or not
       
  2474 @param aRequestStatus TRequestStatus status
       
  2475 @capability WriteUserData
       
  2476 */	
       
  2477 void RMsvServerSession::SearchSortRequestOnHeaderBodyL(const CMsvSearchSortQuery* aQuery, TMsvOp aOperationId, TBool aMarkQuery, TRequestStatus& aRequestStatus)
       
  2478 	{
       
  2479 	TestSlotAvailableL();
       
  2480 	TMsvPackQuery packedQuery(iBuffer);
       
  2481 	TInt error = packedQuery.PackQuery(aQuery);
       
  2482 	while(error!=KErrNone)
       
  2483 		{
       
  2484 		// increase the size of the buffer and try again
       
  2485 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2486 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2487 		error = packedQuery.PackQuery(aQuery);
       
  2488 		}
       
  2489 	// pass data to the server
       
  2490 	SendReceive(EMsvSearchSortOperation, TIpcArgs(aOperationId, iBuffer, aMarkQuery), aRequestStatus);
       
  2491 	}
       
  2492 
       
  2493 
       
  2494 /** 
       
  2495 Get results for given QueryId
       
  2496 @param aQueryId queryId from client
       
  2497 @param aOperationId Opertion Id
       
  2498 @param aIterator Whether results should be send in iterator
       
  2499 @param aRequestStatus TRequestStatus status
       
  2500 @capability ReadUserData
       
  2501 */
       
  2502 void RMsvServerSession::GetResultsForQueryId(TInt& aQueryId, TMsvOp aOperationId, TInt aIterator, TRequestStatus& aRequestStatus)
       
  2503 	{
       
  2504 	SendReceive(EMsvSearchSortQueryId, TIpcArgs(aOperationId, aQueryId, aIterator), aRequestStatus);
       
  2505 	}
       
  2506 
       
  2507 
       
  2508 /** 
       
  2509 Search Sort Request on TMsvEntry
       
  2510 @param aQuery SearchSortQuery object
       
  2511 @param aOperationId Opertion Id
       
  2512 @param aMarkQuery TBool for QueryId, whether needs to mark at server side or not
       
  2513 @param aIterator Whether results should be send in iterator
       
  2514 @param aRequestStatus TRequestStatus status
       
  2515 @capability ReadUserData
       
  2516 */	
       
  2517 void RMsvServerSession::SearchSortRequestOnEntryL(const CMsvSearchSortQuery* aQuery, TMsvOp aOperationId, TBool aMarkQuery, TInt aIterator, TRequestStatus& aRequestStatus)
       
  2518 	{
       
  2519 	TestSlotAvailableL();
       
  2520 	// package up the query into a query entry
       
  2521 	TMsvPackQuery packedQuery(iBuffer);
       
  2522 	TInt error = packedQuery.PackQuery(aQuery);
       
  2523 	while(error!=KErrNone)
       
  2524 		{
       
  2525 		// increase the size of the buffer and try again
       
  2526 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2527 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2528 		error = packedQuery.PackQuery(aQuery);
       
  2529 		}
       
  2530 	SendReceive(EMsvSearchSortOnIndexEntry, TIpcArgs(aOperationId, iBuffer, aMarkQuery, aIterator), aRequestStatus);
       
  2531 	}
       
  2532 	
       
  2533 /** 
       
  2534 Get search sort results as TMsvId
       
  2535 @param aId RArray of TMsvId's sent by server
       
  2536 @capability ReadUserData
       
  2537 */
       
  2538 void RMsvServerSession::GetResultAsIdL(RArray<TMsvId>& aId)
       
  2539 	{
       
  2540 	TBool resultType=ETrue; // result as TMsvId
       
  2541 	
       
  2542 	// pass the buffer to receive the data through
       
  2543 	TPtr8 ptr=iBuffer->Des();
       
  2544 	// signal the server
       
  2545 	TInt error = SendReceive(EMsvGetResult,TIpcArgs(&resultType, &ptr));
       
  2546 	while(error == KErrOverflow)
       
  2547 		{
       
  2548 		// increase the size of the buffer and try again
       
  2549 		iBuffer->Des().SetLength(0);
       
  2550 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2551 		// pass the buffer to receive the data through
       
  2552 		TPtr8 ptr=iBuffer->Des();
       
  2553 		error = SendReceive(EMsvGetResult,TIpcArgs(&resultType, &ptr));
       
  2554 		}
       
  2555 	User::LeaveIfError(error);
       
  2556 	
       
  2557 	// unpack the entries from the buffer
       
  2558 	TMsvPackedIdOperation packedIdOperation(iBuffer);
       
  2559 	packedIdOperation.UnpackL(aId);
       
  2560 	}
       
  2561 
       
  2562 
       
  2563 /** 
       
  2564 Get search sort Request QueryId
       
  2565 @param aQueryId get aQueryId from server
       
  2566 @capability ReadUserData
       
  2567 */
       
  2568 void RMsvServerSession::GetSearchSortRequestQueryIdL(TInt& aQueryId)
       
  2569 	{
       
  2570 	TPckg<TInt> queryId(aQueryId); 
       
  2571 	User::LeaveIfError(SendReceive(EMsvGetQueryId,TIpcArgs(&queryId)));
       
  2572 	}
       
  2573 
       
  2574 
       
  2575 /** 
       
  2576 Unmark the QueryId it was marked at server side
       
  2577 @param aQueryId Unmark the aQueryId at server
       
  2578 @capability WriteUserData
       
  2579 */
       
  2580 void RMsvServerSession::UnmarkSearchSortRequestQueryIdL(TInt aQueryId)
       
  2581 	{
       
  2582 	User::LeaveIfError(SendReceive(EMsvUnmarQueryId,TIpcArgs(&aQueryId)));
       
  2583 	}
       
  2584 
       
  2585 
       
  2586 /** 
       
  2587 Sending TMsvId along with Sort filed to server, so that it will update the data in search-sort cache. 
       
  2588 @param aOperationId Opertion Id
       
  2589 @param aTMsvIdWithSortField RArray of TMsvId along with Sort filed.
       
  2590 @param aRequestStatus TRequestStatus status
       
  2591 @capability WriteUserData
       
  2592 */
       
  2593 void RMsvServerSession::SendResultantListL(TMsvOp aOperationId, RArray<TMsvIdWithSortField> aTMsvIdWithSortField, TRequestStatus& aRequestStatus)	
       
  2594 	{
       
  2595 	TestSlotAvailableL();
       
  2596 	
       
  2597 	// need to pack TMsvId and TMessagePart (i.e TMsvId and Sort field)
       
  2598 	TMsvPackedIdAndMessagePart packIdAndMessagePart;
       
  2599 	
       
  2600 	// calculate size of the TTMsvIdWithMessagePart
       
  2601 	TInt bufferSize = packIdAndMessagePart.Size(aTMsvIdWithSortField);
       
  2602 	
       
  2603 	// if size lessthan KMsvSessionBufferLength, allocate KMsvSessionBufferLength to sync with iBuffer initial allocation.
       
  2604 	if(bufferSize < KMsvSessionBufferLength)
       
  2605 		{
       
  2606 		bufferSize = KMsvSessionBufferLength;
       
  2607 		}
       
  2608 		
       
  2609 	// allocate the buffer
       
  2610 	CBufFlat* flat = CBufFlat::NewL(bufferSize);
       
  2611 	CleanupStack::PushL(flat);
       
  2612 	flat->ExpandL(0, bufferSize);
       
  2613 	
       
  2614 	RBufWriteStream writeStream(*flat);
       
  2615 	CleanupClosePushL (writeStream);
       
  2616 	
       
  2617 	// Externalize the data availbe in TTMsvIdWithMessagePart
       
  2618 	packIdAndMessagePart.ExternalizeL(writeStream, aTMsvIdWithSortField);
       
  2619 	TPtr8 ptr8 = flat->Ptr(0);
       
  2620 	
       
  2621 	// delete memory allocated for iBuffer
       
  2622 	if(iBuffer != NULL)
       
  2623 		{
       
  2624 		delete iBuffer;
       
  2625 		iBuffer = NULL;
       
  2626 		}
       
  2627 
       
  2628 	//Convert CBufFlat into a HBufC8
       
  2629 	iBuffer = ptr8.AllocL();
       
  2630 	
       
  2631 	// send to server
       
  2632 	SendReceive(EMsvIdWithSortFiled, TIpcArgs(aOperationId, iBuffer), aRequestStatus);
       
  2633 	CleanupStack::PopAndDestroy(2, flat);
       
  2634 	}
       
  2635 	
       
  2636 /** 
       
  2637 Sending result to server, this needs be sorted along with existing partial query.
       
  2638 @param aOperationId Opertion Id
       
  2639 @param aIdArray RArray of TMsvId 
       
  2640 @param aRequestStatus TRequestStatus status
       
  2641 @capability WriteUserData
       
  2642 */
       
  2643 void RMsvServerSession::SendNewResultsToServerForSortL(TMsvOp aOperationId, RArray<TMsvId>& aIdArray, TRequestStatus& aRequestStatus)
       
  2644 	{
       
  2645 	TestSlotAvailableL();
       
  2646 	TMsvPackedIdOperation op(iBuffer);
       
  2647 	TInt error = op.Pack(aIdArray);
       
  2648 	while (error != KErrNone)
       
  2649 		{
       
  2650 		// increase the size of the buffer and try again
       
  2651 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2652 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2653 		error = op.Pack(aIdArray);
       
  2654 		}
       
  2655 	SendReceive(EMsvUpdateAndSort, TIpcArgs(aOperationId, iBuffer), aRequestStatus);
       
  2656 	}
       
  2657 
       
  2658 /** 
       
  2659 Get list TMsvId from the server.
       
  2660 The list of TMsvId's may be 
       
  2661     case i)   Final Result
       
  2662     case ii)  Partial Result
       
  2663     case iii) New Query, needs search on Header and/or Body
       
  2664 @param aId RArray of TMsvId's (for case i & ii)
       
  2665 @param aResultStatus Result status, it will tell what kind of result it is..
       
  2666 @capability ReadUserData
       
  2667 */	
       
  2668 void RMsvServerSession::GetResultAsIdL(RArray<TMsvId>& aId, TInt &aResultStatus)
       
  2669 	{
       
  2670 	// pass the buffer to receive the data through
       
  2671 
       
  2672 	TPtr8 ptr=iBuffer->Des();
       
  2673 	TPckg<TInt> resultStatus(aResultStatus);
       
  2674 		
       
  2675 	// signal the server
       
  2676 	TInt error = SendReceive(EMsvGetIdsOrResult,TIpcArgs(&ptr, &resultStatus));
       
  2677 	while(error == KErrOverflow)
       
  2678 		{
       
  2679 		// increase the size of the buffer and try again
       
  2680 		iBuffer->Des().SetLength(0);
       
  2681 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2682 		
       
  2683 		// pass the buffer to receive the data through
       
  2684 		TPtr8 ptr=iBuffer->Des();
       
  2685 		error = SendReceive(EMsvGetIdsOrResult,TIpcArgs(&ptr, &resultStatus));
       
  2686 		}
       
  2687 	User::LeaveIfError(error);
       
  2688 	
       
  2689 	// unpack aId from the buffer
       
  2690 	TMsvPackedIdOperation packedIdOperation(iBuffer);
       
  2691 	packedIdOperation.UnpackL(aId);
       
  2692 	}
       
  2693 	
       
  2694 /** 
       
  2695 Get next TMsvEntry from server
       
  2696 @param aEntry next result as TMsvEntry
       
  2697 @capability ReadUserData
       
  2698 */
       
  2699 void RMsvServerSession::GetNextEntryL(TMsvEntry& aEntry, TInt& aCount)
       
  2700 	{
       
  2701 	TPckg<TInt> count(aCount);
       
  2702 	// pass the buffer to receive the data through
       
  2703 	TPtr8 ptr=iBuffer->Des();
       
  2704 	// signal the server
       
  2705 	TInt error = SendReceive(EMsvGetNextEntry,TIpcArgs(&ptr, &count));
       
  2706 	while(error == KErrOverflow)
       
  2707 		{
       
  2708 		// increase the size of the buffer and try again
       
  2709 		iBuffer->Des().SetLength(0);
       
  2710 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2711 		// pass the buffer to receive the data through
       
  2712 		TPtr8 ptr=iBuffer->Des();
       
  2713 		error = SendReceive(EMsvGetNextEntry,TIpcArgs(&ptr, &count));
       
  2714 		}
       
  2715 	User::LeaveIfError(error);
       
  2716 	TMsvPackedEntry packedEntry(iBuffer);
       
  2717 	packedEntry.UnpackEntry(aEntry);
       
  2718 	}
       
  2719 	
       
  2720 
       
  2721 /** 
       
  2722 Get next TMsvId from server
       
  2723 @param aId next result as TMsvId
       
  2724 @capability ReadUserData
       
  2725 */
       
  2726 void RMsvServerSession::GetNextIdL(TMsvId& aId, TInt& aCount)
       
  2727 	{
       
  2728 	TPckg<TMsvId> tmsvId(aId);
       
  2729 	TPckg<TInt> count(aCount);
       
  2730 	
       
  2731 	TInt error = SendReceive(EMsvGetNextId,TIpcArgs(&tmsvId, &count));
       
  2732 	User::LeaveIfError(error);
       
  2733 	}
       
  2734 
       
  2735 /** 
       
  2736 Get Result count from server
       
  2737 @param aCount Result count
       
  2738 @capability ReadUserData
       
  2739 */
       
  2740 void RMsvServerSession::GetResultCountL(TInt& aCount)
       
  2741 	{
       
  2742 	TPckg<TInt> count(aCount);
       
  2743 	// get result count from server
       
  2744 	User::LeaveIfError(SendReceive(EMsvGetResultCount,TIpcArgs(&count)));
       
  2745 	}
       
  2746 
       
  2747 /** 
       
  2748 Get Search sort request from server
       
  2749 This Query is requied in case partial result for the QueryId
       
  2750 @param aQuery Search Sort Query object
       
  2751 @param aOpId Opertion Id
       
  2752 @capability ReadUserData
       
  2753 */
       
  2754 void RMsvServerSession::GetQueryFromServerL(TMsvOp aOperationId, TInt aQueryId, CMsvSearchSortQuery* aQuery)
       
  2755 	{
       
  2756 	// pass the buffer to receive the query data
       
  2757 	TPtr8 ptr=iBuffer->Des();
       
  2758 	// signal the server
       
  2759 	TInt error = SendReceive(EMsvQueryData,TIpcArgs(aOperationId, aQueryId, &ptr));
       
  2760 	while(error == KErrOverflow)
       
  2761 		{
       
  2762 		// increase the size of the buffer and try again
       
  2763 		iBuffer->Des().SetLength(0);
       
  2764 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2765 		// pass the buffer to receive the data through
       
  2766 		TPtr8 ptr=iBuffer->Des();
       
  2767 		error = SendReceive(EMsvQueryData,TIpcArgs(aOperationId, aQueryId, &ptr));
       
  2768 		}
       
  2769 	User::LeaveIfError(error);
       
  2770 	
       
  2771 	TMsvPackQuery packedQuery(iBuffer);
       
  2772 	packedQuery.UnpackQuery(aQuery);	
       
  2773 	}
       
  2774 
       
  2775 /** 
       
  2776 Get Progress information from the server for a given Request.
       
  2777 @param aOperationProgress Operation progress
       
  2778 @param aOpId Opertion Id
       
  2779 @capability ReadUserData
       
  2780 */	
       
  2781 void RMsvServerSession::SearchSortOperationProgressL(TMsvOp aOperationId, TInt aOperationProgress)
       
  2782 	{
       
  2783 	TPckg<TInt> progressInfo(aOperationProgress);
       
  2784 	User::LeaveIfError(SendReceive(EMsvGetSearchSortProgress,TIpcArgs(aOperationId, &progressInfo)));
       
  2785 	}
       
  2786 
       
  2787 /** 
       
  2788 Cancel current saerch sort Request.
       
  2789 @param aOpId Opertion Id
       
  2790 @capability ReadUserData
       
  2791 */	
       
  2792 int RMsvServerSession::CancelSearchSortOperation(TMsvOp aOperationId)
       
  2793 	{
       
  2794 	TInt error = SendReceive(EMsvCancelSearchSortOp,TIpcArgs(aOperationId));
       
  2795 	return error;
       
  2796 	}
       
  2797 
       
  2798 
       
  2799 #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT)
       
  2800 #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE)
       
  2801 /**
       
  2802 Print cache structure in a log file.
       
  2803 */
       
  2804 EXPORT_C void RMsvServerSession::PrintCache()
       
  2805 	{
       
  2806 	SendReceive(EMsvPrintCache);
       
  2807 	}
       
  2808 #endif
       
  2809 #endif
       
  2810 
       
  2811 
       
  2812 
       
  2813 
       
  2814 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
       
  2815 
       
  2816 /**
       
  2817  * CreateStoreL()
       
  2818  * 
       
  2819  * A headerStore is associated with a mtm type and stores message header
       
  2820  * data. Message server creates a separate store for each MTM type. A 
       
  2821  * header-entry in the headerStore is essentially a list of UID-Data entries.
       
  2822  * For example an email header-entry can have CImHeader, MIME header and 
       
  2823  * encoded header stored as a separate UID-Data entry in the header store.
       
  2824  * By default a UID-Data entry will have a "Default" field which store the
       
  2825  * content of 'Data'. Moreover one such UID-Data pair can also specify mutiple
       
  2826  * fields such that it can store individual portion of data in such fields 
       
  2827  * separately. 
       
  2828  * 
       
  2829  * @param TUid: MtmId of the header store.
       
  2830  * @param RPointerArray<aFieldDetails>: Structure of the Data fields in a UID-Data pair.
       
  2831  * The store by default add a 'Details' field to store the content of data.
       
  2832  * @return None.
       
  2833  *
       
  2834  * @leave: All System wide error code.
       
  2835  *
       
  2836  * @capability WriteDeviceData
       
  2837  */
       
  2838 void RMsvServerSession::CreateStoreL(const TUid& aMtmId, const RPointerArray<CFieldPair>& aFieldDetails)
       
  2839 	{
       
  2840 	TMsvPackedHeaderStructure packedHeaderStruct(iBuffer);
       
  2841 	TInt error = packedHeaderStruct.Pack(aFieldDetails);
       
  2842 	while(error!=KErrNone)
       
  2843 		{
       
  2844 		// increase the size of the buffer and try again
       
  2845 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2846 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
  2847 		error = packedHeaderStruct.Pack(aFieldDetails);
       
  2848 		}
       
  2849 
       
  2850 	// package up the entry into a packed entry
       
  2851 	User::LeaveIfError(SendReceive(EMsvCreateStore, TIpcArgs(aMtmId.iUid, iBuffer)));
       
  2852 	}
       
  2853 
       
  2854 
       
  2855 
       
  2856 
       
  2857 
       
  2858 /**
       
  2859  * DoesStoreExistsL()
       
  2860  * 
       
  2861  * The function checks the existence of a header store
       
  2862  * for a given MTM Id. The function can be called to 
       
  2863  * check if the header store already exist before creating
       
  2864  * the store.
       
  2865  *
       
  2866  * @param TUid: Mtm UID of the store.
       
  2867  * @return TBool: ETrue, if the store exists, else EFalse.
       
  2868  *
       
  2869  * @capability ReadDeviceData 
       
  2870  */
       
  2871 TBool RMsvServerSession::DoesStoreExistsL(const TUid& aMtmId)
       
  2872 	{
       
  2873 	TPckg<TBool> isStoreExists = EFalse;
       
  2874 	User::LeaveIfError(SendReceive(EMsvCheckStoreExists, TIpcArgs(aMtmId.iUid, &isStoreExists)));
       
  2875 	return isStoreExists();
       
  2876 	}
       
  2877 
       
  2878 
       
  2879 
       
  2880 
       
  2881 
       
  2882 
       
  2883 /**
       
  2884  * LastErrorMessageL()
       
  2885  * 
       
  2886  * The function returns the detail error message 
       
  2887  * received while creating the header store.
       
  2888  *
       
  2889  * @param HBufC*: Error message text.
       
  2890  * @return None.
       
  2891  * @leave: All system wide error code.
       
  2892  */
       
  2893 void RMsvServerSession::LastErrorMessageL(HBufC*& aErrorMsg)
       
  2894 	{
       
  2895 	TPtr8 ptr8 = iBuffer->Des();
       
  2896 	User::LeaveIfError(SendReceive(EMsvLastErrorMessage, TIpcArgs(&ptr8)));
       
  2897 
       
  2898 	TInt* ptr = (TInt*) CONST_CAST(TUint8*, iBuffer->Ptr());
       
  2899 	TInt textSize = *ptr++;
       
  2900 	
       
  2901 	TPtrC16 ptrBuf;
       
  2902 	const TText* textPtr = (TText*)ptr;
       
  2903 	ptrBuf.Set(textPtr, (textSize/2));	
       
  2904 	
       
  2905 	aErrorMsg = ptrBuf.AllocL();
       
  2906 	}
       
  2907 
       
  2908 
       
  2909 
       
  2910 
       
  2911 
       
  2912 
       
  2913 
       
  2914 /**
       
  2915  * CreateHeaderEntryL()
       
  2916  * 
       
  2917  * This function creates a new message header in the header-store. A message header is
       
  2918  * essentially a list of UID-Data entry. At most one entry in the list must have 
       
  2919  * values for all the fields created in the header store. Rest all entries should have
       
  2920  * values for only default field 'Details'.
       
  2921  *
       
  2922  * @param TUid: MtmId to identify the header table.
       
  2923  * @param TMsvId: Metadata Entry Id.
       
  2924  * @param RPointerArray<CHeaderFields>: Header details.
       
  2925  * @return None.
       
  2926  * @leave KErrAlreadyExists, if entry already exists.
       
  2927  * @leave KErrArgument, if incorrect arguments and system wide leave code.
       
  2928  *
       
  2929  * @capability WriteUserData
       
  2930  */	
       
  2931 EXPORT_C void RMsvServerSession::CreateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList)
       
  2932 	{
       
  2933 	TMsvPackedHeaderData packedHeaderData(iBuffer);
       
  2934 	TInt error = packedHeaderData.Pack(aFieldPairList);
       
  2935 	while(error!=KErrNone)
       
  2936 		{
       
  2937 		// increase the size of the buffer and try again
       
  2938 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2939 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
  2940 		error = packedHeaderData.Pack(aFieldPairList);
       
  2941 		}
       
  2942 
       
  2943 	User::LeaveIfError(SendReceive(EMsvCreateHeaderEntry, TIpcArgs(aMtmId.iUid, aEntryId, iBuffer)));
       
  2944 	}
       
  2945 
       
  2946 
       
  2947 
       
  2948 
       
  2949 
       
  2950 /**
       
  2951  * LoadHeaderEntryL()
       
  2952  *
       
  2953  * This function loads the header entry from the header-store
       
  2954  * and returns to the client.
       
  2955  *
       
  2956  * @param TUid: MtmId to identify the header table.
       
  2957  * @param TMsvId: Metadata Entry Id.
       
  2958  * @param RPointerArray<CHeaderFields>: Header entry details.
       
  2959  * @return None.
       
  2960  * @leave KErrNotFound: If entry not found. 
       
  2961  *
       
  2962  * @capability ReadUserData
       
  2963  */	
       
  2964  EXPORT_C void RMsvServerSession::LoadHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, RPointerArray<CHeaderFields>& aFieldPairList)
       
  2965 	{
       
  2966 	TPtr8 ptr = iBuffer->Des();	
       
  2967 	User::LeaveIfError(SendReceive(EMsvLoadHeaderEntry, TIpcArgs(aMtmId.iUid, aEntryId, &ptr)));
       
  2968 	
       
  2969 	TMsvPackedHeaderData packedHeaderData(iBuffer);
       
  2970 	TRAPD(error, packedHeaderData.UnpackL(aFieldPairList));	
       
  2971 	while(error!=KErrNone)
       
  2972 		{
       
  2973 		// increase the size of the buffer and try again
       
  2974 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2975 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
  2976 		TRAP(error, packedHeaderData.UnpackL(aFieldPairList));
       
  2977 		}
       
  2978 	}
       
  2979 	
       
  2980 	
       
  2981 	
       
  2982 	
       
  2983 	
       
  2984 
       
  2985 /**
       
  2986  * DeleteHeaderEntryL()
       
  2987  *
       
  2988  * This function deletes the header entry from the header-store.
       
  2989  *
       
  2990  * @param aMtmId: MtmId to identify the header table.
       
  2991  * @param aEntryId: Entry Id.
       
  2992  * @return None.
       
  2993  * @leave KErrNotFound: If entry not found. 
       
  2994  *
       
  2995  * @capability WriteUserData
       
  2996  */		
       
  2997 EXPORT_C void RMsvServerSession::DeleteHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId)
       
  2998 	{
       
  2999 	User::LeaveIfError(SendReceive(EMsvDeleteHeaderEntry, TIpcArgs(aMtmId.iUid, aEntryId)));
       
  3000 	}
       
  3001 
       
  3002 
       
  3003 
       
  3004 
       
  3005 
       
  3006 /**
       
  3007  * UpdateHeaderEntryL()
       
  3008  *
       
  3009  * This function udpates the header entry in the header-store. A header entry is 
       
  3010  * essentially a list of UID-String combination which is stored as a separate 
       
  3011  * element in the passed header structure. 
       
  3012  *
       
  3013  * If the number of UID-String element in the passed header structure is more
       
  3014  * than what is present in the DB, the function inserts the new UID-String entry
       
  3015  * in the header store. And if the few entries are missing from the passed header 
       
  3016  * structure the function deletes the extra entry from the header store.
       
  3017  *
       
  3018  * @param TUid: MtmId to identify the header table.
       
  3019  * @param TMsvId: Entry Id.
       
  3020  * @param RPointerArray<CHeaderFields>: Header entry details.
       
  3021  * @return None.
       
  3022  * @leave KErrNotFound, if entry to be updated not found and all system wide leave code.
       
  3023  *
       
  3024  * @capability WriteUserData
       
  3025  */	
       
  3026 EXPORT_C void RMsvServerSession::UpdateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList)
       
  3027 	{
       
  3028 	TMsvPackedHeaderData packedHeaderData(iBuffer);
       
  3029 	TInt error = packedHeaderData.Pack(aFieldPairList);
       
  3030 	while(error!=KErrNone)
       
  3031 		{
       
  3032 		// increase the size of the buffer and try again
       
  3033 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  3034 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
  3035 		error = packedHeaderData.Pack(aFieldPairList);
       
  3036 		}
       
  3037 
       
  3038 	User::LeaveIfError(SendReceive(EMsvUpdateHeaderEntry, TIpcArgs(aMtmId.iUid, aEntryId, iBuffer)));
       
  3039 	}
       
  3040 	
       
  3041 
       
  3042 
       
  3043 
       
  3044 
       
  3045 
       
  3046 /**
       
  3047  * DoesAnyStoreExists()
       
  3048  *
       
  3049  * This function checks if the store (header/body) exists 
       
  3050  * for a given metadata entry.
       
  3051  */	
       
  3052 EXPORT_C TBool RMsvServerSession::DoesAnyStoreExists(TMsvId aId, TUid aMtmId)
       
  3053 	{
       
  3054 	return SendReceive(EMsvCheckAnyStoreExists, TIpcArgs(aId, aMtmId.iUid));
       
  3055 	}
       
  3056 
       
  3057 
       
  3058 
       
  3059 
       
  3060 /**
       
  3061  * DoesHeaderTableExist()
       
  3062  *
       
  3063  * This function checks if the header table exists
       
  3064  * for a given MTM type.
       
  3065  */	
       
  3066 EXPORT_C TBool RMsvServerSession::DoesHeaderTableExist(const TUid& aMtmId)
       
  3067 	{
       
  3068 	return SendReceive(EMsvCheckHeaderTableExist, TIpcArgs(aMtmId.iUid));
       
  3069 	}
       
  3070 	
       
  3071 
       
  3072 /********************************Converter API's***************************/
       
  3073 /*
       
  3074  GetConvertibleDriveListL()
       
  3075  Fetches a list of unsupported drives. Any drive is rendered unsupported
       
  3076  if the message store version is less than current message store version.
       
  3077  
       
  3078  @param aDriveList: RArray containing unsupported drive numbers.
       
  3079  @return None 
       
  3080  */
       
  3081 void RMsvServerSession::GetConvertibleDriveListL(RArray<TDriveNumber>& aDriveList)
       
  3082 	{
       
  3083 	TPtr8 ptr = iBuffer->Des();	
       
  3084 	User::LeaveIfError(SendReceive(EMsvGetConvertibleDriveList, TIpcArgs(&ptr)));	
       
  3085 	// Unpack the entries from the buffer.
       
  3086 	TMsvPackedDriveIdOperation packedDriveIdOperation(iBuffer);
       
  3087 	packedDriveIdOperation.UnpackL(aDriveList);	
       
  3088 	}
       
  3089 
       
  3090 /*
       
  3091  ConvertMessageStore()
       
  3092  Starts message store conversion on a drive asynchronously.
       
  3093  The message store to be converted is identified by the drive number
       
  3094  Message store conversion is an asynchronous operation and the client gets
       
  3095  notified by TRequestStatus variable.Message store conversion starts only when
       
  3096  the drive meets different validation criteria.
       
  3097    
       
  3098  
       
  3099  @param aDrive: Drive number.
       
  3100  @param aRequestStatus: Indicates the completion status of a request made to a service provider..
       
  3101  @return None 
       
  3102  */
       
  3103 void RMsvServerSession::ConvertMessageStore(TDriveNumber aDrive,TRequestStatus& aRequestStatus)
       
  3104 	{
       
  3105 	aRequestStatus=KRequestPending;
       
  3106 	SendReceive(EMsvConvertMessageStore, TIpcArgs(aDrive), aRequestStatus);
       
  3107 	}
       
  3108 
       
  3109 /*
       
  3110  GetConversionStatusL()
       
  3111  Gets the conversion status for the specified drive
       
  3112  
       
  3113  @param aDrive: Drive number.
       
  3114  @return None 
       
  3115  */
       
  3116 void RMsvServerSession::GetConversionStatusL(TDriveNumber aDrive)
       
  3117 	{
       
  3118 	User::LeaveIfError(SendReceive(EMsvGetConversionStatus, TIpcArgs(aDrive)));
       
  3119 	}
       
  3120 
       
  3121 /*
       
  3122  CancelConversion()
       
  3123  Cancels conversion for the specified drive.
       
  3124  
       
  3125  @param aDrive: Drive number.
       
  3126  @return TInt: System wide error codes
       
  3127  */	
       
  3128 TInt RMsvServerSession::CancelConversion(TDriveNumber aDrive)
       
  3129 	{
       
  3130 	return SendReceive(EMsvCancelConversionRequest, TIpcArgs(aDrive));
       
  3131 	}
       
  3132 #endif			// #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)