From cb137a63a04ccbdc0bf4e4b8e89525126ea22185 Mon Sep 17 00:00:00 2001 From: Donghee Ye Date: Tue, 14 May 2013 18:38:21 +0900 Subject: [PATCH] Update version 0.9.84.1 - Fix : update display_name when setting default property of person - Fix contact_utils_strstr : find searched text - Fix search query with keyword which has space - Change to make display name : set last-first in korean, japanese - DO NOT auto link when two contacts have the same address book id Change-Id: If50a3e59a5090bf1557866d4fc36afe55b749fcd --- CMakeLists.txt | 2 +- client/ctsvc_client_noti.c | 12 +-- common/ctsvc_normalize.c | 4 +- common/ctsvc_vcard.c | 8 +- contacts-service2.manifest | 6 +- include/contacts.h | 8 +- include/contacts_types.h | 5 +- native/ctsvc_db_init.h | 5 +- native/ctsvc_db_plugin_contact.c | 21 +++-- native/ctsvc_db_plugin_contact_helper.c | 120 ++++++++++++++++---------- native/ctsvc_db_query.c | 146 ++++++++++++++++++++++---------- native/ctsvc_person.c | 69 +++++++++++++-- native/ctsvc_sqlite.c | 11 +-- native/ctsvc_utils.c | 75 ++++++++-------- packaging/contacts-service.spec | 10 +-- server/ctsvc_server_sim.c | 4 +- 16 files changed, 328 insertions(+), 178 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba11a6a..b26c0c4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") SET(INCLUDEDIR "\${prefix}/${DEST_INCLUDE_DIR}") SET(VERSION_MAJOR 0) -SET(VERSION "${VERSION_MAJOR}.9.82.2") +SET(VERSION "${VERSION_MAJOR}.9.84.1") EXECUTE_PROCESS(COMMAND build-util/generator.sh) diff --git a/client/ctsvc_client_noti.c b/client/ctsvc_client_noti.c index 946197f..61e3e62 100644 --- a/client/ctsvc_client_noti.c +++ b/client/ctsvc_client_noti.c @@ -47,14 +47,14 @@ static void __ctsvc_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, vo char *str = NULL; subscribe_info_s *info = user_data; - INFO("(%x) subscribe_callback(%p)", (unsigned int)pthread_self(), ipc); - if (data) { + if (data) str = (char*)pims_ipc_data_get(data, &size); - if (!str) { - CTS_ERR("pims_ipc_data_get fail()"); - return; - } + + if (!str) { + CTS_ERR("There is no changed data"); + return; } + if (info) { GSList *l; for (l = info->callbacks;l;l=l->next) { diff --git a/common/ctsvc_normalize.c b/common/ctsvc_normalize.c index 9d4c960..4d9ab2e 100644 --- a/common/ctsvc_normalize.c +++ b/common/ctsvc_normalize.c @@ -484,7 +484,7 @@ static int __ctsvc_normalize_str(const char *src, char **dest) } ret = ctsvc_check_language(result); - ctsvc_extra_normalize(result, size/sizeof(UChar)); + ctsvc_extra_normalize(result, size); u_strToUTF8(NULL, 0, &size, result, -1, &status); status = U_ZERO_ERROR; @@ -823,7 +823,7 @@ static bool __ctsvc_compare_unicode_letter(const UChar* haystack, int haystack_l ctsvc_convert_japanese_to_hiragana_unicode(temp_haystack, hiragana_haystack, 2 ); - ctsvc_convert_japanese_to_hiragana_unicode(temp_haystack, hiragana_needle, 2); + ctsvc_convert_japanese_to_hiragana_unicode(temp_needle, hiragana_needle, 2); if (hiragana_haystack[0] == hiragana_needle[0]) ret = true; diff --git a/common/ctsvc_vcard.c b/common/ctsvc_vcard.c index d68b3e1..4640c47 100644 --- a/common/ctsvc_vcard.c +++ b/common/ctsvc_vcard.c @@ -35,6 +35,8 @@ #include "ctsvc_vcard.h" #include "ctsvc_localize.h" +#define DEFAULT_ADDRESS_BOOK_ID 0 + #define SMART_STRDUP(src) (src && *src)?strdup(src):NULL #define CTSVC_VCARD_PHOTO_MAX_SIZE 1024*1024 #define CTSVC_VCARD_IMAGE_LOCATION "/opt/usr/data/contacts-svc/img/vcard" @@ -1313,7 +1315,7 @@ static inline int __ctsvc_vcard_append_contact(ctsvc_contact_s *contact, char ** RETV_IF(len < 0, len); } - if (contact->uid) { + if (contact->uid && DEFAULT_ADDRESS_BOOK_ID == contact->addressbook_id) { CTSVC_VCARD_APPEND_STR(buf, buf_size, len, content_name[CTSVC_VCARD_VALUE_UID]); CTSVC_VCARD_APPEND_CONTENT(buf, buf_size, len, contact->uid); } @@ -1387,7 +1389,7 @@ static inline int __ctsvc_vcard_append_my_profile(ctsvc_my_profile_s *my_profile RETV_IF(len < 0, len); } - if (my_profile->uid) { + if (my_profile->uid && DEFAULT_ADDRESS_BOOK_ID == my_profile->addressbook_id) { CTSVC_VCARD_APPEND_STR(buf, buf_size, len, content_name[CTSVC_VCARD_VALUE_UID]); CTSVC_VCARD_APPEND_CONTENT(buf, buf_size, len, my_profile->uid); } @@ -1638,7 +1640,7 @@ static int __ctsvc_vcard_append_person(ctsvc_person_s *person, ctsvc_list_s *lis for(cursor=list_contacts->records;cursor;cursor=cursor->next) { contact = (ctsvc_contact_s *)cursor->data; - if (contact && contact->uid) { + if (contact && contact->uid && DEFAULT_ADDRESS_BOOK_ID == contact->addressbook_id) { CTSVC_VCARD_APPEND_STR(buf, buf_size, len, content_name[CTSVC_VCARD_VALUE_UID]); CTSVC_VCARD_APPEND_CONTENT(buf, buf_size, len, contact->uid); } diff --git a/contacts-service2.manifest b/contacts-service2.manifest index d984c56..7afaf3a 100644 --- a/contacts-service2.manifest +++ b/contacts-service2.manifest @@ -3,6 +3,10 @@ @@ -10,7 +14,7 @@ - + diff --git a/include/contacts.h b/include/contacts.h index 410d544..3d0a1bf 100644 --- a/include/contacts.h +++ b/include/contacts.h @@ -558,7 +558,7 @@ * stringuidread, write * stringvibrationread, write * integerchanged_timeread only - * integerlink_moderead, write + * integerlink_moderead, write contacts_contact_link_mode_e * recordnameread, write * recordcompanyread, write * recordnoteread, write @@ -666,7 +666,7 @@ * integer id read only * integer account_id read, write once * string name read, write It can not be NULL. Duplicate names are not allowed. - * integer mode read, write + * integer mode read, write contacts_address_book_mode_e * * * @section CAPI_SOCIAL_CONTACTS_SVC_VIEW_MODULE_contacts_group _contacts_group view @@ -1027,7 +1027,7 @@ * integer person_id read, write once * string address read, write once * integer log_time read, write once - * integer log_type read, write + * integer log_type read, writecontacts_phone_log_type_e * integer extra_data1 read, write once You can set the related integer data(e.g. message_id, email_id) or duration of call. * string extra_data2 read, write once You can set the related string data. e.g.) short message, subject * @@ -1213,7 +1213,7 @@ * boolean is_favorite * boolean has_phonenumber > * boolean has_email - * integer usage_type * + * integer usage_type *contacts_usage_type_e * integer times_used * * diff --git a/include/contacts_types.h b/include/contacts_types.h index 7d7382a..f491877 100644 --- a/include/contacts_types.h +++ b/include/contacts_types.h @@ -45,6 +45,7 @@ extern "C" #define _CONTACTS_PROPERTY_CHILD_SINGLE(property_id_name) unsigned int property_id_name; #define _CONTACTS_PROPERTY_CHILD_MULTIPLE(property_id_name) unsigned int property_id_name; + #define _CONTACTS_PROPERTY_FILTER_INT(property_id_name) unsigned int property_id_name; #define _CONTACTS_PROPERTY_FILTER_STR(property_id_name) unsigned int property_id_name; #define _CONTACTS_PROPERTY_FILTER_BOOL(property_id_name) unsigned int property_id_name; @@ -196,8 +197,8 @@ typedef enum { }contacts_display_name_source_type_e; typedef enum { - CONTACTS_ADDRESS_BOOK_MODE_NONE, /**< .*/ - CONTACTS_ADDRESS_BOOK_MODE_READONLY, /**< .*/ + CONTACTS_ADDRESS_BOOK_MODE_NONE, /**< All module can read and write contacts of this address_book */ + CONTACTS_ADDRESS_BOOK_MODE_READONLY, /**< All module can only read contacts of this address_book*/ }contacts_address_book_mode_e; typedef enum{ diff --git a/native/ctsvc_db_init.h b/native/ctsvc_db_init.h index deb6e91..40ba650 100644 --- a/native/ctsvc_db_init.h +++ b/native/ctsvc_db_init.h @@ -62,10 +62,11 @@ typedef struct { int ctsvc_db_init(); int ctsvc_db_deinit(); -int ctsvc_db_get_table_name(const char *view_uri, const char **out_table); -ctsvc_db_plugin_info_s* ctsvc_db_get_plugin_info(ctsvc_record_type_e type); + int ctsvc_db_plugin_init(); int ctsvc_db_plugin_deinit(); +int ctsvc_db_get_table_name(const char *view_uri, const char **out_table); +ctsvc_db_plugin_info_s* ctsvc_db_get_plugin_info(ctsvc_record_type_e type); #endif // __TIZEN_SOCIAL_CTSVC_DB_INIT_H__ diff --git a/native/ctsvc_db_plugin_contact.c b/native/ctsvc_db_plugin_contact.c index 71ee6f3..d395feb 100644 --- a/native/ctsvc_db_plugin_contact.c +++ b/native/ctsvc_db_plugin_contact.c @@ -145,7 +145,8 @@ static int __ctsvc_db_get_data(int id, ctsvc_contact_s *contact) "data3, data4, data5, data6, data7, data8, data9, data10, data11, data12 " "FROM "CTS_TABLE_DATA", "CTSVC_DB_VIEW_CONTACT" " "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id " - "WHERE data.contact_id = %d AND is_my_profile = 0", id); + "WHERE data.contact_id = %d AND is_my_profile = 0 " + "ORDER BY is_default DESC", id); stmt = cts_query_prepare(query); RETVM_IF(NULL == stmt, CONTACTS_ERROR_DB, "DB error : cts_query_prepare() Failed"); @@ -1768,7 +1769,7 @@ static inline int __ctsvc_contact_insert_grouprel(int contact_id, contacts_list_ return CONTACTS_ERROR_NONE; } -inline static int __ctsvc_find_person_to_link_with_number(const char *normalized_number, int *person_id) +inline static int __ctsvc_find_person_to_link_with_number(const char *normalized_number, int addressbook_id, int *person_id) { int ret; @@ -1782,8 +1783,9 @@ inline static int __ctsvc_find_person_to_link_with_number(const char *normalized snprintf(query, sizeof(query), "SELECT C.person_id FROM "CTS_TABLE_CONTACTS" C, "CTS_TABLE_DATA" D " "ON C.contact_id=D.contact_id AND D.datatype=%d AND C.deleted = 0 " + "AND C.addressbook_id <> %d " "WHERE D.data4='%s' AND D.is_my_profile = 0", - CTSVC_DATA_NUMBER, normal_num); + CTSVC_DATA_NUMBER, addressbook_id, normal_num); ret = ctsvc_query_get_first_int_result(query, person_id); CTS_DBG("%s", query); CTS_DBG("result ret(%d) person_id(%d)", ret, *person_id); @@ -1793,7 +1795,7 @@ inline static int __ctsvc_find_person_to_link_with_number(const char *normalized return CONTACTS_ERROR_INVALID_PARAMETER; } -inline static int __ctsvc_find_person_to_link_with_email(const char *email_addr, int *person_id) +inline static int __ctsvc_find_person_to_link_with_email(const char *email_addr, int addressbook_id, int *person_id) { int ret; char query[CTS_SQL_MIN_LEN] = {0}; @@ -1801,8 +1803,9 @@ inline static int __ctsvc_find_person_to_link_with_email(const char *email_addr, snprintf(query, sizeof(query), "SELECT C.person_id FROM "CTS_TABLE_CONTACTS" C, "CTS_TABLE_DATA" D " "ON C.contact_id=D.contact_id AND D.datatype=%d AND C.deleted = 0 " + "AND C.addressbook_id <> %d " "WHERE D.data3='%s' AND D.is_my_profile = 0", - CTSVC_DATA_EMAIL, email_addr); + CTSVC_DATA_EMAIL, addressbook_id, email_addr); ret = ctsvc_query_get_first_int_result(query, person_id); CTS_DBG("%s", query); CTS_DBG("result ret(%d) person_id(%d)", ret, *person_id); @@ -1811,7 +1814,7 @@ inline static int __ctsvc_find_person_to_link_with_email(const char *email_addr, } -inline static int __ctsvc_find_person_to_link(contacts_record_h record, int *person_id) +inline static int __ctsvc_find_person_to_link(contacts_record_h record, int addressbook_id, int *person_id) { int ret; ctsvc_contact_s *contact = (ctsvc_contact_s*)record; @@ -1822,7 +1825,7 @@ inline static int __ctsvc_find_person_to_link(contacts_record_h record, int *per for(cursor = contact->numbers->records;cursor;cursor=cursor->next) { number_data = (ctsvc_number_s *)cursor->data; if (number_data && number_data->number && number_data->number[0]){ - ret = __ctsvc_find_person_to_link_with_number(number_data->number, person_id); + ret = __ctsvc_find_person_to_link_with_number(number_data->number, addressbook_id, person_id); if (ret == CONTACTS_ERROR_NONE && *person_id > 0) return ret; @@ -1832,7 +1835,7 @@ inline static int __ctsvc_find_person_to_link(contacts_record_h record, int *per for(cursor = contact->emails->records;cursor;cursor=cursor->next) { email_data = (ctsvc_email_s *)cursor->data; if (email_data && email_data->email_addr && email_data->email_addr[0]){ - ret = __ctsvc_find_person_to_link_with_email(email_data->email_addr, person_id); + ret = __ctsvc_find_person_to_link_with_email(email_data->email_addr, addressbook_id, person_id); if (ret == CONTACTS_ERROR_NONE && *person_id > 0) return ret; @@ -1922,7 +1925,7 @@ static int __ctsvc_db_contact_insert_record( contacts_record_h record, int *id) version = ctsvc_get_next_ver(); if (auto_link_enabled) { - ret = __ctsvc_find_person_to_link((contacts_record_h)contact, &person_id); + ret = __ctsvc_find_person_to_link((contacts_record_h)contact, contact->addressbook_id, &person_id); CTS_DBG("__ctsvc_find_person_to_link return %d , person_id(%d)", ret, person_id); if (ret == CONTACTS_ERROR_NONE && person_id > 0) { contact->person_id = person_id; diff --git a/native/ctsvc_db_plugin_contact_helper.c b/native/ctsvc_db_plugin_contact_helper.c index ce8e6e7..2327674 100644 --- a/native/ctsvc_db_plugin_contact_helper.c +++ b/native/ctsvc_db_plugin_contact_helper.c @@ -292,82 +292,110 @@ void ctsvc_make_contact_display_name(ctsvc_contact_s *contact) } if ( name && ( name->first || name->last || name->prefix || name->addition || name->suffix) ) { - // make display name + int reverse_lang_type = -1; + + // make reverse display name display_len = SAFE_STRLEN(name->prefix) + SAFE_STRLEN(name->first) + SAFE_STRLEN(name->addition) + SAFE_STRLEN(name->last) - + SAFE_STRLEN(name->suffix) + 5; + + SAFE_STRLEN(name->suffix) + 6; display = calloc(1, display_len); len=0; if(name->prefix) len += snprintf(display + len, display_len - len, "%s", name->prefix); - if(name->first) { - if (*display) - len += snprintf(display + len, display_len - len, " "); - len += snprintf(display + len, display_len - len, "%s", name->first); - } - - if(name->addition) { - if (*display) - len += snprintf(display + len, display_len - len, " "); - len += snprintf(display + len, display_len - len, "%s", name->addition); - } - - if(name->last) { - if (*display) - len += snprintf(display + len, display_len - len, " "); - len += snprintf(display + len, display_len - len, "%s", name->last); - } - - if(name->suffix) { - if (*display) - len += snprintf(display + len, display_len - len, " "); - len += snprintf(display + len, display_len - len, "%s", name->suffix); - } - - contact->display_name = display; - - display_len += 1; // "," - // make reverse_display_name - display = calloc(1, display_len); - len = 0; - - if(name->prefix) - len += snprintf(display + len, display_len - len, "%s", name->prefix); - if(name->last) { if (*display) len += snprintf(display + len, display_len - len, " "); len += snprintf(display + len, display_len - len, "%s", name->last); - if(name->first || name->addition) - len += snprintf(display + len, display_len - len, ","); + if (reverse_lang_type < 0 ) + reverse_lang_type = ctsvc_check_language_type(display); + + if (reverse_lang_type != CTSVC_LANG_KOREAN && + reverse_lang_type != CTSVC_LANG_JAPANESE) { + if(name->first || name->addition) + len += snprintf(display + len, display_len - len, ","); + } } if(name->first) { - if (*display) - len += snprintf(display + len, display_len - len, " "); + if (*display) { + if (reverse_lang_type < 0 ) + reverse_lang_type = ctsvc_check_language_type(display); + + if (reverse_lang_type != CTSVC_LANG_KOREAN) + len += snprintf(display + len, display_len - len, " "); + } len += snprintf(display + len, display_len - len, "%s", name->first); } if(name->addition) { - if (*display) - len += snprintf(display + len, display_len - len, " "); + if (*display) { + if (reverse_lang_type < 0 ) + reverse_lang_type = ctsvc_check_language_type(display); + + if (reverse_lang_type != CTSVC_LANG_KOREAN) + len += snprintf(display + len, display_len - len, " "); + } len += snprintf(display + len, display_len - len, "%s", name->addition); } if(name->suffix) { - if (*display) + if (*display) { + if (reverse_lang_type < 0 ) + reverse_lang_type = ctsvc_check_language_type(display); + + if (reverse_lang_type != CTSVC_LANG_KOREAN) len += snprintf(display + len, display_len - len, " "); + } len += snprintf(display + len, display_len - len, "%s", name->suffix); } + contact->reverse_display_name = display; + + // make display name + if (reverse_lang_type == CTSVC_LANG_KOREAN || + reverse_lang_type == CTSVC_LANG_JAPANESE) + contact->display_name = strdup(display); + else { + display_len -= 1; // "," + // make reverse_display_name + display = calloc(1, display_len); + len = 0; + + if(name->prefix) + len += snprintf(display + len, display_len - len, "%s", name->prefix); + + if(name->first) { + if (*display) + len += snprintf(display + len, display_len - len, " "); + len += snprintf(display + len, display_len - len, "%s", name->first); + } + + if(name->addition) { + if (*display) + len += snprintf(display + len, display_len - len, " "); + len += snprintf(display + len, display_len - len, "%s", name->addition); + } + + if(name->last) { + if (*display) + len += snprintf(display + len, display_len - len, " "); + len += snprintf(display + len, display_len - len, "%s", name->last); + } + + if(name->suffix) { + if (*display) + len += snprintf(display + len, display_len - len, " "); + len += snprintf(display + len, display_len - len, "%s", name->suffix); + } + contact->display_name = display; + } ctsvc_record_set_property_flag((ctsvc_record_s *)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY); - contact->reverse_display_name = display; contact->sort_name = SAFE_STRDUP(contact->display_name); contact->reverse_sort_name = SAFE_STRDUP(contact->reverse_display_name); contact->display_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NAME; @@ -435,7 +463,7 @@ void ctsvc_make_contact_display_name(ctsvc_contact_s *contact) ret = CTSVC_SORT_OTHERS; if (contact->display_name) ret = ctsvc_get_name_sort_type(contact->display_name); - WARN_IF( ret < 0, "ctsvc_check_language_type Failed(%d)", ret); + WARN_IF( ret < 0, "ctsvc_get_name_sort_type Failed(%d)", ret); switch (ret) { @@ -498,7 +526,7 @@ void ctsvc_make_contact_display_name(ctsvc_contact_s *contact) ret = CTSVC_SORT_OTHERS; if (contact->reverse_display_name) ret = ctsvc_get_name_sort_type(contact->reverse_display_name); - WARN_IF( ret < 0, "ctsvc_check_language_type Failed(%d)", ret); + WARN_IF( ret < 0, "ctsvc_get_name_sort_type Failed(%d)", ret); switch (ret) { case CTSVC_SORT_CJK: diff --git a/native/ctsvc_db_query.c b/native/ctsvc_db_query.c index dd8f68f..282d4fb 100755 --- a/native/ctsvc_db_query.c +++ b/native/ctsvc_db_query.c @@ -540,7 +540,6 @@ static int __ctsvc_db_create_projection(const property_info_s *properties, int i else if (properties[i].property_id == CTSVC_PROPERTY_PERSON_DISPLAY_NAME_INDEX) { snprintf(temp, sizeof(temp), "_NORMALIZE_INDEX_(%s)", ctsvc_get_sort_name_column()); field_name = temp; - CTS_DBG("field_name : %s", field_name); } else field_name = ctsvc_get_display_column(); @@ -842,40 +841,57 @@ static inline bool __ctsvc_db_view_can_keyword_search(const char *view_uri) return false; } +static char* __ctsvc_db_make_search_keyword(const char*keyword) +{ + int size = strlen(keyword); + + if (keyword == NULL) + return NULL; + + if (strstr(keyword, " ") != NULL) { + int i = 0; + int j = 0; + char search_keyword[size * 2+1]; + for(i=0;i0 && keyword[i] == ' ') { + if (search_keyword[j-1] != ' ' ) + search_keyword[j++] = '*'; + } + search_keyword[j++] = keyword[i]; + } + if (j > 0 && search_keyword[j-1] != ' ') + search_keyword[j++] = '*'; + search_keyword[j] = '\0'; + return strdup(search_keyword); + } + else { + char search_keyword[size+2]; + snprintf(search_keyword, sizeof(search_keyword), "%s*", keyword); + return strdup(search_keyword); + } +} + static int __ctsvc_db_append_search_query(const char *keyword, char *query, int size) { - bool emailaddress = false; bool phonenumber = false; int ret; int len = 0, i; - if (strstr(keyword, "@") != NULL) { - emailaddress = true; - } - else { - len = strlen(keyword); - phonenumber = true; - for(i=0; i '9') { - phonenumber = false; - break; - } + len = strlen(keyword); + phonenumber = true; + for(i=0; i '9') { + phonenumber = false; + break; } } - if (emailaddress) { - ret = snprintf(query, size, - "(SELECT contact_id FROM %s WHERE %s MATCH 'data:%s*') ", - CTS_TABLE_SEARCH_INDEX, CTS_TABLE_SEARCH_INDEX, - keyword ); - } - else if (phonenumber) { + if (phonenumber) { char normalized_number[CTSVC_NUMBER_MAX_LEN]; - ctsvc_normalize_number(keyword, normalized_number, CTSVC_NUMBER_MAX_LEN, CTSVC_NUMBER_MAX_LEN -1); ret =snprintf(query, size, - "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s* OR number:%s* OR data:%s*' " + "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s OR number:%s OR data:%s' " "UNION " "SELECT contact_id FROM %s WHERE number LIKE '%%%s%%') ", CTS_TABLE_SEARCH_INDEX, CTS_TABLE_SEARCH_INDEX, @@ -883,47 +899,70 @@ static int __ctsvc_db_append_search_query(const char *keyword, char *query, int } else { char *normalized_name = NULL; + char *search_keyword = NULL; + char *saarch_normal_name = NULL; ret = ctsvc_normalize_str(keyword, &normalized_name); + search_keyword = __ctsvc_db_make_search_keyword(keyword); + saarch_normal_name = __ctsvc_db_make_search_keyword(normalized_name); + if (CTSVC_LANG_KOREAN == ret) { char *chosung = calloc(1, strlen(keyword) * 5); char *korean_pattern = calloc(1, strlen(keyword) * 5); + char *search_chosung = NULL; ctsvc_get_chosung(keyword, chosung, strlen(keyword) * 5 ); ctsvc_get_korean_search_pattern(keyword, korean_pattern, strlen(keyword) * 5 ); + + search_chosung = __ctsvc_db_make_search_keyword(chosung); ret = snprintf(query, size, - "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s* OR number:%s* OR data:%s*' " - "INTERSECT " - "SELECT contact_id FROM %s WHERE name GLOB '*%s*') ", + "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s OR number:%s OR data:%s' " + "INTERSECT SELECT contact_id FROM %s WHERE name GLOB '*%s*' ", CTS_TABLE_SEARCH_INDEX, CTS_TABLE_SEARCH_INDEX, - chosung, keyword, keyword, CTS_TABLE_NAME_LOOKUP, korean_pattern ); + search_chosung, search_keyword, search_keyword, CTS_TABLE_NAME_LOOKUP, korean_pattern); free(chosung); free(korean_pattern); + free(search_chosung); } - else if (CTSVC_LANG_JAPANESE == ret){ + else if (CTSVC_LANG_JAPANESE == ret) { char *hiragana = NULL; + char *search_hiragana = NULL; ctsvc_convert_japanese_to_hiragana(keyword, &hiragana); + search_hiragana = __ctsvc_db_make_search_keyword(hiragana); ret = snprintf(query, size, - "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s* OR number:%s* OR data:%s*') ", + "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s OR number:%s OR data:%s' ", CTS_TABLE_SEARCH_INDEX, CTS_TABLE_SEARCH_INDEX, - hiragana, hiragana, hiragana); + search_hiragana, search_hiragana, search_hiragana); free(hiragana); + free(search_hiragana); } else if (CONTACTS_ERROR_NONE <= ret) { ret = snprintf(query, size, - "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s* OR number:%s* OR data:%s*') ", + "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s OR number:%s OR data:%s' ", CTS_TABLE_SEARCH_INDEX, CTS_TABLE_SEARCH_INDEX, - normalized_name, keyword, keyword); + saarch_normal_name, search_keyword, search_keyword); } else { ret = snprintf(query, size, - "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s* OR number:%s* OR data:%s*') ", + "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s OR number:%s OR data:%s' ", CTS_TABLE_SEARCH_INDEX, CTS_TABLE_SEARCH_INDEX, - keyword, keyword, keyword); + search_keyword, search_keyword, search_keyword); + } + + if (strstr(keyword, "@") != NULL) { + ret += snprintf(query+ret, size-ret, + " UNION " + "SELECT contact_id FROM %s WHERE %s MATCH 'data:%s' ) ", + CTS_TABLE_SEARCH_INDEX, CTS_TABLE_SEARCH_INDEX, search_keyword); } + else + ret += snprintf(query+ret, size-ret,") "); + free(normalized_name); + free(search_keyword); + free(saarch_normal_name); } return ret; @@ -955,7 +994,7 @@ static int __ctsvc_db_search_records_exec(const char *view_uri, const property_i } else { // CTSVC_VIEW_URI_PERSON len = snprintf(query, sizeof(query), "SELECT %s FROM %s, " - "(SELECT person_id person_id_in_contact " + "(SELECT person_id person_id_in_contact, addressbook_id " "FROM "CTS_TABLE_CONTACTS " " "WHERE deleted = 0 AND contact_id IN ", projection, table); @@ -1261,17 +1300,30 @@ static int __ctsvc_db_search_records_with_query( contacts_query_h query, const c RETVM_IF(false == can_keyword_search, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : can not keyword search"); - if (s_query->filter) { - ret = __ctsvc_db_create_composite_condition(s_query->filter, &condition, &bind_text); - RETVM_IF (CONTACTS_ERROR_NONE != ret, ret, "__ctsvc_db_create_composite_condition is failed(%s)", ret); - } - ret = __ctsvc_db_create_projection(s_query->properties, s_query->property_count, s_query->projection, s_query->projection_count, &projection); RETVM_IF (CONTACTS_ERROR_NONE != ret, ret, "__ctsvc_db_create_projection is failed(%s)", ret); + if (s_query->filter) { + ret = __ctsvc_db_create_composite_condition(s_query->filter, &condition, &bind_text); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("__ctsvc_db_create_composite_condition is failed(%s)", ret); + free(projection); + return ret; + } + } + ret = __ctsvc_db_search_records_with_query_exec(s_query, projection, condition, bind_text, keyword, offset, limit, out_list); - RETVM_IF (CONTACTS_ERROR_NONE != ret, ret, "__ctsvc_db_search_records_with_query_exec is failed(%s)", ret); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR("__ctsvc_db_search_records_with_query_exec is failed(%s)", ret); + for (cursor=bind_text;cursor;cursor=cursor->next) + free(cursor->data); + g_slist_free(bind_text); + + free(condition); + free(projection); + return ret; + } for (cursor=bind_text;cursor;cursor=cursor->next) free(cursor->data); @@ -1565,20 +1617,20 @@ static int __ctsvc_db_get_count_with_query( contacts_query_h query, int *out_cou int ret; char *condition = NULL; char *projection; - ctsvc_query_s *query_s; + ctsvc_query_s *s_query; GSList *bind_text = NULL; GSList *cursor; RETV_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER); - query_s = (ctsvc_query_s *)query; + s_query = (ctsvc_query_s *)query; - if (query_s->filter) { - ret = __ctsvc_db_create_composite_condition(query_s->filter, &condition, &bind_text); + if (s_query->filter) { + ret = __ctsvc_db_create_composite_condition(s_query->filter, &condition, &bind_text); RETVM_IF (CONTACTS_ERROR_NONE != ret, ret, "__ctsvc_db_create_composite_condition is failed(%s)", ret); } - ret = __ctsvc_db_create_projection(query_s->properties, query_s->property_count, - query_s->projection, query_s->projection_count, &projection); + ret = __ctsvc_db_create_projection(s_query->properties, s_query->property_count, + s_query->projection, s_query->projection_count, &projection); if (CONTACTS_ERROR_NONE != ret) { CTS_ERR("__ctsvc_db_create_projection is failed(%d)", ret); for (cursor=bind_text;cursor;cursor=cursor->next) @@ -1587,7 +1639,7 @@ static int __ctsvc_db_get_count_with_query( contacts_query_h query, int *out_cou return ret; } - ret = __ctsvc_db_get_count_with_query_exec(query_s, projection, condition, bind_text, out_count); + ret = __ctsvc_db_get_count_with_query_exec(s_query, projection, condition, bind_text, out_count); for (cursor=bind_text;cursor;cursor=cursor->next) free(cursor->data); g_slist_free(bind_text); diff --git a/native/ctsvc_person.c b/native/ctsvc_person.c index 6d46089..079efd8 100644 --- a/native/ctsvc_person.c +++ b/native/ctsvc_person.c @@ -385,17 +385,35 @@ static inline int __ctsvc_put_person_default_image(int person_id, int id) static inline int __ctsvc_put_person_default_data(int person_id, int id, int datatype) { int ret; - int is_default; + int is_default = 0; + int contact_id = 0; + int name_contact_id = 0; char query[CTS_SQL_MAX_LEN] = {0}; + cts_stmt stmt = NULL; + contacts_display_name_source_type_e source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_INVALID; snprintf(query, sizeof(query), - "SELECT D.is_default FROM %s D, %s C " + "SELECT D.is_default, D.contact_id FROM %s D, %s C " "ON (D.contact_id=C.contact_id AND C.deleted = 0) " "WHERE D.datatype=%d AND C.person_id=%d AND D.id=%d", CTS_TABLE_DATA, CTS_TABLE_CONTACTS, datatype, person_id, id); - ret = ctsvc_query_get_first_int_result(query, &is_default); - RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "ctsvc_query_get_first_int_result() Failed(%d)", ret); + stmt = cts_query_prepare(query); + if (NULL == stmt) { + CTS_ERR("cts_query_prepare Fail(stmt NULL)"); + return CONTACTS_ERROR_DB; + } + ret = cts_stmt_step(stmt); + if (1 != ret) { + CTS_ERR("cts_stmt_step Fail(%d)", ret); + cts_stmt_finalize(stmt); + return ret; + } + + is_default = ctsvc_stmt_get_int(stmt, 0); + contact_id = ctsvc_stmt_get_int(stmt, 1); + + cts_stmt_finalize(stmt); ret = ctsvc_begin_trans(); RETVM_IF(CONTACTS_ERROR_NONE > ret, ret, "DB error : ctsvc_begin_trans() Failed(%d)", ret); @@ -434,12 +452,53 @@ static inline int __ctsvc_put_person_default_data(int person_id, int id, int dat "UPDATE "CTS_TABLE_DATA" SET is_primary_default=1, is_default=1 WHERE id=%d ", id); ret = ctsvc_query_exec(query); - if( CONTACTS_ERROR_NONE != ret ) { + if (CONTACTS_ERROR_NONE != ret) { CTS_ERR( "ctsvc_query_exec() Failed(%d)", ret); ctsvc_end_trans(false); return ret; } + if (datatype == CTSVC_DATA_NUMBER) + source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NUMBER; + else if (datatype == CTSVC_DATA_EMAIL) + source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_EMAIL; + + if (CONTACTS_DISPLAY_NAME_SOURCE_TYPE_INVALID != source_type) + ctsvc_contact_update_display_name(contact_id, source_type); + + snprintf(query, sizeof(query), + "SELECT name_contact_id FROM "CTS_TABLE_PERSONS" WHERE person_id = %d", person_id); + ret = ctsvc_query_get_first_int_result(query, &name_contact_id); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR( "ctsvc_query_get_first_int_result() Failed(%d)", ret); + ctsvc_end_trans(false); + return ret; + } + + if (name_contact_id != contact_id) { + int org_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_INVALID; + snprintf(query, sizeof(query), + "SELECT display_name_source FROM "CTS_TABLE_CONTACTS" WHERE contact_id = %d", name_contact_id); + ret = ctsvc_query_get_first_int_result(query, &org_source_type); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR( "ctsvc_query_get_first_int_result() Failed(%d)", ret); + ctsvc_end_trans(false); + return ret; + } + + if (org_source_type <= source_type) { + snprintf(query, sizeof(query), + "UPDATE %s SET name_contact_id=%d WHERE person_id=%d", + CTS_TABLE_PERSONS, contact_id, person_id); + ret = ctsvc_query_exec(query); + if (CONTACTS_ERROR_NONE != ret) { + CTS_ERR( "ctsvc_query_exec() Failed(%d)", ret); + ctsvc_end_trans(false); + return ret; + } + } + } + ret = ctsvc_end_trans(true); if (ret < CONTACTS_ERROR_NONE) { diff --git a/native/ctsvc_sqlite.c b/native/ctsvc_sqlite.c index 202bbf0..e511911 100755 --- a/native/ctsvc_sqlite.c +++ b/native/ctsvc_sqlite.c @@ -145,16 +145,13 @@ int ctsvc_query_get_first_int_result(const char *query, int *result) { ret = sqlite3_step(stmt); if (SQLITE_ROW != ret) { sqlite3_finalize(stmt); + CTS_DBG("query : %s", query); if (SQLITE_DONE == ret) { - INFO("sqlite3_step() return with SQLITE_DONE (it means NO_DATA) (%s, %d, %s)", - query, ret, sqlite3_errmsg(ctsvc_db)); - + CTS_INFO("sqlite3_step() return with SQLITE_DONE (it means NO_DATA) (%d, %s)", + ret, sqlite3_errmsg(ctsvc_db)); return CONTACTS_ERROR_NO_DATA /*CONTACTS_ERR_DB_RECORD_NOT_FOUND*/; } - - CTS_ERR("sqlite3_step() Failed(%s, %d, %s)", - query, ret, sqlite3_errmsg(ctsvc_db)); - + CTS_ERR("sqlite3_step() Failed(%d, %s)", ret, sqlite3_errmsg(ctsvc_db)); return CONTACTS_ERROR_DB; } diff --git a/native/ctsvc_utils.c b/native/ctsvc_utils.c index bdaab49..19d5e7f 100644 --- a/native/ctsvc_utils.c +++ b/native/ctsvc_utils.c @@ -252,27 +252,57 @@ static inline bool ctsvc_check_available_image_space(void){ return false; } -static int __ctsvc_get_exif_info(const char *path) +static image_util_rotation_e __ctsvc_get_rotation_info(const char *path) { ExifData *ed = NULL; ExifEntry *entry; + image_util_rotation_e rotation = IMAGE_UTIL_ROTATION_NONE; + int orientation = 0; ed = exif_data_new_from_file(path); if (ed == NULL) { CTS_ERR("exif_data_new_from_file : ExifData is NULL"); - return 0; + return IMAGE_UTIL_ROTATION_NONE; } entry = exif_data_get_entry(ed, EXIF_TAG_ORIENTATION); if (entry) { ExifByteOrder mByteOrder = exif_data_get_byte_order(ed); - int orientation = (int)exif_get_short(entry->data, mByteOrder); - if (orientation >= 0 && orientation <= 8) - return orientation; - else - return 0; + orientation = (int)exif_get_short(entry->data, mByteOrder); + if (orientation < 0 && orientation > 8) + orientation = 0; } - return 0; + + if (ed) + exif_data_unref(ed); + + switch(orientation) { + case 1: // Top-left + rotation = IMAGE_UTIL_ROTATION_NONE; + break; + case 2: // Top-right + rotation = IMAGE_UTIL_ROTATION_FLIP_HORZ; + break; + case 3: // Bottom-right + rotation = IMAGE_UTIL_ROTATION_180; + break; + case 4: // Bottom-left + rotation = IMAGE_UTIL_ROTATION_FLIP_VERT; + break; + case 6: // Right-top + rotation = IMAGE_UTIL_ROTATION_90; + break; + case 8: // Left-bottom + rotation = IMAGE_UTIL_ROTATION_270; + break; + case 5: // Left-top + case 7: // Right-bottom + case 0: + default: + break; + }; + + return rotation; } static int image_size = 480; @@ -293,7 +323,6 @@ static bool __ctsvc_image_util_supported_jpeg_colorspace_cb(image_util_colorspac unsigned char * img_target = 0; unsigned char * img_source = 0; int dest_fd; - int orientation = 0; image_util_rotation_e rotation; // temporary code @@ -302,33 +331,7 @@ static bool __ctsvc_image_util_supported_jpeg_colorspace_cb(image_util_colorspac return true; } - rotation = IMAGE_UTIL_ROTATION_NONE; - orientation = __ctsvc_get_exif_info(info->src); - switch(orientation) { - case 1: - rotation = IMAGE_UTIL_ROTATION_NONE; - break; - case 2: - rotation = IMAGE_UTIL_ROTATION_FLIP_HORZ; - break; - case 3: - rotation = IMAGE_UTIL_ROTATION_180; - break; - case 4: - rotation = IMAGE_UTIL_ROTATION_FLIP_VERT; - break; - case 6: - rotation = IMAGE_UTIL_ROTATION_90; - break; - case 8: - rotation = IMAGE_UTIL_ROTATION_270; - break; - case 5: - case 7: - case 0: - default: - break; - }; + rotation = __ctsvc_get_rotation_info(info->src); // load jpeg sample file CTS_DBG("colorspace %d src : %s, dest : %s", colorspace, info->src, info->dest); diff --git a/packaging/contacts-service.spec b/packaging/contacts-service.spec index 2900580..06bc589 100644 --- a/packaging/contacts-service.spec +++ b/packaging/contacts-service.spec @@ -1,6 +1,6 @@ Name: contacts-service Summary: Contacts Service -Version: 0.9.82.2 +Version: 0.9.84.1 Release: 1 Group: TO_BE/FILLED_IN License: Apache-2.0 @@ -85,10 +85,10 @@ chmod 775 /opt/usr/data/contacts-svc chmod 770 -R /opt/usr/data/contacts-svc/img/ chmod 660 /opt/usr/data/contacts-svc/.CONTACTS_SVC_* -vconftool set -t int file/private/contacts-service/default_lang 0 -g 6005 -vconftool set -t int db/contacts-svc/name_sorting_order 0 -g 6005 -vconftool set -t int db/contacts-svc/name_display_order 0 -g 6005 -vconftool set -t int db/contacts-svc/phonenumber_min_match_digit 8 -g 6005 +vconftool set -t int file/private/contacts-service/default_lang 0 -g 6005 -s contacts-service::vconf-private +vconftool set -t int db/contacts-svc/name_sorting_order 0 -g 6005 -s contacts-service::vconf +vconftool set -t int db/contacts-svc/name_display_order 0 -g 6005 -s contacts-service::vconf +vconftool set -t int db/contacts-svc/phonenumber_min_match_digit 8 -g 6005 -s contacts-service::vconf %postun -p /sbin/ldconfig diff --git a/server/ctsvc_server_sim.c b/server/ctsvc_server_sim.c index 2296e8b..6d1f0de 100755 --- a/server/ctsvc_server_sim.c +++ b/server/ctsvc_server_sim.c @@ -34,7 +34,7 @@ #include "ctsvc_server_sim.h" #include "ctsvc_utils.h" -#define PHONE_ADDRESSBOOK_ID 0 +#define DEFAULT_ADDRESS_BOOK_ID 0 #define CTSVC_TAPI_SIM_PB_MAX 0xFFFF #define CTSVC_SIM_DATA_MAX_LENGTH (255+1) @@ -431,7 +431,7 @@ static void __ctsvc_server_sim_import_read_cb(TapiHandle *handle, int result, vo case TAPI_SIM_PB_ADN: case TAPI_SIM_PB_3GSIM: record = __ctsvc_server_sim_create_contact_record(sim_info); - ret = __ctsvc_server_insert_contact_to_db(record, &contact_id,PHONE_ADDRESSBOOK_ID); + ret = __ctsvc_server_insert_contact_to_db(record, &contact_id,DEFAULT_ADDRESS_BOOK_ID); ctsvc_server_sim_destroy_contact_record(record); if(ret < CONTACTS_ERROR_NONE || contact_id <= 0) { CTS_ERR("__ctsvc_server_insert_or_update_contact_to_db is fail(%d)",ret); -- 2.7.4