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>
34 typedef struct _msg_launch_app_data {
37 } msg_launch_app_data;
39 #define DEFAULT_MIN_MATCH_DIGIT 8
41 enum _FEATURE_INDEX_E {
42 FEATURE_INDEX_SMS = 0,
43 FEATURE_INDEX_MMS = 1,
46 static bool b_feature_cache_flag = false;
47 static bool b_feature_support[] = {
48 [FEATURE_INDEX_SMS] = false,
49 [FEATURE_INDEX_MMS] = false,
52 static int dpm_policy_enable[] = {
53 [MSG_UNKNOWN_TYPE] = 0,
58 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
59 static int phonenumberMinMatchDigit = -1;
62 /*==================================================================================================
63 FUNCTION IMPLEMENTATION
64 ==================================================================================================*/
66 bool MsgCheckFeatureSupport(const char *feature_name)
70 if (b_feature_cache_flag == false) {
71 if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_support[FEATURE_INDEX_SMS]) != SYSTEM_INFO_ERROR_NONE)
72 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE);
74 if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_support[FEATURE_INDEX_MMS]) != SYSTEM_INFO_ERROR_NONE)
75 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE);
77 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_support[FEATURE_INDEX_SMS]);
78 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_support[FEATURE_INDEX_MMS]);
80 b_feature_cache_flag = true;
83 if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) {
84 result = b_feature_support[FEATURE_INDEX_SMS];
85 } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
86 result = b_feature_support[FEATURE_INDEX_MMS];
93 int MsgContactGetMinMatchDigit()
95 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
96 if (phonenumberMinMatchDigit <= 0) {
97 if (MsgSettingGetInt(VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT, &phonenumberMinMatchDigit) != MSG_SUCCESS) {
98 MSG_INFO("MsgSettingGetInt() is failed");
100 MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
102 if (phonenumberMinMatchDigit < 1) {
103 phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
107 return phonenumberMinMatchDigit;
109 return DEFAULT_MIN_MATCH_DIGIT;
114 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
118 dataSize = sizeof(MSG_COUNT_INFO_S);
120 *ppDest = (char*)new char[dataSize];
122 void* p = (void*)*ppDest;
124 memcpy(p, pCountInfo, dataSize);
130 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
132 int count = 0, dataSize = 0;
134 count = pRecipientList->recipientCnt;
135 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
137 *ppDest = (char*)new char[dataSize];
139 void* p = (void*)*ppDest;
141 memcpy(p, &count, sizeof(int));
142 p = (void*)((char*)p + sizeof(int));
144 for (int i = 0; i < count; i++) {
145 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
146 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
153 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
157 dataSize = sizeof(int);
159 *ppDest = (char*)new char[dataSize];
161 void* p = (void*)*ppDest;
163 memcpy(p, &MsgCount, dataSize);
169 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
173 dataSize = (sizeof(msg_message_id_t));
175 *ppDest = (char*)new char[dataSize];
177 void* p = (void*)*ppDest;
179 memcpy(p, pMsgId, dataSize);
185 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
189 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
191 *ppDest = (char*)new char[dataSize];
193 void* p = (void*)*ppDest;
195 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
197 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
199 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
200 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
201 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
208 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
212 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
214 *ppDest = (char*)new char[dataSize];
216 void* p = (void*)*ppDest;
218 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
220 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
222 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
224 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
226 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
227 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
228 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
235 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
237 int count = 0, dataSize = 0;
239 count = pFolderList->nCount;
240 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
242 *ppDest = (char*)new char[dataSize];
244 void* p = (void*)*ppDest;
246 memcpy(p, &count, sizeof(int));
247 p = (void*)((char*)p + sizeof(int));
249 msg_struct_s *folder_info = NULL;
251 for (int i = 0; i < count; i++) {
252 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
253 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
254 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
261 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
263 int count = 0, dataSize = 0;
265 count = pFilterList->nCount;
266 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
268 *ppDest = (char*)new char[dataSize];
270 void* p = (void*)*ppDest;
272 memcpy(p, &count, sizeof(int));
273 p = (void*)((char*)p + sizeof(int));
275 msg_struct_s *filter_info = NULL;
277 for (int i = 0; i < count; i++) {
278 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
279 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
280 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
287 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
291 dataSize = (sizeof(bool));
293 *ppDest = (char*)new char[dataSize];
295 void* p = (void*)*ppDest;
297 memcpy(p, pSetFlag, dataSize);
303 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
305 int count = 0, dataSize = 0;
307 count = pThreadViewList->nCount;
309 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
311 *ppDest = (char*)new char[dataSize];
313 void* p = (void*)*ppDest;
315 memcpy(p, &count, sizeof(int));
316 p = (void*)((char*)p + sizeof(int));
318 msg_struct_s *thread_info = NULL;
320 for (int i = 0; i < count; i++) {
321 thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
322 memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
323 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
330 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
332 int count = 0, dataSize = 0;
334 count = pConvViewList->nCount;
336 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
338 *ppDest = (char*)new char[dataSize];
340 void* p = (void*)*ppDest;
342 memcpy(p, &count, sizeof(int));
343 p = (void*)((char*)p + sizeof(int));
345 for (int i = 0; i < count; i++) {
346 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
347 p = (void*)((char*)p + sizeof(msg_struct_list_s));
354 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
356 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
358 MSG_DEBUG("datasize = [%d] \n", dataSize);
360 *ppDest = (char*)new char[dataSize];
362 void* p = (void*)*ppDest;
364 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
365 p = (void*)((char*)p + sizeof(int));
367 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
368 p = (void*)((char*)p + sizeof(int));
370 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
371 p = (void*)((char*)p + sizeof(int));
373 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
374 p = (void*)((char*)p + sizeof(int));
379 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
383 dataSize = sizeof(unsigned int);
385 *ppDest = (char*)new char[dataSize];
387 void* p = (void*)*ppDest;
389 memcpy(p, memsize, dataSize);
395 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
399 dataSize = sizeof(int) + sizeof(int);
401 *ppDest = (char*)new char[dataSize];
403 void* p = (void*)*ppDest;
405 memcpy(p, &msgId, sizeof(int));
406 p = (void*)((char*)p + sizeof(int));
408 memcpy(p, &extId, sizeof(int));
414 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
419 count = pMsgIdList->nCount;
421 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
423 *ppDest = (char*)new char[dataSize];
425 void* p = (void*)*ppDest;
427 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
428 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
430 memcpy(p, &count, sizeof(int));
431 p = (void*)((char*)p + sizeof(int));
433 for (int i = 0; i < count; i++) {
434 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
435 p = (void*)((char*)p + sizeof(msg_message_id_t));
442 int MsgEncodeThreadChangeData(const msg_storage_change_type_t storageChangeType, const msg_thread_id_t threadId, char **ppDest)
446 dataSize = sizeof(msg_storage_change_type_t) + sizeof(msg_thread_id_t);
448 *ppDest = (char*)new char[dataSize];
450 void* p = (void*)*ppDest;
452 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
453 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
455 memcpy(p, &threadId, sizeof(msg_thread_id_t));
461 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
466 addr_len = strlen(pMsgInfo->addressList->addressVal);
468 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
470 *ppDest = (char*)new char[dataSize];
472 void* p = (void*)*ppDest;
474 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
475 p = (void*)((char*)p + sizeof(msg_report_type_t));
477 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
478 p = (void*)((char*)p + sizeof(msg_message_id_t));
480 memcpy(p, &addr_len, sizeof(int));
481 p = (void*)((char*)p + sizeof(int));
483 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
484 p = (void*)((char*)p + addr_len);
490 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
494 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
496 *ppDest = (char*)new char[dataSize];
498 void* p = (void*)*ppDest;
500 memcpy(p, &count, sizeof(int));
502 p = (void*)((char*)p + sizeof(int));
504 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
510 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
514 dataSize = (sizeof(msg_thread_id_t));
516 *ppDest = (char*)new char[dataSize];
518 void* p = (void*)*ppDest;
520 memcpy(p, pThreadId, dataSize);
526 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
530 dataSize = sizeof(MSG_THREAD_VIEW_S);
532 *ppDest = (char*)new char[dataSize];
534 void* p = (void*)*ppDest;
536 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
538 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
545 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
547 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
551 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
553 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
557 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
559 memcpy(memsize, pSrc, sizeof(unsigned int));
563 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
565 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
567 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
569 pMsgInfo->addressList = NULL;
571 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
572 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
574 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
575 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
580 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
582 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
584 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
586 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
588 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
590 if(pMsgInfo->nAddressCnt > 0) {
591 pMsgInfo->addressList = NULL;
593 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
594 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
596 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
597 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
603 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
607 memcpy(&count, pSrc, sizeof(int));
608 pSrc = pSrc + sizeof(int);
610 pRecipientList->recipientCnt = count;
611 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
613 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
615 for (int i = 0; i < count; i++) {
616 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
617 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
623 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
627 memcpy(&count, pSrc, sizeof(int));
628 pSrc = pSrc + sizeof(int);
631 pFolderList->nCount = count;
632 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
633 if (pFolderList->msg_struct_info == NULL) {
634 pFolderList->nCount = 0;
637 msg_struct_s *pInfoTmp = NULL;
639 for (int i = 0; i < count; i++) {
640 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
641 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
642 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
643 pInfoTmp->data = new MSG_FOLDER_INFO_S;
644 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
645 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
647 } else if ( count == 0 ) {
648 pFolderList->nCount = count;
649 pFolderList->msg_struct_info = NULL;
654 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
658 memcpy(&count, pSrc, sizeof(int));
659 pSrc = pSrc + sizeof(int);
662 pFilterList->nCount = count;
663 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
665 if (pFilterList->msg_struct_info == NULL) {
666 pFilterList->nCount = 0;
670 msg_struct_s *pStructTmp = NULL;
672 for (int i = 0; i < count; i++) {
673 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
674 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
675 pStructTmp->type = MSG_STRUCT_FILTER;
676 pStructTmp->data = new MSG_FILTER_S;
677 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
678 pSrc = pSrc + sizeof(MSG_FILTER_S);
680 } else if ( count == 0 ) {
681 pFilterList->nCount = count;
682 pFilterList->msg_struct_info = NULL;
687 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
689 memcpy(pSetFlag, pSrc, sizeof(bool));
693 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
695 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
699 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
706 memcpy(&count, pSrc, sizeof(int));
707 pSrc = pSrc + sizeof(int);
708 pMsgThreadCountList->totalCount = count;
711 memcpy(&count, pSrc, sizeof(int));
712 pSrc = pSrc + sizeof(int);
713 pMsgThreadCountList->unReadCount = count;
716 memcpy(&count, pSrc, sizeof(int));
717 pSrc = pSrc + sizeof(int);
718 pMsgThreadCountList->mmsMsgCount = count;
721 memcpy(&count, pSrc, sizeof(int));
722 pSrc = pSrc + sizeof(int);
723 pMsgThreadCountList->smsMsgCount = count;
730 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
737 memcpy(&count, pSrc, sizeof(int));
738 pSrc = pSrc + sizeof(int);
740 report_list->nCount = count;
742 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
743 for (int i = 0; i < count; i++) {
744 msg_struct_s *report_status_item = new msg_struct_s;
745 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
746 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
747 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
749 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
750 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
752 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
754 report_status[i] = (msg_struct_t)report_status_item;
756 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
757 report_status_info->type, report_status_info->addressVal,
758 report_status_info->status, report_status_info->statusTime);
761 report_list->msg_struct_info = report_status;
765 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
767 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
770 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
772 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
776 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
778 MSG_EVENT_S* pMsgEvent = NULL;
781 MSG_DEBUG("*ppEvent is not NULL.");
782 delete [] (char *)*ppEvent;
785 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
787 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
789 pMsgEvent->eventType = MsgEvent;
790 pMsgEvent->result = MsgError;
792 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
793 MSG_DEBUG("result [%d]", pMsgEvent->result);
796 memcpy((void*)pMsgEvent->data, pData, DataSize);
798 return (sizeof(MSG_EVENT_S) + DataSize);
801 int msg_verify_number(const char *raw, char *trimmed)
803 if (!(raw && trimmed)) {
804 MSG_DEBUG("Phone Number is NULL");
805 return MSG_ERR_NULL_POINTER;
808 for (int i=0, j=0 ; raw[i] ; i++) {
809 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
810 || raw[i] == '*' || raw[i] == '#') {
811 trimmed[j++] = raw[i];
812 } else if (raw[i] == '-') {
815 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
816 return MSG_ERR_INVALID_PARAMETER;
820 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
824 int msg_verify_email(const char *raw)
827 bool atExist = false;
830 MSG_DEBUG("Email is NULL");
831 return MSG_ERR_NULL_POINTER;
834 for (int i = 0; raw[i]; i++) {
838 if (atExist == false) {
842 MSG_DEBUG("Character [@] is included more than twice in email address.");
843 return MSG_ERR_INVALID_PARAMETER;
847 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
849 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
852 } else if (raw[i] == ',') {
853 if (onlyNum == false && atExist == false) {
854 MSG_DEBUG("Unacceptable type in address.");
855 return MSG_ERR_INVALID_PARAMETER;
861 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
862 return MSG_ERR_INVALID_PARAMETER;
870 char* msg_clean_country_code(char *src)
874 switch (src[ret++]-'0') {
879 switch (src[ret++]-'0') {
894 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
899 switch (src[ret++]-'0') {
914 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
919 switch (src[ret++]-'0') {
934 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
939 switch (src[ret++]-'0') {
954 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
959 switch (src[ret++]-'0') {
974 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
979 switch (src[ret++]-'0') {
994 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
999 switch (src[ret++]-'0') {
1014 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1020 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1028 char* msg_normalize_number(char *src)
1030 char *normalized_number;
1033 normalized_number = msg_clean_country_code(src);
1034 else if ('0' == src[0])
1035 normalized_number = src+1;
1037 normalized_number = src;
1039 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1041 return normalized_number;
1045 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
1047 char *notiMsg = NULL;
1050 lang = vconf_get_str(VCONFKEY_LANGSET);
1052 setlocale(LC_MESSAGES, lang);
1054 bindtextdomain(pkg_name, locale_dir);
1056 notiMsg = dgettext(pkg_name, text);
1063 return g_strdup(notiMsg);
1067 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1072 memset(sql, 0x00, sizeof(sql));
1073 memset(order, 0x00, sizeof(order));
1075 if (pSortRule->bAscending == true)
1076 strncpy(order, "ASC", 5);
1078 strncpy(order, "DESC", 5);
1080 switch (pSortRule->sortType) {
1081 case MSG_SORT_BY_DISPLAY_FROM :
1082 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1084 case MSG_SORT_BY_DISPLAY_TO :
1085 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1087 case MSG_SORT_BY_DISPLAY_TIME :
1088 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1090 case MSG_SORT_BY_MSG_TYPE :
1091 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1093 case MSG_SORT_BY_READ_STATUS :
1094 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1096 case MSG_SORT_BY_STORAGE_TYPE :
1097 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1099 case MSG_SORT_BY_THREAD_NAME :
1100 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1102 case MSG_SORT_BY_THREAD_DATE :
1103 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1105 case MSG_SORT_BY_THREAD_COUNT :
1106 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1109 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1113 memcpy(pSqlSort, sql, strlen(sql));
1117 bool msg_is_valid_email(char *pAddress)
1119 if (!pAddress || pAddress[0] == 0)
1121 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1126 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1128 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1129 pMsgInfo->bTextSms = false;
1131 /* Save Message Data into File */
1132 char fileName[MSG_FILENAME_LEN_MAX+1];
1133 memset(fileName, 0x00, sizeof(fileName));
1135 if(MsgCreateFileName(fileName) == false) {
1136 MSG_DEBUG("MsgCreateFileName error");
1137 return MSG_ERR_STORAGE_ERROR;
1140 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1142 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1143 MSG_DEBUG("MsgWriteIpcFile error");
1144 return MSG_ERR_STORAGE_ERROR;
1147 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1148 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1150 pMsgInfo->bTextSms = true;
1152 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1153 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1159 /* change illegal filename character to '_' */
1160 void msg_replace_available_file_name(char *fileName)
1164 bool is_converted = false;
1167 len = strlen(fileName);
1169 while (fileName[idx] != 0) {
1171 MSG_WARN("idx : %d, len : %d", idx, len);
1175 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1176 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1177 fileName[idx++] = '_';
1178 is_converted = true;
1186 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1189 /* change character ' ' to '_' */
1190 void msg_replace_space_char(char *pszText)
1193 MSG_ERR("pszText is NULL");
1197 char *spaceCharPtr = strchr(pszText, ' ');
1199 while (spaceCharPtr) {
1200 *spaceCharPtr = '_';
1201 spaceCharPtr = strchr(pszText, ' ');
1205 /* change non-ascii character to underscore */
1206 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1209 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1213 gsize result_len = 0;
1215 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1216 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1218 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1219 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1226 static int __find_login_user(uid_t *uid)
1231 int uids_len = sd_get_uids(&uids);
1235 for (int i = 0; i < uids_len; i++) {
1236 if (sd_uid_get_state(uids[i], &state) < 0) {
1240 if (g_strcmp0(state, "online") == 0) {
1256 uid_t msg_get_login_user()
1260 if (__find_login_user(&uid) < 0) {
1261 MSG_WARN("Cannot find login user");
1264 MSG_DEBUG("login user id [%d]", uid);
1270 void* _msg_launch_app(void *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());
1276 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
1280 bundle_free(ad->bundle_data);
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];