4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <sys/socket.h>
25 #include <security-server.h>
28 #include "MsgMemory.h"
29 #include "MsgException.h"
30 #include "MsgCppTypes.h"
31 #include "MsgContact.h"
32 #include "MsgIpcSocket.h"
33 #include "MsgGconfWrapper.h"
34 #include "MsgUtilFunction.h"
35 #include "MsgCmdHandler.h"
36 #include "MsgSettingHandler.h"
37 #include "MsgStorageHandler.h"
38 #include "MsgPluginManager.h"
39 #include "MsgTransManager.h"
41 /*==================================================================================================
42 FUNCTION IMPLEMENTATION
43 ==================================================================================================*/
44 void MsgContactChangedCallback()
46 msg_id_list_s msgIdList;
47 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
49 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_CONTACT, &msgIdList);
52 /*==================================================================================================
53 IMPLEMENTATION OF MsgTransactionManager - Member Functions
54 ==================================================================================================*/
55 MsgTransactionManager* MsgTransactionManager::pInstance = NULL;
56 MsgIpcServerSocket MsgTransactionManager::servSock;
59 MsgTransactionManager::MsgTransactionManager() : running(false), mx(), cv()
63 statusCBFdMap.clear();
65 newMMSConfMsgCBList.clear();
66 newSyncMLMsgCBList.clear();
67 newLBSMsgCBList.clear();
69 operationSyncMLMsgCBList.clear();
70 storageChangeFdMap.clear();
74 // Fill in mMsgHandlers, as given in the below.
75 handlerMap[MSG_CMD_ADD_MSG] = &MsgAddMessageHandler;
76 handlerMap[MSG_CMD_ADD_SYNCML_MSG] = &MsgAddSyncMLMessageHandler;
77 handlerMap[MSG_CMD_UPDATE_MSG] = &MsgUpdateMessageHandler;
78 handlerMap[MSG_CMD_UPDATE_READ] = &MsgUpdateReadStatusHandler;
79 handlerMap[MSG_CMD_UPDATE_PROTECTED] = &MsgUpdateProtectedStatusHandler;
80 handlerMap[MSG_CMD_DELETE_MSG] = &MsgDeleteMessageHandler;
81 handlerMap[MSG_CMD_DELALL_MSGINFOLDER] = &MsgDeleteAllMessageInFolderHandler;
82 handlerMap[MSG_CMD_MOVE_MSGTOFOLDER] = &MsgMoveMessageToFolderHandler;
83 handlerMap[MSG_CMD_MOVE_MSGTOSTORAGE] = &MsgMoveMessageToStorageHandler;
84 handlerMap[MSG_CMD_COUNT_MSG] = &MsgCountMessageHandler;
85 handlerMap[MSG_CMD_GET_MSG] = &MsgGetMessageHandler;
86 handlerMap[MSG_CMD_GET_FOLDERVIEWLIST] = &MsgGetFolderViewListHandler;
88 handlerMap[MSG_CMD_ADD_FOLDER] = &MsgAddFolderHandler;
89 handlerMap[MSG_CMD_UPDATE_FOLDER] = &MsgUpdateFolderHandler;
90 handlerMap[MSG_CMD_DELETE_FOLDER] = &MsgDeleteFolderHandler;
91 handlerMap[MSG_CMD_GET_FOLDERLIST] = &MsgGetFolderListHandler;
93 handlerMap[MSG_CMD_ADD_FILTER] = &MsgAddFilterHandler;
94 handlerMap[MSG_CMD_UPDATE_FILTER] = &MsgUpdateFilterHandler;
95 handlerMap[MSG_CMD_DELETE_FILTER] = &MsgDeleteFilterHandler;
96 handlerMap[MSG_CMD_GET_FILTERLIST] = &MsgGetFilterListHandler;
97 handlerMap[MSG_CMD_SET_FILTER_OPERATION] = &MsgSetFilterOperationHandler;
98 handlerMap[MSG_CMD_GET_FILTER_OPERATION] = &MsgGetFilterOperationHandler;
99 handlerMap[MSG_CMD_SET_FILTER_ACTIVATION] = &MsgSetFilterActivationHandler;
101 handlerMap[MSG_CMD_GET_MSG_TYPE] = &MsgGetMsgTypeHandler;
103 handlerMap[MSG_CMD_SUBMIT_REQ] = &MsgSubmitReqHandler;
104 handlerMap[MSG_CMD_CANCEL_REQ] = &MsgCancelReqHandler;
106 handlerMap[MSG_CMD_REG_SENT_STATUS_CB] = &MsgRegSentStatusCallbackHandler;
107 handlerMap[MSG_CMD_REG_STORAGE_CHANGE_CB] = &MsgRegStorageChangeCallbackHandler;
108 handlerMap[MSG_CMD_REG_INCOMING_MSG_CB] = &MsgRegIncomingMsgCallbackHandler;
109 handlerMap[MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB] = &MsgRegIncomingMMSConfMsgCallbackHandler;
110 handlerMap[MSG_CMD_REG_INCOMING_SYNCML_MSG_CB] = &MsgRegIncomingSyncMLMsgCallbackHandler;
111 handlerMap[MSG_CMD_REG_INCOMING_PUSH_MSG_CB] = &MsgRegIncomingPushMsgCallbackHandler;
112 handlerMap[MSG_CMD_REG_INCOMING_CB_MSG_CB] = &MsgRegIncomingCBMsgCallbackHandler;
113 handlerMap[MSG_CMD_REG_INCOMING_LBS_MSG_CB] = &MsgRegIncomingLBSMsgCallbackHandler;
114 handlerMap[MSG_CMD_REG_SYNCML_MSG_OPERATION_CB] = &MsgRegSyncMLMsgOperationCallbackHandler;
116 handlerMap[MSG_CMD_PLG_SENT_STATUS_CNF] = &MsgSentStatusHandler;
117 handlerMap[MSG_CMD_PLG_STORAGE_CHANGE_IND] = &MsgStorageChangeHandler;
118 handlerMap[MSG_CMD_PLG_INCOMING_MSG_IND] = &MsgIncomingMsgHandler;
119 handlerMap[MSG_CMD_PLG_INCOMING_MMS_CONF] = &MsgIncomingMMSConfMsgHandler;
120 handlerMap[MSG_CMD_PLG_INCOMING_PUSH_IND] = &MsgIncomingPushMsgHandler;
121 handlerMap[MSG_CMD_PLG_INCOMING_CB_IND] = &MsgIncomingCBMsgHandler;
123 handlerMap[MSG_CMD_PLG_INCOMING_SYNCML_IND] = &MsgIncomingSyncMLMsgHandler;
124 handlerMap[MSG_CMD_PLG_INCOMING_LBS_IND] = &MsgIncomingLBSMsgHandler;
125 handlerMap[MSG_CMD_PLG_INIT_SIM_BY_SAT] = &MsgInitSimBySatHandler;
127 handlerMap[MSG_CMD_GET_THREADVIEWLIST] = &MsgGetThreadViewListHandler;
128 handlerMap[MSG_CMD_GET_CONVERSATIONVIEWLIST] = &MsgGetConversationViewListHandler;
129 handlerMap[MSG_CMD_DELETE_THREADMESSAGELIST] = &MsgDeleteThreadMessageListHandler;
131 handlerMap[MSG_CMD_GET_CONTACT_COUNT] = &MsgCountMsgByContactHandler;
132 handlerMap[MSG_CMD_GET_QUICKPANEL_DATA] = &MsgGetQuickPanelDataHandler;
133 handlerMap[MSG_CMD_COUNT_BY_MSGTYPE] = &MsgCountMsgByTypeHandler;
134 handlerMap[MSG_CMD_RESET_DB] = &MsgResetDatabaseHandler;
135 handlerMap[MSG_CMD_GET_MEMSIZE] = &MsgGetMemSizeHandler;
137 handlerMap[MSG_CMD_BACKUP_MESSAGE] = &MsgBackupMessageHandler;
138 handlerMap[MSG_CMD_RESTORE_MESSAGE] = &MsgRestoreMessageHandler;
140 handlerMap[MSG_CMD_UPDATE_THREAD_READ] = &MsgUpdateThreadReadStatusHandler;
142 handlerMap[MSG_CMD_SYNCML_OPERATION] = &MsgSyncMLMsgOperationHandler;
143 handlerMap[MSG_CMD_GET_REPORT_STATUS] = &MsgGetReportStatusHandler;
145 handlerMap[MSG_CMD_GET_THREAD_ID_BY_ADDRESS] = &MsgGetThreadIdByAddressHandler;
146 handlerMap[MSG_CMD_GET_THREAD_INFO] = &MsgGetThreadInfoHandler;
148 handlerMap[MSG_CMD_GET_SMSC_OPT] = &MsgGetConfigHandler;
149 handlerMap[MSG_CMD_GET_CB_OPT] = &MsgGetConfigHandler;
150 handlerMap[MSG_CMD_GET_SMS_SEND_OPT] = &MsgGetConfigHandler;
151 handlerMap[MSG_CMD_GET_MMS_SEND_OPT] = &MsgGetConfigHandler;
152 handlerMap[MSG_CMD_GET_MMS_RECV_OPT] = &MsgGetConfigHandler;
153 handlerMap[MSG_CMD_GET_PUSH_MSG_OPT] = &MsgGetConfigHandler;
154 handlerMap[MSG_CMD_GET_VOICE_MSG_OPT] = &MsgGetConfigHandler;
155 handlerMap[MSG_CMD_GET_GENERAL_MSG_OPT] = &MsgGetConfigHandler;
156 handlerMap[MSG_CMD_GET_MSG_SIZE_OPT] = &MsgGetConfigHandler;
158 handlerMap[MSG_CMD_SET_SMSC_OPT] = &MsgSetConfigHandler;
159 handlerMap[MSG_CMD_SET_CB_OPT] = &MsgSetConfigHandler;
160 handlerMap[MSG_CMD_SET_SMS_SEND_OPT] = &MsgSetConfigHandler;
161 handlerMap[MSG_CMD_SET_MMS_SEND_OPT] = &MsgSetConfigHandler;
162 handlerMap[MSG_CMD_SET_MMS_RECV_OPT] = &MsgSetConfigHandler;
163 handlerMap[MSG_CMD_SET_PUSH_MSG_OPT] = &MsgSetConfigHandler;
164 handlerMap[MSG_CMD_SET_VOICE_MSG_OPT] = &MsgSetConfigHandler;
165 handlerMap[MSG_CMD_SET_GENERAL_MSG_OPT] = &MsgSetConfigHandler;
166 handlerMap[MSG_CMD_SET_MSG_SIZE_OPT] = &MsgSetConfigHandler;
168 handlerMap[MSG_CMD_ADD_PUSH_EVENT] = &MsgAddPushEventHandler;
169 handlerMap[MSG_CMD_DELETE_PUSH_EVENT] = &MsgDeletePushEventHandler;
170 handlerMap[MSG_CMD_UPDATE_PUSH_EVENT] = &MsgUpdatePushEventHandler;
171 handlerMap[MSG_CMD_DELETE_MESSAGE_BY_LIST] = &MsgDeleteMessageByListHandler;
173 handlerMap[MSG_CMD_CONTACT_SYNC] = &MsgContactSyncEventHandler;
177 MsgTransactionManager::~MsgTransactionManager()
179 // pthread_cond_init(&retCV, NULL); // = PTHREAD_COND_INITIALIZER;
184 MsgTransactionManager* MsgTransactionManager::instance()
187 pInstance = new MsgTransactionManager();
193 void MsgTransactionManager::run()
195 servSock.open(MSG_SOCKET_PATH);
197 fd_set readfds = servSock.fdSet();
200 MSG_DEBUG("Start Transaction Manager");
204 readfds = servSock.fdSet();
205 nfds = servSock.maxFd();
207 MSG_DEBUG("Wait For Select() : nfds %d", nfds);
212 if(select(nfds, &readfds, NULL, NULL, NULL) == -1) {
213 THROW(MsgException::SELECT_ERROR, "select error : %s", strerror(errno));
218 for (int i=0 ; i < nfds; i++)
220 if (FD_ISSET(i, &readfds))
222 if (i == servSock.fd()) // if it is socket connection request
229 catch (MsgException& e)
231 MSG_FATAL("%s", e.what());
235 MSG_FATAL("%s", e.what());
239 //MsgReleaseMemory();
244 void MsgTransactionManager::write(int fd, const char* buf, int len)
246 servSock.write(fd, buf, len);
250 void MsgTransactionManager::insertSentMsg(int reqId, MSG_PROXY_INFO_S* pPrxInfo)
252 if (pPrxInfo == NULL)
253 THROW(MsgException::SENT_STATUS_ERROR, "Input Parameter is NULL");
255 MSG_DEBUG("msg for submit: reqId %d listenerFd %d handleAddr %x", reqId, pPrxInfo->listenerFd, pPrxInfo->handleAddr);
257 fd_map::iterator it = statusCBFdMap.find(pPrxInfo->listenerFd);
259 if (it == statusCBFdMap.end()) { // if the status CB is not registered
260 MSG_DEBUG("No sent_status registered for fd %d", pPrxInfo->listenerFd);
262 sentMsgMap.insert(make_pair(reqId, *pPrxInfo));
267 MSG_PROXY_INFO_S* MsgTransactionManager::getProxyInfo(int reqId)
269 sentmsg_map::iterator it = sentMsgMap.find(reqId);
271 if (it == sentMsgMap.end())
273 //THROW(MsgException::SENT_STATUS_ERROR, "No submit request for %d", reqId);
274 MSG_DEBUG("No sent status cb found (exception: mobile tracker)");
278 return &(it->second);
282 void MsgTransactionManager::delProxyInfo(int reqId)
284 sentmsg_map::iterator it = sentMsgMap.find(reqId);
286 if (it == sentMsgMap.end())
288 THROW(MsgException::SENT_STATUS_ERROR, "channel info does not exist");
291 sentMsgMap.erase(it);
295 void MsgTransactionManager::handleRequest(int fd)
299 MSG_DEBUG("Event from fd %d", fd);
302 AutoPtr<char> wrap(&buf);
304 int ret = servSock.read(fd, &buf, &len);
306 if( ret == CLOSE_CONNECTION_BY_SIGNAL || ret == CLOSE_CONNECTION_BY_USER || ret < 0)
308 MSG_DEBUG("Read value [%d]", ret);
314 THROW(MsgException::INVALID_RESULT, "read buffer size <= 0");
316 char* pEventData = NULL;
317 AutoPtr<char> eventBuf(&pEventData);
321 // decoding cmd from APP
322 MSG_CMD_S* pCmd = (MSG_CMD_S*) buf;
323 MSG_DEBUG("Command Type [%d : %s]", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType));
325 if (pCmd->cmdType > MSG_CMD_NUM)
326 THROW(MsgException::OUT_OF_RANGE, "request CMD is not defined");
329 if (checkPrivilege(fd, pCmd->cmdType) == false) {
330 MSG_DEBUG("No Privilege rule. Not allowed.");
331 #ifdef MSG_CHECK_PRIVILEGE
332 eventSize = sizeof(MSG_EVENT_S);
334 pEventData = new char[eventSize];
336 MSG_EVENT_S* pMsgEvent = (MSG_EVENT_S*)pEventData;
338 pMsgEvent->eventType = pCmd->cmdType;
339 pMsgEvent->result = MSG_ERR_SECURITY_ERROR;
341 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
342 servSock.write(fd, pEventData, eventSize);
348 // determine the handler based on pCmd->cmdType
349 int (*pfHandler)(const MSG_CMD_S*, char**) = NULL;
351 pfHandler = handlerMap[pCmd->cmdType];
354 THROW(MsgException::INVALID_PARAM, "No handler for %d", pCmd->cmdType);
356 // run handler function
357 eventSize = pfHandler(pCmd, &pEventData);
359 if (eventSize == 0 || pEventData == NULL)
360 THROW(MsgException::INVALID_RESULT, "event size = 0 or event data = NULL");
362 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
364 servSock.write(fd, pEventData, eventSize);
370 // terminating the socket connection between ipc server and ipc client
371 void MsgTransactionManager::cleanup(int fd)
377 MSG_DEBUG("fd %d disonnected", fd);
379 // remove sent msg info for fd
380 sentmsg_map::iterator sentmsg_it = sentMsgMap.begin();
382 for (; sentmsg_it != sentMsgMap.end(); sentmsg_it++)
384 if (sentmsg_it->second.listenerFd == fd)
386 sentmsg_it->second.listenerFd = 0;
387 sentmsg_it->second.handleAddr = 0;
391 // remove sent status callback for fd
392 statusCBFdMap.erase(fd);
394 // remove all newMsgCBs for fd
395 newmsg_list::iterator newmsg_it = newMsgCBList.begin();
397 while (newmsg_it != newMsgCBList.end())
399 if (newmsg_it->listenerFd == fd)
401 newmsg_it = newMsgCBList.erase(newmsg_it);
409 // remove all newMMSConfMsgCBs for fd
410 mmsconf_list::iterator mmsconf_it = newMMSConfMsgCBList.begin();
412 while (mmsconf_it != newMMSConfMsgCBList.end())
414 if (mmsconf_it->listenerFd == fd)
416 mmsconf_it = newMMSConfMsgCBList.erase(mmsconf_it);
424 // remove all newSyncMLMsgCBs for fd
425 syncmlmsg_list::iterator syncmlmsg_it = newSyncMLMsgCBList.begin();
427 while (syncmlmsg_it != newSyncMLMsgCBList.end())
429 if (syncmlmsg_it->listenerFd == fd)
431 syncmlmsg_it = newSyncMLMsgCBList.erase(syncmlmsg_it);
439 // remove all newLBSMsgCBs for fd
440 lbsmsg_list::iterator lbsmsg_it = newLBSMsgCBList.begin();
442 while (lbsmsg_it != newLBSMsgCBList.end())
444 if (lbsmsg_it->listenerFd == fd)
446 lbsmsg_it = newLBSMsgCBList.erase(lbsmsg_it);
454 // remove all newPushMsgCBs for fd
455 pushmsg_list::iterator pushmsg_it = newPushMsgCBList.begin();
457 while (pushmsg_it != newPushMsgCBList.end())
459 if (pushmsg_it->listenerFd == fd)
461 pushmsg_it = newPushMsgCBList.erase(pushmsg_it);
469 // remove all newCBMsgCBs for fd
470 cbmsg_list::iterator cbmsg_it = newCBMsgCBList.begin();
473 while (cbmsg_it != newCBMsgCBList.end())
475 if (cbmsg_it->listenerFd == fd)
477 cbmsg_it = newCBMsgCBList.erase(cbmsg_it);
481 if(cbmsg_it->bsave == true)
487 // remove all operationSyncMLMsgCBs for fd
488 syncmlop_list::iterator syncmlop_it = operationSyncMLMsgCBList.begin();
490 while (syncmlop_it != operationSyncMLMsgCBList.end())
492 if (syncmlop_it->listenerFd == fd)
494 syncmlop_it = operationSyncMLMsgCBList.erase(syncmlop_it);
502 // remove storage change callback for fd
503 storageChangeFdMap.erase(fd);
509 bool MsgTransactionManager::checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType)
511 bool bAllowed = true;
514 case MSG_CMD_GET_MSG:
515 case MSG_CMD_COUNT_MSG:
516 case MSG_CMD_COUNT_BY_MSGTYPE:
518 int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::read", "rw");
519 if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
520 MSG_DEBUG("No msg-service::read rw rule.");
525 case MSG_CMD_OPEN_HANDLE:
526 case MSG_CMD_SUBMIT_REQ:
527 case MSG_CMD_SET_CB_OPT:
528 case MSG_CMD_ADD_PUSH_EVENT:
529 case MSG_CMD_DELETE_PUSH_EVENT:
531 int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::write", "rw");
532 if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
533 MSG_DEBUG("No msg-service::write rw rule.");
538 case MSG_CMD_REG_INCOMING_MSG_CB:
540 int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::smstrigger", "rw");
541 if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
542 MSG_DEBUG("No msg-service::smstrigger rw rule.");
547 case MSG_CMD_REG_INCOMING_CB_MSG_CB:
549 int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::cellbroadcast", "rw");
550 if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
551 MSG_DEBUG("No msg-service::cellbroadcast rw rule.");
556 case MSG_CMD_REG_INCOMING_PUSH_MSG_CB:
558 int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::wappush", "rw");
559 if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
560 MSG_DEBUG("No msg-service::wappush rw rule.");
571 void MsgTransactionManager::setSentStatusCB(int listenerFd)
574 THROW(MsgException::INVALID_PARAM,"InParam Error: listenerFd %d",listenerFd);
576 statusCBFdMap[listenerFd] = true;
580 void MsgTransactionManager::setIncomingMsgCB(MSG_CMD_REG_INCOMING_MSG_CB_S *pCbInfo)
584 MSG_FATAL("cbinfo NULL");
588 newmsg_list::iterator it = newMsgCBList.begin();
590 for (; it != newMsgCBList.end(); it++)
592 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && (it->port == pCbInfo->port))
594 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d, port %d", it->listenerFd, it->msgType, it->port);
599 newMsgCBList.push_back(*pCbInfo);
603 void MsgTransactionManager::setMMSConfMsgCB(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCbInfo)
607 MSG_FATAL("cbinfo NULL");
611 mmsconf_list::iterator it = newMMSConfMsgCBList.begin();
613 for (; it != newMMSConfMsgCBList.end(); it++)
615 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && (!strncmp(it->appId, pCbInfo->appId, MAX_MMS_JAVA_APPID_LEN)))
617 MSG_DEBUG("Duplicated MMSConfMessageCB info fd:%d, mType:%d, appId:%s", it->listenerFd, it->msgType, it->appId);
622 newMMSConfMsgCBList.push_back(*pCbInfo);
626 void MsgTransactionManager::setPushMsgCB(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCbInfo)
630 MSG_FATAL("cbinfo NULL");
634 pushmsg_list::iterator it = newPushMsgCBList.begin();
636 for (; it != newPushMsgCBList.end(); it++)
638 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
640 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
645 newPushMsgCBList.push_back(*pCbInfo);
648 void MsgTransactionManager::setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo)
652 MSG_FATAL("cbinfo NULL");
656 cbmsg_list::iterator it = newCBMsgCBList.begin();
658 for (; it != newCBMsgCBList.end(); it++)
660 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
662 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
668 if(MsgSettingSetBool(CB_SAVE, pCbInfo->bsave) != MSG_SUCCESS)
669 MSG_DEBUG("MsgSettingSetBool FAIL: CB_SAVE");
672 newCBMsgCBList.push_back(*pCbInfo);
675 void MsgTransactionManager::setSyncMLMsgCB(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCbInfo)
679 MSG_FATAL("cbinfo NULL");
683 syncmlmsg_list::iterator it = newSyncMLMsgCBList.begin();
685 for (; it != newSyncMLMsgCBList.end(); it++)
687 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
689 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
694 newSyncMLMsgCBList.push_back(*pCbInfo);
698 void MsgTransactionManager::setLBSMsgCB(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCbInfo)
702 MSG_FATAL("cbinfo NULL");
706 lbsmsg_list::iterator it = newLBSMsgCBList.begin();
708 for (; it != newLBSMsgCBList.end(); it++)
710 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
712 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
717 newLBSMsgCBList.push_back(*pCbInfo);
721 void MsgTransactionManager::setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *pTrId)
725 MSG_FATAL("trId NULL");
729 javamms_list::iterator it;
731 for (it = javaMMSList.begin(); it != javaMMSList.end(); it++)
733 if (!strcmp(it->id, pTrId->id))
735 MSG_DEBUG("Duplicated javaMMS transaction Id:%s", it->id);
740 javaMMSList.push_back(*pTrId);
744 void MsgTransactionManager::setSyncMLMsgOperationCB(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCbInfo)
748 MSG_FATAL("cbinfo NULL");
752 syncmlop_list::iterator it = operationSyncMLMsgCBList.begin();
754 for (; it != operationSyncMLMsgCBList.end(); it++)
756 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
758 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
763 operationSyncMLMsgCBList.push_back(*pCbInfo);
767 void MsgTransactionManager::setStorageChangeCB(int listenerFd)
770 THROW(MsgException::INVALID_PARAM,"InParam Error: listenerFd %d", listenerFd);
772 storageChangeFdMap[listenerFd] = true;
776 javamms_list& MsgTransactionManager::getJavaMMSList()
782 void MsgTransactionManager::broadcastIncomingMsgCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo)
786 char* pEventData = NULL;
787 AutoPtr<char> eventBuf(&pEventData);
789 int eventSize = MsgMakeEvent(msgInfo, sizeof(MSG_MESSAGE_INFO_S), MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)(&pEventData));
791 MSG_DEBUG("valid %d dstport %d", msgInfo->msgPort.valid, msgInfo->msgPort.dstPort);
793 newmsg_list::iterator it = newMsgCBList.begin();
795 for (; it != newMsgCBList.end(); it++)
797 MSG_DEBUG("fd %d dstport %d",it->listenerFd, it->port);
799 if ((msgInfo->msgPort.valid == false) && (it->port == 0))
801 MSG_DEBUG("Send incoming normal msg to listener %d", it->listenerFd);
802 write(it->listenerFd, pEventData, eventSize);
804 else if ((msgInfo->msgPort.valid == true) && (it->port == msgInfo->msgPort.dstPort))
806 MSG_DEBUG("Send incoming port msg to listener %d", it->listenerFd);
807 write(it->listenerFd, pEventData, eventSize);
815 void MsgTransactionManager::broadcastMMSConfCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo, const MMS_RECV_DATA_S *mmsRecvData)
819 char* pEventData = NULL;
820 AutoPtr<char> eventBuf(&pEventData);
822 int eventSize = MsgMakeEvent(msgInfo, sizeof(MSG_MESSAGE_INFO_S), MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)(&pEventData));
824 mmsconf_list::iterator it = newMMSConfMsgCBList.begin();
826 for (; it != newMMSConfMsgCBList.end(); it++)
828 MSG_DEBUG("fd:%d appId:%s",it->listenerFd, it->appId);
830 if (mmsRecvData->msgAppId.valid == true)
832 if (!strcmp(it->appId, mmsRecvData->msgAppId.appId))
834 MSG_DEBUG("Send incoming java msg to listener %d", it->listenerFd);
835 write(it->listenerFd, pEventData, eventSize);
840 if (strlen(it->appId) <= 0)
842 MSG_DEBUG("Send incoming normal msg to listener %d", it->listenerFd);
843 write(it->listenerFd, pEventData, eventSize);
852 void MsgTransactionManager::broadcastPushMsgCB(const msg_error_t err, const MSG_PUSH_MESSAGE_DATA_S *pushData)
856 char* pEventData = NULL;
857 AutoPtr<char> eventBuf(&pEventData);
859 int eventSize = MsgMakeEvent(pushData, sizeof(MSG_PUSH_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, err, (void**)(&pEventData));
861 pushmsg_list::iterator it = newPushMsgCBList.begin();
863 for (; it != newPushMsgCBList.end(); it++)
865 if (!strcmp(it->appId, pushData->pushAppId))
867 MSG_DEBUG("Send incoming Push information to listener %d", it->listenerFd);
868 write(it->listenerFd, pEventData, eventSize);
875 void MsgTransactionManager::broadcastCBMsgCB(const msg_error_t err, const MSG_CB_MSG_S *cbMsg)
879 char* pEventData = NULL;
880 AutoPtr<char> eventBuf(&pEventData);
882 int eventSize = MsgMakeEvent(cbMsg, sizeof(MSG_CB_MSG_S), MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)(&pEventData));
884 cbmsg_list::iterator it = newCBMsgCBList.begin();
886 for (; it != newCBMsgCBList.end(); it++)
888 MSG_DEBUG("Send incoming CB information to listener %d", it->listenerFd);
889 write(it->listenerFd, pEventData, eventSize);
895 void MsgTransactionManager::broadcastSyncMLMsgCB(const msg_error_t err, const MSG_SYNCML_MESSAGE_DATA_S *syncMLData)
899 char* pEventData = NULL;
900 AutoPtr<char> eventBuf(&pEventData);
902 int eventSize = MsgMakeEvent(syncMLData, sizeof(MSG_SYNCML_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, err, (void**)(&pEventData));
904 syncmlmsg_list::iterator it = newSyncMLMsgCBList.begin();
906 for (; it != newSyncMLMsgCBList.end(); it++)
908 MSG_DEBUG("Send incoming SyncML information to listener %d", it->listenerFd);
909 write(it->listenerFd, pEventData, eventSize);
916 void MsgTransactionManager::broadcastLBSMsgCB(const msg_error_t err, const MSG_LBS_MESSAGE_DATA_S *lbsData)
920 char* pEventData = NULL;
921 AutoPtr<char> eventBuf(&pEventData);
923 int eventSize = MsgMakeEvent(lbsData, sizeof(MSG_LBS_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, err, (void**)(&pEventData));
925 lbsmsg_list::iterator it = newLBSMsgCBList.begin();
927 for (; it != newLBSMsgCBList.end(); it++)
929 MSG_DEBUG("Send incoming LBS msg to listener %d", it->listenerFd);
930 write(it->listenerFd, pEventData, eventSize);
937 void MsgTransactionManager::broadcastSyncMLMsgOperationCB(const msg_error_t err, const int msgId, const int extId)
941 char* pEventData = NULL;
942 AutoPtr<char> eventBuf(&pEventData);
944 char* encodedData = NULL;
945 AutoPtr<char> buf(&encodedData);
947 // Encoding Storage Change Data
948 int dataSize = MsgEncodeSyncMLOperationData(msgId, extId, &encodedData);
950 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_SYNCML_OPERATION, err, (void**)(&pEventData));
952 syncmlop_list::iterator it = operationSyncMLMsgCBList.begin();
954 for( ; it != operationSyncMLMsgCBList.end() ; it++ )
956 MSG_DEBUG("Send SyncML operation to listener %d", it->listenerFd);
957 write(it->listenerFd, pEventData, eventSize);
964 void MsgTransactionManager::broadcastStorageChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList)
968 if(pMsgIdList == NULL) {
969 MSG_DEBUG("pMsgIdList is NULL.");
973 MSG_DEBUG("storageChangeType [%d]", storageChangeType);
977 char* pEventData = NULL;
978 AutoPtr<char> eventBuf(&pEventData);
980 char* encodedData = NULL;
981 AutoPtr<char> buf(&encodedData);
983 // Encoding Storage Change Data
984 dataSize = MsgEncodeStorageChangeData(storageChangeType, pMsgIdList, &encodedData);
986 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_STORAGE_CHANGE_IND, err, (void**)(&pEventData));
988 fd_map::iterator it = storageChangeFdMap.begin();
990 for (; it != storageChangeFdMap.end(); it++)
992 MSG_DEBUG("Send Storage Change Callback to listener %d", it->first);
993 write(it->first, pEventData, eventSize);
1000 void MsgTransactionManager::setTMStatus()
1010 void MsgTransactionManager::getTMStatus()
1017 ret = cv.timedwait(mx.pMutex(), 3);
1021 if (ret == ETIMEDOUT)
1023 MSG_DEBUG("MsgTransactionManager::getTMStatus TIME-OUT");