Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
client ssl connection added.
Browse files Browse the repository at this point in the history
This requires a SSL_CTX and must be set by the user
  • Loading branch information
StunMan authored and StunMan committed Mar 8, 2013
1 parent a7dabaa commit 439431a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions evhtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 439431a

Please sign in to comment.