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 MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
447 addr_len = strlen(pMsgInfo->addressList->addressVal);
449 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
451 *ppDest = (char*)new char[dataSize];
453 void* p = (void*)*ppDest;
455 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
456 p = (void*)((char*)p + sizeof(msg_report_type_t));
458 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
459 p = (void*)((char*)p + sizeof(msg_message_id_t));
461 memcpy(p, &addr_len, sizeof(int));
462 p = (void*)((char*)p + sizeof(int));
464 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
465 p = (void*)((char*)p + addr_len);
471 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
475 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
477 *ppDest = (char*)new char[dataSize];
479 void* p = (void*)*ppDest;
481 memcpy(p, &count, sizeof(int));
483 p = (void*)((char*)p + sizeof(int));
485 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
491 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
495 dataSize = (sizeof(msg_thread_id_t));
497 *ppDest = (char*)new char[dataSize];
499 void* p = (void*)*ppDest;
501 memcpy(p, pThreadId, dataSize);
507 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
511 dataSize = sizeof(MSG_THREAD_VIEW_S);
513 *ppDest = (char*)new char[dataSize];
515 void* p = (void*)*ppDest;
517 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
519 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
526 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
528 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
532 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
534 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
538 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
540 memcpy(memsize, pSrc, sizeof(unsigned int));
544 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
546 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
548 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
550 pMsgInfo->addressList = NULL;
552 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
553 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
555 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
556 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
561 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
563 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
565 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
567 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
569 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
571 if(pMsgInfo->nAddressCnt > 0) {
572 pMsgInfo->addressList = NULL;
574 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
575 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
577 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
578 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
584 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
588 memcpy(&count, pSrc, sizeof(int));
589 pSrc = pSrc + sizeof(int);
591 pRecipientList->recipientCnt = count;
592 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
594 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
596 for (int i = 0; i < count; i++) {
597 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
598 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
604 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
608 memcpy(&count, pSrc, sizeof(int));
609 pSrc = pSrc + sizeof(int);
612 pFolderList->nCount = count;
613 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
614 if (pFolderList->msg_struct_info == NULL) {
615 pFolderList->nCount = 0;
618 msg_struct_s *pInfoTmp = NULL;
620 for (int i = 0; i < count; i++) {
621 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
622 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
623 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
624 pInfoTmp->data = new MSG_FOLDER_INFO_S;
625 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
626 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
628 } else if ( count == 0 ) {
629 pFolderList->nCount = count;
630 pFolderList->msg_struct_info = NULL;
635 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
639 memcpy(&count, pSrc, sizeof(int));
640 pSrc = pSrc + sizeof(int);
643 pFilterList->nCount = count;
644 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
646 if (pFilterList->msg_struct_info == NULL) {
647 pFilterList->nCount = 0;
651 msg_struct_s *pStructTmp = NULL;
653 for (int i = 0; i < count; i++) {
654 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
655 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
656 pStructTmp->type = MSG_STRUCT_FILTER;
657 pStructTmp->data = new MSG_FILTER_S;
658 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
659 pSrc = pSrc + sizeof(MSG_FILTER_S);
661 } else if ( count == 0 ) {
662 pFilterList->nCount = count;
663 pFilterList->msg_struct_info = NULL;
668 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
670 memcpy(pSetFlag, pSrc, sizeof(bool));
674 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
676 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
680 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
687 memcpy(&count, pSrc, sizeof(int));
688 pSrc = pSrc + sizeof(int);
689 pMsgThreadCountList->totalCount = count;
692 memcpy(&count, pSrc, sizeof(int));
693 pSrc = pSrc + sizeof(int);
694 pMsgThreadCountList->unReadCount = count;
697 memcpy(&count, pSrc, sizeof(int));
698 pSrc = pSrc + sizeof(int);
699 pMsgThreadCountList->mmsMsgCount = count;
702 memcpy(&count, pSrc, sizeof(int));
703 pSrc = pSrc + sizeof(int);
704 pMsgThreadCountList->smsMsgCount = count;
711 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
718 memcpy(&count, pSrc, sizeof(int));
719 pSrc = pSrc + sizeof(int);
721 report_list->nCount = count;
723 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
724 for (int i = 0; i < count; i++) {
725 msg_struct_s *report_status_item = new msg_struct_s;
726 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
727 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
728 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
730 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
731 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
733 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
735 report_status[i] = (msg_struct_t)report_status_item;
737 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
738 report_status_info->type, report_status_info->addressVal,
739 report_status_info->status, report_status_info->statusTime);
742 report_list->msg_struct_info = report_status;
746 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
748 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
751 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
753 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
757 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
759 MSG_EVENT_S* pMsgEvent = NULL;
762 MSG_DEBUG("*ppEvent is not NULL.");
763 delete [] (char *)*ppEvent;
766 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
768 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
770 pMsgEvent->eventType = MsgEvent;
771 pMsgEvent->result = MsgError;
773 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
774 MSG_DEBUG("result [%d]", pMsgEvent->result);
777 memcpy((void*)pMsgEvent->data, pData, DataSize);
779 return (sizeof(MSG_EVENT_S) + DataSize);
782 int msg_verify_number(const char *raw, char *trimmed)
784 if (!(raw && trimmed)) {
785 MSG_DEBUG("Phone Number is NULL");
786 return MSG_ERR_NULL_POINTER;
789 for (int i=0, j=0 ; raw[i] ; i++) {
790 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
791 || raw[i] == '*' || raw[i] == '#') {
792 trimmed[j++] = raw[i];
793 } else if (raw[i] == '-') {
796 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
797 return MSG_ERR_INVALID_PARAMETER;
801 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
805 int msg_verify_email(const char *raw)
808 bool atExist = false;
811 MSG_DEBUG("Email is NULL");
812 return MSG_ERR_NULL_POINTER;
815 for (int i = 0; raw[i]; i++) {
819 if (atExist == false) {
823 MSG_DEBUG("Character [@] is included more than twice in email address.");
824 return MSG_ERR_INVALID_PARAMETER;
828 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
830 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
833 } else if (raw[i] == ',') {
834 if (onlyNum == false && atExist == false) {
835 MSG_DEBUG("Unacceptable type in address.");
836 return MSG_ERR_INVALID_PARAMETER;
842 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
843 return MSG_ERR_INVALID_PARAMETER;
851 char* msg_clean_country_code(char *src)
855 switch (src[ret++]-'0') {
860 switch (src[ret++]-'0') {
875 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
880 switch (src[ret++]-'0') {
895 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
900 switch (src[ret++]-'0') {
915 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
920 switch (src[ret++]-'0') {
935 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
940 switch (src[ret++]-'0') {
955 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
960 switch (src[ret++]-'0') {
975 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
980 switch (src[ret++]-'0') {
995 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1001 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1009 char* msg_normalize_number(char *src)
1011 char *normalized_number;
1014 normalized_number = msg_clean_country_code(src);
1015 else if ('0' == src[0])
1016 normalized_number = src+1;
1018 normalized_number = src;
1020 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1022 return normalized_number;
1026 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
1028 char *notiMsg = NULL;
1031 lang = vconf_get_str(VCONFKEY_LANGSET);
1033 setlocale(LC_MESSAGES, lang);
1035 bindtextdomain(pkg_name, locale_dir);
1037 notiMsg = dgettext(pkg_name, text);
1044 return g_strdup(notiMsg);
1048 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1053 memset(sql, 0x00, sizeof(sql));
1054 memset(order, 0x00, sizeof(order));
1056 if (pSortRule->bAscending == true)
1057 strncpy(order, "ASC", 5);
1059 strncpy(order, "DESC", 5);
1061 switch (pSortRule->sortType) {
1062 case MSG_SORT_BY_DISPLAY_FROM :
1063 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1065 case MSG_SORT_BY_DISPLAY_TO :
1066 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1068 case MSG_SORT_BY_DISPLAY_TIME :
1069 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1071 case MSG_SORT_BY_MSG_TYPE :
1072 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1074 case MSG_SORT_BY_READ_STATUS :
1075 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1077 case MSG_SORT_BY_STORAGE_TYPE :
1078 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1080 case MSG_SORT_BY_THREAD_NAME :
1081 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1083 case MSG_SORT_BY_THREAD_DATE :
1084 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1086 case MSG_SORT_BY_THREAD_COUNT :
1087 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1090 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1094 memcpy(pSqlSort, sql, strlen(sql));
1098 bool msg_is_valid_email(char *pAddress)
1100 if (!pAddress || pAddress[0] == 0)
1102 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1107 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1109 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1110 pMsgInfo->bTextSms = false;
1112 /* Save Message Data into File */
1113 char fileName[MSG_FILENAME_LEN_MAX+1];
1114 memset(fileName, 0x00, sizeof(fileName));
1116 if(MsgCreateFileName(fileName) == false) {
1117 MSG_DEBUG("MsgCreateFileName error");
1118 return MSG_ERR_STORAGE_ERROR;
1121 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1123 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1124 MSG_DEBUG("MsgWriteIpcFile error");
1125 return MSG_ERR_STORAGE_ERROR;
1128 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1129 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1131 pMsgInfo->bTextSms = true;
1133 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1134 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1140 /* change illegal filename character to '_' */
1141 void msg_replace_available_file_name(char *fileName)
1145 bool is_converted = false;
1148 len = strlen(fileName);
1150 while (fileName[idx] != 0) {
1152 MSG_WARN("idx : %d, len : %d", idx, len);
1156 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1157 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1158 fileName[idx++] = '_';
1159 is_converted = true;
1167 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1170 /* change character ' ' to '_' */
1171 void msg_replace_space_char(char *pszText)
1174 MSG_ERR("pszText is NULL");
1178 char *spaceCharPtr = strchr(pszText, ' ');
1180 while (spaceCharPtr) {
1181 *spaceCharPtr = '_';
1182 spaceCharPtr = strchr(pszText, ' ');
1186 /* change non-ascii character to underscore */
1187 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1190 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1194 gsize result_len = 0;
1196 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1197 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1199 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1200 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1207 static int __find_login_user(uid_t *uid)
1212 int uids_len = sd_get_uids(&uids);
1216 for (int i = 0; i < uids_len; i++) {
1217 if (sd_uid_get_state(uids[i], &state) < 0) {
1221 if (g_strcmp0(state, "online") == 0) {
1237 uid_t msg_get_login_user()
1241 if (__find_login_user(&uid) < 0) {
1242 MSG_WARN("Cannot find login user");
1245 MSG_DEBUG("login user id [%d]", uid);
1251 void* _msg_launch_app(void *data)
1254 msg_launch_app_data *ad = (msg_launch_app_data *)data;
1255 int ret = aul_launch_app_for_uid(ad->app_id, ad->bundle_data, msg_get_login_user());
1257 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
1261 bundle_free(ad->bundle_data);
1268 msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
1270 msg_launch_app_data *data = (msg_launch_app_data *)calloc(1, sizeof(msg_launch_app_data));
1271 data->app_id = g_strdup(app_id);
1272 data->bundle_data = bundle_dup(bundle_data);
1275 if (pthread_create(&thd, NULL, &_msg_launch_app, data) < 0) {
1276 MSG_DEBUG("pthread_create() error");
1279 pthread_detach(thd);
1284 msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation)
1286 int ret = aul_svc_set_operation(bundle_data, operation);
1288 MSG_DEBUG("aul_svc_set_operation() is failed : %d", ret);
1289 return MSG_ERR_UNKNOWN;
1296 msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
1298 int ret = aul_svc_set_uri(bundle_data, uri);
1300 MSG_DEBUG("aul_svc_set_uri() is failed : %d", ret);
1301 return MSG_ERR_UNKNOWN;
1308 void msg_set_dpm_policy(int type, int state)
1310 dpm_policy_enable[type] = state;
1314 bool msg_check_dpm_policy(int type)
1316 return dpm_policy_enable[MSG_SMS_TYPE];
1317 // return dpm_policy_enable[type];