4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <pims-ipc-data.h>
26 #include "ctsvc_internal.h"
27 #include "ctsvc_list.h"
28 #include "ctsvc_record.h"
29 #include "ctsvc_inotify.h"
30 #include "ctsvc_ipc_define.h"
31 #include "ctsvc_ipc_marshal.h"
32 #include "ctsvc_view.h"
33 #include "ctsvc_client_ipc.h"
34 #include "ctsvc_mutex.h"
35 #include "ctsvc_handle.h"
36 #include "ctsvc_client_db_helper.h"
38 #define CTSVC_DEFAULT_START_MATCH "["
39 #define CTSVC_DEFAULT_END_MATCH "]"
41 int ctsvc_client_db_insert_record(contacts_h contact, contacts_record_h record, int *id)
43 int ret = CONTACTS_ERROR_NONE;
44 pims_ipc_data_h indata = NULL;
45 pims_ipc_data_h outdata = NULL;
50 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
51 RETV_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER);
54 indata = pims_ipc_data_create(0);
56 ERR("pims_ipc_data_create() Fail");
57 return CONTACTS_ERROR_OUT_OF_MEMORY;
60 ret = ctsvc_ipc_marshal_handle(contact, indata);
61 if (ret != CONTACTS_ERROR_NONE) {
62 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
63 pims_ipc_data_destroy(indata);
67 ret = ctsvc_ipc_marshal_record(record, indata);
68 if (ret != CONTACTS_ERROR_NONE) {
69 ERR("ctsvc_ipc_marshal_record() Fail(%d)", ret);
70 pims_ipc_data_destroy(indata);
75 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORD, indata, &outdata) != 0) {
76 ERR("ctsvc_ipc_call() Fail");
77 pims_ipc_data_destroy(indata);
78 return CONTACTS_ERROR_IPC;
81 pims_ipc_data_destroy(indata);
84 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
85 ERR("ctsvc_ipc_unmarshal_int() Fail");
86 pims_ipc_data_destroy(outdata);
87 return CONTACTS_ERROR_IPC;
90 if (CONTACTS_ERROR_NONE == ret) {
91 int transaction_ver = 0;
92 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
93 ERR("ctsvc_ipc_unmarshal_int() Fail");
94 pims_ipc_data_destroy(outdata);
95 return CONTACTS_ERROR_IPC;
97 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
100 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, id)) {
101 ERR("ctsvc_ipc_unmarshal_int() Fail");
102 pims_ipc_data_destroy(outdata);
103 return CONTACTS_ERROR_IPC;
107 pims_ipc_data_destroy(outdata);
113 int ctsvc_client_db_get_record(contacts_h contact, const char *view_uri, int id, contacts_record_h *out_record)
115 int ret = CONTACTS_ERROR_NONE;
116 pims_ipc_data_h indata = NULL;
117 pims_ipc_data_h outdata = NULL;
119 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
120 RETV_IF(NULL == view_uri, CONTACTS_ERROR_INVALID_PARAMETER);
121 RETVM_IF(id < 0, CONTACTS_ERROR_INVALID_PARAMETER, "id < 0");
122 RETV_IF(NULL == out_record, CONTACTS_ERROR_INVALID_PARAMETER);
126 indata = pims_ipc_data_create(0);
127 if (indata == NULL) {
128 ERR("pims_ipc_data_create() Fail");
129 return CONTACTS_ERROR_OUT_OF_MEMORY;
132 ret = ctsvc_ipc_marshal_handle(contact, indata);
133 if (ret != CONTACTS_ERROR_NONE) {
134 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
135 pims_ipc_data_destroy(indata);
139 ret = ctsvc_ipc_marshal_string(view_uri, indata);
140 if (ret != CONTACTS_ERROR_NONE) {
141 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
142 pims_ipc_data_destroy(indata);
145 ret = ctsvc_ipc_marshal_int(id, indata);
146 if (ret != CONTACTS_ERROR_NONE) {
147 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
148 pims_ipc_data_destroy(indata);
153 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORD, indata, &outdata) != 0) {
154 ERR("ctsvc_ipc_call() Fail");
155 pims_ipc_data_destroy(indata);
156 return CONTACTS_ERROR_IPC;
159 pims_ipc_data_destroy(indata);
162 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
163 ERR("ctsvc_ipc_unmarshal_int() Fail");
164 pims_ipc_data_destroy(outdata);
165 return CONTACTS_ERROR_IPC;
167 if (CONTACTS_ERROR_NONE == ret) {
168 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_record(outdata, out_record)) {
169 ERR("ctsvc_ipc_unmarshal_record() Fail");
170 pims_ipc_data_destroy(outdata);
171 return CONTACTS_ERROR_IPC;
174 pims_ipc_data_destroy(outdata);
179 int ctsvc_client_db_update_record(contacts_h contact, contacts_record_h record)
181 int ret = CONTACTS_ERROR_NONE;
182 pims_ipc_data_h indata = NULL;
183 pims_ipc_data_h outdata = NULL;
185 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
186 RETV_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER);
189 indata = pims_ipc_data_create(0);
190 if (indata == NULL) {
191 ERR("pims_ipc_data_create() Fail");
192 return CONTACTS_ERROR_OUT_OF_MEMORY;
195 ret = ctsvc_ipc_marshal_handle(contact, indata);
196 if (ret != CONTACTS_ERROR_NONE) {
197 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
198 pims_ipc_data_destroy(indata);
202 ret = ctsvc_ipc_marshal_record(record, indata);
203 if (ret != CONTACTS_ERROR_NONE) {
204 ERR("ctsvc_ipc_marshal_record() Fail(%d)", ret);
205 pims_ipc_data_destroy(indata);
210 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORD, indata, &outdata) != 0) {
211 ERR("ctsvc_ipc_call() Fail");
212 pims_ipc_data_destroy(indata);
213 return CONTACTS_ERROR_IPC;
216 pims_ipc_data_destroy(indata);
219 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
220 ERR("ctsvc_ipc_unmarshal_int() Fail");
221 pims_ipc_data_destroy(outdata);
222 return CONTACTS_ERROR_IPC;
224 if (CONTACTS_ERROR_NONE == ret) {
225 CTSVC_RECORD_RESET_PROPERTY_FLAGS((ctsvc_record_s*)record);
226 int transaction_ver = 0;
227 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
228 ERR("ctsvc_ipc_unmarshal_int() Fail");
229 pims_ipc_data_destroy(outdata);
230 return CONTACTS_ERROR_IPC;
232 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
234 pims_ipc_data_destroy(outdata);
239 int ctsvc_client_db_delete_record(contacts_h contact, const char *view_uri, int id)
241 int ret = CONTACTS_ERROR_NONE;
242 pims_ipc_data_h indata = NULL;
243 pims_ipc_data_h outdata = NULL;
245 RETV_IF(NULL == view_uri, CONTACTS_ERROR_INVALID_PARAMETER);
246 RETVM_IF(id <= 0, CONTACTS_ERROR_INVALID_PARAMETER, "id <= 0");
249 indata = pims_ipc_data_create(0);
250 if (indata == NULL) {
251 ERR("pims_ipc_data_create() Fail");
252 return CONTACTS_ERROR_OUT_OF_MEMORY;
255 ret = ctsvc_ipc_marshal_handle(contact, indata);
256 if (CONTACTS_ERROR_NONE != ret) {
257 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
258 pims_ipc_data_destroy(indata);
262 ret = ctsvc_ipc_marshal_string(view_uri, indata);
263 if (ret != CONTACTS_ERROR_NONE) {
264 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
265 pims_ipc_data_destroy(indata);
268 ret = ctsvc_ipc_marshal_int(id, indata);
269 if (ret != CONTACTS_ERROR_NONE) {
270 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
271 pims_ipc_data_destroy(indata);
276 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORD, indata, &outdata) != 0) {
277 ERR("ctsvc_ipc_call() Fail");
278 pims_ipc_data_destroy(indata);
279 return CONTACTS_ERROR_IPC;
282 pims_ipc_data_destroy(indata);
285 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
286 ERR("ctsvc_ipc_unmarshal_int() Fail");
287 pims_ipc_data_destroy(outdata);
288 return CONTACTS_ERROR_IPC;
290 if (CONTACTS_ERROR_NONE == ret) {
291 int transaction_ver = 0;
292 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
293 ERR("ctsvc_ipc_unmarshal_int() Fail");
294 pims_ipc_data_destroy(outdata);
295 return CONTACTS_ERROR_IPC;
297 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
300 pims_ipc_data_destroy(outdata);
306 int ctsvc_client_db_replace_record(contacts_h contact, contacts_record_h record, int id)
308 int ret = CONTACTS_ERROR_NONE;
309 pims_ipc_data_h indata = NULL;
310 pims_ipc_data_h outdata = NULL;
312 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
313 RETV_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER);
316 indata = pims_ipc_data_create(0);
317 if (indata == NULL) {
318 ERR("pims_ipc_data_create() Fail");
319 return CONTACTS_ERROR_OUT_OF_MEMORY;
322 ret = ctsvc_ipc_marshal_handle(contact, indata);
323 if (CONTACTS_ERROR_NONE != ret) {
324 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
325 pims_ipc_data_destroy(indata);
329 ret = ctsvc_ipc_marshal_record(record, indata);
330 if (ret != CONTACTS_ERROR_NONE) {
331 ERR("ctsvc_ipc_marshal_record() Fail(%d)", ret);
332 pims_ipc_data_destroy(indata);
335 ret = ctsvc_ipc_marshal_int(id, indata);
336 if (ret != CONTACTS_ERROR_NONE) {
337 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
338 pims_ipc_data_destroy(indata);
343 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE,
344 CTSVC_IPC_SERVER_DB_REPLACE_RECORD, indata, &outdata) != 0) {
345 ERR("ctsvc_ipc_call() Fail");
346 pims_ipc_data_destroy(indata);
347 return CONTACTS_ERROR_IPC;
350 pims_ipc_data_destroy(indata);
353 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
354 ERR("ctsvc_ipc_unmarshal_int() Fail");
355 pims_ipc_data_destroy(outdata);
356 return CONTACTS_ERROR_IPC;
358 if (CONTACTS_ERROR_NONE == ret) {
359 int transaction_ver = 0;
360 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
361 ERR("ctsvc_ipc_unmarshal_int() Fail");
362 pims_ipc_data_destroy(outdata);
363 return CONTACTS_ERROR_IPC;
365 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
367 pims_ipc_data_destroy(outdata);
373 int ctsvc_client_db_get_all_records(contacts_h contact, const char *view_uri, int offset, int limit, contacts_list_h *out_list)
375 int ret = CONTACTS_ERROR_NONE;
376 pims_ipc_data_h indata = NULL;
377 pims_ipc_data_h outdata = NULL;
379 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
380 RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
382 RETV_IF(NULL == view_uri, CONTACTS_ERROR_INVALID_PARAMETER);
385 indata = pims_ipc_data_create(0);
386 if (indata == NULL) {
387 ERR("pims_ipc_data_create() Fail");
388 return CONTACTS_ERROR_OUT_OF_MEMORY;
391 ret = ctsvc_ipc_marshal_handle(contact, indata);
392 if (CONTACTS_ERROR_NONE != ret) {
393 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
394 pims_ipc_data_destroy(indata);
398 ret = ctsvc_ipc_marshal_string(view_uri, indata);
399 if (ret != CONTACTS_ERROR_NONE) {
400 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
401 pims_ipc_data_destroy(indata);
404 ret = ctsvc_ipc_marshal_int(offset, indata);
405 if (ret != CONTACTS_ERROR_NONE) {
406 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
407 pims_ipc_data_destroy(indata);
410 ret = ctsvc_ipc_marshal_int(limit, indata);
411 if (ret != CONTACTS_ERROR_NONE) {
412 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
413 pims_ipc_data_destroy(indata);
418 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_ALL_RECORDS, indata, &outdata) != 0) {
419 ERR("ctsvc_ipc_call() Fail");
420 pims_ipc_data_destroy(indata);
421 return CONTACTS_ERROR_IPC;
424 pims_ipc_data_destroy(indata);
427 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
428 ERR("ctsvc_ipc_unmarshal_int() Fail");
429 pims_ipc_data_destroy(outdata);
430 return CONTACTS_ERROR_IPC;
433 if (ret == CONTACTS_ERROR_NONE) {
434 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
435 ERR("ctsvc_ipc_unmarshal_list() Fail");
436 pims_ipc_data_destroy(outdata);
437 return CONTACTS_ERROR_IPC;
440 pims_ipc_data_destroy(outdata);
445 int ctsvc_client_db_get_records_with_query(contacts_h contact, contacts_query_h query, int offset, int limit, contacts_list_h *out_list)
447 int ret = CONTACTS_ERROR_NONE;
448 pims_ipc_data_h indata = NULL;
449 pims_ipc_data_h outdata = NULL;
451 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
452 RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
454 RETV_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER);
457 indata = pims_ipc_data_create(0);
458 if (indata == NULL) {
459 ERR("pims_ipc_data_create() Fail");
460 return CONTACTS_ERROR_OUT_OF_MEMORY;
463 ret = ctsvc_ipc_marshal_handle(contact, indata);
464 if (CONTACTS_ERROR_NONE != ret) {
465 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
466 pims_ipc_data_destroy(indata);
470 ret = ctsvc_ipc_marshal_query(query, indata);
471 if (ret != CONTACTS_ERROR_NONE) {
472 ERR("ctsvc_ipc_marshal_query() Fail(%d)", ret);
473 pims_ipc_data_destroy(indata);
477 ret = ctsvc_ipc_marshal_int(offset, indata);
478 if (ret != CONTACTS_ERROR_NONE) {
479 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
480 pims_ipc_data_destroy(indata);
483 ret = ctsvc_ipc_marshal_int(limit, indata);
484 if (ret != CONTACTS_ERROR_NONE) {
485 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
490 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_RECORDS_WITH_QUERY, indata, &outdata) != 0) {
491 ERR("ctsvc_ipc_call() Fail");
492 pims_ipc_data_destroy(indata);
493 return CONTACTS_ERROR_IPC;
496 pims_ipc_data_destroy(indata);
499 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
500 ERR("ctsvc_ipc_unmarshal_int() Fail");
501 pims_ipc_data_destroy(outdata);
502 return CONTACTS_ERROR_IPC;
505 if (CONTACTS_ERROR_NONE == ret) {
506 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
507 ERR("ctsvc_ipc_unmarshal_list() Fail");
508 pims_ipc_data_destroy(outdata);
509 return CONTACTS_ERROR_IPC;
513 pims_ipc_data_destroy(outdata);
520 int ctsvc_client_db_get_count(contacts_h contact, const char *view_uri, int *out_count)
522 int ret = CONTACTS_ERROR_NONE;
523 pims_ipc_data_h indata = NULL;
524 pims_ipc_data_h outdata = NULL;
526 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
527 RETV_IF(NULL == view_uri, CONTACTS_ERROR_INVALID_PARAMETER);
528 RETV_IF(NULL == out_count, CONTACTS_ERROR_INVALID_PARAMETER);
532 indata = pims_ipc_data_create(0);
533 if (indata == NULL) {
534 ERR("pims_ipc_data_create() Fail");
535 return CONTACTS_ERROR_OUT_OF_MEMORY;
538 ret = ctsvc_ipc_marshal_handle(contact, indata);
539 if (CONTACTS_ERROR_NONE != ret) {
540 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
541 pims_ipc_data_destroy(indata);
545 ret = ctsvc_ipc_marshal_string(view_uri, indata);
546 if (ret != CONTACTS_ERROR_NONE) {
547 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
548 pims_ipc_data_destroy(indata);
553 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT, indata, &outdata) != 0) {
554 ERR("ctsvc_ipc_call() Fail");
555 pims_ipc_data_destroy(indata);
556 return CONTACTS_ERROR_IPC;
559 pims_ipc_data_destroy(indata);
562 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
563 ERR("ctsvc_ipc_unmarshal_int() Fail");
564 pims_ipc_data_destroy(outdata);
565 return CONTACTS_ERROR_IPC;
568 if (CONTACTS_ERROR_NONE == ret) {
569 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, out_count)) {
570 ERR("ctsvc_ipc_unmarshal_int() Fail");
571 pims_ipc_data_destroy(outdata);
572 return CONTACTS_ERROR_IPC;
576 pims_ipc_data_destroy(outdata);
582 int ctsvc_client_db_get_count_with_query(contacts_h contact, contacts_query_h query, int *out_count)
584 int ret = CONTACTS_ERROR_NONE;
585 pims_ipc_data_h indata = NULL;
586 pims_ipc_data_h outdata = NULL;
588 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
589 RETV_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER);
590 RETV_IF(NULL == out_count, CONTACTS_ERROR_INVALID_PARAMETER);
594 indata = pims_ipc_data_create(0);
595 if (indata == NULL) {
596 ERR("pims_ipc_data_create() Fail");
597 return CONTACTS_ERROR_OUT_OF_MEMORY;
600 ret = ctsvc_ipc_marshal_handle(contact, indata);
601 if (CONTACTS_ERROR_NONE != ret) {
602 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
603 pims_ipc_data_destroy(indata);
607 ret = ctsvc_ipc_marshal_query(query, indata);
608 if (ret != CONTACTS_ERROR_NONE) {
609 ERR("ctsvc_ipc_marshal_query() Fail(%d)", ret);
610 pims_ipc_data_destroy(indata);
615 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_COUNT_WITH_QUERY, indata, &outdata) != 0) {
616 ERR("ctsvc_ipc_call() Fail");
617 pims_ipc_data_destroy(indata);
618 return CONTACTS_ERROR_IPC;
621 pims_ipc_data_destroy(indata);
624 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
625 ERR("ctsvc_ipc_unmarshal_int() Fail");
626 pims_ipc_data_destroy(outdata);
627 return CONTACTS_ERROR_IPC;
630 if (CONTACTS_ERROR_NONE == ret) {
631 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, out_count)) {
632 ERR("ctsvc_ipc_unmarshal_int() Fail");
633 pims_ipc_data_destroy(outdata);
634 return CONTACTS_ERROR_IPC;
637 pims_ipc_data_destroy(outdata);
643 int ctsvc_client_db_insert_records(contacts_h contact, contacts_list_h list, int **ids, int *count)
645 int ret = CONTACTS_ERROR_NONE;
646 pims_ipc_data_h indata = NULL;
647 pims_ipc_data_h outdata = NULL;
654 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
655 RETV_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER);
657 indata = pims_ipc_data_create(0);
658 if (indata == NULL) {
659 ERR("pims_ipc_data_create() Fail");
660 return CONTACTS_ERROR_OUT_OF_MEMORY;
663 ret = ctsvc_ipc_marshal_handle(contact, indata);
664 if (CONTACTS_ERROR_NONE != ret) {
665 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
666 pims_ipc_data_destroy(indata);
670 ret = ctsvc_ipc_marshal_list(list, indata);
671 if (ret != CONTACTS_ERROR_NONE) {
672 ERR("ctsvc_ipc_marshal_list() Fail(%d)", ret);
673 pims_ipc_data_destroy(indata);
677 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_INSERT_RECORDS,
678 indata, &outdata) != 0) {
679 ERR("ctsvc_ipc_call() Fail");
680 pims_ipc_data_destroy(indata);
681 return CONTACTS_ERROR_IPC;
684 pims_ipc_data_destroy(indata);
687 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
688 ERR("ctsvc_ipc_unmarshal_int() Fail");
689 pims_ipc_data_destroy(outdata);
690 return CONTACTS_ERROR_IPC;
693 if (CONTACTS_ERROR_NONE == ret) {
694 int transaction_ver = 0;
695 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
696 ERR("ctsvc_ipc_unmarshal_int() Fail");
697 pims_ipc_data_destroy(outdata);
698 return CONTACTS_ERROR_IPC;
700 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
707 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &c)) {
708 ERR("ctsvc_ipc_unmarshal_int() Fail");
709 pims_ipc_data_destroy(outdata);
710 return CONTACTS_ERROR_IPC;
712 id = calloc(c, sizeof(int));
714 ERR("calloc() Fail");
715 pims_ipc_data_destroy(outdata);
716 return CONTACTS_ERROR_OUT_OF_MEMORY;
719 for (i = 0; i < c; i++) {
720 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &(id[i]))) {
721 ERR("ctsvc_ipc_unmarshal_int() Fail");
722 pims_ipc_data_destroy(outdata);
724 return CONTACTS_ERROR_IPC;
731 pims_ipc_data_destroy(outdata);
737 int ctsvc_client_db_update_records(contacts_h contact, contacts_list_h list)
739 int ret = CONTACTS_ERROR_NONE;
740 pims_ipc_data_h indata = NULL;
741 pims_ipc_data_h outdata = NULL;
743 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
744 RETV_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER);
746 indata = pims_ipc_data_create(0);
747 if (indata == NULL) {
748 ERR("pims_ipc_data_create() Fail");
749 return CONTACTS_ERROR_OUT_OF_MEMORY;
752 ret = ctsvc_ipc_marshal_handle(contact, indata);
753 if (CONTACTS_ERROR_NONE != ret) {
754 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
755 pims_ipc_data_destroy(indata);
759 ret = ctsvc_ipc_marshal_list(list, indata);
760 if (ret != CONTACTS_ERROR_NONE) {
761 ERR("ctsvc_ipc_marshal_list() Fail(%d)", ret);
762 pims_ipc_data_destroy(indata);
766 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_UPDATE_RECORDS,
767 indata, &outdata) != 0) {
768 ERR("ctsvc_ipc_call() Fail");
769 pims_ipc_data_destroy(indata);
770 return CONTACTS_ERROR_IPC;
773 pims_ipc_data_destroy(indata);
776 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
777 ERR("ctsvc_ipc_unmarshal_int() Fail");
778 pims_ipc_data_destroy(outdata);
779 return CONTACTS_ERROR_IPC;
782 if (CONTACTS_ERROR_NONE == ret) {
783 int transaction_ver = 0;
784 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
785 ERR("ctsvc_ipc_unmarshal_int() Fail");
786 pims_ipc_data_destroy(outdata);
787 return CONTACTS_ERROR_IPC;
789 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
792 pims_ipc_data_destroy(outdata);
798 int ctsvc_client_db_delete_records(contacts_h contact, const char *view_uri, int ids[], int count)
801 int ret = CONTACTS_ERROR_NONE;
802 pims_ipc_data_h indata = NULL;
803 pims_ipc_data_h outdata = NULL;
805 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
806 RETV_IF(NULL == view_uri, CONTACTS_ERROR_INVALID_PARAMETER);
808 indata = pims_ipc_data_create(0);
809 if (indata == NULL) {
810 ERR("pims_ipc_data_create() Fail");
811 return CONTACTS_ERROR_OUT_OF_MEMORY;
814 ret = ctsvc_ipc_marshal_handle(contact, indata);
815 if (CONTACTS_ERROR_NONE != ret) {
816 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
817 pims_ipc_data_destroy(indata);
821 ret = ctsvc_ipc_marshal_string(view_uri, indata);
822 if (ret != CONTACTS_ERROR_NONE) {
823 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
824 pims_ipc_data_destroy(indata);
828 ret = ctsvc_ipc_marshal_int(count, indata);
829 if (ret != CONTACTS_ERROR_NONE) {
830 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
831 pims_ipc_data_destroy(indata);
835 for (i = 0; i < count; i++) {
836 ret = ctsvc_ipc_marshal_int(ids[i], indata);
837 if (ret != CONTACTS_ERROR_NONE) {
838 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
839 pims_ipc_data_destroy(indata);
844 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_DELETE_RECORDS,
845 indata, &outdata) != 0) {
846 ERR("ctsvc_ipc_call() Fail");
847 pims_ipc_data_destroy(indata);
848 return CONTACTS_ERROR_IPC;
851 pims_ipc_data_destroy(indata);
854 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
855 ERR("ctsvc_ipc_unmarshal_int() Fail");
856 pims_ipc_data_destroy(outdata);
857 return CONTACTS_ERROR_IPC;
860 if (CONTACTS_ERROR_NONE == ret) {
861 int transaction_ver = 0;
862 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
863 ERR("ctsvc_ipc_unmarshal_int() Fail");
864 pims_ipc_data_destroy(outdata);
865 return CONTACTS_ERROR_IPC;
867 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
870 pims_ipc_data_destroy(outdata);
876 int ctsvc_client_db_replace_records(contacts_h contact, contacts_list_h list, int ids[], int count)
879 int ret = CONTACTS_ERROR_NONE;
880 pims_ipc_data_h indata = NULL;
881 pims_ipc_data_h outdata = NULL;
883 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
884 RETV_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER);
885 RETV_IF(NULL == ids, CONTACTS_ERROR_INVALID_PARAMETER);
886 RETV_IF(0 == count, CONTACTS_ERROR_INVALID_PARAMETER);
889 indata = pims_ipc_data_create(0);
890 if (indata == NULL) {
891 ERR("pims_ipc_data_create() Fail");
892 return CONTACTS_ERROR_OUT_OF_MEMORY;
895 ret = ctsvc_ipc_marshal_handle(contact, indata);
896 if (CONTACTS_ERROR_NONE != ret) {
897 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
898 pims_ipc_data_destroy(indata);
902 ret = ctsvc_ipc_marshal_list(list, indata);
903 if (ret != CONTACTS_ERROR_NONE) {
904 ERR("ctsvc_ipc_marshal_list() Fail(%d)", ret);
905 pims_ipc_data_destroy(indata);
909 ret = ctsvc_ipc_marshal_int(count, indata);
910 if (ret != CONTACTS_ERROR_NONE) {
911 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
912 pims_ipc_data_destroy(indata);
916 for (i = 0; i < count; i++) {
917 ret = ctsvc_ipc_marshal_int(ids[i], indata);
918 if (ret != CONTACTS_ERROR_NONE) {
919 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
920 pims_ipc_data_destroy(indata);
925 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_REPLACE_RECORDS,
926 indata, &outdata) != 0) {
927 ERR("ctsvc_ipc_call() Fail");
928 pims_ipc_data_destroy(indata);
929 return CONTACTS_ERROR_IPC;
932 pims_ipc_data_destroy(indata);
935 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
936 ERR("ctsvc_ipc_unmarshal_int() Fail");
937 pims_ipc_data_destroy(outdata);
938 return CONTACTS_ERROR_IPC;
940 if (CONTACTS_ERROR_NONE == ret) {
941 int transaction_ver = 0;
942 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
943 ERR("ctsvc_ipc_unmarshal_int() Fail");
944 pims_ipc_data_destroy(outdata);
945 return CONTACTS_ERROR_IPC;
947 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
949 pims_ipc_data_destroy(outdata);
955 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)
957 int ret = CONTACTS_ERROR_NONE;
958 pims_ipc_data_h indata = NULL;
959 pims_ipc_data_h outdata = NULL;
961 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
962 RETV_IF(NULL == record_list, CONTACTS_ERROR_INVALID_PARAMETER);
965 RETV_IF(NULL == view_uri, CONTACTS_ERROR_INVALID_PARAMETER);
966 RETV_IF(NULL == current_contacts_db_version, CONTACTS_ERROR_INVALID_PARAMETER);
969 indata = pims_ipc_data_create(0);
970 if (indata == NULL) {
971 ERR("pims_ipc_data_create() Fail");
972 return CONTACTS_ERROR_OUT_OF_MEMORY;
975 ret = ctsvc_ipc_marshal_handle(contact, indata);
976 if (CONTACTS_ERROR_NONE != ret) {
977 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
978 pims_ipc_data_destroy(indata);
982 ret = ctsvc_ipc_marshal_string(view_uri, indata);
983 if (ret != CONTACTS_ERROR_NONE) {
984 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
985 pims_ipc_data_destroy(indata);
988 ret = ctsvc_ipc_marshal_int(addressbook_id, indata);
989 if (ret != CONTACTS_ERROR_NONE) {
990 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
991 pims_ipc_data_destroy(indata);
994 ret = ctsvc_ipc_marshal_int(contacts_db_version, indata);
995 if (ret != CONTACTS_ERROR_NONE) {
996 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
997 pims_ipc_data_destroy(indata);
1002 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_CHANGES_BY_VERSION, indata, &outdata) != 0) {
1003 ERR("ctsvc_ipc_call() Fail");
1004 pims_ipc_data_destroy(indata);
1005 return CONTACTS_ERROR_IPC;
1008 pims_ipc_data_destroy(indata);
1011 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1012 ERR("ctsvc_ipc_unmarshal_int() Fail");
1013 pims_ipc_data_destroy(outdata);
1014 return CONTACTS_ERROR_IPC;
1017 if (ret == CONTACTS_ERROR_NONE) {
1018 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, record_list)) {
1019 ERR("ctsvc_ipc_unmarshal_list() Fail");
1020 pims_ipc_data_destroy(outdata);
1021 return CONTACTS_ERROR_IPC;
1023 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, current_contacts_db_version)) {
1024 ERR("ctsvc_ipc_unmarshal_int() Fail");
1025 pims_ipc_data_destroy(outdata);
1026 return CONTACTS_ERROR_IPC;
1029 pims_ipc_data_destroy(outdata);
1035 int ctsvc_client_db_get_current_version(contacts_h contact, int *contacts_db_version)
1037 int ret = CONTACTS_ERROR_NONE;
1038 pims_ipc_data_h indata = NULL;
1039 pims_ipc_data_h outdata = NULL;
1041 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1042 RETV_IF(NULL == contacts_db_version, CONTACTS_ERROR_INVALID_PARAMETER);
1044 *contacts_db_version = 0;
1047 indata = pims_ipc_data_create(0);
1048 if (indata == NULL) {
1049 ERR("pims_ipc_data_create() Fail");
1050 return CONTACTS_ERROR_OUT_OF_MEMORY;
1053 ret = ctsvc_ipc_marshal_handle(contact, indata);
1054 if (CONTACTS_ERROR_NONE != ret) {
1055 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1056 pims_ipc_data_destroy(indata);
1061 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_CURRENT_VERSION, indata, &outdata) != 0) {
1062 ERR("ctsvc_ipc_call() Fail");
1063 pims_ipc_data_destroy(indata);
1064 return CONTACTS_ERROR_IPC;
1067 pims_ipc_data_destroy(indata);
1070 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1071 ERR("ctsvc_ipc_unmarshal_int() Fail");
1072 pims_ipc_data_destroy(outdata);
1073 return CONTACTS_ERROR_IPC;
1076 if (CONTACTS_ERROR_NONE == ret) {
1077 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, contacts_db_version)) {
1078 ERR("ctsvc_ipc_unmarshal_int() Fail");
1079 pims_ipc_data_destroy(outdata);
1080 return CONTACTS_ERROR_IPC;
1083 pims_ipc_data_destroy(outdata);
1089 int ctsvc_client_db_search_records_for_snippet(contacts_h contact,
1090 const char *view_uri,
1091 const char *keyword,
1094 const char *start_match,
1095 const char *end_match,
1097 contacts_list_h *out_list)
1099 int ret = CONTACTS_ERROR_NONE;
1100 pims_ipc_data_h indata = NULL;
1101 pims_ipc_data_h outdata = NULL;
1103 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1104 RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
1108 indata = pims_ipc_data_create(0);
1109 if (indata == NULL) {
1110 ERR("pims_ipc_data_create() Fail");
1111 return CONTACTS_ERROR_OUT_OF_MEMORY;
1114 ret = ctsvc_ipc_marshal_handle(contact, indata);
1115 if (CONTACTS_ERROR_NONE != ret) {
1116 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1117 pims_ipc_data_destroy(indata);
1120 ret = ctsvc_ipc_marshal_string(view_uri, indata);
1121 if (ret != CONTACTS_ERROR_NONE) {
1122 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1123 pims_ipc_data_destroy(indata);
1126 ret = ctsvc_ipc_marshal_string(keyword, indata);
1127 if (ret != CONTACTS_ERROR_NONE) {
1128 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1129 pims_ipc_data_destroy(indata);
1132 ret = ctsvc_ipc_marshal_int(offset, indata);
1133 if (ret != CONTACTS_ERROR_NONE) {
1134 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1135 pims_ipc_data_destroy(indata);
1138 ret = ctsvc_ipc_marshal_int(limit, indata);
1139 if (ret != CONTACTS_ERROR_NONE) {
1140 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1141 pims_ipc_data_destroy(indata);
1144 ret = ctsvc_ipc_marshal_string(start_match ? start_match : CTSVC_DEFAULT_START_MATCH, indata);
1145 if (ret != CONTACTS_ERROR_NONE) {
1146 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1147 pims_ipc_data_destroy(indata);
1150 ret = ctsvc_ipc_marshal_string(end_match ? end_match : CTSVC_DEFAULT_END_MATCH, indata);
1151 if (ret != CONTACTS_ERROR_NONE) {
1152 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1153 pims_ipc_data_destroy(indata);
1156 ret = ctsvc_ipc_marshal_int(token_number, indata);
1157 if (ret != CONTACTS_ERROR_NONE) {
1158 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1159 pims_ipc_data_destroy(indata);
1164 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE,
1165 CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_FOR_SNIPPET,
1166 indata, &outdata) != 0) {
1167 ERR("ctsvc_ipc_call() Fail");
1168 pims_ipc_data_destroy(indata);
1169 return CONTACTS_ERROR_IPC;
1172 pims_ipc_data_destroy(indata);
1175 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1176 ERR("ctsvc_ipc_unmarshal_int() Fail");
1177 pims_ipc_data_destroy(outdata);
1178 return CONTACTS_ERROR_IPC;
1181 if (CONTACTS_ERROR_NONE == ret) {
1182 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
1183 ERR("ctsvc_ipc_unmarshal_list() Fail");
1184 pims_ipc_data_destroy(outdata);
1185 return CONTACTS_ERROR_IPC;
1189 pims_ipc_data_destroy(outdata);
1195 int ctsvc_client_db_search_records_with_range_for_snippet(contacts_h contact,
1196 const char *view_uri,
1197 const char *keyword,
1201 const char *start_match,
1202 const char *end_match,
1204 contacts_list_h *out_list)
1206 int ret = CONTACTS_ERROR_NONE;
1207 pims_ipc_data_h indata = NULL;
1208 pims_ipc_data_h outdata = NULL;
1210 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1211 RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
1212 RETV_IF(0 == range, CONTACTS_ERROR_INVALID_PARAMETER);
1215 indata = pims_ipc_data_create(0);
1216 if (indata == NULL) {
1217 ERR("pims_ipc_data_create() Fail");
1218 return CONTACTS_ERROR_OUT_OF_MEMORY;
1220 ret = ctsvc_ipc_marshal_handle(contact, indata);
1221 if (CONTACTS_ERROR_NONE != ret) {
1222 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1223 pims_ipc_data_destroy(indata);
1227 ret = ctsvc_ipc_marshal_string(view_uri, indata);
1228 if (ret != CONTACTS_ERROR_NONE) {
1229 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1230 pims_ipc_data_destroy(indata);
1233 ret = ctsvc_ipc_marshal_string(keyword, indata);
1234 if (ret != CONTACTS_ERROR_NONE) {
1235 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1236 pims_ipc_data_destroy(indata);
1239 ret = ctsvc_ipc_marshal_int(offset, indata);
1240 if (ret != CONTACTS_ERROR_NONE) {
1241 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1242 pims_ipc_data_destroy(indata);
1245 ret = ctsvc_ipc_marshal_int(limit, indata);
1246 if (ret != CONTACTS_ERROR_NONE) {
1247 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1248 pims_ipc_data_destroy(indata);
1251 ret = ctsvc_ipc_marshal_int(range, indata);
1252 if (ret != CONTACTS_ERROR_NONE) {
1253 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1254 pims_ipc_data_destroy(indata);
1257 ret = ctsvc_ipc_marshal_string(start_match ? start_match : CTSVC_DEFAULT_START_MATCH, indata);
1258 if (ret != CONTACTS_ERROR_NONE) {
1259 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1260 pims_ipc_data_destroy(indata);
1263 ret = ctsvc_ipc_marshal_string(end_match ? end_match : CTSVC_DEFAULT_END_MATCH, indata);
1264 if (ret != CONTACTS_ERROR_NONE) {
1265 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1266 pims_ipc_data_destroy(indata);
1269 ret = ctsvc_ipc_marshal_int(token_number, indata);
1270 if (ret != CONTACTS_ERROR_NONE) {
1271 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1272 pims_ipc_data_destroy(indata);
1276 if (0 != ctsvc_ipc_call(CTSVC_IPC_DB_MODULE,
1277 CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_RANGE_FOR_SNIPPET,
1278 indata, &outdata)) {
1279 ERR("ctsvc_ipc_call() Fail");
1280 pims_ipc_data_destroy(indata);
1281 return CONTACTS_ERROR_IPC;
1284 pims_ipc_data_destroy(indata);
1287 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1288 ERR("ctsvc_ipc_unmarshal_int() Fail");
1289 pims_ipc_data_destroy(outdata);
1290 return CONTACTS_ERROR_IPC;
1292 if (CONTACTS_ERROR_NONE == ret) {
1293 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
1294 ERR("ctsvc_ipc_unmarshal_list() Fail");
1295 pims_ipc_data_destroy(outdata);
1296 return CONTACTS_ERROR_IPC;
1299 pims_ipc_data_destroy(outdata);
1305 int ctsvc_client_db_search_records_with_query_for_snippet(contacts_h contact,
1306 contacts_query_h query,
1307 const char *keyword,
1310 const char *start_match,
1311 const char *end_match,
1313 contacts_list_h *out_list)
1315 int ret = CONTACTS_ERROR_NONE;
1316 pims_ipc_data_h indata = NULL;
1317 pims_ipc_data_h outdata = NULL;
1319 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1320 RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
1321 RETV_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER);
1325 indata = pims_ipc_data_create(0);
1326 if (indata == NULL) {
1327 ERR("pims_ipc_data_create() Fail");
1328 return CONTACTS_ERROR_OUT_OF_MEMORY;
1331 ret = ctsvc_ipc_marshal_handle(contact, indata);
1332 if (CONTACTS_ERROR_NONE != ret) {
1333 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1334 pims_ipc_data_destroy(indata);
1337 ret = ctsvc_ipc_marshal_query(query, indata);
1338 if (ret != CONTACTS_ERROR_NONE) {
1339 ERR("ctsvc_ipc_marshal_query() Fail(%d)", ret);
1340 pims_ipc_data_destroy(indata);
1343 ret = ctsvc_ipc_marshal_string(keyword, indata);
1344 if (ret != CONTACTS_ERROR_NONE) {
1345 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1346 pims_ipc_data_destroy(indata);
1349 ret = ctsvc_ipc_marshal_int(offset, indata);
1350 if (ret != CONTACTS_ERROR_NONE) {
1351 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1354 ret = ctsvc_ipc_marshal_int(limit, indata);
1355 if (ret != CONTACTS_ERROR_NONE) {
1356 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1357 pims_ipc_data_destroy(indata);
1360 ret = ctsvc_ipc_marshal_string(start_match ? start_match : CTSVC_DEFAULT_START_MATCH, indata);
1361 if (ret != CONTACTS_ERROR_NONE) {
1362 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1363 pims_ipc_data_destroy(indata);
1366 ret = ctsvc_ipc_marshal_string(end_match ? end_match : CTSVC_DEFAULT_END_MATCH, indata);
1367 if (ret != CONTACTS_ERROR_NONE) {
1368 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1369 pims_ipc_data_destroy(indata);
1372 ret = ctsvc_ipc_marshal_int(token_number, indata);
1373 if (ret != CONTACTS_ERROR_NONE) {
1374 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1375 pims_ipc_data_destroy(indata);
1380 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE,
1381 CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_QUERY_FOR_SNIPPET,
1382 indata, &outdata) != 0) {
1383 ERR("ctsvc_ipc_call() Fail");
1384 pims_ipc_data_destroy(indata);
1385 return CONTACTS_ERROR_IPC;
1388 pims_ipc_data_destroy(indata);
1391 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1392 ERR("ctsvc_ipc_unmarshal_int() Fail");
1393 pims_ipc_data_destroy(outdata);
1394 return CONTACTS_ERROR_IPC;
1397 if (CONTACTS_ERROR_NONE == ret) {
1398 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
1399 ERR("ctsvc_ipc_unmarshal_list() Fail");
1400 pims_ipc_data_destroy(outdata);
1401 return CONTACTS_ERROR_IPC;
1405 pims_ipc_data_destroy(outdata);
1411 int ctsvc_client_db_search_records(contacts_h contact, const char *view_uri, const char *keyword,
1412 int offset, int limit, contacts_list_h *out_list)
1414 int ret = CONTACTS_ERROR_NONE;
1415 pims_ipc_data_h indata = NULL;
1416 pims_ipc_data_h outdata = NULL;
1418 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1419 RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
1423 indata = pims_ipc_data_create(0);
1424 if (indata == NULL) {
1425 ERR("pims_ipc_data_create() Fail");
1426 return CONTACTS_ERROR_OUT_OF_MEMORY;
1429 ret = ctsvc_ipc_marshal_handle(contact, indata);
1430 if (CONTACTS_ERROR_NONE != ret) {
1431 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1432 pims_ipc_data_destroy(indata);
1435 ret = ctsvc_ipc_marshal_string(view_uri, indata);
1436 if (ret != CONTACTS_ERROR_NONE) {
1437 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1438 pims_ipc_data_destroy(indata);
1441 ret = ctsvc_ipc_marshal_string(keyword, indata);
1442 if (ret != CONTACTS_ERROR_NONE) {
1443 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1444 pims_ipc_data_destroy(indata);
1447 ret = ctsvc_ipc_marshal_int(offset, indata);
1448 if (ret != CONTACTS_ERROR_NONE) {
1449 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1450 pims_ipc_data_destroy(indata);
1453 ret = ctsvc_ipc_marshal_int(limit, indata);
1454 if (ret != CONTACTS_ERROR_NONE) {
1455 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1456 pims_ipc_data_destroy(indata);
1461 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS, indata, &outdata) != 0) {
1462 ERR("ctsvc_ipc_call() Fail");
1463 pims_ipc_data_destroy(indata);
1464 return CONTACTS_ERROR_IPC;
1467 pims_ipc_data_destroy(indata);
1470 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1471 ERR("ctsvc_ipc_unmarshal_int() Fail");
1472 pims_ipc_data_destroy(outdata);
1473 return CONTACTS_ERROR_IPC;
1476 if (CONTACTS_ERROR_NONE == ret) {
1477 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
1478 ERR("ctsvc_ipc_unmarshal_list() Fail");
1479 pims_ipc_data_destroy(outdata);
1480 return CONTACTS_ERROR_IPC;
1484 pims_ipc_data_destroy(outdata);
1490 int ctsvc_client_db_search_records_with_range(contacts_h contact, const char *view_uri, const char *keyword,
1491 int offset, int limit, int range, contacts_list_h *out_list)
1493 int ret = CONTACTS_ERROR_NONE;
1494 pims_ipc_data_h indata = NULL;
1495 pims_ipc_data_h outdata = NULL;
1497 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1498 RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
1499 RETV_IF(0 == range, CONTACTS_ERROR_INVALID_PARAMETER);
1502 indata = pims_ipc_data_create(0);
1503 if (indata == NULL) {
1504 ERR("pims_ipc_data_create() Fail");
1505 return CONTACTS_ERROR_OUT_OF_MEMORY;
1507 ret = ctsvc_ipc_marshal_handle(contact, indata);
1508 if (CONTACTS_ERROR_NONE != ret) {
1509 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1510 pims_ipc_data_destroy(indata);
1514 ret = ctsvc_ipc_marshal_string(view_uri, indata);
1515 if (ret != CONTACTS_ERROR_NONE) {
1516 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1517 pims_ipc_data_destroy(indata);
1520 ret = ctsvc_ipc_marshal_string(keyword, indata);
1521 if (ret != CONTACTS_ERROR_NONE) {
1522 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1523 pims_ipc_data_destroy(indata);
1526 ret = ctsvc_ipc_marshal_int(offset, indata);
1527 if (ret != CONTACTS_ERROR_NONE) {
1528 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1529 pims_ipc_data_destroy(indata);
1532 ret = ctsvc_ipc_marshal_int(limit, indata);
1533 if (ret != CONTACTS_ERROR_NONE) {
1534 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1535 pims_ipc_data_destroy(indata);
1538 ret = ctsvc_ipc_marshal_int(range, indata);
1539 if (ret != CONTACTS_ERROR_NONE) {
1540 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1541 pims_ipc_data_destroy(indata);
1545 if (0 != ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_RANGE, indata, &outdata)) {
1546 ERR("ctsvc_ipc_call() Fail");
1547 pims_ipc_data_destroy(indata);
1548 return CONTACTS_ERROR_IPC;
1551 pims_ipc_data_destroy(indata);
1554 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1555 ERR("ctsvc_ipc_unmarshal_int() Fail");
1556 pims_ipc_data_destroy(outdata);
1557 return CONTACTS_ERROR_IPC;
1559 if (CONTACTS_ERROR_NONE == ret) {
1560 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
1561 ERR("ctsvc_ipc_unmarshal_list() Fail");
1562 pims_ipc_data_destroy(outdata);
1563 return CONTACTS_ERROR_IPC;
1566 pims_ipc_data_destroy(outdata);
1572 int ctsvc_client_db_search_records_with_query(contacts_h contact, contacts_query_h query, const char *keyword,
1573 int offset, int limit, contacts_list_h *out_list)
1575 int ret = CONTACTS_ERROR_NONE;
1576 pims_ipc_data_h indata = NULL;
1577 pims_ipc_data_h outdata = NULL;
1579 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1580 RETV_IF(NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
1581 RETV_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER);
1585 indata = pims_ipc_data_create(0);
1586 if (indata == NULL) {
1587 ERR("pims_ipc_data_create() Fail");
1588 return CONTACTS_ERROR_OUT_OF_MEMORY;
1591 ret = ctsvc_ipc_marshal_handle(contact, indata);
1592 if (CONTACTS_ERROR_NONE != ret) {
1593 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1594 pims_ipc_data_destroy(indata);
1597 ret = ctsvc_ipc_marshal_query(query, indata);
1598 if (ret != CONTACTS_ERROR_NONE) {
1599 ERR("ctsvc_ipc_marshal_query() Fail(%d)", ret);
1600 pims_ipc_data_destroy(indata);
1603 ret = ctsvc_ipc_marshal_string(keyword, indata);
1604 if (ret != CONTACTS_ERROR_NONE) {
1605 ERR("ctsvc_ipc_marshal_string() Fail(%d)", ret);
1606 pims_ipc_data_destroy(indata);
1609 ret = ctsvc_ipc_marshal_int(offset, indata);
1610 if (ret != CONTACTS_ERROR_NONE) {
1611 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1614 ret = ctsvc_ipc_marshal_int(limit, indata);
1615 if (ret != CONTACTS_ERROR_NONE) {
1616 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
1617 pims_ipc_data_destroy(indata);
1622 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_SEARCH_RECORDS_WITH_QUERY, indata, &outdata) != 0) {
1623 ERR("ctsvc_ipc_call() Fail");
1624 pims_ipc_data_destroy(indata);
1625 return CONTACTS_ERROR_IPC;
1628 pims_ipc_data_destroy(indata);
1631 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1632 ERR("ctsvc_ipc_unmarshal_int() Fail");
1633 pims_ipc_data_destroy(outdata);
1634 return CONTACTS_ERROR_IPC;
1637 if (CONTACTS_ERROR_NONE == ret) {
1638 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_list(outdata, out_list)) {
1639 ERR("ctsvc_ipc_unmarshal_list() Fail");
1640 pims_ipc_data_destroy(outdata);
1641 return CONTACTS_ERROR_IPC;
1645 pims_ipc_data_destroy(outdata);
1651 int ctsvc_client_db_get_last_change_version(contacts_h contact, int *last_version)
1653 int ret = CONTACTS_ERROR_NONE;
1654 bool result = false;
1656 RETV_IF(NULL == last_version, CONTACTS_ERROR_INVALID_PARAMETER);
1659 ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_CONTACT_READ, &result);
1660 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission Fail(%d)", ret);
1661 if (result == false) {
1662 ret = ctsvc_ipc_client_check_permission(CTSVC_PERMISSION_PHONELOG_READ, &result);
1663 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission Fail(%d)", ret);
1664 RETVM_IF(result == false, CONTACTS_ERROR_PERMISSION_DENIED, "Permission denied");
1667 *last_version = ctsvc_client_ipc_get_change_version(contact);
1672 contacts_db_status_changed_cb cb;
1674 } status_callback_info_s;
1676 static GSList *__status_change_subscribe_list = NULL;
1678 static void __ctsvc_client_db_free_cb_info(status_callback_info_s *cb_info)
1680 if (NULL == cb_info)
1685 static void __ctsvc_db_status_subscriber_callback(pims_ipc_h ipc, pims_ipc_data_h data,
1693 ret = ctsvc_ipc_unmarshal_int(data, &status);
1694 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
1697 for (l = __status_change_subscribe_list; l; l = l->next) {
1698 status_callback_info_s *cb_info = l->data;
1699 /* TODO: Fixme - check zone_name */
1701 cb_info->cb(status, cb_info->user_data);
1705 int ctsvc_client_db_get_status(contacts_h contact, contacts_db_status_e *status)
1707 int ret = CONTACTS_ERROR_NONE;
1708 pims_ipc_data_h outdata = NULL;
1709 pims_ipc_data_h indata = NULL;
1711 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1712 RETV_IF(NULL == status, CONTACTS_ERROR_INVALID_PARAMETER);
1716 indata = pims_ipc_data_create(0);
1717 if (indata == NULL) {
1718 ERR("pims_ipc_data_create() Fail");
1719 return CONTACTS_ERROR_OUT_OF_MEMORY;
1722 ret = ctsvc_ipc_marshal_handle(contact, indata);
1723 if (CONTACTS_ERROR_NONE != ret) {
1724 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
1725 pims_ipc_data_destroy(indata);
1729 if (ctsvc_ipc_call(CTSVC_IPC_DB_MODULE, CTSVC_IPC_SERVER_DB_GET_STATUS, indata, &outdata) != 0) {
1730 pims_ipc_data_destroy(indata);
1731 ERR("ctsvc_ipc_call() Fail");
1732 return CONTACTS_ERROR_IPC;
1734 pims_ipc_data_destroy(indata);
1737 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
1738 ERR("ctsvc_ipc_unmarshal_int() Fail");
1739 pims_ipc_data_destroy(outdata);
1740 return CONTACTS_ERROR_IPC;
1742 if (CONTACTS_ERROR_NONE == ret) {
1743 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, (int*)status)) {
1744 ERR("ctsvc_ipc_unmarshal_int() Fail");
1745 pims_ipc_data_destroy(outdata);
1746 return CONTACTS_ERROR_IPC;
1749 pims_ipc_data_destroy(outdata);
1755 int ctsvc_client_db_add_status_changed_cb(contacts_h contact,
1756 contacts_db_status_changed_cb cb, void *user_data)
1759 status_callback_info_s *cb_info = NULL;
1761 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1762 RETV_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER);
1764 ret = ctsvc_ipc_create_for_change_subscription();
1765 if (CONTACTS_ERROR_NONE != ret) {
1766 ERR("ctsvc_ipc_create_for_change_subscription() Fail(%d)", ret);
1770 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1772 if (pims_ipc_subscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
1773 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_IPC_SERVER_DB_STATUS_CHANGED,
1774 __ctsvc_db_status_subscriber_callback, NULL) != 0) {
1775 ERR("pims_ipc_subscribe error\n");
1776 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1777 return CONTACTS_ERROR_IPC;
1780 cb_info = calloc(1, sizeof(status_callback_info_s));
1781 if (NULL == cb_info) {
1782 ERR("calloc() Fail");
1783 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1784 return CONTACTS_ERROR_OUT_OF_MEMORY;
1786 cb_info->user_data = user_data;
1788 __status_change_subscribe_list = g_slist_append(__status_change_subscribe_list, cb_info);
1790 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1791 return CONTACTS_ERROR_NONE;
1794 int ctsvc_client_db_remove_status_changed_cb(contacts_h contact,
1795 contacts_db_status_changed_cb cb, void *user_data)
1800 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
1801 RETV_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER);
1803 ret = ctsvc_ipc_destroy_for_change_subscription(false);
1804 if (CONTACTS_ERROR_NONE != ret) {
1805 ERR("ctsvc_ipc_destroy_for_change_subscription() Fail(%d)", ret);
1809 ctsvc_mutex_lock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1810 for (l = __status_change_subscribe_list; l; l = l->next) {
1811 status_callback_info_s *cb_info = l->data;
1812 if (cb == cb_info->cb && user_data == cb_info->user_data) {
1813 __status_change_subscribe_list = g_slist_remove(__status_change_subscribe_list, cb_info);
1814 __ctsvc_client_db_free_cb_info(cb_info);
1819 if (g_slist_length(__status_change_subscribe_list) == 0) {
1820 pims_ipc_unsubscribe(ctsvc_ipc_get_handle_for_change_subsciption(),
1821 CTSVC_IPC_SUBSCRIBE_MODULE, CTSVC_IPC_SERVER_DB_STATUS_CHANGED);
1822 g_slist_free(__status_change_subscribe_list);
1823 __status_change_subscribe_list = NULL;
1826 ctsvc_mutex_unlock(CTS_MUTEX_PIMS_IPC_PUBSUB);
1827 return CONTACTS_ERROR_NONE;