Edouard LEFIZELIER 2 лет назад
Родитель
Сommit
d57d0428af
2 измененных файлов с 45 добавлено и 0 удалено
  1. 40 0
      src/microhttpd/connection_https_openssl.c
  2. 5 0
      src/microhttpd/internal.h

+ 40 - 0
src/microhttpd/connection_https_openssl.c

@@ -65,6 +65,33 @@ MHD_TLS_openssl_init (void *ctx)
 
 FILE *err_file;
 
+/**
+ * Callback for receiving data from the socket.
+ *
+ * @param connection the MHD_Connection structure
+ * @param other where to write received data to
+ * @param i maximum size of other (in bytes)
+ * @return positive value for number of bytes actually received or
+ *         negative value for error number MHD_ERR_xxx_
+ */
+static ssize_t
+recv_tls_adapter_openssl_ (struct MHD_Connection *connection,
+                           void *other,
+                           size_t i)
+{
+  ssize_t res;
+
+  if (i > SSIZE_MAX)
+    i = SSIZE_MAX;
+
+  res = SSL_read (connection->tls.openssl.ssl,
+                  other,
+                  i);
+  // TODO error handling
+  return res
+}
+
+
 /**
  * Initialize the OpenSSL library
 */
@@ -172,6 +199,19 @@ MHD_run_tls_handshake_openssl_ (struct MHD_Connection *connection)
 }
 
 
+/**
+ * Set connection callback function to be used through out
+ * the processing of this secure connection.
+ *
+ * @param connection which callbacks should be modified
+ */
+void
+MHD_set_https_callbacks_openssl_ (struct MHD_Connection *connection)
+{
+  connection->recv_cls = &recv_tls_adapter_openssl_;
+}
+
+
 /**
  * Close the connection with the server
  *

+ 5 - 0
src/microhttpd/internal.h

@@ -1199,6 +1199,11 @@ union TLS_ConnectionState
 #if 1 || TLS_SUPPORT_OPENSSL
   struct
   {
+    /**
+     * State required for HTTPS/SSL/TLS support.
+     */
+    SSL *ssl;
+
     /**
      * State of connection's TLS layer
      * To modify