1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-06 05:02:40 +03:00

Added debug levels to warnings

This commit is contained in:
Lammert Bies
2016-12-29 03:10:24 +01:00
parent 0e4deecb3e
commit a03f2e301f
38 changed files with 118 additions and 111 deletions

View File

@@ -924,7 +924,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_base64_encode( const unsigned char *src, int src_len, char *dst, int dst_len );
LIBHTTP_API unsigned httplib_check_feature( unsigned feature ); LIBHTTP_API unsigned httplib_check_feature( unsigned feature );
LIBHTTP_API int httplib_closedir( DIR *dir ); LIBHTTP_API int httplib_closedir( DIR *dir );
LIBHTTP_API void httplib_cry( const struct httplib_context *ctx, const struct httplib_connection *conn, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(3, 4); LIBHTTP_API void httplib_cry( enum debug_level_t debug_level, const struct httplib_context *ctx, const struct httplib_connection *conn, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(4, 5);
LIBHTTP_API char * httplib_error_string( int error_code, char *buf, size_t buf_len ); LIBHTTP_API char * httplib_error_string( int error_code, char *buf, size_t buf_len );
LIBHTTP_API const char * httplib_get_builtin_mime_type( const char *file_name ); LIBHTTP_API const char * httplib_get_builtin_mime_type( const char *file_name );
LIBHTTP_API enum debug_level_t httplib_get_debug_level( struct httplib_context *ctx ); LIBHTTP_API enum debug_level_t httplib_get_debug_level( struct httplib_context *ctx );

View File

@@ -54,7 +54,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct htt
if ( ! XX_httplib_check_acl( ctx, ntohl(*(uint32_t *)&so.rsa.sin.sin_addr )) ) { if ( ! XX_httplib_check_acl( ctx, ntohl(*(uint32_t *)&so.rsa.sin.sin_addr )) ) {
XX_httplib_sockaddr_to_string( src_addr, sizeof(src_addr), &so.rsa ); XX_httplib_sockaddr_to_string( src_addr, sizeof(src_addr), &so.rsa );
httplib_cry( ctx, NULL, "%s: %s is not allowed to connect", __func__, src_addr ); httplib_cry( DEBUG_LEVEL_INFO, ctx, NULL, "%s: %s is not allowed to connect", __func__, src_addr );
closesocket( so.sock ); closesocket( so.sock );
so.sock = INVALID_SOCKET; so.sock = INVALID_SOCKET;
} }
@@ -72,7 +72,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct htt
if ( getsockname( so.sock, &so.lsa.sa, &len ) != 0 ) { if ( getsockname( so.sock, &so.lsa.sa, &len ) != 0 ) {
httplib_cry( ctx, NULL, "%s: getsockname() failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: getsockname() failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
/* /*
@@ -86,7 +86,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct htt
if ( setsockopt( so.sock, SOL_SOCKET, SO_KEEPALIVE, (SOCK_OPT_TYPE)&on, sizeof(on) ) != 0 ) { if ( setsockopt( so.sock, SOL_SOCKET, SO_KEEPALIVE, (SOCK_OPT_TYPE)&on, sizeof(on) ) != 0 ) {
httplib_cry( ctx, NULL, "%s: setsockopt(SOL_SOCKET SO_KEEPALIVE) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: setsockopt(SOL_SOCKET SO_KEEPALIVE) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
/* /*
@@ -100,7 +100,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct htt
if ( ctx->tcp_nodelay && XX_httplib_set_tcp_nodelay( so.sock, 1 ) != 0 ) { if ( ctx->tcp_nodelay && XX_httplib_set_tcp_nodelay( so.sock, 1 ) != 0 ) {
httplib_cry( ctx, NULL, "%s: setsockopt(IPPROTO_TCP TCP_NODELAY) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: setsockopt(IPPROTO_TCP TCP_NODELAY) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
if ( ctx->request_timeout > 0 ) XX_httplib_set_sock_timeout( so.sock, ctx->request_timeout ); if ( ctx->request_timeout > 0 ) XX_httplib_set_sock_timeout( so.sock, ctx->request_timeout );

View File

@@ -79,7 +79,7 @@ void XX_httplib_addenv( struct cgi_environment *env, const char *fmt, ... ) {
* Out of memory * Out of memory
*/ */
httplib_cry( env->conn->ctx, env->conn, "%s: Cannot allocate memory for CGI variable [%s]", __func__, fmt ); httplib_cry( DEBUG_LEVEL_ERROR, env->conn->ctx, env->conn, "%s: Cannot allocate memory for CGI variable [%s]", __func__, fmt );
return; return;
} }
@@ -133,7 +133,7 @@ void XX_httplib_addenv( struct cgi_environment *env, const char *fmt, ... ) {
if ( space < 2 ) { if ( space < 2 ) {
httplib_cry( env->conn->ctx, env->conn, "%s: Cannot register CGI variable [%s]", __func__, fmt ); httplib_cry( DEBUG_LEVEL_ERROR, env->conn->ctx, env->conn, "%s: Cannot register CGI variable [%s]", __func__, fmt );
return; return;
} }

View File

@@ -59,7 +59,7 @@ int XX_httplib_check_acl( struct httplib_context *ctx, uint32_t remote_ip ) {
if ( (flag != '+' && flag != '-') || XX_httplib_parse_net( &vec.ptr[1], &net, &mask ) == 0 ) { if ( (flag != '+' && flag != '-') || XX_httplib_parse_net( &vec.ptr[1], &net, &mask ) == 0 ) {
httplib_cry( ctx, NULL, "%s: subnet must be [+|-]x.x.x.x[/x]", __func__ ); httplib_cry( DEBUG_LEVEL_WARNING, ctx, NULL, "%s: subnet must be [+|-]x.x.x.x[/x]", __func__ );
return -1; return -1;
} }

View File

@@ -54,7 +54,7 @@ bool XX_httplib_check_authorization( struct httplib_connection *conn, const char
if ( truncated || ! XX_httplib_fopen( conn, fname, "r", &file ) ) { if ( truncated || ! XX_httplib_fopen( conn, fname, "r", &file ) ) {
httplib_cry( conn->ctx, conn, "%s: cannot open %s: %s", __func__, fname, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_WARNING, conn->ctx, conn, "%s: cannot open %s: %s", __func__, fname, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
break; break;
} }

View File

@@ -67,7 +67,7 @@ void XX_httplib_close_socket_gracefully( struct httplib_connection *conn ) {
else { else {
if ( setsockopt( conn->client.sock, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(linger) ) != 0 ) { if ( setsockopt( conn->client.sock, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(linger) ) != 0 ) {
httplib_cry( conn->ctx, conn, "%s: setsockopt(SOL_SOCKET SO_LINGER) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: setsockopt(SOL_SOCKET SO_LINGER) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
} }

View File

@@ -112,7 +112,7 @@ static struct httplib_connection *httplib_connect_client_impl( const struct http
conn->client.sock = sock; conn->client.sock = sock;
conn->client.lsa = sa; conn->client.lsa = sa;
if ( getsockname( sock, psa, &len ) != 0 ) httplib_cry( &fake_ctx, conn, "%s: getsockname() failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); if ( getsockname( sock, psa, &len ) != 0 ) httplib_cry( DEBUG_LEVEL_ERROR, &fake_ctx, conn, "%s: getsockname() failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
conn->client.has_ssl = (use_ssl) ? true : false; conn->client.has_ssl = (use_ssl) ? true : false;
httplib_pthread_mutex_init( &conn->mutex, &XX_httplib_pthread_mutex_attr ); httplib_pthread_mutex_init( &conn->mutex, &XX_httplib_pthread_mutex_attr );

View File

@@ -26,14 +26,14 @@
#include "httplib_ssl.h" #include "httplib_ssl.h"
/* /*
* void httplib_cry( const struct httplib_context *ctx, const struct httplib_connection *conn, const char *fmt, ... ); * void httplib_cry( enum debug_level_t debug_level, const struct httplib_context *ctx, const struct httplib_connection *conn, const char *fmt, ... );
* *
* The function httplib_cry() prints a formatted error message to the opened * The function httplib_cry() prints a formatted error message to the opened
* error log stream. It first tries to use a user supplied error handler. If * error log stream. It first tries to use a user supplied error handler. If
* that doesn't work, the alternative is to write to an error log file. * that doesn't work, the alternative is to write to an error log file.
*/ */
void httplib_cry( const struct httplib_context *ctx, const struct httplib_connection *conn, const char *fmt, ... ) { void httplib_cry( enum debug_level_t debug_level, const struct httplib_context *ctx, const struct httplib_connection *conn, const char *fmt, ... ) {
char buf[MG_BUF_LEN]; char buf[MG_BUF_LEN];
char src_addr[IP_ADDR_STR_LEN]; char src_addr[IP_ADDR_STR_LEN];
@@ -50,6 +50,13 @@ void httplib_cry( const struct httplib_context *ctx, const struct httplib_connec
if ( ctx == NULL ) return; if ( ctx == NULL ) return;
/*
* Check if the message is severe enough to display. This is controlled
* with a context specific debug level.
*/
if ( debug_level > ctx->debug_level ) return;
/* /*
* Gather all the information from the parameters of this function and * Gather all the information from the parameters of this function and
* create a NULL terminated string buffer with the error message. * create a NULL terminated string buffer with the error message.

View File

@@ -39,7 +39,7 @@ void XX_httplib_fclose_on_exec( struct file *filep, struct httplib_connection *c
if ( fcntl( fileno( filep->fp ), F_SETFD, FD_CLOEXEC) != 0 ) { if ( fcntl( fileno( filep->fp ), F_SETFD, FD_CLOEXEC) != 0 ) {
if ( conn != NULL && conn->ctx != NULL ) httplib_cry( conn->ctx, conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); if ( conn != NULL && conn->ctx != NULL ) httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
#endif #endif

View File

@@ -118,7 +118,7 @@ const char *httplib_get_response_code_text( struct httplib_connection *conn, int
* This error code is unknown. This should not happen. * This error code is unknown. This should not happen.
*/ */
if ( conn != NULL && conn->ctx != NULL ) httplib_cry( conn->ctx, conn, "Unknown HTTP response code: %u", response_code ); if ( conn != NULL && conn->ctx != NULL ) httplib_cry( DEBUG_LEVEL_INFO, conn->ctx, conn, "Unknown HTTP response code: %u", response_code );
/* /*
* Return at least a category according to RFC 2616 Section 10. * Return at least a category according to RFC 2616 Section 10.

View File

@@ -85,7 +85,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char
if ( truncated ) { if ( truncated ) {
httplib_cry( conn->ctx, conn, "Error: CGI program \"%s\": Path too long", prog ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Path too long", prog );
XX_httplib_send_http_error( conn, 500, "Error: %s", "CGI path too long" ); XX_httplib_send_http_error( conn, 500, "Error: %s", "CGI path too long" );
goto done; goto done;
@@ -106,7 +106,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char
if ( pipe(fdin) != 0 || pipe(fdout) != 0 || pipe(fderr) != 0 ) { if ( pipe(fdin) != 0 || pipe(fdout) != 0 || pipe(fderr) != 0 ) {
status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN );
httplib_cry( conn->ctx, conn, "Error: CGI program \"%s\": Can not create CGI pipes: %s", prog, status ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not create CGI pipes: %s", prog, status );
XX_httplib_send_http_error( conn, 500, "Error: Cannot create CGI pipe: %s", status ); XX_httplib_send_http_error( conn, 500, "Error: Cannot create CGI pipe: %s", status );
goto done; goto done;
@@ -117,7 +117,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char
if ( pid == (pid_t)-1 ) { if ( pid == (pid_t)-1 ) {
status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN );
httplib_cry( conn->ctx, conn, "Error: CGI program \"%s\": Can not spawn CGI process: %s", prog, status ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not spawn CGI process: %s", prog, status );
XX_httplib_send_http_error( conn, 500, "Error: Cannot spawn CGI process [%s]: %s", prog, status ); XX_httplib_send_http_error( conn, 500, "Error: Cannot spawn CGI process [%s]: %s", prog, status );
goto done; goto done;
@@ -152,7 +152,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char
if ( (in = fdopen( fdin[1], "wb" )) == NULL ) { if ( (in = fdopen( fdin[1], "wb" )) == NULL ) {
status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN );
httplib_cry( conn->ctx, conn, "Error: CGI program \"%s\": Can not open stdin: %s", prog, status ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not open stdin: %s", prog, status );
XX_httplib_send_http_error( conn, 500, "Error: CGI can not open fdin\nfopen: %s", status ); XX_httplib_send_http_error( conn, 500, "Error: CGI can not open fdin\nfopen: %s", status );
goto done; goto done;
@@ -161,7 +161,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char
if ( (out = fdopen( fdout[0], "rb" )) == NULL ) { if ( (out = fdopen( fdout[0], "rb" )) == NULL ) {
status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN );
httplib_cry( conn->ctx, conn, "Error: CGI program \"%s\": Can not open stdout: %s", prog, status ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not open stdout: %s", prog, status );
XX_httplib_send_http_error( conn, 500, "Error: CGI can not open fdout\nfopen: %s", status ); XX_httplib_send_http_error( conn, 500, "Error: CGI can not open fdout\nfopen: %s", status );
goto done; goto done;
@@ -170,7 +170,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char
if ( (err = fdopen( fderr[0], "rb" )) == NULL ) { if ( (err = fdopen( fderr[0], "rb" )) == NULL ) {
status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN );
httplib_cry( conn->ctx, conn, "Error: CGI program \"%s\": Can not open stderr: %s", prog, status ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not open stderr: %s", prog, status );
XX_httplib_send_http_error( conn, 500, "Error: CGI can not open fdout\nfopen: %s", status ); XX_httplib_send_http_error( conn, 500, "Error: CGI can not open fdout\nfopen: %s", status );
goto done; goto done;
@@ -194,7 +194,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char
* Error sending the body data * Error sending the body data
*/ */
httplib_cry( conn->ctx, conn, "Error: CGI program \"%s\": Forward body data failed", prog ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Forward body data failed", prog );
goto done; goto done;
} }
@@ -222,7 +222,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char
if ( buf == NULL ) { if ( buf == NULL ) {
XX_httplib_send_http_error( conn, 500, "Error: Not enough memory for CGI buffer (%u bytes)", (unsigned int)buflen ); XX_httplib_send_http_error( conn, 500, "Error: Not enough memory for CGI buffer (%u bytes)", (unsigned int)buflen );
httplib_cry( conn->ctx, conn, "Error: CGI program \"%s\": Not enough memory for buffer (%u " "bytes)", prog, (unsigned int)buflen ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Not enough memory for buffer (%u " "bytes)", prog, (unsigned int)buflen );
goto done; goto done;
} }
@@ -239,12 +239,12 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char
if ( i > 0 ) { if ( i > 0 ) {
httplib_cry( conn->ctx, conn, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf );
XX_httplib_send_http_error( conn, 500, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf ); XX_httplib_send_http_error( conn, 500, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf );
} }
else { else {
httplib_cry( conn->ctx, conn, "Error: CGI program sent malformed or too big " "(>%u bytes) HTTP headers: [%.*s]", (unsigned)buflen, data_len, buf ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program sent malformed or too big " "(>%u bytes) HTTP headers: [%.*s]", (unsigned)buflen, data_len, buf );
XX_httplib_send_http_error( conn, XX_httplib_send_http_error( conn,
500, 500,

View File

@@ -55,7 +55,7 @@ static int url_encoded_field_found(const struct httplib_connection *conn,
* Log error message and skip this field. * Log error message and skip this field.
*/ */
httplib_cry( conn->ctx, conn, "%s: Cannot decode filename", __func__ ); httplib_cry( DEBUG_LEVEL_WARNING, conn->ctx, conn, "%s: Cannot decode filename", __func__ );
return FORM_FIELD_STORAGE_SKIP; return FORM_FIELD_STORAGE_SKIP;
} }
@@ -67,7 +67,7 @@ static int url_encoded_field_found(const struct httplib_connection *conn,
if ( fdh->field_get == NULL ) { if ( fdh->field_get == NULL ) {
httplib_cry( conn->ctx, conn, "%s: Function \"Get\" not available", __func__ ); httplib_cry( DEBUG_LEVEL_WARNING, conn->ctx, conn, "%s: Function \"Get\" not available", __func__ );
return FORM_FIELD_STORAGE_SKIP; return FORM_FIELD_STORAGE_SKIP;
} }
} }
@@ -75,7 +75,7 @@ static int url_encoded_field_found(const struct httplib_connection *conn,
if ( fdh->field_store == NULL ) { if ( fdh->field_store == NULL ) {
httplib_cry( conn->ctx, conn, "%s: Function \"Store\" not available", __func__ ); httplib_cry( DEBUG_LEVEL_WARNING, conn->ctx, conn, "%s: Function \"Store\" not available", __func__ );
return FORM_FIELD_STORAGE_SKIP; return FORM_FIELD_STORAGE_SKIP;
} }
} }
@@ -103,7 +103,7 @@ static int url_encoded_field_get(const struct httplib_connection *conn,
* Log error message and stop parsing the form data. * Log error message and stop parsing the form data.
*/ */
httplib_cry( conn->ctx, conn, "%s: Not enough memory (required: %lu)", __func__, (unsigned long)(value_len + 1)); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Not enough memory (required: %lu)", __func__, (unsigned long)(value_len + 1));
return FORM_FIELD_STORAGE_ABORT; return FORM_FIELD_STORAGE_ABORT;
} }
@@ -282,7 +282,7 @@ int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_
size_t n = (size_t)fwrite(val, 1, (size_t)vallen, fstore.fp); size_t n = (size_t)fwrite(val, 1, (size_t)vallen, fstore.fp);
if ((n != (size_t)vallen) || (ferror(fstore.fp))) { if ((n != (size_t)vallen) || (ferror(fstore.fp))) {
httplib_cry( conn->ctx, conn, "%s: Cannot write file %s", __func__, path ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Cannot write file %s", __func__, path );
fclose( fstore.fp ); fclose( fstore.fp );
fstore.fp = NULL; fstore.fp = NULL;
XX_httplib_remove_bad_file( conn, path ); XX_httplib_remove_bad_file( conn, path );
@@ -302,14 +302,14 @@ int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_
} }
else { else {
httplib_cry( conn->ctx, conn, "%s: Error saving file %s", __func__, path ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Error saving file %s", __func__, path );
XX_httplib_remove_bad_file( conn, path ); XX_httplib_remove_bad_file( conn, path );
} }
fstore.fp = NULL; fstore.fp = NULL;
} }
} else httplib_cry( conn->ctx, conn, "%s: Cannot create file %s", __func__, path ); } else httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Cannot create file %s", __func__, path );
} }
/* /*
@@ -410,7 +410,7 @@ int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_
if (XX_httplib_fopen(conn, path, "wb", &fstore) == 0) fstore.fp = NULL; if (XX_httplib_fopen(conn, path, "wb", &fstore) == 0) fstore.fp = NULL;
file_size = 0; file_size = 0;
if (!fstore.fp) httplib_cry( conn->ctx, conn, "%s: Cannot create file %s", __func__, path); if (!fstore.fp) httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Cannot create file %s", __func__, path);
} }
get_block = 0; get_block = 0;
@@ -455,7 +455,7 @@ int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_
if ( fstore.fp ) { if ( fstore.fp ) {
size_t n = (size_t)fwrite(val, 1, (size_t)vallen, fstore.fp); size_t n = (size_t)fwrite(val, 1, (size_t)vallen, fstore.fp);
if ((n != (size_t)vallen) || (ferror(fstore.fp))) { if ((n != (size_t)vallen) || (ferror(fstore.fp))) {
httplib_cry( conn->ctx, conn, "%s: Cannot write file %s", __func__, path); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Cannot write file %s", __func__, path);
fclose(fstore.fp); fclose(fstore.fp);
fstore.fp = NULL; fstore.fp = NULL;
XX_httplib_remove_bad_file(conn, path); XX_httplib_remove_bad_file(conn, path);
@@ -506,7 +506,7 @@ int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_
} }
else { else {
httplib_cry( conn->ctx, conn, "%s: Error saving file %s", __func__, path ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Error saving file %s", __func__, path );
XX_httplib_remove_bad_file( conn, path ); XX_httplib_remove_bad_file( conn, path );
} }
@@ -708,7 +708,7 @@ int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_
if ( XX_httplib_fopen( conn, path, "wb", &fstore ) == 0 ) fstore.fp = NULL; if ( XX_httplib_fopen( conn, path, "wb", &fstore ) == 0 ) fstore.fp = NULL;
file_size = 0; file_size = 0;
if ( ! fstore.fp ) httplib_cry( conn->ctx, conn, "%s: Cannot create file %s", __func__, path ); if ( ! fstore.fp ) httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Cannot create file %s", __func__, path );
} }
get_block = 0; get_block = 0;
@@ -752,7 +752,7 @@ int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_
if ( n != towrite || ferror( fstore.fp ) ) { if ( n != towrite || ferror( fstore.fp ) ) {
httplib_cry( conn->ctx, conn, "%s: Cannot write file %s", __func__, path ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Cannot write file %s", __func__, path );
fclose( fstore.fp ); fclose( fstore.fp );
fstore.fp = NULL; fstore.fp = NULL;
XX_httplib_remove_bad_file( conn, path ); XX_httplib_remove_bad_file( conn, path );
@@ -808,7 +808,7 @@ int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_
if ( n != towrite || ferror( fstore.fp ) ) { if ( n != towrite || ferror( fstore.fp ) ) {
httplib_cry( conn->ctx, conn, "%s: Cannot write file %s", __func__, path ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Cannot write file %s", __func__, path );
fclose( fstore.fp ); fclose( fstore.fp );
fstore.fp = NULL; fstore.fp = NULL;
XX_httplib_remove_bad_file( conn, path ); XX_httplib_remove_bad_file( conn, path );
@@ -832,7 +832,7 @@ int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_
} }
else { else {
httplib_cry( conn->ctx, conn, "%s: Error saving file %s", __func__, path ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Error saving file %s", __func__, path );
XX_httplib_remove_bad_file( conn, path ); XX_httplib_remove_bad_file( conn, path );
} }
fstore.fp = NULL; fstore.fp = NULL;

View File

@@ -116,7 +116,7 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) {
*/ */
XX_httplib_send_http_error( conn, 503, "%s", "Error: SSL forward not configured properly" ); XX_httplib_send_http_error( conn, 503, "%s", "Error: SSL forward not configured properly" );
httplib_cry( conn->ctx, conn, "Can not redirect to SSL, no SSL port available" ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Can not redirect to SSL, no SSL port available" );
} }
return; return;

View File

@@ -78,7 +78,7 @@ int XX_httplib_initialize_ssl( struct httplib_context *ctx ) {
if ( (XX_httplib_ssl_mutexes = httplib_malloc( size )) == NULL ) { if ( (XX_httplib_ssl_mutexes = httplib_malloc( size )) == NULL ) {
httplib_cry( ctx, NULL, "%s: cannot allocate mutexes: %s", __func__, XX_httplib_ssl_error() ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot allocate mutexes: %s", __func__, XX_httplib_ssl_error() );
return 0; return 0;
} }

View File

@@ -82,7 +82,7 @@ void *XX_httplib_load_dll( struct httplib_context *ctx, const char *dll_name, st
if ( dll_handle == NULL ) { if ( dll_handle == NULL ) {
httplib_cry( ctx, NULL, "%s: cannot load %s", __func__, dll_name ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot load %s", __func__, dll_name );
return NULL; return NULL;
} }
@@ -109,7 +109,7 @@ void *XX_httplib_load_dll( struct httplib_context *ctx, const char *dll_name, st
if ( u.fp == NULL ) { if ( u.fp == NULL ) {
httplib_cry( ctx, NULL, "%s: %s: cannot find %s", __func__, dll_name, fp->name ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: %s: cannot find %s", __func__, dll_name, fp->name );
dlclose( dll_handle ); dlclose( dll_handle );
return NULL; return NULL;

View File

@@ -58,7 +58,7 @@ void XX_httplib_mkcol( struct httplib_connection *conn, const char *path ) {
if ( ! XX_httplib_stat( conn, path, & de.file ) ) { if ( ! XX_httplib_stat( conn, path, & de.file ) ) {
httplib_cry( conn->ctx, conn, "%s: XX_httplib_stat(%s) failed: %s", __func__, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_WARNING, conn->ctx, conn, "%s: XX_httplib_stat(%s) failed: %s", __func__, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
if ( de.file.last_modified ) { if ( de.file.last_modified ) {

View File

@@ -138,7 +138,7 @@ void XX_httplib_prepare_cgi_environment( struct httplib_connection *conn, const
XX_httplib_snprintf( conn, &truncated, http_var_name, sizeof(http_var_name), "HTTP_%s", conn->request_info.http_headers[i].name ); XX_httplib_snprintf( conn, &truncated, http_var_name, sizeof(http_var_name), "HTTP_%s", conn->request_info.http_headers[i].name );
if ( truncated ) { if ( truncated ) {
httplib_cry( conn->ctx, conn, "%s: HTTP header variable too long [%s]", __func__, conn->request_info.http_headers[i].name ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: HTTP header variable too long [%s]", __func__, conn->request_info.http_headers[i].name );
continue; continue;
} }

View File

@@ -91,7 +91,7 @@ bool XX_httplib_read_auth_file( struct file *filep, struct read_auth_file_struct
XX_httplib_fclose( &fp ); XX_httplib_fclose( &fp );
} }
else httplib_cry( workdata->conn->ctx, workdata->conn, "%s: cannot open authorization file: %s", __func__, workdata->buf ); else httplib_cry( DEBUG_LEVEL_ERROR, workdata->conn->ctx, workdata->conn, "%s: cannot open authorization file: %s", __func__, workdata->buf );
continue; continue;
} }
@@ -100,7 +100,7 @@ bool XX_httplib_read_auth_file( struct file *filep, struct read_auth_file_struct
* future) * future)
*/ */
httplib_cry( workdata->conn->ctx, workdata->conn, "%s: syntax error in authorization file: %s", __func__, workdata->buf ); httplib_cry( DEBUG_LEVEL_ERROR, workdata->conn->ctx, workdata->conn, "%s: syntax error in authorization file: %s", __func__, workdata->buf );
continue; continue;
} }
@@ -108,7 +108,7 @@ bool XX_httplib_read_auth_file( struct file *filep, struct read_auth_file_struct
if ( workdata->f_domain == NULL ) { if ( workdata->f_domain == NULL ) {
httplib_cry( workdata->conn->ctx, workdata->conn, "%s: syntax error in authorization file: %s", __func__, workdata->buf ); httplib_cry( DEBUG_LEVEL_ERROR, workdata->conn->ctx, workdata->conn, "%s: syntax error in authorization file: %s", __func__, workdata->buf );
continue; continue;
} }
@@ -119,7 +119,7 @@ bool XX_httplib_read_auth_file( struct file *filep, struct read_auth_file_struct
if ( workdata->f_ha1 == NULL ) { if ( workdata->f_ha1 == NULL ) {
httplib_cry( workdata->conn->ctx, workdata->conn, "%s: syntax error in authorization file: %s", __func__, workdata->buf ); httplib_cry( DEBUG_LEVEL_ERROR, workdata->conn->ctx, workdata->conn, "%s: syntax error in authorization file: %s", __func__, workdata->buf );
continue; continue;
} }

View File

@@ -96,7 +96,7 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock
if ( conn->data_len < conn->request_len ) { if ( conn->data_len < conn->request_len ) {
httplib_cry( conn->ctx, conn, "websocket error: data len less than request len, closing connection" ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "websocket error: data len less than request len, closing connection" );
break; break;
} }
@@ -145,7 +145,7 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock
* connection * connection
*/ */
httplib_cry( conn->ctx, conn, "websocket out of memory; closing connection" ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "websocket out of memory; closing connection" );
break; break;
} }
} }
@@ -161,7 +161,7 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock
if ( body_len < header_len ) { if ( body_len < header_len ) {
httplib_cry( conn->ctx, conn, "websocket error: body len less than header len, closing connection" ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "websocket error: body len less than header len, closing connection" );
break; break;
} }
@@ -195,7 +195,7 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock
if (error) { if (error) {
httplib_cry( conn->ctx, conn, "Websocket pull failed; closing connection" ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Websocket pull failed; closing connection" );
break; break;
} }

View File

@@ -66,7 +66,7 @@ int XX_httplib_refresh_trust( struct httplib_connection *conn ) {
if ( SSL_CTX_load_verify_locations( conn->ctx->ssl_ctx, conn->ctx->ssl_ca_file, conn->ctx->ssl_ca_path ) != 1 ) { if ( SSL_CTX_load_verify_locations( conn->ctx->ssl_ctx, conn->ctx->ssl_ca_file, conn->ctx->ssl_ca_path ) != 1 ) {
httplib_cry( conn->ctx, conn, httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn,
"SSL_CTX_load_verify_locations error: %s " "SSL_CTX_load_verify_locations error: %s "
"ssl_verify_peer requires setting " "ssl_verify_peer requires setting "
"either ssl_ca_path or ssl_ca_file. Is any of them " "either ssl_ca_path or ssl_ca_file. Is any of them "

View File

@@ -38,6 +38,6 @@ void XX_httplib_remove_bad_file( const struct httplib_connection *conn, const ch
int r = httplib_remove( path ); int r = httplib_remove( path );
if ( r != 0 && conn != NULL && conn->ctx != NULL ) httplib_cry( conn->ctx, conn, "%s: Cannot remove invalid file %s", __func__, path ); if ( r != 0 && conn != NULL && conn->ctx != NULL ) httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Cannot remove invalid file %s", __func__, path );
} /* XX_httplib_remove_bad_file */ } /* XX_httplib_remove_bad_file */

View File

@@ -85,7 +85,7 @@ int XX_httplib_remove_directory( struct httplib_connection *conn, const char *di
if ( ! XX_httplib_stat( conn, path, & de.file ) ) { if ( ! XX_httplib_stat( conn, path, & de.file ) ) {
httplib_cry( conn->ctx, conn, "%s: XX_httplib_stat(%s) failed: %s", __func__, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_WARNING, conn->ctx, conn, "%s: XX_httplib_stat(%s) failed: %s", __func__, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
ok = 0; ok = 0;
} }
if ( de.file.membuf == NULL ) { if ( de.file.membuf == NULL ) {

View File

@@ -66,7 +66,7 @@ int XX_httplib_scan_directory( struct httplib_connection *conn, const char *dir,
if ( ! XX_httplib_stat( conn, path, &de.file ) ) { if ( ! XX_httplib_stat( conn, path, &de.file ) ) {
httplib_cry( conn->ctx, conn, "%s: XX_httplib_stat(%s) failed: %s", __func__, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_WARNING, conn->ctx, conn, "%s: XX_httplib_stat(%s) failed: %s", __func__, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
de.file_name = dp->d_name; de.file_name = dp->d_name;

View File

@@ -140,7 +140,7 @@ void XX_httplib_send_file_data( struct httplib_connection *conn, struct file *fi
#endif #endif
if ( offset > 0 && fseeko( filep->fp, offset, SEEK_SET ) != 0 ) { if ( offset > 0 && fseeko( filep->fp, offset, SEEK_SET ) != 0 ) {
httplib_cry( conn->ctx, conn, "%s: fseeko() failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: fseeko() failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
XX_httplib_send_http_error( conn, 500, "%s", "Error: Unable to access file at requested position." ); XX_httplib_send_http_error( conn, 500, "%s", "Error: Unable to access file at requested position." );
} }

View File

@@ -45,7 +45,7 @@ void XX_httplib_set_close_on_exec( SOCKET fd, const struct httplib_context *ctx
if ( fcntl( fd, F_SETFD, FD_CLOEXEC ) != 0 ) { if ( fcntl( fd, F_SETFD, FD_CLOEXEC ) != 0 ) {
if ( ctx != NULL ) httplib_cry( ctx, NULL, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); if ( ctx != NULL ) httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
#endif /* _WIN32 */ #endif /* _WIN32 */

View File

@@ -46,7 +46,7 @@ int XX_httplib_set_gpass_option( struct httplib_context *ctx ) {
if ( path != NULL && ! XX_httplib_stat( NULL, path, &file ) ) { if ( path != NULL && ! XX_httplib_stat( NULL, path, &file ) ) {
httplib_cry( ctx, NULL, "Cannot open %s: %s", path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "Cannot open %s: %s", path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
return 0; return 0;
} }
return 1; return 1;

View File

@@ -140,7 +140,7 @@ void XX_httplib_set_handler_type( struct httplib_context *ctx, const char *uri,
if ( tmp_rh == NULL ) { if ( tmp_rh == NULL ) {
httplib_unlock_context( ctx ); httplib_unlock_context( ctx );
httplib_cry( ctx, NULL, "%s", "Cannot create new request handler struct, OOM" ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s", "Cannot create new request handler struct, OOM" );
return; return;
} }
@@ -151,7 +151,7 @@ void XX_httplib_set_handler_type( struct httplib_context *ctx, const char *uri,
httplib_unlock_context( ctx ); httplib_unlock_context( ctx );
tmp_rh = httplib_free( tmp_rh ); tmp_rh = httplib_free( tmp_rh );
httplib_cry( ctx, NULL, "%s", "Cannot create new request handler struct, OOM" ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s", "Cannot create new request handler struct, OOM" );
return; return;
} }

View File

@@ -73,7 +73,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
if ( ! parse_port_string( &vec, &so, &ip_version ) ) { if ( ! parse_port_string( &vec, &so, &ip_version ) ) {
httplib_cry( ctx, NULL, httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL,
"%.*s: invalid port spec (entry %i). Expecting list of: %s", "%.*s: invalid port spec (entry %i). Expecting list of: %s",
(int)vec.len, (int)vec.len,
vec.ptr, vec.ptr,
@@ -85,14 +85,14 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
#if !defined(NO_SSL) #if !defined(NO_SSL)
if ( so.has_ssl && ctx->ssl_ctx == NULL ) { if ( so.has_ssl && ctx->ssl_ctx == NULL ) {
httplib_cry( ctx, NULL, "Cannot add SSL socket (entry %i). Is -ssl_certificate option set?", ports_total ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "Cannot add SSL socket (entry %i). Is -ssl_certificate option set?", ports_total );
continue; continue;
} }
#endif /* ! NO_SLL */ #endif /* ! NO_SLL */
if ( ( so.sock = socket( so.lsa.sa.sa_family, SOCK_STREAM, 6 ) ) == INVALID_SOCKET ) { if ( ( so.sock = socket( so.lsa.sa.sa_family, SOCK_STREAM, 6 ) ) == INVALID_SOCKET ) {
httplib_cry( ctx, NULL, "cannot create socket (entry %i)", ports_total ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot create socket (entry %i)", ports_total );
continue; continue;
} }
@@ -116,7 +116,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
* Set reuse option, but don't abort on errors. * Set reuse option, but don't abort on errors.
*/ */
httplib_cry( ctx, NULL, "cannot set socket option SO_EXCLUSIVEADDRUSE (entry %i)", ports_total ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot set socket option SO_EXCLUSIVEADDRUSE (entry %i)", ports_total );
} }
#else /* _WIN32 */ #else /* _WIN32 */
if ( setsockopt( so.sock, SOL_SOCKET, SO_REUSEADDR, (SOCK_OPT_TYPE)&on, sizeof(on) ) != 0 ) { if ( setsockopt( so.sock, SOL_SOCKET, SO_REUSEADDR, (SOCK_OPT_TYPE)&on, sizeof(on) ) != 0 ) {
@@ -125,7 +125,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
* Set reuse option, but don't abort on errors. * Set reuse option, but don't abort on errors.
*/ */
httplib_cry( ctx, NULL, "cannot set socket option SO_REUSEADDR (entry %i)", ports_total ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot set socket option SO_REUSEADDR (entry %i)", ports_total );
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
@@ -139,7 +139,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
* Set IPv6 only option, but don't abort on errors. * Set IPv6 only option, but don't abort on errors.
*/ */
httplib_cry( ctx, NULL, "cannot set socket option IPV6_V6ONLY (entry %i)", ports_total ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot set socket option IPV6_V6ONLY (entry %i)", ports_total );
} }
} }
} }
@@ -150,7 +150,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
if ( bind( so.sock, &so.lsa.sa, len ) != 0 ) { if ( bind( so.sock, &so.lsa.sa, len ) != 0 ) {
httplib_cry( ctx, NULL, "cannot bind to %.*s: %d (%s)", (int)vec.len, vec.ptr, (int)ERRNO, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot bind to %.*s: %d (%s)", (int)vec.len, vec.ptr, (int)ERRNO, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
closesocket( so.sock ); closesocket( so.sock );
so.sock = INVALID_SOCKET; so.sock = INVALID_SOCKET;
continue; continue;
@@ -163,7 +163,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
if ( bind( so.sock, &so.lsa.sa, len ) != 0 ) { if ( bind( so.sock, &so.lsa.sa, len ) != 0 ) {
httplib_cry( ctx, NULL, "cannot bind to IPv6 %.*s: %d (%s)", (int)vec.len, vec.ptr, (int)ERRNO, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot bind to IPv6 %.*s: %d (%s)", (int)vec.len, vec.ptr, (int)ERRNO, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
closesocket( so.sock ); closesocket( so.sock );
so.sock = INVALID_SOCKET; so.sock = INVALID_SOCKET;
continue; continue;
@@ -171,13 +171,13 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
} }
else { else {
httplib_cry( ctx, NULL, "cannot bind: address family not supported (entry %i)", ports_total ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot bind: address family not supported (entry %i)", ports_total );
continue; continue;
} }
if ( listen( so.sock, SOMAXCONN ) != 0 ) { if ( listen( so.sock, SOMAXCONN ) != 0 ) {
httplib_cry( ctx, NULL, "cannot listen to %.*s: %d (%s)", (int)vec.len, vec.ptr, (int)ERRNO, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot listen to %.*s: %d (%s)", (int)vec.len, vec.ptr, (int)ERRNO, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
closesocket( so.sock ); closesocket( so.sock );
so.sock = INVALID_SOCKET; so.sock = INVALID_SOCKET;
continue; continue;
@@ -186,7 +186,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
if ( getsockname( so.sock, &(usa.sa), &len ) != 0 || usa.sa.sa_family != so.lsa.sa.sa_family ) { if ( getsockname( so.sock, &(usa.sa), &len ) != 0 || usa.sa.sa_family != so.lsa.sa.sa_family ) {
int err = (int)ERRNO; int err = (int)ERRNO;
httplib_cry( ctx, NULL, "call to getsockname failed %.*s: %d (%s)", (int)vec.len, vec.ptr, err, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "call to getsockname failed %.*s: %d (%s)", (int)vec.len, vec.ptr, err, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
closesocket( so.sock ); closesocket( so.sock );
so.sock = INVALID_SOCKET; so.sock = INVALID_SOCKET;
continue; continue;
@@ -203,7 +203,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
if ( ptr != NULL ) ctx->listening_sockets = ptr; if ( ptr != NULL ) ctx->listening_sockets = ptr;
else { else {
httplib_cry( ctx, NULL, "%s", "Out of memory" ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s", "Out of memory" );
closesocket( so.sock ); closesocket( so.sock );
so.sock = INVALID_SOCKET; so.sock = INVALID_SOCKET;
continue; continue;
@@ -214,7 +214,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) {
if ( pfd != NULL ) ctx->listening_socket_fds = pfd; if ( pfd != NULL ) ctx->listening_socket_fds = pfd;
else { else {
httplib_cry( ctx, NULL, "%s", "Out of memory" ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s", "Out of memory" );
closesocket( so.sock ); closesocket( so.sock );
so.sock = INVALID_SOCKET; so.sock = INVALID_SOCKET;
continue; continue;

View File

@@ -77,7 +77,7 @@ bool XX_httplib_set_ssl_option( struct httplib_context *ctx ) {
ctx->ssl_ctx = SSL_CTX_new( SSLv23_server_method() ); ctx->ssl_ctx = SSL_CTX_new( SSLv23_server_method() );
if ( ctx->ssl_ctx == NULL ) { if ( ctx->ssl_ctx == NULL ) {
httplib_cry( ctx, NULL, "SSL_CTX_new (server) error: %s", XX_httplib_ssl_error() ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "SSL_CTX_new (server) error: %s", XX_httplib_ssl_error() );
return false; return false;
} }
@@ -101,7 +101,7 @@ bool XX_httplib_set_ssl_option( struct httplib_context *ctx ) {
if ( callback_ret < 0 ) { if ( callback_ret < 0 ) {
httplib_cry( ctx, NULL, "SSL callback returned error: %i", callback_ret ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "SSL callback returned error: %i", callback_ret );
return false; return false;
} }
@@ -130,7 +130,7 @@ bool XX_httplib_set_ssl_option( struct httplib_context *ctx ) {
if ( SSL_CTX_load_verify_locations( ctx->ssl_ctx, ctx->ssl_ca_file, ctx->ssl_ca_path ) != 1 ) { if ( SSL_CTX_load_verify_locations( ctx->ssl_ctx, ctx->ssl_ca_file, ctx->ssl_ca_path ) != 1 ) {
httplib_cry( ctx, NULL, httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL,
"SSL_CTX_load_verify_locations error: %s " "SSL_CTX_load_verify_locations error: %s "
"ssl_verify_peer requires setting " "ssl_verify_peer requires setting "
"either ssl_ca_path or ssl_ca_file. Is any of them " "either ssl_ca_path or ssl_ca_file. Is any of them "
@@ -145,7 +145,7 @@ bool XX_httplib_set_ssl_option( struct httplib_context *ctx ) {
if ( ctx->ssl_verify_paths && SSL_CTX_set_default_verify_paths( ctx->ssl_ctx ) != 1 ) { if ( ctx->ssl_verify_paths && SSL_CTX_set_default_verify_paths( ctx->ssl_ctx ) != 1 ) {
httplib_cry( ctx, NULL, "SSL_CTX_set_default_verify_paths error: %s", XX_httplib_ssl_error()); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "SSL_CTX_set_default_verify_paths error: %s", XX_httplib_ssl_error());
return false; return false;
} }
@@ -156,7 +156,7 @@ bool XX_httplib_set_ssl_option( struct httplib_context *ctx ) {
if ( SSL_CTX_set_cipher_list( ctx->ssl_ctx, ctx->ssl_cipher_list ) != 1 ) { if ( SSL_CTX_set_cipher_list( ctx->ssl_ctx, ctx->ssl_cipher_list ) != 1 ) {
httplib_cry( ctx, NULL, "SSL_CTX_set_cipher_list error: %s", XX_httplib_ssl_error()); httplib_cry( DEBUG_LEVEL_WARNING, ctx, NULL, "SSL_CTX_set_cipher_list error: %s", XX_httplib_ssl_error());
} }
} }

View File

@@ -56,10 +56,10 @@ bool XX_httplib_set_uid_option( struct httplib_context *ctx ) {
if ( uid == NULL ) return true; if ( uid == NULL ) return true;
if ( (pw = getpwnam(uid)) == NULL ) httplib_cry( ctx, NULL, "%s: unknown user [%s]", __func__, uid ); if ( (pw = getpwnam(uid)) == NULL ) httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: unknown user [%s]", __func__, uid );
else if ( setgid(pw->pw_gid) == -1 ) httplib_cry( ctx, NULL, "%s: setgid(%s): %s", __func__, uid, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); else if ( setgid(pw->pw_gid) == -1 ) httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: setgid(%s): %s", __func__, uid, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
else if ( setgroups(0, NULL) ) httplib_cry( ctx, NULL, "%s: setgroups(): %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); else if ( setgroups(0, NULL) ) httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: setgroups(): %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
else if ( setuid(pw->pw_uid) == -1 ) httplib_cry( ctx, NULL, "%s: setuid(%s): %s", __func__, uid, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); else if ( setuid(pw->pw_uid) == -1 ) httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: setuid(%s): %s", __func__, uid, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
else return true; else return true;
return false; return false;

View File

@@ -133,7 +133,7 @@ pid_t XX_httplib_spawn_process( struct httplib_connection *conn, const char *pro
if ( CreateProcessA( NULL, cmdline, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP, envblk, NULL, &si, &pi ) == 0 ) { if ( CreateProcessA( NULL, cmdline, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP, envblk, NULL, &si, &pi ) == 0 ) {
httplib_cry( conn->ctx, conn, "%s: CreateProcess(%s): %ld", __func__, cmdline, (long)ERRNO); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CreateProcess(%s): %ld", __func__, cmdline, (long)ERRNO);
pi.hProcess = (pid_t)-1; pi.hProcess = (pid_t)-1;
/* /*
@@ -182,10 +182,10 @@ pid_t XX_httplib_spawn_process( struct httplib_connection *conn, const char *pro
* Child * Child
*/ */
if ( chdir( dir ) != 0 ) httplib_cry( conn->ctx, conn, "%s: chdir(%s): %s", __func__, dir, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); if ( chdir( dir ) != 0 ) httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: chdir(%s): %s", __func__, dir, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
else if ( dup2( fdin[0], 0 ) == -1 ) httplib_cry( conn->ctx, conn, "%s: dup2(%d, 0): %s", __func__, fdin[0], httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); else if ( dup2( fdin[0], 0 ) == -1 ) httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: dup2(%d, 0): %s", __func__, fdin[0], httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
else if ( dup2( fdout[1], 1 ) == -1 ) httplib_cry( conn->ctx, conn, "%s: dup2(%d, 1): %s", __func__, fdout[1], httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); else if ( dup2( fdout[1], 1 ) == -1 ) httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: dup2(%d, 1): %s", __func__, fdout[1], httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
else if ( dup2( fderr[1], 2 ) == -1 ) httplib_cry( conn->ctx, conn, "%s: dup2(%d, 2): %s", __func__, fderr[1], httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); else if ( dup2( fderr[1], 2 ) == -1 ) httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: dup2(%d, 2): %s", __func__, fderr[1], httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
else { else {
/* /*
* Keep stderr and stdout in two different pipes. * Keep stderr and stdout in two different pipes.
@@ -220,12 +220,12 @@ pid_t XX_httplib_spawn_process( struct httplib_connection *conn, const char *pro
if ( interp == NULL ) { if ( interp == NULL ) {
execle( prog, prog, NULL, envp ); execle( prog, prog, NULL, envp );
httplib_cry( conn->ctx, conn, "%s: execle(%s): %s", __func__, prog, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: execle(%s): %s", __func__, prog, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
else { else {
execle( interp, interp, prog, NULL, envp ); execle( interp, interp, prog, NULL, envp );
httplib_cry( conn->ctx, conn, "%s: execle(%s %s): %s", __func__, interp, prog, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: execle(%s %s): %s", __func__, interp, prog, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
} }

View File

@@ -98,19 +98,19 @@ static void do_ssi_include( struct httplib_connection *conn, const char *ssi, ch
} }
else { else {
httplib_cry( conn->ctx, conn, "Bad SSI #include: [%s]", tag ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Bad SSI #include: [%s]", tag );
return; return;
} }
if ( truncated ) { if ( truncated ) {
httplib_cry( conn->ctx, conn, "SSI #include path length overflow: [%s]", tag ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "SSI #include path length overflow: [%s]", tag );
return; return;
} }
if ( ! XX_httplib_fopen( conn, path, "rb", &file ) ) { if ( ! XX_httplib_fopen( conn, path, "rb", &file ) ) {
httplib_cry( conn->ctx, conn, "Cannot open SSI #include: [%s]: fopen(%s): %s", tag, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Cannot open SSI #include: [%s]: fopen(%s): %s", tag, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
return; return;
} }
@@ -135,14 +135,14 @@ static void do_ssi_exec( struct httplib_connection *conn, char *tag ) {
if ( sscanf(tag, " \"%1023[^\"]\"", cmd) != 1 ) { if ( sscanf(tag, " \"%1023[^\"]\"", cmd) != 1 ) {
httplib_cry( conn->ctx, conn, "Bad SSI #exec: [%s]", tag ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Bad SSI #exec: [%s]", tag );
} }
else { else {
cmd[1023] = 0; cmd[1023] = 0;
if ( (file.fp = popen( cmd, "r" ) ) == NULL ) { if ( (file.fp = popen( cmd, "r" ) ) == NULL ) {
httplib_cry( conn->ctx, conn, "Cannot SSI #exec: [%s]: %s", cmd, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Cannot SSI #exec: [%s]: %s", cmd, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) );
} }
else { else {
@@ -175,7 +175,7 @@ static void send_ssi_file( struct httplib_connection *conn, const char *path, st
if ( include_level > 10 ) { if ( include_level > 10 ) {
httplib_cry( conn->ctx, conn, "SSI #include level is too deep (%s)", path ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "SSI #include level is too deep (%s)", path );
return; return;
} }
@@ -213,7 +213,7 @@ static void send_ssi_file( struct httplib_connection *conn, const char *path, st
do_ssi_exec(conn, buf + 9); do_ssi_exec(conn, buf + 9);
#endif /* !NO_POPEN */ #endif /* !NO_POPEN */
} }
else httplib_cry( conn->ctx, conn, "%s: unknown SSI " "command: \"%s\"", path, buf ); else httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: unknown SSI " "command: \"%s\"", path, buf );
} }
len = 0; len = 0;
@@ -232,7 +232,7 @@ static void send_ssi_file( struct httplib_connection *conn, const char *path, st
else if ( len == (int)sizeof(buf) - 2 ) { else if ( len == (int)sizeof(buf) - 2 ) {
httplib_cry( conn->ctx, conn, "%s: SSI tag is too large", path ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: SSI tag is too large", path );
len = 0; len = 0;
} }

View File

@@ -43,7 +43,7 @@ int XX_httplib_ssl_use_pem_file( struct httplib_context *ctx, const char *pem )
if ( SSL_CTX_use_certificate_file( ctx->ssl_ctx, pem, 1 ) == 0 ) { if ( SSL_CTX_use_certificate_file( ctx->ssl_ctx, pem, 1 ) == 0 ) {
httplib_cry( ctx, NULL, "%s: cannot open certificate file %s: %s", __func__, pem, XX_httplib_ssl_error() ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: cannot open certificate file %s: %s", __func__, pem, XX_httplib_ssl_error() );
return 0; return 0;
} }
@@ -53,19 +53,19 @@ int XX_httplib_ssl_use_pem_file( struct httplib_context *ctx, const char *pem )
if ( SSL_CTX_use_PrivateKey_file( ctx->ssl_ctx, pem, 1 ) == 0 ) { if ( SSL_CTX_use_PrivateKey_file( ctx->ssl_ctx, pem, 1 ) == 0 ) {
httplib_cry( ctx, NULL, "%s: cannot open private key file %s: %s", __func__, pem, XX_httplib_ssl_error() ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: cannot open private key file %s: %s", __func__, pem, XX_httplib_ssl_error() );
return 0; return 0;
} }
if ( SSL_CTX_check_private_key( ctx->ssl_ctx ) == 0 ) { if ( SSL_CTX_check_private_key( ctx->ssl_ctx ) == 0 ) {
httplib_cry( ctx, NULL, "%s: certificate and private key do not match: %s", __func__, pem ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: certificate and private key do not match: %s", __func__, pem );
return 0; return 0;
} }
if ( SSL_CTX_use_certificate_chain_file( ctx->ssl_ctx, pem ) == 0 ) { if ( SSL_CTX_use_certificate_chain_file( ctx->ssl_ctx, pem ) == 0 ) {
httplib_cry( ctx, NULL, "%s: cannot use certificate chain file %s: %s", __func__, pem, XX_httplib_ssl_error() ); httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: cannot use certificate chain file %s: %s", __func__, pem, XX_httplib_ssl_error() );
return 0; return 0;
} }

View File

@@ -122,7 +122,7 @@ struct httplib_context *httplib_start( const struct httplib_callbacks *callbacks
*/ */
httplib_atomic_dec( & XX_httplib_sTlsInit ); httplib_atomic_dec( & XX_httplib_sTlsInit );
httplib_cry( ctx, NULL, "Cannot initialize thread local storage" ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "Cannot initialize thread local storage" );
ctx = httplib_free( ctx ); ctx = httplib_free( ctx );
return NULL; return NULL;
@@ -253,9 +253,9 @@ struct httplib_context *httplib_start( const struct httplib_callbacks *callbacks
wta = httplib_free( wta ); wta = httplib_free( wta );
if ( i > 0 ) httplib_cry( ctx, NULL, "Cannot start worker thread %i: error %ld", i + 1, (long)ERRNO ); if ( i > 0 ) httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "Cannot start worker thread %i: error %ld", i + 1, (long)ERRNO );
else return cleanup( ctx, "Cannot create threads: error %ld", (long)ERRNO ); else return cleanup( ctx, "Cannot create worker threads: error %ld", (long)ERRNO );
break; break;
} }
@@ -692,7 +692,7 @@ static struct httplib_context *cleanup( struct httplib_context *ctx, const char
va_end( ap ); va_end( ap );
buf[sizeof(buf)-1] = 0; buf[sizeof(buf)-1] = 0;
httplib_cry( ctx, NULL, "%s", buf ); httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s", buf );
} }
XX_httplib_free_context( ctx ); XX_httplib_free_context( ctx );

View File

@@ -47,7 +47,7 @@ int64_t httplib_store_body( struct httplib_connection *conn, const char *path )
if ( conn->consumed_content != 0 ) { if ( conn->consumed_content != 0 ) {
httplib_cry( conn->ctx, conn, "%s: Contents already consumed", __func__ ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: Contents already consumed", __func__ );
return -11; return -11;
} }

View File

@@ -60,7 +60,7 @@ void XX_httplib_vsnprintf( const struct httplib_connection *conn, bool *truncate
else { else {
if ( truncated != NULL ) *truncated = true; if ( truncated != NULL ) *truncated = true;
if ( conn != NULL && conn->ctx != NULL ) httplib_cry( conn->ctx, conn, "truncating vsnprintf buffer: [%.*s]", (int)((buflen > 200) ? 200 : (buflen - 1)), buf ); if ( conn != NULL && conn->ctx != NULL ) httplib_cry( DEBUG_LEVEL_WARNING, conn->ctx, conn, "truncating vsnprintf buffer: [%.*s]", (int)((buflen > 200) ? 200 : (buflen - 1)), buf );
n = (int)buflen - 1; n = (int)buflen - 1;
} }
buf[n] = '\0'; buf[n] = '\0';

View File

@@ -52,7 +52,7 @@ int httplib_websocket_client_write( struct httplib_connection *conn, int opcode,
if ( masked_data == NULL ) { if ( masked_data == NULL ) {
httplib_cry( conn->ctx, conn, "Cannot allocate buffer for masked websocket response: Out of memory" ); httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Cannot allocate buffer for masked websocket response: Out of memory" );
return -1; return -1;
} }

View File

@@ -90,7 +90,7 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) {
if ( ctx->callbacks.init_thread != NULL ) ctx->callbacks.init_thread( ctx, 1 ); /* call init_thread for a worker thread (type 1) */ if ( ctx->callbacks.init_thread != NULL ) ctx->callbacks.init_thread( ctx, 1 ); /* call init_thread for a worker thread (type 1) */
conn = httplib_calloc( 1, sizeof(*conn) + MAX_REQUEST_SIZE ); conn = httplib_calloc( 1, sizeof(*conn) + MAX_REQUEST_SIZE );
if ( conn == NULL ) httplib_cry( ctx, NULL, "%s", "Cannot create new connection struct, OOM" ); if ( conn == NULL ) httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s", "Cannot create new connection struct, OOM" );
else { else {
httplib_pthread_setspecific( XX_httplib_sTlsKey, &tls ); httplib_pthread_setspecific( XX_httplib_sTlsKey, &tls );