Fixed the build error for gcc-14
[platform/core/pim/contacts-service.git] / client / ctsvc_client_db.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 #include "contacts.h"
22 #include "ctsvc_internal.h"
23 #include "ctsvc_client_handle.h"
24 #include "ctsvc_client_db_helper.h"
25
26 EXPORT_API int contacts_db_insert_record(contacts_record_h record, int *id)
27 {
28         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
29         int ret;
30         contacts_h contact = NULL;
31
32         ret = ctsvc_client_handle_get_p(&contact);
33         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
34
35         ret = ctsvc_client_db_insert_record(contact, record, id);
36
37         return ret;
38 }
39
40 EXPORT_API int contacts_db_get_record(const char *view_uri, int id, contacts_record_h *out_record)
41 {
42         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
43          /*Need to check for telephony support*/
44         int ret;
45         contacts_h contact = NULL;
46
47         ret = ctsvc_client_handle_get_p(&contact);
48         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
49
50         ret = ctsvc_client_db_get_record(contact, view_uri, id, out_record);
51
52         return ret;
53 }
54
55 EXPORT_API int contacts_db_update_record(contacts_record_h record)
56 {
57         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
58         int ret;
59         contacts_h contact = NULL;
60
61         ret = ctsvc_client_handle_get_p(&contact);
62         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
63
64         ret = ctsvc_client_db_update_record(contact, record);
65
66         return ret;
67 }
68
69 EXPORT_API int contacts_db_delete_record(const char *view_uri, int id)
70 {
71         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
72         int ret;
73         contacts_h contact = NULL;
74
75         ret = ctsvc_client_handle_get_p(&contact);
76         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
77
78         ret = ctsvc_client_db_delete_record(contact, view_uri, id);
79
80         return ret;
81 }
82
83 EXPORT_API int contacts_db_replace_record(contacts_record_h record, int id)
84 {
85         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
86         int ret;
87         contacts_h contact = NULL;
88
89         ret = ctsvc_client_handle_get_p(&contact);
90         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
91
92         ret = ctsvc_client_db_replace_record(contact, record, id);
93
94         return ret;
95
96 }
97
98 EXPORT_API int contacts_db_get_all_records(const char *view_uri, int offset, int limit, contacts_list_h *out_list)
99 {
100         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
101         int ret;
102         contacts_h contact = NULL;
103
104         ret = ctsvc_client_handle_get_p(&contact);
105         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
106
107         ret = ctsvc_client_db_get_all_records(contact, view_uri, offset, limit, out_list);
108
109         return ret;
110 }
111
112 EXPORT_API int contacts_db_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h *out_list)
113 {
114         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
115         int ret;
116         contacts_h contact = NULL;
117
118         ret = ctsvc_client_handle_get_p(&contact);
119         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
120
121         ret = ctsvc_client_db_get_records_with_query(contact, query, offset, limit, out_list);
122
123         return ret;
124 }
125
126
127 EXPORT_API int contacts_db_get_count(const char *view_uri, int *out_count)
128 {
129         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
130         int ret;
131         contacts_h contact = NULL;
132
133         ret = ctsvc_client_handle_get_p(&contact);
134         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
135
136         ret = ctsvc_client_db_get_count(contact, view_uri, out_count);
137
138         return ret;
139 }
140
141 EXPORT_API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
142 {
143         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
144         int ret;
145         contacts_h contact = NULL;
146
147         ret = ctsvc_client_handle_get_p(&contact);
148         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
149
150         ret = ctsvc_client_db_get_count_with_query(contact, query, out_count);
151
152         return ret;
153 }
154
155 EXPORT_API int contacts_db_insert_records(contacts_list_h list, int **ids, int *count)
156 {
157         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
158         int ret;
159         contacts_h contact = NULL;
160
161         ret = ctsvc_client_handle_get_p(&contact);
162         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
163
164         ret = ctsvc_client_db_insert_records(contact, list, ids, count);
165
166         return ret;
167 }
168
169 EXPORT_API int contacts_db_update_records(contacts_list_h list)
170 {
171         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
172         int ret;
173         contacts_h contact = NULL;
174
175         ret = ctsvc_client_handle_get_p(&contact);
176         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
177
178         ret = ctsvc_client_db_update_records(contact, list);
179
180         return ret;
181 }
182
183 EXPORT_API int contacts_db_delete_records(const char *view_uri, int ids[], int count)
184 {
185         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
186         int ret;
187         contacts_h contact = NULL;
188
189         ret = ctsvc_client_handle_get_p(&contact);
190         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
191
192         ret = ctsvc_client_db_delete_records(contact, view_uri, ids, count);
193
194         return ret;
195 }
196
197 EXPORT_API int contacts_db_replace_records(contacts_list_h list, int ids[], int count)
198 {
199         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
200         int ret;
201         contacts_h contact = NULL;
202
203         ret = ctsvc_client_handle_get_p(&contact);
204         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
205
206         ret = ctsvc_client_db_replace_records(contact, list, ids, count);
207
208         return ret;
209 }
210
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)
213 {
214         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
215         int ret;
216         contacts_h contact = NULL;
217
218         ret = ctsvc_client_handle_get_p(&contact);
219         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
220
221         ret = ctsvc_client_db_get_changes_by_version(contact, view_uri, addressbook_id, contacts_db_version, record_list, current_contacts_db_version);
222
223         return ret;
224 }
225
226 EXPORT_API int contacts_db_get_current_version(int *contacts_db_version)
227 {
228         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
229         int ret;
230         contacts_h contact = NULL;
231
232         ret = ctsvc_client_handle_get_p(&contact);
233         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
234
235         ret = ctsvc_client_db_get_current_version(contact, contacts_db_version);
236
237         return ret;
238
239 }
240
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)
243 {
244         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
245         int ret;
246         contacts_h contact = NULL;
247
248         ret = ctsvc_client_handle_get_p(&contact);
249         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
250
251         ret = ctsvc_client_db_search_records(contact, view_uri, keyword, offset, limit, out_list);
252
253         return ret;
254 }
255
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)
258 {
259         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
260         int ret;
261         contacts_h contact = NULL;
262
263         ret = ctsvc_client_handle_get_p(&contact);
264         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
265
266         ret = ctsvc_client_db_search_records_with_range(contact, view_uri, keyword, offset, limit, range, out_list);
267
268         return ret;
269 }
270
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)
273 {
274         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
275         int ret;
276         contacts_h contact = NULL;
277
278         ret = ctsvc_client_handle_get_p(&contact);
279         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
280
281         ret = ctsvc_client_db_search_records_with_query(contact, query, keyword, offset, limit, out_list);
282
283         return ret;
284 }
285
286 EXPORT_API int contacts_db_search_records_for_snippet(const char *view_uri,
287                 const char *keyword,
288                 int offset,
289                 int limit,
290                 const char *start_match,
291                 const char *end_match,
292                 int token_number,
293                 contacts_list_h *out_list)
294 {
295         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
296         int ret;
297         contacts_h contact = NULL;
298
299         ret = ctsvc_client_handle_get_p(&contact);
300         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
301
302         ret = ctsvc_client_db_search_records_for_snippet(contact, view_uri, keyword,
303                         offset, limit, start_match, end_match, token_number, out_list);
304
305         return ret;
306 }
307
308 EXPORT_API int contacts_db_search_records_with_range_for_snippet(const char *view_uri,
309                 const char *keyword,
310                 int offset,
311                 int limit,
312                 int range,
313                 const char *start_match,
314                 const char *end_match,
315                 int token_number,
316                 contacts_list_h *out_list)
317 {
318         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
319         int ret;
320         contacts_h contact = NULL;
321
322         ret = ctsvc_client_handle_get_p(&contact);
323         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
324
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);
327
328         return ret;
329 }
330
331 EXPORT_API int contacts_db_search_records_with_query_for_snippet(contacts_query_h query,
332                 const char *keyword,
333                 int offset,
334                 int limit,
335                 const char *start_match,
336                 const char *end_match,
337                 int token_number,
338                 contacts_list_h *out_list)
339 {
340         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
341         int ret;
342         contacts_h contact = NULL;
343
344         ret = ctsvc_client_handle_get_p(&contact);
345         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
346
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);
349
350         return ret;
351 }
352
353 EXPORT_API int contacts_db_get_last_change_version(int *last_version)
354 {
355         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
356         int ret;
357         contacts_h contact = NULL;
358
359         ret = ctsvc_client_handle_get_p(&contact);
360         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
361
362         ret = ctsvc_client_db_get_last_change_version(contact, last_version);
363
364         return ret;
365 }
366
367 EXPORT_API int contacts_db_get_status(contacts_db_status_e *status)
368 {
369         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
370         int ret;
371         contacts_h contact = NULL;
372
373         ret = ctsvc_client_handle_get_p(&contact);
374         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
375
376         ret = ctsvc_client_db_get_status(contact, status);
377
378         return ret;
379 }
380
381 EXPORT_API int contacts_db_add_status_changed_cb(
382                 contacts_db_status_changed_cb cb, void *user_data)
383 {
384         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
385         int ret;
386         contacts_h contact = NULL;
387
388         ret = ctsvc_client_handle_get_p(&contact);
389         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
390
391         ret = ctsvc_client_db_add_status_changed_cb(contact, cb, user_data);
392
393         return ret;
394 }
395
396 EXPORT_API int contacts_db_remove_status_changed_cb(
397                 contacts_db_status_changed_cb cb, void *user_data)
398 {
399         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
400         int ret;
401         contacts_h contact = NULL;
402
403         ret = ctsvc_client_handle_get_p(&contact);
404         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
405
406         ret = ctsvc_client_db_remove_status_changed_cb(contact, cb, user_data);
407
408         return ret;
409 }
410
411
412 EXPORT_API int contacts_db_get_count_for_search_records(const char *view_uri, const char *keyword, unsigned int *out_count)
413 {
414         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
415         int ret;
416         contacts_h contact = NULL;
417
418         ret = ctsvc_client_handle_get_p(&contact);
419         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
420
421         ret = ctsvc_client_db_get_count_for_search_records(contact, view_uri, keyword, out_count);
422
423         return ret;
424 }
425
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)
427 {
428         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
429         int ret;
430         contacts_h contact = NULL;
431
432         ret = ctsvc_client_handle_get_p(&contact);
433         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
434
435         ret = ctsvc_client_db_get_count_for_search_records_with_range(contact, view_uri, keyword, range, out_count);
436
437         return ret;
438 }
439
440 EXPORT_API int contacts_db_get_count_for_search_records_with_query(contacts_query_h query, const char *keyword, unsigned int *out_count)
441 {
442         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
443         int ret;
444         contacts_h contact = NULL;
445
446         ret = ctsvc_client_handle_get_p(&contact);
447         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
448
449         ret = ctsvc_client_db_get_count_for_search_records_with_query(contact, query, keyword, out_count);
450
451         return ret;
452 }
453
454
455