libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

setup_connection.c (2042B)


      1 setup_connection ()
      2 {
      3   connection->tls_state = MHD_TLS_CONN_INIT;
      4   MHD_set_https_callbacks (connection);
      5   gnutls_init (&connection->tls_session,
      6                GNUTLS_SERVER
      7 #if (GNUTLS_VERSION_NUMBER + 0 >= 0x030402)
      8                | GNUTLS_NO_SIGNAL
      9 #endif /* GNUTLS_VERSION_NUMBER >= 0x030402 */
     10 #if GNUTLS_VERSION_MAJOR >= 3
     11                | GNUTLS_NONBLOCK
     12 #endif /* GNUTLS_VERSION_MAJOR >= 3*/
     13                );
     14   gnutls_priority_set (connection->tls_session,
     15                        daemon->priority_cache);
     16   switch (daemon->cred_type)
     17   {
     18   /* set needed credentials for certificate authentication. */
     19   case GNUTLS_CRD_CERTIFICATE:
     20     gnutls_credentials_set (connection->tls_session,
     21                             GNUTLS_CRD_CERTIFICATE,
     22                             daemon->x509_cred);
     23     break;
     24   default:
     25 #ifdef HAVE_MESSAGES
     26     MHD_DLOG (connection->daemon,
     27               _ (
     28                 "Failed to setup TLS credentials: unknown credential type %d.\n"),
     29               daemon->cred_type);
     30 #endif
     31     MHD_socket_close_chk_ (client_socket);
     32     MHD_ip_limit_del (daemon,
     33                       addr,
     34                       addrlen);
     35     free (connection);
     36     MHD_PANIC (_ ("Unknown credential type.\n"));
     37 #if EINVAL
     38     errno = EINVAL;
     39 #endif
     40     return MHD_NO;
     41   }
     42 #if (GNUTLS_VERSION_NUMBER + 0 >= 0x030109) && ! defined(_WIN64)
     43   gnutls_transport_set_int (connection->tls_session, (int) (client_socket));
     44 #else  /* GnuTLS before 3.1.9 or Win x64 */
     45   gnutls_transport_set_ptr (connection->tls_session,
     46                             (gnutls_transport_ptr_t) (intptr_t) (client_socket));
     47 #endif /* GnuTLS before 3.1.9 */
     48 #ifdef MHD_TLSLIB_NEED_PUSH_FUNC
     49   gnutls_transport_set_push_function (connection->tls_session,
     50                                       MHD_tls_push_func_);
     51 #endif /* MHD_TLSLIB_NEED_PUSH_FUNC */
     52   if (daemon->https_mem_trust)
     53     gnutls_certificate_server_set_request (connection->tls_session,
     54                                            GNUTLS_CERT_REQUEST);
     55 #else  /* ! HTTPS_SUPPORT */
     56   return NULL;
     57 
     58 }