- close(h->newfd);
-#endif
- h->newfd = -1;
- }
- xfree (cnew);
- xfree (state);
- return 0;
- }
- h->newfd = -1;
- state->altbuf = 0;
- state->altsize = state->altlen = 0;
- state->towrite = state->written = -1;
- state->complete = st->complete;
- cnew->state = CS_ST_ACCEPT;
- h->state = CS_ST_IDLE;
-
-#if HAVE_OPENSSL_SSL_H
- state->ctx = st->ctx;
- state->ctx_alloc = 0;
- state->ssl = st->ssl;
- if (state->ctx)
- {
- state->ssl = SSL_new (state->ctx);
- SSL_set_fd (state->ssl, cnew->iofile);
- }
-#endif
- h = cnew;
+ close(h->newfd);
+#endif
+ h->newfd = -1;
+ }
+ xfree(cnew);
+ xfree(state);
+ return 0;
+ }
+ h->newfd = -1;
+ state->altbuf = 0;
+ state->altsize = state->altlen = 0;
+ state->towrite = state->written = -1;
+ state->complete = st->complete;
+#if HAVE_GETADDRINFO
+ state->ai = 0;
+#endif
+ cnew->state = CS_ST_ACCEPT;
+ h->state = CS_ST_IDLE;
+
+#if HAVE_GNUTLS_H
+ state->cred_ptr = st->cred_ptr;
+ state->session = 0;
+ if (st->cred_ptr)
+ {
+ int res;
+
+ (state->cred_ptr->ref)++;
+ gnutls_init(&state->session, GNUTLS_SERVER);
+ if (!state->session)
+ {
+ xfree(cnew);
+ xfree(state);
+ return 0;
+ }
+ res = gnutls_set_default_priority(state->session);
+ if (res != GNUTLS_E_SUCCESS)
+ {
+ xfree(cnew);
+ xfree(state);
+ return 0;
+ }
+ res = gnutls_credentials_set(state->session,
+ GNUTLS_CRD_CERTIFICATE,
+ st->cred_ptr->xcred);
+ if (res != GNUTLS_E_SUCCESS)
+ {
+ xfree(cnew);
+ xfree(state);
+ return 0;
+ }
+ /* cast to intermediate size_t to avoid GCC warning. */
+ gnutls_transport_set_ptr(state->session,
+ (gnutls_transport_ptr_t)
+ (size_t) cnew->iofile);
+ }
+#elif HAVE_OPENSSL_SSL_H
+ state->ctx = st->ctx;
+ state->ctx_alloc = 0;
+ state->ssl = st->ssl;
+ if (state->ctx)
+ {
+ state->ssl = SSL_new(state->ctx);
+ SSL_set_fd(state->ssl, cnew->iofile);
+ }
+#endif
+ state->connect_request_buf = 0;
+ state->connect_response_buf = 0;
+ h = cnew;