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, int person_id)
34 int ret = CONTACTS_ERROR_NONE;
36 pims_ipc_data_h indata = NULL;
37 pims_ipc_data_h outdata = NULL;
39 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
40 RETVM_IF(base_person_id <= 0 || person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
41 "id should be greater than 0");
44 indata = pims_ipc_data_create(0);
46 ERR("pims_ipc_data_create() Fail");
47 return CONTACTS_ERROR_OUT_OF_MEMORY;
49 ret = ctsvc_ipc_marshal_handle(contact, indata);
50 if (CONTACTS_ERROR_NONE != ret) {
51 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
52 pims_ipc_data_destroy(indata);
58 if (ctsvc_ipc_marshal_int(base_person_id, indata) != CONTACTS_ERROR_NONE)
60 if (ctsvc_ipc_marshal_int(person_id, indata) != CONTACTS_ERROR_NONE)
66 if (success == false) {
67 ERR("ctsvc_ipc_marshal_int() Fail");
68 pims_ipc_data_destroy(indata);
69 return CONTACTS_ERROR_IPC;
73 ret = ctsvc_ipc_marshal_int(base_person_id, indata);
74 if (CONTACTS_ERROR_NONE != ret) {
78 ret = ctsvc_ipc_marshal_int(person_id, indata);
79 if (CONTACTS_ERROR_NONE != ret) {
86 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_LINK_PERSON,
87 indata, &outdata) != 0) {
88 ERR("ctsvc_ipc_call() Fail");
89 pims_ipc_data_destroy(indata);
90 return CONTACTS_ERROR_IPC;
93 pims_ipc_data_destroy(indata);
96 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
97 ERR("ctsvc_ipc_unmarshal_int() Fail");
98 pims_ipc_data_destroy(outdata);
99 return CONTACTS_ERROR_IPC;
102 if (CONTACTS_ERROR_NONE == ret) {
103 int transaction_ver = 0;
104 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
105 ERR("ctsvc_ipc_unmarshal_int() Fail");
106 pims_ipc_data_destroy(outdata);
107 return CONTACTS_ERROR_IPC;
109 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
112 pims_ipc_data_destroy(outdata);
118 int ctsvc_client_person_unlink_contact(contacts_h contact, int person_id, int contact_id,
119 int *unlinked_person_id)
121 int ret = CONTACTS_ERROR_NONE;
123 pims_ipc_data_h indata = NULL;
124 pims_ipc_data_h outdata = NULL;
126 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
127 RETVM_IF(person_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
128 "id should be greater than 0");
130 if (unlinked_person_id)
131 *unlinked_person_id = 0;
134 indata = pims_ipc_data_create(0);
135 if (NULL == indata) {
136 ERR("pims_ipc_data_create() Fail");
137 return CONTACTS_ERROR_OUT_OF_MEMORY;
140 ret = ctsvc_ipc_marshal_handle(contact, indata);
141 if (CONTACTS_ERROR_NONE != ret) {
142 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
143 pims_ipc_data_destroy(indata);
147 ret = ctsvc_ipc_marshal_int(person_id, indata);
148 if (CONTACTS_ERROR_NONE != ret) {
149 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
150 pims_ipc_data_destroy(indata);
153 ret = ctsvc_ipc_marshal_int(contact_id, indata);
154 if (CONTACTS_ERROR_NONE != ret) {
155 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
156 pims_ipc_data_destroy(indata);
161 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_UNLINK_CONTACT,
162 indata, &outdata) != 0) {
163 ERR("ctsvc_ipc_call() Fail");
164 pims_ipc_data_destroy(indata);
165 return CONTACTS_ERROR_IPC;
168 pims_ipc_data_destroy(indata);
171 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
172 ERR("ctsvc_ipc_unmarshal_int() Fail");
173 pims_ipc_data_destroy(outdata);
174 return CONTACTS_ERROR_IPC;
177 if (CONTACTS_ERROR_NONE == ret) {
178 int transaction_ver = 0;
179 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
180 ERR("ctsvc_ipc_unmarshal_int() Fail");
181 pims_ipc_data_destroy(outdata);
182 return CONTACTS_ERROR_IPC;
184 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
186 if (unlinked_person_id) {
187 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata,
188 unlinked_person_id)) {
189 ERR("ctsvc_ipc_unmarshal_int() Fail");
190 pims_ipc_data_destroy(outdata);
191 return CONTACTS_ERROR_IPC;
195 pims_ipc_data_destroy(outdata);
201 int ctsvc_client_person_reset_usage(contacts_h contact, int person_id,
202 contacts_usage_type_e type)
204 int ret = CONTACTS_ERROR_NONE;
206 pims_ipc_data_h indata = NULL;
207 pims_ipc_data_h outdata = NULL;
209 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
210 RETVM_IF(person_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
211 "contact_id should be greater than 0");
214 indata = pims_ipc_data_create(0);
215 if (NULL == indata) {
216 ERR("pims_ipc_data_create() Fail");
217 return CONTACTS_ERROR_OUT_OF_MEMORY;
220 ret = ctsvc_ipc_marshal_handle(contact, indata);
221 if (CONTACTS_ERROR_NONE != ret) {
222 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
223 pims_ipc_data_destroy(indata);
228 ret = ctsvc_ipc_marshal_int(person_id, indata);
229 if (CONTACTS_ERROR_NONE != ret) {
230 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
231 pims_ipc_data_destroy(indata);
234 ret = ctsvc_ipc_marshal_int((int)type, indata);
235 if (CONTACTS_ERROR_NONE != ret) {
236 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
237 pims_ipc_data_destroy(indata);
242 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_RESET_USAGE,
243 indata, &outdata) != 0) {
244 ERR("ctsvc_ipc_call() Fail");
245 pims_ipc_data_destroy(indata);
246 return CONTACTS_ERROR_IPC;
249 pims_ipc_data_destroy(indata);
252 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
253 ERR("ctsvc_ipc_unmarshal_int() Fail");
254 pims_ipc_data_destroy(outdata);
255 return CONTACTS_ERROR_IPC;
258 if (CONTACTS_ERROR_NONE == ret) {
259 int transaction_ver = 0;
260 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
261 ERR("ctsvc_ipc_unmarshal_int() Fail");
262 pims_ipc_data_destroy(outdata);
263 return CONTACTS_ERROR_IPC;
265 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
268 pims_ipc_data_destroy(outdata);
274 int ctsvc_client_person_set_favorite_order(contacts_h contact, int person_id,
275 int previous_person_id, int next_person_id)
277 int ret = CONTACTS_ERROR_NONE;
279 pims_ipc_data_h indata = NULL;
280 pims_ipc_data_h outdata = NULL;
282 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
283 RETVM_IF(person_id <= 0 || previous_person_id < 0 || next_person_id < 0,
284 CONTACTS_ERROR_INVALID_PARAMETER, "id should be greater than 0");
287 indata = pims_ipc_data_create(0);
288 if (NULL == indata) {
289 ERR("pims_ipc_data_create() Fail");
290 return CONTACTS_ERROR_OUT_OF_MEMORY;
293 ret = ctsvc_ipc_marshal_handle(contact, indata);
294 if (CONTACTS_ERROR_NONE != ret) {
295 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
296 pims_ipc_data_destroy(indata);
300 ret = ctsvc_ipc_marshal_int(person_id, indata);
301 if (CONTACTS_ERROR_NONE != ret) {
302 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
303 pims_ipc_data_destroy(indata);
306 ret = ctsvc_ipc_marshal_int(previous_person_id, indata);
307 if (CONTACTS_ERROR_NONE != ret) {
308 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
309 pims_ipc_data_destroy(indata);
312 ret = ctsvc_ipc_marshal_int(next_person_id, indata);
313 if (CONTACTS_ERROR_NONE != ret) {
314 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
315 pims_ipc_data_destroy(indata);
320 ret = ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE,
321 CTSVC_IPC_SERVER_PERSON_SET_FAVORITE_ORDER, indata, &outdata);
323 ERR("ctsvc_ipc_call() Fail");
324 pims_ipc_data_destroy(indata);
325 return CONTACTS_ERROR_IPC;
328 pims_ipc_data_destroy(indata);
331 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
332 ERR("ctsvc_ipc_unmarshal_int() Fail");
333 pims_ipc_data_destroy(outdata);
334 return CONTACTS_ERROR_IPC;
337 if (CONTACTS_ERROR_NONE == ret) {
338 int transaction_ver = 0;
339 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
340 ERR("ctsvc_ipc_unmarshal_int() Fail");
341 pims_ipc_data_destroy(outdata);
342 return CONTACTS_ERROR_IPC;
344 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
347 pims_ipc_data_destroy(outdata);
354 int ctsvc_client_person_set_default_property(contacts_h contact,
355 contacts_person_property_e property, int person_id, int id)
357 int ret = CONTACTS_ERROR_NONE;
359 pims_ipc_data_h indata = NULL;
360 pims_ipc_data_h outdata = NULL;
362 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
363 RETVM_IF(person_id <= 0 || id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
364 "id should be greater than 0");
367 indata = pims_ipc_data_create(0);
368 if (NULL == indata) {
369 ERR("pims_ipc_data_create() Fail");
370 return CONTACTS_ERROR_OUT_OF_MEMORY;
373 ret = ctsvc_ipc_marshal_handle(contact, indata);
374 if (CONTACTS_ERROR_NONE != ret) {
375 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
376 pims_ipc_data_destroy(indata);
380 ret = ctsvc_ipc_marshal_int(person_id, indata);
381 if (CONTACTS_ERROR_NONE != ret) {
382 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
383 pims_ipc_data_destroy(indata);
386 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
387 if (CONTACTS_ERROR_NONE != ret) {
388 ERR("ctsvc_ipc_marshal_unsigned_int() Fail(%d)", ret);
389 pims_ipc_data_destroy(indata);
392 ret = ctsvc_ipc_marshal_int(id, indata);
393 if (CONTACTS_ERROR_NONE != ret) {
394 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
395 pims_ipc_data_destroy(indata);
400 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_SET_DEFAULT_PROPERTY,
401 indata, &outdata) != 0) {
402 ERR("ctsvc_ipc_call() Fail");
403 pims_ipc_data_destroy(indata);
404 return CONTACTS_ERROR_IPC;
407 pims_ipc_data_destroy(indata);
410 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
411 ERR("ctsvc_ipc_unmarshal_int() Fail");
412 pims_ipc_data_destroy(outdata);
413 return CONTACTS_ERROR_IPC;
415 if (CONTACTS_ERROR_NONE == ret) {
416 int transaction_ver = 0;
417 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
418 ERR("ctsvc_ipc_unmarshal_int() Fail");
419 pims_ipc_data_destroy(outdata);
420 return CONTACTS_ERROR_IPC;
422 ctsvc_client_ipc_set_change_version(contact, transaction_ver);
425 pims_ipc_data_destroy(outdata);
431 int ctsvc_client_person_get_default_property(contacts_h contact,
432 contacts_person_property_e property, int person_id, int *id)
434 int ret = CONTACTS_ERROR_NONE;
435 pims_ipc_data_h indata = NULL;
436 pims_ipc_data_h outdata = NULL;
438 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
439 RETVM_IF(person_id <= 0 || id == NULL, CONTACTS_ERROR_INVALID_PARAMETER,
440 "id should be greater than 0");
444 indata = pims_ipc_data_create(0);
445 if (NULL == indata) {
446 ERR("pims_ipc_data_create() Fail");
447 return CONTACTS_ERROR_OUT_OF_MEMORY;
450 ret = ctsvc_ipc_marshal_handle(contact, indata);
451 if (CONTACTS_ERROR_NONE != ret) {
452 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
453 pims_ipc_data_destroy(indata);
457 ret = ctsvc_ipc_marshal_int(person_id, indata);
458 if (CONTACTS_ERROR_NONE != ret) {
459 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
460 pims_ipc_data_destroy(indata);
464 ret = ctsvc_ipc_marshal_unsigned_int(property, indata);
465 if (CONTACTS_ERROR_NONE != ret) {
466 ERR("ctsvc_ipc_marshal_unsigned_int() Fail(%d)", ret);
467 pims_ipc_data_destroy(indata);
472 if (ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_DEFAULT_PROPERTY,
473 indata, &outdata) != 0) {
474 ERR("ctsvc_ipc_call() Fail");
475 pims_ipc_data_destroy(indata);
476 return CONTACTS_ERROR_IPC;
479 pims_ipc_data_destroy(indata);
482 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
483 ERR("ctsvc_ipc_unmarshal_int() Fail");
484 pims_ipc_data_destroy(outdata);
485 return CONTACTS_ERROR_IPC;
487 if (ret == CONTACTS_ERROR_NONE && id) {
488 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, id)) {
489 ERR("ctsvc_ipc_unmarshal_int() Fail");
490 pims_ipc_data_destroy(outdata);
491 return CONTACTS_ERROR_IPC;
494 pims_ipc_data_destroy(outdata);
500 int ctsvc_client_person_get_aggregation_suggestions(contacts_h contact,
501 int person_id, int limit, contacts_list_h *out_list)
503 int ret = CONTACTS_ERROR_NONE;
504 int ret_val = CONTACTS_ERROR_NONE;
506 pims_ipc_data_h indata = NULL;
507 pims_ipc_data_h outdata = NULL;
509 RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
510 RETV_IF(person_id <= 0 || NULL == out_list, CONTACTS_ERROR_INVALID_PARAMETER);
513 indata = pims_ipc_data_create(0);
514 if (NULL == indata) {
515 ERR("pims_ipc_data_create() Fail");
516 return CONTACTS_ERROR_OUT_OF_MEMORY;
519 ret = ctsvc_ipc_marshal_handle(contact, indata);
520 if (CONTACTS_ERROR_NONE != ret) {
521 ERR("ctsvc_ipc_marshal_handle Fail(%d)", ret);
522 pims_ipc_data_destroy(indata);
526 ret = ctsvc_ipc_marshal_int(person_id, indata);
527 if (CONTACTS_ERROR_NONE != ret) {
528 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
529 pims_ipc_data_destroy(indata);
533 ret = ctsvc_ipc_marshal_int(limit, indata);
534 if (CONTACTS_ERROR_NONE != ret) {
535 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
536 pims_ipc_data_destroy(indata);
541 ret = ctsvc_ipc_call(CTSVC_IPC_PERSON_MODULE, CTSVC_IPC_SERVER_PERSON_GET_AGGREGATION_SUGGESTIONS,
543 pims_ipc_data_destroy(indata);
544 if (CONTACTS_ERROR_NONE != ret) {
545 ERR("ctsvc_ipc_call() Fail(%d)", ret);
546 return CONTACTS_ERROR_IPC;
550 ret = ctsvc_ipc_unmarshal_int(outdata, &ret_val);
551 if (CONTACTS_ERROR_NONE != ret) {
552 ERR("ctsvc_ipc_unmarshal_int() Fail(%d)", ret);
553 pims_ipc_data_destroy(outdata);
554 return CONTACTS_ERROR_IPC;
557 if (CONTACTS_ERROR_NONE == ret_val) {
558 ret = ctsvc_ipc_unmarshal_list(outdata, out_list);
559 if (CONTACTS_ERROR_NONE != ret) {
560 ERR("ctsvc_ipc_unmarshal_list() Fail(%d)");
561 pims_ipc_data_destroy(outdata);
562 return CONTACTS_ERROR_IPC;
565 pims_ipc_data_destroy(outdata);