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>
33 #include <dpm/restriction.h>
35 typedef struct _msg_launch_app_data {
38 } msg_launch_app_data;
40 #define DEFAULT_MIN_MATCH_DIGIT 8
42 enum _FEATURE_INDEX_E {
43 FEATURE_INDEX_SMS = 0,
44 FEATURE_INDEX_MMS = 1,
47 static bool b_feature_cache_flag = false;
48 static bool b_feature_support[] = {
49 [FEATURE_INDEX_SMS] = false,
50 [FEATURE_INDEX_MMS] = false,
53 static int dpm_policy_enable[] = {
54 [MSG_UNKNOWN_TYPE] = 0,
59 device_policy_manager_h dpm_handle = NULL;
60 bool is_dpm_init = false;
61 int dpm_sms_callback_id = 0;
62 int dpm_mms_callback_id = 0;
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 MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
453 addr_len = strlen(pMsgInfo->addressList->addressVal);
455 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
457 *ppDest = (char*)new char[dataSize];
459 void* p = (void*)*ppDest;
461 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
462 p = (void*)((char*)p + sizeof(msg_report_type_t));
464 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
465 p = (void*)((char*)p + sizeof(msg_message_id_t));
467 memcpy(p, &addr_len, sizeof(int));
468 p = (void*)((char*)p + sizeof(int));
470 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
471 p = (void*)((char*)p + addr_len);
477 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
481 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
483 *ppDest = (char*)new char[dataSize];
485 void* p = (void*)*ppDest;
487 memcpy(p, &count, sizeof(int));
489 p = (void*)((char*)p + sizeof(int));
491 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
497 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
501 dataSize = (sizeof(msg_thread_id_t));
503 *ppDest = (char*)new char[dataSize];
505 void* p = (void*)*ppDest;
507 memcpy(p, pThreadId, dataSize);
513 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
517 dataSize = sizeof(MSG_THREAD_VIEW_S);
519 *ppDest = (char*)new char[dataSize];
521 void* p = (void*)*ppDest;
523 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
525 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
532 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
534 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
538 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
540 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
544 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
546 memcpy(memsize, pSrc, sizeof(unsigned int));
550 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
552 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
554 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
556 pMsgInfo->addressList = NULL;
558 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
559 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
561 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
562 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
567 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
569 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
571 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
573 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
575 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
577 if(pMsgInfo->nAddressCnt > 0) {
578 pMsgInfo->addressList = NULL;
580 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
581 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
583 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
584 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
590 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
594 memcpy(&count, pSrc, sizeof(int));
595 pSrc = pSrc + sizeof(int);
597 pRecipientList->recipientCnt = count;
598 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
600 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
602 for (int i = 0; i < count; i++) {
603 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
604 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
610 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
614 memcpy(&count, pSrc, sizeof(int));
615 pSrc = pSrc + sizeof(int);
618 pFolderList->nCount = count;
619 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
620 if (pFolderList->msg_struct_info == NULL) {
621 pFolderList->nCount = 0;
624 msg_struct_s *pInfoTmp = NULL;
626 for (int i = 0; i < count; i++) {
627 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
628 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
629 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
630 pInfoTmp->data = new MSG_FOLDER_INFO_S;
631 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
632 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
634 } else if ( count == 0 ) {
635 pFolderList->nCount = count;
636 pFolderList->msg_struct_info = NULL;
641 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
645 memcpy(&count, pSrc, sizeof(int));
646 pSrc = pSrc + sizeof(int);
649 pFilterList->nCount = count;
650 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
652 if (pFilterList->msg_struct_info == NULL) {
653 pFilterList->nCount = 0;
657 msg_struct_s *pStructTmp = NULL;
659 for (int i = 0; i < count; i++) {
660 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
661 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
662 pStructTmp->type = MSG_STRUCT_FILTER;
663 pStructTmp->data = new MSG_FILTER_S;
664 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
665 pSrc = pSrc + sizeof(MSG_FILTER_S);
667 } else if ( count == 0 ) {
668 pFilterList->nCount = count;
669 pFilterList->msg_struct_info = NULL;
674 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
676 memcpy(pSetFlag, pSrc, sizeof(bool));
680 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
682 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
686 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
693 memcpy(&count, pSrc, sizeof(int));
694 pSrc = pSrc + sizeof(int);
695 pMsgThreadCountList->totalCount = count;
698 memcpy(&count, pSrc, sizeof(int));
699 pSrc = pSrc + sizeof(int);
700 pMsgThreadCountList->unReadCount = count;
703 memcpy(&count, pSrc, sizeof(int));
704 pSrc = pSrc + sizeof(int);
705 pMsgThreadCountList->mmsMsgCount = count;
708 memcpy(&count, pSrc, sizeof(int));
709 pSrc = pSrc + sizeof(int);
710 pMsgThreadCountList->smsMsgCount = count;
717 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
724 memcpy(&count, pSrc, sizeof(int));
725 pSrc = pSrc + sizeof(int);
727 report_list->nCount = count;
729 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
730 for (int i = 0; i < count; i++) {
731 msg_struct_s *report_status_item = new msg_struct_s;
732 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
733 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
734 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
736 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
737 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
739 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
741 report_status[i] = (msg_struct_t)report_status_item;
743 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
744 report_status_info->type, report_status_info->addressVal,
745 report_status_info->status, report_status_info->statusTime);
748 report_list->msg_struct_info = report_status;
752 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
754 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
757 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
759 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
763 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
765 MSG_EVENT_S* pMsgEvent = NULL;
768 MSG_DEBUG("*ppEvent is not NULL.");
769 delete [] (char *)*ppEvent;
772 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
774 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
776 pMsgEvent->eventType = MsgEvent;
777 pMsgEvent->result = MsgError;
779 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
780 MSG_DEBUG("result [%d]", pMsgEvent->result);
783 memcpy((void*)pMsgEvent->data, pData, DataSize);
785 return (sizeof(MSG_EVENT_S) + DataSize);
788 int msg_verify_number(const char *raw, char *trimmed)
790 if (!(raw && trimmed)) {
791 MSG_DEBUG("Phone Number is NULL");
792 return MSG_ERR_NULL_POINTER;
795 for (int i=0, j=0 ; raw[i] ; i++) {
796 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
797 || raw[i] == '*' || raw[i] == '#') {
798 trimmed[j++] = raw[i];
799 } else if (raw[i] == '-') {
802 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
803 return MSG_ERR_INVALID_PARAMETER;
807 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
811 int msg_verify_email(const char *raw)
814 bool atExist = false;
817 MSG_DEBUG("Email is NULL");
818 return MSG_ERR_NULL_POINTER;
821 for (int i = 0; raw[i]; i++) {
825 if (atExist == false) {
829 MSG_DEBUG("Character [@] is included more than twice in email address.");
830 return MSG_ERR_INVALID_PARAMETER;
834 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
836 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
839 } else if (raw[i] == ',') {
840 if (onlyNum == false && atExist == false) {
841 MSG_DEBUG("Unacceptable type in address.");
842 return MSG_ERR_INVALID_PARAMETER;
848 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
849 return MSG_ERR_INVALID_PARAMETER;
857 char* msg_clean_country_code(char *src)
861 switch (src[ret++]-'0') {
866 switch (src[ret++]-'0') {
881 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
886 switch (src[ret++]-'0') {
901 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
906 switch (src[ret++]-'0') {
921 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
926 switch (src[ret++]-'0') {
941 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
946 switch (src[ret++]-'0') {
961 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
966 switch (src[ret++]-'0') {
981 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
986 switch (src[ret++]-'0') {
1001 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1007 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1015 char* msg_normalize_number(char *src)
1017 char *normalized_number;
1020 normalized_number = msg_clean_country_code(src);
1021 else if ('0' == src[0])
1022 normalized_number = src+1;
1024 normalized_number = src;
1026 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1028 return normalized_number;
1032 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
1034 char *notiMsg = NULL;
1037 lang = vconf_get_str(VCONFKEY_LANGSET);
1039 setlocale(LC_MESSAGES, lang);
1041 bindtextdomain(pkg_name, locale_dir);
1043 notiMsg = dgettext(pkg_name, text);
1050 return g_strdup(notiMsg);
1054 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1059 memset(sql, 0x00, sizeof(sql));
1060 memset(order, 0x00, sizeof(order));
1062 if (pSortRule->bAscending == true)
1063 strncpy(order, "ASC", 5);
1065 strncpy(order, "DESC", 5);
1067 switch (pSortRule->sortType) {
1068 case MSG_SORT_BY_DISPLAY_FROM :
1069 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1071 case MSG_SORT_BY_DISPLAY_TO :
1072 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1074 case MSG_SORT_BY_DISPLAY_TIME :
1075 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1077 case MSG_SORT_BY_MSG_TYPE :
1078 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1080 case MSG_SORT_BY_READ_STATUS :
1081 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1083 case MSG_SORT_BY_STORAGE_TYPE :
1084 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1086 case MSG_SORT_BY_THREAD_NAME :
1087 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1089 case MSG_SORT_BY_THREAD_DATE :
1090 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1092 case MSG_SORT_BY_THREAD_COUNT :
1093 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1096 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1100 memcpy(pSqlSort, sql, strlen(sql));
1104 bool msg_is_valid_email(char *pAddress)
1106 if (!pAddress || pAddress[0] == 0)
1108 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1113 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1115 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1116 pMsgInfo->bTextSms = false;
1118 /* Save Message Data into File */
1119 char fileName[MSG_FILENAME_LEN_MAX+1];
1120 memset(fileName, 0x00, sizeof(fileName));
1122 if(MsgCreateFileName(fileName) == false) {
1123 MSG_DEBUG("MsgCreateFileName error");
1124 return MSG_ERR_STORAGE_ERROR;
1127 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1129 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1130 MSG_DEBUG("MsgWriteIpcFile error");
1131 return MSG_ERR_STORAGE_ERROR;
1134 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1135 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1137 pMsgInfo->bTextSms = true;
1139 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1140 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1146 /* change illegal filename character to '_' */
1147 void msg_replace_available_file_name(char *fileName)
1151 bool is_converted = false;
1154 len = strlen(fileName);
1156 while (fileName[idx] != 0) {
1158 MSG_WARN("idx : %d, len : %d", idx, len);
1162 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1163 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1164 fileName[idx++] = '_';
1165 is_converted = true;
1173 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1176 /* change character ' ' to '_' */
1177 void msg_replace_space_char(char *pszText)
1180 MSG_ERR("pszText is NULL");
1184 char *spaceCharPtr = strchr(pszText, ' ');
1186 while (spaceCharPtr) {
1187 *spaceCharPtr = '_';
1188 spaceCharPtr = strchr(pszText, ' ');
1192 /* change non-ascii character to underscore */
1193 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1196 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1200 gsize result_len = 0;
1202 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1203 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1205 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1206 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1213 static int __find_login_user(uid_t *uid)
1218 int uids_len = sd_get_uids(&uids);
1222 for (int i = 0; i < uids_len; i++) {
1223 if (sd_uid_get_state(uids[i], &state) < 0) {
1227 if (g_strcmp0(state, "online") == 0) {
1243 uid_t msg_get_login_user()
1247 if (__find_login_user(&uid) < 0) {
1248 MSG_WARN("Cannot find login user");
1251 MSG_DEBUG("login user id [%d]", uid);
1257 void* _msg_launch_app(void *data)
1260 msg_launch_app_data *ad = (msg_launch_app_data *)data;
1261 int ret = aul_launch_app_for_uid(ad->app_id, ad->bundle_data, msg_get_login_user());
1263 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
1267 bundle_free(ad->bundle_data);
1274 msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
1276 msg_launch_app_data *data = (msg_launch_app_data *)calloc(1, sizeof(msg_launch_app_data));
1277 data->app_id = g_strdup(app_id);
1278 data->bundle_data = bundle_dup(bundle_data);
1281 if (pthread_create(&thd, NULL, &_msg_launch_app, data) < 0) {
1282 MSG_DEBUG("pthread_create() error");
1285 pthread_detach(thd);
1290 msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation)
1292 int ret = aul_svc_set_operation(bundle_data, operation);
1294 MSG_DEBUG("aul_svc_set_operation() is failed : %d", ret);
1295 return MSG_ERR_UNKNOWN;
1302 msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
1304 int ret = aul_svc_set_uri(bundle_data, uri);
1306 MSG_DEBUG("aul_svc_set_uri() is failed : %d", ret);
1307 return MSG_ERR_UNKNOWN;
1314 void dpm_sms_policy_changed_callback(const char* name, const char* object, void *user_data)
1316 MSG_INFO("dpm_sms_policy_changed_callback called. name [%s] object [%s]", name, object);
1320 ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_SMS_TYPE - 1]);
1321 if (ret != DPM_ERROR_NONE) {
1322 MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
1328 void dpm_mms_policy_changed_callback(const char* name, const char* object, void *user_data)
1330 MSG_INFO("dpm_mms_policy_changed_callback called. name [%s] object [%s]", name, object);
1334 ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_MMS_TYPE - 1]);
1335 if (ret != DPM_ERROR_NONE) {
1336 MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
1342 static bool __get_dpm_policy()
1346 ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_SMS_TYPE]);
1347 if (ret != DPM_ERROR_NONE) {
1348 MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
1352 MSG_DEBUG("sms policy [%d]", dpm_policy_enable[MSG_SMS_TYPE]);
1353 MSG_DEBUG("mms policy [%d]", dpm_policy_enable[MSG_MMS_TYPE]);
1355 ret = dpm_add_policy_changed_cb(dpm_handle, "messaging", dpm_sms_policy_changed_callback, NULL, &dpm_sms_callback_id);
1356 if (ret != DPM_ERROR_NONE) {
1357 MSG_ERR("dpm_add_policy_changed_cb failed [%d]", ret);
1364 void msg_init_dpm_policy()
1368 dpm_handle = dpm_manager_create();
1369 if (dpm_handle == NULL) {
1370 MSG_ERR("dpm_manager_create() failed");
1374 is_dpm_init = __get_dpm_policy();
1380 void msg_deinit_dpm_policy()
1383 dpm_manager_destroy(dpm_handle);
1385 if (dpm_sms_callback_id)
1386 dpm_remove_policy_changed_cb(dpm_handle, dpm_sms_callback_id);
1388 if (dpm_mms_callback_id)
1389 dpm_remove_policy_changed_cb(dpm_handle, dpm_mms_callback_id);
1391 is_dpm_init = false;
1394 bool msg_check_dpm_policy(int type)
1396 if (is_dpm_init == false)
1397 msg_init_dpm_policy();
1399 return dpm_policy_enable[MSG_SMS_TYPE];
1400 // return dpm_policy_enable[type];