update tizen source
[framework/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerStorage.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #include <stdlib.h>
32
33 #include "MsgDebug.h"
34 #include "MsgUtilFile.h"
35 #include "MsgException.h"
36 #include "MsgCppTypes.h"
37 #include "MsgUtilFunction.h"
38 #include "MsgStorageHandler.h"
39 #include "MsgPluginManager.h"
40 #include "MsgTransManager.h"
41 #include "MsgCmdHandler.h"
42
43
44 /*==================================================================================================
45                                      FUNCTION IMPLEMENTATION
46 ==================================================================================================*/
47 int MsgAddMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
48 {
49         MSG_ERROR_T err = MSG_SUCCESS;
50
51         char* encodedData = NULL;
52         AutoPtr<char> buf(&encodedData);
53
54         int dataSize = 0, eventSize = 0;
55
56         // Get Message Info
57         MSG_MESSAGE_INFO_S* pMsgInfo = (MSG_MESSAGE_INFO_S*)pCmd->cmdData;
58
59         // Get Sending Option
60         MSG_SENDINGOPT_INFO_S* pSendOptInfo = (MSG_SENDINGOPT_INFO_S*)(pCmd->cmdData + sizeof(MSG_MESSAGE_INFO_S));
61
62         // Add Message with address
63         for (int i = 0; i < pMsgInfo->nAddressCnt; i++)
64         {
65                 err = MsgStoAddMessage(pMsgInfo, pSendOptInfo, i);
66
67                 if (err == MSG_SUCCESS)
68                 {
69                         MSG_DEBUG("Command Handle Success : MsgStoAddMessage()");
70
71                         // Get First Msg Id
72                         if (i == 0)
73                         {
74                                 // Encoding Message ID
75                                 dataSize = MsgEncodeMsgId(&(pMsgInfo->msgId), &encodedData);
76                         }
77                 }
78                 else
79                 {
80                         MSG_DEBUG("Command Handle Fail : MsgStoAddMessage()");
81                 }
82         }
83
84         // Add Message without address
85         if (pMsgInfo->nAddressCnt == 0)
86         {
87                 err = MsgStoAddMessage(pMsgInfo, pSendOptInfo);
88
89                 if (err == MSG_SUCCESS)
90                 {
91                         MSG_DEBUG("Command Handle Success : MsgStoAddMessage()");
92
93                         // Encoding Message ID
94                         dataSize = MsgEncodeMsgId(&(pMsgInfo->msgId), &encodedData);
95                 }
96                 else
97                 {
98                         MSG_DEBUG("Command Handle Fail : MsgStoAddMessage()");
99                 }
100         }
101
102         // Delete Temp File for Message Data
103         if (pMsgInfo->bTextSms == false)
104                 MsgDeleteFile(pMsgInfo->msgData); //ipc
105
106         //storage change CB
107         MSG_MSGID_LIST_S msgIdList;
108         MSG_MESSAGE_ID_T msgIds[1];
109         memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
110
111         msgIdList.nCount = 1;
112         msgIds[0] = pMsgInfo->msgId;
113         msgIdList.msgIdList = msgIds;
114
115         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
116
117         // Make Event Data
118         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_ADD_MSG, err, (void**)ppEvent);
119
120         return eventSize;
121 }
122
123
124 int MsgAddSyncMLMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
125 {
126         MSG_ERROR_T err = MSG_SUCCESS;
127
128         int eventSize = 0;
129
130         int extId = 0, pinCode = 0;
131
132         MSG_MESSAGE_INFO_S msgInfo = {};
133
134         memcpy(&extId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
135         memcpy(&pinCode, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), sizeof(int));
136         memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), sizeof(MSG_MESSAGE_INFO_S));
137
138         // Add Message
139         err = MsgStoAddSyncMLMessage(&msgInfo, extId, pinCode);
140
141         if (err == MSG_SUCCESS)
142         {
143                 MSG_DEBUG("Command Handle Success : MsgStoAddSyncMLMessage()");
144
145                 // broadcast to listener threads, here
146                 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
147                 //storage change CB
148                 MSG_MSGID_LIST_S msgIdList;
149                 MSG_MESSAGE_ID_T msgIds[1];
150                 memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
151
152                 msgIdList.nCount = 1;
153                 msgIds[0] = msgInfo.msgId;
154                 msgIdList.msgIdList = msgIds;
155
156                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
157         }
158         else
159         {
160                 MSG_DEBUG("Command Handle Fail : MsgStoAddSyncMLMessage()");
161         }
162
163         // Make Event Data
164         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_SYNCML_MSG, err, (void**)ppEvent);
165
166         return eventSize;
167 }
168
169
170 int MsgUpdateMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
171 {
172         MSG_ERROR_T err = MSG_SUCCESS;
173
174         int eventSize = 0;
175
176         // Get Message Info
177         MSG_MESSAGE_INFO_S* pMsgInfo = (MSG_MESSAGE_INFO_S*)pCmd->cmdData;
178
179         // Get Sending Option
180         MSG_SENDINGOPT_INFO_S* pSendOptInfo = (MSG_SENDINGOPT_INFO_S*)(pCmd->cmdData + sizeof(MSG_MESSAGE_INFO_S));
181
182         // Update Message
183         err = MsgStoUpdateMessage(pMsgInfo, pSendOptInfo);
184
185         if (err == MSG_SUCCESS)
186                 MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
187         else
188                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateMessage()");
189
190         // Delete Temp File for Message Data
191         if (pMsgInfo->bTextSms == false)
192                 MsgDeleteFile(pMsgInfo->msgData); //ipc
193
194         //storage change CB
195         MSG_MSGID_LIST_S msgIdList;
196         MSG_MESSAGE_ID_T msgIds[1];
197         memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
198
199         msgIdList.nCount = 1;
200         msgIds[0] = pMsgInfo->msgId;
201         msgIdList.msgIdList = msgIds;
202
203         MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
204
205         // Make Event Data
206         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_MSG, err, (void**)ppEvent);
207
208         return eventSize;
209 }
210
211
212 int MsgUpdateReadStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
213 {
214         MSG_ERROR_T err = MSG_SUCCESS;
215
216         int eventSize = 0;
217
218         MSG_MESSAGE_ID_T msgId;
219         bool readStatus;
220
221         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_ID_T));
222         memcpy(&readStatus, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_ID_T)), sizeof(bool));
223
224         // Update Read Status
225         err = MsgStoUpdateReadStatus(msgId, readStatus);
226
227         if (err == MSG_SUCCESS)
228         {
229                 MSG_DEBUG("Command Handle Success : MsgStoUpdateReadStatus()");
230         }
231         else
232         {
233                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateReadStatus()");
234         }
235
236         // Make Event Data
237         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_READ, err, (void**)ppEvent);
238
239         return eventSize;
240 }
241
242
243 int MsgUpdateThreadReadStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
244 {
245         MSG_ERROR_T err = MSG_SUCCESS;
246
247         int eventSize = 0;
248
249         MSG_THREAD_ID_T threadId;
250         int unReadCnt = 0;
251
252         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_THREAD_ID_T));
253
254         MsgStoGetThreadUnreadCnt(threadId, &unReadCnt);
255
256         MSG_DEBUG("unReadCnt [%d]", unReadCnt);
257
258         if (unReadCnt > 0) {
259
260                 err = MsgStoUpdateThreadReadStatus(threadId);
261
262                 if (err == MSG_SUCCESS)
263                         MSG_DEBUG("Command Handle Success : MsgStoUpdateThreadReadStatus()");
264                 else
265                         MSG_DEBUG("Command Handle Fail : MsgStoUpdateThreadReadStatus()");
266         }
267
268         // Make Event Data
269         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_THREAD_READ, err, (void**)ppEvent);
270
271         return eventSize;
272
273 }
274
275
276 int MsgUpdateProtectedStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
277 {
278         MSG_ERROR_T err = MSG_SUCCESS;
279
280         int eventSize = 0;
281
282         MSG_MESSAGE_ID_T msgId;
283         bool protectedStatus;
284
285         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_ID_T));
286         memcpy(&protectedStatus, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_ID_T)), sizeof(bool));
287
288         // Update Protected Status
289         err = MsgStoUpdateProtectedStatus(msgId, protectedStatus);
290
291         if (err == MSG_SUCCESS)
292         {
293                 MSG_DEBUG("Command Handle Success : MsgStoUpdateProtectedStatus()");
294         }
295         else
296         {
297                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateProtectedStatus()");
298         }
299
300         // Make Event Data
301         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_PROTECTED, err, (void**)ppEvent);
302
303         return eventSize;
304 }
305
306
307 int MsgDeleteMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
308 {
309         MSG_ERROR_T err = MSG_SUCCESS;
310
311         int eventSize = 0;
312
313         int extId = 0;
314
315         MSG_MESSAGE_ID_T* msgId = (MSG_MESSAGE_ID_T*)pCmd->cmdData;
316
317         MsgStoGetSyncMLExtId(*msgId, &extId);
318
319         // Delete Message
320         err = MsgStoDeleteMessage(*msgId, true);
321
322         if (err == MSG_SUCCESS) {
323                 MSG_DEBUG("Command Handle Success : MsgStoDeleteMessage()");
324
325                 if(extId > 0) {
326                         // broadcast to listener threads, here
327                         MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, -1, extId);
328                 }
329
330                 MSG_MSGID_LIST_S msgIdList;
331                 MSG_MESSAGE_ID_T msgIds[1];
332                 memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
333
334                 msgIdList.nCount = 1;
335                 msgIds[0] = *msgId;
336                 msgIdList.msgIdList = msgIds;
337
338                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
339         } else {
340                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteMessage()");
341         }
342
343         // Make Event Data
344         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_MSG, err, (void**)ppEvent);
345
346         return eventSize;
347 }
348
349
350 int MsgDeleteAllMessageInFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
351 {
352         MSG_ERROR_T err = MSG_SUCCESS;
353
354         int eventSize = 0;
355
356         MSG_FOLDER_ID_T* folderId = (MSG_FOLDER_ID_T*)pCmd->cmdData;
357
358         bool bOnlyDB;
359         memcpy(&bOnlyDB, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_FOLDER_ID_T)), sizeof(bool));
360
361
362         MSG_MSGID_LIST_S msgIdList;
363         memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
364
365         // Delete Message
366         err = MsgStoDeleteAllMessageInFolder(*folderId, bOnlyDB, &msgIdList);
367
368         if (err == MSG_SUCCESS) {
369                 MSG_DEBUG("Command Handle Success : MsgStoDeleteAllMessageInFolder()");
370                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
371                 if(msgIdList.msgIdList != NULL)
372                         delete [] (char*)msgIdList.msgIdList;
373         } else {
374                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteAllMessageInFolder()");
375         }
376
377         // Make Event Data
378         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELALL_MSGINFOLDER, err, (void**)ppEvent);
379
380         return eventSize;
381
382 }
383
384
385 int MsgMoveMessageToFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
386 {
387         MSG_ERROR_T err = MSG_SUCCESS;
388
389         int eventSize = 0;
390
391         MSG_MESSAGE_ID_T msgId;
392         MSG_FOLDER_ID_T folderId;
393
394         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_ID_T));
395         memcpy(&folderId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_ID_T)), sizeof(MSG_FOLDER_ID_T));
396
397         // Move Message
398         err = MsgStoMoveMessageToFolder(msgId, folderId);
399
400         if (err == MSG_SUCCESS) {
401                 MSG_DEBUG("Command Handle Success : MsgStoMoveMessageToFolder()");
402
403                 MSG_MSGID_LIST_S msgIdList;
404                 MSG_MESSAGE_ID_T msgIds[1];
405                 memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
406
407                 msgIdList.nCount = 1;
408                 msgIds[0] = msgId;
409                 msgIdList.msgIdList = msgIds;
410
411                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
412         } else {
413                 MSG_DEBUG("Command Handle Fail : MsgStoMoveMessageToFolder()");
414         }
415
416         // Make Event Data
417         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_MOVE_MSGTOFOLDER, err, (void**)ppEvent);
418
419         return eventSize;
420 }
421
422
423 int MsgMoveMessageToStorageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
424 {
425         MSG_ERROR_T err = MSG_SUCCESS;
426
427         int eventSize = 0;
428
429         MSG_MESSAGE_ID_T msgId;
430         MSG_STORAGE_ID_T storageId;
431
432         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_ID_T));
433         memcpy(&storageId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_ID_T)), sizeof(MSG_STORAGE_ID_T));
434
435         // Move Message
436         err = MsgStoMoveMessageToStorage(msgId, storageId);
437
438         if (err == MSG_SUCCESS)
439         {
440                 MSG_DEBUG("Command Handle Success : MsgStoMoveMessageToStorage()");
441         }
442         else
443         {
444                 MSG_DEBUG("Command Handle Fail : MsgStoMoveMessageToStorage()");
445         }
446
447         // Make Event Data
448         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_MOVE_MSGTOSTORAGE, err, (void**)ppEvent);
449
450         return eventSize;
451 }
452
453
454 int MsgCountMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
455 {
456         MSG_ERROR_T err = MSG_SUCCESS;
457
458         char* encodedData = NULL;
459         AutoPtr<char> buf(&encodedData);
460
461         int dataSize = 0, eventSize = 0;
462
463         // Get Folder ID
464         MSG_FOLDER_ID_T* folderId = (MSG_FOLDER_ID_T*)pCmd->cmdData;
465
466         // Get Message Count
467         MSG_COUNT_INFO_S countInfo;
468
469         err = MsgStoCountMessage(*folderId, &countInfo);
470
471         if (err == MSG_SUCCESS)
472         {
473                 MSG_DEBUG("Command Handle Success : MsgStoCountMessage()");
474
475                 // Encoding Messaging Count Data
476                 dataSize = MsgEncodeCountInfo(&countInfo, &encodedData);
477         }
478         else
479         {
480                 MSG_DEBUG("Command Handle Fail : MsgStoCountMessage()");
481         }
482
483         // Make Event Data
484         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_COUNT_MSG, err, (void**)ppEvent);
485
486         return eventSize;
487 }
488
489
490 int MsgCountMsgByTypeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
491 {
492         MSG_ERROR_T err = MSG_SUCCESS;
493
494         char* encodedData = NULL;
495         AutoPtr<char> buf(&encodedData);
496
497         int dataSize = 0, eventSize = 0;
498
499         // Get Folder ID
500         MSG_MESSAGE_TYPE_S* pMsgType = (MSG_MESSAGE_TYPE_S*)pCmd->cmdData;
501
502         int nMsgCnt = 0;
503
504         // Get Message Count
505         err = MsgStoCountMsgByType(pMsgType, &nMsgCnt);
506
507         if (err == MSG_SUCCESS)
508         {
509                 MSG_DEBUG("Command Handle Success : MsgStoCountMsgByType()");
510
511                 // Encoding Messaging Count Data
512                 dataSize = MsgEncodeCountByMsgType(nMsgCnt, &encodedData);
513         }
514         else
515         {
516                 MSG_DEBUG("Command Handle Fail : MsgStoCountMsgByType()");
517         }
518
519         // Make Event Data
520         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_COUNT_BY_MSGTYPE, err, (void**)ppEvent);
521
522         return eventSize;
523 }
524
525
526 int MsgGetMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
527 {
528         MSG_ERROR_T err = MSG_SUCCESS;
529
530         // Get Message ID
531         MSG_MESSAGE_ID_T* msgId = (MSG_MESSAGE_ID_T*)pCmd->cmdData;
532
533         char* encodedData = NULL;
534         AutoPtr<char> buf(&encodedData);
535
536         int dataSize = 0, eventSize = 0;
537
538         // Get Message
539         MSG_MESSAGE_INFO_S msgInfo;
540         MSG_SENDINGOPT_INFO_S sendOptInfo;
541
542         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
543         memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
544
545         err = MsgStoGetMessage(*msgId, &msgInfo, &sendOptInfo);
546
547         if (err == MSG_SUCCESS)
548         {
549                 MSG_DEBUG("Command Handle Success : MsgStoGetMessage()");
550
551                 // Encoding Message Info  Data
552                 dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
553         }
554         else
555         {
556                 MSG_DEBUG("Command Handle Fail : MsgStoGetMessage()");
557         }
558
559 //      MsgSoundPlayStop();
560
561         // Make Event Data
562         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_MSG, err, (void**)ppEvent);
563
564         return eventSize;
565 }
566
567
568 int MsgGetFolderViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
569 {
570         MSG_ERROR_T err = MSG_SUCCESS;
571
572         // Get Folder ID
573         MSG_FOLDER_ID_T folderId;
574         MSG_SORT_RULE_S sortRule;
575
576         memcpy(&folderId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_FOLDER_ID_T));
577         memcpy(&sortRule, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_FOLDER_ID_T)), sizeof(MSG_SORT_RULE_S));
578
579         char* encodedData = NULL;
580         AutoPtr<char> buf(&encodedData);
581
582         int dataSize = 0, eventSize = 0;
583
584         // Get Message Common Info
585         MSG_LIST_S folderViewList;
586
587         err = MsgStoGetFolderViewList(folderId, &sortRule, &folderViewList);
588
589         if (err == MSG_SUCCESS)
590         {
591                 MSG_DEBUG("Command Handle Success : MsgStoGetFolderViewList()");
592
593                 // Encoding Folder View List Data
594                 dataSize = MsgEncodeFolderViewList(&folderViewList, &encodedData);
595
596                 MSG_DEBUG("dataSize [%d]", dataSize);
597
598                 if (folderViewList.msgInfo != NULL)
599                 {
600                         delete [] folderViewList.msgInfo;
601                         folderViewList.msgInfo = NULL;
602                 }
603         }
604         else
605         {
606                 MSG_DEBUG("Command Handle Fail : MsgStoGetFolderViewList()");
607                 return err;
608         }
609
610         // Make Event Data
611         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FOLDERVIEWLIST, MSG_SUCCESS, (void**)ppEvent);
612
613         return eventSize;
614 }
615
616
617 int MsgAddFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
618 {
619         MSG_ERROR_T err = MSG_SUCCESS;
620
621         int eventSize = 0;
622
623         // Get Folder Info
624         MSG_FOLDER_INFO_S* pFolderInfo = (MSG_FOLDER_INFO_S*)pCmd->cmdData;
625
626         // Add Folder
627         err = MsgStoAddFolder(pFolderInfo);
628
629         if (err == MSG_SUCCESS)
630         {
631                 MSG_DEBUG("Command Handle Success : MsgStoAddFolder()");
632         }
633         else
634         {
635                 MSG_DEBUG("Command Handle Fail : MsgStoAddFolder()");
636         }
637
638         // Make Event Data
639         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_FOLDER, err, (void**)ppEvent);
640
641         return eventSize;
642 }
643
644
645 int MsgUpdateFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
646 {
647         MSG_ERROR_T err = MSG_SUCCESS;
648
649         int eventSize = 0;
650
651         // Get Folder Info
652         MSG_FOLDER_INFO_S* pFolderInfo = (MSG_FOLDER_INFO_S*)pCmd->cmdData;
653
654         // Update Folder
655         err = MsgStoUpdateFolder(pFolderInfo);
656
657         if (err == MSG_SUCCESS)
658         {
659                 MSG_DEBUG("Command Handle Success : MsgStoUpdateFolder()");
660         }
661         else
662         {
663                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateFolder()");
664         }
665
666         // Make Event Data
667         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_FOLDER, err, (void**)ppEvent);
668
669         return eventSize;
670 }
671
672
673 int MsgDeleteFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
674 {
675         MSG_ERROR_T err = MSG_SUCCESS;
676
677         int eventSize = 0;
678
679         // Get Folder Info
680         MSG_FOLDER_ID_T* pFolderInfo = (MSG_FOLDER_ID_T*)pCmd->cmdData;
681
682         // Delete Folder
683         err = MsgStoDeleteFolder(*pFolderInfo);
684
685         if (err == MSG_SUCCESS)
686         {
687                 MSG_DEBUG("Command Handle Success : MsgStoDeleteFolder()");
688         }
689         else
690         {
691                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteFolder()");
692         }
693
694         // Make Event Data
695         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_FOLDER, err, (void**)ppEvent);
696
697         return eventSize;
698 }
699
700
701 int MsgGetFolderListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
702 {
703         MSG_ERROR_T err = MSG_SUCCESS;
704
705         char* encodedData = NULL;
706         AutoPtr<char> buf(&encodedData);
707
708         int dataSize = 0, eventSize = 0;
709
710         // Get Storage List
711         MSG_FOLDER_LIST_S folderList;
712
713         err = MsgStoGetFolderList(&folderList);
714
715         if (err == MSG_SUCCESS)
716         {
717                 MSG_DEBUG("Command Handle Success : MsgStoGetFolderList()");
718
719                 // Encoding Folder List Data
720                 dataSize = MsgEncodeFolderList(&folderList, &encodedData);
721
722                 delete [] folderList.folderInfo;
723         }
724         else
725         {
726                 MSG_DEBUG("Command Handle Fail : MsgStoGetFolderList()");
727         }
728
729         // Make Event Data
730         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FOLDERLIST, err, (void**)ppEvent);
731
732         return eventSize;
733 }
734
735
736 int MsgInitSimBySatHandler(const MSG_CMD_S *pCmd, char **ppEvent)
737 {
738         MSG_ERROR_T err = MSG_SUCCESS;
739
740         int eventSize = 0;
741
742         // Sim Init - Later
743         //Run msg-init-app
744
745         // Make Event Data
746         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INIT_SIM_BY_SAT, err, (void**)ppEvent);
747
748         return eventSize;
749 }
750
751
752 int MsgGetMsgTypeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
753 {
754         MSG_ERROR_T err = MSG_SUCCESS;
755
756         char* encodedData = NULL;
757         AutoPtr<char> buf(&encodedData);
758
759
760         int dataSize = 0, eventSize = 0;
761
762         // Get Message ID
763         MSG_MESSAGE_ID_T msgId;
764
765         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_ID_T));
766
767         // Get Msg Type
768         MSG_MESSAGE_TYPE_S msgType;
769
770         err = MsgStoGetMsgType(msgId, &msgType);
771
772         if (err == MSG_SUCCESS)
773         {
774                 MSG_DEBUG("Command Handle Success : MsgStoGetMsgType()");
775
776                 // Encoding Storage List Data
777                 dataSize = MsgEncodeMsgType(&msgType, &encodedData);
778
779         }
780         else
781         {
782                 MSG_DEBUG("Command Handle Fail : MsgStoGetMsgType()");
783         }
784
785         // Make Event Data
786         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_MSG_TYPE, err, (void**)ppEvent);
787
788         return eventSize;
789 }
790
791
792 int MsgGetThreadViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
793 {
794         MSG_ERROR_T err = MSG_SUCCESS;
795
796         MSG_SORT_RULE_S sortRule = {0};
797
798         memcpy(&sortRule, pCmd->cmdData, sizeof(MSG_SORT_RULE_S));
799
800         char* encodedData = NULL;
801         AutoPtr<char> buf(&encodedData);
802
803         int dataSize = 0, eventSize = 0;
804
805         // Get Thread View List
806         MSG_THREAD_VIEW_LIST_S msgThreadViewList;
807
808         err = MsgStoGetThreadViewList(&sortRule, &msgThreadViewList);
809
810         if (err == MSG_SUCCESS)
811         {
812                 MSG_DEBUG("Command Handle Success : MsgStoGetThreadViewList()");
813
814                 // Encoding Folder View List Data
815                 dataSize = MsgEncodeThreadViewList(&msgThreadViewList, &encodedData);
816
817                 MSG_DEBUG("dataSize [%d]", dataSize);
818
819                 if (msgThreadViewList.msgThreadInfo != NULL)
820                 {
821                         delete [] msgThreadViewList.msgThreadInfo;
822                         msgThreadViewList.msgThreadInfo = NULL;
823                 }
824         }
825         else
826         {
827                 MSG_DEBUG("Command Handle Fail : MsgStoGetThreadViewList()");
828                 return err;
829         }
830
831         // Make Event Data
832         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_THREADVIEWLIST, err, (void**)ppEvent);
833
834         return eventSize;
835 }
836
837
838 int MsgGetConversationViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
839 {
840         MSG_ERROR_T err = MSG_SUCCESS;
841
842         MSG_THREAD_ID_T threadId;
843
844         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_THREAD_ID_T));
845
846         char* encodedData = NULL;
847         AutoPtr<char> buf(&encodedData);
848
849         int dataSize = 0, eventSize = 0;
850
851         MSG_LIST_S convViewList;
852
853         err = MsgStoGetConversationViewList(threadId, &convViewList);
854
855         if (err == MSG_SUCCESS)
856         {
857                 MSG_DEBUG("Command Handle Success : MsgStoGetConversationViewList()");
858
859                 // Encoding Folder View List Data
860                 dataSize = MsgEncodeConversationViewList(&convViewList, &encodedData);
861
862                 MSG_DEBUG("dataSize [%d]", dataSize);
863
864                 if (convViewList.msgInfo != NULL)
865                 {
866                         delete [] convViewList.msgInfo;
867                         convViewList.msgInfo = NULL;
868                 }
869         }
870         else
871         {
872                 MSG_DEBUG("Command Handle Fail : MsgStoGetConversationViewList()");
873         }
874
875         // Make Event Data
876         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_CONVERSATIONVIEWLIST, err, (void**)ppEvent);
877
878         return eventSize;
879 }
880
881
882 int MsgDeleteThreadMessageListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
883 {
884         MSG_ERROR_T err = MSG_SUCCESS;
885
886         MSG_THREAD_ID_T threadId;
887         bool isSyncMLMsg = false;
888
889         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_THREAD_ID_T));
890
891         int eventSize = 0;
892
893         isSyncMLMsg = MsgStoCheckSyncMLMsgInThread(threadId);
894
895         MSG_MSGID_LIST_S msgIdList;
896         memset(&msgIdList, 0x00, sizeof(MSG_MSGID_LIST_S));
897
898         err = MsgStoDeleteThreadMessageList(threadId, &msgIdList);
899
900         if (err == MSG_SUCCESS) {
901                 MSG_DEBUG("Command Handle Success : MsgStoDeleteThreadMessageList()");
902
903                 if(isSyncMLMsg == true) {
904                         // broadcast to listener threads, here
905                         MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, -1, -1);
906                 }
907
908                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
909                 if(msgIdList.msgIdList != NULL)
910                         delete [] (char*)msgIdList.msgIdList;
911         }
912         else
913         {
914                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteThreadMessageList()");
915         }
916
917         // Make Event Data
918         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_THREADMESSAGELIST, err, (void**)ppEvent);
919
920         return eventSize;
921 }
922
923
924 int MsgCountMsgByContactHandler(const MSG_CMD_S *pCmd, char **ppEvent)
925 {
926         MSG_ERROR_T err = MSG_SUCCESS;
927
928         // Get From address
929         MSG_THREAD_LIST_INDEX_S addrInfo;
930
931         memcpy(&addrInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_THREAD_LIST_INDEX_S));
932
933         char* encodedData = NULL;
934         AutoPtr<char> buf(&encodedData);
935
936         int dataSize = 0, eventSize = 0;
937
938         // Get Message Common Info
939         MSG_THREAD_COUNT_INFO_S threadCountInfo = {0};
940
941         err = MsgStoCountMsgByContact(&addrInfo, &threadCountInfo);
942
943         if (err == MSG_SUCCESS)
944         {
945                 MSG_DEBUG("Command Handle Success : MsgStoCountMsgByContact()");
946
947                 // Encoding Folder View List Data
948                 dataSize = MsgEncodeMsgGetContactCount(&threadCountInfo, &encodedData);
949
950                 MSG_DEBUG("dataSize [%d]", dataSize);
951         }
952         else
953         {
954                 MSG_DEBUG("Command Handle Fail : MsgStoCountMsgByContact()");
955         }
956
957         // Make Event Data
958         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_CONTACT_COUNT, err, (void**)ppEvent);
959
960         return eventSize;
961 }
962
963
964 int MsgGetQuickPanelDataHandler(const MSG_CMD_S *pCmd, char **ppEvent)
965 {
966         MSG_ERROR_T err = MSG_SUCCESS;
967
968         // Get Message ID
969         MSG_QUICKPANEL_TYPE_T* type = (MSG_QUICKPANEL_TYPE_T*)pCmd->cmdData;
970
971         char* encodedData = NULL;
972         AutoPtr<char> buf(&encodedData);
973
974         int dataSize = 0, eventSize = 0;
975
976         // Get Message
977         MSG_MESSAGE_INFO_S msgInfo;
978
979         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
980
981         err = MsgStoGetQuickPanelData(*type, &msgInfo);
982
983         if (err == MSG_SUCCESS)
984         {
985                 MSG_DEBUG("Command Handle Success : MsgStoGetQuickPanelData()");
986
987                 // Encoding Message Info Data
988                 dataSize = MsgEncodeMsgInfo(&msgInfo, &encodedData);
989         }
990         else
991         {
992                 MSG_DEBUG("Command Handle Fail : MsgStoGetQuickPanelData()");
993         }
994
995         // Make Event Data
996         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_QUICKPANEL_DATA, err, (void**)ppEvent);
997
998         return eventSize;
999 }
1000
1001
1002 int MsgResetDatabaseHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1003 {
1004         MSG_ERROR_T err = MSG_SUCCESS;
1005
1006         int eventSize = 0;
1007
1008         // Reset DB
1009         err = MsgStoResetDatabase();
1010
1011         if (err == MSG_SUCCESS)
1012                 MSG_DEBUG("Command Handle Success : MsgStoResetDatabase()");
1013         else
1014                 MSG_DEBUG("Command Handle Fail : MsgStoResetDatabase()");
1015
1016         // Make Event Data
1017         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_RESET_DB, err, (void**)ppEvent);
1018
1019         return eventSize;
1020 }
1021
1022
1023 int MsgGetMemSizeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1024 {
1025         MSG_ERROR_T err = MSG_SUCCESS;
1026
1027         char* encodedData = NULL;
1028         AutoPtr<char> buf(&encodedData);
1029
1030         int dataSize = 0, eventSize = 0;
1031
1032         // Get Memory size
1033         unsigned int memsize = 0;
1034
1035         memsize = MsgDu(MSG_DATA_ROOT_PATH);
1036
1037         dataSize = MsgEncodeMemSize(&memsize, &encodedData);
1038
1039         // Make Event Data
1040         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_MEMSIZE, err, (void**)ppEvent);
1041
1042         return eventSize;
1043 }
1044
1045
1046 int MsgGetReportStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1047 {
1048         MSG_ERROR_T err = MSG_SUCCESS;
1049
1050         // Get Message ID
1051         MSG_MESSAGE_ID_T* msgId = (MSG_MESSAGE_ID_T*)pCmd->cmdData;
1052
1053         char* encodedData = NULL;
1054         AutoPtr<char> buf(&encodedData);
1055
1056         int dataSize = 0, eventSize = 0;
1057
1058         MSG_REPORT_STATUS_INFO_S reportStatus;
1059
1060         memset(&reportStatus, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
1061
1062         err = MsgStoGetReportStatus(*msgId, &reportStatus);
1063
1064         if (err == MSG_SUCCESS)
1065         {
1066                 MSG_DEBUG("Command Handle Success : MsgGetReportStatusHandler()");
1067
1068                 // Encoding Report Status Data
1069                 dataSize = MsgEncodeReportStatus(&reportStatus, &encodedData);
1070         }
1071         else
1072         {
1073                 MSG_DEBUG("Command Handle Fail : MsgGetReportStatusHandler()");
1074         }
1075
1076         // Make Event Data
1077         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_REPORT_STATUS, err, (void**)ppEvent);
1078
1079         return eventSize;
1080 }