os/ossrv/lowlevellibsandfws/apputils/multipartparser/inc/multipartparser.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2005-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 // Implementation of the Multipart Parser
    15 //
    16 
    17 
    18 
    19 /**
    20  @file
    21  @publishedPartner
    22  @prototype
    23 */
    24 #ifndef MULTIPARTPARSER_H
    25 #define MULTIPARTPARSER_H
    26 
    27 #include <bafl/bodypart.h>
    28 
    29 class CBodyPart;
    30 
    31 /**
    32 Provides a RFC2045 MIME multipart parser and composer.  Each body part of a multipart
    33 message is represented by CBodyPart.
    34 */
    35 NONSHARABLE_CLASS(MultipartParser)
    36     {
    37     public:
    38 		/**
    39 		Controls which top level headers are used when composing a multipart message.
    40 		*/
    41         enum TMultipartTopLevelHeader
    42             {
    43 			/** Content-type: */
    44             EMultipartTopLevelHeaderContentType = 0x0001,
    45 			/** Content-length: */
    46             EMultipartTopLevelHeaderContentLength = 0x0002,
    47 			/** Last-modified: */
    48             EMultipartTopLevelHeaderLastModified = 0x0004,
    49 			/** All top level headers */
    50             EMultipartTopLevelHeaderAll = 0x0007	// make SURE to change this when adding new header types
    51             };
    52         
    53 		/**
    54 		Identifies the MIME multipart subtype
    55 		*/
    56         enum TMultipartSubtype
    57             {
    58 			/** multipart/mixed */
    59         	EMultipartSubtypeMixed = 0
    60             };
    61 
    62     public:
    63     
    64         /** 
    65 		Parse a multipart message
    66         @param aMultipartBody   The multipart file to be parsed
    67         @param aContentType     The content type of multipart file: mixed, related etc.
    68         @param aBoundary        The boundary of the multipart file
    69         @param aUrl             The url of the multipart file
    70         @param aBodyPartsArray  The array contains parsed body parts of the multipart file
    71         @param aMaxToParse      The max number of body parts to be parsed
    72 		@post aBodyPartsArray contains the parsed body parts
    73 		@leave KErrNotSupported aContentType is not multipart/mixed or multipart/related
    74 		@leave - One of the system-wide error codes
    75         */
    76         IMPORT_C static void ParseL( const TDesC8& aMultipartBody, 
    77                                      const TDesC8& aContentType,
    78                                      const TDesC8& aBoundary,
    79                                      const TDesC16& aUrl,
    80                                      RPointerArray <CBodyPart>& aBodyPartsArray,
    81                                      TInt aMaxToParse = -1 );
    82 
    83         /** 
    84 		Composes a multipart document
    85         @param aBodyArray      Array of BodyPart objects to be combined into a multipart message
    86         @param aBoundary       A string containing the boundary to be used in construction of multipart document
    87         @param aSubtype        Enumerated value of multipart subtype
    88         @param aHeaderMask     Integer mask of TTopLevelHeaders to indicate which top-level headers should be included
    89         @return multipart document; the ownership of buffer is transferred to caller.
    90 		@leave - One of the system-wide error codes
    91         */
    92         IMPORT_C static HBufC8* ComposeL( RPointerArray<CBodyPart>& aBodyPartsArray,
    93                                           const TDesC8& aBoundary,
    94                                           TMultipartSubtype aSubtype,
    95                                           TInt aHeaderMask );
    96                                  
    97     private:
    98 		/** Default constructor */
    99 		MultipartParser();
   100 
   101         /** 
   102 		Get the buffer of the next body part
   103         @param aStartPosition   The starting position to parse
   104         param aMultipartBody   The full buffer of multipart file
   105         @param aMultipartLen    The length of the multipart file buffer
   106         @param aBoundary        The boundary of the multipart file
   107         @param aSingleEolChar   The single EOL of the multipart file
   108         @param aBodyPartBuffer  The buffer of this body part
   109         @return Length of aBodyPartBuffer
   110         */
   111         static TUint32 GetNextBodyPartBuffer( TUint32 startPosition, 
   112                                        const TUint8* aMultipartBody,
   113                                        TUint32 aMultipartLen,
   114                                        const TDesC8& aBoundary,
   115                                        char* aSingleEolChar,
   116                                        TUint8** aBodyPartBuffer );
   117 
   118         /** 
   119 		Set the single and double EOL of the multipart file
   120         @param aMultipartBody   The full buffer of multipart file
   121         @param aMultipartLen    The length of the multipart file buffer
   122         @param aBoundary        The boundary of the multipart file
   123         @param aSingleEolChar   The single EOL of the multipart file
   124         @param aDoubleEolChar   The double EOL of the multipart file
   125         */
   126         static void SetEolCharacters( const TUint8* aMultipartBody,
   127                                TUint32 aMultipartLen,
   128                                const TDesC8& aBoundary,
   129                                char** aSingleEolChar,
   130                                char** aDoubleEolChar );
   131 
   132         /** 
   133 		Parse the body part
   134         @param aBodyPartBuffer        The buffer of this body part
   135         @param aBodyPartBufferLength  The length of this body part buffer
   136         @param aSingleEolChar         The single EOL of the multipart file
   137         @param aDoubleEolChar         The double EOL of the multipart file
   138         @param aResponseUrl           The url requested for the multipart file
   139         @param aBodyPart              The body part parsed and returned
   140 		@leave - One of the system-wide error codes
   141         */
   142         static void ParseBodyPartL( TUint8* aBodyPartBuffer,
   143                              TUint32 aBodyPartBufferLength,
   144                              char* aSingleEolChar,
   145                              char* aDoubleEolChar,
   146                              const TDesC16& aResponseUrl,
   147                              CBodyPart* aBodyPart );
   148 
   149         /** 
   150 		Checks if a Content-Transfer-Encoding is specified
   151         @param aContentTransferEncodingValue  The transfer encoding of this body part
   152         @return true if contentTransferEncodingValue is neither NULL nor a domain.
   153         */
   154         static TBool IsEncoded( TUint8* aContentTransferEncodingValue );
   155 
   156         /** 
   157 		Decode text given the Content-Transfer-Encoding
   158         @param aContentTransferEncodingValue  The transfer encoding of this body part
   159         @param aEncodedBody                   The encoded body of this body part
   160         @param aDecodedBody                   The decoded body returned
   161         @return KErrNone if successful, otherwise one of the system wide error codes.
   162         */
   163         static TInt DecodeContentTransferEncoding( TUint8* aContentTransferEncodingValue,
   164                                             const TDesC8& aEncodedBody,
   165                                             TPtr8& aDecodedBody );
   166 
   167         /** 
   168 		Checks if the Content-Encoding-Type is application/x-gzip
   169         @param aContentTypeValue  The content type of this body part
   170         @return ETrue if the Content-Encoding-Type is application/x-gzip.
   171         */
   172         static TBool IsZipped( TUint8* aContentTypeValue );
   173 
   174         /** 
   175 		Unzip the body
   176         @param aContentTypeValue     The content type of this body part
   177         @param aZippedBody           The zipped body of this body part
   178         @param aUnzippedBody         The unzipped body returned
   179         @return KErrNone if successful, otherwise one of the system wide error codes.
   180 		@pre aZippedBody has a Content-Encoding-Type of application/x-gzip
   181 		@pre aContentTypeValue is application/x-gzip
   182         */
   183         static TInt Unzip( TUint8* aContentType,
   184                            const TDesC8& aZippedBody,
   185                            TPtr8& aUnzippedBody );
   186 
   187         /** 
   188 		Remove the charset value from the Content-Type header
   189         @param aBodyPart              The body part which contains the content type
   190         */
   191         static void CutOffContentTypeAttributes( CBodyPart* aBodyPart );
   192 
   193         /** 
   194 		Forms a URL that refers to this body part
   195         @param aContentBaseValue      The content base of this body part
   196         @param aContentLocationValue  The content location of this body part
   197         @param aResponseUrl           The url requested for the multipart file
   198         @return URL
   199 		@leave - One of the system-wide error codes
   200         */
   201         static HBufC16* GetBodyPartUrlL( const TDesC8& aContentBaseValue,
   202                                  const TDesC8& aContentLocationValue,
   203                                  const TDesC16& aResponseUrl );
   204 
   205         /** 
   206 		Checks whether a URL is relative or not
   207         @param aUrl The URL to check 
   208         @return ETrue if the URL is relative
   209 		@leave - One of the system-wide error codes
   210         */
   211         static TBool IsUrlRelativeL( const TDesC8& aUrl );
   212 
   213         /** 
   214 		Create an absolute URL from a relative URL
   215         @param aBase         The base URL
   216         @param aRelativeUrl  The relative URL
   217         @return absolute URL
   218 		@leave - One of the system-wide error codes
   219         */
   220         static HBufC16* UrlRelToAbsL( TDesC16& aBase, 
   221                                       const TDesC8& aRelativeUrl );
   222 
   223         /** 
   224 		Composes multipart/mixed document
   225         @param aBodyArray      Array of CBodyPart objects to be included in the output
   226         @param aBoundary       A string containing boundary to be used in construction of multipart document
   227         @param aHeaderMask     Integer mask of TMultipartTopLevelHeader to indicate which top-level headers should be included
   228         @return multipart document; the ownership of buffer is transferred to caller.
   229 		@leave - One of the system-wide error codes
   230         */
   231         static HBufC8* ComposeMixedL( RPointerArray<CBodyPart>& aBodyArray,
   232                                       const TDesC8& aBoundary,
   233                                       TInt aHeaderMask );
   234                                           
   235     };
   236 
   237 #endif      // MULTIPARTPARSER_H   
   238