modify msg-service to support dpm feature
[platform/core/messaging/msg-service.git] / utils / MsgUtilFunction.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16
17 #include <systemd/sd-login.h>
18
19 #include "MsgDebug.h"
20 #include "MsgContact.h"
21 #include "MsgGconfWrapper.h"
22 #include "MsgUtilFile.h"
23 #include "MsgUtilFunction.h"
24 #include "MsgUtilStorage.h"
25
26 #include <system_info.h>
27 #include <libintl.h>
28 #include <locale.h>
29 #include <vconf.h>
30 #include <ctype.h>
31 #include <aul.h>
32 #include <aul_svc.h>
33 #include <dpm/restriction.h>
34
35 typedef struct _msg_launch_app_data {
36         char *app_id;
37         bundle *bundle_data;
38 } msg_launch_app_data;
39
40 #define DEFAULT_MIN_MATCH_DIGIT 8
41
42 enum _FEATURE_INDEX_E {
43         FEATURE_INDEX_SMS = 0,
44         FEATURE_INDEX_MMS = 1,
45 };
46
47 static bool b_feature_cache_flag = false;
48 static bool b_feature_support[] = {
49                 [FEATURE_INDEX_SMS] = false,
50                 [FEATURE_INDEX_MMS] = false,
51 };
52
53 static int dpm_policy_enable[] = {
54                 [MSG_UNKNOWN_TYPE] = 0,
55                 [MSG_SMS_TYPE] = 1,
56                 [MSG_MMS_TYPE] = 1,
57 };
58
59 device_policy_manager_h dpm_handle = NULL;
60 bool is_dpm_init = false;
61 int dpm_sms_callback_id = 0;
62 int dpm_mms_callback_id = 0;
63
64 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
65 static int phonenumberMinMatchDigit = -1;
66 #endif
67
68 /*==================================================================================================
69                                      FUNCTION IMPLEMENTATION
70 ==================================================================================================*/
71
72 bool MsgCheckFeatureSupport(const char *feature_name)
73 {
74         bool result = false;
75
76         if (b_feature_cache_flag == false) {
77                 if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_support[FEATURE_INDEX_SMS]) != SYSTEM_INFO_ERROR_NONE)
78                         MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE);
79
80                 if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_support[FEATURE_INDEX_MMS]) != SYSTEM_INFO_ERROR_NONE)
81                         MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE);
82
83                 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_support[FEATURE_INDEX_SMS]);
84                 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_support[FEATURE_INDEX_MMS]);
85
86                 b_feature_cache_flag = true;
87         }
88
89         if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) {
90                 result = b_feature_support[FEATURE_INDEX_SMS];
91         } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
92                 result = b_feature_support[FEATURE_INDEX_MMS];
93         }
94
95         return result;
96 }
97
98
99 int MsgContactGetMinMatchDigit()
100 {
101 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
102         if (phonenumberMinMatchDigit <= 0) {
103                 if (MsgSettingGetInt(VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT, &phonenumberMinMatchDigit) != MSG_SUCCESS) {
104                         MSG_INFO("MsgSettingGetInt() is failed");
105                 }
106                 MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
107
108                 if (phonenumberMinMatchDigit < 1) {
109                         phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
110                 }
111         }
112
113         return phonenumberMinMatchDigit;
114 #else
115         return DEFAULT_MIN_MATCH_DIGIT;
116 #endif
117 }
118
119 /* Encoders */
120 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
121 {
122         int dataSize = 0;
123
124         dataSize = sizeof(MSG_COUNT_INFO_S);
125
126         *ppDest = (char*)new char[dataSize];
127
128         void* p = (void*)*ppDest;
129
130         memcpy(p, pCountInfo, dataSize);
131
132         return dataSize;
133 }
134
135
136 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
137 {
138         int count = 0, dataSize = 0;
139
140         count = pRecipientList->recipientCnt;
141         dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
142
143         *ppDest = (char*)new char[dataSize];
144
145         void* p = (void*)*ppDest;
146
147         memcpy(p, &count, sizeof(int));
148         p = (void*)((char*)p + sizeof(int));
149
150         for (int i = 0; i < count; i++) {
151                 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
152                 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
153         }
154
155         return dataSize;
156 }
157
158
159 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
160 {
161         int dataSize = 0;
162
163         dataSize = sizeof(int);
164
165         *ppDest = (char*)new char[dataSize];
166
167         void* p = (void*)*ppDest;
168
169         memcpy(p, &MsgCount, dataSize);
170
171         return dataSize;
172 }
173
174
175 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
176 {
177         int dataSize = 0;
178
179         dataSize = (sizeof(msg_message_id_t));
180
181         *ppDest = (char*)new char[dataSize];
182
183         void* p = (void*)*ppDest;
184
185         memcpy(p, pMsgId, dataSize);
186
187         return dataSize;
188 }
189
190
191 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
192 {
193         int dataSize = 0;
194
195         dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
196
197         *ppDest = (char*)new char[dataSize];
198
199         void* p = (void*)*ppDest;
200
201         memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
202
203         p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
204
205         for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
206                 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
207                 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
208         }
209
210         return dataSize;
211 }
212
213
214 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
215 {
216         int dataSize = 0;
217
218         dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
219
220         *ppDest = (char*)new char[dataSize];
221
222         void* p = (void*)*ppDest;
223
224         memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
225
226         p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
227
228         memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
229
230         p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
231
232         for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
233                 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
234                 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
235         }
236
237         return dataSize;
238 }
239
240
241 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
242 {
243         int count = 0, dataSize = 0;
244
245         count = pFolderList->nCount;
246         dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
247
248         *ppDest = (char*)new char[dataSize];
249
250         void* p = (void*)*ppDest;
251
252         memcpy(p, &count, sizeof(int));
253         p = (void*)((char*)p + sizeof(int));
254
255         msg_struct_s *folder_info = NULL;
256
257         for (int i = 0; i < count; i++) {
258                 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
259                 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
260                 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
261         }
262
263         return dataSize;
264 }
265
266
267 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
268 {
269         int count = 0, dataSize = 0;
270
271         count = pFilterList->nCount;
272         dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
273
274         *ppDest = (char*)new char[dataSize];
275
276         void* p = (void*)*ppDest;
277
278         memcpy(p, &count, sizeof(int));
279         p = (void*)((char*)p + sizeof(int));
280
281         msg_struct_s *filter_info = NULL;
282
283         for (int i = 0; i < count; i++) {
284                 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
285                 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
286                 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
287         }
288
289         return dataSize;
290 }
291
292
293 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
294 {
295         int dataSize = 0;
296
297         dataSize = (sizeof(bool));
298
299         *ppDest = (char*)new char[dataSize];
300
301         void* p = (void*)*ppDest;
302
303         memcpy(p, pSetFlag, dataSize);
304
305         return dataSize;
306 }
307
308
309 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
310 {
311         int count = 0, dataSize = 0;
312
313         count = pThreadViewList->nCount;
314
315         dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
316
317         *ppDest = (char*)new char[dataSize];
318
319         void* p = (void*)*ppDest;
320
321         memcpy(p, &count, sizeof(int));
322         p = (void*)((char*)p + sizeof(int));
323
324         msg_struct_s *thread_info = NULL;
325
326         for (int i = 0; i < count; i++) {
327                 thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
328                 memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
329                 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
330         }
331
332         return dataSize;
333 }
334
335
336 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
337 {
338         int count = 0, dataSize = 0;
339
340         count = pConvViewList->nCount;
341
342         dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
343
344         *ppDest = (char*)new char[dataSize];
345
346         void* p = (void*)*ppDest;
347
348         memcpy(p, &count, sizeof(int));
349         p = (void*)((char*)p + sizeof(int));
350
351         for (int i = 0; i < count; i++) {
352                 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
353                 p = (void*)((char*)p + sizeof(msg_struct_list_s));
354         }
355
356         return dataSize;
357 }
358
359
360 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
361 {
362         int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
363
364         MSG_DEBUG("datasize = [%d] \n", dataSize);
365
366         *ppDest = (char*)new char[dataSize];
367
368         void* p = (void*)*ppDest;
369
370         memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
371         p = (void*)((char*)p + sizeof(int));
372
373         memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
374         p = (void*)((char*)p + sizeof(int));
375
376         memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
377         p = (void*)((char*)p + sizeof(int));
378
379         memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
380         p = (void*)((char*)p + sizeof(int));
381
382         return dataSize;
383 }
384
385 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
386 {
387         int dataSize = 0;
388
389         dataSize = sizeof(unsigned int);
390
391         *ppDest = (char*)new char[dataSize];
392
393         void* p = (void*)*ppDest;
394
395         memcpy(p, memsize, dataSize);
396
397         return dataSize;
398 }
399
400
401 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
402 {
403         int dataSize = 0;
404
405         dataSize = sizeof(int) + sizeof(int);
406
407         *ppDest = (char*)new char[dataSize];
408
409         void* p = (void*)*ppDest;
410
411         memcpy(p, &msgId, sizeof(int));
412         p = (void*)((char*)p + sizeof(int));
413
414         memcpy(p, &extId, sizeof(int));
415
416         return dataSize;
417 }
418
419
420 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
421 {
422         int dataSize = 0;
423         int count = 0;
424
425         count = pMsgIdList->nCount;
426
427         dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
428
429         *ppDest = (char*)new char[dataSize];
430
431         void* p = (void*)*ppDest;
432
433         memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
434         p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
435
436         memcpy(p, &count, sizeof(int));
437         p = (void*)((char*)p + sizeof(int));
438
439         for (int i = 0; i < count; i++) {
440                 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
441                 p = (void*)((char*)p + sizeof(msg_message_id_t));
442         }
443
444         return dataSize;
445 }
446
447
448 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
449 {
450         int dataSize = 0;
451         int addr_len = 0;
452
453         addr_len = strlen(pMsgInfo->addressList->addressVal);
454
455         dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
456
457         *ppDest = (char*)new char[dataSize];
458
459         void* p = (void*)*ppDest;
460
461         memcpy(p, &msgReportType, sizeof(msg_report_type_t));
462         p = (void*)((char*)p + sizeof(msg_report_type_t));
463
464         memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
465         p = (void*)((char*)p + sizeof(msg_message_id_t));
466
467         memcpy(p, &addr_len, sizeof(int));
468         p = (void*)((char*)p + sizeof(int));
469
470         memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
471         p = (void*)((char*)p + addr_len);
472
473         return dataSize;
474 }
475
476
477 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
478 {
479         int dataSize = 0;
480
481         dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
482
483         *ppDest = (char*)new char[dataSize];
484
485         void* p = (void*)*ppDest;
486
487         memcpy(p, &count, sizeof(int));
488
489         p = (void*)((char*)p + sizeof(int));
490
491         memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
492
493         return dataSize;
494 }
495
496
497 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
498 {
499         int dataSize = 0;
500
501         dataSize = (sizeof(msg_thread_id_t));
502
503         *ppDest = (char*)new char[dataSize];
504
505         void* p = (void*)*ppDest;
506
507         memcpy(p, pThreadId, dataSize);
508
509         return dataSize;
510 }
511
512
513 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
514 {
515         int dataSize = 0;
516
517         dataSize = sizeof(MSG_THREAD_VIEW_S);
518
519         *ppDest = (char*)new char[dataSize];
520
521         void* p = (void*)*ppDest;
522
523         memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
524
525         p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
526
527         return dataSize;
528 }
529
530
531 /* Decoders */
532 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
533 {
534         memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
535 }
536
537
538 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
539 {
540         memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
541 }
542
543
544 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
545 {
546         memcpy(memsize, pSrc, sizeof(unsigned int));
547 }
548
549
550 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
551 {
552         memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
553
554         pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
555
556         pMsgInfo->addressList = NULL;
557
558         pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
559         memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
560
561         for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
562                 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
563         }
564 }
565
566
567 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
568 {
569         memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
570
571         pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
572
573         memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
574
575         pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
576
577         if(pMsgInfo->nAddressCnt > 0) {
578                 pMsgInfo->addressList = NULL;
579
580                 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
581                 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
582
583                 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
584                         memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
585                 }
586         }
587 }
588
589
590 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
591 {
592         int count = 0;
593
594         memcpy(&count, pSrc, sizeof(int));
595         pSrc = pSrc + sizeof(int);
596
597         pRecipientList->recipientCnt = count;
598         pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
599
600         MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
601
602         for (int i = 0; i < count; i++) {
603                 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
604                 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
605                 pInfoTmp++;
606         }
607 }
608
609
610 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
611 {
612         int count = 0;
613
614         memcpy(&count, pSrc, sizeof(int));
615         pSrc = pSrc + sizeof(int);
616
617         if( count > 0 ) {
618                 pFolderList->nCount = count;
619                 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
620                 if (pFolderList->msg_struct_info == NULL) {
621                         pFolderList->nCount = 0;
622                         return;
623                 }
624                 msg_struct_s *pInfoTmp = NULL;
625
626                 for (int i = 0; i < count; i++) {
627                         pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
628                         pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
629                         pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
630                         pInfoTmp->data = new MSG_FOLDER_INFO_S;
631                         memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
632                         pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
633                 }
634         } else if ( count == 0 ) {
635                 pFolderList->nCount = count;
636                 pFolderList->msg_struct_info = NULL;
637         }
638 }
639
640
641 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
642 {
643         int count = 0;
644
645         memcpy(&count, pSrc, sizeof(int));
646         pSrc = pSrc + sizeof(int);
647
648         if( count > 0 ) {
649                 pFilterList->nCount = count;
650                 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
651
652                 if (pFilterList->msg_struct_info == NULL) {
653                         pFilterList->nCount = 0;
654                         return;
655                 }
656
657                 msg_struct_s *pStructTmp = NULL;
658
659                 for (int i = 0; i < count; i++) {
660                         pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
661                         pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
662                         pStructTmp->type = MSG_STRUCT_FILTER;
663                         pStructTmp->data = new MSG_FILTER_S;
664                         memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
665                         pSrc = pSrc + sizeof(MSG_FILTER_S);
666                 }
667         } else if ( count == 0 ) {
668                 pFilterList->nCount = count;
669                 pFilterList->msg_struct_info = NULL;
670         }
671 }
672
673
674 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
675 {
676         memcpy(pSetFlag, pSrc, sizeof(bool));
677 }
678
679
680 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
681 {
682         memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
683 }
684
685
686 void    MsgDecodeContactCount(char *pSrc,  MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
687 {
688         int count = 0;
689
690         if(pSrc == NULL)
691                 return;
692
693         memcpy(&count, pSrc, sizeof(int));
694         pSrc = pSrc + sizeof(int);
695         pMsgThreadCountList->totalCount = count;
696
697
698         memcpy(&count, pSrc, sizeof(int));
699         pSrc = pSrc + sizeof(int);
700         pMsgThreadCountList->unReadCount        = count;
701
702
703         memcpy(&count, pSrc, sizeof(int));
704         pSrc = pSrc + sizeof(int);
705         pMsgThreadCountList->mmsMsgCount        = count;
706
707
708         memcpy(&count, pSrc, sizeof(int));
709         pSrc = pSrc + sizeof(int);
710         pMsgThreadCountList->smsMsgCount        = count;
711
712
713         return;
714 }
715
716
717 void MsgDecodeReportStatus(char *pSrc,  msg_struct_list_s *report_list)
718 {
719         int count = 0;
720
721         if(pSrc == NULL)
722                 return;
723
724         memcpy(&count, pSrc, sizeof(int));
725         pSrc = pSrc + sizeof(int);
726
727         report_list->nCount = count;
728
729         msg_struct_t *report_status =  (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
730         for (int i = 0; i < count; i++) {
731                 msg_struct_s *report_status_item = new msg_struct_s;
732                 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
733                 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
734                 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
735
736                 MSG_REPORT_STATUS_INFO_S *report_status_info =  (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
737                 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
738
739                 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
740
741                 report_status[i] = (msg_struct_t)report_status_item;
742
743                 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
744                                 report_status_info->type, report_status_info->addressVal,
745                                 report_status_info->status, report_status_info->statusTime);
746         }
747
748         report_list->msg_struct_info = report_status;
749         return;
750 }
751
752 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
753 {
754         memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
755 }
756
757 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
758 {
759         memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
760 }
761
762 /* Event Encoder */
763 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
764 {
765         MSG_EVENT_S* pMsgEvent = NULL;
766
767         if (*ppEvent) {
768                 MSG_DEBUG("*ppEvent is not NULL.");
769                 delete [] (char *)*ppEvent;
770         }
771
772         *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
773
774         pMsgEvent = (MSG_EVENT_S*)*ppEvent;
775
776         pMsgEvent->eventType = MsgEvent;
777         pMsgEvent->result = MsgError;
778
779         MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
780         MSG_DEBUG("result [%d]", pMsgEvent->result);
781
782         if (DataSize > 0)
783                 memcpy((void*)pMsgEvent->data, pData, DataSize);
784
785         return (sizeof(MSG_EVENT_S) + DataSize);
786 }
787
788 int msg_verify_number(const char *raw, char *trimmed)
789 {
790         if (!(raw && trimmed)) {
791                 MSG_DEBUG("Phone Number is NULL");
792                 return MSG_ERR_NULL_POINTER;
793         }
794
795         for (int i=0, j=0 ; raw[i] ; i++) {
796                 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
797                                 || raw[i] == '*' ||  raw[i] == '#') {
798                         trimmed[j++] = raw[i];
799                 } else if (raw[i] == '-') {
800                         continue;
801                 } else {
802                         MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
803                         return MSG_ERR_INVALID_PARAMETER;
804                 }
805         }
806
807         MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
808         return MSG_SUCCESS;
809 }
810
811 int msg_verify_email(const char *raw)
812 {
813         bool onlyNum = true;
814         bool atExist = false;
815
816         if (!raw) {
817                 MSG_DEBUG("Email is NULL");
818                 return MSG_ERR_NULL_POINTER;
819         }
820
821         for (int i = 0; raw[i]; i++) {
822                 if (raw[i] == '@') {
823                         onlyNum = false;
824
825                         if (atExist == false) {
826                                 atExist = true;
827                                 continue;
828                         } else {
829                                 MSG_DEBUG("Character [@] is included more than twice in email address.");
830                                 return MSG_ERR_INVALID_PARAMETER;
831                         }
832                 }
833
834                 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' ||  raw[i] == '#') {
835                         continue;
836                 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
837                         onlyNum = false;
838                         continue;
839                 } else if (raw[i] == ',') {
840                         if (onlyNum == false && atExist == false) {
841                                 MSG_DEBUG("Unacceptable type in address.");
842                                 return MSG_ERR_INVALID_PARAMETER;
843                         }
844                         atExist = false;
845                         onlyNum = true;
846                         continue;
847                 } else {
848                         MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
849                         return MSG_ERR_INVALID_PARAMETER;
850                 }
851         }
852
853         return MSG_SUCCESS;
854 }
855
856
857 char* msg_clean_country_code(char *src)
858 {
859         int ret = 1;
860
861         switch (src[ret++]-'0') {
862                 case 1:
863                 case 7:
864                         break;
865                 case 2:
866                         switch (src[ret++]-'0') {
867                                 case 0:
868                                 case 7:
869                                         break;
870                                 case 1:
871                                 case 2:
872                                 case 3:
873                                 case 4:
874                                 case 5:
875                                 case 6:
876                                 case 8:
877                                 case 9:
878                                         ret += 1;
879                                         break;
880                                 default:
881                                         MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
882                                         break;
883                         }
884                         break;
885                 case 3:
886                         switch (src[ret++]-'0') {
887                                 case 0:
888                                 case 1:
889                                 case 2:
890                                 case 3:
891                                 case 4:
892                                 case 6:
893                                 case 9:
894                                         break;
895                                 case 5:
896                                 case 7:
897                                 case 8:
898                                         ret += 1;
899                                         break;
900                                 default:
901                                         MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
902                                         break;
903                         }
904                         break;
905                 case 4:
906                         switch (src[ret++]-'0') {
907                                 case 0:
908                                 case 1:
909                                 case 3:
910                                 case 4:
911                                 case 5:
912                                 case 6:
913                                 case 7:
914                                 case 8:
915                                 case 9:
916                                         break;
917                                 case 2:
918                                         ret += 1;
919                                         break;
920                                 default:
921                                         MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
922                                         break;
923                         }
924                         break;
925                 case 5:
926                         switch (src[ret++]-'0') {
927                                 case 1:
928                                 case 2:
929                                 case 3:
930                                 case 4:
931                                 case 5:
932                                 case 6:
933                                 case 7:
934                                 case 8:
935                                         break;
936                                 case 0:
937                                 case 9:
938                                         ret += 1;
939                                         break;
940                                 default:
941                                         MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
942                                         break;
943                         }
944                         break;
945                 case 6:
946                         switch (src[ret++]-'0') {
947                                 case 0:
948                                 case 1:
949                                 case 2:
950                                 case 3:
951                                 case 4:
952                                 case 5:
953                                 case 6:
954                                         break;
955                                 case 7:
956                                 case 8:
957                                 case 9:
958                                         ret += 1;
959                                         break;
960                                 default:
961                                         MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
962                                         break;
963                         }
964                         break;
965                 case 8:
966                         switch (src[ret++]-'0') {
967                                 case 1:
968                                 case 2:
969                                 case 4:
970                                 case 6:
971                                         break;
972                                 case 0:
973                                 case 3:
974                                 case 5:
975                                 case 7:
976                                 case 8:
977                                 case 9:
978                                         ret += 1;
979                                         break;
980                                 default:
981                                         MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
982                                         break;
983                         }
984                         break;
985                 case 9:
986                         switch (src[ret++]-'0') {
987                                 case 0:
988                                 case 1:
989                                 case 2:
990                                 case 3:
991                                 case 4:
992                                 case 5:
993                                 case 8:
994                                         break;
995                                 case 6:
996                                 case 7:
997                                 case 9:
998                                         ret += 1;
999                                         break;
1000                                 default:
1001                                         MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1002                                         break;
1003                         }
1004                         break;
1005                 case 0:
1006                 default:
1007                         MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1008                         return src;
1009         }
1010
1011         return &src[ret];
1012 }
1013
1014
1015 char* msg_normalize_number(char *src)
1016 {
1017         char *normalized_number;
1018
1019         if ('+' == src[0])
1020                 normalized_number = msg_clean_country_code(src);
1021         else if ('0' == src[0])
1022                 normalized_number = src+1;
1023         else
1024                 normalized_number = src;
1025
1026         MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1027
1028         return normalized_number;
1029 }
1030
1031
1032 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
1033 {
1034         char *notiMsg = NULL;
1035         char *lang = NULL;
1036
1037         lang = vconf_get_str(VCONFKEY_LANGSET);
1038
1039         setlocale(LC_MESSAGES, lang);
1040
1041         bindtextdomain(pkg_name, locale_dir);
1042
1043         notiMsg = dgettext(pkg_name, text);
1044
1045         if (lang) {
1046                 free(lang);
1047                 lang = NULL;
1048         }
1049
1050         return g_strdup(notiMsg);
1051 }
1052
1053
1054 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1055 {
1056         char sql[128];
1057         char order[6];
1058
1059         memset(sql, 0x00, sizeof(sql));
1060         memset(order, 0x00, sizeof(order));
1061
1062         if (pSortRule->bAscending == true)
1063                 strncpy(order, "ASC", 5);
1064         else
1065                 strncpy(order, "DESC", 5);
1066
1067         switch (pSortRule->sortType) {
1068                 case MSG_SORT_BY_DISPLAY_FROM :
1069                         snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1070                         break;
1071                 case MSG_SORT_BY_DISPLAY_TO :
1072                         snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1073                         break;
1074                 case MSG_SORT_BY_DISPLAY_TIME :
1075                         snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1076                         break;
1077                 case MSG_SORT_BY_MSG_TYPE :
1078                         snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1079                         break;
1080                 case MSG_SORT_BY_READ_STATUS :
1081                         snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1082                         break;
1083                 case MSG_SORT_BY_STORAGE_TYPE :
1084                         snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1085                         break;
1086                 case MSG_SORT_BY_THREAD_NAME :
1087                         snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1088                         break;
1089                 case MSG_SORT_BY_THREAD_DATE :
1090                         snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1091                         break;
1092                 case MSG_SORT_BY_THREAD_COUNT :
1093                         snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1094                         break;
1095                 default :
1096                         snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1097                         break;
1098         }
1099
1100         memcpy(pSqlSort, sql, strlen(sql));
1101
1102         return MSG_SUCCESS;
1103 }
1104 bool msg_is_valid_email(char *pAddress)
1105 {
1106         if (!pAddress || pAddress[0] == 0)
1107                 return false;
1108         if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1109                 return false;
1110         return true;
1111 }
1112
1113 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1114 {
1115         if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1116                 pMsgInfo->bTextSms = false;
1117
1118                 /* Save Message Data into File */
1119                 char fileName[MSG_FILENAME_LEN_MAX+1];
1120                 memset(fileName, 0x00, sizeof(fileName));
1121
1122                 if(MsgCreateFileName(fileName) == false) {
1123                         MSG_DEBUG("MsgCreateFileName error");
1124                         return MSG_ERR_STORAGE_ERROR;
1125                 }
1126
1127                 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1128
1129                 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1130                         MSG_DEBUG("MsgWriteIpcFile error");
1131                         return MSG_ERR_STORAGE_ERROR;
1132                 }
1133
1134                 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1135                 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1136         } else {
1137                 pMsgInfo->bTextSms = true;
1138
1139                 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1140                 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1141         }
1142
1143         return MSG_SUCCESS;
1144 }
1145
1146 /* change illegal filename character to '_' */
1147 void msg_replace_available_file_name(char *fileName)
1148 {
1149         int idx = 0;
1150         int len = 0;
1151         bool is_converted = false;
1152
1153         if (fileName) {
1154                 len = strlen(fileName);
1155
1156                 while (fileName[idx] != 0) {
1157                         if (idx >= len) {
1158                                 MSG_WARN("idx : %d, len : %d", idx, len);
1159                                 break;
1160                         }
1161
1162                         if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1163                                 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1164                                 fileName[idx++] = '_';
1165                                 is_converted = true;
1166                         } else {
1167                                 idx++;
1168                         }
1169                 }
1170         }
1171
1172         if (is_converted)
1173                 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1174 }
1175
1176 /* change character ' ' to '_' */
1177 void msg_replace_space_char(char *pszText)
1178 {
1179         if (!pszText) {
1180                 MSG_ERR("pszText is NULL");
1181                 return;
1182         }
1183
1184         char *spaceCharPtr = strchr(pszText, ' ');
1185
1186         while (spaceCharPtr) {
1187                 *spaceCharPtr = '_';
1188                 spaceCharPtr = strchr(pszText, ' ');
1189         }
1190 }
1191
1192 /* change non-ascii character to underscore */
1193 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1194 {
1195         if (!pszText) {
1196                 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1197                 return NULL;
1198         }
1199         gchar *res;
1200         gsize result_len = 0;
1201         const gchar *p;
1202         result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1203         res = (gchar *)g_malloc (result_len * sizeof (gchar));
1204         int i = 0;
1205         for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1206                 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1207         }
1208         res[i] = '\0';
1209         return res;
1210 }
1211
1212
1213 static int __find_login_user(uid_t *uid)
1214 {
1215         uid_t *uids = NULL;
1216         char *state = NULL;
1217
1218         int uids_len = sd_get_uids(&uids);
1219         if (uids_len <= 0)
1220                 return -1;
1221
1222         for (int i = 0; i < uids_len; i++) {
1223                 if (sd_uid_get_state(uids[i], &state) < 0) {
1224                         free(uids);
1225                         return -1;
1226                 } else {
1227                         if (g_strcmp0(state, "online") == 0) {
1228                                 *uid = uids[i];
1229                                 free(uids);
1230                                 free(state);
1231                                 return 0;
1232                         }
1233                 }
1234
1235                 free(state);
1236         }
1237
1238         free(uids);
1239         return -1;
1240 }
1241
1242
1243 uid_t msg_get_login_user()
1244 {
1245         uid_t uid = -1;
1246
1247         if (__find_login_user(&uid) < 0) {
1248                 MSG_WARN("Cannot find login user");
1249         }
1250
1251         MSG_DEBUG("login user id [%d]", uid);
1252
1253         return uid;
1254 }
1255
1256
1257 void* _msg_launch_app(void *data)
1258 {
1259         if (data) {
1260                 msg_launch_app_data *ad = (msg_launch_app_data *)data;
1261                 int ret = aul_launch_app_for_uid(ad->app_id, ad->bundle_data, msg_get_login_user());
1262                 if (ret <= 0) {
1263                         MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
1264                 }
1265
1266                 g_free(ad->app_id);
1267                 bundle_free(ad->bundle_data);
1268                 g_free(ad);
1269         }
1270
1271         return NULL;
1272 }
1273
1274 msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
1275 {
1276         msg_launch_app_data *data = (msg_launch_app_data *)calloc(1, sizeof(msg_launch_app_data));
1277         data->app_id = g_strdup(app_id);
1278         data->bundle_data = bundle_dup(bundle_data);
1279         pthread_t thd;
1280
1281         if (pthread_create(&thd, NULL, &_msg_launch_app, data) < 0) {
1282                 MSG_DEBUG("pthread_create() error");
1283         }
1284
1285         pthread_detach(thd);
1286         return MSG_SUCCESS;
1287 }
1288
1289
1290 msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation)
1291 {
1292         int ret = aul_svc_set_operation(bundle_data, operation);
1293         if (ret < 0) {
1294                 MSG_DEBUG("aul_svc_set_operation() is failed : %d", ret);
1295                 return MSG_ERR_UNKNOWN;
1296         }
1297
1298         return MSG_SUCCESS;
1299 }
1300
1301
1302 msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
1303 {
1304         int ret = aul_svc_set_uri(bundle_data, uri);
1305         if (ret < 0) {
1306                 MSG_DEBUG("aul_svc_set_uri() is failed : %d", ret);
1307                 return MSG_ERR_UNKNOWN;
1308         }
1309
1310         return MSG_SUCCESS;
1311 }
1312
1313
1314 void dpm_sms_policy_changed_callback(const char* name, const char* object, void *user_data)
1315 {
1316         MSG_INFO("dpm_sms_policy_changed_callback called. name [%s] object [%s]", name, object);
1317
1318         int ret = 0;
1319
1320         ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_SMS_TYPE - 1]);
1321         if (ret != DPM_ERROR_NONE) {
1322                 MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
1323                 return;
1324         }
1325 }
1326
1327
1328 void dpm_mms_policy_changed_callback(const char* name, const char* object, void *user_data)
1329 {
1330         MSG_INFO("dpm_mms_policy_changed_callback called. name [%s] object [%s]", name, object);
1331
1332         int ret = 0;
1333
1334         ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_MMS_TYPE - 1]);
1335         if (ret != DPM_ERROR_NONE) {
1336                 MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
1337                 return;
1338         }
1339 }
1340
1341
1342 static bool __get_dpm_policy()
1343 {
1344         int ret = 0;
1345
1346         ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_SMS_TYPE]);
1347         if (ret != DPM_ERROR_NONE) {
1348                 MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
1349                 return false;
1350         }
1351
1352         MSG_DEBUG("sms policy [%d]", dpm_policy_enable[MSG_SMS_TYPE]);
1353         MSG_DEBUG("mms policy [%d]", dpm_policy_enable[MSG_MMS_TYPE]);
1354
1355         ret = dpm_add_policy_changed_cb(dpm_handle, "messaging", dpm_sms_policy_changed_callback, NULL, &dpm_sms_callback_id);
1356         if (ret != DPM_ERROR_NONE) {
1357                 MSG_ERR("dpm_add_policy_changed_cb failed [%d]", ret);
1358                 return false;
1359         }
1360
1361         return true;
1362 }
1363
1364 void msg_init_dpm_policy()
1365 {
1366         MSG_BEGIN();
1367
1368         dpm_handle = dpm_manager_create();
1369         if (dpm_handle == NULL) {
1370                 MSG_ERR("dpm_manager_create() failed");
1371                 return;
1372         }
1373
1374         is_dpm_init = __get_dpm_policy();
1375
1376         MSG_END();
1377 }
1378
1379
1380 void msg_deinit_dpm_policy()
1381 {
1382         if (dpm_handle)
1383                 dpm_manager_destroy(dpm_handle);
1384
1385         if (dpm_sms_callback_id)
1386                 dpm_remove_policy_changed_cb(dpm_handle, dpm_sms_callback_id);
1387
1388         if (dpm_mms_callback_id)
1389                 dpm_remove_policy_changed_cb(dpm_handle, dpm_mms_callback_id);
1390
1391         is_dpm_init = false;
1392 }
1393
1394 bool msg_check_dpm_policy(int type)
1395 {
1396         if (is_dpm_init == false)
1397                 msg_init_dpm_policy();
1398
1399         return dpm_policy_enable[MSG_SMS_TYPE];
1400 //      return dpm_policy_enable[type];
1401 }
1402