From: Ruediger Pluem Date: Wed, 22 Oct 2008 10:23:52 +0000 (+0000) Subject: * Move ap_timeout_parameter_parse from mod_proxy.c to server/util.c and thus X-Git-Tag: 2.3.0~247 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=81c73ca116cc13acdce5cab416d13ec93f86fdb7;p=apache * Move ap_timeout_parameter_parse from mod_proxy.c to server/util.c and thus make it part of the public API. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@707022 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index e0e1623e75..06c1e47314 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ Changes with Apache 2.3.0 [ When backported to 2.2.x, remove entry from this file ] + *) core: Add ap_timeout_parameter_parse to public API. [Ruediger Pluem] + *) mod_proxy: Prevent segmentation faults by correctly flushing all buckets from the proxy backend. PR 45792 [Ruediger Pluem] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 85814ee772..8e217fa265 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -170,6 +170,7 @@ * 20080830.0 (2.3.0-dev) Cookies can be set on headers_out and err_headers_out * 20080920.0 (2.3.0-dev) Add ap_mpm_register_timed_callback. * 20080920.1 (2.3.0-dev) Export mod_rewrite.h in the public API. + * 20080920.2 (2.3.0-dev) Added ap_timeout_parameter_parse to util.c / httpd.h * */ @@ -178,7 +179,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20080920 #endif -#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/httpd.h b/include/httpd.h index 2be3bf7361..57e8ed380f 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -1746,6 +1746,29 @@ AP_DECLARE(char *) ap_escape_quotes(apr_pool_t *p, const char *instring); AP_DECLARE(char *) ap_append_pid(apr_pool_t *p, const char *string, const char *delim); +/** + * Parse a given timeout parameter string into an apr_interval_time_t value. + * The unit of the time interval is given as postfix string to the numeric + * string. Currently the following units are understood: + * + * ms : milliseconds + * s : seconds + * mi[n] : minutes + * h : hours + * + * If no unit is contained in the given timeout parameter the default_time_unit + * will be used instead. + * @param timeout_parameter The string containing the timeout parameter. + * @param timeout The timeout value to be returned. + * @param default_time_unit The default time unit to use if none is specified + * in timeout_parameter. + * @return Status value indicating whether the parsing was successful or not. + */ +AP_DECLARE(apr_status_t) ap_timeout_parameter_parse( + const char *timeout_parameter, + apr_interval_time_t *timeout, + const char *default_time_unit); + /* Misc system hackery */ /** * Given the name of an object in the file system determine if it is a directory diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index 6be8d5f1c6..f703129db2 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -41,76 +41,6 @@ static int ap_proxy_lb_worker_size(void) return sizeof(proxy_worker_stat); } -/** - * Parse a given timeout parameter string into an apr_interval_time_t value. - * The unit of the time interval is given as postfix string to the numeric - * string. Currently the following units are understood: - * - * ms : milliseconds - * s : seconds - * mi[n] : minutes - * h : hours - * - * If no unit is contained in the given timeout parameter the default_time_unit - * will be used instead. - * @param timeout_parameter The string containing the timeout parameter. - * @param timeout The timeout value to be returned. - * @param default_time_unit The default time unit to use if none is specified - * in timeout_parameter. - * @return Status value indicating whether the parsing was successful or not. - */ -/* - * XXX: Once this function has its final status parameter wise it makes sense - * to move it to some of the util??? files under server/ as public API. - */ -static apr_status_t ap_timeout_parameter_parse(const char *timeout_parameter, - apr_interval_time_t *timeout, - const char *default_time_unit) -{ - char *endp; - const char *time_str; - apr_int64_t tout; - - tout = apr_strtoi64(timeout_parameter, &endp, 10); - if (errno) { - return errno; - } - if (!endp || !*endp) { - time_str = default_time_unit; - } - else { - time_str = endp; - } - - switch (*time_str) { - /* Time is in seconds */ - case 's': - *timeout = (apr_interval_time_t) apr_time_from_sec(tout); - break; - case 'h': - /* Time is in hours */ - *timeout = (apr_interval_time_t) apr_time_from_sec(tout * 3600); - break; - case 'm': - switch (*(++time_str)) { - /* Time is in miliseconds */ - case 's': - *timeout = (apr_interval_time_t) tout * 1000; - break; - /* Time is in minutes */ - case 'i': - *timeout = (apr_interval_time_t) apr_time_from_sec(tout * 60); - break; - default: - return APR_EGENERAL; - } - break; - default: - return APR_EGENERAL; - } - return APR_SUCCESS; -} - /* * A Web proxy module. Stages: * diff --git a/server/util.c b/server/util.c index de23e514e2..3651e05931 100644 --- a/server/util.c +++ b/server/util.c @@ -2152,3 +2152,71 @@ AP_DECLARE(char *) ap_append_pid(apr_pool_t *p, const char *string, delim, getpid()); } + +/** + * Parse a given timeout parameter string into an apr_interval_time_t value. + * The unit of the time interval is given as postfix string to the numeric + * string. Currently the following units are understood: + * + * ms : milliseconds + * s : seconds + * mi[n] : minutes + * h : hours + * + * If no unit is contained in the given timeout parameter the default_time_unit + * will be used instead. + * @param timeout_parameter The string containing the timeout parameter. + * @param timeout The timeout value to be returned. + * @param default_time_unit The default time unit to use if none is specified + * in timeout_parameter. + * @return Status value indicating whether the parsing was successful or not. + */ +AP_DECLARE(apr_status_t) ap_timeout_parameter_parse( + const char *timeout_parameter, + apr_interval_time_t *timeout, + const char *default_time_unit) +{ + char *endp; + const char *time_str; + apr_int64_t tout; + + tout = apr_strtoi64(timeout_parameter, &endp, 10); + if (errno) { + return errno; + } + if (!endp || !*endp) { + time_str = default_time_unit; + } + else { + time_str = endp; + } + + switch (*time_str) { + /* Time is in seconds */ + case 's': + *timeout = (apr_interval_time_t) apr_time_from_sec(tout); + break; + case 'h': + /* Time is in hours */ + *timeout = (apr_interval_time_t) apr_time_from_sec(tout * 3600); + break; + case 'm': + switch (*(++time_str)) { + /* Time is in miliseconds */ + case 's': + *timeout = (apr_interval_time_t) tout * 1000; + break; + /* Time is in minutes */ + case 'i': + *timeout = (apr_interval_time_t) apr_time_from_sec(tout * 60); + break; + default: + return APR_EGENERAL; + } + break; + default: + return APR_EGENERAL; + } + return APR_SUCCESS; +} +