4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
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;
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;
62 static ctsvc_ipc_marshal_record_plugin_cb_s* __ctsvc_ipc_marshal_get_plugin_cb(ctsvc_record_type_e type);
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);
71 static ctsvc_ipc_marshal_record_plugin_cb_s* __ctsvc_ipc_marshal_get_plugin_cb(ctsvc_record_type_e 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);
133 ASSERT_NOT_REACHED("Unimplemented IPC module (%d)", type);
138 static void __ctsvc_ipc_unmarshal_composite_filter_free(ctsvc_composite_filter_s* filter)
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);
147 ctsvc_attribute_filter_s *attr = (ctsvc_attribute_filter_s *)src;
148 if (attr->filter_type == CTSVC_FILTER_STR)
153 g_slist_free(filter->filters);
156 if (filter->filter_ops) {
157 g_slist_free(filter->filter_ops);
160 free(filter->view_uri);
163 static int __ctsvc_ipc_unmarshal_composite_filter(const pims_ipc_data_h ipc_data, ctsvc_composite_filter_s* filter)
165 unsigned int size = 0;
168 ctsvc_filter_type_e filter_type = CTSVC_FILTER_COMPOSITE;
169 contacts_filter_operator_e op = CONTACTS_FILTER_OPERATOR_AND;
171 filter->filter_type = CTSVC_FILTER_COMPOSITE;
174 str = (char*)pims_ipc_data_get(ipc_data,&size);
175 filter->view_uri = (char*)SAFE_STRDUP(str);
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;
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;
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;
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;
203 filter->filters = g_slist_append(filter->filters, com_filter);
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;
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;
219 filter->filters = g_slist_append(filter->filters,attr_filter);
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;
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;
236 filter->filter_ops = g_slist_append(filter->filter_ops, (void*)op);
239 /* properties property_count */
240 filter->properties = (property_info_s *)ctsvc_view_get_all_property_infos(filter->view_uri, &filter->property_count);
242 return CONTACTS_ERROR_NONE;
245 static int __ctsvc_ipc_marshal_composite_filter(const ctsvc_composite_filter_s* filter, pims_ipc_data_h ipc_data)
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;
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;
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;
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;
269 child_filter = (ctsvc_filter_s*)cursor->data;
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;
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;
283 cursor = g_slist_next(cursor);
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;
293 if (filter->filter_ops) {
294 int count = g_slist_length(filter->filter_ops);
295 GSList *cursor = filter->filter_ops;
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;
302 contacts_filter_operator_e op = (contacts_filter_operator_e)cursor->data;
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;
309 cursor = g_slist_next(cursor);
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;
319 return CONTACTS_ERROR_NONE;
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)
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;
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;
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;
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;
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;
352 case CTSVC_FILTER_DOUBLE:
353 case CTSVC_FILTER_LLI:
357 return CONTACTS_ERROR_NONE;
360 static int __ctsvc_ipc_marshal_attribute_filter(const ctsvc_attribute_filter_s* filter, pims_ipc_data_h ipc_data)
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;
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;
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;
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;
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;
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;
393 case CTSVC_FILTER_DOUBLE:
394 case CTSVC_FILTER_LLI:
399 return CONTACTS_ERROR_NONE;
403 int ctsvc_ipc_unmarshal_record(const pims_ipc_data_h ipc_data, contacts_record_h* precord)
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;
410 RETVM_IF(NULL == precord || NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
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;
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;
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);
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;
436 ret = plugin_cb->unmarshal_record(ipc_data, common.view_uri, *precord);
437 if (CONTACTS_ERROR_NONE != ret) {
438 contacts_record_destroy(*precord,true);
440 return CONTACTS_ERROR_IPC;
446 int ctsvc_ipc_marshal_record(const contacts_record_h record, pims_ipc_data_h ipc_data)
448 RETVM_IF(NULL == record || NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
450 ctsvc_record_s *common = (ctsvc_record_s*)(record);
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;
457 ctsvc_ipc_marshal_record_plugin_cb_s *plugin_cb = __ctsvc_ipc_marshal_get_plugin_cb(common->r_type);
459 RETVM_IF(NULL == plugin_cb || NULL == plugin_cb->marshal_record, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter");
461 int ret = plugin_cb->marshal_record(record, ipc_data);
466 int ctsvc_ipc_unmarshal_string(const pims_ipc_data_h ipc_data, char** ppbufchar)
468 int ret = CONTACTS_ERROR_NONE;
471 unsigned int size = 0;
476 RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
477 RETV_IF(ppbufchar==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
479 tmp = pims_ipc_data_get(ipc_data,&size);
481 CTS_ERR("pims_ipc_data_get() Fail");
482 return CONTACTS_ERROR_INVALID_PARAMETER;
487 ret = CONTACTS_ERROR_NONE;
488 CTS_VERBOSE("string is null");
493 str = (char*)pims_ipc_data_get(ipc_data,&size);
495 *ppbufchar = SAFE_STRDUP(str);
501 int ctsvc_ipc_unmarshal_int(const pims_ipc_data_h data, int *pout)
503 RETV_IF(data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
504 RETV_IF(pout==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
506 unsigned int size = 0;
507 void *tmp = pims_ipc_data_get(data,&size);
509 CTS_ERR("pims_ipc_data_get() Fail");
510 return CONTACTS_ERROR_NO_DATA;
515 return CONTACTS_ERROR_NONE;
518 int ctsvc_ipc_unmarshal_unsigned_int(const pims_ipc_data_h data, unsigned int *pout)
520 RETV_IF(data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
521 RETV_IF(pout==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
523 unsigned int size = 0;
524 void *tmp = pims_ipc_data_get(data,&size);
526 CTS_ERR("pims_ipc_data_get() Fail");
527 return CONTACTS_ERROR_NO_DATA;
530 *pout = *(unsigned int*)tmp;
532 return CONTACTS_ERROR_NONE;
535 int ctsvc_ipc_unmarshal_bool(const pims_ipc_data_h data, bool *pout)
537 RETV_IF(data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
538 RETV_IF(pout==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
540 unsigned int size = 0;
541 void *tmp = pims_ipc_data_get(data,&size);
543 CTS_ERR("pims_ipc_data_get() Fail");
544 return CONTACTS_ERROR_NO_DATA;
549 return CONTACTS_ERROR_NONE;
552 int ctsvc_ipc_unmarshal_record_common(const pims_ipc_data_h ipc_data, ctsvc_record_s* common)
555 unsigned int size = 0;
556 const char* str = NULL;
558 RETV_IF(ipc_data==NULL,CONTACTS_ERROR_NO_DATA);
559 tmp = pims_ipc_data_get(ipc_data,&size);
561 CTS_ERR("pims_ipc_data_get() Fail");
562 return CONTACTS_ERROR_NO_DATA;
565 common->r_type = *(ctsvc_record_type_e*)tmp;
568 str = (char*)pims_ipc_data_get(ipc_data,&size);
570 CTS_ERR("pims_ipc_data_get() Fail");
571 return CONTACTS_ERROR_NO_DATA;
573 common->view_uri = ctsvc_view_get_uri(str);
575 tmp = pims_ipc_data_get(ipc_data,&size);
577 CTS_ERR("pims_ipc_data_get() Fail");
578 return CONTACTS_ERROR_NO_DATA;
580 common->property_max_count = *(unsigned int*)tmp;
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;
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;
595 memcpy(common->properties_flags, tmp_properties_flags, sizeof(char)*common->property_max_count);
597 tmp = pims_ipc_data_get(ipc_data,&size);
599 CTS_ERR("pims_ipc_data_get() Fail");
600 return CONTACTS_ERROR_NO_DATA;
602 common->property_flag = *(unsigned char*)tmp;
604 return CONTACTS_ERROR_NONE;
607 int ctsvc_ipc_marshal_string(const char* bufchar, pims_ipc_data_h ipc_data)
609 int ret = CONTACTS_ERROR_NONE;
611 RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
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;
619 if (pims_ipc_data_put(ipc_data,(void*)bufchar,length+1) != 0) {
620 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
627 if (pims_ipc_data_put(ipc_data,(void*)&length,sizeof(int)) != 0) {
628 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
634 int ctsvc_ipc_marshal_int(const int in, pims_ipc_data_h ipc_data)
636 RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
638 if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(int)) != 0) {
639 return CONTACTS_ERROR_OUT_OF_MEMORY;
641 return CONTACTS_ERROR_NONE;
644 int ctsvc_ipc_marshal_unsigned_int(const unsigned int in, pims_ipc_data_h ipc_data)
646 RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
648 if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(unsigned int)) != 0) {
649 return CONTACTS_ERROR_OUT_OF_MEMORY;
651 return CONTACTS_ERROR_NONE;
654 int ctsvc_ipc_marshal_bool(const bool in, pims_ipc_data_h ipc_data)
656 RETV_IF(ipc_data==NULL,CONTACTS_ERROR_INVALID_PARAMETER);
658 if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(bool)) != 0) {
659 return CONTACTS_ERROR_OUT_OF_MEMORY;
661 return CONTACTS_ERROR_NONE;
664 int ctsvc_ipc_marshal_record_common(const ctsvc_record_s* common, pims_ipc_data_h ipc_data)
667 RETV_IF(NULL == common, CONTACTS_ERROR_INVALID_PARAMETER);
668 RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
670 if (pims_ipc_data_put(ipc_data,(void*)&common->r_type,sizeof(int)) < 0) {
671 return CONTACTS_ERROR_NO_DATA;
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;
680 if (pims_ipc_data_put(ipc_data,(void*)&common->property_max_count,sizeof(unsigned int)) < 0) {
681 return CONTACTS_ERROR_NO_DATA;
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;
691 if (pims_ipc_data_put(ipc_data,(void*)&common->property_flag,sizeof(char)) < 0) {
692 return CONTACTS_ERROR_NO_DATA;
694 return CONTACTS_ERROR_NONE;
697 int ctsvc_ipc_unmarshal_query(const pims_ipc_data_h ipc_data, contacts_query_h *out_query)
699 ctsvc_query_s *query = NULL;
700 unsigned int size = 0;
702 unsigned int count = 0, i = 0;
703 int ret = CONTACTS_ERROR_NONE;
705 RETV_IF(NULL == out_query, CONTACTS_ERROR_INVALID_PARAMETER);
706 RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
709 str = (char*)pims_ipc_data_get(ipc_data, &size);
711 ret = contacts_query_create(str, out_query);
712 if (CONTACTS_ERROR_NONE != ret) {
713 CTS_ERR("contacts_query_create() Fail");
716 query = (ctsvc_query_s *)*out_query;
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);
722 return CONTACTS_ERROR_IPC;
726 query->filter = NULL;
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);
735 return CONTACTS_ERROR_OUT_OF_MEMORY;
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;
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);
746 return CONTACTS_ERROR_IPC;
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);
753 return CONTACTS_ERROR_IPC;
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);
761 return CONTACTS_ERROR_IPC;
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);
770 return CONTACTS_ERROR_OUT_OF_MEMORY;
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);
777 return CONTACTS_ERROR_IPC;
782 query->projection = NULL;
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);
789 return CONTACTS_ERROR_IPC;
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);
796 return CONTACTS_ERROR_IPC;
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);
803 return CONTACTS_ERROR_IPC;
806 return CONTACTS_ERROR_NONE;
809 int ctsvc_ipc_marshal_query(const contacts_query_h query, pims_ipc_data_h ipc_data)
811 ctsvc_query_s *que = NULL;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
870 return CONTACTS_ERROR_NONE;
873 int ctsvc_ipc_unmarshal_list(const pims_ipc_data_h ipc_data, contacts_list_h* list)
876 unsigned int deleted_count = 0;
877 contacts_record_h record;
879 RETV_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER);
880 RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
882 if (CONTACTS_ERROR_NONE != contacts_list_create(list)) {
883 CTS_ERR("contacts_list_create() Fail");
884 return CONTACTS_ERROR_OUT_OF_MEMORY;
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);
891 return CONTACTS_ERROR_IPC;
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);
900 return CONTACTS_ERROR_IPC;
903 if (CONTACTS_ERROR_NONE != contacts_list_add(*list, record)) {
904 CTS_ERR("contacts_list_add() Fail");
905 contacts_list_destroy(*list, true);
907 return CONTACTS_ERROR_INVALID_PARAMETER;
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);
915 return CONTACTS_ERROR_IPC;
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);
924 return CONTACTS_ERROR_IPC;
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);
931 return CONTACTS_ERROR_IPC;
935 return CONTACTS_ERROR_NONE;
938 int ctsvc_ipc_unmarshal_child_list(const pims_ipc_data_h ipc_data, contacts_list_h* list)
942 unsigned int deleted_count = 0;
943 contacts_record_h record;
945 RETV_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER);
946 RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
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;
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;
959 if (CONTACTS_ERROR_NONE != contacts_list_add(*list,record)) {
960 CTS_ERR("contacts_list_add() Fail");
961 return CONTACTS_ERROR_INVALID_PARAMETER;
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;
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;
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;
983 return CONTACTS_ERROR_NONE;
986 int ctsvc_ipc_marshal_list(const contacts_list_h list, pims_ipc_data_h ipc_data)
989 unsigned int deleted_count = 0;
990 contacts_record_h record;
992 RETV_IF(NULL == list, CONTACTS_ERROR_INVALID_PARAMETER);
993 RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER);
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;
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;
1005 contacts_list_first(list);
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;
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;
1017 if (CONTACTS_ERROR_NO_DATA == contacts_list_next(list)) {
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;
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;
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;
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;
1044 return CONTACTS_ERROR_NONE;