TransactNamedPipeOutputStream.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // This code is derived from jcifs smb client library <jcifs at samba dot org>
  2. // Ported by J. Arturo <webmaster at komodosoft dot net>
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. namespace SharpCifs.Smb
  18. {
  19. internal class TransactNamedPipeOutputStream : SmbFileOutputStream
  20. {
  21. private string _path;
  22. private SmbNamedPipe _pipe;
  23. private byte[] _tmp = new byte[1];
  24. private bool _dcePipe;
  25. /// <exception cref="System.IO.IOException"></exception>
  26. internal TransactNamedPipeOutputStream(SmbNamedPipe pipe)
  27. : base(pipe, false, (pipe.PipeType & unchecked((int)(0xFFFF00FF))) | SmbFile.OExcl)
  28. {
  29. this._pipe = pipe;
  30. _dcePipe = (pipe.PipeType & SmbNamedPipe.PipeTypeDceTransact)
  31. == SmbNamedPipe.PipeTypeDceTransact;
  32. _path = pipe.Unc;
  33. }
  34. /// <exception cref="System.IO.IOException"></exception>
  35. public override void Close()
  36. {
  37. _pipe.Close();
  38. }
  39. /// <exception cref="System.IO.IOException"></exception>
  40. public override void Write(int b)
  41. {
  42. _tmp[0] = unchecked((byte)b);
  43. Write(_tmp, 0, 1);
  44. }
  45. /// <exception cref="System.IO.IOException"></exception>
  46. public override void Write(byte[] b)
  47. {
  48. Write(b, 0, b.Length);
  49. }
  50. /// <exception cref="System.IO.IOException"></exception>
  51. public override void Write(byte[] b, int off, int len)
  52. {
  53. if (len < 0)
  54. {
  55. len = 0;
  56. }
  57. if ((_pipe.PipeType & SmbNamedPipe.PipeTypeCall) == SmbNamedPipe.PipeTypeCall)
  58. {
  59. _pipe.Send(new TransWaitNamedPipe(_path),
  60. new TransWaitNamedPipeResponse());
  61. _pipe.Send(new TransCallNamedPipe(_path, b, off, len),
  62. new TransCallNamedPipeResponse(_pipe));
  63. }
  64. else
  65. {
  66. if ((_pipe.PipeType & SmbNamedPipe.PipeTypeTransact)
  67. == SmbNamedPipe.PipeTypeTransact)
  68. {
  69. EnsureOpen();
  70. TransTransactNamedPipe req
  71. = new TransTransactNamedPipe(_pipe.Fid, b, off, len);
  72. if (_dcePipe)
  73. {
  74. req.MaxDataCount = 1024;
  75. }
  76. _pipe.Send(req, new TransTransactNamedPipeResponse(_pipe));
  77. }
  78. }
  79. }
  80. }
  81. }