3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
38 #include "MsgException.h"
39 #include "MmsPluginMessage.h"
40 #include "MmsPluginStorage.h"
41 #include "MsgUtilFile.h"
42 #include "MmsPluginCodec.h"
43 #include "MmsPluginDebug.h"
44 #include "MsgSettingTypes.h"
45 #include "MsgSettingHandler.h"
46 #include "MmsPluginInternal.h"
47 #include "MmsPluginAvCodec.h"
48 #include "MmsPluginStorage.h"
49 #include "MmsPluginSmil.h"
50 #ifdef __SUPPORT_DRM__
51 #include "MmsPluginDrm.h"
52 #include "MsgDrmWrapper.h"
53 #include "drm-service.h"
57 static bool _MmsBinaryDecodeGetBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength); /* bufLen < gMmsDecodeMaxLen */
58 static bool _MmsBinaryDecodeGetLongBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength); /* no bufLen limit */
59 static bool _MmsBinaryDecodeGetOneByte(FILE *pFile, UINT8 *pOneByte, int totalLength);
61 static int __MmsBinaryDecodeUintvar(FILE *pFile, UINT32 *pUintVar, int totalLength);
62 static int __MmsDecodeValueLength(FILE *pFile, UINT32 *pValueLength, int totalLength);
63 static int __MmsDecodeValueLength2(FILE *pFile, UINT32 *pValueLength, int totalLength);
64 static int __MmsBinaryDecodeQuotedString(FILE *pFile, char *szBuff, int bufLen, int totalLength);
65 static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen, int totalLength);
66 static bool __MmsBinaryDecodeInteger(FILE *pFile, UINT32 *pInteger, int *pIntLen, int totalLength);
67 static bool __MmsBinaryDecodeCharset(FILE *pFile, UINT32 *nCharSet, int *pCharSetLen, int totalLength);
68 static char *__MmsBinaryDecodeText2(FILE *pFile, int totalLength, int *pLength);
69 static int __MmsBinaryDecodeText(FILE *pFile, char *szBuff, int bufLen, int totalLength);
70 static UINT32 __MmsHeaderDecodeIntegerByLength(FILE *pFile, UINT32 length, int totalLength);
71 static bool __MmsDecodeLongInteger(FILE *pFile, UINT32 *pLongInteger, int totalLength);
72 static int __MmsDecodeGetFilename(FILE *pFile, char *szBuff, int bufLen, int totalLength);
73 static MsgHeaderAddress *__MmsDecodeEncodedAddress(FILE *pFile, int totalLength);
75 #ifdef __SUPPORT_DRM__
76 bool __MmsParseDCFInfo(FILE *pFile, MsgDRMInfo *pDrmInfo, int totalLength);
77 bool __MmsParseDCFHdr(FILE *pFile, MsgDRMInfo *pDrmInfo, UINT32 headerLen, int totalLength);
78 bool MmsBinaryDecodeDRMMessage(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int fullBodyLength, int totalLength);
79 bool MmsBinaryDecodeDRMContent(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int bodyLength, int totalLength);
82 static bool MmsBinaryDecodeMovePointer(FILE *pFile, int offset, int totalLength);
83 bool MmsBinaryIsTextEncodedPart(FILE *pFile, int totalLength);
84 static bool __MmsBinaryDecodeCheckAndDecreaseLength(int *pLength, int valueLength);
86 bool __MmsTextDecodeMsgHeader(FILE *pFile);
87 bool MmsTextDecodeMsgBody(FILE *pFile);
89 char gszMmsLoadBuf1[MSG_MMS_DECODE_BUFFER_MAX + 1] = {0, };
90 char gszMmsLoadBuf2[MSG_MMS_DECODE_BUFFER_MAX + 1] = {0, };
92 static char *gpCurMmsDecodeBuff = NULL;
93 static int gCurMmsDecodeBuffPos = 0; /* next decoding position in gpCurMmsDecodeBuff */
94 static int gMmsDecodeMaxLen = 0;
95 static int gMmsDecodeCurOffset = 0; /* current offset in file (last read) */
96 static int gMmsDecodeBufLen = 0; /* number of last read characters */
98 static char *gpMmsDecodeBuf1 = NULL;
99 static char *gpMmsDecodeBuf2 = NULL;
101 MmsHeader mmsHeader =
107 (MmsMsgType)MMS_MSGTYPE_ERROR, //MmsMsgType iType;
109 //"", //short int version;
110 0, //short int version;
113 NULL, //MsgHeaderAddress* pFrom;
114 NULL, //MsgHeaderAddress* pTo;
115 NULL, //MsgHeaderAddress* pCc;
116 NULL, //MsgHeaderAddress* pBcc;
117 "", //char[] szSubject;
118 (MmsResponseStatus)MMS_RESPSTATUS_OK, //MmsResponseStatus iResponseStatus;
119 (MmsRetrieveStatus)MMS_RETRSTATUS_OK, //MmsRetrieveStatus iRetrieveStatus;
120 "", //char[] szResponseText;
121 "", //char[] szRetrieveText;
124 /* has default value in specification */
126 (MmsMsgClass)MMS_MSGCLASS_PERSONAL, //MmsMsgClass msgClass;
127 {MMS_TIMETYPE_RELATIVE, 0}, //MmsTimeStruct expiryTime;
128 {MMS_TIMETYPE_RELATIVE, 0}, //MmsTimeStruct deliveryTime;
129 (MmsPriority)MMS_PRIORITY_NORMAL, //MmsPriority priority; // Refer [OMA-MMS-ENC-v1_2-20030915-C]
130 (MmsSenderVisible)MMS_SENDER_SHOW, //MmsSenderVisible senderVisible;
131 (MmsReport)MMS_REPORT_NO, //MmsReport deliveryReport;
132 (MmsReport)MMS_REPORT_NO, //MmsReport readReply;
133 (MmsReportAllowed)MMS_REPORTALLOWED_NO,//MmsReportAllowed iReportAllowed;
134 "", //char[] szContentLocation;
137 /* there is no right default value */
139 (MSG_DELIVERY_REPORT_STATUS_T)MSG_DELIVERY_REPORT_NONE, //MmsMsgStatus iMsgStatus;
140 (MSG_READ_REPORT_STATUS_T)MSG_READ_REPORT_NONE, //MmsReadStatus readStatus;
142 /* MMS v1.1 ReplyCharge */
144 (MmsReplyChargeType)MMS_REPLY_NONE, //MmsReplyChargeType chargeType;
145 {MMS_TIMETYPE_RELATIVE, 0}, //MmsTimeStruct deadLine;
147 "" , //char szChargeID;
150 "", //char[] szMsgID;
154 #ifdef __SUPPORT_DRM__
156 #define MMS_DRM2_CONVERT_BUFFER_MAX 4*1024
157 const UINT32 MMS_UINTVAR_LENGTH_1 = 0x0000007f; //7bit
158 const UINT32 MMS_UINTVAR_LENGTH_2 = 0x00003fff; //14bit
159 const UINT32 MMS_UINTVAR_LENGTH_3 = 0x001fffff; //21bit
164 bool _MmsDecodeInitialize(void)
166 MmsInitMsgType(&mmsHeader.msgType);
167 MmsInitMsgBody(&mmsHeader.msgBody);
172 bool __MmsSetMmsHeaderOwner(int msgID, char* pszNewOwner)
176 MSG_DEBUG("__MmsSetMmsHeaderOwner: set (%s, msgID=%d)\n", pszNewOwner, msgID);
178 if ((mmsHeader.pszOwner = (char*)malloc(strlen(pszNewOwner) + 1)) == NULL)
181 memset (mmsHeader.pszOwner, 0, strlen(pszNewOwner) + 1) ;
183 strcpy(mmsHeader.pszOwner, pszNewOwner);
184 mmsHeader.bActive = true;
185 mmsHeader.msgID = msgID;
187 // delete current owner
188 if (mmsHeader.pszOwner) {
189 MSG_DEBUG("__MmsSetMmsHeaderOwner: free (%s %d)\n", mmsHeader.pszOwner, msgID);
190 free(mmsHeader.pszOwner);
191 mmsHeader.pszOwner = NULL;
193 mmsHeader.bActive = false;
194 mmsHeader.msgID = -1;
201 void _MmsInitHeader()
203 mmsHeader.type = MMS_MSGTYPE_ERROR;
205 memset(mmsHeader.szTrID, 0, MMS_TR_ID_LEN + 1);
206 mmsHeader.version = MMS_VERSION;
209 MsgFreeHeaderAddress(mmsHeader.pFrom);
210 MsgFreeHeaderAddress(mmsHeader.pTo);
211 MsgFreeHeaderAddress(mmsHeader.pCc);
212 MsgFreeHeaderAddress(mmsHeader.pBcc);
214 mmsHeader.pFrom = NULL;
215 mmsHeader.pTo = NULL;
216 mmsHeader.pCc = NULL;
217 mmsHeader.pBcc = NULL;
219 memset(mmsHeader.szSubject, 0, MSG_LOCALE_SUBJ_LEN + 1);
221 mmsHeader.responseStatus = (MmsResponseStatus)MMS_RESPSTATUS_OK;
222 mmsHeader.retrieveStatus = (MmsRetrieveStatus)MMS_RETRSTATUS_OK;
223 memset(mmsHeader.szResponseText, 0, MMS_LOCALE_RESP_TEXT_LEN + 1);
224 memset(mmsHeader.szRetrieveText, 0, MMS_LOCALE_RESP_TEXT_LEN + 1);
227 mmsHeader.msgClass = (MmsMsgClass)MMS_MSGCLASS_PERSONAL;
228 mmsHeader.expiryTime.type = MMS_TIMETYPE_RELATIVE;
229 mmsHeader.expiryTime.time = 0;
230 mmsHeader.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
231 mmsHeader.deliveryTime.time = 0;
232 mmsHeader.priority = (MmsPriority)MMS_PRIORITY_NORMAL; // Refer [OMA-MMS-ENC-v1_2-20030915-C]
233 mmsHeader.hideAddress =(MmsSenderVisible)MMS_SENDER_SHOW;
234 mmsHeader.deliveryReport = (MmsReport)MMS_REPORT_NO;
235 mmsHeader.readReply = (MmsReport)MMS_REPORT_NO;
236 mmsHeader.reportAllowed = (MmsReportAllowed)MMS_REPORTALLOWED_YES;
237 memset(mmsHeader.szContentLocation, 0, MMS_LOCATION_LEN + 1);
240 mmsHeader.msgStatus = (MSG_DELIVERY_REPORT_STATUS_T)MSG_DELIVERY_REPORT_NONE;
241 mmsHeader.readStatus = (MSG_READ_REPORT_STATUS_T)MSG_READ_REPORT_NONE;
243 mmsHeader.replyCharge.chargeType = (MmsReplyChargeType)MMS_REPLY_NONE;
244 mmsHeader.replyCharge.chargeSize = 0;
245 mmsHeader.replyCharge.deadLine.type = MMS_TIMETYPE_RELATIVE;
246 mmsHeader.replyCharge.deadLine.time = 0;
247 memset(mmsHeader.replyCharge.szChargeID, 0, MMS_MSG_ID_LEN + 1);
250 memset(mmsHeader.szMsgID, 0, MMS_MSG_ID_LEN + 1);
251 mmsHeader.msgSize = 0;
252 #ifdef __SUPPORT_DRM__
253 mmsHeader.drmType = MSG_DRM_TYPE_NONE;
256 _MmsDecodeInitialize();
261 void _MmsCleanDecodeBuff(void)
263 memset(gpMmsDecodeBuf1, 0, gMmsDecodeMaxLen + 1);
264 memset(gpMmsDecodeBuf2, 0, gMmsDecodeMaxLen + 1);
265 gpCurMmsDecodeBuff = NULL;
266 gCurMmsDecodeBuffPos = 0;
267 gMmsDecodeBufLen = 0;
271 void _MmsRegisterDecodeBuffer(char *pInBuff1, char *pInBuff2, int maxLen)
273 gpMmsDecodeBuf1 = pInBuff1;
274 gpMmsDecodeBuf2 = pInBuff2;
275 gpCurMmsDecodeBuff = NULL;
276 gCurMmsDecodeBuffPos = 0;
277 gMmsDecodeMaxLen = maxLen;
278 gMmsDecodeCurOffset = 0;
279 gMmsDecodeBufLen = 0;
282 void _MmsUnregisterDecodeBuffer(void)
284 gpMmsDecodeBuf1 = NULL;
285 gpMmsDecodeBuf2 = NULL;
286 gpCurMmsDecodeBuff = NULL;
287 gCurMmsDecodeBuffPos = 0;
288 gMmsDecodeMaxLen = 0;
289 gMmsDecodeCurOffset = 0;
290 gMmsDecodeBufLen = 0;
294 int _MmsGetDecodeOffset(void)
296 return (gMmsDecodeCurOffset - gMmsDecodeBufLen + gCurMmsDecodeBuffPos);
300 static bool __MmsBinaryDecodeCheckAndDecreaseLength(int *pLength, int valueLength)
302 if (*pLength <= valueLength) {
303 gCurMmsDecodeBuffPos -= valueLength;
304 gCurMmsDecodeBuffPos += *pLength;
308 *pLength -= valueLength;
314 /* ==========================================================
316 B I N A R Y D E C O D I N G
318 ==========================================================*/
321 * Binary Encoded Message Format
323 * < Single Part Body Message >
324 * -----------------------------------
326 * -----------------------------------
327 * | Content Type:start=xxx;type=xxx | ->(ex) Text/Plain, Text/Html, ....
328 * -----------------------------------
329 * | Single Part Body |
330 * -----------------------------------
332 * < Multi Part Body Message >
333 * -----------------------------------
335 * -----------------------------------
336 * | Content Type:start=xxx;type=xxx | -> (ex) Application/vnd.wap.multipart.mixed(related), multipart/mixed(related)
337 * -----------------------------------
338 * | # of Entries (body parts) |
339 * ----------------------------------- < Each Entry >
340 * | Entry 1 | -> -----------------------------
341 * ----------------------------------- | header Length |
342 * | Entry 2 | -----------------------------
343 * ----------------------------------- | Data Length |
344 * | ...... | ----------------------------- -
345 * ----------------------------------- | Content-Type | |
346 * | Entry n | ----------------------------- | Header Length
347 * ----------------------------------- | Header | |
348 * ----------------------------- -
349 * | Data | | Data Length
350 * ----------------------------- -
352 bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
354 UINT16 fieldCode = 0xffff;
355 UINT16 fieldValue = 0xffff;
356 UINT8 oneByte = 0xff;
358 MsgHeaderAddress *pAddr = NULL;
359 MsgHeaderAddress *pLastTo = NULL;
360 MsgHeaderAddress *pLastCc = NULL;
361 MsgHeaderAddress *pLastBcc = NULL;
363 UINT32 valueLength = 0;
364 UINT32 tmpInteger = 0;
369 char szGarbageBuff[MSG_STDSTR_LONG] = {0, };
370 char *pLimitData = NULL;
373 MSG_DEBUG("MmsBinaryDecodeMsgHeader: pFile=%d, total len=%d\n", pFile, totalLength);
375 _MmsCleanDecodeBuff();
377 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos,
378 &gMmsDecodeCurOffset, gpMmsDecodeBuf1, gpMmsDecodeBuf2,
379 gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
380 MSG_DEBUG("MmsBinaryDecodeMsgHeader: fail to load to buffer \n");
384 while (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength)) {
385 fieldCode = oneByte & 0x7f;
387 switch (_MmsGetBinaryType(MmsCodeFieldCode, fieldCode)) {
388 case MMS_CODE_RESPONSESTATUS:
390 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
391 MSG_DEBUG("MmsBinaryDecodeMsgHeader: responseStatus GetOneByte fail\n");
395 fieldValue = _MmsGetBinaryType(MmsCodeResponseStatus, (UINT16)(oneByte & 0x7F));
397 if (fieldValue == 0xFFFF) {
398 MSG_DEBUG("MmsBinaryDecodeMsgHeader: responseStatus error\n");
402 if (fieldValue >= 0x0044 && fieldValue <= 0x005F) {
404 } else if (fieldValue >= 0x006A && fieldValue <= 0x007F) {
408 mmsHeader.responseStatus = (MmsResponseStatus)fieldValue;
410 MSG_DEBUG("MmsBinaryDecodeMsgHeader: response status = %s\n", MmsDebugGetResponseStatus(mmsHeader.responseStatus));
414 case MMS_CODE_RETRIEVESTATUS:
416 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
417 MSG_DEBUG("MmsBinaryDecodeMsgHeader: retrieveStatus GetOneByte fail\n");
421 fieldValue = _MmsGetBinaryType(MmsCodeRetrieveStatus, (UINT16)(oneByte & 0x7F));
423 if (fieldValue == 0xFFFF) {
424 MSG_DEBUG("MmsBinaryDecodeMsgHeader: retrieveStatus error\n");
428 if (fieldValue >= 0x0043 && fieldValue <= 0x005F) {
429 fieldValue = 0x0040; // 192; Error-transient-failure
430 } else if (fieldValue >= 0x0064 && fieldValue <= 0x007F) {
431 fieldValue = 0x0060; //224; Error-permanent-failure
434 mmsHeader.retrieveStatus = (MmsRetrieveStatus)fieldValue;
436 MSG_DEBUG("MmsBinaryDecodeMsgHeader: retrieve status = %s\n",
437 MmsDebugGetRetrieveStatus(mmsHeader.retrieveStatus));
441 case MMS_CODE_RESPONSETEXT:
443 if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szResponseText, MMS_LOCALE_RESP_TEXT_LEN + 1, totalLength) == false) {
444 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_RESPONSETEXT \n");
448 MSG_DEBUG("MmsBinaryDecodeMsgHeader: response text = %s\n", mmsHeader.szResponseText);
451 case MMS_CODE_RETRIEVETEXT:
453 if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szRetrieveText, MMS_LOCALE_RESP_TEXT_LEN + 1, totalLength) == false) {
454 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_RETRIEVETEXT \n");
458 MSG_DEBUG("MmsBinaryDecodeMsgHeader: retrieve text = %s\n", mmsHeader.szResponseText);
463 if (__MmsBinaryDecodeText(pFile, mmsHeader.szMsgID, MMS_MSG_ID_LEN + 1, totalLength) < 0) {
464 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_MSGID is invalid\n");
468 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg id = %s\n", mmsHeader.szMsgID);
470 if (MsgStrlen (mmsHeader.szMsgID) > 2)
471 MsgMIMERemoveQuote (mmsHeader.szMsgID);
475 case MMS_CODE_SUBJECT:
477 if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN + 1, totalLength) == false) {
478 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_SUBJECT \n");
482 pLimitData = (char *)malloc(MSG_LOCALE_SUBJ_LEN + 1);
484 if (pLimitData == NULL) {
485 MSG_DEBUG("MmsBinaryDecodeMsgHeader : pLimitData malloc fail \n");
489 nRead = MsgCutUTFString((unsigned char*)pLimitData, MSG_LOCALE_SUBJ_LEN + 1, (unsigned char*)mmsHeader.szSubject, MSG_SUBJ_LEN);
490 MSG_DEBUG("MmsBinaryDecodeMsgHeader : Subject edit.. \n");
492 if (nRead > MSG_LOCALE_SUBJ_LEN) {
493 memset(mmsHeader.szSubject, 0 , sizeof(mmsHeader.szSubject));
494 strncpy(mmsHeader.szSubject, pLimitData, MSG_SUBJ_LEN);
496 memset(mmsHeader.szSubject, 0 , sizeof(mmsHeader.szSubject));
497 strncpy(mmsHeader.szSubject, pLimitData, MSG_LOCALE_SUBJ_LEN);
505 MSG_DEBUG("MmsBinaryDecodeMsgHeader: subject = %s\n", mmsHeader.szSubject);
510 /* Value-length (Address-present-token Encoded-string-value | Insert-address-token) */
512 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
513 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_FROM is invalid\n");
517 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
518 MSG_DEBUG("MmsBinaryDecodeMsgHeader: MMS_CODE_FROM GetOneByte fail\n");
522 // DRM_TEMPLATE - start
526 if (oneByte == (_MmsGetBinaryValue(MmsCodeAddressType, MMS_ADDRESS_PRESENT_TOKEN)|0x80)) {
527 if (valueLength > 0) {
528 mmsHeader.pFrom = __MmsDecodeEncodedAddress(pFile, totalLength);
529 if (mmsHeader.pFrom == NULL) {
530 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_FROM __MmsDecodeEncodedAddress fail\n");
534 mmsHeader.pFrom = (MsgHeaderAddress *)malloc(sizeof(MsgHeaderAddress));
535 if (mmsHeader.pFrom == NULL)
538 mmsHeader.pFrom->szAddr = (char *)malloc(1);
539 if (mmsHeader.pFrom->szAddr == NULL) {
540 free(mmsHeader.pFrom);
541 mmsHeader.pFrom = NULL;
545 mmsHeader.pFrom->szAddr[0] = '\0';
546 mmsHeader.pFrom->pNext = NULL;
549 MSG_DEBUG("MmsBinaryDecodeMsgHeader: from = %s\n", mmsHeader.pFrom->szAddr);
550 // DRM_TEMPLATE - end
551 } else if (oneByte == (_MmsGetBinaryValue(MmsCodeAddressType, MMS_INSERT_ADDRESS_TOKEN)|0x80)) {
552 /* Present Token only */
553 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_FROM insert token\n");
555 /* from data broken */
556 MSG_DEBUG("MmsBinaryDecodeMsgHeader: from addr broken\n");
557 gCurMmsDecodeBuffPos--;
564 pAddr = __MmsDecodeEncodedAddress(pFile, totalLength);
566 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_TO __MmsDecodeEncodedAddress fail\n");
570 if (mmsHeader.pTo == NULL) {
572 pLastTo = mmsHeader.pTo = pAddr;
575 pLastTo->pNext = pAddr;
579 MSG_DEBUG("MmsBinaryDecodeMsgHeader: to = %s\n", mmsHeader.pTo->szAddr);
584 pAddr = __MmsDecodeEncodedAddress(pFile, totalLength);
586 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_BCC __MmsDecodeEncodedAddress fail\n");
590 if (mmsHeader.pBcc == NULL) {
592 pLastBcc = mmsHeader.pBcc = pAddr;
595 pLastBcc->pNext = pAddr;
599 MSG_DEBUG("MmsBinaryDecodeMsgHeader: bcc = %s\n", mmsHeader.pBcc->szAddr);
604 pAddr = __MmsDecodeEncodedAddress(pFile, totalLength);
606 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_CC __MmsDecodeEncodedAddress fail\n");
610 if (mmsHeader.pCc == NULL) {
612 pLastCc = mmsHeader.pCc = pAddr;
615 pLastCc->pNext = pAddr;
618 MSG_DEBUG("MmsBinaryDecodeMsgHeader: cc = %s\n", mmsHeader.pCc->szAddr);
621 case MMS_CODE_CONTENTLOCATION:
623 if (__MmsBinaryDecodeText(pFile, mmsHeader.szContentLocation, MMS_LOCATION_LEN + 1, totalLength) < 0) {
624 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_CONTENTLOCATION is invalid\n");
627 MSG_DEBUG("MmsBinaryDecodeMsgHeader: content location = %s\n", mmsHeader.szContentLocation);
632 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.date, totalLength) == false) {
633 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_DATE is invalid\n");
636 MSG_DEBUG("MmsBinaryDecodeMsgHeader: date = %d\n", mmsHeader.date);
639 case MMS_CODE_DELIVERYREPORT:
641 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
642 MSG_DEBUG("MmsBinaryDecodeMsgHeader: deliveryReport GetOneByte fail\n");
646 fieldValue = _MmsGetBinaryType(MmsCodeDeliveryReport, (UINT16)(oneByte & 0x7F));
648 if (fieldValue == 0xFFFF) {
649 MSG_DEBUG("MmsBinaryDecodeMsgHeader: deliveryReport error\n");
653 mmsHeader.deliveryReport = (MmsReport)fieldValue;
655 MSG_DEBUG("MmsBinaryDecodeMsgHeader: delivery report=%s\n", MmsDebugGetMmsReport(mmsHeader.deliveryReport));
658 case MMS_CODE_DELIVERYTIME:
660 /* value_length (absolute-token Long-integer | Relative-token Long-integer) */
662 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
663 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_DELIVERYTIME \n");
667 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
668 MSG_DEBUG("MmsBinaryDecodeMsgHeader: delivery time GetOneByte fail\n");
672 //DRM_TEMPLATE - start
675 if (oneByte == (_MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_ABSOLUTE)|0x80)) {
676 mmsHeader.deliveryTime.type = MMS_TIMETYPE_ABSOLUTE;
678 if (valueLength > 0) {
679 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.deliveryTime.time, totalLength) == false) {
680 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_DELIVERYTIME\n");
684 // DRM_TEMPLATE - end
686 mmsHeader.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
688 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&mmsHeader.deliveryTime.time, &tmpIntLen, totalLength) == false) {
689 MSG_DEBUG("MmsBinaryDecodeMsgHeader : __MmsBinaryDecodeInteger fail...\n");
693 MSG_DEBUG("MmsBinaryDecodeMsgHeader: delivery type=%d, time=%d\n", mmsHeader.deliveryTime.type, mmsHeader.deliveryTime.time);
696 case MMS_CODE_EXPIRYTIME:
698 /* value_length(absolute-token Long-integer | Relative-token Long-integer) */
700 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
701 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_EXPIRYTIME \n");
705 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
706 MSG_DEBUG("MmsBinaryDecodeMsgHeader: expiry time GetOneByte fail\n");
710 // DRM_TEMPLATE - start
713 if (oneByte == (_MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_ABSOLUTE)|0x80)) {
714 mmsHeader.expiryTime.type = MMS_TIMETYPE_ABSOLUTE;
716 if (valueLength > 0) {
717 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.expiryTime.time, totalLength) == false) {
718 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_EXPIRYTIME is invalid\n");
722 // DRM_TEMPLATE - end
724 mmsHeader.expiryTime.type = MMS_TIMETYPE_RELATIVE;
726 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&mmsHeader.expiryTime.time, &tmpIntLen, totalLength) == false) {
727 MSG_DEBUG("MmsBinaryDecodeMsgHeader : __MmsBinaryDecodeInteger fail...\n");
731 MSG_DEBUG("MmsBinaryDecodeMsgHeader: expiry = %d\n", mmsHeader.expiryTime.time);
734 case MMS_CODE_MSGCLASS:
736 /* Class-value = Class-identifier | Token Text */
738 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
739 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgClass GetOneByte fail\n");
743 if (oneByte > 0x7f) {
744 /* Class-identifier */
745 mmsHeader.msgClass = (MmsMsgClass)_MmsGetBinaryType(MmsCodeMsgClass, (UINT16)(oneByte & 0x7F));
747 if (__MmsBinaryDecodeText(pFile, szGarbageBuff, MSG_STDSTR_LONG, totalLength) < 0) {
748 MSG_DEBUG("MmsBinaryDecodeMsgHeader: 1. __MmsBinaryDecodeText fail. (class)\n");
752 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg class=%s\n", MmsDebugGetMsgClass(mmsHeader.msgClass));
755 case MMS_CODE_MSGSIZE:
757 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.msgSize, totalLength) == false) {
758 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_MSGSIZE is invalid\n");
761 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg size = %d\n", mmsHeader.msgSize);
764 case MMS_CODE_MSGSTATUS:
766 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
767 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
771 mmsHeader.msgStatus = (MSG_DELIVERY_REPORT_STATUS_T)_MmsGetBinaryType(MmsCodeMsgStatus, (UINT16)(oneByte & 0x7F));
772 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg status=%s \n", MmsDebugGetMsgStatus(mmsHeader.msgStatus)) ;
775 case MMS_CODE_MSGTYPE:
777 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
778 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
782 mmsHeader.type = (MmsMsgType)_MmsGetBinaryType(MmsCodeMsgType, (UINT16)(oneByte & 0x7F));
783 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg type=%s\n", MmsDebugGetMsgType(mmsHeader.type));
786 case MMS_CODE_PRIORITY:
788 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
789 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
792 mmsHeader.priority = (MmsPriority)_MmsGetBinaryType(MmsCodePriority, (UINT16)(oneByte & 0x7F));
793 MSG_DEBUG("MmsBinaryDecodeMsgHeader: priority=%d\n", mmsHeader.priority);
796 case MMS_CODE_READREPLY:
798 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
799 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
802 mmsHeader.readReply = (MmsReport)_MmsGetBinaryType(MmsCodeReadReply, (UINT16)(oneByte & 0x7F));
803 MSG_DEBUG("MmsBinaryDecodeMsgHeader: read reply=%s \n", MmsDebugGetMmsReport(mmsHeader.readReply));
806 case MMS_CODE_REPORTALLOWED:
808 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
809 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
812 mmsHeader.reportAllowed = (MmsReportAllowed)_MmsGetBinaryType(MmsCodeReportAllowed, (UINT16)(oneByte & 0x7F));
813 MSG_DEBUG("MmsBinaryDecodeMsgHeader: mmsHeader.reportAllowed=%d\n", MmsDebugGetMmsReportAllowed(mmsHeader.reportAllowed));
816 case MMS_CODE_SENDERVISIBILLITY:
818 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
819 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
822 mmsHeader.hideAddress= (MmsSenderVisible)!(_MmsGetBinaryType(MmsCodeSenderVisibility, (UINT16)(oneByte &0x7F)));
823 MSG_DEBUG("MmsBinaryDecodeMsgHeader: sender visible=%d \n", mmsHeader.hideAddress);
828 if (__MmsBinaryDecodeText(pFile, mmsHeader.szTrID, MMS_TR_ID_LEN + 1, totalLength) < 0) {
829 MSG_DEBUG("Transaction ID Too Long \n");
832 MSG_DEBUG("MmsBinaryDecodeMsgHeader: trID = %s\n", mmsHeader.szTrID);
835 case MMS_CODE_VERSION:
836 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
837 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
840 mmsHeader.version = oneByte;
842 MSG_DEBUG("MmsBinaryDecodeMsgHeader: ver = 0x%x\n", mmsHeader.version);
845 case MMS_CODE_CONTENTTYPE:
848 * Content-type is the last header field of SendRequest and RetrieveConf.
849 * It's required to decrease pointer by one and return,
850 * to parse this field in MmsBinaryDecodeContentType().
855 /* ----------- Add by MMSENC v1.1 ----------- */
857 case MMS_CODE_READSTATUS:
859 /* Read-status-value = Read | Deleted without being read */
861 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
862 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
866 mmsHeader.readStatus = (MSG_READ_REPORT_STATUS_T)_MmsGetBinaryType(MmsCodeReadStatus, (UINT16)(oneByte & 0x7F));
867 MSG_DEBUG("MmsBinaryDecodeMsgHeader: read status=%s\n", MmsDebugGetMmsReadStatus(mmsHeader.readStatus));
870 case MMS_CODE_REPLYCHARGING:
872 /* Reply-charging-value = Requested | Requested text only | Accepted | Accepted text only */
874 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
875 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
879 mmsHeader.replyCharge.chargeType = (MmsReplyChargeType)_MmsGetBinaryType(MmsCodeReplyCharging, (UINT16)(oneByte & 0x7F));
880 MSG_DEBUG("MmsBinaryDecodeMsgHeader: mmsHeader.reply charge=%d\n", mmsHeader.replyCharge.chargeType);
883 case MMS_CODE_REPLYCHARGINGDEADLINE:
885 /* Reply-charging-deadline-value = Value-length (Absolute-token Date-value | Relative-token Delta-seconds-value) */
887 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
888 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_REPLYCHARGINGDEADLINE \n");
892 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
893 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
897 if (oneByte == (_MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_ABSOLUTE) | 0x80)) {
898 mmsHeader.replyCharge.deadLine.type = MMS_TIMETYPE_ABSOLUTE;
900 mmsHeader.replyCharge.deadLine.type = MMS_TIMETYPE_RELATIVE;
903 // DRM_TEMPLATE - start
906 if (valueLength > 0) {
907 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.replyCharge.deadLine.time, totalLength) == false) {
908 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_REPLYCHARGINGDEADLINE is invalid\n");
912 // DRM_TEMPLATE - end
915 case MMS_CODE_REPLYCHARGINGID:
917 /* Reply-charging-ID-value = Text-string */
919 if (__MmsBinaryDecodeText(pFile, mmsHeader.replyCharge.szChargeID, MMS_MSG_ID_LEN + 1, totalLength) < 0) {
920 MSG_DEBUG("MmsBinaryDecodeMsgHeader: 1. __MmsBinaryDecodeText fail. (szReplyChargingID)\n");
925 case MMS_CODE_REPLYCHARGINGSIZE:
927 /* Reply-charging-size-value = Long-integer */
929 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.replyCharge.chargeSize, totalLength) == false) {
930 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_REPLYCHARGINGSIZE is invalid\n");
935 case MMS_CODE_PREVIOUSLYSENTBY:
938 * Previously-sent-by-value = Value-length Forwarded-count-value Encoded-string-value
939 * Forwarded-count-value = Integer-value
940 * MMS_CODE_PREVIOUSLYSENTBY shall be a pair with MMS_CODE_PREVIOUSLYSENTDATE
944 * fixme: There is no proper field to store this information.
945 * Just increase pointer now.
948 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
949 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 1. invalid MMS_CODE_PREVIOUSLYSENTBY \n");
953 if (__MmsBinaryDecodeInteger(pFile, &tmpInteger, &tmpIntLen, totalLength) == false) {
954 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 2. invalid MMS_CODE_PREVIOUSLYSENTBY \n");
958 if (__MmsBinaryDecodeEncodedString(pFile, szGarbageBuff, MSG_STDSTR_LONG, totalLength) == false) {
959 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_RETRIEVETEXT \n");
964 case MMS_CODE_PREVIOUSLYSENTDATE:
967 * Previously-sent-date-value = Value-length Forwarded-count-value Date-value
968 * Forwarded-count-value = Integer-value
969 * MMS_CODE_PREVIOUSLYSENTDATE shall be a pair with MMS_CODE_PREVIOUSLYSENTBY
973 * fixme: There is no proper field to store this information.
974 * Just increase pointer now.
977 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
978 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 1. invalid MMS_CODE_PREVIOUSLYSENTDATE \n");
982 if (__MmsBinaryDecodeInteger(pFile, &tmpInteger, &tmpIntLen, totalLength) == false) {
983 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 2. invalid MS_CODE_PREVIOUSLYSENTDATE \n");
987 if (__MmsDecodeLongInteger(pFile, (UINT32*)&tmpInteger, totalLength) == false) {
988 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 3. invalid MMS_CODE_PREVIOUSLYSENTDATE \n");
997 * Application-header = Token-text Application-specific-value
998 * Token-text = Token End-of-string
999 * Application-specific-value = Text -string
1001 * OR unknown header field - Just ignore these fields.
1003 * Read one byte and check the value >= 0x80
1004 * (check these value can be field code)
1007 int remainLength = 0;
1011 offset = _MmsGetDecodeOffset();
1012 if (offset >= totalLength)
1015 remainLength = totalLength - offset;
1017 while ((oneByte < 0x80) && (remainLength > 0)) {
1018 if (__MmsBinaryDecodeCheckAndDecreaseLength(&remainLength, 1) == false) {
1019 MSG_DEBUG("MmsBinaryDecodeMsgHeader: __MmsBinaryDecodeCheckAndDecreaseLength fail\n");
1022 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1023 MSG_DEBUG("MmsBinaryDecodeMsgHeader: responseStatus GetOneByte fail\n");
1028 gCurMmsDecodeBuffPos--;
1034 offset = _MmsGetDecodeOffset();
1035 if (offset >= totalLength)
1043 MSG_DEBUG("MmsBinaryDecodeMsgHeader: success\n");
1048 MSG_DEBUG("MmsBinaryDecodeMsgHeader: failed\n");
1053 #ifdef FEATURE_JAVA_MMS
1054 // for JAVA MMS AppId - check later whether it can be handled by MmsBinaryDecodeMsgHeader
1055 bool MmsBinaryDecodeContentType(FILE *pFile, char *szFilePath, int totalLength)
1059 MSG_DEBUG("MmsBinaryDecodeContentType:\n");
1061 if (szFilePath != NULL)
1062 strncpy(mmsHeader.msgType.szOrgFilePath, szFilePath, strlen(szFilePath));
1063 mmsHeader.msgType.offset = _MmsGetDecodeOffset() - 1; // + Content-Type code value
1065 // read data(2K) from msg file(/User/Msg/Inbox/5) to gpCurMmsDecodeBuff for decoding
1066 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos,
1067 &gMmsDecodeCurOffset, gpMmsDecodeBuf1, gpMmsDecodeBuf2,
1068 gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
1069 MSG_DEBUG("MmsBinaryDecodeContentType: fail to load to buffer \n");
1073 // msg's type [ex] related, mixed, single part (jpg, amr and etc)
1074 length = MmsBinaryDecodeContentType(pFile, &mmsHeader.msgType, totalLength);
1076 MSG_DEBUG("MmsBinaryDecodeContentType: MMS_CODE_CONTENTTYPE is fail\n");
1079 MSG_DEBUG("Content-Type: Application-ID:%s Reply-To-Application-ID:%s",mmsHeader.msgType.param.szApplicationID, mmsHeader.msgType.param.szReplyToApplicationID);
1085 /* fixme: Delete multipart using MmsDeleteMsg() */
1091 bool MmsBinaryDecodeMsgBody(FILE *pFile, char *szFilePath, int totalLength)
1096 MsgMultipart *pMultipart = NULL;
1098 MSG_DEBUG("MmsBinaryDecodeMsgBody:\n");
1100 if (szFilePath != NULL)
1101 strncpy(mmsHeader.msgType.szOrgFilePath, szFilePath , strlen(szFilePath));
1103 mmsHeader.msgType.offset = _MmsGetDecodeOffset() - 1; // + Content-Type code value
1105 // read data(2K) from msg file(/User/Msg/Inbox/5) to gpCurMmsDecodeBuff for decoding
1106 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos,
1107 &gMmsDecodeCurOffset, gpMmsDecodeBuf1, gpMmsDecodeBuf2,
1108 gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
1109 MSG_DEBUG("MmsBinaryDecodeMsgBody: fail to load to buffer \n");
1113 // msg's type [ex] related, mixed, single part (jpg, amr and etc)
1114 length = MmsBinaryDecodeContentType(pFile, &mmsHeader.msgType, totalLength);
1116 MSG_DEBUG("MmsBinaryDecodeMsgBody: MMS_CODE_CONTENTTYPE is fail\n");
1120 mmsHeader.msgType.size = length + 1; // + Content-Type code value
1121 mmsHeader.msgBody.offset = _MmsGetDecodeOffset();
1123 switch (mmsHeader.msgType.type) {
1124 case MIME_APPLICATION_VND_WAP_MULTIPART_MIXED:
1125 case MIME_APPLICATION_VND_WAP_MULTIPART_RELATED:
1126 case MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC:
1127 case MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE:
1128 case MIME_MULTIPART_REPORT:
1129 case MIME_MULTIPART_MIXED:
1130 case MIME_MULTIPART_RELATED:
1131 case MIME_MULTIPART_ALTERNATIVE:
1132 case MIME_APPLICATION_VND_OMA_DRM_MESSAGE:
1133 case MIME_APPLICATION_VND_OMA_DRM_CONTENT:
1135 MSG_DEBUG("__MmsBinaryMsgBodyDecode: Decode multipart\n");
1137 offset = _MmsGetDecodeOffset();
1138 if (offset >= totalLength)
1141 if (MmsBinaryDecodeMultipart(pFile, szFilePath, &mmsHeader.msgType, &mmsHeader.msgBody, totalLength) == false) {
1142 MSG_DEBUG("__MmsBinaryMsgBodyDecode: MmsBinaryDecodeMultipart is fail.\n");
1149 /* Single part message ---------------------------------------------- */
1151 strcpy(mmsHeader.msgBody.szOrgFilePath, szFilePath);
1153 offset = _MmsGetDecodeOffset();
1154 if (offset >= totalLength)
1157 if (MmsBinaryDecodePartBody(pFile, totalLength - mmsHeader.msgBody.offset, totalLength) == false) {
1158 MSG_DEBUG("__MmsBinaryMsgBodyDecode: MmsBinaryDecodePartBody is fail.(Single Part)\n");
1162 mmsHeader.msgBody.size = totalLength - mmsHeader.msgBody.offset;
1163 mmsHeader.msgType.contentSize = totalLength - mmsHeader.msgBody.offset;
1168 #ifdef __SUPPORT_DRM__
1169 mmsHeader.drmType = MsgGetDRMType(&mmsHeader.msgType, &mmsHeader.msgBody);
1178 /* fixme: Delete multipart using MmsDeleteMsg() */
1181 if (pMultipart->pBody) {
1182 if (pMultipart->pBody->body.pText) {
1183 free(pMultipart->pBody->body.pText);
1184 pMultipart->pBody->body.pText = NULL;
1187 free(pMultipart->pBody);
1188 pMultipart->pBody = NULL;
1198 #if MMS_ENABLE_EXTEND_CFM
1199 // DRM (Extended)CFM
1200 // Get Extended CFM value.
1201 static bool __MmsConvertString2Bool(char *pszValue)
1203 if (!strcasecmp(pszValue, "no"))
1210 bool MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int valueLength, int totalLength)
1214 char *szTypeString = NULL;
1215 char *szTypeValue = NULL;
1216 UINT8 paramCode = 0xff;
1223 * Parameter = Typed-parameter | Untyped-parameter
1224 * WAP-230-WSP-20010118-p, Proposed Version 18 January 2001 (pp.107)
1227 MSG_DEBUG("MmsBinaryDecodeParameter: \n");
1229 while (valueLength > 0) {
1230 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1231 MSG_DEBUG("MmsBinaryDecodeContentType: paramCode _MmsBinaryDecodeGetOneByte fail\n");
1235 paramCode = oneByte;
1238 switch (paramCode) {
1239 case 0x81: // charset
1241 if (__MmsBinaryDecodeCharset(pFile, (UINT32*)&(pMsgType->param.charset), &charSetLen, totalLength) == false) {
1242 MSG_DEBUG("MmsBinaryDecodeContentType : __MmsBinaryDecodeCharset fail.\n");
1246 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, charSetLen) == false)
1251 case 0x85: //name = Text-string
1252 case 0x97: //name = Text-value = No-value | Token-text | Quoted-string
1253 memset(pMsgType->param.szName, 0, sizeof(pMsgType->param.szName));
1254 length = __MmsDecodeGetFilename(pFile, pMsgType->param.szName,
1255 MSG_FILENAME_LEN_MAX -5, // MSG_LOCALE_FILENAME_LEN_MAX + 1, : change @ 110(Ui code have to change for this instead of DM)
1258 MSG_DEBUG("MmsBinaryDecodeContentType : __MmsDecodeGetFilename fail. (name parameter)\n");
1262 if (MsgCheckFileNameHasInvalidChar(pMsgType->param.szName)) {
1263 _MsgReplaceInvalidFileNameChar(pMsgType->param.szName, '_');
1266 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, length) == false)
1271 case 0x86: //filename = Text-string
1272 case 0x98: //filename = Text-value = No-value | Token-text | Quoted-string
1273 memset(pMsgType->param.szFileName, 0, sizeof(pMsgType->param.szFileName));
1274 length = __MmsDecodeGetFilename(pFile, pMsgType->param.szFileName, MSG_FILENAME_LEN_MAX -5, totalLength);
1276 MSG_DEBUG("MmsBinaryDecodeContentType : __MmsDecodeGetFilename fail. (filename parameter)\n");
1280 if (MsgCheckFileNameHasInvalidChar(pMsgType->param.szFileName)) {
1281 _MsgReplaceInvalidFileNameChar(pMsgType->param.szFileName, '_');
1284 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, length) == false)
1289 case 0x89: //type = Constrained-encoding = Extension-Media | Short-integer
1291 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1292 MSG_DEBUG("MmsBinaryDecodeContentType: type _MmsBinaryDecodeGetOneByte fail\n");
1296 if (oneByte > 0x7f) {
1297 pMsgType->param.type = _MmsGetBinaryType(MmsCodeContentType,
1298 (UINT16)(oneByte & 0x7f));
1299 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, 1) == false)
1302 gCurMmsDecodeBuffPos--;
1305 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1306 pMsgType->param.type = _MmsGetTextType(MmsCodeContentType, szTypeString);
1310 szTypeString = NULL;
1313 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1319 case 0x8A: //start encoding version 1.2
1320 case 0x99: //start encoding version 1.4
1323 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1325 memset(pMsgType->param.szStart, 0, MMS_CONTENT_ID_LEN + 1);
1326 strncpy(pMsgType->param.szStart, szTypeString, MMS_CONTENT_ID_LEN);
1328 szTypeString = NULL;
1330 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1336 case 0x8B: //startInfo encoding version 1.2
1337 case 0x9A: //startInfo encoding version 1.4
1340 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1343 memset(pMsgType->param.szStartInfo, 0, MMS_CONTENT_ID_LEN + 1);
1344 strncpy(pMsgType->param.szStartInfo, szTypeString, MMS_CONTENT_ID_LEN);
1347 szTypeString = NULL;
1349 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1357 if (paramCode > 0x7F) {
1358 MSG_DEBUG("MmsBinaryDecodeContentType: Unsupported parameter\n");
1360 // In case of the last byte of Parameter field, it should be returned without decreasing the gCurMmsDecodeBuffPos value.
1362 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, 1) == false)
1366 * Untyped Parameter = Token-text Untyped-value
1367 * Token-text = Token End-of-string
1368 * Untyped-value = Integer-value | Text-value
1369 * Text-value = No-value | Token-text | Quoted-string
1371 * Just increase pointer!!!
1377 gCurMmsDecodeBuffPos--;
1381 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1382 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1388 if (__MmsBinaryDecodeInteger(pFile, &integer, &intLen, totalLength) == true) {
1389 MSG_DEBUG("MmsBinaryDecodeContentType: Unsupported parameter(%d)\n", integer);
1390 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, intLen) == false)
1394 szTypeValue = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1397 /* checkMe: forwardLock needs boudary string */
1398 if (strcasecmp(szTypeString, "boundary") == 0) {
1399 memset(pMsgType->param.szBoundary, 0, MSG_BOUNDARY_LEN + 1);
1400 strncpy(pMsgType->param.szBoundary, szTypeValue, MSG_BOUNDARY_LEN);
1401 #ifdef FEATURE_JAVA_MMS
1402 } else if (strcasecmp(szTypeString, "Application-ID") == 0) {
1403 pMsgType->param.szApplicationID = (char*) malloc(textLength + 1);
1404 memset(pMsgType->param.szApplicationID, 0, textLength + 1);
1405 strncpy(pMsgType->param.szApplicationID, szTypeValue, textLength);
1406 MSG_DEBUG("Application-ID:%s",pMsgType->param.szApplicationID);
1407 } else if (strcasecmp(szTypeString,"Reply-To-Application-ID") == 0) {
1408 pMsgType->param.szReplyToApplicationID= (char*) malloc(textLength + 1);
1409 memset(pMsgType->param.szReplyToApplicationID, 0, textLength + 1);
1410 strncpy(pMsgType->param.szReplyToApplicationID, szTypeValue, textLength);
1411 MSG_DEBUG("ReplyToApplication-ID:%s",pMsgType->param.szReplyToApplicationID);
1417 MSG_DEBUG("MmsBinaryDecodeContentType: Unsupported parameter(%s)\n", szTypeValue);
1418 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1424 MSG_DEBUG("MmsBinaryDecodeContentType: Unsupported parameter(%s)\n", szTypeString);
1426 szTypeString = NULL;
1432 } /*end of while loop*/
1439 szTypeString = NULL;
1448 szTypeString = NULL;
1456 * Decode Encoded Content type
1458 * @param pEncodedData [in] ContentType encoded data
1459 * @param pMsgType [out] Decoded MsgType
1460 * @return Decoded address list
1462 int MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int totalLength)
1465 char *szTypeString = NULL;
1466 int valueLength = 0;
1472 * Content-type-value : [WAPWSP 8.4.2.24]
1473 * Preassigned content-types : [WAPWSP Appendix A, Table 40]
1474 * The use of start-parameter : [RFC2387] and SHOULD be encoded according to [WAPWSP].
1476 * Content-type-value = Constrained-media | Content-general-form
1477 * Content-general-form = Value-length Media-type
1478 * Media-type = (Well-known-media | Extension-Media) *(Parameter)
1481 MSG_DEBUG("MmsBinaryDecodeContentType: decoding content type..\n");
1484 length = __MmsDecodeValueLength(pFile, (UINT32*)&valueLength, totalLength);
1487 * Constrained-media or Single part message
1488 * Constrained-media = Constrained-encoding = Extension-Media | Short-integer
1489 * Extension-media = *TEXT End-of-string
1490 * Short-integer = OCTET(1xxx xxxx)
1493 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1494 MSG_DEBUG("MmsBinaryDecodeContentType: Constrained-media _MmsBinaryDecodeGetOneByte fail\n");
1498 if (oneByte > 0x7F) {
1500 pMsgType->type = _MmsGetBinaryType(MmsCodeContentType, (UINT16)(oneByte & 0x7F));
1503 char *pszTemp = NULL;
1505 /* Extension-Media */
1506 gCurMmsDecodeBuffPos--;
1509 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1511 if (szTypeString && (strchr(szTypeString, ';')) != NULL) {
1512 pszTemp = _MsgGetStringUntilDelimiter(szTypeString, ';');
1515 szTypeString = pszTemp;
1519 pMsgType->type = _MmsGetTextType(MmsCodeContentType, szTypeString);
1521 length = textLength;
1525 szTypeString = NULL;
1530 * Content-general-form = Value-length Media-type
1531 * Media-type = (Well-known-media | Extension-Media)*(Parameter)
1534 length += valueLength;
1536 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1537 MSG_DEBUG("MmsBinaryDecodeContentType: Well-known-media _MmsBinaryDecodeGetOneByte fail\n");
1541 if (oneByte > 0x7F) {
1542 /* Well-known-media */
1543 pMsgType->type = _MmsGetBinaryType(MmsCodeContentType, (UINT16)(oneByte & 0x7F));
1546 /* Extension-Media */
1547 gCurMmsDecodeBuffPos--;
1550 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1551 pMsgType->type = _MmsGetTextType(MmsCodeContentType, szTypeString);
1552 valueLength -= textLength;
1556 szTypeString = NULL;
1560 MSG_DEBUG("MmsBinaryDecodeContentType: content type=%s\n", MmsDebugGetMimeType((MimeType)pMsgType->type));
1563 if (MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false) {
1564 MSG_DEBUG("MmsBinaryDecodeContentType: Content-Type parameter fail\n");
1576 bool MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int headerLen, int totalLength)
1578 UINT8 fieldCode = 0xff;
1580 UINT32 valueLength = 0;
1582 char *pValue = NULL;
1583 char *pParam = NULL;
1589 char *pLatinBuff = NULL;
1591 char *szTemp = NULL;
1594 if (pFile == NULL || pMsgType == NULL)
1598 * Message-header = Well-known-header | Application-header
1599 * Well-known-header = Well-known-field-name Wap-value
1600 * Application-header = Token-text Application-specific-value
1601 * Well-known-field-name = Short-integer
1602 * Application-specific-value = Text-string
1605 while (headerLen > 0) {
1606 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1607 MSG_DEBUG("MmsBinaryDecodePartHeader: field code GetOneByte fail\n");
1611 if (0x80 <= oneByte && oneByte <= 0xC7) {
1612 /* Well-known-header = Well-known-field-name Wap-value (0x00 ~ 0x47) */
1614 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, 1) == false)
1617 fieldCode = oneByte & 0x7f;
1619 switch (fieldCode) {
1620 case 0x0E: //Content-Location
1621 case 0x04: //Content-Location
1623 pLatinBuff = (char *)malloc(MMS_CONTENT_ID_LEN + 1);
1624 if (pLatinBuff == NULL)
1627 length = __MmsBinaryDecodeText(pFile, pLatinBuff, MMS_CONTENT_ID_LEN + 1, totalLength);
1629 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeQuotedString fail.\n");
1633 szSrc = MsgChangeHexString(pLatinBuff);
1636 strcpy(pLatinBuff, szSrc);
1641 textLength = strlen(pLatinBuff);
1643 if (MsgLatin2UTF ((unsigned char*)pMsgType->szContentLocation, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, textLength) < 0) {
1644 MSG_DEBUG("MmsBinaryDecodePartHeader: MsgLatin2UTF fail \n");
1651 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1656 case 0x40: // Content-ID
1658 pLatinBuff = (char *)malloc(MMS_CONTENT_ID_LEN + 1);
1659 if (pLatinBuff == NULL)
1662 length = __MmsBinaryDecodeQuotedString(pFile, pLatinBuff, MMS_CONTENT_ID_LEN + 1, totalLength);
1665 MSG_DEBUG("MmsBinaryDecodePartHeader : Content-ID __MmsBinaryDecodeQuotedString fail.\n");
1669 szSrc = MsgChangeHexString(pLatinBuff);
1672 strcpy(pLatinBuff, szSrc);
1677 textLength = strlen(pLatinBuff);
1678 if (MsgLatin2UTF ((unsigned char*)pMsgType->szContentID, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, textLength) < 0) {
1679 MSG_DEBUG("MmsBinaryDecodePartHeader: MsgLatin2UTF fail \n");
1685 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1690 case 0x2E: // Content-Disposition
1691 case 0x45: // Content-Disposition
1694 * Content-disposition-value = Value-length Disposition *(Parameter)
1695 * Disposition = Form-data | Attachment | Inline | Token-text
1696 * Form-data = <Octet 128> : 0x80
1697 * Attachment = <Octet 129> : 0x81
1698 * Inline = <Octet 130> : 0x82
1701 length = __MmsDecodeValueLength2(pFile, &valueLength, totalLength);
1704 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1709 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1710 MSG_DEBUG("MmsBinaryDecodePartHeader: Disposition value GetOneByte fail\n");
1717 if (oneByte >= 0x80) {
1718 pMsgType->disposition = _MmsGetBinaryType(MmsCodeMsgDisposition, (UINT16)(oneByte & 0x7F));
1720 if (pMsgType->disposition == INVALID_HOBJ) {
1721 MSG_DEBUG("MmsBinaryDecodePartHeader : Content-Disposition _MmsGetBinaryType fail.\n");
1722 pMsgType->disposition = MSG_DISPOSITION_ATTACHMENT; // default
1725 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, 1) == false)
1728 if (MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false) {
1729 MSG_DEBUG("MmsBinaryDecodePartHeader: Disposition parameter fail\n");
1733 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, valueLength) == false)
1737 gCurMmsDecodeBuffPos--;
1740 pLatinBuff = (char *)malloc(MSG_FILENAME_LEN_MAX);
1741 memset(pLatinBuff, 0, MSG_FILENAME_LEN_MAX);
1743 textLength = __MmsBinaryDecodeText(pFile, pLatinBuff, MSG_FILENAME_LEN_MAX-1, totalLength);
1746 if (textLength < 0) {
1747 MSG_DEBUG("MmsBinaryDecodePartHeader : Content-Disposition decodingfail. \n");
1753 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, textLength) == false)
1756 valueLength -= textLength;
1758 if (MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false)
1760 MSG_DEBUG("MmsBinaryDecodePartHeader: Disposition parameter fail\n");
1764 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, valueLength) == false)
1771 case 0x0B: //Content-Encoding
1773 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1774 MSG_DEBUG("MmsBinaryDecodePartHeader: Disposition value GetOneByte fail\n");
1778 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, 1) == false)
1783 case 0x0C: //Content-Language
1785 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&tmpInt, &tmpIntLen, totalLength) == true) {
1786 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, tmpIntLen) == false)
1791 cTemp = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1793 if (cTemp == NULL) {
1794 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeText2 fail...\n");
1798 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, textLength) == false) {
1811 case 0x0D: //Content-Length
1813 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&tmpInt, &tmpIntLen, totalLength) == false) {
1814 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeInteger fail...\n");
1818 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, tmpIntLen) == false)
1823 case 0x30: //X-Wap-Content-URI skip this value
1825 MSG_DEBUG("MmsBinaryDecodePartHeader : X-Wap-Content-URI header.\n");
1826 pLatinBuff = (char *)malloc(MMS_TEXT_LEN);
1827 if (pLatinBuff == NULL)
1830 length = __MmsBinaryDecodeText(pFile, pLatinBuff, MMS_TEXT_LEN, totalLength);
1833 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeQuotedString fail.\n");
1837 MSG_DEBUG("MmsBinaryDecodePartHeader : X-Wap-Content-URI header decoded. Value length %d\n", length);
1841 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1844 MSG_DEBUG("MmsBinaryDecodePartHeader : X-Wap-Content-URI header skipped.\n");
1848 case 0x01: // Accept-charset
1849 //if (NvGetInt(NV_SI_ADM_GCF_STATE) == 1)
1851 /* WAP-230-WSP-200010705-a.pdf
1852 8.4.2.8 Accept charset field
1853 The following rules are used to encode accept character set values.
1854 Accept-charset-value = Constrained-charset | Accept-charset-general-form
1855 Accept-charset-general-form = Value-length (Well-known-charset | Token-text) [Q-value]
1856 Constrained-charset = Any-charset | Constrained-encoding
1857 Well-known-charset = Any-charset | Integer-value
1858 ; Both are encoded using values from Character Set Assignments table in Assigned Numbers
1859 Any-charset = <Octet 128>
1860 ; Equivalent to the special RFC2616 charset value ¡°*¡±
1866 MSG_DEBUG("MmsBinaryDecodePartHeader : Accept-charset. \n");
1868 length = __MmsDecodeValueLength(pFile, &valueLength, totalLength);
1870 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1875 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&charset, &charSetLen, totalLength) == false) {
1876 // We only support the well-known-charset format
1877 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeInteger fail...\n");
1882 _MmsGetBinaryType(MmsCodeCharSet, (UINT16)charset);
1884 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, charSetLen) == false)
1892 /* Other Content-xxx headers : Have valueLength */
1894 MSG_DEBUG("MmsBinaryDecodePartHeader : unknown Value = 0x%x\n", oneByte);
1896 length = __MmsDecodeValueLength(pFile, &valueLength, totalLength);
1898 MSG_DEBUG("MmsBinaryDecodePartHeader : 1. invalid MMS_CODE_PREVIOUSLYSENTDATE \n");
1902 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1905 szTemp = (char *)malloc(valueLength);
1909 if (_MmsBinaryDecodeGetBytes(pFile, szTemp, valueLength, totalLength) < 0) {
1910 MSG_DEBUG("MmsBinaryDecodePartHeader : default _MmsBinaryDecodeGetBytes() fail\n");
1918 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, valueLength) == false)
1925 * Application-header = Token-text Application-specific-value
1926 * Application-specific-value = Text-string
1929 MSG_DEBUG(" MmsBinaryDecodePartHeader: Application-header = Token-text Application-specific-value \n");
1931 gCurMmsDecodeBuffPos--;
1936 pCode = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1937 if (pCode == NULL) {
1938 MSG_DEBUG("MmsBinaryDecodePartHeader: pCode is null\n");
1942 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, textLength) == false)
1945 MSG_DEBUG(" MmsBinaryDecodePartHeader: Token-text (%s) \n", pCode);
1948 /* Application-specific-value */
1951 pValue = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1952 if (pValue == NULL) {
1953 MSG_DEBUG("MmsBinaryDecodePartHeader: pValue is null\n");
1957 MSG_DEBUG(" MmsBinaryDecodePartHeader: Application-specific-value (%s) \n", pValue);
1960 pParam = strchr(pValue, MSG_CH_ADDR_DELIMETER);
1966 switch (_MmsGetTextType(MmsCodeMsgBodyHeaderCode, pCode)) {
1967 case MMS_BODYHDR_TRANSFERENCODING: // Content-Transfer-Encoding
1968 pMsgType->encoding = _MmsGetTextType(MmsCodeContentTransferEncoding, pValue);
1971 case MMS_BODYHDR_CONTENTID: // Content-ID
1973 pLatinBuff = (char *)malloc(MMS_CONTENT_ID_LEN + 1);
1974 if (pLatinBuff == NULL)
1979 MsgMIMERemoveQuote (pValue);
1980 strncpy(pLatinBuff, pValue, MMS_MSG_ID_LEN);
1982 length = strlen(pLatinBuff);
1983 if (MsgLatin2UTF ((unsigned char*)pMsgType->szContentID, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, length) < 0)
1985 MSG_DEBUG("MmsBinaryDecodePartHeader: MsgLatin2UTF fail \n");
1993 case MMS_BODYHDR_CONTENTLOCATION: // Content-Location
1995 pLatinBuff = (char *)malloc(MMS_CONTENT_ID_LEN + 1);
1996 if (pLatinBuff == NULL)
1999 strncpy(pLatinBuff, pValue, MMS_MSG_ID_LEN);
2001 length = strlen(pLatinBuff);
2002 if (MsgLatin2UTF ((unsigned char*)pMsgType->szContentLocation, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, length) < 0) {
2003 MSG_DEBUG("MmsBinaryDecodePartHeader: MsgLatin2UTF fail \n");
2011 case MMS_BODYHDR_DISPOSITION: // Content-Disposition
2012 pMsgType->disposition = _MmsGetTextType(MmsCodeMsgDisposition, pValue);
2015 case MMS_BODYHDR_X_OMA_DRM_SEPARATE_DELIVERY: // DRM RO WAITING
2019 MSG_DEBUG("Unknown Field : %s, Value: %s\n", pCode, pValue);
2024 _MsgParseParameter(pMsgType, pParam + 1);
2036 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, textLength) == false)
2085 bool MmsBinaryDecodeEntries(FILE *pFile, UINT32 *npEntries, int totalLength)
2089 length = __MmsBinaryDecodeUintvar(pFile, npEntries, totalLength);
2094 MSG_DEBUG("MmsBinaryDecodeEntries: Number of Entries = %d\n", *npEntries);
2104 bool MmsBinaryDecodePartBody(FILE *pFile, UINT32 bodyLength, int totalLength)
2109 * Currently, offset and size is
2110 * the only information used with msgBody.
2111 * If you need, add here more information
2114 MSG_DEBUG("MmsBinaryDecodePartBody: \n");
2116 offset = _MmsGetDecodeOffset();
2117 offset += bodyLength;
2119 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
2120 MSG_DEBUG("MmsBinaryDecodePartBody: fail to seek file pointer \n");
2124 _MmsCleanDecodeBuff();
2126 gMmsDecodeCurOffset = offset;
2128 if (offset >= totalLength)
2131 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
2132 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
2133 MSG_DEBUG("_MmsBinaryDecodeGetOneByte: fail to load to buffer \n");
2147 static bool MmsBinaryDecodeMovePointer(FILE *pFile, int offset, int totalLength)
2149 if (offset > totalLength)
2152 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
2153 MSG_DEBUG("MmsBinaryDecodeMovePointer: fail to seek file pointer \n");
2157 _MmsCleanDecodeBuff();
2159 gMmsDecodeCurOffset = offset;
2161 if (offset == totalLength)
2164 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
2165 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
2166 MSG_DEBUG("MmsBinaryDecodeMovePointer: fail to load to buffer \n");
2178 bool MmsBinaryIsTextEncodedPart(FILE *pFile, int totalLength)
2183 byteCount++; //check 0x0D
2185 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2188 if (oneByte != 0x0D) {
2189 //it can be started "--" without 0x0D 0x0A
2190 if (oneByte != 0x2D) {
2193 byteCount++; // check 0x2D ('-')
2194 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2197 if (oneByte != 0x2D) {
2204 byteCount++; //check 0x0A
2205 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2208 if (oneByte != 0x0A) {
2211 byteCount++; // check 0x2D ('-')
2212 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2215 if (oneByte != 0x2D) {
2218 byteCount++; // check 0x2D ('-')
2219 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2222 if (oneByte != 0x2D) {
2232 gCurMmsDecodeBuffPos -= byteCount;
2236 gCurMmsDecodeBuffPos -= byteCount;
2241 bool MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, int totalLength)
2243 UINT32 nEntries = 0;
2244 MsgMultipart *pMultipart = NULL;
2245 MsgMultipart *pLastMultipart = NULL;
2246 MsgMultipart *pPreMultipart = NULL;
2250 MsgPresentationFactor factor = MSG_PRESENTATION_NONE;
2251 MsgPresentaionInfo presentationInfo;
2253 MSG_DEBUG("MmsBinaryDecodeMultipart: total length=%d\n", totalLength);
2255 presentationInfo.factor = MSG_PRESENTATION_NONE;
2256 presentationInfo.pCurPresentation = NULL;
2257 presentationInfo.pPrevPart = NULL;
2259 if (MmsBinaryDecodeEntries(pFile, &nEntries, totalLength) == false) {
2260 MSG_DEBUG("MmsBinaryDecodeMultipart: MmsBinaryDecodeEntries is fail.\n");
2265 MSG_DEBUG("MmsBinaryDecodeMultipart: decoding %dth multipart\n", index);
2267 offset = _MmsGetDecodeOffset();
2268 if (offset >= totalLength)
2271 if ((pMultipart = MsgAllocMultipart()) == NULL) {
2272 MSG_DEBUG("MmsBinaryDecodeMultipart: MsgAllocMultipart Fail \n");
2276 if (MmsBinaryDecodeEachPart(pFile, szFilePath, &(pMultipart->type), pMultipart->pBody, totalLength) == false) {
2277 MSG_DEBUG("MmsBinaryDecodeMultipart: MmsBinaryDecodeEachPart is fail.(nEntries = %d)\n", nEntries);
2281 if (pMsgType->param.type == MIME_APPLICATION_SMIL) {
2282 factor = MsgIsPresentationEx(&(pMultipart->type), pMsgType->param.szStart, (MimeType)pMsgType->param.type);
2284 factor = MSG_PRESENTATION_NONE;
2286 // priority 1 : content type match, 2: content location, 3: type
2287 if (presentationInfo.factor < factor) {
2288 // Presentation part
2289 presentationInfo.factor = factor;
2290 presentationInfo.pPrevPart = pPreMultipart;
2291 presentationInfo.pCurPresentation = pMultipart;
2294 if (pMsgBody->body.pMultipart == NULL) {
2295 /* first multipart */
2296 pMsgBody->body.pMultipart = pMultipart;
2297 pLastMultipart = pMultipart;
2298 pPreMultipart = NULL;
2299 } else if (pLastMultipart != NULL) {
2300 pPreMultipart = pLastMultipart;
2302 pLastMultipart->pNext = pMultipart;
2303 pLastMultipart = pMultipart;
2306 pMsgType->contentSize += pMultipart->pBody->size;
2309 pPreMultipart = pMultipart;
2310 MmsDebugPrintMulitpartEntry(pMultipart, index++);
2314 pMsgBody->size = totalLength - pMsgBody->offset;
2316 #ifdef __SUPPORT_DRM__
2317 if (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_REQUIRED)
2319 MsgConfirmPresentationPart(pMsgType, pMsgBody, &presentationInfo);
2321 if (MsgResolveNestedMultipart(pMsgType, pMsgBody) == false) {
2322 MSG_DEBUG("MmsBinaryDecodeMultipart : MsgResolveNestedMultipart failed \n");
2334 bool MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, int totalLength)
2337 bool bSuccess = false;
2338 UINT32 headerLength = 0;
2339 UINT32 bodyLength = 0;
2342 MSG_DEBUG("MmsBinaryDecodeEachPart: total length=%d\n", totalLength);
2346 if (__MmsBinaryDecodeUintvar(pFile, &headerLength, totalLength) <= 0) {
2347 MSG_DEBUG("MmsBinaryDecodeEachPart: Get header length fail \n");
2351 offset = _MmsGetDecodeOffset();
2352 if (offset >= totalLength)
2358 if (__MmsBinaryDecodeUintvar(pFile, &bodyLength, totalLength) <= 0) {
2359 MSG_DEBUG("MmsBinaryDecodeEachPart: Get body length fail\n");
2364 offset = _MmsGetDecodeOffset();
2365 if (offset >= totalLength)
2370 if (szFilePath != NULL)
2371 strncpy(pMsgType->szOrgFilePath, szFilePath, strlen(szFilePath));
2373 pMsgType->offset = _MmsGetDecodeOffset();
2374 pMsgType->size = headerLength;
2375 pMsgType->contentSize = bodyLength;
2377 if (pMsgType->offset > totalLength)
2380 length = MmsBinaryDecodeContentType(pFile, pMsgType, totalLength);
2382 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentType Fail \n");
2386 offset = _MmsGetDecodeOffset();
2387 if (offset >= totalLength)
2393 if (MmsBinaryDecodePartHeader(pFile, pMsgType, headerLength - length, totalLength) == false) {
2394 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentHeader Fail \n");
2398 offset = _MmsGetDecodeOffset();
2399 if (offset >= totalLength)
2404 if (szFilePath != NULL)
2405 strncpy(pMsgBody->szOrgFilePath, szFilePath, strlen(szFilePath));
2407 pMsgBody->offset = _MmsGetDecodeOffset();
2408 pMsgBody->size = bodyLength;
2410 if (pMsgBody->offset > totalLength)
2413 switch (pMsgType->type) {
2414 case MIME_APPLICATION_VND_WAP_MULTIPART_MIXED:
2415 case MIME_APPLICATION_VND_WAP_MULTIPART_RELATED:
2416 case MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC:
2417 case MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE:
2418 case MIME_MULTIPART_REPORT:
2419 case MIME_MULTIPART_MIXED:
2420 case MIME_MULTIPART_RELATED:
2421 case MIME_MULTIPART_ALTERNATIVE:
2423 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode multipart\n");
2425 if (MmsBinaryDecodeMultipart(pFile, szFilePath, pMsgType, pMsgBody, totalLength) == false) {
2426 MSG_DEBUG("MmsBinaryDecodeEachPart: MmsBinaryDecodeMultipart is fail.\n");
2430 offset = _MmsGetDecodeOffset();
2431 if (offset >= totalLength)
2437 #ifdef __SUPPORT_DRM__
2439 case MIME_APPLICATION_VND_OMA_DRM_MESSAGE: /* Contains forwardLock OR combined-delivery media part */
2440 MSG_DEBUG("MmsBinaryDecodeEachPart: MIME_APPLICATION_VND_OMA_DRM_MESSAGE Part \n");
2442 if (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_NOT_FIXED && MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_REQUIRED) {
2444 if (MmsBinaryDecodeDRMContent(pFile, szFilePath, pMsgType, pMsgBody, bodyLength, totalLength) == false)
2447 MmsDrm2SetConvertState(MMS_DRM2_CONVERT_REQUIRED);
2449 bSuccess = MmsBinaryDecodePartBody(pFile, bodyLength, totalLength);
2450 if (bSuccess == false) {
2451 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentBody Fail \n");
2455 offset = _MmsGetDecodeOffset();
2456 if (offset >= totalLength)
2461 case MIME_APPLICATION_VND_OMA_DRM_CONTENT: /* Contains seperate-delivery media part (DCF) */
2463 MSG_DEBUG("MmsBinaryDecodeEachPart: MIME_APPLICATION_VND_OMA_DRM_CONTENT Part \n");
2465 if (MmsBinaryDecodeDRMContent(pFile, szFilePath, pMsgType, pMsgBody, bodyLength, totalLength) == false)
2468 offset = _MmsGetDecodeOffset();
2469 if (offset >= totalLength)
2476 MSG_DEBUG("MmsBinaryDecodeEachPart: Other normal Part \n");
2478 bSuccess = MmsBinaryDecodePartBody(pFile, bodyLength, totalLength);
2479 if (bSuccess == false) {
2480 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentBody Fail \n");
2484 offset = _MmsGetDecodeOffset();
2485 if (offset >= totalLength)
2502 #ifdef __SUPPORT_DRM__
2503 bool __MmsParseDCFInfo(FILE *pFile, MsgDRMInfo *pDrmInfo, int totalLength)
2506 UINT8 contentTypeLen = 0;
2507 UINT8 contentURILen = 0;
2508 char *szContentType = NULL;
2509 char *szContentURI = NULL;
2511 if (_MmsBinaryDecodeGetOneByte(pFile, &version, totalLength) == false) {
2512 MSG_DEBUG("__MmsParseDCFInfo: [version] GetOneByte fail\n");
2516 if (_MmsBinaryDecodeGetOneByte(pFile, &contentTypeLen, totalLength) == false) {
2517 MSG_DEBUG("__MmsParseDCFInfo: [contentTypeLen] GetOneByte fail\n");
2521 if (_MmsBinaryDecodeGetOneByte(pFile, &contentURILen, totalLength) == false) {
2522 MSG_DEBUG("__MmsParseDCFInfo: [contentURILen] GetOneByte fail\n");
2526 //Get media content-type (mime-type)
2527 szContentType = (char *)malloc(contentTypeLen + 1);
2528 if (szContentType == NULL)
2531 memset(szContentType, 0, contentTypeLen + 1);
2533 if (_MmsBinaryDecodeGetBytes(pFile, szContentType, contentTypeLen + 1, totalLength) < 0) {
2534 MSG_DEBUG("__MmsParseDCFInfo : contentType is invalid\n");
2537 gCurMmsDecodeBuffPos--;
2538 pDrmInfo->contentType = (MsgContentType)_MsgGetCode(MSG_TYPE, szContentType);
2541 //Get content-ID - 1.remover "cid:", 2.resolve "%hexa", 3.and copy the string
2542 szContentURI = (char *)malloc(contentURILen + 1);
2543 if (szContentURI == NULL)
2546 memset(szContentURI, 0, contentURILen + 1);
2548 if (_MmsBinaryDecodeGetBytes(pFile, szContentURI, contentURILen + 1, totalLength) < 0) {
2549 MSG_DEBUG("__MmsParseDCFInfo : contentType is invalid\n");
2552 gCurMmsDecodeBuffPos--;
2553 pDrmInfo->szContentURI = MsgResolveContentURI(szContentURI);
2556 if (szContentType) {
2557 free(szContentType);
2558 szContentType = NULL;
2563 szContentURI = NULL;
2570 if (szContentType) {
2571 free(szContentType);
2572 szContentType = NULL;
2577 szContentURI = NULL;
2584 bool __MmsParseDCFHdr(FILE *pFile, MsgDRMInfo *pDrmInfo, UINT32 headerLen, int totalLength)
2586 char *szDCFHdr = NULL;
2591 /* add to parse DCF header such as,
2592 * Right-Issuer, Content-Name, and Content-Description.
2595 szDCFHdr = (char *)malloc(headerLen + 1);
2596 if (szDCFHdr == NULL) {
2597 MSG_DEBUG("__MmsParseDCFHdr: szDCFHdr alloc fail\n");
2600 memset(szDCFHdr, 0, headerLen + 1);
2602 offset = _MmsGetDecodeOffset();
2603 if (offset >= totalLength)
2606 if (MsgFseek(pFile, offset, SEEK_SET) < 0)
2609 if ((nRead = MsgReadFile(szDCFHdr, sizeof(char), headerLen, pFile)) == 0){
2612 szDCFHdr[nRead] = '\0';
2614 _MsgInitMsgType(&partType);
2615 _MsgParsePartHeader(&partType, szDCFHdr, headerLen);
2617 pDrmInfo->szContentName = partType.drmInfo.szContentName;
2618 pDrmInfo->szContentVendor = partType.drmInfo.szContentVendor;
2619 pDrmInfo->szContentDescription = partType.drmInfo.szContentDescription;
2620 pDrmInfo->szRightIssuer = partType.drmInfo.szRightIssuer;
2622 if (MmsBinaryDecodeMovePointer(pFile, offset + headerLen, totalLength) == false)
2645 bool MmsBinaryDecodeDRMContent(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int bodyLength, int totalLength)
2648 char szTempFilePath[MSG_FILEPATH_LEN_MAX] = MSG_DATA_PATH"drm.dcf";
2649 char *pRawData = NULL;
2650 bool isFileCreated = false;
2652 MSG_DEBUG("bodyLength: %d\n", bodyLength);
2654 offset = _MmsGetDecodeOffset();
2656 if (offset >= totalLength)
2659 if (szFilePath != NULL)
2660 strncpy(pMsgBody->szOrgFilePath, szFilePath, strlen(szFilePath));
2661 if (szFilePath != NULL)
2662 strncpy(pMsgType->szOrgFilePath, szFilePath, strlen(szFilePath));
2664 pRawData = (char *)malloc(bodyLength);
2665 if (pRawData == NULL) {
2666 MSG_DEBUG("pRawData alloc FAIL \n");
2670 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
2671 MSG_DEBUG("MsgFseek() returns -1 \n");
2674 if (MsgReadFile(pRawData, sizeof(char), bodyLength, pFile) != (size_t)bodyLength) {
2675 MSG_DEBUG("FmReadFile() returns false \n");
2678 if (MsgOpenCreateAndOverwriteFile(szTempFilePath, pRawData, bodyLength) == false) {
2679 MSG_DEBUG("MsgOpenCreateAndOverwriteFile() returns false \n");
2683 isFileCreated = true;
2684 MSG_DEBUG("MmsDrm2GetConvertState() [%d]", MmsDrm2GetConvertState());
2686 if (pMsgType->type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE && (MmsDrm2GetConvertState()!=MMS_DRM2_CONVERT_FINISH)) {
2687 MmsDrm2SetConvertState(MMS_DRM2_CONVERT_REQUIRED);
2689 if (MsgDRM2GetDRMInfo(szTempFilePath, pMsgType) == false) {
2690 MSG_DEBUG("MsgDRM2GetDRMInfo() returns false \n");
2695 remove(szTempFilePath);
2696 isFileCreated = false;
2698 if (MmsBinaryDecodeMovePointer(pFile, offset + bodyLength, totalLength) == false)
2712 remove(szTempFilePath);
2723 bool MmsBinaryDecodeDRMMessage(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int fullBodyLength, int totalLength)
2726 char szTempFilePath[MSG_FILEPATH_LEN_MAX] = "/User/Msg/Mms/Temp/drm.dm";
2727 char *pRawData = NULL;
2728 bool isFileCreated = false;
2730 offset = _MmsGetDecodeOffset();
2731 if (offset >= totalLength)
2734 if (szFilePath != NULL)
2735 strncpy(pMsgBody->szOrgFilePath, szFilePath, strlen(szFilePath));
2736 if (szFilePath != NULL)
2737 strncpy(pMsgType->szOrgFilePath, szFilePath, strlen(szFilePath));
2739 pRawData = (char *)malloc(fullBodyLength);
2740 if (pRawData == NULL) {
2741 MSG_DEBUG("pRawData alloc FAIL \n");
2745 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
2746 MSG_DEBUG("MsgFseek() returns -1 \n");
2750 if (MsgReadFile(pRawData, sizeof(char), fullBodyLength, pFile)!= (size_t)fullBodyLength) {
2751 MSG_DEBUG("FmReadFile() returns false \n");
2755 if (MsgOpenCreateAndOverwriteFile(szTempFilePath, pRawData, fullBodyLength) == false) {
2756 MSG_DEBUG("MsgOpenCreateAndOverwriteFile() returns false \n");
2759 isFileCreated = true;
2761 if (strstr(szTempFilePath, ".dm")) {
2762 char szConvertedFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
2764 if (MsgDrmConvertDmtoDcfType(szTempFilePath, szConvertedFilePath)) {
2765 remove(szTempFilePath);
2766 memset(szTempFilePath, 0, MSG_FILEPATH_LEN_MAX);
2767 strncpy(szTempFilePath, szConvertedFilePath, MSG_FILEPATH_LEN_MAX-1);
2771 if (MsgDRM2GetDRMInfo(szTempFilePath, pMsgType) == false) {
2772 MSG_DEBUG("MsgDRM2GetDRMInfo() returns false \n");
2776 remove(szTempFilePath);
2777 isFileCreated = false;
2779 if (MmsBinaryDecodeMovePointer(pFile, offset + fullBodyLength, totalLength) == false)
2792 remove(szTempFilePath);
2801 static int __MmsDrm2BinaryEncodeUintvarLen(UINT32 integer)
2805 /* Find encoded unitvar length */
2806 if (integer <= MMS_UINTVAR_LENGTH_1) {
2809 if (integer <= MMS_UINTVAR_LENGTH_2) {
2812 if (integer <= MMS_UINTVAR_LENGTH_3) {
2824 static bool __MmsDrm2BinaryEncodeUintvar(UINT32 integer, int length, char *pszOutput)
2826 const char ZERO = 0x00;
2828 char szReverse[MSG_STDSTR_LONG] = {0, };
2834 source.integer = integer;
2835 memset(szReverse, 0, MSG_STDSTR_LONG);
2837 /* Seperate integer to 4 1 byte integer */
2838 szReverse[3] = source.bytes[3] & 0x0f;
2839 szReverse[0] = source.bytes[0];
2840 szReverse[0] = szReverse[0] & 0x7f;
2842 while (length >= i) {// initially, i = 2
2843 /* Move integer bit to proper position */
2844 source.integer = source.integer << 1;
2845 source.integer = source.integer >> 8;
2846 source.bytes[3] = ZERO;
2848 /* Retrive 1 encode uintvar */
2849 szReverse[i-1] = source.bytes[0];
2850 szReverse[i-1] = szReverse[i-1] | 0x80;
2854 for (i=0; i < length; i++)
2855 pszOutput[i] = szReverse[length - i - 1];
2861 static int __MmsDrm2GetEntriesValueLength(FILE *pFile, int orgOffset)
2863 char szEntries[5] = {0, };
2865 int j = 0; //j is the length of nEntries value
2867 if (MsgReadFile(szEntries, sizeof(char), 4, pFile) != (size_t)4) {
2868 MSG_DEBUG("__MmsDrm2GetEntriesValueLength: FmReadFile() returns false \n");
2873 oneByte = szEntries[j++];
2875 if (oneByte <= 0x7f)
2879 //move file pointer to point nEntries
2880 if (MsgFseek(pFile, orgOffset, SEEK_SET) < 0) {
2881 MSG_DEBUG("__MmsDrm2GetEntriesValueLength: fail to seek file pointer\n");
2889 static bool __MmsDrm2WriteDataToConvertedFile(FILE *pSrcFile, FILE *pDestinationFile, char *pszMmsLoadTempBuf, int length, int bufLen)
2891 int loadLen = 0, totalLoadLen = 0, nRead = 0;
2893 for (int i=0; i<(length/bufLen)+1; i++) {
2894 loadLen = (length-totalLoadLen < bufLen) ? length-totalLoadLen : bufLen;
2896 memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
2898 if (MsgReadFile(pszMmsLoadTempBuf, sizeof(char), loadLen, pSrcFile) != (size_t)loadLen) {
2899 MSG_DEBUG("__MmsDrm2WriteDataToConvertedFile: FmReadFile() returns false \n");
2903 if (MsgWriteFile(pszMmsLoadTempBuf, sizeof(char), loadLen, pDestinationFile) != (size_t)loadLen) {
2904 MSG_DEBUG("__MmsDrm2WriteDataToConvertedFile: File Writing is failed.\n");
2908 totalLoadLen += nRead;
2915 /*************************************************************************
2916 * description : make new message file converting CD & FL part of original message file to SD type
2919 - bool : result of converting
2920 **************************************************************************/
2921 bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
2924 FILE *hConvertedFile = NULL;
2925 FILE *hTempFile = NULL;
2927 MsgMultipart *pMultipart = NULL;
2928 char szTempFilePath[MSG_FILEPATH_LEN_MAX] = MSG_DATA_PATH"Drm_Convert";
2929 char szTempFile[MSG_FILEPATH_LEN_MAX] = MSG_DATA_PATH"temp.dm";
2930 char *pszMmsLoadTempBuf = NULL;
2931 char *pszOrgData = NULL;
2933 int bufLen = MMS_DRM2_CONVERT_BUFFER_MAX;
2936 MSG_DEBUG("start convert~~~~~~\n");
2938 pFile = MsgOpenFile(szOriginFilePath, "rb");
2939 if (pFile == NULL) {
2940 MSG_DEBUG("Open decode temporary file fail\n");
2944 hConvertedFile = MsgOpenFile(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, "wb+");
2945 if (hConvertedFile == NULL) {
2946 MSG_DEBUG("Open decode temporary file fail\n");
2950 pszMmsLoadTempBuf = (char*)malloc(MMS_DRM2_CONVERT_BUFFER_MAX + 1);
2951 if (pszMmsLoadTempBuf == NULL) {
2952 MSG_DEBUG("malloc for pszMmsLoadTempBuf failed\n");
2955 memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
2958 length = mmsHeader.msgBody.offset;
2959 if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
2960 MSG_DEBUG("Write header data fail\n");
2964 curOffset += length; //change offset
2967 if (MsgIsMultipart(mmsHeader.msgType.type) == true)
2970 length = __MmsDrm2GetEntriesValueLength(pFile, curOffset); // getting nEntries value's length
2972 if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
2973 MSG_DEBUG("Write nEntries fail\n");
2977 curOffset += length; //change offset
2979 // each Multipart entry copy
2980 pMultipart = mmsHeader.msgBody.body.pMultipart;
2982 while (pMultipart) {
2983 if (pMultipart->type.type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE) {
2984 int orgDataLen = pMultipart->pBody->size;
2987 MSG_DEBUG("Write MIME_APPLICATION_VND_OMA_DRM_MESSAGE multipart data(orgDataLen = %d).\n", orgDataLen);
2989 pszOrgData = (char *)malloc(orgDataLen + 1);
2990 if (pszOrgData == NULL) {
2991 MSG_DEBUG("pszOrgData is NULL \n");
2994 memset(pszOrgData, 0, orgDataLen + 1);
2996 // move file pointer to data
2997 if (MsgFseek(pFile, pMultipart->pBody->offset, SEEK_SET) < 0) {
2998 MSG_DEBUG("fail to seek file pointer 1\n");
3002 if (MsgReadFile(pszOrgData, sizeof(char), orgDataLen, pFile) != (size_t)orgDataLen) {
3003 MSG_DEBUG("FmReadFile() returns false for orgData\n");
3007 if((hFile = MsgOpenFile(szTempFile, "wb+")) == NULL) {
3008 MSG_DEBUG("file open failed [%s]", szTempFile);
3012 if (MsgWriteFile(pszOrgData, sizeof(char), orgDataLen, hFile) != (size_t)orgDataLen) {
3013 MSG_DEBUG("File write error");
3018 MsgCloseFile(hFile);
3022 // --> invoking drm agent api, converting data part start
3023 MSG_DEBUG("start data part convert by callling drm agent api\n");
3026 ret = MsgDrmConvertDmtoDcfType(szTempFile, szTempFilePath);
3027 MSG_DEBUG("MsgDrmConvertDmtoDcfType returned %s", ret ? "true": "false");
3029 if (MsgGetFileSize(szTempFilePath, &nSize) == false) {
3030 MSG_DEBUG("MsgGetFileSize error");
3033 MSG_DEBUG("MmsDrm2ConvertMsgBody: end data part convert(converted data len = %d)\n", nSize);
3034 // <-- invoking drm agent api, converting data part end
3036 // move file pointer to the head of multipart
3037 if (MsgFseek(pFile, curOffset, SEEK_SET) < 0) {
3038 MSG_DEBUG("fail to seek file pointer 2\n");
3042 // read headerLen, dataLen
3043 length = pMultipart->type.offset - curOffset;
3044 memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
3045 if (MsgReadFile(pszMmsLoadTempBuf, sizeof(char), length, pFile) != (size_t)length) {
3046 MSG_DEBUG("FmReadFile() returns false for headerLen, dataLen\n");
3050 curOffset += length;
3052 // change dataLen based on converted data
3057 char szOutput[MSG_STDSTR_LONG] = {0, };
3060 oneByte = pszMmsLoadTempBuf[j++];
3062 if (oneByte <= 0x7f)
3066 encodeLen = __MmsDrm2BinaryEncodeUintvarLen((UINT32)nSize);
3067 __MmsDrm2BinaryEncodeUintvar((UINT32)nSize, encodeLen, szOutput);
3069 strncpy(&(pszMmsLoadTempBuf[j]), szOutput, encodeLen);
3070 pszMmsLoadTempBuf[j+encodeLen] = '\0';
3072 if (MsgWriteFile(pszMmsLoadTempBuf, sizeof(char), length, hConvertedFile) != (size_t)length) {
3073 MSG_DEBUG("Drm2WriteConvertData: FmWriteFile() returns false for dateLen\n");
3079 length = pMultipart->pBody->offset - pMultipart->type.offset;
3081 if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
3082 MSG_DEBUG("Drm2WriteConvertData: Write content type, headers fail\n");
3086 curOffset += length;
3088 // write converted data
3089 hTempFile = MsgOpenFile(szTempFilePath, "rb");
3090 if (hTempFile == NULL) {
3091 MSG_DEBUG("Open decode temporary file fail\n");
3097 if (__MmsDrm2WriteDataToConvertedFile(hTempFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
3098 MSG_DEBUG("Write converted data fail\n");
3102 if (hTempFile != NULL) {
3103 MsgCloseFile(hTempFile);
3107 curOffset += pMultipart->pBody->size;
3109 // move file pointer to the head of multipart
3110 if (MsgFseek(pFile, curOffset, SEEK_SET) < 0) {
3111 MSG_DEBUG("fail to seek file pointer \n");
3114 } else { // it doesn't need to convert if it is not CD or FL
3115 MSG_DEBUG("Write normal multipart data\n");
3117 length = pMultipart->pBody->offset + pMultipart->pBody->size - curOffset;
3119 if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
3120 MSG_DEBUG("Write multipart data fail \n");
3124 curOffset += length;
3127 pMultipart = pMultipart->pNext;
3131 MSG_DEBUG("end convert~~~~~~\n");
3133 if (pFile != NULL) {
3134 MsgCloseFile(pFile);
3138 if (hConvertedFile != NULL) {
3139 MsgCloseFile(hConvertedFile);
3140 hConvertedFile = NULL;
3143 if (hTempFile != NULL) {
3144 MsgCloseFile(hTempFile);
3148 if (pszMmsLoadTempBuf) {
3149 free(pszMmsLoadTempBuf);
3150 pszMmsLoadTempBuf = NULL;
3158 if (hFile != NULL) {
3159 MsgCloseFile(hFile);
3164 remove(szTempFilePath);
3170 if (pFile != NULL) {
3171 MsgCloseFile(pFile);
3175 if (hConvertedFile != NULL) {
3176 MsgCloseFile(hConvertedFile);
3177 hConvertedFile = NULL;
3180 if (hTempFile != NULL) {
3181 MsgCloseFile(hTempFile);
3185 if (pszMmsLoadTempBuf) {
3186 free(pszMmsLoadTempBuf);
3187 pszMmsLoadTempBuf = NULL;
3197 MsgCloseFile(hFile);
3202 remove(szTempFilePath);
3203 remove(MMS_DECODE_DRM_CONVERTED_TEMP_FILE); //remove convertin result if it goes to __CATCH
3209 /*************************************************************************
3210 * description : Function for decoding a converted file
3213 - bool : result of converting
3214 **************************************************************************/
3215 bool MmsDrm2DecodeConvertedMsg(int msgID, char *pszFullPath)
3217 FILE *hConvertedFile = NULL;
3220 MSG_DEBUG("MmsDrm2DecodeConvertedMsg: start re-decoding~~~~~~\n");
3223 _MsgFreeDRMInfo(&mmsHeader.msgType.drmInfo);
3224 _MsgFreeBody(&mmsHeader.msgBody, mmsHeader.msgType.type);
3227 _MmsUnregisterDecodeBuffer();
3230 _MmsRegisterDecodeBuffer(gszMmsLoadBuf1, gszMmsLoadBuf2, MSG_MMS_DECODE_BUFFER_MAX);
3232 // open converted file
3233 if ((hConvertedFile = MsgOpenFile(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, "rb")) == NULL) {
3234 MSG_DEBUG("MmsDrm2ReDecodeMsg: opening temporary file failed\n");
3238 if (MsgGetFileSize(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, &nSize) == false) {
3239 MSG_DEBUG("MsgGetFileSize: failed\n");
3243 if (!MmsBinaryDecodeMsgHeader(hConvertedFile, nSize)) {
3244 MSG_DEBUG("MmsDrm2ReDecodeMsg: decoding header(binary mode) failed\n");
3248 if (!MmsBinaryDecodeMsgBody(hConvertedFile, pszFullPath, nSize)) {
3249 MSG_DEBUG("MmsDrm2ReDecodeMsg: decoding body failed\n");
3253 if (hConvertedFile != NULL) {
3254 MsgCloseFile(hConvertedFile);
3255 hConvertedFile = NULL;
3262 if (hConvertedFile != NULL) {
3263 MsgCloseFile(hConvertedFile);
3264 remove(MMS_DECODE_DRM_CONVERTED_TEMP_FILE);
3265 hConvertedFile = NULL;
3272 bool MmsDrm2ReadMsgConvertedBody(MSG_MESSAGE_INFO_S *pMsg, bool bSavePartsAsTempFiles, bool bRetrieved, char *retrievedPath)
3275 MmsPluginStorage::instance()->getMmsMessage(&pMmsMsg);
3276 _MmsUnregisterDecodeBuffer();
3277 #ifdef __SUPPORT_DRM__
3278 _MsgFreeDRMInfo(&pMmsMsg->msgType.drmInfo);
3280 _MsgFreeBody(&pMmsMsg->msgBody, pMmsMsg->msgType.type);
3282 if (_MmsReadMsgBody(pMsg->msgId, bSavePartsAsTempFiles, bRetrieved, retrievedPath) == false) {
3283 MSG_DEBUG("MmsDrm2ReadMsgConvertedBody: _MmsReadMsgBody with converted file is failed\n");
3292 /* --------------------------------------------------------------------
3294 * B I N A R Y D E C D E U T I L I T Y
3296 * --------------------------------------------------------------------*/
3298 bool _MmsBinaryDecodeGetOneByte(FILE *pFile, UINT8 *pOneByte, int totalLength)
3300 int length = gMmsDecodeMaxLen - gCurMmsDecodeBuffPos;
3302 if (pFile == NULL || pOneByte == NULL)
3304 MSG_DEBUG("_MmsBinaryDecodeGetOneByte: invalid file or buffer\n");
3309 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3310 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3311 MSG_DEBUG("_MmsBinaryDecodeGetOneByte: fail to load to buffer \n");
3316 *pOneByte = gpCurMmsDecodeBuff[gCurMmsDecodeBuffPos++];
3326 * @remark: bufLen < gMmsDecodeMaxLen
3328 bool _MmsBinaryDecodeGetBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength)
3330 int length = gMmsDecodeMaxLen - gCurMmsDecodeBuffPos;
3334 if (pFile == NULL || szBuff == NULL || bufLen == 0 || bufLen > gMmsDecodeMaxLen)
3337 memset(szBuff, 0, bufLen);
3339 if (length < bufLen) {
3340 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3341 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3342 MSG_DEBUG("_MmsBinaryDecodeGetBytes: fail to load to buffer \n");
3347 for (i = 0; i < bufLen - 1; i++)
3348 szBuff[i] = gpCurMmsDecodeBuff[gCurMmsDecodeBuffPos++];
3351 gCurMmsDecodeBuffPos++; //NULL
3361 bool _MmsBinaryDecodeGetLongBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength)
3365 if (pFile == NULL || szBuff == NULL || bufLen == 0)
3368 memset(szBuff, 0, bufLen);
3370 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3371 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3372 MSG_DEBUG("_MmsBinaryDecodeGetLongBytes: fail to load to buffer \n");
3376 while ((bufLen - iPos) >= gMmsDecodeMaxLen) {
3377 if (_MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, gMmsDecodeMaxLen, totalLength) == false) {
3378 MSG_DEBUG("_MmsBinaryDecodeGetLongBytes: 1. _MmsBinaryDecodeGetBytes fail \n");
3382 iPos += gMmsDecodeMaxLen;
3385 if ((bufLen - iPos) > 0) {
3386 if (_MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, (bufLen - iPos), totalLength) == false) {
3387 MSG_DEBUG("_MmsBinaryDecodeGetLongBytes: 2. _MmsBinaryDecodeGetBytes fail \n");
3391 iPos += (bufLen - iPos);
3402 * Decode uintvar to 32bit unsigned integer
3404 * @param pEncodedData [in] encoded data
3405 * @param pUintVar [out] Decode uintvar (32bit unsigned integer)
3406 * @return The length of uintvar (-1, if cannot be converted to a uintvar)
3408 * 0 XXXXXXX -> 0-bit: continue bit & 1~7bit: integer value
3411 static const UINT32 uintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00100000, 0x08000000 };
3413 static int __MmsBinaryDecodeUintvar(FILE *pFile, UINT32 *pUintVar, int totalLength)
3417 UINT32 decodedUintvar = 0;
3418 UINT8 iBuff[5] = {0};
3419 int length = MSG_MMS_DECODE_BUFFER_MAX - gCurMmsDecodeBuffPos;
3422 if (pFile == NULL || pUintVar == NULL)
3426 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3427 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3428 MSG_DEBUG("__MmsBinaryDecodeUintvar: fail to load to buffer \n");
3434 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
3437 if (oneByte > 0x7f) {
3438 iBuff[count++] = oneByte;
3440 iBuff[count++] = oneByte;
3445 MSG_DEBUG("__MmsBinaryDecodeUintvar : legnth is too long\n");
3450 for (int i = 0; i < count; i++)
3451 decodedUintvar += (uintvarDecodeTable[i] * (iBuff[count-(i+1)]&0x7f));
3453 *pUintVar = decodedUintvar;
3458 gCurMmsDecodeBuffPos -= count;
3464 * Decode uintvar to 32bit unsigned integer by uintvar length
3466 * @param pEncodedData [in] uintvar encoded data
3467 * @param length [in] length of integer value
3468 * @return unsigned integer value
3470 static UINT32 __MmsHeaderDecodeIntegerByLength(FILE *pFile, UINT32 length, int totalLength)
3480 returner.integer = 0;
3487 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
3488 MSG_DEBUG("__MmsHeaderDecodeIntegerByLength: _MmsBinaryDecodeGetOneByte fail\n");
3492 if (oneByte > 0x7f) {
3493 return (oneByte & 0x7f);
3502 pData = (char *)malloc(length + 1);
3503 if (pData == NULL) {
3504 MSG_DEBUG("__MmsHeaderDecodeIntegerByLength: pData alloc fail\n");
3507 memset(pData, 0, length + 1);
3509 if (_MmsBinaryDecodeGetBytes(pFile, pData, length + 1, totalLength) == false) {
3510 MSG_DEBUG("__MmsHeaderDecodeIntegerByLength: _MmsBinaryDecodeGetOneByte fail\n");
3514 gCurMmsDecodeBuffPos--; // - NULL
3516 for (i= 0; i < length; i++)
3517 returner.seg[length - (i+1)] = pData[i];
3524 return returner.integer;
3533 return returner.integer;
3538 * Decode uintvar to 32bit unsigned integer by uintvar length
3540 * @param pEncodedData [in] uintvar encoded data
3541 * @param pInteger [out] Decode integer value (long/short)
3542 * @return unsigned integer value (-1, if cannot be converted to unsigned integer value)
3544 static bool __MmsBinaryDecodeInteger(FILE *pFile, UINT32 *pInteger, int *pIntLen, int totalLength)
3554 if (pInteger == NULL)
3557 returner.integer = 0;
3560 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
3561 MSG_DEBUG("__MmsBinaryDecodeInteger: GetOneByte fail\n");
3565 if (oneByte < 0x1F) /* long integer : WAP-230-WSP-20010118-p, Proposed Version 18 January 2001 (pp.86) */
3567 pData = (char *)malloc(oneByte + 1);
3568 if (pData == NULL) {
3569 MSG_DEBUG("__MmsBinaryDecodeInteger: pData memalloc fail\n");
3572 memset(pData, 0, oneByte + 1);
3574 // Even NULL is copied in the _MmsBinaryDecodeGetBytes
3575 if (_MmsBinaryDecodeGetBytes(pFile, pData, oneByte + 1, totalLength) == false) {
3576 MSG_DEBUG("__MmsBinaryDecodeInteger: GetBytes fail\n");
3580 gCurMmsDecodeBuffPos--; // - NULL
3590 for (i = 0; i < length; i++)
3591 returner.seg[length - (i+1)] = pData[i];
3593 *pInteger = returner.integer;
3594 *pIntLen = oneByte + 1;
3595 } else if (oneByte >= 0x80) {
3596 /* short integer : WAP-230-WSP-20010118-p, Proposed Version 18 January 2001 (pp.86) */
3597 *pInteger = oneByte & 0x7f;
3612 gCurMmsDecodeBuffPos--;
3624 * Decode uintvar to 32bit unsigned integer by uintvar length
3626 * @return 1 : Success
3627 * 0 : This is not Value Length type data
3628 * -1 : Requires System error report
3630 static int __MmsDecodeValueLength(FILE *pFile, UINT32 *pValueLength, int totalLength)
3638 * value-length = short-length | (Length-quote Length)
3639 * = 0~30 | 31 + Uintvar-length
3642 if (pFile == NULL || pValueLength == NULL)
3647 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
3648 gCurMmsDecodeBuffPos--;
3652 if (0x00 < oneByte && oneByte < 0x1F) {
3655 *pValueLength = oneByte;
3657 } else if (oneByte == 0x1F) {
3658 /* Length-quote = 0x1F */
3660 length = __MmsBinaryDecodeUintvar(pFile, &uintvar, totalLength);
3662 MSG_DEBUG("__MmsDecodeValueLength: __MmsBinaryDecodeUintvar fail..\n");
3665 length ++; // + length-quote
3666 *pValueLength = uintvar;
3668 MSG_DEBUG("__MmsDecodeValueLength: not a value length type data\n");
3669 gCurMmsDecodeBuffPos--;
3676 MSG_DEBUG("__MmsDecodeValueLength: getting data fail\n");
3683 * Decode uintvar to 32bit unsigned integer by uintvar length
3685 * @return 1 : Success
3686 * 0 : This is not Value Length type data
3687 * -1 : Requires System error report
3688 * @ defference : if there is not length-quote, consider it as short length.
3690 static int __MmsDecodeValueLength2(FILE *pFile, UINT32 *pValueLength, int totalLength)
3698 * value-length = short-length | (Length-quote Length)
3699 * = 0~30 | 31 + Uintvar-length
3702 if (pFile == NULL || pValueLength == NULL)
3707 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
3708 gCurMmsDecodeBuffPos--;
3712 if (0x00 < oneByte && oneByte < 0x1F) {
3715 *pValueLength = oneByte;
3717 } else if (oneByte == 0x1F) {
3718 /* Length-quote = 0x1F */
3720 length = __MmsBinaryDecodeUintvar(pFile, &uintvar, totalLength);
3722 MSG_DEBUG("__MmsDecodeValueLength2: __MmsBinaryDecodeUintvar fail..\n");
3725 length ++; // + length-quote
3726 *pValueLength = uintvar;
3728 MSG_DEBUG("__MmsDecodeValueLength2: there is not length-quote, consider it as short length.\n");
3729 *pValueLength = oneByte;
3736 MSG_DEBUG("__MmsDecodeValueLength2: getting data fail\n");
3743 * Decode QuotedString
3745 * @param pEncodedData [in] QuotedString encoded data
3746 * @param szBuff [out] Decoded quoted string
3747 * @param bufLen [out] Buffer length
3748 * @return length of quoted string
3750 static int __MmsBinaryDecodeQuotedString(FILE *pFile, char *szBuff, int bufLen, int totalLength)
3756 int returnLength = 0;
3759 * Quoted-string = <Octet 34> *TEXT End-of-string
3760 * The TEXT encodes an RFC2616 Quoted-string with the enclosing quotation-marks <"> removed
3763 if (pFile == NULL || szBuff == NULL || bufLen <= 0)
3766 memset(szBuff, 0, bufLen);
3768 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3769 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3770 MSG_DEBUG("__MmsBinaryDecodeQuotedString: 1. fail to load to buffer \n");
3774 length = strlen(gpCurMmsDecodeBuff) + 1; // + NULL
3779 while (length > gMmsDecodeBufLen) {
3780 if (gMmsDecodeBufLen <= 0) {
3781 MSG_DEBUG("__MmsBinaryDecodeQuotedString: gMmsDecodeBufLen <= 0 \n");
3782 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
3783 gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
3784 gpCurMmsDecodeBuff[3], gpCurMmsDecodeBuff[4]);
3785 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
3786 gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
3787 gpCurMmsDecodeBuff[8], gpCurMmsDecodeBuff[9]);
3788 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
3789 gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
3790 gpCurMmsDecodeBuff[13], gpCurMmsDecodeBuff[14]);
3791 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
3792 gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
3793 gpCurMmsDecodeBuff[18], gpCurMmsDecodeBuff[19]);
3797 pData = (char *)malloc(gMmsDecodeBufLen + 1);
3801 memset(pData, 0, gMmsDecodeBufLen + 1);
3803 if (_MmsBinaryDecodeGetBytes(pFile, pData, gMmsDecodeBufLen, totalLength) == false)
3806 returnLength += gMmsDecodeBufLen;
3808 if ((bufLen - iPos) > 0) {
3809 readBytes = (gMmsDecodeBufLen < (bufLen - iPos)) ? gMmsDecodeBufLen : (bufLen - iPos);
3810 if (iPos == 0 && (pData[0] == MARK)) {
3811 /* MARK: check first time only */
3813 strncpy(szBuff + iPos, (char*)pData + 1, readBytes - 1);
3814 iPos += (readBytes - 1);
3816 strncpy(szBuff + iPos, (char*)pData, readBytes);
3826 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3827 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3828 MSG_DEBUG("__MmsBinaryDecodeText: 2. fail to load to buffer \n");
3831 length = strlen(gpCurMmsDecodeBuff) + 1; // + NULL
3835 pData = (char *)malloc(length);
3839 if (_MmsBinaryDecodeGetBytes(pFile, pData, length, totalLength) == false)
3842 returnLength += length;
3844 if ((bufLen - iPos) > 0) {
3845 /* read until NULL from raw data, and copy only string */
3846 readBytes = (length < (bufLen - iPos)) ? length : (bufLen - iPos);
3847 if (iPos == 0 && (pData[0] == MARK)) {
3848 /* MARK: check first time only */
3849 strncpy(szBuff + iPos, (char*)pData + 1, readBytes - 1);
3850 iPos += (readBytes - 1);
3852 strncpy(szBuff + iPos, (char*)pData, readBytes - 1); // + NULL
3863 szBuff[bufLen - 1] = '\0';
3865 return returnLength;
3890 * @param pEncodedData [in] QuotedString encoded data
3891 * @param szBuff [out] Decoded quoted string
3892 * @param bufLen [out] Buffer length
3893 * @return length of decode text string
3895 static int __MmsBinaryDecodeText(FILE *pFile, char *szBuff, int bufLen, int totalLength)
3900 int returnLength = 0;
3902 bool bQuote = false;
3906 * Text-String = [QUOTE]*TEXT end_of_string
3907 * [QUOTE]*(128~255)\0
3911 if (pFile == NULL || szBuff == NULL || bufLen <= 0)
3914 offset = _MmsGetDecodeOffset();
3915 if (offset >= totalLength)
3918 memset(szBuff, 0, bufLen);
3920 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3921 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3922 MSG_DEBUG("__MmsBinaryDecodeText: 1. fail to load to buffer \n");
3926 length = strlen(gpCurMmsDecodeBuff) + 1; // + NULL
3931 while (length > gMmsDecodeBufLen) {
3932 if (gMmsDecodeBufLen <= 0) {
3933 MSG_DEBUG("__MmsBinaryDecodeQuotedString: gMmsDecodeBufLen <= 0 \n");
3934 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
3935 gpCurMmsDecodeBuff[3], gpCurMmsDecodeBuff[4]);
3936 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
3937 gpCurMmsDecodeBuff[8], gpCurMmsDecodeBuff[9]);
3938 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
3939 gpCurMmsDecodeBuff[13], gpCurMmsDecodeBuff[14]);
3940 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
3941 gpCurMmsDecodeBuff[18], gpCurMmsDecodeBuff[19]);
3945 pData = (char *)malloc(gMmsDecodeBufLen + 1);
3949 memset(pData, 0, gMmsDecodeBufLen + 1);
3951 if (_MmsBinaryDecodeGetBytes(pFile, pData, gMmsDecodeBufLen, totalLength) == false)
3954 if ((bufLen - iPos) > 0) {
3955 readBytes = (gMmsDecodeBufLen < (bufLen - iPos)) ? gMmsDecodeBufLen : (bufLen - iPos);
3956 if (iPos == 0 && (pData[0] == QUOTE) && (bQuote == false)) {
3957 /* QUOTE: check first time only */
3959 strncpy(szBuff + iPos, (char*)pData + 1, readBytes - 1);
3960 iPos += (readBytes - 1);
3963 strncpy(szBuff + iPos, (char*)pData, readBytes);
3973 returnLength += gMmsDecodeBufLen;
3975 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3976 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3977 MSG_DEBUG("__MmsBinaryDecodeText: 2. fail to load to buffer \n");
3980 length = strlen(gpCurMmsDecodeBuff) + 1; // + NULL
3984 pData = (char *)malloc(length);
3988 memset(pData, 0, length);
3990 if (_MmsBinaryDecodeGetBytes(pFile, pData, length, totalLength) == false)
3993 if ((bufLen - iPos) > 0) {
3994 readBytes = (length < (bufLen - iPos)) ? length : (bufLen - iPos);
3995 if (iPos == 0 && (pData[0] == QUOTE) && (bQuote == false)) {
3996 /* QUOTE: check first time only */
3998 strncpy(szBuff + iPos, (char*)pData + 1, readBytes - 1);
3999 iPos += (readBytes - 1);
4002 strncpy(szBuff + iPos, (char*)pData, readBytes - 1); // + NULL
4012 returnLength += length; // + NULL
4015 szBuff[bufLen - 1] = '\0';
4017 return returnLength;
4029 MmsBinaryDecodeMovePointer(pFile, offset, totalLength);
4044 static char* __MmsBinaryDecodeText2(FILE *pFile, int totalLength, int *pLength)
4049 char *szBuff = NULL;
4050 char *szTempPtr = NULL;
4051 bool bQuote = false;
4055 * Text-String = [QUOTE]*TEXT end_of_string
4056 * [QUOTE]*(128~255)\0
4060 if (pFile == NULL || pLength == NULL)
4064 offset = _MmsGetDecodeOffset();
4065 if (offset >= totalLength)
4068 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
4069 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
4070 MSG_DEBUG("__MmsBinaryDecodeTextLen: 1. fail to load to buffer \n");
4074 length = strlen(gpCurMmsDecodeBuff) + 1;
4079 while (length > gMmsDecodeBufLen) {
4080 if (gMmsDecodeBufLen <= 0) {
4081 MSG_DEBUG("__MmsBinaryDecodeQuotedString: gMmsDecodeBufLen <= 0 \n");
4082 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
4083 gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
4084 gpCurMmsDecodeBuff[3], gpCurMmsDecodeBuff[4]);
4085 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
4086 gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
4087 gpCurMmsDecodeBuff[8], gpCurMmsDecodeBuff[9]);
4088 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
4089 gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
4090 gpCurMmsDecodeBuff[13], gpCurMmsDecodeBuff[14]);
4091 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
4092 gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
4093 gpCurMmsDecodeBuff[18], gpCurMmsDecodeBuff[19]);
4097 pData = (char *)malloc(gMmsDecodeBufLen + 1);
4101 memset(pData, 0, gMmsDecodeBufLen + 1);
4103 if (_MmsBinaryDecodeGetBytes(pFile, pData, gMmsDecodeBufLen, totalLength) == false)
4106 if (szBuff == NULL) {
4107 szBuff = (char *)malloc(gMmsDecodeBufLen + 1);
4109 szTempPtr = (char *)realloc(szBuff, curLen + gMmsDecodeBufLen + 1);
4111 //NULL pointer check for realloc
4112 if (szTempPtr == NULL) {
4121 memset(szBuff + curLen, 0, gMmsDecodeBufLen + 1);
4123 if (curLen == 0 && (pData[0] == QUOTE) && (bQuote == false)) {
4124 /* QUOTE: check first time only */
4126 strncpy(szBuff + curLen, (char*)pData + 1, gMmsDecodeBufLen - 1);
4127 curLen += (gMmsDecodeBufLen - 1);
4130 strncpy(szBuff + curLen, (char*)pData, gMmsDecodeBufLen);
4131 curLen += gMmsDecodeBufLen;
4139 *pLength += gMmsDecodeBufLen;
4141 if (MsgLoadDataToDecodeBuffer(pFile,
4142 &gpCurMmsDecodeBuff,
4143 &gCurMmsDecodeBuffPos,
4144 &gMmsDecodeCurOffset,
4149 totalLength) == false)
4151 MSG_DEBUG("__MmsBinaryDecodeText: 2. fail to load to buffer \n");
4154 length = strlen(gpCurMmsDecodeBuff) + 1;
4158 pData = (char *)malloc(length);
4159 if (pData == NULL) {
4163 if (_MmsBinaryDecodeGetBytes(pFile, pData, length, totalLength) == false) {
4167 if (szBuff == NULL) {
4168 szBuff = (char *)malloc(length);
4170 szTempPtr = (char *)realloc(szBuff, curLen + length);
4172 //NULL pointer check for realloc
4173 if (szTempPtr == NULL)
4179 if (szBuff == NULL) {
4183 memset(szBuff + curLen, 0, length);
4185 if (curLen == 0 && (pData[0] == QUOTE) && (bQuote == false)) {
4186 /* QUOTE: check first time only */
4188 strncpy(szBuff + curLen, (char*)pData + 1, length - 2);
4189 curLen += (length - 1);
4192 strncpy(szBuff + curLen, (char*)pData, length - 1);
4201 *pLength += length; // + NULL
4214 MmsBinaryDecodeMovePointer(pFile, offset, totalLength);
4237 * @param pEncodedData [in] QuotedString encoded data
4238 * @param nCharSet [out] Decoded character set
4239 * @return length of charset value
4241 static bool __MmsBinaryDecodeCharset(FILE *pFile, UINT32 *nCharSet, int *pCharSetLen, int totalLength)
4246 * Charset v1.1 0x01 Well-known-charset
4247 * Well-known-charset = Any-charset | Integer-value
4248 * ; Both are encoded using values from
4249 * Character Set Assignments table in Assigned Numbers
4250 * Any-charset = <Octet 128>
4251 * ; Equivalent to the special RFC2616 charset value ¡°*¡±
4254 if (pFile == NULL || nCharSet == NULL || pCharSetLen == NULL)
4257 if (__MmsBinaryDecodeInteger(pFile, &integer, pCharSetLen, totalLength) == false) {
4258 MSG_DEBUG("__MmsBinaryDecodeCharset : __MmsBinaryDecodeInteger fail...\n");
4263 /* AnyCharSet : return MSG_CHARSET_UTF8 */
4264 *nCharSet = MSG_CHARSET_UTF8;
4268 *nCharSet = _MmsGetBinaryType(MmsCodeCharSet, (UINT16)integer);
4270 if (*nCharSet == MIME_UNKNOWN) {
4271 MSG_DEBUG("__MmsBinaryDecodeCharset : _MmsGetBinaryType fail..\n");
4272 *nCharSet = MSG_CHARSET_UNKNOWN;
4284 * Decode EncodedString
4286 * @param pEncodedData [in] QuotedString encoded data
4287 * @param szBuff [out] Decoded string buffer
4288 * @param bufLen [in] Decoded buffer length
4289 * @return length of decoded string length
4291 static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen, int totalLength)
4293 UINT32 valueLength = 0;
4301 char *pTempData = NULL;
4302 unsigned short *mszTempStr = NULL;
4303 char *pConvertedStr = NULL;
4304 char *pNewData = NULL;
4307 MSG_DEBUG("__MmsBinaryDecodeEncodedString: decode string..\n");
4309 if (pFile == NULL || szBuff == NULL || bufLen <= 0) {
4310 MSG_DEBUG("__MmsBinaryDecodeEncodedString: invalid file or buffer\n");
4315 * Encoded_string_value = Text-string | Value-length Char-set Text-String
4316 * Text-string = [Quote]*TEXT End-of-string
4317 * Value-length = 0 ~ 31
4320 memset(szBuff, 0, bufLen);
4322 switch (__MmsDecodeValueLength(pFile, &valueLength, totalLength)) {
4328 /* Text-string = [Quote]*TEXT End-of-string */
4330 if (__MmsBinaryDecodeText(pFile, szBuff, bufLen, totalLength) < 0) {
4331 MSG_DEBUG("__MmsBinaryDecodeEncodedString : 1. __MmsBinaryDecodeText fail.\n");
4338 /* Value-length Charset Text_string */
4340 if (__MmsBinaryDecodeCharset(pFile, &charSet, &charSetLen, totalLength) == false) {
4341 MSG_DEBUG("__MmsBinaryDecodeEncodedString : __MmsBinaryDecodeCharset error\n");
4342 goto __CATCH; /* (valueLength + valueLengthLen) */
4345 nTemp = __MmsBinaryDecodeText(pFile, szBuff, bufLen, totalLength);
4347 /* There can be some error in data - no NULL -> try again with value length */
4349 pData = (char *)malloc(valueLength - charSetLen);
4350 if (pData == NULL) {
4351 MSG_DEBUG("__MmsBinaryDecodeEncodedString : pData alloc fail.\n");
4355 if (_MmsBinaryDecodeGetLongBytes(pFile, pData, valueLength - charSetLen, totalLength) == false) {
4356 MSG_DEBUG("__MmsBinaryDecodeEncodedString : _MmsBinaryDecodeGetLongBytes fail.\n");
4360 strncpy(szBuff, pData, bufLen - 1);
4364 /* fixme: charset transformation */
4366 case MSG_CHARSET_UTF16:
4367 case MSG_CHARSET_USC2:
4369 MSG_DEBUG("__MmsBinaryDecodeEncodedString: MSG_CHARSET_USC2 \n");
4371 nTemp = strlen(szBuff);
4372 pTempData = (char *)malloc(nTemp + 1);
4373 if (pTempData == NULL) {
4374 MSG_DEBUG("__MmsBinaryDecodeEncodedString: Memory Full \n");
4378 memset(pTempData, 0, nTemp + 1);
4379 memcpy(pTempData, szBuff, nTemp + 1);
4381 if (((UINT8)pTempData[0]) == 0xFF && ((UINT8)pTempData[1]) == 0xFE) {
4382 if ((nChar = (nTemp / 2 - 1)) <= 0) {
4383 MSG_DEBUG("__MmsBinaryDecodeEncodedString(%d) : nChar is invalid value (%d), charset(%d)\n", __LINE__, nChar, charSet);
4387 mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
4388 if (mszTempStr == NULL) {
4389 MSG_DEBUG("MmsGetMediaPartData : 1. Memory Full !!! \n");
4393 memcpy(mszTempStr, ((unsigned short*)pTempData + 1), nChar * sizeof(unsigned short));
4395 nByte = MsgGetUnicode2UTFCodeSize(((unsigned short*)pTempData + 1), nChar);
4397 pConvertedStr = (char *)malloc(nByte + 1);
4399 MsgUnicode2UTF ((unsigned char*)pConvertedStr, nByte + 1, mszTempStr, nChar);
4401 if ((nChar = (nTemp / 2)) <= 0) {
4402 MSG_DEBUG("__MmsBinaryDecodeEncodedString(%d) : nChar is invalid value (%d), charset(%d)\n", __LINE__, nChar, charSet);
4406 mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
4407 if (mszTempStr == NULL) {
4408 MSG_DEBUG("__MmsBinaryDecodeEncodedString: 2. Memory Full !!! \n");
4412 memcpy(mszTempStr, ((unsigned short*)pTempData), nChar * sizeof(unsigned short));
4414 nByte = MsgGetUnicode2UTFCodeSize(((unsigned short*)pTempData), nChar);
4416 pConvertedStr = (char *)malloc(nByte + 1);
4417 if (pConvertedStr != NULL)
4418 MsgUnicode2UTF ((unsigned char*)pConvertedStr, nByte + 1, mszTempStr, nChar);
4421 if (pConvertedStr != NULL) {
4422 pNewData = pConvertedStr;
4425 strncpy(szBuff, pNewData, bufLen - 1);
4430 case MSG_CHARSET_US_ASCII:
4432 MSG_DEBUG("__MmsBinaryDecodeEncodedString: MSG_CHARSET_US_ASCII \n");
4434 case MSG_CHARSET_UTF8:
4436 MSG_DEBUG("__MmsBinaryDecodeEncodedString: MSG_CHARSET_UTF8 or Others \n");
4438 pNewData = pTempData;
4443 case MSG_CHARSET_ISO_8859_7: /* Greek */
4445 MSG_DEBUG("__MmsBinaryDecodeEncodedString: MSG_CHARSET_ISO_8859_7 \n");
4447 nTemp = strlen(szBuff);
4448 pTempData = (char *)malloc(nTemp + 1);
4449 if (pTempData == NULL)
4451 MSG_DEBUG("__MmsBinaryDecodeEncodedString: Memory Full \n");
4455 memset(pTempData, 0 , nTemp + 1);
4456 memcpy(pTempData, szBuff, nTemp + 1);
4458 nByte = MsgGetLatin72UTFCodeSize((unsigned char*)pTempData, nTemp);
4459 pConvertedStr = (char *)malloc(nByte + 1);
4461 if (pConvertedStr != NULL) {
4462 MsgLatin7code2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTempData, nTemp);
4464 pNewData = pConvertedStr;
4467 strncpy(szBuff, pNewData, bufLen - 1);
4472 case MSG_CHARSET_ISO_8859_9: /* Turkish */
4474 MSG_DEBUG("__MmsBinaryDecodeEncodedString: MSG_CHARSET_ISO_8859_9 \n");
4476 nTemp = strlen(szBuff);
4477 pTempData = (char *)malloc(nTemp + 1);
4478 if (pTempData == NULL) {
4479 MSG_DEBUG("__MmsBinaryDecodeEncodedString: Memory Full \n");
4483 memset(pTempData, 0 , nTemp + 1);
4484 memcpy(pTempData, szBuff, nTemp + 1);
4486 nByte = MsgGetLatin52UTFCodeSize((unsigned char*)pTempData, nTemp);
4487 pConvertedStr = (char *)malloc(nByte + 1);
4489 if (pConvertedStr != NULL) {
4490 MsgLatin5code2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTempData, nTemp);
4492 pNewData = pConvertedStr;
4495 strncpy(szBuff, pNewData, bufLen - 1);
4502 MSG_DEBUG("__MmsBinaryDecodeEncodedString: Other charsets \n");
4504 nTemp = strlen(szBuff);
4505 pTempData = (char *)malloc(nTemp + 1);
4506 if (pTempData == NULL) {
4507 MSG_DEBUG("__MmsBinaryDecodeEncodedString: Memory Full \n");
4511 memset(pTempData, 0, nTemp + 1);
4512 memcpy(pTempData, szBuff, nTemp + 1);
4514 nByte = MsgGetLatin2UTFCodeSize((unsigned char*)pTempData, nTemp);
4515 pConvertedStr = (char *)malloc(nByte + 1);
4517 if (pConvertedStr != NULL) {
4518 MsgLatin2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTempData, nTemp);
4520 pNewData = pConvertedStr;
4523 strncpy(szBuff, pNewData, bufLen - 1);
4528 } //switch (charset)
4530 } //switch (__MmsDecodeValueLength....)
4547 if (pConvertedStr) {
4548 free(pConvertedStr);
4549 pConvertedStr = NULL;
4572 if (pConvertedStr) {
4573 free(pConvertedStr);
4574 pConvertedStr = NULL;
4583 * Decode Encoded Addresses
4585 * @param pEncodedData [in] QuotedString encoded data
4586 * @param pAddrLength [out] Decoded address length
4587 * @return Decoded address list
4589 MsgHeaderAddress *__MmsDecodeEncodedAddress(FILE *pFile, int totalLength)
4591 UINT32 valueLength = 0;
4595 char *pAddrStr = NULL;
4596 MsgHeaderAddress *pAddr = NULL;
4598 MSG_DEBUG("__MmsDecodeEncodedAddress: decoding address..\n");
4600 if (pFile == NULL) {
4601 MSG_DEBUG("__MmsDecodeEncodedAddress: invalid file or buffer\n");
4606 * Encoded_string_value = Text-string | Value-length Char-set Text-String
4607 * Text-string = [Quote]*TEXT End-of-string
4608 * Value-length = 0 ~ 31
4611 switch (__MmsDecodeValueLength(pFile, &valueLength, totalLength)) {
4617 /* Text-string = [Quote]*TEXT End-of-string */
4620 pAddrStr = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
4621 if (pAddrStr == NULL) {
4622 MSG_DEBUG("__MmsDecodeEncodedAddress : 1. __MmsBinaryDecodeText2 fail.\n");
4629 /* Value-length Charset Text_string */
4631 if (__MmsBinaryDecodeCharset(pFile, &charSet, &charSetLen, totalLength) == false) {
4632 MSG_DEBUG("__MmsDecodeEncodedAddress : __MmsBinaryDecodeCharset error\n");
4637 pAddrStr = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
4638 if (pAddrStr == NULL) {
4639 /* There can be some error in data - no NULL -> try again with value length */
4641 pAddrStr = (char *)malloc(valueLength - charSetLen);
4642 if (pAddrStr == NULL) {
4643 MSG_DEBUG("__MmsDecodeEncodedAddress : pData alloc fail.\n");
4647 if (_MmsBinaryDecodeGetLongBytes(pFile, pAddrStr, valueLength - charSetLen, totalLength) == false) {
4648 MSG_DEBUG("__MmsDecodeEncodedAddress : _MmsBinaryDecodeGetLongBytes fail.\n");
4653 /* fixme: charset transformation */
4658 pAddr = (MsgHeaderAddress *)malloc(sizeof(MsgHeaderAddress));
4662 memset(pAddr, 0, sizeof(MsgHeaderAddress));
4663 pAddr->szAddr = pAddrStr;
4679 * Decode Encoded Pointer String
4681 * @param pEncodedData [in] Long integer encoded data
4682 * @param pLongInteger [out] Decoded long integer
4683 * @return Decoded address list
4685 static bool __MmsDecodeLongInteger(FILE *pFile, UINT32 *pLongInteger, int totalLength)
4690 * Long-integer = Short-length Multi-octet-integer
4691 * Short-length = 0~30
4692 * Multi-octet-integer
4695 if (pFile == NULL || pLongInteger == NULL)
4700 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
4706 *pLongInteger = __MmsHeaderDecodeIntegerByLength(pFile, oneByte, totalLength);
4716 * @param pEncodedData [in] filename encoded data
4717 * @param szBuff [out] filename output buffer
4718 * @param fullLength [in] full filename length
4719 * @param bufLen [in] buffer length
4720 * CAUTION: bufLen - 1
4722 static int __MmsDecodeGetFilename(FILE *pFile, char *szBuff, int bufLen, int totalLength)
4724 char *pUTF8Buff = NULL;
4725 char *pLatinBuff = NULL;
4728 char *szSrc2 = NULL;
4732 char *pTmpBuff = NULL;
4734 memset (szBuff, 0, bufLen);
4737 pLatinBuff = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
4741 szSrc = MsgRemoveQuoteFromFilename(pLatinBuff);
4743 strcpy(pLatinBuff, szSrc);
4748 szSrc2 = MsgChangeHexString(pLatinBuff);
4750 strcpy(pLatinBuff, szSrc2);
4755 if (MsgIsUTF8String((unsigned char*)pLatinBuff, strlen(pLatinBuff)) == false) {
4756 length = strlen(pLatinBuff);
4758 int utf8BufSize = 0;
4759 utf8BufSize = MsgGetLatin2UTFCodeSize((unsigned char*)pLatinBuff, length);
4760 pUTF8Buff = (char *)malloc(utf8BufSize + 1);
4761 if (pUTF8Buff == NULL) {
4762 MSG_DEBUG("__MmsDecodeGetFilename: pUTF8Buff alloc fail \n");
4766 if (MsgLatin2UTF ((unsigned char*)pUTF8Buff, utf8BufSize + 1, (unsigned char*)pLatinBuff, length) < 0) {
4767 MSG_DEBUG("__MmsDecodeGetFilename: MsgLatin2UTF fail \n");
4773 pTmpBuff = _MsgDecodeText(pLatinBuff);
4774 pUTF8Buff = pTmpBuff;
4783 * it should be kept extention even if the file name is shorten
4786 length = strlen(pUTF8Buff);
4787 if ((pExt = strrchr(pUTF8Buff, '.')) != NULL) {
4789 nameLength = (length < bufLen) ? (length - strlen(pExt)) : (bufLen - strlen(pExt));
4790 strncpy(szBuff, pUTF8Buff, nameLength);
4791 strcat (szBuff, pExt);
4793 strncpy(szBuff, pUTF8Buff, bufLen - 1);
4817 /* ==========================================================
4819 T E X T D E C O D I N G
4821 ==========================================================*/
4824 bool MmsTextDecodeMsgBody(FILE *pFile)
4826 MSG_DEBUG("MmsTextDecodeMsgBody: \n");
4830 bool __MmsTextDecodeMsgHeader(FILE *pFile)
4836 /* ==========================================================
4838 M M S D E C O D I N G
4840 ==========================================================*/
4842 // to get message body this function should be modified from message raw file.
4843 bool _MmsReadMsgBody(MSG_MESSAGE_ID_T msgID, bool bSavePartsAsTempFiles, bool bRetrieved, char *retrievedPath)
4846 MmsMsg *pMsg = NULL;
4847 MsgMultipart *pMultipart = NULL;
4849 char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, };
4850 char szTempMediaDir[MSG_FILEPATH_LEN_MAX] = {0, };
4851 int attachmax = MSG_ATTACH_MAX;
4853 MSG_DEBUG("_MmsReadMsgBody: start read msg(msgID=%d)\n", msgID);
4855 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
4856 memset(pMsg, 0, sizeof(MmsMsg));
4860 if (bRetrieved && (retrievedPath != NULL)) {
4861 strncpy(szFullPath, retrievedPath, (strlen(retrievedPath) > MSG_FILEPATH_LEN_MAX ? MSG_FILEPATH_LEN_MAX:strlen(retrievedPath)));
4863 MmsPluginStorage::instance()->getMmsRawFilePath(msgID, szFullPath);
4866 pMsg->msgID = msgID;
4868 /* read from MMS raw file */
4869 if (szFullPath != NULL)
4870 strncpy(pMsg->szFileName, szFullPath + strlen(MSG_DATA_PATH), strlen(szFullPath + strlen(MSG_DATA_PATH)));
4872 MSG_DEBUG("szFullPath = (%s)", szFullPath);
4874 if (MsgGetFileSize(szFullPath, &nSize) == false) {
4875 MSG_DEBUG("MsgGetFileSize: failed");
4879 pFile = MsgOpenFile(szFullPath, "rb");
4881 if (pFile == NULL) {
4882 MSG_DEBUG("_MmsReadMsgBody: invalid mailbox\n");
4886 _MmsRegisterDecodeBuffer(gszMmsLoadBuf1, gszMmsLoadBuf2, MSG_MMS_DECODE_BUFFER_MAX);
4888 if (MmsBinaryDecodeMsgHeader(pFile, nSize) == false) {
4889 MSG_DEBUG("_MmsReadMsgBody: MmsBinaryDecodeMsgHeader fail...\n");
4893 #ifdef __SUPPORT_DRM__
4894 if (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_FINISH)
4895 MmsDrm2SetConvertState(MMS_DRM2_CONVERT_NONE); //initialize convertState
4898 if (MmsBinaryDecodeMsgBody(pFile, szFullPath, nSize) == false) {
4899 MSG_DEBUG("_MmsReadMsgBody: MmsBinaryDecodeMsgBody fail\n");
4903 #ifdef __SUPPORT_DRM__
4904 if (MmsDrm2GetConvertState() == MMS_DRM2_CONVERT_REQUIRED) {
4905 MSG_DEBUG("_MmsReadMsgBody: MmsDrm2GetConvertState returns MMS_DRM2_CONVERT_REQUIRED.\n");
4910 /* Set mmsHeader.msgType & msgBody to pMsg ----------- */
4912 pMsg->mmsAttrib.contentType = (MsgContentType)mmsHeader.msgType.type;
4914 memcpy(&(pMsg->msgType), &(mmsHeader.msgType), sizeof(MsgType));
4915 memcpy(&(pMsg->msgBody), &(mmsHeader.msgBody), sizeof(MsgBody));
4917 if (pMsg->msgBody.pPresentationBody) {
4918 if(MsgFseek(pFile, pMsg->msgBody.pPresentationBody->offset, SEEK_SET) < 0)
4921 pMsg->msgBody.pPresentationBody->body.pText = (char *)malloc(pMsg->msgBody.pPresentationBody->size + 1);
4922 if (pMsg->msgBody.pPresentationBody->body.pText == NULL)
4925 memset(pMsg->msgBody.pPresentationBody->body.pText, 0, pMsg->msgBody.pPresentationBody->size + 1);
4928 nRead = MsgReadFile(pMsg->msgBody.pPresentationBody->body.pText, sizeof(char), pMsg->msgBody.pPresentationBody->size, pFile);
4934 MsgCloseFile(pFile);
4938 pMsg->nPartCount = 0;
4940 if (MsgIsMultipart(mmsHeader.msgType.type) == true) {
4941 pMultipart = pMsg->msgBody.body.pMultipart;
4942 while (pMultipart) {
4945 if (pMultipart->type.type == MIME_TEXT_PLAIN)
4948 if ((mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED)||(mmsHeader.msgType.type == MIME_MULTIPART_MIXED)) {
4949 if ((pMsg->nPartCount >= attachmax)&&(pMultipart->pNext != NULL)) {
4950 _MsgFreeBody(pMultipart->pNext->pBody, pMultipart->pNext->type.type);
4952 free(pMultipart->pNext->pBody);
4953 pMultipart->pNext->pBody= NULL;
4955 free(pMultipart->pNext);
4957 pMultipart->pNext = NULL;
4961 pMultipart = pMultipart->pNext;
4964 if (pMsg->msgBody.size > 0)
4968 /* make temporary */
4969 snprintf(szTempMediaDir, MSG_FILEPATH_LEN_MAX, MSG_DATA_PATH"%s.dir", pMsg->szFileName);
4971 ///////////////////////////////////////////////
4972 // call before processing urgent event.
4974 //_MmsUnregisterDecodeBuffer();
4975 ///////////////////////////////////////////////
4977 if (MsgIsMultipart(pMsg->msgType.type) == true) {
4979 pMultipart = pMsg->msgBody.body.pMultipart;
4981 if (bSavePartsAsTempFiles) {
4982 if (mkdir(szTempMediaDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
4983 if (errno == EEXIST) {
4984 MSG_DEBUG("The %s already exists", szTempMediaDir);
4986 MSG_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
4992 while (pMultipart) {
4994 if (_MmsMultipartSaveAsTempFile(&pMultipart->type, pMultipart->pBody,
4995 (char*)MSG_DATA_PATH, pMsg->szFileName, partIndex, bSavePartsAsTempFiles) == false)
4998 pMultipart = pMultipart->pNext;
5002 } else { //single part
5003 if (pMsg->nPartCount > 0) {
5005 if (bSavePartsAsTempFiles) {
5006 if (mkdir(szTempMediaDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
5007 if (errno == EEXIST) {
5008 MSG_DEBUG("The %s already exists", szTempMediaDir);
5010 MSG_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
5016 if (_MmsMultipartSaveAsTempFile( &pMsg->msgType, &pMsg->msgBody,
5017 (char*)MSG_DATA_PATH, pMsg->szFileName, 0, bSavePartsAsTempFiles) == false)
5021 MSG_DEBUG("**** _MmsReadMsgBody: E N D (Success) ***\n");
5024 #ifdef __SUPPORT_DRM__
5028 if (pFile != NULL) {
5029 MsgCloseFile(pFile);
5040 _MmsUnregisterDecodeBuffer();
5042 if (pFile != NULL) {
5043 MsgCloseFile(pFile);
5047 #ifdef __SUPPORT_DRM__
5048 _MsgFreeDRMInfo(&pMsg->msgType.drmInfo);
5051 _MsgFreeBody(&pMsg->msgBody, pMsg->msgType.type);
5052 MSG_DEBUG("_MmsReadMsgBody: E N D (fail) ******************** \n");
5058 bool MsgFreeHeaderAddress(MsgHeaderAddress *pAddr)
5060 MsgHeaderAddress *pTempAddr = NULL;
5062 while (pAddr != NULL) {
5064 pAddr = pAddr->pNext;
5066 if (pTempAddr->szAddr) {
5067 free(pTempAddr->szAddr);
5068 pTempAddr->szAddr = NULL;
5078 bool MsgCheckFileNameHasInvalidChar(char *szName)
5083 strLen = strlen(szName);
5085 for (i=0; i<strLen; i++) {
5086 if (__MsgIsInvalidFileNameChar(szName[i]))
5093 bool _MsgReplaceInvalidFileNameChar(char *szInText, char replaceChar)
5096 int totalLength = 0;
5098 totalLength = strlen(szInText);
5100 while ((*(szInText+nCount) != '\0') && (nCount < totalLength)) {
5101 if (0x0001 <= *(szInText+nCount) && *(szInText+nCount) <= 0x007F) {
5102 if (__MsgIsInvalidFileNameChar(szInText[nCount]))
5103 *(szInText+nCount) = replaceChar;
5114 char *_MsgGetStringUntilDelimiter(char *pszString, char delimiter)
5116 char *pszBuffer = NULL;
5117 char *pszStrDelimiter = NULL;
5121 MSG_DEBUG("_MsgGetStringUntilDelimiter: pszString == NULL \n");
5125 if ((pszStrDelimiter = strchr(pszString, delimiter)) == NULL) {
5126 MSG_DEBUG("_MsgGetStringUntilDelimiter: There is no %c in %s. \n", delimiter, pszString);
5130 bufLength = pszStrDelimiter - pszString;
5132 if ((pszBuffer = (char*)malloc (bufLength + 1)) == NULL) {
5133 MSG_DEBUG("malloc is failed");
5136 memset(pszBuffer, 0, bufLength + 1) ;
5138 strncat(pszBuffer, pszString, bufLength);
5143 char *MsgChangeHexString(char *pOrg)
5146 char szBuf[10] = {0,};
5155 cLen = strlen(pOrg);
5157 pNew = (char *)malloc(cLen + 1);
5161 memset(pNew, 0, cLen + 1);
5163 for (cIndex = 0; cIndex< cLen ; cIndex++) {
5164 if (pOrg[cIndex] == '%') {
5165 if (pOrg[cIndex+1] != 0 && pOrg[cIndex+2] != 0) {
5166 snprintf(szBuf, sizeof(szBuf), "%c%c", pOrg[cIndex+1], pOrg[cIndex+2]); // read two chars after '%'
5168 if (MsgIsHexChar(szBuf) == true) { // check the two character is between 0 ~ F
5169 OneChar = _MsgConvertHexValue(szBuf);
5171 pNew[index] = OneChar;
5178 pNew[index++] = pOrg[cIndex];
5183 bool _MsgParseParameter(MsgType *pType, char *pSrc)
5186 char *pValue = NULL;
5189 char *pNextParam = NULL;
5193 char *pTempNextParam = NULL;
5196 char *pUTF8Buff = NULL;
5198 while (pSrc != NULL) {
5199 pSrc = _MsgSkipWS(pSrc);
5201 /* End of parse parameter */
5206 pTempNextParam = strchr(pSrc, MSG_CH_SEMICOLON);
5209 if (*pCh == MSG_CH_QUOT) {
5216 for (; pCh<=pTempNextParam ; pCh++) {
5217 if (*pCh == MSG_CH_QUOT)
5218 if (*(pCh - 1) != '\\')
5223 pNextParam = pTempNextParam;
5226 *pNextParam++ = MSG_CH_NULL;
5228 if ((pName = strchr(pSrc, MSG_CH_EQUAL)) != NULL) {
5229 *pName++ = MSG_CH_NULL;
5231 if ((pValue = strchr(pName, MSG_CH_QUOT))!= NULL) {
5232 *pValue++ = MSG_CH_NULL;
5234 if ((pTest = strchr(pValue, MSG_CH_QUOT)) != NULL)
5235 *pTest = MSG_CH_NULL;
5237 pDec = _MsgDecodeText(pValue); // Api is to long, consider Add to another file (MsgMIMECodec.c)
5239 pDec = _MsgDecodeText(pName);
5242 switch (_MsgGetCode(MSG_PARAM, pSrc)) {
5243 case MSG_PARAM_BOUNDARY:
5245 /* RFC 822: boundary := 0*69<bchars> bcharsnospace */
5247 memset (pType->param.szBoundary, 0, MSG_BOUNDARY_LEN + 1);
5248 strncpy(pType->param.szBoundary, pDec, MSG_BOUNDARY_LEN);
5249 MSG_DEBUG("_MsgParseParameter: szBoundary = %s \n", pType->param.szBoundary);
5252 case MSG_PARAM_CHARSET:
5253 pType->param.charset = _MsgGetCode(MSG_CHARSET, pDec);
5255 if (pType->param.charset == INVALID_HOBJ)
5256 pType->param.charset = MSG_CHARSET_UNKNOWN;
5258 MSG_DEBUG("_MsgParseParameter: type = %d [charset] = %d \n", pType->type, pType->param.charset);
5261 case MSG_PARAM_NAME:
5263 memset (pType->param.szName, 0, MSG_LOCALE_FILENAME_LEN_MAX + 1);
5265 pUTF8Buff = MsgConvertLatin2UTF8FileName(pDec);
5268 if ((pExt = strrchr(pUTF8Buff, '.')) != NULL) {
5269 if ((MSG_FILENAME_LEN_MAX-1) < strlen(pUTF8Buff)) {
5270 nameLen = (MSG_FILENAME_LEN_MAX-1) - strlen(pExt);
5272 nameLen = strlen(pUTF8Buff) - strlen(pExt);
5275 strncpy(pType->param.szName, pUTF8Buff, nameLen);
5276 strcat (pType->param.szName, pExt);
5278 strncpy(pType->param.szName, pUTF8Buff, (MSG_FILENAME_LEN_MAX-1));
5283 if (_MsgChangeSpace(pType->param.szName, &szSrc) == true) {
5285 strncpy(pType->param.szName, szSrc , strlen(szSrc));
5293 // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
5294 _MsgRemoveFilePath(pType->param.szName);
5296 MSG_DEBUG("_MsgParseParameter: MsgConvertLatin2UTF8FileName(%s) return NULL\n", pDec);
5299 MSG_DEBUG("_MsgParseParameter: szName = %s \n", pType->param.szName);
5302 case MSG_PARAM_FILENAME:
5304 memset (pType->param.szFileName, 0, MSG_FILENAME_LEN_MAX+1);
5306 pUTF8Buff = MsgConvertLatin2UTF8FileName(pDec);
5309 if ((pExt = strrchr(pUTF8Buff, '.')) != NULL) {
5310 if ((MSG_FILENAME_LEN_MAX-1) < strlen(pUTF8Buff)) {
5311 nameLen = (MSG_FILENAME_LEN_MAX-1) - strlen(pExt);
5313 nameLen = strlen(pUTF8Buff) - strlen(pExt);
5316 strncpy(pType->param.szFileName, pUTF8Buff, nameLen);
5317 strcat (pType->param.szFileName, pExt);
5319 strncpy(pType->param.szFileName, pUTF8Buff, (MSG_FILENAME_LEN_MAX-1));
5324 if (_MsgChangeSpace(pType->param.szFileName, &szSrc) == true)
5325 strcpy(pType->param.szFileName, szSrc);
5332 // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
5333 _MsgRemoveFilePath(pType->param.szFileName);
5335 MSG_DEBUG("_MsgParseParameter: MsgConvertLatin2UTF8FileName(%s) return NULL\n", pDec);
5338 MSG_DEBUG("_MsgParseParameter: szFileName = %s \n", pType->param.szFileName);
5342 case MSG_PARAM_TYPE:
5344 /* type/subtype of root. Only if content-type is multipart/related */
5346 pType->param.type = _MsgGetCode(MSG_TYPE, pDec);
5347 MSG_DEBUG("_MsgParseParameter: type = %d \n", pType->param.type);
5351 case MSG_PARAM_START:
5353 /* Content-id. Only if content-type is multipart/related */
5355 memset (pType->param.szStart, 0, MSG_MSG_ID_LEN + 1);
5356 strncpy(pType->param.szStart, pDec, MSG_MSG_ID_LEN);
5358 MSG_DEBUG("_MsgParseParameter: szStart = %s \n", pType->param.szStart);
5362 case MSG_PARAM_START_INFO :
5364 /* Only if content-type is multipart/related */
5366 memset (pType->param.szStartInfo, 0, MSG_MSG_ID_LEN + 1);
5367 strncpy(pType->param.szStartInfo, pDec, MSG_MSG_ID_LEN);
5369 MSG_DEBUG("_MsgParseParameter: szStartInfo = %s \n", pType->param.szStartInfo);
5373 case MSG_PARAM_REPORT_TYPE :
5375 // only used as parameter of Content-Type: multipart/report; report-type=delivery-status;
5377 if (pDec != NULL && strcasecmp(pDec, "delivery-status") == 0) {
5378 pType->param.reportType = MSG_PARAM_REPORT_TYPE_DELIVERY_STATUS;
5380 pType->param.reportType = MSG_PARAM_REPORT_TYPE_UNKNOWN;
5383 MSG_DEBUG("_MsgParseParameter: reportType = %s \n", pDec);
5388 MSG_DEBUG("_MsgParseParameter: Unknown paremeter (%s)\n", pDec);
5402 char *_MsgSkipWS(char *s)
5405 if ((*s == MSG_CH_CR) || (*s == MSG_CH_LF) || (*s == MSG_CH_SP) || (*s == MSG_CH_TAB)) {
5407 } else if ((*s != '(') || (__MsgSkipComment(s,(long)NULL)==NULL)) {
5413 char *__MsgSkipComment (char *s,long trim)
5420 // ignore empty space
5421 for (ret = ++s1; *ret == ' '; ret++)
5424 // handle '(', ')', '\', '\0'
5428 if (!__MsgSkipComment (s1,(long)NULL))
5459 char *MsgConvertLatin2UTF8FileName(char *pSrc)
5461 char *pUTF8Buff = NULL;
5465 //convert utf8 string
5466 if (MsgIsUTF8String((unsigned char*)pSrc, strlen(pSrc)) == false) {
5468 int utf8BufSize = 0;
5470 length = strlen(pSrc);
5471 utf8BufSize = MsgGetLatin2UTFCodeSize((unsigned char*)pSrc, length);
5472 pUTF8Buff = (char *)malloc(utf8BufSize + 1);
5474 if (pUTF8Buff == NULL) {
5475 MSG_DEBUG("MsgConvertLatin2UTF8FileName: pUTF8Buff alloc fail \n");
5479 if (MsgLatin2UTF ((unsigned char*)pUTF8Buff, utf8BufSize + 1, (unsigned char*)pSrc, length) < 0) {
5480 MSG_DEBUG("MsgConvertLatin2UTF8FileName: MsgLatin2UTF fail \n");
5484 int length = strlen(pSrc);
5485 pUTF8Buff = (char *)calloc(1, length+1);
5487 if (pUTF8Buff == NULL) {
5488 MSG_DEBUG("MsgConvertLatin2UTF8FileName: pUTF8Buff alloc fail \n");
5492 memcpy(pUTF8Buff, pSrc, length);
5495 //convert hex string
5496 if (MsgIsPercentSign(pUTF8Buff) == true) {
5497 pData = MsgChangeHexString(pUTF8Buff);
5499 strcpy(pUTF8Buff, pData);
5520 bool _MsgChangeSpace(char *pOrg, char **ppNew)
5530 cLen = strlen(pOrg);
5532 pNew = (char *)malloc(cLen + 1);
5536 memset(pNew, 0, cLen + 1);
5538 for (cIndex=0; cIndex<cLen;cIndex++) {
5539 if (pOrg[cIndex] == '%' && pOrg[cIndex+1] == '2' && pOrg[cIndex+2] == '0') {
5545 pNew[index++] = pOrg[cIndex];
5553 void _MsgRemoveFilePath(char *pSrc)
5555 // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
5558 char szFileName[MSG_FILENAME_LEN_MAX] = {0};
5564 while ((pTemp = strchr(pTemp, '/')) != NULL) {
5565 // Find the last '/'
5571 MSG_DEBUG("_MsgRemoveFilePath: filename(%s)\n", pSrc);
5573 // case : images/vf7.gif -> vf7.gif
5574 if (pPath != NULL && *(pPath+1) != '\0') {
5575 strncpy(szFileName, pPath+1, strlen(pPath+1));
5576 strncpy(pSrc, szFileName , strlen(szFileName));
5579 // Remove additional file information
5580 // ex) Content-type: application/octet-stream; name="060728gibson_210.jpg?size=s"
5581 // if "?size=" exist, insert NULL char.
5583 pTemp = strcasestr(pSrc, "?size=");
5589 bool MsgIsUTF8String(unsigned char *szSrc, int nChar)
5591 MSG_DEBUG("MsgIsUTF8String: --------------- \n");
5593 if (szSrc == NULL) {
5594 MSG_DEBUG("MsgIsUTF8String: szSrc is NULL !!!! --------------- \n");
5598 while (nChar > 0 && (*szSrc != '\0')) {
5599 if (*szSrc < 0x80) {
5602 } else if ((0xC0 <= *szSrc) && (*szSrc < 0xE0)) {
5603 if (*(szSrc + 1) >= 0x80) {
5607 MSG_DEBUG("MsgIsUTF8String: 1. NOT utf8 range!\n");
5610 } else if (*szSrc >= 0xE0) {
5611 if (*(szSrc + 1) >= 0x80) {
5612 if (*(szSrc + 2) >= 0x80) {
5616 MSG_DEBUG("MsgIsUTF8String: 2. NOT utf8 range!\n");
5620 MSG_DEBUG("MsgIsUTF8String: 3. NOT utf8 range!\n");
5624 MSG_DEBUG("MsgIsUTF8String: 4. NOT utf8 range!\n");
5635 bool MsgIsPercentSign(char *pSrc)
5640 pCh = strchr(pSrc , '%');
5651 MsgMultipart *MsgAllocMultipart(void)
5653 MsgMultipart *pMultipart = NULL;
5655 MSG_DEBUG("MsgAllocMultipart: --------- \n");
5657 pMultipart = (MsgMultipart*)malloc(sizeof(MsgMultipart));
5658 if (pMultipart == NULL) {
5659 MSG_DEBUG("MsgAllocMultipart: pMultipart malloc Fail \n");
5663 pMultipart->pBody = (MsgBody*)malloc(sizeof(MsgBody));
5664 if (pMultipart->pBody == NULL) {
5665 MSG_DEBUG("MsgAllocMultipart: pMultipart->pBody malloc Fail \n");
5669 _MsgInitMsgType(&pMultipart->type);
5670 _MsgInitMsgBody(pMultipart->pBody);
5672 pMultipart->pNext = NULL;
5679 if (pMultipart->pBody) {
5680 free(pMultipart->pBody);
5681 pMultipart->pBody = NULL;
5691 bool _MsgInitMsgType(MsgType *pMsgType)
5693 pMsgType->offset = 0;
5695 pMsgType->contentSize = 0;
5696 pMsgType->disposition = 0;
5697 pMsgType->encoding = 0;
5698 pMsgType->type = MIME_UNKNOWN;
5699 #ifdef FEATURE_JAVA_MMS_MIME
5700 pMsgType->szMimeString[0] ='\0';
5702 pMsgType->section = 0;
5704 pMsgType->szOrgFilePath[0] = '\0';
5705 pMsgType->szContentID[0] = '\0';
5706 pMsgType->szContentLocation[0] = '\0';
5708 pMsgType->szContentRepPos[0] = '\0';
5709 pMsgType->szContentRepSize[0] = '\0';
5710 pMsgType->szContentRepIndex[0] = '\0';
5712 __MsgInitMsgContentParam(&pMsgType->param);
5713 #ifdef __SUPPORT_DRM__
5714 __MsgInitMsgDRMInfo(&pMsgType->drmInfo);
5721 bool __MsgInitMsgContentParam(MsgContentParam *pMsgContentParam)
5723 pMsgContentParam->charset = MSG_CHARSET_UNKNOWN;
5724 pMsgContentParam->type = MIME_UNKNOWN;
5725 pMsgContentParam->szBoundary[0] = '\0';
5726 pMsgContentParam->szFileName[0] = '\0';
5727 pMsgContentParam->szName[0] = '\0';
5728 #ifdef FEATURE_JAVA_MMS
5729 pMsgContentParam->szApplicationID = NULL;
5730 pMsgContentParam->szReplyToApplicationID = NULL;
5732 pMsgContentParam->szStart[0] = '\0';
5733 pMsgContentParam->szStartInfo[0] = '\0';
5734 pMsgContentParam->pPresentation = NULL;
5736 pMsgContentParam->reportType = MSG_PARAM_REPORT_TYPE_UNKNOWN; // add only used as parameter of Content-Type: multipart/report; report-type
5742 bool _MsgInitMsgBody(MsgBody *pMsgBody)
5744 pMsgBody->offset = 0;
5746 pMsgBody->body.pText = NULL;
5747 pMsgBody->szOrgFilePath[0] = '\0';
5749 _MsgInitMsgType(&pMsgBody->presentationType);
5750 pMsgBody->pPresentationBody = NULL;
5752 memset(pMsgBody->szOrgFilePath, 0, MSG_FILEPATH_LEN_MAX);
5758 MsgPresentationFactor MsgIsPresentationEx(MsgType *multipartType, char* szStart, MsgContentType typeParam)
5760 char szTmpStart[MSG_MSG_ID_LEN + 3] = { 0, };
5761 char szTmpContentID[MSG_MSG_ID_LEN + 3] = { 0, };
5762 char szTmpContentLO[MSG_MSG_ID_LEN + 3] = { 0, };
5765 // remove '<' and '>' in Start Param : contentID ex] <0_1.jpg> or <1233445>
5766 if (szStart && szStart[0]) {
5768 startLen = strlen(szStart);
5769 if (szStart[0] == '<' && szStart[startLen - 1] == '>') {
5770 strncpy(szTmpStart, &szStart[1], startLen - 2);
5772 strncpy(szTmpStart, szStart, startLen);
5776 // remove '<' and '>' in ContentID : contentID ex] <0_1.jpg> or <1233445>
5777 if (multipartType->szContentID[0]) {
5778 strLen = strlen(multipartType->szContentID);
5779 if (multipartType->szContentID[0] == '<' && multipartType->szContentID[strLen - 1] == '>') {
5780 strncpy(szTmpContentID, &(multipartType->szContentID[1]), strLen - 2);
5782 strncpy(szTmpContentID, multipartType->szContentID, strLen);
5786 // remove '<' and '>' in ContentLocation : contentID ex] <0_1.jpg> or <1233445>
5787 if (multipartType->szContentLocation[0]) {
5788 strLen = strlen(multipartType->szContentLocation);
5789 if (multipartType->szContentLocation[0] == '<' && multipartType->szContentLocation[strLen - 1] == '>') {
5790 strncpy(szTmpContentLO, &multipartType->szContentLocation[1], strLen - 2);
5792 strncpy(szTmpContentLO, multipartType->szContentLocation, strLen);
5796 if ((szTmpContentID[0] == '\0') && (szTmpContentLO[0] == '\0') && (multipartType->type == MIME_UNKNOWN))
5797 return MSG_PRESENTATION_NONE;
5799 // exception handling
5800 if (szTmpStart[0] != '\0') {
5801 // presentation part : 1.compare with contentID 2.compare with content Location 3. compare with type
5802 if (strcmp(szTmpStart, szTmpContentID) == 0) {
5803 return MSG_PRESENTATION_ID;
5804 } else if (strcmp(szTmpStart, szTmpContentLO) == 0) {
5805 return MSG_PRESENTATION_LOCATION;
5806 } else if (multipartType->type == typeParam) {
5807 return MSG_PRESENTATION_TYPE_BASE;
5809 return MSG_PRESENTATION_NONE;
5812 if (multipartType->type == typeParam && typeParam != MIME_UNKNOWN) {
5813 return MSG_PRESENTATION_TYPE_BASE;
5815 return MSG_PRESENTATION_NONE;
5820 void MsgConfirmPresentationPart(MsgType *pMsgType, MsgBody *pMsgBody, MsgPresentaionInfo *pPresentationInfo)
5823 MsgMultipart *pNextPart = NULL;
5824 MsgMultipart *pRemovePart = NULL;
5826 if (MsgIsMultipartRelated(pMsgType->type)) {
5827 // assign the multipart to presentation part
5828 // remove the multipart(pCurPresentation) which is presentation part from the linked list.
5829 // if there is no presentation part -> assign first multipart to presentation part by force.
5830 if (pPresentationInfo->pCurPresentation == NULL) {
5831 pPresentationInfo->pCurPresentation = pMsgBody->body.pMultipart;
5832 pPresentationInfo->pPrevPart = NULL;
5833 pPresentationInfo->factor = MSG_PRESENTATION_NONE;
5836 if (pPresentationInfo->pCurPresentation != NULL && MsgIsPresentablePart(pPresentationInfo->pCurPresentation->type.type)) {
5837 /* Presentable Part is some MARK-UP page, such as SMIL, HTML, WML, XHTML.
5838 * In this case, COPY the Presentation part and leave other multiparts.
5840 memcpy(&pMsgBody->presentationType, &pPresentationInfo->pCurPresentation->type, sizeof(MsgType));
5841 pMsgBody->pPresentationBody = pPresentationInfo->pCurPresentation->pBody;
5843 // remove pCurPresentation from multipart linked list
5844 if ((pPresentationInfo->factor == MSG_PRESENTATION_NONE)||(pPresentationInfo->pPrevPart == NULL)) {
5846 pMsgBody->body.pMultipart = pPresentationInfo->pCurPresentation->pNext;
5847 pMsgType->contentSize -= pPresentationInfo->pCurPresentation->pBody->size;
5848 pMsgBody->size -= pPresentationInfo->pCurPresentation->pBody->size;
5849 if (pPresentationInfo->pCurPresentation) {
5850 #ifdef __SUPPORT_DRM__
5851 _MsgFreeDRMInfo(&pPresentationInfo->pCurPresentation->type.drmInfo);
5853 free(pPresentationInfo->pCurPresentation);
5854 pPresentationInfo->pCurPresentation = NULL;
5858 pPresentationInfo->pPrevPart->pNext = pPresentationInfo->pCurPresentation->pNext;
5859 pMsgType->contentSize -= pPresentationInfo->pCurPresentation->pBody->size;
5860 pMsgBody->size -= pPresentationInfo->pCurPresentation->pBody->size;
5861 if (pPresentationInfo->pCurPresentation) {
5862 free(pPresentationInfo->pCurPresentation);
5863 pPresentationInfo->pCurPresentation = NULL;
5866 } else if (pPresentationInfo->pCurPresentation != NULL && MsgIsText(pPresentationInfo->pCurPresentation->type.type)) {
5867 /* NON-Presentable Part is some PLAIN part such as, text/plain, multipart/alternative.
5868 * In this case, leave the Presentation part as a multipart and remove other multiparts.
5871 // Backup the multipart link information
5872 pNextPart = pMsgBody->body.pMultipart;
5874 // Copy presentation part as a main part
5875 memcpy(pMsgType, &pPresentationInfo->pCurPresentation->type, sizeof(MsgType));
5876 memcpy(pMsgBody, pPresentationInfo->pCurPresentation->pBody, sizeof(MsgBody));
5878 // Remove multipart linked list
5880 pRemovePart = pNextPart;
5881 pNextPart = pNextPart->pNext;
5883 if (pRemovePart->pBody) {
5884 _MsgFreeBody(pRemovePart->pBody, pRemovePart->type.type);
5885 free(pRemovePart->pBody);
5886 pRemovePart->pBody = NULL;
5893 #ifdef __SUPPORT_DRM__
5894 _MsgFreeDRMInfo(&pMsgBody->presentationType.drmInfo);
5896 _MsgInitMsgType(&pMsgBody->presentationType);
5897 pMsgBody->pPresentationBody = NULL;
5903 bool MsgIsMultipartRelated(int type)
5905 if (type == MIME_MULTIPART_RELATED || type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
5912 bool MsgIsPresentablePart(int type)
5914 if (type == MIME_TEXT_HTML || type == MIME_TEXT_VND_WAP_WML || type == MIME_APPLICATION_SMIL) {
5921 #ifdef __SUPPORT_DRM__
5922 void _MsgFreeDRMInfo(MsgDRMInfo *pDrmInfo)
5924 MSG_DEBUG("_MsgFreeDRMInfo: S T A R T !!! \n");
5926 if (pDrmInfo == NULL) {
5927 MSG_DEBUG("pDrmInfo is NULL");
5931 if (pDrmInfo->szContentDescription) {
5932 free(pDrmInfo->szContentDescription);
5933 pDrmInfo->szContentDescription = NULL;
5936 if (pDrmInfo->szContentVendor) {
5937 free(pDrmInfo->szContentVendor);
5938 pDrmInfo->szContentVendor = NULL;
5941 if (pDrmInfo->szContentName) {
5942 free(pDrmInfo->szContentName);
5943 pDrmInfo->szContentName = NULL;
5946 if (pDrmInfo->szContentURI) {
5947 free(pDrmInfo->szContentURI);
5948 pDrmInfo->szContentURI = NULL;
5951 if (pDrmInfo->szRightIssuer) {
5952 free(pDrmInfo->szRightIssuer);
5953 pDrmInfo->szRightIssuer = NULL;
5956 if (pDrmInfo->szDrm2FullPath) {
5957 free(pDrmInfo->szDrm2FullPath);
5958 pDrmInfo->szDrm2FullPath = NULL;
5961 #if MMS_ENABLE_EXTEND_CFM
5962 // DRM (Extended)CFM
5963 if (pDrmInfo->pszContentType) {
5964 free(pDrmInfo->pszContentType);
5965 pDrmInfo->pszContentType = NULL;
5969 pDrmInfo->contentType = MIME_UNKNOWN;
5970 pDrmInfo->drmType = MSG_DRM_TYPE_NONE;
5973 bool MsgCopyDrmInfo(MsgType *pPartType)
5976 char *pTmpBuf = NULL;
5978 //convert application/vnd.oma.drm.content to media type
5979 pPartType->type = pPartType->drmInfo.contentType;
5981 // fix wrong file name presentation on save media screen.
5982 if (pPartType->szContentID[0] == '\0' && pPartType->drmInfo.szContentURI)
5983 strncpy(pPartType->szContentID, pPartType->drmInfo.szContentURI, MSG_MSG_ID_LEN);
5985 /* set title name (content name) */
5986 if (pPartType->param.szName[0] == '\0') {
5987 /* szName is vitual name, real filename is *.dcf or *.dm */
5988 if (pPartType->drmInfo.szContentName && pPartType->drmInfo.szContentName[0] != '\0') {
5989 /* In case of szContentName retrieved from DRM agent is exist. */
5990 pTmpBuf = pPartType->drmInfo.szContentName;
5991 } else if (pPartType->szContentLocation[0] != '\0') {
5992 /* In case of szContentLocation parsed from MMS header */
5993 pTmpBuf = strrchr(pPartType->szContentLocation, '/');
5994 if (pTmpBuf == NULL)
5995 pTmpBuf = pPartType->szContentLocation;
5997 /* use another name */
5998 /* possible NULL pointer assignment*/
5999 pTmpBuf = strdup("untitled");
6002 if ((pExt = strrchr(pTmpBuf, '.')) != NULL) {
6004 int fileNameLen = 0;
6007 extLen = strlen(pExt);
6008 tmpLen = strlen(pTmpBuf);
6009 fileNameLen = (tmpLen - extLen < MSG_LOCALE_FILENAME_LEN_MAX - extLen)?(tmpLen - extLen):(MSG_LOCALE_FILENAME_LEN_MAX - extLen);
6010 strncpy(pPartType->param.szName, pTmpBuf, fileNameLen);
6011 strcpy (pPartType->param.szName + fileNameLen, pExt);
6013 strncpy(pPartType->param.szName, pTmpBuf, MSG_LOCALE_FILENAME_LEN_MAX);
6014 MsgMakeFileName(pPartType->type, pPartType->param.szName, MSG_DRM_TYPE_NONE, 0);
6023 bool MsgIsText(int type)
6025 if (type == MIME_TEXT_PLAIN || type == MIME_TEXT_HTML || type == MIME_TEXT_VND_WAP_WML ||
6026 type == MIME_TEXT_X_VNOTE || type == MIME_APPLICATION_SMIL || type == MIME_TEXT_X_IMELODY) {
6033 bool MsgFreeAttrib(MmsAttrib *pAttrib)
6037 if (pAttrib == NULL) {
6038 MSG_DEBUG("pAttrib is NULL");
6042 if (pAttrib->szTo) {
6043 free(pAttrib->szTo);
6044 pAttrib->szTo = NULL;
6047 if (pAttrib->szCc) {
6048 free(pAttrib->szCc);
6049 pAttrib->szCc = NULL;
6052 if (pAttrib->szBcc) {
6053 free(pAttrib->szBcc);
6054 pAttrib->szBcc = NULL;
6057 //check if pMultiStatus should be freed or not, because pMultiStatus is not allocated
6058 if (pAttrib->pMultiStatus) {
6059 MmsMsgMultiStatus *pMultiStatus = pAttrib->pMultiStatus;
6060 MmsMsgMultiStatus *pCurStatus = NULL;
6062 while (pMultiStatus != NULL ) {
6063 pCurStatus = pMultiStatus;
6064 pMultiStatus = pMultiStatus->pNext;
6072 pAttrib->pMultiStatus = NULL;
6081 bool _MsgFreeBody(MsgBody *pBody, int type)
6083 MSG_DEBUG("_MsgFreeBody: S T A R T !!! \n") ;
6085 if (pBody == NULL) {
6086 MSG_DEBUG("_MsgFreeBody: pBody == NULL \n" );
6087 MSG_DEBUG("_MsgFreeBody: E N D (End)!!! \n") ;
6093 case MIME_MULTIPART_REPORT:
6094 case MIME_APPLICATION_VND_OMA_DRM_MESSAGE:
6095 case MIME_APPLICATION_VND_WAP_MULTIPART_MIXED:
6096 case MIME_APPLICATION_VND_WAP_MULTIPART_RELATED:
6097 case MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC:
6098 case MIME_MULTIPART_MIXED:
6099 case MIME_MULTIPART_RELATED:
6100 case MIME_MULTIPART_ALTERNATIVE:
6101 case MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE:
6103 MsgMultipart *pMulti = pBody->body.pMultipart;
6104 MsgMultipart *pCurrPart = NULL;
6105 MsgBody *pPresentation = pBody->pPresentationBody;
6106 while (pMulti != NULL) {
6109 pMulti = pMulti->pNext;
6112 #ifdef __SUPPORT_DRM__
6113 _MsgFreeDRMInfo(&pCurrPart->type.drmInfo);
6116 if (pCurrPart->pBody) {
6117 if (pCurrPart->pBody->body.pBinary) {
6118 free(pCurrPart->pBody->body.pBinary);
6119 pCurrPart->pBody->body.pBinary = NULL;
6121 free(pCurrPart->pBody);
6122 pCurrPart->pBody = NULL;
6129 pBody->body.pMultipart = NULL;
6131 if (pPresentation) {
6132 if (pPresentation->body.pText) {
6133 free(pPresentation->body.pText);
6134 pPresentation->body.pText = NULL;
6136 free(pPresentation);
6137 pBody->pPresentationBody = NULL;
6140 _MsgInitMsgType(&pBody->presentationType);
6146 /* Any single part */
6148 if (pBody->body.pBinary) {
6149 free(pBody->body.pBinary);
6150 pBody->body.pBinary = NULL;
6156 MSG_DEBUG("_MsgFreeBody: E N D (Successfully) !!! \n") ;
6162 bool MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
6165 MsgMultipart *pTmpMultipart = NULL;
6166 MsgMultipart *pSelectedPart = NULL;
6167 MsgMultipart *pPrevPart = NULL;
6168 MsgMultipart *pFirstPart = NULL;
6169 MsgMultipart *pLastPart = NULL;
6170 MsgMultipart *pRemoveList = NULL;
6171 MsgMultipart *pNextRemovePart = NULL;
6173 switch (pPartType->type) {
6174 case MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE:
6175 case MIME_MULTIPART_ALTERNATIVE:
6178 * Policy: multipart/alternative
6179 * multipart/alternative message has only several parts of media.
6180 * You should choose one of them and make the alternative part
6181 * to the selected media part.
6184 MSG_DEBUG("MsgResolveNestedMultipart : MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE\n");
6186 pSelectedPart = pPartBody->body.pMultipart;
6188 // NULL Pointer check!!
6189 if (pSelectedPart == NULL) {
6190 MSG_DEBUG("MsgResolveNestedMultipart : multipart(ALTERNATIVE) does not exist\n");
6194 pTmpMultipart = pPartBody->body.pMultipart->pNext;
6196 while (pTmpMultipart) {
6197 if (pSelectedPart->type.type <= pTmpMultipart->type.type)
6198 pSelectedPart = pTmpMultipart;
6200 pTmpMultipart = pTmpMultipart->pNext;
6203 pTmpMultipart = pPartBody->body.pMultipart;
6206 while (pTmpMultipart) {
6207 if (pSelectedPart == pTmpMultipart)
6210 pPrevPart = pTmpMultipart;
6211 pTmpMultipart = pTmpMultipart->pNext;
6214 if (pPrevPart == NULL) {
6215 /* selected part is the first part */
6216 pRemoveList = pSelectedPart->pNext;
6218 pPrevPart->pNext = pSelectedPart->pNext;
6219 pRemoveList = pPartBody->body.pMultipart;
6220 pPartBody->body.pMultipart = pSelectedPart;
6223 pSelectedPart->pNext = NULL;
6226 #ifdef __SUPPORT_DRM__
6227 _MsgFreeDRMInfo(&pRemoveList->type.drmInfo);
6229 _MsgFreeBody(pRemoveList->pBody, pRemoveList->type.type);
6231 free(pRemoveList->pBody);
6235 if (MsgCopyNestedMsgType(pPartType, &(pSelectedPart->type)) == false) {
6236 MSG_DEBUG("MsgResolveNestedMultipart : MsgPriorityCopyMsgType failed \n");
6240 if (pSelectedPart->pBody != NULL)
6241 memcpy(pPartBody, pSelectedPart->pBody, sizeof(MsgBody));
6243 if (pSelectedPart != NULL) {
6244 #ifdef __SUPPORT_DRM__
6245 _MsgFreeDRMInfo(&pSelectedPart->type.drmInfo);
6248 if (pSelectedPart->pBody != NULL) {
6249 free(pSelectedPart->pBody);
6250 pSelectedPart->pBody = NULL;
6252 free(pSelectedPart);
6253 pSelectedPart = NULL;
6258 case MIME_APPLICATION_VND_WAP_MULTIPART_RELATED:
6259 case MIME_MULTIPART_RELATED:
6261 MSG_DEBUG("MsgResolveNestedMultipart : MIME_APPLICATION_VND_WAP_MULTIPART_RELATED\n");
6263 pSelectedPart = pPartBody->body.pMultipart;
6265 while (pSelectedPart) {
6266 if (MsgIsMultipartMixed(pSelectedPart->type.type)) {
6268 if (pSelectedPart->pBody == NULL) {
6269 MSG_DEBUG("MsgResolveNestedMultipart :pSelectedPart->pBody(1) is NULL\n");
6273 pFirstPart = pSelectedPart->pBody->body.pMultipart;
6275 if (pFirstPart == NULL) {
6276 MSG_DEBUG("MsgResolveNestedMultipart : multipart(RELATED) does not exist\n");
6280 if (pFirstPart->pNext) {
6281 pLastPart = pFirstPart->pNext;
6282 while (pLastPart->pNext)
6283 pLastPart = pLastPart->pNext;
6285 pLastPart = pFirstPart;
6288 if (pPrevPart == NULL) {
6289 /* the first part */
6290 pTmpMultipart = pPartBody->body.pMultipart->pNext;
6291 pPartBody->body.pMultipart = pFirstPart;
6292 pLastPart->pNext = pTmpMultipart;
6294 pTmpMultipart = pSelectedPart->pNext;
6295 pPrevPart->pNext = pFirstPart;
6296 pLastPart->pNext = pTmpMultipart;
6299 if (pSelectedPart) {
6300 #ifdef __SUPPORT_DRM__
6301 _MsgFreeDRMInfo(&pSelectedPart->type.drmInfo);
6303 free(pSelectedPart->pBody);
6304 free(pSelectedPart);
6306 pSelectedPart = pTmpMultipart;
6307 } else if (MsgIsMultipartRelated(pSelectedPart->type.type) && pPrevPart != NULL) {
6308 pPrevPart->pNext = pTmpMultipart = pSelectedPart->pNext;
6309 _MsgFreeBody(pSelectedPart->pBody, pSelectedPart->type.type);
6311 free(pSelectedPart->pBody);
6312 free(pSelectedPart);
6313 pSelectedPart = pTmpMultipart;
6315 pPrevPart = pSelectedPart;
6316 pSelectedPart = pSelectedPart->pNext;
6323 case MIME_APPLICATION_VND_WAP_MULTIPART_MIXED:
6324 case MIME_MULTIPART_MIXED:
6326 MSG_DEBUG("MsgResolveNestedMultipart : MIME_APPLICATION_VND_WAP_MULTIPART_MIXED\n");
6329 pSelectedPart = pPartBody->body.pMultipart;
6331 while (pSelectedPart) {
6332 if (MsgIsMultipart(pSelectedPart->type.type)) {
6333 if (pSelectedPart->pBody == NULL) {
6334 MSG_DEBUG("MsgResolveNestedMultipart :pSelectedPart->pBody(2) is NULL\n");
6338 pFirstPart = pSelectedPart->pBody->body.pMultipart;
6340 // NULL Pointer check!!
6341 if (pFirstPart == NULL) {
6342 MSG_DEBUG("MsgResolveNestedMultipart : multipart does not exist\n");
6346 if (pFirstPart->pNext) {
6347 pLastPart = pFirstPart->pNext;
6348 while (pLastPart->pNext)
6349 pLastPart = pLastPart->pNext;
6351 pLastPart = pFirstPart;
6354 if (pPrevPart == NULL) {
6355 /* the first part */
6356 pTmpMultipart = pPartBody->body.pMultipart->pNext;
6357 pPartBody->body.pMultipart = pFirstPart;
6358 pLastPart->pNext = pTmpMultipart;
6360 pTmpMultipart = pSelectedPart->pNext;
6361 pPrevPart->pNext = pFirstPart;
6362 pLastPart->pNext = pTmpMultipart;
6365 if (pSelectedPart->pBody->pPresentationBody)
6366 pPartBody->pPresentationBody = pSelectedPart->pBody->pPresentationBody;
6368 memcpy(&pPartBody->presentationType,
6369 &pSelectedPart->pBody->presentationType, sizeof(MsgType));
6371 pPartType->type = pSelectedPart->type.type;
6373 #ifdef __SUPPORT_DRM__
6374 _MsgFreeDRMInfo(&pSelectedPart->type.drmInfo);
6376 free(pSelectedPart->pBody);
6377 free(pSelectedPart);
6379 pSelectedPart = pTmpMultipart;
6381 pPrevPart = pSelectedPart;
6382 pSelectedPart = pSelectedPart->pNext;
6388 case MIME_MULTIPART_REPORT:
6390 MSG_DEBUG("MsgResolveNestedMultipart : MIME_MULTIPART_REPORT \n");
6392 pTmpMultipart = pPartBody->body.pMultipart;
6395 if (pTmpMultipart == NULL) {
6396 MSG_DEBUG("MsgResolveNestedMultipart : pTmpMultipart == NULL \n");
6400 while (pTmpMultipart) {
6401 if (pTmpMultipart->type.type == MIME_TEXT_PLAIN) {
6402 pSelectedPart = pTmpMultipart;
6406 pPrevPart = pTmpMultipart;
6407 pTmpMultipart = pTmpMultipart->pNext;
6410 if (pSelectedPart == NULL) {
6411 MSG_DEBUG("MsgResolveNestedMultipart : MIME_MULTIPART_REPORT [no selected part]\n");
6412 MSG_DEBUG("MsgResolveNestedMultipart : MIME_MULTIPART_REPORT [no selected part]\n");
6414 pRemoveList = pPartBody->body.pMultipart->pNext;
6415 pSelectedPart = pPartBody->body.pMultipart;
6416 pSelectedPart->pNext = NULL;
6418 if (pPrevPart == NULL) {
6419 // first part is selected
6420 pRemoveList = pPartBody->body.pMultipart->pNext;
6422 pRemoveList = pPartBody->body.pMultipart->pNext;
6423 pPrevPart->pNext = pSelectedPart->pNext;
6426 pSelectedPart->pNext = NULL;
6427 pPartBody->body.pMultipart = pSelectedPart;
6430 pTmpMultipart = pRemoveList;
6432 while (pTmpMultipart) {
6433 #ifdef __SUPPORT_DRM__
6434 _MsgFreeDRMInfo(&pTmpMultipart->type.drmInfo);
6436 _MsgFreeBody(pTmpMultipart->pBody, pTmpMultipart->type.type);
6437 pNextRemovePart = pTmpMultipart->pNext;
6439 free(pTmpMultipart->pBody);
6440 free(pTmpMultipart);
6441 pTmpMultipart = pNextRemovePart;
6444 if (MsgCopyNestedMsgType(pPartType, &(pSelectedPart->type)) == false) {
6445 MSG_DEBUG("MsgResolveNestedMultipart : MsgPriorityCopyMsgType failed \n");
6449 if (pSelectedPart->pBody != NULL)
6450 memcpy(pPartBody, pSelectedPart->pBody, sizeof(MsgBody));
6452 if (pSelectedPart != NULL) {
6453 #ifdef __SUPPORT_DRM__
6454 _MsgFreeDRMInfo(&pSelectedPart->type.drmInfo);
6456 if (pSelectedPart->pBody != NULL) {
6457 free(pSelectedPart->pBody);
6458 pSelectedPart->pBody = NULL;
6460 free(pSelectedPart);
6461 pSelectedPart = NULL;
6478 char *MsgResolveContentURI(char *szSrc)
6480 char *szTemp = NULL;
6481 char *szReturn = NULL;
6484 if (szSrc == NULL) {
6488 if (szSrc[0] == '\0')
6492 if (!strncasecmp(szSrc, "cid:", 4)) {
6493 length = strlen(szSrc) - 3;
6496 length = strlen(szSrc) + 1;
6499 szTemp = (char *)malloc(length);
6500 if (szTemp == NULL) {
6501 MSG_DEBUG("MsgResolveContentURI: memory full\n");
6505 memset(szTemp, 0, length);
6506 strcpy(szTemp, szSrc);
6508 szReturn = MsgChangeHexString(szTemp);
6526 bool _MsgParsePartHeader(MsgType *pType, const char *pRawData, int nRawData)
6529 int cRaw = nRawData;
6530 char *pFieldLine = NULL;
6531 char *pFieldValue = NULL;
6532 char *szFieldValue = NULL;
6535 char fieldLine[MSG_LINE_LEN] = {0, }; //temporary line buffer
6538 char szTempBuf[MSG_LOCAL_TEMP_BUF_SIZE];
6540 while ((cRaw > 0) && *pRawData != MSG_CH_LF) {
6541 memset(fieldLine, 0, MSG_LINE_LEN);
6542 pFieldLine = fieldLine;
6544 ch = MSG_CH_SP; //remember previous character.
6547 switch (ch = *pRawData++) {
6548 case MSG_CH_CR: //'\r'
6549 if (*pRawData == MSG_CH_LF)
6552 case MSG_CH_LF: //'\n'
6553 if (*pRawData != MSG_CH_SP && *pRawData != MSG_CH_TAB) {
6560 case MSG_CH_TAB: //'\t'
6561 *pFieldLine = MSG_CH_SP;
6571 if (--cRaw <= 0) { //If is the last character of header
6572 *pFieldLine = MSG_CH_NULL;
6578 if ((pFieldValue = strchr(fieldLine, MSG_CH_COLON)) != NULL) {
6579 char* pTemp = pFieldValue;
6580 char* pValue = NULL;
6582 *pFieldValue++ = MSG_CH_NULL; //remove ':'
6584 while (*pFieldValue == MSG_CH_SP) //remove space ' '
6587 while ((fieldLine < pTemp--) && (*pTemp == MSG_CH_SP))
6588 *pTemp = MSG_CH_NULL;
6590 nLen = strlen(pFieldValue);
6592 if (nLen >= MSG_LOCAL_TEMP_BUF_SIZE) {
6593 szFieldValue = (char *)malloc(nLen + 1);
6594 memset(szFieldValue, 0 , nLen + 1);
6595 memcpy(szFieldValue, pFieldValue, nLen + 1);
6597 memset(szTempBuf, 0, MSG_LOCAL_TEMP_BUF_SIZE);
6598 strcpy(szTempBuf, pFieldValue);
6599 szFieldValue = szTempBuf;
6602 if (MsgStrcpyWithoutCRLF(szFieldValue, &szSrc) == true) {
6604 strncpy(szFieldValue, szSrc, strlen(szSrc));
6611 switch (_MsgGetCode(MSG_FIELD, fieldLine)) {
6612 case MSG_FIELD_CONTENT_ID:
6613 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) != NULL)
6614 *pTemp++ = MSG_CH_NULL;
6616 pValue = _MsgDecodeText(szFieldValue);
6617 memset (pType->szContentID, 0, MSG_MSG_ID_LEN + 1);
6621 length = MsgStrlen(pValue);
6622 if (pValue[0] == '<' && pValue[length-1] == '>') {
6623 strncpy(pType->szContentID, pValue + 1, length - 2);
6625 strncpy(pType->szContentID, pValue, MSG_MSG_ID_LEN);
6628 MSG_DEBUG("_MsgParsePartHeader: Content-ID = %s %s\n", pFieldValue, pType->szContentID);
6631 _MsgParseParameter(pType, pTemp);
6639 case MSG_FIELD_CONTENT_LOCATION:
6640 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) != NULL)
6641 *pTemp++ = MSG_CH_NULL;
6643 pValue = _MsgDecodeText(szFieldValue);
6644 memset (pType->szContentLocation, 0, MSG_MSG_ID_LEN + 1);
6647 strncpy(pType->szContentLocation, pValue, MSG_MSG_ID_LEN);
6649 MSG_DEBUG("_MsgParsePartHeader: Content-Location = %s %s\n", pFieldValue, pType->szContentLocation);
6652 _MsgParseParameter(pType, pTemp);
6660 case MSG_FIELD_CONTENT_TYPE:
6661 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) == NULL) {
6662 if ((pTemp = strchr(szFieldValue, MSG_CH_SP)) != NULL)
6663 *pTemp++ = MSG_CH_NULL;
6665 *pTemp++ = MSG_CH_NULL;
6668 pType->type = _MsgGetCode(MSG_TYPE, szFieldValue);
6670 MSG_DEBUG("_MsgParsePartHeader: Content-Type = %s %d\n", pFieldValue, pType->type);
6672 if (pType->type == INVALID_HOBJ)
6673 pType->type = MIME_UNKNOWN;
6676 _MsgParseParameter(pType, pTemp);
6680 case MSG_FIELD_CONTENT_TRANSFER_ENCODING:
6681 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) == NULL) {
6682 if ((pTemp = strchr(szFieldValue, MSG_CH_SP)) != NULL)
6683 *pTemp++ = MSG_CH_NULL;
6685 *pTemp++ = MSG_CH_NULL;
6688 pType->encoding = _MsgGetCode(MSG_ENCODING, szFieldValue);
6690 MSG_DEBUG("_MsgParsePartHeader: Content-Encoding = %s %d\n", pFieldValue, pType->encoding);
6693 _MsgParseParameter(pType, pTemp);
6697 case MSG_FIELD_CONTENT_DISPOSITION:
6698 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) == NULL) {
6699 if ((pTemp = strchr(szFieldValue, MSG_CH_SP)) != NULL)
6700 *pTemp++ = MSG_CH_NULL;
6702 *pTemp++ = MSG_CH_NULL;
6705 pType->disposition = _MsgGetCode(MSG_DISPOSITION, szFieldValue);
6707 MSG_DEBUG("_MsgParsePartHeader: Content-Disposition = %s %d\n", pFieldValue, pType->disposition);
6710 _MsgParseParameter(pType, pTemp);
6714 #ifdef __SUPPORT_DRM__
6716 case MSG_FIELD_CONTENT_NAME:
6717 /* add to parse DCF header such as,
6718 * Right-Issuer, Content-Name, and Content-Description.
6720 MsgMIMERemoveQuote(szFieldValue);
6721 pType->drmInfo.szContentName = MsgStrCopy(szFieldValue);
6724 case MSG_FIELD_CONTENT_DESCRIPTION:
6725 MsgMIMERemoveQuote(szFieldValue);
6726 pType->drmInfo.szContentDescription = MsgStrCopy(szFieldValue);
6729 case MSG_FIELD_CONTENT_VENDOR:
6730 MsgMIMERemoveQuote(szFieldValue);
6731 pType->drmInfo.szContentVendor = MsgStrCopy(szFieldValue);
6734 case MSG_FIELD_RIGHT_ISSUER:
6735 MsgMIMERemoveQuote(szFieldValue);
6736 pType->drmInfo.szRightIssuer = MsgStrCopy(szFieldValue);
6740 case MSG_FIELD_DRM_CONVERTED:
6741 MsgMIMERemoveQuote(szFieldValue);
6742 pType->nDrmConvertedStatus = atoi(szFieldValue);
6746 case MSG_FILED_CONTENT_REPLACE_POS:
6747 MsgMIMERemoveQuote(szFieldValue);
6748 strncpy(pType->szContentRepPos, szFieldValue, sizeof(pType->szContentRepPos));
6751 case MSG_FILED_CONTENT_REPLACE_SIZE:
6752 MsgMIMERemoveQuote(szFieldValue);
6753 strncpy(pType->szContentRepSize, szFieldValue, sizeof(pType->szContentRepSize));
6756 case MSG_FILED_CONTENT_REPLACE_INDEX:
6757 MsgMIMERemoveQuote(szFieldValue);
6758 strncpy(pType->szContentRepIndex, szFieldValue, sizeof(pType->szContentRepIndex));
6762 MSG_DEBUG("_MsgParsePartHeader: Unhandled field \n");
6767 if (szFieldValue != NULL && szFieldValue != szTempBuf) {
6769 szFieldValue = NULL;
6777 char *MsgRemoveQuoteFromFilename(char *pSrc)
6779 int cLen = 0; // length of pBuff
6783 MSG_DEBUG("MsgRemoveQuoteFromFilename: pSrc is Null\n");
6787 cLen = strlen(pSrc);
6789 pBuff = (char *)malloc(cLen + 1);
6791 if (pBuff == NULL) {
6792 MSG_DEBUG("MsgRemoveQuoteFromFilename: pBuff mem alloc fail!\n");
6795 memset(pBuff, 0 , sizeof(char)*(cLen + 1));
6797 // remove front quote
6798 if (pSrc[0] == MSG_CH_QUOT) {
6800 strncpy(pBuff, &pSrc[1], cLen);
6804 if (pSrc[0] == MSG_CH_LF) {
6806 strncpy(pBuff, &pSrc[1], cLen);
6808 strcpy(pBuff, pSrc);
6811 // remove last qoute
6812 if (pBuff[cLen-1] == MSG_CH_QUOT) {
6813 pBuff[cLen-1] = '\0';
6819 bool MsgIsMultipart(int type)
6821 if (type == MIME_MULTIPART_RELATED || type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED ||
6822 type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED || type == MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC ||
6823 type == MIME_MULTIPART_MIXED || type == MIME_MULTIPART_REPORT) {
6831 bool MsgIsHexChar(char *pSrc)
6837 cLen = strlen(pSrc);
6839 for (cIndex = 0; cIndex < cLen ; cIndex++) {
6840 if ((pSrc[cIndex] >= '0' && pSrc[cIndex] <= '9') || (pSrc[cIndex] >= 'A'&& pSrc[cIndex] <= 'F') ||
6841 (pSrc[cIndex] >= 'a' && pSrc[cIndex] <= 'f')) {
6851 char _MsgConvertHexValue(char *pSrc)
6857 unsigned char uCh[2] = {0,};
6859 cLen = strlen(pSrc);
6861 for (cIndex = 0; cIndex < cLen ; cIndex += 2) {
6862 uCh[0] = __MsgConvertCharToInt(pSrc[cIndex]);
6863 uCh[1] = __MsgConvertCharToInt(pSrc[cIndex+1]);
6864 ch = (int)uCh[0]<<4|uCh[1];
6867 ResultChar = (char)ch;
6872 int __MsgConvertCharToInt(char ch)
6874 if (ch>='0' && ch<='9') {
6876 } else if (ch>='a'&& ch <='f') {
6878 } else if (ch>='A'&& ch <='F') {
6885 bool MsgCopyNestedMsgType(MsgType *pMsgType1, MsgType *pMsgType2)
6887 if (pMsgType1->section == INVALID_HOBJ)
6888 pMsgType1->section = pMsgType2->section;
6890 #ifdef __SUPPORT_DRM__
6893 if (pMsgType1->drmInfo.drmType == MSG_DRM_TYPE_NONE)
6894 pMsgType1->drmInfo.drmType = pMsgType2->drmInfo.drmType;
6897 if (pMsgType1->szContentID[0] == '\0') {
6898 strcpy(pMsgType1->szContentID, pMsgType2->szContentID);
6900 if (pMsgType2->szContentID[0]) {
6901 length = MsgStrlen(pMsgType2->szContentID);
6902 if (pMsgType2->szContentID[0] == '<' && pMsgType2->szContentID[length - 1] == '>') {
6903 pMsgType1->drmInfo.szContentURI = MsgStrNCopy(pMsgType2->szContentID + 1, length - 2);
6905 pMsgType1->drmInfo.szContentURI = MsgStrCopy(pMsgType2->szContentID);
6909 length = MsgStrlen(pMsgType1->szContentID);
6910 if (pMsgType1->szContentID[0] == '<' && pMsgType1->szContentID[length - 1] == '>') {
6911 pMsgType1->drmInfo.szContentURI = MsgStrNCopy(pMsgType1->szContentID + 1, length - 2);
6913 pMsgType1->drmInfo.szContentURI = MsgStrCopy(pMsgType1->szContentID);
6918 if (pMsgType1->szContentLocation[0] == '\0')
6919 strcpy(pMsgType1->szContentLocation, pMsgType2->szContentLocation);
6921 /* Copy informations - we shoud open the pMsgType2's orgFile
6922 * concerning its offset and size.
6924 if (pMsgType2->szOrgFilePath[0] != '\0')
6925 strcpy(pMsgType1->szOrgFilePath, pMsgType2->szOrgFilePath);
6927 if (pMsgType2->disposition != INVALID_HOBJ)
6928 pMsgType1->disposition = pMsgType2->disposition;
6930 if ((pMsgType1->type != MIME_APPLICATION_VND_OMA_DRM_MESSAGE && pMsgType1->type != MIME_APPLICATION_VND_OMA_DRM_CONTENT) &&
6931 pMsgType2->encoding != INVALID_HOBJ)
6932 pMsgType1->encoding = pMsgType2->encoding;
6934 pMsgType1->contentSize = pMsgType2->contentSize;
6935 pMsgType1->offset = pMsgType2->offset;
6936 pMsgType1->size = pMsgType2->size;
6937 pMsgType1->type = pMsgType2->type;
6939 MsgCopyNestedMsgParam(&(pMsgType1->param), &(pMsgType2->param));
6941 if (pMsgType1->param.szName[0]) {
6942 #ifdef __SUPPORT_DRM__
6943 pMsgType1->drmInfo.szContentName = MsgStrCopy(pMsgType2->param.szName);
6951 bool MsgCopyNestedMsgParam(MsgContentParam *pParam1, MsgContentParam *pParam2)
6953 if (pParam1->charset == MSG_CHARSET_UNKNOWN)
6954 pParam1->charset = pParam2->charset;
6956 if (pParam1->type == MIME_UNKNOWN)
6957 pParam1->type = pParam2->type;
6959 /* Don't copy pParam2->pPresentation */
6961 /* For alternative: copy the boundary string */
6962 if (pParam2->szBoundary[0] !='\0')
6963 strcpy(pParam1->szBoundary, pParam2->szBoundary);
6965 if (pParam1->szFileName[0] =='\0')
6966 strcpy(pParam1->szFileName, pParam2->szFileName);
6968 if (pParam1->szName[0] =='\0')
6969 strcpy(pParam1->szName, pParam2->szName);
6971 if (pParam1->szStart[0] =='\0')
6972 strcpy(pParam1->szStart, pParam2->szStart);
6974 if (pParam1->szStartInfo[0] =='\0')
6975 strcpy(pParam1->szStartInfo, pParam2->szStartInfo);
6980 bool MsgIsMultipartMixed(int type)
6982 if (type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED || type == MIME_MULTIPART_MIXED) {
6989 bool MsgStrcpyWithoutCRLF(char *pOrg, char **ppNew)
6997 nLen = strlen(pOrg);
6999 pDest = (char *)malloc(nLen + 1);
7001 if (pDest == NULL) {
7002 MSG_DEBUG("MsgStrcpyWithoutCRLF: malloc is failed\n");
7006 memset(pDest, 0 , (nLen + 1));
7008 for (i = 0; i < nLen ; i++) {
7010 if ((pOrg[i] == MSG_CH_CR && pOrg[i+1] == MSG_CH_LF && pOrg[i+2] == MSG_CH_TAB) ||
7011 (pOrg[i] == MSG_CH_CR && pOrg[i+1] == MSG_CH_LF && pOrg[i+2] == MSG_CH_SP)) {
7016 pDest[index++] = pOrg[i];
7023 bool MmsGetMsgAttrib(MmsMsgID msgID, MmsAttrib* pAttrib)
7025 MmsMsg *pMsg = NULL;
7027 memset(pAttrib, 0, sizeof(MmsAttrib));
7028 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
7029 memcpy(pAttrib, &(pMsg->mmsAttrib), sizeof(MmsAttrib));
7031 MSG_DEBUG("MmsGetMsgAttrib: msgID = %lu ---------------------\n", msgID);
7033 if ('\0' != pMsg->szTrID[0])
7034 MSG_DEBUG("szTrID = %s \n", pMsg->szTrID);
7040 bool __MsgIsInvalidFileNameChar(char ch)
7042 if ((ch == 0x5C /* \ */) ||
7043 (ch == 0x2F /* / */) ||
7044 (ch == 0x3A /* : */) ||
7045 (ch == 0x2A /* * */) ||
7046 (ch == 0x3F /* ? */) ||
7047 (ch == 0x22 /* " */) ||
7048 (ch == 0x3C /* < */) ||
7049 (ch == 0x3E /* > */) ||
7050 (ch == 0x7C /* | */))
7056 bool _MmsDataUpdateLastStatus(MmsMsg *pMsg)
7058 MmsMsgMultiStatus* pStatus = NULL;
7060 pStatus = pMsg->mmsAttrib.pMultiStatus;
7062 while (pStatus != NULL) {
7063 pStatus->bDeliveyrReportIsLast = false;
7064 pStatus->bReadReplyIsLast = false;
7065 pStatus = pStatus->pNext;
7072 bool MmsAddrUtilCompareAddr(char *pszAddr1, char *pszAddr2)
7078 MmsAddrUtilRemovePlmnString(pszAddr1);
7079 MmsAddrUtilRemovePlmnString(pszAddr2);
7081 MSG_DEBUG("##### pszAddr1 = %s #####", pszAddr1);
7082 MSG_DEBUG("##### pszAddr2 = %s #####", pszAddr2);
7083 if (!strcmp(pszAddr1, pszAddr2))
7086 len1 = strlen(pszAddr1);
7087 len2 = strlen(pszAddr2);
7090 p = strstr(pszAddr1, pszAddr2);
7092 p = strstr(pszAddr2, pszAddr1);
7101 int MsgGetLatin2UTFCodeSize(unsigned char *szSrc, int nChar)
7105 MSG_DEBUG("MsgGetLatin2UTFCodeSize: --------------- \n");
7107 if ((szSrc == NULL) || (nChar <= 0)) {
7108 MSG_DEBUG("MsgGetLatin2UTFCodeSize: szSrc is NULL !!!! --------------- \n");
7112 while ((nChar > 0) && (*szSrc != '\0')) {
7113 if (0x01 <= *szSrc && *szSrc <= 0x7F) {
7127 int MsgLatin5code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
7132 unsigned short temp = 0;
7135 outBufSize--; //Null Character
7137 while ((nChar > 0) && (*szSrc != '\0')) {
7139 if (*szSrc >= 0x01 && *szSrc <= 0x7F) { //basic common
7140 temp = (unsigned short)(*szSrc);
7146 *des = (unsigned char) ((*szSrc) & 0x007F);
7151 } else if ((*szSrc == 0x00) || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
7152 (*szSrc >= 0xA0 && *szSrc <= 0xCF) || (*szSrc >= 0xD1 && *szSrc <= 0xDC) ||
7153 (*szSrc >= 0xDF && *szSrc <= 0xEF) || (*szSrc >= 0xF1 && *szSrc <= 0xFC) ||
7154 (*szSrc == 0xFF)) {//uni 0x00A0 ~ 0x00CF
7156 temp = (unsigned short)(*szSrc);
7162 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7163 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7165 *des = 0xC0 | (t1 & 0x1F);
7166 *(des+1) = 0x80 | (t2 & 0x3F);
7171 } else if (*szSrc == 0xD0) {//empty section OR vendor specific codes.
7179 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7180 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7182 *des = 0xC0 | (t1 & 0x1F);
7183 *(des+1) = 0x80 | (t2 & 0x3F);
7188 } else if (*szSrc == 0xDD) {
7195 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7196 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7198 *des = 0xC0 | (t1 & 0x1F);
7199 *(des+1) = 0x80 | (t2 & 0x3F);
7204 } else if (*szSrc == 0xDE) {
7211 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7212 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7214 *des = 0xC0 | (t1 & 0x1F);
7215 *(des+1) = 0x80 | (t2 & 0x3F);
7220 } else if (*szSrc == 0xF0) {
7226 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7227 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7229 *des = 0xC0 | (t1 & 0x1F);
7230 *(des+1) = 0x80 | (t2 & 0x3F);
7235 } else if (*szSrc == 0xFD) {
7243 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7244 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7246 *des = 0xC0 | (t1 & 0x1F);
7247 *(des+1) = 0x80 | (t2 & 0x3F);
7252 } else if (*szSrc == 0xFE) {
7259 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7260 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7262 *des = 0xC0 | (t1 & 0x1F);
7263 *(des+1) = 0x80 | (t2 & 0x3F);
7277 int MsgGetLatin52UTFCodeSize(unsigned char *szSrc, int nChar)
7281 MSG_DEBUG("MsgGetLatin52UTFCodeSize: --------------- \n");
7283 if ((szSrc == NULL) || (nChar <= 0))
7286 while ((nChar > 0) && (*szSrc != '\0')) {
7287 if (*szSrc >= 0x01 && *szSrc <= 0x7F) {
7291 } else if (*szSrc == 0x00 || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
7292 (*szSrc >= 0xA0 && *szSrc <= 0xCF) || (*szSrc >= 0xD1 && *szSrc <= 0xDC) |
7293 (*szSrc >= 0xDF && *szSrc <= 0xEF) || (*szSrc >= 0xF1 && *szSrc <= 0xFC) ||
7294 *szSrc == 0xD0 || *szSrc == 0xDD || *szSrc == 0xDE || *szSrc == 0xF0 ||
7295 *szSrc == 0xFD || *szSrc == 0xFE || *szSrc == 0xFF) { //uni 0x00A0 ~ 0x00CF
7306 int MsgLatin2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
7309 unsigned char t1, t2;
7311 MSG_DEBUG("MsgLatin2UTF: --------------- \n");
7314 outBufSize--; // NULL character
7316 while ((nChar > 0) && (*szSrc != '\0')) {
7317 if (0x01 <= *szSrc && *szSrc <= 0x7F) {
7318 /* check outbuffer's room for this UTF8 character */
7324 *des = (unsigned char) (*szSrc & 0x007F);
7330 /* check outbuffer's room for this UTF8 character */
7336 t2 = (unsigned char) (*szSrc & 0x003F); // right most 6 bit
7337 t1 = (unsigned char) ((*szSrc & 0xC0) >> 6); // right most 2 bit
7339 *des = 0xC0 | (t1 & 0x1F);
7340 *(des + 1) = 0x80 | (t2 & 0x3F);
7355 int MsgLatin7code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
7361 unsigned short temp = 0;
7363 MSG_DEBUG("MsgUnicode2UTF: --------------- \n");
7366 outBufSize--; //Null Character
7368 while ((nChar > 0) && (*szSrc != '\0')) {
7369 if (*szSrc >= 0x01 && *szSrc <= 0x7F) {
7370 temp = (unsigned short)(*szSrc);
7376 *des = (unsigned char) (temp & 0x007F);
7382 } else if ((*szSrc == 0x00) || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
7383 (*szSrc >= 0xA3 && *szSrc <= 0xAD) || (*szSrc == 0xBB)) { // consider 0xA4, 0xA5
7385 temp = (unsigned short)(*szSrc);
7391 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7392 t1 = (unsigned char) ((temp & 0xC0) >> 6); // right most 2 bit
7394 *des = 0xC0 | (t1 & 0x1F);
7395 *(des + 1) = 0x80 | (t2 & 0x3F);
7400 } else if (*szSrc == 0xA0) {
7402 //*des = temp to utf-8
7407 *des = (unsigned char) (temp & 0x007F);
7413 } else if (*szSrc == 0xA1) {
7420 t3 = (unsigned char) (temp & 0x003F); // right most 6 bit
7421 t2 = (unsigned char) ((temp & 0x0FC0) >> 6); // right most 6 bit
7422 t1 = (unsigned char) ((temp & 0xF000) >> 12); // right most 4 bit
7424 *des = 0xE0 | (t1 & 0x0F);
7425 *(des+1) = 0x80 | (t2 & 0x3F);
7426 *(des+2) = 0x80 | (t3 & 0x3F);
7432 } else if (*szSrc == 0xA2) {
7439 t3 = (unsigned char) (temp & 0x003F); // right most 6 bit
7440 t2 = (unsigned char) ((temp & 0x0FC0) >> 6); // right most 6 bit
7441 t1 = (unsigned char) ((temp & 0xF000) >> 12); // right most 4 bit
7443 *des = 0xE0 | (t1 & 0x0F);
7444 *(des+1) = 0x80 | (t2 & 0x3F);
7445 *(des+2) = 0x80 | (t3 & 0x3F);
7451 } else if (*szSrc == 0xAF) {
7458 t3 = (unsigned char) (temp & 0x003F); // right most 6 bit
7459 t2 = (unsigned char) ((temp & 0x0FC0) >> 6); // right most 6 bit
7460 t1 = (unsigned char) ((temp & 0xF000) >> 12); // right most 4 bit
7462 *des = 0xE0 | (t1 & 0x0F);
7463 *(des+1) = 0x80 | (t2 & 0x3F);
7464 *(des+2) = 0x80 | (t3 & 0x3F);
7470 } else if (0xB0 <= *szSrc && *szSrc <= 0xB4) { //0x00B0 ~ 0x00B4
7472 temp = (unsigned short)(*szSrc);
7478 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7479 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7481 *des = 0xC0 | (t1 & 0x1F);
7482 *(des+1) = 0x80 | (t2 & 0x3F);
7488 } else if ((0xB5 <= *szSrc && *szSrc <= 0xBA) ||
7489 (0xBC <= *szSrc && *szSrc <= 0xD1) ||
7490 (0xD3 <= *szSrc && *szSrc <= 0xFE)) {
7491 temp= (unsigned short)(*szSrc + 0x02D0);
7497 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7498 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7500 *des = 0xC0 | (t1 & 0x1F);
7501 *(des+1) = 0x80 | (t2 & 0x3F);
7518 int MsgGetLatin72UTFCodeSize(unsigned char *szSrc, int nChar)
7522 MSG_DEBUG("MsgGetLatin72UTFCodeSize: --------------- \n");
7524 if ((szSrc == NULL) || (nChar <= 0))
7527 while ((nChar > 0) && (*szSrc != '\0')) {
7529 if ((*szSrc >= 0x01 && *szSrc <= 0x7F) || (*szSrc == 0xA0)) {
7533 } else if (*szSrc == 0x00 || (0x80 <= *szSrc && *szSrc <= 0x9F) || (0xA3 <= *szSrc && *szSrc <= 0xAD) ||
7534 (0xB0 <= *szSrc && *szSrc <= 0xB4) || (0xB5 <= *szSrc && *szSrc <= 0xFE)) {
7538 } else if (*szSrc == 0xA1 ||*szSrc == 0xA2 || *szSrc == 0xAF) {
7550 int MsgUnicode2UTF(unsigned char *des, int outBufSize, unsigned short *szSrc, int nChar)
7557 MSG_DEBUG("MsgUnicode2UTF: --------------- \n");
7560 outBufSize--; // NULL character
7562 while ((nChar > 0) && (*szSrc != '\0')) {
7563 if (0x0001 <= *szSrc && *szSrc <= 0x007F) {
7564 /* check outbuffer's room for this UTF8 character */
7570 *des = (unsigned char) (*szSrc & 0x007F);
7575 } else if ((*szSrc == 0x0000) || (0x0080 <= *szSrc && *szSrc <= 0x07FF)) {
7576 /* check outbuffer's room for this UTF8 character */
7582 t2 = (unsigned char) (*szSrc & 0x003F); // right most 6 bit
7583 t1 = (unsigned char) ((*szSrc & 0x07C0) >> 6); // right most 5 bit
7585 *des = 0xC0 | (t1 & 0x1F);
7586 *(des+1) = 0x80 | (t2 & 0x3F);
7592 /* check outbuffer's room for this UTF8 character */
7598 t3 = (unsigned char) (*szSrc & 0x003F); // right most 6 bit
7599 t2 = (unsigned char) ((*szSrc & 0x0FC0) >> 6); // right most 6 bit
7600 t1 = (unsigned char) ((*szSrc & 0xF000) >> 12); // right most 4 bit
7602 *des = 0xE0 | (t1 & 0x0F);
7603 *(des+1) = 0x80 | (t2 & 0x3F);
7604 *(des+2) = 0x80 | (t3 & 0x3F);
7618 int MsgGetUnicode2UTFCodeSize(unsigned short *szSrc, int nChar)
7622 MSG_DEBUG("MsgGetUnicode2UTFCodeSize: --------------- \n");
7624 if ((szSrc == NULL) || (nChar <= 0)) {
7625 MSG_DEBUG("MsgGetUnicode2UTFCodeSize: szSrc is NULL !!!! --------------- \n");
7629 while ((nChar > 0) && (*szSrc != '\0')) {
7630 if (0x0001 <= *szSrc && *szSrc <= 0x007F) {
7634 } else if ((*szSrc == 0x0000) || (0x0080 <= *szSrc && *szSrc <= 0x07FF)) {
7648 bool MmsAddrUtilCheckEmailAddress(char *pszAddr)
7650 if (!pszAddr || pszAddr[0] == 0)
7653 if (!strchr (pszAddr, MSG_MMS_CH_EMAIL_AT))
7659 bool MmsAddrUtilRemovePlmnString(char *pszAddr)
7661 char *pszAddrCopy = NULL;
7662 char *pszStrStart = NULL;
7663 char *pszStrTemp = NULL;
7666 if ((!pszAddr) || (pszAddr[0] == 0)) {
7667 MSG_DEBUG("MmsAddrUtilRemovePlmnString: pszAddr is null or zero\n");
7671 strLen = strlen(pszAddr);
7673 pszAddrCopy = (char*)malloc(strLen + 1);
7675 MSG_DEBUG("MmsAddrUtilRemovePlmnString: pszAddrCopy is NULL, mem alloc failed\n");
7679 strcpy(pszAddrCopy, pszAddr);
7683 pszStrStart = pszAddrCopy;
7686 char* pszStrEnd = NULL;
7689 if (MmsAddrUtilCheckEmailAddress(pszAddrCopy))
7690 pszStrEnd = strstr(pszStrStart, "/TYPE=PLMN");
7692 pszStrEnd = strstr(pszStrStart, "/");
7695 // "/TYPE=PLMN" not found
7697 int remainedLen = strlen(pszStrStart);
7699 if (remainedLen <= 0)
7702 strcat(pszAddr, pszStrStart);
7707 // Get one address length
7708 addressLen = pszStrEnd - pszStrStart;
7710 strncat(pszAddr, pszStrStart, addressLen);
7712 // Find next address
7713 pszStrStart = pszStrEnd;
7715 pszStrTemp = strstr(pszStrStart, MSG_MMS_STR_ADDR_DELIMETER);
7718 addressLen = pszStrTemp - pszStrEnd;
7719 pszStrStart += addressLen;
7721 pszStrStart += strlen(pszStrEnd);
7724 if (pszStrStart[0] == 0) // end of string
7728 strcat(pszAddr, MSG_MMS_STR_ADDR_DELIMETER); // add ';'
7729 pszStrStart++; // remove ';'
7732 if (pszAddr[0] == 0)
7733 strcpy(pszAddr, pszAddrCopy);
7740 int MsgCutUTFString(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
7744 MSG_DEBUG("MsgCutUTFString: --------------- \n");
7747 outBufSize--; // NULL character
7749 while ((nChar > 0) && (*szSrc != '\0')) {
7750 if (*szSrc < 0x80) {
7758 } else if (((0xC0 <= *szSrc) && (*szSrc < 0xE0)) && (*(szSrc+1) >= 0x80)) {
7764 *(des + 1) = *(szSrc + 1);
7768 } else if ((*szSrc >= 0xE0) && (*(szSrc+1) >= 0x80) && (*(szSrc+2) >= 0x80)) {
7774 *(des + 1) = *(szSrc + 1);
7775 *(des + 2) = *(szSrc + 2);
7787 MSG_DEBUG("MsgCutUTFString: utf8 incorrect range!\n");
7799 void MsgMIMERemoveQuote(char *szSrc)
7803 length = MsgStrlen(szSrc);
7804 if (szSrc[0] == MSG_CH_QUOT && szSrc[length-1] == MSG_CH_QUOT) {
7807 for (index = 0; index < length-2; index++)
7808 szSrc[index] = szSrc[index+1];
7809 szSrc[index] = '\0';
7813 bool MsgLoadDataToDecodeBuffer(FILE *pFile, char **ppBuf, int *pPtr, int *pOffset, char *pInBuf1, char *pInBuf2, int maxLen, int *pBufLen, int endOfFile)
7819 MSG_DEBUG("MsgLoadDataToDecodeBuffer: \n");
7821 if (pFile == NULL) {
7828 if (pPtr == NULL || pInBuf1 == NULL || pInBuf2 == NULL) {
7835 if (*pBufLen == 0) {
7836 length = maxLen - (*pPtr);
7838 length = (*pBufLen) - (*pPtr);
7844 if ((*ppBuf) == NULL) {
7845 memset(pInBuf1, 0, maxLen);
7847 } else if ((*ppBuf) == pInBuf1) {
7848 memset(pInBuf2, 0, maxLen);
7850 memcpy(pInBuf2, pInBuf1 + (*pPtr), length);
7853 memset(pInBuf1, 0, maxLen);
7855 memcpy(pInBuf1, pInBuf2 + (*pPtr), length);
7861 if (*pOffset == endOfFile) {
7866 if (maxLen == length) {
7868 if (MsgReadFileForDecode(pFile, (*ppBuf), maxLen, &nRead) == false)
7873 if (MsgReadFileForDecode(pFile, (*ppBuf) + length, maxLen - length, &nRead) == false)
7876 *pBufLen = length + nRead;
7879 if ((*pOffset = MsgFtell(pFile)) == -1L) {
7880 MSG_DEBUG("MsgFtell Error");
7890 bool MsgGetTypeByFileName(int *type, char *szFileName)
7893 AvCodecType AvType = AV_CODEC_NONE;
7895 pExt = strrchr(szFileName, '.');
7896 if (pExt == NULL || pExt[0] == '\0')
7901 if (strcasecmp(pExt, "mp4") == 0 ||strcasecmp(pExt, "mpeg4") == 0 ||strcasecmp(pExt, "3gp") == 0 ||strcasecmp(pExt, "3gpp") == 0) {
7903 if (szFileName[0] != '/')
7906 AvType = AvGetFileCodecType(szFileName);
7907 MSG_DEBUG("MsgGetTypeByFileName:AvType(0x%x)\n", AvType);
7910 case AV_DEC_AUDIO_MPEG4:
7911 *type = MIME_AUDIO_MP4;
7914 case AV_DEC_VIDEO_MPEG4:
7915 *type = MIME_VIDEO_MP4;
7919 *type = MIME_VIDEO_3GPP;
7925 if (strcasecmp(pExt, "amr") == 0) {
7926 *type = MIME_AUDIO_AMR;
7928 } else if ((strcasecmp(pExt, "mid") == 0) || (strcasecmp(pExt, "midi") == 0)) {
7929 *type = MIME_AUDIO_MIDI;
7931 } else if (strcasecmp(pExt, "imy") == 0) {
7932 *type = MIME_TEXT_X_IMELODY;
7936 *type = MimeGetMimeFromExtInt((const char*)pExt);
7937 MSG_DEBUG("MsgGetTypeByFileName: szFileName = %s type = %d \n", szFileName, type);
7943 *type = MIME_UNKNOWN;
7944 MSG_DEBUG("MsgGetTypeByFileName: szFileName = %s type = %d \n", szFileName, type);
7952 * This function write media data from raw data to file.
7955 * @param pszMailboxPath : path of mailbox
7956 * @param pszMsgFilename : name of msg file
7957 * @param index : used for file naming
7958 * @param bSave : if true, file will be save otherwise just filename will be stored.
7960 bool _MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody, char *pszMailboxPath, char *pszMsgFilename, int index, bool bSave)
7964 char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, }; // file name of temp file
7965 char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, }; // full absolute path of temp file.
7967 MSG_DEBUG("**** _MmsSaveMediaData: [Multi part] START ***\n");
7970 MSG_DEBUG("pPartType is NULL\n");
7971 return true; // why true value is retured ??? ; false;
7974 if (pPartType->param.szName[0] == '\0' && pPartType->param.szFileName[0] == '\0')
7975 strcpy(pPartType->param.szName, pPartType->param.szFileName);
7977 if (pPartType->param.szName) {
7978 strcpy(szFileName, pPartType->param.szName);
7980 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%lu", (unsigned long)index);
7984 #ifndef __SUPPORT_DRM__
7985 MsgMakeFileName(pPartType->type, szFileName, 0); //FL & CD -> extension(.dm) SD -> extension(.dcf)
7987 MsgMakeFileName(pPartType->type, szFileName, pPartType->drmInfo.drmType, 0); //FL & CD -> extension(.dm) SD -> extension(.dcf)
7988 if (MsgDRMIsForwardLockType(pPartType->drmInfo.drmType))
7989 MsgChangeDrm2FileName(szFileName);
7993 snprintf(szFullPath, MSG_FILEPATH_LEN_MAX, "%s%s.dir/%s", pszMailboxPath, pszMsgFilename, szFileName); // get absolute path of each temp file of each part
7994 snprintf(pPartType->param.szFileName, MSG_FILENAME_LEN_MAX+1, "%s.dir/%s", pszMsgFilename, szFileName); // store relative path of each temp file of each part including sub folder.
7996 if (pPartType->type == MIME_APPLICATION_OCTET_STREAM)
7997 MsgGetTypeByFileName(&pPartType->type, szFullPath);
8001 if ((pFile = MsgOpenFile(szFullPath, "wb+")) == NULL) {
8002 MSG_DEBUG("MsgOpenFile failed");
8006 if (MmsGetMediaPartData(pPartType, pPartBody, pFile) == false) {
8007 MSG_DEBUG("MmsGetMediaPartData fail [index:%d]\n", index);
8011 MsgCloseFile(pFile);
8013 if (pPartType->drmInfo.drmType != MSG_DRM_TYPE_NONE) {
8014 MsgDrmRegisterFile(MSG_MODE_FILE, szFullPath, strlen(szFullPath));
8016 /* change szDrm2FullPath as current content path*/
8017 if (pPartType->drmInfo.szDrm2FullPath) {
8018 free(pPartType->drmInfo.szDrm2FullPath);
8019 pPartType->drmInfo.szDrm2FullPath = MsgStrCopy(szFullPath);
8024 MSG_DEBUG("**** MmsGetMediaPartData: [Multi part] E N D (Successfully) ***\n");
8030 if (pFile != NULL) {
8031 MsgCloseFile(pFile);
8040 bool MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE* pFile)
8045 char *pNewData = NULL;
8046 char *pTempData = NULL;
8047 int msgEncodingValue = 0;
8048 int msgTypeValue = 0;
8049 int msgCharsetValue = 0;
8055 msgEncodingValue = pPartType->encoding;
8056 msgTypeValue = pPartType->type;
8057 msgCharsetValue = pPartType->param.charset;
8059 cidLen = MsgStrlen(szCid);
8061 offset = pPartBody->offset;
8062 size = pPartBody->size;
8064 if (pPartBody->szOrgFilePath[0]) {
8065 pTempData = MsgOpenAndReadMmsFile(pPartBody->szOrgFilePath, offset, size, &nRead);
8067 if (pTempData == NULL) {
8068 MSG_DEBUG("MmsGetMediaPartData : pTempData read fail\n");
8073 } else if (pPartBody->body.pText) {
8074 pData = pPartBody->body.pText;
8075 nRead = pPartBody->size;
8078 if (pData == NULL) {
8079 MSG_DEBUG("MmsGetMediaPartData : there is no data \n");
8083 pNewData = MmsGetBinaryUTF8Data(pData, nRead, msgEncodingValue, msgTypeValue, msgCharsetValue, &nRead2);
8084 pPartType->encoding = MSG_ENCODING_BINARY;
8086 if (MsgIsText(msgTypeValue))
8087 pPartType->param.charset = MSG_CHARSET_UTF8;
8089 if (MsgWriteFile(pNewData, sizeof(char), nRead2, pFile) != (size_t)nRead2) {
8090 MSG_DEBUG("MmsGetMediaPartData: file writing fail \n");
8124 char *MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue, int msgTypeValue, int msgCharsetValue, int *npRead)
8130 unsigned short *mszTempStr = NULL;
8131 char *pConvertedStr = NULL;
8132 char *pConvertedData = NULL;
8133 char *pNewData = NULL;
8134 char *pReturnData = NULL;
8137 switch (msgEncodingValue) {
8138 case MSG_ENCODING_BASE64:
8140 pConvertedData = (char*)_MsgDecodeBase64((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
8141 MSG_DEBUG("MmsGetBinaryUTF8Data : MSG_ENCODING_BASE64 bodyLength = %d \n", nByte);
8143 pTemp = pConvertedData;
8148 case MSG_ENCODING_QUOTE_PRINTABLE:
8150 pConvertedData = (char*)_MsgDecodeQuotePrintable((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
8151 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_ENCODING_QUOTE_PRINTABLE bodyLength = %d \n", nByte);
8153 pTemp = pConvertedData;
8160 MSG_DEBUG("MmsGetBinaryUTF8Data: 8bit OR Binary bodyLength = %d \n", nRead);
8168 if (MsgIsText(msgTypeValue)) {
8169 /* charset converting */
8171 switch (msgCharsetValue) {
8172 case MSG_CHARSET_UTF16:
8173 case MSG_CHARSET_USC2:
8175 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_USC2 \n");
8177 if (((UINT8)pTemp[0]) == 0xFF && ((UINT8)pTemp[1]) == 0xFE) {
8178 nChar = (nTemp / 2 - 1);
8180 mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
8181 if (mszTempStr == NULL) {
8182 MSG_DEBUG("MmsGetBinaryUTF8Data : 1. Memory Full !!! \n");
8186 memcpy(mszTempStr, ((unsigned short*)pTemp + 1), nChar * sizeof(unsigned short));
8188 nByte = MsgGetUnicode2UTFCodeSize(((unsigned short*)pTemp + 1), nChar);
8190 pConvertedStr = (char *)malloc(nByte + 1);
8191 if (pConvertedStr != NULL)
8192 MsgUnicode2UTF ((unsigned char*)pConvertedStr, nByte + 1, mszTempStr, nChar);
8194 nChar = (nTemp / 2);
8196 mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
8197 if (mszTempStr == NULL) {
8198 MSG_DEBUG("MmsGetBinaryUTF8Data: 2. Memory Full !!! \n");
8202 memcpy(mszTempStr, ((unsigned short*)pTemp), nChar * sizeof(unsigned short));
8204 nByte = MsgGetUnicode2UTFCodeSize(((unsigned short*)pTemp), nChar);
8206 pConvertedStr = (char *)malloc(nByte + 1);
8208 MsgUnicode2UTF ((unsigned char*)pConvertedStr, nByte + 1, mszTempStr, nChar);
8211 if (pConvertedStr != NULL)
8212 pNewData = pConvertedStr;
8214 *npRead = nByte + 1;
8218 case MSG_CHARSET_US_ASCII:
8220 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_US_ASCII \n");
8224 case MSG_CHARSET_UTF8:
8226 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_UTF8 or Others \n");
8228 // skip BOM (Byte Order Mark) bytes .. (Please refer to the http://www.unicode.org/faq/utf_bom.html#BOM)
8230 if (((UINT8)pTemp[0]) == 0xEF && ((UINT8)pTemp[1]) == 0xBB && ((UINT8)pTemp[2]) == 0xBF) {
8240 case MSG_CHARSET_ISO_8859_7:
8244 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_ISO_8859_7 \n");
8246 nByte = MsgGetLatin72UTFCodeSize((unsigned char*)pTemp, nTemp);
8247 pConvertedStr = (char *)malloc(nByte + 1);
8249 MsgLatin7code2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTemp, nTemp);
8251 pNewData = pConvertedStr;
8252 *npRead = nByte + 1;
8256 case MSG_CHARSET_ISO_8859_9:
8259 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_ISO_8859_9 \n");
8261 nByte = MsgGetLatin52UTFCodeSize((unsigned char*)pTemp, nTemp);
8262 pConvertedStr = (char *)malloc(nByte + 1);
8264 MsgLatin5code2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTemp, nTemp);
8266 pNewData = pConvertedStr;
8267 *npRead = nByte + 1;
8273 MSG_DEBUG("MmsGetBinaryUTF8Data: Other charsets \n");
8275 nByte = MsgGetLatin2UTFCodeSize((unsigned char*)pTemp, nTemp);
8276 pConvertedStr = (char *)malloc(nByte + 1);
8278 MsgLatin2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTemp, nTemp);
8280 pNewData = pConvertedStr;
8281 *npRead = nByte + 1;
8290 pReturnData = (char *)malloc(*npRead);
8291 if (pReturnData == NULL) {
8292 MSG_DEBUG("MmsGetBinaryUTF8Data : pReturnData alloc fail. \n");
8297 if (pNewData != NULL) {
8298 memset(pReturnData, 0, *npRead);
8299 memcpy(pReturnData, pNewData, *npRead);
8302 if (pConvertedData) {
8303 free(pConvertedData);
8304 pConvertedData = NULL;
8307 if (pConvertedStr) {
8308 free(pConvertedStr);
8309 pConvertedStr = NULL;
8321 if (pConvertedData) {
8322 free(pConvertedData);
8323 pConvertedData = NULL;
8326 if (pConvertedStr) {
8327 free(pConvertedStr);
8328 pConvertedStr = NULL;
8339 #ifndef __SUPPORT_DRM__
8340 bool MsgMakeFileName(int iMsgType, char *szFileName, int nUntitleIndex)
8342 char szText[MSG_FILENAME_LEN_MAX+1]={0,};
8343 char szTemp[MSG_FILENAME_LEN_MAX+1]={0,};
8344 char szTempFileName[MSG_FILENAME_LEN_MAX+1]={0,};
8348 MSG_DEBUG("MsgMakeFileName: iMsgType = %d szFileName = %s \n", iMsgType, szFileName);
8350 if (szFileName == NULL)
8353 if (szFileName && (szFileName[0] != '\0')) {
8354 MsgGetFileNameWithoutExtension (szTempFileName, szFileName);
8356 pExt = strrchr(szTempFileName, '.');
8358 memset (szText, 0, MSG_FILENAME_LEN_MAX+1);
8359 strncpy(szText, szTempFileName, MSG_FILEPATH_LEN_MAX - 1);
8360 strcat(szText, "."); // add '.'
8362 memset (szText, 0, MSG_FILENAME_LEN_MAX+1);
8363 strncpy(szText, szTempFileName, pExt+1 - szFileName); // add '.'
8366 if (nUntitleIndex >= 1) {
8367 snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s_%d.", "Untitled", nUntitleIndex);
8369 snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s.", "Untitled");
8373 if (iMsgType == MIME_APPLICATION_OCTET_STREAM) {
8374 MSG_DEBUG("MsgMakeFileName: unsupported MsgType\n");
8378 strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
8379 if (iMsgType == MIME_UNKNOWN || (pExt = MimeGetExtFromMimeInt((MimeType)iMsgType)) == NULL) {
8380 MSG_DEBUG("MsgMakeFileName: Failed to get extension of that mime data file. \n");
8383 nLen = MSG_FILENAME_LEN_MAX - strlen(szTemp);
8384 strncat(szTemp, pExt, nLen);
8388 strcpy(szFileName, szTemp);
8390 MSG_DEBUG("MsgMakeFileName: made szFileName = %s \n", szFileName);
8397 p = strrchr(szText, '.');
8400 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", szText);
8406 bool MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex)
8408 char szText[MSG_FILENAME_LEN_MAX+1]={0,};
8409 char szTemp[MSG_FILENAME_LEN_MAX+1]={0,};
8410 char szTempFileName[MSG_FILENAME_LEN_MAX+1]={0,};
8413 MSG_DEBUG("MsgMakeFileName: iMsgType = 0x%x, drmType = %d, szFileName = %s \n", iMsgType, drmType, szFileName);
8415 if (szFileName == NULL)
8418 if (szFileName && (szFileName[0] != '\0')) {
8419 MsgGetFileNameWithoutExtension (szTempFileName, szFileName);
8421 if (drmType != MSG_DRM_TYPE_NONE) {
8422 pExt = strrchr(szTempFileName, '.');
8424 memset(szText, 0, MSG_FILENAME_LEN_MAX+1);
8425 strncpy(szText, szTempFileName, MSG_FILENAME_LEN_MAX - 1);
8426 strcat(szText, "."); // add '.'
8428 memset(szText, 0, MSG_FILENAME_LEN_MAX+1);
8429 strncpy(szText, szTempFileName, pExt+1 - szFileName);
8432 if (strrchr(szTempFileName, '.'))
8435 memset(szText, 0, MSG_FILENAME_LEN_MAX+1);
8436 strncpy(szText, szTempFileName, MSG_FILENAME_LEN_MAX - 1);
8437 //temporary commented to save file as original name.
8438 pExt = strrchr(szFileName, '.');
8441 if (nUntitleIndex >= 1) {
8442 snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s_%d.", "untitled", nUntitleIndex);
8444 snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s.", "untitled");
8448 if (drmType == MSG_DRM_TYPE_SD) {
8449 strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
8450 strcat(szTemp, "dcf");
8451 } else if (MsgDRMIsForwardLockType(drmType)) {
8452 strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 4);
8453 strcat(szTemp, "dm");
8455 if (iMsgType == MIME_APPLICATION_OCTET_STREAM) {
8456 MSG_DEBUG("MsgMakeFileName: unsupported MsgType\n");
8460 strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
8461 //temporary commented to save file as original name.
8464 if (iMsgType == MIME_UNKNOWN || (pExt = MimeGetExtFromMimeInt((MimeType)iMsgType)) == NULL) {
8465 MSG_DEBUG("MsgMakeFileName: Failed to get extension of that mime data file. \n");
8470 nLen = MSG_FILENAME_LEN_MAX - strlen(szTemp);
8471 strncat(szTemp, pExt, nLen);
8475 strcpy(szFileName, szTemp);
8477 MSG_DEBUG("MsgMakeFileName: made szFileName = %s \n", szFileName);
8484 p = strrchr(szText, '.');
8487 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", szText);
8494 bool MsgGetFileNameWithoutExtension (char *szOutputName, char *szName)
8496 char *pszExt = NULL;
8498 if (szOutputName == NULL) {
8499 MSG_DEBUG("szOutputName is NULL");
8503 strncpy(szOutputName, szName, strlen(szName));
8505 if ((pszExt = strrchr(szOutputName, '.'))) {
8506 if (pszExt[0] == '.')
8513 int MmsGetMediaPartCount(MSG_MESSAGE_ID_T msgId)
8517 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
8519 if (msgId != pMsg->msgID) {
8520 MSG_DEBUG("Invalid Message Id");
8524 return pMsg->nPartCount;
8527 bool MmsGetMediaPartHeader(int index, MsgType *pHeader)
8529 MmsMsg *pMsg = NULL;
8530 MsgMultipart *pPart = NULL;
8532 if (pHeader == NULL) {
8533 MSG_DEBUG("MmsGetMediaPartHeader: Invalid pHeader input. It's null \n");
8537 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
8539 _MsgInitMsgType(pHeader);
8542 /* Requires header of non-presentation */
8543 if (MsgIsMultipart(pMsg->msgType.type)) {
8544 MSG_DEBUG("MmsGetMediaPartHeader: Multipart header [index = %d] \n", index);
8546 pPart = pMsg->msgBody.body.pMultipart;
8548 while (pPart && index--)
8549 pPart = pPart->pNext;
8551 if (pPart == NULL) {
8552 MSG_DEBUG("MmsGetMediaPartHeader: There is no such msg part.\n");
8556 memcpy(pHeader, &pPart->type, sizeof(MsgType));
8558 MSG_DEBUG("MmsGetMediaPartHeader: Requires singlepart header \n");
8559 memcpy(pHeader, &pMsg->msgType, sizeof(MsgType));
8565 bool MmsDebugPrintMulitpartEntry(MsgMultipart *pMultipart, int index)
8567 MSG_DEBUG("------------------------------\n");
8568 MSG_DEBUG("%dth multipart info\n", index);
8569 MSG_DEBUG("header size=%d\n", pMultipart->type.size);
8570 MSG_DEBUG("body size=%d\n", pMultipart->type.contentSize);
8571 MSG_DEBUG("content type=%s\n", MmsDebugGetMimeType((MimeType)pMultipart->type.type));
8572 MSG_DEBUG("content ID=%s\n", pMultipart->type.szContentID);
8573 MSG_DEBUG("content location=%s\n", pMultipart->type.szContentLocation);
8575 if (pMultipart->type.type == MIME_TEXT_PLAIN) {
8576 MSG_DEBUG("text info\n");
8577 MSG_DEBUG("charset=%d\n", pMultipart->type.param.charset);
8578 MSG_DEBUG("text file name=%s\n", pMultipart->type.param.szName);
8580 #ifdef __SUPPORT_DRM__
8581 if (pMultipart->type.drmInfo.drmType != MSG_DRM_TYPE_NONE) {
8582 MSG_DEBUG("drm info\n");
8583 MSG_DEBUG("drm type=%d (0: NONE 1: Fowward Lock, 2:Combined Delivery, 3: Separated Delivery)\n", pMultipart->type.drmInfo.drmType);
8584 MSG_DEBUG("drm content type=%s\n", MmsDebugGetMimeType((MimeType)pMultipart->type.drmInfo.contentType));
8585 MSG_DEBUG("drm content URI=%s\n", pMultipart->type.drmInfo.szContentURI);
8586 MSG_DEBUG("drm2FullPath=%s\n", pMultipart->type.drmInfo.szDrm2FullPath);
8589 MSG_DEBUG("------------------------------\n");