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 #include "domain_filter_rule.h"
17
18 namespace OHOS {
19 namespace EDM {
20 namespace IPTABLES {
21
DomainFilterRuleParcel(DomainFilterRule rule)22 DomainFilterRuleParcel::DomainFilterRuleParcel(DomainFilterRule rule) : rule_(std::move(rule)) {}
23
Marshalling(MessageParcel & parcel) const24 bool DomainFilterRuleParcel::Marshalling(MessageParcel& parcel) const
25 {
26 parcel.WriteInt32(static_cast<int32_t>(std::get<DOMAIN_ACTION_IND>(rule_)));
27 parcel.WriteString(std::get<DOMAIN_APPUID_IND>(rule_));
28 parcel.WriteString(std::get<DOMAIN_DOMAINNAME_IND>(rule_));
29 parcel.WriteInt32(static_cast<int32_t>(std::get<DOMAIN_DIRECTION_IND>(rule_)));
30 return true;
31 }
32
Unmarshalling(MessageParcel & parcel,DomainFilterRuleParcel & domainFilterRuleParcel)33 bool DomainFilterRuleParcel::Unmarshalling(MessageParcel& parcel, DomainFilterRuleParcel& domainFilterRuleParcel)
34 {
35 IPTABLES::Action action = IPTABLES::Action::INVALID;
36 IPTABLES::Direction direction = IPTABLES::Direction::INVALID;
37 IptablesUtils::ProcessFirewallAction(parcel.ReadInt32(), action);
38 std::string appUid = parcel.ReadString();
39 std::string domainName = parcel.ReadString();
40 IptablesUtils::ProcessFirewallDirection(parcel.ReadInt32(), direction);
41 domainFilterRuleParcel.rule_ = {action, appUid, domainName, direction};
42 return true;
43 }
44
GetRule() const45 DomainFilterRule DomainFilterRuleParcel::GetRule() const
46 {
47 return rule_;
48 }
49 } // namespace IPTABLES
50 } // namespace EDM
51 } // namespace OHOS