Modify image-util deprecated APIs
[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         ret = ctsvc_db_insert_records(list, &ids, &id_count);
1247
1248         if (outdata) {
1249                 *outdata = pims_ipc_data_create(0);
1250                 if (NULL == *outdata) {
1251                         /* LCOV_EXCL_START */
1252                         ERR("pims_ipc_data_create() Fail");
1253                         goto DATA_FREE;
1254                         /* LCOV_EXCL_STOP */
1255                 }
1256                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1257                         /* LCOV_EXCL_START */
1258                         pims_ipc_data_destroy(*outdata);
1259                         *outdata = NULL;
1260                         ERR("ctsvc_ipc_marshal_int() Fail");
1261                         goto DATA_FREE;
1262                         /* LCOV_EXCL_STOP */
1263                 }
1264
1265                 if (ret == CONTACTS_ERROR_NONE) {
1266                         int transaction_ver = ctsvc_get_transaction_ver();
1267                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
1268                                 /* LCOV_EXCL_START */
1269                                 pims_ipc_data_destroy(*outdata);
1270                                 *outdata = NULL;
1271                                 ERR("ctsvc_ipc_marshal_int() Fail");
1272                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1273                                 goto ERROR_RETURN;
1274                                 /* LCOV_EXCL_STOP */
1275                         }
1276                         /* marshal : id_count+property_id+[ids]*id_count */
1277                         /* id_count */
1278                         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(id_count, *outdata)) {
1279                                 /* LCOV_EXCL_START */
1280                                 pims_ipc_data_destroy(*outdata);
1281                                 *outdata = NULL;
1282                                 ERR("ctsvc_ipc_marshal_int() Fail");
1283                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1284                                 goto ERROR_RETURN;
1285                                 /* LCOV_EXCL_STOP */
1286                         }
1287
1288                         for (i = 0; i < id_count; i++) {
1289                                 /* marshal ids */
1290                                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ids[i], *outdata)) {
1291                                         /* LCOV_EXCL_START */
1292                                         pims_ipc_data_destroy(*outdata);
1293                                         *outdata = NULL;
1294                                         ERR("ctsvc_ipc_marshal_int() Fail");
1295                                         ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1296                                         goto ERROR_RETURN;
1297                                         /* LCOV_EXCL_STOP */
1298                                 }
1299                         }
1300                 }
1301         } else {
1302                 /* LCOV_EXCL_START */
1303                 ERR("outdata is NULL");
1304                 /* LCOV_EXCL_STOP */
1305         }
1306         goto DATA_FREE;
1307
1308 ERROR_RETURN:
1309         if (outdata) {
1310                 *outdata = pims_ipc_data_create(0);
1311                 if (NULL == *outdata) {
1312                         /* LCOV_EXCL_START */
1313                         ERR("pims_ipc_data_create() Fail");
1314                         goto DATA_FREE;
1315                         /* LCOV_EXCL_STOP */
1316                 }
1317                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1318                         /* LCOV_EXCL_START */
1319                         pims_ipc_data_destroy(*outdata);
1320                         *outdata = NULL;
1321                         ERR("ctsvc_ipc_marshal_int() Fail");
1322                         goto DATA_FREE;
1323                         /* LCOV_EXCL_STOP */
1324                 }
1325         } else {
1326                 /* LCOV_EXCL_START */
1327                 ERR("outdata is NULL");
1328                 /* LCOV_EXCL_STOP */
1329         }
1330 DATA_FREE:
1331         ctsvc_handle_destroy(contact);
1332         contacts_list_destroy(list, true);
1333         free(ids);
1334         ctsvc_server_start_timeout();
1335         return;
1336 }
1337
1338 void ctsvc_ipc_server_db_update_records(pims_ipc_h ipc, pims_ipc_data_h indata,
1339                 pims_ipc_data_h *outdata, void *userdata)
1340 {
1341         int ret = CONTACTS_ERROR_NONE;
1342         contacts_list_h list = NULL;
1343         contacts_h contact = NULL;
1344
1345         if (indata) {
1346                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1347                 if (CONTACTS_ERROR_NONE != ret) {
1348                         /* LCOV_EXCL_START */
1349                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1350                         goto ERROR_RETURN;
1351                         /* LCOV_EXCL_STOP */
1352                 }
1353
1354                 ret = ctsvc_ipc_unmarshal_list(indata, &list);
1355                 if (ret != CONTACTS_ERROR_NONE) {
1356                         /* LCOV_EXCL_START */
1357                         ERR("ctsvc_ipc_unmarshal_list Fail");
1358                         goto ERROR_RETURN;
1359                         /* LCOV_EXCL_STOP */
1360                 }
1361         } else {
1362                 /* LCOV_EXCL_START */
1363                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
1364                 goto ERROR_RETURN;
1365                 /* LCOV_EXCL_STOP */
1366         }
1367
1368         if (list) {
1369                 contacts_record_h record = NULL;
1370                 contacts_list_first(list);
1371                 do {
1372                         ret = contacts_list_get_current_record_p(list, &record);
1373                         if (CONTACTS_ERROR_NONE != ret) {
1374                                 /* LCOV_EXCL_START */
1375                                 ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
1376                                 goto ERROR_RETURN;
1377                                 /* LCOV_EXCL_STOP */
1378                         }
1379
1380                         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(((ctsvc_record_s*)record)->view_uri))) {
1381                                 /* LCOV_EXCL_START */
1382                                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1383                                 goto ERROR_RETURN;
1384                                 /* LCOV_EXCL_STOP */
1385                         }
1386                 } while (CONTACTS_ERROR_NONE == contacts_list_next(list));
1387                 contacts_list_first(list);
1388         }
1389
1390         ret = ctsvc_db_update_records(list);
1391
1392         if (outdata) {
1393                 *outdata = pims_ipc_data_create(0);
1394                 if (NULL == *outdata) {
1395                         /* LCOV_EXCL_START */
1396                         ERR("pims_ipc_data_create() Fail");
1397                         goto DATA_FREE;
1398                         /* LCOV_EXCL_STOP */
1399                 }
1400                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1401                         /* LCOV_EXCL_START */
1402                         pims_ipc_data_destroy(*outdata);
1403                         *outdata = NULL;
1404                         ERR("ctsvc_ipc_marshal_int() Fail");
1405                         goto DATA_FREE;
1406                         /* LCOV_EXCL_STOP */
1407                 }
1408
1409                 if (ret == CONTACTS_ERROR_NONE) {
1410                         int transaction_ver = ctsvc_get_transaction_ver();
1411                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
1412                                 /* LCOV_EXCL_START */
1413                                 pims_ipc_data_destroy(*outdata);
1414                                 *outdata = NULL;
1415                                 ERR("ctsvc_ipc_marshal_int() Fail");
1416                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1417                                 goto ERROR_RETURN;
1418                                 /* LCOV_EXCL_STOP */
1419                         }
1420                 }
1421         } else {
1422                 /* LCOV_EXCL_START */
1423                 ERR("outdata is NULL");
1424                 /* LCOV_EXCL_STOP */
1425         }
1426         goto DATA_FREE;
1427
1428 ERROR_RETURN:
1429         if (outdata) {
1430                 *outdata = pims_ipc_data_create(0);
1431                 if (NULL == *outdata) {
1432                         /* LCOV_EXCL_START */
1433                         ERR("pims_ipc_data_create() Fail");
1434                         goto DATA_FREE;
1435                         /* LCOV_EXCL_STOP */
1436                 }
1437                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1438                         /* LCOV_EXCL_START */
1439                         pims_ipc_data_destroy(*outdata);
1440                         *outdata = NULL;
1441                         ERR("ctsvc_ipc_marshal_int() Fail");
1442                         goto DATA_FREE;
1443                         /* LCOV_EXCL_STOP */
1444                 }
1445         } else {
1446                 /* LCOV_EXCL_START */
1447                 ERR("outdata is NULL");
1448                 /* LCOV_EXCL_STOP */
1449         }
1450 DATA_FREE:
1451         ctsvc_handle_destroy(contact);
1452         contacts_list_destroy(list, true);
1453         ctsvc_server_start_timeout();
1454         return;
1455 }
1456
1457 void ctsvc_ipc_server_db_delete_records(pims_ipc_h ipc, pims_ipc_data_h indata,
1458                 pims_ipc_data_h *outdata, void *userdata)
1459 {
1460         int ret = CONTACTS_ERROR_NONE;
1461         int count = 0;
1462         int *ids = NULL;
1463         char *uri = NULL;
1464         int i = 0;
1465         contacts_h contact = NULL;
1466
1467         if (indata) {
1468                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1469                 if (CONTACTS_ERROR_NONE != ret) {
1470                         /* LCOV_EXCL_START */
1471                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1472                         goto ERROR_RETURN;
1473                         /* LCOV_EXCL_STOP */
1474                 }
1475
1476                 ret = ctsvc_ipc_unmarshal_string(indata, &uri);
1477                 if (ret != CONTACTS_ERROR_NONE) {
1478                         /* LCOV_EXCL_START */
1479                         ERR("ctsvc_ipc_unmarshal_string Fail");
1480                         goto ERROR_RETURN;
1481                         /* LCOV_EXCL_STOP */
1482                 }
1483                 ret = ctsvc_ipc_unmarshal_int(indata, &count);
1484                 if (ret != CONTACTS_ERROR_NONE) {
1485                         /* LCOV_EXCL_START */
1486                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1487                         goto ERROR_RETURN;
1488                         /* LCOV_EXCL_STOP */
1489                 }
1490                 if (count <= 0) {
1491                         /* LCOV_EXCL_START */
1492                         ret = CONTACTS_ERROR_INVALID_PARAMETER;
1493                         goto ERROR_RETURN;
1494                         /* LCOV_EXCL_STOP */
1495                 }
1496                 ids = (int*)malloc(sizeof(int)*count);
1497                 for (i = 0; i < count; i++) {
1498                         ret = ctsvc_ipc_unmarshal_int(indata, &ids[i]);
1499                         if (ret != CONTACTS_ERROR_NONE) {
1500                                 /* LCOV_EXCL_START */
1501                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
1502                                 goto ERROR_RETURN;
1503                                 /* LCOV_EXCL_STOP */
1504                         }
1505                 }
1506         } else {
1507                 /* LCOV_EXCL_START */
1508                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
1509                 goto ERROR_RETURN;
1510                 /* LCOV_EXCL_STOP */
1511         }
1512
1513         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(uri))) {
1514                 /* LCOV_EXCL_START */
1515                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1516                 goto ERROR_RETURN;
1517                 /* LCOV_EXCL_STOP */
1518         }
1519
1520         ret = ctsvc_db_delete_records(uri, ids, count);
1521
1522         if (outdata) {
1523                 *outdata = pims_ipc_data_create(0);
1524                 if (NULL == *outdata) {
1525                         /* LCOV_EXCL_START */
1526                         ERR("pims_ipc_data_create() Fail");
1527                         goto DATA_FREE;
1528                         /* LCOV_EXCL_STOP */
1529                 }
1530
1531                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1532                         /* LCOV_EXCL_START */
1533                         pims_ipc_data_destroy(*outdata);
1534                         *outdata = NULL;
1535                         ERR("ctsvc_ipc_marshal_int() Fail");
1536                         goto DATA_FREE;
1537                         /* LCOV_EXCL_STOP */
1538                 }
1539
1540                 if (ret == CONTACTS_ERROR_NONE) {
1541                         int transaction_ver = ctsvc_get_transaction_ver();
1542                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
1543                                 /* LCOV_EXCL_START */
1544                                 pims_ipc_data_destroy(*outdata);
1545                                 *outdata = NULL;
1546                                 ERR("ctsvc_ipc_marshal_int() Fail");
1547                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1548                                 goto ERROR_RETURN;
1549                                 /* LCOV_EXCL_STOP */
1550                         }
1551                 }
1552         } else {
1553                 /* LCOV_EXCL_START */
1554                 ERR("outdata is NULL");
1555                 /* LCOV_EXCL_STOP */
1556         }
1557
1558         goto DATA_FREE;
1559
1560 ERROR_RETURN:
1561         if (outdata) {
1562                 *outdata = pims_ipc_data_create(0);
1563                 if (NULL == *outdata) {
1564                         /* LCOV_EXCL_START */
1565                         ERR("pims_ipc_data_create() Fail");
1566                         goto DATA_FREE;
1567                         /* LCOV_EXCL_STOP */
1568                 }
1569                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1570                         /* LCOV_EXCL_START */
1571                         pims_ipc_data_destroy(*outdata);
1572                         *outdata = NULL;
1573                         ERR("ctsvc_ipc_marshal_int() Fail");
1574                         goto DATA_FREE;
1575                         /* LCOV_EXCL_STOP */
1576                 }
1577         } else {
1578                 /* LCOV_EXCL_START */
1579                 ERR("outdata is NULL");
1580                 /* LCOV_EXCL_STOP */
1581         }
1582 DATA_FREE:
1583         ctsvc_handle_destroy(contact);
1584         free(uri);
1585         free(ids);
1586         ctsvc_server_start_timeout();
1587         return;
1588 }
1589
1590 void ctsvc_ipc_server_db_replace_records(pims_ipc_h ipc, pims_ipc_data_h indata,
1591                 pims_ipc_data_h *outdata, void *userdata)
1592 {
1593         int ret = CONTACTS_ERROR_NONE;
1594         contacts_list_h list = NULL;
1595         int count = 0;
1596         int *ids = NULL;
1597         int i = 0;
1598         contacts_h contact = NULL;
1599
1600         if (indata) {
1601                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1602                 if (CONTACTS_ERROR_NONE != ret) {
1603                         /* LCOV_EXCL_START */
1604                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1605                         goto ERROR_RETURN;
1606                         /* LCOV_EXCL_STOP */
1607                 }
1608
1609                 ret = ctsvc_ipc_unmarshal_list(indata, &list);
1610                 if (ret != CONTACTS_ERROR_NONE) {
1611                         /* LCOV_EXCL_START */
1612                         ERR("ctsvc_ipc_unmarshal_list Fail");
1613                         goto ERROR_RETURN;
1614                         /* LCOV_EXCL_STOP */
1615                 }
1616
1617                 ret = ctsvc_ipc_unmarshal_int(indata, &count);
1618                 if (ret != CONTACTS_ERROR_NONE) {
1619                         /* LCOV_EXCL_START */
1620                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1621                         goto ERROR_RETURN;
1622                         /* LCOV_EXCL_STOP */
1623                 }
1624
1625                 if (count <= 0) {
1626                         /* LCOV_EXCL_START */
1627                         ret = CONTACTS_ERROR_INVALID_PARAMETER;
1628                         goto ERROR_RETURN;
1629                         /* LCOV_EXCL_STOP */
1630                 }
1631
1632                 ids = (int*)malloc(sizeof(int)*count);
1633                 for (i = 0; i < count; i++) {
1634                         ret = ctsvc_ipc_unmarshal_int(indata, &ids[i]);
1635                         if (ret != CONTACTS_ERROR_NONE) {
1636                                 /* LCOV_EXCL_START */
1637                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
1638                                 goto ERROR_RETURN;
1639                                 /* LCOV_EXCL_STOP */
1640                         }
1641                 }
1642         } else {
1643                 /* LCOV_EXCL_START */
1644                 ERR("ctsvc_ipc_server_db_repalce_records Fail");
1645                 goto ERROR_RETURN;
1646                 /* LCOV_EXCL_STOP */
1647         }
1648
1649         if (list) {
1650                 contacts_record_h record = NULL;
1651                 contacts_list_first(list);
1652                 do {
1653                         ret = contacts_list_get_current_record_p(list, &record);
1654                         if (CONTACTS_ERROR_NONE != ret) {
1655                                 /* LCOV_EXCL_START */
1656                                 ERR("contacts_list_get_current_record_p() Fail(%d)", ret);
1657                                 goto ERROR_RETURN;
1658                                 /* LCOV_EXCL_STOP */
1659                         }
1660
1661                         if (!ctsvc_have_permission(ipc, ctsvc_required_write_permission(((ctsvc_record_s*)record)->view_uri))) {
1662                                 /* LCOV_EXCL_START */
1663                                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1664                                 goto ERROR_RETURN;
1665                                 /* LCOV_EXCL_STOP */
1666                         }
1667                 } while (CONTACTS_ERROR_NONE == contacts_list_next(list));
1668                 contacts_list_first(list);
1669         }
1670
1671         ret = ctsvc_db_replace_records(list, ids, count);
1672
1673         if (outdata) {
1674                 *outdata = pims_ipc_data_create(0);
1675                 if (NULL == *outdata) {
1676                         /* LCOV_EXCL_START */
1677                         ERR("pims_ipc_data_create() Fail");
1678                         goto DATA_FREE;
1679                         /* LCOV_EXCL_STOP */
1680                 }
1681                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1682                         /* LCOV_EXCL_START */
1683                         pims_ipc_data_destroy(*outdata);
1684                         *outdata = NULL;
1685                         ERR("ctsvc_ipc_marshal_int() Fail");
1686                         goto DATA_FREE;
1687                         /* LCOV_EXCL_STOP */
1688                 }
1689                 if (ret == CONTACTS_ERROR_NONE) {
1690                         int transaction_ver = ctsvc_get_transaction_ver();
1691                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
1692                                 /* LCOV_EXCL_START */
1693                                 pims_ipc_data_destroy(*outdata);
1694                                 *outdata = NULL;
1695                                 ERR("ctsvc_ipc_marshal_int() Fail");
1696                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1697                                 goto ERROR_RETURN;
1698                                 /* LCOV_EXCL_STOP */
1699                         }
1700                 }
1701         } else {
1702                 /* LCOV_EXCL_START */
1703                 ERR("outdata is NULL");
1704                 /* LCOV_EXCL_STOP */
1705         }
1706         goto DATA_FREE;
1707
1708 ERROR_RETURN:
1709         if (outdata) {
1710                 *outdata = pims_ipc_data_create(0);
1711                 if (NULL == *outdata) {
1712                         /* LCOV_EXCL_START */
1713                         ERR("pims_ipc_data_create() Fail");
1714                         goto DATA_FREE;
1715                         /* LCOV_EXCL_STOP */
1716                 }
1717                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1718                         /* LCOV_EXCL_START */
1719                         pims_ipc_data_destroy(*outdata);
1720                         *outdata = NULL;
1721                         ERR("ctsvc_ipc_marshal_int() Fail");
1722                         goto DATA_FREE;
1723                         /* LCOV_EXCL_STOP */
1724                 }
1725         } else {
1726                 /* LCOV_EXCL_START */
1727                 ERR("outdata is NULL");
1728                 /* LCOV_EXCL_STOP */
1729         }
1730 DATA_FREE:
1731         ctsvc_handle_destroy(contact);
1732         contacts_list_destroy(list, true);
1733         free(ids);
1734         ctsvc_server_start_timeout();
1735         return;
1736 }
1737
1738 void ctsvc_ipc_server_db_get_changes_by_version(pims_ipc_h ipc, pims_ipc_data_h indata,
1739                 pims_ipc_data_h *outdata, void *userdata)
1740 {
1741         int ret = CONTACTS_ERROR_NONE;
1742         char *view_uri = NULL;
1743         int address_book_id = 0;
1744         int contacts_db_version = 0;
1745         contacts_list_h record_list = NULL;
1746         int current_contacts_db_version = 0;
1747         contacts_h contact = NULL;
1748
1749         if (indata) {
1750                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1751                 if (CONTACTS_ERROR_NONE != ret) {
1752                         /* LCOV_EXCL_START */
1753                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1754                         goto ERROR_RETURN;
1755                         /* LCOV_EXCL_STOP */
1756                 }
1757
1758                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
1759                 if (ret != CONTACTS_ERROR_NONE) {
1760                         /* LCOV_EXCL_START */
1761                         ERR("ctsvc_ipc_unmarshal_string Fail");
1762                         goto ERROR_RETURN;
1763                         /* LCOV_EXCL_STOP */
1764                 }
1765                 ret = ctsvc_ipc_unmarshal_int(indata, &address_book_id);
1766                 if (ret != CONTACTS_ERROR_NONE) {
1767                         /* LCOV_EXCL_START */
1768                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1769                         goto ERROR_RETURN;
1770                         /* LCOV_EXCL_STOP */
1771                 }
1772                 ret = ctsvc_ipc_unmarshal_int(indata, &contacts_db_version);
1773                 if (ret != CONTACTS_ERROR_NONE) {
1774                         /* LCOV_EXCL_START */
1775                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1776                         goto ERROR_RETURN;
1777                         /* LCOV_EXCL_STOP */
1778                 }
1779         } else {
1780                 /* LCOV_EXCL_START */
1781                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
1782                 goto ERROR_RETURN;
1783                 /* LCOV_EXCL_STOP */
1784         }
1785
1786         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_READ)) {
1787                 /* LCOV_EXCL_START */
1788                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1789                 goto ERROR_RETURN;
1790                 /* LCOV_EXCL_STOP */
1791         }
1792
1793         ret = ctsvc_db_get_changes_by_version(view_uri, address_book_id, contacts_db_version,
1794                         &record_list, &current_contacts_db_version);
1795
1796         if (outdata) {
1797                 *outdata = pims_ipc_data_create(0);
1798                 if (NULL == *outdata) {
1799                         /* LCOV_EXCL_START */
1800                         ERR("pims_ipc_data_create() Fail");
1801                         goto DATA_FREE;
1802                         /* LCOV_EXCL_STOP */
1803                 }
1804                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1805                         /* LCOV_EXCL_START */
1806                         pims_ipc_data_destroy(*outdata);
1807                         *outdata = NULL;
1808                         ERR("ctsvc_ipc_marshal_int() Fail");
1809                         goto DATA_FREE;
1810                         /* LCOV_EXCL_STOP */
1811                 }
1812
1813                 if (CONTACTS_ERROR_NO_DATA == ret) {
1814                         DBG("no data");
1815                 } else if (CONTACTS_ERROR_NONE == ret) {
1816                         ret = ctsvc_ipc_marshal_list(record_list, *outdata);
1817                         if (ret != CONTACTS_ERROR_NONE) {
1818                                 /* LCOV_EXCL_START */
1819                                 ERR("ctsvc_ipc_marshal_list Fail");
1820                                 pims_ipc_data_destroy(*outdata);
1821                                 *outdata = NULL;
1822                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1823                                 goto ERROR_RETURN;
1824                                 /* LCOV_EXCL_STOP */
1825                         }
1826                         ret = ctsvc_ipc_marshal_int(current_contacts_db_version, *outdata);
1827                         if (ret != CONTACTS_ERROR_NONE) {
1828                                 /* LCOV_EXCL_START */
1829                                 ERR("ctsvc_ipc_marshal_int() Fail");
1830                                 pims_ipc_data_destroy(*outdata);
1831                                 *outdata = NULL;
1832                                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
1833                                 goto ERROR_RETURN;
1834                                 /* LCOV_EXCL_STOP */
1835                         }
1836                 }
1837         } else {
1838                 /* LCOV_EXCL_START */
1839                 ERR("outdata is NULL");
1840                 /* LCOV_EXCL_STOP */
1841         }
1842         goto DATA_FREE;
1843
1844 ERROR_RETURN:
1845         if (outdata) {
1846                 *outdata = pims_ipc_data_create(0);
1847                 if (NULL == *outdata) {
1848                         /* LCOV_EXCL_START */
1849                         ERR("pims_ipc_data_create() Fail");
1850                         goto DATA_FREE;
1851                         /* LCOV_EXCL_STOP */
1852                 }
1853                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1854                         /* LCOV_EXCL_START */
1855                         pims_ipc_data_destroy(*outdata);
1856                         *outdata = NULL;
1857                         ERR("ctsvc_ipc_marshal_int() Fail");
1858                         goto DATA_FREE;
1859                         /* LCOV_EXCL_STOP */
1860                 }
1861         } else {
1862                 /* LCOV_EXCL_START */
1863                 ERR("outdata is NULL");
1864                 /* LCOV_EXCL_STOP */
1865         }
1866 DATA_FREE:
1867         ctsvc_handle_destroy(contact);
1868         contacts_list_destroy(record_list, true);
1869         free(view_uri);
1870         ctsvc_server_start_timeout();
1871         return;
1872 }
1873
1874 void ctsvc_ipc_server_db_get_current_version(pims_ipc_h ipc, pims_ipc_data_h indata,
1875                 pims_ipc_data_h *outdata, void *userdata)
1876 {
1877         int ret = CONTACTS_ERROR_NONE;
1878         int contacts_db_version = 0;
1879         contacts_h contact = NULL;
1880
1881         if (indata) {
1882                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1883                 if (CONTACTS_ERROR_NONE != ret) {
1884                         /* LCOV_EXCL_START */
1885                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1886                         goto ERROR_RETURN;
1887                         /* LCOV_EXCL_STOP */
1888                 }
1889         }
1890
1891         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_READ) &&
1892                         !ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_READ)) {
1893                 /* LCOV_EXCL_START */
1894                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1895                 goto ERROR_RETURN;
1896                 /* LCOV_EXCL_STOP */
1897         }
1898
1899         ret = ctsvc_db_get_current_version(&contacts_db_version);
1900
1901 ERROR_RETURN:
1902         if (outdata) {
1903                 *outdata = pims_ipc_data_create(0);
1904                 if (NULL == *outdata) {
1905                         /* LCOV_EXCL_START */
1906                         ERR("pims_ipc_data_create() Fail");
1907                         goto DATA_FREE;
1908                         /* LCOV_EXCL_STOP */
1909                 }
1910                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1911                         /* LCOV_EXCL_START */
1912                         pims_ipc_data_destroy(*outdata);
1913                         *outdata = NULL;
1914                         ERR("ctsvc_ipc_marshal_int() Fail");
1915                         goto DATA_FREE;
1916                         /* LCOV_EXCL_STOP */
1917                 }
1918
1919                 if (CONTACTS_ERROR_NO_DATA == ret) {
1920                         DBG("no data");
1921                 } else if (CONTACTS_ERROR_NONE == ret) {
1922                         ret = ctsvc_ipc_marshal_int(contacts_db_version, *outdata);
1923                         if (ret != CONTACTS_ERROR_NONE) {
1924                                 /* LCOV_EXCL_START */
1925                                 ERR("ctsvc_ipc_marshal_int() Fail");
1926                                 goto DATA_FREE;
1927                                 /* LCOV_EXCL_STOP */
1928                         }
1929                 }
1930         } else {
1931                 /* LCOV_EXCL_START */
1932                 ERR("outdata is NULL");
1933                 /* LCOV_EXCL_STOP */
1934         }
1935
1936 DATA_FREE:
1937         ctsvc_handle_destroy(contact);
1938         ctsvc_server_start_timeout();
1939         return;
1940 }
1941
1942 void ctsvc_ipc_server_db_search_records_for_snippet(pims_ipc_h ipc,
1943                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
1944 {
1945         int ret = CONTACTS_ERROR_NONE;
1946         char *view_uri = NULL;
1947         char *keyword = NULL;
1948         int offset = 0;
1949         int limit = 0;
1950         contacts_list_h list = NULL;
1951         contacts_h contact = NULL;
1952         char *start_match = NULL;
1953         char *end_match = NULL;
1954         int token_number = 0;
1955
1956         if (indata) {
1957                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
1958                 if (CONTACTS_ERROR_NONE != ret) {
1959                         /* LCOV_EXCL_START */
1960                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
1961                         goto ERROR_RETURN;
1962                         /* LCOV_EXCL_STOP */
1963                 }
1964                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
1965                 if (ret != CONTACTS_ERROR_NONE) {
1966                         /* LCOV_EXCL_START */
1967                         ERR("ctsvc_ipc_unmarshal_record() Fail(%d)", ret);
1968                         goto ERROR_RETURN;
1969                         /* LCOV_EXCL_STOP */
1970                 }
1971                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
1972                 if (ret != CONTACTS_ERROR_NONE) {
1973                         /* LCOV_EXCL_START */
1974                         ERR("ctsvc_ipc_unmarshal_record() Fail(%d)", ret);
1975                         goto ERROR_RETURN;
1976                         /* LCOV_EXCL_STOP */
1977                 }
1978                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
1979                 if (ret != CONTACTS_ERROR_NONE) {
1980                         /* LCOV_EXCL_START */
1981                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
1982                         goto ERROR_RETURN;
1983                         /* LCOV_EXCL_STOP */
1984                 }
1985                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
1986                 if (ret != CONTACTS_ERROR_NONE) {
1987                         /* LCOV_EXCL_START */
1988                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
1989                         goto ERROR_RETURN;
1990                         /* LCOV_EXCL_STOP */
1991                 }
1992                 ret = ctsvc_ipc_unmarshal_string(indata, &start_match);
1993                 if (ret != CONTACTS_ERROR_NONE) {
1994                         /* LCOV_EXCL_START */
1995                         ERR("ctsvc_ipc_unmarshal_record() Fail");
1996                         goto ERROR_RETURN;
1997                         /* LCOV_EXCL_STOP */
1998                 }
1999                 ret = ctsvc_ipc_unmarshal_string(indata, &end_match);
2000                 if (ret != CONTACTS_ERROR_NONE) {
2001                         /* LCOV_EXCL_START */
2002                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2003                         goto ERROR_RETURN;
2004                         /* LCOV_EXCL_STOP */
2005                 }
2006                 ret = ctsvc_ipc_unmarshal_int(indata, &token_number);
2007                 if (ret != CONTACTS_ERROR_NONE) {
2008                         /* LCOV_EXCL_START */
2009                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2010                         goto ERROR_RETURN;
2011                         /* LCOV_EXCL_STOP */
2012                 }
2013         } else {
2014                 /* LCOV_EXCL_START */
2015                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2016                 goto ERROR_RETURN;
2017                 /* LCOV_EXCL_STOP */
2018         }
2019
2020         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
2021                 /* LCOV_EXCL_START */
2022                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2023                 goto ERROR_RETURN;
2024                 /* LCOV_EXCL_STOP */
2025         }
2026
2027         ret = ctsvc_db_search_records_for_snippet(view_uri, keyword, offset, limit,
2028                         start_match, end_match, token_number, &list);
2029
2030         if (outdata) {
2031                 *outdata = pims_ipc_data_create(0);
2032                 if (NULL == *outdata) {
2033                         /* LCOV_EXCL_START */
2034                         ERR("pims_ipc_data_create() Fail");
2035                         goto DATA_FREE;
2036                         /* LCOV_EXCL_STOP */
2037                 }
2038                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2039                         /* LCOV_EXCL_START */
2040                         pims_ipc_data_destroy(*outdata);
2041                         *outdata = NULL;
2042                         ERR("ctsvc_ipc_marshal_int() Fail");
2043                         goto DATA_FREE;
2044                         /* LCOV_EXCL_STOP */
2045                 }
2046
2047                 if (CONTACTS_ERROR_NO_DATA == ret) {
2048                         DBG("no data");
2049                 } else if (CONTACTS_ERROR_NONE == ret) {
2050                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2051
2052                         if (ret != CONTACTS_ERROR_NONE) {
2053                                 /* LCOV_EXCL_START */
2054                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
2055                                 goto DATA_FREE;
2056                                 /* LCOV_EXCL_STOP */
2057                         }
2058                 }
2059         } else {
2060                 /* LCOV_EXCL_START */
2061                 ERR("outdata is NULL");
2062                 /* LCOV_EXCL_STOP */
2063         }
2064         goto DATA_FREE;
2065
2066 ERROR_RETURN:
2067         if (outdata) {
2068                 *outdata = pims_ipc_data_create(0);
2069                 if (NULL == *outdata) {
2070                         /* LCOV_EXCL_START */
2071                         ERR("pims_ipc_data_create() Fail");
2072                         goto DATA_FREE;
2073                         /* LCOV_EXCL_STOP */
2074                 }
2075                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2076                         /* LCOV_EXCL_START */
2077                         pims_ipc_data_destroy(*outdata);
2078                         *outdata = NULL;
2079                         ERR("ctsvc_ipc_marshal_int() Fail");
2080                         goto DATA_FREE;
2081                         /* LCOV_EXCL_STOP */
2082                 }
2083         } else {
2084                 /* LCOV_EXCL_START */
2085                 ERR("outdata is NULL");
2086                 /* LCOV_EXCL_STOP */
2087         }
2088 DATA_FREE:
2089         ctsvc_handle_destroy(contact);
2090         contacts_list_destroy(list, true);
2091         free(view_uri);
2092         free(keyword);
2093         ctsvc_server_start_timeout();
2094         return;
2095 }
2096
2097 void ctsvc_ipc_server_db_search_records_with_range_for_snippet(pims_ipc_h ipc,
2098                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
2099 {
2100         int ret = CONTACTS_ERROR_NONE;
2101         char *view_uri = NULL;
2102         char *keyword = NULL;
2103         int offset = 0;
2104         int limit = 0;
2105         int range = 0;
2106         contacts_list_h list = NULL;
2107         contacts_h contact = NULL;
2108         char *start_match = NULL;
2109         char *end_match = NULL;
2110         int token_number = 0;
2111
2112         if (indata) {
2113                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2114                 if (CONTACTS_ERROR_NONE != ret) {
2115                         /* LCOV_EXCL_START */
2116                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2117                         goto ERROR_RETURN;
2118                         /* LCOV_EXCL_STOP */
2119                 }
2120                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
2121                 if (ret != CONTACTS_ERROR_NONE) {
2122                         /* LCOV_EXCL_START */
2123                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2124                         goto ERROR_RETURN;
2125                         /* LCOV_EXCL_STOP */
2126                 }
2127                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2128                 if (ret != CONTACTS_ERROR_NONE) {
2129                         /* LCOV_EXCL_START */
2130                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2131                         goto ERROR_RETURN;
2132                         /* LCOV_EXCL_STOP */
2133                 }
2134                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2135                 if (ret != CONTACTS_ERROR_NONE) {
2136                         /* LCOV_EXCL_START */
2137                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2138                         goto ERROR_RETURN;
2139                         /* LCOV_EXCL_STOP */
2140                 }
2141                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2142                 if (ret != CONTACTS_ERROR_NONE) {
2143                         /* LCOV_EXCL_START */
2144                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2145                         goto ERROR_RETURN;
2146                         /* LCOV_EXCL_STOP */
2147                 }
2148                 ret = ctsvc_ipc_unmarshal_int(indata, &range);
2149                 if (ret != CONTACTS_ERROR_NONE) {
2150                         /* LCOV_EXCL_START */
2151                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2152                         goto ERROR_RETURN;
2153                         /* LCOV_EXCL_STOP */
2154                 }
2155                 ret = ctsvc_ipc_unmarshal_string(indata, &start_match);
2156                 if (ret != CONTACTS_ERROR_NONE) {
2157                         /* LCOV_EXCL_START */
2158                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2159                         goto ERROR_RETURN;
2160                         /* LCOV_EXCL_STOP */
2161                 }
2162                 ret = ctsvc_ipc_unmarshal_string(indata, &end_match);
2163                 if (ret != CONTACTS_ERROR_NONE) {
2164                         /* LCOV_EXCL_START */
2165                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2166                         goto ERROR_RETURN;
2167                         /* LCOV_EXCL_STOP */
2168                 }
2169                 ret = ctsvc_ipc_unmarshal_int(indata, &token_number);
2170                 if (ret != CONTACTS_ERROR_NONE) {
2171                         /* LCOV_EXCL_START */
2172                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2173                         goto ERROR_RETURN;
2174                         /* LCOV_EXCL_STOP */
2175                 }
2176         } else {
2177                 /* LCOV_EXCL_START */
2178                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2179                 goto ERROR_RETURN;
2180                 /* LCOV_EXCL_START */
2181         }
2182
2183         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
2184                 /* LCOV_EXCL_START */
2185                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2186                 goto ERROR_RETURN;
2187                 /* LCOV_EXCL_STOP */
2188         }
2189
2190         ret = ctsvc_db_search_records_with_range_for_snippet(view_uri, keyword, offset,
2191                         limit, range, start_match, end_match, token_number, &list);
2192
2193         if (outdata) {
2194                 *outdata = pims_ipc_data_create(0);
2195                 if (NULL == *outdata) {
2196                         /* LCOV_EXCL_START */
2197                         ERR("pims_ipc_data_create() Fail");
2198                         goto DATA_FREE;
2199                         /* LCOV_EXCL_STOP */
2200                 }
2201                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2202                         /* LCOV_EXCL_START */
2203                         pims_ipc_data_destroy(*outdata);
2204                         *outdata = NULL;
2205                         ERR("ctsvc_ipc_marshal_int() Fail");
2206                         goto DATA_FREE;
2207                         /* LCOV_EXCL_STOP */
2208                 }
2209
2210                 if (CONTACTS_ERROR_NO_DATA == ret) {
2211                         DBG("no data");
2212                 } else if (CONTACTS_ERROR_NONE == ret) {
2213                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2214
2215                         if (ret != CONTACTS_ERROR_NONE) {
2216                                 /* LCOV_EXCL_START */
2217                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
2218                                 goto DATA_FREE;
2219                                 /* LCOV_EXCL_STOP */
2220                         }
2221                 }
2222         } else {
2223                 /* LCOV_EXCL_START */
2224                 ERR("outdata is NULL");
2225                 /* LCOV_EXCL_STOP */
2226         }
2227         goto DATA_FREE;
2228
2229 ERROR_RETURN:
2230         if (outdata) {
2231                 *outdata = pims_ipc_data_create(0);
2232                 if (NULL == *outdata) {
2233                         /* LCOV_EXCL_START */
2234                         ERR("pims_ipc_data_create() Fail");
2235                         goto DATA_FREE;
2236                         /* LCOV_EXCL_STOP */
2237                 }
2238                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2239                         /* LCOV_EXCL_START */
2240                         pims_ipc_data_destroy(*outdata);
2241                         *outdata = NULL;
2242                         ERR("ctsvc_ipc_marshal_int() Fail");
2243                         goto DATA_FREE;
2244                         /* LCOV_EXCL_STOP */
2245                 }
2246         } else {
2247                 /* LCOV_EXCL_START */
2248                 ERR("outdata is NULL");
2249                 /* LCOV_EXCL_STOP */
2250         }
2251
2252 DATA_FREE:
2253         ctsvc_handle_destroy(contact);
2254         contacts_list_destroy(list, true);
2255         free(view_uri);
2256         free(keyword);
2257         ctsvc_server_start_timeout();
2258         return;
2259 }
2260
2261 void ctsvc_ipc_server_db_search_records_with_query_for_snippet(pims_ipc_h ipc,
2262                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
2263 {
2264         int ret = CONTACTS_ERROR_NONE;
2265         contacts_query_h query = NULL;
2266         char *keyword = NULL;
2267         int offset = 0;
2268         int limit = 0;
2269         contacts_list_h list = NULL;
2270         contacts_h contact = NULL;
2271         char *start_match = NULL;
2272         char *end_match = NULL;
2273         int token_number = 0;
2274
2275         if (indata) {
2276                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2277                 if (CONTACTS_ERROR_NONE != ret) {
2278                         /* LCOV_EXCL_START */
2279                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2280                         goto ERROR_RETURN;
2281                         /* LCOV_EXCL_STOP */
2282                 }
2283                 ret = ctsvc_ipc_unmarshal_query(indata, &query);
2284                 if (ret != CONTACTS_ERROR_NONE) {
2285                         /* LCOV_EXCL_START */
2286                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2287                         goto ERROR_RETURN;
2288                         /* LCOV_EXCL_STOP */
2289                 }
2290                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2291                 if (ret != CONTACTS_ERROR_NONE) {
2292                         /* LCOV_EXCL_START */
2293                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2294                         goto ERROR_RETURN;
2295                         /* LCOV_EXCL_STOP */
2296                 }
2297                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2298                 if (ret != CONTACTS_ERROR_NONE) {
2299                         /* LCOV_EXCL_START */
2300                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2301                         goto ERROR_RETURN;
2302                         /* LCOV_EXCL_STOP */
2303                 }
2304                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2305                 if (ret != CONTACTS_ERROR_NONE) {
2306                         /* LCOV_EXCL_START */
2307                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2308                         goto ERROR_RETURN;
2309                         /* LCOV_EXCL_STOP */
2310                 }
2311                 ret = ctsvc_ipc_unmarshal_string(indata, &start_match);
2312                 if (ret != CONTACTS_ERROR_NONE) {
2313                         /* LCOV_EXCL_START */
2314                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2315                         goto ERROR_RETURN;
2316                         /* LCOV_EXCL_STOP */
2317                 }
2318                 ret = ctsvc_ipc_unmarshal_string(indata, &end_match);
2319                 if (ret != CONTACTS_ERROR_NONE) {
2320                         /* LCOV_EXCL_START */
2321                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2322                         goto ERROR_RETURN;
2323                         /* LCOV_EXCL_STOP */
2324                 }
2325                 ret = ctsvc_ipc_unmarshal_int(indata, &token_number);
2326                 if (ret != CONTACTS_ERROR_NONE) {
2327                         /* LCOV_EXCL_START */
2328                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2329                         goto ERROR_RETURN;
2330                         /* LCOV_EXCL_STOP */
2331                 }
2332         } else {
2333                 /* LCOV_EXCL_START */
2334                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2335                 goto ERROR_RETURN;
2336                 /* LCOV_EXCL_STOP */
2337         }
2338
2339         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(((ctsvc_query_s*)query)->view_uri))) {
2340                 /* LCOV_EXCL_START */
2341                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2342                 goto ERROR_RETURN;
2343                 /* LCOV_EXCL_STOP */
2344         }
2345
2346         ret = ctsvc_db_search_records_with_query_for_snippet(query, keyword, offset, limit,
2347                         start_match, end_match, token_number, &list);
2348
2349         if (outdata) {
2350                 *outdata = pims_ipc_data_create(0);
2351                 if (NULL == *outdata) {
2352                         /* LCOV_EXCL_START */
2353                         ERR("pims_ipc_data_create() Fail");
2354                         goto DATA_FREE;
2355                         /* LCOV_EXCL_STOP */
2356                 }
2357                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2358                         /* LCOV_EXCL_START */
2359                         pims_ipc_data_destroy(*outdata);
2360                         *outdata = NULL;
2361                         ERR("ctsvc_ipc_marshal_int() Fail");
2362                         goto DATA_FREE;
2363                         /* LCOV_EXCL_STOP */
2364                 }
2365
2366                 if (CONTACTS_ERROR_NO_DATA == ret) {
2367                         DBG("no data");
2368                 } else if (CONTACTS_ERROR_NONE == ret) {
2369                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2370
2371                         if (ret != CONTACTS_ERROR_NONE) {
2372                                 /* LCOV_EXCL_START */
2373                                 ERR("ctsvc_ipc_marshal_list Fail");
2374                                 goto DATA_FREE;
2375                                 /* LCOV_EXCL_STOP */
2376                         }
2377                 }
2378         } else {
2379                 /* LCOV_EXCL_START */
2380                 ERR("outdata is NULL");
2381                 /* LCOV_EXCL_STOP */
2382         }
2383         goto DATA_FREE;
2384
2385 ERROR_RETURN:
2386         if (outdata) {
2387                 *outdata = pims_ipc_data_create(0);
2388                 if (NULL == *outdata) {
2389                         /* LCOV_EXCL_START */
2390                         ERR("pims_ipc_data_create() Fail");
2391                         goto DATA_FREE;
2392                         /* LCOV_EXCL_STOP */
2393                 }
2394                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2395                         /* LCOV_EXCL_START */
2396                         pims_ipc_data_destroy(*outdata);
2397                         *outdata = NULL;
2398                         ERR("ctsvc_ipc_marshal_int() Fail");
2399                         goto DATA_FREE;
2400                         /* LCOV_EXCL_STOP */
2401                 }
2402         } else {
2403                 /* LCOV_EXCL_START */
2404                 ERR("outdata is NULL");
2405                 /* LCOV_EXCL_STOP */
2406         }
2407 DATA_FREE:
2408         ctsvc_handle_destroy(contact);
2409         contacts_list_destroy(list, true);
2410         contacts_query_destroy(query);
2411         free(keyword);
2412         ctsvc_server_start_timeout();
2413         return;
2414 }
2415
2416 void ctsvc_ipc_server_db_search_records(pims_ipc_h ipc, pims_ipc_data_h indata,
2417                 pims_ipc_data_h *outdata, void *userdata)
2418 {
2419         int ret = CONTACTS_ERROR_NONE;
2420         char *view_uri = NULL;
2421         char *keyword = NULL;
2422         int offset = 0;
2423         int limit = 0;
2424         contacts_list_h list = NULL;
2425         contacts_h contact = NULL;
2426
2427         if (indata) {
2428                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2429                 if (CONTACTS_ERROR_NONE != ret) {
2430                         /* LCOV_EXCL_START */
2431                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2432                         goto ERROR_RETURN;
2433                         /* LCOV_EXCL_STOP */
2434                 }
2435                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
2436                 if (ret != CONTACTS_ERROR_NONE) {
2437                         /* LCOV_EXCL_START */
2438                         ERR("ctsvc_ipc_unmarshal_record() Fail(%d)", ret);
2439                         goto ERROR_RETURN;
2440                         /* LCOV_EXCL_STOP */
2441                 }
2442                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2443                 if (ret != CONTACTS_ERROR_NONE) {
2444                         /* LCOV_EXCL_START */
2445                         ERR("ctsvc_ipc_unmarshal_record() Fail(%d)", ret);
2446                         goto ERROR_RETURN;
2447                         /* LCOV_EXCL_STOP */
2448                 }
2449                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2450                 if (ret != CONTACTS_ERROR_NONE) {
2451                         /* LCOV_EXCL_START */
2452                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2453                         goto ERROR_RETURN;
2454                         /* LCOV_EXCL_STOP */
2455                 }
2456                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2457                 if (ret != CONTACTS_ERROR_NONE) {
2458                         /* LCOV_EXCL_START */
2459                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
2460                         goto ERROR_RETURN;
2461                         /* LCOV_EXCL_STOP */
2462                 }
2463         } else {
2464                 /* LCOV_EXCL_START */
2465                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2466                 goto ERROR_RETURN;
2467                 /* LCOV_EXCL_STOP */
2468         }
2469
2470         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
2471                 /* LCOV_EXCL_START */
2472                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2473                 goto ERROR_RETURN;
2474                 /* LCOV_EXCL_STOP */
2475         }
2476
2477         ret = ctsvc_db_search_records(view_uri, keyword, offset, limit, &list);
2478
2479         if (outdata) {
2480                 *outdata = pims_ipc_data_create(0);
2481                 if (NULL == *outdata) {
2482                         /* LCOV_EXCL_START */
2483                         ERR("pims_ipc_data_create() Fail");
2484                         goto DATA_FREE;
2485                         /* LCOV_EXCL_STOP */
2486                 }
2487                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2488                         /* LCOV_EXCL_START */
2489                         pims_ipc_data_destroy(*outdata);
2490                         *outdata = NULL;
2491                         ERR("ctsvc_ipc_marshal_int() Fail");
2492                         goto DATA_FREE;
2493                         /* LCOV_EXCL_STOP */
2494                 }
2495
2496                 if (CONTACTS_ERROR_NO_DATA == ret) {
2497                         DBG("no data");
2498                 } else if (CONTACTS_ERROR_NONE == ret) {
2499                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2500
2501                         if (ret != CONTACTS_ERROR_NONE) {
2502                                 /* LCOV_EXCL_START */
2503                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
2504                                 goto DATA_FREE;
2505                                 /* LCOV_EXCL_STOP */
2506                         }
2507                 }
2508         } else {
2509                 /* LCOV_EXCL_START */
2510                 ERR("outdata is NULL");
2511                 /* LCOV_EXCL_STOP */
2512         }
2513         goto DATA_FREE;
2514
2515 ERROR_RETURN:
2516         if (outdata) {
2517                 *outdata = pims_ipc_data_create(0);
2518                 if (NULL == *outdata) {
2519                         /* LCOV_EXCL_START */
2520                         ERR("pims_ipc_data_create() Fail");
2521                         goto DATA_FREE;
2522                         /* LCOV_EXCL_STOP */
2523                 }
2524                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2525                         /* LCOV_EXCL_START */
2526                         pims_ipc_data_destroy(*outdata);
2527                         *outdata = NULL;
2528                         ERR("ctsvc_ipc_marshal_int() Fail");
2529                         goto DATA_FREE;
2530                         /* LCOV_EXCL_STOP */
2531                 }
2532         } else {
2533                 /* LCOV_EXCL_START */
2534                 ERR("outdata is NULL");
2535                 /* LCOV_EXCL_STOP */
2536         }
2537 DATA_FREE:
2538         ctsvc_handle_destroy(contact);
2539         contacts_list_destroy(list, true);
2540         free(view_uri);
2541         free(keyword);
2542         ctsvc_server_start_timeout();
2543         return;
2544 }
2545
2546 void ctsvc_ipc_server_db_search_records_with_range(pims_ipc_h ipc,
2547                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
2548 {
2549         int ret = CONTACTS_ERROR_NONE;
2550         char *view_uri = NULL;
2551         char *keyword = NULL;
2552         int offset = 0;
2553         int limit = 0;
2554         int range = 0;
2555         contacts_list_h list = NULL;
2556         contacts_h contact = NULL;
2557
2558         if (indata) {
2559                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2560                 if (CONTACTS_ERROR_NONE != ret) {
2561                         /* LCOV_EXCL_START */
2562                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2563                         goto ERROR_RETURN;
2564                         /* LCOV_EXCL_STOP */
2565                 }
2566                 ret = ctsvc_ipc_unmarshal_string(indata, &view_uri);
2567                 if (ret != CONTACTS_ERROR_NONE) {
2568                         /* LCOV_EXCL_START */
2569                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2570                         goto ERROR_RETURN;
2571                         /* LCOV_EXCL_STOP */
2572                 }
2573                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2574                 if (ret != CONTACTS_ERROR_NONE) {
2575                         /* LCOV_EXCL_START */
2576                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2577                         goto ERROR_RETURN;
2578                         /* LCOV_EXCL_STOP */
2579                 }
2580                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2581                 if (ret != CONTACTS_ERROR_NONE) {
2582                         /* LCOV_EXCL_START */
2583                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2584                         goto ERROR_RETURN;
2585                         /* LCOV_EXCL_STOP */
2586                 }
2587                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2588                 if (ret != CONTACTS_ERROR_NONE) {
2589                         /* LCOV_EXCL_START */
2590                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2591                         goto ERROR_RETURN;
2592                         /* LCOV_EXCL_STOP */
2593                 }
2594                 ret = ctsvc_ipc_unmarshal_int(indata, &range);
2595                 if (ret != CONTACTS_ERROR_NONE) {
2596                         /* LCOV_EXCL_START */
2597                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2598                         goto ERROR_RETURN;
2599                         /* LCOV_EXCL_STOP */
2600                 }
2601         } else {
2602                 /* LCOV_EXCL_START */
2603                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2604                 goto ERROR_RETURN;
2605                 /* LCOV_EXCL_STOP */
2606         }
2607
2608         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(view_uri))) {
2609                 /* LCOV_EXCL_START */
2610                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2611                 goto ERROR_RETURN;
2612                 /* LCOV_EXCL_STOP */
2613         }
2614
2615         ret = ctsvc_db_search_records_with_range(view_uri, keyword, offset, limit, range,
2616                         &list);
2617
2618         if (outdata) {
2619                 *outdata = pims_ipc_data_create(0);
2620                 if (NULL == *outdata) {
2621                         /* LCOV_EXCL_START */
2622                         ERR("pims_ipc_data_create() Fail");
2623                         goto DATA_FREE;
2624                         /* LCOV_EXCL_STOP */
2625                 }
2626                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2627                         /* LCOV_EXCL_START */
2628                         pims_ipc_data_destroy(*outdata);
2629                         *outdata = NULL;
2630                         ERR("ctsvc_ipc_marshal_int() Fail");
2631                         goto DATA_FREE;
2632                         /* LCOV_EXCL_STOP */
2633                 }
2634
2635                 if (CONTACTS_ERROR_NO_DATA == ret) {
2636                         DBG("no data");
2637                 } else if (CONTACTS_ERROR_NONE == ret) {
2638                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2639
2640                         if (ret != CONTACTS_ERROR_NONE) {
2641                                 /* LCOV_EXCL_START */
2642                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
2643                                 goto DATA_FREE;
2644                                 /* LCOV_EXCL_STOP */
2645                         }
2646                 }
2647         } else {
2648                 /* LCOV_EXCL_START */
2649                 ERR("outdata is NULL");
2650                 /* LCOV_EXCL_STOP */
2651         }
2652         goto DATA_FREE;
2653
2654 ERROR_RETURN:
2655         if (outdata) {
2656                 *outdata = pims_ipc_data_create(0);
2657                 if (NULL == *outdata) {
2658                         /* LCOV_EXCL_START */
2659                         ERR("pims_ipc_data_create() Fail");
2660                         goto DATA_FREE;
2661                         /* LCOV_EXCL_STOP */
2662                 }
2663                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2664                         /* LCOV_EXCL_START */
2665                         pims_ipc_data_destroy(*outdata);
2666                         *outdata = NULL;
2667                         ERR("ctsvc_ipc_marshal_int() Fail");
2668                         goto DATA_FREE;
2669                         /* LCOV_EXCL_STOP */
2670                 }
2671         } else {
2672                 /* LCOV_EXCL_START */
2673                 ERR("outdata is NULL");
2674                 /* LCOV_EXCL_STOP */
2675         }
2676
2677 DATA_FREE:
2678         ctsvc_handle_destroy(contact);
2679         contacts_list_destroy(list, true);
2680         free(view_uri);
2681         free(keyword);
2682         ctsvc_server_start_timeout();
2683         return;
2684 }
2685
2686 void ctsvc_ipc_server_db_search_records_with_query(pims_ipc_h ipc,
2687                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
2688 {
2689         int ret = CONTACTS_ERROR_NONE;
2690         contacts_query_h query = NULL;
2691         char *keyword = NULL;
2692         int offset = 0;
2693         int limit = 0;
2694         contacts_list_h list = NULL;
2695         contacts_h contact = NULL;
2696
2697         if (indata) {
2698                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2699                 if (CONTACTS_ERROR_NONE != ret) {
2700                         /* LCOV_EXCL_START */
2701                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2702                         goto ERROR_RETURN;
2703                         /* LCOV_EXCL_STOP */
2704                 }
2705                 ret = ctsvc_ipc_unmarshal_query(indata, &query);
2706                 if (ret != CONTACTS_ERROR_NONE) {
2707                         /* LCOV_EXCL_START */
2708                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2709                         goto ERROR_RETURN;
2710                         /* LCOV_EXCL_STOP */
2711                 }
2712                 ret = ctsvc_ipc_unmarshal_string(indata, &keyword);
2713                 if (ret != CONTACTS_ERROR_NONE) {
2714                         /* LCOV_EXCL_START */
2715                         ERR("ctsvc_ipc_unmarshal_record() Fail");
2716                         goto ERROR_RETURN;
2717                         /* LCOV_EXCL_STOP */
2718                 }
2719                 ret = ctsvc_ipc_unmarshal_int(indata, &offset);
2720                 if (ret != CONTACTS_ERROR_NONE) {
2721                         /* LCOV_EXCL_START */
2722                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2723                         goto ERROR_RETURN;
2724                         /* LCOV_EXCL_STOP */
2725                 }
2726                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
2727                 if (ret != CONTACTS_ERROR_NONE) {
2728                         /* LCOV_EXCL_START */
2729                         ERR("ctsvc_ipc_unmarshal_int() Fail");
2730                         goto ERROR_RETURN;
2731                         /* LCOV_EXCL_STOP */
2732                 }
2733         } else {
2734                 /* LCOV_EXCL_START */
2735                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
2736                 goto ERROR_RETURN;
2737                 /* LCOV_EXCL_STOP */
2738         }
2739
2740
2741         if (!ctsvc_have_permission(ipc, ctsvc_required_read_permission(((ctsvc_query_s*)query)->view_uri))) {
2742                 /* LCOV_EXCL_START */
2743                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
2744                 goto ERROR_RETURN;
2745                 /* LCOV_EXCL_STOP */
2746         }
2747
2748
2749         ret = ctsvc_db_search_records_with_query(query, keyword, offset, limit, &list);
2750
2751         if (outdata) {
2752                 *outdata = pims_ipc_data_create(0);
2753                 if (NULL == *outdata) {
2754                         /* LCOV_EXCL_START */
2755                         ERR("pims_ipc_data_create() Fail");
2756                         goto DATA_FREE;
2757                         /* LCOV_EXCL_STOP */
2758                 }
2759                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2760                         /* LCOV_EXCL_START */
2761                         pims_ipc_data_destroy(*outdata);
2762                         *outdata = NULL;
2763                         ERR("ctsvc_ipc_marshal_int() Fail");
2764                         goto DATA_FREE;
2765                         /* LCOV_EXCL_STOP */
2766                 }
2767
2768                 if (CONTACTS_ERROR_NO_DATA == ret) {
2769                         DBG("no data");
2770                 } else if (CONTACTS_ERROR_NONE == ret) {
2771                         ret = ctsvc_ipc_marshal_list(list, *outdata);
2772
2773                         if (ret != CONTACTS_ERROR_NONE) {
2774                                 /* LCOV_EXCL_START */
2775                                 ERR("ctsvc_ipc_marshal_list Fail");
2776                                 goto DATA_FREE;
2777                                 /* LCOV_EXCL_STOP */
2778                         }
2779                 }
2780         } else {
2781                 /* LCOV_EXCL_START */
2782                 ERR("outdata is NULL");
2783                 /* LCOV_EXCL_STOP */
2784         }
2785         goto DATA_FREE;
2786
2787 ERROR_RETURN:
2788         if (outdata) {
2789                 *outdata = pims_ipc_data_create(0);
2790                 if (NULL == *outdata) {
2791                         /* LCOV_EXCL_START */
2792                         ERR("pims_ipc_data_create() Fail");
2793                         goto DATA_FREE;
2794                         /* LCOV_EXCL_STOP */
2795                 }
2796                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2797                         /* LCOV_EXCL_START */
2798                         pims_ipc_data_destroy(*outdata);
2799                         *outdata = NULL;
2800                         ERR("ctsvc_ipc_marshal_int() Fail");
2801                         goto DATA_FREE;
2802                         /* LCOV_EXCL_STOP */
2803                 }
2804         } else {
2805                 /* LCOV_EXCL_START */
2806                 ERR("outdata is NULL");
2807                 /* LCOV_EXCL_STOP */
2808         }
2809 DATA_FREE:
2810         ctsvc_handle_destroy(contact);
2811         contacts_list_destroy(list, true);
2812         contacts_query_destroy(query);
2813         free(keyword);
2814         ctsvc_server_start_timeout();
2815         return;
2816 }
2817
2818 void ctsvc_ipc_server_db_get_status(pims_ipc_h ipc, pims_ipc_data_h indata,
2819                 pims_ipc_data_h *outdata, void *userdata)
2820 {
2821         int ret = CONTACTS_ERROR_NONE;
2822         contacts_db_status_e status;
2823         contacts_h contact = NULL;
2824
2825         if (indata) {
2826                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
2827                 if (CONTACTS_ERROR_NONE != ret) {
2828                         /* LCOV_EXCL_START */
2829                         ERR("ctsvc_ipc_unmarshal_handle() Fail(%d)", ret);
2830                         goto ERROR_RETURN;
2831                         /* LCOV_EXCL_STOP */
2832                 }
2833         }
2834
2835         ret = ctsvc_db_get_status(&status);
2836
2837 ERROR_RETURN:
2838         if (outdata) {
2839                 *outdata = pims_ipc_data_create(0);
2840                 if (NULL == *outdata) {
2841                         /* LCOV_EXCL_START */
2842                         ERR("pims_ipc_data_create() Fail");
2843                         goto DATA_FREE;
2844                         /* LCOV_EXCL_STOP */
2845                 }
2846
2847                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
2848                         /* LCOV_EXCL_START */
2849                         pims_ipc_data_destroy(*outdata);
2850                         *outdata = NULL;
2851                         ERR("ctsvc_ipc_marshal_int() Fail");
2852                         goto DATA_FREE;
2853                         /* LCOV_EXCL_STOP */
2854                 }
2855
2856                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(status, *outdata)) {
2857                         /* LCOV_EXCL_START */
2858                         pims_ipc_data_destroy(*outdata);
2859                         *outdata = NULL;
2860                         ERR("ctsvc_ipc_marshal_int() Fail");
2861                         goto DATA_FREE;
2862                         /* LCOV_EXCL_STOP */
2863                 }
2864         } else {
2865                 /* LCOV_EXCL_START */
2866                 ERR("outdata is NULL");
2867                 /* LCOV_EXCL_STOP */
2868         }
2869 DATA_FREE:
2870         ctsvc_handle_destroy(contact);
2871         ctsvc_server_start_timeout();
2872         return;
2873 }
2874