2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include "MsgException.h"
25 #include "MmsPluginMessage.h"
26 #include "MmsPluginStorage.h"
27 #include "MsgUtilFile.h"
28 #include "MmsPluginCodec.h"
29 #include "MmsPluginDebug.h"
30 #include "MsgSettingTypes.h"
31 #include "MsgSettingHandler.h"
32 #include "MmsPluginInternal.h"
33 #include "MmsPluginAvCodec.h"
34 #include "MmsPluginStorage.h"
35 #include "MmsPluginSmil.h"
36 #ifdef __SUPPORT_DRM__
37 #include "MmsPluginDrm.h"
38 #include "MsgDrmWrapper.h"
40 #include "MmsPluginTextConvert.h"
41 #include "MmsPluginUtil.h"
43 static bool _MmsBinaryDecodeGetBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength); /* bufLen < gMmsDecodeMaxLen */
44 static bool _MmsBinaryDecodeGetLongBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength); /* no bufLen limit */
45 static bool _MmsBinaryDecodeGetOneByte(FILE *pFile, UINT8 *pOneByte, int totalLength);
47 static int __MmsBinaryDecodeUintvar(FILE *pFile, UINT32 *pUintVar, int totalLength);
48 static int __MmsDecodeValueLength(FILE *pFile, UINT32 *pValueLength, int totalLength);
49 static int __MmsDecodeValueLength2(FILE *pFile, UINT32 *pValueLength, int totalLength);
50 static int __MmsBinaryDecodeQuotedString(FILE *pFile, char *szBuff, int bufLen, int totalLength);
51 static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen, int totalLength);
52 static bool __MmsBinaryDecodeInteger(FILE *pFile, UINT32 *pInteger, int *pIntLen, int totalLength);
53 static bool __MmsBinaryDecodeCharset(FILE *pFile, UINT32 *nCharSet, int *pCharSetLen, int totalLength);
54 static char *__MmsBinaryDecodeText2(FILE *pFile, int totalLength, int *pLength);
55 static int __MmsBinaryDecodeText(FILE *pFile, char *szBuff, int bufLen, int totalLength);
56 static UINT32 __MmsHeaderDecodeIntegerByLength(FILE *pFile, UINT32 length, int totalLength);
57 static bool __MmsDecodeLongInteger(FILE *pFile, UINT32 *pLongInteger, int totalLength);
58 static int __MmsDecodeGetFilename(FILE *pFile, char *szBuff, int bufLen, int totalLength);
59 static MsgHeaderAddress *__MmsDecodeEncodedAddress(FILE *pFile, int totalLength);
61 #ifdef __SUPPORT_DRM__
62 bool __MmsParseDCFInfo(FILE *pFile, MsgDRMInfo *pDrmInfo, int totalLength);
63 bool __MmsParseDCFHdr(FILE *pFile, MsgDRMInfo *pDrmInfo, UINT32 headerLen, int totalLength);
64 bool MmsBinaryDecodeDRMMessage(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int fullBodyLength, int totalLength);
65 bool MmsBinaryDecodeDRMContent(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int bodyLength, int totalLength);
68 static bool MmsBinaryDecodeMovePointer(FILE *pFile, int offset, int totalLength);
69 bool MmsBinaryIsTextEncodedPart(FILE *pFile, int totalLength);
70 static bool __MmsBinaryDecodeCheckAndDecreaseLength(int *pLength, int valueLength);
72 bool __MmsTextDecodeMsgHeader(FILE *pFile);
73 bool MmsTextDecodeMsgBody(FILE *pFile);
75 char gszMmsLoadBuf1[MSG_MMS_DECODE_BUFFER_MAX + 1] = {0, };
76 char gszMmsLoadBuf2[MSG_MMS_DECODE_BUFFER_MAX + 1] = {0, };
78 static char *gpCurMmsDecodeBuff = NULL;
79 static int gCurMmsDecodeBuffPos = 0; /* next decoding position in gpCurMmsDecodeBuff */
80 static int gMmsDecodeMaxLen = 0;
81 static int gMmsDecodeCurOffset = 0; /* current offset in file (last read) */
82 static int gMmsDecodeBufLen = 0; /* number of last read characters */
84 static char *gpMmsDecodeBuf1 = NULL;
85 static char *gpMmsDecodeBuf2 = NULL;
93 (MmsMsgType)MMS_MSGTYPE_ERROR, //MmsMsgType iType;
95 //"", //short int version;
96 0, //short int version;
99 NULL, //MsgHeaderAddress* pFrom;
100 NULL, //MsgHeaderAddress* pTo;
101 NULL, //MsgHeaderAddress* pCc;
102 NULL, //MsgHeaderAddress* pBcc;
103 "", //char[] szSubject;
104 (MmsResponseStatus)MMS_RESPSTATUS_OK, //MmsResponseStatus iResponseStatus;
105 (MmsRetrieveStatus)MMS_RETRSTATUS_OK, //MmsRetrieveStatus iRetrieveStatus;
106 "", //char[] szResponseText;
107 "", //char[] szRetrieveText;
110 /* has default value in specification */
112 (MmsMsgClass)MMS_MSGCLASS_PERSONAL, //MmsMsgClass msgClass;
113 {MMS_TIMETYPE_RELATIVE, 0}, //MmsTimeStruct expiryTime;
114 {MMS_TIMETYPE_RELATIVE, 0}, //MmsTimeStruct deliveryTime;
115 (MmsPriority)MMS_PRIORITY_NORMAL, //MmsPriority priority; // Refer [OMA-MMS-ENC-v1_2-20030915-C]
116 (MmsSenderVisible)MMS_SENDER_SHOW, //MmsSenderVisible senderVisible;
117 (MmsReport)MMS_REPORT_NO, //MmsReport deliveryReport;
118 (MmsReport)MMS_REPORT_NO, //MmsReport readReply;
119 (MmsReportAllowed)MMS_REPORTALLOWED_NO,//MmsReportAllowed iReportAllowed;
120 "", //char[] szContentLocation;
123 /* there is no right default value */
125 (msg_delivery_report_status_t)MSG_DELIVERY_REPORT_NONE, //MmsMsgStatus iMsgStatus;
126 (msg_read_report_status_t)MSG_READ_REPORT_NONE, //MmsReadStatus readStatus;
128 /* MMS v1.1 ReplyCharge */
130 (MmsReplyChargeType)MMS_REPLY_NONE, //MmsReplyChargeType chargeType;
131 {MMS_TIMETYPE_RELATIVE, 0}, //MmsTimeStruct deadLine;
133 "" , //char szChargeID;
136 "", //char[] szMsgID;
140 #ifdef __SUPPORT_DRM__
142 #define MMS_DRM2_CONVERT_BUFFER_MAX 4*1024
143 const UINT32 MMS_UINTVAR_LENGTH_1 = 0x0000007f; //7bit
144 const UINT32 MMS_UINTVAR_LENGTH_2 = 0x00003fff; //14bit
145 const UINT32 MMS_UINTVAR_LENGTH_3 = 0x001fffff; //21bit
150 bool _MmsDecodeInitialize(void)
152 MmsInitMsgType(&mmsHeader.msgType);
153 MmsInitMsgBody(&mmsHeader.msgBody);
158 bool __MmsSetMmsHeaderOwner(int msgID, char* pszNewOwner)
162 MSG_DEBUG("__MmsSetMmsHeaderOwner: set (%s, msgID=%d)\n", pszNewOwner, msgID);
164 if ((mmsHeader.pszOwner = (char*)malloc(strlen(pszNewOwner) + 1)) == NULL)
167 memset (mmsHeader.pszOwner, 0, strlen(pszNewOwner) + 1) ;
169 strcpy(mmsHeader.pszOwner, pszNewOwner);
170 mmsHeader.bActive = true;
171 mmsHeader.msgID = msgID;
173 // delete current owner
174 if (mmsHeader.pszOwner) {
175 MSG_DEBUG("__MmsSetMmsHeaderOwner: free (%s %d)\n", mmsHeader.pszOwner, msgID);
176 free(mmsHeader.pszOwner);
177 mmsHeader.pszOwner = NULL;
179 mmsHeader.bActive = false;
180 mmsHeader.msgID = -1;
187 void _MmsInitHeader()
189 mmsHeader.type = MMS_MSGTYPE_ERROR;
191 memset(mmsHeader.szTrID, 0, MMS_TR_ID_LEN + 1);
192 mmsHeader.version = MMS_VERSION;
195 MsgFreeHeaderAddress(mmsHeader.pFrom);
196 MsgFreeHeaderAddress(mmsHeader.pTo);
197 MsgFreeHeaderAddress(mmsHeader.pCc);
198 MsgFreeHeaderAddress(mmsHeader.pBcc);
200 mmsHeader.pFrom = NULL;
201 mmsHeader.pTo = NULL;
202 mmsHeader.pCc = NULL;
203 mmsHeader.pBcc = NULL;
205 memset(mmsHeader.szSubject, 0, MSG_LOCALE_SUBJ_LEN + 1);
207 mmsHeader.responseStatus = (MmsResponseStatus)MMS_RESPSTATUS_OK;
208 mmsHeader.retrieveStatus = (MmsRetrieveStatus)MMS_RETRSTATUS_OK;
209 memset(mmsHeader.szResponseText, 0, MMS_LOCALE_RESP_TEXT_LEN + 1);
210 memset(mmsHeader.szRetrieveText, 0, MMS_LOCALE_RESP_TEXT_LEN + 1);
213 mmsHeader.msgClass = (MmsMsgClass)MMS_MSGCLASS_PERSONAL;
214 mmsHeader.expiryTime.type = MMS_TIMETYPE_RELATIVE;
215 mmsHeader.expiryTime.time = 0;
216 mmsHeader.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
217 mmsHeader.deliveryTime.time = 0;
218 mmsHeader.priority = (MmsPriority)MMS_PRIORITY_NORMAL; // Refer [OMA-MMS-ENC-v1_2-20030915-C]
219 mmsHeader.hideAddress =(MmsSenderVisible)MMS_SENDER_SHOW;
220 mmsHeader.deliveryReport = (MmsReport)MMS_REPORT_NO;
221 mmsHeader.readReply = (MmsReport)MMS_REPORT_NO;
222 mmsHeader.reportAllowed = (MmsReportAllowed)MMS_REPORTALLOWED_YES;
223 memset(mmsHeader.szContentLocation, 0, MMS_LOCATION_LEN + 1);
226 mmsHeader.msgStatus = (msg_delivery_report_status_t)MSG_DELIVERY_REPORT_NONE;
227 mmsHeader.readStatus = (msg_read_report_status_t)MSG_READ_REPORT_NONE;
229 mmsHeader.replyCharge.chargeType = (MmsReplyChargeType)MMS_REPLY_NONE;
230 mmsHeader.replyCharge.chargeSize = 0;
231 mmsHeader.replyCharge.deadLine.type = MMS_TIMETYPE_RELATIVE;
232 mmsHeader.replyCharge.deadLine.time = 0;
233 memset(mmsHeader.replyCharge.szChargeID, 0, MMS_MSG_ID_LEN + 1);
236 memset(mmsHeader.szMsgID, 0, MMS_MSG_ID_LEN + 1);
237 mmsHeader.msgSize = 0;
238 #ifdef __SUPPORT_DRM__
239 mmsHeader.drmType = MSG_DRM_TYPE_NONE;
242 _MmsDecodeInitialize();
247 void _MmsCleanDecodeBuff(void)
249 memset(gpMmsDecodeBuf1, 0, gMmsDecodeMaxLen + 1);
250 memset(gpMmsDecodeBuf2, 0, gMmsDecodeMaxLen + 1);
251 gpCurMmsDecodeBuff = NULL;
252 gCurMmsDecodeBuffPos = 0;
253 gMmsDecodeBufLen = 0;
257 void _MmsRegisterDecodeBuffer(char *pInBuff1, char *pInBuff2, int maxLen)
259 gpMmsDecodeBuf1 = pInBuff1;
260 gpMmsDecodeBuf2 = pInBuff2;
261 gpCurMmsDecodeBuff = NULL;
262 gCurMmsDecodeBuffPos = 0;
263 gMmsDecodeMaxLen = maxLen;
264 gMmsDecodeCurOffset = 0;
265 gMmsDecodeBufLen = 0;
268 void _MmsUnregisterDecodeBuffer(void)
270 gpMmsDecodeBuf1 = NULL;
271 gpMmsDecodeBuf2 = NULL;
272 gpCurMmsDecodeBuff = NULL;
273 gCurMmsDecodeBuffPos = 0;
274 gMmsDecodeMaxLen = 0;
275 gMmsDecodeCurOffset = 0;
276 gMmsDecodeBufLen = 0;
280 int _MmsGetDecodeOffset(void)
282 return (gMmsDecodeCurOffset - gMmsDecodeBufLen + gCurMmsDecodeBuffPos);
286 static bool __MmsBinaryDecodeCheckAndDecreaseLength(int *pLength, int valueLength)
288 if (*pLength <= valueLength) {
289 gCurMmsDecodeBuffPos -= valueLength;
290 gCurMmsDecodeBuffPos += *pLength;
294 *pLength -= valueLength;
300 /* ==========================================================
302 B I N A R Y D E C O D I N G
304 ==========================================================*/
307 * Binary Encoded Message Format
309 * < Single Part Body Message >
310 * -----------------------------------
312 * -----------------------------------
313 * | Content Type:start=xxx;type=xxx | ->(ex) Text/Plain, Text/Html, ....
314 * -----------------------------------
315 * | Single Part Body |
316 * -----------------------------------
318 * < Multi Part Body Message >
319 * -----------------------------------
321 * -----------------------------------
322 * | Content Type:start=xxx;type=xxx | -> (ex) Application/vnd.wap.multipart.mixed(related), multipart/mixed(related)
323 * -----------------------------------
324 * | # of Entries (body parts) |
325 * ----------------------------------- < Each Entry >
326 * | Entry 1 | -> -----------------------------
327 * ----------------------------------- | header Length |
328 * | Entry 2 | -----------------------------
329 * ----------------------------------- | Data Length |
330 * | ...... | ----------------------------- -
331 * ----------------------------------- | Content-Type | |
332 * | Entry n | ----------------------------- | Header Length
333 * ----------------------------------- | Header | |
334 * ----------------------------- -
335 * | Data | | Data Length
336 * ----------------------------- -
338 bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
340 UINT16 fieldCode = 0xffff;
341 UINT16 fieldValue = 0xffff;
342 UINT8 oneByte = 0xff;
344 MsgHeaderAddress *pAddr = NULL;
345 MsgHeaderAddress *pLastTo = NULL;
346 MsgHeaderAddress *pLastCc = NULL;
347 MsgHeaderAddress *pLastBcc = NULL;
349 UINT32 valueLength = 0;
350 UINT32 tmpInteger = 0;
355 char szGarbageBuff[MSG_STDSTR_LONG] = {0, };
356 char *pLimitData = NULL;
359 MSG_DEBUG("MmsBinaryDecodeMsgHeader: pFile=%d, total len=%d\n", pFile, totalLength);
361 _MmsCleanDecodeBuff();
363 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos,
364 &gMmsDecodeCurOffset, gpMmsDecodeBuf1, gpMmsDecodeBuf2,
365 gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
366 MSG_DEBUG("MmsBinaryDecodeMsgHeader: fail to load to buffer \n");
370 while (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength)) {
371 fieldCode = oneByte & 0x7f;
373 switch (_MmsGetBinaryType(MmsCodeFieldCode, fieldCode)) {
374 case MMS_CODE_RESPONSESTATUS:
376 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
377 MSG_DEBUG("MmsBinaryDecodeMsgHeader: responseStatus GetOneByte fail\n");
381 fieldValue = _MmsGetBinaryType(MmsCodeResponseStatus, (UINT16)(oneByte & 0x7F));
383 if (fieldValue == 0xFFFF) {
384 MSG_DEBUG("MmsBinaryDecodeMsgHeader: responseStatus error\n");
388 if (fieldValue >= 0x0044 && fieldValue <= 0x005F) {
390 } else if (fieldValue >= 0x006A && fieldValue <= 0x007F) {
394 mmsHeader.responseStatus = (MmsResponseStatus)fieldValue;
396 MSG_DEBUG("MmsBinaryDecodeMsgHeader: response status = %s\n", MmsDebugGetResponseStatus(mmsHeader.responseStatus));
400 case MMS_CODE_RETRIEVESTATUS:
402 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
403 MSG_DEBUG("MmsBinaryDecodeMsgHeader: retrieveStatus GetOneByte fail\n");
407 fieldValue = _MmsGetBinaryType(MmsCodeRetrieveStatus, (UINT16)(oneByte & 0x7F));
409 if (fieldValue == 0xFFFF) {
410 MSG_DEBUG("MmsBinaryDecodeMsgHeader: retrieveStatus error\n");
414 if (fieldValue >= 0x0043 && fieldValue <= 0x005F) {
415 fieldValue = 0x0040; // 192; Error-transient-failure
416 } else if (fieldValue >= 0x0064 && fieldValue <= 0x007F) {
417 fieldValue = 0x0060; //224; Error-permanent-failure
420 mmsHeader.retrieveStatus = (MmsRetrieveStatus)fieldValue;
422 MSG_DEBUG("MmsBinaryDecodeMsgHeader: retrieve status = %s\n",
423 MmsDebugGetRetrieveStatus(mmsHeader.retrieveStatus));
427 case MMS_CODE_RESPONSETEXT:
429 if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szResponseText, MMS_LOCALE_RESP_TEXT_LEN + 1, totalLength) == false) {
430 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_RESPONSETEXT \n");
434 MSG_DEBUG("MmsBinaryDecodeMsgHeader: response text = %s\n", mmsHeader.szResponseText);
437 case MMS_CODE_RETRIEVETEXT:
439 if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szRetrieveText, MMS_LOCALE_RESP_TEXT_LEN + 1, totalLength) == false) {
440 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_RETRIEVETEXT \n");
444 MSG_DEBUG("MmsBinaryDecodeMsgHeader: retrieve text = %s\n", mmsHeader.szResponseText);
449 if (__MmsBinaryDecodeText(pFile, mmsHeader.szMsgID, MMS_MSG_ID_LEN + 1, totalLength) < 0) {
450 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_MSGID is invalid\n");
454 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg id = %s\n", mmsHeader.szMsgID);
456 if (MsgStrlen (mmsHeader.szMsgID) > 2)
457 MsgMIMERemoveQuote (mmsHeader.szMsgID);
461 case MMS_CODE_SUBJECT:
463 if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN + 1, totalLength) == false) {
464 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_SUBJECT \n");
468 pLimitData = (char *)malloc(MSG_LOCALE_SUBJ_LEN + 1);
470 if (pLimitData == NULL) {
471 MSG_DEBUG("MmsBinaryDecodeMsgHeader : pLimitData malloc fail \n");
475 nRead = MsgCutUTFString((unsigned char*)pLimitData, MSG_LOCALE_SUBJ_LEN + 1, (unsigned char*)mmsHeader.szSubject, MSG_SUBJ_LEN);
476 MSG_DEBUG("MmsBinaryDecodeMsgHeader : Subject edit.. \n");
478 if (nRead > MSG_LOCALE_SUBJ_LEN) {
479 memset(mmsHeader.szSubject, 0 , sizeof(mmsHeader.szSubject));
480 strncpy(mmsHeader.szSubject, pLimitData, MSG_SUBJ_LEN);
482 memset(mmsHeader.szSubject, 0 , sizeof(mmsHeader.szSubject));
483 strncpy(mmsHeader.szSubject, pLimitData, MSG_LOCALE_SUBJ_LEN);
491 MSG_DEBUG("MmsBinaryDecodeMsgHeader: subject = %s\n", mmsHeader.szSubject);
496 /* Value-length (Address-present-token Encoded-string-value | Insert-address-token) */
498 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
499 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_FROM is invalid\n");
503 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
504 MSG_DEBUG("MmsBinaryDecodeMsgHeader: MMS_CODE_FROM GetOneByte fail\n");
508 // DRM_TEMPLATE - start
512 if (oneByte == (_MmsGetBinaryValue(MmsCodeAddressType, MMS_ADDRESS_PRESENT_TOKEN)|0x80)) {
513 if (valueLength > 0) {
514 mmsHeader.pFrom = __MmsDecodeEncodedAddress(pFile, totalLength);
515 if (mmsHeader.pFrom == NULL) {
516 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_FROM __MmsDecodeEncodedAddress fail\n");
520 mmsHeader.pFrom = (MsgHeaderAddress *)malloc(sizeof(MsgHeaderAddress));
521 if (mmsHeader.pFrom == NULL)
524 mmsHeader.pFrom->szAddr = (char *)malloc(1);
525 if (mmsHeader.pFrom->szAddr == NULL) {
526 free(mmsHeader.pFrom);
527 mmsHeader.pFrom = NULL;
531 mmsHeader.pFrom->szAddr[0] = '\0';
532 mmsHeader.pFrom->pNext = NULL;
535 MSG_DEBUG("MmsBinaryDecodeMsgHeader: from = %s\n", mmsHeader.pFrom->szAddr);
536 // DRM_TEMPLATE - end
537 } else if (oneByte == (_MmsGetBinaryValue(MmsCodeAddressType, MMS_INSERT_ADDRESS_TOKEN)|0x80)) {
538 /* Present Token only */
539 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_FROM insert token\n");
541 /* from data broken */
542 MSG_DEBUG("MmsBinaryDecodeMsgHeader: from addr broken\n");
543 gCurMmsDecodeBuffPos--;
550 pAddr = __MmsDecodeEncodedAddress(pFile, totalLength);
552 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_TO __MmsDecodeEncodedAddress fail\n");
556 if (mmsHeader.pTo == NULL) {
558 pLastTo = mmsHeader.pTo = pAddr;
561 pLastTo->pNext = pAddr;
565 MSG_DEBUG("MmsBinaryDecodeMsgHeader: to = %s\n", mmsHeader.pTo->szAddr);
570 pAddr = __MmsDecodeEncodedAddress(pFile, totalLength);
572 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_BCC __MmsDecodeEncodedAddress fail\n");
576 if (mmsHeader.pBcc == NULL) {
578 pLastBcc = mmsHeader.pBcc = pAddr;
581 pLastBcc->pNext = pAddr;
585 MSG_DEBUG("MmsBinaryDecodeMsgHeader: bcc = %s\n", mmsHeader.pBcc->szAddr);
590 pAddr = __MmsDecodeEncodedAddress(pFile, totalLength);
592 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_CC __MmsDecodeEncodedAddress fail\n");
596 if (mmsHeader.pCc == NULL) {
598 pLastCc = mmsHeader.pCc = pAddr;
601 pLastCc->pNext = pAddr;
604 MSG_DEBUG("MmsBinaryDecodeMsgHeader: cc = %s\n", mmsHeader.pCc->szAddr);
607 case MMS_CODE_CONTENTLOCATION:
609 if (__MmsBinaryDecodeText(pFile, mmsHeader.szContentLocation, MMS_LOCATION_LEN + 1, totalLength) < 0) {
610 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_CONTENTLOCATION is invalid\n");
613 MSG_DEBUG("MmsBinaryDecodeMsgHeader: content location = %s\n", mmsHeader.szContentLocation);
618 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.date, totalLength) == false) {
619 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_DATE is invalid\n");
622 MSG_DEBUG("MmsBinaryDecodeMsgHeader: date = %d\n", mmsHeader.date);
625 case MMS_CODE_DELIVERYREPORT:
627 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
628 MSG_DEBUG("MmsBinaryDecodeMsgHeader: deliveryReport GetOneByte fail\n");
632 fieldValue = _MmsGetBinaryType(MmsCodeDeliveryReport, (UINT16)(oneByte & 0x7F));
634 if (fieldValue == 0xFFFF) {
635 MSG_DEBUG("MmsBinaryDecodeMsgHeader: deliveryReport error\n");
639 mmsHeader.deliveryReport = (MmsReport)fieldValue;
641 MSG_DEBUG("MmsBinaryDecodeMsgHeader: delivery report=%s\n", MmsDebugGetMmsReport(mmsHeader.deliveryReport));
644 case MMS_CODE_DELIVERYTIME:
646 /* value_length (absolute-token Long-integer | Relative-token Long-integer) */
648 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
649 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_DELIVERYTIME \n");
653 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
654 MSG_DEBUG("MmsBinaryDecodeMsgHeader: delivery time GetOneByte fail\n");
658 //DRM_TEMPLATE - start
661 if (oneByte == (_MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_ABSOLUTE)|0x80)) {
662 mmsHeader.deliveryTime.type = MMS_TIMETYPE_ABSOLUTE;
664 if (valueLength > 0) {
665 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.deliveryTime.time, totalLength) == false) {
666 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_DELIVERYTIME\n");
670 // DRM_TEMPLATE - end
672 mmsHeader.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
674 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&mmsHeader.deliveryTime.time, &tmpIntLen, totalLength) == false) {
675 MSG_DEBUG("MmsBinaryDecodeMsgHeader : __MmsBinaryDecodeInteger fail...\n");
679 MSG_DEBUG("MmsBinaryDecodeMsgHeader: delivery type=%d, time=%d\n", mmsHeader.deliveryTime.type, mmsHeader.deliveryTime.time);
682 case MMS_CODE_EXPIRYTIME:
684 /* value_length(absolute-token Long-integer | Relative-token Long-integer) */
686 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
687 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_EXPIRYTIME \n");
691 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
692 MSG_DEBUG("MmsBinaryDecodeMsgHeader: expiry time GetOneByte fail\n");
696 // DRM_TEMPLATE - start
699 if (oneByte == (_MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_ABSOLUTE)|0x80)) {
700 mmsHeader.expiryTime.type = MMS_TIMETYPE_ABSOLUTE;
702 if (valueLength > 0) {
703 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.expiryTime.time, totalLength) == false) {
704 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_EXPIRYTIME is invalid\n");
708 // DRM_TEMPLATE - end
710 mmsHeader.expiryTime.type = MMS_TIMETYPE_RELATIVE;
712 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&mmsHeader.expiryTime.time, &tmpIntLen, totalLength) == false) {
713 MSG_DEBUG("MmsBinaryDecodeMsgHeader : __MmsBinaryDecodeInteger fail...\n");
717 MSG_DEBUG("MmsBinaryDecodeMsgHeader: expiry = %d\n", mmsHeader.expiryTime.time);
720 case MMS_CODE_MSGCLASS:
722 /* Class-value = Class-identifier | Token Text */
724 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
725 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgClass GetOneByte fail\n");
729 if (oneByte > 0x7f) {
730 /* Class-identifier */
731 mmsHeader.msgClass = (MmsMsgClass)_MmsGetBinaryType(MmsCodeMsgClass, (UINT16)(oneByte & 0x7F));
733 if (__MmsBinaryDecodeText(pFile, szGarbageBuff, MSG_STDSTR_LONG, totalLength) < 0) {
734 MSG_DEBUG("MmsBinaryDecodeMsgHeader: 1. __MmsBinaryDecodeText fail. (class)\n");
738 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg class=%s\n", MmsDebugGetMsgClass(mmsHeader.msgClass));
741 case MMS_CODE_MSGSIZE:
743 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.msgSize, totalLength) == false) {
744 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_MSGSIZE is invalid\n");
747 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg size = %d\n", mmsHeader.msgSize);
750 case MMS_CODE_MSGSTATUS:
752 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
753 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
757 mmsHeader.msgStatus = (msg_delivery_report_status_t)_MmsGetBinaryType(MmsCodeMsgStatus, (UINT16)(oneByte & 0x7F));
758 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg status=%s \n", MmsDebugGetMsgStatus(mmsHeader.msgStatus)) ;
761 case MMS_CODE_MSGTYPE:
763 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
764 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
768 mmsHeader.type = (MmsMsgType)_MmsGetBinaryType(MmsCodeMsgType, (UINT16)(oneByte & 0x7F));
769 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msg type=%s\n", MmsDebugGetMsgType(mmsHeader.type));
772 case MMS_CODE_PRIORITY:
774 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
775 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
778 mmsHeader.priority = (MmsPriority)_MmsGetBinaryType(MmsCodePriority, (UINT16)(oneByte & 0x7F));
779 MSG_DEBUG("MmsBinaryDecodeMsgHeader: priority=%d\n", mmsHeader.priority);
782 case MMS_CODE_READREPLY:
784 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
785 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
788 mmsHeader.readReply = (MmsReport)_MmsGetBinaryType(MmsCodeReadReply, (UINT16)(oneByte & 0x7F));
789 MSG_DEBUG("MmsBinaryDecodeMsgHeader: read reply=%s \n", MmsDebugGetMmsReport(mmsHeader.readReply));
792 case MMS_CODE_REPORTALLOWED:
794 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
795 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
798 mmsHeader.reportAllowed = (MmsReportAllowed)_MmsGetBinaryType(MmsCodeReportAllowed, (UINT16)(oneByte & 0x7F));
799 MSG_DEBUG("MmsBinaryDecodeMsgHeader: mmsHeader.reportAllowed=%d\n", MmsDebugGetMmsReportAllowed(mmsHeader.reportAllowed));
802 case MMS_CODE_SENDERVISIBILLITY:
804 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
805 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
808 mmsHeader.hideAddress= (MmsSenderVisible)!(_MmsGetBinaryType(MmsCodeSenderVisibility, (UINT16)(oneByte &0x7F)));
809 MSG_DEBUG("MmsBinaryDecodeMsgHeader: sender visible=%d \n", mmsHeader.hideAddress);
814 if (__MmsBinaryDecodeText(pFile, mmsHeader.szTrID, MMS_TR_ID_LEN + 1, totalLength) < 0) {
815 MSG_DEBUG("Transaction ID Too Long \n");
818 MSG_DEBUG("MmsBinaryDecodeMsgHeader: trID = %s\n", mmsHeader.szTrID);
821 case MMS_CODE_VERSION:
822 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
823 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
826 mmsHeader.version = oneByte;
828 MSG_DEBUG("MmsBinaryDecodeMsgHeader: ver = 0x%x\n", mmsHeader.version);
831 case MMS_CODE_CONTENTTYPE:
834 * Content-type is the last header field of SendRequest and RetrieveConf.
835 * It's required to decrease pointer by one and return,
836 * to parse this field in MmsBinaryDecodeContentType().
841 /* ----------- Add by MMSENC v1.1 ----------- */
843 case MMS_CODE_READSTATUS:
845 /* Read-status-value = Read | Deleted without being read */
847 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
848 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
852 mmsHeader.readStatus = (msg_read_report_status_t)_MmsGetBinaryType(MmsCodeReadStatus, (UINT16)(oneByte & 0x7F));
853 MSG_DEBUG("MmsBinaryDecodeMsgHeader: read status=%s\n", MmsDebugGetMmsReadStatus(mmsHeader.readStatus));
856 case MMS_CODE_REPLYCHARGING:
858 /* Reply-charging-value = Requested | Requested text only | Accepted | Accepted text only */
860 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
861 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
865 mmsHeader.replyCharge.chargeType = (MmsReplyChargeType)_MmsGetBinaryType(MmsCodeReplyCharging, (UINT16)(oneByte & 0x7F));
866 MSG_DEBUG("MmsBinaryDecodeMsgHeader: mmsHeader.reply charge=%d\n", mmsHeader.replyCharge.chargeType);
869 case MMS_CODE_REPLYCHARGINGDEADLINE:
871 /* Reply-charging-deadline-value = Value-length (Absolute-token Date-value | Relative-token Delta-seconds-value) */
873 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
874 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_REPLYCHARGINGDEADLINE \n");
878 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
879 MSG_DEBUG("MmsBinaryDecodeMsgHeader: msgStatus GetOneByte fail\n");
883 if (oneByte == (_MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_ABSOLUTE) | 0x80)) {
884 mmsHeader.replyCharge.deadLine.type = MMS_TIMETYPE_ABSOLUTE;
886 mmsHeader.replyCharge.deadLine.type = MMS_TIMETYPE_RELATIVE;
889 // DRM_TEMPLATE - start
892 if (valueLength > 0) {
893 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.replyCharge.deadLine.time, totalLength) == false) {
894 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_REPLYCHARGINGDEADLINE is invalid\n");
898 // DRM_TEMPLATE - end
901 case MMS_CODE_REPLYCHARGINGID:
903 /* Reply-charging-ID-value = Text-string */
905 if (__MmsBinaryDecodeText(pFile, mmsHeader.replyCharge.szChargeID, MMS_MSG_ID_LEN + 1, totalLength) < 0) {
906 MSG_DEBUG("MmsBinaryDecodeMsgHeader: 1. __MmsBinaryDecodeText fail. (szReplyChargingID)\n");
911 case MMS_CODE_REPLYCHARGINGSIZE:
913 /* Reply-charging-size-value = Long-integer */
915 if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.replyCharge.chargeSize, totalLength) == false) {
916 MSG_DEBUG("MmsBinaryDecodeMsgHeader : MMS_CODE_REPLYCHARGINGSIZE is invalid\n");
921 case MMS_CODE_PREVIOUSLYSENTBY:
924 * Previously-sent-by-value = Value-length Forwarded-count-value Encoded-string-value
925 * Forwarded-count-value = Integer-value
926 * MMS_CODE_PREVIOUSLYSENTBY shall be a pair with MMS_CODE_PREVIOUSLYSENTDATE
930 * fixme: There is no proper field to store this information.
931 * Just increase pointer now.
934 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
935 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 1. invalid MMS_CODE_PREVIOUSLYSENTBY \n");
939 if (__MmsBinaryDecodeInteger(pFile, &tmpInteger, &tmpIntLen, totalLength) == false) {
940 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 2. invalid MMS_CODE_PREVIOUSLYSENTBY \n");
944 if (__MmsBinaryDecodeEncodedString(pFile, szGarbageBuff, MSG_STDSTR_LONG, totalLength) == false) {
945 MSG_DEBUG("MmsBinaryDecodeMsgHeader : invalid MMS_CODE_RETRIEVETEXT \n");
950 case MMS_CODE_PREVIOUSLYSENTDATE:
953 * Previously-sent-date-value = Value-length Forwarded-count-value Date-value
954 * Forwarded-count-value = Integer-value
955 * MMS_CODE_PREVIOUSLYSENTDATE shall be a pair with MMS_CODE_PREVIOUSLYSENTBY
959 * fixme: There is no proper field to store this information.
960 * Just increase pointer now.
963 if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
964 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 1. invalid MMS_CODE_PREVIOUSLYSENTDATE \n");
968 if (__MmsBinaryDecodeInteger(pFile, &tmpInteger, &tmpIntLen, totalLength) == false) {
969 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 2. invalid MS_CODE_PREVIOUSLYSENTDATE \n");
973 if (__MmsDecodeLongInteger(pFile, (UINT32*)&tmpInteger, totalLength) == false) {
974 MSG_DEBUG("MmsBinaryDecodeMsgHeader : 3. invalid MMS_CODE_PREVIOUSLYSENTDATE \n");
983 * Application-header = Token-text Application-specific-value
984 * Token-text = Token End-of-string
985 * Application-specific-value = Text -string
987 * OR unknown header field - Just ignore these fields.
989 * Read one byte and check the value >= 0x80
990 * (check these value can be field code)
993 int remainLength = 0;
997 offset = _MmsGetDecodeOffset();
998 if (offset >= totalLength)
1001 remainLength = totalLength - offset;
1003 while ((oneByte < 0x80) && (remainLength > 0)) {
1004 if (__MmsBinaryDecodeCheckAndDecreaseLength(&remainLength, 1) == false) {
1005 MSG_DEBUG("MmsBinaryDecodeMsgHeader: __MmsBinaryDecodeCheckAndDecreaseLength fail\n");
1008 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1009 MSG_DEBUG("MmsBinaryDecodeMsgHeader: responseStatus GetOneByte fail\n");
1014 gCurMmsDecodeBuffPos--;
1020 offset = _MmsGetDecodeOffset();
1021 if (offset >= totalLength)
1029 if (mmsHeader.pTo == NULL && pLastTo) {
1033 if (mmsHeader.pCc == NULL && pLastCc) {
1037 if (mmsHeader.pBcc == NULL && pLastBcc) {
1041 MSG_DEBUG("MmsBinaryDecodeMsgHeader: success\n");
1047 if (mmsHeader.pTo == NULL && pLastTo) {
1051 if (mmsHeader.pCc == NULL && pLastCc) {
1055 if (mmsHeader.pBcc == NULL && pLastBcc) {
1059 MSG_DEBUG("MmsBinaryDecodeMsgHeader: failed\n");
1064 #ifdef FEATURE_JAVA_MMS
1065 // for JAVA MMS AppId - check later whether it can be handled by MmsBinaryDecodeMsgHeader
1066 bool MmsBinaryDecodeContentType(FILE *pFile, char *szFilePath, int totalLength)
1070 MSG_DEBUG("MmsBinaryDecodeContentType:\n");
1072 if (szFilePath != NULL)
1073 strncpy(mmsHeader.msgType.szOrgFilePath, szFilePath, strlen(szFilePath));
1074 mmsHeader.msgType.offset = _MmsGetDecodeOffset() - 1; // + Content-Type code value
1076 // read data(2K) from msg file(/User/Msg/Inbox/5) to gpCurMmsDecodeBuff for decoding
1077 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos,
1078 &gMmsDecodeCurOffset, gpMmsDecodeBuf1, gpMmsDecodeBuf2,
1079 gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
1080 MSG_DEBUG("MmsBinaryDecodeContentType: fail to load to buffer \n");
1084 // msg's type [ex] related, mixed, single part (jpg, amr and etc)
1085 length = MmsBinaryDecodeContentType(pFile, &mmsHeader.msgType, totalLength);
1087 MSG_DEBUG("MmsBinaryDecodeContentType: MMS_CODE_CONTENTTYPE is fail\n");
1090 MSG_DEBUG("Content-Type: Application-ID:%s Reply-To-Application-ID:%s",mmsHeader.msgType.param.szApplicationID, mmsHeader.msgType.param.szReplyToApplicationID);
1096 /* fixme: Delete multipart using MmsDeleteMsg() */
1102 bool MmsBinaryDecodeMsgBody(FILE *pFile, char *szFilePath, int totalLength)
1107 MSG_DEBUG("MmsBinaryDecodeMsgBody:\n");
1109 if (szFilePath != NULL)
1110 strncpy(mmsHeader.msgType.szOrgFilePath, szFilePath , strlen(szFilePath));
1112 mmsHeader.msgType.offset = _MmsGetDecodeOffset() - 1; // + Content-Type code value
1114 // read data(2K) from msg file(/User/Msg/Inbox/5) to gpCurMmsDecodeBuff for decoding
1115 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos,
1116 &gMmsDecodeCurOffset, gpMmsDecodeBuf1, gpMmsDecodeBuf2,
1117 gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
1118 MSG_DEBUG("MmsBinaryDecodeMsgBody: fail to load to buffer \n");
1122 // msg's type [ex] related, mixed, single part (jpg, amr and etc)
1123 length = MmsBinaryDecodeContentType(pFile, &mmsHeader.msgType, totalLength);
1125 MSG_DEBUG("MmsBinaryDecodeMsgBody: MMS_CODE_CONTENTTYPE is fail\n");
1129 mmsHeader.msgType.size = length + 1; // + Content-Type code value
1130 mmsHeader.msgBody.offset = _MmsGetDecodeOffset();
1132 switch (mmsHeader.msgType.type) {
1133 case MIME_APPLICATION_VND_WAP_MULTIPART_MIXED:
1134 case MIME_APPLICATION_VND_WAP_MULTIPART_RELATED:
1135 case MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC:
1136 case MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE:
1137 case MIME_MULTIPART_REPORT:
1138 case MIME_MULTIPART_MIXED:
1139 case MIME_MULTIPART_RELATED:
1140 case MIME_MULTIPART_ALTERNATIVE:
1141 case MIME_APPLICATION_VND_OMA_DRM_MESSAGE:
1142 case MIME_APPLICATION_VND_OMA_DRM_CONTENT:
1144 MSG_DEBUG("__MmsBinaryMsgBodyDecode: Decode multipart\n");
1146 offset = _MmsGetDecodeOffset();
1147 if (offset >= totalLength)
1150 if (MmsBinaryDecodeMultipart(pFile, szFilePath, &mmsHeader.msgType, &mmsHeader.msgBody, totalLength) == false) {
1151 MSG_DEBUG("__MmsBinaryMsgBodyDecode: MmsBinaryDecodeMultipart is fail.\n");
1158 /* Single part message ---------------------------------------------- */
1159 if (szFilePath != NULL)
1160 strcpy(mmsHeader.msgBody.szOrgFilePath, szFilePath);
1162 offset = _MmsGetDecodeOffset();
1163 if (offset >= totalLength)
1166 if (MmsBinaryDecodePartBody(pFile, totalLength - mmsHeader.msgBody.offset, totalLength) == false) {
1167 MSG_DEBUG("__MmsBinaryMsgBodyDecode: MmsBinaryDecodePartBody is fail.(Single Part)\n");
1171 mmsHeader.msgBody.size = totalLength - mmsHeader.msgBody.offset;
1172 mmsHeader.msgType.contentSize = totalLength - mmsHeader.msgBody.offset;
1177 #ifdef __SUPPORT_DRM__
1178 mmsHeader.drmType = MsgGetDRMType(&mmsHeader.msgType, &mmsHeader.msgBody);
1190 #if MMS_ENABLE_EXTEND_CFM
1191 // DRM (Extended)CFM
1192 // Get Extended CFM value.
1193 static bool __MmsConvertString2Bool(char *pszValue)
1195 if (!strcasecmp(pszValue, "no"))
1202 bool MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int valueLength, int totalLength)
1206 char *szTypeString = NULL;
1207 char *szTypeValue = NULL;
1208 UINT8 paramCode = 0xff;
1215 * Parameter = Typed-parameter | Untyped-parameter
1216 * WAP-230-WSP-20010118-p, Proposed Version 18 January 2001 (pp.107)
1219 MSG_DEBUG("MmsBinaryDecodeParameter: \n");
1221 while (valueLength > 0) {
1222 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1223 MSG_DEBUG("MmsBinaryDecodeContentType: paramCode _MmsBinaryDecodeGetOneByte fail\n");
1227 paramCode = oneByte;
1230 switch (paramCode) {
1231 case 0x81: // charset
1233 if (__MmsBinaryDecodeCharset(pFile, (UINT32*)&(pMsgType->param.charset), &charSetLen, totalLength) == false) {
1234 MSG_DEBUG("MmsBinaryDecodeContentType : __MmsBinaryDecodeCharset fail.\n");
1238 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, charSetLen) == false)
1243 case 0x85: //name = Text-string
1244 case 0x97: //name = Text-value = No-value | Token-text | Quoted-string
1245 memset(pMsgType->param.szName, 0, sizeof(pMsgType->param.szName));
1246 length = __MmsDecodeGetFilename(pFile, pMsgType->param.szName,
1247 MSG_FILENAME_LEN_MAX -5, // MSG_LOCALE_FILENAME_LEN_MAX + 1, : change @ 110(Ui code have to change for this instead of DM)
1250 MSG_DEBUG("MmsBinaryDecodeContentType : __MmsDecodeGetFilename fail. (name parameter)\n");
1254 if (MsgCheckFileNameHasInvalidChar(pMsgType->param.szName)) {
1255 _MsgReplaceInvalidFileNameChar(pMsgType->param.szName, '_');
1258 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, length) == false)
1263 case 0x86: //filename = Text-string
1264 case 0x98: //filename = Text-value = No-value | Token-text | Quoted-string
1265 memset(pMsgType->param.szFileName, 0, sizeof(pMsgType->param.szFileName));
1266 length = __MmsDecodeGetFilename(pFile, pMsgType->param.szFileName, MSG_FILENAME_LEN_MAX -5, totalLength);
1268 MSG_DEBUG("MmsBinaryDecodeContentType : __MmsDecodeGetFilename fail. (filename parameter)\n");
1272 if (MsgCheckFileNameHasInvalidChar(pMsgType->param.szFileName)) {
1273 _MsgReplaceInvalidFileNameChar(pMsgType->param.szFileName, '_');
1276 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, length) == false)
1281 case 0x89: //type = Constrained-encoding = Extension-Media | Short-integer
1283 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1284 MSG_DEBUG("MmsBinaryDecodeContentType: type _MmsBinaryDecodeGetOneByte fail\n");
1288 if (oneByte > 0x7f) {
1289 pMsgType->param.type = _MmsGetBinaryType(MmsCodeContentType,
1290 (UINT16)(oneByte & 0x7f));
1291 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, 1) == false)
1294 gCurMmsDecodeBuffPos--;
1297 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1298 pMsgType->param.type = _MmsGetTextType(MmsCodeContentType, szTypeString);
1302 szTypeString = NULL;
1305 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1311 case 0x8A: //start encoding version 1.2
1312 case 0x99: //start encoding version 1.4
1315 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1317 memset(pMsgType->param.szStart, 0, MMS_CONTENT_ID_LEN + 1);
1318 strncpy(pMsgType->param.szStart, szTypeString, MMS_CONTENT_ID_LEN);
1320 szTypeString = NULL;
1322 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1328 case 0x8B: //startInfo encoding version 1.2
1329 case 0x9A: //startInfo encoding version 1.4
1332 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1335 memset(pMsgType->param.szStartInfo, 0, MMS_CONTENT_ID_LEN + 1);
1336 strncpy(pMsgType->param.szStartInfo, szTypeString, MMS_CONTENT_ID_LEN);
1339 szTypeString = NULL;
1341 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1349 if (paramCode > 0x7F) {
1350 MSG_DEBUG("MmsBinaryDecodeContentType: Unsupported parameter\n");
1352 // In case of the last byte of Parameter field, it should be returned without decreasing the gCurMmsDecodeBuffPos value.
1354 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, 1) == false)
1358 * Untyped Parameter = Token-text Untyped-value
1359 * Token-text = Token End-of-string
1360 * Untyped-value = Integer-value | Text-value
1361 * Text-value = No-value | Token-text | Quoted-string
1363 * Just increase pointer!!!
1369 gCurMmsDecodeBuffPos--;
1373 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1374 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1380 if (__MmsBinaryDecodeInteger(pFile, &integer, &intLen, totalLength) == true) {
1381 MSG_DEBUG("MmsBinaryDecodeContentType: Unsupported parameter(%d)\n", integer);
1382 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, intLen) == false)
1386 szTypeValue = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1389 /* checkMe: forwardLock needs boudary string */
1390 if (strcasecmp(szTypeString, "boundary") == 0) {
1391 memset(pMsgType->param.szBoundary, 0, MSG_BOUNDARY_LEN + 1);
1392 strncpy(pMsgType->param.szBoundary, szTypeValue, MSG_BOUNDARY_LEN);
1393 #ifdef FEATURE_JAVA_MMS
1394 } else if (strcasecmp(szTypeString, "Application-ID") == 0) {
1395 pMsgType->param.szApplicationID = (char*) malloc(textLength + 1);
1396 memset(pMsgType->param.szApplicationID, 0, textLength + 1);
1397 strncpy(pMsgType->param.szApplicationID, szTypeValue, textLength);
1398 MSG_DEBUG("Application-ID:%s",pMsgType->param.szApplicationID);
1399 } else if (strcasecmp(szTypeString,"Reply-To-Application-ID") == 0) {
1400 pMsgType->param.szReplyToApplicationID= (char*) malloc(textLength + 1);
1401 memset(pMsgType->param.szReplyToApplicationID, 0, textLength + 1);
1402 strncpy(pMsgType->param.szReplyToApplicationID, szTypeValue, textLength);
1403 MSG_DEBUG("ReplyToApplication-ID:%s",pMsgType->param.szReplyToApplicationID);
1409 MSG_DEBUG("MmsBinaryDecodeContentType: Unsupported parameter(%s)\n", szTypeValue);
1410 if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
1416 MSG_DEBUG("MmsBinaryDecodeContentType: Unsupported parameter(%s)\n", szTypeString);
1418 szTypeString = NULL;
1424 } /*end of while loop*/
1431 szTypeString = NULL;
1444 * Decode Encoded Content type
1446 * @param pEncodedData [in] ContentType encoded data
1447 * @param pMsgType [out] Decoded MsgType
1448 * @return Decoded address list
1450 int MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int totalLength)
1453 char *szTypeString = NULL;
1454 int valueLength = 0;
1460 * Content-type-value : [WAPWSP 8.4.2.24]
1461 * Preassigned content-types : [WAPWSP Appendix A, Table 40]
1462 * The use of start-parameter : [RFC2387] and SHOULD be encoded according to [WAPWSP].
1464 * Content-type-value = Constrained-media | Content-general-form
1465 * Content-general-form = Value-length Media-type
1466 * Media-type = (Well-known-media | Extension-Media) *(Parameter)
1469 MSG_DEBUG("MmsBinaryDecodeContentType: decoding content type..\n");
1472 length = __MmsDecodeValueLength(pFile, (UINT32*)&valueLength, totalLength);
1475 * Constrained-media or Single part message
1476 * Constrained-media = Constrained-encoding = Extension-Media | Short-integer
1477 * Extension-media = *TEXT End-of-string
1478 * Short-integer = OCTET(1xxx xxxx)
1481 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1482 MSG_DEBUG("MmsBinaryDecodeContentType: Constrained-media _MmsBinaryDecodeGetOneByte fail\n");
1486 if (oneByte > 0x7F) {
1488 pMsgType->type = _MmsGetBinaryType(MmsCodeContentType, (UINT16)(oneByte & 0x7F));
1491 char *pszTemp = NULL;
1493 /* Extension-Media */
1494 gCurMmsDecodeBuffPos--;
1497 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1499 if (szTypeString && (strchr(szTypeString, ';')) != NULL) {
1500 pszTemp = _MsgGetStringUntilDelimiter(szTypeString, ';');
1503 szTypeString = pszTemp;
1507 pMsgType->type = _MmsGetTextType(MmsCodeContentType, szTypeString);
1509 length = textLength;
1513 szTypeString = NULL;
1518 * Content-general-form = Value-length Media-type
1519 * Media-type = (Well-known-media | Extension-Media)*(Parameter)
1522 length += valueLength;
1524 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1525 MSG_DEBUG("MmsBinaryDecodeContentType: Well-known-media _MmsBinaryDecodeGetOneByte fail\n");
1529 if (oneByte > 0x7F) {
1530 /* Well-known-media */
1531 pMsgType->type = _MmsGetBinaryType(MmsCodeContentType, (UINT16)(oneByte & 0x7F));
1534 /* Extension-Media */
1535 gCurMmsDecodeBuffPos--;
1538 szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1539 pMsgType->type = _MmsGetTextType(MmsCodeContentType, szTypeString);
1540 valueLength -= textLength;
1544 szTypeString = NULL;
1548 MSG_DEBUG("MmsBinaryDecodeContentType: content type=%s\n", MmsDebugGetMimeType((MimeType)pMsgType->type));
1551 if (MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false) {
1552 MSG_DEBUG("MmsBinaryDecodeContentType: Content-Type parameter fail\n");
1564 bool MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int headerLen, int totalLength)
1566 UINT8 fieldCode = 0xff;
1568 UINT32 valueLength = 0;
1570 char *pValue = NULL;
1571 char *pParam = NULL;
1577 char *pLatinBuff = NULL;
1579 char *szTemp = NULL;
1582 if (pFile == NULL || pMsgType == NULL)
1586 * Message-header = Well-known-header | Application-header
1587 * Well-known-header = Well-known-field-name Wap-value
1588 * Application-header = Token-text Application-specific-value
1589 * Well-known-field-name = Short-integer
1590 * Application-specific-value = Text-string
1593 while (headerLen > 0) {
1594 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1595 MSG_DEBUG("MmsBinaryDecodePartHeader: field code GetOneByte fail\n");
1599 if (0x80 <= oneByte && oneByte <= 0xC7) {
1600 /* Well-known-header = Well-known-field-name Wap-value (0x00 ~ 0x47) */
1602 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, 1) == false)
1605 fieldCode = oneByte & 0x7f;
1607 switch (fieldCode) {
1608 case 0x0E: //Content-Location
1609 case 0x04: //Content-Location
1611 pLatinBuff = (char *)malloc(MMS_CONTENT_ID_LEN + 1);
1612 if (pLatinBuff == NULL)
1615 length = __MmsBinaryDecodeText(pFile, pLatinBuff, MMS_CONTENT_ID_LEN + 1, totalLength);
1617 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeQuotedString fail.\n");
1621 szSrc = MsgChangeHexString(pLatinBuff);
1624 strcpy(pLatinBuff, szSrc);
1629 textLength = strlen(pLatinBuff);
1631 if (MsgLatin2UTF ((unsigned char*)pMsgType->szContentLocation, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, textLength) < 0) {
1632 MSG_DEBUG("MmsBinaryDecodePartHeader: MsgLatin2UTF fail \n");
1639 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1644 case 0x40: // Content-ID
1646 pLatinBuff = (char *)malloc(MMS_CONTENT_ID_LEN + 1);
1647 if (pLatinBuff == NULL)
1650 length = __MmsBinaryDecodeQuotedString(pFile, pLatinBuff, MMS_CONTENT_ID_LEN + 1, totalLength);
1653 MSG_DEBUG("MmsBinaryDecodePartHeader : Content-ID __MmsBinaryDecodeQuotedString fail.\n");
1657 szSrc = MsgChangeHexString(pLatinBuff);
1660 strcpy(pLatinBuff, szSrc);
1665 textLength = strlen(pLatinBuff);
1666 if (MsgLatin2UTF ((unsigned char*)pMsgType->szContentID, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, textLength) < 0) {
1667 MSG_DEBUG("MmsBinaryDecodePartHeader: MsgLatin2UTF fail \n");
1673 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1678 case 0x2E: // Content-Disposition
1679 case 0x45: // Content-Disposition
1682 * Content-disposition-value = Value-length Disposition *(Parameter)
1683 * Disposition = Form-data | Attachment | Inline | Token-text
1684 * Form-data = <Octet 128> : 0x80
1685 * Attachment = <Octet 129> : 0x81
1686 * Inline = <Octet 130> : 0x82
1689 length = __MmsDecodeValueLength2(pFile, &valueLength, totalLength);
1692 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1697 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1698 MSG_DEBUG("MmsBinaryDecodePartHeader: Disposition value GetOneByte fail\n");
1705 if (oneByte >= 0x80) {
1706 pMsgType->disposition = _MmsGetBinaryType(MmsCodeMsgDisposition, (UINT16)(oneByte & 0x7F));
1708 if (pMsgType->disposition == INVALID_HOBJ) {
1709 MSG_DEBUG("MmsBinaryDecodePartHeader : Content-Disposition _MmsGetBinaryType fail.\n");
1710 pMsgType->disposition = MSG_DISPOSITION_ATTACHMENT; // default
1713 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, 1) == false)
1716 if (MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false) {
1717 MSG_DEBUG("MmsBinaryDecodePartHeader: Disposition parameter fail\n");
1721 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, valueLength) == false)
1725 gCurMmsDecodeBuffPos--;
1728 pLatinBuff = (char *)malloc(MSG_FILENAME_LEN_MAX);
1729 memset(pLatinBuff, 0, MSG_FILENAME_LEN_MAX);
1731 textLength = __MmsBinaryDecodeText(pFile, pLatinBuff, MSG_FILENAME_LEN_MAX-1, totalLength);
1734 if (textLength < 0) {
1735 MSG_DEBUG("MmsBinaryDecodePartHeader : Content-Disposition decodingfail. \n");
1741 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, textLength) == false)
1744 valueLength -= textLength;
1746 if (MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false)
1748 MSG_DEBUG("MmsBinaryDecodePartHeader: Disposition parameter fail\n");
1752 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, valueLength) == false)
1759 case 0x0B: //Content-Encoding
1761 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
1762 MSG_DEBUG("MmsBinaryDecodePartHeader: Disposition value GetOneByte fail\n");
1766 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, 1) == false)
1771 case 0x0C: //Content-Language
1773 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&tmpInt, &tmpIntLen, totalLength) == true) {
1774 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, tmpIntLen) == false)
1779 cTemp = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1781 if (cTemp == NULL) {
1782 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeText2 fail...\n");
1786 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, textLength) == false) {
1799 case 0x0D: //Content-Length
1801 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&tmpInt, &tmpIntLen, totalLength) == false) {
1802 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeInteger fail...\n");
1806 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, tmpIntLen) == false)
1811 case 0x30: //X-Wap-Content-URI skip this value
1813 MSG_DEBUG("MmsBinaryDecodePartHeader : X-Wap-Content-URI header.\n");
1814 pLatinBuff = (char *)malloc(MMS_TEXT_LEN);
1815 if (pLatinBuff == NULL)
1818 length = __MmsBinaryDecodeText(pFile, pLatinBuff, MMS_TEXT_LEN, totalLength);
1821 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeQuotedString fail.\n");
1825 MSG_DEBUG("MmsBinaryDecodePartHeader : X-Wap-Content-URI header decoded. Value length %d\n", length);
1829 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1832 MSG_DEBUG("MmsBinaryDecodePartHeader : X-Wap-Content-URI header skipped.\n");
1836 case 0x01: // Accept-charset
1837 //if (NvGetInt(NV_SI_ADM_GCF_STATE) == 1)
1839 /* WAP-230-WSP-200010705-a.pdf
1840 8.4.2.8 Accept charset field
1841 The following rules are used to encode accept character set values.
1842 Accept-charset-value = Constrained-charset | Accept-charset-general-form
1843 Accept-charset-general-form = Value-length (Well-known-charset | Token-text) [Q-value]
1844 Constrained-charset = Any-charset | Constrained-encoding
1845 Well-known-charset = Any-charset | Integer-value
1846 ; Both are encoded using values from Character Set Assignments table in Assigned Numbers
1847 Any-charset = <Octet 128>
1848 ; Equivalent to the special RFC2616 charset value ��*��
1854 MSG_DEBUG("MmsBinaryDecodePartHeader : Accept-charset. \n");
1856 length = __MmsDecodeValueLength(pFile, &valueLength, totalLength);
1858 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1863 if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&charset, &charSetLen, totalLength) == false) {
1864 // We only support the well-known-charset format
1865 MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeInteger fail...\n");
1870 _MmsGetBinaryType(MmsCodeCharSet, (UINT16)charset);
1872 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, charSetLen) == false)
1880 /* Other Content-xxx headers : Have valueLength */
1882 MSG_DEBUG("MmsBinaryDecodePartHeader : unknown Value = 0x%x\n", oneByte);
1884 length = __MmsDecodeValueLength(pFile, &valueLength, totalLength);
1886 MSG_DEBUG("MmsBinaryDecodePartHeader : 1. invalid MMS_CODE_PREVIOUSLYSENTDATE \n");
1890 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
1893 szTemp = (char *)malloc(valueLength);
1897 if (_MmsBinaryDecodeGetBytes(pFile, szTemp, valueLength, totalLength) == false) {
1898 MSG_DEBUG("MmsBinaryDecodePartHeader : default _MmsBinaryDecodeGetBytes() fail\n");
1906 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, valueLength) == false)
1913 * Application-header = Token-text Application-specific-value
1914 * Application-specific-value = Text-string
1917 MSG_DEBUG(" MmsBinaryDecodePartHeader: Application-header = Token-text Application-specific-value \n");
1919 gCurMmsDecodeBuffPos--;
1924 pCode = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1925 if (pCode == NULL) {
1926 MSG_DEBUG("MmsBinaryDecodePartHeader: pCode is null\n");
1930 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, textLength) == false)
1933 MSG_DEBUG(" MmsBinaryDecodePartHeader: Token-text (%s) \n", pCode);
1936 /* Application-specific-value */
1939 pValue = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
1940 if (pValue == NULL) {
1941 MSG_DEBUG("MmsBinaryDecodePartHeader: pValue is null\n");
1945 MSG_DEBUG(" MmsBinaryDecodePartHeader: Application-specific-value (%s) \n", pValue);
1948 pParam = strchr(pValue, MSG_CH_ADDR_DELIMETER);
1954 switch (_MmsGetTextType(MmsCodeMsgBodyHeaderCode, pCode)) {
1955 case MMS_BODYHDR_TRANSFERENCODING: // Content-Transfer-Encoding
1956 pMsgType->encoding = _MmsGetTextType(MmsCodeContentTransferEncoding, pValue);
1959 case MMS_BODYHDR_CONTENTID: // Content-ID
1961 pLatinBuff = (char *)malloc(MMS_CONTENT_ID_LEN + 1);
1962 if (pLatinBuff == NULL)
1967 MsgMIMERemoveQuote (pValue);
1968 strncpy(pLatinBuff, pValue, MMS_MSG_ID_LEN);
1970 length = strlen(pLatinBuff);
1971 if (MsgLatin2UTF ((unsigned char*)pMsgType->szContentID, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, length) < 0)
1973 MSG_DEBUG("MmsBinaryDecodePartHeader: MsgLatin2UTF fail \n");
1981 case MMS_BODYHDR_CONTENTLOCATION: // Content-Location
1983 pLatinBuff = (char *)malloc(MMS_CONTENT_ID_LEN + 1);
1984 if (pLatinBuff == NULL)
1987 strncpy(pLatinBuff, pValue, MMS_MSG_ID_LEN);
1989 length = strlen(pLatinBuff);
1990 if (MsgLatin2UTF ((unsigned char*)pMsgType->szContentLocation, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, length) < 0) {
1991 MSG_DEBUG("MmsBinaryDecodePartHeader: MsgLatin2UTF fail \n");
1999 case MMS_BODYHDR_DISPOSITION: // Content-Disposition
2000 pMsgType->disposition = _MmsGetTextType(MmsCodeMsgDisposition, pValue);
2003 case MMS_BODYHDR_X_OMA_DRM_SEPARATE_DELIVERY: // DRM RO WAITING
2007 MSG_DEBUG("Unknown Field : %s, Value: %s\n", pCode, pValue);
2012 _MsgParseParameter(pMsgType, pParam + 1);
2024 if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, textLength) == false)
2073 bool MmsBinaryDecodeEntries(FILE *pFile, UINT32 *npEntries, int totalLength)
2077 length = __MmsBinaryDecodeUintvar(pFile, npEntries, totalLength);
2082 MSG_DEBUG("MmsBinaryDecodeEntries: Number of Entries = %d\n", *npEntries);
2092 bool MmsBinaryDecodePartBody(FILE *pFile, UINT32 bodyLength, int totalLength)
2097 * Currently, offset and size is
2098 * the only information used with msgBody.
2099 * If you need, add here more information
2102 MSG_DEBUG("MmsBinaryDecodePartBody: \n");
2104 offset = _MmsGetDecodeOffset();
2105 offset += bodyLength;
2107 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
2108 MSG_DEBUG("MmsBinaryDecodePartBody: fail to seek file pointer \n");
2112 _MmsCleanDecodeBuff();
2114 gMmsDecodeCurOffset = offset;
2116 if (offset >= totalLength)
2119 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
2120 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
2121 MSG_DEBUG("_MmsBinaryDecodeGetOneByte: fail to load to buffer \n");
2135 static bool MmsBinaryDecodeMovePointer(FILE *pFile, int offset, int totalLength)
2137 if (offset > totalLength)
2140 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
2141 MSG_DEBUG("MmsBinaryDecodeMovePointer: fail to seek file pointer \n");
2145 _MmsCleanDecodeBuff();
2147 gMmsDecodeCurOffset = offset;
2149 if (offset == totalLength)
2152 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
2153 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
2154 MSG_DEBUG("MmsBinaryDecodeMovePointer: fail to load to buffer \n");
2166 bool MmsBinaryIsTextEncodedPart(FILE *pFile, int totalLength)
2171 byteCount++; //check 0x0D
2173 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2176 if (oneByte != 0x0D) {
2177 //it can be started "--" without 0x0D 0x0A
2178 if (oneByte != 0x2D) {
2181 byteCount++; // check 0x2D ('-')
2182 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2185 if (oneByte != 0x2D) {
2192 byteCount++; //check 0x0A
2193 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2196 if (oneByte != 0x0A) {
2199 byteCount++; // check 0x2D ('-')
2200 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2203 if (oneByte != 0x2D) {
2206 byteCount++; // check 0x2D ('-')
2207 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
2210 if (oneByte != 0x2D) {
2220 gCurMmsDecodeBuffPos -= byteCount;
2224 gCurMmsDecodeBuffPos -= byteCount;
2229 bool MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, int totalLength)
2231 UINT32 nEntries = 0;
2232 MsgMultipart *pMultipart = NULL;
2233 MsgMultipart *pLastMultipart = NULL;
2234 MsgMultipart *pPreMultipart = NULL;
2238 MsgPresentationFactor factor = MSG_PRESENTATION_NONE;
2239 MsgPresentaionInfo presentationInfo;
2241 MSG_DEBUG("MmsBinaryDecodeMultipart: total length=%d\n", totalLength);
2243 presentationInfo.factor = MSG_PRESENTATION_NONE;
2244 presentationInfo.pCurPresentation = NULL;
2245 presentationInfo.pPrevPart = NULL;
2247 if (MmsBinaryDecodeEntries(pFile, &nEntries, totalLength) == false) {
2248 MSG_DEBUG("MmsBinaryDecodeMultipart: MmsBinaryDecodeEntries is fail.\n");
2253 MSG_DEBUG("MmsBinaryDecodeMultipart: decoding %dth multipart\n", index);
2255 offset = _MmsGetDecodeOffset();
2256 if (offset >= totalLength)
2259 if ((pMultipart = MsgAllocMultipart()) == NULL) {
2260 MSG_DEBUG("MmsBinaryDecodeMultipart: MsgAllocMultipart Fail \n");
2264 if (MmsBinaryDecodeEachPart(pFile, szFilePath, &(pMultipart->type), pMultipart->pBody, totalLength) == false) {
2265 MSG_DEBUG("MmsBinaryDecodeMultipart: MmsBinaryDecodeEachPart is fail.(nEntries = %d)\n", nEntries);
2269 if (pMsgType->param.type == MIME_APPLICATION_SMIL) {
2270 factor = MsgIsPresentationEx(&(pMultipart->type), pMsgType->param.szStart, (MimeType)pMsgType->param.type);
2272 factor = MSG_PRESENTATION_NONE;
2274 // priority 1 : content type match, 2: content location, 3: type
2275 if (presentationInfo.factor < factor) {
2276 // Presentation part
2277 presentationInfo.factor = factor;
2278 presentationInfo.pPrevPart = pPreMultipart;
2279 presentationInfo.pCurPresentation = pMultipart;
2282 if (pMsgBody->body.pMultipart == NULL) {
2283 /* first multipart */
2284 pMsgBody->body.pMultipart = pMultipart;
2285 pLastMultipart = pMultipart;
2286 pPreMultipart = NULL;
2287 } else if (pLastMultipart != NULL) {
2288 pPreMultipart = pLastMultipart;
2290 pLastMultipart->pNext = pMultipart;
2291 pLastMultipart = pMultipart;
2292 pPreMultipart = pMultipart;
2295 pMsgType->contentSize += pMultipart->pBody->size;
2299 MmsDebugPrintMulitpartEntry(pMultipart, index++);
2303 pMsgBody->size = totalLength - pMsgBody->offset;
2305 #ifdef __SUPPORT_DRM__
2306 if (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_REQUIRED)
2308 MsgConfirmPresentationPart(pMsgType, pMsgBody, &presentationInfo);
2310 if (MsgResolveNestedMultipart(pMsgType, pMsgBody) == false) {
2311 MSG_DEBUG("MmsBinaryDecodeMultipart : MsgResolveNestedMultipart failed \n");
2323 bool MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, int totalLength)
2326 bool bSuccess = false;
2327 UINT32 headerLength = 0;
2328 UINT32 bodyLength = 0;
2331 MSG_DEBUG("MmsBinaryDecodeEachPart: total length=%d\n", totalLength);
2335 if (__MmsBinaryDecodeUintvar(pFile, &headerLength, totalLength) <= 0) {
2336 MSG_DEBUG("MmsBinaryDecodeEachPart: Get header length fail \n");
2340 offset = _MmsGetDecodeOffset();
2341 if (offset >= totalLength)
2347 if (__MmsBinaryDecodeUintvar(pFile, &bodyLength, totalLength) <= 0) {
2348 MSG_DEBUG("MmsBinaryDecodeEachPart: Get body length fail\n");
2353 offset = _MmsGetDecodeOffset();
2354 if (offset >= totalLength)
2359 if (szFilePath != NULL)
2360 strncpy(pMsgType->szOrgFilePath, szFilePath, strlen(szFilePath));
2362 pMsgType->offset = _MmsGetDecodeOffset();
2363 pMsgType->size = headerLength;
2364 pMsgType->contentSize = bodyLength;
2366 if (pMsgType->offset > totalLength)
2369 length = MmsBinaryDecodeContentType(pFile, pMsgType, totalLength);
2371 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentType Fail \n");
2375 offset = _MmsGetDecodeOffset();
2376 if (offset >= totalLength)
2382 if (MmsBinaryDecodePartHeader(pFile, pMsgType, headerLength - length, totalLength) == false) {
2383 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentHeader Fail \n");
2387 offset = _MmsGetDecodeOffset();
2388 if (offset >= totalLength)
2393 if (szFilePath != NULL)
2394 strncpy(pMsgBody->szOrgFilePath, szFilePath, strlen(szFilePath));
2396 pMsgBody->offset = _MmsGetDecodeOffset();
2397 pMsgBody->size = bodyLength;
2399 if (pMsgBody->offset > totalLength)
2402 switch (pMsgType->type) {
2403 case MIME_APPLICATION_VND_WAP_MULTIPART_MIXED:
2404 case MIME_APPLICATION_VND_WAP_MULTIPART_RELATED:
2405 case MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC:
2406 case MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE:
2407 case MIME_MULTIPART_REPORT:
2408 case MIME_MULTIPART_MIXED:
2409 case MIME_MULTIPART_RELATED:
2410 case MIME_MULTIPART_ALTERNATIVE:
2412 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode multipart\n");
2414 if (MmsBinaryDecodeMultipart(pFile, szFilePath, pMsgType, pMsgBody, totalLength) == false) {
2415 MSG_DEBUG("MmsBinaryDecodeEachPart: MmsBinaryDecodeMultipart is fail.\n");
2419 offset = _MmsGetDecodeOffset();
2420 if (offset >= totalLength)
2426 #ifdef __SUPPORT_DRM__
2428 case MIME_APPLICATION_VND_OMA_DRM_MESSAGE: /* Contains forwardLock OR combined-delivery media part */
2429 MSG_DEBUG("MmsBinaryDecodeEachPart: MIME_APPLICATION_VND_OMA_DRM_MESSAGE Part \n");
2431 if (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_NOT_FIXED && MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_REQUIRED) {
2433 if (MmsBinaryDecodeDRMContent(pFile, szFilePath, pMsgType, pMsgBody, bodyLength, totalLength) == false)
2436 MmsDrm2SetConvertState(MMS_DRM2_CONVERT_REQUIRED);
2438 bSuccess = MmsBinaryDecodePartBody(pFile, bodyLength, totalLength);
2439 if (bSuccess == false) {
2440 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentBody Fail \n");
2444 offset = _MmsGetDecodeOffset();
2445 if (offset >= totalLength)
2450 case MIME_APPLICATION_VND_OMA_DRM_CONTENT: /* Contains seperate-delivery media part (DCF) */
2452 MSG_DEBUG("MmsBinaryDecodeEachPart: MIME_APPLICATION_VND_OMA_DRM_CONTENT Part \n");
2454 if (MmsBinaryDecodeDRMContent(pFile, szFilePath, pMsgType, pMsgBody, bodyLength, totalLength) == false)
2457 offset = _MmsGetDecodeOffset();
2458 if (offset >= totalLength)
2465 MSG_DEBUG("MmsBinaryDecodeEachPart: Other normal Part \n");
2467 bSuccess = MmsBinaryDecodePartBody(pFile, bodyLength, totalLength);
2468 if (bSuccess == false) {
2469 MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentBody Fail \n");
2473 offset = _MmsGetDecodeOffset();
2474 if (offset >= totalLength)
2491 #ifdef __SUPPORT_DRM__
2492 bool __MmsParseDCFInfo(FILE *pFile, MsgDRMInfo *pDrmInfo, int totalLength)
2495 UINT8 contentTypeLen = 0;
2496 UINT8 contentURILen = 0;
2497 char *szContentType = NULL;
2498 char *szContentURI = NULL;
2500 if (_MmsBinaryDecodeGetOneByte(pFile, &version, totalLength) == false) {
2501 MSG_DEBUG("__MmsParseDCFInfo: [version] GetOneByte fail\n");
2505 if (_MmsBinaryDecodeGetOneByte(pFile, &contentTypeLen, totalLength) == false) {
2506 MSG_DEBUG("__MmsParseDCFInfo: [contentTypeLen] GetOneByte fail\n");
2510 if (_MmsBinaryDecodeGetOneByte(pFile, &contentURILen, totalLength) == false) {
2511 MSG_DEBUG("__MmsParseDCFInfo: [contentURILen] GetOneByte fail\n");
2515 //Get media content-type (mime-type)
2516 szContentType = (char *)malloc(contentTypeLen + 1);
2517 if (szContentType == NULL)
2520 memset(szContentType, 0, contentTypeLen + 1);
2522 if (_MmsBinaryDecodeGetBytes(pFile, szContentType, contentTypeLen + 1, totalLength) < 0) {
2523 MSG_DEBUG("__MmsParseDCFInfo : contentType is invalid\n");
2526 gCurMmsDecodeBuffPos--;
2527 pDrmInfo->contentType = (MsgContentType)_MsgGetCode(MSG_TYPE, szContentType);
2530 //Get content-ID - 1.remover "cid:", 2.resolve "%hexa", 3.and copy the string
2531 szContentURI = (char *)malloc(contentURILen + 1);
2532 if (szContentURI == NULL)
2535 memset(szContentURI, 0, contentURILen + 1);
2537 if (_MmsBinaryDecodeGetBytes(pFile, szContentURI, contentURILen + 1, totalLength) == false) {
2538 MSG_DEBUG("__MmsParseDCFInfo : contentType is invalid\n");
2541 gCurMmsDecodeBuffPos--;
2542 pDrmInfo->szContentURI = MsgResolveContentURI(szContentURI);
2545 if (szContentType) {
2546 free(szContentType);
2547 szContentType = NULL;
2552 szContentURI = NULL;
2559 if (szContentType) {
2560 free(szContentType);
2561 szContentType = NULL;
2566 szContentURI = NULL;
2573 bool __MmsParseDCFHdr(FILE *pFile, MsgDRMInfo *pDrmInfo, UINT32 headerLen, int totalLength)
2575 char *szDCFHdr = NULL;
2580 /* add to parse DCF header such as,
2581 * Right-Issuer, Content-Name, and Content-Description.
2584 szDCFHdr = (char *)malloc(headerLen + 1);
2585 if (szDCFHdr == NULL) {
2586 MSG_DEBUG("__MmsParseDCFHdr: szDCFHdr alloc fail\n");
2589 memset(szDCFHdr, 0, headerLen + 1);
2591 offset = _MmsGetDecodeOffset();
2592 if (offset >= totalLength)
2595 if (MsgFseek(pFile, offset, SEEK_SET) < 0)
2598 if ((nRead = MsgReadFile(szDCFHdr, sizeof(char), headerLen, pFile)) == 0){
2601 szDCFHdr[nRead] = '\0';
2603 _MsgInitMsgType(&partType);
2604 _MsgParsePartHeader(&partType, szDCFHdr, headerLen);
2606 pDrmInfo->szContentName = partType.drmInfo.szContentName;
2607 pDrmInfo->szContentVendor = partType.drmInfo.szContentVendor;
2608 pDrmInfo->szContentDescription = partType.drmInfo.szContentDescription;
2609 pDrmInfo->szRightIssuer = partType.drmInfo.szRightIssuer;
2611 if (MmsBinaryDecodeMovePointer(pFile, offset + headerLen, totalLength) == false)
2634 bool MmsBinaryDecodeDRMContent(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int bodyLength, int totalLength)
2637 char szTempFilePath[MSG_FILEPATH_LEN_MAX] = MSG_DATA_PATH"drm.dcf";
2638 char *pRawData = NULL;
2639 bool isFileCreated = false;
2641 MSG_DEBUG("bodyLength: %d\n", bodyLength);
2643 offset = _MmsGetDecodeOffset();
2645 if (offset >= totalLength)
2648 if (szFilePath != NULL)
2649 strncpy(pMsgBody->szOrgFilePath, szFilePath, strlen(szFilePath));
2650 if (szFilePath != NULL)
2651 strncpy(pMsgType->szOrgFilePath, szFilePath, strlen(szFilePath));
2653 pRawData = (char *)malloc(bodyLength);
2654 if (pRawData == NULL) {
2655 MSG_DEBUG("pRawData alloc FAIL \n");
2659 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
2660 MSG_DEBUG("MsgFseek() returns -1 \n");
2663 if (MsgReadFile(pRawData, sizeof(char), bodyLength, pFile) != (size_t)bodyLength) {
2664 MSG_DEBUG("FmReadFile() returns false \n");
2667 if (MsgOpenCreateAndOverwriteFile(szTempFilePath, pRawData, bodyLength) == false) {
2668 MSG_DEBUG("MsgOpenCreateAndOverwriteFile() returns false \n");
2672 isFileCreated = true;
2673 MSG_DEBUG("MmsDrm2GetConvertState() [%d]", MmsDrm2GetConvertState());
2675 if (pMsgType->type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE && (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_FINISH)) {
2676 MmsDrm2SetConvertState(MMS_DRM2_CONVERT_REQUIRED);
2678 if (MsgDRM2GetDRMInfo(szTempFilePath, pMsgType) == false) {
2679 MSG_DEBUG("MsgDRM2GetDRMInfo() returns false \n");
2684 remove(szTempFilePath);
2685 isFileCreated = false;
2687 if (MmsBinaryDecodeMovePointer(pFile, offset + bodyLength, totalLength) == false)
2701 remove(szTempFilePath);
2712 bool MmsBinaryDecodeDRMMessage(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int fullBodyLength, int totalLength)
2715 char szTempFilePath[MSG_FILEPATH_LEN_MAX] = "/User/Msg/Mms/Temp/drm.dm";
2716 char *pRawData = NULL;
2717 bool isFileCreated = false;
2719 offset = _MmsGetDecodeOffset();
2720 if (offset >= totalLength)
2723 if (szFilePath != NULL)
2724 strncpy(pMsgBody->szOrgFilePath, szFilePath, strlen(szFilePath));
2725 if (szFilePath != NULL)
2726 strncpy(pMsgType->szOrgFilePath, szFilePath, strlen(szFilePath));
2728 pRawData = (char *)malloc(fullBodyLength);
2729 if (pRawData == NULL) {
2730 MSG_DEBUG("pRawData alloc FAIL \n");
2734 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
2735 MSG_DEBUG("MsgFseek() returns -1 \n");
2739 if (MsgReadFile(pRawData, sizeof(char), fullBodyLength, pFile)!= (size_t)fullBodyLength) {
2740 MSG_DEBUG("FmReadFile() returns false \n");
2744 if (MsgOpenCreateAndOverwriteFile(szTempFilePath, pRawData, fullBodyLength) == false) {
2745 MSG_DEBUG("MsgOpenCreateAndOverwriteFile() returns false \n");
2748 isFileCreated = true;
2750 if (strstr(szTempFilePath, ".dm")) {
2751 char szConvertedFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
2753 if (MsgDrmConvertDmtoDcfType(szTempFilePath, szConvertedFilePath)) {
2754 remove(szTempFilePath);
2755 memset(szTempFilePath, 0, MSG_FILEPATH_LEN_MAX);
2756 strncpy(szTempFilePath, szConvertedFilePath, MSG_FILEPATH_LEN_MAX-1);
2760 if (MsgDRM2GetDRMInfo(szTempFilePath, pMsgType) == false) {
2761 MSG_DEBUG("MsgDRM2GetDRMInfo() returns false \n");
2765 if (remove(szTempFilePath) != 0)
2766 MSG_DEBUG("remove fail");
2768 isFileCreated = false;
2770 if (MmsBinaryDecodeMovePointer(pFile, offset + fullBodyLength, totalLength) == false)
2782 if (isFileCreated) {
2783 if (remove(szTempFilePath) != 0)
2784 MSG_DEBUG("remove fail");
2793 static int __MmsDrm2BinaryEncodeUintvarLen(UINT32 integer)
2797 /* Find encoded unitvar length */
2798 if (integer <= MMS_UINTVAR_LENGTH_1) {
2801 if (integer <= MMS_UINTVAR_LENGTH_2) {
2804 if (integer <= MMS_UINTVAR_LENGTH_3) {
2816 static bool __MmsDrm2BinaryEncodeUintvar(UINT32 integer, int length, char *pszOutput)
2818 const char ZERO = 0x00;
2820 char szReverse[MSG_STDSTR_LONG] = {0, };
2826 source.integer = integer;
2827 memset(szReverse, 0, MSG_STDSTR_LONG);
2829 /* Seperate integer to 4 1 byte integer */
2830 szReverse[3] = source.bytes[3] & 0x0f;
2831 szReverse[0] = source.bytes[0];
2832 szReverse[0] = szReverse[0] & 0x7f;
2834 while (length >= i) {// initially, i = 2
2835 /* Move integer bit to proper position */
2836 source.integer = source.integer << 1;
2837 source.integer = source.integer >> 8;
2838 source.bytes[3] = ZERO;
2840 /* Retrive 1 encode uintvar */
2841 szReverse[i-1] = source.bytes[0];
2842 szReverse[i-1] = szReverse[i-1] | 0x80;
2846 for (i=0; i < length; i++)
2847 pszOutput[i] = szReverse[length - i - 1];
2853 static int __MmsDrm2GetEntriesValueLength(FILE *pFile, int orgOffset)
2855 char szEntries[5] = {0, };
2857 int j = 0; //j is the length of nEntries value
2859 if (MsgReadFile(szEntries, sizeof(char), 4, pFile) != (size_t)4) {
2860 MSG_DEBUG("__MmsDrm2GetEntriesValueLength: FmReadFile() returns false \n");
2865 oneByte = szEntries[j++];
2867 if (oneByte <= 0x7f)
2871 //move file pointer to point nEntries
2872 if (MsgFseek(pFile, orgOffset, SEEK_SET) < 0) {
2873 MSG_DEBUG("__MmsDrm2GetEntriesValueLength: fail to seek file pointer\n");
2881 static bool __MmsDrm2WriteDataToConvertedFile(FILE *pSrcFile, FILE *pDestinationFile, char *pszMmsLoadTempBuf, int length, int bufLen)
2883 int loadLen = 0, totalLoadLen = 0, nRead = 0;
2885 for (int i=0; i<(length/bufLen)+1; i++) {
2886 loadLen = (length-totalLoadLen < bufLen) ? length-totalLoadLen : bufLen;
2888 memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
2890 if (MsgReadFile(pszMmsLoadTempBuf, sizeof(char), loadLen, pSrcFile) != (size_t)loadLen) {
2891 MSG_DEBUG("__MmsDrm2WriteDataToConvertedFile: FmReadFile() returns false \n");
2895 if (MsgWriteFile(pszMmsLoadTempBuf, sizeof(char), loadLen, pDestinationFile) != (size_t)loadLen) {
2896 MSG_DEBUG("__MmsDrm2WriteDataToConvertedFile: File Writing is failed.\n");
2900 totalLoadLen += nRead;
2907 /*************************************************************************
2908 * description : make new message file converting CD & FL part of original message file to SD type
2911 - bool : result of converting
2912 **************************************************************************/
2913 bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
2916 FILE *hConvertedFile = NULL;
2917 FILE *hTempFile = NULL;
2919 MsgMultipart *pMultipart = NULL;
2920 char szTempFilePath[MSG_FILEPATH_LEN_MAX] = MSG_DATA_PATH"Drm_Convert";
2921 char szTempFile[MSG_FILEPATH_LEN_MAX] = MSG_DATA_PATH"temp.dm";
2922 char *pszMmsLoadTempBuf = NULL;
2923 char *pszOrgData = NULL;
2925 int bufLen = MMS_DRM2_CONVERT_BUFFER_MAX;
2928 MSG_DEBUG("start convert~~~~~~\n");
2930 pFile = MsgOpenFile(szOriginFilePath, "rb");
2931 if (pFile == NULL) {
2932 MSG_DEBUG("Open decode temporary file fail\n");
2936 hConvertedFile = MsgOpenFile(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, "wb+");
2937 if (hConvertedFile == NULL) {
2938 MSG_DEBUG("Open decode temporary file fail\n");
2942 pszMmsLoadTempBuf = (char*)malloc(MMS_DRM2_CONVERT_BUFFER_MAX + 1);
2943 if (pszMmsLoadTempBuf == NULL) {
2944 MSG_DEBUG("malloc for pszMmsLoadTempBuf failed\n");
2947 memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
2950 length = mmsHeader.msgBody.offset;
2951 if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
2952 MSG_DEBUG("Write header data fail\n");
2956 curOffset += length; //change offset
2959 if (MsgIsMultipart(mmsHeader.msgType.type) == true)
2962 length = __MmsDrm2GetEntriesValueLength(pFile, curOffset); // getting nEntries value's length
2964 if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
2965 MSG_DEBUG("Write nEntries fail\n");
2969 curOffset += length; //change offset
2971 // each Multipart entry copy
2972 pMultipart = mmsHeader.msgBody.body.pMultipart;
2974 while (pMultipart) {
2975 if (pMultipart->type.type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE) {
2976 int orgDataLen = pMultipart->pBody->size;
2979 MSG_DEBUG("Write MIME_APPLICATION_VND_OMA_DRM_MESSAGE multipart data(orgDataLen = %d).\n", orgDataLen);
2981 pszOrgData = (char *)malloc(orgDataLen + 1);
2982 if (pszOrgData == NULL) {
2983 MSG_DEBUG("pszOrgData is NULL \n");
2986 memset(pszOrgData, 0, orgDataLen + 1);
2988 // move file pointer to data
2989 if (MsgFseek(pFile, pMultipart->pBody->offset, SEEK_SET) < 0) {
2990 MSG_DEBUG("fail to seek file pointer 1\n");
2994 if (MsgReadFile(pszOrgData, sizeof(char), orgDataLen, pFile) != (size_t)orgDataLen) {
2995 MSG_DEBUG("FmReadFile() returns false for orgData\n");
2999 if((hFile = MsgOpenFile(szTempFile, "wb+")) == NULL) {
3000 MSG_DEBUG("file open failed [%s]", szTempFile);
3004 if (MsgWriteFile(pszOrgData, sizeof(char), orgDataLen, hFile) != (size_t)orgDataLen) {
3005 MSG_DEBUG("File write error");
3015 MsgCloseFile(hFile);
3019 // --> invoking drm agent api, converting data part start
3020 MSG_DEBUG("start data part convert by callling drm agent api\n");
3023 ret = MsgDrmConvertDmtoDcfType(szTempFile, szTempFilePath);
3024 MSG_DEBUG("MsgDrmConvertDmtoDcfType returned %s", ret ? "true": "false");
3026 if (MsgGetFileSize(szTempFilePath, &nSize) == false) {
3027 MSG_DEBUG("MsgGetFileSize error");
3030 MSG_DEBUG("end data part convert(converted data len = %d)\n", nSize);
3032 // move file pointer to the head of multipart
3033 if (MsgFseek(pFile, curOffset, SEEK_SET) < 0) {
3034 MSG_DEBUG("fail to seek file pointer 2\n");
3038 // read headerLen, dataLen
3039 length = pMultipart->type.offset - curOffset;
3040 memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
3041 if (MsgReadFile(pszMmsLoadTempBuf, sizeof(char), length, pFile) != (size_t)length) {
3042 MSG_DEBUG("FmReadFile() returns false for headerLen, dataLen\n");
3046 curOffset += length;
3048 // change dataLen based on converted data
3053 char szOutput[MSG_STDSTR_LONG] = {0, };
3056 oneByte = pszMmsLoadTempBuf[j++];
3058 if (oneByte <= 0x7f)
3062 encodeLen = __MmsDrm2BinaryEncodeUintvarLen((UINT32)nSize);
3063 __MmsDrm2BinaryEncodeUintvar((UINT32)nSize, encodeLen, szOutput);
3065 strncpy(&(pszMmsLoadTempBuf[j]), szOutput, encodeLen);
3066 pszMmsLoadTempBuf[j+encodeLen] = '\0';
3068 if (MsgWriteFile(pszMmsLoadTempBuf, sizeof(char), length, hConvertedFile) != (size_t)length) {
3069 MSG_DEBUG("Drm2WriteConvertData: FmWriteFile() returns false for dateLen\n");
3075 length = pMultipart->pBody->offset - pMultipart->type.offset;
3077 if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
3078 MSG_DEBUG("Drm2WriteConvertData: Write content type, headers fail\n");
3082 curOffset += length;
3084 // write converted data
3085 hTempFile = MsgOpenFile(szTempFilePath, "rb");
3086 if (hTempFile == NULL) {
3087 MSG_DEBUG("Open decode temporary file fail\n");
3093 if (__MmsDrm2WriteDataToConvertedFile(hTempFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
3094 MSG_DEBUG("Write converted data fail\n");
3098 if (hTempFile != NULL) {
3099 MsgCloseFile(hTempFile);
3103 curOffset += pMultipart->pBody->size;
3105 // move file pointer to the head of multipart
3106 if (MsgFseek(pFile, curOffset, SEEK_SET) < 0) {
3107 MSG_DEBUG("fail to seek file pointer \n");
3110 } else { // it doesn't need to convert if it is not CD or FL
3111 MSG_DEBUG("Write normal multipart data\n");
3113 length = pMultipart->pBody->offset + pMultipart->pBody->size - curOffset;
3115 if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
3116 MSG_DEBUG("Write multipart data fail \n");
3120 curOffset += length;
3123 pMultipart = pMultipart->pNext;
3127 MSG_DEBUG("end convert~~~~~~\n");
3129 if (pFile != NULL) {
3130 MsgCloseFile(pFile);
3134 if (hConvertedFile != NULL) {
3135 MsgCloseFile(hConvertedFile);
3136 hConvertedFile = NULL;
3139 if (pszMmsLoadTempBuf) {
3140 free(pszMmsLoadTempBuf);
3141 pszMmsLoadTempBuf = NULL;
3150 remove(szTempFilePath);
3156 if (pFile != NULL) {
3157 MsgCloseFile(pFile);
3161 if (hConvertedFile != NULL) {
3162 MsgCloseFile(hConvertedFile);
3163 hConvertedFile = NULL;
3166 if (hTempFile != NULL) {
3167 MsgCloseFile(hTempFile);
3171 if (pszMmsLoadTempBuf) {
3172 free(pszMmsLoadTempBuf);
3173 pszMmsLoadTempBuf = NULL;
3183 MsgCloseFile(hFile);
3187 if (remove(szTempFile) != 0)
3188 MSG_DEBUG("remove fail");
3190 if (remove(szTempFilePath) != 0)
3191 MSG_DEBUG("remove fail");
3193 if (remove(MMS_DECODE_DRM_CONVERTED_TEMP_FILE) != 0)
3194 MSG_DEBUG("remove fail"); //remove convertin result if it goes to __CATCH
3200 /*************************************************************************
3201 * description : Function for decoding a converted file
3204 - bool : result of converting
3205 **************************************************************************/
3206 bool MmsDrm2DecodeConvertedMsg(int msgID, char *pszFullPath)
3208 FILE *hConvertedFile = NULL;
3211 MSG_DEBUG("MmsDrm2DecodeConvertedMsg: start re-decoding~~~~~~\n");
3214 _MsgFreeDRMInfo(&mmsHeader.msgType.drmInfo);
3215 _MsgFreeBody(&mmsHeader.msgBody, mmsHeader.msgType.type);
3218 _MmsUnregisterDecodeBuffer();
3221 _MmsRegisterDecodeBuffer(gszMmsLoadBuf1, gszMmsLoadBuf2, MSG_MMS_DECODE_BUFFER_MAX);
3223 // open converted file
3224 if ((hConvertedFile = MsgOpenFile(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, "rb")) == NULL) {
3225 MSG_DEBUG("MmsDrm2ReDecodeMsg: opening temporary file failed\n");
3229 if (MsgGetFileSize(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, &nSize) == false) {
3230 MSG_DEBUG("MsgGetFileSize: failed\n");
3234 if (!MmsBinaryDecodeMsgHeader(hConvertedFile, nSize)) {
3235 MSG_DEBUG("MmsDrm2ReDecodeMsg: decoding header(binary mode) failed\n");
3239 if (!MmsBinaryDecodeMsgBody(hConvertedFile, pszFullPath, nSize)) {
3240 MSG_DEBUG("MmsDrm2ReDecodeMsg: decoding body failed\n");
3244 if (hConvertedFile != NULL) {
3245 MsgCloseFile(hConvertedFile);
3246 hConvertedFile = NULL;
3253 if (hConvertedFile != NULL) {
3254 MsgCloseFile(hConvertedFile);
3256 if (remove(MMS_DECODE_DRM_CONVERTED_TEMP_FILE) != 0)
3257 MSG_DEBUG("remove fail");
3259 hConvertedFile = NULL;
3266 bool MmsDrm2ReadMsgConvertedBody(MSG_MESSAGE_INFO_S *pMsg, bool bSavePartsAsTempFiles, bool bRetrieved, char *retrievedPath)
3269 MmsPluginStorage::instance()->getMmsMessage(&pMmsMsg);
3270 _MmsUnregisterDecodeBuffer();
3271 #ifdef __SUPPORT_DRM__
3272 _MsgFreeDRMInfo(&pMmsMsg->msgType.drmInfo);
3274 _MsgFreeBody(&pMmsMsg->msgBody, pMmsMsg->msgType.type);
3276 if (_MmsReadMsgBody(pMsg->msgId, bSavePartsAsTempFiles, bRetrieved, retrievedPath) == false) {
3277 MSG_DEBUG("MmsDrm2ReadMsgConvertedBody: _MmsReadMsgBody with converted file is failed\n");
3286 /* --------------------------------------------------------------------
3288 * B I N A R Y D E C D E U T I L I T Y
3290 * --------------------------------------------------------------------*/
3292 bool _MmsBinaryDecodeGetOneByte(FILE *pFile, UINT8 *pOneByte, int totalLength)
3294 int length = gMmsDecodeMaxLen - gCurMmsDecodeBuffPos;
3296 if (pFile == NULL || pOneByte == NULL)
3298 MSG_DEBUG("_MmsBinaryDecodeGetOneByte: invalid file or buffer\n");
3303 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3304 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3305 MSG_DEBUG("_MmsBinaryDecodeGetOneByte: fail to load to buffer \n");
3310 *pOneByte = gpCurMmsDecodeBuff[gCurMmsDecodeBuffPos++];
3320 * @remark: bufLen < gMmsDecodeMaxLen
3322 bool _MmsBinaryDecodeGetBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength)
3324 int length = gMmsDecodeMaxLen - gCurMmsDecodeBuffPos;
3328 if (pFile == NULL || szBuff == NULL || bufLen == 0 || bufLen > gMmsDecodeMaxLen)
3331 memset(szBuff, 0, bufLen);
3333 if (length < bufLen) {
3334 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3335 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3336 MSG_DEBUG("_MmsBinaryDecodeGetBytes: fail to load to buffer \n");
3341 for (i = 0; i < bufLen - 1; i++)
3342 szBuff[i] = gpCurMmsDecodeBuff[gCurMmsDecodeBuffPos++];
3345 gCurMmsDecodeBuffPos++; //NULL
3355 bool _MmsBinaryDecodeGetLongBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength)
3359 if (pFile == NULL || szBuff == NULL || bufLen == 0)
3362 memset(szBuff, 0, bufLen);
3364 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3365 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3366 MSG_DEBUG("_MmsBinaryDecodeGetLongBytes: fail to load to buffer \n");
3370 while ((bufLen - iPos) >= gMmsDecodeMaxLen) {
3371 if (_MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, gMmsDecodeMaxLen, totalLength) == false) {
3372 MSG_DEBUG("_MmsBinaryDecodeGetLongBytes: 1. _MmsBinaryDecodeGetBytes fail \n");
3376 iPos += gMmsDecodeMaxLen;
3379 if ((bufLen - iPos) > 0) {
3380 if (_MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, (bufLen - iPos), totalLength) == false) {
3381 MSG_DEBUG("_MmsBinaryDecodeGetLongBytes: 2. _MmsBinaryDecodeGetBytes fail \n");
3385 iPos += (bufLen - iPos);
3396 * Decode uintvar to 32bit unsigned integer
3398 * @param pEncodedData [in] encoded data
3399 * @param pUintVar [out] Decode uintvar (32bit unsigned integer)
3400 * @return The length of uintvar (-1, if cannot be converted to a uintvar)
3402 * 0 XXXXXXX -> 0-bit: continue bit & 1~7bit: integer value
3405 static const UINT32 uintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00100000, 0x08000000 };
3407 static int __MmsBinaryDecodeUintvar(FILE *pFile, UINT32 *pUintVar, int totalLength)
3411 UINT32 decodedUintvar = 0;
3412 UINT8 iBuff[5] = {0};
3413 int length = MSG_MMS_DECODE_BUFFER_MAX - gCurMmsDecodeBuffPos;
3416 if (pFile == NULL || pUintVar == NULL)
3420 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3421 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3422 MSG_DEBUG("__MmsBinaryDecodeUintvar: fail to load to buffer \n");
3428 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
3431 if (oneByte > 0x7f) {
3432 iBuff[count++] = oneByte;
3434 iBuff[count++] = oneByte;
3439 MSG_DEBUG("__MmsBinaryDecodeUintvar : legnth is too long\n");
3444 for (int i = 0; i < count; i++)
3445 decodedUintvar += (uintvarDecodeTable[i] * (iBuff[count-(i+1)]&0x7f));
3447 *pUintVar = decodedUintvar;
3452 gCurMmsDecodeBuffPos -= count;
3458 * Decode uintvar to 32bit unsigned integer by uintvar length
3460 * @param pEncodedData [in] uintvar encoded data
3461 * @param length [in] length of integer value
3462 * @return unsigned integer value
3464 static UINT32 __MmsHeaderDecodeIntegerByLength(FILE *pFile, UINT32 length, int totalLength)
3474 returner.integer = 0;
3481 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
3482 MSG_DEBUG("__MmsHeaderDecodeIntegerByLength: _MmsBinaryDecodeGetOneByte fail\n");
3486 if (oneByte > 0x7f) {
3487 return (oneByte & 0x7f);
3496 pData = (char *)malloc(length + 1);
3497 if (pData == NULL) {
3498 MSG_DEBUG("__MmsHeaderDecodeIntegerByLength: pData alloc fail\n");
3501 memset(pData, 0, length + 1);
3503 if (_MmsBinaryDecodeGetBytes(pFile, pData, length + 1, totalLength) == false) {
3504 MSG_DEBUG("__MmsHeaderDecodeIntegerByLength: _MmsBinaryDecodeGetOneByte fail\n");
3508 gCurMmsDecodeBuffPos--; // - NULL
3510 for (i= 0; i < length; i++)
3511 returner.seg[length - (i+1)] = pData[i];
3518 return returner.integer;
3527 return returner.integer;
3532 * Decode uintvar to 32bit unsigned integer by uintvar length
3534 * @param pEncodedData [in] uintvar encoded data
3535 * @param pInteger [out] Decode integer value (long/short)
3536 * @return unsigned integer value (-1, if cannot be converted to unsigned integer value)
3538 static bool __MmsBinaryDecodeInteger(FILE *pFile, UINT32 *pInteger, int *pIntLen, int totalLength)
3548 if (pInteger == NULL)
3551 returner.integer = 0;
3554 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
3555 MSG_DEBUG("__MmsBinaryDecodeInteger: GetOneByte fail\n");
3559 if (oneByte < 0x1F) /* long integer : WAP-230-WSP-20010118-p, Proposed Version 18 January 2001 (pp.86) */
3561 pData = (char *)malloc(oneByte + 1);
3562 if (pData == NULL) {
3563 MSG_DEBUG("__MmsBinaryDecodeInteger: pData memalloc fail\n");
3566 memset(pData, 0, oneByte + 1);
3568 // Even NULL is copied in the _MmsBinaryDecodeGetBytes
3569 if (_MmsBinaryDecodeGetBytes(pFile, pData, oneByte + 1, totalLength) == false) {
3570 MSG_DEBUG("__MmsBinaryDecodeInteger: GetBytes fail\n");
3574 gCurMmsDecodeBuffPos--; // - NULL
3584 for (i = 0; i < length; i++)
3585 returner.seg[length - (i+1)] = pData[i];
3587 *pInteger = returner.integer;
3588 *pIntLen = oneByte + 1;
3589 } else if (oneByte >= 0x80) {
3590 /* short integer : WAP-230-WSP-20010118-p, Proposed Version 18 January 2001 (pp.86) */
3591 *pInteger = oneByte & 0x7f;
3606 gCurMmsDecodeBuffPos--;
3618 * Decode uintvar to 32bit unsigned integer by uintvar length
3620 * @return 1 : Success
3621 * 0 : This is not Value Length type data
3622 * -1 : Requires System error report
3624 static int __MmsDecodeValueLength(FILE *pFile, UINT32 *pValueLength, int totalLength)
3632 * value-length = short-length | (Length-quote Length)
3633 * = 0~30 | 31 + Uintvar-length
3636 if (pFile == NULL || pValueLength == NULL)
3641 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
3642 gCurMmsDecodeBuffPos--;
3646 if (0x00 < oneByte && oneByte < 0x1F) {
3649 *pValueLength = oneByte;
3651 } else if (oneByte == 0x1F) {
3652 /* Length-quote = 0x1F */
3654 length = __MmsBinaryDecodeUintvar(pFile, &uintvar, totalLength);
3656 MSG_DEBUG("__MmsDecodeValueLength: __MmsBinaryDecodeUintvar fail..\n");
3659 length ++; // + length-quote
3660 *pValueLength = uintvar;
3662 MSG_DEBUG("__MmsDecodeValueLength: not a value length type data\n");
3663 gCurMmsDecodeBuffPos--;
3670 MSG_DEBUG("__MmsDecodeValueLength: getting data fail\n");
3677 * Decode uintvar to 32bit unsigned integer by uintvar length
3679 * @return 1 : Success
3680 * 0 : This is not Value Length type data
3681 * -1 : Requires System error report
3682 * @ defference : if there is not length-quote, consider it as short length.
3684 static int __MmsDecodeValueLength2(FILE *pFile, UINT32 *pValueLength, int totalLength)
3692 * value-length = short-length | (Length-quote Length)
3693 * = 0~30 | 31 + Uintvar-length
3696 if (pFile == NULL || pValueLength == NULL)
3701 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
3702 gCurMmsDecodeBuffPos--;
3706 if (0x00 < oneByte && oneByte < 0x1F) {
3709 *pValueLength = oneByte;
3711 } else if (oneByte == 0x1F) {
3712 /* Length-quote = 0x1F */
3714 length = __MmsBinaryDecodeUintvar(pFile, &uintvar, totalLength);
3716 MSG_DEBUG("__MmsDecodeValueLength2: __MmsBinaryDecodeUintvar fail..\n");
3719 length ++; // + length-quote
3720 *pValueLength = uintvar;
3722 MSG_DEBUG("__MmsDecodeValueLength2: there is not length-quote, consider it as short length.\n");
3723 *pValueLength = oneByte;
3730 MSG_DEBUG("__MmsDecodeValueLength2: getting data fail\n");
3737 * Decode QuotedString
3739 * @param pEncodedData [in] QuotedString encoded data
3740 * @param szBuff [out] Decoded quoted string
3741 * @param bufLen [out] Buffer length
3742 * @return length of quoted string
3744 static int __MmsBinaryDecodeQuotedString(FILE *pFile, char *szBuff, int bufLen, int totalLength)
3750 int returnLength = 0;
3753 * Quoted-string = <Octet 34> *TEXT End-of-string
3754 * The TEXT encodes an RFC2616 Quoted-string with the enclosing quotation-marks <"> removed
3757 if (pFile == NULL || szBuff == NULL || bufLen <= 0)
3760 memset(szBuff, 0, bufLen);
3762 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3763 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3764 MSG_DEBUG("__MmsBinaryDecodeQuotedString: 1. fail to load to buffer \n");
3768 length = strlen(gpCurMmsDecodeBuff) + 1; // + NULL
3773 while (length > gMmsDecodeBufLen) {
3774 if (gMmsDecodeBufLen <= 0) {
3775 MSG_DEBUG("__MmsBinaryDecodeQuotedString: gMmsDecodeBufLen <= 0 \n");
3776 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
3777 gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
3778 gpCurMmsDecodeBuff[3], gpCurMmsDecodeBuff[4]);
3779 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
3780 gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
3781 gpCurMmsDecodeBuff[8], gpCurMmsDecodeBuff[9]);
3782 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
3783 gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
3784 gpCurMmsDecodeBuff[13], gpCurMmsDecodeBuff[14]);
3785 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
3786 gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
3787 gpCurMmsDecodeBuff[18], gpCurMmsDecodeBuff[19]);
3791 pData = (char *)malloc(gMmsDecodeBufLen + 1);
3795 memset(pData, 0, gMmsDecodeBufLen + 1);
3797 if (_MmsBinaryDecodeGetBytes(pFile, pData, gMmsDecodeBufLen, totalLength) == false)
3800 returnLength += gMmsDecodeBufLen;
3802 if ((bufLen - iPos) > 0) {
3803 readBytes = (gMmsDecodeBufLen < (bufLen - iPos)) ? gMmsDecodeBufLen : (bufLen - iPos);
3804 if (iPos == 0 && (pData[0] == MARK)) {
3805 /* MARK: check first time only */
3807 strncpy(szBuff + iPos, (char*)pData + 1, readBytes - 1);
3808 iPos += (readBytes - 1);
3810 strncpy(szBuff + iPos, (char*)pData, readBytes);
3820 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3821 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3822 MSG_DEBUG("__MmsBinaryDecodeText: 2. fail to load to buffer \n");
3825 length = strlen(gpCurMmsDecodeBuff) + 1; // + NULL
3829 pData = (char *)malloc(length);
3833 if (_MmsBinaryDecodeGetBytes(pFile, pData, length, totalLength) == false)
3836 returnLength += length;
3838 if ((bufLen - iPos) > 0) {
3839 /* read until NULL from raw data, and copy only string */
3840 readBytes = (length < (bufLen - iPos)) ? length : (bufLen - iPos);
3841 if (iPos == 0 && (pData[0] == MARK)) {
3842 /* MARK: check first time only */
3843 strncpy(szBuff + iPos, (char*)pData + 1, readBytes - 1);
3844 iPos += (readBytes - 1);
3846 strncpy(szBuff + iPos, (char*)pData, readBytes - 1); // + NULL
3857 szBuff[bufLen - 1] = '\0';
3859 return returnLength;
3879 * @param pEncodedData [in] QuotedString encoded data
3880 * @param szBuff [out] Decoded quoted string
3881 * @param bufLen [out] Buffer length
3882 * @return length of decode text string
3884 static int __MmsBinaryDecodeText(FILE *pFile, char *szBuff, int bufLen, int totalLength)
3889 int returnLength = 0;
3891 bool bQuote = false;
3895 * Text-String = [QUOTE]*TEXT end_of_string
3896 * [QUOTE]*(128~255)\0
3900 if (pFile == NULL || szBuff == NULL || bufLen <= 0)
3903 offset = _MmsGetDecodeOffset();
3904 if (offset >= totalLength)
3907 memset(szBuff, 0, bufLen);
3909 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3910 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3911 MSG_DEBUG("__MmsBinaryDecodeText: 1. fail to load to buffer \n");
3915 length = strlen(gpCurMmsDecodeBuff) + 1; // + NULL
3920 while (length > gMmsDecodeBufLen) {
3921 if (gMmsDecodeBufLen <= 0) {
3922 MSG_DEBUG("__MmsBinaryDecodeQuotedString: gMmsDecodeBufLen <= 0 \n");
3923 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
3924 gpCurMmsDecodeBuff[3], gpCurMmsDecodeBuff[4]);
3925 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
3926 gpCurMmsDecodeBuff[8], gpCurMmsDecodeBuff[9]);
3927 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
3928 gpCurMmsDecodeBuff[13], gpCurMmsDecodeBuff[14]);
3929 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
3930 gpCurMmsDecodeBuff[18], gpCurMmsDecodeBuff[19]);
3934 pData = (char *)malloc(gMmsDecodeBufLen + 1);
3938 memset(pData, 0, gMmsDecodeBufLen + 1);
3940 if (_MmsBinaryDecodeGetBytes(pFile, pData, gMmsDecodeBufLen, totalLength) == false)
3943 if ((bufLen - iPos) > 0) {
3944 readBytes = (gMmsDecodeBufLen < (bufLen - iPos)) ? gMmsDecodeBufLen : (bufLen - iPos);
3945 if (iPos == 0 && (pData[0] == QUOTE) && (bQuote == false)) {
3946 /* QUOTE: check first time only */
3948 strncpy(szBuff + iPos, (char*)pData + 1, readBytes - 1);
3949 iPos += (readBytes - 1);
3952 strncpy(szBuff + iPos, (char*)pData, readBytes);
3962 returnLength += gMmsDecodeBufLen;
3964 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
3965 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
3966 MSG_DEBUG("__MmsBinaryDecodeText: 2. fail to load to buffer \n");
3969 length = strlen(gpCurMmsDecodeBuff) + 1; // + NULL
3973 pData = (char *)malloc(length);
3977 memset(pData, 0, length);
3979 if (_MmsBinaryDecodeGetBytes(pFile, pData, length, totalLength) == false)
3982 if ((bufLen - iPos) > 0) {
3983 readBytes = (length < (bufLen - iPos)) ? length : (bufLen - iPos);
3984 if (iPos == 0 && (pData[0] == QUOTE) && (bQuote == false)) {
3985 /* QUOTE: check first time only */
3987 strncpy(szBuff + iPos, (char*)pData + 1, readBytes - 1);
3988 iPos += (readBytes - 1);
3991 strncpy(szBuff + iPos, (char*)pData, readBytes - 1); // + NULL
4001 returnLength += length; // + NULL
4004 szBuff[bufLen - 1] = '\0';
4006 return returnLength;
4013 MmsBinaryDecodeMovePointer(pFile, offset, totalLength);
4028 static char* __MmsBinaryDecodeText2(FILE *pFile, int totalLength, int *pLength)
4033 char *szBuff = NULL;
4034 char *szTempPtr = NULL;
4035 bool bQuote = false;
4039 * Text-String = [QUOTE]*TEXT end_of_string
4040 * [QUOTE]*(128~255)\0
4044 if (pFile == NULL || pLength == NULL)
4048 offset = _MmsGetDecodeOffset();
4049 if (offset >= totalLength)
4052 if (MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
4053 gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
4054 MSG_DEBUG("__MmsBinaryDecodeTextLen: 1. fail to load to buffer \n");
4058 length = strlen(gpCurMmsDecodeBuff) + 1;
4063 while (length > gMmsDecodeBufLen) {
4064 if (gMmsDecodeBufLen <= 0) {
4065 MSG_DEBUG("__MmsBinaryDecodeQuotedString: gMmsDecodeBufLen <= 0 \n");
4066 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
4067 gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
4068 gpCurMmsDecodeBuff[3], gpCurMmsDecodeBuff[4]);
4069 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
4070 gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
4071 gpCurMmsDecodeBuff[8], gpCurMmsDecodeBuff[9]);
4072 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
4073 gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
4074 gpCurMmsDecodeBuff[13], gpCurMmsDecodeBuff[14]);
4075 MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
4076 gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
4077 gpCurMmsDecodeBuff[18], gpCurMmsDecodeBuff[19]);
4081 pData = (char *)malloc(gMmsDecodeBufLen + 1);
4085 memset(pData, 0, gMmsDecodeBufLen + 1);
4087 if (_MmsBinaryDecodeGetBytes(pFile, pData, gMmsDecodeBufLen, totalLength) == false)
4090 if (szBuff == NULL) {
4091 szBuff = (char *)malloc(gMmsDecodeBufLen + 1);
4093 szTempPtr = (char *)realloc(szBuff, curLen + gMmsDecodeBufLen + 1);
4095 //NULL pointer check for realloc
4096 if (szTempPtr == NULL) {
4105 memset(szBuff + curLen, 0, gMmsDecodeBufLen + 1);
4107 if (curLen == 0 && (pData[0] == QUOTE) && (bQuote == false)) {
4108 /* QUOTE: check first time only */
4110 strncpy(szBuff + curLen, (char*)pData + 1, gMmsDecodeBufLen - 1);
4111 curLen += (gMmsDecodeBufLen - 1);
4114 strncpy(szBuff + curLen, (char*)pData, gMmsDecodeBufLen);
4115 curLen += gMmsDecodeBufLen;
4123 *pLength += gMmsDecodeBufLen;
4125 if (MsgLoadDataToDecodeBuffer(pFile,
4126 &gpCurMmsDecodeBuff,
4127 &gCurMmsDecodeBuffPos,
4128 &gMmsDecodeCurOffset,
4133 totalLength) == false)
4135 MSG_DEBUG("__MmsBinaryDecodeText: 2. fail to load to buffer \n");
4138 length = strlen(gpCurMmsDecodeBuff) + 1;
4142 pData = (char *)malloc(length);
4143 if (pData == NULL) {
4147 if (_MmsBinaryDecodeGetBytes(pFile, pData, length, totalLength) == false) {
4151 if (szBuff == NULL) {
4152 szBuff = (char *)malloc(length);
4154 szTempPtr = (char *)realloc(szBuff, curLen + length);
4156 //NULL pointer check for realloc
4157 if (szTempPtr == NULL)
4163 if (szBuff == NULL) {
4167 memset(szBuff + curLen, 0, length);
4169 if (curLen == 0 && (pData[0] == QUOTE) && (bQuote == false)) {
4170 /* QUOTE: check first time only */
4172 strncpy(szBuff + curLen, (char*)pData + 1, length - 2);
4173 curLen += (length - 1);
4176 strncpy(szBuff + curLen, (char*)pData, length - 1);
4185 *pLength += length; // + NULL
4194 MmsBinaryDecodeMovePointer(pFile, offset, totalLength);
4217 * @param pEncodedData [in] QuotedString encoded data
4218 * @param nCharSet [out] Decoded character set
4219 * @return length of charset value
4221 static bool __MmsBinaryDecodeCharset(FILE *pFile, UINT32 *nCharSet, int *pCharSetLen, int totalLength)
4226 * Charset v1.1 0x01 Well-known-charset
4227 * Well-known-charset = Any-charset | Integer-value
4228 * ; Both are encoded using values from
4229 * Character Set Assignments table in Assigned Numbers
4230 * Any-charset = <Octet 128>
4231 * ; Equivalent to the special RFC2616 charset value ��*��
4234 if (pFile == NULL || nCharSet == NULL || pCharSetLen == NULL)
4237 if (__MmsBinaryDecodeInteger(pFile, &integer, pCharSetLen, totalLength) == false) {
4238 MSG_DEBUG("__MmsBinaryDecodeCharset : __MmsBinaryDecodeInteger fail...\n");
4243 /* AnyCharSet : return MSG_CHARSET_UTF8 */
4244 *nCharSet = MSG_CHARSET_UTF8;
4248 *nCharSet = _MmsGetBinaryType(MmsCodeCharSet, (UINT16)integer);
4250 if (*nCharSet == MIME_UNKNOWN) {
4251 MSG_DEBUG("__MmsBinaryDecodeCharset : _MmsGetBinaryType fail..\n");
4252 *nCharSet = MSG_CHARSET_UNKNOWN;
4264 * Decode EncodedString
4266 * @param pEncodedData [in] QuotedString encoded data
4267 * @param szBuff [out] Decoded string buffer
4268 * @param bufLen [in] Decoded buffer length
4269 * @return length of decoded string length
4271 static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen, int totalLength)
4273 UINT32 valueLength = 0;
4278 char *pTempData = NULL;
4279 unsigned short *mszTempStr = NULL;
4280 char *pConvertedStr = NULL;
4282 MSG_DEBUG("__MmsBinaryDecodeEncodedString: decode string..\n");
4284 if (pFile == NULL || szBuff == NULL || bufLen <= 0) {
4285 MSG_DEBUG("__MmsBinaryDecodeEncodedString: invalid file or buffer\n");
4290 * Encoded_string_value = Text-string | Value-length Char-set Text-String
4291 * Text-string = [Quote]*TEXT End-of-string
4292 * Value-length = 0 ~ 31
4295 memset(szBuff, 0, bufLen);
4297 switch (__MmsDecodeValueLength(pFile, &valueLength, totalLength)) {
4303 /* Text-string = [Quote]*TEXT End-of-string */
4305 if (__MmsBinaryDecodeText(pFile, szBuff, bufLen, totalLength) < 0) {
4306 MSG_DEBUG("__MmsBinaryDecodeEncodedString : 1. __MmsBinaryDecodeText fail.\n");
4313 /* Value-length Charset Text_string */
4315 if (__MmsBinaryDecodeCharset(pFile, &charSet, &charSetLen, totalLength) == false) {
4316 MSG_DEBUG("__MmsBinaryDecodeEncodedString : __MmsBinaryDecodeCharset error\n");
4317 goto __CATCH; /* (valueLength + valueLengthLen) */
4320 nTemp = __MmsBinaryDecodeText(pFile, szBuff, bufLen, totalLength);
4322 /* There can be some error in data - no NULL -> try again with value length */
4324 pData = (char *)malloc(valueLength - charSetLen);
4325 if (pData == NULL) {
4326 MSG_DEBUG("__MmsBinaryDecodeEncodedString : pData alloc fail.\n");
4330 if (_MmsBinaryDecodeGetLongBytes(pFile, pData, valueLength - charSetLen, totalLength) == false) {
4331 MSG_DEBUG("__MmsBinaryDecodeEncodedString : _MmsBinaryDecodeGetLongBytes fail.\n");
4335 strncpy(szBuff, pData, bufLen - 1);
4340 nTemp = strlen(szBuff);
4342 const char *pToCharSet = "UTF-8";
4344 UINT16 charset_code = _MmsGetBinaryValue(MmsCodeCharSet, charSet);
4346 const char *pFromCharSet = MmsPluginTextConvertGetCharSet(charset_code);
4347 if (pFromCharSet == NULL || !strcmp(pFromCharSet, pToCharSet)) {
4354 if (MmsPluginTextConvert(pToCharSet, pFromCharSet, szBuff, nTemp, &pDest, &destLen) == false) {
4355 MSG_DEBUG("MmsPluginTextConvert Fail");
4359 memset(szBuff, 0x00, bufLen);
4360 snprintf(szBuff, destLen, "%s", pDest);
4380 if (pConvertedStr) {
4381 free(pConvertedStr);
4382 pConvertedStr = NULL;
4405 if (pConvertedStr) {
4406 free(pConvertedStr);
4407 pConvertedStr = NULL;
4416 * Decode Encoded Addresses
4418 * @param pEncodedData [in] QuotedString encoded data
4419 * @param pAddrLength [out] Decoded address length
4420 * @return Decoded address list
4422 MsgHeaderAddress *__MmsDecodeEncodedAddress(FILE *pFile, int totalLength)
4424 UINT32 valueLength = 0;
4428 char *pAddrStr = NULL;
4429 MsgHeaderAddress *pAddr = NULL;
4431 MSG_DEBUG("__MmsDecodeEncodedAddress: decoding address..\n");
4433 if (pFile == NULL) {
4434 MSG_DEBUG("__MmsDecodeEncodedAddress: invalid file or buffer\n");
4439 * Encoded_string_value = Text-string | Value-length Char-set Text-String
4440 * Text-string = [Quote]*TEXT End-of-string
4441 * Value-length = 0 ~ 31
4444 switch (__MmsDecodeValueLength(pFile, &valueLength, totalLength)) {
4450 /* Text-string = [Quote]*TEXT End-of-string */
4453 pAddrStr = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
4454 if (pAddrStr == NULL) {
4455 MSG_DEBUG("__MmsDecodeEncodedAddress : 1. __MmsBinaryDecodeText2 fail.\n");
4462 /* Value-length Charset Text_string */
4464 if (__MmsBinaryDecodeCharset(pFile, &charSet, &charSetLen, totalLength) == false) {
4465 MSG_DEBUG("__MmsDecodeEncodedAddress : __MmsBinaryDecodeCharset error\n");
4470 pAddrStr = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
4471 if (pAddrStr == NULL) {
4472 /* There can be some error in data - no NULL -> try again with value length */
4474 pAddrStr = (char *)malloc(valueLength - charSetLen);
4475 if (pAddrStr == NULL) {
4476 MSG_DEBUG("__MmsDecodeEncodedAddress : pData alloc fail.\n");
4480 if (_MmsBinaryDecodeGetLongBytes(pFile, pAddrStr, valueLength - charSetLen, totalLength) == false) {
4481 MSG_DEBUG("__MmsDecodeEncodedAddress : _MmsBinaryDecodeGetLongBytes fail.\n");
4486 /* fixme: charset transformation */
4491 pAddr = (MsgHeaderAddress *)malloc(sizeof(MsgHeaderAddress));
4495 memset(pAddr, 0, sizeof(MsgHeaderAddress));
4496 pAddr->szAddr = pAddrStr;
4512 * Decode Encoded Pointer String
4514 * @param pEncodedData [in] Long integer encoded data
4515 * @param pLongInteger [out] Decoded long integer
4516 * @return Decoded address list
4518 static bool __MmsDecodeLongInteger(FILE *pFile, UINT32 *pLongInteger, int totalLength)
4523 * Long-integer = Short-length Multi-octet-integer
4524 * Short-length = 0~30
4525 * Multi-octet-integer
4528 if (pFile == NULL || pLongInteger == NULL)
4533 if (_MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
4539 *pLongInteger = __MmsHeaderDecodeIntegerByLength(pFile, oneByte, totalLength);
4549 * @param pEncodedData [in] filename encoded data
4550 * @param szBuff [out] filename output buffer
4551 * @param fullLength [in] full filename length
4552 * @param bufLen [in] buffer length
4553 * CAUTION: bufLen - 1
4555 static int __MmsDecodeGetFilename(FILE *pFile, char *szBuff, int bufLen, int totalLength)
4557 char *pUTF8Buff = NULL;
4558 char *pLatinBuff = NULL;
4561 char *szSrc2 = NULL;
4565 char *pTmpBuff = NULL;
4567 memset (szBuff, 0, bufLen);
4570 pLatinBuff = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
4574 szSrc = MsgRemoveQuoteFromFilename(pLatinBuff);
4576 strcpy(pLatinBuff, szSrc);
4581 szSrc2 = MsgChangeHexString(pLatinBuff);
4583 strcpy(pLatinBuff, szSrc2);
4588 if (MsgIsUTF8String((unsigned char*)pLatinBuff, strlen(pLatinBuff)) == false) {
4589 length = strlen(pLatinBuff);
4591 int utf8BufSize = 0;
4592 utf8BufSize = MsgGetLatin2UTFCodeSize((unsigned char*)pLatinBuff, length);
4593 if (utf8BufSize < 3)
4594 utf8BufSize = 3;//min value
4596 pUTF8Buff = (char *)malloc(utf8BufSize + 1);
4597 if (pUTF8Buff == NULL) {
4598 MSG_DEBUG("__MmsDecodeGetFilename: pUTF8Buff alloc fail \n");
4602 if (MsgLatin2UTF ((unsigned char*)pUTF8Buff, utf8BufSize + 1, (unsigned char*)pLatinBuff, length) < 0) {
4603 MSG_DEBUG("__MmsDecodeGetFilename: MsgLatin2UTF fail \n");
4609 pTmpBuff = _MsgDecodeText(pLatinBuff);
4610 pUTF8Buff = pTmpBuff;
4619 * it should be kept extention even if the file name is shorten
4622 length = strlen(pUTF8Buff);
4623 if ((pExt = strrchr(pUTF8Buff, '.')) != NULL) {
4625 nameLength = (length < bufLen) ? (length - strlen(pExt)) : (bufLen - strlen(pExt));
4626 strncpy(szBuff, pUTF8Buff, nameLength);
4627 strcat (szBuff, pExt);
4629 strncpy(szBuff, pUTF8Buff, bufLen - 1);
4653 /* ==========================================================
4655 T E X T D E C O D I N G
4657 ==========================================================*/
4660 bool MmsTextDecodeMsgBody(FILE *pFile)
4662 MSG_DEBUG("MmsTextDecodeMsgBody: \n");
4666 bool __MmsTextDecodeMsgHeader(FILE *pFile)
4672 /* ==========================================================
4674 M M S D E C O D I N G
4676 ==========================================================*/
4678 // to get message body this function should be modified from message raw file.
4679 bool _MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRetrieved, char *retrievedPath)
4682 MmsMsg *pMsg = NULL;
4683 MsgMultipart *pMultipart = NULL;
4685 char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, };
4686 char szTempMediaDir[MSG_FILEPATH_LEN_MAX] = {0, };
4687 int attachmax = MSG_ATTACH_MAX;
4689 MSG_DEBUG("_MmsReadMsgBody: start read msg(msgID=%d)\n", msgID);
4691 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
4692 memset(pMsg, 0, sizeof(MmsMsg));
4696 if (bRetrieved && (retrievedPath != NULL)) {
4697 strncpy(szFullPath, retrievedPath, (strlen(retrievedPath) > MSG_FILEPATH_LEN_MAX ? MSG_FILEPATH_LEN_MAX:strlen(retrievedPath)));
4699 MmsPluginStorage::instance()->getMmsRawFilePath(msgID, szFullPath);
4702 pMsg->msgID = msgID;
4704 /* read from MMS raw file */
4705 strncpy(pMsg->szFileName, szFullPath + strlen(MSG_DATA_PATH), strlen(szFullPath + strlen(MSG_DATA_PATH)));
4707 MSG_DEBUG("szFullPath = (%s)", szFullPath);
4709 if (MsgGetFileSize(szFullPath, &nSize) == false) {
4710 MSG_DEBUG("MsgGetFileSize: failed");
4714 pFile = MsgOpenFile(szFullPath, "rb");
4716 if (pFile == NULL) {
4717 MSG_DEBUG("_MmsReadMsgBody: invalid mailbox\n");
4721 _MmsRegisterDecodeBuffer(gszMmsLoadBuf1, gszMmsLoadBuf2, MSG_MMS_DECODE_BUFFER_MAX);
4723 if (MmsBinaryDecodeMsgHeader(pFile, nSize) == false) {
4724 MSG_DEBUG("_MmsReadMsgBody: MmsBinaryDecodeMsgHeader fail...\n");
4728 #ifdef __SUPPORT_DRM__
4729 if (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_FINISH)
4730 MmsDrm2SetConvertState(MMS_DRM2_CONVERT_NONE); //initialize convertState
4733 if (MmsBinaryDecodeMsgBody(pFile, szFullPath, nSize) == false) {
4734 MSG_DEBUG("_MmsReadMsgBody: MmsBinaryDecodeMsgBody fail\n");
4738 #ifdef __SUPPORT_DRM__
4739 if (MmsDrm2GetConvertState() == MMS_DRM2_CONVERT_REQUIRED) {
4740 MSG_DEBUG("_MmsReadMsgBody: MmsDrm2GetConvertState returns MMS_DRM2_CONVERT_REQUIRED.\n");
4745 /* Set mmsHeader.msgType & msgBody to pMsg ----------- */
4747 pMsg->mmsAttrib.contentType = (MsgContentType)mmsHeader.msgType.type;
4749 memcpy(&(pMsg->msgType), &(mmsHeader.msgType), sizeof(MsgType));
4750 memcpy(&(pMsg->msgBody), &(mmsHeader.msgBody), sizeof(MsgBody));
4752 if (pMsg->msgBody.pPresentationBody) {
4753 if(MsgFseek(pFile, pMsg->msgBody.pPresentationBody->offset, SEEK_SET) < 0)
4756 pMsg->msgBody.pPresentationBody->body.pText = (char *)malloc(pMsg->msgBody.pPresentationBody->size + 1);
4757 if (pMsg->msgBody.pPresentationBody->body.pText == NULL)
4760 memset(pMsg->msgBody.pPresentationBody->body.pText, 0, pMsg->msgBody.pPresentationBody->size + 1);
4763 nRead = MsgReadFile(pMsg->msgBody.pPresentationBody->body.pText, sizeof(char), pMsg->msgBody.pPresentationBody->size, pFile);
4769 MsgCloseFile(pFile);
4773 pMsg->nPartCount = 0;
4775 if (MsgIsMultipart(mmsHeader.msgType.type) == true) {
4776 pMultipart = pMsg->msgBody.body.pMultipart;
4777 while (pMultipart) {
4780 if (pMultipart->type.type == MIME_TEXT_PLAIN)
4783 if ((mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED)||(mmsHeader.msgType.type == MIME_MULTIPART_MIXED)) {
4784 if ((pMsg->nPartCount >= attachmax)&&(pMultipart->pNext != NULL)) {
4785 _MsgFreeBody(pMultipart->pNext->pBody, pMultipart->pNext->type.type);
4787 free(pMultipart->pNext->pBody);
4788 pMultipart->pNext->pBody= NULL;
4790 free(pMultipart->pNext);
4792 pMultipart->pNext = NULL;
4796 pMultipart = pMultipart->pNext;
4799 if (pMsg->msgBody.size > 0)
4803 /* make temporary */
4804 snprintf(szTempMediaDir, MSG_FILEPATH_LEN_MAX, MSG_DATA_PATH"%s.dir", pMsg->szFileName);
4806 ///////////////////////////////////////////////
4807 // call before processing urgent event.
4809 //_MmsUnregisterDecodeBuffer();
4810 ///////////////////////////////////////////////
4812 if (MsgIsMultipart(pMsg->msgType.type) == true) {
4814 pMultipart = pMsg->msgBody.body.pMultipart;
4816 if (bSavePartsAsTempFiles) {
4817 if (mkdir(szTempMediaDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
4818 if (errno == EEXIST) {
4819 MSG_DEBUG("The %s already exists", szTempMediaDir);
4821 MSG_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
4827 while (pMultipart) {
4829 if (_MmsMultipartSaveAsTempFile(&pMultipart->type, pMultipart->pBody,
4830 (char*)MSG_DATA_PATH, pMsg->szFileName, partIndex, bSavePartsAsTempFiles) == false)
4833 pMultipart = pMultipart->pNext;
4837 } else { //single part
4838 if (pMsg->nPartCount > 0) {
4840 if (bSavePartsAsTempFiles) {
4841 if (mkdir(szTempMediaDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
4842 if (errno == EEXIST) {
4843 MSG_DEBUG("The %s already exists", szTempMediaDir);
4845 MSG_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
4851 if (_MmsMultipartSaveAsTempFile( &pMsg->msgType, &pMsg->msgBody,
4852 (char*)MSG_DATA_PATH, pMsg->szFileName, 0, bSavePartsAsTempFiles) == false)
4856 MSG_DEBUG("**** _MmsReadMsgBody: E N D (Success) ***\n");
4859 #ifdef __SUPPORT_DRM__
4863 if (pFile != NULL) {
4864 MsgCloseFile(pFile);
4875 _MmsUnregisterDecodeBuffer();
4877 if (pFile != NULL) {
4878 MsgCloseFile(pFile);
4882 #ifdef __SUPPORT_DRM__
4883 _MsgFreeDRMInfo(&pMsg->msgType.drmInfo);
4886 _MsgFreeBody(&pMsg->msgBody, pMsg->msgType.type);
4887 MSG_DEBUG("_MmsReadMsgBody: E N D (fail) ******************** \n");
4893 bool MsgFreeHeaderAddress(MsgHeaderAddress *pAddr)
4895 MsgHeaderAddress *pTempAddr = NULL;
4897 while (pAddr != NULL) {
4899 pAddr = pAddr->pNext;
4901 if (pTempAddr->szAddr) {
4902 free(pTempAddr->szAddr);
4903 pTempAddr->szAddr = NULL;
4913 bool MsgCheckFileNameHasInvalidChar(char *szName)
4918 strLen = strlen(szName);
4920 for (i=0; i<strLen; i++) {
4921 if (__MsgIsInvalidFileNameChar(szName[i]))
4928 bool _MsgReplaceInvalidFileNameChar(char *szInText, char replaceChar)
4931 int totalLength = 0;
4933 totalLength = strlen(szInText);
4935 while ((*(szInText+nCount) != '\0') && (nCount < totalLength)) {
4936 if (0x0001 <= *(szInText+nCount) && *(szInText+nCount) <= 0x007F) {
4937 if (__MsgIsInvalidFileNameChar(szInText[nCount]))
4938 *(szInText+nCount) = replaceChar;
4949 char *_MsgGetStringUntilDelimiter(char *pszString, char delimiter)
4951 char *pszBuffer = NULL;
4952 char *pszStrDelimiter = NULL;
4956 MSG_DEBUG("_MsgGetStringUntilDelimiter: pszString == NULL \n");
4960 if ((pszStrDelimiter = strchr(pszString, delimiter)) == NULL) {
4961 MSG_DEBUG("_MsgGetStringUntilDelimiter: There is no %c in %s. \n", delimiter, pszString);
4965 bufLength = pszStrDelimiter - pszString;
4967 if ((pszBuffer = (char*)malloc (bufLength + 1)) == NULL) {
4968 MSG_DEBUG("malloc is failed");
4971 memset(pszBuffer, 0, bufLength + 1) ;
4973 strncat(pszBuffer, pszString, bufLength);
4978 char *MsgChangeHexString(char *pOrg)
4981 char szBuf[10] = {0,};
4990 cLen = strlen(pOrg);
4992 pNew = (char *)malloc(cLen + 1);
4996 memset(pNew, 0, cLen + 1);
4998 for (cIndex = 0; cIndex< cLen ; cIndex++) {
4999 if (pOrg[cIndex] == '%') {
5000 if (pOrg[cIndex+1] != 0 && pOrg[cIndex+2] != 0) {
5001 snprintf(szBuf, sizeof(szBuf), "%c%c", pOrg[cIndex+1], pOrg[cIndex+2]); // read two chars after '%'
5003 if (MsgIsHexChar(szBuf) == true) { // check the two character is between 0 ~ F
5004 OneChar = _MsgConvertHexValue(szBuf);
5006 pNew[index] = OneChar;
5013 pNew[index++] = pOrg[cIndex];
5018 bool _MsgParseParameter(MsgType *pType, char *pSrc)
5021 char *pValue = NULL;
5024 char *pNextParam = NULL;
5028 char *pTempNextParam = NULL;
5031 char *pUTF8Buff = NULL;
5033 while (pSrc != NULL) {
5034 pSrc = _MsgSkipWS(pSrc);
5036 /* End of parse parameter */
5041 pTempNextParam = strchr(pSrc, MSG_CH_SEMICOLON);
5044 if (*pCh == MSG_CH_QUOT) {
5051 for (; pCh<=pTempNextParam ; pCh++) {
5052 if (*pCh == MSG_CH_QUOT)
5053 if (*(pCh - 1) != '\\')
5058 pNextParam = pTempNextParam;
5061 *pNextParam++ = MSG_CH_NULL;
5063 if ((pName = strchr(pSrc, MSG_CH_EQUAL)) != NULL) {
5064 *pName++ = MSG_CH_NULL;
5066 if ((pValue = strchr(pName, MSG_CH_QUOT))!= NULL) {
5067 *pValue++ = MSG_CH_NULL;
5069 if ((pTest = strchr(pValue, MSG_CH_QUOT)) != NULL)
5070 *pTest = MSG_CH_NULL;
5072 pDec = _MsgDecodeText(pValue); // Api is to long, consider Add to another file (MsgMIMECodec.c)
5074 pDec = _MsgDecodeText(pName);
5077 switch (_MsgGetCode(MSG_PARAM, pSrc)) {
5078 case MSG_PARAM_BOUNDARY:
5080 /* RFC 822: boundary := 0*69<bchars> bcharsnospace */
5082 memset (pType->param.szBoundary, 0, MSG_BOUNDARY_LEN + 1);
5083 strncpy(pType->param.szBoundary, pDec, MSG_BOUNDARY_LEN);
5084 MSG_DEBUG("_MsgParseParameter: szBoundary = %s \n", pType->param.szBoundary);
5087 case MSG_PARAM_CHARSET:
5088 pType->param.charset = _MsgGetCode(MSG_CHARSET, pDec);
5090 if (pType->param.charset == INVALID_HOBJ)
5091 pType->param.charset = MSG_CHARSET_UNKNOWN;
5093 MSG_DEBUG("_MsgParseParameter: type = %d [charset] = %d \n", pType->type, pType->param.charset);
5096 case MSG_PARAM_NAME:
5098 memset (pType->param.szName, 0, MSG_LOCALE_FILENAME_LEN_MAX + 1);
5100 pUTF8Buff = MsgConvertLatin2UTF8FileName(pDec);
5103 if ((pExt = strrchr(pUTF8Buff, '.')) != NULL) {
5104 if ((MSG_LOCALE_FILENAME_LEN_MAX-1) < strlen(pUTF8Buff)) {
5105 nameLen = (MSG_LOCALE_FILENAME_LEN_MAX-1) - strlen(pExt);
5107 nameLen = strlen(pUTF8Buff) - strlen(pExt);
5110 strncpy(pType->param.szName, pUTF8Buff, nameLen);
5111 strcat (pType->param.szName, pExt);
5113 strncpy(pType->param.szName, pUTF8Buff, (MSG_LOCALE_FILENAME_LEN_MAX-1));
5118 if (_MsgChangeSpace(pType->param.szName, &szSrc) == true) {
5120 strncpy(pType->param.szName, szSrc , strlen(szSrc));
5128 // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
5129 _MsgRemoveFilePath(pType->param.szName);
5131 MSG_DEBUG("_MsgParseParameter: MsgConvertLatin2UTF8FileName(%s) return NULL\n", pDec);
5134 MSG_DEBUG("_MsgParseParameter: szName = %s \n", pType->param.szName);
5137 case MSG_PARAM_FILENAME:
5139 memset (pType->param.szFileName, 0, MSG_FILENAME_LEN_MAX+1);
5141 pUTF8Buff = MsgConvertLatin2UTF8FileName(pDec);
5144 if ((pExt = strrchr(pUTF8Buff, '.')) != NULL) {
5145 if ((MSG_FILENAME_LEN_MAX-1) < strlen(pUTF8Buff)) {
5146 nameLen = (MSG_FILENAME_LEN_MAX-1) - strlen(pExt);
5148 nameLen = strlen(pUTF8Buff) - strlen(pExt);
5151 strncpy(pType->param.szFileName, pUTF8Buff, nameLen);
5152 strcat (pType->param.szFileName, pExt);
5154 strncpy(pType->param.szFileName, pUTF8Buff, (MSG_FILENAME_LEN_MAX-1));
5159 if (_MsgChangeSpace(pType->param.szFileName, &szSrc) == true)
5160 strcpy(pType->param.szFileName, szSrc);
5167 // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
5168 _MsgRemoveFilePath(pType->param.szFileName);
5170 MSG_DEBUG("_MsgParseParameter: MsgConvertLatin2UTF8FileName(%s) return NULL\n", pDec);
5173 MSG_DEBUG("_MsgParseParameter: szFileName = %s \n", pType->param.szFileName);
5177 case MSG_PARAM_TYPE:
5179 /* type/subtype of root. Only if content-type is multipart/related */
5181 pType->param.type = _MsgGetCode(MSG_TYPE, pDec);
5182 MSG_DEBUG("_MsgParseParameter: type = %d \n", pType->param.type);
5186 case MSG_PARAM_START:
5188 /* Content-id. Only if content-type is multipart/related */
5190 memset (pType->param.szStart, 0, MSG_MSG_ID_LEN + 1);
5191 strncpy(pType->param.szStart, pDec, MSG_MSG_ID_LEN);
5193 MSG_DEBUG("_MsgParseParameter: szStart = %s \n", pType->param.szStart);
5197 case MSG_PARAM_START_INFO :
5199 /* Only if content-type is multipart/related */
5201 memset (pType->param.szStartInfo, 0, MSG_MSG_ID_LEN + 1);
5202 strncpy(pType->param.szStartInfo, pDec, MSG_MSG_ID_LEN);
5204 MSG_DEBUG("_MsgParseParameter: szStartInfo = %s \n", pType->param.szStartInfo);
5208 case MSG_PARAM_REPORT_TYPE :
5210 // only used as parameter of Content-Type: multipart/report; report-type=delivery-status;
5212 if (pDec != NULL && strcasecmp(pDec, "delivery-status") == 0) {
5213 pType->param.reportType = MSG_PARAM_REPORT_TYPE_DELIVERY_STATUS;
5215 pType->param.reportType = MSG_PARAM_REPORT_TYPE_UNKNOWN;
5218 MSG_DEBUG("_MsgParseParameter: reportType = %s \n", pDec);
5223 MSG_DEBUG("_MsgParseParameter: Unknown paremeter (%s)\n", pDec);
5237 char *_MsgSkipWS(char *s)
5240 if ((*s == MSG_CH_CR) || (*s == MSG_CH_LF) || (*s == MSG_CH_SP) || (*s == MSG_CH_TAB)) {
5242 } else if ((*s != '(') || (__MsgSkipComment(s,(long)NULL)==NULL)) {
5248 char *__MsgSkipComment (char *s,long trim)
5255 // ignore empty space
5256 for (ret = ++s1; *ret == ' '; ret++)
5259 // handle '(', ')', '\', '\0'
5263 if (!__MsgSkipComment (s1,(long)NULL))
5294 char *MsgConvertLatin2UTF8FileName(char *pSrc)
5296 char *pUTF8Buff = NULL;
5300 //convert utf8 string
5301 if (MsgIsUTF8String((unsigned char*)pSrc, strlen(pSrc)) == false) {
5303 int utf8BufSize = 0;
5305 length = strlen(pSrc);
5306 utf8BufSize = MsgGetLatin2UTFCodeSize((unsigned char*)pSrc, length);
5307 if (utf8BufSize < 3)
5308 utf8BufSize = 3; //min value
5310 pUTF8Buff = (char *)malloc(utf8BufSize + 1);
5312 if (pUTF8Buff == NULL) {
5313 MSG_DEBUG("MsgConvertLatin2UTF8FileName: pUTF8Buff alloc fail \n");
5317 if (MsgLatin2UTF ((unsigned char*)pUTF8Buff, utf8BufSize + 1, (unsigned char*)pSrc, length) < 0) {
5318 MSG_DEBUG("MsgConvertLatin2UTF8FileName: MsgLatin2UTF fail \n");
5322 int length = strlen(pSrc);
5323 pUTF8Buff = (char *)calloc(1, length+1);
5325 if (pUTF8Buff == NULL) {
5326 MSG_DEBUG("MsgConvertLatin2UTF8FileName: pUTF8Buff alloc fail \n");
5330 memcpy(pUTF8Buff, pSrc, length);
5333 //convert hex string
5334 if (MsgIsPercentSign(pUTF8Buff) == true) {
5335 pData = MsgChangeHexString(pUTF8Buff);
5337 strcpy(pUTF8Buff, pData);
5355 bool _MsgChangeSpace(char *pOrg, char **ppNew)
5365 cLen = strlen(pOrg);
5367 pNew = (char *)malloc(cLen + 1);
5371 memset(pNew, 0, cLen + 1);
5373 for (cIndex=0; cIndex<cLen;cIndex++) {
5374 if (pOrg[cIndex] == '%' && pOrg[cIndex+1] == '2' && pOrg[cIndex+2] == '0') {
5380 pNew[index++] = pOrg[cIndex];
5388 void _MsgRemoveFilePath(char *pSrc)
5390 // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
5393 char szFileName[MSG_FILENAME_LEN_MAX] = {0};
5399 while ((pTemp = strchr(pTemp, '/')) != NULL) {
5400 // Find the last '/'
5406 MSG_DEBUG("_MsgRemoveFilePath: filename(%s)\n", pSrc);
5408 // case : images/vf7.gif -> vf7.gif
5409 if (pPath != NULL && *(pPath+1) != '\0') {
5410 strncpy(szFileName, pPath+1, strlen(pPath+1));
5411 strncpy(pSrc, szFileName , strlen(szFileName));
5414 // Remove additional file information
5415 // ex) Content-type: application/octet-stream; name="060728gibson_210.jpg?size=s"
5416 // if "?size=" exist, insert NULL char.
5418 pTemp = strcasestr(pSrc, "?size=");
5424 bool MsgIsUTF8String(unsigned char *szSrc, int nChar)
5426 MSG_DEBUG("MsgIsUTF8String: --------------- \n");
5428 if (szSrc == NULL) {
5429 MSG_DEBUG("MsgIsUTF8String: szSrc is NULL !!!! --------------- \n");
5433 while (nChar > 0 && (*szSrc != '\0')) {
5434 if (*szSrc < 0x80) {
5437 } else if ((0xC0 <= *szSrc) && (*szSrc < 0xE0)) {
5438 if (*(szSrc + 1) >= 0x80) {
5442 MSG_DEBUG("MsgIsUTF8String: 1. NOT utf8 range!\n");
5445 } else if (*szSrc >= 0xE0) {
5446 if (*(szSrc + 1) >= 0x80) {
5447 if (*(szSrc + 2) >= 0x80) {
5451 MSG_DEBUG("MsgIsUTF8String: 2. NOT utf8 range!\n");
5455 MSG_DEBUG("MsgIsUTF8String: 3. NOT utf8 range!\n");
5459 MSG_DEBUG("MsgIsUTF8String: 4. NOT utf8 range!\n");
5470 bool MsgIsPercentSign(char *pSrc)
5475 pCh = strchr(pSrc , '%');
5486 MsgMultipart *MsgAllocMultipart(void)
5488 MsgMultipart *pMultipart = NULL;
5490 MSG_DEBUG("MsgAllocMultipart: --------- \n");
5492 pMultipart = (MsgMultipart*)malloc(sizeof(MsgMultipart));
5493 if (pMultipart == NULL) {
5494 MSG_DEBUG("MsgAllocMultipart: pMultipart malloc Fail \n");
5498 pMultipart->pBody = (MsgBody*)malloc(sizeof(MsgBody));
5499 if (pMultipart->pBody == NULL) {
5500 MSG_DEBUG("MsgAllocMultipart: pMultipart->pBody malloc Fail \n");
5504 _MsgInitMsgType(&pMultipart->type);
5505 _MsgInitMsgBody(pMultipart->pBody);
5507 pMultipart->pNext = NULL;
5514 if (pMultipart->pBody) {
5515 free(pMultipart->pBody);
5516 pMultipart->pBody = NULL;
5526 bool _MsgInitMsgType(MsgType *pMsgType)
5528 pMsgType->offset = 0;
5530 pMsgType->contentSize = 0;
5531 pMsgType->disposition = 0;
5532 pMsgType->encoding = 0;
5533 pMsgType->type = MIME_UNKNOWN;
5534 #ifdef FEATURE_JAVA_MMS_MIME
5535 pMsgType->szMimeString[0] ='\0';
5537 pMsgType->section = 0;
5539 pMsgType->szOrgFilePath[0] = '\0';
5540 pMsgType->szContentID[0] = '\0';
5541 pMsgType->szContentLocation[0] = '\0';
5543 pMsgType->szContentRepPos[0] = '\0';
5544 pMsgType->szContentRepSize[0] = '\0';
5545 pMsgType->szContentRepIndex[0] = '\0';
5547 __MsgInitMsgContentParam(&pMsgType->param);
5548 #ifdef __SUPPORT_DRM__
5549 __MsgInitMsgDRMInfo(&pMsgType->drmInfo);
5556 bool __MsgInitMsgContentParam(MsgContentParam *pMsgContentParam)
5558 pMsgContentParam->charset = MSG_CHARSET_UNKNOWN;
5559 pMsgContentParam->type = MIME_UNKNOWN;
5560 pMsgContentParam->szBoundary[0] = '\0';
5561 pMsgContentParam->szFileName[0] = '\0';
5562 pMsgContentParam->szName[0] = '\0';
5563 #ifdef FEATURE_JAVA_MMS
5564 pMsgContentParam->szApplicationID = NULL;
5565 pMsgContentParam->szReplyToApplicationID = NULL;
5567 pMsgContentParam->szStart[0] = '\0';
5568 pMsgContentParam->szStartInfo[0] = '\0';
5569 pMsgContentParam->pPresentation = NULL;
5571 pMsgContentParam->reportType = MSG_PARAM_REPORT_TYPE_UNKNOWN; // add only used as parameter of Content-Type: multipart/report; report-type
5577 bool _MsgInitMsgBody(MsgBody *pMsgBody)
5579 pMsgBody->offset = 0;
5581 pMsgBody->body.pText = NULL;
5582 pMsgBody->szOrgFilePath[0] = '\0';
5584 _MsgInitMsgType(&pMsgBody->presentationType);
5585 pMsgBody->pPresentationBody = NULL;
5587 memset(pMsgBody->szOrgFilePath, 0, MSG_FILEPATH_LEN_MAX);
5593 MsgPresentationFactor MsgIsPresentationEx(MsgType *multipartType, char* szStart, MsgContentType typeParam)
5595 char szTmpStart[MSG_MSG_ID_LEN + 3] = { 0, };
5596 char szTmpContentID[MSG_MSG_ID_LEN + 3] = { 0, };
5597 char szTmpContentLO[MSG_MSG_ID_LEN + 3] = { 0, };
5600 // remove '<' and '>' in Start Param : contentID ex] <0_1.jpg> or <1233445>
5601 if (szStart && szStart[0]) {
5603 startLen = strlen(szStart);
5604 if (szStart[0] == '<' && szStart[startLen - 1] == '>') {
5605 strncpy(szTmpStart, &szStart[1], startLen - 2);
5607 strncpy(szTmpStart, szStart, startLen);
5611 // remove '<' and '>' in ContentID : contentID ex] <0_1.jpg> or <1233445>
5612 if (multipartType->szContentID[0]) {
5613 strLen = strlen(multipartType->szContentID);
5614 if (multipartType->szContentID[0] == '<' && multipartType->szContentID[strLen - 1] == '>') {
5615 strncpy(szTmpContentID, &(multipartType->szContentID[1]), strLen - 2);
5617 strncpy(szTmpContentID, multipartType->szContentID, strLen);
5621 // remove '<' and '>' in ContentLocation : contentID ex] <0_1.jpg> or <1233445>
5622 if (multipartType->szContentLocation[0]) {
5623 strLen = strlen(multipartType->szContentLocation);
5624 if (multipartType->szContentLocation[0] == '<' && multipartType->szContentLocation[strLen - 1] == '>') {
5625 strncpy(szTmpContentLO, &multipartType->szContentLocation[1], strLen - 2);
5627 strncpy(szTmpContentLO, multipartType->szContentLocation, strLen);
5631 if ((szTmpContentID[0] == '\0') && (szTmpContentLO[0] == '\0') && (multipartType->type == MIME_UNKNOWN))
5632 return MSG_PRESENTATION_NONE;
5634 // exception handling
5635 if (szTmpStart[0] != '\0') {
5636 // presentation part : 1.compare with contentID 2.compare with content Location 3. compare with type
5637 if (strcmp(szTmpStart, szTmpContentID) == 0) {
5638 return MSG_PRESENTATION_ID;
5639 } else if (strcmp(szTmpStart, szTmpContentLO) == 0) {
5640 return MSG_PRESENTATION_LOCATION;
5641 } else if (multipartType->type == typeParam) {
5642 return MSG_PRESENTATION_TYPE_BASE;
5644 return MSG_PRESENTATION_NONE;
5647 if (multipartType->type == typeParam && typeParam != MIME_UNKNOWN) {
5648 return MSG_PRESENTATION_TYPE_BASE;
5650 return MSG_PRESENTATION_NONE;
5655 void MsgConfirmPresentationPart(MsgType *pMsgType, MsgBody *pMsgBody, MsgPresentaionInfo *pPresentationInfo)
5658 MsgMultipart *pNextPart = NULL;
5659 MsgMultipart *pRemovePart = NULL;
5661 if (MsgIsMultipartRelated(pMsgType->type)) {
5662 // assign the multipart to presentation part
5663 // remove the multipart(pCurPresentation) which is presentation part from the linked list.
5664 // if there is no presentation part -> assign first multipart to presentation part by force.
5665 if (pPresentationInfo->pCurPresentation == NULL) {
5666 pPresentationInfo->pCurPresentation = pMsgBody->body.pMultipart;
5667 pPresentationInfo->pPrevPart = NULL;
5668 pPresentationInfo->factor = MSG_PRESENTATION_NONE;
5671 if (pPresentationInfo->pCurPresentation != NULL && MsgIsPresentablePart(pPresentationInfo->pCurPresentation->type.type)) {
5672 /* Presentable Part is some MARK-UP page, such as SMIL, HTML, WML, XHTML.
5673 * In this case, COPY the Presentation part and leave other multiparts.
5675 memcpy(&pMsgBody->presentationType, &pPresentationInfo->pCurPresentation->type, sizeof(MsgType));
5676 pMsgBody->pPresentationBody = pPresentationInfo->pCurPresentation->pBody;
5678 // remove pCurPresentation from multipart linked list
5679 if ((pPresentationInfo->factor == MSG_PRESENTATION_NONE)||(pPresentationInfo->pPrevPart == NULL)) {
5681 pMsgBody->body.pMultipart = pPresentationInfo->pCurPresentation->pNext;
5682 pMsgType->contentSize -= pPresentationInfo->pCurPresentation->pBody->size;
5683 pMsgBody->size -= pPresentationInfo->pCurPresentation->pBody->size;
5684 if (pPresentationInfo->pCurPresentation) {
5685 #ifdef __SUPPORT_DRM__
5686 _MsgFreeDRMInfo(&pPresentationInfo->pCurPresentation->type.drmInfo);
5688 free(pPresentationInfo->pCurPresentation);
5689 pPresentationInfo->pCurPresentation = NULL;
5693 pPresentationInfo->pPrevPart->pNext = pPresentationInfo->pCurPresentation->pNext;
5694 pMsgType->contentSize -= pPresentationInfo->pCurPresentation->pBody->size;
5695 pMsgBody->size -= pPresentationInfo->pCurPresentation->pBody->size;
5696 if (pPresentationInfo->pCurPresentation) {
5697 free(pPresentationInfo->pCurPresentation);
5698 pPresentationInfo->pCurPresentation = NULL;
5701 } else if (pPresentationInfo->pCurPresentation != NULL && MsgIsText(pPresentationInfo->pCurPresentation->type.type)) {
5702 /* NON-Presentable Part is some PLAIN part such as, text/plain, multipart/alternative.
5703 * In this case, leave the Presentation part as a multipart and remove other multiparts.
5706 // Backup the multipart link information
5707 pNextPart = pMsgBody->body.pMultipart;
5709 // Copy presentation part as a main part
5710 memcpy(pMsgType, &pPresentationInfo->pCurPresentation->type, sizeof(MsgType));
5711 memcpy(pMsgBody, pPresentationInfo->pCurPresentation->pBody, sizeof(MsgBody));
5713 // Remove multipart linked list
5715 pRemovePart = pNextPart;
5716 pNextPart = pNextPart->pNext;
5718 if (pRemovePart->pBody) {
5719 _MsgFreeBody(pRemovePart->pBody, pRemovePart->type.type);
5720 free(pRemovePart->pBody);
5721 pRemovePart->pBody = NULL;
5728 #ifdef __SUPPORT_DRM__
5729 _MsgFreeDRMInfo(&pMsgBody->presentationType.drmInfo);
5731 _MsgInitMsgType(&pMsgBody->presentationType);
5732 pMsgBody->pPresentationBody = NULL;
5738 bool MsgIsMultipartRelated(int type)
5740 if (type == MIME_MULTIPART_RELATED || type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
5747 bool MsgIsPresentablePart(int type)
5749 if (type == MIME_TEXT_HTML || type == MIME_TEXT_VND_WAP_WML || type == MIME_APPLICATION_SMIL) {
5756 #ifdef __SUPPORT_DRM__
5757 void _MsgFreeDRMInfo(MsgDRMInfo *pDrmInfo)
5759 MSG_DEBUG("_MsgFreeDRMInfo: S T A R T !!! \n");
5761 if (pDrmInfo == NULL) {
5762 MSG_DEBUG("pDrmInfo is NULL");
5766 if (pDrmInfo->szContentDescription) {
5767 free(pDrmInfo->szContentDescription);
5768 pDrmInfo->szContentDescription = NULL;
5771 if (pDrmInfo->szContentVendor) {
5772 free(pDrmInfo->szContentVendor);
5773 pDrmInfo->szContentVendor = NULL;
5776 if (pDrmInfo->szContentName) {
5777 free(pDrmInfo->szContentName);
5778 pDrmInfo->szContentName = NULL;
5781 if (pDrmInfo->szContentURI) {
5782 free(pDrmInfo->szContentURI);
5783 pDrmInfo->szContentURI = NULL;
5786 if (pDrmInfo->szRightIssuer) {
5787 free(pDrmInfo->szRightIssuer);
5788 pDrmInfo->szRightIssuer = NULL;
5791 if (pDrmInfo->szDrm2FullPath) {
5792 free(pDrmInfo->szDrm2FullPath);
5793 pDrmInfo->szDrm2FullPath = NULL;
5796 #if MMS_ENABLE_EXTEND_CFM
5797 // DRM (Extended)CFM
5798 if (pDrmInfo->pszContentType) {
5799 free(pDrmInfo->pszContentType);
5800 pDrmInfo->pszContentType = NULL;
5804 pDrmInfo->contentType = MIME_UNKNOWN;
5805 pDrmInfo->drmType = MSG_DRM_TYPE_NONE;
5808 bool MsgCopyDrmInfo(MsgType *pPartType)
5811 char *pTmpBuf = NULL;
5813 //convert application/vnd.oma.drm.content to media type
5814 pPartType->type = pPartType->drmInfo.contentType;
5816 // fix wrong file name presentation on save media screen.
5817 if (pPartType->szContentID[0] == '\0' && pPartType->drmInfo.szContentURI)
5818 strncpy(pPartType->szContentID, pPartType->drmInfo.szContentURI, MSG_MSG_ID_LEN);
5820 /* set title name (content name) */
5821 if (pPartType->param.szName[0] == '\0') {
5822 /* szName is vitual name, real filename is *.dcf or *.dm */
5823 if (pPartType->drmInfo.szContentName && pPartType->drmInfo.szContentName[0] != '\0') {
5824 /* In case of szContentName retrieved from DRM agent is exist. */
5825 pTmpBuf = pPartType->drmInfo.szContentName;
5826 } else if (pPartType->szContentLocation[0] != '\0') {
5827 /* In case of szContentLocation parsed from MMS header */
5828 pTmpBuf = strrchr(pPartType->szContentLocation, '/');
5829 if (pTmpBuf == NULL)
5830 pTmpBuf = pPartType->szContentLocation;
5832 /* use another name */
5833 /* possible NULL pointer assignment*/
5834 pTmpBuf = strdup("untitled");
5837 if ((pExt = strrchr(pTmpBuf, '.')) != NULL) {
5839 int fileNameLen = 0;
5842 extLen = strlen(pExt);
5843 tmpLen = strlen(pTmpBuf);
5844 fileNameLen = (tmpLen - extLen < MSG_LOCALE_FILENAME_LEN_MAX - extLen)?(tmpLen - extLen):(MSG_LOCALE_FILENAME_LEN_MAX - extLen);
5845 strncpy(pPartType->param.szName, pTmpBuf, fileNameLen);
5846 strcpy (pPartType->param.szName + fileNameLen, pExt);
5848 strncpy(pPartType->param.szName, pTmpBuf, MSG_LOCALE_FILENAME_LEN_MAX);
5849 MsgMakeFileName(pPartType->type, pPartType->param.szName, MSG_DRM_TYPE_NONE, 0);
5858 bool MsgIsText(int type)
5860 if (type == MIME_TEXT_PLAIN || type == MIME_TEXT_HTML || type == MIME_TEXT_VND_WAP_WML ||
5861 type == MIME_TEXT_X_VNOTE || type == MIME_APPLICATION_SMIL || type == MIME_TEXT_X_IMELODY) {
5868 bool MsgFreeAttrib(MmsAttrib *pAttrib)
5872 if (pAttrib == NULL) {
5873 MSG_DEBUG("pAttrib is NULL");
5877 if (pAttrib->szTo) {
5878 free(pAttrib->szTo);
5879 pAttrib->szTo = NULL;
5882 if (pAttrib->szCc) {
5883 free(pAttrib->szCc);
5884 pAttrib->szCc = NULL;
5887 if (pAttrib->szBcc) {
5888 free(pAttrib->szBcc);
5889 pAttrib->szBcc = NULL;
5892 //check if pMultiStatus should be freed or not, because pMultiStatus is not allocated
5893 if (pAttrib->pMultiStatus) {
5894 MmsMsgMultiStatus *pMultiStatus = pAttrib->pMultiStatus;
5895 MmsMsgMultiStatus *pCurStatus = NULL;
5897 while (pMultiStatus != NULL ) {
5898 pCurStatus = pMultiStatus;
5899 pMultiStatus = pMultiStatus->pNext;
5907 pAttrib->pMultiStatus = NULL;
5916 bool _MsgFreeBody(MsgBody *pBody, int type)
5918 MSG_DEBUG("_MsgFreeBody: S T A R T !!! \n") ;
5920 if (pBody == NULL) {
5921 MSG_DEBUG("_MsgFreeBody: pBody == NULL \n" );
5922 MSG_DEBUG("_MsgFreeBody: E N D (End)!!! \n") ;
5928 case MIME_MULTIPART_REPORT:
5929 case MIME_APPLICATION_VND_OMA_DRM_MESSAGE:
5930 case MIME_APPLICATION_VND_WAP_MULTIPART_MIXED:
5931 case MIME_APPLICATION_VND_WAP_MULTIPART_RELATED:
5932 case MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC:
5933 case MIME_MULTIPART_MIXED:
5934 case MIME_MULTIPART_RELATED:
5935 case MIME_MULTIPART_ALTERNATIVE:
5936 case MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE:
5938 MsgMultipart *pMulti = pBody->body.pMultipart;
5939 MsgMultipart *pCurrPart = NULL;
5940 MsgBody *pPresentation = pBody->pPresentationBody;
5941 while (pMulti != NULL) {
5944 pMulti = pMulti->pNext;
5947 #ifdef __SUPPORT_DRM__
5948 _MsgFreeDRMInfo(&pCurrPart->type.drmInfo);
5951 if (pCurrPart->pBody) {
5952 if (pCurrPart->pBody->body.pBinary) {
5953 free(pCurrPart->pBody->body.pBinary);
5954 pCurrPart->pBody->body.pBinary = NULL;
5956 free(pCurrPart->pBody);
5957 pCurrPart->pBody = NULL;
5964 pBody->body.pMultipart = NULL;
5966 if (pPresentation) {
5967 if (pPresentation->body.pText) {
5968 free(pPresentation->body.pText);
5969 pPresentation->body.pText = NULL;
5971 free(pPresentation);
5972 pBody->pPresentationBody = NULL;
5975 _MsgInitMsgType(&pBody->presentationType);
5981 /* Any single part */
5983 if (pBody->body.pBinary) {
5984 free(pBody->body.pBinary);
5985 pBody->body.pBinary = NULL;
5991 MSG_DEBUG("_MsgFreeBody: E N D (Successfully) !!! \n") ;
5997 bool MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
6000 MsgMultipart *pTmpMultipart = NULL;
6001 MsgMultipart *pSelectedPart = NULL;
6002 MsgMultipart *pPrevPart = NULL;
6003 MsgMultipart *pFirstPart = NULL;
6004 MsgMultipart *pLastPart = NULL;
6005 MsgMultipart *pRemoveList = NULL;
6006 MsgMultipart *pNextRemovePart = NULL;
6008 switch (pPartType->type) {
6009 case MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE:
6010 case MIME_MULTIPART_ALTERNATIVE:
6013 * Policy: multipart/alternative
6014 * multipart/alternative message has only several parts of media.
6015 * You should choose one of them and make the alternative part
6016 * to the selected media part.
6019 MSG_DEBUG("MsgResolveNestedMultipart : MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE\n");
6021 pSelectedPart = pPartBody->body.pMultipart;
6023 // NULL Pointer check!!
6024 if (pSelectedPart == NULL) {
6025 MSG_DEBUG("MsgResolveNestedMultipart : multipart(ALTERNATIVE) does not exist\n");
6029 pTmpMultipart = pPartBody->body.pMultipart->pNext;
6031 while (pTmpMultipart) {
6032 if (pSelectedPart->type.type <= pTmpMultipart->type.type)
6033 pSelectedPart = pTmpMultipart;
6035 pTmpMultipart = pTmpMultipart->pNext;
6038 pTmpMultipart = pPartBody->body.pMultipart;
6041 while (pTmpMultipart) {
6042 if (pSelectedPart == pTmpMultipart)
6045 pPrevPart = pTmpMultipart;
6046 pTmpMultipart = pTmpMultipart->pNext;
6049 if (pPrevPart == NULL) {
6050 /* selected part is the first part */
6051 pRemoveList = pSelectedPart->pNext;
6053 pPrevPart->pNext = pSelectedPart->pNext;
6054 pRemoveList = pPartBody->body.pMultipart;
6055 pPartBody->body.pMultipart = pSelectedPart;
6058 pSelectedPart->pNext = NULL;
6061 #ifdef __SUPPORT_DRM__
6062 _MsgFreeDRMInfo(&pRemoveList->type.drmInfo);
6064 _MsgFreeBody(pRemoveList->pBody, pRemoveList->type.type);
6066 free(pRemoveList->pBody);
6070 if (MsgCopyNestedMsgType(pPartType, &(pSelectedPart->type)) == false) {
6071 MSG_DEBUG("MsgResolveNestedMultipart : MsgPriorityCopyMsgType failed \n");
6075 if (pSelectedPart->pBody != NULL)
6076 memcpy(pPartBody, pSelectedPart->pBody, sizeof(MsgBody));
6078 if (pSelectedPart != NULL) {
6079 #ifdef __SUPPORT_DRM__
6080 _MsgFreeDRMInfo(&pSelectedPart->type.drmInfo);
6083 if (pSelectedPart->pBody != NULL) {
6084 free(pSelectedPart->pBody);
6085 pSelectedPart->pBody = NULL;
6087 free(pSelectedPart);
6088 pSelectedPart = NULL;
6093 case MIME_APPLICATION_VND_WAP_MULTIPART_RELATED:
6094 case MIME_MULTIPART_RELATED:
6096 MSG_DEBUG("MsgResolveNestedMultipart : MIME_APPLICATION_VND_WAP_MULTIPART_RELATED\n");
6098 pSelectedPart = pPartBody->body.pMultipart;
6100 while (pSelectedPart) {
6101 if (MsgIsMultipartMixed(pSelectedPart->type.type)) {
6103 if (pSelectedPart->pBody == NULL) {
6104 MSG_DEBUG("MsgResolveNestedMultipart :pSelectedPart->pBody(1) is NULL\n");
6108 pFirstPart = pSelectedPart->pBody->body.pMultipart;
6110 if (pFirstPart == NULL) {
6111 MSG_DEBUG("MsgResolveNestedMultipart : multipart(RELATED) does not exist\n");
6115 if (pFirstPart->pNext) {
6116 pLastPart = pFirstPart->pNext;
6117 while (pLastPart->pNext)
6118 pLastPart = pLastPart->pNext;
6120 pLastPart = pFirstPart;
6123 if (pPrevPart == NULL) {
6124 /* the first part */
6125 pTmpMultipart = pPartBody->body.pMultipart->pNext;
6126 pPartBody->body.pMultipart = pFirstPart;
6127 pLastPart->pNext = pTmpMultipart;
6129 pTmpMultipart = pSelectedPart->pNext;
6130 pPrevPart->pNext = pFirstPart;
6131 pLastPart->pNext = pTmpMultipart;
6134 if (pSelectedPart) {
6135 #ifdef __SUPPORT_DRM__
6136 _MsgFreeDRMInfo(&pSelectedPart->type.drmInfo);
6138 free(pSelectedPart->pBody);
6139 free(pSelectedPart);
6141 pSelectedPart = pTmpMultipart;
6142 } else if (MsgIsMultipartRelated(pSelectedPart->type.type) && pPrevPart != NULL) {
6143 pPrevPart->pNext = pTmpMultipart = pSelectedPart->pNext;
6144 _MsgFreeBody(pSelectedPart->pBody, pSelectedPart->type.type);
6146 free(pSelectedPart->pBody);
6147 free(pSelectedPart);
6148 pSelectedPart = pTmpMultipart;
6150 pPrevPart = pSelectedPart;
6151 pSelectedPart = pSelectedPart->pNext;
6158 case MIME_APPLICATION_VND_WAP_MULTIPART_MIXED:
6159 case MIME_MULTIPART_MIXED:
6161 MSG_DEBUG("MsgResolveNestedMultipart : MIME_APPLICATION_VND_WAP_MULTIPART_MIXED\n");
6164 pSelectedPart = pPartBody->body.pMultipart;
6166 while (pSelectedPart) {
6167 if (MsgIsMultipart(pSelectedPart->type.type)) {
6168 if (pSelectedPart->pBody == NULL) {
6169 MSG_DEBUG("MsgResolveNestedMultipart :pSelectedPart->pBody(2) is NULL\n");
6173 pFirstPart = pSelectedPart->pBody->body.pMultipart;
6175 // NULL Pointer check!!
6176 if (pFirstPart == NULL) {
6177 MSG_DEBUG("MsgResolveNestedMultipart : multipart does not exist\n");
6181 if (pFirstPart->pNext) {
6182 pLastPart = pFirstPart->pNext;
6183 while (pLastPart->pNext)
6184 pLastPart = pLastPart->pNext;
6186 pLastPart = pFirstPart;
6189 if (pPrevPart == NULL) {
6190 /* the first part */
6191 pTmpMultipart = pPartBody->body.pMultipart->pNext;
6192 pPartBody->body.pMultipart = pFirstPart;
6193 pLastPart->pNext = pTmpMultipart;
6195 pTmpMultipart = pSelectedPart->pNext;
6196 pPrevPart->pNext = pFirstPart;
6197 pLastPart->pNext = pTmpMultipart;
6200 if (pSelectedPart->pBody->pPresentationBody)
6201 pPartBody->pPresentationBody = pSelectedPart->pBody->pPresentationBody;
6203 memcpy(&pPartBody->presentationType,
6204 &pSelectedPart->pBody->presentationType, sizeof(MsgType));
6206 pPartType->type = pSelectedPart->type.type;
6208 #ifdef __SUPPORT_DRM__
6209 _MsgFreeDRMInfo(&pSelectedPart->type.drmInfo);
6211 free(pSelectedPart->pBody);
6212 free(pSelectedPart);
6214 pSelectedPart = pTmpMultipart;
6216 pPrevPart = pSelectedPart;
6217 pSelectedPart = pSelectedPart->pNext;
6223 case MIME_MULTIPART_REPORT:
6225 MSG_DEBUG("MsgResolveNestedMultipart : MIME_MULTIPART_REPORT \n");
6227 pTmpMultipart = pPartBody->body.pMultipart;
6230 if (pTmpMultipart == NULL) {
6231 MSG_DEBUG("MsgResolveNestedMultipart : pTmpMultipart == NULL \n");
6235 while (pTmpMultipart) {
6236 if (pTmpMultipart->type.type == MIME_TEXT_PLAIN) {
6237 pSelectedPart = pTmpMultipart;
6241 pPrevPart = pTmpMultipart;
6242 pTmpMultipart = pTmpMultipart->pNext;
6245 if (pSelectedPart == NULL) {
6246 MSG_DEBUG("MsgResolveNestedMultipart : MIME_MULTIPART_REPORT [no selected part]\n");
6248 pRemoveList = pPartBody->body.pMultipart->pNext;
6249 if (pPartBody->body.pMultipart != NULL) {
6250 pSelectedPart = pPartBody->body.pMultipart;
6251 pSelectedPart->pNext = NULL;
6254 if (pPrevPart == NULL) {
6255 // first part is selected
6256 pRemoveList = pPartBody->body.pMultipart->pNext;
6258 pRemoveList = pPartBody->body.pMultipart->pNext;
6259 pPrevPart->pNext = pSelectedPart->pNext;
6262 pSelectedPart->pNext = NULL;
6263 pPartBody->body.pMultipart = pSelectedPart;
6266 pTmpMultipart = pRemoveList;
6268 while (pTmpMultipart) {
6269 #ifdef __SUPPORT_DRM__
6270 _MsgFreeDRMInfo(&pTmpMultipart->type.drmInfo);
6272 _MsgFreeBody(pTmpMultipart->pBody, pTmpMultipart->type.type);
6273 pNextRemovePart = pTmpMultipart->pNext;
6275 free(pTmpMultipart->pBody);
6276 free(pTmpMultipart);
6277 pTmpMultipart = pNextRemovePart;
6280 if (MsgCopyNestedMsgType(pPartType, &(pSelectedPart->type)) == false) {
6281 MSG_DEBUG("MsgResolveNestedMultipart : MsgPriorityCopyMsgType failed \n");
6285 if (pSelectedPart->pBody != NULL)
6286 memcpy(pPartBody, pSelectedPart->pBody, sizeof(MsgBody));
6288 if (pSelectedPart != NULL) {
6289 #ifdef __SUPPORT_DRM__
6290 _MsgFreeDRMInfo(&pSelectedPart->type.drmInfo);
6292 if (pSelectedPart->pBody != NULL) {
6293 free(pSelectedPart->pBody);
6294 pSelectedPart->pBody = NULL;
6296 free(pSelectedPart);
6297 pSelectedPart = NULL;
6314 char *MsgResolveContentURI(char *szSrc)
6316 char *szTemp = NULL;
6317 char *szReturn = NULL;
6320 if (szSrc == NULL) {
6324 if (szSrc[0] == '\0')
6328 if (!strncasecmp(szSrc, "cid:", 4)) {
6329 length = strlen(szSrc) - 3;
6332 length = strlen(szSrc) + 1;
6335 szTemp = (char *)malloc(length);
6336 if (szTemp == NULL) {
6337 MSG_DEBUG("MsgResolveContentURI: memory full\n");
6341 memset(szTemp, 0, length);
6342 strcpy(szTemp, szSrc);
6344 szReturn = MsgChangeHexString(szTemp);
6358 bool _MsgParsePartHeader(MsgType *pType, const char *pRawData, int nRawData)
6361 int cRaw = nRawData;
6362 char *pFieldLine = NULL;
6363 char *pFieldValue = NULL;
6364 char *szFieldValue = NULL;
6367 char fieldLine[MSG_LINE_LEN] = {0, }; //temporary line buffer
6370 char szTempBuf[MSG_LOCAL_TEMP_BUF_SIZE];
6372 while ((cRaw > 0) && *pRawData != MSG_CH_LF) {
6373 memset(fieldLine, 0, MSG_LINE_LEN);
6374 pFieldLine = fieldLine;
6376 ch = MSG_CH_SP; //remember previous character.
6379 switch (ch = *pRawData++) {
6380 case MSG_CH_CR: //'\r'
6381 if (*pRawData == MSG_CH_LF)
6384 case MSG_CH_LF: //'\n'
6385 if (*pRawData != MSG_CH_SP && *pRawData != MSG_CH_TAB) {
6392 case MSG_CH_TAB: //'\t'
6393 *pFieldLine = MSG_CH_SP;
6403 if (--cRaw <= 0) { //If is the last character of header
6404 *pFieldLine = MSG_CH_NULL;
6410 if ((pFieldValue = strchr(fieldLine, MSG_CH_COLON)) != NULL) {
6411 char* pTemp = pFieldValue;
6412 char* pValue = NULL;
6414 *pFieldValue++ = MSG_CH_NULL; //remove ':'
6416 while (*pFieldValue == MSG_CH_SP) //remove space ' '
6419 while ((fieldLine < pTemp--) && (*pTemp == MSG_CH_SP))
6420 *pTemp = MSG_CH_NULL;
6422 nLen = strlen(pFieldValue);
6424 if (nLen >= MSG_LOCAL_TEMP_BUF_SIZE) {
6425 szFieldValue = (char *)malloc(nLen + 1);
6426 memset(szFieldValue, 0 , nLen + 1);
6427 memcpy(szFieldValue, pFieldValue, nLen + 1);
6429 memset(szTempBuf, 0, MSG_LOCAL_TEMP_BUF_SIZE);
6430 strcpy(szTempBuf, pFieldValue);
6431 szFieldValue = szTempBuf;
6434 if (MsgStrcpyWithoutCRLF(szFieldValue, &szSrc) == true) {
6436 strncpy(szFieldValue, szSrc, strlen(szSrc));
6443 switch (_MsgGetCode(MSG_FIELD, fieldLine)) {
6444 case MSG_FIELD_CONTENT_ID:
6445 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) != NULL)
6446 *pTemp++ = MSG_CH_NULL;
6448 pValue = _MsgDecodeText(szFieldValue);
6449 memset (pType->szContentID, 0, MSG_MSG_ID_LEN + 1);
6453 length = MsgStrlen(pValue);
6454 if (pValue[0] == '<' && pValue[length-1] == '>') {
6455 strncpy(pType->szContentID, pValue + 1, length - 2);
6457 strncpy(pType->szContentID, pValue, MSG_MSG_ID_LEN);
6460 MSG_DEBUG("_MsgParsePartHeader: Content-ID = %s %s\n", pFieldValue, pType->szContentID);
6463 _MsgParseParameter(pType, pTemp);
6471 case MSG_FIELD_CONTENT_LOCATION:
6472 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) != NULL)
6473 *pTemp++ = MSG_CH_NULL;
6475 pValue = _MsgDecodeText(szFieldValue);
6476 memset (pType->szContentLocation, 0, MSG_MSG_ID_LEN + 1);
6479 strncpy(pType->szContentLocation, pValue, MSG_MSG_ID_LEN);
6481 MSG_DEBUG("_MsgParsePartHeader: Content-Location = %s %s\n", pFieldValue, pType->szContentLocation);
6484 _MsgParseParameter(pType, pTemp);
6492 case MSG_FIELD_CONTENT_TYPE:
6493 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) == NULL) {
6494 if ((pTemp = strchr(szFieldValue, MSG_CH_SP)) != NULL)
6495 *pTemp++ = MSG_CH_NULL;
6497 *pTemp++ = MSG_CH_NULL;
6500 pType->type = _MsgGetCode(MSG_TYPE, szFieldValue);
6502 MSG_DEBUG("_MsgParsePartHeader: Content-Type = %s %d\n", pFieldValue, pType->type);
6504 if (pType->type == INVALID_HOBJ)
6505 pType->type = MIME_UNKNOWN;
6508 _MsgParseParameter(pType, pTemp);
6512 case MSG_FIELD_CONTENT_TRANSFER_ENCODING:
6513 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) == NULL) {
6514 if ((pTemp = strchr(szFieldValue, MSG_CH_SP)) != NULL)
6515 *pTemp++ = MSG_CH_NULL;
6517 *pTemp++ = MSG_CH_NULL;
6520 pType->encoding = _MsgGetCode(MSG_ENCODING, szFieldValue);
6522 MSG_DEBUG("_MsgParsePartHeader: Content-Encoding = %s %d\n", pFieldValue, pType->encoding);
6525 _MsgParseParameter(pType, pTemp);
6529 case MSG_FIELD_CONTENT_DISPOSITION:
6530 if ((pTemp = strchr(szFieldValue, MSG_CH_SEMICOLON)) == NULL) {
6531 if ((pTemp = strchr(szFieldValue, MSG_CH_SP)) != NULL)
6532 *pTemp++ = MSG_CH_NULL;
6534 *pTemp++ = MSG_CH_NULL;
6537 pType->disposition = _MsgGetCode(MSG_DISPOSITION, szFieldValue);
6539 MSG_DEBUG("_MsgParsePartHeader: Content-Disposition = %s %d\n", pFieldValue, pType->disposition);
6542 _MsgParseParameter(pType, pTemp);
6546 #ifdef __SUPPORT_DRM__
6548 case MSG_FIELD_CONTENT_NAME:
6549 /* add to parse DCF header such as,
6550 * Right-Issuer, Content-Name, and Content-Description.
6552 MsgMIMERemoveQuote(szFieldValue);
6553 pType->drmInfo.szContentName = MsgStrCopy(szFieldValue);
6556 case MSG_FIELD_CONTENT_DESCRIPTION:
6557 MsgMIMERemoveQuote(szFieldValue);
6558 pType->drmInfo.szContentDescription = MsgStrCopy(szFieldValue);
6561 case MSG_FIELD_CONTENT_VENDOR:
6562 MsgMIMERemoveQuote(szFieldValue);
6563 pType->drmInfo.szContentVendor = MsgStrCopy(szFieldValue);
6566 case MSG_FIELD_RIGHT_ISSUER:
6567 MsgMIMERemoveQuote(szFieldValue);
6568 pType->drmInfo.szRightIssuer = MsgStrCopy(szFieldValue);
6572 case MSG_FIELD_DRM_CONVERTED:
6573 MsgMIMERemoveQuote(szFieldValue);
6574 pType->nDrmConvertedStatus = atoi(szFieldValue);
6578 case MSG_FILED_CONTENT_REPLACE_POS:
6579 MsgMIMERemoveQuote(szFieldValue);
6580 strncpy(pType->szContentRepPos, szFieldValue, sizeof(pType->szContentRepPos) - 1);
6583 case MSG_FILED_CONTENT_REPLACE_SIZE:
6584 MsgMIMERemoveQuote(szFieldValue);
6585 strncpy(pType->szContentRepSize, szFieldValue, sizeof(pType->szContentRepSize) - 1);
6588 case MSG_FILED_CONTENT_REPLACE_INDEX:
6589 MsgMIMERemoveQuote(szFieldValue);
6590 strncpy(pType->szContentRepIndex, szFieldValue, sizeof(pType->szContentRepIndex) - 1);
6594 MSG_DEBUG("_MsgParsePartHeader: Unhandled field \n");
6599 if (szFieldValue != NULL && szFieldValue != szTempBuf) {
6601 szFieldValue = NULL;
6609 char *MsgRemoveQuoteFromFilename(char *pSrc)
6611 int cLen = 0; // length of pBuff
6615 MSG_DEBUG("MsgRemoveQuoteFromFilename: pSrc is Null\n");
6619 cLen = strlen(pSrc);
6621 pBuff = (char *)malloc(cLen + 1);
6623 if (pBuff == NULL) {
6624 MSG_DEBUG("MsgRemoveQuoteFromFilename: pBuff mem alloc fail!\n");
6627 memset(pBuff, 0 , sizeof(char)*(cLen + 1));
6629 // remove front quote
6630 if (pSrc[0] == MSG_CH_QUOT) {
6632 strncpy(pBuff, &pSrc[1], cLen);
6636 if (pSrc[0] == MSG_CH_LF) {
6638 strncpy(pBuff, &pSrc[1], cLen);
6640 strcpy(pBuff, pSrc);
6643 // remove last qoute
6644 if (pBuff[cLen-1] == MSG_CH_QUOT) {
6645 pBuff[cLen-1] = '\0';
6651 bool MsgIsMultipart(int type)
6653 if (type == MIME_MULTIPART_RELATED || type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED ||
6654 type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED || type == MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC ||
6655 type == MIME_MULTIPART_MIXED || type == MIME_MULTIPART_REPORT) {
6663 bool MsgIsHexChar(char *pSrc)
6669 cLen = strlen(pSrc);
6671 for (cIndex = 0; cIndex < cLen ; cIndex++) {
6672 if ((pSrc[cIndex] >= '0' && pSrc[cIndex] <= '9') || (pSrc[cIndex] >= 'A'&& pSrc[cIndex] <= 'F') ||
6673 (pSrc[cIndex] >= 'a' && pSrc[cIndex] <= 'f')) {
6683 char _MsgConvertHexValue(char *pSrc)
6689 unsigned char uCh[2] = {0,};
6691 cLen = strlen(pSrc);
6693 for (cIndex = 0; cIndex < cLen ; cIndex += 2) {
6694 uCh[0] = __MsgConvertCharToInt(pSrc[cIndex]);
6695 uCh[1] = __MsgConvertCharToInt(pSrc[cIndex+1]);
6696 ch = (int)uCh[0]<<4|uCh[1];
6699 ResultChar = (char)ch;
6704 int __MsgConvertCharToInt(char ch)
6706 if (ch>='0' && ch<='9') {
6708 } else if (ch>='a'&& ch <='f') {
6710 } else if (ch>='A'&& ch <='F') {
6717 bool MsgCopyNestedMsgType(MsgType *pMsgType1, MsgType *pMsgType2)
6719 if (pMsgType1->section == INVALID_HOBJ)
6720 pMsgType1->section = pMsgType2->section;
6722 #ifdef __SUPPORT_DRM__
6725 if (pMsgType1->drmInfo.drmType == MSG_DRM_TYPE_NONE)
6726 pMsgType1->drmInfo.drmType = pMsgType2->drmInfo.drmType;
6729 if (pMsgType1->szContentID[0] == '\0') {
6730 strcpy(pMsgType1->szContentID, pMsgType2->szContentID);
6732 if (pMsgType2->szContentID[0]) {
6733 length = MsgStrlen(pMsgType2->szContentID);
6734 if (pMsgType2->szContentID[0] == '<' && pMsgType2->szContentID[length - 1] == '>') {
6735 pMsgType1->drmInfo.szContentURI = MsgStrNCopy(pMsgType2->szContentID + 1, length - 2);
6737 pMsgType1->drmInfo.szContentURI = MsgStrCopy(pMsgType2->szContentID);
6741 length = MsgStrlen(pMsgType1->szContentID);
6742 if (pMsgType1->szContentID[0] == '<' && pMsgType1->szContentID[length - 1] == '>') {
6743 pMsgType1->drmInfo.szContentURI = MsgStrNCopy(pMsgType1->szContentID + 1, length - 2);
6745 pMsgType1->drmInfo.szContentURI = MsgStrCopy(pMsgType1->szContentID);
6750 if (pMsgType1->szContentLocation[0] == '\0')
6751 strcpy(pMsgType1->szContentLocation, pMsgType2->szContentLocation);
6753 /* Copy informations - we shoud open the pMsgType2's orgFile
6754 * concerning its offset and size.
6756 if (pMsgType2->szOrgFilePath[0] != '\0')
6757 strcpy(pMsgType1->szOrgFilePath, pMsgType2->szOrgFilePath);
6759 if (pMsgType2->disposition != INVALID_HOBJ)
6760 pMsgType1->disposition = pMsgType2->disposition;
6762 if ((pMsgType1->type != MIME_APPLICATION_VND_OMA_DRM_MESSAGE && pMsgType1->type != MIME_APPLICATION_VND_OMA_DRM_CONTENT) &&
6763 pMsgType2->encoding != INVALID_HOBJ)
6764 pMsgType1->encoding = pMsgType2->encoding;
6766 pMsgType1->contentSize = pMsgType2->contentSize;
6767 pMsgType1->offset = pMsgType2->offset;
6768 pMsgType1->size = pMsgType2->size;
6769 pMsgType1->type = pMsgType2->type;
6771 MsgCopyNestedMsgParam(&(pMsgType1->param), &(pMsgType2->param));
6773 if (pMsgType1->param.szName[0]) {
6774 #ifdef __SUPPORT_DRM__
6775 pMsgType1->drmInfo.szContentName = MsgStrCopy(pMsgType2->param.szName);
6783 bool MsgCopyNestedMsgParam(MsgContentParam *pParam1, MsgContentParam *pParam2)
6785 if (pParam1->charset == MSG_CHARSET_UNKNOWN)
6786 pParam1->charset = pParam2->charset;
6788 if (pParam1->type == MIME_UNKNOWN)
6789 pParam1->type = pParam2->type;
6791 /* Don't copy pParam2->pPresentation */
6793 /* For alternative: copy the boundary string */
6794 if (pParam2->szBoundary[0] !='\0')
6795 strcpy(pParam1->szBoundary, pParam2->szBoundary);
6797 if (pParam1->szFileName[0] =='\0')
6798 strcpy(pParam1->szFileName, pParam2->szFileName);
6800 if (pParam1->szName[0] =='\0')
6801 strcpy(pParam1->szName, pParam2->szName);
6803 if (pParam1->szStart[0] =='\0')
6804 strcpy(pParam1->szStart, pParam2->szStart);
6806 if (pParam1->szStartInfo[0] =='\0')
6807 strcpy(pParam1->szStartInfo, pParam2->szStartInfo);
6812 bool MsgIsMultipartMixed(int type)
6814 if (type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED || type == MIME_MULTIPART_MIXED) {
6821 bool MsgStrcpyWithoutCRLF(char *pOrg, char **ppNew)
6829 nLen = strlen(pOrg);
6831 pDest = (char *)malloc(nLen + 1);
6833 if (pDest == NULL) {
6834 MSG_DEBUG("MsgStrcpyWithoutCRLF: malloc is failed\n");
6838 memset(pDest, 0 , (nLen + 1));
6840 for (i = 0; i < nLen ; i++) {
6842 if ((pOrg[i] == MSG_CH_CR && pOrg[i+1] == MSG_CH_LF && pOrg[i+2] == MSG_CH_TAB) ||
6843 (pOrg[i] == MSG_CH_CR && pOrg[i+1] == MSG_CH_LF && pOrg[i+2] == MSG_CH_SP)) {
6848 pDest[index++] = pOrg[i];
6855 bool MmsGetMsgAttrib(MmsMsgID msgID, MmsAttrib* pAttrib)
6857 MmsMsg *pMsg = NULL;
6859 memset(pAttrib, 0, sizeof(MmsAttrib));
6860 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
6861 memcpy(pAttrib, &(pMsg->mmsAttrib), sizeof(MmsAttrib));
6863 MSG_DEBUG("MmsGetMsgAttrib: msgID = %lu ---------------------\n", msgID);
6865 if ('\0' != pMsg->szTrID[0])
6866 MSG_DEBUG("szTrID = %s \n", pMsg->szTrID);
6872 bool __MsgIsInvalidFileNameChar(char ch)
6874 if ((ch == 0x5C /* \ */) ||
6875 (ch == 0x2F /* / */) ||
6876 (ch == 0x3A /* : */) ||
6877 (ch == 0x2A /* * */) ||
6878 (ch == 0x3F /* ? */) ||
6879 (ch == 0x22 /* " */) ||
6880 (ch == 0x3C /* < */) ||
6881 (ch == 0x3E /* > */) ||
6882 (ch == 0x7C /* | */))
6888 bool _MmsDataUpdateLastStatus(MmsMsg *pMsg)
6890 MmsMsgMultiStatus* pStatus = NULL;
6892 pStatus = pMsg->mmsAttrib.pMultiStatus;
6894 while (pStatus != NULL) {
6895 pStatus->bDeliveyrReportIsLast = false;
6896 pStatus->bReadReplyIsLast = false;
6897 pStatus = pStatus->pNext;
6904 bool MmsAddrUtilCompareAddr(char *pszAddr1, char *pszAddr2)
6910 MmsAddrUtilRemovePlmnString(pszAddr1);
6911 MmsAddrUtilRemovePlmnString(pszAddr2);
6913 MSG_DEBUG("##### pszAddr1 = %s #####", pszAddr1);
6914 MSG_DEBUG("##### pszAddr2 = %s #####", pszAddr2);
6915 if (!strcmp(pszAddr1, pszAddr2))
6918 len1 = strlen(pszAddr1);
6919 len2 = strlen(pszAddr2);
6922 p = strstr(pszAddr1, pszAddr2);
6924 p = strstr(pszAddr2, pszAddr1);
6933 int MsgGetLatin2UTFCodeSize(unsigned char *szSrc, int nChar)
6937 MSG_DEBUG("MsgGetLatin2UTFCodeSize: --------------- \n");
6939 if ((szSrc == NULL) || (nChar <= 0)) {
6940 MSG_DEBUG("MsgGetLatin2UTFCodeSize: szSrc is NULL !!!! --------------- \n");
6944 while ((nChar > 0) && (*szSrc != '\0')) {
6945 if (0x01 <= *szSrc && *szSrc <= 0x7F) {
6959 int MsgLatin5code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
6964 unsigned short temp = 0;
6967 outBufSize--; //Null Character
6969 while ((nChar > 0) && (*szSrc != '\0')) {
6971 if (*szSrc >= 0x01 && *szSrc <= 0x7F) { //basic common
6972 temp = (unsigned short)(*szSrc);
6978 *des = (unsigned char) ((*szSrc) & 0x007F);
6983 } else if ((*szSrc == 0x00) || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
6984 (*szSrc >= 0xA0 && *szSrc <= 0xCF) || (*szSrc >= 0xD1 && *szSrc <= 0xDC) ||
6985 (*szSrc >= 0xDF && *szSrc <= 0xEF) || (*szSrc >= 0xF1 && *szSrc <= 0xFC) ||
6986 (*szSrc == 0xFF)) {//uni 0x00A0 ~ 0x00CF
6988 temp = (unsigned short)(*szSrc);
6994 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
6995 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
6997 *des = 0xC0 | (t1 & 0x1F);
6998 *(des+1) = 0x80 | (t2 & 0x3F);
7003 } else if (*szSrc == 0xD0) {//empty section OR vendor specific codes.
7011 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7012 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7014 *des = 0xC0 | (t1 & 0x1F);
7015 *(des+1) = 0x80 | (t2 & 0x3F);
7020 } else if (*szSrc == 0xDD) {
7027 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7028 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7030 *des = 0xC0 | (t1 & 0x1F);
7031 *(des+1) = 0x80 | (t2 & 0x3F);
7036 } else if (*szSrc == 0xDE) {
7043 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7044 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7046 *des = 0xC0 | (t1 & 0x1F);
7047 *(des+1) = 0x80 | (t2 & 0x3F);
7052 } else if (*szSrc == 0xF0) {
7058 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7059 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7061 *des = 0xC0 | (t1 & 0x1F);
7062 *(des+1) = 0x80 | (t2 & 0x3F);
7067 } else if (*szSrc == 0xFD) {
7075 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7076 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7078 *des = 0xC0 | (t1 & 0x1F);
7079 *(des+1) = 0x80 | (t2 & 0x3F);
7084 } else if (*szSrc == 0xFE) {
7091 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7092 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7094 *des = 0xC0 | (t1 & 0x1F);
7095 *(des+1) = 0x80 | (t2 & 0x3F);
7109 int MsgGetLatin52UTFCodeSize(unsigned char *szSrc, int nChar)
7113 MSG_DEBUG("MsgGetLatin52UTFCodeSize: --------------- \n");
7115 if ((szSrc == NULL) || (nChar <= 0))
7118 while ((nChar > 0) && (*szSrc != '\0')) {
7119 if (*szSrc >= 0x01 && *szSrc <= 0x7F) {
7123 } else if (*szSrc == 0x00 || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
7124 (*szSrc >= 0xA0 && *szSrc <= 0xCF) || (*szSrc >= 0xD1 && *szSrc <= 0xDC) |
7125 (*szSrc >= 0xDF && *szSrc <= 0xEF) || (*szSrc >= 0xF1 && *szSrc <= 0xFC) ||
7126 *szSrc == 0xD0 || *szSrc == 0xDD || *szSrc == 0xDE || *szSrc == 0xF0 ||
7127 *szSrc == 0xFD || *szSrc == 0xFE || *szSrc == 0xFF) { //uni 0x00A0 ~ 0x00CF
7138 int MsgLatin2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
7141 unsigned char t1, t2;
7143 MSG_DEBUG("MsgLatin2UTF: --------------- \n");
7146 outBufSize--; // NULL character
7148 while ((nChar > 0) && (*szSrc != '\0')) {
7149 if (0x01 <= *szSrc && *szSrc <= 0x7F) {
7150 /* check outbuffer's room for this UTF8 character */
7156 *des = (unsigned char) (*szSrc & 0x007F);
7162 /* check outbuffer's room for this UTF8 character */
7168 t2 = (unsigned char) (*szSrc & 0x003F); // right most 6 bit
7169 t1 = (unsigned char) ((*szSrc & 0xC0) >> 6); // right most 2 bit
7171 *des = 0xC0 | (t1 & 0x1F);
7172 *(des + 1) = 0x80 | (t2 & 0x3F);
7187 int MsgLatin7code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
7193 unsigned short temp = 0;
7195 MSG_DEBUG("MsgUnicode2UTF: --------------- \n");
7198 outBufSize--; //Null Character
7200 while ((nChar > 0) && (*szSrc != '\0')) {
7201 if (*szSrc >= 0x01 && *szSrc <= 0x7F) {
7202 temp = (unsigned short)(*szSrc);
7208 *des = (unsigned char) (temp & 0x007F);
7214 } else if ((*szSrc == 0x00) || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
7215 (*szSrc >= 0xA3 && *szSrc <= 0xAD) || (*szSrc == 0xBB)) { // consider 0xA4, 0xA5
7217 temp = (unsigned short)(*szSrc);
7223 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7224 t1 = (unsigned char) ((temp & 0xC0) >> 6); // right most 2 bit
7226 *des = 0xC0 | (t1 & 0x1F);
7227 *(des + 1) = 0x80 | (t2 & 0x3F);
7232 } else if (*szSrc == 0xA0) {
7234 //*des = temp to utf-8
7239 *des = (unsigned char) (temp & 0x007F);
7245 } else if (*szSrc == 0xA1) {
7252 t3 = (unsigned char) (temp & 0x003F); // right most 6 bit
7253 t2 = (unsigned char) ((temp & 0x0FC0) >> 6); // right most 6 bit
7254 t1 = (unsigned char) ((temp & 0xF000) >> 12); // right most 4 bit
7256 *des = 0xE0 | (t1 & 0x0F);
7257 *(des+1) = 0x80 | (t2 & 0x3F);
7258 *(des+2) = 0x80 | (t3 & 0x3F);
7264 } else if (*szSrc == 0xA2) {
7271 t3 = (unsigned char) (temp & 0x003F); // right most 6 bit
7272 t2 = (unsigned char) ((temp & 0x0FC0) >> 6); // right most 6 bit
7273 t1 = (unsigned char) ((temp & 0xF000) >> 12); // right most 4 bit
7275 *des = 0xE0 | (t1 & 0x0F);
7276 *(des+1) = 0x80 | (t2 & 0x3F);
7277 *(des+2) = 0x80 | (t3 & 0x3F);
7283 } else if (*szSrc == 0xAF) {
7290 t3 = (unsigned char) (temp & 0x003F); // right most 6 bit
7291 t2 = (unsigned char) ((temp & 0x0FC0) >> 6); // right most 6 bit
7292 t1 = (unsigned char) ((temp & 0xF000) >> 12); // right most 4 bit
7294 *des = 0xE0 | (t1 & 0x0F);
7295 *(des+1) = 0x80 | (t2 & 0x3F);
7296 *(des+2) = 0x80 | (t3 & 0x3F);
7302 } else if (0xB0 <= *szSrc && *szSrc <= 0xB4) { //0x00B0 ~ 0x00B4
7304 temp = (unsigned short)(*szSrc);
7310 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7311 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7313 *des = 0xC0 | (t1 & 0x1F);
7314 *(des+1) = 0x80 | (t2 & 0x3F);
7320 } else if ((0xB5 <= *szSrc && *szSrc <= 0xBA) ||
7321 (0xBC <= *szSrc && *szSrc <= 0xD1) ||
7322 (0xD3 <= *szSrc && *szSrc <= 0xFE)) {
7323 temp= (unsigned short)(*szSrc + 0x02D0);
7329 t2 = (unsigned char) (temp & 0x003F); // right most 6 bit
7330 t1 = (unsigned char) ((temp & 0x07C0) >> 6); // right most 5 bit
7332 *des = 0xC0 | (t1 & 0x1F);
7333 *(des+1) = 0x80 | (t2 & 0x3F);
7350 int MsgGetLatin72UTFCodeSize(unsigned char *szSrc, int nChar)
7354 MSG_DEBUG("MsgGetLatin72UTFCodeSize: --------------- \n");
7356 if ((szSrc == NULL) || (nChar <= 0))
7359 while ((nChar > 0) && (*szSrc != '\0')) {
7361 if ((*szSrc >= 0x01 && *szSrc <= 0x7F) || (*szSrc == 0xA0)) {
7365 } else if (*szSrc == 0x00 || (0x80 <= *szSrc && *szSrc <= 0x9F) || (0xA3 <= *szSrc && *szSrc <= 0xAD) ||
7366 (0xB0 <= *szSrc && *szSrc <= 0xB4) || (0xB5 <= *szSrc && *szSrc <= 0xFE)) {
7370 } else if (*szSrc == 0xA1 ||*szSrc == 0xA2 || *szSrc == 0xAF) {
7382 int MsgUnicode2UTF(unsigned char *des, int outBufSize, unsigned short *szSrc, int nChar)
7389 MSG_DEBUG("MsgUnicode2UTF: --------------- \n");
7392 outBufSize--; // NULL character
7394 while ((nChar > 0) && (*szSrc != '\0')) {
7395 if (0x0001 <= *szSrc && *szSrc <= 0x007F) {
7396 /* check outbuffer's room for this UTF8 character */
7402 *des = (unsigned char) (*szSrc & 0x007F);
7407 } else if ((*szSrc == 0x0000) || (0x0080 <= *szSrc && *szSrc <= 0x07FF)) {
7408 /* check outbuffer's room for this UTF8 character */
7414 t2 = (unsigned char) (*szSrc & 0x003F); // right most 6 bit
7415 t1 = (unsigned char) ((*szSrc & 0x07C0) >> 6); // right most 5 bit
7417 *des = 0xC0 | (t1 & 0x1F);
7418 *(des+1) = 0x80 | (t2 & 0x3F);
7424 /* check outbuffer's room for this UTF8 character */
7430 t3 = (unsigned char) (*szSrc & 0x003F); // right most 6 bit
7431 t2 = (unsigned char) ((*szSrc & 0x0FC0) >> 6); // right most 6 bit
7432 t1 = (unsigned char) ((*szSrc & 0xF000) >> 12); // right most 4 bit
7434 *des = 0xE0 | (t1 & 0x0F);
7435 *(des+1) = 0x80 | (t2 & 0x3F);
7436 *(des+2) = 0x80 | (t3 & 0x3F);
7450 int MsgGetUnicode2UTFCodeSize(unsigned short *szSrc, int nChar)
7454 MSG_DEBUG("MsgGetUnicode2UTFCodeSize: --------------- \n");
7456 if ((szSrc == NULL) || (nChar <= 0)) {
7457 MSG_DEBUG("MsgGetUnicode2UTFCodeSize: szSrc is NULL !!!! --------------- \n");
7461 while ((nChar > 0) && (*szSrc != '\0')) {
7462 if (0x0001 <= *szSrc && *szSrc <= 0x007F) {
7466 } else if ((*szSrc == 0x0000) || (0x0080 <= *szSrc && *szSrc <= 0x07FF)) {
7480 bool MmsAddrUtilCheckEmailAddress(char *pszAddr)
7482 if (!pszAddr || pszAddr[0] == 0)
7485 if (!strchr (pszAddr, MSG_MMS_CH_EMAIL_AT))
7491 bool MmsAddrUtilRemovePlmnString(char *pszAddr)
7493 char *pszAddrCopy = NULL;
7494 char *pszStrStart = NULL;
7495 char *pszStrTemp = NULL;
7498 if ((!pszAddr) || (pszAddr[0] == 0)) {
7499 MSG_DEBUG("MmsAddrUtilRemovePlmnString: pszAddr is null or zero\n");
7503 strLen = strlen(pszAddr);
7505 pszAddrCopy = (char*)calloc(1,strLen + 1);
7507 MSG_DEBUG("MmsAddrUtilRemovePlmnString: pszAddrCopy is NULL, mem alloc failed\n");
7511 strcpy(pszAddrCopy, pszAddr);
7515 pszStrStart = pszAddrCopy;
7518 char* pszStrEnd = NULL;
7521 if (MmsAddrUtilCheckEmailAddress(pszAddrCopy))
7522 pszStrEnd = strstr(pszStrStart, "/TYPE=PLMN");
7524 pszStrEnd = strstr(pszStrStart, "/");
7527 // "/TYPE=PLMN" not found
7529 int remainedLen = strlen(pszStrStart);
7531 if (remainedLen <= 0)
7534 strcat(pszAddr, pszStrStart);
7539 // Get one address length
7540 addressLen = pszStrEnd - pszStrStart;
7542 strncat(pszAddr, pszStrStart, addressLen);
7544 // Find next address
7545 pszStrStart = pszStrEnd;
7547 pszStrTemp = strstr(pszStrStart, MSG_MMS_STR_ADDR_DELIMETER);
7550 addressLen = pszStrTemp - pszStrEnd;
7551 pszStrStart += addressLen;
7553 pszStrStart += strlen(pszStrEnd);
7556 if (pszStrStart[0] == 0) // end of string
7560 strcat(pszAddr, MSG_MMS_STR_ADDR_DELIMETER); // add ';'
7561 pszStrStart++; // remove ';'
7564 if (pszAddr[0] == 0)
7565 strcpy(pszAddr, pszAddrCopy);
7572 int MsgCutUTFString(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
7576 MSG_DEBUG("MsgCutUTFString: --------------- \n");
7579 outBufSize--; // NULL character
7581 while ((nChar > 0) && (*szSrc != '\0')) {
7582 if (*szSrc < 0x80) {
7590 } else if (((0xC0 <= *szSrc) && (*szSrc < 0xE0)) && (*(szSrc+1) >= 0x80)) {
7596 *(des + 1) = *(szSrc + 1);
7600 } else if ((*szSrc >= 0xE0) && (*(szSrc+1) >= 0x80) && (*(szSrc+2) >= 0x80)) {
7606 *(des + 1) = *(szSrc + 1);
7607 *(des + 2) = *(szSrc + 2);
7619 MSG_DEBUG("MsgCutUTFString: utf8 incorrect range!\n");
7631 void MsgMIMERemoveQuote(char *szSrc)
7635 length = MsgStrlen(szSrc);
7636 if (szSrc[0] == MSG_CH_QUOT && szSrc[length-1] == MSG_CH_QUOT) {
7639 for (index = 0; index < length-2; index++)
7640 szSrc[index] = szSrc[index+1];
7641 szSrc[index] = '\0';
7645 bool MsgLoadDataToDecodeBuffer(FILE *pFile, char **ppBuf, int *pPtr, int *pOffset, char *pInBuf1, char *pInBuf2, int maxLen, int *pBufLen, int endOfFile)
7651 MSG_DEBUG("MsgLoadDataToDecodeBuffer: \n");
7653 if (pFile == NULL) {
7660 if (pPtr == NULL || pInBuf1 == NULL || pInBuf2 == NULL) {
7667 if (*pBufLen == 0) {
7668 length = maxLen - (*pPtr);
7670 length = (*pBufLen) - (*pPtr);
7676 if ((*ppBuf) == NULL) {
7677 memset(pInBuf1, 0, maxLen);
7679 } else if ((*ppBuf) == pInBuf1) {
7680 memset(pInBuf2, 0, maxLen);
7682 memcpy(pInBuf2, pInBuf1 + (*pPtr), length);
7685 memset(pInBuf1, 0, maxLen);
7687 memcpy(pInBuf1, pInBuf2 + (*pPtr), length);
7693 if (*pOffset == endOfFile) {
7698 if (maxLen == length) {
7700 if (MsgReadFileForDecode(pFile, (*ppBuf), maxLen, &nRead) == false)
7705 if (MsgReadFileForDecode(pFile, (*ppBuf) + length, maxLen - length, &nRead) == false)
7708 *pBufLen = length + nRead;
7711 if ((*pOffset = MsgFtell(pFile)) == -1L) {
7712 MSG_DEBUG("MsgFtell Error");
7722 bool MsgGetTypeByFileName(int *type, char *szFileName)
7725 AvCodecType AvType = AV_CODEC_NONE;
7727 pExt = strrchr(szFileName, '.');
7728 if (pExt == NULL || pExt[0] == '\0')
7733 if (strcasecmp(pExt, "mp4") == 0 ||strcasecmp(pExt, "mpeg4") == 0 ||strcasecmp(pExt, "3gp") == 0 ||strcasecmp(pExt, "3gpp") == 0) {
7735 if (szFileName[0] != '/')
7738 AvType = AvGetFileCodecType(szFileName);
7739 MSG_DEBUG("MsgGetTypeByFileName:AvType(0x%x)\n", AvType);
7742 case AV_DEC_AUDIO_MPEG4:
7743 *type = MIME_AUDIO_MP4;
7746 case AV_DEC_VIDEO_MPEG4:
7747 *type = MIME_VIDEO_MP4;
7751 *type = MIME_VIDEO_3GPP;
7757 if (strcasecmp(pExt, "amr") == 0) {
7758 *type = MIME_AUDIO_AMR;
7760 } else if ((strcasecmp(pExt, "mid") == 0) || (strcasecmp(pExt, "midi") == 0)) {
7761 *type = MIME_AUDIO_MIDI;
7763 } else if (strcasecmp(pExt, "imy") == 0) {
7764 *type = MIME_TEXT_X_IMELODY;
7768 *type = MimeGetMimeFromExtInt((const char*)pExt);
7769 MSG_DEBUG("MsgGetTypeByFileName: szFileName = %s type = %d \n", szFileName, type);
7775 *type = MIME_UNKNOWN;
7776 MSG_DEBUG("MsgGetTypeByFileName: szFileName = %s type = %d \n", szFileName, type);
7784 * This function write media data from raw data to file.
7787 * @param pszMailboxPath : path of mailbox
7788 * @param pszMsgFilename : name of msg file
7789 * @param index : used for file naming
7790 * @param bSave : if true, file will be save otherwise just filename will be stored.
7792 bool _MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody, char *pszMailboxPath, char *pszMsgFilename, int index, bool bSave)
7795 // char *pExt = NULL;
7796 char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, }; // file name of temp file
7797 char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, }; // full absolute path of temp file.
7799 MSG_DEBUG("**** _MmsSaveMediaData: [Multi part] START ***\n");
7802 MSG_DEBUG("pPartType is NULL\n");
7803 return true; // why true value is retured ??? ; false;
7806 if (pPartType->param.szName[0] == '\0' && pPartType->param.szFileName[0] == '\0')
7807 snprintf(pPartType->param.szName, sizeof(pPartType->param.szName), "%s", pPartType->param.szFileName);
7809 if (pPartType->param.szName[0] != '\0') {
7810 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", pPartType->param.szName);
7812 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%lu", (unsigned long)index);
7816 #ifndef __SUPPORT_DRM__
7817 MsgMakeFileName(pPartType->type, szFileName, 0); //FL & CD -> extension(.dm) SD -> extension(.dcf)
7819 MsgMakeFileName(pPartType->type, szFileName, pPartType->drmInfo.drmType, 0); //FL & CD -> extension(.dm) SD -> extension(.dcf)
7820 if (MsgDRMIsForwardLockType(pPartType->drmInfo.drmType))
7821 MsgChangeDrm2FileName(szFileName);
7825 snprintf(szFullPath, MSG_FILEPATH_LEN_MAX, "%s%s.dir/%s", pszMailboxPath, pszMsgFilename, szFileName); // get absolute path of each temp file of each part
7826 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.
7828 if (pPartType->type == MIME_APPLICATION_OCTET_STREAM)
7829 MsgGetTypeByFileName(&pPartType->type, szFullPath);
7833 if ((pFile = MsgOpenFile(szFullPath, "wb+")) == NULL) {
7834 MSG_DEBUG("MsgOpenFile failed");
7838 if (MmsGetMediaPartData(pPartType, pPartBody, pFile) == false) {
7839 MSG_DEBUG("MmsGetMediaPartData fail [index:%d]\n", index);
7843 MsgCloseFile(pFile);
7845 if (pPartType->drmInfo.drmType != MSG_DRM_TYPE_NONE) {
7846 MsgDrmRegisterFile(MSG_MODE_FILE, szFullPath, strlen(szFullPath));
7848 /* change szDrm2FullPath as current content path*/
7849 if (pPartType->drmInfo.szDrm2FullPath) {
7850 free(pPartType->drmInfo.szDrm2FullPath);
7851 pPartType->drmInfo.szDrm2FullPath = MsgStrCopy(szFullPath);
7856 MSG_DEBUG("**** MmsGetMediaPartData: [Multi part] E N D (Successfully) ***\n");
7862 if (pFile != NULL) {
7863 MsgCloseFile(pFile);
7872 bool MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE* pFile)
7877 char *pNewData = NULL;
7878 char *pTempData = NULL;
7879 int msgEncodingValue = 0;
7880 int msgTypeValue = 0;
7881 int msgCharsetValue = 0;
7887 msgEncodingValue = pPartType->encoding;
7888 msgTypeValue = pPartType->type;
7889 msgCharsetValue = pPartType->param.charset;
7891 cidLen = MsgStrlen(szCid);
7893 offset = pPartBody->offset;
7894 size = pPartBody->size;
7896 if (pPartBody->szOrgFilePath[0]) {
7897 pTempData = MsgOpenAndReadMmsFile(pPartBody->szOrgFilePath, offset, size, &nRead);
7899 if (pTempData == NULL) {
7900 MSG_DEBUG("MmsGetMediaPartData : pTempData read fail\n");
7905 } else if (pPartBody->body.pText) {
7906 pData = pPartBody->body.pText;
7907 nRead = pPartBody->size;
7910 if (pData == NULL) {
7911 MSG_DEBUG("MmsGetMediaPartData : there is no data \n");
7915 pNewData = MmsGetBinaryUTF8Data(pData, nRead, msgEncodingValue, msgTypeValue, msgCharsetValue, &nRead2);
7916 pPartType->encoding = MSG_ENCODING_BINARY;
7918 if (MsgIsText(msgTypeValue))
7919 pPartType->param.charset = MSG_CHARSET_UTF8;
7921 if (MsgWriteFile(pNewData, sizeof(char), nRead2, pFile) != (size_t)nRead2) {
7922 MSG_DEBUG("MmsGetMediaPartData: file writing fail \n");
7956 char *MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue, int msgTypeValue, int msgCharsetValue, int *npRead)
7962 unsigned short *mszTempStr = NULL;
7963 char *pConvertedStr = NULL;
7964 char *pConvertedData = NULL;
7965 char *pNewData = NULL;
7966 char *pReturnData = NULL;
7969 switch (msgEncodingValue) {
7970 case MSG_ENCODING_BASE64:
7972 pConvertedData = (char*)_MsgDecodeBase64((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
7973 MSG_DEBUG("MmsGetBinaryUTF8Data : MSG_ENCODING_BASE64 bodyLength = %d \n", nByte);
7975 pTemp = pConvertedData;
7980 case MSG_ENCODING_QUOTE_PRINTABLE:
7982 pConvertedData = (char*)_MsgDecodeQuotePrintable((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
7983 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_ENCODING_QUOTE_PRINTABLE bodyLength = %d \n", nByte);
7985 pTemp = pConvertedData;
7992 MSG_DEBUG("MmsGetBinaryUTF8Data: 8bit OR Binary bodyLength = %d \n", nRead);
8000 if (MsgIsText(msgTypeValue)) {
8001 /* charset converting */
8003 switch (msgCharsetValue) {
8004 case MSG_CHARSET_UTF16:
8005 case MSG_CHARSET_USC2:
8007 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_USC2 \n");
8009 if (((UINT8)pTemp[0]) == 0xFF && ((UINT8)pTemp[1]) == 0xFE) {
8010 nChar = (nTemp / 2 - 1);
8012 mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
8013 if (mszTempStr == NULL) {
8014 MSG_DEBUG("MmsGetBinaryUTF8Data : 1. Memory Full !!! \n");
8018 memcpy(mszTempStr, ((unsigned short*)pTemp + 1), nChar * sizeof(unsigned short));
8020 nByte = MsgGetUnicode2UTFCodeSize(((unsigned short*)pTemp + 1), nChar);
8022 nByte = 3; //min value
8024 pConvertedStr = (char *)malloc(nByte + 1);
8025 if (pConvertedStr != NULL)
8026 MsgUnicode2UTF ((unsigned char*)pConvertedStr, nByte + 1, mszTempStr, nChar);
8028 nChar = (nTemp / 2);
8030 mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
8031 if (mszTempStr == NULL) {
8032 MSG_DEBUG("MmsGetBinaryUTF8Data: 2. Memory Full !!! \n");
8036 memcpy(mszTempStr, ((unsigned short*)pTemp), nChar * sizeof(unsigned short));
8038 nByte = MsgGetUnicode2UTFCodeSize(((unsigned short*)pTemp), nChar);
8040 pConvertedStr = (char *)malloc(nByte + 1);
8042 MsgUnicode2UTF ((unsigned char*)pConvertedStr, nByte + 1, mszTempStr, nChar);
8045 if (pConvertedStr != NULL)
8046 pNewData = pConvertedStr;
8048 *npRead = nByte + 1;
8052 case MSG_CHARSET_US_ASCII:
8054 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_US_ASCII \n");
8058 case MSG_CHARSET_UTF8:
8060 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_UTF8 or Others \n");
8062 // skip BOM (Byte Order Mark) bytes .. (Please refer to the http://www.unicode.org/faq/utf_bom.html#BOM)
8064 if (((UINT8)pTemp[0]) == 0xEF && ((UINT8)pTemp[1]) == 0xBB && ((UINT8)pTemp[2]) == 0xBF) {
8074 case MSG_CHARSET_ISO_8859_7:
8078 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_ISO_8859_7 \n");
8080 nByte = MsgGetLatin72UTFCodeSize((unsigned char*)pTemp, nTemp);
8081 pConvertedStr = (char *)malloc(nByte + 1);
8083 MsgLatin7code2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTemp, nTemp);
8085 pNewData = pConvertedStr;
8086 *npRead = nByte + 1;
8090 case MSG_CHARSET_ISO_8859_9:
8093 MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_ISO_8859_9 \n");
8095 nByte = MsgGetLatin52UTFCodeSize((unsigned char*)pTemp, nTemp);
8096 pConvertedStr = (char *)malloc(nByte + 1);
8098 MsgLatin5code2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTemp, nTemp);
8100 pNewData = pConvertedStr;
8101 *npRead = nByte + 1;
8107 MSG_DEBUG("MmsGetBinaryUTF8Data: Other charsets \n");
8109 nByte = MsgGetLatin2UTFCodeSize((unsigned char*)pTemp, nTemp);
8110 pConvertedStr = (char *)malloc(nByte + 1);
8112 MsgLatin2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTemp, nTemp);
8114 pNewData = pConvertedStr;
8115 *npRead = nByte + 1;
8124 pReturnData = (char *)malloc(*npRead);
8125 if (pReturnData == NULL) {
8126 MSG_DEBUG("MmsGetBinaryUTF8Data : pReturnData alloc fail. \n");
8131 if (pNewData != NULL) {
8132 memset(pReturnData, 0, *npRead);
8133 memcpy(pReturnData, pNewData, *npRead);
8136 if (pConvertedData) {
8137 free(pConvertedData);
8138 pConvertedData = NULL;
8141 if (pConvertedStr) {
8142 free(pConvertedStr);
8143 pConvertedStr = NULL;
8155 if (pConvertedData) {
8156 free(pConvertedData);
8157 pConvertedData = NULL;
8160 if (pConvertedStr) {
8161 free(pConvertedStr);
8162 pConvertedStr = NULL;
8173 #ifndef __SUPPORT_DRM__
8174 bool MsgMakeFileName(int iMsgType, char *szFileName, int nUntitleIndex)
8176 char szText[MSG_FILENAME_LEN_MAX+1]={0,};
8177 char szTemp[MSG_FILENAME_LEN_MAX+1]={0,};
8178 char szTempFileName[MSG_FILENAME_LEN_MAX+1]={0,};
8182 MSG_DEBUG("MsgMakeFileName: iMsgType = %d szFileName = %s \n", iMsgType, szFileName);
8184 if (szFileName == NULL)
8187 if (szFileName && (szFileName[0] != '\0')) {
8188 MsgGetFileNameWithoutExtension (szTempFileName, szFileName);
8190 pExt = strrchr(szTempFileName, '.');
8192 memset (szText, 0, MSG_FILENAME_LEN_MAX+1);
8193 strncpy(szText, szTempFileName, MSG_FILEPATH_LEN_MAX - 1);
8194 strcat(szText, "."); // add '.'
8196 memset (szText, 0, MSG_FILENAME_LEN_MAX+1);
8197 strncpy(szText, szTempFileName, pExt+1 - szFileName); // add '.'
8200 if (nUntitleIndex >= 1) {
8201 snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s_%d.", "Untitled", nUntitleIndex);
8203 snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s.", "Untitled");
8207 if (iMsgType == MIME_APPLICATION_OCTET_STREAM) {
8208 MSG_DEBUG("MsgMakeFileName: unsupported MsgType\n");
8212 strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
8213 if (iMsgType == MIME_UNKNOWN || (pExt = MimeGetExtFromMimeInt((MimeType)iMsgType)) == NULL) {
8214 MSG_DEBUG("MsgMakeFileName: Failed to get extension of that mime data file. \n");
8217 nLen = MSG_FILENAME_LEN_MAX - strlen(szTemp);
8218 strncat(szTemp, pExt, nLen);
8222 strcpy(szFileName, szTemp);
8224 MSG_DEBUG("MsgMakeFileName: made szFileName = %s \n", szFileName);
8231 p = strrchr(szText, '.');
8234 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", szText);
8240 bool MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex)
8242 char szText[MSG_FILENAME_LEN_MAX+1]={0,};
8243 char szTemp[MSG_FILENAME_LEN_MAX+1]={0,};
8244 char szTempFileName[MSG_FILENAME_LEN_MAX+1]={0,};
8247 MSG_DEBUG("MsgMakeFileName: iMsgType = 0x%x, drmType = %d, szFileName = %s \n", iMsgType, drmType, szFileName);
8249 if (szFileName == NULL)
8252 if (szFileName && (szFileName[0] != '\0')) {
8253 MsgGetFileNameWithoutExtension (szTempFileName, szFileName);
8255 if (drmType != MSG_DRM_TYPE_NONE) {
8256 pExt = strrchr(szTempFileName, '.');
8258 memset(szText, 0, MSG_FILENAME_LEN_MAX+1);
8259 strncpy(szText, szTempFileName, MSG_FILENAME_LEN_MAX - 1);
8260 strcat(szText, "."); // add '.'
8262 memset(szText, 0, MSG_FILENAME_LEN_MAX+1);
8263 strncpy(szText, szTempFileName, pExt+1 - szFileName);
8266 if (strrchr(szTempFileName, '.'))
8269 memset(szText, 0, MSG_FILENAME_LEN_MAX+1);
8270 strncpy(szText, szTempFileName, MSG_FILENAME_LEN_MAX - 1);
8271 //temporary commented to save file as original name.
8272 pExt = strrchr(szFileName, '.');
8275 if (nUntitleIndex >= 1) {
8276 snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s_%d.", "untitled", nUntitleIndex);
8278 snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s.", "untitled");
8282 if (drmType == MSG_DRM_TYPE_SD) {
8283 strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
8284 strcat(szTemp, "dcf");
8285 } else if (MsgDRMIsForwardLockType(drmType)) {
8286 strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 4);
8287 strcat(szTemp, "dm");
8289 if (iMsgType == MIME_APPLICATION_OCTET_STREAM) {
8290 MSG_DEBUG("MsgMakeFileName: unsupported MsgType\n");
8294 strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
8295 //temporary commented to save file as original name.
8298 if (iMsgType == MIME_UNKNOWN || (pExt = MimeGetExtFromMimeInt((MimeType)iMsgType)) == NULL) {
8299 MSG_DEBUG("MsgMakeFileName: Failed to get extension of that mime data file. \n");
8304 nLen = MSG_FILENAME_LEN_MAX - strlen(szTemp);
8305 strncat(szTemp, pExt, nLen);
8309 strcpy(szFileName, szTemp);
8311 MSG_DEBUG("MsgMakeFileName: made szFileName = %s \n", szFileName);
8318 p = strrchr(szText, '.');
8321 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", szText);
8328 bool MsgGetFileNameWithoutExtension (char *szOutputName, char *szName)
8330 char *pszExt = NULL;
8332 if (szOutputName == NULL) {
8333 MSG_DEBUG("szOutputName is NULL");
8337 strncpy(szOutputName, szName, strlen(szName));
8339 if ((pszExt = strrchr(szOutputName, '.'))) {
8340 if (pszExt[0] == '.')
8347 int MmsGetMediaPartCount(msg_message_id_t msgId)
8351 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
8353 if (msgId != pMsg->msgID) {
8354 MSG_DEBUG("Invalid Message Id");
8358 return pMsg->nPartCount;
8361 bool MmsGetMediaPartHeader(int index, MsgType *pHeader)
8363 MmsMsg *pMsg = NULL;
8364 MsgMultipart *pPart = NULL;
8366 if (pHeader == NULL) {
8367 MSG_DEBUG("MmsGetMediaPartHeader: Invalid pHeader input. It's null \n");
8371 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
8373 _MsgInitMsgType(pHeader);
8376 /* Requires header of non-presentation */
8377 if (MsgIsMultipart(pMsg->msgType.type)) {
8378 MSG_DEBUG("MmsGetMediaPartHeader: Multipart header [index = %d] \n", index);
8380 pPart = pMsg->msgBody.body.pMultipart;
8382 while (pPart && index--)
8383 pPart = pPart->pNext;
8385 if (pPart == NULL) {
8386 MSG_DEBUG("MmsGetMediaPartHeader: There is no such msg part.\n");
8390 memcpy(pHeader, &pPart->type, sizeof(MsgType));
8392 MSG_DEBUG("MmsGetMediaPartHeader: Requires singlepart header \n");
8393 memcpy(pHeader, &pMsg->msgType, sizeof(MsgType));
8399 bool MmsDebugPrintMulitpartEntry(MsgMultipart *pMultipart, int index)
8401 MSG_DEBUG("------------------------------\n");
8402 MSG_DEBUG("%dth multipart info\n", index);
8403 MSG_DEBUG("header size=%d\n", pMultipart->type.size);
8404 MSG_DEBUG("body size=%d\n", pMultipart->type.contentSize);
8405 MSG_DEBUG("content type=%s\n", MmsDebugGetMimeType((MimeType)pMultipart->type.type));
8406 MSG_DEBUG("content ID=%s\n", pMultipart->type.szContentID);
8407 MSG_DEBUG("content location=%s\n", pMultipart->type.szContentLocation);
8409 if (pMultipart->type.type == MIME_TEXT_PLAIN) {
8410 MSG_DEBUG("text info\n");
8411 MSG_DEBUG("charset=%d\n", pMultipart->type.param.charset);
8412 MSG_DEBUG("text file name=%s\n", pMultipart->type.param.szName);
8414 #ifdef __SUPPORT_DRM__
8415 if (pMultipart->type.drmInfo.drmType != MSG_DRM_TYPE_NONE) {
8416 MSG_DEBUG("drm info\n");
8417 MSG_DEBUG("drm type=%d (0: NONE 1: Fowward Lock, 2:Combined Delivery, 3: Separated Delivery)\n", pMultipart->type.drmInfo.drmType);
8418 MSG_DEBUG("drm content type=%s\n", MmsDebugGetMimeType((MimeType)pMultipart->type.drmInfo.contentType));
8419 MSG_DEBUG("drm content URI=%s\n", pMultipart->type.drmInfo.szContentURI);
8420 MSG_DEBUG("drm2FullPath=%s\n", pMultipart->type.drmInfo.szDrm2FullPath);
8423 MSG_DEBUG("------------------------------\n");