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 "MsgUtilFile.h"
23 #include "MsgUtilFunction.h"
25 #include <system_info.h>
32 enum _FEATURE_INDEX_E {
33 FEATURE_INDEX_SMS = 0,
34 FEATURE_INDEX_MMS = 1,
37 static bool b_feature_cache_flag = false;
38 static bool b_feature_support[] = {
39 [FEATURE_INDEX_SMS] = false,
40 [FEATURE_INDEX_MMS] = false,
43 int _dbus_owner_id = 0;
45 /*==================================================================================================
46 FUNCTION IMPLEMENTATION
47 ==================================================================================================*/
49 bool MsgCheckFeatureSupport(const char *feature_name)
53 if (b_feature_cache_flag == false) {
54 if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_support[FEATURE_INDEX_SMS]) != SYSTEM_INFO_ERROR_NONE)
55 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE);
57 if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_support[FEATURE_INDEX_MMS]) != SYSTEM_INFO_ERROR_NONE)
58 MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE);
60 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_support[FEATURE_INDEX_SMS]);
61 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_support[FEATURE_INDEX_MMS]);
63 b_feature_cache_flag = true;
66 if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) {
67 result = b_feature_support[FEATURE_INDEX_SMS];
68 } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
69 result = b_feature_support[FEATURE_INDEX_MMS];
76 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
80 dataSize = sizeof(MSG_COUNT_INFO_S);
82 *ppDest = (char*)new char[dataSize];
84 void* p = (void*)*ppDest;
86 memcpy(p, pCountInfo, dataSize);
92 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
94 int count = 0, dataSize = 0;
96 count = pRecipientList->recipientCnt;
97 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
99 *ppDest = (char*)new char[dataSize];
101 void* p = (void*)*ppDest;
103 memcpy(p, &count, sizeof(int));
104 p = (void*)((char*)p + sizeof(int));
106 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++) {
214 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
215 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
216 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
223 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
225 int count = 0, dataSize = 0;
227 count = pFilterList->nCount;
228 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
230 *ppDest = (char*)new char[dataSize];
232 void* p = (void*)*ppDest;
234 memcpy(p, &count, sizeof(int));
235 p = (void*)((char*)p + sizeof(int));
237 msg_struct_s *filter_info = NULL;
239 for (int i = 0; i < count; i++) {
240 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
241 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
242 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
249 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
253 dataSize = (sizeof(bool));
255 *ppDest = (char*)new char[dataSize];
257 void* p = (void*)*ppDest;
259 memcpy(p, pSetFlag, dataSize);
265 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
267 int count = 0, dataSize = 0;
269 count = pThreadViewList->nCount;
271 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
273 *ppDest = (char*)new char[dataSize];
275 void* p = (void*)*ppDest;
277 memcpy(p, &count, sizeof(int));
278 p = (void*)((char*)p + sizeof(int));
280 msg_struct_s *thread_info = NULL;
282 for (int i = 0; i < count; i++) {
283 thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
284 memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
285 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
292 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
294 int count = 0, dataSize = 0;
296 count = pConvViewList->nCount;
298 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
300 *ppDest = (char*)new char[dataSize];
302 void* p = (void*)*ppDest;
304 memcpy(p, &count, sizeof(int));
305 p = (void*)((char*)p + sizeof(int));
307 for (int i = 0; i < count; i++) {
308 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
309 p = (void*)((char*)p + sizeof(msg_struct_list_s));
316 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
318 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
320 MSG_DEBUG("datasize = [%d] \n", dataSize);
322 *ppDest = (char*)new char[dataSize];
324 void* p = (void*)*ppDest;
326 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
327 p = (void*)((char*)p + sizeof(int));
329 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
330 p = (void*)((char*)p + sizeof(int));
332 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
333 p = (void*)((char*)p + sizeof(int));
335 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
336 p = (void*)((char*)p + sizeof(int));
341 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
345 dataSize = sizeof(unsigned int);
347 *ppDest = (char*)new char[dataSize];
349 void* p = (void*)*ppDest;
351 memcpy(p, memsize, dataSize);
357 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
361 dataSize = sizeof(int) + sizeof(int);
363 *ppDest = (char*)new char[dataSize];
365 void* p = (void*)*ppDest;
367 memcpy(p, &msgId, sizeof(int));
368 p = (void*)((char*)p + sizeof(int));
370 memcpy(p, &extId, sizeof(int));
376 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
381 count = pMsgIdList->nCount;
383 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
385 *ppDest = (char*)new char[dataSize];
387 void* p = (void*)*ppDest;
389 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
390 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
392 memcpy(p, &count, sizeof(int));
393 p = (void*)((char*)p + sizeof(int));
395 for (int i = 0; i < count; i++) {
396 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
397 p = (void*)((char*)p + sizeof(msg_message_id_t));
404 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
409 addr_len = strlen(pMsgInfo->addressList->addressVal);
411 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
413 *ppDest = (char*)new char[dataSize];
415 void* p = (void*)*ppDest;
417 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
418 p = (void*)((char*)p + sizeof(msg_report_type_t));
420 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
421 p = (void*)((char*)p + sizeof(msg_message_id_t));
423 memcpy(p, &addr_len, sizeof(int));
424 p = (void*)((char*)p + sizeof(int));
426 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
427 p = (void*)((char*)p + addr_len);
433 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
437 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
439 *ppDest = (char*)new char[dataSize];
441 void* p = (void*)*ppDest;
443 memcpy(p, &count, sizeof(int));
445 p = (void*)((char*)p + sizeof(int));
447 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
453 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
457 dataSize = (sizeof(msg_thread_id_t));
459 *ppDest = (char*)new char[dataSize];
461 void* p = (void*)*ppDest;
463 memcpy(p, pThreadId, dataSize);
469 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
473 dataSize = sizeof(MSG_THREAD_VIEW_S);
475 *ppDest = (char*)new char[dataSize];
477 void* p = (void*)*ppDest;
479 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
481 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
488 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
490 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
494 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
496 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
500 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
502 memcpy(memsize, pSrc, sizeof(unsigned int));
506 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
508 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
510 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
512 pMsgInfo->addressList = NULL;
514 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
515 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
517 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
518 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
523 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
525 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
527 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
529 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
531 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
533 if(pMsgInfo->nAddressCnt > 0) {
534 pMsgInfo->addressList = NULL;
536 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
537 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
539 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
540 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
546 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
550 memcpy(&count, pSrc, sizeof(int));
551 pSrc = pSrc + sizeof(int);
553 pRecipientList->recipientCnt = count;
554 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
556 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
558 for (int i = 0; i < count; i++) {
559 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
560 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
566 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
570 memcpy(&count, pSrc, sizeof(int));
571 pSrc = pSrc + sizeof(int);
574 pFolderList->nCount = count;
575 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
576 if (pFolderList->msg_struct_info == NULL) {
577 pFolderList->nCount = 0;
580 msg_struct_s *pInfoTmp = NULL;
582 for (int i = 0; i < count; i++) {
583 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
584 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
585 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
586 pInfoTmp->data = new MSG_FOLDER_INFO_S;
587 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
588 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
590 } else if ( count == 0 ) {
591 pFolderList->nCount = count;
592 pFolderList->msg_struct_info = NULL;
597 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
601 memcpy(&count, pSrc, sizeof(int));
602 pSrc = pSrc + sizeof(int);
605 pFilterList->nCount = count;
606 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
608 if (pFilterList->msg_struct_info == NULL) {
609 pFilterList->nCount = 0;
613 msg_struct_s *pStructTmp = NULL;
615 for (int i = 0; i < count; i++) {
616 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
617 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
618 pStructTmp->type = MSG_STRUCT_FILTER;
619 pStructTmp->data = new MSG_FILTER_S;
620 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
621 pSrc = pSrc + sizeof(MSG_FILTER_S);
623 } else if ( count == 0 ) {
624 pFilterList->nCount = count;
625 pFilterList->msg_struct_info = NULL;
630 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
632 memcpy(pSetFlag, pSrc, sizeof(bool));
636 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
638 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
642 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
649 memcpy(&count, pSrc, sizeof(int));
650 pSrc = pSrc + sizeof(int);
651 pMsgThreadCountList->totalCount = count;
654 memcpy(&count, pSrc, sizeof(int));
655 pSrc = pSrc + sizeof(int);
656 pMsgThreadCountList->unReadCount = count;
659 memcpy(&count, pSrc, sizeof(int));
660 pSrc = pSrc + sizeof(int);
661 pMsgThreadCountList->mmsMsgCount = count;
664 memcpy(&count, pSrc, sizeof(int));
665 pSrc = pSrc + sizeof(int);
666 pMsgThreadCountList->smsMsgCount = count;
673 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
680 memcpy(&count, pSrc, sizeof(int));
681 pSrc = pSrc + sizeof(int);
683 report_list->nCount = count;
685 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
686 for (int i = 0; i < count; i++) {
687 msg_struct_s *report_status_item = new msg_struct_s;
688 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
689 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
690 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
692 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
693 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
695 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
697 report_status[i] = (msg_struct_t)report_status_item;
699 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
700 report_status_info->type, report_status_info->addressVal,
701 report_status_info->status, report_status_info->statusTime);
704 report_list->msg_struct_info = report_status;
708 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
710 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
713 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
715 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
719 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
721 MSG_EVENT_S* pMsgEvent = NULL;
724 MSG_DEBUG("*ppEvent is not NULL.");
725 delete [] (char *)*ppEvent;
728 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
730 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
732 pMsgEvent->eventType = MsgEvent;
733 pMsgEvent->result = MsgError;
735 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
736 MSG_DEBUG("result [%d]", pMsgEvent->result);
739 memcpy((void*)pMsgEvent->data, pData, DataSize);
741 return (sizeof(MSG_EVENT_S) + DataSize);
744 int msg_verify_number(const char *raw, char *trimmed)
746 if (!(raw && trimmed)) {
747 MSG_DEBUG("Phone Number is NULL");
748 return MSG_ERR_NULL_POINTER;
751 for (int i=0, j=0 ; raw[i] ; i++) {
752 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
753 || raw[i] == '*' || raw[i] == '#') {
754 trimmed[j++] = raw[i];
755 } else if (raw[i] == '-') {
758 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
759 return MSG_ERR_INVALID_PARAMETER;
763 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
767 int msg_verify_email(const char *raw)
770 bool atExist = false;
773 MSG_DEBUG("Email is NULL");
774 return MSG_ERR_NULL_POINTER;
777 for (int i = 0; raw[i]; i++) {
781 if (atExist == false) {
785 MSG_DEBUG("Character [@] is included more than twice in email address.");
786 return MSG_ERR_INVALID_PARAMETER;
790 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
792 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
795 } else if (raw[i] == ',') {
796 if (onlyNum == false && atExist == false) {
797 MSG_DEBUG("Unacceptable type in address.");
798 return MSG_ERR_INVALID_PARAMETER;
804 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
805 return MSG_ERR_INVALID_PARAMETER;
813 char* msg_clean_country_code(char *src)
817 switch (src[ret++]-'0') {
822 switch (src[ret++]-'0') {
837 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
842 switch (src[ret++]-'0') {
857 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
862 switch (src[ret++]-'0') {
877 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
882 switch (src[ret++]-'0') {
897 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
902 switch (src[ret++]-'0') {
917 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
922 switch (src[ret++]-'0') {
937 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
942 switch (src[ret++]-'0') {
957 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
963 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
971 char* msg_normalize_number(char *src)
973 char *normalized_number;
976 normalized_number = msg_clean_country_code(src);
977 else if ('0' == src[0])
978 normalized_number = src+1;
980 normalized_number = src;
982 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
984 return normalized_number;
988 char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
990 char *notiMsg = NULL;
993 lang = vconf_get_str(VCONFKEY_LANGSET);
995 setlocale(LC_MESSAGES, lang);
997 bindtextdomain(pkg_name, locale_dir);
999 notiMsg = dgettext(pkg_name, text);
1006 return g_strdup(notiMsg);
1010 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1015 memset(sql, 0x00, sizeof(sql));
1016 memset(order, 0x00, sizeof(order));
1018 if (pSortRule->bAscending == true)
1019 strncpy(order, "ASC", 5);
1021 strncpy(order, "DESC", 5);
1023 int nameOrder = MsgGetContactNameOrder();
1025 switch (pSortRule->sortType) {
1026 case MSG_SORT_BY_DISPLAY_FROM :
1028 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1030 snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1032 case MSG_SORT_BY_DISPLAY_TO :
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_TIME :
1039 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1041 case MSG_SORT_BY_MSG_TYPE :
1042 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1044 case MSG_SORT_BY_READ_STATUS :
1045 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1047 case MSG_SORT_BY_STORAGE_TYPE :
1048 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1050 case MSG_SORT_BY_THREAD_NAME :
1052 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1054 snprintf(sql, sizeof(sql), "ORDER BY LAST_NAME %s, FIRST_NAME %s;", order, order);
1056 case MSG_SORT_BY_THREAD_DATE :
1057 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1059 case MSG_SORT_BY_THREAD_COUNT :
1060 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1063 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1067 memcpy(pSqlSort, sql, strlen(sql));
1071 bool msg_is_valid_email(char *pAddress)
1073 if (!pAddress || pAddress[0] == 0)
1075 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1080 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1082 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1083 pMsgInfo->bTextSms = false;
1085 /* Save Message Data into File */
1086 char fileName[MSG_FILENAME_LEN_MAX+1];
1087 memset(fileName, 0x00, sizeof(fileName));
1089 if(MsgCreateFileName(fileName) == false) {
1090 MSG_DEBUG("MsgCreateFileName error");
1091 return MSG_ERR_STORAGE_ERROR;
1094 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1096 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1097 MSG_DEBUG("MsgWriteIpcFile error");
1098 return MSG_ERR_STORAGE_ERROR;
1101 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1102 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1104 pMsgInfo->bTextSms = true;
1106 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1107 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1113 /* change illegal filename character to '_' */
1114 void msg_replace_available_file_name(char *fileName)
1118 bool is_converted = false;
1121 len = strlen(fileName);
1123 while (fileName[idx] != 0) {
1125 MSG_WARN("idx : %d, len : %d", idx, len);
1129 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1130 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1131 fileName[idx++] = '_';
1132 is_converted = true;
1140 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1143 /* change character ' ' to '_' */
1144 void msg_replace_space_char(char *pszText)
1147 MSG_ERR("pszText is NULL");
1151 char *spaceCharPtr = strchr(pszText, ' ');
1153 while (spaceCharPtr) {
1154 *spaceCharPtr = '_';
1155 spaceCharPtr = strchr(pszText, ' ');
1159 /* change non-ascii character to underscore */
1160 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1163 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1167 gsize result_len = 0;
1169 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1170 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1172 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1173 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1180 static int __find_login_user(uid_t *uid)
1185 int uids_len = sd_get_uids(&uids);
1189 for (int i = 0; i < uids_len; i++) {
1190 if (sd_uid_get_state(uids[i], &state) < 0) {
1194 if (g_strcmp0(state, "online") == 0) {
1210 uid_t msg_get_login_user()
1214 if (__find_login_user(&uid) < 0) {
1215 MSG_WARN("Cannot find login user");
1218 MSG_DEBUG("login user id [%d]", uid);
1228 _dbus_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
1229 "msg-service.dbus.service",
1230 G_BUS_NAME_OWNER_FLAGS_NONE,
1234 if (_dbus_owner_id == 0) {
1235 MSG_ERR("g_bus_own_name() error");
1238 MSG_DEBUG("owner_id = [%d]", _dbus_owner_id);
1241 void MsgDbusDeinit()
1245 g_bus_unown_name(_dbus_owner_id);