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_int(plog, _contacts_phone_log.sim_slot_no, (int)pMsgInfo->sim_idx-1);
696 contacts_record_set_str(plog, _contacts_phone_log.address, (char*)pMsgInfo->addressList[i].addressVal);
697 contacts_record_set_int(plog, _contacts_phone_log.log_time, (int)time(NULL));
700 memset(strText, 0x00, sizeof(strText));
702 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
703 strncpy(strText, pMsgInfo->msgText, 100);
704 MSG_SEC_DEBUG("msgText : %s", strText);
705 } else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
706 if (strlen(pMsgInfo->subject) > 0 || pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
707 strncpy(strText, pMsgInfo->subject, 100);
708 MSG_SEC_DEBUG("subject : %s", strText);
710 char *pFileData = NULL;
713 if (pMsgInfo->msgText[0] != '\0' && g_file_get_contents(pMsgInfo->msgText, &pFileData, &fileSize, NULL) == true) {
715 strncpy(strText, pFileData, 100);
721 MSG_SEC_DEBUG("msgText : %s", strText);
725 contacts_record_set_str(plog, _contacts_phone_log.extra_data2, strText);
726 contacts_record_set_int(plog, _contacts_phone_log.extra_data1, (int)pMsgInfo->msgId);
728 if (pMsgInfo->folderId == MSG_INBOX_ID) {
729 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
730 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_INCOMING);
731 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
732 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_INCOMING);
733 } else if (pMsgInfo->folderId == MSG_OUTBOX_ID) {
734 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
735 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_OUTGOING);
736 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
737 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_OUTGOING);
738 } else if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
739 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
740 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_BLOCKED);
741 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
742 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
745 ret = contacts_db_insert_record(plog, NULL);
746 if (ret != CONTACTS_ERROR_NONE) {
747 MSG_DEBUG("contacts_db_insert_record() Error [%d]", ret);
750 contacts_record_destroy(plog, true);
755 void MsgDeletePhoneLog(msg_message_id_t msgId)
757 msg_error_t err = MSG_SUCCESS;
759 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
760 MSG_DEBUG("MsgOpenContactSvc fail.");
764 MSG_DEBUG("MsgDeletePhoneLog [%d]", msgId);
766 if (!isContactSvcConnected) {
767 MSG_DEBUG("Contact Service Not Opened.");
771 int ret = CONTACTS_ERROR_NONE;
774 contacts_query_h query;
775 contacts_filter_h filter;
776 contacts_list_h plogs = NULL;
778 ret = contacts_query_create(_contacts_phone_log._uri, &query);
779 ret = contacts_filter_create(_contacts_phone_log._uri, &filter);
781 ret = contacts_filter_add_int(filter, _contacts_phone_log.extra_data1, CONTACTS_MATCH_EQUAL, (int)msgId);
784 ret = contacts_query_set_filter(query, filter);
785 ret = contacts_db_get_records_with_query(query, 0, 1, &plogs);
787 ret = contacts_list_get_count(plogs, &count);
790 MSG_DEBUG("No Serach Data from Contact Service.");
792 contacts_record_h plog = NULL;
794 ret = contacts_list_get_current_record_p(plogs, &plog);
795 if (ret != CONTACTS_ERROR_NONE) {
796 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
799 ret = contacts_record_get_int(plog, _contacts_phone_log.id, &index);
800 if (ret != CONTACTS_ERROR_NONE) {
801 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
804 ret = contacts_db_delete_record(_contacts_phone_log._uri, index);
805 if (ret != CONTACTS_ERROR_NONE) {
806 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
808 MSG_DEBUG("contacts_db_delete_record() Success.");
812 contacts_query_destroy(query);
813 contacts_filter_destroy(filter);
814 contacts_list_destroy(plogs, true);
818 bool checkBlockingMode(char *address, bool *pisFavorites)
821 msg_error_t err = MSG_SUCCESS;
823 if (pisFavorites != NULL) *pisFavorites = false;
825 bool isBlockModeOn = false;
828 MsgSettingGetBool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &isBlockModeOn);
830 int blockModeType = -1;
832 blockModeType = MsgSettingGetInt(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE);
836 else if (blockModeType < 0)
840 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
841 MSG_DEBUG("MsgOpenContactSvc fail.");
845 if (!isContactSvcConnected) {
846 MSG_DEBUG("Contact Service Not Opened.");
850 MSG_SEC_DEBUG("Address Value [%s]", address);
852 if (strlen(address) > (MAX_PHONE_NUMBER_LEN+1)) {
853 MSG_SEC_DEBUG("Phone Number is too long [%s]", address);
859 bool isFavorites = false;
861 contacts_query_h query = NULL;
862 contacts_filter_h filter = NULL;
863 contacts_list_h personList = NULL;
865 ret = contacts_query_create(_contacts_person_number._uri, &query);
866 ret = contacts_filter_create(_contacts_person_number._uri, &filter);
868 ret = contacts_filter_add_str(filter, _contacts_person_number.number_filter, CONTACTS_MATCH_EXACTLY, address);
870 ret = contacts_query_set_filter(query, filter);
871 ret = contacts_db_get_records_with_query(query, 0, 1, &personList);
873 contacts_query_destroy(query);
874 contacts_filter_destroy(filter);
876 if (ret != CONTACTS_ERROR_NONE) {
877 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
878 contacts_list_destroy(personList, true);
882 ret = contacts_list_get_count(personList, &count);
884 if (count == 0 || ret != CONTACTS_ERROR_NONE) {
885 MSG_DEBUG("No Serach Data from Contact Service.");
886 contacts_list_destroy(personList, true);
888 } else if (ret == CONTACTS_ERROR_NONE && count > 0
889 && blockModeType == 1) { /* For All contacts allow in blocking mode. */
893 contacts_record_h person = NULL;
895 ret = contacts_list_get_current_record_p(personList, &person);
896 if (ret != CONTACTS_ERROR_NONE) {
897 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
898 contacts_list_destroy(personList, true);
902 ret = contacts_record_get_int(person, _contacts_person_number.person_id, &personId);
903 if (ret != CONTACTS_ERROR_NONE) {
904 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
905 contacts_list_destroy(personList, true);
909 MSG_DEBUG("personId [%d]", personId);
911 ret = contacts_record_get_bool(person, _contacts_person_number.is_favorite, &isFavorites);
912 if (ret != CONTACTS_ERROR_NONE) {
913 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
914 contacts_list_destroy(personList, true);
918 contacts_list_destroy(personList, true);
920 switch (blockModeType) {
921 case 2: { /* For Favorites allow in blocking mode. */
922 if (isFavorites) isblock = false;
925 case 3: { /* For Custom allow in blocking mode. */
926 char *allowList = MsgSettingGetString(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_LIST);
928 char *personIdStr = strtok_r(allowList, " ,", &temp);
929 while (personIdStr != NULL) {
930 MSG_DEBUG("personIdStr [%s]", personIdStr);
931 if (personId == atoi(personIdStr)) {
932 MSG_DEBUG("In allow list.");
936 personIdStr = strtok_r(NULL, " ,", &temp);
946 default: /* Wrong blocking mode type. */
950 if (pisFavorites != NULL) *pisFavorites = isFavorites;
954 if (pisFavorites != NULL)
955 *pisFavorites = false;
961 int MsgContactGetMinMatchDigit()
963 return phonenumberMinMatchDigit;
967 void MsgConvertNumber(const char* pSrcNum, char* pDestNum, int destSize)
970 const char *temp_number;
972 if ('+' == pSrcNum[0]) {
973 len = countryCodeLength(&pSrcNum[1]);
974 temp_number = pSrcNum + len +1;
975 } else if ('0' == pSrcNum[0]) {
976 if ('0' == pSrcNum[1]) {
977 len = countryCodeLength(&pSrcNum[2]);
978 temp_number = pSrcNum + len +2;
980 temp_number = pSrcNum+1;
983 temp_number = pSrcNum;
986 strncpy(pDestNum, temp_number, destSize);
990 bool MsgIsNumber(const char* pSrc)
992 int len = strlen(pSrc);
994 for (int i = 0; i < len; ++i) {
995 if (i == 0 && pSrc[i] == '+')
998 if (pSrc[i] < '0' || pSrc[i] > '9') {