Add user space access control
[platform/core/pim/contacts-service.git] / client / ctsvc_client_group.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 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 <glib.h>
21
22 #include "contacts.h"
23 #include "ctsvc_internal.h"
24 #include "ctsvc_ipc_define.h"
25 #include "ctsvc_client_ipc.h"
26 #include <pims-ipc-data.h>
27 #include "ctsvc_ipc_marshal.h"
28
29 API int contacts_group_add_contact(int group_id, int contact_id)
30 {
31         int ret = CONTACTS_ERROR_NONE;
32
33         pims_ipc_data_h indata = NULL;
34         pims_ipc_data_h outdata = NULL;
35
36         RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
37         RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
38
39         // make indata
40         indata = pims_ipc_data_create(0);
41         if (indata == NULL)
42         {
43                 CTS_ERR("ipc data created fail!");
44                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
45                 return ret;
46         }
47
48         ret = ctsvc_ipc_marshal_int( group_id, indata);
49         if (ret != CONTACTS_ERROR_NONE)
50         {
51                 CTS_ERR("marshal fail");
52                 return ret;
53         }
54         ret = ctsvc_ipc_marshal_int( contact_id, indata);
55         if (ret != CONTACTS_ERROR_NONE)
56         {
57                 CTS_ERR("marshal fail");
58                 return ret;
59         }
60
61         // ipc call
62         if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_ADD_CONTACT, indata, &outdata) != 0)
63         {
64                 CTS_ERR("ctsvc_ipc_call failed");
65                 return CONTACTS_ERROR_IPC;
66         }
67
68         if (indata)
69         {
70                 pims_ipc_data_destroy(indata);
71         }
72
73         if (outdata)
74         {
75                 // check result
76                 unsigned int size = 0;
77                 ret = *(int*) pims_ipc_data_get(outdata, &size);
78
79                 if (CONTACTS_ERROR_NONE == ret) {
80                         int transaction_ver = 0;
81                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
82                         ctsvc_client_ipc_set_change_version(transaction_ver);
83                 }
84
85                 pims_ipc_data_destroy(outdata);
86         }
87
88         return ret;
89 }
90
91 API int contacts_group_remove_contact(int group_id, int contact_id)
92 {
93         int ret = CONTACTS_ERROR_NONE;
94
95         pims_ipc_data_h indata = NULL;
96         pims_ipc_data_h outdata = NULL;
97
98         RETVM_IF(group_id <= 0 || contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
99         RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
100
101         // make indata
102         indata = pims_ipc_data_create(0);
103         if (indata == NULL)
104         {
105                 CTS_ERR("ipc data created fail!");
106                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
107                 return ret;
108         }
109
110         ret = ctsvc_ipc_marshal_int( group_id, indata);
111         if (ret != CONTACTS_ERROR_NONE)
112         {
113                 CTS_ERR("marshal fail");
114                 return ret;
115         }
116         ret = ctsvc_ipc_marshal_int( contact_id, indata);
117         if (ret != CONTACTS_ERROR_NONE)
118         {
119                 CTS_ERR("marshal fail");
120                 return ret;
121         }
122
123         // ipc call
124         if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_REMOVE_CONTACT, indata, &outdata) != 0)
125         {
126                 CTS_ERR("ctsvc_ipc_call failed");
127                 return CONTACTS_ERROR_IPC;
128         }
129
130         if (indata)
131         {
132                 pims_ipc_data_destroy(indata);
133         }
134
135         if (outdata)
136         {
137                 // check result
138                 unsigned int size = 0;
139                 ret = *(int*) pims_ipc_data_get(outdata, &size);
140
141                 if (CONTACTS_ERROR_NONE == ret) {
142                         int transaction_ver = 0;
143                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
144                         ctsvc_client_ipc_set_change_version(transaction_ver);
145                 }
146
147                 pims_ipc_data_destroy(outdata);
148         }
149
150         return ret;
151 }
152
153 API int contacts_group_set_group_order(int group_id, int previous_group_id, int next_group_id)
154 {
155         int ret = CONTACTS_ERROR_NONE;
156
157         pims_ipc_data_h indata = NULL;
158         pims_ipc_data_h outdata = NULL;
159
160         RETVM_IF(group_id <= 0 || previous_group_id < 0 || next_group_id < 0, CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");
161         RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
162
163         // make indata
164         indata = pims_ipc_data_create(0);
165         if (indata == NULL)
166         {
167                 CTS_ERR("ipc data created fail!");
168                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
169                 return ret;
170         }
171
172         ret = ctsvc_ipc_marshal_int( group_id, indata);
173         if (ret != CONTACTS_ERROR_NONE)
174         {
175                 CTS_ERR("marshal fail");
176                 pims_ipc_data_destroy(indata);
177                 return ret;
178         }
179         ret = ctsvc_ipc_marshal_int( previous_group_id, indata);
180         if (ret != CONTACTS_ERROR_NONE)
181         {
182                 CTS_ERR("marshal fail");
183                 pims_ipc_data_destroy(indata);
184                 return ret;
185         }
186         ret = ctsvc_ipc_marshal_int( next_group_id, indata);
187         if (ret != CONTACTS_ERROR_NONE)
188         {
189                 CTS_ERR("marshal fail");
190                 pims_ipc_data_destroy(indata);
191                 return ret;
192         }
193
194         // ipc call
195         if (ctsvc_ipc_call(CTSVC_IPC_GROUP_MODULE, CTSVC_IPC_SERVER_GROUP_SET_GROUP_ORDER, indata, &outdata) != 0)
196         {
197                 CTS_ERR("ctsvc_ipc_call failed");
198                 pims_ipc_data_destroy(indata);
199                 return CONTACTS_ERROR_IPC;
200         }
201
202         if (indata)
203         {
204                 pims_ipc_data_destroy(indata);
205         }
206
207         if (outdata)
208         {
209                 // check result
210                 unsigned int size = 0;
211                 ret = *(int*) pims_ipc_data_get(outdata, &size);
212
213                 if (CONTACTS_ERROR_NONE == ret) {
214                         int transaction_ver = 0;
215                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
216                         ctsvc_client_ipc_set_change_version(transaction_ver);
217                 }
218
219                 pims_ipc_data_destroy(outdata);
220         }
221
222         return ret;
223
224 }
225