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++) {
106 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
107 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
114 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
118 dataSize = sizeof(int);
120 *ppDest = (char*)new char[dataSize];
122 void* p = (void*)*ppDest;
124 memcpy(p, &MsgCount, dataSize);
130 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
134 dataSize = (sizeof(msg_message_id_t));
136 *ppDest = (char*)new char[dataSize];
138 void* p = (void*)*ppDest;
140 memcpy(p, pMsgId, dataSize);
146 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
150 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
152 *ppDest = (char*)new char[dataSize];
154 void* p = (void*)*ppDest;
156 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
158 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
160 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
161 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
162 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
169 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
173 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
175 *ppDest = (char*)new char[dataSize];
177 void* p = (void*)*ppDest;
179 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
181 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
183 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
185 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
187 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
188 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
189 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
196 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
198 int count = 0, dataSize = 0;
200 count = pFolderList->nCount;
201 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
203 *ppDest = (char*)new char[dataSize];
205 void* p = (void*)*ppDest;
207 memcpy(p, &count, sizeof(int));
208 p = (void*)((char*)p + sizeof(int));
210 msg_struct_s *folder_info = NULL;
212 for (int i = 0; i < count; i++) {
213 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
214 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
215 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
222 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
224 int count = 0, dataSize = 0;
226 count = pFilterList->nCount;
227 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
229 *ppDest = (char*)new char[dataSize];
231 void* p = (void*)*ppDest;
233 memcpy(p, &count, sizeof(int));
234 p = (void*)((char*)p + sizeof(int));
236 msg_struct_s *filter_info = NULL;
238 for (int i = 0; i < count; i++) {
239 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
240 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
241 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
248 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
252 dataSize = (sizeof(bool));
254 *ppDest = (char*)new char[dataSize];
256 void* p = (void*)*ppDest;
258 memcpy(p, pSetFlag, dataSize);
264 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
266 int count = 0, dataSize = 0;
268 count = pThreadViewList->nCount;
270 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
272 *ppDest = (char*)new char[dataSize];
274 void* p = (void*)*ppDest;
276 memcpy(p, &count, sizeof(int));
277 p = (void*)((char*)p + sizeof(int));
279 msg_struct_s *thread_info = NULL;
281 for (int i = 0; i < count; i++) {
282 thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
283 memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
284 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
291 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
293 int count = 0, dataSize = 0;
295 count = pConvViewList->nCount;
297 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
299 *ppDest = (char*)new char[dataSize];
301 void* p = (void*)*ppDest;
303 memcpy(p, &count, sizeof(int));
304 p = (void*)((char*)p + sizeof(int));
306 for (int i = 0; i < count; i++) {
307 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
308 p = (void*)((char*)p + sizeof(msg_struct_list_s));
315 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
317 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
319 MSG_DEBUG("datasize = [%d] \n", dataSize);
321 *ppDest = (char*)new char[dataSize];
323 void* p = (void*)*ppDest;
325 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
326 p = (void*)((char*)p + sizeof(int));
328 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
329 p = (void*)((char*)p + sizeof(int));
331 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
332 p = (void*)((char*)p + sizeof(int));
334 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
335 p = (void*)((char*)p + sizeof(int));
340 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
344 dataSize = sizeof(unsigned int);
346 *ppDest = (char*)new char[dataSize];
348 void* p = (void*)*ppDest;
350 memcpy(p, memsize, dataSize);
356 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
360 dataSize = sizeof(int) + sizeof(int);
362 *ppDest = (char*)new char[dataSize];
364 void* p = (void*)*ppDest;
366 memcpy(p, &msgId, sizeof(int));
367 p = (void*)((char*)p + sizeof(int));
369 memcpy(p, &extId, sizeof(int));
375 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
380 count = pMsgIdList->nCount;
382 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
384 *ppDest = (char*)new char[dataSize];
386 void* p = (void*)*ppDest;
388 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
389 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
391 memcpy(p, &count, sizeof(int));
392 p = (void*)((char*)p + sizeof(int));
394 for (int i = 0; i < count; i++) {
395 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
396 p = (void*)((char*)p + sizeof(msg_message_id_t));
403 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
408 addr_len = strlen(pMsgInfo->addressList->addressVal);
410 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
412 *ppDest = (char*)new char[dataSize];
414 void* p = (void*)*ppDest;
416 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
417 p = (void*)((char*)p + sizeof(msg_report_type_t));
419 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
420 p = (void*)((char*)p + sizeof(msg_message_id_t));
422 memcpy(p, &addr_len, sizeof(int));
423 p = (void*)((char*)p + sizeof(int));
425 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
426 p = (void*)((char*)p + addr_len);
432 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
436 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
438 *ppDest = (char*)new char[dataSize];
440 void* p = (void*)*ppDest;
442 memcpy(p, &count, sizeof(int));
444 p = (void*)((char*)p + sizeof(int));
446 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
452 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
456 dataSize = (sizeof(msg_thread_id_t));
458 *ppDest = (char*)new char[dataSize];
460 void* p = (void*)*ppDest;
462 memcpy(p, pThreadId, dataSize);
468 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
472 dataSize = sizeof(MSG_THREAD_VIEW_S);
474 *ppDest = (char*)new char[dataSize];
476 void* p = (void*)*ppDest;
478 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
480 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
487 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
489 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
493 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
495 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
499 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
501 memcpy(memsize, pSrc, sizeof(unsigned int));
505 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
507 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
509 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
511 pMsgInfo->addressList = NULL;
513 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
514 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
516 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
517 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
522 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
524 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
526 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
528 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
530 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
532 if(pMsgInfo->nAddressCnt > 0) {
533 pMsgInfo->addressList = NULL;
535 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
536 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
538 for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
539 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
545 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
549 memcpy(&count, pSrc, sizeof(int));
550 pSrc = pSrc + sizeof(int);
552 pRecipientList->recipientCnt = count;
553 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
555 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
557 for (int i = 0; i < count; i++) {
558 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
559 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
565 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
569 memcpy(&count, pSrc, sizeof(int));
570 pSrc = pSrc + sizeof(int);
573 pFolderList->nCount = count;
574 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
575 if (pFolderList->msg_struct_info == NULL) {
576 pFolderList->nCount = 0;
579 msg_struct_s *pInfoTmp = NULL;
581 for (int i = 0; i < count; i++) {
582 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
583 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
584 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
585 pInfoTmp->data = new MSG_FOLDER_INFO_S;
586 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
587 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
589 } else if ( count == 0 ) {
590 pFolderList->nCount = count;
591 pFolderList->msg_struct_info = NULL;
596 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
600 memcpy(&count, pSrc, sizeof(int));
601 pSrc = pSrc + sizeof(int);
604 pFilterList->nCount = count;
605 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
607 if (pFilterList->msg_struct_info == NULL) {
608 pFilterList->nCount = 0;
612 msg_struct_s *pStructTmp = NULL;
614 for (int i = 0; i < count; i++) {
615 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
616 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
617 pStructTmp->type = MSG_STRUCT_FILTER;
618 pStructTmp->data = new MSG_FILTER_S;
619 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
620 pSrc = pSrc + sizeof(MSG_FILTER_S);
622 } else if ( count == 0 ) {
623 pFilterList->nCount = count;
624 pFilterList->msg_struct_info = NULL;
629 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
631 memcpy(pSetFlag, pSrc, sizeof(bool));
635 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
637 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
641 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
648 memcpy(&count, pSrc, sizeof(int));
649 pSrc = pSrc + sizeof(int);
650 pMsgThreadCountList->totalCount = count;
653 memcpy(&count, pSrc, sizeof(int));
654 pSrc = pSrc + sizeof(int);
655 pMsgThreadCountList->unReadCount = count;
658 memcpy(&count, pSrc, sizeof(int));
659 pSrc = pSrc + sizeof(int);
660 pMsgThreadCountList->mmsMsgCount = count;
663 memcpy(&count, pSrc, sizeof(int));
664 pSrc = pSrc + sizeof(int);
665 pMsgThreadCountList->smsMsgCount = count;
672 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
679 memcpy(&count, pSrc, sizeof(int));
680 pSrc = pSrc + sizeof(int);
682 report_list->nCount = count;
684 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
685 for (int i = 0; i < count; i++) {
686 msg_struct_s *report_status_item = new msg_struct_s;
687 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
688 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
689 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
691 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
692 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
694 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
696 report_status[i] = (msg_struct_t)report_status_item;
698 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
699 report_status_info->type, report_status_info->addressVal,
700 report_status_info->status, report_status_info->statusTime);
703 report_list->msg_struct_info = report_status;
707 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
709 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
712 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
714 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
718 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
720 MSG_EVENT_S* pMsgEvent = NULL;
723 MSG_DEBUG("*ppEvent is not NULL.");
724 delete [] (char *)*ppEvent;
727 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
729 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
731 pMsgEvent->eventType = MsgEvent;
732 pMsgEvent->result = MsgError;
734 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
735 MSG_DEBUG("result [%d]", pMsgEvent->result);
738 memcpy((void*)pMsgEvent->data, pData, DataSize);
740 return (sizeof(MSG_EVENT_S) + DataSize);
743 int msg_verify_number(const char *raw, char *trimmed)
745 if (!(raw && trimmed)) {
746 MSG_DEBUG("Phone Number is NULL");
747 return MSG_ERR_NULL_POINTER;
750 for (int i=0, j=0 ; raw[i] ; i++) {
751 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
752 || raw[i] == '*' || raw[i] == '#') {
753 trimmed[j++] = raw[i];
754 } else if (raw[i] == '-') {
757 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
758 return MSG_ERR_INVALID_PARAMETER;
762 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
766 int msg_verify_email(const char *raw)
769 bool atExist = false;
772 MSG_DEBUG("Email is NULL");
773 return MSG_ERR_NULL_POINTER;
776 for (int i = 0; raw[i]; i++) {
780 if (atExist == false) {
784 MSG_DEBUG("Character [@] is included more than twice in email address.");
785 return MSG_ERR_INVALID_PARAMETER;
789 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
791 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
794 } else if (raw[i] == ',') {
795 if (onlyNum == false && atExist == false) {
796 MSG_DEBUG("Unacceptable type in address.");
797 return MSG_ERR_INVALID_PARAMETER;
803 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
804 return MSG_ERR_INVALID_PARAMETER;
812 char* msg_clean_country_code(char *src)
816 switch (src[ret++]-'0') {
821 switch (src[ret++]-'0') {
836 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
841 switch (src[ret++]-'0') {
856 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
861 switch (src[ret++]-'0') {
876 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
881 switch (src[ret++]-'0') {
896 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
901 switch (src[ret++]-'0') {
916 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
921 switch (src[ret++]-'0') {
936 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
941 switch (src[ret++]-'0') {
956 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
962 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
970 char* msg_normalize_number(char *src)
972 char *normalized_number;
975 normalized_number = msg_clean_country_code(src);
976 else if ('0' == src[0])
977 normalized_number = src+1;
979 normalized_number = src;
981 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
983 return normalized_number;
987 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
992 memset(sql, 0x00, sizeof(sql));
993 memset(order, 0x00, sizeof(order));
995 if (pSortRule->bAscending == true)
996 strncpy(order, "ASC", 5);
998 strncpy(order, "DESC", 5);
1000 int nameOrder = MsgGetContactNameOrder();
1002 switch (pSortRule->sortType) {
1003 case MSG_SORT_BY_DISPLAY_FROM :
1005 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1007 snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1009 case MSG_SORT_BY_DISPLAY_TO :
1011 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1013 snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1015 case MSG_SORT_BY_DISPLAY_TIME :
1016 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1018 case MSG_SORT_BY_MSG_TYPE :
1019 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1021 case MSG_SORT_BY_READ_STATUS :
1022 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1024 case MSG_SORT_BY_STORAGE_TYPE :
1025 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1027 case MSG_SORT_BY_THREAD_NAME :
1029 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1031 snprintf(sql, sizeof(sql), "ORDER BY LAST_NAME %s, FIRST_NAME %s;", order, order);
1033 case MSG_SORT_BY_THREAD_DATE :
1034 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1036 case MSG_SORT_BY_THREAD_COUNT :
1037 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1040 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1044 memcpy(pSqlSort, sql, strlen(sql));
1048 bool msg_is_valid_email(char *pAddress)
1050 if (!pAddress || pAddress[0] == 0)
1052 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
1057 msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
1059 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
1060 pMsgInfo->bTextSms = false;
1062 /* Save Message Data into File */
1063 char fileName[MSG_FILENAME_LEN_MAX+1];
1064 memset(fileName, 0x00, sizeof(fileName));
1066 if(MsgCreateFileName(fileName) == false) {
1067 MSG_DEBUG("MsgCreateFileName error");
1068 return MSG_ERR_STORAGE_ERROR;
1071 MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
1073 if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
1074 MSG_DEBUG("MsgWriteIpcFile error");
1075 return MSG_ERR_STORAGE_ERROR;
1078 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
1079 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
1081 pMsgInfo->bTextSms = true;
1083 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
1084 memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
1090 /* change illegal filename character to '_' */
1091 void msg_replace_available_file_name(char *fileName)
1095 bool is_converted = false;
1098 len = strlen(fileName);
1100 while (fileName[idx] != 0) {
1102 MSG_WARN("idx : %d, len : %d", idx, len);
1106 if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
1107 fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
1108 fileName[idx++] = '_';
1109 is_converted = true;
1117 MSG_SEC_DEBUG("converted filename : [%s]", fileName);
1120 /* change character ' ' to '_' */
1121 void msg_replace_space_char(char *pszText)
1124 MSG_ERR("pszText is NULL");
1128 char *spaceCharPtr = strchr(pszText, ' ');
1130 while (spaceCharPtr) {
1131 *spaceCharPtr = '_';
1132 spaceCharPtr = strchr(pszText, ' ');
1136 /* change non-ascii character to underscore */
1137 gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
1140 MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
1144 gsize result_len = 0;
1146 result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
1147 res = (gchar *)g_malloc (result_len * sizeof (gchar));
1149 for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
1150 res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
1160 _dbus_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
1161 "msg-service.dbus.service",
1162 G_BUS_NAME_OWNER_FLAGS_NONE,
1166 if (_dbus_owner_id == 0) {
1167 MSG_ERR("g_bus_own_name() error");
1170 MSG_DEBUG("owner_id = [%d]", _dbus_owner_id);
1173 void MsgDbusDeinit()
1177 g_bus_unown_name(_dbus_owner_id);