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>
35 #define DEFAULT_MIN_MATCH_DIGIT 8
37 enum _FEATURE_INDEX_E {
38 FEATURE_INDEX_SMS = 0,
39 FEATURE_INDEX_MMS = 1,
42 static bool b_feature_cache_flag = false;
43 static bool b_feature_support[] = {
44 [FEATURE_INDEX_SMS] = false,
45 [FEATURE_INDEX_MMS] = false,
48 int _dbus_owner_id = 0;
49 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
50 static int phonenumberMinMatchDigit = -1;
53 /*==================================================================================================
54 FUNCTION IMPLEMENTATION
55 ==================================================================================================*/
57 bool MsgCheckFeatureSupport(const char *feature_name)
61 if (b_feature_cache_flag == false) {
62 if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_support[FEATURE_INDEX_SMS]) != SYSTEM_INFO_ERROR_NONE)
63 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE);
65 if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_support[FEATURE_INDEX_MMS]) != SYSTEM_INFO_ERROR_NONE)
66 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE);
68 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_support[FEATURE_INDEX_SMS]);
69 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_support[FEATURE_INDEX_MMS]);
71 b_feature_cache_flag = true;
74 if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) {
75 result = b_feature_support[FEATURE_INDEX_SMS];
76 } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
77 result = b_feature_support[FEATURE_INDEX_MMS];
84 int MsgContactGetMinMatchDigit()
86 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
87 if (phonenumberMinMatchDigit <= 0) {
88 if (MsgSettingGetInt(VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT, &phonenumberMinMatchDigit) != MSG_SUCCESS) {
89 MSG_INFO("MsgSettingGetInt() is failed");
91 MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
93 if (phonenumberMinMatchDigit < 1) {
94 phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
98 return phonenumberMinMatchDigit;
100 return DEFAULT_MIN_MATCH_DIGIT;
105 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
109 dataSize = sizeof(MSG_COUNT_INFO_S);
111 *ppDest = (char*)new char[dataSize];
113 void* p = (void*)*ppDest;
115 memcpy(p, pCountInfo, dataSize);
121 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
123 int count = 0, dataSize = 0;
125 count = pRecipientList->recipientCnt;
126 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
128 *ppDest = (char*)new char[dataSize];
130 void* p = (void*)*ppDest;
132 memcpy(p, &count, sizeof(int));
133 p = (void*)((char*)p + sizeof(int));
135 for (int i = 0; i < count; i++) {
136 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
137 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
144 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
148 dataSize = sizeof(int);
150 *ppDest = (char*)new char[dataSize];
152 void* p = (void*)*ppDest;
154 memcpy(p, &MsgCount, dataSize);
160 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
164 dataSize = (sizeof(msg_message_id_t));
166 *ppDest = (char*)new char[dataSize];
168 void* p = (void*)*ppDest;
170 memcpy(p, pMsgId, dataSize);
176 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
180 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
182 *ppDest = (char*)new char[dataSize];
184 void* p = (void*)*ppDest;
186 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
188 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
190 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
191 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
192 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
199 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
203 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
205 *ppDest = (char*)new char[dataSize];
207 void* p = (void*)*ppDest;
209 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
211 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
213 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
215 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
217 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
218 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
219 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
226 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
228 int count = 0, dataSize = 0;
230 count = pFolderList->nCount;
231 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
233 *ppDest = (char*)new char[dataSize];
235 void* p = (void*)*ppDest;
237 memcpy(p, &count, sizeof(int));
238 p = (void*)((char*)p + sizeof(int));
240 msg_struct_s *folder_info = NULL;
242 for (int i = 0; i < count; i++) {
243 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
244 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
245 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
252 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
254 int count = 0, dataSize = 0;
256 count = pFilterList->nCount;
257 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
259 *ppDest = (char*)new char[dataSize];
261 void* p = (void*)*ppDest;
263 memcpy(p, &count, sizeof(int));
264 p = (void*)((char*)p + sizeof(int));
266 msg_struct_s *filter_info = NULL;
268 for (int i = 0; i < count; i++) {
269 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
270 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
271 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
278 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
282 dataSize = (sizeof(bool));
284 *ppDest = (char*)new char[dataSize];
286 void* p = (void*)*ppDest;
288 memcpy(p, pSetFlag, dataSize);
294 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
296 int count = 0, dataSize = 0;
298 count = pThreadViewList->nCount;
300 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
302 *ppDest = (char*)new char[dataSize];
304 void* p = (void*)*ppDest;
306 memcpy(p, &count, sizeof(int));
307 p = (void*)((char*)p + sizeof(int));
309 msg_struct_s *thread_info = NULL;
311 for (int i = 0; i < count; i++) {
312 thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
313 memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
314 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
321 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
323 int count = 0, dataSize = 0;
325 count = pConvViewList->nCount;
327 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
329 *ppDest = (char*)new char[dataSize];
331 void* p = (void*)*ppDest;
333 memcpy(p, &count, sizeof(int));
334 p = (void*)((char*)p + sizeof(int));
336 for (int i = 0; i < count; i++) {
337 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
338 p = (void*)((char*)p + sizeof(msg_struct_list_s));
345 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
347 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
349 MSG_DEBUG("datasize = [%d] \n", dataSize);
351 *ppDest = (char*)new char[dataSize];
353 void* p = (void*)*ppDest;
355 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
356 p = (void*)((char*)p + sizeof(int));
358 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
359 p = (void*)((char*)p + sizeof(int));
361 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
362 p = (void*)((char*)p + sizeof(int));
364 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
365 p = (void*)((char*)p + sizeof(int));
370 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
374 dataSize = sizeof(unsigned int);
376 *ppDest = (char*)new char[dataSize];
378 void* p = (void*)*ppDest;
380 memcpy(p, memsize, dataSize);
386 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
390 dataSize = sizeof(int) + sizeof(int);
392 *ppDest = (char*)new char[dataSize];
394 void* p = (void*)*ppDest;
396 memcpy(p, &msgId, sizeof(int));
397 p = (void*)((char*)p + sizeof(int));
399 memcpy(p, &extId, sizeof(int));
405 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
410 count = pMsgIdList->nCount;
412 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
414 *ppDest = (char*)new char[dataSize];
416 void* p = (void*)*ppDest;
418 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
419 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
421 memcpy(p, &count, sizeof(int));
422 p = (void*)((char*)p + sizeof(int));
424 for (int i = 0; i < count; i++) {
425 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
426 p = (void*)((char*)p + sizeof(msg_message_id_t));
433 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
438 addr_len = strlen(pMsgInfo->addressList->addressVal);
440 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
442 *ppDest = (char*)new char[dataSize];
444 void* p = (void*)*ppDest;
446 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
447 p = (void*)((char*)p + sizeof(msg_report_type_t));
449 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
450 p = (void*)((char*)p + sizeof(msg_message_id_t));
452 memcpy(p, &addr_len, sizeof(int));
453 p = (void*)((char*)p + sizeof(int));
455 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
456 p = (void*)((char*)p + addr_len);
462 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
466 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
468 *ppDest = (char*)new char[dataSize];
470 void* p = (void*)*ppDest;
472 memcpy(p, &count, sizeof(int));
474 p = (void*)((char*)p + sizeof(int));
476 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
482 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
486 dataSize = (sizeof(msg_thread_id_t));
488 *ppDest = (char*)new char[dataSize];
490 void* p = (void*)*ppDest;
492 memcpy(p, pThreadId, dataSize);
498 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
502 dataSize = sizeof(MSG_THREAD_VIEW_S);
504 *ppDest = (char*)new char[dataSize];
506 void* p = (void*)*ppDest;
508 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
510 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
517 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
519 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
523 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
525 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
529 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
531 memcpy(memsize, pSrc, sizeof(unsigned int));
535 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
537 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
539 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
541 pMsgInfo->addressList = NULL;
543 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
544 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
546 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
547 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
552 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
554 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
556 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
558 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
560 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
562 if(pMsgInfo->nAddressCnt > 0) {
563 pMsgInfo->addressList = NULL;
565 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
566 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
568 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
569 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
575 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
579 memcpy(&count, pSrc, sizeof(int));
580 pSrc = pSrc + sizeof(int);
582 pRecipientList->recipientCnt = count;
583 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
585 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
587 for (int i = 0; i < count; i++) {
588 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
589 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
595 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
599 memcpy(&count, pSrc, sizeof(int));
600 pSrc = pSrc + sizeof(int);
603 pFolderList->nCount = count;
604 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
605 if (pFolderList->msg_struct_info == NULL) {
606 pFolderList->nCount = 0;
609 msg_struct_s *pInfoTmp = NULL;
611 for (int i = 0; i < count; i++) {
612 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
613 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
614 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
615 pInfoTmp->data = new MSG_FOLDER_INFO_S;
616 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
617 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
619 } else if ( count == 0 ) {
620 pFolderList->nCount = count;
621 pFolderList->msg_struct_info = NULL;
626 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
630 memcpy(&count, pSrc, sizeof(int));
631 pSrc = pSrc + sizeof(int);
634 pFilterList->nCount = count;
635 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
637 if (pFilterList->msg_struct_info == NULL) {
638 pFilterList->nCount = 0;
642 msg_struct_s *pStructTmp = NULL;
644 for (int i = 0; i < count; i++) {
645 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
646 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
647 pStructTmp->type = MSG_STRUCT_FILTER;
648 pStructTmp->data = new MSG_FILTER_S;
649 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
650 pSrc = pSrc + sizeof(MSG_FILTER_S);
652 } else if ( count == 0 ) {
653 pFilterList->nCount = count;
654 pFilterList->msg_struct_info = NULL;
659 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
661 memcpy(pSetFlag, pSrc, sizeof(bool));
665 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
667 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
671 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
678 memcpy(&count, pSrc, sizeof(int));
679 pSrc = pSrc + sizeof(int);
680 pMsgThreadCountList->totalCount = count;
683 memcpy(&count, pSrc, sizeof(int));
684 pSrc = pSrc + sizeof(int);
685 pMsgThreadCountList->unReadCount = count;
688 memcpy(&count, pSrc, sizeof(int));
689 pSrc = pSrc + sizeof(int);
690 pMsgThreadCountList->mmsMsgCount = count;
693 memcpy(&count, pSrc, sizeof(int));
694 pSrc = pSrc + sizeof(int);
695 pMsgThreadCountList->smsMsgCount = count;
702 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
709 memcpy(&count, pSrc, sizeof(int));
710 pSrc = pSrc + sizeof(int);
712 report_list->nCount = count;
714 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
715 for (int i = 0; i < count; i++) {
716 msg_struct_s *report_status_item = new msg_struct_s;
717 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
718 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
719 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
721 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
722 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
724 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
726 report_status[i] = (msg_struct_t)report_status_item;
728 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
729 report_status_info->type, report_status_info->addressVal,
730 report_status_info->status, report_status_info->statusTime);
733 report_list->msg_struct_info = report_status;
737 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
739 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
742 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
744 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
748 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
750 MSG_EVENT_S* pMsgEvent = NULL;
753 MSG_DEBUG("*ppEvent is not NULL.");
754 delete [] (char *)*ppEvent;
757 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
759 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
761 pMsgEvent->eventType = MsgEvent;
762 pMsgEvent->result = MsgError;
764 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
765 MSG_DEBUG("result [%d]", pMsgEvent->result);
768 memcpy((void*)pMsgEvent->data, pData, DataSize);
770 return (sizeof(MSG_EVENT_S) + DataSize);
773 int msg_verify_number(const char *raw, char *trimmed)
775 if (!(raw && trimmed)) {
776 MSG_DEBUG("Phone Number is NULL");
777 return MSG_ERR_NULL_POINTER;
780 for (int i=0, j=0 ; raw[i] ; i++) {
781 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
782 || raw[i] == '*' || raw[i] == '#') {
783 trimmed[j++] = raw[i];
784 } else if (raw[i] == '-') {
787 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
788 return MSG_ERR_INVALID_PARAMETER;
792 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
796 int msg_verify_email(const char *raw)
799 bool atExist = false;
802 MSG_DEBUG("Email is NULL");
803 return MSG_ERR_NULL_POINTER;
806 for (int i = 0; raw[i]; i++) {
810 if (atExist == false) {
814 MSG_DEBUG("Character [@] is included more than twice in email address.");
815 return MSG_ERR_INVALID_PARAMETER;
819 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
821 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
824 } else if (raw[i] == ',') {
825 if (onlyNum == false && atExist == false) {
826 MSG_DEBUG("Unacceptable type in address.");
827 return MSG_ERR_INVALID_PARAMETER;
833 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
834 return MSG_ERR_INVALID_PARAMETER;
842 char* msg_clean_country_code(char *src)
846 switch (src[ret++]-'0') {
851 switch (src[ret++]-'0') {
866 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
871 switch (src[ret++]-'0') {
886 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
891 switch (src[ret++]-'0') {
906 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
911 switch (src[ret++]-'0') {
926 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
931 switch (src[ret++]-'0') {
946 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
951 switch (src[ret++]-'0') {
966 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
971 switch (src[ret++]-'0') {
986 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
992 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
1000 char* msg_normalize_number(char *src)
1002 char *normalized_number;
1005 normalized_number = msg_clean_country_code(src);
1006 else if ('0' == src[0])
1007 normalized_number = src+1;
1009 normalized_number = src;
1011 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1013 return normalized_number;
1017 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
1019 char *notiMsg = NULL;
1022 lang = vconf_get_str(VCONFKEY_LANGSET);
1024 setlocale(LC_MESSAGES, lang);
1026 bindtextdomain(pkg_name, locale_dir);
1028 notiMsg = dgettext(pkg_name, text);
1035 return g_strdup(notiMsg);
1039 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1044 memset(sql, 0x00, sizeof(sql));
1045 memset(order, 0x00, sizeof(order));
1047 if (pSortRule->bAscending == true)
1048 strncpy(order, "ASC", 5);
1050 strncpy(order, "DESC", 5);
1052 switch (pSortRule->sortType) {
1053 case MSG_SORT_BY_DISPLAY_FROM :
1054 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1056 case MSG_SORT_BY_DISPLAY_TO :
1057 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1059 case MSG_SORT_BY_DISPLAY_TIME :
1060 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1062 case MSG_SORT_BY_MSG_TYPE :
1063 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1065 case MSG_SORT_BY_READ_STATUS :
1066 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1068 case MSG_SORT_BY_STORAGE_TYPE :
1069 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1071 case MSG_SORT_BY_THREAD_NAME :
1072 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1074 case MSG_SORT_BY_THREAD_DATE :
1075 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1077 case MSG_SORT_BY_THREAD_COUNT :
1078 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1081 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1085 memcpy(pSqlSort, sql, strlen(sql));
1089 bool msg_is_valid_email(char *pAddress)
1091 if (!pAddress || pAddress[0] == 0)
1093 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1098 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1100 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1101 pMsgInfo->bTextSms = false;
1103 /* Save Message Data into File */
1104 char fileName[MSG_FILENAME_LEN_MAX+1];
1105 memset(fileName, 0x00, sizeof(fileName));
1107 if(MsgCreateFileName(fileName) == false) {
1108 MSG_DEBUG("MsgCreateFileName error");
1109 return MSG_ERR_STORAGE_ERROR;
1112 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1114 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1115 MSG_DEBUG("MsgWriteIpcFile error");
1116 return MSG_ERR_STORAGE_ERROR;
1119 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1120 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1122 pMsgInfo->bTextSms = true;
1124 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1125 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1131 /* change illegal filename character to '_' */
1132 void msg_replace_available_file_name(char *fileName)
1136 bool is_converted = false;
1139 len = strlen(fileName);
1141 while (fileName[idx] != 0) {
1143 MSG_WARN("idx : %d, len : %d", idx, len);
1147 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1148 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1149 fileName[idx++] = '_';
1150 is_converted = true;
1158 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1161 /* change character ' ' to '_' */
1162 void msg_replace_space_char(char *pszText)
1165 MSG_ERR("pszText is NULL");
1169 char *spaceCharPtr = strchr(pszText, ' ');
1171 while (spaceCharPtr) {
1172 *spaceCharPtr = '_';
1173 spaceCharPtr = strchr(pszText, ' ');
1177 /* change non-ascii character to underscore */
1178 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1181 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1185 gsize result_len = 0;
1187 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1188 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1190 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1191 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1198 static int __find_login_user(uid_t *uid)
1203 int uids_len = sd_get_uids(&uids);
1207 for (int i = 0; i < uids_len; i++) {
1208 if (sd_uid_get_state(uids[i], &state) < 0) {
1212 if (g_strcmp0(state, "online") == 0) {
1228 uid_t msg_get_login_user()
1232 if (__find_login_user(&uid) < 0) {
1233 MSG_WARN("Cannot find login user");
1236 MSG_DEBUG("login user id [%d]", uid);
1242 msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
1244 int ret = aul_launch_app_for_uid(app_id, bundle_data, msg_get_login_user());
1246 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
1247 return MSG_ERR_UNKNOWN;
1254 msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation)
1256 int ret = aul_svc_set_operation(bundle_data, operation);
1258 MSG_DEBUG("aul_svc_set_operation() is failed : %d", ret);
1259 return MSG_ERR_UNKNOWN;
1266 msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
1268 int ret = aul_svc_set_uri(bundle_data, uri);
1270 MSG_DEBUG("aul_svc_set_uri() is failed : %d", ret);
1271 return MSG_ERR_UNKNOWN;
1282 _dbus_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
1283 "msg-service.dbus.service",
1284 G_BUS_NAME_OWNER_FLAGS_NONE,
1288 if (_dbus_owner_id == 0) {
1289 MSG_ERR("g_bus_own_name() error");
1292 MSG_DEBUG("owner_id = [%d]", _dbus_owner_id);
1295 void MsgDbusDeinit()
1299 g_bus_unown_name(_dbus_owner_id);