email/pop3andsmtpmtm/smtpservermtm/src/SMTS.CPP
changeset 0 72b543305e3a
child 76 60a8a215b0ec
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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 "SMTS.H"
       
    17 #include "SMTSUTIL.H"
       
    18 #include "IMSM.H"
       
    19 #include <smtpcmds.h>
       
    20 #include <msventry.h>
       
    21 #include <miutset.h>
       
    22 
       
    23 EXPORT_C CSmtpSrvMtm* CSmtpSrvMtm::NewL(CRegisteredMtmDll& aRegisteredMtmDll,CMsvServerEntry*  aEntry)
       
    24 	{
       
    25 	CSmtpSrvMtm* mysvrmtm = new CSmtpSrvMtm(aRegisteredMtmDll, aEntry);
       
    26 	if (mysvrmtm==NULL)
       
    27 		{
       
    28 		aRegisteredMtmDll.ReleaseLibrary();
       
    29 		User::Leave(KErrNoMemory);
       
    30 		}
       
    31 	CleanupStack::PushL(mysvrmtm);
       
    32 	mysvrmtm->ConstructL();
       
    33 	CleanupStack::Pop();
       
    34 	return mysvrmtm;
       
    35 	}
       
    36 
       
    37 CSmtpSrvMtm::CSmtpSrvMtm(CRegisteredMtmDll& aRegisteredMtmDll, CMsvServerEntry* aEntry):
       
    38 	CBaseServerMtm(aRegisteredMtmDll, aEntry)
       
    39 	{
       
    40 	__DECLARE_NAME(_S("CStmpSvrMtm"));
       
    41 	}
       
    42 		
       
    43 void CSmtpSrvMtm::ConstructL()
       
    44 	{
       
    45 	iSessionError=KErrNone;
       
    46 	iProgressBuffer().SetStatus(EMsgOutboxProgressDone);
       
    47 #if (defined SYMBIAN_USER_PROMPT_SERVICE)
       
    48 	iHasCapability = ETrue;
       
    49 #endif
       
    50 	CActiveScheduler::Add(this);
       
    51 	}
       
    52 
       
    53 CSmtpSrvMtm::~CSmtpSrvMtm()
       
    54 	{
       
    55 	Cancel();	//classes derived from CActive MUST call Cancel()
       
    56 	delete iOutboxSend;	//should already be dead
       
    57 	delete iSendSelection;
       
    58 	//  Set the Service Entry to be NOT connected
       
    59     SetServiceToConnected(EFalse);
       
    60    	}
       
    61 
       
    62 
       
    63 // aServiceId is ignored and the service ids of the messages in the selection
       
    64 // are used instead
       
    65 
       
    66 void CSmtpSrvMtm::CopyFromLocalL(const CMsvEntrySelection& aSelection, TMsvId aServiceId, /* Info for protocol....*/ TRequestStatus& aStatus)
       
    67 	{
       
    68 	iServiceId=aServiceId;
       
    69 	__ASSERT_DEBUG(iOutboxSend == NULL,gPanic(ESmtsBusy));
       
    70 	__ASSERT_DEBUG(iServerEntry != NULL,gPanic(EEntryNotSet));
       
    71 	if (IsActive())
       
    72 		User::Leave(KErrServerBusy);
       
    73 
       
    74 	if (iSendSelection)
       
    75 		iSendSelection->Reset();
       
    76 	else
       
    77 		iSendSelection=new (ELeave) CMsvEntrySelection;
       
    78 
       
    79 	CopyToOurSelectionL(aSelection);
       
    80 	AddWaitingInOutboxToSelectionL();
       
    81 
       
    82 	if (iSendSelection->Count())
       
    83 		DoSendMessagesL(aStatus);
       
    84 	else
       
    85 		{
       
    86 		iSessionError=KSmtpNoMsgsToSendWithActiveSettings;
       
    87 		TRequestStatus* pStatus=&aStatus;
       
    88 		User::RequestComplete(pStatus,KErrNone);//nothing to send
       
    89 		}
       
    90 	}
       
    91 
       
    92 
       
    93 
       
    94 void CSmtpSrvMtm::DoSendMessagesL(TRequestStatus& aStatus)
       
    95 	{
       
    96 	iSessionError = KErrNone;
       
    97     
       
    98 	// Set the Service entry to be Connected
       
    99 	User::LeaveIfError(SetServiceToConnected(ETrue));
       
   100 	
       
   101 	delete iOutboxSend;
       
   102 	iOutboxSend=NULL;
       
   103 	iOutboxSend = CMsgImOutboxSend::NewL(*iSendSelection,*iServerEntry,iServiceId);
       
   104 
       
   105 #if (defined SYMBIAN_USER_PROMPT_SERVICE)
       
   106 	iOutboxSend->StartL(iStatus, iClientThreadId, iHasCapability);
       
   107 #else
       
   108 	iOutboxSend->StartL(iStatus);
       
   109 #endif
       
   110 	
       
   111 	SetActive();
       
   112 	aStatus = KRequestPending;
       
   113 	iReport = &aStatus;
       
   114 	}
       
   115 
       
   116 
       
   117 //
       
   118 //	Progress()
       
   119 //
       
   120 //	Args:			None.
       
   121 //	
       
   122 //	Return Value:	TDesC& -- reference to a TBufPckg<TImSmtpProgress>
       
   123 //					maintained by the instantiated CMsgImOutboxSend
       
   124 //					object...
       
   125 //
       
   126 //	Remarks:				
       
   127 //
       
   128 const TDesC8& CSmtpSrvMtm::Progress()
       
   129 	{
       
   130 	//	load in latest progress, otherwise use saved progress
       
   131 	if(iOutboxSend!=NULL)
       
   132 		{
       
   133 		iProgressBuffer = iOutboxSend->Progress();
       
   134 		}
       
   135 	else
       
   136 		iProgressBuffer().SetError(iSessionError);
       
   137 	return iProgressBuffer;
       
   138 	}
       
   139 
       
   140 void CSmtpSrvMtm::DoCancel()
       
   141 	{
       
   142 	if(iOutboxSend)
       
   143 		{
       
   144 		iOutboxSend->Cancel();
       
   145 		Progress();	//update iProgressBuffer
       
   146 		delete  iOutboxSend;
       
   147 		iOutboxSend = NULL;
       
   148 		}
       
   149 
       
   150     //  Set the Service Entry to be NOT connected
       
   151     SetServiceToConnected(EFalse);
       
   152 
       
   153 	User::RequestComplete(iReport,KErrCancel);
       
   154 	}
       
   155 
       
   156 void CSmtpSrvMtm::DoRunL()
       
   157 	{
       
   158 	iSessionError = iStatus.Int();
       
   159 	Progress();
       
   160 
       
   161 	//	Delete the CImOutboxSend object.
       
   162 	delete  iOutboxSend;
       
   163 	iOutboxSend = NULL;
       
   164 
       
   165     //  Set the Service Entry to be NOT connected
       
   166     SetServiceToConnected(EFalse);
       
   167 
       
   168 	User::RequestComplete(iReport,KErrNone);	// always returns KErrNone; errors are returned in Progress
       
   169 	}
       
   170 
       
   171 void CSmtpSrvMtm::DoComplete(TInt aError)
       
   172 	{
       
   173 	iSessionError=aError;	// store error away to set Progress() later
       
   174 	User::RequestComplete(iReport,KErrNone);	// always returns KErrNone; errors are returned in Progress
       
   175 	}
       
   176 
       
   177 
       
   178 TBool CSmtpSrvMtm::CommandExpected()
       
   179 	{
       
   180 	return EFalse;
       
   181 	}
       
   182 
       
   183 void CSmtpSrvMtm::StartCommandL(CMsvEntrySelection& aSelection,
       
   184                                 TInt aCommand,
       
   185                                 const TDesC8& /*aParameter*/,
       
   186                                 TRequestStatus& aStatus)
       
   187 	{
       
   188 	TInt error = KErrNone;
       
   189 
       
   190     switch (aCommand)
       
   191         {
       
   192     //  Is session connected...
       
   193     case KSMTPMTMIsConnected:
       
   194 		if (iOutboxSend)
       
   195 			iOutboxSend->SessionIsConnected();
       
   196 		else 
       
   197             error = KErrDisconnected;    
       
   198         break;
       
   199     case KSMTPMTMSendOnNextConnection:
       
   200 		CopyFromLocalL(aSelection, aSelection.At(0), aStatus);
       
   201 		return;
       
   202     default:
       
   203         error = KErrNotSupported;
       
   204         break;
       
   205         }
       
   206 	iReport=&aStatus;
       
   207 	aStatus=KRequestPending;
       
   208 	User::RequestComplete(iReport, error);
       
   209 	}
       
   210 
       
   211 
       
   212 void CSmtpSrvMtm::CopyToOurSelectionL(const CMsvEntrySelection& aSourceSelection)
       
   213 	{
       
   214   	TInt count=aSourceSelection.Count();
       
   215   	TMsvEntry entry;
       
   216   	while (count--)
       
   217   		{
       
   218   		TInt err=iServerEntry->SetEntry(aSourceSelection[count]);
       
   219 		if(err==KErrNone)
       
   220 			{
       
   221   			entry=iServerEntry->Entry();
       
   222   
       
   223 			// If this entry is a message using the SMTP service & it hasn't been sent, 
       
   224 			// then add it to the list of entries to send.
       
   225   			if (entry.iMtm==KUidMsgTypeSMTP && entry.iType==KUidMsvMessageEntry &&	
       
   226 				entry.iServiceId==iServiceId && entry.SendingState() != KMsvSendStateSent)
       
   227 				{
       
   228 				iSendSelection->AppendL(aSourceSelection[count]);						
       
   229 				}
       
   230 			}
       
   231 		}
       
   232   	}
       
   233 
       
   234 void CSmtpSrvMtm::AddWaitingInOutboxToSelectionL()
       
   235 	{
       
   236 	User::LeaveIfError(iServerEntry->SetEntry(KMsvGlobalOutBoxIndexEntryId));
       
   237 	CMsvEntrySelection *sel = new (ELeave) CMsvEntrySelection;
       
   238 	CleanupStack::PushL(sel);
       
   239 	User::LeaveIfError(iServerEntry->GetChildrenWithService(iServiceId,*sel));
       
   240 	TInt count=sel->Count();
       
   241 	TMsvEntry entry;
       
   242 	while (count--)
       
   243 		{
       
   244 		TInt err=iServerEntry->SetEntry((*sel)[count]);
       
   245 		if(err==KErrNone)
       
   246 			{
       
   247 			entry=iServerEntry->Entry();
       
   248 			if ((entry.SendingState()==KMsvSendStateWaiting ||entry.SendingState()==KMsvSendStateScheduled || entry.SendingState()==KMsvSendStateResend) && //i.e send on next connection
       
   249 				iSendSelection->Find((*sel)[count])==KErrNotFound && 
       
   250 				entry.iType==KUidMsvMessageEntry) 
       
   251 				iSendSelection->AppendL((*sel)[count]);						
       
   252 			}
       
   253 		}
       
   254 	CleanupStack::PopAndDestroy(sel);
       
   255 	}
       
   256 
       
   257 
       
   258 TInt CSmtpSrvMtm::SetServiceToConnected(TBool aConnected)
       
   259 // Set the Service Entry to be either connected or not. 
       
   260 	{
       
   261 	TInt error = iServerEntry->SetEntry( iServiceId );
       
   262     if (error == KErrNone)
       
   263         {
       
   264         TMsvEntry entry = iServerEntry->Entry();
       
   265 
       
   266 		// Change the connected flag if not already set to this value
       
   267 		if (entry.Connected()!=aConnected)
       
   268 			{
       
   269 		    entry.SetConnected(aConnected);
       
   270 			error = iServerEntry->ChangeEntry(entry);
       
   271 			}
       
   272         }
       
   273 
       
   274 	// returns any error that occured
       
   275 	return error;
       
   276 	}
       
   277 
       
   278 
       
   279 //*****************************************************************************
       
   280 //The rest of the commands are unsupported
       
   281 //*****************************************************************************
       
   282 
       
   283 void CSmtpSrvMtm::MoveFromLocalL(const CMsvEntrySelection& /*aSelection*/,
       
   284                                  TMsvId /*aServiceId*/,
       
   285                                  TRequestStatus& aStatus)
       
   286 	{
       
   287 	__ASSERT_DEBUG(iOutboxSend == NULL,gPanic(ESmtsBusy));
       
   288 	iReport=&aStatus;
       
   289 	User::RequestComplete(iReport,KErrNotSupported);
       
   290 	}
       
   291 
       
   292 void CSmtpSrvMtm::CopyToLocalL(const CMsvEntrySelection& /*aSelection*/,
       
   293                                TMsvId /*aDestination*/, 
       
   294                                TRequestStatus& aStatus)
       
   295 	{
       
   296 	__ASSERT_DEBUG(iOutboxSend == NULL,gPanic(ESmtsBusy));
       
   297 	iReport=&aStatus;
       
   298 	User::RequestComplete(iReport,KErrNotSupported);
       
   299 	}
       
   300 
       
   301 void CSmtpSrvMtm::MoveToLocalL(const CMsvEntrySelection& /*aSelection*/,
       
   302                                TMsvId /*aDestination*/,
       
   303                                TRequestStatus& aStatus)
       
   304 	{
       
   305 	__ASSERT_DEBUG(iOutboxSend == NULL,gPanic(ESmtsBusy));
       
   306 	iReport=&aStatus;
       
   307 	User::RequestComplete(iReport,KErrNotSupported);
       
   308 	}
       
   309 
       
   310 void CSmtpSrvMtm::CopyWithinServiceL(const CMsvEntrySelection& /*aSelection*/,
       
   311                                      TMsvId /*aDestination*/, TRequestStatus& aStatus)
       
   312 	{
       
   313 	__ASSERT_DEBUG(iOutboxSend == NULL,gPanic(ESmtsBusy));
       
   314 	iReport=&aStatus;
       
   315 	User::RequestComplete(iReport,KErrNotSupported);
       
   316 	}
       
   317 
       
   318 void CSmtpSrvMtm::MoveWithinServiceL(const CMsvEntrySelection& /*aSelection*/,
       
   319                                      TMsvId /*aDestination*/,
       
   320                                      TRequestStatus& aStatus)
       
   321 	{
       
   322 	__ASSERT_DEBUG(iOutboxSend == NULL,gPanic(ESmtsBusy));
       
   323 	iReport=&aStatus;
       
   324 	User::RequestComplete(iReport,KErrNotSupported);
       
   325 	}
       
   326 
       
   327 void CSmtpSrvMtm::DeleteAllL(const CMsvEntrySelection& /*aSelection*/,
       
   328                              TRequestStatus& aStatus)
       
   329 	{
       
   330 	__ASSERT_DEBUG(iOutboxSend == NULL,gPanic(ESmtsBusy));
       
   331 	iReport=&aStatus;
       
   332 	User::RequestComplete(iReport,KErrNotSupported);
       
   333 	}
       
   334 
       
   335 void CSmtpSrvMtm::CreateL(TMsvEntry /*aNewEntry*/,
       
   336                           TRequestStatus& aStatus)
       
   337 	{
       
   338 	__ASSERT_DEBUG(iOutboxSend == NULL,gPanic(ESmtsBusy));
       
   339 	iReport=&aStatus;
       
   340 	User::RequestComplete(iReport,KErrNotSupported);
       
   341 	}
       
   342 
       
   343 void CSmtpSrvMtm::ChangeL(TMsvEntry /*aNewEntry*/,
       
   344                           TRequestStatus& aStatus)
       
   345 	{
       
   346 	__ASSERT_DEBUG(iOutboxSend == NULL,gPanic(ESmtsBusy));
       
   347 	iReport=&aStatus;
       
   348 	User::RequestComplete(iReport,KErrNotSupported);
       
   349 	}
       
   350 
       
   351 /**
       
   352 The extension method provides a polymorphic behaviour to call the correct
       
   353 MTM.
       
   354 @param aExtensionId The Uid passed in as KUIDMsgClientThreadInfo to copy the
       
   355 					Client Thread Info.
       
   356 @return KErrNone.
       
   357 */
       
   358 TInt CSmtpSrvMtm::Extension_(TUint aExtensionId, TAny *&a0, TAny *a1)	
       
   359 	{
       
   360 	switch(aExtensionId)
       
   361 		{
       
   362 #if (defined SYMBIAN_USER_PROMPT_SERVICE)		
       
   363 		case KUIDMsgClientThreadInfo:
       
   364 			{
       
   365 			iClientThreadId = *(TThreadId*) (a1);
       
   366 	    	iHasCapability = (TBool)*(TInt*)(a0);
       
   367 	    	return KErrNone;
       
   368 			}
       
   369 #endif
       
   370 
       
   371 		case KUidMsgNonOperationMtmData:
       
   372 			{
       
   373 			TNonOperationMtmDataType* mtmDataType = reinterpret_cast<TNonOperationMtmDataType*>(a0);
       
   374 			TPtrC8* mtmDataBuffer = reinterpret_cast<TPtrC8*>(a1);
       
   375 			return GetNonOperationMtmData(*mtmDataType, *mtmDataBuffer);
       
   376 			}
       
   377 
       
   378 		default:
       
   379 			{
       
   380 			// Chain to base class
       
   381 			return CBaseServerMtm::Extension_(aExtensionId, a0, a1);
       
   382 			}
       
   383 		}
       
   384 	}
       
   385 
       
   386 /**
       
   387 Gets MTM information that is not related to the current operation
       
   388 
       
   389 @param aMtmDataType Type of data to fetch
       
   390 @param aMtmDataBuffer On return this points to a descriptor holding the data
       
   391 
       
   392 @return KErrNone if successful, or a system wide error code
       
   393 */
       
   394 TInt CSmtpSrvMtm::GetNonOperationMtmData(TNonOperationMtmDataType aMtmDataType, TPtrC8& aMtmDataBuffer)
       
   395 	{
       
   396 	if (aMtmDataType == EMtmDataAccessPointId)
       
   397 		{
       
   398 		if (iOutboxSend)
       
   399 			{
       
   400 			TNonOperationMtmDataAccessPointId mtmDataAccessPointId;
       
   401 
       
   402 			TInt err = iOutboxSend->GetAccessPointIdForConnection(mtmDataAccessPointId.iAccessPointId);
       
   403 
       
   404 			if (err == KErrNone)
       
   405 				{
       
   406 				iMtmDataAccessPointIdBuffer = TNonOperationMtmDataAccessPointIdBuffer(mtmDataAccessPointId);
       
   407 				aMtmDataBuffer.Set(iMtmDataAccessPointIdBuffer);
       
   408 				return KErrNone;
       
   409 				}
       
   410 			}
       
   411 
       
   412 		return KErrNotFound;
       
   413 		}
       
   414 
       
   415 	return KErrNotSupported;
       
   416 	}
       
   417