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_sms = 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 if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_telephony_sms) != SYSTEM_INFO_ERROR_NONE)
37 MSG_INFO("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE);
38 if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_telephony_mms) != SYSTEM_INFO_ERROR_NONE)
39 MSG_INFO("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE);
41 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_telephony_sms);
42 MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_telephony_mms);
44 b_feature_check_flag = true;
47 if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) {
48 result = b_feature_telephony_sms;
49 } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
50 result = b_feature_telephony_mms;
59 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
63 dataSize = sizeof(MSG_COUNT_INFO_S);
65 *ppDest = (char*)new char[dataSize];
67 void* p = (void*)*ppDest;
69 memcpy(p, pCountInfo, dataSize);
75 int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
77 int count = 0, dataSize = 0;
79 count = pRecipientList->recipientCnt;
80 dataSize = sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*count);
82 *ppDest = (char*)new char[dataSize];
84 void* p = (void*)*ppDest;
86 memcpy(p, &count, sizeof(int));
87 p = (void*)((char*)p + sizeof(int));
89 for (int i = 0; i < count; i++)
91 memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
92 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
99 int MsgEncodeCountByMsgType(int MsgCount, char **ppDest)
103 dataSize = sizeof(int);
105 *ppDest = (char*)new char[dataSize];
107 void* p = (void*)*ppDest;
109 memcpy(p, &MsgCount, dataSize);
115 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
119 dataSize = (sizeof(msg_message_id_t));
121 *ppDest = (char*)new char[dataSize];
123 void* p = (void*)*ppDest;
125 memcpy(p, pMsgId, dataSize);
131 int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
135 dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
137 *ppDest = (char*)new char[dataSize];
139 void* p = (void*)*ppDest;
141 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
143 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
145 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
146 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
147 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
154 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest)
158 dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
160 *ppDest = (char*)new char[dataSize];
162 void* p = (void*)*ppDest;
164 memcpy(p, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
166 p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
168 memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
170 p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
172 for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
173 memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
174 p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
181 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
183 int count = 0, dataSize = 0;
185 count = pFolderList->nCount;
186 dataSize = sizeof(int) + (sizeof(MSG_FOLDER_INFO_S)*count);
188 *ppDest = (char*)new char[dataSize];
190 void* p = (void*)*ppDest;
192 memcpy(p, &count, sizeof(int));
193 p = (void*)((char*)p + sizeof(int));
195 msg_struct_s *folder_info = NULL;
197 for (int i = 0; i < count; i++)
199 folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
200 memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
201 p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
208 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
210 int count = 0, dataSize = 0;
212 count = pFilterList->nCount;
213 dataSize = sizeof(int) + (sizeof(MSG_FILTER_S)*count);
215 *ppDest = (char*)new char[dataSize];
217 void* p = (void*)*ppDest;
219 memcpy(p, &count, sizeof(int));
220 p = (void*)((char*)p + sizeof(int));
222 msg_struct_s *filter_info = NULL;
224 for (int i = 0; i < count; i++)
226 filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
227 memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
228 p = (void*)((char*)p + sizeof(MSG_FILTER_S));
235 int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
239 dataSize = (sizeof(bool));
241 *ppDest = (char*)new char[dataSize];
243 void* p = (void*)*ppDest;
245 memcpy(p, pSetFlag, dataSize);
251 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
253 int count = 0, dataSize = 0;
255 count = pThreadViewList->nCount;
257 dataSize = sizeof(int) + (sizeof(MSG_THREAD_VIEW_S)*count);
259 *ppDest = (char*)new char[dataSize];
261 void* p = (void*)*ppDest;
263 memcpy(p, &count, sizeof(int));
264 p = (void*)((char*)p + sizeof(int));
266 msg_struct_s *thread_info = NULL;
268 for (int i = 0; i < count; i++)
270 thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
271 memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
272 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
279 int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDest)
281 int count = 0, dataSize = 0;
283 count = pConvViewList->nCount;
285 dataSize = sizeof(int) + (sizeof(msg_struct_list_s)*count);
287 *ppDest = (char*)new char[dataSize];
289 void* p = (void*)*ppDest;
291 memcpy(p, &count, sizeof(int));
292 p = (void*)((char*)p + sizeof(int));
294 for (int i = 0; i < count; i++)
296 memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
297 p = (void*)((char*)p + sizeof(msg_struct_list_s));
304 int MsgEncodeMsgGetContactCount(MSG_THREAD_COUNT_INFO_S *threadCountInfo, char **ppDest)
306 int dataSize = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int);
308 MSG_DEBUG("datasize = [%d] \n", dataSize);
310 *ppDest = (char*)new char[dataSize];
312 void* p = (void*)*ppDest;
314 memcpy(p, &(threadCountInfo->totalCount), sizeof(int));
315 p = (void*)((char*)p + sizeof(int));
317 memcpy(p, &(threadCountInfo->unReadCount), sizeof(int));
318 p = (void*)((char*)p + sizeof(int));
320 memcpy(p, &(threadCountInfo->mmsMsgCount), sizeof(int));
321 p = (void*)((char*)p + sizeof(int));
323 memcpy(p, &(threadCountInfo->smsMsgCount), sizeof(int));
324 p = (void*)((char*)p + sizeof(int));
329 int MsgEncodeMemSize(unsigned int *memsize, char **ppDest)
333 dataSize = sizeof(unsigned int);
335 *ppDest = (char*)new char[dataSize];
337 void* p = (void*)*ppDest;
339 memcpy(p, memsize, dataSize);
345 int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest)
349 dataSize = sizeof(int) + sizeof(int);
351 *ppDest = (char*)new char[dataSize];
353 void* p = (void*)*ppDest;
355 memcpy(p, &msgId, sizeof(int));
356 p = (void*)((char*)p + sizeof(int));
358 memcpy(p, &extId, sizeof(int));
364 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest)
369 count = pMsgIdList->nCount;
371 dataSize = sizeof(msg_storage_change_type_t) + sizeof(int) + (sizeof(msg_message_id_t)*count);
373 *ppDest = (char*)new char[dataSize];
375 void* p = (void*)*ppDest;
377 memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
378 p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
380 memcpy(p, &count, sizeof(int));
381 p = (void*)((char*)p + sizeof(int));
383 for (int i = 0; i < count; i++) {
384 memcpy(p, &(pMsgIdList->msgIdList[i]), sizeof(msg_message_id_t));
385 p = (void*)((char*)p + sizeof(msg_message_id_t));
392 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
397 addr_len = strlen(pMsgInfo->addressList->addressVal);
399 dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
401 *ppDest = (char*)new char[dataSize];
403 void* p = (void*)*ppDest;
405 memcpy(p, &msgReportType, sizeof(msg_report_type_t));
406 p = (void*)((char*)p + sizeof(msg_report_type_t));
408 memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
409 p = (void*)((char*)p + sizeof(msg_message_id_t));
411 memcpy(p, &addr_len, sizeof(int));
412 p = (void*)((char*)p + sizeof(int));
414 memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
415 p = (void*)((char*)p + addr_len);
421 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
425 dataSize = (sizeof(MSG_REPORT_STATUS_INFO_S)*count + sizeof(int));
427 *ppDest = (char*)new char[dataSize];
429 void* p = (void*)*ppDest;
431 memcpy(p, &count, sizeof(int));
433 p = (void*)((char*)p + sizeof(int));
435 memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
441 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest)
445 dataSize = (sizeof(msg_thread_id_t));
447 *ppDest = (char*)new char[dataSize];
449 void* p = (void*)*ppDest;
451 memcpy(p, pThreadId, dataSize);
457 int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
461 dataSize = sizeof(MSG_THREAD_VIEW_S);
463 *ppDest = (char*)new char[dataSize];
465 void* p = (void*)*ppDest;
467 memcpy(p, pThreadInfo, sizeof(MSG_THREAD_VIEW_S));
469 p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
477 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
479 memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
483 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo)
485 memcpy(pCountInfo, pSrc, sizeof(MSG_COUNT_INFO_S));
489 void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
491 memcpy(memsize, pSrc, sizeof(unsigned int));
495 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
497 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
499 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
501 pMsgInfo->addressList = NULL;
503 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
504 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
506 for (int i=0; i<pMsgInfo->nAddressCnt; i++) {
507 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
512 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
514 memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
516 pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
518 memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
520 pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
523 if(pMsgInfo->nAddressCnt > 0) {
524 pMsgInfo->addressList = NULL;
526 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
527 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
529 for (int i=0; i<pMsgInfo->nAddressCnt; i++) {
530 memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
536 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
540 memcpy(&count, pSrc, sizeof(int));
541 pSrc = pSrc + sizeof(int);
543 pRecipientList->recipientCnt= count;
544 pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
546 MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
548 for (int i = 0; i < count; i++)
550 memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
551 pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
557 void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
561 memcpy(&count, pSrc, sizeof(int));
562 pSrc = pSrc + sizeof(int);
566 pFolderList->nCount = count;
567 pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
568 if (pFolderList->msg_struct_info == NULL)
570 pFolderList->nCount = 0;
573 msg_struct_s *pInfoTmp = NULL;
575 for (int i = 0; i < count; i++)
577 pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
578 pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
579 pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
580 pInfoTmp->data = new MSG_FOLDER_INFO_S;
581 memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
582 pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
585 else if ( count == 0 )
587 pFolderList->nCount = count;
588 pFolderList->msg_struct_info = NULL;
593 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
597 memcpy(&count, pSrc, sizeof(int));
598 pSrc = pSrc + sizeof(int);
602 pFilterList->nCount = count;
603 pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
605 if (pFilterList->msg_struct_info == NULL) {
606 pFilterList->nCount = 0;
610 msg_struct_s *pStructTmp = NULL;
612 for (int i = 0; i < count; i++)
614 pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
615 pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
616 pStructTmp->type = MSG_STRUCT_FILTER;
617 pStructTmp->data = new MSG_FILTER_S;
618 memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
619 pSrc = pSrc + sizeof(MSG_FILTER_S);
622 else if ( count == 0 )
624 pFilterList->nCount = count;
625 pFilterList->msg_struct_info = NULL;
631 void MsgDecodeFilterFlag(char *pSrc, bool *pSetFlag)
633 memcpy(pSetFlag, pSrc, sizeof(bool));
637 void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
639 memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
643 void MsgDecodeContactCount(char *pSrc, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
650 memcpy(&count, pSrc, sizeof(int));
651 pSrc = pSrc + sizeof(int);
652 pMsgThreadCountList->totalCount = count;
655 memcpy(&count, pSrc, sizeof(int));
656 pSrc = pSrc + sizeof(int);
657 pMsgThreadCountList->unReadCount = count;
660 memcpy(&count, pSrc, sizeof(int));
661 pSrc = pSrc + sizeof(int);
662 pMsgThreadCountList->mmsMsgCount = count;
665 memcpy(&count, pSrc, sizeof(int));
666 pSrc = pSrc + sizeof(int);
667 pMsgThreadCountList->smsMsgCount = count;
674 void MsgDecodeReportStatus(char *pSrc, msg_struct_list_s *report_list)
681 memcpy(&count, pSrc, sizeof(int));
682 pSrc = pSrc + sizeof(int);
684 report_list->nCount = count;
686 msg_struct_t *report_status = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
687 for (int i = 0; i < count; i++) {
689 msg_struct_s *report_status_item = new msg_struct_s;
690 report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
691 report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
692 memset(report_status_item->data, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
694 MSG_REPORT_STATUS_INFO_S *report_status_info = (MSG_REPORT_STATUS_INFO_S *)report_status_item->data;
695 memcpy(report_status_info, pSrc, sizeof(MSG_REPORT_STATUS_INFO_S));
697 pSrc = pSrc + sizeof(MSG_REPORT_STATUS_INFO_S);
699 report_status[i] = (msg_struct_t)report_status_item;
701 MSG_DEBUG("Report_type = %d, status addr = %s, status = %d, time = %d",
702 report_status_info->type, report_status_info->addressVal,
703 report_status_info->status, report_status_info->statusTime);
706 report_list->msg_struct_info = report_status;
710 void MsgDecodeThreadId(char *pSrc, msg_thread_id_t *pThreadId)
712 memcpy(pThreadId, pSrc, sizeof(msg_thread_id_t));
715 void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
717 memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
721 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
723 MSG_EVENT_S* pMsgEvent = NULL;
726 MSG_DEBUG("*ppEvent is not NULL.");
727 delete [] (char *)*ppEvent;
730 *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
732 pMsgEvent = (MSG_EVENT_S*)*ppEvent;
734 pMsgEvent->eventType = MsgEvent;
735 pMsgEvent->result = MsgError;
737 MSG_DEBUG("eventType [%d : %s]", pMsgEvent->eventType, MsgDbgEvtStr(pMsgEvent->eventType));
738 MSG_DEBUG("result [%d]", pMsgEvent->result);
741 memcpy((void*)pMsgEvent->data, pData, DataSize);
743 return (sizeof(MSG_EVENT_S) + DataSize);
746 int msg_verify_number(const char *raw, char *trimmed)
748 if (!(raw && trimmed)) {
749 MSG_DEBUG("Phone Number is NULL");
750 return MSG_ERR_NULL_POINTER;
753 for (int i=0, j=0 ; raw[i] ; i++) {
754 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == ',' || raw[i] == ' ' \
755 || raw[i] == '*' || raw[i] == '#') {
756 trimmed[j++] = raw[i];
757 } else if (raw[i] == '-') {
760 MSG_DEBUG("Unacceptable character in telephone number: [%c]", raw[i]);
761 return MSG_ERR_INVALID_PARAMETER;
765 MSG_DEBUG("Trimming [%s]->[%s]", raw, trimmed);
769 int msg_verify_email(const char *raw)
772 bool atExist = false;
775 MSG_DEBUG("Email is NULL");
776 return MSG_ERR_NULL_POINTER;
779 for (int i = 0; raw[i]; i++) {
784 if (atExist == false) {
788 MSG_DEBUG("Character [@] is included more than twice in email address.");
789 return MSG_ERR_INVALID_PARAMETER;
793 if ((raw[i] >= '0' && raw[i] <= '9') || raw[i] == '+' || raw[i] == '*' || raw[i] == '#') {
795 } else if ((raw[i] >= 'a' && raw[i] <= 'z') ||(raw[i] >= 'A' && raw[i] <= 'Z') ||(raw[i] == '.') || raw[i] == '_' || raw[i] == '-') {
798 } else if (raw[i] == ',') {
799 if (onlyNum == false && atExist == false) {
800 MSG_DEBUG("Unacceptable type in address.");
801 return MSG_ERR_INVALID_PARAMETER;
807 MSG_DEBUG("Unacceptable character in address : [%c]", raw[i]);
808 return MSG_ERR_INVALID_PARAMETER;
816 char* msg_clean_country_code(char *src)
820 switch (src[ret++]-'0')
826 switch (src[ret++]-'0')
842 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
847 switch (src[ret++]-'0')
863 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
868 switch (src[ret++]-'0')
884 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
889 switch (src[ret++]-'0')
905 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
910 switch (src[ret++]-'0')
926 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
931 switch (src[ret++]-'0')
947 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
952 switch (src[ret++]-'0')
968 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
974 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
982 char* msg_normalize_number(char *src)
984 char *normalized_number;
987 normalized_number = msg_clean_country_code(src);
988 else if ('0' == src[0])
989 normalized_number = src+1;
991 normalized_number = src;
993 MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
995 return normalized_number;
999 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
1004 memset(sql, 0x00, sizeof(sql));
1005 memset(order, 0x00, sizeof(order));
1007 if (pSortRule->bAscending == true)
1008 strncpy(order, "ASC", 5);
1010 strncpy(order, "DESC", 5);
1012 //contacts-service is not used for gear
1013 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
1014 int nameOrder = MsgGetContactNameOrder();
1015 #else // MSG_CONTACTS_SERVICE_NOT_SUPPORTED
1017 #endif // MSG_CONTACTS_SERVICE_NOT_SUPPORTED
1019 switch (pSortRule->sortType)
1021 case MSG_SORT_BY_DISPLAY_FROM :
1023 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1025 snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1027 case MSG_SORT_BY_DISPLAY_TO :
1029 snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1031 snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
1033 case MSG_SORT_BY_DISPLAY_TIME :
1034 snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
1036 case MSG_SORT_BY_MSG_TYPE :
1037 snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
1039 case MSG_SORT_BY_READ_STATUS :
1040 snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
1042 case MSG_SORT_BY_STORAGE_TYPE :
1043 snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
1045 case MSG_SORT_BY_THREAD_NAME :
1047 snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
1049 snprintf(sql, sizeof(sql), "ORDER BY LAST_NAME %s, FIRST_NAME %s;", order, order);
1051 case MSG_SORT_BY_THREAD_DATE :
1052 snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
1054 case MSG_SORT_BY_THREAD_COUNT :
1055 snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
1058 snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
1062 memcpy(pSqlSort, sql, strlen(sql));
1066 bool msg_is_valid_email(char *pAddress)
1068 if (!pAddress || pAddress[0] == 0)
1070 if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))