Path: secnews.netscape.com!rls@netscape.com
From: Rob McCool
Newsgroups: netscape.devs-nsapi
Subject: Re: How to Invoke CGI from NSAPI Function
Date: Tue, 19 Nov 1996 17:21:51 -0800
Giles Douglas wrote:
>
> Gary Gies wrote:
> >
> > I have a simple (I hope) Question.
> >
> > Suppose that I have a NSAPI function that does a bunch of checks on a
> > query string, then depending on its value, may return data, or may want
> > to kick off a CGI to return data.
> >
> > So the question is...
> >
> > How do I kick off a CGI from within a NSAPI function.
> >
> > It is unclear how to do this.
>
> Its actually documented in the netscape help pages somewhere I think,
> http://help.netscape.com
>
> > I want DoIt to Run a cgi named mycgi in this cgi-bin directory.
>
> FuncPtr myptr;
> myptr = func_find("send-cgi");
> rval=(myptr)(pb,sn,rq);
>
> Of course, you'll have to setup the filename you want to run
>
> pb_param *pp=pblock_find("ppath",rq->vars);
> strcpy(pp->value,"/cgi-bin/doit.cgi");
This is correct. Two minor edits:
If DoIt is a NameTrans or AuthTrans function, then ppath is correct.
Otherwise, it should be "path".
Also, it is safer to do:
pb_param *pp = pblock_find("path", rq->vars);
FREE(pp->value);
pp->value = STRDUP("/path/to/cgi-bin/doit.cgi");
because in your case, if the path being replaced is shorter than
/cgi-bin/doit.cgi, then you'll walk on innocent memory.
>
> And set the content-type correctly:
>
> param_free(pblock_remove("content-type",rq->srvhdrs));
> pblock_nvinsert("content-type","magnus-internal/cgi",rq->srvhdrs);
>
> Of course, that was from memory, I probably forgot something. But its
> along those lines.
>
> --
> ---
> Giles Douglas - giles@onlinemagic.net - Online Magic NY - 212 373 0237
--
Rob McCool, robm@netscape.com http://home.netscape.com/people/robm/
Stunt Programmer, Netscape Communications Corporation
It was working ten minutes ago, I swear...
Reproduced by permission of the author.