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