Add APIs to set/get limit size of photo for vcard
[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 API int contacts_db_insert_record(contacts_record_h record, int *id)
27 {
28         int ret;
29         contacts_h contact = NULL;
30
31         ret = ctsvc_client_handle_get_p(&contact);
32         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
33
34         ret = ctsvc_client_db_insert_record(contact, record, id);
35
36         return ret;
37 }
38
39 API int contacts_db_get_record(const char *view_uri, int id, contacts_record_h *out_record)
40 {
41         int ret;
42         contacts_h contact = NULL;
43
44         ret = ctsvc_client_handle_get_p(&contact);
45         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
46
47         ret = ctsvc_client_db_get_record(contact, view_uri, id, out_record);
48
49         return ret;
50 }
51
52 API int contacts_db_update_record(contacts_record_h record)
53 {
54         int ret;
55         contacts_h contact = NULL;
56
57         ret = ctsvc_client_handle_get_p(&contact);
58         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
59
60         ret = ctsvc_client_db_update_record(contact, record);
61
62         return ret;
63 }
64
65 API int contacts_db_delete_record(const char *view_uri, int id)
66 {
67         int ret;
68         contacts_h contact = NULL;
69
70         ret = ctsvc_client_handle_get_p(&contact);
71         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
72
73         ret = ctsvc_client_db_delete_record(contact, view_uri, id);
74
75         return ret;
76 }
77
78 API int contacts_db_replace_record(contacts_record_h record, int id)
79 {
80         int ret;
81         contacts_h contact = NULL;
82
83         ret = ctsvc_client_handle_get_p(&contact);
84         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
85
86         ret = ctsvc_client_db_replace_record(contact, record, id);
87
88         return ret;
89
90 }
91
92 API int contacts_db_get_all_records(const char *view_uri, int offset, int limit, contacts_list_h *out_list)
93 {
94         int ret;
95         contacts_h contact = NULL;
96
97         ret = ctsvc_client_handle_get_p(&contact);
98         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
99
100         ret = ctsvc_client_db_get_all_records(contact, view_uri, offset, limit, out_list);
101
102         return ret;
103 }
104
105 API int contacts_db_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h *out_list)
106 {
107         int ret;
108         contacts_h contact = NULL;
109
110         ret = ctsvc_client_handle_get_p(&contact);
111         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
112
113         ret = ctsvc_client_db_get_records_with_query(contact, query, offset, limit, out_list);
114
115         return ret;
116 }
117
118
119 API int contacts_db_get_count(const char *view_uri, int *out_count)
120 {
121         int ret;
122         contacts_h contact = NULL;
123
124         ret = ctsvc_client_handle_get_p(&contact);
125         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
126
127         ret = ctsvc_client_db_get_count(contact, view_uri, out_count);
128
129         return ret;
130 }
131
132 API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
133 {
134         int ret;
135         contacts_h contact = NULL;
136
137         ret = ctsvc_client_handle_get_p(&contact);
138         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
139
140         ret = ctsvc_client_db_get_count_with_query(contact, query, out_count);
141
142         return ret;
143 }
144
145 API int contacts_db_insert_records(contacts_list_h list, int **ids, int *count)
146 {
147         int ret;
148         contacts_h contact = NULL;
149
150         ret = ctsvc_client_handle_get_p(&contact);
151         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
152
153         ret = ctsvc_client_db_insert_records(contact, list, ids, count);
154
155         return ret;
156 }
157
158 API int contacts_db_update_records(contacts_list_h list)
159 {
160         int ret;
161         contacts_h contact = NULL;
162
163         ret = ctsvc_client_handle_get_p(&contact);
164         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
165
166         ret = ctsvc_client_db_update_records(contact, list);
167
168         return ret;
169 }
170
171 API int contacts_db_delete_records(const char *view_uri, int ids[], int count)
172 {
173         int ret;
174         contacts_h contact = NULL;
175
176         ret = ctsvc_client_handle_get_p(&contact);
177         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
178
179         ret = ctsvc_client_db_delete_records(contact, view_uri, ids, count);
180
181         return ret;
182 }
183
184 API int contacts_db_replace_records(contacts_list_h list, int ids[], int count)
185 {
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_replace_records(contact, list, ids, count);
193
194         return ret;
195 }
196
197 API int contacts_db_get_changes_by_version(const char *view_uri, int addressbook_id,
198                 int contacts_db_version, contacts_list_h *record_list, int *current_contacts_db_version)
199 {
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_get_changes_by_version(contact, view_uri, addressbook_id, contacts_db_version, record_list, current_contacts_db_version);
207
208         return ret;
209 }
210
211 API int contacts_db_get_current_version(int *contacts_db_version)
212 {
213         int ret;
214         contacts_h contact = NULL;
215
216         ret = ctsvc_client_handle_get_p(&contact);
217         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
218
219         ret = ctsvc_client_db_get_current_version(contact, contacts_db_version);
220
221         return ret;
222
223 }
224
225 API int contacts_db_search_records(const char *view_uri, const char *keyword,
226                 int offset, int limit, contacts_list_h *out_list)
227 {
228         int ret;
229         contacts_h contact = NULL;
230
231         ret = ctsvc_client_handle_get_p(&contact);
232         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
233
234         ret = ctsvc_client_db_search_records(contact, view_uri, keyword, offset, limit, out_list);
235
236         return ret;
237 }
238
239 API int contacts_db_search_records_with_range(const char *view_uri, const char *keyword,
240                 int offset, int limit, int range, contacts_list_h *out_list)
241 {
242         int ret;
243         contacts_h contact = NULL;
244
245         ret = ctsvc_client_handle_get_p(&contact);
246         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
247
248         ret = ctsvc_client_db_search_records_with_range(contact, view_uri, keyword, offset, limit, range, out_list);
249
250         return ret;
251 }
252
253 API int contacts_db_search_records_with_query(contacts_query_h query, const char *keyword,
254                 int offset, int limit, contacts_list_h *out_list)
255 {
256         int ret;
257         contacts_h contact = NULL;
258
259         ret = ctsvc_client_handle_get_p(&contact);
260         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
261
262         ret = ctsvc_client_db_search_records_with_query(contact, query, keyword, offset, limit, out_list);
263
264         return ret;
265 }
266
267 API int contacts_db_get_last_change_version(int *last_version)
268 {
269         int ret;
270         contacts_h contact = NULL;
271
272         ret = ctsvc_client_handle_get_p(&contact);
273         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
274
275         ret = ctsvc_client_db_get_last_change_version(contact, last_version);
276
277         return ret;
278 }
279
280 API int contacts_db_get_status(contacts_db_status_e *status)
281 {
282         int ret;
283         contacts_h contact = NULL;
284
285         ret = ctsvc_client_handle_get_p(&contact);
286         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
287
288         ret = ctsvc_client_db_get_status(contact, status);
289
290         return ret;
291 }
292
293 API int contacts_db_add_status_changed_cb(
294                 contacts_db_status_changed_cb cb, void *user_data)
295 {
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_add_status_changed_cb(contact, cb, user_data);
303
304         return ret;
305 }
306
307 API int contacts_db_remove_status_changed_cb(
308                 contacts_db_status_changed_cb cb, void *user_data)
309 {
310         int ret;
311         contacts_h contact = NULL;
312
313         ret = ctsvc_client_handle_get_p(&contact);
314         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
315
316         ret = ctsvc_client_db_remove_status_changed_cb(contact, cb, user_data);
317
318         return ret;
319 }
320