Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static Object[] getInfo(boolean doSeeds, String system, HostOutputStream out, HostInputStream in) throws IOException
        private static object[] getInfo(bool doSeeds, string system, HostOutputStream @out, HostInputStream @in)
        {
            object[] ret = new object[3];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long clientSeedLong = sendSignonExchangeAttributeRequest(out);
            long clientSeedLong = sendSignonExchangeAttributeRequest(@out);

            if (doSeeds)
            {
                sbyte[] clientSeed = Conv.longToByteArray(clientSeedLong);
                ret[1] = clientSeed;
            }
            @out.flush();

            int length = @in.readInt();

            if (length < 20)
            {
                throw DataStreamException.badLength("signonExchangeAttributes", length);
            }
            @in.skipBytes(16);
            int rc = @in.readInt();

            if (rc != 0)
            {
                @in.skipBytes(length - 24);
                throw DataStreamException.badReturnCode("signonExchangeAttributes", rc);
            }
            int    curLength          = 24;
            int    serverVersion      = -1;
            bool   foundServerVersion = false;
            int    serverLevel        = -1;
            bool   foundServerLevel   = false;
            bool   foundServerSeed    = false;
            int    passwordLevel      = -1;
            bool   foundPasswordLevel = false;
            string jobName            = null;

            //        while (curLength < length && !foundServerSeed && !foundPasswordLevel && !foundJobName)
            while (curLength < length && (!foundServerVersion || !foundServerLevel || !foundPasswordLevel || (!doSeeds || (doSeeds && !foundServerSeed))))
            {
                int oldLength = curLength;
                int ll        = @in.readInt();
                int cp        = @in.readShort();
                curLength += 6;
                switch (cp)
                {
                case 0x1101:
                    serverVersion      = @in.readInt();
                    curLength         += 4;
                    foundServerVersion = true;
                    break;

                case 0x1102:
                    serverLevel      = @in.readShort();
                    curLength       += 2;
                    foundServerLevel = true;
                    break;

                case 0x1103:
                    if (doSeeds)
                    {
                        sbyte[] serverSeed = new sbyte[ll - 6];
                        @in.readFully(serverSeed);
                        ret[2]          = serverSeed;
                        curLength      += ll - 6;
                        foundServerSeed = true;
                    }
                    else
                    {
                        @in.skipBytes(ll - 6);
                        curLength += ll - 6;
                    }
                    break;

                case 0x1119:
                    passwordLevel      = @in.read();
                    curLength         += 1;
                    foundPasswordLevel = true;
                    break;

                case 0x111F:
                    @in.skipBytes(4);       // CCSID is always 0.
                    curLength += 4;
                    sbyte[] jobBytes = new sbyte[ll - 10];
                    @in.readFully(jobBytes);
                    jobName    = Conv.ebcdicByteArrayToString(jobBytes, 0, jobBytes.Length);
                    curLength += ll - 10;
                    break;

                default:
                    @in.skipBytes(ll - 6);
                    curLength += ll - 6;
                    break;
                }
                int diff = ll - (curLength - oldLength);
                if (diff > 0)
                {
                    @in.skipBytes(diff);
                }
            }
            @in.skipBytes(length - curLength);
            @in.end();

            ret[0] = new SystemInfo(system, serverVersion, serverLevel, passwordLevel, jobName);
            return(ret);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected static String connect(SystemInfo info, HostOutputStream dout, HostInputStream din, int serverID, String user, String password) throws IOException
        protected internal static string connect(SystemInfo info, HostOutputStream dout, HostInputStream din, int serverID, string user, string password)
        {
            // Exchange random seeds.
            long seed = sendExchangeRandomSeedsRequest(dout, serverID);

            sbyte[] clientSeed = Conv.longToByteArray(seed);
            dout.flush();

            int length = din.readInt();

            if (length < 20)
            {
                throw DataStreamException.badLength("exchangeRandomSeeds-" + serverID, length);
            }
            din.skipBytes(16);
            int rc = din.readInt();

            if (rc != 0)
            {
                throw DataStreamException.badReturnCode("exchangeRandomSeeds-" + serverID, rc);
            }
            sbyte[] serverSeed = new sbyte[8];
            din.readFully(serverSeed);

            sbyte[] userBytes     = getUserBytes(user, info.PasswordLevel);
            sbyte[] passwordBytes = getPasswordBytes(password, info.PasswordLevel);
            password = null;
            sbyte[] encryptedPassword = getEncryptedPassword(userBytes, passwordBytes, clientSeed, serverSeed, info.PasswordLevel);

            din.end();

            sbyte[] userEBCDICBytes = (info.PasswordLevel < 2) ? userBytes : getUserBytes(user, 0);
            sendStartServerRequest(dout, userEBCDICBytes, encryptedPassword, serverID);
            dout.flush();

            length = din.readInt();
            if (length < 20)
            {
                throw DataStreamException.badLength("startServer-" + serverID, length);
            }
            din.skipBytes(16);
            rc = din.readInt();
            if (rc != 0)
            {
                string msg = getReturnCodeMessage(rc);
                throw string.ReferenceEquals(msg, null) ? DataStreamException.badReturnCode("startServer-" + serverID, rc) : DataStreamException.errorMessage("startServer-" + serverID, new Message(rc.ToString(), msg));
            }
            string jobName   = null;
            int    remaining = length - 24;

            while (remaining > 10)
            {
                int ll = din.readInt();
                int cp = din.readShort();
                remaining -= 6;
                if (cp == 0x111F)                 // Job name.
                {
                    din.skipBytes(4);             // CCSID is always 0.
                    remaining -= 4;
                    int     jobLength = ll - 10;
                    sbyte[] jobBytes  = new sbyte[jobLength];
                    din.readFully(jobBytes);
                    jobName    = Conv.ebcdicByteArrayToString(jobBytes, 0, jobLength);
                    remaining -= jobLength;
                }
                else
                {
                    din.skipBytes(ll - 6);
                    remaining -= (ll - 6);
                }
            }
            din.skipBytes(remaining);
            din.end();
            return(jobName);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Connects to the Remote Command host server on the specified port using the specified system information and user.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static CommandConnection getConnection(final boolean isSSL, SystemInfo info, String user, String password, int commandPort, boolean compress) throws IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        public static CommandConnection getConnection(bool isSSL, SystemInfo info, string user, string password, int commandPort, bool compress)
        {
            if (commandPort < 0 || commandPort > 65535)
            {
                throw new IOException("Bad command port: " + commandPort);
            }
            CommandConnection conn = null;

            Socket commandServer = isSSL? SSLSocketFactory.Default.createSocket(info.System, commandPort) : new Socket(info.System, commandPort);
            Stream @in           = commandServer.InputStream;
            Stream @out          = commandServer.OutputStream;

            try
            {
                if (compress)
                {
                    throw new IOException("Experimental compression streams not enabled.");
                    //        in = new CompressionInputStream(in);
                    //        out = new CompressionOutputStream(new BufferedOutputStream(out));
                }

                // Exchange random seeds.
                HostOutputStream dout    = new HostOutputStream(compress ? @out : new BufferedOutputStream(@out));
                HostInputStream  din     = new HostInputStream(new BufferedInputStream(@in));
                string           jobName = connect(info, dout, din, 0xE008, user, password);

                string NLV = Conv.DefaultNLV;
                sendExchangeAttributesRequest(dout, NLV);
                dout.flush();

                int length = din.readInt();
                if (length < 20)
                {
                    throw DataStreamException.badLength("commandExchangeAttributes", length);
                }
                din.skipBytes(16);
                int rc = din.readShort();
                // We ignore the same return codes that JTOPEN ignores
                if (rc != 0x0100 && rc != 0x0104 && rc != 0x0105 && rc != 0x0106 && rc != 0x0107 && rc != 0x0108 && rc != 0)
                {
                    throw DataStreamException.badReturnCode("commandExchangeAttributes", rc);
                }
                int     ccsid    = din.readInt();
                sbyte[] nlvBytes = new sbyte[4];
                nlvBytes[0] = (sbyte)din.readByte();
                nlvBytes[1] = (sbyte)din.readByte();
                nlvBytes[2] = (sbyte)din.readByte();
                nlvBytes[3] = (sbyte)din.readByte();
                NLV         = Conv.ebcdicByteArrayToString(nlvBytes, 0, 4);
                // Server version
                din.skipBytes(4);

                int datastreamLevel = din.readShort();
                din.skipBytes(length - 36);
                din.end();

                conn = new CommandConnection(info, commandServer, din, dout, ccsid, datastreamLevel, user, jobName, NLV);
                return(conn);
            }
            finally
            {
                if (conn == null)
                {
                    @in.Close();
                    @out.Close();
                    commandServer.close();
                }
            }
        }