fix svace issues
[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 MsgRegThreadChangeCallbackHandler(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 storage change CB for %d", listenerFd);
384
385         /* storing dst fd in list */
386         MsgTransactionManager::instance()->setThreadChangeCB(listenerFd);
387
388         /* Make Event Data */
389         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_THREAD_CHANGE_CB, MsgException::SUCCESS, (void**)ppEvent);
390
391         return eventSize;
392 }
393
394
395 int MsgRegIncomingReportMsgCallbackHandler(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         int listenerFd = 0;
405         memcpy(&listenerFd, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
406         MSG_DEBUG("Registering report msg incoming CB for %d", listenerFd);
407
408         /* storing dst fd in list */
409         MsgTransactionManager::instance()->setReportMsgCB(listenerFd);
410
411         /* Make Event Data */
412         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_REPORT_MSG_INCOMING_CB, MsgException::SUCCESS, (void**)ppEvent);
413
414         return eventSize;
415 }
416
417
418 int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
419 {
420         /* input check */
421         if (!pCmd || !ppEvent) {
422                 MSG_DEBUG("pCmd or ppEvent is null");
423                 return 0;
424         }
425
426         /* Get Message Request */
427         MSG_SENT_STATUS_S* pStatus = (MSG_SENT_STATUS_S*) pCmd->cmdData;
428
429         MSG_DEBUG("REQID %d, STATUS %d", pStatus->reqId, pStatus->status);
430
431         /* storing dst fd in list */
432         MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(pStatus->reqId);
433
434         /* when no sent status cb is found */
435         if (!prxInfo) {
436                 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
437         }
438
439         MSG_DEBUG("REQID %d, listenerFD %d, handleAddr %x, msgId %d", pStatus->reqId, prxInfo->listenerFd, prxInfo->handleAddr, prxInfo->sentMsgId);
440
441         /* if APP send and quit(not exist at this time), don't send the data up. */
442         if (prxInfo->handleAddr == 0) {
443                 /* just making data which will be passed to plugin. it indicates "handling evt success" */
444                 MsgTransactionManager::instance()->delProxyInfo(pStatus->reqId);
445
446                 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
447         }
448
449         unsigned long ret[3] = {0}; /* reqid, status, object */
450
451         ret[0] = (unsigned long)pStatus->reqId;
452         ret[1] = (unsigned long)pStatus->status;
453         ret[2] = prxInfo->handleAddr;
454
455         /* Make Event Data for APP */
456         int eventSize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
457
458         /* Send to listener thread, here */
459         MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventSize);
460
461         MsgTransactionManager::instance()->delProxyInfo(pStatus->reqId);
462
463         return eventSize;
464 }
465
466
467 int MsgIncomingMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
468 {
469         MSG_BEGIN();
470
471         msg_error_t err = MSG_SUCCESS;
472         int eventSize = 0;
473         bool sendNoti = true;
474         bool isClass2msg = false;
475
476         /* input check */
477         if (!pCmd || !ppEvent) {
478                 MSG_DEBUG("pCmd or ppEvent is null");
479                 return 0;
480         }
481
482         /* Get Incoming Message */
483         MSG_MESSAGE_INFO_S msgInfo;
484         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
485
486         msgInfo.addressList = NULL;
487         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
488
489         MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo);
490
491         /* broadcast to listener threads, here */
492         msg_id_list_s msgIdList;
493         msg_message_id_t msgIds[2];
494         msg_message_id_t class2msgId = 0;
495         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
496
497 #ifdef MSG_NOTI_INTEGRATION
498         if (msgInfo.msgType.classType == MSG_CLASS_2) {
499                 class2msgId = msgInfo.msgId;
500                 isClass2msg = true;
501         }
502 #endif
503
504         /* normal process */
505         err = MsgHandleIncomingMsg(&msgInfo, &sendNoti);
506
507         if (msgInfo.msgType.mainType == MSG_SMS_TYPE) {
508                 /* Send system event */
509                 bundle *b = NULL;
510                 b = bundle_create();
511                 if (b) {
512                         char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
513                         snprintf(msgId, sizeof(msgId), "%u", msgInfo.msgId);
514                         bundle_add_str(b, EVT_KEY_MSG_ID, msgId);
515
516                         if (msgInfo.msgType.subType >= MSG_WAP_SI_SMS && msgInfo.msgType.subType <= MSG_WAP_CO_SMS) {
517                                 bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_PUSH);
518                         } else {
519                                 bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_SMS);
520                                 bundle_add_str(b, "cmd", "incoming_msg");
521                                 msg_launch_app(MSG_MGR_APP_ID, b);
522                         }
523                         eventsystem_send_system_event(SYS_EVENT_INCOMMING_MSG, b);
524                         bundle_free(b);
525                 }
526         }
527
528         if (isClass2msg == true) {
529                 msgIdList.nCount = 2;
530                 msgIds[0] = class2msgId;
531                 msgIds[1] = msgInfo.msgId;
532                 msgIdList.msgIdList = msgIds;
533                 isClass2msg = false;
534         } else {
535                 msgIdList.nCount = 1;
536                 msgIds[0] = msgInfo.msgId;
537                 msgIdList.msgIdList = msgIds;
538         }
539
540         if (sendNoti == true) {
541                 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
542                 if (msgInfo.msgType.subType > MSG_TYPE0_SMS && msgInfo.msgType.subType < MSG_WAP_SI_SMS) { /* if it is replacement message. */
543                         MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
544                 } else {
545                         MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
546                 }
547         } else if (msgInfo.msgPort.valid || (msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) {
548                 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
549         } else if (msgInfo.folderId == MSG_SPAMBOX_ID || msgInfo.bRestricted == true) {
550                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
551         } else if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS || msgInfo.msgType.subType == MSG_DELIVERYIND_MMS) {
552                 MsgTransactionManager::instance()->broadcastReportMsgCB(err, MSG_REPORT_TYPE_DELIVERY, &msgInfo);
553         } else if (msgInfo.msgType.subType == MSG_READORGIND_MMS) {
554                 MsgTransactionManager::instance()->broadcastReportMsgCB(err, MSG_REPORT_TYPE_READ, &msgInfo);
555         }
556
557         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
558         MsgStoAutoDeleteConversation(msgInfo.threadId, &msgIdList);
559         if (msgIdList.msgIdList) {
560                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
561                 delete [] (char*)msgIdList.msgIdList;
562         }
563
564 #ifdef FEATURE_SMS_CDMA
565         eventSize = MsgMakeEvent(&msgInfo.msgId, sizeof(msg_message_id_t), MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
566 #else
567         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
568 #endif
569
570         if (msgInfo.bTextSms == false) {
571                 MsgDeleteFile(msgInfo.msgData); /*ipc */
572                 memset(msgInfo.msgData, 0x00, sizeof(msgInfo.msgData));
573         }
574
575         MSG_END();
576
577         return eventSize;
578 }
579
580 int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
581 {
582         MSG_BEGIN();
583
584         if (!pCmd || !ppEvent) {
585                 MSG_DEBUG("pCmd or ppEvent is null");
586                 return 0;
587         }
588
589         msg_error_t err = MSG_SUCCESS;
590         int eventsize = 0;
591
592         MSG_MESSAGE_INFO_S msgInfo;
593         msg_request_id_t reqID;
594
595         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
596
597         msgInfo.addressList = NULL;
598         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
599
600         memcpy(&reqID, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_request_id_t));
601         MsgDecodeMsgInfo((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t), &msgInfo);
602
603         MSG_DEBUG(" pMsg = %s, pReqId = %d ", msgInfo.msgData, reqID);
604         MSG_DEBUG(" msgtype subtype is [%d]", msgInfo.msgType.subType);
605
606         /* For Storage change callback */
607         msg_id_list_s msgIdList;
608         msg_message_id_t msgIds[1];
609         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
610
611         msgIdList.nCount = 1;
612         msgIds[0] = msgInfo.msgId;
613         msgIdList.msgIdList = msgIds;
614
615         MsgDbHandler *dbHandle = getDbHandle();
616         int tmpAddrCnt = 0;
617         MSG_ADDRESS_INFO_S *tmpAddr = NULL;
618         err = MsgStoGetAddressByMsgId(dbHandle, msgInfo.msgId, &tmpAddrCnt, &tmpAddr);
619         if (err != MSG_SUCCESS) {
620                 MSG_DEBUG("MsgStoGetAddressByMsgId() fail.");
621         }
622
623         if (msgInfo.msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || msgInfo.msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
624                 if (msgInfo.networkStatus != MSG_NETWORK_RETRIEVE_SUCCESS) {
625                         if (msgInfo.addressList) {
626                                 delete[] msgInfo.addressList;
627                                 msgInfo.addressList = NULL;
628                         }
629
630                         msgInfo.addressList = tmpAddr;
631                         msgInfo.nAddressCnt = tmpAddrCnt;
632                 } else {
633                         if (tmpAddr) {
634                                 delete [] tmpAddr;
635                                 tmpAddr = NULL;
636                         }
637                 }
638
639                 msg_thread_id_t prev_conv_id = MsgGetThreadId(dbHandle, msgInfo.msgId);
640                 MSG_SUB_TYPE_T recv_sub_type = msgInfo.msgType.subType; /* Check retrieve mode to determine broadcast type */
641
642                 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
643
644                 if (err != MSG_SUCCESS) {
645                         MSG_DEBUG("MsgHandleMmsConfIncomingMsg failed.");
646                         return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
647                 }
648
649                 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
650
651                 if (pMmsRecvData->msgAppId.valid == true) {
652                         MSG_DEBUG("valid : %d, appId : %s", pMmsRecvData->msgAppId.valid, pMmsRecvData->msgAppId.appId);
653                 } else {
654                         msgInfo.bTextSms = true;
655                         msgInfo.dataSize = 0 ;
656                         memset(msgInfo.msgData, 0x00, sizeof(MMS_RECV_DATA_S));
657                 }
658
659                 /* broadcast to listener threads, here */
660                 MsgTransactionManager::instance()->broadcastMMSConfCB(msgInfo.networkStatus, &msgInfo, pMmsRecvData);
661
662                 /* determine broadcast type with retrieve mode */
663                 if (recv_sub_type == MSG_RETRIEVE_AUTOCONF_MMS) {
664                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
665                 } else {
666                         if (prev_conv_id == msgInfo.threadId
667                                 || msgInfo.networkStatus == MSG_NETWORK_RETRIEVE_FAIL || msgInfo.networkStatus == MSG_NETWORK_RETRIEVE_PENDING) {
668                                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
669                         } else {
670                                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
671                                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
672                         }
673                 }
674
675                 /* make return event */
676                 eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, MSG_SUCCESS, (void**)ppEvent);
677
678         } else if (msgInfo.msgType.subType == MSG_SENDREQ_MMS || msgInfo.msgType.subType == MSG_SENDCONF_MMS) {
679                 if (msgInfo.addressList) {
680                         delete[] msgInfo.addressList;
681                         msgInfo.addressList = NULL;
682                 }
683
684                 msgInfo.addressList = tmpAddr;
685                 msgInfo.nAddressCnt = tmpAddrCnt;
686
687                 MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(reqID);
688
689                 /* when no sent status cb is found */
690                 if (prxInfo) {
691                         /* No need to update javaMMS sent messages */
692                         javamms_list& listenerList = MsgTransactionManager::instance()->getJavaMMSList();
693                         javamms_list::iterator it = listenerList.begin();
694
695                         MSG_DEBUG("listenerList size:%d ", listenerList.size());
696
697                         if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL && msgInfo.msgType.subType == MSG_SENDREQ_MMS) {
698                                 for ( ; it != listenerList.end() ; it++) {
699                                         if (strstr(it->pduFileName, "JAVA")) {
700                                                 MSG_SEC_DEBUG("JAVA MMS fileName:%s", it->pduFileName);
701                                                 MsgDeleteFile(it->pduFileName);         /* ipc */
702                                                 listenerList.erase(it);
703                                                 goto __BYPASS_UPDATE;
704                                         }
705                                 }
706                         } else {
707                                 /*msgData has MMS_RECV_DATA_S */
708                                 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
709
710                                 for ( ; it != listenerList.end() ; it++) {
711                                         if (!strcmp(it->id, pMmsRecvData->szTrID)) {
712                                                 MSG_SEC_DEBUG("find sent JAVA MMS message trId:%s from listener list trId:%s", pMmsRecvData->szTrID, it->id);
713                                                 MsgDeleteFile(it->pduFileName); /* ipc */
714                                                 listenerList.erase(it);
715                                                 goto __BYPASS_UPDATE;
716                                         }
717                                 }
718                         }
719                 } else {
720                         MSG_DEBUG("prxInfo is NULL");
721                 }
722
723                 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
724
725                 if (err != MSG_SUCCESS) {
726                         return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
727                 }
728
729 __BYPASS_UPDATE:
730                 if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL) {
731                         MSG_DEBUG("message-dialog: send fail");
732                         MsgInsertTicker("Sending multimedia message failed.", SENDING_MULTIMEDIA_MESSAGE_FAILED, true, msgInfo.msgId);
733                 } else {
734                         MSG_DEBUG("message-dialog: send success");
735
736 #if 0 /* disabled as per UX request to not show success notification : 2015. 09. 18 */
737                         bool bTTS = false;
738
739                         if (MsgSettingGetBool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &bTTS) != MSG_SUCCESS) {
740                                 MSG_DEBUG("MsgSettingGetBool is failed.");
741                         }
742
743                         if (bTTS) {
744                                 MsgInsertTicker("Multimedia message sent.", MULTIMEDIA_MESSAGE_SENT, false, 0);
745                         }
746
747 #endif
748 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
749                         MSG_SEC_DEBUG("Enter MsgAddPhoneLog() : msgInfo.addressList[0].addressVal [%s]", msgInfo.addressList[0].addressVal);
750                         MsgAddPhoneLog(&msgInfo);
751                         /* Send system event */
752                         bundle *b = NULL;
753                         b = bundle_create();
754                         if (b) {
755                                 bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_MMS);
756                                 char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
757                                 snprintf(msgId, sizeof(msgId), "%u", msgInfo.msgId);
758                                 bundle_add_str(b, EVT_KEY_MSG_ID, msgId);
759                                 eventsystem_send_system_event(SYS_EVENT_INCOMMING_MSG, b);
760                                 bundle_add_str(b, "cmd", "incoming_msg");
761                                 msg_launch_app(MSG_MGR_APP_ID, b);
762                                 bundle_free(b);
763                         }
764 #endif /*MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
765                 }
766
767                 if (prxInfo) {
768                         if (prxInfo->handleAddr == 0) {
769                                 /* just making data which will be passed to plugin. it indicates "handling evt success" */
770                                 MsgTransactionManager::instance()->delProxyInfo(reqID);
771                         } else {
772                                 unsigned long ret[3] = {0}; /* reqid, status, object */
773
774                                 ret[0] = (unsigned long)reqID;
775                                 ret[1] = (unsigned long)msgInfo.networkStatus;
776                                 ret[2] = prxInfo->handleAddr;
777
778                                 /* Make Event Data for APP */
779                                 eventsize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
780
781                                 /* Send to listener thread, here */
782                                 MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventsize);
783
784                                 MsgTransactionManager::instance()->delProxyInfo(reqID);
785                         }
786                 }
787
788                 eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, MSG_SUCCESS, (void**)ppEvent);
789                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
790         } else {
791                 /*To avoid prevent memory leak.. this case will not occur. eventsize will be return as 0. */
792                 if (tmpAddr) {
793                         delete[] tmpAddr;
794                         tmpAddr = NULL;
795                 }
796         }
797
798         MSG_END();
799         return eventsize;
800 }
801
802 int MsgIncomingPushMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
803 {
804         MSG_BEGIN();
805
806         int eventSize = 0;
807
808         /* input check */
809         if (!pCmd || !ppEvent) {
810                 MSG_DEBUG("pCmd or ppEvent is null");
811                 return 0;
812         }
813
814         MSG_PUSH_MESSAGE_DATA_S pushData;
815         memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
816
817         /* Get Incoming Message */
818         memcpy(&pushData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_PUSH_MESSAGE_DATA_S));
819
820
821
822         /* broadcast to listener threads, here */
823         MsgTransactionManager::instance()->broadcastPushMsgCB(MSG_SUCCESS, &pushData);
824
825         /* Make Event Data */
826         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
827
828         MSG_END();
829         return eventSize;
830 }
831
832 int MsgIncomingCBMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
833 {
834         MSG_BEGIN();
835
836         msg_error_t err = MSG_SUCCESS;
837         int eventSize = 0;
838
839         /* input check */
840         if (!pCmd || !ppEvent) {
841                 MSG_DEBUG("pCmd or ppEvent is null");
842                 return 0;
843         }
844
845         /* Get Incoming Message */
846         MSG_CB_MSG_S cbMsg;
847         memset(&cbMsg, 0x00, sizeof(MSG_CB_MSG_S));
848
849         memcpy(&cbMsg, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_CB_MSG_S));
850
851         MSG_MESSAGE_INFO_S msgInfo;
852         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
853
854         msgInfo.addressList = NULL;
855         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
856
857         MsgDecodeMsgInfo((char *)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_CB_MSG_S), &msgInfo);
858
859         MSG_DEBUG("CB MSG ADDRESS COUNT=%d", msgInfo.nAddressCnt);
860
861         if (MsgStoAddCBMsg(&msgInfo) != MSG_SUCCESS) {
862                 MSG_DEBUG("MsgStoAddCBMsg is fail");
863         }
864
865         if (msgInfo.msgType.classType == MSG_CLASS_0) {
866                 MsgLaunchClass0(msgInfo.msgId);
867                 MsgSoundPlayStart(&(msgInfo.addressList[0]), MSG_SOUND_PLAY_USER);
868         } else {
869                 MsgInsertNotification(&msgInfo);
870         }
871
872         MsgChangePmState();
873
874         msg_id_list_s msgIdList;
875         msg_message_id_t msgIds[1];
876         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
877
878         msgIdList.nCount = 1;
879         msgIds[0] = (msg_message_id_t)msgInfo.msgId;
880         msgIdList.msgIdList = msgIds;
881         MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
882         MsgTransactionManager::instance()->broadcastCBMsgCB(err, &cbMsg, msgInfo.msgId);
883
884         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)ppEvent);
885
886         MSG_END();
887
888         return eventSize;
889 }
890
891 int MsgIncomingSyncMLMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
892 {
893         /* input check */
894         if (!pCmd || !ppEvent) {
895                 MSG_DEBUG("pCmd or ppEvent is null");
896                 return 0;
897         }
898
899         MSG_SYNCML_MESSAGE_DATA_S syncMLData;
900         memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
901
902         /* Get Incoming Message */
903         memcpy(&syncMLData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_SYNCML_MESSAGE_DATA_S));
904
905         int eventSize = 0;
906
907         /* broadcast to listener threads, here */
908         MsgTransactionManager::instance()->broadcastSyncMLMsgCB(MSG_SUCCESS, &syncMLData);
909
910         /* Make Event Data */
911         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
912
913         return eventSize;
914 }
915
916
917 int MsgIncomingLBSMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
918 {
919         int eventSize = 0;
920
921         /* input check */
922         if (!pCmd || !ppEvent) {
923                 MSG_DEBUG("pCmd or ppEvent is null");
924                 return 0;
925         }
926
927         MSG_LBS_MESSAGE_DATA_S lbsData;
928         memset(&lbsData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
929
930         /* Get Incoming Message */
931         memcpy(&lbsData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_LBS_MESSAGE_DATA_S));
932
933         /* broadcast to listener threads, here */
934         MsgTransactionManager::instance()->broadcastLBSMsgCB(MSG_SUCCESS, &lbsData);
935
936         /* Make Event Data */
937         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
938
939         return eventSize;
940 }
941
942
943 int MsgSyncMLMsgOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
944 {
945         msg_error_t err = MSG_SUCCESS;
946
947         char* encodedData = NULL;
948         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
949
950         int eventSize = 0;
951
952         msg_message_id_t msgId = 0;
953         int extId = 0;
954
955         /* input check */
956         if (!pCmd || !ppEvent) {
957                 MSG_DEBUG("pCmd or ppEvent is null");
958                 return 0;
959         }
960
961         /* Get Data */
962         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
963         memcpy(&extId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(int));
964
965         err = MsgStoGetSyncMLExtId(msgId, &extId);
966
967         if (err == MSG_SUCCESS) {
968                 MSG_DEBUG("Command Handle Success : MsgStoGetSyncMLExtId()");
969
970                 /* broadcast to listener threads, here */
971                 MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, msgId, extId);
972         } else {
973                 MSG_DEBUG("Command Handle Fail : MsgStoGetSyncMLExtId()");
974         }
975
976         /* Make Event Data to Client */
977         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SYNCML_OPERATION, err, (void**)ppEvent);
978
979         return eventSize;
980 }
981
982
983 int MsgStorageChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
984 {
985         /* input check */
986         if (!pCmd || !ppEvent) {
987                 MSG_DEBUG("pCmd or ppEvent is null");
988                 return 0;
989         }
990
991         msg_id_list_s msgIdList;
992         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
993         msg_storage_change_type_t storageChangeType;
994
995         memcpy(&msgIdList.nCount, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
996
997         msgIdList.msgIdList = new msg_message_id_t[msgIdList.nCount];
998         for (int i = 0; i < msgIdList.nCount; i++) {
999                 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));
1000         }
1001
1002         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));
1003
1004         char* encodedData = NULL;
1005         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1006
1007         int eventSize = 0;
1008
1009         MSG_DEBUG("msgIdList.nCount [%d]", msgIdList.nCount);
1010         for (int i = 0; i < msgIdList.nCount; i++) {
1011                 MSG_DEBUG("storageChangeType : [%d], msg Id : [%d]", storageChangeType, msgIdList.msgIdList[i]);
1012         }
1013
1014         /* broadcast to listener threads, here */
1015         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, storageChangeType, &msgIdList);
1016
1017         if (msgIdList.msgIdList) {
1018                 delete [] msgIdList.msgIdList;
1019         }
1020
1021         /* Make Event Data to Client */
1022         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_STORAGE_CHANGE_IND, MSG_SUCCESS, (void**)ppEvent);
1023
1024         return eventSize;
1025 }
1026
1027 int MsgThreadChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1028 {
1029         /* input check */
1030         if (!pCmd || !ppEvent) {
1031                 MSG_DEBUG("pCmd or ppEvent is null");
1032                 return 0;
1033         }
1034
1035         msg_storage_change_type_t storageChangeType;
1036         msg_thread_id_t threadId;
1037
1038         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_thread_id_t));
1039         memcpy(&storageChangeType, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), sizeof(msg_storage_change_type_t));
1040
1041         char* encodedData = NULL;
1042         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1043
1044         int eventSize = 0;
1045
1046         MSG_DEBUG("storageChangeType : [%d], thread Id : [%d]", storageChangeType, threadId);
1047
1048         /* broadcast to listener threads, here */
1049         MsgTransactionManager::instance()->broadcastThreadChangeCB(MSG_SUCCESS, storageChangeType, threadId);
1050
1051         /* Make Event Data to Client */
1052         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_THREAD_CHANGE_IND, MSG_SUCCESS, (void**)ppEvent);
1053
1054         return eventSize;
1055 }
1056
1057 int MsgResendMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1058 {
1059         msg_error_t err = MSG_SUCCESS;
1060         int eventSize = 0;
1061
1062         if (!pCmd || !ppEvent) {
1063                 MSG_DEBUG("pCmd or ppEvent is null");
1064                 return 0;
1065         }
1066
1067         /* Get the msgIdList of sending failed message. */
1068         int *failed_msg_list = NULL;
1069         int count = 0;
1070         unique_ptr<int*, void(*)(int**)> failed_list(&failed_msg_list, unique_ptr_deleter);
1071
1072
1073         err = MsgStoGetFailedMessage(&failed_msg_list, &count);
1074         if (err != MSG_SUCCESS) {
1075                 MSG_DEBUG("MsgStoGetFailedMessage() Error!! [%d]", err);
1076         }
1077
1078         for (int i = 0; i < count ; ++i) {
1079                 MSG_REQUEST_INFO_S reqInfo = {0};
1080                 reqInfo.msgInfo.addressList = NULL;
1081                 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&reqInfo.msgInfo.addressList, unique_ptr_deleter);
1082                 reqInfo.msgInfo.msgId = failed_msg_list[i];
1083                 err = MsgStoGetMessage(reqInfo.msgInfo.msgId, &(reqInfo.msgInfo), &(reqInfo.sendOptInfo));
1084
1085                 if (err != MSG_SUCCESS) {
1086                         MSG_DEBUG("MsgStoGetMessage() Error!! [%d]", err);
1087                 }
1088
1089                 if (reqInfo.msgInfo.msgType.subType ==  MSG_GET_MMS || \
1090                                 reqInfo.msgInfo.msgType.subType  == MSG_NOTIFICATIONIND_MMS || \
1091                                 reqInfo.msgInfo.msgType.subType  == MSG_RETRIEVE_MMS) {
1092                         MSG_WARN("retrieve pending id[%d]", reqInfo.msgInfo.msgId);
1093                         /* For retrieving failed msg (MMS)*/
1094                         reqInfo.msgInfo.msgType.subType = MSG_RETRIEVE_MMS;
1095                         reqInfo.msgInfo.folderId = MSG_OUTBOX_ID; /* outbox fixed */
1096                         reqInfo.msgInfo.networkStatus = MSG_NETWORK_RETRIEVING;
1097                 } else {
1098                         /* For sending failed msg */
1099                         reqInfo.msgInfo.networkStatus = MSG_NETWORK_SENDING;
1100                 }
1101
1102                 msg_id_list_s msgIdList;
1103                 msg_message_id_t msgIds[1];
1104                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
1105
1106                 msgIdList.nCount = 1;
1107                 msgIds[0] = reqInfo.msgInfo.msgId;
1108                 msgIdList.msgIdList = msgIds;
1109
1110                 err = MsgSubmitReq(&reqInfo, false);
1111
1112                 if (err == MSG_SUCCESS) {
1113                         MSG_DEBUG("MsgSubmitReq() Success");
1114                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
1115                 } else {
1116                         MSG_DEBUG("MsgSubmitReq() Fail, [%d]", err);
1117                 }
1118         }
1119
1120         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_RESEND_MESSAGE, err, (void**)ppEvent);
1121
1122         MSG_END();
1123         return eventSize;
1124 }
1125
1126 #ifdef FEATURE_SMS_CDMA
1127 int MsgCheckUniquenessHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1128 {
1129         MSG_BEGIN();
1130
1131         msg_error_t err = MSG_SUCCESS;
1132         int eventSize = 0;
1133
1134         /* input check */
1135         if (!pCmd || !ppEvent) {
1136                 MSG_DEBUG("pCmd or ppEvent is null");
1137                 return 0;
1138         }
1139
1140         /* Get Incoming Message */
1141         bool bInsert;
1142         memcpy(&bInsert, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(bool));
1143
1144         msg_message_id_t msgId;
1145         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(bool)), sizeof(msg_message_id_t));
1146
1147         MSG_UNIQUE_INDEX_S p_msg;
1148         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));
1149
1150         MSG_DEBUG("Decoded Teleservice Msg Id = [%d]", p_msg.tele_msgId);
1151         MSG_DEBUG("Decoded Address = [%s]", p_msg.address);
1152         MSG_DEBUG("Decoded Sub Address = [%s]", p_msg.sub_address);
1153
1154         err = MsgCheckUniqueness(bInsert, msgId, &p_msg);
1155
1156         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_CHECK_UNIQUENESS, err, (void**)ppEvent);
1157
1158         MSG_END();
1159
1160         return eventSize;
1161 }
1162 #endif