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 MsgSettingGetBool(VCONFKEY_MSG_SERVER_READY, &bReady);
33 MSG_INFO("Message Service Running State Changed bReady:(%d)", bReady);
35 /* bReady false indicates that server has restarted. Hence the proxylistener needs to be reset */
36 if (bReady == false) {
37 MSG_DEBUG("Message Service Is Restarted");
38 MsgProxyListener::instance()->resetProxyListener();
40 MSG_DEBUG("Message Service Is ready again. Refreshing ProxyListener");
41 MsgProxyListener::instance()->refreshProxyListener();
45 gboolean readSocket(GIOChannel *source, GIOCondition condition, gpointer data)
49 if ((G_IO_ERR & condition) || (G_IO_HUP & condition) || (G_IO_NVAL & condition)) {
50 MSG_DEBUG("IO condition Error!!! [%d]", condition);
52 MsgProxyListener::instance()->stop();
56 if (G_IO_ERR & condition) {
57 MSG_ERR("IO Error!!! [%d]", condition);
58 MsgProxyListener::instance()->clearProxyCBLists();
59 MsgProxyListener::instance()->clearOpenHandleSet();
63 if (G_IO_HUP & condition) {
64 MSG_ERR("socket fd Error!!! [%d]", condition);
65 MsgProxyListener::instance()->resetProxyListener();
69 if (G_IO_NVAL & condition) {
70 MSG_ERR("Invaild socket Error!!! [%d]", condition);
71 MsgProxyListener::instance()->clearProxyCBLists();
72 MsgProxyListener::instance()->clearOpenHandleSet();
77 unique_ptr<char*, void(*)(char**)> eventBuf(&buf, unique_ptr_deleter);
80 int n = MsgProxyListener::instance()->readFromSocket(&buf, &len);
83 MSG_DEBUG(">>Receiving %d bytes", n);
84 MsgProxyListener::instance()->handleEvent((MSG_EVENT_S*)buf);
86 MSG_WARN("Server closed connection");
88 } else /* dataSize < 0 */ {
89 MSG_DEBUG("Data is not for Listener");
98 /*==================================================================================================
99 IMPLEMENTATION OF MsgListenerThread - Member Functions
100 ==================================================================================================*/
101 MsgProxyListener* MsgProxyListener::pInstance = NULL;
104 MsgProxyListener::MsgProxyListener() : running(0)
107 clearOpenHandleSet();
108 MsgSettingRegVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
115 MsgProxyListener::~MsgProxyListener()
118 clearOpenHandleSet();
119 MsgSettingRemoveVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
123 MsgProxyListener* MsgProxyListener::instance()
126 MutexLocker lock(mm);
129 pInstance = new MsgProxyListener();
136 void MsgProxyListener::start(MsgHandle* pMsgHandle)
138 MutexLocker lock(mx);
140 this->insertOpenHandleSet(pMsgHandle);
143 cliSock.connect(MSG_SOCKET_PATH);
144 /* wake up the waiting thread */
147 int fd = cliSock.fd();
149 MSG_DEBUG("Socket Fd : %d", fd);
151 /* initializes ref_count = 1 */
152 channel = g_io_channel_unix_new(fd);
154 /* increments ref_count = 2 */
155 eventSourceId = g_io_add_watch(channel, (GIOCondition)(G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), &readSocket, NULL);
157 MSG_DEBUG("Call g_io_add_watch() : %d", eventSourceId);
161 MSG_DEBUG("add Listener and [%d] are running.", running);
165 void MsgProxyListener::stop()
169 MutexLocker lock(mx);
173 MSG_DEBUG("There are still running Listener. [%d] left.", running);
174 } else if (running == 1) {
176 g_io_channel_unref(channel);
180 if (eventSourceId > 0) {
181 g_source_remove(eventSourceId);
188 MSG_DEBUG("client Listener is terminated.");
195 bool MsgProxyListener::regSentStatusEventCB(MsgHandle* pMsgHandle, int fd, msg_sent_status_cb pfSentStatus, void *pUserParam)
197 MutexLocker lock(mx);
199 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
201 for (; it != sentStatusCBList.end(); it++) {
202 if (it->hAddr == pMsgHandle && it->pfSentStatusCB == pfSentStatus) {
204 MSG_DEBUG("msg_sent_status_cb() callback : [%p] is already registered!!!", pfSentStatus);
207 MSG_DEBUG("callback is registered by restarting server");
214 MSG_SENT_STATUS_CB_ITEM_S sentStatusCB = {pMsgHandle, fd, pfSentStatus, pUserParam};
216 sentStatusCBList.push_back(sentStatusCB);
222 bool MsgProxyListener::regMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_sms_incoming_cb pfNewMessage, int port, void *pUserParam)
224 MutexLocker lock(mx);
226 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it = newMessageCBList.begin();
228 for (; it != newMessageCBList.end(); it++) {
229 if (it->hAddr == pMsgHandle && it->port == port && it->pfIncomingCB == pfNewMessage) {
231 MSG_DEBUG("msg_sms_incoming_cb() callback : Port Number [%d] is already registered!!!", port);
234 MSG_DEBUG("callback is registered by restarting server");
241 MSG_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewMessage, port, pUserParam};
243 newMessageCBList.push_back(incomingCB);
249 bool MsgProxyListener::regMMSConfMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_mms_conf_msg_incoming_cb pfNewMMSConfMessage, const char *pAppId, void *pUserParam)
251 MutexLocker lock(mx);
253 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it = newMMSConfMessageCBList.begin();
255 for (; it != newMMSConfMessageCBList.end(); it++) {
256 if (it->hAddr == pMsgHandle && it->pfMMSConfIncomingCB == pfNewMMSConfMessage) {
258 if (pAppId == NULL) {
259 MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback is already registered!!!");
261 } else if (!strncmp(it->appId, pAppId, MAX_MMS_JAVA_APPID_LEN)) {
262 MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
266 MSG_DEBUG("callback is registered by restarting server");
273 MSG_MMS_CONF_INCOMING_CB_ITEM_S incomingConfCB = {pMsgHandle, fd, pfNewMMSConfMessage, {0}, pUserParam};
276 strncpy(incomingConfCB.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
278 newMMSConfMessageCBList.push_back(incomingConfCB);
284 bool MsgProxyListener::regPushMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_push_msg_incoming_cb pfNewPushMessage, const char *pAppId, void *pUserParam)
286 MutexLocker lock(mx);
288 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it = newPushMessageCBList.begin();
290 for (; it != newPushMessageCBList.end(); it++) {
291 if (it->hAddr == pMsgHandle && it->pfPushIncomingCB == pfNewPushMessage) {
293 if (pAppId == NULL) {
294 MSG_DEBUG("msg_push_msg_incoming_cb() callback is already registered!!!");
296 } else if (!strncmp(it->appId, pAppId, MAX_WAPPUSH_ID_LEN)) {
297 MSG_DEBUG("msg_push_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
301 MSG_DEBUG("callback is registered by restarting server");
308 MSG_PUSH_INCOMING_CB_ITEM_S incomingPushCB = {pMsgHandle, fd, pfNewPushMessage, {0}, pUserParam};
311 strncpy(incomingPushCB.appId, pAppId, MAX_WAPPUSH_ID_LEN);
313 newPushMessageCBList.push_back(incomingPushCB);
319 bool MsgProxyListener::regCBMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_cb_incoming_cb pfNewCBMessage, bool bSave, void *pUserParam)
321 MutexLocker lock(mx);
323 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it = newCBMessageCBList.begin();
325 for (; it != newCBMessageCBList.end(); it++) {
326 if (it->hAddr == pMsgHandle && it->pfCBIncomingCB == pfNewCBMessage) {
328 MSG_DEBUG("msg_CB_incoming_cb() callback : [%p] is already registered!!!", pfNewCBMessage);
330 it->userParam = pUserParam;
333 MSG_DEBUG("callback is registered by restarting server");
340 MSG_CB_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewCBMessage, bSave, pUserParam};
342 newCBMessageCBList.push_back(incomingCB);
348 bool MsgProxyListener::regReportMsgIncomingCB(MsgHandle* pMsgHandle, int fd, msg_report_msg_incoming_cb pfReportMessage, void *pUserParam)
350 MutexLocker lock(mx);
352 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it = reportMessageCBList.begin();
354 for (; it != reportMessageCBList.end(); it++) {
355 if (it->hAddr == pMsgHandle && it->pfReportMsgIncomingCB == pfReportMessage) {
357 MSG_DEBUG("msg_report_msg_incoming_cb() callback : [%p] is already registered!!!", pfReportMessage);
358 it->userParam = pUserParam;
361 MSG_DEBUG("callback is registered by restarting server");
368 MSG_REPORT_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfReportMessage, pUserParam};
370 reportMessageCBList.push_back(incomingCB);
376 bool MsgProxyListener::regSyncMLMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_incoming_cb pfNewSyncMLMessage, void *pUserParam)
378 MutexLocker lock(mx);
380 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it = newSyncMLMessageCBList.begin();
382 for (; it != newSyncMLMessageCBList.end(); it++) {
383 if (it->hAddr == pMsgHandle && it->pfSyncMLIncomingCB == pfNewSyncMLMessage) {
385 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewSyncMLMessage);
388 MSG_DEBUG("callback is registered by restarting server");
395 MSG_SYNCML_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewSyncMLMessage, pUserParam};
397 newSyncMLMessageCBList.push_back(incomingCB);
403 bool MsgProxyListener::regLBSMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_lbs_msg_incoming_cb pfNewLBSMsgIncoming, void *pUserParam)
405 MutexLocker lock(mx);
407 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it = newLBSMessageCBList.begin();
409 for (; it != newLBSMessageCBList.end(); it++) {
410 if (it->hAddr == pMsgHandle && it->pfLBSMsgIncoming == pfNewLBSMsgIncoming) {
412 MSG_DEBUG("msg_lbs_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewLBSMsgIncoming);
415 MSG_DEBUG("callback is registered by restarting server");
422 MSG_LBS_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewLBSMsgIncoming, pUserParam};
424 newLBSMessageCBList.push_back(incomingCB);
430 bool MsgProxyListener::regSyncMLMessageOperationEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_operation_cb pfSyncMLMessageOperation, void *pUserParam)
432 MutexLocker lock(mx);
434 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it = operationSyncMLMessageCBList.begin();
436 for (; it != operationSyncMLMessageCBList.end(); it++) {
437 if (it->hAddr == pMsgHandle && it->pfSyncMLOperationCB == pfSyncMLMessageOperation) {
439 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfSyncMLMessageOperation);
442 MSG_DEBUG("callback is registered by restarting server");
449 MSG_SYNCML_OPERATION_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfSyncMLMessageOperation, pUserParam};
451 operationSyncMLMessageCBList.push_back(incomingCB);
457 bool MsgProxyListener::regStorageChangeEventCB(MsgHandle* pMsgHandle, int fd, msg_storage_change_cb pfStorageChangeOperation, void *pUserParam)
459 MutexLocker lock(mx);
461 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it = storageChangeCBList.begin();
463 for (; it != storageChangeCBList.end(); it++) {
464 if (it->hAddr == pMsgHandle && it->pfStorageChangeCB == pfStorageChangeOperation) {
466 MSG_DEBUG("msg_storage_change_cb() callback : [%p] is already registered!!!", pfStorageChangeOperation);
469 MSG_DEBUG("callback is registered by restarting server");
476 MSG_STORAGE_CHANGE_CB_ITEM_S changeCB = {pMsgHandle, fd, pfStorageChangeOperation, pUserParam};
478 storageChangeCBList.push_back(changeCB);
484 void MsgProxyListener::clearListOfClosedHandle(MsgHandle* pMsgHandle)
488 MutexLocker lock(mx);
490 /* sent status CB list */
491 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
493 for (; it != sentStatusCBList.end(); ) {
494 if (it->hAddr == pMsgHandle) {
495 sentStatusCBList.erase(it++);
502 /* new message CB list */
503 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it2 = newMessageCBList.begin();
505 for (; it2 != newMessageCBList.end(); ) {
506 if (it2->hAddr == pMsgHandle) {
507 newMessageCBList.erase(it2++);
514 /* MMS conf Message CB list */
515 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it3 = newMMSConfMessageCBList.begin();
517 for (; it3 != newMMSConfMessageCBList.end(); ) {
518 if (it3->hAddr == pMsgHandle) {
519 newMMSConfMessageCBList.erase(it3++);
526 /* SyncML Message CB list */
527 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it4 = newSyncMLMessageCBList.begin();
529 for (; it4 != newSyncMLMessageCBList.end(); ) {
530 if (it4->hAddr == pMsgHandle) {
531 newSyncMLMessageCBList.erase(it4++);
538 /* LBS Message CB list */
539 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it5 = newLBSMessageCBList.begin();
541 for (; it5 != newLBSMessageCBList.end(); ) {
542 if (it5->hAddr == pMsgHandle) {
543 newLBSMessageCBList.erase(it5++);
550 /* Push Message CB list */
551 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it6 = newPushMessageCBList.begin();
553 for (; it6 != newPushMessageCBList.end(); ) {
554 if (it6->hAddr == pMsgHandle) {
555 newPushMessageCBList.erase(it6++);
562 /* CB Message CB list */
563 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it7 = newCBMessageCBList.begin();
565 for (; it7 != newCBMessageCBList.end(); ) {
566 if (it7->hAddr == pMsgHandle) {
567 newCBMessageCBList.erase(it7++);
574 /* Storage change Message CB list */
575 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it8 = storageChangeCBList.begin();
577 for (; it8 != storageChangeCBList.end(); ) {
578 if (it8->hAddr == pMsgHandle) {
579 storageChangeCBList.erase(it8++);
587 /* Report message incoming CB list */
588 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it9 = reportMessageCBList.begin();
589 for (; it9 != reportMessageCBList.end(); ) {
590 if (it9->hAddr == pMsgHandle) {
591 reportMessageCBList.erase(it9++);
599 /* SyncML Message Operation CB list */
600 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it10 = operationSyncMLMessageCBList.begin();
601 for (; it10 != operationSyncMLMessageCBList.end(); ) {
602 if (it10->hAddr == pMsgHandle) {
603 operationSyncMLMessageCBList.erase(it10++);
610 /* Open Handle Set */
611 openHandleSet.erase(pMsgHandle);
617 void MsgProxyListener::refreshListOfOpenedHandle(MsgHandle* pMsgHandle)
621 MutexLocker lock(mx);
623 /* sent status CB list */
624 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
625 for (; it != sentStatusCBList.end(); ++it) {
626 if (it->hAddr == pMsgHandle) {
627 it->fd = CUSTOM_SOCKET_ERROR;
629 pMsgHandle->regSentStatusCallback(it->pfSentStatusCB, it->userParam);
630 } catch (MsgException& e) {
631 MSG_FATAL("%s", e.what());
636 /* new message CB list */
637 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it2 = newMessageCBList.begin();
638 for (; it2 != newMessageCBList.end(); ++it2) {
639 if (it2->hAddr == pMsgHandle) {
640 it2->fd = CUSTOM_SOCKET_ERROR;
642 pMsgHandle->regSmsMessageCallback(it2->pfIncomingCB, it2->port, it2->userParam);
643 } catch (MsgException& e) {
644 MSG_FATAL("%s", e.what());
649 /* MMS conf Message CB list */
650 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it3 = newMMSConfMessageCBList.begin();
651 for (; it3 != newMMSConfMessageCBList.end(); ++it3) {
652 if (it3->hAddr == pMsgHandle) {
653 it3->fd = CUSTOM_SOCKET_ERROR;
655 pMsgHandle->regMmsConfMessageCallback(it3->pfMMSConfIncomingCB, it3->appId, it3->userParam);
656 } catch (MsgException& e) {
657 MSG_FATAL("%s", e.what());
662 /* SyncML Message CB list */
663 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it4 = newSyncMLMessageCBList.begin();
664 for (; it4 != newSyncMLMessageCBList.end(); ++it4) {
665 if (it4->hAddr == pMsgHandle) {
666 it4->fd = CUSTOM_SOCKET_ERROR;
668 pMsgHandle->regSyncMLMessageCallback(it4->pfSyncMLIncomingCB, it4->userParam);
669 } catch (MsgException& e) {
670 MSG_FATAL("%s", e.what());
675 /* LBS Message CB list */
676 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it5 = newLBSMessageCBList.begin();
677 for (; it5 != newLBSMessageCBList.end(); ++it5) {
678 if (it5->hAddr == pMsgHandle) {
679 it5->fd = CUSTOM_SOCKET_ERROR;
681 pMsgHandle->regLBSMessageCallback(it5->pfLBSMsgIncoming, it5->userParam);
682 } catch (MsgException& e) {
683 MSG_FATAL("%s", e.what());
688 /* Push Message CB list */
689 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it6 = newPushMessageCBList.begin();
690 for (; it6 != newPushMessageCBList.end(); ++it6) {
691 if (it6->hAddr == pMsgHandle) {
692 it6->fd = CUSTOM_SOCKET_ERROR;
694 pMsgHandle->regPushMessageCallback(it6->pfPushIncomingCB, it6->appId, it6->userParam);
695 } catch (MsgException& e) {
696 MSG_FATAL("%s", e.what());
701 /* CB Message CB list */
702 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it7 = newCBMessageCBList.begin();
703 for (; it7 != newCBMessageCBList.end(); ++it7) {
704 if (it7->hAddr == pMsgHandle) {
705 it7->fd = CUSTOM_SOCKET_ERROR;
707 pMsgHandle->regCBMessageCallback(it7->pfCBIncomingCB, it7->bsave, it7->userParam);
708 } catch (MsgException& e) {
709 MSG_FATAL("%s", e.what());
714 /* Storage change Message CB list */
715 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it8 = storageChangeCBList.begin();
716 for (; it8 != storageChangeCBList.end(); ++it8) {
717 if (it8->hAddr == pMsgHandle) {
718 it8->fd = CUSTOM_SOCKET_ERROR;
720 pMsgHandle->regStorageChangeCallback(it8->pfStorageChangeCB, it8->userParam);
721 } catch (MsgException& e) {
722 MSG_FATAL("%s", e.what());
727 /* Report message incoming CB list */
728 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it9 = reportMessageCBList.begin();
729 for (; it9 != reportMessageCBList.end(); ++it9) {
730 if (it9->hAddr == pMsgHandle) {
731 it9->fd = CUSTOM_SOCKET_ERROR;
733 pMsgHandle->regReportMessageCallback(it9->pfReportMsgIncomingCB, it9->userParam);
734 } catch (MsgException& e) {
735 MSG_FATAL("%s", e.what());
740 /* SyncML Message Operation CB list */
741 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it10 = operationSyncMLMessageCBList.begin();
742 for (; it10 != operationSyncMLMessageCBList.end(); ++it10) {
743 if (it10->hAddr == pMsgHandle) {
744 it10->fd = CUSTOM_SOCKET_ERROR;
746 pMsgHandle->regSyncMLMessageOperationCallback(it10->pfSyncMLOperationCB, it10->userParam);
747 } catch (MsgException& e) {
748 MSG_FATAL("%s", e.what());
757 void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
762 THROW(MsgException::INVALID_PARAM, "pMsgEvent is NULL");
764 if (pMsgEvent->eventType == MSG_EVENT_PLG_SENT_STATUS_CNF) {
765 unsigned int chInfo[3] = {0}; /*3 reqid, status, object */
767 memcpy(&chInfo, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(chInfo));
769 msg_struct_s status = {0, };
770 MSG_SENT_STATUS_S statusData = {(msg_request_id_t)chInfo[0], (msg_network_status_t)chInfo[1]};
772 status.type = MSG_STRUCT_SENT_STATUS_INFO;
773 status.data = (void *)&statusData;
777 MsgSentStatusCBList::iterator it = sentStatusCBList.begin();
779 for ( ; it != sentStatusCBList.end() ; it++) {
780 MsgHandle* pHandle = it->hAddr;
782 msg_sent_status_cb pfunc = it->pfSentStatusCB;
784 void* param = it->userParam;
786 pfunc((msg_handle_t)pHandle, (msg_struct_t)&status, param);
790 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MSG_IND) {
791 MSG_MESSAGE_INFO_S msgInfo;
792 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
794 msgInfo.addressList = NULL;
795 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
797 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
799 int portKey = (msgInfo.msgPort.valid)? msgInfo.msgPort.dstPort: 0;
803 MsgNewMessageCBList::iterator it = newMessageCBList.begin();
804 MsgNewMessageCBList matchList;
806 for ( ; it != newMessageCBList.end() ; it++) {
807 if (portKey == it->port) {
808 matchList.push_back(*it);
814 it = matchList.begin();
816 for ( ; it != matchList.end(); it++ ) {
817 MsgHandle* pHandle = it->hAddr;
819 MSG_MESSAGE_HIDDEN_S msgHidden = {0, };
821 msgHidden.pData = NULL;
822 msgHidden.pMmsData = NULL;
824 /* Allocate memory for address list of message */
825 msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
827 addr_list->nCount = 0;
828 addr_list->msg_struct_info = (msg_struct_t *)calloc(MAX_TO_ADDRESS_CNT, sizeof(MSG_ADDRESS_INFO_S *));
829 if (addr_list->msg_struct_info == NULL)
832 msg_struct_s *pTmp = NULL;
834 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
835 addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
836 pTmp = (msg_struct_s *)addr_list->msg_struct_info[i];
837 pTmp->type = MSG_STRUCT_ADDRESS_INFO;
838 pTmp->data = new MSG_ADDRESS_INFO_S;
839 memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
841 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
844 msgHidden.addr_list = addr_list;
847 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
849 catch (MsgException& e) {
850 MSG_FATAL("%s", e.what());
853 msg_struct_s msg = {0, };
854 msg.type = MSG_STRUCT_MESSAGE_INFO;
855 msg.data = &msgHidden;
857 msg_sms_incoming_cb pfunc = it->pfIncomingCB;
859 void* param = it->userParam;
861 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
863 delete [] (char*)msgHidden.pData;
864 if (msgHidden.pMmsData != NULL)
865 delete [] (char*)msgHidden.pMmsData;
867 /* address Memory Free */
868 if (msgHidden.addr_list!= NULL) {
869 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
870 msg_struct_s * addrInfo = (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
871 delete (MSG_ADDRESS_INFO_S *)addrInfo->data;
872 addrInfo->data = NULL;
873 delete (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
874 msgHidden.addr_list->msg_struct_info[i] = NULL;
877 g_free(msgHidden.addr_list->msg_struct_info);
879 delete msgHidden.addr_list;
880 msgHidden.addr_list = NULL;
884 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MMS_CONF) {
885 MSG_MESSAGE_INFO_S msgInfo;
886 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
888 msgInfo.addressList = NULL;
889 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
891 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
894 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
896 char* appIdKey = (pMmsRecvData->msgAppId.valid)? pMmsRecvData->msgAppId.appId: NULL;
900 MsgNewMMSConfMessageCBList::iterator it = newMMSConfMessageCBList.begin();
901 MsgNewMMSConfMessageCBList matchList;
903 for ( ; it != newMMSConfMessageCBList.end(); it++) {
905 if (!strcmp(appIdKey, it->appId))
906 matchList.push_back(*it);
908 /* (appIdKey == NULL && it->appId[0] == 0) */
909 if (it->appId[0] == 0)
910 matchList.push_back(*it);
916 /* Contents of msgData removed and replaced to retrievedFilePath for convertMsgStruct */
917 /* it is moved from UpdateMessage in MmsPluginStorage.cpp */
918 char tempFileName[MSG_FILENAME_LEN_MAX+1] = {0}; /* check MSG_FILENAME_LEN_MAX */
920 strncpy(tempFileName, pMmsRecvData->retrievedFilePath, MSG_FILENAME_LEN_MAX);
922 memset(msgInfo.msgData, 0, MAX_MSG_DATA_LEN+1);
923 memcpy(msgInfo.msgData, tempFileName + strlen(MSG_DATA_PATH), MAX_MSG_DATA_LEN);
925 it = matchList.begin();
927 for ( ; it != matchList.end(); it++) {
928 MsgHandle* pHandle = it->hAddr;
930 MSG_MESSAGE_HIDDEN_S msgHidden = {0, };
932 msgHidden.pData = NULL;
933 msgHidden.pMmsData = NULL;
935 /* Allocate memory for address list of message */
936 msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
938 addr_list->nCount = 0;
939 addr_list->msg_struct_info = (msg_struct_t *)calloc(MAX_TO_ADDRESS_CNT, sizeof(MSG_ADDRESS_INFO_S *));
940 if (addr_list->msg_struct_info == NULL)
943 msg_struct_s *pTmp = NULL;
945 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
946 addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
947 pTmp = (msg_struct_s *)addr_list->msg_struct_info[i];
948 pTmp->type = MSG_STRUCT_ADDRESS_INFO;
949 pTmp->data = new MSG_ADDRESS_INFO_S;
950 memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
952 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
955 msgHidden.addr_list = addr_list;
958 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
960 catch (MsgException& e) {
961 MSG_FATAL("%s", e.what());
964 msg_struct_s msg = {0, };
965 msg.type = MSG_STRUCT_MESSAGE_INFO;
966 msg.data = &msgHidden;
968 msg_mms_conf_msg_incoming_cb pfunc = it->pfMMSConfIncomingCB;
970 void* param = it->userParam;
971 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
973 delete [] (char*)msgHidden.pData;
974 if (msgHidden.pMmsData != NULL)
975 delete [] (char*)msgHidden.pMmsData;
977 /* address Memory Free */
978 if (msgHidden.addr_list != NULL) {
979 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
980 msg_struct_s * addrInfo = (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
981 delete (MSG_ADDRESS_INFO_S *)addrInfo->data;
982 addrInfo->data = NULL;
983 delete (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
984 msgHidden.addr_list->msg_struct_info[i] = NULL;
987 g_free(msgHidden.addr_list->msg_struct_info);
989 delete msgHidden.addr_list;
990 msgHidden.addr_list = NULL;
993 /* Here the retrieved message will be deleted from native storage. */
994 /* as of now, msg which have appId is considered as JAVA MMS message and it will be sent and handled in JAVA app. */
996 MSG_DEBUG("delete received JAVA MMS message:%s from native storage", tempFileName);
997 pHandle->deleteMessage(msgInfo.msgId);
1000 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND) {
1001 MSG_SYNCML_MESSAGE_DATA_S* pSyncMLData = (MSG_SYNCML_MESSAGE_DATA_S *)pMsgEvent->data;
1003 MSG_DEBUG("msgType [%d]", pSyncMLData->syncmlType);
1007 MsgNewSyncMLMessageCBList::iterator it = newSyncMLMessageCBList.begin();
1009 for ( ; it != newSyncMLMessageCBList.end(); it++) {
1010 MsgHandle* pHandle = it->hAddr;
1012 msg_syncml_msg_incoming_cb pfunc = it->pfSyncMLIncomingCB;
1014 void* param = it->userParam;
1016 pfunc((msg_handle_t)pHandle, pSyncMLData->syncmlType, pSyncMLData->pushBody, pSyncMLData->pushBodyLen, pSyncMLData->wspHeader, pSyncMLData->wspHeaderLen, pSyncMLData->simIndex, param);
1020 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_LBS_MSG_IND) {
1021 MSG_LBS_MESSAGE_DATA_S* pLBSData = (MSG_LBS_MESSAGE_DATA_S *)pMsgEvent->data;
1025 MsgNewLBSMessageCBList::iterator it = newLBSMessageCBList.begin();
1027 for ( ; it != newLBSMessageCBList.end(); it++) {
1028 MsgHandle* pHandle = it->hAddr;
1030 msg_lbs_msg_incoming_cb pfunc = it->pfLBSMsgIncoming;
1032 void* param = it->userParam;
1034 pfunc((msg_handle_t)pHandle, pLBSData->pushHeader, pLBSData->pushBody, pLBSData->pushBodyLen, param);
1038 } else if (pMsgEvent->eventType == MSG_EVENT_SYNCML_OPERATION) {
1042 memcpy(&msgId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
1043 memcpy(&extId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(int)), sizeof(int));
1045 MSG_DEBUG("msgId [%d]", msgId);
1046 MSG_DEBUG("extId [%d]", extId);
1050 MsgOperationSyncMLMessageCBList::iterator it = operationSyncMLMessageCBList.begin();
1052 for ( ; it != operationSyncMLMessageCBList.end(); it++) {
1053 MsgHandle* pHandle = it->hAddr;
1055 msg_syncml_msg_operation_cb pfunc = it->pfSyncMLOperationCB;
1057 void* param = it->userParam;
1059 pfunc((msg_handle_t)pHandle, msgId, extId, param);
1063 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_STORAGE_CHANGE_IND) {
1064 msg_storage_change_type_t storageChangeType;
1065 msg_id_list_s msgIdList;
1066 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
1068 /* Decode event data */
1069 memcpy(&storageChangeType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_storage_change_type_t));
1070 memcpy(&msgIdList.nCount, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_storage_change_type_t)), sizeof(int));
1072 if (msgIdList.nCount > 0)
1073 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));
1075 msgIdList.msgIdList = NULL;
1077 MSG_DEBUG("storageChangeType [%d], msgIdList.nCount [%d]", storageChangeType, msgIdList.nCount);
1081 MsgStorageChangeCBList::iterator it = storageChangeCBList.begin();
1083 for ( ; it != storageChangeCBList.end(); it++) {
1084 MsgHandle* pHandle = it->hAddr;
1086 msg_storage_change_cb pfunc = it->pfStorageChangeCB;
1088 void* param = it->userParam;
1090 pfunc((msg_handle_t)pHandle, storageChangeType, (msg_id_list_s*)&msgIdList, param);
1094 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_CB_MSG_IND) {
1095 MSG_CB_MSG_S *pCbMsg = (MSG_CB_MSG_S *)pMsgEvent->data;
1099 MsgNewCBMessageCBList::iterator it = newCBMessageCBList.begin();
1101 for ( ; it != newCBMessageCBList.end(); it++) {
1102 MsgHandle* pHandle = it->hAddr;
1103 msg_struct_s msg = {0, };
1105 msg.type = MSG_STRUCT_CB_MSG;
1108 msg_cb_incoming_cb pfunc = it->pfCBIncomingCB;
1110 void* param = it->userParam;
1112 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
1116 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND) {
1117 MSG_PUSH_MESSAGE_DATA_S* pPushData = (MSG_PUSH_MESSAGE_DATA_S *)pMsgEvent->data;
1121 MsgNewPushMessageCBList::iterator it = newPushMessageCBList.begin();
1123 for ( ; it != newPushMessageCBList.end(); it++) {
1124 MsgHandle* pHandle = it->hAddr;
1126 msg_push_msg_incoming_cb pfunc = it->pfPushIncomingCB;
1128 void* param = it->userParam;
1130 if (!strncmp(it->appId, pPushData->pushAppId, MAX_WAPPUSH_ID_LEN))
1131 pfunc((msg_handle_t)pHandle, pPushData->pushHeader, pPushData->pushBody, pPushData->pushBodyLen, param);
1135 } else if (pMsgEvent->eventType == MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND) {
1136 msg_report_type_t reportType;
1137 msg_message_id_t msgId;
1141 /* Decode event data */
1142 memcpy(&reportType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_report_type_t));
1143 memcpy(&msgId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_report_type_t)), sizeof(msg_message_id_t));
1144 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));
1145 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));
1146 addr_val[addr_len] = '\0';
1148 MSG_SEC_DEBUG("reportType [%d], msgId [%d], Address Length [%d], Address Value [%s]", reportType, msgId, addr_len, addr_val);
1152 MsgReportMessageCBList::iterator it = reportMessageCBList.begin();
1154 for ( ; it != reportMessageCBList.end(); it++) {
1155 MsgHandle* pHandle = it->hAddr;
1157 msg_report_msg_incoming_cb pfunc = it->pfReportMsgIncomingCB;
1159 void* param = it->userParam;
1161 pfunc((msg_handle_t)pHandle, reportType, msgId, addr_len, addr_val, param);
1171 int MsgProxyListener::getRemoteFd()
1173 return cliSock.getRemoteFd();
1177 int MsgProxyListener::readFromSocket(char** buf, unsigned int* len)
1179 return cliSock.read(buf, len);
1183 void MsgProxyListener::resetProxyListener()
1185 MSG_DEBUG("client Listener reset");
1186 MutexLocker lock(mx);
1189 g_io_channel_unref(channel);
1193 if (eventSourceId > 0) {
1194 g_source_remove(eventSourceId);
1202 handle_set::iterator it = openHandleSet.begin();
1203 for (; it != openHandleSet.end(); it++) {
1204 MSG_DEBUG("disconnect socket for opened handle [%p]", it);
1205 MsgHandle *handle = (MsgHandle *)*it;
1206 handle->disconnectSocket();
1211 void MsgProxyListener::refreshProxyListener()
1213 MSG_DEBUG("refresh proxy listener");
1214 MutexLocker lock(mx);
1216 handle_set::iterator it = openHandleSet.begin();
1217 for (; it != openHandleSet.end(); it++) {
1218 MsgHandle *handle = (MsgHandle *)*it;
1219 handle->openHandle();
1220 refreshListOfOpenedHandle(handle);
1225 void MsgProxyListener::clearProxyCBLists()
1227 MSG_DEBUG("clear proxy callback list");
1229 sentStatusCBList.clear();
1230 newMessageCBList.clear();
1231 newMMSConfMessageCBList.clear();
1232 newSyncMLMessageCBList.clear();
1233 newLBSMessageCBList.clear();
1234 newPushMessageCBList.clear();
1235 newCBMessageCBList.clear();
1236 newSyncMLMessageCBList.clear();
1237 storageChangeCBList.clear();
1238 reportMessageCBList.clear();
1242 void MsgProxyListener::insertOpenHandleSet(MsgHandle* pMsgHandle)
1244 MSG_DEBUG("try to insert opened handle. handle=[%p]", pMsgHandle);
1246 MutexLocker lock(mx);
1248 handle_set::iterator it = openHandleSet.find(pMsgHandle);
1249 if (it == openHandleSet.end()) {
1250 openHandleSet.insert(pMsgHandle);
1251 MSG_DEBUG("New handle is added. current count = [%d]", openHandleSet.size());
1256 void MsgProxyListener::clearOpenHandleSet()
1258 MSG_DEBUG("clear opened handle set");
1259 openHandleSet.clear();
1262 #ifdef CHECK_SENT_STATUS_CALLBACK
1263 int MsgProxyListener::getSentStatusCbCnt()
1267 cbCnt = sentStatusCBList.size();
1269 MSG_DEBUG("registered sent status callback count : [%d]", cbCnt);