sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Implementation of the Multipart Parser sl@0: // sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @publishedPartner sl@0: @prototype sl@0: */ sl@0: #ifndef MULTIPARTPARSER_H sl@0: #define MULTIPARTPARSER_H sl@0: sl@0: #include sl@0: sl@0: class CBodyPart; sl@0: sl@0: /** sl@0: Provides a RFC2045 MIME multipart parser and composer. Each body part of a multipart sl@0: message is represented by CBodyPart. sl@0: */ sl@0: NONSHARABLE_CLASS(MultipartParser) sl@0: { sl@0: public: sl@0: /** sl@0: Controls which top level headers are used when composing a multipart message. sl@0: */ sl@0: enum TMultipartTopLevelHeader sl@0: { sl@0: /** Content-type: */ sl@0: EMultipartTopLevelHeaderContentType = 0x0001, sl@0: /** Content-length: */ sl@0: EMultipartTopLevelHeaderContentLength = 0x0002, sl@0: /** Last-modified: */ sl@0: EMultipartTopLevelHeaderLastModified = 0x0004, sl@0: /** All top level headers */ sl@0: EMultipartTopLevelHeaderAll = 0x0007 // make SURE to change this when adding new header types sl@0: }; sl@0: sl@0: /** sl@0: Identifies the MIME multipart subtype sl@0: */ sl@0: enum TMultipartSubtype sl@0: { sl@0: /** multipart/mixed */ sl@0: EMultipartSubtypeMixed = 0 sl@0: }; sl@0: sl@0: public: sl@0: sl@0: /** sl@0: Parse a multipart message sl@0: @param aMultipartBody The multipart file to be parsed sl@0: @param aContentType The content type of multipart file: mixed, related etc. sl@0: @param aBoundary The boundary of the multipart file sl@0: @param aUrl The url of the multipart file sl@0: @param aBodyPartsArray The array contains parsed body parts of the multipart file sl@0: @param aMaxToParse The max number of body parts to be parsed sl@0: @post aBodyPartsArray contains the parsed body parts sl@0: @leave KErrNotSupported aContentType is not multipart/mixed or multipart/related sl@0: @leave - One of the system-wide error codes sl@0: */ sl@0: IMPORT_C static void ParseL( const TDesC8& aMultipartBody, sl@0: const TDesC8& aContentType, sl@0: const TDesC8& aBoundary, sl@0: const TDesC16& aUrl, sl@0: RPointerArray & aBodyPartsArray, sl@0: TInt aMaxToParse = -1 ); sl@0: sl@0: /** sl@0: Composes a multipart document sl@0: @param aBodyArray Array of BodyPart objects to be combined into a multipart message sl@0: @param aBoundary A string containing the boundary to be used in construction of multipart document sl@0: @param aSubtype Enumerated value of multipart subtype sl@0: @param aHeaderMask Integer mask of TTopLevelHeaders to indicate which top-level headers should be included sl@0: @return multipart document; the ownership of buffer is transferred to caller. sl@0: @leave - One of the system-wide error codes sl@0: */ sl@0: IMPORT_C static HBufC8* ComposeL( RPointerArray& aBodyPartsArray, sl@0: const TDesC8& aBoundary, sl@0: TMultipartSubtype aSubtype, sl@0: TInt aHeaderMask ); sl@0: sl@0: private: sl@0: /** Default constructor */ sl@0: MultipartParser(); sl@0: sl@0: /** sl@0: Get the buffer of the next body part sl@0: @param aStartPosition The starting position to parse sl@0: param aMultipartBody The full buffer of multipart file sl@0: @param aMultipartLen The length of the multipart file buffer sl@0: @param aBoundary The boundary of the multipart file sl@0: @param aSingleEolChar The single EOL of the multipart file sl@0: @param aBodyPartBuffer The buffer of this body part sl@0: @return Length of aBodyPartBuffer sl@0: */ sl@0: static TUint32 GetNextBodyPartBuffer( TUint32 startPosition, sl@0: const TUint8* aMultipartBody, sl@0: TUint32 aMultipartLen, sl@0: const TDesC8& aBoundary, sl@0: char* aSingleEolChar, sl@0: TUint8** aBodyPartBuffer ); sl@0: sl@0: /** sl@0: Set the single and double EOL of the multipart file sl@0: @param aMultipartBody The full buffer of multipart file sl@0: @param aMultipartLen The length of the multipart file buffer sl@0: @param aBoundary The boundary of the multipart file sl@0: @param aSingleEolChar The single EOL of the multipart file sl@0: @param aDoubleEolChar The double EOL of the multipart file sl@0: */ sl@0: static void SetEolCharacters( const TUint8* aMultipartBody, sl@0: TUint32 aMultipartLen, sl@0: const TDesC8& aBoundary, sl@0: char** aSingleEolChar, sl@0: char** aDoubleEolChar ); sl@0: sl@0: /** sl@0: Parse the body part sl@0: @param aBodyPartBuffer The buffer of this body part sl@0: @param aBodyPartBufferLength The length of this body part buffer sl@0: @param aSingleEolChar The single EOL of the multipart file sl@0: @param aDoubleEolChar The double EOL of the multipart file sl@0: @param aResponseUrl The url requested for the multipart file sl@0: @param aBodyPart The body part parsed and returned sl@0: @leave - One of the system-wide error codes sl@0: */ sl@0: static void ParseBodyPartL( TUint8* aBodyPartBuffer, sl@0: TUint32 aBodyPartBufferLength, sl@0: char* aSingleEolChar, sl@0: char* aDoubleEolChar, sl@0: const TDesC16& aResponseUrl, sl@0: CBodyPart* aBodyPart ); sl@0: sl@0: /** sl@0: Checks if a Content-Transfer-Encoding is specified sl@0: @param aContentTransferEncodingValue The transfer encoding of this body part sl@0: @return true if contentTransferEncodingValue is neither NULL nor a domain. sl@0: */ sl@0: static TBool IsEncoded( TUint8* aContentTransferEncodingValue ); sl@0: sl@0: /** sl@0: Decode text given the Content-Transfer-Encoding sl@0: @param aContentTransferEncodingValue The transfer encoding of this body part sl@0: @param aEncodedBody The encoded body of this body part sl@0: @param aDecodedBody The decoded body returned sl@0: @return KErrNone if successful, otherwise one of the system wide error codes. sl@0: */ sl@0: static TInt DecodeContentTransferEncoding( TUint8* aContentTransferEncodingValue, sl@0: const TDesC8& aEncodedBody, sl@0: TPtr8& aDecodedBody ); sl@0: sl@0: /** sl@0: Checks if the Content-Encoding-Type is application/x-gzip sl@0: @param aContentTypeValue The content type of this body part sl@0: @return ETrue if the Content-Encoding-Type is application/x-gzip. sl@0: */ sl@0: static TBool IsZipped( TUint8* aContentTypeValue ); sl@0: sl@0: /** sl@0: Unzip the body sl@0: @param aContentTypeValue The content type of this body part sl@0: @param aZippedBody The zipped body of this body part sl@0: @param aUnzippedBody The unzipped body returned sl@0: @return KErrNone if successful, otherwise one of the system wide error codes. sl@0: @pre aZippedBody has a Content-Encoding-Type of application/x-gzip sl@0: @pre aContentTypeValue is application/x-gzip sl@0: */ sl@0: static TInt Unzip( TUint8* aContentType, sl@0: const TDesC8& aZippedBody, sl@0: TPtr8& aUnzippedBody ); sl@0: sl@0: /** sl@0: Remove the charset value from the Content-Type header sl@0: @param aBodyPart The body part which contains the content type sl@0: */ sl@0: static void CutOffContentTypeAttributes( CBodyPart* aBodyPart ); sl@0: sl@0: /** sl@0: Forms a URL that refers to this body part sl@0: @param aContentBaseValue The content base of this body part sl@0: @param aContentLocationValue The content location of this body part sl@0: @param aResponseUrl The url requested for the multipart file sl@0: @return URL sl@0: @leave - One of the system-wide error codes sl@0: */ sl@0: static HBufC16* GetBodyPartUrlL( const TDesC8& aContentBaseValue, sl@0: const TDesC8& aContentLocationValue, sl@0: const TDesC16& aResponseUrl ); sl@0: sl@0: /** sl@0: Checks whether a URL is relative or not sl@0: @param aUrl The URL to check sl@0: @return ETrue if the URL is relative sl@0: @leave - One of the system-wide error codes sl@0: */ sl@0: static TBool IsUrlRelativeL( const TDesC8& aUrl ); sl@0: sl@0: /** sl@0: Create an absolute URL from a relative URL sl@0: @param aBase The base URL sl@0: @param aRelativeUrl The relative URL sl@0: @return absolute URL sl@0: @leave - One of the system-wide error codes sl@0: */ sl@0: static HBufC16* UrlRelToAbsL( TDesC16& aBase, sl@0: const TDesC8& aRelativeUrl ); sl@0: sl@0: /** sl@0: Composes multipart/mixed document sl@0: @param aBodyArray Array of CBodyPart objects to be included in the output sl@0: @param aBoundary A string containing boundary to be used in construction of multipart document sl@0: @param aHeaderMask Integer mask of TMultipartTopLevelHeader to indicate which top-level headers should be included sl@0: @return multipart document; the ownership of buffer is transferred to caller. sl@0: @leave - One of the system-wide error codes sl@0: */ sl@0: static HBufC8* ComposeMixedL( RPointerArray& aBodyArray, sl@0: const TDesC8& aBoundary, sl@0: TInt aHeaderMask ); sl@0: sl@0: }; sl@0: sl@0: #endif // MULTIPARTPARSER_H sl@0: