From c8a404175e20167558e38eb3e63a722f97ac2335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Tue, 24 May 2022 21:21:07 -0700 Subject: [PATCH] civetweb: remove obsolete code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This code has gone unmaintained and bugs continue to be reported against it. We do not have the resources as a project to maintain this in "odd fixes" mode, and nobody has stepped up to maintain it [1], so sadly this must be removed for now. If anyone would like to see civetweb supported in upstream Zephyr again, they are welcome to add it back, as long as they promise to maintain it going forward. Many thanks to everyone who has contributed to civetweb support in Zephyr while it was here. So long and thanks for all the fish. Fixes: #45807 Fixes: #43910 Fixes: #34226 Fixes: #46743 [1] https://lists.zephyrproject.org/g/devel/message/8466 Signed-off-by: Martí Bolívar --- CODEOWNERS | 1 - MAINTAINERS.yml | 10 - modules/Kconfig | 1 - modules/Kconfig.civetweb | 17 -- modules/deprecation_warnings.cmake | 7 +- .../common/include/external_log_access.inl | 29 --- .../include/external_mg_cry_internal_impl.inl | 23 -- samples/net/civetweb/common/include/helper.h | 15 -- .../civetweb/common/include/libc_extensions.h | 70 ----- .../net/civetweb/common/src/libc_extensions.c | 239 ------------------ .../net/civetweb/http_server/CMakeLists.txt | 23 -- samples/net/civetweb/http_server/README.rst | 48 ---- samples/net/civetweb/http_server/prj.conf | 36 --- samples/net/civetweb/http_server/sample.yaml | 13 - samples/net/civetweb/http_server/src/main.c | 187 -------------- .../civetweb/websocket_server/CMakeLists.txt | 54 ---- .../net/civetweb/websocket_server/README.rst | 64 ----- .../include/http_server_handlers.h | 14 - .../include/websocket_server_handlers.h | 14 - .../net/civetweb/websocket_server/prj.conf | 39 --- .../net/civetweb/websocket_server/sample.yaml | 8 - .../src/http_server_handlers.c | 201 --------------- .../net/civetweb/websocket_server/src/main.c | 69 ----- .../src/websocket_server_handlers.c | 149 ----------- .../websocket_server/web_page/index.css | 205 --------------- .../websocket_server/web_page/index.html | 42 --- .../civetweb/websocket_server/web_page/ws.js | 195 -------------- west.yml | 3 - 28 files changed, 1 insertion(+), 1775 deletions(-) delete mode 100644 modules/Kconfig.civetweb delete mode 100644 samples/net/civetweb/common/include/external_log_access.inl delete mode 100644 samples/net/civetweb/common/include/external_mg_cry_internal_impl.inl delete mode 100644 samples/net/civetweb/common/include/helper.h delete mode 100644 samples/net/civetweb/common/include/libc_extensions.h delete mode 100644 samples/net/civetweb/common/src/libc_extensions.c delete mode 100644 samples/net/civetweb/http_server/CMakeLists.txt delete mode 100644 samples/net/civetweb/http_server/README.rst delete mode 100644 samples/net/civetweb/http_server/prj.conf delete mode 100644 samples/net/civetweb/http_server/sample.yaml delete mode 100644 samples/net/civetweb/http_server/src/main.c delete mode 100644 samples/net/civetweb/websocket_server/CMakeLists.txt delete mode 100644 samples/net/civetweb/websocket_server/README.rst delete mode 100644 samples/net/civetweb/websocket_server/include/http_server_handlers.h delete mode 100644 samples/net/civetweb/websocket_server/include/websocket_server_handlers.h delete mode 100644 samples/net/civetweb/websocket_server/prj.conf delete mode 100644 samples/net/civetweb/websocket_server/sample.yaml delete mode 100644 samples/net/civetweb/websocket_server/src/http_server_handlers.c delete mode 100644 samples/net/civetweb/websocket_server/src/main.c delete mode 100644 samples/net/civetweb/websocket_server/src/websocket_server_handlers.c delete mode 100644 samples/net/civetweb/websocket_server/web_page/index.css delete mode 100644 samples/net/civetweb/websocket_server/web_page/index.html delete mode 100644 samples/net/civetweb/websocket_server/web_page/ws.js diff --git a/CODEOWNERS b/CODEOWNERS index 1bb074964f7b85..0e25e88fc6866f 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -664,7 +664,6 @@ /samples/net/mqtt_publisher/ @rlubos /samples/net/sockets/coap_*/ @rlubos /samples/net/sockets/ @rlubos @tbursztyka @pfalcon -/samples/net/*civetweb* @Nukersson /samples/sensor/ @MaureenHelm /samples/shields/ @avisconti /samples/subsys/logging/ @nordic-krch @jakub-uC diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index e0c2576a2fb1ae..6f00dd78423ba7 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1991,16 +1991,6 @@ West: - manifest-canopennode - "area: CAN" -"West project: civetweb": - status: obsolete - files: - - samples/net/civetweb/ - - modules/Kconfig.civetweb - labels: - - manifest-civetweb - - "area: Networking" - - "area: civetweb" - "West project: cmsis": status: maintained maintainers: diff --git a/modules/Kconfig b/modules/Kconfig index 6a45dcbe1c246d..0cf8864e4b5b9b 100644 --- a/modules/Kconfig +++ b/modules/Kconfig @@ -9,7 +9,6 @@ comment "Optional modules. Make sure they're installed, via the project manifest source "modules/Kconfig.altera" source "modules/Kconfig.atmel" -source "modules/Kconfig.civetweb" source "modules/Kconfig.cmsis" source "modules/Kconfig.cypress" source "modules/Kconfig.eos_s3" diff --git a/modules/Kconfig.civetweb b/modules/Kconfig.civetweb deleted file mode 100644 index f8eeb1017d9c64..00000000000000 --- a/modules/Kconfig.civetweb +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (c) 2019 Antmicro Ltd -# SPDX-License-Identifier: Apache-2.0 - -config CIVETWEB - bool "Civetweb Support (DEPRECATED)" - # The CONFIG_NET_TCP_ISN_RFC6528 option would pull in mbedtls, - # and there are include file issues if CONFIG_POSIX_API is set. - # Because Civetweb sets the POSIX API option in the samples, - # make sure that we do not try to use Civetweb if the TCP ISN - # option is set. - depends on !NET_TCP_ISN_RFC6528 - help - This option enables the civetweb HTTP API. - Support for this module is now deprecated due to a lack - of maintainers. Please volunteer to maintain this module - if you would like to see support for it remain in upstream - Zephyr. diff --git a/modules/deprecation_warnings.cmake b/modules/deprecation_warnings.cmake index 7d9d688b6ed982..91b7d8602fa3c3 100644 --- a/modules/deprecation_warnings.cmake +++ b/modules/deprecation_warnings.cmake @@ -11,9 +11,4 @@ # This is done in a separate CMake file because the modules.cmake file # in this same directory is evaluated before Kconfig runs. -if(CONFIG_CIVETWEB) - message(WARNING "The civetweb module is deprecated. \ - Unless someone volunteers to maintain this module, \ - support for it will be removed in Zephyr v3.2." - ) -endif() +# (No modules are currently deprecated.) diff --git a/samples/net/civetweb/common/include/external_log_access.inl b/samples/net/civetweb/common/include/external_log_access.inl deleted file mode 100644 index 438589d5e11e9d..00000000000000 --- a/samples/net/civetweb/common/include/external_log_access.inl +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2019 Antmicro Ltd - * Copyright (c) 2020 Alexander Kozhinov - * - * SPDX-License-Identifier: Apache-2.0 - */ - -static void log_access(const struct mg_connection *conn) -{ - const struct mg_request_info *ri; - char src_addr[IP_ADDR_STR_LEN]; - - if (!conn || !conn->dom_ctx) { - return; - } - - ri = &conn->request_info; - - sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa); - - LOG_DBG("%s - \"%s %s%s%s HTTP/%s\" %d\n", - STR_LOG_ALLOC(src_addr), - STR_LOG_ALLOC(ri->request_method), - STR_LOG_ALLOC(ri->request_uri), - (ri->query_string == NULL) ? log_strdup("?") : log_strdup(""), - STR_LOG_ALLOC(ri->query_string), - STR_LOG_ALLOC(ri->http_version), - conn->status_code); -} diff --git a/samples/net/civetweb/common/include/external_mg_cry_internal_impl.inl b/samples/net/civetweb/common/include/external_mg_cry_internal_impl.inl deleted file mode 100644 index 07f1a7079952e3..00000000000000 --- a/samples/net/civetweb/common/include/external_mg_cry_internal_impl.inl +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2019 Antmicro Ltd - * Copyright (c) 2020 Alexander Kozhinov - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -LOG_MODULE_REGISTER(mg_cry_internal_impl, LOG_LEVEL_DBG); - -#include "helper.h" - -static void mg_cry_internal_impl(const struct mg_connection *conn, - const char *func, - unsigned line, - const char *fmt, - va_list ap) -{ - (void)conn; - - LOG_ERR("%s @ %d in civetweb.c", STR_LOG_ALLOC(func), line); - vprintf(fmt, ap); -} diff --git a/samples/net/civetweb/common/include/helper.h b/samples/net/civetweb/common/include/helper.h deleted file mode 100644 index f01b5436b94c04..00000000000000 --- a/samples/net/civetweb/common/include/helper.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2020 Alexander Kozhinov Mail: - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __HELPER__ -#define __HELPER__ - -#include - -#define STR_LOG_ALLOC(str) ((str == NULL) ? log_strdup("null") :\ - log_strdup(str)) - -#endif /* __HELPER__ */ diff --git a/samples/net/civetweb/common/include/libc_extensions.h b/samples/net/civetweb/common/include/libc_extensions.h deleted file mode 100644 index 54b8cd4354869e..00000000000000 --- a/samples/net/civetweb/common/include/libc_extensions.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2019 Antmicro Ltd - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include - -#define pollfd zsock_pollfd -#define fcntl zsock_fcntl - -#define POLLIN ZSOCK_POLLIN -#define POLLOUT ZSOCK_POLLOUT - -#define addrinfo zsock_addrinfo - -#define F_SETFD 2 -#define FD_CLOEXEC 1 - -size_t strcspn(const char *s1, const char *s2); -size_t strspn(const char *s1, const char *s2); -int iscntrl(int c); - -double atof(const char *str); -int sscanf(const char *s, const char *format, ...); -char *strerror(int err); - -time_t time(time_t *t); -struct tm *gmtime(const time_t *ptime); -size_t strftime(char *dst, size_t dst_size, const char *fmt, - const struct tm *tm); -double difftime(time_t end, time_t beg); -struct tm *localtime(const time_t *timer); - -int fileno(FILE *stream); -int ferror(FILE *stream); -int fclose(FILE *stream); -int fseeko(FILE *stream, off_t offset, int whence); -FILE *fopen(const char *filename, const char *mode); -char *fgets(char *str, int num, FILE *stream); -size_t fread(void *ptr, size_t size, size_t count, FILE *stream); -int remove(const char *filename); - -int getsockname(int sock, struct sockaddr *addr, socklen_t *addrlen); -int poll(struct zsock_pollfd *fds, int nfds, int timeout); - -int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, - char *host, socklen_t hostlen, - char *serv, socklen_t servlen, int flags); - -ssize_t send(int sock, const void *buf, size_t len, int flags); -ssize_t recv(int sock, void *buf, size_t max_len, int flags); -int socket(int family, int type, int proto); -int getaddrinfo(const char *host, const char *service, - const struct zsock_addrinfo *hints, - struct zsock_addrinfo **res); - -void freeaddrinfo(struct zsock_addrinfo *ai); -int connect(int sock, const struct sockaddr *addr, socklen_t addrlen); -int getsockopt(int sock, int level, int optname, - void *optval, socklen_t *optlen); -int setsockopt(int sock, int level, int optname, - const void *optval, socklen_t optlen); -int listen(int sock, int backlog); -int accept(int sock, struct sockaddr *addr, socklen_t *addrlen); -int bind(int sock, const struct sockaddr *addr, socklen_t addrlen); diff --git a/samples/net/civetweb/common/src/libc_extensions.c b/samples/net/civetweb/common/src/libc_extensions.c deleted file mode 100644 index adb26bd2418860..00000000000000 --- a/samples/net/civetweb/common/src/libc_extensions.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 2019 Antmicro Ltd - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -LOG_MODULE_REGISTER(lib_extensions, LOG_LEVEL_DBG); - -#include -#include -#include -#include - -#include "libc_extensions.h" - -#define FN_MISSING() LOG_DBG("[IMPLEMENTATION MISSING : %s]\n", __func__) - -int iscntrl(int c) -{ - /* All the characters placed before the space on the ASCII table - * and the 0x7F character (DEL) are control characters. - */ - return (int)(c < ' ' || c == 0x7F); -} - -size_t strftime(char *dst, size_t dst_size, - const char *fmt, - const struct tm *tm) -{ - FN_MISSING(); - - return 0; -} - -double difftime(time_t end, time_t beg) -{ - return end - beg; -} - -struct __strerr_wrap { - int err; - const char *errstr; -}; - -/* Implementation suggested by @rakons in #16527 */ -#define STRERR_DEFINE(e) {e, #e} - -static const struct __strerr_wrap error_strings[] = { - STRERR_DEFINE(EILSEQ), - STRERR_DEFINE(EDOM), - STRERR_DEFINE(ERANGE), - STRERR_DEFINE(ENOTTY), - STRERR_DEFINE(EACCES), - STRERR_DEFINE(EPERM), - STRERR_DEFINE(ENOENT), - STRERR_DEFINE(ESRCH), - STRERR_DEFINE(EEXIST), - STRERR_DEFINE(ENOSPC), - STRERR_DEFINE(ENOMEM), - STRERR_DEFINE(EBUSY), - STRERR_DEFINE(EINTR), - STRERR_DEFINE(EAGAIN), - STRERR_DEFINE(ESPIPE), - STRERR_DEFINE(EXDEV), - STRERR_DEFINE(EROFS), - STRERR_DEFINE(ENOTEMPTY), - STRERR_DEFINE(ECONNRESET), - STRERR_DEFINE(ETIMEDOUT), - STRERR_DEFINE(ECONNREFUSED), - STRERR_DEFINE(EHOSTDOWN), - STRERR_DEFINE(EHOSTUNREACH), - STRERR_DEFINE(EADDRINUSE), - STRERR_DEFINE(EPIPE), - STRERR_DEFINE(EIO), - STRERR_DEFINE(ENXIO), - STRERR_DEFINE(ENOTBLK), - STRERR_DEFINE(ENODEV), - STRERR_DEFINE(ENOTDIR), - STRERR_DEFINE(EISDIR), - STRERR_DEFINE(ETXTBSY), - STRERR_DEFINE(ENOEXEC), - STRERR_DEFINE(EINVAL), - STRERR_DEFINE(E2BIG), - STRERR_DEFINE(ELOOP), - STRERR_DEFINE(ENAMETOOLONG), - STRERR_DEFINE(ENFILE), - STRERR_DEFINE(EMFILE), - STRERR_DEFINE(EBADF), - STRERR_DEFINE(ECHILD), - STRERR_DEFINE(EFAULT), - STRERR_DEFINE(EFBIG), - STRERR_DEFINE(EMLINK), - STRERR_DEFINE(ENOLCK), - STRERR_DEFINE(EDEADLK), - STRERR_DEFINE(ECANCELED), - STRERR_DEFINE(ENOSYS), - STRERR_DEFINE(ENOMSG), - STRERR_DEFINE(ENOSTR), - STRERR_DEFINE(ENODATA), - STRERR_DEFINE(ETIME), - STRERR_DEFINE(ENOSR), - STRERR_DEFINE(EPROTO), - STRERR_DEFINE(EBADMSG), - STRERR_DEFINE(ENOTSOCK), - STRERR_DEFINE(EDESTADDRREQ), - STRERR_DEFINE(EMSGSIZE), - STRERR_DEFINE(EPROTOTYPE), - STRERR_DEFINE(ENOPROTOOPT), - STRERR_DEFINE(EPROTONOSUPPORT), - STRERR_DEFINE(ESOCKTNOSUPPORT), - STRERR_DEFINE(ENOTSUP), - STRERR_DEFINE(EPFNOSUPPORT), - STRERR_DEFINE(EAFNOSUPPORT), - STRERR_DEFINE(EADDRNOTAVAIL), - STRERR_DEFINE(ENETDOWN), - STRERR_DEFINE(ENETUNREACH), - STRERR_DEFINE(ENETRESET), - STRERR_DEFINE(ECONNABORTED), - STRERR_DEFINE(ENOBUFS), - STRERR_DEFINE(EISCONN), - STRERR_DEFINE(ENOTCONN), - STRERR_DEFINE(ESHUTDOWN), - STRERR_DEFINE(EALREADY), - STRERR_DEFINE(EINPROGRESS), -}; - -static char *strerr_unknown = "UNKNOWN"; - -char *strerror(int err) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(error_strings); ++i) { - if (error_strings[i].err == err) { - return (char *)error_strings[i].errstr; - } - } - - return strerr_unknown; -} - -int sscanf(const char *s, const char *format, ...) -{ - FN_MISSING(); - - return 0; -} - -double atof(const char *str) -{ - /* XXX good enough for civetweb uses */ - return (double)atoi(str); -} - -/* - * Most of the wrappers below are copies of the wrappers in net/sockets.h, - * but they are available only if CONFIG_NET_SOCKETS_POSIX_NAMES is enabled - * which is impossible here. - */ - -int getsockname(int sock, struct sockaddr *addr, - socklen_t *addrlen) -{ - return zsock_getsockname(sock, addr, addrlen); -} - -int poll(struct zsock_pollfd *fds, int nfds, int timeout) -{ - return zsock_poll(fds, nfds, timeout); -} - -int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, - char *host, socklen_t hostlen, - char *serv, socklen_t servlen, int flags) -{ - return zsock_getnameinfo(addr, addrlen, host, hostlen, - serv, servlen, flags); -} - -ssize_t send(int sock, const void *buf, size_t len, int flags) -{ - return zsock_send(sock, buf, len, flags); -} - -ssize_t recv(int sock, void *buf, size_t max_len, int flags) -{ - return zsock_recv(sock, buf, max_len, flags); -} - -int socket(int family, int type, int proto) -{ - return zsock_socket(family, type, proto); -} - -int getaddrinfo(const char *host, const char *service, - const struct zsock_addrinfo *hints, - struct zsock_addrinfo **res) -{ - return zsock_getaddrinfo(host, service, hints, res); -} - -void freeaddrinfo(struct zsock_addrinfo *ai) -{ - zsock_freeaddrinfo(ai); -} - -int connect(int sock, const struct sockaddr *addr, - socklen_t addrlen) -{ - return zsock_connect(sock, addr, addrlen); -} - -int getsockopt(int sock, int level, int optname, - void *optval, socklen_t *optlen) -{ - return zsock_getsockopt(sock, level, optname, optval, optlen); -} - -int setsockopt(int sock, int level, int optname, - const void *optval, socklen_t optlen) -{ - return zsock_setsockopt(sock, level, optname, optval, optlen); -} - -int listen(int sock, int backlog) -{ - return zsock_listen(sock, backlog); -} - -int bind(int sock, const struct sockaddr *addr, socklen_t addrlen) -{ - return zsock_bind(sock, addr, addrlen); -} - -int accept(int sock, struct sockaddr *addr, socklen_t *addrlen) -{ - return zsock_accept(sock, addr, addrlen); -} diff --git a/samples/net/civetweb/http_server/CMakeLists.txt b/samples/net/civetweb/http_server/CMakeLists.txt deleted file mode 100644 index 6a05bbcd4be015..00000000000000 --- a/samples/net/civetweb/http_server/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) 2020 Alexander Kozhinov -# Mail: AlexanderKozhinov@yandex.com -# -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/../common) -set(common_src_dir ${common_dir}/src) -set(common_include_dir ${common_dir}/include) - -include_directories( - ${common_include_dir} -) - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(civetweb_http_server) - -target_sources(app PRIVATE - src/main.c - ${common_src_dir}/libc_extensions.c -) diff --git a/samples/net/civetweb/http_server/README.rst b/samples/net/civetweb/http_server/README.rst deleted file mode 100644 index 6a5741e2376afe..00000000000000 --- a/samples/net/civetweb/http_server/README.rst +++ /dev/null @@ -1,48 +0,0 @@ -.. _civetweb-http_server-sample: - -Civetweb sample -############### - -Overview -******** - -This sample application uses the HTTP APIs provided by the external `Civetweb `_ module to create an HTTP server demonstrating selected Civetweb features. -The Civetweb module is available as a west :ref:`module `. - -The source code for this sample application can be found at: -:zephyr_file:`samples/net/civetweb/http_server`. - -Requirements -************ - -- A board with hardware networking -- The Civetweb module (made available via west) - -Building and Running -******************** - -This sample was tested on the Atmel SAM E70 Xplained board, so this is the recommended target. - -Build it with: - -.. zephyr-app-commands:: - :zephyr-app: samples/net/civetweb/http_server - :board: sam_e70_xplained - :goals: build - :compact: - -The sample application uses a static IP configuration. - -After flashing the board, the server can be accessed with the web browser of your choice at ``192.0.2.1:8080``. - -The sample does not serve any files like HTTP (it does not use any filesystem). -Instead it serves the following three URLs: - -- ``/`` - a basic hello world handler -- ``/info`` - shows OS information, uses the JSON format to achieve that -- ``/history`` - demonstrates the usage of cookies - -A regular 404 status code is returned when trying to access any other URL. - -The IP configuration can be changed in Zephyr config. -The default port can be changed in the sources of the sample. diff --git a/samples/net/civetweb/http_server/prj.conf b/samples/net/civetweb/http_server/prj.conf deleted file mode 100644 index 3b80108a67bc77..00000000000000 --- a/samples/net/civetweb/http_server/prj.conf +++ /dev/null @@ -1,36 +0,0 @@ -# General config -CONFIG_CIVETWEB=y -CONFIG_JSON_LIBRARY=y - -# pthreads -CONFIG_POSIX_API=y -CONFIG_PTHREAD_IPC=y -CONFIG_POSIX_MQUEUE=y - -# networking -CONFIG_NETWORKING=y -CONFIG_NET_IPV4=y -# CONFIG_NET_IPV6 is not set -CONFIG_NET_TCP=y -CONFIG_NET_SOCKETS=y -CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=16384 -CONFIG_NET_TX_STACK_SIZE=2048 -CONFIG_NET_RX_STACK_SIZE=2048 -CONFIG_ISR_STACK_SIZE=2048 -CONFIG_MAIN_STACK_SIZE=2048 -CONFIG_IDLE_STACK_SIZE=1024 - -CONFIG_DNS_RESOLVER=y - -CONFIG_NET_CONFIG_SETTINGS=y -CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" -CONFIG_NET_CONFIG_MY_IPV4_NETMASK="255.255.255.0" -CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" -CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2" - -# logging -CONFIG_NET_LOG=y - -# Do not include mbedtls via this option as civetweb does not -# work properly with mbedtls. -CONFIG_NET_TCP_ISN_RFC6528=n diff --git a/samples/net/civetweb/http_server/sample.yaml b/samples/net/civetweb/http_server/sample.yaml deleted file mode 100644 index 79ba0eaf8e65c4..00000000000000 --- a/samples/net/civetweb/http_server/sample.yaml +++ /dev/null @@ -1,13 +0,0 @@ -sample: - description: Civetweb HTTP API sample - name: http_server -tests: - sample.net.civetweb.http_server: - modules: - - civetweb - harness: net - arch_exclude: posix - depends_on: netif - filter: CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR - integration_platforms: - - sam_e70_xplained diff --git a/samples/net/civetweb/http_server/src/main.c b/samples/net/civetweb/http_server/src/main.c deleted file mode 100644 index 35cb03831e97df..00000000000000 --- a/samples/net/civetweb/http_server/src/main.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2019 Antmicro Ltd - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include "civetweb.h" - -#define HTTP_PORT 8080 -#define HTTPS_PORT 4443 - -#define CIVETWEB_MAIN_THREAD_STACK_SIZE CONFIG_MAIN_STACK_SIZE - -/* Use smallest possible value of 1024 (see the line 18619 of civetweb.c) */ -#define MAX_REQUEST_SIZE_BYTES 1024 - -K_THREAD_STACK_DEFINE(civetweb_stack, CIVETWEB_MAIN_THREAD_STACK_SIZE); - -struct civetweb_info { - const char *version; - const char *os; - uint32_t features; - const char *feature_list; - const char *build; - const char *compiler; - const char *data_model; -}; - -#define FIELD(struct_, member_, type_) { \ - .field_name = #member_, \ - .field_name_len = sizeof(#member_) - 1, \ - .offset = offsetof(struct_, member_), \ - .type = type_ \ -} - -void send_ok(struct mg_connection *conn) -{ - mg_printf(conn, - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" - "Connection: close\r\n\r\n"); -} - -int hello_world_handler(struct mg_connection *conn, void *cbdata) -{ - send_ok(conn); - mg_printf(conn, ""); - mg_printf(conn, "

Hello World from Zephyr!

"); - mg_printf(conn, "See also:\n"); - mg_printf(conn, "\n"); - mg_printf(conn, "\n"); - - return 200; -} - -int system_info_handler(struct mg_connection *conn, void *cbdata) -{ - static const struct json_obj_descr descr[] = { - FIELD(struct civetweb_info, version, JSON_TOK_STRING), - FIELD(struct civetweb_info, os, JSON_TOK_STRING), - FIELD(struct civetweb_info, feature_list, JSON_TOK_STRING), - FIELD(struct civetweb_info, build, JSON_TOK_STRING), - FIELD(struct civetweb_info, compiler, JSON_TOK_STRING), - FIELD(struct civetweb_info, data_model, JSON_TOK_STRING), - }; - - struct civetweb_info info = {}; - char info_str[1024] = {}; - int ret; - int size; - - size = mg_get_system_info(info_str, sizeof(info_str)); - - ret = json_obj_parse(info_str, size, descr, ARRAY_SIZE(descr), &info); - - send_ok(conn); - - if (ret < 0) { - mg_printf(conn, "Could not retrieve: %d\n", ret); - return 500; - } - - - mg_printf(conn, ""); - - mg_printf(conn, "

Server info

"); - mg_printf(conn, "
    \n"); - mg_printf(conn, "
  • host os - %s
  • \n", info.os); - mg_printf(conn, "
  • server - civetweb %s
  • \n", info.version); - mg_printf(conn, "
  • compiler - %s
  • \n", info.compiler); - mg_printf(conn, "
  • board - %s
  • \n", CONFIG_BOARD); - mg_printf(conn, "
\n"); - - mg_printf(conn, "\n"); - - return 200; -} - -int history_handler(struct mg_connection *conn, void *cbdata) -{ - const struct mg_request_info *req_info = mg_get_request_info(conn); - const char *cookie = mg_get_header(conn, "Cookie"); - char history_str[64]; - - mg_get_cookie(cookie, "history", history_str, sizeof(history_str)); - - mg_printf(conn, "HTTP/1.1 200 OK\r\n"); - mg_printf(conn, "Connection: close\r\n"); - mg_printf(conn, "Set-Cookie: history='%s'\r\n", req_info->local_uri); - mg_printf(conn, "Content-Type: text/html\r\n\r\n"); - - mg_printf(conn, ""); - - mg_printf(conn, "

Your URI is: %s

\n", req_info->local_uri); - - if (history_str[0] == 0) { - mg_printf(conn, "

This is your first visit.
\n"); - } else { - mg_printf(conn, "
your last /history visit was: %s
\n", - history_str); - } - - mg_printf(conn, "Some cookie-saving links to try:\n"); - mg_printf(conn, "
    \n"); - mg_printf(conn, "
  • first
  • \n"); - mg_printf(conn, "
  • second
  • \n"); - mg_printf(conn, "
  • third
  • \n"); - mg_printf(conn, "
  • fourth
  • \n"); - mg_printf(conn, "
  • fifth
  • \n"); - mg_printf(conn, "
\n"); - - mg_printf(conn, "\n"); - - return 200; -} - -void *main_pthread(void *arg) -{ - static const char * const options[] = { - "listening_ports", - STRINGIFY(HTTP_PORT), - "num_threads", - "1", - "max_request_size", - STRINGIFY(MAX_REQUEST_SIZE_BYTES), - NULL - }; - - struct mg_callbacks callbacks; - struct mg_context *ctx; - - (void)arg; - - memset(&callbacks, 0, sizeof(callbacks)); - ctx = mg_start(&callbacks, 0, (const char **)options); - - if (ctx == NULL) { - printf("Unable to start the server."); - return 0; - } - - mg_set_request_handler(ctx, "/$", hello_world_handler, 0); - mg_set_request_handler(ctx, "/info$", system_info_handler, 0); - mg_set_request_handler(ctx, "/history", history_handler, 0); - - return 0; -} - -void main(void) -{ - pthread_attr_t civetweb_attr; - pthread_t civetweb_thread; - - (void)pthread_attr_init(&civetweb_attr); - (void)pthread_attr_setstack(&civetweb_attr, &civetweb_stack, - CIVETWEB_MAIN_THREAD_STACK_SIZE); - - (void)pthread_create(&civetweb_thread, &civetweb_attr, - &main_pthread, 0); -} diff --git a/samples/net/civetweb/websocket_server/CMakeLists.txt b/samples/net/civetweb/websocket_server/CMakeLists.txt deleted file mode 100644 index 022e3607628412..00000000000000 --- a/samples/net/civetweb/websocket_server/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (c) 2020 Alexander Kozhinov -# -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/../common) -set(common_src_dir ${common_dir}/src) -set(common_include_dir ${common_dir}/include) - -set(inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include) -set(src_dir ${CMAKE_CURRENT_SOURCE_DIR}/src) - -include_directories( - ${inc_dir} - ${common_include_dir} -) - -option(CIVETWEB_ENABLE_WEBSOCKETS "Enable websockets connections" ON) - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(civetweb_websocket_server) - -target_sources(app PRIVATE - ${src_dir}/main.c - ${common_src_dir}/libc_extensions.c - ${src_dir}/http_server_handlers.c - ${src_dir}/websocket_server_handlers.c) - -set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/) -set(web_page_dir web_page) - -file(MAKE_DIRECTORY ${gen_dir}/${web_page_dir}) - -# List of files that are used to generate .h file that can be included -# into .c file. -foreach(inc_file - ${web_page_dir}/index.html - ${web_page_dir}/index.css - ${web_page_dir}/ws.js) - - # Generate normal and gzipped versions of each file: - generate_inc_file_for_target(app - ${inc_file} - ${gen_dir}/${inc_file}.inc) - - generate_inc_file_for_target(app - ${inc_file} - ${gen_dir}/${inc_file}.gz.inc - --gzip) - -endforeach() - -include(${ZEPHYR_BASE}/samples/net/common/common.cmake) diff --git a/samples/net/civetweb/websocket_server/README.rst b/samples/net/civetweb/websocket_server/README.rst deleted file mode 100644 index f9c731208f5880..00000000000000 --- a/samples/net/civetweb/websocket_server/README.rst +++ /dev/null @@ -1,64 +0,0 @@ -.. _civetweb-websocket-server-sample: - -Civetweb WebSocket Server sample -################################ - -Overview -******** - -This sample application uses the HTTP APIs provided by the external -`Civetweb `_ module to create an WebSocket -server demonstrating selected Civetweb features. -The Civetweb module is available as a west :ref:`module `. - -The source code for this sample application can be found at: -:zephyr_file:`samples/net/civetweb/websocket_server`. - -Requirements -************ - -- A board with hardware networking -- The Civetweb module (made available via west) - -Building and Running -******************** - -This sample was tested on the NUCLEO H745ZI-Q board, so this is the recommended target. - -Build it with: - -.. zephyr-app-commands:: - :zephyr-app: samples/net/civetweb/websocket_server - :board: nucleo_h745zi_q_m7 - :goals: build - :compact: - -The sample application uses a static IP configuration. - -After flashing the board, the server can be accessed with the web browser -of your choice (preferably Chrome) under ``192.0.2.1`` IPv4 address. -The IP address can be changed in :zephyr_file:`samples/net/civetweb/websocket_server/prj.conf` -The port number can be changed in :zephyr_file:`samples/net/civetweb/websocket_server/main.c` - -This sample application consists of two main parts: - -- **HTTP Server** - ``http://192.0.2.1:8080`` or ``http://192.0.2.1:8080/index.html`` It is needed to serve application's main page and its dependencies. -- **WebSocket Server** - ``ws://192.0.2.1:8080/ws``. It is an echo server, which sends received data enclosed in **board name** and a string **too!** back. - -The **HTTP Server*** serves following statically allocated files -(*no file system is present*): - -- ``/`` - main application page (redirects requests to ``/index.html``) -- ``/index.html`` - main application page -- ``/index.css`` - main application page style sheet -- ``/ws.js`` - WebSocket client JavaScript - -A regular 404 status code is returned when trying to access other links. - -The **WebSocket Server** works as follows: - -Calling the ``http://192.0.2.1:8080`` in your browser provides WebSocket -client JavaScript load. This script establishes the connection to the WebSocket -server running on your board. -Putting some message in ```Message Text``` window and pressing *Send* button generates -predefined answer from WebSocket server printed in log window. diff --git a/samples/net/civetweb/websocket_server/include/http_server_handlers.h b/samples/net/civetweb/websocket_server/include/http_server_handlers.h deleted file mode 100644 index 97f481f1acfd57..00000000000000 --- a/samples/net/civetweb/websocket_server/include/http_server_handlers.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2020 Alexander Kozhinov Mail: - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __HTTP_SERVER_HANDLERS__ -#define __HTTP_SERVER_HANDLERS__ - -#include "civetweb.h" - -void init_http_server_handlers(struct mg_context *ctx); - -#endif /* __HTTP_SERVER_HANDLERS__ */ diff --git a/samples/net/civetweb/websocket_server/include/websocket_server_handlers.h b/samples/net/civetweb/websocket_server/include/websocket_server_handlers.h deleted file mode 100644 index 6fe30acf747e61..00000000000000 --- a/samples/net/civetweb/websocket_server/include/websocket_server_handlers.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2020 Alexander Kozhinov - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __WEBSOCKET_SERVER_HANDLERS__ -#define __WEBSOCKET_SERVER_HANDLERS__ - -#include "civetweb.h" - -void init_websocket_server_handlers(struct mg_context *ctx); - -#endif /* __WEBSOCKET_SERVER_HANDLERS__ */ diff --git a/samples/net/civetweb/websocket_server/prj.conf b/samples/net/civetweb/websocket_server/prj.conf deleted file mode 100644 index da9717702d494a..00000000000000 --- a/samples/net/civetweb/websocket_server/prj.conf +++ /dev/null @@ -1,39 +0,0 @@ -# General config -CONFIG_CIVETWEB=y - -# pthreads -CONFIG_POSIX_API=y -CONFIG_PTHREAD_IPC=y -CONFIG_POSIX_MQUEUE=y - -# networking -CONFIG_NETWORKING=y -CONFIG_NET_IPV4=y -# CONFIG_NET_IPV6 is not set -CONFIG_NET_TCP=y -CONFIG_NET_SOCKETS=y - -CONFIG_DNS_RESOLVER=y - -CONFIG_NET_CONFIG_SETTINGS=y -CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" -CONFIG_NET_CONFIG_MY_IPV4_NETMASK="255.255.255.0" -CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" -CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2" - -# memory settings: -CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=16384 -CONFIG_NET_TX_STACK_SIZE=2048 -CONFIG_NET_RX_STACK_SIZE=2048 - -CONFIG_ISR_STACK_SIZE=2048 -CONFIG_MAIN_STACK_SIZE=2048 -CONFIG_IDLE_STACK_SIZE=1024 - -# logging: -CONFIG_LOG=y -# CONFIG_NET_LOG=y - -# Do not include mbedtls via this option as civetweb does not -# work properly with mbedtls. -CONFIG_NET_TCP_ISN_RFC6528=n diff --git a/samples/net/civetweb/websocket_server/sample.yaml b/samples/net/civetweb/websocket_server/sample.yaml deleted file mode 100644 index 18af3024b91535..00000000000000 --- a/samples/net/civetweb/websocket_server/sample.yaml +++ /dev/null @@ -1,8 +0,0 @@ -sample: - description: Civetweb WebSocket Server sample - name: websocket_server -tests: - sample.net.civetweb.websocket_server: - modules: - - civetweb - platform_allow: nucleo_h745zi_q_m7 diff --git a/samples/net/civetweb/websocket_server/src/http_server_handlers.c b/samples/net/civetweb/websocket_server/src/http_server_handlers.c deleted file mode 100644 index 8531861c2cd377..00000000000000 --- a/samples/net/civetweb/websocket_server/src/http_server_handlers.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2020 Alexander Kozhinov - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -LOG_MODULE_REGISTER(http_server_handlers, LOG_LEVEL_DBG); - -#include "http_server_handlers.h" - -#define TX_CHUNK_SIZE_BYTES CONFIG_NET_TX_STACK_SIZE - -#define URL_MAIN "/$" -#define URL_INDEX_CSS "/index.css" -#define URL_INDEX_HTML "/index.html" -#define URL_FAVICON_ICO "/favicon.ico" -#define URL_WS_JS "/ws.js" - -#define HTTP_TEXT_HTML "text/html" -#define HTTP_TEXT_CSS "text/css" -#define HTTP_TEXT_JS "text/javascript" -#define HTTP_EOFL "\r\n" /* http end of line */ - -#define HTTP_CONTEND_ENCODING "Content-Encoding: " -#define HTTP_ENCODING_GZ "gzip" - -#define __code_decl /* static */ -#define __data_decl static - -__code_decl void this_register_handlers(struct mg_context *ctx); - -__code_decl int this_send_buffer_chunked(struct mg_connection *conn, - const char *mime_type, - const char *buff, - const size_t buff_len); - -__code_decl int this_redirect_2_index_html(struct mg_connection *conn, - void *cbdata); -__code_decl int this_index_html_handler(struct mg_connection *conn, - void *cbdata); -__code_decl int this_index_css_handler(struct mg_connection *conn, - void *cbdata); -__code_decl int this_ws_js_handler(struct mg_connection *conn, - void *cbdata); -__code_decl int this_favicon_ico_handler(struct mg_connection *conn, - void *cbdata); - -__code_decl void this_set_return_value(int *ret_val); - -void init_http_server_handlers(struct mg_context *ctx) -{ - this_register_handlers(ctx); -} - -__code_decl void this_register_handlers(struct mg_context *ctx) -{ - mg_set_request_handler(ctx, URL_MAIN, - this_redirect_2_index_html, NULL); - mg_set_request_handler(ctx, URL_INDEX_HTML, - this_index_html_handler, NULL); - mg_set_request_handler(ctx, URL_INDEX_CSS, - this_index_css_handler, NULL); - mg_set_request_handler(ctx, URL_WS_JS, - this_ws_js_handler, NULL); - mg_set_request_handler(ctx, URL_FAVICON_ICO, - this_favicon_ico_handler, NULL); -} - -__code_decl int this_send_buffer_chunked(struct mg_connection *conn, - const char *mime_type, - const char *buff, - const size_t buff_len) -{ - int ret = 0; - - ret = mg_send_http_ok(conn, mime_type, -1); - if (ret < 0) { - goto error_this_send_buffer_chunked; - } - - long left_bytes = buff_len; - char *itr = (char *)buff; /* buffer iterator */ - - LOG_DBG("Transferring:"); - LOG_DBG("itr: 0x%08X ret: %d left_bytes: %ld chunk_size: %zd B", - (unsigned int)itr, ret, left_bytes, TX_CHUNK_SIZE_BYTES); - - while (left_bytes > TX_CHUNK_SIZE_BYTES) { - ret = mg_send_chunk(conn, itr, TX_CHUNK_SIZE_BYTES); - itr += TX_CHUNK_SIZE_BYTES; - left_bytes -= TX_CHUNK_SIZE_BYTES; - - LOG_DBG("itr: 0x%08X ret: %d left_bytes: %ld", - (unsigned int)itr, ret, left_bytes); - - if (ret < 0) { - goto error_this_send_buffer_chunked; - } - } - - if (left_bytes > 0) { - ret = mg_send_chunk(conn, itr, left_bytes); - itr += left_bytes; - left_bytes = 0; - - LOG_DBG("itr: 0x%08X ret: %d left_bytes: %ld", - (unsigned int)itr, ret, left_bytes); - - if (ret < 0) { - goto error_this_send_buffer_chunked; - } - } - - /* Must be sent at the end of the chunked sequence */ - ret = mg_send_chunk(conn, "", 0); - -error_this_send_buffer_chunked: - if (ret < 0) { - LOG_ERR("aborted! ret: %d", ret); - } - - return ret; -} - -__code_decl int this_redirect_2_index_html(struct mg_connection *conn, - void *cbdata) -{ - int ret = 0; - - ret = mg_send_http_redirect(conn, URL_INDEX_HTML, 303); - return 202; -} - -__code_decl int this_index_html_handler(struct mg_connection *conn, - void *cbdata) -{ - __data_decl const char index_html[] = { -#include "web_page/index.html.gz.inc" - }; - - int ret = 0; - - ret = this_send_buffer_chunked(conn, HTTP_TEXT_HTML - HTTP_EOFL - HTTP_CONTEND_ENCODING - HTTP_ENCODING_GZ, - index_html, sizeof(index_html)); - this_set_return_value(&ret); - return ret; -} - -__code_decl int this_index_css_handler(struct mg_connection *conn, void *cbdata) -{ - __data_decl const char index_css[] = { -#include "web_page/index.css.gz.inc" - }; - - int ret = 0; - - ret = this_send_buffer_chunked(conn, HTTP_TEXT_CSS - HTTP_EOFL - HTTP_CONTEND_ENCODING - HTTP_ENCODING_GZ, - index_css, sizeof(index_css)); - this_set_return_value(&ret); - return ret; -} - -__code_decl int this_ws_js_handler(struct mg_connection *conn, void *cbdata) -{ - __data_decl const char ws_js[] = { -#include "web_page/ws.js.gz.inc" - }; - - int ret = 0; - - ret = this_send_buffer_chunked(conn, HTTP_TEXT_JS - HTTP_EOFL - HTTP_CONTEND_ENCODING - HTTP_ENCODING_GZ, - ws_js, sizeof(ws_js)); - this_set_return_value(&ret); - return ret; -} - -__code_decl int this_favicon_ico_handler(struct mg_connection *conn, - void *cbdata) -{ - int ret = 404; - return ret; /* should fail */ -} - -__code_decl void this_set_return_value(int *ret_val) -{ - if (*ret_val < 0) { - *ret_val = 404; /* 404 - HTTP FAIL or 0 - handler fail */ - } else { - *ret_val = 200; /* 200 - HTTP OK*/ - } -} diff --git a/samples/net/civetweb/websocket_server/src/main.c b/samples/net/civetweb/websocket_server/src/main.c deleted file mode 100644 index e68da06f7c801c..00000000000000 --- a/samples/net/civetweb/websocket_server/src/main.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2020 Alexander Kozhinov - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG); - -#include -#include - -#include "civetweb.h" - -#include "http_server_handlers.h" -#include "websocket_server_handlers.h" - -#define HTTP_PORT 8080 -#define HTTPS_PORT 4443 - -#define CIVETWEB_MAIN_THREAD_STACK_SIZE CONFIG_MAIN_STACK_SIZE - -/* Use smallest possible value of 1024 (see the line 18619 of civetweb.c) */ -#define MAX_REQUEST_SIZE_BYTES 1024 - -K_THREAD_STACK_DEFINE(civetweb_stack, CIVETWEB_MAIN_THREAD_STACK_SIZE); - -void *main_pthread(void *arg) -{ - static const char * const options[] = { - "listening_ports", STRINGIFY(HTTP_PORT), - "num_threads", "1", - "max_request_size", STRINGIFY(MAX_REQUEST_SIZE_BYTES), - NULL - }; - - struct mg_callbacks callbacks; - struct mg_context *ctx; - - (void)arg; - - memset(&callbacks, 0, sizeof(callbacks)); - ctx = mg_start(&callbacks, NULL, (const char **)options); - - if (ctx == NULL) { - LOG_ERR("Unable to start the server\n"); - return 0; - } - - init_http_server_handlers(ctx); - init_websocket_server_handlers(ctx); - - return 0; -} - -void main(void) -{ - pthread_attr_t civetweb_attr; - pthread_t civetweb_thread; - - (void)pthread_attr_init(&civetweb_attr); - (void)pthread_attr_setstack(&civetweb_attr, &civetweb_stack, - CIVETWEB_MAIN_THREAD_STACK_SIZE); - - (void)pthread_create(&civetweb_thread, &civetweb_attr, - &main_pthread, 0); - - LOG_INF("WebSocket Server was started!"); -} diff --git a/samples/net/civetweb/websocket_server/src/websocket_server_handlers.c b/samples/net/civetweb/websocket_server/src/websocket_server_handlers.c deleted file mode 100644 index eaf3b5b78c3441..00000000000000 --- a/samples/net/civetweb/websocket_server/src/websocket_server_handlers.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2020 Alexander Kozhinov - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -LOG_MODULE_REGISTER(websocket_server_handlers, LOG_LEVEL_DBG); - -#include "websocket_server_handlers.h" - -#define BOARD_REPLY_PREFIX CONFIG_BOARD" says: " -#define BOARD_REPLY_PREFIX_LEN sizeof(BOARD_REPLY_PREFIX) - -#define BOARD_REPLY_SUFFIX " too!" -#define BOARD_REPLY_SUFFIX_LEN sizeof(BOARD_REPLY_SUFFIX) - -#define BOARD_REPLY_TOAL_LEN (BOARD_REPLY_PREFIX_LEN +\ - BOARD_REPLY_SUFFIX_LEN) - -#define FIN_SHIFT 7u -#define RSV1_SHIFT 6u -#define RSV2_SHIFT 5u -#define RSV3_SHIFT 4u -#define OPCODE_SHIFT 0u - -#define BOOL_MASK 0x1 /* boolean value mask */ -#define HALF_BYTE_MASK 0xF /* half byte value mask */ - -#define WS_URL "/ws" /* WebSocket server main url */ - -#define __code_decl /* static */ -#define __data_decl static - -/* Websocket server handlers: */ -__code_decl int this_connect_handler(const struct mg_connection *conn, - void *cbdata); -__code_decl void this_ready_handler(struct mg_connection *conn, void *cbdata); -__code_decl int this_data_handler(struct mg_connection *conn, int bits, - char *data, size_t data_len, void *cbdata); -__code_decl void this_close_handler(const struct mg_connection *conn, - void *cbdata); - -void init_websocket_server_handlers(struct mg_context *ctx) -{ - mg_set_websocket_handler(ctx, WS_URL, - this_connect_handler, - this_ready_handler, - this_data_handler, - this_close_handler, - NULL); -} - -__code_decl int this_connect_handler(const struct mg_connection *conn, - void *cbdata) -{ - int ret_val = 0; - return ret_val; -} - -__code_decl void this_ready_handler(struct mg_connection *conn, void *cbdata) -{ -} - -__code_decl int this_data_handler(struct mg_connection *conn, int bits, - char *data, size_t data_len, void *cbdata) -{ - int ret_state = 1; - - /* Encode bits as by https://tools.ietf.org/html/rfc6455#section-5.2: */ - const bool FIN = (bits >> FIN_SHIFT) & BOOL_MASK; - const bool RSV1 = (bits >> RSV1_SHIFT) & BOOL_MASK; - const bool RSV2 = (bits >> RSV2_SHIFT) & BOOL_MASK; - const bool RSV3 = (bits >> RSV2_SHIFT) & BOOL_MASK; - - uint8_t OPCODE = (bits >> OPCODE_SHIFT) & HALF_BYTE_MASK; - - (void)FIN; - (void)RSV1; - (void)RSV2; - (void)RSV3; - - LOG_DBG("got bits: %d", bits); - LOG_DBG("\t\twith OPCODE: %d", OPCODE); - - /* TODO: Protect resp_data with semaphore */ - const size_t resp_data_len = BOARD_REPLY_TOAL_LEN + data_len; - - if (resp_data_len > CONFIG_MAIN_STACK_SIZE) { - /* Close connection due to no memory */ - OPCODE = MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE; - } - - char resp_data[resp_data_len]; - - /* Process depending of opcode: */ - switch (OPCODE) { - case MG_WEBSOCKET_OPCODE_CONTINUATION: - break; - case MG_WEBSOCKET_OPCODE_TEXT: - memcpy(resp_data, - BOARD_REPLY_PREFIX, BOARD_REPLY_PREFIX_LEN); - memcpy(resp_data + BOARD_REPLY_PREFIX_LEN, - data, data_len); - memcpy(resp_data + BOARD_REPLY_PREFIX_LEN + data_len, - BOARD_REPLY_SUFFIX, BOARD_REPLY_SUFFIX_LEN); - - ret_state = mg_websocket_write(conn, OPCODE, resp_data, - resp_data_len); - break; - case MG_WEBSOCKET_OPCODE_BINARY: - ret_state = 0; - mg_websocket_write(conn, - MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE, NULL, 0); - - LOG_ERR("Binary data not supported currently: " - "close connection"); - break; - case MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE: - ret_state = 0; - mg_websocket_write(conn, OPCODE, NULL, 0); - break; - case MG_WEBSOCKET_OPCODE_PING: - break; - case MG_WEBSOCKET_OPCODE_PONG: - break; - default: - ret_state = 0; - mg_websocket_write(conn, - MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE, NULL, 0); - - LOG_ERR("Unknown OPCODE: close connection"); - break; - } - - if (ret_state < 0) { - /* TODO: Maybe need we close WS connection here?! */ - LOG_ERR("Unknown ERROR: ret_state = %d", ret_state); - } else if (ret_state == 0) { - LOG_DBG("Close WS connection: ret_state = %d", ret_state); - } - - return ret_state; -} - -__code_decl void this_close_handler(const struct mg_connection *conn, - void *cbdata) -{ -} diff --git a/samples/net/civetweb/websocket_server/web_page/index.css b/samples/net/civetweb/websocket_server/web_page/index.css deleted file mode 100644 index cffc11ac3e20be..00000000000000 --- a/samples/net/civetweb/websocket_server/web_page/index.css +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2020 Alexander Kozhinov - * - * SPDX-License-Identifier: Apache-2.0 - */ - -html, body { - border: 0; - padding: 0; - margin: 0; - height: calc(100% - 45px); -} - -.frame { - display: block; - padding: 5px; - border: 2px solid #000; - margin-top: 5px; - margin-left: 5px; - margin-right: 5px; - width: auto; - box-sizing: border-box; - width: auto; - height: calc(100% - 5px); -} - -.controls { - border: 2px solid #000; - height: 150px; - box-sizing: border-box; - margin-bottom: 5px; -} - -.log { - padding: 5px; - border: 2px solid #000; - box-sizing: border-box; - width: 100%; - height: calc(100% - 155px); - overflow: auto; - position: relative; -} - -.log #btn_clear_log { - position: absolute; - top: 10px; - right: 10px; - z-index: 1; -} - -.log .entries { - display: table; - box-sizing: border-box; - width: 100%; -} - -.log .entry { - display: table-row; - padding-top: 5px; -} - -.log .entry .publisher, -.log .entry .content { - display: table-cell; - vertical-align: top; - padding: 5px; - font-size: 16px; - line-height: 20px; -} - -.log .entry .publisher .timestamp { - font-weight: normal; - font-size: 10px; - color: black; -} - -.log .entry .publisher { - font-weight: bold; - text-align: right; - width: 80px; - text-transform: uppercase; - padding-right: 10px; -} - -.log .entry .publisher.system { - color: red; -} - -.log .entry .publisher.system:before { - content: 'SYSTEM'; -} - -.log .entry .publisher.console { - color: orange; -} - -.log .entry .publisher.console:before { - content: 'CONSOLE'; -} - -.log .entry .publisher.local { - color: grey; -} - -.log .entry .publisher.local:before { - content: 'LOCAL'; -} - -.log .entry .publisher.remote { - color: green; -} - -.log .entry .publisher.remote:before { - content: 'REMOTE'; -} - -.log .entry .content.text { - font-family: 'Source Code Pro', 'Courier New', monospace; - font-size: 15px; - white-space: pre-wrap; -} - -.log .entry .content.binary { - font-family: 'Source Code Pro', 'Courier New', monospace; - font-size: 15px; - white-space: pre-wrap; - color: orange; -} - -.controls .status { - font-weight: bold; - text-transform: uppercase; -} - -.controls.closed .status { - color: red; -} - -.controls.closed .status:after { - content: 'DISCONNECTED'; -} - -.controls.open .status { - color: green; -} - -.controls.open .status:after { - content: 'CONNECTED'; -} - -.controls.connecting .status { - color: orange; -} - -.controls.connecting .status:after { - content: 'CONNECTING'; -} - -.controls.closing .status { - color: red; -} - -.controls.closing .status:after { - content: 'CLOSING'; -} - -.controls .control-pane { - display: block; - float: left; - border-left: 1px solid #000; - height: 100%; - box-sizing: border-box; - padding: 5px; -} - -.controls .control-pane:first-child { - border-left: none; -} - -.controls table { - padding: 0; - margin: 0; - border-collapse: collapse; -} - -.controls table th { - text-align: right; - padding: 3px; -} - -.controls table td { - padding: 3px; -} - -.controls #message_text { - min-width: 300px; - min-height: 60px; -} - -.copyright { - font-size: 10px; - line-height: 10px; - text-align: right; - color: grey; -} diff --git a/samples/net/civetweb/websocket_server/web_page/index.html b/samples/net/civetweb/websocket_server/web_page/index.html deleted file mode 100644 index 519bad6ce622a9..00000000000000 --- a/samples/net/civetweb/websocket_server/web_page/index.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - Zephyr HTTP civetweb websocket server sample - - - - - - -
-
-

Zephyr HTTP civetweb websocket server sample

-
-
-

HTTP connection: ok!

-
-
- - - - - - - - - - -
Message Text
-
-
- -
-
-
-
- -