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