1 /*
2  * Copyright (c) 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 SERVICES_EDM_PLUGIN_INCLUDE_IPTABLES_CHAIN_RULE_H
17 #define SERVICES_EDM_PLUGIN_INCLUDE_IPTABLES_CHAIN_RULE_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "edm_errors.h"
23 
24 namespace OHOS {
25 namespace EDM {
26 namespace IPTABLES {
27 
28 class ChainRule {
29 public:
30     explicit ChainRule(const std::string &rule);
31 
32     virtual uint32_t RuleNum();
33     [[nodiscard]] virtual std::string Parameter() const = 0;
34     virtual std::string Target();
35 
36 protected:
37     ChainRule() = default;
38 
39     void GetOption(const std::string &options, const std::string &key, std::string &value);
40     void GetOption(const std::string &options, const std::string &key, uint32_t &value);
41 
42 private:
43     void TruncateOption(const std::string &options, const std::string &key, std::string &result);
44 
45 protected:
46     uint32_t ruleNo_ = 0;
47 
48     std::string target_;
49     std::string prot_;
50 
51     std::string srcAddr_;
52     std::string destAddr_;
53 
54     std::string otherOptions_;
55 };
56 } // namespace IPTABLES
57 } // namespace EDM
58 } // namespace OHOS
59 #endif // SERVICES_EDM_PLUGIN_INCLUDE_IPTABLES_CHAIN_RULE_H
60