messagingfw/wappushfw/plugins/PushContentHandler/CMultiPartMixedContentHandler.cpp
changeset 0 8e480a14352b
child 44 7c176670643f
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     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 Mixed Loading Content Handler 'CMultiPartMixedContentHandler'
       
    15 // 
       
    16 //
       
    17 
       
    18 // Local includes
       
    19 //
       
    20 #include "CMultiPartMixedContentHandler.h"
       
    21 
       
    22 // System includes
       
    23 #include "cmultiparttextiterator.h"
       
    24 #include "pushdispatcher.h"
       
    25 
       
    26 // Constants
       
    27 _LIT(KReserved, "Reserved");
       
    28 
       
    29 void CMultiPartMixedContentHandler::CPushHandlerBase_Reserved1()
       
    30 	{
       
    31 	User::Panic(KReserved, KErrNotSupported);
       
    32 	}
       
    33 
       
    34 void CMultiPartMixedContentHandler::CPushHandlerBase_Reserved2()
       
    35 	{
       
    36 	User::Panic(KReserved, KErrNotSupported);
       
    37 	}
       
    38 
       
    39 /**
       
    40  * Constructor
       
    41  *
       
    42  * @param aFs Reference to a file session
       
    43  * @param aLibrary Reference to DLL Library Object
       
    44  * @param aIndex Index number corresponding to the Unknown App Handler Class 'EMultiPartMixedContentHandler'
       
    45  */ 
       
    46 CMultiPartMixedContentHandler::CMultiPartMixedContentHandler()
       
    47 : CContentHandlerBase()
       
    48 	{
       
    49 	}
       
    50 
       
    51 /**
       
    52  *  This will complete initialization of the object
       
    53  */
       
    54 void CMultiPartMixedContentHandler::ConstructL()
       
    55 	{
       
    56 	CActiveScheduler::Add(this);
       
    57 	}
       
    58 
       
    59 /** 
       
    60  * Static Factory Construction
       
    61  *
       
    62  * @param aFs Reference to a file session
       
    63  * @param aLibrary Reference to DLL Library Object
       
    64  * @param aIndex Index number corresponding to the Unknown App Handler Class 'EMultiPartMixedContentHandler'
       
    65  *
       
    66  * @return fully initialized instance of this class
       
    67  */
       
    68 CMultiPartMixedContentHandler* CMultiPartMixedContentHandler::NewL()
       
    69 	{
       
    70 	CMultiPartMixedContentHandler* self = new(ELeave) CMultiPartMixedContentHandler;
       
    71 	CleanupStack::PushL(self);
       
    72 	self->ConstructL();
       
    73 	CleanupStack::Pop(self);
       
    74 	return self;
       
    75 	}
       
    76 
       
    77 /** 
       
    78  * Destructor
       
    79  */
       
    80 CMultiPartMixedContentHandler::~CMultiPartMixedContentHandler()
       
    81 	{
       
    82 	 __LOG_PTR_DEBUG("CMultiPartMixedContentHandler:: Destructor"); 
       
    83 	 delete iMultiMessage;
       
    84 	}
       
    85 
       
    86 
       
    87 /** 
       
    88  * Creates a Multipart Binary Iterator that will be used for splitting apart the binary
       
    89  * mulitpart.
       
    90  *
       
    91  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
       
    92  */
       
    93 void CMultiPartMixedContentHandler::LoadMultipartMsgL()
       
    94 	{
       
    95 	__ASSERT_DEBUG( iMessage!= 0 , User::Panic(_L("NULL CPushMessage"),0));
       
    96 
       
    97 	TPtrC contentType;
       
    98 	iMessage->GetContentType(contentType);
       
    99 	if (!contentType.FindF(KMultipartText))
       
   100 		iMultiMessage = CMultipartTextIterator::NewL(*iMessage);
       
   101 	else if (!contentType.FindF(KMultipartBin))
       
   102 		iMultiMessage = CMultipartBinIterator::NewL(*iMessage);
       
   103 	else
       
   104 		User::Leave(KErrCorrupt);
       
   105 	
       
   106 	iMultiMessage->FirstL();
       
   107 	iState = EHandlePart;
       
   108 	
       
   109 	IdleComplete();
       
   110 	}
       
   111 
       
   112 
       
   113 /** 
       
   114  * The Asynchronous entry point for this plug-in to handle the CPushMessage.
       
   115  * 
       
   116  * Since we really didn't start an async event, make it look as though our
       
   117  * asynchronous request has been completed. 
       
   118  *
       
   119  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
       
   120  * @param aStatus The TRequestStatus of the caller indicating that this will be used aysnchronously
       
   121  */
       
   122 void CMultiPartMixedContentHandler::HandleMessageL(CPushMessage* aPushMsg, TRequestStatus& aStatus)
       
   123 	{
       
   124 	 __LOG_PTR_DEBUG("CMultiPartMixedContentHandler:: HandleMessage Async"); 
       
   125 
       
   126 	iAcknowledge = ETrue;
       
   127 	iMessage = aPushMsg;
       
   128 	SetConfirmationStatus(aStatus);
       
   129 	iState = ELoadMsgData;
       
   130 	IdleComplete();
       
   131 	}
       
   132 
       
   133 
       
   134 /** 
       
   135  * The Synchronous entry point for this plug-in to handle the CPushMessage.
       
   136  *
       
   137  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
       
   138  * @param aStatus The TRequestStatus of the caller indicating that this will be used aysnchronously
       
   139  */
       
   140 void CMultiPartMixedContentHandler::HandleMessageL(CPushMessage* aPushMsg)
       
   141 	{
       
   142 	 __LOG_PTR_DEBUG("CMultiPartMixedContentHandler:: HandleMessage Sync");
       
   143 
       
   144 	iAcknowledge = EFalse;
       
   145 	iMessage = aPushMsg;
       
   146 	iState = ELoadMsgData;
       
   147 	IdleComplete();
       
   148 	}
       
   149 
       
   150 
       
   151 /** 
       
   152  * Cancels Asynronous requests on called handler.
       
   153  */
       
   154 void CMultiPartMixedContentHandler::CancelHandleMessage()
       
   155 	{
       
   156 	if(iContentHandler)
       
   157 		iContentHandler->CancelHandleMessage();
       
   158 	}
       
   159 
       
   160 /** 
       
   161  * Cancels Asynronous requests on caller and completes self.
       
   162  */
       
   163 void CMultiPartMixedContentHandler::DoCancel()
       
   164 	{
       
   165 	 __LOG_PTR_DEBUG("CMultiPartMixedContentHandler:: DoCancel");
       
   166 
       
   167 	 if (iAcknowledge)
       
   168 		User::RequestComplete(iConfirmStatus,KErrCancel);
       
   169 	
       
   170 	 Complete(KErrCancel);
       
   171 	}
       
   172 
       
   173 /** 
       
   174  * State machine to step through the multipart message until it is done
       
   175  *
       
   176  * State EHandlePart: Starts the processing of each part of the multipart
       
   177  * State ENextPart: Moves the interator to point to the next part of the multipart
       
   178  * when there are no more parts, EDone will be the next state
       
   179  * State EDone: Clean up and complete
       
   180  */
       
   181 void CMultiPartMixedContentHandler::RunL()
       
   182 	{
       
   183 	switch(iState)
       
   184 		{
       
   185 		case ELoadMsgData:
       
   186 			LoadMultipartMsgL();
       
   187 			break;
       
   188 		case EHandlePart:
       
   189 			HandlePartL();
       
   190 			break;
       
   191 		case ENextPart:
       
   192 			NextPartL();
       
   193 			break;
       
   194 		case EDone:
       
   195 			Complete(KErrNone);
       
   196 			break;
       
   197 		default:
       
   198 			break;
       
   199 		}
       
   200 	}
       
   201 
       
   202 /** 
       
   203  * Clean up
       
   204  */
       
   205 TInt CMultiPartMixedContentHandler::RunError(TInt aError)
       
   206 	{
       
   207 	__LOG_PTR_DEBUG("CMultiPartMixedContentHandler::RunError Called"); 
       
   208 	iState=EDone;
       
   209 	Complete(aError);
       
   210 	return KErrNone;
       
   211 	}
       
   212 
       
   213 
       
   214 /**
       
   215  *	Handles the Message Part returned from the Multipart iterator
       
   216  *  by creating a new handler based on the Content-Type, then dispatches it
       
   217  *  synchronously.
       
   218  */
       
   219 void CMultiPartMixedContentHandler::HandlePartL()
       
   220 	{
       
   221 	 __LOG_PTR_DEBUG("CMultiPartMixedContentHandler:: HandlePart"); 
       
   222 	CPushMessage* msgPart = iMultiMessage->PartL();
       
   223 	CleanupStack::PushL(msgPart);
       
   224 	
       
   225 	TPtrC contentType;
       
   226 	msgPart->GetContentType(contentType);
       
   227 	CContentHandlerBase& contentHandler = PushContentTypeDispatcher::GetHandlerL(contentType, *iLog, *iManager);
       
   228 	iContentHandler = &contentHandler;
       
   229 	CleanupStack::Pop(msgPart);
       
   230 
       
   231 	// treat as an acknowledged message always to ensure 
       
   232 	// sequential creation of handlers
       
   233 	iContentHandler->HandleMessageL(msgPart, iStatus);
       
   234 	iState = ENextPart;
       
   235 	SetActive();
       
   236 	}
       
   237 
       
   238 /**
       
   239  *	Moves multipart iterator to the next part. If there is none,
       
   240  *  State: EDone will be set to complete this handler
       
   241  */
       
   242 void CMultiPartMixedContentHandler::NextPartL()
       
   243 	{
       
   244 	 __LOG_PTR_DEBUG("CMultiPartMixedContentHandler:: NextPartL");
       
   245 	if (iMultiMessage->NextL())
       
   246 		iState = EHandlePart;
       
   247 	else 
       
   248 		iState = EDone;
       
   249 	
       
   250 	IdleComplete();
       
   251 	}