From 439431ab3017158cf418bcf5706b606b6eb24321 Mon Sep 17 00:00:00 2001 From: StunMan Date: Fri, 8 Mar 2013 01:47:49 +0100 Subject: [PATCH] client ssl connection added. This requires a SSL_CTX and must be set by the user --- evhtp.c | 37 +++++++++++++++++++++++++++++++++++++ evhtp.h | 5 +++++ 2 files changed, 42 insertions(+) diff --git a/evhtp.c b/evhtp.c index 088609e..4b2092a 100644 --- a/evhtp.c +++ b/evhtp.c @@ -3621,6 +3621,43 @@ evhtp_connection_new(evbase_t * evbase, const char * addr, uint16_t port) { return conn; } +#ifndef DISABLE_SSL +evhtp_connection_t * +evhtp_connection_ssl_new(evbase_t * evbase, const char * addr, uint16_t port, evhtp_ssl_ctx_t* ctx) { + evhtp_connection_t * conn; + struct sockaddr_in sin; + + if (evbase == NULL) { + return NULL; + } + + if (!(conn = _evhtp_connection_new(NULL, -1, evhtp_type_client))) { + return NULL; + } + + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = inet_addr(addr); + sin.sin_port = htons(port); + + conn->ssl = SSL_new(ctx); + conn->evbase = evbase; + conn->bev = bufferevent_openssl_socket_new(evbase, -1, conn->ssl, BUFFEREVENT_SSL_CONNECTING, BEV_OPT_CLOSE_ON_FREE); + + bufferevent_enable(conn->bev, EV_READ); + + bufferevent_setcb(conn->bev, NULL, NULL, + _evhtp_connection_eventcb, conn); + + bufferevent_socket_connect(conn->bev, + (struct sockaddr *)&sin, sizeof(sin)); + + + return conn; +} +#endif + + + evhtp_request_t * evhtp_request_new(evhtp_callback_cb cb, void * arg) { evhtp_request_t * r; diff --git a/evhtp.h b/evhtp.h index 75185f0..9e49f3a 100644 --- a/evhtp.h +++ b/evhtp.h @@ -1062,6 +1062,11 @@ void evhtp_set_max_keepalive_requests(evhtp_t * htp, uint64_t num); */ evhtp_connection_t * evhtp_connection_new(evbase_t * evbase, const char * addr, uint16_t port); +#ifndef DISABLE_SSL +evhtp_connection_t * evhtp_connection_ssl_new(evbase_t * evbase, const char * addr, uint16_t port, evhtp_ssl_ctx_t* ctx); +#endif + + /** * @brief allocate a new request */