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.
19 #include <sys/socket.h>
23 #include <security-server.h>
26 #include "MsgMemory.h"
27 #include "MsgException.h"
28 #include "MsgCppTypes.h"
29 #include "MsgContact.h"
30 #include "MsgIpcSocket.h"
31 #include "MsgGconfWrapper.h"
32 #include "MsgUtilFunction.h"
33 #include "MsgUtilFile.h"
35 #include "MsgCmdHandler.h"
36 #include "MsgSettingHandler.h"
37 #include "MsgStorageHandler.h"
38 #include "MsgPluginManager.h"
39 #include "MsgTransManager.h"
41 #define MSG_CHECK_PRIVILEGE
44 /*==================================================================================================
45 IMPLEMENTATION OF MsgTransactionManager - Member Functions
46 ==================================================================================================*/
47 MsgTransactionManager* MsgTransactionManager::pInstance = NULL;
48 MsgIpcServerSocket MsgTransactionManager::servSock;
51 MsgTransactionManager::MsgTransactionManager() : running(false), mx(), cv(), eventQueue()
54 #ifdef MSG_PENDING_PUSH_MESSAGE
57 statusCBFdMap.clear();
59 newMMSConfMsgCBList.clear();
60 newSyncMLMsgCBList.clear();
61 newLBSMsgCBList.clear();
63 operationSyncMLMsgCBList.clear();
64 storageChangeFdMap.clear();
68 // Fill in mMsgHandlers, as given in the below.
69 handlerMap[MSG_CMD_ADD_MSG] = &MsgAddMessageHandler;
70 handlerMap[MSG_CMD_ADD_SYNCML_MSG] = &MsgAddSyncMLMessageHandler;
71 handlerMap[MSG_CMD_UPDATE_MSG] = &MsgUpdateMessageHandler;
72 handlerMap[MSG_CMD_UPDATE_READ] = &MsgUpdateReadStatusHandler;
73 handlerMap[MSG_CMD_UPDATE_PROTECTED] = &MsgUpdateProtectedStatusHandler;
74 handlerMap[MSG_CMD_DELETE_MSG] = &MsgDeleteMessageHandler;
75 handlerMap[MSG_CMD_DELALL_MSGINFOLDER] = &MsgDeleteAllMessageInFolderHandler;
76 handlerMap[MSG_CMD_MOVE_MSGTOFOLDER] = &MsgMoveMessageToFolderHandler;
77 handlerMap[MSG_CMD_MOVE_MSGTOSTORAGE] = &MsgMoveMessageToStorageHandler;
78 handlerMap[MSG_CMD_COUNT_MSG] = &MsgCountMessageHandler;
79 handlerMap[MSG_CMD_GET_MSG] = &MsgGetMessageHandler;
80 handlerMap[MSG_CMD_GET_FOLDERVIEWLIST] = &MsgGetFolderViewListHandler;
82 handlerMap[MSG_CMD_ADD_FOLDER] = &MsgAddFolderHandler;
83 handlerMap[MSG_CMD_UPDATE_FOLDER] = &MsgUpdateFolderHandler;
84 handlerMap[MSG_CMD_DELETE_FOLDER] = &MsgDeleteFolderHandler;
85 handlerMap[MSG_CMD_GET_FOLDERLIST] = &MsgGetFolderListHandler;
87 handlerMap[MSG_CMD_ADD_FILTER] = &MsgAddFilterHandler;
88 handlerMap[MSG_CMD_UPDATE_FILTER] = &MsgUpdateFilterHandler;
89 handlerMap[MSG_CMD_DELETE_FILTER] = &MsgDeleteFilterHandler;
90 handlerMap[MSG_CMD_GET_FILTERLIST] = &MsgGetFilterListHandler;
91 handlerMap[MSG_CMD_SET_FILTER_OPERATION] = &MsgSetFilterOperationHandler;
92 handlerMap[MSG_CMD_GET_FILTER_OPERATION] = &MsgGetFilterOperationHandler;
93 handlerMap[MSG_CMD_SET_FILTER_ACTIVATION] = &MsgSetFilterActivationHandler;
95 handlerMap[MSG_CMD_GET_MSG_TYPE] = &MsgGetMsgTypeHandler;
97 handlerMap[MSG_CMD_SUBMIT_REQ] = &MsgSubmitReqHandler;
98 handlerMap[MSG_CMD_CANCEL_REQ] = &MsgCancelReqHandler;
100 handlerMap[MSG_CMD_REG_SENT_STATUS_CB] = &MsgRegSentStatusCallbackHandler;
101 handlerMap[MSG_CMD_REG_STORAGE_CHANGE_CB] = &MsgRegStorageChangeCallbackHandler;
102 handlerMap[MSG_CMD_REG_INCOMING_MSG_CB] = &MsgRegIncomingMsgCallbackHandler;
103 handlerMap[MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB] = &MsgRegIncomingMMSConfMsgCallbackHandler;
104 handlerMap[MSG_CMD_REG_INCOMING_SYNCML_MSG_CB] = &MsgRegIncomingSyncMLMsgCallbackHandler;
105 handlerMap[MSG_CMD_REG_INCOMING_PUSH_MSG_CB] = &MsgRegIncomingPushMsgCallbackHandler;
106 handlerMap[MSG_CMD_REG_INCOMING_CB_MSG_CB] = &MsgRegIncomingCBMsgCallbackHandler;
107 handlerMap[MSG_CMD_REG_INCOMING_LBS_MSG_CB] = &MsgRegIncomingLBSMsgCallbackHandler;
108 handlerMap[MSG_CMD_REG_SYNCML_MSG_OPERATION_CB] = &MsgRegSyncMLMsgOperationCallbackHandler;
109 handlerMap[MSG_CMD_REG_REPORT_MSG_INCOMING_CB] = &MsgRegIncomingReportMsgCallbackHandler;
111 handlerMap[MSG_CMD_PLG_SENT_STATUS_CNF] = &MsgSentStatusHandler;
112 handlerMap[MSG_CMD_PLG_STORAGE_CHANGE_IND] = &MsgStorageChangeHandler;
113 handlerMap[MSG_CMD_PLG_INCOMING_MSG_IND] = &MsgIncomingMsgHandler;
114 handlerMap[MSG_CMD_PLG_INCOMING_MMS_CONF] = &MsgIncomingMMSConfMsgHandler;
115 handlerMap[MSG_CMD_PLG_INCOMING_PUSH_IND] = &MsgIncomingPushMsgHandler;
116 handlerMap[MSG_CMD_PLG_INCOMING_CB_IND] = &MsgIncomingCBMsgHandler;
118 handlerMap[MSG_CMD_PLG_INCOMING_SYNCML_IND] = &MsgIncomingSyncMLMsgHandler;
119 handlerMap[MSG_CMD_PLG_INCOMING_LBS_IND] = &MsgIncomingLBSMsgHandler;
120 handlerMap[MSG_CMD_PLG_INIT_SIM_BY_SAT] = &MsgInitSimBySatHandler;
122 handlerMap[MSG_CMD_GET_THREADVIEWLIST] = &MsgGetThreadViewListHandler;
123 handlerMap[MSG_CMD_GET_CONVERSATIONVIEWLIST] = &MsgGetConversationViewListHandler;
124 handlerMap[MSG_CMD_DELETE_THREADMESSAGELIST] = &MsgDeleteThreadMessageListHandler;
126 handlerMap[MSG_CMD_GET_CONTACT_COUNT] = &MsgCountMsgByContactHandler;
127 handlerMap[MSG_CMD_GET_QUICKPANEL_DATA] = &MsgGetQuickPanelDataHandler;
128 handlerMap[MSG_CMD_COUNT_BY_MSGTYPE] = &MsgCountMsgByTypeHandler;
129 handlerMap[MSG_CMD_RESET_DB] = &MsgResetDatabaseHandler;
130 handlerMap[MSG_CMD_GET_MEMSIZE] = &MsgGetMemSizeHandler;
132 handlerMap[MSG_CMD_BACKUP_MESSAGE] = &MsgBackupMessageHandler;
133 handlerMap[MSG_CMD_RESTORE_MESSAGE] = &MsgRestoreMessageHandler;
135 handlerMap[MSG_CMD_UPDATE_THREAD_READ] = &MsgUpdateThreadReadStatusHandler;
137 handlerMap[MSG_CMD_SYNCML_OPERATION] = &MsgSyncMLMsgOperationHandler;
138 handlerMap[MSG_CMD_GET_REPORT_STATUS] = &MsgGetReportStatusHandler;
140 handlerMap[MSG_CMD_GET_THREAD_ID_BY_ADDRESS] = &MsgGetThreadIdByAddressHandler;
141 handlerMap[MSG_CMD_GET_THREAD_INFO] = &MsgGetThreadInfoHandler;
142 handlerMap[MSG_CMD_GET_SMSC_OPT] = &MsgGetConfigHandler;
143 handlerMap[MSG_CMD_GET_CB_OPT] = &MsgGetConfigHandler;
144 handlerMap[MSG_CMD_GET_SMS_SEND_OPT] = &MsgGetConfigHandler;
145 handlerMap[MSG_CMD_GET_MMS_SEND_OPT] = &MsgGetConfigHandler;
146 handlerMap[MSG_CMD_GET_MMS_RECV_OPT] = &MsgGetConfigHandler;
147 handlerMap[MSG_CMD_GET_PUSH_MSG_OPT] = &MsgGetConfigHandler;
148 handlerMap[MSG_CMD_GET_VOICE_MSG_OPT] = &MsgGetConfigHandler;
149 handlerMap[MSG_CMD_GET_GENERAL_MSG_OPT] = &MsgGetConfigHandler;
150 handlerMap[MSG_CMD_GET_MSG_SIZE_OPT] = &MsgGetConfigHandler;
152 handlerMap[MSG_CMD_SET_SMSC_OPT] = &MsgSetConfigHandler;
153 handlerMap[MSG_CMD_SET_CB_OPT] = &MsgSetConfigHandler;
154 handlerMap[MSG_CMD_SET_SMS_SEND_OPT] = &MsgSetConfigHandler;
155 handlerMap[MSG_CMD_SET_MMS_SEND_OPT] = &MsgSetConfigHandler;
156 handlerMap[MSG_CMD_SET_MMS_RECV_OPT] = &MsgSetConfigHandler;
157 handlerMap[MSG_CMD_SET_PUSH_MSG_OPT] = &MsgSetConfigHandler;
158 handlerMap[MSG_CMD_SET_VOICE_MSG_OPT] = &MsgSetConfigHandler;
159 handlerMap[MSG_CMD_SET_GENERAL_MSG_OPT] = &MsgSetConfigHandler;
160 handlerMap[MSG_CMD_SET_MSG_SIZE_OPT] = &MsgSetConfigHandler;
162 handlerMap[MSG_CMD_ADD_PUSH_EVENT] = &MsgAddPushEventHandler;
163 handlerMap[MSG_CMD_DELETE_PUSH_EVENT] = &MsgDeletePushEventHandler;
164 handlerMap[MSG_CMD_UPDATE_PUSH_EVENT] = &MsgUpdatePushEventHandler;
165 handlerMap[MSG_CMD_DELETE_MESSAGE_BY_LIST] = &MsgDeleteMessageByListHandler;
166 handlerMap[MSG_CMD_ADD_SIM_MSG] = &MsgAddSimMessageHandler;
167 handlerMap[MSG_CMD_PLG_RESEND_MESSAGE] = &MsgResendMessageHandler;
168 #ifdef MSG_PENDING_PUSH_MESSAGE
169 handlerMap[MSG_CMD_SEND_PENDING_PUSH_MESSAGE] = &MsgSendPendingPushMsgHandler;
171 #ifdef FEATURE_SMS_CDMA
172 handlerMap[MSG_CMD_PLG_CHECK_UNIQUENESS] = &MsgCheckUniquenessHandler;
174 handlerMap[MSG_CMD_UPDATE_IMSI] = &MsgUpdateIMSIHandler;
178 MsgTransactionManager::~MsgTransactionManager()
180 // pthread_cond_init(&retCV, NULL); // = PTHREAD_COND_INITIALIZER;
185 MsgTransactionManager* MsgTransactionManager::instance()
188 pInstance = new MsgTransactionManager();
193 static void* worker_event_queue(void* arg)
195 MsgTransactionManager::instance()->workerEventQueue();
199 void MsgTransactionManager::run()
201 servSock.open(MSG_SOCKET_PATH);
203 fd_set readfds = servSock.fdSet();
206 MSG_DEBUG("Start Transaction Manager");
208 // Set Msg FW Ready Flag
209 if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true) != MSG_SUCCESS)
210 MSG_DEBUG("MsgSettingSetBool FAIL : VCONFKEY_MSG_SERVER_READY");
211 MSG_INFO("### VCONFKEY_MSG_SERVER_READY ###");
213 /* running worker for plg task */
215 if (pthread_create (&tv, NULL, &worker_event_queue, NULL) != 0) {
216 THROW(MsgException::SERVER_READY_ERROR, "cannot create thread [%d]", errno);
221 readfds = servSock.fdSet();
222 nfds = servSock.maxFd();
224 MSG_DEBUG("Wait For Select() : nfds %d", nfds);
229 if(select(nfds, &readfds, NULL, NULL, NULL) == -1) {
230 THROW(MsgException::SELECT_ERROR, "select error : %s", strerror(errno));
235 for (int i=0 ; i < nfds; i++)
237 if (FD_ISSET(i, &readfds))
239 if (i == servSock.fd()) // if it is socket connection request
246 catch (MsgException& e)
248 MSG_FATAL("%s", e.what());
252 MSG_FATAL("%s", e.what());
261 void MsgTransactionManager::write(int fd, const char* buf, int len)
263 servSock.write(fd, buf, len);
267 void MsgTransactionManager::insertSentMsg(int reqId, MSG_PROXY_INFO_S* pPrxInfo)
269 if (pPrxInfo == NULL)
270 THROW(MsgException::SENT_STATUS_ERROR, "Input Parameter is NULL");
272 MSG_DEBUG("msg for submit: reqId %d listenerFd %d handleAddr %x", reqId, pPrxInfo->listenerFd, pPrxInfo->handleAddr);
274 fd_map::iterator it = statusCBFdMap.find(pPrxInfo->listenerFd);
276 if (it == statusCBFdMap.end()) { // if the status CB is not registered
277 MSG_DEBUG("No sent_status registered for fd %d", pPrxInfo->listenerFd);
279 sentMsgMap.insert(make_pair(reqId, *pPrxInfo));
284 MSG_PROXY_INFO_S* MsgTransactionManager::getProxyInfo(int reqId)
286 sentmsg_map::iterator it = sentMsgMap.find(reqId);
288 if (it == sentMsgMap.end())
290 MSG_DEBUG("No sent status cb found");
294 return &(it->second);
298 void MsgTransactionManager::delProxyInfo(int reqId)
300 sentmsg_map::iterator it = sentMsgMap.find(reqId);
302 if (it == sentMsgMap.end())
304 THROW(MsgException::SENT_STATUS_ERROR, "channel info does not exist");
307 sentMsgMap.erase(it);
310 void MsgTransactionManager::workerEventQueue()
312 MSG_CMD_S* pCmd = NULL;
313 int (*pfHandler)(const MSG_CMD_S*, char**) = NULL;
314 char* pEventData = NULL;
315 AutoPtr<char> eventBuf(&pEventData);
321 while (!eventQueue.front(&pCmd)) { /* if no item, wait */
322 MSG_DEBUG ("waiting for task");
323 cv.wait(mx.pMutex());
325 eventQueue.pop_front(); /* pop it from queue*/
329 MSG_FATAL("pCmd NULL");
333 memcpy (&fd, pCmd->cmdCookie, sizeof(int));
335 MSG_FATAL("fd [%d] < 0", fd);
336 g_free (pCmd); pCmd = NULL;
339 pfHandler = handlerMap[pCmd->cmdType];
341 MSG_FATAL("No handler for %d", pCmd->cmdType);
342 g_free (pCmd); pCmd = NULL;
346 // run handler function
347 int eventSize = pfHandler(pCmd, &pEventData);
349 if (eventSize == 0 || pEventData == NULL) {
350 MSG_FATAL("event size[%d] = 0 or event data = NULL", eventSize);
351 g_free (pCmd); pCmd = NULL;
355 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
356 servSock.write(fd, pEventData, eventSize);
357 g_free (pCmd); pCmd = NULL;
361 void MsgTransactionManager::handleRequest(int fd)
365 MSG_DEBUG("Event from fd %d", fd);
368 AutoPtr<char> wrap(&buf);
370 int ret = servSock.read(fd, &buf, &len);
372 if( ret == CLOSE_CONNECTION_BY_SIGNAL || ret == CLOSE_CONNECTION_BY_USER || ret < 0)
374 MSG_DEBUG("Read value [%d]", ret);
380 THROW(MsgException::INVALID_RESULT, "read buffer size <= 0");
382 char* pEventData = NULL;
383 AutoPtr<char> eventBuf(&pEventData);
387 // decoding cmd from APP
388 MSG_CMD_S* pCmd = (MSG_CMD_S*) buf;
389 MSG_DEBUG("Command Type [%d : %s]", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType));
391 if (pCmd->cmdType > MSG_CMD_NUM)
392 THROW(MsgException::OUT_OF_RANGE, "request CMD is not defined");
395 // if (checkPrivilege(pCmd->cmdType, pCmd->cmdCookie) == false) {
396 if (checkPrivilege(fd, pCmd->cmdType) == false) {
397 MSG_DEBUG("No Privilege rule. Not allowed.");
398 #ifdef MSG_CHECK_PRIVILEGE
399 eventSize = sizeof(MSG_EVENT_S);
401 pEventData = new char[eventSize];
403 MSG_EVENT_S* pMsgEvent = (MSG_EVENT_S*)pEventData;
405 pMsgEvent->eventType = pCmd->cmdType;
406 pMsgEvent->result = MSG_ERR_PERMISSION_DENIED;
408 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
409 servSock.write(fd, pEventData, eventSize);
415 // determine the handler based on pCmd->cmdType
416 int (*pfHandler)(const MSG_CMD_S*, char**) = NULL;
418 switch (pCmd->cmdType) {
419 case MSG_CMD_PLG_SENT_STATUS_CNF:
420 case MSG_CMD_PLG_STORAGE_CHANGE_IND:
421 case MSG_CMD_PLG_INCOMING_MSG_IND:
422 case MSG_CMD_PLG_INCOMING_MMS_CONF:
423 case MSG_CMD_PLG_INCOMING_SYNCML_IND:
424 case MSG_CMD_PLG_INCOMING_LBS_IND:
425 case MSG_CMD_PLG_INIT_SIM_BY_SAT:
426 case MSG_CMD_PLG_INCOMING_PUSH_IND:
427 case MSG_CMD_PLG_INCOMING_CB_IND: {
429 MSG_CMD_S* pCmdDup = (MSG_CMD_S*) calloc (1, len); /* pCmdDup should be freed afterward */
430 memcpy (pCmdDup, pCmd, len);
431 memcpy (pCmdDup->cmdCookie, &fd, sizeof(int)); /* Now, cmdCookie keeps fd for return */
433 mx.lock(); /* aquire lock before adding cmd */
434 eventQueue.push_back(pCmdDup);
435 cv.signal(); /* wake up worker */
440 pfHandler = handlerMap[pCmd->cmdType];
442 THROW(MsgException::INVALID_PARAM, "No handler for %d", pCmd->cmdType);
444 // run handler function
445 eventSize = pfHandler(pCmd, &pEventData);
447 if (eventSize == 0 || pEventData == NULL)
448 THROW(MsgException::INVALID_RESULT, "event size = 0 or event data = NULL");
450 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
452 servSock.write(fd, pEventData, eventSize);
459 // terminating the socket connection between ipc server and ipc client
460 void MsgTransactionManager::cleanup(int fd)
466 MSG_DEBUG("fd %d disonnected", fd);
468 // remove sent msg info for fd
469 sentmsg_map::iterator sentmsg_it = sentMsgMap.begin();
471 for (; sentmsg_it != sentMsgMap.end(); sentmsg_it++)
473 if (sentmsg_it->second.listenerFd == fd)
475 sentmsg_it->second.listenerFd = 0;
476 sentmsg_it->second.handleAddr = 0;
480 // remove sent status callback for fd
481 statusCBFdMap.erase(fd);
483 MSG_DEBUG("After erase fd [%d], statusCBFdMap has below.", fd);
484 fd_map::iterator it = statusCBFdMap.begin();
485 for (; it!=statusCBFdMap.end(); ++it)
486 MSG_DEBUG("[%d]", it->first);
488 // remove all newMsgCBs for fd
489 newmsg_list::iterator newmsg_it = newMsgCBList.begin();
491 while (newmsg_it != newMsgCBList.end())
493 if (newmsg_it->listenerFd == fd)
495 newmsg_it = newMsgCBList.erase(newmsg_it);
503 // remove all newMMSConfMsgCBs for fd
504 mmsconf_list::iterator mmsconf_it = newMMSConfMsgCBList.begin();
506 while (mmsconf_it != newMMSConfMsgCBList.end())
508 if (mmsconf_it->listenerFd == fd)
510 mmsconf_it = newMMSConfMsgCBList.erase(mmsconf_it);
518 // remove all newSyncMLMsgCBs for fd
519 syncmlmsg_list::iterator syncmlmsg_it = newSyncMLMsgCBList.begin();
521 while (syncmlmsg_it != newSyncMLMsgCBList.end())
523 if (syncmlmsg_it->listenerFd == fd)
525 syncmlmsg_it = newSyncMLMsgCBList.erase(syncmlmsg_it);
533 // remove all newLBSMsgCBs for fd
534 lbsmsg_list::iterator lbsmsg_it = newLBSMsgCBList.begin();
536 while (lbsmsg_it != newLBSMsgCBList.end())
538 if (lbsmsg_it->listenerFd == fd)
540 lbsmsg_it = newLBSMsgCBList.erase(lbsmsg_it);
548 // remove all newPushMsgCBs for fd
549 pushmsg_list::iterator pushmsg_it = newPushMsgCBList.begin();
551 while (pushmsg_it != newPushMsgCBList.end())
553 if (pushmsg_it->listenerFd == fd)
555 pushmsg_it = newPushMsgCBList.erase(pushmsg_it);
563 // remove all newCBMsgCBs for fd
564 cbmsg_list::iterator cbmsg_it = newCBMsgCBList.begin();
565 //bool bSave = false;
567 while (cbmsg_it != newCBMsgCBList.end())
569 if (cbmsg_it->listenerFd == fd)
571 cbmsg_it = newCBMsgCBList.erase(cbmsg_it);
575 //if (cbmsg_it->bsave == true)
581 // remove all operationSyncMLMsgCBs for fd
582 syncmlop_list::iterator syncmlop_it = operationSyncMLMsgCBList.begin();
584 while (syncmlop_it != operationSyncMLMsgCBList.end())
586 if (syncmlop_it->listenerFd == fd)
588 syncmlop_it = operationSyncMLMsgCBList.erase(syncmlop_it);
596 // remove storage change callback for fd
597 storageChangeFdMap.erase(fd);
599 MSG_DEBUG("After erase fd [%d], storageChangeFdMap has below.", fd);
600 it = storageChangeFdMap.begin();
601 for (; it!=storageChangeFdMap.end(); ++it)
602 MSG_DEBUG("[%d]", it->first);
604 // remove report msg incoming callback for fd
605 reportMsgCBFdMap.erase(fd);
607 MSG_DEBUG("After erase fd [%d], reportMsgCBFdMap has below.", fd);
608 it = reportMsgCBFdMap.begin();
609 for (; it!=reportMsgCBFdMap.end(); ++it)
610 MSG_DEBUG("[%d]", it->first);
617 bool MsgTransactionManager::checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType)
619 bool bAllowed = true;
622 case MSG_CMD_GET_MSG:
623 case MSG_CMD_COUNT_MSG:
624 case MSG_CMD_COUNT_BY_MSGTYPE:
625 case MSG_CMD_REG_INCOMING_MSG_CB:
626 case MSG_CMD_REG_INCOMING_CB_MSG_CB:
627 case MSG_CMD_REG_INCOMING_PUSH_MSG_CB:
628 case MSG_CMD_REG_SENT_STATUS_CB:
629 case MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB:
630 case MSG_CMD_REG_INCOMING_SYNCML_MSG_CB:
631 case MSG_CMD_REG_INCOMING_LBS_MSG_CB:
632 case MSG_CMD_REG_SYNCML_MSG_OPERATION_CB:
633 case MSG_CMD_REG_REPORT_MSG_INCOMING_CB:
634 case MSG_CMD_GET_CONTACT_COUNT:
635 case MSG_CMD_GET_FOLDERLIST:
636 case MSG_CMD_GET_QUICKPANEL_DATA:
637 case MSG_CMD_GET_MEMSIZE:
638 case MSG_CMD_BACKUP_MESSAGE:
639 case MSG_CMD_REG_STORAGE_CHANGE_CB:
640 case MSG_CMD_GET_REPORT_STATUS:
641 case MSG_CMD_GET_THREAD_ID_BY_ADDRESS:
642 case MSG_CMD_GET_THREAD_INFO:
643 case MSG_CMD_SYNCML_OPERATION:
644 case MSG_CMD_GET_FILTERLIST:
645 case MSG_CMD_GET_FILTER_OPERATION:
646 case MSG_CMD_GET_SMSC_OPT:
647 case MSG_CMD_GET_CB_OPT:
648 case MSG_CMD_GET_SMS_SEND_OPT:
649 case MSG_CMD_GET_MMS_SEND_OPT:
650 case MSG_CMD_GET_MMS_RECV_OPT:
651 case MSG_CMD_GET_PUSH_MSG_OPT:
652 case MSG_CMD_GET_VOICE_MSG_OPT:
653 case MSG_CMD_GET_GENERAL_MSG_OPT:
654 case MSG_CMD_GET_MSG_SIZE_OPT:
656 int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::read", "rw");
657 if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
658 MSG_DEBUG("No msg-service::read rw rule.");
663 case MSG_CMD_SUBMIT_REQ:
664 case MSG_CMD_SET_CB_OPT:
665 case MSG_CMD_ADD_PUSH_EVENT:
666 case MSG_CMD_DELETE_PUSH_EVENT:
667 case MSG_CMD_UPDATE_PUSH_EVENT:
668 case MSG_CMD_ADD_MSG:
669 case MSG_CMD_ADD_SYNCML_MSG:
670 case MSG_CMD_UPDATE_MSG:
671 case MSG_CMD_UPDATE_READ:
672 case MSG_CMD_UPDATE_PROTECTED:
673 case MSG_CMD_DELETE_MSG:
674 case MSG_CMD_DELALL_MSGINFOLDER:
675 case MSG_CMD_MOVE_MSGTOFOLDER:
676 case MSG_CMD_MOVE_MSGTOSTORAGE:
677 case MSG_CMD_DELETE_THREADMESSAGELIST:
678 case MSG_CMD_ADD_FOLDER:
679 case MSG_CMD_UPDATE_FOLDER:
680 case MSG_CMD_DELETE_FOLDER:
681 case MSG_CMD_RESET_DB:
682 case MSG_CMD_RESTORE_MESSAGE:
683 case MSG_CMD_DELETE_MESSAGE_BY_LIST:
684 case MSG_CMD_UPDATE_THREAD_READ:
685 case MSG_CMD_ADD_FILTER:
686 case MSG_CMD_UPDATE_FILTER:
687 case MSG_CMD_DELETE_FILTER:
688 case MSG_CMD_SET_FILTER_OPERATION:
689 case MSG_CMD_SET_FILTER_ACTIVATION:
690 case MSG_CMD_SET_SMSC_OPT:
691 case MSG_CMD_SET_SMS_SEND_OPT:
692 case MSG_CMD_SET_MMS_SEND_OPT:
693 case MSG_CMD_SET_MMS_RECV_OPT:
694 case MSG_CMD_SET_PUSH_MSG_OPT:
695 case MSG_CMD_SET_VOICE_MSG_OPT:
696 case MSG_CMD_SET_GENERAL_MSG_OPT:
697 case MSG_CMD_SET_MSG_SIZE_OPT:
699 int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::write", "rw");
700 if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
701 MSG_DEBUG("No msg-service::write rw rule.");
711 bool MsgTransactionManager::checkPrivilege(MSG_CMD_TYPE_T CmdType, const char *pCookie)
713 if (CmdType >= MSG_CMD_PLG_SENT_STATUS_CNF && CmdType <= MSG_CMD_PLG_INIT_SIM_BY_SAT)
715 MSG_DEBUG("Request from Plug-in");
719 // Get Cookie from APP
722 MSG_DEBUG("Cookie is NULL");
727 for (int i = 0; i < MAX_COOKIE_LEN; i++)
729 MSG_DEBUG("cookie : [%02x]", pCookie[i]);
737 cookieSize = security_server_get_cookie_size();
739 MSG_DEBUG("cookie size : [%d]", cookieSize);
741 // char cookie[MAX_COOKIE_LEN];
744 if (CmdType == MSG_CMD_REG_INCOMING_SYNCML_MSG_CB)
746 MSG_DEBUG("get GID for message_sync");
747 gid = security_server_get_gid("message_sync");
749 else if (CmdType == MSG_CMD_REG_INCOMING_LBS_MSG_CB)
751 MSG_DEBUG("get GID for message_lbs");
752 gid = security_server_get_gid("message_lbs");
756 MSG_DEBUG("get GID for message");
757 gid = security_server_get_gid("message");
760 MSG_DEBUG("gid [%d]", gid);
764 retVal = security_server_check_privilege(pCookie, gid);
768 if (retVal == SECURITY_SERVER_API_ERROR_ACCESS_DENIED)
770 MSG_DEBUG("access denied !! [%d]", retVal);
774 MSG_DEBUG("fail to check privilege [%d]", retVal);
780 MSG_DEBUG("privilege check success !!");
786 void MsgTransactionManager::setSentStatusCB(int listenerFd)
789 THROW(MsgException::INVALID_PARAM,"InParam Error: listenerFd %d",listenerFd);
791 statusCBFdMap[listenerFd] = true;
795 void MsgTransactionManager::setIncomingMsgCB(MSG_CMD_REG_INCOMING_MSG_CB_S *pCbInfo)
799 MSG_FATAL("cbinfo NULL");
803 newmsg_list::iterator it = newMsgCBList.begin();
805 for (; it != newMsgCBList.end(); it++)
807 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && (it->port == pCbInfo->port))
809 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d, port %d", it->listenerFd, it->msgType, it->port);
814 newMsgCBList.push_back(*pCbInfo);
818 void MsgTransactionManager::setMMSConfMsgCB(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCbInfo)
822 MSG_FATAL("cbinfo NULL");
826 mmsconf_list::iterator it = newMMSConfMsgCBList.begin();
828 for (; it != newMMSConfMsgCBList.end(); it++)
830 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && (!strncmp(it->appId, pCbInfo->appId, MAX_MMS_JAVA_APPID_LEN)))
832 MSG_DEBUG("Duplicated MMSConfMessageCB info fd:%d, mType:%d, appId:%s", it->listenerFd, it->msgType, it->appId);
837 newMMSConfMsgCBList.push_back(*pCbInfo);
841 void MsgTransactionManager::setPushMsgCB(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCbInfo)
845 MSG_FATAL("cbinfo NULL");
849 pushmsg_list::iterator it = newPushMsgCBList.begin();
851 for (; it != newPushMsgCBList.end(); it++)
853 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && !strncmp(it->appId, pCbInfo->appId, MAX_WAPPUSH_ID_LEN))
855 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
860 newPushMsgCBList.push_back(*pCbInfo);
863 void MsgTransactionManager::setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo)
868 MSG_FATAL("cbinfo NULL");
872 cbmsg_list::iterator it = newCBMsgCBList.begin();
874 for (; it != newCBMsgCBList.end(); it++)
876 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
878 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
882 MSG_DEBUG("bSave : [%d]", pCbInfo->bsave);
885 if(MsgSettingSetBool(CB_SAVE, pCbInfo->bsave) != MSG_SUCCESS)
886 MSG_DEBUG("MsgSettingSetBool FAIL: CB_SAVE");
889 newCBMsgCBList.push_back(*pCbInfo);
895 void MsgTransactionManager::setSyncMLMsgCB(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCbInfo)
899 MSG_FATAL("cbinfo NULL");
903 syncmlmsg_list::iterator it = newSyncMLMsgCBList.begin();
905 for (; it != newSyncMLMsgCBList.end(); it++)
907 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
909 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
914 newSyncMLMsgCBList.push_back(*pCbInfo);
918 void MsgTransactionManager::setLBSMsgCB(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCbInfo)
922 MSG_FATAL("cbinfo NULL");
926 lbsmsg_list::iterator it = newLBSMsgCBList.begin();
928 for (; it != newLBSMsgCBList.end(); it++)
930 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
932 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
937 newLBSMsgCBList.push_back(*pCbInfo);
941 void MsgTransactionManager::setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *pTrId)
945 MSG_FATAL("trId NULL");
949 javamms_list::iterator it;
951 for (it = javaMMSList.begin(); it != javaMMSList.end(); it++)
953 if (!strcmp(it->id, pTrId->id))
955 MSG_SEC_DEBUG("Duplicated javaMMS transaction Id:%s", it->id);
960 javaMMSList.push_back(*pTrId);
964 void MsgTransactionManager::setSyncMLMsgOperationCB(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCbInfo)
968 MSG_FATAL("cbinfo NULL");
972 syncmlop_list::iterator it = operationSyncMLMsgCBList.begin();
974 for (; it != operationSyncMLMsgCBList.end(); it++)
976 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
978 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
983 operationSyncMLMsgCBList.push_back(*pCbInfo);
987 void MsgTransactionManager::setStorageChangeCB(int listenerFd)
990 THROW(MsgException::INVALID_PARAM,"InParam Error: listenerFd %d", listenerFd);
992 storageChangeFdMap[listenerFd] = true;
996 void MsgTransactionManager::setReportMsgCB(int listenerFd)
999 THROW(MsgException::INVALID_PARAM,"InParam Error: listenerFd %d", listenerFd);
1001 reportMsgCBFdMap[listenerFd] = true;
1005 javamms_list& MsgTransactionManager::getJavaMMSList()
1011 void MsgTransactionManager::broadcastIncomingMsgCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo)
1015 if ((msgInfo->msgPort.valid == true) && (msgInfo->msgPort.dstPort == MSG_LBS_PORT)) {
1016 MSG_DEBUG("Message for LBS.");
1018 if (msgInfo->bTextSms == false) {
1019 MSG_DEBUG("msgInfo->bTextSms == false");
1023 char* pFileData = NULL;
1024 AutoPtr<char> buf(&pFileData);
1026 // if (MsgOpenAndReadFile(msgInfo->msgData, &pFileData, &fileSize) == true)
1027 // MsgLbsSms(pFileData, fileSize);
1029 MSG_DEBUG("MsgOpenAndReadFile failed.");
1031 // MsgLbsSms(msgInfo->msgText, (int)msgInfo->dataSize);
1036 char* pEventData = NULL;
1037 AutoPtr<char> eventBuf(&pEventData);
1039 char* encodedData = NULL;
1040 AutoPtr<char> buf(&encodedData);
1041 int dataSize = MsgEncodeMsgInfo(msgInfo, &encodedData);
1043 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)(&pEventData));
1045 MSG_DEBUG("valid %d dstport %d", msgInfo->msgPort.valid, msgInfo->msgPort.dstPort);
1047 newmsg_list::iterator it = newMsgCBList.begin();
1049 for (; it != newMsgCBList.end(); it++)
1051 MSG_DEBUG("fd %d dstport %d",it->listenerFd, it->port);
1053 if ((msgInfo->msgPort.valid == false) && (it->port == 0)) {
1054 MSG_DEBUG("Send incoming normal msg to listener %d", it->listenerFd);
1055 write(it->listenerFd, pEventData, eventSize);
1056 } else if ((msgInfo->msgPort.valid == true) && (it->port == msgInfo->msgPort.dstPort)) {
1057 MSG_DEBUG("Send incoming port msg to listener %d", it->listenerFd);
1058 write(it->listenerFd, pEventData, eventSize);
1066 void MsgTransactionManager::broadcastMMSConfCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo, const MMS_RECV_DATA_S *mmsRecvData)
1070 char* pEventData = NULL;
1071 AutoPtr<char> eventBuf(&pEventData);
1073 char* encodedData = NULL;
1074 AutoPtr<char> buf(&encodedData);
1075 int dataSize = MsgEncodeMsgInfo(msgInfo, &encodedData);
1077 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)(&pEventData));
1079 mmsconf_list::iterator it = newMMSConfMsgCBList.begin();
1081 for (; it != newMMSConfMsgCBList.end(); it++)
1083 MSG_DEBUG("fd:%d appId:%s",it->listenerFd, it->appId);
1085 if (mmsRecvData->msgAppId.valid == true)
1087 if (!strcmp(it->appId, mmsRecvData->msgAppId.appId))
1089 MSG_DEBUG("Send incoming java msg to listener %d", it->listenerFd);
1090 write(it->listenerFd, pEventData, eventSize);
1095 if (strlen(it->appId) <= 0)
1097 MSG_DEBUG("Send incoming normal msg to listener %d", it->listenerFd);
1098 write(it->listenerFd, pEventData, eventSize);
1107 void MsgTransactionManager::broadcastPushMsgCB(const msg_error_t err, const MSG_PUSH_MESSAGE_DATA_S *pushData)
1111 char* pEventData = NULL;
1112 AutoPtr<char> eventBuf(&pEventData);
1113 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
1114 #ifdef MSG_PENDING_PUSH_MESSAGE
1115 int bReady = MsgSettingGetInt(VCONFKEY_USER_SERVICE_READY);
1118 MSG_PUSH_MESSAGE_DATA_S push_msg;
1119 memcpy(&push_msg, pushData, sizeof(MSG_PUSH_MESSAGE_DATA_S));
1120 pushMsgList.push_back(push_msg);
1126 int eventSize = MsgMakeEvent(pushData, sizeof(MSG_PUSH_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, err, (void**)(&pEventData));
1128 pushmsg_list::iterator it = newPushMsgCBList.begin();
1130 for (; it != newPushMsgCBList.end(); it++)
1132 MSG_DEBUG("registered_appid : %s, incoming_appid: %s", it->appId, pushData->pushAppId);
1133 if (!strcmp(it->appId, pushData->pushAppId))
1135 MSG_DEBUG("Send incoming Push information to listener %d", it->listenerFd);
1136 write(it->listenerFd, pEventData, eventSize);
1143 void MsgTransactionManager::broadcastCBMsgCB(const msg_error_t err, const MSG_CB_MSG_S *cbMsg)
1147 char* pEventData = NULL;
1148 AutoPtr<char> eventBuf(&pEventData);
1150 int eventSize = MsgMakeEvent(cbMsg, sizeof(MSG_CB_MSG_S), MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)(&pEventData));
1152 cbmsg_list::iterator it = newCBMsgCBList.begin();
1154 for (; it != newCBMsgCBList.end(); it++)
1156 MSG_DEBUG("Send incoming CB information to listener %d", it->listenerFd);
1157 write(it->listenerFd, pEventData, eventSize);
1163 void MsgTransactionManager::broadcastSyncMLMsgCB(const msg_error_t err, const MSG_SYNCML_MESSAGE_DATA_S *syncMLData)
1167 char* pEventData = NULL;
1168 AutoPtr<char> eventBuf(&pEventData);
1170 int eventSize = MsgMakeEvent(syncMLData, sizeof(MSG_SYNCML_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, err, (void**)(&pEventData));
1172 syncmlmsg_list::iterator it = newSyncMLMsgCBList.begin();
1174 for (; it != newSyncMLMsgCBList.end(); it++)
1176 MSG_DEBUG("Send incoming SyncML information to listener %d", it->listenerFd);
1177 write(it->listenerFd, pEventData, eventSize);
1184 void MsgTransactionManager::broadcastLBSMsgCB(const msg_error_t err, const MSG_LBS_MESSAGE_DATA_S *lbsData)
1189 char* pEventData = NULL;
1190 AutoPtr<char> eventBuf(&pEventData);
1192 int eventSize = MsgMakeEvent(lbsData, sizeof(MSG_LBS_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, err, (void**)(&pEventData));
1194 lbsmsg_list::iterator it = newLBSMsgCBList.begin();
1196 for (; it != newLBSMsgCBList.end(); it++)
1198 MSG_DEBUG("Send incoming LBS msg to listener %d", it->listenerFd);
1199 write(it->listenerFd, pEventData, eventSize);
1202 // MsgLbsWapPush(lbsData->pushHeader, lbsData->pushBody, lbsData->pushBodyLen);
1208 void MsgTransactionManager::broadcastSyncMLMsgOperationCB(const msg_error_t err, const int msgId, const int extId)
1212 char* pEventData = NULL;
1213 AutoPtr<char> eventBuf(&pEventData);
1215 char* encodedData = NULL;
1216 AutoPtr<char> buf(&encodedData);
1218 // Encoding Storage Change Data
1219 int dataSize = MsgEncodeSyncMLOperationData(msgId, extId, &encodedData);
1221 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_SYNCML_OPERATION, err, (void**)(&pEventData));
1223 syncmlop_list::iterator it = operationSyncMLMsgCBList.begin();
1225 for( ; it != operationSyncMLMsgCBList.end() ; it++ )
1227 MSG_DEBUG("Send SyncML operation to listener %d", it->listenerFd);
1228 write(it->listenerFd, pEventData, eventSize);
1235 void MsgTransactionManager::broadcastStorageChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList)
1239 if(pMsgIdList == NULL) {
1240 MSG_DEBUG("pMsgIdList is NULL.");
1244 MSG_DEBUG("storageChangeType [%d]", storageChangeType);
1248 char* pEventData = NULL;
1249 AutoPtr<char> eventBuf(&pEventData);
1251 char* encodedData = NULL;
1252 AutoPtr<char> buf(&encodedData);
1254 // Encoding Storage Change Data
1255 dataSize = MsgEncodeStorageChangeData(storageChangeType, pMsgIdList, &encodedData);
1257 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_STORAGE_CHANGE_IND, err, (void**)(&pEventData));
1259 fd_map::iterator it = storageChangeFdMap.begin();
1261 for (; it != storageChangeFdMap.end(); it++)
1263 MSG_DEBUG("Send Storage Change Callback to listener %d", it->first);
1264 write(it->first, pEventData, eventSize);
1271 void MsgTransactionManager::broadcastReportMsgCB(const msg_error_t err, const msg_report_type_t reportMsgType, const MSG_MESSAGE_INFO_S *pMsgInfo)
1275 if(pMsgInfo == NULL) {
1276 MSG_DEBUG("pMsgInfo is NULL.");
1280 MSG_DEBUG("reportMsgType [%d]", reportMsgType);
1284 char* pEventData = NULL;
1285 AutoPtr<char> eventBuf(&pEventData);
1287 char* encodedData = NULL;
1288 AutoPtr<char> buf(&encodedData);
1290 // Encoding Storage Change Data
1291 dataSize = MsgEncodeReportMsgData(reportMsgType, pMsgInfo, &encodedData);
1293 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND, err, (void**)(&pEventData));
1295 fd_map::iterator it = reportMsgCBFdMap.begin();
1297 for (; it != reportMsgCBFdMap.end(); it++)
1299 MSG_DEBUG("Send Report Message Incoming Callback to listener %d", it->first);
1300 write(it->first, pEventData, eventSize);
1307 void MsgTransactionManager::setTMStatus()
1317 void MsgTransactionManager::getTMStatus()
1324 ret = cv.timedwait(mx.pMutex(), 3);
1328 if (ret == ETIMEDOUT)
1330 MSG_DEBUG("MsgTransactionManager::getTMStatus TIME-OUT");
1335 #ifdef MSG_PENDING_PUSH_MESSAGE
1336 void MsgTransactionManager::sendPendingPushMsg(void)
1339 pushpending_list::iterator pushmsg_it = pushMsgList.begin();
1340 while(pushmsg_it != pushMsgList.end())
1342 MSG_PUSH_MESSAGE_DATA_S msg;
1343 memset(&msg, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
1344 memcpy(msg.pushAppId, pushmsg_it->pushAppId, sizeof(msg.pushAppId));
1345 memcpy(msg.pushBody, pushmsg_it->pushBody, sizeof(msg.pushBody));
1346 memcpy(msg.pushContentType, pushmsg_it->pushContentType, sizeof(msg.pushContentType));
1347 memcpy(msg.pushHeader, pushmsg_it->pushHeader, sizeof(msg.pushHeader));
1348 msg.pushBodyLen = pushmsg_it->pushBodyLen;
1349 MsgTransactionManager::instance()->broadcastPushMsgCB(MSG_SUCCESS, (const MSG_PUSH_MESSAGE_DATA_S *)&msg);
1350 pushmsg_it = pushMsgList.erase(pushmsg_it);