dec01c204a4869f9c8bd4b94b8528df447f5f8f6
[platform/core/pim/contacts-service.git] / server / ctsvc_ipc_server.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <stdlib.h>
21 #include <pims-ipc-svc.h>
22 #include "contacts.h"
23
24 #include "ctsvc_handle.h"
25 #include "ctsvc_server_service.h"
26 #include "ctsvc_db_init.h"
27 #include "ctsvc_db_query.h"
28 #include "ctsvc_db_access_control.h"
29
30 #include "ctsvc_ipc_marshal.h"
31 #include "ctsvc_internal.h"
32 #include "ctsvc_ipc_server.h"
33 #include "ctsvc_db_utils.h"
34 #include "ctsvc_server_utils.h"
35
36 void ctsvc_ipc_server_connect(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
37 {
38         CTS_FN_CALL;
39         int ret = CONTACTS_ERROR_NONE;
40         contacts_h contact = NULL;
41
42         if (indata) {
43                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
44                 if (ret != CONTACTS_ERROR_NONE) {
45                         /* LCOV_EXCL_START */
46                         ERR("ctsvc_ipc_unmarshal_handle() Fail");
47                         goto ERROR_RETURN;
48                         /* LCOV_EXCL_STOP */
49                 }
50         } else {
51                 /* LCOV_EXCL_START */
52                 ERR("There is no indata Fail");
53                 ret = CONTACTS_ERROR_SYSTEM;
54                 goto ERROR_RETURN;
55                 /* LCOV_EXCL_STOP */
56         }
57
58         ret = ctsvc_connect();
59
60         if (CONTACTS_ERROR_NONE == ret) {
61                 char *smack = NULL;
62                 if (0 != pims_ipc_svc_get_smack_label(ipc, &smack))
63                         ERR("pims_ipc_svc_get_smack_label() Fail()");
64                 ctsvc_set_client_access_info(ipc, smack);
65                 free(smack);
66         }
67
68 ERROR_RETURN:
69         if (outdata) {
70                 *outdata = pims_ipc_data_create(0);
71                 if (NULL == *outdata) {
72                         /* LCOV_EXCL_START */
73                         ERR("pims_ipc_data_create() Fail");
74                         goto DATA_FREE;
75                         /* LCOV_EXCL_STOP */
76                 }
77
78                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
79                         /* LCOV_EXCL_START */
80                         pims_ipc_data_destroy(*outdata);
81                         *outdata = NULL;
82                         ERR("ctsvc_ipc_unmarshal_int() Fail");
83                         goto DATA_FREE;
84                         /* LCOV_EXCL_STOP */
85                 }
86         } else {
87                 ERR("outdata is NULL");
88         }
89 DATA_FREE:
90         ctsvc_handle_destroy(contact);
91 }
92
93 void ctsvc_ipc_server_disconnect(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
94 {
95         int ret = CONTACTS_ERROR_NONE;
96         contacts_h contact = NULL;
97
98         if (indata) {
99                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
100                 if (CONTACTS_ERROR_NONE != ret) {
101                         /* LCOV_EXCL_START */
102                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
103                         ret = CONTACTS_ERROR_IPC;
104                         goto ERROR_RETURN;
105                         /* LCOV_EXCL_STOP */
106                 }
107         }
108
109         ret = ctsvc_disconnect();
110
111 ERROR_RETURN:
112         if (outdata) {
113                 *outdata = pims_ipc_data_create(0);
114                 if (NULL == *outdata) {
115                         /* LCOV_EXCL_START */
116                         ERR("pims_ipc_data_create() Fail");
117                         goto DATA_FREE;
118                         /* LCOV_EXCL_STOP */
119                 }
120                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
121                         /* LCOV_EXCL_START */
122                         pims_ipc_data_destroy(*outdata);
123                         *outdata = NULL;
124                         ERR("ctsvc_ipc_marshal_int() Fail");
125                         goto DATA_FREE;
126                         /* LCOV_EXCL_STOP */
127                 }
128         } else {
129                 /* LCOV_EXCL_START */
130                 ERR("outdata is NULL");
131                 /* LCOV_EXCL_STOP */
132         }
133 DATA_FREE:
134         ctsvc_handle_destroy(contact);
135         ctsvc_server_trim_memory();
136         ctsvc_server_start_timeout();
137 }
138
139 void ctsvc_ipc_server_check_permission(pims_ipc_h ipc, pims_ipc_data_h indata,
140                 pims_ipc_data_h *outdata, void *userdata)
141 {
142         int ret = CONTACTS_ERROR_NONE;
143         int permission;
144         bool result = false;
145
146         if (NULL == indata) {
147                 /* LCOV_EXCL_START */
148                 ret = CONTACTS_ERROR_INVALID_PARAMETER;
149                 ERR("check permission Fail");
150                 goto ERROR_RETURN;
151                 /* LCOV_EXCL_STOP */
152         }
153
154         ret = ctsvc_ipc_unmarshal_int(indata, &permission);
155         if (ret != CONTACTS_ERROR_NONE) {
156                 /* LCOV_EXCL_START */
157                 ERR("ctsvc_ipc_unmarshal_int() Fail");
158                 goto ERROR_RETURN;
159                 /* LCOV_EXCL_STOP */
160         }
161
162         result = ctsvc_have_permission(ipc, permission);
163
164 ERROR_RETURN:
165         *outdata = pims_ipc_data_create(0);
166         if (NULL == *outdata) {
167                 /* LCOV_EXCL_START */
168                 ERR("pims_ipc_data_create() Fail");
169                 ctsvc_server_start_timeout();
170                 return;
171                 /* LCOV_EXCL_STOP */
172         }
173
174         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
175                 /* LCOV_EXCL_START */
176                 pims_ipc_data_destroy(*outdata);
177                 *outdata = NULL;
178                 ERR("ctsvc_ipc_marshal_int() Fail");
179                 ctsvc_server_start_timeout();
180                 return;
181                 /* LCOV_EXCL_STOP */
182         }
183
184         if (ret == CONTACTS_ERROR_NONE) {
185                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_bool(result, *outdata)) {
186                         /* LCOV_EXCL_START */
187                         pims_ipc_data_destroy(*outdata);
188                         *outdata = NULL;
189                         ERR("ctsvc_ipc_marshal_bool() Fail");
190                         ctsvc_server_start_timeout();
191                         return;
192                         /* LCOV_EXCL_STOP */
193                 }
194         }
195         ctsvc_server_start_timeout();
196 }
197
198 void ctsvc_ipc_server_db_insert_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
199 {
200         int ret = CONTACTS_ERROR_NONE;
201         contacts_record_h record = NULL;
202         int id = 0;
203         contacts_h contact = NULL;
204
205         if (indata) {
206                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
207                 if (CONTACTS_ERROR_NONE != ret) {
208                         /* LCOV_EXCL_START */
209                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
210                         ret = CONTACTS_ERROR_IPC;
211                         goto ERROR_RETURN;
212                         /* LCOV_EXCL_STOP */
213                 }
214
215                 ret = ctsvc_ipc_unmarshal_record(indata, &record);
216                 if (ret != CONTACTS_ERROR_NONE) {
217                         /* LCOV_EXCL_START */
218                         ERR("ctsvc_ipc_unmarshal_record() Fail");
219                         record = NULL;
220                         goto ERROR_RETURN;
221                         /* LCOV_EXCL_STOP */
222                 }
223         } else {
224                 /* LCOV_EXCL_START */
225                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
226                 goto ERROR_RETURN;
227                 /* LCOV_EXCL_STOP */
228         }
229
230         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(((ctsvc_record_s*)record)->view_uri))) {
231                 /* LCOV_EXCL_START */
232                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
233                 goto ERROR_RETURN;
234                 /* LCOV_EXCL_STOP */
235         }
236
237         ret = ctsvc_db_insert_record(record, &id);
238
239         if (outdata) {
240                 *outdata = pims_ipc_data_create(0);
241                 if (NULL == *outdata) {
242                         /* LCOV_EXCL_START */
243                         ERR("pims_ipc_data_create() Fail");
244                         goto DATA_FREE;
245                         /* LCOV_EXCL_STOP */
246                 }
247                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
248                         /* LCOV_EXCL_START */
249                         pims_ipc_data_destroy(*outdata);
250                         *outdata = NULL;
251                         ERR("ctsvc_ipc_marshal_int() Fail");
252                         goto DATA_FREE;
253                         /* LCOV_EXCL_STOP */
254                 }
255                 if (ret == CONTACTS_ERROR_NONE) {
256                         int transaction_ver = ctsvc_get_transaction_ver();
257                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
258                                 /* LCOV_EXCL_START */
259                                 pims_ipc_data_destroy(*outdata);
260                                 *outdata = NULL;
261                                 ERR("ctsvc_ipc_marshal_int() Fail");
262                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
263                                 goto ERROR_RETURN;
264                                 /* LCOV_EXCL_STOP */
265                         }
266                         if (ctsvc_ipc_marshal_int(id, *outdata) != CONTACTS_ERROR_NONE) {
267                                 /* LCOV_EXCL_START */
268                                 pims_ipc_data_destroy(*outdata);
269                                 ERR("ctsvc_ipc_marshal_int() Fail");
270                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
271                                 goto ERROR_RETURN;
272                                 /* LCOV_EXCL_STOP */
273                         }
274                 }
275         } else {
276                 /* LCOV_EXCL_START */
277                 ERR("outdata is NULL");
278                 /* LCOV_EXCL_STOP */
279         }
280         goto DATA_FREE;
281
282 ERROR_RETURN:
283         if (outdata) {
284                 *outdata = pims_ipc_data_create(0);
285                 if (NULL == *outdata) {
286                         /* LCOV_EXCL_START */
287                         ERR("pims_ipc_data_create() Fail");
288                         goto DATA_FREE;
289                         /* LCOV_EXCL_STOP */
290                 }
291                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
292                         /* LCOV_EXCL_START */
293                         pims_ipc_data_destroy(*outdata);
294                         *outdata = NULL;
295                         ERR("ctsvc_ipc_marshal_int() Fail");
296                         goto DATA_FREE;
297                         /* LCOV_EXCL_STOP */
298                 }
299         } else {
300                 /* LCOV_EXCL_START */
301                 ERR("outdata is NULL");
302                 /* LCOV_EXCL_STOP */
303         }
304
305 DATA_FREE:
306         ctsvc_handle_destroy(contact);
307         contacts_record_destroy(record, true);
308         ctsvc_server_trim_memory();
309         ctsvc_server_start_timeout();
310         return;
311 }
312
313 void ctsvc_ipc_server_db_get_record(pims_ipc_h ipc, pims_ipc_data_h indata,
314                 pims_ipc_data_h *outdata, void *userdata)
315 {
316         int ret = CONTACTS_ERROR_NONE;
317         char *view_uri = NULL;
318         int id = 0;
319         contacts_record_h record = NULL;
320         contacts_h contact = NULL;
321
322         if (indata) {
323                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
324                 if (CONTACTS_ERROR_NONE != ret) {
325                         /* LCOV_EXCL_START */
326                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
327                         ret = CONTACTS_ERROR_IPC;
328                         goto ERROR_RETURN;
329                         /* LCOV_EXCL_STOP */
330                 }
331                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
332                 if (ret != CONTACTS_ERROR_NONE) {
333                         /* LCOV_EXCL_START */
334                         ERR("ctsvc_ipc_unmarshal_string Fail");
335                         goto ERROR_RETURN;
336                         /* LCOV_EXCL_STOP */
337                 }
338                 ret = ctsvc_ipc_unmarshal_int(indata, &id);
339                 if (ret != CONTACTS_ERROR_NONE) {
340                         /* LCOV_EXCL_START */
341                         ERR("ctsvc_ipc_unmarshal_int() Fail");
342                         goto ERROR_RETURN;
343                         /* LCOV_EXCL_STOP */
344                 }
345         } else {
346                 /* LCOV_EXCL_START */
347                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
348                 goto ERROR_RETURN;
349                 /* LCOV_EXCL_STOP */
350         }
351
352         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
353                 /* LCOV_EXCL_START */
354                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
355                 goto ERROR_RETURN;
356                 /* LCOV_EXCL_STOP */
357         }
358
359         ret = ctsvc_db_get_record(view_uri, id, &record);
360
361 ERROR_RETURN:
362         if (outdata) {
363                 *outdata = pims_ipc_data_create(0);
364                 if (NULL == *outdata) {
365                         /* LCOV_EXCL_START */
366                         ERR("pims_ipc_data_create() Fail");
367                         goto DATA_FREE;
368                         /* LCOV_EXCL_STOP */
369                 }
370                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
371                         /* LCOV_EXCL_START */
372                         pims_ipc_data_destroy(*outdata);
373                         *outdata = NULL;
374                         ERR("ctsvc_ipc_marshal_int() Fail");
375                         goto DATA_FREE;
376                         /* LCOV_EXCL_STOP */
377                 }
378
379                 if (CONTACTS_ERROR_NO_DATA == ret) {
380                         DBG("no data");
381                 } else if (CONTACTS_ERROR_NONE == ret) {
382                         if (ctsvc_ipc_marshal_record(record, *outdata) != CONTACTS_ERROR_NONE) {
383                                 /* LCOV_EXCL_START */
384                                 pims_ipc_data_destroy(*outdata);
385                                 *outdata = NULL;
386                                 ERR("ctsvc_ipc_marshal_record() Fail");
387                                 goto DATA_FREE;
388                                 /* LCOV_EXCL_STOP */
389                         }
390                 }
391         } else {
392                 /* LCOV_EXCL_START */
393                 ERR("outdata is NULL");
394                 /* LCOV_EXCL_STOP */
395         }
396 DATA_FREE:
397         ctsvc_handle_destroy(contact);
398         contacts_record_destroy(record, true);
399         free(view_uri);
400         ctsvc_server_start_timeout();
401         return;
402 }
403
404 void ctsvc_ipc_server_db_update_record(pims_ipc_h ipc, pims_ipc_data_h indata,
405                 pims_ipc_data_h *outdata, void *userdata)
406 {
407         int ret = CONTACTS_ERROR_NONE;
408         contacts_record_h record = NULL;
409         contacts_h contact = NULL;
410
411         if (indata) {
412                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
413                 if (CONTACTS_ERROR_NONE != ret) {
414                         /* LCOV_EXCL_START */
415                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
416                         ret = CONTACTS_ERROR_IPC;
417                         goto ERROR_RETURN;
418                         /* LCOV_EXCL_STOP */
419                 }
420                 ret = ctsvc_ipc_unmarshal_record(indata, &record);
421                 if (ret != CONTACTS_ERROR_NONE) {
422                         /* LCOV_EXCL_START */
423                         ERR("ctsvc_ipc_unmarshal_record() Fail");
424                         goto ERROR_RETURN;
425                         /* LCOV_EXCL_STOP */
426                 }
427         } else {
428                 /* LCOV_EXCL_START */
429                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
430                 goto ERROR_RETURN;
431                 /* LCOV_EXCL_STOP */
432         }
433
434         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(((ctsvc_record_s*)record)->view_uri))) {
435                 /* LCOV_EXCL_START */
436                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
437                 goto ERROR_RETURN;
438                 /* LCOV_EXCL_STOP */
439         }
440
441         ret = ctsvc_db_update_record(record);
442
443         if (outdata) {
444                 *outdata = pims_ipc_data_create(0);
445                 if (NULL == *outdata) {
446                         /* LCOV_EXCL_START */
447                         ERR("pims_ipc_data_create() Fail");
448                         goto DATA_FREE;
449                         /* LCOV_EXCL_STOP */
450                 }
451                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
452                         /* LCOV_EXCL_START */
453                         pims_ipc_data_destroy(*outdata);
454                         *outdata = NULL;
455                         ERR("ctsvc_ipc_marshal_int() Fail");
456                         goto DATA_FREE;
457                         /* LCOV_EXCL_STOP */
458                 }
459
460                 if (ret == CONTACTS_ERROR_NONE) {
461                         int transaction_ver = ctsvc_get_transaction_ver();
462                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
463                                 /* LCOV_EXCL_START */
464                                 pims_ipc_data_destroy(*outdata);
465                                 *outdata = NULL;
466                                 ERR("ctsvc_ipc_marshal_int() Fail");
467                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
468                                 goto ERROR_RETURN;
469                                 /* LCOV_EXCL_STOP */
470                         }
471                 }
472         }
473
474         goto DATA_FREE;
475
476 ERROR_RETURN:
477         if (outdata) {
478                 *outdata = pims_ipc_data_create(0);
479                 if (NULL == *outdata) {
480                         /* LCOV_EXCL_START */
481                         ERR("pims_ipc_data_create() Fail");
482                         goto DATA_FREE;
483                         /* LCOV_EXCL_STOP */
484                 }
485                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
486                         /* LCOV_EXCL_START */
487                         pims_ipc_data_destroy(*outdata);
488                         *outdata = NULL;
489                         ERR("ctsvc_ipc_marshal_int() Fail");
490                         goto DATA_FREE;
491                         /* LCOV_EXCL_STOP */
492                 }
493         } else {
494                 /* LCOV_EXCL_START */
495                 ERR("outdata is NULL");
496                 /* LCOV_EXCL_STOP */
497         }
498 DATA_FREE:
499         ctsvc_handle_destroy(contact);
500         contacts_record_destroy(record, true);
501         ctsvc_server_trim_memory();
502         ctsvc_server_start_timeout();
503         return;
504 }
505
506 void ctsvc_ipc_server_db_delete_record(pims_ipc_h ipc, pims_ipc_data_h indata,
507                 pims_ipc_data_h *outdata, void *userdata)
508 {
509         int ret = CONTACTS_ERROR_NONE;
510         char *view_uri = NULL;
511         int id = 0;
512         contacts_h contact = NULL;
513
514         if (indata) {
515                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
516                 if (CONTACTS_ERROR_NONE != ret) {
517                         /* LCOV_EXCL_START */
518                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
519                         ret = CONTACTS_ERROR_IPC;
520                         goto ERROR_RETURN;
521                         /* LCOV_EXCL_STOP */
522                 }
523                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
524                 if (ret != CONTACTS_ERROR_NONE) {
525                         /* LCOV_EXCL_START */
526                         ERR("ctsvc_ipc_unmarshal_record() Fail");
527                         goto ERROR_RETURN;
528                         /* LCOV_EXCL_STOP */
529                 }
530                 ret = ctsvc_ipc_unmarshal_int(indata, &id);
531                 if (ret != CONTACTS_ERROR_NONE) {
532                         /* LCOV_EXCL_START */
533                         ERR("ctsvc_ipc_unmarshal_int() Fail");
534                         goto ERROR_RETURN;
535                         /* LCOV_EXCL_STOP */
536                 }
537         } else {
538                 /* LCOV_EXCL_START */
539                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
540                 goto ERROR_RETURN;
541                 /* LCOV_EXCL_STOP */
542         }
543
544         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(view_uri))) {
545                 /* LCOV_EXCL_START */
546                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
547                 goto ERROR_RETURN;
548                 /* LCOV_EXCL_STOP */
549         }
550
551         ret = ctsvc_db_delete_record(view_uri, id);
552
553         if (outdata) {
554                 *outdata = pims_ipc_data_create(0);
555                 if (NULL == *outdata) {
556                         /* LCOV_EXCL_START */
557                         ERR("pims_ipc_data_create() Fail");
558                         goto DATA_FREE;
559                         /* LCOV_EXCL_STOP */
560                 }
561                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
562                         /* LCOV_EXCL_START */
563                         pims_ipc_data_destroy(*outdata);
564                         *outdata = NULL;
565                         ERR("ctsvc_ipc_marshal_int() Fail");
566                         goto DATA_FREE;
567                         /* LCOV_EXCL_STOP */
568                 }
569
570                 if (ret == CONTACTS_ERROR_NONE) {
571                         int transaction_ver = ctsvc_get_transaction_ver();
572                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
573                                 /* LCOV_EXCL_START */
574                                 pims_ipc_data_destroy(*outdata);
575                                 *outdata = NULL;
576                                 ERR("ctsvc_ipc_marshal_int() Fail");
577                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
578                                 goto ERROR_RETURN;
579                                 /* LCOV_EXCL_STOP */
580                         }
581                 }
582         }
583
584         goto DATA_FREE;
585
586 ERROR_RETURN:
587         if (outdata) {
588                 *outdata = pims_ipc_data_create(0);
589                 if (NULL == *outdata) {
590                         /* LCOV_EXCL_START */
591                         ERR("pims_ipc_data_create() Fail");
592                         goto DATA_FREE;
593                         /* LCOV_EXCL_STOP */
594                 }
595                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
596                         /* LCOV_EXCL_START */
597                         pims_ipc_data_destroy(*outdata);
598                         *outdata = NULL;
599                         ERR("ctsvc_ipc_marshal_int() Fail");
600                         goto DATA_FREE;
601                         /* LCOV_EXCL_STOP */
602                 }
603         } else {
604                 /* LCOV_EXCL_START */
605                 ERR("outdata is NULL");
606                 /* LCOV_EXCL_STOP */
607         }
608
609 DATA_FREE:
610         ctsvc_handle_destroy(contact);
611         free(view_uri);
612         ctsvc_server_start_timeout();
613         return;
614 }
615
616 void ctsvc_ipc_server_db_replace_record(pims_ipc_h ipc, pims_ipc_data_h indata,
617                 pims_ipc_data_h *outdata, void *userdata)
618 {
619         int ret = CONTACTS_ERROR_NONE;
620         contacts_record_h record = NULL;
621         int id = 0;
622         contacts_h contact = NULL;
623
624         if (indata) {
625                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
626                 if (CONTACTS_ERROR_NONE != ret) {
627                         /* LCOV_EXCL_START */
628                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
629                         ret = CONTACTS_ERROR_IPC;
630                         goto ERROR_RETURN;
631                         /* LCOV_EXCL_STOP */
632                 }
633
634                 ret = ctsvc_ipc_unmarshal_record(indata, &record);
635                 if (ret != CONTACTS_ERROR_NONE) {
636                         /* LCOV_EXCL_START */
637                         ERR("ctsvc_ipc_unmarshal_record() Fail");
638                         record = NULL;
639                         goto ERROR_RETURN;
640                         /* LCOV_EXCL_STOP */
641                 }
642                 ret = ctsvc_ipc_unmarshal_int(indata, &id);
643                 if (ret != CONTACTS_ERROR_NONE) {
644                         /* LCOV_EXCL_START */
645                         ERR("ctsvc_ipc_unmarshal_int() Fail");
646                         goto ERROR_RETURN;
647                         /* LCOV_EXCL_STOP */
648                 }
649         } else {
650                 /* LCOV_EXCL_START */
651                 ERR("ctsvc_ipc_server_db_replace_record Fail");
652                 goto ERROR_RETURN;
653                 /* LCOV_EXCL_STOP */
654         }
655
656         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(((ctsvc_record_s*)record)->view_uri))) {
657                 /* LCOV_EXCL_START */
658                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
659                 goto ERROR_RETURN;
660                 /* LCOV_EXCL_STOP */
661         }
662
663
664         ret = ctsvc_db_replace_record(record, id);
665
666         if (outdata) {
667                 *outdata = pims_ipc_data_create(0);
668                 if (NULL == *outdata) {
669                         /* LCOV_EXCL_START */
670                         ERR("pims_ipc_data_create() Fail");
671                         goto DATA_FREE;
672                         /* LCOV_EXCL_STOP */
673                 }
674
675                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
676                         /* LCOV_EXCL_START */
677                         pims_ipc_data_destroy(*outdata);
678                         *outdata = NULL;
679                         ERR("ctsvc_ipc_marshal_int() Fail");
680                         goto DATA_FREE;
681                         /* LCOV_EXCL_STOP */
682                 }
683
684                 if (ret == CONTACTS_ERROR_NONE) {
685                         int transaction_ver = ctsvc_get_transaction_ver();
686                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
687                                 /* LCOV_EXCL_START */
688                                 pims_ipc_data_destroy(*outdata);
689                                 *outdata = NULL;
690                                 ERR("ctsvc_ipc_marshal_int() Fail");
691                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
692                                 goto ERROR_RETURN;
693                                 /* LCOV_EXCL_STOP */
694                         }
695                 }
696         } else {
697                 /* LCOV_EXCL_START */
698                 ERR("outdata is NULL");
699                 /* LCOV_EXCL_STOP */
700         }
701         goto DATA_FREE;
702
703 ERROR_RETURN:
704         if (outdata) {
705                 *outdata = pims_ipc_data_create(0);
706                 if (NULL == *outdata) {
707                         /* LCOV_EXCL_START */
708                         ERR("pims_ipc_data_create() Fail");
709                         goto DATA_FREE;
710                         /* LCOV_EXCL_STOP */
711                 }
712                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
713                         /* LCOV_EXCL_START */
714                         pims_ipc_data_destroy(*outdata);
715                         *outdata = NULL;
716                         ERR("ctsvc_ipc_marshal_int() Fail");
717                         goto DATA_FREE;
718                         /* LCOV_EXCL_STOP */
719                 }
720         } else {
721                 /* LCOV_EXCL_START */
722                 ERR("outdata is NULL");
723                 /* LCOV_EXCL_STOP */
724         }
725
726 DATA_FREE:
727         ctsvc_handle_destroy(contact);
728         contacts_record_destroy(record, true);
729         ctsvc_server_start_timeout();
730         return;
731 }
732
733 void ctsvc_ipc_server_db_get_all_records(pims_ipc_h ipc, pims_ipc_data_h indata,
734                 pims_ipc_data_h *outdata, void *userdata)
735 {
736         int ret = CONTACTS_ERROR_NONE;
737         char *view_uri = NULL;
738         int offset = 0;
739         int limit = 0;
740         contacts_list_h list = NULL;
741         contacts_h contact = NULL;
742
743         if (indata) {
744                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
745                 if (CONTACTS_ERROR_NONE != ret) {
746                         /* LCOV_EXCL_START */
747                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
748                         ret = CONTACTS_ERROR_IPC;
749                         goto ERROR_RETURN;
750                         /* LCOV_EXCL_STOP */
751                 }
752
753                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
754                 if (ret != CONTACTS_ERROR_NONE) {
755                         /* LCOV_EXCL_START */
756                         ERR("ctsvc_ipc_unmarshal_record() Fail");
757                         goto ERROR_RETURN;
758                         /* LCOV_EXCL_STOP */
759                 }
760                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
761                 if (ret != CONTACTS_ERROR_NONE) {
762                         /* LCOV_EXCL_START */
763                         ERR("ctsvc_ipc_unmarshal_int() Fail");
764                         goto ERROR_RETURN;
765                         /* LCOV_EXCL_STOP */
766                 }
767                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
768                 if (ret != CONTACTS_ERROR_NONE) {
769                         /* LCOV_EXCL_START */
770                         ERR("ctsvc_ipc_unmarshal_int() Fail");
771                         goto ERROR_RETURN;
772                         /* LCOV_EXCL_STOP */
773                 }
774         } else {
775                 /* LCOV_EXCL_START */
776                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
777                 goto ERROR_RETURN;
778                 /* LCOV_EXCL_STOP */
779         }
780
781         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
782                 /* LCOV_EXCL_START */
783                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
784                 goto ERROR_RETURN;
785                 /* LCOV_EXCL_STOP */
786         }
787
788         ret = ctsvc_db_get_all_records(view_uri, offset, limit, &list);
789
790         if (outdata) {
791                 *outdata = pims_ipc_data_create(0);
792                 if (NULL == *outdata) {
793                         /* LCOV_EXCL_START */
794                         ERR("pims_ipc_data_create() Fail");
795                         goto DATA_FREE;
796                         /* LCOV_EXCL_STOP */
797                 }
798                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
799                         /* LCOV_EXCL_START */
800                         pims_ipc_data_destroy(*outdata);
801                         *outdata = NULL;
802                         ERR("ctsvc_ipc_marshal_int() Fail");
803                         goto DATA_FREE;
804                         /* LCOV_EXCL_STOP */
805                 }
806
807                 if (CONTACTS_ERROR_NO_DATA == ret) {
808                         DBG("no data");
809                 } else if (CONTACTS_ERROR_NONE == ret) {
810                         ret = ctsvc_ipc_marshal_list(list, *outdata);
811
812                         if (ret != CONTACTS_ERROR_NONE) {
813                                 /* LCOV_EXCL_START */
814                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
815                                 goto DATA_FREE;
816                                 /* LCOV_EXCL_STOP */
817                         }
818                 }
819
820         } else {
821                 /* LCOV_EXCL_START */
822                 ERR("outdata is NULL");
823                 /* LCOV_EXCL_STOP */
824         }
825
826         goto DATA_FREE;
827
828 ERROR_RETURN:
829         if (outdata) {
830                 *outdata = pims_ipc_data_create(0);
831                 if (NULL == *outdata) {
832                         /* LCOV_EXCL_START */
833                         ERR("pims_ipc_data_create() Fail");
834                         goto DATA_FREE;
835                         /* LCOV_EXCL_STOP */
836                 }
837                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
838                         /* LCOV_EXCL_START */
839                         pims_ipc_data_destroy(*outdata);
840                         *outdata = NULL;
841                         ERR("ctsvc_ipc_marshal_int() Fail");
842                         goto DATA_FREE;
843                         /* LCOV_EXCL_STOP */
844                 }
845         } else {
846                 /* LCOV_EXCL_START */
847                 ERR("outdata is NULL");
848                 /* LCOV_EXCL_STOP */
849         }
850 DATA_FREE:
851         ctsvc_handle_destroy(contact);
852         contacts_list_destroy(list, true);
853         free(view_uri);
854         ctsvc_server_start_timeout();
855         return;
856 }
857
858 void ctsvc_ipc_server_db_get_records_with_query(pims_ipc_h ipc, pims_ipc_data_h indata,
859                 pims_ipc_data_h *outdata, void *userdata)
860 {
861         int ret = CONTACTS_ERROR_NONE;
862         contacts_query_h query = NULL;
863         int offset = 0;
864         int limit = 0;
865         contacts_list_h list = NULL;
866         contacts_h contact = NULL;
867
868         if (indata) {
869                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
870                 if (CONTACTS_ERROR_NONE != ret) {
871                         /* LCOV_EXCL_START */
872                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
873                         goto ERROR_RETURN;
874                         /* LCOV_EXCL_STOP */
875                 }
876
877                 ret = ctsvc_ipc_unmarshal_query(indata, &query);
878                 if (ret != CONTACTS_ERROR_NONE) {
879                         /* LCOV_EXCL_START */
880                         ERR("ctsvc_ipc_unmarshal_record() Fail");
881                         goto ERROR_RETURN;
882                         /* LCOV_EXCL_STOP */
883                 }
884                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
885                 if (ret != CONTACTS_ERROR_NONE) {
886                         /* LCOV_EXCL_START */
887                         ERR("ctsvc_ipc_unmarshal_int() Fail");
888                         goto ERROR_RETURN;
889                         /* LCOV_EXCL_STOP */
890                 }
891                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
892                 if (ret != CONTACTS_ERROR_NONE) {
893                         /* LCOV_EXCL_START */
894                         ERR("ctsvc_ipc_unmarshal_int() Fail");
895                         goto ERROR_RETURN;
896                         /* LCOV_EXCL_STOP */
897                 }
898         } else {
899                 /* LCOV_EXCL_START */
900                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
901                 goto ERROR_RETURN;
902                 /* LCOV_EXCL_STOP */
903         }
904
905         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(((ctsvc_query_s*)query)->view_uri))) {
906                 /* LCOV_EXCL_START */
907                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
908                 goto ERROR_RETURN;
909                 /* LCOV_EXCL_STOP */
910         }
911
912         ret = ctsvc_db_get_records_with_query(query, offset, limit, &list);
913
914         if (outdata) {
915                 *outdata = pims_ipc_data_create(0);
916                 if (NULL == *outdata) {
917                         /* LCOV_EXCL_START */
918                         ERR("pims_ipc_data_create() Fail");
919                         goto DATA_FREE;
920                         /* LCOV_EXCL_STOP */
921                 }
922                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
923                         /* LCOV_EXCL_START */
924                         pims_ipc_data_destroy(*outdata);
925                         *outdata = NULL;
926                         ERR("ctsvc_ipc_marshal_int() Fail");
927                         goto DATA_FREE;
928                         /* LCOV_EXCL_STOP */
929                 }
930
931                 if (CONTACTS_ERROR_NO_DATA == ret) {
932                         DBG("no data");
933                 } else if (CONTACTS_ERROR_NONE == ret) {
934                         ret = ctsvc_ipc_marshal_list(list, *outdata);
935
936                         if (ret != CONTACTS_ERROR_NONE) {
937                                 /* LCOV_EXCL_START */
938                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
939                                 goto DATA_FREE;
940                                 /* LCOV_EXCL_STOP */
941                         }
942                 }
943         } else {
944                 /* LCOV_EXCL_START */
945                 ERR("outdata is NULL");
946                 /* LCOV_EXCL_STOP */
947         }
948         goto DATA_FREE;
949
950 ERROR_RETURN:
951         if (outdata) {
952                 *outdata = pims_ipc_data_create(0);
953                 if (NULL == *outdata) {
954                         /* LCOV_EXCL_START */
955                         ERR("pims_ipc_data_create() Fail");
956                         goto DATA_FREE;
957                         /* LCOV_EXCL_STOP */
958                 }
959                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
960                         /* LCOV_EXCL_START */
961                         pims_ipc_data_destroy(*outdata);
962                         *outdata = NULL;
963                         ERR("ctsvc_ipc_marshal_int() Fail");
964                         goto DATA_FREE;
965                         /* LCOV_EXCL_STOP */
966                 }
967         } else {
968                 /* LCOV_EXCL_START */
969                 ERR("outdata is NULL");
970                 /* LCOV_EXCL_STOP */
971         }
972 DATA_FREE:
973         ctsvc_handle_destroy(contact);
974         contacts_list_destroy(list, true);
975         contacts_query_destroy(query);
976         ctsvc_server_start_timeout();
977         return;
978 }
979
980
981 void ctsvc_ipc_server_db_get_count(pims_ipc_h ipc, pims_ipc_data_h indata,
982                 pims_ipc_data_h *outdata, void *userdata)
983 {
984         int ret = CONTACTS_ERROR_NONE;
985         char *view_uri = NULL;
986         int count = 0;
987         contacts_h contact = NULL;
988
989         if (indata) {
990                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
991                 if (CONTACTS_ERROR_NONE != ret) {
992                         /* LCOV_EXCL_START */
993                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
994                         goto ERROR_RETURN;
995                         /* LCOV_EXCL_STOP */
996                 }
997
998                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
999                 if (ret != CONTACTS_ERROR_NONE) {
1000                         /* LCOV_EXCL_START */
1001                         ERR("ctsvc_ipc_unmarshal_record() Fail");
1002                         goto ERROR_RETURN;
1003                         /* LCOV_EXCL_STOP */
1004                 }
1005         } else {
1006                 /* LCOV_EXCL_START */
1007                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
1008                 goto ERROR_RETURN;
1009                 /* LCOV_EXCL_STOP */
1010         }
1011
1012         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
1013                 /* LCOV_EXCL_START */
1014                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1015                 goto ERROR_RETURN;
1016                 /* LCOV_EXCL_STOP */
1017         }
1018
1019         ret = ctsvc_db_get_count(view_uri, &count);
1020
1021         if (outdata) {
1022                 *outdata = pims_ipc_data_create(0);
1023                 if (NULL == *outdata) {
1024                         /* LCOV_EXCL_START */
1025                         ERR("pims_ipc_data_create() Fail");
1026                         goto DATA_FREE;
1027                         /* LCOV_EXCL_STOP */
1028                 }
1029                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1030                         /* LCOV_EXCL_START */
1031                         pims_ipc_data_destroy(*outdata);
1032                         *outdata = NULL;
1033                         ERR("ctsvc_ipc_marshal_int() Fail");
1034                         goto DATA_FREE;
1035                         /* LCOV_EXCL_STOP */
1036                 }
1037
1038                 if (CONTACTS_ERROR_NO_DATA == ret) {
1039                         DBG("no data");
1040                 } else if (CONTACTS_ERROR_NONE == ret) {
1041                         ret = ctsvc_ipc_marshal_int(count, *outdata);
1042
1043                         if (ret != CONTACTS_ERROR_NONE) {
1044                                 /* LCOV_EXCL_START */
1045                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
1046                                 goto DATA_FREE;
1047                                 /* LCOV_EXCL_STOP */
1048                         }
1049                 }
1050         } else {
1051                 /* LCOV_EXCL_START */
1052                 ERR("outdata is NULL");
1053                 /* LCOV_EXCL_STOP */
1054         }
1055         goto DATA_FREE;
1056
1057 ERROR_RETURN:
1058         if (outdata) {
1059                 *outdata = pims_ipc_data_create(0);
1060                 if (NULL == *outdata) {
1061                         /* LCOV_EXCL_START */
1062                         ERR("pims_ipc_data_create() Fail");
1063                         goto DATA_FREE;
1064                         /* LCOV_EXCL_STOP */
1065                 }
1066                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1067                         /* LCOV_EXCL_START */
1068                         pims_ipc_data_destroy(*outdata);
1069                         *outdata = NULL;
1070                         ERR("ctsvc_ipc_marshal_int() Fail");
1071                         goto DATA_FREE;
1072                         /* LCOV_EXCL_STOP */
1073                 }
1074         } else {
1075                 /* LCOV_EXCL_START */
1076                 ERR("outdata is NULL");
1077                 /* LCOV_EXCL_STOP */
1078         }
1079 DATA_FREE:
1080         ctsvc_handle_destroy(contact);
1081         free(view_uri);
1082         ctsvc_server_start_timeout();
1083         return;
1084 }
1085
1086 void ctsvc_ipc_server_db_get_count_with_query(pims_ipc_h ipc, pims_ipc_data_h indata,
1087                 pims_ipc_data_h *outdata, void *userdata)
1088 {
1089         int ret = CONTACTS_ERROR_NONE;
1090         contacts_query_h query = NULL;
1091         int count = 0;
1092         contacts_h contact = NULL;
1093
1094         if (indata) {
1095                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1096                 if (CONTACTS_ERROR_NONE != ret) {
1097                         /* LCOV_EXCL_START */
1098                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1099                         goto ERROR_RETURN;
1100                         /* LCOV_EXCL_STOP */
1101                 }
1102
1103                 ret = ctsvc_ipc_unmarshal_query(indata, &query);
1104                 if (ret != CONTACTS_ERROR_NONE) {
1105                         /* LCOV_EXCL_START */
1106                         ERR("ctsvc_ipc_unmarshal_record() Fail");
1107                         goto ERROR_RETURN;
1108                         /* LCOV_EXCL_STOP */
1109                 }
1110         } else {
1111                 /* LCOV_EXCL_START */
1112                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
1113                 goto ERROR_RETURN;
1114                 /* LCOV_EXCL_STOP */
1115         }
1116
1117         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(((ctsvc_query_s*)query)->view_uri))) {
1118                 /* LCOV_EXCL_START */
1119                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1120                 goto ERROR_RETURN;
1121                 /* LCOV_EXCL_STOP */
1122         }
1123
1124         ret = ctsvc_db_get_count_with_query(query, &count);
1125
1126         if (outdata) {
1127                 *outdata = pims_ipc_data_create(0);
1128                 if (NULL == *outdata) {
1129                         /* LCOV_EXCL_START */
1130                         ERR("pims_ipc_data_create() Fail");
1131                         goto DATA_FREE;
1132                         /* LCOV_EXCL_STOP */
1133                 }
1134                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1135                         /* LCOV_EXCL_START */
1136                         pims_ipc_data_destroy(*outdata);
1137                         *outdata = NULL;
1138                         ERR("ctsvc_ipc_marshal_int() Fail");
1139                         goto DATA_FREE;
1140                         /* LCOV_EXCL_STOP */
1141                 }
1142
1143                 if (CONTACTS_ERROR_NO_DATA == ret) {
1144                         DBG("no data");
1145                 } else if (CONTACTS_ERROR_NONE == ret) {
1146                         ret = ctsvc_ipc_marshal_int(count, *outdata);
1147
1148                         if (ret != CONTACTS_ERROR_NONE) {
1149                                 /* LCOV_EXCL_START */
1150                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
1151                                 goto DATA_FREE;
1152                                 /* LCOV_EXCL_STOP */
1153                         }
1154                 }
1155         } else {
1156                 /* LCOV_EXCL_START */
1157                 ERR("outdata is NULL");
1158                 /* LCOV_EXCL_STOP */
1159         }
1160         goto DATA_FREE;
1161
1162 ERROR_RETURN:
1163         if (outdata) {
1164                 *outdata = pims_ipc_data_create(0);
1165                 if (NULL == *outdata) {
1166                         /* LCOV_EXCL_START */
1167                         ERR("pims_ipc_data_create() Fail");
1168                         goto DATA_FREE;
1169                         /* LCOV_EXCL_STOP */
1170                 }
1171                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1172                         /* LCOV_EXCL_START */
1173                         pims_ipc_data_destroy(*outdata);
1174                         *outdata = NULL;
1175                         ERR("ctsvc_ipc_marshal_int() Fail");
1176                         goto DATA_FREE;
1177                         /* LCOV_EXCL_STOP */
1178                 }
1179         } else {
1180                 /* LCOV_EXCL_START */
1181                 ERR("outdata is NULL");
1182                 /* LCOV_EXCL_STOP */
1183         }
1184 DATA_FREE:
1185         ctsvc_handle_destroy(contact);
1186         contacts_query_destroy(query);
1187         ctsvc_server_start_timeout();
1188         return;
1189 }
1190
1191 void ctsvc_ipc_server_db_insert_records(pims_ipc_h ipc, pims_ipc_data_h indata,
1192                 pims_ipc_data_h *outdata, void *userdata)
1193 {
1194         int ret = CONTACTS_ERROR_NONE;
1195         contacts_list_h list = NULL;
1196         int id_count = 0;
1197         int *ids = NULL;
1198         int i = 0;
1199         contacts_h contact = NULL;
1200
1201         if (indata) {
1202                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1203                 if (CONTACTS_ERROR_NONE != ret) {
1204                         /* LCOV_EXCL_START */
1205                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1206                         goto ERROR_RETURN;
1207                         /* LCOV_EXCL_STOP */
1208                 }
1209
1210                 ret = ctsvc_ipc_unmarshal_list(indata, &list);
1211                 if (ret != CONTACTS_ERROR_NONE) {
1212                         /* LCOV_EXCL_START */
1213                         ERR("ctsvc_ipc_unmarshal_list Fail");
1214                         goto ERROR_RETURN;
1215                         /* LCOV_EXCL_STOP */
1216                 }
1217         } else {
1218                 /* LCOV_EXCL_START */
1219                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
1220                 goto ERROR_RETURN;
1221                 /* LCOV_EXCL_STOP */
1222         }
1223
1224         if (list) {
1225                 contacts_record_h record = NULL;
1226                 contacts_list_first(list);
1227                 do {
1228                         ret = contacts_list_get_current_record_p(list, &record);
1229                         if (CONTACTS_ERROR_NONE != ret) {
1230                                 /* LCOV_EXCL_START */
1231                                 ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
1232                                 goto ERROR_RETURN;
1233                                 /* LCOV_EXCL_STOP */
1234                         }
1235
1236                         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(((ctsvc_record_s*)record)->view_uri))) {
1237                                 /* LCOV_EXCL_START */
1238                                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1239                                 goto ERROR_RETURN;
1240                                 /* LCOV_EXCL_STOP */
1241                         }
1242                 } while (CONTACTS_ERROR_NONE == contacts_list_next(list));
1243                 contacts_list_first(list);
1244         }
1245
1246         ctsvc_server_stop_timeout();
1247         ret = ctsvc_db_insert_records(list, &ids, &id_count);
1248
1249         if (outdata) {
1250                 *outdata = pims_ipc_data_create(0);
1251                 if (NULL == *outdata) {
1252                         /* LCOV_EXCL_START */
1253                         ERR("pims_ipc_data_create() Fail");
1254                         goto DATA_FREE;
1255                         /* LCOV_EXCL_STOP */
1256                 }
1257                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1258                         /* LCOV_EXCL_START */
1259                         pims_ipc_data_destroy(*outdata);
1260                         *outdata = NULL;
1261                         ERR("ctsvc_ipc_marshal_int() Fail");
1262                         goto DATA_FREE;
1263                         /* LCOV_EXCL_STOP */
1264                 }
1265
1266                 if (ret == CONTACTS_ERROR_NONE) {
1267                         int transaction_ver = ctsvc_get_transaction_ver();
1268                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
1269                                 /* LCOV_EXCL_START */
1270                                 pims_ipc_data_destroy(*outdata);
1271                                 *outdata = NULL;
1272                                 ERR("ctsvc_ipc_marshal_int() Fail");
1273                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1274                                 goto ERROR_RETURN;
1275                                 /* LCOV_EXCL_STOP */
1276                         }
1277                         /* marshal : id_count+property_id+[ids]*id_count */
1278                         /* id_count */
1279                         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(id_count, *outdata)) {
1280                                 /* LCOV_EXCL_START */
1281                                 pims_ipc_data_destroy(*outdata);
1282                                 *outdata = NULL;
1283                                 ERR("ctsvc_ipc_marshal_int() Fail");
1284                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1285                                 goto ERROR_RETURN;
1286                                 /* LCOV_EXCL_STOP */
1287                         }
1288
1289                         for (i = 0; i < id_count; i++) {
1290                                 /* marshal ids */
1291                                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ids[i], *outdata)) {
1292                                         /* LCOV_EXCL_START */
1293                                         pims_ipc_data_destroy(*outdata);
1294                                         *outdata = NULL;
1295                                         ERR("ctsvc_ipc_marshal_int() Fail");
1296                                         ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1297                                         goto ERROR_RETURN;
1298                                         /* LCOV_EXCL_STOP */
1299                                 }
1300                         }
1301                 }
1302         } else {
1303                 /* LCOV_EXCL_START */
1304                 ERR("outdata is NULL");
1305                 /* LCOV_EXCL_STOP */
1306         }
1307         goto DATA_FREE;
1308
1309 ERROR_RETURN:
1310         if (outdata) {
1311                 *outdata = pims_ipc_data_create(0);
1312                 if (NULL == *outdata) {
1313                         /* LCOV_EXCL_START */
1314                         ERR("pims_ipc_data_create() Fail");
1315                         goto DATA_FREE;
1316                         /* LCOV_EXCL_STOP */
1317                 }
1318                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1319                         /* LCOV_EXCL_START */
1320                         pims_ipc_data_destroy(*outdata);
1321                         *outdata = NULL;
1322                         ERR("ctsvc_ipc_marshal_int() Fail");
1323                         goto DATA_FREE;
1324                         /* LCOV_EXCL_STOP */
1325                 }
1326         } else {
1327                 /* LCOV_EXCL_START */
1328                 ERR("outdata is NULL");
1329                 /* LCOV_EXCL_STOP */
1330         }
1331 DATA_FREE:
1332         ctsvc_handle_destroy(contact);
1333         contacts_list_destroy(list, true);
1334         free(ids);
1335         ctsvc_server_start_timeout();
1336         return;
1337 }
1338
1339 void ctsvc_ipc_server_db_update_records(pims_ipc_h ipc, pims_ipc_data_h indata,
1340                 pims_ipc_data_h *outdata, void *userdata)
1341 {
1342         int ret = CONTACTS_ERROR_NONE;
1343         contacts_list_h list = NULL;
1344         contacts_h contact = NULL;
1345
1346         if (indata) {
1347                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1348                 if (CONTACTS_ERROR_NONE != ret) {
1349                         /* LCOV_EXCL_START */
1350                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1351                         goto ERROR_RETURN;
1352                         /* LCOV_EXCL_STOP */
1353                 }
1354
1355                 ret = ctsvc_ipc_unmarshal_list(indata, &list);
1356                 if (ret != CONTACTS_ERROR_NONE) {
1357                         /* LCOV_EXCL_START */
1358                         ERR("ctsvc_ipc_unmarshal_list Fail");
1359                         goto ERROR_RETURN;
1360                         /* LCOV_EXCL_STOP */
1361                 }
1362         } else {
1363                 /* LCOV_EXCL_START */
1364                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
1365                 goto ERROR_RETURN;
1366                 /* LCOV_EXCL_STOP */
1367         }
1368
1369         if (list) {
1370                 contacts_record_h record = NULL;
1371                 contacts_list_first(list);
1372                 do {
1373                         ret = contacts_list_get_current_record_p(list, &record);
1374                         if (CONTACTS_ERROR_NONE != ret) {
1375                                 /* LCOV_EXCL_START */
1376                                 ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
1377                                 goto ERROR_RETURN;
1378                                 /* LCOV_EXCL_STOP */
1379                         }
1380
1381                         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(((ctsvc_record_s*)record)->view_uri))) {
1382                                 /* LCOV_EXCL_START */
1383                                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1384                                 goto ERROR_RETURN;
1385                                 /* LCOV_EXCL_STOP */
1386                         }
1387                 } while (CONTACTS_ERROR_NONE == contacts_list_next(list));
1388                 contacts_list_first(list);
1389         }
1390
1391         ctsvc_server_stop_timeout();
1392         ret = ctsvc_db_update_records(list);
1393
1394         if (outdata) {
1395                 *outdata = pims_ipc_data_create(0);
1396                 if (NULL == *outdata) {
1397                         /* LCOV_EXCL_START */
1398                         ERR("pims_ipc_data_create() Fail");
1399                         goto DATA_FREE;
1400                         /* LCOV_EXCL_STOP */
1401                 }
1402                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1403                         /* LCOV_EXCL_START */
1404                         pims_ipc_data_destroy(*outdata);
1405                         *outdata = NULL;
1406                         ERR("ctsvc_ipc_marshal_int() Fail");
1407                         goto DATA_FREE;
1408                         /* LCOV_EXCL_STOP */
1409                 }
1410
1411                 if (ret == CONTACTS_ERROR_NONE) {
1412                         int transaction_ver = ctsvc_get_transaction_ver();
1413                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
1414                                 /* LCOV_EXCL_START */
1415                                 pims_ipc_data_destroy(*outdata);
1416                                 *outdata = NULL;
1417                                 ERR("ctsvc_ipc_marshal_int() Fail");
1418                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1419                                 goto ERROR_RETURN;
1420                                 /* LCOV_EXCL_STOP */
1421                         }
1422                 }
1423         } else {
1424                 /* LCOV_EXCL_START */
1425                 ERR("outdata is NULL");
1426                 /* LCOV_EXCL_STOP */
1427         }
1428         goto DATA_FREE;
1429
1430 ERROR_RETURN:
1431         if (outdata) {
1432                 *outdata = pims_ipc_data_create(0);
1433                 if (NULL == *outdata) {
1434                         /* LCOV_EXCL_START */
1435                         ERR("pims_ipc_data_create() Fail");
1436                         goto DATA_FREE;
1437                         /* LCOV_EXCL_STOP */
1438                 }
1439                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1440                         /* LCOV_EXCL_START */
1441                         pims_ipc_data_destroy(*outdata);
1442                         *outdata = NULL;
1443                         ERR("ctsvc_ipc_marshal_int() Fail");
1444                         goto DATA_FREE;
1445                         /* LCOV_EXCL_STOP */
1446                 }
1447         } else {
1448                 /* LCOV_EXCL_START */
1449                 ERR("outdata is NULL");
1450                 /* LCOV_EXCL_STOP */
1451         }
1452 DATA_FREE:
1453         ctsvc_handle_destroy(contact);
1454         contacts_list_destroy(list, true);
1455         ctsvc_server_start_timeout();
1456         return;
1457 }
1458
1459 void ctsvc_ipc_server_db_delete_records(pims_ipc_h ipc, pims_ipc_data_h indata,
1460                 pims_ipc_data_h *outdata, void *userdata)
1461 {
1462         int ret = CONTACTS_ERROR_NONE;
1463         int count = 0;
1464         int *ids = NULL;
1465         char *uri = NULL;
1466         int i = 0;
1467         contacts_h contact = NULL;
1468
1469         if (indata) {
1470                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1471                 if (CONTACTS_ERROR_NONE != ret) {
1472                         /* LCOV_EXCL_START */
1473                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1474                         goto ERROR_RETURN;
1475                         /* LCOV_EXCL_STOP */
1476                 }
1477
1478                 ret = ctsvc_ipc_unmarshal_string(indata, &uri);
1479                 if (ret != CONTACTS_ERROR_NONE) {
1480                         /* LCOV_EXCL_START */
1481                         ERR("ctsvc_ipc_unmarshal_string Fail");
1482                         goto ERROR_RETURN;
1483                         /* LCOV_EXCL_STOP */
1484                 }
1485                 ret = ctsvc_ipc_unmarshal_int(indata, &count);
1486                 if (ret != CONTACTS_ERROR_NONE) {
1487                         /* LCOV_EXCL_START */
1488                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1489                         goto ERROR_RETURN;
1490                         /* LCOV_EXCL_STOP */
1491                 }
1492                 if (count <= 0) {
1493                         /* LCOV_EXCL_START */
1494                         ret = CONTACTS_ERROR_INVALID_PARAMETER;
1495                         goto ERROR_RETURN;
1496                         /* LCOV_EXCL_STOP */
1497                 }
1498                 ids = (int*)malloc(sizeof(int)*count);
1499                 for (i = 0; i < count; i++) {
1500                         ret = ctsvc_ipc_unmarshal_int(indata, &ids[i]);
1501                         if (ret != CONTACTS_ERROR_NONE) {
1502                                 /* LCOV_EXCL_START */
1503                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
1504                                 goto ERROR_RETURN;
1505                                 /* LCOV_EXCL_STOP */
1506                         }
1507                 }
1508         } else {
1509                 /* LCOV_EXCL_START */
1510                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
1511                 goto ERROR_RETURN;
1512                 /* LCOV_EXCL_STOP */
1513         }
1514
1515         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(uri))) {
1516                 /* LCOV_EXCL_START */
1517                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1518                 goto ERROR_RETURN;
1519                 /* LCOV_EXCL_STOP */
1520         }
1521
1522         ret = ctsvc_db_delete_records(uri, ids, count);
1523
1524         if (outdata) {
1525                 *outdata = pims_ipc_data_create(0);
1526                 if (NULL == *outdata) {
1527                         /* LCOV_EXCL_START */
1528                         ERR("pims_ipc_data_create() Fail");
1529                         goto DATA_FREE;
1530                         /* LCOV_EXCL_STOP */
1531                 }
1532
1533                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1534                         /* LCOV_EXCL_START */
1535                         pims_ipc_data_destroy(*outdata);
1536                         *outdata = NULL;
1537                         ERR("ctsvc_ipc_marshal_int() Fail");
1538                         goto DATA_FREE;
1539                         /* LCOV_EXCL_STOP */
1540                 }
1541
1542                 if (ret == CONTACTS_ERROR_NONE) {
1543                         int transaction_ver = ctsvc_get_transaction_ver();
1544                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
1545                                 /* LCOV_EXCL_START */
1546                                 pims_ipc_data_destroy(*outdata);
1547                                 *outdata = NULL;
1548                                 ERR("ctsvc_ipc_marshal_int() Fail");
1549                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1550                                 goto ERROR_RETURN;
1551                                 /* LCOV_EXCL_STOP */
1552                         }
1553                 }
1554         } else {
1555                 /* LCOV_EXCL_START */
1556                 ERR("outdata is NULL");
1557                 /* LCOV_EXCL_STOP */
1558         }
1559
1560         goto DATA_FREE;
1561
1562 ERROR_RETURN:
1563         if (outdata) {
1564                 *outdata = pims_ipc_data_create(0);
1565                 if (NULL == *outdata) {
1566                         /* LCOV_EXCL_START */
1567                         ERR("pims_ipc_data_create() Fail");
1568                         goto DATA_FREE;
1569                         /* LCOV_EXCL_STOP */
1570                 }
1571                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1572                         /* LCOV_EXCL_START */
1573                         pims_ipc_data_destroy(*outdata);
1574                         *outdata = NULL;
1575                         ERR("ctsvc_ipc_marshal_int() Fail");
1576                         goto DATA_FREE;
1577                         /* LCOV_EXCL_STOP */
1578                 }
1579         } else {
1580                 /* LCOV_EXCL_START */
1581                 ERR("outdata is NULL");
1582                 /* LCOV_EXCL_STOP */
1583         }
1584 DATA_FREE:
1585         ctsvc_handle_destroy(contact);
1586         free(uri);
1587         free(ids);
1588         ctsvc_server_start_timeout();
1589         return;
1590 }
1591
1592 void ctsvc_ipc_server_db_replace_records(pims_ipc_h ipc, pims_ipc_data_h indata,
1593                 pims_ipc_data_h *outdata, void *userdata)
1594 {
1595         int ret = CONTACTS_ERROR_NONE;
1596         contacts_list_h list = NULL;
1597         int count = 0;
1598         int *ids = NULL;
1599         int i = 0;
1600         contacts_h contact = NULL;
1601
1602         if (indata) {
1603                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1604                 if (CONTACTS_ERROR_NONE != ret) {
1605                         /* LCOV_EXCL_START */
1606                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1607                         goto ERROR_RETURN;
1608                         /* LCOV_EXCL_STOP */
1609                 }
1610
1611                 ret = ctsvc_ipc_unmarshal_list(indata, &list);
1612                 if (ret != CONTACTS_ERROR_NONE) {
1613                         /* LCOV_EXCL_START */
1614                         ERR("ctsvc_ipc_unmarshal_list Fail");
1615                         goto ERROR_RETURN;
1616                         /* LCOV_EXCL_STOP */
1617                 }
1618
1619                 ret = ctsvc_ipc_unmarshal_int(indata, &count);
1620                 if (ret != CONTACTS_ERROR_NONE) {
1621                         /* LCOV_EXCL_START */
1622                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1623                         goto ERROR_RETURN;
1624                         /* LCOV_EXCL_STOP */
1625                 }
1626
1627                 if (count <= 0) {
1628                         /* LCOV_EXCL_START */
1629                         ret = CONTACTS_ERROR_INVALID_PARAMETER;
1630                         goto ERROR_RETURN;
1631                         /* LCOV_EXCL_STOP */
1632                 }
1633
1634                 ids = (int*)malloc(sizeof(int)*count);
1635                 for (i = 0; i < count; i++) {
1636                         ret = ctsvc_ipc_unmarshal_int(indata, &ids[i]);
1637                         if (ret != CONTACTS_ERROR_NONE) {
1638                                 /* LCOV_EXCL_START */
1639                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
1640                                 goto ERROR_RETURN;
1641                                 /* LCOV_EXCL_STOP */
1642                         }
1643                 }
1644         } else {
1645                 /* LCOV_EXCL_START */
1646                 ERR("ctsvc_ipc_server_db_repalce_records Fail");
1647                 goto ERROR_RETURN;
1648                 /* LCOV_EXCL_STOP */
1649         }
1650
1651         if (list) {
1652                 contacts_record_h record = NULL;
1653                 contacts_list_first(list);
1654                 do {
1655                         ret = contacts_list_get_current_record_p(list, &record);
1656                         if (CONTACTS_ERROR_NONE != ret) {
1657                                 /* LCOV_EXCL_START */
1658                                 ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
1659                                 goto ERROR_RETURN;
1660                                 /* LCOV_EXCL_STOP */
1661                         }
1662
1663                         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(((ctsvc_record_s*)record)->view_uri))) {
1664                                 /* LCOV_EXCL_START */
1665                                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1666                                 goto ERROR_RETURN;
1667                                 /* LCOV_EXCL_STOP */
1668                         }
1669                 } while (CONTACTS_ERROR_NONE == contacts_list_next(list));
1670                 contacts_list_first(list);
1671         }
1672
1673         ctsvc_server_stop_timeout();
1674         ret = ctsvc_db_replace_records(list, ids, count);
1675
1676         if (outdata) {
1677                 *outdata = pims_ipc_data_create(0);
1678                 if (NULL == *outdata) {
1679                         /* LCOV_EXCL_START */
1680                         ERR("pims_ipc_data_create() Fail");
1681                         goto DATA_FREE;
1682                         /* LCOV_EXCL_STOP */
1683                 }
1684                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1685                         /* LCOV_EXCL_START */
1686                         pims_ipc_data_destroy(*outdata);
1687                         *outdata = NULL;
1688                         ERR("ctsvc_ipc_marshal_int() Fail");
1689                         goto DATA_FREE;
1690                         /* LCOV_EXCL_STOP */
1691                 }
1692                 if (ret == CONTACTS_ERROR_NONE) {
1693                         int transaction_ver = ctsvc_get_transaction_ver();
1694                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
1695                                 /* LCOV_EXCL_START */
1696                                 pims_ipc_data_destroy(*outdata);
1697                                 *outdata = NULL;
1698                                 ERR("ctsvc_ipc_marshal_int() Fail");
1699                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1700                                 goto ERROR_RETURN;
1701                                 /* LCOV_EXCL_STOP */
1702                         }
1703                 }
1704         } else {
1705                 /* LCOV_EXCL_START */
1706                 ERR("outdata is NULL");
1707                 /* LCOV_EXCL_STOP */
1708         }
1709         goto DATA_FREE;
1710
1711 ERROR_RETURN:
1712         if (outdata) {
1713                 *outdata = pims_ipc_data_create(0);
1714                 if (NULL == *outdata) {
1715                         /* LCOV_EXCL_START */
1716                         ERR("pims_ipc_data_create() Fail");
1717                         goto DATA_FREE;
1718                         /* LCOV_EXCL_STOP */
1719                 }
1720                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1721                         /* LCOV_EXCL_START */
1722                         pims_ipc_data_destroy(*outdata);
1723                         *outdata = NULL;
1724                         ERR("ctsvc_ipc_marshal_int() Fail");
1725                         goto DATA_FREE;
1726                         /* LCOV_EXCL_STOP */
1727                 }
1728         } else {
1729                 /* LCOV_EXCL_START */
1730                 ERR("outdata is NULL");
1731                 /* LCOV_EXCL_STOP */
1732         }
1733 DATA_FREE:
1734         ctsvc_handle_destroy(contact);
1735         contacts_list_destroy(list, true);
1736         free(ids);
1737         ctsvc_server_start_timeout();
1738         return;
1739 }
1740
1741 void ctsvc_ipc_server_db_get_changes_by_version(pims_ipc_h ipc, pims_ipc_data_h indata,
1742                 pims_ipc_data_h *outdata, void *userdata)
1743 {
1744         int ret = CONTACTS_ERROR_NONE;
1745         char *view_uri = NULL;
1746         int address_book_id = 0;
1747         int contacts_db_version = 0;
1748         contacts_list_h record_list = NULL;
1749         int current_contacts_db_version = 0;
1750         contacts_h contact = NULL;
1751
1752         if (indata) {
1753                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1754                 if (CONTACTS_ERROR_NONE != ret) {
1755                         /* LCOV_EXCL_START */
1756                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1757                         goto ERROR_RETURN;
1758                         /* LCOV_EXCL_STOP */
1759                 }
1760
1761                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
1762                 if (ret != CONTACTS_ERROR_NONE) {
1763                         /* LCOV_EXCL_START */
1764                         ERR("ctsvc_ipc_unmarshal_string Fail");
1765                         goto ERROR_RETURN;
1766                         /* LCOV_EXCL_STOP */
1767                 }
1768                 ret = ctsvc_ipc_unmarshal_int(indata, &address_book_id);
1769                 if (ret != CONTACTS_ERROR_NONE) {
1770                         /* LCOV_EXCL_START */
1771                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1772                         goto ERROR_RETURN;
1773                         /* LCOV_EXCL_STOP */
1774                 }
1775                 ret = ctsvc_ipc_unmarshal_int(indata, &contacts_db_version);
1776                 if (ret != CONTACTS_ERROR_NONE) {
1777                         /* LCOV_EXCL_START */
1778                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1779                         goto ERROR_RETURN;
1780                         /* LCOV_EXCL_STOP */
1781                 }
1782         } else {
1783                 /* LCOV_EXCL_START */
1784                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
1785                 goto ERROR_RETURN;
1786                 /* LCOV_EXCL_STOP */
1787         }
1788
1789         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_READ)) {
1790                 /* LCOV_EXCL_START */
1791                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1792                 goto ERROR_RETURN;
1793                 /* LCOV_EXCL_STOP */
1794         }
1795
1796         ret = ctsvc_db_get_changes_by_version(view_uri, address_book_id, contacts_db_version,
1797                         &record_list, &current_contacts_db_version);
1798
1799         if (outdata) {
1800                 *outdata = pims_ipc_data_create(0);
1801                 if (NULL == *outdata) {
1802                         /* LCOV_EXCL_START */
1803                         ERR("pims_ipc_data_create() Fail");
1804                         goto DATA_FREE;
1805                         /* LCOV_EXCL_STOP */
1806                 }
1807                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1808                         /* LCOV_EXCL_START */
1809                         pims_ipc_data_destroy(*outdata);
1810                         *outdata = NULL;
1811                         ERR("ctsvc_ipc_marshal_int() Fail");
1812                         goto DATA_FREE;
1813                         /* LCOV_EXCL_STOP */
1814                 }
1815
1816                 if (CONTACTS_ERROR_NO_DATA == ret) {
1817                         DBG("no data");
1818                 } else if (CONTACTS_ERROR_NONE == ret) {
1819                         ret = ctsvc_ipc_marshal_list(record_list, *outdata);
1820                         if (ret != CONTACTS_ERROR_NONE) {
1821                                 /* LCOV_EXCL_START */
1822                                 ERR("ctsvc_ipc_marshal_list Fail");
1823                                 pims_ipc_data_destroy(*outdata);
1824                                 *outdata = NULL;
1825                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1826                                 goto ERROR_RETURN;
1827                                 /* LCOV_EXCL_STOP */
1828                         }
1829                         ret = ctsvc_ipc_marshal_int(current_contacts_db_version, *outdata);
1830                         if (ret != CONTACTS_ERROR_NONE) {
1831                                 /* LCOV_EXCL_START */
1832                                 ERR("ctsvc_ipc_marshal_int() Fail");
1833                                 pims_ipc_data_destroy(*outdata);
1834                                 *outdata = NULL;
1835                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1836                                 goto ERROR_RETURN;
1837                                 /* LCOV_EXCL_STOP */
1838                         }
1839                 }
1840         } else {
1841                 /* LCOV_EXCL_START */
1842                 ERR("outdata is NULL");
1843                 /* LCOV_EXCL_STOP */
1844         }
1845         goto DATA_FREE;
1846
1847 ERROR_RETURN:
1848         if (outdata) {
1849                 *outdata = pims_ipc_data_create(0);
1850                 if (NULL == *outdata) {
1851                         /* LCOV_EXCL_START */
1852                         ERR("pims_ipc_data_create() Fail");
1853                         goto DATA_FREE;
1854                         /* LCOV_EXCL_STOP */
1855                 }
1856                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1857                         /* LCOV_EXCL_START */
1858                         pims_ipc_data_destroy(*outdata);
1859                         *outdata = NULL;
1860                         ERR("ctsvc_ipc_marshal_int() Fail");
1861                         goto DATA_FREE;
1862                         /* LCOV_EXCL_STOP */
1863                 }
1864         } else {
1865                 /* LCOV_EXCL_START */
1866                 ERR("outdata is NULL");
1867                 /* LCOV_EXCL_STOP */
1868         }
1869 DATA_FREE:
1870         ctsvc_handle_destroy(contact);
1871         contacts_list_destroy(record_list, true);
1872         free(view_uri);
1873         ctsvc_server_start_timeout();
1874         return;
1875 }
1876
1877 void ctsvc_ipc_server_db_get_current_version(pims_ipc_h ipc, pims_ipc_data_h indata,
1878                 pims_ipc_data_h *outdata, void *userdata)
1879 {
1880         int ret = CONTACTS_ERROR_NONE;
1881         int contacts_db_version = 0;
1882         contacts_h contact = NULL;
1883
1884         if (indata) {
1885                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1886                 if (CONTACTS_ERROR_NONE != ret) {
1887                         /* LCOV_EXCL_START */
1888                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1889                         goto ERROR_RETURN;
1890                         /* LCOV_EXCL_STOP */
1891                 }
1892         }
1893
1894         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_READ) &&
1895                         !ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_READ)) {
1896                 /* LCOV_EXCL_START */
1897                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1898                 goto ERROR_RETURN;
1899                 /* LCOV_EXCL_STOP */
1900         }
1901
1902         ret = ctsvc_db_get_current_version(&contacts_db_version);
1903
1904 ERROR_RETURN:
1905         if (outdata) {
1906                 *outdata = pims_ipc_data_create(0);
1907                 if (NULL == *outdata) {
1908                         /* LCOV_EXCL_START */
1909                         ERR("pims_ipc_data_create() Fail");
1910                         goto DATA_FREE;
1911                         /* LCOV_EXCL_STOP */
1912                 }
1913                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1914                         /* LCOV_EXCL_START */
1915                         pims_ipc_data_destroy(*outdata);
1916                         *outdata = NULL;
1917                         ERR("ctsvc_ipc_marshal_int() Fail");
1918                         goto DATA_FREE;
1919                         /* LCOV_EXCL_STOP */
1920                 }
1921
1922                 if (CONTACTS_ERROR_NO_DATA == ret) {
1923                         DBG("no data");
1924                 } else if (CONTACTS_ERROR_NONE == ret) {
1925                         ret = ctsvc_ipc_marshal_int(contacts_db_version, *outdata);
1926                         if (ret != CONTACTS_ERROR_NONE) {
1927                                 /* LCOV_EXCL_START */
1928                                 ERR("ctsvc_ipc_marshal_int() Fail");
1929                                 goto DATA_FREE;
1930                                 /* LCOV_EXCL_STOP */
1931                         }
1932                 }
1933         } else {
1934                 /* LCOV_EXCL_START */
1935                 ERR("outdata is NULL");
1936                 /* LCOV_EXCL_STOP */
1937         }
1938
1939 DATA_FREE:
1940         ctsvc_handle_destroy(contact);
1941         ctsvc_server_start_timeout();
1942         return;
1943 }
1944
1945 void ctsvc_ipc_server_db_search_records_for_snippet(pims_ipc_h ipc,
1946                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
1947 {
1948         int ret = CONTACTS_ERROR_NONE;
1949         char *view_uri = NULL;
1950         char *keyword = NULL;
1951         int offset = 0;
1952         int limit = 0;
1953         contacts_list_h list = NULL;
1954         contacts_h contact = NULL;
1955         char *start_match = NULL;
1956         char *end_match = NULL;
1957         int token_number = 0;
1958
1959         if (indata) {
1960                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1961                 if (CONTACTS_ERROR_NONE != ret) {
1962                         /* LCOV_EXCL_START */
1963                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1964                         goto ERROR_RETURN;
1965                         /* LCOV_EXCL_STOP */
1966                 }
1967                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
1968                 if (ret != CONTACTS_ERROR_NONE) {
1969                         /* LCOV_EXCL_START */
1970                         ERR("ctsvc_ipc_unmarshal_record() Fail(%d)", ret);
1971                         goto ERROR_RETURN;
1972                         /* LCOV_EXCL_STOP */
1973                 }
1974                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
1975                 if (ret != CONTACTS_ERROR_NONE) {
1976                         /* LCOV_EXCL_START */
1977                         ERR("ctsvc_ipc_unmarshal_record() Fail(%d)", ret);
1978                         goto ERROR_RETURN;
1979                         /* LCOV_EXCL_STOP */
1980                 }
1981                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
1982                 if (ret != CONTACTS_ERROR_NONE) {
1983                         /* LCOV_EXCL_START */
1984                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
1985                         goto ERROR_RETURN;
1986                         /* LCOV_EXCL_STOP */
1987                 }
1988                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
1989                 if (ret != CONTACTS_ERROR_NONE) {
1990                         /* LCOV_EXCL_START */
1991                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
1992                         goto ERROR_RETURN;
1993                         /* LCOV_EXCL_STOP */
1994                 }
1995                 ret = ctsvc_ipc_unmarshal_string(indata, &start_match);
1996                 if (ret != CONTACTS_ERROR_NONE) {
1997                         /* LCOV_EXCL_START */
1998                         ERR("ctsvc_ipc_unmarshal_record() Fail");
1999                         goto ERROR_RETURN;
2000                         /* LCOV_EXCL_STOP */
2001                 }
2002                 ret = ctsvc_ipc_unmarshal_string(indata, &end_match);
2003                 if (ret != CONTACTS_ERROR_NONE) {
2004                         /* LCOV_EXCL_START */
2005                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2006                         goto ERROR_RETURN;
2007                         /* LCOV_EXCL_STOP */
2008                 }
2009                 ret = ctsvc_ipc_unmarshal_int(indata, &token_number);
2010                 if (ret != CONTACTS_ERROR_NONE) {
2011                         /* LCOV_EXCL_START */
2012                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2013                         goto ERROR_RETURN;
2014                         /* LCOV_EXCL_STOP */
2015                 }
2016         } else {
2017                 /* LCOV_EXCL_START */
2018                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2019                 goto ERROR_RETURN;
2020                 /* LCOV_EXCL_STOP */
2021         }
2022
2023         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
2024                 /* LCOV_EXCL_START */
2025                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2026                 goto ERROR_RETURN;
2027                 /* LCOV_EXCL_STOP */
2028         }
2029
2030         ret = ctsvc_db_search_records_for_snippet(view_uri, keyword, offset, limit,
2031                         start_match, end_match, token_number, &list);
2032
2033         if (outdata) {
2034                 *outdata = pims_ipc_data_create(0);
2035                 if (NULL == *outdata) {
2036                         /* LCOV_EXCL_START */
2037                         ERR("pims_ipc_data_create() Fail");
2038                         goto DATA_FREE;
2039                         /* LCOV_EXCL_STOP */
2040                 }
2041                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2042                         /* LCOV_EXCL_START */
2043                         pims_ipc_data_destroy(*outdata);
2044                         *outdata = NULL;
2045                         ERR("ctsvc_ipc_marshal_int() Fail");
2046                         goto DATA_FREE;
2047                         /* LCOV_EXCL_STOP */
2048                 }
2049
2050                 if (CONTACTS_ERROR_NO_DATA == ret) {
2051                         DBG("no data");
2052                 } else if (CONTACTS_ERROR_NONE == ret) {
2053                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2054
2055                         if (ret != CONTACTS_ERROR_NONE) {
2056                                 /* LCOV_EXCL_START */
2057                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
2058                                 goto DATA_FREE;
2059                                 /* LCOV_EXCL_STOP */
2060                         }
2061                 }
2062         } else {
2063                 /* LCOV_EXCL_START */
2064                 ERR("outdata is NULL");
2065                 /* LCOV_EXCL_STOP */
2066         }
2067         goto DATA_FREE;
2068
2069 ERROR_RETURN:
2070         if (outdata) {
2071                 *outdata = pims_ipc_data_create(0);
2072                 if (NULL == *outdata) {
2073                         /* LCOV_EXCL_START */
2074                         ERR("pims_ipc_data_create() Fail");
2075                         goto DATA_FREE;
2076                         /* LCOV_EXCL_STOP */
2077                 }
2078                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2079                         /* LCOV_EXCL_START */
2080                         pims_ipc_data_destroy(*outdata);
2081                         *outdata = NULL;
2082                         ERR("ctsvc_ipc_marshal_int() Fail");
2083                         goto DATA_FREE;
2084                         /* LCOV_EXCL_STOP */
2085                 }
2086         } else {
2087                 /* LCOV_EXCL_START */
2088                 ERR("outdata is NULL");
2089                 /* LCOV_EXCL_STOP */
2090         }
2091 DATA_FREE:
2092         ctsvc_handle_destroy(contact);
2093         contacts_list_destroy(list, true);
2094         free(view_uri);
2095         free(keyword);
2096         ctsvc_server_start_timeout();
2097         return;
2098 }
2099
2100 void ctsvc_ipc_server_db_search_records_with_range_for_snippet(pims_ipc_h ipc,
2101                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
2102 {
2103         int ret = CONTACTS_ERROR_NONE;
2104         char *view_uri = NULL;
2105         char *keyword = NULL;
2106         int offset = 0;
2107         int limit = 0;
2108         int range = 0;
2109         contacts_list_h list = NULL;
2110         contacts_h contact = NULL;
2111         char *start_match = NULL;
2112         char *end_match = NULL;
2113         int token_number = 0;
2114
2115         if (indata) {
2116                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2117                 if (CONTACTS_ERROR_NONE != ret) {
2118                         /* LCOV_EXCL_START */
2119                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2120                         goto ERROR_RETURN;
2121                         /* LCOV_EXCL_STOP */
2122                 }
2123                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
2124                 if (ret != CONTACTS_ERROR_NONE) {
2125                         /* LCOV_EXCL_START */
2126                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2127                         goto ERROR_RETURN;
2128                         /* LCOV_EXCL_STOP */
2129                 }
2130                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2131                 if (ret != CONTACTS_ERROR_NONE) {
2132                         /* LCOV_EXCL_START */
2133                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2134                         goto ERROR_RETURN;
2135                         /* LCOV_EXCL_STOP */
2136                 }
2137                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2138                 if (ret != CONTACTS_ERROR_NONE) {
2139                         /* LCOV_EXCL_START */
2140                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2141                         goto ERROR_RETURN;
2142                         /* LCOV_EXCL_STOP */
2143                 }
2144                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2145                 if (ret != CONTACTS_ERROR_NONE) {
2146                         /* LCOV_EXCL_START */
2147                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2148                         goto ERROR_RETURN;
2149                         /* LCOV_EXCL_STOP */
2150                 }
2151                 ret = ctsvc_ipc_unmarshal_int(indata, &range);
2152                 if (ret != CONTACTS_ERROR_NONE) {
2153                         /* LCOV_EXCL_START */
2154                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2155                         goto ERROR_RETURN;
2156                         /* LCOV_EXCL_STOP */
2157                 }
2158                 ret = ctsvc_ipc_unmarshal_string(indata, &start_match);
2159                 if (ret != CONTACTS_ERROR_NONE) {
2160                         /* LCOV_EXCL_START */
2161                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2162                         goto ERROR_RETURN;
2163                         /* LCOV_EXCL_STOP */
2164                 }
2165                 ret = ctsvc_ipc_unmarshal_string(indata, &end_match);
2166                 if (ret != CONTACTS_ERROR_NONE) {
2167                         /* LCOV_EXCL_START */
2168                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2169                         goto ERROR_RETURN;
2170                         /* LCOV_EXCL_STOP */
2171                 }
2172                 ret = ctsvc_ipc_unmarshal_int(indata, &token_number);
2173                 if (ret != CONTACTS_ERROR_NONE) {
2174                         /* LCOV_EXCL_START */
2175                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2176                         goto ERROR_RETURN;
2177                         /* LCOV_EXCL_STOP */
2178                 }
2179         } else {
2180                 /* LCOV_EXCL_START */
2181                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2182                 goto ERROR_RETURN;
2183                 /* LCOV_EXCL_START */
2184         }
2185
2186         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
2187                 /* LCOV_EXCL_START */
2188                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2189                 goto ERROR_RETURN;
2190                 /* LCOV_EXCL_STOP */
2191         }
2192
2193         ret = ctsvc_db_search_records_with_range_for_snippet(view_uri, keyword, offset,
2194                         limit, range, start_match, end_match, token_number, &list);
2195
2196         if (outdata) {
2197                 *outdata = pims_ipc_data_create(0);
2198                 if (NULL == *outdata) {
2199                         /* LCOV_EXCL_START */
2200                         ERR("pims_ipc_data_create() Fail");
2201                         goto DATA_FREE;
2202                         /* LCOV_EXCL_STOP */
2203                 }
2204                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2205                         /* LCOV_EXCL_START */
2206                         pims_ipc_data_destroy(*outdata);
2207                         *outdata = NULL;
2208                         ERR("ctsvc_ipc_marshal_int() Fail");
2209                         goto DATA_FREE;
2210                         /* LCOV_EXCL_STOP */
2211                 }
2212
2213                 if (CONTACTS_ERROR_NO_DATA == ret) {
2214                         DBG("no data");
2215                 } else if (CONTACTS_ERROR_NONE == ret) {
2216                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2217
2218                         if (ret != CONTACTS_ERROR_NONE) {
2219                                 /* LCOV_EXCL_START */
2220                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
2221                                 goto DATA_FREE;
2222                                 /* LCOV_EXCL_STOP */
2223                         }
2224                 }
2225         } else {
2226                 /* LCOV_EXCL_START */
2227                 ERR("outdata is NULL");
2228                 /* LCOV_EXCL_STOP */
2229         }
2230         goto DATA_FREE;
2231
2232 ERROR_RETURN:
2233         if (outdata) {
2234                 *outdata = pims_ipc_data_create(0);
2235                 if (NULL == *outdata) {
2236                         /* LCOV_EXCL_START */
2237                         ERR("pims_ipc_data_create() Fail");
2238                         goto DATA_FREE;
2239                         /* LCOV_EXCL_STOP */
2240                 }
2241                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2242                         /* LCOV_EXCL_START */
2243                         pims_ipc_data_destroy(*outdata);
2244                         *outdata = NULL;
2245                         ERR("ctsvc_ipc_marshal_int() Fail");
2246                         goto DATA_FREE;
2247                         /* LCOV_EXCL_STOP */
2248                 }
2249         } else {
2250                 /* LCOV_EXCL_START */
2251                 ERR("outdata is NULL");
2252                 /* LCOV_EXCL_STOP */
2253         }
2254
2255 DATA_FREE:
2256         ctsvc_handle_destroy(contact);
2257         contacts_list_destroy(list, true);
2258         free(view_uri);
2259         free(keyword);
2260         ctsvc_server_start_timeout();
2261         return;
2262 }
2263
2264 void ctsvc_ipc_server_db_search_records_with_query_for_snippet(pims_ipc_h ipc,
2265                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
2266 {
2267         int ret = CONTACTS_ERROR_NONE;
2268         contacts_query_h query = NULL;
2269         char *keyword = NULL;
2270         int offset = 0;
2271         int limit = 0;
2272         contacts_list_h list = NULL;
2273         contacts_h contact = NULL;
2274         char *start_match = NULL;
2275         char *end_match = NULL;
2276         int token_number = 0;
2277
2278         if (indata) {
2279                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2280                 if (CONTACTS_ERROR_NONE != ret) {
2281                         /* LCOV_EXCL_START */
2282                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2283                         goto ERROR_RETURN;
2284                         /* LCOV_EXCL_STOP */
2285                 }
2286                 ret = ctsvc_ipc_unmarshal_query(indata, &query);
2287                 if (ret != CONTACTS_ERROR_NONE) {
2288                         /* LCOV_EXCL_START */
2289                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2290                         goto ERROR_RETURN;
2291                         /* LCOV_EXCL_STOP */
2292                 }
2293                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2294                 if (ret != CONTACTS_ERROR_NONE) {
2295                         /* LCOV_EXCL_START */
2296                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2297                         goto ERROR_RETURN;
2298                         /* LCOV_EXCL_STOP */
2299                 }
2300                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2301                 if (ret != CONTACTS_ERROR_NONE) {
2302                         /* LCOV_EXCL_START */
2303                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2304                         goto ERROR_RETURN;
2305                         /* LCOV_EXCL_STOP */
2306                 }
2307                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2308                 if (ret != CONTACTS_ERROR_NONE) {
2309                         /* LCOV_EXCL_START */
2310                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2311                         goto ERROR_RETURN;
2312                         /* LCOV_EXCL_STOP */
2313                 }
2314                 ret = ctsvc_ipc_unmarshal_string(indata, &start_match);
2315                 if (ret != CONTACTS_ERROR_NONE) {
2316                         /* LCOV_EXCL_START */
2317                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2318                         goto ERROR_RETURN;
2319                         /* LCOV_EXCL_STOP */
2320                 }
2321                 ret = ctsvc_ipc_unmarshal_string(indata, &end_match);
2322                 if (ret != CONTACTS_ERROR_NONE) {
2323                         /* LCOV_EXCL_START */
2324                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2325                         goto ERROR_RETURN;
2326                         /* LCOV_EXCL_STOP */
2327                 }
2328                 ret = ctsvc_ipc_unmarshal_int(indata, &token_number);
2329                 if (ret != CONTACTS_ERROR_NONE) {
2330                         /* LCOV_EXCL_START */
2331                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2332                         goto ERROR_RETURN;
2333                         /* LCOV_EXCL_STOP */
2334                 }
2335         } else {
2336                 /* LCOV_EXCL_START */
2337                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2338                 goto ERROR_RETURN;
2339                 /* LCOV_EXCL_STOP */
2340         }
2341
2342         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(((ctsvc_query_s*)query)->view_uri))) {
2343                 /* LCOV_EXCL_START */
2344                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2345                 goto ERROR_RETURN;
2346                 /* LCOV_EXCL_STOP */
2347         }
2348
2349         ret = ctsvc_db_search_records_with_query_for_snippet(query, keyword, offset, limit,
2350                         start_match, end_match, token_number, &list);
2351
2352         if (outdata) {
2353                 *outdata = pims_ipc_data_create(0);
2354                 if (NULL == *outdata) {
2355                         /* LCOV_EXCL_START */
2356                         ERR("pims_ipc_data_create() Fail");
2357                         goto DATA_FREE;
2358                         /* LCOV_EXCL_STOP */
2359                 }
2360                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2361                         /* LCOV_EXCL_START */
2362                         pims_ipc_data_destroy(*outdata);
2363                         *outdata = NULL;
2364                         ERR("ctsvc_ipc_marshal_int() Fail");
2365                         goto DATA_FREE;
2366                         /* LCOV_EXCL_STOP */
2367                 }
2368
2369                 if (CONTACTS_ERROR_NO_DATA == ret) {
2370                         DBG("no data");
2371                 } else if (CONTACTS_ERROR_NONE == ret) {
2372                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2373
2374                         if (ret != CONTACTS_ERROR_NONE) {
2375                                 /* LCOV_EXCL_START */
2376                                 ERR("ctsvc_ipc_marshal_list Fail");
2377                                 goto DATA_FREE;
2378                                 /* LCOV_EXCL_STOP */
2379                         }
2380                 }
2381         } else {
2382                 /* LCOV_EXCL_START */
2383                 ERR("outdata is NULL");
2384                 /* LCOV_EXCL_STOP */
2385         }
2386         goto DATA_FREE;
2387
2388 ERROR_RETURN:
2389         if (outdata) {
2390                 *outdata = pims_ipc_data_create(0);
2391                 if (NULL == *outdata) {
2392                         /* LCOV_EXCL_START */
2393                         ERR("pims_ipc_data_create() Fail");
2394                         goto DATA_FREE;
2395                         /* LCOV_EXCL_STOP */
2396                 }
2397                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2398                         /* LCOV_EXCL_START */
2399                         pims_ipc_data_destroy(*outdata);
2400                         *outdata = NULL;
2401                         ERR("ctsvc_ipc_marshal_int() Fail");
2402                         goto DATA_FREE;
2403                         /* LCOV_EXCL_STOP */
2404                 }
2405         } else {
2406                 /* LCOV_EXCL_START */
2407                 ERR("outdata is NULL");
2408                 /* LCOV_EXCL_STOP */
2409         }
2410 DATA_FREE:
2411         ctsvc_handle_destroy(contact);
2412         contacts_list_destroy(list, true);
2413         contacts_query_destroy(query);
2414         free(keyword);
2415         ctsvc_server_start_timeout();
2416         return;
2417 }
2418
2419 void ctsvc_ipc_server_db_search_records(pims_ipc_h ipc, pims_ipc_data_h indata,
2420                 pims_ipc_data_h *outdata, void *userdata)
2421 {
2422         int ret = CONTACTS_ERROR_NONE;
2423         char *view_uri = NULL;
2424         char *keyword = NULL;
2425         int offset = 0;
2426         int limit = 0;
2427         contacts_list_h list = NULL;
2428         contacts_h contact = NULL;
2429
2430         if (indata) {
2431                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2432                 if (CONTACTS_ERROR_NONE != ret) {
2433                         /* LCOV_EXCL_START */
2434                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2435                         goto ERROR_RETURN;
2436                         /* LCOV_EXCL_STOP */
2437                 }
2438                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
2439                 if (ret != CONTACTS_ERROR_NONE) {
2440                         /* LCOV_EXCL_START */
2441                         ERR("ctsvc_ipc_unmarshal_record() Fail(%d)", ret);
2442                         goto ERROR_RETURN;
2443                         /* LCOV_EXCL_STOP */
2444                 }
2445                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2446                 if (ret != CONTACTS_ERROR_NONE) {
2447                         /* LCOV_EXCL_START */
2448                         ERR("ctsvc_ipc_unmarshal_record() Fail(%d)", ret);
2449                         goto ERROR_RETURN;
2450                         /* LCOV_EXCL_STOP */
2451                 }
2452                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2453                 if (ret != CONTACTS_ERROR_NONE) {
2454                         /* LCOV_EXCL_START */
2455                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2456                         goto ERROR_RETURN;
2457                         /* LCOV_EXCL_STOP */
2458                 }
2459                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2460                 if (ret != CONTACTS_ERROR_NONE) {
2461                         /* LCOV_EXCL_START */
2462                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2463                         goto ERROR_RETURN;
2464                         /* LCOV_EXCL_STOP */
2465                 }
2466         } else {
2467                 /* LCOV_EXCL_START */
2468                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2469                 goto ERROR_RETURN;
2470                 /* LCOV_EXCL_STOP */
2471         }
2472
2473         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
2474                 /* LCOV_EXCL_START */
2475                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2476                 goto ERROR_RETURN;
2477                 /* LCOV_EXCL_STOP */
2478         }
2479
2480         ret = ctsvc_db_search_records(view_uri, keyword, offset, limit, &list);
2481
2482         if (outdata) {
2483                 *outdata = pims_ipc_data_create(0);
2484                 if (NULL == *outdata) {
2485                         /* LCOV_EXCL_START */
2486                         ERR("pims_ipc_data_create() Fail");
2487                         goto DATA_FREE;
2488                         /* LCOV_EXCL_STOP */
2489                 }
2490                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2491                         /* LCOV_EXCL_START */
2492                         pims_ipc_data_destroy(*outdata);
2493                         *outdata = NULL;
2494                         ERR("ctsvc_ipc_marshal_int() Fail");
2495                         goto DATA_FREE;
2496                         /* LCOV_EXCL_STOP */
2497                 }
2498
2499                 if (CONTACTS_ERROR_NO_DATA == ret) {
2500                         DBG("no data");
2501                 } else if (CONTACTS_ERROR_NONE == ret) {
2502                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2503
2504                         if (ret != CONTACTS_ERROR_NONE) {
2505                                 /* LCOV_EXCL_START */
2506                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
2507                                 goto DATA_FREE;
2508                                 /* LCOV_EXCL_STOP */
2509                         }
2510                 }
2511         } else {
2512                 /* LCOV_EXCL_START */
2513                 ERR("outdata is NULL");
2514                 /* LCOV_EXCL_STOP */
2515         }
2516         goto DATA_FREE;
2517
2518 ERROR_RETURN:
2519         if (outdata) {
2520                 *outdata = pims_ipc_data_create(0);
2521                 if (NULL == *outdata) {
2522                         /* LCOV_EXCL_START */
2523                         ERR("pims_ipc_data_create() Fail");
2524                         goto DATA_FREE;
2525                         /* LCOV_EXCL_STOP */
2526                 }
2527                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2528                         /* LCOV_EXCL_START */
2529                         pims_ipc_data_destroy(*outdata);
2530                         *outdata = NULL;
2531                         ERR("ctsvc_ipc_marshal_int() Fail");
2532                         goto DATA_FREE;
2533                         /* LCOV_EXCL_STOP */
2534                 }
2535         } else {
2536                 /* LCOV_EXCL_START */
2537                 ERR("outdata is NULL");
2538                 /* LCOV_EXCL_STOP */
2539         }
2540 DATA_FREE:
2541         ctsvc_handle_destroy(contact);
2542         contacts_list_destroy(list, true);
2543         free(view_uri);
2544         free(keyword);
2545         ctsvc_server_start_timeout();
2546         return;
2547 }
2548
2549 void ctsvc_ipc_server_db_search_records_with_range(pims_ipc_h ipc,
2550                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
2551 {
2552         int ret = CONTACTS_ERROR_NONE;
2553         char *view_uri = NULL;
2554         char *keyword = NULL;
2555         int offset = 0;
2556         int limit = 0;
2557         int range = 0;
2558         contacts_list_h list = NULL;
2559         contacts_h contact = NULL;
2560
2561         if (indata) {
2562                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2563                 if (CONTACTS_ERROR_NONE != ret) {
2564                         /* LCOV_EXCL_START */
2565                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2566                         goto ERROR_RETURN;
2567                         /* LCOV_EXCL_STOP */
2568                 }
2569                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
2570                 if (ret != CONTACTS_ERROR_NONE) {
2571                         /* LCOV_EXCL_START */
2572                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2573                         goto ERROR_RETURN;
2574                         /* LCOV_EXCL_STOP */
2575                 }
2576                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2577                 if (ret != CONTACTS_ERROR_NONE) {
2578                         /* LCOV_EXCL_START */
2579                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2580                         goto ERROR_RETURN;
2581                         /* LCOV_EXCL_STOP */
2582                 }
2583                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2584                 if (ret != CONTACTS_ERROR_NONE) {
2585                         /* LCOV_EXCL_START */
2586                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2587                         goto ERROR_RETURN;
2588                         /* LCOV_EXCL_STOP */
2589                 }
2590                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2591                 if (ret != CONTACTS_ERROR_NONE) {
2592                         /* LCOV_EXCL_START */
2593                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2594                         goto ERROR_RETURN;
2595                         /* LCOV_EXCL_STOP */
2596                 }
2597                 ret = ctsvc_ipc_unmarshal_int(indata, &range);
2598                 if (ret != CONTACTS_ERROR_NONE) {
2599                         /* LCOV_EXCL_START */
2600                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2601                         goto ERROR_RETURN;
2602                         /* LCOV_EXCL_STOP */
2603                 }
2604         } else {
2605                 /* LCOV_EXCL_START */
2606                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2607                 goto ERROR_RETURN;
2608                 /* LCOV_EXCL_STOP */
2609         }
2610
2611         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
2612                 /* LCOV_EXCL_START */
2613                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2614                 goto ERROR_RETURN;
2615                 /* LCOV_EXCL_STOP */
2616         }
2617
2618         ret = ctsvc_db_search_records_with_range(view_uri, keyword, offset, limit, range,
2619                         &list);
2620
2621         if (outdata) {
2622                 *outdata = pims_ipc_data_create(0);
2623                 if (NULL == *outdata) {
2624                         /* LCOV_EXCL_START */
2625                         ERR("pims_ipc_data_create() Fail");
2626                         goto DATA_FREE;
2627                         /* LCOV_EXCL_STOP */
2628                 }
2629                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2630                         /* LCOV_EXCL_START */
2631                         pims_ipc_data_destroy(*outdata);
2632                         *outdata = NULL;
2633                         ERR("ctsvc_ipc_marshal_int() Fail");
2634                         goto DATA_FREE;
2635                         /* LCOV_EXCL_STOP */
2636                 }
2637
2638                 if (CONTACTS_ERROR_NO_DATA == ret) {
2639                         DBG("no data");
2640                 } else if (CONTACTS_ERROR_NONE == ret) {
2641                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2642
2643                         if (ret != CONTACTS_ERROR_NONE) {
2644                                 /* LCOV_EXCL_START */
2645                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
2646                                 goto DATA_FREE;
2647                                 /* LCOV_EXCL_STOP */
2648                         }
2649                 }
2650         } else {
2651                 /* LCOV_EXCL_START */
2652                 ERR("outdata is NULL");
2653                 /* LCOV_EXCL_STOP */
2654         }
2655         goto DATA_FREE;
2656
2657 ERROR_RETURN:
2658         if (outdata) {
2659                 *outdata = pims_ipc_data_create(0);
2660                 if (NULL == *outdata) {
2661                         /* LCOV_EXCL_START */
2662                         ERR("pims_ipc_data_create() Fail");
2663                         goto DATA_FREE;
2664                         /* LCOV_EXCL_STOP */
2665                 }
2666                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2667                         /* LCOV_EXCL_START */
2668                         pims_ipc_data_destroy(*outdata);
2669                         *outdata = NULL;
2670                         ERR("ctsvc_ipc_marshal_int() Fail");
2671                         goto DATA_FREE;
2672                         /* LCOV_EXCL_STOP */
2673                 }
2674         } else {
2675                 /* LCOV_EXCL_START */
2676                 ERR("outdata is NULL");
2677                 /* LCOV_EXCL_STOP */
2678         }
2679
2680 DATA_FREE:
2681         ctsvc_handle_destroy(contact);
2682         contacts_list_destroy(list, true);
2683         free(view_uri);
2684         free(keyword);
2685         ctsvc_server_start_timeout();
2686         return;
2687 }
2688
2689 void ctsvc_ipc_server_db_search_records_with_query(pims_ipc_h ipc,
2690                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
2691 {
2692         int ret = CONTACTS_ERROR_NONE;
2693         contacts_query_h query = NULL;
2694         char *keyword = NULL;
2695         int offset = 0;
2696         int limit = 0;
2697         contacts_list_h list = NULL;
2698         contacts_h contact = NULL;
2699
2700         if (indata) {
2701                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2702                 if (CONTACTS_ERROR_NONE != ret) {
2703                         /* LCOV_EXCL_START */
2704                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2705                         goto ERROR_RETURN;
2706                         /* LCOV_EXCL_STOP */
2707                 }
2708                 ret = ctsvc_ipc_unmarshal_query(indata, &query);
2709                 if (ret != CONTACTS_ERROR_NONE) {
2710                         /* LCOV_EXCL_START */
2711                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2712                         goto ERROR_RETURN;
2713                         /* LCOV_EXCL_STOP */
2714                 }
2715                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2716                 if (ret != CONTACTS_ERROR_NONE) {
2717                         /* LCOV_EXCL_START */
2718                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2719                         goto ERROR_RETURN;
2720                         /* LCOV_EXCL_STOP */
2721                 }
2722                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2723                 if (ret != CONTACTS_ERROR_NONE) {
2724                         /* LCOV_EXCL_START */
2725                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2726                         goto ERROR_RETURN;
2727                         /* LCOV_EXCL_STOP */
2728                 }
2729                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2730                 if (ret != CONTACTS_ERROR_NONE) {
2731                         /* LCOV_EXCL_START */
2732                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2733                         goto ERROR_RETURN;
2734                         /* LCOV_EXCL_STOP */
2735                 }
2736         } else {
2737                 /* LCOV_EXCL_START */
2738                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2739                 goto ERROR_RETURN;
2740                 /* LCOV_EXCL_STOP */
2741         }
2742
2743
2744         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(((ctsvc_query_s*)query)->view_uri))) {
2745                 /* LCOV_EXCL_START */
2746                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2747                 goto ERROR_RETURN;
2748                 /* LCOV_EXCL_STOP */
2749         }
2750
2751
2752         ret = ctsvc_db_search_records_with_query(query, keyword, offset, limit, &list);
2753
2754         if (outdata) {
2755                 *outdata = pims_ipc_data_create(0);
2756                 if (NULL == *outdata) {
2757                         /* LCOV_EXCL_START */
2758                         ERR("pims_ipc_data_create() Fail");
2759                         goto DATA_FREE;
2760                         /* LCOV_EXCL_STOP */
2761                 }
2762                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2763                         /* LCOV_EXCL_START */
2764                         pims_ipc_data_destroy(*outdata);
2765                         *outdata = NULL;
2766                         ERR("ctsvc_ipc_marshal_int() Fail");
2767                         goto DATA_FREE;
2768                         /* LCOV_EXCL_STOP */
2769                 }
2770
2771                 if (CONTACTS_ERROR_NO_DATA == ret) {
2772                         DBG("no data");
2773                 } else if (CONTACTS_ERROR_NONE == ret) {
2774                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2775
2776                         if (ret != CONTACTS_ERROR_NONE) {
2777                                 /* LCOV_EXCL_START */
2778                                 ERR("ctsvc_ipc_marshal_list Fail");
2779                                 goto DATA_FREE;
2780                                 /* LCOV_EXCL_STOP */
2781                         }
2782                 }
2783         } else {
2784                 /* LCOV_EXCL_START */
2785                 ERR("outdata is NULL");
2786                 /* LCOV_EXCL_STOP */
2787         }
2788         goto DATA_FREE;
2789
2790 ERROR_RETURN:
2791         if (outdata) {
2792                 *outdata = pims_ipc_data_create(0);
2793                 if (NULL == *outdata) {
2794                         /* LCOV_EXCL_START */
2795                         ERR("pims_ipc_data_create() Fail");
2796                         goto DATA_FREE;
2797                         /* LCOV_EXCL_STOP */
2798                 }
2799                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2800                         /* LCOV_EXCL_START */
2801                         pims_ipc_data_destroy(*outdata);
2802                         *outdata = NULL;
2803                         ERR("ctsvc_ipc_marshal_int() Fail");
2804                         goto DATA_FREE;
2805                         /* LCOV_EXCL_STOP */
2806                 }
2807         } else {
2808                 /* LCOV_EXCL_START */
2809                 ERR("outdata is NULL");
2810                 /* LCOV_EXCL_STOP */
2811         }
2812 DATA_FREE:
2813         ctsvc_handle_destroy(contact);
2814         contacts_list_destroy(list, true);
2815         contacts_query_destroy(query);
2816         free(keyword);
2817         ctsvc_server_start_timeout();
2818         return;
2819 }
2820
2821 void ctsvc_ipc_server_db_get_status(pims_ipc_h ipc, pims_ipc_data_h indata,
2822                 pims_ipc_data_h *outdata, void *userdata)
2823 {
2824         int ret = CONTACTS_ERROR_NONE;
2825         contacts_db_status_e status = CONTACTS_DB_STATUS_NORMAL;
2826         contacts_h contact = NULL;
2827
2828         if (indata) {
2829                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2830                 if (CONTACTS_ERROR_NONE != ret) {
2831                         /* LCOV_EXCL_START */
2832                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2833                         goto ERROR_RETURN;
2834                         /* LCOV_EXCL_STOP */
2835                 }
2836         }
2837
2838         ret = ctsvc_db_get_status(&status);
2839
2840 ERROR_RETURN:
2841         if (outdata) {
2842                 *outdata = pims_ipc_data_create(0);
2843                 if (NULL == *outdata) {
2844                         /* LCOV_EXCL_START */
2845                         ERR("pims_ipc_data_create() Fail");
2846                         goto DATA_FREE;
2847                         /* LCOV_EXCL_STOP */
2848                 }
2849
2850                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2851                         /* LCOV_EXCL_START */
2852                         pims_ipc_data_destroy(*outdata);
2853                         *outdata = NULL;
2854                         ERR("ctsvc_ipc_marshal_int() Fail");
2855                         goto DATA_FREE;
2856                         /* LCOV_EXCL_STOP */
2857                 }
2858
2859                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(status, *outdata)) {
2860                         /* LCOV_EXCL_START */
2861                         pims_ipc_data_destroy(*outdata);
2862                         *outdata = NULL;
2863                         ERR("ctsvc_ipc_marshal_int() Fail");
2864                         goto DATA_FREE;
2865                         /* LCOV_EXCL_STOP */
2866                 }
2867         } else {
2868                 /* LCOV_EXCL_START */
2869                 ERR("outdata is NULL");
2870                 /* LCOV_EXCL_STOP */
2871         }
2872 DATA_FREE:
2873         ctsvc_handle_destroy(contact);
2874         ctsvc_server_start_timeout();
2875         return;
2876 }
2877