Add APIs to set/get limit size of photo for vcard
[platform/core/pim/contacts-service.git] / client / ctsvc_client_activity_helper.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 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 <pims-ipc-data.h>
21
22 #include "contacts.h"
23 #include "ctsvc_internal.h"
24 #include "ctsvc_ipc_define.h"
25 #include "ctsvc_ipc_marshal.h"
26 #include "ctsvc_client_ipc.h"
27
28 static const char CONTACTS_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.read";
29 static const char CONTACTS_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/contact.write";
30 static const char PHONELOG_READ_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.read";
31 static const char PHONELOG_WRITE_PRIVILEGE_ID[] =  "http://tizen.org/privilege/callhistory.write";
32
33
34 int ctsvc_client_activity_delete_by_contact_id(contacts_h contact, int contact_id)
35 {
36         int ret = CONTACTS_ERROR_NONE;
37         pims_ipc_data_h indata = NULL;
38         pims_ipc_data_h outdata = NULL;
39
40         RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
41         RETVM_IF(contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
42                         "id should be greater than 0");
43
44         /* make indata */
45         indata = pims_ipc_data_create(0);
46         if (indata == NULL) {
47                 ERR("pims_ipc_data_create() Fail");
48                 return CONTACTS_ERROR_OUT_OF_MEMORY;
49         }
50
51         ret = ctsvc_ipc_marshal_handle(contact, indata);
52         if (CONTACTS_ERROR_NONE != ret) {
53                 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
54                 pims_ipc_data_destroy(indata);
55                 return ret;
56         }
57
58         ret = ctsvc_ipc_marshal_int(contact_id, indata);
59         if (ret != CONTACTS_ERROR_NONE) {
60                 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
61                 pims_ipc_data_destroy(indata);
62                 return ret;
63         }
64
65         /* ipc call */
66         ret = ctsvc_ipc_call(CTSVC_IPC_ACTIVITY_MODULE,
67                         CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_CONTACT_ID, indata, &outdata);
68         if (0 != ret) {
69                 ERR("ctsvc_ipc_call() Fail(%d)", ret);
70                 pims_ipc_data_destroy(indata);
71                 return CONTACTS_ERROR_IPC;
72         }
73
74         pims_ipc_data_destroy(indata);
75
76         if (outdata) {
77                 int transaction_ver = 0;
78
79                 /* check result */
80                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
81                         ERR("ctsvc_ipc_unmarshal_int() Fail");
82                         pims_ipc_data_destroy(outdata);
83                         return CONTACTS_ERROR_IPC;
84                 }
85                 if (CONTACTS_ERROR_NONE == ret) {
86                         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
87                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
88                                 pims_ipc_data_destroy(outdata);
89                                 return CONTACTS_ERROR_IPC;
90                         }
91                         ctsvc_client_ipc_set_change_version(contact, transaction_ver);
92                 }
93                 pims_ipc_data_destroy(outdata);
94         }
95
96         return ret;
97 }
98
99 int ctsvc_client_activity_delete_by_account_id(contacts_h contact, int account_id)
100 {
101         int ret = CONTACTS_ERROR_NONE;
102         pims_ipc_data_h indata = NULL;
103         pims_ipc_data_h outdata = NULL;
104
105         RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
106         RETVM_IF(account_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
107                         "id should be greater than 0");
108
109         /* make indata */
110         indata = pims_ipc_data_create(0);
111         if (indata == NULL) {
112                 ERR("pims_ipc_data_create() Fail");
113                 return CONTACTS_ERROR_OUT_OF_MEMORY;
114         }
115
116         ret = ctsvc_ipc_marshal_handle(contact, indata);
117         if (CONTACTS_ERROR_NONE != ret) {
118                 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
119                 pims_ipc_data_destroy(indata);
120                 return ret;
121         }
122
123         ret = ctsvc_ipc_marshal_int(account_id, indata);
124         if (ret != CONTACTS_ERROR_NONE) {
125                 ERR("ctsvc_ipc_marshal_record() Fail");
126                 pims_ipc_data_destroy(indata);
127                 return ret;
128         }
129
130         /* ipc call */
131         ret = ctsvc_ipc_call(CTSVC_IPC_ACTIVITY_MODULE,
132                         CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_ACCOUNT_ID, indata, &outdata);
133         if (0 != ret) {
134                 ERR("ctsvc_ipc_call() Fail(%d)", ret);
135                 pims_ipc_data_destroy(indata);
136                 return CONTACTS_ERROR_IPC;
137         }
138
139         pims_ipc_data_destroy(indata);
140
141         if (outdata) {
142                 int transaction_ver = 0;
143                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
144                         ERR("ctsvc_ipc_unmarshal_int() Fail");
145                         pims_ipc_data_destroy(outdata);
146                         return CONTACTS_ERROR_IPC;
147                 }
148
149                 if (CONTACTS_ERROR_NONE == ret) {
150                         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
151                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
152                                 pims_ipc_data_destroy(outdata);
153                                 return CONTACTS_ERROR_IPC;
154                         }
155                         ctsvc_client_ipc_set_change_version(contact, transaction_ver);
156                 }
157                 pims_ipc_data_destroy(outdata);
158         }
159
160         return ret;
161 }
162