diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/contacts.c | 174 | ||||
-rwxr-xr-x | src/contacts_contact.c | 138 | ||||
-rwxr-xr-x | src/contacts_event.c | 56 | ||||
-rwxr-xr-x | src/contacts_group.c | 239 | ||||
-rwxr-xr-x | src/contacts_messenger.c | 20 | ||||
-rwxr-xr-x | src/contacts_number.c | 4 | ||||
-rwxr-xr-x | src/contacts_private.c | 51 | ||||
-rwxr-xr-x | src/contacts_search.c | 818 |
8 files changed, 1314 insertions, 186 deletions
diff --git a/src/contacts.c b/src/contacts.c index 35a5222..7d1ca55 100755 --- a/src/contacts.c +++ b/src/contacts.c @@ -64,6 +64,27 @@ int contacts_get_db_version(int* contacts_db_version) return CONTACTS_ERROR_NONE; } +int contacts_get_name_display_order(contacts_name_display_order_e *name_display_order) +{ + CONTACTS_NULL_ARG_CHECK(name_display_order); + + if ((*name_display_order = contacts_svc_get_order(CTS_ORDER_OF_DISPLAY)) < 0) { + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; + } + return CONTACTS_ERROR_NONE; +} + +int contacts_set_name_display_order(contacts_name_display_order_e name_display_order) +{ + CONTACTS_INVALID_ARG_CHECK(name_display_order < 0 || 1 < name_display_order); + if (CTS_SUCCESS == contacts_svc_set_order(CTS_ORDER_OF_DISPLAY, name_display_order)) { + return CONTACTS_ERROR_NONE; + } + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; +} + int contacts_add_address_book_db_changed_cb(contacts_db_changed_cb callback, void *user_data) { CONTACTS_NULL_ARG_CHECK(callback); @@ -151,12 +172,36 @@ int contacts_add_group_db_changed_cb(contacts_db_changed_cb callback, void *user int contacts_remove_group_db_changed_cb(contacts_db_changed_cb callback) { CONTACTS_NULL_ARG_CHECK(callback); - + if(contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_GROUP_CHANGE, callback) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; - } - - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contacts_add_group_relation_changed_cb(contacts_db_changed_cb callback, void *user_data) +{ + CONTACTS_NULL_ARG_CHECK(callback); + + if(contacts_svc_subscribe_change(CTS_SUBSCRIBE_GROUP_RELATION_CHANGE, callback, user_data) == CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contacts_remove_group_relation_changed_cb(contacts_db_changed_cb callback) +{ + CONTACTS_NULL_ARG_CHECK(callback); + + if(contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_GROUP_RELATION_CHANGE, callback) == CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); return CONTACTS_ERROR_INVALID_PARAMETER; } @@ -253,6 +298,20 @@ int contacts_address_book_get_from_db(int address_book_db_id, contacts_address_b return CONTACTS_ERROR_INVALID_PARAMETER; } +int contacts_address_book_create(contacts_address_book_h *address_book) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + + CTSvalue* ret = contacts_svc_value_new(CTS_VALUE_ADDRESSBOOK); + if(ret == NULL) { + LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); + return CONTACTS_ERROR_OUT_OF_MEMORY; + } + *address_book = (contacts_address_book_h)ret; + + return CONTACTS_ERROR_NONE; +} + int contacts_address_book_destroy(contacts_address_book_h address_book) { CONTACTS_NULL_ARG_CHECK(address_book); @@ -265,6 +324,70 @@ int contacts_address_book_destroy(contacts_address_book_h address_book) return CONTACTS_ERROR_INVALID_PARAMETER; } +int contacts_address_book_insert_to_db(contacts_address_book_h address_book, int *address_book_db_id) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + + int ret; + CTSvalue* value = (CTSvalue *)address_book; + + ret = contacts_svc_insert_addressbook(value); + if(ret < CTS_SUCCESS) { + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; + } + *address_book_db_id = ret; + return CONTACTS_ERROR_NONE; +} + +int contacts_address_book_delete_from_db(int address_book_db_id) +{ + CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0); + + int ret; + ret = contacts_svc_delete_addressbook(address_book_db_id); + if (CTS_SUCCESS == ret) + return CONTACTS_ERROR_NONE; + else if (CTS_ERR_DB_FAILED == ret) { + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contacts_address_book_update_to_db(contacts_address_book_h address_book) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + + int ret; + ret = contacts_svc_update_addressbook((CTSvalue*)address_book); + if (CTS_SUCCESS == ret) + return CONTACTS_ERROR_NONE; + else if (CTS_ERR_DB_FAILED == ret) { + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; + } + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + + +int contacts_address_book_set_type(contacts_address_book_h address_book, contacts_address_book_type_e address_book_type) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + + int ret; + ret = contacts_svc_value_set_int((CTSvalue *)address_book, CTS_ADDRESSBOOK_VAL_ACC_TYPE_INT, address_book_type); + if (CTS_SUCCESS != ret) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + return CONTACTS_ERROR_NONE; +} + int contacts_address_book_get_db_id(contacts_address_book_h address_book, int *address_book_db_id) { CONTACTS_NULL_ARG_CHECK(address_book); @@ -289,6 +412,21 @@ int contacts_address_book_get_name(contacts_address_book_h address_book, char ** return CONTACTS_ERROR_NONE; } +int contacts_address_book_set_name(contacts_address_book_h address_book, const char *address_book_name) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + CONTACTS_NULL_ARG_CHECK(address_book_name); + + int ret = contacts_svc_value_set_str((CTSvalue*)address_book, CTS_ADDRESSBOOK_VAL_NAME_STR, address_book_name); + if (CTS_SUCCESS != ret) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + return CONTACTS_ERROR_NONE; +} + + int contacts_address_book_get_read_only(contacts_address_book_h address_book, bool *is_read_only) { CONTACTS_NULL_ARG_CHECK(address_book); @@ -300,6 +438,20 @@ int contacts_address_book_get_read_only(contacts_address_book_h address_book, bo return CONTACTS_ERROR_NONE; } +int contacts_address_book_set_read_only(contacts_address_book_h address_book, bool is_read_only) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + + int ret = contacts_svc_value_set_int((CTSvalue*)address_book, CTS_ADDRESSBOOK_VAL_MODE_INT, is_read_only); + if (CTS_SUCCESS != ret) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + return CONTACTS_ERROR_NONE; +} + + int contacts_address_book_get_type(contacts_address_book_h address_book, contacts_address_book_type_e *address_book_type) { CONTACTS_NULL_ARG_CHECK(address_book); @@ -320,7 +472,19 @@ int contacts_address_book_get_account_db_id(contacts_address_book_h address_book *account_db_id = contacts_svc_value_get_int((CTSvalue*)address_book, CTS_ADDRESSBOOK_VAL_ACC_ID_INT); if(*account_db_id < 0) { *account_db_id = 0; - } + } + return CONTACTS_ERROR_NONE; +} + +int contacts_address_book_set_account_db_id(contacts_address_book_h address_book, int account_db_id) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + int ret = contacts_svc_value_set_int((CTSvalue*)address_book, CTS_ADDRESSBOOK_VAL_ACC_ID_INT, account_db_id); + if (CTS_SUCCESS != ret) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + return CONTACTS_ERROR_NONE; } diff --git a/src/contacts_contact.c b/src/contacts_contact.c index 5b66d59..7aaa8f5 100755 --- a/src/contacts_contact.c +++ b/src/contacts_contact.c @@ -478,14 +478,39 @@ int contact_get_birthday(contact_h contact, contact_birthday_h* birthday) *birthday = NULL; GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EVENT_LIST, &cursor); - if(cursor == NULL) { - return CONTACTS_ERROR_NONE; + + for (;cursor;cursor=cursor->next) { + if (CTS_EVENT_TYPE_BIRTH == contacts_svc_value_get_int(cursor->data, CTS_EVENT_VAL_TYPE_INT)) + break; } - *birthday = (contact_birthday_h)cursor->data; - - return CONTACTS_ERROR_NONE; + + if (NULL != cursor) + *birthday = (contact_birthday_h)cursor->data; + + return CONTACTS_ERROR_NONE; } +int contact_get_anniversary(contact_h contact, contact_anniversary_h* anniversary) +{ + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(anniversary); + + *anniversary = NULL; + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EVENT_LIST, &cursor); + + for (;cursor;cursor=cursor->next) { + if (CTS_EVENT_TYPE_ANNIVERSARY == contacts_svc_value_get_int(cursor->data, CTS_EVENT_VAL_TYPE_INT)) + break; + } + + if (NULL != cursor) + *anniversary = (contact_anniversary_h)cursor->data; + + return CONTACTS_ERROR_NONE; +} + + int contact_set_birthday(contact_h contact, contact_birthday_h birthday) { CONTACTS_NULL_ARG_CHECK(contact); @@ -521,25 +546,81 @@ int contact_set_birthday(contact_h contact, contact_birthday_h birthday) return ret; } -int contact_unset_birthday(contact_h contact) +int contact_set_anniversary(contact_h contact, contact_anniversary_h anniversary) { CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(anniversary); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EVENT_LIST, &cursor); + int ret = 0; + bool need_to_free = false; + if(cursor == NULL) { + need_to_free = true; + } else { + for(;cursor;cursor=g_slist_next(cursor)) { + if(contacts_svc_value_get_int((CTSvalue*)cursor->data, CTS_EVENT_VAL_TYPE_INT) == CTS_EVENT_TYPE_ANNIVERSARY) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_EVENT_VAL_DELETE_BOOL, true); + } + } + } + + cursor = g_slist_append((GSList*)cursor, anniversary); + + if(contacts_svc_struct_store_list((CTSstruct*)contact, CTS_CF_EVENT_LIST, cursor) == CTS_SUCCESS) { + ret = CONTACTS_ERROR_NONE; + } else { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + ret = CONTACTS_ERROR_INVALID_PARAMETER; + } + + if(need_to_free == true) { + g_slist_free((GSList*)cursor); + } + + return ret; +} + + +int contact_unset_birthday(contact_h contact) +{ + CONTACTS_NULL_ARG_CHECK(contact); + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EVENT_LIST, &cursor); if(cursor == NULL) { return CONTACTS_ERROR_NONE; } else { for(;cursor;cursor=g_slist_next(cursor)) { if(contacts_svc_value_get_int((CTSvalue*)cursor->data, CTS_EVENT_VAL_TYPE_INT) == CTS_EVENT_TYPE_BIRTH) { contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_EVENT_VAL_DELETE_BOOL, true); - } + } + } + } + + return CONTACTS_ERROR_NONE; +} + +int contact_unset_anniversary(contact_h contact) +{ + CONTACTS_NULL_ARG_CHECK(contact); + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EVENT_LIST, &cursor); + if(cursor == NULL) { + return CONTACTS_ERROR_NONE; + } else { + for(;cursor;cursor=g_slist_next(cursor)) { + if(contacts_svc_value_get_int((CTSvalue*)cursor->data, CTS_EVENT_VAL_TYPE_INT) == CTS_EVENT_TYPE_ANNIVERSARY) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_EVENT_VAL_DELETE_BOOL, true); + } } } return CONTACTS_ERROR_NONE; } + int contact_add_messenger(contact_h contact, contact_messenger_h messenger) { CONTACTS_NULL_ARG_CHECK(contact); @@ -875,6 +956,18 @@ int contact_set_note(contact_h contact, const char* note) return CONTACTS_ERROR_INVALID_PARAMETER; } +int contact_get_last_modified_time(contact_h contact, time_t *last_modified_time) +{ + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(last_modified_time); + + CTSvalue* base = NULL; + if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base) != CTS_SUCCESS) + return CONTACTS_ERROR_NONE; + + *last_modified_time = (time_t)contacts_svc_value_get_int(base, CTS_BASE_VAL_CHANGED_TIME_INT); + return CONTACTS_ERROR_NONE; +} int contact_get_total_count_from_db(int* count) { @@ -884,8 +977,6 @@ int contact_get_total_count_from_db(int* count) return CONTACTS_ERROR_NONE; } - - int contact_get_from_vcard(const char *vcard_stream, contact_h *contact) { CONTACTS_NULL_ARG_CHECK(vcard_stream); @@ -1061,3 +1152,32 @@ int contact_unset_frequent_contact(int contact_db_id) return CONTACTS_ERROR_NONE; } +int contact_set_group_relation_to_db(int contact_db_id, int group_db_id) +{ + CONTACTS_INVALID_ARG_CHECK(contact_db_id < 1); + CONTACTS_INVALID_ARG_CHECK(group_db_id < 1); + + int ret = contacts_svc_group_set_relation(group_db_id, contact_db_id); + + if (ret == CTS_SUCCESS) + return CONTACTS_ERROR_NONE; + + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; +} + +int contact_unset_group_relation_to_db(int contact_db_id, int group_db_id) +{ + CONTACTS_INVALID_ARG_CHECK(contact_db_id < 1); + CONTACTS_INVALID_ARG_CHECK(group_db_id < 1); + + int ret = contacts_svc_group_unset_relation(group_db_id, contact_db_id); + + if (ret == CTS_SUCCESS) + return CONTACTS_ERROR_NONE; + + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; +} + + diff --git a/src/contacts_event.c b/src/contacts_event.c index 7ca2228..6d791c3 100755 --- a/src/contacts_event.c +++ b/src/contacts_event.c @@ -44,6 +44,22 @@ int contact_birthday_create(contact_birthday_h* birthday) return CONTACTS_ERROR_NONE; } +int contact_anniversary_create(contact_anniversary_h* anniversary) +{ + CONTACTS_NULL_ARG_CHECK(anniversary); + + CTSvalue* ret = contacts_svc_value_new(CTS_VALUE_EVENT); + if(ret == NULL) { + LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); + return CONTACTS_ERROR_OUT_OF_MEMORY; + } + contacts_svc_value_set_int(ret, CTS_EVENT_VAL_TYPE_INT, CTS_EVENT_TYPE_ANNIVERSARY); + *anniversary = (contact_anniversary_h)ret; + + return CONTACTS_ERROR_NONE; +} + + int contact_birthday_destroy(contact_birthday_h birthday) { CONTACTS_NULL_ARG_CHECK(birthday); @@ -56,6 +72,17 @@ int contact_birthday_destroy(contact_birthday_h birthday) return CONTACTS_ERROR_INVALID_PARAMETER; } +int contact_anniversary_destroy(contact_anniversary_h anniversary) +{ + CONTACTS_NULL_ARG_CHECK(anniversary); + + if(contacts_svc_value_free((CTSvalue*)anniversary) == CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} int contact_birthday_get_date(contact_birthday_h birthday, int *year, int *month, int *day) { @@ -76,6 +103,26 @@ int contact_birthday_get_date(contact_birthday_h birthday, int *year, int *month return CONTACTS_ERROR_NONE; } +int contact_anniversary_get_date(contact_anniversary_h anniversary, int *year, int *month, int *day) +{ + CONTACTS_NULL_ARG_CHECK(anniversary); + CONTACTS_NULL_ARG_CHECK(year); + CONTACTS_NULL_ARG_CHECK(month); + CONTACTS_NULL_ARG_CHECK(day); + + CTSvalue * CTSevent = (CTSvalue *)anniversary; + int date = contacts_svc_value_get_int(CTSevent, CTS_EVENT_VAL_DATE_INT); + if(date == 0) { + *year = *month = *day = 0; + } else { + *year = date / 10000; + *month = date % 10000 / 100; + *day = date % 100; + } + return CONTACTS_ERROR_NONE; +} + + int contact_birthday_set_date(contact_birthday_h birthday, int year, int month, int day) { CONTACTS_NULL_ARG_CHECK(birthday); @@ -86,3 +133,12 @@ int contact_birthday_set_date(contact_birthday_h birthday, int year, int month, return CONTACTS_ERROR_NONE; } +int contact_anniversary_set_date(contact_anniversary_h anniversary, int year, int month, int day) +{ + CONTACTS_NULL_ARG_CHECK(anniversary); + + CTSvalue * CTSevent = (CTSvalue *)anniversary; + contacts_svc_value_set_int(CTSevent, CTS_EVENT_VAL_DATE_INT, year*10000 + month*100 + day); + + return CONTACTS_ERROR_NONE; +} diff --git a/src/contacts_group.c b/src/contacts_group.c index 8d6cf61..e1e9e68 100755 --- a/src/contacts_group.c +++ b/src/contacts_group.c @@ -22,6 +22,7 @@ #include <stdlib.h> #include <string.h> #include <dlog.h> +#include <contacts_private.h> #ifdef LOG_TAG #undef LOG_TAG @@ -184,6 +185,18 @@ int contacts_group_set_ringtonepath(contacts_group_h group, const char* ringtone return CONTACTS_ERROR_INVALID_PARAMETER; } +int contacts_group_get_count(int address_book_db_id, int *count) +{ + CONTACTS_NULL_ARG_CHECK(count); + + if(ADDRESS_BOOK_FILTER_ALL == address_book_db_id) + *count = contacts_svc_count(CTS_GET_COUNT_ALL_GROUP); + else + *count = contacts_svc_count_with_int(CTS_GET_COUNT_GROUPS_IN_ADDRESSBOOK, address_book_db_id); + + return CONTACTS_ERROR_NONE; +} + int contacts_group_get_member_count_from_db(contacts_group_h group, int* count) { CONTACTS_NULL_ARG_CHECK(group); @@ -282,5 +295,229 @@ int contacts_group_query_group_by_address_book(contacts_foreach_query_group_cb c } contacts_svc_iter_remove(iter); - return CONTACTS_ERROR_NONE;} + return CONTACTS_ERROR_NONE; +} + +int contacts_group_free_query_group_array(pcontacts_query_group_s *group_array) +{ + CONTACTS_NULL_ARG_CHECK(group_array); + int i=0; + while (group_array[i] != NULL) { + _contacts_free_query_group_struct_member_only((contacts_query_group_s *)group_array[i]); + free(group_array[i++]); + } + free(group_array); + return CONTACTS_ERROR_NONE; +} + +int contacts_group_free_query_version_array(pcontacts_group_query_version_s *group_version_array) +{ + CONTACTS_NULL_ARG_CHECK(group_version_array); + int i=0; + while (group_version_array[i] != NULL) { + free(group_version_array[i++]); + } + free(group_version_array); + return CONTACTS_ERROR_NONE; +} + +int contacts_group_search_group_by_address_book(int address_book_db_id, pcontacts_query_group_s **group_array, int *length) +{ + CONTACTS_NULL_ARG_CHECK(length); + CONTACTS_NULL_ARG_CHECK(group_array); + + CTSiter *iter = NULL; + + if (address_book_db_id < 0) { + if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_GROUP, &iter)) { + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; + } + } + else { + if(CTS_SUCCESS != contacts_svc_get_list_with_int(CTS_LIST_GROUPS_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; + } + } + + GSList *grouplist = NULL; + while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { + CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); + if(foreach_data == NULL) { + break; + } + + contacts_query_group_s *query_data = NULL; + query_data = malloc(sizeof(contacts_query_group_s)); + if (NULL == query_data) { + g_slist_foreach(grouplist, _contacts_free_query_group_struct_all, NULL); + g_slist_free(grouplist); + 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->group_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_GROUP_ID_INT); + query_data->address_book_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_GROUP_ADDRESSBOOK_ID_INT); + query_data->group_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_GROUP_NAME_STR)); + query_data->group_ringtonepath = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_GROUP_RINGTONE_STR)); + + grouplist = g_slist_append(grouplist, query_data); + contacts_svc_value_free(foreach_data); + } + contacts_svc_iter_remove(iter); + + *length = g_slist_length(grouplist); + if (0 == *length) { + g_slist_foreach(grouplist, _contacts_free_query_group_struct_all, NULL); + g_slist_free(grouplist); + return CONTACTS_ERROR_NONE; + } + + *group_array = malloc(sizeof(pcontacts_query_group_s) * (*length + 1)); + if (NULL == group_array) { + g_slist_foreach(grouplist, _contacts_free_query_group_struct_all, NULL); + g_slist_free(grouplist); + LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); + return CONTACTS_ERROR_OUT_OF_MEMORY; + } + + GSList *cursor = grouplist; + int i = 0; + for (;cursor;cursor=g_slist_next(cursor)) + (*group_array)[i++] = cursor->data; + (*group_array)[i] = NULL; + g_slist_free(grouplist); + return CONTACTS_ERROR_NONE; +} + +int contacts_svc_get_updated_groups(int addressbook_id, int version, CTSiter **iter); +int contacts_group_search_group_by_version(int address_book_db_id, int contacts_db_version, + pcontacts_group_query_version_s **group_array, int *length) +{ + CONTACTS_NULL_ARG_CHECK(length); + CONTACTS_NULL_ARG_CHECK(group_array); + CONTACTS_INVALID_ARG_CHECK(contacts_db_version < 0); + + CTSiter *iter = NULL; + GSList *versionlist = NULL; + *length = 0; + + if(CTS_SUCCESS != contacts_svc_get_updated_groups(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; + } + + contacts_group_query_version_s *query_data = NULL; + query_data = malloc(sizeof(contacts_group_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->group_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; + } + + *group_array = malloc(sizeof(pcontacts_group_query_version_s) * (*length + 1)); + if (NULL == group_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)) + (*group_array)[i++] = cursor->data; + (*group_array)[i] = NULL; + g_slist_free(versionlist); + + return CONTACTS_ERROR_NONE; +} + +int contacts_svc_group_get_relation_changes(int addressbook_id, int version, CTSiter **iter); +int contacts_group_search_relation_changed_group_by_version(int address_book_db_id, int contacts_db_version, + pcontacts_group_query_version_s **group_array, int *length) +{ + CONTACTS_NULL_ARG_CHECK(length); + CONTACTS_NULL_ARG_CHECK(group_array); + CONTACTS_INVALID_ARG_CHECK(contacts_db_version < 0); + + CTSiter *iter = NULL; + GSList *versionlist = NULL; + *length = 0; + + if(CTS_SUCCESS != contacts_svc_group_get_relation_changes(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; + } + + contacts_group_query_version_s *query_data = NULL; + query_data = malloc(sizeof(contacts_group_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->group_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; + } + + *group_array = malloc(sizeof(pcontacts_group_query_version_s) * (*length + 1)); + if (NULL == group_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)) + (*group_array)[i++] = cursor->data; + (*group_array)[i] = NULL; + g_slist_free(versionlist); + + return CONTACTS_ERROR_NONE; +} diff --git a/src/contacts_messenger.c b/src/contacts_messenger.c index 9d38375..89e167c 100755 --- a/src/contacts_messenger.c +++ b/src/contacts_messenger.c @@ -101,6 +101,26 @@ int contact_messenger_set_type(contact_messenger_h messenger, contact_messenger_ return CONTACTS_ERROR_INVALID_PARAMETER; } +int contact_messenger_get_provider_name(contact_messenger_h messenger, char **provider_name) +{ + CONTACTS_NULL_ARG_CHECK(messenger); + CONTACTS_NULL_ARG_CHECK(provider_name); + + *provider_name = _contacts_safe_strdup(contacts_svc_value_get_str((CTSvalue*)messenger, CTS_MESSENGER_VAL_SERVICE_NAME_STR)); + return CONTACTS_ERROR_NONE; +} + +int contact_messenger_set_provider_name(contact_messenger_h messenger, const char *provider_name) +{ + CONTACTS_NULL_ARG_CHECK(messenger); + + if (contacts_svc_value_set_str((CTSvalue*)messenger, CTS_MESSENGER_VAL_SERVICE_NAME_STR, provider_name) == CTS_SUCCESS) + return CONTACTS_ERROR_NONE; + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + int contact_messenger_iterator_next(contact_messenger_iterator_h* messenger_iterator, contact_messenger_h* messenger) { CONTACTS_NULL_ARG_CHECK(messenger_iterator); diff --git a/src/contacts_number.c b/src/contacts_number.c index 408f056..1f57a1e 100755 --- a/src/contacts_number.c +++ b/src/contacts_number.c @@ -61,7 +61,7 @@ int contact_number_destroy(contact_number_h number) return CONTACTS_ERROR_INVALID_PARAMETER; } -int contact_number_get_type(contact_number_h number, contact_number_type_e* type) +int contact_number_get_type(contact_number_h number, unsigned int* type) { if(number == NULL || type == NULL) { LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); @@ -72,7 +72,7 @@ int contact_number_get_type(contact_number_h number, contact_number_type_e* type return CONTACTS_ERROR_NONE; } -int contact_number_set_type(contact_number_h number, contact_number_type_e type) +int contact_number_set_type(contact_number_h number, unsigned int type) { if(number == NULL) { LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); diff --git a/src/contacts_private.c b/src/contacts_private.c index 78a7561..2b2d5c9 100755 --- a/src/contacts_private.c +++ b/src/contacts_private.c @@ -28,10 +28,11 @@ void _contacts_set_query_person_struct(contact_query_name_s* contact, CTSvalue* contact->first_name = _contacts_safe_strdup(contacts_svc_value_get_str(value, CTS_LIST_CONTACT_FIRST_STR)); contact->last_name = _contacts_safe_strdup(contacts_svc_value_get_str(value, CTS_LIST_CONTACT_LAST_STR)); contact->display_name = _contacts_safe_strdup(contacts_svc_value_get_str(value, CTS_LIST_CONTACT_DISPLAY_STR)); + contact->address_book_db_id = contacts_svc_value_get_int(value, CTS_LIST_CONTACT_ADDRESSBOOK_ID_INT); contact->contact_image_path = _contacts_safe_strdup(contacts_svc_value_get_str(value, CTS_LIST_CONTACT_IMG_PATH_STR)); } -void _contacts_free_query_preson_struct_member_only(contact_query_name_s* person) +void _contacts_free_query_person_struct_member_only(contact_query_name_s* person) { person->contact_db_id = -1; _contacts_safe_free(person->first_name); @@ -50,7 +51,18 @@ void _contacts_free_query_number_struct_member_only(contact_query_number_s* cont _contacts_safe_free(contact->contact_image_path); } -void _contacts_free_query_preson_struct_all(gpointer data, gpointer user_data) +void _contacts_free_query_email_struct_member_only(contact_query_email_s* email) +{ + email->contact_db_id = -1; + _contacts_safe_free(email->first_name); + _contacts_safe_free(email->last_name); + _contacts_safe_free(email->display_name); + _contacts_safe_free(email->contact_image_path); + _contacts_safe_free(email->email_address); +} + + +void _contacts_free_query_person_struct_all(gpointer data, gpointer user_data) { if(data == NULL) return; @@ -72,8 +84,41 @@ void _contacts_free_query_number_struct_all(gpointer data, gpointer user_data) _contacts_safe_free(person->first_name); _contacts_safe_free(person->last_name); _contacts_safe_free(person->display_name); - _contacts_safe_free(person->phone_number); _contacts_safe_free(person->contact_image_path); + _contacts_safe_free(person->phone_number); + _contacts_safe_free(data); +} + +void _contacts_free_query_email_struct_all(gpointer data, gpointer user_data) +{ + if(data == NULL) + return; + contact_query_email_s* email = (contact_query_email_s*)data; + email->contact_db_id = -1; + _contacts_safe_free(email->first_name); + _contacts_safe_free(email->last_name); + _contacts_safe_free(email->display_name); + _contacts_safe_free(email->contact_image_path); + _contacts_safe_free(email->email_address); + _contacts_safe_free(data); +} + + +void _contacts_free_query_group_struct_member_only(contacts_query_group_s* group) +{ + group->group_db_id = -1; + _contacts_safe_free(group->group_name); + _contacts_safe_free(group->group_ringtonepath); +} + +void _contacts_free_query_group_struct_all(gpointer data, gpointer user_data) +{ + if(data == NULL) + return; + contacts_query_group_s* group = (contacts_query_group_s*)data; + group->group_db_id = -1; + _contacts_safe_free(group->group_name); + _contacts_safe_free(group->group_ringtonepath); _contacts_safe_free(data); } diff --git a/src/contacts_search.c b/src/contacts_search.c index d50232c..f48912e 100755 --- a/src/contacts_search.c +++ b/src/contacts_search.c @@ -14,7 +14,6 @@ * limitations under the License. */ - #include <tizen.h> #include <stdlib.h> #include <contacts.h> @@ -47,7 +46,7 @@ int contact_foreach_contact_from_db(contact_foreach_query_name_cb cb, void* user 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_preson_struct_all, 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); @@ -68,167 +67,12 @@ int contact_foreach_contact_from_db(contact_foreach_query_name_cb cb, void* user break; } } - g_slist_foreach(contactlist, _contacts_free_query_preson_struct_all, NULL); - g_slist_free(contactlist); - - return CONTACTS_ERROR_NONE; -} - -int contact_get_all_contact_from_db(contact_query_name_array *contact_array, int *length) -{ - CONTACTS_NULL_ARG_CHECK(contact_array); - CONTACTS_NULL_ARG_CHECK(length); - - *contact_array = NULL; - *length = 0; - CTSiter *iter = NULL; - 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_preson_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); - - *length = g_slist_length(contactlist); - if(*length == 0) { - g_slist_foreach(contactlist, _contacts_free_query_preson_struct_all, NULL); - g_slist_free(contactlist); - return CONTACTS_ERROR_NONE; - } - *contact_array = malloc(sizeof(contact_query_name_s*) * (*length)); - if(*contact_array == NULL) { - g_slist_foreach(contactlist, _contacts_free_query_preson_struct_all, NULL); - g_slist_free(contactlist); - LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); - return CONTACTS_ERROR_OUT_OF_MEMORY; - } - - GSList *cursor = contactlist; - contact_query_name_s** pcontact_array = *contact_array; - int i = 0; - for(;cursor;cursor=g_slist_next(cursor)) { - pcontact_array[i] = (contact_query_name_s*)(cursor->data); - i++; - } - g_slist_free(contactlist); - - return CONTACTS_ERROR_NONE; -} - -int contact_query_name_array_free(contact_query_name_array contact_array, int length) -{ - CONTACTS_NULL_ARG_CHECK(contact_array); - CONTACTS_INVALID_ARG_CHECK(length < 0); - - int i = 0; - for(;i<length; i++) { - _contacts_free_query_preson_struct_member_only(contact_array[i]); - free(contact_array[i]); - } - - free(contact_array); - return CONTACTS_ERROR_NONE; -} - -int contact_get_number_contact_from_db(contact_query_number_array *contact_number_array, int *length) -{ - CONTACTS_NULL_ARG_CHECK(contact_number_array); - CONTACTS_NULL_ARG_CHECK(length); - - *contact_number_array = NULL; - *length = 0; - 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 *contactlist = NULL; - while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { - CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); - - contact_query_number_s *query_data = NULL; - query_data = malloc(sizeof(contact_query_number_s)); - if(query_data == NULL) { - g_slist_foreach(contactlist, _contacts_free_query_number_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; - } - query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CONTACT_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->phone_number = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_NUM_OR_EMAIL_STR)); - query_data->contact_image_path = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_IMG_PATH_STR)); - - contactlist = g_slist_append(contactlist, query_data); - - contacts_svc_value_free(foreach_data); - } - contacts_svc_iter_remove(iter); - - *length = g_slist_length(contactlist); - if(*length == 0) { - g_slist_foreach(contactlist, _contacts_free_query_number_struct_all, NULL); - g_slist_free(contactlist); - return CONTACTS_ERROR_NONE; - } - *contact_number_array = malloc(sizeof(contact_query_number_s*) * (*length)); - if(*contact_number_array == NULL) { - g_slist_foreach(contactlist, _contacts_free_query_number_struct_all, NULL); - g_slist_free(contactlist); - LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); - return CONTACTS_ERROR_OUT_OF_MEMORY; - } - - GSList *cursor = contactlist; - contact_query_number_s** pcontact_array = *contact_number_array; - int i = 0; - for(;cursor;cursor=g_slist_next(cursor)) { - pcontact_array[i] = (contact_query_number_s*)(cursor->data); - i++; - } + g_slist_foreach(contactlist, _contacts_free_query_person_struct_all, NULL); g_slist_free(contactlist); return CONTACTS_ERROR_NONE; } -int contact_query_number_array_free(contact_query_number_array contact_number_array, int length) -{ - CONTACTS_NULL_ARG_CHECK(contact_number_array); - CONTACTS_INVALID_ARG_CHECK(length < 0); - - int i = 0; - for(;i<length; i++) { - _contacts_free_query_number_struct_member_only(contact_number_array[i]); - } - - free(contact_number_array); - 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); @@ -296,7 +140,7 @@ int contact_foreach_frequent_contact_from_db(contact_foreach_query_name_cb callb func_ret = callback(&query_data, user_data); contacts_svc_value_free(foreach_data); - _contacts_free_query_preson_struct_member_only(&query_data); + _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; @@ -330,7 +174,7 @@ int contact_query_contact_by_name(contact_foreach_query_name_cb cb, const char* func_ret = cb(&query_data, user_data); contacts_svc_value_free(foreach_data); - _contacts_free_query_preson_struct_member_only(&query_data); + _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; @@ -364,7 +208,7 @@ int contact_query_contact_by_group(contact_foreach_query_name_cb cb, int group_i func_ret = cb(&query_data, user_data); contacts_svc_value_free(foreach_data); - _contacts_free_query_preson_struct_member_only(&query_data); + _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; @@ -378,7 +222,6 @@ int contact_query_contact_by_group(contact_foreach_query_name_cb cb, int group_i 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); - CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0); CTSiter *iter = NULL; int func_ret = 0; @@ -399,7 +242,7 @@ int contact_query_contact_by_address_book(contact_foreach_query_name_cb callback func_ret = callback(&query_data, user_data); contacts_svc_value_free(foreach_data); - _contacts_free_query_preson_struct_member_only(&query_data); + _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; @@ -499,7 +342,6 @@ int contact_query_contact_by_number(contact_foreach_query_number_cb cb, const ch 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); - CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0); CTSiter *iter = NULL; int func_ret = 0; @@ -535,7 +377,6 @@ int contact_query_contact_by_version(contact_foreach_query_version_cb cb, int ad 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); - CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0); CTSiter *iter = NULL; int func_ret = 0; @@ -556,7 +397,7 @@ int contact_query_contact_not_related_to_group(contact_foreach_query_name_cb cal func_ret = callback(&query_data, user_data); contacts_svc_value_free(foreach_data); - _contacts_free_query_preson_struct_member_only(&query_data); + _contacts_free_query_person_struct_member_only(&query_data); if(func_ret == 0) { break; @@ -567,3 +408,648 @@ int contact_query_contact_not_related_to_group(contact_foreach_query_name_cb cal 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; +} + |