|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Preparation XOP message for HTTP transmission in case |
|
15 * of request and extracting BLOBs from XOP message responsed |
|
16 * through HTTP channel in case of response |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 #ifndef SEN_MultiPart_UTILS_H |
|
28 #define SEN_MultiPart_UTILS_H |
|
29 |
|
30 #include <e32math.h> |
|
31 #include <SenSoapEnvelope2.h> |
|
32 #include "senatomentry.h" |
|
33 #include <RSenDocument.h> |
|
34 |
|
35 #include <xmlengserializer.h> |
|
36 #include <xmlengchunkcontainer.h> |
|
37 #include <xmlengfilecontainer.h> |
|
38 #include <xmlengbinarycontainer.h> |
|
39 #include <xmlengnodelist.h> |
|
40 |
|
41 // CONSTANTS |
|
42 _LIT(KMultiPartNoRequestMessagePanicText, "NULL MultiPart request message"); |
|
43 _LIT(KMultiPartNoBlobsPanicText, "NULL MultiPart BLOB part"); |
|
44 _LIT(KMultiPartNoContentTypeInBlobHeaderPanicText, "NULL MultiPart ContentType in BLOB header"); |
|
45 _LIT(KMultiPartNoCidPanicText, "NULL MultiPart Cid"); |
|
46 _LIT(KMultiPartSoapVersionInvalidPanicText, "MultiPart SOAP version unknown"); |
|
47 _LIT(KMultiPartBlobContainerTypeInvalidPanicText, "MultiPart BLOB container type unknown"); |
|
48 _LIT(KMultiPartResponseBodyInvalidPanicText, "MultiPart response body doesn't conform XOP rules"); |
|
49 _LIT(KMultiPartCidInvalidPanicText, "MultiPart Cid doesn't conform XOP rules"); |
|
50 |
|
51 _LIT(KMultiPartPanicText, "MultiPart panic"); |
|
52 |
|
53 |
|
54 |
|
55 /** numbers 11 or 12 at the end of constant names mean SOAP versions (1.1 or 1.2) */ |
|
56 _LIT8(KMultiPartHeaderRootStart11, "Content-Type: application/xop+xml;charset=UTF-8;type=\"text/xml\"\r\nContent-Transfer-Encoding: 8bit\r\nContent-ID: <"); |
|
57 _LIT8(KMultiPartHeaderRootStart12, "Content-Type: application/xop+xml;charset=UTF-8;type=\"application/soap+xml\"\r\nContent-Transfer-Encoding: binary\r\nContent-ID: <"); |
|
58 _LIT8(KMultiPartAtomHeaderRootStart, "Content-Type: application/atom+xml;charset=UTF-8;type=\"text/xml\"\r\nContent-Transfer-Encoding: 8bit\r\nContent-ID: <"); |
|
59 _LIT8(KMultiPartHeaderRootEnd, ">\r\n\r\n"); |
|
60 |
|
61 _LIT8(KMultiPartContentTypeName, "contentType"); |
|
62 _LIT8(KMultiPartDefaultBinaryContentTypeValue, "application/octet-stream)");// video/mp4 or video/x-flv |
|
63 _LIT8(KMultiPartHeaderBinaryDataContentType, "Content-Type: "); |
|
64 _LIT8(KMultiPartHeaderBinaryDataContentID, "\r\nContent-Transfer-Encoding: binary\r\nContent-ID: <"); |
|
65 _LIT8(KMultiPartHeaderBinaryDataEnd, ">\r\n\r\n"); |
|
66 |
|
67 const TUint KTenKBytes = 10240; |
|
68 _LIT8(KNewLine, "\r\n"); |
|
69 _LIT8(KDush, "--"); |
|
70 |
|
71 /** the common part of file name where will be stored Blobs from Response */ |
|
72 _LIT(KFileName, "c:\\SenBlobResponses\\SenBlobResponse"); |
|
73 |
|
74 /** |
|
75 * Prepares XOP message with binary data to transmit it through HTTP Channel |
|
76 * and extracts BLOBs from XOP message responsed through HTTP channel |
|
77 * |
|
78 * @lib |
|
79 * @since S60 v3.2 |
|
80 */ |
|
81 class SenMultiPartUtils |
|
82 { |
|
83 public: |
|
84 |
|
85 /** |
|
86 * different cases of panics |
|
87 */ |
|
88 enum TMultiPartPanics |
|
89 { |
|
90 EMultiPartNoRequestMessage, |
|
91 EMultiPartNoBlobs, |
|
92 EMultiPartNoContentTypeInBlobHeader, |
|
93 EMultiPartNoCid, |
|
94 EMultiPartSoapVersionInvalid, |
|
95 EMultiPartBlobContainerTypeInvalid, |
|
96 EMultiPartResponseBodyInvalid, |
|
97 EMultiPartCidInvalid |
|
98 }; |
|
99 |
|
100 /** |
|
101 * ContentType for MultiPart consists of |
|
102 * FiledName = "Content-Type" FiledValue = "Multipart/Related" |
|
103 * ParamName1 = "boundary" ParamValue1 = BoundaryValue |
|
104 * ParamName2 = "type" ParamValue1 = TypeValue |
|
105 * ParamName1 = "start" ParamValue1 = StartValue |
|
106 * ParamName1 = "start-info" ParamValue1 = StartInfoValue |
|
107 * ParamName1 = "action" ParamValue1 = ActionValue |
|
108 * This structure describes ParamName & ParamValue of ConetentType |
|
109 */ |
|
110 struct TMultiPartContentTypeParam |
|
111 { |
|
112 TPtrC8 paramName; |
|
113 TPtrC8 paramValue; |
|
114 }; |
|
115 |
|
116 /** |
|
117 * This structure describes FieldValue & Params of ContentType |
|
118 */ |
|
119 struct TMultiPartContentType |
|
120 { |
|
121 TPtrC8 fieldValue; |
|
122 RArray<TMultiPartContentTypeParam> params; |
|
123 }; |
|
124 |
|
125 public: |
|
126 |
|
127 /** |
|
128 * Serializes SenMessage message in MultiPart message |
|
129 * @since S60 v5.0 |
|
130 * @param aMessage The message with multiparts (usual view of message) |
|
131 * @param aMultiPartMessage The message serialized from usual view to MultiPart message |
|
132 * @param aType mode of serialization (see xmlengserializer.h) |
|
133 */ |
|
134 IMPORT_C static void SerializeMessageL(CSenFragmentBase& aMessage, |
|
135 RBuf8& aMultiPartMessage, |
|
136 TXmlEngSerializerType aType = ESerializerXOPInfoset); |
|
137 |
|
138 /** |
|
139 * Generates random content-ID for header of XOP message and for headers of BLOBs |
|
140 * as randomNumber@homeTime |
|
141 * @since S60 v3.2 |
|
142 * @param aRootCid Generated content-ID |
|
143 */ |
|
144 IMPORT_C static void GenerateRandomRootCidL(RBuf8& aRootCid); |
|
145 |
|
146 /** |
|
147 * Generates random boundary for mime header as randomNumber |
|
148 * @since S60 v3.2 |
|
149 * @param aBoundary Generated random boundary |
|
150 */ |
|
151 IMPORT_C static void GenerateRandomBoundaryL(RBuf8& aBoundary); |
|
152 |
|
153 /** |
|
154 * Generates MimeBoundary to separate mime parts of the message as --randomNumber |
|
155 * @since S60 v3.2 |
|
156 * @param aBoundary random boundary |
|
157 * @param aBoundaryStart Generated MIME boundary |
|
158 */ |
|
159 IMPORT_C static void BoundaryLineStartL(const RBuf8& aBoundary, RBuf8& aBoundaryStart); |
|
160 |
|
161 /** |
|
162 * Generates MimeBoundaryEnd to end multipart message (MultiPart) as --randomNumber-- |
|
163 * @since S60 v3.2 |
|
164 * @param aBoundary random boundary |
|
165 * @param aBoundaryEnd Generated MIME boundary end |
|
166 */ |
|
167 IMPORT_C static void BoundaryLineEndL(const RBuf8& aBoundary, RBuf8& aBoundaryEnd); |
|
168 |
|
169 /** |
|
170 * Creates Header for Root of XOP message or other multiPart message |
|
171 * The header sould be the next: |
|
172 * |
|
173 * --MIME_boundary |
|
174 * Content-Type: application/xop+xml; |
|
175 * charset=UTF-8; |
|
176 * type="text/xml" (for SOAP 1.1) or "application/soap+xml" (for SOAP 1.2) |
|
177 * Content-Transfer-Encoding: 8bit |
|
178 * Content-ID: <randomNumber@homeTime> |
|
179 * |
|
180 * where "Content-ID" is the same as "start" in Header of Outer Package |
|
181 * |
|
182 * @since S60 v3.2 |
|
183 * @param aMessage The message with multiparts |
|
184 * @param aRootCid The content ID for the header of XOP or other multiPart message |
|
185 * @param aHeaderRoot11 Header of root of XOP message or other multiPart message |
|
186 */ |
|
187 IMPORT_C static void HeaderRootL(MSenMessage* aMessage, |
|
188 const RBuf8& aRootCid, RBuf8& aHeaderRoot); |
|
189 |
|
190 /** |
|
191 * Creates Header for Binary Data[aIndex] of XOP message |
|
192 * The header sould be the next: |
|
193 * |
|
194 * --MIME_boundary |
|
195 * Content-Type: image/png |
|
196 * Content-Transfer-Encoding: binary |
|
197 * Content-ID: <randomNumber@homeTime> |
|
198 * |
|
199 * @since S60 v3.2 |
|
200 * @param aIndex Which BLOB from array of TXmlEngDataContainer is processed, starts from 0 |
|
201 * @param aBinaryDataList The list of BLOBs |
|
202 * @param aHeaderBinaryData Header of binary data[aIndex] |
|
203 */ |
|
204 IMPORT_C static void HeaderBinaryDataL(TUint aIndex, |
|
205 RArray<TXmlEngDataContainer>& aBinaryDataList, |
|
206 RBuf8& aHeaderBinaryData); |
|
207 |
|
208 /** |
|
209 * Extracts a part of BLOB (10KB) from a file |
|
210 * @since S60 v3.2 |
|
211 * @param aPart Which part of BLOB should be extracted |
|
212 * @param aIndex Which BLOB from array of TXmlEngDataContainer is processed, starts from 0 |
|
213 * @param aBinaryDataList The list of BLOBs |
|
214 * @param aBinaryData Part of BLOB that was extracted from a file |
|
215 */ |
|
216 IMPORT_C static void FileDataPartL(TUint aPart, TUint aIndex, |
|
217 RArray<TXmlEngDataContainer>& aBinaryDataList, |
|
218 RBuf8& aBinaryData); |
|
219 |
|
220 /** |
|
221 * Extracts the rest of BLOB (less than 10KB) from a file |
|
222 * @since S60 v3.2 |
|
223 * @param aParts How many parts of BLOB has already been extracted from a file |
|
224 * @param aRest How many bytes should be exracted from a file |
|
225 * @param aIndex Which BLOB from array of TXmlEngDataContainer is processed, starts from 0 |
|
226 * @param aBinaryDataList The list of BLOBs |
|
227 * @param aBinaryData The last part of BLOB that was extracted from a file |
|
228 */ |
|
229 IMPORT_C static void FileDataRestL(TUint aParts, TUint aRest, TUint aIndex, |
|
230 RArray<TXmlEngDataContainer>& aBinaryDataList, |
|
231 RBuf8& aBinaryData); |
|
232 |
|
233 /** |
|
234 * Extracts CIDs of BLOBs from response MultiPart message |
|
235 * @since S60 v3.2 |
|
236 * @param aBlobHeader Header of Blob from that should be extracted CID of BLOB |
|
237 * @param aCids Array of CIDs for all BLOBs |
|
238 */ |
|
239 IMPORT_C static void CidL(const RBuf8& aBlobHeader, RArray<RBuf8>& aCids); |
|
240 |
|
241 /** |
|
242 * Extracts BLOB from response MultiPart message and writes it in a file |
|
243 * @since S60 v3.2 |
|
244 * @param aIndex Which BLOB from response is processed, starts from 0 |
|
245 * @param aFirst Shows is it First part of BLOB or not |
|
246 * @param aBlob The part of BLOB from response that should be written in fhe file |
|
247 * @param aFileNames Array of File names for the all responsed BLOBs |
|
248 * @return size of file in order to monitor progess |
|
249 */ |
|
250 IMPORT_C static TInt SetFileL(TUint aIndex, TBool aFirst, TDesC8& aBlob, |
|
251 RArray<RBuf8>& aFileNames); |
|
252 |
|
253 private: |
|
254 |
|
255 /** |
|
256 * Generates the file name for BLOB of response MultiPart message |
|
257 * and collects it in array of file names for the all BLOBs |
|
258 * @since S60 v3.2 |
|
259 * @param aIndex Which BLOB from response is processed, starts from 0 |
|
260 * @param aFileNames Array of File names for the all responsed BLOBs |
|
261 */ |
|
262 static void FileNameL(TUint aIndex, RArray<RBuf8>& aFileNames); |
|
263 }; |
|
264 |
|
265 #endif // SEN_MultiPart_UTILS_H |
|
266 |
|
267 // End of file |
|
268 |
|
269 |