From: Ben Laurie Date: Sat, 17 Jun 2000 11:13:05 +0000 (+0000) Subject: Command handler revamp. Note that this makes the code produce a LOT of X-Git-Tag: APACHE_2_0_ALPHA_5~320 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c1b39458ab26904dfd28dccb78d26eb8199f7cf6;p=apache Command handler revamp. Note that this makes the code produce a LOT of warnings! git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85595 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/configure.in b/configure.in index a19afe04ae..405791bc71 100644 --- a/configure.in +++ b/configure.in @@ -124,7 +124,7 @@ AC_ARG_WITH(debug,[ --with-debug Turn on debugging and compile time [if test "$GCC" = "yes"; then CFLAGS="$CFLAGS -g -Wall"; else CFLAGS="$CFLAGS -g"; fi]) AC_ARG_WITH(maintainer-mode,[ --with-maintainer-mode Turn on debugging and compile time warnings], - [if test "$GCC" = "yes"; then CFLAGS="$CFLAGS -g -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations"; else CFLAGS="$CFLAGS -g"; fi]) + [if test "$GCC" = "yes"; then CFLAGS="$CFLAGS -g -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -DAP_DEBUG"; else CFLAGS="$CFLAGS -g"; fi]) APACHE_ENABLE_LAYOUT APACHE_ENABLE_MODULES diff --git a/include/http_config.h b/include/http_config.h index b528bb32f3..7522d1a4ef 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -96,9 +96,55 @@ enum cmd_how { TAKE13 /* one or three arguments */ }; +typedef struct cmd_parms_struct cmd_parms; + +#ifdef AP_DEBUG + +typedef union { + const char *(*no_args) (cmd_parms *parms, void *mconfig); + const char *(*raw_args) (cmd_parms *parms, void *mconfig, + const char *args); + const char *(*take1) (cmd_parms *parms, void *mconfig, const char *w); + const char *(*take2) (cmd_parms *parms, void *mconfig, const char *w, + const char *w2); + const char *(*take3) (cmd_parms *parms, void *mconfig, const char *w, + const char *w2, const char *w3); + const char *(*flag) (cmd_parms *parms, void *mconfig, int on); +} cmd_func; + +# define AP_NO_ARGS func.no_args +# define AP_RAW_ARGS func.raw_args +# define AP_TAKE1 func.take1 +# define AP_TAKE2 func.take2 +# define AP_TAKE3 func.take3 +# define AP_FLAG func.flag + +# define AP_INIT_NO_ARGS(directive, func, mconfig, where, help) \ + { directive, { .no_args=func }, mconfig, where, RAW_ARGS, help } +# define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help) \ + { directive, { .raw_args=func }, mconfig, where, RAW_ARGS, help } +# define AP_INIT_TAKE1(directive, func, mconfig, where, help) \ + { directive, { .take1=func }, mconfig, where, TAKE1, help } +# define AP_INIT_ITERATE(directive, func, mconfig, where, help) \ + { directive, { .take1=func }, mconfig, where, ITERATE, help } +# define AP_INIT_TAKE2(directive, func, mconfig, where, help) \ + { directive, { .take2=func }, mconfig, where, TAKE2, help } +# define AP_INIT_TAKE12(directive, func, mconfig, where, help) \ + { directive, { .take2=func }, mconfig, where, TAKE12, help } +# define AP_INIT_FLAG(directive, func, mconfig, where, help) \ + { directive, { .flag=func }, mconfig, where, FLAG, help } + +#else + +typedef const char *(*cmd_func) (); + +# define AP_RAW_ARGS func + +#endif + typedef struct command_struct { const char *name; /* Name of this command */ - const char *(*func) (); /* Function invoked */ + cmd_func func; void *cmd_data; /* Extra data, for functions which * implement multiple commands... */ @@ -161,7 +207,8 @@ typedef struct { * use to *somebody*... */ -typedef struct { +struct cmd_parms_struct + { void *info; /* Argument to command from cmd_table */ int override; /* Which allow-override bits are set */ int limited; /* Which methods are ed */ @@ -189,7 +236,8 @@ typedef struct { void *context; /* per_dir_config vector passed * to handle_command */ const ap_directive_t *err_directive; /* directive with syntax error */ -} cmd_parms; + +}; /* This structure records the existence of handlers in a module... */ @@ -294,7 +342,8 @@ API_EXPORT(void) ap_set_module_config(void *conf_vector, module *m, void *val); /* Generic command handling function... */ -API_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *, char *, char *); +API_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *, void *, + const char *); API_EXPORT_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *, char *, char *); API_EXPORT_NONSTD(const char *) ap_set_flag_slot(cmd_parms *, char *, int); API_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *, char *, char *); diff --git a/include/http_core.h b/include/http_core.h index ee9a020872..481ff542b6 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -136,7 +136,7 @@ API_EXPORT(const char *) ap_get_server_name(request_rec *r); API_EXPORT(unsigned) ap_get_server_port(const request_rec *r); API_EXPORT(unsigned long) ap_get_limit_req_body(const request_rec *r); API_EXPORT(void) ap_custom_response(request_rec *r, int status, char *string); -API_EXPORT(int) ap_exists_config_define(char *name); +API_EXPORT(int) ap_exists_config_define(const char *name); API_EXPORT_NONSTD(int) ap_core_translate(request_rec *r); /* Authentication stuff. This is one of the places where compatibility @@ -254,7 +254,7 @@ typedef struct { #define ADD_DEFAULT_CHARSET_ON (1) #define ADD_DEFAULT_CHARSET_UNSET (2) unsigned add_default_charset : 2; - char *add_default_charset_name; + const char *add_default_charset_name; /* System Resource Control */ #ifdef RLIMIT_CPU @@ -296,7 +296,7 @@ typedef struct { * so it's at least a minimally functional web server on its own (and * can be tested that way). But let's keep it to the bare minimum: */ - char *ap_document_root; + const char *ap_document_root; /* Access control */ diff --git a/include/http_vhost.h b/include/http_vhost.h index 8d13e49ceb..256609d6aa 100644 --- a/include/http_vhost.h +++ b/include/http_vhost.h @@ -69,7 +69,8 @@ void ap_fini_vhost_config(ap_pool_t *p, server_rec *main_server); const char *ap_parse_vhost_addrs(ap_pool_t *p, const char *hostname, server_rec *s); /* handle NameVirtualHost directive */ -const char *ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *arg); +const char *ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, + const char *arg); /* given an ip address only, give our best guess as to what vhost it is */ void ap_update_vhost_given_ip(conn_rec *conn); diff --git a/include/httpd.h b/include/httpd.h index b06a4556ab..9ad14cba1f 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -558,7 +558,7 @@ API_EXPORT(const char *) ap_get_server_built(void); * each request. */ struct htaccess_result { - char *dir; /* the directory to which this applies */ + const char *dir; /* the directory to which this applies */ int override; /* the overrides allowed for the .htaccess file */ void *htaccess; /* the configuration directives */ /* the next one, or NULL if no more; N.B. never change this */ @@ -854,7 +854,7 @@ struct server_rec { int keep_alive_max; /* Maximum requests per connection */ int keep_alive; /* Use persistent connections? */ - char *path; /* Pathname for ServerPath */ + const char *path; /* Pathname for ServerPath */ int pathlen; /* Length of path */ ap_array_header_t *names; /* Normal names for ServerAlias servers */ @@ -1042,7 +1042,25 @@ API_EXPORT(extern const char *) ap_psignature(const char *prefix, request_rec *r #endif #define strtoul strtoul_is_not_a_portable_function_use_strtol_instead -#define ap_is_aborted(abort) (abort->aborted ==1) +#define ap_is_aborted(abort) (abort->aborted == 1) + + /* The C library has functions that allow const to be silently dropped ... + these macros detect the drop in maintainer mode, but use the native + methods far narmal builds + */ +#ifdef AP_DEBUG + +# define strrchr(s, c) ap_strrchr(s,c) + +char *ap_strrchr(char *s, int c); +const char *ap_strrchr_c(const char *s, int c); + +#else + +# define ap_strrchr(s, c) strrchr(s, c) +# define ap_strrchr_c(s, c) strrchr(s, c) + +#endif #ifdef __cplusplus } diff --git a/modules/http/http_core.c b/modules/http/http_core.c index dc854ac186..17b1ce6fb1 100644 --- a/modules/http/http_core.c +++ b/modules/http/http_core.c @@ -1021,7 +1021,8 @@ API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, return NULL; } -static const char *set_access_name(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_access_name(cmd_parms *cmd, void *dummy, + const char *arg) { void *sconf = cmd->server->module_config; core_server_config *conf = ap_get_module_config(sconf, &core_module); @@ -1054,8 +1055,10 @@ static const char *set_gprof_dir(cmd_parms *cmd, void *dummy, char *arg) #endif /*GPROF*/ static const char *set_add_default_charset(cmd_parms *cmd, - core_dir_config *d, char *arg) + void *d_, const char *arg) { + core_dir_config *d=d_; + const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); if (err != NULL) { return err; @@ -1074,7 +1077,8 @@ static const char *set_add_default_charset(cmd_parms *cmd, return NULL; } -static const char *set_document_root(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_document_root(cmd_parms *cmd, void *dummy, + const char *arg) { void *sconf = cmd->server->module_config; core_server_config *conf = ap_get_module_config(sconf, &core_module); @@ -1121,9 +1125,10 @@ API_EXPORT(void) ap_custom_response(request_rec *r, int status, char *string) ap_pstrdup(r->pool, string) : ap_pstrcat(r->pool, "\"", string, NULL); } -static const char *set_error_document(cmd_parms *cmd, core_dir_config *conf, - char *errno_str, char *msg) +static const char *set_error_document(cmd_parms *cmd, void *conf_, + const char *errno_str, const char *msg) { + core_dir_config *conf=conf_; int error_number, index_number, idx500; enum { MSG, LOCAL_PATH, REMOTE_PATH } what = MSG; @@ -1181,9 +1186,9 @@ static const char *set_error_document(cmd_parms *cmd, core_dir_config *conf, return NULL; } -static const char *set_override(cmd_parms *cmd, core_dir_config *d, - const char *l) +static const char *set_override(cmd_parms *cmd, void *d_, const char *l) { + core_dir_config *d=d_; char *w; const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); @@ -1224,9 +1229,9 @@ static const char *set_override(cmd_parms *cmd, core_dir_config *d, return NULL; } -static const char *set_options(cmd_parms *cmd, core_dir_config *d, - const char *l) +static const char *set_options(cmd_parms *cmd, void *d_, const char *l) { + core_dir_config *d=d_; allow_options_t opt; int first = 1; char action; @@ -1296,8 +1301,10 @@ static const char *set_options(cmd_parms *cmd, core_dir_config *d, return NULL; } -static const char *satisfy(cmd_parms *cmd, core_dir_config *c, char *arg) +static const char *satisfy(cmd_parms *cmd, void *c_, const char *arg) { + core_dir_config *c=c_; + if (!strcasecmp(arg, "all")) { c->satisfy = SATISFY_ALL; } @@ -1310,10 +1317,11 @@ static const char *satisfy(cmd_parms *cmd, core_dir_config *c, char *arg) return NULL; } -static const char *require(cmd_parms *cmd, core_dir_config *c, char *arg) +static const char *require(cmd_parms *cmd, void *c_, const char *arg) { require_line *r; - + core_dir_config *c=c_; + if (!c->ap_requires) { c->ap_requires = ap_make_array(cmd->pool, 2, sizeof(require_line)); } @@ -1383,10 +1391,10 @@ static char *unclosed_directive(cmd_parms *cmd) "> directive missing closing '>'", NULL); } -static const char *dirsection(cmd_parms *cmd, void *dummy, const char *arg) +static const char *dirsection(cmd_parms *cmd, void *mconfig, const char *arg) { const char *errmsg; - char *endp = strrchr(arg, '>'); + const char *endp = ap_strrchr_c(arg, '>'); int old_overrides = cmd->override; char *old_path = cmd->path; core_dir_config *conf; @@ -1444,10 +1452,10 @@ static const char *dirsection(cmd_parms *cmd, void *dummy, const char *arg) return NULL; } -static const char *urlsection(cmd_parms *cmd, void *dummy, const char *arg) +static const char *urlsection(cmd_parms *cmd, void *mconfig, const char *arg) { const char *errmsg; - char *endp = strrchr(arg, '>'); + const char *endp = ap_strrchr_c(arg, '>'); int old_overrides = cmd->override; char *old_path = cmd->path; core_dir_config *conf; @@ -1504,16 +1512,16 @@ static const char *urlsection(cmd_parms *cmd, void *dummy, const char *arg) return NULL; } -static const char *filesection(cmd_parms *cmd, core_dir_config *c, - const char *arg) +static const char *filesection(cmd_parms *cmd, void *mconfig, const char *arg) { const char *errmsg; - char *endp = strrchr(arg, '>'); + const char *endp = ap_strrchr_c(arg, '>'); int old_overrides = cmd->override; char *old_path = cmd->path; core_dir_config *conf; regex_t *r = NULL; const command_rec *thiscmd = cmd->cmd; + core_dir_config *c=mconfig; void *new_file_conf = ap_create_per_dir_config(cmd->pool); @@ -1571,9 +1579,9 @@ static const char *filesection(cmd_parms *cmd, core_dir_config *c, return NULL; } -static const char *start_ifmod(cmd_parms *cmd, void *dummy, char *arg) +static const char *start_ifmod(cmd_parms *cmd, void *mconfig, const char *arg) { - char *endp = strrchr(arg, '>'); + const char *endp = ap_strrchr_c(arg, '>'); int not = (arg[0] == '!'); module *found; @@ -1596,16 +1604,16 @@ static const char *start_ifmod(cmd_parms *cmd, void *dummy, char *arg) retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd, ¤t, &parent, "'); + endp = ap_strrchr_c(arg, '>'); if (endp == NULL) { return unclosed_directive(cmd); } @@ -1656,11 +1664,12 @@ static const char *start_ifdefine(cmd_parms *cmd, void *dummy, char *arg) /* httpd.conf commands... beginning with the business */ -static const char *virtualhost_section(cmd_parms *cmd, void *dummy, char *arg) +static const char *virtualhost_section(cmd_parms *cmd, void *dummy, + const char *arg) { server_rec *main_server = cmd->server, *s; const char *errmsg; - char *endp = strrchr(arg, '>'); + const char *endp = ap_strrchr_c(arg, '>'); ap_pool_t *p = cmd->pool; const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -1723,7 +1732,8 @@ static const char *set_server_alias(cmd_parms *cmd, void *dummy, return NULL; } -static const char *add_module_command(cmd_parms *cmd, void *dummy, char *arg) +static const char *add_module_command(cmd_parms *cmd, void *dummy, + const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { @@ -1751,7 +1761,7 @@ static const char *clear_module_list_command(cmd_parms *cmd, void *dummy) } static const char *set_server_string_slot(cmd_parms *cmd, void *dummy, - char *arg) + const char *arg) { /* This one's pretty generic... */ @@ -1764,11 +1774,11 @@ static const char *set_server_string_slot(cmd_parms *cmd, void *dummy, return err; } - *(char **)(struct_ptr + offset) = arg; + *(const char **)(struct_ptr + offset) = arg; return NULL; } -static const char *server_port(cmd_parms *cmd, void *dummy, char *arg) +static const char *server_port(cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); int port; @@ -1786,9 +1796,11 @@ static const char *server_port(cmd_parms *cmd, void *dummy, char *arg) return NULL; } -static const char *set_signature_flag(cmd_parms *cmd, core_dir_config *d, - char *arg) +static const char *set_signature_flag(cmd_parms *cmd, void *d_, + const char *arg) { + core_dir_config *d=d_; + const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); if (err != NULL) { return err; @@ -1809,7 +1821,8 @@ static const char *set_signature_flag(cmd_parms *cmd, core_dir_config *d, return NULL; } -static const char *set_server_root(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_server_root(cmd_parms *cmd, void *dummy, + const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -1826,7 +1839,7 @@ static const char *set_server_root(cmd_parms *cmd, void *dummy, char *arg) return NULL; } -static const char *set_timeout(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_timeout(cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); if (err != NULL) { @@ -1838,7 +1851,7 @@ static const char *set_timeout(cmd_parms *cmd, void *dummy, char *arg) } static const char *set_keep_alive_timeout(cmd_parms *cmd, void *dummy, - char *arg) + const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); if (err != NULL) { @@ -1849,7 +1862,8 @@ static const char *set_keep_alive_timeout(cmd_parms *cmd, void *dummy, return NULL; } -static const char *set_keep_alive(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_keep_alive(cmd_parms *cmd, void *dummy, + const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); if (err != NULL) { @@ -1868,7 +1882,8 @@ static const char *set_keep_alive(cmd_parms *cmd, void *dummy, char *arg) return NULL; } -static const char *set_keep_alive_max(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_keep_alive_max(cmd_parms *cmd, void *dummy, + const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); if (err != NULL) { @@ -1879,8 +1894,9 @@ static const char *set_keep_alive_max(cmd_parms *cmd, void *dummy, char *arg) return NULL; } -static const char *set_idcheck(cmd_parms *cmd, core_dir_config *d, int arg) +static const char *set_idcheck(cmd_parms *cmd, void *d_, int arg) { + core_dir_config *d=d_; const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); if (err != NULL) { return err; @@ -1890,9 +1906,11 @@ static const char *set_idcheck(cmd_parms *cmd, core_dir_config *d, int arg) return NULL; } -static const char *set_hostname_lookups(cmd_parms *cmd, core_dir_config *d, - char *arg) +static const char *set_hostname_lookups(cmd_parms *cmd, void *d_, + const char *arg) { + core_dir_config *d=d_; + const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); if (err != NULL) { return err; @@ -1913,7 +1931,8 @@ static const char *set_hostname_lookups(cmd_parms *cmd, core_dir_config *d, return NULL; } -static const char *set_serverpath(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_serverpath(cmd_parms *cmd, void *dummy, + const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); if (err != NULL) { @@ -1925,8 +1944,9 @@ static const char *set_serverpath(cmd_parms *cmd, void *dummy, char *arg) return NULL; } -static const char *set_content_md5(cmd_parms *cmd, core_dir_config *d, int arg) +static const char *set_content_md5(cmd_parms *cmd, void *d_, int arg) { + core_dir_config *d=d_; const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); if (err != NULL) { return err; @@ -1936,9 +1956,10 @@ static const char *set_content_md5(cmd_parms *cmd, core_dir_config *d, int arg) return NULL; } -static const char *set_use_canonical_name(cmd_parms *cmd, core_dir_config *d, - char *arg) +static const char *set_use_canonical_name(cmd_parms *cmd, void *d_, + const char *arg) { + core_dir_config *d=d_; const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); if (err != NULL) { return err; @@ -1960,7 +1981,8 @@ static const char *set_use_canonical_name(cmd_parms *cmd, core_dir_config *d, } -static const char *include_config (cmd_parms *cmd, void **dummy, char *name) +static const char *include_config (cmd_parms *cmd, void *dummy, + const char *name) { ap_directive_t *conftree = NULL; @@ -2048,7 +2070,8 @@ API_EXPORT(const char *) ap_psignature(const char *prefix, request_rec *r) * Load an authorisation realm into our location configuration, applying the * usual rules that apply to realms. */ -static const char *set_authname(cmd_parms *cmd, void *mconfig, char *word1) +static const char *set_authname(cmd_parms *cmd, void *mconfig, + const char *word1) { core_dir_config *aconfig = (core_dir_config *)mconfig; @@ -2141,7 +2164,8 @@ static void ap_set_version(ap_pool_t *pconf) } } -static const char *set_serv_tokens(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_serv_tokens(cmd_parms *cmd, void *dummy, + const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { @@ -2163,7 +2187,8 @@ static const char *set_serv_tokens(cmd_parms *cmd, void *dummy, char *arg) return NULL; } -static const char *set_limit_req_line(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_limit_req_line(cmd_parms *cmd, void *dummy, + const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); @@ -2187,7 +2212,7 @@ static const char *set_limit_req_line(cmd_parms *cmd, void *dummy, char *arg) } static const char *set_limit_req_fieldsize(cmd_parms *cmd, void *dummy, - char *arg) + const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); @@ -2211,7 +2236,8 @@ static const char *set_limit_req_fieldsize(cmd_parms *cmd, void *dummy, return NULL; } -static const char *set_limit_req_fields(cmd_parms *cmd, void *dummy, char *arg) +static const char *set_limit_req_fields(cmd_parms *cmd, void *dummy, + const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); @@ -2230,9 +2256,10 @@ static const char *set_limit_req_fields(cmd_parms *cmd, void *dummy, char *arg) return NULL; } -static const char *set_limit_req_body(cmd_parms *cmd, core_dir_config *conf, - char *arg) +static const char *set_limit_req_body(cmd_parms *cmd, void *conf_, + const char *arg) { + core_dir_config *conf=conf_; const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); if (err != NULL) { return err; @@ -2272,18 +2299,22 @@ static const char *no_set_limit(cmd_parms *cmd, core_dir_config *conf, #endif #ifdef RLIMIT_CPU -static const char *set_limit_cpu(cmd_parms *cmd, core_dir_config *conf, - char *arg, char *arg2) +static const char *set_limit_cpu(cmd_parms *cmd, void *conf_, + const char *arg, const char *arg2) { + core_dir_config *conf=conf_; + unixd_set_rlimit(cmd, &conf->limit_cpu, arg, arg2, RLIMIT_CPU); return NULL; } #endif #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS) -static const char *set_limit_mem(cmd_parms *cmd, core_dir_config *conf, - char *arg, char * arg2) +static const char *set_limit_mem(cmd_parms *cmd, void *conf_, + const char *arg, const char * arg2) { + core_dir_config *conf=conf_; + #if defined(RLIMIT_AS) unixd_set_rlimit(cmd, &conf->limit_mem, arg, arg2 ,RLIMIT_AS); #elif defined(RLIMIT_DATA) @@ -2296,9 +2327,11 @@ static const char *set_limit_mem(cmd_parms *cmd, core_dir_config *conf, #endif #ifdef RLIMIT_NPROC -static const char *set_limit_nproc(cmd_parms *cmd, core_dir_config *conf, - char *arg, char * arg2) +static const char *set_limit_nproc(cmd_parms *cmd, void *conf_, + const char *arg, const char * arg2) { + core_dir_config *conf=conf_; + unixd_set_rlimit(cmd, &conf->limit_nproc, arg, arg2, RLIMIT_NPROC); return NULL; } @@ -2312,158 +2345,166 @@ static const command_rec core_cmds[] = { /* Old access config file commands */ -{ "name, '/')) - m->name = 1 + strrchr(m->name, '/'); - if (strrchr(m->name, '\\')) - m->name = 1 + strrchr(m->name, '\\'); + if (ap_strrchr_c(m->name, '/')) + m->name = 1 + ap_strrchr_c(m->name, '/'); + if (ap_strrchr_c(m->name, '\\')) + m->name = 1 + ap_strrchr_c(m->name, '\\'); #ifdef _OSD_POSIX /* __FILE__="*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)" */ /* We cannot fix the string in-place, because it's const */ @@ -635,7 +635,7 @@ API_EXPORT(void) ap_clear_module_list() */ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, - void *mconfig, const char *args) + void *mconfig, const char *args) { char *w, *w2, *w3; const char *errmsg; @@ -651,16 +651,14 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, #ifdef RESOLVE_ENV_PER_TOKEN args = ap_resolve_env(parms->pool,args); #endif - return ((const char *(*)(cmd_parms *, void *, const char *)) - (cmd->func)) (parms, mconfig, args); + return cmd->AP_RAW_ARGS(parms, mconfig, args); case NO_ARGS: if (*args != 0) return ap_pstrcat(parms->pool, cmd->name, " takes no arguments", NULL); - return ((const char *(*)(cmd_parms *, void *)) - (cmd->func)) (parms, mconfig); + return cmd->AP_NO_ARGS(parms, mconfig); case TAKE1: w = ap_getword_conf(parms->pool, &args); @@ -669,11 +667,9 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, return ap_pstrcat(parms->pool, cmd->name, " takes one argument", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return ((const char *(*)(cmd_parms *, void *, const char *)) - (cmd->func)) (parms, mconfig, w); + return cmd->AP_TAKE1(parms, mconfig, w); case TAKE2: - w = ap_getword_conf(parms->pool, &args); w2 = ap_getword_conf(parms->pool, &args); @@ -681,8 +677,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, return ap_pstrcat(parms->pool, cmd->name, " takes two arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return ((const char *(*)(cmd_parms *, void *, const char *, - const char *)) (cmd->func)) (parms, mconfig, w, w2); + return cmd->AP_TAKE2(parms, mconfig, w, w2); case TAKE12: @@ -693,9 +688,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, return ap_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return ((const char *(*)(cmd_parms *, void *, const char *, - const char *)) (cmd->func)) (parms, mconfig, w, - *w2 ? w2 : NULL); + return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL); case TAKE3: @@ -707,9 +700,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, return ap_pstrcat(parms->pool, cmd->name, " takes three arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return ((const char *(*)(cmd_parms *, void *, const char *, - const char *, const char *)) (cmd->func)) (parms, - mconfig, w, w2, w3); + return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case TAKE23: @@ -722,9 +713,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, " takes two or three arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return ((const char *(*)(cmd_parms *, void *, const char *, - const char *, const char *)) (cmd->func)) (parms, - mconfig, w, w2, w3); + return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case TAKE123: @@ -737,9 +726,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, " takes one, two or three arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return ((const char *(*)(cmd_parms *, void *, const char *, - const char *, const char *)) (cmd->func)) (parms, - mconfig, w, w2, w3); + return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case TAKE13: @@ -752,16 +739,15 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, " takes one or three arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return ((const char *(*)(cmd_parms *, void *, const char *, - const char *, const char *)) (cmd->func)) (parms, - mconfig, w, w2, w3); + return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case ITERATE: while (*(w = ap_getword_conf(parms->pool, &args)) != '\0') - if ((errmsg = ((const char *(*)(cmd_parms *, void *, - const char *)) (cmd->func)) (parms, mconfig, w))) - return errmsg; + { + if ((errmsg = cmd->AP_TAKE1(parms, mconfig, w))) + return errmsg; + } return NULL; @@ -774,12 +760,11 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, " requires at least two arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') - if ((errmsg = ((const char *(*)(cmd_parms *, void *, - const char *, const char *)) (cmd->func)) (parms, - mconfig, w, w2))) - return errmsg; + { + if ((errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2))) + return errmsg; + } return NULL; @@ -791,8 +776,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, return ap_pstrcat(parms->pool, cmd->name, " must be On or Off", NULL); - return ((const char *(*)(cmd_parms *, void *, int)) - (cmd->func)) (parms, mconfig, strcasecmp(w, "off") != 0); + return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0); default: @@ -1101,12 +1085,13 @@ API_EXPORT(const char *) ap_build_config(cmd_parms *parms, */ API_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd, - char *struct_ptr, char *arg) + void *struct_ptr, + const char *arg) { /* This one's pretty generic... */ int offset = (int) (long) cmd->info; - *(char **) (struct_ptr + offset) = arg; + *(const char **) ((char *)struct_ptr + offset) = arg; return NULL; } diff --git a/server/util.c b/server/util.c index daa4227e3d..2f4ec7b76d 100644 --- a/server/util.c +++ b/server/util.c @@ -2016,3 +2016,14 @@ API_EXPORT(char *) ap_escape_quotes (ap_pool_t *p, const char *instring) *outchr = '\0'; return outstring; } + +#ifdef AP_DEBUG +# undef strrchr + +char *ap_strrchr(char *s, int c) +{ return strrchr(s,c); } + +const char *ap_strrchr_c(const char *s, int c) +{ return strrchr(s,c); } + +#endif diff --git a/server/vhost.c b/server/vhost.c index 0905eb63e8..920146366a 100644 --- a/server/vhost.c +++ b/server/vhost.c @@ -179,8 +179,8 @@ void ap_init_vhost_config(ap_pool_t *p) * *paddr is the variable used to keep track of **paddr between calls * port is the default port to assume */ -static const char *get_addresses(ap_pool_t *p, char *w, server_addr_rec ***paddr, - unsigned port) +static const char *get_addresses(ap_pool_t *p, const char *w, + server_addr_rec ***paddr, unsigned port) { struct hostent *hep; unsigned long my_addr; @@ -282,7 +282,8 @@ const char *ap_parse_vhost_addrs(ap_pool_t *p, const char *hostname, server_rec } -const char *ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *arg) +const char *ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, + const char *arg) { /* use whatever port the main server has at this point */ return get_addresses(cmd->pool, arg, &name_vhost_list_tail,