Add Privacy-Guard
[platform/core/security/privacy-guard.git] / server / inc / PrivacyGuardDb.h
1 /*
2  * Copyright (c) 2013 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 #ifndef _PRIVACYGUARDDB_H_
18 #define _PRIVACYGUARDDB_H_
19
20 #include <string>
21 #include <memory>
22 #include <list>
23 #include <mutex>
24 #include "ICommonDb.h"
25 #include "privacy_guard_client_types.h"
26 #include "PrivacyGuardTypes.h"
27
28 #ifdef __FILTER_LISTED_PKG
29 #include <map>
30 #endif
31
32 class PrivacyGuardDb : public ICommonDb
33 {
34 private:
35         static std::mutex m_singletonMutex;
36         static PrivacyGuardDb* m_pInstance;
37 #ifdef __FILTER_LISTED_PKG
38     const static std::string PRIVACY_FILTER_LIST_FILE;
39     const static std::string FILTER_KEY;
40     static std::map < std::string, bool > m_filteredPkgList;
41 #endif
42
43 private:
44         void createDB(void);
45
46         PrivacyGuardDb(void);
47
48         ~PrivacyGuardDb(void);
49
50 public:
51         static PrivacyGuardDb* getInstance(void);
52
53         virtual void openSqliteDB(void);
54
55         int PgAddPrivacyAccessLog(const int userId, std::list < std::pair < std::string, std::string > > logInfoList);
56
57         int PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privilege, const timespec *timestamp);
58
59         int PgAddPrivacyAccessLogTest(const int userId, const std::string packageId, const std::string privacyId);
60
61         int PgAddMonitorPolicy(const int userId, const std::string packageId, const std::list < std::string > privacyList, bool monitorPolicy);
62
63         int PgCheckPrivacyPackage(const int userId, const std::string packageId, bool &isPrivacyPackage);
64
65         int PgDeleteAllLogsAndMonitorPolicy(void);
66
67         int PgDeleteLogsByPackageId(const std::string packageId);
68
69         int PgDeleteMonitorPolicyByPackageId(const std::string packageId);
70
71         int PgForeachTotalPrivacyCountOfPackage(const int userId, const int startDate, const int endDate,
72                                 std::list < std::pair < std::string, int > >& packageInfoList);
73
74         int PgForeachTotalPrivacyCountOfPrivacy(const int userId, const int startDate, const int endDate,
75                                 std::list < std::pair < std::string, int > >& privacyInfoList);
76
77         int PgForeachPrivacyCountByPrivacyId(const int userId, const int startDate, const int endDate,
78                                 const std::string privacyId, std::list < std::pair < std::string, int > >& packageInfoList);
79
80         int PgForeachPrivacyCountByPackageId(const int userId, const int startDate, const int endDate,
81                                 const std::string packageId, std::list < std::pair < std::string, int > >& privacyInfoList);
82
83         int PgGetMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, int& monitorPolicy);
84
85         int PgGetAllMonitorPolicy(std::list < std::pair < std::string, int > >& monitorPolicyList);
86
87         int PgForeachMonitorPolicyByPackageId(const int userId, const std::string packageId, std::list <privacy_data_s>& privacyInfoList);
88
89         int PgForeachPrivacyPackageId(const int userId, std::list < std::string > & packageList);
90
91         int PgForeachPackageByPrivacyId(const int userId, const std::string privacyId, std::list < std::string > &packageList);
92
93         int PgUpdateMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, const int monitorPolicy);
94
95         int PgAddMainMonitorPolicy(const int userId);
96
97         int PgUpdateMainMonitorPolicy(const int userId, const bool mainMonitorPolicy);
98
99         int PgGetMainMonitorPolicy(const int userId, bool &mainMonitorPolicy);
100
101         int PgDeleteMainMonitorPolicyByUserId(const int userId);
102 };
103
104
105 #endif // _PRIVACYGUARDDB_H_