libmicrohttpd2

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

commit 1c1957f11e94bacbc71440d3c1489c88bf61d125
parent 2e7c3aebc7f24054aa5296a2678993edc8fa808d
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Sat, 22 Mar 2025 14:54:04 +0300

Refactored MHD_connection_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 | 30+++++++++++++++++-------------
Msrc/include/microhttpd2_main.h.in | 30+++++++++++++++++-------------
Msrc/mhd2/conn_get_info.c | 18+++++++++---------
3 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h @@ -9575,7 +9575,7 @@ enum MHD_ConnectionInfoFixedType * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if connection type is non-IP. * The @a sa pointer is never NULL if the function succeed (#MHD_SC_OK * returned). - * The result is placed in @a v_sa_info member. + * The result is placed in @a v_client_address_sa_info member. * @ingroup request */ MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS = 1 @@ -9586,10 +9586,10 @@ enum MHD_ConnectionInfoFixedType * functions should be used. Any modifications (changing socket attributes, * calling send() or recv(), closing it etc.) will lead to undefined * behaviour. - * The result is placed in @a v_fd member. + * The result is placed in @a v_connection_socket member. * @ingroup request */ - MHD_CONNECTION_INFO_FIXED_CONNECTION_FD = 2 + MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET = 2 , /** * Get the `struct MHD_Daemon *` responsible for managing this connection. @@ -9605,10 +9605,11 @@ enum MHD_ConnectionInfoFixedType * parameter of #MHD_daemon_add_connection(). * By using provided pointer application may get or set the pointer to * any data specific for the particular connection. - * The result is placed in @a v_ppvoid member. + * Note: resulting data is NOT the context pointer itself. + * The result is placed in @a v_app_context_ppvoid member. * @ingroup request */ - MHD_CONNECTION_INFO_FIXED_SOCKET_CONTEXT = 30 + MHD_CONNECTION_INFO_FIXED_APP_CONTEXT = 30 , /* * Sentinel * */ @@ -9620,6 +9621,9 @@ enum MHD_ConnectionInfoFixedType MHD_CONNECTION_INFO_FIXED_SENTINEL = 65535 }; +/** + * Socket address information data + */ struct MHD_ConnInfoFixedSockAddr { /** @@ -9640,31 +9644,31 @@ union MHD_ConnectionInfoFixedData { /** - * Socket Address type + * The data for the #MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS query */ - struct MHD_ConnInfoFixedSockAddr v_sa_info; + struct MHD_ConnInfoFixedSockAddr v_client_address_sa_info; /** - * Socket type + * The data for the #MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET query */ - MHD_Socket v_fd; + MHD_Socket v_connection_socket; /** - * Daemon handler type + * The data for the #MHD_CONNECTION_INFO_FIXED_DAEMON query */ struct MHD_Daemon *v_daemon; /** - * The pointer to pointer to the data + * The data for the #MHD_CONNECTION_INFO_FIXED_APP_CONTEXT query */ - void **v_ppvoid; + void **v_app_context_ppvoid; }; /** * Obtain fixed information about the given connection. * This information is not changed for the lifetime of the connection. - * The wrapper macro #MHD_connection_get_info_fixed() could be more convenient. + * The wrapper macro #MHD_connection_get_info_fixed() may be more convenient. * * @param connection the connection to get information about * @param info_type the type of information requested diff --git a/src/include/microhttpd2_main.h.in b/src/include/microhttpd2_main.h.in @@ -4953,7 +4953,7 @@ enum MHD_ConnectionInfoFixedType * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if connection type is non-IP. * The @a sa pointer is never NULL if the function succeed (#MHD_SC_OK * returned). - * The result is placed in @a v_sa_info member. + * The result is placed in @a v_client_address_sa_info member. * @ingroup request */ MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS = 1 @@ -4964,10 +4964,10 @@ enum MHD_ConnectionInfoFixedType * functions should be used. Any modifications (changing socket attributes, * calling send() or recv(), closing it etc.) will lead to undefined * behaviour. - * The result is placed in @a v_fd member. + * The result is placed in @a v_connection_socket member. * @ingroup request */ - MHD_CONNECTION_INFO_FIXED_CONNECTION_FD = 2 + MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET = 2 , /** * Get the `struct MHD_Daemon *` responsible for managing this connection. @@ -4983,10 +4983,11 @@ enum MHD_ConnectionInfoFixedType * parameter of #MHD_daemon_add_connection(). * By using provided pointer application may get or set the pointer to * any data specific for the particular connection. - * The result is placed in @a v_ppvoid member. + * Note: resulting data is NOT the context pointer itself. + * The result is placed in @a v_app_context_ppvoid member. * @ingroup request */ - MHD_CONNECTION_INFO_FIXED_SOCKET_CONTEXT = 30 + MHD_CONNECTION_INFO_FIXED_APP_CONTEXT = 30 , /* * Sentinel * */ @@ -4998,6 +4999,9 @@ enum MHD_ConnectionInfoFixedType MHD_CONNECTION_INFO_FIXED_SENTINEL = 65535 }; +/** + * Socket address information data + */ struct MHD_ConnInfoFixedSockAddr { /** @@ -5018,31 +5022,31 @@ union MHD_ConnectionInfoFixedData { /** - * Socket Address type + * The data for the #MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS query */ - struct MHD_ConnInfoFixedSockAddr v_sa_info; + struct MHD_ConnInfoFixedSockAddr v_client_address_sa_info; /** - * Socket type + * The data for the #MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET query */ - MHD_Socket v_fd; + MHD_Socket v_connection_socket; /** - * Daemon handler type + * The data for the #MHD_CONNECTION_INFO_FIXED_DAEMON query */ struct MHD_Daemon *v_daemon; /** - * The pointer to pointer to the data + * The data for the #MHD_CONNECTION_INFO_FIXED_APP_CONTEXT query */ - void **v_ppvoid; + void **v_app_context_ppvoid; }; /** * Obtain fixed information about the given connection. * This information is not changed for the lifetime of the connection. - * The wrapper macro #MHD_connection_get_info_fixed() could be more convenient. + * The wrapper macro #MHD_connection_get_info_fixed() may be more convenient. * * @param connection the connection to get information about * @param info_type the type of information requested diff --git a/src/mhd2/conn_get_info.c b/src/mhd2/conn_get_info.c @@ -57,27 +57,27 @@ MHD_connection_get_info_fixed_sz ( return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; } mhd_assert (0 != connection->sk.addr.size); - if (sizeof(output_buf->v_sa_info) > output_buf_size) + if (sizeof(output_buf->v_client_address_sa_info) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; - output_buf->v_sa_info.sa_size = connection->sk.addr.size; - output_buf->v_sa_info.sa = + output_buf->v_client_address_sa_info.sa_size = connection->sk.addr.size; + output_buf->v_client_address_sa_info.sa = (const struct sockaddr*) connection->sk.addr.data; return MHD_SC_OK; - case MHD_CONNECTION_INFO_FIXED_CONNECTION_FD: - if (sizeof(output_buf->v_fd) > output_buf_size) + case MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET: + if (sizeof(output_buf->v_connection_socket) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; mhd_assert (MHD_INVALID_SOCKET != connection->sk.fd); - output_buf->v_fd = connection->sk.fd; + output_buf->v_connection_socket = connection->sk.fd; return MHD_SC_OK; case MHD_CONNECTION_INFO_FIXED_DAEMON: if (sizeof(output_buf->v_daemon) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; output_buf->v_daemon = mhd_daemon_get_master_daemon (connection->daemon); return MHD_SC_OK; - case MHD_CONNECTION_INFO_FIXED_SOCKET_CONTEXT: - if (sizeof(output_buf->v_ppvoid) > output_buf_size) + case MHD_CONNECTION_INFO_FIXED_APP_CONTEXT: + if (sizeof(output_buf->v_app_context_ppvoid) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; - output_buf->v_ppvoid = &(connection->socket_context); + output_buf->v_app_context_ppvoid = &(connection->socket_context); return MHD_SC_OK; case MHD_CONNECTION_INFO_FIXED_SENTINEL: