From 556cd2e4026cf9355814943da0b4ba1bda2b1ef7 Mon Sep 17 00:00:00 2001 From: Graham Leggett Date: Sat, 3 Dec 2011 18:02:24 +0000 Subject: [PATCH] Backport: mod_proxy: Remove dead code from the public API, move single use code out of the public API, remove redundant code from the public API. mod_cache: Remove redundant code from the public API. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1209960 13f79535-47bb-0310-9956-ffa450edef68 --- include/ap_mmn.h | 13 +- modules/cache/cache_util.c | 103 ------------ modules/cache/mod_cache.c | 4 +- modules/cache/mod_cache.h | 2 - modules/proxy/mod_proxy.h | 45 ----- modules/proxy/mod_proxy_ftp.c | 78 ++++++++- modules/proxy/mod_proxy_http.c | 120 ++++++++++++- modules/proxy/proxy_util.c | 299 --------------------------------- modules/proxy/proxy_util.h | 9 + 9 files changed, 211 insertions(+), 462 deletions(-) diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 4e539db751..287d15ca56 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -374,14 +374,23 @@ * 20111201.0 (2.5.0-dev) Add invalidate_entity() to the cache provider. * 20111202.0 (2.5.0-dev) Use apr_status_t across mod_session API. * 20111202.1 (2.5.0-dev) add APLOGNO() + * 20111303.0 (2.5.0-dev) Optional ap_proxy_retry_worker(), remove + * ap_proxy_string_read(), ap_cache_liststr(), + * ap_proxy_buckets_lifetime_transform(), + * ap_proxy_date_canon(), ap_proxy_is_ipaddr(), + * ap_proxy_is_domainname(), ap_proxy_is_hostname(), + * ap_proxy_is_word(), ap_proxy_hex2sec(), + * ap_proxy_sec2hex(), ap_proxy_make_fake_req(), + * ap_proxy_strmatch_path, ap_proxy_strmatch_domain, + * ap_proxy_table_unmerge(). */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ #ifndef MODULE_MAGIC_NUMBER_MAJOR -#define MODULE_MAGIC_NUMBER_MAJOR 20111202 +#define MODULE_MAGIC_NUMBER_MAJOR 20111203 #endif -#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 0 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/modules/cache/cache_util.c b/modules/cache/cache_util.c index a735cef274..5e5f7b8518 100644 --- a/modules/cache/cache_util.c +++ b/modules/cache/cache_util.c @@ -737,109 +737,6 @@ int cache_check_freshness(cache_handle_t *h, cache_request_rec *cache, } -/* - * list is a comma-separated list of case-insensitive tokens, with - * optional whitespace around the tokens. - * The return returns 1 if the token val is found in the list, or 0 - * otherwise. - */ -CACHE_DECLARE(int) ap_cache_liststr(apr_pool_t *p, const char *list, - const char *key, char **val) -{ - apr_size_t key_len; - const char *next; - - if (!list) { - return 0; - } - - key_len = strlen(key); - next = list; - - for (;;) { - - /* skip whitespace and commas to find the start of the next key */ - while (*next && (apr_isspace(*next) || (*next == ','))) { - next++; - } - - if (!*next) { - return 0; - } - - if (!strncasecmp(next, key, key_len)) { - /* this field matches the key (though it might just be - * a prefix match, so make sure the match is followed - * by either a space or an equals sign) - */ - next += key_len; - if (!*next || (*next == '=') || apr_isspace(*next) || - (*next == ',')) { - /* valid match */ - if (val) { - while (*next && (*next != '=') && (*next != ',')) { - next++; - } - if (*next == '=') { - next++; - while (*next && apr_isspace(*next )) { - next++; - } - if (!*next) { - *val = NULL; - } - else { - const char *val_start = next; - while (*next && !apr_isspace(*next) && - (*next != ',')) { - /* EAT QUOTED STRING */ - if (*next == '"' || *next == '\'') { - char delim = *next; - while (*++next != delim) { - if (!*next) { - return 0; - } - else if (*next == '\\') { - ++next; - } - } - } - next++; - } - *val = apr_pstrmemdup(p, val_start, - next - val_start); - } - } - else { - *val = NULL; - } - } - return 1; - } - } - - /* skip to the next field */ - do { - /* EAT QUOTED STRING */ - if (*next == '"' || *next == '\'') { - char delim = *next; - while (*++next != delim) { - if (!*next) { - return 0; - } - else if (*next == '\\') { - ++next; - } - } - } - next++; - if (!*next) { - return 0; - } - } while (*next != ','); - } -} - /* return each comma separated token, one at a time */ CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str) diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c index 69639326cd..391b393576 100644 --- a/modules/cache/mod_cache.c +++ b/modules/cache/mod_cache.c @@ -983,9 +983,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) */ reason = "Authorization required"; } - else if (ap_cache_liststr(NULL, - apr_table_get(r->headers_out, "Vary"), - "*", NULL)) { + else if (ap_find_token(NULL, apr_table_get(r->headers_out, "Vary"), "*")) { reason = "Vary header contains '*'"; } else if (apr_table_get(r->subprocess_env, "no-cache") != NULL) { diff --git a/modules/cache/mod_cache.h b/modules/cache/mod_cache.h index 90c3766ce2..53e80c039d 100644 --- a/modules/cache/mod_cache.h +++ b/modules/cache/mod_cache.h @@ -136,8 +136,6 @@ CACHE_DECLARE(void) ap_cache_usec2hex(apr_time_t j, char *y); CACHE_DECLARE(char *) ap_cache_generate_name(apr_pool_t *p, int dirlevels, int dirlength, const char *name); -CACHE_DECLARE(int) ap_cache_liststr(apr_pool_t *p, const char *list, - const char *key, char **val); CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str); /* Create a new table consisting of those elements from an diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 1ea2ea86c9..3cc5ed83d7 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -483,13 +483,6 @@ struct proxy_balancer_method { #define PROXY_DECLARE_DATA __declspec(dllimport) #endif -/** - * Hook an optional proxy hook. Unlike static hooks, this uses a macro - * instead of a function. - */ -#define PROXY_OPTIONAL_HOOK(name,fn,pre,succ,order) \ - APR_OPTIONAL_HOOK(proxy,name,fn,pre,succ,order) - APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r, proxy_worker *worker, proxy_server_conf *conf, char *url, const char *proxyhost, apr_port_t proxyport)) @@ -530,26 +523,15 @@ APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, request_status, /* proxy_util.c */ PROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char *dst, const char *src, size_t dlen); -PROXY_DECLARE(request_rec *) ap_proxy_make_fake_req(conn_rec *c, request_rec *r); PROXY_DECLARE(int) ap_proxy_hex2c(const char *x); PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x); PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t, int forcedec, int proxyreq); PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp, char **passwordp, char **hostp, apr_port_t *port); -PROXY_DECLARE(const char *)ap_proxy_date_canon(apr_pool_t *p, const char *x); -PROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val); -PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x); -PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y); PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message); -PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p); -PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p); -PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p); -PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p); PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr); PROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r); -PROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, size_t bufflen, int *eos); -PROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key); /* DEPRECATED (will be replaced with ap_proxy_connect_backend */ PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, apr_sockaddr_t *, const char *, proxy_server_conf *, request_rec *); PROXY_DECLARE(apr_status_t) ap_proxy_ssl_connection_cleanup(proxy_conn_rec *conn, @@ -836,28 +818,6 @@ PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r, apr_bucket_brigade *brigade); -/** - * Transform buckets from one bucket allocator to another one by creating a - * transient bucket for each data bucket and let it use the data read from - * the old bucket. Metabuckets are transformed by just recreating them. - * Attention: Currently only the following bucket types are handled: - * - * All data buckets - * FLUSH - * EOS - * - * If an other bucket type is found its type is logged as a debug message - * and APR_EGENERAL is returned. - * @param r current request record of client request. Only used for logging - * purposes - * @param from the brigade that contains the buckets to transform - * @param to the brigade that will receive the transformed buckets - * @return APR_SUCCESS if all buckets could be transformed APR_EGENERAL - * otherwise - */ -PROXY_DECLARE(apr_status_t) ap_proxy_buckets_lifetime_transform(request_rec *r, - apr_bucket_brigade *from, - apr_bucket_brigade *to); /** * Return a hash based on the passed string * @param str string to produce hash from @@ -925,12 +885,7 @@ PROXY_DECLARE(int) ap_proxy_trans_match(request_rec *r, */ int ap_proxy_lb_workers(void); -/* For proxy_util */ extern module PROXY_DECLARE_DATA proxy_module; -extern int PROXY_DECLARE_DATA proxy_lb_workers; -extern const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_path; -extern const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_domain; - #endif /*MOD_PROXY_H*/ /** @} */ diff --git a/modules/proxy/mod_proxy_ftp.c b/modules/proxy/mod_proxy_ftp.c index e7ee16609b..477bc43cfa 100644 --- a/modules/proxy/mod_proxy_ftp.c +++ b/modules/proxy/mod_proxy_ftp.c @@ -209,6 +209,80 @@ static int ftp_check_string(const char *x) return 1; } +/* + * converts a series of buckets into a string + * XXX: BillS says this function performs essentially the same function as + * ap_rgetline() in protocol.c. Deprecate this function and use ap_rgetline() + * instead? I think ftp_string_read() will not work properly on non ASCII + * (EBCDIC) machines either. + */ +static apr_status_t ftp_string_read(conn_rec *c, apr_bucket_brigade *bb, + char *buff, apr_size_t bufflen, int *eos) +{ + apr_bucket *e; + apr_status_t rv; + char *pos = buff; + char *response; + int found = 0; + apr_size_t len; + + /* start with an empty string */ + buff[0] = 0; + *eos = 0; + + /* loop through each brigade */ + while (!found) { + /* get brigade from network one line at a time */ + if (APR_SUCCESS != (rv = ap_get_brigade(c->input_filters, bb, + AP_MODE_GETLINE, + APR_BLOCK_READ, + 0))) { + return rv; + } + /* loop through each bucket */ + while (!found) { + if (*eos || APR_BRIGADE_EMPTY(bb)) { + /* The connection aborted or timed out */ + return APR_ECONNABORTED; + } + e = APR_BRIGADE_FIRST(bb); + if (APR_BUCKET_IS_EOS(e)) { + *eos = 1; + } + else { + if (APR_SUCCESS != (rv = apr_bucket_read(e, + (const char **)&response, + &len, + APR_BLOCK_READ))) { + return rv; + } + /* + * is string LF terminated? + * XXX: This check can be made more efficient by simply checking + * if the last character in the 'response' buffer is an ASCII_LF. + * See ap_rgetline() for an example. + */ + if (memchr(response, APR_ASCII_LF, len)) { + found = 1; + } + /* concat strings until buff is full - then throw the data away */ + if (len > ((bufflen-1)-(pos-buff))) { + len = (bufflen-1)-(pos-buff); + } + if (len > 0) { + memcpy(pos, response, len); + pos += len; + } + } + APR_BUCKET_REMOVE(e); + apr_bucket_destroy(e); + } + *pos = '\0'; + } + + return APR_SUCCESS; +} + /* * Canonicalise ftp URLs. */ @@ -313,7 +387,7 @@ static int ftp_getrc_msg(conn_rec *ftp_ctrl, apr_bucket_brigade *bb, char *msgbu apr_status_t rv; int eos; - if (APR_SUCCESS != (rv = ap_proxy_string_read(ftp_ctrl, bb, response, sizeof(response), &eos))) { + if (APR_SUCCESS != (rv = ftp_string_read(ftp_ctrl, bb, response, sizeof(response), &eos))) { return -1; } /* @@ -332,7 +406,7 @@ static int ftp_getrc_msg(conn_rec *ftp_ctrl, apr_bucket_brigade *bb, char *msgbu memcpy(buff, response, 3); buff[3] = ' '; do { - if (APR_SUCCESS != (rv = ap_proxy_string_read(ftp_ctrl, bb, response, sizeof(response), &eos))) { + if (APR_SUCCESS != (rv = ftp_string_read(ftp_ctrl, bb, response, sizeof(response), &eos))) { return -1; } mb = apr_cpystrn(mb, response + (' ' == response[0] ? 1 : 4), me - mb); diff --git a/modules/proxy/mod_proxy_http.c b/modules/proxy/mod_proxy_http.c index b3186b59f8..0534094ad4 100644 --- a/modules/proxy/mod_proxy_http.c +++ b/modules/proxy/mod_proxy_http.c @@ -688,6 +688,56 @@ static int spool_reqbody_cl(apr_pool_t *p, return(pass_brigade(bucket_alloc, r, p_conn, origin, header_brigade, 1)); } +/* + * Transform buckets from one bucket allocator to another one by creating a + * transient bucket for each data bucket and let it use the data read from + * the old bucket. Metabuckets are transformed by just recreating them. + * Attention: Currently only the following bucket types are handled: + * + * All data buckets + * FLUSH + * EOS + * + * If an other bucket type is found its type is logged as a debug message + * and APR_EGENERAL is returned. + */ +static apr_status_t proxy_buckets_lifetime_transform(request_rec *r, + apr_bucket_brigade *from, apr_bucket_brigade *to) +{ + apr_bucket *e; + apr_bucket *new; + const char *data; + apr_size_t bytes; + apr_status_t rv = APR_SUCCESS; + + apr_brigade_cleanup(to); + for (e = APR_BRIGADE_FIRST(from); + e != APR_BRIGADE_SENTINEL(from); + e = APR_BUCKET_NEXT(e)) { + if (!APR_BUCKET_IS_METADATA(e)) { + apr_bucket_read(e, &data, &bytes, APR_BLOCK_READ); + new = apr_bucket_transient_create(data, bytes, r->connection->bucket_alloc); + APR_BRIGADE_INSERT_TAIL(to, new); + } + else if (APR_BUCKET_IS_FLUSH(e)) { + new = apr_bucket_flush_create(r->connection->bucket_alloc); + APR_BRIGADE_INSERT_TAIL(to, new); + } + else if (APR_BUCKET_IS_EOS(e)) { + new = apr_bucket_eos_create(r->connection->bucket_alloc); + APR_BRIGADE_INSERT_TAIL(to, new); + } + else { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00964) + "Unhandled bucket type of type %s in" + " proxy_buckets_lifetime_transform", e->type->name); + apr_bucket_delete(e); + rv = APR_EGENERAL; + } + } + return rv; +} + static int ap_proxy_http_request(apr_pool_t *p, request_rec *r, proxy_conn_rec *p_conn, proxy_worker *worker, @@ -1195,6 +1245,65 @@ skip_body: return OK; } +/* + * If the date is a valid RFC 850 date or asctime() date, then it + * is converted to the RFC 1123 format. + */ +static const char *date_canon(apr_pool_t *p, const char *date) +{ + apr_status_t rv; + char* ndate; + + apr_time_t time = apr_date_parse_http(date); + if (!time) { + return date; + } + + ndate = apr_palloc(p, APR_RFC822_DATE_LEN); + rv = apr_rfc822_date(ndate, time); + if (rv != APR_SUCCESS) { + return date; + } + + return ndate; +} + +static request_rec *make_fake_req(conn_rec *c, request_rec *r) +{ + apr_pool_t *pool; + request_rec *rp; + + apr_pool_create(&pool, c->pool); + + rp = apr_pcalloc(pool, sizeof(*r)); + + rp->pool = pool; + rp->status = HTTP_OK; + + rp->headers_in = apr_table_make(pool, 50); + rp->subprocess_env = apr_table_make(pool, 50); + rp->headers_out = apr_table_make(pool, 12); + rp->err_headers_out = apr_table_make(pool, 5); + rp->notes = apr_table_make(pool, 5); + + rp->server = r->server; + rp->log = r->log; + rp->proxyreq = r->proxyreq; + rp->request_time = r->request_time; + rp->connection = c; + rp->output_filters = c->output_filters; + rp->input_filters = c->input_filters; + rp->proto_output_filters = c->output_filters; + rp->proto_input_filters = c->input_filters; + rp->client_ip = c->peer_ip; + rp->client_addr = c->peer_addr; + + rp->request_config = ap_create_request_config(pool); + proxy_run_create_req(r, rp); + + return rp; +} + static void process_proxy_header(request_rec *r, proxy_dir_conf *c, const char *key, const char *value) { @@ -1215,7 +1324,7 @@ static void process_proxy_header(request_rec *r, proxy_dir_conf *c, for (i = 0; date_hdrs[i]; ++i) { if (!strcasecmp(date_hdrs[i], key)) { apr_table_add(r->headers_out, key, - ap_proxy_date_canon(r->pool, value)); + date_canon(r->pool, value)); return; } } @@ -1444,7 +1553,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, * filter chain */ - backend->r = ap_proxy_make_fake_req(origin, r); + backend->r = make_fake_req(origin, r); /* In case anyone needs to know, this is a fake request that is really a * response. */ @@ -1646,9 +1755,8 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, */ te = apr_table_get(r->headers_out, "Transfer-Encoding"); /* strip connection listed hop-by-hop headers from response */ - backend->close += ap_proxy_liststr(apr_table_get(r->headers_out, - "Connection"), - "close"); + backend->close += ap_find_token(p, + apr_table_get(r->headers_out, "Connection"), "close"); ap_proxy_clear_connection(p, r->headers_out); if ((buf = apr_table_get(r->headers_out, "Content-Type"))) { ap_set_content_type(r, apr_pstrdup(p, buf)); @@ -1904,7 +2012,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, } /* Switch the allocator lifetime of the buckets */ - ap_proxy_buckets_lifetime_transform(r, bb, pass_bb); + proxy_buckets_lifetime_transform(r, bb, pass_bb); /* found the last brigade? */ if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(pass_bb))) { diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 79d8e15dab..63c3e4da33 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -355,151 +355,6 @@ PROXY_DECLARE(char *) return NULL; } -/* - * If the date is a valid RFC 850 date or asctime() date, then it - * is converted to the RFC 1123 format. - */ -PROXY_DECLARE(const char *) - ap_proxy_date_canon(apr_pool_t *p, const char *date) -{ - apr_status_t rv; - char* ndate; - - apr_time_t time = apr_date_parse_http(date); - if (!time) { - return date; - } - - ndate = apr_palloc(p, APR_RFC822_DATE_LEN); - rv = apr_rfc822_date(ndate, time); - if (rv != APR_SUCCESS) { - return date; - } - - return ndate; -} - -PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r) -{ - apr_pool_t *pool; - request_rec *rp; - - apr_pool_create(&pool, c->pool); - - rp = apr_pcalloc(pool, sizeof(*r)); - - rp->pool = pool; - rp->status = HTTP_OK; - - rp->headers_in = apr_table_make(pool, 50); - rp->subprocess_env = apr_table_make(pool, 50); - rp->headers_out = apr_table_make(pool, 12); - rp->err_headers_out = apr_table_make(pool, 5); - rp->notes = apr_table_make(pool, 5); - - rp->server = r->server; - rp->log = r->log; - rp->proxyreq = r->proxyreq; - rp->request_time = r->request_time; - rp->connection = c; - rp->output_filters = c->output_filters; - rp->input_filters = c->input_filters; - rp->proto_output_filters = c->output_filters; - rp->proto_input_filters = c->input_filters; - - rp->request_config = ap_create_request_config(pool); - proxy_run_create_req(r, rp); - - return rp; -} - - -/* - * list is a comma-separated list of case-insensitive tokens, with - * optional whitespace around the tokens. - * The return returns 1 if the token val is found in the list, or 0 - * otherwise. - */ -PROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val) -{ - int len, i; - const char *p; - - len = strlen(val); - - while (list != NULL) { - p = ap_strchr_c(list, ','); - if (p != NULL) { - i = p - list; - do { - p++; - } while (apr_isspace(*p)); - } - else { - i = strlen(list); - } - - while (i > 0 && apr_isspace(list[i - 1])) { - i--; - } - if (i == len && strncasecmp(list, val, len) == 0) { - return 1; - } - list = p; - } - return 0; -} - -/* - * Converts 8 hex digits to a time integer - */ -PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x) -{ - int i, ch; - unsigned int j; - - for (i = 0, j = 0; i < 8; i++) { - ch = x[i]; - j <<= 4; - if (apr_isdigit(ch)) { - j |= ch - '0'; - } - else if (apr_isupper(ch)) { - j |= ch - ('A' - 10); - } - else { - j |= ch - ('a' - 10); - } - } - if (j == 0xffffffff) { - return -1; /* so that it works with 8-byte ints */ - } - else { - return j; - } -} - -/* - * Converts a time integer to 8 hex digits - */ -PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y) -{ - int i, ch; - unsigned int j = t; - - for (i = 7; i >= 0; i--) { - ch = j & 0xF; - j >>= 4; - if (ch >= 10) { - y[i] = ch + ('A' - 10); - } - else { - y[i] = ch + '0'; - } - } - y[8] = '\0'; -} - PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message) { const char *uri = ap_escape_html(r->pool, r->uri); @@ -951,109 +806,6 @@ PROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r) return OK; } -/* - * converts a series of buckets into a string - * XXX: BillS says this function performs essentially the same function as - * ap_rgetline() in protocol.c. Deprecate this function and use ap_rgetline() - * instead? I think ap_proxy_string_read() will not work properly on non ASCII - * (EBCDIC) machines either. - */ -PROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, - char *buff, apr_size_t bufflen, int *eos) -{ - apr_bucket *e; - apr_status_t rv; - char *pos = buff; - char *response; - int found = 0; - apr_size_t len; - - /* start with an empty string */ - buff[0] = 0; - *eos = 0; - - /* loop through each brigade */ - while (!found) { - /* get brigade from network one line at a time */ - if (APR_SUCCESS != (rv = ap_get_brigade(c->input_filters, bb, - AP_MODE_GETLINE, - APR_BLOCK_READ, - 0))) { - return rv; - } - /* loop through each bucket */ - while (!found) { - if (*eos || APR_BRIGADE_EMPTY(bb)) { - /* The connection aborted or timed out */ - return APR_ECONNABORTED; - } - e = APR_BRIGADE_FIRST(bb); - if (APR_BUCKET_IS_EOS(e)) { - *eos = 1; - } - else { - if (APR_SUCCESS != (rv = apr_bucket_read(e, - (const char **)&response, - &len, - APR_BLOCK_READ))) { - return rv; - } - /* - * is string LF terminated? - * XXX: This check can be made more efficient by simply checking - * if the last character in the 'response' buffer is an ASCII_LF. - * See ap_rgetline() for an example. - */ - if (memchr(response, APR_ASCII_LF, len)) { - found = 1; - } - /* concat strings until buff is full - then throw the data away */ - if (len > ((bufflen-1)-(pos-buff))) { - len = (bufflen-1)-(pos-buff); - } - if (len > 0) { - memcpy(pos, response, len); - pos += len; - } - } - APR_BUCKET_REMOVE(e); - apr_bucket_destroy(e); - } - *pos = '\0'; - } - - return APR_SUCCESS; -} - -/* unmerge an element in the table */ -PROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key) -{ - apr_off_t offset = 0; - apr_off_t count = 0; - char *value = NULL; - - /* get the value to unmerge */ - const char *initial = apr_table_get(t, key); - if (!initial) { - return; - } - value = apr_pstrdup(p, initial); - - /* remove the value from the headers */ - apr_table_unset(t, key); - - /* find each comma */ - while (value[count]) { - if (value[count] == ',') { - value[count] = 0; - apr_table_add(t, key, value + offset); - offset = count + 1; - } - count++; - } - apr_table_add(t, key, value + offset); -} - PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *url) { @@ -2834,57 +2586,6 @@ PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r, APR_BRIGADE_INSERT_TAIL(brigade, e); } -/* - * Transform buckets from one bucket allocator to another one by creating a - * transient bucket for each data bucket and let it use the data read from - * the old bucket. Metabuckets are transformed by just recreating them. - * Attention: Currently only the following bucket types are handled: - * - * All data buckets - * FLUSH - * EOS - * - * If an other bucket type is found its type is logged as a debug message - * and APR_EGENERAL is returned. - */ -PROXY_DECLARE(apr_status_t) -ap_proxy_buckets_lifetime_transform(request_rec *r, apr_bucket_brigade *from, - apr_bucket_brigade *to) -{ - apr_bucket *e; - apr_bucket *new; - const char *data; - apr_size_t bytes; - apr_status_t rv = APR_SUCCESS; - - apr_brigade_cleanup(to); - for (e = APR_BRIGADE_FIRST(from); - e != APR_BRIGADE_SENTINEL(from); - e = APR_BUCKET_NEXT(e)) { - if (!APR_BUCKET_IS_METADATA(e)) { - apr_bucket_read(e, &data, &bytes, APR_BLOCK_READ); - new = apr_bucket_transient_create(data, bytes, r->connection->bucket_alloc); - APR_BRIGADE_INSERT_TAIL(to, new); - } - else if (APR_BUCKET_IS_FLUSH(e)) { - new = apr_bucket_flush_create(r->connection->bucket_alloc); - APR_BRIGADE_INSERT_TAIL(to, new); - } - else if (APR_BUCKET_IS_EOS(e)) { - new = apr_bucket_eos_create(r->connection->bucket_alloc); - APR_BRIGADE_INSERT_TAIL(to, new); - } - else { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "Unhandled bucket type of type %s in" - " ap_proxy_buckets_lifetime_transform", e->type->name); - apr_bucket_delete(e); - rv = APR_EGENERAL; - } - } - return rv; -} - /* * Provide a string hashing function for the proxy. * We offer 2 methods: one is the APR model but we diff --git a/modules/proxy/proxy_util.h b/modules/proxy/proxy_util.h index ac332e4d82..3b32cc052a 100644 --- a/modules/proxy/proxy_util.h +++ b/modules/proxy/proxy_util.h @@ -26,6 +26,15 @@ * @{ */ +PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p); +PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p); +PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p); +PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p); + +extern int PROXY_DECLARE_DATA proxy_lb_workers; +extern const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_path; +extern const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_domain; + /** * Register optional functions declared within proxy_util.c. */ -- 2.50.1