1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/multipartparser/inc/multipartparser.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,238 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Implementation of the Multipart Parser
1.18 +//
1.19 +
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @publishedPartner
1.25 + @prototype
1.26 +*/
1.27 +#ifndef MULTIPARTPARSER_H
1.28 +#define MULTIPARTPARSER_H
1.29 +
1.30 +#include <bafl/bodypart.h>
1.31 +
1.32 +class CBodyPart;
1.33 +
1.34 +/**
1.35 +Provides a RFC2045 MIME multipart parser and composer. Each body part of a multipart
1.36 +message is represented by CBodyPart.
1.37 +*/
1.38 +NONSHARABLE_CLASS(MultipartParser)
1.39 + {
1.40 + public:
1.41 + /**
1.42 + Controls which top level headers are used when composing a multipart message.
1.43 + */
1.44 + enum TMultipartTopLevelHeader
1.45 + {
1.46 + /** Content-type: */
1.47 + EMultipartTopLevelHeaderContentType = 0x0001,
1.48 + /** Content-length: */
1.49 + EMultipartTopLevelHeaderContentLength = 0x0002,
1.50 + /** Last-modified: */
1.51 + EMultipartTopLevelHeaderLastModified = 0x0004,
1.52 + /** All top level headers */
1.53 + EMultipartTopLevelHeaderAll = 0x0007 // make SURE to change this when adding new header types
1.54 + };
1.55 +
1.56 + /**
1.57 + Identifies the MIME multipart subtype
1.58 + */
1.59 + enum TMultipartSubtype
1.60 + {
1.61 + /** multipart/mixed */
1.62 + EMultipartSubtypeMixed = 0
1.63 + };
1.64 +
1.65 + public:
1.66 +
1.67 + /**
1.68 + Parse a multipart message
1.69 + @param aMultipartBody The multipart file to be parsed
1.70 + @param aContentType The content type of multipart file: mixed, related etc.
1.71 + @param aBoundary The boundary of the multipart file
1.72 + @param aUrl The url of the multipart file
1.73 + @param aBodyPartsArray The array contains parsed body parts of the multipart file
1.74 + @param aMaxToParse The max number of body parts to be parsed
1.75 + @post aBodyPartsArray contains the parsed body parts
1.76 + @leave KErrNotSupported aContentType is not multipart/mixed or multipart/related
1.77 + @leave - One of the system-wide error codes
1.78 + */
1.79 + IMPORT_C static void ParseL( const TDesC8& aMultipartBody,
1.80 + const TDesC8& aContentType,
1.81 + const TDesC8& aBoundary,
1.82 + const TDesC16& aUrl,
1.83 + RPointerArray <CBodyPart>& aBodyPartsArray,
1.84 + TInt aMaxToParse = -1 );
1.85 +
1.86 + /**
1.87 + Composes a multipart document
1.88 + @param aBodyArray Array of BodyPart objects to be combined into a multipart message
1.89 + @param aBoundary A string containing the boundary to be used in construction of multipart document
1.90 + @param aSubtype Enumerated value of multipart subtype
1.91 + @param aHeaderMask Integer mask of TTopLevelHeaders to indicate which top-level headers should be included
1.92 + @return multipart document; the ownership of buffer is transferred to caller.
1.93 + @leave - One of the system-wide error codes
1.94 + */
1.95 + IMPORT_C static HBufC8* ComposeL( RPointerArray<CBodyPart>& aBodyPartsArray,
1.96 + const TDesC8& aBoundary,
1.97 + TMultipartSubtype aSubtype,
1.98 + TInt aHeaderMask );
1.99 +
1.100 + private:
1.101 + /** Default constructor */
1.102 + MultipartParser();
1.103 +
1.104 + /**
1.105 + Get the buffer of the next body part
1.106 + @param aStartPosition The starting position to parse
1.107 + param aMultipartBody The full buffer of multipart file
1.108 + @param aMultipartLen The length of the multipart file buffer
1.109 + @param aBoundary The boundary of the multipart file
1.110 + @param aSingleEolChar The single EOL of the multipart file
1.111 + @param aBodyPartBuffer The buffer of this body part
1.112 + @return Length of aBodyPartBuffer
1.113 + */
1.114 + static TUint32 GetNextBodyPartBuffer( TUint32 startPosition,
1.115 + const TUint8* aMultipartBody,
1.116 + TUint32 aMultipartLen,
1.117 + const TDesC8& aBoundary,
1.118 + char* aSingleEolChar,
1.119 + TUint8** aBodyPartBuffer );
1.120 +
1.121 + /**
1.122 + Set the single and double EOL of the multipart file
1.123 + @param aMultipartBody The full buffer of multipart file
1.124 + @param aMultipartLen The length of the multipart file buffer
1.125 + @param aBoundary The boundary of the multipart file
1.126 + @param aSingleEolChar The single EOL of the multipart file
1.127 + @param aDoubleEolChar The double EOL of the multipart file
1.128 + */
1.129 + static void SetEolCharacters( const TUint8* aMultipartBody,
1.130 + TUint32 aMultipartLen,
1.131 + const TDesC8& aBoundary,
1.132 + char** aSingleEolChar,
1.133 + char** aDoubleEolChar );
1.134 +
1.135 + /**
1.136 + Parse the body part
1.137 + @param aBodyPartBuffer The buffer of this body part
1.138 + @param aBodyPartBufferLength The length of this body part buffer
1.139 + @param aSingleEolChar The single EOL of the multipart file
1.140 + @param aDoubleEolChar The double EOL of the multipart file
1.141 + @param aResponseUrl The url requested for the multipart file
1.142 + @param aBodyPart The body part parsed and returned
1.143 + @leave - One of the system-wide error codes
1.144 + */
1.145 + static void ParseBodyPartL( TUint8* aBodyPartBuffer,
1.146 + TUint32 aBodyPartBufferLength,
1.147 + char* aSingleEolChar,
1.148 + char* aDoubleEolChar,
1.149 + const TDesC16& aResponseUrl,
1.150 + CBodyPart* aBodyPart );
1.151 +
1.152 + /**
1.153 + Checks if a Content-Transfer-Encoding is specified
1.154 + @param aContentTransferEncodingValue The transfer encoding of this body part
1.155 + @return true if contentTransferEncodingValue is neither NULL nor a domain.
1.156 + */
1.157 + static TBool IsEncoded( TUint8* aContentTransferEncodingValue );
1.158 +
1.159 + /**
1.160 + Decode text given the Content-Transfer-Encoding
1.161 + @param aContentTransferEncodingValue The transfer encoding of this body part
1.162 + @param aEncodedBody The encoded body of this body part
1.163 + @param aDecodedBody The decoded body returned
1.164 + @return KErrNone if successful, otherwise one of the system wide error codes.
1.165 + */
1.166 + static TInt DecodeContentTransferEncoding( TUint8* aContentTransferEncodingValue,
1.167 + const TDesC8& aEncodedBody,
1.168 + TPtr8& aDecodedBody );
1.169 +
1.170 + /**
1.171 + Checks if the Content-Encoding-Type is application/x-gzip
1.172 + @param aContentTypeValue The content type of this body part
1.173 + @return ETrue if the Content-Encoding-Type is application/x-gzip.
1.174 + */
1.175 + static TBool IsZipped( TUint8* aContentTypeValue );
1.176 +
1.177 + /**
1.178 + Unzip the body
1.179 + @param aContentTypeValue The content type of this body part
1.180 + @param aZippedBody The zipped body of this body part
1.181 + @param aUnzippedBody The unzipped body returned
1.182 + @return KErrNone if successful, otherwise one of the system wide error codes.
1.183 + @pre aZippedBody has a Content-Encoding-Type of application/x-gzip
1.184 + @pre aContentTypeValue is application/x-gzip
1.185 + */
1.186 + static TInt Unzip( TUint8* aContentType,
1.187 + const TDesC8& aZippedBody,
1.188 + TPtr8& aUnzippedBody );
1.189 +
1.190 + /**
1.191 + Remove the charset value from the Content-Type header
1.192 + @param aBodyPart The body part which contains the content type
1.193 + */
1.194 + static void CutOffContentTypeAttributes( CBodyPart* aBodyPart );
1.195 +
1.196 + /**
1.197 + Forms a URL that refers to this body part
1.198 + @param aContentBaseValue The content base of this body part
1.199 + @param aContentLocationValue The content location of this body part
1.200 + @param aResponseUrl The url requested for the multipart file
1.201 + @return URL
1.202 + @leave - One of the system-wide error codes
1.203 + */
1.204 + static HBufC16* GetBodyPartUrlL( const TDesC8& aContentBaseValue,
1.205 + const TDesC8& aContentLocationValue,
1.206 + const TDesC16& aResponseUrl );
1.207 +
1.208 + /**
1.209 + Checks whether a URL is relative or not
1.210 + @param aUrl The URL to check
1.211 + @return ETrue if the URL is relative
1.212 + @leave - One of the system-wide error codes
1.213 + */
1.214 + static TBool IsUrlRelativeL( const TDesC8& aUrl );
1.215 +
1.216 + /**
1.217 + Create an absolute URL from a relative URL
1.218 + @param aBase The base URL
1.219 + @param aRelativeUrl The relative URL
1.220 + @return absolute URL
1.221 + @leave - One of the system-wide error codes
1.222 + */
1.223 + static HBufC16* UrlRelToAbsL( TDesC16& aBase,
1.224 + const TDesC8& aRelativeUrl );
1.225 +
1.226 + /**
1.227 + Composes multipart/mixed document
1.228 + @param aBodyArray Array of CBodyPart objects to be included in the output
1.229 + @param aBoundary A string containing boundary to be used in construction of multipart document
1.230 + @param aHeaderMask Integer mask of TMultipartTopLevelHeader to indicate which top-level headers should be included
1.231 + @return multipart document; the ownership of buffer is transferred to caller.
1.232 + @leave - One of the system-wide error codes
1.233 + */
1.234 + static HBufC8* ComposeMixedL( RPointerArray<CBodyPart>& aBodyArray,
1.235 + const TDesC8& aBoundary,
1.236 + TInt aHeaderMask );
1.237 +
1.238 + };
1.239 +
1.240 +#endif // MULTIPARTPARSER_H
1.241 +