commit 46ffc8fecfe25e739d01d542b3582770dd68cec3
parent 138e9b8d7cbf68a20f8ae13d19ad0031fd7b86f0
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Tue, 9 Dec 2025 20:35:20 +0100
TLS: initial support for TLS custom transport
Diffstat:
14 files changed, 211 insertions(+), 61 deletions(-)
diff --git a/src/mhd2/conn_data_recv.c b/src/mhd2/conn_data_recv.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -57,11 +57,12 @@
#include "stream_funcs.h"
#include "mhd_socket_error_funcs.h"
+#include "sckt_recv.h"
#include "mhd_recv.h"
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void
-mhd_conn_data_recv (struct MHD_Connection *restrict c,
+mhd_conn_data_recv (struct MHD_Connection *c,
bool has_err)
{
void *buf;
@@ -76,6 +77,7 @@ mhd_conn_data_recv (struct MHD_Connection *restrict c,
(0 != (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY)));
mhd_assert ((0 == (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY)) || \
has_err);
+ mhd_assert (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err);
buf = c->read_buffer + c->read_buffer_offset;
buf_size = c->read_buffer_size - c->read_buffer_offset;
@@ -93,23 +95,28 @@ mhd_conn_data_recv (struct MHD_Connection *restrict c,
c->sk.state.rmt_shut_wr = true;
res = mhd_SOCKET_ERR_REMT_DISCONN;
}
- if (has_err && ! mhd_SOCKET_ERR_IS_HARD (res) && c->sk.props.is_nonblck
- && ! mhd_C_HAS_TLS (c))
- {
- /* Re-try last time to detect the error */
- uint_fast64_t dummy_buf;
- res = mhd_recv (c, sizeof(dummy_buf), (char *) &dummy_buf, &received);
- }
- if (mhd_SOCKET_ERR_IS_HARD (res))
+
+ if (has_err && (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err))
{
- c->sk.state.discnt_err = res;
- c->sk.ready =
- (enum mhd_SocketNetState) (((unsigned int) c->sk.ready)
- | mhd_SOCKET_NET_STATE_ERROR_READY);
+ /* Try to get the real error from the socket */
+ if (! mhd_SOCKET_ERR_IS_HARD (res) && c->sk.props.is_nonblck)
+ {
+ /* Re-try the last time with direct socket recv() to detect the error */
+ uint_fast64_t dummy_buf;
+ res = mhd_sckt_recv (&(c->sk),
+ sizeof(dummy_buf),
+ (char *) &dummy_buf,
+ &received);
+ }
+ if (mhd_SOCKET_ERR_IS_HARD (res))
+ {
+ c->sk.state.discnt_err = res;
+ mhd_SCKT_NET_ST_SET_FLAG (&(c->sk.ready),
+ mhd_SOCKET_NET_STATE_ERROR_READY);
+ }
+ else
+ c->sk.state.discnt_err = mhd_socket_error_get_from_socket (c->sk.fd);
}
- else if (has_err &&
- (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err))
- c->sk.state.discnt_err = mhd_socket_error_get_from_socket (c->sk.fd);
return;
}
diff --git a/src/mhd2/conn_data_recv.h b/src/mhd2/conn_data_recv.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -60,7 +60,7 @@ struct MHD_Connection; /* forward declarations */
* type is performed
*/
MHD_INTERNAL void
-mhd_conn_data_recv (struct MHD_Connection *restrict c,
+mhd_conn_data_recv (struct MHD_Connection *c,
bool has_err)
MHD_FN_PAR_NONNULL_ALL_;
diff --git a/src/mhd2/conn_data_send.c b/src/mhd2/conn_data_send.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2015-2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2015-2025 Evgeny Grin (Karlson2k)
Copyright (C) 2007-2020 Daniel Pittman and Christian Grothoff
GNU libmicrohttpd is free software; you can redistribute it and/or
@@ -93,7 +93,7 @@ check_write_done (struct MHD_Connection *restrict connection,
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void
-mhd_conn_data_send (struct MHD_Connection *restrict c)
+mhd_conn_data_send (struct MHD_Connection *c)
{
static const char http_100_continue_msg[] =
mdh_HTTP_1_1_100_CONTINUE_REPLY;
@@ -102,6 +102,8 @@ mhd_conn_data_send (struct MHD_Connection *restrict c)
enum mhd_SocketError res;
size_t sent;
+ mhd_assert (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err);
+
// TODO: assert check suspended
// TODO: MOVE out STATES PROCESSING
@@ -408,7 +410,8 @@ mhd_conn_data_send (struct MHD_Connection *restrict c)
}
else if (mhd_SOCKET_ERR_IS_HARD (res))
{
- c->sk.state.discnt_err = res;
+ if (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err)
+ c->sk.state.discnt_err = res;
c->sk.ready =
(enum mhd_SocketNetState) (((unsigned int) c->sk.ready)
| mhd_SOCKET_NET_STATE_ERROR_READY);
diff --git a/src/mhd2/conn_data_send.h b/src/mhd2/conn_data_send.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -58,7 +58,7 @@ struct MHD_Connection; /* forward declarations */
* @param c the connection to use
*/
MHD_INTERNAL void
-mhd_conn_data_send (struct MHD_Connection *restrict c)
+mhd_conn_data_send (struct MHD_Connection *c)
MHD_FN_PAR_NONNULL_ALL_;
diff --git a/src/mhd2/mhd_send.c b/src/mhd2/mhd_send.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2017-2024 Karlson2k (Evgeny Grin), Full re-write of buffering
+ Copyright (C) 2017-2025 Karlson2k (Evgeny Grin), Full re-write of buffering
and pushing, many bugs fixes, optimisations,
sendfile() porting
Copyright (C) 2019 ng0 <ng0@n0.is>, Initial version of send() wrappers
@@ -886,17 +886,20 @@ mhd_send_tls (struct MHD_Connection *restrict c,
size_t *restrict sent)
{
/* TLS connection */
+ const bool custm_trnsp = mhd_tls_conn_has_cstm_tr (c->tls);
enum mhd_SocketError res;
mhd_assert (mhd_C_HAS_TLS (c));
mhd_assert (mhd_D_HAS_TLS (c->daemon));
mhd_assert (0 != buf_size);
- pre_send_setopt (&(c->sk), false, push_data);
+ if (! custm_trnsp)
+ pre_send_setopt (&(c->sk), false, push_data);
res = mhd_tls_conn_send (c->tls,
buf_size,
buf,
+ push_data,
sent);
if (mhd_SOCKET_ERR_NO_ERROR != res)
@@ -917,7 +920,7 @@ mhd_send_tls (struct MHD_Connection *restrict c,
/* If there is a need to push the data from network buffers
* call post_send_setopt(). */
- if (push_data && (buf_size == *sent))
+ if ((! custm_trnsp) && push_data && (buf_size == *sent))
post_send_setopt (&(c->sk), false, true);
return mhd_SOCKET_ERR_NO_ERROR;
diff --git a/src/mhd2/mhd_send.h b/src/mhd2/mhd_send.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2017-2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2017-2025 Evgeny Grin (Karlson2k)
Copyright (C) 2019 ng0
GNU libmicrohttpd is free software; you can redistribute it and/or
diff --git a/src/mhd2/mhd_tls_funcs.h b/src/mhd2/mhd_tls_funcs.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -194,19 +194,39 @@
* Send data to the remote side over TLS connection
*
* @param c_tls the connection TLS handle
- * @param buffer_size the size of the @a buffer (in bytes)
- * @param buffer content of the buffer to send
+ * @param buf_size the size of the @a buf (in bytes)
+ * @param buf content of the buffer to send
+ * @param push_data set to 'false' if it is know that the data in the @a buf
+ * is incomplete (message or chunk),
+ * set to 'true' if the data is complete or the final part
* @param[out] sent the pointer to get amount of actually sent bytes
* @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets
* the sent size) or socket error
*/
-#define mhd_tls_conn_send(c_tls,buf_size,buf,sent) \
- mhd_TLS_FUNC (_conn_send)((c_tls),(buf_size),(buf),(sent))
+#define mhd_tls_conn_send(c_tls,buf_size,buf,push_data,sent) \
+ mhd_TLS_FUNC (_conn_send)((c_tls),(buf_size),(buf),(push_data),(sent))
/* ** TLS connection information ** */
/**
+ * Check whether the connection is using "custom transport" functions.
+ * "Custom transport" means that data sending and receiving over system
+ * sockets is performed by MHD callbacks.
+ * When "custom transport" is used, backend TLS send/recv functions are:
+ * * perform additional syscalls (socket options) for data pushing/buffering,
+ * * change socket states like corked, NO_DELAY, both by syscalls and in
+ * MHD socket metadata,
+ * * set disconnect error from the system reported socket error.
+ *
+ * @param c_tls the connection TLS handle
+ * @return boolean 'true' if custom transport is used,
+ * boolean 'false' otherwise
+ */
+#define mhd_tls_conn_has_cstm_tr(c_tls) \
+ mhd_TLS_FUNC (_conn_has_cstm_tr)((c_tls))
+
+/**
* Get the TLS session used in connection
* @param c_tls the connection TLS handle
* @param tls_ver_out the pointer to variable to be set to the TLS version
diff --git a/src/mhd2/sckt_send.h b/src/mhd2/sckt_send.h
@@ -63,10 +63,9 @@ struct mhd_ConnSocket; /* Forward declaration */
* @param sk the socket data
* @param buf_size the size of the data @a buf buffer
* @param buf the buffer with the data to send
- * @param push_data set to 'true' if the data in the @a buf is the complete
- * message (chunk of data) or the final part of the message,
- * set to 'false' if it is know that more data will be
- * sent and the next part of the data is (almost) ready
+ * @param push_data set to 'false' if it is know that the data in the @a buf
+ * is incomplete (message or chunk),
+ * set to 'true' if the data is complete or the final part
* @param[out] sent the pointer to variable to set the size of the data
* actually sent
* @return mhd_SOCKET_ERR_NO_ERROR if receive succeed (the @a received gets
diff --git a/src/mhd2/tls_gnu_funcs.c b/src/mhd2/tls_gnu_funcs.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -795,10 +795,10 @@ mhd_tls_gnu_conn_has_data_in (struct mhd_TlsGnuConnData *restrict c_tls)
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_
MHD_FN_PAR_IN_SIZE_ (3,2)
MHD_FN_PAR_OUT_ (4) enum mhd_SocketError
-mhd_tls_gnu_conn_send (struct mhd_TlsGnuConnData *restrict c_tls,
- size_t buf_size,
- const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
- size_t *restrict sent)
+mhd_tls_gnu_conn_send4 (struct mhd_TlsGnuConnData *restrict c_tls,
+ size_t buf_size,
+ const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
+ size_t *restrict sent)
{
ssize_t res;
diff --git a/src/mhd2/tls_gnu_funcs.h b/src/mhd2/tls_gnu_funcs.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -264,16 +264,47 @@ MHD_FN_PAR_NONNULL_ALL_;
* the sent size) or socket error
*/
MHD_INTERNAL enum mhd_SocketError
-mhd_tls_gnu_conn_send (struct mhd_TlsGnuConnData *restrict c_tls,
- size_t buf_size,
- const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
- size_t *restrict sent)
+mhd_tls_gnu_conn_send4 (struct mhd_TlsGnuConnData *restrict c_tls,
+ size_t buf_size,
+ const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
+ size_t *restrict sent)
MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4);
+/**
+ * Send data to the remote side over TLS connection
+ *
+ * @param c_tls the connection TLS handle
+ * @param buf_size the size of the @a buf (in bytes)
+ * @param buf content of the buffer to send
+ * @param push_data set to 'false' if it is know that the data in the @a b
+ * is incomplete (message or chunk),
+ * set to 'true' if the data is complete or the final part
+ * @param[out] sent the pointer to get amount of actually sent bytes
+ * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets
+ * the sent size) or socket error
+ */
+#define mhd_tls_gnu_conn_send(c_tls,buf_size,buf,push_data,sent) \
+ mhd_tls_gnu_conn_send4 (c_tls,buf_size,buf,sent)
/* ** TLS connection information ** */
/**
+ * Check whether the connection is using "custom transport" functions.
+ * "Custom transport" means that data sending and receiving over system
+ * sockets is performed by MHD callbacks.
+ * When "custom transport" is used, backend TLS send/recv functions are:
+ * * perform additional syscalls (socket options) for data pushing/buffering,
+ * * change socket states like corked, NO_DELAY, both by syscalls and in
+ * MHD socket metadata,
+ * * set disconnect error from the system reported socket error.
+ *
+ * @param c_tls the connection TLS handle
+ * @return boolean 'true' if custom transport is used,
+ * boolean 'false' otherwise
+ */
+#define mhd_tls_gnu_conn_has_cstm_tr(c_tls) (! ! 0)
+
+/**
* Get the TLS session used in connection
* @param c_tls the connection TLS handle
* @param tls_sess_out the pointer to variable to be set to the TLS session
diff --git a/src/mhd2/tls_multi_funcs.c b/src/mhd2/tls_multi_funcs.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -576,6 +576,35 @@ mhd_tls_multi_conn_recv (struct mhd_TlsMultiConnData *restrict c_tls,
}
+MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PURE_ bool
+mhd_tls_multi_conn_has_cstm_tr (struct mhd_TlsMultiConnData *restrict c_tls)
+{
+ (void) c_tls; /* Could be unused if all underling functions are actually macros */
+ switch (c_tls->choice)
+ {
+#ifdef MHD_SUPPORT_GNUTLS
+ case mhd_TLS_MULTI_ROUTE_GNU:
+ return mhd_tls_gnu_conn_has_cstm_tr (c_tls->data.gnutls);
+#endif
+#ifdef MHD_SUPPORT_OPENSSL
+ case mhd_TLS_MULTI_ROUTE_OPEN:
+ return mhd_tls_open_conn_has_cstm_tr (c_tls->data.openssl);
+#endif
+#ifndef MHD_SUPPORT_GNUTLS
+ case MHD_TLS_BACKEND_GNUTLS:
+#endif /* ! MHD_SUPPORT_GNUTLS */
+#ifndef MHD_SUPPORT_OPENSSL
+ case MHD_TLS_BACKEND_OPENSSL:
+#endif /* ! MHD_SUPPORT_OPENSSL */
+ case mhd_TLS_MULTI_ROUTE_NONE:
+ default:
+ mhd_UNREACHABLE ();
+ break;
+ }
+ return false;
+}
+
+
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool
mhd_tls_multi_conn_has_data_in (struct mhd_TlsMultiConnData *restrict c_tls)
{
@@ -606,12 +635,14 @@ mhd_tls_multi_conn_has_data_in (struct mhd_TlsMultiConnData *restrict c_tls)
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_
MHD_FN_PAR_IN_SIZE_ (3,2)
-MHD_FN_PAR_OUT_ (4) enum mhd_SocketError
+MHD_FN_PAR_OUT_ (5) enum mhd_SocketError
mhd_tls_multi_conn_send (struct mhd_TlsMultiConnData *restrict c_tls,
size_t buf_size,
const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
+ bool push_data,
size_t *restrict sent)
{
+ (void) push_data; /* Could be unused if not supported by all backends */
switch (c_tls->choice)
{
#ifdef MHD_SUPPORT_GNUTLS
@@ -619,6 +650,7 @@ mhd_tls_multi_conn_send (struct mhd_TlsMultiConnData *restrict c_tls,
return mhd_tls_gnu_conn_send (c_tls->data.gnutls,
buf_size,
buf,
+ push_data,
sent);
#endif
#ifdef MHD_SUPPORT_OPENSSL
@@ -626,6 +658,7 @@ mhd_tls_multi_conn_send (struct mhd_TlsMultiConnData *restrict c_tls,
return mhd_tls_open_conn_send (c_tls->data.openssl,
buf_size,
buf,
+ push_data,
sent);
#endif
#ifndef MHD_SUPPORT_GNUTLS
diff --git a/src/mhd2/tls_multi_funcs.h b/src/mhd2/tls_multi_funcs.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -238,6 +238,9 @@ MHD_FN_PAR_NONNULL_ALL_;
* @param c_tls the connection TLS handle
* @param buf_size the size of the @a buf (in bytes)
* @param buf content of the buffer to send
+ * @param push_data set to 'false' if it is know that the data in the @a buf
+ * is incomplete (message or chunk),
+ * set to 'true' if the data is complete or the final part
* @param[out] sent the pointer to get amount of actually sent bytes
* @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets
* the sent size) or socket error
@@ -246,13 +249,32 @@ MHD_INTERNAL enum mhd_SocketError
mhd_tls_multi_conn_send (struct mhd_TlsMultiConnData *restrict c_tls,
size_t buf_size,
const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
+ bool push_data,
size_t *restrict sent)
-MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4);
+MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (5);
/* ** TLS connection information ** */
/**
+ * Check whether the connection is using "custom transport" functions.
+ * "Custom transport" means that data sending and receiving over system
+ * sockets is performed by MHD callbacks.
+ * When "custom transport" is used, backend TLS send/recv functions are:
+ * * perform additional syscalls (socket options) for data pushing/buffering,
+ * * change socket states like corked, NO_DELAY, both by syscalls and in
+ * MHD socket metadata,
+ * * set disconnect error from the system reported socket error.
+ *
+ * @param c_tls the connection TLS handle
+ * @return boolean 'true' if custom transport is used,
+ * boolean 'false' otherwise
+ */
+MHD_INTERNAL bool
+mhd_tls_multi_conn_has_cstm_tr (struct mhd_TlsMultiConnData *restrict c_tls)
+MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PURE_;
+
+/**
* Get the TLS session used in connection
* @param c_tls the connection TLS handle
* @param tls_sess_out the pointer to variable to be set to the TLS session
diff --git a/src/mhd2/tls_open_funcs.c b/src/mhd2/tls_open_funcs.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -1210,10 +1210,10 @@ mhd_tls_open_conn_has_data_in (struct mhd_TlsOpenConnData *restrict c_tls)
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_
MHD_FN_PAR_IN_SIZE_ (3,2)
MHD_FN_PAR_OUT_ (4) enum mhd_SocketError
-mhd_tls_open_conn_send (struct mhd_TlsOpenConnData *restrict c_tls,
- size_t buf_size,
- const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
- size_t *restrict sent)
+mhd_tls_open_conn_send4 (struct mhd_TlsOpenConnData *restrict c_tls,
+ size_t buf_size,
+ const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
+ size_t *restrict sent)
{
int res;
diff --git a/src/mhd2/tls_open_funcs.h b/src/mhd2/tls_open_funcs.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
/*
This file is part of GNU libmicrohttpd.
- Copyright (C) 2024 Evgeny Grin (Karlson2k)
+ Copyright (C) 2024-2025 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -248,16 +248,48 @@ MHD_FN_PAR_NONNULL_ALL_;
* the sent size) or socket error
*/
MHD_INTERNAL enum mhd_SocketError
-mhd_tls_open_conn_send (struct mhd_TlsOpenConnData *restrict c_tls,
- size_t buf_size,
- const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
- size_t *restrict sent)
+mhd_tls_open_conn_send4 (struct mhd_TlsOpenConnData *restrict c_tls,
+ size_t buf_size,
+ const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
+ size_t *restrict sent)
MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4);
+/**
+ * Send data to the remote side over TLS connection
+ *
+ * @param c_tls the connection TLS handle
+ * @param buf_size the size of the @a buf (in bytes)
+ * @param buf content of the buffer to send
+ * @param push_data set to 'false' if it is know that the data in the @a buf
+ * is incomplete (message or chunk),
+ * set to 'true' if the data is complete or the final part
+ * @param[out] sent the pointer to get amount of actually sent bytes
+ * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets
+ * the sent size) or socket error
+ */
+#define mhd_tls_open_conn_send(c_tls,buf_size,buf,push_data,sent) \
+ mhd_tls_open_conn_send4 (c_tls,buf_size,buf,sent)
+
/* ** TLS connection information ** */
/**
+ * Check whether the connection is using "custom transport" functions.
+ * "Custom transport" means that data sending and receiving over system
+ * sockets is performed by MHD callbacks.
+ * When "custom transport" is used, backend TLS send/recv functions are:
+ * * perform additional syscalls (socket options) for data pushing/buffering,
+ * * change socket states like corked, NO_DELAY, both by syscalls and in
+ * MHD socket metadata,
+ * * set disconnect error from the system reported socket error.
+ *
+ * @param c_tls the connection TLS handle
+ * @return boolean 'true' if custom transport is used,
+ * boolean 'false' otherwise
+ */
+#define mhd_tls_open_conn_has_cstm_tr(c_tls) (! ! 0)
+
+/**
* Get the TLS session used in connection
* @param c_tls the connection TLS handle
* @param tls_sess_out the pointer to variable to be set to the TLS session