mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-09 03:22:45 +03:00
SSL flags now proper booleans
This commit is contained in:
@@ -164,7 +164,7 @@ struct httplib_request_info {
|
||||
int64_t content_length; /* Length (in bytes) of the request body,
|
||||
can be -1 if no length was given. */
|
||||
int remote_port; /* Client's port */
|
||||
int is_ssl; /* 1 if SSL-ed, 0 if not */
|
||||
bool has_ssl; /* 1 if SSL-ed, 0 if not */
|
||||
void *user_data; /* User data pointer passed to httplib_start() */
|
||||
void *conn_data; /* Connection-specific user data */
|
||||
|
||||
@@ -444,14 +444,8 @@ httplib_get_context(const struct httplib_connection *conn);
|
||||
LIBHTTP_API void *httplib_get_user_data(const struct httplib_context *ctx);
|
||||
|
||||
|
||||
/* Set user data for the current connection. */
|
||||
LIBHTTP_API void httplib_set_user_connection_data(struct httplib_connection *conn,
|
||||
void *data);
|
||||
|
||||
|
||||
/* Get user data set for the current connection. */
|
||||
LIBHTTP_API void *
|
||||
httplib_get_user_connection_data(const struct httplib_connection *conn);
|
||||
|
||||
|
||||
struct httplib_option {
|
||||
@@ -481,8 +475,8 @@ LIBHTTP_API const struct httplib_option *httplib_get_valid_options(void);
|
||||
struct httplib_server_ports {
|
||||
int protocol; /* 1 = IPv4, 2 = IPv6, 3 = both */
|
||||
int port; /* port number */
|
||||
int is_ssl; /* https port: 0 = no, 1 = yes */
|
||||
int is_redirect; /* redirect all requests: 0 = no, 1 = yes */
|
||||
bool has_ssl; /* https port: 0 = no, 1 = yes */
|
||||
bool has_redirect; /* redirect all requests: 0 = no, 1 = yes */
|
||||
int _reserved1;
|
||||
int _reserved2;
|
||||
int _reserved3;
|
||||
@@ -983,6 +977,7 @@ LIBHTTP_API int httplib_atomic_inc( volatile int *addr );
|
||||
LIBHTTP_API int httplib_base64_encode( const unsigned char *src, int src_len, char *dst, int dst_len );
|
||||
LIBHTTP_API int httplib_closedir( DIR *dir );
|
||||
LIBHTTP_API uint64_t httplib_get_random( void );
|
||||
LIBHTTP_API void * httplib_get_user_connection_data( const struct httplib_connection *conn );
|
||||
LIBHTTP_API int httplib_kill( pid_t pid, int sig_num );
|
||||
LIBHTTP_API int httplib_mkdir( const char *path, int mode );
|
||||
LIBHTTP_API DIR * httplib_opendir( const char *name );
|
||||
@@ -1008,6 +1003,7 @@ LIBHTTP_API struct dirent * httplib_readdir( DIR *dir );
|
||||
LIBHTTP_API int httplib_remove( const char *path );
|
||||
LIBHTTP_API void httplib_send_file( struct httplib_connection *conn, const char *path, const char *mime_type, const char *additional_headers );
|
||||
LIBHTTP_API void httplib_set_alloc_callback_func( httplib_alloc_callback_func log_func );
|
||||
LIBHTTP_API void httplib_set_user_connection_data( struct httplib_connection *conn, void *data );
|
||||
LIBHTTP_API int httplib_strcasecmp( const char *s1, const char *s2 );
|
||||
LIBHTTP_API const char * httplib_strcasestr( const char *big_str, const char *small_str );
|
||||
LIBHTTP_API char * httplib_strdup( const char *str );
|
||||
|
@@ -66,8 +66,8 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct htt
|
||||
|
||||
XX_httplib_set_close_on_exec( so.sock, XX_httplib_fc(ctx) );
|
||||
|
||||
so.is_ssl = listener->is_ssl;
|
||||
so.ssl_redir = listener->ssl_redir;
|
||||
so.has_ssl = listener->has_ssl;
|
||||
so.has_redir = listener->has_redir;
|
||||
|
||||
if ( getsockname( so.sock, &so.lsa.sa, &len ) != 0 ) {
|
||||
|
||||
|
@@ -114,7 +114,7 @@ static struct httplib_connection *httplib_connect_client_impl( const struct http
|
||||
|
||||
if ( getsockname( sock, psa, &len ) != 0 ) httplib_cry(conn, "%s: getsockname() failed: %s", __func__, strerror(ERRNO) );
|
||||
|
||||
conn->client.is_ssl = (use_ssl) ? 1 : 0;
|
||||
conn->client.has_ssl = (use_ssl) ? true : false;
|
||||
httplib_pthread_mutex_init( &conn->mutex, &XX_httplib_pthread_mutex_attr );
|
||||
|
||||
#ifndef NO_SSL
|
||||
|
@@ -30,7 +30,7 @@
|
||||
/*
|
||||
* struct httplib_connection *XX_httplib_fc( struct httplib_context *ctx );
|
||||
*
|
||||
* TThe function XX_httplib_fc() returns a fake connection structure specific
|
||||
* The function XX_httplib_fc() returns a fake connection structure specific
|
||||
* for logging if a connection is not applicable at the moment of logging.
|
||||
*/
|
||||
|
||||
|
@@ -42,7 +42,7 @@ int XX_httplib_get_first_ssl_listener_index( const struct httplib_context *ctx )
|
||||
|
||||
idx = -1;
|
||||
|
||||
if ( ctx != NULL ) for (i=0; idx == -1 && i < ctx->num_listening_sockets; i++) idx = ctx->listening_sockets[i].is_ssl ? ((int)(i)) : -1;
|
||||
if ( ctx != NULL ) for (i=0; idx == -1 && i < ctx->num_listening_sockets; i++) idx = (ctx->listening_sockets[i].has_ssl) ? ((int)(i)) : -1;
|
||||
|
||||
return idx;
|
||||
|
||||
|
@@ -46,8 +46,8 @@ int httplib_get_server_ports( const struct httplib_context *ctx, int size, struc
|
||||
? ntohs( ctx->listening_sockets[i].lsa.sin6.sin6_port )
|
||||
: ntohs( ctx->listening_sockets[i].lsa.sin.sin_port );
|
||||
|
||||
ports[cnt].is_ssl = ctx->listening_sockets[i].is_ssl;
|
||||
ports[cnt].is_redirect = ctx->listening_sockets[i].ssl_redir;
|
||||
ports[cnt].has_ssl = ctx->listening_sockets[i].has_ssl;
|
||||
ports[cnt].has_redirect = ctx->listening_sockets[i].has_redir;
|
||||
|
||||
if ( ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET ) ports[cnt++].protocol = 1;
|
||||
else if ( ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET6 ) ports[cnt++].protocol = 3;
|
||||
|
@@ -20,14 +20,20 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* ============
|
||||
* Release: 2.0
|
||||
*/
|
||||
|
||||
#include "httplib_main.h"
|
||||
|
||||
void * httplib_get_user_connection_data( const struct httplib_connection *conn ) {
|
||||
/*
|
||||
* void *httplib_get_user_connection_data( const struct httplib_connection *conn );
|
||||
*
|
||||
* The function httplib_get_user_connection_data() returns a pointer to user
|
||||
* data associated with a connection which was previously registered with a
|
||||
* call to httplib_set_user_connection_data(). In case of problems the value
|
||||
* NULL is returned.
|
||||
*/
|
||||
|
||||
LIBHTTP_API void * httplib_get_user_connection_data( const struct httplib_connection *conn ) {
|
||||
|
||||
if ( conn == NULL ) return NULL;
|
||||
|
||||
|
@@ -105,7 +105,7 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) {
|
||||
* 1.2. do a https redirect, if required. Do not decode URIs yet.
|
||||
*/
|
||||
|
||||
if ( ! conn->client.is_ssl && conn->client.ssl_redir ) {
|
||||
if ( ! conn->client.has_ssl && conn->client.has_redir ) {
|
||||
|
||||
ssl_index = XX_httplib_get_first_ssl_listener_index( conn->ctx );
|
||||
|
||||
|
@@ -519,9 +519,8 @@ struct socket {
|
||||
SOCKET sock; /* Listening socket */
|
||||
union usa lsa; /* Local socket address */
|
||||
union usa rsa; /* Remote socket address */
|
||||
unsigned char is_ssl; /* Is port SSL-ed */
|
||||
unsigned char ssl_redir; /* Is port supposed to redirect everything to SSL
|
||||
* port */
|
||||
bool has_ssl; /* Is port SSL-ed */
|
||||
bool has_redir; /* Is port supposed to redirect everything to SSL port */
|
||||
unsigned char in_use; /* Is valid */
|
||||
};
|
||||
|
||||
|
@@ -82,7 +82,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
|
||||
}
|
||||
|
||||
#if !defined(NO_SSL)
|
||||
if ( so.is_ssl && ctx->ssl_ctx == NULL ) {
|
||||
if ( so.has_ssl && ctx->ssl_ctx == NULL ) {
|
||||
|
||||
httplib_cry( XX_httplib_fc(ctx), "Cannot add SSL socket (entry %i). Is -ssl_certificate option set?", ports_total );
|
||||
continue;
|
||||
@@ -355,8 +355,8 @@ static bool parse_port_string( const struct vec *vec, struct socket *so, int *ip
|
||||
}
|
||||
|
||||
ch = vec->ptr[len]; /* Next character after the port number */
|
||||
so->is_ssl = ( ch == 's' );
|
||||
so->ssl_redir = ( ch == 'r' );
|
||||
so->has_ssl = ( ch == 's' );
|
||||
so->has_redir = ( ch == 'r' );
|
||||
|
||||
/*
|
||||
* Make sure the port is valid and vector ends with 's', 'r' or ','
|
||||
|
@@ -20,9 +20,6 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* ============
|
||||
* Release: 2.0
|
||||
*/
|
||||
|
||||
#include "httplib_main.h"
|
||||
@@ -35,7 +32,7 @@
|
||||
* the data, the link between the connection and data is removed.
|
||||
*/
|
||||
|
||||
void httplib_set_user_connection_data( struct httplib_connection *conn, void *data ) {
|
||||
LIBHTTP_API void httplib_set_user_connection_data( struct httplib_connection *conn, void *data ) {
|
||||
|
||||
if ( conn != NULL ) conn->request_info.conn_data = data;
|
||||
|
||||
|
@@ -20,9 +20,6 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* ============
|
||||
* Release: 2.0
|
||||
*/
|
||||
|
||||
#include "httplib_main.h"
|
||||
|
@@ -111,19 +111,17 @@ static void do_ssi_include(struct httplib_connection *conn, const char *ssi, cha
|
||||
if ( ! XX_httplib_fopen( conn, path, "rb", &file ) ) {
|
||||
|
||||
httplib_cry( conn, "Cannot open SSI #include: [%s]: fopen(%s): %s", tag, path, strerror(ERRNO) );
|
||||
return;
|
||||
}
|
||||
|
||||
else {
|
||||
XX_httplib_fclose_on_exec( & file, conn );
|
||||
|
||||
ssi_ext = conn->ctx->cfg[SSI_EXTENSIONS];
|
||||
|
||||
if ( ssi_ext != NULL && XX_httplib_match_prefix( ssi_ext, strlen( ssi_ext ), path ) > 0 ) send_ssi_file( conn, path, &file, include_level+1 );
|
||||
|
||||
else XX_httplib_send_file_data(conn, &file, 0, INT64_MAX);
|
||||
else XX_httplib_send_file_data( conn, &file, 0, INT64_MAX );
|
||||
|
||||
XX_httplib_fclose( & file );
|
||||
}
|
||||
|
||||
} /* do_ssi_include */
|
||||
|
||||
|
@@ -129,9 +129,9 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) {
|
||||
|
||||
XX_httplib_sockaddr_to_string( conn->request_info.remote_addr, sizeof(conn->request_info.remote_addr), &conn->client.rsa );
|
||||
|
||||
conn->request_info.is_ssl = conn->client.is_ssl;
|
||||
conn->request_info.has_ssl = conn->client.has_ssl;
|
||||
|
||||
if ( conn->client.is_ssl ) {
|
||||
if ( conn->client.has_ssl ) {
|
||||
#ifndef NO_SSL
|
||||
/*
|
||||
* HTTPS connection
|
||||
|
Reference in New Issue
Block a user