Merge with master
authorDonghee Ye <donghee.ye@samsung.com>
Mon, 18 Mar 2013 10:45:52 +0000 (19:45 +0900)
committerDonghee Ye <donghee.ye@samsung.com>
Mon, 18 Mar 2013 10:45:52 +0000 (19:45 +0900)
Change-Id: I4c88b2ed860bc97729ccf79952e16e2960db3555

43 files changed:
CMakeLists.txt
client/ctsvc_client_service.c
client/ctsvc_client_sim.c [deleted file]
common/ctsvc_localize.c
common/ctsvc_normalize.c
common/ctsvc_record.c
common/ctsvc_record_contact.c
common/ctsvc_record_my_profile.c
common/ctsvc_struct.h
common/ctsvc_vcard.c
common/ctsvc_view.c
common/ctsvc_view.h
common/ipc/ctsvc_ipc_contact.c
common/ipc/ctsvc_ipc_my_profile.c
common/ipc/ctsvc_ipc_simple_contact.c
contacts-service2.manifest
native/ctsvc_db_init.c
native/ctsvc_db_plugin_contact.c
native/ctsvc_db_plugin_contact_helper.c
native/ctsvc_db_plugin_contact_helper.h
native/ctsvc_db_plugin_image_helper.c
native/ctsvc_db_plugin_my_profile.c
native/ctsvc_db_plugin_name_helper.c
native/ctsvc_db_plugin_person.c
native/ctsvc_db_plugin_person_helper.c
native/ctsvc_db_plugin_person_helper.h
native/ctsvc_db_plugin_simple_contact.c
native/ctsvc_db_query.c
native/ctsvc_person.c
native/ctsvc_restriction.c [deleted file]
native/ctsvc_restriction.h [deleted file]
native/ctsvc_schema.h
native/ctsvc_service.c
native/ctsvc_sqlite.c
native/ctsvc_utils.c
native/ctsvc_utils.h
packaging/contacts-service.spec
res/.CONTACTS_SVC_RESTRICTION_CHECK [deleted file]
schema.sql
server/CMakeLists.txt
server/ctsvc_server_bg.c
server/ctsvc_server_bg.h
server/ctsvc_server_sim.c

index d29377c..bd3ea75 100755 (executable)
@@ -14,7 +14,7 @@ SET(EXEC_PREFIX "\${prefix}")
 SET(LIBDIR "\${prefix}/lib")
 SET(INCLUDEDIR "\${prefix}/${DEST_INCLUDE_DIR}")
 SET(VERSION_MAJOR 0)
-SET(VERSION "${VERSION_MAJOR}.9.45.3")
+SET(VERSION "${VERSION_MAJOR}.9.52.1")
 
 EXECUTE_PROCESS(COMMAND build-util/generator.sh)
 
index 39b9048..681f8ef 100644 (file)
@@ -50,13 +50,16 @@ API int contacts_connect_with_flags(unsigned int flags)
        if (flags & CONTACTS_CONNECT_FLAG_RETRY) {
                int i;
                int waiting_time = 500;
-               for (i=0;i<7;i++) {
+               for (i=0;i<9;i++) {
                        usleep(waiting_time * 1000);
                        DBG("retry cnt=%d, ret=%x, %d",(i+1), ret, waiting_time);
                        ret = contacts_connect2();
                        if (ret == CONTACTS_ERROR_NONE)
                                break;
-                       waiting_time *= 2;
+                       if (6 < i)
+                               waiting_time += 30000;
+                       else
+                               waiting_time *= 2;
                }
        }
 
diff --git a/client/ctsvc_client_sim.c b/client/ctsvc_client_sim.c
deleted file mode 100644 (file)
index a309537..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Contacts Service
- *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "contacts.h"
-#include "ctsvc_internal.h"
-#include "ctsvc_ipc_define.h"
-#include "ctsvc_ipc_marshal.h"
-#include "ctsvc_client_ipc.h"
-#include <pims-ipc-data.h>
-
-API int contacts_sim_insert(contacts_record_h record, int *contact_id)
-{
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-
-
-       // make indata
-       indata = pims_ipc_data_create(0);
-       if (indata == NULL)
-       {
-               CTS_ERR("ipc data created fail!");
-               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
-               return ret;
-       }
-
-       ret = ctsvc_ipc_marshal_record( record, indata );
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       // ipc call
-       if (ctsvc_ipc_call(CTSVC_IPC_SIM_MODULE, CTSVC_IPC_SERVER_SIM_INSERT_CONTACT, indata, &outdata) != 0)
-       {
-               pims_ipc_data_destroy(indata);
-               CTS_ERR("ctsvc_ipc_call failed");
-               return CONTACTS_ERROR_IPC;
-       }
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               pims_ipc_data_destroy(outdata);
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       return ret;
-}
-
-API int contacts_sim_update(contacts_record_h record)
-{
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-
-
-       // make indata
-       indata = pims_ipc_data_create(0);
-       if (indata == NULL)
-       {
-               CTS_ERR("ipc data created fail!");
-               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
-               return ret;
-       }
-
-       ret = ctsvc_ipc_marshal_record( record, indata );
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       // ipc call
-       if (ctsvc_ipc_call(CTSVC_IPC_SIM_MODULE, CTSVC_IPC_SERVER_SIM_UPDATE_CONTACT, indata, &outdata) != 0)
-       {
-               pims_ipc_data_destroy(indata);
-               CTS_ERR("ctsvc_ipc_call failed");
-               return CONTACTS_ERROR_IPC;
-       }
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               pims_ipc_data_destroy(outdata);
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       return ret;
-}
-
-API int contacts_sim_delete(int person_id)
-{
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(person_id <= 0,CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
-
-
-       // make indata
-       indata = pims_ipc_data_create(0);
-       if (indata == NULL)
-       {
-               CTS_ERR("ipc data created fail!");
-               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
-               return ret;
-       }
-
-       ret = ctsvc_ipc_marshal_int( person_id, indata );
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       // ipc call
-       if (ctsvc_ipc_call(CTSVC_IPC_SIM_MODULE, CTSVC_IPC_SERVER_SIM_DELETE_CONTACT, indata, &outdata) != 0)
-       {
-               pims_ipc_data_destroy(indata);
-               CTS_ERR("ctsvc_ipc_call failed");
-               return CONTACTS_ERROR_IPC;
-       }
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               pims_ipc_data_destroy(outdata);
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       return ret;
-}
index b6f2d03..52a24f1 100755 (executable)
 #define CTSVC_JAPANESE_HALFWIDTH_AND_FULLWIDTH_FORMS_START 0xFF00
 #define CTSVC_JAPANESE_HALFWIDTH_AND_FULLWIDTH_FORMS_END 0xFFEF
 
+/* japanese - halfwidth and fullwidth forms */
+#define CTSVC_ASCII_HALFWIDTH_AND_FULLWIDTH_FORMS_START 0xFF01
+#define CTSVC_ASCII_HALFWIDTH_AND_FULLWIDTH_FORMS_END 0xFF5E
+
 /* japanese - hiragana */
 #define CTSVC_JAPANESE_HIRAGANA_START 0x3040
 #define CTSVC_JAPANESE_HIRAGANA_END 0x309F
@@ -226,19 +230,21 @@ static inline int __ctsvc_convert_japanese_to_hiragana(UChar *src, UChar *dest,
                int unicode_value1 = 0;
                int unicode_value2 = 0;
 
-               unicode_value1 = 0x30;
                unicode_value2 = (0xFF & (src[i]));
 
                if (CTSVC_COMPARE_BETWEEN(CTSVC_JAPANESE_KATAKANA_START, src[i], CTSVC_JAPANESE_KATAKANA_END)) {
+                       unicode_value1 = 0x30;
                        if ((unicode_value2 >= 0xa1 && unicode_value2 <= 0xef )
                                        || (unicode_value2 == 0xF2 || unicode_value2 == 0xF3) ) {
                                unicode_value2 -= 0x60;
                                dest[j] = unicode_value1 << 8 | unicode_value2;
                        }
-                       else
+                       else {
                                dest[j] = src[i];
+                       }
                }
                else if (CTSVC_COMPARE_BETWEEN(CTSVC_JAPANESE_HALFWIDTH_AND_FULLWIDTH_FORMS_START, src[i], CTSVC_JAPANESE_HALFWIDTH_AND_FULLWIDTH_FORMS_END)) {
+                       unicode_value1 = 0x30;
                        if (i+1 < len && (0xFF & (src[i+1])) == 0x9E
                                        && unicode_value2 >= 0x76 && unicode_value2 <= 0x89) {
                                unicode_value2 = japanese_halfwidth_katakana_sonant_to_hiragana[unicode_value2 - 0x76];
@@ -255,11 +261,17 @@ static inline int __ctsvc_convert_japanese_to_hiragana(UChar *src, UChar *dest,
                                unicode_value2 = japanese_halfwidth_katakana_to_hiragana[unicode_value2 - 0x66];
                                dest[j] = unicode_value1 << 8 | unicode_value2;
                        }
-                       else
+                       else {
                                dest[j] = src[i];
-
-               } else
+                       }
+               }
+               else if (CTSVC_COMPARE_BETWEEN(CTSVC_ASCII_HALFWIDTH_AND_FULLWIDTH_FORMS_START, src[i], CTSVC_ASCII_HALFWIDTH_AND_FULLWIDTH_FORMS_END)) {
+                       unicode_value1 = 0x00;
+                       unicode_value2 = unicode_value2 - 0x20;
+                       dest[j] = unicode_value1 << 8 | unicode_value2;
+               } else {
                        dest[j] = src[i];
+               }
                j++;
        }
 
@@ -290,6 +302,7 @@ int ctsvc_convert_japanese_to_hiragana(const char *src, char **dest)
                ret = CONTACTS_ERROR_SYSTEM;
                goto DATA_FREE;
        }
+
        result = calloc(1, sizeof(UChar) * (size + 1));
 
        __ctsvc_convert_japanese_to_hiragana(tmp_result, result, size + 1 );
@@ -313,7 +326,6 @@ int ctsvc_convert_japanese_to_hiragana(const char *src, char **dest)
        }
 
 DATA_FREE:
-
        free(tmp_result);
        free(result);
 
@@ -335,7 +347,8 @@ int ctsvc_check_language(UChar *word)
        if (CTSVC_COMPARE_BETWEEN('0', word[0], '9')) {
                type = CTSVC_LANG_NUMBER;
        }
-       else if (CTSVC_COMPARE_BETWEEN(0x41, word[0], 0x7A)) {  /* english */
+       else if (CTSVC_COMPARE_BETWEEN(0x41, word[0], 0x7A)  /* english */
+               || CTSVC_COMPARE_BETWEEN(0x0300, word[0], 0x036f)) { /* diacritical marks */
                type = CTSVC_LANG_ENGLISH;
        }
        else if (is_hangul(word[0])){
index cfdee58..5dfa096 100644 (file)
@@ -326,7 +326,6 @@ int ctsvc_normalize_number(const char *src, char *dest, int dest_size, int min_m
                CTS_ERR("__ctsvc_normalize_number(src) failed(%d)", src, ret);
                return ret;
        }
-
        return CONTACTS_ERROR_NONE;
 }
 
@@ -392,6 +391,7 @@ static inline int __ctsvc_collation_str(const char *src, char **dest)
        u_strFromUTF8(tmp_result, size + 1, NULL, src, -1, &status);
        if (U_FAILURE(status)){
                CTS_ERR("u_strFromUTF8 Failed(%s)", u_errorName(status));
+               free(tmp_result);
                ucol_close(collator);
                return CONTACTS_ERROR_SYSTEM;
        }
@@ -401,7 +401,7 @@ static inline int __ctsvc_collation_str(const char *src, char **dest)
        size = ucol_getSortKey(collator, tmp_result, -1, (uint8_t *)*dest, size + 1);
 
        ucol_close(collator);
-
+       free(tmp_result);
        return CONTACTS_ERROR_NONE;
 }
 
index 06fdd1c..e0c7bed 100644 (file)
@@ -165,7 +165,7 @@ int ctsvc_record_set_property_flag(ctsvc_record_s* _record, int property_id, con
        if (NULL == _record->properties_flags) {
                unsigned int count = 0;
                ctsvc_view_get_all_property_infos(_record->view_uri, &count);
-               RETVM_IF(count < 0, CONTACTS_ERROR_INVALID_PARAMETER, "ctsvc_view_get_all_property_infos() Failed");
+               RETVM_IF(count <= 0, CONTACTS_ERROR_INVALID_PARAMETER, "ctsvc_view_get_all_property_infos() Failed");
 
                _record->properties_flags = calloc(count, sizeof(char));
                _record->property_max_count = count;
@@ -589,8 +589,6 @@ API int contacts_record_clone_child_record_list( contacts_record_h record,
 int ctsvc_record_set_projection_flags( contacts_record_h record, const unsigned int *projection, const unsigned int projection_count, const unsigned int property_max_count)
 {
        int i;
-       unsigned int count;
-       const property_info_s *property_info;
 
        RETV_IF(record == NULL, CONTACTS_ERROR_INVALID_PARAMETER);
 
@@ -604,7 +602,6 @@ int ctsvc_record_set_projection_flags( contacts_record_h record, const unsigned
 
        _record->property_max_count = property_max_count;
 
-       property_info = ctsvc_view_get_all_property_infos(_record->view_uri, &count);
        if (CTSVC_RECORD_RESULT == _record->r_type)
                _record->property_flag |= CTSVC_PROPERTY_FLAG_PROJECTION;
        else {
index 3660d54..dbb28bb 100644 (file)
@@ -3799,10 +3799,10 @@ static int __ctsvc_contact_clone(contacts_record_h record, contacts_record_h *ou
        out_data->addressbook_id = src_data->addressbook_id;
        out_data->changed_time = src_data->changed_time;
        out_data->display_source_type = src_data->display_source_type;
+       out_data->display_name_language = src_data->display_name_language;
        out_data->has_phonenumber = src_data->has_phonenumber;
        out_data->has_email = src_data->has_email;
        out_data->is_favorite = src_data->is_favorite;
-       out_data->is_restricted = src_data->is_restricted;
 
        out_data->display_name = SAFE_STRDUP(src_data->display_name);
        out_data->reverse_display_name = SAFE_STRDUP(src_data->reverse_display_name);
@@ -4294,6 +4294,7 @@ static int __ctsvc_simple_contact_clone(contacts_record_h record, contacts_recor
        out_data->vibration_changed = src_data->vibration_changed;
        out_data->image_thumbnail_changed = src_data->image_thumbnail_changed;
        out_data->ringtone_changed = src_data->ringtone_changed;
+       out_data->display_name_changed = src_data->display_name_changed;
 
        out_data->contact_id = src_data->contact_id;
        out_data->person_id = src_data->person_id;
@@ -4303,7 +4304,6 @@ static int __ctsvc_simple_contact_clone(contacts_record_h record, contacts_recor
        out_data->has_phonenumber = src_data->has_phonenumber;
        out_data->has_email = src_data->has_email;
        out_data->is_favorite = src_data->is_favorite;
-       //      out_data->is_restricted = src_data->is_restricted;
 
        out_data->display_name = SAFE_STRDUP(src_data->display_name);
        out_data->uid = SAFE_STRDUP(src_data->uid);
index 80e608f..8688529 100644 (file)
@@ -126,6 +126,7 @@ static int __ctsvc_my_profile_destroy(contacts_record_h record, bool delete_chil
        free(my_profile->base.properties_flags);
 
        free(my_profile->display_name);
+       free(my_profile->reverse_display_name);
        free(my_profile->uid);
        free(my_profile->image_thumbnail_path);
 
@@ -541,6 +542,7 @@ static int __ctsvc_my_profile_clone(contacts_record_h record, contacts_record_h
        out_data->changed_time = src_data->changed_time;
 
        out_data->display_name = SAFE_STRDUP(src_data->display_name);
+       out_data->reverse_display_name = SAFE_STRDUP(src_data->reverse_display_name);
        out_data->uid = SAFE_STRDUP(src_data->uid);
        out_data->image_thumbnail_path = SAFE_STRDUP(src_data->image_thumbnail_path);
 
index da86cab..53918a9 100644 (file)
@@ -262,7 +262,6 @@ typedef struct {
        bool image_thumbnail_changed;
        bool ringtone_changed;
        bool vibration_changed;
-       bool is_restricted;
        bool is_favorite;
        int changed_time;
        bool has_phonenumber;
@@ -502,7 +501,6 @@ typedef struct {
        bool image_thumbnail_changed;
        bool ringtone_changed;
        bool vibration_changed;
-       bool is_restricted;
        bool is_favorite;
        int id;
        int person_id;
@@ -545,10 +543,12 @@ typedef struct {
 
 typedef struct {
        ctsvc_record_s base;
+       bool display_name_changed;
        int id;
        int addressbook_id;
        int changed_time;
        char *display_name;
+       char *reverse_display_name;
        char *uid;
        char *image_thumbnail_path;
        ctsvc_list_s* name;
index 46e3159..1709413 100644 (file)
@@ -1873,7 +1873,6 @@ static char* __ctsvc_vcard_get_val(int ver, char *src, char **dest)
                        return NULL;
                case '\r':
                case ' ':
-               case ':':
                        src++;
                        break;
                default:
@@ -2082,13 +2081,17 @@ static inline int __ctsvc_vcard_get_nickname(ctsvc_list_s *nickname_list, char *
 {
        int ret;
        char *temp;
+       char *start;
        const char *separator = ",";
        contacts_record_h nickname;
 
+       start = __ctsvc_get_content_value(val);
+       RETV_IF(NULL == start, CONTACTS_ERROR_NO_DATA);
+
        ret = contacts_record_create(_contacts_nickname._uri, &nickname);
        RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "contacts_record_create is failed(%d)", ret);
 
-       temp = strtok(val, separator);
+       temp = strtok(start, separator);
        while (temp) {
                if ('\0' == *temp) continue;
 
index 77f27b6..709ba3b 100644 (file)
@@ -753,8 +753,8 @@ const property_info_s __property_company[] = {
        {CTSVC_PROPERTY_COMPANY_NAME,                           CTSVC_SEARCH_PROPERTY_ALL,      "data3"},
        {CTSVC_PROPERTY_COMPANY_DEPARTMENT,     CTSVC_SEARCH_PROPERTY_ALL,      "data4"},
        {CTSVC_PROPERTY_COMPANY_JOB_TITLE,              CTSVC_SEARCH_PROPERTY_ALL,      "data5"},
-       {CTSVC_PROPERTY_COMPANY_ASSISTANT_NAME,CTSVC_SEARCH_PROPERTY_ALL,       "data6"},
-       {CTSVC_PROPERTY_COMPANY_ROLE,                           CTSVC_SEARCH_PROPERTY_ALL,      "data7"},
+       {CTSVC_PROPERTY_COMPANY_ROLE,                   CTSVC_SEARCH_PROPERTY_ALL,      "data6"},
+       {CTSVC_PROPERTY_COMPANY_ASSISTANT_NAME, CTSVC_SEARCH_PROPERTY_ALL,      "data7"},
        {CTSVC_PROPERTY_COMPANY_LOGO,                           CTSVC_SEARCH_PROPERTY_ALL,      "data8"},
        {CTSVC_PROPERTY_COMPANY_LOCATION,               CTSVC_SEARCH_PROPERTY_ALL,      "data9"},
        {CTSVC_PROPERTY_COMPANY_DESCRIPTION,    CTSVC_SEARCH_PROPERTY_ALL,      "data10"},
index 94f4d31..1658708 100644 (file)
@@ -326,8 +326,8 @@ typedef enum {
        CTSVC_PROPERTY_COMPANY_NAME = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +4,
        CTSVC_PROPERTY_COMPANY_DEPARTMENT = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +5,
        CTSVC_PROPERTY_COMPANY_JOB_TITLE = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +6,
-       CTSVC_PROPERTY_COMPANY_ASSISTANT_NAME = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +7,
-       CTSVC_PROPERTY_COMPANY_ROLE = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +8,
+       CTSVC_PROPERTY_COMPANY_ROLE = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +7,
+       CTSVC_PROPERTY_COMPANY_ASSISTANT_NAME = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +8,
        CTSVC_PROPERTY_COMPANY_LOGO = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +9,
        CTSVC_PROPERTY_COMPANY_LOCATION = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +10,
        CTSVC_PROPERTY_COMPANY_DESCRIPTION = (CTSVC_PROPERTY_COMPANY | CTSVC_VIEW_DATA_TYPE_STR) +11,
index 6e4e2f8..a2f77c2 100644 (file)
@@ -29,7 +29,6 @@ static int __ctsvc_ipc_unmarshal_contact(pims_ipc_data_h ipc_data, const char* v
                if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->image_thumbnail_changed) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->ringtone_changed) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->vibration_changed) != CONTACTS_ERROR_NONE) break;
-               if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->is_restricted) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->is_favorite) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->id) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->person_id) != CONTACTS_ERROR_NONE) break;
@@ -89,7 +88,6 @@ static int __ctsvc_ipc_marshal_contact(const contacts_record_h record, pims_ipc_
                if (ctsvc_ipc_marshal_bool((pcontact->image_thumbnail_changed),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_bool((pcontact->ringtone_changed),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_bool((pcontact->vibration_changed),ipc_data) != CONTACTS_ERROR_NONE) break;
-               if (ctsvc_ipc_marshal_bool((pcontact->is_restricted),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_bool((pcontact->is_favorite),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_int((pcontact->id),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_int((pcontact->person_id),ipc_data) != CONTACTS_ERROR_NONE) break;
index e91f9fc..c386a45 100644 (file)
@@ -29,6 +29,7 @@ static int __ctsvc_ipc_unmarshal_my_profile(pims_ipc_data_h ipc_data, const char
                if (ctsvc_ipc_unmarshal_int(ipc_data, &pmy_profile->changed_time) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_int(ipc_data, &pmy_profile->addressbook_id) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_string(ipc_data, &pmy_profile->display_name) != CONTACTS_ERROR_NONE) break;
+               if (ctsvc_ipc_unmarshal_string(ipc_data, &pmy_profile->reverse_display_name) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_string(ipc_data, &pmy_profile->uid) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_string(ipc_data, &pmy_profile->image_thumbnail_path) != CONTACTS_ERROR_NONE) break;
 
@@ -65,6 +66,7 @@ static int __ctsvc_ipc_marshal_my_profile(const contacts_record_h record, pims_i
                if (ctsvc_ipc_marshal_int((pcontact->changed_time),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_int((pcontact->addressbook_id),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_string((pcontact->display_name),ipc_data) != CONTACTS_ERROR_NONE) break;
+               if (ctsvc_ipc_marshal_string((pcontact->reverse_display_name),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_string((pcontact->uid),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_string((pcontact->image_thumbnail_path),ipc_data) != CONTACTS_ERROR_NONE) break;
 
index aaab788..d3cc62f 100644 (file)
@@ -20,7 +20,6 @@ static int __ctsvc_ipc_unmarshal_simple_contact(pims_ipc_data_h ipc_data, const
 
        ctsvc_simple_contact_s* pcontact = (ctsvc_simple_contact_s*) record;
        do {
-               if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->is_restricted) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->is_favorite) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->changed_time) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->has_phonenumber) != CONTACTS_ERROR_NONE) break;
@@ -48,7 +47,6 @@ static int __ctsvc_ipc_marshal_simple_contact(const contacts_record_h record, pi
        RETV_IF(ipc_data==NULL,CONTACTS_ERROR_NO_DATA);
        RETV_IF(pcontact==NULL,CONTACTS_ERROR_NO_DATA);
        do {
-               if (ctsvc_ipc_marshal_bool((pcontact->is_restricted),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_bool((pcontact->is_favorite),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_int((pcontact->changed_time),ipc_data) != CONTACTS_ERROR_NONE) break;
                if (ctsvc_ipc_marshal_bool((pcontact->has_phonenumber),ipc_data) != CONTACTS_ERROR_NONE) break;
index 7761304..a47a145 100644 (file)
@@ -9,9 +9,9 @@
                </request>
        </define>
        <assign>
-               <filesystem path="/usr/lib/libcontacts-service2.so.0.9.45.3" label="_"/>
+               <filesystem path="/usr/lib/libcontacts-service2.so.0.9.52.1" label="_"/>
                <filesystem path="/usr/lib/libcontacts-service2.so.0" label="_"/>
-               <filesystem path="/usr/lib/libcontacts-service3.so.0.9.45.3" label="_"/>
+               <filesystem path="/usr/lib/libcontacts-service3.so.0.9.52.1" label="_"/>
                <filesystem path="/usr/lib/libcontacts-service3.so.0" label="_"/>
                <filesystem path="/opt/usr/dbspace/.contacts-svc.db" label="contacts-service::db"/>
                <filesystem path="/opt/usr/dbspace/.contacts-svc.db-journal" label="contacts-service::db"/>
index a5dd1fd..afdf171 100644 (file)
@@ -28,7 +28,6 @@
 #include "ctsvc_sqlite.h"
 #include "ctsvc_db_init.h"
 #include "ctsvc_utils.h"
-#include "ctsvc_restriction.h"
 #include "ctsvc_view.h"
 #include "ctsvc_notification.h"
 
@@ -843,11 +842,6 @@ int ctsvc_db_init()
                CTS_ERR("ctsvc_db_open() Failed(%d)", ret);
                return ret;
        }
-       ret = ctsvc_restriction_init();
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("ctsvc_restriction_init() Failed(%d)", ret);
-               return ret;
-       }
 
 #ifdef _CONTACTS_IPC_SERVER
        ret = __ctsvc_db_create_views();
@@ -868,7 +862,6 @@ int ctsvc_db_deinit()
                CTS_ERR("ctsvc_db_close() Failed(%d)", ret);
                return ret;
        }
-       ctsvc_restriction_deinit();
        return CONTACTS_ERROR_NONE;
 }
 
index 1166bf3..a47298b 100644 (file)
@@ -292,87 +292,7 @@ static int __ctsvc_db_contact_get_record( int id, contacts_record_h* out_record
 
 static int __ctsvc_db_contact_delete_record( int id )
 {
-       CTS_FN_CALL;
-       int ret, rel_changed;
-       int addressbook_id;
-       int person_id;
-       int link_count = 0;
-       char query[CTS_SQL_MAX_LEN] = {0};
-       cts_stmt stmt = NULL;
-
-       ret = ctsvc_begin_trans();
-       RETVM_IF(ret, ret, "DB error : ctsvc_begin_trans() Failed(%d)", ret);
-
-       snprintf(query, sizeof(query),
-               "SELECT addressbook_id, person_id "
-               "FROM "CTS_TABLE_CONTACTS" WHERE contact_id = %d AND deleted = 0", id);
-
-       stmt = cts_query_prepare(query);
-       if (NULL == stmt) {
-               CTS_ERR("DB error : cts_query_prepare() Failed");
-               ctsvc_end_trans(false);
-               return CONTACTS_ERROR_DB;
-       }
-
-       ret = cts_stmt_step(stmt);
-       if (1 != ret) {
-               CTS_ERR("DB error : cts_stmt_step() Failed(%d)", ret);
-               cts_stmt_finalize(stmt);
-               ctsvc_end_trans(false);
-               if (CONTACTS_ERROR_NONE == ret)
-                       return CONTACTS_ERROR_NO_DATA;
-               else
-                       return ret;
-       }
-
-       addressbook_id = ctsvc_stmt_get_int(stmt, 0);
-       person_id = ctsvc_stmt_get_int(stmt, 1);
-       CTS_DBG("addressbook_id : %d, person_id : %d", addressbook_id, person_id);
-       cts_stmt_finalize(stmt);
-
-       snprintf(query, sizeof(query),
-                       "UPDATE %s SET member_changed_ver=%d "
-                               "WHERE group_id IN (SELECT group_id FROM %s WHERE contact_id = %d AND deleted = 0) ",
-                               CTS_TABLE_GROUPS, ctsvc_get_next_ver(), CTS_TABLE_GROUP_RELATIONS, 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;
-       }
-
-       rel_changed = cts_db_change();
-       // images are deleted by db trigger callback function in ctsvc_db_contact_delete_callback
-       snprintf(query, sizeof(query), "DELETE FROM %s WHERE contact_id = %d",
-                       CTS_TABLE_CONTACTS, 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;
-       }
-
-       snprintf(query, sizeof(query), "SELECT link_count FROM "CTS_TABLE_PERSONS" WHERE person_id = %d", person_id);
-       ret = ctsvc_query_get_first_int_result(query, &link_count);
-       WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_query_get_first_int_result() Failed(%d)", ret);
-       // set dirty bit to person by trigger : person will be aggregated in ctsvc_person_aggregate
-       if (1 < link_count)
-               ctsvc_person_aggregate(person_id);
-       else
-               ctsvc_set_person_noti();
-
-       ctsvc_set_contact_noti();
-       if (rel_changed > 0)
-               ctsvc_set_group_rel_noti();
-
-       ret = ctsvc_end_trans(true);
-       if (ret < CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("DB error : ctsvc_end_trans() Failed(%d)", ret);
-               return ret;
-       }
-       else
-               return CONTACTS_ERROR_NONE;
+       return ctsvc_db_contact_delete(id);
 }
 
 static inline int __ctsvc_safe_strcmp(char *s1, char *s2)
@@ -723,6 +643,7 @@ static inline int __ctsvc_contact_make_search_data(int contact_id, char **search
 
        char *number = NULL;
        char *data = NULL;
+       char *normalized_data = NULL;
        char *temp_number=NULL;
        char *temp_data=NULL;
        int buf_size=0;
@@ -750,7 +671,6 @@ static inline int __ctsvc_contact_make_search_data(int contact_id, char **search
                contacts_list_h number_list = (contacts_list_h)contact->numbers;
                ctsvc_number_s *number_record;
                contacts_list_first(number_list);
-               len = 0;
                do {
                        contacts_list_get_current_record_p(number_list, (contacts_record_h*)&number_record);
                        if (NULL != number_record) {
@@ -766,7 +686,6 @@ static inline int __ctsvc_contact_make_search_data(int contact_id, char **search
                }while(CONTACTS_ERROR_NONE == contacts_list_next(number_list));
        }
 
-       len = 0;
        if (contact->emails) {
                contacts_list_h email_list = (contacts_list_h)contact->emails;
                ctsvc_email_s *email;
@@ -798,7 +717,7 @@ static inline int __ctsvc_contact_make_search_data(int contact_id, char **search
                                if (data)
                                        snprintf(temp_data, buf_size, "%s %s ", data, nickname->nickname);
                                else
-                                       snprintf(temp_data+len, buf_size, "%s ", nickname->nickname);
+                                       snprintf(temp_data, buf_size, "%s ", nickname->nickname);
                                free(data);
                                data = temp_data;
                        }
@@ -844,10 +763,114 @@ static inline int __ctsvc_contact_make_search_data(int contact_id, char **search
                }while(CONTACTS_ERROR_NONE == contacts_list_next(address_list));
        }
 
+       if (contact->note) {
+               contacts_list_h note_list = (contacts_list_h)contact->note;
+               ctsvc_note_s *note;
+               contacts_list_first(note_list);
+               do {
+                       contacts_list_get_current_record_p(note_list, (contacts_record_h*)&note);
+                       if (NULL != note) {
+                               buf_size = SAFE_STRLEN(data) + SAFE_STRLEN(note->note) + 3;
+                               temp_data = calloc(1, buf_size);
+                               if (data)
+                                       snprintf(temp_data, buf_size, "%s %s ",data, note->note);
+                               else
+                                       snprintf(temp_data, buf_size, "%s",note->note);
+                               free(data);
+                               data = temp_data;
+                       }
+               }while(CONTACTS_ERROR_NONE == contacts_list_next(note_list));
+       }
+
+       if (contact->messengers) {
+               contacts_list_h messenger_list = (contacts_list_h)contact->messengers;
+               ctsvc_messenger_s *messenger;
+               contacts_list_first(messenger_list);
+               do {
+                       contacts_list_get_current_record_p(messenger_list, (contacts_record_h*)&messenger);
+                       if (NULL != messenger) {
+                               buf_size = SAFE_STRLEN(data) + SAFE_STRLEN(messenger->im_id) + 3;
+                               temp_data = calloc(1, buf_size);
+                               if (data)
+                                       snprintf(temp_data, buf_size, "%s %s ",data, messenger->im_id);
+                               else
+                                       snprintf(temp_data, buf_size, "%s",messenger->im_id);
+                               free(data);
+                               data = temp_data;
+                       }
+               }while(CONTACTS_ERROR_NONE == contacts_list_next(messenger_list));
+       }
+
+       if (contact->relationships) {
+               contacts_list_h relationship_list = (contacts_list_h)contact->relationships;
+               ctsvc_relationship_s *relationship;
+               contacts_list_first(relationship_list);
+               do {
+                       contacts_list_get_current_record_p(relationship_list, (contacts_record_h*)&relationship);
+                       if (NULL != relationship) {
+                               buf_size = SAFE_STRLEN(data) + SAFE_STRLEN(relationship->name) + 3;
+                               temp_data = calloc(1, buf_size);
+                               if (data)
+                                       snprintf(temp_data, buf_size, "%s %s ",data, relationship->name);
+                               else
+                                       snprintf(temp_data, buf_size, "%s",relationship->name);
+                               free(data);
+                               data = temp_data;
+                       }
+               }while(CONTACTS_ERROR_NONE == contacts_list_next(relationship_list));
+       }
+
+       if (contact->company) {
+               contacts_list_h company_list = (contacts_list_h)contact->company;
+               ctsvc_company_s *company;
+               contacts_list_first(company_list);
+               do {
+                       contacts_list_get_current_record_p(company_list, (contacts_record_h*)&company);
+                       if (NULL != company) {
+                               len =0;
+                               buf_size = SAFE_STRLEN(data)
+                                                       + SAFE_STRLEN(company->name)
+                                                       + SAFE_STRLEN(company->department)
+                                                       + SAFE_STRLEN(company->job_title)
+                                                       + SAFE_STRLEN(company->role)
+                                                       + SAFE_STRLEN(company->assistant_name)
+                                                       + SAFE_STRLEN(company->location)
+                                                       + SAFE_STRLEN(company->description)
+                                                       + SAFE_STRLEN(company->phonetic_name)+ 10;
+                               temp_data = calloc(1, buf_size);
+                               if(data)
+                                       len += snprintf(temp_data + len, buf_size - len, "%s ", data);
+                               if (company->name)
+                                       len += snprintf(temp_data + len, buf_size - len, "%s ", company->name);
+                               if (company->department)
+                                       len += snprintf(temp_data + len, buf_size - len, "%s ", company->department);
+                               if (company->job_title)
+                                       len += snprintf(temp_data + len, buf_size - len, "%s ", company->job_title);
+                               if (company->role)
+                                       len += snprintf(temp_data + len, buf_size - len, "%s ", company->role);
+                               if (company->assistant_name)
+                                       len += snprintf(temp_data + len, buf_size - len, "%s ", company->assistant_name);
+                               if (company->location)
+                                       len += snprintf(temp_data + len, buf_size - len, "%s ", company->location);
+                               if (company->description)
+                                       len += snprintf(temp_data + len, buf_size - len, "%s ", company->description);
+                               if (company->phonetic_name)
+                                       len += snprintf(temp_data + len, buf_size - len, "%s ", company->phonetic_name);
+
+                               free(data);
+                               data = temp_data;
+                       }
+               }while(CONTACTS_ERROR_NONE == contacts_list_next(company_list));
+       }
+
        contacts_record_destroy((contacts_record_h)contact, true);
 
        *search_number = number;
-       *search_data = data;
+       if (data) {
+               ctsvc_normalize_str(data, &normalized_data);
+               *search_data = normalized_data;
+               free(data);
+       }
        return CONTACTS_ERROR_NONE;
 }
 
@@ -1737,6 +1760,7 @@ static int __ctsvc_db_contact_insert_record( contacts_record_h record, int *id)
        int ret, person_id = 0;
        char query[CTS_SQL_MAX_LEN] = {0};
        bool auto_link_enabled = true;
+       bool auto_linked = false;
 
        ctsvc_contact_s *contact = (ctsvc_contact_s*)record;
        int rel_changed = 0;
@@ -1763,9 +1787,8 @@ static int __ctsvc_db_contact_insert_record( contacts_record_h record, int *id)
        if (id)
                *id = ret;
 
-       DBG("B ctsvc_make_contact_display_name");
        ctsvc_make_contact_display_name(contact);
-       DBG("A ctsvc_make_contact_display_name");
+
        __ctsvc_contact_check_default_data(contact);
 
        //Insert Data
@@ -1813,6 +1836,7 @@ static int __ctsvc_db_contact_insert_record( contacts_record_h record, int *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;
+                       auto_linked = true;
                }
                else {
                        ret = ctsvc_db_insert_person((contacts_record_h)contact);
@@ -1837,14 +1861,14 @@ static int __ctsvc_db_contact_insert_record( contacts_record_h record, int *id)
        }
 
        snprintf(query, sizeof(query),
-               "INSERT INTO "CTS_TABLE_CONTACTS"(contact_id, person_id, addressbook_id, is_restricted, "
+               "INSERT INTO "CTS_TABLE_CONTACTS"(contact_id, person_id, addressbook_id, is_favorite, "
                        "created_ver, changed_ver, changed_time, image_changed_ver, has_phonenumber, has_email, "
                        "display_name, reverse_display_name, display_name_source, display_name_language, "
                        "sort_name, reverse_sort_name, "
                        "sortkey, reverse_sortkey, "
                        "uid, ringtone_path, vibration, image_thumbnail_path) "
                        "VALUES(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, ?, ?, %d, %d, ?, ?, ?, ?, ?, ?, ?, ?)",
-                       contact->id, contact->person_id, contact->addressbook_id, contact->is_restricted,
+                       contact->id, contact->person_id, contact->addressbook_id, contact->is_favorite,
                        version, version, (int)time(NULL), (NULL !=contact->image_thumbnail_path)?version:0, contact->has_phonenumber, contact->has_email,
                        contact->display_source_type, contact->display_name_language);
 
@@ -1895,9 +1919,11 @@ static int __ctsvc_db_contact_insert_record( contacts_record_h record, int *id)
                }
        }
 
-       DBG("B __ctsvc_contact_insert_search_data");
        __ctsvc_contact_insert_search_data(contact->id);
-       DBG("A __ctsvc_contact_insert_search_data");
+
+       // person aggregation when auto_linked
+       if (auto_linked)
+               ctsvc_person_aggregate(contact->person_id);
 
        if (rel_changed)
                ctsvc_set_group_rel_noti();
index 4042a1d..c97623c 100644 (file)
 
 //#include "ctsvc_db_plugin_grouprelation_helper.h"
 
+#include "ctsvc_person.h"
 #include "ctsvc_group.h"
 
-#define CTSVC_MY_IMAGE_LOCATION "/opt/usr/data/contacts-svc/img/my"
-
-int ctsvc_contact_add_image_file(ctsvc_img_e image_type, int parent_id, int img_id,
+int ctsvc_contact_add_image_file(int parent_id, int img_id,
                char *src_img, char *dest_name, int dest_size)
 {
        int ret;
+       int version;
        char *ext;
        char dest[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
 
@@ -71,28 +71,17 @@ int ctsvc_contact_add_image_file(ctsvc_img_e image_type, int parent_id, int img_
        if (NULL == ext || strchr(ext, '/'))
                ext = "";
 
-       snprintf(dest, sizeof(dest), "%s/%d_%d-%d%s", CTS_IMG_FULL_LOCATION, parent_id, img_id, image_type, ext);
+       version = ctsvc_get_next_ver();
+       snprintf(dest, sizeof(dest), "%s/%d_%d-%d%s", CTS_IMG_FULL_LOCATION, parent_id, img_id, version, ext);
 
        ret = ctsvc_copy_image(src_img, dest);
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "cts_copy_file() Failed(%d)", ret);
 
-       snprintf(dest_name, dest_size, "%d_%d-%d%s", parent_id, img_id, image_type, ext);
+       snprintf(dest_name, dest_size, "%d_%d-%d%s", parent_id, img_id, version, ext);
        return CONTACTS_ERROR_NONE;
 }
 
-static inline const char* __ctsvc_get_image_column_name(ctsvc_img_e image_type)
-{
-       switch(image_type)
-       {
-       case CTSVC_IMG_NORMAL:
-               return "image_thumbnail_path";
-       default:
-               CTS_ERR("Invalid parameter : The image_type(%d) is not supported", image_type);
-               return NULL;
-       }
-}
-
-static int __ctsvc_contact_delete_image_file(ctsvc_img_e image_type, int image_id)
+static int __ctsvc_contact_delete_image_file(int image_id)
 {
        int ret;
        cts_stmt stmt;
@@ -125,7 +114,7 @@ static int __ctsvc_contact_delete_image_file(ctsvc_img_e image_type, int image_i
        return CONTACTS_ERROR_NONE;
 }
 
-int ctsvc_contact_update_image_file(int image_type, int parent_id, int img_id,
+int ctsvc_contact_update_image_file(int parent_id, int img_id,
                char *src_img, char *dest_name, int dest_size)
 {
        int ret;
@@ -134,12 +123,12 @@ int ctsvc_contact_update_image_file(int image_type, int parent_id, int img_id,
                return CONTACTS_ERROR_NONE;
        }
 
-       ret = __ctsvc_contact_delete_image_file(image_type, img_id);
+       ret = __ctsvc_contact_delete_image_file(img_id);
        WARN_IF(CONTACTS_ERROR_NONE != ret && CONTACTS_ERROR_NO_DATA != ret,
                        "__ctsvc_contact_delete_image_file() Failed(%d)", ret);
 
        if (src_img) {
-               ret = ctsvc_contact_add_image_file(image_type, parent_id, img_id, src_img, dest_name, dest_size);
+               ret = ctsvc_contact_add_image_file(parent_id, img_id, src_img, dest_name, dest_size);
                RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_contact_add_image_file() Failed(%d)", ret);
        }
 
@@ -177,6 +166,94 @@ int ctsvc_contact_delete_image_file_with_path(const unsigned char* image_path)
        return CONTACTS_ERROR_NONE;
 }
 
+int ctsvc_db_contact_delete(int contact_id)
+{
+       CTS_FN_CALL;
+       int ret, rel_changed;
+       int addressbook_id;
+       int person_id;
+       int link_count = 0;
+       char query[CTS_SQL_MAX_LEN] = {0};
+       cts_stmt stmt = NULL;
+       int version;
+
+       ret = ctsvc_begin_trans();
+       RETVM_IF(ret, ret, "DB error : ctsvc_begin_trans() Failed(%d)", ret);
+
+       snprintf(query, sizeof(query),
+               "SELECT addressbook_id, person_id "
+               "FROM "CTS_TABLE_CONTACTS" WHERE contact_id = %d AND deleted = 0", contact_id);
+
+       stmt = cts_query_prepare(query);
+       if (NULL == stmt) {
+               CTS_ERR("DB error : cts_query_prepare() Failed");
+               ctsvc_end_trans(false);
+               return CONTACTS_ERROR_DB;
+       }
+
+       ret = cts_stmt_step(stmt);
+       if (1 != ret) {
+               CTS_ERR("DB error : cts_stmt_step() Failed(%d)", ret);
+               cts_stmt_finalize(stmt);
+               ctsvc_end_trans(false);
+               if (CONTACTS_ERROR_NONE == ret)
+                       return CONTACTS_ERROR_NO_DATA;
+               else
+                       return ret;
+       }
+
+       addressbook_id = ctsvc_stmt_get_int(stmt, 0);
+       person_id = ctsvc_stmt_get_int(stmt, 1);
+       CTS_DBG("addressbook_id : %d, person_id : %d", addressbook_id, person_id);
+       cts_stmt_finalize(stmt);
+
+       version = ctsvc_get_next_ver();
+       snprintf(query, sizeof(query),
+                       "UPDATE %s SET member_changed_ver=%d "
+                               "WHERE group_id IN (SELECT group_id FROM %s WHERE contact_id = %d AND deleted = 0) ",
+                               CTS_TABLE_GROUPS, version, CTS_TABLE_GROUP_RELATIONS, contact_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;
+       }
+
+       rel_changed = cts_db_change();
+       snprintf(query, sizeof(query),
+                       "UPDATE %s SET deleted = 1, person_id = 0, changed_ver=%d WHERE contact_id = %d",
+                       CTS_TABLE_CONTACTS, version, contact_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;
+       }
+
+       snprintf(query, sizeof(query), "SELECT link_count FROM "CTS_TABLE_PERSONS" WHERE person_id = %d", person_id);
+       ret = ctsvc_query_get_first_int_result(query, &link_count);
+       WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_query_get_first_int_result() Failed(%d)", ret);
+       // set dirty bit to person by trigger : person will be aggregated in ctsvc_person_aggregate
+
+       if (1 < link_count)
+               ctsvc_person_aggregate(person_id);
+       else
+               ctsvc_set_person_noti();
+
+       ctsvc_set_contact_noti();
+       if (rel_changed > 0)
+               ctsvc_set_group_rel_noti();
+
+       ret = ctsvc_end_trans(true);
+       if (ret < CONTACTS_ERROR_NONE)
+       {
+               CTS_ERR("DB error : ctsvc_end_trans() Failed(%d)", ret);
+               return ret;
+       }
+       else
+               return CONTACTS_ERROR_NONE;
+}
+
 void ctsvc_make_contact_display_name(ctsvc_contact_s *contact)
 {
        char *display = NULL;
@@ -187,6 +264,12 @@ void ctsvc_make_contact_display_name(ctsvc_contact_s *contact)
 
        ctsvc_name_s *name = NULL;
 
+       free(contact->display_name);
+       contact->display_name = NULL;
+
+       free(contact->reverse_display_name);
+       contact->reverse_display_name = NULL;
+
        contact->display_name_language = CTSVC_SORT_OTHERS;
 
        if ( contact->name->count > 0 && contact->name->records != NULL && contact->name->records->data != NULL )
@@ -1212,7 +1295,7 @@ int ctsvc_contact_update_data_number(contacts_list_h number_list,
                        }
                        else
                                ret = ctsvc_db_number_insert(record, contact_id, is_my_profile, NULL);
-                       if (CONTACTS_ERROR_DB == ret){
+                       if (CONTACTS_ERROR_DB == ret) {
                                CTS_ERR("DB error : return (%d)", ret);
                                break;
                        }
index c449026..1ab89cf 100644 (file)
 #include "ctsvc_struct.h"
 #include "ctsvc_sqlite.h"
 
-typedef enum
-{
-       CTSVC_IMG_NORMAL, /**< . */
-} ctsvc_img_e;
-
 int ctsvc_db_contact_update_changed_time(int contact_id);
 
-int ctsvc_contact_add_image_file(ctsvc_img_e image_type, int parent_id, int img_id,
+int ctsvc_contact_add_image_file(int parent_id, int img_id,
                char *src_img, char *dest_name, int dest_size);
-int ctsvc_contact_update_image_file(int image_type, int parent_id, int img_id,
+int ctsvc_contact_update_image_file(int parent_id, int img_id,
                char *src_img, char *dest_name, int dest_size);
 void ctsvc_make_contact_display_name(ctsvc_contact_s *contact);
 
+int ctsvc_db_contact_delete(int contact_id);
 int ctsvc_contact_delete_image_file_with_path(const unsigned char* image_path);
 
 int ctsvc_get_data_info_name(cts_stmt stmt, contacts_list_h name_list);
index 63eab60..0fc7630 100644 (file)
@@ -81,7 +81,7 @@ int ctsvc_db_image_insert(contacts_record_h record, int contact_id, bool is_my_p
                                "Invalid parameter : id(%d), This record is already inserted", image->id);
 
        image_id = cts_db_get_next_id(CTS_TABLE_DATA);
-       ret = ctsvc_contact_add_image_file(CTSVC_IMG_NORMAL, contact_id, image_id, image->path, image_path, sizeof(image_path));
+       ret = ctsvc_contact_add_image_file(contact_id, image_id, image->path, image_path, sizeof(image_path));
 
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("ctsvc_contact_add_image_file(NORMAL) Failed(%d)", ret);
@@ -139,7 +139,7 @@ int ctsvc_db_image_update(contacts_record_h record, int contact_id, bool is_my_p
        if (image->is_changed) {
                char image_path[CTS_SQL_MAX_LEN] = {0};
 
-               ret = ctsvc_contact_update_image_file(CTSVC_IMG_NORMAL, contact_id, image->id, image->path, image_path, sizeof(image_path));
+               ret = ctsvc_contact_update_image_file(contact_id, image->id, image->path, image_path, sizeof(image_path));
                RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_contact_update_image_file() Failed(%d)", ret);
 
                if (*image_path) {
index 358bce7..2bb4a02 100644 (file)
@@ -265,104 +265,6 @@ static inline int __ctsvc_safe_strcmp(char *s1, char *s2)
                return strcmp(s1, s2);
 }
 
-static inline void __ctsvc_update_my_profile_display_name(ctsvc_my_profile_s *my_profile)
-{
-       char *temp_display_name = NULL;
-       char display[CTSVC_MY_PROFILE_DISPLAY_NAME_MAX_LEN] = {0};
-       GList *cur;
-       int len=0;
-
-       ctsvc_name_s *name = NULL;
-       if ( my_profile->name->count > 0 && my_profile->name->records != NULL && my_profile->name->records->data != NULL )
-       {
-               name = (ctsvc_name_s *)my_profile->name->records->data;
-       }
-
-       if ( name && ( name->first || name->last) ) {
-               if (name->first && name->last){
-                       snprintf(display, sizeof(display), "%s %s",name->first,name->last);
-                       temp_display_name = strdup(display);
-               }
-               else if (name->first)
-                       temp_display_name = strdup(name->first);
-               else
-                       temp_display_name = strdup(name->last);
-
-               if (0 != __ctsvc_safe_strcmp(my_profile->display_name, temp_display_name)) {
-                       // make display name
-                       if(name->first)
-                               len += snprintf(display + len, sizeof(display) - len, "%s", name->first);
-
-                       if(name->addition) {
-                               if (*display)
-                                       len += snprintf(display + len, sizeof(display) - len, " ");
-                               len += snprintf(display + len, sizeof(display) - len, "%s", name->addition);
-                       }
-
-                       if(name->last) {
-                               if (*display)
-                                       len += snprintf(display + len, sizeof(display) - len, " ");
-                               len += snprintf(display + len, sizeof(display) - len, "%s", name->last);
-                       }
-
-                       if(name->suffix) {
-                               if (*display)
-                                       len += snprintf(display + len, sizeof(display) - len, " ");
-                               len += snprintf(display + len, sizeof(display) - len, "%s", name->suffix);
-                       }
-                       my_profile->display_name = strdup(display);
-               }
-               free(temp_display_name);
-       }
-       else {
-               if (my_profile->company && my_profile->company->records) {
-                       for (cur=my_profile->company->records;cur;cur=cur->next) {
-                               ctsvc_company_s *company = (ctsvc_company_s *)cur->data;
-                               if (company && company->name) {
-                                       if (__ctsvc_safe_strcmp(my_profile->display_name, company->name)) {
-                                               my_profile->display_name = SAFE_STRDUP(company->name);
-                                               break;
-                                       }
-                               }
-                       }
-               }
-               else if (my_profile->nicknames && my_profile->nicknames->records) {
-                       for (cur=my_profile->nicknames->records;cur;cur=cur->next) {
-                               ctsvc_nickname_s *nickname = (ctsvc_nickname_s *)cur->data;
-                               if (nickname && nickname->nickname) {
-                                       if (__ctsvc_safe_strcmp(my_profile->display_name, nickname->nickname)) {
-                                               my_profile->display_name = SAFE_STRDUP(nickname->nickname);
-                                               break;
-                                       }
-                               }
-                       }
-               }
-               else if (my_profile->numbers && my_profile->numbers->records) {
-                       for (cur=my_profile->numbers->records;cur;cur=cur->next) {
-                               ctsvc_number_s *number = (ctsvc_number_s *)cur->data;
-                               if (number && number->number) {
-                                       if (__ctsvc_safe_strcmp(my_profile->display_name, number->number)) {
-                                               my_profile->display_name = SAFE_STRDUP(number->number);
-                                               break;
-                                       }
-                               }
-                       }
-               }
-               else if (my_profile->emails && my_profile->emails->records) {
-                       for (cur=my_profile->emails->records;cur;cur=cur->next) {
-                               ctsvc_email_s *email = (ctsvc_email_s*)cur->data;
-                               if (email && email->email_addr) {
-                                       if (__ctsvc_safe_strcmp(my_profile->display_name, email->email_addr)) {
-                                               my_profile->display_name = SAFE_STRDUP(email->email_addr);
-                                               break;
-                                       }
-                               }
-                       }
-               }
-       }
-       return;
-}
-
 static inline int __ctsvc_my_profile_update_data(ctsvc_my_profile_s *my_profile)
 {
        int ret;
@@ -491,6 +393,153 @@ static void __ctsvc_my_profile_check_default_data(ctsvc_my_profile_s *my_profile
        ctsvc_contact_check_default_image((contacts_list_h)my_profile->images);
 }
 
+static void __ctsvc_make_my_profile_display_name(ctsvc_my_profile_s *my_profile)
+{
+       char *display = NULL;
+       GList *cur;
+       int len, display_len;
+
+       ctsvc_name_s *name = NULL;
+
+       free(my_profile->display_name);
+       my_profile->display_name = NULL;
+
+       free(my_profile->reverse_display_name);
+       my_profile->reverse_display_name = NULL;
+
+       if (my_profile->name->count > 0 && my_profile->name->records != NULL && my_profile->name->records->data != NULL) {
+               name = (ctsvc_name_s *)my_profile->name->records->data;
+       }
+
+       if (name && (name->first || name->last)) {
+               // make 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;
+               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);
+               }
+
+               my_profile->display_name = display;
+
+               // 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 (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->suffix) {
+                       if (*display)
+                               len += snprintf(display + len, display_len - len, " ");
+                       len += snprintf(display + len, display_len - len, "%s", name->suffix);
+               }
+
+               my_profile->reverse_display_name = display;
+       }
+       else {
+               if (my_profile->company && my_profile->company->records) {
+                       for (cur=my_profile->company->records;cur;cur=cur->next) {
+                               ctsvc_company_s *company = (ctsvc_company_s *)cur->data;
+                               if (company && company->name) {
+                                       my_profile->display_name_changed = true;
+                                       my_profile->display_name = SAFE_STRDUP(company->name);
+                                       break;
+                               }
+                       }
+               }
+
+               if (!my_profile->display_name_changed && my_profile->nicknames && my_profile->nicknames->records) {
+                       for (cur=my_profile->nicknames->records;cur;cur=cur->next) {
+                               ctsvc_nickname_s *nickname = (ctsvc_nickname_s *)cur->data;
+                               if (nickname && nickname->nickname) {
+                                       my_profile->display_name_changed = true;
+                                       my_profile->display_name = SAFE_STRDUP(nickname->nickname);
+                                       break;
+                               }
+                       }
+               }
+
+               if (!my_profile->display_name_changed && my_profile->numbers && my_profile->numbers->records) {
+                       for (cur=my_profile->numbers->records;cur;cur=cur->next) {
+                               ctsvc_number_s *number = (ctsvc_number_s *)cur->data;
+                               if (number && number->number) {
+                                       my_profile->display_name_changed = true;
+                                       my_profile->display_name = SAFE_STRDUP(number->number);
+                                       break;
+                               }
+                       }
+               }
+
+               if (!my_profile->display_name_changed && my_profile->emails && my_profile->emails->records) {
+                       for (cur=my_profile->emails->records;cur;cur=cur->next) {
+                               ctsvc_email_s *email = (ctsvc_email_s *)cur->data;
+                               if (email && email->email_addr) {
+                                       my_profile->display_name_changed = true;
+                                       my_profile->display_name = SAFE_STRDUP(email->email_addr);
+                                       break;
+                               }
+                       }
+               }
+
+               if (my_profile->display_name_changed) {
+                       my_profile->reverse_display_name = SAFE_STRDUP(my_profile->display_name);
+               }
+       }
+       return;
+}
+
+
 static int __ctsvc_db_my_profile_update_record( contacts_record_h record )
 {
        int ret, len;
@@ -511,7 +560,7 @@ static int __ctsvc_db_my_profile_update_record( contacts_record_h record )
                return ret;
        }
 
-       __ctsvc_update_my_profile_display_name(my_profile);
+       __ctsvc_make_my_profile_display_name(my_profile);
        __ctsvc_my_profile_check_default_data(my_profile);
 
        //update data
@@ -564,7 +613,7 @@ static int __ctsvc_db_my_profile_update_record( contacts_record_h record )
 
        len = snprintf(query, sizeof(query),
                        "UPDATE "CTS_TABLE_MY_PROFILES" SET changed_ver=%d, changed_time=%d, "
-                               "display_name=?, uid=?, image_thumbnail_path=?",
+                               "display_name=?, reverse_display_name=?, uid=?, image_thumbnail_path=?",
                                ctsvc_get_next_ver(), (int)time(NULL));
        snprintf(query+len, sizeof(query)-len, " WHERE my_profile_id=%d", my_profile->id);
 
@@ -576,10 +625,11 @@ static int __ctsvc_db_my_profile_update_record( contacts_record_h record )
        }
 
        cts_stmt_bind_text(stmt, 1, my_profile->display_name);
+       cts_stmt_bind_text(stmt, 2, my_profile->reverse_display_name);
        if (my_profile->uid)
-               cts_stmt_bind_text(stmt, 2, my_profile->uid);
+               cts_stmt_bind_text(stmt, 3, my_profile->uid);
        if (my_profile->image_thumbnail_path)
-               cts_stmt_bind_text(stmt, 3, my_profile->image_thumbnail_path);
+               cts_stmt_bind_text(stmt, 4, my_profile->image_thumbnail_path);
 
        ret = cts_stmt_step(stmt);
        if (CONTACTS_ERROR_NONE != ret) {
@@ -909,89 +959,6 @@ static int __ctsvc_my_profile_insert_data(ctsvc_my_profile_s *contact)
        return CONTACTS_ERROR_NONE;
 }
 
-void __ctsvc_make_my_profile_display_name(ctsvc_my_profile_s *my_profile)
-{
-       char display[CTS_SQL_MAX_LEN]={0};
-       GList *cur;
-       int len;
-
-       ctsvc_name_s *name = NULL;
-
-       if ( my_profile->name->count > 0 && my_profile->name->records != NULL && my_profile->name->records->data != NULL ) {
-               name = (ctsvc_name_s *)my_profile->name->records->data;
-       }
-
-       if ( name && ( name->first || name->last) ) {
-
-               // make display name
-               len=0;
-               if(name->first)
-                       len += snprintf(display + len, sizeof(display) - len, "%s", name->first);
-
-               if(name->addition) {
-                       if (*display)
-                               len += snprintf(display + len, sizeof(display) - len, " ");
-                       len += snprintf(display + len, sizeof(display) - len, "%s", name->addition);
-               }
-
-               if(name->last) {
-                       if (*display)
-                               len += snprintf(display + len, sizeof(display) - len, " ");
-                       len += snprintf(display + len, sizeof(display) - len, "%s", name->last);
-               }
-
-               if(name->suffix) {
-                       if (*display)
-                               len += snprintf(display + len, sizeof(display) - len, " ");
-                       len += snprintf(display + len, sizeof(display) - len, "%s", name->suffix);
-               }
-
-               my_profile->display_name = strdup(display);
-       }
-       else {
-               if (my_profile->company && my_profile->company->records) {
-                       for (cur=my_profile->company->records;cur;cur=cur->next) {
-                               ctsvc_company_s *company = (ctsvc_company_s *)cur->data;
-                               if (company && company->name) {
-                                       my_profile->display_name = SAFE_STRDUP(company->name);
-                                       break;
-                               }
-                       }
-               }
-
-               if (NULL == my_profile->display_name && my_profile->nicknames->records) {
-                       for (cur=my_profile->nicknames->records;cur;cur=cur->next) {
-                               ctsvc_nickname_s *nickname = (ctsvc_nickname_s *)cur->data;
-                               if (nickname && nickname->nickname) {
-                                       my_profile->display_name = SAFE_STRDUP(nickname->nickname);
-                                       break;
-                               }
-                       }
-               }
-
-               if (NULL == my_profile->display_name && my_profile->numbers->records) {
-                       for (cur=my_profile->numbers->records;cur;cur=cur->next) {
-                               ctsvc_number_s *number = (ctsvc_number_s *)cur->data;
-                               if (number && number->number) {
-                                       my_profile->display_name = SAFE_STRDUP(number->number);
-                                       break;
-                               }
-                       }
-               }
-
-               if (NULL == my_profile->display_name && my_profile->emails->records) {
-                       for (cur=my_profile->emails->records;cur;cur=cur->next) {
-                               ctsvc_email_s *email = (ctsvc_email_s *)cur->data;
-                               if (email && email->email_addr) {
-                                       my_profile->display_name = SAFE_STRDUP(email->email_addr);
-                                       break;
-                               }
-                       }
-               }
-       }
-       return;
-}
-
 static int __ctsvc_db_my_profile_insert_record( contacts_record_h record, int *id)
 {
        CTS_FN_CALL;
@@ -1073,8 +1040,8 @@ static int __ctsvc_db_my_profile_insert_record( contacts_record_h record, int *i
        snprintf(query, sizeof(query),
                "INSERT INTO "CTS_TABLE_MY_PROFILES"(my_profile_id, addressbook_id, "
                        "created_ver, changed_ver, changed_time, "
-                       "display_name, uid, image_thumbnail_path) "
-                       "VALUES(%d, %d, %d, %d, %d, ?, ?, ?)",
+                       "display_name, reverse_display_name, uid, image_thumbnail_path) "
+                       "VALUES(%d, %d, %d, %d, %d, ?, ?, ?, ?)",
                        my_profile->id, my_profile->addressbook_id, version, version, (int)time(NULL));
 
        stmt = cts_query_prepare(query);
@@ -1086,10 +1053,12 @@ static int __ctsvc_db_my_profile_insert_record( contacts_record_h record, int *i
 
        if (my_profile->display_name)
                cts_stmt_bind_text(stmt, 1, my_profile->display_name);
+       if (my_profile->reverse_display_name)
+               cts_stmt_bind_text(stmt, 2, my_profile->reverse_display_name);
        if (my_profile->uid)
-               cts_stmt_bind_text(stmt, 2, my_profile->uid);
+               cts_stmt_bind_text(stmt, 3, my_profile->uid);
        if (my_profile->image_thumbnail_path)
-               cts_stmt_bind_text(stmt, 3, my_profile->image_thumbnail_path);
+               cts_stmt_bind_text(stmt, 4, my_profile->image_thumbnail_path);
 
        ret = cts_stmt_step(stmt);
        if (CONTACTS_ERROR_NONE != ret) {
index 7c6cde0..d4f7421 100644 (file)
@@ -119,7 +119,6 @@ int ctsvc_db_name_insert(contacts_record_h record, int contact_id, bool is_my_pr
        int ret, len = 0;
        cts_stmt stmt = NULL;
        ctsvc_name_s *name = (ctsvc_name_s*)record;
-       char *tmp_first, *tmp_last;
        char query[CTS_SQL_MAX_LEN]={0};
        char *normal_name[CTSVC_NN_MAX]={NULL}; //insert name search info
        char *temp_normal_first = NULL;
@@ -143,9 +142,6 @@ int ctsvc_db_name_insert(contacts_record_h record, int contact_id, bool is_my_pr
                stmt = cts_query_prepare(query);
                RETVM_IF(NULL == stmt, CONTACTS_ERROR_DB, "DB error : cts_query_prepare() Failed");
 
-               tmp_first = name->first;
-               tmp_last = name->last;
-
                ret = __ctsvc_normalize_name(name, normal_name);
                if (ret < CONTACTS_ERROR_NONE) {
                        CTS_ERR("__ctsvc_normalize_name() Failed(%d)", ret);
@@ -169,14 +165,11 @@ int ctsvc_db_name_insert(contacts_record_h record, int contact_id, bool is_my_pr
                case CTSVC_LANG_ENGLISH:
                default:
                        if (normal_name[CTSVC_NN_FIRST] && normal_name[CTSVC_NN_FIRST][0])
-                               temp_normal_first = normal_name[CTSVC_NN_FIRST];
-                       else
-                               name->first = NULL;
+                               temp_normal_first = SAFE_STRDUP(normal_name[CTSVC_NN_FIRST]);
 
                        if (normal_name[CTSVC_NN_LAST] && normal_name[CTSVC_NN_LAST][0])
-                               temp_normal_last = normal_name[CTSVC_NN_LAST];
-                       else
-                               name->last = NULL;
+                               temp_normal_last = SAFE_STRDUP(normal_name[CTSVC_NN_LAST]);
+
                        break;
                }
 
@@ -188,8 +181,6 @@ int ctsvc_db_name_insert(contacts_record_h record, int contact_id, bool is_my_pr
                else
                        name->language_type = ret;
 
-               name->first = tmp_first;
-               name->last = tmp_last;
 
                __ctsvc_make_name_lookup(CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST,
                                                                        temp_normal_first, temp_normal_last, &name->lookup);
@@ -197,6 +188,8 @@ int ctsvc_db_name_insert(contacts_record_h record, int contact_id, bool is_my_pr
                __ctsvc_make_name_lookup(CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST,
                                                                        temp_normal_first, temp_normal_last, &name->reverse_lookup);
 
+               free(temp_normal_first);
+               free(temp_normal_last);
                free(normal_name[CTSVC_NN_FIRST]);
                free(normal_name[CTSVC_NN_LAST]);
 
index 7e2bd1c..900abcc 100644 (file)
@@ -119,60 +119,6 @@ static int __ctsvc_db_person_get_record( int id, contacts_record_h* out_record )
        return CONTACTS_ERROR_NONE;
 }
 
-static inline int __ctsvc_db_person_set_favorite(int person_id, bool set)
-{
-       int ret;
-       double prio = 0.0;
-       cts_stmt stmt = NULL;
-       char query[CTS_SQL_MIN_LEN] = {0};
-
-       if (set) {
-               snprintf(query, sizeof(query),
-                       "SELECT MAX(favorite_prio) FROM "CTS_TABLE_FAVORITES);
-
-               stmt = cts_query_prepare(query);
-               RETVM_IF(NULL == stmt, CONTACTS_ERROR_DB, "cts_query_prepare() Failed");
-
-               ret = cts_stmt_step(stmt);
-               if (1 /*CTS_TRUE*/ == ret) {
-                       prio = ctsvc_stmt_get_dbl(stmt, 0);
-               }
-               else if (CONTACTS_ERROR_NONE != ret) {
-                       CTS_ERR("cts_stmt_step() Failed(%d)", ret);
-                       cts_stmt_finalize(stmt);
-                       return ret;
-               }
-               cts_stmt_finalize(stmt);
-
-               prio = prio + 1.0;
-               snprintf(query, sizeof(query),
-                       "INSERT OR REPLACE INTO "CTS_TABLE_FAVORITES" values(%d, %f)", person_id, prio);
-       }
-       else {
-               snprintf(query, sizeof(query),
-                       "DELETE FROM "CTS_TABLE_FAVORITES" WHERE person_id = %d", person_id);
-       }
-
-       ret = ctsvc_query_exec(query);
-       if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("cts_query_exec() Failed(%d)", ret);
-               return ret;
-       }
-
-       ret = cts_db_change();
-
-       snprintf(query, sizeof(query),
-                       "UPDATE "CTS_TABLE_CONTACTS" SET is_favorite = %d "
-                               "WHERE person_id=%d AND deleted = 0", set?1:0, person_id);
-       ret = ctsvc_query_exec(query);
-       if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("cts_query_exec() Failed(%d)", ret);
-               return ret;
-       }
-
-       return CONTACTS_ERROR_NONE;
-}
-
 static int __ctsvc_db_person_update_record( contacts_record_h record )
 {
        int ret, i, len;
@@ -241,13 +187,14 @@ static int __ctsvc_db_person_update_record( contacts_record_h record )
        int index_favorite = CTSVC_PROPERTY_PERSON_IS_FAVORITE & 0x000000FF;
        if (person->base.properties_flags &&
                        CTSVC_PROPERTY_FLAG_DIRTY == person->base.properties_flags[index_favorite]) {
-               ret = __ctsvc_db_person_set_favorite(person->person_id, person->is_favorite);
+               ret = ctsvc_db_person_set_favorite(person->person_id, person->is_favorite, true);
                if (CONTACTS_ERROR_NONE != ret) {
                        CTS_ERR("cts_stmt_step() Failed(%d)", ret);
                        ctsvc_end_trans(false);
                        return ret;
                }
                person->base.properties_flags[index_favorite] = 0;
+               ctsvc_set_contact_noti();
        }
 
        do {
@@ -374,6 +321,7 @@ static int __ctsvc_db_person_delete_record( int id )
        int ret, rel_changed;
        int person_id;
        char query[CTS_SQL_MAX_LEN] = {0};
+       int version;
 
        ret = ctsvc_begin_trans();
        RETVM_IF(ret, ret, "DB error : ctsvc_begin_trans() Failed(%d)", ret);
@@ -387,13 +335,14 @@ static int __ctsvc_db_person_delete_record( int id )
                return ret;
        }
 
+       version = ctsvc_get_next_ver();
        snprintf(query, sizeof(query),
                        "UPDATE "CTS_TABLE_GROUPS" SET member_changed_ver=%d "
                                "WHERE group_id IN (SELECT distinct group_id "
                                                                        "FROM "CTS_TABLE_CONTACTS" C, "CTS_TABLE_GROUP_RELATIONS" R "
                                                                        "ON C.contact_id=R.contact_id AND R.deleted = 0 AND C.deleted = 0 "
                                                                        "WHERE person_id = %d)",
-                               ctsvc_get_next_ver(), id);
+                               version, id);
        ret = ctsvc_query_exec(query);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("ctsvc_query_exec() Failed(%d)", ret);
@@ -404,7 +353,9 @@ static int __ctsvc_db_person_delete_record( int id )
        rel_changed = cts_db_change();
 
        // images are deleted by db trigger callback function in ctsvc_db_contact_delete_callback
-       snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_CONTACTS" WHERE person_id = %d", id);
+       snprintf(query, sizeof(query),
+                       "UPDATE "CTS_TABLE_CONTACTS" SET deleted = 1, person_id = 0, changed_ver=%d WHERE person_id = %d",
+                       version, id);
        ret = ctsvc_query_exec(query);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("ctsvc_query_exec() Failed(%d)", ret);
index a0af89d..38174d7 100755 (executable)
@@ -209,6 +209,60 @@ inline static const char* __cts_get_image_filename(const char* src)
        return src+pos;
 }
 
+int ctsvc_db_person_set_favorite(int person_id, bool set, bool propagate)
+{
+       int ret;
+       double prio = 0.0;
+       cts_stmt stmt = NULL;
+       char query[CTS_SQL_MIN_LEN] = {0};
+
+       if (set) {
+               snprintf(query, sizeof(query),
+                       "SELECT MAX(favorite_prio) FROM "CTS_TABLE_FAVORITES);
+
+               stmt = cts_query_prepare(query);
+               RETVM_IF(NULL == stmt, CONTACTS_ERROR_DB, "cts_query_prepare() Failed");
+
+               ret = cts_stmt_step(stmt);
+               if (1 /*CTS_TRUE*/ == ret) {
+                       prio = ctsvc_stmt_get_dbl(stmt, 0);
+               }
+               else if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("cts_stmt_step() Failed(%d)", ret);
+                       cts_stmt_finalize(stmt);
+                       return ret;
+               }
+               cts_stmt_finalize(stmt);
+
+               prio = prio + 1.0;
+               snprintf(query, sizeof(query),
+                       "INSERT OR REPLACE INTO "CTS_TABLE_FAVORITES" values(%d, %f)", person_id, prio);
+       }
+       else {
+               snprintf(query, sizeof(query),
+                       "DELETE FROM "CTS_TABLE_FAVORITES" WHERE person_id = %d", person_id);
+       }
+
+       ret = ctsvc_query_exec(query);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("cts_query_exec() Failed(%d)", ret);
+               return ret;
+       }
+
+       if (propagate) {
+               snprintf(query, sizeof(query),
+                               "UPDATE "CTS_TABLE_CONTACTS" SET is_favorite = %d "
+                                       "WHERE person_id=%d AND deleted = 0", set?1:0, person_id);
+               ret = ctsvc_query_exec(query);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("cts_query_exec() Failed(%d)", ret);
+                       return ret;
+               }
+       }
+
+       return CONTACTS_ERROR_NONE;
+}
+
 int ctsvc_db_insert_person(contacts_record_h record)
 {
        int ret, index;
@@ -240,8 +294,7 @@ int ctsvc_db_insert_person(contacts_record_h record)
 
        if (1 == cts_stmt_step(stmt))
                status = SAFE_STRDUP(ctsvc_stmt_get_text(stmt, 0));
-
-       sqlite3_finalize(stmt);
+       cts_stmt_finalize(stmt);
 
        version = ctsvc_get_next_ver();
        snprintf(query, sizeof(query),
@@ -289,6 +342,15 @@ int ctsvc_db_insert_person(contacts_record_h record)
                return ret;
        }
 
+       // set favorite
+       if (contact->is_favorite) {
+               ret = ctsvc_db_person_set_favorite(index, contact->is_favorite, false);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("cts_stmt_step() Failed(%d)", ret);
+                       return ret;
+               }
+       }
+
        free(status);
        ctsvc_set_person_noti();
 #ifdef _CONTACTS_IPC_SERVER
@@ -399,7 +461,6 @@ static int __ctsvc_get_thumbnail_contact_id(int person_id)
        return contact_id;
 }
 
-
 int ctsvc_db_update_person(contacts_record_h record)
 {
        int ret, i=1, len=0;
@@ -408,6 +469,7 @@ int ctsvc_db_update_person(contacts_record_h record)
        ctsvc_contact_s *contact = (ctsvc_contact_s*)record;
        bool has_phonenumber=false, has_email=false;
        int thumbnail_contact_id = 0;
+       int person_id = 0;
 
        ret = ctsvc_begin_trans();
        RETVM_IF(ret, ret, "ctsvc_begin_trans() Failed(%d)", ret);
@@ -464,8 +526,44 @@ int ctsvc_db_update_person(contacts_record_h record)
                ctsvc_end_trans(false);
                return ret;
        }
-
        cts_stmt_finalize(stmt);
+
+       // update favorite
+       snprintf(query, sizeof(query),
+                       "SELECT person_id FROM "CTS_TABLE_FAVORITES" WHERE person_id =%d ", contact->person_id);
+       ret = ctsvc_query_get_first_int_result(query, &person_id);
+       if (CONTACTS_ERROR_NO_DATA == ret && contact->is_favorite) {
+               ret = ctsvc_db_person_set_favorite(contact->person_id, true, false);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_db_person_set_favorite() Failed(%d)", ret);
+                       ctsvc_end_trans(false);
+                       return ret;
+               }
+       }
+       else if (CONTACTS_ERROR_NONE == ret && !contact->is_favorite) {
+               snprintf(query, sizeof(query),
+                       "SELECT person_id FROM "CTS_TABLE_CONTACTS" WHERE person_id =%d AND is_favorite = 1", contact->person_id);
+               ret = ctsvc_query_get_first_int_result(query, &person_id);
+               if (CONTACTS_ERROR_NO_DATA == ret) {
+                       ret = ctsvc_db_person_set_favorite(contact->person_id, false, false);
+                       if (CONTACTS_ERROR_NONE != ret) {
+                               CTS_ERR("ctsvc_db_person_set_favorite() Failed(%d)", ret);
+                               ctsvc_end_trans(false);
+                               return ret;
+                       }
+               }
+               else if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_query_get_first_int_result() Failed(%d)", ret);
+                       ctsvc_end_trans(false);
+                       return ret;
+               }
+       }
+       else if (ret < CONTACTS_ERROR_NONE && CONTACTS_ERROR_NO_DATA != ret) {
+               CTS_ERR("ctsvc_query_get_first_int_result() Failed(%d)", ret);
+               ctsvc_end_trans(false);
+               return ret;
+       }
+
        ctsvc_set_person_noti();
 
 #ifdef _CONTACTS_IPC_SERVER
index 15ff251..421eed1 100755 (executable)
@@ -29,5 +29,6 @@ int ctsvc_db_person_create_record_from_stmt(cts_stmt stmt, contacts_record_h *re
 int ctsvc_db_person_create_record_from_stmt_with_query(cts_stmt stmt, contacts_query_h query, contacts_record_h *record);
 int ctsvc_db_person_create_record_from_stmt_with_projection(cts_stmt stmt, unsigned int *projection, int projection_count, contacts_record_h *record);
 void ctsvc_db_normalize_str_callback(sqlite3_context * context,        int argc, sqlite3_value ** argv);
+int ctsvc_db_person_set_favorite(int person_id, bool set, bool propagate);
 
 #endif // __CTSVC_DB_PLUGIN_PERSON_HELPER_H__
index ffccdca..53aa584 100644 (file)
@@ -106,8 +106,6 @@ static int __ctsvc_db_simple_contact_get_record( int id, contacts_record_h* out_
 
        RETV_IF(NULL == out_record, CONTACTS_ERROR_INVALID_PARAMETER);
        *out_record = NULL;
-//     if (0 == id)
-//             return ctsvc_get_myprofile(contact);
 
        len = snprintf(query, sizeof(query),
                                "SELECT contact_id, addressbook_id, person_id, changed_time, %s, "
@@ -241,11 +239,11 @@ static int __ctsvc_db_simple_contact_update_record( contacts_record_h record )
 
                if (0 == img_id) {
                        img_id = cts_db_get_next_id(CTS_TABLE_DATA);
-                       ret = ctsvc_contact_add_image_file(CTSVC_IMG_NORMAL, contact->contact_id, img_id, contact->image_thumbnail_path,
+                       ret = ctsvc_contact_add_image_file(contact->contact_id, img_id, contact->image_thumbnail_path,
                                        image, sizeof(image));
                }
                else  {
-                       ret = ctsvc_contact_update_image_file(CTSVC_IMG_NORMAL, contact->contact_id, img_id,
+                       ret = ctsvc_contact_update_image_file(contact->contact_id, img_id,
                                        contact->image_thumbnail_path, image, sizeof(image));
                }
                if (*image) {
@@ -277,38 +275,7 @@ static int __ctsvc_db_simple_contact_update_record( contacts_record_h record )
 
 static int __ctsvc_db_simple_contact_delete_record( int id )
 {
-       int ret;
-       int addressbook_id;
-       char query[CTS_SQL_MAX_LEN] = {0};
-
-       ret = ctsvc_begin_trans();
-       RETVM_IF(ret, ret, "ctsvc_begin_trans() Failed(%d)", ret);
-
-       snprintf(query, sizeof(query),
-               "SELECT addressbook_id FROM "CTS_TABLE_CONTACTS" WHERE contact_id = %d AND deleted = 0", id);
-       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
-       if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("DB error : cts_stmt_step() Failed(%d)", ret);
-               ctsvc_end_trans(false);
-               return ret;
-       }
-
-       snprintf(query, sizeof(query), "DELETE FROM %s WHERE contact_id = %d AND deleted = 0",
-                       CTS_TABLE_CONTACTS, id);
-
-       ret = ctsvc_query_exec(query);
-       if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("cts_query_exec() Failed(%d)", ret);
-               ctsvc_end_trans(false);
-               return ret;
-       }
-
-       ctsvc_set_contact_noti();
-       ret = ctsvc_end_trans(true);
-       if (ret < CONTACTS_ERROR_NONE)
-               return ret;
-       else
-               return CONTACTS_ERROR_NONE;
+       return ctsvc_db_contact_delete(id);
 }
 
 static int __ctsvc_db_simple_contact_get_all_records( int offset, int limit,
@@ -501,7 +468,7 @@ static int __ctsvc_db_simple_contact_insert_record( contacts_record_h record, in
                int image_id;
                image[0] = '\0';
                image_id = __ctsvc_db_simple_contact_get_default_image_id(contact->contact_id);
-               ret = ctsvc_contact_add_image_file(CTSVC_IMG_NORMAL, contact->contact_id, image_id, contact->image_thumbnail_path,
+               ret = ctsvc_contact_add_image_file(contact->contact_id, image_id, contact->image_thumbnail_path,
                                image, sizeof(image));
                if (CONTACTS_ERROR_NONE != ret) {
                        CTS_ERR("ctsvc_contact_add_image_file(NORMAL) Failed(%d)", ret);
@@ -523,11 +490,11 @@ static int __ctsvc_db_simple_contact_insert_record( contacts_record_h record, in
        contact->person_id = ret;
 
        snprintf(query, sizeof(query),
-               "INSERT INTO "CTS_TABLE_CONTACTS"(contact_id, person_id, addressbook_id, is_restricted, "
+               "INSERT INTO "CTS_TABLE_CONTACTS"(contact_id, person_id, addressbook_id, is_favorite, "
                        "created_ver, changed_ver, changed_time, "
                        "uid, ringtone_path, vibration, image_thumbnail_path) "
                        "VALUES(%d, %d, %d, %d, %d, %d, %d, ?, ?, ?, ?)",
-                       contact->contact_id, contact->person_id, contact->addressbook_id, contact->is_restricted,
+                       contact->contact_id, contact->person_id, contact->addressbook_id, contact->is_favorite,
                        version, version, (int)time(NULL));
 
        stmt = cts_query_prepare(query);
index 6727a07..a58ef4a 100755 (executable)
@@ -31,7 +31,6 @@
 #include "ctsvc_record.h"
 #include "ctsvc_utils.h"
 #include "ctsvc_normalize.h"
-#include "ctsvc_restriction.h"
 #include "ctsvc_db_init.h"
 #include "ctsvc_view.h"
 #include "ctsvc_inotify.h"
@@ -1647,31 +1646,39 @@ static int __ctsvc_db_get_contact_changes(const char* view_uri, int addressbook_
 
        if (0 <= addressbook_id) {
                snprintf(query, sizeof(query),
-                       "SELECT %d, contact_id, changed_ver, created_ver, addressbook_id, image_changed_ver FROM %s "
-                       "WHERE changed_ver > %d AND addressbook_id = %d AND deleted = 0 "
+                       "SELECT %d, contact_id, changed_ver, created_ver, addressbook_id, image_changed_ver "
+                                       "FROM "CTS_TABLE_CONTACTS" "
+                                       "WHERE changed_ver > %d AND addressbook_id = %d AND deleted = 0 "
                        "UNION "
-                       "SELECT %d, contact_id, deleted_ver, -1, addressbook_id, 0 FROM %s "
-                       "WHERE deleted_ver > %d AND created_ver <= %d AND addressbook_id = %d "
+                       "SELECT %d, contact_id, deleted_ver, -1, addressbook_id, 0 "
+                                       "FROM "CTS_TABLE_DELETEDS" "
+                                       "WHERE deleted_ver > %d AND created_ver <= %d AND addressbook_id = %d "
                        "UNION "
-                       "SELECT %d, contact_id, changed_ver, -1, addressbook_id, 0 FROM %s "
-                       "WHERE changed_ver > %d AND addressbook_id = %d AND deleted = 1",
-                       CONTACTS_CHANGE_UPDATED, CTS_TABLE_CONTACTS, version, addressbook_id,
-                       CONTACTS_CHANGE_DELETED, CTS_TABLE_DELETEDS, version, version, addressbook_id,
-                       CONTACTS_CHANGE_DELETED, CTS_TABLE_CONTACTS, version, addressbook_id);
+                       "SELECT %d, contact_id, changed_ver, -1, addressbook_id, 0 "
+                                       "FROM "CTS_TABLE_CONTACTS" "
+                                       "WHERE changed_ver > %d AND created_ver <= %d AND addressbook_id = %d AND deleted = 1 "
+                                               "AND addressbook_id = (SELECT addressbook_id FROM "CTS_TABLE_ADDRESSBOOKS" WHERE addressbook_id = %d)",
+                       CONTACTS_CHANGE_UPDATED, version, addressbook_id,
+                       CONTACTS_CHANGE_DELETED, version, version, addressbook_id,
+                       CONTACTS_CHANGE_DELETED, version, version, addressbook_id, addressbook_id);
        }
        else {
                snprintf(query, sizeof(query),
-                       "SELECT %d, contact_id, changed_ver, created_ver, addressbook_id, image_changed_ver FROM %s "
-                       "WHERE changed_ver > %d AND deleted = 0 "
+                       "SELECT %d, contact_id, changed_ver, created_ver, addressbook_id, image_changed_ver "
+                                       "FROM "CTS_TABLE_CONTACTS" "
+                                       "WHERE changed_ver > %d AND deleted = 0 "
                        "UNION "
-                       "SELECT %d, contact_id, deleted_ver, -1, addressbook_id, 0 FROM %s "
-                       "WHERE deleted_ver > %d AND created_ver <= %d "
+                       "SELECT %d, contact_id, deleted_ver, -1, addressbook_id, 0 "
+                                       "FROM "CTS_TABLE_DELETEDS" "
+                                       "WHERE deleted_ver > %d AND created_ver <= %d "
                        "UNION "
-                       "SELECT %d, contact_id, changed_ver, -1, addressbook_id, 0 FROM %s "
-                       "WHERE changed_ver > %d AND deleted = 1",
-                       CONTACTS_CHANGE_UPDATED, CTS_TABLE_CONTACTS, version,
-                       CONTACTS_CHANGE_DELETED, CTS_TABLE_DELETEDS, version, version,
-                       CONTACTS_CHANGE_DELETED, CTS_TABLE_CONTACTS, version);
+                       "SELECT %d, contact_id, changed_ver, -1, "CTS_TABLE_CONTACTS".addressbook_id, 0 "
+                                       "FROM "CTS_TABLE_CONTACTS",  "CTS_TABLE_ADDRESSBOOKS" "
+                                       "WHERE changed_ver > %d AND created_ver <= %d AND deleted = 1 "
+                                               "AND "CTS_TABLE_CONTACTS".addressbook_id = "CTS_TABLE_ADDRESSBOOKS".addressbook_id",
+                       CONTACTS_CHANGE_UPDATED, version,
+                       CONTACTS_CHANGE_DELETED, version, version,
+                       CONTACTS_CHANGE_DELETED, version ,version);
        }
 
        stmt = cts_query_prepare(query);
index ca4e858..07c4c30 100644 (file)
@@ -492,7 +492,8 @@ int ctsvc_person_aggregate(int person_id)
        int link_count;
        int id = 0;
        int account_ids[DISPLAY_ACCOUNT_MAX] = {0};
-       char addressbook_ids[100] = {0};
+       char *addressbook_ids = NULL;
+       int addressbooks_len = 100;
        int name_contact_id = 0;
        int person_name_contact_id = 0;
        int display_name_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_INVALID;
@@ -599,6 +600,8 @@ int ctsvc_person_aggregate(int person_id)
                char *contact_image_thumbnail_path = NULL;
                char *contact_vibration = NULL;
                bool is_favorite = false;
+               char addr[10] = {0};
+               int addr_len = 0;
 
                contact_id = ctsvc_stmt_get_int(stmt, i++);
                addressbook_id = ctsvc_stmt_get_int(stmt, i++);
@@ -635,9 +638,17 @@ int ctsvc_person_aggregate(int person_id)
                                name_contact_id = person_name_contact_id;
                }
 
-               len += snprintf(addressbook_ids + len, sizeof(addressbook_ids)-len, "%d ", addressbook_id );
+               addr_len = snprintf(addr, sizeof(addr), "%d ", addressbook_id);
+               if (NULL == addressbook_ids)
+                       addressbook_ids = calloc(addressbooks_len, sizeof(char));
+               else if (addressbooks_len <= strlen(addressbook_ids)+addr_len) {
+                       addressbooks_len *= 2;
+                       addressbook_ids = realloc(addressbook_ids, addressbooks_len);
+               }
+
+               len += snprintf(addressbook_ids + len, addressbooks_len -len, "%d ", addressbook_id );
 
-               if (contact_image_thumbnail_path && *contact_image_thumbnail_path) {
+               if (!image_thumbnail_path && contact_image_thumbnail_path && *contact_image_thumbnail_path) {
                        temp = __cts_get_image_filename(contact_image_thumbnail_path);
                        image_thumbnail_path = SAFE_STRDUP(temp);
                        // update data table : is_primary_default
@@ -673,27 +684,29 @@ int ctsvc_person_aggregate(int person_id)
        stmt = cts_query_prepare(query);
        if (NULL == stmt) {
                ERR("DB error : cts_query_prepare() Failed");
+               free(addressbook_ids);
                free(image_thumbnail_path);
                free(ringtone_path);
                free(vibration);
                return CONTACTS_ERROR_DB;
        }
 
-       cts_stmt_bind_text(stmt, 1, addressbook_ids);
-
-       if(ringtone_path)
+       if (addressbook_ids)
+               cts_stmt_bind_text(stmt, 1, addressbook_ids);
+       if (ringtone_path)
                cts_stmt_bind_text(stmt, 2, ringtone_path);
-       if(vibration)
+       if (vibration)
                cts_stmt_bind_text(stmt, 3, vibration);
-       if(status)
+       if (status)
                cts_stmt_bind_text(stmt, 4, status);
-       if(image_thumbnail_path)
+       if (image_thumbnail_path)
                cts_stmt_bind_text(stmt, 5, image_thumbnail_path);
 
        ret = cts_stmt_step(stmt);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("cts_stmt_step() Failed(%d)", ret);
                cts_stmt_finalize(stmt);
+               free(addressbook_ids);
                free(image_thumbnail_path);
                free(ringtone_path);
                free(vibration);
@@ -702,6 +715,7 @@ int ctsvc_person_aggregate(int person_id)
 
        cts_stmt_finalize(stmt);
 
+       free(addressbook_ids);
        free(image_thumbnail_path);
        free(ringtone_path);
        free(vibration);
diff --git a/native/ctsvc_restriction.c b/native/ctsvc_restriction.c
deleted file mode 100755 (executable)
index bc8f27d..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Contacts Service
- *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Youngjae Shin <yj99.shin@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "contacts.h"
-#include "ctsvc_internal.h"
-#include "ctsvc_sqlite.h"
-#include "ctsvc_schema.h"
-
-static const char *CTS_RESTRICTION_CHECK_FILE="/opt/usr/data/contacts-svc/.CONTACTS_SVC_RESTRICTION_CHECK";
-static TLS int ctsvc_restriction_permit;
-
-int ctsvc_restriction_init(void)
-{
-       if (!ctsvc_restriction_permit) {
-               int fd = open(CTS_RESTRICTION_CHECK_FILE, O_RDONLY);
-               if (0 <= fd) {
-                       close(fd);
-                       ctsvc_restriction_permit = TRUE;
-               } else {
-                       CTS_ERR("Restriction Mode");
-               }
-       }
-       if (!ctsvc_restriction_permit) {
-               int ret;
-               const char *query;
-               query = "CREATE TEMP VIEW "CTS_TABLE_RESTRICTED_DATA_VIEW" AS SELECT * FROM "CTS_TABLE_DATA" WHERE is_restricted != 1 AND is_my_profile = 0";
-
-               ret = ctsvc_query_exec(query);
-               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "cts_query_exec() Failed(%d)", ret);
-       }
-       return CONTACTS_ERROR_NONE;
-}
-
-void ctsvc_restriction_deinit(void)
-{
-       ctsvc_restriction_permit = FALSE;
-}
-
-int ctsvc_restriction_get_permit(void)
-{
-       return ctsvc_restriction_permit;
-}
-#if 0
-/**
- * This function make restricted contact.
- * If process does not have permission for restriction, this function will be failed.
- *
- * @param[in] contact The contacts service struct
- * @return     #CTS_SUCCESS on success, Negative value(#cts_error) on error
- */
-API int contacts_svc_struct_set_restriction(CTSstruct *contact)
-{
-       contact_t *record = (contact_t *)contact;
-
-       RETV_IF(NULL == contact, CTS_ERR_ARG_NULL);
-       RETV_IF(FALSE == ctsvc_restriction_permit, CTS_ERR_ENV_INVALID);
-
-       record->is_restricted = TRUE;
-
-       return CONTACTS_ERROR_NONE;
-}
-#endif
diff --git a/native/ctsvc_restriction.h b/native/ctsvc_restriction.h
deleted file mode 100755 (executable)
index 0e4ac6b..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Contacts Service
- *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Youngjae Shin <yj99.shin@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __TIZEN_SOCIAL_CTSVC_RESTRICTION_H__
-#define __TIZEN_SOCIAL_CTSVC_RESTRICTION_H__
-
-int ctsvc_restriction_init(void);
-void ctsvc_restriction_deinit(void);
-
-int ctsvc_restriction_get_permit(void);
-
-#endif //__TIZEN_SOCIAL_CTSVC_RESTRICTION_H__
-
index 44ebf66..b58e9b8 100755 (executable)
@@ -59,8 +59,6 @@
 #define CTS_TABLE_ACTIVITIES "activities"
 #define CTS_TABLE_ACTIVITY_PHOTOS "activity_photos"
 
-#define CTS_TABLE_RESTRICTED_DATA_VIEW "restricted_data"
-
 // DB views /////////////////////////////////////////////////////////////////////
 #define CTSVC_DB_VIEW_PERSON                                   "view_person"
 #define CTSVC_DB_VIEW_CONTACT                                  "view_contact"
index 5ec43d2..e57ea8f 100644 (file)
@@ -82,31 +82,6 @@ API int contacts_connect2()
        return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_connect_with_flags(unsigned int flags)
-{
-       CTS_FN_CALL;
-       int ret = CONTACTS_ERROR_NONE;
-
-       ret = contacts_connect2();
-       if (ret == CONTACTS_ERROR_NONE)
-               return ret;
-
-       if (flags & CONTACTS_CONNECT_FLAG_RETRY) {
-               int i;
-               int waiting_time = 500;
-               for (i=0;i<7;i++) {
-                       usleep(waiting_time * 1000);
-                       DBG("retry cnt=%d, ret=%x, %d",(i+1), ret, waiting_time);
-                       ret = contacts_connect2();
-                       if (ret == CONTACTS_ERROR_NONE)
-                               break;
-                       waiting_time *= 2;
-               }
-       }
-
-       return ret;
-}
-
 API int contacts_disconnect2()
 {
        if (1 == thread_connection)
@@ -141,6 +116,34 @@ API int contacts_disconnect2()
        return CONTACTS_ERROR_NONE;
 }
 
+#ifdef _CONTACTS_NATIVE
+API int contacts_connect_with_flags(unsigned int flags)
+{
+       CTS_FN_CALL;
+       int ret = CONTACTS_ERROR_NONE;
+
+       ret = contacts_connect2();
+       if (ret == CONTACTS_ERROR_NONE)
+               return ret;
+
+       if (flags & CONTACTS_CONNECT_FLAG_RETRY) {
+               int i;
+               int waiting_time = 500;
+               for (i=0;i<9;i++) {
+                       usleep(waiting_time * 1000);
+                       DBG("retry cnt=%d, ret=%x, %d",(i+1), ret, waiting_time);
+                       ret = contacts_connect2();
+                       if (ret == CONTACTS_ERROR_NONE)
+                               break;
+                       if (6 < i)
+                               waiting_time += 30000;
+                       else
+                               waiting_time *= 2;
+               }
+       }
+       return ret;
+}
+
 API int contacts_connect_on_thread()
 {
        int ret;
@@ -193,3 +196,5 @@ API int contacts_disconnect_on_thread()
 
        return CONTACTS_ERROR_NONE;
 }
+#endif
+
index 913a57a..9dfff89 100755 (executable)
@@ -208,11 +208,13 @@ cts_stmt cts_query_prepare(char *query) {
                        CTS_ERR("DB error : sqlite3_prepare_v2() Failed(%d, %s)", ret, sqlite3_errmsg(ctsvc_db));
 
                if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
-                       usleep(50*1000); // 50 ms
                        gettimeofday(&now, NULL);
                        timersub(&now, &from, &diff);
                        retry = (diff.tv_sec < 1)? true:false; // retry it during 1 second
-               }
+                       if (retry)
+                               usleep(50*1000); // 50 ms
+               } else
+                       retry = false;
        }while(retry);
 
        return stmt;
@@ -250,11 +252,14 @@ int cts_stmt_step(cts_stmt stmt) {
                        CTS_ERR("DB error : sqlite3_step() Failed(%d, %s)", ret, sqlite3_errmsg(ctsvc_db));
 
                if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
-                       usleep(50*1000); // 50 ms
                        gettimeofday(&now, NULL);
                        timersub(&now, &from, &diff);
                        retry = (diff.tv_sec < 1)? true:false; // retry it during 1 second
+                       if (retry)
+                               usleep(50*1000); // 50 ms
                }
+               else
+                       retry = false;
        }while(retry);
 
        switch (ret) {
index cb20e46..24e407e 100644 (file)
@@ -194,8 +194,7 @@ const char* ctsvc_get_sort_column(void)
                return "display_name_language, reverse_sortkey";
 }
 
-// This function is for MY profile and group image.
-char* ctsvc_get_image(const char *dir, int index, char *dest, int dest_size)
+static char* __ctsvc_get_image(const char *dir, int index, char *dest, int dest_size)
 {
        DIR *dp;
        char *ret_val;
@@ -452,12 +451,13 @@ int ctsvc_copy_image(const char *src, const char *dest)
        return CONTACTS_ERROR_NONE;
 }
 
+// This function is for group image.
 int ctsvc_change_image(const char *dir, int index, const char *path, char *image, int image_len)
 {
        int ret;
        char dest[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
 
-       if (ctsvc_get_image(dir, index, dest, sizeof(dest))) {
+       if (__ctsvc_get_image(dir, index, dest, sizeof(dest))) {
                if (path && 0 == strcmp(dest, path))
                        return CONTACTS_ERROR_NONE;
                ret = unlink(dest);
index c74c425..e9aa273 100644 (file)
@@ -30,7 +30,6 @@ int ctsvc_get_next_ver(void);
 int ctsvc_get_current_version( int* out_current_version );\r
 int ctsvc_get_transaction_ver(void);\r
 \r
-char* ctsvc_get_image(const char *dir, int index, char *dest, int dest_size);\r
 int ctsvc_change_image(const char *dir, int index, const char *path, char *image, int image_len);\r
 int ctsvc_copy_image(const char *src, const char *dest);\r
 \r
index 2221167..6552daa 100644 (file)
@@ -1,6 +1,6 @@
 Name:       contacts-service
 Summary:    Contacts Service
-Version: 0.9.45.3
+Version: 0.9.52.1
 Release:    1
 Group:      TO_BE/FILLED_IN
 License:    Apache-2.0
@@ -83,9 +83,9 @@ 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 100
 
-chown :6016 /opt/usr/data/contacts-svc/.CONTACTS_SVC_RESTRICTION_CHECK
 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
 
 
 %postun -p /sbin/ldconfig
diff --git a/res/.CONTACTS_SVC_RESTRICTION_CHECK b/res/.CONTACTS_SVC_RESTRICTION_CHECK
deleted file mode 100644 (file)
index e69de29..0000000
index 79233e2..5a4875c 100755 (executable)
@@ -76,7 +76,6 @@ CREATE TABLE contacts
        addressbook_id                  INTEGER NOT NULL DEFAULT 0,
        has_phonenumber         INTEGER,
        has_email                       INTEGER,
-       is_restricted                   INTEGER DEFAULT 0,
        is_favorite                     INTEGER DEFAULT 0,
        deleted                         INTEGER DEFAULT 0,
        display_name                    TEXT,
@@ -103,6 +102,11 @@ CREATE INDEX contacts_idx2 ON contacts(person_id);
 CREATE INDEX contacts_idx3 ON contacts(display_name_language, sortkey);
 CREATE INDEX contacts_idx4 ON contacts(display_name_language, reverse_sortkey);
 
+-- There are three case of deleting contact logically
+--   Case 1 : delete contact
+--   Case 2 : delete addressbook
+--   Case 3 : delete person
+-- In all Case, the deleted contacts(deleted=1) are really deleted in the background.
 CREATE TRIGGER trg_contacts_del AFTER DELETE ON contacts
        BEGIN
                DELETE FROM data WHERE contact_id = old.contact_id AND is_my_profile = 0;
@@ -115,12 +119,20 @@ CREATE TRIGGER trg_contacts_del AFTER DELETE ON contacts
                UPDATE persons SET dirty=1 WHERE person_id = old.person_id AND link_count > 1;
        END;
 
+-- It is triggered during really deleting contact in the background (deleted = 1).
+-- Deleted version(changed_ver) is already set when updating deleted field as 1.
 CREATE TRIGGER trg_contacts_del2 AFTER DELETE ON contacts
-       WHEN old.addressbook_id IN (SELECT addressbook_id from addressbooks WHERE addressbook_id = old.addressbook_id)
+       WHEN old.addressbook_id = (SELECT addressbook_id from addressbooks WHERE addressbook_id = old.addressbook_id) AND old.deleted = 1
        BEGIN
-               INSERT INTO contact_deleteds VALUES(old.contact_id, old.addressbook_id, old.created_ver, (SELECT ver FROM cts_version) + 1);
+               INSERT INTO contact_deleteds VALUES(old.contact_id, old.addressbook_id, old.created_ver, old.changed_ver);
        END;
 
+-- CREATE TRIGGER trg_contacts_del3 AFTER DELETE ON contacts
+--     WHEN old.addressbook_id = (SELECT addressbook_id from addressbooks WHERE addressbook_id = old.addressbook_id) AND old.deleted = 0
+--     BEGIN
+--             INSERT INTO contact_deleteds VALUES(old.contact_id, old.addressbook_id, old.created_ver, (SELECT ver FROM cts_version) + 1);
+--     END;
+
 CREATE TRIGGER trg_contacts_update AFTER UPDATE ON contacts
        WHEN new.deleted = 1
        BEGIN
@@ -408,6 +420,7 @@ CREATE TABLE my_profiles
        my_profile_id                   INTEGER PRIMARY KEY AUTOINCREMENT,
        addressbook_id                  INTEGER NOT NULL DEFAULT 0,
        display_name                    TEXT,
+       reverse_display_name            TEXT,
        created_ver                     INTEGER NOT NULL,
        changed_ver                     INTEGER NOT NULL,
        changed_time                    INTEGER NOT NULL,
index c752343..144fa1c 100755 (executable)
@@ -134,7 +134,6 @@ SET(SRCS
 
        ${CMAKE_SOURCE_DIR}/native/ctsvc_person.c
        ${CMAKE_SOURCE_DIR}/native/ctsvc_phonelog.c
-       ${CMAKE_SOURCE_DIR}/native/ctsvc_restriction.c
        ${CMAKE_SOURCE_DIR}/native/ctsvc_service.c
        ${CMAKE_SOURCE_DIR}/native/ctsvc_sqlite.c
        ${CMAKE_SOURCE_DIR}/native/ctsvc_utils.c
index eefa170..7416328 100644 (file)
@@ -366,18 +366,31 @@ void ctsvc_server_bg_delete_start()
        g_cond_signal(&__ctsvc_server_bg_delete_cond);\r
 }\r
 \r
-void __ctsvc_server_addressbook_deleted_cb(const char *view_uri, void *data)\r
+static void __ctsvc_server_addressbook_deleted_cb(const char *view_uri, void *data)
 {\r
        ctsvc_server_bg_delete_start();\r
 }\r
 \r
-int ctsvc_server_bg_add_cb()\r
+static void __ctsvc_server_contact_deleted_cb(const char *view_uri, void *data)
 {\r
-       return contacts_db_add_changed_cb(_contacts_address_book._uri, __ctsvc_server_addressbook_deleted_cb, NULL);\r
+       ctsvc_server_bg_delete_start();
 }\r
 \r
-int ctsvc_server_bg_remove_cb()\r
+void ctsvc_server_bg_add_cb()
 {\r
-       return contacts_db_remove_changed_cb(_contacts_address_book._uri, __ctsvc_server_addressbook_deleted_cb, NULL);\r
+       int ret;
+       ret = contacts_db_add_changed_cb(_contacts_address_book._uri, __ctsvc_server_addressbook_deleted_cb, NULL);
+       SERVER_DBG("call contacts_db_add_changed_cb (_contacts_address_book)  : return (%d)", ret);
+       ret = contacts_db_add_changed_cb(_contacts_contact._uri, __ctsvc_server_contact_deleted_cb, NULL);
+       SERVER_DBG("call contacts_db_add_changed_cb (_contacts_contact): return (%d)", ret);
+}
+
+void ctsvc_server_bg_remove_cb()
+{
+       int ret;
+       ret = contacts_db_remove_changed_cb(_contacts_address_book._uri, __ctsvc_server_addressbook_deleted_cb, NULL);
+       SERVER_DBG("call contacts_db_remove_changed_cb (_contacts_address_book): return (%d)", ret);
+       ret = contacts_db_remove_changed_cb(_contacts_contact._uri, __ctsvc_server_contact_deleted_cb, NULL);
+       SERVER_DBG("call contacts_db_remove_changed_cb (_contacts_contact) : return (%d)", ret);
 }\r
 \r
index 9ad1064..bbc51ee 100644 (file)
@@ -21,7 +21,7 @@
 #define __CTSVC_SERVER_BG_H__\r
 \r
 void ctsvc_server_bg_delete_start();\r
-int ctsvc_server_bg_add_cb();\r
-int ctsvc_server_bg_remove_cb();\r
+void ctsvc_server_bg_add_cb();\r
+void ctsvc_server_bg_remove_cb();\r
 \r
 #endif /* __CTSVC_SERVER_BG_H__ */\r
index e30537a..4167bf5 100755 (executable)
@@ -59,7 +59,6 @@ typedef struct {
        unsigned int (*get_index_max)(void *);
        unsigned int (*get_text_max)(void *);
        unsigned int (*get_unused_count)(void *);
-       void (*increase_used_count)(void *);
        void (*set)(void *,int ,int ,int );
 }sim_file_s;
 
@@ -82,11 +81,6 @@ static inline unsigned int get_text_max(void *this)
        return ((sim_file_s*)this)->text_max;
 }
 
-static inline void increase_used_count(void *this)
-{
-       ((sim_file_s*)this)->used_count++;
-}
-
 static inline void set(void *this,int index,int text,int used_count)
 {
        ((sim_file_s*)this)->index_max = index;
@@ -131,7 +125,6 @@ static void __ctsvc_server_init_sim_file(void)
                gfile_record[i].get_unused_count = get_unused_count;
                gfile_record[i].get_text_max = get_text_max;
                gfile_record[i].set = set;
-               gfile_record[i].increase_used_count = increase_used_count;
                gfile_record[i].index_max = 0;
                gfile_record[i].text_max = 0;
                gfile_record[i].used_count = 0;