merge with master
[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 "ctsvc_service.h"
23 #include "ctsvc_db_init.h"
24
25 #include "ctsvc_ipc_marshal.h"
26 #include "ctsvc_internal.h"
27 #include "ctsvc_ipc_server.h"
28 #include "ctsvc_utils.h"
29
30
31 void ctsvc_ipc_activity_delete_by_contact_id(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
32 {
33         int ret = CONTACTS_ERROR_NONE;
34         int contact_id = 0;
35
36         if (indata)
37         {
38                 ret = ctsvc_ipc_unmarshal_int(indata, &contact_id);
39                 if (ret != CONTACTS_ERROR_NONE)
40                 {
41                         ERR("ctsvc_ipc_unmarshal_int fail");
42                         goto ERROR_RETURN;
43                 }
44         }
45         else
46         {
47                 ERR("ctsvc_ipc_server_db_insert_record fail");
48                 goto ERROR_RETURN;
49         }
50
51         ret = contacts_activity_delete_by_contact_id(contact_id);
52
53
54 ERROR_RETURN:
55
56         if (outdata)
57         {
58                 *outdata = pims_ipc_data_create(0);
59                 if (!*outdata)
60                 {
61                         ERR("pims_ipc_data_create fail");
62                         return;
63                 }
64                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
65                 {
66                         pims_ipc_data_destroy(*outdata);
67                         *outdata = NULL;
68                         ERR("pims_ipc_data_put fail");
69                         return;
70                 }
71
72                 if (ret == CONTACTS_ERROR_NONE) {
73                         int transaction_ver = ctsvc_get_transaction_ver();
74                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
75                                 pims_ipc_data_destroy(*outdata);
76                                 *outdata = NULL;
77                                 ERR("ctsvc_ipc_marshal_int fail");
78                                 return;
79                         }
80                 }
81         }
82         else
83         {
84                 ERR("outdata is NULL");
85         }
86
87         return;
88 }
89
90 void ctsvc_ipc_activity_delete_by_account_id(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
91 {
92         int ret = CONTACTS_ERROR_NONE;
93         int account_id = 0;
94
95         if (indata)
96         {
97                 ret = ctsvc_ipc_unmarshal_int(indata, &account_id);
98                 if (ret != CONTACTS_ERROR_NONE)
99                 {
100                         ERR("ctsvc_ipc_unmarshal_int fail");
101                         goto ERROR_RETURN;
102                 }
103         }
104         else
105         {
106                 ERR("ctsvc_ipc_activity_delete_by_account_id fail");
107                 goto ERROR_RETURN;
108         }
109
110         ret = contacts_activity_delete_by_account_id(account_id);
111
112 ERROR_RETURN:
113
114         if (outdata)
115         {
116                 *outdata = pims_ipc_data_create(0);
117                 if (!*outdata)
118                 {
119                         ERR("pims_ipc_data_create fail");
120                         return;
121                 }
122                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
123                 {
124                         pims_ipc_data_destroy(*outdata);
125                         *outdata = NULL;
126                         ERR("pims_ipc_data_put fail");
127                         return;
128                 }
129
130                 if (ret == CONTACTS_ERROR_NONE) {
131                         int transaction_ver = ctsvc_get_transaction_ver();
132                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
133                                 pims_ipc_data_destroy(*outdata);
134                                 *outdata = NULL;
135                                 ERR("ctsvc_ipc_marshal_int fail");
136                                 return;
137                         }
138                 }
139         }
140         else
141         {
142                 ERR("outdata is NULL");
143         }
144
145         return;
146 }
147
148 void ctsvc_ipc_group_add_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
149 {
150         int ret = CONTACTS_ERROR_NONE;
151         int group_id = 0;
152         int contact_id = 0;
153
154         if (indata)
155         {
156                 ret = ctsvc_ipc_unmarshal_int(indata, &group_id);
157                 if (ret != CONTACTS_ERROR_NONE)
158                 {
159                         ERR("ctsvc_ipc_unmarshal_int fail");
160                         goto ERROR_RETURN;
161                 }
162                 ret = ctsvc_ipc_unmarshal_int(indata, &contact_id);
163                 if (ret != CONTACTS_ERROR_NONE)
164                 {
165                         ERR("ctsvc_ipc_unmarshal_int fail");
166                         goto ERROR_RETURN;
167                 }
168         }
169         else
170         {
171                 ERR("ctsvc_ipc_group_add_contact fail");
172                 goto ERROR_RETURN;
173         }
174
175         ret = contacts_group_add_contact(group_id, contact_id);
176
177 ERROR_RETURN:
178
179         if (outdata)
180         {
181                 *outdata = pims_ipc_data_create(0);
182                 if (!*outdata)
183                 {
184                         ERR("pims_ipc_data_create fail");
185                         return;
186                 }
187                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
188                 {
189                         pims_ipc_data_destroy(*outdata);
190                         *outdata = NULL;
191                         ERR("pims_ipc_data_put fail");
192                         return;
193                 }
194
195                 if (ret == CONTACTS_ERROR_NONE) {
196                         int transaction_ver = ctsvc_get_transaction_ver();
197                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
198                                 pims_ipc_data_destroy(*outdata);
199                                 *outdata = NULL;
200                                 ERR("ctsvc_ipc_marshal_int fail");
201                                 return;
202                         }
203                 }
204         }
205         else
206         {
207                 ERR("outdata is NULL");
208         }
209
210         return;
211 }
212
213 void ctsvc_ipc_group_remove_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
214 {
215         int ret = CONTACTS_ERROR_NONE;
216         int group_id = 0;
217         int contact_id = 0;
218
219         if (indata)
220         {
221                 ret = ctsvc_ipc_unmarshal_int(indata, &group_id);
222                 if (ret != CONTACTS_ERROR_NONE)
223                 {
224                         ERR("ctsvc_ipc_unmarshal_int fail");
225                         goto ERROR_RETURN;
226                 }
227                 ret = ctsvc_ipc_unmarshal_int(indata, &contact_id);
228                 if (ret != CONTACTS_ERROR_NONE)
229                 {
230                         ERR("ctsvc_ipc_unmarshal_int fail");
231                         goto ERROR_RETURN;
232                 }
233         }
234         else
235         {
236                 ERR("ctsvc_ipc_group_remove_contact fail");
237                 goto ERROR_RETURN;
238         }
239
240         ret = contacts_group_remove_contact(group_id, contact_id);
241
242 ERROR_RETURN:
243
244         if (outdata)
245         {
246                 *outdata = pims_ipc_data_create(0);
247                 if (!*outdata)
248                 {
249                         ERR("pims_ipc_data_create fail");
250                         return;
251                 }
252                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
253                 {
254                         pims_ipc_data_destroy(*outdata);
255                         *outdata = NULL;
256                         ERR("pims_ipc_data_put fail");
257                         return;
258                 }
259                 if (ret == CONTACTS_ERROR_NONE) {
260                         int transaction_ver = ctsvc_get_transaction_ver();
261                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
262                                 pims_ipc_data_destroy(*outdata);
263                                 *outdata = NULL;
264                                 ERR("ctsvc_ipc_marshal_int fail");
265                                 return;
266                         }
267                 }
268
269         }
270         else
271         {
272                 ERR("outdata is NULL");
273         }
274
275         return;
276 }
277
278 void ctsvc_ipc_group_set_group_order(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
279 {
280         int ret = CONTACTS_ERROR_NONE;
281         int group_id = 0;
282         int previous_group_id;
283         int next_group_id;
284
285         if (indata)
286         {
287                 ret = ctsvc_ipc_unmarshal_int(indata, &group_id);
288                 if (ret != CONTACTS_ERROR_NONE)
289                 {
290                         ERR("ctsvc_ipc_unmarshal_int fail");
291                         goto ERROR_RETURN;
292                 }
293                 ret = ctsvc_ipc_unmarshal_int(indata, &previous_group_id);
294                 if (ret != CONTACTS_ERROR_NONE)
295                 {
296                         ERR("ctsvc_ipc_unmarshal_int fail");
297                         goto ERROR_RETURN;
298                 }
299                 ret = ctsvc_ipc_unmarshal_int(indata, &next_group_id);
300                 if (ret != CONTACTS_ERROR_NONE)
301                 {
302                         ERR("ctsvc_ipc_unmarshal_int fail");
303                         goto ERROR_RETURN;
304                 }
305         }
306         else
307         {
308                 ERR("ctsvc_ipc_group_link_group fail");
309                 goto ERROR_RETURN;
310         }
311
312         ret = contacts_group_set_group_order(group_id, previous_group_id, next_group_id );
313
314 ERROR_RETURN:
315
316         if (outdata)
317         {
318                 *outdata = pims_ipc_data_create(0);
319                 if (!*outdata)
320                 {
321                         ERR("pims_ipc_data_create fail");
322                         return;
323                 }
324                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
325                 {
326                         pims_ipc_data_destroy(*outdata);
327                         *outdata = NULL;
328                         ERR("pims_ipc_data_put fail");
329                         return;
330                 }
331                 if (ret == CONTACTS_ERROR_NONE) {
332                         int transaction_ver = ctsvc_get_transaction_ver();
333                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
334                                 pims_ipc_data_destroy(*outdata);
335                                 *outdata = NULL;
336                                 ERR("ctsvc_ipc_marshal_int fail");
337                                 return;
338                         }
339                 }
340         }
341         else
342         {
343                 ERR("outdata is NULL");
344         }
345
346         return;
347 }
348
349 void ctsvc_ipc_person_link_person(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
350 {
351         int ret = CONTACTS_ERROR_NONE;
352         int base_person_id = 0;
353         int person_id = 0;
354
355         if (indata)
356         {
357                 ret = ctsvc_ipc_unmarshal_int(indata, &base_person_id);
358                 if (ret != CONTACTS_ERROR_NONE)
359                 {
360                         ERR("ctsvc_ipc_unmarshal_int fail");
361                         goto ERROR_RETURN;
362                 }
363                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
364                 if (ret != CONTACTS_ERROR_NONE)
365                 {
366                         ERR("ctsvc_ipc_unmarshal_int fail");
367                         goto ERROR_RETURN;
368                 }
369         }
370         else
371         {
372                 ERR("ctsvc_ipc_person_link_person fail");
373                 goto ERROR_RETURN;
374         }
375
376         ret = contacts_person_link_person(base_person_id, person_id);
377
378 ERROR_RETURN:
379
380         if (outdata)
381         {
382                 *outdata = pims_ipc_data_create(0);
383                 if (!*outdata)
384                 {
385                         ERR("pims_ipc_data_create fail");
386                         return;
387                 }
388                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
389                 {
390                         pims_ipc_data_destroy(*outdata);
391                         *outdata = NULL;
392                         ERR("pims_ipc_data_put fail");
393                         return;
394                 }
395                 if (ret == CONTACTS_ERROR_NONE) {
396                         int transaction_ver = ctsvc_get_transaction_ver();
397                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
398                                 pims_ipc_data_destroy(*outdata);
399                                 *outdata = NULL;
400                                 ERR("ctsvc_ipc_marshal_int fail");
401                                 return;
402                         }
403                 }
404         }
405         else
406         {
407                 ERR("outdata is NULL");
408         }
409
410         return;
411 }
412 void ctsvc_ipc_person_unlink_contact(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
413 {
414         int ret = CONTACTS_ERROR_NONE;
415         int person_id = 0;
416         int contact_id = 0;
417
418         if (indata)
419         {
420                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
421                 if (ret != CONTACTS_ERROR_NONE)
422                 {
423                         ERR("ctsvc_ipc_unmarshal_int fail");
424                         goto ERROR_RETURN;
425                 }
426                 ret = ctsvc_ipc_unmarshal_int(indata, &contact_id);
427                 if (ret != CONTACTS_ERROR_NONE)
428                 {
429                         ERR("ctsvc_ipc_unmarshal_int fail");
430                         goto ERROR_RETURN;
431                 }
432         }
433         else
434         {
435                 ERR("ctsvc_ipc_person_link_person fail");
436                 goto ERROR_RETURN;
437         }
438
439         int unlinked_person_id;
440         ret = contacts_person_unlink_contact(person_id, contact_id, &unlinked_person_id);
441
442 ERROR_RETURN:
443
444         if (outdata)
445         {
446                 *outdata = pims_ipc_data_create(0);
447                 if (!*outdata)
448                 {
449                         ERR("pims_ipc_data_create fail");
450                         return;
451                 }
452                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
453                 {
454                         pims_ipc_data_destroy(*outdata);
455                         *outdata = NULL;
456                         ERR("pims_ipc_data_put fail");
457                         return;
458                 }
459                 if (ret == CONTACTS_ERROR_NONE) {
460                         int transaction_ver = ctsvc_get_transaction_ver();
461                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
462                                 pims_ipc_data_destroy(*outdata);
463                                 *outdata = NULL;
464                                 ERR("ctsvc_ipc_marshal_int fail");
465                                 return;
466                         }
467                 }
468                 if (pims_ipc_data_put(*outdata, (void*)&unlinked_person_id, sizeof(int)) != 0)
469                 {
470                         pims_ipc_data_destroy(*outdata);
471                         *outdata = NULL;
472                         ERR("pims_ipc_data_put fail");
473                 }
474
475         }
476         else
477         {
478                 ERR("outdata is NULL");
479         }
480
481         return;
482 }
483 void ctsvc_ipc_person_reset_usage(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
484 {
485         int ret = CONTACTS_ERROR_NONE;
486         int person_id = 0;
487         contacts_usage_type_e type;
488
489         if (indata)
490         {
491                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
492                 if (ret != CONTACTS_ERROR_NONE)
493                 {
494                         ERR("ctsvc_ipc_unmarshal_int fail");
495                         goto ERROR_RETURN;
496                 }
497                 int temp = 0;
498                 ret = ctsvc_ipc_unmarshal_int(indata, &temp);
499                 type = (int)temp;
500                 if (ret != CONTACTS_ERROR_NONE)
501                 {
502                         ERR("ctsvc_ipc_unmarshal_int fail");
503                         goto ERROR_RETURN;
504                 }
505         }
506         else
507         {
508                 ERR("ctsvc_ipc_person_link_person fail");
509                 goto ERROR_RETURN;
510         }
511
512         ret = contacts_person_reset_usage(person_id, type);
513
514 ERROR_RETURN:
515
516         if (outdata)
517         {
518                 *outdata = pims_ipc_data_create(0);
519                 if (!*outdata)
520                 {
521                         ERR("pims_ipc_data_create fail");
522                         return;
523                 }
524                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
525                 {
526                         pims_ipc_data_destroy(*outdata);
527                         *outdata = NULL;
528                         ERR("pims_ipc_data_put fail");
529                         return;
530                 }
531                 if (ret == CONTACTS_ERROR_NONE) {
532                         int transaction_ver = ctsvc_get_transaction_ver();
533                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
534                                 pims_ipc_data_destroy(*outdata);
535                                 *outdata = NULL;
536                                 ERR("ctsvc_ipc_marshal_int fail");
537                                 return;
538                         }
539                 }
540         }
541         else
542         {
543                 ERR("outdata is NULL");
544         }
545
546         return;
547 }
548 void ctsvc_ipc_person_set_favorite_order(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
549 {
550         int ret = CONTACTS_ERROR_NONE;
551         int person_id = 0;
552         int previous_person_id;
553         int next_person_id;
554
555         if (indata)
556         {
557                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
558                 if (ret != CONTACTS_ERROR_NONE)
559                 {
560                         ERR("ctsvc_ipc_unmarshal_int fail");
561                         goto ERROR_RETURN;
562                 }
563                 ret = ctsvc_ipc_unmarshal_int(indata, &previous_person_id);
564                 if (ret != CONTACTS_ERROR_NONE)
565                 {
566                         ERR("ctsvc_ipc_unmarshal_int fail");
567                         goto ERROR_RETURN;
568                 }
569                 ret = ctsvc_ipc_unmarshal_int(indata, &next_person_id);
570                 if (ret != CONTACTS_ERROR_NONE)
571                 {
572                         ERR("ctsvc_ipc_unmarshal_int fail");
573                         goto ERROR_RETURN;
574                 }
575         }
576         else
577         {
578                 ERR("ctsvc_ipc_person_link_person fail");
579                 goto ERROR_RETURN;
580         }
581
582         ret = contacts_person_set_favorite_order(person_id, previous_person_id, next_person_id );
583
584 ERROR_RETURN:
585
586         if (outdata)
587         {
588                 *outdata = pims_ipc_data_create(0);
589                 if (!*outdata)
590                 {
591                         ERR("pims_ipc_data_create fail");
592                         return;
593                 }
594                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
595                 {
596                         pims_ipc_data_destroy(*outdata);
597                         *outdata = NULL;
598                         ERR("pims_ipc_data_put fail");
599                         return;
600                 }
601                 if (ret == CONTACTS_ERROR_NONE) {
602                         int transaction_ver = ctsvc_get_transaction_ver();
603                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
604                                 pims_ipc_data_destroy(*outdata);
605                                 *outdata = NULL;
606                                 ERR("ctsvc_ipc_marshal_int fail");
607                                 return;
608                         }
609                 }
610         }
611         else
612         {
613                 ERR("outdata is NULL");
614         }
615
616         return;
617 }
618
619 void ctsvc_ipc_person_set_default_property(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
620 {
621         int ret = CONTACTS_ERROR_NONE;
622         int person_id = 0;
623         int id;
624         contacts_person_property_e property;
625
626         if (indata)
627         {
628                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
629                 if (ret != CONTACTS_ERROR_NONE)
630                 {
631                         ERR("ctsvc_ipc_unmarshal_int fail");
632                         goto ERROR_RETURN;
633                 }
634                 ret = ctsvc_ipc_unmarshal_unsigned_int(indata, &property);
635                 if (ret != CONTACTS_ERROR_NONE)
636                 {
637                         ERR("ctsvc_ipc_unmarshal_int fail");
638                         goto ERROR_RETURN;
639                 }
640                 ret = ctsvc_ipc_unmarshal_int(indata, &id);
641                 if (ret != CONTACTS_ERROR_NONE)
642                 {
643                         ERR("ctsvc_ipc_unmarshal_int fail");
644                         goto ERROR_RETURN;
645                 }
646         }
647         else
648         {
649                 ERR("ctsvc_ipc_person_set_default_property fail");
650                 goto ERROR_RETURN;
651         }
652
653         ret = contacts_person_set_default_property(property, person_id, id );
654
655 ERROR_RETURN:
656
657         if (outdata)
658         {
659                 *outdata = pims_ipc_data_create(0);
660                 if (!*outdata)
661                 {
662                         ERR("pims_ipc_data_create fail");
663                         return;
664                 }
665                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
666                 {
667                         pims_ipc_data_destroy(*outdata);
668                         *outdata = NULL;
669                         ERR("pims_ipc_data_put fail");
670                         return;
671                 }
672                 if (ret == CONTACTS_ERROR_NONE) {
673                         int transaction_ver = ctsvc_get_transaction_ver();
674                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
675                                 pims_ipc_data_destroy(*outdata);
676                                 *outdata = NULL;
677                                 ERR("ctsvc_ipc_marshal_int fail");
678                                 return;
679                         }
680                 }
681         }
682         else
683         {
684                 ERR("outdata is NULL");
685         }
686
687         return;
688 }
689
690 void ctsvc_ipc_person_get_default_property(pims_ipc_h ipc, pims_ipc_data_h indata,
691                 pims_ipc_data_h *outdata, void *userdata)
692 {
693         int ret = CONTACTS_ERROR_NONE;
694         int person_id = 0;
695         int id;
696         contacts_person_property_e op;
697
698         if (indata) {
699                 ret = ctsvc_ipc_unmarshal_int(indata, &person_id);
700                 if (ret != CONTACTS_ERROR_NONE) {
701                         ERR("ctsvc_ipc_unmarshal_int fail");
702                         goto ERROR_RETURN;
703                 }
704                 ret = ctsvc_ipc_unmarshal_unsigned_int(indata, &op);
705                 if (ret != CONTACTS_ERROR_NONE) {
706                         ERR("ctsvc_ipc_unmarshal_int fail");
707                         goto ERROR_RETURN;
708                 }
709         }
710         else {
711                 ERR("ctsvc_ipc_person_get_default_property fail");
712                 goto ERROR_RETURN;
713         }
714
715         ret = contacts_person_get_default_property(op, person_id, &id );
716
717 ERROR_RETURN:
718
719         if (outdata) {
720                 *outdata = pims_ipc_data_create(0);
721                 if (!*outdata) {
722                         ERR("pims_ipc_data_create fail");
723                         return;
724                 }
725                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
726                         pims_ipc_data_destroy(*outdata);
727                         *outdata = NULL;
728                         ERR("pims_ipc_data_put fail (return value)");
729                         return;
730                 }
731                 if (pims_ipc_data_put(*outdata, (void*)&id, sizeof(int)) != 0) {
732                         pims_ipc_data_destroy(*outdata);
733                         *outdata = NULL;
734                         ERR("pims_ipc_data_put fail (id)");
735                         return;
736                 }
737         }
738         else {
739                 ERR("outdata is NULL");
740         }
741
742         return;
743 }
744
745 void ctsvc_ipc_phone_log_reset_statistics(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
746 {
747         int ret = contacts_phone_log_reset_statistics();
748
749         if (outdata)
750         {
751                 *outdata = pims_ipc_data_create(0);
752                 if (!*outdata)
753                 {
754                         ERR("pims_ipc_data_create fail");
755                         return;
756                 }
757                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0)
758                 {
759                         pims_ipc_data_destroy(*outdata);
760                         *outdata = NULL;
761                         ERR("pims_ipc_data_put fail");
762                         return;
763                 }
764                 if (ret == CONTACTS_ERROR_NONE) {
765                         int transaction_ver = ctsvc_get_transaction_ver();
766                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
767                                 pims_ipc_data_destroy(*outdata);
768                                 *outdata = NULL;
769                                 ERR("ctsvc_ipc_marshal_int fail");
770                                 return;
771                         }
772                 }
773         }
774         else
775         {
776                 ERR("outdata is NULL");
777         }
778
779         return;
780 }
781
782 void ctsvc_ipc_phone_log_delete(pims_ipc_h ipc, pims_ipc_data_h indata,
783                 pims_ipc_data_h *outdata, void *userdata)
784 {
785         int ret= CONTACTS_ERROR_NONE;
786         int extra_data1;
787         char *number = NULL;
788         contacts_phone_log_delete_e op;
789
790         if (indata) {
791                 ret = ctsvc_ipc_unmarshal_int(indata, (int*)&op);
792                 if (ret != CONTACTS_ERROR_NONE) {
793                         ERR("ctsvc_ipc_unmarshal_int fail");
794                         goto ERROR_RETURN;
795                 }
796
797                 switch(op){
798                 case CONTACTS_PHONE_LOG_DELETE_BY_ADDRESS:
799                         ret = ctsvc_ipc_unmarshal_string(indata, &number);
800                         if (ret != CONTACTS_ERROR_NONE) {
801                                 ERR("ctsvc_ipc_unmarshal_string fail");
802                                 goto ERROR_RETURN;
803                         }
804                         ret = contacts_phone_log_delete(op, number);
805                         break;
806                 case CONTACTS_PHONE_LOG_DELETE_BY_MESSAGE_EXTRA_DATA1:
807                 case CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1:
808                         ret = ctsvc_ipc_unmarshal_int(indata, &extra_data1);
809                         if (ret != CONTACTS_ERROR_NONE) {
810                                 ERR("ctsvc_ipc_unmarshal_int fail");
811                                 goto ERROR_RETURN;
812                         }
813                         ret = contacts_phone_log_delete(op, extra_data1);
814                         break;
815                 default:
816                         ERR("Invalid parameter : the operation is not proper (op : %d)", op);
817                         ret = CONTACTS_ERROR_INVALID_PARAMETER;
818                         break;
819                 }
820         }
821
822 ERROR_RETURN:
823         if (outdata) {
824                 *outdata = pims_ipc_data_create(0);
825                 if (!*outdata) {
826                         ERR("pims_ipc_data_create fail");
827                         return;
828                 }
829                 if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
830                         pims_ipc_data_destroy(*outdata);
831                         *outdata = NULL;
832                         ERR("pims_ipc_data_put fail");
833                         return;
834                 }
835                 if (ret == CONTACTS_ERROR_NONE) {
836                         int transaction_ver = ctsvc_get_transaction_ver();
837                         if (ctsvc_ipc_marshal_int(transaction_ver, *outdata) != CONTACTS_ERROR_NONE) {
838                                 pims_ipc_data_destroy(*outdata);
839                                 *outdata = NULL;
840                                 ERR("ctsvc_ipc_marshal_int fail");
841                                 return;
842                         }
843                 }
844         }
845 }
846