redirect_cgi.c netscape enterprise server nsapi redirect
| From: | Mike Caughran | Date: | Sat, 25 Nov 2000 01:37:09 +0000 |
| Subject: | redirect_cgi.c netscape enterprise server nsapi redirect | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-27069@lists.php.net to get a copy of this message | ||
notes on compiling and runnining an old file which I had a use for
emulates the apache action statement
under netscape web servers
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
notes by mike_caughran@admin.state.ak.us:
I found this code here:
http://swt-www.informatik.uni-hamburg.de/howto/redirect.tar.gz
vex.net is toast
useful urls:
http://docs.iplanet.com/docs/manuals/enterprise/40/nsapi/contents.htm
http://docs.iplanet.com/docs/manuals/enterprise/40/nsapi/06_exmpl.htm#1043086
I had to make some modifications so that it work with
Netscape Enterprise Server v4.1
The changes I made are here as 3 files between <snip> and </snip>
README, Makefile, and redirect_cgi.c.
The key observation here for me is that this is an ObjectType stage
nsapi module. I spent a lot of time trying with NameTrans stage
nsapi modules and made some good headway but came back to this code
after I understood the difference between the two.
I basically ripped the Makefile from the one in
/usr/netscape/server4/plugins/nsapi/examples
to get this to build
<snip README>
REDIRECT-CGI Module for Netscape Servers
Version 1.2 Copyright 1996 Rasmus Lerdorf <rasmus@vex.net>
LICENSE
-------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
See the file, COPYING, for the complete terms of the GPL.
INTRODUCTION
------------
This is a standard NSAPI module which allows you to redirect any
request to a given cgi program based on the extension of the
requested file. This is particularly useful for the PHP/FI package
(http://www.vex.net/php). The examples in the installation
instructions refer to php.cgi for this reason. This module will
however work equally well with other cgi programs.
Please note that I don't use Netscape servers myself. I only know
enough about them to be dangerous and enough to write this module.
Chances are that I won't be able to answer specific installation
questions for you. You are pretty much on your own here.
INSTALLATION
------------
Your first step is to compile the module. The included Makefile is
configured for Solaris. You will need to modify it to reflect your
local compiler conventions for creating shared libraries. Read the
Makefile. There are some hints for other operating systems.
Once you have a redirect_cgi.so shared library, you need to edit three
different server configuration files. These are in your ns-home
config directory.
In mime.types, add the following line to the end of the file:
type=magnus-internal/php exts=phtml
This creates a new mime type to be used internally by the server.
You may substitute "php" with whatever you like. Substitute phtml
with whatever extension you wish to use to base the redirection on.
Init fn=load-modules shlib=/www/nsapi/redirect_cgi.so funcs=redirect-cgi
Replace the /www/nsapi with the path to your redirect_cgi.so file.
It can be anywhere on your system.
Finally, in obj.conf, you need to insert the following line:
ObjectType fn="redirect-cgi" cgi_path="/www/cgi-bin/php.cgi"
type="magnus-internal/php"
Here, replace /www/cgi-bin/php.cgi with the path to your cgi program.
Also, replace the type with the type you configured in the mime.types file.
The line should be inserted after the "type-by-extension" line, but before
the "force-type" line.
If you want to have multiple cgi redirections, simply add more mime types
to mime.types and add multiple ObjectType lines to obj.conf.
Note that if you are running multiple servers, you will need to configure
each one individually according to the above instructions.
The most recent version of this module can be found in the file archive
at http://www.vex.net/php.
</snip>
<snip Makefile>
# Defines for example NSAPI programs running under Linux
CC_CMD=/usr/bin/gcc -fpic -DNET_SSL -DLinux -DLINUX -D_REENTRANT
LD_SHAREDCMD=/usr/bin/gcc -shared
all:
prepare:
INCLUDEDIR=/usr/netscape/server4/plugins/include
REDIRECT_OBJS = redirect_cgi.o
INCLUDE_FLAGS=-I$(INCLUDEDIR) -I$(INCLUDEDIR)/base -I$(INCLUDEDIR)/frame
COMMON_DEFS=-DMCC_HTTPD -DXP_UNIX -DSPAPI20
all: redirect_cgi.so
redirect_cgi.so: $(REDIRECT_OBJS)
$(MAKE) prepare
$(LD_SHAREDCMD) $(REDIRECT_OBJS) -o redirect_cgi.so $(EXTRA_LDDEFINES)
$(MAKE) install
$(MAKE) restart
c.o:
$(CC_CMD) $(COMMON_DEFS) $(INCLUDE_FLAGS) -c $<
clean:
rm $(OBJS) redirect_cgi.so $(EXTRA_CLEAN)
install:
cp redirect_cgi.so /usr/netscape/server4/bin
edit:
pico -w redirect_cgi.c
editconf:
pico -w /usr/netscape/server4/https-foo/config/obj.conf
restart:
/usr/netscape/server4/https-foo/stop
/usr/netscape/server4/https-foo/start
tail -f /usr/netscape/server4/https-foo/logs/errors
accesslog:
more /usr/netscape/server4/https-foo/logs/access
clearlog:
cat /dev/null > /usr/netscape/server4/https-foo/logs/access
</snip>
</snip redirect_cgi.c>
/***[redirect_cgi.c]**********************************************[TAB=4]****\
* *
* NSAPI CGI Redirection Module *
* *
* Copyright 1995,1996 Rasmus Lerdorf <rasmus@vex.net> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
* 8/28/98 - Modified by Landon Bradshaw *
* Added the HTTP_REDIRECT_STATUS to the environment so that you *
* you can compile PHP with --force-redirect-status *
* *
* 9/4/98 - Modified by Landon Bradshaw *
* Added the check to see if PHP is being called by the server to *
* process an index.phtml. Finds out if rqpath->value ends with *
* '/' and then appends "index.pthml" to the calling string. *
* 9/23/98 - Modified by Landon Bradshaw *
* Took out the query test that added the QUERY_STRING to the end *
* the file argument. Fixes GET to the script. *
\****************************************************************************/
#include "nsapi.h"
#include "base/util.h"
#include "frame/protocol.h"
#include "base/shexp.h"
//#include "base/pblock.h"
//#include "frame/http.h"
//#include "frame/log.h"
#include <string.h>
#define NSAPI_PUBLIC
#ifdef __cplusplus
extern "C"
#endif
NSAPI_PUBLIC int redirect_cgi(pblock *pb, Session *sn, Request *rq) {
int l=0, lr=0, lq=0, lc=0;
char *rpath, *pi;
pb_param *path = pblock_find("path", rq->vars);
pb_param *rqpath = pblock_find("uri", rq->reqpb);
pb_param *query = pblock_find("query", rq->reqpb);
pb_param *ctype = pblock_find("content-type", rq->srvhdrs);
char *cgi_path = pblock_findval("cgi_path", pb);
char *type = pblock_findval("type", pb);
if(!cgi_path || !type) {
log_error(LOG_MISCONFIG, "redirect-cgi", sn, rq,
"missing parameters (need cgi_path and type)");
return REQ_ABORTED;
}
l = strlen(path->value);
lr = strlen(rqpath->value);
if(query) lq = strlen(query->value);
lc = strlen(cgi_path);
if(l && !strcmp(ctype->value,type)) {
rpath = (char *)MALLOC(lc + 1);
pi = (char *)MALLOC(lr + lq + 12);
strcpy(rpath,cgi_path);
sprintf(pi,"%s",rqpath->value);
if (*(pi+lr-1)=='/') strcat(pi,"index.html");
FREE(path->value);
path->value = rpath;
FREE(ctype->value);
ctype->value = STRDUP("magnus-internal/cgi");
pblock_nvinsert("path-info", pi, rq->vars);
pblock_nvinsert("redirect-status","200", rq->headers);
pblock_nvinsert("redirect-status","200", rq->vars);
}
return REQ_PROCEED;
}
</snip>