summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonghee Ye <donghee.ye@samsung.com>2013-04-16 23:06:46 +0900
committerDonghee Ye <donghee.ye@samsung.com>2013-04-16 23:06:46 +0900
commit98a1bb5c5e2bd1b5ea69395b9ff0e66270b52379 (patch)
tree2dc21270fed1a5fa005b8d4cd02394df84ce4cf4
parenta808165200ba247c5af56f5f3603543812380a61 (diff)
downloadcontacts-service-98a1bb5c5e2bd1b5ea69395b9ff0e66270b52379.tar.gz
contacts-service-98a1bb5c5e2bd1b5ea69395b9ff0e66270b52379.tar.bz2
contacts-service-98a1bb5c5e2bd1b5ea69395b9ff0e66270b52379.zip
Update version 0.9.66
- Fix : set default value of out- param value - Fix search query by keyword - Fix sorting order for japanese - Fix : special char on __ctsvc_contact_refresh_lookup_data - Fix : person changed info when changing default property - Fix make_vcard error - Add link_mode of contact Change-Id: I29cc6e952efbcfb1ffbd81e0531fa273be424ec3
-rwxr-xr-xCMakeLists.txt2
-rw-r--r--client/ctsvc_client_db.c17
-rw-r--r--common/ctsvc_record_contact.c7
-rw-r--r--common/ctsvc_struct.h1
-rw-r--r--common/ctsvc_vcard.c9
-rw-r--r--common/ctsvc_view.c2
-rw-r--r--common/ctsvc_view.h1
-rw-r--r--common/ipc/ctsvc_ipc_contact.c2
-rw-r--r--contacts-service2.manifest4
-rw-r--r--include/contacts.h1
-rw-r--r--include/contacts_types.h5
-rwxr-xr-xinclude/contacts_views.h1
-rw-r--r--native/ctsvc_db_plugin_contact.c88
-rw-r--r--native/ctsvc_db_plugin_contact_helper.c1
-rwxr-xr-xnative/ctsvc_db_query.c76
-rw-r--r--native/ctsvc_person.c16
-rw-r--r--packaging/contacts-service.spec2
-rwxr-xr-xschema.sql1
-rw-r--r--server/ctsvc_server_bg.c744
19 files changed, 525 insertions, 455 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d59252b..542b2c7 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(EXEC_PREFIX "\${prefix}")
SET(INCLUDEDIR "\${prefix}/${DEST_INCLUDE_DIR}")
SET(VERSION_MAJOR 0)
-SET(VERSION "${VERSION_MAJOR}.9.64")
+SET(VERSION "${VERSION_MAJOR}.9.66")
EXECUTE_PROCESS(COMMAND build-util/generator.sh)
diff --git a/client/ctsvc_client_db.c b/client/ctsvc_client_db.c
index faafdaa..f7c8037 100644
--- a/client/ctsvc_client_db.c
+++ b/client/ctsvc_client_db.c
@@ -221,6 +221,7 @@ API int contacts_db_get_record( const char* view_uri, int id, contacts_record_h*
RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
RETVM_IF(id<0,CONTACTS_ERROR_INVALID_PARAMETER,"id<0");
RETVM_IF(out_record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
+ *out_record = NULL;
// make indata
indata = pims_ipc_data_create(0);
@@ -248,7 +249,6 @@ API int contacts_db_get_record( const char* view_uri, int id, contacts_record_h*
{
CTS_ERR("ctsvc_ipc_call failed");
pims_ipc_data_destroy(indata);
- *out_record = NULL;
return CONTACTS_ERROR_IPC;
}
@@ -450,6 +450,7 @@ API int contacts_db_get_all_records( const char* view_uri, int offset, int limit
RETVM_IF(out_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+ *out_list = NULL;
// make indata
indata = pims_ipc_data_create(0);
@@ -484,7 +485,6 @@ API int contacts_db_get_all_records( const char* view_uri, int offset, int limit
{
CTS_ERR("ctsvc_ipc_call failed");
pims_ipc_data_destroy(indata);
- *out_list = NULL;
return CONTACTS_ERROR_IPC;
}
@@ -517,6 +517,7 @@ API int contacts_db_get_records_with_query( contacts_query_h query, int offset,
RETVM_IF(query==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"query is NULL");
RETVM_IF(out_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
+ *out_list = NULL;
// make indata
indata = pims_ipc_data_create(0);
@@ -550,7 +551,6 @@ API int contacts_db_get_records_with_query( contacts_query_h query, int offset,
{
CTS_ERR("ctsvc_ipc_call failed");
pims_ipc_data_destroy(indata);
- *out_list = NULL;
return CONTACTS_ERROR_IPC;
}
@@ -585,6 +585,7 @@ API int contacts_db_get_count( const char* view_uri, int *out_count )
RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
RETVM_IF(out_count==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"count pointer is NULL");
+ *out_count = 0;
// make indata
indata = pims_ipc_data_create(0);
@@ -638,6 +639,8 @@ API int contacts_db_get_count_with_query( contacts_query_h query, int *out_count
pims_ipc_data_h outdata = NULL;
RETVM_IF(query==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is NULL");
+ RETVM_IF(out_count==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"count pointer is NULL");
+ *out_count = 0;
// make indata
indata = pims_ipc_data_create(0);
@@ -1175,7 +1178,7 @@ API int contacts_db_get_changes_by_version(const char* view_uri, int addressbook
RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
RETVM_IF(record_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record_list is NULL");
RETVM_IF(current_contacts_db_version==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"current_contacts_db_version is NULL");
-
+ *record_list = NULL;
// make indata
indata = pims_ipc_data_create(0);
@@ -1209,7 +1212,6 @@ API int contacts_db_get_changes_by_version(const char* view_uri, int addressbook
{
CTS_ERR("ctsvc_ipc_call failed");
pims_ipc_data_destroy(indata);
- *record_list = NULL;
return CONTACTS_ERROR_IPC;
}
@@ -1246,6 +1248,7 @@ API int contacts_db_get_current_version(int* contacts_db_version)
pims_ipc_data_h outdata = NULL;
RETVM_IF(contacts_db_version==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"contacts_db_version is null");
+ *contacts_db_version = 0;
// ipc call
if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_CURRENT_VERSION, NULL, &outdata) != 0)
@@ -1278,6 +1281,7 @@ API int contacts_db_search_records(const char* view_uri, const char *keyword,
RETVM_IF(out_list == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
RETVM_IF(ctsvc_get_ipc_handle() == NULL, CONTACTS_ERROR_IPC, "contacts not connected");
+ *out_list = NULL;
// make indata
indata = pims_ipc_data_create(0);
@@ -1317,7 +1321,6 @@ API int contacts_db_search_records(const char* view_uri, const char *keyword,
{
CTS_ERR("ctsvc_ipc_call failed");
pims_ipc_data_destroy(indata);
- *out_list = NULL;
return CONTACTS_ERROR_IPC;
}
@@ -1353,6 +1356,7 @@ API int contacts_db_search_records_with_query(contacts_query_h query, const char
RETVM_IF(query==NULL, CONTACTS_ERROR_INVALID_PARAMETER, "query is NULL");
RETVM_IF(out_list==NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
RETVM_IF(ctsvc_get_ipc_handle() == NULL, CONTACTS_ERROR_IPC, "contacts not connected");
+ *out_list = NULL;
// make indata
indata = pims_ipc_data_create(0);
@@ -1392,7 +1396,6 @@ API int contacts_db_search_records_with_query(contacts_query_h query, const char
{
CTS_ERR("ctsvc_ipc_call failed");
pims_ipc_data_destroy(indata);
- *out_list = NULL;
return CONTACTS_ERROR_IPC;
}
diff --git a/common/ctsvc_record_contact.c b/common/ctsvc_record_contact.c
index 071b52f..e9aa48b 100644
--- a/common/ctsvc_record_contact.c
+++ b/common/ctsvc_record_contact.c
@@ -1259,6 +1259,9 @@ static int __ctsvc_contact_get_int(contacts_record_h record, unsigned int proper
case CTSVC_PROPERTY_CONTACT_CHANGED_TIME:
*out = contact->changed_time;
break;
+ case CTSVC_PROPERTY_CONTACT_LINK_MODE:
+ *out = contact->link_mode;
+ break;
default:
ASSERT_NOT_REACHED("Invalid parameter : property_id(%d) is not supported in value(contact)", property_id);
return CONTACTS_ERROR_INVALID_PARAMETER;
@@ -1674,6 +1677,9 @@ static int __ctsvc_contact_set_int(contacts_record_h record, unsigned int proper
"Invalid parameter : property_id(%d) is a read-only value (contact)", property_id);
contact->addressbook_id = value;
break;
+ case CTSVC_PROPERTY_CONTACT_LINK_MODE:
+ contact->link_mode = value;
+ break;
default:
CTS_ERR("Invalid parameter : property_id(%d) is not supported in valuecontact)", property_id);
return CONTACTS_ERROR_INVALID_PARAMETER;
@@ -3799,6 +3805,7 @@ static int __ctsvc_contact_clone(contacts_record_h record, contacts_record_h *ou
out_data->person_id = src_data->person_id;
out_data->addressbook_id = src_data->addressbook_id;
out_data->changed_time = src_data->changed_time;
+ out_data->link_mode = src_data->link_mode;
out_data->display_source_type = src_data->display_source_type;
out_data->display_name_language = src_data->display_name_language;
out_data->reverse_display_name_language = src_data->reverse_display_name_language;
diff --git a/common/ctsvc_struct.h b/common/ctsvc_struct.h
index 858ae66..1c71651 100644
--- a/common/ctsvc_struct.h
+++ b/common/ctsvc_struct.h
@@ -488,6 +488,7 @@ typedef struct {
int person_id;
int changed_time;
int addressbook_id;
+ int link_mode;
bool has_phonenumber;
bool has_email;
char *display_name;
diff --git a/common/ctsvc_vcard.c b/common/ctsvc_vcard.c
index eff08d0..ed2afef 100644
--- a/common/ctsvc_vcard.c
+++ b/common/ctsvc_vcard.c
@@ -262,7 +262,7 @@ static inline int __ctsvc_vcard_append_name(ctsvc_list_s *names, char **buf, int
GList *cursor = names->records;
ctsvc_name_s *name;
- RETV_IF(NULL == cursor, 0);
+ RETV_IF(NULL == cursor, len);
name = (ctsvc_name_s *)cursor->data;
@@ -395,10 +395,10 @@ static inline int __ctsvc_vcard_put_company_logo(const char *path, char **buf, i
guchar image[CTSVC_VCARD_PHOTO_MAX_SIZE] = {0};
suffix = strrchr(path, '.');
- RETVM_IF(NULL == suffix, 0, "Image Type(%s) is invalid", path);
+ RETVM_IF(NULL == suffix, len, "Image Type(%s) is invalid", path);
type = __ctsvc_vcard_get_image_type(suffix);
- RETVM_IF(CTSVC_VCARD_IMG_NONE == type, 0, "Invalid parameter : Image Type(%s) is invalid", path);
+ RETVM_IF(CTSVC_VCARD_IMG_NONE == type, len, "Invalid parameter : Image Type(%s) is invalid", path);
fd = open(path, O_RDONLY);
RETVM_IF(fd < 0, CONTACTS_ERROR_SYSTEM, "System : Open(%s) Failed(%d)", path, errno);
@@ -1042,7 +1042,7 @@ static inline int __ctsvc_vcard_put_photo(ctsvc_list_s *image_list, char **buf,
"Invalid parameter : Image Type(%s) is invalid", data->path);
type = __ctsvc_vcard_get_image_type(suffix);
- RETVM_IF(CTSVC_VCARD_IMG_NONE == type, 0, "Invalid parameter : Image Type(%s) is invalid", data->path);
+ RETVM_IF(CTSVC_VCARD_IMG_NONE == type, len, "Invalid parameter : Image Type(%s) is invalid", data->path);
fd = open(data->path, O_RDONLY);
RETVM_IF(fd < 0, CONTACTS_ERROR_SYSTEM, "System : Open(%s) Failed(%d)", data->path, errno);
@@ -1499,7 +1499,6 @@ static int __ctsvc_vcard_append_person(ctsvc_person_s *person, ctsvc_list_s *lis
static int __ctsvc_vcard_make_from_person(ctsvc_person_s *person, ctsvc_list_s *list_contacts,
char **vcard_stream)
{
- int ret = CONTACTS_ERROR_NONE;
char *buf = NULL;
int buf_size = VCARD_INIT_LENGTH;
int len = 0;
diff --git a/common/ctsvc_view.c b/common/ctsvc_view.c
index 58b408c..19f530d 100644
--- a/common/ctsvc_view.c
+++ b/common/ctsvc_view.c
@@ -79,6 +79,7 @@ API const _contacts_contact_property_ids _contacts_contact = {
.uid = CTSVC_PROPERTY_CONTACT_UID,
.vibration = CTSVC_PROPERTY_CONTACT_VIBRATION,
.changed_time = CTSVC_PROPERTY_CONTACT_CHANGED_TIME,
+ .link_mode = CTSVC_PROPERTY_CONTACT_LINK_MODE,
.name = CTSVC_PROPERTY_CONTACT_NAME,
.company = CTSVC_PROPERTY_CONTACT_COMPANY,
.note = CTSVC_PROPERTY_CONTACT_NOTE,
@@ -844,6 +845,7 @@ const property_info_s __property_contact[] = {
{CTSVC_PROPERTY_CONTACT_UID, CTSVC_SEARCH_PROPERTY_ALL, "uid"},
{CTSVC_PROPERTY_CONTACT_VIBRATION, CTSVC_SEARCH_PROPERTY_ALL, "vibration"},
{CTSVC_PROPERTY_CONTACT_CHANGED_TIME, CTSVC_SEARCH_PROPERTY_ALL, "changed_time"},
+ {CTSVC_PROPERTY_CONTACT_LINK_MODE, CTSVC_SEARCH_PROPERTY_ALL, "link_mode"},
{CTSVC_PROPERTY_CONTACT_NAME, CTSVC_SEARCH_PROPERTY_NONE,(void*)__property_name},
{CTSVC_PROPERTY_CONTACT_COMPANY, CTSVC_SEARCH_PROPERTY_NONE,(void*)__property_company},
{CTSVC_PROPERTY_CONTACT_NOTE, CTSVC_SEARCH_PROPERTY_NONE,(void*)__property_note},
diff --git a/common/ctsvc_view.h b/common/ctsvc_view.h
index a7510f1..fdd5846 100644
--- a/common/ctsvc_view.h
+++ b/common/ctsvc_view.h
@@ -211,6 +211,7 @@ typedef enum {
CTSVC_PROPERTY_CONTACT_RELATIONSHIP = (CTSVC_PROPERTY_CONTACT | CTSVC_VIEW_DATA_TYPE_REC) +25,
CTSVC_PROPERTY_CONTACT_GROUP_RELATION = (CTSVC_PROPERTY_CONTACT | CTSVC_VIEW_DATA_TYPE_REC) +26,
CTSVC_PROPERTY_CONTACT_EXTENSION = (CTSVC_PROPERTY_CONTACT | CTSVC_VIEW_DATA_TYPE_REC) +27,
+ CTSVC_PROPERTY_CONTACT_LINK_MODE = (CTSVC_PROPERTY_CONTACT | CTSVC_VIEW_DATA_TYPE_INT) +28,
// my_profile
CTSVC_PROPERTY_MY_PROFILE_ID = (CTSVC_PROPERTY_MY_PROFILE | CTSVC_VIEW_DATA_TYPE_INT | CTSVC_READ_ONLY_PROPERTY),
diff --git a/common/ipc/ctsvc_ipc_contact.c b/common/ipc/ctsvc_ipc_contact.c
index e25599a..9d6f9d3 100644
--- a/common/ipc/ctsvc_ipc_contact.c
+++ b/common/ipc/ctsvc_ipc_contact.c
@@ -28,6 +28,7 @@ static int __ctsvc_ipc_unmarshal_contact(pims_ipc_data_h ipc_data, const char* v
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;
if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->changed_time) != CONTACTS_ERROR_NONE) break;
+ if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->link_mode) != CONTACTS_ERROR_NONE) break;
if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->addressbook_id) != CONTACTS_ERROR_NONE) break;
if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->has_phonenumber) != CONTACTS_ERROR_NONE) break;
if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->has_email) != CONTACTS_ERROR_NONE) break;
@@ -83,6 +84,7 @@ static int __ctsvc_ipc_marshal_contact(const contacts_record_h record, pims_ipc_
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;
if (ctsvc_ipc_marshal_int((pcontact->changed_time),ipc_data) != CONTACTS_ERROR_NONE) break;
+ if (ctsvc_ipc_marshal_int((pcontact->link_mode),ipc_data) != CONTACTS_ERROR_NONE) break;
if (ctsvc_ipc_marshal_int((pcontact->addressbook_id),ipc_data) != CONTACTS_ERROR_NONE) break;
if (ctsvc_ipc_marshal_bool((pcontact->has_phonenumber),ipc_data) != CONTACTS_ERROR_NONE) break;
if (ctsvc_ipc_marshal_bool((pcontact->has_email),ipc_data) != CONTACTS_ERROR_NONE) break;
diff --git a/contacts-service2.manifest b/contacts-service2.manifest
index 7543246..8326f12 100644
--- a/contacts-service2.manifest
+++ b/contacts-service2.manifest
@@ -10,9 +10,9 @@
</request>
</define>
<assign>
- <filesystem path="/usr/lib/libcontacts-service2.so.0.9.64" label="_"/>
+ <filesystem path="/usr/lib/libcontacts-service2.so.0.9.66" label="_"/>
<filesystem path="/usr/lib/libcontacts-service2.so.0" label="_"/>
- <filesystem path="/usr/lib/libcontacts-service3.so.0.9.64" label="_"/>
+ <filesystem path="/usr/lib/libcontacts-service3.so.0.9.66" 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"/>
diff --git a/include/contacts.h b/include/contacts.h
index d9de6cf..9f9b938 100644
--- a/include/contacts.h
+++ b/include/contacts.h
@@ -558,6 +558,7 @@
* <tr><td>string</td><td>uid</td><td>read, write</td><td></td></tr>
* <tr><td>string</td><td>vibration</td><td>read, write</td><td></td></tr>
* <tr><td>integer</td><td>changed_time</td><td>read only</td><td></td></tr>
+ * <tr><td>integer</td><td>link_mode</td><td>read, write</td><td></td></tr>
* <tr><td>record</td><td>name</td><td>read, write</td><td></td></tr>
* <tr><td>record</td><td>company</td><td>read, write</td><td></td></tr>
* <tr><td>record</td><td>note</td><td>read, write</td><td></td></tr>
diff --git a/include/contacts_types.h b/include/contacts_types.h
index 0112176..7d7382a 100644
--- a/include/contacts_types.h
+++ b/include/contacts_types.h
@@ -200,6 +200,11 @@ typedef enum {
CONTACTS_ADDRESS_BOOK_MODE_READONLY, /**< .*/
}contacts_address_book_mode_e;
+typedef enum{
+ CONTACTS_CONTACT_LINK_MODE_NONE, /**< Auto link immediatly */
+ CONTACTS_CONTACT_LINK_MODE_IGNORE_ONCE, /**< Do not auto link when the contact is inserted */
+}contacts_contact_link_mode_e;
+
typedef enum {
CONTACTS_RELATIONSHIP_TYPE_OTHER, /**< .*/
CONTACTS_RELATIONSHIP_TYPE_ASSISTANT, /**< .*/
diff --git a/include/contacts_views.h b/include/contacts_views.h
index c770a5b..7e9632f 100755
--- a/include/contacts_views.h
+++ b/include/contacts_views.h
@@ -102,6 +102,7 @@ _CONTACTS_BEGIN_VIEW()
_CONTACTS_PROPERTY_STR( uid ) // read, write
_CONTACTS_PROPERTY_STR( vibration ) // read, write
_CONTACTS_PROPERTY_INT( changed_time ) // read only
+ _CONTACTS_PROPERTY_INT( link_mode ) // read, write
_CONTACTS_PROPERTY_CHILD_SINGLE( name ) // read, write
_CONTACTS_PROPERTY_CHILD_SINGLE( image ) // read, write
_CONTACTS_PROPERTY_CHILD_MULTIPLE( company ) // read, write
diff --git a/native/ctsvc_db_plugin_contact.c b/native/ctsvc_db_plugin_contact.c
index be785df..8f35617 100644
--- a/native/ctsvc_db_plugin_contact.c
+++ b/native/ctsvc_db_plugin_contact.c
@@ -84,7 +84,7 @@ static int __ctsvc_db_get_contact_base_info(int id, ctsvc_contact_s *contact)
char full_path[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
len = snprintf(query, sizeof(query),
- "SELECT contact_id, addressbook_id, person_id, changed_time, %s, "
+ "SELECT contact_id, addressbook_id, person_id, changed_time, link_mode, %s, "
"display_name_source, image_thumbnail_path, "
"ringtone_path, vibration, uid, is_favorite, has_phonenumber, has_email, "
"sort_name, reverse_sort_name "
@@ -106,6 +106,7 @@ static int __ctsvc_db_get_contact_base_info(int id, ctsvc_contact_s *contact)
contact->addressbook_id = ctsvc_stmt_get_int(stmt, i++);
contact->person_id = ctsvc_stmt_get_int(stmt, i++);
contact->changed_time = ctsvc_stmt_get_int(stmt, i++);
+ contact->link_mode = ctsvc_stmt_get_int(stmt, i++);
temp = ctsvc_stmt_get_text(stmt, i++);
contact->display_name = SAFE_STRDUP(temp);
contact->display_source_type = ctsvc_stmt_get_int(stmt, i++);
@@ -949,6 +950,7 @@ static inline int __ctsvc_contact_refresh_lookup_data(int contact_id)
if (contact->name) {
contacts_list_h name_list = (contacts_list_h)contact->name;
ctsvc_name_s *name_record;
+ cts_stmt stmt = NULL;
char *temp_name = NULL;
contacts_list_first(name_list);
len = 0;
@@ -971,15 +973,29 @@ static inline int __ctsvc_contact_refresh_lookup_data(int contact_id)
ctsvc_normalize_str(temp_name, &normalized_name);
snprintf(query, sizeof(query), "INSERT INTO %s(data_id, contact_id, name, type) "
- "VALUES(%d, %d, '%s', %d)", CTS_TABLE_NAME_LOOKUP, name_record->id,
- contact_id, normalized_name, 0);
+ "VALUES(%d, %d, ?, %d)", CTS_TABLE_NAME_LOOKUP, name_record->id,
+ contact_id, 0);
+
+ stmt = cts_query_prepare(query);
+ if (NULL == stmt) {
+ CTS_ERR("cts_query_prepare() Failed");
+ free(temp_name);
+ free(normalized_name);
+ return CONTACTS_ERROR_DB;
+ }
+
+ if (normalized_name)
+ cts_stmt_bind_text(stmt, 1, normalized_name);
+
+ ret = cts_stmt_step(stmt);
- ret = ctsvc_query_exec(query);
free(temp_name);
free(normalized_name);
+ cts_stmt_finalize(stmt);
+
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("ctsvc_query_exec() Failed(%d)", ret);
+ CTS_ERR("cts_stmt_step() Failed(%d)", ret);
contacts_record_destroy((contacts_record_h)contact, true);
return CONTACTS_ERROR_DB;
}
@@ -989,23 +1005,38 @@ static inline int __ctsvc_contact_refresh_lookup_data(int contact_id)
if (contact->numbers) {
contacts_list_h number_list = (contacts_list_h)contact->numbers;
+ cts_stmt stmt = NULL;
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) {
- char normalized_number[CTSVC_NUMBER_MAX_LEN];
+ char normalized_number[CTSVC_NUMBER_MAX_LEN] = {0};
ctsvc_normalize_number(number_record->number, normalized_number, CTSVC_NUMBER_MAX_LEN, CTSVC_NUMBER_MAX_LEN -1);
snprintf(query, sizeof(query), "INSERT INTO %s(data_id, contact_id, number, min_match) "
- "VALUES(%d, %d, '%s', '%s')", CTS_TABLE_PHONE_LOOKUP, number_record->id,
- contact_id, normalized_number, number_record->lookup);
+ "VALUES(%d, %d, ?, ?)", CTS_TABLE_PHONE_LOOKUP, number_record->id,
+ contact_id);
+
+ stmt = cts_query_prepare(query);
+ if (NULL == stmt) {
+ CTS_ERR("cts_query_prepare() Failed");
+ return CONTACTS_ERROR_DB;
+ }
+
+ if (*normalized_number)
+ cts_stmt_bind_text(stmt, 1, normalized_number);
+
+ if (number_record->lookup)
+ cts_stmt_bind_text(stmt, 2, number_record->lookup);
- ret = ctsvc_query_exec(query);
+ ret = cts_stmt_step(stmt);
+
+ cts_stmt_finalize(stmt);
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("ctsvc_query_exec() Failed(%d)", ret);
+ CTS_ERR("cts_stmt_step() Failed(%d)", ret);
contacts_record_destroy((contacts_record_h)contact, true);
return CONTACTS_ERROR_DB;
}
@@ -1015,6 +1046,7 @@ static inline int __ctsvc_contact_refresh_lookup_data(int contact_id)
if (contact->nicknames) {
contacts_list_h nickname_list = (contacts_list_h)contact->nicknames;
+ cts_stmt stmt = NULL;
ctsvc_nickname_s *nickname;
contacts_list_first(nickname_list);
do {
@@ -1023,14 +1055,27 @@ static inline int __ctsvc_contact_refresh_lookup_data(int contact_id)
char *normalized_nickname = NULL;
ctsvc_normalize_str(nickname->nickname, &normalized_nickname);
snprintf(query, sizeof(query), "INSERT INTO %s(data_id, contact_id, name, type) "
- "VALUES(%d, %d, '%s', %d)", CTS_TABLE_NAME_LOOKUP, nickname->id,
- contact_id, normalized_nickname, 0);
+ "VALUES(%d, %d, ?, %d)", CTS_TABLE_NAME_LOOKUP, nickname->id,
+ contact_id, 0);
+
+ stmt = cts_query_prepare(query);
+ if (NULL == stmt) {
+ CTS_ERR("cts_query_prepare() Failed");
+ free(normalized_nickname);
+ return CONTACTS_ERROR_DB;
+ }
+
+ if (*normalized_nickname)
+ cts_stmt_bind_text(stmt, 1, normalized_nickname);
+
+ ret = cts_stmt_step(stmt);
- ret = ctsvc_query_exec(query);
free(normalized_nickname);
+ cts_stmt_finalize(stmt);
+
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("ctsvc_query_exec() Failed(%d)", ret);
+ CTS_ERR("cts_stmt_step() Failed(%d)", ret);
contacts_record_destroy((contacts_record_h)contact, true);
return CONTACTS_ERROR_DB;
}
@@ -1456,6 +1501,9 @@ static int __ctsvc_db_contact_get_records_with_query( contacts_query_h query, in
case CTSVC_PROPERTY_CONTACT_CHANGED_TIME:
contact->changed_time = ctsvc_stmt_get_int(stmt, i);
break;
+ case CTSVC_PROPERTY_CONTACT_LINK_MODE:
+ contact->link_mode = ctsvc_stmt_get_int(stmt, i);
+ break;
default:
break;
}
@@ -1827,6 +1875,9 @@ static int __ctsvc_db_contact_insert_record( contacts_record_h record, int *id)
RETVM_IF(0 < contact->id, CONTACTS_ERROR_INVALID_PARAMETER,
"Invalid parameter : id(%d), This record is already inserted", contact->id);
+ if (contact->link_mode == CONTACTS_CONTACT_LINK_MODE_IGNORE_ONCE)
+ auto_link_enabled = false;
+
ret = ctsvc_begin_trans();
RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "ctsvc_begin_trans() Failed(%d)", ret);
@@ -1841,7 +1892,6 @@ static int __ctsvc_db_contact_insert_record( contacts_record_h record, int *id)
*id = ret;
ctsvc_make_contact_display_name(contact);
-
__ctsvc_contact_check_default_data(contact);
//Insert Data
@@ -1915,15 +1965,17 @@ 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_favorite, "
- "created_ver, changed_ver, changed_time, image_changed_ver, has_phonenumber, has_email, "
+ "created_ver, changed_ver, changed_time, link_mode, "
+ "image_changed_ver, has_phonenumber, has_email, "
"display_name, reverse_display_name, display_name_source, "
"display_name_language, reverse_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, %d, ?, ?, ?, ?, ?, ?, ?, ?)",
+ "VALUES(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, ?, ?, %d, %d, %d, ?, ?, ?, ?, ?, ?, ?, ?)",
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,
+ version, version, (int)time(NULL), contact->link_mode,
+ (NULL !=contact->image_thumbnail_path)?version:0, contact->has_phonenumber, contact->has_email,
contact->display_source_type, contact->display_name_language, contact->reverse_display_name_language);
stmt = cts_query_prepare(query);
diff --git a/native/ctsvc_db_plugin_contact_helper.c b/native/ctsvc_db_plugin_contact_helper.c
index 95064fc..24c83f4 100644
--- a/native/ctsvc_db_plugin_contact_helper.c
+++ b/native/ctsvc_db_plugin_contact_helper.c
@@ -480,6 +480,7 @@ void ctsvc_make_contact_display_name(ctsvc_contact_s *contact)
contact->display_name_language = ret;
// check reverse sort_name, reverser_display_name_language
+ temp_len = 0;
ret = ctsvc_get_name_sort_type(contact->reverse_display_name);
WARN_IF( ret < 0, "ctsvc_check_language_type Failed(%d)", ret);
switch (ret)
diff --git a/native/ctsvc_db_query.c b/native/ctsvc_db_query.c
index ce655f0..f543484 100755
--- a/native/ctsvc_db_query.c
+++ b/native/ctsvc_db_query.c
@@ -911,12 +911,18 @@ static int __ctsvc_db_append_search_query(const char *keyword, char *query, int
hiragana, hiragana, hiragana);
free(hiragana);
}
- else {
+ else if (CONTACTS_ERROR_NONE <= ret) {
ret = snprintf(query, size,
"(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s* OR number:%s* OR data:%s*') ",
CTS_TABLE_SEARCH_INDEX, CTS_TABLE_SEARCH_INDEX,
normalized_name, keyword, keyword);
}
+ else {
+ ret = snprintf(query, size,
+ "(SELECT contact_id FROM %s WHERE %s MATCH 'name:%s* OR number:%s* OR data:%s*') ",
+ CTS_TABLE_SEARCH_INDEX, CTS_TABLE_SEARCH_INDEX,
+ keyword, keyword, keyword);
+ }
free(normalized_name);
}
@@ -924,7 +930,7 @@ static int __ctsvc_db_append_search_query(const char *keyword, char *query, int
}
static int __ctsvc_db_search_records_exec(const char *view_uri, const property_info_s* properties,
- int ids_count, const char *projection, const char *keyword, int offset, int limit, contacts_list_h* out_list )
+ int ids_count, const char *projection, const char *keyword, int offset, int limit, contacts_list_h* out_list )
{
char query[CTS_SQL_MAX_LEN*8] = {0}; // temporarily extend
const char *table;
@@ -940,52 +946,30 @@ static int __ctsvc_db_search_records_exec(const char *view_uri, const property_i
ret = ctsvc_db_get_table_name(view_uri, &table);
RETVM_IF (CONTACTS_ERROR_NONE != ret, ret, "Invalid parameter : view uri (%s)", view_uri);
- if (CONTACTS_ERROR_NONE <= ret) {
- if (0 == strcmp(view_uri, CTSVC_VIEW_URI_READ_ONLY_PERSON_CONTACT)
- || 0 == strcmp(view_uri, CTSVC_VIEW_URI_READ_ONLY_PERSON_GROUP)) {
- len = snprintf(query, sizeof(query), "SELECT %s FROM %s "
- "WHERE contact_id IN ",
- projection, table);
- len += __ctsvc_db_append_search_query(keyword, query + len, sizeof(query) - len);
- }
- else { // CTSVC_VIEW_URI_PERSON
- len = snprintf(query, sizeof(query), "SELECT %s FROM %s, "
- "(SELECT person_id person_id_in_contact "
- "FROM "CTS_TABLE_CONTACTS " "
- "WHERE deleted = 0 AND contact_id IN ",
- projection, table);
- len += __ctsvc_db_append_search_query(keyword, query + len, sizeof(query) - len);
- len += snprintf(query + len, sizeof(query) - len, " GROUP BY person_id_in_contact) temp_contacts "
- "ON %s.person_id = temp_contacts.person_id_in_contact", table);
- }
-/*
- len += snprintf(query+len, sizeof(query)-len, "FROM %s, %s "
- "LEFT JOIN (SELECT contact_id, person_id person_id_in_contact FROM %s) temp_contacts "
- "ON %s.person_id = temp_contacts.person_id_in_contact AND "
- "temp_contacts.contact_id = %s.contact_id",
- table, CTS_TABLE_SEARCH_INDEX, CTS_TABLE_CONTACTS, table, CTS_TABLE_SEARCH_INDEX);
-*/
-
+ if (0 == strcmp(view_uri, CTSVC_VIEW_URI_READ_ONLY_PERSON_CONTACT)
+ || 0 == strcmp(view_uri, CTSVC_VIEW_URI_READ_ONLY_PERSON_GROUP)) {
+ len = snprintf(query, sizeof(query), "SELECT %s FROM %s "
+ "WHERE contact_id IN ",
+ projection, table);
+ len += __ctsvc_db_append_search_query(keyword, query + len, sizeof(query) - len);
}
- else {
- if (0 == strcmp(view_uri, CTSVC_VIEW_URI_READ_ONLY_PERSON_CONTACT)
- || 0 == strcmp(view_uri, CTSVC_VIEW_URI_READ_ONLY_PERSON_GROUP)) {
- len = snprintf(query, sizeof(query), "SELECT %s FROM %s "
- "WHERE contact_id IN ",
- projection, table);
- len += __ctsvc_db_append_search_query(keyword, query + len, sizeof(query) - len);
- }
- else { // CTSVC_VIEW_URI_PERSON
- len = snprintf(query, sizeof(query),
- "SELECT %s FROM %s, "
- "(SELECT contact_id, person_id person_id_in_contact FROM "CTS_TABLE_CONTACTS") temp_contacts "
- "ON %s.person_id = temp_contacts.person_id_in_contact "
- "AND temp_contacts.deleted = 0 "
- "WHERE temp_contacts.contact_id IN ",
- projection, table, table);
- len += __ctsvc_db_append_search_query(keyword, query + len, sizeof(query) - len);
- }
+ else { // CTSVC_VIEW_URI_PERSON
+ len = snprintf(query, sizeof(query), "SELECT %s FROM %s, "
+ "(SELECT person_id person_id_in_contact "
+ "FROM "CTS_TABLE_CONTACTS " "
+ "WHERE deleted = 0 AND contact_id IN ",
+ projection, table);
+ len += __ctsvc_db_append_search_query(keyword, query + len, sizeof(query) - len);
+ len += snprintf(query + len, sizeof(query) - len, " GROUP BY person_id_in_contact) temp_contacts "
+ "ON %s.person_id = temp_contacts.person_id_in_contact", table);
}
+/*
+ len += snprintf(query+len, sizeof(query)-len, "FROM %s, %s "
+ "LEFT JOIN (SELECT contact_id, person_id person_id_in_contact FROM %s) temp_contacts "
+ "ON %s.person_id = temp_contacts.person_id_in_contact AND "
+ "temp_contacts.contact_id = %s.contact_id",
+ table, CTS_TABLE_SEARCH_INDEX, CTS_TABLE_CONTACTS, table, CTS_TABLE_SEARCH_INDEX);
+*/
if (__ctsvc_db_view_has_display_name(view_uri, properties, ids_count)) {
sortkey = ctsvc_get_sort_column();
diff --git a/native/ctsvc_person.c b/native/ctsvc_person.c
index 3b1e260..39fe10c 100644
--- a/native/ctsvc_person.c
+++ b/native/ctsvc_person.c
@@ -975,6 +975,7 @@ API int contacts_person_unlink_contact(int person_id, int contact_id, int* out_p
{
int ret;
int id;
+ int link_count = 0;
char query[CTS_SQL_MIN_LEN] = {0};
contacts_record_h record = NULL;
bool is_favorite = false;
@@ -990,13 +991,19 @@ API int contacts_person_unlink_contact(int person_id, int contact_id, int* out_p
RETVM_IF(ret, ret, "ctsvc_begin_trans() Failed(%d)", ret);
snprintf(query, sizeof(query),
- "SELECT person_id FROM "CTS_TABLE_PERSONS" WHERE person_id=%d", person_id);
- ret = ctsvc_query_get_first_int_result(query, &id);
+ "SELECT link_count FROM "CTS_TABLE_PERSONS" WHERE person_id=%d", person_id);
+ ret = ctsvc_query_get_first_int_result(query, &link_count);
if (CONTACTS_ERROR_NONE != ret) {
ctsvc_end_trans(false);
return ret;
}
+ if (link_count == 1) {
+ CTS_ERR("This person(%d) has one contact(%d)", person_id, contact_id);
+ ctsvc_end_trans(false);
+ return CONTACTS_ERROR_INVALID_PARAMETER;
+ }
+
ret = contacts_db_get_record(_contacts_contact._uri, contact_id, &record);
if (CONTACTS_ERROR_NONE != ret) {
CTS_ERR("contacts_db_get_record() Failed(%d)", ret);
@@ -1209,7 +1216,7 @@ API int contacts_person_set_default_property(contacts_person_property_e property
}
#ifdef _CONTACTS_IPC_SERVER
- ctsvc_change_subject_add_changed_person_id(CONTACTS_CHANGE_UPDATED, id);
+ ctsvc_change_subject_add_changed_person_id(CONTACTS_CHANGE_UPDATED, person_id);
#endif
ctsvc_set_person_noti();
ret = ctsvc_end_trans(true);
@@ -1223,6 +1230,9 @@ API int contacts_person_get_default_property(contacts_person_property_e property
int ret = CONTACTS_ERROR_NONE;
char query[CTS_SQL_MAX_LEN] = {0};
+ RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
+ *id = 0;
+
switch(property) {
case CONTACTS_PERSON_PROPERTY_NAME_CONTACT:
snprintf(query, sizeof(query),
diff --git a/packaging/contacts-service.spec b/packaging/contacts-service.spec
index 5187d26..aad400d 100644
--- a/packaging/contacts-service.spec
+++ b/packaging/contacts-service.spec
@@ -1,6 +1,6 @@
Name: contacts-service
Summary: Contacts Service
-Version: 0.9.64
+Version: 0.9.66
Release: 1
Group: TO_BE/FILLED_IN
License: Apache-2.0
diff --git a/schema.sql b/schema.sql
index 3a6017a..9ded2a5 100755
--- a/schema.sql
+++ b/schema.sql
@@ -87,6 +87,7 @@ CREATE TABLE contacts
created_ver INTEGER NOT NULL,
changed_ver INTEGER NOT NULL,
changed_time INTEGER NOT NULL,
+ link_mode INTEGER NOT NULL,
image_changed_ver INTEGER NOT NULL,
uid TEXT,
ringtone_path TEXT,
diff --git a/server/ctsvc_server_bg.c b/server/ctsvc_server_bg.c
index 175ab10..c2a2717 100644
--- a/server/ctsvc_server_bg.c
+++ b/server/ctsvc_server_bg.c
@@ -1,388 +1,388 @@
-/*
- * Contact Service
- *
- * Copyright (c) 2000 - 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 <glib.h>
-#include <stdlib.h>
-#include <unistd.h> //sleep
-
+/*
+ * Contact Service
+ *
+ * Copyright (c) 2000 - 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 <glib.h>
+#include <stdlib.h>
+#include <unistd.h> //sleep
+
#include <account.h>
-#include "contacts.h"
-#include "internal.h"
-#include "ctsvc_schema.h"
-#include "ctsvc_sqlite.h"
-#include "ctsvc_server_bg.h"
-#include "ctsvc_utils.h"
+#include "contacts.h"
+#include "internal.h"
+#include "ctsvc_schema.h"
+#include "ctsvc_sqlite.h"
+#include "ctsvc_server_bg.h"
+#include "ctsvc_utils.h"
#include "ctsvc_db_plugin_addressbook_helper.h"
-
-#define CTSVC_SERVER_BG_DELETE_COUNT 50
-#define CTSVC_SERVER_BG_DELETE_STEP_TIME 1
-#define CTSVC_SERVER_BG_DELETE_THREAD "ctsvc_server_bg_delete"
-
-typedef enum
-{
- STEP_1, // get contact_ids
- STEP_2, // delete data
- STEP_3, // delete activity
- STEP_4, // delete search_index, contact(image by trigger)
-} __ctsvc_delete_step_e;
-
-typedef struct {
- GSList *contact_ids;
- int current_contact_id;
- __ctsvc_delete_step_e step;
-} __ctsvc_delete_data_s;
-
-GThread *__ctsvc_server_bg_delete_thread = NULL;
-GCond __ctsvc_server_bg_delete_cond;
-GMutex __ctsvc_server_bg_delete_mutex;
-
+
+#define CTSVC_SERVER_BG_DELETE_COUNT 50
+#define CTSVC_SERVER_BG_DELETE_STEP_TIME 1
+#define CTSVC_SERVER_BG_DELETE_THREAD "ctsvc_server_bg_delete"
+
+typedef enum
+{
+ STEP_1, // get contact_ids
+ STEP_2, // delete data
+ STEP_3, // delete activity
+ STEP_4, // delete search_index, contact(image by trigger)
+} __ctsvc_delete_step_e;
+
+typedef struct {
+ GSList *contact_ids;
+ int current_contact_id;
+ __ctsvc_delete_step_e step;
+} __ctsvc_delete_data_s;
+
+GThread *__ctsvc_server_bg_delete_thread = NULL;
+GCond __ctsvc_server_bg_delete_cond;
+GMutex __ctsvc_server_bg_delete_mutex;
+
account_subscribe_h account = NULL;
-static int __ctsvc_server_bg_contact_delete_step1(__ctsvc_delete_data_s* data)
-{
- char query[CTS_SQL_MIN_LEN] = {0,};
- int ret;
- cts_stmt stmt = NULL;
- int count = 0;
- GSList *cursor;
-
- if (data->contact_ids == NULL){
- // get event_list
- snprintf(query, sizeof(query), "SELECT contact_id FROM "CTS_TABLE_CONTACTS" WHERE deleted = 1");
- stmt = cts_query_prepare(query);
- if (NULL == stmt) {
- ERR("cts_query_prepare() Failed");
- return CONTACTS_ERROR_DB;
- }
-
- while(1 == (ret = cts_stmt_step(stmt))) {
- int id = 0;
- id = ctsvc_stmt_get_int(stmt, 0);
- data->contact_ids = g_slist_append(data->contact_ids, GINT_TO_POINTER(id));
- }
- cts_stmt_finalize(stmt);
+static int __ctsvc_server_bg_contact_delete_step1(__ctsvc_delete_data_s* data)
+{
+ char query[CTS_SQL_MIN_LEN] = {0,};
+ int ret;
+ cts_stmt stmt = NULL;
+ int count = 0;
+ GSList *cursor;
+
+ if (data->contact_ids == NULL){
+ // get event_list
+ snprintf(query, sizeof(query), "SELECT contact_id FROM "CTS_TABLE_CONTACTS" WHERE deleted = 1");
+ stmt = cts_query_prepare(query);
+ if (NULL == stmt) {
+ ERR("cts_query_prepare() Failed");
+ return CONTACTS_ERROR_DB;
+ }
+
+ while(1 == (ret = cts_stmt_step(stmt))) {
+ int id = 0;
+ id = ctsvc_stmt_get_int(stmt, 0);
+ data->contact_ids = g_slist_append(data->contact_ids, GINT_TO_POINTER(id));
+ }
+ cts_stmt_finalize(stmt);
if (ret < CONTACTS_ERROR_NONE)
return ret;
- }
-
- count = g_slist_length(data->contact_ids);
- if (count <= 0)
+ }
+
+ count = g_slist_length(data->contact_ids);
+ if (count <= 0)
+ return CONTACTS_ERROR_NO_DATA;
+
+ cursor = g_slist_nth(data->contact_ids, 0);
+ if (cursor) {
+ data->current_contact_id = GPOINTER_TO_INT(cursor->data);
+ data->contact_ids = g_slist_remove(data->contact_ids, GINT_TO_POINTER(data->current_contact_id));
+
+ return CONTACTS_ERROR_NONE;
+ }
+ else {
return CONTACTS_ERROR_NO_DATA;
-
- cursor = g_slist_nth(data->contact_ids, 0);
- if (cursor) {
- data->current_contact_id = GPOINTER_TO_INT(cursor->data);
- data->contact_ids = g_slist_remove(data->contact_ids, GINT_TO_POINTER(data->current_contact_id));
-
- return CONTACTS_ERROR_NONE;
- }
- else {
- return CONTACTS_ERROR_NO_DATA;
- }
-}
-
-// remove data
-static int __ctsvc_server_bg_contact_delete_step2(__ctsvc_delete_data_s* data)
-{
- SERVER_FN_CALL;
- int ret;
- char query[CTS_SQL_MIN_LEN] = {0};
- GSList *list = NULL;
- cts_stmt stmt = NULL;
- int count = 0;
- GSList *cursor;
-
- // get event_list
- snprintf(query, sizeof(query),
- "SELECT id FROM "CTS_TABLE_DATA" WHERE contact_id = %d LIMIT %d",
- data->current_contact_id, CTSVC_SERVER_BG_DELETE_COUNT);
-
- stmt = cts_query_prepare(query);
- if (NULL == stmt) {
- ERR("cts_query_prepare() Failed");
- return CONTACTS_ERROR_DB;
- }
-
- while(1 == (ret = cts_stmt_step(stmt))) {
- int id = 0;
- id = ctsvc_stmt_get_int(stmt, 0);
- list = g_slist_append(list, GINT_TO_POINTER(id));
- }
- cts_stmt_finalize(stmt);
-
- count = g_slist_length(list);
- if (count <= 0)
- return CONTACTS_ERROR_NO_DATA;
-
- ret = ctsvc_begin_trans();
- h_retvm_if(CONTACTS_ERROR_NONE != ret, CONTACTS_ERROR_DB, "DB failed" );
-
- cursor = g_slist_nth(list, 0);
- while(cursor) {
- int id = GPOINTER_TO_INT(cursor->data);
- snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_DATA" WHERE id = %d", id);
-
- ret = ctsvc_query_exec(query);
- SERVER_DBG("%s",query);
- if (ret != CONTACTS_ERROR_NONE) {
- ERR("DB failed");
- ctsvc_end_trans(false);
- g_slist_free(list);
- return CONTACTS_ERROR_DB;
- }
- cursor = g_slist_next(cursor);
- }
- g_slist_free(list);
- ret = ctsvc_end_trans(true);
-
- return ret;
-}
-
-// remove activities
-static int __ctsvc_server_bg_contact_delete_step3(__ctsvc_delete_data_s* data)
-{
- SERVER_FN_CALL;
-
- int ret;
- char query[CTS_SQL_MIN_LEN] = {0};
- GSList *list = NULL;
- cts_stmt stmt = NULL;
- int count = 0;
- GSList *cursor;
-
- // get event_list
- snprintf(query, sizeof(query),
- "SELECT id FROM "CTS_TABLE_ACTIVITIES" WHERE contact_id = %d LIMIT %d",
- data->current_contact_id, CTSVC_SERVER_BG_DELETE_COUNT);
-
- stmt = cts_query_prepare(query);
- if (NULL == stmt) {
- ERR("cts_query_prepare() Failed");
- return CONTACTS_ERROR_DB;
- }
-
- while(1 == (ret = cts_stmt_step(stmt))) {
- int id = 0;
- id = ctsvc_stmt_get_int(stmt, 0);
- list = g_slist_append(list, GINT_TO_POINTER(id));
- }
- cts_stmt_finalize(stmt);
-
- count = g_slist_length(list);
- if (count <= 0)
- return CONTACTS_ERROR_NO_DATA;
-
- ret = ctsvc_begin_trans();
- h_retvm_if(CONTACTS_ERROR_NONE != ret, CONTACTS_ERROR_DB, "DB failed" );
-
- cursor = g_slist_nth(list, 0);
- while(cursor) {
- int id = GPOINTER_TO_INT(cursor->data);
- snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_ACTIVITIES" WHERE id = %d", id);
-
- ret = ctsvc_query_exec(query);
- SERVER_DBG("%s",query);
- if (ret != CONTACTS_ERROR_NONE) {
- ERR("DB failed");
- ctsvc_end_trans(false);
- g_slist_free(list);
- return CONTACTS_ERROR_DB;
- }
- cursor = g_slist_next(cursor);
- }
- g_slist_free(list);
- ret = ctsvc_end_trans(true);
-
- return ret;
-}
-
-static int __ctsvc_server_bg_contact_delete_step4(__ctsvc_delete_data_s* data)
-{
- int ret;
- char query[CTS_SQL_MIN_LEN] = {0};
-
- ret = ctsvc_begin_trans();
- h_retvm_if(CONTACTS_ERROR_NONE != ret, CONTACTS_ERROR_DB, "DB failed" );
-
- snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_SEARCH_INDEX" WHERE contact_id = %d",
- data->current_contact_id);
- ret = ctsvc_query_exec(query);
- SERVER_DBG("%s",query);
- if (CONTACTS_ERROR_NONE != ret) {
- ERR("DB failed");
- ctsvc_end_trans(false);
- return CONTACTS_ERROR_DB;
- }
-
- snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_CONTACTS" WHERE contact_id = %d",
- data->current_contact_id);
- ret = ctsvc_query_exec(query);
- SERVER_DBG("%s",query);
- if (CONTACTS_ERROR_NONE != ret) {
- ERR("DB failed");
- ctsvc_end_trans(false);
- return CONTACTS_ERROR_DB;
- }
-
- ret = ctsvc_end_trans(true);
- return ret;
-}
-
-static bool __ctsvc_server_bg_contact_delete_step(int ret, __ctsvc_delete_data_s* data)
-{
- if (ret != CONTACTS_ERROR_NONE && ret != CONTACTS_ERROR_NO_DATA) {
+ }
+}
+
+// remove data
+static int __ctsvc_server_bg_contact_delete_step2(__ctsvc_delete_data_s* data)
+{
+ SERVER_FN_CALL;
+ int ret;
+ char query[CTS_SQL_MIN_LEN] = {0};
+ GSList *list = NULL;
+ cts_stmt stmt = NULL;
+ int count = 0;
+ GSList *cursor;
+
+ // get event_list
+ snprintf(query, sizeof(query),
+ "SELECT id FROM "CTS_TABLE_DATA" WHERE contact_id = %d LIMIT %d",
+ data->current_contact_id, CTSVC_SERVER_BG_DELETE_COUNT);
+
+ stmt = cts_query_prepare(query);
+ if (NULL == stmt) {
+ ERR("cts_query_prepare() Failed");
+ return CONTACTS_ERROR_DB;
+ }
+
+ while(1 == (ret = cts_stmt_step(stmt))) {
+ int id = 0;
+ id = ctsvc_stmt_get_int(stmt, 0);
+ list = g_slist_append(list, GINT_TO_POINTER(id));
+ }
+ cts_stmt_finalize(stmt);
+
+ count = g_slist_length(list);
+ if (count <= 0)
+ return CONTACTS_ERROR_NO_DATA;
+
+ ret = ctsvc_begin_trans();
+ h_retvm_if(CONTACTS_ERROR_NONE != ret, CONTACTS_ERROR_DB, "DB failed" );
+
+ cursor = g_slist_nth(list, 0);
+ while(cursor) {
+ int id = GPOINTER_TO_INT(cursor->data);
+ snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_DATA" WHERE id = %d", id);
+
+ ret = ctsvc_query_exec(query);
+ SERVER_DBG("%s",query);
+ if (ret != CONTACTS_ERROR_NONE) {
+ ERR("DB failed");
+ ctsvc_end_trans(false);
+ g_slist_free(list);
+ return CONTACTS_ERROR_DB;
+ }
+ cursor = g_slist_next(cursor);
+ }
+ g_slist_free(list);
+ ret = ctsvc_end_trans(true);
+
+ return ret;
+}
+
+// remove activities
+static int __ctsvc_server_bg_contact_delete_step3(__ctsvc_delete_data_s* data)
+{
+ SERVER_FN_CALL;
+
+ int ret;
+ char query[CTS_SQL_MIN_LEN] = {0};
+ GSList *list = NULL;
+ cts_stmt stmt = NULL;
+ int count = 0;
+ GSList *cursor;
+
+ // get event_list
+ snprintf(query, sizeof(query),
+ "SELECT id FROM "CTS_TABLE_ACTIVITIES" WHERE contact_id = %d LIMIT %d",
+ data->current_contact_id, CTSVC_SERVER_BG_DELETE_COUNT);
+
+ stmt = cts_query_prepare(query);
+ if (NULL == stmt) {
+ ERR("cts_query_prepare() Failed");
+ return CONTACTS_ERROR_DB;
+ }
+
+ while(1 == (ret = cts_stmt_step(stmt))) {
+ int id = 0;
+ id = ctsvc_stmt_get_int(stmt, 0);
+ list = g_slist_append(list, GINT_TO_POINTER(id));
+ }
+ cts_stmt_finalize(stmt);
+
+ count = g_slist_length(list);
+ if (count <= 0)
+ return CONTACTS_ERROR_NO_DATA;
+
+ ret = ctsvc_begin_trans();
+ h_retvm_if(CONTACTS_ERROR_NONE != ret, CONTACTS_ERROR_DB, "DB failed" );
+
+ cursor = g_slist_nth(list, 0);
+ while(cursor) {
+ int id = GPOINTER_TO_INT(cursor->data);
+ snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_ACTIVITIES" WHERE id = %d", id);
+
+ ret = ctsvc_query_exec(query);
+ SERVER_DBG("%s",query);
+ if (ret != CONTACTS_ERROR_NONE) {
+ ERR("DB failed");
+ ctsvc_end_trans(false);
+ g_slist_free(list);
+ return CONTACTS_ERROR_DB;
+ }
+ cursor = g_slist_next(cursor);
+ }
+ g_slist_free(list);
+ ret = ctsvc_end_trans(true);
+
+ return ret;
+}
+
+static int __ctsvc_server_bg_contact_delete_step4(__ctsvc_delete_data_s* data)
+{
+ int ret;
+ char query[CTS_SQL_MIN_LEN] = {0};
+
+ ret = ctsvc_begin_trans();
+ h_retvm_if(CONTACTS_ERROR_NONE != ret, CONTACTS_ERROR_DB, "DB failed" );
+
+ snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_SEARCH_INDEX" WHERE contact_id = %d",
+ data->current_contact_id);
+ ret = ctsvc_query_exec(query);
+ SERVER_DBG("%s",query);
+ if (CONTACTS_ERROR_NONE != ret) {
+ ERR("DB failed");
+ ctsvc_end_trans(false);
+ return CONTACTS_ERROR_DB;
+ }
+
+ snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_CONTACTS" WHERE contact_id = %d",
+ data->current_contact_id);
+ ret = ctsvc_query_exec(query);
+ SERVER_DBG("%s",query);
+ if (CONTACTS_ERROR_NONE != ret) {
+ ERR("DB failed");
+ ctsvc_end_trans(false);
+ return CONTACTS_ERROR_DB;
+ }
+
+ ret = ctsvc_end_trans(true);
+ return ret;
+}
+
+static bool __ctsvc_server_bg_contact_delete_step(int ret, __ctsvc_delete_data_s* data)
+{
+ if (ret != CONTACTS_ERROR_NONE && ret != CONTACTS_ERROR_NO_DATA) {
if(data->contact_ids)
g_slist_free(data->contact_ids);
- ERR("fail (%d)",ret);
- return false;
- }
-
- switch (data->step) {
- case STEP_1:
- if (ret == CONTACTS_ERROR_NO_DATA) {
- if(data->contact_ids)
- g_slist_free(data->contact_ids);
- ERR("step_1 no_data");
- return false;
- }
- data->step = STEP_2;
- break;
- case STEP_2:
- if (ret == CONTACTS_ERROR_NO_DATA)
- data->step = STEP_3;
- break;
- case STEP_3:
- if (ret == CONTACTS_ERROR_NO_DATA)
- data->step = STEP_4;
- break;
- case STEP_4:
- data->step = STEP_1;
- break;
- default:
- data->step = STEP_1;
- break;
- }
-
- return true;
-}
-
-static bool __ctsvc_server_db_delete_run(__ctsvc_delete_data_s* data)
-{
- SERVER_FN_CALL;
- int ret = CONTACTS_ERROR_NONE;
-
- if(data == NULL) {
- ERR("data is NULL");
- return false;
- }
-
- switch (data->step) {
- case STEP_1:
- ret = __ctsvc_server_bg_contact_delete_step1(data);
- break;
- case STEP_2:
- ret = __ctsvc_server_bg_contact_delete_step2(data);
- break;
- case STEP_3:
- ret = __ctsvc_server_bg_contact_delete_step3(data);
- break;
- case STEP_4:
- ret = __ctsvc_server_bg_contact_delete_step4(data);
- break;
- default:
- ERR("invalid step");
- if(data->contact_ids)
- g_slist_free(data->contact_ids);
- return false;
- }
-
- return __ctsvc_server_bg_contact_delete_step(ret, data);
-}
-
-static gpointer __ctsvc_server_bg_delete(gpointer user_data)
-{
- SERVER_FN_CALL;
- int ret;
- __ctsvc_delete_data_s *callback_data = NULL;
-
- while(1) {
- callback_data = calloc(1,sizeof(__ctsvc_delete_data_s));
- if (callback_data == NULL) {
- ERR("calloc fail");
- continue;
- }
- callback_data->step = STEP_1;
-
- ret = contacts_connect2();
- if (CONTACTS_ERROR_NONE != ret) {
+ ERR("fail (%d)",ret);
+ return false;
+ }
+
+ switch (data->step) {
+ case STEP_1:
+ if (ret == CONTACTS_ERROR_NO_DATA) {
+ if(data->contact_ids)
+ g_slist_free(data->contact_ids);
+ ERR("step_1 no_data");
+ return false;
+ }
+ data->step = STEP_2;
+ break;
+ case STEP_2:
+ if (ret == CONTACTS_ERROR_NO_DATA)
+ data->step = STEP_3;
+ break;
+ case STEP_3:
+ if (ret == CONTACTS_ERROR_NO_DATA)
+ data->step = STEP_4;
+ break;
+ case STEP_4:
+ data->step = STEP_1;
+ break;
+ default:
+ data->step = STEP_1;
+ break;
+ }
+
+ return true;
+}
+
+static bool __ctsvc_server_db_delete_run(__ctsvc_delete_data_s* data)
+{
+ SERVER_FN_CALL;
+ int ret = CONTACTS_ERROR_NONE;
+
+ if(data == NULL) {
+ ERR("data is NULL");
+ return false;
+ }
+
+ switch (data->step) {
+ case STEP_1:
+ ret = __ctsvc_server_bg_contact_delete_step1(data);
+ break;
+ case STEP_2:
+ ret = __ctsvc_server_bg_contact_delete_step2(data);
+ break;
+ case STEP_3:
+ ret = __ctsvc_server_bg_contact_delete_step3(data);
+ break;
+ case STEP_4:
+ ret = __ctsvc_server_bg_contact_delete_step4(data);
+ break;
+ default:
+ ERR("invalid step");
+ if(data->contact_ids)
+ g_slist_free(data->contact_ids);
+ return false;
+ }
+
+ return __ctsvc_server_bg_contact_delete_step(ret, data);
+}
+
+static gpointer __ctsvc_server_bg_delete(gpointer user_data)
+{
+ SERVER_FN_CALL;
+ int ret;
+ __ctsvc_delete_data_s *callback_data = NULL;
+
+ while(1) {
+ callback_data = calloc(1,sizeof(__ctsvc_delete_data_s));
+ if (callback_data == NULL) {
+ ERR("calloc fail");
+ continue;
+ }
+ callback_data->step = STEP_1;
+
+ ret = contacts_connect2();
+ if (CONTACTS_ERROR_NONE != ret) {
SERVER_DBG("%d", ret);
free(callback_data);
- continue;
+ continue;
}
-
- while(1) {
- sleep(CTSVC_SERVER_BG_DELETE_STEP_TIME); // sleep 1 sec.
- if (__ctsvc_server_db_delete_run(callback_data) == false) {
- SERVER_DBG("end");
- free(callback_data);
- break;
- }
- }
- ret = contacts_disconnect2();
- if (CONTACTS_ERROR_NONE != ret)
- SERVER_DBG("%d", ret);
-
- g_mutex_lock(&__ctsvc_server_bg_delete_mutex);
- SERVER_DBG("wait");
- g_cond_wait(&__ctsvc_server_bg_delete_cond, &__ctsvc_server_bg_delete_mutex);
- g_mutex_unlock(&__ctsvc_server_bg_delete_mutex);
- }
-
- return NULL;
-}
-
-void ctsvc_server_bg_delete_start()
-{
- SERVER_FN_CALL;
-
- if (__ctsvc_server_bg_delete_thread == NULL) {
- g_mutex_init(&__ctsvc_server_bg_delete_mutex);
- g_cond_init(&__ctsvc_server_bg_delete_cond);
- __ctsvc_server_bg_delete_thread = g_thread_new(CTSVC_SERVER_BG_DELETE_THREAD,
- __ctsvc_server_bg_delete, NULL);
- }
-
- // don't use mutex.
- g_cond_signal(&__ctsvc_server_bg_delete_cond);
-}
-
+
+ while(1) {
+ sleep(CTSVC_SERVER_BG_DELETE_STEP_TIME); // sleep 1 sec.
+ if (__ctsvc_server_db_delete_run(callback_data) == false) {
+ SERVER_DBG("end");
+ free(callback_data);
+ break;
+ }
+ }
+ ret = contacts_disconnect2();
+ if (CONTACTS_ERROR_NONE != ret)
+ SERVER_DBG("%d", ret);
+
+ g_mutex_lock(&__ctsvc_server_bg_delete_mutex);
+ SERVER_DBG("wait");
+ g_cond_wait(&__ctsvc_server_bg_delete_cond, &__ctsvc_server_bg_delete_mutex);
+ g_mutex_unlock(&__ctsvc_server_bg_delete_mutex);
+ }
+
+ return NULL;
+}
+
+void ctsvc_server_bg_delete_start()
+{
+ SERVER_FN_CALL;
+
+ if (__ctsvc_server_bg_delete_thread == NULL) {
+ g_mutex_init(&__ctsvc_server_bg_delete_mutex);
+ g_cond_init(&__ctsvc_server_bg_delete_cond);
+ __ctsvc_server_bg_delete_thread = g_thread_new(CTSVC_SERVER_BG_DELETE_THREAD,
+ __ctsvc_server_bg_delete, NULL);
+ }
+
+ // don't use mutex.
+ g_cond_signal(&__ctsvc_server_bg_delete_cond);
+}
+
static void __ctsvc_server_addressbook_deleted_cb(const char *view_uri, void *data)
-{
- ctsvc_server_bg_delete_start();
-}
-
+{
+ ctsvc_server_bg_delete_start();
+}
+
static void __ctsvc_server_contact_deleted_cb(const char *view_uri, void *data)
-{
+{
ctsvc_server_bg_delete_start();
-}
-
+}
+
static bool __ctsvc_server_account_delete_cb(const char* event_type, int account_id, void* user_data)
{
SERVER_FN_CALL;
@@ -392,7 +392,7 @@ static bool __ctsvc_server_account_delete_cb(const char* event_type, int account
}
void ctsvc_server_bg_add_cb()
-{
+{
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);
@@ -422,5 +422,5 @@ void ctsvc_server_bg_remove_cb()
account_unsubscribe_notification(account); // unsubscirbe & destroy
account = NULL;
}
-}
-
+}
+