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