2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "MsgException.h"
21 #include "MsgUtilFile.h"
22 #include "MsgContact.h"
23 #include "MsgSoundPlayer.h"
24 #include "MsgGconfWrapper.h"
25 #include "MsgNotificationWrapper.h"
26 #include "MsgUtilFunction.h"
27 #include "MsgSubmitHandler.h"
28 #include "MsgDeliverHandler.h"
29 #include "MsgStorageHandler.h"
30 #include "MsgTransManager.h"
31 #include "MsgPluginManager.h"
32 #include "MsgUtilStorage.h"
34 #include "MsgCmdHandler.h"
35 #include "MsgDevicedWrapper.h"
36 #include "MsgMmsMessage.h"
39 /*==================================================================================================
40 FUNCTION IMPLEMENTATION
41 ==================================================================================================*/
42 int MsgSubmitReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
44 msg_error_t err = MSG_SUCCESS;
47 if (!pCmd || !ppEvent) {
48 MSG_DEBUG("pCmd or ppEvent is null");
55 MSG_REQUEST_INFO_S reqInfo = {0,};
56 MSG_PROXY_INFO_S proxyInfo = {0,};
58 reqInfo.msgInfo.addressList = NULL;
59 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&reqInfo.msgInfo.addressList, unique_ptr_deleter);
61 // Get Message Request
62 memcpy(&reqInfo.reqId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_request_id_t));
64 // Storing Request ID, Proxy Info for Sent Status CNF
65 memcpy(&proxyInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)), sizeof(MSG_PROXY_INFO_S));
67 MsgDecodeMsgInfo((char *)(pCmd->cmdData+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)), &reqInfo.msgInfo, &reqInfo.sendOptInfo);
70 if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE
71 && reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_MMS) {
73 memcpy(&fd, pCmd->cmdCookie, sizeof(int));
74 if (reqInfo.msgInfo.bTextSms == false) {
75 err = MsgMmsCheckFilepathSmack(fd, reqInfo.msgInfo.msgData);
76 if (err != MSG_SUCCESS) {
77 return MsgMakeEvent(NULL, 0, MSG_EVENT_SUBMIT_REQ, err, (void**)ppEvent);
82 if (reqInfo.msgInfo.msgId > 0)
86 err = MsgSubmitReq(&reqInfo, false);
88 if (err == MSG_SUCCESS){
89 MSG_DEBUG("Command Handle Success : MsgSubmitReq()");
91 MSG_DEBUG("Command Handle Fail : MsgSubmitReq()");
94 int reqId = reqInfo.reqId;
95 proxyInfo.sentMsgId = reqInfo.msgInfo.msgId;
97 MSG_DEBUG("REQID: %d, MSGID: %d", reqId, proxyInfo.sentMsgId);
99 if (reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE) {
100 MsgTransactionManager::instance()->insertSentMsg(reqId, &proxyInfo);
101 } else if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE) {
102 // Retrieve MMS shall not be kept in sentMsg
103 if ((reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_MMS) ||
104 (reqInfo.msgInfo.msgType.subType == MSG_FORWARD_MMS) ||
105 (reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS))
106 MsgTransactionManager::instance()->insertSentMsg(reqId, &proxyInfo);
109 // keep transaction Id list for distinguish java MMS sent msg when sendconf received
110 if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE &&
111 reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS) {
112 MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S trId={0};
113 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 pFileName = strstr(reqInfo.msgInfo.msgData, "MSG_");
117 strncpy(trId.pduFileName, pFileName, MAX_COMMON_INFO_SIZE);
119 MSG_SEC_DEBUG("java MMS msg trId:%s filepath:%s ",trId.id, reqInfo.msgInfo.msgData);
121 MsgTransactionManager* tm = MsgTransactionManager::instance();
122 tm->setJavaMMSList(&trId);
126 ret[1] = reqInfo.msgInfo.msgId;
127 ret[2] = reqInfo.msgInfo.threadId;
130 eventSize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_SUBMIT_REQ, err, (void**)ppEvent);
132 /* reject_msg_support */
133 if (((reqInfo.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS) &&
134 (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE)))
135 err = MsgStoDeleteMessage(reqInfo.msgInfo.msgId, true);
137 /** send storage CB */
138 msg_id_list_s msgIdList;
139 msg_message_id_t msgIds[1];
140 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
142 msgIdList.nCount = 1;
143 msgIds[0] = reqInfo.msgInfo.msgId;
144 msgIdList.msgIdList = msgIds;
146 if ((err == MSG_SUCCESS || err != MSG_ERR_PLUGIN_STORAGE) && reqInfo.msgInfo.msgPort.valid == false) {
148 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
150 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
153 MSG_DEBUG("No need to broadcast storage change CB");
156 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
158 MsgStoAutoDeleteConversation(reqInfo.msgInfo.threadId, &msgIdList);
159 if (msgIdList.msgIdList)
161 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
162 delete [] (char*)msgIdList.msgIdList;
169 int MsgRegSentStatusCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
172 if (!pCmd || !ppEvent) {
173 MSG_DEBUG("pCmd or ppEvent is null");
177 // Get Message Request
179 memcpy(&listenerFd, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
180 MSG_DEBUG("Registering sent status CB for %d", listenerFd);
182 // storing dst fd in list
183 MsgTransactionManager::instance()->setSentStatusCB(listenerFd);
186 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SENT_STATUS_CB, MSG_SUCCESS, (void**)ppEvent);
192 int MsgRegIncomingMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
195 if (!pCmd || !ppEvent) {
196 MSG_DEBUG("pCmd or ppEvent is null");
200 // Get Message Request
201 MSG_CMD_REG_INCOMING_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_MSG_CB_S*) pCmd->cmdData;
202 MSG_DEBUG("Registering incoming SMS CB for fd %d mType %d port %d", pCmdData->listenerFd, pCmdData->msgType, pCmdData->port);
204 // storing dst fd in list
205 MsgTransactionManager::instance()->setIncomingMsgCB(pCmdData);
208 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
214 int MsgRegIncomingMMSConfMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
217 if (!pCmd || !ppEvent) {
218 MSG_DEBUG("pCmd or ppEvent is null");
222 // Get Message Request
223 MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S*) pCmd->cmdData;
224 MSG_DEBUG("Registering incoming MMS Conf CB for fd:%d mType:%d appId:%s", pCmdData->listenerFd, pCmdData->msgType, pCmdData->appId);
226 // storing dst fd in list
227 MsgTransactionManager::instance()->setMMSConfMsgCB(pCmdData);
230 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
235 int MsgRegIncomingPushMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
238 if (!pCmd || !ppEvent) {
239 MSG_DEBUG("pCmd or ppEvent is null");
243 // Get Message Request
244 MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S*) pCmd->cmdData;
245 MSG_DEBUG("Registering incoming Push Msg CB for fd:%d mType:%d appId:%s", pCmdData->listenerFd, pCmdData->msgType, pCmdData->appId);
247 // storing dst fd in list
248 MsgTransactionManager::instance()->setPushMsgCB(pCmdData);
249 //MsgTransactionManager::instance()->sendPendigPushMsg(pCmdData);
253 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_PUSH_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
260 int MsgRegIncomingCBMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
263 if (!pCmd || !ppEvent) {
264 MSG_DEBUG("pCmd or ppEvent is null");
268 // Get Message Request
269 MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_CB_MSG_CB_S*) pCmd->cmdData;
270 MSG_DEBUG("Registering incoming CB Msg CB for fd:%d mType:%d: bSave: %d", pCmdData->listenerFd, pCmdData->msgType, pCmdData->bsave);
272 // storing dst fd in list
273 MsgTransactionManager::instance()->setCBMsgCB(pCmdData);
276 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_CB_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
282 int MsgRegIncomingSyncMLMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
285 if (!pCmd || !ppEvent) {
286 MSG_DEBUG("pCmd or ppEvent is null");
290 // Get Message Request
291 MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S*) pCmd->cmdData;
292 MSG_DEBUG("Registering incoming Sync ML Msg CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
294 // storing dst fd in list
295 MsgTransactionManager::instance()->setSyncMLMsgCB(pCmdData);
298 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
304 int MsgRegIncomingLBSMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
307 if (!pCmd || !ppEvent) {
308 MSG_DEBUG("pCmd or ppEvent is null");
312 // Get Message Request
313 MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_LBS_MSG_CB_S*) pCmd->cmdData;
314 MSG_DEBUG("Registering incoming LBS Msg CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
316 // storing dst fd in list
317 MsgTransactionManager::instance()->setLBSMsgCB(pCmdData);
320 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_LBS_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
326 int MsgRegSyncMLMsgOperationCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
329 if (!pCmd || !ppEvent) {
330 MSG_DEBUG("pCmd or ppEvent is null");
334 // Get Message Request
335 MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCmdData = (MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S*) pCmd->cmdData;
336 MSG_DEBUG("Registering SyncML Msg ooperation CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
338 // storing dst fd in list
339 MsgTransactionManager::instance()->setSyncMLMsgOperationCB(pCmdData);
342 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB, MSG_SUCCESS, (void**)ppEvent);
348 int MsgRegStorageChangeCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
351 if (!pCmd || !ppEvent) {
352 MSG_DEBUG("pCmd or ppEvent is null");
356 // Get Message Request
358 memcpy(&listenerFd, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
359 MSG_DEBUG("Registering storage change CB for %d", listenerFd);
361 // storing dst fd in list
362 MsgTransactionManager::instance()->setStorageChangeCB(listenerFd);
365 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_STORAGE_CHANGE_CB, MsgException::SUCCESS, (void**)ppEvent);
371 int MsgRegIncomingReportMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
374 if (!pCmd || !ppEvent) {
375 MSG_DEBUG("pCmd or ppEvent is null");
379 // Get Message Request
381 memcpy(&listenerFd, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
382 MSG_DEBUG("Registering report msg incoming CB for %d", listenerFd);
384 // storing dst fd in list
385 MsgTransactionManager::instance()->setReportMsgCB(listenerFd);
388 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_REPORT_MSG_INCOMING_CB, MsgException::SUCCESS, (void**)ppEvent);
394 int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
397 if (!pCmd || !ppEvent) {
398 MSG_DEBUG("pCmd or ppEvent is null");
402 // Get Message Request
403 MSG_SENT_STATUS_S* pStatus = (MSG_SENT_STATUS_S*) pCmd->cmdData;
405 MSG_DEBUG("REQID %d, STATUS %d", pStatus->reqId, pStatus->status);
407 // storing dst fd in list
408 MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(pStatus->reqId);
410 // when no sent status cb is found
412 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
415 MSG_DEBUG("REQID %d, listenerFD %d, handleAddr %x, msgId %d", pStatus->reqId, prxInfo->listenerFd, prxInfo->handleAddr, prxInfo->sentMsgId);
417 // if APP send and quit(not exist at this time), don't send the data up.
418 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);
423 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
426 unsigned long ret[3] = {0}; //3// reqid, status, object
428 ret[0] = (unsigned long)pStatus->reqId;
429 ret[1] = (unsigned long)pStatus->status;
430 ret[2] = prxInfo->handleAddr;
432 // Make Event Data for APP
433 int eventSize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
435 // Send to listener thread, here
436 MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventSize);
438 MsgTransactionManager::instance()->delProxyInfo(pStatus->reqId);
444 int MsgIncomingMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
448 msg_error_t err = MSG_SUCCESS;
450 bool sendNoti = true;
451 bool isClass2msg = false;
454 if (!pCmd || !ppEvent) {
455 MSG_DEBUG("pCmd or ppEvent is null");
459 // Get Incoming Message
460 MSG_MESSAGE_INFO_S msgInfo;
461 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
463 msgInfo.addressList = NULL;
464 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
466 MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo);
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));
474 #ifdef MSG_NOTI_INTEGRATION
475 if (msgInfo.msgType.classType == MSG_CLASS_2) {
476 class2msgId = msgInfo.msgId;
482 err = MsgHandleIncomingMsg(&msgInfo, &sendNoti);
484 if (isClass2msg == true) {
485 msgIdList.nCount = 2;
486 msgIds[0] = class2msgId;
487 msgIds[1] = msgInfo.msgId;
488 msgIdList.msgIdList = msgIds;
491 msgIdList.nCount = 1;
492 msgIds[0] = msgInfo.msgId;
493 msgIdList.msgIdList = msgIds;
496 if (sendNoti == true) {
497 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
498 if (msgInfo.msgType.subType > MSG_TYPE0_SMS && msgInfo.msgType.subType < MSG_WAP_SI_SMS) { // if it is replacement message.
499 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
501 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
503 } else if (msgInfo.msgPort.valid || (msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) {
504 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
505 } else if (msgInfo.folderId == MSG_SPAMBOX_ID) {
506 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
507 } else if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS || msgInfo.msgType.subType == MSG_DELIVERYIND_MMS) {
508 MsgTransactionManager::instance()->broadcastReportMsgCB(err, MSG_REPORT_TYPE_DELIVERY, &msgInfo);
509 } else if (msgInfo.msgType.subType == MSG_READORGIND_MMS) {
510 MsgTransactionManager::instance()->broadcastReportMsgCB(err, MSG_REPORT_TYPE_READ, &msgInfo);
513 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
514 MsgStoAutoDeleteConversation(msgInfo.threadId, &msgIdList);
515 if (msgIdList.msgIdList)
517 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
518 delete [] (char*)msgIdList.msgIdList;
521 #ifdef FEATURE_SMS_CDMA
522 eventSize = MsgMakeEvent(&msgInfo.msgId, sizeof(msg_message_id_t), MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
524 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
527 if (msgInfo.bTextSms == false) {
528 MsgDeleteFile(msgInfo.msgData); //ipc
529 memset(msgInfo.msgData, 0x00, sizeof(msgInfo.msgData));
537 int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
541 if (!pCmd || !ppEvent) {
542 MSG_DEBUG("pCmd or ppEvent is null");
546 msg_error_t err = MSG_SUCCESS;
549 MSG_MESSAGE_INFO_S msgInfo;
550 msg_request_id_t reqID;
552 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
554 msgInfo.addressList = NULL;
555 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
557 memcpy(&reqID, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_request_id_t));
558 MsgDecodeMsgInfo((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t), &msgInfo);
560 MSG_DEBUG(" pMsg = %s, pReqId = %d ", msgInfo.msgData, reqID);
561 MSG_DEBUG(" msgtype subtype is [%d]", msgInfo.msgType.subType);
563 /* For Storage change callback */
564 msg_id_list_s msgIdList;
565 msg_message_id_t msgIds[1];
566 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
568 msgIdList.nCount = 1;
569 msgIds[0] = msgInfo.msgId;
570 msgIdList.msgIdList = msgIds;
572 MsgDbHandler *dbHandle = getDbHandle();
574 MSG_ADDRESS_INFO_S *tmpAddr = NULL;
575 int order = MsgGetContactNameOrder();
576 err = MsgStoGetAddressByMsgId(dbHandle, msgInfo.msgId, order, &tmpAddrCnt, &tmpAddr);
577 if (err != MSG_SUCCESS) {
578 MSG_DEBUG("MsgStoGetAddressByMsgId() fail.");
581 if (msgInfo.msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || msgInfo.msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
582 if (msgInfo.networkStatus != MSG_NETWORK_RETRIEVE_SUCCESS) {
583 if (msgInfo.addressList) {
584 delete[] msgInfo.addressList;
585 msgInfo.addressList = NULL;
588 msgInfo.addressList = tmpAddr;
589 msgInfo.nAddressCnt = tmpAddrCnt;
597 msg_thread_id_t prev_conv_id = MsgGetThreadId(dbHandle, msgInfo.msgId);
598 MSG_SUB_TYPE_T recv_sub_type = msgInfo.msgType.subType; /* Check retrieve mode to determine broadcast type */
600 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
602 if (err != MSG_SUCCESS) {
603 MSG_DEBUG("MsgHandleMmsConfIncomingMsg failed.");
604 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
607 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
609 if (pMmsRecvData->msgAppId.valid == true) {
610 MSG_DEBUG("valid : %d, appId : %s", pMmsRecvData->msgAppId.valid, pMmsRecvData->msgAppId.appId);
612 msgInfo.bTextSms = true;
613 msgInfo.dataSize = 0 ;
614 memset(msgInfo.msgData, 0x00, sizeof(MMS_RECV_DATA_S));
617 /* broadcast to listener threads, here */
618 MsgTransactionManager::instance()->broadcastMMSConfCB(msgInfo.networkStatus, &msgInfo, pMmsRecvData);
620 /* determine broadcast type with retrieve mode */
621 if (recv_sub_type == MSG_RETRIEVE_AUTOCONF_MMS) {
622 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
624 if (prev_conv_id == msgInfo.threadId
625 || msgInfo.networkStatus == MSG_NETWORK_RETRIEVE_FAIL || msgInfo.networkStatus == MSG_NETWORK_RETRIEVE_PENDING) {
626 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
628 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
629 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
634 eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, MSG_SUCCESS, (void**)ppEvent);
636 } else if (msgInfo.msgType.subType == MSG_SENDREQ_MMS || msgInfo.msgType.subType == MSG_SENDCONF_MMS) {
637 if (msgInfo.addressList) {
638 delete[] msgInfo.addressList;
639 msgInfo.addressList = NULL;
642 msgInfo.addressList = tmpAddr;
643 msgInfo.nAddressCnt = tmpAddrCnt;
645 MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(reqID);
647 // when no sent status cb is found
649 // No need to update javaMMS sent messages
650 javamms_list& listenerList = MsgTransactionManager::instance()->getJavaMMSList();
651 javamms_list::iterator it = listenerList.begin();
653 MSG_DEBUG("listenerList size:%d ",listenerList.size());
655 if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL && msgInfo.msgType.subType == MSG_SENDREQ_MMS) {
656 for ( ; it != listenerList.end() ; it++) {
657 if (strstr(it->pduFileName, "JAVA")) {
658 MSG_SEC_DEBUG("JAVA MMS fileName:%s", it->pduFileName);
659 MsgDeleteFile(it->pduFileName); // ipc
660 listenerList.erase(it);
661 goto __BYPASS_UPDATE;
665 //msgData has MMS_RECV_DATA_S
666 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
668 for ( ; it != listenerList.end() ; it++) {
669 if (!strcmp(it->id, pMmsRecvData->szTrID)) {
670 MSG_SEC_DEBUG("find sent JAVA MMS message trId:%s from listener list trId:%s",pMmsRecvData->szTrID, it->id);
671 MsgDeleteFile(it->pduFileName); // ipc
672 listenerList.erase(it);
673 goto __BYPASS_UPDATE;
678 MSG_DEBUG("prxInfo is NULL");
681 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
683 if (err != MSG_SUCCESS) {
684 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
688 if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL) {
689 MSG_DEBUG("message-dialog: send fail");
690 MsgInsertTicker("Sending multimedia message failed.", SENDING_MULTIMEDIA_MESSAGE_FAILED, true, msgInfo.msgId);
691 // MsgSoundPlayer::instance()->MsgSoundPlayStart(NULL, MSG_NORMAL_SOUND_PLAY);
693 MSG_DEBUG("message-dialog: send success");
695 #if 0 // disabled as per UX request to not show success notification : 2015. 09. 18
698 if (MsgSettingGetBool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &bTTS) != MSG_SUCCESS) {
699 MSG_DEBUG("MsgSettingGetBool is failed.");
703 MsgInsertTicker("Multimedia message sent.", MULTIMEDIA_MESSAGE_SENT, false, 0);
707 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
708 MSG_SEC_DEBUG("Enter MsgAddPhoneLog() : msgInfo.addressList[0].addressVal [%s]", msgInfo.addressList[0].addressVal);
709 MsgAddPhoneLog(&msgInfo);
710 #endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
714 if (prxInfo->handleAddr == 0) {
715 // just making data which will be passed to plugin. it indicates "handling evt success"
716 MsgTransactionManager::instance()->delProxyInfo(reqID);
719 unsigned long ret[3] = {0}; //3// reqid, status, object
721 ret[0] = (unsigned long)reqID;
722 ret[1] = (unsigned long)msgInfo.networkStatus;
723 ret[2] = prxInfo->handleAddr;
725 // Make Event Data for APP
726 eventsize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
728 // Send to listener thread, here
729 MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventsize);
731 MsgTransactionManager::instance()->delProxyInfo(reqID);
735 eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, MSG_SUCCESS, (void**)ppEvent);
736 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
738 //To avoid prevent memory leak.. this case will not occur. eventsize will be return as 0.
749 int MsgIncomingPushMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
756 if (!pCmd || !ppEvent) {
757 MSG_DEBUG("pCmd or ppEvent is null");
761 MSG_PUSH_MESSAGE_DATA_S pushData;
762 memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
764 // Get Incoming Message
765 memcpy(&pushData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_PUSH_MESSAGE_DATA_S));
769 // broadcast to listener threads, here
770 MsgTransactionManager::instance()->broadcastPushMsgCB(MSG_SUCCESS, &pushData);
773 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
779 int MsgIncomingCBMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
783 msg_error_t err = MSG_SUCCESS;
787 if (!pCmd || !ppEvent) {
788 MSG_DEBUG("pCmd or ppEvent is null");
792 // Get Incoming Message
794 memset(&cbMsg, 0x00, sizeof(MSG_CB_MSG_S));
796 memcpy(&cbMsg, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_CB_MSG_S));
798 MSG_MESSAGE_INFO_S msgInfo;
799 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
801 msgInfo.addressList = NULL;
802 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
804 MsgDecodeMsgInfo((char *)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_CB_MSG_S), &msgInfo);
806 MSG_DEBUG("CB MSG ADDRESS COUNT=%d", msgInfo.nAddressCnt);
808 if (MsgStoAddCBMsg(&msgInfo) != MSG_SUCCESS) {
809 MSG_DEBUG("MsgStoAddCBMsg is fail");
812 if (msgInfo.msgType.classType == MSG_CLASS_0) {
813 MsgLaunchClass0(msgInfo.msgId);
814 bool isFavorites = false;
815 if (!checkBlockingMode(msgInfo.addressList[0].addressVal, &isFavorites)) {
816 MsgPlayTTSMode(msgInfo.msgType.subType, msgInfo.msgId, isFavorites);
817 MsgSoundPlayer::instance()->MsgSoundPlayStart(&(msgInfo.addressList[0]), MSG_SOUND_PLAY_USER);
820 MsgInsertNotification(&msgInfo);
823 if (MsgCheckNotificationSettingEnable())
826 msg_id_list_s msgIdList;
827 msg_message_id_t msgIds[1];
828 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
830 msgIdList.nCount = 1;
831 msgIds[0] = (msg_message_id_t)msgInfo.msgId;
832 msgIdList.msgIdList = msgIds;
833 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
834 MsgTransactionManager::instance()->broadcastCBMsgCB(err, &cbMsg, msgInfo.msgId);
836 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)ppEvent);
843 int MsgIncomingSyncMLMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
846 if (!pCmd || !ppEvent) {
847 MSG_DEBUG("pCmd or ppEvent is null");
851 MSG_SYNCML_MESSAGE_DATA_S syncMLData;
852 memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
854 // Get Incoming Message
855 memcpy(&syncMLData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_SYNCML_MESSAGE_DATA_S));
859 // broadcast to listener threads, here
860 MsgTransactionManager::instance()->broadcastSyncMLMsgCB(MSG_SUCCESS, &syncMLData);
863 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
869 int MsgIncomingLBSMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
874 if (!pCmd || !ppEvent) {
875 MSG_DEBUG("pCmd or ppEvent is null");
879 MSG_LBS_MESSAGE_DATA_S lbsData;
880 memset(&lbsData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
882 // Get Incoming Message
883 memcpy(&lbsData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_LBS_MESSAGE_DATA_S));
885 // broadcast to listener threads, here
886 MsgTransactionManager::instance()->broadcastLBSMsgCB(MSG_SUCCESS, &lbsData);
889 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
895 int MsgSyncMLMsgOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
897 msg_error_t err = MSG_SUCCESS;
899 char* encodedData = NULL;
900 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
904 msg_message_id_t msgId = 0;
908 if (!pCmd || !ppEvent) {
909 MSG_DEBUG("pCmd or ppEvent is null");
914 memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
915 memcpy(&extId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(int));
917 err = MsgStoGetSyncMLExtId(msgId, &extId);
919 if (err == MSG_SUCCESS)
921 MSG_DEBUG("Command Handle Success : MsgStoGetSyncMLExtId()");
923 // broadcast to listener threads, here
924 MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, msgId, extId);
928 MSG_DEBUG("Command Handle Fail : MsgStoGetSyncMLExtId()");
931 // Make Event Data to Client
932 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SYNCML_OPERATION, err, (void**)ppEvent);
938 int MsgStorageChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
941 if (!pCmd || !ppEvent) {
942 MSG_DEBUG("pCmd or ppEvent is null");
946 msg_id_list_s msgIdList;
947 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
948 msg_storage_change_type_t storageChangeType;
950 memcpy(&msgIdList.nCount, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
952 msgIdList.msgIdList = new msg_message_id_t[msgIdList.nCount];
953 for (int i = 0; i < msgIdList.nCount; i++) {
954 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));
957 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));
959 char* encodedData = NULL;
960 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
964 MSG_DEBUG("msgIdList.nCount [%d]", msgIdList.nCount);
965 for (int i = 0; i < msgIdList.nCount; i++) {
966 MSG_DEBUG("storageChangeType : [%d], msg Id : [%d]", storageChangeType, msgIdList.msgIdList[i]);
969 // broadcast to listener threads, here
970 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, storageChangeType, &msgIdList);
972 if (msgIdList.msgIdList) {
973 delete [] msgIdList.msgIdList;
976 // Make Event Data to Client
977 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_STORAGE_CHANGE_IND, MSG_SUCCESS, (void**)ppEvent);
982 int MsgResendMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
984 msg_error_t err = MSG_SUCCESS;
987 if (!pCmd || !ppEvent) {
988 MSG_DEBUG("pCmd or ppEvent is null");
992 // Get the msgIdList of sending failed message.
993 int *failed_msg_list = NULL;
995 unique_ptr<int*, void(*)(int**)> failed_list(&failed_msg_list, unique_ptr_deleter);
998 err = MsgStoGetFailedMessage(&failed_msg_list, &count);
999 if (err != MSG_SUCCESS) {
1000 MSG_DEBUG("MsgStoGetFailedMessage() Error!! [%d]", err);
1003 for(int i=0; i < count ; ++i)
1005 MSG_REQUEST_INFO_S reqInfo = {0};
1006 reqInfo.msgInfo.addressList = NULL;
1007 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&reqInfo.msgInfo.addressList, unique_ptr_deleter);
1008 reqInfo.msgInfo.msgId = failed_msg_list[i];
1009 err = MsgStoGetMessage(reqInfo.msgInfo.msgId, &(reqInfo.msgInfo), &(reqInfo.sendOptInfo));
1011 if (err != MSG_SUCCESS) {
1012 MSG_DEBUG("MsgStoGetMessage() Error!! [%d]", err);
1015 if (reqInfo.msgInfo.msgType.subType == MSG_GET_MMS || \
1016 reqInfo.msgInfo.msgType.subType == MSG_NOTIFICATIONIND_MMS || \
1017 reqInfo.msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
1019 MSG_WARN("retrieve pending id[%d]", reqInfo.msgInfo.msgId);
1020 /* For retrieving failed msg (MMS)*/
1021 reqInfo.msgInfo.msgType.subType = MSG_RETRIEVE_MMS;
1022 reqInfo.msgInfo.folderId = MSG_OUTBOX_ID; // outbox fixed
1023 reqInfo.msgInfo.networkStatus = MSG_NETWORK_RETRIEVING;
1025 /* For sending failed msg */
1026 reqInfo.msgInfo.networkStatus = MSG_NETWORK_SENDING;
1029 msg_id_list_s msgIdList;
1030 msg_message_id_t msgIds[1];
1031 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
1033 msgIdList.nCount = 1;
1034 msgIds[0] = reqInfo.msgInfo.msgId;
1035 msgIdList.msgIdList = msgIds;
1037 err = MsgSubmitReq(&reqInfo, false);
1039 if (err == MSG_SUCCESS) {
1040 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
1041 if (err == MSG_SUCCESS)
1042 MSG_DEBUG("MsgSubmitReq() Success");
1044 MSG_DEBUG("MsgSubmitReq() Fail, [%d]", err);
1046 MSG_DEBUG("MsgSubmitReq() Fail, [%d]", err);
1050 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_RESEND_MESSAGE, err, (void**)ppEvent);
1056 #ifdef FEATURE_SMS_CDMA
1057 int MsgCheckUniquenessHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1061 msg_error_t err = MSG_SUCCESS;
1065 if (!pCmd || !ppEvent) {
1066 MSG_DEBUG("pCmd or ppEvent is null");
1070 // Get Incoming Message
1072 memcpy(&bInsert, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(bool));
1074 msg_message_id_t msgId;
1075 memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(bool)), sizeof(msg_message_id_t));
1077 MSG_UNIQUE_INDEX_S p_msg;
1078 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));
1080 MSG_DEBUG("Decoded Teleservice Msg Id = [%d]", p_msg.tele_msgId);
1081 MSG_DEBUG("Decoded Address = [%s]", p_msg.address);
1082 MSG_DEBUG("Decoded Sub Address = [%s]", p_msg.sub_address);
1084 err = MsgCheckUniqueness(bInsert, msgId, &p_msg);
1086 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_CHECK_UNIQUENESS, err, (void**)ppEvent);