1        ____           _
2    ___|  _ \ ___ _ __| |
3   / _ \ |_) / _ \ '__| |
4  |  __/  __/  __/ |  | |
5   \___|_|   \___|_|  |_|
6
7  ePerl -- Embedded Perl 5 Language
8
9  I N S T A L L A T I O N
10  as a Server-Side-Scripting-Language
11  for a Netscape Server via the NSAPI
12  ===================================
13
14  OVERVIEW
15  --------
16
17  This is the documentation and source of a standard NSAPI module written by
18  Rasmus Lerdorf <rasmus@lerdorf.on.ca> which allows you to redirect any
19  request to a given CGI program based on the extension of the requested file.
20  Please note that neither the author of ePerl nor Rasmus Lerdorf use Netscape
21  servers, so they won't be able to answer specific installation questions for
22  you.  You are pretty much on your own here. If you want support from authors
23  writing free software, then you have to use a free webserver as well ;-)
24
25  INSTALLATION
26  ------------
27
28  Your first step is save the two files appended at the end of this document
29  as ``Makefile'' and ``redirect_cgi.c'' to any location. Then compile the
30  module.  The Makefile is configured for Solaris.  You will need to modify it
31  to reflect your local compiler conventions for creating shared libraries.
32  Read the Makefile.  There are some hints for other operating systems.
33
34  Once you have a redirect_cgi.so shared library, you need to edit three
35  different server configuration files.  These are in your ns-home config
36  directory.
37
38  1. In mime.types, add the following line to the end of the file
39     to create a new mime type to be used internally by the server.
40
41         type=magnus-internal/eperl exts=phtml
42
43  2. In magnus.conf add the following line to the end of the file
44     to make the link between the Netscape server core and the new module
45     (only one line, backslashes are are written down for readability only):
46
47         Init fn=load-modules \
48              shlib=/www/nsapi/redirect_cgi.so \
49              funcs=redirect-cgi
50
51     Replace the /www/nsapi with the path to your redirect_cgi.so file.
52     It can be anywhere on your system.
53
54  3. In obj.conf insert the following line (only one line,
55     backslashes are are written down for readability only):
56
57         ObjectType fn="redirect-cgi" \
58                    cgi_path="/www/cgi-bin/eperl.cgi" \
59                    type="magnus-internal/eperl"
60
61     Here, replace /www/cgi-bin/eperl.cgi with the path to your ePerl program.
62     The line should be inserted after the "type-by-extension" line, but
63     before the "force-type" line.
64
65  HINTS
66  -----
67
68  Note that if you are running multiple servers, you will need to configure
69  each one individually according to the above instructions.
70
71  The most recent version of this module can be found in the file archive at
72  http://www.vex.net/php/.
73
74  FILES
75  -----
76
77--Makefile--------------------------------------
78#
79# Edit the following to reflect the location of your nsapi include directory.
80#
81INCLUDEDIR=/opt/www/etc/ns-home/nsapi/include
82
83#
84# Now, pick your operating system
85#
86
87
88# For Solaris (using Sun's compiler)
89CC_CMD=cc -DSOLARIS
90SHARED=-G
91
92#
93# I haven't tested on any platform except Solaris.  If you find
94# that some of these work, or if you make it work on any platform
95# except Solaris, please e-mail me at: rasmus@vex.net
96# so I can update this file.
97#
98# For Irix
99#CC_CMD=cc -DIRIX
100#SHARED=-shared
101
102# For SunOS (using gcc)
103#CC_CMD=gcc -DSUNOS4 -fpic
104#LD_SHAREDCMD=ld -assert pure-text
105
106# For OSF/1
107#CC_CMD=cc -DOSF
108#SHARED=-all -shared -expect_unresolved "*"
109
110# For HP-UX
111#CC_CMD=cc -DHPUX
112#SHARED=-b
113
114# For AIX (good luck)
115#CC_CMD=cc -DAIX
116#SHARED=-bM:SRE -bE:module.exp -bI:module.imp -e _nostart
117##module.exp is a file you create which lists each function in your module
118##module.imp is a function you create which lists each function which
119##           should be exported from the server into the module.
120
121INCLUDE_FLAGS=-I$(INCLUDEDIR)
122COMMON_DEFS=-DMCC_HTTPD -DXP_UNIX
123
124
125#
126# For Solaris, use single-step compile and link with the following
127all: redirect_cgi.so
128
129redirect_cgi.so: redirect_cgi.c
130	$(CC_CMD) $(COMMON_DEFS) $(INCLUDE_FLAGS) $(SHARED) -o redirect_cgi.so redirect_cgi.c
131
132#
133# For SUNOS, use two-step compile and link.  uncomment the following:
134#
135#OBJS=redirect_cgi.o
136#
137#all: redirect_cgi.so
138#
139#redirect_cgi.so: $(OBJS)
140#	$(LD_SHAREDCMD) $(OBJS) -o redirect_cgi.so
141#
142#.c.o:
143#	$(CC_CMD) $(COMMON_DEFS) $(INCLUDE_FLAGS) -c $<
144
145clean:
146	rm redirect_cgi.so
147--Makefile--------------------------------------
148
149--redirect_cgi.c--------------------------------
150/***[redirect_cgi.c]**********************************************[TAB=4]****\
151*                                                                            *
152* NSAPI CGI Redirection Module                                               *
153*                                                                            *
154* Copyright 1995,1996,1997 Rasmus Lerdorf <rasmus@lerdorf.on.ca>             *
155*                                                                            *
156*  This program is free software; you can redistribute it and/or modify      *
157*  it under the terms of the GNU General Public License as published by      *
158*  the Free Software Foundation; either version 2 of the License, or         *
159*  (at your option) any later version.                                       *
160*                                                                            *
161*  This program is distributed in the hope that it will be useful,           *
162*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
163*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
164*  GNU General Public License for more details.                              *
165*                                                                            *
166*  You should have received a copy of the GNU General Public License         *
167*  along with this program; if not, write to the Free Software               *
168*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
169*                                                                            *
170\****************************************************************************/
171#include "base/pblock.h"
172#include "frame/http.h"
173#include "frame/log.h"
174#include <string.h>
175
176int redirect_cgi(pblock *pb, Session *sn, Request *rq) {
177	int l=0, lr=0, lq=0, lc=0;
178	char *rpath, *pi;
179	pb_param *path = pblock_find("path", rq->vars);
180	pb_param *rqpath = pblock_find("uri", rq->reqpb);
181	pb_param *query = pblock_find("query", rq->reqpb);
182	pb_param *ctype = pblock_find("content-type", rq->srvhdrs);
183	char *cgi_path = pblock_findval("cgi_path", pb);
184	char *type = pblock_findval("type", pb);
185
186    if(!cgi_path || !type) {
187        log_error(LOG_MISCONFIG, "redirect-cgi", sn, rq,
188			"missing parameters (need cgi_path and type)");
189		return REQ_ABORTED;
190	}
191	l = strlen(path->value);
192	lr = strlen(rqpath->value);
193	if(query) lq = strlen(query->value);
194	lc = strlen(cgi_path);
195	if(l && !strcmp(ctype->value,type)) {
196		rpath = (char *)MALLOC(lc + 1);
197		pi = (char *)MALLOC(lr + lq + 2);
198		strcpy(rpath,cgi_path);
199		if(query) sprintf(pi,"%s?%s",rqpath->value,query->value);
200		else strcpy(pi,rqpath->value);
201		FREE(path->value);
202		path->value = rpath;
203		FREE(ctype->value);
204		ctype->value = STRDUP("magnus-internal/cgi");
205		pblock_nvinsert("path-info", pi, rq->vars);
206	}
207	return REQ_PROCEED;
208}
209--redirect_cgi.c--------------------------------
210
211