1 /* 2 * Copyright (c) 2025-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 COMMUNICATIONNETSTACK_NETSTACK_CHR_CLIENT_H 17 #define COMMUNICATIONNETSTACK_NETSTACK_CHR_CLIENT_H 18 19 #include <cstdint> 20 #include <string> 21 #include "curl/curl.h" 22 #include "netstack_chr_report.h" 23 #include "i_netstack_chr_client.h" 24 25 namespace OHOS::NetStack::ChrClient { 26 27 class NetStackChrClient { 28 public: 29 static NetStackChrClient &GetInstance(); 30 void GetDfxInfoFromCurlHandleAndReport(CURL *handle, int32_t curlCode); 31 32 private: 33 NetStackChrClient() = default; 34 ~NetStackChrClient() = default; 35 36 static int GetAddrFromSock( 37 int sockfd, std::string &srcIp, std::string &dstIp, uint16_t &srcPort, uint16_t &dstPort); 38 static int GetTcpInfoFromSock(const curl_socket_t sockfd, DataTransTcpInfo &httpTcpInfo); 39 static void GetHttpInfoFromCurl(CURL *handle, DataTransHttpInfo &httpInfo); 40 41 template <typename DataType> 42 static DataType GetNumericAttributeFromCurl(CURL *handle, CURLINFO info); 43 static std::string GetStringAttributeFromCurl(CURL *handle, CURLINFO info); 44 static long GetRequestStartTime(curl_off_t totalTime); 45 static int ShouldReportHttpAbnormalEvent(const DataTransHttpInfo &httpInfo); 46 NetStackChrReport netstackChrReport_; 47 }; 48 49 } // namespace OHOS::NetStack::ChrClient 50 51 #endif // COMMUNICATIONNETSTACK_NETSTACK_CHR_CLIENT_H