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 "MsgUtilStorage.h"
21 #include "MsgUtilFile.h"
22 #include "MsgGconfWrapper.h"
23 #include "MsgContact.h"
25 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
30 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
32 /*==================================================================================================
34 ==================================================================================================*/
35 __thread bool isContactSvcConnected = false;
37 MsgDbHandler ContactDbHandle;
39 /* phonenumber minimum match digit. */
40 #define PHONENUMBER_MIN_MATCH_DIGIT VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT
41 #define DEFAULT_MIN_MATCH_DIGIT 8
43 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
44 static int phonenumberMinMatchDigit = -1;
47 /*==================================================================================================
48 INTERNAL FUNCTION IMPLEMENTATION
49 ==================================================================================================*/
51 int countryCodeLength(const char *src)
54 switch (src[ret++]-'0') {
59 switch (src[ret++]-'0') {
74 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
78 switch (src[ret++]-'0') {
93 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
97 switch (src[ret++]-'0') {
112 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
116 switch (src[ret++]-'0') {
131 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
135 switch (src[ret++]-'0') {
150 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
154 switch (src[ret++]-'0') {
169 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
173 switch (src[ret++]-'0') {
188 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
193 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
201 void normalizeNumber(const char *orig, char* dest, unsigned int destSize)
203 unsigned int pos = 0;
204 for (unsigned int i = 0; (orig[i] && i < destSize); i++) {
205 if (isdigit(orig[i]) || (orig[i] == '+')) {
206 dest[pos++] = orig[i];
211 /*==================================================================================================
212 FUNCTION IMPLEMENTATION
213 ==================================================================================================*/
214 msg_error_t MsgOpenContactSvc()
216 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
217 int errCode = CONTACTS_ERROR_NONE;
219 if (!isContactSvcConnected) {
220 errCode = contacts_connect();
222 if (errCode == CONTACTS_ERROR_NONE) {
223 MSG_DEBUG("Connect to Contact Service Success");
224 isContactSvcConnected = true;
226 MSG_DEBUG("Connect to Contact Service Fail [%d]", errCode);
227 isContactSvcConnected = false;
228 return MSG_ERR_DB_CONNECT;
231 MSG_DEBUG("Already connected to Contact Service.");
233 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
238 msg_error_t MsgCloseContactSvc()
240 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
241 int errCode = CONTACTS_ERROR_NONE;
243 if (isContactSvcConnected) {
244 errCode = contacts_disconnect();
246 if (errCode == CONTACTS_ERROR_NONE) {
247 MSG_DEBUG("Disconnect to Contact Service Success");
248 isContactSvcConnected = false;
250 MSG_DEBUG("Disconnect to Contact Service Fail [%d]", errCode);
251 return MSG_ERR_DB_DISCONNECT;
254 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
259 msg_error_t MsgInitContactSvc()
261 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
262 phonenumberMinMatchDigit = MsgSettingGetInt(PHONENUMBER_MIN_MATCH_DIGIT);
263 MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
265 if (phonenumberMinMatchDigit < 1) {
266 phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
268 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
273 msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_INFO_S *pContactInfo)
276 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
277 msg_error_t err = MSG_SUCCESS;
279 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
280 MSG_DEBUG("MsgOpenContactSvc fail.");
284 if (!isContactSvcConnected) {
285 MSG_DEBUG("Contact Service Not Opened.");
286 return MSG_ERR_UNKNOWN;
289 MSG_SEC_DEBUG("Address Type [%d], Address Value [%s]", pAddrInfo->addressType, pAddrInfo->addressVal);
291 memset(pContactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
293 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN && strlen(pAddrInfo->addressVal) > (MAX_PHONE_NUMBER_LEN+1)) {
294 MSG_SEC_DEBUG("Phone Number is too long [%s]", pAddrInfo->addressVal);
295 return MSG_ERR_UNKNOWN;
301 contacts_query_h query = NULL;
302 contacts_filter_h filter = NULL;
303 contacts_list_h contacts = NULL;
305 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
306 ret = contacts_query_create(_contacts_contact_number._uri, &query);
307 ret = contacts_filter_create(_contacts_contact_number._uri, &filter);
309 ret = contacts_filter_add_str(filter, _contacts_contact_number.number_filter, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
311 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
312 ret = contacts_query_create(_contacts_contact_email._uri, &query);
313 ret = contacts_filter_create(_contacts_contact_email._uri, &filter);
315 ret = contacts_filter_add_str(filter, _contacts_contact_email.email, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
318 MSG_DEBUG("Invalid pAddrInfo->addressType.");
319 return MSG_ERR_UNKNOWN;
322 ret = contacts_query_set_filter(query, filter);
323 ret = contacts_db_get_records_with_query(query, 0, 1, &contacts);
324 if (ret != CONTACTS_ERROR_NONE) {
325 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
326 contacts_query_destroy(query);
327 contacts_filter_destroy(filter);
328 contacts_list_destroy(contacts, true);
329 return MSG_ERR_UNKNOWN;
332 ret = contacts_list_get_count(contacts, &count);
334 if (count == 0 || ret != CONTACTS_ERROR_NONE) {
335 MSG_DEBUG("No Serach Data from Contact Service.");
336 contacts_query_destroy(query);
337 contacts_filter_destroy(filter);
338 contacts_list_destroy(contacts, true);
342 contacts_query_destroy(query);
343 contacts_filter_destroy(filter);
345 contacts_record_h contact = NULL;
347 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
348 contacts_record_h number = NULL;
350 ret = contacts_list_get_current_record_p(contacts, &number);
351 if (ret != CONTACTS_ERROR_NONE) {
352 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
353 contacts_list_destroy(contacts, true);
354 return MSG_ERR_UNKNOWN;
357 ret = contacts_record_get_int(number, _contacts_contact_number.contact_id, &index);
358 if (ret != CONTACTS_ERROR_NONE) {
359 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
360 contacts_list_destroy(contacts, true);
361 return MSG_ERR_UNKNOWN;
364 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
365 if (ret != CONTACTS_ERROR_NONE) {
366 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
367 contacts_list_destroy(contacts, true);
368 return MSG_ERR_UNKNOWN;
370 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
371 contacts_record_h email = NULL;
373 ret = contacts_list_get_current_record_p(contacts, &email);
374 if (ret != CONTACTS_ERROR_NONE) {
375 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
376 contacts_list_destroy(contacts, true);
377 return MSG_ERR_UNKNOWN;
380 ret = contacts_record_get_int(email, _contacts_contact_email.contact_id, &index);
381 if (ret != CONTACTS_ERROR_NONE) {
382 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
383 contacts_list_destroy(contacts, true);
384 return MSG_ERR_UNKNOWN;
387 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
388 if (ret != CONTACTS_ERROR_NONE) {
389 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
390 contacts_list_destroy(contacts, true);
391 return MSG_ERR_UNKNOWN;
395 contacts_list_destroy(contacts, true);
397 ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&pContactInfo->contactId);
398 if (ret != CONTACTS_ERROR_NONE) {
399 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
400 contacts_record_destroy(contact, true);
401 return MSG_ERR_UNKNOWN;
404 MSG_DEBUG("Contact ID [%d]", pContactInfo->contactId);
406 ret = contacts_record_get_int(contact, _contacts_contact.address_book_id, (int*)&pContactInfo->addrbookId);
407 if (ret != CONTACTS_ERROR_NONE) {
408 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
409 contacts_record_destroy(contact, true);
410 return MSG_ERR_UNKNOWN;
413 MSG_DEBUG("Address Book ID [%d]", pContactInfo->addrbookId);
415 char* strImagePath = NULL;
416 ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
417 if (ret != CONTACTS_ERROR_NONE) {
418 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
420 if (strImagePath != NULL) {
421 strncpy(pContactInfo->imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
422 MSG_DEBUG("Image Path [%s]", pContactInfo->imagePath);
425 char* alerttonePath = NULL;
426 ret = contacts_record_get_str_p(contact, _contacts_contact.message_alert, &alerttonePath);
427 if (ret != CONTACTS_ERROR_NONE) {
428 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
431 if (MsgAccessFile(alerttonePath, F_OK) == false) {
432 alerttonePath = NULL;
435 if (alerttonePath != NULL) {
436 MSG_DEBUG("alert tone Path [%s]", alerttonePath);
437 strncpy(pContactInfo->alerttonePath , alerttonePath, MSG_FILEPATH_LEN_MAX);
439 MSG_DEBUG("alert tone Path for this contact is default");
441 ret = contacts_record_get_child_record_count(contact, _contacts_contact.group_relation, &count);
442 if (ret != CONTACTS_ERROR_NONE) {
443 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
446 contacts_record_h group_relation_record;
448 for (int i = 0; i < count; i++) {
450 contacts_record_get_child_record_at_p(contact, _contacts_contact.group_relation, i, &group_relation_record);
451 contacts_record_get_int(group_relation_record, _contacts_group_relation.group_id, &group_id);
453 contacts_record_h group_record;
454 contacts_db_get_record(_contacts_group._uri, group_id, &group_record);
456 MSG_DEBUG("Group ID = [%d]", group_id);
458 char *group_ringtone_path;
459 ret = contacts_record_get_str_p(group_record, _contacts_group.message_alert, &group_ringtone_path);
460 if (ret != CONTACTS_ERROR_NONE) {
461 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
463 if (group_ringtone_path) {
464 MSG_DEBUG("Msg alert_tone is change to [%s] as contact group", group_ringtone_path);
465 memset(pContactInfo->alerttonePath, 0x00, sizeof(pContactInfo->alerttonePath));
466 snprintf(pContactInfo->alerttonePath, sizeof(pContactInfo->alerttonePath), "%s", group_ringtone_path);
467 contacts_record_destroy(group_record, true);
471 contacts_record_destroy(group_record, true);
475 char* vibrationPath = NULL;
476 ret = contacts_record_get_str_p(contact, _contacts_contact.vibration, &vibrationPath);
477 if (ret != CONTACTS_ERROR_NONE) {
478 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
480 if (vibrationPath != NULL) {
481 MSG_DEBUG("vibration Path [%s]", vibrationPath);
482 strncpy(pContactInfo->vibrationPath , vibrationPath, MSG_FILEPATH_LEN_MAX);
485 char* displayName = NULL;
486 ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &displayName);
487 if (ret != CONTACTS_ERROR_NONE) {
488 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
490 if (displayName != NULL) {
491 MSG_DEBUG("displayName [%s]", displayName);
492 strncpy(pContactInfo->firstName , displayName, MAX_DISPLAY_NAME_LEN);
495 contacts_record_destroy(contact, true);
497 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
504 msg_error_t MsgGetContactSearchList(const char *pSearchVal, MSG_ADDRESS_INFO_S **pAddrInfo, int *count)
507 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
509 msg_error_t err = MSG_SUCCESS;
513 if (pSearchVal == NULL) {
514 MSG_DEBUG("pSearchVal is NULL.");
515 return MSG_ERR_NULL_POINTER;
518 if (pAddrInfo == NULL) {
519 MSG_DEBUG("pAddrInfo is NULL.");
520 return MSG_ERR_NULL_POINTER;
523 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
524 MSG_DEBUG("MsgOpenContactSvc fail.");
528 if (!isContactSvcConnected) {
529 MSG_DEBUG("Contact Service Not Opened.");
530 return MSG_ERR_UNKNOWN;
533 MSG_SEC_DEBUG("pSearchVal [%s]", pSearchVal);
536 unsigned int index = 0;
537 contacts_query_h query = NULL;
538 contacts_filter_h filter = NULL;
539 contacts_list_h personNumbers = NULL;
541 ret = contacts_query_create(_contacts_person_number._uri, &query);
542 ret = contacts_filter_create(_contacts_person_number._uri, &filter);
544 ret = contacts_filter_add_str(filter, _contacts_person_number.display_name, CONTACTS_MATCH_CONTAINS, pSearchVal);
545 ret = contacts_query_set_filter(query, filter);
547 ret = contacts_db_get_records_with_query(query, 0, 0, &personNumbers);
548 if (ret != CONTACTS_ERROR_NONE) {
549 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
550 contacts_query_destroy(query);
551 contacts_filter_destroy(filter);
552 contacts_list_destroy(personNumbers, true);
553 return MSG_ERR_UNKNOWN;
556 ret = contacts_list_get_count(personNumbers, count);
557 if (*count == 0 || ret != CONTACTS_ERROR_NONE) {
558 MSG_DEBUG("No Serach Data from Contact Service.");
560 contacts_query_destroy(query);
561 contacts_filter_destroy(filter);
562 contacts_list_destroy(personNumbers, true);
566 contacts_query_destroy(query);
567 contacts_filter_destroy(filter);
569 MSG_DEBUG(" *count [%d]", *count);
571 *pAddrInfo = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * (*count)];
572 memset(*pAddrInfo, 0x00, (sizeof(MSG_ADDRESS_INFO_S) * (*count)));
574 contacts_record_h personNumber = NULL;
576 while (CONTACTS_ERROR_NONE == contacts_list_get_current_record_p(personNumbers, &personNumber)) {
577 char* normalizedNumber = NULL;
578 ret = contacts_record_get_str(personNumber, _contacts_person_number.normalized_number, &normalizedNumber);
579 if (ret != CONTACTS_ERROR_NONE) {
580 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
582 else if (normalizedNumber) {
583 MSG_DEBUG("normalizedNumber [%s]", normalizedNumber);
584 strncpy((*pAddrInfo)[index].addressVal, normalizedNumber, MAX_ADDRESS_VAL_LEN);
587 contacts_list_next(personNumbers);
591 contacts_list_destroy(personNumbers, true);
593 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
600 int MsgGetContactNameOrder()
602 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
603 contacts_name_display_order_e order = CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST;
608 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
612 msg_error_t MsgGetContactStyleDisplayName(const char *first, const char *last, const char *middle, const char *prefix, const char *suffix, int contactNameOrder, char *displayName, unsigned int size)
614 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
616 if (first == NULL || last == NULL || middle == NULL || prefix == NULL || suffix == NULL || displayName == NULL || size ==0) {
617 MSG_DEBUG("Invalid parameter.");
618 return MSG_ERR_INVALID_PARAMETER;
621 if (contactNameOrder == CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST) {
622 if (strlen(prefix) > 0) {
623 strncpy(displayName, prefix, size);
626 if (strlen(first) > 0) {
627 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
628 strncat(displayName, first, size-strlen(displayName));
631 if (strlen(middle) > 0) {
632 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
634 strncat(displayName, middle, size-strlen(displayName));
637 if (strlen(last) > 0) {
638 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
639 strncat(displayName, last, size-strlen(displayName));
642 if (strlen(suffix) > 0) {
643 if (strlen(displayName) > 0) strncat(displayName, ", ", size-strlen(displayName));
644 strncat(displayName, suffix, size-strlen(displayName));
647 if (strlen(prefix) > 0) {
648 strncpy(displayName, prefix, size);
651 if (strlen(last) > 0) {
652 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
653 strncat(displayName, last, size-strlen(displayName));
655 if (strlen(first) > 0 || strlen(middle) > 0 || strlen(suffix) > 0)
656 strncat(displayName, ",", size-strlen(displayName));
659 if (strlen(first) > 0) {
660 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
661 strncat(displayName, first, size-strlen(displayName));
664 if (strlen(middle) > 0) {
665 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
666 strncat(displayName, middle, size-strlen(displayName));
669 if (strlen(suffix) > 0) {
670 if (strlen(displayName) > 0) strncat(displayName, ", ", size-strlen(displayName));
671 strncat(displayName, suffix, size-strlen(displayName));
675 MSG_SEC_DEBUG("displayName [%s]", displayName);
677 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
682 void MsgAddPhoneLog(const MSG_MESSAGE_INFO_S *pMsgInfo)
684 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
686 msg_error_t err = MSG_SUCCESS;
688 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
689 MSG_DEBUG("MsgOpenContactSvc fail.");
693 if (!isContactSvcConnected) {
694 MSG_DEBUG("Contact Service Not Opened.");
698 if (pMsgInfo->nAddressCnt < 1) {
699 MSG_DEBUG("address count is [%d]", pMsgInfo->nAddressCnt);
703 for (int i = 0; pMsgInfo->nAddressCnt > i; i++) {
705 contacts_record_h plog = NULL;
707 ret = contacts_record_create(_contacts_phone_log._uri, &plog);
708 if (ret != CONTACTS_ERROR_NONE) {
709 MSG_DEBUG("contacts_record_create() Error [%d]", ret);
710 contacts_record_destroy(plog, true);
714 contacts_record_set_int(plog, _contacts_phone_log.sim_slot_no, (int)pMsgInfo->sim_idx-1);
715 contacts_record_set_str(plog, _contacts_phone_log.address, (char*)pMsgInfo->addressList[i].addressVal);
716 contacts_record_set_int(plog, _contacts_phone_log.log_time, (int)time(NULL));
719 memset(strText, 0x00, sizeof(strText));
721 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
722 strncpy(strText, pMsgInfo->msgText, 100);
723 MSG_SEC_DEBUG("msgText : %s", strText);
724 } else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
725 if (strlen(pMsgInfo->subject) > 0 || pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
726 strncpy(strText, pMsgInfo->subject, 100);
727 MSG_SEC_DEBUG("subject : %s", strText);
729 char *pFileData = NULL;
732 if (pMsgInfo->msgText[0] != '\0' && g_file_get_contents(pMsgInfo->msgText, &pFileData, &fileSize, NULL) == true) {
734 strncpy(strText, pFileData, 100);
740 MSG_SEC_DEBUG("msgText : %s", strText);
744 contacts_record_set_str(plog, _contacts_phone_log.extra_data2, strText);
745 contacts_record_set_int(plog, _contacts_phone_log.extra_data1, (int)pMsgInfo->msgId);
747 if (pMsgInfo->folderId == MSG_INBOX_ID) {
748 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
749 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_INCOMING);
750 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
751 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_INCOMING);
752 } else if (pMsgInfo->folderId == MSG_OUTBOX_ID) {
753 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
754 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_OUTGOING);
755 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
756 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_OUTGOING);
757 } else if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
758 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
759 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_BLOCKED);
760 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
761 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
764 ret = contacts_db_insert_record(plog, NULL);
765 if (ret != CONTACTS_ERROR_NONE) {
766 MSG_DEBUG("contacts_db_insert_record() Error [%d]", ret);
769 contacts_record_destroy(plog, true);
771 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
775 void MsgDeletePhoneLog(msg_message_id_t msgId)
777 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
778 msg_error_t err = MSG_SUCCESS;
780 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
781 MSG_DEBUG("MsgOpenContactSvc fail.");
785 MSG_DEBUG("MsgDeletePhoneLog [%d]", msgId);
787 if (!isContactSvcConnected) {
788 MSG_DEBUG("Contact Service Not Opened.");
792 int ret = CONTACTS_ERROR_NONE;
795 contacts_query_h query;
796 contacts_filter_h filter;
797 contacts_list_h plogs = NULL;
799 ret = contacts_query_create(_contacts_phone_log._uri, &query);
800 ret = contacts_filter_create(_contacts_phone_log._uri, &filter);
802 ret = contacts_filter_add_int(filter, _contacts_phone_log.extra_data1, CONTACTS_MATCH_EQUAL, (int)msgId);
805 ret = contacts_query_set_filter(query, filter);
806 ret = contacts_db_get_records_with_query(query, 0, 1, &plogs);
808 ret = contacts_list_get_count(plogs, &count);
811 MSG_DEBUG("No Serach Data from Contact Service.");
813 contacts_record_h plog = NULL;
815 ret = contacts_list_get_current_record_p(plogs, &plog);
816 if (ret != CONTACTS_ERROR_NONE) {
817 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
820 ret = contacts_record_get_int(plog, _contacts_phone_log.id, &index);
821 if (ret != CONTACTS_ERROR_NONE) {
822 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
825 ret = contacts_db_delete_record(_contacts_phone_log._uri, index);
826 if (ret != CONTACTS_ERROR_NONE) {
827 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
829 MSG_DEBUG("contacts_db_delete_record() Success.");
833 contacts_query_destroy(query);
834 contacts_filter_destroy(filter);
835 contacts_list_destroy(plogs, true);
836 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
840 bool checkBlockingMode(char *address, bool *pisFavorites)
843 msg_error_t err = MSG_SUCCESS;
845 if (pisFavorites != NULL) *pisFavorites = false;
847 bool isBlockModeOn = false;
850 MsgSettingGetBool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &isBlockModeOn);
852 int blockModeType = -1;
854 blockModeType = MsgSettingGetInt(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE);
858 else if (blockModeType < 0)
862 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
863 MSG_DEBUG("MsgOpenContactSvc fail.");
867 if (!isContactSvcConnected) {
868 MSG_DEBUG("Contact Service Not Opened.");
872 MSG_SEC_DEBUG("Address Value [%s]", address);
874 if (strlen(address) > (MAX_PHONE_NUMBER_LEN+1)) {
875 MSG_SEC_DEBUG("Phone Number is too long [%s]", address);
881 bool isFavorites = false;
883 contacts_query_h query = NULL;
884 contacts_filter_h filter = NULL;
885 contacts_list_h personList = NULL;
887 ret = contacts_query_create(_contacts_person_number._uri, &query);
888 ret = contacts_filter_create(_contacts_person_number._uri, &filter);
890 ret = contacts_filter_add_str(filter, _contacts_person_number.number_filter, CONTACTS_MATCH_EXACTLY, address);
892 ret = contacts_query_set_filter(query, filter);
893 ret = contacts_db_get_records_with_query(query, 0, 1, &personList);
895 contacts_query_destroy(query);
896 contacts_filter_destroy(filter);
898 if (ret != CONTACTS_ERROR_NONE) {
899 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
900 contacts_list_destroy(personList, true);
904 ret = contacts_list_get_count(personList, &count);
906 if (count == 0 || ret != CONTACTS_ERROR_NONE) {
907 MSG_DEBUG("No Serach Data from Contact Service.");
908 contacts_list_destroy(personList, true);
910 } else if (ret == CONTACTS_ERROR_NONE && count > 0
911 && blockModeType == 1) { /* For All contacts allow in blocking mode. */
915 contacts_record_h person = NULL;
917 ret = contacts_list_get_current_record_p(personList, &person);
918 if (ret != CONTACTS_ERROR_NONE) {
919 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
920 contacts_list_destroy(personList, true);
924 ret = contacts_record_get_int(person, _contacts_person_number.person_id, &personId);
925 if (ret != CONTACTS_ERROR_NONE) {
926 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
927 contacts_list_destroy(personList, true);
931 MSG_DEBUG("personId [%d]", personId);
933 ret = contacts_record_get_bool(person, _contacts_person_number.is_favorite, &isFavorites);
934 if (ret != CONTACTS_ERROR_NONE) {
935 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
936 contacts_list_destroy(personList, true);
940 contacts_list_destroy(personList, true);
942 switch (blockModeType) {
943 case 2: { /* For Favorites allow in blocking mode. */
944 if (isFavorites) isblock = false;
947 case 3: { /* For Custom allow in blocking mode. */
948 char *allowList = MsgSettingGetString(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_LIST);
950 char *personIdStr = strtok_r(allowList, " ,", &temp);
951 while (personIdStr != NULL) {
952 MSG_DEBUG("personIdStr [%s]", personIdStr);
953 if (personId == atoi(personIdStr)) {
954 MSG_DEBUG("In allow list.");
958 personIdStr = strtok_r(NULL, " ,", &temp);
968 default: /* Wrong blocking mode type. */
972 if (pisFavorites != NULL) *pisFavorites = isFavorites;
976 if (pisFavorites != NULL)
977 *pisFavorites = false;
983 int MsgContactGetMinMatchDigit()
985 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
986 return phonenumberMinMatchDigit;
988 return DEFAULT_MIN_MATCH_DIGIT;
993 void MsgConvertNumber(const char* pSrcNum, char* pDestNum, int destSize)
996 const char *temp_number;
998 if ('+' == pSrcNum[0]) {
999 len = countryCodeLength(&pSrcNum[1]);
1000 temp_number = pSrcNum + len +1;
1001 } else if ('0' == pSrcNum[0]) {
1002 if ('0' == pSrcNum[1]) {
1003 len = countryCodeLength(&pSrcNum[2]);
1004 temp_number = pSrcNum + len +2;
1006 temp_number = pSrcNum+1;
1009 temp_number = pSrcNum;
1012 strncpy(pDestNum, temp_number, destSize);
1016 bool MsgIsNumber(const char* pSrc)
1018 int len = strlen(pSrc);
1020 for (int i = 0; i < len; ++i) {
1021 if (i == 0 && pSrc[i] == '+')
1024 if (pSrc[i] < '0' || pSrc[i] > '9') {