pushmtm/Plugins/PushContentHandler/CMultiPartMixedContentHandler.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 CMultiPartMixedContentHandler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "CMultiPartMixedContentHandler.h"
       
    23 #include <PushDispatcher.h>
       
    24 #include <CMultiPartTextIterator.h>
       
    25 #include <CMultiPartBinIterator.h>
       
    26 
       
    27 // Constants
       
    28 
       
    29 _LIT(KReserved, "Reserved");
       
    30 #if defined(_DEBUG)
       
    31 _LIT(KErrPushMsgNull,	"NULL CPushMessage");
       
    32 #endif
       
    33 
       
    34 /** 
       
    35  * Static Factory Construction
       
    36  *
       
    37  * @param aFs Reference to a file session
       
    38  * @param aLibrary Reference to DLL Library Object
       
    39  * @param aIndex Index number corresponding to the Unknown App Handler Class 
       
    40  *        'EMultiPartMixedContentHandler'
       
    41  *
       
    42  * @return fully initialized instance of this class
       
    43  */
       
    44 CMultiPartMixedContentHandler* CMultiPartMixedContentHandler::NewL()
       
    45 	{
       
    46 	CMultiPartMixedContentHandler* self = 
       
    47         new (ELeave) CMultiPartMixedContentHandler;
       
    48 	CleanupStack::PushL(self);
       
    49 	self->ConstructL();
       
    50 	CleanupStack::Pop(self);
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 /** 
       
    55  * Destructor
       
    56  */
       
    57 CMultiPartMixedContentHandler::~CMultiPartMixedContentHandler()
       
    58 	{
       
    59     Cancel();
       
    60 	delete iMultiMessage;
       
    61     iContentHandler = NULL; // Not owned.
       
    62 	}
       
    63 
       
    64 /**
       
    65  * Constructor
       
    66  *
       
    67  * @param aFs Reference to a file session
       
    68  * @param aLibrary Reference to DLL Library Object
       
    69  * @param aIndex Index number corresponding to the Unknown App Handler Class 
       
    70  *        'EMultiPartMixedContentHandler'
       
    71  */ 
       
    72 CMultiPartMixedContentHandler::CMultiPartMixedContentHandler()
       
    73 :   CContentHandlerBase()
       
    74 	{
       
    75 	}
       
    76 
       
    77 /**
       
    78  *  This will complete initialization of the object
       
    79  */
       
    80 void CMultiPartMixedContentHandler::ConstructL()
       
    81 	{
       
    82 	CActiveScheduler::Add(this);
       
    83 	}
       
    84 
       
    85 #ifdef __TEST_MULTIPART_MIX_SUPP
       
    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(KErrPushMsgNull,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  *	Handles the Message Part returned from the Multipart iterator
       
   114  *  by creating a new handler based on the Content-Type, then dispatches it
       
   115  *  synchronously.
       
   116  */
       
   117 void CMultiPartMixedContentHandler::HandlePartL()
       
   118 	{
       
   119 	CPushMessage* msgPart = iMultiMessage->PartL();
       
   120 	CleanupStack::PushL(msgPart);
       
   121 	
       
   122 	TPtrC contentType;
       
   123 	msgPart->GetContentType(contentType);
       
   124 	CContentHandlerBase& contentHandler = 
       
   125         PushContentTypeDispatcher::GetHandlerL( contentType, *iLog, *iManager );
       
   126 	iContentHandler = &contentHandler;
       
   127 	CleanupStack::Pop(msgPart);
       
   128 
       
   129 	// treat as an acknowledged message always to ensure 
       
   130 	// sequential creation of handlers
       
   131 	iContentHandler->HandleMessageL(msgPart, iStatus);
       
   132 	iState = ENextPart;
       
   133 	SetActive();
       
   134 	}
       
   135 
       
   136 /**
       
   137  *	Moves multipart iterator to the next part. If there is none,
       
   138  *  State: EDone will be set to complete this handler
       
   139  */
       
   140 void CMultiPartMixedContentHandler::NextPartL()
       
   141 	{
       
   142 	if (iMultiMessage->NextL())
       
   143 		iState = EHandlePart;
       
   144 	else 
       
   145 		iState = EDone;
       
   146 	
       
   147 	IdleComplete();
       
   148 	}
       
   149 
       
   150 #endif // __TEST_MULTIPART_MIX_SUPP
       
   151 
       
   152 /** 
       
   153  * The Asynchronous entry point for this plug-in to handle the CPushMessage.
       
   154  * 
       
   155  * Since we really didn't start an async event, make it look as though our
       
   156  * asynchronous request has been completed. 
       
   157  *
       
   158  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
       
   159  * @param aStatus The TRequestStatus of the caller indicating that this will 
       
   160  *        be used aysnchronously
       
   161  */
       
   162 void CMultiPartMixedContentHandler::HandleMessageL( CPushMessage* aPushMsg, 
       
   163                                                     TRequestStatus& aStatus )
       
   164 	{
       
   165 	__ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone));
       
   166 
       
   167 #ifdef __TEST_MULTIPART_MIX_SUPP
       
   168 	iAcknowledge = ETrue;
       
   169 	iMessage = aPushMsg;
       
   170 	SetConfirmationStatus(aStatus);
       
   171 	iState = ELoadMsgData;
       
   172 	IdleComplete();
       
   173 #else // __TEST_MULTIPART_MIX_SUPP
       
   174 	iAcknowledge = ETrue;
       
   175 	iMessage = aPushMsg;
       
   176 	SetConfirmationStatus(aStatus);
       
   177     // Drop all multipart/mixed messages.
       
   178     iState = EDone;
       
   179 	IdleComplete();
       
   180 #endif // __TEST_MULTIPART_MIX_SUPP
       
   181 	}
       
   182 
       
   183 
       
   184 /** 
       
   185  * The Synchronous entry point for this plug-in to handle the CPushMessage.
       
   186  *
       
   187  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
       
   188  * @param aStatus The TRequestStatus of the caller indicating that this will be 
       
   189  *        used aysnchronously
       
   190  */
       
   191 void CMultiPartMixedContentHandler::HandleMessageL( CPushMessage* aPushMsg )
       
   192 	{
       
   193 	__ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone));
       
   194 
       
   195 #ifdef __TEST_MULTIPART_MIX_SUPP
       
   196 	iAcknowledge = EFalse;
       
   197 	iMessage = aPushMsg;
       
   198 	iState = ELoadMsgData;
       
   199 	IdleComplete();
       
   200 #else // __TEST_MULTIPART_MIX_SUPP
       
   201 	iAcknowledge = EFalse;
       
   202 	iMessage = aPushMsg;
       
   203     // Drop all multipart messages.
       
   204     iState = EDone;
       
   205 	IdleComplete();
       
   206 #endif // __TEST_MULTIPART_MIX_SUPP
       
   207 	}
       
   208 
       
   209 /** 
       
   210  * Cancels Asynronous requests on called handler.
       
   211  */
       
   212 void CMultiPartMixedContentHandler::CancelHandleMessage()
       
   213 	{
       
   214     Cancel();
       
   215 	}
       
   216 
       
   217 void CMultiPartMixedContentHandler::CPushHandlerBase_Reserved1()
       
   218 	{
       
   219 	User::Panic(KReserved, KErrNotSupported);
       
   220 	}
       
   221 
       
   222 void CMultiPartMixedContentHandler::CPushHandlerBase_Reserved2()
       
   223 	{
       
   224 	User::Panic(KReserved, KErrNotSupported);
       
   225 	}
       
   226 
       
   227 /** 
       
   228  * Cancels Asynronous requests on caller and completes self.
       
   229  */
       
   230 void CMultiPartMixedContentHandler::DoCancel()
       
   231 	{
       
   232 	if ( iContentHandler )
       
   233         {
       
   234 		iContentHandler->CancelHandleMessage();
       
   235         }
       
   236 	Complete( KErrCancel );
       
   237 	}
       
   238 
       
   239 /** 
       
   240  * State machine to step through the multipart message until it is done
       
   241  *
       
   242  * State EHandlePart: Starts the processing of each part of the multipart
       
   243  * State ENextPart: Moves the interator to point to the next part of the multipart
       
   244  * when there are no more parts, EDone will be the next state
       
   245  * State EDone: Clean up and complete
       
   246  */
       
   247 void CMultiPartMixedContentHandler::RunL()
       
   248 	{
       
   249 	switch(iState)
       
   250 		{
       
   251 
       
   252 #ifdef __TEST_MULTIPART_MIX_SUPP
       
   253 
       
   254         case ELoadMsgData:
       
   255             {
       
   256 			LoadMultipartMsgL();
       
   257 			break;
       
   258             }
       
   259 		case EHandlePart:
       
   260             {
       
   261 			HandlePartL();
       
   262 			break;
       
   263             }
       
   264 		case ENextPart:
       
   265             {
       
   266 			NextPartL();
       
   267 			break;
       
   268             }
       
   269 
       
   270 #endif // __TEST_MULTIPART_MIX_SUPP
       
   271 
       
   272         case EDone:
       
   273             {
       
   274 			Complete(KErrNone);
       
   275 			break;
       
   276             }
       
   277 		default:
       
   278             {
       
   279 			break;
       
   280             }
       
   281 		}
       
   282 	}
       
   283 
       
   284 /** 
       
   285  * Clean up
       
   286  */
       
   287 TInt CMultiPartMixedContentHandler::RunError(TInt aError)
       
   288 	{
       
   289 	iState=EDone;
       
   290 	Complete(aError);
       
   291 	return KErrNone;
       
   292 	}
       
   293