modify msg-service to support dpm feature
[platform/core/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerTransport.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 <time.h>
18
19 #include <bundle.h>
20 #include <eventsystem.h>
21
22 #include "MsgDebug.h"
23 #include "MsgException.h"
24 #include "MsgUtilFile.h"
25 #include "MsgContact.h"
26 #include "MsgGconfWrapper.h"
27 #include "MsgNotificationWrapper.h"
28 #include "MsgUtilFunction.h"
29 #include "MsgSubmitHandler.h"
30 #include "MsgDeliverHandler.h"
31 #include "MsgStorageHandler.h"
32 #include "MsgTransManager.h"
33 #include "MsgPluginManager.h"
34 #include "MsgUtilStorage.h"
35 #include "MsgAlarm.h"
36 #include "MsgCmdHandler.h"
37 #include "MsgDevicedWrapper.h"
38 #include "MsgMmsMessage.h"
39
40
41 /*==================================================================================================
42                                      FUNCTION IMPLEMENTATION
43 ==================================================================================================*/
44 int MsgSubmitReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
45 {
46         msg_error_t err = MSG_SUCCESS;
47         bool bNewMsg = true;
48
49         if (!pCmd || !ppEvent) {
50                 MSG_DEBUG("pCmd or ppEvent is null");
51                 return 0;
52         }
53
54         int ret[3];
55         int eventSize = 0;
56
57         MSG_REQUEST_INFO_S reqInfo = {0, };
58         MSG_PROXY_INFO_S proxyInfo = {0, };
59
60         reqInfo.msgInfo.addressList = NULL;
61         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&reqInfo.msgInfo.addressList, unique_ptr_deleter);
62
63         /* Get Message Request */
64         memcpy(&reqInfo.reqId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_request_id_t));
65
66         /* Storing Request ID, Proxy Info for Sent Status CNF */
67         memcpy(&proxyInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)), sizeof(MSG_PROXY_INFO_S));
68
69         MsgDecodeMsgInfo((char *)(pCmd->cmdData+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)), &reqInfo.msgInfo, &reqInfo.sendOptInfo);
70
71
72         if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE
73                         && reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_MMS) {
74                 int fd = 0;
75                 memcpy(&fd, pCmd->cmdCookie, sizeof(int));
76                 if (reqInfo.msgInfo.bTextSms == false) {
77                         err = MsgMmsCheckFilepathSmack(fd, reqInfo.msgInfo.msgData);
78                         if (err != MSG_SUCCESS) {
79                                 return MsgMakeEvent(NULL, 0, MSG_EVENT_SUBMIT_REQ, err, (void**)ppEvent);
80                         }
81                 }
82         }
83
84         if (reqInfo.msgInfo.msgId > 0)
85                 bNewMsg = false;
86
87         /* Submit Request */
88         err = MsgSubmitReq(&reqInfo, false);
89
90         if (err == MSG_SUCCESS) {
91                 MSG_DEBUG("Command Handle Success : MsgSubmitReq()");
92         } else {
93                 MSG_DEBUG("Command Handle Fail : MsgSubmitReq()");
94         }
95
96         int reqId = reqInfo.reqId;
97         proxyInfo.sentMsgId = reqInfo.msgInfo.msgId;
98
99         MSG_DEBUG("REQID: %d, MSGID: %d", reqId, proxyInfo.sentMsgId);
100
101         if (reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE) {
102                 MsgTransactionManager::instance()->insertSentMsg(reqId, &proxyInfo);
103         } else if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE) {
104                 /* Retrieve MMS shall not be kept in sentMsg */
105                 if ((reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_MMS) ||
106                         (reqInfo.msgInfo.msgType.subType == MSG_FORWARD_MMS) ||
107                         (reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS))
108                 MsgTransactionManager::instance()->insertSentMsg(reqId, &proxyInfo);
109         }
110
111         /* keep transaction Id list for distinguish java MMS sent msg when sendconf received */
112         if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE &&
113                 reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS) {
114                 MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S trId = {0};
115                 memcpy(&trId.id, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)+sizeof(MSG_PROXY_INFO_S)), MMS_TR_ID_LEN);
116
117                 char* pFileName;
118                 pFileName = strstr(reqInfo.msgInfo.msgData, "MSG_");
119                 strncpy(trId.pduFileName, pFileName, MAX_COMMON_INFO_SIZE);
120
121                 MSG_SEC_DEBUG("java MMS msg trId:%s filepath:%s", trId.id, reqInfo.msgInfo.msgData);
122
123                 MsgTransactionManager* tm = MsgTransactionManager::instance();
124                 tm->setJavaMMSList(&trId);
125         }
126
127                 ret[0] = reqId;
128                 ret[1] = reqInfo.msgInfo.msgId;
129                 ret[2] = reqInfo.msgInfo.threadId;
130
131         /* Make Event Data */
132         eventSize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_SUBMIT_REQ, err, (void**)ppEvent);
133
134         /* reject_msg_support */
135         if (((reqInfo.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS) &&
136                  (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE)))
137                 err = MsgStoDeleteMessage(reqInfo.msgInfo.msgId, true);
138
139         /** send storage CB */
140         msg_id_list_s msgIdList;
141         msg_message_id_t msgIds[1];
142         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
143
144         msgIdList.nCount = 1;
145         msgIds[0] = reqInfo.msgInfo.msgId;
146         msgIdList.msgIdList = msgIds;
147
148         if ((err == MSG_SUCCESS || err != MSG_ERR_PLUGIN_STORAGE) && reqInfo.msgInfo.msgPort.valid == false) {
149                 if (bNewMsg) {
150                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
151                 } else {
152                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
153                 }
154         } else {
155                 MSG_DEBUG("No need to broadcast storage change CB");
156         }
157
158         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
159
160         MsgStoAutoDeleteConversation(reqInfo.msgInfo.threadId, &msgIdList);
161         if (msgIdList.msgIdList) {
162                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
163                 delete [] (char*)msgIdList.msgIdList;
164         }
165
166         return eventSize;
167 }
168
169
170 int MsgRegSentStatusCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
171 {
172         /* input check */
173         if (!pCmd || !ppEvent) {
174                 MSG_DEBUG("pCmd or ppEvent is null");
175                 return 0;
176         }
177
178         /* Get Message Request */
179         int listenerFd = 0;
180         memcpy(&listenerFd, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
181         MSG_DEBUG("Registering sent status CB for %d", listenerFd);
182
183         /* storing dst fd in list */
184         MsgTransactionManager::instance()->setSentStatusCB(listenerFd);
185
186         /* Make Event Data */
187         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SENT_STATUS_CB, MSG_SUCCESS, (void**)ppEvent);
188
189         return eventSize;
190 }
191
192
193 int MsgRegIncomingMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
194 {
195         /* input check */
196         if (!pCmd || !ppEvent) {
197                 MSG_DEBUG("pCmd or ppEvent is null");
198                 return 0;
199         }
200
201         /* Get Message Request */
202         MSG_CMD_REG_INCOMING_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_MSG_CB_S*) pCmd->cmdData;
203         MSG_DEBUG("Registering incoming SMS CB for fd %d mType %d port %d", pCmdData->listenerFd, pCmdData->msgType, pCmdData->port);
204
205         /* storing dst fd in list */
206         MsgTransactionManager::instance()->setIncomingMsgCB(pCmdData);
207
208         /* Make Event Data */
209         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
210
211         return eventSize;
212 }
213
214
215 int MsgRegIncomingMMSConfMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
216 {
217         /* input check */
218         if (!pCmd || !ppEvent) {
219                 MSG_DEBUG("pCmd or ppEvent is null");
220                 return 0;
221         }
222
223         /* Get Message Request */
224         MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S*) pCmd->cmdData;
225         MSG_DEBUG("Registering incoming MMS Conf CB for fd:%d mType:%d appId:%s", pCmdData->listenerFd, pCmdData->msgType, pCmdData->appId);
226
227         /* storing dst fd in list */
228         MsgTransactionManager::instance()->setMMSConfMsgCB(pCmdData);
229
230         /* Make Event Data */
231         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
232
233         return eventSize;
234 }
235
236 int MsgRegIncomingPushMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
237 {
238         /* input check */
239         if (!pCmd || !ppEvent) {
240                 MSG_DEBUG("pCmd or ppEvent is null");
241                 return 0;
242         }
243
244         /* Get Message Request */
245         MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S*) pCmd->cmdData;
246         MSG_DEBUG("Registering incoming Push Msg CB for fd:%d mType:%d appId:%s", pCmdData->listenerFd, pCmdData->msgType, pCmdData->appId);
247
248         /* storing dst fd in list */
249         MsgTransactionManager::instance()->setPushMsgCB(pCmdData);
250         /* MsgTransactionManager::instance()->sendPendigPushMsg(pCmdData); */
251
252
253         /* Make Event Data */
254         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_PUSH_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
255
256         return eventSize;
257 }
258
259
260
261 int MsgRegIncomingCBMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
262 {
263         /* input check */
264         if (!pCmd || !ppEvent) {
265                 MSG_DEBUG("pCmd or ppEvent is null");
266                 return 0;
267         }
268
269         /* Get Message Request */
270         MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_CB_MSG_CB_S*) pCmd->cmdData;
271         MSG_DEBUG("Registering incoming CB Msg CB for fd:%d mType:%d: bSave: %d", pCmdData->listenerFd, pCmdData->msgType, pCmdData->bsave);
272
273         /* storing dst fd in list */
274         MsgTransactionManager::instance()->setCBMsgCB(pCmdData);
275
276         /* Make Event Data */
277         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_CB_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
278
279         return eventSize;
280 }
281
282
283 int MsgRegIncomingSyncMLMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
284 {
285         /* input check */
286         if (!pCmd || !ppEvent) {
287                 MSG_DEBUG("pCmd or ppEvent is null");
288                 return 0;
289         }
290
291         /* Get Message Request */
292         MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S*) pCmd->cmdData;
293         MSG_DEBUG("Registering incoming Sync ML Msg CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
294
295         /* storing dst fd in list */
296         MsgTransactionManager::instance()->setSyncMLMsgCB(pCmdData);
297
298         /* Make Event Data */
299         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
300
301         return eventSize;
302 }
303
304
305 int MsgRegIncomingLBSMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
306 {
307         /* input check */
308         if (!pCmd || !ppEvent) {
309                 MSG_DEBUG("pCmd or ppEvent is null");
310                 return 0;
311         }
312
313         /* Get Message Request */
314         MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_LBS_MSG_CB_S*) pCmd->cmdData;
315         MSG_DEBUG("Registering incoming LBS Msg CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
316
317         /* storing dst fd in list */
318         MsgTransactionManager::instance()->setLBSMsgCB(pCmdData);
319
320         /* Make Event Data */
321         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_LBS_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
322
323         return eventSize;
324 }
325
326
327 int MsgRegSyncMLMsgOperationCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
328 {
329         /* input check */
330         if (!pCmd || !ppEvent) {
331                 MSG_DEBUG("pCmd or ppEvent is null");
332                 return 0;
333         }
334
335         /* Get Message Request */
336         MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCmdData = (MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S*) pCmd->cmdData;
337         MSG_DEBUG("Registering SyncML Msg ooperation CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
338
339         /* storing dst fd in list */
340         MsgTransactionManager::instance()->setSyncMLMsgOperationCB(pCmdData);
341
342         /* Make Event Data */
343         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB, MSG_SUCCESS, (void**)ppEvent);
344
345         return eventSize;
346 }
347
348
349 int MsgRegStorageChangeCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
350 {
351         /* input check */
352         if (!pCmd || !ppEvent) {
353                 MSG_DEBUG("pCmd or ppEvent is null");
354                 return 0;
355         }
356
357         /* Get Message Request */
358         int listenerFd = 0;
359         memcpy(&listenerFd, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
360         MSG_DEBUG("Registering storage change CB for %d", listenerFd);
361
362         /* storing dst fd in list */
363         MsgTransactionManager::instance()->setStorageChangeCB(listenerFd);
364
365         /* Make Event Data */
366         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_STORAGE_CHANGE_CB, MsgException::SUCCESS, (void**)ppEvent);
367
368         return eventSize;
369 }
370
371
372 int MsgRegIncomingReportMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
373 {
374         /* input check */
375         if (!pCmd || !ppEvent) {
376                 MSG_DEBUG("pCmd or ppEvent is null");
377                 return 0;
378         }
379
380         /* Get Message Request */
381         int listenerFd = 0;
382         memcpy(&listenerFd, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
383         MSG_DEBUG("Registering report msg incoming CB for %d", listenerFd);
384
385         /* storing dst fd in list */
386         MsgTransactionManager::instance()->setReportMsgCB(listenerFd);
387
388         /* Make Event Data */
389         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_REPORT_MSG_INCOMING_CB, MsgException::SUCCESS, (void**)ppEvent);
390
391         return eventSize;
392 }
393
394
395 int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
396 {
397         /* input check */
398         if (!pCmd || !ppEvent) {
399                 MSG_DEBUG("pCmd or ppEvent is null");
400                 return 0;
401         }
402
403         /* Get Message Request */
404         MSG_SENT_STATUS_S* pStatus = (MSG_SENT_STATUS_S*) pCmd->cmdData;
405
406         MSG_DEBUG("REQID %d, STATUS %d", pStatus->reqId, pStatus->status);
407
408         /* storing dst fd in list */
409         MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(pStatus->reqId);
410
411         /* when no sent status cb is found */
412         if (!prxInfo) {
413                 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
414         }
415
416         MSG_DEBUG("REQID %d, listenerFD %d, handleAddr %x, msgId %d", pStatus->reqId, prxInfo->listenerFd, prxInfo->handleAddr, prxInfo->sentMsgId);
417
418         /* if APP send and quit(not exist at this time), don't send the data up. */
419         if (prxInfo->handleAddr == 0) {
420                 /* just making data which will be passed to plugin. it indicates "handling evt success" */
421                 MsgTransactionManager::instance()->delProxyInfo(pStatus->reqId);
422
423                 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
424         }
425
426         unsigned long ret[3] = {0}; /* reqid, status, object */
427
428         ret[0] = (unsigned long)pStatus->reqId;
429         ret[1] = (unsigned long)pStatus->status;
430         ret[2] = prxInfo->handleAddr;
431
432         /* Make Event Data for APP */
433         int eventSize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
434
435         /* Send to listener thread, here */
436         MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventSize);
437
438         MsgTransactionManager::instance()->delProxyInfo(pStatus->reqId);
439
440         return eventSize;
441 }
442
443
444 int MsgIncomingMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
445 {
446         MSG_BEGIN();
447
448         msg_error_t err = MSG_SUCCESS;
449         int eventSize = 0;
450         bool sendNoti = true;
451         bool isClass2msg = false;
452
453         /* input check */
454         if (!pCmd || !ppEvent) {
455                 MSG_DEBUG("pCmd or ppEvent is null");
456                 return 0;
457         }
458
459         /* Get Incoming Message */
460         MSG_MESSAGE_INFO_S msgInfo;
461         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
462
463         msgInfo.addressList = NULL;
464         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
465
466         MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo);
467
468         /* broadcast to listener threads, here */
469         msg_id_list_s msgIdList;
470         msg_message_id_t msgIds[2];
471         msg_message_id_t class2msgId = 0;
472         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
473
474 #ifdef MSG_NOTI_INTEGRATION
475         if (msgInfo.msgType.classType == MSG_CLASS_2) {
476                 class2msgId = msgInfo.msgId;
477                 isClass2msg = true;
478         }
479 #endif
480
481         /* normal process */
482         err = MsgHandleIncomingMsg(&msgInfo, &sendNoti);
483
484         if (msgInfo.msgType.mainType == MSG_SMS_TYPE) {
485                 /* Send system event */
486                 bundle *b = NULL;
487                 b = bundle_create();
488                 if (b) {
489                         char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
490                         snprintf(msgId, sizeof(msgId), "%u", msgInfo.msgId);
491                         bundle_add_str(b, EVT_KEY_MSG_ID, msgId);
492
493                         if (msgInfo.msgType.subType >= MSG_WAP_SI_SMS && msgInfo.msgType.subType <= MSG_WAP_CO_SMS) {
494                                 bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_PUSH);
495                         } else {
496                                 bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_SMS);
497                                 bundle_add_str(b, "cmd", "incoming_msg");
498                                 msg_launch_app(MSG_MGR_APP_ID, b);
499                         }
500                         eventsystem_send_system_event(SYS_EVENT_INCOMMING_MSG, b);
501                         bundle_free(b);
502                 }
503         }
504
505         if (isClass2msg == true) {
506                 msgIdList.nCount = 2;
507                 msgIds[0] = class2msgId;
508                 msgIds[1] = msgInfo.msgId;
509                 msgIdList.msgIdList = msgIds;
510                 isClass2msg = false;
511         } else {
512                 msgIdList.nCount = 1;
513                 msgIds[0] = msgInfo.msgId;
514                 msgIdList.msgIdList = msgIds;
515         }
516
517         if (sendNoti == true) {
518                 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
519                 if (msgInfo.msgType.subType > MSG_TYPE0_SMS && msgInfo.msgType.subType < MSG_WAP_SI_SMS) { /* if it is replacement message. */
520                         MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
521                 } else {
522                         MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
523                 }
524         } else if (msgInfo.msgPort.valid || (msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) {
525                 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
526         } else if (msgInfo.folderId == MSG_SPAMBOX_ID || msgInfo.bRestricted == true) {
527                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
528         } else if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS || msgInfo.msgType.subType == MSG_DELIVERYIND_MMS) {
529                 MsgTransactionManager::instance()->broadcastReportMsgCB(err, MSG_REPORT_TYPE_DELIVERY, &msgInfo);
530         } else if (msgInfo.msgType.subType == MSG_READORGIND_MMS) {
531                 MsgTransactionManager::instance()->broadcastReportMsgCB(err, MSG_REPORT_TYPE_READ, &msgInfo);
532         }
533
534         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
535         MsgStoAutoDeleteConversation(msgInfo.threadId, &msgIdList);
536         if (msgIdList.msgIdList) {
537                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
538                 delete [] (char*)msgIdList.msgIdList;
539         }
540
541 #ifdef FEATURE_SMS_CDMA
542         eventSize = MsgMakeEvent(&msgInfo.msgId, sizeof(msg_message_id_t), MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
543 #else
544         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
545 #endif
546
547         if (msgInfo.bTextSms == false) {
548                 MsgDeleteFile(msgInfo.msgData); /*ipc */
549                 memset(msgInfo.msgData, 0x00, sizeof(msgInfo.msgData));
550         }
551
552         MSG_END();
553
554         return eventSize;
555 }
556
557 int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
558 {
559         MSG_BEGIN();
560
561         if (!pCmd || !ppEvent) {
562                 MSG_DEBUG("pCmd or ppEvent is null");
563                 return 0;
564         }
565
566         msg_error_t err = MSG_SUCCESS;
567         int eventsize = 0;
568
569         MSG_MESSAGE_INFO_S msgInfo;
570         msg_request_id_t reqID;
571
572         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
573
574         msgInfo.addressList = NULL;
575         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
576
577         memcpy(&reqID, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_request_id_t));
578         MsgDecodeMsgInfo((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t), &msgInfo);
579
580         MSG_DEBUG(" pMsg = %s, pReqId = %d ", msgInfo.msgData, reqID);
581         MSG_DEBUG(" msgtype subtype is [%d]", msgInfo.msgType.subType);
582
583         /* For Storage change callback */
584         msg_id_list_s msgIdList;
585         msg_message_id_t msgIds[1];
586         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
587
588         msgIdList.nCount = 1;
589         msgIds[0] = msgInfo.msgId;
590         msgIdList.msgIdList = msgIds;
591
592         MsgDbHandler *dbHandle = getDbHandle();
593         int tmpAddrCnt = 0;
594         MSG_ADDRESS_INFO_S *tmpAddr = NULL;
595         err = MsgStoGetAddressByMsgId(dbHandle, msgInfo.msgId, &tmpAddrCnt, &tmpAddr);
596         if (err != MSG_SUCCESS) {
597                 MSG_DEBUG("MsgStoGetAddressByMsgId() fail.");
598         }
599
600         if (msgInfo.msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || msgInfo.msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
601                 if (msgInfo.networkStatus != MSG_NETWORK_RETRIEVE_SUCCESS) {
602                         if (msgInfo.addressList) {
603                                 delete[] msgInfo.addressList;
604                                 msgInfo.addressList = NULL;
605                         }
606
607                         msgInfo.addressList = tmpAddr;
608                         msgInfo.nAddressCnt = tmpAddrCnt;
609                 } else {
610                         if (tmpAddr) {
611                                 delete [] tmpAddr;
612                                 tmpAddr = NULL;
613                         }
614                 }
615
616                 msg_thread_id_t prev_conv_id = MsgGetThreadId(dbHandle, msgInfo.msgId);
617                 MSG_SUB_TYPE_T recv_sub_type = msgInfo.msgType.subType; /* Check retrieve mode to determine broadcast type */
618
619                 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
620
621                 if (err != MSG_SUCCESS) {
622                         MSG_DEBUG("MsgHandleMmsConfIncomingMsg failed.");
623                         return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
624                 }
625
626                 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
627
628                 if (pMmsRecvData->msgAppId.valid == true) {
629                         MSG_DEBUG("valid : %d, appId : %s", pMmsRecvData->msgAppId.valid, pMmsRecvData->msgAppId.appId);
630                 } else {
631                         msgInfo.bTextSms = true;
632                         msgInfo.dataSize = 0 ;
633                         memset(msgInfo.msgData, 0x00, sizeof(MMS_RECV_DATA_S));
634                 }
635
636                 /* broadcast to listener threads, here */
637                 MsgTransactionManager::instance()->broadcastMMSConfCB(msgInfo.networkStatus, &msgInfo, pMmsRecvData);
638
639                 /* determine broadcast type with retrieve mode */
640                 if (recv_sub_type == MSG_RETRIEVE_AUTOCONF_MMS) {
641                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
642                 } else {
643                         if (prev_conv_id == msgInfo.threadId
644                                 || msgInfo.networkStatus == MSG_NETWORK_RETRIEVE_FAIL || msgInfo.networkStatus == MSG_NETWORK_RETRIEVE_PENDING) {
645                                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
646                         } else {
647                                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
648                                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
649                         }
650                 }
651
652                 /* make return event */
653                 eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, MSG_SUCCESS, (void**)ppEvent);
654
655         } else if (msgInfo.msgType.subType == MSG_SENDREQ_MMS || msgInfo.msgType.subType == MSG_SENDCONF_MMS) {
656                 if (msgInfo.addressList) {
657                         delete[] msgInfo.addressList;
658                         msgInfo.addressList = NULL;
659                 }
660
661                 msgInfo.addressList = tmpAddr;
662                 msgInfo.nAddressCnt = tmpAddrCnt;
663
664                 MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(reqID);
665
666                 /* when no sent status cb is found */
667                 if (prxInfo) {
668                         /* No need to update javaMMS sent messages */
669                         javamms_list& listenerList = MsgTransactionManager::instance()->getJavaMMSList();
670                         javamms_list::iterator it = listenerList.begin();
671
672                         MSG_DEBUG("listenerList size:%d ", listenerList.size());
673
674                         if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL && msgInfo.msgType.subType == MSG_SENDREQ_MMS) {
675                                 for ( ; it != listenerList.end() ; it++) {
676                                         if (strstr(it->pduFileName, "JAVA")) {
677                                                 MSG_SEC_DEBUG("JAVA MMS fileName:%s", it->pduFileName);
678                                                 MsgDeleteFile(it->pduFileName);         /* ipc */
679                                                 listenerList.erase(it);
680                                                 goto __BYPASS_UPDATE;
681                                         }
682                                 }
683                         } else {
684                                 /*msgData has MMS_RECV_DATA_S */
685                                 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
686
687                                 for ( ; it != listenerList.end() ; it++) {
688                                         if (!strcmp(it->id, pMmsRecvData->szTrID)) {
689                                                 MSG_SEC_DEBUG("find sent JAVA MMS message trId:%s from listener list trId:%s", pMmsRecvData->szTrID, it->id);
690                                                 MsgDeleteFile(it->pduFileName); /* ipc */
691                                                 listenerList.erase(it);
692                                                 goto __BYPASS_UPDATE;
693                                         }
694                                 }
695                         }
696                 } else {
697                         MSG_DEBUG("prxInfo is NULL");
698                 }
699
700                 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
701
702                 if (err != MSG_SUCCESS) {
703                         return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
704                 }
705
706 __BYPASS_UPDATE:
707                 if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL) {
708                         MSG_DEBUG("message-dialog: send fail");
709                         MsgInsertTicker("Sending multimedia message failed.", SENDING_MULTIMEDIA_MESSAGE_FAILED, true, msgInfo.msgId);
710                 } else {
711                         MSG_DEBUG("message-dialog: send success");
712
713 #if 0 /* disabled as per UX request to not show success notification : 2015. 09. 18 */
714                         bool bTTS = false;
715
716                         if (MsgSettingGetBool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &bTTS) != MSG_SUCCESS) {
717                                 MSG_DEBUG("MsgSettingGetBool is failed.");
718                         }
719
720                         if (bTTS) {
721                                 MsgInsertTicker("Multimedia message sent.", MULTIMEDIA_MESSAGE_SENT, false, 0);
722                         }
723
724 #endif
725 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
726                         MSG_SEC_DEBUG("Enter MsgAddPhoneLog() : msgInfo.addressList[0].addressVal [%s]", msgInfo.addressList[0].addressVal);
727                         MsgAddPhoneLog(&msgInfo);
728                         /* Send system event */
729                         bundle *b = NULL;
730                         b = bundle_create();
731                         if (b) {
732                                 bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_MMS);
733                                 char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
734                                 snprintf(msgId, sizeof(msgId), "%u", msgInfo.msgId);
735                                 bundle_add_str(b, EVT_KEY_MSG_ID, msgId);
736                                 eventsystem_send_system_event(SYS_EVENT_INCOMMING_MSG, b);
737                                 bundle_add_str(b, "cmd", "incoming_msg");
738                                 msg_launch_app(MSG_MGR_APP_ID, b);
739                                 bundle_free(b);
740                         }
741 #endif /*MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
742                 }
743
744                 if (prxInfo) {
745                         if (prxInfo->handleAddr == 0) {
746                                 /* just making data which will be passed to plugin. it indicates "handling evt success" */
747                                 MsgTransactionManager::instance()->delProxyInfo(reqID);
748                         } else {
749                                 unsigned long ret[3] = {0}; /* reqid, status, object */
750
751                                 ret[0] = (unsigned long)reqID;
752                                 ret[1] = (unsigned long)msgInfo.networkStatus;
753                                 ret[2] = prxInfo->handleAddr;
754
755                                 /* Make Event Data for APP */
756                                 eventsize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
757
758                                 /* Send to listener thread, here */
759                                 MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventsize);
760
761                                 MsgTransactionManager::instance()->delProxyInfo(reqID);
762                         }
763                 }
764
765                 eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, MSG_SUCCESS, (void**)ppEvent);
766                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
767         } else {
768                 /*To avoid prevent memory leak.. this case will not occur. eventsize will be return as 0. */
769                 if (tmpAddr) {
770                         delete[] tmpAddr;
771                         tmpAddr = NULL;
772                 }
773         }
774
775         MSG_END();
776         return eventsize;
777 }
778
779 int MsgIncomingPushMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
780 {
781         MSG_BEGIN();
782
783         int eventSize = 0;
784
785         /* input check */
786         if (!pCmd || !ppEvent) {
787                 MSG_DEBUG("pCmd or ppEvent is null");
788                 return 0;
789         }
790
791         MSG_PUSH_MESSAGE_DATA_S pushData;
792         memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
793
794         /* Get Incoming Message */
795         memcpy(&pushData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_PUSH_MESSAGE_DATA_S));
796
797
798
799         /* broadcast to listener threads, here */
800         MsgTransactionManager::instance()->broadcastPushMsgCB(MSG_SUCCESS, &pushData);
801
802         /* Make Event Data */
803         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
804
805         MSG_END();
806         return eventSize;
807 }
808
809 int MsgIncomingCBMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
810 {
811         MSG_BEGIN();
812
813         msg_error_t err = MSG_SUCCESS;
814         int eventSize = 0;
815
816         /* input check */
817         if (!pCmd || !ppEvent) {
818                 MSG_DEBUG("pCmd or ppEvent is null");
819                 return 0;
820         }
821
822         /* Get Incoming Message */
823         MSG_CB_MSG_S cbMsg;
824         memset(&cbMsg, 0x00, sizeof(MSG_CB_MSG_S));
825
826         memcpy(&cbMsg, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_CB_MSG_S));
827
828         MSG_MESSAGE_INFO_S msgInfo;
829         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
830
831         msgInfo.addressList = NULL;
832         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
833
834         MsgDecodeMsgInfo((char *)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_CB_MSG_S), &msgInfo);
835
836         MSG_DEBUG("CB MSG ADDRESS COUNT=%d", msgInfo.nAddressCnt);
837
838         if (MsgStoAddCBMsg(&msgInfo) != MSG_SUCCESS) {
839                 MSG_DEBUG("MsgStoAddCBMsg is fail");
840         }
841
842         if (msgInfo.msgType.classType == MSG_CLASS_0) {
843                 MsgLaunchClass0(msgInfo.msgId);
844                 MsgSoundPlayStart(&(msgInfo.addressList[0]), MSG_SOUND_PLAY_USER);
845         } else {
846                 MsgInsertNotification(&msgInfo);
847         }
848
849         MsgChangePmState();
850
851         msg_id_list_s msgIdList;
852         msg_message_id_t msgIds[1];
853         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
854
855         msgIdList.nCount = 1;
856         msgIds[0] = (msg_message_id_t)msgInfo.msgId;
857         msgIdList.msgIdList = msgIds;
858         MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
859         MsgTransactionManager::instance()->broadcastCBMsgCB(err, &cbMsg, msgInfo.msgId);
860
861         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)ppEvent);
862
863         MSG_END();
864
865         return eventSize;
866 }
867
868 int MsgIncomingSyncMLMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
869 {
870         /* input check */
871         if (!pCmd || !ppEvent) {
872                 MSG_DEBUG("pCmd or ppEvent is null");
873                 return 0;
874         }
875
876         MSG_SYNCML_MESSAGE_DATA_S syncMLData;
877         memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
878
879         /* Get Incoming Message */
880         memcpy(&syncMLData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_SYNCML_MESSAGE_DATA_S));
881
882         int eventSize = 0;
883
884         /* broadcast to listener threads, here */
885         MsgTransactionManager::instance()->broadcastSyncMLMsgCB(MSG_SUCCESS, &syncMLData);
886
887         /* Make Event Data */
888         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
889
890         return eventSize;
891 }
892
893
894 int MsgIncomingLBSMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
895 {
896         int eventSize = 0;
897
898         /* input check */
899         if (!pCmd || !ppEvent) {
900                 MSG_DEBUG("pCmd or ppEvent is null");
901                 return 0;
902         }
903
904         MSG_LBS_MESSAGE_DATA_S lbsData;
905         memset(&lbsData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
906
907         /* Get Incoming Message */
908         memcpy(&lbsData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_LBS_MESSAGE_DATA_S));
909
910         /* broadcast to listener threads, here */
911         MsgTransactionManager::instance()->broadcastLBSMsgCB(MSG_SUCCESS, &lbsData);
912
913         /* Make Event Data */
914         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
915
916         return eventSize;
917 }
918
919
920 int MsgSyncMLMsgOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
921 {
922         msg_error_t err = MSG_SUCCESS;
923
924         char* encodedData = NULL;
925         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
926
927         int eventSize = 0;
928
929         msg_message_id_t msgId = 0;
930         int extId = 0;
931
932         /* input check */
933         if (!pCmd || !ppEvent) {
934                 MSG_DEBUG("pCmd or ppEvent is null");
935                 return 0;
936         }
937
938         /* Get Data */
939         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
940         memcpy(&extId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(int));
941
942         err = MsgStoGetSyncMLExtId(msgId, &extId);
943
944         if (err == MSG_SUCCESS) {
945                 MSG_DEBUG("Command Handle Success : MsgStoGetSyncMLExtId()");
946
947                 /* broadcast to listener threads, here */
948                 MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, msgId, extId);
949         } else {
950                 MSG_DEBUG("Command Handle Fail : MsgStoGetSyncMLExtId()");
951         }
952
953         /* Make Event Data to Client */
954         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SYNCML_OPERATION, err, (void**)ppEvent);
955
956         return eventSize;
957 }
958
959
960 int MsgStorageChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
961 {
962         /* input check */
963         if (!pCmd || !ppEvent) {
964                 MSG_DEBUG("pCmd or ppEvent is null");
965                 return 0;
966         }
967
968         msg_id_list_s msgIdList;
969         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
970         msg_storage_change_type_t storageChangeType;
971
972         memcpy(&msgIdList.nCount, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
973
974         msgIdList.msgIdList = new msg_message_id_t[msgIdList.nCount];
975         for (int i = 0; i < msgIdList.nCount; i++) {
976                 memcpy(&msgIdList.msgIdList[i], (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+i*sizeof(msg_message_id_t)), sizeof(msg_message_id_t));
977         }
978
979         memcpy(&storageChangeType, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+(sizeof(msg_message_id_t)*msgIdList.nCount)), sizeof(msg_storage_change_type_t));
980
981         char* encodedData = NULL;
982         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
983
984         int eventSize = 0;
985
986         MSG_DEBUG("msgIdList.nCount [%d]", msgIdList.nCount);
987         for (int i = 0; i < msgIdList.nCount; i++) {
988                 MSG_DEBUG("storageChangeType : [%d], msg Id : [%d]", storageChangeType, msgIdList.msgIdList[i]);
989         }
990
991         /* broadcast to listener threads, here */
992         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, storageChangeType, &msgIdList);
993
994         if (msgIdList.msgIdList) {
995                 delete [] msgIdList.msgIdList;
996         }
997
998         /* Make Event Data to Client */
999         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_STORAGE_CHANGE_IND, MSG_SUCCESS, (void**)ppEvent);
1000
1001         return eventSize;
1002 }
1003
1004 int MsgResendMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1005 {
1006         msg_error_t err = MSG_SUCCESS;
1007         int eventSize = 0;
1008
1009         if (!pCmd || !ppEvent) {
1010                 MSG_DEBUG("pCmd or ppEvent is null");
1011                 return 0;
1012         }
1013
1014         /* Get the msgIdList of sending failed message. */
1015         int *failed_msg_list = NULL;
1016         int count = 0;
1017         unique_ptr<int*, void(*)(int**)> failed_list(&failed_msg_list, unique_ptr_deleter);
1018
1019
1020         err = MsgStoGetFailedMessage(&failed_msg_list, &count);
1021         if (err != MSG_SUCCESS) {
1022                 MSG_DEBUG("MsgStoGetFailedMessage() Error!! [%d]", err);
1023         }
1024
1025         for (int i = 0; i < count ; ++i) {
1026                 MSG_REQUEST_INFO_S reqInfo = {0};
1027                 reqInfo.msgInfo.addressList = NULL;
1028                 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&reqInfo.msgInfo.addressList, unique_ptr_deleter);
1029                 reqInfo.msgInfo.msgId = failed_msg_list[i];
1030                 err = MsgStoGetMessage(reqInfo.msgInfo.msgId, &(reqInfo.msgInfo), &(reqInfo.sendOptInfo));
1031
1032                 if (err != MSG_SUCCESS) {
1033                         MSG_DEBUG("MsgStoGetMessage() Error!! [%d]", err);
1034                 }
1035
1036                 if (reqInfo.msgInfo.msgType.subType ==  MSG_GET_MMS || \
1037                                 reqInfo.msgInfo.msgType.subType  == MSG_NOTIFICATIONIND_MMS || \
1038                                 reqInfo.msgInfo.msgType.subType  == MSG_RETRIEVE_MMS) {
1039                         MSG_WARN("retrieve pending id[%d]", reqInfo.msgInfo.msgId);
1040                         /* For retrieving failed msg (MMS)*/
1041                         reqInfo.msgInfo.msgType.subType = MSG_RETRIEVE_MMS;
1042                         reqInfo.msgInfo.folderId = MSG_OUTBOX_ID; /* outbox fixed */
1043                         reqInfo.msgInfo.networkStatus = MSG_NETWORK_RETRIEVING;
1044                 } else {
1045                         /* For sending failed msg */
1046                         reqInfo.msgInfo.networkStatus = MSG_NETWORK_SENDING;
1047                 }
1048
1049                 msg_id_list_s msgIdList;
1050                 msg_message_id_t msgIds[1];
1051                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
1052
1053                 msgIdList.nCount = 1;
1054                 msgIds[0] = reqInfo.msgInfo.msgId;
1055                 msgIdList.msgIdList = msgIds;
1056
1057                 err = MsgSubmitReq(&reqInfo, false);
1058
1059                 if (err == MSG_SUCCESS) {
1060                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
1061                         if (err == MSG_SUCCESS)
1062                                 MSG_DEBUG("MsgSubmitReq() Success");
1063                         else
1064                                 MSG_DEBUG("MsgSubmitReq() Fail, [%d]", err);
1065                 } else {
1066                         MSG_DEBUG("MsgSubmitReq() Fail, [%d]", err);
1067                 }
1068         }
1069
1070         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_RESEND_MESSAGE, err, (void**)ppEvent);
1071
1072         MSG_END();
1073         return eventSize;
1074 }
1075
1076 #ifdef FEATURE_SMS_CDMA
1077 int MsgCheckUniquenessHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1078 {
1079         MSG_BEGIN();
1080
1081         msg_error_t err = MSG_SUCCESS;
1082         int eventSize = 0;
1083
1084         /* input check */
1085         if (!pCmd || !ppEvent) {
1086                 MSG_DEBUG("pCmd or ppEvent is null");
1087                 return 0;
1088         }
1089
1090         /* Get Incoming Message */
1091         bool bInsert;
1092         memcpy(&bInsert, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(bool));
1093
1094         msg_message_id_t msgId;
1095         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(bool)), sizeof(msg_message_id_t));
1096
1097         MSG_UNIQUE_INDEX_S p_msg;
1098         memcpy(&p_msg, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(bool)+sizeof(msg_message_id_t)), sizeof(MSG_UNIQUE_INDEX_S));
1099
1100         MSG_DEBUG("Decoded Teleservice Msg Id = [%d]", p_msg.tele_msgId);
1101         MSG_DEBUG("Decoded Address = [%s]", p_msg.address);
1102         MSG_DEBUG("Decoded Sub Address = [%s]", p_msg.sub_address);
1103
1104         err = MsgCheckUniqueness(bInsert, msgId, &p_msg);
1105
1106         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_CHECK_UNIQUENESS, err, (void**)ppEvent);
1107
1108         MSG_END();
1109
1110         return eventSize;
1111 }
1112 #endif