You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Rief, Jacob" <Ja...@TIScover.com> on 2001/08/10 22:13:09 UTC

[PATCH] mod_rewrite. Additional RewriteMap: dso

This new patch has been added as change-request with
the issue number: 7688, see also
http://bugs.apache.org/index.cgi/full/7688

Add support for mod_rewrite so that an external rewrite-program for
mapping attribute to value may link dynamically the mod_rewrite.

This method has the advantage instead of an external
rewrite-program (such as prg:/path/to/external/program) under the 
following conditions:

External rewrite programs which do their lookup by connecting
a database or other complicate operations 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 this patch to mod_rewrite: Instead of
having an external program communicating with all the httpd-process through
one
single pipe, it would be an alternative to use a dynamic shared object which
runs inside 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.

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

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 and finalite the dso.


Put the following lines into Your httpd.conf:
----- httpd.conf -----
...
RewriteEngine On
RewriteMap togglecase dso:/path/to/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 or 1.3.20 from
http://homes.tiscover.com/jrief/apache_1.3.19-rewrite-dso.patch
> cd apache_1.3.19 or 1.3.20
> 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