pushmtm/plugins/PushContentHandler/CMultiPartRelAndAltContentHandler.cpp
branchRCL_3
changeset 69 4455192101e4
equal deleted inserted replaced
65:8e6fa1719340 69:4455192101e4
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of CMultiPartRelAndAltContentHandler.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "CMultiPartRelAndAltContentHandler.h"
       
    21 #include <push/cmultipartiteratorbase.h>
       
    22 #include <msvids.h>
       
    23 
       
    24 // Constants
       
    25 
       
    26 _LIT(KReserved, "Reserved");
       
    27 
       
    28 /**
       
    29  * Static Factory Construction
       
    30  *
       
    31  * version of NewLC which leaves nothing
       
    32  * on the cleanup stack
       
    33  */
       
    34 CMultiPartRelAndAltContentHandler* CMultiPartRelAndAltContentHandler::NewL()
       
    35 	{
       
    36 	CMultiPartRelAndAltContentHandler* self = new (ELeave) CMultiPartRelAndAltContentHandler;
       
    37 	CleanupStack::PushL(self);
       
    38 	self->ConstructL();
       
    39 	CleanupStack::Pop(self);
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 /**
       
    44  * Default d'tor
       
    45  */
       
    46 CMultiPartRelAndAltContentHandler::~CMultiPartRelAndAltContentHandler()
       
    47 	{
       
    48     Cancel();
       
    49 	delete iMultiMessage;
       
    50     delete iMsvSession;
       
    51 	}
       
    52 
       
    53 /**
       
    54  * The Multipart Related Content handler 
       
    55  * Index number : ESLContentHandlerIndex 
       
    56  */ 
       
    57 CMultiPartRelAndAltContentHandler::CMultiPartRelAndAltContentHandler()
       
    58 :   CContentHandlerBase(), 
       
    59     iSavedMsgId( KMsvNullIndexEntryId )
       
    60 	{
       
    61 	}
       
    62 
       
    63 /**
       
    64  *  This will complete initialization of the object
       
    65  */
       
    66 void CMultiPartRelAndAltContentHandler::ConstructL()
       
    67 	{
       
    68     iMsvSession = CMsvSession::OpenSyncL( *this );
       
    69 	CActiveScheduler::Add(this);
       
    70 	}
       
    71 
       
    72 #ifdef __TEST_MULTIPART_REL_SUPP
       
    73 
       
    74 /**
       
    75 * Setup the multipart message.
       
    76 */
       
    77 void CMultiPartRelAndAltContentHandler::LoadMultiPartMsgL()
       
    78 	{
       
    79 #ifdef _DEBUG
       
    80 	_LIT(KNullMsg,"NULL CPushMessage");
       
    81 	__ASSERT_DEBUG( iMessage != 0 , User::Panic(KNullMsg,0));
       
    82 #endif
       
    83 	TPtrC contentType;
       
    84 	iMessage->GetContentType(contentType);
       
    85 	if (!contentType.FindF(KMultipartText))
       
    86 		iMultiMessage = CMultipartTextIterator::NewL(*iMessage);
       
    87 	else if (!contentType.FindF(KMultipartBin))
       
    88 		iMultiMessage = CMultipartBinIterator::NewL(*iMessage);
       
    89 	else
       
    90 		User::Leave(KErrCorrupt);
       
    91 	iMultiMessage->FirstL();
       
    92 	IdleComplete();
       
    93 	}
       
    94 
       
    95 /**
       
    96  *	Saves message part to messaging server
       
    97  */
       
    98 void CMultiPartRelAndAltContentHandler::HandlePartL()
       
    99 	{
       
   100 	CPushMessage* msgPart = iMultiMessage->PartL();
       
   101 	CleanupStack::PushL(msgPart);
       
   102 
       
   103 	// Create a new Unknown Push Entry to hold the header and body data
       
   104 	CUnknownPushMsgEntry* msgEntry=CUnknownPushMsgEntry::NewL();
       
   105 	CleanupStack::PushL(msgEntry);
       
   106 	// Get the header
       
   107 	TPtrC8 header;
       
   108 	msgPart->GetHeader(header);
       
   109 	//Get the From field
       
   110 	TPtrC8 from;
       
   111 	if (!msgPart->GetBinaryHeaderField(EHttpFrom,from) &&
       
   112 		!msgPart->GetBinaryHeaderField(EHttpXWapInitiatorURI,from) &&
       
   113 		!msgPart->GetBinaryHeaderField(EHttpContentLocation,from) )
       
   114 		{
       
   115 		from.Set(KNullDesC8);
       
   116 		}
       
   117 	// Get the body
       
   118 	TPtrC8 body;
       
   119 	msgPart->GetMessageBody(body);
       
   120 	TPtrC content;
       
   121 	msgPart->GetContentType(content);
       
   122 
       
   123 	//Set fields of the Unknown Entry
       
   124 	msgEntry->SetHeaderL(header);
       
   125 	msgEntry->SetMessageDataL(body);	
       
   126 	msgEntry->SetFromL(from);
       
   127 	//Need this next  bit so UI knows what to do with the data in the Push Entry
       
   128 	msgEntry->SetContentTypeL( content );
       
   129 
       
   130 	msgEntry->SaveL( *iMsvSession, iSavedMsgId );
       
   131 	CleanupStack::PopAndDestroy( 2 ); //msgEntry, msgPart
       
   132 	
       
   133 	iState = ENextPart;
       
   134 	IdleComplete();
       
   135 
       
   136 	}
       
   137 
       
   138 /**
       
   139  *	Move multipart iterator to the next part
       
   140  */
       
   141 void CMultiPartRelAndAltContentHandler::NextPartL()
       
   142 	{
       
   143 	if (iMultiMessage->NextL())
       
   144 		{
       
   145 		iState = EHandlePart;
       
   146 		}
       
   147 	else 
       
   148 		{
       
   149 		iState = EDone;
       
   150 		}
       
   151 	IdleComplete();
       
   152 	}
       
   153 
       
   154 /**
       
   155  * 
       
   156  */
       
   157 void CMultiPartRelAndAltContentHandler::SaveMsgRootL()
       
   158 	{
       
   159 	TPtrC8 msgHeaderPtr;
       
   160 	iMessage->GetHeader(msgHeaderPtr);
       
   161 	CMultiPartPushMsgEntry* msgEntry=CMultiPartPushMsgEntry::NewL();
       
   162 	CleanupStack::PushL(msgEntry);
       
   163 	msgEntry->SetHeaderL(msgHeaderPtr); //Top level entry
       
   164 	TPtrC contentType;
       
   165 	iMessage->GetContentType(contentType);
       
   166 	msgEntry->SetContentTypeL(contentType);
       
   167 
       
   168 	iSavedMsgId = msgEntry->SaveL(*iMsvSession, 
       
   169                                   KMsvGlobalInBoxIndexEntryId);
       
   170 	CleanupStack::PopAndDestroy();//msgEntry
       
   171 	}
       
   172 
       
   173 /**
       
   174  * Loads multipart data and creates multipart head entry in the message 
       
   175  * server index.
       
   176  * @throw KErrCorrupt - message data is corrupt 
       
   177  * @throw KErrNoMemory - insufficient free memory to complete operations
       
   178  */
       
   179 
       
   180 void CMultiPartRelAndAltContentHandler::LoadMsgDataL()
       
   181 	{
       
   182 	LoadMultiPartMsgL();
       
   183 	SaveMsgRootL();
       
   184 	iState = EHandlePart;
       
   185 	}
       
   186 
       
   187 void CMultiPartRelAndAltContentHandler::SetMsgCorruptFlagL()
       
   188 	{
       
   189 	CMsvEntry* msvEntry = iMsvSession->GetEntryL( iSavedMsgId );
       
   190 	CleanupStack::PushL( msvEntry );
       
   191 	TMsvEntry entry = msvEntry->Entry();
       
   192 	// get the iMtmData1 value & zero bits 0-3 then add new status
       
   193 	TInt32 mtmdata1 = ( entry.iMtmData1 & 0xFFFFFFF0 );
       
   194 	mtmdata1 += CPushMsgEntryBase::EPushMsgStatusCorrupt;
       
   195 	// Now set values for TMsvEntry and update the server entry
       
   196 	entry.iMtmData1 = mtmdata1;
       
   197 	msvEntry->ChangeL( entry );
       
   198 
       
   199 	CleanupStack::PopAndDestroy( msvEntry );
       
   200 	}
       
   201 
       
   202 #endif // __TEST_MULTIPART_REL_SUPP
       
   203 
       
   204 /**
       
   205  * Async. Version
       
   206  */
       
   207 void CMultiPartRelAndAltContentHandler::HandleMessageL( CPushMessage* aPushMsg, 
       
   208                                                         TRequestStatus& aStatus )
       
   209 	{
       
   210 #ifdef __TEST_MULTIPART_REL_SUPP
       
   211 	iAcknowledge=ETrue;
       
   212 	SetConfirmationStatus(aStatus);
       
   213 	iMessage = aPushMsg;
       
   214 	iState = ELoadMsgData;
       
   215 	IdleComplete();
       
   216 #else // __TEST_MULTIPART_REL_SUPP
       
   217 	iAcknowledge=ETrue;
       
   218 	SetConfirmationStatus(aStatus);
       
   219 	iMessage = aPushMsg;
       
   220     // Drop all multipart messages.
       
   221     iState = EDone;
       
   222 	IdleComplete();
       
   223 #endif // __TEST_MULTIPART_REL_SUPP
       
   224 	}
       
   225 
       
   226 /**
       
   227  * Sync. Version
       
   228  */
       
   229 void CMultiPartRelAndAltContentHandler::HandleMessageL( CPushMessage* aPushMsg )
       
   230 	{
       
   231 #ifdef __TEST_MULTIPART_REL_SUPP
       
   232 	iAcknowledge=EFalse;
       
   233 	iMessage = aPushMsg;
       
   234 	iState = ELoadMsgData;
       
   235 	IdleComplete();
       
   236 #else // __TEST_MULTIPART_REL_SUPP
       
   237 	iAcknowledge=EFalse;
       
   238 	iMessage = aPushMsg;
       
   239     // Drop all multipart messages.
       
   240     iState = EDone;
       
   241 	IdleComplete();
       
   242 #endif // __TEST_MULTIPART_REL_SUPP
       
   243 	}
       
   244 
       
   245 void CMultiPartRelAndAltContentHandler::CancelHandleMessage()
       
   246 	{
       
   247     Cancel();
       
   248 	}
       
   249 
       
   250 void CMultiPartRelAndAltContentHandler::CPushHandlerBase_Reserved1()
       
   251 	{
       
   252 	User::Panic(KReserved, KErrNotSupported);
       
   253 	}
       
   254 
       
   255 void CMultiPartRelAndAltContentHandler::CPushHandlerBase_Reserved2()
       
   256 	{
       
   257 	User::Panic(KReserved, KErrNotSupported);
       
   258 	}
       
   259 
       
   260 void CMultiPartRelAndAltContentHandler::DoCancel()
       
   261 	{
       
   262 	Complete( KErrCancel );
       
   263 	}
       
   264 
       
   265 /**
       
   266 *RunL handles each part separately
       
   267 */
       
   268 void CMultiPartRelAndAltContentHandler::RunL()
       
   269 	{
       
   270 	switch(iState)
       
   271 		{
       
   272 
       
   273 #ifdef __TEST_MULTIPART_REL_SUPP
       
   274 
       
   275         case ELoadMsgData:
       
   276             {
       
   277 			LoadMsgDataL();
       
   278 			break;
       
   279             }
       
   280 		case EHandlePart:
       
   281             {
       
   282 			HandlePartL();
       
   283 			break;
       
   284             }
       
   285 		case ENextPart:
       
   286             {
       
   287 			NextPartL();
       
   288 			break;
       
   289             }
       
   290 
       
   291 #endif // __TEST_MULTIPART_REL_SUPP
       
   292 
       
   293         case EDone:
       
   294             {
       
   295 			Complete(KErrNone);
       
   296 			break;
       
   297             }
       
   298 		default:
       
   299             {
       
   300 			break;
       
   301             }
       
   302 		}
       
   303 	}
       
   304 
       
   305 /** 
       
   306  * Clean up
       
   307  */
       
   308 TInt CMultiPartRelAndAltContentHandler::RunError(TInt aError)
       
   309 	{
       
   310 	iState=EDone;
       
   311 
       
   312 #ifdef __TEST_MULTIPART_REL_SUPP
       
   313 
       
   314     if (iSavedMsgId != KMsvNullIndexEntryId)
       
   315 		{
       
   316 		TRAPD(error, SetMsgCorruptFlagL());
       
   317 		}
       
   318 
       
   319 #endif // __TEST_MULTIPART_REL_SUPP
       
   320 
       
   321 	Complete(aError);
       
   322 	return KErrNone;
       
   323 	}
       
   324 
       
   325 // ---------------------------------------------------------
       
   326 // CMultiPartRelAndAltContentHandler::HandleSessionEventL
       
   327 // ---------------------------------------------------------
       
   328 //
       
   329 void CMultiPartRelAndAltContentHandler::HandleSessionEventL( 
       
   330                                              TMsvSessionEvent /*aEvent*/, 
       
   331                                              TAny* /*aArg1*/, 
       
   332                                              TAny* /*aArg2*/, 
       
   333                                              TAny* /*aArg3*/ )
       
   334     {}
       
   335