4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include "ctsvc_internal.h"
23 #include "ctsvc_client_handle.h"
24 #include "ctsvc_client_db_helper.h"
26 EXPORT_API int contacts_db_insert_record(contacts_record_h record, int *id)
28 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
30 contacts_h contact = NULL;
32 ret = ctsvc_client_handle_get_p(&contact);
33 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
35 ret = ctsvc_client_db_insert_record(contact, record, id);
40 EXPORT_API int contacts_db_get_record(const char *view_uri, int id, contacts_record_h *out_record)
42 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
43 /*Need to check for telephony support*/
45 contacts_h contact = NULL;
47 ret = ctsvc_client_handle_get_p(&contact);
48 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
50 ret = ctsvc_client_db_get_record(contact, view_uri, id, out_record);
55 EXPORT_API int contacts_db_update_record(contacts_record_h record)
57 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
59 contacts_h contact = NULL;
61 ret = ctsvc_client_handle_get_p(&contact);
62 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
64 ret = ctsvc_client_db_update_record(contact, record);
69 EXPORT_API int contacts_db_delete_record(const char *view_uri, int id)
71 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
73 contacts_h contact = NULL;
75 ret = ctsvc_client_handle_get_p(&contact);
76 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
78 ret = ctsvc_client_db_delete_record(contact, view_uri, id);
83 EXPORT_API int contacts_db_replace_record(contacts_record_h record, int id)
85 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
87 contacts_h contact = NULL;
89 ret = ctsvc_client_handle_get_p(&contact);
90 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
92 ret = ctsvc_client_db_replace_record(contact, record, id);
98 EXPORT_API int contacts_db_get_all_records(const char *view_uri, int offset, int limit, contacts_list_h *out_list)
100 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
102 contacts_h contact = NULL;
104 ret = ctsvc_client_handle_get_p(&contact);
105 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
107 ret = ctsvc_client_db_get_all_records(contact, view_uri, offset, limit, out_list);
112 EXPORT_API int contacts_db_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h *out_list)
114 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
116 contacts_h contact = NULL;
118 ret = ctsvc_client_handle_get_p(&contact);
119 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
121 ret = ctsvc_client_db_get_records_with_query(contact, query, offset, limit, out_list);
127 EXPORT_API int contacts_db_get_count(const char *view_uri, int *out_count)
129 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
131 contacts_h contact = NULL;
133 ret = ctsvc_client_handle_get_p(&contact);
134 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
136 ret = ctsvc_client_db_get_count(contact, view_uri, out_count);
141 EXPORT_API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
143 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
145 contacts_h contact = NULL;
147 ret = ctsvc_client_handle_get_p(&contact);
148 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
150 ret = ctsvc_client_db_get_count_with_query(contact, query, out_count);
155 EXPORT_API int contacts_db_insert_records(contacts_list_h list, int **ids, int *count)
157 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
159 contacts_h contact = NULL;
161 ret = ctsvc_client_handle_get_p(&contact);
162 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
164 ret = ctsvc_client_db_insert_records(contact, list, ids, count);
169 EXPORT_API int contacts_db_update_records(contacts_list_h list)
171 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
173 contacts_h contact = NULL;
175 ret = ctsvc_client_handle_get_p(&contact);
176 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
178 ret = ctsvc_client_db_update_records(contact, list);
183 EXPORT_API int contacts_db_delete_records(const char *view_uri, int ids[], int count)
185 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
187 contacts_h contact = NULL;
189 ret = ctsvc_client_handle_get_p(&contact);
190 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
192 ret = ctsvc_client_db_delete_records(contact, view_uri, ids, count);
197 EXPORT_API int contacts_db_replace_records(contacts_list_h list, int ids[], int count)
199 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
201 contacts_h contact = NULL;
203 ret = ctsvc_client_handle_get_p(&contact);
204 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
206 ret = ctsvc_client_db_replace_records(contact, list, ids, count);
211 EXPORT_API int contacts_db_get_changes_by_version(const char *view_uri, int addressbook_id,
212 int contacts_db_version, contacts_list_h *record_list, int *current_contacts_db_version)
214 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
216 contacts_h contact = NULL;
218 ret = ctsvc_client_handle_get_p(&contact);
219 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
221 ret = ctsvc_client_db_get_changes_by_version(contact, view_uri, addressbook_id, contacts_db_version, record_list, current_contacts_db_version);
226 EXPORT_API int contacts_db_get_current_version(int *contacts_db_version)
228 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
230 contacts_h contact = NULL;
232 ret = ctsvc_client_handle_get_p(&contact);
233 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
235 ret = ctsvc_client_db_get_current_version(contact, contacts_db_version);
241 EXPORT_API int contacts_db_search_records(const char *view_uri, const char *keyword,
242 int offset, int limit, contacts_list_h *out_list)
244 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
246 contacts_h contact = NULL;
248 ret = ctsvc_client_handle_get_p(&contact);
249 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
251 ret = ctsvc_client_db_search_records(contact, view_uri, keyword, offset, limit, out_list);
256 EXPORT_API int contacts_db_search_records_with_range(const char *view_uri, const char *keyword,
257 int offset, int limit, int range, contacts_list_h *out_list)
259 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
261 contacts_h contact = NULL;
263 ret = ctsvc_client_handle_get_p(&contact);
264 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
266 ret = ctsvc_client_db_search_records_with_range(contact, view_uri, keyword, offset, limit, range, out_list);
271 EXPORT_API int contacts_db_search_records_with_query(contacts_query_h query, const char *keyword,
272 int offset, int limit, contacts_list_h *out_list)
274 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
276 contacts_h contact = NULL;
278 ret = ctsvc_client_handle_get_p(&contact);
279 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
281 ret = ctsvc_client_db_search_records_with_query(contact, query, keyword, offset, limit, out_list);
286 EXPORT_API int contacts_db_search_records_for_snippet(const char *view_uri,
290 const char *start_match,
291 const char *end_match,
293 contacts_list_h *out_list)
295 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
297 contacts_h contact = NULL;
299 ret = ctsvc_client_handle_get_p(&contact);
300 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
302 ret = ctsvc_client_db_search_records_for_snippet(contact, view_uri, keyword,
303 offset, limit, start_match, end_match, token_number, out_list);
308 EXPORT_API int contacts_db_search_records_with_range_for_snippet(const char *view_uri,
313 const char *start_match,
314 const char *end_match,
316 contacts_list_h *out_list)
318 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
320 contacts_h contact = NULL;
322 ret = ctsvc_client_handle_get_p(&contact);
323 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
325 ret = ctsvc_client_db_search_records_with_range_for_snippet(contact, view_uri,
326 keyword, offset, limit, range, start_match, end_match, token_number, out_list);
331 EXPORT_API int contacts_db_search_records_with_query_for_snippet(contacts_query_h query,
335 const char *start_match,
336 const char *end_match,
338 contacts_list_h *out_list)
340 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
342 contacts_h contact = NULL;
344 ret = ctsvc_client_handle_get_p(&contact);
345 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
347 ret = ctsvc_client_db_search_records_with_query_for_snippet(contact, query, keyword,
348 offset, limit, start_match, end_match, token_number, out_list);
353 EXPORT_API int contacts_db_get_last_change_version(int *last_version)
355 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
357 contacts_h contact = NULL;
359 ret = ctsvc_client_handle_get_p(&contact);
360 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
362 ret = ctsvc_client_db_get_last_change_version(contact, last_version);
367 EXPORT_API int contacts_db_get_status(contacts_db_status_e *status)
369 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
371 contacts_h contact = NULL;
373 ret = ctsvc_client_handle_get_p(&contact);
374 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
376 ret = ctsvc_client_db_get_status(contact, status);
381 EXPORT_API int contacts_db_add_status_changed_cb(
382 contacts_db_status_changed_cb cb, void *user_data)
384 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
386 contacts_h contact = NULL;
388 ret = ctsvc_client_handle_get_p(&contact);
389 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
391 ret = ctsvc_client_db_add_status_changed_cb(contact, cb, user_data);
396 EXPORT_API int contacts_db_remove_status_changed_cb(
397 contacts_db_status_changed_cb cb, void *user_data)
399 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
401 contacts_h contact = NULL;
403 ret = ctsvc_client_handle_get_p(&contact);
404 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
406 ret = ctsvc_client_db_remove_status_changed_cb(contact, cb, user_data);
412 EXPORT_API int contacts_db_get_count_for_search_records(const char *view_uri, const char *keyword, unsigned int *out_count)
414 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
416 contacts_h contact = NULL;
418 ret = ctsvc_client_handle_get_p(&contact);
419 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
421 ret = ctsvc_client_db_get_count_for_search_records(contact, view_uri, keyword, out_count);
426 EXPORT_API int contacts_db_get_count_for_search_records_with_range(const char *view_uri, const char *keyword, int range, unsigned int *out_count)
428 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
430 contacts_h contact = NULL;
432 ret = ctsvc_client_handle_get_p(&contact);
433 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
435 ret = ctsvc_client_db_get_count_for_search_records_with_range(contact, view_uri, keyword, range, out_count);
440 EXPORT_API int contacts_db_get_count_for_search_records_with_query(contacts_query_h query, const char *keyword, unsigned int *out_count)
442 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
444 contacts_h contact = NULL;
446 ret = ctsvc_client_handle_get_p(&contact);
447 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
449 ret = ctsvc_client_db_get_count_for_search_records_with_query(contact, query, keyword, out_count);