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. Resetting ProxyListener");
38 MsgProxyListener::instance()->resetProxyListener();
42 gboolean readSocket(GIOChannel *source, GIOCondition condition, gpointer data)
46 if ((G_IO_ERR & condition) || (G_IO_HUP & condition) || (G_IO_NVAL & condition))
48 MSG_DEBUG("IO condition Error!!! [%d]", condition);
50 MsgProxyListener::instance()->stop();
54 if (G_IO_ERR & condition)
56 MSG_ERR("IO Error!!! [%d]", condition);
58 MsgProxyListener::instance()->stop();
62 if (G_IO_HUP & condition)
64 MSG_ERR("socket fd Error!!! [%d]", condition);
66 MsgProxyListener::instance()->stop();
70 if (G_IO_NVAL & condition)
72 MSG_ERR("Invaild socket Error!!! [%d]", condition);
74 MsgProxyListener::instance()->stop();
79 unique_ptr<char*, void(*)(char**)> eventBuf(&buf, unique_ptr_deleter);
82 int n = MsgProxyListener::instance()->readFromSocket(&buf, &len);
86 MSG_DEBUG(">>Receiving %d bytes", n);
87 MsgProxyListener::instance()->handleEvent((MSG_EVENT_S*)buf);
91 MSG_WARN("Server closed connection");
92 MsgProxyListener::instance()->stop();
97 MSG_DEBUG("Data is not for Listener");
106 /*==================================================================================================
107 IMPLEMENTATION OF MsgListenerThread - Member Functions
108 ==================================================================================================*/
109 MsgProxyListener* MsgProxyListener::pInstance = NULL;
112 MsgProxyListener::MsgProxyListener() : running(0)
114 sentStatusCBList.clear();
115 newMessageCBList.clear();
116 newMMSConfMessageCBList.clear();
117 newSyncMLMessageCBList.clear();
118 newLBSMessageCBList.clear();
119 openHandleSet.clear();
120 MsgSettingRegVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
127 MsgProxyListener::~MsgProxyListener()
129 sentStatusCBList.clear();
130 newMessageCBList.clear();
131 newMMSConfMessageCBList.clear();
132 newSyncMLMessageCBList.clear();
133 newLBSMessageCBList.clear();
134 openHandleSet.clear();
135 MsgSettingRemoveVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
139 MsgProxyListener* MsgProxyListener::instance()
142 MutexLocker lock(mm);
145 pInstance = new MsgProxyListener();
152 void MsgProxyListener::start(MsgHandle* pMsgHandle)
154 MutexLocker lock(mx);
156 handle_set::iterator it = openHandleSet.find(pMsgHandle);
157 if (it == openHandleSet.end())
158 openHandleSet.insert(pMsgHandle);
161 cliSock.connect(MSG_SOCKET_PATH);
162 cv.signal(); // wake up the waiting thread
164 int fd = cliSock.fd();
166 MSG_DEBUG("Socket Fd : %d", fd);
168 channel = g_io_channel_unix_new(fd); // initializes ref_count = 1
170 eventSourceId = g_io_add_watch(channel, (GIOCondition)(G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), &readSocket, NULL); // increments ref_count =2
172 MSG_DEBUG("Call g_io_add_watch() : %d", eventSourceId);
176 MSG_DEBUG("add Listener and [%d] are running.", running);
180 void MsgProxyListener::stop()
187 MSG_DEBUG("There are still running Listener. [%d] left.", running);
189 else if (running == 1)
193 g_io_channel_unref(channel); // decrements ref_count = 1
195 g_source_remove(eventSourceId);
199 MSG_DEBUG("client Listener is terminated.");
206 bool MsgProxyListener::regSentStatusEventCB(MsgHandle* pMsgHandle, msg_sent_status_cb pfSentStatus, void *pUserParam)
208 MutexLocker lock(mx);
210 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
212 for (; it != sentStatusCBList.end(); it++)
214 if (it->hAddr == pMsgHandle && it->pfSentStatusCB == pfSentStatus) {
215 MSG_DEBUG("msg_sent_status_cb() callback : [%p] is already registered!!!", pfSentStatus);
220 MSG_SENT_STATUS_CB_ITEM_S sentStatusCB = {pMsgHandle, pfSentStatus, pUserParam};
222 sentStatusCBList.push_back(sentStatusCB);
228 bool MsgProxyListener::regMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_sms_incoming_cb pfNewMessage, int port, void *pUserParam)
230 MutexLocker lock(mx);
232 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it = newMessageCBList.begin();
234 for (; it != newMessageCBList.end(); it++)
236 if (it->hAddr == pMsgHandle && it->port == port && it->pfIncomingCB == pfNewMessage) {
237 MSG_DEBUG("msg_sms_incoming_cb() callback : Port Number [%d] is already registered!!!", port);
242 MSG_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, pfNewMessage, port, pUserParam};
244 newMessageCBList.push_back(incomingCB);
250 bool MsgProxyListener::regMMSConfMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_mms_conf_msg_incoming_cb pfNewMMSConfMessage, const char *pAppId, void *pUserParam)
252 MutexLocker lock(mx);
254 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it = newMMSConfMessageCBList.begin();
256 for (; it != newMMSConfMessageCBList.end(); it++)
258 if (it->hAddr == pMsgHandle && it->pfMMSConfIncomingCB == pfNewMMSConfMessage) {
261 MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback is already registered!!!");
263 } else if(!strncmp(it->appId, pAppId, MAX_MMS_JAVA_APPID_LEN)) {
264 MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
270 MSG_MMS_CONF_INCOMING_CB_ITEM_S incomingConfCB = {pMsgHandle, pfNewMMSConfMessage, {0}, pUserParam};
273 strncpy(incomingConfCB.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
275 newMMSConfMessageCBList.push_back(incomingConfCB);
281 bool MsgProxyListener::regPushMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_push_msg_incoming_cb pfNewPushMessage, const char *pAppId, void *pUserParam)
283 MutexLocker lock(mx);
285 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it = newPushMessageCBList.begin();
287 for (; it != newPushMessageCBList.end(); it++)
289 if (it->hAddr == pMsgHandle && it->pfPushIncomingCB == pfNewPushMessage) {
292 MSG_DEBUG("msg_push_msg_incoming_cb() callback is already registered!!!");
294 } else if(!strncmp(it->appId, pAppId, MAX_WAPPUSH_ID_LEN)) {
295 MSG_DEBUG("msg_push_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
301 MSG_PUSH_INCOMING_CB_ITEM_S incomingPushCB = {pMsgHandle, pfNewPushMessage, {0}, pUserParam};
304 strncpy(incomingPushCB.appId, pAppId, MAX_WAPPUSH_ID_LEN);
306 newPushMessageCBList.push_back(incomingPushCB);
311 bool MsgProxyListener::regCBMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_cb_incoming_cb pfNewCBMessage, bool bSave, void *pUserParam)
313 MutexLocker lock(mx);
315 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it = newCBMessageCBList.begin();
317 for (; it != newCBMessageCBList.end(); it++)
319 if (it->hAddr == pMsgHandle && it->pfCBIncomingCB == pfNewCBMessage) {
320 MSG_DEBUG("msg_CB_incoming_cb() callback : [%p] is already registered!!!", pfNewCBMessage);
322 it->userParam = pUserParam;
327 MSG_CB_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, pfNewCBMessage, bSave, pUserParam};
329 newCBMessageCBList.push_back(incomingCB);
335 bool MsgProxyListener::regReportMsgIncomingCB(MsgHandle* pMsgHandle, msg_report_msg_incoming_cb pfReportMessage, void *pUserParam)
337 MutexLocker lock(mx);
339 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it = reportMessageCBList.begin();
341 for (; it != reportMessageCBList.end(); it++)
343 if (it->hAddr == pMsgHandle && it->pfReportMsgIncomingCB == pfReportMessage) {
344 MSG_DEBUG("msg_report_msg_incoming_cb() callback : [%p] is already registered!!!", pfReportMessage);
345 it->userParam = pUserParam;
350 MSG_REPORT_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, pfReportMessage, pUserParam};
352 reportMessageCBList.push_back(incomingCB);
358 bool MsgProxyListener::regSyncMLMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_syncml_msg_incoming_cb pfNewSyncMLMessage, void *pUserParam)
360 MutexLocker lock(mx);
362 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it = newSyncMLMessageCBList.begin();
364 for (; it != newSyncMLMessageCBList.end(); it++)
366 if (it->hAddr == pMsgHandle && it->pfSyncMLIncomingCB == pfNewSyncMLMessage) {
367 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewSyncMLMessage);
372 MSG_SYNCML_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, pfNewSyncMLMessage, pUserParam};
374 newSyncMLMessageCBList.push_back(incomingCB);
380 bool MsgProxyListener::regLBSMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_lbs_msg_incoming_cb pfNewLBSMsgIncoming, void *pUserParam)
382 MutexLocker lock(mx);
384 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it = newLBSMessageCBList.begin();
386 for (; it != newLBSMessageCBList.end(); it++)
388 if (it->hAddr == pMsgHandle && it->pfLBSMsgIncoming == pfNewLBSMsgIncoming) {
389 MSG_DEBUG("msg_lbs_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewLBSMsgIncoming);
394 MSG_LBS_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, pfNewLBSMsgIncoming, pUserParam};
396 newLBSMessageCBList.push_back(incomingCB);
402 bool MsgProxyListener::regSyncMLMessageOperationEventCB(MsgHandle* pMsgHandle, msg_syncml_msg_operation_cb pfSyncMLMessageOperation, void *pUserParam)
404 MutexLocker lock(mx);
406 std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it = operationSyncMLMessageCBList.begin();
408 for (; it != operationSyncMLMessageCBList.end(); it++)
410 if (it->hAddr == pMsgHandle && it->pfSyncMLOperationCB == pfSyncMLMessageOperation) {
411 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfSyncMLMessageOperation);
416 MSG_SYNCML_OPERATION_CB_ITEM_S incomingCB = {pMsgHandle, pfSyncMLMessageOperation, pUserParam};
418 operationSyncMLMessageCBList.push_back(incomingCB);
424 bool MsgProxyListener::regStorageChangeEventCB(MsgHandle* pMsgHandle, msg_storage_change_cb pfStorageChangeOperation, void *pUserParam)
426 MutexLocker lock(mx);
428 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it = storageChangeCBList.begin();
430 for (; it != storageChangeCBList.end(); it++)
432 if (it->hAddr == pMsgHandle && it->pfStorageChangeCB == pfStorageChangeOperation) {
433 MSG_DEBUG("msg_storage_change_cb() callback : [%p] is already registered!!!", pfStorageChangeOperation);
438 MSG_STORAGE_CHANGE_CB_ITEM_S changeCB = {pMsgHandle, pfStorageChangeOperation, pUserParam};
440 storageChangeCBList.push_back(changeCB);
446 void MsgProxyListener::clearListOfClosedHandle(MsgHandle* pMsgHandle)
450 MutexLocker lock(mx);
452 // sent status CB list
453 std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
455 for (; it != sentStatusCBList.end(); )
457 if (it->hAddr == pMsgHandle)
459 sentStatusCBList.erase(it++);
461 //Stop client Listener
468 // new message CB list
469 std::list<MSG_INCOMING_CB_ITEM_S>::iterator it2 = newMessageCBList.begin();
471 for (; it2 != newMessageCBList.end(); )
473 if (it2->hAddr == pMsgHandle)
475 newMessageCBList.erase(it2++);
477 //Stop client Listener
484 // MMS conf Message CB list
485 std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it3 = newMMSConfMessageCBList.begin();
487 for (; it3 != newMMSConfMessageCBList.end(); )
489 if (it3->hAddr == pMsgHandle)
491 newMMSConfMessageCBList.erase(it3++);
493 //Stop client Listener
500 // SyncML Message CB list
501 std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it4 = newSyncMLMessageCBList.begin();
503 for (; it4 != newSyncMLMessageCBList.end(); )
505 if (it4->hAddr == pMsgHandle)
507 newSyncMLMessageCBList.erase(it4++);
509 //Stop client Listener
516 // LBS Message CB list
517 std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it5 = newLBSMessageCBList.begin();
519 for (; it5 != newLBSMessageCBList.end(); )
521 if (it5->hAddr == pMsgHandle)
523 newLBSMessageCBList.erase(it5++);
525 //Stop client Listener
532 // Push Message CB list
533 std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it6 = newPushMessageCBList.begin();
535 for (; it6 != newPushMessageCBList.end(); )
537 if (it6->hAddr == pMsgHandle)
539 newPushMessageCBList.erase(it6++);
541 //Stop client Listener
549 // CB Message CB list
550 std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it7 = newCBMessageCBList.begin();
552 for (; it7 != newCBMessageCBList.end(); )
555 if (it7->hAddr == pMsgHandle)
558 newCBMessageCBList.erase(it7++);
560 //Stop client Listener
569 // Storage change Message CB list
570 std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it8 = storageChangeCBList.begin();
572 for (; it8 != storageChangeCBList.end(); )
574 if (it8->hAddr == pMsgHandle)
576 storageChangeCBList.erase(it8++);
578 //Stop client Listener
586 // Report message incoming CB list
587 std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it9 = reportMessageCBList.begin();
588 for (; it9 != reportMessageCBList.end(); )
590 if (it9->hAddr == pMsgHandle)
592 reportMessageCBList.erase(it9++);
594 //Stop client Listener
605 void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
610 THROW(MsgException::INVALID_PARAM, "pMsgEvent is NULL");
612 if (pMsgEvent->eventType == MSG_EVENT_PLG_SENT_STATUS_CNF)
614 unsigned int chInfo[3] = {0}; //3// reqid, status, object
616 memcpy(&chInfo, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(chInfo));
618 msg_struct_s status = {0,};
619 MSG_SENT_STATUS_S statusData = {(msg_request_id_t)chInfo[0], (msg_network_status_t)chInfo[1]};
621 status.type = MSG_STRUCT_SENT_STATUS_INFO;
622 status.data = (void *)&statusData;
626 MsgSentStatusCBList::iterator it = sentStatusCBList.begin();
628 for( ; it != sentStatusCBList.end() ; it++)
630 MsgHandle* pHandle = it->hAddr;
632 msg_sent_status_cb pfunc = it->pfSentStatusCB;
634 void* param = it->userParam;
636 pfunc((msg_handle_t)pHandle, (msg_struct_t)&status, param);
641 else if ( pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MSG_IND )
643 MSG_MESSAGE_INFO_S msgInfo;
644 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
646 msgInfo.addressList = NULL;
647 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
649 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
651 int portKey = (msgInfo.msgPort.valid)? msgInfo.msgPort.dstPort: 0;
655 MsgNewMessageCBList::iterator it = newMessageCBList.begin();
656 MsgNewMessageCBList matchList;
658 for( ; it != newMessageCBList.end() ; it++)
660 if( portKey == it->port)
662 matchList.push_back(*it);
668 it = matchList.begin();
670 for( ; it != matchList.end(); it++ )
672 MsgHandle* pHandle = it->hAddr;
674 MSG_MESSAGE_HIDDEN_S msgHidden = {0,};
676 msgHidden.pData = NULL;
677 msgHidden.pMmsData = NULL;
679 /* Allocate memory for address list of message */
680 msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
682 addr_list->nCount = 0;
683 addr_list->msg_struct_info = (msg_struct_t *)calloc(MAX_TO_ADDRESS_CNT, sizeof(MSG_ADDRESS_INFO_S *));
684 if (addr_list->msg_struct_info == NULL)
687 msg_struct_s *pTmp = NULL;
689 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
690 addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
691 pTmp = (msg_struct_s *)addr_list->msg_struct_info[i];
692 pTmp->type = MSG_STRUCT_ADDRESS_INFO;
693 pTmp->data = new MSG_ADDRESS_INFO_S;
694 memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
696 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
699 msgHidden.addr_list = addr_list;
702 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
704 catch (MsgException& e) {
705 MSG_FATAL("%s", e.what());
708 msg_struct_s msg = {0,};
709 msg.type = MSG_STRUCT_MESSAGE_INFO;
710 msg.data = &msgHidden;
712 msg_sms_incoming_cb pfunc = it->pfIncomingCB;
714 void* param = it->userParam;
716 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
718 delete [] (char*)msgHidden.pData;
719 if (msgHidden.pMmsData != NULL)
720 delete [] (char*)msgHidden.pMmsData;
722 // address Memory Free
723 if (msgHidden.addr_list!= NULL)
725 for(int i=0; i<MAX_TO_ADDRESS_CNT; i++) {
726 msg_struct_s * addrInfo = (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
727 delete (MSG_ADDRESS_INFO_S *)addrInfo->data;
728 addrInfo->data = NULL;
729 delete (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
730 msgHidden.addr_list->msg_struct_info[i] = NULL;
733 g_free(msgHidden.addr_list->msg_struct_info);
735 delete msgHidden.addr_list;
736 msgHidden.addr_list = NULL;
742 else if ( pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MMS_CONF )
744 MSG_MESSAGE_INFO_S msgInfo;
745 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
747 msgInfo.addressList = NULL;
748 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
750 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
753 MMS_RECV_DATA_S* pMmsRecvData = ( MMS_RECV_DATA_S*)msgInfo.msgData;
755 char* appIdKey = (pMmsRecvData->msgAppId.valid)? pMmsRecvData->msgAppId.appId: NULL;
759 MsgNewMMSConfMessageCBList::iterator it = newMMSConfMessageCBList.begin();
760 MsgNewMMSConfMessageCBList matchList;
762 for( ; it != newMMSConfMessageCBList.end() ; it++)
766 if(!strcmp(appIdKey, it->appId))
767 matchList.push_back(*it);
769 else//(appIdKey == NULL && it->appId[0] == 0)
771 if(it->appId[0] == 0)
772 matchList.push_back(*it);
778 // Contents of msgData removed and replaced to retrievedFilePath for convertMsgStruct
779 // it is moved from UpdateMessage in MmsPluginStorage.cpp
780 char tempFileName[MSG_FILENAME_LEN_MAX+1] = {0}; // check MSG_FILENAME_LEN_MAX
782 strncpy(tempFileName, pMmsRecvData->retrievedFilePath, MSG_FILENAME_LEN_MAX);
784 memset(msgInfo.msgData, 0, MAX_MSG_DATA_LEN+1);
785 memcpy(msgInfo.msgData, tempFileName + strlen(MSG_DATA_PATH), MAX_MSG_DATA_LEN);
787 it = matchList.begin();
789 for( ; it != matchList.end() ; it++)
791 MsgHandle* pHandle = it->hAddr;
793 MSG_MESSAGE_HIDDEN_S msgHidden = {0,};
795 msgHidden.pData = NULL;
796 msgHidden.pMmsData = NULL;
798 /* Allocate memory for address list of message */
799 msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
801 addr_list->nCount = 0;
802 addr_list->msg_struct_info = (msg_struct_t *)calloc(MAX_TO_ADDRESS_CNT, sizeof(MSG_ADDRESS_INFO_S *));
803 if (addr_list->msg_struct_info == NULL)
806 msg_struct_s *pTmp = NULL;
808 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
809 addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
810 pTmp = (msg_struct_s *)addr_list->msg_struct_info[i];
811 pTmp->type = MSG_STRUCT_ADDRESS_INFO;
812 pTmp->data = new MSG_ADDRESS_INFO_S;
813 memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
815 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
818 msgHidden.addr_list = addr_list;
821 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
823 catch (MsgException& e) {
824 MSG_FATAL("%s", e.what());
827 msg_struct_s msg = {0,};
828 msg.type = MSG_STRUCT_MESSAGE_INFO;
829 msg.data = &msgHidden;
831 msg_mms_conf_msg_incoming_cb pfunc = it->pfMMSConfIncomingCB;
833 void* param = it->userParam;
834 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
836 delete [] (char*)msgHidden.pData;
837 if (msgHidden.pMmsData != NULL)
838 delete [] (char*)msgHidden.pMmsData;
840 // address Memory Free
841 if (msgHidden.addr_list != NULL)
843 for(int i=0; i<MAX_TO_ADDRESS_CNT; i++) {
844 msg_struct_s * addrInfo = (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
845 delete (MSG_ADDRESS_INFO_S *)addrInfo->data;
846 addrInfo->data = NULL;
847 delete (msg_struct_s *)msgHidden.addr_list->msg_struct_info[i];
848 msgHidden.addr_list->msg_struct_info[i] = NULL;
851 g_free(msgHidden.addr_list->msg_struct_info);
853 delete msgHidden.addr_list;
854 msgHidden.addr_list = NULL;
857 // Here the retrieved message will be deleted from native storage.
858 // as of now, msg which have appId is considered as JAVA MMS message and it will be sent and handled in JAVA app.
861 MSG_DEBUG("delete received JAVA MMS message:%s from native storage",tempFileName);
862 pHandle->deleteMessage(msgInfo.msgId);
866 else if ( pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND )
868 MSG_SYNCML_MESSAGE_DATA_S* pSyncMLData = (MSG_SYNCML_MESSAGE_DATA_S *)pMsgEvent->data;
870 MSG_DEBUG("msgType [%d]", pSyncMLData->syncmlType);
874 MsgNewSyncMLMessageCBList::iterator it = newSyncMLMessageCBList.begin();
876 for( ; it != newSyncMLMessageCBList.end() ; it++)
878 MsgHandle* pHandle = it->hAddr;
880 msg_syncml_msg_incoming_cb pfunc = it->pfSyncMLIncomingCB;
882 void* param = it->userParam;
884 pfunc((msg_handle_t)pHandle, pSyncMLData->syncmlType, pSyncMLData->pushBody, pSyncMLData->pushBodyLen, pSyncMLData->wspHeader, pSyncMLData->wspHeaderLen, pSyncMLData->simIndex, param);
889 else if ( pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_LBS_MSG_IND )
891 MSG_LBS_MESSAGE_DATA_S* pLBSData = (MSG_LBS_MESSAGE_DATA_S *)pMsgEvent->data;
895 MsgNewLBSMessageCBList::iterator it = newLBSMessageCBList.begin();
897 for( ; it != newLBSMessageCBList.end() ; it++)
899 MsgHandle* pHandle = it->hAddr;
901 msg_lbs_msg_incoming_cb pfunc = it->pfLBSMsgIncoming;
903 void* param = it->userParam;
905 pfunc((msg_handle_t)pHandle, pLBSData->pushHeader, pLBSData->pushBody, pLBSData->pushBodyLen, param);
910 else if ( pMsgEvent->eventType == MSG_EVENT_SYNCML_OPERATION )
915 memcpy(&msgId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
916 memcpy(&extId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(int)), sizeof(int));
918 MSG_DEBUG("msgId [%d]", msgId);
919 MSG_DEBUG("extId [%d]", extId);
923 MsgOperationSyncMLMessageCBList::iterator it = operationSyncMLMessageCBList.begin();
925 for( ; it != operationSyncMLMessageCBList.end() ; it++)
927 MsgHandle* pHandle = it->hAddr;
929 msg_syncml_msg_operation_cb pfunc = it->pfSyncMLOperationCB;
931 void* param = it->userParam;
933 pfunc((msg_handle_t)pHandle, msgId, extId, param);
938 else if (pMsgEvent->eventType == MSG_EVENT_PLG_STORAGE_CHANGE_IND)
940 msg_storage_change_type_t storageChangeType;
941 msg_id_list_s msgIdList;
942 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
945 memcpy(&storageChangeType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_storage_change_type_t));
946 memcpy(&msgIdList.nCount, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_storage_change_type_t)), sizeof(int));
948 if(msgIdList.nCount > 0)
949 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));
951 msgIdList.msgIdList = NULL;
953 MSG_DEBUG("storageChangeType [%d], msgIdList.nCount [%d]", storageChangeType, msgIdList.nCount);
957 MsgStorageChangeCBList::iterator it = storageChangeCBList.begin();
959 for( ; it != storageChangeCBList.end() ; it++)
961 MsgHandle* pHandle = it->hAddr;
963 msg_storage_change_cb pfunc = it->pfStorageChangeCB;
965 void* param = it->userParam;
967 pfunc((msg_handle_t)pHandle, storageChangeType, (msg_id_list_s*)&msgIdList, param);
973 else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_CB_MSG_IND)
975 MSG_CB_MSG_S *pCbMsg = (MSG_CB_MSG_S *)pMsgEvent->data;
979 MsgNewCBMessageCBList::iterator it = newCBMessageCBList.begin();
981 for( ; it != newCBMessageCBList.end() ; it++)
983 MsgHandle* pHandle = it->hAddr;
984 msg_struct_s msg = {0,};
986 msg.type = MSG_STRUCT_CB_MSG;
989 msg_cb_incoming_cb pfunc = it->pfCBIncomingCB;
991 void* param = it->userParam;
993 pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
999 else if ( pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND )
1001 MSG_PUSH_MESSAGE_DATA_S* pPushData = (MSG_PUSH_MESSAGE_DATA_S *)pMsgEvent->data;
1005 MsgNewPushMessageCBList::iterator it = newPushMessageCBList.begin();
1007 for( ; it != newPushMessageCBList.end() ; it++)
1009 MsgHandle* pHandle = it->hAddr;
1011 msg_push_msg_incoming_cb pfunc = it->pfPushIncomingCB;
1013 void* param = it->userParam;
1015 if(!strncmp(it->appId, pPushData->pushAppId, MAX_WAPPUSH_ID_LEN))
1016 pfunc((msg_handle_t)pHandle, pPushData->pushHeader, pPushData->pushBody, pPushData->pushBodyLen, param);
1022 else if (pMsgEvent->eventType == MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND)
1024 msg_report_type_t reportType;
1025 msg_message_id_t msgId;
1029 // Decode event data
1030 memcpy(&reportType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_report_type_t));
1031 memcpy(&msgId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_report_type_t)), sizeof(msg_message_id_t));
1032 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));
1033 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));
1034 addr_val[addr_len] = '\0';
1036 MSG_SEC_DEBUG("reportType [%d], msgId [%d], Address Length [%d], Address Value [%s]", reportType, msgId, addr_len, addr_val);
1040 MsgReportMessageCBList::iterator it = reportMessageCBList.begin();
1042 for( ; it != reportMessageCBList.end() ; it++)
1044 MsgHandle* pHandle = it->hAddr;
1046 msg_report_msg_incoming_cb pfunc = it->pfReportMsgIncomingCB;
1048 void* param = it->userParam;
1050 pfunc((msg_handle_t)pHandle, reportType, msgId, addr_len, addr_val, param);
1060 int MsgProxyListener::getRemoteFd()
1063 //MutexLocker lock(mx);
1066 int ret = mx.timedlock();
1069 MSG_DEBUG("mx.timedlock fail [%d]", ret);
1073 tmpFd = cliSock.getRemoteFd();
1075 MSG_DEBUG("listener fd [%d]", tmpFd);
1078 ret = cv.timedwait(mx.pMutex(),1);
1081 if (ret == ETIMEDOUT) {
1082 MSG_DEBUG("get listener fd TIME-OUT");
1087 tmpFd = cliSock.getRemoteFd();
1096 int MsgProxyListener::readFromSocket(char** buf, unsigned int* len)
1098 return cliSock.read(buf, len);
1101 void MsgProxyListener::resetProxyListener()
1104 MutexLocker lock(mx);
1105 handle_set::iterator it = openHandleSet.begin();
1106 for (; it != openHandleSet.end(); it++) {
1107 MsgHandle *handle = (MsgHandle *)*it;
1108 clearListOfClosedHandle(handle);
1110 openHandleSet.clear();
1114 #ifdef CHECK_SENT_STATUS_CALLBACK
1115 int MsgProxyListener::getSentStatusCbCnt()
1119 cbCnt = sentStatusCBList.size();
1121 MSG_DEBUG("registered sent status callback count : [%d]", cbCnt);