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 #include "openvpn_config.h"
17 #include "netmgr_ext_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace NetManagerStandard {
Marshalling(Parcel &parcel) const21 bool OpenvpnConfig::Marshalling(Parcel &parcel) const
22 {
23     if (!SysVpnConfig::Marshalling(parcel)) {
24         NETMGR_EXT_LOG_E("OpenvpnConfig Marshalling failed");
25         return false;
26     }
27     if (!parcel.WriteString(ovpnPort_)) {
28         return false;
29     }
30 
31     if (!parcel.WriteInt32(ovpnProtocol_)) {
32         return false;
33     }
34 
35     if (!parcel.WriteString(ovpnConfig_)) {
36         return false;
37     }
38 
39     if (!parcel.WriteInt32(ovpnAuthType_)) {
40         return false;
41     }
42 
43     if (!parcel.WriteString(askpass_)) {
44         return false;
45     }
46 
47     if (!parcel.WriteString(ovpnConfigFilePath_)) {
48         return false;
49     }
50 
51     if (!parcel.WriteString(ovpnCaCertFilePath_)) {
52         return false;
53     }
54 
55     if (!parcel.WriteString(ovpnUserCertFilePath_)) {
56         return false;
57     }
58 
59     if (!parcel.WriteString(ovpnPrivateKeyFilePath_)) {
60         return false;
61     }
62 
63     return true;
64 }
65 
Unmarshalling(Parcel &parcel)66 sptr<OpenvpnConfig> OpenvpnConfig::Unmarshalling(Parcel &parcel)
67 {
68     sptr<OpenvpnConfig> ptr = new (std::nothrow) OpenvpnConfig();
69     if (ptr == nullptr) {
70         NETMGR_EXT_LOG_E("OpenvpnConfig ptr is null");
71         return nullptr;
72     }
73     if (!SysVpnConfig::Unmarshalling(parcel, ptr)) {
74         NETMGR_EXT_LOG_E("OpenvpnConfig Unmarshalling failed");
75         return nullptr;
76     }
77     if (!parcel.ReadString(ptr->ovpnPort_)) {
78         return nullptr;
79     }
80 
81     if (!parcel.ReadInt32(ptr->ovpnProtocol_)) {
82         return nullptr;
83     }
84 
85     if (!parcel.ReadString(ptr->ovpnConfig_)) {
86         return nullptr;
87     }
88 
89     if (!parcel.ReadInt32(ptr->ovpnAuthType_)) {
90         return nullptr;
91     }
92 
93     if (!parcel.ReadString(ptr->askpass_)) {
94         return nullptr;
95     }
96 
97     if (!parcel.ReadString(ptr->ovpnConfigFilePath_)) {
98         return nullptr;
99     }
100 
101     if (!parcel.ReadString(ptr->ovpnCaCertFilePath_)) {
102         return nullptr;
103     }
104 
105     if (!parcel.ReadString(ptr->ovpnUserCertFilePath_)) {
106         return nullptr;
107     }
108 
109     if (!parcel.ReadString(ptr->ovpnPrivateKeyFilePath_)) {
110         return nullptr;
111     }
112     return ptr;
113 }
114 } // namespace NetManagerStandard
115 } // namespace OHOS