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.WriteUint32(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 return true;
30 }
31
Unmarshalling(MessageParcel & parcel,DomainFilterRuleParcel & domainFilterRuleParcel)32 bool DomainFilterRuleParcel::Unmarshalling(MessageParcel& parcel, DomainFilterRuleParcel& domainFilterRuleParcel)
33 {
34 IPTABLES::Action action = IPTABLES::Action::INVALID;
35 IptablesUtils::ProcessFirewallAction(parcel.ReadInt32(), action);
36 std::string appUid = parcel.ReadString();
37 std::string domainName = parcel.ReadString();
38 domainFilterRuleParcel.rule_ = {action, appUid, domainName};
39 return true;
40 }
41
GetRule() const42 DomainFilterRule DomainFilterRuleParcel::GetRule() const
43 {
44 return rule_;
45 }
46 } // namespace IPTABLES
47 } // namespace EDM
48 } // namespace OHOS