httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francis Daly <>
Subject Re: [PATCH] mod_negotiation and order of suffixes
Date Fri, 06 Apr 2001 17:24:55 GMT
On Thu, Apr 05, 2001 at 09:29:27PM +0100, Francis Daly wrote:

Replying to my own post, to add to it before I go away for the

> The patch is relative to the version of mod_negotiation.c distributed
> with apache-2.0.15.  I believe that's identical to the one from
> apache-2.0.16.

There are a few enhancements to this patch, which relate to optimising
for the normal case.  I've attached three individual patches to it, as
described below -- attached, because I don't see how to cleanly append
them while keeping them distinct.  Hopefully that won't break for

The first moves a constant calculation out of a loop -- at the cost of
one int and one strchr() in each request, it saves one strchr() per
file in the directory, if the request contains no dots.

The second requires the first to have been applied.  It moves another
constant calculation out of a loop -- at the cost of a further
strchr() per request where the request contains at least one dot, it
saves one strchr() per file, if the request contains exactly one dot.

Without having numbers to back me up, I'd dare suggest that the normal
case for mod_negotiation and faked type-maps involves requests with 0
or 1 dots (index or index.html, rather than index.html.en) in
directories containing enough files to make both patches worthwhile.

If that's not the normal case, then either or both patches can be

The first patch is relative to the distributed mod_negotiation.c from
apache-2.0.15, patched with the "order" diff from
<>.  The second patch is relative to the
result of the first patch.  In fact, the second is a diff -u -b,
because the main change is surrounding a while loop with an if
statement, and consequently indenting the loop.  I presume it's clearer
to use the -b here.

The third patch is independent of the first two -- it implements the
side note from the original mail.  The effect of this is to limit the
number of different URLs which will return the same Content-Location,
and also prevent the server working too hard when a malicious request
with a thousand trailing dots is received.

As provided here, it is a diff against the same code as the first
patch; it can be applied equally to the output of the first or second
patch, modulo a warning about line offsets.

One thing I'm not certain about, is where precisely the three lines of
the third patch should go -- depending on the common requests and
directories, it may be more efficient overall to have it on either
side of one of the if(dots_in_request) tests.

Each of those are changes to the original patch.  If preferred, I can
provide a single patch against the distributed mod_negotiation.c which
includes all of the changes.

Oh, and having thought about it properly, it seems clear that the
mention of PR6282 was in the wrong place -- if anywhere, before the
while loop reading into &dirent would be the place to take care of it.
But that's a completely separate problem.

Finally, a coding question, if I may:

is there a reason (stylistic or otherwise), when given

    int var = 2; /* i.e., neither 0 nor 1 */

to prefer one of

    if (var) 
        ; /* var != 0 */
        ; /* var == 0 */
    if (!var)
        ; /* var == 0 */
        ; /* var != 0 */
    if (!!var) 
        ; /* var != 0 */
        ; /* var == 0 */

over the others?

For a real example, see the second diff below and dots_in_request.
I've used the first method, but don't know enough about portability to
be certain that it is as safe as the third method.

Thanks for your time,

Francis Daly

View raw message