예제 #1
0
        /// <summary>
        /// Common initialization routine called by the constructures
        /// </summary>
        /// <param name="user">
        /// User name, or null for no authentication
        /// </param>
        /// <param name="password">
        /// Password for the user, or null
        /// </param>
        private void Init(string user, string password)
        {
            var buf      = new byte[32];
            int received = _socket.Receive(buf);

            if (received == 0)
            {
                throw new RserveException("Rserve connection was closed by the remote host");
            }

            var parms = new List <string>();

            for (int i = 0; i < buf.Length; i += 4)
            {
                var b = new byte[4];
                Array.Copy(buf, i, b, 0, 4);
                parms.Add(Encoding.ASCII.GetString(b));
            }

            _connectionParameters = parms.ToArray();
            if (_connectionParameters[0] != "Rsrv")
            {
                throw new ProtocolViolationException("Did not receive Rserve ID signature.");
            }

            if (_connectionParameters[2] != "QAP1")
            {
                throw new NotSupportedException("Only QAP1 protocol is supported.");
            }

            _protocol = new Qap1(_socket);
            if (_connectionParameters.Contains("ARuc"))
            {
                string key = _connectionParameters.FirstOrDefault(x => !String.IsNullOrEmpty(x) && x[0] == 'K');
                key = String.IsNullOrEmpty(key) ? "rs" : key.Substring(1, key.Length - 1);

                Login(user, password, "uc", key);
            }
            else if (_connectionParameters.Contains("ARpt"))
            {
                Login(user, password, "pt");
            }
        }
예제 #2
0
 RConnection(RConnection connection) :
     this(ref connection._socket)
 {
     _protocol = connection._protocol;
     _connectionParameters = connection._connectionParameters;
 }
예제 #3
0
        /// <summary>
        /// Common initialization routine called by the constructures
        /// </summary>
        /// <param name="user">
        /// User name, or null for no authentication
        /// </param>
        /// <param name="password">
        /// Password for the user, or null
        /// </param>
        private void Init( string user , string password )
        {
            var buf = new byte[ 32 ];
            int received = _socket.Receive( buf );
            if ( received == 0 )
            {
                throw new RserveException( "Rserve connection was closed by the remote host" );
            }

            var parms = new List<string>();
            for ( int i = 0 ; i < buf.Length ; i += 4 )
            {
                var b = new byte[ 4 ];
                Array.Copy( buf , i , b , 0 , 4 );
                parms.Add( Encoding.ASCII.GetString( b ) );
            }

            _connectionParameters = parms.ToArray();
            if ( _connectionParameters[ 0 ] != "Rsrv" )
            {
                throw new ProtocolViolationException( "Did not receive Rserve ID signature." );
            }

            if ( _connectionParameters[ 2 ] != "QAP1" )
            {
                throw new NotSupportedException( "Only QAP1 protocol is supported." );
            }

            _protocol = new Qap1( _socket );
            if ( _connectionParameters.Contains( "ARuc" ) )
            {
                string key = _connectionParameters.FirstOrDefault( x => !String.IsNullOrEmpty( x ) && x[ 0 ] == 'K' );
                key = String.IsNullOrEmpty( key ) ? "rs" : key.Substring( 1 , key.Length - 1 );

                Login( user , password , "uc" , key );
            }
            else if ( _connectionParameters.Contains( "ARpt" ) )
            {
                Login( user , password , "pt" );
            }
        }
예제 #4
0
 RConnection(RConnection connection) :
     this(ref connection._socket)
 {
     _protocol             = connection._protocol;
     _connectionParameters = connection._connectionParameters;
 }