diff -urN jta20-20001106-2155/Makefile jta20-p3/Makefile --- jta20-20001106-2155/Makefile Thu Nov 9 22:49:38 2000 +++ jta20-p3/Makefile Thu Nov 9 23:49:04 2000 @@ -15,9 +15,14 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -JAVA = java -JAR = jar -JAVAC = javac +#JAVA = java +#JAR = jar +#JAVAC = javac +#JAVADOC = javadoc +JAVA = /q/opt/jdk1.2.2/bin/java +JAR = /q/opt/jdk1.2.2/bin/jar +JAVAC = /q/opt/jdk1.2.2/bin/javac +JAVADOC = /q/opt/jdk1.2.2/bin/javadoc #DEBUG = -g -deprecation DEBUG = -g JFLAGS = -classpath $(CLASSPATH):jar/cryptix.jar:. @@ -36,7 +41,8 @@ # # major rules to create files # -all: app cont doc jar tools/mrelayd tools/relayd +#all: app cont doc jar tools/mrelayd tools/relayd +all: app doc jar run: app $(JAVA) $(JFLAGS) de.mud.jta.Main @@ -45,7 +51,7 @@ @echo Creating source documentation ... @if [ ! -d doc ]; then mkdir doc; fi @-rm -r doc/source/*.html doc/source/de - @javadoc -d doc/source -version -author \ + @$(JAVADOC) -d doc/source -version -author \ -sourcepath $(CLASSPATH):.:contrib \ `(find de -name \*.java -printf '%h\n'; \ (cd contrib; find * -name \*.java -printf '%h\n')) | \ @@ -55,7 +61,7 @@ tex: app @echo Creating latex source documentation ... - @javadoc -docletpath ../tex -doclet TexDoclet \ + @$(JAVADOC) -docletpath ../tex -doclet TexDoclet \ -output $(PKGNAME).tex \ -docdir de/mud/jta `find de/mud -type d -print | \ grep -v CVS | grep -v '^de/mud$$' | sed 's/\//./g'`; > /dev/null @@ -158,7 +164,8 @@ clean: -find . -name \*.class -print | xargs rm > /dev/null 2>&1 -find . -name \*~ -print | xargs rm > /dev/null 2>&1 - -rm tools/relayd tools/mrelayd + -rm -f tools/relayd tools/mrelayd realclean: clean -rm -f jar/$(PKGNAME).jar jar/$(PKGNAME)-src.jar + @echo "Please clean manually in jni/ if you built any native classes" diff -urN jta20-20001106-2155/README jta20-p3/README --- jta20-20001106-2155/README Thu Nov 9 22:49:38 2000 +++ jta20-p3/README Thu Nov 9 23:12:56 2000 @@ -39,6 +39,8 @@ Using the make file to compile the source and building jar files will result in the packages to be stored in that directory. +jni/ + Implementation of native methods for different platforms. license/ Contains the license this software is covered by in text format. diff -urN jta20-20001106-2155/TODO jta20-p3/TODO --- jta20-20001106-2155/TODO Wed Dec 31 16:00:00 1969 +++ jta20-p3/TODO Fri Nov 10 00:04:53 2000 @@ -0,0 +1,32 @@ +Shell +===== + +2000/10/07: Got first well working version with PTY. +Why did glibc-2.1.3 move forkpty() into libutil? + +2000/10/21: Fixed Process p = Runtime.getRuntime().exec("/bin/sh") mode. +Good exercise, entirely useless otherwise. + +2000/11/09: Moved C modules into jni/. + + * Without arguments it ends with "localhost". + Make different default arguments for different plugins. +[zaitcev@niphredil jta20-p3]$ find . -name '*.java'| xargs grep localhost| more +./de/mud/jta/Main.java: if(host1 == null) host1 = "localhost"; +./contrib/hc/net/TelnetClient.java: String host = "localhost"; + + * Argument list to start "/bin/sh -i" - is related to host/port "argument". + Currently we pass only one String, so you must use wrappers. Bleah. + + * Need to track if the process ends running (^D, or "exit"), then go "offline". + Or, perhaps, exit the whole program? (this is what xterm does) + + * Selection does now work (jta -> X11). Why? + You *CAN* select visually, so apparently it was designed to work. Or was it? + + * 2000/11/04 Make it so that window resize gets through PTY and does SIGWINCH. + +General +======= + + * 2000/11/09: Something must be done about "^?" diff -urN jta20-20001106-2155/de/mud/jta/default.conf jta20-p3/de/mud/jta/default.conf --- jta20-20001106-2155/de/mud/jta/default.conf Thu Nov 9 22:49:38 2000 +++ jta20-p3/de/mud/jta/default.conf Thu Nov 9 23:05:32 2000 @@ -25,7 +25,8 @@ # ======================================================================= # common program defaults # ======================================================================= -plugins = Status,Socket,Telnet,Terminal +#plugins = Status,Socket,Telnet,Terminal +plugins = Status,Shell,Terminal pluginPath = de.mud.jta.plugin layout = BorderLayout layout.Terminal = Center diff -urN jta20-20001106-2155/de/mud/jta/plugin/HandlerPTY.java jta20-p3/de/mud/jta/plugin/HandlerPTY.java --- jta20-20001106-2155/de/mud/jta/plugin/HandlerPTY.java Wed Dec 31 16:00:00 1969 +++ jta20-p3/de/mud/jta/plugin/HandlerPTY.java Thu Nov 9 22:59:58 2000 @@ -0,0 +1,31 @@ +// JNI interface to slave process. +// This is a part of Shell plugin. +// If not for a static member, we'd have HandlerPTY private to Shell. XXX + +// HandlerPTY is meant to be robust, in a way that you can +// instantiate it and work with it until it throws an exception, +// then forget it. A finalizer takes care of file descriptors. + +package de.mud.jta.plugin; + +public class HandlerPTY { + public native int start(String cmd); // open + fork/exec + public native void close(); + public native int read(byte[] b); + public native int write(byte[] b); + + private int fd; + boolean good = false; + + static { + // System.loadLibrary("libutil"); // forkpty on Linux lives in libutil + System.loadLibrary("jtapty"); + } + + protected void finalize() throws Throwable { + super.finalize(); + if(good) { + close(); + } + } +} diff -urN jta20-20001106-2155/de/mud/jta/plugin/Shell.java jta20-p3/de/mud/jta/plugin/Shell.java --- jta20-20001106-2155/de/mud/jta/plugin/Shell.java Thu Nov 9 22:49:38 2000 +++ jta20-p3/de/mud/jta/plugin/Shell.java Fri Nov 10 00:01:12 2000 @@ -28,30 +28,24 @@ import de.mud.jta.event.ConfigurationListener; import de.mud.jta.event.OnlineStatus; -import java.io.InputStream; -import java.io.OutputStream; +// import java.io.InputStream; +// import java.io.OutputStream; import java.io.IOException; /** * The shell plugin is the backend component for terminal emulation using * a shell. It provides the i/o streams of the shell as data source. *
- * Thomas Kriegelstein wrote a hack that converted newlines to \r\n which - * was used as an example for improving this plugin. - *
* Maintainer: Matthias L. Jugel
*
* @version $Id: Shell.java,v 2.3 2000/05/26 06:08:16 leo Exp $
- * @author Matthias L. Jugel, Marcus Meißner
+ * @author Matthias L. Jugel, Marcus Meißner, Pete Zaitcev
*/
public class Shell extends Plugin implements FilterPlugin {
- private final static int debug = 1;
-
protected String shellCommand;
- protected InputStream in, err;
- protected OutputStream out;
- protected Process p;
+
+ private HandlerPTY pty;
public Shell(final PluginBus bus, final String id) {
super(bus, id);
@@ -59,103 +53,53 @@
bus.registerPluginListener(new ConfigurationListener() {
public void setConfiguration(PluginConfig cfg) {
String tmp;
- if((tmp = cfg.getProperty("Shell", id, "command")) != null)
+ if((tmp = cfg.getProperty("Shell", id, "command")) != null) {
shellCommand = tmp;
+ // System.out.println("Shell: Setting config " + tmp); // P3
+ } else {
+ // System.out.println("Shell: Not setting config"); // P3
+ }
}
});
-
+
bus.registerPluginListener(new SocketListener() {
// we do actually ignore these parameters
public void connect(String host, int port) {
- if(p == null) execute(host);
+ // XXX Fix this together with window size changes
+ // String ttype = (String)bus.broadcast(new TerminalTypeRequest());
+ // String ttype = getTerminalType();
+ // if(ttype == null) ttype = "dumb";
+
+ // XXX Add try around here to catch missing DLL/.so.
+ pty = new HandlerPTY();
+
+ if(pty.start(host) == 0) {
+ bus.broadcast(new OnlineStatus(true));
+ } else {
+ bus.broadcast(new OnlineStatus(false));
+ }
}
public void disconnect() {
- if(p != null) {
- p.destroy();
- p = null; in = null; out = null;
- }
- else execute(null);
+ bus.broadcast(new OnlineStatus(false));
+ pty = null;
}
});
}
- private void execute(String command) {
- shellCommand = (command != null) ? command : shellCommand;
- if(shellCommand == null) return;
- Runtime rt = Runtime.getRuntime();
- try {
- p = rt.exec(shellCommand);
- in = p.getInputStream();
- out = p.getOutputStream();
- err = p.getErrorStream();
- } catch(Exception e) {
- Shell.this.error("error: "+e);
- e.printStackTrace();
- }
- bus.broadcast(new OnlineStatus(true));
- }
-
public void setFilterSource(FilterPlugin plugin) {
// we do not have a source other than our socket
}
- private byte[] transpose(byte[] buf) {
- byte[] nbuf;
- int nbufptr = 0;
- nbuf = new byte[buf.length * 2];
- for(int i = 0; i < buf.length; i++)
- switch(buf[i]) {
- case 10: // \n
- nbuf[nbufptr++] = 13;
- nbuf[nbufptr++] = 10;
- break;
- default:
- nbuf[nbufptr++] = buf[i];
- }
- byte[] xbuf = new byte[nbufptr];
- System.arraycopy(nbuf, 0, xbuf, 0, nbufptr);
- return xbuf;
- }
-
- private byte buffer[];
- private int pos;
-
public int read(byte[] b) throws IOException {
- // empty the buffer before reading more data
- if(buffer != null) {
- int amount = (buffer.length - pos) <= b.length ?
- buffer.length - pos : b.length;
- System.arraycopy(buffer, pos, b, 0, amount);
- if(pos + amount < buffer.length) {
- pos += amount;
- } else
- buffer = null;
- return amount;
+ if(pty == null) return 0;
+ int ret = pty.read(b);
+ if(ret <= 0) {
+ throw new IOException("EOF on PTY");
}
-
- // now we are sure the buffer is empty and read on
- int n = (err.available() > 0) ? err.read(b) : in.read(b);
- if(n > 0) {
- byte[] tmp = new byte[n];
- System.arraycopy(b, 0, tmp, 0, n);
- buffer = transpose(tmp);
- if(buffer != null && buffer.length > 0) {
- int amount = buffer.length <= b.length ? buffer.length : b.length;
- System.arraycopy(buffer, 0, b, 0, amount);
- pos = n = amount;
- if(amount == buffer.length) {
- buffer = null;
- pos = 0;
- }
- } else
- return 0;
- }
- return n;
+ return ret;
}
-
public void write(byte[] b) throws IOException {
- out.write(b);
- out.flush();
+ if(pty != null) pty.write(b);
}
}
diff -urN jta20-20001106-2155/de/mud/terminal/vt320.java jta20-p3/de/mud/terminal/vt320.java
--- jta20-20001106-2155/de/mud/terminal/vt320.java Thu Nov 9 22:49:38 2000
+++ jta20-p3/de/mud/terminal/vt320.java Thu Nov 9 23:31:13 2000
@@ -221,7 +221,7 @@
java.awt.Point pos = mouseGetPos(evt.getPoint());
byte b[] = new byte[6];
- b[0] = 27; b[1] = '['; b[2] = 'M';
+ b[0] = 27; b[1] = (byte) '['; b[2] = (byte) 'M';
b[3] = (byte)mousecode;
b[4] = (byte) (0x20 + pos.x + 1);
b[5] = (byte) (0x20 + pos.y + 1);
@@ -249,7 +249,7 @@
mousecode = '#';
byte b[] = new byte[6];
- b[0] = 27; b[1] = '['; b[2] = 'M';
+ b[0] = 27; b[1] = (byte) '['; b[2] = (byte) 'M';
b[3] = (byte)mousecode;
b[4] = (byte) (0x20 + pos.x + 1);
b[5] = (byte) (0x20 + pos.y + 1);
diff -urN jta20-20001106-2155/jni/linux/Makefile jta20-p3/jni/linux/Makefile
--- jta20-20001106-2155/jni/linux/Makefile Wed Dec 31 16:00:00 1969
+++ jta20-p3/jni/linux/Makefile Thu Nov 9 23:45:43 2000
@@ -0,0 +1,51 @@
+# This file is part of "The Java Telnet Application".
+#
+# This 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, or (at your option)
+# any later version.
+#
+# "The Java Telnet Application" 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 software; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+JAVAH = /q/opt/jdk1.2.2/bin/javah
+TOPDIR = ../..
+SRCDIR = ../../de
+CDIR = ../src
+
+JNI_INCLUDE = -I/q/opt/jdk1.2.2/include -I/q/opt/jdk1.2.2/include/linux
+
+# Linux (glibc 2.1.3)
+# libutil contains forkpty()
+CC = gcc
+SOCFLAGS = -fPIC -c -Wall -I. $(JNI_INCLUDE)
+SOLFLAGS = -shared -lutil
+
+#
+# major rules to create files
+#
+all: libjtapty.so
+
+HandlerPTY.h: $(SRCDIR)/mud/jta/plugin/HandlerPTY.class
+ $(JAVAH) -force -classpath $(TOPDIR) -o $@ de.mud.jta.plugin.HandlerPTY
+
+libjtapty.so: HandlerPTY.lo
+ $(CC) $(SOLFLAGS) -o $@ HandlerPTY.lo
+
+HandlerPTY.lo: $(CDIR)/HandlerPTY.c HandlerPTY.h
+ $(CC) $(SOCFLAGS) -o $@ $(CDIR)/HandlerPTY.c
+
+clean:
+ -find . -name \*~ -print | xargs rm -f
+ -rm -f HandlerPTY.h HandlerPTY.lo libjtapty.so
+
+realclean: clean
+
+# EOF
diff -urN jta20-20001106-2155/jni/solaris/Makefile jta20-p3/jni/solaris/Makefile
--- jta20-20001106-2155/jni/solaris/Makefile Wed Dec 31 16:00:00 1969
+++ jta20-p3/jni/solaris/Makefile Thu Nov 9 23:45:02 2000
@@ -0,0 +1,51 @@
+# This file is part of "The Java Telnet Application".
+#
+# This 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, or (at your option)
+# any later version.
+#
+# "The Java Telnet Application" 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 software; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+### This makefile is incomplete. Please adjust it to your environment.
+
+JAVAH = /usr/java/bin/javah
+TOPDIR = ../..
+SRCDIR = ../../de
+CDIR = ../src
+
+JNI_INCLUDE = -I/usr/java/include -I/usr/java/include/linux
+
+CC = /opt/SUNWspro/SC5.0/bin/cc
+SOCFLAGS = -c -I. $(JNI_INCLUDE) -G
+SOLFLAGS = -G
+
+#
+# major rules to create files
+#
+all: libjtapty.so
+
+HandlerPTY.h: $(SRCDIR)/mud/jta/plugin/HandlerPTY.class
+ $(JAVAH) -force -classpath $(TOPDIR) -o $@ de.mud.jta.plugin.HandlerPTY
+
+libjtapty.so: HandlerPTY.lo
+ $(CC) $(SOLFLAGS) -o $@ HandlerPTY.lo
+
+HandlerPTY.lo: $(CDIR)/HandlerPTY.c HandlerPTY.h
+ $(CC) $(SOCFLAGS) -o $@ $(CDIR)/HandlerPTY.c
+
+clean:
+ -find . -name \*~ -print | xargs rm -f
+ -rm -f HandlerPTY.h libjtapty.so
+
+realclean: clean
+
+# EOF
diff -urN jta20-20001106-2155/jni/src/HandlerPTY.c jta20-p3/jni/src/HandlerPTY.c
--- jta20-20001106-2155/jni/src/HandlerPTY.c Wed Dec 31 16:00:00 1969
+++ jta20-p3/jni/src/HandlerPTY.c Thu Nov 9 22:59:58 2000
@@ -0,0 +1,243 @@
+/*
+ * Native methods for HandlerPTY (part of Shell).
+ */
+#include