• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef REQUEST_GET_PROXY_H
17 #define REQUEST_GET_PROXY_H
18 
19 #include <string>
20 
21 #include "c_string_wrapper.h"
22 #include "common_event_manager.h"
23 #include "common_event_subscriber.h"
24 #include "common_event_support.h"
25 #include "log.h"
26 #include "matching_skills.h"
27 #include "want.h"
28 
29 class SysNetProxySubscriber : public OHOS::EventFwk::CommonEventSubscriber {
30 public:
SysNetProxySubscriber(OHOS::EventFwk::CommonEventSubscribeInfo & subscriberInfo)31     SysNetProxySubscriber(OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo)
32         : CommonEventSubscriber(subscriberInfo)
33     {
34     }
35     ~SysNetProxySubscriber() = default;
36     void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override;
37 };
38 
39 class SysNetProxyManager {
40 public:
41     static SysNetProxyManager &GetInstance();
42     void SubscriberEvent();
43     CStringWrapper GetHost();
44     CStringWrapper GetPort();
45     CStringWrapper GetExclusionList();
46 
47     void GetHttpProxy(const std::string proxyContent, std::string &host, std::string &port, std::string &exclusionList);
48     void InitProxy(std::string &host, std::string &port, std::string &exclusion);
SetHttpProxy(std::string host,std::string port,std::string list)49     void SetHttpProxy(std::string host, std::string port, std::string list)
50     {
51         REQUEST_HILOGD("SysNetProxyManager SetHttpProxy host is %{public}s", host.c_str());
52         REQUEST_HILOGD("SysNetProxyManager SetHttpProxy port is %{public}s", port.c_str());
53         REQUEST_HILOGD("SysNetProxyManager SetHttpProxy list is %{public}s", list.c_str());
54 
55         host_ = host;
56         port_ = port;
57         exclusionList_ = list;
58     }
59 
60 private:
61     static std::shared_ptr<SysNetProxySubscriber> subscriber_;
62     std::string host_;
63     std::string port_;
64     std::string exclusionList_;
65     std::mutex proxyMutex;
66 };
67 std::shared_ptr<SysNetProxySubscriber> SysNetProxyManager::subscriber_ = nullptr;
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
73 void RegisterProxySubscriber();
74 CStringWrapper GetHost();
75 CStringWrapper GetPort();
76 CStringWrapper GetExclusionList();
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif // REQUEST_GET_PROXY_H
83