Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 15368 invoked from network); 27 Dec 2003 06:39:56 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 27 Dec 2003 06:39:56 -0000 Received: (qmail 14836 invoked by uid 500); 27 Dec 2003 06:39:33 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 14806 invoked by uid 500); 27 Dec 2003 06:39:33 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 14793 invoked by uid 500); 27 Dec 2003 06:39:33 -0000 Delivered-To: apmail-httpd-2.0-cvs@apache.org Received: (qmail 14790 invoked from network); 27 Dec 2003 06:39:33 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 27 Dec 2003 06:39:33 -0000 Received: (qmail 15351 invoked by uid 1327); 27 Dec 2003 06:39:54 -0000 Date: 27 Dec 2003 06:39:54 -0000 Message-ID: <20031227063954.15350.qmail@minotaur.apache.org> From: jerenkrantz@apache.org To: httpd-2.0-cvs@apache.org Subject: cvs commit: httpd-2.0/modules/mappers mod_rewrite.c X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N jerenkrantz 2003/12/26 22:39:54 Modified: . Tag: APACHE_2_0_BRANCH CHANGES modules/mappers Tag: APACHE_2_0_BRANCH mod_rewrite.c Log: optimization: - add comment about what subst_prefix_path function does - reduce the use of fixed buffers - get a rid of unnecessary memory operations Justin adds: Fixes // problem and rewrites subst_prefix_path to make it intelligble. Backport of modules/mappers/mod_rewrite.c r1.162 from httpd-2.1 Submitted by: Andr� Malo Reviewed by: Andr� Malo, Jeff Trawick, Justin Erenkrantz Revision Changes Path No revision No revision 1.988.2.204 +2 -0 httpd-2.0/CHANGES Index: CHANGES =================================================================== RCS file: /home/cvs/httpd-2.0/CHANGES,v retrieving revision 1.988.2.203 retrieving revision 1.988.2.204 diff -u -u -r1.988.2.203 -r1.988.2.204 --- CHANGES 27 Dec 2003 06:27:07 -0000 1.988.2.203 +++ CHANGES 27 Dec 2003 06:39:53 -0000 1.988.2.204 @@ -1,5 +1,7 @@ Changes with Apache 2.0.49 + *) Fix RewriteBase directive to not add double slashes. [Andr� Malo] + *) Improve 'configure --help' output for some modules. [Astrid Ke�ler] *) Correct UseCanonicalName Off to properly check incoming port number. No revision No revision 1.135.2.19 +36 -34 httpd-2.0/modules/mappers/mod_rewrite.c Index: mod_rewrite.c =================================================================== RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v retrieving revision 1.135.2.18 retrieving revision 1.135.2.19 diff -u -u -r1.135.2.18 -r1.135.2.19 --- mod_rewrite.c 24 Oct 2003 16:19:32 -0000 1.135.2.18 +++ mod_rewrite.c 27 Dec 2003 06:39:54 -0000 1.135.2.19 @@ -4229,47 +4229,49 @@ ** +-------------------------------------------------------+ */ +/* + * substitute the prefix path 'match' in 'input' with 'subst' + * (think of RewriteBase which substitutes the physical path with + * the virtual path) + */ + static char *subst_prefix_path(request_rec *r, char *input, char *match, const char *subst) { - char matchbuf[LONG_STRING_LEN]; - char substbuf[LONG_STRING_LEN]; - char *output; - int l; - - output = input; - - /* first create a match string which always has a trailing slash */ - l = apr_cpystrn(matchbuf, match, sizeof(matchbuf) - 1) - matchbuf; - if (!l || matchbuf[l-1] != '/') { - matchbuf[l] = '/'; - matchbuf[l+1] = '\0'; - l++; + apr_size_t len = strlen(match); + + if (len && match[len - 1] == '/') { + --len; } - /* now compare the prefix */ - if (strncmp(input, matchbuf, l) == 0) { - rewritelog(r, 5, "strip matching prefix: %s -> %s", output, output+l); - output = apr_pstrdup(r->pool, output+l); - - /* and now add the base-URL as replacement prefix */ - l = apr_cpystrn(substbuf, subst, sizeof(substbuf) - 1) - substbuf; - if (!l || substbuf[l-1] != '/') { - substbuf[l] = '/'; - substbuf[l+1] = '\0'; - l++; - } - if (output[0] == '/') { - rewritelog(r, 4, "add subst prefix: %s -> %s%s", - output, substbuf, output+1); - output = apr_pstrcat(r->pool, substbuf, output+1, NULL); + + if (!strncmp(input, match, len) && input[len++] == '/') { + apr_size_t slen, outlen; + char *output; + + rewritelog(r, 5, "strip matching prefix: %s -> %s", input, input+len); + + slen = strlen(subst); + if (slen && subst[slen - 1] != '/') { + ++slen; } - else { - rewritelog(r, 4, "add subst prefix: %s -> %s%s", - output, substbuf, output); - output = apr_pstrcat(r->pool, substbuf, output, NULL); + + outlen = strlen(input) + slen - len; + output = apr_palloc(r->pool, outlen + 1); /* don't forget the \0 */ + + memcpy(output, subst, slen); + if (slen && !output[slen-1]) { + output[slen-1] = '/'; } + memcpy(output+slen, input+len, outlen - slen); + output[outlen] = '\0'; + + rewritelog(r, 4, "add subst prefix: %s -> %s", input+len, output); + + return output; } - return output; + + /* prefix didn't match */ + return input; }