update tizen source
[framework/messaging/msg-service.git] / mapi / MapiStorage.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 <errno.h>
32
33 #include "MsgHandle.h"
34 #include "MsgDebug.h"
35 #include "MsgException.h"
36 #include "MapiMessage.h"
37 #include "MapiStorage.h"
38
39
40 /*==================================================================================================
41                                      FUNCTION IMPLEMENTATION
42 ==================================================================================================*/
43 EXPORT_API int msg_add_message(MSG_HANDLE_T handle, const msg_message_t opq_msg, const MSG_SENDINGOPT_S *send_opt)
44 {
45         MSG_ERROR_T err =  MSG_SUCCESS;
46
47         if (handle == NULL || opq_msg == NULL || send_opt == NULL)
48         {
49                 return -EINVAL;
50         }
51
52         MsgHandle* pHandle = (MsgHandle*)handle;
53         MSG_MESSAGE_S* pMsg = (MSG_MESSAGE_S*) opq_msg;
54
55         try
56         {
57                 err = pHandle->addMessage(pMsg, send_opt);
58         }
59         catch (MsgException& e)
60         {
61                 MSG_FATAL("%s", e.what());
62                 return MSG_ERR_STORAGE_ERROR;
63         }
64
65         return err;
66 }
67
68
69 EXPORT_API int msg_add_syncml_message(MSG_HANDLE_T handle, const MSG_SYNCML_MESSAGE_S *syncml_msg)
70 {
71         MSG_ERROR_T err =  MSG_SUCCESS;
72
73         if (handle == NULL || syncml_msg == NULL)
74         {
75                 return -EINVAL;
76         }
77
78         MsgHandle* pHandle = (MsgHandle*)handle;
79
80         try
81         {
82                 err = pHandle->addSyncMLMessage(syncml_msg);
83         }
84         catch (MsgException& e)
85         {
86                 MSG_FATAL("%s", e.what());
87                 return MSG_ERR_STORAGE_ERROR;
88         }
89
90         return err;
91 }
92
93
94 EXPORT_API int msg_update_message(MSG_HANDLE_T handle, const msg_message_t opq_msg, const MSG_SENDINGOPT_S *send_opt)
95 {
96         MSG_ERROR_T err =  MSG_SUCCESS;
97
98         if (handle == NULL || opq_msg == NULL || send_opt == NULL)
99         {
100                 return -EINVAL;
101         }
102
103         MsgHandle* pHandle = (MsgHandle*)handle;
104         MSG_MESSAGE_S* pMsg = (MSG_MESSAGE_S*) opq_msg;
105
106         if (pMsg->nAddressCnt > 1)
107         {
108                 MSG_DEBUG("Multiple Address cannot be updated [%d]", pMsg->nAddressCnt);
109                 return -EINVAL;
110         }
111
112         try
113         {
114                 err = pHandle->updateMessage(pMsg, send_opt);
115         }
116         catch (MsgException& e)
117         {
118                 MSG_FATAL("%s", e.what());
119                 return MSG_ERR_STORAGE_ERROR;
120         }
121
122         return err;
123 }
124
125
126 EXPORT_API int msg_update_read_status(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id, bool read)
127 {
128         MSG_ERROR_T err =  MSG_SUCCESS;
129
130         if (handle == NULL)
131         {
132                 return -EINVAL;
133         }
134
135         MsgHandle* pHandle = (MsgHandle*)handle;
136
137         try
138         {
139                 err = pHandle->updateReadStatus(msg_id, read);
140         }
141         catch (MsgException& e)
142         {
143                 MSG_FATAL("%s", e.what());
144                 return MSG_ERR_STORAGE_ERROR;
145         }
146
147         return err;
148 }
149
150
151 EXPORT_API int msg_update_protected_status(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id, bool is_protected)
152 {
153         MSG_ERROR_T err =  MSG_SUCCESS;
154
155         if (handle == NULL)
156         {
157                 return -EINVAL;
158         }
159
160         MsgHandle* pHandle = (MsgHandle*)handle;
161
162         try
163         {
164                 err = pHandle->updateProtectedStatus(msg_id, is_protected);
165         }
166         catch (MsgException& e)
167         {
168                 MSG_FATAL("%s", e.what());
169                 return MSG_ERR_STORAGE_ERROR;
170         }
171
172         return err;
173 }
174
175
176 EXPORT_API int msg_delete_message(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id)
177 {
178         MSG_ERROR_T err =  MSG_SUCCESS;
179
180         if (handle == NULL)
181         {
182                 return -EINVAL;
183         }
184
185         MsgHandle* pHandle = (MsgHandle*)handle;
186
187         try
188         {
189                 err = pHandle->deleteMessage(msg_id);
190         }
191         catch (MsgException& e)
192         {
193                 MSG_FATAL("%s", e.what());
194                 return MSG_ERR_STORAGE_ERROR;
195         }
196
197         return err;
198 }
199
200
201 EXPORT_API int msg_delete_all_msgs_in_folder(MSG_HANDLE_T handle, MSG_FOLDER_ID_T folder_id, bool bOnlyDB)
202 {
203         MSG_ERROR_T err =  MSG_SUCCESS;
204
205         if (handle == NULL)
206         {
207                 return -EINVAL;
208         }
209
210         MsgHandle* pHandle = (MsgHandle*)handle;
211
212         try
213         {
214                 err = pHandle->deleteAllMessagesInFolder(folder_id, bOnlyDB);
215         }
216         catch (MsgException& e)
217         {
218                 MSG_FATAL("%s", e.what());
219                 return MSG_ERR_STORAGE_ERROR;
220         }
221
222         return err;
223 }
224
225
226 EXPORT_API int msg_move_msg_to_folder(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id, MSG_FOLDER_ID_T dest_folder_id)
227 {
228         MSG_ERROR_T err =  MSG_SUCCESS;
229
230         if (handle == NULL)
231         {
232                 return -EINVAL;
233         }
234
235         MsgHandle* pHandle = (MsgHandle*)handle;
236
237         try
238         {
239                 err = pHandle->moveMessageToFolder(msg_id, dest_folder_id);
240         }
241         catch (MsgException& e)
242         {
243                 MSG_FATAL("%s", e.what());
244                 return MSG_ERR_STORAGE_ERROR;
245         }
246
247         return err;
248 }
249
250
251 EXPORT_API int msg_move_msg_to_storage(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id, MSG_STORAGE_ID_T storage_id)
252 {
253         MSG_ERROR_T err =  MSG_SUCCESS;
254
255         if (handle == NULL)
256         {
257                 return -EINVAL;
258         }
259
260         if (storage_id != MSG_STORAGE_PHONE && storage_id != MSG_STORAGE_SIM)
261         {
262                 MSG_FATAL("unsupported storage [%d]", storage_id);
263                 return MSG_ERR_INVALID_PARAMETER;
264         }
265
266         MsgHandle* pHandle = (MsgHandle*)handle;
267
268         try
269         {
270                 err = pHandle->moveMessageToStorage(msg_id, storage_id);
271         }
272         catch (MsgException& e)
273         {
274                 MSG_FATAL("%s", e.what());
275                 return MSG_ERR_STORAGE_ERROR;
276         }
277
278         return err;
279 }
280
281
282 EXPORT_API int msg_count_message(MSG_HANDLE_T handle, MSG_FOLDER_ID_T folder_id, MSG_COUNT_INFO_S *count_info)
283 {
284         MSG_ERROR_T err =  MSG_SUCCESS;
285
286         if (handle == NULL)
287         {
288                 return -EINVAL;
289         }
290
291         MsgHandle* pHandle = (MsgHandle*)handle;
292
293         try
294         {
295                 err = pHandle->countMessage(folder_id, count_info);
296         }
297         catch (MsgException& e)
298         {
299                 MSG_FATAL("%s", e.what());
300                 return MSG_ERR_STORAGE_ERROR;
301         }
302
303         return err;
304 }
305
306
307 EXPORT_API int msg_count_msg_by_type(MSG_HANDLE_T handle, MSG_MESSAGE_TYPE_T msg_type, int *msg_count)
308 {
309         MSG_ERROR_T err =  MSG_SUCCESS;
310
311         if (handle == NULL)
312         {
313                 return -EINVAL;
314         }
315
316         MsgHandle* pHandle = (MsgHandle*)handle;
317
318         MSG_MESSAGE_TYPE_S msgType = {0};
319
320         if (msg_type == MSG_TYPE_SMS)
321         {
322                 msgType.mainType = MSG_SMS_TYPE;
323                 msgType.subType = MSG_NORMAL_SMS;
324         }
325         else if (msg_type == MSG_TYPE_SMS_WAPPUSH)
326         {
327                 msgType.mainType = MSG_SMS_TYPE;
328                 msgType.subType = MSG_WAP_SI_SMS;
329         }
330         else if (msg_type == MSG_TYPE_MMS)
331         {
332                 msgType.mainType = MSG_MMS_TYPE;
333                 msgType.subType = MSG_SENDREQ_MMS;
334         }
335
336         try
337         {
338                 err = pHandle->countMsgByType(&msgType, msg_count);
339         }
340         catch (MsgException& e)
341         {
342                 MSG_FATAL("%s", e.what());
343                 return MSG_ERR_STORAGE_ERROR;
344         }
345
346         return err;
347 }
348
349
350 EXPORT_API int msg_count_msg_by_contact(MSG_HANDLE_T handle, const MSG_THREAD_LIST_INDEX_S *addr_info, MSG_THREAD_COUNT_INFO_S *msg_thread_count_list)
351 {
352         MSG_ERROR_T err =  MSG_SUCCESS;
353
354         if (handle == NULL || addr_info == NULL)
355         {
356                 return -EINVAL;
357         }
358
359         MsgHandle* pHandle = (MsgHandle*)handle;
360
361         try
362         {
363                 err = pHandle->countMsgByContact(addr_info, msg_thread_count_list);
364         }
365         catch (MsgException& e)
366         {
367                 MSG_FATAL("%s", e.what());
368                 return MSG_ERR_STORAGE_ERROR;
369         }
370
371         return err;
372 }
373
374
375 EXPORT_API int msg_get_message(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id, msg_message_t opq_msg, MSG_SENDINGOPT_S *send_opt)
376 {
377         MSG_ERROR_T err =  MSG_SUCCESS;
378
379         if (handle == NULL || !opq_msg)
380         {
381                 MSG_FATAL("handle or opq_msg is NULL");
382                 return -EINVAL;
383         }
384
385         MsgHandle* pHandle = (MsgHandle*)handle;
386         MSG_MESSAGE_S* pMsg = (MSG_MESSAGE_S*) opq_msg;
387
388         try
389         {
390                 err = pHandle->getMessage(msg_id, pMsg, send_opt);
391         }
392         catch (MsgException& e)
393         {
394                 MSG_FATAL("%s", e.what());
395                 return MSG_ERR_STORAGE_ERROR;
396         }
397
398         return err;
399 }
400
401
402 EXPORT_API int msg_get_folder_view_list(MSG_HANDLE_T handle, MSG_FOLDER_ID_T folder_id, const MSG_SORT_RULE_S *sort_rule, MSG_LIST_S *msg_folder_view_list)
403 {
404         MSG_ERROR_T err =  MSG_SUCCESS;
405
406         if (handle == NULL)
407         {
408                 return -EINVAL;
409         }
410
411         MsgHandle* pHandle = (MsgHandle*)handle;
412
413         try
414         {
415                 if (sort_rule == NULL)
416                 {
417                         MSG_SORT_RULE_S sortRule = {0};
418
419                         sortRule.sortType = MSG_SORT_BY_READ_STATUS;
420                         sortRule.bAscending = true;
421
422                         err = pHandle->getFolderViewList(folder_id, &sortRule, msg_folder_view_list);
423                 }
424                 else
425                 {
426                 err = pHandle->getFolderViewList(folder_id, sort_rule, msg_folder_view_list);
427         }
428         }
429         catch (MsgException& e)
430         {
431                 MSG_FATAL("%s", e.what());
432                 return MSG_ERR_STORAGE_ERROR;
433         }
434
435         return err;
436 }
437
438
439 EXPORT_API int msg_get_thread_view_list(MSG_HANDLE_T handle, const MSG_SORT_RULE_S *sort_rule, MSG_THREAD_VIEW_LIST_S *msg_thread_view_list)
440 {
441         MSG_ERROR_T err =  MSG_SUCCESS;
442
443         if (handle == NULL)
444         {
445                 return -EINVAL;
446         }
447
448         MsgHandle* pHandle = (MsgHandle*)handle;
449
450         try
451         {
452                 if (sort_rule == NULL)
453                 {
454                         MSG_SORT_RULE_S sortRule = {0};
455
456                         sortRule.sortType = MSG_SORT_BY_THREAD_DATE;
457                         sortRule.bAscending = false;
458
459                         err = pHandle->getThreadViewList(&sortRule, msg_thread_view_list);
460                 }
461                 else
462                 {
463                         err = pHandle->getThreadViewList(sort_rule, msg_thread_view_list);
464                 }
465         }
466         catch (MsgException& e)
467         {
468                 MSG_FATAL("%s", e.what());
469                 return MSG_ERR_STORAGE_ERROR;
470         }
471
472         return err;
473 }
474
475
476 EXPORT_API void msg_release_thread_view_list(MSG_THREAD_VIEW_LIST_S *msg_thread_view_list)
477 {
478         if (msg_thread_view_list == NULL)
479         {
480                 return;
481         }
482
483         // Memory Free
484         if(msg_thread_view_list->msgThreadInfo != NULL)
485         {
486                 if(msg_thread_view_list->nCount > 0)
487                 {
488                         for(int i=0; i<msg_thread_view_list->nCount; i++)
489                                 delete [] (MSG_THREAD_VIEW_S*)msg_thread_view_list->msgThreadInfo[i];
490                 }
491
492                 //free peer info list
493                 delete [] msg_thread_view_list->msgThreadInfo;
494                 msg_thread_view_list->msgThreadInfo = NULL;
495         }
496
497         msg_thread_view_list->nCount = 0;
498 }
499
500
501 EXPORT_API int msg_get_conversation_view_list(MSG_HANDLE_T handle, MSG_THREAD_ID_T thread_id, MSG_LIST_S *msg_conv_view_list)
502 {
503         MSG_ERROR_T err =  MSG_SUCCESS;
504
505         if (handle == NULL)
506         {
507                 return -EINVAL;
508         }
509
510         MsgHandle* pHandle = (MsgHandle*)handle;
511
512         try
513         {
514                 err = pHandle->getConversationViewList(thread_id, msg_conv_view_list);
515         }
516         catch (MsgException& e)
517         {
518                 MSG_FATAL("%s", e.what());
519                 return MSG_ERR_STORAGE_ERROR;
520         }
521
522         return err;
523 }
524
525
526 EXPORT_API int msg_delete_thread_message_list(MSG_HANDLE_T handle, MSG_THREAD_ID_T thread_id)
527 {
528         MSG_ERROR_T err =  MSG_SUCCESS;
529
530         if (handle == NULL)
531         {
532                 return -EINVAL;
533         }
534
535         MsgHandle* pHandle = (MsgHandle*)handle;
536
537         try
538         {
539                 err = pHandle->deleteThreadMessageList(thread_id);
540         }
541         catch (MsgException& e)
542         {
543                 MSG_FATAL("%s", e.what());
544                 return MSG_ERR_STORAGE_ERROR;
545         }
546
547         return err;
548 }
549
550
551 EXPORT_API int msg_add_folder(MSG_HANDLE_T handle, const MSG_FOLDER_INFO_S *folder_info)
552 {
553         MSG_ERROR_T err =  MSG_SUCCESS;
554
555         if (handle == NULL || folder_info == NULL)
556         {
557                 return -EINVAL;
558         }
559
560         MsgHandle* pHandle = (MsgHandle*)handle;
561
562         try
563         {
564                 err = pHandle->addFolder(folder_info);
565         }
566         catch (MsgException& e)
567         {
568                 MSG_FATAL("%s", e.what());
569                 return MSG_ERR_STORAGE_ERROR;
570         }
571
572         return err;
573 }
574
575
576 EXPORT_API int msg_update_folder(MSG_HANDLE_T handle, const MSG_FOLDER_INFO_S *folder_info)
577 {
578         MSG_ERROR_T err =  MSG_SUCCESS;
579
580         if (handle == NULL || folder_info == NULL)
581         {
582                 return -EINVAL;
583         }
584
585         MsgHandle* pHandle = (MsgHandle*)handle;
586
587         try
588         {
589                 err = pHandle->updateFolder(folder_info);
590         }
591         catch (MsgException& e)
592         {
593                 MSG_FATAL("%s", e.what());
594                 return MSG_ERR_STORAGE_ERROR;
595         }
596
597         return err;
598 }
599
600
601 EXPORT_API int msg_delete_folder(MSG_HANDLE_T handle, MSG_FOLDER_ID_T folder_id)
602 {
603         MSG_ERROR_T err =  MSG_SUCCESS;
604
605         if (handle == NULL)
606         {
607                 return -EINVAL;
608         }
609
610         MsgHandle* pHandle = (MsgHandle*)handle;
611
612         try
613         {
614                 err = pHandle->deleteFolder(folder_id);
615         }
616         catch (MsgException& e)
617         {
618                 MSG_FATAL("%s", e.what());
619                 return MSG_ERR_STORAGE_ERROR;
620         }
621
622         return err;
623 }
624
625
626 EXPORT_API int msg_get_folder_list(MSG_HANDLE_T handle, MSG_FOLDER_LIST_S *folder_list)
627 {
628         MSG_ERROR_T err =  MSG_SUCCESS;
629
630         if (handle == NULL)
631         {
632                 return -EINVAL;
633         }
634
635         MsgHandle* pHandle = (MsgHandle*)handle;
636
637         try
638         {
639                 err = pHandle->getFolderList(folder_list);
640         }
641         catch (MsgException& e)
642         {
643                 MSG_FATAL("%s", e.what());
644                 return MSG_ERR_STORAGE_ERROR;
645         }
646
647         return err;
648 }
649
650
651 EXPORT_API void msg_release_folder_list(MSG_FOLDER_LIST_S *folder_list)
652 {
653         if (folder_list == NULL)
654         {
655                 return;
656         }
657
658         // Memory Free
659         if (folder_list->folderInfo != NULL)
660         {
661                 free(folder_list->folderInfo);
662                 folder_list->folderInfo = NULL;
663         }
664
665         folder_list->nCount = 0;
666 }
667
668
669 EXPORT_API int msg_generate_message(MSG_HANDLE_T handle, MSG_MESSAGE_TYPE_T msg_type, MSG_FOLDER_ID_T folder_id, unsigned int num_msg)
670 {
671         if (handle == NULL)
672         {
673                 MSG_DEBUG("Handle is NULL");
674                 return -EINVAL;
675         }
676
677         if (folder_id >= MSG_MAX_FOLDER_ID)
678         {
679                 MSG_DEBUG("folderId is invalid [%d]", folder_id);
680                 return -EINVAL;
681         }
682
683         MSG_DEBUG("type : %d, folder : %d, num_msg : %d", msg_type, folder_id, num_msg);
684
685         int err = 0;
686         MSG_SENDINGOPT_S sendingOpt = {0};
687         sendingOpt.bSetting = false;
688
689         char strMsg[20] = {0};
690         char prefix[10] ="0103001";
691 //      int postfix = 8111;
692         int postfix = 0;
693
694         srand(getpid());
695         // Make Message
696         MSG_MESSAGE_S msgInfo = {0, };  //structure is used to enhance performance
697
698         for (unsigned int i = 0; i < num_msg; i++)
699         {
700                 bzero(&msgInfo, sizeof(MSG_MESSAGE_S));
701
702                 msgInfo.msgId   = 0; // It should be set 0
703                 msgInfo.folderId = folder_id;
704
705                 if (msg_type == MSG_TYPE_MMS)
706                 {
707                         msgInfo.msgType.mainType = MSG_MMS_TYPE;
708                         //msgInfo.msgType.subType = MSG_RETRIEVE_MMS;
709                         msgInfo.msgType.subType = MSG_SENDREQ_MMS;
710                 }
711                 else
712                 {
713                         msgInfo.msgType.mainType = MSG_SMS_TYPE;
714                         msgInfo.msgType.subType = MSG_NORMAL_SMS;
715
716                         snprintf(strMsg, sizeof(strMsg), "test msg %d", i);
717                         msgInfo.dataSize = strlen(strMsg);
718                         msgInfo.pData = strMsg;
719                 }
720
721                 msgInfo.storageId = MSG_STORAGE_PHONE;
722
723                 msgInfo.nAddressCnt = 1;
724
725                 msgInfo.addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
726
727                 postfix = rand()%10000;
728                 snprintf(msgInfo.addressList[0].addressVal, MAX_ADDRESS_VAL_LEN+1, "%s%04d", prefix, postfix);
729
730                 msgInfo.addressList[0].recipientType = MSG_RECIPIENTS_TYPE_TO;
731
732                 time(&(msgInfo.displayTime));
733
734                 msgInfo.networkStatus = MSG_NETWORK_NOT_SEND;
735                 msgInfo.bRead = false;
736                 msgInfo.bProtected = false;
737                 msgInfo.priority = MSG_MESSAGE_PRIORITY_NORMAL;
738
739                 if (folder_id == MSG_OUTBOX_ID || folder_id == MSG_SENTBOX_ID)
740                         msgInfo.direction = MSG_DIRECTION_TYPE_MO;
741                 else
742                         msgInfo.direction = MSG_DIRECTION_TYPE_MT;
743
744                 if (msg_type == MSG_TYPE_MMS)
745                 {
746                         snprintf(msgInfo.subject, MAX_SUBJECT_LEN+1, "subject %d", i);
747
748                         if(folder_id == MSG_INBOX_ID) msgInfo.networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
749
750                         MMS_MESSAGE_DATA_S* mms_data;
751                         MMS_PAGE_S* page[2];
752                         MMS_MEDIA_S* media[5];
753
754                         mms_data = msg_mms_create_message();
755
756                         msg_mms_set_rootlayout(mms_data, 100, 100, 0xffffff);
757                         msg_mms_add_region(mms_data, "Image", 0, 50, 100, 50, 0xffffff);
758                         msg_mms_add_region(mms_data, "Text", 0, 0, 100, 50, 0xffffff);
759
760                         //------------>  1st Slide Composing
761                         page[0] = msg_mms_add_page(mms_data, 5440);
762
763                         media[0] = msg_mms_add_media(page[0], MMS_SMIL_MEDIA_IMG, "Image", (char*)"/opt/etc/msg-service/P091120_104633.jpg");
764                         media[1] = msg_mms_add_media(page[0], MMS_SMIL_MEDIA_AUDIO, NULL, (char*)"/opt/etc/msg-service/audio.amr");
765                         media[2] = msg_mms_add_media(page[0], MMS_SMIL_MEDIA_TEXT, "Text", (char*)"/opt/etc/msg-service/Temp0_2.txt");
766                         media[2]->sMedia.sText.nColor = 0x000000;
767                         media[2]->sMedia.sText.nSize = MMS_SMIL_FONT_SIZE_NORMAL;
768                         media[2]->sMedia.sText.bBold = true;
769
770                         //------------>  2nd Slide Composing
771                         page[1] = msg_mms_add_page(mms_data, 4544);
772
773                         media[3] = msg_mms_add_media(page[1], MMS_SMIL_MEDIA_TEXT, "Text", (char*)"/opt/etc/msg-service/Temp1_0.txt");
774                         media[3]->sMedia.sText.nColor = 0x000000;
775                         media[3]->sMedia.sText.nSize = MMS_SMIL_FONT_SIZE_NORMAL;
776                         media[3]->sMedia.sText.bItalic = true;
777                         media[4] = msg_mms_add_media(page[1], MMS_SMIL_MEDIA_VIDEO, "Text", (char*)"/opt/etc/msg-service/V091120_104905.3gp");
778                         strncpy(media[4]->szAlt, "Video Load Fail", MAX_SMIL_ALT_LEN-1);
779
780                         msg_mms_set_message_body((msg_message_t)&msgInfo, mms_data);
781
782                         msg_mms_destroy_message(mms_data);
783                 }
784
785                 err = msg_add_message(handle, (msg_message_t)&msgInfo, &sendingOpt);
786
787                 if (msg_type == MSG_TYPE_MMS && msgInfo.pMmsData) //free pMmsData directly. It is added to enhance performance
788                         delete [] static_cast<char*>(msgInfo.pMmsData);
789
790                 if (err < 0)
791                 {
792                         MSG_DEBUG("err [%d]", err);
793                         return err;
794                 }
795         }
796
797         return MSG_SUCCESS;
798 }
799
800
801 EXPORT_API int msg_generate_sms(MSG_HANDLE_T handle, MSG_FOLDER_ID_T folder_id, unsigned int num_msg)
802 {
803         MSG_DEBUG("folder %d, num_msg %d", folder_id, num_msg);
804
805         if (handle == NULL)
806         {
807                 MSG_DEBUG("Handle is NULL");
808                 return -EINVAL;
809         }
810
811         if (folder_id >= MSG_MAX_FOLDER_ID)
812         {
813                 MSG_DEBUG("folderId is invalid");
814                 return -EINVAL;
815         }
816
817         int err = 0;
818
819         // Make Message
820         MSG_MESSAGE_S msgInfo = {0};
821         char strMsg[20] = {0};
822
823         char prefix[10] ="0103001";
824         int postfix = 0;
825
826         MSG_SENDINGOPT_S sendingOpt = {0};
827         sendingOpt.bSetting = false;
828
829         srand(getpid());
830
831         for (unsigned int i = 0; i < num_msg; i++)
832         {
833                 bzero(&msgInfo, sizeof(msgInfo));
834                 msgInfo.msgId   = 0; // It should be set 0
835                 msgInfo.folderId = folder_id;
836
837                 msgInfo.msgType.mainType = MSG_SMS_TYPE;
838                 msgInfo.msgType.subType = 0;
839
840                 msgInfo.storageId = MSG_STORAGE_PHONE;
841
842                 snprintf(strMsg, sizeof(strMsg), "test %d", i);
843                 msgInfo.dataSize = strlen(strMsg);
844                 msgInfo.pData = strMsg;
845
846                 msgInfo.addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
847                 postfix = rand()%10000;
848                 snprintf(msgInfo.addressList[0].addressVal, MAX_ADDRESS_VAL_LEN+1, "%s%04d", prefix, postfix);
849                 msgInfo.addressList[0].recipientType = MSG_RECIPIENTS_TYPE_TO;
850                 msgInfo.nAddressCnt = 1;
851
852                 time(&(msgInfo.displayTime));
853
854                 msgInfo.networkStatus = MSG_NETWORK_NOT_SEND;
855                 msgInfo.bRead = false;
856                 msgInfo.bProtected = false;
857                 msgInfo.priority = MSG_MESSAGE_PRIORITY_NORMAL;
858                 msgInfo.direction = MSG_DIRECTION_TYPE_MO;
859
860                 err = msg_add_message(handle, (msg_message_t) &msgInfo, &sendingOpt);
861
862                 if (err < 0)
863                 {
864                         MSG_DEBUG("err [%d]", err);
865                         return err;
866                 }
867         }
868
869         return MSG_SUCCESS;
870 }
871
872
873 EXPORT_API int msg_get_quick_panel_data(MSG_HANDLE_T handle, MSG_QUICKPANEL_TYPE_T type, msg_message_t opq_msg)
874 {
875         MSG_ERROR_T err =  MSG_SUCCESS;
876
877         if (handle == NULL || !opq_msg )
878         {
879                 MSG_FATAL("handle or opq_msg is NULL");
880                 return -EINVAL;
881         }
882
883         MsgHandle* pHandle = (MsgHandle*)handle;
884         MSG_MESSAGE_S* pMsg = (MSG_MESSAGE_S*) opq_msg;
885
886         try
887         {
888                 err = pHandle->getQuickPanelData(type, pMsg);
889         }
890         catch (MsgException& e)
891         {
892                 MSG_FATAL("%s", e.what());
893                 return MSG_ERR_STORAGE_ERROR;
894         }
895
896         return err;
897 }
898
899
900 EXPORT_API int msg_reset_database(MSG_HANDLE_T handle)
901 {
902         MSG_ERROR_T err =  MSG_SUCCESS;
903
904         if (handle == NULL)
905         {
906                 return -EINVAL;
907         }
908
909         MsgHandle* pHandle = (MsgHandle*)handle;
910
911         try
912         {
913                 err = pHandle->resetDatabase();
914         }
915         catch (MsgException& e)
916         {
917                 MSG_FATAL("%s", e.what());
918                 return MSG_ERR_STORAGE_ERROR;
919         }
920
921         return err;
922 }
923
924
925 EXPORT_API int msg_get_mem_size(MSG_HANDLE_T handle, unsigned int* memsize)
926 {
927         MSG_ERROR_T err =  MSG_SUCCESS;
928
929         if (handle == NULL)
930         {
931                 return -EINVAL;
932         }
933
934         MsgHandle* pHandle = (MsgHandle*)handle;
935
936         try
937         {
938                 err = pHandle->getMemSize(memsize);
939         }
940         catch (MsgException& e)
941         {
942                 MSG_FATAL("%s", e.what());
943                 return MSG_ERR_STORAGE_ERROR;
944         }
945
946         return err;
947
948 }
949
950
951 EXPORT_API int msg_thread_view_get_thread_id(msg_thread_view_t msg_thread)
952 {
953         if (msg_thread == NULL)
954         {
955                 MSG_FATAL("msg_thread is NULL");
956                 return -EINVAL;
957         }
958
959         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
960
961         return pMsg->threadId;
962 }
963
964
965 EXPORT_API const char* msg_thread_view_get_address(msg_thread_view_t msg_thread)
966 {
967         if (msg_thread == NULL)
968         {
969                 MSG_FATAL("msg_thread is NULL");
970                 return NULL;
971         }
972
973         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
974
975         return pMsg->threadAddr;
976 }
977
978
979 EXPORT_API const char* msg_thread_view_get_name(msg_thread_view_t msg_thread)
980 {
981         if (msg_thread == NULL)
982         {
983                 MSG_FATAL("msg_thread is NULL");
984                 return NULL;
985         }
986
987         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
988
989         return pMsg->threadName;
990 }
991
992
993 EXPORT_API const char* msg_thread_view_get_image_path(msg_thread_view_t msg_thread)
994 {
995         if (msg_thread == NULL)
996         {
997                 MSG_FATAL("msg_thread is NULL");
998                 return NULL;
999         }
1000
1001         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
1002
1003         return pMsg->threadImagePath;
1004 }
1005
1006
1007 EXPORT_API int msg_thread_view_get_message_type(msg_thread_view_t msg_thread)
1008 {
1009         if (msg_thread == NULL)
1010         {
1011                 MSG_FATAL("msg_thread is NULL");
1012                 return -EINVAL;
1013         }
1014
1015         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
1016
1017         if (pMsg->threadType.mainType == MSG_SMS_TYPE)
1018         {
1019                 if (pMsg->threadType.subType == MSG_CB_SMS)
1020                         return MSG_TYPE_SMS_CB;
1021                 else    if (pMsg->threadType.subType == MSG_JAVACB_SMS)
1022                         return MSG_TYPE_SMS_JAVACB;
1023                 else    if (pMsg->threadType.subType == MSG_WAP_SI_SMS || pMsg->threadType.subType == MSG_WAP_SL_SMS)
1024                         return MSG_TYPE_SMS_WAPPUSH;
1025                 else    if (pMsg->threadType.subType == MSG_MWI_VOICE_SMS || pMsg->threadType.subType == MSG_MWI_FAX_SMS
1026                                 || pMsg->threadType.subType == MSG_MWI_EMAIL_SMS || pMsg->threadType.subType == MSG_MWI_OTHER_SMS)
1027                         return MSG_TYPE_SMS_MWI;
1028                 else    if (pMsg->threadType.subType == MSG_SYNCML_CP)
1029                         return MSG_TYPE_SMS_SYNCML;
1030                 else    if (pMsg->threadType.subType == MSG_REJECT_SMS)
1031                         return MSG_TYPE_SMS_REJECT;
1032                 else
1033                         return MSG_TYPE_SMS;
1034         }
1035         else if (pMsg->threadType.mainType == MSG_MMS_TYPE)
1036         {
1037                 if (pMsg->threadType.subType == MSG_NOTIFICATIONIND_MMS)
1038                         return MSG_TYPE_MMS_NOTI;
1039                 else if (pMsg->threadType.subType == MSG_SENDREQ_JAVA_MMS)
1040                         return MSG_TYPE_MMS_JAVA;
1041                 else
1042                         return MSG_TYPE_MMS;
1043         }
1044         else
1045                 return MSG_TYPE_INVALID;
1046 }
1047
1048
1049 EXPORT_API const char* msg_thread_view_get_data(msg_thread_view_t msg_thread)
1050 {
1051         if (msg_thread == NULL)
1052         {
1053                 MSG_FATAL("msg_thread is NULL");
1054                 return NULL;
1055         }
1056
1057         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
1058
1059         return pMsg->threadData;
1060 }
1061
1062
1063 EXPORT_API time_t* msg_thread_view_get_time(msg_thread_view_t msg_thread)
1064 {
1065         if (msg_thread == NULL)
1066         {
1067                 MSG_FATAL("msg_thread is NULL");
1068                 return NULL;
1069         }
1070
1071         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
1072
1073         return &(pMsg->threadTime);
1074 }
1075
1076
1077 EXPORT_API int msg_thread_view_get_direction(msg_thread_view_t msg_thread)
1078 {
1079         if (msg_thread == NULL)
1080         {
1081                 MSG_FATAL("msg_thread is NULL");
1082                 return -EINVAL;
1083         }
1084
1085         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
1086
1087         return pMsg->direction;
1088 }
1089
1090
1091 EXPORT_API int msg_thread_view_get_contact_id(msg_thread_view_t msg_thread)
1092 {
1093         if (msg_thread == NULL)
1094         {
1095                 MSG_FATAL("msg_thread is NULL");
1096                 return -EINVAL;
1097         }
1098
1099         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
1100
1101         return pMsg->contactId;
1102 }
1103
1104
1105 EXPORT_API int msg_thread_view_get_unread_cnt(msg_thread_view_t msg_thread)
1106 {
1107         if (msg_thread == NULL)
1108         {
1109                 MSG_FATAL("msg_thread is NULL");
1110                 return -EINVAL;
1111         }
1112
1113         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
1114
1115         return pMsg->unreadCnt;
1116 }
1117
1118
1119 EXPORT_API int msg_thread_view_get_sms_cnt(msg_thread_view_t msg_thread)
1120 {
1121         if (msg_thread == NULL)
1122         {
1123                 MSG_FATAL("msg_thread is NULL");
1124                 return -EINVAL;
1125         }
1126
1127         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
1128
1129         return pMsg->smsCnt;
1130 }
1131
1132
1133 EXPORT_API int msg_thread_view_get_mms_cnt(msg_thread_view_t msg_thread)
1134 {
1135         if (msg_thread == NULL)
1136         {
1137                 MSG_FATAL("msg_thread is NULL");
1138                 return -EINVAL;
1139         }
1140
1141         MSG_THREAD_VIEW_S* pMsg = (MSG_THREAD_VIEW_S*)msg_thread;
1142
1143         return pMsg->mmsCnt;
1144 }
1145
1146
1147 EXPORT_API int msg_search_message_for_thread_view(MSG_HANDLE_T handle, const char *search_string, MSG_THREAD_VIEW_LIST_S *msg_thread_view_list)
1148 {
1149         MSG_ERROR_T err =  MSG_SUCCESS;
1150
1151         if (handle == NULL || search_string == NULL)
1152         {
1153                 return -EINVAL;
1154         }
1155
1156         if (strlen(search_string) <= 0 || strlen(search_string) > MAX_MSG_TEXT_LEN)
1157         {
1158                 return -EINVAL;
1159         }
1160
1161         MsgHandle* pHandle = (MsgHandle*)handle;
1162
1163         try
1164         {
1165                 err = pHandle->searchMessage(search_string, msg_thread_view_list);
1166         }
1167         catch (MsgException& e)
1168         {
1169                 MSG_FATAL("%s", e.what());
1170                 return MSG_ERR_STORAGE_ERROR;
1171         }
1172
1173         return err;
1174 }
1175
1176
1177 EXPORT_API int msg_search_message(MSG_HANDLE_T handle, const MSG_SEARCH_CONDITION_S *msg_search_conditions, int offset, int limit, MSG_LIST_S *msg_list)
1178 {
1179         MSG_ERROR_T err =  MSG_SUCCESS;
1180
1181         if (handle == NULL || msg_search_conditions == NULL)
1182         {
1183                 return -EINVAL;
1184         }
1185
1186         MsgHandle* pHandle = (MsgHandle*)handle;
1187
1188         try
1189         {
1190                 err = pHandle->searchMessage(msg_search_conditions, offset, limit, msg_list);
1191         }
1192         catch (MsgException& e)
1193         {
1194                 MSG_FATAL("%s", e.what());
1195                 return MSG_ERR_STORAGE_ERROR;
1196         }
1197
1198         return err;
1199 }
1200
1201
1202 EXPORT_API int msg_release_message_list(MSG_LIST_S *msg_list)
1203 {
1204         if (msg_list == NULL)
1205         {
1206                 MSG_FATAL("msg_list is NULL");
1207                 return MSG_ERR_NULL_POINTER;
1208         }
1209
1210
1211         // Memory Free
1212         if (msg_list->msgInfo!= NULL)
1213         {
1214                 if(msg_list->nCount > 0)
1215                 {
1216                         for(int i=0; i<msg_list->nCount; i++)
1217                                 msg_release_message(&(msg_list->msgInfo[i]));
1218                 }
1219
1220                 delete [] msg_list->msgInfo;
1221                 msg_list->msgInfo = NULL;
1222         }
1223
1224         msg_list->nCount = 0;
1225
1226         return MSG_SUCCESS;
1227 }
1228
1229
1230 EXPORT_API int msg_get_msgid_list(MSG_HANDLE_T handle, MSG_REFERENCE_ID_T ref_id, MSG_MSGID_LIST_S *msg_msgid_list)
1231 {
1232         MSG_ERROR_T err =  MSG_SUCCESS;
1233
1234         if (handle == NULL)
1235         {
1236                 return -EINVAL;
1237         }
1238
1239         MsgHandle* pHandle = (MsgHandle*)handle;
1240
1241         try
1242         {
1243                 err = pHandle->getMsgIdList(ref_id, msg_msgid_list);
1244         }
1245         catch (MsgException& e)
1246         {
1247                 MSG_FATAL("%s", e.what());
1248                 return MSG_ERR_STORAGE_ERROR;
1249         }
1250
1251         return err;
1252 }
1253
1254
1255 EXPORT_API void msg_release_msgid_list(MSG_MSGID_LIST_S *msg_msgid_list)
1256 {
1257         if (msg_msgid_list == NULL)
1258         {
1259                 return;
1260         }
1261
1262         // Memory Free
1263         if(msg_msgid_list->msgIdList != NULL)
1264         {
1265                 //free peer info list
1266                 delete [] msg_msgid_list->msgIdList;
1267                 msg_msgid_list->msgIdList = NULL;
1268         }
1269
1270         msg_msgid_list->nCount = 0;
1271 }
1272
1273
1274 EXPORT_API int msg_get_reject_msg_list(MSG_HANDLE_T handle, const char *phone_num, MSG_REJECT_MSG_LIST_S *msg_reject_msg_list)
1275 {
1276         MSG_ERROR_T err =  MSG_SUCCESS;
1277
1278         if (handle == NULL)
1279         {
1280                 return -EINVAL;
1281         }
1282
1283         MsgHandle* pHandle = (MsgHandle*)handle;
1284
1285         try
1286         {
1287                 err = pHandle->getRejectMsgList(phone_num, msg_reject_msg_list);
1288         }
1289         catch (MsgException& e)
1290         {
1291                 MSG_FATAL("%s", e.what());
1292                 return MSG_ERR_STORAGE_ERROR;
1293         }
1294
1295         return err;
1296 }
1297
1298
1299 EXPORT_API void msg_release_reject_msg_list(MSG_REJECT_MSG_LIST_S *msg_reject_msg_list)
1300 {
1301         if (msg_reject_msg_list == NULL)
1302         {
1303                 return;
1304         }
1305
1306         // Memory Free
1307         if(msg_reject_msg_list->rejectMsgInfo != NULL)
1308         {
1309                 //free peer info list
1310                 delete [] msg_reject_msg_list->rejectMsgInfo;
1311                 msg_reject_msg_list->rejectMsgInfo = NULL;
1312         }
1313
1314         msg_reject_msg_list->nCount = 0;
1315 }
1316
1317
1318 EXPORT_API int msg_reg_storage_change_callback(MSG_HANDLE_T handle, msg_storage_change_cb cb, void *user_param)
1319 {
1320         MSG_ERROR_T err =  MSG_SUCCESS;
1321
1322         if (handle == NULL || cb == NULL)
1323         {
1324                 return -EINVAL;
1325         }
1326
1327         MsgHandle* pHandle = (MsgHandle*)handle;
1328
1329         try
1330         {
1331                 err = pHandle->regStorageChangeCallback(cb, user_param);
1332         }
1333         catch (MsgException& e)
1334         {
1335                 MSG_FATAL("%s", e.what());
1336                 return MSG_ERR_CALLBACK_ERROR;
1337         }
1338
1339         return err;
1340 }
1341
1342
1343 EXPORT_API int msg_get_report_status(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id, MSG_REPORT_STATUS_INFO_S *report_status)
1344 {
1345         MSG_ERROR_T err =  MSG_SUCCESS;
1346
1347         if (handle == NULL || msg_id < 1)
1348         {
1349                 return -EINVAL;
1350         }
1351
1352         MsgHandle* pHandle = (MsgHandle*)handle;
1353
1354         try
1355         {
1356                 err = pHandle->getReportStatus(msg_id, report_status);
1357         }
1358         catch (MsgException& e)
1359         {
1360                 MSG_FATAL("%s", e.what());
1361                 return MSG_ERR_STORAGE_ERROR;
1362         }
1363
1364         return err;
1365 }
1366