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 NET_FIREWALL_STUB_H
17 #define NET_FIREWALL_STUB_H
18 
19 #include <map>
20 
21 #include "i_netfirewall_service.h"
22 #include "iremote_stub.h"
23 #include "net_manager_constants.h"
24 #include "netmanager_ext_log.h"
25 #include "refbase.h"
26 
27 namespace OHOS {
28 namespace NetManagerStandard {
29 class NetFirewallStub : public IRemoteStub<INetFirewallService> {
30     using NetFirewallServiceFunc = int32_t (NetFirewallStub::*)(MessageParcel &, MessageParcel &);
31     struct ServicePermissionAndFunc {
32         std::string strPermission;
33         NetFirewallServiceFunc serviceFunc;
34     };
35 
36 public:
37     NetFirewallStub();
38 
39     ~NetFirewallStub() = default;
40 
41     int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
42 
43 private:
44     int32_t OnSetNetFirewallPolicy(MessageParcel &data, MessageParcel &reply);
45 
46     int32_t OnGetNetFirewallPolicy(MessageParcel &data, MessageParcel &reply);
47 
48     int32_t OnAddNetFirewallRule(MessageParcel &data, MessageParcel &reply);
49 
50     int32_t OnUpdateNetFirewallRule(MessageParcel &data, MessageParcel &reply);
51 
52     int32_t OnDeleteNetFirewallRule(MessageParcel &data, MessageParcel &reply);
53 
54     int32_t OnGetNetFirewallRules(MessageParcel &data, MessageParcel &reply);
55 
56     int32_t OnGetNetFirewallRule(MessageParcel &data, MessageParcel &reply);
57 
58     int32_t OnGetInterceptRecords(MessageParcel &data, MessageParcel &reply);
59 
60     int32_t CheckFirewallPermission(std::string &strPermission);
61 
62 private:
63     std::map<uint32_t, ServicePermissionAndFunc> memberFuncMap_;
64 };
65 } // namespace NetManagerStandard
66 } // namespace OHOS
67 #endif /* NET_FIREWALL_STUB_H */
68