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