httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rief, Jacob" <Jacob.R...@TIScover.com>
Subject FW: [PATCH] mod_rewrite. Additional RewriteMap: dso
Date Wed, 02 May 2001 16:48:47 GMT

I would like to release a patch for mod_rewrite to add support for
an external rewrite-program which links dynamically instead of 
communicating through a pipe, such as RewriteMap
prg:/path/to/external/program
This patch is applyed to our apache servers and now runs stable for
more than one week, serving at least 300000 requests. 

I named this additional RewriteMap "dso" (dynamic shared object).
It may be used in the same way as an external mapping program.

This feature can be useful in the following conditions:
External rewrite programs which do their lookup by connecting
a database may hang. And if they hang, all of the httpd-processes which have
to
consult the external mapping programm will hang too.
To get arround this problem I added the following patch to mod_rewrite:
Instead of
having an external program communicating with all the httpd-process through
a pipe,
it would be an alternative to use a dynamic shared object which runs inside
the
each httpd's-address space.
Such a dynamic shared object can communicate through a singe function call
which I named 'rewrite_lookup_map'. This function takes three parameters,
a const char* for the key, a char* for the mapping result, and the string
length of the result buffer, currently 2048. The function should return
zero on failure and one on success.

Have a look at this example, it just maps lowercase chars to upercase
and vice versa.

----- example.c -----
int rewrite_lookup_map(const char* key, char* result, int size)
{
	int i;
	const char* c;

	i = 0;
	for (c = key; c; c++) {
		if (*c>='A' && *c<='Z') {
			result[i] = *c|32;
		} else if (*c>='a' && *c<='z') {
			result[i] = *c&223;
		} else {
			result[i] = *c;
		}
		i++;
		if (i==size-1)
			return 0;
	}
	result[i] = '\0';
	return 1;
}
----- example.c -----

You may build this example program by compiling it as dso:
> cc -c example -o example.o
> ld -shared example.o -o example.so

You may also put the functions _init() and _fini() into
Your program to initialize it.


Put the following lines into Your httpd.conf:
----- httpd.conf -----
...
RewriteEngine On
RewriteMap togglecase dso:example.so
RewriteRule ^(.*)$ ${togglecase:$1}
...
----- httpd.conf -----

and restart the server. This will toggle the case
of Your URL's. This also avoids RewriteLock directive
for external rewrite programs. In order to initialise the
module You may add the function _init() to Your external
rewrite program, but consult 'man dlopen' for details.


Download the patch for apache_1.3.19 from
http://homes.tiscover.com/jrief/apache_1.3.19-rewrite-dso.patch
> cd apache_1.3.19
> patch -p1 < apache_1.3.19.rewrite-dso.patch
configure apache before remaking with 
> configure ... --with-module=so ...
to enable dynamic linking.
> make && make install

Best luck, Jacob

Mime
View raw message