From 1d13f83395c1c9b597d5781ffd48b488fdd1782f Mon Sep 17 00:00:00 2001 From: cy Date: Wed, 25 Dec 2024 17:25:19 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=B8=80=E8=87=B4=E6=80=A7=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cy --- BUILD.gn | 1 + for_ios.patch | 1 + for_ios.sh | 1 + include/lws_config.h | 1 + include/lws_config_private.h | 1 + lib/core-net/client/connect3.c | 3 ++- 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/BUILD.gn b/BUILD.gn index d3309d55..afde97fa 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + import("//build/ohos.gni") platform = "${current_os}_${current_cpu}" diff --git a/for_ios.patch b/for_ios.patch index c3c398ae..5790cf05 100755 --- a/for_ios.patch +++ b/for_ios.patch @@ -11,3 +11,4 @@ index 298bf01e..e8dc468e 100644 #endif NULL }; + diff --git a/for_ios.sh b/for_ios.sh index fbc3cdbe..e943c393 100755 --- a/for_ios.sh +++ b/for_ios.sh @@ -1,5 +1,6 @@ #!/bin/bash + # Copyright (c) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/include/lws_config.h b/include/lws_config.h index cf9bdd02..a7f03419 100644 --- a/include/lws_config.h +++ b/include/lws_config.h @@ -1,6 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * + * * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/lws_config_private.h b/include/lws_config_private.h index 24897944..4eb12236 100644 --- a/include/lws_config_private.h +++ b/include/lws_config_private.h @@ -1,6 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * + * * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/lib/core-net/client/connect3.c b/lib/core-net/client/connect3.c index 9d669e3b..34b2232c 100644 --- a/lib/core-net/client/connect3.c +++ b/lib/core-net/client/connect3.c @@ -1,6 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * + * * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -244,7 +245,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, * If the connection failed, the OS-level errno may be * something like EINPROGRESS rather than the actual problem * that prevented a connection. This value will represent the - * ¡°real¡± problem that we should report to the caller. + * ��real�� problem that we should report to the caller. */ int real_errno = 0; -- Gitee From a40591588d6b0b3a6efbcf4b0d9cc6fd410f5124 Mon Sep 17 00:00:00 2001 From: cy Date: Thu, 26 Dec 2024 11:15:00 +0000 Subject: [PATCH 2/7] update BUILD.gn. Signed-off-by: cy --- BUILD.gn | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index afde97fa..e024d61f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -11,16 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. - import("//build/ohos.gni") platform = "${current_os}_${current_cpu}" -if (target_os == "ios") { - libwebsockets_path = rebase_path("//third_party/libwebsockets") - exec_script("for_ios.sh", [ "$libwebsockets_path" ]) -} - ohos_static_library("websockets") { sources = [ "//third_party/libwebsockets/lib/core-net/adopt.c", @@ -36,9 +30,11 @@ ohos_static_library("websockets") { "//third_party/libwebsockets/lib/core-net/network.c", "//third_party/libwebsockets/lib/core-net/output.c", "//third_party/libwebsockets/lib/core-net/pollfd.c", + "//third_party/libwebsockets/lib/core-net/route.c", "//third_party/libwebsockets/lib/core-net/service.c", "//third_party/libwebsockets/lib/core-net/sorted-usec-list.c", "//third_party/libwebsockets/lib/core-net/state.c", + "//third_party/libwebsockets/lib/core-net/vhost.c", "//third_party/libwebsockets/lib/core-net/wsi-timeout.c", "//third_party/libwebsockets/lib/core-net/wsi.c", "//third_party/libwebsockets/lib/core/alloc.c", @@ -82,6 +78,7 @@ ohos_static_library("websockets") { "//third_party/libwebsockets/lib/roles/http/server/lws-spa.c", "//third_party/libwebsockets/lib/roles/http/server/server.c", "//third_party/libwebsockets/lib/roles/listen/ops-listen.c", + "//third_party/libwebsockets/lib/roles/netlink/ops-netlink.c", "//third_party/libwebsockets/lib/roles/pipe/ops-pipe.c", "//third_party/libwebsockets/lib/roles/raw-file/ops-raw-file.c", "//third_party/libwebsockets/lib/roles/raw-skt/ops-raw-skt.c", @@ -107,13 +104,6 @@ ohos_static_library("websockets") { part_name = "libwebsockets" subsystem_name = "thirdparty" - if (target_os != "ios") { - sources += [ - "//third_party/libwebsockets/lib/core-net/route.c", - "//third_party/libwebsockets/lib/roles/netlink/ops-netlink.c", - ] - } - include_dirs = [ "//third_party/libwebsockets/include", "//third_party/libwebsockets/include/libwebsockets", @@ -218,20 +208,10 @@ ohos_static_library("websockets") { "//third_party/glib", ] - if (target_os == "ios") { - sources += [ "//third_party/libwebsockets/lib/core-net/vhost_ios.c" ] - } else { - sources += [ "//third_party/libwebsockets/lib/core-net/vhost.c" ] - } - defines = [ "OHOS_LIBWEBSOCKETS=1", "OPENSSL_SUPPRESS_DEPRECATED", ] - if (target_os == "ios") { - defines += [ "LWS_DETECTED_PLAT_IOS=1" ] - defines += [ "CROSS_PLATFORM_IOS_LIBWEBSOCKETS=1" ] - } cflags = [ "-fPIC", @@ -306,7 +286,7 @@ config("websockets_public_config") { if (platform == "mingw_x86_64") { include_dirs += [ "//third_party/libwebsockets/lib/plat/windows" ] } else if (platform == "mac_arm64" || platform == "mac_x64" || - platform == "linux_x64" || platform == "linux_arm64") { + platform == "linux_x64") { include_dirs += [ "//third_party/libwebsockets/lib/plat/unix" ] } cflags = [ "-Wno-error=#warnings" ] @@ -379,7 +359,7 @@ ohos_static_library("websockets_static") { "//third_party/libwebsockets/lib/plat/windows/windows-sockets.c", ] } else if (platform == "mac_arm64" || platform == "mac_x64" || - platform == "linux_x64" || platform == "linux_arm64") { + platform == "linux_x64") { defines = [ "LWS_HAVE_SYS_RESOURCE_H" ] sources += [ "//third_party/libwebsockets/lib/plat/unix/unix-caps.c", -- Gitee From 9d840a598b516e47806d24dc37880fc052354b15 Mon Sep 17 00:00:00 2001 From: cy Date: Thu, 26 Dec 2024 11:26:44 +0000 Subject: [PATCH 3/7] update lib/core-net/client/connect3.c. Signed-off-by: cy --- lib/core-net/client/connect3.c | 106 ++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/lib/core-net/client/connect3.c b/lib/core-net/client/connect3.c index 34b2232c..2a9fa6b8 100644 --- a/lib/core-net/client/connect3.c +++ b/lib/core-net/client/connect3.c @@ -1,7 +1,6 @@ /* * libwebsockets - small server side websockets and web server implementation * - * * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,6 +24,108 @@ #include "private-lib-core.h" +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +size_t get_res_size(struct addrinfo *res) +{ + size_t size = 0; + for (struct addrinfo *p = res; p; p = p->ai_next) { + if (p->ai_family != AF_INET && p->ai_family != AF_INET6) { + continue; + } + ++size; + } + return size; +} + +struct addrinfo **get_dns_res(struct addrinfo *res, sa_family_t family, size_t totalLength, size_t *size) +{ + struct addrinfo **temp = (struct addrinfo **)(malloc(sizeof(struct addrinfo *) * totalLength)); + if (!temp) { + return NULL; + } + size_t index = 0; + for (struct addrinfo *p = res; p; p = p->ai_next) { + if (p->ai_family == family) { + temp[index] = p; + ++index; + } + } + *size = index; + return temp; +} + +sa_family_t change_family(sa_family_t nowFamily) +{ + if (nowFamily == AF_INET6) { + return AF_INET; + } + return AF_INET6; +} + +struct addrinfo *sort_dns(struct addrinfo *res) +{ + size_t totalLength = get_res_size(res); + if (totalLength == 0) { + return NULL; + } + + size_t ipv6Size = 0; + struct addrinfo **ipv6Dns = get_dns_res(res, AF_INET6, totalLength, &ipv6Size); + size_t ipv4Size = 0; + struct addrinfo **ipv4Dns = get_dns_res(res, AF_INET, totalLength, &ipv4Size); + if (ipv4Dns == NULL && ipv6Dns == NULL) { + return NULL; + } + + for (size_t i = 0; i < ipv6Size; ++i) { + ipv6Dns[i]->ai_next = NULL; + } + for (size_t i = 0; i < ipv4Size; ++i) { + ipv4Dns[i]->ai_next = NULL; + } + + size_t ipv6Index = 0; + size_t ipv4Index = 0; + sa_family_t now = AF_INET6; + + struct addrinfo *head = (struct addrinfo *)malloc(sizeof(struct addrinfo)); + memset(head, 0, sizeof(struct addrinfo)); + struct addrinfo *next = head; + + size_t minSize = MIN(ipv6Size, ipv4Size); + size_t index = 0; + while (index < 2 * minSize) { + if (now == AF_INET6) { + next->ai_next = ipv6Dns[ipv6Index++]; + } else { + next->ai_next = ipv4Dns[ipv4Index++]; + } + ++index; + now = change_family(now); + next = next->ai_next; + } + while (ipv6Index < ipv6Size) { + next->ai_next = ipv6Dns[ipv6Index++]; + ++index; + next = next->ai_next; + } + while (ipv4Index < ipv4Size) { + next->ai_next = ipv4Dns[ipv4Index++]; + ++index; + next = next->ai_next; + } + struct addrinfo *result = head->ai_next; + free(head); + if (ipv6Dns) { + free(ipv6Dns); + } + if (ipv4Dns) { + free(ipv4Dns); + } + return result; +} + void lws_client_conn_wait_timeout(lws_sorted_usec_list_t *sul) { @@ -184,6 +285,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, lws_conmon_append_copy_new_dns_results(wsi, result); #endif + result = sort_dns((struct addrinfo *)result); lws_sort_dns(wsi, result); #if defined(LWS_WITH_SYS_ASYNC_DNS) lws_async_dns_freeaddrinfo(&result); @@ -245,7 +347,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, * If the connection failed, the OS-level errno may be * something like EINPROGRESS rather than the actual problem * that prevented a connection. This value will represent the - * ��real�� problem that we should report to the caller. + * "real" problem that we should report to the caller. */ int real_errno = 0; -- Gitee From 3b45402d84706d1eeafcd78955a4da84ef60658a Mon Sep 17 00:00:00 2001 From: cy Date: Thu, 26 Dec 2024 11:27:23 +0000 Subject: [PATCH 4/7] update include/lws_config_private.h. Signed-off-by: cy --- include/lws_config_private.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/lws_config_private.h b/include/lws_config_private.h index 4eb12236..1005421b 100644 --- a/include/lws_config_private.h +++ b/include/lws_config_private.h @@ -1,7 +1,6 @@ /* * libwebsockets - small server side websockets and web server implementation * - * * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -72,10 +71,8 @@ /* Define to 1 if you have the header file. */ #define LWS_HAVE_STRING_H -#if !defined (CROSS_PLATFORM_IOS_LIBWEBSOCKETS) /* Define to 1 if you have the header file. */ #define LWS_HAVE_SYS_PRCTL_H -#endif /* Define to 1 if you have the header file. */ #define LWS_HAVE_SYS_RESOURCE_H -- Gitee From a2007b37d73b70132f4bdadf8ea89e7210e599e1 Mon Sep 17 00:00:00 2001 From: cy Date: Thu, 26 Dec 2024 11:27:50 +0000 Subject: [PATCH 5/7] update include/lws_config.h. Signed-off-by: cy --- include/lws_config.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/lws_config.h b/include/lws_config.h index a7f03419..55dcbe37 100644 --- a/include/lws_config.h +++ b/include/lws_config.h @@ -1,7 +1,6 @@ /* * libwebsockets - small server side websockets and web server implementation * - * * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -90,9 +89,7 @@ #define LWS_HAVE_HMAC_CTX_new #define LWS_HAVE_MALLOC_H #define LWS_HAVE_MALLOC_TRIM -#if !defined (CROSS_PLATFORM_IOS_LIBWEBSOCKETS) #define LWS_HAVE_MALLOC_USABLE_SIZE -#endif /* #undef LWS_HAVE_mbedtls_md_setup */ /* #undef LWS_HAVE_mbedtls_net_init */ /* #undef LWS_HAVE_mbedtls_rsa_complete */ @@ -110,10 +107,8 @@ /* #undef LWS_HAVE_NEW_UV_VERSION_H */ #define LWS_HAVE_OPENSSL_ECDH_H #define LWS_HAVE_OPENSSL_STACK -#if !defined (CROSS_PLATFORM_IOS_LIBWEBSOCKETS) #define LWS_HAVE_PIPE2 #define LWS_HAVE_EVENTFD -#endif #define LWS_HAVE_PTHREAD_H #define LWS_HAVE_RSA_SET0_KEY /* #undef LWS_HAVE_RSA_verify_pss_mgf1 */ @@ -213,9 +208,7 @@ #define LWS_LOGS_TIMESTAMP /* #undef LWS_WITH_MBEDTLS */ /* #undef LWS_WITH_MINIZ */ -#if !defined (CROSS_PLATFORM_IOS_LIBWEBSOCKETS) #define LWS_WITH_NETLINK -#endif #define LWS_WITH_NETWORK /* #undef LWS_WITH_NO_LOGS */ #define LWS_WITH_CACHE_NSCOOKIEJAR -- Gitee From 40c216921ec752c1c2f25ae6a8031f59b6c928e5 Mon Sep 17 00:00:00 2001 From: cy Date: Thu, 26 Dec 2024 11:41:22 +0000 Subject: [PATCH 6/7] update for_ios.patch. Signed-off-by: cy --- for_ios.patch | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/for_ios.patch b/for_ios.patch index 5790cf05..e69de29b 100755 --- a/for_ios.patch +++ b/for_ios.patch @@ -1,14 +0,0 @@ -diff --git a/lib/core-net/vhost_ios.c b/lib/core-net/vhost_ios.c -index 298bf01e..e8dc468e 100644 ---- a/lib/core-net/vhost_ios.c -+++ b/lib/core-net/vhost_ios.c -@@ -48,6 +48,8 @@ const struct lws_role_ops *available_roles[] = { - #endif - #if defined(LWS_WITH_NETLINK) - &role_ops_netlink, -+#else -+ NULL, - #endif - NULL - }; - -- Gitee From 9b5e6287dbb11fb232d62d3c545738f167464fd9 Mon Sep 17 00:00:00 2001 From: cy Date: Thu, 26 Dec 2024 11:41:47 +0000 Subject: [PATCH 7/7] update for_ios.sh. Signed-off-by: cy --- for_ios.sh | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/for_ios.sh b/for_ios.sh index e943c393..e69de29b 100755 --- a/for_ios.sh +++ b/for_ios.sh @@ -1,22 +0,0 @@ -#!/bin/bash - - -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -e - -cd $1 -rm -f lib/core-net/vhost_ios.c -cp lib/core-net/vhost.c lib/core-net/vhost_ios.c -git apply for_ios.patch -- Gitee