• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef JERRY_NET_PAC_MANAGER_H
17 #define JERRY_NET_PAC_MANAGER_H
18 #ifdef NETMANAGER_ENABLE_PAC_PROXY
19 #include <string>
20 #include <memory>
21 #include "mutex"
22 namespace OHOS {
23 namespace NetManagerStandard {
24 enum PAC_STATUS {
25     /**
26      * 执行成功
27      */
28     PAC_OK,
29 
30     /**
31      * pac脚本格式有误
32      */
33     PAC_SCRIPT_DOWNLOAD_ERROR,
34 
35     /**
36      * pac加载执行错误
37      */
38     PAC_SCRIPT_RUN_ERROR,
39 
40     /**
41      * pac FindProxyForURL函数没有找到
42      */
43     PAC_SCRIPT_FUNCTION_ERROR,
44 
45     /**
46      *pac FindProxyForURL函数调用错误
47      */
48     PAC_SCRIPT_CALL_ERROR
49 };
50 
51 class NetPACManager {
52 public:
53     NetPACManager();
54 
55     ~NetPACManager();
56 
57     bool InitPACScriptWithURL(const std::string &scriptUrl);
58 
59     bool InitPACScript(const std::string &script);
60 
61     PAC_STATUS FindProxyForURL(const std::string &url, std::string &proxy);
62 
63     PAC_STATUS FindProxyForURL(const std::string &url, const std::string &host, std::string &proxy);
64 
65     void DownloadPACScript(const std::string &url);
66 
67     std::string ParseHost(const std::string &url);
68 
69     void SetFileUrl(const std::string &url);
70 
71 private:
72     uint32_t pacScriptVal_;
73     std::mutex pacMutex_;
74     std::string scriptFileUrl_;
75     bool status_;
76     bool engineInitialized_;
77 };
78 }  // namespace NetManagerStandard
79 }  // namespace OHOS
80 #endif
81 #endif  // JERRY_NET_PAC_MANAGER_H
82