• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 VPN_DATABASE_HELPER_H
17 #define VPN_DATABASE_HELPER_H
18 
19 #include <climits>
20 #include <functional>
21 #include <string>
22 
23 #include "ipsecvpn_config.h"
24 #include "l2tpvpn_config.h"
25 #include "rdb_common.h"
26 #include "rdb_errno.h"
27 #include "rdb_helper.h"
28 #include "rdb_open_callback.h"
29 #include "rdb_predicates.h"
30 #include "rdb_store.h"
31 #include "result_set.h"
32 #include "vpn_data_bean.h"
33 
34 namespace OHOS {
35 namespace NetManagerStandard {
36 class VpnDatabaseHelper {
37 public:
38     static VpnDatabaseHelper &GetInstance();
39     int32_t InsertOrUpdateData(const sptr<VpnDataBean> &vpnBean);
40     int32_t QueryVpnData(sptr<VpnDataBean> &vpnBean, const std::string &vpnUuid);
41     int32_t QueryAllData(std::vector<sptr<SysVpnConfig>> &infos, const int32_t userId);
42     int32_t DeleteVpnData(const std::string &vpnUuid);
43     bool IsVpnInfoExists(const std::string &vpnId);
44 
45 private:
46     VpnDatabaseHelper();
47     ~VpnDatabaseHelper() = default;
48     int32_t InsertData(const sptr<VpnDataBean> &vpnBean);
49     int32_t UpdateData(const sptr<VpnDataBean> &vpnBean);
50     int32_t EncryptData(const sptr<VpnDataBean> &vpnBean);
51     int32_t DecryptData(const sptr<VpnDataBean> &vpnBean);
52 
53     void GetVpnDataFromResultSet(const std::shared_ptr<OHOS::NativeRdb::ResultSet> &queryResultSet,
54         sptr<VpnDataBean> &vpnBean);
55     void BindVpnData(NativeRdb::ValuesBucket &values, const sptr<VpnDataBean> &info);
56     int32_t getVpnDataSize(const sptr<VpnDataBean> &vpnBean);
57     std::shared_ptr<OHOS::NativeRdb::RdbStore> store_ = nullptr;
58 };
59 
60 class VpnDataBaseCallBack : public OHOS::NativeRdb::RdbOpenCallback {
61 public:
62     int32_t OnCreate(OHOS::NativeRdb::RdbStore &rdbStore) override;
63     int32_t OnUpgrade(OHOS::NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override;
64     int32_t OnDowngrade(OHOS::NativeRdb::RdbStore &rdbStore, int32_t currentVersion, int32_t targetVersion) override;
65 };
66 } // namespace NetManagerStandard
67 } // namespace OHOS
68 
69 #endif // VPN_DATABASE_HELPER_H
70