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