author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 00:13:15 +0300 | |
changeset 72 | 6f657153cbc5 |
parent 44 | 36f374c67aa8 |
permissions | -rw-r--r-- |
31 | 1 |
/* |
2 |
* Copyright (c) 2002-2009 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: |
|
15 |
* binary encoding of a multimedia message |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
||
20 |
||
21 |
//#define CONTENT_DISPOSITION_TEST |
|
22 |
||
23 |
// INCLUDE FILES |
|
24 |
#include <e32std.h> |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
25 |
#include <e32hal.h> |
31 | 26 |
#include <apparc.h> |
27 |
#include <s32mem.h> |
|
28 |
#include <msventry.h> |
|
29 |
#include <utf.h> |
|
30 |
#include <e32math.h> |
|
31 |
#include <msvids.h> |
|
32 |
#include <escapeutils.h> |
|
33 |
#include <badesca.h> |
|
34 |
#include <mmsvattachmentmanager.h> |
|
35 |
#include <mmsvattachmentmanagersync.h> |
|
36 |
#include <cmsvmimeheaders.h> |
|
37 |
#include <imcvcodc.h> |
|
38 |
||
39 |
#include <msgtextutils.h> |
|
40 |
#include <msvstore.h> |
|
41 |
#include <charconv.h> |
|
42 |
||
43 |
#include <centralrepository.h> // link against centralrepository.lib |
|
44 |
#include "MmsEnginePrivateCRKeys.h" |
|
45 |
||
46 |
#include "mmsheaders.h" |
|
47 |
#include "mmsconst.h" |
|
48 |
#include "mmscodec.h" |
|
49 |
#include "mmsencode.h" |
|
50 |
#include "mmsservercommon.h" |
|
51 |
#include "mmssession.h" |
|
52 |
#include "mmsgenutils.h" |
|
53 |
#include "mmserrors.h" |
|
54 |
#include "mmsentrywrapper.h" |
|
55 |
#include "mmsmmboxmessageheaders.h" |
|
56 |
#include "mmsmmboxviewheaders.h" |
|
57 |
#include "mmssendingchain.h" |
|
58 |
||
59 |
const TInt KMmsExtra = 1024; // extra memory left for others |
|
60 |
const TInt KMmsShortIntegerLimit127 = 127; // limit for short integer length |
|
61 |
const TInt KMmsOneByteLimit = 0x100; |
|
62 |
const TInt KMmsTwoByteLimit = 0x10000; |
|
63 |
const TInt KMmsThreeByteLimit = 0x1000000; |
|
64 |
const TInt KMms2 = 2; |
|
65 |
const TInt KMms3 = 3; |
|
66 |
const TInt KMms4 = 4; |
|
67 |
const TInt KMms5 = 5; |
|
68 |
const TInt KMms7 = 7; |
|
69 |
const TInt KMms8 = 8; |
|
70 |
const TInt KMms24 = 24; // shift of three half bytes |
|
71 |
const TInt KMms30 = 30; // upper limit for short length encoding |
|
72 |
const TUint8 KMms0x80 = 0x80; // 128 |
|
73 |
const TUint8 KMms0x7F = 0x7F; // 127 |
|
74 |
const TUint8 KMms0xFF = 0xFF; |
|
75 |
const TInt KMmsMaxCidLength = 18; |
|
76 |
// max filename length according to MMS conformance specs |
|
77 |
const TInt KMmsMaxFileNameLength = 40; |
|
78 |
// if 40 bytes are encoded in base 64, the result is 56 bytes |
|
79 |
// (two bytes of padding are needed to make the number divisible by 3) |
|
80 |
const TInt KMaxEncodingLength = 56; |
|
81 |
// Maximum length of output buffer needed for encoding the filename |
|
82 |
// Max 56 bytes for actual encoding and 12 bytes for character set (utf8) |
|
83 |
// and encoding scheme indicator 68 for final result, but we allocate |
|
84 |
// the maximum Mime header length to be sure everything fits. |
|
85 |
const TInt KMaxNameBufferLength = 75; |
|
86 |
const TInt KMmsEncodingExtraLength = 12; |
|
87 |
const TInt KMmsPreambleLength = 10; |
|
88 |
_LIT8( KMmsQuotedPreamble, "=?utf-8?Q?" ); |
|
89 |
_LIT8( KMmsBase64Preamble, "=?utf-8?B?" ); |
|
90 |
_LIT8( KMmsEncodingTrailer, "?=" ); |
|
91 |
const TInt KMmsIntUnderscore = 0x5F; // underscore |
|
92 |
||
93 |
||
94 |
enum TMmsMachineStates |
|
95 |
{ |
|
96 |
EMmsIdle, |
|
97 |
EMmsEncodingHeaders, |
|
98 |
EMmsEncodingAttachments, |
|
99 |
EMmsFinished |
|
100 |
}; |
|
101 |
||
102 |
// These are the stages for chunked encoding. |
|
103 |
// The chunked encoding is synchronous, so the stages are different |
|
104 |
// from the machine states. |
|
105 |
enum TMmsChunkedEncodingStages |
|
106 |
{ |
|
107 |
EMmsHeaders, |
|
108 |
EMmsAttachmentHeaders, |
|
109 |
EMmsAttachmentData |
|
110 |
}; |
|
111 |
||
112 |
// ==================== LOCAL FUNCTIONS ==================== |
|
113 |
||
114 |
// ================= MEMBER FUNCTIONS ======================= |
|
115 |
||
116 |
// --------------------------------------------------------------------------- |
|
117 |
// C++ default constructor can NOT contain any code, that |
|
118 |
// might leave. |
|
119 |
// |
|
120 |
// All member variables are automatically zeroed in the constructor |
|
121 |
// of a class derived from CBase. |
|
122 |
// Priority is set slightly above standard (1 instead of 0) to make sure |
|
123 |
// that message is sent as soon as possible (user input has priority 10). |
|
124 |
// Variables related to chunked encoding are initialized to indicate |
|
125 |
// one complete chunk only. |
|
126 |
// --------------------------------------------------------------------------- |
|
127 |
// |
|
128 |
CMmsEncode::CMmsEncode() |
|
129 |
:CMsgActive ( KMmsActiveObjectPriority ), |
|
130 |
iState ( EMmsIdle ), |
|
131 |
iOverallDataSize ( -1 ), |
|
132 |
iLastChunk ( ETrue ), |
|
133 |
iOnlyOneChunk( ETrue ) |
|
134 |
{ |
|
135 |
} |
|
136 |
||
137 |
// --------------------------------------------------------------------------- |
|
138 |
// Symbian OS default constructor can leave. |
|
139 |
// --------------------------------------------------------------------------- |
|
140 |
// |
|
141 |
void CMmsEncode::ConstructL( RFs& aFs ) |
|
142 |
{ |
|
143 |
iFs = aFs; |
|
144 |
CActiveScheduler::Add( this ); |
|
145 |
} |
|
146 |
||
147 |
// --------------------------------------------------------------------------- |
|
148 |
// Two-phased constructor. |
|
149 |
// --------------------------------------------------------------------------- |
|
150 |
// |
|
151 |
EXPORT_C CMmsEncode* CMmsEncode::NewL( RFs& aFs ) |
|
152 |
{ |
|
153 |
CMmsEncode* self = new ( ELeave ) CMmsEncode; |
|
154 |
||
155 |
CleanupStack::PushL( self ); |
|
156 |
self->ConstructL( aFs ); |
|
157 |
CleanupStack::Pop( self ); |
|
158 |
||
159 |
return self; |
|
160 |
} |
|
161 |
||
162 |
||
163 |
// --------------------------------------------------------------------------- |
|
164 |
// Destructor |
|
165 |
// --------------------------------------------------------------------------- |
|
166 |
// |
|
167 |
CMmsEncode::~CMmsEncode() |
|
168 |
{ |
|
169 |
||
170 |
Cancel(); |
|
171 |
||
172 |
if ( iFileOpen ) |
|
173 |
{ |
|
174 |
iAttachFile.Close(); |
|
175 |
iFileOpen = EFalse; |
|
176 |
} |
|
177 |
||
178 |
// Do not delete pointers that were presents from the caller. |
|
179 |
// The caller still owns that data |
|
180 |
delete iMimeHeaders; // this is ours too. |
|
181 |
||
182 |
} |
|
183 |
||
184 |
// --------------------------------------------------------- |
|
185 |
// |
|
186 |
// --------------------------------------------------------- |
|
187 |
// |
|
188 |
EXPORT_C void CMmsEncode::StartL( |
|
189 |
MMmsEntryWrapper& aEntryWrapper, |
|
190 |
CMmsHeaders& aMmsHeaders, |
|
191 |
CBufFlat& aEncodeBuffer, |
|
192 |
TRequestStatus& aStatus ) |
|
193 |
{ |
|
194 |
||
195 |
// This is the entry point for encoding all PDUs that contain both headers |
|
196 |
// and data. |
|
197 |
// For normal use the only PDUs in this category would be M-send.req and |
|
198 |
// M-MBox-Upload.req, but for testing purposes the following PDUs may |
|
199 |
// also be handled using this entry point: |
|
200 |
// M-retrieve.conf (for testing purposes) |
|
201 |
// M-Mbox-View.conf (for testing purposes) |
|
202 |
// M-Mbox-Descr (for testing purposes) |
|
203 |
||
204 |
// Old asynchronous encoding is retained. |
|
205 |
// Reset sets all chunk-related variables to indicate one chunk which is the last one |
|
206 |
Reset(); |
|
207 |
||
208 |
iEntryWrapper = &aEntryWrapper; |
|
209 |
iMmsHeaders = &aMmsHeaders; |
|
210 |
iEncodeBuffer = &aEncodeBuffer; |
|
211 |
||
212 |
if ( iMimeHeaders ) |
|
213 |
{ |
|
214 |
iMimeHeaders->Reset(); |
|
215 |
} |
|
216 |
else |
|
217 |
{ |
|
218 |
iMimeHeaders = CMsvMimeHeaders::NewL(); |
|
219 |
} |
|
220 |
||
221 |
// We need to know the message entry ID |
|
222 |
// The wrapper originally points to the message entry |
|
223 |
||
224 |
TMsvEntry indexEntry; |
|
225 |
iError = iEntryWrapper->GetIndexEntry( indexEntry ); |
|
226 |
iCurrentMessageId = indexEntry.Id(); |
|
227 |
||
228 |
CMsvStore* store = iEntryWrapper->ReadStoreL(); |
|
229 |
CleanupStack::PushL( store ); |
|
230 |
||
231 |
// Only new attachment structure is supported |
|
232 |
MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
233 |
iNumberOfAttachments = attachMan.AttachmentCount(); |
|
234 |
||
235 |
CleanupStack::PopAndDestroy( store ); |
|
236 |
||
237 |
Queue( aStatus ); |
|
238 |
||
239 |
iStatus = KRequestPending; |
|
240 |
SetActive(); |
|
241 |
// Pretend that we called an asynchronous service |
|
242 |
// in order to get into the state machine loop |
|
243 |
TRequestStatus* status = &iStatus; |
|
244 |
User::RequestComplete( status, iError ); |
|
245 |
||
246 |
} |
|
247 |
||
248 |
// --------------------------------------------------------- |
|
249 |
// |
|
250 |
// --------------------------------------------------------- |
|
251 |
// |
|
252 |
EXPORT_C void CMmsEncode::EncodeHeadersL( |
|
253 |
CMmsHeaders& aMmsHeaders, |
|
254 |
CBufFlat& aEncodeBuffer ) |
|
255 |
{ |
|
256 |
// This function is used to encode all PDUs that contain only headers, |
|
257 |
// not data. Some are responses sent to MMSC, some are requests that |
|
258 |
// contain headers only. |
|
259 |
// Nothing is read from storage, everything to be encoded is contained |
|
260 |
// in the headers. |
|
261 |
// No active object is invoked, this is a synchronous function |
|
262 |
||
263 |
// Old one-chunk encoding is retained for encoding headers only. |
|
264 |
// Reset sets all chunk-related variables to indicate one chunk which is the last one |
|
265 |
Reset(); // also sets iError to KErrNone |
|
266 |
||
267 |
iMmsHeaders = &aMmsHeaders; |
|
268 |
iEncodeBuffer = &aEncodeBuffer; |
|
269 |
||
270 |
// start from the beginning |
|
271 |
iPosition = 0; |
|
272 |
// we discard old contents of the buffer in case we must expand it |
|
273 |
iEncodeBuffer->Reset(); |
|
274 |
||
275 |
// We are a bit greedy here so that we don't need |
|
276 |
// to change the code if there is a minor change in the specs. |
|
277 |
iEncodeBuffer->ResizeL( iMmsHeaders->Size() + KMMSBufferExtra ); |
|
278 |
||
279 |
// encode message depending on type |
|
280 |
// these are all types that contain headers only, never data |
|
281 |
switch ( iMmsHeaders->MessageType() ) |
|
282 |
{ |
|
283 |
case KMmsMessageTypeMNotifyRespInd: |
|
284 |
EncodeNotifyResponse(); |
|
285 |
break; |
|
286 |
case KMmsMessageTypeAcknowledgeInd: |
|
287 |
EncodeAcknowledgeIndication(); |
|
288 |
break; |
|
289 |
case KMmsMessageTypeMNotificationInd: |
|
290 |
EncodeMmsNotificationL(); |
|
291 |
break; |
|
292 |
case KMmsMessageTypeForwardReq: |
|
293 |
EncodeForwardRequestL(); |
|
294 |
break; |
|
295 |
case KMmsMessageTypeReadRecInd: |
|
296 |
EncodeReadReplyL(); |
|
297 |
break; |
|
298 |
case KMmsMessageTypeMboxStoreReq: |
|
299 |
EncodeMMBoxStoreRequestL(); |
|
300 |
break; |
|
301 |
case KMmsMessageTypeMboxViewReq: |
|
302 |
// This may contain keywords. Reserve some extra space |
|
303 |
EncodeMMBoxViewRequestL(); |
|
304 |
break; |
|
305 |
case KMmsMessageTypeMBoxDeleteReq: |
|
306 |
case KMmsMessageTypeDeleteReq: |
|
307 |
EncodeDeleteRequestL(); |
|
308 |
break; |
|
309 |
case KMmsMessageTypeCancelConf: |
|
310 |
EncodeCancelResponse(); |
|
311 |
break; |
|
312 |
case KMmsMessageTypeReadOrigInd: |
|
313 |
// This is for testing purposes. |
|
314 |
// identical to ReadRecInd except for PDU type |
|
315 |
// This would be the PDU sent to originator by MMSC |
|
316 |
EncodeReadReplyL(); |
|
317 |
break; |
|
318 |
case KMmsMessageTypeMSendConf: |
|
319 |
// for testing purposes |
|
320 |
EncodeSendConfirmationL(); |
|
321 |
break; |
|
322 |
case KMmsMessageTypeDeliveryInd: |
|
323 |
// for testing purposes |
|
324 |
EncodeDeliveryReportL(); |
|
325 |
break; |
|
326 |
case KMmsMessageTypeForwardConf: |
|
327 |
// for testing purposes |
|
328 |
EncodeForwardConfirmationL(); |
|
329 |
break; |
|
330 |
case KMmsMessageTypeMboxStoreConf: |
|
331 |
// for testing purposes |
|
332 |
EncodeMMBoxStoreConfirmationL(); |
|
333 |
break; |
|
334 |
case KMmsMessageTypeMBoxUploadConf: |
|
335 |
// for testing purposes |
|
336 |
EncodeMMBoxUploadConfirmationL(); |
|
337 |
break; |
|
338 |
case KMmsMessageTypeMBoxDeleteConf: |
|
339 |
case KMmsMessageTypeDeleteConf: |
|
340 |
// for testing purposes |
|
341 |
EncodeDeleteConfirmationL(); |
|
342 |
break; |
|
343 |
case KMmsMessageTypeCancelReq: |
|
344 |
// for testing purposes |
|
345 |
EncodeCancelRequest(); |
|
346 |
break; |
|
347 |
#ifdef __WINS__ |
|
348 |
case KMmsMessageTypeMSendReq: |
|
349 |
EncodeSendRequestHeadersL(); |
|
350 |
break; |
|
351 |
case KMmsMessageTypeMBoxUploadReq: |
|
352 |
// This type has attachments and headers |
|
353 |
// This function encodes headers only |
|
354 |
EncodeMMBoxUploadRequestL(); |
|
355 |
break; |
|
356 |
case KMmsMessageTypeMRetrieveConf: |
|
357 |
// for test purposes |
|
358 |
EncodeRetrieveConfirmationL(); |
|
359 |
break; |
|
360 |
case KMmsMessageTypeMboxViewConf: |
|
361 |
// for test purposes |
|
362 |
EncodeMMBoxViewConfirmationL(); |
|
363 |
break; |
|
364 |
case KMmsMessageTypeMBoxDescr: |
|
365 |
// for test purposes |
|
366 |
EncodeMMBoxDescriptionL(); |
|
367 |
break; |
|
368 |
#endif |
|
369 |
default: |
|
370 |
// Illegal message type. |
|
371 |
iEncodeBuffer->Reset(); |
|
372 |
iPosition = 0; |
|
373 |
break; |
|
374 |
} |
|
375 |
||
376 |
// Remove slack to keep garbage out from the end of the file |
|
377 |
iEncodeBuffer->ResizeL( iPosition ); |
|
378 |
// Dump the buffer contents into file if requested |
|
379 |
Dump(); |
|
380 |
||
381 |
iOverallDataSize = iEncodeBuffer->Size(); |
|
382 |
||
383 |
} |
|
384 |
||
385 |
// --------------------------------------------------------- |
|
386 |
// |
|
387 |
// --------------------------------------------------------- |
|
388 |
// |
|
389 |
EXPORT_C void CMmsEncode::StartChunkedL( |
|
390 |
MMmsEntryWrapper& aEntryWrapper, |
|
391 |
CMmsHeaders& aMmsHeaders, |
|
392 |
CBufFlat& aEncodeBuffer, |
|
393 |
TRequestStatus& aStatus ) |
|
394 |
{ |
|
395 |
||
396 |
// This is the entry point for chunked encoding all PDUs that contain both headers |
|
397 |
// and data. |
|
398 |
||
399 |
// Reset sets all chunk-related variables to indicate one chunk which is the last one |
|
400 |
#ifndef _NO_MMSS_LOGGING_ |
|
401 |
TMmsLogger::Log( _L("CMmsEncode: Start chunked") ); |
|
402 |
#endif |
|
403 |
Reset(); // also sets iError to KErrNone |
|
404 |
iDataSupplierStage = EMmsHeaders; |
|
405 |
||
406 |
iEntryWrapper = &aEntryWrapper; |
|
407 |
iMmsHeaders = &aMmsHeaders; |
|
408 |
iEncodeBuffer = &aEncodeBuffer; |
|
409 |
||
410 |
if ( iMimeHeaders ) |
|
411 |
{ |
|
412 |
iMimeHeaders->Reset(); |
|
413 |
} |
|
414 |
else |
|
415 |
{ |
|
416 |
iMimeHeaders = CMsvMimeHeaders::NewL(); |
|
417 |
} |
|
418 |
||
419 |
// We need to know the message entry ID |
|
420 |
// The wrapper originally points to the message entry |
|
421 |
||
422 |
TMsvEntry indexEntry; |
|
423 |
iError = iEntryWrapper->GetIndexEntry( indexEntry ); |
|
424 |
iCurrentMessageId = indexEntry.Id(); |
|
425 |
||
426 |
// Encode headers to the buffer |
|
427 |
// The rest will follow when next data chunk is requested. |
|
428 |
EncodeHeadersChunkedL(); |
|
429 |
||
430 |
aStatus=KRequestPending; |
|
431 |
TRequestStatus* status = &aStatus; |
|
432 |
User::RequestComplete( status, iError ); |
|
433 |
} |
|
434 |
||
435 |
||
436 |
// --------------------------------------------------------- |
|
437 |
// From class MMmsCodecDataSupplier |
|
438 |
// |
|
439 |
// --------------------------------------------------------- |
|
440 |
// |
|
441 |
TInt CMmsEncode::GetNextDataPart( TPtrC8& aDataPart, TBool& aLastDataChunk ) |
|
442 |
{ |
|
443 |
TInt error = KErrNone; |
|
444 |
if ( !iEncodeBuffer || iEncodeBuffer->Size() == 0 ) |
|
445 |
{ |
|
446 |
// called out of context or no message data available |
|
447 |
error = KErrNotFound; |
|
448 |
} |
|
449 |
else |
|
450 |
{ |
|
451 |
aDataPart.Set( iEncodeBuffer->BackPtr( iPosition ) ); |
|
452 |
} |
|
453 |
aLastDataChunk = iLastChunk; |
|
454 |
||
455 |
return error; |
|
456 |
} |
|
457 |
||
458 |
// --------------------------------------------------------- |
|
459 |
// From class MMmsCodecDataSupplier |
|
460 |
// |
|
461 |
// --------------------------------------------------------- |
|
462 |
// |
|
463 |
TInt CMmsEncode::ReleaseData() |
|
464 |
{ |
|
465 |
if ( iOnlyOneChunk ) |
|
466 |
{ |
|
467 |
// if we have only one chunk we always point to the beginning |
|
468 |
// the buffer gets cleared when all data has been handled |
|
469 |
return KErrNone; |
|
470 |
} |
|
471 |
||
472 |
iPosition = 0; |
|
473 |
||
474 |
// encode next data part into the buffer |
|
475 |
||
476 |
if ( iDataSupplierStage == EMmsAttachmentHeaders && iNumberOfAttachments == 0 ) |
|
477 |
{ |
|
478 |
iLastChunk = ETrue; |
|
479 |
iDataSupplierStage = EMmsHeaders; |
|
480 |
} |
|
481 |
else if ( iDataSupplierStage == EMmsAttachmentHeaders ) |
|
482 |
{ |
|
483 |
#ifndef _NO_MMSS_LOGGING_ |
|
484 |
TMmsLogger::Log( _L("- data supplier stage: Attachment headers") ); |
|
485 |
#endif |
|
486 |
iError = iEntryWrapper->SetCurrentEntry( iCurrentMessageId ); |
|
487 |
if ( iError != KErrNone ) |
|
488 |
{ |
|
489 |
return iError; |
|
490 |
} |
|
491 |
||
492 |
iCurrentFileSize = 0; |
|
493 |
CMsvStore* store = NULL; |
|
494 |
TRAP( iError, |
|
495 |
{ |
|
496 |
store = iEntryWrapper->ReadStoreL(); |
|
497 |
CleanupStack::PushL( store ); |
|
498 |
MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
499 |
iCurrentFileSize = EncodeHeadersAndGetFileL( attachMan ); |
|
500 |
CleanupStack::PopAndDestroy( store ); |
|
501 |
}); |
|
502 |
if ( iError != KErrNone ) |
|
503 |
{ |
|
504 |
return iError; |
|
505 |
} |
|
506 |
||
507 |
// Now we have the attachment headers in our buffer. |
|
508 |
// If there is room, put data there, too |
|
509 |
||
510 |
if ( iBufferSize - iPosition >= iCurrentFileSize ) |
|
511 |
{ |
|
512 |
#ifndef _NO_MMSS_LOGGING_ |
|
513 |
TMmsLogger::Log( _L("- enough room left in buffer for attachment data") ); |
|
514 |
#endif |
|
515 |
EncodeAttachmentData( iAttachFile, iCurrentFileSize ); |
|
516 |
iPosition += iCurrentFileSize; |
|
517 |
iAttachFile.Close(); |
|
518 |
iFileOpen = EFalse; |
|
519 |
iCurrentAttachment++; |
|
520 |
if ( iCurrentAttachment >= iNumberOfAttachments ) |
|
521 |
{ |
|
522 |
iLastChunk = ETrue; |
|
523 |
iDataSupplierStage = EMmsHeaders; |
|
524 |
} |
|
525 |
else |
|
526 |
{ |
|
527 |
// one attachment finished - move to next one |
|
528 |
iDataSupplierStage = EMmsAttachmentHeaders; |
|
529 |
} |
|
530 |
} |
|
531 |
else |
|
532 |
{ |
|
533 |
iDataSupplierStage = EMmsAttachmentData; |
|
534 |
} |
|
535 |
} |
|
536 |
else if ( iDataSupplierStage == EMmsAttachmentData ) |
|
537 |
{ |
|
538 |
#ifndef _NO_MMSS_LOGGING_ |
|
539 |
TMmsLogger::Log( _L("- data supplier stage: Attachment data") ); |
|
540 |
#endif |
|
541 |
// Add as much attachment data as possible. |
|
542 |
// Attachment file is now open, check position |
|
543 |
TInt filePosition = 0; |
|
544 |
iError = iAttachFile.Seek( ESeekCurrent, filePosition ); |
|
545 |
if ( iError != KErrNone ) |
|
546 |
{ |
|
547 |
return iError; |
|
548 |
} |
|
549 |
TInt dataLeft = iCurrentFileSize - filePosition; |
|
550 |
TInt roomLeft = iBufferSize - iPosition; |
|
551 |
if ( roomLeft >= dataLeft ) |
|
552 |
{ |
|
553 |
EncodeAttachmentData( iAttachFile, dataLeft ); |
|
554 |
iPosition += dataLeft; |
|
555 |
iAttachFile.Close(); |
|
556 |
iFileOpen = EFalse; |
|
557 |
iCurrentAttachment++; |
|
558 |
if ( iCurrentAttachment >= iNumberOfAttachments ) |
|
559 |
{ |
|
560 |
iLastChunk = ETrue; |
|
561 |
iDataSupplierStage = EMmsHeaders; |
|
562 |
} |
|
563 |
else |
|
564 |
{ |
|
565 |
// one attachment finished - move to next one |
|
566 |
iDataSupplierStage = EMmsAttachmentHeaders; |
|
567 |
} |
|
568 |
} |
|
569 |
else |
|
570 |
{ |
|
571 |
// we have more data than fits into buffer |
|
572 |
EncodeAttachmentData( iAttachFile, roomLeft ); |
|
573 |
iPosition += roomLeft; |
|
574 |
// We don't close the file because we still have data. |
|
575 |
// We stay in EMmsAttachmentHeaders state |
|
576 |
} |
|
577 |
} |
|
578 |
else |
|
579 |
{ |
|
580 |
// do nothing, keep LINT happy |
|
581 |
} |
|
582 |
#ifndef _NO_MMSS_LOGGING_ |
|
583 |
if ( iDataSupplierStage == EMmsHeaders ) |
|
584 |
{ |
|
585 |
TMmsLogger::Log( _L("- last chunk released") ); |
|
586 |
TMmsLogger::Log( _L("- data supplier stage: MMS headers") ); |
|
587 |
} |
|
588 |
#endif |
|
589 |
// If we have reached the end and have been asked to release data |
|
590 |
// we have nothing left to do. |
|
591 |
||
592 |
// dump what we got into file - if needed |
|
593 |
if ( iPosition > 0 ) |
|
594 |
{ |
|
595 |
DumpAppend(); |
|
596 |
} |
|
597 |
return iError; |
|
598 |
} |
|
599 |
||
600 |
// --------------------------------------------------------- |
|
601 |
// From class MMmsCodecDataSupplier |
|
602 |
// |
|
603 |
// --------------------------------------------------------- |
|
604 |
// |
|
605 |
TInt CMmsEncode::OverallDataSize() |
|
606 |
{ |
|
607 |
// If we have encoded all data, iOverallDataSize contains the |
|
608 |
// actual amount of data. |
|
609 |
// If we are doing chunked encoding, it contains -1. |
|
610 |
return iOverallDataSize; |
|
611 |
} |
|
612 |
||
613 |
||
614 |
// --------------------------------------------------------- |
|
615 |
// From class MMmsCodecDataSupplier |
|
616 |
// |
|
617 |
// --------------------------------------------------------- |
|
618 |
// |
|
619 |
TInt CMmsEncode::ResetSupplier() |
|
620 |
{ |
|
621 |
#ifndef _NO_MMSS_LOGGING_ |
|
622 |
TMmsLogger::Log( _L("CMmsEncode: ResetSupplier") ); |
|
623 |
#endif |
|
624 |
if ( iOnlyOneChunk ) |
|
625 |
{ |
|
626 |
// if we have only one chunk we always point to the beginning |
|
627 |
// the buffer gets cleared when all data has been handled |
|
628 |
return KErrNone; |
|
629 |
} |
|
630 |
||
631 |
// start data from the beginning |
|
632 |
iError = KErrNone; |
|
633 |
iDataSupplierStage = EMmsHeaders; |
|
634 |
TRAP( iError, EncodeHeadersChunkedL() ); |
|
635 |
||
636 |
return iError; |
|
637 |
} |
|
638 |
||
639 |
// --------------------------------------------------------- |
|
640 |
// From class CMsgActive |
|
641 |
// |
|
642 |
// --------------------------------------------------------- |
|
643 |
// |
|
644 |
void CMmsEncode::DoRunL() |
|
645 |
{ |
|
646 |
||
647 |
// This routine takes the state machine through the states |
|
648 |
// until an error is encountered or the cycle completes. |
|
649 |
||
650 |
if ( iError != KErrNone ) |
|
651 |
{ |
|
652 |
// We encountered an error, and cannot continue |
|
653 |
// For the time being we just give up without trying |
|
654 |
// to do any decent cleanup. |
|
655 |
iStatus = iError; |
|
656 |
// If we return from DoRunL without becoming active again, |
|
657 |
// RunL completes. |
|
658 |
return; |
|
659 |
} |
|
660 |
||
661 |
if ( iState != EMmsFinished ) |
|
662 |
{ |
|
663 |
SelectNextState(); |
|
664 |
// If appropriate, ChangeStateL makes us active again |
|
665 |
ChangeStateL(); |
|
666 |
} |
|
667 |
else |
|
668 |
{ |
|
669 |
// We are done, we must become idle again |
|
670 |
FinishL(); |
|
671 |
iStatus = iError; |
|
672 |
// If we return from DoRunL without becoming active again, |
|
673 |
// RunL completes. |
|
674 |
} |
|
675 |
// As we are using standard Mentact RunL, we must leave |
|
676 |
// if we have encountered an error, and do not want to continue |
|
677 |
||
678 |
if ( iError != KErrNone && !IsActive() ) |
|
679 |
{ |
|
680 |
iPosition = 0; |
|
681 |
FinishL(); |
|
682 |
User::Leave( iError ); |
|
683 |
} |
|
684 |
} |
|
685 |
||
686 |
// --------------------------------------------------------- |
|
687 |
// From class CMsgActive |
|
688 |
// |
|
689 |
// --------------------------------------------------------- |
|
690 |
// |
|
691 |
void CMmsEncode::DoComplete( TInt& /* aStatus */ ) |
|
692 |
{ |
|
693 |
// We are exiting the loop - we say we are idle now |
|
694 |
iState = EMmsIdle; |
|
695 |
} |
|
696 |
||
697 |
// --------------------------------------------------------- |
|
698 |
// |
|
699 |
// --------------------------------------------------------- |
|
700 |
// |
|
701 |
void CMmsEncode::SelectNextState() |
|
702 |
{ |
|
703 |
||
704 |
// If appropriate, the functions called within the switch statement |
|
705 |
// will make us active again. If all is done, the asynchronous request |
|
706 |
// will complete |
|
707 |
||
708 |
switch ( iState ) |
|
709 |
{ |
|
710 |
case EMmsIdle: |
|
711 |
// start the loop |
|
712 |
iState = EMmsEncodingHeaders; |
|
713 |
break; |
|
714 |
case EMmsEncodingHeaders: |
|
715 |
if ( iNumberOfAttachments > 0 ) |
|
716 |
{ |
|
717 |
iState = EMmsEncodingAttachments; |
|
718 |
} |
|
719 |
else |
|
720 |
{ |
|
721 |
iState = EMmsFinished; |
|
722 |
} |
|
723 |
break; |
|
724 |
case EMmsEncodingAttachments: |
|
725 |
// if there are more attachments, don't change state |
|
726 |
if ( iCurrentAttachment >= iNumberOfAttachments ) |
|
727 |
{ |
|
728 |
iState = EMmsFinished; |
|
729 |
} |
|
730 |
break; |
|
731 |
case EMmsFinished: |
|
732 |
// No more states |
|
733 |
iState = EMmsIdle; |
|
734 |
break; |
|
735 |
default: |
|
736 |
// Illegal state |
|
737 |
break; |
|
738 |
} |
|
739 |
} |
|
740 |
||
741 |
// --------------------------------------------------------- |
|
742 |
// |
|
743 |
// --------------------------------------------------------- |
|
744 |
// |
|
745 |
void CMmsEncode::ChangeStateL() |
|
746 |
{ |
|
747 |
switch ( iState ) |
|
748 |
{ |
|
749 |
case EMmsEncodingHeaders: |
|
750 |
EncodeHeadersL(); |
|
751 |
break; |
|
752 |
case EMmsEncodingAttachments: |
|
753 |
EncodeAttachmentL(); |
|
754 |
iCurrentAttachment++; |
|
755 |
break; |
|
756 |
case EMmsFinished: |
|
757 |
FinishL(); |
|
758 |
break; |
|
759 |
default: |
|
760 |
// Should not be here anymore |
|
761 |
break; |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
// --------------------------------------------------------- |
|
766 |
// |
|
767 |
// --------------------------------------------------------- |
|
768 |
// |
|
769 |
void CMmsEncode::Reset() |
|
770 |
{ |
|
771 |
// close open file in case operation has ended with error |
|
772 |
// and the attachment file is still open |
|
773 |
if ( iFileOpen ) |
|
774 |
{ |
|
775 |
iAttachFile.Close(); |
|
776 |
iFileOpen = EFalse; |
|
777 |
} |
|
778 |
||
779 |
iNumberOfAttachments = 0; |
|
780 |
iCurrentAttachment = 0; |
|
781 |
iError = KErrNone; |
|
782 |
iCurrentMessageId = KMsvNullIndexEntryId; |
|
783 |
iOverallDataSize = -1; |
|
784 |
iLastChunk = ETrue; |
|
785 |
iOnlyOneChunk = ETrue; |
|
786 |
} |
|
787 |
||
788 |
// --------------------------------------------------------- |
|
789 |
// |
|
790 |
// --------------------------------------------------------- |
|
791 |
// |
|
792 |
void CMmsEncode::EncodeHeadersL() |
|
793 |
{ |
|
794 |
||
795 |
// start from the beginning |
|
796 |
iPosition = 0; |
|
797 |
// we discard old contents of the buffer in case we must expand it |
|
798 |
iEncodeBuffer->Reset(); |
|
799 |
||
800 |
// calculate space needed and resize buffer |
|
801 |
TInt size = 0; |
|
802 |
size += iMmsHeaders->Size(); |
|
803 |
||
804 |
User::LeaveIfError( iEntryWrapper->SetCurrentEntry( iCurrentMessageId ) ); |
|
805 |
CMsvStore* store = iEntryWrapper->ReadStoreL(); |
|
806 |
CleanupStack::PushL( store ); |
|
807 |
// AttachmentsSize function asks actual size from files |
|
808 |
// in case the info in CMsvAttachment is not up to date. |
|
809 |
// This function leaves if the attachment file is not found. |
|
810 |
// A message cannot be sent if it refers to attachment files that no |
|
811 |
// longer exist. |
|
812 |
size += iEntryWrapper->AttachmentsSizeL( *store ); |
|
813 |
CleanupStack::PopAndDestroy( store ); |
|
814 |
store = NULL; |
|
815 |
||
816 |
size += KMMSBufferExtra; // this is just an estimate of header size... |
|
817 |
// extra needed if lots of attachments. |
|
818 |
size += KMMSAttachmentExtra * iNumberOfAttachments; |
|
819 |
TMemoryInfoV1Buf memory; |
|
820 |
UserHal::MemoryInfo( memory ); |
|
821 |
TInt available = memory().iFreeRamInBytes; |
|
822 |
// check that buffer fits, leave a little memory for others too. |
|
823 |
if ( size > ( available - KMmsExtra ) ) |
|
824 |
{ |
|
825 |
// message is too big - don't even try |
|
826 |
iError = KMmsErrorMessageTooBig; |
|
827 |
} |
|
828 |
||
829 |
if ( iError == KErrNone ) |
|
830 |
{ |
|
831 |
iEncodeBuffer->ResizeL( size ); |
|
832 |
EncodeRequestHeadersL(); |
|
833 |
} |
|
834 |
||
835 |
iStatus = KRequestPending; |
|
836 |
SetActive(); |
|
837 |
||
838 |
// We complete ourselves. |
|
839 |
TRequestStatus* status = &iStatus; |
|
840 |
User::RequestComplete( status, iError ); |
|
841 |
||
842 |
} |
|
843 |
||
844 |
// --------------------------------------------------------- |
|
845 |
// |
|
846 |
// --------------------------------------------------------- |
|
847 |
// |
|
848 |
void CMmsEncode::EncodeHeadersChunkedL() |
|
849 |
{ |
|
850 |
// The first step of chunked encoding |
|
851 |
#ifndef _NO_MMSS_LOGGING_ |
|
852 |
TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: start") ); |
|
853 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
854 |
User::LeaveIfError( iEntryWrapper->SetCurrentEntry( iCurrentMessageId ) ); |
|
855 |
||
856 |
/* Korean req: 415-5434 |
|
857 |
* Get the target encoding MIB enum from cenrep and encode MMS text objects using corresponding conversion plugins |
|
858 |
*/ |
|
859 |
TInt temp; |
|
860 |
iTargetEncodingType = 0; |
|
861 |
CRepository* repository = CRepository::NewLC( KUidMmsServerMtm ); |
|
862 |
if ( repository->Get( KMmsEncodingType, temp ) == KErrNone ) |
|
863 |
{ |
|
864 |
iTargetEncodingType = temp; |
|
865 |
} |
|
866 |
CleanupStack::PopAndDestroy( repository ); |
|
867 |
#ifndef _NO_MMSS_LOGGING_ |
|
868 |
TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: target encoding type: %d"), iTargetEncodingType ); |
|
869 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
870 |
||
871 |
if( iTargetEncodingType != 0 ) |
|
872 |
{ |
|
873 |
TRAPD( err, PreProcessAttachmentDataL() ); |
|
874 |
||
875 |
#ifndef _NO_MMSS_LOGGING_ |
|
876 |
/* if any error, korean specific encoding failed, But this should not stop from sending MMS using |
|
877 |
* existing default encoding. Hence just log the error and continue in any case |
|
878 |
*/ |
|
879 |
if( err != KErrNone ) |
|
880 |
{ |
|
881 |
TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: PreProcessAttachmentDataL error: %d"), err ); |
|
882 |
} |
|
883 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
884 |
} |
|
885 |
||
886 |
//Open store for read-only purpose |
|
887 |
CMsvStore* store = iEntryWrapper->ReadStoreL(); |
|
888 |
CleanupStack::PushL( store ); |
|
889 |
||
890 |
// Only new attachment structure is supported |
|
891 |
MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
892 |
iNumberOfAttachments = attachMan.AttachmentCount(); |
|
893 |
||
894 |
TInt size = 0; |
|
895 |
size += iMmsHeaders->Size(); |
|
896 |
size += KMMSBufferExtra; // this is just an estimate of header size... |
|
897 |
// The buffer must be at least big enough to hold all headers |
|
898 |
iBufferSize = Max( KMmsChunkedBufferSize, size ); |
|
899 |
||
900 |
// extra needed if lots of attachments. |
|
901 |
// AttachmentsSize function asks actual size from files |
|
902 |
// in case the info in CMsvAttachment is not up to date. |
|
903 |
// This function leaves if the attachment file is not found. |
|
904 |
// A message cannot be sent if it refers to attachment files that no |
|
905 |
// longer exist. |
|
906 |
size += iEntryWrapper->AttachmentsSizeL( *store ); |
|
907 |
size += KMMSAttachmentExtra * iNumberOfAttachments; |
|
908 |
CleanupStack::PopAndDestroy( store ); |
|
909 |
store = NULL; |
|
910 |
||
911 |
if ( iBufferSize > size ) |
|
912 |
{ |
|
913 |
// Our message is small enough to be sent in one chunk. |
|
914 |
// It does not make sense to send the message in small chunks |
|
915 |
// it the total is only a few kilobytes |
|
916 |
iBufferSize = size; |
|
917 |
iOnlyOneChunk = ETrue; |
|
918 |
iLastChunk = ETrue; |
|
919 |
} |
|
920 |
else |
|
921 |
{ |
|
922 |
// we need several chunks |
|
923 |
iOnlyOneChunk = EFalse; |
|
924 |
iLastChunk = EFalse; |
|
925 |
} |
|
926 |
||
927 |
// start from the beginning |
|
928 |
iPosition = 0; |
|
929 |
iEncodeBuffer->Reset(); |
|
930 |
// This leaves if unable to resize. |
|
931 |
// We try to keep our buffer small enough so that this does not leave. |
|
932 |
iEncodeBuffer->ResizeL( iBufferSize ); |
|
933 |
#ifndef _NO_MMSS_LOGGING_ |
|
934 |
TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: MMS buff Size(Approx): %d"), iBufferSize ); |
|
935 |
#endif /* _NO_MMSS_LOGGING_ */ // The message is small enough to be sent as one chunk |
|
936 |
||
937 |
EncodeRequestHeadersL(); |
|
938 |
||
939 |
TInt i = 0; |
|
940 |
if ( iOnlyOneChunk ) |
|
941 |
{ |
|
942 |
#ifndef _NO_MMSS_LOGGING_ |
|
943 |
TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: only one chunk") ); |
|
944 |
#endif /* _NO_MMSS_LOGGING_ */ // The message is small enough to be sent as one chunk |
|
945 |
for ( i = 0; ( i < iNumberOfAttachments ) && ( iError == KErrNone ); ++i ) |
|
946 |
{ |
|
947 |
iCurrentAttachment = i; |
|
948 |
// encode attachments, too, as we have decided that our message |
|
949 |
// is small enough to fit into the buffer as one chunk |
|
950 |
// DoEncodeAttachment always encodes iCurrentAttachment |
|
951 |
// and updates buffer position as needed. |
|
952 |
DoEncodeAttachmentL(); |
|
953 |
// If something goes wrong, DoEncodeAttachmentL() sets iError, |
|
954 |
// and StartChunkedL will complete the caller with error. |
|
955 |
} |
|
956 |
iEncodeBuffer->ResizeL( iPosition ); |
|
957 |
iOverallDataSize = iEncodeBuffer->Size(); |
|
958 |
} |
|
959 |
else |
|
960 |
{ |
|
961 |
#ifndef _NO_MMSS_LOGGING_ |
|
962 |
TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: Multiple chunks") ); |
|
963 |
#endif /* _NO_MMSS_LOGGING_ */ // The message is small enough to be sent as one chunk |
|
964 |
// chunked sending - but it should be possible to calculate data size |
|
965 |
iOverallDataSize = iPosition; // This is the amount taken by headers |
|
966 |
// The message is small enough to be sent as one chunk |
|
967 |
for ( i = 0; ( i < iNumberOfAttachments ) && ( iError == KErrNone ); ++i ) |
|
968 |
{ |
|
969 |
iCurrentAttachment = i; |
|
970 |
// encode attachments, too, as we have decided that our message |
|
971 |
// is small enough to fit into the buffer as one chunk |
|
972 |
// DoEncodeAttachment always encodes iCurrentAttachment |
|
973 |
// and updates buffer position as needed. |
|
974 |
iOverallDataSize += DoGetAttachmentEncodingLengthL(); |
|
975 |
// If something goes wrong, DoEncodeAttachmentL() sets iError, |
|
976 |
// and StartChunkedL will complete the caller with error. |
|
977 |
} |
|
978 |
iCurrentAttachment = 0; |
|
979 |
iDataSupplierStage = EMmsAttachmentHeaders; |
|
980 |
if ( iError != KErrNone ) |
|
981 |
{ |
|
982 |
iOverallDataSize = -1; |
|
983 |
} |
|
984 |
} |
|
985 |
||
986 |
// Dump headers. More data will follow |
|
987 |
Dump(); |
|
988 |
#ifndef _NO_MMSS_LOGGING_ |
|
989 |
TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: end") ); |
|
990 |
#endif /* _NO_MMSS_LOGGING_ */ // The message is small enough to be sent as one chunk |
|
991 |
} |
|
992 |
||
993 |
// --------------------------------------------------------- |
|
994 |
// |
|
995 |
// --------------------------------------------------------- |
|
996 |
// |
|
997 |
void CMmsEncode::EncodeAttachmentL() |
|
998 |
{ |
|
999 |
||
1000 |
DoEncodeAttachmentL(); |
|
1001 |
||
1002 |
if ( iError != KErrNone ) |
|
1003 |
{ |
|
1004 |
// If we return without becoming active again, RunL completes |
|
1005 |
// we cannot send this message, because we cannot access attachments |
|
1006 |
return; |
|
1007 |
} |
|
1008 |
||
1009 |
iStatus = KRequestPending; |
|
1010 |
SetActive(); |
|
1011 |
||
1012 |
// Now we indicate we already did it. |
|
1013 |
TRequestStatus* status = &iStatus; |
|
1014 |
User::RequestComplete( status, iError ); |
|
1015 |
||
1016 |
} |
|
1017 |
||
1018 |
// --------------------------------------------------------- |
|
1019 |
// |
|
1020 |
// --------------------------------------------------------- |
|
1021 |
// |
|
1022 |
void CMmsEncode::DoEncodeAttachmentL() |
|
1023 |
{ |
|
1024 |
||
1025 |
// Encode one part |
|
1026 |
// We must calculate length of headers and content type |
|
1027 |
||
1028 |
User::LeaveIfError( iEntryWrapper->SetCurrentEntry( iCurrentMessageId ) ); |
|
1029 |
||
1030 |
CMsvStore* store = iEntryWrapper->ReadStoreL(); |
|
1031 |
CleanupStack::PushL( store ); |
|
1032 |
MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
1033 |
||
1034 |
TInt size = 0; |
|
1035 |
size = EncodeHeadersAndGetFileL( attachMan ); |
|
1036 |
if ( iError != KErrNone ) |
|
1037 |
{ |
|
1038 |
CleanupStack::PopAndDestroy( store ); |
|
1039 |
return; |
|
1040 |
} |
|
1041 |
||
1042 |
// The data read function will not leave |
|
1043 |
EncodeAttachmentData( iAttachFile, size ); |
|
1044 |
iPosition += size; |
|
1045 |
iAttachFile.Close(); |
|
1046 |
||
1047 |
CleanupStack::PopAndDestroy( store ); |
|
1048 |
||
1049 |
} |
|
1050 |
||
1051 |
// --------------------------------------------------------- |
|
1052 |
// |
|
1053 |
// --------------------------------------------------------- |
|
1054 |
// |
|
1055 |
TInt CMmsEncode::DoGetAttachmentEncodingLengthL() |
|
1056 |
{ |
|
1057 |
||
1058 |
// calculate length of headers and content type |
|
1059 |
||
1060 |
User::LeaveIfError( iEntryWrapper->SetCurrentEntry( iCurrentMessageId ) ); |
|
1061 |
||
1062 |
CMsvStore* store = iEntryWrapper->ReadStoreL(); |
|
1063 |
CleanupStack::PushL( store ); |
|
1064 |
MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
1065 |
||
1066 |
TInt size = 0; |
|
1067 |
size = GetHeadersAndFileSizeL( attachMan ); |
|
1068 |
CleanupStack::PopAndDestroy( store ); |
|
1069 |
return size; |
|
1070 |
||
1071 |
} |
|
1072 |
||
1073 |
// --------------------------------------------------------- |
|
1074 |
// |
|
1075 |
// --------------------------------------------------------- |
|
1076 |
// |
|
1077 |
TInt CMmsEncode::EncodeHeadersAndGetFileL( MMsvAttachmentManager& aAttachMan ) |
|
1078 |
{ |
|
1079 |
||
1080 |
CMsvAttachment* attachmentInfo = NULL; |
|
1081 |
attachmentInfo = aAttachMan.GetAttachmentInfoL( iCurrentAttachment ); |
|
1082 |
CleanupStack::PushL( attachmentInfo ); |
|
1083 |
||
1084 |
iMimeHeaders->RestoreL( *attachmentInfo ); |
|
1085 |
||
1086 |
// We don't trust the info, we ask the file itself |
|
1087 |
// Someone outside the messaging system may have changed the file |
|
1088 |
// without changing the attachment info |
|
1089 |
TInt size = 0; |
|
1090 |
if ( iFileOpen ) |
|
1091 |
{ |
|
1092 |
// close file in case we have been reset while the file is still open |
|
1093 |
iAttachFile.Close(); |
|
1094 |
iFileOpen = EFalse; |
|
1095 |
} |
|
1096 |
iAttachFile = aAttachMan.GetAttachmentFileL( iCurrentAttachment ); |
|
1097 |
iError = iAttachFile.Size( size ); |
|
1098 |
iAttachFile.Close(); |
|
1099 |
||
1100 |
if ( iError != KErrNone ) |
|
1101 |
{ |
|
1102 |
CleanupStack::PopAndDestroy( attachmentInfo ); |
|
1103 |
return size; |
|
1104 |
} |
|
1105 |
||
1106 |
// calculate the length of the headers |
|
1107 |
TBool foundName = EFalse; |
|
1108 |
TUint contentTypeSize = 0; |
|
1109 |
TInt8 contentType = -1; // indicate not found |
|
1110 |
TPtrC8 contentTypeString; |
|
1111 |
||
1112 |
TUint headerSize = 0; |
|
1113 |
||
1114 |
HBufC8* buf8 = CalculateAttachmentHeaderLengthL( |
|
1115 |
*attachmentInfo, |
|
1116 |
headerSize, |
|
1117 |
foundName, |
|
1118 |
contentTypeSize, |
|
1119 |
contentType, |
|
1120 |
contentTypeString ); |
|
1121 |
||
1122 |
CleanupStack::PushL( buf8 ); |
|
1123 |
||
1124 |
// We have calculated the header length, now we can encode: |
|
1125 |
||
1126 |
TPtrC8 nameString; |
|
1127 |
if ( !foundName && buf8 ) |
|
1128 |
{ |
|
1129 |
nameString.Set( buf8->Des() ); |
|
1130 |
} |
|
1131 |
||
1132 |
EncodeAttachmentHeadersL( |
|
1133 |
size, |
|
1134 |
headerSize, |
|
1135 |
foundName, |
|
1136 |
contentTypeSize, |
|
1137 |
contentType, |
|
1138 |
contentTypeString, |
|
1139 |
nameString ); |
|
1140 |
||
1141 |
// now we have put the name all over, we can destroy the buffer |
|
1142 |
CleanupStack::PopAndDestroy( buf8 ); |
|
1143 |
buf8 = NULL; |
|
1144 |
CleanupStack::PopAndDestroy( attachmentInfo ); |
|
1145 |
attachmentInfo = NULL; |
|
1146 |
||
1147 |
// Now just write all the data octets |
|
1148 |
iAttachFile = aAttachMan.GetAttachmentFileL( iCurrentAttachment ); |
|
1149 |
iFileOpen = ETrue; |
|
1150 |
||
1151 |
return size; |
|
1152 |
} |
|
1153 |
||
1154 |
// --------------------------------------------------------- |
|
1155 |
// |
|
1156 |
// --------------------------------------------------------- |
|
1157 |
// |
|
1158 |
TInt CMmsEncode::GetHeadersAndFileSizeL( MMsvAttachmentManager& aAttachMan ) |
|
1159 |
{ |
|
1160 |
||
1161 |
CMsvAttachment* attachmentInfo = NULL; |
|
1162 |
attachmentInfo = aAttachMan.GetAttachmentInfoL( iCurrentAttachment ); |
|
1163 |
CleanupStack::PushL( attachmentInfo ); |
|
1164 |
||
1165 |
iMimeHeaders->RestoreL( *attachmentInfo ); |
|
1166 |
||
1167 |
// We don't trust the info, we ask the file itself |
|
1168 |
// Someone outside the messaging system may have changed the file |
|
1169 |
// without changing the attachment info |
|
1170 |
TInt size = 0; |
|
1171 |
if ( iFileOpen ) |
|
1172 |
{ |
|
1173 |
// close file in case we have been reset while the file is still open |
|
1174 |
iAttachFile.Close(); |
|
1175 |
iFileOpen = EFalse; |
|
1176 |
} |
|
1177 |
iAttachFile = aAttachMan.GetAttachmentFileL( iCurrentAttachment ); |
|
1178 |
iError = iAttachFile.Size( size ); |
|
1179 |
iAttachFile.Close(); |
|
1180 |
||
1181 |
if ( iError != KErrNone ) |
|
1182 |
{ |
|
1183 |
CleanupStack::PopAndDestroy( attachmentInfo ); |
|
1184 |
return 0; |
|
1185 |
} |
|
1186 |
||
1187 |
// calculate the length of the headers |
|
1188 |
TBool foundName = EFalse; |
|
1189 |
TUint contentTypeSize = 0; |
|
1190 |
TInt8 contentType = -1; // indicate not found |
|
1191 |
TPtrC8 contentTypeString; |
|
1192 |
||
1193 |
TUint headerSize = 0; |
|
1194 |
||
1195 |
HBufC8* buf8 = CalculateAttachmentHeaderLengthL( |
|
1196 |
*attachmentInfo, |
|
1197 |
headerSize, |
|
1198 |
foundName, |
|
1199 |
contentTypeSize, |
|
1200 |
contentType, |
|
1201 |
contentTypeString ); |
|
1202 |
||
1203 |
delete buf8; // This is not needed |
|
1204 |
buf8 = NULL; |
|
1205 |
||
1206 |
CleanupStack::PopAndDestroy( attachmentInfo ); |
|
1207 |
attachmentInfo = NULL; |
|
1208 |
||
1209 |
// We have calculated the header length, now we still need the |
|
1210 |
// uintvar lengths: |
|
1211 |
||
1212 |
size += GetUintvarLength( size ); // encoding size for attachment length |
|
1213 |
size += headerSize; |
|
1214 |
size += GetUintvarLength( headerSize ); // encoding size for header length |
|
1215 |
||
1216 |
return size; |
|
1217 |
} |
|
1218 |
||
1219 |
// --------------------------------------------------------- |
|
1220 |
// |
|
1221 |
// --------------------------------------------------------- |
|
1222 |
// |
|
1223 |
HBufC8* CMmsEncode::CalculateAttachmentHeaderLengthL( |
|
1224 |
CMsvAttachment& aAttachmentInfo, |
|
1225 |
TUint& aHeaderLength, |
|
1226 |
TBool& aFoundName, |
|
1227 |
TUint& aContentTypeSize, |
|
1228 |
TInt8& aContentType, |
|
1229 |
TPtrC8& aContentTypeString ) |
|
1230 |
{ |
|
1231 |
||
1232 |
TInt numNonSafe = 0; // number of characters in filename that would require encoding |
|
1233 |
// Not all content types have parameters. |
|
1234 |
// The only parameter we can handle to some extent |
|
1235 |
// is the character set parameter for text content types. |
|
1236 |
// The name parameter will always be added if not already present |
|
1237 |
||
1238 |
// Check if we have well-known media. |
|
1239 |
aContentType = -1; // indicate not found |
|
1240 |
aContentTypeString.Set( aAttachmentInfo.MimeType() ); |
|
1241 |
if ( aContentTypeString.Length() == 0 ) |
|
1242 |
{ |
|
1243 |
// take type from mime headers |
|
1244 |
HBufC8* tempContentType = HBufC8::NewL( |
|
1245 |
iMimeHeaders->ContentType().Length() + |
|
1246 |
iMimeHeaders->ContentSubType().Length() + 1 ); |
|
1247 |
CleanupStack::PushL( tempContentType ); |
|
1248 |
tempContentType->Des().Copy( iMimeHeaders->ContentType() ); |
|
1249 |
if ( ( iMimeHeaders->ContentType().Find( KMmsSlash8 ) != |
|
1250 |
( iMimeHeaders->ContentType().Length() - 1 ) ) && |
|
1251 |
( iMimeHeaders->ContentSubType().Find( KMmsSlash8 ) != 0 ) && |
|
1252 |
( iMimeHeaders->ContentSubType().Length() != 0 ) ) |
|
1253 |
{ |
|
1254 |
tempContentType->Des().Append( KMmsSlash8 ); |
|
1255 |
} |
|
1256 |
tempContentType->Des().Append( iMimeHeaders->ContentSubType() ); |
|
1257 |
aAttachmentInfo.SetMimeTypeL( tempContentType->Des() ); |
|
1258 |
CleanupStack::PopAndDestroy( tempContentType ); |
|
1259 |
aContentTypeString.Set( aAttachmentInfo.MimeType() ); |
|
1260 |
} |
|
1261 |
||
1262 |
TInt8 i; |
|
1263 |
for ( i = 0; i < KNumberContentTypes && aContentType < 0; ++i ) |
|
1264 |
{ |
|
1265 |
if ( aContentTypeString.CompareF( |
|
1266 |
TPtrC8( KContentTypeTable[i] ) ) == 0 ) |
|
1267 |
{ |
|
1268 |
aContentType = i; |
|
1269 |
} |
|
1270 |
} |
|
1271 |
if ( aContentTypeString.Length() == 0 ) |
|
1272 |
{ |
|
1273 |
aContentTypeString.Set( KMmsUnknownType ); |
|
1274 |
aContentType = -1; |
|
1275 |
} |
|
1276 |
||
1277 |
// we always add the name parameter to content type, so we always |
|
1278 |
// use the general form. If no name is given, we use the original filename |
|
1279 |
// If the name parameter is defined, we use it. |
|
1280 |
||
1281 |
aFoundName = EFalse; |
|
1282 |
iFileName.SetLength( 0 ); |
|
1283 |
||
1284 |
aHeaderLength = 0; |
|
1285 |
// add media type length |
|
1286 |
if ( aContentType >= 0 ) |
|
1287 |
{ |
|
1288 |
// well-known media |
|
1289 |
aHeaderLength += 1; |
|
1290 |
} |
|
1291 |
else |
|
1292 |
{ |
|
1293 |
// Extension media |
|
1294 |
aHeaderLength += aContentTypeString.Length(); |
|
1295 |
aHeaderLength += 1; // terminating zero |
|
1296 |
} |
|
1297 |
||
1298 |
// If we have parameters, we must calculate their length. |
|
1299 |
if ( iMimeHeaders->MimeCharset() != 0 ) |
|
1300 |
{ |
|
1301 |
// charset has well-known encoding |
|
1302 |
aHeaderLength += 1; |
|
1303 |
if ( iMimeHeaders->MimeCharset() <= KMmsShortIntegerLimit127 ) |
|
1304 |
{ |
|
1305 |
// short integer |
|
1306 |
aHeaderLength += 1; |
|
1307 |
} |
|
1308 |
else if ( iMimeHeaders->MimeCharset() < KMmsOneByteLimit ) |
|
1309 |
{ |
|
1310 |
// long integer, short length + 1 byte of value |
|
1311 |
aHeaderLength += KMms2; |
|
1312 |
} |
|
1313 |
else if ( iMimeHeaders->MimeCharset() < KMmsTwoByteLimit ) |
|
1314 |
{ |
|
1315 |
// long integer, short length + 2 bytes of value |
|
1316 |
// so far I don't know any IANA numbers that would |
|
1317 |
// take more than two hex bytes. |
|
1318 |
aHeaderLength += KMms3; |
|
1319 |
} |
|
1320 |
else if ( iMimeHeaders->MimeCharset() < KMmsThreeByteLimit ) |
|
1321 |
{ |
|
1322 |
// long integer, short length + 3 bytes of value |
|
1323 |
aHeaderLength += KMms4; |
|
1324 |
} |
|
1325 |
else |
|
1326 |
{ |
|
1327 |
// long integer, short length + 4 bytes of value |
|
1328 |
// cannot be longer than this in any case |
|
1329 |
aHeaderLength += KMms5; |
|
1330 |
} |
|
1331 |
} |
|
1332 |
// Then the rest of the parameters, unknown, |
|
1333 |
// sent as text strings |
|
1334 |
// If "name" attribute has been defined, we use it. |
|
1335 |
// if it is not added, we must add it. |
|
1336 |
// We must ensure that we don't add it twice... |
|
1337 |
||
1338 |
TInt mimeHeaderCount = iMimeHeaders->ContentTypeParams().MdcaCount(); |
|
1339 |
||
1340 |
for ( i = 0; i < mimeHeaderCount; i++ ) |
|
1341 |
{ |
|
1342 |
// If we have corrupted parameters (length of name is zero) |
|
1343 |
// we skip the name/value pair. |
|
1344 |
// value may be zero, it will be encoded as just the terminating zero |
|
1345 |
if ( i%2 == 0 && |
|
1346 |
iMimeHeaders->ContentTypeParams().MdcaPoint( i ).Length() == 0 ) |
|
1347 |
{ |
|
1348 |
i++; |
|
1349 |
} |
|
1350 |
else |
|
1351 |
{ |
|
1352 |
// 8-byte string size + terminating zero |
|
1353 |
// If parameter has no value, it still must have |
|
1354 |
// the "no-value" indicator (just the terminating zero.) |
|
1355 |
if ( iMimeHeaders->ContentTypeParams().MdcaPoint( i ).CompareF( |
|
1356 |
KWspNameString ) == 0 && i%2 == 0 ) |
|
1357 |
{ |
|
1358 |
if ( ( i + 1 ) < mimeHeaderCount && |
|
1359 |
IsStringSafe( iMimeHeaders->ContentTypeParams().MdcaPoint( i + 1 ), |
|
1360 |
numNonSafe ) ) |
|
1361 |
{ |
|
1362 |
// We always move the name to the first item. |
|
1363 |
// It may be this parameter or something else |
|
1364 |
||
1365 |
// Content type parameters are 8-bit strings. |
|
1366 |
// We can use the name only if it is safe, otherwise it may contain some |
|
1367 |
// unknown encoding (maybe utf-8). |
|
1368 |
iFileName.Copy( ( iMimeHeaders->ContentTypeParams(). |
|
1369 |
MdcaPoint( i + 1 ) ).Right( KMmsMaxFileName ) ); |
|
1370 |
i++; |
|
1371 |
} |
|
1372 |
else |
|
1373 |
{ |
|
1374 |
// Skip the next field as it can only be used if it is safe |
|
1375 |
i++; |
|
1376 |
} |
|
1377 |
} |
|
1378 |
else |
|
1379 |
{ |
|
1380 |
aHeaderLength += iMimeHeaders->ContentTypeParams().MdcaPoint( i ).Length() + 1; |
|
1381 |
} |
|
1382 |
} |
|
1383 |
} |
|
1384 |
if ( ( iMimeHeaders->ContentTypeParams().MdcaCount() % 2 ) == 1 ) |
|
1385 |
{ |
|
1386 |
// Odd number. Obviously last parameter has no value. |
|
1387 |
// Add the "no value" token |
|
1388 |
aHeaderLength++; |
|
1389 |
} |
|
1390 |
||
1391 |
// include name parameter to content-type |
|
1392 |
||
1393 |
// if the name was not among our mime headers, |
|
1394 |
// we must add it. |
|
1395 |
TInt nameLength = 0; |
|
1396 |
||
1397 |
// We prefer the suggested filename as the content type name parameter. |
|
1398 |
// If version is 1.3 or later, we can encode a non-safe filename. |
|
1399 |
// If suggested filename is not safe, but we already have a safe filename |
|
1400 |
// in iFilename, we don't override it if version is 1.2 or lower |
|
1401 |
if ( iMimeHeaders->SuggestedFilename().Length() > 0 ) |
|
1402 |
{ |
|
1403 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion12 || |
|
1404 |
IsStringSafe( iMimeHeaders->SuggestedFilename() ) || |
|
1405 |
iFileName.Length() == 0 ) |
|
1406 |
{ |
|
1407 |
iFileName.Copy( iMimeHeaders->SuggestedFilename().Right( KMmsMaxFileName ) ); |
|
1408 |
} |
|
1409 |
} |
|
1410 |
||
1411 |
TParse* parse = NULL; |
|
1412 |
// If we don't have a filename suggestion so far, we just use the |
|
1413 |
// actual filename the attachment manager has used to save the file. |
|
1414 |
if ( iFileName.Length() == 0 ) |
|
1415 |
{ |
|
1416 |
parse = new( ELeave )TParse; |
|
1417 |
CleanupStack::PushL( parse ); |
|
1418 |
// aAttachmentInfo.FilePath() is an actual Symbian filename including path |
|
1419 |
// so it never can be too long to fit into TParse or TFilename |
|
1420 |
parse->Set( aAttachmentInfo.FilePath(), NULL, NULL ); |
|
1421 |
iFileName.Copy( parse->NameAndExt() ); |
|
1422 |
CleanupStack::PopAndDestroy( parse ); |
|
1423 |
parse = NULL; |
|
1424 |
} |
|
1425 |
||
1426 |
// Last effort: |
|
1427 |
// If our version is 1.2 or lower and the filename suggestion so far |
|
1428 |
// is not safe, we try content-location. It is always safe |
|
1429 |
||
1430 |
if ( iMmsHeaders->MmsVersion() <= KMmsVersion12 && |
|
1431 |
!IsStringSafe( iFileName ) ) |
|
1432 |
{ |
|
1433 |
if ( iMimeHeaders->ContentLocation().Length() > 0 ) |
|
1434 |
{ |
|
1435 |
// content location should be safe. |
|
1436 |
// However, we must make sure it contains no URI escapes. |
|
1437 |
// for example space is legal in filename, but not in URI. |
|
1438 |
HBufC16* decoded = NULL; |
|
1439 |
TRAPD( error, ( decoded = EscapeUtils::EscapeDecodeL( |
|
1440 |
iMimeHeaders->ContentLocation() ) ) ); |
|
1441 |
if ( error == KErrNone ) |
|
1442 |
{ |
|
1443 |
iFileName.Copy( decoded->Des().Right( KMmsMaxFileName ) ); |
|
1444 |
delete decoded; |
|
1445 |
decoded = NULL; |
|
1446 |
} |
|
1447 |
else |
|
1448 |
{ |
|
1449 |
iFileName.Copy( iMimeHeaders->ContentLocation().Right( KMmsMaxFileName ) ); |
|
1450 |
} |
|
1451 |
} |
|
1452 |
} |
|
1453 |
||
1454 |
// remove leading and trailing spaces just in case... |
|
1455 |
iFileName.Trim(); |
|
1456 |
||
1457 |
// We should now make sure that the filename is not too long. |
|
1458 |
// According to MMS conformance specs, the maximum should be 40 characters |
|
1459 |
// It is unclear if the characters mean the total length or the length |
|
1460 |
// after conversion to utf-8, but as a first approximation we try |
|
1461 |
// to ensure that the total does not exceed 40 characters |
|
1462 |
||
1463 |
nameLength = iFileName.Length(); |
|
1464 |
||
1465 |
if ( nameLength > KMmsMaxFileNameLength ) |
|
1466 |
{ |
|
1467 |
parse = new( ELeave )TParse; |
|
1468 |
CleanupStack::PushL( parse ); |
|
1469 |
parse->Set( aAttachmentInfo.FilePath(), NULL, NULL ); |
|
1470 |
iFileName.Copy( parse->Name().Left( KMmsMaxFileNameLength - parse->Ext().Length() ) ); |
|
1471 |
iFileName.Append( parse->Ext() ); |
|
1472 |
CleanupStack::PopAndDestroy( parse ); |
|
1473 |
parse = NULL; |
|
1474 |
nameLength = iFileName.Length(); |
|
1475 |
} |
|
1476 |
||
1477 |
// If encoding version is <=1.2, make filename safe, |
|
1478 |
// otherwise use MIME encoding (either base64 or quoted printable) |
|
1479 |
||
1480 |
HBufC8* buf8 = NULL; |
|
1481 |
||
1482 |
TPtrC16 originalName; |
|
1483 |
TBuf16<1> oneCharacter; |
|
1484 |
originalName.Set( iFileName ); |
|
1485 |
||
1486 |
TInt j; |
|
1487 |
||
1488 |
if ( IsStringSafe( iFileName ) ) |
|
1489 |
{ |
|
1490 |
// filename only contains us-ascii characters - use as is |
|
1491 |
buf8 = HBufC8::NewL( nameLength ); |
|
1492 |
CleanupStack::PushL( buf8 ); |
|
1493 |
buf8->Des().Copy( iFileName ); |
|
1494 |
} |
|
1495 |
else |
|
1496 |
{ |
|
1497 |
if ( iMmsHeaders->MmsVersion() <= KMmsVersion12 ) |
|
1498 |
{ |
|
1499 |
// if version is <= 1.2, the filename must be us-ascii |
|
1500 |
// replace all illegal characters by underscore |
|
1501 |
buf8 = HBufC8::NewL( nameLength ); |
|
1502 |
CleanupStack::PushL( buf8 ); |
|
1503 |
for ( j = 0; j < nameLength; ++j ) |
|
1504 |
{ |
|
1505 |
oneCharacter.Copy( originalName.Mid( j, 1 ) ); |
|
1506 |
if ( !IsStringSafe( oneCharacter ) ) |
|
1507 |
{ |
|
1508 |
_LIT( KMmsUnderscore, "_" ); |
|
1509 |
oneCharacter.Copy( KMmsUnderscore ); |
|
1510 |
} |
|
1511 |
buf8->Des().Append( oneCharacter ); |
|
1512 |
} |
|
1513 |
} |
|
1514 |
else |
|
1515 |
{ |
|
1516 |
// MMS encapsulation version is 1.3 or later |
|
1517 |
// Using non-ascii characters in filename parameter is allowed |
|
1518 |
// The filename must be encoded either using base64 or quoted printable |
|
1519 |
HBufC8* temp = NULL; |
|
72
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
1520 |
// coverity[size_error][buffer_alloc] |
31 | 1521 |
temp = CnvUtfConverter::ConvertFromUnicodeToUtf8L( originalName ); |
1522 |
CleanupStack::PushL( temp ); |
|
1523 |
// Now we have the filename in utf-8. |
|
1524 |
// We must check if it contains non-ascii, and if it does, |
|
1525 |
// we must use base64 or quoted-printable encoding. |
|
1526 |
TInt numNonSafe; |
|
1527 |
// Actually we know already that we are not safe. We just need |
|
1528 |
// to get the number of non-ascii characters |
|
1529 |
IsStringSafe( temp->Des(), numNonSafe ); |
|
1530 |
// We prefer quoted printable as it looks nicer in case we have mostly ascii, |
|
1531 |
// and it leaves extension in cleartext anyway |
|
1532 |
if ( ( temp->Des().Length() + ( KMms2 * numNonSafe ) ) <= KMaxEncodingLength ) |
|
1533 |
{ |
|
1534 |
// use quoted printable, but first convert spaces to underscores |
|
1535 |
TInt spacePosition = temp->Des().Find( KSpace8 ); |
|
1536 |
while ( spacePosition != KErrNotFound ) |
|
1537 |
{ |
|
1538 |
temp->Des()[ spacePosition ] = KMmsIntUnderscore; |
|
1539 |
spacePosition = temp->Des().Find( KSpace8 ); |
|
1540 |
} |
|
1541 |
buf8 = EncodeQuotedPrintableWordL( temp->Des() ); |
|
1542 |
} |
|
1543 |
else |
|
1544 |
{ |
|
1545 |
// use base64 |
|
1546 |
// We have not restricted the filename length in utf-8 format, |
|
1547 |
// so it may be way longer than 40 bytes. |
|
1548 |
// However, we can calculate the length the buffer needs, so we |
|
1549 |
// can try. However, we may end up with some soft line break in |
|
1550 |
// the middle of the parameter which may not be acceptable. |
|
1551 |
buf8 = EncodeBase64WordL( temp->Des() ); |
|
1552 |
} |
|
1553 |
||
1554 |
CleanupStack::PopAndDestroy( temp ); |
|
1555 |
||
1556 |
CleanupStack::PushL( buf8 ); |
|
1557 |
// we must change nameLength here |
|
1558 |
} |
|
1559 |
} |
|
1560 |
||
1561 |
// The name is now in buf8, either just copied or encoded |
|
1562 |
nameLength = buf8->Des().Length(); |
|
1563 |
||
1564 |
if ( aFoundName == EFalse ) |
|
1565 |
{ |
|
1566 |
// well-known encoding for the header itself |
|
1567 |
aHeaderLength++; |
|
1568 |
aHeaderLength += nameLength; |
|
1569 |
aHeaderLength += 1; // terminating zero |
|
1570 |
} |
|
1571 |
||
1572 |
aContentTypeSize = aHeaderLength; |
|
1573 |
||
1574 |
// As we have general form (at least name parameter), we need to indicate the length |
|
1575 |
if ( aContentTypeSize <= KMms30 ) |
|
1576 |
{ |
|
1577 |
// short length |
|
1578 |
aHeaderLength += 1; |
|
1579 |
} |
|
1580 |
else |
|
1581 |
{ |
|
1582 |
// length quote + at least one byte of uintvar |
|
1583 |
aHeaderLength += KMms2; |
|
1584 |
// Expecting over 128 bytes is paranoid. |
|
1585 |
if ( aContentTypeSize >= KMms0x7F ) |
|
1586 |
{ |
|
1587 |
aHeaderLength++; |
|
1588 |
} |
|
1589 |
} |
|
1590 |
||
1591 |
// Now the rest of the mime headers: |
|
1592 |
||
1593 |
// Content-location |
|
1594 |
// just a short integer + a null terminated string |
|
1595 |
||
1596 |
if ( iMimeHeaders->ContentLocation().Length() > 0 ) |
|
1597 |
{ |
|
1598 |
aHeaderLength += 1; // encoding of header as short integer |
|
1599 |
||
1600 |
// If we want to make sure we are safe, |
|
1601 |
// we must call IsStringSafe() function. |
|
1602 |
||
1603 |
// We just assume we are safe now. |
|
1604 |
aHeaderLength += iMimeHeaders->ContentLocation().Length(); |
|
1605 |
aHeaderLength += 1; // terminating zero |
|
1606 |
} |
|
1607 |
||
1608 |
// Content-ID |
|
1609 |
||
1610 |
if ( iMimeHeaders->ContentId().Length() > 0 ) |
|
1611 |
{ |
|
1612 |
aHeaderLength += 1; // encoding of header as short integer |
|
1613 |
// add terminating zero and preceding quote. |
|
1614 |
// (needed according to WSP 1.3) |
|
1615 |
aHeaderLength += iMimeHeaders->ContentId().Length() + KMms2; |
|
1616 |
if ( iMimeHeaders->ContentId().Find( KMmsLeftAngle ) != 0 ) |
|
1617 |
{ |
|
1618 |
aHeaderLength += KMms2; // we must add angle bracket |
|
1619 |
} |
|
1620 |
} |
|
1621 |
||
1622 |
// x-type parameters |
|
1623 |
// Must be stored as name/value pairs like content-type parameters |
|
1624 |
// X-parameter[i] = parameter name |
|
1625 |
// X-parameter[i+1] = parameter value |
|
1626 |
||
1627 |
for ( i = 0; i < iMimeHeaders->XTypeParams().MdcaCount(); ++i ) |
|
1628 |
{ |
|
1629 |
// If we have corrupted parameters (length of name is zero) |
|
1630 |
// we skip the name/value pair. |
|
1631 |
// value may be zero, it will be encoded as just the terminating zero |
|
1632 |
if ( i%2 == 0 && |
|
1633 |
( iMimeHeaders->XTypeParams().MdcaPoint( i ).Length() == 0 || |
|
1634 |
iMimeHeaders->XTypeParams().MdcaPoint( i ).CompareF( |
|
1635 |
KMmsSeparateDeliveryOmaXHeader ) == 0 ) ) |
|
1636 |
{ |
|
1637 |
// We skip the header and its value if |
|
1638 |
// a) the header length is 0 |
|
1639 |
// b) the header is X-Oma-Drm-Separate-Delivery |
|
1640 |
i++; |
|
1641 |
} |
|
1642 |
else |
|
1643 |
{ |
|
1644 |
aHeaderLength += iMimeHeaders->XTypeParams().MdcaPoint( i ).Length() + 1; |
|
1645 |
} |
|
1646 |
} |
|
1647 |
if ( ( iMimeHeaders->XTypeParams().MdcaCount() % 2 ) == 1 ) |
|
1648 |
{ |
|
1649 |
// Odd number. Obviously last parameter has no value. |
|
1650 |
// Add the "no value" token |
|
1651 |
aHeaderLength++; |
|
1652 |
} |
|
1653 |
||
1654 |
// THESE ARE NOT IMPLEMENTED |
|
1655 |
||
1656 |
// Content-disposition & parameters |
|
1657 |
// Content-description |
|
1658 |
// Content-base |
|
1659 |
// Relative path |
|
1660 |
// version |
|
1661 |
||
1662 |
#ifdef CONTENT_DISPOSITION_TEST |
|
1663 |
// not supported |
|
1664 |
||
1665 |
// We generate a general header for content disposition |
|
1666 |
// for tests we use the actual filename. |
|
1667 |
// In real life the user's filename should not be |
|
1668 |
// sent out to the world |
|
1669 |
||
1670 |
// Fixed coding: |
|
1671 |
// Content Disposition, value length, attachment, filename, |
|
1672 |
// actual filename + terminating 0 |
|
1673 |
||
1674 |
// attachment, filename, terminating zero |
|
1675 |
// content disposition should be text-string, not quoted text string |
|
1676 |
TInt contentDispositionLength = KMms3 + nameLength; |
|
1677 |
||
1678 |
TInt valueLengthLength = 1; |
|
1679 |
if ( contentDispositionLength > KMms30 ) |
|
1680 |
{ |
|
1681 |
// lengths 0 - 30 are encoded using "short length" |
|
1682 |
valueLengthLength++; |
|
1683 |
// |
|
1684 |
if ( contentDispositionLength > ShortIntegerLimit127 ) |
|
1685 |
{ |
|
1686 |
valueLengthLength++; |
|
1687 |
} |
|
1688 |
// Should never be longer than this. |
|
1689 |
// I don't think anybody has a filename that is longer than 16383 bytes. |
|
1690 |
} |
|
1691 |
||
1692 |
aHeaderLength += valueLengthLength + contentDispositionLength + 1; |
|
1693 |
#endif |
|
1694 |
||
1695 |
CleanupStack::Pop( buf8 ); |
|
1696 |
return buf8; // caller will delete this afterwards |
|
1697 |
||
1698 |
} |
|
1699 |
||
1700 |
// --------------------------------------------------------- |
|
1701 |
// |
|
1702 |
// --------------------------------------------------------- |
|
1703 |
// |
|
1704 |
void CMmsEncode::EncodeAttachmentHeadersL( |
|
1705 |
TUint aSize, |
|
1706 |
TUint aHeaderSize, |
|
1707 |
TBool aFoundName, |
|
1708 |
TUint aContentTypeSize, |
|
1709 |
TInt8 aContentType, |
|
1710 |
TPtrC8& aContentTypeString, |
|
1711 |
TPtrC8& aNameString ) |
|
1712 |
{ |
|
1713 |
||
1714 |
EncodeUintvar( aHeaderSize ); |
|
1715 |
||
1716 |
EncodeUintvar( aSize ); |
|
1717 |
||
1718 |
TUint8 temp = 0; // used to set the high bit for integers |
|
1719 |
||
1720 |
// if we have character set (or other parameters), |
|
1721 |
// we must use general encoding |
|
1722 |
||
1723 |
EncodeValueLength( aContentTypeSize ); |
|
1724 |
||
1725 |
if ( aContentType >= 0 ) |
|
1726 |
{ |
|
1727 |
temp = aContentType | KMms0x80; |
|
1728 |
iEncodeBuffer->Write( iPosition, &temp, 1 ); |
|
1729 |
iPosition++; |
|
1730 |
} |
|
1731 |
else |
|
1732 |
{ |
|
1733 |
// we assume this is a safe string |
|
1734 |
EncodeTextString( aContentTypeString ); |
|
1735 |
} |
|
1736 |
||
1737 |
// Then content type parameters. Mainly character set, |
|
1738 |
// but maybe something else, too |
|
1739 |
||
1740 |
temp = KWspCharset | KMms0x80; // encode as short integer |
|
1741 |
EncodeOptionalInteger( temp, iMimeHeaders->MimeCharset() ); |
|
1742 |
||
1743 |
// if we didn't find "Name" parameter among our parameters, we |
|
1744 |
// put it first. |
|
1745 |
||
1746 |
// we need the name later anyway... |
|
1747 |
||
1748 |
if ( !aFoundName ) |
|
1749 |
{ |
|
1750 |
temp = KWspName | KMms0x80; // encode as short integer |
|
1751 |
EncodeHeaderAndTextString( temp, aNameString ); |
|
1752 |
} |
|
1753 |
||
1754 |
// Then the rest of content type parameters, just text strings. |
|
1755 |
||
1756 |
TInt i = 0; |
|
1757 |
||
1758 |
for ( i = 0; i < iMimeHeaders->ContentTypeParams().MdcaCount(); ++i ) |
|
1759 |
{ |
|
1760 |
// If we have corrupted parameters (length of name is zero) |
|
1761 |
// we skip the name/value pair. |
|
1762 |
// value may be zero, it will be encoded as just the terminating zero |
|
1763 |
if ( i%2 == 0 && |
|
1764 |
iMimeHeaders->ContentTypeParams().MdcaPoint( i ).Length() == 0 ) |
|
1765 |
{ |
|
1766 |
i++; |
|
1767 |
} |
|
1768 |
else |
|
1769 |
{ |
|
1770 |
// 8-byte string + terminating zero |
|
1771 |
// If parameter has no value, it still must have |
|
1772 |
// the "no-value" indicator (just the terminating zero.) |
|
1773 |
// The ContentTypeParameters function provides |
|
1774 |
// an empty string in this case. |
|
1775 |
if ( iMimeHeaders->ContentTypeParams().MdcaPoint( i ).CompareF( |
|
1776 |
KWspNameString ) == 0 && i%2 == 0 ) |
|
1777 |
{ |
|
1778 |
if ( aFoundName ) |
|
1779 |
{ |
|
1780 |
temp = KWspName | KMms0x80; // encode as short integer |
|
1781 |
iEncodeBuffer->Write( iPosition, &temp, 1 ); |
|
1782 |
iPosition++; |
|
1783 |
} |
|
1784 |
else |
|
1785 |
{ |
|
1786 |
// we can use name from mime headers only if it is "safe" |
|
1787 |
// (contains only us-ascii characters) |
|
1788 |
// If the name is not safe, the parameter value is skipped |
|
1789 |
i++; |
|
1790 |
} |
|
1791 |
} |
|
1792 |
else |
|
1793 |
{ |
|
1794 |
EncodeTextString( |
|
1795 |
iMimeHeaders->ContentTypeParams().MdcaPoint( i ) ); |
|
1796 |
} |
|
1797 |
} |
|
1798 |
} |
|
1799 |
if ( ( iMimeHeaders->ContentTypeParams().MdcaCount() % 2 ) == 1 ) |
|
1800 |
{ |
|
1801 |
// Odd number. Obviously last parameter has no value. |
|
1802 |
// Add the "no value" token |
|
1803 |
iEncodeBuffer->Write( iPosition, &KMmsNull, 1 ); |
|
1804 |
iPosition++; |
|
1805 |
} |
|
1806 |
||
1807 |
// content-location |
|
1808 |
temp = KWspContentLocation | KMms0x80; // encode as short integer |
|
1809 |
EncodeOptionalStringL( temp, iMimeHeaders->ContentLocation() ); |
|
1810 |
||
1811 |
// content-id |
|
1812 |
if ( iMimeHeaders->ContentId().Length() > 0 ) |
|
1813 |
{ |
|
1814 |
HBufC8* tempContentId = HBufC8::NewL( iMimeHeaders->ContentId().Length() + KMms2 ); |
|
1815 |
CleanupStack::PushL( tempContentId ); |
|
1816 |
if ( iMimeHeaders->ContentId().Find( KMmsLeftAngle ) != 0 ) |
|
1817 |
{ |
|
1818 |
tempContentId->Des().Copy( KMmsLeftAngle ); |
|
1819 |
tempContentId->Des().Append( iMimeHeaders->ContentId() ); |
|
1820 |
tempContentId->Des().Append( KMmsRightAngle ); |
|
1821 |
} |
|
1822 |
else |
|
1823 |
{ |
|
1824 |
tempContentId->Des().Copy( iMimeHeaders->ContentId() ); |
|
1825 |
} |
|
1826 |
temp = KWspContentId | KMms0x80; // encode as short integer |
|
1827 |
iEncodeBuffer->Write( iPosition, &temp, 1 ); |
|
1828 |
iPosition++; |
|
1829 |
EncodeQuotedTextString( tempContentId->Des() ); |
|
1830 |
CleanupStack::PopAndDestroy( tempContentId ); |
|
1831 |
} |
|
1832 |
||
1833 |
#ifdef CONTENT_DISPOSITION_TEST |
|
1834 |
// not supported |
|
1835 |
temp = 0x2E | KMms0x80; // content disposition |
|
1836 |
iEncodeBuffer->Write( iPosition, &temp, 1 ); |
|
1837 |
iPosition++; |
|
1838 |
EncodeValueLength( contentDispositionLength ); |
|
1839 |
temp = 0x81; // attachment |
|
1840 |
iEncodeBuffer->Write( iPosition, &temp, 1 ); |
|
1841 |
iPosition++; |
|
1842 |
temp = 0x06 | KMms0x80; // filename |
|
1843 |
// filename should be text-string, not quoted |
|
1844 |
EncodeHeaderAndTextString( temp, buf8->Des() ); |
|
1845 |
#endif |
|
1846 |
||
1847 |
// x-type parameters |
|
1848 |
for ( i = 0; i < iMimeHeaders->XTypeParams().MdcaCount(); ++i ) |
|
1849 |
{ |
|
1850 |
// If we have corrupted parameters (length of name is zero) |
|
1851 |
// we skip the name/value pair. |
|
1852 |
// value may be zero, it will be encoded as just the terminating zero |
|
1853 |
if ( i%2 == 0 && |
|
1854 |
( iMimeHeaders->XTypeParams().MdcaPoint( i ).Length() == 0 || |
|
1855 |
iMimeHeaders->XTypeParams().MdcaPoint( i ).CompareF( |
|
1856 |
KMmsSeparateDeliveryOmaXHeader ) == 0 ) ) |
|
1857 |
{ |
|
1858 |
// We skip the header and its value if |
|
1859 |
// a) the header length is 0 |
|
1860 |
// b) the header is X-Oma-Drm-Separate-Delivery |
|
1861 |
i++; |
|
1862 |
} |
|
1863 |
else |
|
1864 |
{ |
|
1865 |
// 8-byte string + terminating zero |
|
1866 |
// If parameter has no value, it still must have |
|
1867 |
// the "no-value" indicator (just the terminating zero.) |
|
1868 |
// The ContentTypeParameters function provides |
|
1869 |
// an empty string in this case. |
|
1870 |
EncodeTextString( iMimeHeaders->XTypeParams().MdcaPoint( i ) ); |
|
1871 |
} |
|
1872 |
} |
|
1873 |
if ( ( iMimeHeaders->XTypeParams().MdcaCount() % 2 ) == 1 ) |
|
1874 |
{ |
|
1875 |
// Odd number. Obviously last parameter has no value. |
|
1876 |
// Add the "no value" token |
|
1877 |
iEncodeBuffer->Write( iPosition, &KMmsNull, 1 ); |
|
1878 |
iPosition++; |
|
1879 |
} |
|
1880 |
||
1881 |
// End of MIME headers |
|
1882 |
||
1883 |
} |
|
1884 |
||
1885 |
// --------------------------------------------------------- |
|
1886 |
// |
|
1887 |
// --------------------------------------------------------- |
|
1888 |
// |
|
1889 |
void CMmsEncode::EncodeAttachmentData( RFile& aAttachFile, TInt aSize ) |
|
1890 |
{ |
|
1891 |
// read the attachment file |
|
1892 |
// set up a pointer to point to iEncodeBuffer at iPosition |
|
1893 |
TPtr8 pos = iEncodeBuffer->Ptr( iPosition ); |
|
1894 |
// Attachemnt may be a file attacment or a linked file. |
|
1895 |
// The file pointer will point to unread part if file is read in chunks |
|
1896 |
iError = aAttachFile.Read( pos, aSize ); |
|
1897 |
} |
|
1898 |
||
1899 |
||
1900 |
// --------------------------------------------------------- |
|
1901 |
// |
|
1902 |
// --------------------------------------------------------- |
|
1903 |
// |
|
1904 |
void CMmsEncode::FinishL() |
|
1905 |
{ |
|
1906 |
||
1907 |
// Remove slack to keep garbage out from the end of the file |
|
1908 |
iEncodeBuffer->ResizeL( iPosition ); |
|
1909 |
iOverallDataSize = iEncodeBuffer->Size(); |
|
1910 |
iState = EMmsIdle; |
|
1911 |
||
1912 |
// Dump the buffer contents into file if requested |
|
1913 |
Dump(); |
|
1914 |
||
1915 |
} |
|
1916 |
||
1917 |
// --------------------------------------------------------- |
|
1918 |
// |
|
1919 |
// --------------------------------------------------------- |
|
1920 |
// |
|
1921 |
void CMmsEncode::EncodeRequestHeadersL() |
|
1922 |
{ |
|
1923 |
// encode message depending on type |
|
1924 |
switch ( iMmsHeaders->MessageType() ) |
|
1925 |
{ |
|
1926 |
// KMmsMessageTypeMNotifyRespInd and KMmsMessageTypeAcknowledgeInd and all other PDUs |
|
1927 |
// that contain only headers and no data should be handled by |
|
1928 |
// using function |
|
1929 |
// EncodeHeadersL(CMmsHeaders& aMmsHeaders,CBufFlat& aEncodeBuffer) |
|
1930 |
case KMmsMessageTypeMSendReq: |
|
1931 |
EncodeSendRequestHeadersL(); |
|
1932 |
break; |
|
1933 |
case KMmsMessageTypeMBoxUploadReq: |
|
1934 |
// This type has attachments and headers |
|
1935 |
EncodeMMBoxUploadRequestL(); |
|
1936 |
break; |
|
1937 |
case KMmsMessageTypeMRetrieveConf: |
|
1938 |
// for test purposes |
|
1939 |
EncodeRetrieveConfirmationL(); |
|
1940 |
break; |
|
1941 |
case KMmsMessageTypeMboxViewConf: |
|
1942 |
// for test purposes |
|
1943 |
EncodeMMBoxViewConfirmationL(); |
|
1944 |
break; |
|
1945 |
case KMmsMessageTypeMBoxDescr: |
|
1946 |
// for test purposes |
|
1947 |
EncodeMMBoxDescriptionL(); |
|
1948 |
break; |
|
1949 |
default: |
|
1950 |
iError = KMmsErrorUnknownMessageType; |
|
1951 |
break; |
|
1952 |
} |
|
1953 |
} |
|
1954 |
||
1955 |
// --------------------------------------------------------- |
|
1956 |
// |
|
1957 |
// --------------------------------------------------------- |
|
1958 |
// |
|
1959 |
void CMmsEncode::EncodeSendRequestHeadersL() |
|
1960 |
{ |
|
1961 |
||
1962 |
// Insert message type, TID and version number |
|
1963 |
EncodeStartingHeaders( KMmsMessageTypeMSendReq, |
|
1964 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
1965 |
||
1966 |
// if we have set a date, insert it |
|
1967 |
EncodeDate( iMmsHeaders->Date() ); |
|
1968 |
||
1969 |
// If we have set the sender, encode it |
|
1970 |
// If not, we ask MMSC to add the sender |
|
1971 |
EncodeSenderL( iMmsHeaders->Sender() ); |
|
1972 |
||
1973 |
// All recipient lists. If no recipients in some of the lists, |
|
1974 |
// nothing is encoded, no need to check separately |
|
1975 |
EncodeRecipientL( iMmsHeaders->ToRecipients(), EMmsTo ); |
|
1976 |
EncodeRecipientL( iMmsHeaders->CcRecipients(), EMmsCc ); |
|
1977 |
EncodeRecipientL( iMmsHeaders->BccRecipients(), EMmsBcc ); |
|
1978 |
||
1979 |
// Subject |
|
1980 |
EncodeOptionalStringL( KMmsAssignedSubject, iMmsHeaders->Subject() ); |
|
1981 |
||
1982 |
// Message class |
|
1983 |
EncodeOptionalByte( KMmsAssignedMessageClass, |
|
1984 |
iMmsHeaders->MessageClass() ); |
|
1985 |
||
1986 |
// Expiration time |
|
1987 |
EncodeOptionalIntervalOrDate( KMmsAssignedExpiry, |
|
1988 |
iMmsHeaders->ExpiryInterval(), |
|
1989 |
iMmsHeaders->ExpiryDate() ); |
|
1990 |
||
1991 |
// Delivery time |
|
1992 |
EncodeOptionalIntervalOrDate( KMmsAssignedDeliveryTime, |
|
1993 |
iMmsHeaders->DeliveryTimeInterval(), |
|
1994 |
iMmsHeaders->DeliveryDate() ); |
|
1995 |
||
1996 |
// Priority |
|
1997 |
EncodeOptionalByte( KMmsAssignedPriority, iMmsHeaders->MessagePriority() ); |
|
1998 |
||
1999 |
// Sender visibility |
|
2000 |
EncodeOptionalByte( KMmsAssignedSenderVisibility, |
|
2001 |
iMmsHeaders->SenderVisibility() ); |
|
2002 |
||
2003 |
// Delivery report |
|
2004 |
EncodeOptionalByte( KMmsAssignedDeliveryReport, |
|
2005 |
iMmsHeaders->DeliveryReport() ); |
|
2006 |
||
2007 |
// Read reply |
|
2008 |
EncodeOptionalByte( KMmsAssignedReadReply, iMmsHeaders->ReadReply() ); |
|
2009 |
||
2010 |
// MMS encapsulation 1.1 headers - optional |
|
2011 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion1 ) |
|
2012 |
{ |
|
2013 |
// Do we want to specify reply charging |
|
2014 |
if ( iMmsHeaders->ReplyCharging() == KMmsReplyChargingRequested || |
|
2015 |
iMmsHeaders->ReplyCharging() == KMmsReplyChargingRequestedTextOnly ) |
|
2016 |
{ |
|
2017 |
// Reply charging value |
|
2018 |
EncodeOptionalByte( KMmsAssignedReplyCharging, |
|
2019 |
iMmsHeaders->ReplyCharging() ); |
|
2020 |
// Reply charging deadline |
|
2021 |
EncodeOptionalIntervalOrDate( KMmsAssignedReplyChargingDeadline, |
|
2022 |
iMmsHeaders->ReplyChargingInterval(), |
|
2023 |
iMmsHeaders->ReplyChargingDate() ); |
|
2024 |
// Reply charging size |
|
2025 |
EncodeReplyChargingSize( iMmsHeaders->ReplyChargingSize() ); |
|
2026 |
} |
|
2027 |
// Reply charging ID |
|
2028 |
EncodeOptionalString( KMmsAssignedReplyChargingID, |
|
2029 |
iMmsHeaders->ReplyChargingId() ); |
|
2030 |
} |
|
2031 |
||
2032 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion11 ) |
|
2033 |
{ |
|
2034 |
// MMBox related headers - optional |
|
2035 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2036 |
{ |
|
2037 |
// X-Mms-MM-Store |
|
2038 |
EncodeOptionalByte( KMmsAssignedMmsStore, |
|
2039 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsStore() ); |
|
2040 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsStore() == KMmsYes ) |
|
2041 |
{ |
|
2042 |
// X-Mms-MM-State |
|
2043 |
EncodeOptionalByte( KMmsAssignedMMState, |
|
2044 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsMMState() ); |
|
2045 |
// X-MMs-MM-Flags |
|
2046 |
// The keyword token should always be "add" or "remove" |
|
2047 |
EncodeKeywordArrayL(); |
|
2048 |
} |
|
2049 |
} |
|
2050 |
} |
|
2051 |
||
2052 |
// Add encapsulation version 1.3 headers - optional |
|
2053 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion12 ) |
|
2054 |
{ |
|
2055 |
// X-Mms-Applic-ID, X-Mms-Reply-Applic-ID and X-Mms-Aux-Applic-Info |
|
2056 |
EncodeApplicationHeadersL(); |
|
2057 |
// X-Mms-Content-Class |
|
2058 |
EncodeOptionalByte( KMmsAssignedContentClass, iMmsHeaders->ContentClass() ); |
|
2059 |
// X-Mms-DRM-Content |
|
2060 |
EncodeOptionalByte( KMmsAssignedDrmContent, iMmsHeaders->DrmContent() ); |
|
2061 |
// X-Mms-Adaptation-Allowed |
|
2062 |
EncodeOptionalByte( KMmsAssignedAdaptationAllowed, iMmsHeaders->AdaptationAllowed() ); |
|
2063 |
} |
|
2064 |
||
2065 |
// Get Root TMsvId from headers if set |
|
2066 |
TMsvAttachmentId rootId = iMmsHeaders->MessageRoot(); |
|
2067 |
||
2068 |
TInt error = KErrNone; |
|
2069 |
// If we are handling headers only, we may not have iEntryWrapper |
|
2070 |
if ( iEntryWrapper ) |
|
2071 |
{ |
|
2072 |
CMsvStore* store = iEntryWrapper->ReadStoreL(); |
|
2073 |
CleanupStack::PushL( store ); |
|
2074 |
MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
2075 |
TRAP( error, |
|
2076 |
{ |
|
2077 |
CMsvAttachment* attachmentInfo = attachMan.GetAttachmentInfoL( |
|
2078 |
(TMsvAttachmentId) rootId ); |
|
2079 |
delete attachmentInfo; // we just wanted to check that it was found |
|
2080 |
} |
|
2081 |
); |
|
2082 |
CleanupStack::PopAndDestroy( store ); |
|
2083 |
} |
|
2084 |
||
2085 |
// If we have a valid root part, we send the message as multipart/related. |
|
2086 |
// Otherwise we send it as multipart mixed. |
|
2087 |
// We don't try to guess what the root is supposed to be, if it |
|
2088 |
// is not specified or does not point to an existing attachment. |
|
2089 |
||
2090 |
if ( error == KErrNone && rootId != 0 && iEntryWrapper ) |
|
2091 |
{ |
|
2092 |
EncodeMultipartRelatedHeaderL( rootId ); |
|
2093 |
} |
|
2094 |
else |
|
2095 |
{ |
|
2096 |
EncodeMultipartMixedHeaderL(); |
|
2097 |
} |
|
2098 |
||
2099 |
} |
|
2100 |
||
2101 |
// --------------------------------------------------------- |
|
2102 |
// |
|
2103 |
// --------------------------------------------------------- |
|
2104 |
// |
|
2105 |
void CMmsEncode::EncodeNotifyResponse() |
|
2106 |
{ |
|
2107 |
||
2108 |
// version may be current version or 1.0 |
|
2109 |
// Only byte is used. iMmsHeaders controls the value. |
|
2110 |
||
2111 |
// Insert message type, TID and version number |
|
2112 |
EncodeStartingHeaders( KMmsMessageTypeMNotifyRespInd, iMmsHeaders->Tid(), |
|
2113 |
iMmsHeaders->MmsVersion() ); |
|
2114 |
||
2115 |
// insert message status |
|
2116 |
EncodeMandatoryByte( KMmsAssignedStatus, iMmsHeaders->Status() ); |
|
2117 |
||
2118 |
// insert report allowed if present |
|
2119 |
EncodeOptionalByte( KMmsAssignedReportAllowed, |
|
2120 |
iMmsHeaders->ReportAllowed() ); |
|
2121 |
||
2122 |
} |
|
2123 |
||
2124 |
// --------------------------------------------------------- |
|
2125 |
// |
|
2126 |
// --------------------------------------------------------- |
|
2127 |
// |
|
2128 |
void CMmsEncode::EncodeAcknowledgeIndication() |
|
2129 |
{ |
|
2130 |
// Insert message type, TID and version number |
|
2131 |
EncodeStartingHeaders( KMmsMessageTypeAcknowledgeInd, |
|
2132 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
2133 |
||
2134 |
// insert report allowed if present |
|
2135 |
EncodeOptionalByte( KMmsAssignedReportAllowed, |
|
2136 |
iMmsHeaders->ReportAllowed() ); |
|
2137 |
} |
|
2138 |
||
2139 |
// --------------------------------------------------------- |
|
2140 |
// |
|
2141 |
// --------------------------------------------------------- |
|
2142 |
// |
|
2143 |
void CMmsEncode::EncodeMmsNotificationL() |
|
2144 |
{ |
|
2145 |
||
2146 |
// Insert message type, TID and version number |
|
2147 |
EncodeStartingHeaders( KMmsMessageTypeMNotificationInd, |
|
2148 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
2149 |
||
2150 |
// for notification sender is optional - added only if it is known |
|
2151 |
if ( iMmsHeaders->Sender().Length() > 0 ) |
|
2152 |
{ |
|
2153 |
EncodeSenderL( iMmsHeaders->Sender() ); |
|
2154 |
} |
|
2155 |
||
2156 |
EncodeOptionalStringL( KMmsAssignedSubject, iMmsHeaders->Subject() ); |
|
2157 |
||
2158 |
EncodeOptionalByte( KMmsAssignedDeliveryReport, |
|
2159 |
iMmsHeaders->DeliveryReport() ); |
|
2160 |
||
2161 |
EncodeOptionalByte( KMmsAssignedMessageClass, |
|
2162 |
iMmsHeaders->MessageClass() ); |
|
2163 |
||
2164 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedMessageSize, 1 ); |
|
2165 |
iPosition++; |
|
2166 |
||
2167 |
TInt64 size = iMmsHeaders->MessageSize(); |
|
2168 |
EncodeLongInteger( size ); |
|
2169 |
||
2170 |
EncodeOptionalIntervalOrDate( KMmsAssignedExpiry, |
|
2171 |
iMmsHeaders->ExpiryInterval(), |
|
2172 |
iMmsHeaders->ExpiryDate() ); |
|
2173 |
||
2174 |
// version 1.1 fields - optional |
|
2175 |
// reply-charging |
|
2176 |
// reply-charging deadline |
|
2177 |
// reply-charging size |
|
2178 |
// reply-charging ID |
|
2179 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion1 ) |
|
2180 |
{ |
|
2181 |
// Do we want to specify |
|
2182 |
if ( iMmsHeaders->ReplyCharging() == KMmsReplyChargingAccepted || |
|
2183 |
iMmsHeaders->ReplyCharging() == KMmsReplyChargingAcceptedTextOnly ) |
|
2184 |
{ |
|
2185 |
// Reply charging value |
|
2186 |
EncodeOptionalByte( KMmsAssignedReplyCharging, |
|
2187 |
iMmsHeaders->ReplyCharging() ); |
|
2188 |
// Reply charging deadline |
|
2189 |
EncodeOptionalIntervalOrDate( KMmsAssignedReplyChargingDeadline, |
|
2190 |
iMmsHeaders->ReplyChargingInterval(), |
|
2191 |
iMmsHeaders->ReplyChargingDate() ); |
|
2192 |
// Reply charging size |
|
2193 |
EncodeReplyChargingSize( iMmsHeaders->ReplyChargingSize() ); |
|
2194 |
} |
|
2195 |
// if this is a reply, we may specify the ID |
|
2196 |
// Reply charging ID |
|
2197 |
EncodeOptionalString( KMmsAssignedReplyChargingID, |
|
2198 |
iMmsHeaders->ReplyChargingId() ); |
|
2199 |
} |
|
2200 |
||
2201 |
// version 1.2 headers - optional |
|
2202 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion11 ) |
|
2203 |
{ |
|
2204 |
// MMBox headers |
|
2205 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2206 |
{ |
|
2207 |
EncodeOptionalByte( KMmsAssignedStored, |
|
2208 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsStored() ); |
|
2209 |
} |
|
2210 |
||
2211 |
// Distribution indicator |
|
2212 |
EncodeOptionalByte( KMmsAssignedDistributionIndicator, |
|
2213 |
iMmsHeaders->DistributionIndicator() ); |
|
2214 |
} |
|
2215 |
||
2216 |
// Element descriptor |
|
2217 |
// This is somewhat a mystery - not implemented |
|
2218 |
||
2219 |
// version 1.3 headers - optional |
|
2220 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion12 ) |
|
2221 |
{ |
|
2222 |
// X-Mms-Applic-ID, X-Mms-Reply-Applic-ID and X-Mms-Aux-Applic-Info |
|
2223 |
EncodeApplicationHeadersL(); |
|
2224 |
// X-Mms-Recommended-Retrieval-Mode |
|
2225 |
EncodeOptionalByte( KMmsAssignedRecommendedRetrievalMode, |
|
2226 |
iMmsHeaders->RecommendedRetrievalMode() ); |
|
2227 |
// X-Mms-Recommended-Retrieval-Mode-Text |
|
2228 |
EncodeOptionalStringL( KMmsAssignedRecommendedRetrievalModeText, |
|
2229 |
iMmsHeaders->RecommendedRetrievalModeText() ); |
|
2230 |
// X-Mms-Content-Class |
|
2231 |
EncodeOptionalByte( KMmsAssignedContentClass, iMmsHeaders->ContentClass() ); |
|
2232 |
// X-Mms-DRM-Content |
|
2233 |
EncodeOptionalByte( KMmsAssignedDrmContent, iMmsHeaders->DrmContent() ); |
|
2234 |
// X-Mms-Replace-ID |
|
2235 |
EncodeOptionalString( KMmsAssignedReplaceId, iMmsHeaders->ReplaceCancelId() ); |
|
2236 |
} |
|
2237 |
||
2238 |
// We keep this as the last one, though it does not really matter |
|
2239 |
// Mandatory content-location |
|
2240 |
// this must be USASCII or URL encoded |
|
2241 |
EncodeHeaderAndTextString( KMmsAssignedContentLocation, |
|
2242 |
iMmsHeaders->ContentLocation() ); |
|
2243 |
||
2244 |
} |
|
2245 |
||
2246 |
// --------------------------------------------------------- |
|
2247 |
// |
|
2248 |
// --------------------------------------------------------- |
|
2249 |
// |
|
2250 |
void CMmsEncode::EncodeSendConfirmationL() |
|
2251 |
{ |
|
2252 |
// implemented for test purposes |
|
2253 |
#ifdef __WINS__ |
|
2254 |
// Insert message type, TID and version number |
|
2255 |
EncodeStartingHeaders( KMmsMessageTypeMSendConf, |
|
2256 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
2257 |
||
2258 |
EncodeMandatoryByte( KMmsAssignedResponseStatus, |
|
2259 |
iMmsHeaders->ResponseStatus() ); |
|
2260 |
||
2261 |
EncodeOptionalStringL( KMmsAssignedResponseText, |
|
2262 |
iMmsHeaders->ResponseText() ); |
|
2263 |
||
2264 |
// if send confirmation returns error, it might not contain message id |
|
2265 |
EncodeOptionalString( KMmsAssignedMessageId, iMmsHeaders->MessageId() ); |
|
2266 |
||
2267 |
// MMBox related headers - optional |
|
2268 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2269 |
{ |
|
2270 |
EncodeOptionalByte( KMmsAssignedStoreStatus, |
|
2271 |
iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatus() ); |
|
2272 |
EncodeOptionalStringL( KMmsAssignedStoreStatusText, |
|
2273 |
iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatusText() ); |
|
2274 |
if ( iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatus() == |
|
2275 |
KMmsStatusOk ) |
|
2276 |
{ |
|
2277 |
// this must be USASCII or URL encoded |
|
2278 |
// If message was stored to MMBox, this is mandatory |
|
2279 |
EncodeHeaderAndTextString( KMmsAssignedContentLocation, |
|
2280 |
iMmsHeaders->ContentLocation() ); |
|
2281 |
} |
|
2282 |
} |
|
2283 |
||
2284 |
#endif |
|
2285 |
||
2286 |
} |
|
2287 |
||
2288 |
// --------------------------------------------------------- |
|
2289 |
// |
|
2290 |
// --------------------------------------------------------- |
|
2291 |
// |
|
2292 |
void CMmsEncode::EncodeRetrieveConfirmationL() |
|
2293 |
{ |
|
2294 |
// implemented for test purposes |
|
2295 |
#ifdef __WINS__ |
|
2296 |
||
2297 |
// Insert message type, TID and version number |
|
2298 |
EncodeStartingHeaders( KMmsMessageTypeMRetrieveConf, |
|
2299 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
2300 |
||
2301 |
// message id |
|
2302 |
EncodeOptionalString( KMmsAssignedMessageId, iMmsHeaders->MessageId() ); |
|
2303 |
||
2304 |
// if we have set a date, insert it |
|
2305 |
EncodeDate( iMmsHeaders->Date() ); |
|
2306 |
||
2307 |
// If we have set the sender, encode it |
|
2308 |
if ( iMmsHeaders->Sender().Length() > 0 ) |
|
2309 |
{ |
|
2310 |
EncodeSenderL( iMmsHeaders->Sender() ); |
|
2311 |
} |
|
2312 |
||
2313 |
// previously sent by array |
|
2314 |
TInt i; |
|
2315 |
TUint oldPosition; |
|
2316 |
TUint length; |
|
2317 |
for ( i = 0; i < iMmsHeaders->PreviouslySentList().Count(); ++i ) |
|
2318 |
{ |
|
2319 |
oldPosition = iPosition; |
|
2320 |
length = 0; |
|
2321 |
// Encode once just to find out filed length |
|
2322 |
EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() ); |
|
2323 |
EncodeAddressL( iMmsHeaders->PreviouslySentList()[i]->Sender() ); |
|
2324 |
length += iPosition - oldPosition; |
|
2325 |
iPosition = oldPosition; |
|
2326 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedPreviouslySentBy, 1 ); |
|
2327 |
iPosition++; |
|
2328 |
EncodeValueLength( length ); |
|
2329 |
// now we have added length, do the actual encoding |
|
2330 |
EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() ); |
|
2331 |
EncodeAddressL( iMmsHeaders->PreviouslySentList()[i]->Sender() ); |
|
2332 |
oldPosition = iPosition; |
|
2333 |
length = 0; |
|
2334 |
EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() ); |
|
2335 |
EncodeLongInteger( iMmsHeaders->PreviouslySentList()[i]->Date() ); |
|
2336 |
length += iPosition - oldPosition; |
|
2337 |
iPosition = oldPosition; |
|
2338 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedPreviouslySentDate, 1 ); |
|
2339 |
iPosition++; |
|
2340 |
EncodeValueLength( length ); |
|
2341 |
EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() ); |
|
2342 |
EncodeLongInteger( iMmsHeaders->PreviouslySentList()[i]->Date() ); |
|
2343 |
} |
|
2344 |
||
2345 |
// All recipient lists. If no recipients in some of the lists, |
|
2346 |
// nothing is encoded, no need to check separately |
|
2347 |
EncodeRecipientL( iMmsHeaders->ToRecipients(), EMmsTo ); |
|
2348 |
EncodeRecipientL( iMmsHeaders->CcRecipients(), EMmsCc ); |
|
2349 |
// no Bcc in retrieve confirmation |
|
2350 |
||
2351 |
// Subject |
|
2352 |
EncodeOptionalStringL( KMmsAssignedSubject, iMmsHeaders->Subject() ); |
|
2353 |
||
2354 |
// MMBox headers |
|
2355 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2356 |
{ |
|
2357 |
// X-Mms-MM-State |
|
2358 |
EncodeOptionalByte( KMmsAssignedMMState, |
|
2359 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsMMState() ); |
|
2360 |
// X-MMs-MM-Flags |
|
2361 |
// The keyword token should always be "add" or "remove" |
|
2362 |
EncodeKeywordArrayL(); |
|
2363 |
} |
|
2364 |
||
2365 |
// Message class |
|
2366 |
EncodeOptionalByte( KMmsAssignedMessageClass, |
|
2367 |
iMmsHeaders->MessageClass() ); |
|
2368 |
||
2369 |
// Priority |
|
2370 |
EncodeOptionalByte( KMmsAssignedPriority, iMmsHeaders->MessagePriority() ); |
|
2371 |
||
2372 |
// Delivery report |
|
2373 |
EncodeOptionalByte( KMmsAssignedDeliveryReport, |
|
2374 |
iMmsHeaders->DeliveryReport() ); |
|
2375 |
||
2376 |
// Read reply |
|
2377 |
EncodeOptionalByte( KMmsAssignedReadReply, iMmsHeaders->ReadReply() ); |
|
2378 |
||
2379 |
// MMS encapsulation 1.1 headers - optional |
|
2380 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion1 ) |
|
2381 |
{ |
|
2382 |
// Do we want to specify reply charging |
|
2383 |
if ( iMmsHeaders->ReplyCharging() == KMmsReplyChargingAccepted || |
|
2384 |
iMmsHeaders->ReplyCharging() == KMmsReplyChargingAcceptedTextOnly ) |
|
2385 |
{ |
|
2386 |
// Reply charging value |
|
2387 |
EncodeOptionalByte( KMmsAssignedReplyCharging, |
|
2388 |
iMmsHeaders->ReplyCharging() ); |
|
2389 |
// Reply charging deadline |
|
2390 |
EncodeOptionalIntervalOrDate( KMmsAssignedReplyChargingDeadline, |
|
2391 |
iMmsHeaders->ReplyChargingInterval(), |
|
2392 |
iMmsHeaders->ReplyChargingDate() ); |
|
2393 |
// Reply charging size |
|
2394 |
EncodeReplyChargingSize( iMmsHeaders->ReplyChargingSize() ); |
|
2395 |
} |
|
2396 |
// Reply charging ID |
|
2397 |
EncodeOptionalString( KMmsAssignedReplyChargingID, |
|
2398 |
iMmsHeaders->ReplyChargingId() ); |
|
2399 |
// status of the operation |
|
2400 |
EncodeOptionalByte( KMmsAssignedRetrieveStatus, |
|
2401 |
iMmsHeaders->ResponseStatus() ); |
|
2402 |
||
2403 |
EncodeOptionalStringL( KMmsAssignedRetrieveText, |
|
2404 |
iMmsHeaders->ResponseText() ); |
|
2405 |
} |
|
2406 |
||
2407 |
// version 1.2 headers - optional |
|
2408 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion11 ) |
|
2409 |
{ |
|
2410 |
// Distribution indicator |
|
2411 |
EncodeOptionalByte( KMmsAssignedDistributionIndicator, |
|
2412 |
iMmsHeaders->DistributionIndicator() ); |
|
2413 |
} |
|
2414 |
||
2415 |
// version 1.3 headers - optional |
|
2416 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion12 ) |
|
2417 |
{ |
|
2418 |
// X-Mms-Applic-ID, X-Mms-Reply-Applic-ID and X-Mms-Aux-Applic-Info |
|
2419 |
EncodeApplicationHeadersL(); |
|
2420 |
// X-Mms-Content-Class |
|
2421 |
EncodeOptionalByte( KMmsAssignedContentClass, iMmsHeaders->ContentClass() ); |
|
2422 |
// X-Mms-DRM-Content |
|
2423 |
EncodeOptionalByte( KMmsAssignedDrmContent, iMmsHeaders->DrmContent() ); |
|
2424 |
// X-Mms-Replace-ID |
|
2425 |
EncodeOptionalString( KMmsAssignedReplaceId, iMmsHeaders->ReplaceCancelId() ); |
|
2426 |
} |
|
2427 |
||
2428 |
// Start pointer |
|
2429 |
TUint ii = 0; |
|
2430 |
// Get Root TMsvId from headers if set |
|
2431 |
TMsvId rootId = iMmsHeaders->MessageRoot(); |
|
2432 |
||
2433 |
TInt error = KErrNone; |
|
2434 |
if ( iEntryWrapper ) |
|
2435 |
{ |
|
2436 |
CMsvStore* store = iEntryWrapper->ReadStoreL(); |
|
2437 |
CleanupStack::PushL( store ); |
|
2438 |
MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
2439 |
TRAP( error, |
|
2440 |
{ |
|
2441 |
CMsvAttachment* attachmentInfo = attachMan.GetAttachmentInfoL( |
|
2442 |
(TMsvAttachmentId) rootId ); |
|
2443 |
delete attachmentInfo; // we just wanted to check that it was found |
|
2444 |
} |
|
2445 |
); |
|
2446 |
CleanupStack::PopAndDestroy( store ); |
|
2447 |
} |
|
2448 |
||
2449 |
// If we have a valid root part, we send the message as multipart/related. |
|
2450 |
// Otherwise we send it as multipart mixed. |
|
2451 |
// We don't try to guess what the root is supposed to be, if it |
|
2452 |
// is not specified or does not point to an existing attachment. |
|
2453 |
||
2454 |
if ( error == KErrNone && rootId != 0 && iEntryWrapper ) |
|
2455 |
{ |
|
2456 |
EncodeMultipartRelatedHeaderL( rootId ); |
|
2457 |
} |
|
2458 |
else |
|
2459 |
{ |
|
2460 |
EncodeMultipartMixedHeaderL(); |
|
2461 |
} |
|
2462 |
||
2463 |
||
2464 |
#endif |
|
2465 |
} |
|
2466 |
||
2467 |
// --------------------------------------------------------- |
|
2468 |
// |
|
2469 |
// --------------------------------------------------------- |
|
2470 |
// |
|
2471 |
void CMmsEncode::EncodeDeliveryReportL() |
|
2472 |
{ |
|
2473 |
// implemented for test purposes |
|
2474 |
#ifdef __WINS__ |
|
2475 |
||
2476 |
// Insert message type, TID and version number |
|
2477 |
EncodeStartingHeaders( KMmsMessageTypeDeliveryInd, TPtrC8(), |
|
2478 |
iMmsHeaders->MmsVersion() ); |
|
2479 |
||
2480 |
EncodeHeaderAndTextString( KMmsAssignedMessageId, |
|
2481 |
iMmsHeaders->MessageId() ); |
|
2482 |
||
2483 |
EncodeRecipientL( iMmsHeaders->ToRecipients(), EMmsTo ); |
|
2484 |
||
2485 |
// if we have set a date, insert it |
|
2486 |
EncodeDate( iMmsHeaders->Date() ); |
|
2487 |
||
2488 |
// insert message status |
|
2489 |
EncodeMandatoryByte( KMmsAssignedStatus, iMmsHeaders->Status() ); |
|
2490 |
||
2491 |
// version 1.3 headers - optional |
|
2492 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion12 ) |
|
2493 |
{ |
|
2494 |
// X-Mms-Status-Text |
|
2495 |
// Status text is stored in the same place as response text and retrieve |
|
2496 |
// text as only one of them can appear in any PDU |
|
2497 |
EncodeOptionalStringL( KMmsAssignedStatusText, |
|
2498 |
iMmsHeaders->ResponseText() ); |
|
2499 |
// X-Mms-Applic-ID, X-Mms-Reply-Applic-ID and X-Mms-Aux-Applic-Info |
|
2500 |
EncodeApplicationHeadersL(); |
|
2501 |
} |
|
2502 |
||
2503 |
#endif |
|
2504 |
} |
|
2505 |
||
2506 |
// --------------------------------------------------------- |
|
2507 |
// |
|
2508 |
// --------------------------------------------------------- |
|
2509 |
// |
|
2510 |
void CMmsEncode::EncodeForwardRequestL() |
|
2511 |
{ |
|
2512 |
// Insert message type, TID and version number |
|
2513 |
EncodeStartingHeaders( KMmsMessageTypeForwardReq, |
|
2514 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
2515 |
||
2516 |
// if we have set a date, insert it |
|
2517 |
EncodeDate( iMmsHeaders->Date() ); |
|
2518 |
||
2519 |
// If we have set the sender, encode it |
|
2520 |
// If not, we ask MMSC to add the sender |
|
2521 |
EncodeSenderL( iMmsHeaders->Sender() ); |
|
2522 |
||
2523 |
// All recipient lists. If no recipients in some of the lists, |
|
2524 |
// nothing is encoded, no need to check separately |
|
2525 |
EncodeRecipientL( iMmsHeaders->ToRecipients(), EMmsTo ); |
|
2526 |
EncodeRecipientL( iMmsHeaders->CcRecipients(), EMmsCc ); |
|
2527 |
EncodeRecipientL( iMmsHeaders->BccRecipients(), EMmsBcc ); |
|
2528 |
||
2529 |
// Expiration time |
|
2530 |
EncodeOptionalIntervalOrDate( KMmsAssignedExpiry, |
|
2531 |
iMmsHeaders->ExpiryInterval(), |
|
2532 |
iMmsHeaders->ExpiryDate() ); |
|
2533 |
||
2534 |
// Delivery time |
|
2535 |
EncodeOptionalIntervalOrDate( KMmsAssignedDeliveryTime, |
|
2536 |
iMmsHeaders->DeliveryTimeInterval(), |
|
2537 |
iMmsHeaders->DeliveryDate() ); |
|
2538 |
||
2539 |
// Delivery report allowed |
|
2540 |
EncodeOptionalByte( KMmsAssignedReportAllowed, |
|
2541 |
iMmsHeaders->ReportAllowed() ); |
|
2542 |
||
2543 |
// Delivery report |
|
2544 |
EncodeOptionalByte( KMmsAssignedDeliveryReport, |
|
2545 |
iMmsHeaders->DeliveryReport() ); |
|
2546 |
||
2547 |
// Read reply |
|
2548 |
EncodeOptionalByte( KMmsAssignedReadReply, iMmsHeaders->ReadReply() ); |
|
2549 |
||
2550 |
// version 1.2 headers - optional |
|
2551 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion11 ) |
|
2552 |
{ |
|
2553 |
// MMBox related headers - optional |
|
2554 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2555 |
{ |
|
2556 |
// X-Mms-MM-Store |
|
2557 |
EncodeOptionalByte( KMmsAssignedMmsStore, |
|
2558 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsStore() ); |
|
2559 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsStore() == KMmsYes || |
|
2560 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsStored() == KMmsYes ) |
|
2561 |
{ |
|
2562 |
// X-Mms-MM-State |
|
2563 |
EncodeOptionalByte( KMmsAssignedMMState, |
|
2564 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsMMState() ); |
|
2565 |
// X-MMs-MM-Flags |
|
2566 |
// The keyword token should always be "add" or "remove" |
|
2567 |
EncodeKeywordArrayL(); |
|
2568 |
} |
|
2569 |
} |
|
2570 |
} |
|
2571 |
||
2572 |
// version 1.3 headers - optional |
|
2573 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion12 ) |
|
2574 |
{ |
|
2575 |
// Do we want to specify reply charging |
|
2576 |
if ( iMmsHeaders->ReplyCharging() == KMmsReplyChargingRequested || |
|
2577 |
iMmsHeaders->ReplyCharging() == KMmsReplyChargingRequestedTextOnly ) |
|
2578 |
{ |
|
2579 |
// Reply charging value |
|
2580 |
EncodeOptionalByte( KMmsAssignedReplyCharging, |
|
2581 |
iMmsHeaders->ReplyCharging() ); |
|
2582 |
// Reply charging deadline |
|
2583 |
EncodeOptionalIntervalOrDate( KMmsAssignedReplyChargingDeadline, |
|
2584 |
iMmsHeaders->ReplyChargingInterval(), |
|
2585 |
iMmsHeaders->ReplyChargingDate() ); |
|
2586 |
// Reply charging size |
|
2587 |
EncodeReplyChargingSize( iMmsHeaders->ReplyChargingSize() ); |
|
2588 |
} |
|
2589 |
} |
|
2590 |
||
2591 |
// Mandatory content-location |
|
2592 |
// this must be USASCII or URL encoded |
|
2593 |
EncodeHeaderAndTextString( KMmsAssignedContentLocation, |
|
2594 |
iMmsHeaders->ContentLocation() ); |
|
2595 |
||
2596 |
} |
|
2597 |
||
2598 |
// --------------------------------------------------------- |
|
2599 |
// |
|
2600 |
// --------------------------------------------------------- |
|
2601 |
// |
|
2602 |
void CMmsEncode::EncodeForwardConfirmationL() |
|
2603 |
{ |
|
2604 |
// implemented for test purposes |
|
2605 |
#ifdef __WINS__ |
|
2606 |
// Insert message type, TID and version number |
|
2607 |
EncodeStartingHeaders( KMmsMessageTypeForwardConf, |
|
2608 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
2609 |
||
2610 |
EncodeMandatoryByte( KMmsAssignedResponseStatus, |
|
2611 |
iMmsHeaders->ResponseStatus() ); |
|
2612 |
||
2613 |
EncodeOptionalStringL( KMmsAssignedResponseText, |
|
2614 |
iMmsHeaders->ResponseText() ); |
|
2615 |
||
2616 |
EncodeOptionalString( KMmsAssignedMessageId, iMmsHeaders->MessageId() ); |
|
2617 |
||
2618 |
// MMBox related headers - optional |
|
2619 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2620 |
{ |
|
2621 |
EncodeOptionalByte( KMmsAssignedStoreStatus, |
|
2622 |
iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatus() ); |
|
2623 |
EncodeOptionalStringL( KMmsAssignedStoreStatusText, |
|
2624 |
iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatusText() ); |
|
2625 |
if ( iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatus() == |
|
2626 |
KMmsStatusOk ) |
|
2627 |
{ |
|
2628 |
// this must be USASCII or URL encoded |
|
2629 |
// If message was stored to MMBox, this is mandatory |
|
2630 |
EncodeHeaderAndTextString( KMmsAssignedContentLocation, |
|
2631 |
iMmsHeaders->ContentLocation() ); |
|
2632 |
} |
|
2633 |
} |
|
2634 |
||
2635 |
#endif |
|
2636 |
} |
|
2637 |
||
2638 |
// --------------------------------------------------------- |
|
2639 |
// |
|
2640 |
// --------------------------------------------------------- |
|
2641 |
// |
|
2642 |
void CMmsEncode::EncodeReadReplyL() |
|
2643 |
{ |
|
2644 |
// Insert message type, TID and version number |
|
2645 |
EncodeStartingHeaders( iMmsHeaders->MessageType(), TPtrC8(), iMmsHeaders->MmsVersion() ); |
|
2646 |
||
2647 |
// message id |
|
2648 |
EncodeHeaderAndTextString( KMmsAssignedMessageId, |
|
2649 |
iMmsHeaders->MessageId() ); |
|
2650 |
||
2651 |
// originator of the original message |
|
2652 |
EncodeRecipientL( iMmsHeaders->ToRecipients(), EMmsTo ); |
|
2653 |
||
2654 |
// If we have set the sender, encode it |
|
2655 |
// If not, we ask MMSC to add the sender |
|
2656 |
EncodeSenderL( iMmsHeaders->Sender() ); |
|
2657 |
||
2658 |
// if we have set a date, insert it |
|
2659 |
EncodeDate( iMmsHeaders->Date() ); |
|
2660 |
||
2661 |
EncodeMandatoryByte( KMmsAssignedReadStatus, iMmsHeaders->ReadStatus() ); |
|
2662 |
||
2663 |
// version 1.3 headers - optional |
|
2664 |
if ( iMmsHeaders->MmsVersion() > KMmsVersion12 ) |
|
2665 |
{ |
|
2666 |
// X-Mms-Applic-ID, X-Mms-Reply-Applic-ID and X-Mms-Aux-Applic-Info |
|
2667 |
EncodeApplicationHeadersL(); |
|
2668 |
} |
|
2669 |
} |
|
2670 |
||
2671 |
// --------------------------------------------------------- |
|
2672 |
// |
|
2673 |
// --------------------------------------------------------- |
|
2674 |
// |
|
2675 |
void CMmsEncode::EncodeMMBoxStoreRequestL() |
|
2676 |
{ |
|
2677 |
// Insert message type, TID and version number |
|
2678 |
EncodeStartingHeaders( KMmsMessageTypeMboxStoreReq, iMmsHeaders->Tid(), |
|
2679 |
iMmsHeaders->MmsVersion() ); |
|
2680 |
||
2681 |
// this must be USASCII or URL encoded |
|
2682 |
EncodeHeaderAndTextString( KMmsAssignedContentLocation, |
|
2683 |
iMmsHeaders->ContentLocation() ); |
|
2684 |
||
2685 |
// MMBox headers |
|
2686 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2687 |
{ |
|
2688 |
// X-Mms-MM-State |
|
2689 |
EncodeOptionalByte( KMmsAssignedMMState, |
|
2690 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsMMState() ); |
|
2691 |
// X-MMs-MM-Flags |
|
2692 |
// The keyword token should always be "add" or "remove" |
|
2693 |
EncodeKeywordArrayL(); |
|
2694 |
} |
|
2695 |
} |
|
2696 |
||
2697 |
// --------------------------------------------------------- |
|
2698 |
// |
|
2699 |
// --------------------------------------------------------- |
|
2700 |
// |
|
2701 |
void CMmsEncode::EncodeMMBoxStoreConfirmationL() |
|
2702 |
{ |
|
2703 |
// implemented for test purposes |
|
2704 |
#ifdef __WINS__ |
|
2705 |
// Insert message type, TID and version number |
|
2706 |
EncodeStartingHeaders( KMmsMessageTypeMboxStoreConf, iMmsHeaders->Tid(), |
|
2707 |
iMmsHeaders->MmsVersion() ); |
|
2708 |
||
2709 |
// this must be USASCII or URL encoded |
|
2710 |
EncodeOptionalString( KMmsAssignedContentLocation, |
|
2711 |
iMmsHeaders->ContentLocation() ); |
|
2712 |
||
2713 |
EncodeMandatoryByte( KMmsAssignedStoreStatus, |
|
2714 |
iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatus() ); |
|
2715 |
||
2716 |
EncodeOptionalStringL( KMmsAssignedStoreStatusText, |
|
2717 |
iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatusText() ); |
|
2718 |
||
2719 |
#endif |
|
2720 |
} |
|
2721 |
||
2722 |
// --------------------------------------------------------- |
|
2723 |
// |
|
2724 |
// --------------------------------------------------------- |
|
2725 |
// |
|
2726 |
void CMmsEncode::EncodeMMBoxViewRequestL() |
|
2727 |
{ |
|
2728 |
// Insert message type, TID and version number |
|
2729 |
EncodeStartingHeaders( KMmsMessageTypeMboxViewReq, iMmsHeaders->Tid(), |
|
2730 |
iMmsHeaders->MmsVersion() ); |
|
2731 |
||
2732 |
// Insert content location header. There may be more than one |
|
2733 |
EncodeContentLocationArray(); |
|
2734 |
||
2735 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2736 |
{ |
|
2737 |
// X-MMs-MM-Flags. The token should always be "filter" |
|
2738 |
EncodeKeywordArrayL(); |
|
2739 |
} |
|
2740 |
||
2741 |
if ( iMmsHeaders->ReadOnlyMMBoxViewHeaders() ) |
|
2742 |
{ |
|
2743 |
CMmsMMBoxViewHeaders& viewHeaders = iMmsHeaders->MMBoxViewHeadersL(); |
|
2744 |
||
2745 |
// states used as filter |
|
2746 |
// X-Mms-MM-State may appear multiple times in view request |
|
2747 |
EncodeMMBoxStates( viewHeaders.MMStateArray() ); |
|
2748 |
||
2749 |
// start |
|
2750 |
EncodeOptionalInteger( KMmsAssignedStart, viewHeaders.MmsStart() ); |
|
2751 |
// limit |
|
2752 |
if ( viewHeaders.MmsLimit() != KMaxTUint32 ) |
|
2753 |
{ |
|
2754 |
// 0 means no message information, absence means all remaining |
|
2755 |
// messages. |
|
2756 |
// If header has value KMaxTUint32, it means that info about all |
|
2757 |
// remaining messages is wanted. |
|
2758 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedLimit, 1 ); |
|
2759 |
iPosition++; |
|
2760 |
EncodeInteger( viewHeaders.MmsLimit() ); |
|
2761 |
} |
|
2762 |
||
2763 |
EncodeAttributes( viewHeaders.AttributeArray() ); |
|
2764 |
// request totals |
|
2765 |
EncodeOptionalByte( KMmsAssignedTotals, viewHeaders.MmsTotals() ); |
|
2766 |
// request quotas |
|
2767 |
EncodeOptionalByte( KMmsAssignedQuotas, viewHeaders.MmsQuotas() ); |
|
2768 |
} |
|
2769 |
} |
|
2770 |
||
2771 |
// --------------------------------------------------------- |
|
2772 |
// |
|
2773 |
// --------------------------------------------------------- |
|
2774 |
// |
|
2775 |
void CMmsEncode::EncodeMMBoxViewConfirmationL() |
|
2776 |
{ |
|
2777 |
// implemented for test purposes |
|
2778 |
#ifdef __WINS__ |
|
2779 |
// Insert message type, TID and version number |
|
2780 |
EncodeStartingHeaders( KMmsMessageTypeMboxViewConf, |
|
2781 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
2782 |
||
2783 |
EncodeMandatoryByte( KMmsAssignedResponseStatus, |
|
2784 |
iMmsHeaders->ResponseStatus() ); |
|
2785 |
||
2786 |
EncodeOptionalStringL( KMmsAssignedResponseText, |
|
2787 |
iMmsHeaders->ResponseText() ); |
|
2788 |
||
2789 |
EncodeContentLocationArray(); |
|
2790 |
||
2791 |
// MMBox headers |
|
2792 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2793 |
{ |
|
2794 |
// X-MMs-MM-Flags. The token should always be "filter" |
|
2795 |
EncodeKeywordArrayL(); |
|
2796 |
} |
|
2797 |
||
2798 |
if ( iMmsHeaders->ReadOnlyMMBoxViewHeaders() ) |
|
2799 |
{ |
|
2800 |
CMmsMMBoxViewHeaders& viewHeaders = iMmsHeaders->MMBoxViewHeadersL(); |
|
2801 |
||
2802 |
// states used as filter |
|
2803 |
// X-Mms-MM-State may appear multiple times in view request |
|
2804 |
EncodeMMBoxStates( viewHeaders.MMStateArray() ); |
|
2805 |
||
2806 |
// start |
|
2807 |
EncodeOptionalInteger( KMmsAssignedStart, viewHeaders.MmsStart() ); |
|
2808 |
// limit |
|
2809 |
if ( viewHeaders.MmsLimit() != KMaxTUint32 ) |
|
2810 |
{ |
|
2811 |
// 0 means no message information, absence means all remaining |
|
2812 |
// messages. |
|
2813 |
// If header has value KMaxTUint32, it means that info about |
|
2814 |
// all remaining messages is wanted. |
|
2815 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedLimit, 1 ); |
|
2816 |
iPosition++; |
|
2817 |
EncodeInteger( viewHeaders.MmsLimit() ); |
|
2818 |
} |
|
2819 |
EncodeAttributes( viewHeaders.AttributeArray() ); |
|
2820 |
||
2821 |
// totals |
|
2822 |
TUint oldPosition = iPosition; |
|
2823 |
TUint length = 0; |
|
2824 |
||
2825 |
if ( viewHeaders.MMBoxTotalNumber() != KMaxTUint32 ) |
|
2826 |
{ |
|
2827 |
oldPosition = iPosition; |
|
2828 |
EncodeInteger( viewHeaders.MMBoxTotalNumber() ); |
|
2829 |
length = iPosition - oldPosition; |
|
2830 |
length += 1; // quota token |
|
2831 |
iPosition = oldPosition; |
|
2832 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedMboxTotals, 1 ); |
|
2833 |
iPosition++; |
|
2834 |
EncodeValueLength( length ); |
|
2835 |
iEncodeBuffer->Write( iPosition, &KMmsMessageCountToken, 1 ); |
|
2836 |
iPosition++; |
|
2837 |
EncodeInteger( viewHeaders.MMBoxTotalNumber() ); |
|
2838 |
} |
|
2839 |
||
2840 |
if ( viewHeaders.MMBoxTotalSize() != KMaxTUint32 ) |
|
2841 |
{ |
|
2842 |
oldPosition = iPosition; |
|
2843 |
EncodeInteger( viewHeaders.MMBoxTotalSize() ); |
|
2844 |
length = iPosition - oldPosition; |
|
2845 |
length += 1; // quota token |
|
2846 |
iPosition = oldPosition; |
|
2847 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedMboxTotals, 1 ); |
|
2848 |
iPosition++; |
|
2849 |
EncodeValueLength( length ); |
|
2850 |
iEncodeBuffer->Write( iPosition, &KMmsMessageSizeToken, 1 ); |
|
2851 |
iPosition++; |
|
2852 |
EncodeInteger( viewHeaders.MMBoxTotalSize() ); |
|
2853 |
} |
|
2854 |
||
2855 |
// quotas |
|
2856 |
if ( viewHeaders.MMBoxQuotaNumber() != KMaxTUint32 ) |
|
2857 |
{ |
|
2858 |
oldPosition = iPosition; |
|
2859 |
EncodeInteger( viewHeaders.MMBoxQuotaNumber() ); |
|
2860 |
length = iPosition - oldPosition; |
|
2861 |
length += 1; // quota token |
|
2862 |
iPosition = oldPosition; |
|
2863 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedMboxQuotas, 1 ); |
|
2864 |
iPosition++; |
|
2865 |
EncodeValueLength( length ); |
|
2866 |
iEncodeBuffer->Write( iPosition, &KMmsMessageCountToken, 1 ); |
|
2867 |
iPosition++; |
|
2868 |
EncodeInteger( viewHeaders.MMBoxQuotaNumber() ); |
|
2869 |
} |
|
2870 |
||
2871 |
if ( viewHeaders.MMBoxQuotaSize() != KMaxTUint32 ) |
|
2872 |
{ |
|
2873 |
oldPosition = iPosition; |
|
2874 |
EncodeInteger( viewHeaders.MMBoxQuotaSize() ); |
|
2875 |
length = iPosition - oldPosition; |
|
2876 |
length += 1; // quota token |
|
2877 |
iPosition = oldPosition; |
|
2878 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedMboxQuotas, 1 ); |
|
2879 |
iPosition++; |
|
2880 |
EncodeValueLength( length ); |
|
2881 |
iEncodeBuffer->Write( iPosition, &KMmsMessageSizeToken, 1 ); |
|
2882 |
iPosition++; |
|
2883 |
EncodeInteger( viewHeaders.MMBoxQuotaSize() ); |
|
2884 |
} |
|
2885 |
||
2886 |
// Message count |
|
2887 |
// This should in principle come from the viewHeaders.MmsMessageCount() |
|
2888 |
// But in this context the number of messages will be the number of |
|
2889 |
// attachments available in this entry |
|
2890 |
||
2891 |
// However, we will use the viewHeaders.MmsMessageCount() to generate |
|
2892 |
// the header so that we can test that the decoding part can handle |
|
2893 |
// possible conflict between message number and the number of parts |
|
2894 |
// in the multipart structure. This header is optional. KMaxTUint32 |
|
2895 |
// will mean unspecified. |
|
2896 |
||
2897 |
if ( viewHeaders.MmsMessageCount() != KMaxTUint32 ) |
|
2898 |
{ |
|
2899 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedMessageCount, 1 ); |
|
2900 |
iPosition++; |
|
2901 |
EncodeInteger( viewHeaders.MmsMessageCount() ); |
|
2902 |
} |
|
2903 |
} |
|
2904 |
||
2905 |
if ( iNumberOfAttachments == 0 ) |
|
2906 |
{ |
|
2907 |
EncodeMandatoryByte( KMmsAssignedContentType, KMmsAssignedAny ); |
|
2908 |
} |
|
2909 |
else |
|
2910 |
{ |
|
2911 |
EncodeMultipartMixedHeaderL(); |
|
2912 |
} |
|
2913 |
#endif |
|
2914 |
} |
|
2915 |
||
2916 |
// --------------------------------------------------------- |
|
2917 |
// |
|
2918 |
// --------------------------------------------------------- |
|
2919 |
// |
|
2920 |
void CMmsEncode::EncodeMMBoxUploadRequestL() |
|
2921 |
{ |
|
2922 |
// Insert message type, TID and version number |
|
2923 |
EncodeStartingHeaders( KMmsMessageTypeMBoxUploadReq, iMmsHeaders->Tid(), |
|
2924 |
iMmsHeaders->MmsVersion() ); |
|
2925 |
||
2926 |
// MMBox headers |
|
2927 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
2928 |
{ |
|
2929 |
// X-Mms-MM-State |
|
2930 |
EncodeOptionalByte( KMmsAssignedMMState, |
|
2931 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsMMState() ); |
|
2932 |
// X-MMs-MM-Flags |
|
2933 |
// The keyword token should always be "add" or "remove" |
|
2934 |
EncodeKeywordArrayL(); |
|
2935 |
} |
|
2936 |
||
2937 |
// Get Root TMsvId from headers if set |
|
2938 |
TMsvAttachmentId rootId = iMmsHeaders->MessageRoot(); |
|
2939 |
||
2940 |
// Find the matching id from attachment list |
|
2941 |
||
2942 |
TInt error = KErrNone; |
|
2943 |
if ( iEntryWrapper ) |
|
2944 |
{ |
|
2945 |
CMsvStore* store = iEntryWrapper->ReadStoreL(); |
|
2946 |
CleanupStack::PushL( store ); |
|
2947 |
// Only new attachment structure is supported |
|
2948 |
MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
2949 |
TRAP( error, |
|
2950 |
{ |
|
2951 |
CMsvAttachment* attachmentInfo = attachMan.GetAttachmentInfoL( |
|
2952 |
(TMsvAttachmentId) rootId ); |
|
2953 |
delete attachmentInfo; // we just wanted to check that it was found |
|
2954 |
} |
|
2955 |
); |
|
2956 |
CleanupStack::PopAndDestroy( store ); |
|
2957 |
} |
|
2958 |
||
2959 |
// If we have a valid root part, we send the message as multipart/related. |
|
2960 |
// Otherwise we send it as multipart mixed. |
|
2961 |
// We don't try to guess what the root is supposed to be, if it |
|
2962 |
// is not specified or does not point to an existing attachment. |
|
2963 |
||
2964 |
// actually the content should be an MMS PDU as in M-MBox-Descr PDU |
|
2965 |
// It is unclear if if should be wrapped in a multipart structure |
|
2966 |
// (containing only one header) |
|
2967 |
// or if the content type should be application/vnd.wap.mms-message |
|
2968 |
if ( error == KErrNone && rootId != 0 && iEntryWrapper ) |
|
2969 |
{ |
|
2970 |
EncodeMultipartRelatedHeaderL( rootId ); |
|
2971 |
} |
|
2972 |
else |
|
2973 |
{ |
|
2974 |
EncodeMultipartMixedHeaderL(); |
|
2975 |
} |
|
2976 |
||
2977 |
} |
|
2978 |
||
2979 |
// --------------------------------------------------------- |
|
2980 |
// |
|
2981 |
// --------------------------------------------------------- |
|
2982 |
// |
|
2983 |
void CMmsEncode::EncodeMMBoxUploadConfirmationL() |
|
2984 |
{ |
|
2985 |
// implemented for test purposes |
|
2986 |
#ifdef __WINS__ |
|
2987 |
// Insert message type, TID and version number |
|
2988 |
EncodeStartingHeaders( KMmsMessageTypeMBoxUploadConf, iMmsHeaders->Tid(), |
|
2989 |
iMmsHeaders->MmsVersion() ); |
|
2990 |
||
2991 |
// this must be USASCII or URL encoded |
|
2992 |
EncodeOptionalString( KMmsAssignedContentLocation, |
|
2993 |
iMmsHeaders->ContentLocation() ); |
|
2994 |
||
2995 |
EncodeMandatoryByte( KMmsAssignedStoreStatus, |
|
2996 |
iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatus() ); |
|
2997 |
||
2998 |
EncodeOptionalStringL( KMmsAssignedStoreStatusText, |
|
2999 |
iMmsHeaders->MMBoxMessageHeadersL().MmsStoreStatusText() ); |
|
3000 |
#endif |
|
3001 |
} |
|
3002 |
||
3003 |
// --------------------------------------------------------- |
|
3004 |
// |
|
3005 |
// --------------------------------------------------------- |
|
3006 |
// |
|
3007 |
void CMmsEncode::EncodeDeleteRequestL() |
|
3008 |
{ |
|
3009 |
// Insert message type, TID and version number |
|
3010 |
||
3011 |
EncodeStartingHeaders( iMmsHeaders->MessageType(), iMmsHeaders->Tid(), |
|
3012 |
iMmsHeaders->MmsVersion() ); |
|
3013 |
||
3014 |
// Insert content location header. There may be more than one |
|
3015 |
EncodeContentLocationArray(); |
|
3016 |
} |
|
3017 |
||
3018 |
// --------------------------------------------------------- |
|
3019 |
// |
|
3020 |
// --------------------------------------------------------- |
|
3021 |
// |
|
3022 |
void CMmsEncode::EncodeDeleteConfirmationL() |
|
3023 |
{ |
|
3024 |
// implemented for test purposes |
|
3025 |
#ifdef __WINS__ |
|
3026 |
// Insert message type, TID and version number |
|
3027 |
EncodeStartingHeaders( iMmsHeaders->MessageType(), iMmsHeaders->Tid(), |
|
3028 |
iMmsHeaders->MmsVersion() ); |
|
3029 |
||
3030 |
// content location, response status and response text headers have |
|
3031 |
// different format from other PDUs |
|
3032 |
||
3033 |
const RPointerArray<CMmsDeleteResultArray>& resultArray = |
|
3034 |
iMmsHeaders->DeleteResultArray(); |
|
3035 |
||
3036 |
TInt i; |
|
3037 |
TInt length = 0; |
|
3038 |
TInt oldPosition = 0; |
|
3039 |
TUint oldIndex = KMaxTUint32; |
|
3040 |
||
3041 |
for ( i = 0; i < resultArray.Count(); i++ ) |
|
3042 |
{ |
|
3043 |
TUint index = resultArray[i]->Order(); |
|
3044 |
if ( index != oldIndex ) |
|
3045 |
{ |
|
3046 |
// We add status and status text only once, there may be more |
|
3047 |
// than one content location with the same status |
|
3048 |
oldIndex = index; |
|
3049 |
if ( resultArray[i]->ResponseStatus() != 0 ) |
|
3050 |
{ |
|
3051 |
oldPosition = iPosition; |
|
3052 |
length = 0; |
|
3053 |
// Encode once just to find out field length |
|
3054 |
EncodeInteger( index ); |
|
3055 |
length += iPosition - oldPosition; |
|
3056 |
length ++; // response status is only one byte |
|
3057 |
iPosition = oldPosition; |
|
3058 |
// now we have calculated length, do the actual encoding |
|
3059 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedResponseStatus, 1 ); |
|
3060 |
iPosition++; |
|
3061 |
EncodeValueLength( length ); |
|
3062 |
EncodeInteger( index ); |
|
3063 |
TUint8 value = (TUint8) resultArray[i]->ResponseStatus(); |
|
3064 |
iEncodeBuffer->Write( iPosition, &value, 1 ); |
|
3065 |
iPosition++; |
|
3066 |
} |
|
3067 |
if ( resultArray[i]->ResponseText().Length() > 0 ) |
|
3068 |
{ |
|
3069 |
oldPosition = iPosition; |
|
3070 |
length = 0; |
|
3071 |
// Encode once just to find out field length |
|
3072 |
EncodeInteger( index ); |
|
3073 |
EncodeTextStringL( resultArray[i]->ResponseText() ); |
|
3074 |
length += iPosition - oldPosition; |
|
3075 |
iPosition = oldPosition; |
|
3076 |
// now we have calculated length, do the actual encoding |
|
3077 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedResponseText, 1 ); |
|
3078 |
iPosition++; |
|
3079 |
EncodeValueLength( length ); |
|
3080 |
EncodeInteger( index ); |
|
3081 |
EncodeTextStringL( resultArray[i]->ResponseText() ); |
|
3082 |
} |
|
3083 |
} |
|
3084 |
if ( resultArray[i]->ContentLocation().Length() > 0 ) |
|
3085 |
{ |
|
3086 |
oldPosition = iPosition; |
|
3087 |
length = 0; |
|
3088 |
// Encode once just to find out field length |
|
3089 |
EncodeInteger( index ); |
|
3090 |
EncodeTextString( resultArray[i]->ContentLocation() ); |
|
3091 |
length += iPosition - oldPosition; |
|
3092 |
iPosition = oldPosition; |
|
3093 |
// now we have calculated length, do the actual encoding |
|
3094 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedContentLocation, 1 ); |
|
3095 |
iPosition++; |
|
3096 |
EncodeValueLength( length ); |
|
3097 |
EncodeInteger( index ); |
|
3098 |
EncodeTextString( resultArray[i]->ContentLocation() ); |
|
3099 |
} |
|
3100 |
} |
|
3101 |
#endif |
|
3102 |
} |
|
3103 |
||
3104 |
// --------------------------------------------------------- |
|
3105 |
// |
|
3106 |
// --------------------------------------------------------- |
|
3107 |
// |
|
3108 |
void CMmsEncode::EncodeMMBoxDescriptionL() |
|
3109 |
{ |
|
3110 |
// implemented for test purposes |
|
3111 |
#ifdef __WINS__ |
|
3112 |
EncodeMandatoryByte( KMmsAssignedMessageType, KMmsMessageTypeMBoxDescr ); |
|
3113 |
||
3114 |
// this must be USASCII or URL encoded |
|
3115 |
EncodeOptionalString( KMmsAssignedContentLocation, |
|
3116 |
iMmsHeaders->ContentLocation() ); |
|
3117 |
||
3118 |
EncodeOptionalString( KMmsAssignedMessageId, iMmsHeaders->MessageId() ); |
|
3119 |
||
3120 |
// MMBox headers |
|
3121 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
3122 |
{ |
|
3123 |
// X-Mms-MM-State |
|
3124 |
EncodeOptionalByte( KMmsAssignedMMState, |
|
3125 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->MmsMMState() ); |
|
3126 |
// X-MMs-MM-Flags |
|
3127 |
// The keyword token should always be "add" or "remove" |
|
3128 |
EncodeKeywordArrayL(); |
|
3129 |
} |
|
3130 |
||
3131 |
// if we have set a date, insert it |
|
3132 |
EncodeDate( iMmsHeaders->Date() ); |
|
3133 |
||
3134 |
// sender is optional |
|
3135 |
if ( iMmsHeaders->Sender().Length() > 0 ) |
|
3136 |
{ |
|
3137 |
EncodeSenderL( iMmsHeaders->Sender() ); |
|
3138 |
} |
|
3139 |
||
3140 |
// All recipient lists. If no recipients in some of the lists, |
|
3141 |
// nothing is encoded, no need to check separately |
|
3142 |
EncodeRecipientL( iMmsHeaders->ToRecipients(), EMmsTo ); |
|
3143 |
EncodeRecipientL( iMmsHeaders->CcRecipients(), EMmsCc ); |
|
3144 |
EncodeRecipientL( iMmsHeaders->BccRecipients(), EMmsBcc ); |
|
3145 |
||
3146 |
// Message class |
|
3147 |
EncodeOptionalByte( KMmsAssignedMessageClass, |
|
3148 |
iMmsHeaders->MessageClass() ); |
|
3149 |
||
3150 |
// Subject |
|
3151 |
EncodeOptionalStringL( KMmsAssignedSubject, iMmsHeaders->Subject() ); |
|
3152 |
||
3153 |
// Priority |
|
3154 |
EncodeOptionalByte( KMmsAssignedPriority, iMmsHeaders->MessagePriority() ); |
|
3155 |
||
3156 |
// Delivery time |
|
3157 |
EncodeOptionalIntervalOrDate( KMmsAssignedDeliveryTime, |
|
3158 |
iMmsHeaders->DeliveryTimeInterval(), |
|
3159 |
iMmsHeaders->DeliveryDate() ); |
|
3160 |
||
3161 |
// Expiration time |
|
3162 |
EncodeOptionalIntervalOrDate( KMmsAssignedExpiry, |
|
3163 |
iMmsHeaders->ExpiryInterval(), |
|
3164 |
iMmsHeaders->ExpiryDate() ); |
|
3165 |
||
3166 |
// Delivery report |
|
3167 |
EncodeOptionalByte( KMmsAssignedDeliveryReport, |
|
3168 |
iMmsHeaders->DeliveryReport() ); |
|
3169 |
||
3170 |
// Read reply |
|
3171 |
EncodeOptionalByte( KMmsAssignedReadReply, iMmsHeaders->ReadReply() ); |
|
3172 |
||
3173 |
if ( iMmsHeaders->MessageSize() > 0 ) |
|
3174 |
{ |
|
3175 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedMessageSize, 1 ); |
|
3176 |
iPosition++; |
|
3177 |
TInt64 size = iMmsHeaders->MessageSize(); |
|
3178 |
EncodeLongInteger( size ); |
|
3179 |
} |
|
3180 |
||
3181 |
// MMBox description appears from 1.2 onwards - no use to check if we are |
|
3182 |
// 1.1 or later. |
|
3183 |
// Do we want to specify reply charging |
|
3184 |
if ( iMmsHeaders->ReplyCharging() == KMmsReplyChargingRequested || |
|
3185 |
iMmsHeaders->ReplyCharging() == KMmsReplyChargingRequestedTextOnly || |
|
3186 |
iMmsHeaders->ReplyCharging() == KMmsReplyChargingAccepted || |
|
3187 |
iMmsHeaders->ReplyCharging() == KMmsReplyChargingAcceptedTextOnly ) |
|
3188 |
{ |
|
3189 |
// Reply charging value |
|
3190 |
EncodeOptionalByte( KMmsAssignedReplyCharging, |
|
3191 |
iMmsHeaders->ReplyCharging() ); |
|
3192 |
// Reply charging deadline |
|
3193 |
EncodeOptionalIntervalOrDate( KMmsAssignedReplyChargingDeadline, |
|
3194 |
iMmsHeaders->ReplyChargingInterval(), |
|
3195 |
iMmsHeaders->ReplyChargingDate() ); |
|
3196 |
// Reply charging size |
|
3197 |
EncodeReplyChargingSize( iMmsHeaders->ReplyChargingSize() ); |
|
3198 |
} |
|
3199 |
// Reply charging ID |
|
3200 |
EncodeOptionalString( KMmsAssignedReplyChargingID, |
|
3201 |
iMmsHeaders->ReplyChargingId() ); |
|
3202 |
||
3203 |
TInt i; |
|
3204 |
TUint oldPosition; |
|
3205 |
TUint length; |
|
3206 |
for ( i = 0; i < iMmsHeaders->PreviouslySentList().Count(); ++i ) |
|
3207 |
{ |
|
3208 |
oldPosition = iPosition; |
|
3209 |
length = 0; |
|
3210 |
// Encode once just to find out field length |
|
3211 |
EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() ); |
|
3212 |
EncodeAddressL( iMmsHeaders->PreviouslySentList()[i]->Sender() ); |
|
3213 |
length += iPosition - oldPosition; |
|
3214 |
iPosition = oldPosition; |
|
3215 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedPreviouslySentBy, 1 ); |
|
3216 |
iPosition++; |
|
3217 |
EncodeValueLength( length ); |
|
3218 |
// now we have added length, do the actual encoding |
|
3219 |
EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() ); |
|
3220 |
EncodeAddressL( iMmsHeaders->PreviouslySentList()[i]->Sender() ); |
|
3221 |
oldPosition = iPosition; |
|
3222 |
length = 0; |
|
3223 |
EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() ); |
|
3224 |
EncodeLongInteger( iMmsHeaders->PreviouslySentList()[i]->Date() ); |
|
3225 |
length += iPosition - oldPosition; |
|
3226 |
iPosition = oldPosition; |
|
3227 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedPreviouslySentDate, 1 ); |
|
3228 |
iPosition++; |
|
3229 |
EncodeValueLength( length ); |
|
3230 |
EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() ); |
|
3231 |
EncodeLongInteger( iMmsHeaders->PreviouslySentList()[i]->Date() ); |
|
3232 |
} |
|
3233 |
||
3234 |
if ( iNumberOfAttachments > 0 ) |
|
3235 |
{ |
|
3236 |
EncodeMultipartMixedHeaderL(); |
|
3237 |
} |
|
3238 |
||
3239 |
#endif |
|
3240 |
} |
|
3241 |
||
3242 |
// --------------------------------------------------------- |
|
3243 |
// 8-bit version (no conversions) |
|
3244 |
// --------------------------------------------------------- |
|
3245 |
// |
|
3246 |
void CMmsEncode::EncodeTextString( const TDesC8& aString ) |
|
3247 |
{ |
|
3248 |
// Only Content-Id needs a quoted string, for example |
|
3249 |
// "<agjrfnjr> |
|
3250 |
// content-id encoding uses a separate function that adds the quote. |
|
3251 |
// EncodeQuotedTextString |
|
3252 |
||
3253 |
// Check if we need a Quote (This does not mean the quoted string.) |
|
3254 |
TInt length = aString.Length(); |
|
3255 |
if ( length > 0 && aString[0] >= KMms0x80 ) |
|
3256 |
{ |
|
3257 |
iEncodeBuffer->Write( iPosition, &KMmsQuote, 1 ); |
|
3258 |
iPosition++; |
|
3259 |
} |
|
3260 |
||
3261 |
iEncodeBuffer->Write( iPosition, aString, length ); |
|
3262 |
iPosition += length; |
|
3263 |
||
3264 |
iEncodeBuffer->Write( iPosition, &KMmsNull, 1 ); |
|
3265 |
iPosition++; |
|
3266 |
||
3267 |
} |
|
3268 |
||
3269 |
// --------------------------------------------------------- |
|
3270 |
// 8-bit version (no conversions) |
|
3271 |
// --------------------------------------------------------- |
|
3272 |
// |
|
3273 |
void CMmsEncode::EncodeQuotedTextString( const TDesC8& aString ) |
|
3274 |
{ |
|
3275 |
// Before this function is called, the caller must check |
|
3276 |
// that the length of the string is not 0. Otherwise this |
|
3277 |
// makes no sense. You cannot quote a zero-length string |
|
3278 |
||
3279 |
// We need quoted string for content-id. |
|
3280 |
// So far for nothing else. |
|
3281 |
// (for the filename in MIME headers, too, just in case) |
|
3282 |
||
3283 |
// We add one quote to the beginning, nothing to the end. |
|
3284 |
// As we start with a quote, we don't need to check for the special |
|
3285 |
// Quote that is needed if a string starts with a character above 128 |
|
3286 |
TInt length = aString.Length(); |
|
3287 |
iEncodeBuffer->Write( iPosition, &KMmsStringQuote, 1 ); |
|
3288 |
iPosition++; |
|
3289 |
||
3290 |
iEncodeBuffer->Write( iPosition, aString, length ); |
|
3291 |
iPosition += length; |
|
3292 |
||
3293 |
iEncodeBuffer->Write( iPosition, &KMmsNull, 1 ); |
|
3294 |
iPosition++; |
|
3295 |
||
3296 |
} |
|
3297 |
||
3298 |
// --------------------------------------------------------- |
|
3299 |
// unicode version |
|
3300 |
// --------------------------------------------------------- |
|
3301 |
// |
|
3302 |
void CMmsEncode::EncodeTextStringL( const TDesC& aString ) |
|
3303 |
{ |
|
3304 |
||
3305 |
// What about a RFC2068 quoted strings - |
|
3306 |
// see explanation in EncodeTextString( const TDesC8& aString ) function |
|
3307 |
||
3308 |
TInt i = 0; |
|
3309 |
TInt length = aString.Length(); |
|
3310 |
||
3311 |
TBool safe = IsStringSafe( aString ); |
|
3312 |
||
3313 |
// If the string can be encoded as ASCII, go ahead |
|
3314 |
if ( safe ) |
|
3315 |
{ |
|
3316 |
TUint8 character; |
|
3317 |
// No need to check if we need a quote - if we are safe, we have |
|
3318 |
// no characters >= 128. |
|
3319 |
||
3320 |
for ( i = 0; i < aString.Length(); ++i ) |
|
3321 |
{ |
|
3322 |
character = TUint8( aString[i] & KMms0xFF ); |
|
3323 |
iEncodeBuffer->Write( iPosition, &character, 1 ); |
|
3324 |
iPosition++; |
|
3325 |
} |
|
3326 |
iEncodeBuffer->Write( iPosition, &KMmsNull, 1 ); |
|
3327 |
iPosition++; |
|
3328 |
} |
|
3329 |
else |
|
3330 |
{ |
|
3331 |
// if our length is 0, we are safe, no need to check the |
|
3332 |
// length here anymore |
|
3333 |
// we must convert to utf-8 |
|
3334 |
||
3335 |
//one ucs-2 character should never produce more than 4 bytes when converted to utf-8 |
|
72
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
3336 |
// coverity[incorrect_multiplication][buffer_alloc] |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
3337 |
HBufC8* buffer = HBufC8::NewL( aString.Length() * KMms4 ); // paranoid. |
31 | 3338 |
// we don't leave while we need buffer |
3339 |
TPtr8 buf8 = buffer->Des(); |
|
3340 |
||
3341 |
// if conversion fails, something is really seriously wrong |
|
3342 |
iError = CnvUtfConverter::ConvertFromUnicodeToUtf8( buf8, aString ); |
|
3343 |
||
3344 |
length = buf8.Length(); |
|
3345 |
// utf8 character set encoding needs one byte (fits into short integer) |
|
3346 |
length += KMms2; // add character set encoding byte and trailing NULL |
|
3347 |
||
3348 |
if ( buf8[0] >= KMms0x80 ) // 128 |
|
3349 |
{ |
|
3350 |
length++; // we will need a quote byte at the start... |
|
3351 |
} |
|
3352 |
||
3353 |
EncodeValueLength( length ); |
|
3354 |
||
3355 |
// add one byte of character set |
|
3356 |
// this is a short integer, high bit must be set |
|
3357 |
TUint8 charset = KMmsUtf8 | KMms0x80; |
|
3358 |
||
3359 |
iEncodeBuffer->Write( iPosition, &charset, 1 ); |
|
3360 |
iPosition++; |
|
3361 |
||
3362 |
// Check if we need a quote |
|
3363 |
if ( buf8[0] >= KMms0x80 ) // 128 |
|
3364 |
{ |
|
3365 |
iEncodeBuffer->Write( iPosition, &KMmsQuote, 1 ); |
|
3366 |
iPosition++; |
|
3367 |
} |
|
3368 |
||
3369 |
// Then write the string itself |
|
3370 |
iEncodeBuffer->Write( iPosition, buf8, buf8.Length() ); |
|
3371 |
iPosition += buf8.Length(); |
|
3372 |
||
3373 |
// Add terminating NULL |
|
3374 |
iEncodeBuffer->Write( iPosition, &KMmsNull, 1 ); |
|
3375 |
iPosition++; |
|
3376 |
||
3377 |
delete buffer; |
|
3378 |
buffer = NULL; |
|
3379 |
} |
|
3380 |
||
3381 |
} |
|
3382 |
||
3383 |
// --------------------------------------------------------- |
|
3384 |
// |
|
3385 |
// --------------------------------------------------------- |
|
3386 |
// |
|
3387 |
void CMmsEncode::EncodeDate( const TInt64& aDate) |
|
3388 |
{ |
|
3389 |
||
3390 |
if ( aDate == 0 ) |
|
3391 |
{ |
|
3392 |
return; |
|
3393 |
} |
|
3394 |
||
3395 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedDate, 1 ); |
|
3396 |
iPosition++; |
|
3397 |
||
3398 |
EncodeLongInteger( aDate ); |
|
3399 |
||
3400 |
} |
|
3401 |
||
3402 |
// --------------------------------------------------------- |
|
3403 |
// |
|
3404 |
// --------------------------------------------------------- |
|
3405 |
// |
|
3406 |
void CMmsEncode::EncodeLongInteger( const TInt64& aLongInteger ) |
|
3407 |
{ |
|
3408 |
||
3409 |
TUint8 length = 0; // number of bytes we will need |
|
3410 |
// The long integer will take 8 bytes or less |
|
3411 |
TUint8 array[KMms8]; |
|
3412 |
||
3413 |
TInt64 temp = aLongInteger; |
|
3414 |
TInt i = 0; |
|
3415 |
TInt64 reminder = 0; |
|
3416 |
||
3417 |
for ( i = 7; i >= 0; --i ) |
|
3418 |
{ |
|
3419 |
reminder = temp % 0x100; |
|
3420 |
temp = temp / 0x100; |
|
3421 |
array[i] = TInt8 ( I64INT( reminder ) ) ; |
|
3422 |
} |
|
3423 |
||
3424 |
length = KMms8; |
|
3425 |
i = 0; |
|
3426 |
// The array has 8 elements, so this is safe. |
|
3427 |
while( ( i < KMms8 ) && ( array[i] == 0 ) ) |
|
3428 |
{ |
|
3429 |
i++; |
|
3430 |
length--; |
|
3431 |
} |
|
3432 |
||
3433 |
// a zero should be coded as short integer. |
|
3434 |
// However, if there is a valid reason to code a zero as a long integer, |
|
3435 |
// we allow it. The caller should know what he is doing. |
|
3436 |
if ( length == 0 ) |
|
3437 |
{ |
|
3438 |
length = 1; |
|
3439 |
} |
|
3440 |
||
3441 |
// write short length |
|
3442 |
iEncodeBuffer->Write( iPosition, &length, 1 ); |
|
3443 |
iPosition++; |
|
3444 |
||
3445 |
// write as many bytes as were non-zero |
|
3446 |
// array index will stay withing limits because of the way it was calculated |
|
3447 |
iEncodeBuffer->Write( iPosition, &(array[KMms8 - length] ), length ); |
|
3448 |
iPosition+= length; |
|
3449 |
||
3450 |
} |
|
3451 |
||
3452 |
// --------------------------------------------------------- |
|
3453 |
// |
|
3454 |
// --------------------------------------------------------- |
|
3455 |
// |
|
3456 |
void CMmsEncode::EncodeInteger( TUint aInteger ) |
|
3457 |
{ |
|
3458 |
// KMms1 = 1 |
|
3459 |
// KMms2 = 2 |
|
3460 |
// KMms3 = 3 |
|
3461 |
// KMms4 = 4 |
|
3462 |
// KMms5 = 5 |
|
3463 |
// etc. |
|
3464 |
||
3465 |
TUint8 byte = 0; |
|
3466 |
||
3467 |
if ( aInteger <= KMmsShortIntegerLimit127 ) |
|
3468 |
{ |
|
3469 |
byte = ( TInt8 ) aInteger; |
|
3470 |
byte |= KMms0x80; |
|
3471 |
iEncodeBuffer->Write( iPosition, &byte, 1); |
|
3472 |
iPosition++; |
|
3473 |
return; // this was easy |
|
3474 |
} |
|
3475 |
||
3476 |
TUint8 length = KMms4; // number of bytes we will need |
|
3477 |
TUint8 array[KMms4]; |
|
3478 |
||
3479 |
TUint temp = aInteger; |
|
3480 |
byte = TInt8( ( temp >> KMms24 ) & KMms0xFF ); |
|
3481 |
||
3482 |
while ( byte == 0 && length > 0 ) |
|
3483 |
{ |
|
3484 |
length--; |
|
3485 |
temp = temp << KMms8; |
|
3486 |
byte = TInt8( ( temp >> KMms24 ) & KMms0xFF ); |
|
3487 |
} |
|
3488 |
||
3489 |
TUint i = 0; |
|
3490 |
for ( i = 0; i < length; ++i ) |
|
3491 |
{ |
|
3492 |
array[i] = TInt8( ( temp >> ( KMms8 * ( KMms3 - i ) ) ) & KMms0xFF ); |
|
3493 |
} |
|
3494 |
||
3495 |
// write short length |
|
3496 |
iEncodeBuffer->Write( iPosition, &length, 1 ); |
|
3497 |
iPosition++; |
|
3498 |
||
3499 |
// write as many bytes as were non-zero |
|
3500 |
// aInteger was tested in the beginning - it needs at least one byte |
|
3501 |
// So length is at least 1 and the array has been properly initialized. |
|
3502 |
iEncodeBuffer->Write( iPosition, &array[0], length ); |
|
3503 |
iPosition+= length; |
|
3504 |
||
3505 |
} |
|
3506 |
||
3507 |
// --------------------------------------------------------- |
|
3508 |
// |
|
3509 |
// --------------------------------------------------------- |
|
3510 |
// |
|
3511 |
void CMmsEncode::EncodeSenderL( const TPtrC& aSender ) |
|
3512 |
{ |
|
3513 |
||
3514 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedFrom, 1 ); |
|
3515 |
iPosition++; |
|
3516 |
||
3517 |
// We must insert value length. |
|
3518 |
||
3519 |
if ( aSender.Length() == 0 ) |
|
3520 |
{ |
|
3521 |
// The MMSC must insert our address |
|
3522 |
TUint8 length; |
|
3523 |
length = 1; |
|
3524 |
iEncodeBuffer->Write( iPosition, &length, 1 ); |
|
3525 |
iPosition++; |
|
3526 |
iEncodeBuffer->Write( iPosition, &KMmsInsertAddressToken, 1 ); |
|
3527 |
iPosition++; |
|
3528 |
return; |
|
3529 |
} |
|
3530 |
||
3531 |
// Now we must insert something |
|
3532 |
TUint length = 1; // address present token |
|
3533 |
||
3534 |
if ( aSender.Find( KMiuMau ) != KErrNotFound ) |
|
3535 |
{ |
|
3536 |
TBool safe = IsStringSafe( aSender ); |
|
3537 |
if ( safe ) |
|
3538 |
{ |
|
3539 |
// this was easy, just ASCII, no conversion |
|
3540 |
length += aSender.Length(); |
|
3541 |
length ++; // room for terminating zero |
|
3542 |
} |
|
3543 |
else // not USASCII, charset must be specified |
|
3544 |
{ |
|
3545 |
// worst case scenario. |
|
3546 |
// must be encoded as UTF-8, value length and character set |
|
3547 |
// must be added |
|
3548 |
||
3549 |
// one ucs-2 character will not produce more than 4 bytes when converted to utf-8 |
|
72
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
3550 |
// coverity[incorrect_multiplication][buffer_alloc] |
31 | 3551 |
HBufC8* buffer = HBufC8::NewL( aSender.Length() * KMms4 ); // paranoid. |
3552 |
// we don't need to push buffer onto cleanup stack, as we don't |
|
3553 |
// leave while we are using it |
|
3554 |
TPtr8 buf8 = buffer->Des(); |
|
3555 |
||
3556 |
// if we get error here, something is badly wrong |
|
3557 |
iError = CnvUtfConverter::ConvertFromUnicodeToUtf8( buf8, aSender ); |
|
3558 |
||
3559 |
length += buf8.Length(); |
|
3560 |
// utf8 character set encoding needs one byte (short integer) |
|
3561 |
length += KMms2; // add character set encoding byte and trailing NULL |
|
3562 |
||
3563 |
if ( buf8[0] >= KMms0x80 ) // 128 |
|
3564 |
{ |
|
3565 |
length++; // we will need a quote byte at the start... |
|
3566 |
} |
|
3567 |
delete buffer; |
|
3568 |
buffer = NULL; |
|
3569 |
} |
|
3570 |
} |
|
3571 |
else // no miumau found |
|
3572 |
{ |
|
3573 |
// phone number, must be ASCII |
|
3574 |
length += aSender.Length(); |
|
3575 |
length ++; // room for terminating zero |
|
3576 |
length += KMmsPlmnLength; // type indication |
|
3577 |
// this should be the length, if we have a phone number (no alias.) |
|
3578 |
} |
|
3579 |
||
3580 |
EncodeValueLength( length ); |
|
3581 |
||
3582 |
iEncodeBuffer->Write( iPosition, &KMmsAddressPresentToken, 1 ); |
|
3583 |
iPosition++; |
|
3584 |
||
3585 |
// If the address contains some non-ascii characters, |
|
3586 |
// it must be converted to utf-8 |
|
3587 |
||
3588 |
EncodeAddressL( aSender ); |
|
3589 |
||
3590 |
} |
|
3591 |
||
3592 |
// --------------------------------------------------------- |
|
3593 |
// |
|
3594 |
// --------------------------------------------------------- |
|
3595 |
// |
|
3596 |
void CMmsEncode::EncodeAddressL( const TPtrC& aAddress ) |
|
3597 |
{ |
|
3598 |
// Supports only address types PLMN and email. |
|
3599 |
// If the address string contains a @ character, |
|
3600 |
// it is interpreted as an email |
|
3601 |
||
3602 |
// Internal alias is removed |
|
3603 |
||
3604 |
TMmsAddressType addressType = EMmsAddressTypeUnknown; |
|
3605 |
HBufC* realAddress = HBufC::NewL( aAddress.Length() ); |
|
3606 |
CleanupStack::PushL( realAddress ); |
|
3607 |
||
3608 |
TInt error = KErrNone; |
|
3609 |
||
3610 |
TPtr realAddressPointer = realAddress->Des(); |
|
3611 |
error = TMmsGenUtils::AddressTypeAndRealAddress( |
|
3612 |
aAddress, |
|
3613 |
addressType, |
|
3614 |
realAddressPointer, |
|
3615 |
aAddress.Length()); |
|
3616 |
||
3617 |
if ( error != KErrNone || addressType == EMmsAddressTypeUnknown ) |
|
3618 |
{ |
|
3619 |
// could not resolve. Send unchanged |
|
3620 |
realAddress->Des().Copy( aAddress ); |
|
3621 |
if ( aAddress.Find( KMiuMau ) != KErrNotFound ) |
|
3622 |
{ |
|
3623 |
addressType = EMmsAddressTypeEmail; |
|
3624 |
} |
|
3625 |
else |
|
3626 |
{ |
|
3627 |
addressType = EMmsAddressTypeMobile; |
|
3628 |
} |
|
3629 |
} |
|
3630 |
||
3631 |
if ( addressType == EMmsAddressTypeEmail ) |
|
3632 |
{ |
|
3633 |
// email address |
|
3634 |
// If the address contains only ASCII characters, |
|
3635 |
// it can be sent as text string, if not, it must be sent as utf-8 |
|
3636 |
||
3637 |
EncodeTextStringL( *realAddress ); |
|
3638 |
||
3639 |
} |
|
3640 |
else |
|
3641 |
{ |
|
3642 |
// must be a phone number |
|
3643 |
// We expect for now that the format is correct as is |
|
3644 |
// All legal characters present in a phone number are ASCII |
|
3645 |
||
3646 |
TInt i = 0; |
|
3647 |
TUint8 character = 0; |
|
3648 |
realAddressPointer = realAddress->Des(); |
|
3649 |
for ( i = 0; i < realAddress->Length(); ++i ) |
|
3650 |
{ |
|
3651 |
// The array index is safe because i is always < realAddress->Length(). |
|
3652 |
character = TUint8( realAddressPointer[i] & KMms0xFF ); |
|
3653 |
iEncodeBuffer->Write( iPosition, &character, 1 ); |
|
3654 |
iPosition++; |
|
3655 |
} |
|
3656 |
iEncodeBuffer->Write( iPosition, KMmsPlmn, KMmsPlmnLength ); |
|
3657 |
iPosition += KMmsPlmnLength; |
|
3658 |
iEncodeBuffer->Write( iPosition, &KMmsNull, 1 ); |
|
3659 |
iPosition++; |
|
3660 |
} |
|
3661 |
CleanupStack::PopAndDestroy( realAddress ); |
|
3662 |
||
3663 |
} |
|
3664 |
||
3665 |
// --------------------------------------------------------- |
|
3666 |
// |
|
3667 |
// --------------------------------------------------------- |
|
3668 |
// |
|
3669 |
void CMmsEncode::EncodeValueLength( TUint aLength ) |
|
3670 |
{ |
|
3671 |
||
3672 |
TUint8 shortLength = 0; |
|
3673 |
||
3674 |
if ( aLength <= KMms30 ) |
|
3675 |
{ |
|
3676 |
// short length |
|
3677 |
shortLength = TUint8( aLength ) ; |
|
3678 |
iEncodeBuffer->Write( iPosition, &shortLength, 1 ); |
|
3679 |
iPosition++; |
|
3680 |
} |
|
3681 |
else |
|
3682 |
{ |
|
3683 |
iEncodeBuffer->Write( iPosition, &KMmsLengthQuote, 1 ); |
|
3684 |
iPosition++; |
|
3685 |
EncodeUintvar( aLength ); |
|
3686 |
} |
|
3687 |
||
3688 |
} |
|
3689 |
||
3690 |
// --------------------------------------------------------- |
|
3691 |
// |
|
3692 |
// --------------------------------------------------------- |
|
3693 |
// |
|
3694 |
void CMmsEncode::EncodeUintvar( TUint aInteger ) |
|
3695 |
{ |
|
3696 |
||
3697 |
// The value is split into 7 bit chunks, and continue bit set |
|
3698 |
// when needed. |
|
3699 |
||
3700 |
// No more than 5 bytes will be produced |
|
3701 |
TUint8 buffer[KMms5]; |
|
3702 |
TUint temp = aInteger; |
|
3703 |
TInt i; |
|
3704 |
||
3705 |
for ( i = 0; i < KMms5; ++i ) |
|
3706 |
{ |
|
3707 |
buffer[KMms4 - i] = TUint8( temp & KMms0x7F ); |
|
3708 |
temp >>= KMms7; |
|
3709 |
} |
|
3710 |
||
3711 |
i = 0; |
|
3712 |
// buffer indexes are safe because the buffer has been defined long enough. |
|
3713 |
while ( i < KMms4 && buffer[i] == 0 ) |
|
3714 |
{ |
|
3715 |
i++; |
|
3716 |
} |
|
3717 |
||
3718 |
TInt j; |
|
3719 |
||
3720 |
for ( j = i; j < KMms4; ++j ) |
|
3721 |
{ |
|
3722 |
// buffer indexes are safe because the buffer has been defined long enough. |
|
3723 |
buffer[j] |= KMms0x80; // set Continue bit, but never to last |
|
3724 |
} |
|
3725 |
||
3726 |
// buffer indexes are safe because the buffer has been defined long enough. |
|
3727 |
iEncodeBuffer->Write( iPosition, &buffer[i], KMms5 - i ); |
|
3728 |
iPosition += KMms5 - i; |
|
3729 |
||
3730 |
} |
|
3731 |
||
3732 |
// --------------------------------------------------------- |
|
3733 |
// |
|
3734 |
// --------------------------------------------------------- |
|
3735 |
// |
|
3736 |
TInt CMmsEncode::GetUintvarLength( TUint aInteger ) |
|
3737 |
{ |
|
3738 |
||
3739 |
// The value is split into 7 bit chunks, and continue bit set |
|
3740 |
// when needed. |
|
3741 |
||
3742 |
// No more than 5 bytes will be produced |
|
3743 |
TUint8 buffer[KMms5]; |
|
3744 |
TUint temp = aInteger; |
|
3745 |
TInt i; |
|
3746 |
||
3747 |
for (i = 0; i < KMms5; ++i ) |
|
3748 |
{ |
|
3749 |
buffer[KMms4 - i] = TUint8( temp & KMms0x7F ); |
|
3750 |
temp >>= KMms7; |
|
3751 |
} |
|
3752 |
||
3753 |
i = 0; |
|
3754 |
// buffer indexes are safe because the buffer has been defined long enough. |
|
3755 |
while ( i < KMms4 && buffer[i] == 0 ) |
|
3756 |
{ |
|
3757 |
i++; |
|
3758 |
} |
|
3759 |
||
3760 |
return KMms5 - i; |
|
3761 |
||
3762 |
} |
|
3763 |
||
3764 |
// --------------------------------------------------------- |
|
3765 |
// |
|
3766 |
// --------------------------------------------------------- |
|
3767 |
// |
|
3768 |
void CMmsEncode::EncodeRecipientL( const CDesCArray& aRecipientList, |
|
3769 |
TMmsRecipients aType ) |
|
3770 |
{ |
|
3771 |
||
3772 |
TInt i; |
|
3773 |
TInt size = aRecipientList.Count(); |
|
3774 |
if ( size == 0 ) |
|
3775 |
{ |
|
3776 |
return; |
|
3777 |
} |
|
3778 |
||
3779 |
TUint8 recipientType = KMmsAssignedTo; |
|
3780 |
||
3781 |
switch ( aType ) |
|
3782 |
{ |
|
3783 |
case EMmsTo: |
|
3784 |
recipientType = KMmsAssignedTo; |
|
3785 |
break; |
|
3786 |
case EMmsCc: |
|
3787 |
recipientType = KMmsAssignedCc; |
|
3788 |
break; |
|
3789 |
case EMmsBcc: |
|
3790 |
recipientType = KMmsAssignedBcc; |
|
3791 |
break; |
|
3792 |
default: |
|
3793 |
break; |
|
3794 |
} |
|
3795 |
||
3796 |
for ( i = 0; i < size; ++i ) |
|
3797 |
{ |
|
3798 |
// check for fakes |
|
3799 |
if ( aRecipientList[i].Length() > 0 ) |
|
3800 |
{ |
|
3801 |
iEncodeBuffer->Write( iPosition, &recipientType, 1 ); |
|
3802 |
iPosition++; |
|
3803 |
||
3804 |
EncodeAddressL( aRecipientList[i] ); |
|
3805 |
} |
|
3806 |
||
3807 |
} |
|
3808 |
||
3809 |
} |
|
3810 |
||
3811 |
// --------------------------------------------------------- |
|
3812 |
// |
|
3813 |
// --------------------------------------------------------- |
|
3814 |
// |
|
3815 |
void CMmsEncode::EncodeOptionalStringL( TUint8 aHeader, |
|
3816 |
const TPtrC16& aString ) |
|
3817 |
{ |
|
3818 |
||
3819 |
if ( aString.Length() == 0 ) |
|
3820 |
{ |
|
3821 |
return; |
|
3822 |
} |
|
3823 |
||
3824 |
iEncodeBuffer->Write( iPosition, &aHeader, 1 ); |
|
3825 |
iPosition++; |
|
3826 |
||
3827 |
EncodeTextStringL( aString ); |
|
3828 |
||
3829 |
} |
|
3830 |
||
3831 |
// --------------------------------------------------------- |
|
3832 |
// |
|
3833 |
// --------------------------------------------------------- |
|
3834 |
// |
|
3835 |
void CMmsEncode::EncodeOptionalString( TUint8 aHeader, const TPtrC8& aString ) |
|
3836 |
{ |
|
3837 |
||
3838 |
if ( aString.Length() == 0 ) |
|
3839 |
{ |
|
3840 |
return; |
|
3841 |
} |
|
3842 |
||
3843 |
EncodeHeaderAndTextString( aHeader, aString ); |
|
3844 |
||
3845 |
} |
|
3846 |
||
3847 |
// --------------------------------------------------------- |
|
3848 |
// |
|
3849 |
// --------------------------------------------------------- |
|
3850 |
// |
|
3851 |
void CMmsEncode::EncodeIntervalOrDate( TInt aInterval, const TInt64& aDate ) |
|
3852 |
{ |
|
3853 |
||
3854 |
TInt64 temp = 0; |
|
3855 |
TUint8 token = 0; |
|
3856 |
||
3857 |
if ( aDate != 0 ) |
|
3858 |
{ |
|
3859 |
temp = aDate; |
|
3860 |
token = KMmsAbsoluteToken; |
|
3861 |
} |
|
3862 |
else |
|
3863 |
{ |
|
3864 |
temp = aInterval; |
|
3865 |
token = KMmsRelativeToken; |
|
3866 |
} |
|
3867 |
||
3868 |
// calculate value length |
|
3869 |
||
3870 |
TUint length = KMms8; |
|
3871 |
TUint mask = 0xff000000; |
|
3872 |
||
3873 |
while ( ( I64HIGH( temp ) & mask ) == 0 && length > KMms4) |
|
3874 |
{ |
|
3875 |
mask >>= KMms8; |
|
3876 |
length--; |
|
3877 |
} |
|
3878 |
||
3879 |
mask = 0xff000000; |
|
3880 |
||
3881 |
// Test if the whole high half was zero |
|
3882 |
if ( I64HIGH( temp ) == 0 ) |
|
3883 |
{ |
|
3884 |
while ( ( I64LOW( temp ) & mask ) == 0 && length > 1) |
|
3885 |
{ |
|
3886 |
mask >>= KMms8; |
|
3887 |
length--; |
|
3888 |
} |
|
3889 |
} |
|
3890 |
||
3891 |
// now add short length and absolute/relative token |
|
3892 |
||
3893 |
length += KMms2; |
|
3894 |
||
3895 |
EncodeValueLength( length ); |
|
3896 |
||
3897 |
iEncodeBuffer->Write( iPosition, &token, 1 ); |
|
3898 |
iPosition++; |
|
3899 |
||
3900 |
EncodeLongInteger( temp ); |
|
3901 |
||
3902 |
} |
|
3903 |
||
3904 |
// --------------------------------------------------------- |
|
3905 |
// |
|
3906 |
// --------------------------------------------------------- |
|
3907 |
// |
|
3908 |
void CMmsEncode::EncodeReplyChargingSize( TInt aReplyChargingSize ) |
|
3909 |
{ |
|
3910 |
if ( aReplyChargingSize == 0 ) |
|
3911 |
{ |
|
3912 |
return; |
|
3913 |
} |
|
3914 |
TInt64 size = aReplyChargingSize; |
|
3915 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedReplyChargingSize, 1 ); |
|
3916 |
iPosition++; |
|
3917 |
||
3918 |
EncodeLongInteger( size ); |
|
3919 |
} |
|
3920 |
||
3921 |
// --------------------------------------------------------- |
|
3922 |
// |
|
3923 |
// --------------------------------------------------------- |
|
3924 |
// |
|
3925 |
void CMmsEncode::EncodeOptionalByte( TUint8 aHeader, TInt aValue ) |
|
3926 |
{ |
|
3927 |
if ( aValue == 0 ) |
|
3928 |
{ |
|
3929 |
return; // not set, nothing to encode, header is optional |
|
3930 |
} |
|
3931 |
EncodeMandatoryByte( aHeader, aValue ); |
|
3932 |
||
3933 |
} |
|
3934 |
||
3935 |
// --------------------------------------------------------- |
|
3936 |
// |
|
3937 |
// --------------------------------------------------------- |
|
3938 |
// |
|
3939 |
void CMmsEncode::EncodeMandatoryByte( TUint8 aHeader, TInt aValue ) |
|
3940 |
{ |
|
3941 |
// When ecoding mandatory byte even value 0 is allowed. |
|
3942 |
// It will become 0x80, and be correctly decoded back to 0. |
|
3943 |
TUint8 value = TUint8 ( aValue ) | KMms0x80 ; |
|
3944 |
||
3945 |
iEncodeBuffer->Write( iPosition, &aHeader, 1 ); |
|
3946 |
iPosition++; |
|
3947 |
||
3948 |
iEncodeBuffer->Write( iPosition, &value, 1 ); |
|
3949 |
iPosition++; |
|
3950 |
} |
|
3951 |
||
3952 |
||
3953 |
// --------------------------------------------------------- |
|
3954 |
// |
|
3955 |
// --------------------------------------------------------- |
|
3956 |
// |
|
3957 |
void CMmsEncode::EncodeOptionalIntervalOrDate( TUint8 aHeader, |
|
3958 |
TInt aInterval, |
|
3959 |
const TInt64& aDate ) |
|
3960 |
{ |
|
3961 |
if ( aInterval == 0 && aDate == 0 ) |
|
3962 |
{ |
|
3963 |
return; // not set, nothing to encode, header is optional |
|
3964 |
} |
|
3965 |
||
3966 |
iEncodeBuffer->Write( iPosition, &aHeader, 1 ); |
|
3967 |
iPosition++; |
|
3968 |
||
3969 |
EncodeIntervalOrDate( aInterval, aDate ); |
|
3970 |
} |
|
3971 |
||
3972 |
// --------------------------------------------------------- |
|
3973 |
// |
|
3974 |
// --------------------------------------------------------- |
|
3975 |
// |
|
3976 |
void CMmsEncode::EncodeHeaderAndTextString( TUint8 aHeader, |
|
3977 |
const TDesC8& aString ) |
|
3978 |
{ |
|
3979 |
||
3980 |
iEncodeBuffer->Write( iPosition, &aHeader, 1 ); |
|
3981 |
iPosition++; |
|
3982 |
||
3983 |
EncodeTextString( aString ); |
|
3984 |
||
3985 |
} |
|
3986 |
||
3987 |
||
3988 |
// --------------------------------------------------------- |
|
3989 |
// |
|
3990 |
// --------------------------------------------------------- |
|
3991 |
// |
|
3992 |
TBool CMmsEncode::IsStringSafe( const TDesC& aString ) |
|
3993 |
{ |
|
3994 |
||
3995 |
// Very simple check to see if string is "safe" ASCII |
|
3996 |
// Used for headers, which are short strings |
|
3997 |
||
3998 |
TInt i; |
|
3999 |
TBool safe = ETrue; |
|
4000 |
||
4001 |
for ( i = 0; i < aString.Length() && safe; ++i ) |
|
4002 |
{ |
|
4003 |
if ( aString[i] < KMmsLowestAscii || aString[i] >= KMmsHighestAscii ) |
|
4004 |
{ |
|
4005 |
safe = EFalse; |
|
4006 |
} |
|
4007 |
} |
|
4008 |
return safe; |
|
4009 |
||
4010 |
} |
|
4011 |
||
4012 |
// --------------------------------------------------------- |
|
4013 |
// |
|
4014 |
// --------------------------------------------------------- |
|
4015 |
// |
|
4016 |
TBool CMmsEncode::IsStringSafe( const TDesC8& aString, TInt& aNumNonSafe ) |
|
4017 |
{ |
|
4018 |
||
4019 |
// Very simple check to see if string is "safe" ASCII |
|
4020 |
// Used for headers, which are short strings |
|
4021 |
// spaces count as non-safe because their number must be taken into |
|
4022 |
// account when calculating the length |
|
4023 |
||
4024 |
const TInt KIntQuestion = 0x3F; |
|
4025 |
const TInt KIntEquals = 0x3D; |
|
4026 |
||
4027 |
TInt i; |
|
4028 |
aNumNonSafe = 0; |
|
4029 |
TBool safe = ETrue; |
|
4030 |
||
4031 |
for ( i = 0; i < aString.Length()/* && safe*/; ++i ) |
|
4032 |
{ |
|
4033 |
if ( aString[i] < KMmsLowestAscii || aString[i] >= KMmsHighestAscii ) |
|
4034 |
{ |
|
4035 |
safe = EFalse; |
|
4036 |
aNumNonSafe++; |
|
4037 |
} |
|
4038 |
if ( aString[i] == KIntQuestion || aString[i] == KIntEquals ) |
|
4039 |
{ |
|
4040 |
// These are safe but must be encoded if quoted printable |
|
4041 |
// encoding is used. The number is needed to check the header length |
|
4042 |
aNumNonSafe++; |
|
4043 |
} |
|
4044 |
if ( aString[i] == KMmsIntUnderscore ) |
|
4045 |
{ |
|
4046 |
// This must always be encoded as base64 because Symbian |
|
4047 |
// does not encode underscores when quoted printable is used. |
|
4048 |
aNumNonSafe = KMaxEncodingLength; |
|
4049 |
} |
|
4050 |
||
4051 |
} |
|
4052 |
return safe; |
|
4053 |
||
4054 |
} |
|
4055 |
||
4056 |
// --------------------------------------------------------- |
|
4057 |
// |
|
4058 |
// --------------------------------------------------------- |
|
4059 |
// |
|
4060 |
void CMmsEncode::EncodeMultipartRelatedHeaderL( const TMsvAttachmentId aRootId ) |
|
4061 |
{ |
|
4062 |
||
4063 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedContentType, 1 ); |
|
4064 |
iPosition++; |
|
4065 |
||
4066 |
// We have parameters (start), so we must use Content-general-form |
|
4067 |
||
4068 |
// We need the content-id for the root part. If it is not defined already, |
|
4069 |
// we must generate one. |
|
4070 |
||
4071 |
TUint headerLength = 1; // one byte for well known media |
|
4072 |
TInt cleanupCount = 0; // we must keep track what we have on store |
|
4073 |
||
4074 |
User::LeaveIfError( iEntryWrapper->SetCurrentEntry( iCurrentMessageId ) ); |
|
4075 |
||
4076 |
CMsvStore* store = iEntryWrapper->EditStoreL(); |
|
4077 |
CleanupStack::PushL( store ); cleanupCount++; |
|
4078 |
MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
4079 |
CMsvAttachment* attachmentInfo = NULL; |
|
4080 |
attachmentInfo = attachMan.GetAttachmentInfoL( (TMsvAttachmentId) aRootId ); |
|
4081 |
CleanupStack::PushL( attachmentInfo ); cleanupCount++; |
|
4082 |
||
4083 |
iMimeHeaders->RestoreL( *attachmentInfo ); |
|
4084 |
||
4085 |
if ( iError != KErrNone ) |
|
4086 |
{ |
|
4087 |
CleanupStack::PopAndDestroy( cleanupCount ); |
|
4088 |
return; |
|
4089 |
} |
|
4090 |
||
4091 |
TPtrC8 cid = iMimeHeaders->ContentId(); |
|
4092 |
TBufC8<KMmsMaxCidLength> target; |
|
4093 |
||
4094 |
// If cid has not been defined, we must generate one |
|
4095 |
if ( cid.Length() == 0 ) |
|
4096 |
{ |
|
4097 |
TTime now; |
|
4098 |
now.UniversalTime(); |
|
4099 |
TInt random; |
|
4100 |
TInt64 seed = now.Int64(); |
|
4101 |
random = Math::Rand( seed ); |
|
4102 |
// type conversions irrelevant - just creating a magic number for content id |
|
4103 |
target.Des().Num( random ); |
|
4104 |
target.Des().Insert(0, KMmsLeftAngle ); |
|
4105 |
target.Des().Append( KMmsRightAngle ); |
|
4106 |
cid.Set( target.Des() ); |
|
4107 |
// exclude the angle brackets |
|
4108 |
iMimeHeaders->SetContentIdL( cid.Mid( 1, cid.Length() - KMms2 ) ); |
|
4109 |
// save the cid to be present when we create the attachment headers |
|
4110 |
// If this does not succeed, the message will have no root. |
|
4111 |
MMsvAttachmentManagerSync& attachManSync = |
|
4112 |
store->AttachmentManagerExtensionsL(); |
|
4113 |
iMimeHeaders->StoreL( *attachmentInfo ); |
|
4114 |
attachManSync.ModifyAttachmentInfoL( attachmentInfo ); |
|
4115 |
// attachment manager now own attachemnt info |
|
4116 |
CleanupStack::Pop( attachmentInfo ); cleanupCount--; |
|
4117 |
store->CommitL(); |
|
4118 |
attachmentInfo = attachMan.GetAttachmentInfoL( (TMsvAttachmentId) aRootId ); |
|
4119 |
CleanupStack::PushL( attachmentInfo ); cleanupCount++; |
|
4120 |
} |
|
4121 |
||
4122 |
// add start header length & |
|
4123 |
// assigned number for start parameter, and terminating zero for cid |
|
4124 |
headerLength += cid.Length() + KMms2; |
|
4125 |
if ( cid.Find( KMmsLeftAngle ) != 0 ) |
|
4126 |
{ |
|
4127 |
headerLength += KMms2; // we must add angle bracket |
|
4128 |
} |
|
4129 |
||
4130 |
// Then the length of the content-type header... |
|
4131 |
TPtrC8 contentTypeString = iMimeHeaders->ContentType(); |
|
4132 |
||
4133 |
HBufC8* tempContentType = HBufC8::NewL( iMimeHeaders->ContentType().Length() + |
|
4134 |
iMimeHeaders->ContentSubType().Length() + 1 ); |
|
4135 |
CleanupStack::PushL( tempContentType ); |
|
4136 |
tempContentType->Des().Copy( iMimeHeaders->ContentType() ); |
|
4137 |
if ( ( iMimeHeaders->ContentType().Find( KMmsSlash8 ) != |
|
4138 |
( iMimeHeaders->ContentType().Length() - 1 ) ) && |
|
4139 |
( iMimeHeaders->ContentSubType().Find( KMmsSlash8 ) != 0 ) && |
|
4140 |
( iMimeHeaders->ContentSubType().Length() != 0 ) ) |
|
4141 |
{ |
|
4142 |
tempContentType->Des().Append( KMmsSlash8 ); |
|
4143 |
} |
|
4144 |
tempContentType->Des().Append( iMimeHeaders->ContentSubType() ); |
|
4145 |
attachmentInfo->SetMimeTypeL( tempContentType->Des() ); |
|
4146 |
CleanupStack::PopAndDestroy( tempContentType ); |
|
4147 |
contentTypeString.Set( attachmentInfo->MimeType() ); |
|
4148 |
||
4149 |
if ( contentTypeString.Length() == 0 ) |
|
4150 |
{ |
|
4151 |
// We need a content type... |
|
4152 |
// If we don't know, we say "Any" |
|
4153 |
contentTypeString.Set( KMmsAny ); |
|
4154 |
} |
|
4155 |
// Check if we have well-known media. |
|
4156 |
TInt8 rootContentType = -1; |
|
4157 |
||
4158 |
TInt8 i = 0; |
|
4159 |
for ( i = 0; i < KNumberContentTypes && rootContentType < 0; ++i ) |
|
4160 |
{ |
|
4161 |
if ( contentTypeString.CompareF( TPtrC8( KContentTypeTable[i] ) ) == 0 ) |
|
4162 |
{ |
|
4163 |
rootContentType = i; |
|
4164 |
} |
|
4165 |
} |
|
4166 |
||
4167 |
// start parameter assignment |
|
4168 |
headerLength += 1; |
|
4169 |
if ( rootContentType != -1 ) |
|
4170 |
{ |
|
4171 |
// well known content type |
|
4172 |
headerLength += 1; |
|
4173 |
} |
|
4174 |
else |
|
4175 |
{ |
|
4176 |
// string + terminating zero |
|
4177 |
headerLength += contentTypeString.Length() + 1; |
|
4178 |
} |
|
4179 |
||
4180 |
TPtrC8 appIdPtr; |
|
4181 |
appIdPtr.Set( KMmsJavaApplicationId ); |
|
4182 |
// Java application id parameters added to content-type |
|
4183 |
if ( iMmsHeaders->ApplicId().Length() > 0 ) |
|
4184 |
{ |
|
4185 |
headerLength += appIdPtr.Length() + 1 ; |
|
4186 |
headerLength += iMmsHeaders->ApplicId().Length() + 1; |
|
4187 |
} |
|
4188 |
appIdPtr.Set( KMmsJavaReplyApplicationId ); |
|
4189 |
if ( iMmsHeaders->ReplyApplicId().Length() > 0 ) |
|
4190 |
{ |
|
4191 |
headerLength += appIdPtr.Length() + 1 ; |
|
4192 |
headerLength += iMmsHeaders->ReplyApplicId().Length() + 1; |
|
4193 |
} |
|
4194 |
||
4195 |
// write general encoding length |
|
4196 |
EncodeValueLength( headerLength ); |
|
4197 |
||
4198 |
// Then the Media Type with parameters |
|
4199 |
||
4200 |
// We are multipart/related, which is a well-known media |
|
4201 |
// encode as short integer |
|
4202 |
TUint8 byte = KMmsAssignedApplicationVndWapMultipartRelated | KMms0x80; |
|
4203 |
iEncodeBuffer->Write( iPosition, &byte, 1 ); |
|
4204 |
iPosition++; |
|
4205 |
||
4206 |
// Then the start parameter and cid text string |
|
4207 |
byte = KWspStart | KMms0x80; |
|
4208 |
||
4209 |
if ( cid.Length() > 0 ) |
|
4210 |
{ |
|
4211 |
HBufC8* tempContentId = HBufC8::NewL( iMimeHeaders->ContentId().Length() + KMms2 ); |
|
4212 |
CleanupStack::PushL( tempContentId ); |
|
4213 |
if ( cid.Find( KMmsLeftAngle ) != 0 ) |
|
4214 |
{ |
|
4215 |
tempContentId->Des().Copy( KMmsLeftAngle ); |
|
4216 |
tempContentId->Des().Append( cid ); |
|
4217 |
tempContentId->Des().Append( KMmsRightAngle ); |
|
4218 |
} |
|
4219 |
else |
|
4220 |
{ |
|
4221 |
tempContentId->Des().Copy( cid ); |
|
4222 |
} |
|
4223 |
EncodeHeaderAndTextString( byte, tempContentId->Des() ); |
|
4224 |
CleanupStack::PopAndDestroy( tempContentId ); |
|
4225 |
} |
|
4226 |
||
4227 |
||
4228 |
// next the content type of the root part |
|
4229 |
byte = KWspRelatedType | KMms0x80; |
|
4230 |
// and the actual type either as a well-known media type |
|
4231 |
// or a text string. |
|
4232 |
||
4233 |
if ( rootContentType != -1 ) |
|
4234 |
{ |
|
4235 |
// Well known content type. |
|
4236 |
// EncodeMandatoryByte will set the high bit |
|
4237 |
EncodeMandatoryByte( byte, rootContentType ); |
|
4238 |
} |
|
4239 |
else |
|
4240 |
{ |
|
4241 |
// string + terminating zero |
|
4242 |
EncodeHeaderAndTextString( byte, contentTypeString ); |
|
4243 |
} |
|
4244 |
||
4245 |
if ( iMmsHeaders->ApplicId().Length() > 0 || |
|
4246 |
iMmsHeaders->ReplyApplicId().Length() > 0 ) |
|
4247 |
{ |
|
4248 |
EncodeApplicationIdParametersL(); |
|
4249 |
} |
|
4250 |
||
4251 |
// encode number of parts |
|
4252 |
EncodeUintvar( iNumberOfAttachments ); |
|
4253 |
||
4254 |
// get rid of stuff we put on stack |
|
4255 |
CleanupStack::PopAndDestroy( cleanupCount ); |
|
4256 |
} |
|
4257 |
||
4258 |
// --------------------------------------------------------- |
|
4259 |
// |
|
4260 |
// --------------------------------------------------------- |
|
4261 |
// |
|
4262 |
void CMmsEncode::EncodeMultipartMixedHeaderL() |
|
4263 |
{ |
|
4264 |
||
4265 |
// If Java has added application id or reply-to application id, |
|
4266 |
// even multipart/mxed type needs parameters. |
|
4267 |
||
4268 |
TUint headerLength = 0; // assume no parameters |
|
4269 |
||
4270 |
if ( iMmsHeaders->ApplicId().Length() > 0 || |
|
4271 |
iMmsHeaders->ReplyApplicId().Length() > 0 ) |
|
4272 |
{ |
|
4273 |
headerLength = 1; // one byte for well known media |
|
4274 |
TPtrC8 appIdPtr; |
|
4275 |
appIdPtr.Set( KMmsJavaApplicationId ); |
|
4276 |
if ( iMmsHeaders->ApplicId().Length() > 0 ) |
|
4277 |
{ |
|
4278 |
headerLength += appIdPtr.Length() + 1 ; |
|
4279 |
headerLength += iMmsHeaders->ApplicId().Length() + 1; |
|
4280 |
} |
|
4281 |
appIdPtr.Set( KMmsJavaReplyApplicationId ); |
|
4282 |
if ( iMmsHeaders->ReplyApplicId().Length() > 0 ) |
|
4283 |
{ |
|
4284 |
headerLength += appIdPtr.Length() + 1 ; |
|
4285 |
headerLength += iMmsHeaders->ReplyApplicId().Length() + 1; |
|
4286 |
} |
|
4287 |
} |
|
4288 |
||
4289 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedContentType, 1 ); |
|
4290 |
iPosition++; |
|
4291 |
||
4292 |
if ( headerLength > 0 ) |
|
4293 |
{ |
|
4294 |
// write general encoding length |
|
4295 |
EncodeValueLength( headerLength ); |
|
4296 |
} |
|
4297 |
||
4298 |
// encode as short integer |
|
4299 |
TUint8 contentType = KMmsAssignedApplicationVndWapMultipartMixed | KMms0x80; |
|
4300 |
iEncodeBuffer->Write( iPosition, &contentType, 1 ); |
|
4301 |
iPosition++; |
|
4302 |
||
4303 |
if ( iMmsHeaders->ApplicId().Length() > 0 || |
|
4304 |
iMmsHeaders->ReplyApplicId().Length() > 0 ) |
|
4305 |
{ |
|
4306 |
EncodeApplicationIdParametersL(); |
|
4307 |
} |
|
4308 |
||
4309 |
// No more parameters for multipart/mixed, actual parts follow |
|
4310 |
||
4311 |
// encode number of parts |
|
4312 |
EncodeUintvar( iNumberOfAttachments ); |
|
4313 |
||
4314 |
} |
|
4315 |
||
4316 |
// --------------------------------------------------------- |
|
4317 |
// |
|
4318 |
// --------------------------------------------------------- |
|
4319 |
// |
|
4320 |
void CMmsEncode::EncodeKeywordArrayL() |
|
4321 |
{ |
|
4322 |
TInt i = 0; |
|
4323 |
TInt length = 0; |
|
4324 |
||
4325 |
// caller must check that iMmsHeaders->ReadOnlyMMBoxMessageHeaders() is not NULL |
|
4326 |
CMmsMMBoxMessageHeaders& temp = iMmsHeaders->MMBoxMessageHeadersL(); |
|
4327 |
for ( i = 0; i < temp.KeywordArray().Count(); ++i ) |
|
4328 |
{ |
|
4329 |
length = temp.KeywordArray()[i]->Keyword().Length(); |
|
4330 |
if ( length > 0 ) |
|
4331 |
{ |
|
4332 |
iEncodeBuffer->Write( iPosition, &KMmsAssignedMMFlags, 1 ); |
|
4333 |
iPosition++; |
|
4334 |
// do some fake encoding to get the text length |
|
4335 |
TUint oldPosition = iPosition; // we will return here |
|
4336 |
EncodeTextStringL( temp.KeywordArray()[i]->Keyword() ); |
|
4337 |
length = iPosition - oldPosition; |
|
4338 |
iPosition = oldPosition; // return to original place |
|
4339 |
length += 1; // token must come before string |
|
4340 |
EncodeValueLength( length ); |
|
4341 |
TUint8 token = (TUint8) temp.KeywordArray()[i]->Token(); |
|
4342 |
if ( iMmsHeaders->MessageType() == KMmsMessageTypeMboxViewReq || |
|
4343 |
iMmsHeaders->MessageType() == KMmsMessageTypeMboxViewConf || |
|
4344 |
iMmsHeaders->MessageType() == KMmsMessageTypeMBoxDescr ) |
|
4345 |
{ |
|
4346 |
// the token must always be filter for MMbox PDUs |
|
4347 |
token = KMmsFilterToken; |
|
4348 |
} |
|
4349 |
iEncodeBuffer->Write( iPosition, &token, 1 ); |
|
4350 |
iPosition++; |
|
4351 |
EncodeTextStringL( temp.KeywordArray()[i]->Keyword() ); |
|
4352 |
} |
|
4353 |
} |
|
4354 |
} |
|
4355 |
||
4356 |
// --------------------------------------------------------- |
|
4357 |
// |
|
4358 |
// --------------------------------------------------------- |
|
4359 |
// |
|
4360 |
void CMmsEncode::EncodeOptionalInteger( TUint8 aHeader, TUint aValue ) |
|
4361 |
{ |
|
4362 |
if ( aValue == 0 ) |
|
4363 |
{ |
|
4364 |
return; // not set, nothing to encode, header is optional |
|
4365 |
} |
|
4366 |
||
4367 |
iEncodeBuffer->Write( iPosition, &aHeader, 1 ); |
|
4368 |
iPosition++; |
|
4369 |
||
4370 |
EncodeInteger( aValue ); |
|
4371 |
||
4372 |
} |
|
4373 |
||
4374 |
// --------------------------------------------------------- |
|
4375 |
// |
|
4376 |
// --------------------------------------------------------- |
|
4377 |
// |
|
4378 |
void CMmsEncode::EncodeAttributes( RArray<TUint>& aAttributeArray ) |
|
4379 |
{ |
|
4380 |
TInt i; |
|
4381 |
||
4382 |
for ( i = 0; i < aAttributeArray.Count(); ++i ) |
|
4383 |
{ |
|
4384 |
EncodeMandatoryByte( KMmsAssignedAttributes, aAttributeArray[i] ); |
|
4385 |
} |
|
4386 |
} |
|
4387 |
||
4388 |
// --------------------------------------------------------- |
|
4389 |
// |
|
4390 |
// --------------------------------------------------------- |
|
4391 |
// |
|
4392 |
void CMmsEncode::EncodeMMBoxStates( RArray<TInt>& aStateArray ) |
|
4393 |
{ |
|
4394 |
TInt i; |
|
4395 |
||
4396 |
for ( i = 0; i < aStateArray.Count(); ++i ) |
|
4397 |
{ |
|
4398 |
EncodeMandatoryByte( KMmsAssignedMMState, aStateArray[i] ); |
|
4399 |
} |
|
4400 |
} |
|
4401 |
||
4402 |
// --------------------------------------------------------- |
|
4403 |
// |
|
4404 |
// --------------------------------------------------------- |
|
4405 |
// |
|
4406 |
void CMmsEncode::EncodeContentLocationArray() |
|
4407 |
{ |
|
4408 |
TBool mustCheck = EFalse; |
|
4409 |
if ( iMmsHeaders->ContentLocation().Length() > 0 ) |
|
4410 |
{ |
|
4411 |
mustCheck = ETrue; |
|
4412 |
EncodeHeaderAndTextString( KMmsAssignedContentLocation, |
|
4413 |
iMmsHeaders->ContentLocation() ); |
|
4414 |
} |
|
4415 |
// If there is content location array, encode it, too. |
|
4416 |
// A content-location should never occur in both places, but we still check |
|
4417 |
||
4418 |
TInt i = 0; |
|
4419 |
if ( iMmsHeaders->ReadOnlyMMBoxMessageHeaders() ) |
|
4420 |
{ |
|
4421 |
for ( i = 0; |
|
4422 |
i < iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->ContentLocationList().Count(); |
|
4423 |
i++ ) |
|
4424 |
{ |
|
4425 |
if ( !( mustCheck && iMmsHeaders->ContentLocation().Compare( |
|
4426 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->ContentLocationList()[i] ) == 0 ) ) |
|
4427 |
{ |
|
4428 |
// the content location in the list does not appear as |
|
4429 |
// separate header, we must add it |
|
4430 |
EncodeHeaderAndTextString( KMmsAssignedContentLocation, |
|
4431 |
iMmsHeaders->ReadOnlyMMBoxMessageHeaders()->ContentLocationList()[i] ); |
|
4432 |
} |
|
4433 |
} |
|
4434 |
} |
|
4435 |
} |
|
4436 |
||
4437 |
// --------------------------------------------------------- |
|
4438 |
// |
|
4439 |
// --------------------------------------------------------- |
|
4440 |
// |
|
4441 |
void CMmsEncode::EncodeStartingHeaders( TInt aMessageType, |
|
4442 |
const TPtrC8& aTID, TInt aVersion ) |
|
4443 |
{ |
|
4444 |
// EncodeMandatoryByte will always set the high bit. |
|
4445 |
||
4446 |
// Message type |
|
4447 |
EncodeMandatoryByte( KMmsAssignedMessageType, aMessageType ); |
|
4448 |
// TID if present |
|
4449 |
EncodeOptionalString( KMmsAssignedTID, aTID ); |
|
4450 |
// MMS encapsulation version |
|
4451 |
EncodeMandatoryByte( KMmsAssignedMmsVersion, aVersion ); |
|
4452 |
} |
|
4453 |
||
4454 |
// --------------------------------------------------------- |
|
4455 |
// |
|
4456 |
// --------------------------------------------------------- |
|
4457 |
// |
|
4458 |
void CMmsEncode::EncodeApplicationIdParametersL() |
|
4459 |
{ |
|
4460 |
if ( iMmsHeaders->ApplicId().Length() > 0 ) |
|
4461 |
{ |
|
4462 |
EncodeTextString( KMmsJavaApplicationId ); |
|
4463 |
EncodeTextStringL( iMmsHeaders->ApplicId() ); |
|
4464 |
} |
|
4465 |
if ( iMmsHeaders->ReplyApplicId().Length() > 0 ) |
|
4466 |
{ |
|
4467 |
EncodeTextString( KMmsJavaReplyApplicationId ); |
|
4468 |
EncodeTextStringL( iMmsHeaders->ReplyApplicId() ); |
|
4469 |
} |
|
4470 |
} |
|
4471 |
||
4472 |
// --------------------------------------------------------- |
|
4473 |
// |
|
4474 |
// --------------------------------------------------------- |
|
4475 |
void CMmsEncode::Dump() |
|
4476 |
{ |
|
4477 |
// no dump if not logging |
|
4478 |
#ifndef _NO_MMSS_LOGGING_ |
|
4479 |
TInt error = KErrNone; |
|
4480 |
// if no can do, sorry. |
|
4481 |
TRAP( error, |
|
4482 |
{ |
|
4483 |
if ( iEntryWrapper ) |
|
4484 |
{ |
|
4485 |
if ( ( iEntryWrapper->GetDumpFlag() ) && |
|
4486 |
iEncodeBuffer && |
|
4487 |
iEncodeBuffer->Size() > 0 ) |
|
4488 |
{ |
|
4489 |
iFileName = KMmsDefaultLogDirectory; |
|
4490 |
TUint att; |
|
4491 |
if ( iFs.Att( iFileName, att ) == KErrNone ) |
|
4492 |
{ |
|
4493 |
_LIT( KRelated, "Sent.mms"); |
|
4494 |
iParse.Set( iFileName, &KRelated, NULL ); |
|
4495 |
iFileName = iParse.FullName(); |
|
4496 |
User::LeaveIfError( CApaApplication::GenerateFileName( |
|
4497 |
iFs, iFileName ) ); |
|
4498 |
RFile file; |
|
4499 |
User::LeaveIfError( file.Create( iFs, iFileName, |
|
4500 |
EFileWrite | EFileShareExclusive ) ); |
|
4501 |
// for message id generation |
|
4502 |
iParse.Set( iFileName, NULL, NULL ); |
|
4503 |
||
4504 |
// the data is supposed to be in the encode buffer |
|
4505 |
TPtr8 ptr = iEncodeBuffer->BackPtr( iPosition ); |
|
4506 |
file.Write( ptr ); |
|
4507 |
file.Flush(); |
|
4508 |
||
4509 |
// done - close files |
|
4510 |
file.Close(); |
|
4511 |
} |
|
4512 |
} |
|
4513 |
} |
|
4514 |
} |
|
4515 |
); |
|
4516 |
if ( error != KErrNone ) |
|
4517 |
{ |
|
4518 |
TMmsLogger::Log( _L("Dump left with error %d"), error ); |
|
4519 |
} |
|
4520 |
#endif |
|
4521 |
} |
|
4522 |
||
4523 |
// --------------------------------------------------------- |
|
4524 |
// |
|
4525 |
// --------------------------------------------------------- |
|
4526 |
void CMmsEncode::DumpAppend() |
|
4527 |
{ |
|
4528 |
||
4529 |
// no dump if not logging |
|
4530 |
#ifndef _NO_MMSS_LOGGING_ |
|
4531 |
TInt error = KErrNone; |
|
4532 |
// if no can do, sorry. |
|
4533 |
TRAP( error, |
|
4534 |
{ |
|
4535 |
if ( iEntryWrapper ) |
|
4536 |
{ |
|
4537 |
if ( ( iEntryWrapper->GetDumpFlag() ) && |
|
4538 |
iEncodeBuffer && |
|
4539 |
iEncodeBuffer->Size() > 0 ) |
|
4540 |
{ |
|
4541 |
iFileName = KMmsDefaultLogDirectory; |
|
4542 |
TUint att; |
|
4543 |
if ( iFs.Att( iFileName, att ) == KErrNone ) |
|
4544 |
{ |
|
4545 |
RFile file; |
|
4546 |
iFileName = iParse.FullName(); |
|
4547 |
User::LeaveIfError( file.Open( iFs, iFileName, |
|
4548 |
EFileWrite | EFileShareExclusive ) ); |
|
4549 |
TInt position = 0; // seek to end |
|
4550 |
file.Seek( ESeekEnd, position ); |
|
4551 |
// the data is supposed to be in the encode buffer |
|
4552 |
TPtr8 ptr = iEncodeBuffer->BackPtr( iPosition ); |
|
4553 |
file.Write( ptr ); |
|
4554 |
file.Flush(); |
|
4555 |
// done - close files |
|
4556 |
file.Close(); |
|
4557 |
} |
|
4558 |
} |
|
4559 |
} |
|
4560 |
} |
|
4561 |
); |
|
4562 |
if ( error != KErrNone ) |
|
4563 |
{ |
|
4564 |
TMmsLogger::Log( _L("DumpAppend left with error %d"), error ); |
|
4565 |
} |
|
4566 |
#endif |
|
4567 |
} |
|
4568 |
||
4569 |
// --------------------------------------------------------- |
|
4570 |
// |
|
4571 |
// --------------------------------------------------------- |
|
4572 |
void CMmsEncode::EncodeApplicationHeadersL() |
|
4573 |
{ |
|
4574 |
// Application headers are only supported in WINS for testing purposes |
|
4575 |
// Complete support for routing messages to arbitrary applications |
|
4576 |
// requires support for selecting which applications are allowed |
|
4577 |
// to send messages etc. |
|
4578 |
#ifdef __WINS__ |
|
4579 |
// The optional string functions check the length |
|
4580 |
// and return without doing anything if the length of the string is 0 |
|
4581 |
if ( IsStringSafe( iMmsHeaders->ApplicId() ) ) |
|
4582 |
{ |
|
4583 |
// We only send this header if it is us-ascii only |
|
4584 |
// There is no encoding defined, so if this is converted |
|
4585 |
// from unicode to some other character set there is |
|
4586 |
// no guarantee that the recipient can decode it. |
|
4587 |
EncodeOptionalStringL( KMmsAssignedApplicId, iMmsHeaders->ApplicId() ); |
|
4588 |
} |
|
4589 |
||
4590 |
if ( IsStringSafe( iMmsHeaders->ReplyApplicId() ) ) |
|
4591 |
{ |
|
4592 |
EncodeOptionalStringL( KMmsAssignedReplyApplicId, iMmsHeaders->ReplyApplicId() ); |
|
4593 |
} |
|
4594 |
||
4595 |
EncodeOptionalString( KMmsAssignedAuxApplicInfo, iMmsHeaders->AuxApplicInfo() ); |
|
4596 |
#endif |
|
4597 |
} |
|
4598 |
||
4599 |
// --------------------------------------------------------- |
|
4600 |
// |
|
4601 |
// --------------------------------------------------------- |
|
4602 |
void CMmsEncode::EncodeCancelRequest() |
|
4603 |
{ |
|
4604 |
// implemented for test purposes |
|
4605 |
#ifdef __WINS__ |
|
4606 |
// Insert message type, TID and version number |
|
4607 |
EncodeStartingHeaders( KMmsMessageTypeCancelReq, |
|
4608 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
4609 |
||
4610 |
EncodeOptionalString( KMmsAssignedCancelId, iMmsHeaders->ReplaceCancelId() ); |
|
4611 |
#endif |
|
4612 |
} |
|
4613 |
||
4614 |
// --------------------------------------------------------- |
|
4615 |
// |
|
4616 |
// --------------------------------------------------------- |
|
4617 |
void CMmsEncode::EncodeCancelResponse() |
|
4618 |
{ |
|
4619 |
// Insert message type, TID and version number |
|
4620 |
EncodeStartingHeaders( KMmsMessageTypeCancelConf, |
|
4621 |
iMmsHeaders->Tid(), iMmsHeaders->MmsVersion() ); |
|
4622 |
||
4623 |
EncodeOptionalByte( KMmsAssignedCancelStatus, iMmsHeaders->CancelStatus() ); |
|
4624 |
} |
|
4625 |
||
4626 |
// --------------------------------------------------------- |
|
4627 |
// |
|
4628 |
// --------------------------------------------------------- |
|
4629 |
HBufC8* CMmsEncode::EncodeQuotedPrintableWordL( const TPtrC8& aSource ) |
|
4630 |
{ |
|
4631 |
// We have calculated that it fits |
|
4632 |
||
4633 |
TInt bufferLength = KMaxNameBufferLength; |
|
4634 |
||
4635 |
HBufC8* buffer = HBufC8::NewL( bufferLength ); |
|
4636 |
CleanupStack::PushL( buffer ); |
|
4637 |
TPtr8 ptr = buffer->Des(); |
|
4638 |
buffer->Des().Copy( KMmsQuotedPreamble ); |
|
4639 |
ptr.SetLength( bufferLength ); |
|
4640 |
TPtr8 encodeBuffer = ptr.MidTPtr( KMmsPreambleLength ); |
|
4641 |
encodeBuffer.SetLength( 0 ); // empty the buffer |
|
4642 |
||
4643 |
TImCodecQP encoder; |
|
4644 |
||
4645 |
// The function would return the number of characters written to the buffer. |
|
4646 |
// We don't do anything with the result, so we ignore the return value. |
|
4647 |
encoder.Encode( aSource, encodeBuffer ); |
|
4648 |
||
4649 |
ptr.SetLength( encodeBuffer.Length() + KMmsPreambleLength ); |
|
4650 |
||
4651 |
buffer->Des().Append( KMmsEncodingTrailer ); |
|
4652 |
CleanupStack::Pop( buffer ); |
|
4653 |
return buffer; |
|
4654 |
} |
|
4655 |
||
4656 |
// --------------------------------------------------------- |
|
4657 |
// |
|
4658 |
// --------------------------------------------------------- |
|
4659 |
HBufC8* CMmsEncode::EncodeBase64WordL( const TPtrC8& aSource ) |
|
4660 |
{ |
|
4661 |
// ((length + 2)/3)*4 3 bytes alwaus produces 4 encoded bytes. Allow filler |
|
4662 |
TInt bufferLength = KMmsEncodingExtraLength + ( aSource.Length() + KMms2 ) / KMms3 * KMms4; |
|
4663 |
||
4664 |
HBufC8* buffer = HBufC8::NewL( bufferLength ); |
|
4665 |
CleanupStack::PushL( buffer ); |
|
4666 |
TPtr8 ptr = buffer->Des(); |
|
4667 |
buffer->Des().Copy( KMmsBase64Preamble ); |
|
4668 |
ptr.SetLength( bufferLength ); |
|
4669 |
||
4670 |
TPtr8 encodeBuffer = ptr.MidTPtr( KMmsPreambleLength ); |
|
4671 |
encodeBuffer.SetLength( 0 ); // empty the buffer |
|
4672 |
||
4673 |
TImCodecB64 encoder; |
|
4674 |
||
4675 |
// It is rather unclear what this function actually returns (no documentation found). |
|
4676 |
// Therefore we just ignore the result. |
|
4677 |
// Our buffer is long enough for the result to always fit. |
|
4678 |
encoder.Encode( aSource, encodeBuffer ); |
|
4679 |
||
4680 |
ptr.SetLength( encodeBuffer.Length() + KMmsPreambleLength ); |
|
4681 |
||
4682 |
buffer->Des().Append( KMmsEncodingTrailer ); |
|
4683 |
CleanupStack::Pop( buffer ); |
|
4684 |
return buffer; |
|
4685 |
} |
|
4686 |
||
4687 |
||
4688 |
// --------------------------------------------------------- |
|
4689 |
// CMmsEncode::PreProcessAttachmentDataL |
|
4690 |
// Open the message store(Edit mode) and process attachments for further encoding in required encoding type. |
|
4691 |
// Update the message store accordingly with the new encoding type and data in the corresponding attachments. |
|
4692 |
// --------------------------------------------------------- |
|
4693 |
void CMmsEncode::PreProcessAttachmentDataL() |
|
4694 |
{ |
|
4695 |
TInt error = KErrNone; |
|
4696 |
RFile attachFile; |
|
4697 |
TBool retVal = EFalse; |
|
4698 |
TInt currAttachI; |
|
4699 |
||
4700 |
#ifndef _NO_MMSS_LOGGING_ |
|
4701 |
TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentDataL- start ") ); |
|
4702 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4703 |
CMsvStore* editStore = iEntryWrapper->EditStoreL(); |
|
4704 |
CleanupStack::PushL( editStore ); |
|
4705 |
||
4706 |
MMsvAttachmentManager& attachMan = editStore->AttachmentManagerL(); |
|
4707 |
MMsvAttachmentManagerSync& attachManagerSync = editStore->AttachmentManagerExtensionsL(); |
|
4708 |
TInt numberOfAttachments = attachMan.AttachmentCount(); |
|
4709 |
CMsvAttachment* attachmentInfo = NULL; |
|
4710 |
iTextUtils = CMsgTextUtils::NewL( iFs ); |
|
4711 |
||
4712 |
for ( currAttachI = 0; ( currAttachI < numberOfAttachments ) && ( error == KErrNone ); currAttachI++ ) |
|
4713 |
{ |
|
4714 |
//gets the ownership from attachment manager |
|
4715 |
attachmentInfo = attachMan.GetAttachmentInfoL( currAttachI ); |
|
4716 |
CleanupStack::PushL( attachmentInfo ); |
|
4717 |
iMimeHeaders->RestoreL( *attachmentInfo ); |
|
4718 |
#ifndef _NO_MMSS_LOGGING_ |
|
4719 |
TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentDataL- Attchment:%d "), currAttachI ); |
|
4720 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4721 |
||
4722 |
if ( iFileOpen ) |
|
4723 |
{ |
|
4724 |
// close any file in case we have been reset while the file is still open |
|
4725 |
iAttachFile.Close(); |
|
4726 |
iFileOpen = EFalse; |
|
4727 |
} |
|
4728 |
||
4729 |
retVal = CheckAndUpdateAttachmentL(*attachmentInfo, *iMimeHeaders); |
|
4730 |
||
4731 |
if( retVal ) |
|
4732 |
{ |
|
4733 |
TRAPD( |
|
4734 |
err, |
|
4735 |
attachManagerSync.ModifyAttachmentInfoL(attachmentInfo); |
|
4736 |
editStore->CommitL(); |
|
4737 |
); |
|
4738 |
#ifndef _NO_MMSS_LOGGING_ |
|
4739 |
if(err != KErrNone) |
|
4740 |
{ |
|
4741 |
TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentData:: store commit error: %d"), err ); |
|
4742 |
} |
|
4743 |
else |
|
4744 |
{ |
|
4745 |
TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentData:: store commit success") ); |
|
4746 |
} |
|
4747 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4748 |
/* attachmentInfo ownership is transferred to attachment manager |
|
4749 |
* Hence, JUST pop attachmentInfo, DO NOT Destroy. |
|
4750 |
*/ |
|
4751 |
CleanupStack::Pop( attachmentInfo ); |
|
4752 |
} |
|
4753 |
else |
|
4754 |
{ |
|
4755 |
CleanupStack::PopAndDestroy( attachmentInfo ); |
|
4756 |
attachmentInfo = NULL; |
|
4757 |
#ifndef _NO_MMSS_LOGGING_ |
|
4758 |
TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentData:: Tgt encoding NOT Reqd.") ); |
|
4759 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4760 |
} |
|
4761 |
} |
|
4762 |
CleanupStack::PopAndDestroy( editStore ); |
|
4763 |
||
4764 |
delete iTextUtils; |
|
4765 |
iTextUtils = NULL; |
|
4766 |
#ifndef _NO_MMSS_LOGGING_ |
|
4767 |
TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentDataL- end ") ); |
|
4768 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4769 |
} |
|
4770 |
||
4771 |
// --------------------------------------------------------- |
|
4772 |
// CMmsEncode::CheckAndUpdateAttachmentL |
|
4773 |
// Check and proceed if given attachment can be encoded using target encoding type based on its content type. |
|
4774 |
// Returns False if target encoding is not supported for this content type. |
|
4775 |
// --------------------------------------------------------- |
|
4776 |
TBool CMmsEncode::CheckAndUpdateAttachmentL( CMsvAttachment& aAttachmentInfo, |
|
4777 |
CMsvMimeHeaders& aMimeHeaders ) |
|
4778 |
{ |
|
4779 |
//get the content type string... and set to attachment if required |
|
4780 |
TInt contentType = -1; // indicate not found |
|
4781 |
TPtrC8 contentTypeString; |
|
4782 |
TBool retVal = EFalse; |
|
4783 |
#ifndef _NO_MMSS_LOGGING_ |
|
4784 |
TMmsLogger::Log( _L("CMmsEncode::CheckAndUpdateAttachmentL- start ") ); |
|
4785 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4786 |
||
4787 |
HBufC8* tempContentType = NULL; |
|
4788 |
contentTypeString.Set( aAttachmentInfo.MimeType() ); |
|
4789 |
if ( contentTypeString.Length() == 0 ) |
|
4790 |
{ |
|
4791 |
// take type from mime headers |
|
4792 |
TInt cotentLength = aMimeHeaders.ContentType().Length(); |
|
4793 |
TInt subCotentLength = aMimeHeaders.ContentSubType().Length(); |
|
4794 |
tempContentType = HBufC8::NewL( cotentLength + subCotentLength + 1 ); |
|
4795 |
CleanupStack::PushL( tempContentType ); |
|
4796 |
tempContentType->Des().Copy( aMimeHeaders.ContentType() ); |
|
4797 |
if ( ( aMimeHeaders.ContentType().Find( KMmsSlash8 ) != ( cotentLength - 1 ) ) && |
|
4798 |
( aMimeHeaders.ContentSubType().Find( KMmsSlash8 ) != 0 ) && ( subCotentLength != 0 ) ) |
|
4799 |
{ |
|
4800 |
tempContentType->Des().Append( KMmsSlash8 ); |
|
4801 |
} |
|
4802 |
tempContentType->Des().Append( aMimeHeaders.ContentSubType() ); |
|
4803 |
aAttachmentInfo.SetMimeTypeL( tempContentType->Des() ); |
|
4804 |
contentTypeString.Set( aAttachmentInfo.MimeType() ); |
|
4805 |
} |
|
4806 |
||
4807 |
//map the content type string to content type |
|
4808 |
TInt8 i; |
|
4809 |
for ( i = 0; i < KNumberContentTypes && contentType < 0; i++ ) |
|
4810 |
{ |
|
4811 |
if ( contentTypeString.CompareF( TPtrC8( KContentTypeTable[i] ) ) == 0 ) |
|
4812 |
{ |
|
4813 |
contentType = i; |
|
4814 |
} |
|
4815 |
} |
|
4816 |
#ifndef _NO_MMSS_LOGGING_ |
|
4817 |
TMmsLogger::Log( _L("CMmsEncode::CheckAndUpdateAttachmentL- content type:%d" ), contentType ); |
|
4818 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4819 |
//check if this content type need to be encoded using korean specific |
|
4820 |
if( IsConversionSupportedContentType( contentType ) ) |
|
4821 |
{ |
|
4822 |
/* Do the attachment data conversion from "src type" to "target type" for the given "attached file". |
|
4823 |
* Target type encodng MIB enum is obtained from cenrep. |
|
4824 |
*/ |
|
4825 |
retVal = ProcessAndConvertAttachmentDataL( aMimeHeaders.MimeCharset(), |
|
4826 |
iTargetEncodingType, |
|
4827 |
aAttachmentInfo); |
|
4828 |
if( retVal ) |
|
4829 |
{ |
|
4830 |
#ifndef _NO_MMSS_LOGGING_ |
|
4831 |
TMmsLogger::Log( _L("CMmsEncode::CheckAndUpdateAttachmentL- conv success: Tgt Enc: %d"), iTargetEncodingType ); |
|
4832 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4833 |
//set new charset type in headers and update attachment info |
|
4834 |
aMimeHeaders.SetMimeCharset( iTargetEncodingType ); |
|
4835 |
aMimeHeaders.StoreL(aAttachmentInfo); // save the new charset to attachment as well |
|
4836 |
/* mimetype might get reset to original mimeheader content type. |
|
4837 |
* ensure the full content type(if created from mime content and subcontent) is set to attachment |
|
4838 |
*/ |
|
4839 |
if( tempContentType != NULL ) |
|
4840 |
{ |
|
4841 |
aAttachmentInfo.SetMimeTypeL( tempContentType->Des() ); |
|
4842 |
CleanupStack::PopAndDestroy( tempContentType ); |
|
4843 |
} |
|
4844 |
} |
|
4845 |
} |
|
4846 |
#ifndef _NO_MMSS_LOGGING_ |
|
4847 |
TMmsLogger::Log( _L("CMmsEncode::CheckAndUpdateAttachmentL- End , retVal: %d"), retVal ); |
|
4848 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4849 |
return retVal; |
|
4850 |
} |
|
4851 |
||
4852 |
// --------------------------------------------------------- |
|
4853 |
// CMmsEncode::ProcessAndConvertAttachmentDataL |
|
4854 |
// converts of attachment data from source to target encoding type. |
|
4855 |
// |src charset buffer| --->converted to ---> |unicode buffer| ---> converted to ---> |target charset| |
|
4856 |
// Returns false if data is already int target format, or plugins are missing, or file operation issues. |
|
4857 |
// --------------------------------------------------------- |
|
4858 |
TBool CMmsEncode::ProcessAndConvertAttachmentDataL( TUint aSrcCharSetMIBEnum, |
|
4859 |
TUint aTargetCharSetMIBEnum, |
|
4860 |
CMsvAttachment& aAttachmentInfo) |
|
4861 |
{ |
|
4862 |
#ifndef _NO_MMSS_LOGGING_ |
|
4863 |
TMmsLogger::Log( _L("CMmsEncode::ProcessAndConvertAttachmentDataL- start ") ); |
|
4864 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4865 |
if( aSrcCharSetMIBEnum == aTargetCharSetMIBEnum ) |
|
4866 |
{ |
|
4867 |
#ifndef _NO_MMSS_LOGGING_ |
|
4868 |
TMmsLogger::Log( _L("CMmsEncode::ProcessAndConvertAttachmentDataL- src and dest are same ") ); |
|
4869 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4870 |
//if source and target charset MIB enums are same. |
|
4871 |
return EFalse; // no conversion |
|
4872 |
} |
|
4873 |
||
4874 |
//get source and target charset mapping here. if any error, return |
|
4875 |
TUint srcCharSetId = iTextUtils->MibIdToCharconvIdL( aSrcCharSetMIBEnum ); |
|
4876 |
TUint targetCharSetId = iTextUtils->MibIdToCharconvIdL( aTargetCharSetMIBEnum ); |
|
4877 |
if( srcCharSetId == targetCharSetId || KDefaultCharConvCharset == targetCharSetId) |
|
4878 |
{ |
|
4879 |
/* If target charset plugin is missing, then default is returned. |
|
4880 |
Do not encode to any target encoding type, send data as is . |
|
4881 |
*/ |
|
4882 |
#ifndef _NO_MMSS_LOGGING_ |
|
4883 |
TMmsLogger::Log( _L("CMmsEncode::ProcessAndConvertAttachmentDataL- missing plugin: Tgt Charset %x"), targetCharSetId ); |
|
4884 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4885 |
return EFalse; |
|
4886 |
} |
|
4887 |
||
4888 |
RFile attachFile; |
|
4889 |
TInt error; |
|
4890 |
||
4891 |
const TDesC& fileName = aAttachmentInfo.FilePath(); |
|
4892 |
error = attachFile.Open(iFs, fileName, EFileWrite); |
|
4893 |
if(error != KErrNone) |
|
4894 |
{ |
|
4895 |
#ifndef _NO_MMSS_LOGGING_ |
|
4896 |
TMmsLogger::Log( _L("CMmsEncode::ProcessAndConvertAttachmentData:: file: %s, open error: %d"), fileName, error ); |
|
4897 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4898 |
attachFile.Close(); |
|
4899 |
return EFalse; |
|
4900 |
} |
|
4901 |
||
72
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
44
diff
changeset
|
4902 |
TInt maxLength=0; |
31 | 4903 |
error = attachFile.Size(maxLength); |
4904 |
if( error != KErrNone || maxLength == 0 ) |
|
4905 |
{ |
|
4906 |
#ifndef _NO_MMSS_LOGGING_ |
|
4907 |
TMmsLogger::Log( _L("CMmsEncode::ProcessAndConvertAttachmentData:: file size: %d, error: %d"), maxLength, error ); |
|
4908 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4909 |
attachFile.Close(); |
|
4910 |
return EFalse; |
|
4911 |
} |
|
4912 |
||
4913 |
//read the original file data into srcBuffer |
|
4914 |
TInt cleanupCount = 0; |
|
4915 |
HBufC8* srcBuffer = HBufC8::NewLC( maxLength ); |
|
4916 |
cleanupCount++; |
|
4917 |
||
4918 |
TPtr8 srcPtr = srcBuffer->Des(); |
|
4919 |
attachFile.Read( srcPtr, maxLength ); |
|
4920 |
||
4921 |
//intermediate buffer in the form of unicode. |
|
4922 |
HBufC16* unicodeBuffer(NULL); |
|
4923 |
||
4924 |
//Convert, scrBuffer to unicode format if not already in unicode format |
|
4925 |
if(srcCharSetId != 0) |
|
4926 |
{ |
|
4927 |
//Convert from respective foreign charset to unicode buffer. |
|
4928 |
//returns buf16 pointer descriptor |
|
4929 |
TRAPD(err, unicodeBuffer = iTextUtils->ConvertToUnicodeL(srcPtr, srcCharSetId) ); |
|
4930 |
if( err != KErrNone ) |
|
4931 |
{ |
|
4932 |
#ifndef _NO_MMSS_LOGGING_ |
|
4933 |
TMmsLogger::Log( _L("CMmsEncode::ProcessAndConvertAttachmentData:: ConvertToUnicodeL error: %d"), err ); |
|
4934 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4935 |
delete unicodeBuffer; |
|
4936 |
attachFile.Close(); |
|
4937 |
CleanupStack::PopAndDestroy( cleanupCount, srcBuffer ); // srcBuffer |
|
4938 |
return EFalse; |
|
4939 |
} |
|
4940 |
CleanupStack::PushL( unicodeBuffer ); |
|
4941 |
cleanupCount++; |
|
4942 |
} |
|
4943 |
else |
|
4944 |
{ |
|
4945 |
TInt unicodeStdHeaderWordLE = 0xFEFF; |
|
4946 |
TInt unicodeStdHeaderWordBE = 0xFFFE; |
|
4947 |
//data is already in unicode format. need to extract the data to 16-bit buffer |
|
4948 |
unicodeBuffer = HBufC16::NewLC( maxLength/2 );//maxlength value is in terms of bytes |
|
4949 |
cleanupCount++; |
|
4950 |
||
4951 |
TPtr16 ptr = unicodeBuffer->Des(); |
|
4952 |
iTextUtils->ConvertPtrToDesC16(srcPtr, ptr); |
|
4953 |
/* In case if attachment is UTF-16 format, it will have the UTF-16 representation word(2 butes) |
|
4954 |
* at the start. Find and delete it before passing the data for conversion |
|
4955 |
*/ |
|
4956 |
if( ptr[0] == unicodeStdHeaderWordLE || ptr[0] == unicodeStdHeaderWordBE ) |
|
4957 |
{ |
|
4958 |
ptr.Delete(0, 1); |
|
4959 |
} |
|
4960 |
} |
|
4961 |
||
4962 |
//Now convert unicode buffer to respective target charset type. |
|
4963 |
if( targetCharSetId != 0 ) |
|
4964 |
{ |
|
4965 |
// reset this file and write new encoded data to it directly |
|
4966 |
error = attachFile.SetSize(0); |
|
4967 |
#ifndef _NO_MMSS_LOGGING_ |
|
4968 |
if( error != KErrNone ) |
|
4969 |
{ |
|
4970 |
TMmsLogger::Log( _L("CMmsEncode::ProcessAndConvertAttachmentData:: file size: %d, error: %d"), maxLength, error ); |
|
4971 |
//attachFile.Close(); |
|
4972 |
//return EFalse; |
|
4973 |
} |
|
4974 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
4975 |
||
4976 |
/* convert to target charset id. |
|
4977 |
* Ideally, this should not leave with plugin-NOT-found, since it it already verified |
|
4978 |
*/ |
|
4979 |
iTextUtils->ConvertToFileL(*unicodeBuffer, attachFile, targetCharSetId ); |
|
4980 |
} |
|
4981 |
else |
|
4982 |
{ |
|
4983 |
TPtr16 ptr = unicodeBuffer->Des(); |
|
4984 |
//Reset/erase old file content. |
|
4985 |
TInt err = attachFile.SetSize(0); |
|
4986 |
||
4987 |
//write new encoded data to file using write stream |
|
4988 |
RFileWriteStream writer( attachFile ); |
|
4989 |
writer.PushL(); |
|
4990 |
writer.WriteL( ptr ); |
|
4991 |
//writer.CommitL(); |
|
4992 |
writer.Pop(); |
|
4993 |
writer.Close(); |
|
4994 |
} |
|
4995 |
//close file |
|
4996 |
attachFile.Close(); |
|
4997 |
CleanupStack::PopAndDestroy( cleanupCount, srcBuffer ); //unicodeBuffer, srcBuffer |
|
4998 |
#ifndef _NO_MMSS_LOGGING_ |
|
4999 |
TMmsLogger::Log( _L("CMmsEncode::ProcessAndConvertAttachmentDataL- End, retVal: TRUE") ); |
|
5000 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
5001 |
return ETrue; |
|
5002 |
} |
|
5003 |
||
5004 |
||
5005 |
// --------------------------------------------------------- |
|
5006 |
// CMmsEncode::IsConversionSupportedContentType |
|
5007 |
// checks if input content type is supported for target encoding |
|
5008 |
// --------------------------------------------------------- |
|
5009 |
TBool CMmsEncode::IsConversionSupportedContentType( TInt aContentType ) |
|
5010 |
{ |
|
5011 |
/* Currently only "text/plain" content types are supported for korean encoding. |
|
5012 |
* Add to the switch case, if any new content type can be supported as well. |
|
5013 |
* |
|
5014 |
* IMPORTANT: |
|
5015 |
* Ensure the values added map to corresponding content type entry in the table KContentTypeTable[], |
|
5016 |
* defined in ../inc/mmscodec.h |
|
5017 |
*/ |
|
5018 |
#ifndef _NO_MMSS_LOGGING_ |
|
5019 |
TMmsLogger::Log( _L("CMmsEncode::IsConversionSupportedContentType- start: %d "), aContentType ); |
|
5020 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
5021 |
TBool retVal = EFalse; |
|
5022 |
switch( aContentType ) |
|
5023 |
{ |
|
5024 |
case 0x03 : // "text/plain" |
|
5025 |
{ |
|
5026 |
retVal = ETrue; |
|
5027 |
break; |
|
5028 |
} |
|
5029 |
default: |
|
5030 |
//do nothing |
|
5031 |
break;// to avoid compile errors/warning |
|
5032 |
} |
|
5033 |
#ifndef _NO_MMSS_LOGGING_ |
|
5034 |
TMmsLogger::Log( _L("CMmsEncode::IsConversionSupportedContentType- end ") ); |
|
5035 |
#endif /* _NO_MMSS_LOGGING_ */ |
|
5036 |
return retVal; |
|
5037 |
} |
|
5038 |
||
5039 |
// ================= OTHER EXPORTED FUNCTIONS ============== |
|
5040 |
||
5041 |
// End of File |