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.
20 #include "MsgContact.h"
21 #include "MsgUtilFile.h"
22 #include "MsgUtilFunction.h"
24 #include <system_info.h>
31 enum _FEATURE_INDEX_E {
32 FEATURE_INDEX_SMS = 0,
33 FEATURE_INDEX_MMS = 1,
36 static bool b_feature_cache_flag = false;
37 static bool b_feature_support[] = {
38 [FEATURE_INDEX_SMS] = false,
39 [FEATURE_INDEX_MMS] = false,
42 int _dbus_owner_id = 0;
44 /*==================================================================================================
45 FUNCTION IMPLEMENTATION
46 ==================================================================================================*/
48 bool MsgCheckFeatureSupport(const char *feature_name)
52 if (b_feature_cache_flag == false) {
53 if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_support[FEATURE_INDEX_SMS]) != SYSTEM_INFO_ERROR_NONE)
54 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE);
56 if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_support[FEATURE_INDEX_MMS]) != SYSTEM_INFO_ERROR_NONE)
57 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE);
59 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_support[FEATURE_INDEX_SMS]);
60 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_support[FEATURE_INDEX_MMS]);
62 b_feature_cache_flag = true;
65 if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) {
66 result = b_feature_support[FEATURE_INDEX_SMS];
67 } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
68 result = b_feature_support[FEATURE_INDEX_MMS];
75 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
79 dataSize = sizeof(MSG_COUNT_INFO_S);
81 *ppDest = (char*)new char[dataSize];
83 void* p = (void*)*ppDest;
85 memcpy(p, pCountInfo, dataSize);
91 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
93 int count = 0, dataSize = 0;
95 count = pRecipientList->recipientCnt;
96 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
98 *ppDest = (char*)new char[dataSize];
100 void* p = (void*)*ppDest;
102 memcpy(p, &count, sizeof(int));
103 p = (void*)((char*)p + sizeof(int));
105 for (int i = 0; i < count; i++)
107 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
108 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
115 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
119 dataSize = sizeof(int);
121 *ppDest = (char*)new char[dataSize];
123 void* p = (void*)*ppDest;
125 memcpy(p, &MsgCount, dataSize);
131 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
135 dataSize = (sizeof(msg_message_id_t));
137 *ppDest = (char*)new char[dataSize];
139 void* p = (void*)*ppDest;
141 memcpy(p, pMsgId, dataSize);
147 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
151 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
153 *ppDest = (char*)new char[dataSize];
155 void* p = (void*)*ppDest;
157 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
159 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
161 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
162 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
163 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
170 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
174 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
176 *ppDest = (char*)new char[dataSize];
178 void* p = (void*)*ppDest;
180 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
182 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
184 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
186 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
188 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
189 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
190 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
197 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
199 int count = 0, dataSize = 0;
201 count = pFolderList->nCount;
202 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
204 *ppDest = (char*)new char[dataSize];
206 void* p = (void*)*ppDest;
208 memcpy(p, &count, sizeof(int));
209 p = (void*)((char*)p + sizeof(int));
211 msg_struct_s *folder_info = NULL;
213 for (int i = 0; i < count; i++)
215 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
216 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
217 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
224 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
226 int count = 0, dataSize = 0;
228 count = pFilterList->nCount;
229 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
231 *ppDest = (char*)new char[dataSize];
233 void* p = (void*)*ppDest;
235 memcpy(p, &count, sizeof(int));
236 p = (void*)((char*)p + sizeof(int));
238 msg_struct_s *filter_info = NULL;
240 for (int i = 0; i < count; i++)
242 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
243 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
244 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
251 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
255 dataSize = (sizeof(bool));
257 *ppDest = (char*)new char[dataSize];
259 void* p = (void*)*ppDest;
261 memcpy(p, pSetFlag, dataSize);
267 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
269 int count = 0, dataSize = 0;
271 count = pThreadViewList->nCount;
273 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
275 *ppDest = (char*)new char[dataSize];
277 void* p = (void*)*ppDest;
279 memcpy(p, &count, sizeof(int));
280 p = (void*)((char*)p + sizeof(int));
282 msg_struct_s *thread_info = NULL;
284 for (int i = 0; i < count; i++)
286 thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
287 memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
288 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
295 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
297 int count = 0, dataSize = 0;
299 count = pConvViewList->nCount;
301 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
303 *ppDest = (char*)new char[dataSize];
305 void* p = (void*)*ppDest;
307 memcpy(p, &count, sizeof(int));
308 p = (void*)((char*)p + sizeof(int));
310 for (int i = 0; i < count; i++)
312 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
313 p = (void*)((char*)p + sizeof(msg_struct_list_s));
320 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
322 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
324 MSG_DEBUG("datasize = [%d] \n", dataSize);
326 *ppDest = (char*)new char[dataSize];
328 void* p = (void*)*ppDest;
330 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
331 p = (void*)((char*)p + sizeof(int));
333 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
334 p = (void*)((char*)p + sizeof(int));
336 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
337 p = (void*)((char*)p + sizeof(int));
339 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
340 p = (void*)((char*)p + sizeof(int));
345 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
349 dataSize = sizeof(unsigned int);
351 *ppDest = (char*)new char[dataSize];
353 void* p = (void*)*ppDest;
355 memcpy(p, memsize, dataSize);
361 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
365 dataSize = sizeof(int) + sizeof(int);
367 *ppDest = (char*)new char[dataSize];
369 void* p = (void*)*ppDest;
371 memcpy(p, &msgId, sizeof(int));
372 p = (void*)((char*)p + sizeof(int));
374 memcpy(p, &extId, sizeof(int));
380 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
385 count = pMsgIdList->nCount;
387 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
389 *ppDest = (char*)new char[dataSize];
391 void* p = (void*)*ppDest;
393 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
394 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
396 memcpy(p, &count, sizeof(int));
397 p = (void*)((char*)p + sizeof(int));
399 for (int i = 0; i < count; i++) {
400 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
401 p = (void*)((char*)p + sizeof(msg_message_id_t));
408 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
413 addr_len = strlen(pMsgInfo->addressList->addressVal);
415 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
417 *ppDest = (char*)new char[dataSize];
419 void* p = (void*)*ppDest;
421 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
422 p = (void*)((char*)p + sizeof(msg_report_type_t));
424 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
425 p = (void*)((char*)p + sizeof(msg_message_id_t));
427 memcpy(p, &addr_len, sizeof(int));
428 p = (void*)((char*)p + sizeof(int));
430 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
431 p = (void*)((char*)p + addr_len);
437 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
441 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
443 *ppDest = (char*)new char[dataSize];
445 void* p = (void*)*ppDest;
447 memcpy(p, &count, sizeof(int));
449 p = (void*)((char*)p + sizeof(int));
451 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
457 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
461 dataSize = (sizeof(msg_thread_id_t));
463 *ppDest = (char*)new char[dataSize];
465 void* p = (void*)*ppDest;
467 memcpy(p, pThreadId, dataSize);
473 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
477 dataSize = sizeof(MSG_THREAD_VIEW_S);
479 *ppDest = (char*)new char[dataSize];
481 void* p = (void*)*ppDest;
483 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
485 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
493 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
495 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
499 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
501 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
505 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
507 memcpy(memsize, pSrc, sizeof(unsigned int));
511 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
513 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
515 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
517 pMsgInfo->addressList = NULL;
519 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
520 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
522 for (int i=0; i<pMsgInfo->nAddressCnt; i++) {
523 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
528 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
530 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
532 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
534 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
536 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
539 if(pMsgInfo->nAddressCnt > 0) {
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));
552 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
556 memcpy(&count, pSrc, sizeof(int));
557 pSrc = pSrc + sizeof(int);
559 pRecipientList->recipientCnt= count;
560 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
562 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
564 for (int i = 0; i < count; i++)
566 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
567 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
573 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
577 memcpy(&count, pSrc, sizeof(int));
578 pSrc = pSrc + sizeof(int);
582 pFolderList->nCount = count;
583 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
584 if (pFolderList->msg_struct_info == NULL)
586 pFolderList->nCount = 0;
589 msg_struct_s *pInfoTmp = NULL;
591 for (int i = 0; i < count; i++)
593 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
594 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
595 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
596 pInfoTmp->data = new MSG_FOLDER_INFO_S;
597 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
598 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
601 else if ( count == 0 )
603 pFolderList->nCount = count;
604 pFolderList->msg_struct_info = NULL;
609 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
613 memcpy(&count, pSrc, sizeof(int));
614 pSrc = pSrc + sizeof(int);
618 pFilterList->nCount = count;
619 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
621 if (pFilterList->msg_struct_info == NULL) {
622 pFilterList->nCount = 0;
626 msg_struct_s *pStructTmp = NULL;
628 for (int i = 0; i < count; i++)
630 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
631 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
632 pStructTmp->type = MSG_STRUCT_FILTER;
633 pStructTmp->data = new MSG_FILTER_S;
634 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
635 pSrc = pSrc + sizeof(MSG_FILTER_S);
638 else if ( count == 0 )
640 pFilterList->nCount = count;
641 pFilterList->msg_struct_info = NULL;
647 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
649 memcpy(pSetFlag, pSrc, sizeof(bool));
653 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
655 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
659 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
666 memcpy(&count, pSrc, sizeof(int));
667 pSrc = pSrc + sizeof(int);
668 pMsgThreadCountList->totalCount = count;
671 memcpy(&count, pSrc, sizeof(int));
672 pSrc = pSrc + sizeof(int);
673 pMsgThreadCountList->unReadCount = count;
676 memcpy(&count, pSrc, sizeof(int));
677 pSrc = pSrc + sizeof(int);
678 pMsgThreadCountList->mmsMsgCount = count;
681 memcpy(&count, pSrc, sizeof(int));
682 pSrc = pSrc + sizeof(int);
683 pMsgThreadCountList->smsMsgCount = count;
690 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
697 memcpy(&count, pSrc, sizeof(int));
698 pSrc = pSrc + sizeof(int);
700 report_list->nCount = count;
702 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
703 for (int i = 0; i < count; i++) {
705 msg_struct_s *report_status_item = new msg_struct_s;
706 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
707 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
708 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
710 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
711 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
713 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
715 report_status[i] = (msg_struct_t)report_status_item;
717 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
718 report_status_info->type, report_status_info->addressVal,
719 report_status_info->status, report_status_info->statusTime);
722 report_list->msg_struct_info = report_status;
726 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
728 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
731 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
733 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
737 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
739 MSG_EVENT_S* pMsgEvent = NULL;
742 MSG_DEBUG("*ppEvent is not NULL.");
743 delete [] (char *)*ppEvent;
746 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
748 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
750 pMsgEvent->eventType = MsgEvent;
751 pMsgEvent->result = MsgError;
753 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
754 MSG_DEBUG("result [%d]", pMsgEvent->result);
757 memcpy((void*)pMsgEvent->data, pData, DataSize);
759 return (sizeof(MSG_EVENT_S) + DataSize);
762 int msg_verify_number(const char *raw, char *trimmed)
764 if (!(raw && trimmed)) {
765 MSG_DEBUG("Phone Number is NULL");
766 return MSG_ERR_NULL_POINTER;
769 for (int i=0, j=0 ; raw[i] ; i++) {
770 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
771 || raw[i] == '*' || raw[i] == '#') {
772 trimmed[j++] = raw[i];
773 } else if (raw[i] == '-') {
776 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
777 return MSG_ERR_INVALID_PARAMETER;
781 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
785 int msg_verify_email(const char *raw)
788 bool atExist = false;
791 MSG_DEBUG("Email is NULL");
792 return MSG_ERR_NULL_POINTER;
795 for (int i = 0; raw[i]; i++) {
800 if (atExist == false) {
804 MSG_DEBUG("Character [@] is included more than twice in email address.");
805 return MSG_ERR_INVALID_PARAMETER;
809 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
811 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
814 } else if (raw[i] == ',') {
815 if (onlyNum == false && atExist == false) {
816 MSG_DEBUG("Unacceptable type in address.");
817 return MSG_ERR_INVALID_PARAMETER;
823 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
824 return MSG_ERR_INVALID_PARAMETER;
832 char* msg_clean_country_code(char *src)
836 switch (src[ret++]-'0')
842 switch (src[ret++]-'0')
858 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
863 switch (src[ret++]-'0')
879 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
884 switch (src[ret++]-'0')
900 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
905 switch (src[ret++]-'0')
921 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
926 switch (src[ret++]-'0')
942 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
947 switch (src[ret++]-'0')
963 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
968 switch (src[ret++]-'0')
984 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
990 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
998 char* msg_normalize_number(char *src)
1000 char *normalized_number;
1003 normalized_number = msg_clean_country_code(src);
1004 else if ('0' == src[0])
1005 normalized_number = src+1;
1007 normalized_number = src;
1009 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
1011 return normalized_number;
1015 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1020 memset(sql, 0x00, sizeof(sql));
1021 memset(order, 0x00, sizeof(order));
1023 if (pSortRule->bAscending == true)
1024 strncpy(order, "ASC", 5);
1026 strncpy(order, "DESC", 5);
1028 int nameOrder = MsgGetContactNameOrder();
1030 switch (pSortRule->sortType)
1032 case MSG_SORT_BY_DISPLAY_FROM :
1034 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1036 snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1038 case MSG_SORT_BY_DISPLAY_TO :
1040 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1042 snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1044 case MSG_SORT_BY_DISPLAY_TIME :
1045 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1047 case MSG_SORT_BY_MSG_TYPE :
1048 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1050 case MSG_SORT_BY_READ_STATUS :
1051 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1053 case MSG_SORT_BY_STORAGE_TYPE :
1054 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1056 case MSG_SORT_BY_THREAD_NAME :
1058 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1060 snprintf(sql, sizeof(sql), "ORDER BY LAST_NAME %s, FIRST_NAME %s;", order, order);
1062 case MSG_SORT_BY_THREAD_DATE :
1063 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1065 case MSG_SORT_BY_THREAD_COUNT :
1066 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1069 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1073 memcpy(pSqlSort, sql, strlen(sql));
1077 bool msg_is_valid_email(char *pAddress)
1079 if (!pAddress || pAddress[0] == 0)
1081 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1086 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1088 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1089 pMsgInfo->bTextSms = false;
1091 // Save Message Data into File
1092 char fileName[MSG_FILENAME_LEN_MAX+1];
1093 memset(fileName, 0x00, sizeof(fileName));
1095 if(MsgCreateFileName(fileName) == false) {
1096 MSG_DEBUG("MsgCreateFileName error");
1097 return MSG_ERR_STORAGE_ERROR;
1100 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1102 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1103 MSG_DEBUG("MsgWriteIpcFile error");
1104 return MSG_ERR_STORAGE_ERROR;
1107 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1108 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1110 pMsgInfo->bTextSms = true;
1112 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1113 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1119 /* change illegal filename character to '_' */
1120 void msg_replace_available_file_name(char *fileName)
1124 bool is_converted = false;
1127 len = strlen(fileName);
1129 while (fileName[idx] != 0) {
1131 MSG_WARN("idx : %d, len : %d", idx, len);
1135 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1136 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1137 fileName[idx++] = '_';
1138 is_converted = true;
1146 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1149 /* change character ' ' to '_' */
1150 void msg_replace_space_char(char *pszText)
1153 MSG_ERR("pszText is NULL");
1157 char *spaceCharPtr = strchr(pszText, ' ');
1159 while (spaceCharPtr) {
1160 *spaceCharPtr = '_';
1161 spaceCharPtr = strchr(pszText, ' ');
1165 /* change non-ascii character to underscore */
1166 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1169 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1173 gsize result_len = 0;
1175 result_len = g_utf8_strlen (pszText, -1) + 1; //+1 for malloc of non-terminating chracter
1176 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1178 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char (p), i++) {
1179 res[i] = isascii(g_utf8_get_char (p)) ? *p : replacementChar;
1189 _dbus_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
1190 "msg-service.dbus.service",
1191 G_BUS_NAME_OWNER_FLAGS_NONE,
1195 if (_dbus_owner_id == 0) {
1196 MSG_ERR("g_bus_own_name() error");
1199 MSG_DEBUG("owner_id = [%d]", _dbus_owner_id);
1202 void MsgDbusDeinit()
1206 g_bus_unown_name(_dbus_owner_id);