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