diff --git a/include/libhttp.h b/include/libhttp.h index 2681a507..16185a50 100644 --- a/include/libhttp.h +++ b/include/libhttp.h @@ -207,7 +207,7 @@ struct lh_clb_t { }; /************************************************************************************************/ -struct httplib_option_t { /* */ +struct lh_opt_t { /* */ const char * name; /* name of the option used when creating a context */ const char * value; /* value of the option */ }; /* */ @@ -265,7 +265,6 @@ typedef void (*httplib_websocket_close_handler)( const struct lh_ctx_t *ctx, s /* Get user data passed to httplib_start from context. */ -LIBHTTP_API void *httplib_get_user_data(const struct lh_ctx_t *ctx); struct httplib_server_ports { @@ -281,7 +280,6 @@ struct httplib_server_ports { The caller is responsibility to allocate the required memory. This function returns the number of struct httplib_server_ports elements filled in, or <0 in case of an error. */ -LIBHTTP_API int httplib_get_server_ports(const struct lh_ctx_t *ctx, int size, struct httplib_server_ports *ports); /* Add, edit or delete the entry in the passwords file. @@ -296,11 +294,9 @@ LIBHTTP_API int httplib_get_server_ports(const struct lh_ctx_t *ctx, int size, s Return: 1 on success, 0 on error. */ -LIBHTTP_API int httplib_modify_passwords_file(const char *passwords_file_name, const char *domain, const char *user, const char *password); /* Return information associated with the request. */ -LIBHTTP_API const struct lh_rqi_t *httplib_get_request_info( const struct lh_con_t *conn ); /* Send data to the client. @@ -620,7 +616,7 @@ LIBHTTP_API int httplib_closedir( DIR *dir ); LIBHTTP_API struct lh_con_t * httplib_connect_client( struct lh_ctx_t *ctx, const char *host, int port, int use_ssl ); LIBHTTP_API struct lh_con_t * httplib_connect_client_secure( struct lh_ctx_t *ctx, const struct httplib_client_options *client_options ); LIBHTTP_API struct lh_con_t * httplib_connect_websocket_client( struct lh_ctx_t *ctx, const char *host, int port, int use_ssl, const char *path, const char *origin, httplib_websocket_data_handler data_func, httplib_websocket_close_handler close_func, void *user_data ); -LIBHTTP_API struct lh_ctx_t * httplib_create_client_context( const struct lh_clb_t *callbacks, const struct httplib_option_t *options ); +LIBHTTP_API struct lh_ctx_t * httplib_create_client_context( const struct lh_clb_t *callbacks, const struct lh_opt_t *options ); LIBHTTP_API void httplib_cry( enum debug_level_t debug_level, const struct lh_ctx_t *ctx, const struct lh_con_t *conn, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(4, 5); LIBHTTP_API void httplib_destroy_client_context( struct lh_ctx_t *ctx ); LIBHTTP_API struct lh_con_t * httplib_download( struct lh_ctx_t *ctx, const char *host, int port, int use_ssl, PRINTF_FORMAT_STRING(const char *request_fmt), ...) PRINTF_ARGS(5, 6); @@ -631,9 +627,12 @@ LIBHTTP_API enum debug_level_t httplib_get_debug_level( struct lh_ctx_t *ctx ); LIBHTTP_API const char * httplib_get_header( const struct lh_con_t *conn, const char *name ); LIBHTTP_API const char * httplib_get_option( const struct lh_ctx_t *ctx, const char *name, char *buffer, size_t buflen ); LIBHTTP_API uint64_t httplib_get_random( void ); +LIBHTTP_API const struct lh_rqi_t *httplib_get_request_info( const struct lh_con_t *conn ); LIBHTTP_API int httplib_get_response( const struct lh_ctx_t *ctx, struct lh_con_t *conn, int timeout ); LIBHTTP_API const char * httplib_get_response_code_text( const struct lh_ctx_t *ctx, struct lh_con_t *conn, int response_code ); +LIBHTTP_API int httplib_get_server_ports( const struct lh_ctx_t *ctx, int size, struct httplib_server_ports *ports ); LIBHTTP_API void * httplib_get_user_connection_data( const struct lh_con_t *conn ); +LIBHTTP_API void * httplib_get_user_data( const struct lh_ctx_t *ctx ); LIBHTTP_API int httplib_get_var( const char *data, size_t data_len, const char *var_name, char *dst, size_t dst_len ); LIBHTTP_API int httplib_get_var2( const char *data, size_t data_len, const char *var_name, char *dst, size_t dst_len, size_t occurrence ); LIBHTTP_API struct tm * httplib_gmtime_r( const time_t *clock, struct tm *result ); @@ -644,6 +643,7 @@ LIBHTTP_API void httplib_lock_connection( struct lh_con_t *conn ); LIBHTTP_API void httplib_lock_context( struct lh_ctx_t *ctx ); LIBHTTP_API char * httplib_md5( char buf[33], ... ); LIBHTTP_API int httplib_mkdir( const char *path, int mode ); +LIBHTTP_API int httplib_modify_passwords_file( const char *passwords_file_name, const char *domain, const char *user, const char *password ); LIBHTTP_API DIR * httplib_opendir( const char *name ); LIBHTTP_API int httplib_poll( struct pollfd *pfd, unsigned int nfds, int timeout ); LIBHTTP_API int httplib_printf( const struct lh_ctx_t *ctx, struct lh_con_t *conn, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(3, 4); @@ -674,7 +674,7 @@ LIBHTTP_API enum debug_level_t httplib_set_debug_level( struct lh_ctx_t *ctx, en LIBHTTP_API void httplib_set_request_handler( struct lh_ctx_t *ctx, const char *uri, httplib_request_handler handler, void *cbdata ); LIBHTTP_API void httplib_set_user_connection_data( struct lh_con_t *conn, void *data ); LIBHTTP_API void httplib_set_websocket_handler( struct lh_ctx_t *ctx, const char *uri, httplib_websocket_connect_handler connect_handler, httplib_websocket_ready_handler ready_handler, httplib_websocket_data_handler data_handler, httplib_websocket_close_handler close_handler, void *cbdata ); -LIBHTTP_API struct lh_ctx_t * httplib_start( const struct lh_clb_t *callbacks, void *user_data, const struct httplib_option_t *options ); +LIBHTTP_API struct lh_ctx_t * httplib_start( const struct lh_clb_t *callbacks, void *user_data, const struct lh_opt_t *options ); LIBHTTP_API void httplib_stop( struct lh_ctx_t *ctx ); LIBHTTP_API int64_t httplib_store_body( const struct lh_ctx_t *ctx, struct lh_con_t *conn, const char *path ); LIBHTTP_API int httplib_strcasecmp( const char *s1, const char *s2 ); diff --git a/src/httplib_create_client_context.c b/src/httplib_create_client_context.c index a03fb9da..d2468ae6 100644 --- a/src/httplib_create_client_context.c +++ b/src/httplib_create_client_context.c @@ -23,7 +23,7 @@ #include "httplib_main.h" /* - * struct lh_ctx_t *httplib_create_client_context( const struct lh_clb_t *callbacks, const struct httplib_option_t *options ); + * struct lh_ctx_t *httplib_create_client_context( const struct lh_clb_t *callbacks, const struct lh_opt_t *options ); * * The function httplib_create_client_context() creates a context to be used * for one simultaneous client connection. It is not possible to use one client @@ -31,7 +31,7 @@ * contains SSL context information which is specific for one connection. */ -struct lh_ctx_t *httplib_create_client_context( const struct lh_clb_t *callbacks, const struct httplib_option_t *options ) { +struct lh_ctx_t *httplib_create_client_context( const struct lh_clb_t *callbacks, const struct lh_opt_t *options ) { struct lh_ctx_t *ctx; void (*exit_callback)(const struct lh_ctx_t *ctx); diff --git a/src/httplib_main.h b/src/httplib_main.h index 8ea00d8c..0780da1c 100644 --- a/src/httplib_main.h +++ b/src/httplib_main.h @@ -860,7 +860,7 @@ void XX_httplib_path_to_unicode( const char *path, wchar_t *wbuf, size_t wbuf_ void XX_httplib_prepare_cgi_environment( const struct lh_ctx_t *ctx, struct lh_con_t *conn, const char *prog, struct cgi_environment *env ); void XX_httplib_print_dir_entry( const struct lh_ctx_t *ctx, struct de *de ); void XX_httplib_process_new_connection( struct lh_ctx_t *ctx, struct lh_con_t *conn ); -bool XX_httplib_process_options( struct lh_ctx_t *ctx, const struct httplib_option_t *options ); +bool XX_httplib_process_options( struct lh_ctx_t *ctx, const struct lh_opt_t *options ); void XX_httplib_produce_socket( struct lh_ctx_t *ctx, const struct socket *sp ); int XX_httplib_pull( const struct lh_ctx_t *ctx, FILE *fp, struct lh_con_t *conn, char *buf, int len, double timeout ); int XX_httplib_pull_all( const struct lh_ctx_t *ctx, FILE *fp, struct lh_con_t *conn, char *buf, int len ); diff --git a/src/httplib_process_options.c b/src/httplib_process_options.c index c9e2f7c6..0a062798 100644 --- a/src/httplib_process_options.c +++ b/src/httplib_process_options.c @@ -22,16 +22,16 @@ #include "httplib_main.h" -static bool check_bool( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, bool *config ); -static bool check_dbg( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, enum debug_level_t *config ); -static bool check_dir( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ); -static bool check_file( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ); -static bool check_int( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, int *config, int minval, int maxval ); -static bool check_patt( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ); -static bool check_str( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ); +static bool check_bool( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, bool *config ); +static bool check_dbg( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, enum debug_level_t *config ); +static bool check_dir( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ); +static bool check_file( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ); +static bool check_int( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, int *config, int minval, int maxval ); +static bool check_patt( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ); +static bool check_str( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ); /* - * bool XX_httplib_process_options( struct lh_ctx_t *ctx, const struct httplib_option_t *options ); + * bool XX_httplib_process_options( struct lh_ctx_t *ctx, const struct lh_opt_t *options ); * * The function process_options() processes the user supplied options and adds * them to the central option list of the context. If en error occurs, the @@ -40,7 +40,7 @@ static bool check_str( struct lh_ctx_t *ctx, const struct httplib_option_t *o * generated. */ -bool XX_httplib_process_options( struct lh_ctx_t *ctx, const struct httplib_option_t *options ) { +bool XX_httplib_process_options( struct lh_ctx_t *ctx, const struct lh_opt_t *options ) { if ( ctx == NULL ) return true; @@ -101,7 +101,7 @@ bool XX_httplib_process_options( struct lh_ctx_t *ctx, const struct httplib_opti } /* XX_httplib_process_options */ /* - * static bool check_bool( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, bool *config ); + * static bool check_bool( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, bool *config ); * * The function check_bool() checks if an option is equal to a boolean config * parameter and stores the value if that is the case. If the value cannot be @@ -111,7 +111,7 @@ bool XX_httplib_process_options( struct lh_ctx_t *ctx, const struct httplib_opti * false is returned. */ -static bool check_bool( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, bool *config ) { +static bool check_bool( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, bool *config ) { if ( ctx == NULL || option == NULL || option->name == NULL || name == NULL || config == NULL ) { @@ -128,7 +128,7 @@ static bool check_bool( struct lh_ctx_t *ctx, const struct httplib_option_t *opt } /* check_bool */ /* - * static bool check_dir( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ); + * static bool check_dir( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ); * * The function check_dir() checks if an option is equal to a directory config * parameter and stores the value if that is the case. If the value cannot be @@ -138,7 +138,7 @@ static bool check_bool( struct lh_ctx_t *ctx, const struct httplib_option_t *opt * false is returned. */ -static bool check_dir( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ) { +static bool check_dir( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ) { if ( ctx == NULL || option == NULL || option->name == NULL || name == NULL || config == NULL ) { @@ -161,7 +161,7 @@ static bool check_dir( struct lh_ctx_t *ctx, const struct httplib_option_t *opti } /* check_dir */ /* - * static bool check_patt( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ); + * static bool check_patt( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ); * * The function check_patt() checks if an option is equal to a pattern config * parameter and stores the value if that is the case. If the value cannot be @@ -171,7 +171,7 @@ static bool check_dir( struct lh_ctx_t *ctx, const struct httplib_option_t *opti * false is returned. */ -static bool check_patt( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ) { +static bool check_patt( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ) { if ( ctx == NULL || option == NULL || option->name == NULL || name == NULL || config == NULL ) { @@ -194,7 +194,7 @@ static bool check_patt( struct lh_ctx_t *ctx, const struct httplib_option_t *opt } /* check_patt */ /* - * static bool check_file( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ); + * static bool check_file( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ); * * The function check_file() checks if an option is equal to a filename config * parameter and stores the value if that is the case. If the value cannot be @@ -204,7 +204,7 @@ static bool check_patt( struct lh_ctx_t *ctx, const struct httplib_option_t *opt * false is returned. */ -static bool check_file( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ) { +static bool check_file( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ) { if ( ctx == NULL || option == NULL || option->name == NULL || name == NULL || config == NULL ) { @@ -227,7 +227,7 @@ static bool check_file( struct lh_ctx_t *ctx, const struct httplib_option_t *opt } /* check_file */ /* - * static bool check_str( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ); + * static bool check_str( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ); * * The function check_str() checks if an option is equal to a string config * parameter and stores the value if that is the case. If the value cannot be @@ -237,7 +237,7 @@ static bool check_file( struct lh_ctx_t *ctx, const struct httplib_option_t *opt * false is returned. */ -static bool check_str( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, char **config ) { +static bool check_str( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, char **config ) { if ( ctx == NULL || option == NULL || option->name == NULL || name == NULL || config == NULL ) { @@ -270,7 +270,7 @@ static bool check_str( struct lh_ctx_t *ctx, const struct httplib_option_t *opti * valud, also false is returned. */ -static bool check_int( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, int *config, int minval, int maxval ) { +static bool check_int( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, int *config, int minval, int maxval ) { int val; @@ -297,7 +297,7 @@ static bool check_int( struct lh_ctx_t *ctx, const struct httplib_option_t *opti } /* check_int */ /* - * static bool check_dbg( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name ); + * static bool check_dbg( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name ); * * The function check_dbg() checks if an option is equal to a debug level * config parameter and stores the value if that is the case. If the value @@ -307,7 +307,7 @@ static bool check_int( struct lh_ctx_t *ctx, const struct httplib_option_t *opti * valid, also false is returned. */ -static bool check_dbg( struct lh_ctx_t *ctx, const struct httplib_option_t *option, const char *name, enum debug_level_t *config ) { +static bool check_dbg( struct lh_ctx_t *ctx, const struct lh_opt_t *option, const char *name, enum debug_level_t *config ) { int val; diff --git a/src/httplib_start.c b/src/httplib_start.c index 2eff7f90..70ccef24 100644 --- a/src/httplib_start.c +++ b/src/httplib_start.c @@ -32,14 +32,14 @@ #include "httplib_utils.h" /* - * struct lh_ctx_t *httplib_start( const struct lh_clb_t *callbacks, void *user_data, const struct httplib_t *options ); + * struct lh_ctx_t *httplib_start( const struct lh_clb_t *callbacks, void *user_data, const struct lh_opt_t *options ); * * The function httplib_start() functions as the main entry point for the LibHTTP * server. The function starts all threads and when finished returns the * context to the running server for future reference. */ -struct lh_ctx_t *httplib_start( const struct lh_clb_t *callbacks, void *user_data, const struct httplib_option_t *options ) { +struct lh_ctx_t *httplib_start( const struct lh_clb_t *callbacks, void *user_data, const struct lh_opt_t *options ) { struct lh_ctx_t *ctx; int i;