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 #define DEFAULT_MIN_MATCH_DIGIT 8
36 enum _FEATURE_INDEX_E {
37 FEATURE_INDEX_SMS = 0,
38 FEATURE_INDEX_MMS = 1,
41 static bool b_feature_cache_flag = false;
42 static bool b_feature_support[] = {
43 [FEATURE_INDEX_SMS] = false,
44 [FEATURE_INDEX_MMS] = false,
47 int _dbus_owner_id = 0;
48 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
49 static int phonenumberMinMatchDigit = -1;
52 /*==================================================================================================
53 FUNCTION IMPLEMENTATION
54 ==================================================================================================*/
56 bool MsgCheckFeatureSupport(const char *feature_name)
60 if (b_feature_cache_flag == false) {
61 if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_support[FEATURE_INDEX_SMS]) != SYSTEM_INFO_ERROR_NONE)
62 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE);
64 if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_support[FEATURE_INDEX_MMS]) != SYSTEM_INFO_ERROR_NONE)
65 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE);
67 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_support[FEATURE_INDEX_SMS]);
68 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_support[FEATURE_INDEX_MMS]);
70 b_feature_cache_flag = true;
73 if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) {
74 result = b_feature_support[FEATURE_INDEX_SMS];
75 } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
76 result = b_feature_support[FEATURE_INDEX_MMS];
83 int MsgContactGetMinMatchDigit()
85 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
86 if (phonenumberMinMatchDigit <= 0) {
87 if (MsgSettingGetInt(VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT, &phonenumberMinMatchDigit) != MSG_SUCCESS) {
88 MSG_INFO("MsgSettingGetInt() is failed");
90 MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
92 if (phonenumberMinMatchDigit < 1) {
93 phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
97 return phonenumberMinMatchDigit;
99 return DEFAULT_MIN_MATCH_DIGIT;
104 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
108 dataSize = sizeof(MSG_COUNT_INFO_S);
110 *ppDest = (char*)new char[dataSize];
112 void* p = (void*)*ppDest;
114 memcpy(p, pCountInfo, dataSize);
120 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
122 int count = 0, dataSize = 0;
124 count = pRecipientList->recipientCnt;
125 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
127 *ppDest = (char*)new char[dataSize];
129 void* p = (void*)*ppDest;
131 memcpy(p, &count, sizeof(int));
132 p = (void*)((char*)p + sizeof(int));
134 for (int i = 0; i < count; i++) {
135 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
136 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
143 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
147 dataSize = sizeof(int);
149 *ppDest = (char*)new char[dataSize];
151 void* p = (void*)*ppDest;
153 memcpy(p, &MsgCount, dataSize);
159 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
163 dataSize = (sizeof(msg_message_id_t));
165 *ppDest = (char*)new char[dataSize];
167 void* p = (void*)*ppDest;
169 memcpy(p, pMsgId, dataSize);
175 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
179 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
181 *ppDest = (char*)new char[dataSize];
183 void* p = (void*)*ppDest;
185 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
187 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
189 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
190 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
191 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
198 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
202 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
204 *ppDest = (char*)new char[dataSize];
206 void* p = (void*)*ppDest;
208 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
210 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
212 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
214 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
216 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
217 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
218 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
225 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
227 int count = 0, dataSize = 0;
229 count = pFolderList->nCount;
230 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
232 *ppDest = (char*)new char[dataSize];
234 void* p = (void*)*ppDest;
236 memcpy(p, &count, sizeof(int));
237 p = (void*)((char*)p + sizeof(int));
239 msg_struct_s *folder_info = NULL;
241 for (int i = 0; i < count; i++) {
242 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
243 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
244 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
251 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
253 int count = 0, dataSize = 0;
255 count = pFilterList->nCount;
256 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
258 *ppDest = (char*)new char[dataSize];
260 void* p = (void*)*ppDest;
262 memcpy(p, &count, sizeof(int));
263 p = (void*)((char*)p + sizeof(int));
265 msg_struct_s *filter_info = NULL;
267 for (int i = 0; i < count; i++) {
268 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
269 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
270 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
277 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
281 dataSize = (sizeof(bool));
283 *ppDest = (char*)new char[dataSize];
285 void* p = (void*)*ppDest;
287 memcpy(p, pSetFlag, dataSize);
293 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
295 int count = 0, dataSize = 0;
297 count = pThreadViewList->nCount;
299 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
301 *ppDest = (char*)new char[dataSize];
303 void* p = (void*)*ppDest;
305 memcpy(p, &count, sizeof(int));
306 p = (void*)((char*)p + sizeof(int));
308 msg_struct_s *thread_info = NULL;
310 for (int i = 0; i < count; i++) {
311 thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
312 memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
313 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
320 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
322 int count = 0, dataSize = 0;
324 count = pConvViewList->nCount;
326 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
328 *ppDest = (char*)new char[dataSize];
330 void* p = (void*)*ppDest;
332 memcpy(p, &count, sizeof(int));
333 p = (void*)((char*)p + sizeof(int));
335 for (int i = 0; i < count; i++) {
336 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
337 p = (void*)((char*)p + sizeof(msg_struct_list_s));
344 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
346 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
348 MSG_DEBUG("datasize = [%d] \n", dataSize);
350 *ppDest = (char*)new char[dataSize];
352 void* p = (void*)*ppDest;
354 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
355 p = (void*)((char*)p + sizeof(int));
357 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
358 p = (void*)((char*)p + sizeof(int));
360 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
361 p = (void*)((char*)p + sizeof(int));
363 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
364 p = (void*)((char*)p + sizeof(int));
369 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
373 dataSize = sizeof(unsigned int);
375 *ppDest = (char*)new char[dataSize];
377 void* p = (void*)*ppDest;
379 memcpy(p, memsize, dataSize);
385 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
389 dataSize = sizeof(int) + sizeof(int);
391 *ppDest = (char*)new char[dataSize];
393 void* p = (void*)*ppDest;
395 memcpy(p, &msgId, sizeof(int));
396 p = (void*)((char*)p + sizeof(int));
398 memcpy(p, &extId, sizeof(int));
404 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
409 count = pMsgIdList->nCount;
411 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
413 *ppDest = (char*)new char[dataSize];
415 void* p = (void*)*ppDest;
417 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
418 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
420 memcpy(p, &count, sizeof(int));
421 p = (void*)((char*)p + sizeof(int));
423 for (int i = 0; i < count; i++) {
424 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
425 p = (void*)((char*)p + sizeof(msg_message_id_t));
432 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
437 addr_len = strlen(pMsgInfo->addressList->addressVal);
439 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
441 *ppDest = (char*)new char[dataSize];
443 void* p = (void*)*ppDest;
445 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
446 p = (void*)((char*)p + sizeof(msg_report_type_t));
448 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
449 p = (void*)((char*)p + sizeof(msg_message_id_t));
451 memcpy(p, &addr_len, sizeof(int));
452 p = (void*)((char*)p + sizeof(int));
454 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
455 p = (void*)((char*)p + addr_len);
461 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
465 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
467 *ppDest = (char*)new char[dataSize];
469 void* p = (void*)*ppDest;
471 memcpy(p, &count, sizeof(int));
473 p = (void*)((char*)p + sizeof(int));
475 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
481 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
485 dataSize = (sizeof(msg_thread_id_t));
487 *ppDest = (char*)new char[dataSize];
489 void* p = (void*)*ppDest;
491 memcpy(p, pThreadId, dataSize);
497 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
501 dataSize = sizeof(MSG_THREAD_VIEW_S);
503 *ppDest = (char*)new char[dataSize];
505 void* p = (void*)*ppDest;
507 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
509 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
516 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
518 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
522 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
524 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
528 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
530 memcpy(memsize, pSrc, sizeof(unsigned int));
534 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
536 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
538 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
540 pMsgInfo->addressList = NULL;
542 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
543 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
545 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
546 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
551 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
553 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
555 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
557 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
559 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
561 if(pMsgInfo->nAddressCnt > 0) {
562 pMsgInfo->addressList = NULL;
564 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
565 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
567 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
568 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
574 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
578 memcpy(&count, pSrc, sizeof(int));
579 pSrc = pSrc + sizeof(int);
581 pRecipientList->recipientCnt = count;
582 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
584 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
586 for (int i = 0; i < count; i++) {
587 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
588 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
594 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
598 memcpy(&count, pSrc, sizeof(int));
599 pSrc = pSrc + sizeof(int);
602 pFolderList->nCount = count;
603 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
604 if (pFolderList->msg_struct_info == NULL) {
605 pFolderList->nCount = 0;
608 msg_struct_s *pInfoTmp = NULL;
610 for (int i = 0; i < count; i++) {
611 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
612 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
613 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
614 pInfoTmp->data = new MSG_FOLDER_INFO_S;
615 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
616 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
618 } else if ( count == 0 ) {
619 pFolderList->nCount = count;
620 pFolderList->msg_struct_info = NULL;
625 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
629 memcpy(&count, pSrc, sizeof(int));
630 pSrc = pSrc + sizeof(int);
633 pFilterList->nCount = count;
634 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
636 if (pFilterList->msg_struct_info == NULL) {
637 pFilterList->nCount = 0;
641 msg_struct_s *pStructTmp = NULL;
643 for (int i = 0; i < count; i++) {
644 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
645 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
646 pStructTmp->type = MSG_STRUCT_FILTER;
647 pStructTmp->data = new MSG_FILTER_S;
648 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
649 pSrc = pSrc + sizeof(MSG_FILTER_S);
651 } else if ( count == 0 ) {
652 pFilterList->nCount = count;
653 pFilterList->msg_struct_info = NULL;
658 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
660 memcpy(pSetFlag, pSrc, sizeof(bool));
664 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
666 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
670 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
677 memcpy(&count, pSrc, sizeof(int));
678 pSrc = pSrc + sizeof(int);
679 pMsgThreadCountList->totalCount = count;
682 memcpy(&count, pSrc, sizeof(int));
683 pSrc = pSrc + sizeof(int);
684 pMsgThreadCountList->unReadCount = count;
687 memcpy(&count, pSrc, sizeof(int));
688 pSrc = pSrc + sizeof(int);
689 pMsgThreadCountList->mmsMsgCount = count;
692 memcpy(&count, pSrc, sizeof(int));
693 pSrc = pSrc + sizeof(int);
694 pMsgThreadCountList->smsMsgCount = count;
701 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
708 memcpy(&count, pSrc, sizeof(int));
709 pSrc = pSrc + sizeof(int);
711 report_list->nCount = count;
713 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
714 for (int i = 0; i < count; i++) {
715 msg_struct_s *report_status_item = new msg_struct_s;
716 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
717 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
718 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
720 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
721 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
723 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
725 report_status[i] = (msg_struct_t)report_status_item;
727 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
728 report_status_info->type, report_status_info->addressVal,
729 report_status_info->status, report_status_info->statusTime);
732 report_list->msg_struct_info = report_status;
736 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
738 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
741 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
743 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
747 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
749 MSG_EVENT_S* pMsgEvent = NULL;
752 MSG_DEBUG("*ppEvent is not NULL.");
753 delete [] (char *)*ppEvent;
756 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
758 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
760 pMsgEvent->eventType = MsgEvent;
761 pMsgEvent->result = MsgError;
763 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
764 MSG_DEBUG("result [%d]", pMsgEvent->result);
767 memcpy((void*)pMsgEvent->data, pData, DataSize);
769 return (sizeof(MSG_EVENT_S) + DataSize);
772 int msg_verify_number(const char *raw, char *trimmed)
774 if (!(raw && trimmed)) {
775 MSG_DEBUG("Phone Number is NULL");
776 return MSG_ERR_NULL_POINTER;
779 for (int i=0, j=0 ; raw[i] ; i++) {
780 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
781 || raw[i] == '*' || raw[i] == '#') {
782 trimmed[j++] = raw[i];
783 } else if (raw[i] == '-') {
786 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
787 return MSG_ERR_INVALID_PARAMETER;
791 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
795 int msg_verify_email(const char *raw)
798 bool atExist = false;
801 MSG_DEBUG("Email is NULL");
802 return MSG_ERR_NULL_POINTER;
805 for (int i = 0; raw[i]; i++) {
809 if (atExist == false) {
813 MSG_DEBUG("Character [@] is included more than twice in email address.");
814 return MSG_ERR_INVALID_PARAMETER;
818 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
820 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
823 } else if (raw[i] == ',') {
824 if (onlyNum == false && atExist == false) {
825 MSG_DEBUG("Unacceptable type in address.");
826 return MSG_ERR_INVALID_PARAMETER;
832 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
833 return MSG_ERR_INVALID_PARAMETER;
841 char* msg_clean_country_code(char *src)
845 switch (src[ret++]-'0') {
850 switch (src[ret++]-'0') {
865 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
870 switch (src[ret++]-'0') {
885 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
890 switch (src[ret++]-'0') {
905 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
910 switch (src[ret++]-'0') {
925 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
930 switch (src[ret++]-'0') {
945 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
950 switch (src[ret++]-'0') {
965 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
970 switch (src[ret++]-'0') {
985 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
991 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
999 char* msg_normalize_number(char *src)
1001 char *normalized_number;
1004 normalized_number = msg_clean_country_code(src);
1005 else if ('0' == src[0])
1006 normalized_number = src+1;
1008 normalized_number = src;
1010 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1012 return normalized_number;
1016 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
1018 char *notiMsg = NULL;
1021 lang = vconf_get_str(VCONFKEY_LANGSET);
1023 setlocale(LC_MESSAGES, lang);
1025 bindtextdomain(pkg_name, locale_dir);
1027 notiMsg = dgettext(pkg_name, text);
1034 return g_strdup(notiMsg);
1038 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1043 memset(sql, 0x00, sizeof(sql));
1044 memset(order, 0x00, sizeof(order));
1046 if (pSortRule->bAscending == true)
1047 strncpy(order, "ASC", 5);
1049 strncpy(order, "DESC", 5);
1051 switch (pSortRule->sortType) {
1052 case MSG_SORT_BY_DISPLAY_FROM :
1053 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1055 case MSG_SORT_BY_DISPLAY_TO :
1056 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1058 case MSG_SORT_BY_DISPLAY_TIME :
1059 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1061 case MSG_SORT_BY_MSG_TYPE :
1062 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1064 case MSG_SORT_BY_READ_STATUS :
1065 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1067 case MSG_SORT_BY_STORAGE_TYPE :
1068 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1070 case MSG_SORT_BY_THREAD_NAME :
1071 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1073 case MSG_SORT_BY_THREAD_DATE :
1074 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1076 case MSG_SORT_BY_THREAD_COUNT :
1077 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1080 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1084 memcpy(pSqlSort, sql, strlen(sql));
1088 bool msg_is_valid_email(char *pAddress)
1090 if (!pAddress || pAddress[0] == 0)
1092 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1097 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1099 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1100 pMsgInfo->bTextSms = false;
1102 /* Save Message Data into File */
1103 char fileName[MSG_FILENAME_LEN_MAX+1];
1104 memset(fileName, 0x00, sizeof(fileName));
1106 if(MsgCreateFileName(fileName) == false) {
1107 MSG_DEBUG("MsgCreateFileName error");
1108 return MSG_ERR_STORAGE_ERROR;
1111 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1113 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1114 MSG_DEBUG("MsgWriteIpcFile error");
1115 return MSG_ERR_STORAGE_ERROR;
1118 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1119 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1121 pMsgInfo->bTextSms = true;
1123 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1124 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1130 /* change illegal filename character to '_' */
1131 void msg_replace_available_file_name(char *fileName)
1135 bool is_converted = false;
1138 len = strlen(fileName);
1140 while (fileName[idx] != 0) {
1142 MSG_WARN("idx : %d, len : %d", idx, len);
1146 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1147 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1148 fileName[idx++] = '_';
1149 is_converted = true;
1157 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1160 /* change character ' ' to '_' */
1161 void msg_replace_space_char(char *pszText)
1164 MSG_ERR("pszText is NULL");
1168 char *spaceCharPtr = strchr(pszText, ' ');
1170 while (spaceCharPtr) {
1171 *spaceCharPtr = '_';
1172 spaceCharPtr = strchr(pszText, ' ');
1176 /* change non-ascii character to underscore */
1177 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1180 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1184 gsize result_len = 0;
1186 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1187 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1189 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1190 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1197 static int __find_login_user(uid_t *uid)
1202 int uids_len = sd_get_uids(&uids);
1206 for (int i = 0; i < uids_len; i++) {
1207 if (sd_uid_get_state(uids[i], &state) < 0) {
1211 if (g_strcmp0(state, "online") == 0) {
1227 uid_t msg_get_login_user()
1231 if (__find_login_user(&uid) < 0) {
1232 MSG_WARN("Cannot find login user");
1235 MSG_DEBUG("login user id [%d]", uid);
1241 msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
1243 int ret = aul_launch_app_for_uid(app_id, bundle_data, msg_get_login_user());
1245 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
1246 return MSG_ERR_UNKNOWN;
1257 _dbus_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
1258 "msg-service.dbus.service",
1259 G_BUS_NAME_OWNER_FLAGS_NONE,
1263 if (_dbus_owner_id == 0) {
1264 MSG_ERR("g_bus_own_name() error");
1267 MSG_DEBUG("owner_id = [%d]", _dbus_owner_id);
1270 void MsgDbusDeinit()
1274 g_bus_unown_name(_dbus_owner_id);