libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 35ae3e8d78eb4175fcba760459b3da56b6d2e2c0
parent 199e7bb6c7e87fb9ac5c9607e620d8bb27dd665f
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Sat, 22 Mar 2025 13:59:35 +0300

Refactored MHD_daemon_get_info_fixed_sz() and relevant types

Resulting values now are individual for each query value.
Some names have been updated for clarity

Diffstat:
Msrc/include/microhttpd2.h | 25++++++++++++-------------
Msrc/include/microhttpd2_main.h.in | 25++++++++++++-------------
Msrc/mhd2/daemon_get_info.c | 14+++++++-------
Msrc/tests/client_server/libtest.c | 4++--
Msrc/tests/upgrade/test_upgrade.c | 4++--
5 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h @@ -9276,7 +9276,7 @@ enum MHD_DaemonInfoFixedType * The function returns #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the port number * detection failed or not supported by the platform. * If the function succeed, the returned port number is never zero. - * The result is placed in @a v_port member. + * The result is placed in @a v_bind_port_uint16 member. */ MHD_DAEMON_INFO_FIXED_BIND_PORT = 1 , @@ -9287,7 +9287,7 @@ enum MHD_DaemonInfoFixedType * calling accept(), closing it etc.) will lead to undefined behaviour. * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon * does not have listening socket. - * The result is placed in @a v_socket member. + * The result is placed in @a v_listen_socket member. */ MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET = 2 , @@ -9297,12 +9297,12 @@ enum MHD_DaemonInfoFixedType * This FD can be watched as aggregate indicator for all MHD events. * The provided socket must be used as 'read-only': only select() or similar * functions should be used. Any modifications (changing socket attributes, - * calling accept() closing it etc.) will lead to undefined behaviour. + * calling accept(), closing it etc.) will lead to undefined behaviour. * The function returns #MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD if the library * does not support mode with agregate FD. * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon * is not configured to use this mode. - * The result is placed in @a v_fd member. + * The result is placed in @a v_aggreagate_fd member. */ MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD = 3 , @@ -9313,7 +9313,7 @@ enum MHD_DaemonInfoFixedType * If MHD built without TLS support then #MHD_TLS_BACKEND_NONE is always set. * The result is placed in @a v_tls_backend member. */ - MHD_DAEMON_INFO_FIXED_TLS_TYPE = 100 + MHD_DAEMON_INFO_FIXED_TLS_BACKEND = 100 , /* * Sentinel * */ @@ -9332,24 +9332,23 @@ enum MHD_DaemonInfoFixedType */ union MHD_DaemonInfoFixedData { - /** - * The socket type of data. + * The data for the #MHD_DAEMON_INFO_FIXED_BIND_PORT query */ - MHD_Socket v_socket; + uint_least16_t v_bind_port_uint16; /** - * File descriptor, except sockets + * The data for the #MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET query */ - int v_fd; + MHD_Socket v_listen_socket; /** - * Port number + * The data for the #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD query */ - uint_least16_t v_port; + int v_aggreagate_fd; /** - * The TLS backend + * The data for the #MHD_DAEMON_INFO_FIXED_TLS_BACKEND query */ enum MHD_TlsBackend v_tls_backend; diff --git a/src/include/microhttpd2_main.h.in b/src/include/microhttpd2_main.h.in @@ -4654,7 +4654,7 @@ enum MHD_DaemonInfoFixedType * The function returns #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the port number * detection failed or not supported by the platform. * If the function succeed, the returned port number is never zero. - * The result is placed in @a v_port member. + * The result is placed in @a v_bind_port_uint16 member. */ MHD_DAEMON_INFO_FIXED_BIND_PORT = 1 , @@ -4665,7 +4665,7 @@ enum MHD_DaemonInfoFixedType * calling accept(), closing it etc.) will lead to undefined behaviour. * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon * does not have listening socket. - * The result is placed in @a v_socket member. + * The result is placed in @a v_listen_socket member. */ MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET = 2 , @@ -4675,12 +4675,12 @@ enum MHD_DaemonInfoFixedType * This FD can be watched as aggregate indicator for all MHD events. * The provided socket must be used as 'read-only': only select() or similar * functions should be used. Any modifications (changing socket attributes, - * calling accept() closing it etc.) will lead to undefined behaviour. + * calling accept(), closing it etc.) will lead to undefined behaviour. * The function returns #MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD if the library * does not support mode with agregate FD. * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon * is not configured to use this mode. - * The result is placed in @a v_fd member. + * The result is placed in @a v_aggreagate_fd member. */ MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD = 3 , @@ -4691,7 +4691,7 @@ enum MHD_DaemonInfoFixedType * If MHD built without TLS support then #MHD_TLS_BACKEND_NONE is always set. * The result is placed in @a v_tls_backend member. */ - MHD_DAEMON_INFO_FIXED_TLS_TYPE = 100 + MHD_DAEMON_INFO_FIXED_TLS_BACKEND = 100 , /* * Sentinel * */ @@ -4710,24 +4710,23 @@ enum MHD_DaemonInfoFixedType */ union MHD_DaemonInfoFixedData { - /** - * The socket type of data. + * The data for the #MHD_DAEMON_INFO_FIXED_BIND_PORT query */ - MHD_Socket v_socket; + uint_least16_t v_bind_port_uint16; /** - * File descriptor, except sockets + * The data for the #MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET query */ - int v_fd; + MHD_Socket v_listen_socket; /** - * Port number + * The data for the #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD query */ - uint_least16_t v_port; + int v_aggreagate_fd; /** - * The TLS backend + * The data for the #MHD_DAEMON_INFO_FIXED_TLS_BACKEND query */ enum MHD_TlsBackend v_tls_backend; diff --git a/src/mhd2/daemon_get_info.c b/src/mhd2/daemon_get_info.c @@ -70,30 +70,30 @@ MHD_daemon_get_info_fixed_sz ( return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; return MHD_SC_INFO_GET_TYPE_UNOBTAINABLE; } - if (sizeof(output_buf->v_port) > output_buf_size) + if (sizeof(output_buf->v_bind_port_uint16) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; - output_buf->v_port = daemon->net.listen.port; + output_buf->v_bind_port_uint16 = daemon->net.listen.port; return MHD_SC_OK; case MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET: if (MHD_INVALID_SOCKET == daemon->net.listen.fd) return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; - if (sizeof(MHD_Socket) > output_buf_size) + if (sizeof(output_buf->v_listen_socket) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; - output_buf->v_socket = daemon->net.listen.fd; + output_buf->v_listen_socket = daemon->net.listen.fd; return MHD_SC_OK; case MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD: #ifdef MHD_SUPPORT_EPOLL if (! mhd_D_IS_USING_EPOLL (daemon)) return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; - if (sizeof(int) > output_buf_size) + if (sizeof(output_buf->v_aggreagate_fd) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; - output_buf->v_fd = daemon->events.data.epoll.e_fd; + output_buf->v_aggreagate_fd = daemon->events.data.epoll.e_fd; return MHD_SC_OK; #else return MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD; #endif break; - case MHD_DAEMON_INFO_FIXED_TLS_TYPE: + case MHD_DAEMON_INFO_FIXED_TLS_BACKEND: if (sizeof(output_buf->v_tls_backend) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; if (! mhd_D_HAS_TLS (daemon)) diff --git a/src/tests/client_server/libtest.c b/src/tests/client_server/libtest.c @@ -552,11 +552,11 @@ MHDT_test (MHDT_ServerSetup ss_cb, snprintf (base_http_url, sizeof (base_http_url), "http://localhost:%u/", - (unsigned int) info.v_port); + (unsigned int) info.v_bind_port_uint16); snprintf (base_https_url, sizeof (base_https_url), "https://localhost:%u/", - (unsigned int) info.v_port); + (unsigned int) info.v_bind_port_uint16); pc_http.base_url = base_http_url; pc_https.base_url = base_https_url; } diff --git a/src/tests/upgrade/test_upgrade.c b/src/tests/upgrade/test_upgrade.c @@ -1667,9 +1667,9 @@ test_upgrade (void) &dinfo)) mhdErrorExitDesc ("MHD_daemon_get_info_fixed() failed"); - if (0 == dinfo.v_port) + if (0 == dinfo.v_bind_port_uint16) mhdErrorExitDesc ("MHD_daemon_get_info_fixed() returned wrong data"); - global_port = dinfo.v_port; /* Re-use the same port for the next checks */ + global_port = dinfo.v_bind_port_uint16; /* Re-use the same port for the next checks */ if (! test_tls || (TLS_LIB_GNUTLS == use_tls_tool)) { sock = test_tls ? wr_create_tls_sckt () : wr_create_plain_sckt ();