changeset 69:294435151b0c tn5250

use 5250 encryption config entry
author Carl Byington <carl@five-ten-sg.com>
date Fri, 13 Jun 2014 19:06:01 -0700
parents cc7e3588a0f3
children c56032728742
files src/com/five_ten_sg/connectbot/service/TerminalMonitor.java src/com/five_ten_sg/connectbot/transport/AbsTransport.java src/com/five_ten_sg/connectbot/transport/TN5250.java src/de/mud/terminal/vt320.java src/org/tn5250j/framework/tn5250/DataStreamProducer.java src/org/tn5250j/framework/tn5250/Screen5250.java src/org/tn5250j/framework/tn5250/ScreenField.java src/org/tn5250j/framework/tn5250/ScreenFields.java src/org/tn5250j/framework/tn5250/tnvt.java
diffstat 9 files changed, 86 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Fri Jun 13 16:24:59 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Fri Jun 13 19:06:01 2014 -0700
@@ -332,10 +332,9 @@
 
     public synchronized void setField(int l, int c, char[] data, int offset) {
         Log.i(TAG, "setField()");
-        byte[] d = charsToBytes(data);
-        byte[] b = new byte[d.length - offset];
-        System.arraycopy(d, offset, b, 0, d.length - offset);
-        buffer.write(b);
+        char[] d = new char[data.length - offset];
+        System.arraycopy(data, offset, d, 0, data.length - offset);
+        buffer.setField(l, c, d);
     }
 
     public synchronized void getField(int l, int c, int len) {
--- a/src/com/five_ten_sg/connectbot/transport/AbsTransport.java	Fri Jun 13 16:24:59 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/transport/AbsTransport.java	Fri Jun 13 19:06:01 2014 -0700
@@ -48,6 +48,8 @@
         public void debug(String s) {
             Log.d(TAG, s);
         }
+
+        // terminal key listener sending to the host
         @Override
         public void write(byte[] b) {
             try {
@@ -70,6 +72,7 @@
                 Log.e(TAG, "Problem writing outgoing data in vt320() thread", e);
             }
         }
+
         // We don't use telnet sequences.
         @Override
         public void sendTelnetCommand(byte cmd) {
@@ -78,11 +81,6 @@
         @Override
         public void setWindowSize(int c, int r) {
         }
-        // test for changed screen contents
-        @Override
-        public void testChanged() {
-            if (bridge.monitor != null) bridge.monitor.testChanged();
-        }
         // play beep noise
         @Override
         public void beep() {
@@ -91,6 +89,13 @@
             else
                 manager.sendActivityNotification(host);
         }
+
+        // test for changed screen contents
+        @Override
+        public void testChanged() {
+            if (bridge.monitor != null) bridge.monitor.testChanged();
+        }
+        // relay socket writing to the screen
         // bridge.monitor placement of new characters
         @Override
         public void putChar(int c, int l, char ch, int attributes) {
@@ -131,6 +136,9 @@
 
             super.setCursorPosition(c, l);
         }
+
+        // monitor setField()
+
     };
 
 
--- a/src/com/five_ten_sg/connectbot/transport/TN5250.java	Fri Jun 13 16:24:59 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/transport/TN5250.java	Fri Jun 13 19:06:01 2014 -0700
@@ -130,24 +130,39 @@
             Log.d(TAG, s);
         }
 
-        // terminal key listener sending to the host
+        // monitor injecting a field
+        @Override
+        public void setField(int l, int c, char [] d) {
+            screen52.setField(l, c, d);
+        }
+
+        // terminal key listener sending to local screen
         @Override
         public void write(byte[] b) {
+            if (bridge.monitor != null) bridge.monitor.hostData(b);
             screen52.sendKeys(new String(b));
         }
         @Override
         public void write(int b) {
+            if (bridge.monitor != null) bridge.monitor.hostData(b);
             screen52.sendKeys(new String(new byte[] {(byte)b}));
         }
         @Override
         public void keyPressed(int keyCode, char keyChar, int modifiers) {
-            String s;
             if (mnemonics.containsKey(keyCode)) {
-                s = mnemonics.get(keyCode);
-                if (s != "") screen52.sendKeys(s);
+                String s = mnemonics.get(keyCode);
+                if (s != "") {
+                    if (bridge.monitor != null) bridge.monitor.hostData(s);
+                    screen52.sendKeys(s);
+                }
             }
         }
         // 5250 writing to the screen
+        // test for changed screen contents
+        @Override
+        public void testChanged() {
+            if (bridge.monitor != null) bridge.monitor.testChanged();
+        }
         @Override
         public void putChar(int c, int l, char ch, int attributes) {
             if (bridge.monitor != null) bridge.monitor.screenChanged(l, c);
@@ -230,7 +245,7 @@
         handler.setSSLType(encryption);
         screen52.setVT(handler);
         screen52.setBuffer(buffer);
-        connected = handler.connect(host.getHostname(), host.getPort());
+        connected = handler.connect(host.getHostname(), host.getPort(), buffer);
         if (connected) bridge.onConnected();
     }
 
--- a/src/de/mud/terminal/vt320.java	Fri Jun 13 16:24:59 2014 -0700
+++ b/src/de/mud/terminal/vt320.java	Fri Jun 13 19:06:01 2014 -0700
@@ -66,6 +66,17 @@
     }
 
     /**
+     * inject field contents as if typed
+     */
+    public void setField(int l, int c, char [] d) {
+        // ignore line and column, just send the bytes to the host.
+        int n = d.length;
+        byte [] b = new byte [n];
+        for (int i=0; i<n; i++) b[i] = c[i] & 0x00ff;
+        write(b);
+    }
+
+    /**
      * Play the beep sound ...
      */
     public void beep() {
--- a/src/org/tn5250j/framework/tn5250/DataStreamProducer.java	Fri Jun 13 16:24:59 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/DataStreamProducer.java	Fri Jun 13 19:06:01 2014 -0700
@@ -16,12 +16,13 @@
 
 public class DataStreamProducer implements Runnable {
     private static final String TAG = "DataStreamProducer";
+   private tnvt                vt;
    private BufferedInputStream bin;
+   private vt320               buffer;
    private ByteArrayOutputStream baosin;
    private Thread me;
    private byte[] saveStream;
    private final BlockingQueue<Object> dsq;
-   private tnvt vt;
    private byte[] abyte2;
    private FileOutputStream fw;
    private BufferedOutputStream dw;
@@ -30,9 +31,10 @@
 
 
 
-   public DataStreamProducer(tnvt vt, BufferedInputStream in, BlockingQueue<Object> queue, byte[] init) {
-      bin = in;
-      this.vt = vt;
+   public DataStreamProducer(tnvt vt, BufferedInputStream bin, vt320 buffer, BlockingQueue<Object> queue, byte[] init) {
+      this.bin    = bin;
+      this.vt     = vt;
+      this.buffer = buffer;
       baosin = new ByteArrayOutputStream();
       dsq = queue;
       abyte2 = init;
@@ -162,7 +164,7 @@
       int i = 0;
 
       while(!done) {
-
+         if (bin.available() == 0) buffer.testChanged();
          i = bin.read();
 
          // WVL - LDC : 16/07/2003 : TR.000345
--- a/src/org/tn5250j/framework/tn5250/Screen5250.java	Fri Jun 13 16:24:59 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/Screen5250.java	Fri Jun 13 19:06:01 2014 -0700
@@ -2682,6 +2682,24 @@
         updateCursorLoc();
     }
 
+    /*
+     * set the content of the field at (l,c) to d
+     * if l == -1, set the current field contents to d
+     */
+    public void setField(int l, int c, char [] d) {
+        ScreenField cf;
+        if (l >= 0) {
+            int position = l * numCols + c;
+            isInField(position, true);
+        }
+        if ((d != null) && (d.length > 0)) {
+            cf = screenFields.getCurrentField();
+            cf.setString(new String(d));
+            lastPos = cf.getStartPos();
+        }
+        updateDirty();
+    }
+
     /**
      * Set the current working field to the field number specified.
      *
@@ -2690,6 +2708,7 @@
      * @return true or false whether it was sucessful
      */
     public boolean gotoField(int f) {
+    public boolean gotoField(int f) {
 
         int sizeFields = screenFields.getSize();
 
--- a/src/org/tn5250j/framework/tn5250/ScreenField.java	Fri Jun 13 16:24:59 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/ScreenField.java	Fri Jun 13 19:06:01 2014 -0700
@@ -51,13 +51,12 @@
 
 //      startRow = row;
 //      startCol = col;
-      startPos = (row * s.getColumns()) + col;
-      endPos = startPos + length -1;
       cursorProg = 0;
-      fieldId = 0;
-      length = len;
-      endPos = startPos + length -1;
-      this.attr = attr;
+      fieldId    = 0;
+      length     = len;
+      startPos   = (row * s.getColumns()) + col;
+      endPos     = startPos + length - 1;
+      this.attr  = attr;
       setFFWs(ffw1,ffw2);
       setFCWs(fcw1,fcw2);
 
@@ -169,8 +168,6 @@
    }
 
    protected String getText() {
-
-
       StringBuffer text = new StringBuffer();
       getKeyPos(endPos);
       int x = length;
@@ -372,7 +369,7 @@
       return (getFieldShift() == 7);
 
    }
-   
+
    public boolean isRightToLeft() {
 	   return (getFieldShift() == 0x04);
    }
@@ -580,6 +577,10 @@
             " mdt = " + mdt;
    }
 
+    public int getStartPos() {
+        return startPos;
+    }
+
    int startPos = 0;
    int endPos = 0;
    boolean mdt = false;
--- a/src/org/tn5250j/framework/tn5250/ScreenFields.java	Fri Jun 13 16:24:59 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/ScreenFields.java	Fri Jun 13 19:06:01 2014 -0700
@@ -427,7 +427,7 @@
 
    public void gotoFieldNext() {
 
-      // sanity check - we where getting null pointers after a restore of screen
+      // sanity check - we were getting null pointers after a restore of screen
       //   and cursor was not positioned on a field when returned
       //   *** Note *** to myself
       //   maybe this is fixed I will have to check this some time
--- a/src/org/tn5250j/framework/tn5250/tnvt.java	Fri Jun 13 16:24:59 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/tnvt.java	Fri Jun 13 19:06:01 2014 -0700
@@ -265,7 +265,7 @@
     }
 
 
-    public final boolean connect(String hostname, int port) {
+    public final boolean connect(String hostname, int port, vt320 buffer) {
         try {
             this.hostname = hostname;
             this.port     = port;
@@ -308,7 +308,7 @@
 
             }
 
-            producer = new DataStreamProducer(this, bin, dsq, abyte0);
+            producer = new DataStreamProducer(this, bin, buffer, dsq, abyte0);
             pthread = new Thread(producer);
             //         pthread.setPriority(pthread.MIN_PRIORITY);
             pthread.setPriority(Thread.NORM_PRIORITY);