add handle 19/47319/2
authorGukhwan Cho <gh78.cho@samsung.com>
Wed, 2 Sep 2015 08:37:05 +0000 (17:37 +0900)
committerGukhwan Cho <gh78.cho@samsung.com>
Thu, 3 Sep 2015 06:21:39 +0000 (15:21 +0900)
Change-Id: I471cc3ef9a59c2ff7df018f31b53eddb48fc4d61
Signed-off-by: Gukhwan Cho <gh78.cho@samsung.com>
87 files changed:
client/CMakeLists.txt [changed mode: 0755->0644]
client/ctsvc_client_activity.c
client/ctsvc_client_activity_helper.c [new file with mode: 0644]
client/ctsvc_client_activity_helper.h [new file with mode: 0644]
client/ctsvc_client_db.c
client/ctsvc_client_db_helper.c [new file with mode: 0644]
client/ctsvc_client_db_helper.h [new file with mode: 0644]
client/ctsvc_client_db_notification.c [moved from common/ctsvc_db_notification.c with 73% similarity]
client/ctsvc_client_group.c
client/ctsvc_client_group_helper.c [new file with mode: 0644]
client/ctsvc_client_group_helper.h [new file with mode: 0644]
client/ctsvc_client_handle.c [new file with mode: 0644]
client/ctsvc_client_handle.h [new file with mode: 0644]
client/ctsvc_client_ipc.c
client/ctsvc_client_ipc.h
client/ctsvc_client_noti.c
client/ctsvc_client_person.c
client/ctsvc_client_person_helper.c [new file with mode: 0644]
client/ctsvc_client_person_helper.h [new file with mode: 0644]
client/ctsvc_client_phonelog.c
client/ctsvc_client_phonelog_helper.c [new file with mode: 0644]
client/ctsvc_client_phonelog_helper.h [new file with mode: 0644]
client/ctsvc_client_service.c
client/ctsvc_client_service_helper.c [new file with mode: 0644]
client/ctsvc_client_service_helper.h [new file with mode: 0644]
client/ctsvc_client_setting.c [changed mode: 0755->0644]
common/ctsvc_handle.c [new file with mode: 0644]
common/ctsvc_handle.h [new file with mode: 0644]
common/ctsvc_inotify.c
common/ctsvc_inotify.h
common/ctsvc_mutex.c
common/ctsvc_mutex.h
common/ctsvc_struct.h
common/ctsvc_vcard.c
common/ipc/ctsvc_ipc_marshal.c
common/ipc/ctsvc_ipc_marshal.h
include/contacts_types.h
server/CMakeLists.txt [changed mode: 0755->0644]
server/ctsvc_ipc_server.c
server/ctsvc_ipc_server2.c
server/ctsvc_localize.c
server/ctsvc_server.c
server/ctsvc_server_activity.c
server/ctsvc_server_activity.h
server/ctsvc_server_bg.c
server/ctsvc_server_change_subject.c
server/ctsvc_server_group.c
server/ctsvc_server_group.h
server/ctsvc_server_person.c
server/ctsvc_server_person.h
server/ctsvc_server_phonelog.c
server/ctsvc_server_phonelog.h
server/ctsvc_server_service.c
server/ctsvc_server_service.h
server/ctsvc_server_setting.c
server/ctsvc_server_setting.h
server/ctsvc_server_sim.c
server/ctsvc_server_socket.c
server/db/ctsvc_db_plugin_activity.c
server/db/ctsvc_db_plugin_address.c
server/db/ctsvc_db_plugin_addressbook.c
server/db/ctsvc_db_plugin_company.c
server/db/ctsvc_db_plugin_contact.c
server/db/ctsvc_db_plugin_email.c
server/db/ctsvc_db_plugin_event.c
server/db/ctsvc_db_plugin_extension.c
server/db/ctsvc_db_plugin_group.c
server/db/ctsvc_db_plugin_grouprelation.c
server/db/ctsvc_db_plugin_image.c
server/db/ctsvc_db_plugin_messenger.c
server/db/ctsvc_db_plugin_my_profile.c
server/db/ctsvc_db_plugin_name.c
server/db/ctsvc_db_plugin_nickname.c
server/db/ctsvc_db_plugin_note.c
server/db/ctsvc_db_plugin_number.c
server/db/ctsvc_db_plugin_person.c
server/db/ctsvc_db_plugin_phonelog.c
server/db/ctsvc_db_plugin_profile.c
server/db/ctsvc_db_plugin_relationship.c
server/db/ctsvc_db_plugin_sdn.c
server/db/ctsvc_db_plugin_simple_contact.c
server/db/ctsvc_db_plugin_speeddial.c
server/db/ctsvc_db_plugin_url.c
server/db/ctsvc_db_query.c
server/db/ctsvc_db_query.h
server/db/ctsvc_db_sqlite.c
server/db/ctsvc_db_utils.c

old mode 100755 (executable)
new mode 100644 (file)
index a4e6bb0..b11e2df
@@ -8,12 +8,21 @@ SET(CLIENT contacts-service2)
 SET(SRCS
        ctsvc_client_activity.c
        ctsvc_client_db.c
+       ctsvc_client_db_notification.c
        ctsvc_client_group.c
        ctsvc_client_person.c
        ctsvc_client_service.c
        ctsvc_client_ipc.c
        ctsvc_client_noti.c
        ctsvc_client_setting.c
+       ctsvc_client_handle.c
+
+       ctsvc_client_service_helper.c
+       ctsvc_client_db_helper.c
+       ctsvc_client_activity_helper.c
+       ctsvc_client_person_helper.c
+       ctsvc_client_group_helper.c
+       ctsvc_client_phonelog_helper.c
 
        ${CMAKE_SOURCE_DIR}/common/ipc/ctsvc_ipc_marshal.c
        ${CMAKE_SOURCE_DIR}/common/ipc/ctsvc_ipc_addressbook.c
@@ -44,7 +53,6 @@ SET(SRCS
        ${CMAKE_SOURCE_DIR}/common/ipc/ctsvc_ipc_extension.c
        ${CMAKE_SOURCE_DIR}/common/ipc/ctsvc_ipc_profile.c
 
-       ${CMAKE_SOURCE_DIR}/common/ctsvc_db_notification.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_filter.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_inotify.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_list.c
@@ -62,6 +70,7 @@ SET(SRCS
        ${CMAKE_SOURCE_DIR}/common/ctsvc_socket.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_vcard.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_view.c
+       ${CMAKE_SOURCE_DIR}/common/ctsvc_handle.c
 
        ${CMAKE_SOURCE_DIR}/common/ipc/ctsvc_ipc_sdn.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_record_sdn.c
index 276cdd2..e555832 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 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.
  *
  */
 
-#include <glib.h>
-#include <pims-ipc-data.h>
-
 #include "contacts.h"
 #include "ctsvc_internal.h"
-#include "ctsvc_ipc_define.h"
-#include "ctsvc_ipc_marshal.h"
-#include "ctsvc_client_ipc.h"
+#include "ctsvc_client_handle.h"
+#include "ctsvc_client_activity_helper.h"
 
 API int contacts_activity_delete_by_contact_id(int contact_id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(contact_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(contact_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
+       int ret;
+       contacts_h contact = NULL;
 
-       // ipc call
-       if (ctsvc_ipc_call(CTSVC_IPC_ACTIVITY_MODULE, CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_CONTACT_ID, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_activity_delete_by_contact_id(contact, contact_id);
 
        return ret;
 }
 
 API int contacts_activity_delete_by_account_id(int account_id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(account_id <= 0,CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
+       int ret;
+       contacts_h contact = 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_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       ret = ctsvc_ipc_marshal_int(account_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_ACTIVITY_MODULE, CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_ACCOUNT_ID, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_activity_delete_by_account_id(contact, account_id);
 
        return ret;
-}
\ No newline at end of file
+}
+
diff --git a/client/ctsvc_client_activity_helper.c b/client/ctsvc_client_activity_helper.c
new file mode 100644 (file)
index 0000000..fd5bb86
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2015 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 <pims-ipc-data.h>
+
+#include "contacts.h"
+#include "ctsvc_internal.h"
+#include "ctsvc_ipc_define.h"
+#include "ctsvc_ipc_marshal.h"
+#include "ctsvc_client_ipc.h"
+
+static const char CONTACTS_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.read";
+static const char CONTACTS_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.write";
+static const char PHONELOG_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.read";
+static const char PHONELOG_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.write";
+
+
+int ctsvc_client_activity_delete_by_contact_id(contacts_h contact, int contact_id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(contact_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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_int(contact_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_ACTIVITY_MODULE, CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_CONTACT_ID, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_activity_delete_by_account_id(contacts_h contact, int account_id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(account_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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_int(account_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_ACTIVITY_MODULE, CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_ACCOUNT_ID, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
diff --git a/client/ctsvc_client_activity_helper.h b/client/ctsvc_client_activity_helper.h
new file mode 100644 (file)
index 0000000..12d50c9
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2015 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.
+ *
+ */
+
+#ifndef __CTSVC_CLIENT_ACTIVITY_HELPER_H__
+#define __CTSVC_CLIENT_ACTIVITY_HELPER_H__
+
+#include "contacts_types.h"
+
+int ctsvc_client_activity_delete_by_contact_id(contacts_h contact, int contact_id);
+int ctsvc_client_activity_delete_by_account_id(contacts_h contact, int account_id);
+
+#endif /* __CTSVC_CLIENT_ACTIVITY_HELPER_H__ */
\ No newline at end of file
index 674083f..27f96bb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact: Dohyung Jin <dh.jin@samsung.com>
  *                 Jongwon Lee <gogosing.lee@samsung.com>
  *
  */
 
-#include <glib.h>
-#include <pims-ipc.h>
-#include <pims-ipc-data.h>
-
 #include "contacts.h"
-#include "contacts_internal.h"
-
 #include "ctsvc_internal.h"
-#include "ctsvc_list.h"
-#include "ctsvc_record.h"
-#include "ctsvc_inotify.h"
-
-#include "ctsvc_ipc_define.h"
-#include "ctsvc_ipc_marshal.h"
-#include "ctsvc_view.h"
-
-#include "ctsvc_client_ipc.h"
-
-#include "ctsvc_mutex.h"
-
+#include "ctsvc_client_handle.h"
+#include "ctsvc_client_db_helper.h"
 
 API int contacts_db_insert_record(contacts_record_h record, int *id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       if (id)
-               *id = 0;
-
-       RETVM_IF(record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is 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_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORD, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-
-                       if (id)
-                               *id = *(int*)pims_ipc_data_get(outdata,&size);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_insert_record(contact, record, id);
 
        return ret;
 }
 
 API int contacts_db_get_record(const char* view_uri, int id, contacts_record_h* out_record)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       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);
-       if (indata == NULL)
-       {
-               CTS_ERR("ipc data created fail!");
-               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_string(view_uri,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(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_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORD, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE)
-               {
-                       ret = ctsvc_ipc_unmarshal_record(outdata,out_record);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_get_record(contact, view_uri, id, out_record);
 
        return ret;
 }
 
 API int contacts_db_update_record(contacts_record_h record)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is 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_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORD, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-               if (CONTACTS_ERROR_NONE == ret) {
-                       CTSVC_RECORD_RESET_PROPERTY_FLAGS((ctsvc_record_s *)record);
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_update_record(contact, record);
 
        return ret;
 }
 
 API int contacts_db_delete_record(const char* view_uri, int id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
-       RETVM_IF(id<=0,CONTACTS_ERROR_INVALID_PARAMETER,"id <= 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_string(view_uri,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(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_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORD, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_delete_record(contact, view_uri, id);
 
        return ret;
 }
 
 API int contacts_db_replace_record(contacts_record_h record, int id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : record is 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;
-       }
-       ret = ctsvc_ipc_marshal_int(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_DB_MODULE,
-                               CTSVC_IPC_SERVER_DB_REPLACE_RECORD, indata, &outdata) != 0) {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata) {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_replace_record(contact, record, id);
 
        return ret;
+
 }
 
 API int contacts_db_get_all_records(const char* view_uri, int offset, int limit, contacts_list_h* out_list)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(out_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
-       *out_list = NULL;
-       RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is 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_string(view_uri,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(offset,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(limit,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_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_ALL_RECORDS, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE)
-               {
-                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
-               }
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_get_all_records(contact, view_uri, offset, limit, out_list);
 
        return ret;
 }
 
 API int contacts_db_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(out_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
-       *out_list = NULL;
-       RETVM_IF(query==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"query is 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_query(query,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(offset,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(limit,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               return ret;
-       }
-
-       // ipc call
-       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORDS_WITH_QUERY, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE)
-               {
-                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_get_records_with_query(contact, query, offset, limit, out_list);
 
        return ret;
 }
 
+
 API int contacts_db_get_count(const char* view_uri, int *out_count)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       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);
-       if (indata == NULL)
-       {
-               CTS_ERR("ipc data created fail!");
-               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_string(view_uri,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_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE)
-               {
-                       ret = ctsvc_ipc_unmarshal_int(outdata,out_count);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_get_count(contact, view_uri, out_count);
 
        return ret;
 }
 
 API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       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;
-
-       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_query(query,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_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT_WITH_QUERY, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE)
-               {
-                       ret = ctsvc_ipc_unmarshal_int(outdata,out_count);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_get_count_with_query(contact, query, out_count);
 
        return ret;
 }
 
 API int contacts_db_insert_records(contacts_list_h list, int **ids, int *count)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       if (ids)
-               *ids = NULL;
-       if (count)
-               *count = 0;
-
-       RETVM_IF(list==NULL,CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
-
-       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_list(list,indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORDS,
-                               indata, &outdata) != 0) {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata) {
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-
-                       if (ids && count) {
-                               int i = 0;
-                               int *id = NULL;
-                               int c;
-                               c = *(int*)pims_ipc_data_get(outdata, &size);
-                               id = calloc(c, sizeof(int));
-                               for(i=0;i<c;i++)
-                                       id[i] = *(int*) pims_ipc_data_get(outdata, &size);
-                               *ids = id;
-                               *count = c;
-                       }
-               }
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_insert_records(contact, list, ids, count);
 
        return ret;
 }
 
 API int contacts_db_update_records(contacts_list_h list)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
-
-       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_list(list,indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORDS,
-                               indata, &outdata) != 0) {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata) {
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_update_records(contact, list);
 
        return ret;
 }
 
 API int contacts_db_delete_records(const char* view_uri, int ids[], int count)
 {
-       int i;
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(view_uri == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "view_uri is NULL");
-
-       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_string(view_uri,indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       ret = ctsvc_ipc_marshal_int(count,indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       for (i=0;i<count;i++) {
-               ret = ctsvc_ipc_marshal_int(ids[i],indata);
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("marshal fail");
-                       pims_ipc_data_destroy(indata);
-                       return ret;
-               }
-       }
-
-       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORDS,
-                               indata, &outdata) != 0) {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata) {
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_delete_records(contact, view_uri, ids, count);
 
        return ret;
 }
 
 API int contacts_db_replace_records(contacts_list_h list, int ids[], int count)
 {
-       int i;
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(NULL == list,CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
-       RETVM_IF(NULL == ids, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
-       RETVM_IF(0 == count, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
-
-       // 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_list(list, indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       ret = ctsvc_ipc_marshal_int(count, indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       for (i=0;i<count;i++) {
-               ret = ctsvc_ipc_marshal_int(ids[i], indata);
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("marshal fail");
-                       pims_ipc_data_destroy(indata);
-                       return ret;
-               }
-       }
-
-       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_REPLACE_RECORDS,
-                               indata, &outdata) != 0) {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata) {
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_replace_records(contact, list, ids, count);
 
        return ret;
 }
@@ -805,177 +200,41 @@ API int contacts_db_replace_records(contacts_list_h list, int ids[], int count)
 API int contacts_db_get_changes_by_version(const char* view_uri, int addressbook_id,
                int contacts_db_version, contacts_list_h* record_list, int* current_contacts_db_version)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(record_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record_list is NULL");
-       *record_list = NULL;
-       RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
-       RETVM_IF(current_contacts_db_version==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"current_contacts_db_version is 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_string(view_uri,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(addressbook_id,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(contacts_db_version,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_DB_MODULE, CTSVC_IPC_SERVER_DB_CHANGES_BY_VERSION, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE)
-               {
-                       ret = ctsvc_ipc_unmarshal_list(outdata,record_list);
-
-                       if (ret == CONTACTS_ERROR_NONE)
-                       {
-                               ret = ctsvc_ipc_unmarshal_int(outdata,current_contacts_db_version);
-                       }
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_get_changes_by_version(contact, view_uri, addressbook_id, contacts_db_version, record_list, current_contacts_db_version);
 
        return ret;
 }
 
 API int contacts_db_get_current_version(int* contacts_db_version)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       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)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               return CONTACTS_ERROR_IPC;
-       }
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-               if (ret == CONTACTS_ERROR_NONE)
-               {
-                       ret = ctsvc_ipc_unmarshal_int(outdata,contacts_db_version);
-               }
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_get_current_version(contact, contacts_db_version);
 
        return ret;
+
 }
 
 API int contacts_db_search_records(const char* view_uri, const char *keyword,
                int offset, int limit, contacts_list_h* out_list)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(out_list == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
-       *out_list = 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_string(view_uri,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_string(keyword,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(offset,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(limit,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_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE)
-               {
-                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_search_records(contact, view_uri, keyword, offset, limit, out_list);
 
        return ret;
 }
@@ -983,209 +242,53 @@ API int contacts_db_search_records(const char* view_uri, const char *keyword,
 API int contacts_db_search_records_with_range(const char* view_uri, const char *keyword,
                int offset, int limit, int range, contacts_list_h* out_list)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(out_list == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
-       *out_list = NULL;
-       RETVM_IF(range == 0, CONTACTS_ERROR_INVALID_PARAMETER, "range is 0");
-
-       indata = pims_ipc_data_create(0);
-       if (indata == NULL) {
-               CTS_ERR("ipc data created fail !");
-               return CONTACTS_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = ctsvc_ipc_marshal_string(view_uri, indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               goto DATA_FREE;
-       }
-       ret = ctsvc_ipc_marshal_string(keyword, indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               goto DATA_FREE;
-       }
-       ret = ctsvc_ipc_marshal_int(offset, indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               goto DATA_FREE;
-       }
-       ret = ctsvc_ipc_marshal_int(limit, indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               goto DATA_FREE;
-       }
-       ret = ctsvc_ipc_marshal_int(range, indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("marshal fail");
-               goto DATA_FREE;
-       }
-
-       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_RANGE, indata, &outdata) != 0) {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata) {
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE)
-                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
 
-       return ret;
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_search_records_with_range(contact, view_uri, keyword, offset, limit, range, out_list);
 
-DATA_FREE:
-       pims_ipc_data_destroy(indata);
        return ret;
 }
 
 API int contacts_db_search_records_with_query(contacts_query_h query, const char *keyword,
                int offset, int limit, contacts_list_h* out_list)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(out_list==NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
-       *out_list = NULL;
-       RETVM_IF(query==NULL, CONTACTS_ERROR_INVALID_PARAMETER, "query is 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_query(query,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_string(keyword,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(offset,indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(limit,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_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_QUERY, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check outdata
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata,&size);
-
-               if (ret == CONTACTS_ERROR_NONE)
-               {
-                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_search_records_with_query(contact, query, keyword, offset, limit, out_list);
 
        return ret;
 }
 
 API int contacts_db_get_last_change_version(int* last_version)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       bool result = false;
+       int ret;
+       contacts_h contact = NULL;
 
-       RETVM_IF(NULL == last_version, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
-       *last_version = 0;
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_CONTACT_READ, &result);
-       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
-       if (result == false) {
-               ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_PHONELOG_READ, &result);
-               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
-               RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied");
-       }
+       ret = ctsvc_client_db_get_last_change_version(contact, last_version);
 
-       *last_version = ctsvc_client_ipc_get_change_version();
        return ret;
 }
 
-typedef struct
+API int contacts_db_get_status(contacts_db_status_e *status)
 {
-       contacts_db_status_changed_cb cb;
-       void *user_data;
-}status_callback_info_s;
+       int ret;
+       contacts_h contact = NULL;
 
-static GSList *__status_change_subscribe_list = NULL;
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-static void __ctsvc_db_status_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
-{
-       int status = -1;
-       unsigned int size = 0;
-       GSList *l;
-
-       if (data)
-               status = *(int*)pims_ipc_data_get(data, &size);
-
-       for (l = __status_change_subscribe_list;l;l=l->next) {
-               status_callback_info_s *cb_info = l->data;
-               if (cb_info->cb)
-                       cb_info->cb(status, cb_info->user_data);
-       }
-}
-
-API int contacts_db_get_status(contacts_db_status_e *status)
-{
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(status == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"The out param is NULL");
-       *status = 0;
-
-       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_STATUS, NULL, &outdata) != 0) {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               return CONTACTS_ERROR_IPC;
-       }
-
-       if (outdata) {
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-               if (CONTACTS_ERROR_NONE == ret) {
-                       *status = *(int*) pims_ipc_data_get(outdata, &size);
-               }
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_db_get_status(contact, status);
 
        return ret;
 }
@@ -1193,54 +296,28 @@ API int contacts_db_get_status(contacts_db_status_e *status)
 API int contacts_db_add_status_changed_cb(
                contacts_db_status_changed_cb cb, void* user_data)
 {
-       status_callback_info_s *cb_info = NULL;
-       RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
-                       "Invalid parameter : callback is null");
-
-       ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
-
-       if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
-                               CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_IPC_SERVER_DB_STATUS_CHANGED,
-                               __ctsvc_db_status_subscriber_callback, NULL) != 0) {
-               CTS_ERR("pims_ipc_subscribe error\n");
-               ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       cb_info = calloc(1, sizeof(status_callback_info_s));
-       cb_info->user_data = user_data;
-       cb_info->cb = cb;
-       __status_change_subscribe_list = g_slist_append(__status_change_subscribe_list, cb_info);
-
-       ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
-       return CONTACTS_ERROR_NONE;
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_add_status_changed_cb(contact, cb, user_data);
+
+       return ret;
 }
 
 API int contacts_db_remove_status_changed_cb(
                contacts_db_status_changed_cb cb, void* user_data)
 {
-       GSList *l;
-
-       RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
-                       "Invalid parameter : callback is null");
-
-       ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
-       for(l = __status_change_subscribe_list;l;l=l->next) {
-               status_callback_info_s *cb_info = l->data;
-               if (cb == cb_info->cb && user_data == cb_info->user_data) {
-                       __status_change_subscribe_list = g_slist_remove(__status_change_subscribe_list, cb_info);
-                       break;
-               }
-       }
-
-       if (g_slist_length(__status_change_subscribe_list) == 0) {
-               pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
-                               CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_IPC_SERVER_DB_STATUS_CHANGED);
-               g_slist_free(__status_change_subscribe_list);
-               __status_change_subscribe_list = NULL;
-       }
-
-       ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
-       return CONTACTS_ERROR_NONE;
+       int ret;
+       contacts_h contact = NULL;
+
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_client_db_remove_status_changed_cb(contact, cb, user_data);
+
+       return ret;
 }
 
diff --git a/client/ctsvc_client_db_helper.c b/client/ctsvc_client_db_helper.c
new file mode 100644 (file)
index 0000000..38a4292
--- /dev/null
@@ -0,0 +1,1371 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Dohyung Jin <dh.jin@samsung.com>
+ *                 Jongwon Lee <gogosing.lee@samsung.com>
+ *                 Donghee Ye <donghee.ye@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 <glib.h>
+#include <pims-ipc.h>
+#include <pims-ipc-data.h>
+
+#include "contacts.h"
+
+#include "ctsvc_internal.h"
+#include "ctsvc_list.h"
+#include "ctsvc_record.h"
+#include "ctsvc_inotify.h"
+#include "ctsvc_ipc_define.h"
+#include "ctsvc_ipc_marshal.h"
+#include "ctsvc_view.h"
+#include "ctsvc_client_ipc.h"
+#include "ctsvc_mutex.h"
+#include "ctsvc_handle.h"
+#include "ctsvc_client_db_helper.h"
+
+int ctsvc_client_db_insert_record(contacts_h contact, contacts_record_h record, int *id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       if (id)
+               *id = 0;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is 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_handle(contact, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               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_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORD, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+
+                       if (id)
+                               *id = *(int*)pims_ipc_data_get(outdata,&size);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_get_record(contacts_h contact, const char* view_uri, int id, contacts_record_h* out_record)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       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);
+       if (indata == NULL) {
+               CTS_ERR("ipc data created fail!");
+               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_handle(contact, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_string(view_uri,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(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_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORD, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE)
+               {
+                       ret = ctsvc_ipc_unmarshal_record(outdata,out_record);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_update_record(contacts_h contact, contacts_record_h record)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(record==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record is 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_handle(contact, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               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_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORD, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+               if (CONTACTS_ERROR_NONE == ret) {
+                       CTSVC_RECORD_RESET_PROPERTY_FLAGS((ctsvc_record_s *)record);
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_delete_record(contacts_h contact, const char* view_uri, int id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+       RETVM_IF(id<=0,CONTACTS_ERROR_INVALID_PARAMETER,"id <= 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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_string(view_uri,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(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_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORD, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_replace_record(contacts_h contact, contacts_record_h record, int id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact,CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : record is 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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               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;
+       }
+       ret = ctsvc_ipc_marshal_int(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_DB_MODULE,
+                               CTSVC_IPC_SERVER_DB_REPLACE_RECORD, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_get_all_records(contacts_h contact, const char* view_uri, int offset, int limit, contacts_list_h* out_list)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(NULL == out_list,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
+       *out_list = NULL;
+       RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is 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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_string(view_uri,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(offset,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(limit,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_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_ALL_RECORDS, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
+               }
+               pims_ipc_data_destroy(outdata);
+       }
+       return ret;
+}
+
+int ctsvc_client_db_get_records_with_query(contacts_h contact, contacts_query_h query, int offset, int limit, contacts_list_h* out_list)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(NULL == out_list,CONTACTS_ERROR_INVALID_PARAMETER,"list is NULL");
+       *out_list = NULL;
+       RETVM_IF(NULL == query,CONTACTS_ERROR_INVALID_PARAMETER,"query is 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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_query(query,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_int(offset,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(limit,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               return ret;
+       }
+
+       /* ipc call */
+       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORDS_WITH_QUERY, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+
+int ctsvc_client_db_get_count(contacts_h contact, const char* view_uri, int *out_count)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       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);
+       if (indata == NULL) {
+               CTS_ERR("ipc data created fail!");
+               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_string(view_uri,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_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       ret = ctsvc_ipc_unmarshal_int(outdata,out_count);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_get_count_with_query(contacts_h contact, contacts_query_h query, int *out_count)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(NULL == query,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);
+       if (indata == NULL) {
+               CTS_ERR("ipc data created fail!");
+               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_query(query,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_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT_WITH_QUERY, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       ret = ctsvc_ipc_unmarshal_int(outdata,out_count);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_insert_records(contacts_h contact, contacts_list_h list, int **ids, int *count)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       if (ids)
+               *ids = NULL;
+       if (count)
+               *count = 0;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(list==NULL,CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
+
+       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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_list(list,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORDS,
+                               indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+
+                       if (ids && count) {
+                               int i = 0;
+                               int *id = NULL;
+                               int c;
+                               c = *(int*)pims_ipc_data_get(outdata, &size);
+                               id = calloc(c, sizeof(int));
+                               for(i=0;i<c;i++)
+                                       id[i] = *(int*) pims_ipc_data_get(outdata, &size);
+                               *ids = id;
+                               *count = c;
+                       }
+               }
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_update_records(contacts_h contact, contacts_list_h list)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contct is NULL");
+       RETVM_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
+
+       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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_list(list,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORDS,
+                               indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_delete_records(contacts_h contact, const char* view_uri, int ids[], int count)
+{
+       int i;
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(view_uri == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "view_uri is NULL");
+
+       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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_string(view_uri,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_int(count,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       for (i=0;i<count;i++) {
+               ret = ctsvc_ipc_marshal_int(ids[i],indata);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("marshal fail");
+                       pims_ipc_data_destroy(indata);
+                       return ret;
+               }
+       }
+
+       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORDS,
+                               indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_replace_records(contacts_h contact, contacts_list_h list, int ids[], int count)
+{
+       int i;
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact,CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(NULL == list,CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
+       RETVM_IF(NULL == ids, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       RETVM_IF(0 == count, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       /* 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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_list(list, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_int(count, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       for (i=0;i<count;i++) {
+               ret = ctsvc_ipc_marshal_int(ids[i], indata);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("marshal fail");
+                       pims_ipc_data_destroy(indata);
+                       return ret;
+               }
+       }
+
+       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_REPLACE_RECORDS,
+                               indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_get_changes_by_version(contacts_h contact, const char* view_uri, int addressbook_id, int contacts_db_version, contacts_list_h* record_list, int* current_contacts_db_version)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(record_list==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"record_list is NULL");
+       *record_list = NULL;
+       RETVM_IF(view_uri==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+       RETVM_IF(current_contacts_db_version==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"current_contacts_db_version is 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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_string(view_uri,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(addressbook_id,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(contacts_db_version,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_DB_MODULE, CTSVC_IPC_SERVER_DB_CHANGES_BY_VERSION, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       ret = ctsvc_ipc_unmarshal_list(outdata,record_list);
+
+                       if (ret == CONTACTS_ERROR_NONE) {
+                               ret = ctsvc_ipc_unmarshal_int(outdata,current_contacts_db_version);
+                       }
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_get_current_version(contacts_h contact, int* contacts_db_version)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is null");
+       RETVM_IF(contacts_db_version==NULL,CONTACTS_ERROR_INVALID_PARAMETER,"contacts_db_version is null");
+       *contacts_db_version = 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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       /* ipc call */
+       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_CURRENT_VERSION, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+               if (ret == CONTACTS_ERROR_NONE) {
+                       ret = ctsvc_ipc_unmarshal_int(outdata,contacts_db_version);
+               }
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_search_records(contacts_h contact, const char* view_uri, const char *keyword,
+               int offset, int limit, contacts_list_h* out_list)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact 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);
+       if (indata == NULL) {
+               CTS_ERR("pims_ipc_data_create() Fail");
+               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_string(view_uri,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_string(keyword,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(offset,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(limit,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_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE)
+               {
+                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_search_records_with_range(contacts_h contact, const char* view_uri, const char *keyword,
+               int offset, int limit, int range, contacts_list_h* out_list)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(contact == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(out_list == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
+       RETVM_IF(range == 0, CONTACTS_ERROR_INVALID_PARAMETER, "range is 0");
+       *out_list = NULL;
+
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL) {
+               CTS_ERR("pims_ipc_data_create() Fail");
+               return CONTACTS_ERROR_OUT_OF_MEMORY;
+       }
+       ret = ctsvc_ipc_marshal_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_string(view_uri, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_string(keyword, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(offset, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(limit, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(range, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       if (0 != ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_RANGE, indata, &outdata)) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE)
+                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_search_records_with_query(contacts_h contact, contacts_query_h query, const char *keyword,
+               int offset, int limit, contacts_list_h* out_list)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER, "list is NULL");
+       RETVM_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER, "query is NULL");
+       *out_list = NULL;
+
+       /* make indata */
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL) {
+               CTS_ERR("pims_ipc_data_create() Fail");
+               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_query(query,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_string(keyword,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(offset,indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(limit,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_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_QUERY, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       ret = ctsvc_ipc_unmarshal_list(outdata,out_list);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_get_last_change_version(contacts_h contact, int* last_version)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       bool result = false;
+
+       RETVM_IF(NULL == last_version, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       *last_version = 0;
+
+       ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_CONTACT_READ, &result);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
+       if (result == false) {
+               ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_PHONELOG_READ, &result);
+               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
+               RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied");
+       }
+
+       *last_version = ctsvc_client_ipc_get_change_version(contact);
+       return ret;
+}
+
+typedef struct
+{
+       contacts_db_status_changed_cb cb;
+       void *user_data;
+}status_callback_info_s;
+
+static GSList *__status_change_subscribe_list = NULL;
+
+static void __ctsvc_client_db_free_cb_info(status_callback_info_s *cb_info)
+{
+       if (NULL == cb_info)
+               return;
+       free(cb_info);
+}
+
+static void __ctsvc_db_status_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
+{
+       int ret;
+       int status = -1;
+       GSList *l;
+
+       if (data) {
+               ret = ctsvc_ipc_unmarshal_int(data, &status);
+               WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
+       }
+
+       for (l = __status_change_subscribe_list;l;l=l->next) {
+               status_callback_info_s *cb_info = l->data;
+               /* TODO: Fixme - check zone_name */
+               if (cb_info->cb)
+                       cb_info->cb(status, cb_info->user_data);
+       }
+}
+
+int ctsvc_client_db_get_status(contacts_h contact, contacts_db_status_e *status)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h outdata = NULL;
+       pims_ipc_data_h indata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(status == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"The out param is NULL");
+       *status = 0;
+
+       /* make indata */
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL) {
+               CTS_ERR("pims_ipc_data_create() Fail");
+               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_STATUS, indata, &outdata) != 0) {
+               pims_ipc_data_destroy(indata);
+               CTS_ERR("ctsvc_ipc_call failed");
+               return CONTACTS_ERROR_IPC;
+       }
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+               if (CONTACTS_ERROR_NONE == ret) {
+                       *status = *(int*) pims_ipc_data_get(outdata, &size);
+               }
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_db_add_status_changed_cb(contacts_h contact,
+               contacts_db_status_changed_cb cb, void* user_data)
+{
+       status_callback_info_s *cb_info = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : callback is null");
+
+       ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+
+       if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
+                               CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_IPC_SERVER_DB_STATUS_CHANGED,
+                               __ctsvc_db_status_subscriber_callback, NULL) != 0) {
+               CTS_ERR("pims_ipc_subscribe error\n");
+               ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       cb_info = calloc(1, sizeof(status_callback_info_s));
+       if (NULL == cb_info) {
+               CTS_ERR("calloc() Fail");
+               ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+               return CONTACTS_ERROR_OUT_OF_MEMORY;
+       }
+       cb_info->user_data = user_data;
+       cb_info->cb = cb;
+       __status_change_subscribe_list = g_slist_append(__status_change_subscribe_list, cb_info);
+
+       ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_client_db_remove_status_changed_cb(contacts_h contact,
+       contacts_db_status_changed_cb cb, void* user_data)
+{
+       GSList *l;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : callback is null");
+
+       ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+       for (l = __status_change_subscribe_list;l;l=l->next) {
+               status_callback_info_s *cb_info = l->data;
+               if (cb == cb_info->cb && user_data == cb_info->user_data) {
+                       __status_change_subscribe_list = g_slist_remove(__status_change_subscribe_list, cb_info);
+                       __ctsvc_client_db_free_cb_info(cb_info);
+                       break;
+               }
+       }
+
+       if (g_slist_length(__status_change_subscribe_list) == 0) {
+               pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
+                               CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_IPC_SERVER_DB_STATUS_CHANGED);
+               g_slist_free(__status_change_subscribe_list);
+               __status_change_subscribe_list = NULL;
+       }
+
+       ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
+       return CONTACTS_ERROR_NONE;
+}
diff --git a/client/ctsvc_client_db_helper.h b/client/ctsvc_client_db_helper.h
new file mode 100644 (file)
index 0000000..a6a8d69
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2014 - 2015 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.
+ *
+ */
+
+#ifndef __CTSVC_CLIENT_DB_HELPER_H__
+#define __CTSVC_CLIENT_DB_HELPER_H__
+
+#include "contacts_types.h"
+
+int ctsvc_client_db_insert_record(contacts_h contact, contacts_record_h record, int *id);
+int ctsvc_client_db_get_record(contacts_h contact, const char* view_uri, int id, contacts_record_h* out_record);
+int ctsvc_client_db_update_record(contacts_h contact, contacts_record_h record);
+int ctsvc_client_db_delete_record(contacts_h contact, const char* view_uri, int id);
+int ctsvc_client_db_replace_record(contacts_h contact, contacts_record_h record, int id);
+int ctsvc_client_db_get_all_records(contacts_h contact, const char* view_uri, int offset, int limit, contacts_list_h* out_list);
+int ctsvc_client_db_get_records_with_query(contacts_h contact, contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
+int ctsvc_client_db_get_count(contacts_h contact, const char* view_uri, int *out_count);
+int ctsvc_client_db_get_count_with_query(contacts_h contact, contacts_query_h query, int *out_count);
+int ctsvc_client_db_insert_records(contacts_h contact, contacts_list_h list, int **ids, int *count);
+int ctsvc_client_db_update_records(contacts_h contact, contacts_list_h list);
+int ctsvc_client_db_delete_records(contacts_h contact, const char* view_uri, int ids[], int count);
+int ctsvc_client_db_replace_records(contacts_h contact, contacts_list_h list, int ids[], int count);
+int ctsvc_client_db_get_changes_by_version(contacts_h contact, const char* view_uri, int addressbook_id, int ctsvc_client_db_version, contacts_list_h* record_list, int* current_ctsvc_client_db_version);
+int ctsvc_client_db_get_current_version(contacts_h contact, int* ctsvc_client_db_version);
+int ctsvc_client_db_search_records(contacts_h contact, const char* view_uri, const char *keyword, int offset, int limit, contacts_list_h* out_list);
+int ctsvc_client_db_search_records_with_range(contacts_h contact, const char* view_uri, const char *keyword, int offset, int limit, int range, contacts_list_h* out_list);
+int ctsvc_client_db_search_records_with_query(contacts_h contact, contacts_query_h query, const char *keyword, int offset, int limit, contacts_list_h* out_list);
+int ctsvc_client_db_get_last_change_version(contacts_h contact, int* last_version);
+int ctsvc_client_db_get_status(contacts_h contact, contacts_db_status_e *status);
+int ctsvc_client_db_add_status_changed_cb(contacts_h contact, contacts_db_status_changed_cb cb, void* user_data);
+int ctsvc_client_db_remove_status_changed_cb(contacts_h contact, contacts_db_status_changed_cb cb, void* user_data);
+
+#endif /* __CTSVC_CLIENT_DB_HELPER_H__ */
\ No newline at end of file
similarity index 73%
rename from common/ctsvc_db_notification.c
rename to client/ctsvc_client_db_notification.c
index 92c8042..c3360d4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 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.
 #include "contacts.h"
 #include "ctsvc_internal.h"
 #include "ctsvc_inotify.h"
+#include "ctsvc_client_handle.h"
 
 API int contacts_db_add_changed_cb(const char* view_uri, contacts_db_changed_cb cb,
                void* user_data)
 {
        int ret;
+       contacts_h contact = NULL;
 
        RETVM_IF(NULL == view_uri, CONTACTS_ERROR_INVALID_PARAMETER,
                        "Invalid parameter : view_uri is null");
        RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
                        "Invalid parameter : callback is null");
 
-       ret = ctsvc_inotify_subscribe(view_uri, cb, user_data);
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_inotify_subscribe(contact, view_uri, cb, user_data);
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret,
                        "ctsvc_inotify_subscribe(%s) Fail(%d)", view_uri, ret);
 
@@ -42,13 +47,17 @@ API int contacts_db_remove_changed_cb(const char* view_uri, contacts_db_changed_
                void* user_data)
 {
        int ret;
+       contacts_h contact = NULL;
 
        RETVM_IF(NULL == view_uri, CONTACTS_ERROR_INVALID_PARAMETER,
                        "Invalid parameter : view_uri is null");
        RETVM_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER,
                        "Invalid parameter : callback is null");
 
-       ret = ctsvc_inotify_unsubscribe(view_uri, cb, user_data);
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+
+       ret = ctsvc_inotify_unsubscribe(contact, view_uri, cb, user_data);
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret,
                        "ctsvc_inotify_unsubscribe(%s) Fail(%d)", view_uri, ret);
 
index e6dffb8..7641e62 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 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.
  *
  */
 
-#include <glib.h>
-
 #include "contacts.h"
 #include "ctsvc_internal.h"
-#include "ctsvc_ipc_define.h"
-#include "ctsvc_client_ipc.h"
-#include <pims-ipc-data.h>
-#include "ctsvc_ipc_marshal.h"
+#include "ctsvc_client_handle.h"
+#include "ctsvc_client_group_helper.h"
 
 API int contacts_group_add_contact(int group_id, int contact_id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(group_id <= 0 || contact_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(group_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(contact_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_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_ADD_CONTACT, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
+       int ret;
+       contacts_h contact = NULL;
 
-       pims_ipc_data_destroy(indata);
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_group_add_contact(contact, group_id, contact_id);
 
        return ret;
 }
 
 API int contacts_group_remove_contact(int group_id, int contact_id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(group_id <= 0 || contact_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(group_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(contact_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
+       int ret;
+       contacts_h contact = NULL;
 
-       // ipc call
-       if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_REMOVE_CONTACT, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_group_remove_contact(contact, group_id, contact_id);
 
        return ret;
 }
 
 API int contacts_group_set_group_order(int group_id, int previous_group_id, int next_group_id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(group_id <= 0 || previous_group_id < 0 || next_group_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;
-       }
+       int ret;
+       contacts_h contact = NULL;
 
-       ret = ctsvc_ipc_marshal_int(group_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(previous_group_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(next_group_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       // ipc call
-       if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_SET_GROUP_ORDER, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_group_set_group_order(contact, group_id, previous_group_id, next_group_id);
 
        return ret;
-
 }
 
diff --git a/client/ctsvc_client_group_helper.c b/client/ctsvc_client_group_helper.c
new file mode 100644 (file)
index 0000000..7f42439
--- /dev/null
@@ -0,0 +1,230 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2015 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_client_ipc.h"
+#include <pims-ipc-data.h>
+#include "ctsvc_ipc_marshal.h"
+
+
+static const char CONTACTS_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.read";
+static const char CONTACTS_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.write";
+static const char PHONELOG_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.read";
+static const char PHONELOG_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.write";
+
+int ctsvc_client_group_add_contact(contacts_h contact, int group_id, int contact_id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(group_id <= 0 || contact_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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_int(group_id, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(contact_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_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_ADD_CONTACT, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_group_remove_contact(contacts_h contact, int group_id, int contact_id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(group_id <= 0 || contact_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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+
+       ret = ctsvc_ipc_marshal_int(group_id, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(contact_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_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_REMOVE_CONTACT, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_group_set_group_order(contacts_h contact, int group_id, int previous_group_id, int next_group_id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(group_id <= 0 || previous_group_id < 0 || next_group_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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_int(group_id, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(previous_group_id, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(next_group_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_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_SET_GROUP_ORDER, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+
+}
+
diff --git a/client/ctsvc_client_group_helper.h b/client/ctsvc_client_group_helper.h
new file mode 100644 (file)
index 0000000..38d6120
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2015 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.
+ *
+ */
+
+#ifndef __CTSVC_CLIENT_GROUP_HELPER_H__
+#define __CTSVC_CLIENT_GROUP_HELPER_H__
+
+#include "contacts_types.h"
+
+int ctsvc_client_group_add_contact(contacts_h contact, int group_id, int contact_id);
+int ctsvc_client_group_remove_contact(contacts_h contact, int group_id, int contact_id);
+int ctsvc_client_group_set_group_order(contacts_h contact, int group_id, int previous_group_id, int next_group_id);
+
+#endif /* __CTSVC_CLIENT_GROUP_HELPER_H__ */
+
diff --git a/client/ctsvc_client_handle.c b/client/ctsvc_client_handle.c
new file mode 100644 (file)
index 0000000..0b34d63
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2015 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 <unistd.h>
+#include <pthread.h>
+#include <glib.h>
+
+#include "ctsvc_internal.h"
+#include "ctsvc_handle.h"
+#include "ctsvc_mutex.h"
+#include "ctsvc_client_handle.h"
+
+static GHashTable *_ctsvc_handle_table = NULL;
+
+static int _ctsvc_client_handle_get_key(char *key, int key_len)
+{
+       int ret;
+       int len;
+
+       ret = gethostname(key, key_len);
+       RETVM_IF(0 != ret, CONTACTS_ERROR_SYSTEM, "gethostname() Failed(%d)", errno);
+
+       len = strlen(key);
+       snprintf(key+len, key_len-len, ":%d", (int)pthread_self());
+
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_client_handle_get_current_p(contacts_h *p_contact)
+{
+       int ret;
+       char key[CTSVC_STR_SHORT_LEN] = {0};
+       contacts_h contact = NULL;
+
+       RETVM_IF(NULL == _ctsvc_handle_table, CONTACTS_ERROR_NO_DATA, "_ctsvc_handle_table is NULL");
+
+       ret = _ctsvc_client_handle_get_key(key, sizeof(key));
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "_ctsvc_client_handle_get_key() Fail(%d)", ret);
+
+       ctsvc_mutex_lock(CTS_MUTEX_HANDLE);
+       contact = g_hash_table_lookup(_ctsvc_handle_table, key);
+       ctsvc_mutex_unlock(CTS_MUTEX_HANDLE);
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_NO_DATA, "g_hash_table_lookup() return NULL");
+
+       *p_contact = contact;
+       return CONTACTS_ERROR_NONE;
+}
+
+static int _ctsvc_client_handle_add(contacts_h contact)
+{
+       int ret;
+       char key[CTSVC_STR_SHORT_LEN] = {0};
+
+       if (NULL == _ctsvc_handle_table)
+               _ctsvc_handle_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+
+       ret = _ctsvc_client_handle_get_key(key, sizeof(key));
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "_ctsvc_client_handle_get_key() Fail(%d)", ret);
+
+       g_hash_table_insert(_ctsvc_handle_table, strdup(key), contact);
+
+       ctsvc_mutex_unlock(CTS_MUTEX_HANDLE);
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_client_handle_create(contacts_h *p_contact)
+{
+       int ret;
+       contacts_h contact = NULL;
+
+       RETVM_IF(NULL == p_contact, CONTACTS_ERROR_INVALID_PARAMETER, "p_contact is NULL");
+       *p_contact = NULL;
+
+       ret = ctsvc_handle_create(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_handle_create() Fail(%d)", ret);
+
+       ret = _ctsvc_client_handle_add(contact);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("_ctsvc_client_handle_add() Fail(%d)", ret);
+               ctsvc_handle_destroy(contact);
+               return ret;
+       }
+
+       *p_contact = contact;
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_client_handle_remove(contacts_h contact)
+{
+       int ret;
+       char key[CTSVC_STR_SHORT_LEN] = {0};
+       RETVM_IF(NULL == _ctsvc_handle_table, CONTACTS_ERROR_NONE, "_ctsvc_handle_table is NULL");
+
+       ret = _ctsvc_client_handle_get_key(key, sizeof(key));
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "_ctsvc_client_handle_get_key() Fail(%d)", ret);
+
+       ctsvc_mutex_lock(CTS_MUTEX_HANDLE);
+       g_hash_table_remove(_ctsvc_handle_table, key);
+       if (0 == g_hash_table_size(_ctsvc_handle_table)) {
+               g_hash_table_destroy(_ctsvc_handle_table);
+               _ctsvc_handle_table = NULL;
+       }
+       ctsvc_mutex_unlock(CTS_MUTEX_HANDLE);
+       ctsvc_handle_destroy(contact);
+
+       return CONTACTS_ERROR_NONE;
+}
+
+
diff --git a/client/ctsvc_client_handle.h b/client/ctsvc_client_handle.h
new file mode 100644 (file)
index 0000000..c39e002
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2015 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.
+ *
+ */
+
+#ifndef __CTSVC_CLIENT_HANDLE_H__
+#define __CTSVC_CLIENT_HANDLE_H__
+#include "contacts_types.h"
+
+int ctsvc_client_handle_get_current_p(contacts_h *p_contact);
+int ctsvc_client_handle_remove(contacts_h contact);
+int ctsvc_client_handle_create(contacts_h *p_contact);
+
+#endif /* __CTSVC_CLIENT_HANDLE_H__ */
index 6626fa2..5c36072 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 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.
  *
  */
 
-#include <glib.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
 #include <pims-ipc-data.h>
 
 #include "ctsvc_client_ipc.h"
 #include "ctsvc_ipc_marshal.h"
 #include "ctsvc_view.h"
 #include "ctsvc_mutex.h"
+#include "ctsvc_handle.h"
 
 static __thread pims_ipc_h __contacts_ipc = NULL;
 static pims_ipc_h __contacts_global_ipc = NULL;
 
-static __thread int __contacts_change_version = 0;
-static int __contacts_global_change_version = 0;
-
-int ctsvc_ipc_connect_on_thread(void)
+int ctsvc_ipc_connect_on_thread(contacts_h contact)
 {
        int ret = CONTACTS_ERROR_NONE;
        pims_ipc_data_h outdata = NULL;
@@ -60,10 +60,7 @@ int ctsvc_ipc_connect_on_thread(void)
                        }
                }
        }
-       else {
-               CTS_DBG("contacts already connected");
-               return CONTACTS_ERROR_NONE;
-       }
+
 
        // ipc call
        if (pims_ipc_call(__contacts_ipc, CTSVC_IPC_MODULE, CTSVC_IPC_SERVER_CONNECT, NULL, &outdata) != 0) {
@@ -93,7 +90,7 @@ DATA_FREE:
        return ret;
 }
 
-int ctsvc_ipc_disconnect_on_thread(void)
+int ctsvc_ipc_disconnect_on_thread(contacts_h contact, int connection_count)
 {
        int ret = CONTACTS_ERROR_NONE;
        pims_ipc_data_h outdata = NULL;
@@ -113,8 +110,10 @@ int ctsvc_ipc_disconnect_on_thread(void)
                if (ret != CONTACTS_ERROR_NONE)
                        CTS_ERR("[GLOBAL_IPC_CHANNEL] pims_ipc didn't destroyed!!!(%d)", ret);
 
-               pims_ipc_destroy(__contacts_ipc);
-               __contacts_ipc = NULL;
+               if (1 == connection_count) {
+                       pims_ipc_destroy(__contacts_ipc);
+                       __contacts_ipc = NULL;
+               }
        }
        else {
                CTS_ERR("pims_ipc_call out data is NULL");
@@ -156,7 +155,7 @@ bool ctsvc_ipc_is_busy()
        return ret;
 }
 
-int ctsvc_ipc_connect(void)
+int ctsvc_ipc_connect(contacts_h contact)
 {
        int ret = CONTACTS_ERROR_NONE;
        pims_ipc_data_h outdata = NULL;
@@ -177,10 +176,6 @@ int ctsvc_ipc_connect(void)
                        }
                }
        }
-       else {
-               CTS_DBG("[GLOBAL_IPC_CHANNEL] contacts already connected");
-               return CONTACTS_ERROR_NONE;
-       }
 
        /* ipc call */
        if (pims_ipc_call(__contacts_global_ipc, CTSVC_IPC_MODULE, CTSVC_IPC_SERVER_CONNECT, NULL, &outdata) != 0) {
@@ -199,6 +194,7 @@ int ctsvc_ipc_connect(void)
                        goto DATA_FREE;
                }
        }
+
        return ret;
 
 DATA_FREE:
@@ -208,7 +204,7 @@ DATA_FREE:
 }
 
 
-int ctsvc_ipc_disconnect(void)
+int ctsvc_ipc_disconnect(contacts_h contact, int connection_count)
 {
        int ret = CONTACTS_ERROR_NONE;
        pims_ipc_data_h outdata = NULL;
@@ -230,8 +226,13 @@ int ctsvc_ipc_disconnect(void)
                        return ret;
                }
 
-               pims_ipc_destroy(__contacts_global_ipc);
-               __contacts_global_ipc = NULL;
+               ctsvc_base_s *base = (ctsvc_base_s *)contact;
+               base->connection_count--;
+
+               if (1 == connection_count) {
+                       pims_ipc_destroy(__contacts_global_ipc);
+                       __contacts_global_ipc = NULL;
+               }
        }
        else {
                CTS_ERR("pims_ipc_call out data is NULL");
@@ -266,23 +267,18 @@ int ctsvc_ipc_call(char *module, char *function, pims_ipc_h data_in, pims_ipc_da
        return ret;
 }
 
-void ctsvc_client_ipc_set_change_version(int version)
+void ctsvc_client_ipc_set_change_version(contacts_h contact, int version)
 {
-       if (__contacts_ipc == NULL) {
-               __contacts_global_change_version = version;
-               CTS_DBG("change_version = %d", version);
-               return;
-       }
-       __contacts_change_version = version;
-       CTS_DBG("change_version = %d", version);
+       RETM_IF(NULL == contact, "contact is NULL");
+       ctsvc_base_s *base = (ctsvc_base_s *)contact;
+       base->version = version;
 }
 
-int ctsvc_client_ipc_get_change_version(void)
+int ctsvc_client_ipc_get_change_version(contacts_h contact)
 {
-       if (__contacts_ipc == NULL)
-               return __contacts_global_change_version;
-
-       return __contacts_change_version;
+       RETVM_IF(NULL == contact, -1, "contact is NULL");
+       ctsvc_base_s *base = (ctsvc_base_s *)contact;
+       return base->version;
 }
 
 int ctsvc_ipc_client_check_permission(int permission, bool *result)
index 7c8464b..861fad2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 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.
 #define __CTSVC_CLIENT_IPC_H__
 
 #include <pims-ipc.h>
+#include "contacts_types.h"
 
 pims_ipc_h ctsvc_get_ipc_handle();
 
-int ctsvc_ipc_connect(void);
-int ctsvc_ipc_disconnect(void);
+int ctsvc_ipc_connect(contacts_h contact);
+int ctsvc_ipc_disconnect(contacts_h contact, int connection_count);
 
-int ctsvc_ipc_connect_on_thread(void);
-int ctsvc_ipc_disconnect_on_thread(void);
+int ctsvc_ipc_connect_on_thread(contacts_h contact);
+int ctsvc_ipc_disconnect_on_thread(contacts_h contact, int connection_count);
 
 
 bool ctsvc_ipc_is_busy();
@@ -39,8 +40,8 @@ int ctsvc_ipc_destroy_for_change_subscription();
 
 int ctsvc_ipc_call(char *module, char *function, pims_ipc_h data_in, pims_ipc_data_h *data_out);
 
-void ctsvc_client_ipc_set_change_version(int version);
-int ctsvc_client_ipc_get_change_version(void);
+void ctsvc_client_ipc_set_change_version(contacts_h contact, int version);
+int ctsvc_client_ipc_get_change_version(contacts_h contact);
 
 int ctsvc_ipc_client_check_permission(int permission, bool *result);
 
index ba195cf..44788e4 100644 (file)
@@ -17,6 +17,8 @@
  *
  */
 
+#include <stdio.h>
+#include <unistd.h>
 #include <pims-ipc.h>
 #include <pims-ipc-svc.h>
 #include <pims-ipc-data.h>
@@ -24,6 +26,7 @@
 #include "contacts.h"
 #include "ctsvc_internal.h"
 #include "ctsvc_ipc_define.h"
+#include "ctsvc_ipc_marshal.h"
 #include "ctsvc_mutex.h"
 #include "ctsvc_client_ipc.h"
 #include "contacts_extension.h"
@@ -46,16 +49,18 @@ static GSList *__db_change_subscribe_list = NULL;
 
 static void __ctsvc_db_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
 {
-       unsigned int size = 0;
+       int ret;
        char *str = NULL;
        subscribe_info_s *info = user_data;
 
-       if (data)
-               str = (char*)pims_ipc_data_get(data, &size);
+       if (data) {
+               ret = ctsvc_ipc_unmarshal_string(data, &str);
+               WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_ipc_unmarshal_string() Fail(%d)", ret);
+       }
 
        if (NULL == str) {
                CTS_ERR("There is no changed data");
-               return;
+               goto DATA_FREE;
        }
 
        if (info) {
@@ -67,6 +72,8 @@ static void __ctsvc_db_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data,
                        }
                }
        }
+DATA_FREE:
+       free(str);
 }
 
 /* This API should be called in CTS_MUTEX_PIMS_IPC_PUBSUB mutex */
index bd3348f..b566690 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 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.
  *
  */
 
-#include <glib.h>
-#include <pims-ipc-data.h>
-
 #include "contacts.h"
 #include "ctsvc_internal.h"
-#include "ctsvc_ipc_define.h"
-#include "ctsvc_client_ipc.h"
-#include "ctsvc_ipc_marshal.h"
+#include "ctsvc_client_handle.h"
+#include "ctsvc_client_person_helper.h"
 
 API int contacts_person_link_person(int base_person_id, int person_id)
 {
+       int ret;
+       contacts_h contact = NULL;
 
-       int ret = CONTACTS_ERROR_NONE;
-
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(base_person_id <= 0 || 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!");
-               return CONTACTS_ERROR_OUT_OF_MEMORY;
-       }
-
-       bool success = false;
-       do {
-               if (ctsvc_ipc_marshal_int(base_person_id, indata) != CONTACTS_ERROR_NONE) break;
-               if (ctsvc_ipc_marshal_int(person_id, indata) != CONTACTS_ERROR_NONE) break;
-
-               success = true;
-       } while(0);
-
-       if (success == false) {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-/*
-       ret = ctsvc_ipc_marshal_int(base_person_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(person_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               return ret;
-       }
-*/
-
-       // ipc call
-       if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_LINK_PERSON, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_person_link_person(contact, base_person_id, person_id);
 
        return ret;
 }
 
 API int contacts_person_unlink_contact(int person_id, int contact_id, int* unlinked_person_id)
 {
-       int ret = CONTACTS_ERROR_NONE;
+       int ret;
+       contacts_h contact = NULL;
 
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       RETVM_IF(person_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
-
-       if (unlinked_person_id)
-               *unlinked_person_id = 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;
-       }
-       ret = ctsvc_ipc_marshal_int(contact_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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_UNLINK_CONTACT, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-
-                       if (unlinked_person_id)
-                               *unlinked_person_id = *(int*)pims_ipc_data_get(outdata,&size);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_person_unlink_contact(contact, person_id, contact_id, unlinked_person_id);
 
        return ret;
+
 }
 
 API int contacts_person_reset_usage(int person_id, contacts_usage_type_e type)
 {
-       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,"contact_id should be greater than 0");
+       int ret;
+       contacts_h contact = 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_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", 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;
-       }
-       ret = ctsvc_ipc_marshal_int((int)type, 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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_RESET_USAGE, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_person_reset_usage(contact, person_id, type);
 
        return ret;
 }
 
 API int contacts_person_set_favorite_order(int person_id, int previous_person_id, int next_person_id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(person_id <= 0 || previous_person_id < 0 || next_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;
-       }
-       ret = ctsvc_ipc_marshal_int(previous_person_id, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(next_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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_FAVORITE_ORDER, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
+       int ret;
+       contacts_h contact = NULL;
 
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_person_set_favorite_order(contact, person_id, previous_person_id, next_person_id);
 
        return ret;
-
 }
 
 API int contacts_person_set_default_property(contacts_person_property_e property,
                int person_id, int id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(person_id <= 0 || 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;
-       }
-       ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
-       if (ret != CONTACTS_ERROR_NONE)
-       {
-               CTS_ERR("marshal fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-       ret = ctsvc_ipc_marshal_int(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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_DEFAULT_PROPERTY, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
+       int ret;
+       contacts_h contact = NULL;
 
-       pims_ipc_data_destroy(indata);
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_person_set_default_property(contact, property, person_id, id);
 
        return ret;
 }
@@ -369,55 +92,13 @@ API int contacts_person_set_default_property(contacts_person_property_e property
 API int contacts_person_get_default_property(contacts_person_property_e property,
                int person_id, int *id)
 {
-       int ret = CONTACTS_ERROR_NONE;
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-
-       RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
-       *id = 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;
-       }
-
-       ret = ctsvc_ipc_marshal_unsigned_int(property, 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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_DEFAULT_PROPERTY,
-                               indata, &outdata) != 0) {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
+       int ret;
+       contacts_h contact = NULL;
 
-       pims_ipc_data_destroy(indata);
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       if (outdata) {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-               if (ret == CONTACTS_ERROR_NONE) {
-                       if (id)
-                               *id = *(int*)pims_ipc_data_get(outdata,&size);
-               }
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_person_get_default_property(contact, property, person_id, id);
 
        return ret;
 }
diff --git a/client/ctsvc_client_person_helper.c b/client/ctsvc_client_person_helper.c
new file mode 100644 (file)
index 0000000..4d17f7a
--- /dev/null
@@ -0,0 +1,446 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2015 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 <pims-ipc-data.h>
+
+#include "contacts.h"
+#include "ctsvc_internal.h"
+#include "ctsvc_ipc_define.h"
+#include "ctsvc_client_ipc.h"
+#include "ctsvc_ipc_marshal.h"
+
+static const char CONTACTS_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.read";
+static const char CONTACTS_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.write";
+static const char PHONELOG_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.read";
+static const char PHONELOG_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.write";
+
+int ctsvc_client_person_link_person(contacts_h contact, int base_person_id, int person_id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(base_person_id <= 0 || 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!");
+               return CONTACTS_ERROR_OUT_OF_MEMORY;
+       }
+       ret = ctsvc_ipc_marshal_handle(contact, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       bool success = false;
+       do {
+               if (ctsvc_ipc_marshal_int(base_person_id, indata) != CONTACTS_ERROR_NONE) break;
+               if (ctsvc_ipc_marshal_int(person_id, indata) != CONTACTS_ERROR_NONE) break;
+
+               success = true;
+       } while (0);
+
+       if (success == false) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+/*
+       ret = ctsvc_ipc_marshal_int(base_person_id, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(person_id, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               return ret;
+       }
+*/
+
+       /* ipc call */
+       if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_LINK_PERSON, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_person_unlink_contact(contacts_h contact, int person_id, int contact_id, int* unlinked_person_id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(person_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
+
+       if (unlinked_person_id)
+               *unlinked_person_id = 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_handle(contact, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               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;
+       }
+       ret = ctsvc_ipc_marshal_int(contact_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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_UNLINK_CONTACT, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+
+                       if (unlinked_person_id)
+                               *unlinked_person_id = *(int*)pims_ipc_data_get(outdata,&size);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_person_reset_usage(contacts_h contact, int person_id, contacts_usage_type_e type)
+{
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"contact_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_handle(contact, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               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;
+       }
+       ret = ctsvc_ipc_marshal_int((int)type, 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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_RESET_USAGE, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_person_set_favorite_order(contacts_h contact, int person_id, int previous_person_id, int next_person_id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(person_id <= 0 || previous_person_id < 0 || next_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_handle(contact, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               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;
+       }
+       ret = ctsvc_ipc_marshal_int(previous_person_id, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(next_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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_FAVORITE_ORDER, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+
+}
+
+int ctsvc_client_person_set_default_property(contacts_h contact, contacts_person_property_e property,
+               int person_id, int id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(person_id <= 0 || 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_handle(contact, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               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;
+       }
+       ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+       ret = ctsvc_ipc_marshal_int(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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_DEFAULT_PROPERTY, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
+int ctsvc_client_person_get_default_property(contacts_h contact, contacts_person_property_e property,
+               int person_id, int *id)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+       RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
+       *id = 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_handle(contact, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               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;
+       }
+
+       ret = ctsvc_ipc_marshal_unsigned_int(property, 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_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_DEFAULT_PROPERTY,
+                               indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+               if (ret == CONTACTS_ERROR_NONE) {
+                       if (id)
+                               *id = *(int*)pims_ipc_data_get(outdata,&size);
+               }
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
diff --git a/client/ctsvc_client_person_helper.h b/client/ctsvc_client_person_helper.h
new file mode 100644 (file)
index 0000000..1fce48e
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2015 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.
+ *
+ */
+
+#ifndef __CTSVC_CLIENT_PERSON_HELPER_H__
+#define __CTSVC_CLIENT_PERSON_HELPER_H__
+
+#include "contacts_types.h"
+
+int ctsvc_client_person_link_person(contacts_h contact, int base_person_id, int person_id);
+int ctsvc_client_person_unlink_contact(contacts_h contact, int person_id, int contact_id, int* unlinked_person_id);
+int ctsvc_client_person_reset_usage(contacts_h contact, int person_id, contacts_usage_type_e type);
+int ctsvc_client_person_set_favorite_order(contacts_h contact, int person_id, int previous_person_id, int next_person_id);
+int ctsvc_client_person_set_default_property(contacts_h contact, contacts_person_property_e property, int person_id, int id);
+int ctsvc_client_person_get_default_property(contacts_h contact, contacts_person_property_e property, int person_id, int *id);
+
+#endif /* __CTSVC_CLIENT_PERSON_HELPER_H__ */
\ No newline at end of file
index 44d348a..7fd6e29 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 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.
  *
  */
 
-#include <glib.h>
-#include <pims-ipc-data.h>
-
 #include "contacts.h"
-#include "contacts_phone_log_internal.h"
 #include "ctsvc_internal.h"
-#include "ctsvc_ipc_define.h"
-#include "ctsvc_client_ipc.h"
-#include "ctsvc_ipc_marshal.h"
+#include "ctsvc_client_handle.h"
+#include "ctsvc_client_phonelog_helper.h"
 
 API int contacts_phone_log_reset_statistics(void)
 {
-#ifndef ENABLE_LOG_FEATURE
-       return CONTACTS_ERROR_NOT_SUPPORTED;
-#endif // ENABLE_LOG_FEATURE
-
-       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;
-       }
-
-       // ipc call
-       if (ctsvc_ipc_call(CTSVC_IPC_PHONELOG_MODULE, CTSVC_IPC_SERVER_PHONELOG_RESET_STATISTICS, indata, &outdata) != 0)
-       {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
+       int ret;
+       contacts_h contact = NULL;
 
-       pims_ipc_data_destroy(indata);
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       if (outdata)
-       {
-               // check result
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       ret = ctsvc_client_phone_log_reset_statistics(contact);
 
        return ret;
-
 }
 
 API int contacts_phone_log_delete(contacts_phone_log_delete_e op, ...)
 {
-#ifndef ENABLE_LOG_FEATURE
-       return CONTACTS_ERROR_NOT_SUPPORTED;
-#endif // ENABLE_LOG_FEATURE
-
-       int ret = CONTACTS_ERROR_NONE;
+       int ret;
+       contacts_h contact = NULL;
 
-       pims_ipc_data_h indata = NULL;
-       pims_ipc_data_h outdata = NULL;
-       char *number = NULL;
-       int extra_data1;
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
        va_list args;
-
-       indata = pims_ipc_data_create(0);
-       if (indata == NULL) {
-               CTS_ERR("ipc data created fail!");
-               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       ret = ctsvc_ipc_marshal_int(op, indata);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("ctsvc_ipc_marshal_int fail");
-               pims_ipc_data_destroy(indata);
-               return ret;
-       }
-
-       switch(op) {
-       case CONTACTS_PHONE_LOG_DELETE_BY_ADDRESS:
-               va_start(args, op);
-               number = va_arg(args, char *);
-               va_end(args);
-               if (NULL == number) {
-                       pims_ipc_data_destroy(indata);
-                       return CONTACTS_ERROR_INVALID_PARAMETER;
-               }
-               ret = ctsvc_ipc_marshal_string(number, indata);
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_ipc_marshal_string fail");
-                       pims_ipc_data_destroy(indata);
-                       return ret;
-               }
-               break;
-       case CONTACTS_PHONE_LOG_DELETE_BY_MESSAGE_EXTRA_DATA1:
-       case CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1:
-               va_start(args, op);
-               extra_data1 = va_arg(args, int);
-               va_end(args);
-               ret = ctsvc_ipc_marshal_int(extra_data1, indata);
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_ipc_marshal_int fail");
-                       pims_ipc_data_destroy(indata);
-                       return ret;
-               }
-               break;
-       default:
-               CTS_ERR("Invalid parameter : operation is not proper (%d)", ret);
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
-       }
-
-       if (ctsvc_ipc_call(CTSVC_IPC_PHONELOG_MODULE,
-                       CTSVC_IPC_SERVER_PHONELOG_DELETE, indata, &outdata) != 0) {
-               CTS_ERR("ctsvc_ipc_call Fail");
-               pims_ipc_data_destroy(indata);
-               return CONTACTS_ERROR_IPC;
-       }
-
-       pims_ipc_data_destroy(indata);
-
-       if (outdata) {
-               unsigned int size = 0;
-               ret = *(int*) pims_ipc_data_get(outdata, &size);
-
-               if (CONTACTS_ERROR_NONE == ret) {
-                       int transaction_ver = 0;
-                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
-                       ctsvc_client_ipc_set_change_version(transaction_ver);
-               }
-
-               pims_ipc_data_destroy(outdata);
-       }
+       va_start(args, op);
+       ret = ctsvc_client_phone_log_delete(contact, op, args);
+       va_end(args);
 
        return ret;
 }
diff --git a/client/ctsvc_client_phonelog_helper.c b/client/ctsvc_client_phonelog_helper.c
new file mode 100644 (file)
index 0000000..1888f92
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * 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 <pims-ipc-data.h>
+
+#include "contacts.h"
+#include "contacts_phone_log_internal.h"
+#include "ctsvc_internal.h"
+#include "ctsvc_ipc_define.h"
+#include "ctsvc_client_ipc.h"
+#include "ctsvc_ipc_marshal.h"
+
+
+static const char CONTACTS_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.read";
+static const char CONTACTS_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.write";
+static const char PHONELOG_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.read";
+static const char PHONELOG_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.write";
+
+int ctsvc_client_phone_log_reset_statistics(contacts_h contact)
+{
+#ifndef ENABLE_LOG_FEATURE
+       return CONTACTS_ERROR_NOT_SUPPORTED;
+#endif /* ENABLE_LOG_FEATURE */
+
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is 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_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       /* ipc call */
+       if (ctsvc_ipc_call(CTSVC_IPC_PHONELOG_MODULE, CTSVC_IPC_SERVER_PHONELOG_RESET_STATISTICS, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               // check result
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+
+}
+
+int ctsvc_client_phone_log_delete(contacts_h contact, contacts_phone_log_delete_e op, va_list args)
+{
+#ifndef ENABLE_LOG_FEATURE
+       return CONTACTS_ERROR_NOT_SUPPORTED;
+#endif /* ENABLE_LOG_FEATURE */
+
+       int ret = CONTACTS_ERROR_NONE;
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+       char *number = NULL;
+       int extra_data1;
+
+       RETVM_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER, "contact is NULL");
+
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL) {
+               CTS_ERR("ipc data created fail!");
+               ret = CONTACTS_ERROR_OUT_OF_MEMORY;
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_handle(contact, indata);
+       if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       ret = ctsvc_ipc_marshal_int(op, indata);
+       if (ret != CONTACTS_ERROR_NONE) {
+               CTS_ERR("ctsvc_ipc_marshal_int fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       switch(op) {
+       case CONTACTS_PHONE_LOG_DELETE_BY_ADDRESS:
+               number = va_arg(args, char *);
+               if (NULL == number) {
+                       pims_ipc_data_destroy(indata);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               ret = ctsvc_ipc_marshal_string(number, indata);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_ipc_marshal_string fail");
+                       pims_ipc_data_destroy(indata);
+                       return ret;
+               }
+               break;
+       case CONTACTS_PHONE_LOG_DELETE_BY_MESSAGE_EXTRA_DATA1:
+       case CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1:
+               extra_data1 = va_arg(args, int);
+               ret = ctsvc_ipc_marshal_int(extra_data1, indata);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_ipc_marshal_int fail");
+                       pims_ipc_data_destroy(indata);
+                       return ret;
+               }
+               break;
+       default:
+               CTS_ERR("Invalid parameter : operation is not proper (%d)", ret);
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (ctsvc_ipc_call(CTSVC_IPC_PHONELOG_MODULE,
+                       CTSVC_IPC_SERVER_PHONELOG_DELETE, indata, &outdata) != 0) {
+               CTS_ERR("ctsvc_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CONTACTS_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata, &size);
+
+               if (CONTACTS_ERROR_NONE == ret) {
+                       int transaction_ver = 0;
+                       transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
+                       ctsvc_client_ipc_set_change_version(contact, transaction_ver);
+               }
+
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
+
diff --git a/client/ctsvc_client_phonelog_helper.h b/client/ctsvc_client_phonelog_helper.h
new file mode 100644 (file)
index 0000000..fae103a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2015 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.
+ *
+ */
+#ifndef __CTSVC_CLIENT_PHONELOG_HELPER_H__
+#define __CTSVC_CLIENT_PHONELOG_HELPER_H__
+
+#include "contacts_types.h"
+#include "contacts_phone_log_internal.h"
+
+int ctsvc_client_phone_log_reset_statistics(contacts_h contact);
+int ctsvc_client_phone_log_delete(contacts_h contact, contacts_phone_log_delete_e op, va_list args);
+
+
+#endif /* __CTSVC_CLIENT_PHONELOG_HELPER_H__ */
\ No newline at end of file
index 7e4b2a5..2336248 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact: Dohyung Jin <dh.jin@samsung.com>
  *                 Jongwon Lee <gogosing.lee@samsung.com>
  * limitations under the License.
  *
  */
-#include <errno.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <pims-ipc-data.h>
-
 #include "contacts.h"
 #include "ctsvc_internal.h"
-#include "ctsvc_socket.h"
-#include "ctsvc_mutex.h"
-#include "ctsvc_inotify.h"
 #include "ctsvc_client_ipc.h"
-
-static int ctsvc_connection = 0;
-
-static __thread int ctsvc_connection_on_thread = 0;
+#include "ctsvc_client_handle.h"
+#include "ctsvc_client_service_helper.h"
 
 API int contacts_connect_with_flags(unsigned int flags)
 {
        CTS_FN_CALL;
-       int ret = CONTACTS_ERROR_NONE;
-
-       // If new flag is defined, errer check should be updated
-       RETVM_IF(flags & 0x11111110, CONTACTS_ERROR_INVALID_PARAMETER, "flags is invalid");
+       int ret;
+       contacts_h contact = NULL;
 
-       ret = contacts_connect();
-       if (ret == CONTACTS_ERROR_PERMISSION_DENIED)
-               return ret;
-       else if (ret == CONTACTS_ERROR_NONE)
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       if (CONTACTS_ERROR_NO_DATA == ret) {
+               ret = ctsvc_client_handle_create(&contact);
+               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
+       }
+       else if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
                return ret;
-
-       if (flags & CONTACTS_CONNECT_FLAG_RETRY) {
-               int i;
-               int waiting_time = 500;
-               for (i=0;i<9;i++) {
-                       usleep(waiting_time * 1000);
-                       CTS_DBG("retry cnt=%d, ret=%x, %d",(i+1), ret, waiting_time);
-                       ret = contacts_connect();
-                       if (ret == CONTACTS_ERROR_NONE)
-                               break;
-                       if (6 < i)
-                               waiting_time += 30000;
-                       else
-                               waiting_time *= 2;
-               }
        }
 
+       ret = ctsvc_client_connect_with_flags(contact, flags);
+
        return ret;
 }
 
@@ -74,154 +51,73 @@ API int contacts_connect(void)
 {
        CTS_FN_CALL;
        int ret;
+       contacts_h contact = NULL;
 
-       ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
-       if (0 == ctsvc_connection) {
-               ret = ctsvc_ipc_connect();
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_ipc_connect() Fail(%d)", ret);
-                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-                       return ret;
-               }
-
-               ret = ctsvc_socket_init();
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_socket_init() Fail(%d)", ret);
-                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-                       return ret;
-               }
-
-               ret = ctsvc_inotify_init();
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_inotify_init() Fail(%d)", ret);
-                       ctsvc_socket_final();
-                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-                       return ret;
-               }
-
-               ctsvc_view_uri_init();
-               ctsvc_ipc_create_for_change_subscription();
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       if (CONTACTS_ERROR_NO_DATA == ret) {
+               ret = ctsvc_client_handle_create(&contact);
+               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
        }
-       else
-               CTS_DBG("System : Contacts service has been already connected(%d)", ctsvc_connection + 1);
-
-       ctsvc_connection++;
-       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+       else if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+               return ret;
+       }
+       ret = ctsvc_client_connect(contact);
 
-       return CONTACTS_ERROR_NONE;
+       return ret;
 }
 
 API int contacts_disconnect(void)
 {
-       int ret;
-
        CTS_FN_CALL;
+       int ret;
+       contacts_h contact = NULL;
 
-       ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
-       if (1 == ctsvc_connection) {
-               ctsvc_ipc_destroy_for_change_subscription();
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-               ret = ctsvc_ipc_disconnect();
-               if (ret != CONTACTS_ERROR_NONE) {
-                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-                       CTS_ERR("ctsvc_ipc_disconnect() Fail(%d)", ret);
-                       return ret;
-               }
+       ret = ctsvc_client_disconnect(contact);
+       WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
 
-               ctsvc_view_uri_deinit();
-               ctsvc_inotify_close();
-               ctsvc_socket_final();
-       }
-       else if (1 < ctsvc_connection)
-               CTS_DBG("System : connection count is %d", ctsvc_connection);
-       else {
-               CTS_DBG("System : please call contacts_connect(), connection count is (%d)", ctsvc_connection);
-               ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-               return CONTACTS_ERROR_DB;
-       }
-
-       ctsvc_connection--;
-       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-
-       return CONTACTS_ERROR_NONE;
+       return ret;
 }
 
 API int contacts_connect_on_thread(void)
 {
+       CTS_FN_CALL;
        int ret;
+       contacts_h contact = NULL;
 
-       ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
-
-       if (0 == ctsvc_connection_on_thread) {
-               ret = ctsvc_ipc_connect_on_thread();
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_ipc_connect_on_thread() Fail(%d)", ret);
-                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-                       return ret;
-               }
-
-               ret = ctsvc_socket_init();
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_socket_init() Fail(%d)", ret);
-                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-                       return ret;
-               }
-
-               ret = ctsvc_inotify_init();
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_inotify_init() Fail(%d)", ret);
-                       ctsvc_socket_final();
-                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-                       return ret;
-               }
-
-               ctsvc_view_uri_init();
-               ctsvc_ipc_create_for_change_subscription();
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       if (CONTACTS_ERROR_NO_DATA == ret) {
+               ret = ctsvc_client_handle_create(&contact);
+               RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
+       }
+       else if (CONTACTS_ERROR_NONE != ret) {
+               CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
+               return ret;
        }
-       else if (0 < ctsvc_connection_on_thread)
-               CTS_DBG("System : Contacts service has been already connected");
-
-       ctsvc_connection_on_thread++;
 
-       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+       ret = ctsvc_client_connect_on_thread(contact);
+       WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_connect_on_thread() Fail(%d)", ret);
 
-       return CONTACTS_ERROR_NONE;
+       return ret;
 }
 
 API int contacts_disconnect_on_thread(void)
 {
+       CTS_FN_CALL;
        int ret;
+       contacts_h contact = NULL;
 
-       ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
+       ret = ctsvc_client_handle_get_current_p(&contact);
+       RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
 
-       if (1 == ctsvc_connection_on_thread) {
-               ctsvc_ipc_destroy_for_change_subscription();
+       ret = ctsvc_client_disconnect_on_thread(contact);
+       WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
 
-               ret = ctsvc_ipc_disconnect_on_thread();
-               if (ret != CONTACTS_ERROR_NONE) {
-                       CTS_ERR("ctsvc_ipc_disconnect_on_thread() Fail(%d)", ret);
-                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-                       return ret;
-               }
-
-               ctsvc_view_uri_deinit();
-               ctsvc_inotify_close();
-               ctsvc_socket_final();
-               CTS_DBG("System : connection_on_thread was destroyed successfully");
-       }
-       else if (1 < ctsvc_connection_on_thread) {
-               CTS_DBG("System : connection count is %d", ctsvc_connection_on_thread);
-       }
-       else {
-               CTS_DBG("System : please call contacts_connect_on_thread(), connection count is (%d)", ctsvc_connection_on_thread);
-               ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-               return CONTACTS_ERROR_DB;
-       }
-
-       ctsvc_connection_on_thread--;
-
-       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
-
-       return CONTACTS_ERROR_NONE;
+       return ret;
 }
 
diff --git a/client/ctsvc_client_service_helper.c b/client/ctsvc_client_service_helper.c
new file mode 100644 (file)
index 0000000..84f58da
--- /dev/null
@@ -0,0 +1,247 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Dohyung Jin <dh.jin@samsung.com>
+ *                 Jongwon Lee <gogosing.lee@samsung.com>
+ *                 Donghee Ye <donghee.ye@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 <errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#include "contacts.h"
+#include "ctsvc_internal.h"
+#include "ctsvc_socket.h"
+#include "ctsvc_mutex.h"
+#include "ctsvc_inotify.h"
+#include "ctsvc_client_ipc.h"
+#include "ctsvc_client_handle.h"
+#include "ctsvc_client_service_helper.h"
+
+static int ctsvc_connection = 0;
+static __thread int ctsvc_connection_on_thread = 0;
+
+int ctsvc_client_connect_with_flags(contacts_h contact, unsigned int flags)
+{
+       CTS_FN_CALL;
+       int ret = CONTACTS_ERROR_NONE;
+
+       /* If new flag is defined, errer check should be updated */
+       RETVM_IF(flags & 0x11111110, CONTACTS_ERROR_INVALID_PARAMETER, "flags is invalid");
+
+       ret = ctsvc_client_connect(contact);
+       if (ret == CONTACTS_ERROR_PERMISSION_DENIED)
+               return ret;
+       else 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);
+                       CTS_DBG("retry cnt=%d, ret=%x, %d",(i+1), ret, waiting_time);
+                       ret = ctsvc_client_connect(contact);
+                       if (ret == CONTACTS_ERROR_NONE)
+                               break;
+                       if (6 < i)
+                               waiting_time += 30000;
+                       else
+                               waiting_time *= 2;
+               }
+       }
+
+       return ret;
+}
+
+int ctsvc_client_connect(contacts_h contact)
+{
+       CTS_FN_CALL;
+       int ret;
+       ctsvc_base_s *base = (ctsvc_base_s *)contact;
+
+       ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
+       if (0 == base->connection_count) {
+               ret = ctsvc_ipc_connect(contact);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_ipc_connect() Fail(%d)", ret);
+                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+                       return ret;
+               }
+       }
+       base->connection_count++;
+
+       if (0 == ctsvc_connection) {
+               ret = ctsvc_socket_init();
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_socket_init() Fail(%d)", ret);
+                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+                       return ret;
+               }
+
+               ret = ctsvc_inotify_init();
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_inotify_init() Fail(%d)", ret);
+                       ctsvc_socket_final();
+                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+                       return ret;
+               }
+
+               ctsvc_view_uri_init();
+               ctsvc_ipc_create_for_change_subscription();
+       }
+       else
+               CTS_DBG("System : Contacts service has been already connected(%d)", ctsvc_connection + 1);
+
+       ctsvc_connection++;
+       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_client_disconnect(contacts_h contact)
+{
+       CTS_FN_CALL;
+       int ret;
+       ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
+
+       ctsvc_base_s *base = (ctsvc_base_s *)contact;
+       if (1 == base->connection_count) {
+               ret = ctsvc_ipc_disconnect(contact, ctsvc_connection);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+                       CTS_ERR("ctsvc_ipc_disconnect() Fail(%d)", ret);
+                       return ret;
+               }
+               ctsvc_client_handle_remove((contacts_h)base);
+       }
+       else {
+               base->connection_count--;
+       }
+
+       if (1 == ctsvc_connection) {
+               ctsvc_ipc_destroy_for_change_subscription();
+               ctsvc_view_uri_deinit();
+               ctsvc_inotify_close();
+               ctsvc_socket_final();
+       }
+       else if (1 < ctsvc_connection)
+               CTS_DBG("System : connection count is %d", ctsvc_connection);
+       else {
+               CTS_DBG("System : please call contacts_connect(), connection count is (%d)", ctsvc_connection);
+               ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+               return CONTACTS_ERROR_INVALID_PARAMETER;
+       }
+
+       ctsvc_connection--;
+       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_client_connect_on_thread(contacts_h contact)
+{
+       int ret;
+       ctsvc_base_s *base = (ctsvc_base_s *)contact;
+
+       ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
+
+       if (0 == base->connection_count) {
+               ret = ctsvc_ipc_connect_on_thread(contact);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_ipc_connect_on_thread() Fail(%d)", ret);
+                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+                       return ret;
+               }
+       }
+       base->connection_count++;
+
+       if (0 == ctsvc_connection_on_thread) {
+               ret = ctsvc_socket_init();
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_socket_init() Fail(%d)", ret);
+                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+                       return ret;
+               }
+
+               ret = ctsvc_inotify_init();
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_inotify_init() Fail(%d)", ret);
+                       ctsvc_socket_final();
+                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+                       return ret;
+               }
+
+               ctsvc_view_uri_init();
+               ctsvc_ipc_create_for_change_subscription();
+       }
+       else if (0 < ctsvc_connection_on_thread)
+               CTS_DBG("System : Contacts service has been already connected");
+
+       ctsvc_connection_on_thread++;
+
+       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_client_disconnect_on_thread(contacts_h contact)
+{
+       int ret;
+       ctsvc_base_s *base = (ctsvc_base_s *)contact;
+
+       ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
+
+       if (1 == base->connection_count) {
+               ret = ctsvc_ipc_disconnect_on_thread(contact, ctsvc_connection_on_thread);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_ipc_disconnect_on_thread() Fail(%d)", ret);
+                       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+                       return ret;
+               }
+               ctsvc_client_handle_remove((contacts_h)base);
+
+       }
+       else {
+               base->connection_count--;
+       }
+
+       if (1 == ctsvc_connection_on_thread) {
+               ctsvc_ipc_destroy_for_change_subscription();
+               ctsvc_view_uri_deinit();
+               ctsvc_inotify_close();
+               ctsvc_socket_final();
+               CTS_DBG("System : connection_on_thread was destroyed successfully");
+       }
+       else if (1 < ctsvc_connection_on_thread) {
+               CTS_DBG("System : connection count is %d", ctsvc_connection_on_thread);
+       }
+       else {
+               CTS_DBG("System : please call contacts_connect_on_thread(), connection count is (%d)", ctsvc_connection_on_thread);
+               ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+               return CONTACTS_ERROR_INVALID_PARAMETER;
+       }
+
+       ctsvc_connection_on_thread--;
+
+       ctsvc_mutex_unlock(CTS_MUTEX_CONNECTION);
+
+       return CONTACTS_ERROR_NONE;
+}
+
diff --git a/client/ctsvc_client_service_helper.h b/client/ctsvc_client_service_helper.h
new file mode 100644 (file)
index 0000000..5f27eb7
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Dohyung Jin <dh.jin@samsung.com>
+ *                 Jongwon Lee <gogosing.lee@samsung.com>
+ *                 Donghee Ye <donghee.ye@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 __CTSVC_CLIENT_SERVICE_HELPER_H__
+#define __CTSVC_CLIENT_SERVICE_HELPER_H__
+
+int ctsvc_client_connect_with_flags(contacts_h contact, unsigned int flags);
+int ctsvc_client_connect(contacts_h contact);
+int ctsvc_client_disconnect(contacts_h contact);
+int ctsvc_client_connect_on_thread(contacts_h contact);
+int ctsvc_client_disconnect_on_thread(contacts_h contact);
+
+#endif /* __CTSVC_CLIENT_SERVICE_HELPER_H__ */
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index 7411258..9498ef5
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 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.
@@ -168,11 +168,13 @@ static GSList *__setting_name_display_order_subscribe_list = NULL;
 
 static void __ctsvc_setting_name_display_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
 {
+       int ret;
        int value = -1;
-       unsigned int size = 0;
-       if (data)
-               value = *(int*)pims_ipc_data_get(data, &size);
 
+       if (data) {
+               ret = ctsvc_ipc_unmarshal_int(data, &value);
+               WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
+       }
        if (__setting_name_display_order_subscribe_list) {
                GSList *l;
                for (l = __setting_name_display_order_subscribe_list;l;l=l->next) {
@@ -213,6 +215,7 @@ API int contacts_setting_add_name_display_order_changed_cb(
                ctsvc_name_display_order_changed_cb_info_s *cb_info = l->data;
                if (cb_info->cb == cb && cb_info->user_data == user_data) {
                        CTS_ERR("The same callback(%s) is already exist");
+                       ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
                        return CONTACTS_ERROR_INVALID_PARAMETER;
                }
        }
@@ -270,10 +273,13 @@ static GSList *__setting_name_sorting_order_subscribe_list = NULL;
 
 static void __ctsvc_setting_name_sorting_order_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
 {
+       int ret;
        int value = -1;
-       unsigned int size = 0;
-       if (data)
-               value = *(int*)pims_ipc_data_get(data, &size);
+
+       if (data) {
+               ret = ctsvc_ipc_unmarshal_int(data, &value);
+               WARN_IF(CONTACTS_ERROR_NONE != ret, "() Fail(%d)", ret);
+       }
 
        if (__setting_name_sorting_order_subscribe_list) {
                GSList *l;
@@ -315,6 +321,7 @@ API int contacts_setting_add_name_sorting_order_changed_cb(
                ctsvc_name_sorting_order_changed_cb_info_s *cb_info = l->data;
                if (cb_info->cb == cb && cb_info->user_data == user_data) {
                        CTS_ERR("The same callback(%s) is already exist");
+                       ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
                        return CONTACTS_ERROR_INVALID_PARAMETER;
                }
        }
diff --git a/common/ctsvc_handle.c b/common/ctsvc_handle.c
new file mode 100644 (file)
index 0000000..a10a420
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2015 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 "ctsvc_internal.h"
+#include "ctsvc_handle.h"
+
+int ctsvc_handle_create(contacts_h *contact)
+{
+       RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
+       ctsvc_base_s *base = calloc(1, sizeof(ctsvc_base_s));
+       *contact = (contacts_h)base;
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_handle_destroy(contacts_h contact)
+{
+       RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
+       ctsvc_base_s *base = (ctsvc_base_s *)contact;
+       free(base);
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_handle_clone(contacts_h contact, contacts_h *pcontact)
+{
+       RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == pcontact, CONTACTS_ERROR_INVALID_PARAMETER);
+
+       ctsvc_base_s *base = (ctsvc_base_s *)contact;
+       ctsvc_base_s *clone = calloc(1, sizeof(ctsvc_base_s));
+       clone->connection_count = base->connection_count;
+       clone->version = base->version;
+
+       *pcontact = (contacts_h)clone;
+
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_handle_compare(contacts_h contact1, contacts_h contact2)
+{
+       if (NULL == contact1 && NULL == contact2)
+               return 0;
+       else if (NULL == contact1)
+               return 1;
+       else if (NULL == contact2)
+               return 1;
+
+       ctsvc_base_s *base1 = (ctsvc_base_s *)contact1;
+       ctsvc_base_s *base2 = (ctsvc_base_s *)contact2;
+
+       if ((base1->connection_count == base2->connection_count) &&
+               (base1->version == base2->version))
+               return 0;
+       else
+               return 1;
+}
+
diff --git a/common/ctsvc_handle.h b/common/ctsvc_handle.h
new file mode 100644 (file)
index 0000000..4d6ad75
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Contacts Service
+ *
+ * Copyright (c) 2015 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.
+ *
+ */
+#ifndef __CTSVC_HANDLE_H__
+#define __CTSVC_HANDLE_H__
+
+#include "contacts_types.h"
+
+int ctsvc_handle_create(contacts_h *contact);
+int ctsvc_handle_destroy(contacts_h contact);
+int ctsvc_handle_clone(contacts_h contact, contacts_h *pcontact);
+int ctsvc_handle_compare(contacts_h contact1, contacts_h contact2);
+
+
+#endif // __CTSVC_HANDLE_H__
index 8db2850..81592e5 100644 (file)
@@ -28,6 +28,7 @@
 #include "ctsvc_internal.h"
 #include "ctsvc_notify.h"
 #include "ctsvc_view.h"
+#include "ctsvc_handle.h"
 
 #include <stdbool.h>
 
@@ -37,6 +38,7 @@
 
 typedef struct
 {
+       contacts_h contact;
        int wd;
        char *view_uri;
        contacts_db_changed_cb cb;
@@ -240,14 +242,14 @@ static inline const char* __ctsvc_noti_get_file_path(const char *view_uri)
                return CTSVC_NOTI_SDN_CHANGED;
        case CTSVC_RECORD_RESULT:
        default:
-               CTS_ERR("Invalid parameter : The type(%d) is not supported", view_uri);
+               CTS_ERR("Invalid parameter : The type(%s) is not supported", view_uri);
                return NULL;
        }
        return NULL;
 }
 
-int ctsvc_inotify_subscribe(const char *view_uri,
-                       contacts_db_changed_cb cb, void *data)
+int ctsvc_inotify_subscribe(contacts_h contact, const char *view_uri,
+                       void *cb, void *data)
 {
        int ret, wd;
        noti_info *noti, *same_noti = NULL;
@@ -274,7 +276,8 @@ int ctsvc_inotify_subscribe(const char *view_uri,
                if (it->data) {
                        same_noti = it->data;
                        if (same_noti->wd == wd && same_noti->cb == cb &&
-                                       STRING_EQUAL == strcmp(same_noti->view_uri, view_uri) && same_noti->cb_data == data)
+                                       STRING_EQUAL == strcmp(same_noti->view_uri, view_uri) && same_noti->cb_data == data &&
+                                       0 == ctsvc_handle_compare(contact, same_noti->contact))
                                break;
                        else
                                same_noti = NULL;
@@ -297,6 +300,7 @@ int ctsvc_inotify_subscribe(const char *view_uri,
        noti->view_uri = strdup(view_uri);
        noti->cb_data = data;
        noti->cb = cb;
+       ctsvc_handle_clone(contact, &(noti->contact));
        noti->blocked = false;
 
        __noti_list = g_slist_append(__noti_list, noti);
@@ -304,8 +308,8 @@ int ctsvc_inotify_subscribe(const char *view_uri,
        return CONTACTS_ERROR_NONE;
 }
 
-static inline int __ctsvc_del_noti(GSList **noti_list, int wd,
-               const char *view_uri, contacts_db_changed_cb cb, void *user_data)
+static inline int __ctsvc_del_noti(GSList **noti_list, contacts_h contact, int wd,
+               const char *view_uri, void *cb, void *user_data)
 {
        int del_cnt, remain_cnt;
        GSList *it, *result;
@@ -318,9 +322,11 @@ static inline int __ctsvc_del_noti(GSList **noti_list, int wd,
                noti_info *noti = it->data;
                if (noti && wd == noti->wd) {
                        if (cb == noti->cb && user_data == noti->cb_data
-                               && STRING_EQUAL == strcmp(noti->view_uri, view_uri)) {
+                               && STRING_EQUAL == strcmp(noti->view_uri, view_uri)
+                               && 0 == ctsvc_handle_compare(contact, noti->contact)) {
                                it = it->next;
                                result = g_slist_remove(result, noti);
+                               ctsvc_handle_destroy(noti->contact);
                                free(noti->view_uri);
                                free(noti);
                                del_cnt++;
@@ -339,7 +345,7 @@ static inline int __ctsvc_del_noti(GSList **noti_list, int wd,
        return remain_cnt;
 }
 
-int ctsvc_inotify_unsubscribe(const char *view_uri, contacts_db_changed_cb cb, void *user_data)
+int ctsvc_inotify_unsubscribe(contacts_h contact, const char *view_uri, void *cb, void *user_data)
 {
        int ret, wd;
        const char *path;
@@ -360,7 +366,7 @@ int ctsvc_inotify_unsubscribe(const char *view_uri, contacts_db_changed_cb cb, v
                return CONTACTS_ERROR_SYSTEM;
        }
 
-       ret = __ctsvc_del_noti(&__noti_list, wd, view_uri, cb, user_data);
+       ret = __ctsvc_del_noti(&__noti_list, contact, wd, view_uri, cb, user_data);
        WARN_IF(ret < CONTACTS_ERROR_NONE, "__ctsvc_del_noti() Fail(%d)", ret);
 
        if (0 == ret)
@@ -412,3 +418,4 @@ void ctsvc_inotify_close(void)
                __inoti_fd = -1;
        }
 }
+
index 1457c38..fec35c3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact: Youngjae Shin <yj99.shin@samsung.com>
  *
@@ -25,7 +25,7 @@
 
 int ctsvc_inotify_init(void);
 void ctsvc_inotify_close(void);
-int ctsvc_inotify_subscribe(const char *view_uri, contacts_db_changed_cb cb, void *data);
-int ctsvc_inotify_unsubscribe(const char *view_uri, contacts_db_changed_cb cb, void *user_data);
+int ctsvc_inotify_subscribe(contacts_h contact, const char *view_uri, contacts_db_changed_cb cb, void *data);
+int ctsvc_inotify_unsubscribe(contacts_h contact, const char *view_uri, contacts_db_changed_cb cb, void *user_data);
 
 #endif /* __CTSVC_INOTIFY_H__ */
index 8bcd633..14ab422 100644 (file)
@@ -40,6 +40,7 @@ static pthread_mutex_t sockfd_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t ipc_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t ipc_pubsub_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t access_control_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t handle_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t socket_client_info_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t cynara_mutex = PTHREAD_MUTEX_INITIALIZER;
 
@@ -66,6 +67,9 @@ static inline pthread_mutex_t* __ctsvc_mutex_get_mutex(int type)
        case CTS_MUTEX_ACCESS_CONTROL:
                ret_val = &access_control_mutex;
                break;
+       case CTS_MUTEX_HANDLE:
+               ret_val = &handle_mutex;
+               break;
        case CTS_MUTEX_SOCKET_CLIENT_INFO:
                ret_val = &socket_client_info_mutex;
                break;
index 3d31776..ea951d5 100644 (file)
@@ -28,6 +28,7 @@ enum {
        CTS_MUTEX_PIMS_IPC_CALL,
        CTS_MUTEX_PIMS_IPC_PUBSUB,
        CTS_MUTEX_ACCESS_CONTROL,
+       CTS_MUTEX_HANDLE,
        CTS_MUTEX_CYNARA,
        CTS_MUTEX_SOCKET_CLIENT_INFO,
 };
index fd949ad..af86260 100644 (file)
@@ -33,9 +33,9 @@
 #include "contacts_views.h"
 
 #define CTSVC_SOCK_PATH "/run/user/%d"
-#define CTSVC_PATH_MAX_LEN 1024
-
 #define CTSVC_IMG_FULL_PATH_SIZE_MAX 1024              /* current max length file path is 256 */
+#define CTSVC_PATH_MAX_LEN 1024
+#define CTSVC_STR_SHORT_LEN 1024
 #define STRING_EQUAL 0
 
 #define SAFE_STR(src) (src)?src:""
@@ -622,5 +622,9 @@ typedef struct {
        GSList *values;
 }ctsvc_result_s;
 
+typedef struct {
+       int version;
+       int connection_count;
+}ctsvc_base_s;
 
 #endif /* __CTSVC_STRUCT_H__ */
index c3fb788..fb2d6ed 100644 (file)
@@ -465,17 +465,17 @@ static inline int __ctsvc_vcard_append_name(ctsvc_list_s *names, char **buf, int
        CTSVC_VCARD_APPEND_STR(buf, buf_size, len, CTSVC_CRLF);
 
        if (name->first && name->last) {
-               contacts_name_display_order_e order;
+               contacts_name_display_order_e order = CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST;
+#ifdef _CONTACTS_IPC_CLIENT
                contacts_setting_get_name_display_order(&order);
+#endif
                if (CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST == order) {
                        snprintf(display, sizeof(display), "%s %s", name->first, name->last);
                }
-#ifdef _CONTACTS_IPC_CLIENT
                else {
                        /* CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST */
                        snprintf(display, sizeof(display), "%s, %s", name->last, name->first);
                }
-#endif
        }
        else
                snprintf(display, sizeof(display), "%s%s", SAFE_STR(name->first), SAFE_STR(name->last));
@@ -1792,7 +1792,7 @@ API int contacts_vcard_make_from_my_profile(contacts_record_h record, char **vca
        return __ctsvc_vcard_make_from_my_profile(my_profile, vcard_stream);
 }
 
-
+#ifdef _CONTACTS_IPC_CLIENT
 static int __ctsvc_vcard_append_person(ctsvc_person_s *person, ctsvc_list_s *list_contacts, char **buf, int *buf_size, int len)
 {
        int changed_time = 0;
@@ -1921,7 +1921,9 @@ static int __ctsvc_vcard_append_person(ctsvc_person_s *person, ctsvc_list_s *lis
 #endif
        return len;
 }
+#endif // _CONTACTS_IPC_CLIENT
 
+#ifdef _CONTACTS_IPC_CLIENT
 static int __ctsvc_vcard_make_from_person(ctsvc_person_s *person, ctsvc_list_s *list_contacts,
                char **vcard_stream)
 {
@@ -1967,7 +1969,9 @@ static int __ctsvc_vcard_make_from_person(ctsvc_person_s *person, ctsvc_list_s *
 
        return CONTACTS_ERROR_NONE;
 }
+#endif // _CONTACTS_IPC_CLIENT
 
+#ifdef _CONTACTS_IPC_CLIENT
 API int contacts_vcard_make_from_person(contacts_record_h record, char **vcard_stream)
 {
        int ret;
@@ -1999,6 +2003,7 @@ API int contacts_vcard_make_from_person(contacts_record_h record, char **vcard_s
        contacts_list_destroy(list, true);
        return ret;
 }
+#endif
 
 static inline char* __ctsvc_vcard_remove_empty_line(char *src)
 {
@@ -4013,17 +4018,17 @@ static inline void __ctsvc_vcard_make_contact_display_name(ctsvc_contact_s *cont
                        }
                }
 
+#ifdef _CONTACTS_IPC_CLIENT
                contacts_setting_get_name_display_order(&name_display_order);
+#endif
                if (CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST == name_display_order) {
                        contact->display_name = display;
                        free(reverse_display);
                }
-#ifdef _CONTACTS_IPC_CLIENT
                else {
                        contact->display_name = reverse_display;
                        free(display);
                }
-#endif
 
                contact->display_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NAME;
        }
index efd55b0..eb6b87d 100644 (file)
@@ -26,6 +26,7 @@
 #include "contacts_filter.h"
 #include "contacts_list.h"
 #include "ctsvc_list.h"
+#include "ctsvc_handle.h"
 
 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_contact_plugin_cb;
 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_my_profile_plugin_cb;
@@ -399,6 +400,38 @@ static int __ctsvc_ipc_marshal_attribute_filter(const ctsvc_attribute_filter_s*
        return CONTACTS_ERROR_NONE;
 }
 
+int ctsvc_ipc_marshal_handle(const contacts_h contact, pims_ipc_data_h ipc_data)
+{
+       int ret;
+       ctsvc_base_s *base = (ctsvc_base_s *)contact;
+
+       ret = ctsvc_ipc_marshal_int(base->version, ipc_data);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_marshal_int() Fail(%d)", ret);
+
+       ret = ctsvc_ipc_marshal_int(base->connection_count, ipc_data);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_marshal_int() Fail(%d)", ret);
+
+       return CONTACTS_ERROR_NONE;
+}
+
+int ctsvc_ipc_unmarshal_handle(const pims_ipc_data_h ipc_data, contacts_h *pcontact)
+{
+       int ret;
+       ctsvc_base_s *base = NULL;
+
+       ret = ctsvc_handle_create(pcontact);
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_handle_create() Fail(%d)", ret);
+
+       base = (ctsvc_base_s *)*pcontact;
+
+       ret = ctsvc_ipc_unmarshal_int(ipc_data, &(base->version));
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
+
+       ret = ctsvc_ipc_unmarshal_int(ipc_data, &(base->connection_count));
+       RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
+
+       return CONTACTS_ERROR_NONE;
+}
 
 int ctsvc_ipc_unmarshal_record(const pims_ipc_data_h ipc_data, contacts_record_h* precord)
 {
index a056dd6..a8eb41f 100644 (file)
@@ -42,6 +42,9 @@ typedef struct {
 int ctsvc_ipc_unmarshal_record(const pims_ipc_data_h ipc_data, contacts_record_h* precord);
 int ctsvc_ipc_marshal_record(const contacts_record_h record, pims_ipc_data_h ipc_data);
 
+int ctsvc_ipc_marshal_handle(const contacts_h contact, pims_ipc_data_h ipc_data);
+int ctsvc_ipc_unmarshal_handle(const pims_ipc_data_h ipc_data, contacts_h *pcontact);
+
 /*
  * string
  * char의 경우 NULL 설정의 이슈로 인하여, [int:string length]+[char*] 로 넘길 수 있도록 설정..
index 43b8a54..51a7f5c 100644 (file)
@@ -68,6 +68,7 @@ _CONTACTS_HANDLE(contacts_record_h)
 _CONTACTS_HANDLE(contacts_filter_h)
 _CONTACTS_HANDLE(contacts_list_h)
 _CONTACTS_HANDLE(contacts_query_h)
+_CONTACTS_HANDLE(contacts_h)
 
 /**
  * @file contacts_types.h
old mode 100755 (executable)
new mode 100644 (file)
index d9f3f6d..9aa4a70
@@ -41,7 +41,6 @@ SET(SRCS
        ${CMAKE_SOURCE_DIR}/common/ipc/ctsvc_ipc_speeddial.c
 
        ${CMAKE_SOURCE_DIR}/common/ctsvc_filter.c
-       ${CMAKE_SOURCE_DIR}/common/ctsvc_db_notification.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_inotify.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_list.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_localize_utils.c
@@ -60,6 +59,7 @@ SET(SRCS
        ${CMAKE_SOURCE_DIR}/common/ctsvc_view.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_record_speeddial.c
        ${CMAKE_SOURCE_DIR}/common/ctsvc_record_sdn.c
+       ${CMAKE_SOURCE_DIR}/common/ctsvc_handle.c
 
        db/ctsvc_db_access_control.c
        db/ctsvc_db_init.c
index a9d2c6b..f64c640 100644 (file)
@@ -21,6 +21,7 @@
 #include <pims-ipc-svc.h>
 #include "contacts.h"
 
+#include "ctsvc_handle.h"
 #include "ctsvc_server_service.h"
 #include "ctsvc_db_init.h"
 #include "ctsvc_db_query.h"
@@ -36,8 +37,22 @@ void ctsvc_ipc_server_connect(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_d
 {
        CTS_FN_CALL;
        int ret = CONTACTS_ERROR_NONE;
+       contacts_h contact = NULL;
 
-       ret = contacts_connect();
+       if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else {
+               CTS_ERR("There is no indata fail");
+               ret = CONTACTS_ERROR_SYSTEM;
+               goto ERROR_RETURN;
+       }
+
+       ret = ctsvc_connect();
 
        if (CONTACTS_ERROR_NONE == ret) {
                char *smack = NULL;
@@ -47,56 +62,64 @@ void ctsvc_ipc_server_connect(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_d
                free(smack);
        }
 
+ERROR_RETURN:
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
 
                if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
 }
 
 void ctsvc_ipc_server_disconnect(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
 {
        int ret = CONTACTS_ERROR_NONE;
+       contacts_h contact = NULL;
 
-       ret = contacts_disconnect();
+       if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
+                       ret = CONTACTS_ERROR_IPC;
+                       goto ERROR_RETURN;
+               }
+       }
 
-       // related data will be freed in __ctsvc_client_disconnected_cb
-//     if (ret == CONTACTS_ERROR_NONE)
-//             ctsvc_unset_client_access_info();
+       ret = ctsvc_disconnect();
 
-       if (outdata)
-       {
+ERROR_RETURN:
+       if (outdata) {
                *outdata = pims_ipc_data_create(0);
-               if (NULL == *outdata)
-               {
+               if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
-               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
-               {
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
        }
-       else
-       {
+       else {
                CTS_ERR("outdata is NULL");
        }
-       return;
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
+       ctsvc_server_trim_memory();
 }
 
 void ctsvc_ipc_server_check_permission(pims_ipc_h ipc, pims_ipc_data_h indata,
@@ -149,8 +172,16 @@ void ctsvc_ipc_server_db_insert_record(pims_ipc_h ipc, pims_ipc_data_h indata, p
        int ret = CONTACTS_ERROR_NONE;
        contacts_record_h record = NULL;
        int id = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
+                       ret = CONTACTS_ERROR_IPC;
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_record(indata,&record);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -168,7 +199,7 @@ void ctsvc_ipc_server_db_insert_record(pims_ipc_h ipc, pims_ipc_data_h indata, p
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_insert_record(record, &id);
+       ret = ctsvc_db_insert_record(record, &id);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -223,10 +254,9 @@ ERROR_RETURN:
        }
 
 DATA_FREE:
-       if (record)
-       {
-               contacts_record_destroy(record,true);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_record_destroy(record,true);
+       ctsvc_server_trim_memory();
        return;
 }
 
@@ -236,8 +266,15 @@ void ctsvc_ipc_server_db_get_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims
        char* view_uri = NULL;
        int id = 0;
        contacts_record_h record = NULL;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
+                       ret = CONTACTS_ERROR_IPC;
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_string(indata,&view_uri);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_string fail");
@@ -259,7 +296,7 @@ void ctsvc_ipc_server_db_get_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_get_record(view_uri,id,&record);
+       ret = ctsvc_db_get_record(view_uri,id,&record);
 
 ERROR_RETURN:
        if (outdata) {
@@ -291,10 +328,8 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-       if (record)
-       {
-               contacts_record_destroy(record,true);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_record_destroy(record,true);
        CONTACTS_FREE(view_uri);
        return;
 }
@@ -303,18 +338,22 @@ void ctsvc_ipc_server_db_update_record(pims_ipc_h ipc, pims_ipc_data_h indata, p
 {
        int ret = CONTACTS_ERROR_NONE;
        contacts_record_h record = NULL;
+       contacts_h contact = NULL;
 
-       if (indata)
-       {
+       if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
+                       ret = CONTACTS_ERROR_IPC;
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_record(indata,&record);
-               if (ret != CONTACTS_ERROR_NONE)
-               {
+               if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
                        goto ERROR_RETURN;
                }
        }
-       else
-       {
+       else {
                CTS_ERR("ctsvc_ipc_server_db_insert_record fail");
                goto ERROR_RETURN;
        }
@@ -324,7 +363,7 @@ void ctsvc_ipc_server_db_update_record(pims_ipc_h ipc, pims_ipc_data_h indata, p
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_update_record(record);
+       ret = ctsvc_db_update_record(record);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -371,10 +410,9 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-       if (record)
-       {
-               contacts_record_destroy(record,true);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_record_destroy(record,true);
+       ctsvc_server_trim_memory();
        return;
 }
 
@@ -383,8 +421,15 @@ void ctsvc_ipc_server_db_delete_record(pims_ipc_h ipc, pims_ipc_data_h indata, p
        int ret = CONTACTS_ERROR_NONE;
        char* view_uri = NULL;
        int id = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
+                       ret = CONTACTS_ERROR_IPC;
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_string(indata,&view_uri);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -406,7 +451,7 @@ void ctsvc_ipc_server_db_delete_record(pims_ipc_h ipc, pims_ipc_data_h indata, p
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_delete_record(view_uri,id);
+       ret = ctsvc_db_delete_record(view_uri,id);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -455,6 +500,7 @@ ERROR_RETURN:
 
 DATA_FREE:
 
+       ctsvc_handle_destroy(contact);
        CONTACTS_FREE(view_uri);
        return;
 }
@@ -465,8 +511,16 @@ void ctsvc_ipc_server_db_replace_record(pims_ipc_h ipc, pims_ipc_data_h indata,
        int ret = CONTACTS_ERROR_NONE;
        contacts_record_h record = NULL;
        int id = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
+                       ret = CONTACTS_ERROR_IPC;
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_record(indata, &record);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -490,7 +544,7 @@ void ctsvc_ipc_server_db_replace_record(pims_ipc_h ipc, pims_ipc_data_h indata,
        }
 
 
-       ret = contacts_db_replace_record(record, id);
+       ret = ctsvc_db_replace_record(record, id);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -540,8 +594,8 @@ ERROR_RETURN:
        }
 
 DATA_FREE:
-       if (record)
-               contacts_record_destroy(record, true);
+       ctsvc_handle_destroy(contact);
+       contacts_record_destroy(record, true);
 
        return;
 }
@@ -553,8 +607,16 @@ void ctsvc_ipc_server_db_get_all_records(pims_ipc_h ipc, pims_ipc_data_h indata,
        int offset = 0;
        int limit = 0;
        contacts_list_h list = NULL;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
+                       ret = CONTACTS_ERROR_IPC;
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_string(indata,&view_uri);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -581,7 +643,7 @@ void ctsvc_ipc_server_db_get_all_records(pims_ipc_h ipc, pims_ipc_data_h indata,
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_get_all_records(view_uri,offset,limit,&list);
+       ret = ctsvc_db_get_all_records(view_uri,offset,limit,&list);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -633,11 +695,8 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-
-       if (list)
-       {
-               contacts_list_destroy(list,true);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_list_destroy(list,true);
        CONTACTS_FREE(view_uri);
        return;
 }
@@ -649,8 +708,15 @@ void ctsvc_ipc_server_db_get_records_with_query(pims_ipc_h ipc, pims_ipc_data_h
        int offset = 0;
        int limit = 0;
        contacts_list_h list = NULL;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_query(indata,&query);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -677,7 +743,7 @@ void ctsvc_ipc_server_db_get_records_with_query(pims_ipc_h ipc, pims_ipc_data_h
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_get_records_with_query(query,offset,limit,&list);
+       ret = ctsvc_db_get_records_with_query(query,offset,limit,&list);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -727,15 +793,9 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-
-       if (list)
-       {
-               contacts_list_destroy(list,true);
-       }
-       if (query)
-       {
-               contacts_query_destroy(query);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_list_destroy(list,true);
+       contacts_query_destroy(query);
        return;
 }
 
@@ -745,8 +805,15 @@ void ctsvc_ipc_server_db_get_count(pims_ipc_h ipc, pims_ipc_data_h indata, pims_
        int ret = CONTACTS_ERROR_NONE;
        char* view_uri = NULL;
        int count = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_string(indata,&view_uri);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -763,7 +830,7 @@ void ctsvc_ipc_server_db_get_count(pims_ipc_h ipc, pims_ipc_data_h indata, pims_
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_get_count(view_uri,&count);
+       ret = ctsvc_db_get_count(view_uri,&count);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -813,6 +880,7 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
+       ctsvc_handle_destroy(contact);
        CONTACTS_FREE(view_uri);
        return;
 }
@@ -822,8 +890,15 @@ void ctsvc_ipc_server_db_get_count_with_query(pims_ipc_h ipc, pims_ipc_data_h in
        int ret = CONTACTS_ERROR_NONE;
        contacts_query_h query = NULL;
        int count = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_query(indata,&query);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -840,7 +915,7 @@ void ctsvc_ipc_server_db_get_count_with_query(pims_ipc_h ipc, pims_ipc_data_h in
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_get_count_with_query(query,&count);
+       ret = ctsvc_db_get_count_with_query(query,&count);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -890,10 +965,8 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-       if (query)
-       {
-               contacts_query_destroy(query);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_query_destroy(query);
        return;
 }
 
@@ -902,11 +975,18 @@ void ctsvc_ipc_server_db_insert_records(pims_ipc_h ipc, pims_ipc_data_h indata,
 {
        int ret = CONTACTS_ERROR_NONE;
        contacts_list_h list = NULL;
-       unsigned int id_count = 0;
+       int id_count = 0;
        int *ids = NULL;
        int i=0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_list(indata,&list);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_list fail");
@@ -1005,10 +1085,8 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-       if (list)
-       {
-               contacts_list_destroy(list,true);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_list_destroy(list,true);
        CONTACTS_FREE(ids);
        return;
 }
@@ -1018,8 +1096,15 @@ void ctsvc_ipc_server_db_update_records(pims_ipc_h ipc, pims_ipc_data_h indata,
 {
        int ret = CONTACTS_ERROR_NONE;
        contacts_list_h list = NULL;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_list(indata,&list);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_list fail");
@@ -1049,7 +1134,7 @@ void ctsvc_ipc_server_db_update_records(pims_ipc_h ipc, pims_ipc_data_h indata,
                contacts_list_first(list);
        }
 
-       ret = contacts_db_update_records(list);
+       ret = ctsvc_db_update_records(list);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -1098,10 +1183,8 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-       if (list)
-       {
-               contacts_list_destroy(list,true);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_list_destroy(list,true);
        return;
 }
 
@@ -1113,8 +1196,15 @@ void ctsvc_ipc_server_db_delete_records(pims_ipc_h ipc, pims_ipc_data_h indata,
        int *ids = NULL;
        char *uri = NULL;
        int i = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_string(indata,&uri);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_string fail");
@@ -1148,7 +1238,7 @@ void ctsvc_ipc_server_db_delete_records(pims_ipc_h ipc, pims_ipc_data_h indata,
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_delete_records(uri, ids, count);
+       ret = ctsvc_db_delete_records(uri, ids, count);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -1197,6 +1287,7 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
+       ctsvc_handle_destroy(contact);
        CONTACTS_FREE(uri);
        CONTACTS_FREE(ids);
        return;
@@ -1210,8 +1301,15 @@ void ctsvc_ipc_server_db_replace_records(pims_ipc_h ipc, pims_ipc_data_h indata,
        int count = 0;
        int *ids = NULL;
        int i=0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_list(indata, &list);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_list fail");
@@ -1309,9 +1407,8 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-       if (list) {
-               contacts_list_destroy(list,true);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_list_destroy(list,true);
        CONTACTS_FREE(ids);
        return;
 }
@@ -1324,8 +1421,15 @@ void ctsvc_ipc_server_db_get_changes_by_version(pims_ipc_h ipc, pims_ipc_data_h
        int contacts_db_version = 0;
        contacts_list_h record_list = NULL;
        int current_contacts_db_version = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+
                ret = ctsvc_ipc_unmarshal_string(indata,&view_uri);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_string fail");
@@ -1352,7 +1456,7 @@ void ctsvc_ipc_server_db_get_changes_by_version(pims_ipc_h ipc, pims_ipc_data_h
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_get_changes_by_version(view_uri, address_book_id,contacts_db_version,&record_list,&current_contacts_db_version);
+       ret = ctsvc_db_get_changes_by_version(view_uri, address_book_id,contacts_db_version,&record_list,&current_contacts_db_version);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -1412,10 +1516,8 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-       if (record_list)
-       {
-               contacts_list_destroy(record_list,true);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_list_destroy(record_list,true);
        CONTACTS_FREE(view_uri);
        return;
 }
@@ -1424,6 +1526,15 @@ void ctsvc_ipc_server_db_get_current_version(pims_ipc_h ipc, pims_ipc_data_h ind
 {
        int ret = CONTACTS_ERROR_NONE;
        int contacts_db_version = 0;
+       contacts_h contact = NULL;
+
+       if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+       }
 
        if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_READ) &&
                        !ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_READ)) {
@@ -1431,20 +1542,20 @@ void ctsvc_ipc_server_db_get_current_version(pims_ipc_h ipc, pims_ipc_data_h ind
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_get_current_version(&contacts_db_version);
+       ret = ctsvc_db_get_current_version(&contacts_db_version);
 
 ERROR_RETURN:
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
 
                if (CONTACTS_ERROR_NO_DATA == ret) {
@@ -1454,13 +1565,16 @@ ERROR_RETURN:
                        ret = ctsvc_ipc_marshal_int(contacts_db_version,*outdata);
                        if (ret != CONTACTS_ERROR_NONE) {
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
+
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -1472,8 +1586,14 @@ void ctsvc_ipc_server_db_search_records(pims_ipc_h ipc, pims_ipc_data_h indata,
        int offset = 0;
        int limit = 0;
        contacts_list_h list = NULL;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_string(indata,&view_uri);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -1505,7 +1625,7 @@ void ctsvc_ipc_server_db_search_records(pims_ipc_h ipc, pims_ipc_data_h indata,
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_search_records(view_uri, keyword, offset,limit,&list);
+       ret = ctsvc_db_search_records(view_uri, keyword, offset,limit,&list);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -1555,11 +1675,8 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-
-       if (list)
-       {
-               contacts_list_destroy(list,true);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_list_destroy(list,true);
        CONTACTS_FREE(view_uri);
        CONTACTS_FREE(keyword);
        return;
@@ -1574,8 +1691,14 @@ void ctsvc_ipc_server_db_search_records_with_range(pims_ipc_h ipc, pims_ipc_data
        int limit = 0;
        int range = 0;
        contacts_list_h list = NULL;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_string(indata,&view_uri);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -1612,7 +1735,7 @@ void ctsvc_ipc_server_db_search_records_with_range(pims_ipc_h ipc, pims_ipc_data
                goto ERROR_RETURN;
        }
 
-       ret = contacts_db_search_records_with_range(view_uri, keyword, offset,limit,range, &list);
+       ret = ctsvc_db_search_records_with_range(view_uri, keyword, offset,limit,range, &list);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -1663,9 +1786,8 @@ ERROR_RETURN:
        }
 
 DATA_FREE:
-
-       if (list)
-               contacts_list_destroy(list,true);
+       ctsvc_handle_destroy(contact);
+       contacts_list_destroy(list,true);
        free(view_uri);
        free(keyword);
        return;
@@ -1679,8 +1801,14 @@ void ctsvc_ipc_server_db_search_records_with_query(pims_ipc_h ipc, pims_ipc_data
        int offset = 0;
        int limit = 0;
        contacts_list_h list = NULL;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_query(indata,&query);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_record fail");
@@ -1714,7 +1842,7 @@ void ctsvc_ipc_server_db_search_records_with_query(pims_ipc_h ipc, pims_ipc_data
        }
 
 
-       ret = contacts_db_search_records_with_query(query, keyword, offset,limit,&list);
+       ret = ctsvc_db_search_records_with_query(query, keyword, offset,limit,&list);
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
@@ -1764,17 +1892,10 @@ ERROR_RETURN:
                CTS_ERR("outdata is NULL");
        }
 DATA_FREE:
-
-       if (list)
-       {
-               contacts_list_destroy(list,true);
-       }
-       if (query)
-       {
-               contacts_query_destroy(query);
-       }
+       ctsvc_handle_destroy(contact);
+       contacts_list_destroy(list,true);
+       contacts_query_destroy(query);
        CONTACTS_FREE(keyword);
-
        return;
 }
 
@@ -1783,30 +1904,45 @@ void ctsvc_ipc_server_db_get_status(pims_ipc_h ipc, pims_ipc_data_h indata,
 {
        int ret = CONTACTS_ERROR_NONE;
        contacts_db_status_e status;
+       contacts_h contact = NULL;
 
-       RETM_IF(outdata == NULL, "outdata is NULL");
-
-       *outdata = pims_ipc_data_create(0);
-       if (!*outdata) {
-               CTS_ERR("pims_ipc_data_create fail");
-               return;
+       if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
        }
 
-       ret = contacts_db_get_status(&status);
-       if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
-               pims_ipc_data_destroy(*outdata);
-               *outdata = NULL;
-               CTS_ERR("pims_ipc_data_put fail (return value)");
-               return;
-       }
+       ret = ctsvc_db_get_status(&status);
 
-       if (pims_ipc_data_put(*outdata, (void*)&status, sizeof(int)) != 0) {
-               pims_ipc_data_destroy(*outdata);
-               *outdata = NULL;
-               CTS_ERR("pims_ipc_data_put fail (id)");
-               return;
-       }
+ERROR_RETURN:
+       if (outdata) {
+               *outdata = pims_ipc_data_create(0);
+               if (NULL == *outdata) {
+                       CTS_ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
 
+               if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       CTS_ERR("pims_ipc_data_put fail (return value)");
+                       goto DATA_FREE;
+               }
+
+               if (pims_ipc_data_put(*outdata, (void*)&status, sizeof(int)) != 0) {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       CTS_ERR("pims_ipc_data_put fail (id)");
+                       goto DATA_FREE;
+               }
+       }
+       else {
+               CTS_ERR("outdata is NULL");
+       }
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
index 251f2e1..6685cb6 100644 (file)
 
 #include "ctsvc_server_service.h"
 #include "ctsvc_db_init.h"
-#include "ctsvc_db_access_control.h"
 
+#include "ctsvc_server_activity.h"
+#include "ctsvc_server_person.h"
+#include "ctsvc_server_group.h"
+#include "ctsvc_server_phonelog.h"
+#include "ctsvc_server_setting.h"
+
+#include "ctsvc_db_access_control.h"
 
 #include "ctsvc_ipc_marshal.h"
 #include "ctsvc_internal.h"
 #include "ctsvc_ipc_server.h"
 #include "ctsvc_db_utils.h"
+#include "ctsvc_handle.h"
 
 void ctsvc_ipc_activity_delete_by_contact_id(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
 {
        int ret = CONTACTS_ERROR_NONE;
        int contact_id = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &contact_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -55,7 +68,7 @@ void ctsvc_ipc_activity_delete_by_contact_id(pims_ipc_h ipc, pims_ipc_data_h ind
                ret = CONTACTS_ERROR_PERMISSION_DENIED;
                goto ERROR_RETURN;
        }
-       ret = contacts_activity_delete_by_contact_id(contact_id);
+       ret = ctsvc_activity_delete_by_contact_id(contact_id);
 
 
 ERROR_RETURN:
@@ -64,13 +77,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
 
                if (ret == CONTACTS_ERROR_NONE) {
@@ -79,14 +92,15 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -94,8 +108,14 @@ void ctsvc_ipc_activity_delete_by_account_id(pims_ipc_h ipc, pims_ipc_data_h ind
 {
        int ret = CONTACTS_ERROR_NONE;
        int account_id = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &account_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -111,7 +131,7 @@ void ctsvc_ipc_activity_delete_by_account_id(pims_ipc_h ipc, pims_ipc_data_h ind
                ret = CONTACTS_ERROR_PERMISSION_DENIED;
                goto ERROR_RETURN;
        }
-       ret = contacts_activity_delete_by_account_id(account_id);
+       ret = ctsvc_activity_delete_by_account_id(account_id);
 
 ERROR_RETURN:
 
@@ -119,13 +139,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
 
                if (ret == CONTACTS_ERROR_NONE) {
@@ -134,14 +154,15 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -150,8 +171,14 @@ void ctsvc_ipc_group_add_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ip
        int ret = CONTACTS_ERROR_NONE;
        int group_id = 0;
        int contact_id = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &group_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -173,7 +200,7 @@ void ctsvc_ipc_group_add_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ip
                goto ERROR_RETURN;
        }
 
-       ret = contacts_group_add_contact(group_id, contact_id);
+       ret = ctsvc_group_add_contact(group_id, contact_id);
 
 ERROR_RETURN:
 
@@ -181,13 +208,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
 
                if (ret == CONTACTS_ERROR_NONE) {
@@ -196,14 +223,15 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -212,8 +240,14 @@ void ctsvc_ipc_group_remove_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims
        int ret = CONTACTS_ERROR_NONE;
        int group_id = 0;
        int contact_id = 0;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &group_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -236,7 +270,7 @@ void ctsvc_ipc_group_remove_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims
        }
 
 
-       ret = contacts_group_remove_contact(group_id, contact_id);
+       ret = ctsvc_group_remove_contact(group_id, contact_id);
 
 ERROR_RETURN:
 
@@ -244,13 +278,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (ret == CONTACTS_ERROR_NONE) {
                        int transaction_ver = ctsvc_get_transaction_ver();
@@ -258,7 +292,7 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
 
@@ -266,7 +300,8 @@ ERROR_RETURN:
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -277,7 +312,13 @@ void ctsvc_ipc_group_set_group_order(pims_ipc_h ipc, pims_ipc_data_h indata, pim
        int previous_group_id;
        int next_group_id;
 
+       contacts_h contact = NULL;
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &group_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -304,7 +345,7 @@ void ctsvc_ipc_group_set_group_order(pims_ipc_h ipc, pims_ipc_data_h indata, pim
                goto ERROR_RETURN;
        }
 
-       ret = contacts_group_set_group_order(group_id, previous_group_id, next_group_id);
+       ret = ctsvc_group_set_group_order(group_id, previous_group_id, next_group_id);
 
 ERROR_RETURN:
 
@@ -312,13 +353,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (ret == CONTACTS_ERROR_NONE) {
                        int transaction_ver = ctsvc_get_transaction_ver();
@@ -326,14 +367,15 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -343,7 +385,13 @@ void ctsvc_ipc_person_link_person(pims_ipc_h ipc, pims_ipc_data_h indata, pims_i
        int base_person_id = 0;
        int person_id = 0;
 
+       contacts_h contact = NULL;
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &base_person_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -365,7 +413,7 @@ void ctsvc_ipc_person_link_person(pims_ipc_h ipc, pims_ipc_data_h indata, pims_i
                goto ERROR_RETURN;
        }
 
-       ret = contacts_person_link_person(base_person_id, person_id);
+       ret = ctsvc_person_link_person(base_person_id, person_id);
 
 ERROR_RETURN:
 
@@ -373,13 +421,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (ret == CONTACTS_ERROR_NONE) {
                        int transaction_ver = ctsvc_get_transaction_ver();
@@ -387,14 +435,15 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 void ctsvc_ipc_person_unlink_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
@@ -403,7 +452,13 @@ void ctsvc_ipc_person_unlink_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pim
        int person_id = 0;
        int contact_id = 0;
 
+       contacts_h contact = NULL;
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -426,7 +481,7 @@ void ctsvc_ipc_person_unlink_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pim
        }
 
        int unlinked_person_id;
-       ret = contacts_person_unlink_contact(person_id, contact_id, &unlinked_person_id);
+       ret = ctsvc_person_unlink_contact(person_id, contact_id, &unlinked_person_id);
 
 ERROR_RETURN:
 
@@ -434,13 +489,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (ret == CONTACTS_ERROR_NONE) {
                        int transaction_ver = ctsvc_get_transaction_ver();
@@ -448,20 +503,22 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
                if (pims_ipc_data_put(*outdata, (void*)&unlinked_person_id, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
                }
 
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 void ctsvc_ipc_person_reset_usage(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
@@ -469,8 +526,14 @@ void ctsvc_ipc_person_reset_usage(pims_ipc_h ipc, pims_ipc_data_h indata, pims_i
        int ret = CONTACTS_ERROR_NONE;
        int person_id = 0;
        contacts_usage_type_e type;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -494,7 +557,7 @@ void ctsvc_ipc_person_reset_usage(pims_ipc_h ipc, pims_ipc_data_h indata, pims_i
                goto ERROR_RETURN;
        }
 
-       ret = contacts_person_reset_usage(person_id, type);
+       ret = ctsvc_person_reset_usage(person_id, type);
 
 ERROR_RETURN:
 
@@ -502,13 +565,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (ret == CONTACTS_ERROR_NONE) {
                        int transaction_ver = ctsvc_get_transaction_ver();
@@ -516,14 +579,15 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 void ctsvc_ipc_person_set_favorite_order(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
@@ -532,8 +596,14 @@ void ctsvc_ipc_person_set_favorite_order(pims_ipc_h ipc, pims_ipc_data_h indata,
        int person_id = 0;
        int previous_person_id;
        int next_person_id;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -560,7 +630,7 @@ void ctsvc_ipc_person_set_favorite_order(pims_ipc_h ipc, pims_ipc_data_h indata,
                goto ERROR_RETURN;
        }
 
-       ret = contacts_person_set_favorite_order(person_id, previous_person_id, next_person_id);
+       ret = ctsvc_person_set_favorite_order(person_id, previous_person_id, next_person_id);
 
 ERROR_RETURN:
 
@@ -568,13 +638,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (ret == CONTACTS_ERROR_NONE) {
                        int transaction_ver = ctsvc_get_transaction_ver();
@@ -582,14 +652,15 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -599,8 +670,14 @@ void ctsvc_ipc_person_set_default_property(pims_ipc_h ipc, pims_ipc_data_h indat
        int person_id = 0;
        int id;
        contacts_person_property_e property;
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -622,7 +699,7 @@ void ctsvc_ipc_person_set_default_property(pims_ipc_h ipc, pims_ipc_data_h indat
                goto ERROR_RETURN;
        }
 
-       ret = contacts_person_set_default_property(property, person_id, id);
+       ret = ctsvc_person_set_default_property(property, person_id, id);
 
 ERROR_RETURN:
 
@@ -630,13 +707,13 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (ret == CONTACTS_ERROR_NONE) {
                        int transaction_ver = ctsvc_get_transaction_ver();
@@ -644,14 +721,15 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -662,8 +740,13 @@ void ctsvc_ipc_person_get_default_property(pims_ipc_h ipc, pims_ipc_data_h indat
        int person_id = 0;
        int id;
        contacts_person_property_e op;
-
+       contacts_h contact = NULL;
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
@@ -685,7 +768,7 @@ void ctsvc_ipc_person_get_default_property(pims_ipc_h ipc, pims_ipc_data_h indat
                goto ERROR_RETURN;
        }
 
-       ret = contacts_person_get_default_property(op, person_id, &id);
+       ret = ctsvc_person_get_default_property(op, person_id, &id);
 
 ERROR_RETURN:
 
@@ -693,25 +776,26 @@ ERROR_RETURN:
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail (return value)");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&id, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail (id)");
-                       return;
+                       goto DATA_FREE;
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -719,26 +803,35 @@ ERROR_RETURN:
 void ctsvc_ipc_phone_log_reset_statistics(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
 {
        int ret;
+       contacts_h contact = NULL;
+
+       if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
+       }
 
        if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_WRITE)) {
                ret = CONTACTS_ERROR_PERMISSION_DENIED;
                goto ERROR_RETURN;
        }
 
-       ret = contacts_phone_log_reset_statistics();
+       ret = ctsvc_phone_log_reset_statistics();
 
 ERROR_RETURN:
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
                if (NULL == *outdata) {
                        CTS_ERR("pims_ipc_data_create fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
                        pims_ipc_data_destroy(*outdata);
                        *outdata = NULL;
                        CTS_ERR("pims_ipc_data_put fail");
-                       return;
+                       goto DATA_FREE;
                }
                if (ret == CONTACTS_ERROR_NONE) {
                        int transaction_ver = ctsvc_get_transaction_ver();
@@ -746,14 +839,15 @@ ERROR_RETURN:
                                pims_ipc_data_destroy(*outdata);
                                *outdata = NULL;
                                CTS_ERR("ctsvc_ipc_marshal_int fail");
-                               return;
+                               goto DATA_FREE;
                        }
                }
        }
        else {
                CTS_ERR("outdata is NULL");
        }
-
+DATA_FREE:
+       ctsvc_handle_destroy(contact);
        return;
 }
 
@@ -764,17 +858,23 @@ void ctsvc_ipc_phone_log_delete(pims_ipc_h ipc, pims_ipc_data_h indata,
        int extra_data1;
        char *number = NULL;
        contacts_phone_log_delete_e op;
-
-       if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_WRITE)) {
-               ret = CONTACTS_ERROR_PERMISSION_DENIED;
-               goto ERROR_RETURN;
-       }
+       contacts_h contact = NULL;
 
        if (indata) {
+               ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       CTS_ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
+                       goto ERROR_RETURN;
+               }
                ret = ctsvc_ipc_unmarshal_int(indata, (int*)&op);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("ctsvc_ipc_unmarshal_int fail");
                        goto ERROR_RETURN;
+       if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_WRITE)) {
+               ret = CONTACTS_ERROR_PERMISSION_DENIED;
+               goto ERROR_RETURN;
+       }
+
                }
 
                switch(op) {
@@ -784,7 +884,7 @@ void ctsvc_ipc_phone_log_delete(pims_ipc_h ipc, pims_ipc_data_h indata,
                                CTS_ERR("ctsvc_ipc_unmarshal_string fail");
                                goto ERROR_RETURN;
                        }
-                       ret = contacts_phone_log_delete(op, number);
+                       ret = ctsvc_phone_log_delete(op, number);
                        break;
                case CONTACTS_PHONE_LOG_DELETE_BY_MESSAGE_EXTRA_DATA1:
                case CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1:
@@ -793,7 +893,7 @@ void ctsvc_ipc_phone_log_delete(pims_ipc_h ipc, pims_ipc_data_h indata,
                                CTS_ERR("ctsvc_ipc_unmarshal_int fail");
                                goto ERROR_RETURN;
                        }
-                       ret = contacts_phone_log_delete(op, extra_data1);
+                       ret = ctsvc_phone_log_delete(op, extra_data1);
                        break;
                default:
                        CTS_ERR("Invalid parameter : the operation is not proper (op : %d)", op);
@@ -826,6 +926,7 @@ ERROR_RETURN:
                }
        }
 DATA_FREE:
+       ctsvc_handle_destroy(contact);
        free(number);
 
        return;
@@ -843,7 +944,7 @@ void ctsvc_ipc_setting_get_name_display_order(pims_ipc_h ipc, pims_ipc_data_h in
                goto ERROR_RETURN;
        }
 
-       ret = contacts_setting_get_name_display_order(&order);
+       ret = ctsvc_setting_get_name_display_order(&order);
 
 ERROR_RETURN:
        if (outdata) {
@@ -883,7 +984,7 @@ void ctsvc_ipc_setting_get_name_sorting_order(pims_ipc_h ipc, pims_ipc_data_h in
                goto ERROR_RETURN;
        }
 
-       ret = contacts_setting_get_name_sorting_order(&order);
+       ret = ctsvc_setting_get_name_sorting_order(&order);
 
 ERROR_RETURN:
        if (outdata) {
@@ -935,7 +1036,7 @@ void ctsvc_ipc_setting_set_name_display_order(pims_ipc_h ipc,
                goto ERROR_RETURN;
        }
 
-       ret = contacts_setting_set_name_display_order((contacts_name_display_order_e)order);
+       ret = ctsvc_setting_set_name_display_order((contacts_name_display_order_e)order);
 
 ERROR_RETURN:
        if (outdata) {
@@ -981,7 +1082,7 @@ void ctsvc_ipc_setting_set_name_sorting_order(pims_ipc_h ipc,
                goto ERROR_RETURN;
        }
 
-       ret = contacts_setting_set_name_sorting_order((contacts_name_sorting_order_e)order);
+       ret = ctsvc_setting_set_name_sorting_order((contacts_name_sorting_order_e)order);
 
 ERROR_RETURN:
        if (outdata) {
index dbeb924..72f5905 100644 (file)
@@ -487,7 +487,7 @@ static char *langset = NULL;
 
 char* ctsvc_get_langset()
 {
-       return langset;
+       return SAFE_STR(langset);
 }
 
 void ctsvc_set_langset(char *new_langset)
index cff745e..1e3c064 100644 (file)
@@ -36,6 +36,8 @@
 #include "ctsvc_server_utils.h"
 #include "ctsvc_server_bg.h"
 #include "ctsvc_server_update.h"
+#include "ctsvc_server_service.h"
+
 #include "ctsvc_db_access_control.h"
 
 #include "ctsvc_ipc_define.h"
@@ -108,7 +110,7 @@ static int __server_main(void)
                snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s_for_subscribe", getuid(), CTSVC_IPC_SERVICE);
                pims_ipc_svc_init_for_publish(sock_file, CTS_SECURITY_FILE_GROUP, 0660);
 
-               ret = contacts_connect();
+               ret = ctsvc_connect();
                if (CONTACTS_ERROR_NONE != ret) {
                        CTS_ERR("contacts_connect fail(%d)", ret);
                        break;
@@ -132,7 +134,7 @@ static int __server_main(void)
 
                ctsvc_unset_client_access_info();
 
-               ret = contacts_disconnect();
+               ret = ctsvc_disconnect();
                if (CONTACTS_ERROR_NONE != ret)
                        CTS_DBG("%d", ret);
 
@@ -168,8 +170,7 @@ void ctsvc_create_file_set_permission(const char* file, mode_t mode)
 
 void ctsvc_create_rep_set_permission(const char* directory, mode_t mode)
 {
-       if (-1 == access (directory, F_OK))
-       {
+       if (-1 == access (directory, F_OK)) {
                mkdir(directory, mode);
        }
 }
index 783f09c..8b589d4 100644 (file)
@@ -26,7 +26,7 @@
 #include "ctsvc_notification.h"
 #include "ctsvc_db_access_control.h"
 
-API int contacts_activity_delete_by_contact_id(int contact_id)
+int ctsvc_activity_delete_by_contact_id(int contact_id)
 {
        char query[CTS_SQL_MAX_LEN] = {0};
 
@@ -51,7 +51,7 @@ API int contacts_activity_delete_by_contact_id(int contact_id)
        return ret;
 }
 
-API int contacts_activity_delete_by_account_id(int account_id)
+int ctsvc_activity_delete_by_account_id(int account_id)
 {
        char query[CTS_SQL_MAX_LEN] = {0};
 
index b9b379f..266db54 100644 (file)
@@ -20,4 +20,8 @@
 #ifndef __CTSVC_SERVER_ACTIVITY_H__
 #define __CTSVC_SERVER_ACTIVITY_H__
 
+int ctsvc_activity_delete_by_contact_id(int contact_id);
+int ctsvc_activity_delete_by_account_id(int account_id);
+
+
 #endif /* __CTSVC_SERVER_ACTIVITY_H__ */
index 44310bd..c4521f4 100644 (file)
 
 #include "contacts.h"
 #include "ctsvc_internal.h"
+#include "ctsvc_inotify.h"
+#include "ctsvc_handle.h"
 #include "ctsvc_db_schema.h"
 #include "ctsvc_db_sqlite.h"
+#include "ctsvc_server_service.h"
 #include "ctsvc_server_bg.h"
 #include "ctsvc_server_utils.h"
 #include "ctsvc_db_utils.h"
@@ -58,6 +61,7 @@ GCond __ctsvc_server_bg_delete_cond;
 GMutex __ctsvc_server_bg_delete_mutex;
 
 account_subscribe_h account = NULL;
+contacts_h bg_contact;
 
 static int __ctsvc_server_bg_contact_delete_step1(__ctsvc_delete_data_s* data)
 {
@@ -339,8 +343,7 @@ static process_stat* __ctsvc_get_cpu_stat()
        }
 
        result = calloc(1, sizeof(process_stat));
-       if (NULL == result)
-       {
+       if (NULL == result) {
                CTS_ERR("calloc() Fail");
                return NULL;
        }
@@ -397,7 +400,7 @@ static gpointer __ctsvc_server_bg_delete(gpointer user_data)
                }
                callback_data->step = STEP_1;
 
-               ret = contacts_connect();
+               ret = ctsvc_connect();
                if (CONTACTS_ERROR_NONE != ret) {
                        CTS_ERR("contacts_connect() fail(%d)", ret);
                        free(callback_data);
@@ -420,7 +423,7 @@ static gpointer __ctsvc_server_bg_delete(gpointer user_data)
 
                ctsvc_unset_client_access_info();
 
-               ret = contacts_disconnect();
+               ret = ctsvc_disconnect();
                if (CONTACTS_ERROR_NONE != ret)
                        CTS_ERR("contacts_disconnect Fail(%d)", ret);
 
@@ -473,10 +476,12 @@ 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);
-       CTS_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);
-       CTS_DBG("call contacts_db_add_changed_cb (_contacts_contact): return (%d)", ret);
+       ctsvc_handle_create(&bg_contact);
+       ret = ctsvc_inotify_subscribe(bg_contact, _contacts_address_book._uri, __ctsvc_server_addressbook_deleted_cb, NULL);
+       CTS_DBG("call ctsvc_inotify_subscribe (_contacts_address_book)  : return (%d)", ret);
+
+       ret = ctsvc_inotify_subscribe(bg_contact, _contacts_contact._uri, __ctsvc_server_contact_deleted_cb, NULL);
+       CTS_DBG("call ctsvc_inotify_subscribe (_contacts_contact): return (%d)", ret);
 
        ret = account_subscribe_create(&account);
        if (ACCOUNT_ERROR_NONE == ret) {
@@ -492,10 +497,11 @@ void ctsvc_server_bg_add_cb()
 void ctsvc_server_bg_remove_cb()
 {
        int ret;
-       ret = contacts_db_remove_changed_cb(_contacts_address_book._uri, __ctsvc_server_addressbook_deleted_cb, NULL);
-       CTS_ERR("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);
-       CTS_ERR("call contacts_db_remove_changed_cb (_contacts_contact) : return (%d)", ret);
+
+       ret = ctsvc_inotify_unsubscribe(bg_contact, _contacts_address_book._uri, __ctsvc_server_addressbook_deleted_cb, NULL);
+       CTS_ERR("call ctsvc_inotify_unsubscribe (_contacts_address_book): return (%d)", ret);
+       ret = ctsvc_inotify_unsubscribe(bg_contact, _contacts_contact._uri, __ctsvc_server_contact_deleted_cb, NULL);
+       CTS_ERR("call ctsvc_inotify_unsubscribe (_contacts_contact) : return (%d)", ret);
 
        if (account) {
                account_unsubscribe_notification(account);  /* unsubscirbe & destroy */
index 8a4f889..ec709c5 100644 (file)
@@ -94,7 +94,7 @@ void ctsvc_change_subject_add_changed_phone_log_id(contacts_changed_e type, int
        int info_len = 0;
        char changed_info[30] = {0};
 
-       if (!__phone_log_chanaged_info) {
+       if (NULL == __phone_log_chanaged_info) {
                __phone_log_chanaged_info = (char*)calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char));
                __phone_log_buf_size = CTSVC_SUBSCRIBE_MAX_LEN;
                __phone_log_chanaged_info[0] = '\0';
index 9552969..1854864 100644 (file)
@@ -94,7 +94,7 @@ int ctsvc_group_add_contact_in_transaction(int group_id, int contact_id)
        return ret;
 }
 
-API int contacts_group_add_contact(int group_id, int contact_id)
+int ctsvc_group_add_contact(int group_id, int contact_id)
 {
        int ret;
        int addressbook_id;
@@ -189,7 +189,7 @@ int ctsvc_group_remove_contact_in_transaction(int group_id, int contact_id)
        return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_group_remove_contact(int group_id, int contact_id)
+int ctsvc_group_remove_contact(int group_id, int contact_id)
 {
        int ret;
        int addressbook_id;
@@ -251,7 +251,7 @@ API int contacts_group_remove_contact(int group_id, int contact_id)
 }
 
 
-API int contacts_group_set_group_order(int group_id, int previous_group_id, int next_group_id)
+int ctsvc_group_set_group_order(int group_id, int previous_group_id, int next_group_id)
 {
        int ret;
        double previous_prio = 0.0;
index 42f858f..c2c9506 100644 (file)
 #define __CTSVC_SERVER_GROUP_H__
 
 int ctsvc_group_add_contact_in_transaction(int group_id, int contact_id);
-
 int ctsvc_group_remove_contact_in_transaction(int group_id, int contact_id);
+int ctsvc_group_add_contact(int group_id, int contact_id);
+int ctsvc_group_remove_contact(int group_id, int contact_id);
+int ctsvc_group_set_group_order(int group_id, int previous_group_id, int next_group_id);
+
+
 /*
 int ctsvc_group_add_contacts_in_person(int group_id, int person_id);
 int ctsvc_group_remove_contacts_in_person(int group_id, int person_id);
index fa7bdec..4216a4f 100644 (file)
@@ -916,7 +916,7 @@ static bool __ctsvc_get_person_favorite_info(int person_id, double *priority)
        return false;
 }
 
-API int contacts_person_link_person(int base_person_id, int person_id)
+int ctsvc_person_link_person(int base_person_id, int person_id)
 {
        int ret;
        char query[CTS_SQL_MIN_LEN] = {0};
@@ -1177,7 +1177,7 @@ static int __ctsvc_update_primary_default_data(int person_id)
        return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_person_unlink_contact(int person_id, int contact_id, int* out_person_id)
+int ctsvc_person_unlink_contact(int person_id, int contact_id, int* out_person_id)
 {
        int ret;
        int id;
@@ -1319,7 +1319,7 @@ int ctsvc_person_do_garbage_collection(void)
        return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_person_reset_usage(int person_id, contacts_usage_type_e type)
+int ctsvc_person_reset_usage(int person_id, contacts_usage_type_e type)
 {
        int ret ;
        char query[CTS_SQL_MAX_LEN] = {0};
@@ -1349,7 +1349,7 @@ API int contacts_person_reset_usage(int person_id, contacts_usage_type_e type)
                return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_person_set_favorite_order(int person_id, int front_person_id, int back_person_id)
+int ctsvc_person_set_favorite_order(int person_id, int front_person_id, int back_person_id)
 {
        int ret;
        double front_prio = 0.0;
@@ -1407,7 +1407,7 @@ API int contacts_person_set_favorite_order(int person_id, int front_person_id, i
                return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_person_set_default_property(contacts_person_property_e property, int person_id,
+int ctsvc_person_set_default_property(contacts_person_property_e property, int person_id,
                int id)
 {
        int ret;
@@ -1447,7 +1447,7 @@ API int contacts_person_set_default_property(contacts_person_property_e property
        return ret;
 }
 
-API int contacts_person_get_default_property(contacts_person_property_e property, int person_id,
+int ctsvc_person_get_default_property(contacts_person_property_e property, int person_id,
                int *id)
 {
        int ret = CONTACTS_ERROR_NONE;
index 5f02dd4..c949453 100644 (file)
 int ctsvc_person_do_garbage_collection(void);
 int ctsvc_person_aggregate(int person_id);
 void ctsvc_db_person_delete_callback(sqlite3_context * context, int argc, sqlite3_value ** argv);
+int ctsvc_person_link_person(int base_person_id, int person_id);
+int ctsvc_person_unlink_contact(int person_id, int contact_id, int* out_person_id );
+int ctsvc_person_reset_usage(int person_id, contacts_usage_type_e type);
+int ctsvc_person_set_favorite_order(int person_id, int front_person_id, int back_person_id);
+int ctsvc_person_set_default_property(contacts_person_property_e property, int person_id, int id);
+int ctsvc_person_get_default_property(contacts_person_property_e property, int person_id, int *id);
 
 #endif /* __CTSVC_SERVER_PERSON_H__ */
index 347a8fd..52ad39d 100644 (file)
 #include "ctsvc_server_sim.h"
 #endif /* _CONTACTS_IPC_SERVER */
 
-API int contacts_phone_log_reset_statistics()
+int ctsvc_phone_log_reset_statistics()
 {
        char query[CTS_SQL_MIN_LEN] = {0};
        snprintf(query, sizeof(query),"DELETE FROM "CTS_TABLE_PHONELOG_STAT);
        return ctsvc_query_exec(query);
 }
 
-API int contacts_phone_log_delete(contacts_phone_log_delete_e op, ...)
+int ctsvc_phone_log_delete(contacts_phone_log_delete_e op, ...)
 {
        int ret;
        int extra_data1;
index 67857c0..5ba8e1a 100644 (file)
 #define __CTSVC_SERVER_PHONELOG_H__
 
 #include "ctsvc_db_sqlite.h"
+#include "contacts_phone_log_internal.h"
+
+int ctsvc_phone_log_reset_statistics();
+int ctsvc_phone_log_delete(contacts_phone_log_delete_e op, ...);
 void ctsvc_db_phone_log_delete_callback(sqlite3_context * context,
                int argc, sqlite3_value ** argv);
 int ctsvc_db_phone_log_update_person_id(const char *number, int old_person_id, int candidate_person_id, bool person_link);
index af886e8..9433314 100644 (file)
@@ -38,7 +38,7 @@
 static int ctsvc_connection = 0;
 static __thread int thread_connection = 0;
 
-API int contacts_connect()
+int ctsvc_connect()
 {
        CTS_FN_CALL;
        int ret;
@@ -75,7 +75,7 @@ API int contacts_connect()
        return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_disconnect()
+int ctsvc_disconnect()
 {
        ctsvc_mutex_lock(CTS_MUTEX_CONNECTION);
 
index 1d986db..604701e 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef __CTSVC_SERVER_SERVICE_H__
 #define __CTSVC_SERVER_SERVICE_H__
 
+int ctsvc_connect();
+int ctsvc_disconnect();
 int ctsvc_contacts_internal_disconnect();
 
 #endif /*  __CTSVC_SERVER_SERVICE_H__ */
index 2b83196..535dee5 100644 (file)
 #include "ctsvc_server_change_subject.h"
 #endif
 
-#ifdef _CONTACTS_NATIVE
-static int __ctsvc_vconf_ref_count = 0;
-#endif
-
 static int primary_sort = -1;
 static int secondary_sort = -1;
 
@@ -52,7 +48,7 @@ static const char *CTSVC_VCONF_DISPLAY_ORDER = VCONFKEY_CONTACTS_SVC_NAME_DISPLA
 static const char *CTSVC_VCONF_SORTING_ORDER = VCONFKEY_CONTACTS_SVC_NAME_SORTING_ORDER;
 static const char *CTSVC_VCONF_PHONENUMBER_MIN_MATCH_DIGIT = VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT;
 
-API int contacts_setting_get_name_display_order(contacts_name_display_order_e *order)
+int ctsvc_setting_get_name_display_order(contacts_name_display_order_e *order)
 {
        int ret;
 
@@ -66,7 +62,7 @@ API int contacts_setting_get_name_display_order(contacts_name_display_order_e *o
        return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_setting_set_name_display_order(contacts_name_display_order_e order)
+int ctsvc_setting_set_name_display_order(contacts_name_display_order_e order)
 {
        int ret;
        RETVM_IF(CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST != order && CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST != order,
@@ -83,7 +79,7 @@ API int contacts_setting_set_name_display_order(contacts_name_display_order_e or
        return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *order)
+int ctsvc_setting_get_name_sorting_order(contacts_name_sorting_order_e *order)
 {
        int ret;
        if (name_sorting_order < 0) {
@@ -96,7 +92,7 @@ API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *o
        return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e order)
+int ctsvc_setting_set_name_sorting_order(contacts_name_sorting_order_e order)
 {
        int ret;
        RETVM_IF(CONTACTS_NAME_SORTING_ORDER_FIRSTLAST != order && CONTACTS_NAME_SORTING_ORDER_LASTFIRST != order,
@@ -149,11 +145,6 @@ int ctsvc_register_vconf(void)
 {
        int ret;
 
-#ifdef _CONTACTS_NATIVE
-       __ctsvc_vconf_ref_count++;
-       if (__ctsvc_vconf_ref_count != 1)
-               return;
-#endif
 
        // display order
        ret = vconf_get_int(CTSVC_VCONF_DISPLAY_ORDER, &name_display_order);
@@ -197,11 +188,6 @@ void ctsvc_deregister_vconf(void)
 {
        int ret;
 
-#ifdef _CONTACTS_NATIVE
-       __ctsvc_vconf_ref_count--;
-       if (__ctsvc_vconf_ref_count != 0)
-               return;
-#endif
 
        ret = vconf_ignore_key_changed(CTSVC_VCONF_DISPLAY_ORDER, ctsvc_vconf_display_order_cb);
        RETM_IF(ret<0,"vconf_ignore_key_changed(display order) Fail(%d)", ret);
@@ -217,6 +203,12 @@ int ctsvc_get_phonenumber_min_match_digit(void)
        return phonenumber_min_match_digit;
 }
 
+void ctsvc_set_phonenumber_min_match_digit(int min)
+{
+       phonenumber_min_match_digit = min;
+}
+
+
 const char* ctsvc_get_default_sort_vconfkey(void)
 {
        return "file/private/contacts-service/default_lang";
@@ -238,35 +230,3 @@ int ctsvc_get_secondary_sort(void)
        return secondary_sort;
 }
 
-#ifdef _CONTACTS_NATIVE
-API int contacts_setting_add_name_display_order_changed_cb(
-       contacts_setting_name_display_order_changed_cb cb, void* user_data)
-{
-       CTS_ERR("Please use contacts-service2 instead of contacts-service3");
-       return CONTACTS_ERROR_INTERNAL;
-}
-
-API int contacts_setting_remove_name_display_order_changed_cb(
-       contacts_setting_name_display_order_changed_cb cb, void* user_data)
-{
-       CTS_ERR("Please use contacts-service2 instead of contacts-service3");
-       return CONTACTS_ERROR_INTERNAL;
-
-}
-
-API int contacts_setting_add_name_sorting_order_changed_cb(
-       contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
-{
-       CTS_ERR("Please use contacts-service2 instead of contacts-service3");
-       return CONTACTS_ERROR_INTERNAL;
-}
-
-
-API int contacts_setting_remove_name_sorting_order_changed_cb(
-       contacts_setting_name_sorting_order_changed_cb cb, void* user_data)
-{
-       CTS_ERR("Please use contacts-service2 instead of contacts-service3");
-       return CONTACTS_ERROR_INTERNAL;
-}
-
-#endif
index e252a7f..bdc5eb7 100644 (file)
 #ifndef __CTSVC_SERVER_SETTING_H__
 #define __CTSVC_SERVER_SETTING_H__
 
+int ctsvc_setting_get_name_display_order(contacts_name_display_order_e *order);
+int ctsvc_setting_set_name_display_order(contacts_name_display_order_e order);
+int ctsvc_setting_get_name_sorting_order(contacts_name_sorting_order_e *order);
+int ctsvc_setting_set_name_sorting_order(contacts_name_sorting_order_e order);
+
 int ctsvc_register_vconf(void);
 void ctsvc_deregister_vconf(void);
 
 int ctsvc_get_phonenumber_min_match_digit(void);
+void ctsvc_set_phonenumber_min_match_digit(int min);
 int ctsvc_get_primary_sort(void);
 int ctsvc_get_secondary_sort(void);
 const char *ctsvc_get_default_sort_vconfkey(void);
index e2f469c..6015dd6 100644 (file)
@@ -39,6 +39,7 @@
 #include "ctsvc_db_utils.h"
 #include "ctsvc_list.h"
 #include "ctsvc_db_access_control.h"
+#include "ctsvc_db_query.h"
 
 /* #define CTSVC_SIM_FIELD_FULL_SUPPORT// support ANR,EMAIL2,3,NICK NAME */
 #define DEFAULT_ADDRESS_BOOK_ID 0
index b77a9ea..e7c2cd3 100644 (file)
@@ -450,7 +450,11 @@ int ctsvc_server_socket_init(void)
        RETVM_IF(-1 == sockfd, CONTACTS_ERROR_SYSTEM, "socket() Fail(errno = %d)", errno);
 
        ret = bind(sockfd, (struct sockaddr *)&addr, sizeof(addr));
-       RETVM_IF(-1 == ret, CONTACTS_ERROR_SYSTEM, "bind() Fail(errno = %d)", errno);
+       if (-1 == ret){
+               close(sockfd);
+               CTS_ERR("bind() Failed(errno = %d)", errno);
+               return CONTACTS_ERROR_SYSTEM;
+       }
 
        ret = chown(sock_file, getuid(), CTS_SECURITY_FILE_GROUP);
        if (0 != ret)
index fd5449d..6cf060f 100644 (file)
@@ -37,9 +37,6 @@ static int __ctsvc_db_activity_update_record(contacts_record_h record);
 static int __ctsvc_db_activity_delete_record(int id);
 static int __ctsvc_db_activity_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_activity_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-/* static int __ctsvc_db_activity_insert_records(const contacts_list_h in_list, int **ds); */
-/* static int __ctsvc_db_activity_update_records(const contacts_list_h in_list); */
-/* static int __ctsvc_db_activity_delete_records(int ids[], int count); */
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_activity = {
        .is_query_only = false,
@@ -49,9 +46,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_activity = {
        .delete_record = __ctsvc_db_activity_delete_record,
        .get_all_records = __ctsvc_db_activity_get_all_records,
        .get_records_with_query = __ctsvc_db_activity_get_records_with_query,
-       .insert_records = NULL, //__ctsvc_db_activity_insert_records,
-       .update_records = NULL, //__ctsvc_db_activity_update_records,
-       .delete_records = NULL, //__ctsvc_db_activity_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -316,7 +313,7 @@ static int __ctsvc_db_activity_get_all_records(int offset, int limit,
                        return ret;
                }
                activity_id = ctsvc_stmt_get_int(stmt, 0);
-               ret = contacts_db_get_record(_contacts_activity._uri, activity_id, &record);
+               ret = ctsvc_db_get_record(_contacts_activity._uri, activity_id, &record);
                if (CONTACTS_ERROR_NONE != ret) {
                        CTS_ERR("DB error : contacts_db_get_record() Fail(%d)", ret);
                        ctsvc_stmt_finalize(stmt);
@@ -449,6 +446,3 @@ static int __ctsvc_db_activity_get_records_with_query(contacts_query_h query, in
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-//static int __ctsvc_db_activity_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_activity_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_activity_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 75e43a1..b4dd61d 100644 (file)
@@ -37,9 +37,6 @@ static int __ctsvc_db_address_update_record(contacts_record_h record);
 static int __ctsvc_db_address_delete_record(int id);
 static int __ctsvc_db_address_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_address_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_address_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_address_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_address_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_address = {
        .is_query_only = false,
@@ -49,9 +46,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_address = {
        .delete_record = __ctsvc_db_address_delete_record,
        .get_all_records = __ctsvc_db_address_get_all_records,
        .get_records_with_query = __ctsvc_db_address_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_address_insert_records,
-       .update_records = NULL,//__ctsvc_db_address_update_records,
-       .delete_records = NULL,//__ctsvc_db_address_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -429,7 +426,3 @@ static int __ctsvc_db_address_get_records_with_query(contacts_query_h query, int
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_address_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_address_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_address_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index df7d1e3..3095c34 100644 (file)
@@ -39,9 +39,6 @@ static int __ctsvc_db_addressbook_update_record(contacts_record_h record);
 static int __ctsvc_db_addressbook_delete_record(int id);
 static int __ctsvc_db_addressbook_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_addressbook_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_addressbook_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_addressbook_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_addressbook_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_addressbook = {
        .is_query_only = false,
@@ -51,9 +48,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_addressbook = {
        .delete_record = __ctsvc_db_addressbook_delete_record,
        .get_all_records = __ctsvc_db_addressbook_get_all_records,
        .get_records_with_query = __ctsvc_db_addressbook_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_addressbook_insert_records,
-       .update_records = NULL,//__ctsvc_db_addressbook_update_records,
-       .delete_records = NULL,//__ctsvc_db_addressbook_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -494,19 +491,3 @@ static int __ctsvc_db_addressbook_get_records_with_query(contacts_query_h query,
        return CONTACTS_ERROR_NONE;
 }
 
-#if 0
-static int __ctsvc_db_addressbook_insert_records(const contacts_list_h in_list, int **ids)
-{
-       return CONTACTS_ERROR_NONE;
-}
-
-static int __ctsvc_db_addressbook_update_records(const contacts_list_h in_list)
-{
-       return CONTACTS_ERROR_NONE;
-}
-
-static int __ctsvc_db_addressbook_delete_records(int ids[], int count)
-{
-       return CONTACTS_ERROR_NONE;
-}
-#endif
index 5ee1518..e10702e 100644 (file)
@@ -39,9 +39,6 @@ static int __ctsvc_db_company_update_record(contacts_record_h record);
 static int __ctsvc_db_company_delete_record(int id);
 static int __ctsvc_db_company_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_company_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_company_insert_records(const contacts_list_h in_list, int **ds);
-//static int __ctsvc_db_company_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_company_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_company = {
        .is_query_only = false,
@@ -51,9 +48,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_company = {
        .delete_record = __ctsvc_db_company_delete_record,
        .get_all_records = __ctsvc_db_company_get_all_records,
        .get_records_with_query = __ctsvc_db_company_get_records_with_query,
-       .insert_records = NULL, /* __ctsvc_db_company_insert_records, */
-       .update_records = NULL, /* __ctsvc_db_company_update_records, */
-       .delete_records = NULL, /* __ctsvc_db_company_delete_records, */
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -455,7 +452,3 @@ static int __ctsvc_db_company_get_records_with_query(contacts_query_h query, int
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_company_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_company_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_company_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 05d9287..0982b1e 100644 (file)
@@ -57,9 +57,6 @@ static int __ctsvc_db_contact_replace_record(contacts_record_h record, int id);
 
 static int __ctsvc_db_contact_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_contact_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_contact_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_contact_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_contact_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_contact = {
        .is_query_only = false,
@@ -69,9 +66,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_contact = {
        .delete_record = __ctsvc_db_contact_delete_record,
        .get_all_records = __ctsvc_db_contact_get_all_records,
        .get_records_with_query = __ctsvc_db_contact_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_contact_insert_records,
-       .update_records = NULL,//__ctsvc_db_contact_update_records,
-       .delete_records = NULL,//__ctsvc_db_contact_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = __ctsvc_db_contact_replace_record,
@@ -1626,11 +1623,6 @@ static int __ctsvc_db_contact_get_records_with_query(contacts_query_h query, int
        return CONTACTS_ERROR_NONE;
 }
 
-/*
- * static int __ctsvc_db_contact_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
- * static int __ctsvc_db_contact_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
- * static int __ctsvc_db_contact_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
- */
 
 static int __ctsvc_contact_insert_data(ctsvc_contact_s *contact)
 {
index 885a5e4..4fa4677 100644 (file)
@@ -37,9 +37,6 @@ static int __ctsvc_db_email_update_record(contacts_record_h record);
 static int __ctsvc_db_email_delete_record(int id);
 static int __ctsvc_db_email_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_email_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_email_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_email_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_email_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_email = {
        .is_query_only = false,
@@ -49,9 +46,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_email = {
        .delete_record = __ctsvc_db_email_delete_record,
        .get_all_records = __ctsvc_db_email_get_all_records,
        .get_records_with_query = __ctsvc_db_email_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_email_insert_records,
-       .update_records = NULL,//__ctsvc_db_email_update_records,
-       .delete_records = NULL,//__ctsvc_db_email_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -598,7 +595,3 @@ static int __ctsvc_db_email_get_records_with_query(contacts_query_h query, int o
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_email_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_email_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_email_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 3416c91..425f547 100644 (file)
@@ -37,9 +37,6 @@ static int __ctsvc_db_event_update_record(contacts_record_h record);
 static int __ctsvc_db_event_delete_record(int id);
 static int __ctsvc_db_event_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_event_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_event_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_event_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_event_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_event = {
        .is_query_only = false,
@@ -49,9 +46,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_event = {
        .delete_record = __ctsvc_db_event_delete_record,
        .get_all_records = __ctsvc_db_event_get_all_records,
        .get_records_with_query = __ctsvc_db_event_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_event_insert_records,
-       .update_records = NULL,//__ctsvc_db_event_update_records,
-       .delete_records = NULL,//__ctsvc_db_event_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -403,7 +400,3 @@ static int __ctsvc_db_event_get_records_with_query(contacts_query_h query, int o
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_event_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_event_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_event_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index d09a0ff..d1d6065 100644 (file)
@@ -37,9 +37,6 @@ static int __ctsvc_db_extension_update_record(contacts_record_h record);
 static int __ctsvc_db_extension_delete_record(int id);
 static int __ctsvc_db_extension_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_extension_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_extension_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_extension_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_extension_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_extension = {
        .is_query_only = false,
@@ -49,9 +46,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_extension = {
        .delete_record = __ctsvc_db_extension_delete_record,
        .get_all_records = __ctsvc_db_extension_get_all_records,
        .get_records_with_query = __ctsvc_db_extension_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_extension_insert_records,
-       .update_records = NULL,//__ctsvc_db_extension_update_records,
-       .delete_records = NULL,//__ctsvc_db_extension_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -453,7 +450,3 @@ static int __ctsvc_db_extension_get_records_with_query(contacts_query_h query, i
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_extension_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_extension_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_extension_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 5a7d648..ab982e8 100644 (file)
@@ -39,9 +39,6 @@ static int __ctsvc_db_group_update_record(contacts_record_h record);
 static int __ctsvc_db_group_delete_record(int id);
 static int __ctsvc_db_group_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_group_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_group_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_group_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_group_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_group = {
        .is_query_only = false,
@@ -51,9 +48,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_group = {
        .delete_record = __ctsvc_db_group_delete_record,
        .get_all_records = __ctsvc_db_group_get_all_records,
        .get_records_with_query = __ctsvc_db_group_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_group_insert_records,
-       .update_records = NULL,//__ctsvc_db_group_update_records,
-       .delete_records = NULL,//__ctsvc_db_group_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -662,8 +659,4 @@ static int __ctsvc_db_group_get_records_with_query(contacts_query_h query,
        return CONTACTS_ERROR_NONE;
 }
 
-//static int __ctsvc_db_group_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_group_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_group_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
-
 
index a074975..b2ba991 100644 (file)
@@ -34,9 +34,6 @@ static int __ctsvc_db_grouprelation_update_record(contacts_record_h record);
 static int __ctsvc_db_grouprelation_delete_record(int id);
 static int __ctsvc_db_grouprelation_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_grouprelation_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_grouprelation_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_grouprelation_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_grouprelation_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_grouprelation = {
        .is_query_only = false,
@@ -46,9 +43,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_grouprelation = {
        .delete_record = __ctsvc_db_grouprelation_delete_record,
        .get_all_records = __ctsvc_db_grouprelation_get_all_records,
        .get_records_with_query = __ctsvc_db_grouprelation_get_records_with_query,
-       .insert_records = NULL, //__ctsvc_db_grouprelation_insert_records,
-       .update_records = NULL, //__ctsvc_db_grouprelation_update_records,
-       .delete_records = NULL, //__ctsvc_db_grouprelation_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -204,7 +201,3 @@ static int __ctsvc_db_grouprelation_get_records_with_query(contacts_query_h quer
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_grouprelation_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_grouprelation_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_grouprelation_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index f5e1b9f..8180943 100644 (file)
@@ -37,9 +37,6 @@ static int __ctsvc_db_image_update_record(contacts_record_h record);
 static int __ctsvc_db_image_delete_record(int id);
 static int __ctsvc_db_image_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_image_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_image_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_image_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_image_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_image = {
        .is_query_only = false,
@@ -49,9 +46,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_image = {
        .delete_record = __ctsvc_db_image_delete_record,
        .get_all_records = __ctsvc_db_image_get_all_records,
        .get_records_with_query = __ctsvc_db_image_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_image_insert_records,
-       .update_records = NULL,//__ctsvc_db_image_update_records,
-       .delete_records = NULL,//__ctsvc_db_image_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -666,7 +663,3 @@ static int __ctsvc_db_image_get_records_with_query(contacts_query_h query, int o
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_image_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_image_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_image_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 6a8bd7e..fa40178 100644 (file)
@@ -36,9 +36,6 @@ static int __ctsvc_db_messenger_update_record(contacts_record_h record);
 static int __ctsvc_db_messenger_delete_record(int id);
 static int __ctsvc_db_messenger_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_messenger_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_messenger_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_messenger_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_messenger_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_messenger = {
        .is_query_only = false,
@@ -48,9 +45,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_messenger = {
        .delete_record = __ctsvc_db_messenger_delete_record,
        .get_all_records = __ctsvc_db_messenger_get_all_records,
        .get_records_with_query = __ctsvc_db_messenger_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_messenger_insert_records,
-       .update_records = NULL,//__ctsvc_db_messenger_update_records,
-       .delete_records = NULL,//__ctsvc_db_messenger_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -399,6 +396,3 @@ static int __ctsvc_db_messenger_get_records_with_query(contacts_query_h query, i
        return CONTACTS_ERROR_NONE;
 }
 
-//static int __ctsvc_db_messenger_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_messenger_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_messenger_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 4bc92ad..34a8d48 100644 (file)
@@ -862,7 +862,7 @@ static int __ctsvc_db_my_profile_get_all_records(int offset, int limit, contacts
                        return ret;
                }
                my_profile_id = ctsvc_stmt_get_int(stmt, 0);
-               ret = contacts_db_get_record(_contacts_my_profile._uri, my_profile_id, &record);
+               ret = ctsvc_db_get_record(_contacts_my_profile._uri, my_profile_id, &record);
                if (CONTACTS_ERROR_NONE != ret) {
                        CTS_ERR("DB error : contacts_db_get_record() Fail(%d)", ret);
                        ctsvc_stmt_finalize(stmt);
@@ -1001,10 +1001,6 @@ static int __ctsvc_db_my_profile_get_records_with_query(contacts_query_h query,
        return CONTACTS_ERROR_NONE;
 }
 
-//static int __ctsvc_db_my_profile_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_my_profile_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_my_profile_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
-
 static int __ctsvc_my_profile_insert_data(ctsvc_my_profile_s *contact)
 {
        int ret;
index 8fefbb9..6bb2729 100644 (file)
@@ -38,9 +38,6 @@ static int __ctsvc_db_name_update_record(contacts_record_h record);
 static int __ctsvc_db_name_delete_record(int id);
 static int __ctsvc_db_name_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_name_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_name_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_name_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_name_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_name = {
        .is_query_only = false,
@@ -50,9 +47,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_name = {
        .delete_record = __ctsvc_db_name_delete_record,
        .get_all_records = __ctsvc_db_name_get_all_records,
        .get_records_with_query = __ctsvc_db_name_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_name_insert_records,
-       .update_records = NULL,//__ctsvc_db_name_update_records,
-       .delete_records = NULL,//__ctsvc_db_name_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -446,7 +443,3 @@ static int __ctsvc_db_name_get_records_with_query(contacts_query_h query, int of
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_name_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_name_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_name_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 0fe6313..7fcaf52 100644 (file)
@@ -36,9 +36,6 @@ static int __ctsvc_db_nickname_update_record(contacts_record_h record);
 static int __ctsvc_db_nickname_delete_record(int id);
 static int __ctsvc_db_nickname_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_nickname_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_nickname_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_nickname_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_nickname_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_nickname = {
        .is_query_only = false,
@@ -48,9 +45,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_nickname = {
        .delete_record = __ctsvc_db_nickname_delete_record,
        .get_all_records = __ctsvc_db_nickname_get_all_records,
        .get_records_with_query = __ctsvc_db_nickname_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_nickname_insert_records,
-       .update_records = NULL,//__ctsvc_db_nickname_update_records,
-       .delete_records = NULL,//__ctsvc_db_nickname_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -397,7 +394,3 @@ static int __ctsvc_db_nickname_get_records_with_query(contacts_query_h query, in
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_nickname_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_nickname_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_nickname_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index ad2be5c..858fd9c 100644 (file)
@@ -37,9 +37,6 @@ static int __ctsvc_db_note_update_record(contacts_record_h record);
 static int __ctsvc_db_note_delete_record(int id);
 static int __ctsvc_db_note_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_note_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_note_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_note_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_note_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_note = {
        .is_query_only = false,
@@ -49,9 +46,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_note = {
        .delete_record = __ctsvc_db_note_delete_record,
        .get_all_records = __ctsvc_db_note_get_all_records,
        .get_records_with_query = __ctsvc_db_note_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_note_insert_records,
-       .update_records = NULL,//__ctsvc_db_note_update_records,
-       .delete_records = NULL,//__ctsvc_db_note_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -395,7 +392,3 @@ static int __ctsvc_db_note_get_records_with_query(contacts_query_h query, int of
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_note_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_note_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_note_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 6328788..1d852af 100644 (file)
@@ -38,9 +38,6 @@ static int __ctsvc_db_number_update_record(contacts_record_h record);
 static int __ctsvc_db_number_delete_record(int id);
 static int __ctsvc_db_number_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_number_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_number_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_number_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_number_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_number = {
        .is_query_only = false,
@@ -50,9 +47,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_number = {
        .delete_record = __ctsvc_db_number_delete_record,
        .get_all_records = __ctsvc_db_number_get_all_records,
        .get_records_with_query = __ctsvc_db_number_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_number_insert_records,
-       .update_records = NULL,//__ctsvc_db_number_update_records,
-       .delete_records = NULL,//__ctsvc_db_number_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -597,7 +594,3 @@ static int __ctsvc_db_number_get_records_with_query(contacts_query_h query, int
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_number_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_number_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_number_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 969e008..e94c338 100644 (file)
@@ -42,9 +42,6 @@ static int __ctsvc_db_person_update_record(contacts_record_h record);
 static int __ctsvc_db_person_delete_record(int id);
 static int __ctsvc_db_person_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_person_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_person_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_person_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_person_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_person = {
        .is_query_only = false,
@@ -54,9 +51,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_person = {
        .delete_record = __ctsvc_db_person_delete_record,
        .get_all_records = __ctsvc_db_person_get_all_records,
        .get_records_with_query = __ctsvc_db_person_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_person_insert_records,
-       .update_records = NULL,//__ctsvc_db_person_update_records,
-       .delete_records = NULL,//__ctsvc_db_person_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -629,19 +626,3 @@ static int __ctsvc_db_person_get_records_with_query(contacts_query_h query, int
        return CONTACTS_ERROR_NONE;
 }
 
-#if 0
-static int __ctsvc_db_person_insert_records(const contacts_list_h in_list, int **ids)
-{
-       return CONTACTS_ERROR_NONE;
-}
-
-static int __ctsvc_db_person_update_records(const contacts_list_h in_list)
-{
-       return CONTACTS_ERROR_NONE;
-}
-
-static int __ctsvc_db_person_delete_records(int ids[], int count)
-{
-       return CONTACTS_ERROR_NONE;
-}
-#endif
index 9aef592..cb9fc89 100644 (file)
@@ -46,9 +46,6 @@ static int __ctsvc_db_phonelog_update_record(contacts_record_h record);
 static int __ctsvc_db_phonelog_delete_record(int id);
 static int __ctsvc_db_phonelog_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_phonelog_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_phonelog_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_phonelog_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_phonelog_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_phonelog = {
        .is_query_only = false,
@@ -58,9 +55,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_phonelog = {
        .delete_record = __ctsvc_db_phonelog_delete_record,
        .get_all_records = __ctsvc_db_phonelog_get_all_records,
        .get_records_with_query = __ctsvc_db_phonelog_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_phonelog_insert_records,
-       .update_records = NULL,//__ctsvc_db_phonelog_update_records,
-       .delete_records = NULL,//__ctsvc_db_phonelog_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -362,10 +359,6 @@ static int __ctsvc_db_phonelog_get_records_with_query(contacts_query_h query, in
 
        return CONTACTS_ERROR_NONE;
 }
-//static int __ctsvc_db_phonelog_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_phonelog_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_phonelog_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
-
 static int __ctsvc_db_phonelog_increase_outgoing_count(ctsvc_phonelog_s *phonelog)
 {
        int ret;
index 5f20686..2f590a2 100644 (file)
@@ -37,9 +37,6 @@ static int __ctsvc_db_profile_update_record(contacts_record_h record);
 static int __ctsvc_db_profile_delete_record(int id);
 static int __ctsvc_db_profile_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_profile_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_profile_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_profile_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_profile_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_profile = {
        .is_query_only = false,
@@ -49,9 +46,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_profile = {
        .delete_record = __ctsvc_db_profile_delete_record,
        .get_all_records = __ctsvc_db_profile_get_all_records,
        .get_records_with_query = __ctsvc_db_profile_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_profile_insert_records,
-       .update_records = NULL,//__ctsvc_db_profile_update_records,
-       .delete_records = NULL,//__ctsvc_db_profile_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -431,7 +428,3 @@ static int __ctsvc_db_profile_get_records_with_query(contacts_query_h query, int
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_profile_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_profile_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_profile_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index ecfbc77..31ad456 100644 (file)
@@ -38,9 +38,6 @@ static int __ctsvc_db_relationship_update_record(contacts_record_h record);
 static int __ctsvc_db_relationship_delete_record(int id);
 static int __ctsvc_db_relationship_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_relationship_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_relationship_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_relationship_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_relationship_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_relationship = {
        .is_query_only = false,
@@ -50,9 +47,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_relationship = {
        .delete_record = __ctsvc_db_relationship_delete_record,
        .get_all_records = __ctsvc_db_relationship_get_all_records,
        .get_records_with_query = __ctsvc_db_relationship_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_relationship_insert_records,
-       .update_records = NULL,//__ctsvc_db_relationship_update_records,
-       .delete_records = NULL,//__ctsvc_db_relationship_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -400,7 +397,3 @@ static int __ctsvc_db_relationship_get_records_with_query(contacts_query_h query
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_relationship_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_relationship_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_relationship_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 39cc71b..5ff5cad 100644 (file)
 #include "ctsvc_notification.h"
 #include "ctsvc_server_utils.h"
 
-//static int __ctsvc_db_sdn_insert_record(contacts_record_h record, int *id);
 static int __ctsvc_db_sdn_get_record(int id, contacts_record_h* record);
-//static int __ctsvc_db_sdn_update_record(contacts_record_h record);
-//static int __ctsvc_db_sdn_delete_record(int id);
 static int __ctsvc_db_sdn_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_sdn_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_sdn_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_sdn_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_sdn_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_sdn = {
        .is_query_only = false,
-       .insert_record = NULL,//__ctsvc_db_sdn_insert_record,
+       .insert_record = NULL,
        .get_record = __ctsvc_db_sdn_get_record,
-       .update_record = NULL,//__ctsvc_db_sdn_update_record,
-       .delete_record = NULL,//__ctsvc_db_sdn_delete_record,
+       .update_record = NULL,
+       .delete_record = NULL,
        .get_all_records = __ctsvc_db_sdn_get_all_records,
        .get_records_with_query = __ctsvc_db_sdn_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_sdn_insert_records,
-       .update_records = NULL,//__ctsvc_db_sdn_update_records,
-       .delete_records = NULL,//__ctsvc_db_sdn_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -120,153 +114,6 @@ static int __ctsvc_db_sdn_get_record(int id, contacts_record_h* out_record)
        return CONTACTS_ERROR_NONE;
 }
 
-#if 0
-static int __ctsvc_db_sdn_insert_record(contacts_record_h record, int *id)
-{
-       int ret;
-       ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
-
-       RETV_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == sdn->name, CONTACTS_ERROR_INVALID_PARAMETER);
-       RETVM_IF(CTSVC_RECORD_SDN != sdn->base.r_type, CONTACTS_ERROR_INVALID_PARAMETER,
-                       "Invalid parameter : record is invalid type(%d)", sdn->base.r_type);
-
-       cts_stmt stmt = NULL;
-       char query[CTS_SQL_MAX_LEN] = {0};
-
-       snprintf(query, sizeof(query),
-                       "INSERT INTO "CTS_TABLE_SDN"(name, number, sim_slot_no) VALUES(?, ?, ?)");
-
-       ret = ctsvc_query_prepare(query, &stmt);
-       RETVM_IF(NULL == stmt, ret, "DB error : ctsvc_query_prepare() Fail(%d)", ret);
-
-       ctsvc_stmt_bind_text(stmt, 1, sdn->name);
-       ctsvc_stmt_bind_text(stmt, 2, sdn->number);
-       ctsvc_stmt_bind_int(stmt, 3, sdn->sim_slot_no);
-
-       ret = ctsvc_begin_trans();
-       if (ret < CONTACTS_ERROR_NONE) {
-               CTS_ERR("DB error : ctsvc_begin_trans() Fail(%d)", ret);
-               ctsvc_stmt_finalize(stmt);
-               return ret;
-       }
-
-       ret = ctsvc_stmt_step(stmt);
-       if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("DB error : ctsvc_stmt_step() Fail(%d)", ret);
-               ctsvc_stmt_finalize(stmt);
-               ctsvc_end_trans(false);
-               return ret;
-       }
-
-       //sdn->id = ctsvc_db_get_last_insert_id();
-       if (id)
-               *id = ctsvc_db_get_last_insert_id();
-       ctsvc_stmt_finalize(stmt);
-
-       ctsvc_set_sdn_noti();
-       ret = ctsvc_end_trans(true);
-       if (ret < CONTACTS_ERROR_NONE) {
-               CTS_ERR("DB error : ctsvc_end_trans() Fail(%d)", ret);
-               return ret;
-       }
-
-       return CONTACTS_ERROR_NONE;
-}
-
-static int __ctsvc_db_sdn_update_record(contacts_record_h record)
-{
-       int sdn_id;
-       int ret = CONTACTS_ERROR_NONE;
-       char* set = NULL;
-       GSList *bind_text = NULL;
-       GSList *cursor = NULL;
-       ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
-       char query[CTS_SQL_MIN_LEN] = {0};
-
-       RETV_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER);
-       RETVM_IF(CTSVC_RECORD_SDN != sdn->base.r_type, CONTACTS_ERROR_INVALID_PARAMETER,
-                       "Invalid parameter : record is invalid type(%d)", sdn->base.r_type);
-       RETVM_IF(!sdn->id, CONTACTS_ERROR_INVALID_PARAMETER, "sdn of contact has no ID.");
-       RETV_IF(NULL == sdn->name, CONTACTS_ERROR_INVALID_PARAMETER);
-       RETVM_IF(CTSVC_PROPERTY_FLAG_DIRTY != (sdn->base.property_flag & CTSVC_PROPERTY_FLAG_DIRTY), CONTACTS_ERROR_NONE, "No update");
-
-       ret = ctsvc_begin_trans();
-       RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "DB error : ctsvc_begin_trans() Fail(%d)", ret);
-
-       snprintf(query, sizeof(query),
-                       "SELECT id FROM "CTS_TABLE_SDN" WHERE id = %d", sdn->id);
-       ret = ctsvc_query_get_first_int_result(query, &sdn_id);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
-               ctsvc_end_trans(false);
-               return ret;
-       }
-
-       do {
-               if (CONTACTS_ERROR_NONE != (ret = ctsvc_db_create_set_query(record, &set, &bind_text))) break;
-               if (CONTACTS_ERROR_NONE != (ret = ctsvc_db_update_record_with_set_query(set, bind_text, CTS_TABLE_SDN, sdn->id))) break;
-               ctsvc_set_sdn_noti();
-       } while (0);
-
-       CTSVC_RECORD_RESET_PROPERTY_FLAGS((ctsvc_record_s *)record);
-       CONTACTS_FREE(set);
-       if (bind_text) {
-               for (cursor=bind_text;cursor;cursor=cursor->next)
-                       CONTACTS_FREE(cursor->data);
-               g_slist_free(bind_text);
-       }
-
-       ret = ctsvc_end_trans(true);
-       RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "DB error : ctsvc_end_trans() Fail(%d)", ret);
-
-       return CONTACTS_ERROR_NONE;
-}
-
-static int __ctsvc_db_sdn_delete_record(int sdn_id)
-{
-       int ret;
-       int id;
-       char query[CTS_SQL_MAX_LEN] = {0};
-
-       ret = ctsvc_begin_trans();
-       RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "DB error : ctsvc_begin_trans() Fail(%d)", ret);
-
-       snprintf(query, sizeof(query),
-                       "SELECT id FROM "CTS_TABLE_SDN" WHERE id = %d", sdn_id);
-       ret = ctsvc_query_get_first_int_result(query, &id);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
-               ctsvc_end_trans(false);
-               return ret;
-       }
-
-       snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_SDN" WHERE id = %d", sdn_id);
-       ret = ctsvc_query_exec(query);
-       if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("DB error : ctsvc_query_exec() Fail(%d)", ret);
-               ctsvc_end_trans(false);
-               return ret;
-       }
-
-       ret = ctsvc_db_change();
-       if (ret <= 0) {
-               ret = CONTACTS_ERROR_NO_DATA;
-               ctsvc_end_trans(false);
-               return ret;
-       }
-
-       ctsvc_set_sdn_noti();
-       ret = ctsvc_end_trans(true);
-       if (ret != CONTACTS_ERROR_NONE) {
-               CTS_ERR("DB error : ctsvc_end_trans() Fail(%d)", ret);
-               return ret;
-       }
-
-       return CONTACTS_ERROR_NONE;
-}
-#endif
-
 static int __ctsvc_db_sdn_get_all_records(int offset, int limit,
        contacts_list_h* out_list)
 {
@@ -389,19 +236,3 @@ static int __ctsvc_db_sdn_get_records_with_query(contacts_query_h query, int off
        return CONTACTS_ERROR_NONE;
 }
 
-#if 0
-static int __ctsvc_db_sdn_insert_records(const contacts_list_h in_list, int **ids)
-{
-       return CONTACTS_ERROR_NONE;
-}
-
-static int __ctsvc_db_sdn_update_records(const contacts_list_h in_list)
-{
-       return CONTACTS_ERROR_NONE;
-}
-
-static int __ctsvc_db_sdn_delete_records(int ids[], int count)
-{
-       return CONTACTS_ERROR_NONE;
-}
-#endif
index e561b19..7bb242d 100644 (file)
@@ -303,7 +303,3 @@ static int __ctsvc_db_simple_contact_get_records_with_query(contacts_query_h que
 
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_simple_contact_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_simple_contact_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_simple_contact_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 2ac4d12..4250b27 100644 (file)
@@ -35,9 +35,6 @@ static int __ctsvc_db_speeddial_update_record(contacts_record_h record);
 static int __ctsvc_db_speeddial_delete_record(int id);
 static int __ctsvc_db_speeddial_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_speeddial_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_speeddial_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_speeddial_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_speeddial_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_speeddial = {
        .is_query_only = false,
@@ -47,9 +44,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_speeddial = {
        .delete_record = __ctsvc_db_speeddial_delete_record,
        .get_all_records = __ctsvc_db_speeddial_get_all_records,
        .get_records_with_query = __ctsvc_db_speeddial_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_speeddial_insert_records,
-       .update_records = NULL,//__ctsvc_db_speeddial_update_records,
-       .delete_records = NULL,//__ctsvc_db_speeddial_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -449,7 +446,3 @@ static int __ctsvc_db_speeddial_get_records_with_query(contacts_query_h query,
 
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_speeddial_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_speeddial_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_speeddial_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index e2564b2..7a98df3 100644 (file)
@@ -37,9 +37,6 @@ static int __ctsvc_db_url_update_record(contacts_record_h record);
 static int __ctsvc_db_url_delete_record(int id);
 static int __ctsvc_db_url_get_all_records(int offset, int limit, contacts_list_h* out_list);
 static int __ctsvc_db_url_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_url_insert_records(const contacts_list_h in_list, int **ids);
-//static int __ctsvc_db_url_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_url_delete_records(int ids[], int count);
 
 ctsvc_db_plugin_info_s ctsvc_db_plugin_url = {
        .is_query_only = false,
@@ -49,9 +46,9 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_url = {
        .delete_record = __ctsvc_db_url_delete_record,
        .get_all_records = __ctsvc_db_url_get_all_records,
        .get_records_with_query = __ctsvc_db_url_get_records_with_query,
-       .insert_records = NULL,//__ctsvc_db_url_insert_records,
-       .update_records = NULL,//__ctsvc_db_url_update_records,
-       .delete_records = NULL,//__ctsvc_db_url_delete_records
+       .insert_records = NULL,
+       .update_records = NULL,
+       .delete_records = NULL,
        .get_count = NULL,
        .get_count_with_query = NULL,
        .replace_record = NULL,
@@ -398,7 +395,3 @@ static int __ctsvc_db_url_get_records_with_query(contacts_query_h query, int off
        *out_list = list;
        return CONTACTS_ERROR_NONE;
 }
-
-//static int __ctsvc_db_url_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_url_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_url_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
index 2ef9cae..2dc24b8 100644 (file)
@@ -46,6 +46,7 @@
 #include "ctsvc_db_plugin_person_helper.h"
 #include "ctsvc_db_plugin_group_helper.h"
 #include "ctsvc_db_plugin_company_helper.h"
+#include "ctsvc_db_query.h"
 
 #ifdef _CONTACTS_IPC_SERVER
 #include "ctsvc_server_sim.h"
@@ -362,8 +363,11 @@ static inline int __ctsvc_db_create_str_condition(ctsvc_composite_filter_s *com_
                filter->match = CONTACTS_MATCH_EXACTLY;
 
        ret = __ctsvc_db_add_str_matching_rule(field_name, filter->match, &temp, &with_escape);
-       RETVM_IF(ret <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
-                       "__ctsvc_db_add_str_matching_rule Fail");
+       if(ret <= 0 ){
+               free(temp);
+               CTS_ERR("__ctsvc_db_add_str_matching_rule Fail");
+               return CONTACTS_ERROR_INVALID_PARAMETER;
+       }
        cond_len = snprintf(out_cond, sizeof(out_cond), "%s", temp);
        free(temp);
        temp = NULL;
@@ -383,6 +387,7 @@ static inline int __ctsvc_db_create_str_condition(ctsvc_composite_filter_s *com_
                        ret = ctsvc_clean_number(filter->value.s, clean_num, sizeof(clean_num), false);
                        if (0 < ret) {
                                ret = ctsvc_normalize_number(clean_num, normal_num, sizeof(normal_num), false);
+                               normal_num[sizeof(normal_num) -1] = '\0';
                                if (0 < ret) {
                                        char min_match[strlen(filter->value.s)+1+5];   /* for cc */
                                        ret = ctsvc_get_minmatch_number(normal_num, min_match, sizeof(min_match), ctsvc_get_phonenumber_min_match_digit());
@@ -472,8 +477,11 @@ static inline int __ctsvc_db_create_str_condition(ctsvc_composite_filter_s *com_
                                        if (add_condition)
                                                cond_len += snprintf(out_cond+cond_len, sizeof(out_cond)-cond_len, " OR ");
                                        ret = __ctsvc_db_add_str_matching_rule(clean_field, filter->match, &temp, &with_escape);
-                                       RETVM_IF(ret <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
-                                                       "__ctsvc_db_add_str_matching_rule Fail");
+                                       if(ret <= 0){
+                                               free(temp);
+                                               CTS_ERR("__ctsvc_db_add_str_matching_rule Fail");
+                                               return CONTACTS_ERROR_INVALID_PARAMETER;
+                                       }
                                        cond_len += snprintf(out_cond+cond_len, sizeof(out_cond)-cond_len, "%s", temp);
                                        free(temp);
                                        temp = NULL;
@@ -1677,7 +1685,7 @@ static int __ctsvc_db_search_records_append_sort(const char *view_uri,
                contacts_name_sorting_order_e order;
                const char *field = NULL;
                char *temp_keyword = NULL;
-               contacts_setting_get_name_sorting_order(&order);
+               ctsvc_setting_get_name_sorting_order(&order);
 
                if (CONTACTS_NAME_SORTING_ORDER_FIRSTLAST == order)
                        field = "display_name";
@@ -2500,7 +2508,7 @@ static int __ctsvc_db_insert_records(contacts_list_h list, int **ids)
                        return ret;
                }
 
-               ret = contacts_db_insert_record(record, &id[index++]);
+               ret = ctsvc_db_insert_record(record, &id[index++]);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("contacts_db_insert_record is faild(%d)", ret);
                        ctsvc_end_trans(false);
@@ -2533,7 +2541,7 @@ static int __ctsvc_db_delete_records(const char* view_uri, int ids[], int count)
 
        index = 0;
        do {
-               ret = contacts_db_delete_record(view_uri, ids[index++]);
+               ret = ctsvc_db_delete_record(view_uri, ids[index++]);
                if (CONTACTS_ERROR_NO_DATA == ret) {
                        CTS_DBG("the record is not exist : %d", ret);
                        continue;
@@ -2576,7 +2584,7 @@ static int __ctsvc_db_update_records(contacts_list_h list)
                        return ret;
                }
 
-               ret = contacts_db_update_record(record);
+               ret = ctsvc_db_update_record(record);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("contacts_db_update_record is faild(%d)", ret);
                        ctsvc_end_trans(false);
@@ -2746,7 +2754,7 @@ static int __ctsvc_db_get_count_with_query(contacts_query_h query, int *out_coun
        return ret;
 }
 
-API int contacts_db_get_records_with_query(contacts_query_h query, int offset, int limit,
+int ctsvc_db_get_records_with_query(contacts_query_h query, int offset, int limit,
        contacts_list_h* out_list)
 {
        int ret = CONTACTS_ERROR_NONE;
@@ -3096,7 +3104,7 @@ static int __ctsvc_db_get_my_profile_changes(const char* view_uri, int addressbo
        return CONTACTS_ERROR_NONE;
 }
 
-API int contacts_db_get_changes_by_version(const char* view_uri, int addressbook_id,
+int ctsvc_db_get_changes_by_version(const char* view_uri, int addressbook_id,
                int version, contacts_list_h* out_list, int* out_current_version)
 {
        int ret;
@@ -3136,13 +3144,13 @@ API int contacts_db_get_changes_by_version(const char* view_uri, int addressbook
        return CONTACTS_ERROR_INVALID_PARAMETER;
 }
 
-API int contacts_db_get_current_version(int* out_current_version)
+int ctsvc_db_get_current_version(int* out_current_version)
 {
        RETVM_IF(NULL == out_current_version, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
        return ctsvc_get_current_version(out_current_version);
 }
 
-API int contacts_db_search_records(const char* view_uri, const char *keyword,
+int ctsvc_db_search_records(const char* view_uri, const char *keyword,
                int offset, int limit, contacts_list_h* out_list)
 {
        RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
@@ -3152,7 +3160,7 @@ API int contacts_db_search_records(const char* view_uri, const char *keyword,
        return __ctsvc_db_search_records(view_uri, keyword, offset, limit, out_list);
 }
 
-API int contacts_db_search_records_with_range(const char* view_uri, const char *keyword,
+int ctsvc_db_search_records_with_range(const char* view_uri, const char *keyword,
                int offset, int limit, int range, contacts_list_h* out_list)
 {
        RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
@@ -3163,7 +3171,7 @@ API int contacts_db_search_records_with_range(const char* view_uri, const char *
        return __ctsvc_db_search_records_with_range(view_uri, keyword, offset, limit, range, out_list);
 }
 
-API int contacts_db_search_records_with_query(contacts_query_h query, const char *keyword,
+int ctsvc_db_search_records_with_query(contacts_query_h query, const char *keyword,
                int offset, int limit, contacts_list_h* out_list)
 {
        RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
@@ -3172,7 +3180,7 @@ API int contacts_db_search_records_with_query(contacts_query_h query, const char
        return __ctsvc_db_search_records_with_query(query, keyword, offset, limit, out_list);
 }
 
-API int contacts_db_get_count(const char* view_uri, int *out_count)
+int ctsvc_db_get_count(const char* view_uri, int *out_count)
 {
        int ret;
        ctsvc_db_plugin_info_s* plugin_info = NULL;
@@ -3191,7 +3199,7 @@ API int contacts_db_get_count(const char* view_uri, int *out_count)
        return __ctsvc_db_get_count(view_uri, out_count);
 }
 
-API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
+int ctsvc_db_get_count_with_query(contacts_query_h query, int *out_count)
 {
        int ret = CONTACTS_ERROR_NONE;
        ctsvc_record_type_e type = CTSVC_RECORD_INVALID;
@@ -3216,7 +3224,7 @@ API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
        return __ctsvc_db_get_count_with_query(query, out_count);
 }
 
-API int contacts_db_insert_record(contacts_record_h record, int *id)
+int ctsvc_db_insert_record(contacts_record_h record, int *id)
 {
        ctsvc_db_plugin_info_s* plugin_info = NULL;
 
@@ -3232,7 +3240,7 @@ API int contacts_db_insert_record(contacts_record_h record, int *id)
        return plugin_info->insert_record(record, id);
 }
 
-API int contacts_db_update_record(contacts_record_h record)
+int ctsvc_db_update_record(contacts_record_h record)
 {
        ctsvc_db_plugin_info_s* plugin_info = NULL;
 
@@ -3245,7 +3253,7 @@ API int contacts_db_update_record(contacts_record_h record)
        return plugin_info->update_record(record);
 }
 
-API int contacts_db_delete_record(const char* view_uri, int id)
+int ctsvc_db_delete_record(const char* view_uri, int id)
 {
        ctsvc_record_type_e type = CTSVC_RECORD_INVALID;
        ctsvc_db_plugin_info_s* plugin_info = NULL;
@@ -3260,7 +3268,7 @@ API int contacts_db_delete_record(const char* view_uri, int id)
        return plugin_info->delete_record(id);
 }
 
-API int contacts_db_get_record(const char* view_uri, int id, contacts_record_h* out_record)
+int ctsvc_db_get_record(const char* view_uri, int id, contacts_record_h* out_record)
 {
        ctsvc_record_type_e type = CTSVC_RECORD_INVALID;
        ctsvc_db_plugin_info_s* plugin_info = NULL;
@@ -3278,7 +3286,7 @@ API int contacts_db_get_record(const char* view_uri, int id, contacts_record_h*
        return plugin_info->get_record(id, out_record);
 }
 
-API int contacts_db_replace_record(contacts_record_h record, int id)
+int ctsvc_db_replace_record(contacts_record_h record, int id)
 {
        ctsvc_db_plugin_info_s* plugin_info = NULL;
 
@@ -3291,7 +3299,7 @@ API int contacts_db_replace_record(contacts_record_h record, int id)
        return plugin_info->replace_record(record, id);
 }
 
-API int contacts_db_get_all_records(const char* view_uri, int offset, int limit, contacts_list_h* out_list)
+int ctsvc_db_get_all_records(const char* view_uri, int offset, int limit, contacts_list_h* out_list)
 {
        int ret = CONTACTS_ERROR_NONE;
        ctsvc_record_type_e type = CTSVC_RECORD_INVALID;
@@ -3393,7 +3401,7 @@ static int __ctsvc_db_replace_records(contacts_list_h list, int ids[], int count
                        return ret;
                }
 
-               ret = contacts_db_replace_record(record, ids[i++]);
+               ret = ctsvc_db_replace_record(record, ids[i++]);
                if (ret != CONTACTS_ERROR_NONE) {
                        CTS_ERR("contacts_db_replace_record is faild(%d)", ret);
                        ctsvc_end_trans(false);
@@ -3406,7 +3414,8 @@ static int __ctsvc_db_replace_records(contacts_list_h list, int ids[], int count
        return ret;
 }
 
-int ctsvc_db_replace_records(contacts_list_h list, int ids[], unsigned int count)
+
+int ctsvc_db_replace_records(contacts_list_h list, int ids[], int count)
 {
        int ret = CONTACTS_ERROR_NONE;
        ctsvc_db_plugin_info_s* plugin_info = NULL;
@@ -3424,36 +3433,7 @@ int ctsvc_db_replace_records(contacts_list_h list, int ids[], unsigned int count
        return __ctsvc_db_replace_records(list, ids, count);
 }
 
-API int contacts_db_insert_records(contacts_list_h record_list, int **ids, int *count)
-{
-       return ctsvc_db_insert_records(record_list, ids, count);
-}
-
-API int contacts_db_update_records(contacts_list_h record_list)
-{
-       return ctsvc_db_update_records(record_list);
-}
-
-API int contacts_db_delete_records(const char* view_uri, int record_id_array[], int count)
-{
-       return ctsvc_db_delete_records(view_uri, record_id_array, count);
-}
-
-API int contacts_db_replace_records(contacts_list_h list, int record_id_array[], int count)
-{
-       return ctsvc_db_replace_records(list, record_id_array, count);
-}
-
-API int contacts_db_get_last_change_version(int* last_version)
-{
-       int ret = CONTACTS_ERROR_NONE;
-
-       RETVM_IF(NULL == last_version, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
-       *last_version = ctsvc_get_transaction_ver();
-       return ret;
-}
-
-API int contacts_db_get_status(contacts_db_status_e *status)
+int ctsvc_db_get_status(contacts_db_status_e *status)
 {
        *status = __db_status;
        return CONTACTS_ERROR_NONE;
@@ -3463,9 +3443,7 @@ void ctsvc_db_set_status(contacts_db_status_e status)
 {
        __db_status = status;
 
-#ifdef _CONTACTS_IPC_SERVER
        ctsvc_change_subject_publish_status(status);
-#endif
        return;
 }
 
index bc71d6c..d6ba18f 100644 (file)
  *
  */
 
-#ifndef __CTSVC_DB_SCHEMA_H__
-#define __CTSVC_DB_SCHEMA_H__
+#ifndef __CTSVC_DB_QUERY_H__
+#define __CTSVC_DB_QUERY_H__
 
 #include "contacts.h"
 #include "contacts_db_status.h"
 #include "ctsvc_struct.h"
 #include "ctsvc_db_sqlite.h"
 
-int ctsvc_db_insert_records(contacts_list_h list, int **ids, unsigned int *count);
+int ctsvc_db_insert_record(contacts_record_h record, int *id);
+int ctsvc_db_get_record(const char* view_uri, int id, contacts_record_h* out_record);
+int ctsvc_db_update_record(contacts_record_h record);
+int ctsvc_db_delete_record(const char* view_uri, int id);
+int ctsvc_db_replace_record(contacts_record_h record, int id);
+int ctsvc_db_get_all_records(const char* view_uri, int offset, int limit, contacts_list_h* out_list );
+int ctsvc_db_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list );
+int ctsvc_db_get_count(const char* view_uri, int *out_count);
+int ctsvc_db_get_count_with_query(contacts_query_h query, int *out_count);
+int ctsvc_db_get_changes_by_version(const char* view_uri, int addressbook_id, int version, contacts_list_h* out_list, int* out_current_version );
+int ctsvc_db_get_current_version(int* out_current_version);
+int ctsvc_db_search_records(const char* view_uri, const char *keyword, int offset, int limit, contacts_list_h* out_list);
+int ctsvc_db_search_records_with_range(const char* view_uri, const char *keyword, int offset, int limit, int range, contacts_list_h* out_list);
+int ctsvc_db_search_records_with_query(contacts_query_h query, const char *keyword, int offset, int limit, contacts_list_h* out_list);
+int ctsvc_db_get_status(contacts_db_status_e *status);
+int ctsvc_db_insert_records_with_vcard(const char* vcard_stream, int **record_id_array, int *count);
+int ctsvc_db_replace_records_with_vcard(const char* vcard_stream, int *record_id_array, int count);
+
+
+int ctsvc_db_insert_records(contacts_list_h list, int **ids, int *count);
 int ctsvc_db_update_records(contacts_list_h list);
 int ctsvc_db_delete_records(const char* view_uri, int *ids, int count);
-int ctsvc_db_replace_records(contacts_list_h list, int ids[], unsigned int count);
+int ctsvc_db_replace_records(contacts_list_h list, int ids[], int count);
 
 int ctsvc_db_make_get_records_query_stmt(ctsvc_query_s *s_query, int offset, int limit, cts_stmt *stmt);
 int ctsvc_db_create_set_query(contacts_record_h record, char **set, GSList **bind_text);
@@ -40,5 +59,5 @@ int ctsvc_db_update_record_with_set_query(const char *set, GSList *bind_text, co
 
 void ctsvc_db_set_status(contacts_db_status_e status);
 
-#endif /*  __CTSVC_DB_SCHEMA_H__ */
+#endif /*  __CTSVC_DB_QUERY_H__ */
 
index 32d21e5..f196841 100644 (file)
@@ -46,7 +46,8 @@
 
 static __thread sqlite3 *ctsvc_db = NULL;
 
-int ctsvc_db_open(void) {
+int ctsvc_db_open(void)
+{
        CTS_FN_CALL;
        int ret;
 
@@ -93,7 +94,8 @@ int ctsvc_db_open(void) {
        return CONTACTS_ERROR_NONE /*CTS_SUCCESS*/;
 }
 
-int ctsvc_db_close(void) {
+int ctsvc_db_close(void)
+{
        int ret = 0;
 
        if (ctsvc_db) {
@@ -106,15 +108,18 @@ int ctsvc_db_close(void) {
        return CONTACTS_ERROR_NONE /*CTS_SUCCESS*/;
 }
 
-int ctsvc_db_change(void) {
+int ctsvc_db_change(void)
+{
        return sqlite3_changes(ctsvc_db);
 }
 
-int ctsvc_db_get_last_insert_id(void) {
+int ctsvc_db_get_last_insert_id(void)
+{
        return sqlite3_last_insert_rowid(ctsvc_db);
 }
 
-int ctsvc_db_get_next_id(const char *table) {
+int ctsvc_db_get_next_id(const char *table)
+{
        int id;
        int ret;
        char query[CTS_SQL_MAX_LEN] = { 0 };
@@ -133,7 +138,8 @@ int ctsvc_db_get_next_id(const char *table) {
        }
 }
 
-int ctsvc_query_get_first_int_result(const char *query, int *result) {
+int ctsvc_query_get_first_int_result(const char *query, int *result)
+{
        int ret;
        struct timeval from, now, diff;
        bool retry = false;
@@ -204,7 +210,8 @@ int ctsvc_query_get_first_int_result(const char *query, int *result) {
        return CONTACTS_ERROR_NONE;
 }
 
-int ctsvc_query_exec(const char *query) {
+int ctsvc_query_exec(const char *query)
+{
        int ret;
        cts_stmt stmt = NULL;
        char *err_msg = NULL;
@@ -223,7 +230,8 @@ int ctsvc_query_exec(const char *query) {
        return ret;
 }
 
-int ctsvc_query_prepare(char *query, cts_stmt *stmt) {
+int ctsvc_query_prepare(char *query, cts_stmt *stmt)
+{
        int ret = -1;
        struct timeval from, now, diff;
        bool retry = false;
@@ -256,7 +264,8 @@ int ctsvc_query_prepare(char *query, cts_stmt *stmt) {
                return CONTACTS_ERROR_DB;
 }
 
-int ctsvc_stmt_get_first_int_result(cts_stmt stmt, int *result) {
+int ctsvc_stmt_get_first_int_result(cts_stmt stmt, int *result)
+{
        int ret;
        struct timeval from, now, diff;
        bool retry = false;
@@ -298,7 +307,8 @@ int ctsvc_stmt_get_first_int_result(cts_stmt stmt, int *result) {
        return CONTACTS_ERROR_NONE;
 }
 
-int ctsvc_stmt_step(cts_stmt stmt) {
+int ctsvc_stmt_step(cts_stmt stmt)
+{
        int ret = CONTACTS_ERROR_NONE;
        struct timeval from, now, diff;
        bool retry = false;
@@ -354,12 +364,14 @@ int ctsvc_stmt_step(cts_stmt stmt) {
        return ret;
 }
 
-void ctsvc_stmt_reset(cts_stmt stmt) {
+void ctsvc_stmt_reset(cts_stmt stmt)
+{
        sqlite3_reset(stmt);
        sqlite3_clear_bindings(stmt);
 }
 
-void ctsvc_stmt_finalize(cts_stmt stmt) {
+void ctsvc_stmt_finalize(cts_stmt stmt)
+{
        int ret;
 
        if (NULL == stmt)
index 3fd8e83..ce15ac4 100644 (file)
@@ -108,9 +108,7 @@ int ctsvc_end_trans(bool is_success)
 
        if (false == is_success) {
                ctsvc_nofitication_cancel();
-#ifdef _CONTACTS_IPC_SERVER
                ctsvc_change_subject_clear_changed_info();
-#endif
                ret = ctsvc_query_exec("ROLLBACK TRANSACTION");
 
                return CONTACTS_ERROR_NONE;
@@ -138,18 +136,14 @@ int ctsvc_end_trans(bool is_success)
                int tmp_ret;
                CTS_ERR("ctsvc_query_exec() Fail(%d)", ret);
                ctsvc_nofitication_cancel();
-#ifdef _CONTACTS_IPC_SERVER
                ctsvc_change_subject_clear_changed_info();
-#endif
                tmp_ret = ctsvc_query_exec("ROLLBACK TRANSACTION");
                WARN_IF(CONTACTS_ERROR_NONE != tmp_ret, "ctsvc_query_exec(ROLLBACK) Fail(%d)", tmp_ret);
                return ret;
        }
 
        ctsvc_notification_send();
-#ifdef _CONTACTS_IPC_SERVER
        ctsvc_change_subject_publish_changed_info();
-#endif
 
        CTS_DBG("Transaction shut down! : (%d)\n", transaction_ver);
 
@@ -160,7 +154,7 @@ const char* ctsvc_get_display_column(void)
 {
        contacts_name_display_order_e order;
 
-       contacts_setting_get_name_display_order(&order);
+       ctsvc_setting_get_name_display_order(&order);
        if (CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST == order)
                return "display_name";
        else
@@ -171,7 +165,7 @@ const char* ctsvc_get_sort_name_column(void)
 {
        contacts_name_sorting_order_e order;
 
-       contacts_setting_get_name_sorting_order(&order);
+       ctsvc_setting_get_name_sorting_order(&order);
        if (CONTACTS_NAME_SORTING_ORDER_FIRSTLAST == order)
                return "sort_name, display_name_language";
        else
@@ -182,7 +176,7 @@ const char* ctsvc_get_sort_column(void)
 {
        contacts_name_sorting_order_e order;
 
-       contacts_setting_get_name_sorting_order(&order);
+       ctsvc_setting_get_name_sorting_order(&order);
        if (CONTACTS_NAME_SORTING_ORDER_FIRSTLAST == order)
                return "display_name_language, sortkey";
        else