Re: advice on httpd sought

neuss@igd.fhg.de
X-Delivered: at request of secret on dxcern.cern.ch
From: neuss@igd.fhg.de
X-Mailer-Igd: ## IGD.FHG.DE ## Thu, 7 Oct 93 09:45:55 +0100
Date: Thu, 7 Oct 93 09:45:50 +0100
Message-id: <9310070845.AA05214@wildturkey.igd.fhg.de>
To: WWW-TALK@nxoc01.cern.ch
Subject: Re: advice on httpd sought
Dear fellow Webbers,

> I can't believe I'm alone in wanting to do this. Nor that no-one has
> thought of this way of doing it. Would someone therefore please very
> kindly tell me (and preferably offline if I am asking a really dim
> question)  how to tell my httpd server that when it gets a request for a
> document with extension .blort it should pass said document through a
> filter FOO before serving it forth? 


Hmpf.. no very obvious way to do so. I had to do a similar hacking, so
I can give some help here. I'll include a code fragment at the end of my 

mail, if anyone out there needs further info, please feel free to send 

me e-mail to neuss@igd.fhg.de. What I mainly did was modify send_file()
so that if the file name equals "gen.html", it would call up a special
conversion routine. Please note that I used the new HTTP 1.0 compliant 

version of NCSA's httpd. 


Peace, Chris

/*
 *  Christian Neuss  %  neuss@igd.fhg.de  %  ..in the humdrum
 */
==== snip ====
void send_file(char *file, FILE *fd, char *args) {
    FILE *f;
    if(!(f=fopen(file,"r"))) {
        unmunge_name(file);
        die(FORBIDDEN,file,fd); /* we've already established that it exists  
*/
    }
    set_content_type(file);
#ifdef ICIB_HACK
{
    char *base; int found=0;
    for(base=file;*base;base++)if(*base=='/')found=1;
    if(found){
      for(;*base!='/';base--);
      base++;
    }else{
      base=file; 

    }
    if(strcmp(base,"gen.html")==0){
      FILE *f2;
      char *tmpfile;
      tmpfile = tmpnam(NULL);
      f2 = f;
      f = fopen(tmpfile,"wb+");
      if(f==NULL){
        char err[MAX_STRING_LEN];
        sprintf(err,"could not create temp file %s",tmpfile);
        log_error(err);
      }
      ConvertTable(f2,f);
      rewind(f);
      send_fd(f,fd,args);
      unlink(f);
      return;
    }
}
#endif  /* ICIB_HACK */

    send_fd(f,fd,args);
}