From 83807e88f73bb7d580a874caf29172128f763d2e Mon Sep 17 00:00:00 2001 From: Jonghoon Lim Date: Fri, 10 Feb 2012 15:13:49 +0900 Subject: [PATCH] capi-social-contacts_0.1.1-25 --- debian/changelog | 8 + include/contacts.h | 204 +++++++++++++++++++- include/contacts_company.h | 1 + include/contacts_contact.h | 103 +++++++++- include/contacts_group.h | 48 ++++- include/contacts_private.h | 35 +++- include/contacts_relatedgroup.h | 8 - include/contacts_search.h | 151 +++++++++++++-- include/contacts_types.h | 118 +++++++++++- include/contacts_web.h | 2 - src/contacts.c | 226 +++++++++++++++++++--- src/contacts_address.c | 40 ++-- src/contacts_company.c | 25 +-- src/contacts_contact.c | 404 ++++++++++++++++++++-------------------- src/contacts_email.c | 54 ++---- src/contacts_event.c | 25 +-- src/contacts_group.c | 134 +++++++------ src/contacts_messenger.c | 43 ++--- src/contacts_private.c | 40 ++++ src/contacts_search.c | 302 +++++++++++++++++++++++++++--- 20 files changed, 1502 insertions(+), 469 deletions(-) diff --git a/debian/changelog b/debian/changelog index b172d94..abe040a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +capi-social-contacts (0.1.1-25) unstable; urgency=low + + * Multiple address books feature added + * Git: api/contacts + * Tag: capi-social-contacts_0.1.1-25 + + -- Jonghoon Lim Fri, 10 Feb 2012 15:12:20 +0900 + capi-social-contacts (0.1.1-23) unstable; urgency=low * version updated diff --git a/include/contacts.h b/include/contacts.h index 2f299ff..b72099b 100755 --- a/include/contacts.h +++ b/include/contacts.h @@ -87,7 +87,7 @@ int contacts_disconnect(void); int contacts_get_db_version(int* contacts_db_version); /** - * @brief Registers a callback function to be invoked when the contacts changes. + * @brief Registers a callback function to be invoked when the address book changes. * * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function @@ -97,7 +97,40 @@ int contacts_get_db_version(int* contacts_db_version); * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter * * @pre This function requires an open connection to the contacts service by contacts_connect(). - * @post contacts_db_changed_cb() will be invoked when a contact changes. + * @post contacts_db_changed_cb() will be invoked when the address book changes. + * + * @see contacts_db_changed_cb() + * @see contacts_address_book_foreach_address_book_from_db() + * @see contacts_address_book_query_address_book_by_account_db_id() + */ +int contacts_add_address_book_db_changed_cb(contacts_db_changed_cb callback, void *user_data); + +/** + * @brief Unregisters the callback function. + * + * @param[in] callback The callback function to unregister + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contacts_db_changed_cb() + * @see contacts_add_address_book_db_changed_cb() + */ +int contacts_remove_address_book_db_changed_cb(contacts_db_changed_cb callback); + +/** + * @brief Registers a callback function to be invoked when the contact changes. + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre This function requires an open connection to the contacts service by contacts_connect(). + * @post contacts_db_changed_cb() will be invoked when the contact changes. * * @see contacts_db_changed_cb() * @see contact_query_contact_by_version() @@ -194,10 +227,177 @@ int contacts_add_group_db_changed_cb(contacts_db_changed_cb callback, void *user * @see contacts_add_group_db_changed_cb() */ int contacts_remove_group_db_changed_cb(contacts_db_changed_cb callback); + +/** + * @brief Imports all contacts from SIM card to the contacts database. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to contacts service by contacts_connect(). + */ +int contacts_import_all_contacts_from_sim_card(); + /** * @} */ +/** + * @addtogroup CAPI_SOCIAL_CONTACTS_ADDRESS_BOOK_MODULE + * @{ + */ + +/** + * @brief Gets the address book from the contacts databse. + * + * @details This funcstion creates a new address book handle from the contacts database by the given @a address_book_db_id. \n + * @a address_book will be created, which is filled with address book informations. + * + * @remarks @a address_book must be released with contacts_address_book_destroy() by you. + * + * @param[in] address_book_db_id The address book database ID to get from database + * @param[out] address_book The address book handle associated with the address book database ID + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to contacts service by contacts_connect(). + * + * @see contacts_connect() + * @see contacts_address_book_destroy() + * @see contacts_foreach_query_address_book_cb() + */ +int contacts_address_book_get_from_db(int address_book_db_id, contacts_address_book_h *address_book); + +/** + * @brief Destroys the address book handle and releases all its resources. + * + * @param[in] address_book The address book handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contacts_address_book_get_from_db() + */ +int contacts_address_book_destroy(contacts_address_book_h address_book); + +/** + * @brief Gets the address book database ID for the given address book handle. + * + * @param[in] address_book The address book handle + * @param[out] address_book_db_id The address book database ID fetched from contacts database (default : -1) \n + * -1 means the address book is not in the contacts database. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contacts_address_book_get_from_db() + */ +int contacts_address_book_get_db_id(contacts_address_book_h address_book, int *address_book_db_id); + +/** + * @brief Gets the address book name from the address book handle. + * + * @remarks @a address_book_name must be released with free() by you. + * + * @param[in] address_book The contacts name handle + * @param[out] address_book_name The address book name to be returned \n + * If requested data does not exist, @a detail is NULL + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + */ +int contacts_address_book_get_name(contacts_address_book_h address_book, char **address_book_name); + +/** + * @brief Gets the read only status of the address book from the address book handle. + * + * @param[in] address_book The contact handle + * @param[out] is_read_only @c true if the address book is read only, otherwise @c false ( default : @c false ) + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + */ +int contacts_address_book_get_read_only(contacts_address_book_h address_book, bool *is_read_only); + +/** + * @brief Gets the address book type from the address book handle. + * + * @param[in] address_book The address book handle + * @param[out] address_book_type The type of address book to get + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + */ +int contacts_address_book_get_type(contacts_address_book_h address_book, contacts_address_book_type_e *address_book_type); + +/** + * @brief Gets the account database ID for the given address book handle. + * + * @param[in] address_book The address book handle + * @param[out] account_db_id The account database ID (default : 0) \n + * 0 means the address book is not related to any accounts. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + */ +int contacts_address_book_get_account_db_id(contacts_address_book_h address_book, int *account_db_id); + +/** + * @brief Retrieves all address book by invoking the given callback function + * + * @param[in] callback The callback function to unregister + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to contacts service by contacts_connect(). + * @post This function invokes contact_foreach_query_favorites_cb(). + * + * @see contacts_connect() + * @see contacts_foreach_query_address_book_cb() + */ +int contacts_address_book_foreach_address_book_from_db(contacts_foreach_query_address_book_cb callback, void *user_data); + +/** + * @brief Retrieves all address book with the account database ID. + * + * @param[in] callback The callback function to invoke + * @param[in] account_db_id The account database ID to filter + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to contacts service by contacts_connect(). + * @post This function invokes contact_foreach_query_number_cb(). + * + * @see contacts_connect() + * @see contacts_foreach_query_address_book_cb() + */ +int contacts_address_book_query_address_book_by_account_db_id(contacts_foreach_query_address_book_cb callback, int account_db_id, void *user_data); + + +/** + * @} + */ + + + #ifdef __cplusplus } #endif diff --git a/include/contacts_company.h b/include/contacts_company.h index e79207a..8cc54cb 100755 --- a/include/contacts_company.h +++ b/include/contacts_company.h @@ -77,6 +77,7 @@ int contact_company_destroy(contact_company_h company); * @see contact_company_set_detail() */ int contact_company_get_detail(contact_company_h company, contact_company_detail_e detail_type, char **detail); + /** * @brief Sets a company information detail to the contacts company handle. * diff --git a/include/contacts_contact.h b/include/contacts_contact.h index a2b27df..1410200 100755 --- a/include/contacts_contact.h +++ b/include/contacts_contact.h @@ -65,7 +65,9 @@ int contact_destroy(contact_h contact); /** * @brief Inserts a new contact to the contacts database. * - * @param[in] contact The contact handle + * @param[in] contact The contact handle + * @param[in] address_book_db_id The address book database ID to which the contact insert. \n + * 0 means the default address book on the device * @param[out] contact_db_id The contact ID to be assigned to a new contact \n * If inserting a new contact succeeds, contact ID will be assigned to a new contact, * otherwise contact_db_id stays unchanged @@ -81,7 +83,7 @@ int contact_destroy(contact_h contact); * @see contact_delete_from_db() * @see contact_get_from_db() */ -int contact_insert_to_db(contact_h contact, int *contact_db_id); +int contact_insert_to_db(contact_h contact, int address_book_db_id, int *contact_db_id); /** * @brief Deletes the contact from the contacts database. @@ -267,7 +269,6 @@ int contact_set_name(contact_h contact, contact_name_h name); */ int contact_get_default_number(contact_h contact, contact_number_h *number); - /** * @brief Adds a contacts new number handle to the contact handle. * @@ -422,7 +423,7 @@ int contact_get_address_iterator(contact_h contact, contact_address_iterator_h * int contact_get_birthday(contact_h contact, contact_birthday_h* birthday); /** - * @brief Adds the contacts birthday handle to the contact handle. + * @brief Sets the contacts birthday handle to the contact handle. * * @param[in] contact The contact handle * @param[in] birthday The contacts birthday handle @@ -436,6 +437,19 @@ int contact_get_birthday(contact_h contact, contact_birthday_h* birthday); int contact_set_birthday(contact_h contact, contact_birthday_h birthday); /** + * @brief Unsets the contacts birthday handle to the contact handle. + * + * @param[in] contact The contact handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contact_get_birthday() + */ +int contact_unset_birthday(contact_h contact); + +/** * @brief Gets the contacts company handle from the contact handle. * * @param[in] contact The contact handle @@ -728,6 +742,7 @@ int contact_set_ringtonepath(contact_h contact, const char *ringtone_path); * @see contact_set_note() */ int contact_get_note(contact_h contact, char **note); + /** * @brief Sets the note to the contact handle. * @@ -742,7 +757,6 @@ int contact_get_note(contact_h contact, char **note); */ int contact_set_note(contact_h contact, const char *note); - /** * @brief Gets the all contact count * @@ -792,6 +806,85 @@ int contact_get_from_vcard(const char *vcard_stream, contact_h *contact); int contact_get_vcard_from_contact(contact_h contact, char **vcard_stream); /** + * @brief Retrieves all vCard stream each from multiple vCard file. + * + * @param[in] callback The callback function to invoke + * @param[in] multiple_vcard_file_path The file path of multiple vCard stream file + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @post This function invokes contacts_vcard_stream_cb(). + * @see contacts_vcard_stream_cb() + */ +int contact_parse_multiple_vcard_file(contacts_vcard_stream_cb callback, const char *multiple_vcard_file_path, void *user_data); + +/** + * @brief Gets the address book database ID of the contact from the contact handle. + * + * @param[in] contact The contact handle + * @param[out] address_book_db_id The address book database ID of the contact to get (default : 0) \n + * 0 means the contact is not in the contacts database or in the contacts default address book. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contact_set_address_book_db_id() + * @see contacts_address_book_get_from_db() + */ +int contact_get_address_book_db_id(contact_h contact, int *address_book_db_id); + +/** + * @brief Gets the all contact count in the given address book database ID + * + * @param[in] address_book_db_id The address book database ID + * @param[out] count The all contact count of the address book + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contacts_connect() + * @see contact_get_total_count_not_related_to_group() + */ +int contact_get_total_count_in_address_book(int address_book_db_id, int *count); + +/** + * @brief Gets the contacts count which are related to any group in the given address book database ID + * + * @param[in] address_book_db_id The address book database ID + * @param[out] count The contacts count + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contacts_connect() + * @see contact_get_total_count_in_address_book() + */ +int contact_get_total_count_not_related_to_group(int address_book_db_id, int *count); + +/** + * @brief Unsets the contact from frequent contacts + * + * @param[in] contact_db_id The contact ID to unset + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to contacts service by contacts_connect(). + * + * @see contact_foreach_frequent_contact_from_db() + */ +int contact_unset_frequent_contact(int contact_db_id); + +/** * @} */ diff --git a/include/contacts_group.h b/include/contacts_group.h index 8690a51..0293517 100755 --- a/include/contacts_group.h +++ b/include/contacts_group.h @@ -65,6 +65,8 @@ int contacts_group_destroy(contacts_group_h group); * @brief Inserts a new group to the contacts database. * * @param[in] group The contacts group handle + * @param[in] address_book_db_id The address book database ID to which the contact insert. \n + * 0 means the default address book on the device * @param[out] group_db_id A group ID to be assigned to the group handle \n * If inserting a new group succeeds, database ID will be assigned to a new group, otherwise @a group_db_id stays unchanged * @@ -78,7 +80,7 @@ int contacts_group_destroy(contacts_group_h group); * @see contacts_group_delete_from_db() * @see contacts_group_update_to_db() */ -int contacts_group_insert_to_db(contacts_group_h group, int *group_db_id); +int contacts_group_insert_to_db(contacts_group_h group, int address_book_db_id, int *group_db_id); /** * @brief Deletes the group from the contacts database. @@ -143,7 +145,7 @@ int contacts_group_get_from_db(int group_db_id, contacts_group_h *group); * * @param[in] group The contacts group handle * @param[out] group_db_id The group ID fetched from contacts database (default : 0) \n - * 0 means the contact is not in the contacts database. + * 0 means the group is not in the contacts database. * * @return 0 on success, otherwise a negative error value. * @retval #CONTACTS_ERROR_NONE Successful @@ -245,10 +247,46 @@ int contacts_group_get_member_count_from_db(contacts_group_h group, int *count); * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure * * @pre This function requires an open connection to Contacts Service by contacts_connect(). - * @post This function invokes contacts_foreach_group_cb(). - * @see contacts_foreach_group_cb() + * @post This function invokes contacts_foreach_query_group_cb(). + * @see contacts_foreach_query_group_cb() */ -int contacts_group_foreach_group_from_db(contacts_foreach_group_cb callback, void *user_data); +int contacts_group_foreach_group_from_db(contacts_foreach_query_group_cb callback, void *user_data); + +/** + * @brief Gets the address book database ID for the given contacts group handle. + * + * @param[in] group The contacts group handle + * @param[out] address_book_db_id The address book database ID fetched from contacts database (default : 0) \n + * 0 means the group is not in the contacts database. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contacts_group_set_address_book_db_id() + * @see contacts_address_book_get_from_db() + */ +int contacts_group_get_address_book_db_id(contacts_group_h group, int *address_book_db_id); + +/** + * @brief Retrieves all groups with the given address book database ID + * + * @param[in] callback The callback function to invoke + * @param[in] address_book_db_id The address book database ID to filter + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to Contacts Service by contacts_connect() + * @post This function invokes contacts_foreach_query_group_cb(). + * + * @see contacts_connect() + * @see contacts_foreach_query_group_cb() + */ +int contacts_group_query_group_by_address_book(contacts_foreach_query_group_cb callback, int address_book_db_id, void *user_data); /** * @} diff --git a/include/contacts_private.h b/include/contacts_private.h index 5b83d74..fb25596 100755 --- a/include/contacts_private.h +++ b/include/contacts_private.h @@ -44,6 +44,20 @@ typedef struct { int v_type:16; bool embedded; bool deleted; + int id; + int acc_id; + int acc_type; + int mode; + char *name; +}_contacts_address_book_s; // cts_addrbook, CTS_ADDRESSBOOK_VAL_ + +/** + * @internal + */ +typedef struct { + int v_type:16; + bool embedded; + bool deleted; bool uid_changed; bool img_changed; bool full_img_changed; @@ -120,7 +134,7 @@ typedef struct { GSList *extended_values; char *vcard_img; int vcard_img_type; -}_contact_s; //cts_struct_field +}_contact_s; //contact_t, cts_struct_field /** * @internal @@ -424,8 +438,27 @@ typedef struct GSList contacts_iterator_s; void _contacts_set_query_person_struct(contact_query_name_s* contact, CTSvalue* value); void _contacts_free_query_preson_struct_member_only(contact_query_name_s* person); void _contacts_free_query_preson_struct_all(gpointer data, gpointer user_data); +void _contacts_free_query_number_struct_member_only(contact_query_number_s* contact); +void _contacts_free_query_number_struct_all(gpointer data, gpointer user_data); +void _contacts_set_query_address_book_struct(contacts_query_address_book_s* addressbook, CTSvalue* value); +void _contacts_free_query_address_book_struct_member_only(contacts_query_address_book_s* addressbook); + GSList* _contacts_gslist_next_until_not_deleted(GSList* list); +#define CONTACTS_NULL_ARG_CHECK(_arg_) do { \ + if(_arg_ == NULL) { \ + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); \ + return CONTACTS_ERROR_INVALID_PARAMETER; \ + } \ +}while(0) + +#define CONTACTS_INVALID_ARG_CHECK(_condition_) do { \ + if(_condition_) { \ + LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); \ + return CONTACTS_ERROR_INVALID_PARAMETER; \ + } \ +}while(0) + #ifdef __cplusplus } #endif diff --git a/include/contacts_relatedgroup.h b/include/contacts_relatedgroup.h index 0bbd690..9620e7d 100755 --- a/include/contacts_relatedgroup.h +++ b/include/contacts_relatedgroup.h @@ -44,8 +44,6 @@ extern "C" * @return 0 on success, otherwise a negative error value. * @retval #CONTACTS_ERROR_NONE Successful * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter - * - * */ int contact_relatedgroup_get_name(contact_relatedgroup_h relatedgroup, char **name); @@ -61,8 +59,6 @@ int contact_relatedgroup_get_name(contact_relatedgroup_h relatedgroup, char **na * @return 0 on success, otherwise a negative error value. * @retval #CONTACTS_ERROR_NONE Successful * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter - * - * */ int contact_relatedgroup_get_ringtonepath(contact_relatedgroup_h relatedgroup, char **ringtone_path); @@ -100,7 +96,6 @@ int contact_relatedgroup_get_group_db_id(contact_relatedgroup_h relatedgroup, in */ int contact_relatedgroup_iterator_next(contact_relatedgroup_iterator_h *relatedgroup_iterator, contact_relatedgroup_h *relatedgroup); - /** * @brief Checks whether the next element of the related group iterator exists or not. * @@ -112,9 +107,6 @@ int contact_relatedgroup_iterator_next(contact_relatedgroup_iterator_h *relatedg */ bool contact_relatedgroup_iterator_has_next(contact_relatedgroup_iterator_h relatedgroup_iterator); - - - /** * @} */ diff --git a/include/contacts_search.h b/include/contacts_search.h index 56a587d..d3fd03e 100755 --- a/include/contacts_search.h +++ b/include/contacts_search.h @@ -31,8 +31,7 @@ extern "C" */ /** - * @brief Retrieves all contacts by invoking the given callback function iteratively. - * + * @brief Retrieves all contacts from all of address books by invoking the given callback function * * @param[in] callback The callback function to invoke * @param[in] user_data The user data to be passed to the callback function @@ -45,13 +44,12 @@ extern "C" * * @pre This function requires an open connection to contacts service by contacts_connect(). * @post This function invokes contact_foreach_query_name_cb(). + * * @see contact_foreach_query_name_cb() * @see contacts_connect() - * */ int contact_foreach_contact_from_db(contact_foreach_query_name_cb callback, void *user_data); - /** * @brief Retrieves all favorite contacts by invoking the given callback function * @@ -64,11 +62,31 @@ int contact_foreach_contact_from_db(contact_foreach_query_name_cb callback, void * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure * * @pre This function requires an open connection to contacts service by contacts_connect(). - * @post This function invokes contact_foreach_favorites_cb(). + * @post This function invokes contact_foreach_query_favorites_cb(). * - * @see contact_foreach_favorites_cb() + * @see contact_foreach_query_favorites_cb() */ -int contact_foreach_favorite_contact_from_db(contact_foreach_favorites_cb callback, void *user_data); +int contact_foreach_favorite_contact_from_db(contact_foreach_query_favorites_cb callback, void *user_data); + +/** + * @brief Retrieves most frequent contacts by invoking the given callback function + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to contacts service by contacts_connect(). + * @post This function invokes contact_foreach_query_name_cb(). + * + * @see contact_foreach_query_name_cb() + * @see contact_unset_frequent_contact() + * @see contacts_connect() + */ +int contact_foreach_frequent_contact_from_db(contact_foreach_query_name_cb callback, void *user_data); /** * @brief Retrieves all contacts with the given name. @@ -94,8 +112,6 @@ int contact_query_contact_by_name(contact_foreach_query_name_cb callback, const /** * @brief Retrieves all contacts with the given group contacts database ID. * - * - * * @param[in] callback The callback function to invoke * @param[out] group_db_id The group contacts database ID to filter * @param[in] user_data The user data to be passed to the callback function @@ -113,6 +129,25 @@ int contact_query_contact_by_name(contact_foreach_query_name_cb callback, const int contact_query_contact_by_group(contact_foreach_query_name_cb callback, int group_db_id, void *user_data); /** + * @brief Retrieves all contacts with the given address book database ID. + * + * @param[in] callback The callback function to invoke + * @param[out] address_book_db_id The address book database ID to filter + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * @pre This function requires an open connection to contacts service by contacts_connect(). + * @post This function invokes contact_foreach_query_name_cb(). + * + * @see contacts_connect() + * @see contact_foreach_query_name_cb() + */ +int contact_query_contact_by_address_book(contact_foreach_query_name_cb callback, int address_book_db_id, void *user_data); + +/** * @brief Retrieves all contacts with the given number. * * @@ -136,7 +171,6 @@ int contact_query_contact_by_number(contact_foreach_query_number_cb callback, co /** * @brief Retrieves all contacts with the given email address. * - * * @param[in] callback The callback function to invoke * @param[in] email_to_find The email address to filter * @param[in] user_data The user data to be passed to the callback function @@ -146,7 +180,6 @@ int contact_query_contact_by_number(contact_foreach_query_number_cb callback, co * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure * - * * @pre This function requires an open connection to Contacts Service by contacts_connect() * @post This function invokes contact_foreach_query_email_cb(). * @see contacts_connect() @@ -159,8 +192,8 @@ int contact_query_contact_by_email(contact_foreach_query_email_cb callback, cons * * @details This function will find all changed contacts since the given @a contacts_db_version * - * * @param[in] callback The callback function to invoke + * @param[in] address_book_db_id The address book database ID to filter * @param[in] contacts_db_version The contacts database version to filter * @param[in] user_data The user data to be passed to the callback function * @@ -171,10 +204,102 @@ int contact_query_contact_by_email(contact_foreach_query_email_cb callback, cons * * @pre This function requires an open connection to contacts service by contacts_connect(). * @post This function invokes contact_foreach_query_version_cb() + * * @see contacts_connect() * @see contact_foreach_query_version_cb() + * @see contacts_get_db_version() + */ +int contact_query_contact_by_version(contact_foreach_query_version_cb callback, int address_book_db_id, int contacts_db_version, void *user_data); + +/** + * @brief Retrieves all contacts which are not related to any group in the given address book database ID + * + * @param[in] callback The callback function to invoke + * @param[in] address_book_db_id The address book database ID to filter + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to Contacts Service by contacts_connect() + * @post This function invokes contact_foreach_query_name_cb(). + * + * @see contacts_connect() + * @see contact_foreach_query_name_cb() + */ +int contact_query_contact_not_related_to_group(contact_foreach_query_name_cb callback, int address_book_db_id, void *user_data); + +/** + * @brief Retrieves all contacts from all of address books with array + * + * @remarks @a contact_array must be released with contact_query_name_array_free() by you. + * + * @param[out] contact_array The contact array + * @param[out] length The length of the contact array + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to contacts service by contacts_connect(). + * + * @see contact_query_name_array_free() + * @see contacts_connect() + */ +int contact_get_all_contact_from_db(contact_query_name_array *contact_array, int *length); + +/** + * @brief Frees contact array + * + * @param[out] contact_array The contact array + * @param[out] length The length of the contact array + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contact_get_all_contact_from_db() + */ +int contact_query_name_array_free(contact_query_name_array contact_array, int length); + +/** + * @brief Retrieves all number contacts from all of address books with array + * + * @remarks @a contact_number_array must be released with contact_query_number_array_free() by you. + * + * @param[out] contact_number_array The contact array + * @param[out] length The length of the contact array + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTACTS_ERROR_DB_FAILED Database operation failure + * + * @pre This function requires an open connection to contacts service by contacts_connect(). + * + * @see contact_query_number_array_free() + * @see contacts_connect() + */ +int contact_get_number_contact_from_db(contact_query_number_array *contact_number_array, int *length); + +/** + * @brief Frees contact number array + * + * @param[out] contact_number_array The contact array + * @param[out] length The length of the contact array + * + * @return 0 on success, otherwise a negative error value. + * @retval #CONTACTS_ERROR_NONE Successful + * @retval #CONTACTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see contact_get_number_contact_from_db() */ -int contact_query_contact_by_version(contact_foreach_query_version_cb callback, int contacts_db_version, void *user_data); +int contact_query_number_array_free(contact_query_number_array contact_number_array, int length); /** * @} diff --git a/include/contacts_types.h b/include/contacts_types.h index 4bb7648..5a9e7ed 100755 --- a/include/contacts_types.h +++ b/include/contacts_types.h @@ -271,7 +271,6 @@ typedef struct _contacts_group_s* contacts_group_h; /** * @brief The structure of contact in search results. * - * * @see contact_foreach_query_name_cb() */ typedef struct { @@ -282,6 +281,14 @@ typedef struct { char* contact_image_path; /**< Path to persons picture */ }contact_query_name_s; +/** + * @brief The array type of #contact_query_name_s + * + * @see contact_query_name_s + * @see contact_get_all_contact_from_db() + * @see contact_query_name_array_free() + */ +typedef contact_query_name_s** contact_query_name_array; /** * @brief The structure of number in search results. @@ -299,6 +306,15 @@ typedef struct } contact_query_number_s; /** + * @brief The array type of #contact_query_number_s + * + * @see contact_query_number_s + * @see contact_get_number_contact_from_db() + * @see contact_query_number_array_free() + */ +typedef contact_query_number_s** contact_query_number_array; + +/** * @brief The structure of email in search results. * * @see contact_foreach_query_email_cb() @@ -315,17 +331,18 @@ typedef struct /** * @brief The structure of group in search results. - * @see contacts_foreach_group_cb() + * @see contacts_foreach_query_group_cb() */ typedef struct { int group_db_id; /**< Group database id */ + int address_book_db_id; /**< Address book database id */ char* group_name; /**< Group name */ } contacts_query_group_s; /** * @brief The structure of favorite in search results. - * @see contact_foreach_favorites_cb() + * @see contact_foreach_query_favorites_cb() */ typedef struct { @@ -425,7 +442,7 @@ typedef bool (*contact_foreach_query_version_cb)(contact_query_version_s *query_ * @see contact_foreach_favorite_contact_from_db() * */ -typedef bool (*contact_foreach_favorites_cb)(contact_query_favorite_s *query_favorite, void *user_data); +typedef bool (*contact_foreach_query_favorites_cb)(contact_query_favorite_s *query_favorite, void *user_data); /** * @ingroup CAPI_SOCIAL_CONTACTS_GROUP_MODULE @@ -440,8 +457,22 @@ typedef bool (*contact_foreach_favorites_cb)(contact_query_favorite_s *query_fav * * @see contacts_group_foreach_group_from_db() */ -typedef bool (*contacts_foreach_group_cb)(contacts_query_group_s *query_group, void *user_data); +typedef bool (*contacts_foreach_query_group_cb)(contacts_query_group_s *query_group, void *user_data); +/** + * @ingroup CAPI_SOCIAL_CONTACTS_CONTACT_MODULE + * @brief The callback function to get vCard stream + * + * @param[in] vcard_stream The vCard stream + * @param[in] user_data The user data passed from the foreach function + * + * @return @c true to continue with the next iteration of the loop or @c false to break out of the loop. + * + * @pre contact_parse_multi_vcard() will invoke this callback. + * + * @see contact_parse_multi_vcard() + */ +typedef bool (*contacts_vcard_stream_cb)(const char *vcard_stream, void *user_data); /** * @addtogroup CAPI_SOCIAL_CONTACTS_CONTACT_MODULE @@ -569,7 +600,84 @@ typedef enum CONTACT_COMPANY_DETAIL_ASSISTANT /**< Assistant name */ } contact_company_detail_e; +/** + * @} + */ +/** + * @ingroup CAPI_SOCIAL_CONTACTS_MODULE + * @defgroup CAPI_SOCIAL_CONTACTS_ADDRESS_BOOK_MODULE Address Book + * + * @brief Address book definition and Address book related operations. + * + * @section SOCIAL_CONTACTS_ADDRESS_BOOK_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_SOCIAL_CONTACTS_ADDRESS_BOOK_OVERVIEW Overview + * Address book + * + *
+ */ + +/** + * @addtogroup CAPI_SOCIAL_CONTACTS_ADDRESS_BOOK_MODULE + * @{ + */ + +/** + * @brief Enumerations for address book types. + */ +typedef enum +{ + CONTACTS_ADDRESS_BOOK_TYPE_DEFAULT, /**< Default */ + CONTACTS_ADDRESS_BOOK_TYPE_EXCHANGE, /**< Exchange */ + CONTACTS_ADDRESS_BOOK_TYPE_GOOGLE, /**< Goolge */ + CONTACTS_ADDRESS_BOOK_TYPE_YAHOO, /**< Yahoo */ + CONTACTS_ADDRESS_BOOK_TYPE_FACEBOOK, /**< Facebook */ + CONTACTS_ADDRESS_BOOK_TYPE_OTHER /**< Other domains */ +} contacts_address_book_type_e; + +/** + * @brief Definition for default address book database ID + */ +#define DEFAULT_ADDRESS_BOOK_DB_ID 0 + +/** + * @brief The structure of address book in search results. + * + * @see contacts_foreach_query_address_book_cb() + */ +typedef struct +{ + int address_book_db_id; /**< address book database ID */ + char* address_book_name; /**< address book name */ + bool address_book_is_read_only; /**< address book read only status */ + contacts_address_book_type_e address_book_type; /**< address book type */ + int account_db_id; /**< account database ID */ +}contacts_query_address_book_s; + +/** + * @brief The callback function to get the address book + * + * @param[in] address_book The address book + * @param[in] user_data The user data passed from the foreach function + * + * @return @c true to continue with the next iteration of the loop or @c false to break out of the loop. + * + * @pre contacts_address_book_foreach_address_book_from_db() will invoke this callback. + * + * @see contacts_address_book_foreach_address_book_from_db() + * @see contacts_address_book_query_address_book_by_account_db_id() + */ +typedef bool (*contacts_foreach_query_address_book_cb)(contacts_query_address_book_s *address_book, void *user_data); + +/** + * @brief The address book handle. + * + * @see contacts_address_book_get_from_db() + * @see contacts_address_book_destroy() + */ +typedef struct _contacts_address_book_s* contacts_address_book_h; /** * @} diff --git a/include/contacts_web.h b/include/contacts_web.h index 8cb51cc..f2f2367 100755 --- a/include/contacts_web.h +++ b/include/contacts_web.h @@ -155,8 +155,6 @@ int contact_web_iterator_next(contact_web_iterator_h *web_iterator, contact_web_ */ bool contact_web_iterator_has_next(contact_web_iterator_h web_iterator); - - /** * @} */ diff --git a/src/contacts.c b/src/contacts.c index db041f4..35a5222 100755 --- a/src/contacts.c +++ b/src/contacts.c @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef LOG_TAG #undef LOG_TAG @@ -51,10 +52,7 @@ int contacts_disconnect(void) int contacts_get_db_version(int* contacts_db_version) { - if(contacts_db_version == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(contacts_db_version); if(contacts_svc_begin_trans() != CTS_SUCCESS) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); @@ -66,13 +64,34 @@ int contacts_get_db_version(int* contacts_db_version) return CONTACTS_ERROR_NONE; } -int contacts_add_contact_db_changed_cb(contacts_db_changed_cb callback, void *user_data) +int contacts_add_address_book_db_changed_cb(contacts_db_changed_cb callback, void *user_data) +{ + CONTACTS_NULL_ARG_CHECK(callback); + + if(contacts_svc_subscribe_change(CTS_SUBSCRIBE_ADDRESSBOOK_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_address_book_db_changed_cb(contacts_db_changed_cb callback) { - if(callback == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; + CONTACTS_NULL_ARG_CHECK(callback); + + if(contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_ADDRESSBOOK_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; +} + +int contacts_add_contact_db_changed_cb(contacts_db_changed_cb callback, void *user_data) +{ + CONTACTS_NULL_ARG_CHECK(callback); + if(contacts_svc_subscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE, callback, user_data) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; } @@ -83,10 +102,7 @@ int contacts_add_contact_db_changed_cb(contacts_db_changed_cb callback, void *us int contacts_remove_contact_db_changed_cb(contacts_db_changed_cb callback) { - if(callback == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(callback); if(contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE, callback) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -98,10 +114,7 @@ int contacts_remove_contact_db_changed_cb(contacts_db_changed_cb callback) int contacts_add_favorite_db_changed_cb(contacts_db_changed_cb callback, void *user_data) { - if(callback == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(callback); if(contacts_svc_subscribe_change(CTS_SUBSCRIBE_FAVORITE_CHANGE, callback, user_data) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -113,11 +126,8 @@ int contacts_add_favorite_db_changed_cb(contacts_db_changed_cb callback, void *u int contacts_remove_favorite_db_changed_cb(contacts_db_changed_cb callback) { - if(callback == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } - + CONTACTS_NULL_ARG_CHECK(callback); + if(contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_FAVORITE_CHANGE, callback) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; } @@ -128,10 +138,7 @@ int contacts_remove_favorite_db_changed_cb(contacts_db_changed_cb callback) int contacts_add_group_db_changed_cb(contacts_db_changed_cb callback, void *user_data) { - if(callback == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(callback); if(contacts_svc_subscribe_change(CTS_SUBSCRIBE_GROUP_CHANGE, callback, user_data) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -143,10 +150,7 @@ 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) { - if(callback == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(callback); if(contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_GROUP_CHANGE, callback) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -156,3 +160,167 @@ int contacts_remove_group_db_changed_cb(contacts_db_changed_cb callback) return CONTACTS_ERROR_INVALID_PARAMETER; } +int contacts_import_all_contacts_from_sim_card() +{ + int ret = contacts_svc_import_sim(); + if(CTS_ERR_DB_FAILED == ret || CTS_ERR_DB_NOT_OPENED == ret) { + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; + } + return CONTACTS_ERROR_NONE; +} + +int contacts_address_book_foreach_address_book_from_db(contacts_foreach_query_address_book_cb callback, void *user_data) +{ + CONTACTS_NULL_ARG_CHECK(callback); + + CTSiter *iter = NULL; + int func_ret = 0; + if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_ADDRESSBOOK, &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_query_address_book_s query_data; + _contacts_set_query_address_book_struct(&query_data, foreach_data); + + func_ret = callback(&query_data, user_data); + + contacts_svc_value_free(foreach_data); + _contacts_free_query_address_book_struct_member_only(&query_data); + + if(func_ret == 0) { + break; + } + } + + contacts_svc_iter_remove(iter); + return CONTACTS_ERROR_NONE; +} + +int contacts_address_book_query_address_book_by_account_db_id(contacts_foreach_query_address_book_cb callback, int account_db_id, void *user_data) +{ + CONTACTS_NULL_ARG_CHECK(callback); + + CTSiter *iter = NULL; + int func_ret = 0; + if(CTS_SUCCESS != contacts_svc_get_list_with_int(CTS_LIST_ADDRESSBOOKS_OF_ACCOUNT_ID, account_db_id, &iter)) { + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; + } + + while(CTS_SUCCESS == contacts_svc_iter_next(iter)) { + CTSvalue* foreach_data = contacts_svc_iter_get_info(iter); + if(foreach_data == NULL) { + break; + } + contacts_query_address_book_s query_data; + _contacts_set_query_address_book_struct(&query_data, foreach_data); + + func_ret = callback(&query_data, user_data); + + contacts_svc_value_free(foreach_data); + _contacts_free_query_address_book_struct_member_only(&query_data); + + if(func_ret == 0) { + break; + } + } + contacts_svc_iter_remove(iter); + + return CONTACTS_ERROR_NONE; +} + +int contacts_address_book_get_from_db(int address_book_db_id, contacts_address_book_h *address_book) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0); + + int ret = CTS_SUCCESS; + if((ret=contacts_svc_get_addressbook(address_book_db_id, (CTSvalue**)address_book)) == 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 contacts_address_book_destroy(contacts_address_book_h address_book) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + + if(contacts_svc_value_free((CTSvalue*)address_book) == 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_address_book_get_db_id(contacts_address_book_h address_book, int *address_book_db_id) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + CONTACTS_NULL_ARG_CHECK(address_book_db_id); + + *address_book_db_id = 0; + *address_book_db_id = contacts_svc_value_get_int((CTSvalue*)address_book, CTS_ADDRESSBOOK_VAL_ID_INT); + if(*address_book_db_id < 0) { + *address_book_db_id = 0; + } + return CONTACTS_ERROR_NONE; +} + +int contacts_address_book_get_name(contacts_address_book_h address_book, char **address_book_name) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + CONTACTS_NULL_ARG_CHECK(address_book_name); + + *address_book_name = NULL; + *address_book_name = _contacts_safe_strdup(contacts_svc_value_get_str((CTSvalue*)address_book, CTS_ADDRESSBOOK_VAL_NAME_STR)); + + 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); + CONTACTS_NULL_ARG_CHECK(is_read_only); + + *is_read_only = false; + *is_read_only = contacts_svc_value_get_int((CTSvalue*)address_book, CTS_ADDRESSBOOK_VAL_MODE_INT); + + 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); + CONTACTS_NULL_ARG_CHECK(address_book_type); + + *address_book_type = CONTACTS_ADDRESS_BOOK_TYPE_OTHER; + *address_book_type = contacts_svc_value_get_int((CTSvalue*)address_book, CTS_ADDRESSBOOK_VAL_ACC_TYPE_INT); + + return CONTACTS_ERROR_NONE; +} + +int contacts_address_book_get_account_db_id(contacts_address_book_h address_book, int *account_db_id) +{ + CONTACTS_NULL_ARG_CHECK(address_book); + CONTACTS_NULL_ARG_CHECK(account_db_id); + + *account_db_id = 0; + *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; +} + diff --git a/src/contacts_address.c b/src/contacts_address.c index bb7f23e..e1adc80 100755 --- a/src/contacts_address.c +++ b/src/contacts_address.c @@ -33,10 +33,8 @@ int contact_address_create(contact_address_h* address) { - if(address == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(address); + CTSvalue* ret = contacts_svc_value_new(CTS_VALUE_POSTAL); if(ret == NULL) { LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); @@ -50,10 +48,8 @@ int contact_address_create(contact_address_h* address) int contact_address_destroy(contact_address_h address) { - if(address == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(address); + if(contacts_svc_value_free((CTSvalue*)address) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; } @@ -64,10 +60,9 @@ int contact_address_destroy(contact_address_h address) int contact_address_get_type(contact_address_h address, contact_address_type_e* type) { - if(type == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(address); + CONTACTS_NULL_ARG_CHECK(type); + CTSvalue * CTSaddress = (CTSvalue *)address; *type = contacts_svc_value_get_int(CTSaddress, CTS_POSTAL_VAL_TYPE_INT); @@ -88,10 +83,9 @@ int contact_address_set_type(contact_address_h address, contact_address_type_e t int contact_address_get_detail(contact_address_h address, contact_address_detail_e detail_type, char** data) { - if(address == NULL || data == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(address); + CONTACTS_NULL_ARG_CHECK(data); + *data = NULL; CTSvalue * CTSaddress = (CTSvalue *)address; switch(detail_type) @@ -128,10 +122,9 @@ int contact_address_get_detail(contact_address_h address, contact_address_detail int contact_address_set_detail(contact_address_h address, contact_address_detail_e detail_type, const char* data) { - if(address == NULL || data == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(address); + CONTACTS_NULL_ARG_CHECK(data); + CTSvalue * CTSaddress = (CTSvalue *)address; int ret = CTS_ERR_ARG_INVALID; switch(detail_type) @@ -167,10 +160,9 @@ int contact_address_set_detail(contact_address_h address, contact_address_detail int contact_address_iterator_next(contact_address_iterator_h* address_iterator, contact_address_h* address) { - if(address_iterator == NULL || address == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(address_iterator); + CONTACTS_NULL_ARG_CHECK(address); + *address = NULL; GSList* gslist = (GSList*)*address_iterator; gslist = _contacts_gslist_next_until_not_deleted(gslist); diff --git a/src/contacts_company.c b/src/contacts_company.c index 7bdcd17..5b5fd2f 100755 --- a/src/contacts_company.c +++ b/src/contacts_company.c @@ -32,10 +32,8 @@ int contact_company_create(contact_company_h* company) { - if(company == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(company); + CTSvalue* ret = contacts_svc_value_new(CTS_VALUE_COMPANY); if(ret == NULL) { LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); @@ -48,10 +46,7 @@ int contact_company_create(contact_company_h* company) int contact_company_destroy(contact_company_h company) { - if(company == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(company); if(contacts_svc_value_free((CTSvalue*)company) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -63,10 +58,9 @@ int contact_company_destroy(contact_company_h company) int contact_company_get_detail(contact_company_h company, contact_company_detail_e detail_type, char** data) { - if(company == NULL || data == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(company); + CONTACTS_NULL_ARG_CHECK(data); + CTSvalue * CTScompany = (CTSvalue *)company; *data = NULL; switch(detail_type) @@ -94,10 +88,9 @@ int contact_company_get_detail(contact_company_h company, contact_company_detail int contact_company_set_detail(contact_company_h company, contact_company_detail_e detail_type, const char* data) { - if(company == NULL || data == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(company); + CONTACTS_NULL_ARG_CHECK(data); + CTSvalue * CTScompany = (CTSvalue *)company; int ret = CTS_ERR_ARG_INVALID; switch(detail_type) diff --git a/src/contacts_contact.c b/src/contacts_contact.c index a8901a0..5b66d59 100755 --- a/src/contacts_contact.c +++ b/src/contacts_contact.c @@ -32,10 +32,8 @@ 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + 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); @@ -48,10 +46,7 @@ int contact_create(contact_h* contact) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); if(contacts_svc_struct_free((CTSstruct*)contact) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -61,14 +56,13 @@ int contact_destroy(contact_h contact) return CONTACTS_ERROR_INVALID_PARAMETER; } -int contact_insert_to_db(contact_h contact, int *db_id) +int contact_insert_to_db(contact_h contact, int address_book_db_id, int *db_id) { - if(contact == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0); + int contact_index = -1; - contact_index = contacts_svc_insert_contact(0, (CTSstruct*)contact); + contact_index = contacts_svc_insert_contact(address_book_db_id, (CTSstruct*)contact); if(contact_index < 0) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; @@ -82,10 +76,7 @@ int contact_insert_to_db(contact_h contact, int *db_id) 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; - } + CONTACTS_INVALID_ARG_CHECK(db_id <= 0); int ret = CTS_SUCCESS; if((ret=contacts_svc_delete_contact(db_id)) == CTS_SUCCESS) { @@ -100,10 +91,7 @@ int contact_delete_from_db(int db_id) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); int ret = CTS_SUCCESS; if((ret=contacts_svc_update_contact((CTSstruct*)contact)) == CTS_SUCCESS) { @@ -118,10 +106,8 @@ int contact_update_to_db(contact_h contact) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_INVALID_ARG_CHECK(db_id <= 0); int ret = CTS_SUCCESS; if((ret=contacts_svc_get_contact(db_id, (CTSstruct**)contact)) == CTS_SUCCESS) { @@ -136,10 +122,9 @@ int contact_get_from_db(int db_id, contact_h* contact) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(db_id); + int ret = 0; *db_id = 0; CTSvalue* base = NULL; @@ -155,10 +140,7 @@ int contact_get_db_id(contact_h contact, int* db_id) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); bool need_to_free = false; GSList *cursor = NULL; @@ -199,10 +181,7 @@ int contact_add_group(contact_h contact, int group_db_id) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); int ret = CONTACTS_ERROR_INVALID_PARAMETER; GSList *group_relation_list = NULL; @@ -232,10 +211,8 @@ int contact_remove_group(contact_h contact, int group_db_id) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(name); *name = NULL; int ret = CTS_SUCCESS; @@ -251,10 +228,8 @@ int contact_get_name(contact_h contact, contact_name_h* name) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(name); if(contacts_svc_struct_store_value((CTSstruct*)contact, CTS_CF_NAME_VALUE, (CTSvalue*)name) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -266,10 +241,8 @@ int contact_set_name(contact_h contact, contact_name_h name) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(number); *number = NULL; GSList *cursor = NULL; @@ -286,10 +259,8 @@ int contact_get_default_number(contact_h contact, contact_number_h* number) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(number); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NUMBER_LIST, &cursor); @@ -314,10 +285,8 @@ int contact_add_number(contact_h contact, contact_number_h number) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(number); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NUMBER_LIST, &cursor); @@ -334,10 +303,8 @@ int contact_remove_number(contact_h contact, contact_number_h number) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(number_iterator); *number_iterator = NULL; int ret = CTS_SUCCESS; @@ -353,10 +320,8 @@ int contact_get_number_iterator(contact_h contact, contact_number_iterator_h* nu 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(email); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EMAIL_LIST, &cursor); @@ -383,10 +348,8 @@ int contact_add_email(contact_h contact, contact_email_h email) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(email); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EMAIL_LIST, &cursor); @@ -403,10 +366,8 @@ int contact_remove_email(contact_h contact, contact_email_h email) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(email_iterator); *email_iterator = NULL; int ret = CTS_SUCCESS; @@ -422,10 +383,8 @@ int contact_get_email_iterator(contact_h contact, contact_email_iterator_h* emai 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(address); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_POSTAL_ADDR_LIST, &cursor); @@ -452,10 +411,8 @@ int contact_add_address(contact_h contact, contact_address_h address) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(address); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_POSTAL_ADDR_LIST, &cursor); @@ -472,10 +429,8 @@ int contact_remove_address(contact_h contact, contact_address_h address) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(address_iterator); *address_iterator = NULL; int ret = CTS_SUCCESS; @@ -491,10 +446,8 @@ int contact_get_address_iterator(contact_h contact, contact_address_iterator_h* 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(company); if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_COMPANY_VALUE, (CTSvalue**)company) == CTS_SUCCESS){ return CONTACTS_ERROR_NONE; @@ -506,10 +459,8 @@ int contact_get_company(contact_h contact, contact_company_h* company) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(company); if(contacts_svc_struct_store_value((CTSstruct*)contact, CTS_CF_COMPANY_VALUE, (CTSvalue*)company) == CTS_SUCCESS){ return CONTACTS_ERROR_NONE; @@ -521,10 +472,8 @@ int contact_set_company(contact_h contact, contact_company_h company) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(birthday); *birthday = NULL; GSList *cursor = NULL; @@ -539,10 +488,8 @@ int contact_get_birthday(contact_h contact, contact_birthday_h* birthday) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(birthday); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_EVENT_LIST, &cursor); @@ -551,14 +498,15 @@ int contact_set_birthday(contact_h contact, contact_birthday_h birthday) 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); - } + 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); + } + } } 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 { @@ -573,12 +521,29 @@ int contact_set_birthday(contact_h contact, contact_birthday_h birthday) return ret; } -int contact_add_messenger(contact_h contact, contact_messenger_h messenger) +int contact_unset_birthday(contact_h contact) { - if(contact == NULL || messenger == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; + 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_add_messenger(contact_h contact, contact_messenger_h messenger) +{ + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(messenger); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_MESSENGER_LIST, &cursor); @@ -605,10 +570,8 @@ int contact_add_messenger(contact_h contact, contact_messenger_h messenger) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(messenger); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_MESSENGER_LIST, &cursor); @@ -625,10 +588,8 @@ int contact_remove_messenger(contact_h contact, contact_messenger_h messenger) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(messenger_iterator); int ret = CTS_SUCCESS; if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_MESSENGER_LIST, (GSList**)messenger_iterator)) == CTS_SUCCESS){ @@ -643,10 +604,8 @@ int contact_get_messenger_iterator(contact_h contact, contact_messenger_iterator 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(nickname); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NICKNAME_LIST, &cursor); @@ -674,10 +633,8 @@ int contact_add_nickname(contact_h contact, contact_nickname_h nickname) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(nickname); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NICKNAME_LIST, &cursor); @@ -694,10 +651,8 @@ int contact_remove_nickname(contact_h contact, contact_nickname_h nickname) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(nickname_iterator); int ret = CTS_SUCCESS; if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_NICKNAME_LIST, (GSList**)nickname_iterator)) == CTS_SUCCESS){ @@ -712,10 +667,8 @@ int contact_get_nickname_iterator(contact_h contact, contact_nickname_iterator_h 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(web); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_WEB_ADDR_LIST, &cursor); @@ -742,10 +695,8 @@ int contact_add_web(contact_h contact, contact_web_h web) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(web); GSList *cursor = NULL; contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_WEB_ADDR_LIST, &cursor); @@ -762,10 +713,8 @@ int contact_remove_web(contact_h contact, contact_web_h web) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(web_iterator); int ret = CTS_SUCCESS; if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_WEB_ADDR_LIST, (GSList**)web_iterator)) == CTS_SUCCESS){ @@ -780,10 +729,8 @@ int contact_get_web_iterator(contact_h contact, contact_web_iterator_h* web_iter 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(relatedgroup_iterator); int ret = CTS_SUCCESS; if((ret = contacts_svc_struct_get_list((CTSstruct*)contact, CTS_CF_GROUPREL_LIST, (GSList**)relatedgroup_iterator)) == CTS_SUCCESS) { @@ -798,10 +745,9 @@ int contact_get_relatedgroup_iterator(contact_h contact, contact_relatedgroup_it 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(src_img); + int ret = CONTACTS_ERROR_INVALID_PARAMETER; int ret_temp = 0; CTSvalue* base = NULL; @@ -828,10 +774,9 @@ int contact_set_image(contact_h contact, const char* src_img) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(img_path); + *img_path = NULL; CTSvalue* base = NULL; if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base) != CTS_SUCCESS) { @@ -845,10 +790,9 @@ int contact_get_image(contact_h contact, char** img_path) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(ringtone_path); + *ringtone_path = NULL; CTSvalue* base = NULL; if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base) != CTS_SUCCESS) { @@ -861,10 +805,9 @@ int contact_get_ringtonepath(contact_h contact, char** ringtone_path) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(ringtone_path); + int ret = CTS_SUCCESS; CTSvalue* base = NULL; if((ret = contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base)) != CTS_SUCCESS) { @@ -891,10 +834,9 @@ int contact_set_ringtonepath(contact_h contact, const char* ringtone_path) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(note); + *note = NULL; CTSvalue* base = NULL; if(contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base) != CTS_SUCCESS) { @@ -907,10 +849,9 @@ int contact_get_note(contact_h contact, char** note) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(note); + int ret = CTS_SUCCESS; CTSvalue* base = NULL; if((ret = contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base)) != CTS_SUCCESS) { @@ -937,10 +878,8 @@ int contact_set_note(contact_h contact, const char* note) 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; - } + CONTACTS_NULL_ARG_CHECK(count); + *count = contacts_svc_count(CTS_GET_ALL_CONTACT); return CONTACTS_ERROR_NONE; } @@ -949,10 +888,8 @@ int contact_get_total_count_from_db(int* count) 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; - } + CONTACTS_NULL_ARG_CHECK(vcard_stream); + CONTACTS_NULL_ARG_CHECK(contact); if(contacts_svc_get_contact_from_vcard((const void*)vcard_stream, (CTSstruct**)contact) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -964,10 +901,8 @@ int contact_get_from_vcard(const char *vcard_stream, contact_h *contact) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(vcard_stream); if(contacts_svc_get_vcard_from_contact((const CTSstruct*)contact, vcard_stream) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -977,12 +912,42 @@ int contact_get_vcard_from_contact(contact_h contact, char **vcard_stream) return CONTACTS_ERROR_INVALID_PARAMETER; } +contacts_vcard_stream_cb _parse_multiple_vcard_cb = NULL; + +int contact_parse_multiple_vcard_fw_cb(const char *a_vcard_stream, void *data) +{ + if(_parse_multiple_vcard_cb) { + bool ret = _parse_multiple_vcard_cb(a_vcard_stream, data); + if(ret == false) + return 1; // return 1 means end foreach in F/W + else + return 0; // return 0 means continue foreach in F/W + } + return 1; // return 1 means end foreach in F/W +} + +int contact_parse_multiple_vcard_file(contacts_vcard_stream_cb callback, const char *multiple_vcard_file_path, void *user_data) +{ + CONTACTS_NULL_ARG_CHECK(callback); + CONTACTS_NULL_ARG_CHECK(multiple_vcard_file_path); + + _parse_multiple_vcard_cb = callback; + int ret = contacts_svc_vcard_foreach(multiple_vcard_file_path, contact_parse_multiple_vcard_fw_cb, user_data); + + if(ret == CTS_SUCCESS || ret == CTS_ERR_FINISH_ITER) { + return CONTACTS_ERROR_NONE; + } else if(ret == CTS_ERR_OUT_OF_MEMORY) { + LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); + return CONTACTS_ERROR_OUT_OF_MEMORY; + } + + 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; - } + CONTACTS_INVALID_ARG_CHECK(contact_db_id <= 0); if(CTS_SUCCESS == contacts_svc_set_favorite(CTS_FAVOR_CONTACT, contact_db_id)) { return CONTACTS_ERROR_NONE; @@ -994,10 +959,7 @@ int contact_set_favorite_to_db(int contact_db_id) 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; - } + CONTACTS_INVALID_ARG_CHECK(contact_db_id <= 0); if(CTS_SUCCESS == contacts_svc_unset_favorite(CTS_FAVOR_CONTACT, contact_db_id)) { return CONTACTS_ERROR_NONE; @@ -1009,10 +971,8 @@ int contact_unset_favorite_to_db(int contact_db_id) 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; - } + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(is_favorite); *is_favorite = false; CTSvalue* base = NULL; @@ -1026,11 +986,8 @@ int contact_get_favorite(contact_h contact, bool *is_favorite) 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; - } - + CONTACTS_NULL_ARG_CHECK(contact); + int ret = CTS_SUCCESS; CTSvalue* base = NULL; if((ret = contacts_svc_struct_get_value((CTSstruct*)contact, CTS_CF_BASE_INFO_VALUE, &base)) != CTS_SUCCESS) { @@ -1055,3 +1012,52 @@ int contact_set_favorite(contact_h contact, bool is_favorite) return CONTACTS_ERROR_INVALID_PARAMETER; } +int contact_get_address_book_db_id(contact_h contact, int *address_book_db_id) +{ + CONTACTS_NULL_ARG_CHECK(contact); + CONTACTS_NULL_ARG_CHECK(address_book_db_id); + + int ret = 0; + *address_book_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; + } + *address_book_db_id = contacts_svc_value_get_int(base, CTS_BASE_VAL_ADDRESSBOOK_ID_INT); + if(*address_book_db_id < 0) { + *address_book_db_id = 0; + } + return CONTACTS_ERROR_NONE; +} + +int contact_get_total_count_in_address_book(int address_book_db_id, int *count) +{ + CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0); + CONTACTS_NULL_ARG_CHECK(count); + + *count = contacts_svc_count_with_int(CTS_GET_COUNT_CONTACTS_IN_ADDRESSBOOK, address_book_db_id); + return CONTACTS_ERROR_NONE; +} + +int contact_get_total_count_not_related_to_group(int address_book_db_id, int *count) +{ + CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0); + CONTACTS_NULL_ARG_CHECK(count); + + *count = contacts_svc_count_with_int(CTS_GET_COUNT_NO_GROUP_CONTACTS_IN_ADDRESSBOOK, address_book_db_id); + return CONTACTS_ERROR_NONE; +} + +int contact_unset_frequent_contact(int contact_db_id) +{ + CONTACTS_INVALID_ARG_CHECK(contact_db_id < 1); + int ret = contacts_svc_reset_outgoing_count(contact_db_id); + + if(ret == CTS_ERR_DB_NOT_OPENED || ret == CTS_ERR_DB_FAILED) { + LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); + return CONTACTS_ERROR_DB_FAILED; + } + + return CONTACTS_ERROR_NONE; +} + diff --git a/src/contacts_email.c b/src/contacts_email.c index 8edf26b..143c3ff 100755 --- a/src/contacts_email.c +++ b/src/contacts_email.c @@ -32,10 +32,8 @@ int contact_email_create(contact_email_h* email) { - if(email == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(email); + CTSvalue* ret = contacts_svc_value_new(CTS_VALUE_EMAIL); if(ret == NULL) { LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); @@ -48,10 +46,7 @@ int contact_email_create(contact_email_h* email) int contact_email_destroy(contact_email_h email) { - if(email == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(email); if(contacts_svc_value_free((CTSvalue*)email) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -64,47 +59,39 @@ int contact_email_destroy(contact_email_h email) int contact_email_get_type(contact_email_h email, contact_email_type_e* type) { - if(email == NULL || type == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } - CTSvalue * CTSemail = (CTSvalue *)email; - *type = contacts_svc_value_get_int(CTSemail, CTS_EMAIL_VAL_TYPE_INT); + CONTACTS_NULL_ARG_CHECK(email); + CONTACTS_NULL_ARG_CHECK(type); + + *type = contacts_svc_value_get_int((CTSvalue *)email, CTS_EMAIL_VAL_TYPE_INT); return CONTACTS_ERROR_NONE; } int contact_email_set_type(contact_email_h email, contact_email_type_e type) { - if(email == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } - CTSvalue * CTSemail = (CTSvalue *)email; - contacts_svc_value_set_int(CTSemail, CTS_NUM_VAL_TYPE_INT, type); + CONTACTS_NULL_ARG_CHECK(email); + + contacts_svc_value_set_int((CTSvalue*)email, CTS_EMAIL_VAL_TYPE_INT, type); return CONTACTS_ERROR_NONE; } int contact_email_get_address(contact_email_h email, char** address) { - if(email == NULL || address == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(email); + CONTACTS_NULL_ARG_CHECK(address); + *address = NULL; - CTSvalue * CTSemail = (CTSvalue *)email; - *address = _contacts_safe_strdup(contacts_svc_value_get_str(CTSemail, CTS_EMAIL_VAL_ADDR_STR)); + *address = _contacts_safe_strdup(contacts_svc_value_get_str((CTSvalue*)email, CTS_EMAIL_VAL_ADDR_STR)); return CONTACTS_ERROR_NONE; } int contact_email_set_address(contact_email_h email, const char* address) { - if(email == NULL || address == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(email); + CONTACTS_NULL_ARG_CHECK(address); + CTSvalue * CTSemail = (CTSvalue *)email; contacts_svc_value_set_str(CTSemail, CTS_EMAIL_VAL_ADDR_STR,address); @@ -114,10 +101,9 @@ int contact_email_set_address(contact_email_h email, const char* address) int contact_email_iterator_next(contact_email_iterator_h* email_iterator, contact_email_h* email) { - if(email_iterator == NULL || email == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(email_iterator); + CONTACTS_NULL_ARG_CHECK(email); + *email = NULL; GSList* gslist = (GSList*)*email_iterator; gslist = _contacts_gslist_next_until_not_deleted(gslist); diff --git a/src/contacts_event.c b/src/contacts_event.c index dd51aa7..7ca2228 100755 --- a/src/contacts_event.c +++ b/src/contacts_event.c @@ -31,10 +31,8 @@ int contact_birthday_create(contact_birthday_h* birthday) { - if(birthday == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(birthday); + 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); @@ -48,10 +46,7 @@ int contact_birthday_create(contact_birthday_h* birthday) int contact_birthday_destroy(contact_birthday_h birthday) { - if(birthday == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(birthday); if(contacts_svc_value_free((CTSvalue*)birthday) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -64,10 +59,10 @@ int contact_birthday_destroy(contact_birthday_h birthday) int contact_birthday_get_date(contact_birthday_h birthday, int *year, int *month, int *day) { - if(birthday == NULL || year == NULL || month == NULL || day == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(birthday); + CONTACTS_NULL_ARG_CHECK(year); + CONTACTS_NULL_ARG_CHECK(month); + CONTACTS_NULL_ARG_CHECK(day); CTSvalue * CTSevent = (CTSvalue *)birthday; int date = contacts_svc_value_get_int(CTSevent, CTS_EVENT_VAL_DATE_INT); @@ -83,10 +78,8 @@ int contact_birthday_get_date(contact_birthday_h birthday, int *year, int *month int contact_birthday_set_date(contact_birthday_h birthday, int year, int month, int day) { - if(birthday == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(birthday); + CTSvalue * CTSevent = (CTSvalue *)birthday; contacts_svc_value_set_int(CTSevent, CTS_EVENT_VAL_DATE_INT, year*10000 + month*100 + day); diff --git a/src/contacts_group.c b/src/contacts_group.c index ba86f14..8d6cf61 100755 --- a/src/contacts_group.c +++ b/src/contacts_group.c @@ -32,10 +32,7 @@ int contacts_group_create(contacts_group_h* group) { - if(group == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(group); CTSvalue* ret = contacts_svc_value_new(CTS_VALUE_GROUP); if(ret == NULL) { @@ -49,10 +46,7 @@ int contacts_group_create(contacts_group_h* group) int contacts_group_destroy(contacts_group_h group) { - if(group == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(group); if(contacts_svc_value_free((CTSvalue*)group) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -62,13 +56,13 @@ int contacts_group_destroy(contacts_group_h group) return CONTACTS_ERROR_INVALID_PARAMETER; } -int contacts_group_insert_to_db(contacts_group_h group, int* db_id) +int contacts_group_insert_to_db(contacts_group_h group, int address_book_db_id, int* db_id) { - if(group == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } - int group_index = contacts_svc_insert_group(0, (CTSvalue*)group); + CONTACTS_NULL_ARG_CHECK(group); + CONTACTS_NULL_ARG_CHECK(db_id); + CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0); + + int group_index = contacts_svc_insert_group(address_book_db_id, (CTSvalue*)group); if(group_index < 0) { LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED); return CONTACTS_ERROR_DB_FAILED; @@ -81,10 +75,7 @@ int contacts_group_insert_to_db(contacts_group_h group, int* db_id) int contacts_group_update_to_db(contacts_group_h group) { - if(group == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(group); int ret = CTS_SUCCESS; if((ret=contacts_svc_update_group((CTSvalue*)group)) == CTS_SUCCESS) { @@ -100,10 +91,7 @@ int contacts_group_update_to_db(contacts_group_h group) int contacts_group_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; - } + CONTACTS_INVALID_ARG_CHECK(db_id <= 0); int ret = CTS_SUCCESS; if((ret=contacts_svc_delete_group(db_id)) == CTS_SUCCESS) { @@ -119,10 +107,9 @@ int contacts_group_delete_from_db(int db_id) int contacts_group_get_db_id(contacts_group_h group, int* db_id) { - if(group == NULL || db_id == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(group); + CONTACTS_NULL_ARG_CHECK(db_id); + *db_id = contacts_svc_value_get_int((CTSvalue*)group, CTS_GROUP_VAL_ID_INT); if(*db_id < 0) { *db_id = 0; @@ -133,10 +120,8 @@ int contacts_group_get_db_id(contacts_group_h group, int* db_id) int contacts_group_get_from_db(int db_id, contacts_group_h* group) { - if(group == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_INVALID_ARG_CHECK(db_id <= 0); + CONTACTS_NULL_ARG_CHECK(group); int ret = CTS_SUCCESS; if((ret=contacts_svc_get_group(db_id, (CTSvalue**)group)) == CTS_SUCCESS) { @@ -152,8 +137,9 @@ int contacts_group_get_from_db(int db_id, contacts_group_h* group) int contacts_group_get_name(contacts_group_h group, char** name) { - if(group == NULL || name == NULL) - return CONTACTS_ERROR_INVALID_PARAMETER; + CONTACTS_NULL_ARG_CHECK(group); + CONTACTS_NULL_ARG_CHECK(name); + *name = NULL; *name = _contacts_safe_strdup(contacts_svc_value_get_str((CTSvalue*)group, CTS_GROUP_VAL_NAME_STR)); @@ -162,10 +148,8 @@ int contacts_group_get_name(contacts_group_h group, char** name) int contacts_group_set_name(contacts_group_h group, const char* name) { - if(group == NULL || name == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(group); + CONTACTS_NULL_ARG_CHECK(name); if(contacts_svc_value_set_str((CTSvalue*)group, CTS_GROUP_VAL_NAME_STR, name) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -178,10 +162,9 @@ int contacts_group_set_name(contacts_group_h group, const char* name) int contacts_group_get_ringtonepath(contacts_group_h group, char** ringtonepath) { - if(ringtonepath == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(group); + CONTACTS_NULL_ARG_CHECK(ringtonepath); + *ringtonepath = NULL; *ringtonepath = _contacts_safe_strdup(contacts_svc_value_get_str((CTSvalue*)group, CTS_GROUP_VAL_RINGTONE_STR)); @@ -190,10 +173,8 @@ int contacts_group_get_ringtonepath(contacts_group_h group, char** ringtonepath) int contacts_group_set_ringtonepath(contacts_group_h group, const char* ringtonepath) { - if(group == NULL || ringtonepath == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(group); + CONTACTS_NULL_ARG_CHECK(ringtonepath); if(contacts_svc_value_set_str((CTSvalue*)group, CTS_GROUP_VAL_RINGTONE_STR, ringtonepath) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -205,10 +186,9 @@ int contacts_group_set_ringtonepath(contacts_group_h group, const char* ringtone int contacts_group_get_member_count_from_db(contacts_group_h group, int* count) { - if(count == NULL || group == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(group); + CONTACTS_NULL_ARG_CHECK(count); + int group_id = contacts_svc_value_get_int((CTSvalue*)group, CTS_GROUP_VAL_ID_INT); if(group_id < 0) { LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); @@ -219,12 +199,10 @@ int contacts_group_get_member_count_from_db(contacts_group_h group, int* count) return CONTACTS_ERROR_NONE; } -int contacts_group_foreach_group_from_db(contacts_foreach_group_cb cb, void* user_data) +int contacts_group_foreach_group_from_db(contacts_foreach_query_group_cb cb, void* user_data) { - if(cb == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(cb); + CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_GROUP, &iter)) { @@ -240,6 +218,7 @@ int contacts_group_foreach_group_from_db(contacts_foreach_group_cb cb, void* use contacts_query_group_s query_data; 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)); func_ret = cb(&query_data, user_data); @@ -256,3 +235,52 @@ int contacts_group_foreach_group_from_db(contacts_foreach_group_cb cb, void* use return CONTACTS_ERROR_NONE; } +int contacts_group_get_address_book_db_id(contacts_group_h group, int *address_book_db_id) +{ + CONTACTS_NULL_ARG_CHECK(group); + CONTACTS_NULL_ARG_CHECK(address_book_db_id); + + *address_book_db_id = contacts_svc_value_get_int((CTSvalue*)group, CTS_GROUP_VAL_ADDRESSBOOK_ID_INT); + if(*address_book_db_id < 0) { + *address_book_db_id = 0; + } + + return CONTACTS_ERROR_NONE; +} + +int contacts_group_query_group_by_address_book(contacts_foreach_query_group_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; + 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; + } + + 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; + 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)); + + func_ret = callback(&query_data, user_data); + + contacts_svc_value_free(foreach_data); + _contacts_safe_free(query_data.group_name); + + if(func_ret == 0) { + break; + } + } + + contacts_svc_iter_remove(iter); + return CONTACTS_ERROR_NONE;} + diff --git a/src/contacts_messenger.c b/src/contacts_messenger.c index 777ef22..9d38375 100755 --- a/src/contacts_messenger.c +++ b/src/contacts_messenger.c @@ -32,10 +32,8 @@ int contact_messenger_create(contact_messenger_h* messenger) { - if(messenger == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(messenger); + CTSvalue* ret = contacts_svc_value_new(CTS_VALUE_MESSENGER); if(ret == NULL) { LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY); @@ -48,10 +46,8 @@ int contact_messenger_create(contact_messenger_h* messenger) int contact_messenger_destroy(contact_messenger_h messenger) { - if(messenger == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(messenger); + if(contacts_svc_value_free((CTSvalue*)messenger) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; } @@ -62,10 +58,9 @@ int contact_messenger_destroy(contact_messenger_h messenger) int contact_messenger_get_id(contact_messenger_h messenger, char** id) { - if(messenger == NULL || id == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(messenger); + CONTACTS_NULL_ARG_CHECK(id); + *id = NULL; *id = _contacts_safe_strdup(contacts_svc_value_get_str((CTSvalue*)messenger, CTS_MESSENGER_VAL_IM_ID_STR)); @@ -74,10 +69,8 @@ int contact_messenger_get_id(contact_messenger_h messenger, char** id) int contact_messenger_set_id(contact_messenger_h messenger, const char* id) { - if(messenger == NULL || id == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(messenger); + CONTACTS_NULL_ARG_CHECK(id); if(contacts_svc_value_set_str((CTSvalue*)messenger, CTS_MESSENGER_VAL_IM_ID_STR, id) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -89,10 +82,8 @@ int contact_messenger_set_id(contact_messenger_h messenger, const char* id) int contact_messenger_get_type(contact_messenger_h messenger, contact_messenger_type_e *type) { - if(messenger == NULL || type == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(messenger); + CONTACTS_NULL_ARG_CHECK(type); *type = contacts_svc_value_get_int((CTSvalue*)messenger, CTS_MESSENGER_VAL_TYPE_INT); return CONTACTS_ERROR_NONE; @@ -100,10 +91,7 @@ int contact_messenger_get_type(contact_messenger_h messenger, contact_messenger_ int contact_messenger_set_type(contact_messenger_h messenger, contact_messenger_type_e type) { - if(messenger == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(messenger); if(contacts_svc_value_set_int((CTSvalue*)messenger, CTS_MESSENGER_VAL_TYPE_INT, type) == CTS_SUCCESS) { return CONTACTS_ERROR_NONE; @@ -115,10 +103,9 @@ int contact_messenger_set_type(contact_messenger_h messenger, contact_messenger_ int contact_messenger_iterator_next(contact_messenger_iterator_h* messenger_iterator, contact_messenger_h* messenger) { - if(messenger_iterator == NULL || messenger == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(messenger_iterator); + CONTACTS_NULL_ARG_CHECK(messenger); + *messenger = NULL; GSList* gslist = (GSList*)*messenger_iterator; gslist = _contacts_gslist_next_until_not_deleted(gslist); diff --git a/src/contacts_private.c b/src/contacts_private.c index 23cf4ae..78a7561 100755 --- a/src/contacts_private.c +++ b/src/contacts_private.c @@ -40,6 +40,16 @@ void _contacts_free_query_preson_struct_member_only(contact_query_name_s* person _contacts_safe_free(person->contact_image_path); } +void _contacts_free_query_number_struct_member_only(contact_query_number_s* contact) +{ + contact->contact_db_id = -1; + _contacts_safe_free(contact->first_name); + _contacts_safe_free(contact->last_name); + _contacts_safe_free(contact->display_name); + _contacts_safe_free(contact->phone_number); + _contacts_safe_free(contact->contact_image_path); +} + void _contacts_free_query_preson_struct_all(gpointer data, gpointer user_data) { if(data == NULL) @@ -53,6 +63,36 @@ void _contacts_free_query_preson_struct_all(gpointer data, gpointer user_data) _contacts_safe_free(data); } +void _contacts_free_query_number_struct_all(gpointer data, gpointer user_data) +{ + if(data == NULL) + return; + contact_query_number_s* person = (contact_query_number_s*)data; + person->contact_db_id = -1; + _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(data); +} + +void _contacts_set_query_address_book_struct(contacts_query_address_book_s* addressbook, CTSvalue* value) +{ + addressbook->address_book_db_id = contacts_svc_value_get_int(value, CTS_LIST_ADDRESSBOOK_ID_INT); + addressbook->address_book_name = _contacts_safe_strdup(contacts_svc_value_get_str(value, CTS_LIST_ADDRESSBOOK_NAME_STR)); + addressbook->address_book_type = contacts_svc_value_get_int(value, CTS_LIST_ADDRESSBOOK_ACC_TYPE_INT); + addressbook->account_db_id = contacts_svc_value_get_int(value, CTS_LIST_ADDRESSBOOK_ACC_ID_INT); + addressbook->address_book_is_read_only = contacts_svc_value_get_int(value, CTS_LIST_ADDRESSBOOK_MODE_INT); +} + +void _contacts_free_query_address_book_struct_member_only(contacts_query_address_book_s* addressbook) +{ + addressbook->address_book_db_id = 0; + _contacts_safe_free(addressbook->address_book_name); + addressbook->address_book_type = 1; +} + GSList* _contacts_gslist_next_until_not_deleted(GSList* list) { if(list == NULL) diff --git a/src/contacts_search.c b/src/contacts_search.c index f854c26..fe7edb7 100755 --- a/src/contacts_search.c +++ b/src/contacts_search.c @@ -32,10 +32,7 @@ int contact_foreach_contact_from_db(contact_foreach_query_name_cb cb, void* user_data) { - if(cb == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + CONTACTS_NULL_ARG_CHECK(cb); CTSiter *iter = NULL; int func_ret = 0; if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_CONTACT, &iter)) { @@ -73,16 +70,168 @@ int contact_foreach_contact_from_db(contact_foreach_query_name_cb cb, void* user } g_slist_foreach(contactlist, _contacts_free_query_preson_struct_all, NULL); g_slist_free(contactlist); - + return CONTACTS_ERROR_NONE; } -int contact_foreach_favorite_contact_from_db(contact_foreach_favorites_cb cb, void* user_data) +int contact_get_all_contact_from_db(contact_query_name_array *contact_array, int *length) { - if(cb == NULL) { - LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER); - return CONTACTS_ERROR_INVALID_PARAMETER; - } + 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(;icontact_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_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