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"
30 /*==================================================================================================
32 ==================================================================================================*/
33 __thread bool isContactSvcConnected = false;
35 MsgDbHandler ContactDbHandle;
37 /* phonenumber minimum match digit. */
38 #define PHONENUMBER_MIN_MATCH_DIGIT VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT
39 #define DEFAULT_MIN_MATCH_DIGIT 8
41 static int phonenumberMinMatchDigit = -1;
43 /*==================================================================================================
44 INTERNAL FUNCTION IMPLEMENTATION
45 ==================================================================================================*/
46 int countryCodeLength(const char *src)
49 switch (src[ret++]-'0') {
54 switch (src[ret++]-'0') {
69 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
73 switch (src[ret++]-'0') {
88 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
92 switch (src[ret++]-'0') {
107 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
111 switch (src[ret++]-'0') {
126 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
130 switch (src[ret++]-'0') {
145 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
149 switch (src[ret++]-'0') {
164 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
168 switch (src[ret++]-'0') {
183 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
188 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
196 void normalizeNumber(const char *orig, char* dest, unsigned int destSize)
198 unsigned int pos = 0;
199 for (unsigned int i = 0; (orig[i] && i < destSize); i++) {
200 if (isdigit(orig[i]) || (orig[i] == '+')) {
201 dest[pos++] = orig[i];
207 /*==================================================================================================
208 FUNCTION IMPLEMENTATION
209 ==================================================================================================*/
210 msg_error_t MsgOpenContactSvc()
212 int errCode = CONTACTS_ERROR_NONE;
214 if (!isContactSvcConnected) {
215 errCode = contacts_connect();
217 if (errCode == CONTACTS_ERROR_NONE) {
218 MSG_DEBUG("Connect to Contact Service Success");
219 isContactSvcConnected = true;
221 MSG_DEBUG("Connect to Contact Service Fail [%d]", errCode);
222 isContactSvcConnected = false;
223 return MSG_ERR_DB_CONNECT;
226 MSG_DEBUG("Already connected to Contact Service.");
233 msg_error_t MsgCloseContactSvc()
235 int errCode = CONTACTS_ERROR_NONE;
237 if (isContactSvcConnected) {
238 errCode = contacts_disconnect();
240 if (errCode == CONTACTS_ERROR_NONE) {
241 MSG_DEBUG("Disconnect to Contact Service Success");
242 isContactSvcConnected = false;
244 MSG_DEBUG("Disconnect to Contact Service Fail [%d]", errCode);
245 return MSG_ERR_DB_DISCONNECT;
253 msg_error_t MsgInitContactSvc()
255 phonenumberMinMatchDigit = MsgSettingGetInt(PHONENUMBER_MIN_MATCH_DIGIT);
256 MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
258 if (phonenumberMinMatchDigit < 1) {
259 phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
266 msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_INFO_S *pContactInfo)
270 msg_error_t err = MSG_SUCCESS;
272 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
273 MSG_DEBUG("MsgOpenContactSvc fail.");
277 if (!isContactSvcConnected) {
278 MSG_DEBUG("Contact Service Not Opened.");
279 return MSG_ERR_UNKNOWN;
282 MSG_SEC_DEBUG("Address Type [%d], Address Value [%s]", pAddrInfo->addressType, pAddrInfo->addressVal);
284 memset(pContactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
286 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN && strlen(pAddrInfo->addressVal) > (MAX_PHONE_NUMBER_LEN+1)) {
287 MSG_SEC_DEBUG("Phone Number is too long [%s]", pAddrInfo->addressVal);
288 return MSG_ERR_UNKNOWN;
294 contacts_query_h query = NULL;
295 contacts_filter_h filter = NULL;
296 contacts_list_h contacts = NULL;
298 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
299 ret = contacts_query_create(_contacts_contact_number._uri, &query);
300 ret = contacts_filter_create(_contacts_contact_number._uri, &filter);
302 ret = contacts_filter_add_str(filter, _contacts_contact_number.number_filter, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
304 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
305 ret = contacts_query_create(_contacts_contact_email._uri, &query);
306 ret = contacts_filter_create(_contacts_contact_email._uri, &filter);
308 ret = contacts_filter_add_str(filter, _contacts_contact_email.email, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
311 MSG_DEBUG("Invalid pAddrInfo->addressType.");
312 return MSG_ERR_UNKNOWN;
315 ret = contacts_query_set_filter(query, filter);
316 ret = contacts_db_get_records_with_query(query, 0, 1, &contacts);
317 if (ret != CONTACTS_ERROR_NONE) {
318 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
319 contacts_query_destroy(query);
320 contacts_filter_destroy(filter);
321 contacts_list_destroy(contacts, true);
322 return MSG_ERR_UNKNOWN;
325 ret = contacts_list_get_count(contacts, &count);
327 if (count == 0 || ret != CONTACTS_ERROR_NONE) {
328 MSG_DEBUG("No Serach Data from Contact Service.");
329 contacts_query_destroy(query);
330 contacts_filter_destroy(filter);
331 contacts_list_destroy(contacts, true);
335 contacts_query_destroy(query);
336 contacts_filter_destroy(filter);
338 contacts_record_h contact = NULL;
340 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
341 contacts_record_h number = NULL;
343 ret = contacts_list_get_current_record_p(contacts, &number);
344 if (ret != CONTACTS_ERROR_NONE) {
345 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
346 contacts_list_destroy(contacts, true);
347 return MSG_ERR_UNKNOWN;
350 ret = contacts_record_get_int(number, _contacts_contact_number.contact_id, &index);
351 if (ret != CONTACTS_ERROR_NONE) {
352 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
353 contacts_list_destroy(contacts, true);
354 return MSG_ERR_UNKNOWN;
357 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
358 if (ret != CONTACTS_ERROR_NONE) {
359 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
360 contacts_list_destroy(contacts, true);
361 return MSG_ERR_UNKNOWN;
363 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
364 contacts_record_h email = NULL;
366 ret = contacts_list_get_current_record_p(contacts, &email);
367 if (ret != CONTACTS_ERROR_NONE) {
368 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
369 contacts_list_destroy(contacts, true);
370 return MSG_ERR_UNKNOWN;
373 ret = contacts_record_get_int(email, _contacts_contact_email.contact_id, &index);
374 if (ret != CONTACTS_ERROR_NONE) {
375 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
376 contacts_list_destroy(contacts, true);
377 return MSG_ERR_UNKNOWN;
380 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
381 if (ret != CONTACTS_ERROR_NONE) {
382 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
383 contacts_list_destroy(contacts, true);
384 return MSG_ERR_UNKNOWN;
388 contacts_list_destroy(contacts, true);
390 ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&pContactInfo->contactId);
391 if (ret != CONTACTS_ERROR_NONE) {
392 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
393 contacts_record_destroy(contact, true);
394 return MSG_ERR_UNKNOWN;
397 MSG_DEBUG("Contact ID [%d]", pContactInfo->contactId);
399 ret = contacts_record_get_int(contact, _contacts_contact.address_book_id, (int*)&pContactInfo->addrbookId);
400 if (ret != CONTACTS_ERROR_NONE) {
401 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
402 contacts_record_destroy(contact, true);
403 return MSG_ERR_UNKNOWN;
406 MSG_DEBUG("Address Book ID [%d]", pContactInfo->addrbookId);
408 char* strImagePath = NULL;
409 ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
410 if (ret != CONTACTS_ERROR_NONE) {
411 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
413 if (strImagePath != NULL) {
414 strncpy(pContactInfo->imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
415 MSG_DEBUG("Image Path [%s]", pContactInfo->imagePath);
418 char* alerttonePath = NULL;
419 ret = contacts_record_get_str_p(contact, _contacts_contact.message_alert, &alerttonePath);
420 if (ret != CONTACTS_ERROR_NONE) {
421 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
424 if (MsgAccessFile(alerttonePath, F_OK) == false) {
425 alerttonePath = NULL;
428 if (alerttonePath != NULL) {
429 MSG_DEBUG("alert tone Path [%s]", alerttonePath);
430 strncpy(pContactInfo->alerttonePath , alerttonePath, MSG_FILEPATH_LEN_MAX);
432 MSG_DEBUG("alert tone Path for this contact is default");
434 ret = contacts_record_get_child_record_count(contact, _contacts_contact.group_relation, &count);
435 if (ret != CONTACTS_ERROR_NONE) {
436 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
439 contacts_record_h group_relation_record;
441 for (int i = 0; i < count; i++) {
443 contacts_record_get_child_record_at_p(contact, _contacts_contact.group_relation, i, &group_relation_record);
444 contacts_record_get_int(group_relation_record, _contacts_group_relation.group_id, &group_id);
446 contacts_record_h group_record;
447 contacts_db_get_record(_contacts_group._uri, group_id, &group_record);
449 MSG_DEBUG("Group ID = [%d]", group_id);
451 char *group_ringtone_path;
452 ret = contacts_record_get_str_p(group_record, _contacts_group.message_alert, &group_ringtone_path);
453 if (ret != CONTACTS_ERROR_NONE) {
454 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
456 if (group_ringtone_path) {
457 MSG_DEBUG("Msg alert_tone is change to [%s] as contact group", group_ringtone_path);
458 memset(pContactInfo->alerttonePath, 0x00, sizeof(pContactInfo->alerttonePath));
459 snprintf(pContactInfo->alerttonePath, sizeof(pContactInfo->alerttonePath), "%s", group_ringtone_path);
460 contacts_record_destroy(group_record, true);
464 contacts_record_destroy(group_record, true);
468 char* vibrationPath = NULL;
469 ret = contacts_record_get_str_p(contact, _contacts_contact.vibration, &vibrationPath);
470 if (ret != CONTACTS_ERROR_NONE) {
471 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
473 if (vibrationPath != NULL) {
474 MSG_DEBUG("vibration Path [%s]", vibrationPath);
475 strncpy(pContactInfo->vibrationPath , vibrationPath, MSG_FILEPATH_LEN_MAX);
478 char* displayName = NULL;
479 ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &displayName);
480 if (ret != CONTACTS_ERROR_NONE) {
481 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
483 if (displayName != NULL) {
484 MSG_DEBUG("displayName [%s]", displayName);
485 strncpy(pContactInfo->firstName , displayName, MAX_DISPLAY_NAME_LEN);
488 contacts_record_destroy(contact, true);
496 msg_error_t MsgGetContactSearchList(const char *pSearchVal, MSG_ADDRESS_INFO_S **pAddrInfo, int *count)
500 msg_error_t err = MSG_SUCCESS;
504 if (pSearchVal == NULL) {
505 MSG_DEBUG("pSearchVal is NULL.");
506 return MSG_ERR_NULL_POINTER;
509 if (pAddrInfo == NULL) {
510 MSG_DEBUG("pAddrInfo is NULL.");
511 return MSG_ERR_NULL_POINTER;
514 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
515 MSG_DEBUG("MsgOpenContactSvc fail.");
519 if (!isContactSvcConnected) {
520 MSG_DEBUG("Contact Service Not Opened.");
521 return MSG_ERR_UNKNOWN;
524 MSG_SEC_DEBUG("pSearchVal [%s]", pSearchVal);
527 unsigned int index = 0;
528 contacts_query_h query = NULL;
529 contacts_filter_h filter = NULL;
530 contacts_list_h personNumbers = NULL;
532 ret = contacts_query_create(_contacts_person_number._uri, &query);
533 ret = contacts_filter_create(_contacts_person_number._uri, &filter);
535 ret = contacts_filter_add_str(filter, _contacts_person_number.display_name, CONTACTS_MATCH_CONTAINS, pSearchVal);
536 ret = contacts_query_set_filter(query, filter);
538 ret = contacts_db_get_records_with_query(query, 0, 0, &personNumbers);
539 if (ret != CONTACTS_ERROR_NONE) {
540 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
541 contacts_query_destroy(query);
542 contacts_filter_destroy(filter);
543 contacts_list_destroy(personNumbers, true);
544 return MSG_ERR_UNKNOWN;
547 ret = contacts_list_get_count(personNumbers, count);
548 if (*count == 0 || ret != CONTACTS_ERROR_NONE) {
549 MSG_DEBUG("No Serach Data from Contact Service.");
551 contacts_query_destroy(query);
552 contacts_filter_destroy(filter);
553 contacts_list_destroy(personNumbers, true);
557 contacts_query_destroy(query);
558 contacts_filter_destroy(filter);
560 MSG_DEBUG(" *count [%d]", *count);
562 *pAddrInfo = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * (*count)];
563 memset(*pAddrInfo, 0x00, (sizeof(MSG_ADDRESS_INFO_S) * (*count)));
565 contacts_record_h personNumber = NULL;
567 while (CONTACTS_ERROR_NONE == contacts_list_get_current_record_p(personNumbers, &personNumber)) {
568 char* normalizedNumber = NULL;
569 ret = contacts_record_get_str(personNumber, _contacts_person_number.normalized_number, &normalizedNumber);
570 if (ret != CONTACTS_ERROR_NONE) {
571 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
573 else if (normalizedNumber) {
574 MSG_DEBUG("normalizedNumber [%s]", normalizedNumber);
575 strncpy((*pAddrInfo)[index].addressVal, normalizedNumber, MAX_ADDRESS_VAL_LEN);
578 contacts_list_next(personNumbers);
582 contacts_list_destroy(personNumbers, true);
590 int MsgGetContactNameOrder()
592 contacts_name_display_order_e order = CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST;
598 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)
600 if (first == NULL || last == NULL || middle == NULL || prefix == NULL || suffix == NULL || displayName == NULL || size ==0) {
601 MSG_DEBUG("Invalid parameter.");
602 return MSG_ERR_INVALID_PARAMETER;
605 if (contactNameOrder == CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST) {
606 if (strlen(prefix) > 0) {
607 strncpy(displayName, prefix, size);
610 if (strlen(first) > 0) {
611 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
612 strncat(displayName, first, size-strlen(displayName));
615 if (strlen(middle) > 0) {
616 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
618 strncat(displayName, middle, size-strlen(displayName));
621 if (strlen(last) > 0) {
622 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
623 strncat(displayName, last, size-strlen(displayName));
626 if (strlen(suffix) > 0) {
627 if (strlen(displayName) > 0) strncat(displayName, ", ", size-strlen(displayName));
628 strncat(displayName, suffix, size-strlen(displayName));
631 if (strlen(prefix) > 0) {
632 strncpy(displayName, prefix, size);
635 if (strlen(last) > 0) {
636 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
637 strncat(displayName, last, size-strlen(displayName));
639 if (strlen(first) > 0 || strlen(middle) > 0 || strlen(suffix) > 0)
640 strncat(displayName, ",", size-strlen(displayName));
643 if (strlen(first) > 0) {
644 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
645 strncat(displayName, first, size-strlen(displayName));
648 if (strlen(middle) > 0) {
649 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
650 strncat(displayName, middle, size-strlen(displayName));
653 if (strlen(suffix) > 0) {
654 if (strlen(displayName) > 0) strncat(displayName, ", ", size-strlen(displayName));
655 strncat(displayName, suffix, size-strlen(displayName));
659 MSG_SEC_DEBUG("displayName [%s]", displayName);
665 void MsgAddPhoneLog(const MSG_MESSAGE_INFO_S *pMsgInfo)
667 msg_error_t err = MSG_SUCCESS;
669 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
670 MSG_DEBUG("MsgOpenContactSvc fail.");
674 if (!isContactSvcConnected) {
675 MSG_DEBUG("Contact Service Not Opened.");
679 if (pMsgInfo->nAddressCnt < 1) {
680 MSG_DEBUG("address count is [%d]", pMsgInfo->nAddressCnt);
684 for (int i = 0; pMsgInfo->nAddressCnt > i; i++) {
686 contacts_record_h plog = NULL;
688 ret = contacts_record_create(_contacts_phone_log._uri, &plog);
689 if (ret != CONTACTS_ERROR_NONE) {
690 MSG_DEBUG("contacts_record_create() Error [%d]", ret);
691 contacts_record_destroy(plog, true);
695 contacts_record_set_str(plog, _contacts_phone_log.address, (char*)pMsgInfo->addressList[i].addressVal);
696 contacts_record_set_int(plog, _contacts_phone_log.log_time, (int)time(NULL));
699 memset(strText, 0x00, sizeof(strText));
701 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
702 strncpy(strText, pMsgInfo->msgText, 100);
703 MSG_SEC_DEBUG("msgText : %s", strText);
704 } else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
705 if (strlen(pMsgInfo->subject) > 0 || pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
706 strncpy(strText, pMsgInfo->subject, 100);
707 MSG_SEC_DEBUG("subject : %s", strText);
709 char *pFileData = NULL;
712 if (pMsgInfo->msgText[0] != '\0' && g_file_get_contents(pMsgInfo->msgText, &pFileData, &fileSize, NULL) == true) {
714 strncpy(strText, pFileData, 100);
720 MSG_SEC_DEBUG("msgText : %s", strText);
724 contacts_record_set_str(plog, _contacts_phone_log.extra_data2, strText);
725 contacts_record_set_int(plog, _contacts_phone_log.extra_data1, (int)pMsgInfo->msgId);
727 if (pMsgInfo->folderId == MSG_INBOX_ID) {
728 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
729 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_INCOMMING);
730 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
731 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_INCOMMING);
732 } else if (pMsgInfo->folderId == MSG_OUTBOX_ID) {
733 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
734 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_OUTGOING);
735 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
736 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_OUTGOING);
737 } else if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
738 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
739 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_BLOCKED);
740 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
741 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
744 ret = contacts_db_insert_record(plog, NULL);
745 if (ret != CONTACTS_ERROR_NONE) {
746 MSG_DEBUG("contacts_db_insert_record() Error [%d]", ret);
749 contacts_record_destroy(plog, true);
754 void MsgDeletePhoneLog(msg_message_id_t msgId)
756 msg_error_t err = MSG_SUCCESS;
758 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
759 MSG_DEBUG("MsgOpenContactSvc fail.");
763 MSG_DEBUG("MsgDeletePhoneLog [%d]", msgId);
765 if (!isContactSvcConnected) {
766 MSG_DEBUG("Contact Service Not Opened.");
770 int ret = CONTACTS_ERROR_NONE;
773 contacts_query_h query;
774 contacts_filter_h filter;
775 contacts_list_h plogs = NULL;
777 ret = contacts_query_create(_contacts_phone_log._uri, &query);
778 ret = contacts_filter_create(_contacts_phone_log._uri, &filter);
780 ret = contacts_filter_add_int(filter, _contacts_phone_log.extra_data1, CONTACTS_MATCH_EQUAL, (int)msgId);
783 ret = contacts_query_set_filter(query, filter);
784 ret = contacts_db_get_records_with_query(query, 0, 1, &plogs);
786 ret = contacts_list_get_count(plogs, &count);
789 MSG_DEBUG("No Serach Data from Contact Service.");
791 contacts_record_h plog = NULL;
793 ret = contacts_list_get_current_record_p(plogs, &plog);
794 if (ret != CONTACTS_ERROR_NONE) {
795 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
798 ret = contacts_record_get_int(plog, _contacts_phone_log.id, &index);
799 if (ret != CONTACTS_ERROR_NONE) {
800 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
803 ret = contacts_db_delete_record(_contacts_phone_log._uri, index);
804 if (ret != CONTACTS_ERROR_NONE) {
805 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
807 MSG_DEBUG("contacts_db_delete_record() Success.");
811 contacts_query_destroy(query);
812 contacts_filter_destroy(filter);
813 contacts_list_destroy(plogs, true);
817 bool checkBlockingMode(char *address, bool *pisFavorites)
820 msg_error_t err = MSG_SUCCESS;
822 if (pisFavorites != NULL) *pisFavorites = false;
824 bool isBlockModeOn = false;
827 MsgSettingGetBool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &isBlockModeOn);
829 int blockModeType = -1;
831 blockModeType = MsgSettingGetInt(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE);
835 else if (blockModeType < 0)
839 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
840 MSG_DEBUG("MsgOpenContactSvc fail.");
844 if (!isContactSvcConnected) {
845 MSG_DEBUG("Contact Service Not Opened.");
849 MSG_SEC_DEBUG("Address Value [%s]", address);
851 if (strlen(address) > (MAX_PHONE_NUMBER_LEN+1)) {
852 MSG_SEC_DEBUG("Phone Number is too long [%s]", address);
858 bool isFavorites = false;
860 contacts_query_h query = NULL;
861 contacts_filter_h filter = NULL;
862 contacts_list_h personList = NULL;
864 ret = contacts_query_create(_contacts_person_number._uri, &query);
865 ret = contacts_filter_create(_contacts_person_number._uri, &filter);
867 ret = contacts_filter_add_str(filter, _contacts_person_number.number_filter, CONTACTS_MATCH_EXACTLY, address);
869 ret = contacts_query_set_filter(query, filter);
870 ret = contacts_db_get_records_with_query(query, 0, 1, &personList);
872 contacts_query_destroy(query);
873 contacts_filter_destroy(filter);
875 if (ret != CONTACTS_ERROR_NONE) {
876 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
877 contacts_list_destroy(personList, true);
881 ret = contacts_list_get_count(personList, &count);
883 if (count == 0 || ret != CONTACTS_ERROR_NONE) {
884 MSG_DEBUG("No Serach Data from Contact Service.");
885 contacts_list_destroy(personList, true);
887 } else if (ret == CONTACTS_ERROR_NONE && count > 0
888 && blockModeType == 1) { /* For All contacts allow in blocking mode. */
892 contacts_record_h person = NULL;
894 ret = contacts_list_get_current_record_p(personList, &person);
895 if (ret != CONTACTS_ERROR_NONE) {
896 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
897 contacts_list_destroy(personList, true);
901 ret = contacts_record_get_int(person, _contacts_person_number.person_id, &personId);
902 if (ret != CONTACTS_ERROR_NONE) {
903 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
904 contacts_list_destroy(personList, true);
908 MSG_DEBUG("personId [%d]", personId);
910 ret = contacts_record_get_bool(person, _contacts_person_number.is_favorite, &isFavorites);
911 if (ret != CONTACTS_ERROR_NONE) {
912 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
913 contacts_list_destroy(personList, true);
917 contacts_list_destroy(personList, true);
919 switch (blockModeType) {
920 case 2: { /* For Favorites allow in blocking mode. */
921 if (isFavorites) isblock = false;
924 case 3: { /* For Custom allow in blocking mode. */
925 char *allowList = MsgSettingGetString(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_LIST);
927 char *personIdStr = strtok_r(allowList, " ,", &temp);
928 while (personIdStr != NULL) {
929 MSG_DEBUG("personIdStr [%s]", personIdStr);
930 if (personId == atoi(personIdStr)) {
931 MSG_DEBUG("In allow list.");
935 personIdStr = strtok_r(NULL, " ,", &temp);
945 default: /* Wrong blocking mode type. */
949 if (pisFavorites != NULL) *pisFavorites = isFavorites;
953 if (pisFavorites != NULL)
954 *pisFavorites = false;
960 int MsgContactGetMinMatchDigit()
962 return phonenumberMinMatchDigit;
966 void MsgConvertNumber(const char* pSrcNum, char* pDestNum, int destSize)
969 const char *temp_number;
971 if ('+' == pSrcNum[0]) {
972 len = countryCodeLength(&pSrcNum[1]);
973 temp_number = pSrcNum + len +1;
974 } else if ('0' == pSrcNum[0]) {
975 if ('0' == pSrcNum[1]) {
976 len = countryCodeLength(&pSrcNum[2]);
977 temp_number = pSrcNum + len +2;
979 temp_number = pSrcNum+1;
982 temp_number = pSrcNum;
985 strncpy(pDestNum, temp_number, destSize);
989 bool MsgIsNumber(const char* pSrc)
991 int len = strlen(pSrc);
993 for (int i = 0; i < len; ++i) {
994 if (i == 0 && pSrc[i] == '+')
997 if (pSrc[i] < '0' || pSrc[i] > '9') {