/** * @short Creates a request object * @memberof onion_request_t * * @param op Listen point this request is listening to, to be able to read and write data */ onion_request *onion_request_new(onion_listen_point *op) { onion_request *req; req=onion_low_calloc(1, sizeof(onion_request)); req->connection.listen_point=op; req->connection.fd=-1; //req->connection=con; req->headers=onion_dict_new(); onion_dict_set_flags(req->headers, OD_ICASE); ONION_DEBUG0("Create request %p", req); if (op) { if (op->request_init) { if (op->request_init(req)<0) { ONION_DEBUG("Invalid request, closing"); onion_request_free(req); return NULL; } } else onion_listen_point_request_init_from_socket(req); } return req; }
/** * @short Initializes a connection on a request * @memberof onion_https_t * * Do the accept of the request, and the SSL handshake. * * @param req The request * @returns <0 in case of error. */ static int onion_https_request_init(onion_request *req){ onion_listen_point_request_init_from_socket(req); onion_https *https=(onion_https*)req->connection.listen_point->user_data; ONION_DEBUG("Accept new request, fd %d",req->connection.fd); gnutls_session_t session; gnutls_init (&session, GNUTLS_SERVER); gnutls_priority_set (session, https->priority_cache); gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, https->x509_cred); /* Set maximum compatibility mode. This is only suggested on public webservers * that need to trade security for compatibility */ gnutls_session_enable_compatibility_mode (session); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t)(long) req->connection.fd); int ret; do{ ret = gnutls_handshake (session); }while (ret < 0 && gnutls_error_is_fatal (ret) == 0); if (ret<0){ // could not handshake. assume an error. ONION_ERROR("Handshake has failed (%s)", gnutls_strerror (ret)); gnutls_bye (session, GNUTLS_SHUT_WR); gnutls_deinit(session); onion_listen_point_request_close_socket(req); return -1; } req->connection.user_data=(void*)session; return 0; }