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]] static std::optional<HttpProxy> FromString(const std::string &str); SetHost(std::string && host)44 void inline SetHost(std::string &&host) 45 { 46 host_ = host; 47 } SetPort(uint16_t port)48 void inline SetPort(uint16_t port) 49 { 50 port_ = port; 51 } SetExclusionList(const std::list<std::string> & list)52 void inline SetExclusionList(const std::list<std::string> &list) 53 { 54 exclusionList_ = list; 55 } SetUserName(const SecureData & username)56 void inline SetUserName(const SecureData &username) 57 { 58 username_ = username; 59 } SetPassword(const SecureData & password)60 void inline SetPassword(const SecureData &password) 61 { 62 password_ = password; 63 } 64 65 bool operator==(const HttpProxy &httpProxy) const; 66 bool operator!=(const HttpProxy &httpProxy) const; 67 bool Marshalling(Parcel &parcel) const override; 68 static bool Unmarshalling(Parcel &parcel, HttpProxy &httpProxy); 69 70 private: 71 std::string host_; 72 uint16_t port_; 73 SecureData username_; 74 SecureData password_; 75 std::list<std::string> exclusionList_; 76 }; 77 } // namespace NetManagerStandard 78 } // namespace OHOS 79 #endif /* NETMANAGER_BASE_HTTP_PROXY_H */ 80