2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <systemd/sd-login.h>
20 #include "MsgContact.h"
21 #include "MsgGconfWrapper.h"
22 #include "MsgUtilFile.h"
23 #include "MsgUtilFunction.h"
24 #include "MsgUtilStorage.h"
26 #include <system_info.h>
35 typedef struct _msg_launch_app_data {
38 } msg_launch_app_data;
40 #define DEFAULT_MIN_MATCH_DIGIT 8
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"
47 enum _FEATURE_INDEX_E {
48 FEATURE_INDEX_SMS = 0,
49 FEATURE_INDEX_MMS = 1,
52 static bool b_feature_cache_flag = false;
53 static bool b_feature_support[] = {
54 [FEATURE_INDEX_SMS] = false,
55 [FEATURE_INDEX_MMS] = false,
58 static int dpm_policy_enable[] = {
59 [MSG_UNKNOWN_TYPE] = 0,
64 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
65 static int phonenumberMinMatchDigit = -1;
68 /*==================================================================================================
69 FUNCTION IMPLEMENTATION
70 ==================================================================================================*/
72 bool MsgCheckFeatureSupport(const char *feature_name)
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);
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);
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]);
86 b_feature_cache_flag = true;
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];
99 int MsgContactGetMinMatchDigit()
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");
106 MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
108 if (phonenumberMinMatchDigit < 1) {
109 phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
113 return phonenumberMinMatchDigit;
115 return DEFAULT_MIN_MATCH_DIGIT;
120 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
124 dataSize = sizeof(MSG_COUNT_INFO_S);
126 *ppDest = (char*)new char[dataSize];
128 void* p = (void*)*ppDest;
130 memcpy(p, pCountInfo, dataSize);
136 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
138 int count = 0, dataSize = 0;
140 count = pRecipientList->recipientCnt;
141 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
143 *ppDest = (char*)new char[dataSize];
145 void* p = (void*)*ppDest;
147 memcpy(p, &count, sizeof(int));
148 p = (void*)((char*)p + sizeof(int));
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));
159 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
163 dataSize = sizeof(int);
165 *ppDest = (char*)new char[dataSize];
167 void* p = (void*)*ppDest;
169 memcpy(p, &MsgCount, dataSize);
175 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
179 dataSize = (sizeof(msg_message_id_t));
181 *ppDest = (char*)new char[dataSize];
183 void* p = (void*)*ppDest;
185 memcpy(p, pMsgId, dataSize);
191 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
195 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
197 *ppDest = (char*)new char[dataSize];
199 void* p = (void*)*ppDest;
201 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
203 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
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));
214 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
218 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
220 *ppDest = (char*)new char[dataSize];
222 void* p = (void*)*ppDest;
224 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
226 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
228 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
230 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
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));
241 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
243 int count = 0, dataSize = 0;
245 count = pFolderList->nCount;
246 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
248 *ppDest = (char*)new char[dataSize];
250 void* p = (void*)*ppDest;
252 memcpy(p, &count, sizeof(int));
253 p = (void*)((char*)p + sizeof(int));
255 msg_struct_s *folder_info = NULL;
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));
267 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
269 int count = 0, dataSize = 0;
271 count = pFilterList->nCount;
272 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
274 *ppDest = (char*)new char[dataSize];
276 void* p = (void*)*ppDest;
278 memcpy(p, &count, sizeof(int));
279 p = (void*)((char*)p + sizeof(int));
281 msg_struct_s *filter_info = NULL;
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));
293 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
297 dataSize = (sizeof(bool));
299 *ppDest = (char*)new char[dataSize];
301 void* p = (void*)*ppDest;
303 memcpy(p, pSetFlag, dataSize);
309 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
311 int count = 0, dataSize = 0;
313 count = pThreadViewList->nCount;
315 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
317 *ppDest = (char*)new char[dataSize];
319 void* p = (void*)*ppDest;
321 memcpy(p, &count, sizeof(int));
322 p = (void*)((char*)p + sizeof(int));
324 msg_struct_s *thread_info = NULL;
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));
336 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
338 int count = 0, dataSize = 0;
340 count = pConvViewList->nCount;
342 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
344 *ppDest = (char*)new char[dataSize];
346 void* p = (void*)*ppDest;
348 memcpy(p, &count, sizeof(int));
349 p = (void*)((char*)p + sizeof(int));
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));
360 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
362 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
364 MSG_DEBUG("datasize = [%d] \n", dataSize);
366 *ppDest = (char*)new char[dataSize];
368 void* p = (void*)*ppDest;
370 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
371 p = (void*)((char*)p + sizeof(int));
373 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
374 p = (void*)((char*)p + sizeof(int));
376 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
377 p = (void*)((char*)p + sizeof(int));
379 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
380 p = (void*)((char*)p + sizeof(int));
385 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
389 dataSize = sizeof(unsigned int);
391 *ppDest = (char*)new char[dataSize];
393 void* p = (void*)*ppDest;
395 memcpy(p, memsize, dataSize);
401 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
405 dataSize = sizeof(int) + sizeof(int);
407 *ppDest = (char*)new char[dataSize];
409 void* p = (void*)*ppDest;
411 memcpy(p, &msgId, sizeof(int));
412 p = (void*)((char*)p + sizeof(int));
414 memcpy(p, &extId, sizeof(int));
420 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
425 count = pMsgIdList->nCount;
427 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
429 *ppDest = (char*)new char[dataSize];
431 void* p = (void*)*ppDest;
433 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
434 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
436 memcpy(p, &count, sizeof(int));
437 p = (void*)((char*)p + sizeof(int));
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));
448 int MsgEncodeThreadChangeData(const msg_storage_change_type_t storageChangeType, const msg_thread_id_t threadId, char **ppDest)
452 dataSize = sizeof(msg_storage_change_type_t) + sizeof(msg_thread_id_t);
454 *ppDest = (char*)new char[dataSize];
456 void* p = (void*)*ppDest;
458 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
459 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
461 memcpy(p, &threadId, sizeof(msg_thread_id_t));
467 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
472 addr_len = strlen(pMsgInfo->addressList->addressVal);
474 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
476 *ppDest = (char*)new char[dataSize];
478 void* p = (void*)*ppDest;
480 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
481 p = (void*)((char*)p + sizeof(msg_report_type_t));
483 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
484 p = (void*)((char*)p + sizeof(msg_message_id_t));
486 memcpy(p, &addr_len, sizeof(int));
487 p = (void*)((char*)p + sizeof(int));
489 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
490 p = (void*)((char*)p + addr_len);
496 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
500 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
502 *ppDest = (char*)new char[dataSize];
504 void* p = (void*)*ppDest;
506 memcpy(p, &count, sizeof(int));
508 p = (void*)((char*)p + sizeof(int));
510 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
516 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
520 dataSize = (sizeof(msg_thread_id_t));
522 *ppDest = (char*)new char[dataSize];
524 void* p = (void*)*ppDest;
526 memcpy(p, pThreadId, dataSize);
532 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
536 dataSize = sizeof(MSG_THREAD_VIEW_S);
538 *ppDest = (char*)new char[dataSize];
540 void* p = (void*)*ppDest;
542 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
544 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
551 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
553 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
557 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
559 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
563 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
565 memcpy(memsize, pSrc, sizeof(unsigned int));
569 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
571 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
573 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
575 pMsgInfo->addressList = NULL;
577 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
578 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
580 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
581 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
586 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
588 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
590 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
592 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
594 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
596 if(pMsgInfo->nAddressCnt > 0) {
597 pMsgInfo->addressList = NULL;
599 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
600 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
602 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
603 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
609 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
613 memcpy(&count, pSrc, sizeof(int));
614 pSrc = pSrc + sizeof(int);
616 pRecipientList->recipientCnt = count;
617 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
619 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
621 for (int i = 0; i < count; i++) {
622 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
623 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
629 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
633 memcpy(&count, pSrc, sizeof(int));
634 pSrc = pSrc + sizeof(int);
637 pFolderList->nCount = count;
638 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
639 if (pFolderList->msg_struct_info == NULL) {
640 pFolderList->nCount = 0;
643 msg_struct_s *pInfoTmp = NULL;
645 for (int i = 0; i < count; i++) {
646 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
647 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
648 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
649 pInfoTmp->data = new MSG_FOLDER_INFO_S;
650 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
651 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
653 } else if ( count == 0 ) {
654 pFolderList->nCount = count;
655 pFolderList->msg_struct_info = NULL;
660 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
664 memcpy(&count, pSrc, sizeof(int));
665 pSrc = pSrc + sizeof(int);
668 pFilterList->nCount = count;
669 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
671 if (pFilterList->msg_struct_info == NULL) {
672 pFilterList->nCount = 0;
676 msg_struct_s *pStructTmp = NULL;
678 for (int i = 0; i < count; i++) {
679 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
680 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
681 pStructTmp->type = MSG_STRUCT_FILTER;
682 pStructTmp->data = new MSG_FILTER_S;
683 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
684 pSrc = pSrc + sizeof(MSG_FILTER_S);
686 } else if ( count == 0 ) {
687 pFilterList->nCount = count;
688 pFilterList->msg_struct_info = NULL;
693 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
695 memcpy(pSetFlag, pSrc, sizeof(bool));
699 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
701 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
705 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
712 memcpy(&count, pSrc, sizeof(int));
713 pSrc = pSrc + sizeof(int);
714 pMsgThreadCountList->totalCount = count;
717 memcpy(&count, pSrc, sizeof(int));
718 pSrc = pSrc + sizeof(int);
719 pMsgThreadCountList->unReadCount = count;
722 memcpy(&count, pSrc, sizeof(int));
723 pSrc = pSrc + sizeof(int);
724 pMsgThreadCountList->mmsMsgCount = count;
727 memcpy(&count, pSrc, sizeof(int));
728 pSrc = pSrc + sizeof(int);
729 pMsgThreadCountList->smsMsgCount = count;
736 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
743 memcpy(&count, pSrc, sizeof(int));
744 pSrc = pSrc + sizeof(int);
746 report_list->nCount = count;
748 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
749 for (int i = 0; i < count; i++) {
750 msg_struct_s *report_status_item = new msg_struct_s;
751 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
752 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
753 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
755 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
756 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
758 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
760 report_status[i] = (msg_struct_t)report_status_item;
762 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
763 report_status_info->type, report_status_info->addressVal,
764 report_status_info->status, report_status_info->statusTime);
767 report_list->msg_struct_info = report_status;
771 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
773 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
776 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
778 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
782 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
784 MSG_EVENT_S* pMsgEvent = NULL;
787 MSG_DEBUG("*ppEvent is not NULL.");
788 delete [] (char *)*ppEvent;
791 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
793 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
795 pMsgEvent->eventType = MsgEvent;
796 pMsgEvent->result = MsgError;
798 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
799 MSG_DEBUG("result [%d]", pMsgEvent->result);
802 memcpy((void*)pMsgEvent->data, pData, DataSize);
804 return (sizeof(MSG_EVENT_S) + DataSize);
807 int msg_verify_number(const char *raw, char *trimmed)
809 if (!(raw && trimmed)) {
810 MSG_DEBUG("Phone Number is NULL");
811 return MSG_ERR_NULL_POINTER;
814 for (int i=0, j=0 ; raw[i] ; i++) {
815 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
816 || raw[i] == '*' || raw[i] == '#') {
817 trimmed[j++] = raw[i];
818 } else if (raw[i] == '-') {
821 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
822 return MSG_ERR_INVALID_PARAMETER;
826 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
830 int msg_verify_email(const char *raw)
833 bool atExist = false;
836 MSG_DEBUG("Email is NULL");
837 return MSG_ERR_NULL_POINTER;
840 for (int i = 0; raw[i]; i++) {
844 if (atExist == false) {
848 MSG_DEBUG("Character [@] is included more than twice in email address.");
849 return MSG_ERR_INVALID_PARAMETER;
853 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
855 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
858 } else if (raw[i] == ',') {
859 if (onlyNum == false && atExist == false) {
860 MSG_DEBUG("Unacceptable type in address.");
861 return MSG_ERR_INVALID_PARAMETER;
867 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
868 return MSG_ERR_INVALID_PARAMETER;
876 char* msg_clean_country_code(char *src)
880 switch (src[ret++]-'0') {
885 switch (src[ret++]-'0') {
900 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
905 switch (src[ret++]-'0') {
920 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
925 switch (src[ret++]-'0') {
940 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
945 switch (src[ret++]-'0') {
960 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
965 switch (src[ret++]-'0') {
980 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
985 switch (src[ret++]-'0') {
1000 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1005 switch (src[ret++]-'0') {
1020 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1026 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1034 char* msg_normalize_number(char *src)
1036 char *normalized_number;
1039 normalized_number = msg_clean_country_code(src);
1040 else if ('0' == src[0])
1041 normalized_number = src+1;
1043 normalized_number = src;
1045 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1047 return normalized_number;
1051 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
1053 char *notiMsg = NULL;
1056 lang = vconf_get_str(VCONFKEY_LANGSET);
1058 setlocale(LC_MESSAGES, lang);
1060 bindtextdomain(pkg_name, locale_dir);
1062 notiMsg = dgettext(pkg_name, text);
1069 return g_strdup(notiMsg);
1073 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1078 memset(sql, 0x00, sizeof(sql));
1079 memset(order, 0x00, sizeof(order));
1081 if (pSortRule->bAscending == true)
1082 strncpy(order, "ASC", 5);
1084 strncpy(order, "DESC", 5);
1086 switch (pSortRule->sortType) {
1087 case MSG_SORT_BY_DISPLAY_FROM :
1088 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1090 case MSG_SORT_BY_DISPLAY_TO :
1091 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1093 case MSG_SORT_BY_DISPLAY_TIME :
1094 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1096 case MSG_SORT_BY_MSG_TYPE :
1097 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1099 case MSG_SORT_BY_READ_STATUS :
1100 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1102 case MSG_SORT_BY_STORAGE_TYPE :
1103 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1105 case MSG_SORT_BY_THREAD_NAME :
1106 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1108 case MSG_SORT_BY_THREAD_DATE :
1109 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1111 case MSG_SORT_BY_THREAD_COUNT :
1112 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1115 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1119 memcpy(pSqlSort, sql, strlen(sql));
1123 bool msg_is_valid_email(char *pAddress)
1125 if (!pAddress || pAddress[0] == 0)
1127 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1132 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1134 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1135 pMsgInfo->bTextSms = false;
1137 /* Save Message Data into File */
1138 char fileName[MSG_FILENAME_LEN_MAX+1];
1139 memset(fileName, 0x00, sizeof(fileName));
1141 if(MsgCreateFileName(fileName) == false) {
1142 MSG_DEBUG("MsgCreateFileName error");
1143 return MSG_ERR_STORAGE_ERROR;
1146 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1148 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1149 MSG_DEBUG("MsgWriteIpcFile error");
1150 return MSG_ERR_STORAGE_ERROR;
1153 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1154 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1156 pMsgInfo->bTextSms = true;
1158 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1159 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1165 /* change illegal filename character to '_' */
1166 void msg_replace_available_file_name(char *fileName)
1170 bool is_converted = false;
1173 len = strlen(fileName);
1175 while (fileName[idx] != 0) {
1177 MSG_WARN("idx : %d, len : %d", idx, len);
1181 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1182 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1183 fileName[idx++] = '_';
1184 is_converted = true;
1192 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1195 /* change character ' ' to '_' */
1196 void msg_replace_space_char(char *pszText)
1199 MSG_ERR("pszText is NULL");
1203 char *spaceCharPtr = strchr(pszText, ' ');
1205 while (spaceCharPtr) {
1206 *spaceCharPtr = '_';
1207 spaceCharPtr = strchr(pszText, ' ');
1211 /* change non-ascii character to underscore */
1212 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1215 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1219 gsize result_len = 0;
1221 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1222 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1224 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1225 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1232 static int __find_login_user(uid_t *uid)
1236 int uids_len = sd_get_active_uids(&uids);
1240 if (uids_len != 1) {
1252 uid_t msg_get_login_user()
1256 if (__find_login_user(&uid) < 0) {
1257 MSG_WARN("Cannot find login user");
1260 MSG_DEBUG("login user id [%d]", uid);
1266 void* _msg_launch_app(void *data)
1269 msg_launch_app_data *ad = (msg_launch_app_data *)data;
1270 int ret = aul_launch_app_for_uid(ad->app_id, ad->bundle_data, msg_get_login_user());
1272 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
1276 bundle_free(ad->bundle_data);
1283 msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
1285 msg_launch_app_data *data = (msg_launch_app_data *)calloc(1, sizeof(msg_launch_app_data));
1287 MSG_ERR("Memory alloc failed!");
1288 return MSG_ERR_MEMORY_ERROR;
1291 data->app_id = g_strdup(app_id);
1292 data->bundle_data = bundle_dup(bundle_data);
1295 if (pthread_create(&thd, NULL, &_msg_launch_app, data) < 0) {
1296 MSG_DEBUG("pthread_create() error");
1299 pthread_detach(thd);
1304 msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation)
1306 int ret = aul_svc_set_operation(bundle_data, operation);
1308 MSG_DEBUG("aul_svc_set_operation() is failed : %d", ret);
1309 return MSG_ERR_UNKNOWN;
1316 msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
1318 int ret = aul_svc_set_uri(bundle_data, uri);
1320 MSG_DEBUG("aul_svc_set_uri() is failed : %d", ret);
1321 return MSG_ERR_UNKNOWN;
1328 void msg_set_dpm_policy(int type, int state)
1330 dpm_policy_enable[type] = state;
1334 bool msg_check_dpm_policy(int type)
1336 return dpm_policy_enable[MSG_SMS_TYPE];
1337 // return dpm_policy_enable[type];
1341 void msg_syspopup_message(bool is_sending)
1343 MSG_DEBUG("popup toast for dpm restriction. is_sending [%d]", is_sending);
1345 GDBusConnection *connection = NULL;
1346 GDBusProxy *dbus_proxy = NULL;
1347 GVariant *result = NULL;
1348 GError *error = NULL;
1350 connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1352 MSG_ERR("Connecting to system bus failed: %s\n", error->message);
1356 dbus_proxy = g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_NONE, NULL,
1357 SYSPOPUP_BUS_NAME, SYSPOPUP_OBJECT_PATH, SYSPOPUP_INTERFACE, NULL, &error);
1359 MSG_ERR("Connecting to proxy failed: %s\n", error->message);
1363 result = g_dbus_proxy_call_sync(dbus_proxy, SYSPOPUP_METHOD_SHOW,
1364 g_variant_new("(s)", is_sending ? "message-sending" : "message-retrieving"),
1365 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1367 MSG_ERR("invoking proxy call failed: %s\n", error->message);
1373 g_error_free(error);
1378 g_object_unref(connection);
1383 g_object_unref(dbus_proxy);
1388 g_object_unref(result);