modify code to get contact info on proxy side for search_msg and get_message_list
[platform/core/messaging/msg-service.git] / proxy / MsgProxyListener.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15 */
16
17 #include <errno.h>
18
19 #include "MsgDebug.h"
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
22 #include "MsgUtilFunction.h"
23 #include "MsgUtilFile.h"
24 #include "MsgProxyListener.h"
25 #include "MsgGconfWrapper.h"
26
27 void MsgServerRestartCb(keynode_t *key, void* data)
28 {
29         bool bReady = false;
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);
34
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();
39         } else {
40                 MSG_DEBUG("Message Service Is ready again. Refreshing ProxyListener");
41                 MsgProxyListener::instance()->refreshProxyListener();
42         }
43 }
44
45 gboolean readSocket(GIOChannel *source, GIOCondition condition, gpointer data)
46 {
47         MSG_BEGIN();
48 #if 0
49         if ((G_IO_ERR & condition) || (G_IO_HUP & condition) || (G_IO_NVAL & condition)) {
50                 MSG_DEBUG("IO condition Error!!! [%d]", condition);
51
52                 MsgProxyListener::instance()->stop();
53                 return FALSE;
54         }
55 #endif
56         if (G_IO_ERR & condition) {
57                 MSG_ERR("IO Error!!! [%d]", condition);
58                 MsgProxyListener::instance()->clearProxyCBLists();
59                 MsgProxyListener::instance()->clearOpenHandleSet();
60                 return FALSE;
61         }
62
63         if (G_IO_HUP & condition) {
64                 MSG_ERR("socket fd Error!!! [%d]", condition);
65                 MsgProxyListener::instance()->resetProxyListener();
66                 return FALSE;
67         }
68
69         if (G_IO_NVAL & condition) {
70                 MSG_ERR("Invaild socket Error!!! [%d]", condition);
71                 MsgProxyListener::instance()->clearProxyCBLists();
72                 MsgProxyListener::instance()->clearOpenHandleSet();
73                 return FALSE;
74         }
75
76         char* buf = NULL;
77         unique_ptr<char*, void(*)(char**)> eventBuf(&buf, unique_ptr_deleter);
78         unsigned int len = 0;
79
80         int n = MsgProxyListener::instance()->readFromSocket(&buf, &len);
81
82         if (n > 0) {
83                 MSG_DEBUG(">>Receiving %d bytes", n);
84                 MsgProxyListener::instance()->handleEvent((MSG_EVENT_S*)buf);
85         } else if (n == 0) {
86                 MSG_WARN("Server closed connection");
87                 return FALSE;
88         } else /* dataSize < 0 */ {
89                 MSG_DEBUG("Data is not for Listener");
90         }
91
92         MSG_END();
93
94         return TRUE;
95 }
96
97
98 /*==================================================================================================
99                                      IMPLEMENTATION OF MsgListenerThread - Member Functions
100 ==================================================================================================*/
101 MsgProxyListener* MsgProxyListener::pInstance = NULL;
102
103
104 MsgProxyListener::MsgProxyListener() : running(0)
105 {
106         clearProxyCBLists();
107         clearOpenHandleSet();
108         MsgSettingRegVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
109
110         channel = NULL;
111         eventSourceId = 0;
112 }
113
114
115 MsgProxyListener::~MsgProxyListener()
116 {
117         clearProxyCBLists();
118         clearOpenHandleSet();
119         MsgSettingRemoveVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
120 }
121
122
123 MsgProxyListener* MsgProxyListener::instance()
124 {
125         static Mutex mm;
126         MutexLocker lock(mm);
127
128         if (!pInstance) {
129                 pInstance = new MsgProxyListener();
130         }
131
132         return pInstance;
133 }
134
135
136 void MsgProxyListener::start(MsgHandle* pMsgHandle)
137 {
138         MutexLocker lock(mx);
139
140         this->insertOpenHandleSet(pMsgHandle);
141
142         if (running == 0) {
143                 cliSock.connect(MSG_SOCKET_PATH);
144                 /* wake up the waiting thread */
145                 cv.signal();
146
147                 int fd = cliSock.fd();
148
149                 MSG_DEBUG("Socket Fd : %d", fd);
150
151                 /* initializes ref_count = 1 */
152                 channel = g_io_channel_unix_new(fd);
153
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);
156
157                 MSG_DEBUG("Call g_io_add_watch() : %d", eventSourceId);
158         }
159
160         running++;
161         MSG_DEBUG("add Listener and [%d] are running.", running);
162 }
163
164
165 void MsgProxyListener::stop()
166 {
167         MSG_BEGIN();
168
169         MutexLocker lock(mx);
170
171         if (running > 1) {
172                 running--;
173                 MSG_DEBUG("There are still running Listener. [%d] left.", running);
174         } else if (running == 1) {
175                 if (channel) {
176                         g_io_channel_unref(channel);
177                         channel = NULL;
178                 }
179
180                 if (eventSourceId > 0) {
181                         g_source_remove(eventSourceId);
182                         eventSourceId = 0;
183                 }
184
185                 running = 0;
186
187                 cliSock.close();
188                 MSG_DEBUG("client Listener is terminated.");
189         }
190
191         MSG_END();
192 }
193
194
195 bool MsgProxyListener::regSentStatusEventCB(MsgHandle* pMsgHandle, int fd, msg_sent_status_cb pfSentStatus, void *pUserParam)
196 {
197         MutexLocker lock(mx);
198
199         std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
200
201         for (; it != sentStatusCBList.end(); it++) {
202                 if (it->hAddr == pMsgHandle && it->pfSentStatusCB == pfSentStatus) {
203                         if (it->fd == fd) {
204                                 MSG_DEBUG("msg_sent_status_cb() callback : [%p] is already registered!!!", pfSentStatus);
205                                 return false;
206                         } else {
207                                 MSG_DEBUG("callback is registered by restarting server");
208                                 it->fd = fd;
209                                 return true;
210                         }
211                 }
212         }
213
214         MSG_SENT_STATUS_CB_ITEM_S sentStatusCB = {pMsgHandle, fd, pfSentStatus, pUserParam};
215
216         sentStatusCBList.push_back(sentStatusCB);
217
218         return true;
219 }
220
221
222 bool MsgProxyListener::regMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_sms_incoming_cb pfNewMessage, int port, void *pUserParam)
223 {
224         MutexLocker lock(mx);
225
226         std::list<MSG_INCOMING_CB_ITEM_S>::iterator it = newMessageCBList.begin();
227
228         for (; it != newMessageCBList.end(); it++) {
229                 if (it->hAddr == pMsgHandle && it->port == port && it->pfIncomingCB == pfNewMessage) {
230                         if (it->fd == fd) {
231                                 MSG_DEBUG("msg_sms_incoming_cb() callback : Port Number [%d] is already registered!!!", port);
232                                 return false;
233                         } else {
234                                 MSG_DEBUG("callback is registered by restarting server");
235                                 it->fd = fd;
236                                 return true;
237                         }
238                 }
239         }
240
241         MSG_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewMessage, port, pUserParam};
242
243         newMessageCBList.push_back(incomingCB);
244
245         return true;
246 }
247
248
249 bool MsgProxyListener::regMMSConfMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_mms_conf_msg_incoming_cb pfNewMMSConfMessage, const char *pAppId, void *pUserParam)
250 {
251         MutexLocker lock(mx);
252
253         std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it = newMMSConfMessageCBList.begin();
254
255         for (; it != newMMSConfMessageCBList.end(); it++) {
256                 if (it->hAddr == pMsgHandle && it->pfMMSConfIncomingCB == pfNewMMSConfMessage) {
257                         if (it->fd == fd) {
258                                 if (pAppId == NULL) {
259                                         MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback is already registered!!!");
260                                         return false;
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);
263                                         return false;
264                                 }
265                         } else {
266                                 MSG_DEBUG("callback is registered by restarting server");
267                                 it->fd = fd;
268                                 return true;
269                         }
270                 }
271         }
272
273         MSG_MMS_CONF_INCOMING_CB_ITEM_S incomingConfCB = {pMsgHandle, fd, pfNewMMSConfMessage, {0}, pUserParam};
274
275         if (pAppId != NULL)
276                 strncpy(incomingConfCB.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
277
278         newMMSConfMessageCBList.push_back(incomingConfCB);
279
280         return true;
281 }
282
283
284 bool MsgProxyListener::regPushMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_push_msg_incoming_cb pfNewPushMessage, const char *pAppId, void *pUserParam)
285 {
286         MutexLocker lock(mx);
287
288         std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it = newPushMessageCBList.begin();
289
290         for (; it != newPushMessageCBList.end(); it++) {
291                 if (it->hAddr == pMsgHandle && it->pfPushIncomingCB == pfNewPushMessage) {
292                         if (it->fd == fd) {
293                                 if (pAppId == NULL) {
294                                         MSG_DEBUG("msg_push_msg_incoming_cb() callback is already registered!!!");
295                                         return false;
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);
298                                         return false;
299                                 }
300                         } else {
301                                 MSG_DEBUG("callback is registered by restarting server");
302                                 it->fd = fd;
303                                 return true;
304                         }
305                 }
306         }
307
308         MSG_PUSH_INCOMING_CB_ITEM_S incomingPushCB = {pMsgHandle, fd, pfNewPushMessage, {0}, pUserParam};
309
310         if (pAppId != NULL)
311                 strncpy(incomingPushCB.appId, pAppId, MAX_WAPPUSH_ID_LEN);
312
313         newPushMessageCBList.push_back(incomingPushCB);
314
315         return true;
316 }
317
318
319 bool MsgProxyListener::regCBMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_cb_incoming_cb pfNewCBMessage, bool bSave, void *pUserParam)
320 {
321         MutexLocker lock(mx);
322
323         std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it = newCBMessageCBList.begin();
324
325         for (; it != newCBMessageCBList.end(); it++) {
326                 if (it->hAddr == pMsgHandle && it->pfCBIncomingCB == pfNewCBMessage) {
327                         if (it->fd == fd) {
328                                 MSG_DEBUG("msg_CB_incoming_cb() callback : [%p] is already registered!!!", pfNewCBMessage);
329                                  it->bsave = bSave;
330                                  it->userParam = pUserParam;
331                                 return false;
332                         } else {
333                                 MSG_DEBUG("callback is registered by restarting server");
334                                 it->fd = fd;
335                                 return true;
336                         }
337                 }
338         }
339
340         MSG_CB_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewCBMessage, bSave, pUserParam};
341
342         newCBMessageCBList.push_back(incomingCB);
343
344         return true;
345 }
346
347
348 bool MsgProxyListener::regReportMsgIncomingCB(MsgHandle* pMsgHandle, int fd, msg_report_msg_incoming_cb pfReportMessage, void *pUserParam)
349 {
350         MutexLocker lock(mx);
351
352         std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it = reportMessageCBList.begin();
353
354         for (; it != reportMessageCBList.end(); it++) {
355                 if (it->hAddr == pMsgHandle && it->pfReportMsgIncomingCB == pfReportMessage) {
356                         if (it->fd == fd) {
357                                 MSG_DEBUG("msg_report_msg_incoming_cb() callback : [%p] is already registered!!!", pfReportMessage);
358                                  it->userParam = pUserParam;
359                                 return false;
360                         } else {
361                                 MSG_DEBUG("callback is registered by restarting server");
362                                 it->fd = fd;
363                                 return true;
364                         }
365                 }
366         }
367
368         MSG_REPORT_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfReportMessage, pUserParam};
369
370         reportMessageCBList.push_back(incomingCB);
371
372         return true;
373 }
374
375
376 bool MsgProxyListener::regSyncMLMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_incoming_cb pfNewSyncMLMessage, void *pUserParam)
377 {
378         MutexLocker lock(mx);
379
380         std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it = newSyncMLMessageCBList.begin();
381
382         for (; it != newSyncMLMessageCBList.end(); it++) {
383                 if (it->hAddr == pMsgHandle && it->pfSyncMLIncomingCB == pfNewSyncMLMessage) {
384                         if (it->fd == fd) {
385                                 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewSyncMLMessage);
386                                 return false;
387                         } else {
388                                 MSG_DEBUG("callback is registered by restarting server");
389                                 it->fd = fd;
390                                 return true;
391                         }
392                 }
393         }
394
395         MSG_SYNCML_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewSyncMLMessage, pUserParam};
396
397         newSyncMLMessageCBList.push_back(incomingCB);
398
399         return true;
400 }
401
402
403 bool MsgProxyListener::regLBSMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_lbs_msg_incoming_cb pfNewLBSMsgIncoming, void *pUserParam)
404 {
405         MutexLocker lock(mx);
406
407         std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it = newLBSMessageCBList.begin();
408
409         for (; it != newLBSMessageCBList.end(); it++) {
410                 if (it->hAddr == pMsgHandle && it->pfLBSMsgIncoming == pfNewLBSMsgIncoming) {
411                         if (it->fd == fd) {
412                                 MSG_DEBUG("msg_lbs_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewLBSMsgIncoming);
413                                 return false;
414                         } else {
415                                 MSG_DEBUG("callback is registered by restarting server");
416                                 it->fd = fd;
417                                 return true;
418                         }
419                 }
420         }
421
422         MSG_LBS_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfNewLBSMsgIncoming, pUserParam};
423
424         newLBSMessageCBList.push_back(incomingCB);
425
426         return true;
427 }
428
429
430 bool MsgProxyListener::regSyncMLMessageOperationEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_operation_cb pfSyncMLMessageOperation, void *pUserParam)
431 {
432         MutexLocker lock(mx);
433
434         std::list<MSG_SYNCML_OPERATION_CB_ITEM_S>::iterator it = operationSyncMLMessageCBList.begin();
435
436         for (; it != operationSyncMLMessageCBList.end(); it++) {
437                 if (it->hAddr == pMsgHandle && it->pfSyncMLOperationCB == pfSyncMLMessageOperation) {
438                         if (it->fd == fd) {
439                                 MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfSyncMLMessageOperation);
440                                 return false;
441                         } else {
442                                 MSG_DEBUG("callback is registered by restarting server");
443                                 it->fd = fd;
444                                 return true;
445                         }
446                 }
447         }
448
449         MSG_SYNCML_OPERATION_CB_ITEM_S incomingCB = {pMsgHandle, fd, pfSyncMLMessageOperation, pUserParam};
450
451         operationSyncMLMessageCBList.push_back(incomingCB);
452
453         return true;
454 }
455
456
457 bool MsgProxyListener::regStorageChangeEventCB(MsgHandle* pMsgHandle, int fd, msg_storage_change_cb pfStorageChangeOperation, void *pUserParam)
458 {
459         MutexLocker lock(mx);
460
461         std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it = storageChangeCBList.begin();
462
463         for (; it != storageChangeCBList.end(); it++) {
464                 if (it->hAddr == pMsgHandle && it->pfStorageChangeCB == pfStorageChangeOperation) {
465                         if (it->fd == fd) {
466                                 MSG_DEBUG("msg_storage_change_cb() callback : [%p] is already registered!!!", pfStorageChangeOperation);
467                                 return false;
468                         } else {
469                                 MSG_DEBUG("callback is registered by restarting server");
470                                 it->fd = fd;
471                                 return true;
472                         }
473                 }
474         }
475
476         MSG_STORAGE_CHANGE_CB_ITEM_S changeCB = {pMsgHandle, fd, pfStorageChangeOperation, pUserParam};
477
478         storageChangeCBList.push_back(changeCB);
479
480         return true;
481 }
482
483
484 void MsgProxyListener::clearListOfClosedHandle(MsgHandle* pMsgHandle)
485 {
486         MSG_BEGIN();
487
488         MutexLocker lock(mx);
489
490         /* sent status CB list */
491         std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
492
493         for (; it != sentStatusCBList.end(); ) {
494                 if (it->hAddr == pMsgHandle) {
495                         sentStatusCBList.erase(it++);
496                         stop();
497                 } else {
498                         ++it;
499                 }
500         }
501
502         /* new message CB list */
503         std::list<MSG_INCOMING_CB_ITEM_S>::iterator it2 = newMessageCBList.begin();
504
505         for (; it2 != newMessageCBList.end(); ) {
506                 if (it2->hAddr == pMsgHandle) {
507                         newMessageCBList.erase(it2++);
508                         stop();
509                 } else {
510                         ++it2;
511                 }
512         }
513
514         /* MMS conf Message CB list */
515         std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it3 = newMMSConfMessageCBList.begin();
516
517         for (; it3 != newMMSConfMessageCBList.end(); ) {
518                 if (it3->hAddr == pMsgHandle) {
519                         newMMSConfMessageCBList.erase(it3++);
520                         stop();
521                 } else {
522                         ++it3;
523                 }
524         }
525
526         /* SyncML Message CB list */
527         std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it4 = newSyncMLMessageCBList.begin();
528
529         for (; it4 != newSyncMLMessageCBList.end(); ) {
530                 if (it4->hAddr == pMsgHandle) {
531                         newSyncMLMessageCBList.erase(it4++);
532                         stop();
533                 } else {
534                         ++it4;
535                 }
536         }
537
538         /* LBS Message CB list */
539         std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it5 = newLBSMessageCBList.begin();
540
541         for (; it5 != newLBSMessageCBList.end(); ) {
542                 if (it5->hAddr == pMsgHandle) {
543                         newLBSMessageCBList.erase(it5++);
544                         stop();
545                 } else {
546                         ++it5;
547                 }
548         }
549
550         /* Push Message CB list */
551         std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it6 = newPushMessageCBList.begin();
552
553         for (; it6 != newPushMessageCBList.end(); ) {
554                 if (it6->hAddr == pMsgHandle) {
555                         newPushMessageCBList.erase(it6++);
556                         stop();
557                 } else {
558                         ++it6;
559                 }
560         }
561
562         /* CB Message CB list */
563         std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it7 = newCBMessageCBList.begin();
564
565         for (; it7 != newCBMessageCBList.end(); ) {
566                 if (it7->hAddr == pMsgHandle) {
567                         newCBMessageCBList.erase(it7++);
568                         stop();
569                 } else {
570                         ++it7;
571                 }
572         }
573
574         /* Storage change Message CB list */
575         std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it8 = storageChangeCBList.begin();
576
577         for (; it8 != storageChangeCBList.end(); ) {
578                 if (it8->hAddr == pMsgHandle) {
579                         storageChangeCBList.erase(it8++);
580                         stop();
581                 } else {
582                         ++it8;
583                 }
584         }
585
586
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++);
592                         stop();
593                 } else {
594                         ++it9;
595                 }
596         }
597
598
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++);
604                         stop();
605                 } else {
606                         ++it10;
607                 }
608         }
609
610         /* Open Handle Set */
611         openHandleSet.erase(pMsgHandle);
612
613         MSG_END();
614 }
615
616
617 void MsgProxyListener::refreshListOfOpenedHandle(MsgHandle* pMsgHandle)
618 {
619         MSG_BEGIN();
620
621         MutexLocker lock(mx);
622
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;
628                         try {
629                                 pMsgHandle->regSentStatusCallback(it->pfSentStatusCB, it->userParam);
630                         } catch (MsgException& e) {
631                                 MSG_FATAL("%s", e.what());
632                         }
633                 }
634         }
635
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;
641                         try {
642                                 pMsgHandle->regSmsMessageCallback(it2->pfIncomingCB, it2->port, it2->userParam);
643                         } catch (MsgException& e) {
644                                 MSG_FATAL("%s", e.what());
645                         }
646                 }
647         }
648
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;
654                         try {
655                                 pMsgHandle->regMmsConfMessageCallback(it3->pfMMSConfIncomingCB, it3->appId, it3->userParam);
656                         } catch (MsgException& e) {
657                                 MSG_FATAL("%s", e.what());
658                         }
659                 }
660         }
661
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;
667                         try {
668                                 pMsgHandle->regSyncMLMessageCallback(it4->pfSyncMLIncomingCB, it4->userParam);
669                         } catch (MsgException& e) {
670                                 MSG_FATAL("%s", e.what());
671                         }
672                 }
673         }
674
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;
680                         try {
681                                 pMsgHandle->regLBSMessageCallback(it5->pfLBSMsgIncoming, it5->userParam);
682                         } catch (MsgException& e) {
683                                 MSG_FATAL("%s", e.what());
684                         }
685                 }
686         }
687
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;
693                         try {
694                                 pMsgHandle->regPushMessageCallback(it6->pfPushIncomingCB, it6->appId, it6->userParam);
695                         } catch (MsgException& e) {
696                                 MSG_FATAL("%s", e.what());
697                         }
698                 }
699         }
700
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;
706                         try {
707                                 pMsgHandle->regCBMessageCallback(it7->pfCBIncomingCB, it7->bsave, it7->userParam);
708                         } catch (MsgException& e) {
709                                 MSG_FATAL("%s", e.what());
710                         }
711                 }
712         }
713
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;
719                         try {
720                                 pMsgHandle->regStorageChangeCallback(it8->pfStorageChangeCB, it8->userParam);
721                         } catch (MsgException& e) {
722                                 MSG_FATAL("%s", e.what());
723                         }
724                 }
725         }
726
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;
732                         try {
733                                 pMsgHandle->regReportMessageCallback(it9->pfReportMsgIncomingCB, it9->userParam);
734                         } catch (MsgException& e) {
735                                 MSG_FATAL("%s", e.what());
736                         }
737                 }
738         }
739
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;
745                         try {
746                                 pMsgHandle->regSyncMLMessageOperationCallback(it10->pfSyncMLOperationCB, it10->userParam);
747                         } catch (MsgException& e) {
748                                 MSG_FATAL("%s", e.what());
749                         }
750                 }
751         }
752
753         MSG_END();
754 }
755
756
757 void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
758 {
759         MSG_BEGIN();
760
761         if (!pMsgEvent)
762                 THROW(MsgException::INVALID_PARAM, "pMsgEvent is NULL");
763
764         if (pMsgEvent->eventType == MSG_EVENT_PLG_SENT_STATUS_CNF) {
765                 unsigned int chInfo[3] = {0}; /*3 reqid, status, object */
766
767                 memcpy(&chInfo, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(chInfo));
768
769                 msg_struct_s status = {0, };
770                 MSG_SENT_STATUS_S statusData = {(msg_request_id_t)chInfo[0], (msg_network_status_t)chInfo[1]};
771
772                 status.type = MSG_STRUCT_SENT_STATUS_INFO;
773                 status.data = (void *)&statusData;
774
775                 mx.lock();
776
777                 MsgSentStatusCBList::iterator it = sentStatusCBList.begin();
778
779                 for ( ; it != sentStatusCBList.end() ; it++) {
780                         MsgHandle* pHandle = it->hAddr;
781
782                         msg_sent_status_cb pfunc = it->pfSentStatusCB;
783
784                         void* param = it->userParam;
785
786                         pfunc((msg_handle_t)pHandle, (msg_struct_t)&status, param);
787                 }
788
789                 mx.unlock();
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));
793
794                 msgInfo.addressList = NULL;
795                 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
796
797                 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
798
799                 int portKey = (msgInfo.msgPort.valid)? msgInfo.msgPort.dstPort: 0;
800
801                 mx.lock();
802
803                 MsgNewMessageCBList::iterator it = newMessageCBList.begin();
804                 MsgNewMessageCBList matchList;
805
806                 for ( ; it != newMessageCBList.end() ; it++) {
807                         if (portKey == it->port) {
808                                 matchList.push_back(*it);
809                         }
810                 }
811
812                 mx.unlock();
813
814                 it = matchList.begin();
815
816                 for ( ; it != matchList.end(); it++ ) {
817                         MsgHandle* pHandle = it->hAddr;
818
819                         MSG_MESSAGE_HIDDEN_S msgHidden = {0, };
820
821                         msgHidden.pData = NULL;
822                         msgHidden.pMmsData = NULL;
823
824                         /* Allocate memory for address list of message */
825                         msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
826
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)
830                                 continue;
831
832                         msg_struct_s *pTmp = NULL;
833
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));
840
841                                 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
842                         }
843
844                         msgHidden.addr_list = addr_list;
845
846                         try {
847                                 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
848                         }
849                         catch (MsgException& e) {
850                                 MSG_FATAL("%s", e.what());
851                         }
852
853                         msg_struct_s msg = {0, };
854                         msg.type = MSG_STRUCT_MESSAGE_INFO;
855                         msg.data = &msgHidden;
856
857                         msg_sms_incoming_cb pfunc = it->pfIncomingCB;
858
859                         void* param = it->userParam;
860
861                         pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
862
863                         delete [] (char*)msgHidden.pData;
864                         if (msgHidden.pMmsData != NULL)
865                                 delete [] (char*)msgHidden.pMmsData;
866
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;
875                                 }
876
877                                 g_free(msgHidden.addr_list->msg_struct_info);
878
879                                 delete msgHidden.addr_list;
880                                 msgHidden.addr_list = NULL;
881                         }
882                 }
883
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));
887
888                 msgInfo.addressList = NULL;
889                 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
890
891                 MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
892
893
894                 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
895
896                 char* appIdKey = (pMmsRecvData->msgAppId.valid)? pMmsRecvData->msgAppId.appId: NULL;
897
898                 mx.lock();
899
900                 MsgNewMMSConfMessageCBList::iterator it = newMMSConfMessageCBList.begin();
901                 MsgNewMMSConfMessageCBList matchList;
902
903                 for ( ; it != newMMSConfMessageCBList.end(); it++) {
904                         if (appIdKey) {
905                                 if (!strcmp(appIdKey, it->appId))
906                                         matchList.push_back(*it);
907                         } else {
908                                 /* (appIdKey == NULL && it->appId[0] == 0) */
909                                 if (it->appId[0] == 0)
910                                         matchList.push_back(*it);
911                         }
912                 }
913
914                 mx.unlock();
915
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 */
919
920                 strncpy(tempFileName, pMmsRecvData->retrievedFilePath, MSG_FILENAME_LEN_MAX);
921
922                 memset(msgInfo.msgData, 0, MAX_MSG_DATA_LEN+1);
923                 memcpy(msgInfo.msgData, tempFileName + strlen(MSG_DATA_PATH), MAX_MSG_DATA_LEN);
924
925                 it = matchList.begin();
926
927                 for ( ; it != matchList.end(); it++) {
928                         MsgHandle* pHandle = it->hAddr;
929
930                         MSG_MESSAGE_HIDDEN_S msgHidden = {0, };
931
932                         msgHidden.pData = NULL;
933                         msgHidden.pMmsData = NULL;
934
935                         /* Allocate memory for address list of message */
936                         msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
937
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)
941                                 continue;
942
943                         msg_struct_s *pTmp = NULL;
944
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));
951
952                                 addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
953                         }
954
955                         msgHidden.addr_list = addr_list;
956
957                         try {
958                                 pHandle->convertMsgStruct(&msgInfo, &msgHidden);
959                         }
960                         catch (MsgException& e) {
961                                 MSG_FATAL("%s", e.what());
962                         }
963
964                         msg_struct_s msg = {0, };
965                         msg.type = MSG_STRUCT_MESSAGE_INFO;
966                         msg.data = &msgHidden;
967
968                         msg_mms_conf_msg_incoming_cb pfunc = it->pfMMSConfIncomingCB;
969
970                         void* param = it->userParam;
971                         pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
972
973                         delete [] (char*)msgHidden.pData;
974                         if (msgHidden.pMmsData != NULL)
975                                 delete [] (char*)msgHidden.pMmsData;
976
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;
985                                 }
986
987                                 g_free(msgHidden.addr_list->msg_struct_info);
988
989                                 delete msgHidden.addr_list;
990                                 msgHidden.addr_list = NULL;
991                         }
992
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. */
995                         if (appIdKey) {
996                                 MSG_DEBUG("delete received JAVA MMS message:%s from native storage", tempFileName);
997                                 pHandle->deleteMessage(msgInfo.msgId);
998                         }
999                 }
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;
1002
1003                 MSG_DEBUG("msgType [%d]", pSyncMLData->syncmlType);
1004
1005                 mx.lock();
1006
1007                 MsgNewSyncMLMessageCBList::iterator it = newSyncMLMessageCBList.begin();
1008
1009                 for ( ; it != newSyncMLMessageCBList.end(); it++) {
1010                         MsgHandle* pHandle = it->hAddr;
1011
1012                         msg_syncml_msg_incoming_cb pfunc = it->pfSyncMLIncomingCB;
1013
1014                         void* param = it->userParam;
1015
1016                         pfunc((msg_handle_t)pHandle, pSyncMLData->syncmlType, pSyncMLData->pushBody, pSyncMLData->pushBodyLen, pSyncMLData->wspHeader, pSyncMLData->wspHeaderLen, pSyncMLData->simIndex, param);
1017                 }
1018
1019                 mx.unlock();
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;
1022
1023                 mx.lock();
1024
1025                 MsgNewLBSMessageCBList::iterator it = newLBSMessageCBList.begin();
1026
1027                 for ( ; it != newLBSMessageCBList.end(); it++) {
1028                         MsgHandle* pHandle = it->hAddr;
1029
1030                         msg_lbs_msg_incoming_cb pfunc = it->pfLBSMsgIncoming;
1031
1032                         void* param = it->userParam;
1033
1034                         pfunc((msg_handle_t)pHandle, pLBSData->pushHeader, pLBSData->pushBody, pLBSData->pushBodyLen, param);
1035                 }
1036
1037                 mx.unlock();
1038         } else if (pMsgEvent->eventType == MSG_EVENT_SYNCML_OPERATION) {
1039                 int msgId;
1040                 int extId;
1041
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));
1044
1045                 MSG_DEBUG("msgId [%d]", msgId);
1046                 MSG_DEBUG("extId [%d]", extId);
1047
1048                 mx.lock();
1049
1050                 MsgOperationSyncMLMessageCBList::iterator it = operationSyncMLMessageCBList.begin();
1051
1052                 for ( ; it != operationSyncMLMessageCBList.end(); it++) {
1053                         MsgHandle* pHandle = it->hAddr;
1054
1055                         msg_syncml_msg_operation_cb pfunc = it->pfSyncMLOperationCB;
1056
1057                         void* param = it->userParam;
1058
1059                         pfunc((msg_handle_t)pHandle, msgId, extId, param);
1060                 }
1061
1062                 mx.unlock();
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));
1067
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));
1071
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));
1074                 else
1075                         msgIdList.msgIdList = NULL;
1076
1077                 MSG_DEBUG("storageChangeType [%d], msgIdList.nCount [%d]", storageChangeType, msgIdList.nCount);
1078
1079                 mx.lock();
1080
1081                 MsgStorageChangeCBList::iterator it = storageChangeCBList.begin();
1082
1083                 for ( ; it != storageChangeCBList.end(); it++) {
1084                         MsgHandle* pHandle = it->hAddr;
1085
1086                         msg_storage_change_cb pfunc = it->pfStorageChangeCB;
1087
1088                         void* param = it->userParam;
1089
1090                         pfunc((msg_handle_t)pHandle, storageChangeType, (msg_id_list_s*)&msgIdList, param);
1091                 }
1092
1093                 mx.unlock();
1094         } else if (pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_CB_MSG_IND) {
1095                 MSG_CB_MSG_S *pCbMsg = (MSG_CB_MSG_S *)pMsgEvent->data;
1096
1097                 mx.lock();
1098
1099                 MsgNewCBMessageCBList::iterator it = newCBMessageCBList.begin();
1100
1101                 for ( ; it != newCBMessageCBList.end(); it++) {
1102                         MsgHandle* pHandle = it->hAddr;
1103                         msg_struct_s msg = {0, };
1104
1105                         msg.type = MSG_STRUCT_CB_MSG;
1106                         msg.data = pCbMsg;
1107
1108                         msg_cb_incoming_cb pfunc = it->pfCBIncomingCB;
1109
1110                         void* param = it->userParam;
1111
1112                         pfunc((msg_handle_t)pHandle, (msg_struct_t) &msg, param);
1113                 }
1114
1115                 mx.unlock();
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;
1118
1119                 mx.lock();
1120
1121                 MsgNewPushMessageCBList::iterator it = newPushMessageCBList.begin();
1122
1123                 for ( ; it != newPushMessageCBList.end(); it++) {
1124                         MsgHandle* pHandle = it->hAddr;
1125
1126                         msg_push_msg_incoming_cb pfunc = it->pfPushIncomingCB;
1127
1128                         void* param = it->userParam;
1129
1130                         if (!strncmp(it->appId, pPushData->pushAppId, MAX_WAPPUSH_ID_LEN))
1131                                 pfunc((msg_handle_t)pHandle, pPushData->pushHeader, pPushData->pushBody, pPushData->pushBodyLen, param);
1132                 }
1133
1134                 mx.unlock();
1135         } else if (pMsgEvent->eventType == MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND) {
1136                 msg_report_type_t reportType;
1137                 msg_message_id_t msgId;
1138                 int addr_len;
1139                 char *addr_val;
1140
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';
1147
1148                 MSG_SEC_DEBUG("reportType [%d], msgId [%d], Address Length [%d], Address Value [%s]", reportType, msgId, addr_len, addr_val);
1149
1150                 mx.lock();
1151
1152                 MsgReportMessageCBList::iterator it = reportMessageCBList.begin();
1153
1154                 for ( ; it != reportMessageCBList.end(); it++) {
1155                         MsgHandle* pHandle = it->hAddr;
1156
1157                         msg_report_msg_incoming_cb pfunc = it->pfReportMsgIncomingCB;
1158
1159                         void* param = it->userParam;
1160
1161                         pfunc((msg_handle_t)pHandle, reportType, msgId, addr_len, addr_val, param);
1162                 }
1163
1164                 mx.unlock();
1165         }
1166
1167         MSG_END();
1168 }
1169
1170
1171 int MsgProxyListener::getRemoteFd()
1172 {
1173         return cliSock.getRemoteFd();
1174 }
1175
1176
1177 int MsgProxyListener::readFromSocket(char** buf, unsigned int* len)
1178 {
1179         return cliSock.read(buf, len);
1180 }
1181
1182
1183 void MsgProxyListener::resetProxyListener()
1184 {
1185         MSG_DEBUG("client Listener reset");
1186         MutexLocker lock(mx);
1187
1188         if (channel) {
1189                 g_io_channel_unref(channel);
1190                 channel = NULL;
1191         }
1192
1193         if (eventSourceId > 0) {
1194                 g_source_remove(eventSourceId);
1195                 eventSourceId = 0;
1196         }
1197
1198         running = 0;
1199
1200         cliSock.close();
1201
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();
1207         }
1208 }
1209
1210
1211 void MsgProxyListener::refreshProxyListener()
1212 {
1213         MSG_DEBUG("refresh proxy listener");
1214         MutexLocker lock(mx);
1215
1216         handle_set::iterator it = openHandleSet.begin();
1217         for (; it != openHandleSet.end(); it++) {
1218                 MsgHandle *handle = (MsgHandle *)*it;
1219                 handle->openHandle();
1220                 refreshListOfOpenedHandle(handle);
1221         }
1222 }
1223
1224
1225 void MsgProxyListener::clearProxyCBLists()
1226 {
1227         MSG_DEBUG("clear proxy callback list");
1228
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();
1239 }
1240
1241
1242 void MsgProxyListener::insertOpenHandleSet(MsgHandle* pMsgHandle)
1243 {
1244         MSG_DEBUG("try to insert opened handle. handle=[%p]", pMsgHandle);
1245
1246         MutexLocker lock(mx);
1247
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());
1252         }
1253 }
1254
1255
1256 void MsgProxyListener::clearOpenHandleSet()
1257 {
1258         MSG_DEBUG("clear opened handle set");
1259         openHandleSet.clear();
1260 }
1261
1262 #ifdef CHECK_SENT_STATUS_CALLBACK
1263 int MsgProxyListener::getSentStatusCbCnt()
1264 {
1265         int cbCnt = 0;
1266
1267         cbCnt = sentStatusCBList.size();
1268
1269         MSG_DEBUG("registered sent status callback count : [%d]", cbCnt);
1270
1271         return cbCnt;
1272 }
1273 #endif