It was thus said that the Great Brian Mearns once stated: > On Wed, Apr 29, 2009 at 1:58 PM, ricardo figueiredo > <ricardoogrande@xxxxxxxxx> wrote: > > Sorry, > > > > Let me explain my situation again. > > I'm using directive RewriteMap using external rewriting program. > > This program is developed in language C. > > > First of all, like Eric said yesterday, you need a loop in your main > function. The program is not invoked every time the rewrite needs to > be applied, it is started once when the Apache server starts, and just > gets a new line of input for each request to be mapped. > > Second, you need to terminate your output with a newline. Apparently, > apache gave up waiting for your program to give it a valid output (one > that is terminated by a newline) and decided to go with an empty > value, instead. Using fflush is probably a good idea, but you'll want > to make sure it's inside the loop, so the output gets flushed for > every mapping. > > To make this a proper program for this use, it should read an entire > line up to and including the linebreak (which Eric also said). I think > gets or fgets will do the job just fine, and then if you want to use > scanf, you can use sscanf to scan the string that you read with fgets. > Second, you'll want some way to terminate the loop, so it doesn't run > forever. I'm not sure exactly how this is normally handled (or maybe > apache even forcibly kills the program when it's done, but that's > unlikely). My best guess would be if you read an EOF on standard > input, you can quit. Avoid gets() and use fgets(). Heck, the program is easy enough: #include <stdio.h> #include <stdlib.h> int main(int argc,char *argv[]) { char input[BUFSIZ]; int id; while(fgets(input,BUFSIZ,stdin) != NULL) { id = strtol(input,NULL,10); switch(id) { case 111: fputs("/index.html",stdout); break; case 222: fputs("/new.html",stdout); break; case 333: fputs("/tests.php?var=4/8"); break; default: fputs("/bogusrequest.html"); break; } fputc('\n',stdout); fflush(stdout); } return EXIT_SUCCESS; } fgets() returns NULL on EOF, strtol() will do the conversion for you (I find it easier to use than scanf() but that's me) and I even added a case for an unexpected value. -spc (Hope this helps) --------------------------------------------------------------------- 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@xxxxxxxxxxxxxxxx " from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx