Modify flora license version.
[platform/core/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginInternal.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (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
7 *
8 *    http://floralicense.org/license/
9 *
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.
15 */
16
17 #include <stdlib.h>
18 #include <errno.h>
19 #include <sys/stat.h>
20
21 #include "MsgUtilFile.h"
22 #include "MsgException.h"
23 #include "MsgSettingTypes.h"
24 #include "MsgMmsMessage.h"
25 #include "MsgGconfWrapper.h"
26 #include "MsgStorageHandler.h"
27 #include "MmsPluginDebug.h"
28 #include "MmsPluginTypes.h"
29 #include "MmsPluginCodec.h"
30 #include "MmsPluginInternal.h"
31 #include "MmsPluginStorage.h"
32 #include "MmsPluginSmil.h"
33 /*==================================================================================================
34                                      IMPLEMENTATION OF MmsPluginInternal - Member Functions
35 ==================================================================================================*/
36 MmsPluginInternal *MmsPluginInternal::pInstance = NULL;
37
38
39 MmsPluginInternal::MmsPluginInternal()
40 {
41
42 }
43
44 MmsPluginInternal::~MmsPluginInternal()
45 {
46
47 }
48
49 MmsPluginInternal *MmsPluginInternal::instance()
50 {
51         if (!pInstance)
52                 pInstance = new MmsPluginInternal();
53
54         return pInstance;
55 }
56
57 void MmsPluginInternal::processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest, bool *bReject)
58 {
59         MSG_BEGIN();
60
61         FILE *pFile = NULL;
62         char fileName[MSG_FILENAME_LEN_MAX] = {0,};
63
64         if (pMsgInfo->bTextSms == true) {
65                 char fullPath[MAX_FULL_PATH_SIZE+1] = {0,};
66
67                 if(MsgCreateFileName(fileName) == false)
68                         THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
69
70                 MSG_DEBUG("File name = %s", fileName);
71
72                 if(MsgWriteIpcFile(fileName, pMsgInfo->msgText, pMsgInfo->dataSize) == false)
73                         THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
74
75                 snprintf(fullPath, MAX_FULL_PATH_SIZE+1, MSG_IPC_DATA_PATH"%s", fileName);
76
77                 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
78                 memcpy(pMsgInfo->msgData, fullPath, strlen(fullPath));
79                 pMsgInfo->bTextSms = false;
80         }
81
82         MSG_DEBUG("MMS File Path = %s", pMsgInfo->msgData);
83
84         MmsInitHeader();
85         MmsRegisterDecodeBuffer();
86
87         if ((pFile = MsgOpenFile(pMsgInfo->msgData, "rb+")) == NULL) {
88                 MSG_DEBUG("File Open Error: %s", pMsgInfo->msgData);
89         } else {
90                 //Decode Header
91                 if (!MmsBinaryDecodeMsgHeader(pFile, pMsgInfo->dataSize))
92                         MSG_DEBUG("Decoding Header Failed \r\n");
93
94                 MsgDeleteFile(pMsgInfo->msgData + strlen(MSG_IPC_DATA_PATH));
95
96                 switch (mmsHeader.type) {
97                 case MMS_MSGTYPE_NOTIFICATION_IND:
98                         MSG_DEBUG("process noti.ind\n");
99                         // For Set Value pMsgInfo
100                         if (processNotiInd(pMsgInfo, pRequest) == false)
101                                 *bReject = true;
102                         else
103                                 *bReject = false;
104                         break;
105
106                 case MMS_MSGTYPE_DELIVERY_IND:
107                         MSG_DEBUG("process delivery.ind\n");
108                         // For Set Value pMsgInfo
109                         processDeliveryInd(pMsgInfo);
110                         break;
111
112                 case MMS_MSGTYPE_READORG_IND:
113                         MSG_DEBUG("process readorig.ind\n");
114                         processReadOrgInd(pMsgInfo);
115                         break;
116                 default:
117                         break;
118                 }
119
120                 MsgCloseFile(pFile);
121         }
122
123         MSG_END();
124 }
125
126 bool MmsPluginInternal::processNotiInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest)
127 {
128         MSG_DEBUG("MmsProcessNotiInd");
129         msg_error_t     err = MSG_SUCCESS;
130
131         MSG_MMS_HOME_RETRIEVE_TYPE_T retrieveType;
132         bool bReportAllowed;
133
134         MmsAttrib attrib;
135
136         MmsInitMsgAttrib(&attrib);
137
138         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
139         pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
140         pMsgInfo->priority = mmsHeader.priority;
141         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
142
143         MSG_DEBUG("pMsgInfo->subject [%s]", pMsgInfo->subject);
144
145         if (strlen(pMsgInfo->subject) < 1)
146                 snprintf(pMsgInfo->subject, MAX_SUBJECT_LEN, "MMS Notification Message.");
147
148         attrib.expiryTime = mmsHeader.expiryTime;
149
150         MmsPluginStorage *pStorage = MmsPluginStorage::instance();
151         err = pStorage->updateMmsAttrib(pMsgInfo->msgId, &attrib, pMsgInfo->msgType.subType);
152
153         if (mmsHeader.pFrom) {
154                 MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
155                 // From
156                 strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pFrom->szAddr, MAX_ADDRESS_VAL_LEN);
157         }
158
159         int roamState = 0;
160
161         roamState = MsgSettingGetInt(VCONFKEY_TELEPHONY_SVC_ROAM);
162         MsgSettingGetBool(MMS_SEND_REPORT_ALLOWED, &bReportAllowed);
163
164         if (checkRejectNotiInd(roamState, bReportAllowed, pMsgInfo->msgData)) {
165                 MSG_DEBUG("MMS Message Rejected......");
166
167                 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
168                 pMsgInfo->bTextSms = true;
169                 memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
170
171                 pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
172
173                 return false;
174         }
175
176         if (roamState == VCONFKEY_TELEPHONY_SVC_ROAM_OFF) {
177                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)MsgSettingGetInt(MMS_RECV_HOME_NETWORK);
178                 MSG_DEBUG("$$$$$$$$$$ MMS_RECV_HOME_NETWORK = %d $$$$$$$$$$$$$", retrieveType);
179         } else {
180                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)MsgSettingGetInt(MMS_RECV_ABROAD_NETWORK);
181                 MSG_DEBUG("$$$$$$$$$$ MMS_RECV_ABROAD_NETWORK = %d $$$$$$$$$$$$$", retrieveType);
182
183                 if (retrieveType == MSG_ABROAD_RESTRICTED) {
184                         MSG_DEBUG("MMS Receiving Setting Restricted was selected.");
185                         // m-notify-resp-ind encoding process
186                         memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
187
188                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pMsgInfo->msgData);
189
190                         pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
191                         pMsgInfo->bTextSms = true;
192                         memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
193
194                         pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
195
196                         return true;
197                 }
198         }
199
200         // should send http 'GET'
201         if (retrieveType == MSG_HOME_AUTO_DOWNLOAD || retrieveType == MSG_ABROAD_AUTO_DOWNLOAD) {
202                 MSG_DEBUG("=========== START AUTO RETRIEVE MODE ============");
203                 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
204
205                 memcpy(pMsgInfo->msgData, mmsHeader.szContentLocation, strlen(mmsHeader.szContentLocation)) ;
206
207                 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
208
209                 pMsgInfo->bTextSms = true;
210
211                 memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
212
213                 pRequest->msgInfo.msgType.subType = MSG_GET_MMS;
214
215                 MSG_DEBUG("MSG SUBTYPE = %d msg data %s bTextsms %d", pRequest->msgInfo.msgType.subType, pRequest->msgInfo.msgData, pRequest->msgInfo.bTextSms);
216         } else {
217         // should send m-notify-resp-ind
218                 MSG_DEBUG("=========== START MANUAL RETRIEVE MODE ===========");
219                 // m-notify-resp-ind encoding process
220                 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
221
222                 if (retrieveType == MSG_HOME_MANUAL || retrieveType == MSG_ABROAD_MANUAL) {
223                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pMsgInfo->msgData);
224                 }
225
226                 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
227                 pMsgInfo->bTextSms = true;
228                 memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
229
230                 pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
231         }
232
233         return true;
234 }
235
236 void MmsPluginInternal::processDeliveryInd(MSG_MESSAGE_INFO_S *pMsgInfo)
237 {
238         MSG_BEGIN();
239
240         MmsMsgMultiStatus status;
241         memset(&status, 0x00, sizeof(MmsMsgMultiStatus));
242
243         status.msgStatus = mmsHeader.msgStatus;
244         status.handledTime = mmsHeader.date;
245         status.bDeliveryReportIsRead = false;
246         status.bDeliveyrReportIsLast= true;
247
248         MmsAddrUtilRemovePlmnString(mmsHeader.pTo->szAddr);
249         MSG_DEBUG("[INFO] [ADDR: %s, MMSID: %s]",mmsHeader.pTo->szAddr, mmsHeader.szMsgID);
250
251         pMsgInfo->msgType.mainType      = MSG_MMS_TYPE;
252         pMsgInfo->msgType.subType       = MSG_DELIVERYIND_MMS;
253         pMsgInfo->bTextSms = true;
254         pMsgInfo->dataSize = 0;
255         memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
256
257         strncpy(pMsgInfo->msgData, getMmsDeliveryStatus(status.msgStatus), MAX_MSG_DATA_LEN);
258         pMsgInfo->dataSize  = strlen(pMsgInfo->msgData);
259         MSG_DEBUG("Delivery Status = %s", pMsgInfo->msgData);
260
261         strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pTo->szAddr, MAX_ADDRESS_VAL_LEN);
262
263         int tmpId = (msg_message_id_t)MmsPluginStorage::instance()->searchMsgId(mmsHeader.pTo->szAddr, mmsHeader.szMsgID);
264         if (tmpId > 0) {
265                 MSG_DEBUG("Found MSG_ID = %d", tmpId);
266
267                 //Insert to Delievery DB
268                 MmsPluginStorage::instance()->insertDeliveryReport(tmpId, mmsHeader.pTo->szAddr, &status);
269
270                 pMsgInfo->msgId = (msg_message_id_t)tmpId;
271
272         } else {
273                 MSG_DEBUG("Can not find MMS message in DB");
274         }
275
276         MSG_END();
277 }
278
279 void MmsPluginInternal::processReadOrgInd(MSG_MESSAGE_INFO_S *pMsgInfo)
280 {
281         MSG_BEGIN();
282
283         if (pMsgInfo == NULL) {
284                 MSG_DEBUG("parameter err");
285                 return;
286         }
287
288         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
289         pMsgInfo->msgType.subType = MSG_READORGIND_MMS;
290         pMsgInfo->bTextSms = true;
291
292         MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
293         MmsAddrUtilRemovePlmnString(mmsHeader.pTo->szAddr);
294
295         memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
296         pMsgInfo->dataSize = 0;
297
298         strncpy(pMsgInfo->msgData, getMmsReadStatus(mmsHeader.readStatus), MAX_MSG_DATA_LEN);
299         pMsgInfo->dataSize  = strlen(pMsgInfo->msgData);
300
301         MSG_DEBUG("read Status = %s", pMsgInfo->msgData);
302         strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pFrom->szAddr, MAX_ADDRESS_VAL_LEN);
303
304         int tmpId = MmsPluginStorage::instance()->searchMsgId(mmsHeader.pFrom->szAddr, mmsHeader.szMsgID);
305         if (tmpId > 0) {
306                 pMsgInfo->msgId = (msg_message_id_t)tmpId;
307
308                 MmsMsgMultiStatus Status;
309                 memset(&Status, 0x00, sizeof(MmsMsgMultiStatus));
310                 Status.readTime = mmsHeader.date;
311                 Status.readStatus = mmsHeader.readStatus;
312
313                 MmsPluginStorage::instance()->insertReadReport(pMsgInfo->msgId, mmsHeader.pFrom->szAddr, &Status);
314
315         } else {
316                 MSG_DEBUG("Can't not find Message!");
317         }
318
319         MSG_END();
320 }
321
322 void MmsPluginInternal::processSendConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEntity *pRequest)
323 {
324         MSG_BEGIN();
325
326         MMS_RECV_DATA_S recvData = {{0}, };
327
328         pMsgInfo->msgId = pRequest->msgId;
329
330         //Set only changed members
331         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
332         pMsgInfo->msgType.subType = MSG_SENDCONF_MMS;
333
334         pMsgInfo->folderId = MSG_OUTBOX_ID;
335
336         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
337
338         if (mmsHeader.responseStatus == MMS_RESPSTATUS_OK) {
339                 pMsgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
340                 pMsgInfo->dataSize = pRequest->postDataLen;
341         } else {
342                 pMsgInfo->networkStatus = MSG_NETWORK_SEND_FAIL;
343
344                 char responseText[MMS_LOCALE_RESP_TEXT_LEN];
345
346                 memset(responseText, 0x00, MMS_LOCALE_RESP_TEXT_LEN);
347                 snprintf(responseText, MMS_LOCALE_RESP_TEXT_LEN, " %s [%d]", mmsHeader.szResponseText, mmsHeader.responseStatus);
348
349                 memset(pMsgInfo->msgText, 0x00, MAX_MSG_TEXT_LEN + 1);
350                 strncpy(pMsgInfo->msgText, responseText, MMS_LOCALE_RESP_TEXT_LEN);
351         }
352
353         MSG_ADDRESS_INFO_S addressinfo = {0,};
354         char *msisdn = NULL;
355         msisdn = MsgSettingGetString(MSG_SIM_MSISDN);
356
357         MmsPluginStorage::instance()->getAddressInfo(pMsgInfo->msgId, &addressinfo);
358
359         MSG_MMS_VLD_INFO("%d, MMS Send End %s->%s %s", pMsgInfo->msgId
360                                                                                                         , (msisdn == NULL)?"ME":msisdn
361                                                                                                         , addressinfo.addressVal
362                                                                                                         , (pMsgInfo->networkStatus == MSG_NETWORK_SEND_SUCCESS)?"Success":"Fail");
363
364         // set message-id from mmsc
365         strncpy(recvData.szMsgID, mmsHeader.szMsgID, MMS_MSG_ID_LEN);
366         strncpy(recvData.szTrID, mmsHeader.szTrID, MMS_TR_ID_LEN);
367
368         memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
369         memcpy(pMsgInfo->msgData, &recvData, sizeof(MMS_RECV_DATA_S));
370
371         time_t curTime;
372         curTime = time(NULL);
373
374         pMsgInfo->displayTime = curTime;
375
376
377         MmsInitHeader();
378 #if 0 // Not Need Release
379         MmsMsg *pMsg = NULL;
380         MmsPluginStorage::instance()->getMmsMessage(&pMsg);
381 #ifdef __SUPPORT_DRM__
382         MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
383 #endif
384         MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
385 #endif
386
387         MSG_END();
388 }
389
390
391 void MmsPluginInternal::processRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEntity *pRequest, char *pRetrievedFilePath)
392 {
393         MSG_BEGIN();
394
395         int partCnt = 0;
396         int attachCount = 0;
397         MsgType partHeader;
398         bool bMultipartRelated = false;
399
400         msg_error_t err = MSG_SUCCESS;
401         MMS_RECV_DATA_S recvData = {{0}, };
402
403         MmsAttrib attrib;
404
405         MmsInitMsgAttrib(&attrib);
406
407         attrib.priority = mmsHeader.priority;
408         attrib.bAskDeliveryReport = getMmsReport(mmsHeader.deliveryReport);
409         attrib.bAskReadReply = getMmsReport(mmsHeader.readReply);
410
411         //Set only changed members
412         pMsgInfo->msgId = pRequest->msgId;
413         MSG_DEBUG("@@@@@ msgId = %d @@@@@", pMsgInfo->msgId);
414         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
415
416         if (pRequest->eMmsPduType == eMMS_RETRIEVE_AUTO_CONF)
417                 pMsgInfo->msgType.subType = MSG_RETRIEVE_AUTOCONF_MMS;
418         else
419                 pMsgInfo->msgType.subType = MSG_RETRIEVE_MANUALCONF_MMS;
420
421         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
422
423         strncpy(pRequest->transactionId, mmsHeader.szTrID, MMS_TR_ID_LEN);
424
425         time_t curTime;
426         curTime = time(NULL);
427
428         pMsgInfo->displayTime = curTime;
429
430         if (mmsHeader.retrieveStatus == MMS_RETRSTATUS_OK) {
431                 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
432                 pMsgInfo->folderId = MSG_INBOX_ID;
433         } else {
434                 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
435                 pMsgInfo->folderId = MSG_INBOX_ID;
436                 // If failed MMS Retrieve, then saved as MMS Noti Ind Message.
437                 // It will changed in MsgHandleMmsConfIncomingMsg
438                 //pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
439         }
440
441         char *msisdn = NULL;
442         msisdn = MsgSettingGetString(MSG_SIM_MSISDN);
443
444         if (mmsHeader.pFrom)
445                 MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
446
447         MSG_MMS_VLD_INFO("%d, MMS Receive %s End %s->%s %s", pMsgInfo->msgId
448                                                                                                                 , (pRequest->eMmsPduType == eMMS_RETRIEVE_AUTO_CONF)?"Auto":"Manual"
449                                                                                                                 , (mmsHeader.pFrom)?mmsHeader.pFrom->szAddr:"YOU"
450                                                                                                                 , (msisdn == NULL)?"ME":msisdn
451                                                                                                                 , (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS)?"Success":"Fail");
452         pMsgInfo->dataSize = pRequest->getDataLen;
453
454         // set message-id & MMS TPDU file path
455         strcpy(recvData.szMsgID, mmsHeader.szMsgID);
456         if (pRetrievedFilePath)
457                 strncpy(recvData.retrievedFilePath, pRetrievedFilePath, sizeof(recvData.retrievedFilePath));
458
459 #ifdef FEATURE_JAVA_MMS
460         if (mmsHeader.msgType.param.szApplicationID || mmsHeader.msgType.param.szReplyToApplicationID) {
461                 recvData.msgAppId.valid = true;
462                 if (mmsHeader.msgType.param.szApplicationID)
463                         strncpy(recvData.msgAppId.appId, mmsHeader.msgType.param.szApplicationID, sizeof(recvData.msgAppId.appId));
464                 if (mmsHeader.msgType.param.szReplyToApplicationID)
465                         strncpy(recvData.msgAppId.replyToAppId, mmsHeader.msgType.param.szReplyToApplicationID, sizeof(recvData.msgAppId.replyToAppId));
466
467                 char fullPath[MAX_FULL_PATH_SIZE+1] = {0, };
468
469                 char *filename = NULL;
470                 filename = strrchr(pRetrievedFilePath, '/');
471
472                 snprintf(fullPath, MAX_FULL_PATH_SIZE+1, "%s%s", MSG_IPC_DATA_PATH, filename + 1);
473
474                 int ret  = rename(pRetrievedFilePath, fullPath);
475                 if (ret != 0) {
476                         MSG_DEBUG("File rename Error: %s", strerror(errno));
477                 }
478
479                 if (chmod(fullPath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) != 0) {
480                         MSG_DEBUG("File Write Error: %s", strerror(errno));
481                 }
482
483                 if (chown(fullPath, 0, 6502 ) != 0) {
484                         MSG_DEBUG("File Write Error: %s", strerror(errno));
485                 }
486         }
487 #endif
488         memcpy(pMsgInfo->msgData, &recvData, sizeof(MMS_RECV_DATA_S));
489
490         MSG_DEBUG("@@@@@ MsgData = %s @@@@@", pMsgInfo->msgData);
491         MSG_DEBUG("@@@@@ retrievedFilePath = %s @@@@@", recvData.retrievedFilePath);
492         MSG_DEBUG("@@@@@ szMsgID = %s @@@@@", recvData.szMsgID);
493         //update delivery report, read reply
494
495         MmsPluginStorage *pStorage = MmsPluginStorage::instance();
496
497         MMS_MESSAGE_DATA_S msgData;
498         memset(&msgData, 0, sizeof(MMS_MESSAGE_DATA_S));
499
500         // Conversation is supported only Multipart Related message, Presentation info should be provided
501         if (mmsHeader.msgType.type == MIME_MULTIPART_RELATED || mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
502                 char *pSmilDoc = NULL;
503                 MmsMsg *pMsg = NULL;
504                 char szFileName[MSG_FILENAME_LEN_MAX] = {0, };
505
506                 msgData.regionCnt = 0;
507                 msgData.pageCnt = 0;
508                 msgData.attachCnt = 0;
509                 msgData.transitionCnt = 0;
510                 msgData.metaCnt = 0;
511                 memset(msgData.szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
512
513                 pSmilDoc = MmsSmilGetPresentationData(pMsgInfo->msgId);
514                 MmsSmilParseSmilDoc(&msgData, pSmilDoc);
515                 MmsRemovePims(&msgData);
516
517                 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
518                 strcpy(szFileName, pMsg->szFileName);
519
520                 err = pStorage->getMsgText(&msgData, pMsgInfo->msgText);
521                 bMultipartRelated = true;
522         } else {
523                 MSG_DEBUG("Multipart mixed message doesn't support mms conversation");
524         }
525
526         err = pStorage->updateMmsAttrib(pMsgInfo->msgId, &attrib, pMsgInfo->msgType.subType);
527
528         partCnt = MmsGetMediaPartCount(pMsgInfo->msgId);
529         MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt );
530
531         if (partCnt < 0) {
532                 MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt );
533         } else {
534                 for (int i = 0; i < partCnt; ++i) {
535                         if (!MmsGetMediaPartHeader(i, &partHeader)) {
536                                 MSG_DEBUG("MmsUiGetMediaAttachInfo: MmsGetMediaPartHeader failed\n" );
537                                 break;
538                         }
539
540                         if (partHeader.contentSize > 0) {
541                                 char szBuf[MSG_FILEPATH_LEN_MAX + 1];
542
543                                 strcpy((char *)szBuf, partHeader.param.szFileName);
544                                 sprintf(partHeader.param.szFileName, MSG_DATA_PATH"%s", szBuf);
545                                 if (!bMultipartRelated || MmsCheckAdditionalMedia(&msgData, &partHeader)) {
546                                         MMS_ATTACH_S *attachment = NULL;
547                                         int tempType;
548
549                                         attachment = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
550
551                                         MsgGetTypeByFileName(&tempType, partHeader.param.szFileName);
552                                         attachment->mediatype = (MimeType)tempType;
553
554                                         strcpy(attachment->szFilePath, partHeader.param.szFileName);
555
556                                         strncpy(attachment->szFileName, partHeader.param.szName, MSG_FILENAME_LEN_MAX - 1);
557
558                                         attachment->fileSize = partHeader.contentSize;
559
560                                         _MsgMmsAddAttachment(&msgData, attachment);
561                                         attachCount++;
562
563                                 }
564
565                         }
566                 }
567         }
568
569         MmsMakePreviewInfo(pMsgInfo->msgId, &msgData);
570         MSG_DEBUG("attachCount [%d]", attachCount);
571         err = pStorage->updateMmsAttachCount(pMsgInfo->msgId, attachCount);
572
573         if (bMultipartRelated) {
574                 MsgMmsReleaseMmsLists(&msgData);
575         }
576
577         MmsMsg *pMsg = NULL;
578         pStorage->getMmsMessage(&pMsg);
579         MmsInitHeader();
580 #ifdef __SUPPORT_DRM__
581         MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
582 #endif
583         MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
584
585         MSG_END();
586 }
587
588 void MmsPluginInternal::processForwardConf(MSG_MESSAGE_INFO_S *msgInfo, mmsTranQEntity *pRequest)
589 {
590
591 }
592
593 /* This function Send NotifyRespInd Msg
594  *
595  * @param       pTrID [in] Specifies Transaction ID
596  * @param       iStatus [in] Specifies Msg Status
597  * @param       iReportAllowed [in] Specifies whether to send deliveryReport to sender or not
598  * @return      This function returns true on success, or false on failure.
599  */
600 bool MmsPluginInternal::encodeNotifyRespInd(char *szTrID, msg_delivery_report_status_t iStatus, bool bReportAllowed, char *pSendFilePath)
601 {
602         MSG_BEGIN();
603
604         FILE *pFile = NULL;
605         char pTempFileName[MSG_FILENAME_LEN_MAX+1] = {0};
606         char pTempFilePath[MAX_FULL_PATH_SIZE] = {0};
607
608         if (MsgCreateFileName(pTempFileName) == false)
609                 return false;
610
611         snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"%s.noti.ind", pTempFileName);
612
613         pFile = MsgOpenMMSFile(pTempFilePath);
614
615         if (!pFile) {
616                 MSG_DEBUG("[ERROR] MsgOpenMMSFile fail");
617                 return false;
618         }
619
620         if (MmsEncodeNotiRespInd(pFile, szTrID, iStatus, bReportAllowed) == false) {
621                 MSG_DEBUG("MmsEncodeNotifyRespInd: MmsEncodeNotiRespInd fail");
622                 MsgCloseFile(pFile);
623                 return false;
624         }
625
626         MsgCloseFile(pFile);
627
628         if (pSendFilePath) {
629                 snprintf(pSendFilePath, MAX_MSG_DATA_LEN+1, "%s.mms", pTempFilePath);
630         } else {
631                 MSG_DEBUG("[ERROR] pSendFilePath is NULL");
632                 return false;
633         }
634
635         MSG_END();
636
637         return true;
638 }
639
640 /* This function Send AcknowledgeInd Msg
641  *
642  * @param       pTrID [in] Specifies Transaction ID
643  * @param       iReportAllowed [in] Specifies whether to send deliveryReport to sender or not
644  * @return      This function returns true on success, or false on failure.
645  */
646 bool MmsPluginInternal::encodeAckInd(char *szTrID, bool bReportAllowed, char *pSendFilePath)
647 {
648         MSG_BEGIN();
649         FILE *pFile = NULL;
650         char pTempFileName[MSG_FILENAME_LEN_MAX+1] = {0};
651         char pTempFilePath[MAX_FULL_PATH_SIZE] = {0};
652
653         if (MsgCreateFileName(pTempFileName) == false)
654                 return false;
655
656         snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"%s.ack.ind", pTempFileName);
657
658         pFile = MsgOpenMMSFile(pTempFilePath);
659         if (!pFile) {
660                 MSG_DEBUG("[ERROR] MsgOpenMMSFile fail \n" );
661                 return false;
662         }
663
664         if (MmsEncodeAckInd(pFile, szTrID, bReportAllowed) == false) {
665                 MSG_DEBUG("MmsEncodeAckInd: MmsEncodeAckInd fail \n" );
666                 MsgCloseFile(pFile);
667                 return false;
668         }
669
670         MsgCloseFile(pFile);
671
672         if (pSendFilePath) {
673                 snprintf(pSendFilePath, MAX_MSG_DATA_LEN+1, "%s.mms", pTempFilePath);
674         } else {
675                 MSG_DEBUG("[ERROR] pSendFilePath is NULL");
676                 return false;
677         }
678
679         MSG_END();
680
681         return true;
682 }
683
684 bool MmsPluginInternal::checkRejectNotiInd(int roamState, bool bReportAllowed, char *pSendFilePath)
685 {
686         MSG_BEGIN();
687         MSG_MMS_HOME_RETRIEVE_TYPE_T retrieveType;
688         bool bRejectAnonymous;
689         bool bRejectAdvertisement;
690
691         MsgSettingGetBool(MMS_RECV_REJECT_UNKNOWN, &bRejectAnonymous);
692         MsgSettingGetBool(MMS_RECV_REJECT_ADVERTISE, &bRejectAdvertisement);
693
694         // Anonymous Reject
695         if (bRejectAnonymous &&
696                 (mmsHeader.pFrom == NULL || mmsHeader.pFrom->szAddr[0] == '\0')) {
697                 MSG_DEBUG("Anonymous Reject... ");
698                 encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
699
700                 return true;
701         }
702
703         // Advertisement Reject
704         if (bRejectAdvertisement && mmsHeader.msgClass == MMS_MSGCLASS_ADVERTISEMENT) {
705                 MSG_DEBUG("Advertisement Reject... ");
706                 encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
707
708                 return true;
709         }
710
711         // Message Reject - Roaming Case
712         if (roamState == VCONFKEY_TELEPHONY_SVC_ROAM_ON) {
713                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)MsgSettingGetInt(MMS_RECV_ABROAD_NETWORK);
714                 if (retrieveType == MSG_ABROAD_REJECT) {
715                         MSG_DEBUG("Abroad_Network : Notification Reject... ");
716                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
717
718                         return true;
719                 }
720         } else {
721                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)MsgSettingGetInt(MMS_RECV_HOME_NETWORK);
722                 if (retrieveType == MSG_HOME_REJECT) {
723                         MSG_DEBUG("Home_Network : Notification Reject... ");
724                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
725
726                         return true;
727                 }
728         }
729
730         // Not Rejected
731         MSG_END();
732         return false;
733
734 }
735
736 bool MmsPluginInternal::getMmsReport(MmsReport mmsReport)
737 {
738         bool result = false;
739
740         if (mmsReport == MMS_REPORT_YES)
741                 result = true;
742         else if (mmsReport == MMS_REPORT_NO)
743                 result = false;
744
745         return result;
746 }
747
748 const char *MmsPluginInternal::getMmsDeliveryStatus(msg_delivery_report_status_t deliveryStatus)
749 {
750         MSG_DEBUG("msgStatus= %d", deliveryStatus);
751
752         switch (deliveryStatus) {
753         case MSG_DELIVERY_REPORT_EXPIRED:
754                 return "expired.";
755         case MSG_DELIVERY_REPORT_REJECTED:
756                 return "rejected.";
757         case MSG_DELIVERY_REPORT_UNREACHABLE:
758                 return "unreachable.";
759         case MSG_DELIVERY_REPORT_UNRECOGNISED:
760                 return "unrecognised.";
761         case MSG_DELIVERY_REPORT_SUCCESS:
762                 return "delivered.";
763         default:
764                 return "delivery failed.";
765         }
766 }
767
768 const char *MmsPluginInternal::getMmsReadStatus(msg_read_report_status_t readStatus)
769 {
770         switch (readStatus) {
771         case MSG_READ_REPORT_IS_READ:
772                 return "message is read.";
773         case MSG_READ_REPORT_IS_DELETED:
774                 return "message is deleted.";
775         default:
776                 return "read status is none.";
777         }
778 }
779