4 * Copyright (c) 2010 - 2015 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.
19 #include <pims-ipc-data.h>
22 #include "ctsvc_internal.h"
23 #include "ctsvc_ipc_define.h"
24 #include "ctsvc_client_ipc.h"
25 #include "ctsvc_ipc_marshal.h"
27 static const char CONTACTS_READ_PRIVILEGE_ID[] = "http://tizen.org/privilege/contact.read";
28 static const char CONTACTS_WRITE_PRIVILEGE_ID[] = "http://tizen.org/privilege/contact.write";
29 static const char PHONELOG_READ_PRIVILEGE_ID[] = "http://tizen.org/privilege/callhistory.read";
30 static const char PHONELOG_WRITE_PRIVILEGE_ID[] = "http://tizen.org/privilege/callhistory.write";
32 int ctsvc_client_person_link_person(contacts_h contact, int base_person_id,
35 int ret = CONTACTS_ERROR_NONE;
37 pims_ipc_data_h indata = NULL;
38 pims_ipc_data_h outdata = NULL;
40 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
41 RETVM_IF(base_person_id <= 0 || person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
42 "id should be greater than 0");
45 indata = pims_ipc_data_create(0);
47 ERR("pims_ipc_data_create() Fail");
48 return CONTACTS_ERROR_OUT_OF_MEMORY;
50 ret = ctsvc_ipc_marshal_handle(contact, indata);
51 if (CONTACTS_ERROR_NONE != ret) {
52 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
53 pims_ipc_data_destroy(indata);
59 if (ctsvc_ipc_marshal_int(base_person_id, indata) != CONTACTS_ERROR_NONE)
61 if (ctsvc_ipc_marshal_int(person_id, indata) != CONTACTS_ERROR_NONE)
67 if (success == false) {
68 ERR("ctsvc_ipc_marshal_int() Fail");
69 pims_ipc_data_destroy(indata);
70 return CONTACTS_ERROR_IPC;
74 ret = ctsvc_ipc_marshal_int(base_person_id, indata);
75 if (CONTACTS_ERROR_NONE != ret) {
79 ret = ctsvc_ipc_marshal_int(person_id, indata);
80 if (CONTACTS_ERROR_NONE != ret) {
87 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_LINK_PERSON,
88 indata, &outdata) != 0) {
89 ERR("ctsvc_ipc_call() Fail");
90 pims_ipc_data_destroy(indata);
91 return CONTACTS_ERROR_IPC;
94 pims_ipc_data_destroy(indata);
97 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
98 ERR("ctsvc_ipc_unmarshal_int() Fail");
99 pims_ipc_data_destroy(outdata);
100 return CONTACTS_ERROR_IPC;
103 if (CONTACTS_ERROR_NONE == ret) {
104 int transaction_ver = 0;
105 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
106 ERR("ctsvc_ipc_unmarshal_int() Fail");
107 pims_ipc_data_destroy(outdata);
108 return CONTACTS_ERROR_IPC;
110 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
113 pims_ipc_data_destroy(outdata);
119 int ctsvc_client_person_unlink_contact(contacts_h contact, int person_id, int contact_id,
120 int *unlinked_person_id)
122 int ret = CONTACTS_ERROR_NONE;
124 pims_ipc_data_h indata = NULL;
125 pims_ipc_data_h outdata = NULL;
127 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
128 RETVM_IF(person_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
129 "id should be greater than 0");
131 if (unlinked_person_id)
132 *unlinked_person_id = 0;
135 indata = pims_ipc_data_create(0);
136 if (NULL == indata) {
137 ERR("pims_ipc_data_create() Fail");
138 return CONTACTS_ERROR_OUT_OF_MEMORY;
141 ret = ctsvc_ipc_marshal_handle(contact, indata);
142 if (CONTACTS_ERROR_NONE != ret) {
143 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
144 pims_ipc_data_destroy(indata);
148 ret = ctsvc_ipc_marshal_int(person_id, indata);
149 if (CONTACTS_ERROR_NONE != ret) {
150 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
151 pims_ipc_data_destroy(indata);
154 ret = ctsvc_ipc_marshal_int(contact_id, indata);
155 if (CONTACTS_ERROR_NONE != ret) {
156 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
157 pims_ipc_data_destroy(indata);
162 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_UNLINK_CONTACT,
163 indata, &outdata) != 0) {
164 ERR("ctsvc_ipc_call() Fail");
165 pims_ipc_data_destroy(indata);
166 return CONTACTS_ERROR_IPC;
169 pims_ipc_data_destroy(indata);
172 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
173 ERR("ctsvc_ipc_unmarshal_int() Fail");
174 pims_ipc_data_destroy(outdata);
175 return CONTACTS_ERROR_IPC;
178 if (CONTACTS_ERROR_NONE == ret) {
179 int transaction_ver = 0;
180 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
181 ERR("ctsvc_ipc_unmarshal_int() Fail");
182 pims_ipc_data_destroy(outdata);
183 return CONTACTS_ERROR_IPC;
185 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
187 if (unlinked_person_id) {
188 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata,
189 unlinked_person_id)) {
190 ERR("ctsvc_ipc_unmarshal_int() Fail");
191 pims_ipc_data_destroy(outdata);
192 return CONTACTS_ERROR_IPC;
196 pims_ipc_data_destroy(outdata);
202 int ctsvc_client_person_reset_usage(contacts_h contact, int person_id,
203 contacts_usage_type_e type)
205 int ret = CONTACTS_ERROR_NONE;
207 pims_ipc_data_h indata = NULL;
208 pims_ipc_data_h outdata = NULL;
210 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
211 RETVM_IF(person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
212 "contact_id should be greater than 0");
215 indata = pims_ipc_data_create(0);
216 if (NULL == indata) {
217 ERR("pims_ipc_data_create() Fail");
218 return CONTACTS_ERROR_OUT_OF_MEMORY;
221 ret = ctsvc_ipc_marshal_handle(contact, indata);
222 if (CONTACTS_ERROR_NONE != ret) {
223 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
224 pims_ipc_data_destroy(indata);
229 ret = ctsvc_ipc_marshal_int(person_id, indata);
230 if (CONTACTS_ERROR_NONE != ret) {
231 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
232 pims_ipc_data_destroy(indata);
235 ret = ctsvc_ipc_marshal_int((int)type, indata);
236 if (CONTACTS_ERROR_NONE != ret) {
237 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
238 pims_ipc_data_destroy(indata);
243 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_RESET_USAGE,
244 indata, &outdata) != 0) {
245 ERR("ctsvc_ipc_call() Fail");
246 pims_ipc_data_destroy(indata);
247 return CONTACTS_ERROR_IPC;
250 pims_ipc_data_destroy(indata);
253 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
254 ERR("ctsvc_ipc_unmarshal_int() Fail");
255 pims_ipc_data_destroy(outdata);
256 return CONTACTS_ERROR_IPC;
259 if (CONTACTS_ERROR_NONE == ret) {
260 int transaction_ver = 0;
261 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
262 ERR("ctsvc_ipc_unmarshal_int() Fail");
263 pims_ipc_data_destroy(outdata);
264 return CONTACTS_ERROR_IPC;
266 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
269 pims_ipc_data_destroy(outdata);
275 int ctsvc_client_person_set_favorite_order(contacts_h contact, int person_id,
276 int previous_person_id, int next_person_id)
278 int ret = CONTACTS_ERROR_NONE;
280 pims_ipc_data_h indata = NULL;
281 pims_ipc_data_h outdata = NULL;
283 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
284 RETVM_IF(person_id <= 0 || previous_person_id < 0 || next_person_id < 0,
285 CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
288 indata = pims_ipc_data_create(0);
289 if (NULL == indata) {
290 ERR("pims_ipc_data_create() Fail");
291 return CONTACTS_ERROR_OUT_OF_MEMORY;
294 ret = ctsvc_ipc_marshal_handle(contact, indata);
295 if (CONTACTS_ERROR_NONE != ret) {
296 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
297 pims_ipc_data_destroy(indata);
301 ret = ctsvc_ipc_marshal_int(person_id, indata);
302 if (CONTACTS_ERROR_NONE != ret) {
303 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
304 pims_ipc_data_destroy(indata);
307 ret = ctsvc_ipc_marshal_int(previous_person_id, indata);
308 if (CONTACTS_ERROR_NONE != ret) {
309 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
310 pims_ipc_data_destroy(indata);
313 ret = ctsvc_ipc_marshal_int(next_person_id, indata);
314 if (CONTACTS_ERROR_NONE != ret) {
315 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
316 pims_ipc_data_destroy(indata);
321 ret = ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE,
322 CTSVC_IPC_SERVER_PERSON_SET_FAVORITE_ORDER, indata, &outdata);
324 ERR("ctsvc_ipc_call() Fail");
325 pims_ipc_data_destroy(indata);
326 return CONTACTS_ERROR_IPC;
329 pims_ipc_data_destroy(indata);
332 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
333 ERR("ctsvc_ipc_unmarshal_int() Fail");
334 pims_ipc_data_destroy(outdata);
335 return CONTACTS_ERROR_IPC;
338 if (CONTACTS_ERROR_NONE == ret) {
339 int transaction_ver = 0;
340 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
341 ERR("ctsvc_ipc_unmarshal_int() Fail");
342 pims_ipc_data_destroy(outdata);
343 return CONTACTS_ERROR_IPC;
345 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
348 pims_ipc_data_destroy(outdata);
355 int ctsvc_client_person_set_default_property(contacts_h contact,
356 contacts_person_property_e property, int person_id, int id)
358 int ret = CONTACTS_ERROR_NONE;
360 pims_ipc_data_h indata = NULL;
361 pims_ipc_data_h outdata = NULL;
363 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
364 RETVM_IF(person_id <= 0 || id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
365 "id should be greater than 0");
368 indata = pims_ipc_data_create(0);
369 if (NULL == indata) {
370 ERR("pims_ipc_data_create() Fail");
371 return CONTACTS_ERROR_OUT_OF_MEMORY;
374 ret = ctsvc_ipc_marshal_handle(contact, indata);
375 if (CONTACTS_ERROR_NONE != ret) {
376 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
377 pims_ipc_data_destroy(indata);
381 ret = ctsvc_ipc_marshal_int(person_id, indata);
382 if (CONTACTS_ERROR_NONE != ret) {
383 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
384 pims_ipc_data_destroy(indata);
387 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
388 if (CONTACTS_ERROR_NONE != ret) {
389 ERR("ctsvc_ipc_marshal_unsigned_int() Fail(%d)", ret);
390 pims_ipc_data_destroy(indata);
393 ret = ctsvc_ipc_marshal_int(id, indata);
394 if (CONTACTS_ERROR_NONE != ret) {
395 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
396 pims_ipc_data_destroy(indata);
401 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_DEFAULT_PROPERTY,
402 indata, &outdata) != 0) {
403 ERR("ctsvc_ipc_call() Fail");
404 pims_ipc_data_destroy(indata);
405 return CONTACTS_ERROR_IPC;
408 pims_ipc_data_destroy(indata);
411 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
412 ERR("ctsvc_ipc_unmarshal_int() Fail");
413 pims_ipc_data_destroy(outdata);
414 return CONTACTS_ERROR_IPC;
416 if (CONTACTS_ERROR_NONE == ret) {
417 int transaction_ver = 0;
418 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
419 ERR("ctsvc_ipc_unmarshal_int() Fail");
420 pims_ipc_data_destroy(outdata);
421 return CONTACTS_ERROR_IPC;
423 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
426 pims_ipc_data_destroy(outdata);
432 int ctsvc_client_person_get_default_property(contacts_h contact,
433 contacts_person_property_e property, int person_id, int *id)
435 int ret = CONTACTS_ERROR_NONE;
436 pims_ipc_data_h indata = NULL;
437 pims_ipc_data_h outdata = NULL;
439 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
440 RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,
441 "id should be greater than 0");
445 indata = pims_ipc_data_create(0);
446 if (NULL == indata) {
447 ERR("pims_ipc_data_create() Fail");
448 return CONTACTS_ERROR_OUT_OF_MEMORY;
451 ret = ctsvc_ipc_marshal_handle(contact, indata);
452 if (CONTACTS_ERROR_NONE != ret) {
453 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
454 pims_ipc_data_destroy(indata);
458 ret = ctsvc_ipc_marshal_int(person_id, indata);
459 if (CONTACTS_ERROR_NONE != ret) {
460 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
461 pims_ipc_data_destroy(indata);
465 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
466 if (CONTACTS_ERROR_NONE != ret) {
467 ERR("ctsvc_ipc_marshal_unsigned_int() Fail(%d)", ret);
468 pims_ipc_data_destroy(indata);
473 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_DEFAULT_PROPERTY,
474 indata, &outdata) != 0) {
475 ERR("ctsvc_ipc_call() Fail");
476 pims_ipc_data_destroy(indata);
477 return CONTACTS_ERROR_IPC;
480 pims_ipc_data_destroy(indata);
483 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
484 ERR("ctsvc_ipc_unmarshal_int() Fail");
485 pims_ipc_data_destroy(outdata);
486 return CONTACTS_ERROR_IPC;
488 if (ret == CONTACTS_ERROR_NONE && id) {
489 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, id)) {
490 ERR("ctsvc_ipc_unmarshal_int() Fail");
491 pims_ipc_data_destroy(outdata);
492 return CONTACTS_ERROR_IPC;
495 pims_ipc_data_destroy(outdata);
501 int ctsvc_client_person_get_aggregation_suggestions(contacts_h contact,
502 int person_id, int limit, contacts_list_h *out_list)
504 int ret = CONTACTS_ERROR_NONE;
505 int ret_val = CONTACTS_ERROR_NONE;
507 pims_ipc_data_h indata = NULL;
508 pims_ipc_data_h outdata = NULL;
510 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
511 RETV_IF(person_id <= 0 ||NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
514 indata = pims_ipc_data_create(0);
515 if (NULL == indata) {
516 ERR("pims_ipc_data_create() Fail");
517 return CONTACTS_ERROR_OUT_OF_MEMORY;
520 ret = ctsvc_ipc_marshal_handle(contact, indata);
521 if (CONTACTS_ERROR_NONE != ret) {
522 ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
523 pims_ipc_data_destroy(indata);
527 ret = ctsvc_ipc_marshal_int(person_id, indata);
528 if (CONTACTS_ERROR_NONE != ret) {
529 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
530 pims_ipc_data_destroy(indata);
534 ret = ctsvc_ipc_marshal_int(limit, indata);
535 if (CONTACTS_ERROR_NONE != ret) {
536 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
537 pims_ipc_data_destroy(indata);
542 ret = ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_AGGREGATION_SUGGESTIONS,
544 pims_ipc_data_destroy(indata);
545 if (CONTACTS_ERROR_NONE != ret) {
546 ERR("ctsvc_ipc_call() Fail(%d)", ret);
547 return CONTACTS_ERROR_IPC;
551 ret = ctsvc_ipc_unmarshal_int(outdata, &ret_val);
552 if (CONTACTS_ERROR_NONE != ret) {
553 ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
554 pims_ipc_data_destroy(outdata);
555 return CONTACTS_ERROR_IPC;
558 if (CONTACTS_ERROR_NONE == ret_val) {
559 ret = ctsvc_ipc_unmarshal_list(outdata, out_list);
560 if (CONTACTS_ERROR_NONE != ret) {
561 ERR("ctsvc_ipc_unmarshal_list() Fail(%d)");
562 pims_ipc_data_destroy(outdata);
563 return CONTACTS_ERROR_IPC;
566 pims_ipc_data_destroy(outdata);