//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.º 2
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);
        }