• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SECURITY_GUARD_DATABASE_HELPER_H
17 #define SECURITY_GUARD_DATABASE_HELPER_H
18 
19 #include "database.h"
20 #include "i_model_info.h"
21 
22 namespace OHOS::Security::SecurityGuard {
23 class DatabaseHelper : public Database {
24 public:
25     explicit DatabaseHelper(std::string dbTable);
26     ~DatabaseHelper() override = default;
27     virtual int Init();
28     virtual void Release();
29     virtual int InsertEvent(const SecEvent& event);
30     virtual int QueryAllEvent(std::vector<SecEvent> &events);
31     virtual int QueryRecentEventByEventId(int64_t eventId, SecEvent &event);
32     virtual int QueryRecentEventByEventId(const std::vector<int64_t> &eventId, std::vector<SecEvent> &event);
33     virtual int QueryEventByEventId(int64_t eventId, std::vector<SecEvent> &events);
34     virtual int QueryEventByEventId(std::vector<int64_t> &eventIds, std::vector<SecEvent> &events);
35     virtual int QueryEventByEventIdAndDate(std::vector<int64_t> &eventIds, std::vector<SecEvent> &events,
36         std::string beginTime, std::string endTime);
37     virtual int QueryEventByEventType(int32_t eventType, std::vector<SecEvent> &events);
38     virtual int QueryEventByLevel(int32_t level, std::vector<SecEvent> &events);
39     virtual int QueryEventByOwner(std::string owner, std::vector<SecEvent> &events);
40     virtual int64_t CountAllEvent();
41     virtual int64_t CountEventByEventId(int64_t eventId);
42     virtual int DeleteOldEventByEventId(int64_t eventId, int64_t count);
43     virtual int DeleteAllEventByEventId(int64_t eventId);
44     virtual int FlushAllEvent();
45 
46 protected:
47     int QueryEventBase(const GenericValues &conditions, std::vector<SecEvent> &events,
48         const QueryOptions &options = {});
49     std::string CreateTable();
50     void SetValuesBucket(const SecEvent &event, GenericValues &values);
51     std::string Join(const std::vector<int64_t> &vec, const std::string delimiter);
52     std::string Join(const std::vector<std::string> &vec, const std::string delimiter);
53     std::string FilterSpecialChars(const std::string &input);
54     std::string dbPath_{};
55     std::string dbTable_{};
56 };
57 } // namespace OHOS::Security::SecurityGuard
58 #endif // SECURITY_GUARD_DATABASE_HELPER_H