Apply coding rule
[platform/core/pim/contacts-service.git] / server / ctsvc_ipc_server2.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
22 #include "contacts.h"
23 #ifdef ENABLE_LOG_FEATURE
24 #include "contacts_phone_log_internal.h"
25 #endif /* ENABLE_LOG_FEATURE */
26
27 #include "ctsvc_server_service.h"
28 #include "ctsvc_db_init.h"
29
30 #include "ctsvc_server_activity.h"
31 #include "ctsvc_server_person.h"
32 #include "ctsvc_server_group.h"
33 #include "ctsvc_server_phonelog.h"
34 #include "ctsvc_server_setting.h"
35
36 #include "ctsvc_db_access_control.h"
37
38 #include "ctsvc_ipc_marshal.h"
39 #include "ctsvc_internal.h"
40 #include "ctsvc_ipc_server.h"
41 #include "ctsvc_db_utils.h"
42 #include "ctsvc_handle.h"
43 #include "ctsvc_server_utils.h"
44
45 void ctsvc_ipc_activity_delete_by_contact_id(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
46 {
47         int ret = CONTACTS_ERROR_NONE;
48         int contact_id = 0;
49         contacts_h contact = NULL;
50
51         if (indata) {
52                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
53                 if (CONTACTS_ERROR_NONE != ret) {
54                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
55                         goto ERROR_RETURN;
56                 }
57                 ret = ctsvc_ipc_unmarshal_int(indata, &contact_id);
58                 if (ret != CONTACTS_ERROR_NONE) {
59                         ERR("ctsvc_ipc_unmarshal_int() Fail");
60                         goto ERROR_RETURN;
61                 }
62         } else {
63                 ERR("ctsvc_ipc_server_db_insert_record() Fail");
64                 goto ERROR_RETURN;
65         }
66
67         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
68                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
69                 goto ERROR_RETURN;
70         }
71         ret = ctsvc_activity_delete_by_contact_id(contact_id);
72
73
74 ERROR_RETURN:
75
76         if (outdata) {
77                 *outdata = pims_ipc_data_create(0);
78                 if (NULL == *outdata) {
79                         ERR("pims_ipc_data_create() Fail");
80                         goto DATA_FREE;
81                 }
82
83                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
84                         pims_ipc_data_destroy(*outdata);
85                         *outdata = NULL;
86                         ERR("ctsvc_ipc_marshal_int() Fail");
87                         goto DATA_FREE;
88                 }
89
90                 if (ret == CONTACTS_ERROR_NONE) {
91                         int transaction_ver = ctsvc_get_transaction_ver();
92                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
93                                 pims_ipc_data_destroy(*outdata);
94                                 *outdata = NULL;
95                                 ERR("ctsvc_ipc_marshal_int() Fail");
96                                 goto DATA_FREE;
97                         }
98                 }
99         } else {
100                 ERR("outdata is NULL");
101         }
102 DATA_FREE:
103         ctsvc_handle_destroy(contact);
104         ctsvc_server_start_timeout();
105         return;
106 }
107
108 void ctsvc_ipc_activity_delete_by_account_id(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
109 {
110         int ret = CONTACTS_ERROR_NONE;
111         int account_id = 0;
112         contacts_h contact = NULL;
113
114         if (indata) {
115                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
116                 if (CONTACTS_ERROR_NONE != ret) {
117                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
118                         goto ERROR_RETURN;
119                 }
120                 ret = ctsvc_ipc_unmarshal_int(indata, &account_id);
121                 if (ret != CONTACTS_ERROR_NONE) {
122                         ERR("ctsvc_ipc_unmarshal_int() Fail");
123                         goto ERROR_RETURN;
124                 }
125         } else {
126                 ERR("ctsvc_ipc_activity_delete_by_account_id() Fail");
127                 goto ERROR_RETURN;
128         }
129
130         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
131                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
132                 goto ERROR_RETURN;
133         }
134         ret = ctsvc_activity_delete_by_account_id(account_id);
135
136 ERROR_RETURN:
137
138         if (outdata) {
139                 *outdata = pims_ipc_data_create(0);
140                 if (NULL == *outdata) {
141                         ERR("pims_ipc_data_create() Fail");
142                         goto DATA_FREE;
143                 }
144                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
145                         pims_ipc_data_destroy(*outdata);
146                         *outdata = NULL;
147                         ERR("ctsvc_ipc_marshal_int() Fail");
148                         goto DATA_FREE;
149                 }
150
151                 if (ret == CONTACTS_ERROR_NONE) {
152                         int transaction_ver = ctsvc_get_transaction_ver();
153                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
154                                 pims_ipc_data_destroy(*outdata);
155                                 *outdata = NULL;
156                                 ERR("ctsvc_ipc_marshal_int() Fail");
157                                 goto DATA_FREE;
158                         }
159                 }
160         } else {
161                 ERR("outdata is NULL");
162         }
163 DATA_FREE:
164         ctsvc_handle_destroy(contact);
165         ctsvc_server_start_timeout();
166         return;
167 }
168
169 void ctsvc_ipc_group_add_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
170 {
171         int ret = CONTACTS_ERROR_NONE;
172         int group_id = 0;
173         int contact_id = 0;
174         contacts_h contact = NULL;
175
176         if (indata) {
177                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
178                 if (CONTACTS_ERROR_NONE != ret) {
179                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
180                         goto ERROR_RETURN;
181                 }
182                 ret = ctsvc_ipc_unmarshal_int(indata, &group_id);
183                 if (ret != CONTACTS_ERROR_NONE) {
184                         ERR("ctsvc_ipc_unmarshal_int() Fail");
185                         goto ERROR_RETURN;
186                 }
187                 ret = ctsvc_ipc_unmarshal_int(indata, &contact_id);
188                 if (ret != CONTACTS_ERROR_NONE) {
189                         ERR("ctsvc_ipc_unmarshal_int() Fail");
190                         goto ERROR_RETURN;
191                 }
192         } else {
193                 ERR("ctsvc_ipc_group_add_contact() Fail");
194                 goto ERROR_RETURN;
195         }
196
197         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
198                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
199                 goto ERROR_RETURN;
200         }
201
202         ret = ctsvc_group_add_contact(group_id, contact_id);
203
204 ERROR_RETURN:
205
206         if (outdata) {
207                 *outdata = pims_ipc_data_create(0);
208                 if (NULL == *outdata) {
209                         ERR("pims_ipc_data_create() Fail");
210                         goto DATA_FREE;
211                 }
212                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
213                         pims_ipc_data_destroy(*outdata);
214                         *outdata = NULL;
215                         ERR("ctsvc_ipc_marshal_int() Fail");
216                         goto DATA_FREE;
217                 }
218
219                 if (ret == CONTACTS_ERROR_NONE) {
220                         int transaction_ver = ctsvc_get_transaction_ver();
221                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
222                                 pims_ipc_data_destroy(*outdata);
223                                 *outdata = NULL;
224                                 ERR("ctsvc_ipc_marshal_int() Fail");
225                                 goto DATA_FREE;
226                         }
227                 }
228         } else {
229                 ERR("outdata is NULL");
230         }
231 DATA_FREE:
232         ctsvc_handle_destroy(contact);
233         ctsvc_server_start_timeout();
234         return;
235 }
236
237 void ctsvc_ipc_group_remove_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
238 {
239         int ret = CONTACTS_ERROR_NONE;
240         int group_id = 0;
241         int contact_id = 0;
242         contacts_h contact = NULL;
243
244         if (indata) {
245                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
246                 if (CONTACTS_ERROR_NONE != ret) {
247                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
248                         goto ERROR_RETURN;
249                 }
250                 ret = ctsvc_ipc_unmarshal_int(indata, &group_id);
251                 if (ret != CONTACTS_ERROR_NONE) {
252                         ERR("ctsvc_ipc_unmarshal_int() Fail");
253                         goto ERROR_RETURN;
254                 }
255                 ret = ctsvc_ipc_unmarshal_int(indata, &contact_id);
256                 if (ret != CONTACTS_ERROR_NONE) {
257                         ERR("ctsvc_ipc_unmarshal_int() Fail");
258                         goto ERROR_RETURN;
259                 }
260         } else {
261                 ERR("ctsvc_ipc_group_remove_contact() Fail");
262                 goto ERROR_RETURN;
263         }
264
265         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
266                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
267                 goto ERROR_RETURN;
268         }
269
270
271         ret = ctsvc_group_remove_contact(group_id, contact_id);
272
273 ERROR_RETURN:
274
275         if (outdata) {
276                 *outdata = pims_ipc_data_create(0);
277                 if (NULL == *outdata) {
278                         ERR("pims_ipc_data_create() Fail");
279                         goto DATA_FREE;
280                 }
281                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
282                         pims_ipc_data_destroy(*outdata);
283                         *outdata = NULL;
284                         ERR("ctsvc_ipc_marshal_int() Fail");
285                         goto DATA_FREE;
286                 }
287                 if (ret == CONTACTS_ERROR_NONE) {
288                         int transaction_ver = ctsvc_get_transaction_ver();
289                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
290                                 pims_ipc_data_destroy(*outdata);
291                                 *outdata = NULL;
292                                 ERR("ctsvc_ipc_marshal_int() Fail");
293                                 goto DATA_FREE;
294                         }
295                 }
296
297         } else {
298                 ERR("outdata is NULL");
299         }
300 DATA_FREE:
301         ctsvc_handle_destroy(contact);
302         ctsvc_server_start_timeout();
303         return;
304 }
305
306 void ctsvc_ipc_group_set_group_order(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
307 {
308         int ret = CONTACTS_ERROR_NONE;
309         int group_id = 0;
310         int previous_group_id;
311         int next_group_id;
312
313         contacts_h contact = NULL;
314         if (indata) {
315                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
316                 if (CONTACTS_ERROR_NONE != ret) {
317                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
318                         goto ERROR_RETURN;
319                 }
320                 ret = ctsvc_ipc_unmarshal_int(indata, &group_id);
321                 if (ret != CONTACTS_ERROR_NONE) {
322                         ERR("ctsvc_ipc_unmarshal_int() Fail");
323                         goto ERROR_RETURN;
324                 }
325                 ret = ctsvc_ipc_unmarshal_int(indata, &previous_group_id);
326                 if (ret != CONTACTS_ERROR_NONE) {
327                         ERR("ctsvc_ipc_unmarshal_int() Fail");
328                         goto ERROR_RETURN;
329                 }
330                 ret = ctsvc_ipc_unmarshal_int(indata, &next_group_id);
331                 if (ret != CONTACTS_ERROR_NONE) {
332                         ERR("ctsvc_ipc_unmarshal_int() Fail");
333                         goto ERROR_RETURN;
334                 }
335         } else {
336                 ERR("ctsvc_ipc_group_link_group() Fail");
337                 goto ERROR_RETURN;
338         }
339
340         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
341                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
342                 goto ERROR_RETURN;
343         }
344
345         ret = ctsvc_group_set_group_order(group_id, previous_group_id, next_group_id);
346
347 ERROR_RETURN:
348
349         if (outdata) {
350                 *outdata = pims_ipc_data_create(0);
351                 if (NULL == *outdata) {
352                         ERR("pims_ipc_data_create() Fail");
353                         goto DATA_FREE;
354                 }
355                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
356                         pims_ipc_data_destroy(*outdata);
357                         *outdata = NULL;
358                         ERR("ctsvc_ipc_marshal_int() Fail");
359                         goto DATA_FREE;
360                 }
361                 if (ret == CONTACTS_ERROR_NONE) {
362                         int transaction_ver = ctsvc_get_transaction_ver();
363                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
364                                 pims_ipc_data_destroy(*outdata);
365                                 *outdata = NULL;
366                                 ERR("ctsvc_ipc_marshal_int() Fail");
367                                 goto DATA_FREE;
368                         }
369                 }
370         } else {
371                 ERR("outdata is NULL");
372         }
373 DATA_FREE:
374         ctsvc_handle_destroy(contact);
375         ctsvc_server_start_timeout();
376         return;
377 }
378
379 void ctsvc_ipc_person_link_person(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
380 {
381         int ret = CONTACTS_ERROR_NONE;
382         int base_person_id = 0;
383         int person_id = 0;
384
385         contacts_h contact = NULL;
386         if (indata) {
387                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
388                 if (CONTACTS_ERROR_NONE != ret) {
389                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
390                         goto ERROR_RETURN;
391                 }
392                 ret = ctsvc_ipc_unmarshal_int(indata, &base_person_id);
393                 if (ret != CONTACTS_ERROR_NONE) {
394                         ERR("ctsvc_ipc_unmarshal_int() Fail");
395                         goto ERROR_RETURN;
396                 }
397                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
398                 if (ret != CONTACTS_ERROR_NONE) {
399                         ERR("ctsvc_ipc_unmarshal_int() Fail");
400                         goto ERROR_RETURN;
401                 }
402         } else {
403                 ERR("ctsvc_ipc_person_link_person() Fail");
404                 goto ERROR_RETURN;
405         }
406
407         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
408                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
409                 goto ERROR_RETURN;
410         }
411
412         ret = ctsvc_person_link_person(base_person_id, person_id);
413
414 ERROR_RETURN:
415
416         if (outdata) {
417                 *outdata = pims_ipc_data_create(0);
418                 if (NULL == *outdata) {
419                         ERR("pims_ipc_data_create() Fail");
420                         goto DATA_FREE;
421                 }
422                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
423                         pims_ipc_data_destroy(*outdata);
424                         *outdata = NULL;
425                         ERR("ctsvc_ipc_marshal_int() Fail");
426                         goto DATA_FREE;
427                 }
428                 if (ret == CONTACTS_ERROR_NONE) {
429                         int transaction_ver = ctsvc_get_transaction_ver();
430                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
431                                 pims_ipc_data_destroy(*outdata);
432                                 *outdata = NULL;
433                                 ERR("ctsvc_ipc_marshal_int() Fail");
434                                 goto DATA_FREE;
435                         }
436                 }
437         } else {
438                 ERR("outdata is NULL");
439         }
440 DATA_FREE:
441         ctsvc_handle_destroy(contact);
442         ctsvc_server_start_timeout();
443         return;
444 }
445 void ctsvc_ipc_person_unlink_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
446 {
447         int ret = CONTACTS_ERROR_NONE;
448         int person_id = 0;
449         int contact_id = 0;
450
451         contacts_h contact = NULL;
452         if (indata) {
453                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
454                 if (CONTACTS_ERROR_NONE != ret) {
455                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
456                         goto ERROR_RETURN;
457                 }
458                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
459                 if (ret != CONTACTS_ERROR_NONE) {
460                         ERR("ctsvc_ipc_unmarshal_int() Fail");
461                         goto ERROR_RETURN;
462                 }
463                 ret = ctsvc_ipc_unmarshal_int(indata, &contact_id);
464                 if (ret != CONTACTS_ERROR_NONE) {
465                         ERR("ctsvc_ipc_unmarshal_int() Fail");
466                         goto ERROR_RETURN;
467                 }
468         } else {
469                 ERR("ctsvc_ipc_person_link_person() Fail");
470                 goto ERROR_RETURN;
471         }
472
473         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
474                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
475                 goto ERROR_RETURN;
476         }
477
478         int unlinked_person_id;
479         ret = ctsvc_person_unlink_contact(person_id, contact_id, &unlinked_person_id);
480
481 ERROR_RETURN:
482
483         if (outdata) {
484                 *outdata = pims_ipc_data_create(0);
485                 if (NULL == *outdata) {
486                         ERR("pims_ipc_data_create() Fail");
487                         goto DATA_FREE;
488                 }
489                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
490                         pims_ipc_data_destroy(*outdata);
491                         *outdata = NULL;
492                         ERR("ctsvc_ipc_marshal_int() Fail");
493                         goto DATA_FREE;
494                 }
495                 if (ret == CONTACTS_ERROR_NONE) {
496                         int transaction_ver = ctsvc_get_transaction_ver();
497                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
498                                 pims_ipc_data_destroy(*outdata);
499                                 *outdata = NULL;
500                                 ERR("ctsvc_ipc_marshal_int() Fail");
501                                 goto DATA_FREE;
502                         }
503                 }
504                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(unlinked_person_id, *outdata)) {
505                         pims_ipc_data_destroy(*outdata);
506                         *outdata = NULL;
507                         ERR("ctsvc_ipc_marshal_int() Fail");
508                         goto DATA_FREE;
509                 }
510
511         } else {
512                 ERR("outdata is NULL");
513         }
514 DATA_FREE:
515         ctsvc_handle_destroy(contact);
516         ctsvc_server_start_timeout();
517         return;
518 }
519 void ctsvc_ipc_person_reset_usage(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
520 {
521         int ret = CONTACTS_ERROR_NONE;
522         int person_id = 0;
523         contacts_usage_type_e type;
524         contacts_h contact = NULL;
525
526         if (indata) {
527                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
528                 if (CONTACTS_ERROR_NONE != ret) {
529                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
530                         goto ERROR_RETURN;
531                 }
532                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
533                 if (ret != CONTACTS_ERROR_NONE) {
534                         ERR("ctsvc_ipc_unmarshal_int() Fail");
535                         goto ERROR_RETURN;
536                 }
537                 int temp = 0;
538                 ret = ctsvc_ipc_unmarshal_int(indata, &temp);
539                 type = (int)temp;
540                 if (ret != CONTACTS_ERROR_NONE) {
541                         ERR("ctsvc_ipc_unmarshal_int() Fail");
542                         goto ERROR_RETURN;
543                 }
544         } else {
545                 ERR("ctsvc_ipc_person_link_person() Fail");
546                 goto ERROR_RETURN;
547         }
548
549         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
550                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
551                 goto ERROR_RETURN;
552         }
553
554         ret = ctsvc_person_reset_usage(person_id, type);
555
556 ERROR_RETURN:
557
558         if (outdata) {
559                 *outdata = pims_ipc_data_create(0);
560                 if (NULL == *outdata) {
561                         ERR("pims_ipc_data_create() Fail");
562                         goto DATA_FREE;
563                 }
564                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
565                         pims_ipc_data_destroy(*outdata);
566                         *outdata = NULL;
567                         ERR("ctsvc_ipc_marshal_int() Fail");
568                         goto DATA_FREE;
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                                 pims_ipc_data_destroy(*outdata);
574                                 *outdata = NULL;
575                                 ERR("ctsvc_ipc_marshal_int() Fail");
576                                 goto DATA_FREE;
577                         }
578                 }
579         } else {
580                 ERR("outdata is NULL");
581         }
582 DATA_FREE:
583         ctsvc_handle_destroy(contact);
584         ctsvc_server_start_timeout();
585         return;
586 }
587 void ctsvc_ipc_person_set_favorite_order(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
588 {
589         int ret = CONTACTS_ERROR_NONE;
590         int person_id = 0;
591         int previous_person_id;
592         int next_person_id;
593         contacts_h contact = NULL;
594
595         if (indata) {
596                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
597                 if (CONTACTS_ERROR_NONE != ret) {
598                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
599                         goto ERROR_RETURN;
600                 }
601                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
602                 if (ret != CONTACTS_ERROR_NONE) {
603                         ERR("ctsvc_ipc_unmarshal_int() Fail");
604                         goto ERROR_RETURN;
605                 }
606                 ret = ctsvc_ipc_unmarshal_int(indata, &previous_person_id);
607                 if (ret != CONTACTS_ERROR_NONE) {
608                         ERR("ctsvc_ipc_unmarshal_int() Fail");
609                         goto ERROR_RETURN;
610                 }
611                 ret = ctsvc_ipc_unmarshal_int(indata, &next_person_id);
612                 if (ret != CONTACTS_ERROR_NONE) {
613                         ERR("ctsvc_ipc_unmarshal_int() Fail");
614                         goto ERROR_RETURN;
615                 }
616         } else {
617                 ERR("ctsvc_ipc_person_link_person() Fail");
618                 goto ERROR_RETURN;
619         }
620
621         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
622                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
623                 goto ERROR_RETURN;
624         }
625
626         ret = ctsvc_person_set_favorite_order(person_id, previous_person_id, next_person_id);
627
628 ERROR_RETURN:
629
630         if (outdata) {
631                 *outdata = pims_ipc_data_create(0);
632                 if (NULL == *outdata) {
633                         ERR("pims_ipc_data_create() Fail");
634                         goto DATA_FREE;
635                 }
636                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
637                         pims_ipc_data_destroy(*outdata);
638                         *outdata = NULL;
639                         ERR("ctsvc_ipc_marshal_int() Fail");
640                         goto DATA_FREE;
641                 }
642                 if (ret == CONTACTS_ERROR_NONE) {
643                         int transaction_ver = ctsvc_get_transaction_ver();
644                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
645                                 pims_ipc_data_destroy(*outdata);
646                                 *outdata = NULL;
647                                 ERR("ctsvc_ipc_marshal_int() Fail");
648                                 goto DATA_FREE;
649                         }
650                 }
651         } else {
652                 ERR("outdata is NULL");
653         }
654 DATA_FREE:
655         ctsvc_handle_destroy(contact);
656         ctsvc_server_start_timeout();
657         return;
658 }
659
660 void ctsvc_ipc_person_set_default_property(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
661 {
662         int ret = CONTACTS_ERROR_NONE;
663         int person_id = 0;
664         int id;
665         contacts_person_property_e property;
666         contacts_h contact = NULL;
667
668         if (indata) {
669                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
670                 if (CONTACTS_ERROR_NONE != ret) {
671                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
672                         goto ERROR_RETURN;
673                 }
674                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
675                 if (ret != CONTACTS_ERROR_NONE) {
676                         ERR("ctsvc_ipc_unmarshal_int() Fail");
677                         goto ERROR_RETURN;
678                 }
679                 ret = ctsvc_ipc_unmarshal_unsigned_int(indata, &property);
680                 if (ret != CONTACTS_ERROR_NONE) {
681                         ERR("ctsvc_ipc_unmarshal_int() Fail");
682                         goto ERROR_RETURN;
683                 }
684                 ret = ctsvc_ipc_unmarshal_int(indata, &id);
685                 if (ret != CONTACTS_ERROR_NONE) {
686                         ERR("ctsvc_ipc_unmarshal_int() Fail");
687                         goto ERROR_RETURN;
688                 }
689         } else {
690                 ERR("ctsvc_ipc_person_set_default_property() Fail");
691                 goto ERROR_RETURN;
692         }
693
694         ret = ctsvc_person_set_default_property(property, person_id, id);
695
696 ERROR_RETURN:
697
698         if (outdata) {
699                 *outdata = pims_ipc_data_create(0);
700                 if (NULL == *outdata) {
701                         ERR("pims_ipc_data_create() Fail");
702                         goto DATA_FREE;
703                 }
704                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
705                         pims_ipc_data_destroy(*outdata);
706                         *outdata = NULL;
707                         ERR("ctsvc_ipc_marshal_int() Fail");
708                         goto DATA_FREE;
709                 }
710                 if (ret == CONTACTS_ERROR_NONE) {
711                         int transaction_ver = ctsvc_get_transaction_ver();
712                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
713                                 pims_ipc_data_destroy(*outdata);
714                                 *outdata = NULL;
715                                 ERR("ctsvc_ipc_marshal_int() Fail");
716                                 goto DATA_FREE;
717                         }
718                 }
719         } else {
720                 ERR("outdata is NULL");
721         }
722 DATA_FREE:
723         ctsvc_handle_destroy(contact);
724         ctsvc_server_start_timeout();
725         return;
726 }
727
728 void ctsvc_ipc_person_get_default_property(pims_ipc_h ipc, pims_ipc_data_h indata,
729                 pims_ipc_data_h *outdata, void *userdata)
730 {
731         int ret = CONTACTS_ERROR_NONE;
732         int person_id = 0;
733         int id;
734         contacts_person_property_e op;
735         contacts_h contact = NULL;
736         if (indata) {
737                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
738                 if (CONTACTS_ERROR_NONE != ret) {
739                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
740                         goto ERROR_RETURN;
741                 }
742                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
743                 if (ret != CONTACTS_ERROR_NONE) {
744                         ERR("ctsvc_ipc_unmarshal_int() Fail");
745                         goto ERROR_RETURN;
746                 }
747                 ret = ctsvc_ipc_unmarshal_unsigned_int(indata, &op);
748                 if (ret != CONTACTS_ERROR_NONE) {
749                         ERR("ctsvc_ipc_unmarshal_int() Fail");
750                         goto ERROR_RETURN;
751                 }
752         } else {
753                 ERR("ctsvc_ipc_person_get_default_property() Fail");
754                 goto ERROR_RETURN;
755         }
756
757         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_READ)) {
758                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
759                 goto ERROR_RETURN;
760         }
761
762         ret = ctsvc_person_get_default_property(op, person_id, &id);
763
764 ERROR_RETURN:
765
766         if (outdata) {
767                 *outdata = pims_ipc_data_create(0);
768                 if (NULL == *outdata) {
769                         ERR("pims_ipc_data_create() Fail");
770                         goto DATA_FREE;
771                 }
772                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
773                         pims_ipc_data_destroy(*outdata);
774                         *outdata = NULL;
775                         ERR("ctsvc_ipc_marshal_int() Fail (return value)");
776                         goto DATA_FREE;
777                 }
778                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(id, *outdata)) {
779                         pims_ipc_data_destroy(*outdata);
780                         *outdata = NULL;
781                         ERR("ctsvc_ipc_marshal_int() Fail (id)");
782                         goto DATA_FREE;
783                 }
784         } else {
785                 ERR("outdata is NULL");
786         }
787 DATA_FREE:
788         ctsvc_handle_destroy(contact);
789         ctsvc_server_start_timeout();
790         return;
791 }
792
793 void ctsvc_ipc_person_get_aggregation_suggestions(pims_ipc_h ipc, pims_ipc_data_h indata,
794                 pims_ipc_data_h *outdata, void *userdata)
795 {
796         int ret = CONTACTS_ERROR_NONE;
797         int person_id = 0;
798         int limit = 0;
799         contacts_list_h list = NULL;
800         contacts_h contact = NULL;
801
802         if (indata) {
803                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
804                 if (CONTACTS_ERROR_NONE != ret) {
805                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
806                         goto ERROR_RETURN;
807                 }
808                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
809                 if (ret != CONTACTS_ERROR_NONE) {
810                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
811                         goto ERROR_RETURN;
812                 }
813                 ret = ctsvc_ipc_unmarshal_int(indata, &limit);
814                 if (ret != CONTACTS_ERROR_NONE) {
815                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
816                         goto ERROR_RETURN;
817                 }
818         } else {
819                 ERR("ctsvc_ipc_person_get_aggregation_suggestions() Fail");
820                 goto ERROR_RETURN;
821         }
822
823         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_READ)) {
824                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
825                 goto ERROR_RETURN;
826         }
827
828         ret = ctsvc_person_get_aggregation_suggestions(person_id, limit, &list);
829
830 ERROR_RETURN:
831
832         if (outdata) {
833                 *outdata = pims_ipc_data_create(0);
834                 if (NULL == *outdata) {
835                         ERR("pims_ipc_data_create() Fail");
836                         goto DATA_FREE;
837                 }
838                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
839                         pims_ipc_data_destroy(*outdata);
840                         *outdata = NULL;
841                         ERR("ctsvc_ipc_marshal_int() Fail");
842                         goto DATA_FREE;
843                 }
844
845                 if (CONTACTS_ERROR_NO_DATA == ret) {
846                         DBG("no data");
847                 } else if (CONTACTS_ERROR_NONE == ret) {
848                         ret = ctsvc_ipc_marshal_list(list, *outdata);
849
850                         if (ret != CONTACTS_ERROR_NONE) {
851                                 ERR("ctsvc_ipc_marshal_list() Fail(%d)", ret);
852                                 goto DATA_FREE;
853                         }
854                 }
855         } else {
856                 ERR("outdata is NULL");
857         }
858 DATA_FREE:
859         ctsvc_handle_destroy(contact);
860         contacts_list_destroy(list, true);
861         ctsvc_server_start_timeout();
862         return;
863 }
864
865 #ifdef ENABLE_LOG_FEATURE
866 void ctsvc_ipc_phone_log_reset_statistics(pims_ipc_h ipc,
867                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
868 {
869         int ret;
870         contacts_h contact = NULL;
871
872         if (indata) {
873                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
874                 if (CONTACTS_ERROR_NONE != ret) {
875                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
876                         goto ERROR_RETURN;
877                 }
878         }
879
880         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_WRITE)) {
881                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
882                 goto ERROR_RETURN;
883         }
884
885         ret = ctsvc_phone_log_reset_statistics();
886
887 ERROR_RETURN:
888         if (outdata) {
889                 *outdata = pims_ipc_data_create(0);
890                 if (NULL == *outdata) {
891                         ERR("pims_ipc_data_create() Fail");
892                         goto DATA_FREE;
893                 }
894                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
895                         pims_ipc_data_destroy(*outdata);
896                         *outdata = NULL;
897                         ERR("ctsvc_ipc_marshal_int() Fail");
898                         goto DATA_FREE;
899                 }
900                 if (ret == CONTACTS_ERROR_NONE) {
901                         int transaction_ver = ctsvc_get_transaction_ver();
902                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
903                                 pims_ipc_data_destroy(*outdata);
904                                 *outdata = NULL;
905                                 ERR("ctsvc_ipc_marshal_int() Fail");
906                                 goto DATA_FREE;
907                         }
908                 }
909         } else {
910                 ERR("outdata is NULL");
911         }
912 DATA_FREE:
913         ctsvc_handle_destroy(contact);
914         ctsvc_server_start_timeout();
915         return;
916 }
917
918 void ctsvc_ipc_phone_log_reset_statistics_by_sim(pims_ipc_h ipc,
919                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
920 {
921         int ret;
922         int sim_slot_no;
923         contacts_h contact = NULL;
924
925         if (indata) {
926                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
927                 if (CONTACTS_ERROR_NONE != ret) {
928                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
929                         goto ERROR_RETURN;
930                 }
931
932                 ret = ctsvc_ipc_unmarshal_int(indata, &sim_slot_no);
933                 if (CONTACTS_ERROR_NONE != ret) {
934                         ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
935                         goto ERROR_RETURN;
936                 }
937         }
938
939         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_WRITE)) {
940                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
941                 goto ERROR_RETURN;
942         }
943
944         ret = ctsvc_phone_log_reset_statistics_by_sim(sim_slot_no);
945
946 ERROR_RETURN:
947         if (outdata) {
948                 *outdata = pims_ipc_data_create(0);
949                 if (NULL == *outdata) {
950                         ERR("pims_ipc_data_create() Fail");
951                         goto DATA_FREE;
952                 }
953                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
954                         pims_ipc_data_destroy(*outdata);
955                         *outdata = NULL;
956                         ERR("ctsvc_ipc_marshal_int() Fail");
957                         goto DATA_FREE;
958                 }
959                 if (CONTACTS_ERROR_NONE == ret) {
960                         int transaction_ver = ctsvc_get_transaction_ver();
961                         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(transaction_ver, *outdata)) {
962                                 pims_ipc_data_destroy(*outdata);
963                                 *outdata = NULL;
964                                 ERR("ctsvc_ipc_marshal_int() Fail");
965                                 goto DATA_FREE;
966                         }
967                 }
968         } else {
969                 ERR("outdata is NULL");
970         }
971 DATA_FREE:
972         ctsvc_handle_destroy(contact);
973         ctsvc_server_start_timeout();
974         return;
975 }
976
977
978 void ctsvc_ipc_phone_log_delete(pims_ipc_h ipc, pims_ipc_data_h indata,
979                 pims_ipc_data_h *outdata, void *userdata)
980 {
981         int ret = CONTACTS_ERROR_NONE;
982         int extra_data1;
983         char *number = NULL;
984         contacts_phone_log_delete_e op;
985         contacts_h contact = NULL;
986
987         if (indata) {
988                 ret = ctsvc_ipc_unmarshal_handle(indata, &contact);
989                 if (CONTACTS_ERROR_NONE != ret) {
990                         ERR("ctsvc_ipc_unmarshal_handle Fail(%d)", ret);
991                         goto ERROR_RETURN;
992                 }
993                 ret = ctsvc_ipc_unmarshal_int(indata, (int*)&op);
994                 if (ret != CONTACTS_ERROR_NONE) {
995                         ERR("ctsvc_ipc_unmarshal_int() Fail");
996                         goto ERROR_RETURN;
997                         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_WRITE)) {
998                                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
999                                 goto ERROR_RETURN;
1000                         }
1001
1002                 }
1003
1004                 switch (op) {
1005                 case CONTACTS_PHONE_LOG_DELETE_BY_ADDRESS:
1006                         ret = ctsvc_ipc_unmarshal_string(indata, &number);
1007                         if (ret != CONTACTS_ERROR_NONE) {
1008                                 ERR("ctsvc_ipc_unmarshal_string() Fail");
1009                                 goto ERROR_RETURN;
1010                         }
1011                         ret = ctsvc_phone_log_delete(op, number);
1012                         break;
1013                 case CONTACTS_PHONE_LOG_DELETE_BY_MESSAGE_EXTRA_DATA1:
1014                 case CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1:
1015                         ret = ctsvc_ipc_unmarshal_int(indata, &extra_data1);
1016                         if (ret != CONTACTS_ERROR_NONE) {
1017                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
1018                                 goto ERROR_RETURN;
1019                         }
1020                         ret = ctsvc_phone_log_delete(op, extra_data1);
1021                         break;
1022                 default:
1023                         ERR("the operation is not proper (op : %d)", op);
1024                         ret = CONTACTS_ERROR_INVALID_PARAMETER;
1025                         break;
1026                 }
1027         }
1028
1029 ERROR_RETURN:
1030         if (outdata) {
1031                 *outdata = pims_ipc_data_create(0);
1032                 if (NULL == *outdata) {
1033                         ERR("pims_ipc_data_create() Fail");
1034                         goto DATA_FREE;
1035                 }
1036                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1037                         pims_ipc_data_destroy(*outdata);
1038                         *outdata = NULL;
1039                         ERR("ctsvc_ipc_marshal_int() Fail");
1040                         goto DATA_FREE;
1041                 }
1042                 if (ret == CONTACTS_ERROR_NONE) {
1043                         int transaction_ver = ctsvc_get_transaction_ver();
1044                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
1045                                 pims_ipc_data_destroy(*outdata);
1046                                 *outdata = NULL;
1047                                 ERR("ctsvc_ipc_marshal_int() Fail");
1048                                 goto DATA_FREE;
1049                         }
1050                 }
1051         }
1052 DATA_FREE:
1053         ctsvc_handle_destroy(contact);
1054         free(number);
1055
1056         ctsvc_server_start_timeout();
1057         return;
1058 }
1059 #endif /* ENABLE_LOG_FEATURE */
1060
1061 void ctsvc_ipc_setting_get_name_display_order(pims_ipc_h ipc, pims_ipc_data_h indata,
1062                 pims_ipc_data_h *outdata, void *userdata)
1063 {
1064         int ret = CONTACTS_ERROR_NONE;
1065         contacts_name_display_order_e order;
1066
1067         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_READ)) {
1068                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1069                 goto ERROR_RETURN;
1070         }
1071
1072         ret = ctsvc_setting_get_name_display_order(&order);
1073
1074 ERROR_RETURN:
1075         if (outdata) {
1076                 *outdata = pims_ipc_data_create(0);
1077                 if (NULL == *outdata) {
1078                         ERR("pims_ipc_data_create() Fail");
1079                         ctsvc_server_start_timeout();
1080                         return;
1081                 }
1082                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1083                         pims_ipc_data_destroy(*outdata);
1084                         *outdata = NULL;
1085                         ERR("ctsvc_ipc_marshal_int() Fail (return value)");
1086                         ctsvc_server_start_timeout();
1087                         return;
1088                 }
1089                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(order, *outdata)) {
1090                         pims_ipc_data_destroy(*outdata);
1091                         *outdata = NULL;
1092                         ERR("ctsvc_ipc_marshal_int() Fail (id)");
1093                         ctsvc_server_start_timeout();
1094                         return;
1095                 }
1096         } else {
1097                 ERR("outdata is NULL");
1098         }
1099
1100         ctsvc_server_start_timeout();
1101         return;
1102 }
1103
1104 void ctsvc_ipc_setting_get_name_sorting_order(pims_ipc_h ipc, pims_ipc_data_h indata,
1105                 pims_ipc_data_h *outdata, void *userdata)
1106 {
1107         int ret = CONTACTS_ERROR_NONE;
1108         contacts_name_sorting_order_e order;
1109
1110         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_READ)) {
1111                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1112                 goto ERROR_RETURN;
1113         }
1114
1115         ret = ctsvc_setting_get_name_sorting_order(&order);
1116
1117 ERROR_RETURN:
1118         if (outdata) {
1119                 *outdata = pims_ipc_data_create(0);
1120                 if (NULL == *outdata) {
1121                         ERR("pims_ipc_data_create() Fail");
1122                         ctsvc_server_start_timeout();
1123                         return;
1124                 }
1125                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1126                         pims_ipc_data_destroy(*outdata);
1127                         *outdata = NULL;
1128                         ERR("ctsvc_ipc_marshal_int() Fail (return value)");
1129                         ctsvc_server_start_timeout();
1130                         return;
1131                 }
1132                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(order, *outdata)) {
1133                         pims_ipc_data_destroy(*outdata);
1134                         *outdata = NULL;
1135                         ERR("ctsvc_ipc_marshal_int() Fail (id)");
1136                         return;
1137                 }
1138         } else {
1139                 ERR("outdata is NULL");
1140         }
1141
1142         ctsvc_server_start_timeout();
1143         return;
1144 }
1145
1146 void ctsvc_ipc_setting_set_name_display_order(pims_ipc_h ipc,
1147                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
1148 {
1149         int ret = CONTACTS_ERROR_NONE;
1150         int order;
1151
1152         if (indata) {
1153                 ret = ctsvc_ipc_unmarshal_int(indata, &order);
1154                 if (ret != CONTACTS_ERROR_NONE) {
1155                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1156                         goto ERROR_RETURN;
1157                 }
1158         } else {
1159                 ERR("ctsvc_ipc_person_set_default_property() Fail");
1160                 goto ERROR_RETURN;
1161         }
1162
1163         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
1164                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1165                 goto ERROR_RETURN;
1166         }
1167
1168         ret = ctsvc_setting_set_name_display_order((contacts_name_display_order_e)order);
1169
1170 ERROR_RETURN:
1171         if (outdata) {
1172                 *outdata = pims_ipc_data_create(0);
1173                 if (NULL == *outdata) {
1174                         ERR("pims_ipc_data_create() Fail");
1175                         ctsvc_server_start_timeout();
1176                         return;
1177                 }
1178                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1179                         pims_ipc_data_destroy(*outdata);
1180                         *outdata = NULL;
1181                         ERR("ctsvc_ipc_marshal_int() Fail");
1182                         ctsvc_server_start_timeout();
1183                         return;
1184                 }
1185         } else {
1186                 ERR("outdata is NULL");
1187         }
1188
1189         ctsvc_server_start_timeout();
1190         return;
1191 }
1192
1193 void ctsvc_ipc_setting_set_name_sorting_order(pims_ipc_h ipc,
1194                 pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
1195 {
1196         int ret = CONTACTS_ERROR_NONE;
1197         int order;
1198
1199         if (indata) {
1200                 ret = ctsvc_ipc_unmarshal_int(indata, &order);
1201                 if (ret != CONTACTS_ERROR_NONE) {
1202                         ERR("ctsvc_ipc_unmarshal_int() Fail");
1203                         goto ERROR_RETURN;
1204                 }
1205         } else {
1206                 ERR("ctsvc_ipc_person_set_default_property() Fail");
1207                 goto ERROR_RETURN;
1208         }
1209
1210         if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_CONTACT_WRITE)) {
1211                 ret = CONTACTS_ERROR_PERMISSION_DENIED;
1212                 goto ERROR_RETURN;
1213         }
1214
1215         ret = ctsvc_setting_set_name_sorting_order((contacts_name_sorting_order_e)order);
1216
1217 ERROR_RETURN:
1218         if (outdata) {
1219                 *outdata = pims_ipc_data_create(0);
1220                 if (NULL == *outdata) {
1221                         ERR("pims_ipc_data_create() Fail");
1222                         ctsvc_server_start_timeout();
1223                         return;
1224                 }
1225                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
1226                         pims_ipc_data_destroy(*outdata);
1227                         *outdata = NULL;
1228                         ERR("ctsvc_ipc_marshal_int() Fail");
1229                         ctsvc_server_start_timeout();
1230                         return;
1231                 }
1232         } else {
1233                 ERR("outdata is NULL");
1234         }
1235
1236         ctsvc_server_start_timeout();
1237         return;
1238 }
1239