Inheritance: IDisposable
		/// <exception cref="System.IO.IOException"></exception>
		internal override int ReadTrailerWireFormat(InputStream @in, byte[] buffer, int bufferIndex
			)
		{
			int start = bufferIndex;
			if (@in.Read(buffer, bufferIndex, Length) != Length)
			{
				throw new IOException("invalid session request wire format");
			}
			bufferIndex += _calledName.ReadWireFormat(buffer, bufferIndex);
			bufferIndex += _callingName.ReadWireFormat(buffer, bufferIndex);
			return bufferIndex - start;
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal override int ReadTrailerWireFormat(InputStream @in, byte[] buffer, int bufferIndex
			)
		{
			if (@in.Read(buffer, bufferIndex, Length) != Length)
			{
				throw new IOException("unexpected EOF reading netbios retarget session response");
			}
			int addr = ReadInt4(buffer, bufferIndex);
			bufferIndex += 4;
			_retargetAddress = new NbtAddress(null, addr, false, NbtAddress.BNode);
			_retargetPort = ReadInt2(buffer, bufferIndex);
			return Length;
		}
示例#3
0
        public void Load(InputStream input)
        {
            StreamReader sr = new StreamReader(input);
            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();

                if (!string.IsNullOrEmpty(line))
                {
                    string[] tokens = line.Split('=');
                    //_properties.Add(tokens[0], tokens[1]);
                    _properties.Put(tokens[0], tokens[1]);
                }
            }
        }
		/// <exception cref="System.IO.IOException"></exception>
		internal static int Readn(InputStream @in, byte[] b, int off, int len)
		{
			int i = 0;
			int n;
			while (i < len)
			{
				n = @in.Read(b, off + i, len - i);
				if (n <= 0)
				{
					break;
				}
				i += n;
			}
			return i;
		}
示例#5
0
文件: Config.cs 项目: kztao/SharpCifs
 /// <summary>
 /// Load the <code>Config</code> with properties from the stream
 /// <code>in</code> from a <code>Properties</code> file.
 /// </summary>
 /// <remarks>
 /// Load the <code>Config</code> with properties from the stream
 /// <code>in</code> from a <code>Properties</code> file.
 /// </remarks>
 /// <exception cref="System.IO.IOException"></exception>
 public static void Load(InputStream input)
 {
     if (input != null)
     {
         _prp.Load(input);
     }
     try
     {
         _prp.PutAll(Runtime.GetProperties());
     }
     catch (SecurityException)
     {
         if (_log.Level > 1)
         {
             _log.WriteLine("SecurityException: jcifs will ignore System properties");
         }
     }
 }
示例#6
0
		static internal InputStream Wrap (Stream s)
		{
			InputStream stream = new InputStream ();
			stream.Wrapped = s;
			return stream;
		}
示例#7
0
		/// <summary>
		/// Return the <code>InputStream</code> used to read information
		/// from this pipe instance.
		/// </summary>
		/// <remarks>
		/// Return the <code>InputStream</code> used to read information
		/// from this pipe instance. Presumably data would first be written
		/// to the <code>OutputStream</code> associated with this Named
		/// Pipe instance although this is not a requirement (e.g. a
		/// read-only named pipe would write data to this stream on
		/// connection). Reading from this stream may block. Therefore it
		/// may be necessary that an addition thread be used to read and
		/// write to a Named Pipe.
		/// </remarks>
		/// <exception cref="System.IO.IOException"></exception>
		public virtual InputStream GetNamedPipeInputStream()
		{
			if (PipeIn == null)
			{
				if ((PipeType & PipeTypeCall) == PipeTypeCall || (PipeType & PipeTypeTransact
					) == PipeTypeTransact)
				{
					PipeIn = new TransactNamedPipeInputStream(this);
				}
				else
				{
					PipeIn = new SmbFileInputStream(this, (PipeType & unchecked((int)(0xFFFF00FF))) |
						 OExcl);
				}
			}
			return PipeIn;
		}
示例#8
0
        /// <exception cref="System.IO.IOException"></exception>
        private void Negotiate(int port, ServerMessageBlock resp)
        {
            lock (Sbuf)
            {
                if (port == 139)
                {
                    Ssn139();
                }
                else
                {
                    if (port == -1)
                    {
                        port = SmbConstants.DefaultPort;
                    }
                    // 445
                    Socket = new SocketEx(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    if (LocalAddr != null)
                    {
                        Socket.Bind2(new IPEndPoint(LocalAddr, LocalPort));
                    }

                    Socket.Connect(new IPEndPoint(IPAddress.Parse(Address.GetHostAddress()), port), SmbConstants.ConnTimeout);
                    Socket.SoTimeOut = SmbConstants.SoTimeout;
                    Out = Socket.GetOutputStream();
                    In = Socket.GetInputStream();
                }
                if (++Mid == 32000)
                {
                    Mid = 1;
                }
                NegotiateRequest.Mid = Mid;
                int n = NegotiateRequest.Encode(Sbuf, 4);
                Encdec.Enc_uint32be(n & 0xFFFF, Sbuf, 0);
                if (Log.Level >= 4)
                {
                    Log.WriteLine(NegotiateRequest);
                    if (Log.Level >= 6)
                    {
                        Hexdump.ToHexdump(Log, Sbuf, 4, n);
                    }
                }
                Out.Write(Sbuf, 0, 4 + n);
                Out.Flush();
                if (PeekKey() == null)
                {
                    throw new IOException("transport closed in negotiate");
                }
                int size = Encdec.Dec_uint16be(Sbuf, 2) & 0xFFFF;
                if (size < 33 || (4 + size) > Sbuf.Length)
                {
                    throw new IOException("Invalid payload size: " + size);
                }
                Readn(In, Sbuf, 4 + 32, size - 32);
                resp.Decode(Sbuf, 4);
                if (Log.Level >= 4)
                {
                    Log.WriteLine(resp);
                    if (Log.Level >= 6)
                    {
                        Hexdump.ToHexdump(Log, Sbuf, 4, n);
                    }
                }
            }
        }
示例#9
0
 public InputStreamReader(InputStream s, Encoding e) : base(s.GetWrappedStream(), e)
 {
 }
示例#10
0
 public InputStreamReader(InputStream s, Encoding e)
     : base(s.GetWrappedStream (), e)
 {
 }
		/// <exception cref="System.IO.IOException"></exception>
		internal static int ReadPacketType(InputStream @in, byte[] buffer, int bufferIndex
			)
		{
			int n;
			if ((n = Readn(@in, buffer, bufferIndex, HeaderLength)) != HeaderLength)
			{
				if (n == -1)
				{
					return -1;
				}
				throw new IOException("unexpected EOF reading netbios session header");
			}
			int t = buffer[bufferIndex] & unchecked(0xFF);
			return t;
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal abstract int ReadTrailerWireFormat(InputStream @in, byte[] buffer, int bufferIndex
			);
		/// <exception cref="System.IO.IOException"></exception>
		internal virtual int ReadHeaderWireFormat(InputStream @in, byte[] buffer, int bufferIndex
			)
		{
			Type = buffer[bufferIndex++] & unchecked(0xFF);
			Length = ((buffer[bufferIndex] & unchecked(0x01)) << 16) + ReadInt2(buffer
				, bufferIndex + 1);
			return HeaderLength;
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal virtual int ReadWireFormat(InputStream @in, byte[] buffer, int bufferIndex
			)
		{
			ReadHeaderWireFormat(@in, buffer, bufferIndex);
			return HeaderLength + ReadTrailerWireFormat(@in, buffer, bufferIndex);
		}
示例#15
0
		public ObjectInputStream (InputStream s)
		{
			_reader = new BinaryReader (s.GetWrappedStream ());
		}
示例#16
0
 public WrappedSystemStream(InputStream ist)
 {
     this._ist = ist;
 }
示例#17
0
        //Stream(string path) constructor deleted
        //protected InputStreamReader (string file) : base(file)
        //{
        //}

        public InputStreamReader(InputStream s) : base(s.GetWrappedStream())
        {
        }
示例#18
0
 public InputStreamReader(InputStream s, string encoding)
     : base(s.GetWrappedStream (), Encoding.GetEncoding (encoding))
 {
 }
示例#19
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual void Ssn139()
        {
            Name calledName = new Name(Address.FirstCalledName(), 0x20, null
                );
            do
            {
                Socket = new SocketEx(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                if (LocalAddr != null)
                {
                    Socket.Bind2(new IPEndPoint(LocalAddr, LocalPort));
                }

                Socket.Connect(new IPEndPoint(IPAddress.Parse(Address.GetHostAddress()), 139), SmbConstants.ConnTimeout);
                Socket.SoTimeOut = SmbConstants.SoTimeout;

                Out = Socket.GetOutputStream();
                In = Socket.GetInputStream();
                SessionServicePacket ssp = new SessionRequestPacket(calledName, NbtAddress.GetLocalName
                    ());
                Out.Write(Sbuf, 0, ssp.WriteWireFormat(Sbuf, 0));
                if (Readn(In, Sbuf, 0, 4) < 4)
                {
                    try
                    {
                        Socket.Dispose();
                    }
                    catch (IOException)
                    {
                    }
                    throw new SmbException("EOF during NetBIOS session request");
                }
                switch (Sbuf[0] & 0xFF)
                {
                    case SessionServicePacket.PositiveSessionResponse:
                        {
                            if (Log.Level >= 4)
                            {
                                Log.WriteLine("session established ok with " + Address);
                            }
                            return;
                        }

                    case SessionServicePacket.NegativeSessionResponse:
                        {
                            int errorCode = In.Read() & 0xFF;
                            switch (errorCode)
                            {
                                case NbtException.CalledNotPresent:
                                case NbtException.NotListeningCalled:
                                    {
                                        Socket.Dispose();
                                        break;
                                    }

                                default:
                                    {
                                        Disconnect(true);
                                        throw new NbtException(NbtException.ErrSsnSrvc, errorCode);
                                    }
                            }
                            break;
                        }

                    case -1:
                        {
                            Disconnect(true);
                            throw new NbtException(NbtException.ErrSsnSrvc, NbtException.ConnectionRefused
                                );
                        }

                    default:
                        {
                            Disconnect(true);
                            throw new NbtException(NbtException.ErrSsnSrvc, 0);
                        }
                }
            }
            while ((calledName.name = Address.NextCalledName()) != null);
            throw new IOException("Failed to establish session with " + Address);
        }
示例#20
0
 public InputStreamReader(InputStream s)
     : base(s.GetWrappedStream ())
 {
 }
示例#21
0
 public InputStreamReader(InputStream s, string encoding) : base(s.GetWrappedStream(), Encoding.GetEncoding(encoding))
 {
 }