• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 COMMUNICATIONNETMANAGERBASE_CONNECTION_EXEC_H
17 #define COMMUNICATIONNETMANAGERBASE_CONNECTION_EXEC_H
18 
19 #include <netdb.h>
20 
21 #include "bindsocket_context.h"
22 #include "getaddressbyname_context.h"
23 #include "getappnet_context.h"
24 #include "getdefaultnet_context.h"
25 #include "gethttpproxy_context.h"
26 #include "napi/native_api.h"
27 #include "none_params_context.h"
28 #include "parse_nethandle_context.h"
29 #include "register_context.h"
30 #include "setappnet_context.h"
31 #include "setglobalhttpproxy_context.h"
32 #include "setcustomdnsrule_context.h"
33 #include "deletecustomdnsrule_context.h"
34 #include "deletecustomdnsrules_context.h"
35 #include "factoryresetnetwork_context.h"
36 #include "setapphttpproxy_context.h"
37 #include "pacurl_context.h"
38 #include "setinterfaceup_context.h"
39 #include "setinterfaceipaddr_context.h"
40 #include "addnetworkroute_context.h"
41 #include "interfaceregister_context.h"
42 #include "getinterfaceconfig_context.h"
43 #include "registernetsupplier_context.h"
44 #include "unregisternetsupplier_context.h"
45 
46 namespace OHOS::NetManagerStandard {
47 static constexpr size_t MAX_ARRAY_LENGTH = 64;
48 static constexpr size_t MAX_IPV4_STR_LEN = 16;
49 static constexpr size_t MAX_IPV6_STR_LEN = 64;
50 class ConnectionExec final {
51 public:
52     ConnectionExec() = delete;
53 
54     ~ConnectionExec() = delete;
55 
56     static napi_value CreateNetHandle(napi_env env, NetHandle *handle);
57 
58     static napi_value CreateNetCapabilities(napi_env env, NetAllCapabilities *capabilities);
59 
60     static napi_value CreateConnectionProperties(napi_env env, NetLinkInfo *linkInfo);
61 
62     static bool ExecGetDefaultNet(GetDefaultNetContext *context);
63 
64     static napi_value GetDefaultNetCallback(GetDefaultNetContext *context);
65 
66     static bool ExecHasDefaultNet(HasDefaultNetContext *context);
67 
68     static napi_value HasDefaultNetCallback(HasDefaultNetContext *context);
69 
70     static bool ExecIsDefaultNetMetered(IsDefaultNetMeteredContext *context);
71 
72     static napi_value IsDefaultNetMeteredCallback(IsDefaultNetMeteredContext *context);
73 
74     static bool ExecGetNetCapabilities(GetNetCapabilitiesContext *context);
75 
76     static napi_value GetNetCapabilitiesCallback(GetNetCapabilitiesContext *context);
77 
78     static bool ExecGetConnectionProperties(GetConnectionPropertiesContext *context);
79 
80     static napi_value GetConnectionPropertiesCallback(GetConnectionPropertiesContext *context);
81 
82     static bool ExecGetAddressByName(GetAddressByNameContext *context);
83 
84     static napi_value GetAddressByNameCallback(GetAddressByNameContext *context);
85 
86     static bool ExecGetAllNets(GetAllNetsContext *context);
87 
88     static napi_value GetAllNetsCallback(GetAllNetsContext *context);
89 
90     static bool ExecEnableAirplaneMode(EnableAirplaneModeContext *context);
91 
92     static napi_value EnableAirplaneModeCallback(EnableAirplaneModeContext *context);
93 
94     static bool ExecDisableAirplaneMode(DisableAirplaneModeContext *context);
95 
96     static napi_value DisableAirplaneModeCallback(DisableAirplaneModeContext *context);
97 
98     static bool ExecReportNetConnected(ReportNetConnectedContext *context);
99 
100     static napi_value ReportNetConnectedCallback(ReportNetConnectedContext *context);
101 
102     static bool ExecReportNetDisconnected(ReportNetDisconnectedContext *context);
103 
104     static napi_value ReportNetDisconnectedCallback(ReportNetDisconnectedContext *context);
105 
106     static bool ExecGetDefaultHttpProxy(GetHttpProxyContext *context);
107 
108     static napi_value GetDefaultHttpProxyCallback(GetHttpProxyContext *context);
109 
110     static bool ExecGetGlobalHttpProxy(GetHttpProxyContext *context);
111 
112     static napi_value GetGlobalHttpProxyCallback(GetHttpProxyContext *context);
113 
114     static bool ExecSetGlobalHttpProxy(SetGlobalHttpProxyContext *context);
115 
116     static napi_value SetGlobalHttpProxyCallback(SetGlobalHttpProxyContext *context);
117 
118     static bool ExecSetAppHttpProxy(SetAppHttpProxyContext *context);
119 
120     static napi_value SetAppHttpProxyCallback(SetAppHttpProxyContext *context);
121 
122     static bool ExecGetAppNet(GetAppNetContext *context);
123 
124     static napi_value GetAppNetCallback(GetAppNetContext *context);
125 
126     static bool ExecSetAppNet(SetAppNetContext *context);
127 
128     static napi_value SetAppNetCallback(SetAppNetContext *context);
129 
130     static bool ExecSetInterfaceUp(SetInterfaceUpContext *context);
131 
132     static napi_value SetInterfaceUpCallback(SetInterfaceUpContext *context);
133 
134     static bool ExecSetInterfaceIpAddr(SetInterfaceIpAddrContext *context);
135 
136     static napi_value SetInterfaceIpAddrCallback(SetInterfaceIpAddrContext *context);
137 
138     static bool ExecAddNetworkRoute(AddNetworkRouteContext *context);
139 
140     static napi_value AddNetworkRouteCallback(AddNetworkRouteContext *context);
141 
142     static bool ExecGetNetInterfaceConfiguration(GetNetInterfaceConfigurationContext *context);
143 
144     static napi_value GetNetInterfaceConfigurationCallback(GetNetInterfaceConfigurationContext *context);
145 
146     static bool ExecRegisterNetSupplier(RegisterNetSupplierContext *context);
147 
148     static napi_value RegisterNetSupplierCallback(RegisterNetSupplierContext *context);
149 
150     static bool ExecUnregisterNetSupplier(UnregisterNetSupplierContext *context);
151 
152     static napi_value UnregisterNetSupplierCallback(UnregisterNetSupplierContext *context);
153 
154     static bool ExecSetCustomDNSRule(SetCustomDNSRuleContext *context);
155 
156     static napi_value SetCustomDNSRuleCallback(SetCustomDNSRuleContext *context);
157 
158     static bool ExecDeleteCustomDNSRule(DeleteCustomDNSRuleContext *context);
159 
160     static napi_value DeleteCustomDNSRuleCallback(DeleteCustomDNSRuleContext *context);
161 
162     static bool ExecDeleteCustomDNSRules(DeleteCustomDNSRulesContext *context);
163 
164     static napi_value DeleteCustomDNSRulesCallback(DeleteCustomDNSRulesContext *context);
165 
166     static bool ExecFactoryResetNetwork(FactoryResetNetworkContext *context);
167 
168     static napi_value FactoryResetNetworkCallback(FactoryResetNetworkContext *context);
169 
170     static bool ExecSetPacUrl(SetPacUrlContext *context);
171 
172     static napi_value SetPacUrlCallback(SetPacUrlContext *context);
173 
174     static bool ExecGetPacUrl(GetPacUrlContext *context);
175 
176     static napi_value GetPacUrlCallback(GetPacUrlContext *context);
177 
178     class NetHandleExec final {
179     public:
180         NetHandleExec() = delete;
181 
182         ~NetHandleExec() = delete;
183 
184         static bool ExecGetAddressByName(GetAddressByNameContext *context);
185 
186         static napi_value GetAddressByNameCallback(GetAddressByNameContext *context);
187 
188         static bool ExecGetAddressesByName(GetAddressByNameContext *context);
189 
190         static napi_value GetAddressesByNameCallback(GetAddressByNameContext *context);
191 
192         static bool ExecBindSocket(BindSocketContext *context);
193 
194         static napi_value BindSocketCallback(BindSocketContext *context);
195 
196     private:
197         static napi_value MakeNetAddressJsValue(napi_env env, const NetAddress &address);
198 
199         static void SetAddressInfo(const char *host, addrinfo *info, NetAddress &address);
200     };
201 
202     class NetConnectionExec final {
203     public:
204         NetConnectionExec() = delete;
205 
206         ~NetConnectionExec() = delete;
207 
208         static bool ExecRegister(RegisterContext *context);
209 
210         static napi_value RegisterCallback(RegisterContext *context);
211 
212         static bool ExecUnregister(UnregisterContext *context);
213 
214         static napi_value UnregisterCallback(UnregisterContext *context);
215     };
216 
217     class NetInterfaceExec final {
218     public:
219         NetInterfaceExec() = delete;
220 
221         ~NetInterfaceExec() = delete;
222 
223         static bool ExecIfaceRegister(IfaceRegisterContext *context);
224 
225         static napi_value IfaceRegisterCallback(IfaceRegisterContext *context);
226 
227         static bool ExecIfaceUnregister(IfaceUnregisterContext *context);
228 
229         static napi_value IfaceUnregisterCallback(IfaceUnregisterContext *context);
230     };
231 
232 private:
233     static void FillLinkAddress(napi_env env, napi_value connectionProperties, NetLinkInfo *linkInfo);
234 
235     static void FillRouoteList(napi_env env, napi_value connectionProperties, NetLinkInfo *linkInfo);
236 
237     static void FillDns(napi_env env, napi_value connectionProperties, NetLinkInfo *linkInfo);
238 };
239 } // namespace OHOS::NetManagerStandard
240 
241 #endif /* COMMUNICATIONNETMANAGERBASE_CONNECTION_EXEC_H */
242