diff options
author | Kibum Kim <kb0929.kim@samsung.com> | 2012-01-07 00:42:30 +0900 |
---|---|---|
committer | Kibum Kim <kb0929.kim@samsung.com> | 2012-01-07 00:42:30 +0900 |
commit | 9dc895cff369b90eac117149860365ef33139889 (patch) | |
tree | c0f869e0776ec77a4ff482788e300bc8a2e985f1 /src/contacts_contact.c | |
parent | e0ca36eef24c43274d4a5375cd492c0cdcbec878 (diff) | |
download | contacts-9dc895cff369b90eac117149860365ef33139889.tar.gz contacts-9dc895cff369b90eac117149860365ef33139889.tar.bz2 contacts-9dc895cff369b90eac117149860365ef33139889.zip |
Git init
Diffstat (limited to 'src/contacts_contact.c')
-rwxr-xr-x | src/contacts_contact.c | 1057 |
1 files changed, 1057 insertions, 0 deletions
diff --git a/src/contacts_contact.c b/src/contacts_contact.c new file mode 100755 index 0000000..a8901a0 --- /dev/null +++ b/src/contacts_contact.c @@ -0,0 +1,1057 @@ +/* + * 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 <tizen.h> +#include <contacts.h> +#include <contacts-svc.h> +#include <contacts_private.h> +#include <string.h> +#include <stdlib.h> +#include <dlog.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "TIZEN_N_CONTACTS" +#define LOG_MODE (1) + +int contact_create(contact_h* contact) +{ + if(contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + CTSstruct* ret_val = contacts_svc_struct_new(CTS_STRUCT_CONTACT); + if(ret_val == NULL) { + LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); + return CONTACTS_ERROR_OUT_OF_MEMORY; + } + + *contact = (contact_h)ret_val; + return CONTACTS_ERROR_NONE; +} + +int contact_destroy(contact_h contact) +{ + if(contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + if(contacts_svc_struct_free((CTSstruct*)contact) == 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_insert_to_db(contact_h contact, int *db_id) +{ + if(contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + int contact_index = -1; + contact_index = contacts_svc_insert_contact(0, (CTSstruct*)contact); + if(contact_index < 0) { + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; + } + if(db_id != NULL) { + *db_id = contact_index; + } + + return CONTACTS_ERROR_NONE; +} + +int contact_delete_from_db(int db_id) +{ + if(db_id < 0) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + int ret = CTS_SUCCESS; + if((ret=contacts_svc_delete_contact(db_id)) == CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_DB_FAILED || ret == CTS_ERR_DB_NOT_OPENED || ret == CTS_ERR_DB_RECORD_NOT_FOUND) { + 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 contact_update_to_db(contact_h contact) +{ + if(contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + int ret = CTS_SUCCESS; + if((ret=contacts_svc_update_contact((CTSstruct*)contact)) == CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_DB_FAILED || ret == CTS_ERR_DB_NOT_OPENED || ret == CTS_ERR_DB_RECORD_NOT_FOUND) { + 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 contact_get_from_db(int db_id, contact_h* contact) +{ + if(contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + int ret = CTS_SUCCESS; + if((ret=contacts_svc_get_contact(db_id, (CTSstruct**)contact)) == CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_DB_FAILED || ret == CTS_ERR_DB_NOT_OPENED || ret == CTS_ERR_DB_RECORD_NOT_FOUND) { + 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 contact_get_db_id(contact_h contact, int* db_id) +{ + if(contact == NULL || db_id == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + int ret = 0; + *db_id = 0; + CTSvalue* base = NULL; + if((ret = contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base)) != CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } + *db_id = contacts_svc_value_get_int(base, CTS_BASE_VAL_ID_INT); + if(*db_id < 0) { + *db_id = 0; + } + return CONTACTS_ERROR_NONE; +} + +int contact_add_group(contact_h contact, int group_db_id) +{ + if(contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + bool need_to_free = false; + GSList *cursor = NULL; + int ret = CONTACTS_ERROR_INVALID_PARAMETER; + + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_GROUPREL_LIST, &cursor); + if(cursor == NULL) { + need_to_free = true; + } + CTSvalue* group = NULL; + contacts_connect(); + if(contacts_svc_get_group(group_db_id, &group) != CONTACTS_ERROR_NONE) { + LOGE("[%s] CONTACTS_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CONTACTS_ERROR_NO_DATA); + return CONTACTS_ERROR_NO_DATA; + } + contacts_disconnect(); + CTSvalue* relatedgroup = contacts_svc_value_new(CTS_VALUE_GROUP_RELATION); + if(relatedgroup == NULL) { + contacts_svc_value_free(group); + 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(relatedgroup, CTS_GROUPREL_VAL_ID_INT, group_db_id); + ((_contacts_group_s*)relatedgroup)->name = _contacts_safe_strdup(contacts_svc_value_get_str(group, CTS_GROUP_VAL_NAME_STR)); + ((_contacts_group_s*)relatedgroup)->ringtone_path = _contacts_safe_strdup(contacts_svc_value_get_str(group, CTS_GROUP_VAL_RINGTONE_STR)); + + cursor = g_slist_append((GSList*)cursor, relatedgroup); + if(contacts_svc_struct_store_list((CTSstruct*)contact, CTS_CF_GROUPREL_LIST, cursor) == CTS_SUCCESS) { + ret = CONTACTS_ERROR_NONE; + } + if(need_to_free == true) { + g_slist_free((GSList*)cursor); + } + contacts_svc_value_free(group); + contacts_svc_value_free(relatedgroup); + return ret; +} + +int contact_remove_group(contact_h contact, int group_db_id) +{ + if(contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + int ret = CONTACTS_ERROR_INVALID_PARAMETER; + GSList *group_relation_list = NULL; + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_GROUPREL_LIST, &group_relation_list); + if(group_relation_list == NULL) { + LOGE("[%s] CONTACTS_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CONTACTS_ERROR_NO_DATA); + return CONTACTS_ERROR_NO_DATA; + } + cursor = group_relation_list; + for(;cursor;cursor=g_slist_next(cursor)) { + if(group_db_id == contacts_svc_value_get_int((CTSvalue*)cursor->data, CTS_GROUPREL_VAL_ID_INT)) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_GROUPREL_VAL_DELETE_BOOL, true); + break; + } + } + + if(contacts_svc_struct_store_list((CTSstruct*)contact, CTS_CF_GROUPREL_LIST, group_relation_list) == CTS_SUCCESS) { + ret = CONTACTS_ERROR_NONE; + } + + if(ret == CONTACTS_ERROR_INVALID_PARAMETER) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + } + return ret; +} + +int contact_get_name(contact_h contact, contact_name_h* name) +{ + if(contact == NULL || name == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + *name = NULL; + int ret = CTS_SUCCESS; + if((ret=contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_NAME_VALUE, (CTSvalue**)name)) == CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_NO_DATA) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contact_set_name(contact_h contact, contact_name_h name) +{ + if(contact == NULL || name == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + if(contacts_svc_struct_store_value((CTSstruct*)contact, CTS_CF_NAME_VALUE, (CTSvalue*)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_get_default_number(contact_h contact, contact_number_h* number) +{ + if(contact == NULL || number == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + *number = NULL; + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NUMBER_LIST, &cursor); + + for(;cursor;cursor=g_slist_next(cursor)) { + if(contacts_svc_value_get_bool((CTSvalue*)cursor->data, CTS_NUM_VAL_DEFAULT_BOOL) == true) { + *number = (contact_number_h)cursor->data; + return CONTACTS_ERROR_NONE; + } + } + return CONTACTS_ERROR_NONE; +} + +int contact_add_number(contact_h contact, contact_number_h number) +{ + if(contact == NULL || number == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NUMBER_LIST, &cursor); + int ret = 0; + bool need_to_free = false; + if(cursor == NULL) { + need_to_free = true; + } + + cursor = g_slist_append((GSList*)cursor, number); + if(contacts_svc_struct_store_list((CTSstruct*)contact, CTS_CF_NUMBER_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_remove_number(contact_h contact, contact_number_h number) +{ + if(contact == NULL || number == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NUMBER_LIST, &cursor); + + for(;cursor;cursor=g_slist_next(cursor)) { + if((CTSvalue*)cursor->data == (CTSvalue*)number) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_NUM_VAL_DELETE_BOOL, true); + return CONTACTS_ERROR_NONE; + } + } + + return CONTACTS_ERROR_NONE; +} + +int contact_get_number_iterator(contact_h contact, contact_number_iterator_h* number_iterator) +{ + if(contact == NULL || number_iterator == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + *number_iterator = NULL; + int ret = CTS_SUCCESS; + if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NUMBER_LIST, (GSList**)number_iterator)) == CTS_SUCCESS){ + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_NO_DATA) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contact_add_email(contact_h contact, contact_email_h email) +{ + if(contact == NULL || email == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EMAIL_LIST, &cursor); + int ret = 0; + bool need_to_free = false; + if(cursor == NULL) { + need_to_free = true; + } + + cursor = g_slist_append((GSList*)cursor, email); + + if(contacts_svc_struct_store_list((CTSstruct*)contact, CTS_CF_EMAIL_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_remove_email(contact_h contact, contact_email_h email) +{ + if(contact == NULL || email == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EMAIL_LIST, &cursor); + + for(;cursor;cursor=g_slist_next(cursor)) { + if((CTSvalue*)cursor->data == (CTSvalue*)email) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_EMAIL_VAL_DELETE_BOOL, true); + return CONTACTS_ERROR_NONE; + } + } + + return CONTACTS_ERROR_NONE; +} + +int contact_get_email_iterator(contact_h contact, contact_email_iterator_h* email_iterator) +{ + if(contact == NULL || email_iterator == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + *email_iterator = NULL; + int ret = CTS_SUCCESS; + if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EMAIL_LIST, (GSList**)email_iterator)) == CTS_SUCCESS){ + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_NO_DATA) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contact_add_address(contact_h contact, contact_address_h address) +{ + if(contact == NULL || address == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_POSTAL_ADDR_LIST, &cursor); + int ret = 0; + bool need_to_free = false; + if(cursor == NULL) { + need_to_free = true; + } + + cursor = g_slist_append((GSList*)cursor, address); + + if(contacts_svc_struct_store_list((CTSstruct*)contact, CTS_CF_POSTAL_ADDR_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_remove_address(contact_h contact, contact_address_h address) +{ + if(contact == NULL || address == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_POSTAL_ADDR_LIST, &cursor); + + for(;cursor;cursor=g_slist_next(cursor)) { + if((CTSvalue*)cursor->data == (CTSvalue*)address) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_POSTAL_VAL_DELETE_BOOL, true); + return CONTACTS_ERROR_NONE; + } + } + + return CONTACTS_ERROR_NONE; +} + +int contact_get_address_iterator(contact_h contact, contact_address_iterator_h* address_iterator) +{ + if(contact == NULL || address_iterator == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + *address_iterator = NULL; + int ret = CTS_SUCCESS; + if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_POSTAL_ADDR_LIST, (GSList**)address_iterator)) == CTS_SUCCESS){ + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_NO_DATA) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contact_get_company(contact_h contact, contact_company_h* company) +{ + if(contact == NULL || company == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_COMPANY_VALUE, (CTSvalue**)company) == 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_set_company(contact_h contact, contact_company_h company) +{ + if(contact == NULL || company == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + if(contacts_svc_struct_store_value((CTSstruct*)contact, CTS_CF_COMPANY_VALUE, (CTSvalue*)company) == 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_get_birthday(contact_h contact, contact_birthday_h* birthday) +{ + if(contact == NULL || birthday == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + *birthday = NULL; + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EVENT_LIST, &cursor); + if(cursor == NULL) { + return CONTACTS_ERROR_NONE; + } + *birthday = (contact_birthday_h)cursor->data; + + return CONTACTS_ERROR_NONE; +} + +int contact_set_birthday(contact_h contact, contact_birthday_h birthday) +{ + if(contact == NULL || birthday == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + 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 { + if((contact_birthday_h)cursor->data != birthday) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_EVENT_VAL_DELETE_BOOL, true); + } + } + + cursor = g_slist_append((GSList*)cursor, birthday); + + + 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_add_messenger(contact_h contact, contact_messenger_h messenger) +{ + if(contact == NULL || messenger == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_MESSENGER_LIST, &cursor); + int ret = 0; + bool need_to_free = false; + if(cursor == NULL) { + need_to_free = true; + } + + cursor = g_slist_append((GSList*)cursor, messenger); + + if(contacts_svc_struct_store_list((CTSstruct*)contact, CTS_CF_MESSENGER_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_remove_messenger(contact_h contact, contact_messenger_h messenger) +{ + if(contact == NULL || messenger == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_MESSENGER_LIST, &cursor); + + for(;cursor;cursor=g_slist_next(cursor)) { + if((CTSvalue*)cursor->data == (CTSvalue*)messenger) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_MESSENGER_VAL_DELETE_BOOL, true); + return CONTACTS_ERROR_NONE; + } + } + + return CONTACTS_ERROR_NONE; +} + +int contact_get_messenger_iterator(contact_h contact, contact_messenger_iterator_h* messenger_iterator) +{ + if(contact == NULL || messenger_iterator == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + int ret = CTS_SUCCESS; + if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_MESSENGER_LIST, (GSList**)messenger_iterator)) == CTS_SUCCESS){ + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_NO_DATA) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contact_add_nickname(contact_h contact, contact_nickname_h nickname) +{ + if(contact == NULL || nickname == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NICKNAME_LIST, &cursor); + int ret = 0; + bool need_to_free = false; + if(cursor == NULL) { + need_to_free = true; + } + + cursor = g_slist_append((GSList*)cursor, nickname); + + if(contacts_svc_struct_store_list((CTSstruct*)contact, CTS_CF_NICKNAME_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_remove_nickname(contact_h contact, contact_nickname_h nickname) +{ + if(contact == NULL || nickname == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NICKNAME_LIST, &cursor); + + for(;cursor;cursor=g_slist_next(cursor)) { + if((CTSvalue*)cursor->data == (CTSvalue*)nickname) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_NICKNAME_VAL_DELETE_BOOL, true); + return CONTACTS_ERROR_NONE; + } + } + + return CONTACTS_ERROR_NONE; +} + +int contact_get_nickname_iterator(contact_h contact, contact_nickname_iterator_h* nickname_iterator) +{ + if(contact == NULL || nickname_iterator == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + int ret = CTS_SUCCESS; + if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NICKNAME_LIST, (GSList**)nickname_iterator)) == CTS_SUCCESS){ + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_NO_DATA) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contact_add_web(contact_h contact, contact_web_h web) +{ + if(contact == NULL || web == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_WEB_ADDR_LIST, &cursor); + int ret = 0; + bool need_to_free = false; + if(cursor == NULL) { + need_to_free = true; + } + + cursor = g_slist_append((GSList*)cursor, web); + + if(contacts_svc_struct_store_list((CTSstruct*)contact, CTS_CF_WEB_ADDR_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_remove_web(contact_h contact, contact_web_h web) +{ + if(contact == NULL || web == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + GSList *cursor = NULL; + contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_WEB_ADDR_LIST, &cursor); + + for(;cursor;cursor=g_slist_next(cursor)) { + if((CTSvalue*)cursor->data == (CTSvalue*)web) { + contacts_svc_value_set_bool((CTSvalue*)cursor->data, CTS_WEB_VAL_DELETE_BOOL, true); + return CONTACTS_ERROR_NONE; + } + } + + return CONTACTS_ERROR_NONE; +} + +int contact_get_web_iterator(contact_h contact, contact_web_iterator_h* web_iterator) +{ + if(contact == NULL || web_iterator == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + int ret = CTS_SUCCESS; + if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_WEB_ADDR_LIST, (GSList**)web_iterator)) == CTS_SUCCESS){ + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_NO_DATA) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contact_get_relatedgroup_iterator(contact_h contact, contact_relatedgroup_iterator_h* relatedgroup_iterator) +{ + if(contact == NULL || relatedgroup_iterator == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + int ret = CTS_SUCCESS; + if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_GROUPREL_LIST, (GSList**)relatedgroup_iterator)) == CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_NO_DATA) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + +int contact_set_image(contact_h contact, const char* src_img) +{ + if(contact == NULL || src_img == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + int ret = CONTACTS_ERROR_INVALID_PARAMETER; + int ret_temp = 0; + CTSvalue* base = NULL; + if((ret_temp = contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base)) != CTS_SUCCESS) { + if(ret_temp == CTS_ERR_NO_DATA) { + base = contacts_svc_value_new(CTS_VALUE_CONTACT_BASE_INFO); + contacts_svc_value_set_str(base, CTS_BASE_VAL_IMG_PATH_STR, src_img); + if(contacts_svc_struct_store_value((CTSstruct *)contact, CTS_CF_BASE_INFO_VALUE, base) == CTS_SUCCESS) { + ret = CONTACTS_ERROR_NONE; + } + contacts_svc_value_free(base); + } + } else { + if(contacts_svc_value_set_str(base, CTS_BASE_VAL_IMG_PATH_STR, src_img) == CTS_SUCCESS) { + ret = CONTACTS_ERROR_NONE; + } + } + + if(ret == CONTACTS_ERROR_INVALID_PARAMETER) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + } + return ret; +} + +int contact_get_image(contact_h contact, char** img_path) +{ + if(contact == NULL || img_path == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + *img_path = NULL; + CTSvalue* base = NULL; + if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base) != CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } + + *img_path = _contacts_safe_strdup(contacts_svc_value_get_str(base, CTS_BASE_VAL_IMG_PATH_STR)); + return CONTACTS_ERROR_NONE; +} + + +int contact_get_ringtonepath(contact_h contact, char** ringtone_path) +{ + if(contact == NULL || ringtone_path == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + *ringtone_path = NULL; + CTSvalue* base = NULL; + if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base) != CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } + + *ringtone_path = _contacts_safe_strdup(contacts_svc_value_get_str(base, CTS_BASE_VAL_RINGTONE_PATH_STR)); + return CONTACTS_ERROR_NONE; +} + +int contact_set_ringtonepath(contact_h contact, const char* ringtone_path) +{ + if(contact == NULL || ringtone_path == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + int ret = CTS_SUCCESS; + CTSvalue* base = NULL; + if((ret = contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base)) != CTS_SUCCESS) { + if(ret == CTS_ERR_NO_DATA) { + base = contacts_svc_value_new(CTS_VALUE_CONTACT_BASE_INFO); + contacts_svc_value_set_str(base, CTS_BASE_VAL_RINGTONE_PATH_STR, ringtone_path); + ret = contacts_svc_struct_store_value((CTSstruct *)contact, CTS_CF_BASE_INFO_VALUE, base); + contacts_svc_value_free(base); + } else { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + } else { + ret = contacts_svc_value_set_str(base, CTS_BASE_VAL_RINGTONE_PATH_STR, ringtone_path); + } + + if(ret == 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_get_note(contact_h contact, char** note) +{ + if(contact == NULL || note == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + *note = NULL; + CTSvalue* base = NULL; + if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base) != CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } + + *note = _contacts_safe_strdup(contacts_svc_value_get_str(base, CTS_BASE_VAL_NOTE_STR)); + return CONTACTS_ERROR_NONE; +} + +int contact_set_note(contact_h contact, const char* note) +{ + if(contact == NULL || note == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + int ret = CTS_SUCCESS; + CTSvalue* base = NULL; + if((ret = contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base)) != CTS_SUCCESS) { + if(ret == CTS_ERR_NO_DATA) { + base = contacts_svc_value_new(CTS_VALUE_CONTACT_BASE_INFO); + contacts_svc_value_set_str(base, CTS_BASE_VAL_NOTE_STR, note); + ret = contacts_svc_struct_store_value((CTSstruct *)contact, CTS_CF_BASE_INFO_VALUE, base); + contacts_svc_value_free(base); + } else { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + } else { + ret = contacts_svc_value_set_str(base, CTS_BASE_VAL_NOTE_STR, note); + } + + if(ret == 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_get_total_count_from_db(int* count) +{ + if(count == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + *count = contacts_svc_count(CTS_GET_ALL_CONTACT); + return CONTACTS_ERROR_NONE; +} + + + +int contact_get_from_vcard(const char *vcard_stream, contact_h *contact) +{ + if(vcard_stream == NULL || contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + if(contacts_svc_get_contact_from_vcard((const void*)vcard_stream, (CTSstruct**)contact) == 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_get_vcard_from_contact(contact_h contact, char **vcard_stream) +{ + if(vcard_stream == NULL || contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + if(contacts_svc_get_vcard_from_contact((const CTSstruct*)contact, vcard_stream) == 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_set_favorite_to_db(int contact_db_id) +{ + if(contact_db_id <= 0) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + if(CTS_SUCCESS == contacts_svc_set_favorite(CTS_FAVOR_CONTACT, contact_db_id)) { + 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_favorite_to_db(int contact_db_id) +{ + if(contact_db_id <= 0) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + if(CTS_SUCCESS == contacts_svc_unset_favorite(CTS_FAVOR_CONTACT, contact_db_id)) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; +} + +int contact_get_favorite(contact_h contact, bool *is_favorite) +{ + if(contact == NULL || is_favorite == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + *is_favorite = false; + CTSvalue* base = NULL; + if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base) != CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } + + *is_favorite = contacts_svc_value_get_bool(base, CTS_BASE_VAL_FAVORITE_BOOL); + return CONTACTS_ERROR_NONE; +} + +int contact_set_favorite(contact_h contact, bool is_favorite) +{ + if(contact == NULL) { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + + int ret = CTS_SUCCESS; + CTSvalue* base = NULL; + if((ret = contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base)) != CTS_SUCCESS) { + if(ret == CTS_ERR_NO_DATA) { + base = contacts_svc_value_new(CTS_VALUE_CONTACT_BASE_INFO); + contacts_svc_value_set_bool(base, CTS_BASE_VAL_FAVORITE_BOOL, is_favorite); + ret = contacts_svc_struct_store_value((CTSstruct *)contact, CTS_CF_BASE_INFO_VALUE, base); + contacts_svc_value_free(base); + } else { + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + } else { + ret = contacts_svc_value_set_bool(base, CTS_BASE_VAL_FAVORITE_BOOL, is_favorite); + } + + if(ret == CTS_SUCCESS) { + return CONTACTS_ERROR_NONE; + } + + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); + return CONTACTS_ERROR_INVALID_PARAMETER; +} + |