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

Removed NO_FILES compile option

This commit is contained in:
Lammert Bies
2016-12-26 21:25:49 +01:00
parent 2105bd3f1f
commit fe0b6dfad7
16 changed files with 41 additions and 122 deletions

View File

@@ -22,7 +22,6 @@ The following parameter values can be used:
| Value | Compilation option | Description |
| :---: | :---: | :--- |
| **1** | NO_FILES | *Able to serve files*. If this feature is available, the webserver is able to serve files directly from a directory tree. |
| **2** | NO_SSL | *Support for HTTPS*. If this feature is available, the webserver van use encryption in the client-server connection. SSLv2, SSLv3, TLSv1.0, TLSv1.1 and TLSv1.2 are supported depending on the SSL library LibHTTP has been compiled with, but which protocols are used effectively when the server is running is dependent on the options used when the server is started. |
| **4** | NO_CGI | *Support for CGI*. If this feature is available, external CGI scripts can be called by the webserver. |

View File

@@ -930,10 +930,8 @@ LIBHTTP_API int httplib_get_response(struct httplib_connection *conn, char *ebuf
/* Check which features where set when LibHTTP has been compiled.
Parameters:
feature: specifies which feature should be checked
1 serve files (NO_FILES not set)
2 support HTTPS (NO_SSL not set)
4 support CGI (NO_CGI not set)
128 support caching (NO_CACHING not set)
The result is undefined for all other feature values.
Return:

View File

@@ -34,12 +34,17 @@
* connection.
*/
#if !defined(NO_FILES)
void XX_httplib_delete_file( struct httplib_connection *conn, const char *path ) {
struct de de;
if ( conn == NULL || conn->ctx == NULL ) return;
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) {
XX_httplib_send_http_error( conn, 405, "Error: File delete operations are not supported" );
return;
}
memset( &de.file, 0, sizeof(de.file) );
if ( ! XX_httplib_stat( conn, path, &de.file ) ) {
@@ -106,5 +111,3 @@ void XX_httplib_delete_file( struct httplib_connection *conn, const char *path )
else XX_httplib_send_http_error( conn, 423, "Error: Cannot delete file\nremove(%s): %s", path, strerror(ERRNO) );
} /* XX_httplib_delete_file */
#endif /* !NO_FILES */

View File

@@ -34,7 +34,6 @@
* client. The function returns true if successful, and false otherwise.
*/
#if !defined(NO_CGI) || !defined(NO_FILES)
bool XX_httplib_forward_body_data( struct httplib_connection *conn, FILE *fp, SOCKET sock, SSL *ssl ) {
const char *expect;
@@ -52,7 +51,7 @@ bool XX_httplib_forward_body_data( struct httplib_connection *conn, FILE *fp, SO
if ( conn->ctx->cfg[REQUEST_TIMEOUT] != NULL ) timeout = atof( conn->ctx->cfg[REQUEST_TIMEOUT] ) / 1000.0;
else timeout = -1.0;
expect = httplib_get_header(conn, "Expect");
expect = httplib_get_header( conn, "Expect" );
if ( fp == NULL ) {
@@ -139,4 +138,3 @@ bool XX_httplib_forward_body_data( struct httplib_connection *conn, FILE *fp, SO
return success;
} /* XX_httplib_forward_body_data */
#endif

View File

@@ -29,8 +29,6 @@
#include "httplib_string.h"
#include "httplib_utils.h"
#if !defined(NO_FILES)
/*
* static void print_props( struct httplib_connection *conn, const char *uri, struct file *filep );
*
@@ -106,6 +104,7 @@ void XX_httplib_handle_propfind( struct httplib_connection *conn, const char *pa
const char *edl;
if ( conn == NULL || conn->ctx == NULL || path == NULL || filep == NULL ) return;
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) return;
depth = httplib_get_header( conn, "Depth" );
curtime = time( NULL );
@@ -139,5 +138,3 @@ void XX_httplib_handle_propfind( struct httplib_connection *conn, const char *pa
conn->num_bytes_sent += httplib_printf( conn, "%s\n", "</d:multistatus>" );
} /* XX_httplib_handle_propfind */
#endif

View File

@@ -60,14 +60,12 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) {
httplib_authorization_handler auth_handler;
void *auth_callback_data;
const char *edl;
time_t curtime;
char date[64];
union {
const char * con;
char * var;
} ptr;
#if !defined(NO_FILES)
time_t curtime = time( NULL );
char date[64];
#endif
if ( conn == NULL ) return;
@@ -86,6 +84,7 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) {
auth_handler = NULL;
auth_callback_data = NULL;
path[0] = 0;
curtime = time( NULL );
if ( ri == NULL ) return;
@@ -272,11 +271,8 @@ no_callback_resource:
* 6.2.1. thus, the server must have real files
*/
#if defined(NO_FILES)
if (1) {
#else
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) {
#endif
/*
* This server does not have any real files, thus the
* PUT/DELETE methods are not valid.
@@ -286,7 +282,6 @@ no_callback_resource:
return;
}
#if !defined(NO_FILES)
/*
* 6.2.2. Check if put authorization for static files is
* available.
@@ -296,8 +291,6 @@ no_callback_resource:
XX_httplib_send_authorization_request( conn );
return;
}
#endif
}
else {
@@ -394,25 +387,12 @@ no_callback_resource:
return;
}
else
#if defined(NO_FILES)
/*
* 9a. In case the server uses only callbacks, this uri is
* unknown.
* Then, all request handling ends here.
*/
XX_httplib_send_http_error( conn, 404, "%s", "Not Found" );
#else
/*
* 9b. This request is either for a static file or resource handled
* 9. This request is either for a static file or resource handled
* by a script file. Thus, a DOCUMENT_ROOT must exist.
*/
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) {
else if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) {
XX_httplib_send_http_error( conn, 404, "%s", "Not Found" );
return;
@@ -434,35 +414,9 @@ no_callback_resource:
if ( is_put_or_delete_request ) {
/*
* 11.1. PUT method
*/
if ( ! strcmp( ri->request_method, "PUT" ) ) {
XX_httplib_put_file( conn, path );
return;
}
/*
* 11.2. DELETE method
*/
if ( ! strcmp( ri->request_method, "DELETE" ) ) {
XX_httplib_delete_file( conn, path );
return;
}
/*
* 11.3. MKCOL method
*/
if ( ! strcmp( ri->request_method, "MKCOL" ) ) {
XX_httplib_mkcol( conn, path );
return;
}
if ( ! strcmp( ri->request_method, "PUT" ) ) { XX_httplib_put_file( conn, path ); return; }
if ( ! strcmp( ri->request_method, "DELETE" ) ) { XX_httplib_delete_file( conn, path ); return; }
if ( ! strcmp( ri->request_method, "MKCOL" ) ) { XX_httplib_mkcol( conn, path ); return; }
/*
* 11.4. PATCH method
@@ -575,8 +529,6 @@ no_callback_resource:
XX_httplib_handle_file_based_request( conn, path, &file );
#endif /* !defined(NO_FILES) */
#if 0
/*
* Perform redirect and auth checks before calling begin_request() handler.

View File

@@ -48,7 +48,6 @@ void XX_httplib_interpret_uri( struct httplib_connection *conn, char *filename,
/* TODO (high): Restructure this function */
#if !defined(NO_FILES)
const char *uri;
const char *root;
const char *rewrite;
@@ -62,9 +61,6 @@ void XX_httplib_interpret_uri( struct httplib_connection *conn, char *filename,
char *p;
const char *cgi_ext;
#endif /* !NO_CGI */
#else /* NO_FILES */
UNUSED_PARAMETER( filename_buf_len );
#endif /* NO_FILES */
if ( conn == NULL || conn->ctx == NULL || filep == NULL ) return;
@@ -79,7 +75,7 @@ void XX_httplib_interpret_uri( struct httplib_connection *conn, char *filename,
*is_put_or_delete_request = XX_httplib_is_put_or_delete_method( conn );
*is_websocket_request = XX_httplib_is_websocket_protocol( conn );
#if !defined(NO_FILES)
if ( *is_websocket_request && conn->ctx->cfg[WEBSOCKET_ROOT] != NULL ) root = conn->ctx->cfg[WEBSOCKET_ROOT];
/*
@@ -230,11 +226,8 @@ void XX_httplib_interpret_uri( struct httplib_connection *conn, char *filename,
}
}
#endif /* !defined(NO_CGI) */
#endif /* !defined(NO_FILES) */
return;
#if !defined(NO_FILES)
/*
* Reset all outputs
*/
@@ -249,6 +242,4 @@ interpret_cleanup:
*is_websocket_request = false;
*is_put_or_delete_request = false;
#endif /* !defined(NO_FILES) */
} /* XX_httplib_interpret_uri */

View File

@@ -24,8 +24,6 @@
#include "httplib_main.h"
#if !defined(NO_FILES)
/*
* bool XX_httplib_is_authorized_for_put( struct httplib_connection *conn );
*
@@ -40,7 +38,8 @@ bool XX_httplib_is_authorized_for_put( struct httplib_connection *conn ) {
const char *passfile;
bool ret;
if ( conn == NULL || conn->ctx == NULL ) return 0;
if ( conn == NULL || conn->ctx == NULL ) return false;
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) return false;
passfile = conn->ctx->cfg[PUT_DELETE_PASSWORDS_FILE];
@@ -55,5 +54,3 @@ bool XX_httplib_is_authorized_for_put( struct httplib_connection *conn ) {
return false;
} /* XX_httplib_is_authorized_for_put */
#endif

View File

@@ -36,7 +36,6 @@
* location specificied by the request URI.
*/
#if !defined(NO_FILES)
void XX_httplib_mkcol( struct httplib_connection *conn, const char *path ) {
int rc;
@@ -46,6 +45,7 @@ void XX_httplib_mkcol( struct httplib_connection *conn, const char *path ) {
time_t curtime;
if ( conn == NULL || conn->ctx == NULL ) return;
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) return;
curtime = time( NULL );
@@ -98,5 +98,3 @@ void XX_httplib_mkcol( struct httplib_connection *conn, const char *path ) {
}
} /* XX_httplib_mkcol */
#endif /* !NO_FILES */

View File

@@ -49,7 +49,7 @@ void XX_httplib_prepare_cgi_environment( struct httplib_connection *conn, const
int i;
bool truncated;
if ( conn == NULL || conn->ctx == NULL || prog == NULL || env == NULL ) return;
if ( conn == NULL || conn->ctx == NULL || prog == NULL || env == NULL || conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) return;
env->conn = conn;
env->buflen = CGI_ENVIRONMENT_SIZE;
@@ -60,8 +60,8 @@ void XX_httplib_prepare_cgi_environment( struct httplib_connection *conn, const
env->var = httplib_malloc( env->buflen * sizeof(char *) );
if ( conn->ctx->cfg[AUTHENTICATION_DOMAIN] != NULL ) XX_httplib_addenv( env, "SERVER_NAME=%s", conn->ctx->cfg[AUTHENTICATION_DOMAIN] );
if ( conn->ctx->cfg[DOCUMENT_ROOT] != NULL ) XX_httplib_addenv( env, "SERVER_ROOT=%s", conn->ctx->cfg[DOCUMENT_ROOT] );
if ( conn->ctx->cfg[DOCUMENT_ROOT] != NULL ) XX_httplib_addenv( env, "DOCUMENT_ROOT=%s", conn->ctx->cfg[DOCUMENT_ROOT] );
XX_httplib_addenv( env, "SERVER_ROOT=%s", conn->ctx->cfg[DOCUMENT_ROOT] );
XX_httplib_addenv( env, "DOCUMENT_ROOT=%s", conn->ctx->cfg[DOCUMENT_ROOT] );
XX_httplib_addenv( env, "SERVER_SOFTWARE=%s/%s", "LibHTTP", httplib_version() );
/*
@@ -91,8 +91,7 @@ void XX_httplib_prepare_cgi_environment( struct httplib_connection *conn, const
XX_httplib_addenv( env, "SCRIPT_FILENAME=%s", prog );
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) XX_httplib_addenv( env, "PATH_TRANSLATED=" );
else if ( conn->path_info == NULL ) XX_httplib_addenv( env, "PATH_TRANSLATED=%s", conn->ctx->cfg[DOCUMENT_ROOT] );
if ( conn->path_info == NULL ) XX_httplib_addenv( env, "PATH_TRANSLATED=%s", conn->ctx->cfg[DOCUMENT_ROOT] );
else XX_httplib_addenv( env, "PATH_TRANSLATED=%s%s", conn->ctx->cfg[DOCUMENT_ROOT], conn->path_info );
XX_httplib_addenv( env, "HTTPS=%s", (conn->ssl == NULL) ? "off" : "on" );

View File

@@ -35,8 +35,6 @@
* a remote client.
*/
#if !defined(NO_FILES)
void XX_httplib_put_file( struct httplib_connection *conn, const char *path ) {
struct file file = STRUCT_FILE_INITIALIZER;
@@ -47,7 +45,8 @@ void XX_httplib_put_file( struct httplib_connection *conn, const char *path ) {
char date[64];
time_t curtime;
if ( conn == NULL ) return;
if ( conn == NULL || conn->ctx == NULL ) return;
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) return;
curtime = time( NULL );
@@ -198,5 +197,3 @@ void XX_httplib_put_file( struct httplib_connection *conn, const char *path ) {
XX_httplib_fclose( & file );
} /* XX_httplib_put_file */
#endif /* !NO_FILES */

View File

@@ -35,14 +35,13 @@
* client can use to connect to the server.
*/
#if !defined(NO_FILES)
void XX_httplib_send_options( struct httplib_connection *conn ) {
char date[64];
time_t curtime;
if ( conn == NULL ) return;
if ( conn == NULL || conn->ctx == NULL ) return;
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) return;
curtime = time( NULL );
conn->status_code = 200;
@@ -62,5 +61,3 @@ void XX_httplib_send_options( struct httplib_connection *conn ) {
XX_httplib_suggest_connection_header( conn ) );
} /* XX_httplib_send_options */
#endif

View File

@@ -32,7 +32,7 @@
static void send_ssi_file(struct httplib_connection *, const char *, struct file *, int);
static void do_ssi_include(struct httplib_connection *conn, const char *ssi, char *tag, int include_level) {
static void do_ssi_include( struct httplib_connection *conn, const char *ssi, char *tag, int include_level ) {
char file_name[MG_BUF_LEN];
char path[512];
@@ -43,7 +43,7 @@ static void do_ssi_include(struct httplib_connection *conn, const char *ssi, cha
size_t len;
bool truncated;
if ( conn == NULL || conn->ctx == NULL ) return;
if ( conn == NULL || conn->ctx == NULL || conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) return;
truncated = false;
@@ -60,8 +60,7 @@ static void do_ssi_include(struct httplib_connection *conn, const char *ssi, cha
*/
file_name[511] = 0;
if ( conn->ctx->cfg[DOCUMENT_ROOT] != NULL ) doc_root = conn->ctx->cfg[DOCUMENT_ROOT];
else doc_root = "";
doc_root = conn->ctx->cfg[DOCUMENT_ROOT];
XX_httplib_snprintf( conn, &truncated, path, sizeof(path), "%s/%s", doc_root, file_name );

View File

@@ -146,10 +146,6 @@ struct httplib_context *httplib_start( const struct httplib_callbacks *callbacks
if ( ctx->cfg[i] == NULL && default_value != NULL ) ctx->cfg[i] = httplib_strdup( default_value );
}
#if defined(NO_FILES)
if ( ctx->cfg[DOCUMENT_ROOT] != NULL ) return cleanup( ctx, "Document root must not be set" );
#endif
XX_httplib_get_system_name( & ctx->systemName );
/*

View File

@@ -37,8 +37,6 @@
* located, it's stats are returnd in stp.
*/
#if !defined(NO_FILES)
int XX_httplib_substitute_index_file( struct httplib_connection *conn, char *path, size_t path_len, struct file *filep ) {
const char *list;
@@ -48,6 +46,7 @@ int XX_httplib_substitute_index_file( struct httplib_connection *conn, char *pat
bool found;
if ( conn == NULL || conn->ctx == NULL || path == NULL ) return 0;
if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) return 0;
list = conn->ctx->cfg[INDEX_FILES];
n = strlen( path );
@@ -106,4 +105,3 @@ int XX_httplib_substitute_index_file( struct httplib_connection *conn, char *pat
return found;
} /* XX_httplib_substitute_index_file */
#endif