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;
70 /*==================================================================================================
71 FUNCTION IMPLEMENTATION
72 ==================================================================================================*/
74 bool MsgCheckFeatureSupport(const char *feature_name)
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);
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);
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]);
88 b_feature_cache_flag = true;
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];
101 int MsgContactGetMinMatchDigit()
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");
108 MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
110 if (phonenumberMinMatchDigit < 1) {
111 phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
115 return phonenumberMinMatchDigit;
117 return DEFAULT_MIN_MATCH_DIGIT;
122 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
126 dataSize = sizeof(MSG_COUNT_INFO_S);
128 *ppDest = (char*)new char[dataSize];
130 void* p = (void*)*ppDest;
132 memcpy(p, pCountInfo, dataSize);
138 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
140 int count = 0, dataSize = 0;
142 count = pRecipientList->recipientCnt;
143 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
145 *ppDest = (char*)new char[dataSize];
147 void* p = (void*)*ppDest;
149 memcpy(p, &count, sizeof(int));
150 p = (void*)((char*)p + sizeof(int));
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));
161 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
165 dataSize = sizeof(int);
167 *ppDest = (char*)new char[dataSize];
169 void* p = (void*)*ppDest;
171 memcpy(p, &MsgCount, dataSize);
177 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
181 dataSize = (sizeof(msg_message_id_t));
183 *ppDest = (char*)new char[dataSize];
185 void* p = (void*)*ppDest;
187 memcpy(p, pMsgId, dataSize);
193 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
197 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
199 *ppDest = (char*)new char[dataSize];
201 void* p = (void*)*ppDest;
203 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
205 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
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));
216 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
220 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
222 *ppDest = (char*)new char[dataSize];
224 void* p = (void*)*ppDest;
226 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
228 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
230 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
232 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
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));
243 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
245 int count = 0, dataSize = 0;
247 count = pFolderList->nCount;
248 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
250 *ppDest = (char*)new char[dataSize];
252 void* p = (void*)*ppDest;
254 memcpy(p, &count, sizeof(int));
255 p = (void*)((char*)p + sizeof(int));
257 msg_struct_s *folder_info = NULL;
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));
269 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
271 int count = 0, dataSize = 0;
273 count = pFilterList->nCount;
274 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
276 *ppDest = (char*)new char[dataSize];
278 void* p = (void*)*ppDest;
280 memcpy(p, &count, sizeof(int));
281 p = (void*)((char*)p + sizeof(int));
283 msg_struct_s *filter_info = NULL;
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));
295 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
299 dataSize = (sizeof(bool));
301 *ppDest = (char*)new char[dataSize];
303 void* p = (void*)*ppDest;
305 memcpy(p, pSetFlag, dataSize);
311 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
313 int count = 0, dataSize = 0;
315 count = pThreadViewList->nCount;
317 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
319 *ppDest = (char*)new char[dataSize];
321 void* p = (void*)*ppDest;
323 memcpy(p, &count, sizeof(int));
324 p = (void*)((char*)p + sizeof(int));
326 msg_struct_s *thread_info = NULL;
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));
338 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
340 int count = 0, dataSize = 0;
342 count = pConvViewList->nCount;
344 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
346 *ppDest = (char*)new char[dataSize];
348 void* p = (void*)*ppDest;
350 memcpy(p, &count, sizeof(int));
351 p = (void*)((char*)p + sizeof(int));
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));
362 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
364 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
366 MSG_DEBUG("datasize = [%d] \n", dataSize);
368 *ppDest = (char*)new char[dataSize];
370 void* p = (void*)*ppDest;
372 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
373 p = (void*)((char*)p + sizeof(int));
375 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
376 p = (void*)((char*)p + sizeof(int));
378 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
379 p = (void*)((char*)p + sizeof(int));
381 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
382 p = (void*)((char*)p + sizeof(int));
387 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
391 dataSize = sizeof(unsigned int);
393 *ppDest = (char*)new char[dataSize];
395 void* p = (void*)*ppDest;
397 memcpy(p, memsize, dataSize);
403 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
407 dataSize = sizeof(int) + sizeof(int);
409 *ppDest = (char*)new char[dataSize];
411 void* p = (void*)*ppDest;
413 memcpy(p, &msgId, sizeof(int));
414 p = (void*)((char*)p + sizeof(int));
416 memcpy(p, &extId, sizeof(int));
422 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
427 count = pMsgIdList->nCount;
429 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
431 *ppDest = (char*)new char[dataSize];
433 void* p = (void*)*ppDest;
435 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
436 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
438 memcpy(p, &count, sizeof(int));
439 p = (void*)((char*)p + sizeof(int));
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));
450 int MsgEncodeThreadChangeData(const msg_storage_change_type_t storageChangeType, const msg_thread_id_t threadId, char **ppDest)
454 dataSize = sizeof(msg_storage_change_type_t) + sizeof(msg_thread_id_t);
456 *ppDest = (char*)new char[dataSize];
458 void* p = (void*)*ppDest;
460 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
461 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
463 memcpy(p, &threadId, sizeof(msg_thread_id_t));
469 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
474 addr_len = strlen(pMsgInfo->addressList->addressVal);
476 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
478 *ppDest = (char*)new char[dataSize];
480 void* p = (void*)*ppDest;
482 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
483 p = (void*)((char*)p + sizeof(msg_report_type_t));
485 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
486 p = (void*)((char*)p + sizeof(msg_message_id_t));
488 memcpy(p, &addr_len, sizeof(int));
489 p = (void*)((char*)p + sizeof(int));
491 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
492 p = (void*)((char*)p + addr_len);
498 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
502 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
504 *ppDest = (char*)new char[dataSize];
506 void* p = (void*)*ppDest;
508 memcpy(p, &count, sizeof(int));
510 p = (void*)((char*)p + sizeof(int));
512 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
518 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
522 dataSize = (sizeof(msg_thread_id_t));
524 *ppDest = (char*)new char[dataSize];
526 void* p = (void*)*ppDest;
528 memcpy(p, pThreadId, dataSize);
534 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
538 dataSize = sizeof(MSG_THREAD_VIEW_S);
540 *ppDest = (char*)new char[dataSize];
542 void* p = (void*)*ppDest;
544 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
546 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
553 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
555 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
559 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
561 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
565 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
567 memcpy(memsize, pSrc, sizeof(unsigned int));
571 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
573 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
575 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
577 pMsgInfo->addressList = NULL;
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);
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));
588 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
590 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
592 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
594 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
596 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
598 if(pMsgInfo->nAddressCnt > 0) {
599 pMsgInfo->addressList = NULL;
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);
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));
611 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
615 memcpy(&count, pSrc, sizeof(int));
616 pSrc = pSrc + sizeof(int);
618 pRecipientList->recipientCnt = count;
619 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
621 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
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);
631 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
635 memcpy(&count, pSrc, sizeof(int));
636 pSrc = pSrc + sizeof(int);
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;
645 msg_struct_s *pInfoTmp = NULL;
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);
655 } else if ( count == 0 ) {
656 pFolderList->nCount = count;
657 pFolderList->msg_struct_info = NULL;
662 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
666 memcpy(&count, pSrc, sizeof(int));
667 pSrc = pSrc + sizeof(int);
670 pFilterList->nCount = count;
671 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
673 if (pFilterList->msg_struct_info == NULL) {
674 pFilterList->nCount = 0;
678 msg_struct_s *pStructTmp = NULL;
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);
688 } else if ( count == 0 ) {
689 pFilterList->nCount = count;
690 pFilterList->msg_struct_info = NULL;
695 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
697 memcpy(pSetFlag, pSrc, sizeof(bool));
701 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
703 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
707 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
714 memcpy(&count, pSrc, sizeof(int));
715 pSrc = pSrc + sizeof(int);
716 pMsgThreadCountList->totalCount = count;
719 memcpy(&count, pSrc, sizeof(int));
720 pSrc = pSrc + sizeof(int);
721 pMsgThreadCountList->unReadCount = count;
724 memcpy(&count, pSrc, sizeof(int));
725 pSrc = pSrc + sizeof(int);
726 pMsgThreadCountList->mmsMsgCount = count;
729 memcpy(&count, pSrc, sizeof(int));
730 pSrc = pSrc + sizeof(int);
731 pMsgThreadCountList->smsMsgCount = count;
738 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
745 memcpy(&count, pSrc, sizeof(int));
746 pSrc = pSrc + sizeof(int);
748 report_list->nCount = count;
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));
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));
760 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
762 report_status[i] = (msg_struct_t)report_status_item;
764 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
765 report_status_info->type, report_status_info->addressVal,
766 report_status_info->status, report_status_info->statusTime);
769 report_list->msg_struct_info = report_status;
773 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
775 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
778 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
780 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
784 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
786 MSG_EVENT_S* pMsgEvent = NULL;
789 MSG_DEBUG("*ppEvent is not NULL.");
790 delete [] (char *)*ppEvent;
793 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
795 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
797 pMsgEvent->eventType = MsgEvent;
798 pMsgEvent->result = MsgError;
800 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
801 MSG_DEBUG("result [%d]", pMsgEvent->result);
804 memcpy((void*)pMsgEvent->data, pData, DataSize);
806 return (sizeof(MSG_EVENT_S) + DataSize);
809 int msg_verify_number(const char *raw, char *trimmed)
811 if (!(raw && trimmed)) {
812 MSG_DEBUG("Phone Number is NULL");
813 return MSG_ERR_NULL_POINTER;
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] == '-') {
823 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
824 return MSG_ERR_INVALID_PARAMETER;
828 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
832 int msg_verify_email(const char *raw)
835 bool atExist = false;
838 MSG_DEBUG("Email is NULL");
839 return MSG_ERR_NULL_POINTER;
842 for (int i = 0; raw[i]; i++) {
846 if (atExist == false) {
850 MSG_DEBUG("Character [@] is included more than twice in email address.");
851 return MSG_ERR_INVALID_PARAMETER;
855 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
857 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
860 } else if (raw[i] == ',') {
861 if (onlyNum == false && atExist == false) {
862 MSG_DEBUG("Unacceptable type in address.");
863 return MSG_ERR_INVALID_PARAMETER;
869 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
870 return MSG_ERR_INVALID_PARAMETER;
878 char* msg_clean_country_code(char *src)
882 switch (src[ret++]-'0') {
887 switch (src[ret++]-'0') {
902 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
907 switch (src[ret++]-'0') {
922 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
927 switch (src[ret++]-'0') {
942 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
947 switch (src[ret++]-'0') {
962 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
967 switch (src[ret++]-'0') {
982 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
987 switch (src[ret++]-'0') {
1002 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1007 switch (src[ret++]-'0') {
1022 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1028 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1036 char* msg_normalize_number(char *src)
1038 char *normalized_number;
1041 normalized_number = msg_clean_country_code(src);
1042 else if ('0' == src[0])
1043 normalized_number = src+1;
1045 normalized_number = src;
1047 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1049 return normalized_number;
1053 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
1055 char *notiMsg = NULL;
1058 lang = vconf_get_str(VCONFKEY_LANGSET);
1060 setlocale(LC_MESSAGES, lang);
1062 bindtextdomain(pkg_name, locale_dir);
1064 notiMsg = dgettext(pkg_name, text);
1071 return g_strdup(notiMsg);
1075 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1080 memset(sql, 0x00, sizeof(sql));
1081 memset(order, 0x00, sizeof(order));
1083 if (pSortRule->bAscending == true)
1084 strncpy(order, "ASC", 5);
1086 strncpy(order, "DESC", 5);
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);
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);
1095 case MSG_SORT_BY_DISPLAY_TIME :
1096 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1098 case MSG_SORT_BY_MSG_TYPE :
1099 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1101 case MSG_SORT_BY_READ_STATUS :
1102 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1104 case MSG_SORT_BY_STORAGE_TYPE :
1105 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1107 case MSG_SORT_BY_THREAD_NAME :
1108 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1110 case MSG_SORT_BY_THREAD_DATE :
1111 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1113 case MSG_SORT_BY_THREAD_COUNT :
1114 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1117 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1121 memcpy(pSqlSort, sql, strlen(sql));
1125 bool msg_is_valid_email(char *pAddress)
1127 if (!pAddress || pAddress[0] == 0)
1129 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1134 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1136 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1137 pMsgInfo->bTextSms = false;
1139 /* Save Message Data into File */
1140 char fileName[MSG_FILENAME_LEN_MAX+1];
1141 memset(fileName, 0x00, sizeof(fileName));
1143 if(MsgCreateFileName(fileName) == false) {
1144 MSG_DEBUG("MsgCreateFileName error");
1145 return MSG_ERR_STORAGE_ERROR;
1148 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1150 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1151 MSG_DEBUG("MsgWriteIpcFile error");
1152 return MSG_ERR_STORAGE_ERROR;
1155 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1156 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1158 pMsgInfo->bTextSms = true;
1160 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1161 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1167 /* change illegal filename character to '_' */
1168 void msg_replace_available_file_name(char *fileName)
1172 bool is_converted = false;
1175 len = strlen(fileName);
1177 while (fileName[idx] != 0) {
1179 MSG_WARN("idx : %d, len : %d", idx, len);
1183 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1184 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1185 fileName[idx++] = '_';
1186 is_converted = true;
1194 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1197 /* change character ' ' to '_' */
1198 void msg_replace_space_char(char *pszText)
1201 MSG_ERR("pszText is NULL");
1205 char *spaceCharPtr = strchr(pszText, ' ');
1207 while (spaceCharPtr) {
1208 *spaceCharPtr = '_';
1209 spaceCharPtr = strchr(pszText, ' ');
1213 /* change non-ascii character to underscore */
1214 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1217 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1221 gsize result_len = 0;
1223 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1224 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1226 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1227 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1234 static int __find_login_user(uid_t *uid)
1238 int uids_len = sd_get_active_uids(&uids);
1242 if (uids_len != 1) {
1254 uid_t msg_get_login_user()
1258 if (__find_login_user(&uid) < 0) {
1259 MSG_WARN("Cannot find login user");
1262 MSG_DEBUG("login user id [%d]", uid);
1268 void* _msg_launch_app(void *data)
1270 pthread_mutex_lock(&mx);
1272 msg_launch_app_data *ad = (msg_launch_app_data *)data;
1273 int ret = aul_launch_app_for_uid(ad->app_id, ad->bundle_data, msg_get_login_user());
1275 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
1279 bundle_free(ad->bundle_data);
1282 pthread_mutex_unlock(&mx);
1287 msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
1289 msg_launch_app_data *data = (msg_launch_app_data *)calloc(1, sizeof(msg_launch_app_data));
1291 MSG_ERR("Memory alloc failed!");
1292 return MSG_ERR_MEMORY_ERROR;
1295 data->app_id = g_strdup(app_id);
1296 data->bundle_data = bundle_dup(bundle_data);
1299 if (pthread_create(&thd, NULL, &_msg_launch_app, data) < 0) {
1300 MSG_DEBUG("pthread_create() error");
1303 pthread_detach(thd);
1308 msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation)
1310 int ret = aul_svc_set_operation(bundle_data, operation);
1312 MSG_DEBUG("aul_svc_set_operation() is failed : %d", ret);
1313 return MSG_ERR_UNKNOWN;
1320 msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
1322 int ret = aul_svc_set_uri(bundle_data, uri);
1324 MSG_DEBUG("aul_svc_set_uri() is failed : %d", ret);
1325 return MSG_ERR_UNKNOWN;
1332 void msg_set_dpm_policy(int type, int state)
1334 dpm_policy_enable[type] = state;
1338 bool msg_check_dpm_policy(int type)
1340 return dpm_policy_enable[MSG_SMS_TYPE];
1341 // return dpm_policy_enable[type];
1345 void msg_syspopup_message(bool is_sending)
1347 MSG_DEBUG("popup toast for dpm restriction. is_sending [%d]", is_sending);
1349 GDBusConnection *connection = NULL;
1350 GDBusProxy *dbus_proxy = NULL;
1351 GVariant *result = NULL;
1352 GError *error = NULL;
1354 connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1356 MSG_ERR("Connecting to system bus failed: %s\n", error->message);
1360 dbus_proxy = g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_NONE, NULL,
1361 SYSPOPUP_BUS_NAME, SYSPOPUP_OBJECT_PATH, SYSPOPUP_INTERFACE, NULL, &error);
1363 MSG_ERR("Connecting to proxy failed: %s\n", error->message);
1367 result = g_dbus_proxy_call_sync(dbus_proxy, SYSPOPUP_METHOD_SHOW,
1368 g_variant_new("(s)", is_sending ? "message-sending" : "message-retrieving"),
1369 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1371 MSG_ERR("invoking proxy call failed: %s\n", error->message);
1377 g_error_free(error);
1382 g_object_unref(connection);
1387 g_object_unref(dbus_proxy);
1392 g_object_unref(result);