update tizen source
[framework/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginInternal.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #include <stdlib.h>
32 #include <errno.h>
33 #include <sys/stat.h>
34
35 #include "MsgDebug.h"
36 #include "MsgUtilFile.h"
37 #include "MsgException.h"
38 #include "MsgMmsMessage.h"
39 #include "MsgTransportTypes.h"
40 #include "MsgGconfWrapper.h"
41 #include "MsgSoundPlayer.h"
42 #include "MsgStorageHandler.h"
43 #include "MmsPluginTypes.h"
44 #include "MmsPluginCodec.h"
45 #include "MmsPluginSetup.h"
46 #include "MmsPluginInternal.h"
47 #include "MmsPluginStorage.h"
48 #include "MmsPluginHttp.h"
49 #include "MmsPluginCodec.h"
50
51 #include "MsgNotificationWrapper.h"
52 #include "MmsPluginSmil.h"
53
54 MmsSetup gMmsSetup;
55
56 /*==================================================================================================
57                                      IMPLEMENTATION OF MmsPluginInternal - Member Functions
58 ==================================================================================================*/
59 MmsPluginInternal *MmsPluginInternal::pInstance = NULL;
60
61
62 MmsPluginInternal::MmsPluginInternal()
63 {
64
65 }
66
67 MmsPluginInternal::~MmsPluginInternal()
68 {
69
70 }
71
72 MmsPluginInternal *MmsPluginInternal::instance()
73 {
74         if (!pInstance)
75                 pInstance = new MmsPluginInternal();
76
77         return pInstance;
78 }
79
80 void MmsPluginInternal::processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest, bool *bReject)
81 {
82         MSG_DEBUG("processReceivedInd \r\n");
83
84         FILE *pFile = NULL;
85         char fileName[MSG_FILENAME_LEN_MAX] = {0,};
86
87         if (pMsgInfo->bTextSms == true) {
88                 char fullPath[MAX_FULL_PATH_SIZE+1] = {0,};
89
90                 if(MsgCreateFileName(fileName) == false)
91                         THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
92
93                 MSG_DEBUG(" File name = %s", fileName);
94
95                 if(MsgWriteIpcFile(fileName, pMsgInfo->msgText, pMsgInfo->dataSize) == false)
96                         THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
97
98                 snprintf(fullPath, MAX_FULL_PATH_SIZE+1, MSG_IPC_DATA_PATH"%s", fileName);
99
100                 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
101                 memcpy(pMsgInfo->msgData, fullPath, strlen(fullPath));
102                 pMsgInfo->bTextSms = false;
103         }
104
105         MSG_DEBUG("MMS File Path = %s", pMsgInfo->msgData);
106
107         _MmsInitHeader();
108         _MmsRegisterDecodeBuffer(gszMmsLoadBuf1,  gszMmsLoadBuf2, MSG_MMS_DECODE_BUFFER_MAX);
109
110         if ((pFile = MsgOpenFile(pMsgInfo->msgData, "rb+")) == NULL) {
111                 MSG_DEBUG("File Open Error: %s", pMsgInfo->msgData);
112         } else {
113                 //Decode Header
114                 if (!MmsBinaryDecodeMsgHeader(pFile, pMsgInfo->dataSize))
115                         MSG_DEBUG("Decoding Header Failed \r\n");
116
117                 MsgDeleteFile(pMsgInfo->msgData + strlen(MSG_IPC_DATA_PATH));
118
119                 switch (mmsHeader.type) {
120                 case MMS_MSGTYPE_NOTIFICATION_IND:
121                         MSG_DEBUG("MmsProcessNewMsgInd: process noti.ind\n");
122                         // For Set Value pMsgInfo
123                         if (processNotiInd(pMsgInfo, pRequest) == false)
124                                 *bReject = true;
125                         else
126                                 *bReject = false;
127                         break;
128
129                 case MMS_MSGTYPE_DELIVERY_IND:
130                         MSG_DEBUG("MmsProcessNewMsgInd: process delivery.ind\n");
131                         // For Set Value pMsgInfo
132                         processDeliveryInd(pMsgInfo);
133                         break;
134
135                 case MMS_MSGTYPE_READORG_IND:
136                         MSG_DEBUG("MmsProcessNewMsgInd: process readorig.ind\n");
137                         processReadOrgInd(pMsgInfo);
138                         break;
139                 default:
140                         break;
141                 }
142
143                 MsgCloseFile(pFile);
144         }
145         //Check Msg Type & Process(Save ...)
146 }
147
148 bool MmsPluginInternal::processNotiInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest)
149 {
150         MSG_DEBUG("MmsProcessNotiInd");
151         MSG_ERROR_T     err = MSG_SUCCESS;
152
153         MSG_MMS_HOME_RETRIEVE_TYPE_T retrieveType;
154         bool bReportAllowed;
155
156         MmsAttrib attrib;
157
158         MmsInitMsgAttrib(&attrib);
159
160         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
161         pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
162         pMsgInfo->priority = mmsHeader.priority;
163         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
164
165         MSG_DEBUG("pMsgInfo->subject [%s]", pMsgInfo->subject);
166
167         if (strlen(pMsgInfo->subject) < 1)
168                 snprintf(pMsgInfo->subject, MAX_SUBJECT_LEN, "MMS Notification Message.");
169
170         attrib.expiryTime = mmsHeader.expiryTime;
171
172         MmsPluginStorage *pStorage = MmsPluginStorage::instance();
173         err = pStorage->updateMmsAttrib(pMsgInfo->msgId, &attrib, pMsgInfo->msgType.subType);
174
175         if (mmsHeader.pFrom) {
176                 MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
177                 // From
178                 strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pFrom->szAddr, MAX_ADDRESS_VAL_LEN);
179         }
180
181         int roamState = 0;
182
183         roamState = MsgSettingGetInt(VCONFKEY_TELEPHONY_SVC_ROAM);
184         MsgSettingGetBool(MMS_SEND_REPORT_ALLOWED, &bReportAllowed);
185
186         if (checkRejectNotiInd(roamState, bReportAllowed, pMsgInfo->msgData)) {
187                 MSG_DEBUG("MMS Message Rejected......");
188
189                 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
190                 pMsgInfo->bTextSms = true;
191                 memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
192
193                 pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
194
195                 return false;
196         }
197
198         if (roamState == VCONFKEY_TELEPHONY_SVC_ROAM_OFF) {
199                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)MsgSettingGetInt(MMS_RECV_HOME_NETWORK);
200                 MSG_DEBUG("$$$$$$$$$$ MMS_RECV_HOME_NETWORK = %d $$$$$$$$$$$$$", retrieveType);
201         } else {
202                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)MsgSettingGetInt(MMS_RECV_ABROAD_NETWORK);
203                 MSG_DEBUG("$$$$$$$$$$ MMS_RECV_ABROAD_NETWORK = %d $$$$$$$$$$$$$", retrieveType);
204
205                 if (retrieveType == MSG_ABROAD_RESTRICTED) {
206                         MSG_DEBUG("MMS Receiving Setting Restricted was selected.");
207                         // m-notify-resp-ind encoding process
208                         memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
209
210                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pMsgInfo->msgData);
211
212                         pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
213                         pMsgInfo->bTextSms = true;
214                         memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
215
216                         pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
217
218                         return true;
219                 }
220         }
221
222         // should send http 'GET'
223         if (retrieveType == MSG_HOME_AUTO_DOWNLOAD || retrieveType == MSG_ABROAD_AUTO_DOWNLOAD) {
224                 MSG_DEBUG("=========== START AUTO RETRIEVE MODE ============");
225                 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
226
227                 memcpy(pMsgInfo->msgData, mmsHeader.szContentLocation, strlen(mmsHeader.szContentLocation)) ;
228
229                 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
230
231                 pMsgInfo->bTextSms = true;
232
233                 memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
234
235                 pRequest->msgInfo.msgType.subType = MSG_GET_MMS;
236
237                 MSG_DEBUG("MSG SUBTYPE = %d msg data %s bTextsms %d", pRequest->msgInfo.msgType.subType, pRequest->msgInfo.msgData, pRequest->msgInfo.bTextSms);
238         } else {
239         // should send m-notify-resp-ind
240                 MSG_DEBUG("=========== START MANUAL RETRIEVE MODE ===========");
241                 // m-notify-resp-ind encoding process
242                 memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
243
244                 if (retrieveType == MSG_HOME_MANUAL || retrieveType == MSG_ABROAD_MANUAL) {
245                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pMsgInfo->msgData);
246                 }
247
248                 pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
249                 pMsgInfo->bTextSms = true;
250                 memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
251
252                 pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
253         }
254
255         return true;
256 }
257
258
259 void MmsPluginInternal::processDeliveryInd(MSG_MESSAGE_INFO_S *pMsgInfo)
260 {
261         MSG_BEGIN();
262
263         MmsMsg *pMsg = NULL;
264         bool bFound = false;
265         MmsMsgMultiStatus *pStatus = NULL;
266         MmsMsgMultiStatus *pLastStatus = NULL;
267
268         pMsg = (MmsMsg *)malloc(sizeof(MmsMsg));
269
270         if (pMsg == NULL) {
271                 MSG_DEBUG("fail to allocation memory.");
272                 return;
273         }
274
275         MmsInitMsgAttrib(&pMsg->mmsAttrib);
276
277         pMsgInfo->msgType.mainType      = MSG_MMS_TYPE;
278         pMsgInfo->msgType.subType       = MSG_DELIVERYIND_MMS;
279         pMsgInfo->bTextSms = true;
280
281         MSG_DEBUG("#### mmsHeader.szMsgID = %s : when received delivery ind####", mmsHeader.szMsgID);
282
283         int tmpId = (MSG_MESSAGE_ID_T)MmsSearchMsgId(mmsHeader.pTo->szAddr, mmsHeader.szMsgID);
284
285
286         MSG_DEBUG("tmpId [%d]", tmpId);
287         MSG_DEBUG("mmsHeader.pTo->szAddr [%s]", mmsHeader.pTo->szAddr);
288
289         if (tmpId > 0) {
290                 pMsgInfo->msgId = (MSG_MESSAGE_ID_T)tmpId;
291
292                 pMsg->mmsAttrib.pMultiStatus = MmsGetMultiStatus(pMsgInfo->msgId);
293
294                 pStatus = pMsg->mmsAttrib.pMultiStatus;
295
296                 MSG_DEBUG("### pStatus->szTo = %s ###", pStatus->szTo);
297
298                 while (pStatus && !bFound) {
299                         MSG_DEBUG("### MmsAddrUtilCompareAddr ###");
300                         MSG_DEBUG("### mmsHeader.pTo->szAddr = %s ###", mmsHeader.pTo->szAddr);
301                         if (MmsAddrUtilCompareAddr( pStatus->szTo, mmsHeader.pTo->szAddr)) {
302                                 bFound = true;
303                                 break;
304                         }
305
306                         pStatus = pStatus->pNext;
307                 }
308
309                 if (bFound == false) {
310                         MSG_DEBUG("### bFound == false ###");
311                         /* Queue the delivery report  --------------------------- */
312
313                         pStatus = (MmsMsgMultiStatus *)malloc(sizeof(MmsMsgMultiStatus));
314                         memset(pStatus, 0, sizeof(MmsMsgMultiStatus));
315
316                         pStatus->readStatus = MMS_READSTATUS_NONE;
317                         memset(pStatus->szTo, 0, MSG_ADDR_LEN + 1);
318                         strncpy(pStatus->szTo, mmsHeader.pTo->szAddr, MSG_ADDR_LEN);
319
320                         if (pMsg->mmsAttrib.pMultiStatus == NULL) {
321                                 /* first delivery report */
322                                 pMsg->mmsAttrib.pMultiStatus = pStatus;
323                         } else {
324                                 pLastStatus = pMsg->mmsAttrib.pMultiStatus;
325
326                                 while (pLastStatus->pNext) {
327                                         pLastStatus = pLastStatus->pNext;
328                                 }
329
330                                 pLastStatus->pNext = pStatus;
331                                 pLastStatus = pStatus;
332                         }
333                 }
334
335                 pStatus->handledTime = mmsHeader.date;
336                 pStatus->msgStatus = mmsHeader.msgStatus;
337
338                 memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
339                 pMsgInfo->dataSize = 0;
340                 strncpy(pMsgInfo->msgData, getMmsDeliveryStatus(pStatus->msgStatus), MAX_MSG_DATA_LEN);
341                 pMsgInfo->dataSize  = strlen(pMsgInfo->msgData);
342                 pMsgInfo->bTextSms = true;
343                 MSG_DEBUG("Delivery Status = %s", pMsgInfo->msgData);
344
345                 strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pTo->szAddr, MAX_ADDRESS_VAL_LEN);
346
347                 pStatus->bDeliveryReportIsRead = false;
348
349                 _MmsDataUpdateLastStatus(pMsg);
350
351                 pStatus->bDeliveyrReportIsLast= true;
352
353                 MmsUpdateDeliveryReport(pMsgInfo->msgId, pStatus);
354
355                 MmsPluginStorage::instance()->addMmsNoti(pMsgInfo);
356         } else {
357                 MSG_DEBUG("Can't not find Message!");
358                 memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
359                 pMsgInfo->dataSize = 0;
360                 strncpy(pMsgInfo->msgData, getMmsDeliveryStatus(mmsHeader.msgStatus), MAX_MSG_DATA_LEN);
361
362                 MSG_DEBUG("Delivery Status = %s", pMsgInfo->msgData);
363
364                 pMsgInfo->dataSize  = strlen(pMsgInfo->msgData);
365
366                 MmsAddrUtilRemovePlmnString(mmsHeader.pTo->szAddr);
367
368                 strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pTo->szAddr, MAX_ADDRESS_VAL_LEN);
369         }
370
371         MsgFreeAttrib(&pMsg->mmsAttrib);
372
373         free(pMsg);
374
375         MSG_END();
376 }
377
378 void MmsPluginInternal::processReadOrgInd(MSG_MESSAGE_INFO_S *pMsgInfo)
379 {
380         MSG_BEGIN();
381
382         MmsMsg *pMsg = NULL;
383         bool bFound = false;
384         MmsMsgMultiStatus *pStatus = NULL;
385         MmsMsgMultiStatus *pLastStatus = NULL;
386
387         pMsg = (MmsMsg *)malloc(sizeof(MmsMsg));
388
389         if (pMsg == NULL) {
390                 MSG_DEBUG("fail to allocation memory.");
391                 return;
392         }
393
394         MmsInitMsgAttrib(&pMsg->mmsAttrib);
395
396         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
397         pMsgInfo->msgType.subType = MSG_READORGIND_MMS;
398         pMsgInfo->bTextSms = true;
399
400         MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
401         MmsAddrUtilRemovePlmnString(mmsHeader.pTo->szAddr);
402
403         if (mmsHeader.readStatus != MSG_READ_REPORT_IS_DELETED || (strcmp(mmsHeader.pFrom->szAddr, mmsHeader.pTo->szAddr))) {
404                 MSG_DEBUG("#### mmsHeader.szMsgID = %s : when received read orig ind####", mmsHeader.szMsgID);
405
406                 int tmpId = MmsSearchMsgId(mmsHeader.pFrom->szAddr, mmsHeader.szMsgID);
407
408                 if (tmpId > 0) {
409                         pMsgInfo->msgId = (MSG_MESSAGE_ID_T)tmpId;
410
411                         pMsg->mmsAttrib.pMultiStatus = MmsGetMultiStatus(pMsgInfo->msgId);
412
413                         pStatus = pMsg->mmsAttrib.pMultiStatus;
414
415                         MSG_DEBUG("### pStatus->szTo = %s ###", pStatus->szTo);
416
417                         while (pStatus && !bFound) {
418                                 MSG_DEBUG("### MmsAddrUtilCompareAddr ###");
419                                 MSG_DEBUG("### mmsHeader.pFrom->szAddr = %s ###", mmsHeader.pFrom->szAddr);
420                                 if (MmsAddrUtilCompareAddr(pStatus->szTo, mmsHeader.pFrom->szAddr)) {
421                                         bFound = true;
422                                         break;
423                                 }
424
425                                 pStatus = pStatus->pNext;
426                         }
427
428                         if (bFound == false) {
429                                 MSG_DEBUG("### bFound == false ###");
430                                 /* Queue the delivery report  --------------------------- */
431
432                                 pStatus = (MmsMsgMultiStatus *)malloc(sizeof(MmsMsgMultiStatus));
433                                 memset(pStatus, 0, sizeof(MmsMsgMultiStatus));
434
435                                 pStatus->msgStatus = MMS_MSGSTATUS_NONE;
436
437                                 memset(pStatus->szTo, 0, MSG_ADDR_LEN + 1);
438                                 strncpy(pStatus->szTo, mmsHeader.pFrom->szAddr, MSG_ADDR_LEN);
439
440                                 if (pMsg->mmsAttrib.pMultiStatus == NULL) {
441                                         /* first readOrg report */
442                                         pMsg->mmsAttrib.pMultiStatus = pStatus;
443                                 } else {
444                                         pLastStatus = pMsg->mmsAttrib.pMultiStatus;
445
446                                         while (pLastStatus->pNext) {
447                                                 pLastStatus = pLastStatus->pNext;
448                                         }
449
450                                         pLastStatus->pNext = pStatus;
451                                         pLastStatus = pStatus;
452                                 }
453                         }
454
455                         pStatus->readTime = mmsHeader.date;
456                         pStatus->readStatus = mmsHeader.readStatus;
457
458                         memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
459                         pMsgInfo->dataSize = 0;
460                         strncpy(pMsgInfo->msgData, getMmsReadStatus(pStatus->readStatus), MAX_MSG_DATA_LEN);
461                         pMsgInfo->dataSize  = strlen(pMsgInfo->msgData);
462                         pMsgInfo->bTextSms = true;
463                         MSG_DEBUG("read Status = %s", pMsgInfo->msgData);
464
465                         strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pTo->szAddr, MAX_ADDRESS_VAL_LEN);
466
467                         pStatus->bReadReplyIsRead = false;
468
469                         _MmsDataUpdateLastStatus(pMsg);
470
471                         pStatus->bReadReplyIsLast= true;
472
473                         MmsUpdateReadReport(pMsgInfo->msgId, pStatus);
474
475                         MmsPluginStorage::instance()->addMmsNoti(pMsgInfo);
476                 } else {
477                         MSG_DEBUG("Can't not find Message!");
478                         memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
479                         pMsgInfo->dataSize = 0;
480                         strncpy(pMsgInfo->msgData, getMmsReadStatus(mmsHeader.readStatus), MAX_MSG_DATA_LEN);
481                         pMsgInfo->dataSize  = strlen(pMsgInfo->msgData);
482                         MSG_DEBUG("read Status = %s", pMsgInfo->msgData);
483
484                         MmsAddrUtilRemovePlmnString(mmsHeader.pTo->szAddr);
485
486                         strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pTo->szAddr, MAX_ADDRESS_VAL_LEN);
487                 }
488         }
489
490         MsgFreeAttrib(&pMsg->mmsAttrib);
491
492         free(pMsg);
493
494         MSG_END();
495 }
496
497 void MmsPluginInternal::processSendConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEntity *pRequest)
498 {
499         MSG_BEGIN();
500
501         MSG_ERROR_T err = MSG_SUCCESS;
502
503         MMS_RECV_DATA_S recvData = {{0}, };
504
505         pMsgInfo->msgId = pRequest->msgId;
506
507         //Set only changed members
508         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
509         pMsgInfo->msgType.subType = MSG_SENDCONF_MMS;
510
511         pMsgInfo->folderId = MSG_OUTBOX_ID;
512
513         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
514
515         if (mmsHeader.responseStatus == MMS_RESPSTATUS_OK) {
516                 pMsgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
517         } else {
518                 pMsgInfo->networkStatus = MSG_NETWORK_SEND_FAIL;
519
520                 char responseText[MMS_LOCALE_RESP_TEXT_LEN];
521
522                 memset(responseText, 0x00, MMS_LOCALE_RESP_TEXT_LEN);
523                 snprintf(responseText, MMS_LOCALE_RESP_TEXT_LEN, " %s [%d]", mmsHeader.szResponseText, mmsHeader.responseStatus);
524
525                 memset(pMsgInfo->msgText, 0x00, MAX_MSG_TEXT_LEN + 1);
526                 strncpy(pMsgInfo->msgText, responseText, MMS_LOCALE_RESP_TEXT_LEN);
527         }
528
529         // set message-id from mmsc
530         strncpy(recvData.szMsgID, mmsHeader.szMsgID, MMS_MSG_ID_LEN);
531         strncpy(recvData.szTrID, mmsHeader.szTrID, MMS_TR_ID_LEN);
532
533         memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
534         memcpy(pMsgInfo->msgData, &recvData, sizeof(MMS_RECV_DATA_S));
535
536         time_t curTime;
537         curTime = time(NULL);
538
539         pMsgInfo->displayTime = curTime;
540
541         MmsMsg *pMsg = NULL;
542         MmsPluginStorage::instance()->getMmsMessage(&pMsg);
543         _MmsInitHeader();
544 #ifdef __SUPPORT_DRM__
545         _MsgFreeDRMInfo(&pMsg->msgType.drmInfo);
546 #endif
547         _MsgFreeBody(&pMsg->msgBody, pMsg->msgType.type);
548
549
550         MSG_END();
551 }
552
553
554 void MmsPluginInternal::processRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEntity *pRequest, char *pRetrievedFilePath)
555 {
556         MSG_BEGIN();
557
558         int partCnt = 0;
559         int attachCount = 0;
560         MsgType partHeader;
561         bool bMultipartRelated = false;
562
563         MSG_ERROR_T err = MSG_SUCCESS;
564         MMS_RECV_DATA_S recvData = {{0}, };
565
566         MmsAttrib attrib;
567
568         MmsInitMsgAttrib(&attrib);
569
570         attrib.priority = mmsHeader.priority;
571         attrib.bAskDeliveryReport = getMmsReport(mmsHeader.deliveryReport);
572         attrib.bAskReadReply = getMmsReport(mmsHeader.readReply);
573
574         //Set only changed members
575         pMsgInfo->msgId = pRequest->msgId;
576         MSG_DEBUG("@@@@@ msgId = %d @@@@@", pMsgInfo->msgId);
577         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
578
579         if (pRequest->eMmsPduType == eMMS_RETRIEVE_AUTO_CONF)
580                 pMsgInfo->msgType.subType = MSG_RETRIEVE_AUTOCONF_MMS;
581         else
582                 pMsgInfo->msgType.subType = MSG_RETRIEVE_MANUALCONF_MMS;
583
584         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
585
586         strncpy(pRequest->transactionId, mmsHeader.szTrID, MMS_TR_ID_LEN);
587
588         time_t curTime;
589         curTime = time(NULL);
590
591         pMsgInfo->displayTime = curTime;
592
593         if (mmsHeader.retrieveStatus == MMS_RETRSTATUS_OK) {
594                 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
595                 pMsgInfo->folderId = MSG_INBOX_ID;
596         } else {
597                 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
598                 pMsgInfo->folderId = MSG_INBOX_ID;
599                 // If failed MMS Retrieve, then saved as MMS Noti Ind Message.
600                 pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
601         }
602
603         pMsgInfo->dataSize = pRequest->getDataLen;
604
605         // set message-id & MMS TPDU file path
606         strcpy(recvData.szMsgID, mmsHeader.szMsgID);
607         if (pRetrievedFilePath)
608                 strncpy(recvData.retrievedFilePath, pRetrievedFilePath, sizeof(recvData.retrievedFilePath));
609
610 #ifdef FEATURE_JAVA_MMS
611         if (mmsHeader.msgType.param.szApplicationID || mmsHeader.msgType.param.szReplyToApplicationID) {
612                 recvData.msgAppId.valid = true;
613                 if (mmsHeader.msgType.param.szApplicationID)
614                         strncpy(recvData.msgAppId.appId, mmsHeader.msgType.param.szApplicationID, sizeof(recvData.msgAppId.appId));
615                 if (mmsHeader.msgType.param.szReplyToApplicationID)
616                         strncpy(recvData.msgAppId.replyToAppId, mmsHeader.msgType.param.szReplyToApplicationID, sizeof(recvData.msgAppId.replyToAppId));
617
618                 char fullPath[MAX_FULL_PATH_SIZE+1] = {0, };
619
620                 char *filename = NULL;
621                 filename = strrchr(pRetrievedFilePath, '/');
622
623                 snprintf(fullPath, MAX_FULL_PATH_SIZE+1, "%s%s", MSG_IPC_DATA_PATH, filename + 1);
624
625                 rename(pRetrievedFilePath, fullPath);
626
627                 if (chmod(fullPath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) != 0) {
628                         MSG_DEBUG("File Write Error: %s", strerror(errno));
629                 }
630
631                 if (chown(fullPath, 0, 6502 ) != 0) {
632                         MSG_DEBUG("File Write Error: %s", strerror(errno));
633                 }
634         }
635 #endif
636         memcpy(pMsgInfo->msgData, &recvData, sizeof(MMS_RECV_DATA_S));
637
638         MSG_DEBUG("@@@@@ MsgData = %s @@@@@", pMsgInfo->msgData);
639         MSG_DEBUG("@@@@@ retrievedFilePath = %s @@@@@", recvData.retrievedFilePath);
640         MSG_DEBUG("@@@@@ szMsgID = %s @@@@@", recvData.szMsgID);
641         //update delivery report, read reply
642
643         MmsPluginStorage *pStorage = MmsPluginStorage::instance();
644
645         MMS_MESSAGE_DATA_S msgData;
646         memset(&msgData, 0, sizeof(MMS_MESSAGE_DATA_S));
647
648         // Conversation is supported only Multipart Related message, Presentation info should be provided
649         if (mmsHeader.msgType.type == MIME_MULTIPART_RELATED || mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
650                 char *pSmilDoc = NULL;
651                 MmsMsg *pMsg = NULL;
652                 char szFileName[MSG_FILENAME_LEN_MAX] = {0, };
653
654                 msgData.regionCnt = 0;
655                 msgData.pageCnt = 0;
656                 msgData.attachCnt = 0;
657                 msgData.transitionCnt = 0;
658                 msgData.metaCnt = 0;
659                 memset(msgData.szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
660
661                 pSmilDoc = MmsSmilGetPresentationData(pMsgInfo->msgId);
662                 MmsSmilParseSmilDoc(&msgData, pSmilDoc);
663
664                 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
665                 strcpy(szFileName, pMsg->szFileName);
666
667                 err = pStorage->getMsgText(&msgData, pMsgInfo->msgText);
668                 err = pStorage->makeThumbnail(&msgData, pMsgInfo->thumbPath, szFileName);
669
670                 bMultipartRelated = true;
671         } else {
672                 MSG_DEBUG("Multipart mixed message doesn't support mms conversation");
673         }
674
675         err = pStorage->updateMmsAttrib(pMsgInfo->msgId, &attrib, pMsgInfo->msgType.subType);
676
677         partCnt = MmsGetMediaPartCount(pMsgInfo->msgId);
678         MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt );
679
680         if (partCnt < 0) {
681                 MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt );
682         } else {
683                 for (int i = 0; i < partCnt; ++i) {
684                         if (!MmsGetMediaPartHeader(i, &partHeader)) {
685                                 MSG_DEBUG("MmsUiGetMediaAttachInfo: MmsGetMediaPartHeader failed\n" );
686                                 break;
687                         }
688
689                         if (partHeader.contentSize > 0) {
690                                 char szBuf[MSG_FILEPATH_LEN_MAX];
691
692                                 strcpy((char *)szBuf, partHeader.param.szFileName);
693                                 sprintf(partHeader.param.szFileName, MSG_DATA_PATH"%s", szBuf);
694                                 if (!bMultipartRelated || MmsCheckAdditionalMedia(&msgData, &partHeader))
695                                         attachCount++;
696                         }
697                 }
698         }
699         MSG_DEBUG("attachCount [%d]", attachCount);
700         err = pStorage->updateMmsAttachCount(pMsgInfo->msgId, attachCount);
701
702         if (bMultipartRelated) {
703                 _MsgMmsReleasePageList(&msgData);
704                 _MsgMmsReleaseRegionList(&msgData);
705                 _MsgMmsReleaseAttachList(&msgData);
706                 _MsgMmsReleaseTransitionList(&msgData);
707                 _MsgMmsReleaseMetaList(&msgData);
708         }
709
710         MmsMsg *pMsg = NULL;
711         pStorage->getMmsMessage(&pMsg);
712         _MmsInitHeader();
713 #ifdef __SUPPORT_DRM__
714         _MsgFreeDRMInfo(&pMsg->msgType.drmInfo);
715 #endif
716         _MsgFreeBody(&pMsg->msgBody, pMsg->msgType.type);
717
718         MSG_END();
719 }
720
721 void MmsPluginInternal::processForwardConf(MSG_MESSAGE_INFO_S *msgInfo, mmsTranQEntity *pRequest)
722 {
723
724 }
725
726 /* This function Send NotifyRespInd Msg
727  *
728  * @param       pTrID [in] Specifies Transaction ID
729  * @param       iStatus [in] Specifies Msg Status
730  * @param       iReportAllowed [in] Specifies whether to send deliveryReport to sender or not
731  * @return      This function returns true on success, or false on failure.
732  */
733 bool MmsPluginInternal::encodeNotifyRespInd(char *szTrID, MSG_DELIVERY_REPORT_STATUS_T iStatus, bool bReportAllowed, char *pSendFilePath)
734 {
735         MSG_BEGIN();
736
737         FILE *pFile = NULL;
738         char pTempFileName[MSG_FILENAME_LEN_MAX+1] = {0};
739         char pTempFilePath[MAX_FULL_PATH_SIZE] = {0};
740
741         if (MsgCreateFileName(pTempFileName) == false)
742                 return false;
743
744         snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"%s.noti.ind", pTempFileName);
745
746         pFile = MsgOpenMMSFile(pTempFilePath);
747
748         if (!pFile) {
749                 MSG_DEBUG("[ERROR] MsgOpenMMSFile fail");
750                 return false;
751         }
752
753         if (_MmsEncodeNotiRespInd(pFile, szTrID, iStatus, bReportAllowed) == false) {
754                 MSG_DEBUG("MmsEncodeNotifyRespInd: _MmsEncodeNotiRespInd fail");
755                 MsgCloseFile(pFile);
756                 return false;
757         }
758
759         MsgCloseFile(pFile);
760
761         if (pSendFilePath) {
762                 snprintf(pSendFilePath, MAX_MSG_DATA_LEN+1, "%s.mms", pTempFilePath);
763         } else {
764                 MSG_DEBUG("[ERROR] pSendFilePath is NULL");
765                 return false;
766         }
767
768         MSG_END();
769
770         return true;
771 }
772
773 /* This function Send AcknowledgeInd Msg
774  *
775  * @param       pTrID [in] Specifies Transaction ID
776  * @param       iReportAllowed [in] Specifies whether to send deliveryReport to sender or not
777  * @return      This function returns true on success, or false on failure.
778  */
779 bool MmsPluginInternal::encodeAckInd(char *szTrID, bool bReportAllowed, char *pSendFilePath)
780 {
781         MSG_BEGIN();
782         FILE *pFile = NULL;
783         char pTempFileName[MSG_FILENAME_LEN_MAX+1] = {0};
784         char pTempFilePath[MAX_FULL_PATH_SIZE] = {0};
785
786         if (MsgCreateFileName(pTempFileName) == false)
787                 return false;
788
789         snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"%s.ack.ind", pTempFileName);
790
791         pFile = MsgOpenMMSFile(pTempFilePath);
792         if (!pFile) {
793                 MSG_DEBUG("[ERROR] MsgOpenMMSFile fail \n" );
794                 return false;
795         }
796
797         if (_MmsEncodeAckInd(pFile, szTrID, bReportAllowed) == false) {
798                 MSG_DEBUG("MmsEncodeAckInd: _MmsEncodeAckInd fail \n" );
799                 MsgCloseFile(pFile);
800                 return false;
801         }
802
803         MsgCloseFile(pFile);
804
805         if (pSendFilePath) {
806                 snprintf(pSendFilePath, MAX_MSG_DATA_LEN+1, "%s.mms", pTempFilePath);
807         } else {
808                 MSG_DEBUG("[ERROR] pSendFilePath is NULL");
809                 return false;
810         }
811
812         MSG_END();
813
814         return true;
815 }
816
817 bool MmsPluginInternal::checkRejectNotiInd(int roamState, bool bReportAllowed, char *pSendFilePath)
818 {
819         MSG_BEGIN();
820         MSG_MMS_HOME_RETRIEVE_TYPE_T retrieveType;
821         bool bRejectAnonymous;
822         bool bRejectAdvertisement;
823
824         MsgSettingGetBool(MMS_RECV_REJECT_UNKNOWN, &bRejectAnonymous);
825         MsgSettingGetBool(MMS_RECV_REJECT_ADVERTISE, &bRejectAdvertisement);
826
827         // Anonymous Reject
828         if (bRejectAnonymous &&
829                 (mmsHeader.pFrom == NULL || mmsHeader.pFrom->szAddr[0] == '\0')) {
830                 MSG_DEBUG("Anonymous Reject... ");
831                 encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
832
833                 return true;
834         }
835
836         // Advertisement Reject
837         if (bRejectAdvertisement && mmsHeader.msgClass == MMS_MSGCLASS_ADVERTISEMENT) {
838                 MSG_DEBUG("Advertisement Reject... ");
839                 encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
840
841                 return true;
842         }
843
844         // Message Reject - Roaming Case
845         if (roamState == VCONFKEY_TELEPHONY_SVC_ROAM_ON) {
846                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)MsgSettingGetInt(MMS_RECV_ABROAD_NETWORK);
847                 if (retrieveType == MSG_ABROAD_REJECT) {
848                         MSG_DEBUG("Abroad_Network : Notification Reject... ");
849                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
850
851                         return true;
852                 }
853         } else {
854                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)MsgSettingGetInt(MMS_RECV_HOME_NETWORK);
855                 if (retrieveType == MSG_HOME_REJECT) {
856                         MSG_DEBUG("Home_Network : Notification Reject... ");
857                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
858
859                         return true;
860                 }
861         }
862
863         // Not Rejected
864         MSG_END();
865         return false;
866
867 }
868
869 bool MmsPluginInternal::getMmsReport(MmsReport mmsReport)
870 {
871         bool result = false;
872
873         if (mmsReport == MMS_REPORT_YES)
874                 result = true;
875         else if (mmsReport == MMS_REPORT_NO)
876                 result = false;
877
878         return result;
879 }
880
881 const char *MmsPluginInternal::getMmsDeliveryStatus(MSG_DELIVERY_REPORT_STATUS_T deliveryStatus)
882 {
883         MSG_DEBUG("msgStatus= %d", deliveryStatus);
884
885         switch (deliveryStatus) {
886         case MSG_DELIVERY_REPORT_EXPIRED:
887                 return "expired.";
888         case MSG_DELIVERY_REPORT_REJECTED:
889                 return "rejected.";
890         case MSG_DELIVERY_REPORT_UNREACHABLE:
891                 return "unreachable.";
892         case MSG_DELIVERY_REPORT_UNRECOGNISED:
893                 return "unrecognised.";
894         case MSG_DELIVERY_REPORT_SUCCESS:
895                 return "delivered.";
896         default:
897                 return "delivery failed.";
898         }
899 }
900
901 const char *MmsPluginInternal::getMmsReadStatus(MSG_READ_REPORT_STATUS_T readStatus)
902 {
903         switch (readStatus) {
904         case MSG_READ_REPORT_IS_READ:
905                 return "message is read.";
906         case MSG_READ_REPORT_IS_DELETED:
907                 return "message is deleted.";
908         default:
909                 return "read status is none.";
910         }
911 }
912