• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 NETMANAGER_BASE_HTTP_PROXY_H
17 #define NETMANAGER_BASE_HTTP_PROXY_H
18 
19 #include <string>
20 #include <list>
21 #include <optional>
22 
23 #include "parcel.h"
24 #include "securec.h"
25 #include "netmanager_secure_data.h"
26 
27 namespace OHOS {
28 namespace NetManagerStandard {
29 class NetConnService;
30 #define NET_SYMBOL_VISIBLE __attribute__ ((visibility("default")))
31 class NET_SYMBOL_VISIBLE HttpProxy final : public Parcelable {
32 public:
33     friend class NetConnService;
34     HttpProxy();
35     HttpProxy(std::string host, uint16_t port, const std::list<std::string> &exclusionList);
36 
37     [[nodiscard]] std::string GetHost() const;
38     [[nodiscard]] uint16_t GetPort() const;
39     [[nodiscard]] std::list<std::string> GetExclusionList() const;
40     [[nodiscard]] std::string ToString() const;
41     [[nodiscard]] SecureData GetUsername() const;
42     [[nodiscard]] SecureData GetPassword() const;
43     [[nodiscard]] int32_t GetUserId() const;
44     [[nodiscard]] static std::optional<HttpProxy> FromString(const std::string &str);
SetHost(std::string && host)45     void inline SetHost(std::string &&host)
46     {
47         host_ = host;
48     }
SetPort(uint16_t port)49     void inline SetPort(uint16_t port)
50     {
51         port_ = port;
52     }
SetExclusionList(const std::list<std::string> & list)53     void inline SetExclusionList(const std::list<std::string> &list)
54     {
55         exclusionList_ = list;
56     }
SetUserName(const SecureData & username)57     void inline SetUserName(const SecureData &username)
58     {
59         username_ = username;
60     }
SetPassword(const SecureData & password)61     void inline SetPassword(const SecureData &password)
62     {
63         password_ = password;
64     }
65 
SetUserId(int32_t userId)66     void inline SetUserId(int32_t userId)
67     {
68         userId_ = userId;
69     }
70 
71     bool operator==(const HttpProxy &httpProxy) const;
72     bool operator!=(const HttpProxy &httpProxy) const;
73     bool Marshalling(Parcel &parcel) const override;
74     static bool Unmarshalling(Parcel &parcel, HttpProxy &httpProxy);
75 
76 private:
77     std::string host_;
78     uint16_t port_;
79     SecureData username_;
80     SecureData password_;
81     std::list<std::string> exclusionList_;
82     int32_t userId_ = -1;
83 };
84 } // namespace NetManagerStandard
85 } // namespace OHOS
86 #endif /* NETMANAGER_BASE_HTTP_PROXY_H */
87