Add user space access control
[platform/core/pim/contacts-service.git] / client / ctsvc_client_activity.c
1 /*\r
2  * Contacts Service\r
3  *\r
4  * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
5  *\r
6  * Licensed under the Apache License, Version 2.0 (the "License");\r
7  * you may not use this file except in compliance with the License.\r
8  * You may obtain a copy of the License at\r
9  *\r
10  * http://www.apache.org/licenses/LICENSE-2.0\r
11  *\r
12  * Unless required by applicable law or agreed to in writing, software\r
13  * distributed under the License is distributed on an "AS IS" BASIS,\r
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
15  * See the License for the specific language governing permissions and\r
16  * limitations under the License.\r
17  *\r
18  */\r
19 \r
20 #include <glib.h>\r
21 \r
22 #include "contacts.h"\r
23 #include "ctsvc_internal.h"\r
24 #include "ctsvc_ipc_define.h"\r
25 #include "ctsvc_ipc_marshal.h"\r
26 #include "ctsvc_client_ipc.h"\r
27 #include <pims-ipc-data.h>\r
28 \r
29 API int contacts_activity_delete_by_contact_id(int contact_id)\r
30 {\r
31         int ret = CONTACTS_ERROR_NONE;\r
32         pims_ipc_data_h indata = NULL;\r
33         pims_ipc_data_h outdata = NULL;\r
34 \r
35         RETVM_IF(contact_id <= 0,CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");\r
36 \r
37         // make indata\r
38         indata = pims_ipc_data_create(0);\r
39         if (indata == NULL)\r
40         {\r
41                 CTS_ERR("ipc data created fail!");\r
42                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;\r
43                 return ret;\r
44         }\r
45 \r
46         ret = ctsvc_ipc_marshal_int( contact_id, indata);\r
47         if (ret != CONTACTS_ERROR_NONE)\r
48         {\r
49                 CTS_ERR("marshal fail");\r
50                 return ret;\r
51         }\r
52 \r
53         // ipc call\r
54         if (ctsvc_ipc_call( CTSVC_IPC_ACTIVITY_MODULE, CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_CONTACT_ID, indata, &outdata) != 0)\r
55         {\r
56                 CTS_ERR("ctsvc_ipc_call failed");\r
57                 pims_ipc_data_destroy(indata);\r
58                 return CONTACTS_ERROR_IPC;\r
59         }\r
60 \r
61         if (indata)\r
62         {\r
63                 pims_ipc_data_destroy(indata);\r
64         }\r
65 \r
66         if (outdata)\r
67         {\r
68                 // check result\r
69                 unsigned int size = 0;\r
70                 ret = *(int*) pims_ipc_data_get(outdata, &size);\r
71                 if (CONTACTS_ERROR_NONE == ret) {\r
72                         int transaction_ver = 0;\r
73                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);\r
74                         ctsvc_client_ipc_set_change_version(transaction_ver);\r
75                 }\r
76 \r
77                 pims_ipc_data_destroy(outdata);\r
78         }\r
79 \r
80         return ret;\r
81 }\r
82 \r
83 API int contacts_activity_delete_by_account_id(int account_id)\r
84 {\r
85         int ret = CONTACTS_ERROR_NONE;\r
86         pims_ipc_data_h indata = NULL;\r
87         pims_ipc_data_h outdata = NULL;\r
88 \r
89         RETVM_IF(account_id <= 0,CONTACTS_ERROR_INVALID_PARAMETER,"id should be greater than 0");\r
90 \r
91         // make indata\r
92         indata = pims_ipc_data_create(0);\r
93         if (indata == NULL)\r
94         {\r
95                 CTS_ERR("ipc data created fail!");\r
96                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;\r
97                 return ret;\r
98         }\r
99 \r
100         ret = ctsvc_ipc_marshal_int( account_id, indata);\r
101         if (ret != CONTACTS_ERROR_NONE)\r
102         {\r
103                 CTS_ERR("marshal fail");\r
104                 return ret;\r
105         }\r
106 \r
107         // ipc call\r
108         if (ctsvc_ipc_call( CTSVC_IPC_ACTIVITY_MODULE, CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_ACCOUNT_ID, indata, &outdata) != 0)\r
109         {\r
110                 CTS_ERR("ctsvc_ipc_call failed");\r
111                 pims_ipc_data_destroy(indata);\r
112                 return CONTACTS_ERROR_IPC;\r
113         }\r
114 \r
115         if (indata)\r
116         {\r
117                 pims_ipc_data_destroy(indata);\r
118         }\r
119 \r
120         if (outdata)\r
121         {\r
122                 // check result\r
123                 unsigned int size = 0;\r
124                 ret = *(int*) pims_ipc_data_get(outdata, &size);\r
125                 if (CONTACTS_ERROR_NONE == ret) {\r
126                         int transaction_ver = 0;\r
127                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);\r
128                         ctsvc_client_ipc_set_change_version(transaction_ver);\r
129                 }\r
130 \r
131                 pims_ipc_data_destroy(outdata);\r
132         }\r
133 \r
134         return ret;\r
135 }\r
136 \r