summaryrefslogtreecommitdiff
path: root/src/contacts_search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/contacts_search.c')
-rwxr-xr-xsrc/contacts_search.c302
1 files changed, 273 insertions, 29 deletions
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(;i<length; i++) {
+ _contacts_free_query_preson_struct_member_only(contact_array[i]);
+ free(contact_array[i]);
+ }
+
+ free(contact_array);
+ return CONTACTS_ERROR_NONE;
+}
+
+int contact_get_number_contact_from_db(contact_query_number_array *contact_number_array, int *length)
+{
+ CONTACTS_NULL_ARG_CHECK(contact_number_array);
+ CONTACTS_NULL_ARG_CHECK(length);
+
+ *contact_number_array = NULL;
+ *length = 0;
+ CTSiter *iter = NULL;
+ if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_CONTACT_HAD_NUMBER, &iter)) {
+ LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED);
+ return CONTACTS_ERROR_DB_FAILED;
+ }
+
+ GSList *contactlist = NULL;
+ while(CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue* foreach_data = contacts_svc_iter_get_info(iter);
+
+ contact_query_number_s *query_data = NULL;
+ query_data = malloc(sizeof(contact_query_number_s));
+ if(query_data == NULL) {
+ g_slist_foreach(contactlist, _contacts_free_query_number_struct_all, NULL);
+ g_slist_free(contactlist);
+ contacts_svc_value_free(foreach_data);
+ contacts_svc_iter_remove(iter);
+ LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY);
+ return CONTACTS_ERROR_OUT_OF_MEMORY;
+ }
+ query_data->contact_db_id = contacts_svc_value_get_int(foreach_data, CTS_LIST_CONTACT_ID_INT);
+ query_data->first_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_FIRST_STR));
+ query_data->last_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_LAST_STR));
+ query_data->display_name = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_DISPLAY_STR));
+ query_data->phone_number = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_NUM_OR_EMAIL_STR));
+ query_data->contact_image_path = _contacts_safe_strdup(contacts_svc_value_get_str(foreach_data, CTS_LIST_CONTACT_IMG_PATH_STR));
+
+ contactlist = g_slist_append(contactlist, query_data);
+
+ contacts_svc_value_free(foreach_data);
+ }
+ contacts_svc_iter_remove(iter);
+
+ *length = g_slist_length(contactlist);
+ if(*length == 0) {
+ g_slist_foreach(contactlist, _contacts_free_query_number_struct_all, NULL);
+ g_slist_free(contactlist);
+ return CONTACTS_ERROR_NONE;
+ }
+ *contact_number_array = malloc(sizeof(contact_query_number_s*) * (*length));
+ if(*contact_number_array == NULL) {
+ g_slist_foreach(contactlist, _contacts_free_query_number_struct_all, NULL);
+ g_slist_free(contactlist);
+ LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY);
+ return CONTACTS_ERROR_OUT_OF_MEMORY;
+ }
+
+ GSList *cursor = contactlist;
+ contact_query_number_s** pcontact_array = *contact_number_array;
+ int i = 0;
+ for(;cursor;cursor=g_slist_next(cursor)) {
+ pcontact_array[i] = (contact_query_number_s*)(cursor->data);
+ i++;
+ }
+ g_slist_free(contactlist);
+
+ return CONTACTS_ERROR_NONE;
+}
+
+int contact_query_number_array_free(contact_query_number_array contact_number_array, int length)
+{
+ CONTACTS_NULL_ARG_CHECK(contact_number_array);
+ CONTACTS_INVALID_ARG_CHECK(length < 0);
+
+ int i = 0;
+ for(;i<length; i++) {
+ _contacts_free_query_number_struct_member_only(contact_number_array[i]);
+ }
+
+ free(contact_number_array);
+ return CONTACTS_ERROR_NONE;
+}
+
+int contact_foreach_favorite_contact_from_db(contact_foreach_query_favorites_cb cb, void* user_data)
+{
+ CONTACTS_NULL_ARG_CHECK(cb);
CTSiter *iter = NULL;
int func_ret = 0;
if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_CONTACT_FAVORITE, &iter)) {
@@ -124,12 +273,44 @@ int contact_foreach_favorite_contact_from_db(contact_foreach_favorites_cb cb, vo
return CONTACTS_ERROR_NONE;
}
+int contact_foreach_frequent_contact_from_db(contact_foreach_query_name_cb callback, void *user_data)
+{
+ CONTACTS_NULL_ARG_CHECK(callback);
+
+ CTSiter *iter = NULL;
+ int func_ret = 0;
+ if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_OFTEN_USED_CONTACT, &iter)) {
+ LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED);
+ return CONTACTS_ERROR_DB_FAILED;
+ }
+
+ while(CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue* foreach_data = contacts_svc_iter_get_info(iter);
+ if(foreach_data == NULL) {
+ break;
+ }
+
+ contact_query_name_s query_data;
+ _contacts_set_query_person_struct(&query_data, foreach_data);
+
+ func_ret = callback(&query_data, user_data);
+
+ contacts_svc_value_free(foreach_data);
+ _contacts_free_query_preson_struct_member_only(&query_data);
+
+ if(func_ret == 0) {
+ break;
+ }
+ }
+ contacts_svc_iter_remove(iter);
+
+ return CONTACTS_ERROR_NONE;
+}
+
int contact_query_contact_by_name(contact_foreach_query_name_cb cb, const char* name_to_find, void* user_data)
{
- 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_with_str(CTS_LIST_CONTACTS_WITH_NAME, name_to_find, &iter)) {
@@ -162,10 +343,8 @@ int contact_query_contact_by_name(contact_foreach_query_name_cb cb, const char*
int contact_query_contact_by_group(contact_foreach_query_name_cb cb, int group_id, 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_with_int(CTS_LIST_MEMBERS_OF_GROUP_ID, group_id, &iter)) {
@@ -196,6 +375,41 @@ int contact_query_contact_by_group(contact_foreach_query_name_cb cb, int group_i
return CONTACTS_ERROR_NONE;
}
+int contact_query_contact_by_address_book(contact_foreach_query_name_cb callback, int address_book_db_id, void *user_data)
+{
+ CONTACTS_NULL_ARG_CHECK(callback);
+ 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_MEMBERS_OF_ADDRESSBOOK_ID, address_book_db_id, &iter)) {
+ LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED);
+ return CONTACTS_ERROR_DB_FAILED;
+ }
+
+ while(CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue* foreach_data = contacts_svc_iter_get_info(iter);
+ if(foreach_data == NULL) {
+ break;
+ }
+
+ contact_query_name_s query_data;
+ _contacts_set_query_person_struct(&query_data, foreach_data);
+
+ func_ret = callback(&query_data, user_data);
+
+ contacts_svc_value_free(foreach_data);
+ _contacts_free_query_preson_struct_member_only(&query_data);
+
+ if(func_ret == 0) {
+ break;
+ }
+ }
+ contacts_svc_iter_remove(iter);
+
+ return CONTACTS_ERROR_NONE;
+}
+
int contact_query_contact_by_email(contact_foreach_query_email_cb cb, const char* email_to_find, void* user_data)
{
if(cb == NULL) {
@@ -271,11 +485,7 @@ int contact_query_contact_by_number(contact_foreach_query_number_cb cb, const ch
func_ret = cb(&query_data, user_data);
contacts_svc_value_free(foreach_data);
- _contacts_safe_free(query_data.first_name);
- _contacts_safe_free(query_data.last_name);
- _contacts_safe_free(query_data.display_name);
- _contacts_safe_free(query_data.phone_number);
- _contacts_safe_free(query_data.contact_image_path);
+ _contacts_free_query_number_struct_member_only(&query_data);
if(func_ret == 0) {
break;
@@ -286,15 +496,14 @@ int contact_query_contact_by_number(contact_foreach_query_number_cb cb, const ch
return CONTACTS_ERROR_NONE;
}
-int contact_query_contact_by_version(contact_foreach_query_version_cb cb, int contacts_db_version, void* user_data)
+int contact_query_contact_by_version(contact_foreach_query_version_cb cb, int address_book_db_id, int contacts_db_version, 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);
+ CONTACTS_INVALID_ARG_CHECK(address_book_db_id < 0);
+
CTSiter *iter = NULL;
int func_ret = 0;
- if(CTS_SUCCESS != contacts_svc_get_updated_contacts(0, contacts_db_version, &iter)) {
+ if(CTS_SUCCESS != contacts_svc_get_updated_contacts(address_book_db_id, contacts_db_version, &iter)) {
LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED);
return CONTACTS_ERROR_DB_FAILED;
}
@@ -323,3 +532,38 @@ int contact_query_contact_by_version(contact_foreach_query_version_cb cb, int co
return CONTACTS_ERROR_NONE;
}
+int contact_query_contact_not_related_to_group(contact_foreach_query_name_cb callback, int address_book_db_id, void *user_data)
+{
+ CONTACTS_NULL_ARG_CHECK(callback);
+ 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_NO_GROUP_MEMBERS_OF_ADDRESSBOOK_ID, address_book_db_id, &iter)) {
+ LOGE("[%s] CONTACTS_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CONTACTS_ERROR_DB_FAILED);
+ return CONTACTS_ERROR_DB_FAILED;
+ }
+
+ while(CTS_SUCCESS == contacts_svc_iter_next(iter)) {
+ CTSvalue* foreach_data = contacts_svc_iter_get_info(iter);
+ if(foreach_data == NULL) {
+ break;
+ }
+
+ contact_query_name_s query_data;
+ _contacts_set_query_person_struct(&query_data, foreach_data);
+
+ func_ret = callback(&query_data, user_data);
+
+ contacts_svc_value_free(foreach_data);
+ _contacts_free_query_preson_struct_member_only(&query_data);
+
+ if(func_ret == 0) {
+ break;
+ }
+ }
+ contacts_svc_iter_remove(iter);
+
+ return CONTACTS_ERROR_NONE;
+}
+