From bfcd1b520fd79b893e721ba916ae5e1656407d2f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Aug 2017 02:43:41 -0400 Subject: merge common implementations and server implementations --- .../SharpCifs/Smb/TransactNamedPipeOutputStream.cs | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeOutputStream.cs (limited to 'Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeOutputStream.cs') diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeOutputStream.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeOutputStream.cs new file mode 100644 index 0000000000..d3e8d3e1ad --- /dev/null +++ b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeOutputStream.cs @@ -0,0 +1,86 @@ +// This code is derived from jcifs smb client library +// Ported by J. Arturo +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +namespace SharpCifs.Smb +{ + internal class TransactNamedPipeOutputStream : SmbFileOutputStream + { + private string _path; + + private SmbNamedPipe _pipe; + + private byte[] _tmp = new byte[1]; + + private bool _dcePipe; + + /// + internal TransactNamedPipeOutputStream(SmbNamedPipe pipe) : base(pipe, false, (pipe + .PipeType & unchecked((int)(0xFFFF00FF))) | SmbFile.OExcl) + { + this._pipe = pipe; + _dcePipe = (pipe.PipeType & SmbNamedPipe.PipeTypeDceTransact) == SmbNamedPipe + .PipeTypeDceTransact; + _path = pipe.Unc; + } + + /// + public override void Close() + { + _pipe.Close(); + } + + /// + public override void Write(int b) + { + _tmp[0] = unchecked((byte)b); + Write(_tmp, 0, 1); + } + + /// + public override void Write(byte[] b) + { + Write(b, 0, b.Length); + } + + /// + public override void Write(byte[] b, int off, int len) + { + if (len < 0) + { + len = 0; + } + if ((_pipe.PipeType & SmbNamedPipe.PipeTypeCall) == SmbNamedPipe.PipeTypeCall) + { + _pipe.Send(new TransWaitNamedPipe(_path), new TransWaitNamedPipeResponse()); + _pipe.Send(new TransCallNamedPipe(_path, b, off, len), new TransCallNamedPipeResponse + (_pipe)); + } + else + { + if ((_pipe.PipeType & SmbNamedPipe.PipeTypeTransact) == SmbNamedPipe.PipeTypeTransact) + { + EnsureOpen(); + TransTransactNamedPipe req = new TransTransactNamedPipe(_pipe.Fid, b, off, len); + if (_dcePipe) + { + req.MaxDataCount = 1024; + } + _pipe.Send(req, new TransTransactNamedPipeResponse(_pipe)); + } + } + } + } +} -- cgit v1.2.3