pushmtm/Plugins/PushContentHandler/CMultiPartMixedContentHandler.cpp
changeset 32 92a061761a7b
parent 0 84ad3b177aa3
equal deleted inserted replaced
31:868cceedabd3 32:92a061761a7b
    13 *
    13 *
    14 * Description:  Implementation of CMultiPartMixedContentHandler.
    14 * Description:  Implementation of CMultiPartMixedContentHandler.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
       
    19 
       
    20 // INCLUDE FILES
    18 // INCLUDE FILES
    21 
    19 
    22 #include "CMultiPartMixedContentHandler.h"
    20 #include "CMultiPartMixedContentHandler.h"
    23 #include <PushDispatcher.h>
    21 #include <push/pushdispatcher.h>
    24 #include <CMultiPartTextIterator.h>
    22 #include <push/cmultiparttextiterator.h>
    25 #include <CMultiPartBinIterator.h>
    23 #include <push/cmultipartbiniterator.h>
    26 
    24 
    27 // Constants
    25 // Constants
    28 
    26 
    29 _LIT(KReserved, "Reserved");
    27 _LIT(KReserved, "Reserved");
    30 #if defined(_DEBUG)
    28 #if defined(_DEBUG)
    31 _LIT(KErrPushMsgNull,	"NULL CPushMessage");
    29 _LIT(KErrPushMsgNull,	"NULL CPushMessage");
    32 #endif
    30 #endif
    33 
    31 
    34 /** 
    32 /**
    35  * Static Factory Construction
    33  * Static Factory Construction
    36  *
    34  *
    37  * @param aFs Reference to a file session
    35  * @param aFs Reference to a file session
    38  * @param aLibrary Reference to DLL Library Object
    36  * @param aLibrary Reference to DLL Library Object
    39  * @param aIndex Index number corresponding to the Unknown App Handler Class 
    37  * @param aIndex Index number corresponding to the Unknown App Handler Class
    40  *        'EMultiPartMixedContentHandler'
    38  *        'EMultiPartMixedContentHandler'
    41  *
    39  *
    42  * @return fully initialized instance of this class
    40  * @return fully initialized instance of this class
    43  */
    41  */
    44 CMultiPartMixedContentHandler* CMultiPartMixedContentHandler::NewL()
    42 CMultiPartMixedContentHandler* CMultiPartMixedContentHandler::NewL()
    45 	{
    43 	{
    46 	CMultiPartMixedContentHandler* self = 
    44 	CMultiPartMixedContentHandler* self =
    47         new (ELeave) CMultiPartMixedContentHandler;
    45         new (ELeave) CMultiPartMixedContentHandler;
    48 	CleanupStack::PushL(self);
    46 	CleanupStack::PushL(self);
    49 	self->ConstructL();
    47 	self->ConstructL();
    50 	CleanupStack::Pop(self);
    48 	CleanupStack::Pop(self);
    51 	return self;
    49 	return self;
    52 	}
    50 	}
    53 
    51 
    54 /** 
    52 /**
    55  * Destructor
    53  * Destructor
    56  */
    54  */
    57 CMultiPartMixedContentHandler::~CMultiPartMixedContentHandler()
    55 CMultiPartMixedContentHandler::~CMultiPartMixedContentHandler()
    58 	{
    56 	{
    59     Cancel();
    57     Cancel();
    64 /**
    62 /**
    65  * Constructor
    63  * Constructor
    66  *
    64  *
    67  * @param aFs Reference to a file session
    65  * @param aFs Reference to a file session
    68  * @param aLibrary Reference to DLL Library Object
    66  * @param aLibrary Reference to DLL Library Object
    69  * @param aIndex Index number corresponding to the Unknown App Handler Class 
    67  * @param aIndex Index number corresponding to the Unknown App Handler Class
    70  *        'EMultiPartMixedContentHandler'
    68  *        'EMultiPartMixedContentHandler'
    71  */ 
    69  */
    72 CMultiPartMixedContentHandler::CMultiPartMixedContentHandler()
    70 CMultiPartMixedContentHandler::CMultiPartMixedContentHandler()
    73 :   CContentHandlerBase()
    71 :   CContentHandlerBase()
    74 	{
    72 	{
    75 	}
    73 	}
    76 
    74 
    82 	CActiveScheduler::Add(this);
    80 	CActiveScheduler::Add(this);
    83 	}
    81 	}
    84 
    82 
    85 #ifdef __TEST_MULTIPART_MIX_SUPP
    83 #ifdef __TEST_MULTIPART_MIX_SUPP
    86 
    84 
    87 /** 
    85 /**
    88  * Creates a Multipart Binary Iterator that will be used for splitting apart the binary
    86  * Creates a Multipart Binary Iterator that will be used for splitting apart the binary
    89  * mulitpart.
    87  * mulitpart.
    90  *
    88  *
    91  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
    89  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
    92  */
    90  */
   100 		iMultiMessage = CMultipartTextIterator::NewL(*iMessage);
    98 		iMultiMessage = CMultipartTextIterator::NewL(*iMessage);
   101 	else if (!contentType.FindF(KMultipartBin))
    99 	else if (!contentType.FindF(KMultipartBin))
   102 		iMultiMessage = CMultipartBinIterator::NewL(*iMessage);
   100 		iMultiMessage = CMultipartBinIterator::NewL(*iMessage);
   103 	else
   101 	else
   104 		User::Leave(KErrCorrupt);
   102 		User::Leave(KErrCorrupt);
   105 	
   103 
   106 	iMultiMessage->FirstL();
   104 	iMultiMessage->FirstL();
   107 	iState = EHandlePart;
   105 	iState = EHandlePart;
   108 	
   106 
   109 	IdleComplete();
   107 	IdleComplete();
   110 	}
   108 	}
   111 
   109 
   112 /**
   110 /**
   113  *	Handles the Message Part returned from the Multipart iterator
   111  *	Handles the Message Part returned from the Multipart iterator
   116  */
   114  */
   117 void CMultiPartMixedContentHandler::HandlePartL()
   115 void CMultiPartMixedContentHandler::HandlePartL()
   118 	{
   116 	{
   119 	CPushMessage* msgPart = iMultiMessage->PartL();
   117 	CPushMessage* msgPart = iMultiMessage->PartL();
   120 	CleanupStack::PushL(msgPart);
   118 	CleanupStack::PushL(msgPart);
   121 	
   119 
   122 	TPtrC contentType;
   120 	TPtrC contentType;
   123 	msgPart->GetContentType(contentType);
   121 	msgPart->GetContentType(contentType);
   124 	CContentHandlerBase& contentHandler = 
   122 	CContentHandlerBase& contentHandler =
   125         PushContentTypeDispatcher::GetHandlerL( contentType, *iLog, *iManager );
   123         PushContentTypeDispatcher::GetHandlerL( contentType, *iLog, *iManager );
   126 	iContentHandler = &contentHandler;
   124 	iContentHandler = &contentHandler;
   127 	CleanupStack::Pop(msgPart);
   125 	CleanupStack::Pop(msgPart);
   128 
   126 
   129 	// treat as an acknowledged message always to ensure 
   127 	// treat as an acknowledged message always to ensure
   130 	// sequential creation of handlers
   128 	// sequential creation of handlers
   131 	iContentHandler->HandleMessageL(msgPart, iStatus);
   129 	iContentHandler->HandleMessageL(msgPart, iStatus);
   132 	iState = ENextPart;
   130 	iState = ENextPart;
   133 	SetActive();
   131 	SetActive();
   134 	}
   132 	}
   139  */
   137  */
   140 void CMultiPartMixedContentHandler::NextPartL()
   138 void CMultiPartMixedContentHandler::NextPartL()
   141 	{
   139 	{
   142 	if (iMultiMessage->NextL())
   140 	if (iMultiMessage->NextL())
   143 		iState = EHandlePart;
   141 		iState = EHandlePart;
   144 	else 
   142 	else
   145 		iState = EDone;
   143 		iState = EDone;
   146 	
   144 
   147 	IdleComplete();
   145 	IdleComplete();
   148 	}
   146 	}
   149 
   147 
   150 #endif // __TEST_MULTIPART_MIX_SUPP
   148 #endif // __TEST_MULTIPART_MIX_SUPP
   151 
   149 
   152 /** 
   150 /**
   153  * The Asynchronous entry point for this plug-in to handle the CPushMessage.
   151  * The Asynchronous entry point for this plug-in to handle the CPushMessage.
   154  * 
   152  *
   155  * Since we really didn't start an async event, make it look as though our
   153  * Since we really didn't start an async event, make it look as though our
   156  * asynchronous request has been completed. 
   154  * asynchronous request has been completed.
   157  *
   155  *
   158  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
   156  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
   159  * @param aStatus The TRequestStatus of the caller indicating that this will 
   157  * @param aStatus The TRequestStatus of the caller indicating that this will
   160  *        be used aysnchronously
   158  *        be used aysnchronously
   161  */
   159  */
   162 void CMultiPartMixedContentHandler::HandleMessageL( CPushMessage* aPushMsg, 
   160 void CMultiPartMixedContentHandler::HandleMessageL( CPushMessage* aPushMsg,
   163                                                     TRequestStatus& aStatus )
   161                                                     TRequestStatus& aStatus )
   164 	{
   162 	{
   165 	__ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone));
   163 	__ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone));
   166 
   164 
   167 #ifdef __TEST_MULTIPART_MIX_SUPP
   165 #ifdef __TEST_MULTIPART_MIX_SUPP
   179 	IdleComplete();
   177 	IdleComplete();
   180 #endif // __TEST_MULTIPART_MIX_SUPP
   178 #endif // __TEST_MULTIPART_MIX_SUPP
   181 	}
   179 	}
   182 
   180 
   183 
   181 
   184 /** 
   182 /**
   185  * The Synchronous entry point for this plug-in to handle the CPushMessage.
   183  * The Synchronous entry point for this plug-in to handle the CPushMessage.
   186  *
   184  *
   187  * @param aPushMsg A WAP binary multipart.mixed message that will be processed
   185  * @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 
   186  * @param aStatus The TRequestStatus of the caller indicating that this will be
   189  *        used aysnchronously
   187  *        used aysnchronously
   190  */
   188  */
   191 void CMultiPartMixedContentHandler::HandleMessageL( CPushMessage* aPushMsg )
   189 void CMultiPartMixedContentHandler::HandleMessageL( CPushMessage* aPushMsg )
   192 	{
   190 	{
   193 	__ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone));
   191 	__ASSERT_DEBUG( aPushMsg != NULL, User::Panic(KErrPushMsgNull, KErrNone));
   204     iState = EDone;
   202     iState = EDone;
   205 	IdleComplete();
   203 	IdleComplete();
   206 #endif // __TEST_MULTIPART_MIX_SUPP
   204 #endif // __TEST_MULTIPART_MIX_SUPP
   207 	}
   205 	}
   208 
   206 
   209 /** 
   207 /**
   210  * Cancels Asynronous requests on called handler.
   208  * Cancels Asynronous requests on called handler.
   211  */
   209  */
   212 void CMultiPartMixedContentHandler::CancelHandleMessage()
   210 void CMultiPartMixedContentHandler::CancelHandleMessage()
   213 	{
   211 	{
   214     Cancel();
   212     Cancel();
   222 void CMultiPartMixedContentHandler::CPushHandlerBase_Reserved2()
   220 void CMultiPartMixedContentHandler::CPushHandlerBase_Reserved2()
   223 	{
   221 	{
   224 	User::Panic(KReserved, KErrNotSupported);
   222 	User::Panic(KReserved, KErrNotSupported);
   225 	}
   223 	}
   226 
   224 
   227 /** 
   225 /**
   228  * Cancels Asynronous requests on caller and completes self.
   226  * Cancels Asynronous requests on caller and completes self.
   229  */
   227  */
   230 void CMultiPartMixedContentHandler::DoCancel()
   228 void CMultiPartMixedContentHandler::DoCancel()
   231 	{
   229 	{
   232 	if ( iContentHandler )
   230 	if ( iContentHandler )
   234 		iContentHandler->CancelHandleMessage();
   232 		iContentHandler->CancelHandleMessage();
   235         }
   233         }
   236 	Complete( KErrCancel );
   234 	Complete( KErrCancel );
   237 	}
   235 	}
   238 
   236 
   239 /** 
   237 /**
   240  * State machine to step through the multipart message until it is done
   238  * State machine to step through the multipart message until it is done
   241  *
   239  *
   242  * State EHandlePart: Starts the processing of each part of the multipart
   240  * 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
   241  * 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
   242  * when there are no more parts, EDone will be the next state
   279 			break;
   277 			break;
   280             }
   278             }
   281 		}
   279 		}
   282 	}
   280 	}
   283 
   281 
   284 /** 
   282 /**
   285  * Clean up
   283  * Clean up
   286  */
   284  */
   287 TInt CMultiPartMixedContentHandler::RunError(TInt aError)
   285 TInt CMultiPartMixedContentHandler::RunError(TInt aError)
   288 	{
   286 	{
   289 	iState=EDone;
   287 	iState=EDone;