Add user space access control
[platform/core/pim/contacts-service.git] / client / ctsvc_client_phonelog.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_phone_log_reset_statistics(void)
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(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");
37
38         // make indata
39         indata = pims_ipc_data_create(0);
40         if (indata == NULL)
41         {
42                 CTS_ERR("ipc data created fail!");
43                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
44                 return ret;
45         }
46
47         // ipc call
48         if (ctsvc_ipc_call(CTSVC_IPC_PHONELOG_MODULE, CTSVC_IPC_SERVER_PHONELOG_RESET_STATISTICS, indata, &outdata) != 0)
49         {
50                 CTS_ERR("ctsvc_ipc_call failed");
51                 return CONTACTS_ERROR_IPC;
52         }
53
54         if (indata)
55         {
56                 pims_ipc_data_destroy(indata);
57         }
58
59         if (outdata)
60         {
61                 // check result
62                 unsigned int size = 0;
63                 ret = *(int*) pims_ipc_data_get(outdata, &size);
64
65                 if (CONTACTS_ERROR_NONE == ret) {
66                         int transaction_ver = 0;
67                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
68                         ctsvc_client_ipc_set_change_version(transaction_ver);
69                 }
70
71                 pims_ipc_data_destroy(outdata);
72         }
73
74         return ret;
75
76 }
77
78 API int contacts_phone_log_delete(contacts_phone_log_delete_e op, ...)
79 {
80         int ret = CONTACTS_ERROR_NONE;
81
82         pims_ipc_data_h indata = NULL;
83         pims_ipc_data_h outdata = NULL;
84         char *number = NULL;
85         int extra_data1;
86
87         va_list args;
88
89         RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC, "contacts not connected");
90
91         indata = pims_ipc_data_create(0);
92         if (indata == NULL) {
93                 CTS_ERR("ipc data created fail!");
94                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
95                 pims_ipc_data_destroy(indata);
96                 return ret;
97         }
98
99         ret = ctsvc_ipc_marshal_int( op, indata);
100         if (ret != CONTACTS_ERROR_NONE) {
101                 CTS_ERR("ctsvc_ipc_marshal_int fail");
102                 pims_ipc_data_destroy(indata);
103                 return ret;
104         }
105
106         switch(op) {
107         case CONTACTS_PHONE_LOG_DELETE_BY_ADDRESS:
108                 va_start(args, op);
109                 number = va_arg(args, char *);
110                 va_end(args);
111                 RETV_IF(NULL == number, CONTACTS_ERROR_INVALID_PARAMETER);
112                 ret = ctsvc_ipc_marshal_string( number, indata);
113                 if (ret != CONTACTS_ERROR_NONE) {
114                         CTS_ERR("ctsvc_ipc_marshal_string fail");
115                         pims_ipc_data_destroy(indata);
116                         return ret;
117                 }
118                 break;
119         case CONTACTS_PHONE_LOG_DELETE_BY_MESSAGE_EXTRA_DATA1:
120         case CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1:
121                 va_start(args, op);
122                 extra_data1 = va_arg(args, int);
123                 va_end(args);
124                 ret = ctsvc_ipc_marshal_int( extra_data1, indata);
125                 if (ret != CONTACTS_ERROR_NONE) {
126                         CTS_ERR("ctsvc_ipc_marshal_int fail");
127                         pims_ipc_data_destroy(indata);
128                         return ret;
129                 }
130                 break;
131         default:
132                 CTS_ERR("Invalid parameter : operation is not proper (%d)", ret);
133                 pims_ipc_data_destroy(indata);
134                 return CONTACTS_ERROR_INVALID_PARAMETER;
135         }
136
137         if (ctsvc_ipc_call(CTSVC_IPC_PHONELOG_MODULE,
138                         CTSVC_IPC_SERVER_PHONELOG_DELETE, indata, &outdata) != 0) {
139                 CTS_ERR("ctsvc_ipc_call failed");
140                 pims_ipc_data_destroy(indata);
141                 return CONTACTS_ERROR_IPC;
142         }
143
144         pims_ipc_data_destroy(indata);
145
146         if (outdata) {
147                 unsigned int size = 0;
148                 ret = *(int*) pims_ipc_data_get(outdata, &size);
149
150                 if (CONTACTS_ERROR_NONE == ret) {
151                         int transaction_ver = 0;
152                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
153                         ctsvc_client_ipc_set_change_version(transaction_ver);
154                 }
155
156                 pims_ipc_data_destroy(outdata);
157         }
158
159         return ret;
160 }
161