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 MsgMutexLocker lock(mm);
149 pInstance = new MsgProxyListener();
156 void MsgProxyListener::start(MsgHandle* pMsgHandle)
158 MsgMutexLocker lock(mx);
160 this->insertOpenHandleSet(pMsgHandle);
163 cliSock.connect(MSG_SOCKET_PATH);
165 int fd = cliSock.fd();
167 MSG_DEBUG("Socket Fd : %d", fd);
169 /* initializes ref_count = 1 */
170 channel = g_io_channel_unix_new(fd);
172 /* increments ref_count = 2 */
173 eventSourceId = g_io_add_watch(channel, (GIOCondition)(G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), &readSocket, NULL);
175 MSG_DEBUG("Call g_io_add_watch() : %d", eventSourceId);
179 MSG_DEBUG("add Listener and [%d] are running.", running);
183 void MsgProxyListener::stop()
187 MsgMutexLocker lock(mx);
191 MSG_DEBUG("There are still running Listener. [%d] left.", running);
192 } else if (running == 1) {
194 g_io_channel_unref(channel);
198 if (eventSourceId > 0) {
199 g_source_remove(eventSourceId);
206 MSG_DEBUG("client Listener is terminated.");
213 bool MsgProxyListener::regSentStatusEventCB(MsgHandle* pMsgHandle, int fd, msg_sent_status_cb pfSentStatus, void *pUserParam)
215 MsgMutexLocker lock(mx);
217 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
219 for (; it != sentStatusCBList.end(); it++) {
220 if (it->hAddr == pMsgHandle && it->pfSentStatusCB == pfSentStatus) {
222 MSG_DEBUG("msg_sent_status_cb() callback : [%p] is already registered!!!", pfSentStatus);
225 MSG_DEBUG("callback is registered by restarting server");
232 MSG_SENT_STATUS_CB_ITEM_S sentStatusCB = {pMsgHandle, fd, pfSentStatus, pUserParam};
234 sentStatusCBList.push_back(sentStatusCB);
240 bool MsgProxyListener::regMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_sms_incoming_cb pfNewMessage, int port, void *pUserParam)
242 MsgMutexLocker lock(mx);
244 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it = newMessageCBList.begin();
246 for (; it != newMessageCBList.end(); it++) {
247 if (it->hAddr == pMsgHandle && it->port == port && it->pfIncomingCB == pfNewMessage) {
249 MSG_DEBUG("msg_sms_incoming_cb() callback : Port Number [%d] is already registered!!!", port);
252 MSG_DEBUG("callback is registered by restarting server");
259 MSG_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewMessage, port, pUserParam};
261 newMessageCBList.push_back(incomingCB);
267 bool MsgProxyListener::regMMSConfMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_mms_conf_msg_incoming_cb pfNewMMSConfMessage, const char *pAppId, void *pUserParam)
269 MsgMutexLocker lock(mx);
271 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it = newMMSConfMessageCBList.begin();
273 for (; it != newMMSConfMessageCBList.end(); it++) {
274 if (it->hAddr == pMsgHandle && it->pfMMSConfIncomingCB == pfNewMMSConfMessage) {
276 if (pAppId == NULL) {
277 MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback is already registered!!!");
279 } else if (!strncmp(it->appId, pAppId, MAX_MMS_JAVA_APPID_LEN)) {
280 MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
284 MSG_DEBUG("callback is registered by restarting server");
291 MSG_MMS_CONF_INCOMING_CB_ITEM_S incomingConfCB = {pMsgHandle, fd, pfNewMMSConfMessage, {0}, pUserParam};
294 strncpy(incomingConfCB.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
296 newMMSConfMessageCBList.push_back(incomingConfCB);
302 bool MsgProxyListener::regPushMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_push_msg_incoming_cb pfNewPushMessage, const char *pAppId, void *pUserParam)
304 MsgMutexLocker lock(mx);
306 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it = newPushMessageCBList.begin();
308 for (; it != newPushMessageCBList.end(); it++) {
309 if (it->hAddr == pMsgHandle && it->pfPushIncomingCB == pfNewPushMessage) {
311 if (pAppId == NULL) {
312 MSG_DEBUG("msg_push_msg_incoming_cb() callback is already registered!!!");
314 } else if (!strncmp(it->appId, pAppId, MAX_WAPPUSH_ID_LEN)) {
315 MSG_DEBUG("msg_push_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
319 MSG_DEBUG("callback is registered by restarting server");
326 MSG_PUSH_INCOMING_CB_ITEM_S incomingPushCB = {pMsgHandle, fd, pfNewPushMessage, {0}, pUserParam};
329 strncpy(incomingPushCB.appId, pAppId, MAX_WAPPUSH_ID_LEN);
331 newPushMessageCBList.push_back(incomingPushCB);
337 bool MsgProxyListener::regCBMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_cb_incoming_cb pfNewCBMessage, bool bSave, void *pUserParam)
339 MsgMutexLocker lock(mx);
341 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it = newCBMessageCBList.begin();
343 for (; it != newCBMessageCBList.end(); it++) {
344 if (it->hAddr == pMsgHandle && it->pfCBIncomingCB == pfNewCBMessage) {
346 MSG_DEBUG("msg_CB_incoming_cb() callback : [%p] is already registered!!!", pfNewCBMessage);
348 it->userParam = pUserParam;
351 MSG_DEBUG("callback is registered by restarting server");
358 MSG_CB_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewCBMessage, bSave, pUserParam};
360 newCBMessageCBList.push_back(incomingCB);
366 bool MsgProxyListener::regReportMsgIncomingCB(MsgHandle* pMsgHandle, int fd, msg_report_msg_incoming_cb pfReportMessage, void *pUserParam)
368 MsgMutexLocker lock(mx);
370 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it = reportMessageCBList.begin();
372 for (; it != reportMessageCBList.end(); it++) {
373 if (it->hAddr == pMsgHandle && it->pfReportMsgIncomingCB == pfReportMessage) {
375 MSG_DEBUG("msg_report_msg_incoming_cb() callback : [%p] is already registered!!!", pfReportMessage);
376 it->userParam = pUserParam;
379 MSG_DEBUG("callback is registered by restarting server");
386 MSG_REPORT_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfReportMessage, pUserParam};
388 reportMessageCBList.push_back(incomingCB);
394 bool MsgProxyListener::regSyncMLMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_incoming_cb pfNewSyncMLMessage, void *pUserParam)
396 MsgMutexLocker lock(mx);
398 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it = newSyncMLMessageCBList.begin();
400 for (; it != newSyncMLMessageCBList.end(); it++) {
401 if (it->hAddr == pMsgHandle && it->pfSyncMLIncomingCB == pfNewSyncMLMessage) {
403 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewSyncMLMessage);
406 MSG_DEBUG("callback is registered by restarting server");
413 MSG_SYNCML_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewSyncMLMessage, pUserParam};
415 newSyncMLMessageCBList.push_back(incomingCB);
421 bool MsgProxyListener::regLBSMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_lbs_msg_incoming_cb pfNewLBSMsgIncoming, void *pUserParam)
423 MsgMutexLocker lock(mx);
425 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it = newLBSMessageCBList.begin();
427 for (; it != newLBSMessageCBList.end(); it++) {
428 if (it->hAddr == pMsgHandle && it->pfLBSMsgIncoming == pfNewLBSMsgIncoming) {
430 MSG_DEBUG("msg_lbs_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewLBSMsgIncoming);
433 MSG_DEBUG("callback is registered by restarting server");
440 MSG_LBS_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewLBSMsgIncoming, pUserParam};
442 newLBSMessageCBList.push_back(incomingCB);
448 bool MsgProxyListener::regSyncMLMessageOperationEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_operation_cb pfSyncMLMessageOperation, void *pUserParam)
450 MsgMutexLocker lock(mx);
452 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it = operationSyncMLMessageCBList.begin();
454 for (; it != operationSyncMLMessageCBList.end(); it++) {
455 if (it->hAddr == pMsgHandle && it->pfSyncMLOperationCB == pfSyncMLMessageOperation) {
457 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfSyncMLMessageOperation);
460 MSG_DEBUG("callback is registered by restarting server");
467 MSG_SYNCML_OPERATION_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfSyncMLMessageOperation, pUserParam};
469 operationSyncMLMessageCBList.push_back(incomingCB);
475 bool MsgProxyListener::regStorageChangeEventCB(MsgHandle* pMsgHandle, int fd, msg_storage_change_cb pfStorageChangeOperation, void *pUserParam)
477 MsgMutexLocker lock(mx);
479 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it = storageChangeCBList.begin();
481 for (; it != storageChangeCBList.end(); it++) {
482 if (it->hAddr == pMsgHandle && it->pfStorageChangeCB == pfStorageChangeOperation) {
484 MSG_DEBUG("msg_storage_change_cb() callback : [%p] is already registered!!!", pfStorageChangeOperation);
487 MSG_DEBUG("callback is registered by restarting server");
494 MSG_STORAGE_CHANGE_CB_ITEM_S changeCB = {pMsgHandle, fd, pfStorageChangeOperation, pUserParam};
496 storageChangeCBList.push_back(changeCB);
502 bool MsgProxyListener::regThreadChangeEventCB(MsgHandle* pMsgHandle, int fd, msg_thread_change_cb pfThreadChangeOperation, void *pUserParam)
504 MsgMutexLocker lock(mx);
506 std::list<MSG_THREAD_CHANGE_CB_ITEM_S>::iterator it = threadChangeCBList.begin();
508 for (; it != threadChangeCBList.end(); it++) {
509 if (it->hAddr == pMsgHandle && it->pfThreadChangeCB == pfThreadChangeOperation) {
511 MSG_DEBUG("msg_thread_change_cb() callback : [%p] is already registered!!!", pfThreadChangeOperation);
514 MSG_DEBUG("callback is registered by restarting server");
521 MSG_THREAD_CHANGE_CB_ITEM_S changeCB = {pMsgHandle, fd, pfThreadChangeOperation, pUserParam};
523 threadChangeCBList.push_back(changeCB);
529 void MsgProxyListener::clearListOfClosedHandle(MsgHandle* pMsgHandle)
533 MsgMutexLocker lock(mx);
535 /* sent status CB list */
536 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
538 for (; it != sentStatusCBList.end(); ) {
539 if (it->hAddr == pMsgHandle) {
540 sentStatusCBList.erase(it++);
547 /* new message CB list */
548 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it2 = newMessageCBList.begin();
550 for (; it2 != newMessageCBList.end(); ) {
551 if (it2->hAddr == pMsgHandle) {
552 newMessageCBList.erase(it2++);
559 /* MMS conf Message CB list */
560 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it3 = newMMSConfMessageCBList.begin();
562 for (; it3 != newMMSConfMessageCBList.end(); ) {
563 if (it3->hAddr == pMsgHandle) {
564 newMMSConfMessageCBList.erase(it3++);
571 /* SyncML Message CB list */
572 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it4 = newSyncMLMessageCBList.begin();
574 for (; it4 != newSyncMLMessageCBList.end(); ) {
575 if (it4->hAddr == pMsgHandle) {
576 newSyncMLMessageCBList.erase(it4++);
583 /* LBS Message CB list */
584 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it5 = newLBSMessageCBList.begin();
586 for (; it5 != newLBSMessageCBList.end(); ) {
587 if (it5->hAddr == pMsgHandle) {
588 newLBSMessageCBList.erase(it5++);
595 /* Push Message CB list */
596 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it6 = newPushMessageCBList.begin();
598 for (; it6 != newPushMessageCBList.end(); ) {
599 if (it6->hAddr == pMsgHandle) {
600 newPushMessageCBList.erase(it6++);
607 /* CB Message CB list */
608 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it7 = newCBMessageCBList.begin();
610 for (; it7 != newCBMessageCBList.end(); ) {
611 if (it7->hAddr == pMsgHandle) {
612 newCBMessageCBList.erase(it7++);
619 /* Storage change Message CB list */
620 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it8 = storageChangeCBList.begin();
622 for (; it8 != storageChangeCBList.end(); ) {
623 if (it8->hAddr == pMsgHandle) {
624 storageChangeCBList.erase(it8++);
632 /* Report message incoming CB list */
633 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it9 = reportMessageCBList.begin();
634 for (; it9 != reportMessageCBList.end(); ) {
635 if (it9->hAddr == pMsgHandle) {
636 reportMessageCBList.erase(it9++);
644 /* SyncML Message Operation CB list */
645 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it10 = operationSyncMLMessageCBList.begin();
646 for (; it10 != operationSyncMLMessageCBList.end(); ) {
647 if (it10->hAddr == pMsgHandle) {
648 operationSyncMLMessageCBList.erase(it10++);
656 /* Thread change Message CB list */
657 std::list<MSG_THREAD_CHANGE_CB_ITEM_S>::iterator it11 = threadChangeCBList.begin();
659 for (; it11 != threadChangeCBList.end(); ) {
660 if (it11->hAddr == pMsgHandle) {
661 threadChangeCBList.erase(it11++);
668 /* Open Handle Set */
669 openHandleSet.erase(pMsgHandle);
675 void MsgProxyListener::refreshListOfOpenedHandle(MsgHandle* pMsgHandle)
679 MsgMutexLocker lock(mx);
681 /* sent status CB list */
682 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
683 for (; it != sentStatusCBList.end(); ++it) {
684 if (it->hAddr == pMsgHandle) {
685 it->fd = CUSTOM_SOCKET_ERROR;
687 pMsgHandle->regSentStatusCallback(it->pfSentStatusCB, it->userParam);
688 } catch (MsgException& e) {
689 MSG_FATAL("%s", e.what());
694 /* new message CB list */
695 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it2 = newMessageCBList.begin();
696 for (; it2 != newMessageCBList.end(); ++it2) {
697 if (it2->hAddr == pMsgHandle) {
698 it2->fd = CUSTOM_SOCKET_ERROR;
700 pMsgHandle->regSmsMessageCallback(it2->pfIncomingCB, it2->port, it2->userParam);
701 } catch (MsgException& e) {
702 MSG_FATAL("%s", e.what());
707 /* MMS conf Message CB list */
708 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it3 = newMMSConfMessageCBList.begin();
709 for (; it3 != newMMSConfMessageCBList.end(); ++it3) {
710 if (it3->hAddr == pMsgHandle) {
711 it3->fd = CUSTOM_SOCKET_ERROR;
713 pMsgHandle->regMmsConfMessageCallback(it3->pfMMSConfIncomingCB, it3->appId, it3->userParam);
714 } catch (MsgException& e) {
715 MSG_FATAL("%s", e.what());
720 /* SyncML Message CB list */
721 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it4 = newSyncMLMessageCBList.begin();
722 for (; it4 != newSyncMLMessageCBList.end(); ++it4) {
723 if (it4->hAddr == pMsgHandle) {
724 it4->fd = CUSTOM_SOCKET_ERROR;
726 pMsgHandle->regSyncMLMessageCallback(it4->pfSyncMLIncomingCB, it4->userParam);
727 } catch (MsgException& e) {
728 MSG_FATAL("%s", e.what());
733 /* LBS Message CB list */
734 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it5 = newLBSMessageCBList.begin();
735 for (; it5 != newLBSMessageCBList.end(); ++it5) {
736 if (it5->hAddr == pMsgHandle) {
737 it5->fd = CUSTOM_SOCKET_ERROR;
739 pMsgHandle->regLBSMessageCallback(it5->pfLBSMsgIncoming, it5->userParam);
740 } catch (MsgException& e) {
741 MSG_FATAL("%s", e.what());
746 /* Push Message CB list */
747 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it6 = newPushMessageCBList.begin();
748 for (; it6 != newPushMessageCBList.end(); ++it6) {
749 if (it6->hAddr == pMsgHandle) {
750 it6->fd = CUSTOM_SOCKET_ERROR;
752 pMsgHandle->regPushMessageCallback(it6->pfPushIncomingCB, it6->appId, it6->userParam);
753 } catch (MsgException& e) {
754 MSG_FATAL("%s", e.what());
759 /* CB Message CB list */
760 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it7 = newCBMessageCBList.begin();
761 for (; it7 != newCBMessageCBList.end(); ++it7) {
762 if (it7->hAddr == pMsgHandle) {
763 it7->fd = CUSTOM_SOCKET_ERROR;
765 pMsgHandle->regCBMessageCallback(it7->pfCBIncomingCB, it7->bsave, it7->userParam);
766 } catch (MsgException& e) {
767 MSG_FATAL("%s", e.what());
772 /* Storage change Message CB list */
773 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it8 = storageChangeCBList.begin();
774 for (; it8 != storageChangeCBList.end(); ++it8) {
775 if (it8->hAddr == pMsgHandle) {
776 it8->fd = CUSTOM_SOCKET_ERROR;
778 pMsgHandle->regStorageChangeCallback(it8->pfStorageChangeCB, it8->userParam);
779 } catch (MsgException& e) {
780 MSG_FATAL("%s", e.what());
785 /* Report message incoming CB list */
786 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it9 = reportMessageCBList.begin();
787 for (; it9 != reportMessageCBList.end(); ++it9) {
788 if (it9->hAddr == pMsgHandle) {
789 it9->fd = CUSTOM_SOCKET_ERROR;
791 pMsgHandle->regReportMessageCallback(it9->pfReportMsgIncomingCB, it9->userParam);
792 } catch (MsgException& e) {
793 MSG_FATAL("%s", e.what());
798 /* SyncML Message Operation CB list */
799 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it10 = operationSyncMLMessageCBList.begin();
800 for (; it10 != operationSyncMLMessageCBList.end(); ++it10) {
801 if (it10->hAddr == pMsgHandle) {
802 it10->fd = CUSTOM_SOCKET_ERROR;
804 pMsgHandle->regSyncMLMessageOperationCallback(it10->pfSyncMLOperationCB, it10->userParam);
805 } catch (MsgException& e) {
806 MSG_FATAL("%s", e.what());
811 /* Thread change Message CB list */
812 std::list<MSG_THREAD_CHANGE_CB_ITEM_S>::iterator it11 = threadChangeCBList.begin();
813 for (; it11 != threadChangeCBList.end(); ++it11) {
814 if (it11->hAddr == pMsgHandle) {
815 it11->fd = CUSTOM_SOCKET_ERROR;
817 pMsgHandle->regThreadChangeCallback(it11->pfThreadChangeCB, it11->userParam);
818 } catch (MsgException& e) {
819 MSG_FATAL("%s", e.what());
828 void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
833 THROW(MsgException::INVALID_PARAM, "pMsgEvent is NULL");
835 if (pMsgEvent->eventType == MSG_EVENT_PLG_SENT_STATUS_CNF) {
836 unsigned long chInfo[3] = {0}; /*3 reqid, status, object */
838 memcpy(&chInfo, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(chInfo));
840 msg_struct_s status = {0, };
841 MSG_SENT_STATUS_S statusData = {(msg_request_id_t)chInfo[0], (msg_network_status_t)chInfo[1]};
843 status.type = MSG_STRUCT_SENT_STATUS_INFO;
844 status.data = (void *)&statusData;
848 MsgSentStatusCBList::iterator it = sentStatusCBList.begin();
850 for ( ; it != sentStatusCBList.end() ; it++) {
851 MsgHandle* pHandle = it->hAddr;
853 msg_sent_status_cb pfunc = it->pfSentStatusCB;
855 void* param = it->userParam;
857 pfunc((msg_handle_t)pHandle, (msg_struct_t)&status, param);
861 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MSG_IND) {
862 MSG_MESSAGE_INFO_S msgInfo;
863 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
865 msgInfo.addressList = NULL;
866 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
868 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
870 int portKey = (msgInfo.msgPort.valid)? msgInfo.msgPort.dstPort: 0;
874 MsgNewMessageCBList::iterator it = newMessageCBList.begin();
875 MsgNewMessageCBList matchList;
877 for ( ; it != newMessageCBList.end() ; it++) {
878 if (portKey == it->port) {
879 matchList.push_back(*it);
885 it = matchList.begin();
887 for ( ; it != matchList.end(); it++ ) {
888 MsgHandle* pHandle = it->hAddr;
890 MSG_MESSAGE_HIDDEN_S msgHidden = {0, };
892 msgHidden.pData = NULL;
893 msgHidden.pMmsData = NULL;
895 /* Allocate memory for address list of message */
896 msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
898 addr_list->nCount = 0;
899 addr_list->msg_struct_info = (msg_struct_t *)calloc(MAX_TO_ADDRESS_CNT, sizeof(MSG_ADDRESS_INFO_S *));
900 if (addr_list->msg_struct_info == NULL)
903 msg_struct_s *pTmp = NULL;
905 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
906 addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
907 pTmp = (msg_struct_s *)addr_list->msg_struct_info[i];
908 pTmp->type = MSG_STRUCT_ADDRESS_INFO;
909 pTmp->data = new MSG_ADDRESS_INFO_S;
910 memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
912 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
915 msgHidden.addr_list = addr_list;
918 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
920 catch (MsgException& e) {
921 MSG_FATAL("%s", e.what());
924 msg_struct_s msg = {0, };
925 msg.type = MSG_STRUCT_MESSAGE_INFO;
926 msg.data = &msgHidden;
928 msg_sms_incoming_cb pfunc = it->pfIncomingCB;
930 void* param = it->userParam;
932 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
934 delete [] (char*)msgHidden.pData;
935 if (msgHidden.pMmsData != NULL)
936 delete [] (char*)msgHidden.pMmsData;
938 /* address Memory Free */
939 if (msgHidden.addr_list!= NULL) {
940 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
941 msg_struct_s * addrInfo = (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
942 delete (MSG_ADDRESS_INFO_S *)addrInfo->data;
943 addrInfo->data = NULL;
944 delete (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
945 msgHidden.addr_list->msg_struct_info[i] = NULL;
948 g_free(msgHidden.addr_list->msg_struct_info);
950 delete msgHidden.addr_list;
951 msgHidden.addr_list = NULL;
955 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MMS_CONF) {
956 MSG_MESSAGE_INFO_S msgInfo;
957 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
959 msgInfo.addressList = NULL;
960 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
962 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
965 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
967 char* appIdKey = (pMmsRecvData->msgAppId.valid)? pMmsRecvData->msgAppId.appId: NULL;
971 MsgNewMMSConfMessageCBList::iterator it = newMMSConfMessageCBList.begin();
972 MsgNewMMSConfMessageCBList matchList;
974 for ( ; it != newMMSConfMessageCBList.end(); it++) {
976 if (!strcmp(appIdKey, it->appId))
977 matchList.push_back(*it);
979 /* (appIdKey == NULL && it->appId[0] == 0) */
980 if (it->appId[0] == 0)
981 matchList.push_back(*it);
987 /* Contents of msgData removed and replaced to retrievedFilePath for convertMsgStruct */
988 /* it is moved from UpdateMessage in MmsPluginStorage.cpp */
989 char tempFileName[MSG_FILENAME_LEN_MAX+1] = {0}; /* check MSG_FILENAME_LEN_MAX */
991 strncpy(tempFileName, pMmsRecvData->retrievedFilePath, MSG_FILENAME_LEN_MAX);
993 memset(msgInfo.msgData, 0, MAX_MSG_DATA_LEN+1);
994 memcpy(msgInfo.msgData, tempFileName + strlen(MSG_DATA_PATH), MAX_MSG_DATA_LEN);
996 it = matchList.begin();
998 for ( ; it != matchList.end(); it++) {
999 MsgHandle* pHandle = it->hAddr;
1001 MSG_MESSAGE_HIDDEN_S msgHidden = {0, };
1003 msgHidden.pData = NULL;
1004 msgHidden.pMmsData = NULL;
1006 /* Allocate memory for address list of message */
1007 msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
1009 addr_list->nCount = 0;
1010 addr_list->msg_struct_info = (msg_struct_t *)calloc(MAX_TO_ADDRESS_CNT, sizeof(MSG_ADDRESS_INFO_S *));
1011 if (addr_list->msg_struct_info == NULL)
1014 msg_struct_s *pTmp = NULL;
1016 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
1017 addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
1018 pTmp = (msg_struct_s *)addr_list->msg_struct_info[i];
1019 pTmp->type = MSG_STRUCT_ADDRESS_INFO;
1020 pTmp->data = new MSG_ADDRESS_INFO_S;
1021 memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1023 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
1026 msgHidden.addr_list = addr_list;
1029 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
1031 catch (MsgException& e) {
1032 MSG_FATAL("%s", e.what());
1035 msg_struct_s msg = {0, };
1036 msg.type = MSG_STRUCT_MESSAGE_INFO;
1037 msg.data = &msgHidden;
1039 msg_mms_conf_msg_incoming_cb pfunc = it->pfMMSConfIncomingCB;
1041 void* param = it->userParam;
1042 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
1044 delete [] (char*)msgHidden.pData;
1045 if (msgHidden.pMmsData != NULL)
1046 delete [] (char*)msgHidden.pMmsData;
1048 /* address Memory Free */
1049 if (msgHidden.addr_list != NULL) {
1050 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
1051 msg_struct_s * addrInfo = (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
1052 delete (MSG_ADDRESS_INFO_S *)addrInfo->data;
1053 addrInfo->data = NULL;
1054 delete (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
1055 msgHidden.addr_list->msg_struct_info[i] = NULL;
1058 g_free(msgHidden.addr_list->msg_struct_info);
1060 delete msgHidden.addr_list;
1061 msgHidden.addr_list = NULL;
1064 /* Here the retrieved message will be deleted from native storage. */
1065 /* as of now, msg which have appId is considered as JAVA MMS message and it will be sent and handled in JAVA app. */
1067 MSG_DEBUG("delete received JAVA MMS message:%s from native storage", tempFileName);
1068 pHandle->deleteMessage(msgInfo.msgId);
1071 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND) {
1072 MSG_SYNCML_MESSAGE_DATA_S* pSyncMLData = (MSG_SYNCML_MESSAGE_DATA_S *)pMsgEvent->data;
1074 MSG_DEBUG("msgType [%d]", pSyncMLData->syncmlType);
1078 MsgNewSyncMLMessageCBList::iterator it = newSyncMLMessageCBList.begin();
1080 for ( ; it != newSyncMLMessageCBList.end(); it++) {
1081 MsgHandle* pHandle = it->hAddr;
1083 msg_syncml_msg_incoming_cb pfunc = it->pfSyncMLIncomingCB;
1085 void* param = it->userParam;
1087 pfunc((msg_handle_t)pHandle, pSyncMLData->syncmlType, pSyncMLData->pushBody, pSyncMLData->pushBodyLen, pSyncMLData->wspHeader, pSyncMLData->wspHeaderLen, pSyncMLData->simIndex, param);
1091 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_LBS_MSG_IND) {
1092 MSG_LBS_MESSAGE_DATA_S* pLBSData = (MSG_LBS_MESSAGE_DATA_S *)pMsgEvent->data;
1096 MsgNewLBSMessageCBList::iterator it = newLBSMessageCBList.begin();
1098 for ( ; it != newLBSMessageCBList.end(); it++) {
1099 MsgHandle* pHandle = it->hAddr;
1101 msg_lbs_msg_incoming_cb pfunc = it->pfLBSMsgIncoming;
1103 void* param = it->userParam;
1105 pfunc((msg_handle_t)pHandle, pLBSData->pushHeader, pLBSData->pushBody, pLBSData->pushBodyLen, param);
1109 } else if (pMsgEvent->eventType == MSG_EVENT_SYNCML_OPERATION) {
1113 memcpy(&msgId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
1114 memcpy(&extId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(int)), sizeof(int));
1116 MSG_DEBUG("msgId [%d]", msgId);
1117 MSG_DEBUG("extId [%d]", extId);
1121 MsgOperationSyncMLMessageCBList::iterator it = operationSyncMLMessageCBList.begin();
1123 for ( ; it != operationSyncMLMessageCBList.end(); it++) {
1124 MsgHandle* pHandle = it->hAddr;
1126 msg_syncml_msg_operation_cb pfunc = it->pfSyncMLOperationCB;
1128 void* param = it->userParam;
1130 pfunc((msg_handle_t)pHandle, msgId, extId, param);
1134 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_STORAGE_CHANGE_IND) {
1135 msg_storage_change_type_t storageChangeType;
1136 msg_id_list_s msgIdList;
1137 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
1139 /* Decode event data */
1140 memcpy(&storageChangeType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_storage_change_type_t));
1141 memcpy(&msgIdList.nCount, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_storage_change_type_t)), sizeof(int));
1143 if (msgIdList.nCount > 0)
1144 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));
1146 msgIdList.msgIdList = NULL;
1148 MSG_DEBUG("storageChangeType [%d], msgIdList.nCount [%d]", storageChangeType, msgIdList.nCount);
1152 MsgStorageChangeCBList::iterator it = storageChangeCBList.begin();
1154 for ( ; it != storageChangeCBList.end(); it++) {
1155 MsgHandle* pHandle = it->hAddr;
1157 msg_storage_change_cb pfunc = it->pfStorageChangeCB;
1159 void* param = it->userParam;
1161 pfunc((msg_handle_t)pHandle, storageChangeType, (msg_id_list_s*)&msgIdList, param);
1165 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_THREAD_CHANGE_IND) {
1166 msg_storage_change_type_t storageChangeType;
1167 msg_thread_id_t threadId;
1169 /* Decode event data */
1170 memcpy(&storageChangeType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_storage_change_type_t));
1171 memcpy(&threadId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_storage_change_type_t)), sizeof(msg_thread_id_t));
1173 MSG_DEBUG("storageChangeType [%d], threadId [%d]", storageChangeType, threadId);
1177 MsgThreadChangeCBList::iterator it = threadChangeCBList.begin();
1179 for ( ; it != threadChangeCBList.end(); it++) {
1180 MsgHandle* pHandle = it->hAddr;
1182 msg_thread_change_cb pfunc = it->pfThreadChangeCB;
1184 void* param = it->userParam;
1186 pfunc((msg_handle_t)pHandle, storageChangeType, threadId, param);
1190 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_CB_MSG_IND) {
1191 MSG_CB_MSG_S *pCbMsg = (MSG_CB_MSG_S *)pMsgEvent->data;
1195 MsgNewCBMessageCBList::iterator it = newCBMessageCBList.begin();
1197 for ( ; it != newCBMessageCBList.end(); it++) {
1198 MsgHandle* pHandle = it->hAddr;
1199 msg_struct_s msg = {0, };
1201 msg.type = MSG_STRUCT_CB_MSG;
1204 msg_cb_incoming_cb pfunc = it->pfCBIncomingCB;
1206 void* param = it->userParam;
1208 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
1212 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND) {
1213 MSG_PUSH_MESSAGE_DATA_S* pPushData = (MSG_PUSH_MESSAGE_DATA_S *)pMsgEvent->data;
1217 MsgNewPushMessageCBList::iterator it = newPushMessageCBList.begin();
1219 for ( ; it != newPushMessageCBList.end(); it++) {
1220 MsgHandle* pHandle = it->hAddr;
1222 msg_push_msg_incoming_cb pfunc = it->pfPushIncomingCB;
1224 void* param = it->userParam;
1226 if (!strncmp(it->appId, pPushData->pushAppId, MAX_WAPPUSH_ID_LEN))
1227 pfunc((msg_handle_t)pHandle, pPushData->pushHeader, pPushData->pushBody, pPushData->pushBodyLen, param);
1231 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND) {
1232 msg_report_type_t reportType;
1233 msg_message_id_t msgId;
1237 /* Decode event data */
1238 memcpy(&reportType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_report_type_t));
1239 memcpy(&msgId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_report_type_t)), sizeof(msg_message_id_t));
1240 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));
1241 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));
1242 addr_val[addr_len] = '\0';
1244 MSG_SEC_DEBUG("reportType [%d], msgId [%d], Address Length [%d], Address Value [%s]", reportType, msgId, addr_len, addr_val);
1248 MsgReportMessageCBList::iterator it = reportMessageCBList.begin();
1250 for ( ; it != reportMessageCBList.end(); it++) {
1251 MsgHandle* pHandle = it->hAddr;
1253 msg_report_msg_incoming_cb pfunc = it->pfReportMsgIncomingCB;
1255 void* param = it->userParam;
1257 pfunc((msg_handle_t)pHandle, reportType, msgId, addr_len, addr_val, param);
1267 int MsgProxyListener::getRemoteFd()
1269 return cliSock.getRemoteFd();
1273 int MsgProxyListener::readFromSocket(char** buf, unsigned int* len)
1275 return cliSock.read(buf, len);
1279 void MsgProxyListener::resetProxyListener()
1281 MSG_DEBUG("client Listener reset");
1282 MsgMutexLocker lock(mx);
1285 g_io_channel_unref(channel);
1289 if (eventSourceId > 0) {
1290 g_source_remove(eventSourceId);
1298 handle_set::iterator it = openHandleSet.begin();
1299 for (; it != openHandleSet.end(); it++) {
1300 MSG_DEBUG("disconnect socket for opened handle [%p]", it);
1301 MsgHandle *handle = (MsgHandle *)*it;
1302 handle->disconnectSocket();
1307 void MsgProxyListener::refreshProxyListener()
1309 MSG_DEBUG("refresh proxy listener");
1310 MsgMutexLocker lock(mx);
1312 handle_set::iterator it = openHandleSet.begin();
1313 for (; it != openHandleSet.end(); it++) {
1314 MsgHandle *handle = (MsgHandle *)*it;
1315 handle->openHandle();
1316 refreshListOfOpenedHandle(handle);
1321 void MsgProxyListener::clearProxyCBLists()
1323 MSG_DEBUG("clear proxy callback list");
1325 sentStatusCBList.clear();
1326 newMessageCBList.clear();
1327 newMMSConfMessageCBList.clear();
1328 newSyncMLMessageCBList.clear();
1329 newLBSMessageCBList.clear();
1330 newPushMessageCBList.clear();
1331 newCBMessageCBList.clear();
1332 storageChangeCBList.clear();
1333 threadChangeCBList.clear();
1334 reportMessageCBList.clear();
1338 void MsgProxyListener::insertOpenHandleSet(MsgHandle* pMsgHandle)
1340 MSG_DEBUG("try to insert opened handle. handle=[%p]", pMsgHandle);
1342 MsgMutexLocker lock(mx);
1344 handle_set::iterator it = openHandleSet.find(pMsgHandle);
1345 if (it == openHandleSet.end()) {
1346 openHandleSet.insert(pMsgHandle);
1347 MSG_DEBUG("New handle is added. current count = [%d]", openHandleSet.size());
1352 void MsgProxyListener::clearOpenHandleSet()
1354 MSG_DEBUG("clear opened handle set");
1355 openHandleSet.clear();
1358 #ifdef CHECK_SENT_STATUS_CALLBACK
1359 int MsgProxyListener::getSentStatusCbCnt()
1363 cbCnt = sentStatusCBList.size();
1365 MSG_DEBUG("registered sent status callback count : [%d]", cbCnt);