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>
24 #include <eventsystem.h>
27 #include "MsgMemory.h"
28 #include "MsgException.h"
29 #include "MsgCppTypes.h"
30 #include "MsgContact.h"
31 #include "MsgIpcSocket.h"
32 #include "MsgGconfWrapper.h"
33 #include "MsgUtilFunction.h"
34 #include "MsgUtilFile.h"
36 #include "MsgCmdHandler.h"
37 #include "MsgSettingHandler.h"
38 #include "MsgStorageHandler.h"
39 #include "MsgPluginManager.h"
40 #include "MsgTransManager.h"
42 #define MSG_CHECK_PRIVILEGE
44 void MsgMakeErrorEvent(MSG_CMD_TYPE_T cmdType, msg_error_t errType, int *pEventSize, char **ppEvent)
46 if (*ppEvent) delete [] *ppEvent;
48 *pEventSize = sizeof(MSG_EVENT_S);
49 *ppEvent = new char[sizeof(MSG_EVENT_S)];
51 MSG_EVENT_S* pMsgEvent = (MSG_EVENT_S*)*ppEvent;
53 pMsgEvent->eventType = cmdType;
54 pMsgEvent->result = errType;
57 /*==================================================================================================
58 IMPLEMENTATION OF MsgTransactionManager - Member Functions
59 ==================================================================================================*/
60 MsgTransactionManager* MsgTransactionManager::pInstance = NULL;
61 MsgIpcServerSocket MsgTransactionManager::servSock;
64 MsgTransactionManager::MsgTransactionManager() : running(false), mx(), mxQ(), cv(), eventQueue()
67 statusCBFdMap.clear();
69 newMMSConfMsgCBList.clear();
70 newSyncMLMsgCBList.clear();
71 newLBSMsgCBList.clear();
73 operationSyncMLMsgCBList.clear();
74 storageChangeFdMap.clear();
78 /* Fill in mMsgHandlers, as given in the below. */
79 handlerMap[MSG_CMD_ADD_MSG] = &MsgAddMessageHandler;
80 handlerMap[MSG_CMD_ADD_SYNCML_MSG] = &MsgAddSyncMLMessageHandler;
81 handlerMap[MSG_CMD_UPDATE_MSG] = &MsgUpdateMessageHandler;
82 handlerMap[MSG_CMD_UPDATE_READ] = &MsgUpdateReadStatusHandler;
83 handlerMap[MSG_CMD_UPDATE_PROTECTED] = &MsgUpdateProtectedStatusHandler;
84 handlerMap[MSG_CMD_DELETE_MSG] = &MsgDeleteMessageHandler;
85 handlerMap[MSG_CMD_DELALL_MSGINFOLDER] = &MsgDeleteAllMessageInFolderHandler;
86 handlerMap[MSG_CMD_MOVE_MSGTOFOLDER] = &MsgMoveMessageToFolderHandler;
87 handlerMap[MSG_CMD_MOVE_MSGTOSTORAGE] = &MsgMoveMessageToStorageHandler;
88 handlerMap[MSG_CMD_COUNT_MSG] = &MsgCountMessageHandler;
89 handlerMap[MSG_CMD_GET_MSG] = &MsgGetMessageHandler;
91 handlerMap[MSG_CMD_ADD_FOLDER] = &MsgAddFolderHandler;
92 handlerMap[MSG_CMD_UPDATE_FOLDER] = &MsgUpdateFolderHandler;
93 handlerMap[MSG_CMD_DELETE_FOLDER] = &MsgDeleteFolderHandler;
94 handlerMap[MSG_CMD_GET_FOLDERLIST] = &MsgGetFolderListHandler;
96 handlerMap[MSG_CMD_ADD_FILTER] = &MsgAddFilterHandler;
97 handlerMap[MSG_CMD_UPDATE_FILTER] = &MsgUpdateFilterHandler;
98 handlerMap[MSG_CMD_DELETE_FILTER] = &MsgDeleteFilterHandler;
99 handlerMap[MSG_CMD_GET_FILTERLIST] = &MsgGetFilterListHandler;
100 handlerMap[MSG_CMD_SET_FILTER_OPERATION] = &MsgSetFilterOperationHandler;
101 handlerMap[MSG_CMD_GET_FILTER_OPERATION] = &MsgGetFilterOperationHandler;
102 handlerMap[MSG_CMD_SET_FILTER_ACTIVATION] = &MsgSetFilterActivationHandler;
104 handlerMap[MSG_CMD_SUBMIT_REQ] = &MsgSubmitReqHandler;
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;
115 handlerMap[MSG_CMD_REG_REPORT_MSG_INCOMING_CB] = &MsgRegIncomingReportMsgCallbackHandler;
117 handlerMap[MSG_CMD_PLG_SENT_STATUS_CNF] = &MsgSentStatusHandler;
118 handlerMap[MSG_CMD_PLG_STORAGE_CHANGE_IND] = &MsgStorageChangeHandler;
119 handlerMap[MSG_CMD_PLG_INCOMING_MSG_IND] = &MsgIncomingMsgHandler;
120 handlerMap[MSG_CMD_PLG_INCOMING_MMS_CONF] = &MsgIncomingMMSConfMsgHandler;
121 handlerMap[MSG_CMD_PLG_INCOMING_PUSH_IND] = &MsgIncomingPushMsgHandler;
122 handlerMap[MSG_CMD_PLG_INCOMING_CB_IND] = &MsgIncomingCBMsgHandler;
124 handlerMap[MSG_CMD_PLG_INCOMING_SYNCML_IND] = &MsgIncomingSyncMLMsgHandler;
125 handlerMap[MSG_CMD_PLG_INCOMING_LBS_IND] = &MsgIncomingLBSMsgHandler;
126 handlerMap[MSG_CMD_PLG_INIT_SIM_BY_SAT] = &MsgInitSimBySatHandler;
128 handlerMap[MSG_CMD_GET_THREADVIEWLIST] = &MsgGetThreadViewListHandler;
129 handlerMap[MSG_CMD_DELETE_THREADMESSAGELIST] = &MsgDeleteThreadMessageListHandler;
130 handlerMap[MSG_CMD_SET_TEMP_ADDRESS_TABLE] = &MsgSetTempAddressTableHandler;
132 handlerMap[MSG_CMD_GET_CONTACT_COUNT] = &MsgCountMsgByContactHandler;
133 handlerMap[MSG_CMD_GET_QUICKPANEL_DATA] = &MsgGetQuickPanelDataHandler;
134 handlerMap[MSG_CMD_COUNT_BY_MSGTYPE] = &MsgCountMsgByTypeHandler;
135 handlerMap[MSG_CMD_RESET_DB] = &MsgResetDatabaseHandler;
136 handlerMap[MSG_CMD_GET_MEMSIZE] = &MsgGetMemSizeHandler;
138 handlerMap[MSG_CMD_BACKUP_MESSAGE] = &MsgBackupMessageHandler;
139 handlerMap[MSG_CMD_RESTORE_MESSAGE] = &MsgRestoreMessageHandler;
141 handlerMap[MSG_CMD_UPDATE_THREAD_READ] = &MsgUpdateThreadReadStatusHandler;
143 handlerMap[MSG_CMD_SYNCML_OPERATION] = &MsgSyncMLMsgOperationHandler;
144 handlerMap[MSG_CMD_GET_REPORT_STATUS] = &MsgGetReportStatusHandler;
146 handlerMap[MSG_CMD_GET_THREAD_ID_BY_ADDRESS] = &MsgGetThreadIdByAddressHandler;
147 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;
172 handlerMap[MSG_CMD_ADD_SIM_MSG] = &MsgAddSimMessageHandler;
173 handlerMap[MSG_CMD_PLG_RESEND_MESSAGE] = &MsgResendMessageHandler;
174 #ifdef FEATURE_SMS_CDMA
175 handlerMap[MSG_CMD_PLG_CHECK_UNIQUENESS] = &MsgCheckUniquenessHandler;
177 handlerMap[MSG_CMD_UPDATE_IMSI] = &MsgUpdateIMSIHandler;
181 MsgTransactionManager::~MsgTransactionManager()
183 /* pthread_cond_init(&retCV, NULL); */ /* = PTHREAD_COND_INITIALIZER; */
187 MsgTransactionManager* MsgTransactionManager::instance()
190 pInstance = new MsgTransactionManager();
195 static void* worker_event_queue(void* arg)
197 MsgTransactionManager::instance()->workerEventQueue();
201 void MsgTransactionManager::run()
203 servSock.open(MSG_SOCKET_PATH);
205 fd_set readfds = servSock.fdSet();
208 MSG_DEBUG("Start Transaction Manager");
210 /* Set Msg FW Ready Flag */
211 if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true) != MSG_SUCCESS)
212 MSG_DEBUG("MsgSettingSetBool FAIL : VCONFKEY_MSG_SERVER_READY");
213 MSG_INFO("### VCONFKEY_MSG_SERVER_READY ###");
215 /* running worker for plg task */
217 if (pthread_create(&tv, NULL, &worker_event_queue, NULL) != 0) {
218 THROW(MsgException::SERVER_READY_ERROR, "cannot create thread [%d]", errno);
222 readfds = servSock.fdSet();
223 nfds = servSock.maxFd();
225 MSG_DEBUG("Wait For Select() : nfds %d", nfds);
227 if(select(nfds, &readfds, NULL, NULL, NULL) == -1) {
228 THROW(MsgException::SELECT_ERROR, "select error : %s", g_strerror(errno));
232 for (int i=0 ; i < nfds; i++) {
233 if (FD_ISSET(i, &readfds)) {
234 if (i == servSock.fd()) /* if it is socket connection request */
240 } catch (MsgException& e) {
241 MSG_FATAL("%s", e.what());
242 } catch (exception& e) {
243 MSG_FATAL("%s", e.what());
249 void MsgTransactionManager::write(int fd, const char* buf, int len)
251 servSock.write(fd, buf, len);
255 void MsgTransactionManager::insertSentMsg(int reqId, MSG_PROXY_INFO_S* pPrxInfo)
257 if (pPrxInfo == NULL)
258 THROW(MsgException::SENT_STATUS_ERROR, "Input Parameter is NULL");
260 MSG_DEBUG("msg for submit: reqId %d listenerFd %d handleAddr %x", reqId, pPrxInfo->listenerFd, pPrxInfo->handleAddr);
262 MsgMutexLocker lock(mx);
264 fd_map::iterator it = statusCBFdMap.find(pPrxInfo->listenerFd);
266 if (it == statusCBFdMap.end()) { /* if the status CB is not registered */
267 MSG_DEBUG("No sent_status registered for fd %d", pPrxInfo->listenerFd);
269 sentMsgMap.insert(make_pair(reqId, *pPrxInfo));
274 MSG_PROXY_INFO_S* MsgTransactionManager::getProxyInfo(int reqId)
276 sentmsg_map::iterator it = sentMsgMap.find(reqId);
278 if (it == sentMsgMap.end()) {
279 MSG_DEBUG("No sent status cb found");
283 return &(it->second);
287 void MsgTransactionManager::delProxyInfo(int reqId)
289 MsgMutexLocker lock(mx);
291 sentmsg_map::iterator it = sentMsgMap.find(reqId);
293 if (it == sentMsgMap.end()) {
294 THROW(MsgException::SENT_STATUS_ERROR, "channel info does not exist");
297 sentMsgMap.erase(it);
300 void MsgTransactionManager::workerEventQueue()
302 MSG_CMD_S* pCmd = NULL;
303 int (*pfHandler)(const MSG_CMD_S*, char**) = NULL;
304 char* pEventData = NULL;
305 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
312 while (!eventQueue.front(&pCmd)) { /* if no item, wait */
313 MSG_DEBUG("waiting for task");
314 cv.wait(mxQ.pMsgMutex());
316 eventQueue.pop_front(); /* pop it from queue*/
320 MSG_FATAL("pCmd NULL");
324 memcpy (&fd, pCmd->cmdCookie, sizeof(int));
326 MSG_FATAL("fd [%d] < 0", fd);
327 g_free(pCmd); pCmd = NULL;
330 pfHandler = handlerMap[pCmd->cmdType];
332 MSG_FATAL("No handler for %d", pCmd->cmdType);
333 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_INVALID_PARAMETER, &eventSize, &pEventData);
335 /* run handler function */
336 eventSize = pfHandler(pCmd, &pEventData);
338 if (eventSize == 0 || pEventData == NULL) {
339 MSG_FATAL("event size[%d] = 0 or event data = NULL", eventSize);
340 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_INVALID_PARAMETER, &eventSize, &pEventData);
344 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
345 servSock.write(fd, pEventData, eventSize);
346 g_free(pCmd); pCmd = NULL;
350 void MsgTransactionManager::handleRequest(int fd)
354 MSG_DEBUG("Event from fd %d", fd);
357 unique_ptr<char*, void(*)(char**)> wrap(&buf, unique_ptr_deleter);
359 int ret = servSock.read(fd, &buf, &len);
361 if (ret == CLOSE_CONNECTION_BY_SIGNAL || ret == CLOSE_CONNECTION_BY_USER || ret < 0) {
362 MSG_DEBUG("Read value [%d]", ret);
367 if (len <= 0 && len >= MSG_MAX_IPC_SIZE)
368 THROW(MsgException::INVALID_RESULT, "read buffer size <= 0 or over max ipc size");
370 char* pEventData = NULL;
371 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
375 /* decoding cmd from APP */
376 MSG_CMD_S* pCmd = (MSG_CMD_S*) buf;
377 MSG_DEBUG("Command Type [%d : %s]", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType));
379 if (pCmd->cmdType > MSG_CMD_NUM)
380 THROW(MsgException::OUT_OF_RANGE, "request CMD is not defined");
382 /* check privilege */
383 if (checkPrivilege(fd, pCmd->cmdType) == false) {
384 MSG_DEBUG("No Privilege rule. Not allowed.");
385 #ifdef MSG_CHECK_PRIVILEGE
386 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_PERMISSION_DENIED, &eventSize, &pEventData);
388 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
389 servSock.write(fd, pEventData, eventSize);
395 /* determine the handler based on pCmd->cmdType */
396 int (*pfHandler)(const MSG_CMD_S*, char**) = NULL;
397 MSG_CMD_S* pCmdDup = NULL;
399 switch (pCmd->cmdType) {
400 case MSG_CMD_PLG_SENT_STATUS_CNF:
401 case MSG_CMD_PLG_STORAGE_CHANGE_IND:
402 case MSG_CMD_PLG_INCOMING_MSG_IND:
403 case MSG_CMD_PLG_INCOMING_MMS_CONF:
404 case MSG_CMD_PLG_INCOMING_SYNCML_IND:
405 case MSG_CMD_PLG_INCOMING_LBS_IND:
406 case MSG_CMD_PLG_INIT_SIM_BY_SAT:
407 case MSG_CMD_PLG_INCOMING_PUSH_IND:
408 case MSG_CMD_PLG_INCOMING_CB_IND:
409 pCmdDup = (MSG_CMD_S*)calloc(1, len); /* pCmdDup should be freed afterward */
410 if (pCmdDup != NULL) {
411 memcpy(pCmdDup, pCmd, len);
412 memcpy(pCmdDup->cmdCookie, &fd, sizeof(int)); /* Now, cmdCookie keeps fd for return */
414 mxQ.lock(); /* aquire lock before adding cmd */
415 eventQueue.push_back(pCmdDup);
416 cv.signal(); /* wake up worker */
420 case MSG_CMD_CHECK_PERMISSION:
421 MSG_DEBUG("Client has privilege. Allowed.");
422 MsgMakeErrorEvent(pCmd->cmdType, MSG_SUCCESS, &eventSize, &pEventData);
423 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
424 servSock.write(fd, pEventData, eventSize);
427 pfHandler = handlerMap[pCmd->cmdType];
429 MSG_FATAL("No handler for %d", pCmd->cmdType);
430 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_INVALID_PARAMETER, &eventSize, &pEventData);
432 /* run handler function */
433 memcpy (pCmd->cmdCookie, &fd, sizeof(int)); /* Now, cmdCookie keeps fd for return */
434 eventSize = pfHandler(pCmd, &pEventData);
436 if (eventSize == 0 || pEventData == NULL) {
437 MSG_FATAL("event size[%d] = 0 or event data = NULL", eventSize);
438 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_INVALID_PARAMETER, &eventSize, &pEventData);
442 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
443 servSock.write(fd, pEventData, eventSize);
451 /* terminating the socket connection between ipc server and ipc client */
452 void MsgTransactionManager::cleanup(int fd)
456 MsgMutexLocker lock(mx);
460 MSG_DEBUG("fd %d disonnected", fd);
462 /* remove sent msg info for fd */
463 sentmsg_map::iterator sentmsg_it = sentMsgMap.begin();
465 for (; sentmsg_it != sentMsgMap.end(); sentmsg_it++) {
466 if (sentmsg_it->second.listenerFd == fd) {
467 sentmsg_it->second.listenerFd = 0;
468 sentmsg_it->second.handleAddr = 0;
472 /* remove sent status callback for fd */
473 statusCBFdMap.erase(fd);
475 MSG_DEBUG("After erase fd [%d], statusCBFdMap has below.", fd);
476 fd_map::iterator it = statusCBFdMap.begin();
477 for (; it != statusCBFdMap.end(); ++it)
478 MSG_DEBUG("[%d]", it->first);
480 /* remove all newMsgCBs for fd */
481 newmsg_list::iterator newmsg_it = newMsgCBList.begin();
483 while (newmsg_it != newMsgCBList.end()) {
484 if (newmsg_it->listenerFd == fd) {
485 newmsg_it = newMsgCBList.erase(newmsg_it);
491 /* remove all newMMSConfMsgCBs for fd */
492 mmsconf_list::iterator mmsconf_it = newMMSConfMsgCBList.begin();
494 while (mmsconf_it != newMMSConfMsgCBList.end()) {
495 if (mmsconf_it->listenerFd == fd) {
496 mmsconf_it = newMMSConfMsgCBList.erase(mmsconf_it);
502 /* remove all newSyncMLMsgCBs for fd */
503 syncmlmsg_list::iterator syncmlmsg_it = newSyncMLMsgCBList.begin();
505 while (syncmlmsg_it != newSyncMLMsgCBList.end()) {
506 if (syncmlmsg_it->listenerFd == fd) {
507 syncmlmsg_it = newSyncMLMsgCBList.erase(syncmlmsg_it);
513 /* remove all newLBSMsgCBs for fd */
514 lbsmsg_list::iterator lbsmsg_it = newLBSMsgCBList.begin();
516 while (lbsmsg_it != newLBSMsgCBList.end()) {
517 if (lbsmsg_it->listenerFd == fd) {
518 lbsmsg_it = newLBSMsgCBList.erase(lbsmsg_it);
524 /* remove all newPushMsgCBs for fd */
525 pushmsg_list::iterator pushmsg_it = newPushMsgCBList.begin();
527 while (pushmsg_it != newPushMsgCBList.end()) {
528 if (pushmsg_it->listenerFd == fd) {
529 pushmsg_it = newPushMsgCBList.erase(pushmsg_it);
535 /* remove all newCBMsgCBs for fd */
536 cbmsg_list::iterator cbmsg_it = newCBMsgCBList.begin();
537 /*bool bSave = false; */
539 while (cbmsg_it != newCBMsgCBList.end()) {
540 if (cbmsg_it->listenerFd == fd) {
541 cbmsg_it = newCBMsgCBList.erase(cbmsg_it);
543 /*if (cbmsg_it->bsave == true) */
549 /* remove all operationSyncMLMsgCBs for fd */
550 syncmlop_list::iterator syncmlop_it = operationSyncMLMsgCBList.begin();
552 while (syncmlop_it != operationSyncMLMsgCBList.end()) {
553 if (syncmlop_it->listenerFd == fd) {
554 syncmlop_it = operationSyncMLMsgCBList.erase(syncmlop_it);
560 /* remove storage change callback for fd */
561 storageChangeFdMap.erase(fd);
563 MSG_DEBUG("After erase fd [%d], storageChangeFdMap has below.", fd);
564 it = storageChangeFdMap.begin();
565 for (; it != storageChangeFdMap.end(); ++it)
566 MSG_DEBUG("[%d]", it->first);
568 /* remove report msg incoming callback for fd */
569 reportMsgCBFdMap.erase(fd);
571 MSG_DEBUG("After erase fd [%d], reportMsgCBFdMap has below.", fd);
572 it = reportMsgCBFdMap.begin();
573 for (; it != reportMsgCBFdMap.end(); ++it)
574 MSG_DEBUG("[%d]", it->first);
580 bool MsgTransactionManager::checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType)
582 bool bAllowed = true;
585 char *peer_client = NULL;
586 char *peer_user = NULL;
587 char *peer_session = NULL;
590 if (p_cynara == NULL) {
591 if (this->initCynara() == false) {
592 MSG_ERR("Cynara initialize failed. It will try again when API is called.");
598 ret = cynara_creds_socket_get_client(fd, client_method, &peer_client);
599 if (ret != CYNARA_API_SUCCESS) {
600 MSG_ERR("cynara_creds_socket_get_client() is failed [%d]", ret);
605 ret = cynara_creds_socket_get_user(fd, user_method, &peer_user);
606 if (ret != CYNARA_API_SUCCESS) {
607 MSG_ERR("cynara_creds_socket_get_user() is failed [%d]", ret);
612 ret = cynara_creds_socket_get_pid(fd, &peer_pid);
613 if (ret != CYNARA_API_SUCCESS) {
614 MSG_ERR("cynara_creds_socket_get_pid() is failed [%d]", ret);
619 peer_session = cynara_session_from_pid(peer_pid);
620 if (peer_session == NULL) {
621 MSG_ERR("cynara_session_from_pid() is failed");
627 case MSG_CMD_GET_MSG:
628 case MSG_CMD_COUNT_MSG:
629 case MSG_CMD_COUNT_BY_MSGTYPE:
630 case MSG_CMD_REG_INCOMING_MSG_CB:
631 case MSG_CMD_REG_INCOMING_CB_MSG_CB:
632 case MSG_CMD_REG_INCOMING_PUSH_MSG_CB:
633 case MSG_CMD_REG_SENT_STATUS_CB:
634 case MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB:
635 case MSG_CMD_REG_INCOMING_SYNCML_MSG_CB:
636 case MSG_CMD_REG_INCOMING_LBS_MSG_CB:
637 case MSG_CMD_REG_SYNCML_MSG_OPERATION_CB:
638 case MSG_CMD_REG_REPORT_MSG_INCOMING_CB:
639 case MSG_CMD_GET_CONTACT_COUNT:
640 case MSG_CMD_GET_FOLDERLIST:
641 case MSG_CMD_GET_QUICKPANEL_DATA:
642 case MSG_CMD_GET_MEMSIZE:
643 case MSG_CMD_BACKUP_MESSAGE:
644 case MSG_CMD_REG_STORAGE_CHANGE_CB:
645 case MSG_CMD_GET_REPORT_STATUS:
646 case MSG_CMD_GET_THREAD_ID_BY_ADDRESS:
647 case MSG_CMD_GET_THREAD_INFO:
648 case MSG_CMD_SYNCML_OPERATION:
649 case MSG_CMD_GET_FILTERLIST:
650 case MSG_CMD_GET_FILTER_OPERATION:
651 case MSG_CMD_GET_SMSC_OPT:
652 case MSG_CMD_GET_CB_OPT:
653 case MSG_CMD_GET_SMS_SEND_OPT:
654 case MSG_CMD_GET_MMS_SEND_OPT:
655 case MSG_CMD_GET_MMS_RECV_OPT:
656 case MSG_CMD_GET_PUSH_MSG_OPT:
657 case MSG_CMD_GET_VOICE_MSG_OPT:
658 case MSG_CMD_GET_GENERAL_MSG_OPT:
659 case MSG_CMD_GET_MSG_SIZE_OPT:
660 ret = cynara_check(p_cynara, peer_client, peer_session, peer_user,
661 "http://tizen.org/privilege/message.read");
662 if (ret != CYNARA_API_ACCESS_ALLOWED) {
663 MSG_INFO("privilege [read] not allowd : [%d]", ret);
667 case MSG_CMD_SUBMIT_REQ:
668 case MSG_CMD_SET_CB_OPT:
669 case MSG_CMD_ADD_PUSH_EVENT:
670 case MSG_CMD_DELETE_PUSH_EVENT:
671 case MSG_CMD_UPDATE_PUSH_EVENT:
672 case MSG_CMD_ADD_MSG:
673 case MSG_CMD_ADD_SYNCML_MSG:
674 case MSG_CMD_UPDATE_MSG:
675 case MSG_CMD_UPDATE_READ:
676 case MSG_CMD_UPDATE_PROTECTED:
677 case MSG_CMD_DELETE_MSG:
678 case MSG_CMD_DELALL_MSGINFOLDER:
679 case MSG_CMD_MOVE_MSGTOFOLDER:
680 case MSG_CMD_MOVE_MSGTOSTORAGE:
681 case MSG_CMD_DELETE_THREADMESSAGELIST:
682 case MSG_CMD_ADD_FOLDER:
683 case MSG_CMD_UPDATE_FOLDER:
684 case MSG_CMD_DELETE_FOLDER:
685 case MSG_CMD_RESET_DB:
686 case MSG_CMD_RESTORE_MESSAGE:
687 case MSG_CMD_DELETE_MESSAGE_BY_LIST:
688 case MSG_CMD_UPDATE_THREAD_READ:
689 case MSG_CMD_ADD_FILTER:
690 case MSG_CMD_UPDATE_FILTER:
691 case MSG_CMD_DELETE_FILTER:
692 case MSG_CMD_SET_FILTER_OPERATION:
693 case MSG_CMD_SET_FILTER_ACTIVATION:
694 case MSG_CMD_SET_SMSC_OPT:
695 case MSG_CMD_SET_SMS_SEND_OPT:
696 case MSG_CMD_SET_MMS_SEND_OPT:
697 case MSG_CMD_SET_MMS_RECV_OPT:
698 case MSG_CMD_SET_PUSH_MSG_OPT:
699 case MSG_CMD_SET_VOICE_MSG_OPT:
700 case MSG_CMD_SET_GENERAL_MSG_OPT:
701 case MSG_CMD_SET_MSG_SIZE_OPT:
702 ret = cynara_check(p_cynara, peer_client, peer_session, peer_user,
703 "http://tizen.org/privilege/message.write");
704 if (ret != CYNARA_API_ACCESS_ALLOWED) {
705 MSG_INFO("privilege [write] not allowd : [%d]", ret);
709 case MSG_CMD_CHECK_PERMISSION:
710 ret = cynara_check(p_cynara, peer_client, peer_session, peer_user,
711 "http://tizen.org/privilege/message.read");
712 if (ret != CYNARA_API_ACCESS_ALLOWED) {
713 ret = cynara_check(p_cynara, peer_client, peer_session, peer_user,
714 "http://tizen.org/privilege/message.write");
715 if (ret != CYNARA_API_ACCESS_ALLOWED) {
716 MSG_INFO("privilege [write] not allowd : [%d]", ret);
726 MSG_FREE(peer_client);
728 MSG_FREE(peer_session);
734 void MsgTransactionManager::setSentStatusCB(int listenerFd)
737 THROW(MsgException::INVALID_PARAM, "InParam Error: listenerFd %d", listenerFd);
739 statusCBFdMap[listenerFd] = true;
743 void MsgTransactionManager::setIncomingMsgCB(MSG_CMD_REG_INCOMING_MSG_CB_S *pCbInfo)
746 MSG_FATAL("cbinfo NULL");
750 MsgMutexLocker lock(mx);
752 newmsg_list::iterator it = newMsgCBList.begin();
754 for (; it != newMsgCBList.end(); it++) {
755 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && (it->port == pCbInfo->port)) {
756 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d, port %d", it->listenerFd, it->msgType, it->port);
761 newMsgCBList.push_back(*pCbInfo);
765 void MsgTransactionManager::setMMSConfMsgCB(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCbInfo)
768 MSG_FATAL("cbinfo NULL");
772 MsgMutexLocker lock(mx);
774 mmsconf_list::iterator it = newMMSConfMsgCBList.begin();
776 for (; it != newMMSConfMsgCBList.end(); it++) {
777 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && (!strncmp(it->appId, pCbInfo->appId, MAX_MMS_JAVA_APPID_LEN))) {
778 MSG_DEBUG("Duplicated MMSConfMessageCB info fd:%d, mType:%d, appId:%s", it->listenerFd, it->msgType, it->appId);
783 newMMSConfMsgCBList.push_back(*pCbInfo);
787 void MsgTransactionManager::setPushMsgCB(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCbInfo)
790 MSG_FATAL("cbinfo NULL");
794 MsgMutexLocker lock(mx);
796 pushmsg_list::iterator it = newPushMsgCBList.begin();
798 for (; it != newPushMsgCBList.end(); it++) {
799 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && !strncmp(it->appId, pCbInfo->appId, MAX_WAPPUSH_ID_LEN)) {
800 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
805 newPushMsgCBList.push_back(*pCbInfo);
808 void MsgTransactionManager::setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo)
812 MSG_FATAL("cbinfo NULL");
816 MsgMutexLocker lock(mx);
818 cbmsg_list::iterator it = newCBMsgCBList.begin();
820 for (; it != newCBMsgCBList.end(); it++) {
821 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType)) {
822 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
826 MSG_DEBUG("bSave : [%d]", pCbInfo->bsave);
829 if(MsgSettingSetBool(CB_SAVE, pCbInfo->bsave) != MSG_SUCCESS)
830 MSG_DEBUG("MsgSettingSetBool FAIL: CB_SAVE");
834 newCBMsgCBList.push_back(*pCbInfo);
840 void MsgTransactionManager::setSyncMLMsgCB(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCbInfo)
843 MSG_FATAL("cbinfo NULL");
847 MsgMutexLocker lock(mx);
849 syncmlmsg_list::iterator it = newSyncMLMsgCBList.begin();
851 for (; it != newSyncMLMsgCBList.end(); it++) {
852 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType)) {
853 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
858 newSyncMLMsgCBList.push_back(*pCbInfo);
862 void MsgTransactionManager::setLBSMsgCB(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCbInfo)
865 MSG_FATAL("cbinfo NULL");
869 MsgMutexLocker lock(mx);
871 lbsmsg_list::iterator it = newLBSMsgCBList.begin();
873 for (; it != newLBSMsgCBList.end(); it++) {
874 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType)) {
875 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
880 newLBSMsgCBList.push_back(*pCbInfo);
884 void MsgTransactionManager::setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *pTrId)
887 MSG_FATAL("trId NULL");
891 javamms_list::iterator it;
893 for (it = javaMMSList.begin(); it != javaMMSList.end(); it++) {
894 if (!strcmp(it->id, pTrId->id)) {
895 MSG_SEC_DEBUG("Duplicated javaMMS transaction Id:%s", it->id);
900 javaMMSList.push_back(*pTrId);
904 void MsgTransactionManager::setSyncMLMsgOperationCB(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCbInfo)
907 MSG_FATAL("cbinfo NULL");
911 MsgMutexLocker lock(mx);
913 syncmlop_list::iterator it = operationSyncMLMsgCBList.begin();
915 for (; it != operationSyncMLMsgCBList.end(); it++) {
916 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType)) {
917 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
922 operationSyncMLMsgCBList.push_back(*pCbInfo);
926 void MsgTransactionManager::setStorageChangeCB(int listenerFd)
929 THROW(MsgException::INVALID_PARAM, "InParam Error: listenerFd %d", listenerFd);
931 MsgMutexLocker lock(mx);
933 storageChangeFdMap[listenerFd] = true;
937 void MsgTransactionManager::setReportMsgCB(int listenerFd)
940 THROW(MsgException::INVALID_PARAM, "InParam Error: listenerFd %d", listenerFd);
942 MsgMutexLocker lock(mx);
944 reportMsgCBFdMap[listenerFd] = true;
948 javamms_list& MsgTransactionManager::getJavaMMSList()
954 void MsgTransactionManager::broadcastIncomingMsgCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo)
958 if ((msgInfo->msgPort.valid == true) && (msgInfo->msgPort.dstPort == MSG_LBS_PORT)) {
959 MSG_DEBUG("Message for LBS.");
961 if (msgInfo->bTextSms == false) {
962 MSG_DEBUG("msgInfo->bTextSms == false");
966 char* pFileData = NULL;
967 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
969 if (MsgOpenAndReadFile(msgInfo->msgData, &pFileData, &fileSize) == true)
970 MsgLbsSms(pFileData, fileSize);
972 MSG_DEBUG("MsgOpenAndReadFile failed.");
974 MsgLbsSms(msgInfo->msgText, (int)msgInfo->dataSize);
979 char* pEventData = NULL;
980 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
982 char* encodedData = NULL;
983 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
984 int dataSize = MsgEncodeMsgInfo(msgInfo, &encodedData);
986 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)(&pEventData));
988 MSG_DEBUG("valid %d dstport %d", msgInfo->msgPort.valid, msgInfo->msgPort.dstPort);
990 MsgMutexLocker lock(mx);
992 newmsg_list::iterator it = newMsgCBList.begin();
994 for (; it != newMsgCBList.end(); it++) {
995 MSG_DEBUG("fd %d dstport %d", it->listenerFd, it->port);
997 if ((msgInfo->msgPort.valid == false) && (it->port == 0)) {
998 MSG_DEBUG("Send incoming normal msg to listener %d", it->listenerFd);
999 write(it->listenerFd, pEventData, eventSize);
1000 } else if ((msgInfo->msgPort.valid == true) && (it->port == msgInfo->msgPort.dstPort)) {
1001 MSG_DEBUG("Send incoming port msg to listener %d", it->listenerFd);
1002 write(it->listenerFd, pEventData, eventSize);
1010 void MsgTransactionManager::broadcastMMSConfCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo, const MMS_RECV_DATA_S *mmsRecvData)
1014 char* pEventData = NULL;
1015 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1017 char* encodedData = NULL;
1018 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1019 int dataSize = MsgEncodeMsgInfo(msgInfo, &encodedData);
1021 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)(&pEventData));
1023 MsgMutexLocker lock(mx);
1025 mmsconf_list::iterator it = newMMSConfMsgCBList.begin();
1027 for (; it != newMMSConfMsgCBList.end(); it++) {
1028 MSG_DEBUG("fd:%d appId:%s", it->listenerFd, it->appId);
1030 if (mmsRecvData->msgAppId.valid == true) {
1031 if (!strcmp(it->appId, mmsRecvData->msgAppId.appId)) {
1032 MSG_DEBUG("Send incoming java msg to listener %d", it->listenerFd);
1033 write(it->listenerFd, pEventData, eventSize);
1036 if (strlen(it->appId) <= 0) {
1037 MSG_DEBUG("Send incoming normal msg to listener %d", it->listenerFd);
1038 write(it->listenerFd, pEventData, eventSize);
1047 void MsgTransactionManager::broadcastPushMsgCB(const msg_error_t err, const MSG_PUSH_MESSAGE_DATA_S *pushData)
1051 char* pEventData = NULL;
1052 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1054 int eventSize = MsgMakeEvent(pushData, sizeof(MSG_PUSH_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, err, (void**)(&pEventData));
1056 MsgMutexLocker lock(mx);
1058 pushmsg_list::iterator it = newPushMsgCBList.begin();
1060 for (; it != newPushMsgCBList.end(); it++) {
1061 MSG_DEBUG("registered_appid : %s, incoming_appid: %s", it->appId, pushData->pushAppId);
1062 if (!strcmp(it->appId, pushData->pushAppId)) {
1063 MSG_DEBUG("Send incoming Push information to listener %d", it->listenerFd);
1064 write(it->listenerFd, pEventData, eventSize);
1071 void MsgTransactionManager::broadcastCBMsgCB(const msg_error_t err, const MSG_CB_MSG_S *cbMsg, msg_message_id_t cbMsgId)
1075 char* pEventData = NULL;
1076 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1078 int eventSize = MsgMakeEvent(cbMsg, sizeof(MSG_CB_MSG_S), MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)(&pEventData));
1080 MsgMutexLocker lock(mx);
1082 cbmsg_list::iterator it = newCBMsgCBList.begin();
1084 for (; it != newCBMsgCBList.end(); it++) {
1085 MSG_DEBUG("Send incoming CB information to listener %d", it->listenerFd);
1086 write(it->listenerFd, pEventData, eventSize);
1089 /* Send system event */
1091 b = bundle_create();
1093 bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_CB);
1094 char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
1095 snprintf(msgId, sizeof(msgId), "%u", cbMsgId);
1096 bundle_add_str(b, EVT_KEY_MSG_ID, msgId);
1097 eventsystem_send_system_event(SYS_EVENT_INCOMMING_MSG, b);
1104 void MsgTransactionManager::broadcastSyncMLMsgCB(const msg_error_t err, const MSG_SYNCML_MESSAGE_DATA_S *syncMLData)
1108 char* pEventData = NULL;
1109 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1111 int eventSize = MsgMakeEvent(syncMLData, sizeof(MSG_SYNCML_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, err, (void**)(&pEventData));
1113 MsgMutexLocker lock(mx);
1115 syncmlmsg_list::iterator it = newSyncMLMsgCBList.begin();
1117 for (; it != newSyncMLMsgCBList.end(); it++) {
1118 MSG_DEBUG("Send incoming SyncML information to listener %d", it->listenerFd);
1119 write(it->listenerFd, pEventData, eventSize);
1126 void MsgTransactionManager::broadcastLBSMsgCB(const msg_error_t err, const MSG_LBS_MESSAGE_DATA_S *lbsData)
1131 char* pEventData = NULL;
1132 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1134 int eventSize = MsgMakeEvent(lbsData, sizeof(MSG_LBS_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, err, (void**)(&pEventData));
1136 MsgMutexLocker lock(mx);
1138 lbsmsg_list::iterator it = newLBSMsgCBList.begin();
1140 for (; it != newLBSMsgCBList.end(); it++) {
1141 MSG_DEBUG("Send incoming LBS msg to listener %d", it->listenerFd);
1142 write(it->listenerFd, pEventData, eventSize);
1145 MsgLbsWapPush(lbsData->pushHeader, lbsData->pushBody, lbsData->pushBodyLen);
1151 void MsgTransactionManager::broadcastSyncMLMsgOperationCB(const msg_error_t err, const int msgId, const int extId)
1155 char* pEventData = NULL;
1156 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1158 char* encodedData = NULL;
1159 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1161 /* Encoding Storage Change Data */
1162 int dataSize = MsgEncodeSyncMLOperationData(msgId, extId, &encodedData);
1164 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_SYNCML_OPERATION, err, (void**)(&pEventData));
1166 MsgMutexLocker lock(mx);
1168 syncmlop_list::iterator it = operationSyncMLMsgCBList.begin();
1170 for( ; it != operationSyncMLMsgCBList.end() ; it++ ) {
1171 MSG_DEBUG("Send SyncML operation to listener %d", it->listenerFd);
1172 write(it->listenerFd, pEventData, eventSize);
1179 void MsgTransactionManager::broadcastStorageChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList)
1183 if(pMsgIdList == NULL) {
1184 MSG_DEBUG("pMsgIdList is NULL.");
1188 MSG_DEBUG("storageChangeType [%d]", storageChangeType);
1192 char* pEventData = NULL;
1193 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1195 char* encodedData = NULL;
1196 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1198 /* Encoding Storage Change Data */
1199 dataSize = MsgEncodeStorageChangeData(storageChangeType, pMsgIdList, &encodedData);
1201 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_STORAGE_CHANGE_IND, err, (void**)(&pEventData));
1203 MsgMutexLocker lock(mx);
1205 fd_map::iterator it = storageChangeFdMap.begin();
1207 for (; it != storageChangeFdMap.end(); it++) {
1208 MSG_DEBUG("Send Storage Change Callback to listener %d", it->first);
1209 write(it->first, pEventData, eventSize);
1216 void MsgTransactionManager::broadcastReportMsgCB(const msg_error_t err, const msg_report_type_t reportMsgType, const MSG_MESSAGE_INFO_S *pMsgInfo)
1220 if(pMsgInfo == NULL) {
1221 MSG_DEBUG("pMsgInfo is NULL.");
1225 MSG_DEBUG("reportMsgType [%d]", reportMsgType);
1229 char* pEventData = NULL;
1230 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1232 char* encodedData = NULL;
1233 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1235 /* Encoding Storage Change Data */
1236 dataSize = MsgEncodeReportMsgData(reportMsgType, pMsgInfo, &encodedData);
1238 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND, err, (void**)(&pEventData));
1240 MsgMutexLocker lock(mx);
1242 fd_map::iterator it = reportMsgCBFdMap.begin();
1244 for (; it != reportMsgCBFdMap.end(); it++) {
1245 MSG_DEBUG("Send Report Message Incoming Callback to listener %d", it->first);
1246 write(it->first, pEventData, eventSize);
1253 bool MsgTransactionManager::initCynara()
1257 ret = cynara_initialize(&p_cynara, NULL);
1259 if (ret == CYNARA_API_SUCCESS) {
1260 MSG_INFO("cynara_initialize() is successful");
1262 MSG_INFO("cynara_initialize() is failed [%d]", ret);
1266 ret = cynara_creds_get_default_client_method(&client_method);
1267 if (ret != CYNARA_API_SUCCESS) {
1268 MSG_ERR("cynara_creds_get_default_client_method() is failed [%d]", ret);
1272 ret = cynara_creds_get_default_user_method(&user_method);
1273 if (ret != CYNARA_API_SUCCESS) {
1274 MSG_ERR("cynara_creds_get_default_user_method() is failed [%d]", ret);
1282 void MsgTransactionManager::finishCynara()
1286 ret = cynara_finish(p_cynara);
1288 if (ret == CYNARA_API_SUCCESS) {
1289 MSG_INFO("cynara_finish() is successful");
1291 MSG_INFO("cynara_finish() is failed [%d]", ret);