update tizen source
[framework/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerTransport.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #include <time.h>
32
33 #include "MsgDebug.h"
34 #include "MsgException.h"
35 #include "MsgUtilFile.h"
36 #include "MsgContact.h"
37 #include "MsgSoundPlayer.h"
38 #include "MsgGconfWrapper.h"
39 #include "MsgNotificationWrapper.h"
40 #include "MsgUtilFunction.h"
41 #include "MsgSubmitHandler.h"
42 #include "MsgDeliverHandler.h"
43 #include "MsgStorageHandler.h"
44 #include "MsgTransManager.h"
45 #include "MsgPluginManager.h"
46 #include "MsgCmdHandler.h"
47
48
49 /*==================================================================================================
50                                      FUNCTION IMPLEMENTATION
51 ==================================================================================================*/
52 int MsgSubmitReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
53 {
54         MSG_ERROR_T err = MSG_SUCCESS;
55         bool bNewMsg = true;
56
57         int eventSize = 0;
58
59         MSG_REQUEST_INFO_S reqInfo = {0,};
60         MSG_PROXY_INFO_S proxyInfo = {0,};
61
62         // Get Message Request
63         memcpy(&reqInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_REQUEST_INFO_S));
64
65         // Storing Request ID, Proxy Info for Sent Status CNF
66         memcpy(&proxyInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)), sizeof(MSG_PROXY_INFO_S));
67
68         if (reqInfo.msgInfo.msgId > 0)
69                 bNewMsg = false;
70
71         // Submit Request
72         err = MsgSubmitReq(&reqInfo, false);
73
74         if (err == MSG_SUCCESS){
75                 MSG_DEBUG("Command Handle Success : MsgSubmitReq()");
76         } else {
77                 MSG_DEBUG("Command Handle Fail : MsgSubmitReq()");
78         }
79
80         int reqId = reqInfo.reqId;
81         proxyInfo.sentMsgId = reqInfo.msgInfo.msgId;
82
83         MSG_DEBUG("REQID: %d, MSGID: %d", reqId, proxyInfo.sentMsgId);
84
85         if (reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE) {
86                 MsgTransactionManager::instance()->insertSentMsg(reqId, &proxyInfo);
87         } else if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE) {
88                 // Retrieve MMS shall not be kept in sentMsg
89                 if ((reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_MMS) ||
90                         (reqInfo.msgInfo.msgType.subType == MSG_FORWARD_MMS) ||
91                         (reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS))
92                 MsgTransactionManager::instance()->insertSentMsg(reqId, &proxyInfo);
93         }
94
95         // keep transaction Id list for distinguish java MMS sent msg when sendconf received
96         if (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE &&
97                 reqInfo.msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS) {
98                 MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S trId={0};
99                 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);
100
101                 char* pFileName;
102                 pFileName = strstr(reqInfo.msgInfo.msgData, "MSG_");
103                 strncpy(trId.pduFileName, pFileName, MAX_COMMON_INFO_SIZE);
104
105                 MSG_DEBUG("java MMS msg trId:%s filepath:%s ",trId.id, reqInfo.msgInfo.msgData);
106
107                 MsgTransactionManager* tm = MsgTransactionManager::instance();
108                 tm->setJavaMMSList(&trId);
109         }
110
111         // Make Event Data
112         eventSize = MsgMakeEvent(&reqId, sizeof(reqId), MSG_EVENT_SUBMIT_REQ, err, (void**)ppEvent);
113
114         /* reject_msg_support */
115         if(((reqInfo.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS) &&
116                  (reqInfo.msgInfo.msgType.mainType == MSG_MMS_TYPE)))
117                 err = MsgStoDeleteMessage(reqInfo.msgInfo.msgId, true);
118         /* reject_msg_support */
119
120         /** send storage CB */
121         if (err == MSG_SUCCESS && bNewMsg && reqInfo.msgInfo.msgPort.valid == false) {
122
123                 MSG_MSGID_LIST_S msgIdList;
124                 MSG_MESSAGE_ID_T msgIds[1];
125                 memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
126
127                 msgIdList.nCount = 1;
128                 msgIds[0] = reqInfo.msgInfo.msgId;
129                 msgIdList.msgIdList = msgIds;
130
131                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
132         }
133         return eventSize;
134 }
135
136
137 int MsgCancelReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
138 {
139         MSG_ERROR_T err = MSG_SUCCESS;
140
141         int eventSize = 0;
142
143         // Get Request ID
144         MSG_REQUEST_ID_T* reqId = (MSG_REQUEST_ID_T*)pCmd->cmdData;
145
146         // Cancel Request
147         err = MsgCancelReq(*reqId);
148
149         if (err == MSG_SUCCESS)
150         {
151                 MSG_DEBUG("Command Handle Success : MsgSubCancelReq()");
152         }
153         else
154         {
155                 MSG_DEBUG("Command Handle Fail : MsgSubCancelReq()");
156         }
157
158         // Make Event Data
159         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_CANCEL_REQ, err, (void**)ppEvent);
160
161         return eventSize;
162 }
163
164
165 int MsgRegSentStatusCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
166 {
167         // input check
168         if( !pCmd || !ppEvent)
169                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
170
171         // Get Message Request
172         int listenerFd = *((int*) pCmd->cmdData);
173         MSG_DEBUG("Registering sent status CB for %d", listenerFd);
174
175         // storing dst fd in list
176         MsgTransactionManager::instance()->setSentStatusCB(listenerFd);
177
178         // Make Event Data
179         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SENT_STATUS_CB, MSG_SUCCESS, (void**)ppEvent);
180
181         return eventSize;
182 }
183
184
185 int MsgRegIncomingMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
186 {
187         // input check
188         if( !pCmd || !ppEvent)
189                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
190
191         // Get Message Request
192         MSG_CMD_REG_INCOMING_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_MSG_CB_S*) pCmd->cmdData;
193         MSG_DEBUG("Registering incoming SMS CB for fd %d mType %d port %d", pCmdData->listenerFd, pCmdData->msgType, pCmdData->port);
194
195         // storing dst fd in list
196         MsgTransactionManager::instance()->setIncomingMsgCB(pCmdData);
197
198         // Make Event Data
199         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
200
201         return eventSize;
202 }
203
204
205 int MsgRegIncomingMMSConfMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
206 {
207         // input check
208         if( !pCmd || !ppEvent)
209                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
210
211         // Get Message Request
212         MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S*) pCmd->cmdData;
213         MSG_DEBUG("Registering incoming MMS Conf CB for fd:%d mType:%d appId:%s", pCmdData->listenerFd, pCmdData->msgType, pCmdData->appId);
214
215         // storing dst fd in list
216         MsgTransactionManager::instance()->setMMSConfMsgCB(pCmdData);
217
218         // Make Event Data
219         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
220
221         return eventSize;
222 }
223
224
225 int MsgRegIncomingSyncMLMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
226 {
227         // input check
228         if( !pCmd || !ppEvent)
229                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
230
231         // Get Message Request
232         MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S*) pCmd->cmdData;
233         MSG_DEBUG("Registering incoming Sync ML Msg CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
234
235         // storing dst fd in list
236         MsgTransactionManager::instance()->setSyncMLMsgCB(pCmdData);
237
238         // Make Event Data
239         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
240
241         return eventSize;
242 }
243
244
245 int MsgRegIncomingLBSMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
246 {
247         // input check
248         if( !pCmd || !ppEvent)
249                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
250
251         // Get Message Request
252         MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_LBS_MSG_CB_S*) pCmd->cmdData;
253         MSG_DEBUG("Registering incoming LBS Msg CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
254
255         // storing dst fd in list
256         MsgTransactionManager::instance()->setLBSMsgCB(pCmdData);
257
258         // Make Event Data
259         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_LBS_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
260
261         return eventSize;
262 }
263
264
265 int MsgRegSyncMLMsgOperationCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
266 {
267         // input check
268         if( !pCmd || !ppEvent)
269                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
270
271         // Get Message Request
272         MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCmdData = (MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S*) pCmd->cmdData;
273         MSG_DEBUG("Registering SyncML Msg ooperation CB for fd %d mType %d", pCmdData->listenerFd, pCmdData->msgType);
274
275         // storing dst fd in list
276         MsgTransactionManager::instance()->setSyncMLMsgOperationCB(pCmdData);
277
278         // Make Event Data
279         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB, MSG_SUCCESS, (void**)ppEvent);
280
281         return eventSize;
282 }
283
284
285 int MsgRegStorageChangeCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
286 {
287         // input check
288         if( !pCmd || !ppEvent)
289                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
290
291         // Get Message Request
292         int listenerFd = *((int*) pCmd->cmdData);
293         MSG_DEBUG("Registering storage change CB for %d", listenerFd);
294
295         // storing dst fd in list
296         MsgTransactionManager::instance()->setStorageChangeCB(listenerFd);
297
298         // Make Event Data
299         int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_STORAGE_CHANGE_CB, MsgException::SUCCESS, (void**)ppEvent);
300
301         return eventSize;
302 }
303
304
305 int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
306 {
307         // input check
308         if (!pCmd || !ppEvent)
309                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
310
311         // Get Message Request
312         MSG_SENT_STATUS_S* pStatus = (MSG_SENT_STATUS_S*) pCmd->cmdData;
313
314         MSG_DEBUG("REQID %d, STATUS %d", pStatus->reqId, pStatus->status);
315
316         // storing dst fd in list
317         MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(pStatus->reqId);
318
319         // when no sent status cb is found (in case of mobile tracker)
320         if (!prxInfo)
321         {
322                 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
323         }
324
325         MSG_DEBUG("REQID %d, listenerFD %d, handleAddr %x, msgId %d", pStatus->reqId, prxInfo->listenerFd, prxInfo->handleAddr, prxInfo->sentMsgId);
326
327         // if APP send and quit(not exist at this time), don't send the data up.
328         if (prxInfo->handleAddr == 0)
329         {
330                 // just making data which will be passed to plugin. it indicates "handling evt success"
331                 MsgTransactionManager::instance()->delProxyInfo(pStatus->reqId);
332
333                 //in case of scheduled message sending, scheduled msg table should be updated.
334                 MsgStoDeleteScheduledMessage(prxInfo->sentMsgId);
335
336                 return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
337         }
338
339         unsigned int ret[3] = {0}; //3// reqid, status, object
340
341         ret[0] = pStatus->reqId;
342         ret[1] = pStatus->status;
343         ret[2] = prxInfo->handleAddr;
344
345         // Make Event Data for APP
346         int eventSize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
347
348         // Send to listener thread, here
349         MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventSize);
350
351         MsgTransactionManager::instance()->delProxyInfo(pStatus->reqId);
352
353         return eventSize;
354 }
355
356
357 int MsgIncomingMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
358 {
359         MSG_BEGIN();
360
361         MSG_ERROR_T err = MSG_SUCCESS;
362         int eventSize = 0;
363         bool sendNoti = true;
364
365         // input check
366         if (!pCmd || !ppEvent)
367                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
368
369         // Get Incoming Message
370         MSG_MESSAGE_INFO_S msgInfo;
371         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
372
373         memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_INFO_S));
374
375         // normal process
376         err = MsgHandleIncomingMsg(&msgInfo, &sendNoti);
377
378         // broadcast to listener threads, here
379         MSG_MSGID_LIST_S msgIdList;
380         MSG_MESSAGE_ID_T msgIds[1];
381         memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
382
383         msgIdList.nCount = 1;
384         msgIds[0] = msgInfo.msgId;
385         msgIdList.msgIdList = msgIds;
386
387         if (sendNoti == true) {
388                 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
389                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
390         }
391
392         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
393
394         MSG_END();
395
396         return eventSize;
397 }
398
399 int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
400 {
401         MSG_BEGIN();
402         MSG_ERROR_T err = MSG_SUCCESS;
403         int eventsize = 0;
404
405         MSG_MESSAGE_INFO_S msgInfo = {0};
406         MSG_REQUEST_ID_T reqID;
407
408         memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_INFO_S));
409         memcpy(&reqID, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), sizeof(MSG_REQUEST_ID_T));
410
411         MSG_DEBUG(" pMsg = %s, pReqId = %d ", msgInfo.msgData, reqID);
412         MSG_DEBUG(" msgtype subtype is [%d]", msgInfo.msgType.subType);
413
414         // For Storage change callback
415         MSG_MSGID_LIST_S msgIdList;
416         MSG_MESSAGE_ID_T msgIds[1];
417         memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
418
419         msgIdList.nCount = 1;
420         msgIds[0] = msgInfo.msgId;
421         msgIdList.msgIdList = msgIds;
422
423         err = MsgStoGetAddrInfo(msgInfo.msgId, &(msgInfo.addressList[0]));
424
425         if (err == MSG_SUCCESS) {
426                 MSG_DEBUG("MmsStoGetAddrInfo() success.");
427                 msgInfo.nAddressCnt = 1;
428         } else {
429                 MSG_DEBUG("MmsStoGetAddrInfo() fail.");
430         }
431
432         if(msgInfo.msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || msgInfo.msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
433
434                 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
435
436                 if(err != MSG_SUCCESS)
437                         return err;
438
439                 MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
440
441                 if (pMmsRecvData->msgAppId.valid == true) {
442                         MSG_DEBUG("valid : %d, appId : %s", pMmsRecvData->msgAppId.valid, pMmsRecvData->msgAppId.appId);
443                 } else {
444                         msgInfo.bTextSms = true;
445                         msgInfo.dataSize = 0 ;
446                         memset(msgInfo.msgData, 0x00, sizeof(MMS_RECV_DATA_S));
447                 }
448
449                 eventsize = MsgMakeEvent(&msgInfo, sizeof(MSG_MESSAGE_INFO_S), MSG_EVENT_PLG_INCOMING_MMS_CONF, msgInfo.networkStatus, (void**)ppEvent);
450
451                 // broadcast to listener threads, here
452                 MsgTransactionManager::instance()->broadcastMMSConfCB(msgInfo.networkStatus, &msgInfo, pMmsRecvData);
453                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
454         } else if (msgInfo.msgType.subType == MSG_SENDREQ_MMS || msgInfo.msgType.subType == MSG_SENDCONF_MMS) {
455                 MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(reqID);
456
457                 // when no sent status cb is found (in case of mobile tracker)
458                 if (!prxInfo)
459                         return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
460
461                 // No need to update javaMMS sent messages
462                 javamms_list& listenerList = MsgTransactionManager::instance()->getJavaMMSList();
463                 javamms_list::iterator it = listenerList.begin();
464
465                 MSG_DEBUG("listenerList size:%d ",listenerList.size());
466
467                 if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL && msgInfo.msgType.subType == MSG_SENDREQ_MMS) {
468                         for ( ; it != listenerList.end() ; it++) {
469                                 if (strstr(it->pduFileName,"JAVA")) {
470                                         MSG_DEBUG("JAVA MMS fileName:%s", it->pduFileName);
471                                         MsgDeleteFile(it->pduFileName);         // ipc
472                                         listenerList.erase(it);
473                                         goto __BYPASS_UPDATE;
474                                 }
475                         }
476                 } else {
477                         //msgData has MMS_RECV_DATA_S
478                         MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
479
480                         for ( ; it != listenerList.end() ; it++) {
481                                 if(!strcmp(it->id, pMmsRecvData->szTrID)) {
482                                         MSG_DEBUG("find sent JAVA MMS message trId:%s from listener list trId:%s",pMmsRecvData->szTrID, it->id);
483                                         MsgDeleteFile(it->pduFileName); // ipc
484                                         listenerList.erase(it);
485                                         goto __BYPASS_UPDATE;
486                                 }
487                         }
488                 }
489
490                 err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
491
492                 if(err != MSG_SUCCESS)
493                         return err;
494
495 __BYPASS_UPDATE:
496                 if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL) {
497                         MSG_DEBUG("message-dialog: send fail");
498                         MsgInsertTicker("Sending multimedia message failed.", SENDING_MULTIMEDIA_MESSAGE_FAILED);
499                 } else {
500                         MSG_DEBUG("message-dialog: send success");
501                         MsgInsertTicker("Multimedia message sent.", MULTIMEDIA_MESSAGE_SENT);
502                 }
503
504                 if (prxInfo->handleAddr == 0) {
505                         // just making data which will be passed to plugin. it indicates "handling evt success"
506                         MsgTransactionManager::instance()->delProxyInfo(reqID);
507
508                         //in case of scheduled message sending, scheduled msg table should be updated.
509                         MsgStoDeleteScheduledMessage(prxInfo->sentMsgId);
510
511                         return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
512                 }
513
514                 unsigned int ret[3] = {0}; //3// reqid, status, object
515
516                 ret[0] = reqID;
517                 ret[1] = msgInfo.networkStatus;
518                 ret[2] = prxInfo->handleAddr;
519
520                 // Make Event Data for APP
521                 eventsize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
522
523                 // Send to listener thread, here
524                 MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventsize);
525
526                 MsgTransactionManager::instance()->delProxyInfo(reqID);
527
528                 msgInfo.bTextSms = true;
529                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
530         }
531
532         MSG_END();
533         return eventsize;
534 }
535
536
537 int MsgIncomingSyncMLMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
538 {
539         // input check
540         if (!pCmd || !ppEvent)
541                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
542
543         MSG_SYNCML_MESSAGE_DATA_S syncMLData;
544         memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
545
546         // Get Incoming Message
547         memcpy(&syncMLData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_SYNCML_MESSAGE_DATA_S));
548
549         int eventSize = 0;
550
551         // broadcast to listener threads, here
552         MsgTransactionManager::instance()->broadcastSyncMLMsgCB(MSG_SUCCESS, &syncMLData);
553
554         // Make Event Data
555         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
556
557         return eventSize;
558 }
559
560
561 int MsgIncomingLBSMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
562 {
563         int eventSize = 0;
564
565         // input check
566         if (!pCmd || !ppEvent)
567                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
568
569         MSG_LBS_MESSAGE_DATA_S lbsData;
570         memset(&lbsData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
571
572         // Get Incoming Message
573         memcpy(&lbsData, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_LBS_MESSAGE_DATA_S));
574
575         // broadcast to listener threads, here
576         MsgTransactionManager::instance()->broadcastLBSMsgCB(MSG_SUCCESS, &lbsData);
577
578         // Make Event Data
579         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_LBS_MSG_IND, MSG_SUCCESS, (void**)ppEvent);
580
581         return eventSize;
582 }
583
584
585 int MsgSyncMLMsgOperationHandler(const MSG_CMD_S *pCmd, char **ppEvent)
586 {
587         MSG_ERROR_T err = MSG_SUCCESS;
588
589         char* encodedData = NULL;
590         AutoPtr<char> buf(&encodedData);
591
592         int eventSize = 0;
593
594         MSG_MESSAGE_ID_T msgId = 0;
595         int extId = 0;
596
597         // input check
598         if (!pCmd || !ppEvent)
599                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
600
601         // Get Data
602         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_ID_T));
603         memcpy(&extId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_ID_T)), sizeof(int));
604
605         err = MsgStoGetSyncMLExtId(msgId, &extId);
606
607         if (err == MSG_SUCCESS)
608         {
609                 MSG_DEBUG("Command Handle Success : MsgStoGetSyncMLExtId()");
610
611                 // broadcast to listener threads, here
612                 MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, msgId, extId);
613         }
614         else
615         {
616                 MSG_DEBUG("Command Handle Fail : MsgStoGetSyncMLExtId()");
617         }
618
619         // Make Event Data to Client
620         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SYNCML_OPERATION, err, (void**)ppEvent);
621
622         return eventSize;
623 }
624
625
626 int MsgStorageChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
627 {
628         // input check
629         if (!pCmd || !ppEvent)
630                 THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
631
632         MSG_STORAGE_CHANGE_TYPE_T storageChangeType;
633
634         MSG_MESSAGE_INFO_S msgInfo;
635         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
636
637         memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_INFO_S));
638         memcpy(&storageChangeType, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), sizeof(MSG_STORAGE_CHANGE_TYPE_T));
639
640         char* encodedData = NULL;
641         AutoPtr<char> buf(&encodedData);
642
643         int eventSize = 0;
644
645         MSG_DEBUG("storageChangeType : [%d], msg Id : [%d]", storageChangeType, msgInfo.msgId);
646
647         // broadcast to listener threads, here
648         MSG_MSGID_LIST_S msgIdList;
649         MSG_MESSAGE_ID_T msgIds[1];
650         memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
651
652         msgIdList.nCount = 1;
653         msgIds[0] = msgInfo.msgId;
654         msgIdList.msgIdList = msgIds;
655
656         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, storageChangeType, &msgIdList);
657
658         // Make Event Data to Client
659         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_STORAGE_CHANGE_IND, MSG_SUCCESS, (void**)ppEvent);
660
661         return eventSize;
662 }