1 /* 2 * Copyright (c) 2022-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 NETWORKSHARE_CONFIGURATION_H 17 #define NETWORKSHARE_CONFIGURATION_H 18 19 #include <fstream> 20 #include <map> 21 #include <vector> 22 23 #include "networkshare_configuration.h" 24 25 namespace OHOS { 26 namespace NetManagerStandard { 27 class NetworkShareConfiguration { 28 public: 29 NetworkShareConfiguration(); 30 ~NetworkShareConfiguration() = default; 31 32 /** 33 * is surpport share network 34 */ 35 bool IsNetworkSharingSupported() const; 36 37 /** 38 * is usb iface by regex 39 */ 40 bool IsUsbIface(const std::string &iface); 41 42 /** 43 * is wifi iface by regex 44 */ 45 bool IsWifiIface(const std::string &iface); 46 47 /** 48 * is bluetooth iface by regex 49 */ 50 bool IsBluetoothIface(const std::string &iface); 51 52 /** 53 * get usb iface regex 54 */ 55 const std::vector<std::string> &GetUsbIfaceRegexs(); 56 57 /** 58 * get wifi iface regex 59 */ 60 const std::vector<std::string> &GetWifiIfaceRegexs(); 61 62 /** 63 * get bluetooth iface regex 64 */ 65 const std::vector<std::string> &GetBluetoothIfaceRegexs(); 66 67 /** 68 * get wifi hotspot set dhcp flag 69 */ 70 bool GetWifiHotspotSetDhcpFlag() const; 71 72 /** 73 * get btpan default ipv4 address 74 */ 75 std::string &GetBtpanIpv4Addr(); 76 77 /** 78 * get wifi hotspot default ipv4 address 79 */ 80 std::string &GetWifiHotspotIpv4Addr(); 81 82 /** 83 * get usb rndis default ipv4 address 84 */ 85 std::string &GetUsbRndisIpv4Addr(); 86 87 /** 88 * get the default route suffix 89 */ 90 std::string &GetRouteSuffix(); 91 92 /** 93 * get the btpan dhcp server name 94 */ 95 std::string &GetBtpanDhcpServerName(); 96 97 /** 98 * get the wifi hotspot dhcp server name 99 */ 100 std::string &GetWifiHotspotDhcpServerName(); 101 102 /** 103 * get the usb rndis dhcp server name 104 */ 105 std::string &GetUsbRndisDhcpServerName(); 106 107 /** 108 * get the usb rndis iface name 109 */ 110 std::string &GetUsbRndisIfaceName(); 111 112 /** 113 * get default net mask 114 */ 115 std::string &GetDefaultMask(); 116 117 /** 118 * get dhcp endIP 119 */ 120 std::string &GetDhcpEndIP(); 121 122 private: 123 int32_t LoadConfigData(); 124 bool MatchesDownstreamRegexs(const std::string &, std::vector<std::string> ®exs); 125 std::vector<std::string> ReadConfigFile(); 126 void ParseLineData(std::string &strKey, std::string &strVal); 127 void ParseRegexsData(std::vector<std::string> ®exs, std::string &strVal); 128 129 private: 130 enum class Config_Value { 131 CONFIG_VALUE_SHARE_SUPPORT, 132 CONFIG_VALUE_USB_REGEXS, 133 CONFIG_VALUE_WIFI_REGEXS, 134 CONFIG_VALUE_BLUETOOTH_REGEXS, 135 CONFIG_VALUE_BT_PAN_ADDR, 136 CONFIG_VALUE_WIFI_HOTSPOT_ADDR, 137 CONFIG_VALUE_USB_RNDIS_ADDR, 138 CONFIG_VALUE_BT_PAN_DHCP_NAME, 139 CONFIG_VALUE_WIFI_DHCP_NAME, 140 CONFIG_VALUE_USB_DHCP_NAME, 141 CONFIG_VALUE_USB_IFACE_NAME, 142 CONFIG_VALUE_ROUTE_SUFFIX, 143 CONFIG_VALUE_DHCP_ENDIP, 144 CONFIG_VALUE_DEFAULT_MASK, 145 CONFIG_VALUE_WIFI_SET_DHCP, 146 }; 147 148 bool isWifiHotspotSetDhcp_ = false; 149 bool supported_ = false; 150 std::vector<std::string> usbRegexs_; 151 std::vector<std::string> wifiRegexs_; 152 std::vector<std::string> blueToothRegexs_; 153 std::string btPanIpv4Str_; 154 std::string wifiIpv4Str_; 155 std::string usbIpv4Str_; 156 std::string routeSuffix_; 157 std::string btPanDhcpServerName_; 158 std::string wifiDhcpServerName_; 159 std::string usbDhcpServerName_; 160 std::string usbIfaceName_; 161 std::string defaultMask_; 162 std::string dhcpEndIP_; 163 std::map<std::string, Config_Value> configMap_; 164 165 private: 166 void ParseConfigData(Config_Value cfgValue, std::string &strKey, std::string &strVal); 167 }; 168 } // namespace NetManagerStandard 169 } // namespace OHOS 170 #endif // NETWORKSHARE_CONFIGURATION_H 171