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 NET_WEBSOCKET_CONNECT_CONTEXT_H 17 #define NET_WEBSOCKET_CONNECT_CONTEXT_H 18 19 #include <map> 20 #include <string> 21 22 #include "constant.h" 23 #include "secure_char.h" 24 #include "ffi_structs.h" 25 #include "net_websocket_utils.h" 26 #include "net_websocket_base_context.h" 27 28 namespace OHOS::NetStack::NetWebSocket { 29 30 class CJWebsocketProxy; 31 32 class WebSocketConnectContext : public WebSocketBaseContext { 33 public: 34 friend class NetWebSocketExec; 35 WebSocketConnectContext() = delete; 36 37 WebSocketConnectContext(CJWebsocketProxy* websocketProxy); 38 39 virtual ~WebSocketConnectContext(); 40 41 void ParseParams(std::string url, CWebSocketRequestOptions *opt); 42 43 void SetClientCert(std::string &cert, SecureChar &key, SecureChar &keyPassword); 44 45 void GetClientCert(std::string &cert, SecureChar &key, SecureChar &keyPassword); 46 47 void SetProtocol(std::string protocol); 48 49 [[nodiscard]] std::string GetProtocol() const; 50 51 void SetWebsocketProxyType(WebsocketProxyType type); 52 53 [[nodiscard]] WebsocketProxyType GetUsingWebsocketProxyType() const; 54 55 void SetSpecifiedWebsocketProxy(const std::string &host, int32_t port, const std::string &exclusionList); 56 57 void GetSpecifiedWebsocketProxy(std::string &host, uint32_t &port, std::string &exclusionList) const; 58 59 std::string url; 60 61 std::map<std::string, std::string> header; 62 63 std::string caPath_; 64 65 std::string clientCert_; 66 67 SecureChar clientKey_; 68 69 SecureChar keyPassword_; 70 71 std::string websocketProtocol_; 72 73 WebsocketProxyType usingWebsocketProxyType_ = WebsocketProxyType::USE_SYSTEM; 74 75 std::string websocketProxyHost_; 76 77 int32_t websocketProxyPort_ = 0; 78 79 std::string websocketProxyExclusions_; 80 81 [[nodiscard]] int32_t GetErrorCode() const override; 82 83 [[nodiscard]] std::string GetErrorMessage() const override; 84 private: 85 std::string userCertPath_; 86 87 void ParseHeader(CArrString header); 88 89 void ParseProxy(CHttpProxy* proxy, bool useDefault); 90 }; 91 } 92 #endif