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