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 "api_policy_adapter.h"
17
ApiPolicyAdapter()18 ApiPolicyAdapter::ApiPolicyAdapter()
19 {
20 #ifndef __WIN32
21 handle = dlopen("/system/lib64/platformsdk/libapipolicy_client.z.so", RTLD_NOW);
22 if (!handle) {
23 return;
24 }
25 func = reinterpret_cast<CheckUrlFunc>(dlsym(handle, "CheckUrl"));
26 #endif
27 }
28
~ApiPolicyAdapter()29 ApiPolicyAdapter::~ApiPolicyAdapter()
30 {
31 #ifndef __WIN32
32 if (handle) {
33 dlclose(handle);
34 handle = nullptr;
35 }
36 #endif
37 }
38
CheckUrl(const std::string & bundleName,const std::string & domainType,const std::string & url)39 int32_t ApiPolicyAdapter::CheckUrl(const std::string& bundleName, const std::string& domainType, const std::string& url)
40 {
41 int32_t res = 0;
42 if (func == nullptr) {
43 return res;
44 }
45 res = func(bundleName, domainType, url);
46 return res;
47 }
48