/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "TIZEN_N_CONTACTS" #define LOG_MODE (1) int contact_foreach_contact_from_db(contact_foreach_query_name_cb cb, void* user_data) { CONTACTS_NULL_ARG_CHECK(cb); CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_CONTACT, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } GSList *contactlist = NULL; while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); contact_query_name_s *query_data = NULL; query_data = malloc(sizeof(contact_query_name_s)); if(query_data == NULL) { g_slist_foreach(contactlist, _contacts_free_query_person_struct_all, NULL); g_slist_free(contactlist); contacts_svc_value_free(foreach_data); contacts_svc_iter_remove(iter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } _contacts_set_query_person_struct(query_data, foreach_data); contactlist = g_slist_append(contactlist, query_data); contacts_svc_value_free(foreach_data); } contacts_svc_iter_remove(iter); GSList *cursor = contactlist; for(;cursor;cursor=g_slist_next(cursor)) { func_ret = cb((contact_query_name_s*)cursor->data, user_data); if(func_ret == false) { break; } } g_slist_foreach(contactlist, _contacts_free_query_person_struct_all, NULL); g_slist_free(contactlist); return CONTACTS_ERROR_NONE; } int contact_foreach_favorite_contact_from_db(contact_foreach_query_favorites_cb cb, void* user_data) { CONTACTS_NULL_ARG_CHECK(cb); CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_CONTACT_FAVORITE, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_favorite_s query_data; query_data.contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_SHORTCUT_CONTACT_ID_INT); query_data.first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_SHORTCUT_FIRST_NAME_STR)); query_data.last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_SHORTCUT_LAST_NAME_STR)); query_data.display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_SHORTCUT_DISPLAY_NAME_STR)); query_data.contact_image_path = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_SHORTCUT_IMG_PATH_STR)); query_data.phone_type = contacts_svc_value_get_int(foreach_data, CTS_LIST_SHORTCUT_NUMBER_TYPE_INT); query_data.phone_number = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_SHORTCUT_NUMBER_STR)); func_ret = cb(&query_data, user_data); contacts_svc_value_free(foreach_data); _contacts_safe_free(query_data.first_name); _contacts_safe_free(query_data.last_name); _contacts_safe_free(query_data.display_name); _contacts_safe_free(query_data.contact_image_path); _contacts_safe_free(query_data.phone_number); if(func_ret == 0) { break; } } contacts_svc_iter_remove(iter); return CONTACTS_ERROR_NONE; } int contact_foreach_frequent_contact_from_db(contact_foreach_query_name_cb callback, void *user_data) { CONTACTS_NULL_ARG_CHECK(callback); CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_OFTEN_USED_CONTACT, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_name_s query_data; _contacts_set_query_person_struct(&query_data, foreach_data); func_ret = callback(&query_data, user_data); contacts_svc_value_free(foreach_data); _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; } } contacts_svc_iter_remove(iter); return CONTACTS_ERROR_NONE; } int contact_query_contact_by_name(contact_foreach_query_name_cb cb, const char* name_to_find, void* user_data) { CONTACTS_NULL_ARG_CHECK(cb); CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list_with_str(CTS_LIST_CONTACTS_WITH_NAME, name_to_find, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_name_s query_data; _contacts_set_query_person_struct(&query_data, foreach_data); func_ret = cb(&query_data, user_data); contacts_svc_value_free(foreach_data); _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; } } contacts_svc_iter_remove(iter); return CONTACTS_ERROR_NONE; } int contact_query_contact_by_group(contact_foreach_query_name_cb cb, int group_id, void* user_data) { CONTACTS_NULL_ARG_CHECK(cb); CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list_with_int(CTS_LIST_MEMBERS_OF_GROUP_ID, group_id, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_name_s query_data; _contacts_set_query_person_struct(&query_data, foreach_data); func_ret = cb(&query_data, user_data); contacts_svc_value_free(foreach_data); _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; } } contacts_svc_iter_remove(iter); return CONTACTS_ERROR_NONE; } int contact_query_contact_by_address_book(contact_foreach_query_name_cb callback, int address_book_db_id, void *user_data) { CONTACTS_NULL_ARG_CHECK(callback); CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list_with_int(CTS_LIST_MEMBERS_OF_ADDRESSBOOK_ID, address_book_db_id, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_name_s query_data; _contacts_set_query_person_struct(&query_data, foreach_data); func_ret = callback(&query_data, user_data); contacts_svc_value_free(foreach_data); _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; } } contacts_svc_iter_remove(iter); return CONTACTS_ERROR_NONE; } int contact_query_contact_by_email(contact_foreach_query_email_cb cb, const char* email_to_find, void* user_data) { if(cb == NULL) { LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); return CONTACTS_ERROR_INVALID_PARAMETER; } CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list_with_str(CTS_LIST_EMAILINFOS_WITH_EMAIL, email_to_find, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_email_s query_data; query_data.contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_NUM_CONTACT_ID_INT); query_data.first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_CONTACT_FIRST_STR)); query_data.last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_CONTACT_LAST_STR)); query_data.display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_CONTACT_DISPLAY_STR)); query_data.email_address = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_ADDR_STR)); query_data.contact_image_path = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_CONTACT_IMG_PATH_STR)); func_ret = cb(&query_data, user_data); contacts_svc_value_free(foreach_data); _contacts_safe_free(query_data.first_name); _contacts_safe_free(query_data.last_name); _contacts_safe_free(query_data.display_name); _contacts_safe_free(query_data.email_address); _contacts_safe_free(query_data.contact_image_path); if(func_ret == 0) { break; } } contacts_svc_iter_remove(iter); return CONTACTS_ERROR_NONE; } int contact_query_contact_by_number(contact_foreach_query_number_cb cb, const char* number_to_find, void* user_data) { if(cb == NULL) { LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); return CONTACTS_ERROR_INVALID_PARAMETER; } CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list_with_str(CTS_LIST_NUMBERINFOS_WITH_NUM, number_to_find, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_number_s query_data; query_data.contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_NUM_CONTACT_ID_INT); query_data.first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_CONTACT_FIRST_STR)); query_data.last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_CONTACT_LAST_STR)); query_data.display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_CONTACT_DISPLAY_STR)); query_data.phone_number = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_NUMBER_STR)); query_data.contact_image_path = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_CONTACT_IMG_PATH_STR)); func_ret = cb(&query_data, user_data); contacts_svc_value_free(foreach_data); _contacts_free_query_number_struct_member_only(&query_data); if(func_ret == 0) { break; } } contacts_svc_iter_remove(iter); return CONTACTS_ERROR_NONE; } int contact_query_contact_by_version(contact_foreach_query_version_cb cb, int address_book_db_id, int contacts_db_version, void* user_data) { CONTACTS_NULL_ARG_CHECK(cb); CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_updated_contacts(address_book_db_id, contacts_db_version, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_version_s query_data; query_data.contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CHANGE_ID_INT); query_data.changed_type = contacts_svc_value_get_int(foreach_data, CTS_LIST_CHANGE_TYPE_INT); query_data.contacts_db_version = contacts_svc_value_get_int(foreach_data, CTS_LIST_CHANGE_VER_INT); func_ret = cb(&query_data, user_data); contacts_svc_value_free(foreach_data); if(func_ret == 0) { break; } } contacts_svc_iter_remove(iter); return CONTACTS_ERROR_NONE; } int contact_query_contact_not_related_to_group(contact_foreach_query_name_cb callback, int address_book_db_id, void *user_data) { CONTACTS_NULL_ARG_CHECK(callback); CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list_with_int(CTS_LIST_NO_GROUP_MEMBERS_OF_ADDRESSBOOK_ID, address_book_db_id, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_name_s query_data; _contacts_set_query_person_struct(&query_data, foreach_data); func_ret = callback(&query_data, user_data); contacts_svc_value_free(foreach_data); _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; } } contacts_svc_iter_remove(iter); return CONTACTS_ERROR_NONE; } int contact_free_query_name_array(pcontact_query_name_s* contact_array) { CONTACTS_NULL_ARG_CHECK(contact_array); int i=0; while (contact_array[i] != NULL) { _contacts_free_query_person_struct_member_only((contact_query_name_s *)contact_array[i]); free(contact_array[i++]); } free(contact_array); return CONTACTS_ERROR_NONE; } int contact_free_query_number_array(pcontact_query_number_s *contact_number_array) { CONTACTS_NULL_ARG_CHECK(contact_number_array); int i=0; while (contact_number_array[i] != NULL) { _contacts_free_query_number_struct_member_only((contact_query_number_s *)contact_number_array[i]); free(contact_number_array[i++]); } free(contact_number_array); return CONTACTS_ERROR_NONE; } int contact_free_query_email_array(pcontact_query_email_s *contact_email_array) { CONTACTS_NULL_ARG_CHECK(contact_email_array); int i=0; while (contact_email_array[i] != NULL) { _contacts_free_query_email_struct_member_only((contact_query_email_s *)contact_email_array[i]); free(contact_email_array[i++]); } free(contact_email_array); return CONTACTS_ERROR_NONE; } int contact_free_query_version_array(pcontact_query_version_s *contact_version_array) { CONTACTS_NULL_ARG_CHECK(contact_version_array); int i=0; while (contact_version_array[i] != NULL) { free(contact_version_array[i++]); } free(contact_version_array); return CONTACTS_ERROR_NONE; } int contact_search_contact_by_address_book(int address_book_db_id, pcontact_query_name_s **contact_array, int *length) { CONTACTS_NULL_ARG_CHECK(contact_array); CONTACTS_NULL_ARG_CHECK(length); CTSiter *iter = NULL; CTSfilter *filter = NULL; if (ADDRESS_BOOK_FILTER_ALL == address_book_db_id) filter = contacts_svc_list_filter_new(CTS_FILTERED_ALL_CONTACT_OSP, CTS_LIST_FILTER_NONE); else filter = contacts_svc_list_filter_new(CTS_FILTERED_ALL_CONTACT_OSP, CTS_LIST_FILTER_ADDRESBOOK_ID_INT, address_book_db_id, CTS_LIST_FILTER_NONE); if (CTS_SUCCESS != contacts_svc_get_list_with_filter(filter, &iter)) { contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } GSList *list = NULL; while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_name_s *query_data = NULL; query_data = malloc(sizeof(contact_query_name_s)); if (NULL == query_data) { g_slist_foreach(list, _contacts_free_query_person_struct_all, NULL); g_slist_free(list); contacts_svc_value_free(foreach_data); contacts_svc_iter_remove(iter); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_OSP_CONTACT_ID_INT); query_data->first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_OSP_FIRST_STR)); query_data->last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_OSP_LAST_STR)); query_data->display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_OSP_DISPLAY_STR)); query_data->address_book_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_OSP_ADDRESSBOOK_ID_INT); query_data->contact_image_path = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_OSP_IMG_PATH_STR)); list = g_slist_append(list, query_data); contacts_svc_value_free(foreach_data); } contacts_svc_iter_remove(iter); *length = g_slist_length(list); if (0 == *length) { g_slist_foreach(list, _contacts_free_query_person_struct_all, NULL); g_slist_free(list); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } *contact_array = malloc(sizeof(pcontact_query_name_s) * (*length + 1)); if (NULL == *contact_array) { g_slist_foreach(list, _contacts_free_query_person_struct_all, NULL); g_slist_free(list); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } GSList *cursor = list; int i = 0; for (;cursor;cursor=g_slist_next(cursor)) (*contact_array)[i++] = cursor->data; (*contact_array)[i] = NULL; g_slist_free(list); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } int contact_search_contact_with_default_number_by_address_book(int address_book_db_id, pcontact_query_number_s **contact_array, int *length) { CONTACTS_NULL_ARG_CHECK(contact_array); CONTACTS_NULL_ARG_CHECK(length); CTSiter *iter = NULL; CTSfilter *filter = NULL; if (ADDRESS_BOOK_FILTER_ALL == address_book_db_id) filter = contacts_svc_list_filter_new(CTS_FILTERED_ALL_CONTACT_HAD_NUMBER, CTS_LIST_FILTER_NONE); else filter = contacts_svc_list_filter_new(CTS_FILTERED_ALL_CONTACT_HAD_NUMBER, CTS_LIST_FILTER_ADDRESBOOK_ID_INT, address_book_db_id, CTS_LIST_FILTER_NONE); if (CTS_SUCCESS != contacts_svc_get_list_with_filter(filter, &iter)) { contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } GSList *list = NULL; while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_number_s *query_data = NULL; query_data = malloc(sizeof(contact_query_number_s)); if (NULL == query_data) { g_slist_foreach(list, _contacts_free_query_number_struct_all, NULL); g_slist_free(list); contacts_svc_value_free(foreach_data); contacts_svc_iter_remove(iter); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CONTACT_ID_INT); query_data->address_book_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_OSP_ADDRESSBOOK_ID_INT); query_data->first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_FIRST_STR)); query_data->last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_LAST_STR)); query_data->display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_DISPLAY_STR)); query_data->contact_image_path = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_IMG_PATH_STR)); query_data->phone_number = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_NUM_OR_EMAIL_STR)); list = g_slist_append(list, query_data); contacts_svc_value_free(foreach_data); } contacts_svc_iter_remove(iter); *length = g_slist_length(list); if (0 == *length) { g_slist_foreach(list, _contacts_free_query_number_struct_all, NULL); g_slist_free(list); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } *contact_array = malloc(sizeof(pcontact_query_number_s) * (*length + 1)); if (NULL == *contact_array) { g_slist_foreach(list, _contacts_free_query_number_struct_all, NULL); g_slist_free(list); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } GSList *cursor = list; int i = 0; for (;cursor;cursor=g_slist_next(cursor)) (*contact_array)[i++] = cursor->data; (*contact_array)[i] = NULL; g_slist_free(list); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } int contact_get_all_phone_number(pcontact_query_number_s **phone_number_array, int *length) { CONTACTS_NULL_ARG_CHECK(phone_number_array); CONTACTS_NULL_ARG_CHECK(length); CTSiter *iter = NULL; if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_NUMBER, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } GSList *list = NULL; while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_number_s *query_data = NULL; query_data = malloc(sizeof(contact_query_number_s)); if (NULL == query_data) { g_slist_foreach(list, _contacts_free_query_number_struct_all, NULL); g_slist_free(list); contacts_svc_value_free(foreach_data); contacts_svc_iter_remove(iter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CONTACT_ID_INT); query_data->address_book_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CONTACT_ADDRESSBOOK_ID_INT); query_data->first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_FIRST_STR)); query_data->last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_LAST_STR)); query_data->display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_DISPLAY_STR)); query_data->contact_image_path = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_IMG_PATH_STR)); query_data->phone_number = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_NUM_OR_EMAIL_STR)); list = g_slist_append(list, query_data); contacts_svc_value_free(foreach_data); } contacts_svc_iter_remove(iter); *length = g_slist_length(list); if (0 == *length) { g_slist_foreach(list, _contacts_free_query_number_struct_all, NULL); g_slist_free(list); return CONTACTS_ERROR_NONE; } *phone_number_array = malloc(sizeof(pcontact_query_number_s) * (*length + 1)); if (NULL == *phone_number_array) { g_slist_foreach(list, _contacts_free_query_number_struct_all, NULL); g_slist_free(list); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } GSList *cursor = list; int i = 0; for (;cursor;cursor=g_slist_next(cursor)) (*phone_number_array)[i++] = cursor->data; (*phone_number_array)[i] = NULL; g_slist_free(list); return CONTACTS_ERROR_NONE; } int contact_search_contact_by_email(int address_book_db_id, const char *email_to_find, pcontact_query_email_s **contact_email_array, int *length) { CONTACTS_NULL_ARG_CHECK(email_to_find); CONTACTS_NULL_ARG_CHECK(contact_email_array); CONTACTS_NULL_ARG_CHECK(length); CTSiter *iter = NULL; CTSfilter *filter = NULL; if (ADDRESS_BOOK_FILTER_ALL == address_book_db_id) filter = contacts_svc_list_str_filter_new(CTS_FILTERED_EMAILINFOS_WITH_EMAIL, email_to_find, CTS_LIST_FILTER_NONE); else filter = contacts_svc_list_str_filter_new(CTS_FILTERED_EMAILINFOS_WITH_EMAIL, email_to_find, CTS_LIST_FILTER_ADDRESBOOK_ID_INT, address_book_db_id, CTS_LIST_FILTER_NONE); if (CTS_SUCCESS != contacts_svc_get_list_with_filter(filter, &iter)) { contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } GSList *list = NULL; while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_email_s *query_data = NULL; query_data = malloc(sizeof(contact_query_email_s)); if (NULL == query_data) { g_slist_foreach(list, _contacts_free_query_email_struct_all, NULL); g_slist_free(list); contacts_svc_value_free(foreach_data); contacts_svc_iter_remove(iter); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_EMAIL_CONTACT_ID_INT); query_data->address_book_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_OSP_ADDRESSBOOK_ID_INT); query_data->first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_CONTACT_FIRST_STR)); query_data->last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_CONTACT_LAST_STR)); query_data->display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_CONTACT_DISPLAY_STR)); query_data->contact_image_path= _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_CONTACT_IMG_PATH_STR)); query_data->email_address = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_EMAIL_ADDR_STR)); list = g_slist_append(list, query_data); contacts_svc_value_free(foreach_data); } contacts_svc_iter_remove(iter); *length = g_slist_length(list); if (0 == *length) { g_slist_foreach(list, _contacts_free_query_email_struct_all, NULL); g_slist_free(list); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } *contact_email_array = malloc(sizeof(pcontact_query_email_s) * (*length + 1)); if (NULL == *contact_email_array) { g_slist_foreach(list, _contacts_free_query_email_struct_all, NULL); g_slist_free(list); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } GSList *cursor = list; int i = 0; for (;cursor;cursor=g_slist_next(cursor)) (*contact_email_array)[i++] = cursor->data; (*contact_email_array)[i] = NULL; g_slist_free(list); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } int contact_search_contact_by_number(int address_book_db_id, const char *number_to_find, pcontact_query_number_s **contact_number_array, int *length) { CONTACTS_NULL_ARG_CHECK(number_to_find); CONTACTS_NULL_ARG_CHECK(contact_number_array); CONTACTS_NULL_ARG_CHECK(length); CTSiter *iter = NULL; CTSfilter *filter = NULL; if (ADDRESS_BOOK_FILTER_ALL == address_book_db_id) filter = contacts_svc_list_str_filter_new(CTS_FILTERED_NUMBERINFOS_WITH_NUM, number_to_find, CTS_LIST_FILTER_NONE); else filter = contacts_svc_list_str_filter_new(CTS_FILTERED_NUMBERINFOS_WITH_NUM, number_to_find, CTS_LIST_FILTER_ADDRESBOOK_ID_INT, address_book_db_id, CTS_LIST_FILTER_NONE); if (CTS_SUCCESS != contacts_svc_get_list_with_filter(filter, &iter)) { contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } GSList *numlist = NULL; while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_number_s *query_data = NULL; query_data = malloc(sizeof(contact_query_number_s)); if (NULL == query_data) { g_slist_foreach(numlist, _contacts_free_query_number_struct_all, NULL); g_slist_free(numlist); contacts_svc_value_free(foreach_data); contacts_svc_iter_remove(iter); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_NUM_CONTACT_ID_INT); query_data->address_book_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_OSP_ADDRESSBOOK_ID_INT); query_data->first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_CONTACT_FIRST_STR)); query_data->last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_CONTACT_LAST_STR)); query_data->display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_CONTACT_DISPLAY_STR)); query_data->contact_image_path= _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_CONTACT_IMG_PATH_STR)); query_data->phone_number = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_NUM_NUMBER_STR)); numlist = g_slist_append(numlist, query_data); contacts_svc_value_free(foreach_data); } contacts_svc_iter_remove(iter); *length = g_slist_length(numlist); if (0 == *length) { g_slist_foreach(numlist, _contacts_free_query_number_struct_all, NULL); g_slist_free(numlist); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } *contact_number_array = malloc(sizeof(pcontact_query_number_s) * (*length + 1)); if (NULL == *contact_number_array) { g_slist_foreach(numlist, _contacts_free_query_number_struct_all, NULL); g_slist_free(numlist); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } GSList *cursor = numlist; int i = 0; for (;cursor;cursor=g_slist_next(cursor)) (*contact_number_array)[i++] = cursor->data; (*contact_number_array)[i] = NULL; g_slist_free(numlist); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } int contact_search_contact_by_name(int address_book_db_id, const char *name_to_find, pcontact_query_name_s **contact_name_array, int *length) { CONTACTS_NULL_ARG_CHECK(name_to_find); CONTACTS_NULL_ARG_CHECK(contact_name_array); CONTACTS_NULL_ARG_CHECK(length); CTSiter *iter = NULL; CTSfilter *filter = NULL; if (ADDRESS_BOOK_FILTER_ALL == address_book_db_id) filter = contacts_svc_list_str_filter_new(CTS_FILTERED_CONTACTS_WITH_NAME, name_to_find, CTS_LIST_FILTER_NONE); else filter = contacts_svc_list_str_filter_new(CTS_FILTERED_CONTACTS_WITH_NAME, name_to_find, CTS_LIST_FILTER_ADDRESBOOK_ID_INT, address_book_db_id, CTS_LIST_FILTER_NONE); if (CTS_SUCCESS != contacts_svc_get_list_with_filter(filter, &iter)) { contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } GSList *namelist = NULL; while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_name_s *query_data = NULL; query_data = malloc(sizeof(contact_query_name_s)); if (NULL == query_data) { g_slist_foreach(namelist, _contacts_free_query_person_struct_all, NULL); g_slist_free(namelist); contacts_svc_value_free(foreach_data); contacts_svc_iter_remove(iter); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CONTACT_ID_INT); query_data->address_book_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_OSP_ADDRESSBOOK_ID_INT); query_data->first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_FIRST_STR)); query_data->last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_LAST_STR)); query_data->display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_DISPLAY_STR)); query_data->contact_image_path= _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_IMG_PATH_STR)); namelist = g_slist_append(namelist, query_data); contacts_svc_value_free(foreach_data); } contacts_svc_iter_remove(iter); *length = g_slist_length(namelist); if (0 == *length) { g_slist_foreach(namelist, _contacts_free_query_person_struct_all, NULL); g_slist_free(namelist); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } *contact_name_array = malloc(sizeof(pcontact_query_name_s) * (*length + 1)); if (NULL == *contact_name_array) { g_slist_foreach(namelist, _contacts_free_query_person_struct_all, NULL); g_slist_free(namelist); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } GSList *cursor = namelist; int i = 0; for (;cursor;cursor=g_slist_next(cursor)) (*contact_name_array)[i++] = cursor->data; (*contact_name_array)[i] = NULL; g_slist_free(namelist); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } int contact_search_contact_by_group(int group_db_id, pcontact_query_name_s **contact_name_array, int *length) { CONTACTS_NULL_ARG_CHECK(contact_name_array); CONTACTS_NULL_ARG_CHECK(length); CONTACTS_INVALID_ARG_CHECK(group_db_id < 0); CTSiter *iter = NULL; CTSfilter *filter = NULL; filter = contacts_svc_list_filter_new(CTS_FILTERED_ALL_CONTACT, CTS_LIST_FILTER_GROUP_ID_INT, group_db_id, CTS_LIST_FILTER_NONE); if (CTS_SUCCESS != contacts_svc_get_list_with_filter(filter, &iter)) { contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } GSList *namelist = NULL; while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_name_s *query_data = NULL; query_data = malloc(sizeof(contact_query_name_s)); if (NULL == query_data) { g_slist_foreach(namelist, _contacts_free_query_person_struct_all, NULL); g_slist_free(namelist); contacts_svc_value_free(foreach_data); contacts_svc_iter_remove(iter); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CONTACT_ID_INT); query_data->address_book_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CONTACT_ADDRESSBOOK_ID_INT); query_data->first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_FIRST_STR)); query_data->last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_LAST_STR)); query_data->display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_DISPLAY_STR)); query_data->contact_image_path= _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_IMG_PATH_STR)); namelist = g_slist_append(namelist, query_data); contacts_svc_value_free(foreach_data); } contacts_svc_iter_remove(iter); *length = g_slist_length(namelist); if (0 == *length) { g_slist_foreach(namelist, _contacts_free_query_person_struct_all, NULL); g_slist_free(namelist); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } *contact_name_array = malloc(sizeof(pcontact_query_name_s) * (*length + 1)); if (NULL == *contact_name_array) { g_slist_foreach(namelist, _contacts_free_query_person_struct_all, NULL); g_slist_free(namelist); contacts_svc_list_filter_free(filter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } GSList *cursor = namelist; int i = 0; for (;cursor;cursor=g_slist_next(cursor)) (*contact_name_array)[i++] = cursor->data; (*contact_name_array)[i] = NULL; g_slist_free(namelist); contacts_svc_list_filter_free(filter); return CONTACTS_ERROR_NONE; } int contact_search_contact_by_version(int address_book_db_id, int contacts_db_version, pcontact_query_version_s **contact_version_array, int *length) { CONTACTS_NULL_ARG_CHECK(length); CONTACTS_NULL_ARG_CHECK(contact_version_array); CONTACTS_INVALID_ARG_CHECK(contacts_db_version < 0); CTSiter *iter = NULL; GSList *versionlist = NULL; *length = 0; if(CTS_SUCCESS != contacts_svc_get_updated_contacts(address_book_db_id, contacts_db_version, &iter)) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; } while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); if(foreach_data == NULL) { break; } contact_query_version_s *query_data = NULL; query_data = malloc(sizeof(contact_query_version_s)); if (NULL == query_data) { g_slist_free(versionlist); contacts_svc_value_free(foreach_data); contacts_svc_iter_remove(iter); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CHANGE_ID_INT); query_data->changed_type = contacts_svc_value_get_int(foreach_data, CTS_LIST_CHANGE_TYPE_INT); query_data->contacts_db_version = contacts_svc_value_get_int(foreach_data, CTS_LIST_CHANGE_VER_INT); query_data->address_book_db_id = address_book_db_id; versionlist = g_slist_append(versionlist, query_data); contacts_svc_value_free(foreach_data); } contacts_svc_iter_remove(iter); *length = g_slist_length(versionlist); if (0 == *length) { g_slist_free(versionlist); return CONTACTS_ERROR_NONE; } *contact_version_array = malloc(sizeof(pcontact_query_version_s) * (*length + 1)); if (NULL == *contact_version_array) { g_slist_free(versionlist); LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); return CONTACTS_ERROR_OUT_OF_MEMORY; } GSList *cursor = versionlist; int i = 0; for (;cursor;cursor=g_slist_next(cursor)) (*contact_version_array)[i++] = cursor->data; (*contact_version_array)[i] = NULL; g_slist_free(versionlist); return CONTACTS_ERROR_NONE; }