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
72ohos_shared_library("http") {
73  if (product_name != "ohos-sdk") {
74    sanitize = {
75      cfi = true
76      cfi_cross_dso = true
77      debug = false
78    }
79  }
80
81  branch_protector_ret = "pac_ret"
82
83  include_dirs = []
84
85  sources = [
86    "$NETSTACK_DIR/utils/profiler_utils/src/http_network_message.cpp",
87    "$NETSTACK_DIR/utils/profiler_utils/src/i_network_message.cpp",
88    "$NETSTACK_DIR/utils/profiler_utils/src/netstack_network_profiler.cpp",
89    "$NETSTACK_DIR/utils/tlv_utils/src/tlv_utils.cpp",
90    "async_context/src/request_context.cpp",
91    "async_work/src/http_async_work.cpp",
92    "cache/base64/src/base64_utils.cpp",
93    "cache/cache_proxy/src/cache_proxy.cpp",
94    "cache/cache_strategy/src/http_cache_request.cpp",
95    "cache/cache_strategy/src/http_cache_response.cpp",
96    "cache/cache_strategy/src/http_cache_strategy.cpp",
97    "cache/cache_strategy/src/http_time.cpp",
98    "cache/lru_cache/src/disk_handler.cpp",
99    "cache/lru_cache/src/lru_cache.cpp",
100    "cache/lru_cache/src/lru_cache_disk_handler.cpp",
101    "constant/src/constant.cpp",
102    "http_exec/src/http_exec.cpp",
103    "http_module/src/http_module.cpp",
104    "options/src/http_request_options.cpp",
105    "options/src/http_response.cpp",
106  ]
107
108  configs = [ ":http_config" ]
109
110  if (is_mingw || is_mac) {
111    sources +=
112        [ "$NETSTACK_DIR/utils/common_utils/src/netstack_common_utils.cpp" ]
113    deps = [
114      "$ARKUI_ROOT/napi:ace_napi",
115      "$NETSTACK_DIR/utils/napi_utils:napi_utils_static",
116      "$THIRD_PARTY_ROOT/bounds_checking_function:libsec_static",
117      "$THIRD_PARTY_ROOT/jsoncpp:jsoncpp_static",
118    ]
119    external_deps = [
120      "cJSON:cjson",
121      "curl:curl_shared",
122    ]
123    ldflags = [ "-lpthread" ]
124  } else {
125    deps = [
126      "$NETSTACK_DIR/utils:stack_utils_common",
127      "$NETSTACK_DIR/utils/napi_utils:napi_utils",
128      "$THIRD_PARTY_ROOT/jsoncpp:jsoncpp",
129    ]
130    external_deps = [
131      "ability_runtime:wantagent_innerkits",
132      "cJSON:cjson",
133      "curl:curl_shared_http3",
134      "hilog:libhilog",
135      "hiprofiler:libnetwork_profiler",
136      "hitrace:hitrace_meter",
137      "napi:ace_napi",
138      "time_service:time_client",
139    ]
140    if (netstack_http_boringssl) {
141      deps += [
142        "//vendor/open_source/boringssl:crypto_boringssl",
143        "//vendor/open_source/boringssl:ssl_boringssl",
144      ]
145    } else {
146      external_deps += [
147        "openssl:libcrypto_shared",
148        "openssl:libssl_shared",
149      ]
150    }
151    if (defined(global_parts_info) &&
152        defined(global_parts_info.communication_netmanager_base) &&
153        global_parts_info.communication_netmanager_base) {
154      external_deps += [ "netmanager_base:net_conn_manager_if" ]
155      external_deps += [ "netmanager_base:netsys_client" ]
156      defines = [ "HAS_NETMANAGER_BASE=1" ]
157      sources += [
158        "$NETSTACK_DIR/utils/http_over_curl/src/epoll_multi_driver.cpp",
159        "$NETSTACK_DIR/utils/http_over_curl/src/epoll_request_handler.cpp",
160      ]
161    } else {
162      defines = [ "HAS_NETMANAGER_BASE=0" ]
163    }
164    if (product_name != "ohos-sdk") {
165      external_deps += [ "init:libbegetutil" ]
166    }
167  }
168  include_dirs += [
169    "$NETSTACK_DIR/utils/profiler_utils/include",
170    "$NETSTACK_DIR/utils/tlv_utils/include",
171  ]
172  cflags = [
173    "-fstack-protector-strong",
174    "-D_FORTIFY_SOURCE=2",
175    "-O2",
176  ]
177
178  relative_install_dir = "module/net"
179  part_name = "netstack"
180  subsystem_name = "communication"
181}
182