rm useless (not used,set to readonly)functions
[platform/core/pim/contacts-service.git] / common / ipc / ctsvc_ipc_marshal.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <stdlib.h>
21 #include <string.h>
22 #include "ctsvc_ipc_marshal.h"
23 #include "contacts_record.h"
24 #include "ctsvc_internal.h"
25 #include "contacts_query.h"
26 #include "contacts_filter.h"
27 #include "contacts_list.h"
28 #include "ctsvc_list.h"
29
30 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_contact_plugin_cb;
31 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_my_profile_plugin_cb;
32 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_addressbook_plugin_cb;
33 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_group_plugin_cb;
34 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_person_plugin_cb;
35 #ifdef ENABLE_LOG_FEATURE
36 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_phonelog_plugin_cb;
37 #endif /* ENABLE_LOG_FEATURE */
38 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_result_plugin_cb;
39 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_sdn_plugin_cb;
40 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_speeddial_plugin_cb;
41 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_updated_info_plugin_cb;
42
43 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_simple_contact_plugin_cb;
44 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_address_plugin_cb;
45 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_activity_plugin_cb;
46 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_activity_photo_plugin_cb;
47 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_company_plugin_cb;
48 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_email_plugin_cb;
49 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_event_plugin_cb;
50 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_extension_plugin_cb;
51 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_group_relation_plugin_cb;
52 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_messenger_plugin_cb;
53 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_name_plugin_cb;
54 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_nickname_plugin_cb;
55 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_note_plugin_cb;
56 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_number_plugin_cb;
57 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_profile_plugin_cb;
58 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_relationship_plugin_cb;
59 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_url_plugin_cb;
60 extern ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_image_plugin_cb;
61
62 static ctsvc_ipc_marshal_record_plugin_cb_s* __ctsvc_ipc_marshal_get_plugin_cb(ctsvc_record_type_e type);
63
64
65 static int __ctsvc_ipc_unmarshal_composite_filter(const pims_ipc_data_h ipc_data, ctsvc_composite_filter_s* filter);
66 static int __ctsvc_ipc_marshal_composite_filter(const ctsvc_composite_filter_s* filter, pims_ipc_data_h ipc_data);
67 static int __ctsvc_ipc_unmarshal_attribute_filter(const pims_ipc_data_h ipc_data, const ctsvc_filter_type_e filter_type, ctsvc_attribute_filter_s* filter);
68 static int __ctsvc_ipc_marshal_attribute_filter(const ctsvc_attribute_filter_s* filter, pims_ipc_data_h ipc_data);
69
70
71 static ctsvc_ipc_marshal_record_plugin_cb_s* __ctsvc_ipc_marshal_get_plugin_cb(ctsvc_record_type_e type)
72 {
73         switch (type) {
74         case CTSVC_RECORD_ADDRESSBOOK:
75                 return (&_ctsvc_ipc_record_addressbook_plugin_cb);
76         case CTSVC_RECORD_GROUP:
77                 return (&_ctsvc_ipc_record_group_plugin_cb);
78         case CTSVC_RECORD_PERSON:
79                 return (&_ctsvc_ipc_record_person_plugin_cb);
80         case CTSVC_RECORD_CONTACT:
81                 return (&_ctsvc_ipc_record_contact_plugin_cb);
82         case CTSVC_RECORD_MY_PROFILE:
83                 return (&_ctsvc_ipc_record_my_profile_plugin_cb);
84         case CTSVC_RECORD_UPDATED_INFO:
85                 return (&_ctsvc_ipc_record_updated_info_plugin_cb);
86 #ifdef ENABLE_LOG_FEATURE
87         case CTSVC_RECORD_PHONELOG:
88                 return (&_ctsvc_ipc_record_phonelog_plugin_cb);
89 #endif /* ENABLE_LOG_FEATURE */
90         case CTSVC_RECORD_SPEEDDIAL:
91                 return (&_ctsvc_ipc_record_speeddial_plugin_cb);
92         case CTSVC_RECORD_SDN:
93                 return (&_ctsvc_ipc_record_sdn_plugin_cb);
94         case CTSVC_RECORD_RESULT:
95                 return (&_ctsvc_ipc_record_result_plugin_cb);
96         case CTSVC_RECORD_SIMPLE_CONTACT:
97                 return &_ctsvc_ipc_record_simple_contact_plugin_cb;
98         case CTSVC_RECORD_NAME:
99                 return (&_ctsvc_ipc_record_name_plugin_cb);
100         case CTSVC_RECORD_COMPANY:
101                 return (&_ctsvc_ipc_record_company_plugin_cb);
102         case CTSVC_RECORD_NOTE:
103                 return (&_ctsvc_ipc_record_note_plugin_cb);
104         case CTSVC_RECORD_NUMBER:
105                 return (&_ctsvc_ipc_record_number_plugin_cb);
106         case CTSVC_RECORD_EMAIL:
107                 return (&_ctsvc_ipc_record_email_plugin_cb);
108         case CTSVC_RECORD_URL:
109                 return (&_ctsvc_ipc_record_url_plugin_cb);
110         case CTSVC_RECORD_EVENT:
111                 return (&_ctsvc_ipc_record_event_plugin_cb);
112         case CTSVC_RECORD_NICKNAME:
113                 return (&_ctsvc_ipc_record_nickname_plugin_cb);
114         case CTSVC_RECORD_ADDRESS:
115                 return (&_ctsvc_ipc_record_address_plugin_cb);
116         case CTSVC_RECORD_MESSENGER:
117                 return (&_ctsvc_ipc_record_messenger_plugin_cb);
118         case CTSVC_RECORD_GROUP_RELATION:
119                 return (&_ctsvc_ipc_record_group_relation_plugin_cb);
120         case CTSVC_RECORD_ACTIVITY:
121                 return (&_ctsvc_ipc_record_activity_plugin_cb);
122         case CTSVC_RECORD_ACTIVITY_PHOTO:
123                 return (&_ctsvc_ipc_record_activity_photo_plugin_cb);
124         case CTSVC_RECORD_PROFILE:
125                 return (&_ctsvc_ipc_record_profile_plugin_cb);
126         case CTSVC_RECORD_RELATIONSHIP:
127                 return (&_ctsvc_ipc_record_relationship_plugin_cb);
128         case CTSVC_RECORD_IMAGE:
129                 return (&_ctsvc_ipc_record_image_plugin_cb);
130         case CTSVC_RECORD_EXTENSION:
131                 return (&_ctsvc_ipc_record_extension_plugin_cb);
132         default:
133                 ASSERT_NOT_REACHED("Unimplemented IPC module (%d)", type);
134                 return NULL;
135         }
136 }
137
138 static void __ctsvc_ipc_unmarshal_composite_filter_free(ctsvc_composite_filter_s* filter)
139 {
140         if (filter->filters) {
141                 GSList *cursor = NULL;
142                 for (cursor=filter->filters;cursor;cursor=cursor->next) {
143                         ctsvc_filter_s *src = (ctsvc_filter_s*)cursor->data;
144                         if (src->filter_type == CTSVC_FILTER_COMPOSITE)
145                                 __ctsvc_ipc_unmarshal_composite_filter_free((ctsvc_composite_filter_s *)src);
146                         else {
147                                 ctsvc_attribute_filter_s *attr = (ctsvc_attribute_filter_s *)src;
148                                 if (attr->filter_type == CTSVC_FILTER_STR)
149                                         free(attr->value.s);
150                         }
151                         free(src);
152                 }
153                 g_slist_free(filter->filters);
154         }
155
156         if (filter->filter_ops) {
157                 g_slist_free(filter->filter_ops);
158         }
159
160         free(filter->view_uri);
161 }
162
163 static int __ctsvc_ipc_unmarshal_composite_filter(const pims_ipc_data_h ipc_data, ctsvc_composite_filter_s* filter)
164 {
165         unsigned int size = 0;
166         char* str = NULL;
167         int count =0, i=0;
168         ctsvc_filter_type_e filter_type = CTSVC_FILTER_COMPOSITE;
169         contacts_filter_operator_e op = CONTACTS_FILTER_OPERATOR_AND;
170
171         filter->filter_type = CTSVC_FILTER_COMPOSITE;
172
173         /* view_uri */
174         str = (char*)pims_ipc_data_get(ipc_data,&size);
175         filter->view_uri = (char*)SAFE_STRDUP(str);
176
177         /* filters */
178         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(ipc_data,&count)) {
179                 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
180                 return CONTACTS_ERROR_INVALID_PARAMETER;
181         }
182
183         for (i=0;i<count;i++) {
184                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(ipc_data, (int*)&filter_type)) {
185                         CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
186                         __ctsvc_ipc_unmarshal_composite_filter_free(filter);
187                         return CONTACTS_ERROR_IPC;
188                 }
189                 if (filter_type == CTSVC_FILTER_COMPOSITE) {
190                         ctsvc_composite_filter_s *com_filter = NULL;
191                         com_filter = (ctsvc_composite_filter_s*)calloc(1,sizeof(ctsvc_composite_filter_s));
192                         if (com_filter == NULL) {
193                                 CTS_ERR("calloc() Fail");
194                                 __ctsvc_ipc_unmarshal_composite_filter_free(filter);
195                                 return CONTACTS_ERROR_OUT_OF_MEMORY;
196                         }
197                         if (CONTACTS_ERROR_NONE != __ctsvc_ipc_unmarshal_composite_filter(ipc_data, com_filter)) {
198                                 CTS_ERR("__ctsvc_ipc_unmarshal_composite_filter() Fail");
199                                 CONTACTS_FREE(com_filter);
200                                 __ctsvc_ipc_unmarshal_composite_filter_free(filter);
201                                 return CONTACTS_ERROR_IPC;
202                         }
203                         filter->filters = g_slist_append(filter->filters, com_filter);
204                 }
205                 else {
206                         ctsvc_attribute_filter_s *attr_filter = NULL;
207                         attr_filter = (ctsvc_attribute_filter_s*)calloc(1,sizeof(ctsvc_attribute_filter_s));
208                         if (attr_filter == NULL) {
209                                 CTS_ERR("calloc() Fail");
210                                 __ctsvc_ipc_unmarshal_composite_filter_free(filter);
211                                 return CONTACTS_ERROR_OUT_OF_MEMORY;
212                         }
213                         if (CONTACTS_ERROR_NONE != __ctsvc_ipc_unmarshal_attribute_filter(ipc_data, filter_type, attr_filter)) {
214                                 CTS_ERR("__ctsvc_ipc_unmarshal_attribute_filter() Fail");
215                                 CONTACTS_FREE(attr_filter);
216                                 __ctsvc_ipc_unmarshal_composite_filter_free(filter);
217                                 return CONTACTS_ERROR_IPC;
218                         }
219                         filter->filters = g_slist_append(filter->filters,attr_filter);
220                 }
221         }
222
223         /* filters */
224         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(ipc_data, &count)) {
225                 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
226                 __ctsvc_ipc_unmarshal_composite_filter_free(filter);
227                 return CONTACTS_ERROR_IPC;
228         }
229
230         for (i=0;i<count;i++) {
231                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(ipc_data, (int *)&op)) {
232                         CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
233                         __ctsvc_ipc_unmarshal_composite_filter_free(filter);
234                         return CONTACTS_ERROR_IPC;
235                 }
236                 filter->filter_ops = g_slist_append(filter->filter_ops, (void*)op);
237         }
238
239         /* properties  property_count */
240         filter->properties = (property_info_s *)ctsvc_view_get_all_property_infos(filter->view_uri, &filter->property_count);
241
242         return CONTACTS_ERROR_NONE;
243 }
244
245 static int __ctsvc_ipc_marshal_composite_filter(const ctsvc_composite_filter_s* filter, pims_ipc_data_h ipc_data)
246 {
247         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int((filter->filter_type),ipc_data)) {
248                 CTS_ERR("ctsvc_ipc_marshal_int() Fail");
249                 return CONTACTS_ERROR_INVALID_PARAMETER;
250         }
251
252         /* view_uri */
253         int length = strlen(filter->view_uri);
254         if (pims_ipc_data_put(ipc_data,(void*)filter->view_uri,length+1) < 0) {
255                 CTS_ERR("pims_ipc_data_put() Fail");
256                 return CONTACTS_ERROR_INVALID_PARAMETER;
257         }
258         /* filter->filters */
259         if (filter->filters) {
260                 int count = g_slist_length(filter->filters);
261                 GSList *cursor = filter->filters;
262                 ctsvc_filter_s* child_filter;
263
264                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(count,ipc_data)) {
265                         CTS_ERR("ctsvc_ipc_marshal_int() Fail");
266                         return CONTACTS_ERROR_INVALID_PARAMETER;
267                 }
268                 while (cursor) {
269                         child_filter = (ctsvc_filter_s*)cursor->data;
270
271                         if (child_filter->filter_type == CTSVC_FILTER_COMPOSITE) {
272                                 if (CONTACTS_ERROR_NONE != __ctsvc_ipc_marshal_composite_filter((ctsvc_composite_filter_s*)child_filter, ipc_data)) {
273                                         CTS_ERR("__ctsvc_ipc_marshal_composite_filter() Fail");
274                                         return CONTACTS_ERROR_INVALID_PARAMETER;
275                                 }
276                         }
277                         else {
278                                 if (CONTACTS_ERROR_NONE != __ctsvc_ipc_marshal_attribute_filter((ctsvc_attribute_filter_s*)child_filter, ipc_data)) {
279                                         CTS_ERR("__ctsvc_ipc_marshal_attribute_filter() Fail");
280                                         return CONTACTS_ERROR_INVALID_PARAMETER;
281                                 }
282                         }
283                         cursor = g_slist_next(cursor);
284                 }
285         }
286         else {
287                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(0,ipc_data)) {
288                         CTS_ERR("ctsvc_ipc_marshal_int() Fail");
289                         return CONTACTS_ERROR_INVALID_PARAMETER;
290                 }
291         }
292
293         if (filter->filter_ops) {
294                 int count = g_slist_length(filter->filter_ops);
295                 GSList *cursor = filter->filter_ops;
296
297                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(count,ipc_data)) {
298                         CTS_ERR("ctsvc_ipc_marshal_int() Fail");
299                         return CONTACTS_ERROR_INVALID_PARAMETER;
300                 }
301                 while (cursor) {
302                         contacts_filter_operator_e op = (contacts_filter_operator_e)cursor->data;
303
304                         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(op,ipc_data)) {
305                                 CTS_ERR("ctsvc_ipc_marshal_int() Fail");
306                                 return CONTACTS_ERROR_INVALID_PARAMETER;
307                         }
308
309                         cursor = g_slist_next(cursor);
310                 }
311         }
312         else {
313                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(0,ipc_data)) {
314                         CTS_ERR("ctsvc_ipc_marshal_int() Fail");
315                         return CONTACTS_ERROR_INVALID_PARAMETER;
316                 }
317         }
318
319         return CONTACTS_ERROR_NONE;
320 }
321
322 static int __ctsvc_ipc_unmarshal_attribute_filter(const pims_ipc_data_h ipc_data, const ctsvc_filter_type_e filter_type, ctsvc_attribute_filter_s* filter)
323 {
324         filter->filter_type = filter_type;
325         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(ipc_data,&filter->property_id)) {
326                 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
327                 return CONTACTS_ERROR_INVALID_PARAMETER;
328         }
329         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(ipc_data,&filter->match)) {
330                 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
331                 return CONTACTS_ERROR_INVALID_PARAMETER;
332         }
333         switch(filter->filter_type) {
334         case CTSVC_FILTER_STR:
335                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_string(ipc_data,&filter->value.s)) {
336                         CTS_ERR("ctsvc_ipc_unmarshal_string() Fail");
337                         return CONTACTS_ERROR_INVALID_PARAMETER;
338                 }
339                 break;
340         case CTSVC_FILTER_INT:
341                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(ipc_data,&filter->value.i)) {
342                         CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
343                         return CONTACTS_ERROR_INVALID_PARAMETER;
344                 }
345                 break;
346         case CTSVC_FILTER_BOOL:
347                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_bool(ipc_data,&filter->value.b)) {
348                         CTS_ERR("ctsvc_ipc_unmarshal_bool() Fail");
349                         return CONTACTS_ERROR_INVALID_PARAMETER;
350                 }
351                 break;
352         case CTSVC_FILTER_DOUBLE:
353         case CTSVC_FILTER_LLI:
354         default:
355                 break;
356         }
357         return CONTACTS_ERROR_NONE;
358 }
359
360 static int __ctsvc_ipc_marshal_attribute_filter(const ctsvc_attribute_filter_s* filter, pims_ipc_data_h ipc_data)
361 {
362         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int((filter->filter_type),ipc_data)) {
363                 CTS_ERR("ctsvc_ipc_marshal_int() Fail");
364                 return CONTACTS_ERROR_INVALID_PARAMETER;
365         }
366         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int((filter->property_id),ipc_data)) {
367                 CTS_ERR("ctsvc_ipc_marshal_int() Fail");
368                 return CONTACTS_ERROR_INVALID_PARAMETER;
369         }
370         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int((filter->match),ipc_data)) {
371                 CTS_ERR("ctsvc_ipc_marshal_int() Fail");
372                 return CONTACTS_ERROR_INVALID_PARAMETER;
373         }
374         switch(filter->filter_type) {
375         case CTSVC_FILTER_STR:
376                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_string((filter->value.s),ipc_data)) {
377                         CTS_ERR("ctsvc_ipc_marshal_string() Fail");
378                         return CONTACTS_ERROR_INVALID_PARAMETER;
379                 }
380                 break;
381         case CTSVC_FILTER_INT:
382                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int((filter->value.i),ipc_data)) {
383                         CTS_ERR("ctsvc_ipc_marshal_int() Fail");
384                         return CONTACTS_ERROR_INVALID_PARAMETER;
385                 }
386                 break;
387         case CTSVC_FILTER_BOOL:
388                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_bool((filter->value.b),ipc_data)) {
389                         CTS_ERR("ctsvc_ipc_marshal_bool() Fail");
390                         return CONTACTS_ERROR_INVALID_PARAMETER;
391                 }
392                 break;
393         case CTSVC_FILTER_DOUBLE:
394         case CTSVC_FILTER_LLI:
395         default:
396                 break;
397         }
398
399         return CONTACTS_ERROR_NONE;
400 }
401
402
403 int ctsvc_ipc_unmarshal_record(const pims_ipc_data_h ipc_data, contacts_record_h* precord)
404 {
405         int ret = CONTACTS_ERROR_NONE;
406         ctsvc_record_s common = {0,};
407         ctsvc_record_s *precord_common = NULL;
408         ctsvc_ipc_marshal_record_plugin_cb_s *plugin_cb;
409
410         RETVM_IF(NULL == precord || NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
411
412         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_record_common(ipc_data, &common)) {
413                 CTS_ERR("ctsvc_ipc_unmarshal_record_common() Fail");
414                 return CONTACTS_ERROR_INVALID_PARAMETER;
415         }
416
417         plugin_cb = __ctsvc_ipc_marshal_get_plugin_cb(common.r_type);
418         if (NULL == plugin_cb || NULL == plugin_cb->unmarshal_record) {
419                 CTS_ERR("Invalid parameter");
420                 free(common.properties_flags);
421                 return CONTACTS_ERROR_INVALID_PARAMETER;
422         }
423
424         ret = contacts_record_create(common.view_uri, precord);
425         if (CONTACTS_ERROR_NONE != ret) {
426                 CTS_ERR("contacts_record_create() Fail");
427                 free(common.properties_flags);
428                 return ret;
429         }
430
431         precord_common = (ctsvc_record_s *)(*precord);
432         precord_common->property_max_count = common.property_max_count;
433         precord_common->properties_flags = common.properties_flags;
434         precord_common->property_flag = common.property_flag;
435
436         ret = plugin_cb->unmarshal_record(ipc_data, common.view_uri, *precord);
437         if (CONTACTS_ERROR_NONE != ret) {
438                 contacts_record_destroy(*precord,true);
439                 *precord = NULL;
440                 return CONTACTS_ERROR_IPC;
441         }
442
443         return ret;
444 }
445
446 int ctsvc_ipc_marshal_record(const contacts_record_h record, pims_ipc_data_h ipc_data)
447 {
448         RETVM_IF(NULL == record || NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
449
450         ctsvc_record_s *common = (ctsvc_record_s*)(record);
451
452         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_record_common(common, ipc_data)) {
453                 CTS_ERR("ctsvc_ipc_marshal_record_common() Fail");
454                 return CONTACTS_ERROR_INVALID_PARAMETER;
455         }
456
457         ctsvc_ipc_marshal_record_plugin_cb_s *plugin_cb = __ctsvc_ipc_marshal_get_plugin_cb(common->r_type);
458
459         RETVM_IF(NULL == plugin_cb || NULL == plugin_cb->marshal_record, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
460
461         int ret = plugin_cb->marshal_record(record, ipc_data);
462
463         return ret;
464 }
465
466 int ctsvc_ipc_unmarshal_string(const pims_ipc_data_h ipc_data, char** ppbufchar)
467 {
468         int ret = CONTACTS_ERROR_NONE;
469
470         void *tmp = NULL;
471         unsigned int size = 0;
472         char *str = NULL;
473
474         int length = 0;
475
476         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
477         RETV_IF(ppbufchar==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
478
479         tmp = pims_ipc_data_get(ipc_data,&size);
480         if (tmp == NULL) {
481                 CTS_ERR("pims_ipc_data_get() Fail");
482                 return CONTACTS_ERROR_INVALID_PARAMETER;
483         }
484         length = *(int*)tmp;
485
486         if (length == -1) {
487                 ret = CONTACTS_ERROR_NONE;
488                 CTS_VERBOSE("string is null");
489                 *ppbufchar = NULL;
490                 return ret;
491         }
492
493         str = (char*)pims_ipc_data_get(ipc_data,&size);
494         if (str) {
495                 *ppbufchar = SAFE_STRDUP(str);
496         }
497
498         return ret;
499 }
500
501 int ctsvc_ipc_unmarshal_int(const pims_ipc_data_h data, int *pout)
502 {
503         RETV_IF(data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
504         RETV_IF(pout==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
505
506         unsigned int size = 0;
507         void *tmp = pims_ipc_data_get(data,&size);
508         if (tmp == NULL) {
509                 CTS_ERR("pims_ipc_data_get() Fail");
510                 return CONTACTS_ERROR_NO_DATA;
511         }
512         else {
513                 *pout = *(int*)tmp;
514         }
515         return CONTACTS_ERROR_NONE;
516 }
517
518 int ctsvc_ipc_unmarshal_unsigned_int(const pims_ipc_data_h data, unsigned int *pout)
519 {
520         RETV_IF(data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
521         RETV_IF(pout==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
522
523         unsigned int size = 0;
524         void *tmp = pims_ipc_data_get(data,&size);
525         if (tmp == NULL) {
526                 CTS_ERR("pims_ipc_data_get() Fail");
527                 return CONTACTS_ERROR_NO_DATA;
528         }
529         else {
530                 *pout = *(unsigned int*)tmp;
531         }
532         return CONTACTS_ERROR_NONE;
533 }
534
535 int ctsvc_ipc_unmarshal_bool(const pims_ipc_data_h data, bool *pout)
536 {
537         RETV_IF(data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
538         RETV_IF(pout==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
539
540         unsigned int size = 0;
541         void *tmp = pims_ipc_data_get(data,&size);
542         if (tmp == NULL) {
543                 CTS_ERR("pims_ipc_data_get() Fail");
544                 return CONTACTS_ERROR_NO_DATA;
545         }
546         else {
547                 *pout = *(bool*)tmp;
548         }
549         return CONTACTS_ERROR_NONE;
550 }
551
552 int ctsvc_ipc_unmarshal_record_common(const pims_ipc_data_h ipc_data, ctsvc_record_s* common)
553 {
554         void *tmp = NULL;
555         unsigned int size = 0;
556         const char* str = NULL;
557
558         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_NO_DATA);
559         tmp = pims_ipc_data_get(ipc_data,&size);
560         if (tmp == NULL) {
561                 CTS_ERR("pims_ipc_data_get() Fail");
562                 return CONTACTS_ERROR_NO_DATA;
563         }
564         else {
565                 common->r_type = *(ctsvc_record_type_e*)tmp;
566         }
567
568         str = (char*)pims_ipc_data_get(ipc_data,&size);
569         if (NULL == str) {
570                 CTS_ERR("pims_ipc_data_get() Fail");
571                 return CONTACTS_ERROR_NO_DATA;
572         }
573         common->view_uri = ctsvc_view_get_uri(str);
574
575         tmp = pims_ipc_data_get(ipc_data,&size);
576         if (NULL == tmp) {
577                 CTS_ERR("pims_ipc_data_get() Fail");
578                 return CONTACTS_ERROR_NO_DATA;
579         }
580         common->property_max_count = *(unsigned int*)tmp;
581
582         if (0 < common->property_max_count) {
583                 unsigned char *tmp_properties_flags;
584                 tmp_properties_flags = (unsigned char*)pims_ipc_data_get(ipc_data, &size);
585                 if (NULL == tmp_properties_flags) {
586                         CTS_ERR("pims_ipc_data_get() Fail");
587                         return CONTACTS_ERROR_NO_DATA;
588                 }
589
590                 common->properties_flags  = calloc(common->property_max_count, sizeof(char));
591                 if (common->properties_flags == NULL) {
592                         CTS_ERR("calloc() Fail");
593                         return CONTACTS_ERROR_OUT_OF_MEMORY;
594                 }
595                 memcpy(common->properties_flags, tmp_properties_flags, sizeof(char)*common->property_max_count);
596         }
597         tmp = pims_ipc_data_get(ipc_data,&size);
598         if (NULL == tmp) {
599                 CTS_ERR("pims_ipc_data_get() Fail");
600                 return CONTACTS_ERROR_NO_DATA;
601         }
602         common->property_flag = *(unsigned char*)tmp;
603
604         return CONTACTS_ERROR_NONE;
605 }
606
607 int ctsvc_ipc_marshal_string(const char* bufchar, pims_ipc_data_h ipc_data)
608 {
609         int ret = CONTACTS_ERROR_NONE;
610
611         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
612
613         if (bufchar) {
614                 int length = strlen(bufchar);
615                 if (pims_ipc_data_put(ipc_data,(void*)&length,sizeof(int)) != 0) {
616                         ret = CONTACTS_ERROR_OUT_OF_MEMORY;
617                 }
618
619                 if (pims_ipc_data_put(ipc_data,(void*)bufchar,length+1) != 0) {
620                         ret = CONTACTS_ERROR_OUT_OF_MEMORY;
621                         return ret;
622                 }
623         }
624         else {
625                 int length = -1;
626
627                 if (pims_ipc_data_put(ipc_data,(void*)&length,sizeof(int)) != 0) {
628                         ret = CONTACTS_ERROR_OUT_OF_MEMORY;
629                 }
630         }
631         return ret;
632 }
633
634 int ctsvc_ipc_marshal_int(const int in, pims_ipc_data_h ipc_data)
635 {
636         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
637
638         if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(int)) != 0) {
639                 return CONTACTS_ERROR_OUT_OF_MEMORY;
640         }
641         return CONTACTS_ERROR_NONE;
642 }
643
644 int ctsvc_ipc_marshal_unsigned_int(const unsigned int in, pims_ipc_data_h ipc_data)
645 {
646         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
647
648         if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(unsigned int)) != 0) {
649                 return CONTACTS_ERROR_OUT_OF_MEMORY;
650         }
651         return CONTACTS_ERROR_NONE;
652 }
653
654 int ctsvc_ipc_marshal_bool(const bool in, pims_ipc_data_h ipc_data)
655 {
656         RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
657
658         if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(bool)) != 0) {
659                 return CONTACTS_ERROR_OUT_OF_MEMORY;
660         }
661         return CONTACTS_ERROR_NONE;
662 }
663
664 int ctsvc_ipc_marshal_record_common(const ctsvc_record_s* common, pims_ipc_data_h ipc_data)
665 {
666
667         RETV_IF(NULL == common, CONTACTS_ERROR_INVALID_PARAMETER);
668         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
669
670         if (pims_ipc_data_put(ipc_data,(void*)&common->r_type,sizeof(int)) < 0) {
671                 return CONTACTS_ERROR_NO_DATA;
672         }
673
674         int length = strlen(common->view_uri);
675         if (pims_ipc_data_put(ipc_data,(void*)common->view_uri,length+1) < 0) {
676                 CTS_ERR("pims_ipc_data_put() Fail");
677                 return CONTACTS_ERROR_INVALID_PARAMETER;
678         }
679
680         if (pims_ipc_data_put(ipc_data,(void*)&common->property_max_count,sizeof(unsigned int)) < 0) {
681                 return CONTACTS_ERROR_NO_DATA;
682         }
683
684         if (0 < common->property_max_count) {
685                 if (pims_ipc_data_put(ipc_data,(void*)common->properties_flags,sizeof(unsigned char)*common->property_max_count) < 0) {
686                         CTS_ERR("pims_ipc_data_put() Fail");
687                         return CONTACTS_ERROR_NO_DATA;
688                 }
689         }
690
691         if (pims_ipc_data_put(ipc_data,(void*)&common->property_flag,sizeof(char)) < 0) {
692                 return CONTACTS_ERROR_NO_DATA;
693         }
694         return CONTACTS_ERROR_NONE;
695 }
696
697 int ctsvc_ipc_unmarshal_query(const pims_ipc_data_h ipc_data, contacts_query_h *out_query)
698 {
699         ctsvc_query_s *query = NULL;
700         unsigned int size = 0;
701         char* str = NULL;
702         unsigned int count = 0, i = 0;
703         int ret = CONTACTS_ERROR_NONE;
704
705         RETV_IF(NULL == out_query, CONTACTS_ERROR_INVALID_PARAMETER);
706         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
707
708         /* view_uri */
709         str = (char*)pims_ipc_data_get(ipc_data, &size);
710
711         ret = contacts_query_create(str, out_query);
712         if (CONTACTS_ERROR_NONE != ret) {
713                 CTS_ERR("contacts_query_create() Fail");
714                 return ret;
715         }
716         query = (ctsvc_query_s *)*out_query;
717
718         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_unsigned_int(ipc_data, &count)) {
719                 CTS_ERR("contacts_query_create() Fail");
720                 contacts_query_destroy(*out_query);
721                 *out_query = NULL;
722                 return CONTACTS_ERROR_IPC;
723         }
724
725         if (0 == count) {
726                 query->filter = NULL;
727         }
728         else {
729                 ctsvc_composite_filter_s *filter = NULL;
730                 filter = (ctsvc_composite_filter_s *)calloc(1, sizeof(ctsvc_composite_filter_s));
731                 if (NULL == filter) {
732                         CTS_ERR("calloc() Fail");
733                         contacts_query_destroy(*out_query);
734                         *out_query = NULL;
735                         return CONTACTS_ERROR_OUT_OF_MEMORY;
736                 }
737                 filter->filter_type = CTSVC_FILTER_COMPOSITE;
738                 filter->properties = (property_info_s *)ctsvc_view_get_all_property_infos(query->view_uri, &filter->property_count);
739                 query->filter = filter;
740
741                 /* for filter_type */
742                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_unsigned_int(ipc_data, &count)) {
743                         CTS_ERR("ctsvc_ipc_unmarshal_unsigned_int() Fail");
744                         contacts_query_destroy(*out_query);
745                         *out_query = NULL;
746                         return CONTACTS_ERROR_IPC;
747                 }
748
749                 if (CONTACTS_ERROR_NONE != __ctsvc_ipc_unmarshal_composite_filter(ipc_data, query->filter)) {
750                         CTS_ERR("__ctsvc_ipc_unmarshal_composite_filter() Fail");
751                         contacts_query_destroy(*out_query);
752                         *out_query = NULL;
753                         return CONTACTS_ERROR_IPC;
754                 }
755         }
756
757         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_unsigned_int(ipc_data, &(query->projection_count))) {
758                 CTS_ERR("ctsvc_ipc_unmarshal_unsigned_int() Fail");
759                 contacts_query_destroy(*out_query);
760                 *out_query = NULL;
761                 return CONTACTS_ERROR_IPC;
762         }
763
764         if (0 < query->projection_count) {
765                 query->projection = (unsigned int*)malloc(sizeof(unsigned int)*query->projection_count);
766                 if (query->projection == NULL) {
767                         CTS_ERR("malloc() Fail");
768                         contacts_query_destroy(*out_query);
769                         *out_query = NULL;
770                         return CONTACTS_ERROR_OUT_OF_MEMORY;
771                 }
772                 for (i=0;i<query->projection_count;i++) {
773                         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_unsigned_int(ipc_data,&(query->projection[i]))) {
774                                 CTS_ERR("ctsvc_ipc_unmarshal_unsigned_int() Fail");
775                                 contacts_query_destroy(*out_query);
776                                 *out_query = NULL;
777                                 return CONTACTS_ERROR_IPC;
778                         }
779                 }
780         }
781         else {
782                 query->projection = NULL;
783         }
784
785         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_unsigned_int(ipc_data,&(query->sort_property_id))) {
786                 CTS_ERR("ctsvc_ipc_unmarshal_unsigned_int() Fail");
787                 contacts_query_destroy(*out_query);
788                 *out_query = NULL;
789                 return CONTACTS_ERROR_IPC;
790         }
791
792         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_bool(ipc_data,&(query->sort_asc))) {
793                 CTS_ERR("ctsvc_ipc_unmarshal_bool() Fail");
794                 contacts_query_destroy(*out_query);
795                 *out_query = NULL;
796                 return CONTACTS_ERROR_IPC;
797         }
798
799         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_bool(ipc_data,&(query->distinct))) {
800                 CTS_ERR("ctsvc_ipc_unmarshal_bool() Fail");
801                 contacts_query_destroy(*out_query);
802                 *out_query = NULL;
803                 return CONTACTS_ERROR_IPC;
804         }
805
806         return CONTACTS_ERROR_NONE;
807 }
808
809 int ctsvc_ipc_marshal_query(const contacts_query_h query, pims_ipc_data_h ipc_data)
810 {
811         ctsvc_query_s *que = NULL;
812         int i = 0;
813         int length = 0;
814
815         RETV_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER);
816         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
817         que = (ctsvc_query_s *)query;
818
819         /* view_uri */
820         length = strlen(que->view_uri);
821         if (pims_ipc_data_put(ipc_data,(void*)que->view_uri,length+1) < 0) {
822                 CTS_ERR("pims_ipc_data_put() Fail");
823                 return CONTACTS_ERROR_INVALID_PARAMETER;
824         }
825
826         if (que->filter) {
827                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(1,ipc_data)) {
828                         CTS_ERR("ctsvc_ipc_marshal_int() Fail");
829                         return CONTACTS_ERROR_INVALID_PARAMETER;
830                 }
831
832                 if (CONTACTS_ERROR_NONE != __ctsvc_ipc_marshal_composite_filter(que->filter,ipc_data)) {
833                         CTS_ERR("__ctsvc_ipc_marshal_composite_filter() Fail");
834                         return CONTACTS_ERROR_INVALID_PARAMETER;
835                 }
836         }
837         else {
838                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(0,ipc_data)) {
839                         CTS_ERR("ctsvc_ipc_marshal_int() Fail");
840                         return CONTACTS_ERROR_INVALID_PARAMETER;
841                 }
842         }
843
844         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_unsigned_int(que->projection_count,ipc_data)) {
845                 CTS_ERR("ctsvc_ipc_marshal_unsigned_int() Fail");
846                 return CONTACTS_ERROR_INVALID_PARAMETER;
847         }
848         for (i=0;i<que->projection_count;i++) {
849                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_unsigned_int(que->projection[i],ipc_data)) {
850                         CTS_ERR("ctsvc_ipc_marshal_unsigned_int() Fail");
851                         return CONTACTS_ERROR_INVALID_PARAMETER;
852                 }
853         }
854
855         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_unsigned_int(que->sort_property_id,ipc_data)) {
856                 CTS_ERR("ctsvc_ipc_marshal_unsigned_int() Fail");
857                 return CONTACTS_ERROR_INVALID_PARAMETER;
858         }
859
860         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_bool(que->sort_asc,ipc_data)) {
861                 CTS_ERR("ctsvc_ipc_marshal_bool() Fail");
862                 return CONTACTS_ERROR_INVALID_PARAMETER;
863         }
864
865         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_bool(que->distinct,ipc_data)) {
866                 CTS_ERR("ctsvc_ipc_marshal_bool() Fail");
867                 return CONTACTS_ERROR_INVALID_PARAMETER;
868         }
869
870         return CONTACTS_ERROR_NONE;
871 }
872
873 int ctsvc_ipc_unmarshal_list(const pims_ipc_data_h ipc_data, contacts_list_h* list)
874 {
875         int count = 0;
876         unsigned int deleted_count = 0;
877         contacts_record_h record;
878
879         RETV_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER);
880         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
881
882         if (CONTACTS_ERROR_NONE != contacts_list_create(list)) {
883                 CTS_ERR("contacts_list_create() Fail");
884                 return CONTACTS_ERROR_OUT_OF_MEMORY;
885         }
886
887         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(ipc_data, &(count))) {
888                 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
889                 contacts_list_destroy(*list, true);
890                 *list = NULL;
891                 return CONTACTS_ERROR_IPC;
892         }
893
894         unsigned int i = 0;
895         for (i=0;i<count;i++) {
896                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_record(ipc_data, &record)) {
897                         CTS_ERR("ctsvc_ipc_unmarshal_record() Fail");
898                         contacts_list_destroy(*list, true);
899                         *list = NULL;
900                         return CONTACTS_ERROR_IPC;
901                 }
902
903                 if (CONTACTS_ERROR_NONE != contacts_list_add(*list, record)) {
904                         CTS_ERR("contacts_list_add() Fail");
905                         contacts_list_destroy(*list, true);
906                         *list = NULL;
907                         return CONTACTS_ERROR_INVALID_PARAMETER;
908                 }
909         }
910
911         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_unsigned_int(ipc_data, &deleted_count)) {
912                 CTS_ERR("ctsvc_ipc_unmarshal_unsigned_int() Fail");
913                 contacts_list_destroy(*list, true);
914                 *list = NULL;
915                 return CONTACTS_ERROR_IPC;
916         }
917
918         i = 0;
919         for (i=0;i<deleted_count;i++) {
920                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_record(ipc_data, &record)) {
921                         CTS_ERR("ctsvc_ipc_unmarshal_record() Fail");
922                         contacts_list_destroy(*list, true);
923                         *list = NULL;
924                         return CONTACTS_ERROR_IPC;
925                 }
926
927                 if (CONTACTS_ERROR_NONE != ctsvc_list_append_deleted_record(*list, record)) {
928                         CTS_ERR("ctsvc_list_append_deleted_record() Fail");
929                         contacts_list_destroy(*list, true);
930                         *list = NULL;
931                         return CONTACTS_ERROR_IPC;
932                 }
933         }
934
935         return CONTACTS_ERROR_NONE;
936 }
937
938 int ctsvc_ipc_unmarshal_child_list(const pims_ipc_data_h ipc_data, contacts_list_h* list)
939 {
940         unsigned int i = 0;
941         int count = 0;
942         unsigned int deleted_count = 0;
943         contacts_record_h record;
944
945         RETV_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER);
946         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
947
948         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(ipc_data,&(count))) {
949                 CTS_ERR("ctsvc_ipc_unmarshal_int() Fail");
950                 return CONTACTS_ERROR_INVALID_PARAMETER;
951         }
952
953         for (i=0;i<count;i++) {
954                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_record(ipc_data,&record)) {
955                         CTS_ERR("ctsvc_ipc_unmarshal_record() Fail");
956                         return CONTACTS_ERROR_INVALID_PARAMETER;
957                 }
958
959                 if (CONTACTS_ERROR_NONE != contacts_list_add(*list,record)) {
960                         CTS_ERR("contacts_list_add() Fail");
961                         return CONTACTS_ERROR_INVALID_PARAMETER;
962                 }
963         }
964
965         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_unsigned_int(ipc_data,&deleted_count)) {
966                 CTS_ERR("ctsvc_ipc_unmarshal_unsigned_int() Fail");
967                 return CONTACTS_ERROR_INVALID_PARAMETER;
968         }
969
970         i = 0;
971         for (i=0;i<deleted_count;i++) {
972                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_record(ipc_data,&record)) {
973                         CTS_ERR("ctsvc_ipc_unmarshal_record() Fail");
974                         return CONTACTS_ERROR_INVALID_PARAMETER;
975                 }
976
977                 if (CONTACTS_ERROR_NONE != ctsvc_list_append_deleted_record(*list,record)) {
978                         CTS_ERR("ctsvc_list_append_deleted_record() Fail");
979                         return CONTACTS_ERROR_INVALID_PARAMETER;
980                 }
981         }
982
983         return CONTACTS_ERROR_NONE;
984 }
985
986 int ctsvc_ipc_marshal_list(const contacts_list_h list, pims_ipc_data_h ipc_data)
987 {
988         int count = 0;
989         unsigned int deleted_count = 0;
990         contacts_record_h record;
991
992         RETV_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER);
993         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
994
995         /* count */
996         if (CONTACTS_ERROR_NONE != contacts_list_get_count(list, &count)) {
997                 CTS_ERR("contacts_list_get_count() Fail");
998                 return CONTACTS_ERROR_INVALID_PARAMETER;
999         }
1000         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(count,ipc_data)) {
1001                 CTS_ERR("ctsvc_ipc_marshal_int() Fail");
1002                 return CONTACTS_ERROR_INVALID_PARAMETER;
1003         }
1004
1005         contacts_list_first(list);
1006
1007         unsigned int i = 0;
1008         for (i=0;i<count;i++) {
1009                 if (CONTACTS_ERROR_NONE != contacts_list_get_current_record_p(list,&record)) {
1010                         CTS_ERR("contacts_list_get_current_record_p() Fail");
1011                         return CONTACTS_ERROR_INVALID_PARAMETER;
1012                 }
1013                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_record(record,ipc_data)) {
1014                         CTS_ERR("ctsvc_ipc_marshal_record() Fail");
1015                         return CONTACTS_ERROR_INVALID_PARAMETER;
1016                 }
1017                 if (CONTACTS_ERROR_NO_DATA == contacts_list_next(list)) {
1018                         break;
1019                 }
1020         }
1021
1022         /* count */
1023         if (ctsvc_list_get_deleted_count(list, &deleted_count)) {
1024                 CTS_ERR("ctsvc_list_get_deleted_count() Fail");
1025                 return CONTACTS_ERROR_INVALID_PARAMETER;
1026         }
1027         if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(deleted_count,ipc_data)) {
1028                 CTS_ERR("ctsvc_ipc_marshal_int() Fail");
1029                 return CONTACTS_ERROR_INVALID_PARAMETER;
1030         }
1031
1032         i = 0;
1033         for (i=0;i<deleted_count;i++) {
1034                 if (CONTACTS_ERROR_NONE != ctsvc_list_get_deleted_nth_record_p(list, i, &record)) {
1035                         CTS_ERR("ctsvc_list_get_deleted_nth_record_p() Fail");
1036                         return CONTACTS_ERROR_INVALID_PARAMETER;
1037                 }
1038                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_record(record,ipc_data)) {
1039                         CTS_ERR("ctsvc_ipc_marshal_record() Fail");
1040                         return CONTACTS_ERROR_INVALID_PARAMETER;
1041                 }
1042         }
1043
1044         return CONTACTS_ERROR_NONE;
1045 }
1046