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 <eventsystem.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"
36 #include "MsgCmdHandler.h"
37 #include "MsgDevicedWrapper.h"
38 #include "MsgMmsMessage.h"
41 /*==================================================================================================
42 FUNCTION IMPLEMENTATION
43 ==================================================================================================*/
44 int MsgSubmitReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
46 msg_error_t err = MSG_SUCCESS;
49 if (!pCmd || !ppEvent) {
50 MSG_DEBUG("pCmd or ppEvent is null");
57 MSG_REQUEST_INFO_S reqInfo = {0, };
58 MSG_PROXY_INFO_S proxyInfo = {0, };
60 reqInfo.msgInfo.addressList = NULL;
61 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&reqInfo.msgInfo.addressList, unique_ptr_deleter);
63 /* Get Message Request */
64 memcpy(&reqInfo.reqId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_request_id_t));
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));
69 MsgDecodeMsgInfo((char *)(pCmd->cmdData+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)), &reqInfo.msgInfo, &reqInfo.sendOptInfo);
72 if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE
73 && reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_MMS) {
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);
84 if (reqInfo.msgInfo.msgId > 0)
88 err = MsgSubmitReq(&reqInfo, false);
90 if (err == MSG_SUCCESS) {
91 MSG_DEBUG("Command Handle Success : MsgSubmitReq()");
93 MSG_DEBUG("Command Handle Fail : MsgSubmitReq()");
96 int reqId = reqInfo.reqId;
97 proxyInfo.sentMsgId = reqInfo.msgInfo.msgId;
99 MSG_DEBUG("REQID: %d, MSGID: %d", reqId, proxyInfo.sentMsgId);
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);
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);
118 pFileName = strstr(reqInfo.msgInfo.msgData, "MSG_");
119 strncpy(trId.pduFileName, pFileName, MAX_COMMON_INFO_SIZE);
121 MSG_SEC_DEBUG("java MMS msg trId:%s filepath:%s", trId.id, reqInfo.msgInfo.msgData);
123 MsgTransactionManager* tm = MsgTransactionManager::instance();
124 tm->setJavaMMSList(&trId);
128 ret[1] = reqInfo.msgInfo.msgId;
129 ret[2] = reqInfo.msgInfo.threadId;
131 /* Make Event Data */
132 eventSize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_SUBMIT_REQ, err, (void**)ppEvent);
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);
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));
144 msgIdList.nCount = 1;
145 msgIds[0] = reqInfo.msgInfo.msgId;
146 msgIdList.msgIdList = msgIds;
148 if ((err == MSG_SUCCESS || err != MSG_ERR_PLUGIN_STORAGE) && reqInfo.msgInfo.msgPort.valid == false) {
150 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
152 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
155 MSG_DEBUG("No need to broadcast storage change CB");
158 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
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;
170 int MsgRegSentStatusCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
173 if (!pCmd || !ppEvent) {
174 MSG_DEBUG("pCmd or ppEvent is null");
178 /* Get Message Request */
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);
183 /* storing dst fd in list */
184 MsgTransactionManager::instance()->setSentStatusCB(listenerFd);
186 /* Make Event Data */
187 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SENT_STATUS_CB, MSG_SUCCESS, (void**)ppEvent);
193 int MsgRegIncomingMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
196 if (!pCmd || !ppEvent) {
197 MSG_DEBUG("pCmd or ppEvent is null");
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);
205 /* storing dst fd in list */
206 MsgTransactionManager::instance()->setIncomingMsgCB(pCmdData);
208 /* Make Event Data */
209 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
215 int MsgRegIncomingMMSConfMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
218 if (!pCmd || !ppEvent) {
219 MSG_DEBUG("pCmd or ppEvent is null");
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);
227 /* storing dst fd in list */
228 MsgTransactionManager::instance()->setMMSConfMsgCB(pCmdData);
230 /* Make Event Data */
231 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
236 int MsgRegIncomingPushMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
239 if (!pCmd || !ppEvent) {
240 MSG_DEBUG("pCmd or ppEvent is null");
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);
248 /* storing dst fd in list */
249 MsgTransactionManager::instance()->setPushMsgCB(pCmdData);
250 /* MsgTransactionManager::instance()->sendPendigPushMsg(pCmdData); */
253 /* Make Event Data */
254 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_PUSH_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
261 int MsgRegIncomingCBMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
264 if (!pCmd || !ppEvent) {
265 MSG_DEBUG("pCmd or ppEvent is null");
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);
273 /* storing dst fd in list */
274 MsgTransactionManager::instance()->setCBMsgCB(pCmdData);
276 /* Make Event Data */
277 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_CB_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
283 int MsgRegIncomingSyncMLMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
286 if (!pCmd || !ppEvent) {
287 MSG_DEBUG("pCmd or ppEvent is null");
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);
295 /* storing dst fd in list */
296 MsgTransactionManager::instance()->setSyncMLMsgCB(pCmdData);
298 /* Make Event Data */
299 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
305 int MsgRegIncomingLBSMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
308 if (!pCmd || !ppEvent) {
309 MSG_DEBUG("pCmd or ppEvent is null");
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);
317 /* storing dst fd in list */
318 MsgTransactionManager::instance()->setLBSMsgCB(pCmdData);
320 /* Make Event Data */
321 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_LBS_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
327 int MsgRegSyncMLMsgOperationCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
330 if (!pCmd || !ppEvent) {
331 MSG_DEBUG("pCmd or ppEvent is null");
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);
339 /* storing dst fd in list */
340 MsgTransactionManager::instance()->setSyncMLMsgOperationCB(pCmdData);
342 /* Make Event Data */
343 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB, MSG_SUCCESS, (void**)ppEvent);
349 int MsgRegStorageChangeCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
352 if (!pCmd || !ppEvent) {
353 MSG_DEBUG("pCmd or ppEvent is null");
357 /* Get Message Request */
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);
362 /* storing dst fd in list */
363 MsgTransactionManager::instance()->setStorageChangeCB(listenerFd);
365 /* Make Event Data */
366 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_STORAGE_CHANGE_CB, MsgException::SUCCESS, (void**)ppEvent);
372 int MsgRegIncomingReportMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
375 if (!pCmd || !ppEvent) {
376 MSG_DEBUG("pCmd or ppEvent is null");
380 /* Get Message Request */
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);
385 /* storing dst fd in list */
386 MsgTransactionManager::instance()->setReportMsgCB(listenerFd);
388 /* Make Event Data */
389 int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_REPORT_MSG_INCOMING_CB, MsgException::SUCCESS, (void**)ppEvent);
395 int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
398 if (!pCmd || !ppEvent) {
399 MSG_DEBUG("pCmd or ppEvent is null");
403 /* Get Message Request */
404 MSG_SENT_STATUS_S* pStatus = (MSG_SENT_STATUS_S*) pCmd->cmdData;
406 MSG_DEBUG("REQID %d, STATUS %d", pStatus->reqId, pStatus->status);
408 /* storing dst fd in list */
409 MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(pStatus->reqId);
411 /* when no sent status cb is found */
413 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
416 MSG_DEBUG("REQID %d, listenerFD %d, handleAddr %x, msgId %d", pStatus->reqId, prxInfo->listenerFd, prxInfo->handleAddr, prxInfo->sentMsgId);
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);
423 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
426 unsigned long ret[3] = {0}; /* 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 (msgInfo.msgType.mainType == MSG_SMS_TYPE) {
485 /* Send system event */
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);
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);
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);
500 eventsystem_send_system_event(SYS_EVENT_INCOMMING_MSG, b);
505 if (isClass2msg == true) {
506 msgIdList.nCount = 2;
507 msgIds[0] = class2msgId;
508 msgIds[1] = msgInfo.msgId;
509 msgIdList.msgIdList = msgIds;
512 msgIdList.nCount = 1;
513 msgIds[0] = msgInfo.msgId;
514 msgIdList.msgIdList = msgIds;
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);
522 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
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);
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;
541 #ifdef FEATURE_SMS_CDMA
542 eventSize = MsgMakeEvent(&msgInfo.msgId, sizeof(msg_message_id_t), MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
544 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
547 if (msgInfo.bTextSms == false) {
548 MsgDeleteFile(msgInfo.msgData); /*ipc */
549 memset(msgInfo.msgData, 0x00, sizeof(msgInfo.msgData));
557 int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
561 if (!pCmd || !ppEvent) {
562 MSG_DEBUG("pCmd or ppEvent is null");
566 msg_error_t err = MSG_SUCCESS;
569 MSG_MESSAGE_INFO_S msgInfo;
570 msg_request_id_t reqID;
572 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
574 msgInfo.addressList = NULL;
575 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
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);
580 MSG_DEBUG(" pMsg = %s, pReqId = %d ", msgInfo.msgData, reqID);
581 MSG_DEBUG(" msgtype subtype is [%d]", msgInfo.msgType.subType);
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));
588 msgIdList.nCount = 1;
589 msgIds[0] = msgInfo.msgId;
590 msgIdList.msgIdList = msgIds;
592 MsgDbHandler *dbHandle = getDbHandle();
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.");
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;
607 msgInfo.addressList = tmpAddr;
608 msgInfo.nAddressCnt = tmpAddrCnt;
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 */
619 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
621 if (err != MSG_SUCCESS) {
622 MSG_DEBUG("MsgHandleMmsConfIncomingMsg failed.");
623 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
626 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
628 if (pMmsRecvData->msgAppId.valid == true) {
629 MSG_DEBUG("valid : %d, appId : %s", pMmsRecvData->msgAppId.valid, pMmsRecvData->msgAppId.appId);
631 msgInfo.bTextSms = true;
632 msgInfo.dataSize = 0 ;
633 memset(msgInfo.msgData, 0x00, sizeof(MMS_RECV_DATA_S));
636 /* broadcast to listener threads, here */
637 MsgTransactionManager::instance()->broadcastMMSConfCB(msgInfo.networkStatus, &msgInfo, pMmsRecvData);
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);
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);
647 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
648 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
652 /* make return event */
653 eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, MSG_SUCCESS, (void**)ppEvent);
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;
661 msgInfo.addressList = tmpAddr;
662 msgInfo.nAddressCnt = tmpAddrCnt;
664 MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(reqID);
666 /* when no sent status cb is found */
668 /* No need to update javaMMS sent messages */
669 javamms_list& listenerList = MsgTransactionManager::instance()->getJavaMMSList();
670 javamms_list::iterator it = listenerList.begin();
672 MSG_DEBUG("listenerList size:%d ", listenerList.size());
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;
684 /*msgData has MMS_RECV_DATA_S */
685 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
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;
697 MSG_DEBUG("prxInfo is NULL");
700 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
702 if (err != MSG_SUCCESS) {
703 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
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);
711 MSG_DEBUG("message-dialog: send success");
713 #if 0 /* disabled as per UX request to not show success notification : 2015. 09. 18 */
716 if (MsgSettingGetBool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &bTTS) != MSG_SUCCESS) {
717 MSG_DEBUG("MsgSettingGetBool is failed.");
721 MsgInsertTicker("Multimedia message sent.", MULTIMEDIA_MESSAGE_SENT, false, 0);
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 */
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);
741 #endif /*MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
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);
749 unsigned long ret[3] = {0}; /* reqid, status, object */
751 ret[0] = (unsigned long)reqID;
752 ret[1] = (unsigned long)msgInfo.networkStatus;
753 ret[2] = prxInfo->handleAddr;
755 /* Make Event Data for APP */
756 eventsize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
758 /* Send to listener thread, here */
759 MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventsize);
761 MsgTransactionManager::instance()->delProxyInfo(reqID);
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);
768 /*To avoid prevent memory leak.. this case will not occur. eventsize will be return as 0. */
779 int MsgIncomingPushMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
786 if (!pCmd || !ppEvent) {
787 MSG_DEBUG("pCmd or ppEvent is null");
791 MSG_PUSH_MESSAGE_DATA_S pushData;
792 memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
794 /* Get Incoming Message */
795 memcpy(&pushData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_PUSH_MESSAGE_DATA_S));
799 /* broadcast to listener threads, here */
800 MsgTransactionManager::instance()->broadcastPushMsgCB(MSG_SUCCESS, &pushData);
802 /* Make Event Data */
803 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
809 int MsgIncomingCBMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
813 msg_error_t err = MSG_SUCCESS;
817 if (!pCmd || !ppEvent) {
818 MSG_DEBUG("pCmd or ppEvent is null");
822 /* Get Incoming Message */
824 memset(&cbMsg, 0x00, sizeof(MSG_CB_MSG_S));
826 memcpy(&cbMsg, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_CB_MSG_S));
828 MSG_MESSAGE_INFO_S msgInfo;
829 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
831 msgInfo.addressList = NULL;
832 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
834 MsgDecodeMsgInfo((char *)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_CB_MSG_S), &msgInfo);
836 MSG_DEBUG("CB MSG ADDRESS COUNT=%d", msgInfo.nAddressCnt);
838 if (MsgStoAddCBMsg(&msgInfo) != MSG_SUCCESS) {
839 MSG_DEBUG("MsgStoAddCBMsg is fail");
842 if (msgInfo.msgType.classType == MSG_CLASS_0) {
843 MsgLaunchClass0(msgInfo.msgId);
844 MsgSoundPlayStart(&(msgInfo.addressList[0]), MSG_SOUND_PLAY_USER);
846 MsgInsertNotification(&msgInfo);
851 msg_id_list_s msgIdList;
852 msg_message_id_t msgIds[1];
853 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
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);
861 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)ppEvent);
868 int MsgIncomingSyncMLMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
871 if (!pCmd || !ppEvent) {
872 MSG_DEBUG("pCmd or ppEvent is null");
876 MSG_SYNCML_MESSAGE_DATA_S syncMLData;
877 memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
879 /* Get Incoming Message */
880 memcpy(&syncMLData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_SYNCML_MESSAGE_DATA_S));
884 /* broadcast to listener threads, here */
885 MsgTransactionManager::instance()->broadcastSyncMLMsgCB(MSG_SUCCESS, &syncMLData);
887 /* Make Event Data */
888 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
894 int MsgIncomingLBSMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
899 if (!pCmd || !ppEvent) {
900 MSG_DEBUG("pCmd or ppEvent is null");
904 MSG_LBS_MESSAGE_DATA_S lbsData;
905 memset(&lbsData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
907 /* Get Incoming Message */
908 memcpy(&lbsData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_LBS_MESSAGE_DATA_S));
910 /* broadcast to listener threads, here */
911 MsgTransactionManager::instance()->broadcastLBSMsgCB(MSG_SUCCESS, &lbsData);
913 /* Make Event Data */
914 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
920 int MsgSyncMLMsgOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
922 msg_error_t err = MSG_SUCCESS;
924 char* encodedData = NULL;
925 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
929 msg_message_id_t msgId = 0;
933 if (!pCmd || !ppEvent) {
934 MSG_DEBUG("pCmd or ppEvent is null");
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));
942 err = MsgStoGetSyncMLExtId(msgId, &extId);
944 if (err == MSG_SUCCESS) {
945 MSG_DEBUG("Command Handle Success : MsgStoGetSyncMLExtId()");
947 /* broadcast to listener threads, here */
948 MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, msgId, extId);
950 MSG_DEBUG("Command Handle Fail : MsgStoGetSyncMLExtId()");
953 /* Make Event Data to Client */
954 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SYNCML_OPERATION, err, (void**)ppEvent);
960 int MsgStorageChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
963 if (!pCmd || !ppEvent) {
964 MSG_DEBUG("pCmd or ppEvent is null");
968 msg_id_list_s msgIdList;
969 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
970 msg_storage_change_type_t storageChangeType;
972 memcpy(&msgIdList.nCount, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
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));
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));
981 char* encodedData = NULL;
982 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
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]);
991 /* broadcast to listener threads, here */
992 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, storageChangeType, &msgIdList);
994 if (msgIdList.msgIdList) {
995 delete [] msgIdList.msgIdList;
998 /* Make Event Data to Client */
999 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_STORAGE_CHANGE_IND, MSG_SUCCESS, (void**)ppEvent);
1004 int MsgResendMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1006 msg_error_t err = MSG_SUCCESS;
1009 if (!pCmd || !ppEvent) {
1010 MSG_DEBUG("pCmd or ppEvent is null");
1014 /* Get the msgIdList of sending failed message. */
1015 int *failed_msg_list = NULL;
1017 unique_ptr<int*, void(*)(int**)> failed_list(&failed_msg_list, unique_ptr_deleter);
1020 err = MsgStoGetFailedMessage(&failed_msg_list, &count);
1021 if (err != MSG_SUCCESS) {
1022 MSG_DEBUG("MsgStoGetFailedMessage() Error!! [%d]", err);
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));
1032 if (err != MSG_SUCCESS) {
1033 MSG_DEBUG("MsgStoGetMessage() Error!! [%d]", err);
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;
1045 /* For sending failed msg */
1046 reqInfo.msgInfo.networkStatus = MSG_NETWORK_SENDING;
1049 msg_id_list_s msgIdList;
1050 msg_message_id_t msgIds[1];
1051 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
1053 msgIdList.nCount = 1;
1054 msgIds[0] = reqInfo.msgInfo.msgId;
1055 msgIdList.msgIdList = msgIds;
1057 err = MsgSubmitReq(&reqInfo, false);
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");
1064 MSG_DEBUG("MsgSubmitReq() Fail, [%d]", err);
1066 MSG_DEBUG("MsgSubmitReq() Fail, [%d]", err);
1070 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_RESEND_MESSAGE, err, (void**)ppEvent);
1076 #ifdef FEATURE_SMS_CDMA
1077 int MsgCheckUniquenessHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1081 msg_error_t err = MSG_SUCCESS;
1085 if (!pCmd || !ppEvent) {
1086 MSG_DEBUG("pCmd or ppEvent is null");
1090 /* Get Incoming Message */
1092 memcpy(&bInsert, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(bool));
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));
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));
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);
1104 err = MsgCheckUniqueness(bInsert, msgId, &p_msg);
1106 eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_CHECK_UNIQUENESS, err, (void**)ppEvent);