Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Implementation of the Multipart Parser
24 #ifndef MULTIPARTPARSER_H
25 #define MULTIPARTPARSER_H
27 #include <bafl/bodypart.h>
32 Provides a RFC2045 MIME multipart parser and composer. Each body part of a multipart
33 message is represented by CBodyPart.
35 NONSHARABLE_CLASS(MultipartParser)
39 Controls which top level headers are used when composing a multipart message.
41 enum TMultipartTopLevelHeader
44 EMultipartTopLevelHeaderContentType = 0x0001,
45 /** Content-length: */
46 EMultipartTopLevelHeaderContentLength = 0x0002,
48 EMultipartTopLevelHeaderLastModified = 0x0004,
49 /** All top level headers */
50 EMultipartTopLevelHeaderAll = 0x0007 // make SURE to change this when adding new header types
54 Identifies the MIME multipart subtype
56 enum TMultipartSubtype
58 /** multipart/mixed */
59 EMultipartSubtypeMixed = 0
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
76 IMPORT_C static void ParseL( const TDesC8& aMultipartBody,
77 const TDesC8& aContentType,
78 const TDesC8& aBoundary,
80 RPointerArray <CBodyPart>& aBodyPartsArray,
81 TInt aMaxToParse = -1 );
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
92 IMPORT_C static HBufC8* ComposeL( RPointerArray<CBodyPart>& aBodyPartsArray,
93 const TDesC8& aBoundary,
94 TMultipartSubtype aSubtype,
98 /** Default constructor */
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
111 static TUint32 GetNextBodyPartBuffer( TUint32 startPosition,
112 const TUint8* aMultipartBody,
113 TUint32 aMultipartLen,
114 const TDesC8& aBoundary,
115 char* aSingleEolChar,
116 TUint8** aBodyPartBuffer );
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
126 static void SetEolCharacters( const TUint8* aMultipartBody,
127 TUint32 aMultipartLen,
128 const TDesC8& aBoundary,
129 char** aSingleEolChar,
130 char** aDoubleEolChar );
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
142 static void ParseBodyPartL( TUint8* aBodyPartBuffer,
143 TUint32 aBodyPartBufferLength,
144 char* aSingleEolChar,
145 char* aDoubleEolChar,
146 const TDesC16& aResponseUrl,
147 CBodyPart* aBodyPart );
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.
154 static TBool IsEncoded( TUint8* aContentTransferEncodingValue );
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.
163 static TInt DecodeContentTransferEncoding( TUint8* aContentTransferEncodingValue,
164 const TDesC8& aEncodedBody,
165 TPtr8& aDecodedBody );
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.
172 static TBool IsZipped( TUint8* aContentTypeValue );
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
183 static TInt Unzip( TUint8* aContentType,
184 const TDesC8& aZippedBody,
185 TPtr8& aUnzippedBody );
188 Remove the charset value from the Content-Type header
189 @param aBodyPart The body part which contains the content type
191 static void CutOffContentTypeAttributes( CBodyPart* aBodyPart );
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
199 @leave - One of the system-wide error codes
201 static HBufC16* GetBodyPartUrlL( const TDesC8& aContentBaseValue,
202 const TDesC8& aContentLocationValue,
203 const TDesC16& aResponseUrl );
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
211 static TBool IsUrlRelativeL( const TDesC8& aUrl );
214 Create an absolute URL from a relative URL
215 @param aBase The base URL
216 @param aRelativeUrl The relative URL
218 @leave - One of the system-wide error codes
220 static HBufC16* UrlRelToAbsL( TDesC16& aBase,
221 const TDesC8& aRelativeUrl );
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
231 static HBufC8* ComposeMixedL( RPointerArray<CBodyPart>& aBodyArray,
232 const TDesC8& aBoundary,
237 #endif // MULTIPARTPARSER_H