RSA sync with private
[platform/core/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerTransport.cpp
1 /*
2 * Copyright 2012  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 <time.h>
18
19 #include "MsgDebug.h"
20 #include "MsgException.h"
21 #include "MsgUtilFile.h"
22 #include "MsgContact.h"
23 #include "MsgSoundPlayer.h"
24 #include "MsgGconfWrapper.h"
25 #include "MsgNotificationWrapper.h"
26 #include "MsgUtilFunction.h"
27 #include "MsgSubmitHandler.h"
28 #include "MsgDeliverHandler.h"
29 #include "MsgStorageHandler.h"
30 #include "MsgTransManager.h"
31 #include "MsgPluginManager.h"
32 #include "MsgCmdHandler.h"
33 #include "MsgUtilStorage.h"
34
35 #include <alarm.h>
36
37 /*==================================================================================================
38                                      FUNCTION IMPLEMENTATION
39 ==================================================================================================*/
40 int MsgSubmitReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
41 {
42         msg_error_t err = MSG_SUCCESS;
43         bool bNewMsg = true;
44
45         int eventSize = 0;
46
47         MSG_REQUEST_INFO_S reqInfo = {0,};
48         MSG_PROXY_INFO_S proxyInfo = {0,};
49
50         // Get Message Request
51         memcpy(&reqInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_REQUEST_INFO_S));
52
53         // Storing Request ID, Proxy Info for Sent Status CNF
54         memcpy(&proxyInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)), sizeof(MSG_PROXY_INFO_S));
55
56         if (reqInfo.msgInfo.msgId > 0)
57                 bNewMsg = false;
58
59         // Submit Request
60         err = MsgSubmitReq(&reqInfo, false);
61
62         if (err == MSG_SUCCESS){
63                 MSG_DEBUG("Command Handle Success : MsgSubmitReq()");
64         } else {
65                 MSG_DEBUG("Command Handle Fail : MsgSubmitReq()");
66         }
67
68         int reqId = reqInfo.reqId;
69         proxyInfo.sentMsgId = reqInfo.msgInfo.msgId;
70
71         MSG_DEBUG("REQID: %d, MSGID: %d", reqId, proxyInfo.sentMsgId);
72
73         if (reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE) {
74                 MsgTransactionManager::instance()->insertSentMsg(reqId, &proxyInfo);
75         } else if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE) {
76                 // Retrieve MMS shall not be kept in sentMsg
77                 if ((reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_MMS) ||
78                         (reqInfo.msgInfo.msgType.subType == MSG_FORWARD_MMS) ||
79                         (reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS))
80                 MsgTransactionManager::instance()->insertSentMsg(reqId, &proxyInfo);
81         }
82
83         // keep transaction Id list for distinguish java MMS sent msg when sendconf received
84         if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE &&
85                 reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS) {
86                 MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S trId={0};
87                 memcpy(&trId.id, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)+sizeof(MSG_PROXY_INFO_S)), MMS_TR_ID_LEN);
88
89                 char* pFileName;
90                 pFileName = strstr(reqInfo.msgInfo.msgData, "MSG_");
91                 strncpy(trId.pduFileName, pFileName, MAX_COMMON_INFO_SIZE);
92
93                 MSG_DEBUG("java MMS msg trId:%s filepath:%s ",trId.id, reqInfo.msgInfo.msgData);
94
95                 MsgTransactionManager* tm = MsgTransactionManager::instance();
96                 tm->setJavaMMSList(&trId);
97         }
98
99         // Make Event Data
100         eventSize = MsgMakeEvent(&reqId, sizeof(reqId), MSG_EVENT_SUBMIT_REQ, err, (void**)ppEvent);
101
102         /* reject_msg_support */
103         if(((reqInfo.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS) &&
104                  (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE)))
105                 err = MsgStoDeleteMessage(reqInfo.msgInfo.msgId, true);
106
107         /** send storage CB */
108         msg_id_list_s msgIdList;
109         msg_message_id_t msgIds[1];
110         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
111
112         msgIdList.nCount = 1;
113         msgIds[0] = reqInfo.msgInfo.msgId;
114         msgIdList.msgIdList = msgIds;
115
116         if ((err == MSG_SUCCESS || err != MSG_ERR_PLUGIN_STORAGE) && bNewMsg && reqInfo.msgInfo.msgPort.valid == false) {
117                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
118         } else if (err == MSG_ERR_SECURITY_ERROR) { // Case of MDM enabled, it returns MSG_ERR_SECURITY_ERROR.
119                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
120         } else {
121                 MSG_DEBUG("No need to broadcast storage change CB");
122         }
123
124         return eventSize;
125 }
126
127
128 int MsgCancelReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
129 {
130         msg_error_t err = MSG_SUCCESS;
131
132         int eventSize = 0;
133
134         // Get Request ID
135         msg_request_id_t* reqId = (msg_request_id_t*)pCmd->cmdData;
136
137         // Cancel Request
138         err = MsgCancelReq(*reqId);
139
140         if (err == MSG_SUCCESS)
141         {
142                 MSG_DEBUG("Command Handle Success : MsgSubCancelReq()");
143         }
144         else
145         {
146                 MSG_DEBUG("Command Handle Fail : MsgSubCancelReq()");
147         }
148
149         // Make Event Data
150         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_CANCEL_REQ, err, (void**)ppEvent);
151
152         return eventSize;
153 }
154
155
156 int MsgRegSentStatusCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
157 {
158         // input check
159         if( !pCmd || !ppEvent)
160                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
161
162         // Get Message Request
163         int listenerFd = *((int*) pCmd->cmdData);
164         MSG_DEBUG("Registering sent status CB for %d", listenerFd);
165
166         // storing dst fd in list
167         MsgTransactionManager::instance()->setSentStatusCB(listenerFd);
168
169         // Make Event Data
170         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SENT_STATUS_CB, MSG_SUCCESS, (void**)ppEvent);
171
172         return eventSize;
173 }
174
175
176 int MsgRegIncomingMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
177 {
178         // input check
179         if( !pCmd || !ppEvent)
180                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
181
182         // Get Message Request
183         MSG_CMD_REG_INCOMING_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_MSG_CB_S*) pCmd->cmdData;
184         MSG_DEBUG("Registering incoming SMS CB for fd %d mType %d port %d", pCmdData->listenerFd, pCmdData->msgType, pCmdData->port);
185
186         // storing dst fd in list
187         MsgTransactionManager::instance()->setIncomingMsgCB(pCmdData);
188
189         // Make Event Data
190         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
191
192         return eventSize;
193 }
194
195
196 int MsgRegIncomingMMSConfMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
197 {
198         // input check
199         if( !pCmd || !ppEvent)
200                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
201
202         // Get Message Request
203         MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S*) pCmd->cmdData;
204         MSG_DEBUG("Registering incoming MMS Conf CB for fd:%d mType:%d appId:%s", pCmdData->listenerFd, pCmdData->msgType, pCmdData->appId);
205
206         // storing dst fd in list
207         MsgTransactionManager::instance()->setMMSConfMsgCB(pCmdData);
208
209         // Make Event Data
210         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
211
212         return eventSize;
213 }
214
215 int MsgRegIncomingPushMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
216 {
217         // input check
218         if( !pCmd || !ppEvent)
219                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
220
221         // Get Message Request
222         MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S*) pCmd->cmdData;
223         MSG_DEBUG("Registering incoming Push Msg CB for fd:%d mType:%d appId:%s", pCmdData->listenerFd, pCmdData->msgType, pCmdData->appId);
224
225         // storing dst fd in list
226         MsgTransactionManager::instance()->setPushMsgCB(pCmdData);
227
228         // Make Event Data
229         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_PUSH_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
230
231         return eventSize;
232 }
233
234 int MsgRegIncomingCBMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
235 {
236         // input check
237         if( !pCmd || !ppEvent)
238                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
239
240         // Get Message Request
241         MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_CB_MSG_CB_S*) pCmd->cmdData;
242         MSG_DEBUG("Registering incoming Push Msg CB for fd:%d mType:%d", pCmdData->listenerFd, pCmdData->msgType);
243
244         // storing dst fd in list
245         MsgTransactionManager::instance()->setCBMsgCB(pCmdData);
246
247         // Make Event Data
248         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_CB_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
249
250         return eventSize;
251 }
252
253
254 int MsgRegIncomingSyncMLMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
255 {
256         // input check
257         if( !pCmd || !ppEvent)
258                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
259
260         // Get Message Request
261         MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S*) pCmd->cmdData;
262         MSG_DEBUG("Registering incoming Sync ML Msg CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
263
264         // storing dst fd in list
265         MsgTransactionManager::instance()->setSyncMLMsgCB(pCmdData);
266
267         // Make Event Data
268         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
269
270         return eventSize;
271 }
272
273
274 int MsgRegIncomingLBSMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
275 {
276         // input check
277         if( !pCmd || !ppEvent)
278                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
279
280         // Get Message Request
281         MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_LBS_MSG_CB_S*) pCmd->cmdData;
282         MSG_DEBUG("Registering incoming LBS Msg CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
283
284         // storing dst fd in list
285         MsgTransactionManager::instance()->setLBSMsgCB(pCmdData);
286
287         // Make Event Data
288         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_LBS_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
289
290         return eventSize;
291 }
292
293
294 int MsgRegSyncMLMsgOperationCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
295 {
296         // input check
297         if( !pCmd || !ppEvent)
298                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
299
300         // Get Message Request
301         MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCmdData = (MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S*) pCmd->cmdData;
302         MSG_DEBUG("Registering SyncML Msg ooperation CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
303
304         // storing dst fd in list
305         MsgTransactionManager::instance()->setSyncMLMsgOperationCB(pCmdData);
306
307         // Make Event Data
308         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB, MSG_SUCCESS, (void**)ppEvent);
309
310         return eventSize;
311 }
312
313
314 int MsgRegStorageChangeCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
315 {
316         // input check
317         if( !pCmd || !ppEvent)
318                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
319
320         // Get Message Request
321         int listenerFd = *((int*) pCmd->cmdData);
322         MSG_DEBUG("Registering storage change CB for %d", listenerFd);
323
324         // storing dst fd in list
325         MsgTransactionManager::instance()->setStorageChangeCB(listenerFd);
326
327         // Make Event Data
328         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_STORAGE_CHANGE_CB, MsgException::SUCCESS, (void**)ppEvent);
329
330         return eventSize;
331 }
332
333
334 int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
335 {
336         // input check
337         if (!pCmd || !ppEvent)
338                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
339
340         // Get Message Request
341         MSG_SENT_STATUS_S* pStatus = (MSG_SENT_STATUS_S*) pCmd->cmdData;
342
343         MSG_DEBUG("REQID %d, STATUS %d", pStatus->reqId, pStatus->status);
344
345         // storing dst fd in list
346         MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(pStatus->reqId);
347
348         // when no sent status cb is found (in case of mobile tracker)
349         if (!prxInfo)
350         {
351                 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
352         }
353
354         MSG_DEBUG("REQID %d, listenerFD %d, handleAddr %x, msgId %d", pStatus->reqId, prxInfo->listenerFd, prxInfo->handleAddr, prxInfo->sentMsgId);
355
356         // if APP send and quit(not exist at this time), don't send the data up.
357         if (prxInfo->handleAddr == 0)
358         {
359                 // just making data which will be passed to plugin. it indicates "handling evt success"
360                 MsgTransactionManager::instance()->delProxyInfo(pStatus->reqId);
361
362                 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
363         }
364
365         unsigned int ret[3] = {0}; //3// reqid, status, object
366
367         ret[0] = pStatus->reqId;
368         ret[1] = pStatus->status;
369         ret[2] = prxInfo->handleAddr;
370
371         // Make Event Data for APP
372         int eventSize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
373
374         // Send to listener thread, here
375         MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventSize);
376
377         MsgTransactionManager::instance()->delProxyInfo(pStatus->reqId);
378
379         return eventSize;
380 }
381
382
383 int MsgIncomingMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
384 {
385         MSG_BEGIN();
386
387         msg_error_t err = MSG_SUCCESS;
388         int eventSize = 0;
389         bool sendNoti = true;
390
391         // input check
392         if (!pCmd || !ppEvent)
393                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
394
395         // Get Incoming Message
396         MSG_MESSAGE_INFO_S msgInfo;
397         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
398
399         memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_INFO_S));
400
401         // normal process
402         err = MsgHandleIncomingMsg(&msgInfo, &sendNoti);
403
404         // broadcast to listener threads, here
405         msg_id_list_s msgIdList;
406         msg_message_id_t msgIds[1];
407         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
408
409         msgIdList.nCount = 1;
410         msgIds[0] = msgInfo.msgId;
411         msgIdList.msgIdList = msgIds;
412
413         if (sendNoti == true) {
414                 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
415                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
416         } else if (msgInfo.folderId == MSG_SPAMBOX_ID) {
417                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
418         }
419
420         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
421
422         MSG_END();
423
424         return eventSize;
425 }
426
427 int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
428 {
429         MSG_BEGIN();
430         msg_error_t err = MSG_SUCCESS;
431         int eventsize = 0;
432
433         MSG_MESSAGE_INFO_S msgInfo = {0};
434         msg_request_id_t reqID;
435
436         memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_INFO_S));
437         memcpy(&reqID, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), sizeof(msg_request_id_t));
438
439         MSG_DEBUG(" pMsg = %s, pReqId = %d ", msgInfo.msgData, reqID);
440         MSG_DEBUG(" msgtype subtype is [%d]", msgInfo.msgType.subType);
441
442         // For Storage change callback
443         msg_id_list_s msgIdList;
444         msg_message_id_t msgIds[1];
445         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
446
447         msgIdList.nCount = 1;
448         msgIds[0] = msgInfo.msgId;
449         msgIdList.msgIdList = msgIds;
450
451         err = MsgStoGetAddrInfo(msgInfo.msgId, &(msgInfo.addressList[0]));
452
453         if (err == MSG_SUCCESS) {
454                 MSG_DEBUG("MmsStoGetAddrInfo() success.");
455                 msgInfo.nAddressCnt = 1;
456         } else {
457                 MSG_DEBUG("MmsStoGetAddrInfo() fail.");
458         }
459
460         if(msgInfo.msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || msgInfo.msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
461
462                 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
463
464                 if(err != MSG_SUCCESS)
465                         return err;
466
467                 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
468
469                 if (pMmsRecvData->msgAppId.valid == true) {
470                         MSG_DEBUG("valid : %d, appId : %s", pMmsRecvData->msgAppId.valid, pMmsRecvData->msgAppId.appId);
471                 } else {
472                         msgInfo.bTextSms = true;
473                         msgInfo.dataSize = 0 ;
474                         memset(msgInfo.msgData, 0x00, sizeof(MMS_RECV_DATA_S));
475                 }
476
477                 eventsize = MsgMakeEvent(&msgInfo, sizeof(MSG_MESSAGE_INFO_S), MSG_EVENT_PLG_INCOMING_MMS_CONF, msgInfo.networkStatus, (void**)ppEvent);
478
479                 // broadcast to listener threads, here
480                 MsgTransactionManager::instance()->broadcastMMSConfCB(msgInfo.networkStatus, &msgInfo, pMmsRecvData);
481                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
482         } else if (msgInfo.msgType.subType == MSG_SENDREQ_MMS || msgInfo.msgType.subType == MSG_SENDCONF_MMS) {
483                 MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(reqID);
484
485                 // when no sent status cb is found (in case of mobile tracker)
486                 if (!prxInfo) {
487                         MSG_DEBUG("prxInfo is NULL");
488                         eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
489                 } else {
490                         // No need to update javaMMS sent messages
491                         javamms_list& listenerList = MsgTransactionManager::instance()->getJavaMMSList();
492                         javamms_list::iterator it = listenerList.begin();
493
494                         MSG_DEBUG("listenerList size:%d ",listenerList.size());
495
496                         if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL && msgInfo.msgType.subType == MSG_SENDREQ_MMS) {
497                                 for ( ; it != listenerList.end() ; it++) {
498                                         if (strstr(it->pduFileName, "JAVA")) {
499                                                 MSG_DEBUG("JAVA MMS fileName:%s", it->pduFileName);
500                                                 MsgDeleteFile(it->pduFileName);         // ipc
501                                                 listenerList.erase(it);
502                                                 goto __BYPASS_UPDATE;
503                                         }
504                                 }
505                         } else {
506                                 //msgData has MMS_RECV_DATA_S
507                                 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
508
509                                 for ( ; it != listenerList.end() ; it++) {
510                                         if(!strcmp(it->id, pMmsRecvData->szTrID)) {
511                                                 MSG_DEBUG("find sent JAVA MMS message trId:%s from listener list trId:%s",pMmsRecvData->szTrID, it->id);
512                                                 MsgDeleteFile(it->pduFileName); // ipc
513                                                 listenerList.erase(it);
514                                                 goto __BYPASS_UPDATE;
515                                         }
516                                 }
517                         }
518                 }
519
520                 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
521
522                 if(err != MSG_SUCCESS)
523                         return err;
524
525 __BYPASS_UPDATE:
526                 if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL) {
527                         MSG_DEBUG("message-dialog: send fail");
528                         MsgInsertTicker("Sending multimedia message failed.", SENDING_MULTIMEDIA_MESSAGE_FAILED);
529                 } else {
530                         MSG_DEBUG("message-dialog: send success");
531                         MsgInsertTicker("Multimedia message sent.", MULTIMEDIA_MESSAGE_SENT);
532
533                         MSG_DEBUG("Enter MsgAddPhoneLog() : msgInfo.addressList[0].addressVal [%s]", msgInfo.addressList[0].addressVal);
534                         MsgAddPhoneLog(&msgInfo);
535                 }
536
537                 if (prxInfo) {
538                         if (prxInfo->handleAddr == 0) {
539                                 // just making data which will be passed to plugin. it indicates "handling evt success"
540                                 MsgTransactionManager::instance()->delProxyInfo(reqID);
541
542                                 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
543                         }
544
545                         unsigned int ret[3] = {0}; //3// reqid, status, object
546
547                         ret[0] = reqID;
548                         ret[1] = msgInfo.networkStatus;
549                         ret[2] = prxInfo->handleAddr;
550
551                         // Make Event Data for APP
552                         eventsize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
553
554                         // Send to listener thread, here
555                         MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventsize);
556
557                         MsgTransactionManager::instance()->delProxyInfo(reqID);
558                 }
559
560                 msgInfo.bTextSms = true;
561                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
562         }
563
564         MSG_END();
565         return eventsize;
566 }
567
568 int MsgIncomingPushMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
569 {
570         MSG_BEGIN();
571         // input check
572         if (!pCmd || !ppEvent)
573                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
574
575         MSG_PUSH_MESSAGE_DATA_S pushData;
576         memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
577
578         // Get Incoming Message
579         memcpy(&pushData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_PUSH_MESSAGE_DATA_S));
580
581         int eventSize = 0;
582
583         // broadcast to listener threads, here
584         MsgTransactionManager::instance()->broadcastPushMsgCB(MSG_SUCCESS, &pushData);
585
586         // Make Event Data
587         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
588
589         MSG_END();
590         return eventSize;
591 }
592
593 int MsgIncomingCBMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
594 {
595         MSG_BEGIN();
596
597         msg_error_t err = MSG_SUCCESS;
598         int eventSize = 0;
599
600         // input check
601         if (!pCmd || !ppEvent)
602                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
603
604         // Get Incoming Message
605         MSG_CB_MSG_S cbMsg;
606         memset(&cbMsg, 0x00, sizeof(MSG_CB_MSG_S));
607
608         memcpy(&cbMsg, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_CB_MSG_S));
609
610         msg_id_list_s msgIdList;
611         msg_message_id_t msgIds[1];
612         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
613
614         MsgTransactionManager::instance()->broadcastCBMsgCB(err, &cbMsg);
615
616         bool bSave = false;
617         MsgSettingGetBool(CB_SAVE, &bSave);
618
619         if(bSave && cbMsg.type!= MSG_ETWS_SMS) {
620                 msgIdList.nCount = 1;
621                 msgIds[0] = (msg_message_id_t)cbMsg.messageId;
622                 msgIdList.msgIdList = msgIds;
623                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
624         }
625         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)ppEvent);
626
627         MSG_END();
628
629         return eventSize;
630 }
631
632 int MsgIncomingSyncMLMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
633 {
634         // input check
635         if (!pCmd || !ppEvent)
636                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
637
638         MSG_SYNCML_MESSAGE_DATA_S syncMLData;
639         memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
640
641         // Get Incoming Message
642         memcpy(&syncMLData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_SYNCML_MESSAGE_DATA_S));
643
644         int eventSize = 0;
645
646         // broadcast to listener threads, here
647         MsgTransactionManager::instance()->broadcastSyncMLMsgCB(MSG_SUCCESS, &syncMLData);
648
649         // Make Event Data
650         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
651
652         return eventSize;
653 }
654
655
656 int MsgIncomingLBSMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
657 {
658         int eventSize = 0;
659
660         // input check
661         if (!pCmd || !ppEvent)
662                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
663
664         MSG_LBS_MESSAGE_DATA_S lbsData;
665         memset(&lbsData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
666
667         // Get Incoming Message
668         memcpy(&lbsData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_LBS_MESSAGE_DATA_S));
669
670         // broadcast to listener threads, here
671         MsgTransactionManager::instance()->broadcastLBSMsgCB(MSG_SUCCESS, &lbsData);
672
673         // Make Event Data
674         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
675
676         return eventSize;
677 }
678
679
680 int MsgSyncMLMsgOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
681 {
682         msg_error_t err = MSG_SUCCESS;
683
684         char* encodedData = NULL;
685         AutoPtr<char> buf(&encodedData);
686
687         int eventSize = 0;
688
689         msg_message_id_t msgId = 0;
690         int extId = 0;
691
692         // input check
693         if (!pCmd || !ppEvent)
694                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
695
696         // Get Data
697         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
698         memcpy(&extId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(int));
699
700         err = MsgStoGetSyncMLExtId(msgId, &extId);
701
702         if (err == MSG_SUCCESS)
703         {
704                 MSG_DEBUG("Command Handle Success : MsgStoGetSyncMLExtId()");
705
706                 // broadcast to listener threads, here
707                 MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, msgId, extId);
708         }
709         else
710         {
711                 MSG_DEBUG("Command Handle Fail : MsgStoGetSyncMLExtId()");
712         }
713
714         // Make Event Data to Client
715         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SYNCML_OPERATION, err, (void**)ppEvent);
716
717         return eventSize;
718 }
719
720
721 int MsgStorageChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
722 {
723         // input check
724         if (!pCmd || !ppEvent)
725                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
726
727         msg_storage_change_type_t storageChangeType;
728
729         MSG_MESSAGE_INFO_S msgInfo;
730         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
731
732         memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_INFO_S));
733         memcpy(&storageChangeType, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), sizeof(msg_storage_change_type_t));
734
735         char* encodedData = NULL;
736         AutoPtr<char> buf(&encodedData);
737
738         int eventSize = 0;
739
740         MSG_DEBUG("storageChangeType : [%d], msg Id : [%d]", storageChangeType, msgInfo.msgId);
741
742         // broadcast to listener threads, here
743         msg_id_list_s msgIdList;
744         msg_message_id_t msgIds[1];
745         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
746
747         msgIdList.nCount = 1;
748         msgIds[0] = msgInfo.msgId;
749         msgIdList.msgIdList = msgIds;
750
751         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, storageChangeType, &msgIdList);
752
753         // Make Event Data to Client
754         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_STORAGE_CHANGE_IND, MSG_SUCCESS, (void**)ppEvent);
755
756         return eventSize;
757 }