1# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/ohos.gni")
15import("//foundation/communication/netstack/netstack_config.gni")
16
17config("http_config") {
18  include_dirs = [
19    "async_context/include",
20    "async_work/include",
21    "cache/base64/include",
22    "cache/cache_constant/include",
23    "cache/cache_proxy/include",
24    "cache/cache_strategy/include",
25    "cache/lru_cache/include",
26    "constant/include",
27    "http_exec/include",
28    "http_module/include",
29    "options/include",
30    "$NETSTACK_DIR/utils/common_utils/include",
31  ]
32  if (defined(global_parts_info) &&
33      defined(global_parts_info.communication_netmanager_base) &&
34      global_parts_info.communication_netmanager_base) {
35    include_dirs += [
36      "$NETMANAGER_BASE_INNERKITS_DIR/include",
37      "$NETMANAGER_BASE_INNERKITS_DIR/netconnclient/include",
38      "$NETSTACK_DIR/utils/http_over_curl/include",
39    ]
40  }
41  defines = []
42
43  if (is_mingw || is_mac) {
44    cflags = [
45      "-std=c++17",
46      "-stdlib=libc++",
47    ]
48  }
49  if (is_mingw) {
50    defines += [ "WINDOWS_PLATFORM" ]
51  } else if (is_mac) {
52    defines += [ "MAC_PLATFORM" ]
53    cflags_cc = [
54      "-fstack-protector-strong",
55      "-D_FORTIFY_SOURCE=2",
56      "-O2",
57    ]
58  } else if (product_name != "ohos-sdk") {
59    defines += [ "HTTP_PROXY_ENABLE" ]
60    cflags_cc = [
61      "-fstack-protector-strong",
62      "-D_FORTIFY_SOURCE=2",
63      "-O2",
64    ]
65  }
66
67  if (product_name != "ohos-sdk") {
68    defines += [ "HTTP_MULTIPATH_CERT_ENABLE" ]
69  }
70
71  if (netstack_http_boringssl) {
72    defines += [ "HTTP_CACHE_FILE_PATH_USE_BASE" ]
73  }
74}
75
76ohos_shared_library("http") {
77  if (product_name != "ohos-sdk") {
78    sanitize = {
79      cfi = true
80      cfi_cross_dso = true
81      debug = false
82    }
83  }
84
85  branch_protector_ret = "pac_ret"
86
87  include_dirs = []
88
89  sources = [
90    "$NETSTACK_DIR/utils/profiler_utils/src/http_network_message.cpp",
91    "$NETSTACK_DIR/utils/profiler_utils/src/i_network_message.cpp",
92    "$NETSTACK_DIR/utils/profiler_utils/src/netstack_network_profiler.cpp",
93    "$NETSTACK_DIR/utils/tlv_utils/src/tlv_utils.cpp",
94    "async_context/src/request_context.cpp",
95    "async_work/src/http_async_work.cpp",
96    "cache/base64/src/base64_utils.cpp",
97    "cache/cache_proxy/src/cache_proxy.cpp",
98    "cache/cache_strategy/src/http_cache_request.cpp",
99    "cache/cache_strategy/src/http_cache_response.cpp",
100    "cache/cache_strategy/src/http_cache_strategy.cpp",
101    "cache/cache_strategy/src/http_time.cpp",
102    "cache/lru_cache/src/disk_handler.cpp",
103    "cache/lru_cache/src/lru_cache.cpp",
104    "cache/lru_cache/src/lru_cache_disk_handler.cpp",
105    "constant/src/constant.cpp",
106    "http_exec/src/http_exec.cpp",
107    "http_module/src/http_module.cpp",
108    "options/src/http_request_options.cpp",
109    "options/src/http_response.cpp",
110  ]
111
112  configs = [ ":http_config" ]
113
114  if (is_mingw || is_mac) {
115    sources += [
116      "$NETSTACK_DIR/utils/common_utils/src/netstack_common_utils.cpp",
117      "$NETSTACK_DIR/utils/common_utils/src/request_tracer.cpp",
118    ]
119    deps = [
120      "$ARKUI_ROOT/napi:ace_napi",
121      "$NETSTACK_DIR/utils/napi_utils:napi_utils_static",
122      "$THIRD_PARTY_ROOT/bounds_checking_function:libsec_static",
123      "$THIRD_PARTY_ROOT/jsoncpp:jsoncpp_static",
124    ]
125    external_deps = [
126      "cJSON:cjson",
127      "curl:curl_shared",
128    ]
129    ldflags = [ "-lpthread" ]
130  } else {
131    deps = [
132      "$NETSTACK_DIR/utils:stack_utils_common",
133      "$NETSTACK_DIR/utils/napi_utils:napi_utils",
134      "$THIRD_PARTY_ROOT/jsoncpp:jsoncpp",
135    ]
136    external_deps = [
137      "ability_runtime:wantagent_innerkits",
138      "cJSON:cjson",
139      "curl:curl_shared_http3",
140      "hilog:libhilog",
141      "hiprofiler:libnetwork_profiler",
142      "hitrace:hitrace_meter",
143      "napi:ace_napi",
144      "time_service:time_client",
145    ]
146    if (netstack_http_boringssl) {
147      deps += [
148        "//vendor/open_source/boringssl:crypto_boringssl",
149        "//vendor/open_source/boringssl:ssl_boringssl",
150      ]
151    } else {
152      external_deps += [
153        "openssl:libcrypto_shared",
154        "openssl:libssl_shared",
155      ]
156    }
157    if (defined(global_parts_info) &&
158        defined(global_parts_info.communication_netmanager_base) &&
159        global_parts_info.communication_netmanager_base) {
160      external_deps += [ "netmanager_base:net_conn_manager_if" ]
161      external_deps += [ "netmanager_base:netsys_client" ]
162      defines = [ "HAS_NETMANAGER_BASE=1" ]
163      sources += [
164        "$NETSTACK_DIR/utils/http_over_curl/src/epoll_multi_driver.cpp",
165        "$NETSTACK_DIR/utils/http_over_curl/src/epoll_request_handler.cpp",
166      ]
167    } else {
168      defines = [ "HAS_NETMANAGER_BASE=0" ]
169    }
170    if (product_name != "ohos-sdk") {
171      external_deps += [ "init:libbegetutil" ]
172    }
173  }
174  include_dirs += [
175    "$NETSTACK_DIR/utils/profiler_utils/include",
176    "$NETSTACK_DIR/utils/tlv_utils/include",
177  ]
178  cflags = [
179    "-fstack-protector-strong",
180    "-D_FORTIFY_SOURCE=2",
181    "-O2",
182  ]
183
184  relative_install_dir = "module/net"
185  part_name = "netstack"
186  subsystem_name = "communication"
187}
188