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 "MsgContact.h"
19 #include "MsgUtilFunction.h"
21 #include <system_info.h>
23 bool b_feature_check_flag = false;
24 bool b_feature_telephony = false;
25 bool b_feature_telephony_mms = false;
27 /*==================================================================================================
28 FUNCTION IMPLEMENTATION
29 ==================================================================================================*/
31 bool MsgCheckFeatureSupport(const char *feature_name)
35 if (b_feature_check_flag == false) {
36 system_info_get_platform_bool(MSG_TELEPHONY_FEATURE, &b_feature_telephony);
37 system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_telephony_mms);
38 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_FEATURE, b_feature_telephony);
39 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_telephony_mms);
41 b_feature_check_flag = true;
44 if (!g_strcmp0(feature_name, MSG_TELEPHONY_FEATURE)) {
45 result = b_feature_telephony;
46 } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
47 result = b_feature_telephony_mms;
56 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
60 dataSize = sizeof(MSG_COUNT_INFO_S);
62 *ppDest = (char*)new char[dataSize];
64 void* p = (void*)*ppDest;
66 memcpy(p, pCountInfo, dataSize);
72 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
74 int count = 0, dataSize = 0;
76 count = pRecipientList->recipientCnt;
77 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
79 *ppDest = (char*)new char[dataSize];
81 void* p = (void*)*ppDest;
83 memcpy(p, &count, sizeof(int));
84 p = (void*)((char*)p + sizeof(int));
86 for (int i = 0; i < count; i++)
88 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
89 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
96 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
100 dataSize = sizeof(int);
102 *ppDest = (char*)new char[dataSize];
104 void* p = (void*)*ppDest;
106 memcpy(p, &MsgCount, dataSize);
112 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
116 dataSize = (sizeof(msg_message_id_t));
118 *ppDest = (char*)new char[dataSize];
120 void* p = (void*)*ppDest;
122 memcpy(p, pMsgId, dataSize);
128 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
132 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
134 *ppDest = (char*)new char[dataSize];
136 void* p = (void*)*ppDest;
138 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
140 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
142 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
143 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
144 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
151 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
155 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
157 *ppDest = (char*)new char[dataSize];
159 void* p = (void*)*ppDest;
161 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
163 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
165 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
167 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
169 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
170 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
171 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
178 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
180 int count = 0, dataSize = 0;
182 count = pFolderList->nCount;
183 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
185 *ppDest = (char*)new char[dataSize];
187 void* p = (void*)*ppDest;
189 memcpy(p, &count, sizeof(int));
190 p = (void*)((char*)p + sizeof(int));
192 msg_struct_s *folder_info = NULL;
194 for (int i = 0; i < count; i++)
196 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
197 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
198 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
205 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
207 int count = 0, dataSize = 0;
209 count = pFilterList->nCount;
210 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
212 *ppDest = (char*)new char[dataSize];
214 void* p = (void*)*ppDest;
216 memcpy(p, &count, sizeof(int));
217 p = (void*)((char*)p + sizeof(int));
219 msg_struct_s *filter_info = NULL;
221 for (int i = 0; i < count; i++)
223 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
224 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
225 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
232 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
236 dataSize = (sizeof(bool));
238 *ppDest = (char*)new char[dataSize];
240 void* p = (void*)*ppDest;
242 memcpy(p, pSetFlag, dataSize);
248 int MsgEncodeMsgType(MSG_MESSAGE_TYPE_S *pMsgType, char **ppDest)
252 dataSize = (sizeof(MSG_MESSAGE_TYPE_S));
254 *ppDest = (char*)new char[dataSize];
256 void* p = (void*)*ppDest;
258 memcpy(p, pMsgType, 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++)
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++)
309 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
310 p = (void*)((char*)p + sizeof(msg_struct_list_s));
317 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
319 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
321 MSG_DEBUG("datasize = [%d] \n", dataSize);
323 *ppDest = (char*)new char[dataSize];
325 void* p = (void*)*ppDest;
327 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
328 p = (void*)((char*)p + sizeof(int));
330 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
331 p = (void*)((char*)p + sizeof(int));
333 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
334 p = (void*)((char*)p + sizeof(int));
336 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
337 p = (void*)((char*)p + sizeof(int));
342 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
346 dataSize = sizeof(unsigned int);
348 *ppDest = (char*)new char[dataSize];
350 void* p = (void*)*ppDest;
352 memcpy(p, memsize, dataSize);
358 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
362 dataSize = sizeof(int) + sizeof(int);
364 *ppDest = (char*)new char[dataSize];
366 void* p = (void*)*ppDest;
368 memcpy(p, &msgId, sizeof(int));
369 p = (void*)((char*)p + sizeof(int));
371 memcpy(p, &extId, sizeof(int));
377 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
382 count = pMsgIdList->nCount;
384 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
386 *ppDest = (char*)new char[dataSize];
388 void* p = (void*)*ppDest;
390 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
391 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
393 memcpy(p, &count, sizeof(int));
394 p = (void*)((char*)p + sizeof(int));
396 for (int i = 0; i < count; i++) {
397 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
398 p = (void*)((char*)p + sizeof(msg_message_id_t));
405 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
410 addr_len = strlen(pMsgInfo->addressList->addressVal);
412 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
414 *ppDest = (char*)new char[dataSize];
416 void* p = (void*)*ppDest;
418 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
419 p = (void*)((char*)p + sizeof(msg_report_type_t));
421 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
422 p = (void*)((char*)p + sizeof(msg_message_id_t));
424 memcpy(p, &addr_len, sizeof(int));
425 p = (void*)((char*)p + sizeof(int));
427 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
428 p = (void*)((char*)p + addr_len);
434 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
438 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
440 *ppDest = (char*)new char[dataSize];
442 void* p = (void*)*ppDest;
444 memcpy(p, &count, sizeof(int));
446 p = (void*)((int)p + sizeof(int));
448 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
454 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
458 dataSize = (sizeof(msg_thread_id_t));
460 *ppDest = (char*)new char[dataSize];
462 void* p = (void*)*ppDest;
464 memcpy(p, pThreadId, dataSize);
470 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
474 dataSize = sizeof(MSG_THREAD_VIEW_S);
476 *ppDest = (char*)new char[dataSize];
478 void* p = (void*)*ppDest;
480 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
482 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
490 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
492 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
496 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
498 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
502 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
504 memcpy(memsize, pSrc, sizeof(unsigned int));
508 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
510 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
512 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
514 pMsgInfo->addressList = NULL;
516 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
517 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
519 for (int i=0; i<pMsgInfo->nAddressCnt; i++) {
520 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
525 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
527 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
529 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
531 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
533 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
536 if(pMsgInfo->nAddressCnt > 0) {
537 pMsgInfo->addressList = NULL;
539 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
540 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
542 for (int i=0; i<pMsgInfo->nAddressCnt; i++) {
543 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
549 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
553 memcpy(&count, pSrc, sizeof(int));
554 pSrc = pSrc + sizeof(int);
556 pRecipientList->recipientCnt= count;
557 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
559 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
561 for (int i = 0; i < count; i++)
563 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
564 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
570 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
574 memcpy(&count, pSrc, sizeof(int));
575 pSrc = pSrc + sizeof(int);
579 pFolderList->nCount = count;
580 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
582 msg_struct_s *pInfoTmp = NULL;
584 for (int i = 0; i < count; i++)
586 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
587 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
588 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
589 pInfoTmp->data = new MSG_FOLDER_INFO_S;
590 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
591 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
594 else if ( count == 0 )
596 pFolderList->nCount = count;
597 pFolderList->msg_struct_info = NULL;
602 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
606 memcpy(&count, pSrc, sizeof(int));
607 pSrc = pSrc + sizeof(int);
611 pFilterList->nCount = count;
612 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
614 msg_struct_s *pStructTmp = NULL;
616 for (int i = 0; i < count; i++)
618 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
619 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
620 pStructTmp->type = MSG_STRUCT_FILTER;
621 pStructTmp->data = new MSG_FILTER_S;
622 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
623 pSrc = pSrc + sizeof(MSG_FILTER_S);
626 else if ( count == 0 )
628 pFilterList->nCount = count;
629 pFilterList->msg_struct_info = NULL;
635 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
637 memcpy(pSetFlag, pSrc, sizeof(bool));
641 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
643 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
647 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
654 memcpy(&count, pSrc, sizeof(int));
655 pSrc = pSrc + sizeof(int);
656 pMsgThreadCountList->totalCount = count;
659 memcpy(&count, pSrc, sizeof(int));
660 pSrc = pSrc + sizeof(int);
661 pMsgThreadCountList->unReadCount = count;
664 memcpy(&count, pSrc, sizeof(int));
665 pSrc = pSrc + sizeof(int);
666 pMsgThreadCountList->mmsMsgCount = count;
669 memcpy(&count, pSrc, sizeof(int));
670 pSrc = pSrc + sizeof(int);
671 pMsgThreadCountList->smsMsgCount = count;
678 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
685 memcpy(&count, pSrc, sizeof(int));
686 pSrc = pSrc + sizeof(int);
688 report_list->nCount = count;
690 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
691 for (int i = 0; i < count; i++) {
693 msg_struct_s *report_status_item = new msg_struct_s;
694 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
695 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
696 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
698 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
699 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
701 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
703 report_status[i] = (msg_struct_t)report_status_item;
705 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
706 report_status_info->type, report_status_info->addressVal,
707 report_status_info->status, report_status_info->statusTime);
710 report_list->msg_struct_info = report_status;
714 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
716 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
719 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
721 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
725 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
727 MSG_EVENT_S* pMsgEvent = NULL;
730 MSG_DEBUG("*ppEvent is not NULL.");
731 delete [] (char *)*ppEvent;
734 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
736 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
738 pMsgEvent->eventType = MsgEvent;
739 pMsgEvent->result = MsgError;
741 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
742 MSG_DEBUG("result [%d]", pMsgEvent->result);
745 memcpy((void*)pMsgEvent->data, pData, DataSize);
747 return (sizeof(MSG_EVENT_S) + DataSize);
750 int msg_verify_number(const char *raw, char *trimmed)
752 if (!(raw && trimmed)) {
753 MSG_DEBUG("Phone Number is NULL");
754 return MSG_ERR_NULL_POINTER;
757 for (int i=0, j=0 ; raw[i] ; i++) {
758 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
759 || raw[i] == '*' || raw[i] == '#') {
760 trimmed[j++] = raw[i];
761 } else if (raw[i] == '-') {
764 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
765 return MSG_ERR_INVALID_PARAMETER;
769 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
773 int msg_verify_email(const char *raw)
776 bool atExist = false;
779 MSG_DEBUG("Email is NULL");
780 return MSG_ERR_NULL_POINTER;
783 for (int i = 0; raw[i]; i++) {
788 if (atExist == false) {
792 MSG_DEBUG("Character [@] is included more than twice in email address.");
793 return MSG_ERR_INVALID_PARAMETER;
797 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
799 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
802 } else if (raw[i] == ',') {
803 if (onlyNum == false && atExist == false) {
804 MSG_DEBUG("Unacceptable type in address.");
805 return MSG_ERR_INVALID_PARAMETER;
811 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
812 return MSG_ERR_INVALID_PARAMETER;
820 char* msg_clean_country_code(char *src)
824 switch (src[ret++]-'0')
830 switch (src[ret++]-'0')
846 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
851 switch (src[ret++]-'0')
867 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
872 switch (src[ret++]-'0')
888 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
893 switch (src[ret++]-'0')
909 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
914 switch (src[ret++]-'0')
930 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
935 switch (src[ret++]-'0')
951 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
956 switch (src[ret++]-'0')
972 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
978 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
986 char* msg_normalize_number(char *src)
988 char *normalized_number;
991 normalized_number = msg_clean_country_code(src);
992 else if ('0' == src[0])
993 normalized_number = src+1;
995 normalized_number = src;
997 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
999 return normalized_number;
1003 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1008 memset(sql, 0x00, sizeof(sql));
1009 memset(order, 0x00, sizeof(order));
1011 if (pSortRule->bAscending == true)
1012 strncpy(order, "ASC", 5);
1014 strncpy(order, "DESC", 5);
1016 //contacts-service is not used for gear
1017 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
1018 int nameOrder = MsgGetContactNameOrder();
1021 #endif // MSG_CONTACTS_SERVICE_NOT_SUPPORTED
1023 switch (pSortRule->sortType)
1025 case MSG_SORT_BY_DISPLAY_FROM :
1027 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1029 snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1031 case MSG_SORT_BY_DISPLAY_TO :
1033 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1035 snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1037 case MSG_SORT_BY_DISPLAY_TIME :
1038 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1040 case MSG_SORT_BY_MSG_TYPE :
1041 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1043 case MSG_SORT_BY_READ_STATUS :
1044 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1046 case MSG_SORT_BY_STORAGE_TYPE :
1047 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1049 case MSG_SORT_BY_THREAD_NAME :
1051 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1053 snprintf(sql, sizeof(sql), "ORDER BY LAST_NAME %s, FIRST_NAME %s;", order, order);
1055 case MSG_SORT_BY_THREAD_DATE :
1056 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1058 case MSG_SORT_BY_THREAD_COUNT :
1059 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1062 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1066 memcpy(pSqlSort, sql, strlen(sql));
1070 bool msg_is_valid_email(char *pAddress)
1072 if (!pAddress || pAddress[0] == 0)
1074 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))