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