fix bug
[platform/core/security/privacy-guard.git] / server / src / service / PrivacyInfoService.cpp
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #include "PrivacyInfoService.h"
18 #include "PrivacyGuardDb.h"
19 #include "Utils.h"
20
21 void
22 PrivacyInfoService::PgAddPrivacyAccessLog(SocketConnection* pConnector)
23 {
24         int userId = 0;
25         std::string packageId;
26         std::string privacyId;
27         time_t accessTime = 0;
28
29         pConnector->read(&userId, &packageId, &privacyId, &accessTime);
30
31         int result = PrivacyGuardDb::getInstance()->PgAddPrivacyAccessLog(userId, packageId, privacyId, accessTime);
32
33         pConnector->write(result);
34 }
35
36 void
37 PrivacyInfoService::PgAddMonitorPolicy(SocketConnection* pConnector)
38 {
39         int userId = 0;
40         std::string pkgId;
41         std::list < std::string > list;
42         bool privacyPopupRequired = true;
43
44         pConnector->read(&userId, &pkgId, &list, &privacyPopupRequired);
45
46         int result = PrivacyGuardDb::getInstance()->PgAddMonitorPolicy(userId, pkgId, list, privacyPopupRequired);
47
48         pConnector->write(result);
49 }
50
51 /*void
52 PrivacyInfoService::PgDeleteAllLogsAndMonitorPolicy(SocketConnection* pConnector)
53 {
54         int result = PrivacyGuardDb::getInstance()->PgDeleteAllLogsAndMonitorPolicy();
55
56         pConnector->write(result);
57 }*/
58
59 void
60 PrivacyInfoService::PgDeleteAllLogs(SocketConnection* pConnector)
61 {
62         int result = PrivacyGuardDb::getInstance()->PgDeleteAllLogs();
63
64         pConnector->write(result);
65 }
66
67 void
68 PrivacyInfoService::PgDeleteLogsByPackageId(SocketConnection* pConnector)
69 {
70         std::string packageId;
71
72         pConnector->read(&packageId);
73
74         int result = PrivacyGuardDb::getInstance()->PgDeleteLogsByPackageId(packageId);
75
76         pConnector->write(result);
77 }
78
79 void
80 PrivacyInfoService::PgDeleteMonitorPolicyByPackageId(SocketConnection* pConnector)
81 {
82         std::string packageId;
83
84         pConnector->read(&packageId);
85
86         int result = PrivacyGuardDb::getInstance()->PgDeleteMonitorPolicyByPackageId(packageId);
87
88         pConnector->write(result);
89 }
90
91 void
92 PrivacyInfoService::PgForeachTotalPrivacyCountOfPackage(SocketConnection* pConnector)
93 {
94         int userId = 0;
95         int startDate = -1;
96         int endDate = -1;
97         std::list < std::pair < std::string, int > > packageInfoList;
98
99         pConnector->read(&userId, &startDate, &endDate);
100
101         int result = PrivacyGuardDb::getInstance()->PgForeachTotalPrivacyCountOfPackage(userId, startDate, endDate, packageInfoList);
102
103         pConnector->write(result);
104         pConnector->write(packageInfoList);
105 }
106
107 void
108 PrivacyInfoService::PgForeachTotalPrivacyCountOfPrivacy(SocketConnection* pConnector)
109 {
110         int userId = 0;
111         int startDate = -1;
112         int endDate = -1;
113         std::list < std::pair < std::string, int > > privacyInfoList;
114
115         pConnector->read(&userId, &startDate, &endDate);
116
117         int result = PrivacyGuardDb::getInstance()->PgForeachTotalPrivacyCountOfPrivacy(userId, startDate, endDate, privacyInfoList);
118
119         pConnector->write(result);
120         pConnector->write(privacyInfoList);
121 }
122
123 void
124 PrivacyInfoService::PgForeachPrivacyCountByPrivacyId(SocketConnection* pConnector)
125 {
126         int userId = 0;
127         int startDate = -1;
128         int endDate = -1;
129         std::string privacyId;
130         std::list < std::pair < std::string, int > > packageInfoList;
131
132         pConnector->read(&userId, &startDate, &endDate, &privacyId);
133
134         int result = PrivacyGuardDb::getInstance()->PgForeachPrivacyCountByPrivacyId(userId, startDate, endDate, privacyId, packageInfoList);
135
136         pConnector->write(result);
137         pConnector->write(packageInfoList);
138 }
139
140 void
141 PrivacyInfoService::PgForeachPrivacyCountByPackageId(SocketConnection* pConnector)
142 {
143         int userId = 0;
144         int startDate = -1;
145         int endDate = -1;
146         std::string packageId;
147         std::list < std::pair < std::string, int > > privacyInfoList;
148
149         pConnector->read(&userId, &startDate, &endDate, &packageId);
150
151         int result = PrivacyGuardDb::getInstance()->PgForeachPrivacyCountByPackageId(userId, startDate, endDate, packageId, privacyInfoList);
152
153         pConnector->write(result);
154         pConnector->write(privacyInfoList);
155 }
156
157 void
158 PrivacyInfoService::PgForeachPackageIdUsingPrivacy(SocketConnection* pConnector)
159 {
160         int userId = 0;
161         std::list < std::string > packageList;
162
163         pConnector->read(&userId);
164
165         int result = PrivacyGuardDb::getInstance()->PgForeachPackageIdUsingPrivacy(userId, packageList);
166
167         pConnector->write(result);
168         pConnector->write(packageList);
169 }
170
171 void
172 PrivacyInfoService::PgForeachMonitorPolicyByPackageId(SocketConnection* pConnector)
173 {
174         int userId = 0;
175         std::string packageId;
176         std::list <privacy_data_s> privacyInfoList;
177
178         pConnector->read(&userId, &packageId);
179
180         int result = PrivacyGuardDb::getInstance()->PgForeachMonitorPolicyByPackageId(userId, packageId, privacyInfoList);
181
182         pConnector->write(result);
183         pConnector->write(privacyInfoList);
184 }
185
186 void
187 PrivacyInfoService::PgGetMonitorPolicy(SocketConnection* pConnector)
188 {
189         int userId = 0;
190         std::string packageId;
191         std::string privacyId;
192         int monitorPolicy = 1;
193
194         pConnector->read(&userId, &packageId, &privacyId);
195
196         int result = PrivacyGuardDb::getInstance()->PgGetMonitorPolicy(userId, packageId, privacyId, monitorPolicy);
197
198         pConnector->write(result);
199         pConnector->write(monitorPolicy);
200 }
201
202 void
203 PrivacyInfoService::PgGetAllMonitorPolicy(SocketConnection* pConnector)
204 {
205         std::list < std::pair < std::string, int > > monitorPolicyList;
206
207         int result = PrivacyGuardDb::getInstance()->PgGetAllMonitorPolicy(monitorPolicyList);
208
209         pConnector->write(result);
210         pConnector->write(monitorPolicyList);
211 }
212
213 void
214 PrivacyInfoService::PgForeachPackageInfoByPrivacyId(SocketConnection* pConnector)
215 {
216         int userId = 0;
217         std::string privacyId;
218         std::list < package_data_s > packageInfoList;
219
220         pConnector->read(&userId, &privacyId);
221
222         int result = PrivacyGuardDb::getInstance()->PgForeachPackageInfoByPrivacyId(userId, privacyId, packageInfoList);
223
224         pConnector->write(result);
225         pConnector->write(packageInfoList);
226 }
227
228 void
229 PrivacyInfoService::PgCheckPrivacyPackage(SocketConnection* pConnector)
230 {
231         int userId = 0;
232         std::string packageId;
233         bool isPrivacyPackage = false;
234
235         pConnector->read(&userId, &packageId);
236
237         int result = PrivacyGuardDb::getInstance()->PgCheckPrivacyPackage(userId, packageId, isPrivacyPackage);
238
239         pConnector->write(result);
240         pConnector->write(isPrivacyPackage);
241 }
242
243 void
244 PrivacyInfoService::PgUpdateMonitorPolicy(SocketConnection* pConnector)
245 {
246         int userId = 0;
247         std::string packageId;
248         std::string privacyId;
249         int monitorPolicy = 1;
250
251         pConnector->read(&userId, &packageId, &privacyId, &monitorPolicy);
252
253         int result = PrivacyGuardDb::getInstance()->PgUpdateMonitorPolicy(userId, packageId, privacyId, monitorPolicy);
254
255         pConnector->write(result);
256 }
257
258 void
259 PrivacyInfoService::PgUpdateMainMonitorPolicy(SocketConnection* pConnector)
260 {
261         int userId = 0;
262         int mainMonitorPolicy = 0;
263
264         pConnector->read(&userId, &mainMonitorPolicy);
265
266         int result = PrivacyGuardDb::getInstance()->PgUpdateMainMonitorPolicy(userId, mainMonitorPolicy);
267
268         pConnector->write(result);
269 }
270
271 void
272 PrivacyInfoService::PgGetMainMonitorPolicy(SocketConnection* pConnector)
273 {
274         int userId = 0;
275         int mainMonitorPolicy = 0;
276
277         pConnector->read(&userId);
278
279         int result = PrivacyGuardDb::getInstance()->PgGetMainMonitorPolicy(userId, mainMonitorPolicy);
280
281         pConnector->write(result);
282         pConnector->write(mainMonitorPolicy);
283 }