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