Mercurial > hg > Applications > TreeVNC
changeset 60:ac6f9e46566f
proxy mode ok.
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Sat Dec 21 18:46:54 2013 +0900 @@ -327,12 +327,12 @@ return protocolVersion; } - public void startNormalHandling(VncProxyService vncProxyService, - Surface surface, ClipboardControllerImpl clipboardController, - MyRfbProtoProxy rfb) + public void startNormalHandling(IRfbSessionListener rfbSessionListener, + IRepaintController repaintController, ClipboardController clipboardController, + MyRfbProto rfb) { - this.rfbSessionListener = vncProxyService; - this.repaintController = surface; + this.rfbSessionListener = rfbSessionListener; + this.repaintController = repaintController; // if (settings.getBitsPerPixel() == 0) { // settings.setBitsPerPixel(pixelFormat.bitsPerPixel); // the same the server sent when not initialized yet // } @@ -344,7 +344,7 @@ sendSupportedEncodingsMessage(settings); settings.addListener(this); // to support pixel format (color depth), and encodings changes - settings.addListener(surface); + settings.addListener(repaintController); sendRefreshMessage(); senderTask = new SenderTask(messageQueue, writer, this); senderThread = new Thread(senderTask);
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Sat Dec 21 18:46:54 2013 +0900 @@ -30,6 +30,7 @@ private boolean proxyFlag = true; private EchoClient echo; private String proxyAddr; + public int acceptPort; public MyRfbProto() { rThread = new RequestScreenThread(this); @@ -364,4 +365,8 @@ //nothing } + public int getAcceptPort() { + return 0; + } + }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetDataClient.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetDataClient.java Sat Dec 21 18:46:54 2013 +0900 @@ -6,6 +6,8 @@ import java.net.ServerSocket; import java.net.Socket; +import com.glavsoft.viewer.mvp.View; + public class GetDataClient implements Runnable { private ServerSocket server = null; @@ -14,8 +16,10 @@ private boolean stopFlag; private TextBoxClient text = new TextBoxClient(); private String proxyAddr; + private View v; - + + public String textAddress() { return text.getAddress(); }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/GetBroadCastProxy.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/GetBroadCastProxy.java Sat Dec 21 18:46:54 2013 +0900 @@ -22,7 +22,7 @@ public GetBroadCastProxy(VncProxyService _vps,String desktopName,String host){ vps = _vps; - bCast = new BroadCastProxy(vps.rfb.acceptPort+":"+host+":" + bCast = new BroadCastProxy(vps.myRfb.getAcceptPort()+":"+host+":" +desktopName+":"+getMyAddress()+":"); } @@ -66,7 +66,7 @@ private String castString(byte[] a) { String recover = new String(a); - recover = recover.replace("��n", ""); + recover = recover.replace("������n", ""); recover = recover.trim(); return recover; }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Sat Dec 21 18:46:54 2013 +0900 @@ -98,7 +98,7 @@ return port; } - int getAcceptPort() { + public int getAcceptPort() { return acceptPort; }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Sat Dec 21 18:46:54 2013 +0900 @@ -23,11 +23,17 @@ import com.glavsoft.rfb.protocol.ProtocolSettings; import com.glavsoft.transport.Reader; import com.glavsoft.transport.Writer; +import com.glavsoft.viewer.ConnectionPresenter; import com.glavsoft.viewer.Viewer; import com.glavsoft.viewer.cli.Parser; +import com.glavsoft.viewer.mvp.View; import com.glavsoft.viewer.swing.ClipboardControllerImpl; +import com.glavsoft.viewer.swing.ConnectionParams; import com.glavsoft.viewer.swing.ParametersHandler; import com.glavsoft.viewer.swing.Surface; +import com.glavsoft.viewer.swing.SwingConnectionWorkerFactory; +import com.glavsoft.viewer.swing.SwingViewerWindowFactory; +import com.glavsoft.viewer.swing.gui.ConnectionView; public class VncProxyService extends Viewer implements Runnable, IRfbSessionListener, IChangeSettingsListener { @@ -37,8 +43,6 @@ */ private static final long serialVersionUID = 1L; - public MyRfbProtoProxy rfb; - public static final int DEFAULT_PORT = 5900; public static Logger logger = Logger.getLogger("com.glavsoft"); private boolean forceReconnection; @@ -48,6 +52,7 @@ private GetBroadCastProxy getCast; public AcceptClient aClient; public int opendPort; + private Viewer view; private VncProxyService prevVps; static VncProxyService currentVps; @@ -64,17 +69,15 @@ } public VncProxyService() { + // connectionParams = new ConnectionParams(); settings = ProtocolSettings.getDefaultSettings(); uiSettings = super.uiSettings; - connectionParams.hostName = "localhost"; } - - public VncProxyService(VncProxyService vps, String hostName) { this(); connectionParams.hostName = hostName; - rfb = vps.rfb; + myRfb = vps.myRfb; forceReconnection = vps.forceReconnection; reconnectionReason = vps.reconnectionReason; acceptThread = vps.acceptThread; @@ -88,7 +91,7 @@ String[] mainArgs = argv; System.out.println(mainArgs.length); // input into arguments Decision - + Parser parser = new Parser(); ParametersHandler.completeParserOptions(parser); @@ -101,8 +104,8 @@ vps.initProxy1(argv, mainArgs, parser); } - private void initProxy1(String[] argv, String[] mainArgs, - Parser parser) { + private void initProxy1(String[] argv, String[] mainArgs, Parser parser) { + myRfb = new MyRfbProtoProxy(); initProxy(parser); if (mainArgs.length != 0) { for (int i = 0; i < argv.length; i++) { @@ -112,13 +115,16 @@ } else { // getHostData(); } - //run1(); + setIsTreeVNC(true); + setConnectionParam("localhost",5900); + isApplet = true; + run(); createConnectionAndStart(); getChangeScreenRequest(); // Should be used Client Socket. try { threadSetAndStart(); } catch (UnknownHostException e) { - + } catch (IOException e) { } @@ -126,129 +132,40 @@ private void setArguments(String[] mainArgs) { } - - /* - public boolean run1() { - rfb = new MyRfbProtoProxy(); - // getHostData(); - if (forceReconnection) { - connectionManager.showReconnectDialog("Connection lost", - prevVps.reconnectionReason); - forceReconnection = false; - } - tryAgain = true; - while (tryAgain) { - workingSocket = connectionManager.connectToHost(connectionParams, - settings, rfb); - if (null == workingSocket) { - closeApp(); - break; - } - logger.info("Connected"); - try { - workingSocket.setTcpNoDelay(true); // disable Nagle algorithm - Reader reader = new Reader(workingSocket.getInputStream()); - Writer writer = new Writer(workingSocket.getOutputStream()); - // rfb.setStream(reader,writer); - workingProtocol = new Protocol(reader, writer, - new PasswordChooser(passwordFromParams, - connectionParams, containerFrame, this), - settings); -// if(fbWidth!=0) - workingProtocol.setScreenSizeRetina(1080, 1080); - workingProtocol.handshake(); - rfb.setProtocolContext(workingProtocol); - // input into change parents - ClipboardControllerImpl clipboardController = new ClipboardControllerImpl( - workingProtocol, settings.getRemoteCharsetName()); - clipboardController.setEnabled(settings - .isAllowClipboardTransfer()); - settings.addListener(clipboardController); - surface = new Surface(workingProtocol, this, - uiSettings.getScaleFactor()); // this method - settings.addListener(this); - uiSettings.addListener(surface); - containerFrame = createContainer(); - connectionManager.setContainerFrame(containerFrame); - updateFrameTitle(); - containerFrame.dispose(); - containerFrame = null; - if (prevVps != null) { - prevVps.cleanUpSession(); - prevVps = null; - } - currentVps = this; - workingProtocol.startNormalHandling(this, surface, - clipboardController, rfb); - // rfb.setInitData(workingProtocol.getInitData()); too early - // workingProtocol.startNormalHandling(this, surface, - // clipboardController); - tryAgain = false; - } catch (UnsupportedProtocolVersionException e) { - connectionManager.showReconnectDialog( - "Unsupported Protocol Version", e.getMessage()); - logger.severe(e.getMessage()); - } catch (UnsupportedSecurityTypeException e) { - connectionManager.showReconnectDialog( - "Unsupported Security Type", e.getMessage()); - logger.severe(e.getMessage()); - } catch (AuthenticationFailedException e) { - passwordFromParams = null; - connectionManager.showReconnectDialog("Authentication Failed", - e.getMessage()); - logger.severe(e.getMessage()); - } catch (TransportException e) { - connectionManager.showReconnectDialog("Connection Error", - "Connection Error" + ": " + e.getMessage()); - logger.severe(e.getMessage()); - } catch (IOException e) { - connectionManager.showReconnectDialog("Connection Error", - "Connection Error" + ": " + e.getMessage()); - logger.severe(e.getMessage()); - } catch (FatalException e) { - connectionManager.showReconnectDialog("Connection Error", - "Connection Error" + ": " + e.getMessage()); - logger.severe(e.getMessage()); - } - } - return !tryAgain; - } -*/ + private void cleanUpSession() { if (prevVps != null) { prevVps.cleanUpSession(); prevVps = null; } -// workingProtocol.cleanUpSession(); + // workingProtocol.cleanUpSession(); } public void createConnectionAndStart() { Thread thread; - opendPort = rfb.selectPort(5999); - acceptThread = new AcceptThread(rfb, opendPort); + opendPort = myRfb.selectPort(5999); + acceptThread = new AcceptThread(myRfb, opendPort); thread = new Thread(acceptThread); thread.start(); -// getCast = new GetBroadCastProxy(this, -// workingProtocol.getRemoteDesktopName(), -// this.connectionParams.hostName); -// thread = new Thread(getCast); -// thread.start(); + getCast = new GetBroadCastProxy(this, + this.connectionParams.getHostName(), + this.connectionParams.getHostName()); + thread = new Thread(getCast); + thread.start(); } - - public void proxyStart(String[] argv,int width,int height) { + public void proxyStart(String[] argv, int width, int height) { fbWidth = width; fbHeight = height; proxyStart(argv); } - + public void proxyStart(String[] argv) { String[] mainArgs = argv; - System.out.println(mainArgs.length); // input into arguments Decision Parser parser = new Parser(); ParametersHandler.completeParserOptions(parser); - if(fbWidth==0) + if (fbWidth == 0) parser.parse(argv); if (parser.isSet(ParametersHandler.ARG_HELP)) { printUsage(parser.optionsUsage()); @@ -278,7 +195,6 @@ thread2.start(); } - private void getChangeScreenRequest() { Thread th = new Thread(new Runnable() { @Override @@ -296,24 +212,24 @@ int width = Integer.parseInt(is.readLine()); int height = Integer.parseInt(is.readLine()); // String screenSize = is.readLine(); - if(permitChangeScreen()) { - changeVNCServer(newHostName,width,height); + if (permitChangeScreen()) { + changeVNCServer(newHostName, width, height); } else { continue; } clientSocket.close(); } } catch (IOException e) { - continue; // log + continue; // log } } } }); th.start(); } - + private boolean permitChangeScreen() { - + return true; } @@ -325,8 +241,8 @@ } - private void createSocketAndSend(LinkedList<String> clientList, String host, String port) - throws UnknownHostException, IOException { + private void createSocketAndSend(LinkedList<String> clientList, + String host, String port) throws UnknownHostException, IOException { boolean passFlag = false; for (String client : clientList) { if (passFlag) { @@ -341,30 +257,34 @@ passFlag = true; } } - + /** - * chnageVNCServer is called when host change. - * @param hostName HostAddress - * @param width FrameWidth - * @param height FrameHeight + * chnageVNCServer is called when host change. + * + * @param hostName + * HostAddress + * @param width + * FrameWidth + * @param height + * FrameHeight */ - public void changeVNCServer(String hostName, int width, int height) throws UnknownHostException, - IOException { + public void changeVNCServer(String hostName, int width, int height) + throws UnknownHostException, IOException { // sender and reader stop - VncProxyService newVps = new VncProxyService(this,hostName); -// newVps.fbWidth = width; -// newVps.fbHeight = height; + VncProxyService newVps = new VncProxyService(this, hostName); + // newVps.fbWidth = width; + // newVps.fbHeight = height; // run call and change workingProtocol - newVps.connectionParams.hostName = hostName; - socketClose(); - newVps.createConnectionAndStart(); - newVps.createSocketAndSend(aClient.getList(), hostName, String.valueOf(newVps.opendPort)); + newVps.connectionParams.setHostName(hostName); + socketClose(); + newVps.createConnectionAndStart(); + newVps.createSocketAndSend(aClient.getList(), hostName, + String.valueOf(newVps.opendPort)); } @Override public void settingsChanged(SettingsChangedEvent event) { - // TODO Auto-generated method stub - + } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java Sat Dec 21 18:46:54 2013 +0900 @@ -35,6 +35,9 @@ import java.net.Socket; import java.util.logging.Logger; +import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; +import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient; + /** * @author dime at tightvnc.com */ @@ -61,6 +64,7 @@ private AbstractConnectionWorkerFactory connectionWorkerFactory; private NetworkConnectionWorker networkConnectionWorker; private boolean needReconnection = true; + private boolean isTreeVNC = false; public ConnectionPresenter(boolean hasSshSupport, boolean allowInteractive) { this.hasSshSupport = hasSshSupport; @@ -75,9 +79,12 @@ if ( ! isModelRegisteredByName(CONNECTION_PARAMS_MODEL)) { throw new IllegalStateException("No Connection Params model added."); } - connectionsHistory = new ConnectionsHistory(); - addModel(CONNECTIONS_HISTORY_MODEL, connectionsHistory); - syncModels(paramSettingsMask); + + if(!isTreeVNC) { + connectionsHistory = new ConnectionsHistory(); + addModel(CONNECTIONS_HISTORY_MODEL, connectionsHistory); + syncModels(paramSettingsMask); + } if (allowInteractive) { show(); populate(); @@ -287,4 +294,8 @@ public boolean allowInteractive() { return allowInteractive; } + + public void setIsTreeVNC(boolean flag) { + isTreeVNC = flag; + } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Sat Dec 21 18:46:54 2013 +0900 @@ -22,8 +22,10 @@ Viewer v = new Viewer(); v.startViewer(args); } else { - MyVncClient mvc = new MyVncClient(); - mvc.startClient(args); + //MyVncClient mvc = new MyVncClient(); + //mvc.startClient(args); + Viewer v = new Viewer(); + v.startViewer(args); } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sat Dec 21 18:46:54 2013 +0900 @@ -44,6 +44,8 @@ import java.util.jar.Manifest; import java.util.logging.*; +import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; import jp.ac.u_ryukyu.treevnc.client.GetDataClient; import jp.ac.u_ryukyu.treevnc.client.GetHostClient; import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient; @@ -55,7 +57,7 @@ private int paramsMask; private boolean allowAppletInteractiveConnections; - protected final ConnectionParams connectionParams; + public final ConnectionParams connectionParams; protected String passwordFromParams; boolean isSeparateFrame = true; protected boolean isApplet = true; @@ -63,6 +65,8 @@ protected UiSettings uiSettings; private volatile boolean isAppletStopped = false; private ConnectionPresenter connectionPresenter; + private boolean isTreeVNC = false; + public MyRfbProto myRfb; public static void main(String[] args) { Parser parser = new Parser(); @@ -226,11 +230,11 @@ } }); } - + SwingViewerWindowFactory viewerWindowFactory = new SwingViewerWindowFactory(isSeparateFrame, isApplet, this); connectionPresenter.setConnectionWorkerFactory( - new SwingConnectionWorkerFactory(connectionView.getFrame(), passwordFromParams, connectionPresenter, viewerWindowFactory)); + new SwingConnectionWorkerFactory(connectionView.getFrame(), passwordFromParams, connectionPresenter, viewerWindowFactory, myRfb)); connectionPresenter.startConnection(settings, uiSettings, paramsMask); } @@ -285,17 +289,24 @@ } public void startViewer(String[] args) { - GetHostClient bCast = new GetHostClient("who"); - bCast.getHost(); - GetDataClient getBcast = new GetDataClient(); - Thread runBcast = new Thread(getBcast); - runBcast.start(); - connectionParams.hostName = getBcast.textAddress(); - getBcast.interrupt(); Viewer viewer = new Viewer(); + CreateConnectionParam cp = new CreateConnectionParam(new MyRfbProtoClient()); + cp.communicationToProxy(); + cp.createConnectionParam(viewer); + viewer.isTreeVNC = true; + SwingUtilities.invokeLater(viewer); + } - + + public void setConnectionParam(String hostName, int port) { + connectionParams.setHostName(hostName); + connectionParams.setPortNumber(port); + } + + public void setIsTreeVNC(boolean flag) { + isTreeVNC = flag; + } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingConnectionWorkerFactory.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingConnectionWorkerFactory.java Sat Dec 21 18:46:54 2013 +0900 @@ -31,6 +31,8 @@ import javax.swing.*; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; + /** * @author dime at tightvnc.com */ @@ -40,13 +42,15 @@ private String predefinedPassword; private final ConnectionPresenter presenter; private final SwingViewerWindowFactory viewerWindowFactory; + private MyRfbProto myRfb; public SwingConnectionWorkerFactory(JFrame parentWindow, String predefinedPassword, ConnectionPresenter presenter, - SwingViewerWindowFactory viewerWindowFactory) { + SwingViewerWindowFactory viewerWindowFactory, MyRfbProto rfb) { this.parentWindow = parentWindow; this.predefinedPassword = predefinedPassword; this.presenter = presenter; this.viewerWindowFactory = viewerWindowFactory; + this.myRfb = rfb; } @Override @@ -56,7 +60,7 @@ @Override public RfbConnectionWorker createRfbConnectionWorker() { - return new SwingRfbConnectionWorker(predefinedPassword, presenter, parentWindow, viewerWindowFactory); + return new SwingRfbConnectionWorker(predefinedPassword, presenter, parentWindow, viewerWindowFactory, myRfb); } @Override
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingRfbConnectionWorker.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingRfbConnectionWorker.java Sat Dec 21 18:46:54 2013 +0900 @@ -44,6 +44,9 @@ import java.util.concurrent.ExecutionException; import java.util.logging.Logger; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; +import jp.ac.u_ryukyu.treevnc.server.MyRfbProtoProxy; + /** * @author dime at tightvnc.com */ @@ -61,6 +64,7 @@ protected Socket workingSocket; protected ProtocolSettings rfbSettings; protected UiSettings uiSettings; + private MyRfbProto myRfb; @Override public Void doInBackground() throws Exception { @@ -77,16 +81,18 @@ publish(message); workingProtocol.handshake(); + myRfb.setProtocolContext(workingProtocol); // tryAgain = false; return null; } public SwingRfbConnectionWorker(String predefinedPassword, ConnectionPresenter presenter, JFrame parentWindow, - SwingViewerWindowFactory viewerWindowFactory) { + SwingViewerWindowFactory viewerWindowFactory, MyRfbProto myRfb) { this.predefinedPassword = predefinedPassword; this.presenter = presenter; this.parentWindow = parentWindow; this.viewerWindowFactory = viewerWindowFactory; + this.myRfb = myRfb; logger = Logger.getLogger(getClass().getName()); } @@ -108,8 +114,10 @@ rfbSettings.addListener(clipboardController); viewerWindow = viewerWindowFactory.createViewerWindow( workingProtocol, rfbSettings, uiSettings, connectionString, presenter); - - workingProtocol.startNormalHandling(this, viewerWindow.getSurface(), clipboardController); + if(myRfb instanceof MyRfbProtoProxy) + workingProtocol.startNormalHandling(this, viewerWindow.getSurface(), clipboardController, myRfb); + else + workingProtocol.startNormalHandling(this, viewerWindow.getSurface(), clipboardController); presenter.showMessage("Started"); presenter.successfulRfbConnection();
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/ssh/SwingSshUserInfo.java Tue Dec 17 20:16:48 2013 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/ssh/SwingSshUserInfo.java Sat Dec 21 18:46:54 2013 +0900 @@ -48,17 +48,14 @@ this.parentFrame = parentFrame; } - @Override public String getPassphrase() { return passphrase; } - @Override public String getPassword() { return password; } - @Override public boolean promptPassword(final String message) { final int[] result = new int[1]; try { @@ -93,7 +90,6 @@ return JOptionPane.OK_OPTION == result[0]; } - @Override public boolean promptPassphrase(final String message) { final int[] result = new int[1]; try { @@ -122,7 +118,6 @@ return JOptionPane.OK_OPTION == result[0]; } - @Override public boolean promptYesNo(final String message) { final int[] result = new int[1]; try { @@ -145,7 +140,6 @@ return JOptionPane.YES_OPTION == result[0]; } - @Override public void showMessage(final String message) { try { SwingUtilities.invokeAndWait(new Runnable() { @@ -165,7 +159,6 @@ } } - @Override public String[] promptKeyboardInteractive(final String destination, final String name, final String instruction,