[TNEXT-639] block codes related with group message feature
[platform/core/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginInternal.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 "MsgCppTypes.h"
22 #include "MsgUtilFile.h"
23 #include "MsgException.h"
24 #include "MsgSettingTypes.h"
25 #include "MsgMmsMessage.h"
26 #include "MsgGconfWrapper.h"
27 #include "MsgSerialize.h"
28 #include "MsgSpamFilter.h"
29 #include "MsgUtilMime.h"
30 #include "MsgUtilFunction.h"
31
32 #include "MmsPluginDebug.h"
33 #include "MmsPluginTypes.h"
34 #include "MmsPluginCodec.h"
35 #include "MmsPluginInternal.h"
36 #include "MmsPluginStorage.h"
37 #include "MmsPluginAppBase.h"
38
39 /*==================================================================================================
40                                      IMPLEMENTATION OF MmsPluginInternal - Member Functions
41 ==================================================================================================*/
42 MmsPluginInternal *MmsPluginInternal::pInstance = NULL;
43
44
45 MmsPluginInternal::MmsPluginInternal()
46 {
47 }
48
49 MmsPluginInternal::~MmsPluginInternal()
50 {
51 }
52
53 MmsPluginInternal *MmsPluginInternal::instance()
54 {
55         if (!pInstance)
56                 pInstance = new MmsPluginInternal();
57
58         return pInstance;
59 }
60
61 void MmsPluginInternal::processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest, bool *bReject)
62 {
63         MSG_BEGIN();
64
65         FILE *pFile = NULL;
66         char fileName[MSG_FILENAME_LEN_MAX] = {0, };
67
68         if (pMsgInfo->bTextSms == true) {
69                 char fullPath[MAX_FULL_PATH_SIZE+1] = {0, };
70
71                 if (MsgCreateFileName(fileName) == false)
72                         THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
73
74                 MSG_SEC_DEBUG("File name = %s", fileName);
75
76                 if (MsgWriteIpcFile(fileName, pMsgInfo->msgText, pMsgInfo->dataSize) == false)
77                         THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
78
79                 snprintf(fullPath, MAX_FULL_PATH_SIZE+1, "%s%s", MSG_IPC_DATA_PATH, fileName);
80
81                 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
82                 memcpy(pMsgInfo->msgData, fullPath, strlen(fullPath));
83                 pMsgInfo->bTextSms = false;
84         }
85
86         MSG_SEC_DEBUG("MMS File Path = %s", pMsgInfo->msgData);
87
88         MmsInitHeader();
89         MmsRegisterDecodeBuffer();
90
91         if ((pFile = MsgOpenFile(pMsgInfo->msgData, "rb+")) == NULL) {
92                 MSG_DEBUG("File Open Error: %s", pMsgInfo->msgData);
93         } else {
94                 /* Decode Header */
95                 if (!MmsBinaryDecodeMsgHeader(pFile, pMsgInfo->dataSize))
96                         MSG_DEBUG("Decoding Header Failed \r\n");
97
98                 MsgCloseFile(pFile);
99
100                 if (remove(pMsgInfo->msgData) != 0)
101                         MSG_DEBUG("Fail remove");
102
103                 switch (mmsHeader.type) {
104                 case MMS_MSGTYPE_NOTIFICATION_IND:
105                         MSG_DEBUG("process noti.ind\n");
106                         /* For Set Value pMsgInfo */
107                         if (processNotiInd(pMsgInfo, pRequest) == false)
108                                 *bReject = true;
109                         else
110                                 *bReject = false;
111                         break;
112
113                 case MMS_MSGTYPE_DELIVERY_IND:
114                         MSG_DEBUG("process delivery.ind\n");
115                         /* For Set Value pMsgInfo */
116                         processDeliveryInd(pMsgInfo);
117                         break;
118
119                 case MMS_MSGTYPE_READORG_IND:
120                         MSG_DEBUG("process readorig.ind\n");
121                         processReadOrgInd(pMsgInfo);
122                         break;
123                 default:
124                         break;
125                 }
126         }
127
128         MSG_END();
129 }
130
131 bool MmsPluginInternal::processNotiInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest)
132 {
133         MSG_DEBUG("MmsProcessNotiInd");
134
135         MSG_MMS_HOME_RETRIEVE_TYPE_T retrieveType;
136         bool bReportAllowed;
137
138         MmsAttrib attrib;
139         MsgDbHandler *dbHandle = getDbHandle();
140
141         MmsInitMsgAttrib(&attrib);
142
143         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
144         pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
145         pMsgInfo->priority = mmsHeader.priority;
146         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
147
148         MSG_DEBUG("pMsgInfo->subject [%s]", pMsgInfo->subject);
149
150 #if 0   /* we do not need to add empty subject text any more. */
151         if (strlen(pMsgInfo->subject) < 1)
152                 snprintf(pMsgInfo->subject, MAX_SUBJECT_LEN, "MMS Notification Message.");
153 #endif
154
155         attrib.expiryTime = mmsHeader.expiryTime;
156
157         if (mmsHeader.pFrom) {
158                 MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
159                 /* From */
160                 strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pFrom->szAddr, MAX_ADDRESS_VAL_LEN);
161                 if (MmsAddrUtilCheckEmailAddress(pMsgInfo->addressList[0].addressVal)) {
162                         pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_EMAIL;
163                 }
164         }
165
166         MMS_DATA_S *mms_data = MsgMmsCreate();
167         if (mms_data == NULL)
168                 return false;
169
170         mms_data->header = MsgMmsCreateHeader();
171
172         if (mms_data->header == NULL) {
173                 MsgMmsRelease(&mms_data);
174                 return false;
175         }
176
177         MMS_HEADER_DATA_S *pHeader = mms_data->header;
178
179         pHeader->messageType = mmsHeader.type;
180
181         snprintf(pHeader->trID, sizeof(pHeader->trID), "%s", mmsHeader.szTrID);
182
183         pHeader->mmsVersion = mmsHeader.version;
184
185         /* From */
186         if (mmsHeader.pFrom) {
187                 MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
188                 snprintf(pHeader->szFrom, sizeof(pHeader->szFrom), "%s", mmsHeader.pFrom->szAddr);
189         }
190
191         /* Subject */
192         snprintf(pHeader->szSubject, sizeof(pHeader->szSubject), "%s", mmsHeader.szSubject);
193         /* Delivery Report */
194         pHeader->bDeliveryReport = (mmsHeader.deliveryReport != MMS_REPORT_YES);
195         /* Message Class */
196         pHeader->messageClass = mmsHeader.msgClass;
197
198         /* Priority */
199         pHeader->mmsPriority = mmsHeader.priority;
200
201         /* Message Size : pMmsMsg->mmsAttrib.msgSize = mmsHeader.msgSize; */
202         /* Expiry */
203         pHeader->expiry.type = mmsHeader.expiryTime.type;
204         pHeader->expiry.time = mmsHeader.expiryTime.time;
205
206         time_t curTime = time(NULL);
207
208         if (pHeader->expiry.type == MMS_TIMETYPE_RELATIVE) {
209                 pHeader->expiry.type = MMS_TIMETYPE_ABSOLUTE;
210                 pHeader->expiry.time += curTime;
211         }
212
213         /* Charge */
214         /* contentclass */
215         /* int contentClass; */ /*text | image-basic| image-rich | video-basic | video-rich | megapixel | content-basic | content-rich */
216         strncpy(pHeader->contentLocation, mmsHeader.szContentLocation, MMS_LOCATION_LEN);
217
218         pHeader->messageSize = mmsHeader.msgSize;
219
220         MSG_DEBUG("Message size = [%d]", pHeader->messageSize);
221
222         char *pSerializedMms = NULL;
223         int serializeDataSize = 0;
224
225         char pTempFileName[MSG_FILENAME_LEN_MAX+1] = {0};
226         char pTempFilePath[MSG_FILEPATH_LEN_MAX+1] = {0};
227
228         serializeDataSize = MsgSerializeMms(mms_data, &pSerializedMms);
229
230         if (pSerializedMms) {
231                 if (MsgCreateFileName(pTempFileName) == true) {
232                         pMsgInfo->bTextSms = false;
233
234                         snprintf(pTempFilePath, sizeof(pTempFilePath), "%s%s", MSG_IPC_DATA_PATH, pTempFileName);
235
236                         MsgOpenCreateAndOverwriteFile(pTempFilePath, pSerializedMms, serializeDataSize);
237
238                         /* set file name */
239                         snprintf(pMsgInfo->msgData, sizeof(pMsgInfo->msgData), "%s", pTempFileName);
240                 }
241
242                 delete [] pSerializedMms;
243         }
244
245                 MsgMmsRelease(&mms_data);
246
247         /* Check contents-location is in noti.ind */
248         if (mmsHeader.szContentLocation[0] == '\0') {
249                 THROW(MsgException::INCOMING_MSG_ERROR, "######## Contents-location is empty in MMS-Noti-Ind  #######");
250                 return false;
251         }
252
253         int roamState = 0;
254         char pPduFilePath[MAX_FULL_PATH_SIZE] = {0};
255
256         if (MsgSettingGetInt(VCONFKEY_TELEPHONY_SVC_ROAM, &roamState) != MSG_SUCCESS)
257                 MSG_INFO("MsgSettingGetInt() is failed");
258
259         if (MsgSettingGetBool(MMS_SEND_REPORT_ALLOWED, &bReportAllowed) != MSG_SUCCESS)
260                 MSG_INFO("MsgSettingGetBool() is failed");
261
262         if (checkRejectNotiInd(roamState, bReportAllowed, pPduFilePath)) {
263                 MSG_DEBUG("MMS Message Rejected......");
264
265                 pMsgInfo->dataSize = strlen(pPduFilePath);
266                 memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
267                 snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
268                 pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
269
270                 return false;
271         }
272
273         if (MsgCheckFilter(dbHandle, pMsgInfo)) {
274                 encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pPduFilePath);
275
276                 pMsgInfo->dataSize = strlen(pPduFilePath);
277
278                 pRequest->msgInfo.bTextSms = false;
279
280                 memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
281
282                 snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
283                 MSG_SEC_DEBUG("pRequest->msgInfo.msgData = %s", pRequest->msgInfo.msgData);
284                 pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
285                 pRequest->msgInfo.folderId = MSG_SPAMBOX_ID;
286
287                 return true;
288         }
289
290         int tmpVal = 0;
291         if (roamState == VCONFKEY_TELEPHONY_SVC_ROAM_OFF) {
292                 if (MsgSettingGetInt(MMS_RECV_HOME_NETWORK, &tmpVal) != MSG_SUCCESS) {
293                         MSG_INFO("MsgSettingGetInt() is failed");
294                 }
295                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)tmpVal;
296                 MSG_DEBUG("$$$$$$$$$$ MMS_RECV_HOME_NETWORK = %d $$$$$$$$$$$$$", retrieveType);
297         } else {
298                 if (MsgSettingGetInt(MMS_RECV_ABROAD_NETWORK, &tmpVal) != MSG_SUCCESS) {
299                         MSG_INFO("MsgSettingGetInt() is failed");
300                 }
301                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)tmpVal;
302                 MSG_DEBUG("$$$$$$$$$$ MMS_RECV_ABROAD_NETWORK = %d $$$$$$$$$$$$$", retrieveType);
303
304                 if (retrieveType == MSG_ABROAD_RESTRICTED) {
305                         MSG_DEBUG("MMS Receiving Setting Restricted was selected.");
306                         /* m-notify-resp-ind encoding process */
307                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pPduFilePath);
308
309                         pMsgInfo->dataSize = strlen(pPduFilePath);
310
311                         pRequest->msgInfo.bTextSms = false;
312
313                         memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
314
315                         snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
316
317                         pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
318
319                         return true;
320                 }
321         }
322
323         /* should send http 'GET' */
324         if (retrieveType == MSG_HOME_AUTO_DOWNLOAD || retrieveType == MSG_ABROAD_AUTO_DOWNLOAD) {
325                 /* Check if current request sim index is different from default network SIM */
326                 /* Convert auto-retrieve to manual retrieve in case sim indexes are different */
327                 int default_sim = 0;
328                 if (MsgSettingGetInt(MSG_NETWORK_SIM, &default_sim) != MSG_SUCCESS) {
329                         MSG_INFO("MsgSettingGetInt() is failed");
330                 }
331
332                 MSG_DEBUG("default_sim = %d, pMsgInfo->sim_idx = %d", default_sim, pMsgInfo->sim_idx);
333
334                 if (default_sim == (int)pMsgInfo->sim_idx) {
335                         MSG_DEBUG("=========== START AUTO RETRIEVE MODE ============");
336
337                         pMsgInfo->dataSize = strlen(mmsHeader.szContentLocation);
338
339                         pRequest->msgInfo.bTextSms = true;
340
341                         memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
342
343                         snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", mmsHeader.szContentLocation);
344
345                         pRequest->msgInfo.msgType.subType = MSG_GET_MMS;
346
347                         MSG_SEC_DEBUG("MSG SUBTYPE = %d msg data %s bTextsms %d", pRequest->msgInfo.msgType.subType, pRequest->msgInfo.msgData, pRequest->msgInfo.bTextSms);
348                 } else {
349                         /* should send m-notify-resp-ind */
350                         MSG_DEBUG("=========== START MANUAL RETRIEVE MODE ===========");
351                         /* m-notify-resp-ind encoding process */
352                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pPduFilePath);
353
354                         pMsgInfo->dataSize = strlen(pPduFilePath);
355
356                         pRequest->msgInfo.bTextSms = false;
357
358                         memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
359
360                         snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
361                         MSG_SEC_DEBUG("pRequest->msgInfo.msgData = %s", pRequest->msgInfo.msgData);
362                         snprintf(pRequest->msgInfo.msgURL, sizeof(pRequest->msgInfo.msgURL), "%s", mmsHeader.szContentLocation);
363                         pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
364                 }
365         } else {
366                 /* should send m-notify-resp-ind */
367                 MSG_DEBUG("=========== START MANUAL RETRIEVE MODE ===========");
368                 /* m-notify-resp-ind encoding process */
369
370                 if (retrieveType == MSG_HOME_MANUAL || retrieveType == MSG_ABROAD_MANUAL) {
371                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pPduFilePath);
372                 }
373
374                 pMsgInfo->dataSize = strlen(pPduFilePath);
375
376                 pRequest->msgInfo.bTextSms = false;
377
378                 memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
379
380                 snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
381                 MSG_SEC_DEBUG("pRequest->msgInfo.msgData = %s", pRequest->msgInfo.msgData);
382                 snprintf(pRequest->msgInfo.msgURL, sizeof(pRequest->msgInfo.msgURL), "%s", mmsHeader.szContentLocation);
383                 pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
384         }
385
386         return true;
387 }
388
389 void MmsPluginInternal::processDeliveryInd(MSG_MESSAGE_INFO_S *pMsgInfo)
390 {
391         MSG_BEGIN();
392
393         MmsMsgMultiStatus status;
394         memset(&status, 0x00, sizeof(MmsMsgMultiStatus));
395
396         status.msgStatus = mmsHeader.msgStatus;
397         status.handledTime = mmsHeader.date;
398         status.bDeliveryReportIsRead = false;
399         status.bDeliveyrReportIsLast = true;
400
401         MmsAddrUtilRemovePlmnString(mmsHeader.pTo->szAddr);
402         MSG_SEC_DEBUG("[INFO] [ADDR: %s, MMSID: %s]", mmsHeader.pTo->szAddr, mmsHeader.szMsgID);
403
404         pMsgInfo->msgType.mainType      = MSG_MMS_TYPE;
405         pMsgInfo->msgType.subType       = MSG_DELIVERYIND_MMS;
406         pMsgInfo->bTextSms = true;
407         pMsgInfo->dataSize = 0;
408         memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
409
410         strncpy(pMsgInfo->msgData, getMmsDeliveryStatus(status.msgStatus), MAX_MSG_DATA_LEN);
411         pMsgInfo->dataSize  = strlen(pMsgInfo->msgData);
412         MSG_DEBUG("Delivery Status = %s", pMsgInfo->msgData);
413
414         strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pTo->szAddr, MAX_ADDRESS_VAL_LEN);
415
416         int tmpId = (msg_message_id_t)MmsPluginStorage::instance()->searchMsgId(mmsHeader.pTo->szAddr, mmsHeader.szMsgID);
417         if (tmpId > 0) {
418                 MSG_DEBUG("Found MSG_ID = %d", tmpId);
419
420                 /* Insert to Delievery DB */
421                 MmsPluginStorage::instance()->insertDeliveryReport(tmpId, mmsHeader.pTo->szAddr, &status);
422
423                 pMsgInfo->msgId = (msg_message_id_t)tmpId;
424
425         } else {
426                 MSG_DEBUG("Can not find MMS message in DB");
427         }
428
429         MSG_END();
430 }
431
432 void MmsPluginInternal::processReadOrgInd(MSG_MESSAGE_INFO_S *pMsgInfo)
433 {
434         MSG_BEGIN();
435
436         if (pMsgInfo == NULL) {
437                 MSG_DEBUG("parameter err");
438                 return;
439         }
440
441         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
442         pMsgInfo->msgType.subType = MSG_READORGIND_MMS;
443         pMsgInfo->bTextSms = true;
444
445         MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
446         MmsAddrUtilRemovePlmnString(mmsHeader.pTo->szAddr);
447
448         memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
449         pMsgInfo->dataSize = 0;
450
451         strncpy(pMsgInfo->msgData, getMmsReadStatus(mmsHeader.readStatus), MAX_MSG_DATA_LEN);
452         pMsgInfo->dataSize  = strlen(pMsgInfo->msgData);
453
454         MSG_SEC_DEBUG("read Status = %s", pMsgInfo->msgData);
455         strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pFrom->szAddr, MAX_ADDRESS_VAL_LEN);
456
457         int tmpId = MmsPluginStorage::instance()->searchMsgId(mmsHeader.pFrom->szAddr, mmsHeader.szMsgID);
458         if (tmpId > 0) {
459                 pMsgInfo->msgId = (msg_message_id_t)tmpId;
460
461                 MmsMsgMultiStatus Status;
462                 memset(&Status, 0x00, sizeof(MmsMsgMultiStatus));
463                 Status.readTime = mmsHeader.date;
464                 Status.readStatus = mmsHeader.readStatus;
465
466                 MmsPluginStorage::instance()->insertReadReport(pMsgInfo->msgId, mmsHeader.pFrom->szAddr, &Status);
467
468         } else {
469                 MSG_DEBUG("Can't not find Message!");
470         }
471
472         MSG_END();
473 }
474
475 void MmsPluginInternal::processSendConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEntity *pRequest)
476 {
477         MSG_BEGIN();
478
479         MMS_RECV_DATA_S recvData = {{0}, };
480
481         pMsgInfo->msgId = pRequest->msgId;
482
483         /* Set only changed members */
484         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
485         pMsgInfo->msgType.subType = MSG_SENDCONF_MMS;
486
487         pMsgInfo->folderId = MSG_OUTBOX_ID;
488
489         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
490
491         if (mmsHeader.responseStatus == MMS_RESPSTATUS_OK) {
492                 pMsgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
493                 pMsgInfo->dataSize = pRequest->postDataLen;
494         } else {
495                 pMsgInfo->networkStatus = MSG_NETWORK_SEND_FAIL;
496
497                 char responseText[MMS_LOCALE_RESP_TEXT_LEN];
498
499                 memset(responseText, 0x00, MMS_LOCALE_RESP_TEXT_LEN);
500                 snprintf(responseText, MMS_LOCALE_RESP_TEXT_LEN, " %s [%d]", mmsHeader.szResponseText, mmsHeader.responseStatus);
501
502                 memset(pMsgInfo->msgText, 0x00, MAX_MSG_TEXT_LEN + 1);
503                 strncpy(pMsgInfo->msgText, responseText, MMS_LOCALE_RESP_TEXT_LEN);
504         }
505
506         MSG_ADDRESS_INFO_S addressinfo = {0, };
507         char keyName[MAX_VCONFKEY_NAME_LEN];
508         memset(keyName, 0x00, sizeof(keyName));
509
510         snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, pMsgInfo->sim_idx);
511         char *msisdn = NULL;
512         if (MsgSettingGetString(keyName, &msisdn) != MSG_SUCCESS) {
513                 MSG_INFO("MsgSettingGetString() is failed");
514         }
515
516         MmsPluginStorage::instance()->getAddressInfo(pMsgInfo->msgId, &addressinfo);
517
518         MSG_SEC_DEBUG("%d, MMS Send End %s->%s %s", pMsgInfo->msgId
519                                                                                                         , (msisdn == NULL)?"ME":msisdn
520                                                                                                         , addressinfo.addressVal
521                                                                                                         , (pMsgInfo->networkStatus == MSG_NETWORK_SEND_SUCCESS)?"Success":"Fail");
522
523         if (msisdn) {
524                 free(msisdn);
525                 msisdn = NULL;
526         }
527
528         /* set message-id from mmsc */
529         strncpy(recvData.szMsgID, mmsHeader.szMsgID, MMS_MSG_ID_LEN);
530         strncpy(recvData.szTrID, mmsHeader.szTrID, MMS_TR_ID_LEN);
531
532         memset(pMsgInfo->msgData, 0x00, MAX_MSG_DATA_LEN + 1);
533         memcpy(pMsgInfo->msgData, &recvData, sizeof(MMS_RECV_DATA_S));
534
535         time_t curTime;
536         curTime = time(NULL);
537
538         pMsgInfo->displayTime = curTime;
539
540         MmsMsg *pMsg = NULL;
541         MmsPluginStorage::instance()->getMmsMessage(&pMsg);
542         MmsInitHeader();
543         MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
544         MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
545
546         MSG_END();
547 }
548
549 #if 1
550 void __fillAddressInfo(MSG_ADDRESS_INFO_S *addressInfo, const char *addressVal, msg_recipient_type_t recipientType)
551 {
552         strncpy(addressInfo->addressVal, addressVal, MAX_ADDRESS_VAL_LEN);
553         addressInfo->recipientType = recipientType;
554         if (MmsAddrUtilCheckEmailAddress(addressInfo->addressVal)) {
555                 addressInfo->addressType = MSG_ADDRESS_TYPE_EMAIL;
556         } else {
557                 addressInfo->addressType = MSG_ADDRESS_TYPE_PLMN;
558         }
559 }
560
561 void MmsPluginInternal::processRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEntity *pRequest, char *pRetrievedFilePath)
562 {
563         MSG_BEGIN();
564
565         msg_error_t err = MSG_SUCCESS;
566         MMS_RECV_DATA_S recvData = {{0}, };
567
568         MmsAttrib attrib;
569
570         MmsInitMsgAttrib(&attrib);
571
572         attrib.priority = mmsHeader.priority;
573         attrib.bAskDeliveryReport = getMmsReport(mmsHeader.deliveryReport);
574         attrib.bAskReadReply = getMmsReport(mmsHeader.readReply);
575
576         /* Set only changed members */
577         pMsgInfo->msgId = pRequest->msgId;
578         MSG_DEBUG("@@@@@ msgId = %d @@@@@", pMsgInfo->msgId);
579         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
580
581         if (pRequest->eMmsPduType == eMMS_RETRIEVE_AUTO_CONF)
582                 pMsgInfo->msgType.subType = MSG_RETRIEVE_AUTOCONF_MMS;
583         else
584                 pMsgInfo->msgType.subType = MSG_RETRIEVE_MANUALCONF_MMS;
585
586         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
587
588         strncpy(pRequest->transactionId, mmsHeader.szTrID, MMS_TR_ID_LEN);
589
590         time_t curTime;
591         curTime = time(NULL);
592
593         pMsgInfo->displayTime = curTime;
594
595         if (mmsHeader.retrieveStatus == MMS_RETRSTATUS_OK) {
596                 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
597                 pMsgInfo->folderId = MSG_INBOX_ID;
598         } else {
599                 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
600                 pMsgInfo->folderId = MSG_INBOX_ID;
601                 /* If failed MMS Retrieve, then saved as MMS Noti Ind Message.
602                  * It will changed in MsgHandleMmsConfIncomingMsg */
603 /*              pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS; */
604         }
605
606         char keyName[MAX_VCONFKEY_NAME_LEN];
607         memset(keyName, 0x00, sizeof(keyName));
608
609         snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, pMsgInfo->sim_idx);
610         char *msisdn = NULL;
611         if (MsgSettingGetString(keyName, &msisdn) != MSG_SUCCESS) {
612                 MSG_INFO("MsgSettingGetString() is failed");
613         }
614         char *normal_msisdn = NULL;
615         if (msisdn)
616                 normal_msisdn = msg_normalize_number(msisdn);
617
618         int addr_cnt = 0;
619         int recipients_cnt = 0;
620         MsgHeaderAddress *iter = NULL;
621
622         iter = mmsHeader.pFrom;
623         while (iter) {
624                 MmsAddrUtilRemovePlmnString(iter->szAddr);
625                 recipients_cnt++;
626                 addr_cnt++;
627                 iter = iter->pNext;
628         }
629 #if 0 /* This block will be activated after find way to get own number with any SIMs */
630         iter = mmsHeader.pTo;
631         while (iter) {
632                 MmsAddrUtilRemovePlmnString(iter->szAddr);
633                 recipients_cnt++;
634                 if (normal_msisdn == NULL || normal_msisdn[0] == '\0' || !g_str_has_suffix(iter->szAddr, normal_msisdn))
635                         addr_cnt++;
636                 iter = iter->pNext;
637         }
638
639         iter = mmsHeader.pCc;
640         while (iter) {
641                 MmsAddrUtilRemovePlmnString(iter->szAddr);
642                 recipients_cnt++;
643                 if (normal_msisdn == NULL || normal_msisdn[0] == '\0' || !g_str_has_suffix(iter->szAddr, normal_msisdn))
644                         addr_cnt++;
645                 iter = iter->pNext;
646         }
647 #endif
648         MSG_ADDRESS_INFO_S *recipients_addr_info = NULL;
649         if (recipients_cnt > 0) {
650                 recipients_addr_info = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)*recipients_cnt];
651                 memset(recipients_addr_info, 0x00, sizeof(MSG_ADDRESS_INFO_S)*recipients_cnt);
652         }
653
654         MSG_ADDRESS_INFO_S *tmp_addr_info = NULL;
655         if (addr_cnt > 0) {
656                 tmp_addr_info = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)*addr_cnt];
657                 memset(tmp_addr_info, 0x00, sizeof(MSG_ADDRESS_INFO_S)*addr_cnt);
658         }
659
660         pMsgInfo->nAddressCnt = addr_cnt;
661         pMsgInfo->addressList = tmp_addr_info;
662
663         if (recipients_addr_info != NULL && pMsgInfo->addressList != NULL) {
664                 if (mmsHeader.pFrom) {
665                         MSG_DEBUG("FROM : [%s]", mmsHeader.pFrom->szAddr);
666                         /* From */
667                         __fillAddressInfo(&(pMsgInfo->addressList[0]), mmsHeader.pFrom->szAddr, MSG_RECIPIENTS_TYPE_UNKNOWN);
668                         __fillAddressInfo(&recipients_addr_info[0], mmsHeader.pFrom->szAddr, MSG_RECIPIENTS_TYPE_UNKNOWN);
669                 }
670 #if 0 /* This block will be activated after find way to get own number with any SIMs */
671                 int addr_idx = 0;
672                 int recipients_idx = 0;
673                 if (mmsHeader.pTo) {
674                         MsgHeaderAddress *iter = mmsHeader.pTo;
675                         while (iter) {
676                                 MSG_DEBUG("TO : [%s]", iter->szAddr);
677                                 /* To */
678                                 if (normal_msisdn == NULL || normal_msisdn[0] == '\0' || !g_str_has_suffix(iter->szAddr, normal_msisdn)) {
679                                         __fillAddressInfo(&(pMsgInfo->addressList[++addr_idx]), iter->szAddr, MSG_RECIPIENTS_TYPE_TO);
680                                 }
681                                 __fillAddressInfo(&recipients_addr_info[++recipients_idx], iter->szAddr, MSG_RECIPIENTS_TYPE_TO);
682
683                                 iter = iter->pNext;
684                         }
685                 }
686
687                 if (mmsHeader.pCc) {
688                         MsgHeaderAddress *iter = mmsHeader.pCc;
689                         while (iter) {
690                                 MSG_DEBUG("CC : [%s]", iter->szAddr);
691                                 /* Cc */
692                                 if (normal_msisdn == NULL || normal_msisdn[0] == '\0' || !g_str_has_suffix(iter->szAddr, normal_msisdn)) {
693                                         __fillAddressInfo(&(pMsgInfo->addressList[++addr_idx]), iter->szAddr, MSG_RECIPIENTS_TYPE_CC);
694                                 }
695                                 __fillAddressInfo(&recipients_addr_info[++recipients_idx], iter->szAddr, MSG_RECIPIENTS_TYPE_CC);
696
697                                 iter = iter->pNext;
698                         }
699                 }
700 #endif
701         }
702
703         MSG_SEC_DEBUG("%d, MMS Receive %s End %s->%s %s", pMsgInfo->msgId
704                                                                                                                 , (pRequest->eMmsPduType == eMMS_RETRIEVE_AUTO_CONF)?"Auto":"Manual"
705                                                                                                                 , (mmsHeader.pFrom)?mmsHeader.pFrom->szAddr:"YOU"
706                                                                                                                 , (msisdn == NULL)?"ME":msisdn
707                                                                                                                 , (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS)?"Success":"Fail");
708
709         if (msisdn) {
710                 free(msisdn);
711                 msisdn = NULL;
712         }
713
714         pMsgInfo->dataSize = pRequest->getDataLen;
715
716         /* set message-id & MMS TPDU file path */
717         snprintf(recvData.szMsgID, sizeof(recvData.szMsgID), "%s", mmsHeader.szMsgID);
718
719         if (pRetrievedFilePath)
720                 strncpy(recvData.retrievedFilePath, pRetrievedFilePath, sizeof(recvData.retrievedFilePath)-1);
721
722         char *filename = NULL;
723
724 #ifdef FEATURE_JAVA_MMS
725         if (mmsHeader.msgType.param.szApplicationID || mmsHeader.msgType.param.szReplyToApplicationID) {
726                 recvData.msgAppId.valid = true;
727                 if (mmsHeader.msgType.param.szApplicationID)
728                         strncpy(recvData.msgAppId.appId, mmsHeader.msgType.param.szApplicationID, sizeof(recvData.msgAppId.appId));
729                 if (mmsHeader.msgType.param.szReplyToApplicationID)
730                         strncpy(recvData.msgAppId.replyToAppId, mmsHeader.msgType.param.szReplyToApplicationID, sizeof(recvData.msgAppId.replyToAppId));
731
732                 char fullPath[MAX_FULL_PATH_SIZE+1] = {0, };
733
734                 filename = MsgGetFileName(pRetrievedFilePath);
735
736                 snprintf(fullPath, MAX_FULL_PATH_SIZE+1, "%s%s", MSG_IPC_DATA_PATH, filename);
737
738                 if (pRetrievedFilePath) {
739                         int ret  = rename(pRetrievedFilePath, fullPath);
740                         if (ret != 0) {
741                                 MSG_DEBUG("File rename Error: %s", g_strerror(errno));
742                         }
743                 }
744         }
745 #endif
746         memcpy(pMsgInfo->msgData, &recvData, sizeof(MMS_RECV_DATA_S));
747
748         MSG_SEC_DEBUG("@@@@@ MsgData = %s @@@@@", pMsgInfo->msgData);
749         MSG_SEC_DEBUG("@@@@@ retrievedFilePath = %s @@@@@", recvData.retrievedFilePath);
750         MSG_DEBUG("@@@@@ szMsgID = %s @@@@@", recvData.szMsgID);
751         /* update delivery report, read reply */
752
753         MmsPluginStorage *pStorage = MmsPluginStorage::instance();
754
755         err = pStorage->insertRecipientsInfo(pMsgInfo->msgId, recipients_addr_info, recipients_cnt);
756
757         MSG_DEBUG("Result of insertRecipientsInfo [%d]", err);
758
759         err = pStorage->updateMmsAttrib(pMsgInfo->msgId, &attrib, pMsgInfo->msgType.subType);
760
761         MSG_DEBUG("Result of updateMmsAttrib [%d]", err);
762
763         /* make MmsData & insert multipart */
764         MMSList *multipart_list = NULL;
765         MMS_MULTIPART_DATA_S *pSmilMultipart = NULL;
766
767         MmsMsg *pMmsMsg = NULL;
768         MmsPluginStorage::instance()->getMmsMessage(&pMmsMsg);
769
770         bool bFiltered;
771         MmsPluginAppBase *appBase;
772
773         MMS_DATA_S *pMmsData = MsgMmsCreate();
774         if (pMmsData == NULL) {
775                 MSG_SEC_ERR("Fail to create mms");
776                 goto __CATCH;
777         }
778
779         pMmsData->header = MsgMmsCreateHeader();
780
781         MmsConvertMmsData(pMmsMsg, pMmsData);
782         /* CID 41996 : MmsConvertMmsData always returns true */
783         /*
784         if (MmsConvertMmsData(pMmsMsg, pMmsData) != true) {
785                 MSG_DEBUG("Fail to Compose MMS Message");
786                 goto __CATCH;
787         } */
788
789         bFiltered = checkFilterMmsBody(pMmsData);
790         if (bFiltered == true) {
791                 pMsgInfo->folderId = MSG_SPAMBOX_ID;
792         }
793
794         pSmilMultipart = pMmsData->smil;
795         if (pSmilMultipart) {
796                 MmsPluginStorage::instance()->insertMultipart(pMsgInfo->msgId, pSmilMultipart);
797         }
798
799         multipart_list = pMmsData->multipartlist;
800
801         for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
802                 MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
803                 MmsPluginStorage::instance()->insertMultipart(pMsgInfo->msgId, pMultipart);
804         }
805
806         /* make Preview info for APP */
807         appBase = new MmsPluginAppBase(pMmsData);
808         appBase->makePreviewInfo(pMsgInfo->msgId, false, pRetrievedFilePath);
809         appBase->getFirstPageTextFilePath(pMsgInfo->msgText, sizeof(pMsgInfo->msgText));
810         delete appBase;
811
812         MsgMmsRelease(&pMmsData);
813
814         if (MsgGetFileSize(pRetrievedFilePath, (int *)&pMsgInfo->dataSize) == false) {
815                 MSG_SEC_ERR("Fail to get mms file size [%s]", pRetrievedFilePath);
816                 goto __CATCH;
817         }
818
819 __CATCH: {
820                 MmsMsg *pMsg = NULL;
821                 pStorage->getMmsMessage(&pMsg);
822                 MmsInitHeader();
823                 MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
824                 MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
825                 g_free(filename); filename = NULL;
826                 if (recipients_addr_info) {
827                         delete [] recipients_addr_info;
828                         recipients_addr_info = NULL;
829                 }
830         }
831         MSG_END();
832 }
833 #else /* NEW process RetrieveConf */
834 void MmsPluginInternal::processRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEntity *pRequest, char *pRetrievedFilePath)
835 {
836         MSG_BEGIN();
837
838         msg_error_t err = MSG_SUCCESS;
839
840         pMsgInfo->msgId = pRequest->msgId;
841
842         pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
843         if (pRequest->eMmsPduType == eMMS_RETRIEVE_AUTO_CONF)
844                 pMsgInfo->msgType.subType = MSG_RETRIEVE_AUTOCONF_MMS;
845         else
846                 pMsgInfo->msgType.subType = MSG_RETRIEVE_MANUALCONF_MMS;
847
848         strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
849         strncpy(pRequest->transactionId, mmsHeader.szTrID, MMS_TR_ID_LEN);
850
851         time_t curTime;
852         curTime = time(NULL);
853
854         pMsgInfo->displayTime = curTime;
855
856         if (mmsHeader.retrieveStatus == MMS_RETRSTATUS_OK) {
857                 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
858                 pMsgInfo->folderId = MSG_INBOX_ID;
859         } else {
860                 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
861                 pMsgInfo->folderId = MSG_INBOX_ID;
862                 /* If failed MMS Retrieve, then saved as MMS Noti Ind Message.
863                  * It will changed in MsgHandleMmsConfIncomingMsg */
864 /*              pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS; */
865         }
866
867         char *msisdn = NULL;
868         if (MsgSettingGetString(MSG_SIM_MSISDN, &msisdn) != MSG_SUCCESS) {
869                 MSG_INFO("MsgSettingGetString() is failed");
870         }
871
872         if (mmsHeader.pFrom)
873                 MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
874
875         MSG_MMS_VLD_INFO("%d, MMS Receive %s End %s->%s %s", pMsgInfo->msgId
876                                                                                                                 , (pRequest->eMmsPduType == eMMS_RETRIEVE_AUTO_CONF)?"Auto":"Manual"
877                                                                                                                 , (mmsHeader.pFrom)?mmsHeader.pFrom->szAddr:"YOU"
878                                                                                                                 , (msisdn == NULL)?"ME":msisdn
879                                                                                                                 , (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS)?"Success":"Fail");
880
881         if (msisdn) {
882                 free(msisdn);
883                 msisdn = NULL;
884         }
885
886         pMsgInfo->dataSize = pRequest->getDataLen;
887
888         MmsMsg *pMmsMsg = NULL;
889         MmsPluginStorage::instance()->getMmsMessage(&pMmsMsg);
890
891         MMS_DATA_S *pMmsData = MsgMmsCreate();
892         pMmsData->header = MsgMmsCreateHeader();
893
894         if (MmsConvertMmsData(pMmsMsg, pMmsData) != true) {
895                 MSG_DEBUG("Fail to Compose MMS Message");
896                 goto __CATCH;
897         }
898
899         char *pSerializedData = NULL;
900
901         MsgSerializeMms(pMmsData, &pSerializedData);
902
903         MsgMmsRelease(&pMmsData);
904
905
906         char fileName[MSG_FILENAME_LEN_MAX] = {0};
907         char fileFilePath[MSG_FILEPATH_LEN_MAX] = {0};
908
909         if (MsgCreateFileName(fileName) == false)
910                 goto __CATCH;
911
912         snprintf(fileFilePath, sizeof(fileFilePath), "%s%s", MSG_DATA_PATH, fileName);
913
914         if (!MsgOpenCreateAndOverwriteFile(fileFilePath, (char *)pSerializedData, (int)strlen(pSerializedData))) {
915                 goto __CATCH;
916         }
917
918         snprintf(pMsgInfo->msgData, sizeof(pMsgInfo->msgData), "%s", fileFilePath);
919
920         if (MsgGetFileSize(pRetrievedFilePath, (int *)&pMsgInfo->dataSize) == false) {
921                 MSG_SEC_DEBUG("Fail to get mms file size [%s]", pRetrievedFilePath);
922                 goto __CATCH;
923         }
924
925 __CATCH: {
926                 MmsMsg *pMsg = NULL;
927                 MmsPluginStorage::instance()->getMmsMessage(&pMsg);
928                 MmsInitHeader();
929                 MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
930                 MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
931         }
932         MSG_END();
933 }
934 #endif
935 void MmsPluginInternal::processForwardConf(MSG_MESSAGE_INFO_S *msgInfo, mmsTranQEntity *pRequest)
936 {
937 }
938
939 /* This function Send NotifyRespInd Msg
940  *
941  * @param       pTrID [in] Specifies Transaction ID
942  * @param       iStatus [in] Specifies Msg Status
943  * @param       iReportAllowed [in] Specifies whether to send deliveryReport to sender or not
944  * @return      This function returns true on success, or false on failure.
945  */
946 bool MmsPluginInternal::encodeNotifyRespInd(char *szTrID, msg_delivery_report_status_t iStatus, bool bReportAllowed, char *pSendFilePath)
947 {
948         MSG_BEGIN();
949
950         FILE *pFile = NULL;
951         char pTempFileName[MSG_FILENAME_LEN_MAX+1] = {0};
952         char pTempFilePath[MAX_FULL_PATH_SIZE] = {0};
953
954         if (MsgCreateFileName(pTempFileName) == false)
955                 return false;
956
957         snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, "%s%s.noti.ind", MSG_DATA_PATH, pTempFileName);
958
959         pFile = MsgOpenMMSFile(pTempFilePath);
960
961         if (!pFile) {
962                 MSG_DEBUG("[ERROR] MsgOpenMMSFile fail");
963                 return false;
964         }
965
966         if (MmsEncodeNotiRespInd(pFile, szTrID, iStatus, bReportAllowed) == false) {
967                 MSG_DEBUG("MmsEncodeNotifyRespInd: MmsEncodeNotiRespInd fail");
968                 MsgCloseFile(pFile);
969                 return false;
970         }
971
972         MsgCloseFile(pFile);
973
974         if (pSendFilePath) {
975                 /* CID 41993: replaced size 'MAX_MSG_DATA_LEN+1' with MAX_FULL_PATH_SIZE */
976                 snprintf(pSendFilePath, MAX_FULL_PATH_SIZE, "%s.mms", pTempFilePath);
977         } else {
978                 MSG_DEBUG("[ERROR] pSendFilePath is NULL");
979                 return false;
980         }
981
982         MSG_END();
983
984         return true;
985 }
986
987 /* This function Send AcknowledgeInd Msg
988  *
989  * @param       pTrID [in] Specifies Transaction ID
990  * @param       iReportAllowed [in] Specifies whether to send deliveryReport to sender or not
991  * @return      This function returns true on success, or false on failure.
992  */
993 bool MmsPluginInternal::encodeAckInd(char *szTrID, bool bReportAllowed, char *pSendFilePath)
994 {
995         MSG_BEGIN();
996         FILE *pFile = NULL;
997         char pTempFileName[MSG_FILENAME_LEN_MAX+1] = {0};
998         char pTempFilePath[MAX_FULL_PATH_SIZE] = {0};
999
1000         if (MsgCreateFileName(pTempFileName) == false)
1001                 return false;
1002
1003         snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, "%s%s.ack.ind", MSG_DATA_PATH, pTempFileName);
1004
1005         pFile = MsgOpenMMSFile(pTempFilePath);
1006         if (!pFile) {
1007                 MSG_ERR("MsgOpenMMSFile fail \n");
1008                 return false;
1009         }
1010
1011         if (MmsEncodeAckInd(pFile, szTrID, bReportAllowed) == false) {
1012                 MSG_ERR("MmsEncodeAckInd: MmsEncodeAckInd fail \n");
1013                 MsgCloseFile(pFile);
1014                 return false;
1015         }
1016
1017         MsgCloseFile(pFile);
1018
1019         if (pSendFilePath) {
1020                 snprintf(pSendFilePath, MAX_MSG_DATA_LEN+1, "%s.mms", pTempFilePath);
1021         } else {
1022                 MSG_ERR("pSendFilePath is NULL");
1023                 return false;
1024         }
1025
1026         MSG_END();
1027
1028         return true;
1029 }
1030
1031 bool MmsPluginInternal::checkRejectNotiInd(int roamState, bool bReportAllowed, char *pSendFilePath)
1032 {
1033         MSG_BEGIN();
1034         MSG_MMS_HOME_RETRIEVE_TYPE_T retrieveType;
1035         bool bRejectAnonymous;
1036         bool bRejectAdvertisement;
1037
1038         if (MsgSettingGetBool(MMS_RECV_REJECT_UNKNOWN, &bRejectAnonymous) != MSG_SUCCESS)
1039                 MSG_INFO("MsgSettingGetBool() is failed");
1040
1041         if (MsgSettingGetBool(MMS_RECV_REJECT_ADVERTISE, &bRejectAdvertisement) != MSG_SUCCESS)
1042                 MSG_INFO("MsgSettingGetBool() is failed");
1043
1044         /* Anonymous Reject */
1045         if (bRejectAnonymous &&
1046                 (mmsHeader.pFrom == NULL || mmsHeader.pFrom->szAddr[0] == '\0')) {
1047                 MSG_DEBUG("Anonymous Reject... ");
1048                 encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
1049
1050                 return true;
1051         }
1052
1053         /* Advertisement Reject */
1054         if (bRejectAdvertisement && mmsHeader.msgClass == MMS_MSGCLASS_ADVERTISEMENT) {
1055                 MSG_DEBUG("Advertisement Reject... ");
1056                 encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
1057
1058                 return true;
1059         }
1060
1061         /* Message Reject - Roaming Case */
1062         int tmpVal = 0;
1063         if (roamState == VCONFKEY_TELEPHONY_SVC_ROAM_ON) {
1064                 if (MsgSettingGetInt(MMS_RECV_ABROAD_NETWORK, &tmpVal) != MSG_SUCCESS) {
1065                         MSG_INFO("MsgSettingGetInt() is failed");
1066                 }
1067                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)tmpVal;
1068                 if (retrieveType == MSG_ABROAD_REJECT) {
1069                         MSG_DEBUG("Abroad_Network : Notification Reject... ");
1070                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
1071
1072                         return true;
1073                 }
1074         } else {
1075                 if (MsgSettingGetInt(MMS_RECV_HOME_NETWORK, &tmpVal) != MSG_SUCCESS) {
1076                         MSG_INFO("MsgSettingGetInt() is failed");
1077                 }
1078                 retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)tmpVal;
1079                 if (retrieveType == MSG_HOME_REJECT) {
1080                         MSG_DEBUG("Home_Network : Notification Reject... ");
1081                         encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_REJECTED, bReportAllowed, pSendFilePath);
1082
1083                         return true;
1084                 }
1085         }
1086
1087         /* Duplicate MMS notification */
1088         int msgId = 0;
1089
1090         msgId = MmsPluginStorage::instance()->checkDuplicateNotification(mmsHeader.szTrID, mmsHeader.szContentLocation);
1091
1092         MSG_DEBUG("Msg Id = %d", msgId);
1093         if (msgId > 0)
1094                 return true;
1095
1096         /* Not Rejected */
1097         MSG_END();
1098         return false;
1099 }
1100
1101
1102 bool MmsPluginInternal::checkFilterMmsBody(MMS_DATA_S *pMmsData)
1103 {
1104         if (pMmsData == NULL)
1105                 return false;
1106
1107         bool bFiltered = false;
1108         MMS_PAGE_S *pPage = NULL;
1109         MMS_MEDIA_S *pMedia = NULL;
1110         char filePath[MSG_FILEPATH_LEN_MAX + 1];
1111         gchar *fileContent = NULL;
1112         MsgDbHandler *dbHandle = getDbHandle();
1113         MimeType mimeType = MIME_UNKNOWN;
1114
1115         MMS_MESSAGE_DATA_S *mmsMsg = NULL;
1116         unique_ptr<MMS_MESSAGE_DATA_S*, void(*)(MMS_MESSAGE_DATA_S**)> buf(&mmsMsg, unique_ptr_deleter);
1117         mmsMsg = (MMS_MESSAGE_DATA_S *)new char[sizeof(MMS_MESSAGE_DATA_S)];
1118         memset(mmsMsg, 0x00, sizeof(MMS_MESSAGE_DATA_S));
1119
1120         MsgMmsConvertMmsDataToMmsMessageData(pMmsData, mmsMsg);
1121
1122         /* Get the text data from the 1st slide. */
1123         if (mmsMsg->pageCnt <= 0) {
1124                 MSG_WARN("pageCnt : %d", mmsMsg->pageCnt);
1125                 MsgMmsReleaseMmsLists(mmsMsg);
1126                 return false;
1127         }
1128
1129         pPage = _MsgMmsGetPage(mmsMsg, 0);
1130
1131         if (!pPage) {
1132                 MSG_WARN("page is NULL");
1133                 MsgMmsReleaseMmsLists(mmsMsg);
1134                 return false;
1135         }
1136
1137         for (int j = 0; j < pPage->mediaCnt; ++j) {
1138                 pMedia = _MsgMmsGetMedia(pPage, j);
1139
1140                 if (pMedia && pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
1141                         MsgGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
1142
1143                         if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD || mimeType == MIME_TEXT_X_VTODO || mimeType == MIME_TEXT_X_VNOTE) {
1144                                 MSG_SEC_DEBUG("Media Type is Text, but Vobject file [%s]", pMedia->szFilePath);
1145                         } else {
1146                                 strncpy(filePath, pMedia->szFilePath, MSG_FILEPATH_LEN_MAX);
1147
1148                                 g_file_get_contents((const gchar*)filePath, (gchar**)&fileContent, NULL, NULL);
1149
1150                                 bFiltered = MsgCheckFilterByWord(dbHandle, (const char *)fileContent);
1151
1152                                 g_free(fileContent);
1153                                 fileContent = NULL;
1154
1155                                 if (bFiltered == true)
1156                                         break;
1157                         }
1158                 }
1159         }
1160
1161         MsgMmsReleaseMmsLists(mmsMsg);
1162
1163         return bFiltered;
1164 }
1165
1166 bool MmsPluginInternal::getMmsReport(MmsReport mmsReport)
1167 {
1168         bool result = false;
1169
1170         if (mmsReport == MMS_REPORT_YES)
1171                 result = true;
1172         else if (mmsReport == MMS_REPORT_NO)
1173                 result = false;
1174
1175         return result;
1176 }
1177
1178 const char *MmsPluginInternal::getMmsDeliveryStatus(msg_delivery_report_status_t deliveryStatus)
1179 {
1180         MSG_DEBUG("msgStatus= %d", deliveryStatus);
1181
1182         switch (deliveryStatus) {
1183         case MSG_DELIVERY_REPORT_EXPIRED:
1184                 return "expired.";
1185         case MSG_DELIVERY_REPORT_REJECTED:
1186                 return "rejected.";
1187         case MSG_DELIVERY_REPORT_UNREACHABLE:
1188                 return "unreachable.";
1189         case MSG_DELIVERY_REPORT_UNRECOGNISED:
1190                 return "unrecognised.";
1191         case MSG_DELIVERY_REPORT_SUCCESS:
1192                 return "delivered.";
1193         default:
1194                 return "delivery failed.";
1195         }
1196 }
1197
1198 const char *MmsPluginInternal::getMmsReadStatus(msg_read_report_status_t readStatus)
1199 {
1200         switch (readStatus) {
1201         case MSG_READ_REPORT_IS_READ:
1202                 return "message is read.";
1203         case MSG_READ_REPORT_IS_DELETED:
1204                 return "message is deleted.";
1205         default:
1206                 return "read status is none.";
1207         }
1208 }
1209