From a07a98d37360cd65cc9a6bc84ef42c75cb2648a1 Mon Sep 17 00:00:00 2001 From: cy Date: Sat, 28 Dec 2024 10:14:34 +0800 Subject: [PATCH 1/8] =?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 + bundle.json | 1 + for_ios.patch | 1 + for_ios.sh | 1 + include/lws_config.h | 3 ++- include/lws_config_private.h | 3 ++- lib/core-net/client/connect3.c | 3 ++- 7 files changed, 10 insertions(+), 3 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index d3309d55..afc4d476 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -20,6 +20,7 @@ if (target_os == "ios") { exec_script("for_ios.sh", [ "$libwebsockets_path" ]) } + ohos_static_library("websockets") { sources = [ "//third_party/libwebsockets/lib/core-net/adopt.c", diff --git a/bundle.json b/bundle.json index ec52483f..9795eef0 100644 --- a/bundle.json +++ b/bundle.json @@ -19,6 +19,7 @@ "rom": "319KB", "ram": "13865KB", "deps": { + "components": [], "third_party": [ "openssl", diff --git a/for_ios.patch b/for_ios.patch index c3c398ae..d752e454 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..faffca9c 100755 --- a/for_ios.sh +++ b/for_ios.sh @@ -19,3 +19,4 @@ 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 + diff --git a/include/lws_config.h b/include/lws_config.h index cf9bdd02..e84870d2 100644 --- a/include/lws_config.h +++ b/include/lws_config.h @@ -4,7 +4,8 @@ * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to + * of this softwar + * e and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is diff --git a/include/lws_config_private.h b/include/lws_config_private.h index 24897944..818de4db 100644 --- a/include/lws_config_private.h +++ b/include/lws_config_private.h @@ -5,7 +5,8 @@ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the + * deal i + * n the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: diff --git a/lib/core-net/client/connect3.c b/lib/core-net/client/connect3.c index 9d669e3b..826a81b8 100644 --- a/lib/core-net/client/connect3.c +++ b/lib/core-net/client/connect3.c @@ -3,6 +3,7 @@ * * Copyright (C) 2010 - 2020 Andy Green * + * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the @@ -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 7fee327a7f5f030f536e043b54a357cef1496559 Mon Sep 17 00:00:00 2001 From: cy Date: Sat, 28 Dec 2024 02:57:44 +0000 Subject: [PATCH 2/8] update BUILD.gn. Signed-off-by: cy --- BUILD.gn | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index afc4d476..590da7be 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -15,12 +15,6 @@ 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", @@ -248,7 +228,6 @@ ohos_static_library("websockets") { deps = [ "//third_party/openssl:libcrypto_shared", "//third_party/openssl:libssl_shared", - "//third_party/zlib:libz", ] } @@ -306,7 +285,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 +358,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 98f0b2db225809deb634775d2b2a6e0296c1e604 Mon Sep 17 00:00:00 2001 From: cy Date: Sat, 28 Dec 2024 02:58:48 +0000 Subject: [PATCH 3/8] update bundle.json. Signed-off-by: cy --- bundle.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bundle.json b/bundle.json index 9795eef0..4df4850c 100644 --- a/bundle.json +++ b/bundle.json @@ -19,11 +19,9 @@ "rom": "319KB", "ram": "13865KB", "deps": { - - "components": [], + "components": [ "zlib" ], "third_party": [ - "openssl", - "zlib" + "openssl" ] }, "build": { -- Gitee From 5de3bde0acac5c41f5bfe8b643716e46b6725668 Mon Sep 17 00:00:00 2001 From: cy Date: Sat, 28 Dec 2024 03:10:03 +0000 Subject: [PATCH 4/8] update include/lws_config.h. Signed-off-by: cy --- include/lws_config.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/include/lws_config.h b/include/lws_config.h index e84870d2..55dcbe37 100644 --- a/include/lws_config.h +++ b/include/lws_config.h @@ -4,8 +4,7 @@ * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this softwar - * e and associated documentation files (the "Software"), to + * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is @@ -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 68cfa7ca5e7f74f5c10e218dfcd8ae0caf20fad2 Mon Sep 17 00:00:00 2001 From: cy Date: Sat, 28 Dec 2024 03:11:03 +0000 Subject: [PATCH 5/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20for?= =?UTF-8?q?=5Fios.patch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- for_ios.patch | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100755 for_ios.patch diff --git a/for_ios.patch b/for_ios.patch deleted file mode 100755 index d752e454..00000000 --- a/for_ios.patch +++ /dev/null @@ -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 0681fbea36c053d9ea9da8709ff753046ec4c497 Mon Sep 17 00:00:00 2001 From: cy Date: Sat, 28 Dec 2024 03:11:12 +0000 Subject: [PATCH 6/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20for?= =?UTF-8?q?=5Fios.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- for_ios.sh | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100755 for_ios.sh diff --git a/for_ios.sh b/for_ios.sh deleted file mode 100755 index faffca9c..00000000 --- a/for_ios.sh +++ /dev/null @@ -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 From 1698061f1252fafeaa660b90ebf582ad642805ed Mon Sep 17 00:00:00 2001 From: cy Date: Sat, 28 Dec 2024 03:12:18 +0000 Subject: [PATCH 7/8] update include/lws_config_private.h. Signed-off-by: cy --- include/lws_config_private.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/lws_config_private.h b/include/lws_config_private.h index 818de4db..1005421b 100644 --- a/include/lws_config_private.h +++ b/include/lws_config_private.h @@ -5,8 +5,7 @@ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to - * deal i - * n the Software without restriction, including without limitation the + * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: @@ -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 eb66ff575d97cb882cc8c3299d23334b946a2973 Mon Sep 17 00:00:00 2001 From: cy Date: Sat, 28 Dec 2024 03:16:05 +0000 Subject: [PATCH 8/8] 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 826a81b8..c0c826f9 100644 --- a/lib/core-net/client/connect3.c +++ b/lib/core-net/client/connect3.c @@ -3,7 +3,6 @@ * * Copyright (C) 2010 - 2020 Andy Green * - * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the @@ -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