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>
25 #include <eventsystem.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 "MsgSqliteWrapper.h"
35 #include "MsgUtilStorage.h"
36 #include "MsgUtilFunction.h"
37 #include "MsgUtilFile.h"
39 #include "MsgCmdHandler.h"
40 #include "MsgSettingHandler.h"
41 #include "MsgStorageHandler.h"
42 #include "MsgPluginManager.h"
43 #include "MsgTransManager.h"
45 #define MSG_CHECK_PRIVILEGE
47 std::list<msg_thread_id_t> cur_conv_list;
49 void MsgMakeErrorEvent(MSG_CMD_TYPE_T cmdType, msg_error_t errType, int *pEventSize, char **ppEvent)
51 if (*ppEvent) delete [] *ppEvent;
53 *pEventSize = sizeof(MSG_EVENT_S);
54 *ppEvent = new char[sizeof(MSG_EVENT_S)];
56 MSG_EVENT_S* pMsgEvent = (MSG_EVENT_S*)*ppEvent;
58 pMsgEvent->eventType = cmdType;
59 pMsgEvent->result = errType;
62 void initConversationList()
64 MsgDbHandler *dbHandle = getDbHandle();
66 msg_error_t err = MSG_SUCCESS;
69 char sqlQuery[MAX_QUERY_LEN+1] = {0};
70 snprintf(sqlQuery, MAX_QUERY_LEN, "SELECT CONV_ID FROM %s;", MSGFW_CONVERSATION_TABLE_NAME);
72 err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
73 if (err != MSG_SUCCESS) {
74 MSG_DEBUG("getTable failed [%d]", err);
75 dbHandle->freeTable();
79 for (int i = 0; i < rowCnt; i++)
80 cur_conv_list.push_back((msg_thread_id_t)dbHandle->getColumnToInt(i+1));
82 dbHandle->freeTable();
85 /*==================================================================================================
86 IMPLEMENTATION OF MsgTransactionManager - Member Functions
87 ==================================================================================================*/
88 MsgTransactionManager* MsgTransactionManager::pInstance = NULL;
89 MsgIpcServerSocket MsgTransactionManager::servSock;
92 MsgTransactionManager::MsgTransactionManager() : running(false), mx(), mxQ(), cv(), eventQueue()
95 client_method = CLIENT_METHOD_DEFAULT;
96 user_method = USER_METHOD_DEFAULT;
99 statusCBFdMap.clear();
100 newMsgCBList.clear();
101 newMMSConfMsgCBList.clear();
102 newSyncMLMsgCBList.clear();
103 newLBSMsgCBList.clear();
105 operationSyncMLMsgCBList.clear();
106 storageChangeFdMap.clear();
107 threadChangeFdMap.clear();
111 initConversationList();
113 /* Fill in mMsgHandlers, as given in the below. */
114 handlerMap[MSG_CMD_ADD_MSG] = &MsgAddMessageHandler;
115 handlerMap[MSG_CMD_ADD_SYNCML_MSG] = &MsgAddSyncMLMessageHandler;
116 handlerMap[MSG_CMD_UPDATE_MSG] = &MsgUpdateMessageHandler;
117 handlerMap[MSG_CMD_UPDATE_READ] = &MsgUpdateReadStatusHandler;
118 handlerMap[MSG_CMD_UPDATE_PROTECTED] = &MsgUpdateProtectedStatusHandler;
119 handlerMap[MSG_CMD_DELETE_MSG] = &MsgDeleteMessageHandler;
120 handlerMap[MSG_CMD_DELALL_MSGINFOLDER] = &MsgDeleteAllMessageInFolderHandler;
121 handlerMap[MSG_CMD_MOVE_MSGTOFOLDER] = &MsgMoveMessageToFolderHandler;
122 handlerMap[MSG_CMD_MOVE_MSGTOSTORAGE] = &MsgMoveMessageToStorageHandler;
123 handlerMap[MSG_CMD_COUNT_MSG] = &MsgCountMessageHandler;
124 handlerMap[MSG_CMD_GET_MSG] = &MsgGetMessageHandler;
126 handlerMap[MSG_CMD_ADD_FOLDER] = &MsgAddFolderHandler;
127 handlerMap[MSG_CMD_UPDATE_FOLDER] = &MsgUpdateFolderHandler;
128 handlerMap[MSG_CMD_DELETE_FOLDER] = &MsgDeleteFolderHandler;
129 handlerMap[MSG_CMD_GET_FOLDERLIST] = &MsgGetFolderListHandler;
131 handlerMap[MSG_CMD_ADD_FILTER] = &MsgAddFilterHandler;
132 handlerMap[MSG_CMD_UPDATE_FILTER] = &MsgUpdateFilterHandler;
133 handlerMap[MSG_CMD_DELETE_FILTER] = &MsgDeleteFilterHandler;
134 handlerMap[MSG_CMD_GET_FILTERLIST] = &MsgGetFilterListHandler;
135 handlerMap[MSG_CMD_SET_FILTER_OPERATION] = &MsgSetFilterOperationHandler;
136 handlerMap[MSG_CMD_GET_FILTER_OPERATION] = &MsgGetFilterOperationHandler;
137 handlerMap[MSG_CMD_SET_FILTER_ACTIVATION] = &MsgSetFilterActivationHandler;
139 handlerMap[MSG_CMD_SUBMIT_REQ] = &MsgSubmitReqHandler;
141 handlerMap[MSG_CMD_REG_SENT_STATUS_CB] = &MsgRegSentStatusCallbackHandler;
142 handlerMap[MSG_CMD_REG_STORAGE_CHANGE_CB] = &MsgRegStorageChangeCallbackHandler;
143 handlerMap[MSG_CMD_REG_THREAD_CHANGE_CB] = &MsgRegThreadChangeCallbackHandler;
144 handlerMap[MSG_CMD_REG_INCOMING_MSG_CB] = &MsgRegIncomingMsgCallbackHandler;
145 handlerMap[MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB] = &MsgRegIncomingMMSConfMsgCallbackHandler;
146 handlerMap[MSG_CMD_REG_INCOMING_SYNCML_MSG_CB] = &MsgRegIncomingSyncMLMsgCallbackHandler;
147 handlerMap[MSG_CMD_REG_INCOMING_PUSH_MSG_CB] = &MsgRegIncomingPushMsgCallbackHandler;
148 handlerMap[MSG_CMD_REG_INCOMING_CB_MSG_CB] = &MsgRegIncomingCBMsgCallbackHandler;
149 handlerMap[MSG_CMD_REG_INCOMING_LBS_MSG_CB] = &MsgRegIncomingLBSMsgCallbackHandler;
150 handlerMap[MSG_CMD_REG_SYNCML_MSG_OPERATION_CB] = &MsgRegSyncMLMsgOperationCallbackHandler;
151 handlerMap[MSG_CMD_REG_REPORT_MSG_INCOMING_CB] = &MsgRegIncomingReportMsgCallbackHandler;
153 handlerMap[MSG_CMD_PLG_SENT_STATUS_CNF] = &MsgSentStatusHandler;
154 handlerMap[MSG_CMD_PLG_STORAGE_CHANGE_IND] = &MsgStorageChangeHandler;
155 handlerMap[MSG_CMD_PLG_THREAD_CHANGE_IND] = &MsgThreadChangeHandler;
156 handlerMap[MSG_CMD_PLG_INCOMING_MSG_IND] = &MsgIncomingMsgHandler;
157 handlerMap[MSG_CMD_PLG_INCOMING_MMS_CONF] = &MsgIncomingMMSConfMsgHandler;
158 handlerMap[MSG_CMD_PLG_INCOMING_PUSH_IND] = &MsgIncomingPushMsgHandler;
159 handlerMap[MSG_CMD_PLG_INCOMING_CB_IND] = &MsgIncomingCBMsgHandler;
161 handlerMap[MSG_CMD_PLG_INCOMING_SYNCML_IND] = &MsgIncomingSyncMLMsgHandler;
162 handlerMap[MSG_CMD_PLG_INCOMING_LBS_IND] = &MsgIncomingLBSMsgHandler;
163 handlerMap[MSG_CMD_PLG_INIT_SIM_BY_SAT] = &MsgInitSimBySatHandler;
165 handlerMap[MSG_CMD_GET_THREADVIEWLIST] = &MsgGetThreadViewListHandler;
166 handlerMap[MSG_CMD_DELETE_THREADMESSAGELIST] = &MsgDeleteThreadMessageListHandler;
167 handlerMap[MSG_CMD_SET_TEMP_ADDRESS_TABLE] = &MsgSetTempAddressTableHandler;
169 handlerMap[MSG_CMD_GET_CONTACT_COUNT] = &MsgCountMsgByContactHandler;
170 handlerMap[MSG_CMD_GET_QUICKPANEL_DATA] = &MsgGetQuickPanelDataHandler;
171 handlerMap[MSG_CMD_COUNT_BY_MSGTYPE] = &MsgCountMsgByTypeHandler;
172 handlerMap[MSG_CMD_RESET_DB] = &MsgResetDatabaseHandler;
173 handlerMap[MSG_CMD_GET_MEMSIZE] = &MsgGetMemSizeHandler;
175 handlerMap[MSG_CMD_BACKUP_MESSAGE] = &MsgBackupMessageHandler;
176 handlerMap[MSG_CMD_RESTORE_MESSAGE] = &MsgRestoreMessageHandler;
178 handlerMap[MSG_CMD_UPDATE_THREAD_READ] = &MsgUpdateThreadReadStatusHandler;
180 handlerMap[MSG_CMD_SYNCML_OPERATION] = &MsgSyncMLMsgOperationHandler;
181 handlerMap[MSG_CMD_GET_REPORT_STATUS] = &MsgGetReportStatusHandler;
183 handlerMap[MSG_CMD_GET_THREAD_ID_BY_ADDRESS] = &MsgGetThreadIdByAddressHandler;
184 handlerMap[MSG_CMD_GET_THREAD_INFO] = &MsgGetThreadInfoHandler;
185 handlerMap[MSG_CMD_GET_SMSC_OPT] = &MsgGetConfigHandler;
186 handlerMap[MSG_CMD_GET_CB_OPT] = &MsgGetConfigHandler;
187 handlerMap[MSG_CMD_GET_SMS_SEND_OPT] = &MsgGetConfigHandler;
188 handlerMap[MSG_CMD_GET_MMS_SEND_OPT] = &MsgGetConfigHandler;
189 handlerMap[MSG_CMD_GET_MMS_RECV_OPT] = &MsgGetConfigHandler;
190 handlerMap[MSG_CMD_GET_PUSH_MSG_OPT] = &MsgGetConfigHandler;
191 handlerMap[MSG_CMD_GET_VOICE_MSG_OPT] = &MsgGetConfigHandler;
192 handlerMap[MSG_CMD_GET_GENERAL_MSG_OPT] = &MsgGetConfigHandler;
193 handlerMap[MSG_CMD_GET_MSG_SIZE_OPT] = &MsgGetConfigHandler;
195 handlerMap[MSG_CMD_SET_SMSC_OPT] = &MsgSetConfigHandler;
196 handlerMap[MSG_CMD_SET_CB_OPT] = &MsgSetConfigHandler;
197 handlerMap[MSG_CMD_SET_SMS_SEND_OPT] = &MsgSetConfigHandler;
198 handlerMap[MSG_CMD_SET_MMS_SEND_OPT] = &MsgSetConfigHandler;
199 handlerMap[MSG_CMD_SET_MMS_RECV_OPT] = &MsgSetConfigHandler;
200 handlerMap[MSG_CMD_SET_PUSH_MSG_OPT] = &MsgSetConfigHandler;
201 handlerMap[MSG_CMD_SET_VOICE_MSG_OPT] = &MsgSetConfigHandler;
202 handlerMap[MSG_CMD_SET_GENERAL_MSG_OPT] = &MsgSetConfigHandler;
203 handlerMap[MSG_CMD_SET_MSG_SIZE_OPT] = &MsgSetConfigHandler;
205 handlerMap[MSG_CMD_ADD_PUSH_EVENT] = &MsgAddPushEventHandler;
206 handlerMap[MSG_CMD_DELETE_PUSH_EVENT] = &MsgDeletePushEventHandler;
207 handlerMap[MSG_CMD_UPDATE_PUSH_EVENT] = &MsgUpdatePushEventHandler;
208 handlerMap[MSG_CMD_DELETE_MESSAGE_BY_LIST] = &MsgDeleteMessageByListHandler;
209 handlerMap[MSG_CMD_ADD_SIM_MSG] = &MsgAddSimMessageHandler;
210 handlerMap[MSG_CMD_PLG_RESEND_MESSAGE] = &MsgResendMessageHandler;
211 #ifdef FEATURE_SMS_CDMA
212 handlerMap[MSG_CMD_PLG_CHECK_UNIQUENESS] = &MsgCheckUniquenessHandler;
214 handlerMap[MSG_CMD_UPDATE_IMSI] = &MsgUpdateIMSIHandler;
215 handlerMap[MSG_CMD_ALLOW_TCS_MESSAGE] = &MsgAllowTcsMessageHandler;
219 MsgTransactionManager::~MsgTransactionManager()
221 /* pthread_cond_init(&retCV, NULL); */ /* = PTHREAD_COND_INITIALIZER; */
225 MsgTransactionManager* MsgTransactionManager::instance()
228 pInstance = new MsgTransactionManager();
233 static void* worker_event_queue(void* arg)
235 MsgTransactionManager::instance()->workerEventQueue();
239 void MsgTransactionManager::run()
241 servSock.open(MSG_SOCKET_PATH);
243 fd_set readfds = servSock.fdSet();
246 MSG_DEBUG("Start Transaction Manager");
248 /* Set Msg FW Ready Flag */
249 if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true) != MSG_SUCCESS)
250 MSG_DEBUG("MsgSettingSetBool FAIL : VCONFKEY_MSG_SERVER_READY");
251 MSG_INFO("### VCONFKEY_MSG_SERVER_READY ###");
253 /* running worker for plg task */
255 if (pthread_create(&tv, NULL, &worker_event_queue, NULL) != 0) {
256 THROW(MsgException::SERVER_READY_ERROR, "cannot create thread [%d]", errno);
260 readfds = servSock.fdSet();
261 nfds = servSock.maxFd();
263 MSG_DEBUG("Wait For Select() : nfds %d", nfds);
265 if(select(nfds, &readfds, NULL, NULL, NULL) == -1) {
266 THROW(MsgException::SELECT_ERROR, "select error : %s", g_strerror(errno));
270 for (int i=0 ; i < nfds; i++) {
271 if (FD_ISSET(i, &readfds)) {
272 if (i == servSock.fd()) /* if it is socket connection request */
278 } catch (MsgException& e) {
279 MSG_FATAL("%s", e.what());
280 } catch (exception& e) {
281 MSG_FATAL("%s", e.what());
287 void MsgTransactionManager::write(int fd, const char* buf, int len)
289 servSock.write(fd, buf, len);
293 void MsgTransactionManager::insertSentMsg(int reqId, MSG_PROXY_INFO_S* pPrxInfo)
295 if (pPrxInfo == NULL)
296 THROW(MsgException::SENT_STATUS_ERROR, "Input Parameter is NULL");
298 MSG_DEBUG("msg for submit: reqId %d listenerFd %d handleAddr %x", reqId, pPrxInfo->listenerFd, pPrxInfo->handleAddr);
300 MsgMutexLocker lock(mx);
302 fd_map::iterator it = statusCBFdMap.find(pPrxInfo->listenerFd);
304 if (it == statusCBFdMap.end()) { /* if the status CB is not registered */
305 MSG_DEBUG("No sent_status registered for fd %d", pPrxInfo->listenerFd);
307 sentMsgMap.insert(make_pair(reqId, *pPrxInfo));
312 MSG_PROXY_INFO_S* MsgTransactionManager::getProxyInfo(int reqId)
314 sentmsg_map::iterator it = sentMsgMap.find(reqId);
316 if (it == sentMsgMap.end()) {
317 MSG_DEBUG("No sent status cb found");
321 return &(it->second);
325 void MsgTransactionManager::delProxyInfo(int reqId)
327 MsgMutexLocker lock(mx);
329 sentmsg_map::iterator it = sentMsgMap.find(reqId);
331 if (it == sentMsgMap.end()) {
332 THROW(MsgException::SENT_STATUS_ERROR, "channel info does not exist");
335 sentMsgMap.erase(it);
338 void MsgTransactionManager::workerEventQueue()
340 MSG_CMD_S* pCmd = NULL;
341 int (*pfHandler)(const MSG_CMD_S*, char**) = NULL;
342 char* pEventData = NULL;
343 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
350 while (!eventQueue.front(&pCmd)) { /* if no item, wait */
351 MSG_DEBUG("waiting for task");
352 cv.wait(mxQ.pMsgMutex());
354 eventQueue.pop_front(); /* pop it from queue*/
358 MSG_FATAL("pCmd NULL");
362 memcpy (&fd, pCmd->cmdCookie, sizeof(int));
364 MSG_FATAL("fd [%d] < 0", fd);
365 g_free(pCmd); pCmd = NULL;
368 pfHandler = handlerMap[pCmd->cmdType];
370 MSG_FATAL("No handler for %d", pCmd->cmdType);
371 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_INVALID_PARAMETER, &eventSize, &pEventData);
373 /* run handler function */
374 eventSize = pfHandler(pCmd, &pEventData);
376 if (eventSize == 0 || pEventData == NULL) {
377 MSG_FATAL("event size[%d] = 0 or event data = NULL", eventSize);
378 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_INVALID_PARAMETER, &eventSize, &pEventData);
382 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
383 servSock.write(fd, pEventData, eventSize);
384 g_free(pCmd); pCmd = NULL;
388 void MsgTransactionManager::handleRequest(int fd)
392 MSG_DEBUG("Event from fd %d", fd);
395 unique_ptr<char*, void(*)(char**)> wrap(&buf, unique_ptr_deleter);
397 int ret = servSock.read(fd, &buf, &len);
399 if (ret == CLOSE_CONNECTION_BY_SIGNAL || ret == CLOSE_CONNECTION_BY_USER || ret < 0) {
400 MSG_DEBUG("Read value [%d]", ret);
405 if (len <= 0 && len >= MSG_MAX_IPC_SIZE)
406 THROW(MsgException::INVALID_RESULT, "read buffer size <= 0 or over max ipc size");
408 char* pEventData = NULL;
409 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
413 /* decoding cmd from APP */
414 MSG_CMD_S* pCmd = (MSG_CMD_S*) buf;
415 MSG_DEBUG("Command Type [%d : %s]", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType));
417 if (pCmd->cmdType > MSG_CMD_NUM)
418 THROW(MsgException::OUT_OF_RANGE, "request CMD is not defined");
420 /* check privilege */
421 if (checkPrivilege(fd, pCmd->cmdType) == false) {
422 MSG_DEBUG("No Privilege rule. Not allowed.");
423 #ifdef MSG_CHECK_PRIVILEGE
424 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_PERMISSION_DENIED, &eventSize, &pEventData);
426 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
427 servSock.write(fd, pEventData, eventSize);
433 /* determine the handler based on pCmd->cmdType */
434 int (*pfHandler)(const MSG_CMD_S*, char**) = NULL;
435 MSG_CMD_S* pCmdDup = NULL;
437 switch (pCmd->cmdType) {
438 case MSG_CMD_PLG_SENT_STATUS_CNF:
439 case MSG_CMD_PLG_STORAGE_CHANGE_IND:
440 case MSG_CMD_PLG_THREAD_CHANGE_IND:
441 case MSG_CMD_PLG_INCOMING_MSG_IND:
442 case MSG_CMD_PLG_INCOMING_MMS_CONF:
443 case MSG_CMD_PLG_INCOMING_SYNCML_IND:
444 case MSG_CMD_PLG_INCOMING_LBS_IND:
445 case MSG_CMD_PLG_INIT_SIM_BY_SAT:
446 case MSG_CMD_PLG_INCOMING_PUSH_IND:
447 case MSG_CMD_PLG_INCOMING_CB_IND:
448 pCmdDup = (MSG_CMD_S*)calloc(1, len); /* pCmdDup should be freed afterward */
449 if (pCmdDup != NULL) {
450 memcpy(pCmdDup, pCmd, len);
451 memcpy(pCmdDup->cmdCookie, &fd, sizeof(int)); /* Now, cmdCookie keeps fd for return */
453 mxQ.lock(); /* aquire lock before adding cmd */
454 eventQueue.push_back(pCmdDup);
455 cv.signal(); /* wake up worker */
459 case MSG_CMD_CHECK_PERMISSION:
460 MSG_DEBUG("Client has privilege. Allowed.");
461 MsgMakeErrorEvent(pCmd->cmdType, MSG_SUCCESS, &eventSize, &pEventData);
462 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
463 servSock.write(fd, pEventData, eventSize);
466 pfHandler = handlerMap[pCmd->cmdType];
468 MSG_FATAL("No handler for %d", pCmd->cmdType);
469 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_INVALID_PARAMETER, &eventSize, &pEventData);
471 /* run handler function */
472 memcpy (pCmd->cmdCookie, &fd, sizeof(int)); /* Now, cmdCookie keeps fd for return */
473 eventSize = pfHandler(pCmd, &pEventData);
475 if (eventSize == 0 || pEventData == NULL) {
476 MSG_FATAL("event size[%d] = 0 or event data = NULL", eventSize);
477 MsgMakeErrorEvent(pCmd->cmdType, MSG_ERR_INVALID_PARAMETER, &eventSize, &pEventData);
481 MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
482 servSock.write(fd, pEventData, eventSize);
490 /* terminating the socket connection between ipc server and ipc client */
491 void MsgTransactionManager::cleanup(int fd)
495 MsgMutexLocker lock(mx);
499 MSG_DEBUG("fd %d disonnected", fd);
501 /* remove sent msg info for fd */
502 sentmsg_map::iterator sentmsg_it = sentMsgMap.begin();
504 for (; sentmsg_it != sentMsgMap.end(); sentmsg_it++) {
505 if (sentmsg_it->second.listenerFd == fd) {
506 sentmsg_it->second.listenerFd = 0;
507 sentmsg_it->second.handleAddr = 0;
511 /* remove sent status callback for fd */
512 statusCBFdMap.erase(fd);
514 MSG_DEBUG("After erase fd [%d], statusCBFdMap has below.", fd);
515 fd_map::iterator it = statusCBFdMap.begin();
516 for (; it != statusCBFdMap.end(); ++it)
517 MSG_DEBUG("[%d]", it->first);
519 /* remove all newMsgCBs for fd */
520 newmsg_list::iterator newmsg_it = newMsgCBList.begin();
522 while (newmsg_it != newMsgCBList.end()) {
523 if (newmsg_it->listenerFd == fd) {
524 newmsg_it = newMsgCBList.erase(newmsg_it);
530 /* remove all newMMSConfMsgCBs for fd */
531 mmsconf_list::iterator mmsconf_it = newMMSConfMsgCBList.begin();
533 while (mmsconf_it != newMMSConfMsgCBList.end()) {
534 if (mmsconf_it->listenerFd == fd) {
535 mmsconf_it = newMMSConfMsgCBList.erase(mmsconf_it);
541 /* remove all newSyncMLMsgCBs for fd */
542 syncmlmsg_list::iterator syncmlmsg_it = newSyncMLMsgCBList.begin();
544 while (syncmlmsg_it != newSyncMLMsgCBList.end()) {
545 if (syncmlmsg_it->listenerFd == fd) {
546 syncmlmsg_it = newSyncMLMsgCBList.erase(syncmlmsg_it);
552 /* remove all newLBSMsgCBs for fd */
553 lbsmsg_list::iterator lbsmsg_it = newLBSMsgCBList.begin();
555 while (lbsmsg_it != newLBSMsgCBList.end()) {
556 if (lbsmsg_it->listenerFd == fd) {
557 lbsmsg_it = newLBSMsgCBList.erase(lbsmsg_it);
563 /* remove all newPushMsgCBs for fd */
564 pushmsg_list::iterator pushmsg_it = newPushMsgCBList.begin();
566 while (pushmsg_it != newPushMsgCBList.end()) {
567 if (pushmsg_it->listenerFd == fd) {
568 pushmsg_it = newPushMsgCBList.erase(pushmsg_it);
574 /* remove all newCBMsgCBs for fd */
575 cbmsg_list::iterator cbmsg_it = newCBMsgCBList.begin();
576 /*bool bSave = false; */
578 while (cbmsg_it != newCBMsgCBList.end()) {
579 if (cbmsg_it->listenerFd == fd) {
580 cbmsg_it = newCBMsgCBList.erase(cbmsg_it);
582 /*if (cbmsg_it->bsave == true) */
588 /* remove all operationSyncMLMsgCBs for fd */
589 syncmlop_list::iterator syncmlop_it = operationSyncMLMsgCBList.begin();
591 while (syncmlop_it != operationSyncMLMsgCBList.end()) {
592 if (syncmlop_it->listenerFd == fd) {
593 syncmlop_it = operationSyncMLMsgCBList.erase(syncmlop_it);
599 /* remove storage change callback for fd */
600 storageChangeFdMap.erase(fd);
602 MSG_DEBUG("After erase fd [%d], storageChangeFdMap has below.", fd);
603 it = storageChangeFdMap.begin();
604 for (; it != storageChangeFdMap.end(); ++it)
605 MSG_DEBUG("[%d]", it->first);
607 /* remove thread change callback for fd */
608 threadChangeFdMap.erase(fd);
610 MSG_DEBUG("After erase fd [%d], threadChangeFdMap has below.", fd);
611 it = threadChangeFdMap.begin();
612 for (; it != threadChangeFdMap.end(); ++it)
613 MSG_DEBUG("[%d]", it->first);
615 /* remove report msg incoming callback for fd */
616 reportMsgCBFdMap.erase(fd);
618 MSG_DEBUG("After erase fd [%d], reportMsgCBFdMap has below.", fd);
619 it = reportMsgCBFdMap.begin();
620 for (; it != reportMsgCBFdMap.end(); ++it)
621 MSG_DEBUG("[%d]", it->first);
627 bool MsgTransactionManager::checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType)
629 bool bAllowed = true;
632 char *peer_client = NULL;
633 char *peer_user = NULL;
634 char *peer_session = NULL;
637 if (p_cynara == NULL) {
638 if (this->initCynara() == false) {
639 MSG_ERR("Cynara initialize failed. It will try again when API is called.");
645 ret = cynara_creds_socket_get_client(fd, client_method, &peer_client);
646 if (ret != CYNARA_API_SUCCESS) {
647 MSG_ERR("cynara_creds_socket_get_client() is failed [%d]", ret);
652 ret = cynara_creds_socket_get_user(fd, user_method, &peer_user);
653 if (ret != CYNARA_API_SUCCESS) {
654 MSG_ERR("cynara_creds_socket_get_user() is failed [%d]", ret);
659 ret = cynara_creds_socket_get_pid(fd, &peer_pid);
660 if (ret != CYNARA_API_SUCCESS) {
661 MSG_ERR("cynara_creds_socket_get_pid() is failed [%d]", ret);
666 peer_session = cynara_session_from_pid(peer_pid);
667 if (peer_session == NULL) {
668 MSG_ERR("cynara_session_from_pid() is failed");
674 case MSG_CMD_GET_MSG:
675 case MSG_CMD_COUNT_MSG:
676 case MSG_CMD_COUNT_BY_MSGTYPE:
677 case MSG_CMD_REG_INCOMING_MSG_CB:
678 case MSG_CMD_REG_INCOMING_CB_MSG_CB:
679 case MSG_CMD_REG_INCOMING_PUSH_MSG_CB:
680 case MSG_CMD_REG_SENT_STATUS_CB:
681 case MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB:
682 case MSG_CMD_REG_INCOMING_SYNCML_MSG_CB:
683 case MSG_CMD_REG_INCOMING_LBS_MSG_CB:
684 case MSG_CMD_REG_SYNCML_MSG_OPERATION_CB:
685 case MSG_CMD_REG_REPORT_MSG_INCOMING_CB:
686 case MSG_CMD_GET_CONTACT_COUNT:
687 case MSG_CMD_GET_FOLDERLIST:
688 case MSG_CMD_GET_QUICKPANEL_DATA:
689 case MSG_CMD_GET_MEMSIZE:
690 case MSG_CMD_BACKUP_MESSAGE:
691 case MSG_CMD_REG_STORAGE_CHANGE_CB:
692 case MSG_CMD_REG_THREAD_CHANGE_CB:
693 case MSG_CMD_GET_REPORT_STATUS:
694 case MSG_CMD_GET_THREAD_ID_BY_ADDRESS:
695 case MSG_CMD_GET_THREAD_INFO:
696 case MSG_CMD_SYNCML_OPERATION:
697 case MSG_CMD_GET_FILTERLIST:
698 case MSG_CMD_GET_FILTER_OPERATION:
699 case MSG_CMD_GET_SMSC_OPT:
700 case MSG_CMD_GET_CB_OPT:
701 case MSG_CMD_GET_SMS_SEND_OPT:
702 case MSG_CMD_GET_MMS_SEND_OPT:
703 case MSG_CMD_GET_MMS_RECV_OPT:
704 case MSG_CMD_GET_PUSH_MSG_OPT:
705 case MSG_CMD_GET_VOICE_MSG_OPT:
706 case MSG_CMD_GET_GENERAL_MSG_OPT:
707 case MSG_CMD_GET_MSG_SIZE_OPT:
708 ret = cynara_check(p_cynara, peer_client, peer_session, peer_user,
709 "http://tizen.org/privilege/message.read");
710 if (ret != CYNARA_API_ACCESS_ALLOWED) {
711 MSG_INFO("privilege [read] not allowd : [%d]", ret);
715 case MSG_CMD_SUBMIT_REQ:
716 case MSG_CMD_SET_CB_OPT:
717 case MSG_CMD_ADD_PUSH_EVENT:
718 case MSG_CMD_DELETE_PUSH_EVENT:
719 case MSG_CMD_UPDATE_PUSH_EVENT:
720 case MSG_CMD_ADD_MSG:
721 case MSG_CMD_ADD_SYNCML_MSG:
722 case MSG_CMD_UPDATE_MSG:
723 case MSG_CMD_UPDATE_READ:
724 case MSG_CMD_UPDATE_PROTECTED:
725 case MSG_CMD_DELETE_MSG:
726 case MSG_CMD_DELALL_MSGINFOLDER:
727 case MSG_CMD_MOVE_MSGTOFOLDER:
728 case MSG_CMD_MOVE_MSGTOSTORAGE:
729 case MSG_CMD_DELETE_THREADMESSAGELIST:
730 case MSG_CMD_ADD_FOLDER:
731 case MSG_CMD_UPDATE_FOLDER:
732 case MSG_CMD_DELETE_FOLDER:
733 case MSG_CMD_RESET_DB:
734 case MSG_CMD_RESTORE_MESSAGE:
735 case MSG_CMD_DELETE_MESSAGE_BY_LIST:
736 case MSG_CMD_UPDATE_THREAD_READ:
737 case MSG_CMD_ADD_FILTER:
738 case MSG_CMD_UPDATE_FILTER:
739 case MSG_CMD_DELETE_FILTER:
740 case MSG_CMD_SET_FILTER_OPERATION:
741 case MSG_CMD_SET_FILTER_ACTIVATION:
742 case MSG_CMD_SET_SMSC_OPT:
743 case MSG_CMD_SET_SMS_SEND_OPT:
744 case MSG_CMD_SET_MMS_SEND_OPT:
745 case MSG_CMD_SET_MMS_RECV_OPT:
746 case MSG_CMD_SET_PUSH_MSG_OPT:
747 case MSG_CMD_SET_VOICE_MSG_OPT:
748 case MSG_CMD_SET_GENERAL_MSG_OPT:
749 case MSG_CMD_SET_MSG_SIZE_OPT:
750 ret = cynara_check(p_cynara, peer_client, peer_session, peer_user,
751 "http://tizen.org/privilege/message.write");
752 if (ret != CYNARA_API_ACCESS_ALLOWED) {
753 MSG_INFO("privilege [write] not allowd : [%d]", ret);
757 case MSG_CMD_CHECK_PERMISSION:
758 ret = cynara_check(p_cynara, peer_client, peer_session, peer_user,
759 "http://tizen.org/privilege/message.read");
760 if (ret != CYNARA_API_ACCESS_ALLOWED) {
761 ret = cynara_check(p_cynara, peer_client, peer_session, peer_user,
762 "http://tizen.org/privilege/message.write");
763 if (ret != CYNARA_API_ACCESS_ALLOWED) {
764 MSG_INFO("privilege [write] not allowd : [%d]", ret);
774 MSG_FREE(peer_client);
776 MSG_FREE(peer_session);
782 void MsgTransactionManager::setSentStatusCB(int listenerFd)
785 THROW(MsgException::INVALID_PARAM, "InParam Error: listenerFd %d", listenerFd);
787 statusCBFdMap[listenerFd] = true;
791 void MsgTransactionManager::setIncomingMsgCB(MSG_CMD_REG_INCOMING_MSG_CB_S *pCbInfo)
794 MSG_FATAL("cbinfo NULL");
798 MsgMutexLocker lock(mx);
800 newmsg_list::iterator it = newMsgCBList.begin();
802 for (; it != newMsgCBList.end(); it++) {
803 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && (it->port == pCbInfo->port)) {
804 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d, port %d", it->listenerFd, it->msgType, it->port);
809 newMsgCBList.push_back(*pCbInfo);
813 void MsgTransactionManager::setMMSConfMsgCB(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCbInfo)
816 MSG_FATAL("cbinfo NULL");
820 MsgMutexLocker lock(mx);
822 mmsconf_list::iterator it = newMMSConfMsgCBList.begin();
824 for (; it != newMMSConfMsgCBList.end(); it++) {
825 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && (!strncmp(it->appId, pCbInfo->appId, MAX_MMS_JAVA_APPID_LEN))) {
826 MSG_DEBUG("Duplicated MMSConfMessageCB info fd:%d, mType:%d, appId:%s", it->listenerFd, it->msgType, it->appId);
831 newMMSConfMsgCBList.push_back(*pCbInfo);
835 void MsgTransactionManager::setPushMsgCB(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCbInfo)
838 MSG_FATAL("cbinfo NULL");
842 MsgMutexLocker lock(mx);
844 pushmsg_list::iterator it = newPushMsgCBList.begin();
846 for (; it != newPushMsgCBList.end(); it++) {
847 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && !strncmp(it->appId, pCbInfo->appId, MAX_WAPPUSH_ID_LEN)) {
848 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
853 newPushMsgCBList.push_back(*pCbInfo);
856 void MsgTransactionManager::setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo)
860 MSG_FATAL("cbinfo NULL");
864 MsgMutexLocker lock(mx);
866 cbmsg_list::iterator it = newCBMsgCBList.begin();
868 for (; it != newCBMsgCBList.end(); it++) {
869 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType)) {
870 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
874 MSG_DEBUG("bSave : [%d]", pCbInfo->bsave);
877 if(MsgSettingSetBool(CB_SAVE, pCbInfo->bsave) != MSG_SUCCESS)
878 MSG_DEBUG("MsgSettingSetBool FAIL: CB_SAVE");
882 newCBMsgCBList.push_back(*pCbInfo);
888 void MsgTransactionManager::setSyncMLMsgCB(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCbInfo)
891 MSG_FATAL("cbinfo NULL");
895 MsgMutexLocker lock(mx);
897 syncmlmsg_list::iterator it = newSyncMLMsgCBList.begin();
899 for (; it != newSyncMLMsgCBList.end(); it++) {
900 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType)) {
901 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
906 newSyncMLMsgCBList.push_back(*pCbInfo);
910 void MsgTransactionManager::setLBSMsgCB(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCbInfo)
913 MSG_FATAL("cbinfo NULL");
917 MsgMutexLocker lock(mx);
919 lbsmsg_list::iterator it = newLBSMsgCBList.begin();
921 for (; it != newLBSMsgCBList.end(); it++) {
922 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType)) {
923 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
928 newLBSMsgCBList.push_back(*pCbInfo);
932 void MsgTransactionManager::setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *pTrId)
935 MSG_FATAL("trId NULL");
939 javamms_list::iterator it;
941 for (it = javaMMSList.begin(); it != javaMMSList.end(); it++) {
942 if (!strcmp(it->id, pTrId->id)) {
943 MSG_SEC_DEBUG("Duplicated javaMMS transaction Id:%s", it->id);
948 javaMMSList.push_back(*pTrId);
952 void MsgTransactionManager::setSyncMLMsgOperationCB(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCbInfo)
955 MSG_FATAL("cbinfo NULL");
959 MsgMutexLocker lock(mx);
961 syncmlop_list::iterator it = operationSyncMLMsgCBList.begin();
963 for (; it != operationSyncMLMsgCBList.end(); it++) {
964 if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType)) {
965 MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
970 operationSyncMLMsgCBList.push_back(*pCbInfo);
974 void MsgTransactionManager::setStorageChangeCB(int listenerFd)
977 THROW(MsgException::INVALID_PARAM, "InParam Error: listenerFd %d", listenerFd);
979 MsgMutexLocker lock(mx);
981 storageChangeFdMap[listenerFd] = true;
985 void MsgTransactionManager::setThreadChangeCB(int listenerFd)
988 THROW(MsgException::INVALID_PARAM, "InParam Error: listenerFd %d", listenerFd);
990 MsgMutexLocker lock(mx);
992 threadChangeFdMap[listenerFd] = true;
996 void MsgTransactionManager::setReportMsgCB(int listenerFd)
999 THROW(MsgException::INVALID_PARAM, "InParam Error: listenerFd %d", listenerFd);
1001 MsgMutexLocker lock(mx);
1003 reportMsgCBFdMap[listenerFd] = true;
1007 javamms_list& MsgTransactionManager::getJavaMMSList()
1013 void MsgTransactionManager::broadcastIncomingMsgCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo)
1017 if ((msgInfo->msgPort.valid == true) && (msgInfo->msgPort.dstPort == MSG_LBS_PORT)) {
1018 MSG_DEBUG("Message for LBS.");
1020 if (msgInfo->bTextSms == false) {
1021 MSG_DEBUG("msgInfo->bTextSms == false");
1025 char* pFileData = NULL;
1026 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
1028 if (MsgOpenAndReadFile(msgInfo->msgData, &pFileData, &fileSize) == true)
1029 MsgLbsSms(pFileData, fileSize);
1031 MSG_DEBUG("MsgOpenAndReadFile failed.");
1033 MsgLbsSms(msgInfo->msgText, (int)msgInfo->dataSize);
1038 char* pEventData = NULL;
1039 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1041 char* encodedData = NULL;
1042 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1043 int dataSize = MsgEncodeMsgInfo(msgInfo, &encodedData);
1045 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)(&pEventData));
1047 MSG_DEBUG("valid %d dstport %d", msgInfo->msgPort.valid, msgInfo->msgPort.dstPort);
1049 MsgMutexLocker lock(mx);
1051 newmsg_list::iterator it = newMsgCBList.begin();
1053 for (; it != newMsgCBList.end(); it++) {
1054 MSG_DEBUG("fd %d dstport %d", it->listenerFd, it->port);
1056 if ((msgInfo->msgPort.valid == false) && (it->port == 0)) {
1057 MSG_DEBUG("Send incoming normal msg to listener %d", it->listenerFd);
1058 write(it->listenerFd, pEventData, eventSize);
1059 } else if ((msgInfo->msgPort.valid == true) && (it->port == msgInfo->msgPort.dstPort)) {
1060 MSG_DEBUG("Send incoming port msg to listener %d", it->listenerFd);
1061 write(it->listenerFd, pEventData, eventSize);
1069 void MsgTransactionManager::broadcastMMSConfCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo, const MMS_RECV_DATA_S *mmsRecvData)
1073 char* pEventData = NULL;
1074 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1076 char* encodedData = NULL;
1077 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1078 int dataSize = MsgEncodeMsgInfo(msgInfo, &encodedData);
1080 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)(&pEventData));
1082 MsgMutexLocker lock(mx);
1084 mmsconf_list::iterator it = newMMSConfMsgCBList.begin();
1086 for (; it != newMMSConfMsgCBList.end(); it++) {
1087 MSG_DEBUG("fd:%d appId:%s", it->listenerFd, it->appId);
1089 if (mmsRecvData->msgAppId.valid == true) {
1090 if (!strcmp(it->appId, mmsRecvData->msgAppId.appId)) {
1091 MSG_DEBUG("Send incoming java msg to listener %d", it->listenerFd);
1092 write(it->listenerFd, pEventData, eventSize);
1095 if (strlen(it->appId) <= 0) {
1096 MSG_DEBUG("Send incoming normal msg to listener %d", it->listenerFd);
1097 write(it->listenerFd, pEventData, eventSize);
1106 void MsgTransactionManager::broadcastPushMsgCB(const msg_error_t err, const MSG_PUSH_MESSAGE_DATA_S *pushData)
1110 char* pEventData = NULL;
1111 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1113 int eventSize = MsgMakeEvent(pushData, sizeof(MSG_PUSH_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, err, (void**)(&pEventData));
1115 MsgMutexLocker lock(mx);
1117 pushmsg_list::iterator it = newPushMsgCBList.begin();
1119 for (; it != newPushMsgCBList.end(); it++) {
1120 MSG_DEBUG("registered_appid : %s, incoming_appid: %s", it->appId, pushData->pushAppId);
1121 if (!strcmp(it->appId, pushData->pushAppId)) {
1122 MSG_DEBUG("Send incoming Push information to listener %d", it->listenerFd);
1123 write(it->listenerFd, pEventData, eventSize);
1130 void MsgTransactionManager::broadcastCBMsgCB(const msg_error_t err, const MSG_CB_MSG_S *cbMsg, msg_message_id_t cbMsgId)
1134 char* pEventData = NULL;
1135 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1137 int eventSize = MsgMakeEvent(cbMsg, sizeof(MSG_CB_MSG_S), MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)(&pEventData));
1139 MsgMutexLocker lock(mx);
1141 cbmsg_list::iterator it = newCBMsgCBList.begin();
1143 for (; it != newCBMsgCBList.end(); it++) {
1144 MSG_DEBUG("Send incoming CB information to listener %d", it->listenerFd);
1145 write(it->listenerFd, pEventData, eventSize);
1148 /* Send system event */
1150 b = bundle_create();
1152 bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_CB);
1153 char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
1154 snprintf(msgId, sizeof(msgId), "%u", cbMsgId);
1155 bundle_add_str(b, EVT_KEY_MSG_ID, msgId);
1156 eventsystem_send_system_event(SYS_EVENT_INCOMMING_MSG, b);
1163 void MsgTransactionManager::broadcastSyncMLMsgCB(const msg_error_t err, const MSG_SYNCML_MESSAGE_DATA_S *syncMLData)
1167 char* pEventData = NULL;
1168 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1170 int eventSize = MsgMakeEvent(syncMLData, sizeof(MSG_SYNCML_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, err, (void**)(&pEventData));
1172 MsgMutexLocker lock(mx);
1174 syncmlmsg_list::iterator it = newSyncMLMsgCBList.begin();
1176 for (; it != newSyncMLMsgCBList.end(); it++) {
1177 MSG_DEBUG("Send incoming SyncML information to listener %d", it->listenerFd);
1178 write(it->listenerFd, pEventData, eventSize);
1185 void MsgTransactionManager::broadcastLBSMsgCB(const msg_error_t err, const MSG_LBS_MESSAGE_DATA_S *lbsData)
1190 char* pEventData = NULL;
1191 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1193 int eventSize = MsgMakeEvent(lbsData, sizeof(MSG_LBS_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, err, (void**)(&pEventData));
1195 MsgMutexLocker lock(mx);
1197 lbsmsg_list::iterator it = newLBSMsgCBList.begin();
1199 for (; it != newLBSMsgCBList.end(); it++) {
1200 MSG_DEBUG("Send incoming LBS msg to listener %d", it->listenerFd);
1201 write(it->listenerFd, pEventData, eventSize);
1204 MsgLbsWapPush(lbsData->pushHeader, lbsData->pushBody, lbsData->pushBodyLen);
1210 void MsgTransactionManager::broadcastSyncMLMsgOperationCB(const msg_error_t err, const int msgId, const int extId)
1214 char* pEventData = NULL;
1215 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1217 char* encodedData = NULL;
1218 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1220 /* Encoding Storage Change Data */
1221 int dataSize = MsgEncodeSyncMLOperationData(msgId, extId, &encodedData);
1223 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_SYNCML_OPERATION, err, (void**)(&pEventData));
1225 MsgMutexLocker lock(mx);
1227 syncmlop_list::iterator it = operationSyncMLMsgCBList.begin();
1229 for( ; it != operationSyncMLMsgCBList.end() ; it++ ) {
1230 MSG_DEBUG("Send SyncML operation to listener %d", it->listenerFd);
1231 write(it->listenerFd, pEventData, eventSize);
1238 bool compare_func(msg_thread_id_t const &a, msg_thread_id_t const &b)
1247 void MsgTransactionManager::broadcastStorageChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList)
1251 if(pMsgIdList == NULL) {
1252 MSG_DEBUG("pMsgIdList is NULL.");
1256 MSG_DEBUG("storageChangeType [%d]", storageChangeType);
1260 char* pEventData = NULL;
1261 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1263 char* encodedData = NULL;
1264 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1266 /* Encoding Storage Change Data */
1267 dataSize = MsgEncodeStorageChangeData(storageChangeType, pMsgIdList, &encodedData);
1269 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_STORAGE_CHANGE_IND, err, (void**)(&pEventData));
1273 fd_map::iterator it = storageChangeFdMap.begin();
1275 for (; it != storageChangeFdMap.end(); it++) {
1276 MSG_DEBUG("Send Storage Change Callback to listener %d", it->first);
1277 write(it->first, pEventData, eventSize);
1282 MsgDbHandler *dbHandle = getDbHandle();
1283 MsgSimpleQ<msg_thread_id_t> updatedConvQ;
1285 if (storageChangeType == MSG_STORAGE_CHANGE_INSERT || storageChangeType == MSG_STORAGE_CHANGE_UPDATE) {
1286 for (int i = 0; i < pMsgIdList->nCount; i++) {
1287 msg_thread_id_t conv_id = MsgGetThreadId(dbHandle, pMsgIdList->msgIdList[i]);
1288 bool found = (std::find(cur_conv_list.begin(), cur_conv_list.end(), conv_id) != cur_conv_list.end());
1290 if (found == false) {
1291 cur_conv_list.push_back(conv_id);
1292 updatedConvQ.push_back(conv_id);
1293 broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, conv_id);
1295 if (updatedConvQ.checkExist(conv_id, compare_func) == false) {
1296 broadcastThreadChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, conv_id);
1297 updatedConvQ.push_back(conv_id);
1303 updatedConvQ.clear();
1309 void MsgTransactionManager::broadcastThreadChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_thread_id_t threadId)
1313 MSG_DEBUG("storageChangeType [%d], threadId [%d]", storageChangeType, threadId);
1318 if (storageChangeType == MSG_STORAGE_CHANGE_DELETE)
1319 cur_conv_list.remove(threadId);
1323 char* pEventData = NULL;
1324 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1326 char* encodedData = NULL;
1327 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1329 /* Encoding Thread Change Data */
1330 dataSize = MsgEncodeThreadChangeData(storageChangeType, threadId, &encodedData);
1332 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_THREAD_CHANGE_IND, err, (void**)(&pEventData));
1334 MsgMutexLocker lock(mx);
1336 fd_map::iterator it = threadChangeFdMap.begin();
1338 for (; it != threadChangeFdMap.end(); it++) {
1339 MSG_DEBUG("Send Thread Change Callback to listener %d", it->first);
1340 write(it->first, pEventData, eventSize);
1347 void MsgTransactionManager::broadcastReportMsgCB(const msg_error_t err, const msg_report_type_t reportMsgType, const MSG_MESSAGE_INFO_S *pMsgInfo)
1351 if(pMsgInfo == NULL) {
1352 MSG_DEBUG("pMsgInfo is NULL.");
1356 MSG_DEBUG("reportMsgType [%d]", reportMsgType);
1360 char* pEventData = NULL;
1361 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1363 char* encodedData = NULL;
1364 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1366 /* Encoding Storage Change Data */
1367 dataSize = MsgEncodeReportMsgData(reportMsgType, pMsgInfo, &encodedData);
1369 int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND, err, (void**)(&pEventData));
1371 MsgMutexLocker lock(mx);
1373 fd_map::iterator it = reportMsgCBFdMap.begin();
1375 for (; it != reportMsgCBFdMap.end(); it++) {
1376 MSG_DEBUG("Send Report Message Incoming Callback to listener %d", it->first);
1377 write(it->first, pEventData, eventSize);
1384 bool MsgTransactionManager::initCynara()
1389 cynara_configuration *p_conf = NULL;
1390 size_t cache_size = 100;
1392 ret = cynara_configuration_create(&p_conf);
1393 if (ret != CYNARA_API_SUCCESS) {
1394 MSG_ERR("cynara_configuration_create() is failed [%d]", ret);
1399 ret = cynara_configuration_set_cache_size(p_conf, cache_size);
1400 if (ret != CYNARA_API_SUCCESS) {
1401 MSG_ERR("cynara_configuration_set_cache_size() is failed [%d]", ret);
1406 ret = cynara_initialize(&p_cynara, p_conf);
1407 if (ret == CYNARA_API_SUCCESS) {
1408 MSG_INFO("cynara_initialize() is successful");
1410 MSG_INFO("cynara_initialize() is failed [%d]", ret);
1415 ret = cynara_creds_get_default_client_method(&client_method);
1416 if (ret != CYNARA_API_SUCCESS) {
1417 MSG_ERR("cynara_creds_get_default_client_method() is failed [%d]", ret);
1422 ret = cynara_creds_get_default_user_method(&user_method);
1423 if (ret != CYNARA_API_SUCCESS) {
1424 MSG_ERR("cynara_creds_get_default_user_method() is failed [%d]", ret);
1431 cynara_configuration_destroy(p_conf);
1438 void MsgTransactionManager::finishCynara()
1442 ret = cynara_finish(p_cynara);
1444 if (ret == CYNARA_API_SUCCESS) {
1445 MSG_INFO("cynara_finish() is successful");
1447 MSG_INFO("cynara_finish() is failed [%d]", ret);