Fix issue : fail to make thumbnail
[platform/core/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerStorage.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16
17 #include <stdlib.h>
18
19 #include "MsgDebug.h"
20 #include "MsgUtilFile.h"
21 #include "MsgException.h"
22 #include "MsgCppTypes.h"
23 /*#include "MsgSoundPlayer.h" */
24 #include "MsgUtilFunction.h"
25 #include "MsgStorageHandler.h"
26 #include "MsgPluginManager.h"
27 #include "MsgTransManager.h"
28 #include "MsgCmdHandler.h"
29 #include "MsgNotificationWrapper.h"
30 #include "MsgMutex.h"
31 #include <glib.h>
32
33 /*==================================================================================================
34                                      FUNCTION IMPLEMENTATION
35 ==================================================================================================*/
36
37 MsgMutex mx;
38 int g_job_cnt = 0;
39
40 static gboolean  __refresh_noti(void *data)
41 {
42         mx.lock();
43
44         g_job_cnt--;
45
46         if (g_job_cnt <= 0) {
47                 MSG_DEBUG("## Refresh notification ##");
48                 if (MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, false, MSG_ACTIVE_NOTI_TYPE_NONE) != MSG_SUCCESS) {
49                         MSG_DEBUG("MsgRefreshNoti is failed");
50                 }
51                 g_job_cnt = 0;
52         }
53
54         mx.unlock();
55
56         return FALSE;
57 }
58
59 int MsgAddMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
60 {
61         msg_error_t err = MSG_SUCCESS;
62
63         if (!pCmd || !ppEvent) {
64                 MSG_DEBUG("pCmd or ppEvent is null");
65                 return 0;
66         }
67
68         char* encodedData = NULL;
69         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
70
71         int dataSize = 0, eventSize = 0;
72
73         MSG_MESSAGE_INFO_S msgInfo;
74         MSG_SENDINGOPT_INFO_S sendOptInfo;
75         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
76         memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
77
78         msgInfo.addressList = NULL;
79         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
80
81         MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo, &sendOptInfo);
82
83         if (msgInfo.bBackup) {
84                 err = MsgStoRestoreMessage(&msgInfo, &sendOptInfo);
85
86                 if (err == MSG_SUCCESS) {
87                         MSG_DEBUG("Command Handle Success : MsgStoRestoreMessage()");
88
89                         /* Encoding Message ID */
90                         dataSize = MsgEncodeMsgId(&(msgInfo.msgId), &encodedData);
91                 } else {
92                         MSG_DEBUG("Command Handle Fail : MsgStoRestoreMessage()");
93                 }
94         } else {
95                 /* Add Message */
96                 msgInfo.msgId = 0;
97                 err = MsgStoAddMessage(&msgInfo, &sendOptInfo);
98
99                 if (err == MSG_SUCCESS) {
100                         MSG_DEBUG("Command Handle Success : MsgStoAddMessage()");
101                         /* Encoding Message ID */
102                         dataSize = MsgEncodeMsgId(&(msgInfo.msgId), &encodedData);
103                 } else {
104                         MSG_DEBUG("Command Handle Fail : MsgStoAddMessage()");
105                 }
106         }
107
108         /*storage change CB */
109         msg_id_list_s msgIdList;
110         msg_message_id_t msgIds[1];
111         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
112
113         msgIdList.nCount = 1;
114         msgIds[0] = msgInfo.msgId;
115         msgIdList.msgIdList = msgIds;
116
117         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
118
119         /* Update unread message status */
120         if (msgInfo.folderId == MSG_INBOX_ID && msgInfo.bRead == false) {
121                 mx.lock();
122                 g_job_cnt++;
123                 g_timeout_add(300, __refresh_noti, NULL);
124                 mx.unlock();
125         }
126
127         /* Delete Temp File for Message Data */
128         if (msgInfo.bTextSms == false)
129                 MsgDeleteFile(msgInfo.msgData); /*ipc */
130
131         /* Make Event Data */
132         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_ADD_MSG, err, (void**)ppEvent);
133
134         return eventSize;
135 }
136
137
138 int MsgAddSyncMLMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
139 {
140         msg_error_t err = MSG_SUCCESS;
141
142         if (!pCmd || !ppEvent) {
143                 MSG_DEBUG("pCmd or ppEvent is null");
144                 return 0;
145         }
146
147         char* encodedData = NULL;
148         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
149
150         int dataSize = 0, eventSize = 0;
151
152         int extId = 0, pinCode = 0;
153
154         MSG_MESSAGE_INFO_S msgInfo;
155         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
156
157         msgInfo.addressList = NULL;
158         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
159
160         memcpy(&extId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
161         memcpy(&pinCode, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), sizeof(int));
162
163         MsgDecodeMsgInfo((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int), &msgInfo);
164
165         msgInfo.msgId = 0;
166         /* Add Message */
167         err = MsgStoAddSyncMLMessage(&msgInfo, extId, pinCode);
168
169         if (err == MSG_SUCCESS) {
170                 MSG_DEBUG("Command Handle Success : MsgStoAddSyncMLMessage()");
171
172                 /* Encoding Message ID */
173                 dataSize = MsgEncodeMsgId(&(msgInfo.msgId), &encodedData);
174
175                 /* broadcast to listener threads, here */
176                 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
177                 /*storage change CB */
178                 msg_id_list_s msgIdList;
179                 msg_message_id_t msgIds[1];
180                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
181
182                 msgIdList.nCount = 1;
183                 msgIds[0] = msgInfo.msgId;
184                 msgIdList.msgIdList = msgIds;
185
186                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
187         } else {
188                 MSG_DEBUG("Command Handle Fail : MsgStoAddSyncMLMessage()");
189         }
190
191         /* Make Event Data */
192         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_ADD_SYNCML_MSG, err, (void**)ppEvent);
193
194         return eventSize;
195 }
196
197
198 int MsgUpdateMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
199 {
200         msg_error_t err = MSG_SUCCESS;
201
202         if (!pCmd || !ppEvent) {
203                 MSG_DEBUG("pCmd or ppEvent is null");
204                 return 0;
205         }
206
207         int eventSize = 0;
208
209         MSG_MESSAGE_INFO_S msgInfo;
210         MSG_SENDINGOPT_INFO_S sendOptInfo;
211         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
212         memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
213
214         msgInfo.addressList = NULL;
215         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
216
217         MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo, &sendOptInfo);
218
219         /* Update Message */
220         err = MsgStoUpdateMessage(&msgInfo, &sendOptInfo);
221
222         if (err == MSG_SUCCESS)
223                 MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
224         else
225                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateMessage()");
226
227         /* Delete Temp File for Message Data */
228         if (msgInfo.bTextSms == false)
229                 MsgDeleteFile(msgInfo.msgData); /*ipc */
230
231         /*storage change CB */
232         msg_id_list_s msgIdList;
233         msg_message_id_t msgIds[1];
234         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
235
236         msgIdList.nCount = 1;
237         msgIds[0] = msgInfo.msgId;
238         msgIdList.msgIdList = msgIds;
239
240         MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
241
242         /* Make Event Data */
243         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_MSG, err, (void**)ppEvent);
244
245         return eventSize;
246 }
247
248
249 int MsgUpdateReadStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
250 {
251         msg_error_t err = MSG_SUCCESS;
252
253         if (!pCmd || !ppEvent) {
254                 MSG_DEBUG("pCmd or ppEvent is null");
255                 return 0;
256         }
257
258         int eventSize = 0;
259
260         msg_message_id_t msgId;
261         bool readStatus;
262
263         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
264         memcpy(&readStatus, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(bool));
265
266         /* Update Read Status */
267         err = MsgStoUpdateReadStatus(msgId, readStatus);
268
269         MSG_DEBUG("message id = [%d], readStatus = [%d]", msgId, readStatus);
270
271         if (err == MSG_SUCCESS) {
272                 MSG_DEBUG("Command Handle Success : MsgStoUpdateReadStatus()");
273         } else {
274                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateReadStatus()");
275         }
276
277         /*storage change CB */
278         msg_id_list_s msgIdList;
279         msg_message_id_t msgIds[1];
280         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
281
282         msgIdList.nCount = 1;
283         msgIds[0] = msgId;
284         msgIdList.msgIdList = msgIds;
285
286         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
287
288         /* Make Event Data */
289         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_READ, err, (void**)ppEvent);
290
291         return eventSize;
292 }
293
294
295 int MsgUpdateThreadReadStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
296 {
297         msg_error_t err = MSG_SUCCESS;
298
299         if (!pCmd || !ppEvent) {
300                 MSG_DEBUG("pCmd or ppEvent is null");
301                 return 0;
302         }
303
304         int eventSize = 0;
305
306         msg_thread_id_t threadId;
307         int unReadCnt = 0;
308
309         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_thread_id_t));
310
311         MsgStoGetThreadUnreadCnt(threadId, &unReadCnt);
312
313         MSG_DEBUG("unReadCnt [%d]", unReadCnt);
314
315         if (unReadCnt > 0) {
316                 msg_id_list_s msgIdList;
317                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
318
319                 err = MsgStoUpdateThreadReadStatus(threadId, &msgIdList);
320
321                 if (err == MSG_SUCCESS) {
322                         MSG_DEBUG("Command Handle Success : MsgStoUpdateThreadReadStatus()");
323                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
324                 } else {
325                         MSG_DEBUG("Command Handle Fail : MsgStoUpdateThreadReadStatus()");
326                 }
327
328                 if(msgIdList.msgIdList != NULL)
329                         delete [] (char*)msgIdList.msgIdList;
330         }
331
332         /* delete report notification */
333         if (err == MSG_SUCCESS) {
334                 MsgDbHandler *dbHandle = getDbHandle();
335                 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
336                 char sqlQuery[MAX_QUERY_LEN+1];
337
338                 memset(tempAddr, 0x00, sizeof(tempAddr));
339                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
340                 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.ADDRESS_VAL FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND A.CONV_ID = %d;"
341                                 , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, threadId);
342
343                 err = dbHandle->prepareQuery(sqlQuery);
344
345                 if (err == MSG_SUCCESS) {
346                         err = dbHandle->stepQuery();
347
348                         if (err == MSG_ERR_DB_ROW) {
349                                 snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
350                                 MSG_SEC_DEBUG("Updated address = %s", tempAddr);
351                                 MsgDeleteReportNotification(tempAddr);
352                                 err = MSG_SUCCESS;
353                         }
354                 }
355
356                 dbHandle->finalizeQuery();
357         }
358
359         /* Make Event Data */
360         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_THREAD_READ, err, (void**)ppEvent);
361
362         return eventSize;
363 }
364
365
366 int MsgUpdateProtectedStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
367 {
368         msg_error_t err = MSG_SUCCESS;
369
370         if (!pCmd || !ppEvent) {
371                 MSG_DEBUG("pCmd or ppEvent is null");
372                 return 0;
373         }
374
375         int eventSize = 0;
376
377         msg_message_id_t msgId;
378         bool protectedStatus;
379
380         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
381         memcpy(&protectedStatus, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(bool));
382
383         /* Update Protected Status */
384         err = MsgStoUpdateProtectedStatus(msgId, protectedStatus);
385
386         if (err == MSG_SUCCESS) {
387                 MSG_DEBUG("Command Handle Success : MsgStoUpdateProtectedStatus()");
388         } else {
389                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateProtectedStatus()");
390         }
391
392         /*storage change CB */
393         msg_id_list_s msgIdList;
394         msg_message_id_t msgIds[1];
395         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
396
397         msgIdList.nCount = 1;
398         msgIds[0] = msgId;
399         msgIdList.msgIdList = msgIds;
400
401         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
402
403         /* Make Event Data */
404         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_PROTECTED, err, (void**)ppEvent);
405
406         return eventSize;
407 }
408
409
410 int MsgDeleteMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
411 {
412         msg_error_t err = MSG_SUCCESS;
413
414         if (!pCmd || !ppEvent) {
415                 MSG_DEBUG("pCmd or ppEvent is null");
416                 return 0;
417         }
418
419         int eventSize = 0;
420
421         int extId = 0;
422
423         msg_message_id_t* msgId = (msg_message_id_t*)pCmd->cmdData;
424
425         MsgStoGetSyncMLExtId(*msgId, &extId);
426
427         /* Delete Message */
428         err = MsgStoDeleteMessage(*msgId, true);
429
430         if (err == MSG_SUCCESS) {
431                 MSG_DEBUG("Command Handle Success : MsgStoDeleteMessage()");
432
433                 if(extId > 0) {
434                         /* broadcast to listener threads, here */
435                         MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, -1, extId);
436                 }
437
438                 msg_id_list_s msgIdList;
439                 msg_message_id_t msgIds[1];
440                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
441
442                 msgIdList.nCount = 1;
443                 msgIds[0] = *msgId;
444                 msgIdList.msgIdList = msgIds;
445
446                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
447         } else {
448                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteMessage()");
449         }
450
451         /* Make Event Data */
452         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_MSG, err, (void**)ppEvent);
453
454         return eventSize;
455 }
456
457
458 int MsgDeleteAllMessageInFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
459 {
460         msg_error_t err = MSG_SUCCESS;
461
462         if (!pCmd || !ppEvent) {
463                 MSG_DEBUG("pCmd or ppEvent is null");
464                 return 0;
465         }
466
467         int eventSize = 0;
468
469         msg_folder_id_t* folderId = (msg_folder_id_t*)pCmd->cmdData;
470
471         bool bOnlyDB;
472         memcpy(&bOnlyDB, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_folder_id_t)), sizeof(bool));
473
474
475         msg_id_list_s msgIdList;
476         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
477
478         /* Delete Message */
479         err = MsgStoDeleteAllMessageInFolder(*folderId, bOnlyDB, &msgIdList);
480
481         if (err == MSG_SUCCESS) {
482                 MSG_DEBUG("Command Handle Success : MsgStoDeleteAllMessageInFolder()");
483                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
484                 if(msgIdList.msgIdList != NULL)
485                         delete [] (char*)msgIdList.msgIdList;
486         } else {
487                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteAllMessageInFolder()");
488         }
489
490         /* Make Event Data */
491         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELALL_MSGINFOLDER, err, (void**)ppEvent);
492
493         return eventSize;
494 }
495
496
497 int MsgDeleteMessageByListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
498 {
499         msg_error_t err = MSG_SUCCESS;
500
501         if (!pCmd || !ppEvent) {
502                 MSG_DEBUG("pCmd or ppEvent is null");
503                 return 0;
504         }
505
506         int eventSize = 0;
507
508         msg_id_list_s msgIdList;
509         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
510
511         memcpy(&msgIdList.nCount, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
512
513         MSG_DEBUG("msgIdList.nCount [%d]", msgIdList.nCount);
514
515         msg_message_id_t msgIds[msgIdList.nCount];
516         memset(msgIds, 0x00, sizeof(msgIds));
517
518         msgIdList.msgIdList = msgIds;
519
520         for (int i = 0; i < msgIdList.nCount; i++) {
521                 memcpy(&msgIds[i], (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(msg_message_id_t)*i), sizeof(msg_message_id_t));
522         }
523
524         /* Delete Message */
525         err = MsgStoDeleteMessageByList(&msgIdList);
526
527         if (err == MSG_SUCCESS) {
528                 MSG_DEBUG("Command Handle Success : MsgStoDeleteMessageByList()");
529                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
530         } else {
531                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteMessageByList()");
532         }
533
534         /* Make Event Data */
535         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_MESSAGE_BY_LIST, err, (void**)ppEvent);
536
537         return eventSize;
538 }
539
540
541 int MsgMoveMessageToFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
542 {
543         msg_error_t err = MSG_SUCCESS;
544
545         if (!pCmd || !ppEvent) {
546                 MSG_DEBUG("pCmd or ppEvent is null");
547                 return 0;
548         }
549
550         int eventSize = 0;
551
552         msg_message_id_t msgId;
553         msg_folder_id_t folderId;
554
555         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
556         memcpy(&folderId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(msg_folder_id_t));
557
558         /* Move Message */
559         err = MsgStoMoveMessageToFolder(msgId, folderId);
560
561         if (err == MSG_SUCCESS) {
562                 MSG_DEBUG("Command Handle Success : MsgStoMoveMessageToFolder()");
563
564                 msg_id_list_s msgIdList;
565                 msg_message_id_t msgIds[1];
566                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
567
568                 msgIdList.nCount = 1;
569                 msgIds[0] = msgId;
570                 msgIdList.msgIdList = msgIds;
571
572                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
573         } else {
574                 MSG_DEBUG("Command Handle Fail : MsgStoMoveMessageToFolder()");
575         }
576
577         /* Make Event Data */
578         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_MOVE_MSGTOFOLDER, err, (void**)ppEvent);
579
580         return eventSize;
581 }
582
583
584 int MsgMoveMessageToStorageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
585 {
586         msg_error_t err = MSG_SUCCESS;
587
588         if (!pCmd || !ppEvent) {
589                 MSG_DEBUG("pCmd or ppEvent is null");
590                 return 0;
591         }
592
593         int eventSize = 0;
594
595         msg_message_id_t msgId;
596         msg_storage_id_t storageId;
597
598         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
599         memcpy(&storageId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(msg_storage_id_t));
600
601         /* Move Message */
602         err = MsgStoMoveMessageToStorage(msgId, storageId);
603
604         if (err == MSG_SUCCESS) {
605                 MSG_DEBUG("Command Handle Success : MsgStoMoveMessageToStorage()");
606         } else {
607                 MSG_DEBUG("Command Handle Fail : MsgStoMoveMessageToStorage()");
608         }
609
610         /* Make Event Data */
611         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_MOVE_MSGTOSTORAGE, err, (void**)ppEvent);
612
613         return eventSize;
614 }
615
616
617 int MsgCountMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
618 {
619         msg_error_t err = MSG_SUCCESS;
620
621         if (!pCmd || !ppEvent) {
622                 MSG_DEBUG("pCmd or ppEvent is null");
623                 return 0;
624         }
625
626         char* encodedData = NULL;
627         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
628
629         int dataSize = 0, eventSize = 0;
630
631         /* Get Folder ID */
632         msg_folder_id_t* folderId = (msg_folder_id_t*)pCmd->cmdData;
633
634         /* Get Message Count */
635         MSG_COUNT_INFO_S countInfo;
636
637         err = MsgStoCountMessage(*folderId, &countInfo);
638
639         if (err == MSG_SUCCESS) {
640                 MSG_DEBUG("Command Handle Success : MsgStoCountMessage()");
641
642                 /* Encoding Messaging Count Data */
643                 dataSize = MsgEncodeCountInfo(&countInfo, &encodedData);
644         } else {
645                 MSG_DEBUG("Command Handle Fail : MsgStoCountMessage()");
646         }
647
648         /* Make Event Data */
649         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_COUNT_MSG, err, (void**)ppEvent);
650
651         return eventSize;
652 }
653
654
655 int MsgCountMsgByTypeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
656 {
657         msg_error_t err = MSG_SUCCESS;
658
659         if (!pCmd || !ppEvent) {
660                 MSG_DEBUG("pCmd or ppEvent is null");
661                 return 0;
662         }
663
664         char* encodedData = NULL;
665         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
666
667         int dataSize = 0, eventSize = 0;
668
669         /* Get Folder ID */
670         MSG_MESSAGE_TYPE_S* pMsgType = (MSG_MESSAGE_TYPE_S*)pCmd->cmdData;
671
672         int nMsgCnt = 0;
673
674         /* Get Message Count */
675         err = MsgStoCountMsgByType(pMsgType, &nMsgCnt);
676
677         if (err == MSG_SUCCESS) {
678                 MSG_DEBUG("Command Handle Success : MsgStoCountMsgByType()");
679
680                 /* Encoding Messaging Count Data */
681                 dataSize = MsgEncodeCountByMsgType(nMsgCnt, &encodedData);
682         } else {
683                 MSG_DEBUG("Command Handle Fail : MsgStoCountMsgByType()");
684         }
685
686         /* Make Event Data */
687         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_COUNT_BY_MSGTYPE, err, (void**)ppEvent);
688
689         return eventSize;
690 }
691
692
693 int MsgGetMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
694 {
695         msg_error_t err = MSG_SUCCESS;
696
697         if (!pCmd || !ppEvent) {
698                 MSG_DEBUG("pCmd or ppEvent is null");
699                 return 0;
700         }
701
702         /* Get Message ID */
703         msg_message_id_t* msgId = (msg_message_id_t*)pCmd->cmdData;
704
705         char* encodedData = NULL;
706         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
707
708         int dataSize = 0, eventSize = 0;
709
710         /* Get Message */
711         MSG_MESSAGE_INFO_S msgInfo;
712         MSG_SENDINGOPT_INFO_S sendOptInfo;
713
714         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
715         memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
716
717         msgInfo.addressList = NULL;
718         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
719
720         err = MsgStoGetMessage(*msgId, &msgInfo, &sendOptInfo);
721
722         if (err == MSG_SUCCESS) {
723                 MSG_DEBUG("Command Handle Success : MsgStoGetMessage()");
724
725                 /* Encoding Message Info  Data */
726                 dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
727         } else {
728                 MSG_DEBUG("Command Handle Fail : MsgStoGetMessage()");
729         }
730
731 /*      MsgSoundPlayStop(); */
732
733         /* Make Event Data */
734         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_MSG, err, (void**)ppEvent);
735
736         return eventSize;
737 }
738
739
740 int MsgAddFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
741 {
742         msg_error_t err = MSG_SUCCESS;
743
744         if (!pCmd || !ppEvent) {
745                 MSG_DEBUG("pCmd or ppEvent is null");
746                 return 0;
747         }
748
749         int eventSize = 0;
750
751         /* Get Folder Info */
752         MSG_FOLDER_INFO_S* pFolderInfo = (MSG_FOLDER_INFO_S*)pCmd->cmdData;
753
754         /* Add Folder */
755         err = MsgStoAddFolder(pFolderInfo);
756
757         if (err == MSG_SUCCESS) {
758                 MSG_DEBUG("Command Handle Success : MsgStoAddFolder()");
759         } else {
760                 MSG_DEBUG("Command Handle Fail : MsgStoAddFolder()");
761         }
762
763         /* Make Event Data */
764         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_FOLDER, err, (void**)ppEvent);
765
766         return eventSize;
767 }
768
769
770 int MsgUpdateFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
771 {
772         msg_error_t err = MSG_SUCCESS;
773
774         if (!pCmd || !ppEvent) {
775                 MSG_DEBUG("pCmd or ppEvent is null");
776                 return 0;
777         }
778
779         int eventSize = 0;
780
781         /* Get Folder Info */
782         MSG_FOLDER_INFO_S* pFolderInfo = (MSG_FOLDER_INFO_S*)pCmd->cmdData;
783
784         /* Update Folder */
785         err = MsgStoUpdateFolder(pFolderInfo);
786
787         if (err == MSG_SUCCESS) {
788                 MSG_DEBUG("Command Handle Success : MsgStoUpdateFolder()");
789         } else {
790                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateFolder()");
791         }
792
793         /* Make Event Data */
794         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_FOLDER, err, (void**)ppEvent);
795
796         return eventSize;
797 }
798
799
800 int MsgDeleteFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
801 {
802         msg_error_t err = MSG_SUCCESS;
803
804         if (!pCmd || !ppEvent) {
805                 MSG_DEBUG("pCmd or ppEvent is null");
806                 return 0;
807         }
808
809         int eventSize = 0;
810
811         /* Get Folder Info */
812         msg_folder_id_t* pFolderInfo = (msg_folder_id_t*)pCmd->cmdData;
813
814         /* Delete Folder */
815         err = MsgStoDeleteFolder(*pFolderInfo);
816
817         if (err == MSG_SUCCESS) {
818                 MSG_DEBUG("Command Handle Success : MsgStoDeleteFolder()");
819         } else {
820                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteFolder()");
821         }
822
823         /* Make Event Data */
824         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_FOLDER, err, (void**)ppEvent);
825
826         return eventSize;
827 }
828
829
830 int MsgGetFolderListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
831 {
832         msg_error_t err = MSG_SUCCESS;
833
834         if (!pCmd || !ppEvent) {
835                 MSG_DEBUG("pCmd or ppEvent is null");
836                 return 0;
837         }
838
839         char* encodedData = NULL;
840         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
841
842         int dataSize = 0, eventSize = 0;
843
844         /* Get Storage List */
845         msg_struct_list_s folderList;
846
847         err = MsgStoGetFolderList(&folderList);
848
849         if (err == MSG_SUCCESS) {
850                 MSG_DEBUG("Command Handle Success : MsgStoGetFolderList()");
851
852                 /* Encoding Folder List Data */
853                 dataSize = MsgEncodeFolderList(&folderList, &encodedData);
854
855                 if (folderList.msg_struct_info) {
856                         msg_struct_s *msg_struct;
857                         for (int i = 0; i < folderList.nCount; i++) {
858                                 msg_struct = (msg_struct_s *)folderList.msg_struct_info[i];
859                                 if (msg_struct) {
860                                         delete (MSG_FOLDER_INFO_S *)msg_struct->data;
861                                         delete msg_struct;
862                                 }
863                         }
864                         g_free(folderList.msg_struct_info);
865                 }
866         } else {
867                 MSG_DEBUG("Command Handle Fail : MsgStoGetFolderList()");
868         }
869
870         /* Make Event Data */
871         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FOLDERLIST, err, (void**)ppEvent);
872
873         return eventSize;
874 }
875
876
877 int MsgInitSimBySatHandler(const MSG_CMD_S *pCmd, char **ppEvent)
878 {
879         msg_error_t err = MSG_SUCCESS;
880
881         if (!pCmd || !ppEvent) {
882                 MSG_DEBUG("pCmd or ppEvent is null");
883                 return 0;
884         }
885
886         int eventSize = 0;
887
888         /* Sim Init - Later */
889         /* Run msg-init-app */
890
891         /* Make Event Data */
892         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INIT_SIM_BY_SAT, err, (void**)ppEvent);
893
894         return eventSize;
895 }
896
897
898 int MsgGetThreadViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
899 {
900         msg_error_t err = MSG_SUCCESS;
901
902         if (!pCmd || !ppEvent) {
903                 MSG_DEBUG("pCmd or ppEvent is null");
904                 return 0;
905         }
906
907         MSG_SORT_RULE_S sortRule = {0};
908
909         memcpy(&sortRule, pCmd->cmdData, sizeof(MSG_SORT_RULE_S));
910
911         char* encodedData = NULL;
912         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
913
914         int dataSize = 0, eventSize = 0;
915 #if 0
916         /* Get Thread View List */
917         msg_struct_list_s msgThreadViewList;
918
919         /*err = MsgStoGetThreadViewList(&sortRule, &msgThreadViewList); */
920
921         if (err == MSG_SUCCESS) {
922                 MSG_DEBUG("Command Handle Success : MsgStoGetThreadViewList()");
923
924                 /* Encoding Folder View List Data */
925                 dataSize = MsgEncodeThreadViewList(&msgThreadViewList, &encodedData);
926
927                 MSG_DEBUG("dataSize [%d]", dataSize);
928
929                 if (msgThreadViewList.msg_struct_info) {
930                         msg_struct_s *msg_struct;
931                         for (int i = 0; i < folderList.nCount; i++) {
932                                 msg_struct = (msg_struct_s *)msgThreadViewList.msg_struct_info[i];
933                                 if (msg_struct) {
934                                         delete (MSG_THREAD_VIEW_S *)msg_struct->data;
935                                         delete msg_struct;
936                                 }
937                         }
938                         g_free(msgThreadViewList.msg_struct_info);
939                 }
940         } else {
941                 MSG_DEBUG("Command Handle Fail : MsgStoGetThreadViewList()");
942                 return err;
943         }
944 #endif
945         /* Make Event Data */
946         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_THREADVIEWLIST, err, (void**)ppEvent);
947
948         return eventSize;
949 }
950
951
952 int MsgDeleteThreadMessageListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
953 {
954         msg_error_t err = MSG_SUCCESS;
955
956         if (!pCmd || !ppEvent) {
957                 MSG_DEBUG("pCmd or ppEvent is null");
958                 return 0;
959         }
960
961         msg_thread_id_t threadId;
962         bool bIncludeProtect = false;
963         bool isSyncMLMsg = false;
964
965         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_thread_id_t));
966         memcpy(&bIncludeProtect, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), sizeof(bool));
967
968         int eventSize = 0;
969
970         isSyncMLMsg = MsgStoCheckSyncMLMsgInThread(threadId);
971
972         msg_id_list_s msgIdList;
973         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
974
975         err = MsgStoDeleteThreadMessageList(threadId, bIncludeProtect, &msgIdList);
976
977         if (err == MSG_SUCCESS) {
978                 MSG_DEBUG("Command Handle Success : MsgStoDeleteThreadMessageList()");
979
980                 if(isSyncMLMsg == true) {
981                         /* broadcast to listener threads, here */
982                         MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, -1, -1);
983                 }
984
985                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
986         } else {
987                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteThreadMessageList()");
988         }
989
990         if(msgIdList.msgIdList != NULL) {
991                 delete [] (char*)msgIdList.msgIdList;
992         }
993
994         /* Make Event Data */
995         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_THREADMESSAGELIST, err, (void**)ppEvent);
996
997         return eventSize;
998 }
999
1000
1001 int MsgSetTempAddressTableHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1002 {
1003         msg_error_t err = MSG_SUCCESS;
1004
1005         if (!pCmd || !ppEvent) {
1006                 MSG_DEBUG("pCmd or ppEvent is null");
1007                 return 0;
1008         }
1009
1010         int count = 0;
1011         memcpy(&count, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
1012
1013         MSG_ADDRESS_INFO_S addr_info[count] = {0, };
1014         memcpy(addr_info, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), sizeof(MSG_ADDRESS_INFO_S)*count);
1015
1016         int eventSize = 0;
1017
1018         err = MsgStoSetTempAddressTable(addr_info, count);
1019
1020         if (err == MSG_SUCCESS) {
1021                 MSG_DEBUG("Command Handle Success : MsgStoSetTmpAddressTable()");
1022         } else {
1023                 MSG_DEBUG("Command Handle Fail : MsgStoSetTmpAddressTable()");
1024         }
1025
1026         /* Make Event Data */
1027         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SET_TEMP_ADDRESS_TABLE, err, (void**)ppEvent);
1028
1029         MSG_END();
1030
1031         return eventSize;
1032 }
1033
1034
1035 int MsgCountMsgByContactHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1036 {
1037         msg_error_t err = MSG_SUCCESS;
1038
1039         if (!pCmd || !ppEvent) {
1040                 MSG_DEBUG("pCmd or ppEvent is null");
1041                 return 0;
1042         }
1043
1044         /* Get From address */
1045         MSG_THREAD_LIST_INDEX_S addrInfo;
1046
1047         memcpy(&addrInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_THREAD_LIST_INDEX_S));
1048
1049         char* encodedData = NULL;
1050         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1051
1052         int dataSize = 0, eventSize = 0;
1053
1054         /* Get Message Common Info */
1055         MSG_THREAD_COUNT_INFO_S threadCountInfo = {0};
1056
1057         err = MsgStoCountMsgByContact(&addrInfo, &threadCountInfo);
1058
1059         if (err == MSG_SUCCESS) {
1060                 MSG_DEBUG("Command Handle Success : MsgStoCountMsgByContact()");
1061
1062                 /* Encoding Folder View List Data */
1063                 dataSize = MsgEncodeMsgGetContactCount(&threadCountInfo, &encodedData);
1064
1065                 MSG_DEBUG("dataSize [%d]", dataSize);
1066         } else {
1067                 MSG_DEBUG("Command Handle Fail : MsgStoCountMsgByContact()");
1068         }
1069
1070         /* Make Event Data */
1071         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_CONTACT_COUNT, err, (void**)ppEvent);
1072
1073         return eventSize;
1074 }
1075
1076
1077 int MsgGetQuickPanelDataHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1078 {
1079         msg_error_t err = MSG_SUCCESS;
1080
1081         if (!pCmd || !ppEvent) {
1082                 MSG_DEBUG("pCmd or ppEvent is null");
1083                 return 0;
1084         }
1085
1086         /* Get Message ID */
1087         msg_quickpanel_type_t* type = (msg_quickpanel_type_t*)pCmd->cmdData;
1088
1089         char* encodedData = NULL;
1090         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1091
1092         int dataSize = 0, eventSize = 0;
1093
1094         /* Get Message */
1095         MSG_MESSAGE_INFO_S msgInfo;
1096         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1097
1098         msgInfo.addressList = NULL;
1099         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1100
1101         err = MsgStoGetQuickPanelData(*type, &msgInfo);
1102
1103         if (err == MSG_SUCCESS) {
1104                 MSG_DEBUG("Command Handle Success : MsgStoGetQuickPanelData()");
1105
1106                 /* Encoding Message Info Data */
1107                 dataSize = MsgEncodeMsgInfo(&msgInfo, &encodedData);
1108         } else {
1109                 MSG_DEBUG("Command Handle Fail : MsgStoGetQuickPanelData()");
1110         }
1111
1112         /* Make Event Data */
1113         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_QUICKPANEL_DATA, err, (void**)ppEvent);
1114
1115         return eventSize;
1116 }
1117
1118
1119 int MsgResetDatabaseHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1120 {
1121         msg_error_t err = MSG_SUCCESS;
1122
1123         if (!pCmd || !ppEvent) {
1124                 MSG_DEBUG("pCmd or ppEvent is null");
1125                 return 0;
1126         }
1127
1128         int eventSize = 0;
1129
1130         /* Reset DB */
1131         err = MsgStoResetDatabase();
1132
1133         if (err == MSG_SUCCESS)
1134                 MSG_DEBUG("Command Handle Success : MsgStoResetDatabase()");
1135         else
1136                 MSG_DEBUG("Command Handle Fail : MsgStoResetDatabase()");
1137
1138         /* Make Event Data */
1139         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_RESET_DB, err, (void**)ppEvent);
1140
1141         return eventSize;
1142 }
1143
1144
1145 int MsgGetMemSizeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1146 {
1147         msg_error_t err = MSG_SUCCESS;
1148
1149         if (!pCmd || !ppEvent) {
1150                 MSG_DEBUG("pCmd or ppEvent is null");
1151                 return 0;
1152         }
1153
1154         char* encodedData = NULL;
1155         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1156
1157         int dataSize = 0, eventSize = 0;
1158
1159         /* Get Memory size */
1160         unsigned int memsize = 0;
1161
1162         memsize = MsgDu(MSG_DATA_ROOT_PATH);
1163
1164         dataSize = MsgEncodeMemSize(&memsize, &encodedData);
1165
1166         /* Make Event Data */
1167         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_MEMSIZE, err, (void**)ppEvent);
1168
1169         return eventSize;
1170 }
1171
1172
1173 int MsgBackupMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1174 {
1175         msg_error_t err = MSG_SUCCESS;
1176
1177         if (!pCmd || !ppEvent) {
1178                 MSG_DEBUG("pCmd or ppEvent is null");
1179                 return 0;
1180         }
1181
1182         int eventSize = 0;
1183         char path[MSG_FILEPATH_LEN_MAX+1] = {0, };
1184         msg_message_backup_type_t type;
1185
1186         memcpy(&type, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_backup_type_t));
1187         memcpy(&path, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_backup_type_t)), sizeof(path));
1188
1189         err = MsgStoBackupMessage(type, path);
1190         if (err == MSG_SUCCESS)
1191                 MSG_DEBUG("Command Handle Success : MsgBackupMessageHandler()");
1192         else
1193                 MSG_DEBUG("Command Handle Fail : MsgBackupMessageHandler()");
1194
1195         /* Make Event Data */
1196         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_BACKUP_MESSAGE, err, (void**)ppEvent);
1197
1198         return eventSize;
1199 }
1200
1201
1202 int MsgRestoreMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1203 {
1204         msg_error_t err = MSG_SUCCESS;
1205
1206         if (!pCmd || !ppEvent) {
1207                 MSG_DEBUG("pCmd or ppEvent is null");
1208                 return 0;
1209         }
1210
1211         int eventSize = 0;
1212         msg_id_list_s *msgIdList = NULL;
1213         char path[MSG_FILEPATH_LEN_MAX+1] = {0, };
1214         memcpy(&path, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(path));
1215         MSG_DEBUG("path = %s", path);
1216
1217         /* Reset DB */
1218         err = MsgStoRestoreMessage(path, &msgIdList);
1219
1220         if (err == MSG_SUCCESS) {
1221                 MSG_DEBUG("Command Handle Success : MsgStoRestoreMessage()");
1222
1223                 if (msgIdList) {
1224                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, msgIdList);
1225
1226                         if (msgIdList->msgIdList)
1227                                 free(msgIdList->msgIdList);
1228
1229                         free(msgIdList);
1230                         msgIdList = NULL;
1231                 } else {
1232                         MSG_DEBUG("Not Exist msg id list to restore");
1233                 }
1234         } else
1235                 MSG_DEBUG("Command Handle Fail : MsgStoRestoreMessage()");
1236
1237         /* Make Event Data */
1238         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_RESTORE_MESSAGE, err, (void**)ppEvent);
1239
1240         return eventSize;
1241 }
1242
1243
1244 int MsgGetReportStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1245 {
1246         msg_error_t err = MSG_SUCCESS;
1247
1248         if (!pCmd || !ppEvent) {
1249                 MSG_DEBUG("pCmd or ppEvent is null");
1250                 return 0;
1251         }
1252
1253         /* Get Message ID */
1254         msg_message_id_t* msgId = (msg_message_id_t*)pCmd->cmdData;
1255         MSG_MESSAGE_TYPE_S msgType = {0, };
1256
1257         char* encodedData = NULL;
1258         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1259
1260         int dataSize = 0, eventSize = 0;
1261
1262         MSG_REPORT_STATUS_INFO_S *reportStatus = NULL;
1263         int report_count = 0;
1264
1265         if (MsgStoGetMsgType(*msgId, &msgType) != MSG_SUCCESS)
1266                 MSG_DEBUG("MsgStoGetMsgType is failed");
1267
1268         if (msgType.mainType == MSG_SMS_TYPE) {
1269                 err = MsgStoGetSmsReportStatus(*msgId, &report_count, &reportStatus);
1270         } else if (msgType.mainType == MSG_MMS_TYPE) {
1271                 err = MsgStoGetMmsReportStatus(*msgId, &report_count, &reportStatus);
1272         } else {
1273                 MSG_DEBUG("Message Type is unknown!");
1274                 err = MSG_ERR_INVALID_MSG_TYPE;
1275         }
1276
1277         if (err == MSG_SUCCESS) {
1278                 MSG_DEBUG("Command Handle Success : MsgGetReportStatusHandler()");
1279
1280                 /* Encoding Report Status Data */
1281                 dataSize = MsgEncodeReportStatus(reportStatus, report_count, &encodedData);
1282         } else {
1283                 MSG_DEBUG("Command Handle Fail : MsgGetReportStatusHandler()");
1284         }
1285
1286         /* Make Event Data */
1287         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_REPORT_STATUS, err, (void**)ppEvent);
1288
1289         return eventSize;
1290 }
1291
1292
1293 int MsgGetThreadIdByAddressHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1294 {
1295         msg_error_t err = MSG_SUCCESS;
1296
1297         if (!pCmd || !ppEvent) {
1298                 MSG_DEBUG("pCmd or ppEvent is null");
1299                 return 0;
1300         }
1301
1302         MSG_MESSAGE_INFO_S msgInfo;
1303         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1304
1305         msgInfo.addressList = NULL;
1306         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1307
1308         int *addrCnt = (int *)pCmd->cmdData;
1309         MSG_DEBUG("*addrCnt [%d]", *addrCnt);
1310
1311         msgInfo.nAddressCnt = *addrCnt;
1312
1313         msgInfo.addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * msgInfo.nAddressCnt];
1314
1315         for(int i = 0; i < msgInfo.nAddressCnt; i++)
1316                 memcpy(&msgInfo.addressList[i], (MSG_ADDRESS_INFO_S *)(pCmd->cmdData+sizeof(int)+(sizeof(MSG_ADDRESS_INFO_S)*i)), sizeof(MSG_ADDRESS_INFO_S));
1317
1318         char* encodedData = NULL;
1319         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1320
1321         int dataSize = 0, eventSize = 0;
1322
1323         msg_thread_id_t threadId;
1324
1325         err = MsgStoGetThreadIdByAddress(&msgInfo, &threadId);
1326
1327         if (err == MSG_SUCCESS) {
1328                 MSG_DEBUG("threadId [%d]", threadId);
1329                 MSG_DEBUG("Command Handle Success : MsgGetThreadIdByAddressHandler()");
1330
1331                 /* Encoding threadId Data */
1332                 dataSize = MsgEncodeThreadId(&threadId, &encodedData);
1333         } else {
1334                 MSG_DEBUG("Command Handle Fail : MsgGetThreadIdByAddressHandler()");
1335         }
1336
1337         /* Make Event Data */
1338         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_THREAD_ID_BY_ADDRESS, err, (void**)ppEvent);
1339
1340         return eventSize;
1341 }
1342
1343
1344 int MsgGetThreadInfoHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1345 {
1346         msg_error_t err = MSG_SUCCESS;
1347
1348         if (!pCmd || !ppEvent) {
1349                 MSG_DEBUG("pCmd or ppEvent is null");
1350                 return 0;
1351         }
1352
1353         char* encodedData = NULL;
1354         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1355
1356         int dataSize = 0;
1357         int eventSize = 0;
1358
1359         msg_thread_id_t threadId;
1360
1361         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_thread_id_t));
1362
1363         MSG_THREAD_VIEW_S threadInfo;
1364         memset(&threadInfo, 0x00, sizeof(threadInfo));
1365
1366         err = MsgStoGetThreadInfo(threadId, &threadInfo);
1367
1368         if (err == MSG_SUCCESS) {
1369                 MSG_DEBUG("Command Handle Success : MsgStoGetThreadInfo()");
1370
1371                 /* Encoding thread Info Data */
1372                 dataSize = MsgEncodeThreadInfo(&threadInfo, &encodedData);
1373         } else {
1374                 MSG_DEBUG("Command Handle Fail : MsgStoGetThreadInfo()");
1375         }
1376
1377         /* Make Event Data */
1378         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_THREAD_INFO, err, (void**)ppEvent);
1379
1380         return eventSize;
1381 }
1382
1383
1384 #ifdef MMS_REPORT_OPERATIONS
1385 int MsgCheckReadReportRequestedHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1386 {
1387         MSG_DEBUG();
1388         msg_error_t err = MSG_SUCCESS;
1389
1390         char* encodedData = NULL;
1391         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1392
1393         int dataSize = 0, eventSize = 0;
1394
1395         /* Get Message ID */
1396         msg_message_id_t* MsgId = (msg_message_id_t*)pCmd->cmdData;
1397
1398         /* Check ReadReport Is Requested */
1399         bool    bReadReportRequested;
1400
1401         bReadReportRequested = MsgStoCheckReadReportRequested(*MsgId);
1402         if (err == MSG_SUCCESS) {
1403                 MSG_DEBUG("Command Handle Success : MsgStoCheckSendReadReport()");
1404
1405                 /* Encoding ReadReportIsSent Data */
1406                 dataSize = MsgEncodeReadReportRequested(bReadReportRequested, &encodedData);
1407         } else {
1408                 MSG_DEBUG("Command Handle Fail : MsgStoCheckReadReportIsSent()");
1409         }
1410
1411         /* Make Event Data */
1412         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_CHECK_READ_REPORT_REQUESTED, err, (void**)ppEvent);
1413
1414         return eventSize;
1415 }
1416
1417
1418 int MsgCheckReadReportIsSentHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1419 {
1420         MSG_DEBUG();
1421         msg_error_t err = MSG_SUCCESS;
1422
1423         char* encodedData = NULL;
1424         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1425
1426         int dataSize = 0, eventSize = 0;
1427
1428         /* Get Message ID */
1429         msg_message_id_t* MsgId = (msg_message_id_t*)pCmd->cmdData;
1430
1431         /* Check ReadReport Is Sent */
1432         bool    bReadReportIsSent;
1433
1434         MSG_DEBUG("#### MSGID = %d ####", *MsgId);
1435
1436         bReadReportIsSent = MsgStoCheckReadReportIsSent(*MsgId);
1437         MSG_DEBUG("######## 1. bReadStatusIsSent = %d #######", bReadReportIsSent);
1438         if (err == MSG_SUCCESS) {
1439                 MSG_DEBUG("Command Handle Success : MsgStoCheckReadReportIsSent()");
1440
1441                 /* Encoding ReadReportIsSent Data */
1442                 dataSize = MsgEncodeReadReportIsSent(bReadReportIsSent, &encodedData);
1443         } else {
1444                 MSG_DEBUG("Command Handle Fail : MsgStoCheckReadReportIsSent()");
1445         }
1446
1447         /* Make Event Data */
1448         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_CHECK_READ_REPORT_IS_SENT, err, (void**)ppEvent);
1449
1450         return eventSize;
1451 }
1452
1453
1454 int MsgSetReadReportSendStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1455 {
1456         MSG_DEBUG();
1457         msg_error_t err = MSG_SUCCESS;
1458
1459         char* encodedData = NULL;
1460         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1461
1462         int dataSize = 0, eventSize = 0;
1463
1464         /* Get Message ID */
1465         msg_message_id_t msgId;
1466         int     readReportSendStatus;
1467
1468         memcpy(&msgId, (char*)pCmd + sizeof(MSG_CMD_TYPE_T), sizeof(msg_message_id_t));
1469         memcpy(&readReportSendStatus, (char*)pCmd + sizeof(MSG_CMD_TYPE_T) + sizeof(msg_message_id_t), sizeof(int));
1470
1471         /* Set Read Report Send Status */
1472         err = MsgStoSetReadReportSendStatus(msgId, readReportSendStatus);
1473
1474         if (err == MSG_SUCCESS) {
1475                 MSG_DEBUG("Command Handle Success : MsgStoUpdateReadStatus()");
1476         } else {
1477                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateReadStatus()");
1478         }
1479
1480         /* Make Event Data */
1481         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_SET_READ_REPORT_SEND_STATUS, err, (void**)ppEvent);
1482
1483         return eventSize;
1484 }
1485
1486
1487 int MsgGetMmsVersionHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1488 {
1489         MSG_DEBUG();
1490         msg_error_t err = MSG_SUCCESS;
1491
1492         char* encodedData = NULL;
1493         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1494
1495         int dataSize = 0, eventSize = 0;
1496
1497         /* Get Message ID */
1498         msg_message_id_t* MsgId = (msg_message_id_t*)pCmd->cmdData;
1499
1500         /* Check ReadReport Is Sent */
1501         int     version;
1502
1503         MSG_DEBUG("#### MSGID = %d ####", *MsgId);
1504
1505         version = MsgStoGetMmsVersion(*MsgId);
1506         MSG_DEBUG("######## 1. version = %x #######", version);
1507         if (err == MSG_SUCCESS) {
1508                 MSG_DEBUG("Command Handle Success : MsgStoCheckReadReportIsSent()");
1509
1510                 /* Encoding ReadReportIsSent Data */
1511                 dataSize = MsgEncodeMmsVersion(version, &encodedData);
1512         } else {
1513                 MSG_DEBUG("Command Handle Fail : MsgStoCheckReadReportIsSent()");
1514         }
1515
1516         /* Make Event Data */
1517         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_GET_MMS_VERSION, err, (void**)ppEvent);
1518
1519         return eventSize;
1520 }
1521
1522
1523 int MsgGetMmsStatusInfoHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1524 {
1525         MSG_DEBUG();
1526         msg_error_t err = MSG_SUCCESS;
1527
1528         char* encodedData = NULL;
1529         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
1530
1531         int dataSize = 0, eventSize = 0;
1532
1533         /* Get Message ID */
1534         msg_message_id_t* MsgId = (msg_message_id_t*)pCmd->cmdData;
1535
1536         MMS_STATUS_INFO_S mmsStatusInfo;
1537
1538         MSG_DEBUG("#### MSGID = %d ####", *MsgId);
1539
1540         err = MsgStoGetMmsStatusInfo(*MsgId, &mmsStatusInfo);
1541         if (err == MSG_SUCCESS) {
1542                 MSG_DEBUG("Command Handle Success : MsgGetMmsStatusInfoHandler()");
1543
1544                 /* Encoding ReadReportIsSent Data */
1545                 dataSize = MsgEncodeMmsStatusInfo(&mmsStatusInfo, &encodedData);
1546         } else {
1547                 MSG_DEBUG("Command Handle Fail : MsgGetMmsStatusInfoHandler()");
1548         }
1549
1550         /* Make Event Data */
1551         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_GET_MMS_STATUS_INFO, err, (void**)ppEvent);
1552
1553         return eventSize;
1554 }
1555 #endif
1556
1557
1558 int MsgAddPushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1559 {
1560         msg_error_t err = MSG_SUCCESS;
1561
1562         if (!pCmd || !ppEvent) {
1563                 MSG_DEBUG("pCmd or ppEvent is null");
1564                 return 0;
1565         }
1566
1567         int eventSize = 0;
1568
1569         /* Get Message Info */
1570         MSG_PUSH_EVENT_INFO_S* pPushEvent = (MSG_PUSH_EVENT_INFO_S*)pCmd->cmdData;
1571
1572         /* Add Message */
1573         err = MsgStoAddPushEvent(pPushEvent);
1574
1575         if (err == MSG_SUCCESS) {
1576                 MSG_DEBUG("Command Handle Success : MsgStoAddPushEvent()");
1577         } else {
1578                 MSG_DEBUG("Command Handle Fail : MsgStoAddPushEvent()");
1579         }
1580
1581         /* Make Event Data */
1582         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_PUSH_EVENT, err, (void**)ppEvent);
1583
1584         return eventSize;
1585 }
1586
1587 int MsgDeletePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1588 {
1589         msg_error_t err = MSG_SUCCESS;
1590
1591         if (!pCmd || !ppEvent) {
1592                 MSG_DEBUG("pCmd or ppEvent is null");
1593                 return 0;
1594         }
1595
1596         int eventSize = 0;
1597
1598         /* Get Message Info */
1599         MSG_PUSH_EVENT_INFO_S* pPushEvent = (MSG_PUSH_EVENT_INFO_S*)pCmd->cmdData;
1600
1601         /* Add Message */
1602         err = MsgStoDeletePushEvent(pPushEvent);
1603
1604         if (err == MSG_SUCCESS) {
1605                 MSG_DEBUG("Command Handle Success : MsgStoDeletePushEvent()");
1606         } else {
1607                 MSG_DEBUG("Command Handle Fail : MsgStoDeletePushEvent()");
1608         }
1609
1610         /* Make Event Data */
1611         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_PUSH_EVENT, err, (void**)ppEvent);
1612
1613         return eventSize;
1614 }
1615
1616 int MsgUpdatePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1617 {
1618         msg_error_t err = MSG_SUCCESS;
1619
1620         if (!pCmd || !ppEvent) {
1621                 MSG_DEBUG("pCmd or ppEvent is null");
1622                 return 0;
1623         }
1624
1625         int eventSize = 0;
1626
1627         /* Get Message Info */
1628         MSG_PUSH_EVENT_INFO_S pSrc;
1629         MSG_PUSH_EVENT_INFO_S pDst;
1630         memcpy(&pSrc, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_PUSH_EVENT_INFO_S));
1631         memcpy(&pDst, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_PUSH_EVENT_INFO_S)), sizeof(MSG_PUSH_EVENT_INFO_S));
1632
1633         /* Add Message */
1634         err = MsgStoUpdatePushEvent(&pSrc, &pDst);
1635
1636         if (err == MSG_SUCCESS) {
1637                 MSG_DEBUG("Command Handle Success : MsgStoUpdatePushEvent()");
1638         } else {
1639                 MSG_DEBUG("Command Handle Fail : MsgStoUpdatePushEvent()");
1640         }
1641
1642         /* Make Event Data */
1643         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_PUSH_EVENT, err, (void**)ppEvent);
1644
1645         return eventSize;
1646 }
1647
1648 int MsgAddSimMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1649 {
1650         msg_error_t err = MSG_SUCCESS;
1651
1652         if (!pCmd || !ppEvent) {
1653                 MSG_DEBUG("pCmd or ppEvent is null");
1654                 return 0;
1655         }
1656
1657         int eventSize = 0;
1658
1659         MSG_MESSAGE_INFO_S msgInfo;
1660         MSG_SENDINGOPT_INFO_S sendOptInfo;
1661         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1662         memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
1663
1664         msgInfo.addressList = NULL;
1665         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1666
1667         MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo);
1668
1669         int *simIdList = NULL;
1670         int listSize = 0;
1671         char *offset = NULL;
1672         offset = ((char *)pCmd->cmdData) + sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S) * msgInfo.nAddressCnt);
1673
1674         listSize = *(int*)offset;
1675         offset += sizeof(int);
1676         MSG_DEBUG("listSize [%d]", listSize);
1677
1678         simIdList = (int *)offset;
1679
1680         MSG_DEBUG("simIdList[0] [%d]", simIdList[0]);
1681
1682         /* Add Message */
1683 #if 0 /* Not to broadcast callback here. */
1684         bool isReplaceMsg = false;
1685
1686         if (msgInfo.msgId <= 0)
1687                 msgInfo.msgId = 0;
1688         else
1689                 isReplaceMsg = true;
1690 #else
1691         if (msgInfo.msgId <= 0)
1692                 msgInfo.msgId = 0;
1693 #endif
1694
1695         msg_message_id_t msg_id = MsgStoAddSimMessage(&msgInfo, simIdList, listSize);
1696
1697         if (msg_id > 0) {
1698                 MSG_DEBUG("Command Handle Success : MsgStoAddSimMessage()");
1699
1700 #if 0 /* Not to broadcast callback here. */
1701                 /*storage change CB */
1702                 msg_id_list_s msgIdList;
1703                 msg_message_id_t msgIds[1];
1704                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
1705
1706                 msgIdList.nCount = 1;
1707                 msgIds[0] = msgInfo.msgId;
1708                 msgIdList.msgIdList = msgIds;
1709
1710                 if (isReplaceMsg)
1711                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
1712                 else
1713                         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
1714 #endif
1715         } else {
1716                         MSG_DEBUG("Command Handle Fail : MsgStoAddSimMessage()");
1717                         err = MSG_ERR_INVALID_MESSAGE;
1718         }
1719
1720         /* Delete Temp File for Message Data */
1721         if (msgInfo.bTextSms == false)
1722                 MsgDeleteFile(msgInfo.msgData); /*ipc */
1723
1724         /* Make Event Data */
1725         eventSize = MsgMakeEvent((const void *)&msg_id, sizeof(msg_message_id_t), MSG_EVENT_ADD_SIM_MSG, err, (void**)ppEvent);
1726
1727         return eventSize;
1728 }
1729
1730
1731 int MsgUpdateIMSIHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1732 {
1733         msg_error_t err = MSG_SUCCESS;
1734
1735         if (!pCmd || !ppEvent) {
1736                 MSG_DEBUG("pCmd or ppEvent is null");
1737                 return 0;
1738         }
1739
1740         int eventSize = 0;
1741
1742         int sim_idx = 0;
1743         memcpy(&sim_idx, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
1744
1745         /* Add Message */
1746         err = MsgStoUpdateIMSI(sim_idx);
1747
1748         if (err == MSG_SUCCESS) {
1749                 MSG_DEBUG("Command Handle Success : MsgStoUpdateIMSI()");
1750         } else {
1751                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateIMSI()");
1752         }
1753
1754         /* Make Event Data */
1755         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_IMSI, err, (void**)ppEvent);
1756
1757         return eventSize;
1758 }