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 /*==================================================================================================
38 INTERNAL FUNCTION IMPLEMENTATION
39 ==================================================================================================*/
41 int countryCodeLength(const char *src)
44 switch (src[ret++]-'0') {
49 switch (src[ret++]-'0') {
64 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
68 switch (src[ret++]-'0') {
83 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
87 switch (src[ret++]-'0') {
102 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
106 switch (src[ret++]-'0') {
121 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
125 switch (src[ret++]-'0') {
140 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
144 switch (src[ret++]-'0') {
159 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
163 switch (src[ret++]-'0') {
178 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
183 MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
191 void normalizeNumber(const char *orig, char* dest, unsigned int destSize)
193 unsigned int pos = 0;
194 for (unsigned int i = 0; (orig[i] && i < destSize); i++) {
195 if (isdigit(orig[i]) || (orig[i] == '+')) {
196 dest[pos++] = orig[i];
201 /*==================================================================================================
202 FUNCTION IMPLEMENTATION
203 ==================================================================================================*/
204 msg_error_t MsgOpenContactSvc()
206 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
207 int errCode = CONTACTS_ERROR_NONE;
209 if (!isContactSvcConnected) {
210 errCode = contacts_connect();
212 if (errCode == CONTACTS_ERROR_NONE) {
213 MSG_DEBUG("Connect to Contact Service Success");
214 isContactSvcConnected = true;
216 MSG_DEBUG("Connect to Contact Service Fail [%d]", errCode);
217 isContactSvcConnected = false;
218 return MSG_ERR_DB_CONNECT;
221 MSG_DEBUG("Already connected to Contact Service.");
223 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
228 msg_error_t MsgCloseContactSvc()
230 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
231 int errCode = CONTACTS_ERROR_NONE;
233 if (isContactSvcConnected) {
234 errCode = contacts_disconnect();
236 if (errCode == CONTACTS_ERROR_NONE) {
237 MSG_DEBUG("Disconnect to Contact Service Success");
238 isContactSvcConnected = false;
240 MSG_DEBUG("Disconnect to Contact Service Fail [%d]", errCode);
241 return MSG_ERR_DB_DISCONNECT;
244 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
248 msg_error_t MsgGetContactSearchList(const char *pSearchVal, MSG_ADDRESS_INFO_S **pAddrInfo, int *count)
251 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
253 msg_error_t err = MSG_SUCCESS;
257 if (pSearchVal == NULL) {
258 MSG_DEBUG("pSearchVal is NULL.");
259 return MSG_ERR_NULL_POINTER;
262 if (pAddrInfo == NULL) {
263 MSG_DEBUG("pAddrInfo is NULL.");
264 return MSG_ERR_NULL_POINTER;
267 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
268 MSG_DEBUG("MsgOpenContactSvc fail.");
272 if (!isContactSvcConnected) {
273 MSG_DEBUG("Contact Service Not Opened.");
274 return MSG_ERR_UNKNOWN;
277 MSG_SEC_DEBUG("pSearchVal [%s]", pSearchVal);
280 unsigned int index = 0;
281 contacts_query_h query = NULL;
282 contacts_filter_h filter = NULL;
283 contacts_list_h personNumbers = NULL;
285 ret = contacts_query_create(_contacts_person_number._uri, &query);
286 ret = contacts_filter_create(_contacts_person_number._uri, &filter);
288 ret = contacts_filter_add_str(filter, _contacts_person_number.display_name, CONTACTS_MATCH_CONTAINS, pSearchVal);
289 ret = contacts_query_set_filter(query, filter);
291 ret = contacts_db_get_records_with_query(query, 0, 0, &personNumbers);
292 if (ret != CONTACTS_ERROR_NONE) {
293 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
294 contacts_query_destroy(query);
295 contacts_filter_destroy(filter);
296 contacts_list_destroy(personNumbers, true);
297 return MSG_ERR_UNKNOWN;
300 ret = contacts_list_get_count(personNumbers, count);
301 if (*count == 0 || ret != CONTACTS_ERROR_NONE) {
302 MSG_DEBUG("No Serach Data from Contact Service.");
304 contacts_query_destroy(query);
305 contacts_filter_destroy(filter);
306 contacts_list_destroy(personNumbers, true);
310 contacts_query_destroy(query);
311 contacts_filter_destroy(filter);
313 MSG_DEBUG(" *count [%d]", *count);
315 *pAddrInfo = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * (*count)];
316 memset(*pAddrInfo, 0x00, (sizeof(MSG_ADDRESS_INFO_S) * (*count)));
318 contacts_record_h personNumber = NULL;
320 while (CONTACTS_ERROR_NONE == contacts_list_get_current_record_p(personNumbers, &personNumber)) {
321 char* normalizedNumber = NULL;
322 ret = contacts_record_get_str(personNumber, _contacts_person_number.normalized_number, &normalizedNumber);
323 if (ret != CONTACTS_ERROR_NONE) {
324 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
325 } else if (normalizedNumber) {
326 MSG_DEBUG("normalizedNumber [%s]", normalizedNumber);
327 strncpy((*pAddrInfo)[index].addressVal, normalizedNumber, MAX_ADDRESS_VAL_LEN);
330 contacts_list_next(personNumbers);
334 contacts_list_destroy(personNumbers, true);
336 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
342 msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_INFO_S *pContactInfo)
345 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
346 msg_error_t err = MSG_SUCCESS;
348 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
349 MSG_DEBUG("MsgOpenContactSvc fail.");
353 if (!isContactSvcConnected) {
354 MSG_DEBUG("Contact Service Not Opened.");
355 return MSG_ERR_UNKNOWN;
358 MSG_SEC_DEBUG("Address Type [%d], Address Value [%s]", pAddrInfo->addressType, pAddrInfo->addressVal);
360 memset(pContactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
362 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN && strlen(pAddrInfo->addressVal) > (MAX_PHONE_NUMBER_LEN+1)) {
363 MSG_SEC_DEBUG("Phone Number is too long [%s]", pAddrInfo->addressVal);
364 return MSG_ERR_UNKNOWN;
370 contacts_query_h query = NULL;
371 contacts_filter_h filter = NULL;
372 contacts_list_h contacts = NULL;
374 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
375 ret = contacts_query_create(_contacts_contact_number._uri, &query);
376 ret = contacts_filter_create(_contacts_contact_number._uri, &filter);
378 ret = contacts_filter_add_str(filter, _contacts_contact_number.number_filter, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
380 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
381 ret = contacts_query_create(_contacts_contact_email._uri, &query);
382 ret = contacts_filter_create(_contacts_contact_email._uri, &filter);
384 ret = contacts_filter_add_str(filter, _contacts_contact_email.email, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
387 MSG_DEBUG("Invalid pAddrInfo->addressType.");
388 return MSG_ERR_UNKNOWN;
391 ret = contacts_query_set_filter(query, filter);
392 ret = contacts_db_get_records_with_query(query, 0, 1, &contacts);
393 if (ret != CONTACTS_ERROR_NONE) {
394 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
395 contacts_query_destroy(query);
396 contacts_filter_destroy(filter);
397 contacts_list_destroy(contacts, true);
398 return MSG_ERR_UNKNOWN;
401 ret = contacts_list_get_count(contacts, &count);
403 if (count == 0 || ret != CONTACTS_ERROR_NONE) {
404 MSG_DEBUG("No Serach Data from Contact Service.");
405 contacts_query_destroy(query);
406 contacts_filter_destroy(filter);
407 contacts_list_destroy(contacts, true);
411 contacts_query_destroy(query);
412 contacts_filter_destroy(filter);
414 contacts_record_h contact = NULL;
416 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
417 contacts_record_h number = NULL;
419 ret = contacts_list_get_current_record_p(contacts, &number);
420 if (ret != CONTACTS_ERROR_NONE) {
421 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
422 contacts_list_destroy(contacts, true);
423 return MSG_ERR_UNKNOWN;
426 ret = contacts_record_get_int(number, _contacts_contact_number.contact_id, &index);
427 if (ret != CONTACTS_ERROR_NONE) {
428 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
429 contacts_list_destroy(contacts, true);
430 return MSG_ERR_UNKNOWN;
433 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
434 if (ret != CONTACTS_ERROR_NONE) {
435 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
436 contacts_list_destroy(contacts, true);
437 return MSG_ERR_UNKNOWN;
439 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
440 contacts_record_h email = NULL;
442 ret = contacts_list_get_current_record_p(contacts, &email);
443 if (ret != CONTACTS_ERROR_NONE) {
444 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
445 contacts_list_destroy(contacts, true);
446 return MSG_ERR_UNKNOWN;
449 ret = contacts_record_get_int(email, _contacts_contact_email.contact_id, &index);
450 if (ret != CONTACTS_ERROR_NONE) {
451 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
452 contacts_list_destroy(contacts, true);
453 return MSG_ERR_UNKNOWN;
456 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
457 if (ret != CONTACTS_ERROR_NONE) {
458 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
459 contacts_list_destroy(contacts, true);
460 return MSG_ERR_UNKNOWN;
464 contacts_list_destroy(contacts, true);
466 ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&pContactInfo->contactId);
467 if (ret != CONTACTS_ERROR_NONE) {
468 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
469 contacts_record_destroy(contact, true);
470 return MSG_ERR_UNKNOWN;
473 MSG_DEBUG("Contact ID [%d]", pContactInfo->contactId);
475 ret = contacts_record_get_int(contact, _contacts_contact.address_book_id, (int*)&pContactInfo->addrbookId);
476 if (ret != CONTACTS_ERROR_NONE) {
477 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
478 contacts_record_destroy(contact, true);
479 return MSG_ERR_UNKNOWN;
482 MSG_DEBUG("Address Book ID [%d]", pContactInfo->addrbookId);
484 char* strImagePath = NULL;
485 ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
486 if (ret != CONTACTS_ERROR_NONE) {
487 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
489 if (strImagePath != NULL) {
490 strncpy(pContactInfo->imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
491 MSG_DEBUG("Image Path [%s]", pContactInfo->imagePath);
494 char* alerttonePath = NULL;
495 ret = contacts_record_get_str_p(contact, _contacts_contact.message_alert, &alerttonePath);
496 if (ret != CONTACTS_ERROR_NONE) {
497 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
500 if (MsgAccessFile(alerttonePath, F_OK) == false) {
501 alerttonePath = NULL;
504 if (alerttonePath != NULL) {
505 MSG_DEBUG("alert tone Path [%s]", alerttonePath);
506 strncpy(pContactInfo->alerttonePath , alerttonePath, MSG_FILEPATH_LEN_MAX);
508 MSG_DEBUG("alert tone Path for this contact is default");
510 ret = contacts_record_get_child_record_count(contact, _contacts_contact.group_relation, &count);
511 if (ret != CONTACTS_ERROR_NONE) {
512 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
515 contacts_record_h group_relation_record;
517 for (int i = 0; i < count; i++) {
519 contacts_record_get_child_record_at_p(contact, _contacts_contact.group_relation, i, &group_relation_record);
520 contacts_record_get_int(group_relation_record, _contacts_group_relation.group_id, &group_id);
522 contacts_record_h group_record;
523 contacts_db_get_record(_contacts_group._uri, group_id, &group_record);
525 MSG_DEBUG("Group ID = [%d]", group_id);
527 char *group_ringtone_path;
528 ret = contacts_record_get_str_p(group_record, _contacts_group.message_alert, &group_ringtone_path);
529 if (ret != CONTACTS_ERROR_NONE) {
530 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
532 if (group_ringtone_path) {
533 MSG_DEBUG("Msg alert_tone is change to [%s] as contact group", group_ringtone_path);
534 memset(pContactInfo->alerttonePath, 0x00, sizeof(pContactInfo->alerttonePath));
535 snprintf(pContactInfo->alerttonePath, sizeof(pContactInfo->alerttonePath), "%s", group_ringtone_path);
536 contacts_record_destroy(group_record, true);
540 contacts_record_destroy(group_record, true);
544 char* vibrationPath = NULL;
545 ret = contacts_record_get_str_p(contact, _contacts_contact.vibration, &vibrationPath);
546 if (ret != CONTACTS_ERROR_NONE) {
547 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
549 if (vibrationPath != NULL) {
550 MSG_DEBUG("vibration Path [%s]", vibrationPath);
551 strncpy(pContactInfo->vibrationPath , vibrationPath, MSG_FILEPATH_LEN_MAX);
554 char* displayName = NULL;
555 ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &displayName);
556 if (ret != CONTACTS_ERROR_NONE) {
557 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
559 if (displayName != NULL) {
560 MSG_DEBUG("displayName [%s]", displayName);
561 strncpy(pContactInfo->firstName , displayName, MAX_DISPLAY_NAME_LEN);
564 contacts_record_destroy(contact, true);
565 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
572 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)
574 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
575 if (first == NULL || last == NULL || middle == NULL || prefix == NULL || suffix == NULL || displayName == NULL || size ==0) {
576 MSG_DEBUG("Invalid parameter.");
577 return MSG_ERR_INVALID_PARAMETER;
580 if (contactNameOrder == CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST) {
581 if (strlen(prefix) > 0) {
582 strncpy(displayName, prefix, size);
585 if (strlen(first) > 0) {
586 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
587 strncat(displayName, first, size-strlen(displayName));
590 if (strlen(middle) > 0) {
591 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
593 strncat(displayName, middle, size-strlen(displayName));
596 if (strlen(last) > 0) {
597 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
598 strncat(displayName, last, size-strlen(displayName));
601 if (strlen(suffix) > 0) {
602 if (strlen(displayName) > 0) strncat(displayName, ", ", size-strlen(displayName));
603 strncat(displayName, suffix, size-strlen(displayName));
606 if (strlen(prefix) > 0) {
607 strncpy(displayName, prefix, size);
610 if (strlen(last) > 0) {
611 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
612 strncat(displayName, last, size-strlen(displayName));
614 if (strlen(first) > 0 || strlen(middle) > 0 || strlen(suffix) > 0)
615 strncat(displayName, ",", size-strlen(displayName));
618 if (strlen(first) > 0) {
619 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
620 strncat(displayName, first, size-strlen(displayName));
623 if (strlen(middle) > 0) {
624 if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
625 strncat(displayName, middle, size-strlen(displayName));
628 if (strlen(suffix) > 0) {
629 if (strlen(displayName) > 0) strncat(displayName, ", ", size-strlen(displayName));
630 strncat(displayName, suffix, size-strlen(displayName));
634 MSG_SEC_DEBUG("displayName [%s]", displayName);
635 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
640 void MsgAddPhoneLog(const MSG_MESSAGE_INFO_S *pMsgInfo)
642 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
643 msg_error_t err = MSG_SUCCESS;
645 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
646 MSG_DEBUG("MsgOpenContactSvc fail.");
650 if (!isContactSvcConnected) {
651 MSG_DEBUG("Contact Service Not Opened.");
655 if (pMsgInfo->nAddressCnt < 1) {
656 MSG_DEBUG("address count is [%d]", pMsgInfo->nAddressCnt);
660 for (int i = 0; pMsgInfo->nAddressCnt > i; i++) {
662 contacts_record_h plog = NULL;
664 ret = contacts_record_create(_contacts_phone_log._uri, &plog);
665 if (ret != CONTACTS_ERROR_NONE) {
666 MSG_DEBUG("contacts_record_create() Error [%d]", ret);
667 contacts_record_destroy(plog, true);
671 contacts_record_set_int(plog, _contacts_phone_log.sim_slot_no, (int)pMsgInfo->sim_idx-1);
672 contacts_record_set_str(plog, _contacts_phone_log.address, (char*)pMsgInfo->addressList[i].addressVal);
673 contacts_record_set_int(plog, _contacts_phone_log.log_time, (int)time(NULL));
676 memset(strText, 0x00, sizeof(strText));
678 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
679 g_strlcpy(strText, pMsgInfo->msgText, sizeof(strText));
680 MSG_SEC_DEBUG("msgText : %s", strText);
681 } else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
682 if (strlen(pMsgInfo->subject) > 0 || pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
683 g_strlcpy(strText, pMsgInfo->subject, sizeof(strText));
684 MSG_SEC_DEBUG("subject : %s", strText);
686 char *pFileData = NULL;
689 if (pMsgInfo->msgText[0] != '\0' && g_file_get_contents(pMsgInfo->msgText, &pFileData, &fileSize, NULL) == true) {
691 strncpy(strText, pFileData, 100);
697 MSG_SEC_DEBUG("msgText : %s", strText);
701 contacts_record_set_str(plog, _contacts_phone_log.extra_data2, strText);
702 contacts_record_set_int(plog, _contacts_phone_log.extra_data1, (int)pMsgInfo->msgId);
704 if (pMsgInfo->folderId == MSG_INBOX_ID) {
705 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
706 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_INCOMING);
707 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
708 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_INCOMING);
709 } else if (pMsgInfo->folderId == MSG_OUTBOX_ID) {
710 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
711 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_OUTGOING);
712 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
713 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_OUTGOING);
714 } else if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
715 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
716 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_BLOCKED);
717 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
718 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
721 ret = contacts_db_insert_record(plog, NULL);
722 if (ret != CONTACTS_ERROR_NONE) {
723 MSG_DEBUG("contacts_db_insert_record() Error [%d]", ret);
726 contacts_record_destroy(plog, true);
728 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
732 void MsgDeletePhoneLog(msg_message_id_t msgId)
734 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
735 msg_error_t err = MSG_SUCCESS;
737 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
738 MSG_DEBUG("MsgOpenContactSvc fail.");
742 MSG_DEBUG("MsgDeletePhoneLog [%d]", msgId);
744 if (!isContactSvcConnected) {
745 MSG_DEBUG("Contact Service Not Opened.");
749 int ret = CONTACTS_ERROR_NONE;
752 contacts_query_h query;
753 contacts_filter_h filter;
754 contacts_list_h plogs = NULL;
756 ret = contacts_query_create(_contacts_phone_log._uri, &query);
757 ret = contacts_filter_create(_contacts_phone_log._uri, &filter);
759 ret = contacts_filter_add_int(filter, _contacts_phone_log.extra_data1, CONTACTS_MATCH_EQUAL, (int)msgId);
762 ret = contacts_query_set_filter(query, filter);
763 ret = contacts_db_get_records_with_query(query, 0, 1, &plogs);
765 ret = contacts_list_get_count(plogs, &count);
768 MSG_DEBUG("No Serach Data from Contact Service.");
770 contacts_record_h plog = NULL;
772 ret = contacts_list_get_current_record_p(plogs, &plog);
773 if (ret != CONTACTS_ERROR_NONE) {
774 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
777 ret = contacts_record_get_int(plog, _contacts_phone_log.id, &index);
778 if (ret != CONTACTS_ERROR_NONE) {
779 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
782 ret = contacts_db_delete_record(_contacts_phone_log._uri, index);
783 if (ret != CONTACTS_ERROR_NONE) {
784 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
786 MSG_DEBUG("contacts_db_delete_record() Success.");
790 contacts_query_destroy(query);
791 contacts_filter_destroy(filter);
792 contacts_list_destroy(plogs, true);
793 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
797 bool checkBlockingMode(char *address, bool *pisFavorites)
800 msg_error_t err = MSG_SUCCESS;
802 if (pisFavorites != NULL) *pisFavorites = false;
804 bool isBlockModeOn = false;
807 if (MsgSettingGetBool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &isBlockModeOn) != MSG_SUCCESS)
808 MSG_INFO("MsgSettingGetBool() is failed");
810 int blockModeType = -1;
812 if (MsgSettingGetInt(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE, &blockModeType) != MSG_SUCCESS) {
813 MSG_INFO("MsgSettingGetInt() is failed");
818 else if (blockModeType < 0)
822 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
823 MSG_DEBUG("MsgOpenContactSvc fail.");
827 if (!isContactSvcConnected) {
828 MSG_DEBUG("Contact Service Not Opened.");
832 MSG_SEC_DEBUG("Address Value [%s]", address);
834 if (strlen(address) > (MAX_PHONE_NUMBER_LEN+1)) {
835 MSG_SEC_DEBUG("Phone Number is too long [%s]", address);
841 bool isFavorites = false;
843 contacts_query_h query = NULL;
844 contacts_filter_h filter = NULL;
845 contacts_list_h personList = NULL;
847 ret = contacts_query_create(_contacts_person_number._uri, &query);
848 ret = contacts_filter_create(_contacts_person_number._uri, &filter);
850 ret = contacts_filter_add_str(filter, _contacts_person_number.number_filter, CONTACTS_MATCH_EXACTLY, address);
852 ret = contacts_query_set_filter(query, filter);
853 ret = contacts_db_get_records_with_query(query, 0, 1, &personList);
855 contacts_query_destroy(query);
856 contacts_filter_destroy(filter);
858 if (ret != CONTACTS_ERROR_NONE) {
859 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
860 contacts_list_destroy(personList, true);
864 ret = contacts_list_get_count(personList, &count);
866 if (count == 0 || ret != CONTACTS_ERROR_NONE) {
867 MSG_DEBUG("No Serach Data from Contact Service.");
868 contacts_list_destroy(personList, true);
870 } else if (ret == CONTACTS_ERROR_NONE && count > 0
871 && blockModeType == 1) { /* For All contacts allow in blocking mode. */
875 contacts_record_h person = NULL;
877 ret = contacts_list_get_current_record_p(personList, &person);
878 if (ret != CONTACTS_ERROR_NONE) {
879 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
880 contacts_list_destroy(personList, true);
884 ret = contacts_record_get_int(person, _contacts_person_number.person_id, &personId);
885 if (ret != CONTACTS_ERROR_NONE) {
886 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
887 contacts_list_destroy(personList, true);
891 MSG_DEBUG("personId [%d]", personId);
893 ret = contacts_record_get_bool(person, _contacts_person_number.is_favorite, &isFavorites);
894 if (ret != CONTACTS_ERROR_NONE) {
895 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
896 contacts_list_destroy(personList, true);
900 contacts_list_destroy(personList, true);
902 switch (blockModeType) {
903 case 2: { /* For Favorites allow in blocking mode. */
904 if (isFavorites) isblock = false;
907 case 3: { /* For Custom allow in blocking mode. */
908 char *allowList = NULL;
909 if (MsgSettingGetString(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_LIST, &allowList) != MSG_SUCCESS) {
910 MSG_INFO("MsgSettingGetString() is failed");
913 char *personIdStr = strtok_r(allowList, " ,", &temp);
914 while (personIdStr != NULL) {
915 MSG_DEBUG("personIdStr [%s]", personIdStr);
916 if (personId == atoi(personIdStr)) {
917 MSG_DEBUG("In allow list.");
921 personIdStr = strtok_r(NULL, " ,", &temp);
931 default: /* Wrong blocking mode type. */
935 if (pisFavorites != NULL) *pisFavorites = isFavorites;
939 if (pisFavorites != NULL)
940 *pisFavorites = false;
947 void MsgConvertNumber(const char* pSrcNum, char* pDestNum, int destSize)
950 const char *temp_number;
952 if ('+' == pSrcNum[0]) {
953 len = countryCodeLength(&pSrcNum[1]);
954 temp_number = pSrcNum + len +1;
955 } else if ('0' == pSrcNum[0]) {
956 if ('0' == pSrcNum[1]) {
957 len = countryCodeLength(&pSrcNum[2]);
958 temp_number = pSrcNum + len +2;
960 temp_number = pSrcNum+1;
963 temp_number = pSrcNum;
966 strncpy(pDestNum, temp_number, destSize);
970 bool MsgIsNumber(const char* pSrc)
972 int len = strlen(pSrc);
974 for (int i = 0; i < len; ++i) {
975 if (i == 0 && pSrc[i] == '+')
978 if (pSrc[i] < '0' || pSrc[i] > '9') {