Commit 1802f92d authored by 's avatar

initial

parent 6501f1f8
#!/usr/local/bin/pcgi-wrapper
# example pcgi info file - JeffBauer@bigfoot.com
# substitute 'BogusDirectory' with appropriate path
# To invoke from browser: http://.../cgi-bin/pcgitest/getTime
PCGI_PUBLISHER=/BogusDirectory/pcgi_publisher.py
PCGI_MODULE_PATH=/BogusDirectory/pcgitime.py
PCGI_SOCKET_FILE=/tmp/pcgitest.socket
PCGI_PID_FILE=/tmp/pcgitest.pid
# pcgitime.py - example pcgi script - JeffBauer@bigfoot.com
from time import asctime, localtime, time
beginTime = "<html><pre>time started: %s" % asctime(localtime(time()))
def getTime(arg=None):
"""It's later than you think (don't remove this docstring)"""
return "%s\ncurrent time: %s" % (beginTime, asctime(localtime(time())))
### Makefile.in - Persistent CGI configuration ###
### start of system configuration section ###
prefix= @prefix@
exec_prefix= @exec_prefix@
BINDIR= $(exec_prefix)/bin
srcdir= @srcdir@
VPATH = @srcdir@
VERSION= @VERSION@
MACHDEP= @MACHDEP@
CC = @CC@
DEFS= @DEFS@ -DUNIX -DOPT_NO_STDERR -DCLOSE_FDS
LIBS= @LIBS@
creosotedir = $(srcdir)/MrCreosote
testdir = $(srcdir)/Test
utildir = $(srcdir)/Util
### end of system configuration section ###
.c.o:
$(CC) -c $(CPPFLAGS) $(DEFS) -I. -I$(srcdir) $(CFLAGS) $<
PROGS = pcgi-wrapper $(creosotedir)/pcgi-creosote $(testdir)/parseinfo
SRCS = pcgi-wrapper.c parseinfo.c $(creosotedir)/creosote.c
OBJS1 = pcgi-wrapper.o parseinfo.o
OBJS2 = $(creosotedir)/pcgi-wrapper.o parseinfo.o $(creosotedir)/creosote.o
OBJS3 = $(srcdir)/pcgi-wrapper.o $(testdir)/parseinfo.o
HDRS = pcgi.h $(creosotedir)/creosote.h
# --with-XXX options for configure
WITH=
MANIFEST=$(srcdir)/manifest
# default path permission settings
DIRMODE= 775
EXEMODE= 755
FILEMODE= 644
# Portable install script (configure doesn't always guess right)
INSTALL= ./install-sh -c
INSTALL_PROGRAM=${INSTALL} -m $(EXEMODE)
INSTALL_DATA= ${INSTALL} -m $(FILEMODE)
##################################################
all: pcgi-wrapper $(testdir)/parseinfo
pcgi-wrapper.o: pcgi-wrapper.c pcgi.h
$(CC) -c -I. -I$(srcdir) $(CFLAGS) -DPCGI_WRAPPER_MAIN -DVERSION=\"$(VERSION)\" $(DEFS) $(srcdir)/pcgi-wrapper.c
parseinfo.o: parseinfo.c pcgi.h
$(CC) -c -I. -I$(srcdir) $(CFLAGS) $(DEFS) $(srcdir)/parseinfo.c
pcgi-wrapper: pcgi-wrapper.o parseinfo.o
$(CC) $(LIBS) $(LDFLAGS) -o pcgi-wrapper $(OBJS1)
### begin CREOSOTE stuff ###
$(creosotedir)/creosote.o: $(creosotedir)/creosote.c $(creosotedir)/creosote.h
$(CC) -c -o $(creosotedir)/creosote.o -I. -I$(srcdir) -I$(creosotedir) $(CFLAGS) -DCREOSOTE $(DEFS) $(creosotedir)/creosote.c
$(creosotedir)/pcgi-wrapper.o: $(srcdir)/pcgi-wrapper.c
$(CC) -c -o $(creosotedir)/pcgi-wrapper.o -I. -I$(srcdir) -I$(creosotedir) $(CFLAGS) -DPCGI_WRAPPER_MAIN -DCREOSOTE $(DEFS) $(srcdir)/pcgi-wrapper.c
creosote: $(creosotedir)/pcgi-creosote
$(creosotedir)/pcgi-creosote: $(creosotedir)/pcgi-wrapper.o parseinfo.o $(creosotedir)/creosote.o
$(CC) $(LIBS) $(LDFLAGS) -o $(creosotedir)/pcgi-creosote $(OBJS2)
### end CREOSOTE stuff ###
### begin TEST stuff ###
$(testdir)/parseinfo.o: $(srcdir)/parseinfo.c
$(CC) -c -o $(testdir)/parseinfo.o -I. -I$(srcdir) -I$(testdir) $(CFLAGS) -DMAIN_PARSEINFO $(DEFS) $(srcdir)/parseinfo.c
$(testdir)/pcgi-wrapper.o: $(srcdir)/pcgi-wrapper.c
$(CC) -c -o $(testdir)/pcgi-wrapper.o -I. -I$(srcdir) -I$(testdir) $(CFLAGS) $(DEFS) $(srcdir)/pcgi-wrapper.c
parseinfo: $(testdir)/parseinfo
$(testdir)/parseinfo: $(testdir)/parseinfo.o $(testdir)/pcgi-wrapper.o
$(CC) $(LIBS) $(LDFLAGS) -o $(testdir)/parseinfo $(testdir)/parseinfo.o $(testdir)/pcgi-wrapper.o
### end TEST stuff ###
install: bininstall
bininstall: altbininstall
cp pcgi-wrapper $(BINDIR)
chmod a+rx $(BINDIR)/pcgi-wrapper
-if test -f $(BINDIR)/pcgi-wrapper; \
then rm -f $(BINDIR)/pcgi-wrapper; \
else true; \
fi
(cd $(BINDIR); ln pcgi-wrapper$(VERSION) pcgi-wrapper)
altbininstall: pcgi-wrapper
@for i in $(BINDIR); \
do \
if test ! -d $$i; then \
echo "Creating directory $$i"; \
mkdir $$i; \
chmod $(DIRMODE) $$i; \
else true; \
fi; \
done
$(INSTALL_PROGRAM) pcgi-wrapper $(BINDIR)/pcgi-wrapper$(VERSION)
clean:
rm -f $(PROGS) *.o *.out core $(creosotedir)/*.o $(testdir)/*.o $(utildir)/*.o Win32/*.obj
distclean: clean
rm -f Makefile autoconf.h config.status config.cache config.log *~
tarball:
cd $(srcdir); mkdir pcgi-$(VERSION)
cpio -pd < $(MANIFEST) pcgi-$(VERSION)
tar -czf $(srcdir)/pcgi-$(VERSION).tgz pcgi-$(VERSION)
rm -rf pcgi-$(VERSION)
# Build the toplevel Makefile
#Makefile: Makefile.in config.status
# CONFIG_FILES=Makefile $(SHELL) config.status
# Run the configure script, calling it with --recheck if config.status exists
#config.status: $(srcdir)/configure
# if test -f config.status; \
# then $(SHELL) config.status --recheck; \
# $(SHELL) config.status; \
# else $(SHELL) $(srcdir)/configure $(WITH); \
# fi
# Rebuild the configure script from configure.in
autoconf:
(cd $(srcdir); autoconf)
(cd $(srcdir); autoheader)
README notes for Persistent CGI - version 2.0 alpha 4
What it is?
Persistent CGI is an architecture designed by Digital Creations
http://www.digicool.com to publish web objects as long-running
processes. The pcgi component is an integral part of DC's
Principia product, but is also provided to Bobo developers
under open software terms. Please review the copyright appearing
in the source code for full details.
How to build?
Unix:
./configure
make
make install <-- only copies the binary, not the .py modules
Win32:
cd Win32
nmake /f Makefile.nt
A Win32 binary (pcgi-wrapper.exe) is included with the source
distribution.
How to use?
See the HOWTO section in notes I have published:
http://starship.skyport.net/crew/jbauer/persistcgi/
How to get help?
Subscribe to the Bobo mailing list: bobo@digicool.com
Contact me: jeffbauer@bigfoot.com
Have fun.
-Jeff
/* config.h.in. Generated automatically from configure.in by autoheader. */
/* Define to empty if the keyword does not work. */
#undef const
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
#undef HAVE_SYS_WAIT_H
/* Define to `int' if <sys/types.h> doesn't define. */
#undef pid_t
/* Define as the return type of signal handlers (int or void). */
#undef RETSIGTYPE
/* Define if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define if you have the putenv function. */
#undef HAVE_PUTENV
/* Define if you have the socket function. */
#undef HAVE_SOCKET
/* Define if you have the strerror function. */
#undef HAVE_STRERROR
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
This diff is collapsed.
dnl Process this file with autoconf to produce a configure script.
AC_INIT(pcgi.h)
AC_PROG_CC
AC_PROG_CPP
# Set VERSION here so we only need to edit it in one place
AC_SUBST(VERSION)
VERSION=2.0a4
# Set name for machine-dependent library files
AC_SUBST(MACHDEP)
AC_MSG_CHECKING(MACHDEP)
if test -z "$MACHDEP"
then
ac_sys_system=`uname -s`
if test "$ac_sys_system" = "AIX" ; then
ac_sys_release=`uname -v`
else
ac_sys_release=`uname -r`
fi
ac_md_system=`echo $ac_sys_system | tr -d '[/ ]' | tr '[[A-Z]]' '[[a-z]]'`
ac_md_release=`echo $ac_sys_release | tr -d '[/ ]' | sed 's/\..*//'`
MACHDEP="$ac_md_system$ac_md_release"
case $MACHDEP in
'') MACHDEP="unknown";;
esac
fi
AC_MSG_RESULT($MACHDEP)
dnl Checks for programs.
dnl Checks for libraries.
case $ac_sys_system in
hp*|HP*)
case $CC in
cc|*/cc) CC="$CC -Aa -D_HPUX_SOURCE";;
esac;;
esac
if test "$ac_sys_system" != IRIX
then
AC_CHECK_LIB(nsl, inet_addr, [LIBS="-lnsl $LIBS"]) # SVR4
AC_CHECK_LIB(socket, socket, [LIBS="-lsocket $LIBS"], [], $LIBS) # SVR4 sockets
fi
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(unistd.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_PID_T
dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(putenv socket strerror)
AC_OUTPUT(Makefile)
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5; it is not part of GNU.
#
# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
#
# This script is compatible with the BSD install script, but was written
# from scratch.
#
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
instcmd="$mvprog"
chmodcmd=""
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
fi
# Make a temp file name in the proper directory.
dstdir=`dirname $dst`
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp
# and set any options; do chmod last to preserve setuid bits
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi
# Now rename the file to the real destination.
$doit $rmcmd $dst
$doit $mvcmd $dsttmp $dst
exit 0
Example/pcgitest
Example/pcgitime.py
Makefile.in
MrCreosote/README.MrCreosote
MrCreosote/creosote.c
MrCreosote/creosote.h
MrCreosote/creosote.py
README
Test/README.parseinfo
Util/README
Util/killpcgi.py
Util/pcgifile.py
Win32/Makefile.nt
Win32/README.NT
Win32/parseinfo.exe
Win32/pcgi-wrapper.exe
config.h.in
configure
configure.in
install-sh
manifest
parseinfo.c
pcgi_publisher.py
pcgi-wrapper.c
pcgi.h
This diff is collapsed.
This diff is collapsed.
/* pcgi.h - Persistent CGI header file for pcgi-wrapper.c, parseinfo.c
Copyright (c) 1998, Digital Creations, Fredericksburg, VA, USA. All
rights reserved. This software includes contributions from Jeff Bauer.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
o Redistributions of source code must retain the above copyright
notice, this list of conditions, and the disclaimer that follows.
o Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
o All advertising materials mentioning features or use of this
software must display the following acknowledgement:
This product includes software developed by Digital Creations
and its contributors.
o Neither the name of Digital Creations nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS *AS IS* AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PCGI_H
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef UNIX
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#ifdef WIN32
#include <windows.h>
#include <io.h>
#include <iostream.h>
#include <winsock.h>
#endif
#define MAXLINEBUFFER 12
#define PATHSEP_UNIX '/'
#define PATHSEP_WIN32 '\\'
#define DEFAULT_SOCK_PORT 7244
/*#define DEFAULT_SOCK_HOST "127.0.0.1"*/
#define MAXPATH 1024
#define PUBLISHER_NAME_1 "pcgi_publisher.py"
#define PUBLISHER_NAME_2 "pcgi_publisher.pyc"
#define PUBLISHER_NAME_3 "pcgi_publisher.pyo"
#define PUBLISHER_NAME_4 "pcgi_publisher"
#define HDRLEN 10
#define HDRFMT "%010ld"
#ifdef UNIX
#define PATHSEP PATHSEP_UNIX
typedef int pcgi_socket;
#endif
#ifdef WIN32
#define PATHSEP PATHSEP_WIN32
typedef SOCKET pcgi_socket;
#define sleep(x) Sleep(x * 1000)
#define read(x,y,z) _read(x,y,z)
#define write(x,y,z) _write(x,y,z)
#define MUTEX_NAME "pcgiMutex"
#define AUTODELAY 5
#define CONNRETRY 0
#define CONNDELAY 1
#endif
#ifndef CREOSOTE
/* no-op in case someone forgets to remove a spew() in their debug code */
#define spew(x)
#endif
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
#define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
#define STDERR_FILENO 2
#endif
#define MAXSZ 256
#define RKEY 99
#define E_500 "500 Server Error"
#define E_503 "503 Service Unavailable"
#define ERR101_FAILURE_DURING_START "(101) failure during start"
#define ERR102_FAILURE_DURING_CONNECT "(102) failure during connect"
#define ERR103_UNABLE_VERIFY_RUNNING "(103) unable to verify if process is running"
#define ERR104_ENVIRONMENT_SEND "(104) environment send"
#define ERR105_STDIN_SEND "(105) stdin send"
#define ERR106_STDOUT_READ_HEADER "(106) stdout read header"
#define ERR107_BAD_STDOUT_STRLEN "(107) bad stdout strlen"
#define ERR108_STDOUT_READ_BODY "(108) stdout read body"
#define ERR109_STDERR_READ_HEADER "(109 stderr read header"
#define ERR110_BAD_STDERR_STRLEN "(110) bad stderr strlen"
#define ERR111_STDERR_READ_BODY "(111) stderr read body"
#define ERR112_STDOUT_TO_SERVER "(112) error returning stdout to server"
#define ERR113_STDOUT_TO_SERVER "(113) error returning stderr to server"
#define ERR114_UNABLE_TO_OPEN_SOCKET "(114) unable to open socket"
#define ERR115_CONNECTION_REFUSED "(115) connection refused"
#define ERR116_UNABLE_TO_CONNECT "(116) unable to connect"
#define ERR117_LOCK_ERROR_EACCES "(117) lock error: EACCES"
#define ERR118_LOCK_ERROR_EEXIST "(118) lock error: EEXIST"
#define ERR119_LOCK_ERROR_EINVAL "(119) lock error: EINVAL"
#define ERR120_LOCK_ERROR_ENOENT "(120) lock error: ENOENT"
#define ERR121_LOCK_ERROR_ENOSPC "(121) lock error: ENOSPC"
#define ERR122_LOCK_ERROR_OTHER "(122) lock error"
#define ERR123_BAD_ENV_HEADER "(123) bad environment header"
#define ERR124_BAD_STDIN_HEADER "(124) bad stdin header"
/* #define onError(s,x) {estatus=s; emsg=x; goto error;} */
typedef struct resource_tag
{
char sw_info [MAXSZ]; /* path to pcgi info file */
char sw_name [MAXSZ]; /* module name */
char sw_home [MAXSZ]; /* home path */
char sw_exe [MAXSZ]; /* path to executable, e.g. /usr/local/bin/python */
char procpath [MAXSZ]; /* path to file containing pid */
char sockpath [MAXSZ]; /* binding path for UNIX, Win32 named pipes */
char pubpath [MAXSZ]; /* path to pcgi_publisher.py(c) */
int sockport; /* port number, if INET socket */
char sockhost [MAXSZ]; /* hostname, if INET socket */
char modpath [MAXSZ]; /* module path */
char errmsg [MAXSZ]; /* last error, brief message */
char errlog [MAXSZ]; /* fully qualified path to error log file */
char insertPath [MAXPATH]; /* insert path by publisher */
char pythonPath [MAXPATH]; /* PYTHONPATH, if provided */
short displayErrors; /* displayErrors = 0,1 */
long sz_env;
long sz_input;
long sz_output;
long sz_error;
char *p_env;
char *p_input;
char *p_output;
char *p_error;
int procid;
int conn;
int lock;
} pcgiResource;
static char errorHtml[]=
"Status: %s\n"
"Content-Type: text/html\n"
"Pragma: nocache\n"
"Expires: Thu, 01 Dec 1994 16:00:00 GMT\n\n"
"<HTML>\n"
"<HEAD>\n"
"<TITLE>Temporarily Unavailable</TITLE>\n"
"</HEAD>\n"
"<BODY BGCOLOR=\"#FFFFFF\">\n"
"<TABLE BORDER=\"0\" WIDTH=\"100%%\">\n"
"<TR>\n"
" <TD WIDTH=\"10%%\">\n"
" <CENTER>\n"
" <B><FONT SIZE=\"+6\" COLOR=\"#77003B\">!</FONT></B>\n"
" </CENTER>\n"
" </TD>\n"
" <TD WIDTH=\"90%%\"><BR>\n"
" <FONT SIZE=\"+2\">Temporarily Unavailable</FONT>\n"
" <P>\n"
" The resource you requested is temporarily unavailable - "
"please try again later.\n"
" </TD>\n"
"</TR>\n"
"</TABLE>\n"
"%s\n"
"<!--\n%s\n%s\n-->\n"
"</BODY></HTML>";
/* To ensure backward compatibility with pcgi info files, */
/* don't change the order of the first 4 enum elements. */
enum { resource_sockpath=0,
resource_procpath=1,
resource_workdir=2,
resource_modpath=3, /* remaining elements not order dependent */
resource_sockport,
resource_sockhost,
resource_exepath,
resource_exefile,
resource_pubpath,
resource_ENUM };
/* Declarations */
void cleanup(void);
void onError(char *, char *, pcgiResource *);
int pcgiAssignPublisherPath(char *, pcgiResource *);
int pcgiPutEnvironment(char *);
long pcgiRead(pcgi_socket, char *, long);
long pcgiWrite(pcgi_socket, const char *, long);
int pcgiVerifyProc(pcgiResource *);
pcgi_socket pcgiConnect(pcgiResource *);
int pcgiStartProc(pcgiResource *);
int pcgiParseInfo(pcgiResource *);
int pcgiPutNameValueInEnvironment(char *, char *);
void pcgiSIG(int);
void pcgiPrintEnvironment();
void pcgiPrintResourceInfo(pcgiResource *);
int pcgiTruthValue(char);
#ifdef WIN32
void amendPathSeparators(char *);
long pcgiReadSocket(pcgi_socket, char *, long);
long pcgiWriteSocket(pcgi_socket, const char *, long);
#endif
#define PCGI_H 1
#endif
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment