X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=utils%2FMsgUtilFunction.cpp;h=e66bfa19d4ddf6203175af713e0d3876be72277e;hb=bca0e9ec6458f92795ca1f032ae94325cf285914;hp=0d746867cade037a6cdb15d127e5381176731230;hpb=7dc0929d24a67391e71e4e07f385acc7b7db1850;p=platform%2Fcore%2Fmessaging%2Fmsg-service.git diff --git a/utils/MsgUtilFunction.cpp b/utils/MsgUtilFunction.cpp index 0d74686..e66bfa1 100755 --- a/utils/MsgUtilFunction.cpp +++ b/utils/MsgUtilFunction.cpp @@ -1,27 +1,124 @@ /* -* Copyright 2012 Samsung Electronics Co., Ltd -* -* Licensed under the Flora License, Version 1.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.tizenopensource.org/license -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. + * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ +#include + #include "MsgDebug.h" +#include "MsgContact.h" +#include "MsgGconfWrapper.h" +#include "MsgUtilFile.h" #include "MsgUtilFunction.h" - - /*================================================================================================== +#include "MsgUtilStorage.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct _msg_launch_app_data { + char *app_id; + bundle *bundle_data; +} msg_launch_app_data; + +#define DEFAULT_MIN_MATCH_DIGIT 8 + +#define SYSPOPUP_BUS_NAME "org.tizen.DevicePolicyManager" +#define SYSPOPUP_OBJECT_PATH "/org/tizen/DevicePolicyManager/Syspopup" +#define SYSPOPUP_INTERFACE "org.tizen.DevicePolicyManager.Syspopup" +#define SYSPOPUP_METHOD_SHOW "show" + +enum _FEATURE_INDEX_E { + FEATURE_INDEX_SMS = 0, + FEATURE_INDEX_MMS = 1, +}; + +static bool b_feature_cache_flag = false; +static bool b_feature_support[] = { + [FEATURE_INDEX_SMS] = false, + [FEATURE_INDEX_MMS] = false, +}; + +static int dpm_policy_enable[] = { + [MSG_UNKNOWN_TYPE] = 0, + [MSG_SMS_TYPE] = 1, + [MSG_MMS_TYPE] = 1, +}; + +#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED +static int phonenumberMinMatchDigit = -1; +#endif + +pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER; + +/*================================================================================================== FUNCTION IMPLEMENTATION ==================================================================================================*/ -// Encoders +bool MsgCheckFeatureSupport(const char *feature_name) +{ + bool result = false; + + if (b_feature_cache_flag == false) { + if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_support[FEATURE_INDEX_SMS]) != SYSTEM_INFO_ERROR_NONE) + MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE); + + if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_support[FEATURE_INDEX_MMS]) != SYSTEM_INFO_ERROR_NONE) + MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE); + + MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_support[FEATURE_INDEX_SMS]); + MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_support[FEATURE_INDEX_MMS]); + + b_feature_cache_flag = true; + } + + if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) { + result = b_feature_support[FEATURE_INDEX_SMS]; + } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) { + result = b_feature_support[FEATURE_INDEX_MMS]; + } + + return result; +} + + +int MsgContactGetMinMatchDigit() +{ +#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED + if (phonenumberMinMatchDigit <= 0) { + if (MsgSettingGetInt(VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT, &phonenumberMinMatchDigit) != MSG_SUCCESS) { + MSG_INFO("MsgSettingGetInt() is failed"); + } + MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit); + + if (phonenumberMinMatchDigit < 1) { + phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT; + } + } + + return phonenumberMinMatchDigit; +#else + return DEFAULT_MIN_MATCH_DIGIT; +#endif +} + +/* Encoders */ int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest) { int dataSize = 0; @@ -52,8 +149,7 @@ int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest) memcpy(p, &count, sizeof(int)); p = (void*)((char*)p + sizeof(int)); - for (int i = 0; i < count; i++) - { + for (int i = 0; i < count; i++) { memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S)); p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S)); } @@ -94,11 +190,11 @@ int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest) } -int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest) +int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest) { int dataSize = 0; - dataSize = sizeof(MSG_MESSAGE_INFO_S); + dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt); *ppDest = (char*)new char[dataSize]; @@ -108,6 +204,11 @@ int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest) p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S)); + for (int i=0; i < pMsgInfo->nAddressCnt; i++) { + memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S)); + p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S)); + } + return dataSize; } @@ -116,7 +217,7 @@ int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendO { int dataSize = 0; - dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S)); + dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt)); *ppDest = (char*)new char[dataSize]; @@ -128,9 +229,17 @@ int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendO memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S)); + p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S)); + + for (int i=0; i < pMsgInfo->nAddressCnt; i++) { + memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S)); + p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S)); + } + return dataSize; } + int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest) { int count = 0, dataSize = 0; @@ -147,8 +256,7 @@ int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest) msg_struct_s *folder_info = NULL; - for (int i = 0; i < count; i++) - { + for (int i = 0; i < count; i++) { folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i]; memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S)); p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S)); @@ -157,6 +265,7 @@ int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest) return dataSize; } + int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest) { int count = 0, dataSize = 0; @@ -173,8 +282,7 @@ int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest) msg_struct_s *filter_info = NULL; - for (int i = 0; i < count; i++) - { + for (int i = 0; i < count; i++) { filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i]; memcpy(p, filter_info->data, sizeof(MSG_FILTER_S)); p = (void*)((char*)p + sizeof(MSG_FILTER_S)); @@ -200,22 +308,6 @@ int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest) } -int MsgEncodeMsgType(MSG_MESSAGE_TYPE_S *pMsgType, char **ppDest) -{ - int dataSize = 0; - - dataSize = (sizeof(MSG_MESSAGE_TYPE_S)); - - *ppDest = (char*)new char[dataSize]; - - void* p = (void*)*ppDest; - - memcpy(p, pMsgType, dataSize); - - return dataSize; -} - - int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest) { int count = 0, dataSize = 0; @@ -233,8 +325,7 @@ int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest) msg_struct_s *thread_info = NULL; - for (int i = 0; i < count; i++) - { + for (int i = 0; i < count; i++) { thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i]; memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S)); p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S)); @@ -259,8 +350,7 @@ int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDes memcpy(p, &count, sizeof(int)); p = (void*)((char*)p + sizeof(int)); - for (int i = 0; i < count; i++) - { + for (int i = 0; i < count; i++) { memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s)); p = (void*)((char*)p + sizeof(msg_struct_list_s)); } @@ -357,6 +447,54 @@ int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType } +int MsgEncodeThreadChangeData(const msg_storage_change_type_t storageChangeType, const msg_thread_id_t threadId, char **ppDest) +{ + int dataSize = 0; + + dataSize = sizeof(msg_storage_change_type_t) + sizeof(msg_thread_id_t); + + *ppDest = (char*)new char[dataSize]; + + void* p = (void*)*ppDest; + + memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t)); + p = (void*)((char*)p + sizeof(msg_storage_change_type_t)); + + memcpy(p, &threadId, sizeof(msg_thread_id_t)); + + return dataSize; +} + + +int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest) +{ + int dataSize = 0; + int addr_len = 0; + + addr_len = strlen(pMsgInfo->addressList->addressVal); + + dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len; + + *ppDest = (char*)new char[dataSize]; + + void* p = (void*)*ppDest; + + memcpy(p, &msgReportType, sizeof(msg_report_type_t)); + p = (void*)((char*)p + sizeof(msg_report_type_t)); + + memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t)); + p = (void*)((char*)p + sizeof(msg_message_id_t)); + + memcpy(p, &addr_len, sizeof(int)); + p = (void*)((char*)p + sizeof(int)); + + memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len); + p = (void*)((char*)p + addr_len); + + return dataSize; +} + + int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest) { int dataSize = 0; @@ -369,7 +507,7 @@ int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, ch memcpy(p, &count, sizeof(int)); - p = (void*)((int)p + sizeof(int)); + p = (void*)((char*)p + sizeof(int)); memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count); @@ -411,8 +549,7 @@ int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest) } - -// Decoders +/* Decoders */ void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId) { memcpy(pMsgId, pSrc, sizeof(msg_message_id_t)); @@ -431,6 +568,23 @@ void MsgDecodeMemSize(char *pSrc, unsigned int *memsize) } +void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo) +{ + memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S)); + + pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S); + + pMsgInfo->addressList = NULL; + + pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt]; + memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt); + + for (int i = 0; i < pMsgInfo->nAddressCnt; i++) { + memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S)); + } +} + + void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo) { memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S)); @@ -438,8 +592,22 @@ void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_I pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S); memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S)); + + pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S); + + if(pMsgInfo->nAddressCnt > 0) { + pMsgInfo->addressList = NULL; + + pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt]; + memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt); + + for (int i = 0; i < pMsgInfo->nAddressCnt; i++) { + memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S)); + } + } } + void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList) { int count = 0; @@ -447,13 +615,12 @@ void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList) memcpy(&count, pSrc, sizeof(int)); pSrc = pSrc + sizeof(int); - pRecipientList->recipientCnt= count; + pRecipientList->recipientCnt = count; pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count]; MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr; - for (int i = 0; i < count; i++) - { + for (int i = 0; i < count; i++) { memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S)); pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S); pInfoTmp++; @@ -468,31 +635,30 @@ void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList) memcpy(&count, pSrc, sizeof(int)); pSrc = pSrc + sizeof(int); - if( count > 0 ) - { + if( count > 0 ) { pFolderList->nCount = count; - pFolderList->msg_struct_info = (msg_struct_t *)new char[sizeof(MSG_FOLDER_INFO_S *)*count]; - + pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t)); + if (pFolderList->msg_struct_info == NULL) { + pFolderList->nCount = 0; + return; + } msg_struct_s *pInfoTmp = NULL; - for (int i = 0; i < count; i++) - { - - pFolderList->msg_struct_info[i] = (msg_struct_t )new char[sizeof(msg_struct_s)]; + for (int i = 0; i < count; i++) { + pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s; pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i]; pInfoTmp->type = MSG_STRUCT_FOLDER_INFO; - pInfoTmp->data = new char[sizeof(MSG_FOLDER_INFO_S)]; + pInfoTmp->data = new MSG_FOLDER_INFO_S; memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S)); pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S); } - } - else if ( count == 0 ) - { + } else if ( count == 0 ) { pFolderList->nCount = count; pFolderList->msg_struct_info = NULL; } } + void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList) { int count = 0; @@ -500,29 +666,29 @@ void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList) memcpy(&count, pSrc, sizeof(int)); pSrc = pSrc + sizeof(int); - if( count > 0 ) - { + if( count > 0 ) { pFilterList->nCount = count; - pFilterList->msg_struct_info = (msg_struct_t *)new char[sizeof(MSG_FILTER_S *)*count]; + pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *)); + + if (pFilterList->msg_struct_info == NULL) { + pFilterList->nCount = 0; + return; + } msg_struct_s *pStructTmp = NULL; - for (int i = 0; i < count; i++) - { - pFilterList->msg_struct_info[i] = (msg_struct_t )new char[sizeof(msg_struct_s)]; + for (int i = 0; i < count; i++) { + pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s; pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i]; pStructTmp->type = MSG_STRUCT_FILTER; - pStructTmp->data = new char[sizeof(MSG_FILTER_S)]; + pStructTmp->data = new MSG_FILTER_S; memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S)); pSrc = pSrc + sizeof(MSG_FILTER_S); } - } - else if ( count == 0 ) - { + } else if ( count == 0 ) { pFilterList->nCount = count; pFilterList->msg_struct_info = NULL; } - } @@ -537,6 +703,7 @@ void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType) memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S)); } + void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList) { int count = 0; @@ -582,7 +749,6 @@ void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list) msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count]; for (int i = 0; i < count; i++) { - msg_struct_s *report_status_item = new msg_struct_s; report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO; report_status_item->data = new MSG_REPORT_STATUS_INFO_S; @@ -595,7 +761,7 @@ void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list) report_status[i] = (msg_struct_t)report_status_item; - MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d", + MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %ld", report_status_info->type, report_status_info->addressVal, report_status_info->status, report_status_info->statusTime); } @@ -614,11 +780,16 @@ void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo) memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S)); } -// Event Encoder +/* Event Encoder */ int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent) { MSG_EVENT_S* pMsgEvent = NULL; + if (*ppEvent) { + MSG_DEBUG("*ppEvent is not NULL."); + delete [] (char *)*ppEvent; + } + *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize]; pMsgEvent = (MSG_EVENT_S*)*ppEvent; @@ -669,7 +840,6 @@ int msg_verify_email(const char *raw) } for (int i = 0; raw[i]; i++) { - if (raw[i] == '@') { onlyNum = false; @@ -703,3 +873,539 @@ int msg_verify_email(const char *raw) return MSG_SUCCESS; } + + +char* msg_clean_country_code(char *src) +{ + int ret = 1; + + switch (src[ret++]-'0') { + case 1: + case 7: + break; + case 2: + switch (src[ret++]-'0') { + case 0: + case 7: + break; + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 8: + case 9: + ret += 1; + break; + default: + MSG_DEBUG("The parameter(src:%s) has invalid character set", src); + break; + } + break; + case 3: + switch (src[ret++]-'0') { + case 0: + case 1: + case 2: + case 3: + case 4: + case 6: + case 9: + break; + case 5: + case 7: + case 8: + ret += 1; + break; + default: + MSG_DEBUG("The parameter(src:%s) has invalid character set", src); + break; + } + break; + case 4: + switch (src[ret++]-'0') { + case 0: + case 1: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + break; + case 2: + ret += 1; + break; + default: + MSG_DEBUG("The parameter(src:%s) has invalid character set", src); + break; + } + break; + case 5: + switch (src[ret++]-'0') { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + break; + case 0: + case 9: + ret += 1; + break; + default: + MSG_DEBUG("The parameter(src:%s) has invalid character set", src); + break; + } + break; + case 6: + switch (src[ret++]-'0') { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + break; + case 7: + case 8: + case 9: + ret += 1; + break; + default: + MSG_DEBUG("The parameter(src:%s) has invalid character set", src); + break; + } + break; + case 8: + switch (src[ret++]-'0') { + case 1: + case 2: + case 4: + case 6: + break; + case 0: + case 3: + case 5: + case 7: + case 8: + case 9: + ret += 1; + break; + default: + MSG_DEBUG("The parameter(src:%s) has invalid character set", src); + break; + } + break; + case 9: + switch (src[ret++]-'0') { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 8: + break; + case 6: + case 7: + case 9: + ret += 1; + break; + default: + MSG_DEBUG("The parameter(src:%s) has invalid character set", src); + break; + } + break; + case 0: + default: + MSG_DEBUG("The parameter(src:%s) has invalid character set", src); + return src; + } + + return &src[ret]; +} + + +char* msg_normalize_number(char *src) +{ + char *normalized_number; + + if ('+' == src[0]) + normalized_number = msg_clean_country_code(src); + else if ('0' == src[0]) + normalized_number = src+1; + else + normalized_number = src; + + MSG_DEBUG("src = %s, normalized = %s", src, normalized_number); + + return normalized_number; +} + + +char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text) +{ + char *notiMsg = NULL; + char *lang = NULL; + + lang = vconf_get_str(VCONFKEY_LANGSET); + + setlocale(LC_MESSAGES, lang); + + bindtextdomain(pkg_name, locale_dir); + + notiMsg = dgettext(pkg_name, text); + + if (lang) { + free(lang); + lang = NULL; + } + + return g_strdup(notiMsg); +} + + +msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort) +{ + char sql[128]; + char order[6]; + + memset(sql, 0x00, sizeof(sql)); + memset(order, 0x00, sizeof(order)); + + if (pSortRule->bAscending == true) + strncpy(order, "ASC", 5); + else + strncpy(order, "DESC", 5); + + switch (pSortRule->sortType) { + case MSG_SORT_BY_DISPLAY_FROM : + snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order); + break; + case MSG_SORT_BY_DISPLAY_TO : + snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order); + break; + case MSG_SORT_BY_DISPLAY_TIME : + snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order); + break; + case MSG_SORT_BY_MSG_TYPE : + snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order); + break; + case MSG_SORT_BY_READ_STATUS : + snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order); + break; + case MSG_SORT_BY_STORAGE_TYPE : + snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order); + break; + case MSG_SORT_BY_THREAD_NAME : + snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order); + break; + case MSG_SORT_BY_THREAD_DATE : + snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order); + break; + case MSG_SORT_BY_THREAD_COUNT : + snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order); + break; + default : + snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order); + break; + } + + memcpy(pSqlSort, sql, strlen(sql)); + pSqlSort[strlen(sql)] = '\0'; + + return MSG_SUCCESS; +} +bool msg_is_valid_email(char *pAddress) +{ + if (!pAddress || pAddress[0] == 0) + return false; + if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT)) + return false; + return true; +} + +msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text) +{ + if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) { + pMsgInfo->bTextSms = false; + + /* Save Message Data into File */ + char fileName[MSG_FILENAME_LEN_MAX+1]; + memset(fileName, 0x00, sizeof(fileName)); + + if(MsgCreateFileName(fileName) == false) { + MSG_DEBUG("MsgCreateFileName error"); + return MSG_ERR_STORAGE_ERROR; + } + + MSG_SEC_DEBUG("Save text into file : size[%zu] name[%s]", pMsgInfo->dataSize, fileName); + + if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) { + MSG_DEBUG("MsgWriteIpcFile error"); + return MSG_ERR_STORAGE_ERROR; + } + + memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData)); + strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN); + } else { + pMsgInfo->bTextSms = true; + + memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText)); + memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize); + } + + return MSG_SUCCESS; +} + +/* change illegal filename character to '_' */ +void msg_replace_available_file_name(char *fileName) +{ + int idx = 0; + int len = 0; + bool is_converted = false; + + if (fileName) { + len = strlen(fileName); + + while (fileName[idx] != 0) { + if (idx >= len) { + MSG_WARN("idx : %d, len : %d", idx, len); + break; + } + + if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' || + fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') { + fileName[idx++] = '_'; + is_converted = true; + } else { + idx++; + } + } + } + + if (is_converted) + MSG_SEC_DEBUG("converted filename : [%s]", fileName); +} + +/* change character ' ' to '_' */ +void msg_replace_space_char(char *pszText) +{ + if (!pszText) { + MSG_ERR("pszText is NULL"); + return; + } + + char *spaceCharPtr = strchr(pszText, ' '); + + while (spaceCharPtr) { + *spaceCharPtr = '_'; + spaceCharPtr = strchr(pszText, ' '); + } +} + +/* change non-ascii character to underscore */ +gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar) +{ + if (!pszText) { + MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL"); + return NULL; + } + gchar *res; + gsize result_len = 0; + const gchar *p; + result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */ + res = (gchar *)g_malloc (result_len * sizeof (gchar)); + int i = 0; + for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) { + res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar; + } + res[i] = '\0'; + return res; +} + + +static int __find_login_user(uid_t *uid) +{ + uid_t *uids = NULL; + + int uids_len = sd_get_uids(&uids); + if (uids == NULL) + return -1; + + if (uids_len != 1) { + free(uids); + return -1; + } + + *uid = uids[0]; + + free(uids); + return 0; +} + + +uid_t msg_get_login_user() +{ + uid_t uid = -1; + + if (__find_login_user(&uid) < 0) { + MSG_WARN("Cannot find login user"); + } + + MSG_DEBUG("login user id [%d]", uid); + + return uid; +} + + +void* _msg_launch_app(void *data) +{ + pthread_mutex_lock(&mx); + if (data) { + msg_launch_app_data *ad = (msg_launch_app_data *)data; + int ret = aul_launch_app_for_uid(ad->app_id, ad->bundle_data, msg_get_login_user()); + if (ret <= 0) { + MSG_ERR("aul_launch_app_for_uid() is failed : %d", ret); + } + + g_free(ad->app_id); + bundle_free(ad->bundle_data); + g_free(ad); + } + pthread_mutex_unlock(&mx); + + return NULL; +} + +msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data) +{ + pthread_t thd; + pthread_attr_t attr; + + if (pthread_attr_init(&attr) < 0) { + MSG_ERR("pthread_attr_init() error"); + return MSG_ERR_UNKNOWN; + } + + if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) < 0) { + MSG_ERR("pthread_attr_setdetachstate() error"); + return MSG_ERR_UNKNOWN; + } + + msg_launch_app_data *data = (msg_launch_app_data *)calloc(1, sizeof(msg_launch_app_data)); + if (data == NULL) { + MSG_ERR("Memory alloc failed!"); + return MSG_ERR_MEMORY_ERROR; + } + + data->app_id = g_strdup(app_id); + data->bundle_data = bundle_dup(bundle_data); + + if (pthread_create(&thd, &attr, &_msg_launch_app, data) < 0) { + MSG_ERR("pthread_create() error"); + } + + if (pthread_attr_destroy(&attr) < 0) { + MSG_ERR("pthread_attr_destroy() error"); + } + + return MSG_SUCCESS; +} + + +msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation) +{ + int ret = aul_svc_set_operation(bundle_data, operation); + if (ret < 0) { + MSG_ERR("aul_svc_set_operation() is failed : %d", ret); + return MSG_ERR_UNKNOWN; + } + + return MSG_SUCCESS; +} + + +msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri) +{ + int ret = aul_svc_set_uri(bundle_data, uri); + if (ret < 0) { + MSG_ERR("aul_svc_set_uri() is failed : %d", ret); + return MSG_ERR_UNKNOWN; + } + + return MSG_SUCCESS; +} + + +void msg_set_dpm_policy(int type, int state) +{ + dpm_policy_enable[type] = state; +} + + +bool msg_check_dpm_policy(int type) +{ + return dpm_policy_enable[MSG_SMS_TYPE]; +// return dpm_policy_enable[type]; +} + + +void msg_syspopup_message(bool is_sending) +{ + MSG_INFO("popup toast for dpm restriction. is_sending [%d]", is_sending); + + GDBusConnection *connection = NULL; + GDBusProxy *dbus_proxy = NULL; + GVariant *result = NULL; + GError *error = NULL; + + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (error) { + MSG_ERR("Connecting to system bus failed: %s\n", error->message); + goto _DBUS_ERROR; + } + + dbus_proxy = g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, + SYSPOPUP_BUS_NAME, SYSPOPUP_OBJECT_PATH, SYSPOPUP_INTERFACE, NULL, &error); + if (error) { + MSG_ERR("Connecting to proxy failed: %s\n", error->message); + goto _DBUS_ERROR; + } + + result = g_dbus_proxy_call_sync(dbus_proxy, SYSPOPUP_METHOD_SHOW, + g_variant_new("(s)", is_sending ? "message-sending" : "message-retrieving"), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + MSG_ERR("invoking proxy call failed: %s\n", error->message); + goto _DBUS_ERROR; + } + +_DBUS_ERROR: + if (error) { + g_error_free(error); + error = NULL; + } + + if (connection) { + g_object_unref(connection); + connection = NULL; + } + + if (dbus_proxy) { + g_object_unref(dbus_proxy); + dbus_proxy = NULL; + } + + if (result) { + g_object_unref(result); + result = NULL; + } +}