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.
18 #include <systemd/sd-login.h>
21 #include "MsgContact.h"
22 #include "MsgGconfWrapper.h"
23 #include "MsgUtilFile.h"
24 #include "MsgUtilFunction.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 int _dbus_owner_id = 0;
53 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
54 static int phonenumberMinMatchDigit = -1;
57 /*==================================================================================================
58 FUNCTION IMPLEMENTATION
59 ==================================================================================================*/
61 bool MsgCheckFeatureSupport(const char *feature_name)
65 if (b_feature_cache_flag == false) {
66 if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_support[FEATURE_INDEX_SMS]) != SYSTEM_INFO_ERROR_NONE)
67 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE);
69 if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_support[FEATURE_INDEX_MMS]) != SYSTEM_INFO_ERROR_NONE)
70 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE);
72 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_support[FEATURE_INDEX_SMS]);
73 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_support[FEATURE_INDEX_MMS]);
75 b_feature_cache_flag = true;
78 if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) {
79 result = b_feature_support[FEATURE_INDEX_SMS];
80 } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
81 result = b_feature_support[FEATURE_INDEX_MMS];
88 int MsgContactGetMinMatchDigit()
90 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
91 if (phonenumberMinMatchDigit <= 0) {
92 if (MsgSettingGetInt(VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT, &phonenumberMinMatchDigit) != MSG_SUCCESS) {
93 MSG_INFO("MsgSettingGetInt() is failed");
95 MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
97 if (phonenumberMinMatchDigit < 1) {
98 phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
102 return phonenumberMinMatchDigit;
104 return DEFAULT_MIN_MATCH_DIGIT;
109 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
113 dataSize = sizeof(MSG_COUNT_INFO_S);
115 *ppDest = (char*)new char[dataSize];
117 void* p = (void*)*ppDest;
119 memcpy(p, pCountInfo, dataSize);
125 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
127 int count = 0, dataSize = 0;
129 count = pRecipientList->recipientCnt;
130 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
132 *ppDest = (char*)new char[dataSize];
134 void* p = (void*)*ppDest;
136 memcpy(p, &count, sizeof(int));
137 p = (void*)((char*)p + sizeof(int));
139 for (int i = 0; i < count; i++) {
140 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
141 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
148 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
152 dataSize = sizeof(int);
154 *ppDest = (char*)new char[dataSize];
156 void* p = (void*)*ppDest;
158 memcpy(p, &MsgCount, dataSize);
164 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
168 dataSize = (sizeof(msg_message_id_t));
170 *ppDest = (char*)new char[dataSize];
172 void* p = (void*)*ppDest;
174 memcpy(p, pMsgId, dataSize);
180 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
184 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
186 *ppDest = (char*)new char[dataSize];
188 void* p = (void*)*ppDest;
190 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
192 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
194 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
195 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
196 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
203 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
207 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
209 *ppDest = (char*)new char[dataSize];
211 void* p = (void*)*ppDest;
213 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
215 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
217 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
219 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
221 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
222 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
223 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
230 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
232 int count = 0, dataSize = 0;
234 count = pFolderList->nCount;
235 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
237 *ppDest = (char*)new char[dataSize];
239 void* p = (void*)*ppDest;
241 memcpy(p, &count, sizeof(int));
242 p = (void*)((char*)p + sizeof(int));
244 msg_struct_s *folder_info = NULL;
246 for (int i = 0; i < count; i++) {
247 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
248 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
249 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
256 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
258 int count = 0, dataSize = 0;
260 count = pFilterList->nCount;
261 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
263 *ppDest = (char*)new char[dataSize];
265 void* p = (void*)*ppDest;
267 memcpy(p, &count, sizeof(int));
268 p = (void*)((char*)p + sizeof(int));
270 msg_struct_s *filter_info = NULL;
272 for (int i = 0; i < count; i++) {
273 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
274 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
275 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
282 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
286 dataSize = (sizeof(bool));
288 *ppDest = (char*)new char[dataSize];
290 void* p = (void*)*ppDest;
292 memcpy(p, pSetFlag, dataSize);
298 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
300 int count = 0, dataSize = 0;
302 count = pThreadViewList->nCount;
304 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
306 *ppDest = (char*)new char[dataSize];
308 void* p = (void*)*ppDest;
310 memcpy(p, &count, sizeof(int));
311 p = (void*)((char*)p + sizeof(int));
313 msg_struct_s *thread_info = NULL;
315 for (int i = 0; i < count; i++) {
316 thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
317 memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
318 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
325 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
327 int count = 0, dataSize = 0;
329 count = pConvViewList->nCount;
331 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
333 *ppDest = (char*)new char[dataSize];
335 void* p = (void*)*ppDest;
337 memcpy(p, &count, sizeof(int));
338 p = (void*)((char*)p + sizeof(int));
340 for (int i = 0; i < count; i++) {
341 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
342 p = (void*)((char*)p + sizeof(msg_struct_list_s));
349 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
351 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
353 MSG_DEBUG("datasize = [%d] \n", dataSize);
355 *ppDest = (char*)new char[dataSize];
357 void* p = (void*)*ppDest;
359 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
360 p = (void*)((char*)p + sizeof(int));
362 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
363 p = (void*)((char*)p + sizeof(int));
365 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
366 p = (void*)((char*)p + sizeof(int));
368 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
369 p = (void*)((char*)p + sizeof(int));
374 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
378 dataSize = sizeof(unsigned int);
380 *ppDest = (char*)new char[dataSize];
382 void* p = (void*)*ppDest;
384 memcpy(p, memsize, dataSize);
390 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
394 dataSize = sizeof(int) + sizeof(int);
396 *ppDest = (char*)new char[dataSize];
398 void* p = (void*)*ppDest;
400 memcpy(p, &msgId, sizeof(int));
401 p = (void*)((char*)p + sizeof(int));
403 memcpy(p, &extId, sizeof(int));
409 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
414 count = pMsgIdList->nCount;
416 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
418 *ppDest = (char*)new char[dataSize];
420 void* p = (void*)*ppDest;
422 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
423 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
425 memcpy(p, &count, sizeof(int));
426 p = (void*)((char*)p + sizeof(int));
428 for (int i = 0; i < count; i++) {
429 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
430 p = (void*)((char*)p + sizeof(msg_message_id_t));
437 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
442 addr_len = strlen(pMsgInfo->addressList->addressVal);
444 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
446 *ppDest = (char*)new char[dataSize];
448 void* p = (void*)*ppDest;
450 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
451 p = (void*)((char*)p + sizeof(msg_report_type_t));
453 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
454 p = (void*)((char*)p + sizeof(msg_message_id_t));
456 memcpy(p, &addr_len, sizeof(int));
457 p = (void*)((char*)p + sizeof(int));
459 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
460 p = (void*)((char*)p + addr_len);
466 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
470 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
472 *ppDest = (char*)new char[dataSize];
474 void* p = (void*)*ppDest;
476 memcpy(p, &count, sizeof(int));
478 p = (void*)((char*)p + sizeof(int));
480 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
486 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
490 dataSize = (sizeof(msg_thread_id_t));
492 *ppDest = (char*)new char[dataSize];
494 void* p = (void*)*ppDest;
496 memcpy(p, pThreadId, dataSize);
502 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
506 dataSize = sizeof(MSG_THREAD_VIEW_S);
508 *ppDest = (char*)new char[dataSize];
510 void* p = (void*)*ppDest;
512 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
514 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
521 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
523 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
527 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
529 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
533 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
535 memcpy(memsize, pSrc, sizeof(unsigned int));
539 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
541 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
543 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
545 pMsgInfo->addressList = NULL;
547 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
548 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
550 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
551 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
556 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
558 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
560 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
562 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
564 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
566 if(pMsgInfo->nAddressCnt > 0) {
567 pMsgInfo->addressList = NULL;
569 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
570 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
572 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
573 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
579 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
583 memcpy(&count, pSrc, sizeof(int));
584 pSrc = pSrc + sizeof(int);
586 pRecipientList->recipientCnt = count;
587 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
589 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
591 for (int i = 0; i < count; i++) {
592 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
593 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
599 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
603 memcpy(&count, pSrc, sizeof(int));
604 pSrc = pSrc + sizeof(int);
607 pFolderList->nCount = count;
608 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
609 if (pFolderList->msg_struct_info == NULL) {
610 pFolderList->nCount = 0;
613 msg_struct_s *pInfoTmp = NULL;
615 for (int i = 0; i < count; i++) {
616 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
617 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
618 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
619 pInfoTmp->data = new MSG_FOLDER_INFO_S;
620 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
621 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
623 } else if ( count == 0 ) {
624 pFolderList->nCount = count;
625 pFolderList->msg_struct_info = NULL;
630 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
634 memcpy(&count, pSrc, sizeof(int));
635 pSrc = pSrc + sizeof(int);
638 pFilterList->nCount = count;
639 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
641 if (pFilterList->msg_struct_info == NULL) {
642 pFilterList->nCount = 0;
646 msg_struct_s *pStructTmp = NULL;
648 for (int i = 0; i < count; i++) {
649 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
650 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
651 pStructTmp->type = MSG_STRUCT_FILTER;
652 pStructTmp->data = new MSG_FILTER_S;
653 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
654 pSrc = pSrc + sizeof(MSG_FILTER_S);
656 } else if ( count == 0 ) {
657 pFilterList->nCount = count;
658 pFilterList->msg_struct_info = NULL;
663 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
665 memcpy(pSetFlag, pSrc, sizeof(bool));
669 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
671 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
675 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
682 memcpy(&count, pSrc, sizeof(int));
683 pSrc = pSrc + sizeof(int);
684 pMsgThreadCountList->totalCount = count;
687 memcpy(&count, pSrc, sizeof(int));
688 pSrc = pSrc + sizeof(int);
689 pMsgThreadCountList->unReadCount = count;
692 memcpy(&count, pSrc, sizeof(int));
693 pSrc = pSrc + sizeof(int);
694 pMsgThreadCountList->mmsMsgCount = count;
697 memcpy(&count, pSrc, sizeof(int));
698 pSrc = pSrc + sizeof(int);
699 pMsgThreadCountList->smsMsgCount = count;
706 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
713 memcpy(&count, pSrc, sizeof(int));
714 pSrc = pSrc + sizeof(int);
716 report_list->nCount = count;
718 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
719 for (int i = 0; i < count; i++) {
720 msg_struct_s *report_status_item = new msg_struct_s;
721 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
722 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
723 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
725 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
726 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
728 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
730 report_status[i] = (msg_struct_t)report_status_item;
732 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
733 report_status_info->type, report_status_info->addressVal,
734 report_status_info->status, report_status_info->statusTime);
737 report_list->msg_struct_info = report_status;
741 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
743 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
746 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
748 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
752 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
754 MSG_EVENT_S* pMsgEvent = NULL;
757 MSG_DEBUG("*ppEvent is not NULL.");
758 delete [] (char *)*ppEvent;
761 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
763 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
765 pMsgEvent->eventType = MsgEvent;
766 pMsgEvent->result = MsgError;
768 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
769 MSG_DEBUG("result [%d]", pMsgEvent->result);
772 memcpy((void*)pMsgEvent->data, pData, DataSize);
774 return (sizeof(MSG_EVENT_S) + DataSize);
777 int msg_verify_number(const char *raw, char *trimmed)
779 if (!(raw && trimmed)) {
780 MSG_DEBUG("Phone Number is NULL");
781 return MSG_ERR_NULL_POINTER;
784 for (int i=0, j=0 ; raw[i] ; i++) {
785 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
786 || raw[i] == '*' || raw[i] == '#') {
787 trimmed[j++] = raw[i];
788 } else if (raw[i] == '-') {
791 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
792 return MSG_ERR_INVALID_PARAMETER;
796 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
800 int msg_verify_email(const char *raw)
803 bool atExist = false;
806 MSG_DEBUG("Email is NULL");
807 return MSG_ERR_NULL_POINTER;
810 for (int i = 0; raw[i]; i++) {
814 if (atExist == false) {
818 MSG_DEBUG("Character [@] is included more than twice in email address.");
819 return MSG_ERR_INVALID_PARAMETER;
823 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
825 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
828 } else if (raw[i] == ',') {
829 if (onlyNum == false && atExist == false) {
830 MSG_DEBUG("Unacceptable type in address.");
831 return MSG_ERR_INVALID_PARAMETER;
837 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
838 return MSG_ERR_INVALID_PARAMETER;
846 char* msg_clean_country_code(char *src)
850 switch (src[ret++]-'0') {
855 switch (src[ret++]-'0') {
870 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
875 switch (src[ret++]-'0') {
890 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
895 switch (src[ret++]-'0') {
910 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
915 switch (src[ret++]-'0') {
930 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
935 switch (src[ret++]-'0') {
950 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
955 switch (src[ret++]-'0') {
970 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
975 switch (src[ret++]-'0') {
990 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
996 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1004 char* msg_normalize_number(char *src)
1006 char *normalized_number;
1009 normalized_number = msg_clean_country_code(src);
1010 else if ('0' == src[0])
1011 normalized_number = src+1;
1013 normalized_number = src;
1015 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1017 return normalized_number;
1021 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
1023 char *notiMsg = NULL;
1026 lang = vconf_get_str(VCONFKEY_LANGSET);
1028 setlocale(LC_MESSAGES, lang);
1030 bindtextdomain(pkg_name, locale_dir);
1032 notiMsg = dgettext(pkg_name, text);
1039 return g_strdup(notiMsg);
1043 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1048 memset(sql, 0x00, sizeof(sql));
1049 memset(order, 0x00, sizeof(order));
1051 if (pSortRule->bAscending == true)
1052 strncpy(order, "ASC", 5);
1054 strncpy(order, "DESC", 5);
1056 switch (pSortRule->sortType) {
1057 case MSG_SORT_BY_DISPLAY_FROM :
1058 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1060 case MSG_SORT_BY_DISPLAY_TO :
1061 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1063 case MSG_SORT_BY_DISPLAY_TIME :
1064 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1066 case MSG_SORT_BY_MSG_TYPE :
1067 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1069 case MSG_SORT_BY_READ_STATUS :
1070 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1072 case MSG_SORT_BY_STORAGE_TYPE :
1073 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1075 case MSG_SORT_BY_THREAD_NAME :
1076 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1078 case MSG_SORT_BY_THREAD_DATE :
1079 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1081 case MSG_SORT_BY_THREAD_COUNT :
1082 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1085 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1089 memcpy(pSqlSort, sql, strlen(sql));
1093 bool msg_is_valid_email(char *pAddress)
1095 if (!pAddress || pAddress[0] == 0)
1097 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1102 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1104 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1105 pMsgInfo->bTextSms = false;
1107 /* Save Message Data into File */
1108 char fileName[MSG_FILENAME_LEN_MAX+1];
1109 memset(fileName, 0x00, sizeof(fileName));
1111 if(MsgCreateFileName(fileName) == false) {
1112 MSG_DEBUG("MsgCreateFileName error");
1113 return MSG_ERR_STORAGE_ERROR;
1116 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1118 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1119 MSG_DEBUG("MsgWriteIpcFile error");
1120 return MSG_ERR_STORAGE_ERROR;
1123 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1124 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1126 pMsgInfo->bTextSms = true;
1128 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1129 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1135 /* change illegal filename character to '_' */
1136 void msg_replace_available_file_name(char *fileName)
1140 bool is_converted = false;
1143 len = strlen(fileName);
1145 while (fileName[idx] != 0) {
1147 MSG_WARN("idx : %d, len : %d", idx, len);
1151 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1152 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1153 fileName[idx++] = '_';
1154 is_converted = true;
1162 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1165 /* change character ' ' to '_' */
1166 void msg_replace_space_char(char *pszText)
1169 MSG_ERR("pszText is NULL");
1173 char *spaceCharPtr = strchr(pszText, ' ');
1175 while (spaceCharPtr) {
1176 *spaceCharPtr = '_';
1177 spaceCharPtr = strchr(pszText, ' ');
1181 /* change non-ascii character to underscore */
1182 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1185 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1189 gsize result_len = 0;
1191 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1192 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1194 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1195 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1202 static int __find_login_user(uid_t *uid)
1207 int uids_len = sd_get_uids(&uids);
1211 for (int i = 0; i < uids_len; i++) {
1212 if (sd_uid_get_state(uids[i], &state) < 0) {
1216 if (g_strcmp0(state, "online") == 0) {
1232 uid_t msg_get_login_user()
1236 if (__find_login_user(&uid) < 0) {
1237 MSG_WARN("Cannot find login user");
1240 MSG_DEBUG("login user id [%d]", uid);
1246 void* _msg_launch_app(void *data)
1249 msg_launch_app_data *ad = (msg_launch_app_data *)data;
1250 int ret = aul_launch_app_for_uid(ad->app_id, ad->bundle_data, msg_get_login_user());
1252 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
1256 bundle_free(ad->bundle_data);
1263 msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
1265 msg_launch_app_data *data = (msg_launch_app_data *)calloc(1, sizeof(msg_launch_app_data));
1266 data->app_id = g_strdup(app_id);
1267 data->bundle_data = bundle_dup(bundle_data);
1270 if (pthread_create(&thd, NULL, &_msg_launch_app, data) < 0) {
1271 MSG_DEBUG("pthread_create() error");
1274 pthread_detach(thd);
1279 msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation)
1281 int ret = aul_svc_set_operation(bundle_data, operation);
1283 MSG_DEBUG("aul_svc_set_operation() is failed : %d", ret);
1284 return MSG_ERR_UNKNOWN;
1291 msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
1293 int ret = aul_svc_set_uri(bundle_data, uri);
1295 MSG_DEBUG("aul_svc_set_uri() is failed : %d", ret);
1296 return MSG_ERR_UNKNOWN;
1307 _dbus_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
1308 "msg-service.dbus.service",
1309 G_BUS_NAME_OWNER_FLAGS_NONE,
1313 if (_dbus_owner_id == 0) {
1314 MSG_ERR("g_bus_own_name() error");
1317 MSG_DEBUG("owner_id = [%d]", _dbus_owner_id);
1320 void MsgDbusDeinit()
1324 g_bus_unown_name(_dbus_owner_id);