commit 48dd53c7eb6a0ec3f47c23511bcf94d3f6f52e24
parent f65dd8e0969d6c43913da51b585437c7f8447cac
Author: Christian Grothoff <christian@grothoff.org>
Date: Fri, 9 Feb 2018 06:13:12 +0100
more work on MHD2 API
Diffstat:
2 files changed, 118 insertions(+), 5 deletions(-)
diff --git a/src/include/microhttpd_tls.h b/src/include/microhttpd_tls.h
@@ -0,0 +1,104 @@
+#ifndef MICROHTTPD_TLS_H
+#define MICROHTTPD_TLS_H
+
+/**
+ * Version of the TLS ABI.
+ */
+#define MHD_TLS_ABI_VERSION 0
+
+/**
+ * Version of the TLS ABI as a string.
+ * Must match #MHD_TLS_ABI_VERSION!
+ */
+#define MHD_TLS_ABI_VERSION_STR "0"
+
+
+/**
+ * Callback functions to use for TLS operations.
+ */
+struct MHD_TLS_Plugin
+{
+ /**
+ * Closure with plugin's internal state, opaque to MHD.
+ */
+ void *cls;
+
+ /**
+ * Destroy the plugin, we are done with it.
+ */
+ void
+ (*done)(struct MHD_TLS_Plugin *plugin);
+
+ /**
+ * Initialize key and certificate data from memory.
+ *
+ * @param cls the @e cls of this struct
+ * @param mem_key private key (key.pem) to be used by the
+ * HTTPS daemon. Must be the actual data in-memory, not a filename.
+ * @param mem_cert certificate (cert.pem) to be used by the
+ * HTTPS daemon. Must be the actual data in-memory, not a filename.
+ * @param pass passphrase phrase to decrypt 'key.pem', NULL
+ * if @param mem_key is in cleartext already
+ * @return #MHD_SC_OK upon success; TODO: define failure modes
+ */
+ enum MHD_StatusCode
+ (*init_kcp)(void *cls,
+ const char *mem_key,
+ const char *mem_cert,
+ const char *pass);
+
+
+ /**
+ * Initialize DH parameters.
+ *
+ * @param cls the @e cls of this struct
+ * @param dh parameters to use
+ * @return #MHD_SC_OK upon success; TODO: define failure modes
+ */
+ enum MHD_StatusCode
+ (*init_dhparams)(void *cls,
+ const char *dh);
+
+
+ /**
+ * Initialize certificate to use for client authentication.
+ *
+ * @param cls the @e cls of this struct
+ * @param mem_trust client certificate
+ * @return #MHD_SC_OK upon success; TODO: define failure modes
+ */
+ enum MHD_StatusCode
+ (*init_mem_trust)(void *cls,
+ const char *mem_trust);
+
+
+ /**
+ * TODO: More functions here....
+ */
+
+};
+
+
+/**
+ * Signature of the initialization function each TLS plugin must
+ * export.
+ *
+ * @param ciphers desired cipher suite
+ * @return NULL on errors (in particular, invalid cipher suite)
+ */
+typedef struct MHD_TLS_Plugin *
+MHD_TLS_PluginInit (const char *ciphers);
+
+
+/**
+ * Define function to be exported from the TLS plugin.
+ *
+ * @a body function body that receives `ciphers` argument
+ * and must return the plugin API, or NULL on error.
+ */
+#define MHD_TLS_INIT(body) \
+ struct MHD_TLS_Plugin * \
+ MHD_TLS_init_ ## MHD_TLS_ABI_VERSION (const char *ciphers) \\
+ { body }
+
+#endif
diff --git a/src/lib/daemon_start.c b/src/lib/daemon_start.c
@@ -177,11 +177,12 @@ static enum MHD_StatusCode
open_listen_socket (struct MHD_Daemon *daemon)
{
enum MHD_StatusCode sc;
- bool usev6;
socklen_t addrlen;
struct sockaddr_storage ss;
const struct sockaddr *sa;
-
+ int pf;
+ bool use_v6;
+
if (MHD_INVALID_SOCKET != daemon->listen_fd)
return MHD_SC_OK; /* application opened it for us! */
@@ -194,17 +195,21 @@ open_listen_socket (struct MHD_Daemon *daemon)
abort ();
case MHD_AF_AUTO:
#if HAVE_INET6
+ pf = PF_INET6;
use_v6 = true;
#else
+ pf = PF_INET;
use_v6 = false;
#endif
break;
case MHD_AF_INET:
use_v6 = false;
+ pf = PF_INET;
break;
case MHD_AF_INET6:
case MHD_AF_DUAL:
#if HAVE_INET6
+ pf = PF_INET6;
use_v6 = true;
break;
#else
@@ -219,21 +224,24 @@ open_listen_socket (struct MHD_Daemon *daemon)
}
else if (0 != daemon->listen_sa_len)
{
+
/* we have a listen address, get AF from there! */
switch (daemon->listen_sa.ss_family)
{
case AF_INET:
+ pf = PF_INET;
use_v6 = false;
break;
#ifdef AF_INET6
case AF_INET6:
+ pf = PF_INET6;
use_v6 = true;
break;
#endif
#ifdef AF_UNIX
case AF_UNIX:
- // FIXME: not implemented
- // (need to change MHD_socket_create_listen_() API!)
+ pf = PF_UNIX;
+ use_v6 = false;
#endif
default:
return MHD_SC_AF_NOT_SUPPORTED_BY_BUILD;
@@ -247,12 +255,13 @@ open_listen_socket (struct MHD_Daemon *daemon)
/* try to open listen socket */
try_open_listen_socket:
- daemon->listen_socket = MHD_socket_create_listen_(use_v6);
+ daemon->listen_socket = MHD_socket_create_listen_(pf);
if ( (MHD_INVALID_SOCKET == daemon->listen_socket) &&
(MHD_AF_AUTO == daemon->address_family) &&
(use_v6) )
{
use_v6 = false;
+ pf = PF_INET;
goto try_open_listen_socket;
}
if (MHD_INVALID_SOCKET == daemon->listen_socket)