1 /* 2 * Copyright (c) 2021 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 "static_configuration.h" 17 #include "netmgr_ext_log_wrapper.h" 18 19 namespace OHOS { 20 namespace NetManagerStandard { Marshalling(Parcel & parcel) const21bool StaticConfiguration::Marshalling(Parcel &parcel) const 22 { 23 if (!ipAddr_.Marshalling(parcel)) { 24 NETMGR_EXT_LOG_E("write ipAddr_ to parcel failed"); 25 return false; 26 } 27 if (!route_.Marshalling(parcel)) { 28 NETMGR_EXT_LOG_E("write route_ to parcel failed"); 29 return false; 30 } 31 if (!gateway_.Marshalling(parcel)) { 32 NETMGR_EXT_LOG_E("write gateway_ to parcel failed"); 33 return false; 34 } 35 if (!netMask_.Marshalling(parcel)) { 36 NETMGR_EXT_LOG_E("write netMask_ to parcel failed"); 37 return false; 38 } 39 if (!parcel.WriteUint32(dnsServers_.size())) { 40 NETMGR_EXT_LOG_E("write dnsServers_ size to parcel failed"); 41 return false; 42 } 43 for (auto it = dnsServers_.begin(); it != dnsServers_.end(); ++it) { 44 if (!it->Marshalling(parcel)) { 45 NETMGR_EXT_LOG_E("write dnsServers_ to parcel failed"); 46 return false; 47 } 48 } 49 if (!parcel.WriteString(domain_)) { 50 NETMGR_EXT_LOG_E("write domain_ to parcel failed"); 51 return false; 52 } 53 return true; 54 } 55 Unmarshalling(Parcel & parcel)56sptr<StaticConfiguration> StaticConfiguration::Unmarshalling(Parcel &parcel) 57 { 58 sptr<StaticConfiguration> ptr = (std::make_unique<StaticConfiguration>()).release(); 59 if (ptr == nullptr) { 60 return nullptr; 61 } 62 sptr<INetAddr> ipAddr = INetAddr::Unmarshalling(parcel); 63 if (ipAddr == nullptr) { 64 NETMGR_EXT_LOG_E("ipAddr_ is null"); 65 return nullptr; 66 } 67 ptr->ipAddr_ = *ipAddr; 68 sptr<INetAddr> route = INetAddr::Unmarshalling(parcel); 69 if (route == nullptr) { 70 NETMGR_EXT_LOG_E("route_ is null"); 71 return nullptr; 72 } 73 ptr->route_ = *route; 74 sptr<INetAddr> gateway = INetAddr::Unmarshalling(parcel); 75 if (gateway == nullptr) { 76 NETMGR_EXT_LOG_E("gateway_ is null"); 77 return nullptr; 78 } 79 ptr->gateway_ = *gateway; 80 sptr<INetAddr> netMask = INetAddr::Unmarshalling(parcel); 81 if (netMask == nullptr) { 82 NETMGR_EXT_LOG_E("netMask_ is null"); 83 return nullptr; 84 } 85 ptr->netMask_ = *netMask; 86 uint32_t size = 0; 87 if (!parcel.ReadUint32(size)) { 88 return nullptr; 89 } 90 for (uint32_t i = 0; i < size; i++) { 91 sptr<INetAddr> netAddr = INetAddr::Unmarshalling(parcel); 92 if (netAddr == nullptr) { 93 NETMGR_EXT_LOG_E("netAddr is null"); 94 return nullptr; 95 } 96 ptr->dnsServers_.push_back(*netAddr); 97 } 98 if (!parcel.ReadString(ptr->domain_)) { 99 return nullptr; 100 } 101 return ptr; 102 } 103 } // namespace NetManagerStandard 104 } // namespace OHOS