2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
22 #include "MsgUtilFunction.h"
23 #include "MsgUtilFile.h"
24 #include "MsgProxyListener.h"
25 #include "MsgGconfWrapper.h"
27 void MsgServerRestartCb(keynode_t *key, void* data)
30 MSG_DEBUG("Message Service Running State Changed");
31 /* server is currently booting and service is not available until the end of booting */
32 if (MsgSettingGetBool(VCONFKEY_MSG_SERVER_READY, &bReady) != MSG_SUCCESS)
33 MSG_INFO("MsgSettingGetBool() is failed");
35 MSG_INFO("Message Service Running State Changed bReady:(%d)", bReady);
37 /* bReady false indicates that server has restarted. Hence the proxylistener needs to be reset */
38 if (bReady == false) {
39 MSG_DEBUG("Message Service Is Restarted");
40 MsgProxyListener::instance()->resetProxyListener();
42 MSG_DEBUG("Message Service Is ready again. Refreshing ProxyListener");
43 MsgProxyListener::instance()->refreshProxyListener();
47 gboolean readSocket(GIOChannel *source, GIOCondition condition, gpointer data)
51 if ((G_IO_ERR & condition) || (G_IO_HUP & condition) || (G_IO_NVAL & condition)) {
52 MSG_DEBUG("IO condition Error!!! [%d]", condition);
54 MsgProxyListener::instance()->stop();
58 if (G_IO_ERR & condition) {
59 MSG_ERR("IO Error!!! [%d]", condition);
60 MsgProxyListener::instance()->clearProxyCBLists();
61 MsgProxyListener::instance()->clearOpenHandleSet();
65 if (G_IO_HUP & condition) {
66 MSG_ERR("socket fd Error!!! [%d]", condition);
67 MsgProxyListener::instance()->resetProxyListener();
71 if (G_IO_NVAL & condition) {
72 MSG_ERR("Invaild socket Error!!! [%d]", condition);
73 MsgProxyListener::instance()->clearProxyCBLists();
74 MsgProxyListener::instance()->clearOpenHandleSet();
79 unique_ptr<char*, void(*)(char**)> eventBuf(&buf, unique_ptr_deleter);
82 int n = MsgProxyListener::instance()->readFromSocket(&buf, &len);
85 MSG_DEBUG(">>Receiving %d bytes", n);
86 MsgProxyListener::instance()->handleEvent((MSG_EVENT_S*)buf);
88 MSG_WARN("Server closed connection");
90 } else /* dataSize < 0 */ {
91 MSG_DEBUG("Data is not for Listener");
100 /*==================================================================================================
101 IMPLEMENTATION OF MsgListenerThread - Member Functions
102 ==================================================================================================*/
103 MsgProxyListener* MsgProxyListener::pInstance = NULL;
106 MsgProxyListener::MsgProxyListener() : running(0)
109 clearOpenHandleSet();
111 msg_error_t err = MSG_SUCCESS;
112 err = MsgSettingRegVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
113 if (err != MSG_SUCCESS) {
114 if (err == MSG_ERR_PERMISSION_DENIED) {
115 THROW(MsgException::SECURITY_ERROR, "It must have privilege to access vconf key");
117 THROW(MsgException::SERVER_READY_ERROR, "vconf register fail");
126 MsgProxyListener::~MsgProxyListener()
129 clearOpenHandleSet();
131 msg_error_t err = MSG_SUCCESS;
132 err = MsgSettingRemoveVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
133 if (err != MSG_SUCCESS) {
134 if (err == MSG_ERR_PERMISSION_DENIED) {
135 MSG_DEBUG("It must have privilege to access vconf key");
137 MSG_DEBUG("vconf register fail");
143 MsgProxyListener* MsgProxyListener::instance()
146 MutexLocker lock(mm);
149 pInstance = new MsgProxyListener();
156 void MsgProxyListener::start(MsgHandle* pMsgHandle)
158 MutexLocker lock(mx);
160 this->insertOpenHandleSet(pMsgHandle);
163 cliSock.connect(MSG_SOCKET_PATH);
164 /* wake up the waiting thread */
167 int fd = cliSock.fd();
169 MSG_DEBUG("Socket Fd : %d", fd);
171 /* initializes ref_count = 1 */
172 channel = g_io_channel_unix_new(fd);
174 /* increments ref_count = 2 */
175 eventSourceId = g_io_add_watch(channel, (GIOCondition)(G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), &readSocket, NULL);
177 MSG_DEBUG("Call g_io_add_watch() : %d", eventSourceId);
181 MSG_DEBUG("add Listener and [%d] are running.", running);
185 void MsgProxyListener::stop()
189 MutexLocker lock(mx);
193 MSG_DEBUG("There are still running Listener. [%d] left.", running);
194 } else if (running == 1) {
196 g_io_channel_unref(channel);
200 if (eventSourceId > 0) {
201 g_source_remove(eventSourceId);
208 MSG_DEBUG("client Listener is terminated.");
215 bool MsgProxyListener::regSentStatusEventCB(MsgHandle* pMsgHandle, int fd, msg_sent_status_cb pfSentStatus, void *pUserParam)
217 MutexLocker lock(mx);
219 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
221 for (; it != sentStatusCBList.end(); it++) {
222 if (it->hAddr == pMsgHandle && it->pfSentStatusCB == pfSentStatus) {
224 MSG_DEBUG("msg_sent_status_cb() callback : [%p] is already registered!!!", pfSentStatus);
227 MSG_DEBUG("callback is registered by restarting server");
234 MSG_SENT_STATUS_CB_ITEM_S sentStatusCB = {pMsgHandle, fd, pfSentStatus, pUserParam};
236 sentStatusCBList.push_back(sentStatusCB);
242 bool MsgProxyListener::regMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_sms_incoming_cb pfNewMessage, int port, void *pUserParam)
244 MutexLocker lock(mx);
246 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it = newMessageCBList.begin();
248 for (; it != newMessageCBList.end(); it++) {
249 if (it->hAddr == pMsgHandle && it->port == port && it->pfIncomingCB == pfNewMessage) {
251 MSG_DEBUG("msg_sms_incoming_cb() callback : Port Number [%d] is already registered!!!", port);
254 MSG_DEBUG("callback is registered by restarting server");
261 MSG_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewMessage, port, pUserParam};
263 newMessageCBList.push_back(incomingCB);
269 bool MsgProxyListener::regMMSConfMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_mms_conf_msg_incoming_cb pfNewMMSConfMessage, const char *pAppId, void *pUserParam)
271 MutexLocker lock(mx);
273 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it = newMMSConfMessageCBList.begin();
275 for (; it != newMMSConfMessageCBList.end(); it++) {
276 if (it->hAddr == pMsgHandle && it->pfMMSConfIncomingCB == pfNewMMSConfMessage) {
278 if (pAppId == NULL) {
279 MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback is already registered!!!");
281 } else if (!strncmp(it->appId, pAppId, MAX_MMS_JAVA_APPID_LEN)) {
282 MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
286 MSG_DEBUG("callback is registered by restarting server");
293 MSG_MMS_CONF_INCOMING_CB_ITEM_S incomingConfCB = {pMsgHandle, fd, pfNewMMSConfMessage, {0}, pUserParam};
296 strncpy(incomingConfCB.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
298 newMMSConfMessageCBList.push_back(incomingConfCB);
304 bool MsgProxyListener::regPushMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_push_msg_incoming_cb pfNewPushMessage, const char *pAppId, void *pUserParam)
306 MutexLocker lock(mx);
308 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it = newPushMessageCBList.begin();
310 for (; it != newPushMessageCBList.end(); it++) {
311 if (it->hAddr == pMsgHandle && it->pfPushIncomingCB == pfNewPushMessage) {
313 if (pAppId == NULL) {
314 MSG_DEBUG("msg_push_msg_incoming_cb() callback is already registered!!!");
316 } else if (!strncmp(it->appId, pAppId, MAX_WAPPUSH_ID_LEN)) {
317 MSG_DEBUG("msg_push_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
321 MSG_DEBUG("callback is registered by restarting server");
328 MSG_PUSH_INCOMING_CB_ITEM_S incomingPushCB = {pMsgHandle, fd, pfNewPushMessage, {0}, pUserParam};
331 strncpy(incomingPushCB.appId, pAppId, MAX_WAPPUSH_ID_LEN);
333 newPushMessageCBList.push_back(incomingPushCB);
339 bool MsgProxyListener::regCBMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_cb_incoming_cb pfNewCBMessage, bool bSave, void *pUserParam)
341 MutexLocker lock(mx);
343 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it = newCBMessageCBList.begin();
345 for (; it != newCBMessageCBList.end(); it++) {
346 if (it->hAddr == pMsgHandle && it->pfCBIncomingCB == pfNewCBMessage) {
348 MSG_DEBUG("msg_CB_incoming_cb() callback : [%p] is already registered!!!", pfNewCBMessage);
350 it->userParam = pUserParam;
353 MSG_DEBUG("callback is registered by restarting server");
360 MSG_CB_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewCBMessage, bSave, pUserParam};
362 newCBMessageCBList.push_back(incomingCB);
368 bool MsgProxyListener::regReportMsgIncomingCB(MsgHandle* pMsgHandle, int fd, msg_report_msg_incoming_cb pfReportMessage, void *pUserParam)
370 MutexLocker lock(mx);
372 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it = reportMessageCBList.begin();
374 for (; it != reportMessageCBList.end(); it++) {
375 if (it->hAddr == pMsgHandle && it->pfReportMsgIncomingCB == pfReportMessage) {
377 MSG_DEBUG("msg_report_msg_incoming_cb() callback : [%p] is already registered!!!", pfReportMessage);
378 it->userParam = pUserParam;
381 MSG_DEBUG("callback is registered by restarting server");
388 MSG_REPORT_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfReportMessage, pUserParam};
390 reportMessageCBList.push_back(incomingCB);
396 bool MsgProxyListener::regSyncMLMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_incoming_cb pfNewSyncMLMessage, void *pUserParam)
398 MutexLocker lock(mx);
400 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it = newSyncMLMessageCBList.begin();
402 for (; it != newSyncMLMessageCBList.end(); it++) {
403 if (it->hAddr == pMsgHandle && it->pfSyncMLIncomingCB == pfNewSyncMLMessage) {
405 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewSyncMLMessage);
408 MSG_DEBUG("callback is registered by restarting server");
415 MSG_SYNCML_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewSyncMLMessage, pUserParam};
417 newSyncMLMessageCBList.push_back(incomingCB);
423 bool MsgProxyListener::regLBSMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_lbs_msg_incoming_cb pfNewLBSMsgIncoming, void *pUserParam)
425 MutexLocker lock(mx);
427 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it = newLBSMessageCBList.begin();
429 for (; it != newLBSMessageCBList.end(); it++) {
430 if (it->hAddr == pMsgHandle && it->pfLBSMsgIncoming == pfNewLBSMsgIncoming) {
432 MSG_DEBUG("msg_lbs_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewLBSMsgIncoming);
435 MSG_DEBUG("callback is registered by restarting server");
442 MSG_LBS_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewLBSMsgIncoming, pUserParam};
444 newLBSMessageCBList.push_back(incomingCB);
450 bool MsgProxyListener::regSyncMLMessageOperationEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_operation_cb pfSyncMLMessageOperation, void *pUserParam)
452 MutexLocker lock(mx);
454 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it = operationSyncMLMessageCBList.begin();
456 for (; it != operationSyncMLMessageCBList.end(); it++) {
457 if (it->hAddr == pMsgHandle && it->pfSyncMLOperationCB == pfSyncMLMessageOperation) {
459 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfSyncMLMessageOperation);
462 MSG_DEBUG("callback is registered by restarting server");
469 MSG_SYNCML_OPERATION_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfSyncMLMessageOperation, pUserParam};
471 operationSyncMLMessageCBList.push_back(incomingCB);
477 bool MsgProxyListener::regStorageChangeEventCB(MsgHandle* pMsgHandle, int fd, msg_storage_change_cb pfStorageChangeOperation, void *pUserParam)
479 MutexLocker lock(mx);
481 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it = storageChangeCBList.begin();
483 for (; it != storageChangeCBList.end(); it++) {
484 if (it->hAddr == pMsgHandle && it->pfStorageChangeCB == pfStorageChangeOperation) {
486 MSG_DEBUG("msg_storage_change_cb() callback : [%p] is already registered!!!", pfStorageChangeOperation);
489 MSG_DEBUG("callback is registered by restarting server");
496 MSG_STORAGE_CHANGE_CB_ITEM_S changeCB = {pMsgHandle, fd, pfStorageChangeOperation, pUserParam};
498 storageChangeCBList.push_back(changeCB);
504 void MsgProxyListener::clearListOfClosedHandle(MsgHandle* pMsgHandle)
508 MutexLocker lock(mx);
510 /* sent status CB list */
511 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
513 for (; it != sentStatusCBList.end(); ) {
514 if (it->hAddr == pMsgHandle) {
515 sentStatusCBList.erase(it++);
522 /* new message CB list */
523 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it2 = newMessageCBList.begin();
525 for (; it2 != newMessageCBList.end(); ) {
526 if (it2->hAddr == pMsgHandle) {
527 newMessageCBList.erase(it2++);
534 /* MMS conf Message CB list */
535 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it3 = newMMSConfMessageCBList.begin();
537 for (; it3 != newMMSConfMessageCBList.end(); ) {
538 if (it3->hAddr == pMsgHandle) {
539 newMMSConfMessageCBList.erase(it3++);
546 /* SyncML Message CB list */
547 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it4 = newSyncMLMessageCBList.begin();
549 for (; it4 != newSyncMLMessageCBList.end(); ) {
550 if (it4->hAddr == pMsgHandle) {
551 newSyncMLMessageCBList.erase(it4++);
558 /* LBS Message CB list */
559 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it5 = newLBSMessageCBList.begin();
561 for (; it5 != newLBSMessageCBList.end(); ) {
562 if (it5->hAddr == pMsgHandle) {
563 newLBSMessageCBList.erase(it5++);
570 /* Push Message CB list */
571 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it6 = newPushMessageCBList.begin();
573 for (; it6 != newPushMessageCBList.end(); ) {
574 if (it6->hAddr == pMsgHandle) {
575 newPushMessageCBList.erase(it6++);
582 /* CB Message CB list */
583 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it7 = newCBMessageCBList.begin();
585 for (; it7 != newCBMessageCBList.end(); ) {
586 if (it7->hAddr == pMsgHandle) {
587 newCBMessageCBList.erase(it7++);
594 /* Storage change Message CB list */
595 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it8 = storageChangeCBList.begin();
597 for (; it8 != storageChangeCBList.end(); ) {
598 if (it8->hAddr == pMsgHandle) {
599 storageChangeCBList.erase(it8++);
607 /* Report message incoming CB list */
608 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it9 = reportMessageCBList.begin();
609 for (; it9 != reportMessageCBList.end(); ) {
610 if (it9->hAddr == pMsgHandle) {
611 reportMessageCBList.erase(it9++);
619 /* SyncML Message Operation CB list */
620 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it10 = operationSyncMLMessageCBList.begin();
621 for (; it10 != operationSyncMLMessageCBList.end(); ) {
622 if (it10->hAddr == pMsgHandle) {
623 operationSyncMLMessageCBList.erase(it10++);
630 /* Open Handle Set */
631 openHandleSet.erase(pMsgHandle);
637 void MsgProxyListener::refreshListOfOpenedHandle(MsgHandle* pMsgHandle)
641 MutexLocker lock(mx);
643 /* sent status CB list */
644 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
645 for (; it != sentStatusCBList.end(); ++it) {
646 if (it->hAddr == pMsgHandle) {
647 it->fd = CUSTOM_SOCKET_ERROR;
649 pMsgHandle->regSentStatusCallback(it->pfSentStatusCB, it->userParam);
650 } catch (MsgException& e) {
651 MSG_FATAL("%s", e.what());
656 /* new message CB list */
657 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it2 = newMessageCBList.begin();
658 for (; it2 != newMessageCBList.end(); ++it2) {
659 if (it2->hAddr == pMsgHandle) {
660 it2->fd = CUSTOM_SOCKET_ERROR;
662 pMsgHandle->regSmsMessageCallback(it2->pfIncomingCB, it2->port, it2->userParam);
663 } catch (MsgException& e) {
664 MSG_FATAL("%s", e.what());
669 /* MMS conf Message CB list */
670 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it3 = newMMSConfMessageCBList.begin();
671 for (; it3 != newMMSConfMessageCBList.end(); ++it3) {
672 if (it3->hAddr == pMsgHandle) {
673 it3->fd = CUSTOM_SOCKET_ERROR;
675 pMsgHandle->regMmsConfMessageCallback(it3->pfMMSConfIncomingCB, it3->appId, it3->userParam);
676 } catch (MsgException& e) {
677 MSG_FATAL("%s", e.what());
682 /* SyncML Message CB list */
683 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it4 = newSyncMLMessageCBList.begin();
684 for (; it4 != newSyncMLMessageCBList.end(); ++it4) {
685 if (it4->hAddr == pMsgHandle) {
686 it4->fd = CUSTOM_SOCKET_ERROR;
688 pMsgHandle->regSyncMLMessageCallback(it4->pfSyncMLIncomingCB, it4->userParam);
689 } catch (MsgException& e) {
690 MSG_FATAL("%s", e.what());
695 /* LBS Message CB list */
696 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it5 = newLBSMessageCBList.begin();
697 for (; it5 != newLBSMessageCBList.end(); ++it5) {
698 if (it5->hAddr == pMsgHandle) {
699 it5->fd = CUSTOM_SOCKET_ERROR;
701 pMsgHandle->regLBSMessageCallback(it5->pfLBSMsgIncoming, it5->userParam);
702 } catch (MsgException& e) {
703 MSG_FATAL("%s", e.what());
708 /* Push Message CB list */
709 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it6 = newPushMessageCBList.begin();
710 for (; it6 != newPushMessageCBList.end(); ++it6) {
711 if (it6->hAddr == pMsgHandle) {
712 it6->fd = CUSTOM_SOCKET_ERROR;
714 pMsgHandle->regPushMessageCallback(it6->pfPushIncomingCB, it6->appId, it6->userParam);
715 } catch (MsgException& e) {
716 MSG_FATAL("%s", e.what());
721 /* CB Message CB list */
722 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it7 = newCBMessageCBList.begin();
723 for (; it7 != newCBMessageCBList.end(); ++it7) {
724 if (it7->hAddr == pMsgHandle) {
725 it7->fd = CUSTOM_SOCKET_ERROR;
727 pMsgHandle->regCBMessageCallback(it7->pfCBIncomingCB, it7->bsave, it7->userParam);
728 } catch (MsgException& e) {
729 MSG_FATAL("%s", e.what());
734 /* Storage change Message CB list */
735 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it8 = storageChangeCBList.begin();
736 for (; it8 != storageChangeCBList.end(); ++it8) {
737 if (it8->hAddr == pMsgHandle) {
738 it8->fd = CUSTOM_SOCKET_ERROR;
740 pMsgHandle->regStorageChangeCallback(it8->pfStorageChangeCB, it8->userParam);
741 } catch (MsgException& e) {
742 MSG_FATAL("%s", e.what());
747 /* Report message incoming CB list */
748 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it9 = reportMessageCBList.begin();
749 for (; it9 != reportMessageCBList.end(); ++it9) {
750 if (it9->hAddr == pMsgHandle) {
751 it9->fd = CUSTOM_SOCKET_ERROR;
753 pMsgHandle->regReportMessageCallback(it9->pfReportMsgIncomingCB, it9->userParam);
754 } catch (MsgException& e) {
755 MSG_FATAL("%s", e.what());
760 /* SyncML Message Operation CB list */
761 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it10 = operationSyncMLMessageCBList.begin();
762 for (; it10 != operationSyncMLMessageCBList.end(); ++it10) {
763 if (it10->hAddr == pMsgHandle) {
764 it10->fd = CUSTOM_SOCKET_ERROR;
766 pMsgHandle->regSyncMLMessageOperationCallback(it10->pfSyncMLOperationCB, it10->userParam);
767 } catch (MsgException& e) {
768 MSG_FATAL("%s", e.what());
777 void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
782 THROW(MsgException::INVALID_PARAM, "pMsgEvent is NULL");
784 if (pMsgEvent->eventType == MSG_EVENT_PLG_SENT_STATUS_CNF) {
785 unsigned int chInfo[3] = {0}; /*3 reqid, status, object */
787 memcpy(&chInfo, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(chInfo));
789 msg_struct_s status = {0, };
790 MSG_SENT_STATUS_S statusData = {(msg_request_id_t)chInfo[0], (msg_network_status_t)chInfo[1]};
792 status.type = MSG_STRUCT_SENT_STATUS_INFO;
793 status.data = (void *)&statusData;
797 MsgSentStatusCBList::iterator it = sentStatusCBList.begin();
799 for ( ; it != sentStatusCBList.end() ; it++) {
800 MsgHandle* pHandle = it->hAddr;
802 msg_sent_status_cb pfunc = it->pfSentStatusCB;
804 void* param = it->userParam;
806 pfunc((msg_handle_t)pHandle, (msg_struct_t)&status, param);
810 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MSG_IND) {
811 MSG_MESSAGE_INFO_S msgInfo;
812 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
814 msgInfo.addressList = NULL;
815 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
817 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
819 int portKey = (msgInfo.msgPort.valid)? msgInfo.msgPort.dstPort: 0;
823 MsgNewMessageCBList::iterator it = newMessageCBList.begin();
824 MsgNewMessageCBList matchList;
826 for ( ; it != newMessageCBList.end() ; it++) {
827 if (portKey == it->port) {
828 matchList.push_back(*it);
834 it = matchList.begin();
836 for ( ; it != matchList.end(); it++ ) {
837 MsgHandle* pHandle = it->hAddr;
839 MSG_MESSAGE_HIDDEN_S msgHidden = {0, };
841 msgHidden.pData = NULL;
842 msgHidden.pMmsData = NULL;
844 /* Allocate memory for address list of message */
845 msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
847 addr_list->nCount = 0;
848 addr_list->msg_struct_info = (msg_struct_t *)calloc(MAX_TO_ADDRESS_CNT, sizeof(MSG_ADDRESS_INFO_S *));
849 if (addr_list->msg_struct_info == NULL)
852 msg_struct_s *pTmp = NULL;
854 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
855 addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
856 pTmp = (msg_struct_s *)addr_list->msg_struct_info[i];
857 pTmp->type = MSG_STRUCT_ADDRESS_INFO;
858 pTmp->data = new MSG_ADDRESS_INFO_S;
859 memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
861 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
864 msgHidden.addr_list = addr_list;
867 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
869 catch (MsgException& e) {
870 MSG_FATAL("%s", e.what());
873 msg_struct_s msg = {0, };
874 msg.type = MSG_STRUCT_MESSAGE_INFO;
875 msg.data = &msgHidden;
877 msg_sms_incoming_cb pfunc = it->pfIncomingCB;
879 void* param = it->userParam;
881 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
883 delete [] (char*)msgHidden.pData;
884 if (msgHidden.pMmsData != NULL)
885 delete [] (char*)msgHidden.pMmsData;
887 /* address Memory Free */
888 if (msgHidden.addr_list!= NULL) {
889 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
890 msg_struct_s * addrInfo = (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
891 delete (MSG_ADDRESS_INFO_S *)addrInfo->data;
892 addrInfo->data = NULL;
893 delete (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
894 msgHidden.addr_list->msg_struct_info[i] = NULL;
897 g_free(msgHidden.addr_list->msg_struct_info);
899 delete msgHidden.addr_list;
900 msgHidden.addr_list = NULL;
904 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MMS_CONF) {
905 MSG_MESSAGE_INFO_S msgInfo;
906 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
908 msgInfo.addressList = NULL;
909 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
911 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
914 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
916 char* appIdKey = (pMmsRecvData->msgAppId.valid)? pMmsRecvData->msgAppId.appId: NULL;
920 MsgNewMMSConfMessageCBList::iterator it = newMMSConfMessageCBList.begin();
921 MsgNewMMSConfMessageCBList matchList;
923 for ( ; it != newMMSConfMessageCBList.end(); it++) {
925 if (!strcmp(appIdKey, it->appId))
926 matchList.push_back(*it);
928 /* (appIdKey == NULL && it->appId[0] == 0) */
929 if (it->appId[0] == 0)
930 matchList.push_back(*it);
936 /* Contents of msgData removed and replaced to retrievedFilePath for convertMsgStruct */
937 /* it is moved from UpdateMessage in MmsPluginStorage.cpp */
938 char tempFileName[MSG_FILENAME_LEN_MAX+1] = {0}; /* check MSG_FILENAME_LEN_MAX */
940 strncpy(tempFileName, pMmsRecvData->retrievedFilePath, MSG_FILENAME_LEN_MAX);
942 memset(msgInfo.msgData, 0, MAX_MSG_DATA_LEN+1);
943 memcpy(msgInfo.msgData, tempFileName + strlen(MSG_DATA_PATH), MAX_MSG_DATA_LEN);
945 it = matchList.begin();
947 for ( ; it != matchList.end(); it++) {
948 MsgHandle* pHandle = it->hAddr;
950 MSG_MESSAGE_HIDDEN_S msgHidden = {0, };
952 msgHidden.pData = NULL;
953 msgHidden.pMmsData = NULL;
955 /* Allocate memory for address list of message */
956 msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
958 addr_list->nCount = 0;
959 addr_list->msg_struct_info = (msg_struct_t *)calloc(MAX_TO_ADDRESS_CNT, sizeof(MSG_ADDRESS_INFO_S *));
960 if (addr_list->msg_struct_info == NULL)
963 msg_struct_s *pTmp = NULL;
965 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
966 addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
967 pTmp = (msg_struct_s *)addr_list->msg_struct_info[i];
968 pTmp->type = MSG_STRUCT_ADDRESS_INFO;
969 pTmp->data = new MSG_ADDRESS_INFO_S;
970 memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
972 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
975 msgHidden.addr_list = addr_list;
978 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
980 catch (MsgException& e) {
981 MSG_FATAL("%s", e.what());
984 msg_struct_s msg = {0, };
985 msg.type = MSG_STRUCT_MESSAGE_INFO;
986 msg.data = &msgHidden;
988 msg_mms_conf_msg_incoming_cb pfunc = it->pfMMSConfIncomingCB;
990 void* param = it->userParam;
991 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
993 delete [] (char*)msgHidden.pData;
994 if (msgHidden.pMmsData != NULL)
995 delete [] (char*)msgHidden.pMmsData;
997 /* address Memory Free */
998 if (msgHidden.addr_list != NULL) {
999 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
1000 msg_struct_s * addrInfo = (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
1001 delete (MSG_ADDRESS_INFO_S *)addrInfo->data;
1002 addrInfo->data = NULL;
1003 delete (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
1004 msgHidden.addr_list->msg_struct_info[i] = NULL;
1007 g_free(msgHidden.addr_list->msg_struct_info);
1009 delete msgHidden.addr_list;
1010 msgHidden.addr_list = NULL;
1013 /* Here the retrieved message will be deleted from native storage. */
1014 /* as of now, msg which have appId is considered as JAVA MMS message and it will be sent and handled in JAVA app. */
1016 MSG_DEBUG("delete received JAVA MMS message:%s from native storage", tempFileName);
1017 pHandle->deleteMessage(msgInfo.msgId);
1020 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND) {
1021 MSG_SYNCML_MESSAGE_DATA_S* pSyncMLData = (MSG_SYNCML_MESSAGE_DATA_S *)pMsgEvent->data;
1023 MSG_DEBUG("msgType [%d]", pSyncMLData->syncmlType);
1027 MsgNewSyncMLMessageCBList::iterator it = newSyncMLMessageCBList.begin();
1029 for ( ; it != newSyncMLMessageCBList.end(); it++) {
1030 MsgHandle* pHandle = it->hAddr;
1032 msg_syncml_msg_incoming_cb pfunc = it->pfSyncMLIncomingCB;
1034 void* param = it->userParam;
1036 pfunc((msg_handle_t)pHandle, pSyncMLData->syncmlType, pSyncMLData->pushBody, pSyncMLData->pushBodyLen, pSyncMLData->wspHeader, pSyncMLData->wspHeaderLen, pSyncMLData->simIndex, param);
1040 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_LBS_MSG_IND) {
1041 MSG_LBS_MESSAGE_DATA_S* pLBSData = (MSG_LBS_MESSAGE_DATA_S *)pMsgEvent->data;
1045 MsgNewLBSMessageCBList::iterator it = newLBSMessageCBList.begin();
1047 for ( ; it != newLBSMessageCBList.end(); it++) {
1048 MsgHandle* pHandle = it->hAddr;
1050 msg_lbs_msg_incoming_cb pfunc = it->pfLBSMsgIncoming;
1052 void* param = it->userParam;
1054 pfunc((msg_handle_t)pHandle, pLBSData->pushHeader, pLBSData->pushBody, pLBSData->pushBodyLen, param);
1058 } else if (pMsgEvent->eventType == MSG_EVENT_SYNCML_OPERATION) {
1062 memcpy(&msgId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
1063 memcpy(&extId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(int)), sizeof(int));
1065 MSG_DEBUG("msgId [%d]", msgId);
1066 MSG_DEBUG("extId [%d]", extId);
1070 MsgOperationSyncMLMessageCBList::iterator it = operationSyncMLMessageCBList.begin();
1072 for ( ; it != operationSyncMLMessageCBList.end(); it++) {
1073 MsgHandle* pHandle = it->hAddr;
1075 msg_syncml_msg_operation_cb pfunc = it->pfSyncMLOperationCB;
1077 void* param = it->userParam;
1079 pfunc((msg_handle_t)pHandle, msgId, extId, param);
1083 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_STORAGE_CHANGE_IND) {
1084 msg_storage_change_type_t storageChangeType;
1085 msg_id_list_s msgIdList;
1086 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
1088 /* Decode event data */
1089 memcpy(&storageChangeType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_storage_change_type_t));
1090 memcpy(&msgIdList.nCount, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_storage_change_type_t)), sizeof(int));
1092 if (msgIdList.nCount > 0)
1093 msgIdList.msgIdList = (msg_message_id_t*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_storage_change_type_t)+sizeof(int));
1095 msgIdList.msgIdList = NULL;
1097 MSG_DEBUG("storageChangeType [%d], msgIdList.nCount [%d]", storageChangeType, msgIdList.nCount);
1101 MsgStorageChangeCBList::iterator it = storageChangeCBList.begin();
1103 for ( ; it != storageChangeCBList.end(); it++) {
1104 MsgHandle* pHandle = it->hAddr;
1106 msg_storage_change_cb pfunc = it->pfStorageChangeCB;
1108 void* param = it->userParam;
1110 pfunc((msg_handle_t)pHandle, storageChangeType, (msg_id_list_s*)&msgIdList, param);
1114 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_CB_MSG_IND) {
1115 MSG_CB_MSG_S *pCbMsg = (MSG_CB_MSG_S *)pMsgEvent->data;
1119 MsgNewCBMessageCBList::iterator it = newCBMessageCBList.begin();
1121 for ( ; it != newCBMessageCBList.end(); it++) {
1122 MsgHandle* pHandle = it->hAddr;
1123 msg_struct_s msg = {0, };
1125 msg.type = MSG_STRUCT_CB_MSG;
1128 msg_cb_incoming_cb pfunc = it->pfCBIncomingCB;
1130 void* param = it->userParam;
1132 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
1136 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND) {
1137 MSG_PUSH_MESSAGE_DATA_S* pPushData = (MSG_PUSH_MESSAGE_DATA_S *)pMsgEvent->data;
1141 MsgNewPushMessageCBList::iterator it = newPushMessageCBList.begin();
1143 for ( ; it != newPushMessageCBList.end(); it++) {
1144 MsgHandle* pHandle = it->hAddr;
1146 msg_push_msg_incoming_cb pfunc = it->pfPushIncomingCB;
1148 void* param = it->userParam;
1150 if (!strncmp(it->appId, pPushData->pushAppId, MAX_WAPPUSH_ID_LEN))
1151 pfunc((msg_handle_t)pHandle, pPushData->pushHeader, pPushData->pushBody, pPushData->pushBodyLen, param);
1155 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND) {
1156 msg_report_type_t reportType;
1157 msg_message_id_t msgId;
1161 /* Decode event data */
1162 memcpy(&reportType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_report_type_t));
1163 memcpy(&msgId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_report_type_t)), sizeof(msg_message_id_t));
1164 memcpy(&addr_len, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_report_type_t)+sizeof(msg_message_id_t)), sizeof(int));
1165 addr_val = (char*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_report_type_t)+sizeof(msg_message_id_t)+sizeof(int));
1166 addr_val[addr_len] = '\0';
1168 MSG_SEC_DEBUG("reportType [%d], msgId [%d], Address Length [%d], Address Value [%s]", reportType, msgId, addr_len, addr_val);
1172 MsgReportMessageCBList::iterator it = reportMessageCBList.begin();
1174 for ( ; it != reportMessageCBList.end(); it++) {
1175 MsgHandle* pHandle = it->hAddr;
1177 msg_report_msg_incoming_cb pfunc = it->pfReportMsgIncomingCB;
1179 void* param = it->userParam;
1181 pfunc((msg_handle_t)pHandle, reportType, msgId, addr_len, addr_val, param);
1191 int MsgProxyListener::getRemoteFd()
1193 return cliSock.getRemoteFd();
1197 int MsgProxyListener::readFromSocket(char** buf, unsigned int* len)
1199 return cliSock.read(buf, len);
1203 void MsgProxyListener::resetProxyListener()
1205 MSG_DEBUG("client Listener reset");
1206 MutexLocker lock(mx);
1209 g_io_channel_unref(channel);
1213 if (eventSourceId > 0) {
1214 g_source_remove(eventSourceId);
1222 handle_set::iterator it = openHandleSet.begin();
1223 for (; it != openHandleSet.end(); it++) {
1224 MSG_DEBUG("disconnect socket for opened handle [%p]", it);
1225 MsgHandle *handle = (MsgHandle *)*it;
1226 handle->disconnectSocket();
1231 void MsgProxyListener::refreshProxyListener()
1233 MSG_DEBUG("refresh proxy listener");
1234 MutexLocker lock(mx);
1236 handle_set::iterator it = openHandleSet.begin();
1237 for (; it != openHandleSet.end(); it++) {
1238 MsgHandle *handle = (MsgHandle *)*it;
1239 handle->openHandle();
1240 refreshListOfOpenedHandle(handle);
1245 void MsgProxyListener::clearProxyCBLists()
1247 MSG_DEBUG("clear proxy callback list");
1249 sentStatusCBList.clear();
1250 newMessageCBList.clear();
1251 newMMSConfMessageCBList.clear();
1252 newSyncMLMessageCBList.clear();
1253 newLBSMessageCBList.clear();
1254 newPushMessageCBList.clear();
1255 newCBMessageCBList.clear();
1256 newSyncMLMessageCBList.clear();
1257 storageChangeCBList.clear();
1258 reportMessageCBList.clear();
1262 void MsgProxyListener::insertOpenHandleSet(MsgHandle* pMsgHandle)
1264 MSG_DEBUG("try to insert opened handle. handle=[%p]", pMsgHandle);
1266 MutexLocker lock(mx);
1268 handle_set::iterator it = openHandleSet.find(pMsgHandle);
1269 if (it == openHandleSet.end()) {
1270 openHandleSet.insert(pMsgHandle);
1271 MSG_DEBUG("New handle is added. current count = [%d]", openHandleSet.size());
1276 void MsgProxyListener::clearOpenHandleSet()
1278 MSG_DEBUG("clear opened handle set");
1279 openHandleSet.clear();
1282 #ifdef CHECK_SENT_STATUS_CALLBACK
1283 int MsgProxyListener::getSentStatusCbCnt()
1287 cbCnt = sentStatusCBList.size();
1289 MSG_DEBUG("registered sent status callback count : [%d]", cbCnt);