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 #include "skill_uri.h"
16 #include "parcel.h"
17 #include "app_domain_verify_parcel_util.h"
18 
19 namespace OHOS {
20 namespace AppDomainVerify {
21 
Marshalling(Parcel & parcel) const22 bool SkillUri::Marshalling(Parcel &parcel) const
23 {
24     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, scheme);
25     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, host);
26     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, port);
27     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, path);
28     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, pathStartWith);
29     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, pathRegex);
30     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, type);
31     return true;
32 }
ReadFromParcel(Parcel & parcel)33 bool SkillUri::ReadFromParcel(Parcel &parcel)
34 {
35     if (parcel.ReadString(scheme) && parcel.ReadString(host)) {
36         // todo 判断host是否要string16
37         port = parcel.ReadString();
38         path = parcel.ReadString();
39         pathStartWith = parcel.ReadString();
40         pathRegex = parcel.ReadString();
41         type = parcel.ReadString();
42         return true;
43     }
44     return false;
45 }
46 
Unmarshalling(Parcel & parcel)47 SkillUri *SkillUri::Unmarshalling(Parcel &parcel)
48 {
49     SkillUri *skillUri = new (std::nothrow) SkillUri();
50     if (skillUri && !skillUri->ReadFromParcel(parcel)) {
51         APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "read from parcel failed");
52         delete skillUri;
53         skillUri = nullptr;
54     }
55     return skillUri;
56 }
57 }  // namespace AppDomainVerify
58 }  // namespace OHOS