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