diff --git a/src/httplib_abort_start.c b/src/httplib_abort_start.c index 8ecd54a5..e3ec8547 100644 --- a/src/httplib_abort_start.c +++ b/src/httplib_abort_start.c @@ -44,7 +44,7 @@ struct httplib_context *XX_httplib_abort_start( struct httplib_context *ctx, con va_end( ap ); buf[sizeof(buf)-1] = 0; - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s", buf ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: %s", __func__, buf ); } XX_httplib_free_context( ctx ); diff --git a/src/httplib_connect_client.c b/src/httplib_connect_client.c index 8ddbaabb..0e21b4c6 100644 --- a/src/httplib_connect_client.c +++ b/src/httplib_connect_client.c @@ -89,14 +89,14 @@ static struct httplib_connection *httplib_connect_client_impl( struct httplib_co if ( (conn = httplib_calloc( 1, sizeof(*conn) + MAX_REQUEST_SIZE )) == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s (%u): calloc(): %s", __func__, __LINE__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: calloc(): %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); closesocket( sock ); } #ifndef NO_SSL else if ( use_ssl && (conn->client_ssl_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): SSL_CTX_new error", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: SSL_CTX_new error", __func__ ); closesocket( sock ); conn = httplib_free( conn ); } @@ -113,7 +113,7 @@ static struct httplib_connection *httplib_connect_client_impl( struct httplib_co conn->client.sock = sock; conn->client.lsa = sa; - if ( getsockname( sock, psa, &len ) != 0 ) httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): getsockname() failed: %s", __func__, __LINE__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); + if ( getsockname( sock, psa, &len ) != 0 ) httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: getsockname() failed: %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); conn->client.has_ssl = (use_ssl) ? true : false; httplib_pthread_mutex_init( &conn->mutex, &XX_httplib_pthread_mutex_attr ); @@ -137,7 +137,7 @@ static struct httplib_connection *httplib_connect_client_impl( struct httplib_co if ( ! XX_httplib_ssl_use_pem_file( ctx, client_options->client_cert ) ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): can not use SSL client certificate", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: can not use SSL client certificate", __func__ ); SSL_CTX_free( conn->client_ssl_ctx ); closesocket( sock ); conn = httplib_free( conn ); @@ -154,7 +154,7 @@ static struct httplib_connection *httplib_connect_client_impl( struct httplib_co if ( ! XX_httplib_sslize( conn, conn->client_ssl_ctx, SSL_connect ) ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): SSL connection error", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: SSL connection error", __func__ ); SSL_CTX_free( conn->client_ssl_ctx ); closesocket( sock ); conn = httplib_free( conn ); diff --git a/src/httplib_connect_socket.c b/src/httplib_connect_socket.c index 5e30ccf2..be985af1 100644 --- a/src/httplib_connect_socket.c +++ b/src/httplib_connect_socket.c @@ -54,13 +54,13 @@ bool XX_httplib_connect_socket( struct httplib_context *ctx, const char *host, i if ( host == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s (%u): NULL host", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: NULL host", __func__ ); return false; } if ( port < 0 || ! XX_httplib_is_valid_port( (unsigned)port) ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s (%u): invalid port", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: invalid port", __func__ ); return false; } @@ -68,7 +68,7 @@ bool XX_httplib_connect_socket( struct httplib_context *ctx, const char *host, i if ( use_ssl && SSLv23_client_method == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s (%u): SSL is not initialized", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: SSL is not initialized", __func__ ); return false; } #else /* NO_SSL */ @@ -112,7 +112,7 @@ bool XX_httplib_connect_socket( struct httplib_context *ctx, const char *host, i if ( ip_ver == 0 ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s (%u): host not found", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: host not found", __func__ ); return false; } @@ -121,7 +121,7 @@ bool XX_httplib_connect_socket( struct httplib_context *ctx, const char *host, i if ( *sock == INVALID_SOCKET ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s (%u): socket(): %s", __func__, __LINE__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: socket(): %s", __func__, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); return false; } @@ -134,7 +134,7 @@ bool XX_httplib_connect_socket( struct httplib_context *ctx, const char *host, i * Not connected */ - httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s (%u): connect(%s:%d): %s", __func__, __LINE__, host, port, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: connect(%s:%d): %s", __func__, host, port, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); closesocket( *sock ); *sock = INVALID_SOCKET; diff --git a/src/httplib_connect_websocket_client.c b/src/httplib_connect_websocket_client.c index 1832e346..774d5629 100644 --- a/src/httplib_connect_websocket_client.c +++ b/src/httplib_connect_websocket_client.c @@ -47,7 +47,7 @@ struct httplib_connection *httplib_connect_websocket_client( struct httplib_cont if ( ctx->status != CTX_STATUS_TERMINATED ) { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s (%u): client context not in terminated state", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: client context not in terminated state", __func__ ); return NULL; } @@ -75,13 +75,13 @@ struct httplib_connection *httplib_connect_websocket_client( struct httplib_cont conn = httplib_download( ctx, host, port, use_ssl, handshake_req, path, host, magic, origin ); if ( conn == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s (%u): Init of download failed", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: init of download failed", __func__ ); return NULL; } if ( strcmp( conn->request_info.request_uri, "101" ) ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): unexpected server reply \"%s\"", __func__, __LINE__, conn->request_info.request_uri ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: unexpected server reply \"%s\"", __func__, conn->request_info.request_uri ); conn = httplib_free( conn ); return NULL; @@ -94,7 +94,7 @@ struct httplib_connection *httplib_connect_websocket_client( struct httplib_cont if ( ctx->workerthreadids == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): out of memory allocating worker thread IDs", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: out of memory allocating worker thread IDs", __func__ ); ctx->num_threads = 0; ctx->user_data = NULL; @@ -107,7 +107,7 @@ struct httplib_connection *httplib_connect_websocket_client( struct httplib_cont if ( thread_data == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): out of memory allocating thread data", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: out of memory allocating thread data", __func__ ); ctx->workerthreadids = httplib_free( ctx->workerthreadids ); ctx->num_threads = 0; @@ -130,7 +130,7 @@ struct httplib_connection *httplib_connect_websocket_client( struct httplib_cont if ( XX_httplib_start_thread_with_id( XX_httplib_websocket_client_thread, thread_data, ctx->workerthreadids) != 0 ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): thread failed to start", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: thread failed to start", __func__ ); thread_data = httplib_free( thread_data ); ctx->workerthreadids = httplib_free( ctx->workerthreadids ); diff --git a/src/httplib_download.c b/src/httplib_download.c index 1603b15b..efa0ac5a 100644 --- a/src/httplib_download.c +++ b/src/httplib_download.c @@ -52,7 +52,7 @@ struct httplib_connection * httplib_download( struct httplib_context *ctx, const i = XX_httplib_vprintf( conn, fmt, ap ); - if ( i <= 0 ) httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%d): error sending request", __func__, __LINE__ ); + if ( i <= 0 ) httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: error sending request", __func__ ); else { XX_httplib_getreq( ctx, conn, &reqerr ); diff --git a/src/httplib_get_response_code_text.c b/src/httplib_get_response_code_text.c index 69cd0fea..ed33e537 100644 --- a/src/httplib_get_response_code_text.c +++ b/src/httplib_get_response_code_text.c @@ -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. */ - if ( conn != NULL && conn->ctx != NULL ) httplib_cry( DEBUG_LEVEL_INFO, conn->ctx, conn, "Unknown HTTP response code: %u", response_code ); + if ( conn != NULL && conn->ctx != NULL ) httplib_cry( DEBUG_LEVEL_INFO, conn->ctx, conn, "%s: unknown HTTP response code: %u", __func__, response_code ); /* * Return at least a category according to RFC 2616 Section 10. diff --git a/src/httplib_getreq.c b/src/httplib_getreq.c index aa15fca6..33f465ed 100644 --- a/src/httplib_getreq.c +++ b/src/httplib_getreq.c @@ -44,7 +44,7 @@ bool XX_httplib_getreq( struct httplib_context *ctx, struct httplib_connection * if ( conn == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): internal error", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: internal error", __func__ ); *err = 500; return false; } @@ -66,14 +66,14 @@ bool XX_httplib_getreq( struct httplib_context *ctx, struct httplib_connection * if ( conn->request_len >= 0 && conn->data_len < conn->request_len ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): invalid request size", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: invalid request size", __func__ ); *err = 500; return false; } if ( conn->request_len == 0 && conn->data_len == conn->buf_size ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): request too large", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: request too large", __func__ ); *err = 413; return false; } @@ -82,7 +82,7 @@ bool XX_httplib_getreq( struct httplib_context *ctx, struct httplib_connection * if ( conn->data_len > 0 ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): client sent malformed request", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: client sent malformed request", __func__ ); *err = 400; } @@ -93,7 +93,7 @@ bool XX_httplib_getreq( struct httplib_context *ctx, struct httplib_connection * conn->must_close = true; - httplib_cry( DEBUG_LEVEL_WARNING, ctx, conn, "%s (%u): client did not send a request", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_WARNING, ctx, conn, "%s: client did not send a request", __func__ ); *err = 0; } return false; @@ -101,7 +101,7 @@ bool XX_httplib_getreq( struct httplib_context *ctx, struct httplib_connection * else if ( XX_httplib_parse_http_message( conn->buf, conn->buf_size, &conn->request_info ) <= 0 ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): bad request", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: bad request", __func__ ); *err = 400; return false; } @@ -122,7 +122,7 @@ bool XX_httplib_getreq( struct httplib_context *ctx, struct httplib_connection * if ( endptr == cl ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s (%u): bad request", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, ctx, conn, "%s: bad request", __func__ ); *err = 411; return false; } diff --git a/src/httplib_handle_cgi_request.c b/src/httplib_handle_cgi_request.c index f28d415a..e1b238d1 100644 --- a/src/httplib_handle_cgi_request.c +++ b/src/httplib_handle_cgi_request.c @@ -85,7 +85,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char if ( truncated ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Path too long", prog ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program \"%s\": Path too long", __func__, prog ); XX_httplib_send_http_error( conn, 500, "Error: %s", "CGI path too long" ); 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 ) { status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not create CGI pipes: %s", prog, status ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program \"%s\": Can not create CGI pipes: %s", __func__, prog, status ); XX_httplib_send_http_error( conn, 500, "Error: Cannot create CGI pipe: %s", status ); goto done; @@ -117,7 +117,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char if ( pid == (pid_t)-1 ) { status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not spawn CGI process: %s", prog, status ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program \"%s\": Can not spawn CGI process: %s", __func__, prog, status ); XX_httplib_send_http_error( conn, 500, "Error: Cannot spawn CGI process [%s]: %s", prog, status ); 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 ) { status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not open stdin: %s", prog, status ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program \"%s\": Can not open stdin: %s", __func__, prog, status ); XX_httplib_send_http_error( conn, 500, "Error: CGI can not open fdin\nfopen: %s", status ); 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 ) { status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not open stdout: %s", prog, status ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program \"%s\": Can not open stdout: %s", __func__, prog, status ); XX_httplib_send_http_error( conn, 500, "Error: CGI can not open fdout\nfopen: %s", status ); 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 ) { status = httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ); - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Can not open stderr: %s", prog, status ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program \"%s\": Can not open stderr: %s", __func__, prog, status ); XX_httplib_send_http_error( conn, 500, "Error: CGI can not open fdout\nfopen: %s", status ); goto done; @@ -194,7 +194,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char * Error sending the body data */ - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\": Forward body data failed", prog ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program \"%s\": Forward body data failed", __func__, prog ); goto done; } @@ -222,7 +222,7 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char if ( buf == NULL ) { XX_httplib_send_http_error( conn, 500, "Error: Not enough memory for CGI buffer (%u bytes)", (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 ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program \"%s\": Not enough memory for buffer (%u " "bytes)", __func__, prog, (unsigned int)buflen ); goto done; } @@ -239,12 +239,12 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char if ( i > 0 ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program \"%s\" sent error " "message: [%.*s]", __func__, prog, i, buf ); XX_httplib_send_http_error( conn, 500, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf ); } else { - 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 ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: CGI program sent malformed or too big " "(>%u bytes) HTTP headers: [%.*s]", __func__, (unsigned)buflen, data_len, buf ); XX_httplib_send_http_error( conn, 500, diff --git a/src/httplib_handle_request.c b/src/httplib_handle_request.c index 8af4ab89..89379897 100644 --- a/src/httplib_handle_request.c +++ b/src/httplib_handle_request.c @@ -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" ); - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Can not redirect to SSL, no SSL port available" ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: can not redirect to SSL, no SSL port available", __func__ ); } return; diff --git a/src/httplib_main.h b/src/httplib_main.h index 582797ac..c55bce2d 100644 --- a/src/httplib_main.h +++ b/src/httplib_main.h @@ -885,7 +885,7 @@ int XX_httplib_send_static_cache_header( struct httplib_connection *conn ); int XX_httplib_send_websocket_handshake( struct httplib_connection *conn, const char *websock_key ); int XX_httplib_set_acl_option( struct httplib_context *ctx ); void XX_httplib_set_close_on_exec( SOCKET sock ); -int XX_httplib_set_gpass_option( struct httplib_context *ctx ); +bool XX_httplib_set_gpass_option( struct httplib_context *ctx ); void XX_httplib_set_handler_type( struct httplib_context *ctx, const char *uri, int handler_type, int is_delete_request, httplib_request_handler handler, httplib_websocket_connect_handler connect_handler, httplib_websocket_ready_handler ready_handler, httplib_websocket_data_handler data_handler, httplib_websocket_close_handler close_handler, httplib_authorization_handler auth_handler, void *cbdata ); int XX_httplib_set_non_blocking_mode( SOCKET sock ); int XX_httplib_set_ports_option( struct httplib_context *ctx ); diff --git a/src/httplib_open_auth_file.c b/src/httplib_open_auth_file.c index 1eb65faa..e84c012e 100644 --- a/src/httplib_open_auth_file.c +++ b/src/httplib_open_auth_file.c @@ -28,14 +28,15 @@ #include "httplib_main.h" #include "httplib_string.h" -/* Use the global passwords file, if specified by auth_gpass option, - * or search for .htpasswd in the requested directory. */ +/* + * Use the global passwords file, if specified by auth_gpass option, + * or search for .htpasswd in the requested directory. + */ + void XX_httplib_open_auth_file( struct httplib_connection *conn, const char *path, struct file *filep ) { char name[PATH_MAX]; -#ifdef DEBUG char error_string[ERROR_STRING_LEN]; -#endif const char *p; const char *e; const char *gpass; @@ -53,9 +54,8 @@ void XX_httplib_open_auth_file( struct httplib_connection *conn, const char *pat */ if ( ! XX_httplib_fopen( conn, gpass, "r", filep ) ) { -#ifdef DEBUG - httplib_cry( conn, "fopen(%s): %s", gpass, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); -#endif + + httplib_cry( DEBUG_LEVEL_INFO, conn->ctx, conn, "%s: fopen(%s): %s", __func__, gpass, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); } /* * Important: using local struct file to test path for is_directory @@ -70,9 +70,8 @@ void XX_httplib_open_auth_file( struct httplib_connection *conn, const char *pat XX_httplib_snprintf( conn, &truncated, name, sizeof(name), "%s/%s", path, PASSWORDS_FILE_NAME ); if ( truncated || ! XX_httplib_fopen( conn, name, "r", filep ) ) { -#ifdef DEBUG - httplib_cry( conn, "fopen(%s): %s", name, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); -#endif + + httplib_cry( DEBUG_LEVEL_INFO, conn->ctx, conn, "%s: fopen(%s): %s", __func__, name, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); } } @@ -88,9 +87,8 @@ void XX_httplib_open_auth_file( struct httplib_connection *conn, const char *pat XX_httplib_snprintf( conn, &truncated, name, sizeof(name), "%.*s/%s", (int)(e - p), p, PASSWORDS_FILE_NAME ); if ( truncated || ! XX_httplib_fopen( conn, name, "r", filep ) ) { -#ifdef DEBUG - httplib_cry( conn, "fopen(%s): %s", name, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); -#endif + + httplib_cry( DEBUG_LEVEL_INFO, conn->ctx, conn, "%s: fopen(%s): %s", __func__, name, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); } } diff --git a/src/httplib_process_new_connection.c b/src/httplib_process_new_connection.c index 2c558fec..42363d57 100644 --- a/src/httplib_process_new_connection.c +++ b/src/httplib_process_new_connection.c @@ -77,7 +77,7 @@ void XX_httplib_process_new_connection( struct httplib_connection *conn ) { else if ( strcmp( ri->http_version, "1.0" ) && strcmp( ri->http_version, "1.1" ) ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s (%u): bad HTTP version \"%s\"", __func__, __LINE__, ri->http_version ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: bad HTTP version \"%s\"", __func__, ri->http_version ); XX_httplib_send_http_error( conn, 505, "%s", httplib_get_response_code_text( conn, 505 ) ); was_error = true; @@ -109,7 +109,7 @@ void XX_httplib_process_new_connection( struct httplib_connection *conn ) { break; default : - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s (%u): invalid URI", __func__, __LINE__ ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: invalid URI", __func__ ); XX_httplib_send_http_error( conn, 400, "%s", httplib_get_response_code_text( conn, 400 ) ); conn->request_info.local_uri = NULL; diff --git a/src/httplib_read_websocket.c b/src/httplib_read_websocket.c index 700bc1e4..a1dcbd8c 100644 --- a/src/httplib_read_websocket.c +++ b/src/httplib_read_websocket.c @@ -96,7 +96,7 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock if ( conn->data_len < conn->request_len ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "websocket error: data len less than request len, closing connection" ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: websocket error: data len less than request len, closing connection", __func__ ); break; } @@ -145,7 +145,7 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock * connection */ - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "websocket out of memory; closing connection" ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: websocket out of memory; closing connection", __func__ ); break; } } @@ -161,7 +161,7 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock if ( body_len < header_len ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "websocket error: body len less than header len, closing connection" ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: websocket error: body len less than header len, closing connection", __func__ ); break; } @@ -195,7 +195,7 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock if (error) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Websocket pull failed; closing connection" ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: websocket pull failed; closing connection", __func__ ); break; } diff --git a/src/httplib_refresh_trust.c b/src/httplib_refresh_trust.c index af0d612e..dea5883b 100644 --- a/src/httplib_refresh_trust.c +++ b/src/httplib_refresh_trust.c @@ -66,13 +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 ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, - "SSL_CTX_load_verify_locations error: %s " - "ssl_verify_peer requires setting " - "either ssl_ca_path or ssl_ca_file. Is any of them " - "present in " - "the .conf file?", - XX_httplib_ssl_error() ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: SSL_CTX_load_verify_locations error: %s ssl_verify_peer requires setting either ssl_ca_path or ssl_ca_file. Is any of them present in the .conf file?", __func__, XX_httplib_ssl_error() ); return 0; } diff --git a/src/httplib_set_gpass_option.c b/src/httplib_set_gpass_option.c index 7b087ec2..cf58d383 100644 --- a/src/httplib_set_gpass_option.c +++ b/src/httplib_set_gpass_option.c @@ -28,27 +28,28 @@ #include "httplib_main.h" /* - * int XX_httplib_set_gpass_option( struct httplib_context *ctx ); + * bool XX_httplib_set_gpass_option( struct httplib_context *ctx ); * * The function XX_httplib_set_gpass_option() sets the global password file - * option for a context. + * option for a context. The function returns false when an error occurs and + * true when successful. */ -int XX_httplib_set_gpass_option( struct httplib_context *ctx ) { +bool XX_httplib_set_gpass_option( struct httplib_context *ctx ) { struct file file = STRUCT_FILE_INITIALIZER; const char *path; char error_string[ERROR_STRING_LEN]; - if ( ctx == NULL ) return 0; + if ( ctx == NULL ) return false; path = ctx->global_auth_file; if ( path != NULL && ! XX_httplib_stat( NULL, path, &file ) ) { - httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "Cannot open %s: %s", path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); - return 0; + httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: cannot open %s: %s", __func__, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); + return false; } - return 1; + return true; } /* XX_httplib_set_gpass_option */ diff --git a/src/httplib_set_handler_type.c b/src/httplib_set_handler_type.c index 878d5378..0029042e 100644 --- a/src/httplib_set_handler_type.c +++ b/src/httplib_set_handler_type.c @@ -140,7 +140,7 @@ void XX_httplib_set_handler_type( struct httplib_context *ctx, const char *uri, if ( tmp_rh == NULL ) { httplib_unlock_context( ctx ); - httplib_cry( DEBUG_LEVEL_ERROR, 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", __func__ ); return; } @@ -151,7 +151,7 @@ void XX_httplib_set_handler_type( struct httplib_context *ctx, const char *uri, httplib_unlock_context( ctx ); tmp_rh = httplib_free( tmp_rh ); - httplib_cry( DEBUG_LEVEL_ERROR, 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", __func__ ); return; } diff --git a/src/httplib_set_ports_option.c b/src/httplib_set_ports_option.c index 16607fe2..d7a9b772 100644 --- a/src/httplib_set_ports_option.c +++ b/src/httplib_set_ports_option.c @@ -73,26 +73,21 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) { if ( ! parse_port_string( &vec, &so, &ip_version ) ) { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, - "%.*s: invalid port spec (entry %i). Expecting list of: %s", - (int)vec.len, - vec.ptr, - ports_total, - "[IP_ADDRESS:]PORT[s|r]" ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: %.*s: invalid port spec (entry %i). Expecting list of: %s", __func__, (int)vec.len, vec.ptr, ports_total, "[IP_ADDRESS:]PORT[s|r]" ); continue; } #if !defined(NO_SSL) if ( so.has_ssl && ctx->ssl_ctx == NULL ) { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "Cannot add SSL socket (entry %i). Is -ssl_certificate option set?", ports_total ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot add SSL socket (entry %i). Is -ssl_certificate option set?", __func__, ports_total ); continue; } #endif /* ! NO_SLL */ if ( ( so.sock = socket( so.lsa.sa.sa_family, SOCK_STREAM, 6 ) ) == INVALID_SOCKET ) { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot create socket (entry %i)", ports_total ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot create socket (entry %i)", __func__, ports_total ); continue; } @@ -116,7 +111,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) { * Set reuse option, but don't abort on errors. */ - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot set socket option SO_EXCLUSIVEADDRUSE (entry %i)", ports_total ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot set socket option SO_EXCLUSIVEADDRUSE (entry %i)", __func__, ports_total ); } #else /* _WIN32 */ if ( setsockopt( so.sock, SOL_SOCKET, SO_REUSEADDR, (SOCK_OPT_TYPE)&on, sizeof(on) ) != 0 ) { @@ -125,7 +120,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) { * Set reuse option, but don't abort on errors. */ - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot set socket option SO_REUSEADDR (entry %i)", ports_total ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot set socket option SO_REUSEADDR (entry %i)", __func__, ports_total ); } #endif /* _WIN32 */ @@ -139,7 +134,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) { * Set IPv6 only option, but don't abort on errors. */ - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot set socket option IPV6_V6ONLY (entry %i)", ports_total ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot set socket option IPV6_V6ONLY (entry %i)", __func__, ports_total ); } } } @@ -150,7 +145,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) { if ( bind( so.sock, &so.lsa.sa, len ) != 0 ) { - 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 ) ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot bind to %.*s: %d (%s)", __func__, (int)vec.len, vec.ptr, (int)ERRNO, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); closesocket( so.sock ); so.sock = INVALID_SOCKET; continue; @@ -163,7 +158,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) { if ( bind( so.sock, &so.lsa.sa, len ) != 0 ) { - 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 ) ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot bind to IPv6 %.*s: %d (%s)", __func__, (int)vec.len, vec.ptr, (int)ERRNO, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); closesocket( so.sock ); so.sock = INVALID_SOCKET; continue; @@ -171,13 +166,13 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) { } else { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "cannot bind: address family not supported (entry %i)", ports_total ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot bind: address family not supported (entry %i)", __func__, ports_total ); continue; } if ( listen( so.sock, SOMAXCONN ) != 0 ) { - 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 ) ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot listen to %.*s: %d (%s)", __func__, (int)vec.len, vec.ptr, (int)ERRNO, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); closesocket( so.sock ); so.sock = INVALID_SOCKET; continue; @@ -186,7 +181,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 ) { int err = (int)ERRNO; - 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 ) ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: call to getsockname failed %.*s: %d (%s)", __func__, (int)vec.len, vec.ptr, err, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); closesocket( so.sock ); so.sock = INVALID_SOCKET; continue; @@ -203,7 +198,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) { if ( ptr != NULL ) ctx->listening_sockets = ptr; else { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s", "Out of memory" ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: out of memory on listening sockets", __func__ ); closesocket( so.sock ); so.sock = INVALID_SOCKET; continue; @@ -214,7 +209,7 @@ int XX_httplib_set_ports_option( struct httplib_context *ctx ) { if ( pfd != NULL ) ctx->listening_socket_fds = pfd; else { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s", "Out of memory" ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: out of memory on fds", __func__ ); closesocket( so.sock ); so.sock = INVALID_SOCKET; continue; diff --git a/src/httplib_set_ssl_option.c b/src/httplib_set_ssl_option.c index 79b7672b..af7f0303 100644 --- a/src/httplib_set_ssl_option.c +++ b/src/httplib_set_ssl_option.c @@ -77,7 +77,7 @@ bool XX_httplib_set_ssl_option( struct httplib_context *ctx ) { ctx->ssl_ctx = SSL_CTX_new( SSLv23_server_method() ); if ( ctx->ssl_ctx == NULL ) { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "SSL_CTX_new (server) error: %s", XX_httplib_ssl_error() ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: SSL_CTX_new (server) error: %s", __func__, XX_httplib_ssl_error() ); return false; } @@ -101,7 +101,7 @@ bool XX_httplib_set_ssl_option( struct httplib_context *ctx ) { if ( callback_ret < 0 ) { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "SSL callback returned error: %i", callback_ret ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: SSL callback returned error: %i", __func__, callback_ret ); return false; } @@ -130,13 +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 ) { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, - "SSL_CTX_load_verify_locations error: %s " - "ssl_verify_peer requires setting " - "either ssl_ca_path or ssl_ca_file. Is any of them " - "present in " - "the .conf file?", - XX_httplib_ssl_error() ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: SSL_CTX_load_verify_locations error: %s ssl_verify_peer requires setting either ssl_ca_path or ssl_ca_file. Is any of them present in the .conf file?", __func__, XX_httplib_ssl_error() ); return false; } @@ -145,7 +139,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 ) { - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "SSL_CTX_set_default_verify_paths error: %s", XX_httplib_ssl_error()); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: SSL_CTX_set_default_verify_paths error: %s", __func__, XX_httplib_ssl_error()); return false; } @@ -156,7 +150,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 ) { - httplib_cry( DEBUG_LEVEL_WARNING, ctx, NULL, "SSL_CTX_set_cipher_list error: %s", XX_httplib_ssl_error()); + httplib_cry( DEBUG_LEVEL_WARNING, ctx, NULL, "%s: SSL_CTX_set_cipher_list error: %s", __func__, XX_httplib_ssl_error() ); } } diff --git a/src/httplib_ssi.c b/src/httplib_ssi.c index 68235bc8..1b7a512b 100644 --- a/src/httplib_ssi.c +++ b/src/httplib_ssi.c @@ -98,19 +98,19 @@ static void do_ssi_include( struct httplib_connection *conn, const char *ssi, ch } else { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Bad SSI #include: [%s]", tag ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: bad SSI #include: [%s]", __func__, tag ); return; } if ( truncated ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "SSI #include path length overflow: [%s]", tag ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: SSI #include path length overflow: [%s]", __func__, tag ); return; } if ( ! XX_httplib_fopen( conn, path, "rb", &file ) ) { - 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 ) ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: cannot open SSI #include: [%s]: fopen(%s): %s", __func__, tag, path, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); return; } @@ -135,14 +135,14 @@ static void do_ssi_exec( struct httplib_connection *conn, char *tag ) { if ( sscanf(tag, " \"%1023[^\"]\"", cmd) != 1 ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Bad SSI #exec: [%s]", tag ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: bad SSI #exec: [%s]", __func__, tag ); } else { cmd[1023] = 0; if ( (file.fp = popen( cmd, "r" ) ) == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, 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, "%s: cannot SSI #exec: [%s]: %s", __func__, cmd, httplib_error_string( ERRNO, error_string, ERROR_STRING_LEN ) ); } else { @@ -175,7 +175,7 @@ static void send_ssi_file( struct httplib_connection *conn, const char *path, st if ( include_level > 10 ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "SSI #include level is too deep (%s)", path ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: SSI #include level is too deep (%s)", __func__, path ); return; } @@ -213,7 +213,7 @@ static void send_ssi_file( struct httplib_connection *conn, const char *path, st do_ssi_exec(conn, buf + 9); #endif /* !NO_POPEN */ } - else httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: unknown SSI " "command: \"%s\"", path, buf ); + else httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: %s: unknown SSI command: \"%s\"", __func__, path, buf ); } 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 ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: SSI tag is too large", path ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: %s: SSI tag is too large", __func__, path ); len = 0; } diff --git a/src/httplib_start.c b/src/httplib_start.c index 1b591255..85e8e4af 100644 --- a/src/httplib_start.c +++ b/src/httplib_start.c @@ -99,7 +99,7 @@ struct httplib_context *httplib_start( const struct httplib_callbacks *callbacks */ httplib_atomic_dec( & XX_httplib_sTlsInit ); - httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "Cannot initialize thread local storage" ); + httplib_cry( DEBUG_LEVEL_CRASH, ctx, NULL, "%s: cannot initialize thread local storage", __func__ ); ctx = httplib_free( ctx ); return NULL; @@ -230,7 +230,7 @@ struct httplib_context *httplib_start( const struct httplib_callbacks *callbacks wta = httplib_free( wta ); - if ( i > 0 ) httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "Cannot start worker thread %i: error %ld", i + 1, (long)ERRNO ); + if ( i > 0 ) httplib_cry( DEBUG_LEVEL_ERROR, ctx, NULL, "%s: cannot start worker thread %i: error %ld", __func__, i+1, (long)ERRNO ); else return XX_httplib_abort_start( ctx, "Cannot create worker threads: error %ld", (long)ERRNO ); diff --git a/src/httplib_vsnprintf.c b/src/httplib_vsnprintf.c index b7cb91a1..aebc3dcd 100644 --- a/src/httplib_vsnprintf.c +++ b/src/httplib_vsnprintf.c @@ -60,7 +60,7 @@ void XX_httplib_vsnprintf( const struct httplib_connection *conn, bool *truncate else { if ( truncated != NULL ) *truncated = true; - 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 ); + if ( conn != NULL && conn->ctx != NULL ) httplib_cry( DEBUG_LEVEL_WARNING, conn->ctx, conn, "%s: truncating vsnprintf buffer: [%.*s]", __func__, (int)((buflen > 200) ? 200 : (buflen - 1)), buf ); n = (int)buflen - 1; } buf[n] = '\0'; diff --git a/src/httplib_websocket_client_write.c b/src/httplib_websocket_client_write.c index 189bc120..05c62abe 100644 --- a/src/httplib_websocket_client_write.c +++ b/src/httplib_websocket_client_write.c @@ -52,7 +52,7 @@ int httplib_websocket_client_write( struct httplib_connection *conn, int opcode, if ( masked_data == NULL ) { - httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "Cannot allocate buffer for masked websocket response: Out of memory" ); + httplib_cry( DEBUG_LEVEL_ERROR, conn->ctx, conn, "%s: cannot allocate buffer for masked websocket response: Out of memory", __func__ ); return -1; } diff --git a/src/httplib_worker_thread.c b/src/httplib_worker_thread.c index dc761193..f3ac0350 100644 --- a/src/httplib_worker_thread.c +++ b/src/httplib_worker_thread.c @@ -89,7 +89,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) */ conn = httplib_calloc( 1, sizeof(*conn) + MAX_REQUEST_SIZE ); - if ( conn == NULL ) httplib_cry( DEBUG_LEVEL_ERROR, 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", __func__ ); else { httplib_pthread_setspecific( XX_httplib_sTlsKey, &tls );