libmatthew-java-0.7.3/ 0000755 0001750 0001750 00000000000 11426572746 013266 5 ustar mjj29 mjj29 libmatthew-java-0.7.3/Makefile 0000644 0001750 0001750 00000011671 11426572742 014730 0 ustar mjj29 mjj29 JAVAC?=javac JAVADOC?=javadoc JAR?=jar JAVAH?=javah GCJ?=gcj CC?=gcc LD?=gcc JPPFLAGS+=-C -P CFLAGS+=-Wall -Os -pedantic -Werror CSTD?=-std=c99 CSHAREFLAG+=-fpic -fno-stack-protector GCJJNIFLAG=-fjni JVERCFLAGS+=-source 1.5 JCFLAGS+= INCLUDES+=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux JAVADOCFLAGS?=-quiet -author -link http://java.sun.com/j2se/1.4.2/docs/api/ LDVER?=$(shell ld -v | cut -d' ' -f1) UNAME?=$(shell uname -s) ifeq ($(LDVER),GNU) LDSHAREFLAGS+=-fpic -shared else LDSHAREFLAGS+=-lc endif PREFIX?=/usr/local JARDIR?=$(PREFIX)/share/java DOCDIR?=$(PREFIX)/share/doc/libmatthew-java/ LIBDIR?=$(PREFIX)/lib/jni MATTVER=0.7.3 DEBUGVER=1.1 UNIXVER=0.5 CGIVER=0.5 IOVER=0.1 HEXVER=0.2 SRC=$(shell find cx -name '*.java' -and -not -name 'Debug.java') DEBUG?=disable .NOPARALLEL: .NO_PARALLEL: .NOTPARALLEL: all: unix-$(UNIXVER).jar cgi-$(CGIVER).jar debug-enable-$(DEBUGVER).jar debug-disable-$(DEBUGVER).jar io-$(IOVER).jar hexdump-$(HEXVER).jar libcgi-java.so libunix-java.so classes: .classes .classes: $(SRC) mkdir -p classes $(MAKE) .$(DEBUG)debug $(JAVAC) $(JVERCFLAGS) $(JCFLAGS) -d classes -cp classes $^ touch .classes clean: rm -rf classes doc rm -f .classes .enabledebug .disabledebug *.o *.h *.so *.tar.gz *.jar *.cgi Manifest rm -rf libmatthew-java-$(MATTVER) cgi-$(CGIVER).jar: .classes (cd classes; $(JAR) cf ../$@ cx/ath/matthew/cgi/*class) io-$(IOVER).jar: .classes (cd classes; $(JAR) cf ../$@ cx/ath/matthew/io/*class) unix-$(UNIXVER).jar: .classes ifeq ($(DEBUG),enable) echo "Class-Path: $(JARDIR)/debug-$(DEBUG).jar" > Manifest else echo "Class-Path: " > Manifest endif (cd classes; $(JAR) cfm ../$@ ../Manifest cx/ath/matthew/unix/*class) hexdump-$(HEXVER).jar: .classes (cd classes; $(JAR) cf ../$@ cx/ath/matthew/utils/Hexdump.class) %.o: %.c %.h $(CC) $(CFLAGS) $(CSTD) $(CSHAREFLAG) $(INCLUDES) -c -o $@ $< lib%.so: %.o $(CC) $(LDFLAGS) $(LDSHAREFLAGS) -o $@ $< unix-java.h: .classes $(JAVAH) -classpath classes -o $@ cx.ath.matthew.unix.UnixServerSocket cx.ath.matthew.unix.UnixSocket cx.ath.matthew.unix.USInputStream cx.ath.matthew.unix.USOutputStream cgi-java.h: .classes $(JAVAH) -classpath classes -o $@ cx.ath.matthew.cgi.CGI test.cgi: cgi-$(CGIVER).jar libcgi-java.so $(GCJ) $(GCJFLAGS) $(GCJJNIFLAG) -L. -lcgi-java -o test.cgi --main=cx.ath.matthew.cgi.testcgi cgi-$(CGIVER).jar libmatthew-java-$(MATTVER).tar.gz: Makefile cx cgi-java.c unix-java.c README INSTALL COPYING changelog mkdir -p libmatthew-java-$(MATTVER) cp -a $^ libmatthew-java-$(MATTVER) tar zcf $@ libmatthew-java-$(MATTVER) debug-enable-$(DEBUGVER).jar: cx/ath/matthew/debug/Debug.jpp make .enabledebug echo "Class-Path: $(JARDIR)/hexdump.jar" > Manifest (cd classes;jar cfm ../$@ ../Manifest cx/ath/matthew/debug/*.class) debug-disable-$(DEBUGVER).jar: cx/ath/matthew/debug/Debug.jpp make .disabledebug echo "Class-Path: $(JARDIR)/hexdump.jar" > Manifest (cd classes;jar cfm ../$@ ../Manifest cx/ath/matthew/debug/*.class) .enabledebug: cx/ath/matthew/debug/Debug.jpp mkdir -p classes cpp $(PPFLAGS) $(JPPFLAGS) -DDEBUGSETTING=true < cx/ath/matthew/debug/Debug.jpp > cx/ath/matthew/debug/Debug.java $(JAVAC) $(JVERCFLAGS) $(JCFLAGS) -cp classes -d classes cx/ath/matthew/debug/Debug.java cx/ath/matthew/utils/Hexdump.java rm -f .disabledebug touch .enabledebug .disabledebug: cx/ath/matthew/debug/Debug.jpp mkdir -p classes cpp $(PPFLAGS) $(JPPFLAGS) -DDEBUGSETTING=false < cx/ath/matthew/debug/Debug.jpp > cx/ath/matthew/debug/Debug.java $(JAVAC) $(JVERCFLAGS) $(JCFLAGS) -cp classes -d classes cx/ath/matthew/debug/Debug.java cx/ath/matthew/utils/Hexdump.java rm -f .enabledebug touch .disabledebug cx/ath/matthew/debug/Debug.java: .disabledebug doc/index.html: $(JAVADOC) $(JAVADOCFLAGS) -d doc/ cx/ath/matthew/debug/Debug.java $(SRC) doc: doc/index.html install-doc: doc/index.html install -d $(DESTDIR)$(DOCDIR) cp -a doc $(DESTDIR)$(DOCDIR)/api install-native: libcgi-java.so libunix-java.so install -d $(DESTDIR)$(LIBDIR) install libcgi-java.so $(DESTDIR)$(LIBDIR) install libunix-java.so $(DESTDIR)$(LIBDIR) install-jar: unix-$(UNIXVER).jar cgi-$(CGIVER).jar debug-enable-$(DEBUGVER).jar debug-disable-$(DEBUGVER).jar io-$(IOVER).jar hexdump-$(HEXVER).jar install -d $(DESTDIR)$(JARDIR) install -m 644 debug-enable-$(DEBUGVER).jar $(DESTDIR)$(JARDIR) install -m 644 debug-disable-$(DEBUGVER).jar $(DESTDIR)$(JARDIR) install -m 644 unix-$(UNIXVER).jar $(DESTDIR)$(JARDIR) install -m 644 cgi-$(CGIVER).jar $(DESTDIR)$(JARDIR) install -m 644 io-$(IOVER).jar $(DESTDIR)$(JARDIR) install -m 644 hexdump-$(HEXVER).jar $(DESTDIR)$(JARDIR) ln -sf debug-disable-$(DEBUGVER).jar $(DESTDIR)$(JARDIR)/debug-disable.jar ln -sf debug-enable-$(DEBUGVER).jar $(DESTDIR)$(JARDIR)/debug-enable.jar ln -sf unix-$(UNIXVER).jar $(DESTDIR)$(JARDIR)/unix.jar ln -sf io-$(IOVER).jar $(DESTDIR)$(JARDIR)/io.jar ln -sf cgi-$(CGIVER).jar $(DESTDIR)$(JARDIR)/cgi.jar ln -sf hexdump-$(HEXVER).jar $(DESTDIR)$(JARDIR)/hexdump.jar install: install-native install-jar libmatthew-java-0.7.3/cx/ 0000755 0001750 0001750 00000000000 10542112620 013653 5 ustar mjj29 mjj29 libmatthew-java-0.7.3/cx/ath/ 0000755 0001750 0001750 00000000000 10542112620 014427 5 ustar mjj29 mjj29 libmatthew-java-0.7.3/cx/ath/matthew/ 0000755 0001750 0001750 00000000000 10542112620 016100 5 ustar mjj29 mjj29 libmatthew-java-0.7.3/cx/ath/matthew/cgi/ 0000755 0001750 0001750 00000000000 10652135003 016644 5 ustar mjj29 mjj29 libmatthew-java-0.7.3/cx/ath/matthew/cgi/CGI.java 0000644 0001750 0001750 00000044166 10652135002 020123 0 ustar mjj29 mjj29 /* * Java CGI Library * * Copyright (c) Matthew Johnson 2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, version 2 only. * 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 Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * To Contact the author, please email src@matthew.ath.cx * */ package cx.ath.matthew.cgi; import java.io.IOException; import java.io.OutputStream; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; import java.util.Set; import java.util.Vector; import java.text.DateFormat; import java.text.SimpleDateFormat; /** * This is the main class you have to extend with your CGI program. * You should implement the cgi() method. * * @author Matthew Johnson <src@matthew.ath.cx> */ abstract public class CGI { private CGIErrorHandler errorhandler = new DefaultErrorHandler(); private boolean headers_sent = false; private HashMap headers = new HashMap(); private Vector cookies = new Vector(); private LinkedList pagedata = new LinkedList(); private LinkedList rawdata = new LinkedList(); private native String getenv(String var); /** MUST pass String.class and ALWAYS returns a String[] */ private native Object[] getfullenv(Class c); private native void setenv(String var, String value); { System.loadLibrary("cgi-java"); } /** * Called by CGIs to send a header to the output * * @param variable The header variable to set. * @param value The value of the variable. * * @throws CGIHeaderSentException if the headers have already been sent. * * @see #flush */ public final void header(String variable, String value) throws CGIHeaderSentException { // only send headers once if (headers_sent) throw new CGIHeaderSentException(); // buffer the variable (Map so that each header is only set once) headers.put(variable, value); } /** * Sets a Cookie in the web browser, with extended attributes. * Calls header() so must be called before sending any output. * * A parameter will not be sent if it is null. * * @param variable The cookie variable to set. * @param value The value of the variable. * @param path The path that the cookie will be returned for. * @param domain The domain that the cookie will be returned for. * @param expires The expiry date of the cookie. * @param secure Will only send the cookie over HTTPS if this is true. * * @throws CGIHeaderSentException if the headers have already been sent. * * @see #flush * @see #header */ public final void setcookie(String variable, String value, String path, String domain, Date expires, boolean secure) throws CGIHeaderSentException { if (headers_sent) throw new CGIHeaderSentException(); //Set-Cookie: NAME=VALUE; expires=DATE; //path=PATH; domain=DOMAIN_NAME; secure //Wdy, DD-Mon-YYYY HH:MM:SS GMT DateFormat df = new SimpleDateFormat("E, dd-MMM-yyyy HH:mm:ss zzz"); String cookie = variable+"="+value; if (null != path) cookie += "; path="+path; if (null != domain) cookie += "; domain="+domain; if (null != expires) cookie += "; expires="+df.format(expires); if (secure) cookie += "; secure"; cookies.add("Set-Cookie: "+ cookie); } /** * Sets a Cookie in the web browser. * Calls header() so must be called before sending any output. * * @param variable The cookie variable to set. * @param value The value of the variable. * * @throws CGIHeaderSentException if the headers have already been sent. * * @see #flush * @see #header */ public final void setcookie(String variable, String value) throws CGIHeaderSentException { if (headers_sent) throw new CGIHeaderSentException(); //Set-Cookie: NAME=VALUE; expires=DATE; //path=PATH; domain=DOMAIN_NAME; secure cookies.add("Set-Cookie: "+ variable+"="+value); } /** * Called by CGIs to send byte data to the output. * The data is buffered until the CGI exits, or a call of flush. * * @param data The page data. * @throws CGIInvalidContentFormatException if text data has already been sent. * * @see #flush */ public final void out(byte[] data) throws CGIInvalidContentFormatException { if (pagedata.size() > 0) throw new CGIInvalidContentFormatException(); rawdata.add(data); } /** * Called by CGIs to send a string to the output. * The data is buffered until the CGI exits, or a call of flush. * * @param data The page data. * @throws CGIInvalidContentFormatException if raw data has already been sent. * * @see #flush */ public final void out(String data) throws CGIInvalidContentFormatException { if (rawdata.size() > 0) throw new CGIInvalidContentFormatException(); pagedata.add(data); } /** * This will return an OutputStream that you can write data * directly to. Calling this method will cause the output to be * flushed and the Headers sent. At the moment this is not buffered * and will be sent directly to the client. Subsequent calls * to out() will appear after data written to the output stream. * * @see #out * @return an OutputStream */ public final OutputStream getOutputStream() throws IOException { flush(); return System.out; } /** * Flushes the output. * Note that you cannot send a header after a flush. * If you want to send both text and binary data in a page * you may do so either side of a flush. * * @see #header */ public final void flush() throws IOException { if (!headers_sent) { // don't send headers again headers_sent = true; // send headers Iterator i = headers.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); String value = (String) headers.get(key); System.out.println(key + ": " + value); } // send cookies i = cookies.iterator(); while (i.hasNext()) { System.out.println((String) i.next()); } System.out.println(); } // send data if (pagedata.size() >0) { Iterator j = pagedata.iterator(); while (j.hasNext()) { System.out.println((String) j.next()); } pagedata.clear(); } else if (rawdata.size() > 0) { Iterator j = rawdata.iterator(); while (j.hasNext()) { System.out.write((byte[]) j.next()); } pagedata.clear(); } System.out.flush(); } /** * Sets a custom exception handler. * Gets called when an exception is thrown. * The default error handler prints the error nicely in HTML * and then exits gracefully. * * @param handler The new exception handler */ protected final void setErrorHandler(CGIErrorHandler handler) { errorhandler = handler; } /** * Override this method in your CGI program. * * @param POST A Map of variable =$gt; value for the POST variables. * @param GET A Map of variable =$gt; value for the GET variables. * @param ENV A Map of variable =$gt; value for the Webserver environment variables. * @param COOKIES A Map of variable =$gt; value for the browser-sent cookies. * @param params An array of parameters passed to the CGI (GET with no variable assignments) * * @throws Exception You can throw anything, it will be caught by the error handler. */ abstract protected void cgi(Map POST, Map GET, Map ENV, Map COOKIES, String[] params) throws Exception; /** * Reads variables from a String like a=b&c=d to a Map {a => b, c => d}. * * @param s String to read from. * @param seperator seperator character between variables (eg &) * @param values whether or not this string has values for variables * * @return a Map with values, a Vector without */ private Object readVariables(String s, char seperator, boolean values) { HashMap vars = new HashMap(); Vector varv = new Vector(); String temp = ""; String variable = null; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == seperator) { // new variable if (null != temp) temp = temp.trim(); if (values) { if (variable == null) {variable = temp; temp = "";} else variable.trim(); if (!variable.equals("")) { Object o = vars.get(variable); if (o == null) vars.put(variable.trim(), temp); else if (o instanceof String) { LinkedList l = new LinkedList(); l.add(o); l.add(temp); vars.put(variable.trim(), l); } else if (o instanceof LinkedList) ((LinkedList) o).add(temp); } temp = ""; } else { varv.add(temp); temp = ""; } variable = null; continue; } if (values && c == '=') { variable = temp; temp = ""; continue; } switch (c) { case '%': // escaped character try { char a = s.charAt(++i); char b = s.charAt(++i); int ch = 0; switch (a) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': ch += 0x10 * (a - '0'); break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': ch += 0x10 * (a - 'a' + 0xa); break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': ch += 0x10 * (a - 'A' + 0xA); break; } switch (b) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': ch += (b - '0'); break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': ch += (b - 'a' + 0xa); break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': ch += (b - 'A' + 0xA); break; } temp += (char) ch; } catch (StringIndexOutOfBoundsException SIOOBe) { // this means someone has included an invalid escape sequence. // Invalid URIs can just be thrown on the floor. } break; // + is a space case '+': temp += ' '; break; default: temp += c; } } if (values) { if (variable == null) {variable = temp; temp = "";} else variable.trim(); //out("DEBUG variable read: "+variable+"/"+temp); if (!variable.equals("")) { Object o = vars.get(variable); if (o == null) vars.put(variable.trim(), temp); else if (o instanceof String) { LinkedList l = new LinkedList(); l.add(o); l.add(temp); vars.put(variable.trim(), l); } else if (o instanceof LinkedList) ((LinkedList) o).add(temp); } return vars; } else { varv.add(temp); return varv; } } /** * Sets up the POST variables */ private Map getPOST() { try { String s = ""; while(System.in.available() > 0) s += (char) System.in.read(); //out("DEBUG: POST STRING: "+s); return (Map) readVariables(s, '&', true); } catch (IOException IOe) { try { out("ERROR: IOException: "+IOe); } catch (CGIInvalidContentFormatException CGIICFe) { System.err.println("ERROR: IOException: "+IOe); } return new HashMap(); } } /** * Sets up the COOKIEs */ private Map getCOOKIE() { String s = getenv("HTTP_COOKIE"); if (null == s) return new HashMap(); else return (Map) readVariables(s, ';', true); } /** * Sets up the GET variables */ private Map getGET() { String s = getenv("QUERY_STRING"); if (null == s) return new HashMap(); else return (Map) readVariables(s, '&', true); } /** * Sets up the ENV variables */ private Map getENV() { Map m = new HashMap(); String[] env = (String[]) getfullenv(String.class); for (int i = 0; i < env.length; i++){ if (null == env[i]) continue; String[] e = env[i].split("="); if (1 == e.length) m.put(e[0], ""); else m.put(e[0], e[1]); } /* m.put("SERVER_SOFTWARE", getenv("SERVER_SOFTWARE")); m.put("SERVER_NAME", getenv("SERVER_NAME")); m.put("GATEWAY_INTERFACE", getenv("GATEWAY_INTERFACE")); m.put("SERVER_PROTOCOL", getenv("SERVER_PROTOCOL")); m.put("SERVER_PORT", getenv("SERVER_PORT")); m.put("REQUEST_METHOD", getenv("REQUEST_METHOD")); m.put("PATH_INFO", getenv("PATH_INFO")); m.put("PATH_TRANSLATED", getenv("PATH_TRANSLATED")); m.put("SCRIPT_NAME", getenv("SCRIPT_NAME")); m.put("QUERY_STRING", getenv("QUERY_STRING")); m.put("REMOTE_HOST", getenv("REMOTE_HOST")); m.put("REMOTE_ADDR", getenv("REMOTE_ADDR")); m.put("AUTH_TYPE", getenv("AUTH_TYPE")); m.put("REMOTE_USER", getenv("REMOTE_USER")); m.put("REMOTE_IDENT", getenv("REMOTE_IDENT")); m.put("CONTENT_TYPE", getenv("CONTENT_TYPE")); m.put("CONTENT_LENGTH", getenv("CONTENT_LENGTH")); m.put("HTTP_ACCEPT", getenv("HTTP_ACCEPT")); m.put("HTTP_USER_AGENT", getenv("HTTP_USER_AGENT")); m.put("HTTP_COOKIE", getenv("HTTP_COOKIE")); m.put("HTTP_ACCEPT_CHARSET", getenv("HTTP_ACCEPT_CHARSET")); m.put("HTTP_ACCEPT_ENCODING", getenv("HTTP_ACCEPT_ENCODING")); m.put("HTTP_CACHE_CONTROL", getenv("HTTP_CACHE_CONTROL")); m.put("HTTP_REFERER", getenv("HTTP_REFERER")); m.put("HTTP_X_FORWARDED_FOR", getenv("HTTP_X_FORWARDED_FOR")); m.put("HTTP_HOST", getenv("HTTP_HOST")); m.put("REQUEST_URI", getenv("REQUEST_URI")); m.put("DOCUMENT_ROOT", getenv("DOCUMENT_ROOT")); m.put("PATH", getenv("PATH")); m.put("SERVER_ADDR", getenv("SERVER_ADDR")); m.put("SCRIPT_FILENAME", getenv("SCRIPT_FILENAME")); m.put("HTTP_COOKIE2", getenv("HTTP_COOKIE2")); m.put("HTTP_CONNECTION", getenv("HTTP_CONNECTION")); m.put("LANG", getenv("LANG")); m.put("REDIRECT_LANG", getenv("REDIRECT_LANG")); */ return m; } /** * Sets up the param variables */ private String[] getParams(String args) { Vector v = (Vector) readVariables(args, ',', false); String[] params = new String[v.size()]; Iterator i = v.iterator(); for (int j = 0; j < params.length; j++) params[j] = (String) i.next(); return params; } /** * This method sets up all the CGI variables and calls the cgi() method, then writes out the page data. */ public final void doCGI(String[] args) { CGI cgiclass = null; // wrap everything in a try, we need to handle all our own errors. try { // setup the CGI variables Map POST = getPOST(); Map GET = getGET(); Map ENV = getENV(); Map COOKIE = getCOOKIE(); String[] params = new String[] {}; if (args.length >= 1) params = getParams(args[0]); // instantiate CGI class /* Class c = Class.forName(args[0]); cgiclass = (CGI) c.newInstance(); */ // set default headers /*cgiclass.*/headers.put("Content-type", "text/html"); // execute the CGI /*cgiclass.*/cgi(POST, GET, ENV, COOKIE, params); // send the output / remaining output /*cgiclass.*/flush(); } // yes, we really want to do this. CGI programs can't send errors. Print nicely to the screen. catch (Exception e) { errorhandler.print(/*null == cgiclass ? false : cgiclass.*/headers_sent, e); } catch (Throwable t) { t.printStackTrace(); // this is bad enough to produce stderr errors errorhandler.print(/*null == cgiclass ? false : cgiclass.*/headers_sent, new Exception(t.toString())); } } } libmatthew-java-0.7.3/cx/ath/matthew/cgi/CGIErrorHandler.java 0000644 0001750 0001750 00000002221 10652135002 022415 0 ustar mjj29 mjj29 /* * Java CGI Library * * Copyright (c) Matthew Johnson 2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, version 2 only. * 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 Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * To Contact the author, please email src@matthew.ath.cx * */ package cx.ath.matthew.cgi; /** * Interface to handle exceptions in the CGI. */ public interface CGIErrorHandler { /** * This is called if an exception is not caught in the CGI. * It should handle printing the error message nicely to the user, * and then exit gracefully. */ public void print(boolean headers_sent, Exception e); } libmatthew-java-0.7.3/cx/ath/matthew/cgi/CGIHeaderSentException.java 0000644 0001750 0001750 00000002057 10652135002 023736 0 ustar mjj29 mjj29 /* * Java CGI Library * * Copyright (c) Matthew Johnson 2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, version 2 only. * 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 Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * To Contact the author, please email src@matthew.ath.cx * */ package cx.ath.matthew.cgi; /** * Thrown if the headers have already been sent and CGI.header is called. */ public class CGIHeaderSentException extends Exception { public CGIHeaderSentException() { super("Headers already sent by CGI"); } } libmatthew-java-0.7.3/cx/ath/matthew/cgi/CGIInvalidContentFormatException.java 0000644 0001750 0001750 00000002076 10652135002 026007 0 ustar mjj29 mjj29 /* * Java CGI Library * * Copyright (c) Matthew Johnson 2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, version 2 only. * 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 Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * To Contact the author, please email src@matthew.ath.cx * */ package cx.ath.matthew.cgi; /** * Thrown if both raw and text data are set in the same page. */ public class CGIInvalidContentFormatException extends Exception { public CGIInvalidContentFormatException() { super("Cannot send both raw and text data"); } } libmatthew-java-0.7.3/cx/ath/matthew/cgi/CGITools.java 0000644 0001750 0001750 00000002540 10652135002 021132 0 ustar mjj29 mjj29 /* * CUAG AutoUmpire System * * Copyright (C) 2003/2004 Matthew Johnson, Adam Biltcliffe, * Michael Cripps, Martin O'Leary, Edward Allcutt and James Osborn * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, version 2 only. * 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 Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * To Contact the authors, please email assassins@srcf.ucam.org * */ package cx.ath.matthew.cgi; abstract class CGITools { /** * Escape a character in a string. * @param in String to escape in. * @param c Character to escape. * @return in with c replaced with \c */ public static String escapeChar(String in, char c) { String out = ""; for (int i = 0; i < in.length(); i++) { if (in.charAt(i) == c) out += '\\'; out += in.charAt(i); } return out; } } libmatthew-java-0.7.3/cx/ath/matthew/cgi/CheckBox.java 0000644 0001750 0001750 00000002247 10652135002 021201 0 ustar mjj29 mjj29 /* * Java CGI Library * * Copyright (c) Matthew Johnson 2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, version 2 only. * 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 Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * To Contact the author, please email src@matthew.ath.cx * */ package cx.ath.matthew.cgi; public class CheckBox extends Field { boolean checked; public CheckBox(String name, String label, boolean checked) { this.name = name; this.label = label; this.checked = checked; } protected String print() { return ""; } } libmatthew-java-0.7.3/cx/ath/matthew/cgi/DefaultErrorHandler.java 0000644 0001750 0001750 00000004153 10652135002 023405 0 ustar mjj29 mjj29 /* * Java CGI Library * * Copyright (c) Matthew Johnson 2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, version 2 only. * 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 Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * To Contact the author, please email src@matthew.ath.cx * */ package cx.ath.matthew.cgi; /** * Interface to handle exceptions in the CGI. */ public class DefaultErrorHandler implements CGIErrorHandler { /** * This is called if an exception is not caught in the CGI. * It should handle printing the error message nicely to the user, * and then exit gracefully. */ public void print(boolean headers_sent, Exception e) { if (!headers_sent) { System.out.println("Content-type: text/html"); System.out.println(""); System.out.println(""); System.out.println("
"); System.out.println(""); System.out.println("Exception Message: "+e.getMessage()); System.out.println("
"); System.out.println(""); System.out.println("Stack Trace:"); System.out.println("
"); System.out.println(""); e.printStackTrace(System.out); System.out.println(""); System.out.println("