|
From: <cr...@us...> - 2009-04-16 13:27:08
|
Revision: 5291
http://jnode.svn.sourceforge.net/jnode/?rev=5291&view=rev
Author: crawley
Date: 2009-04-16 13:27:02 +0000 (Thu, 16 Apr 2009)
Log Message:
-----------
Changes aimed at protecting the shell from applications that close
the console input, output or error streams.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
trunk/shell/src/shell/org/jnode/shell/CommandShell.java
trunk/shell/src/shell/org/jnode/shell/io/Pipeline.java
trunk/shell/src/shell/org/jnode/shell/io/PipelineInputStream.java
trunk/shell/src/shell/org/jnode/shell/io/PipelineOutputStream.java
Added Paths:
-----------
trunk/shell/src/shell/org/jnode/shell/io/ShellConsoleReader.java
trunk/shell/src/shell/org/jnode/shell/io/ShellConsoleWriter.java
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2009-04-16 08:57:24 UTC (rev 5290)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2009-04-16 13:27:02 UTC (rev 5291)
@@ -93,7 +93,25 @@
private final KeyboardHandler keyboardHandler;
private final FocusListener focusListener;
+
+ /**
+ * This constructor is used by wrappers.
+ */
+ protected KeyboardReader() {
+ this.keyboardHandler = null;
+ this.focusListener = null;
+ this.currentLine = null;
+ this.out = null;
+ this.console = null;
+ }
+ /**
+ * Create KeyboardReader using the supplied handler as the source of
+ * keyboard events and the supplied TextConsole to echo typed characters.
+ *
+ * @param kbHandler
+ * @param console
+ */
public KeyboardReader(KeyboardHandler kbHandler, TextConsole console) {
this.keyboardHandler = kbHandler;
this.console = console;
Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2009-04-16 08:57:24 UTC (rev 5290)
+++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2009-04-16 13:27:02 UTC (rev 5291)
@@ -51,6 +51,7 @@
import org.jnode.driver.console.ConsoleManager;
import org.jnode.driver.console.InputHistory;
import org.jnode.driver.console.TextConsole;
+import org.jnode.driver.console.spi.ConsoleWriter;
import org.jnode.driver.console.textscreen.KeyboardReader;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.alias.AliasManager;
@@ -62,6 +63,8 @@
import org.jnode.shell.io.FanoutWriter;
import org.jnode.shell.io.NullInputStream;
import org.jnode.shell.io.NullOutputStream;
+import org.jnode.shell.io.ShellConsoleReader;
+import org.jnode.shell.io.ShellConsoleWriter;
import org.jnode.shell.isolate.IsolateCommandInvoker;
import org.jnode.shell.proclet.ProcletCommandInvoker;
import org.jnode.shell.syntax.ArgumentBundle;
@@ -197,11 +200,14 @@
debugEnabled = true;
try {
console = cons;
- Reader in = console.getIn();
+ KeyboardReader in = (KeyboardReader) console.getIn();
+ ConsoleWriter out = (ConsoleWriter) console.getOut();
+ ConsoleWriter err = (ConsoleWriter) console.getErr();
if (in == null) {
throw new ShellException("console input stream is null");
}
- setupStreams(in, console.getOut(), console.getErr());
+ setupStreams(new ShellConsoleReader(in), new ShellConsoleWriter(out),
+ new ShellConsoleWriter(err));
SystemInputStream.getInstance().initialize(new ReaderInputStream(in));
cons.setCompleter(this);
Modified: trunk/shell/src/shell/org/jnode/shell/io/Pipeline.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/io/Pipeline.java 2009-04-16 08:57:24 UTC (rev 5290)
+++ trunk/shell/src/shell/org/jnode/shell/io/Pipeline.java 2009-04-16 13:27:02 UTC (rev 5291)
@@ -1,3 +1,23 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library 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; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
package org.jnode.shell.io;
import java.io.IOException;
Modified: trunk/shell/src/shell/org/jnode/shell/io/PipelineInputStream.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/io/PipelineInputStream.java 2009-04-16 08:57:24 UTC (rev 5290)
+++ trunk/shell/src/shell/org/jnode/shell/io/PipelineInputStream.java 2009-04-16 13:27:02 UTC (rev 5291)
@@ -1,3 +1,23 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library 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; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
package org.jnode.shell.io;
import java.io.IOException;
Modified: trunk/shell/src/shell/org/jnode/shell/io/PipelineOutputStream.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/io/PipelineOutputStream.java 2009-04-16 08:57:24 UTC (rev 5290)
+++ trunk/shell/src/shell/org/jnode/shell/io/PipelineOutputStream.java 2009-04-16 13:27:02 UTC (rev 5291)
@@ -1,3 +1,23 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library 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; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
package org.jnode.shell.io;
import java.io.IOException;
Added: trunk/shell/src/shell/org/jnode/shell/io/ShellConsoleReader.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/io/ShellConsoleReader.java (rev 0)
+++ trunk/shell/src/shell/org/jnode/shell/io/ShellConsoleReader.java 2009-04-16 13:27:02 UTC (rev 5291)
@@ -0,0 +1,142 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library 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; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.shell.io;
+
+import java.io.IOException;
+import java.nio.CharBuffer;
+
+import org.jnode.driver.console.InputCompleter;
+import org.jnode.driver.console.TextConsole;
+import org.jnode.driver.console.textscreen.ConsoleKeyEventBindings;
+import org.jnode.driver.console.textscreen.KeyboardReader;
+import org.jnode.system.event.FocusEvent;
+
+/**
+ * This is a wrapper class that protects the shell's KeyboardReader from
+ * applications closing it.
+ *
+ * @author cr...@jn...
+ */
+public class ShellConsoleReader extends KeyboardReader {
+
+ private final KeyboardReader reader;
+
+ public ShellConsoleReader(KeyboardReader reader) {
+ super();
+ this.reader = reader;
+ }
+
+ @Override
+ public void close() throws IOException {
+ // Do nothing
+ }
+
+ @Override
+ public int read(char[] buf, int off, int len) throws IOException {
+ return reader.read(buf, off, len);
+ }
+
+ @Override
+ public void mark(int readAheadLimit) {
+ reader.mark(readAheadLimit);
+ }
+
+ @Override
+ public boolean markSupported() {
+ return reader.markSupported();
+ }
+
+ @Override
+ public int read() throws IOException {
+ return reader.read();
+ }
+
+ @Override
+ public int read(char[] cbuf) throws IOException {
+ return reader.read(cbuf);
+ }
+
+ @Override
+ public int read(CharBuffer target) throws IOException {
+ return reader.read(target);
+ }
+
+ @Override
+ public boolean ready() throws IOException {
+ return reader.ready();
+ }
+
+ @Override
+ public void reset() throws IOException {
+ reader.reset();
+ }
+
+ @Override
+ public long skip(long arg0) throws IOException {
+ return reader.skip(arg0);
+ }
+
+ @Override
+ public void clearSoftEOF() {
+ reader.clearSoftEOF();
+ }
+
+ @Override
+ public void focusGained(FocusEvent event) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void focusLost(FocusEvent event) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public InputCompleter getCompleter() {
+ return reader.getCompleter();
+ }
+
+ @Override
+ public ConsoleKeyEventBindings getKeyEventBindings() {
+ return reader.getKeyEventBindings();
+ }
+
+ @Override
+ public TextConsole getTextConsole() {
+ return reader.getTextConsole();
+ }
+
+ @Override
+ public boolean isSoftEOF() {
+ return reader.isSoftEOF();
+ }
+
+ @Override
+ public void setCompleter(InputCompleter completer) {
+ reader.setCompleter(completer);
+ }
+
+ @Override
+ public void setKeyEventBindings(ConsoleKeyEventBindings bindings) {
+ reader.setKeyEventBindings(bindings);
+ }
+
+}
Added: trunk/shell/src/shell/org/jnode/shell/io/ShellConsoleWriter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/io/ShellConsoleWriter.java (rev 0)
+++ trunk/shell/src/shell/org/jnode/shell/io/ShellConsoleWriter.java 2009-04-16 13:27:02 UTC (rev 5291)
@@ -0,0 +1,111 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library 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; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.shell.io;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.jnode.driver.console.TextConsole;
+import org.jnode.driver.console.spi.ConsoleWriter;
+
+/**
+ * This is a wrapper class that protects the shell's ConsoleWriter from
+ * applications closing it.
+ *
+ * @author cr...@jn...
+ */
+public class ShellConsoleWriter extends ConsoleWriter {
+
+ private final ConsoleWriter writer;
+
+ public ShellConsoleWriter(ConsoleWriter writer) {
+ super(null, 0);
+ this.writer = writer;
+ }
+
+ @Override
+ public void close() throws IOException {
+ flush();
+ }
+
+ @Override
+ public void flush() throws IOException {
+ writer.flush();
+ }
+
+ @Override
+ public int getFgColor() {
+ return writer.getFgColor();
+ }
+
+ @Override
+ public TextConsole getTextConsole() {
+ return writer.getTextConsole();
+ }
+
+ @Override
+ public void setFgColor(int fgColor) {
+ writer.setFgColor(fgColor);
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException,
+ NullPointerException, IndexOutOfBoundsException {
+ writer.write(cbuf, off, len);
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ writer.write(b);
+ }
+
+ @Override
+ public Writer append(CharSequence csq) throws IOException {
+ return writer.append(csq);
+ }
+
+ @Override
+ public Writer append(char c) throws IOException {
+ return writer.append(c);
+ }
+
+ @Override
+ public Writer append(CharSequence csq, int start, int end)
+ throws IOException {
+ return writer.append(csq, start, end);
+ }
+
+ @Override
+ public void write(char[] cbuf) throws IOException {
+ writer.write(cbuf);
+ }
+
+ @Override
+ public void write(String str) throws IOException {
+ writer.write(str);
+ }
+
+ @Override
+ public void write(String str, int off, int len) throws IOException {
+ writer.write(str, off, len);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|