You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Razvan Costea-Barlutiu <cb...@laitek.com> on 2003/01/10 17:38:23 UTC

[users@httpd] mod_rewrite with external program

Hello--

I've set up a mod_rewrite engine mapped to an external program and I can't 
really make it work on my win2k box.

Below is the section of the httpd.conf dedicated to the rewrite. Basically, 
I want to rewrite any incoming URL, hence the rule (hope at least I got 
that right...)

RewriteEngine On
RewriteMap pramap prg:e:/_Archive/Source/_PRA_Apps/prarwrurl/prarwrurl_d.exe
RewriteRule ^.* ${pramap:$1}
RewriteLogLevel 9
RewriteLog e:/_Archive/Source/_PRA_Apps/prarwrurl/rewrite.log
RewriteLock	e:/_Archive/Source/_PRA_Apps/prarwrurl/rewritelock

The things is that the program starts, but it seems to be hanging the 
server, without reading anything from the stdin. The program is a plain C 
program and it doesn't do anything but printfing the input.
As soon as I kill the program, the server returns the 404 error.
I guess that this has something to do with RewriteLock and it seems that I 
just don't know how to use that (the same thing happens without the line in 
the CFG).

Below is the C source of the program.

int main(int argc, char *argv[])
{
	FILE* f = fopen("asa","wt"),*ff;
	char url[1024];
	while (1)
	{	if (ff = fopen("rewritelock","rt"))
		{	fprintf(f,"rewritelock opened");
			if (scanf("%s\n",url) != -1)
			{	fprintf(f,"URL received: %s\n",url);
				printf("http://localhost:1977");
			}
			fclose(ff);
		}
	}
	fclose(f);
	return 1;
}


Any help is much appreciated.
TIA,
--Razvan


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite with external program

Posted by Razvan Costea-Barlutiu <cb...@laitek.com>.
Thanks for your reply Zac.

Indeed, I still wear the beginners blindfold around my eyes when it comes 
to regexps... I wasn't making any logic.
But the server still hangs with no response.

In fact, the log throws at me the following lines ___before___ I kill the 
external program:
... (2) init rewrite engine with requested uri /
... (3) applying pattern '^(.*)' to uri '/'

and the following ___after____ I kill it:
... (5) map lookup OK: map=pramap key=/ -> val=
... (2) rewrite / ->
... (2) local path result:


So it seems that the program is causing this hang-up... But I really don't 
know why is that...
Did anybody had any problems of this kind?

It seems to me that this is a wild teritory of apache, as not many people 
used it (at least, I am having a hard time finding anything useful about 
this external mapping).
I need to use this because I will allow users (programs) to query for files 
and folders on the servers that have very long paths (>256) and I need the 
rewriting program to perform a transformation of the incoming paths, so 
this cannot be done with mod_rewrite alone.

Thanks again and I hope to hear/write from any you...

--Razvan


At 03:49 11-01-03 +1100, you wrote:
>I'm not a big mod_rewrite user, so I can't offer any comments on your
>actual program, however it seems to me that the big problem here is
>withyour RewriteRule - you're making use of a backreference ($1) without
>actually defining it.  Assuming all is well with your program, that would
>explain why it is sitting there without responding.
>
>Try this instead:
>
>RewriteRule ^(.*) ${pramap:$1}
>
>
>Cheers,
>
>
>Zac



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] mod_rewrite with external program probably useful tip

Posted by Razvan Costea-Barlutiu <cb...@laitek.com>.
[This is a follow-up on  {mod_rewrite with external program} topic]

Well, I finally got it so I am posting this just in case someone else runs 
into such problem with Apache and C (as stated before, the internet looked 
to me extremely arid on this matter). It was not a big deal after all, 
but... it cost me several hours to figure it out.

Indeed, the rewriteLock was not the problem - the server runs with that 
option off by default anyway. The problem was the buffered I/O on the 
rewriting program. But that's clearly stated into the mod_rewrite 
documentation. However, the thing was that I wasn't realizing that I was 
doing buffered I/O, as this is also the default option for stdin/out 
operations, at least on windows.

Hence, the code:

while(1)
{       if (scanf("%s\n",url))
         {       ... do the monkey...
                 printf("%s\n",resultedURL);
         }
}
will hang on the ___printf___ part and Apache will never get a chance to 
see the new url...

A simple (and, after all this time, obvious) call to setbuf function will 
release the program and the server will resume its activity.
So,
---------->>>> setbuf(stdout,NULL)
is all that one would need to avoid certain headaches.

Regards,
--Razvan

>Hi Razvan,
>
>On Fri, Jan 10, 2003 at 06:38:23PM +0200, Razvan Costea-Barlutiu wrote:
> > RewriteEngine On
> > RewriteMap pramap 
> prg:e:/_Archive/Source/_PRA_Apps/prarwrurl/prarwrurl_d.exe
> > RewriteRule ^.* ${pramap:$1}
>
>I'm not a big mod_rewrite user, so I can't offer any comments on your
>actual program, however it seems to me that the big problem here is
>withyour RewriteRule - you're making use of a backreference ($1) without
>actually defining it.  Assuming all is well with your program, that would
>explain why it is sitting there without responding.



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite with external program

Posted by Zac Stevens <zt...@cryptocracy.com>.
Hi Razvan,

On Fri, Jan 10, 2003 at 06:38:23PM +0200, Razvan Costea-Barlutiu wrote:
> RewriteEngine On
> RewriteMap pramap prg:e:/_Archive/Source/_PRA_Apps/prarwrurl/prarwrurl_d.exe
> RewriteRule ^.* ${pramap:$1}

I'm not a big mod_rewrite user, so I can't offer any comments on your
actual program, however it seems to me that the big problem here is
withyour RewriteRule - you're making use of a backreference ($1) without
actually defining it.  Assuming all is well with your program, that would
explain why it is sitting there without responding.

Try this instead:

RewriteRule ^(.*) ${pramap:$1}


Cheers,


Zac

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite with external program

Posted by Zac Stevens <zt...@cryptocracy.com>.
Hi Razvan,

On Fri, Jan 10, 2003 at 06:38:23PM +0200, Razvan Costea-Barlutiu wrote:
> I guess that this has something to do with RewriteLock and it seems that I 
> just don't know how to use that (the same thing happens without the line in 
> the CFG).

Another thought, from my reading of the RewriteLock documentation I don't
believe that you actually need to do anything with it from inside your
external map program.  Perhaps both Apache and your program are attempting
to use the same file to serialise access, and this is creating a deadlock.

Following that reasoning, it might be worth taking that out of your
program.  Beyond that, I'm afraid I'm out of ideas!

Good luck :)


Zac

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org